OSDN Git Service

New anonymous patterns to combine insert with arbitrary ashift, ashiftrt,
[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, 1995 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, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
22 \f
23 ;; Define an insn type attribute.  This is used in function unit delay
24 ;; computations.
25 (define_attr "type" "integer,load,fpload,imul,idiv,branch,compare,delayed_compare,fpcompare,mtjmpr,fp,dmul,sdiv,ddiv,ssqrt,dsqrt,jmpreg"
26   (const_string "integer"))
27
28 ;; Length (in bytes).
29 (define_attr "length" ""
30   (if_then_else (eq_attr "type" "branch")
31                 (if_then_else (and (ge (minus (pc) (match_dup 0))
32                                        (const_int -32768))
33                                    (lt (minus (pc) (match_dup 0))
34                                        (const_int 32767)))
35                               (const_int 8)
36                               (const_int 12))
37                 (const_int 4)))
38
39 ;; Processor type -- this attribute must exactly match the processor_type
40 ;; enumeration in rs6000.h.
41
42 (define_attr "cpu" "rios1,rios2,ppc403,ppc601,ppc603,ppc604,ppc620"
43   (const (symbol_ref "rs6000_cpu_attr")))
44
45 ; (define_function_unit NAME MULTIPLICITY SIMULTANEITY
46 ;                       TEST READY-DELAY ISSUE-DELAY [CONFLICT-LIST])
47
48 ; Load/Store Unit -- POWER/2 and pure PowerPC only
49 ; (POWER and 601 use Integer Unit)
50 (define_function_unit "lsu" 1 0
51   (and (eq_attr "type" "load")
52        (eq_attr "cpu" "rios2,ppc603,ppc604,ppc620"))
53   2 0)
54
55 (define_function_unit "lsu" 1 0
56   (and (eq_attr "type" "fpload")
57        (eq_attr "cpu" "rios2,ppc603,ppc604,ppc620"))
58   2 0)
59
60 (define_function_unit "iu" 1 0
61   (and (eq_attr "type" "load")
62        (eq_attr "cpu" "rios1,ppc403,ppc601"))
63   2 0)
64
65 (define_function_unit "iu" 1 0
66   (and (eq_attr "type" "fpload")
67        (eq_attr "cpu" "rios1,ppc601"))
68   3 0)
69
70 ; Integer Unit (RIOS1, PPC601, PPC603)
71 ; Trivial operations take one cycle which need not be listed here.
72 (define_function_unit "iu" 1 0
73   (and (eq_attr "type" "imul")
74        (eq_attr "cpu" "rios1"))
75   3 3)
76
77 (define_function_unit "iu" 1 0
78   (and (eq_attr "type" "imul")
79        (eq_attr "cpu" "ppc403"))
80   4 4)
81
82 (define_function_unit "iu" 1 0
83   (and (eq_attr "type" "imul")
84        (eq_attr "cpu" "ppc601,ppc603"))
85   5 5)
86
87 (define_function_unit "iu" 1 0
88   (and (eq_attr "type" "idiv")
89        (eq_attr "cpu" "rios1"))
90   19 19)
91
92 (define_function_unit "iu" 1 0
93   (and (eq_attr "type" "idiv")
94        (eq_attr "cpu" "ppc403"))
95   33 33)
96
97 (define_function_unit "iu" 1 0
98   (and (eq_attr "type" "idiv")
99        (eq_attr "cpu" "ppc601"))
100   36 36)
101
102 (define_function_unit "iu" 1 0
103   (and (eq_attr "type" "idiv")
104        (eq_attr "cpu" "ppc603"))
105   37 36)
106
107 ; RIOS2 has two integer units: a primary one which can perform all
108 ; operations and a secondary one which is fed in lock step with the first
109 ; and can perform "simple" integer operations.
110 (define_function_unit "iu2" 2 0
111   (and (eq_attr "type" "integer")
112        (eq_attr "cpu" "rios2"))
113   1 0
114   [(eq_attr "type" "imul,idiv")])
115
116 (define_function_unit "imuldiv" 1 0
117   (and (eq_attr "type" "imul")
118        (eq_attr "cpu" "rios2"))
119   2 2
120   [(eq_attr "type" "integer")])
121
122 (define_function_unit "imuldiv" 1 0
123   (and (eq_attr "type" "idiv")
124        (eq_attr "cpu" "rios2"))
125   13 13
126   [(eq_attr "type" "integer")])
127
128 ; PPC604 has three integer units: one primary and two secondary.
129 (define_function_unit "iu3" 3 0
130   (and (eq_attr "type" "integer")
131        (eq_attr "cpu" "ppc604,ppc620"))
132   1 0
133   [(eq_attr "type" "imul,idiv")])
134
135 (define_function_unit "imuldiv" 1 0
136   (and (eq_attr "type" "imul")
137        (eq_attr "cpu" "ppc604,ppc620"))
138   4 2
139   [(eq_attr "type" "integer")])
140
141 (define_function_unit "imuldiv" 1 0
142   (and (eq_attr "type" "idiv")
143        (eq_attr "cpu" "ppc604,ppc620"))
144   20 19
145   [(eq_attr "type" "integer")])
146
147 ; Branch Processing Unit
148 (define_function_unit "bpu" 1 0
149   (eq_attr "type" "compare")
150   4 0)
151
152 (define_function_unit "bpu" 1 0
153   (eq_attr "type" "delayed_compare")
154   5 0)
155
156 (define_function_unit "bpu" 1 0
157   (and (eq_attr "type" "fpcompare")
158        (eq_attr "cpu" "rios1,rios2"))
159   8 0)
160
161 (define_function_unit "bpu" 1 0
162   (and (eq_attr "type" "fpcompare")
163        (eq_attr "cpu" "ppc601,ppc603,ppc604,ppc620"))
164   4 0)
165
166 (define_function_unit "bpu" 1 0
167   (and (eq_attr "type" "mtjmpr")
168        (eq_attr "cpu" "rios1,rios2"))
169   5 0)
170
171 (define_function_unit "bpu" 1 0
172   (and (eq_attr "type" "mtjmpr")
173        (eq_attr "cpu" "ppc403,ppc601,ppc603,ppc604,ppc620"))
174   4 0)
175
176 ; Floating Point Unit (RIOS1, PPC601, PPC603, PPC604).
177 (define_function_unit "fpu" 1 0
178   (and (eq_attr "type" "fp,dmul")
179        (eq_attr "cpu" "rios1"))
180   2 0)
181
182 (define_function_unit "fpu" 1 0
183   (and (eq_attr "type" "fp")
184        (eq_attr "cpu" "ppc601"))
185   4 0)
186
187 (define_function_unit "fpu" 1 0
188   (and (eq_attr "type" "fp")
189        (eq_attr "cpu" "ppc603,ppc604,ppc620"))
190   3 0)
191
192 (define_function_unit "fpu" 1 0
193   (and (eq_attr "type" "dmul")
194        (eq_attr "cpu" "ppc601"))
195   5 5)
196
197 (define_function_unit "fpu" 1 0
198   (and (eq_attr "type" "dmul")
199        (eq_attr "cpu" "ppc603"))
200   4 2)
201
202 (define_function_unit "fpu" 1 0
203   (and (eq_attr "type" "dmul")
204        (eq_attr "cpu" "ppc604,ppc620"))
205   3 0)
206
207 (define_function_unit "fpu" 1 0
208   (and (eq_attr "type" "sdiv,ddiv")
209        (eq_attr "cpu" "rios1"))
210   19 19)
211
212 (define_function_unit "fpu" 1 0
213   (and (eq_attr "type" "sdiv")
214        (eq_attr "cpu" "ppc601"))
215   17 17)
216
217 (define_function_unit "fpu" 1 0
218   (and (eq_attr "type" "sdiv")
219        (eq_attr "cpu" "ppc603,ppc604,ppc620"))
220   18 18)
221
222 (define_function_unit "fpu" 1 0
223   (and (eq_attr "type" "ddiv")
224        (eq_attr "cpu" "ppc601,ppc604,ppc620"))
225   31 31)
226
227 (define_function_unit "fpu" 1 0
228   (and (eq_attr "type" "ddiv")
229        (eq_attr "cpu" "ppc603"))
230   33 33)
231
232 (define_function_unit "fpu" 1 0
233   (and (eq_attr "type" "ssqrt")
234        (eq_attr "cpu" "ppc620"))
235   31 31)
236
237 (define_function_unit "fpu" 1 0
238   (and (eq_attr "type" "dsqrt")
239        (eq_attr "cpu" "ppc620"))
240   31 31)
241
242 ; RIOS2 has two symmetric FPUs.
243 (define_function_unit "fpu2" 2 0
244   (and (eq_attr "type" "fp")
245        (eq_attr "cpu" "rios2"))
246   2 0)
247
248 (define_function_unit "fpu2" 2 0
249   (and (eq_attr "type" "dmul")
250        (eq_attr "cpu" "rios2"))
251   2 0)
252
253 (define_function_unit "fpu2" 2 0
254   (and (eq_attr "type" "sdiv,ddiv")
255        (eq_attr "cpu" "rios2"))
256   17 17)
257
258 (define_function_unit "fpu2" 2 0
259   (and (eq_attr "type" "ssqrt,dsqrt")
260        (eq_attr "cpu" "rios2"))
261   26 26)
262 \f
263 ;; Start with fixed-point load and store insns.  Here we put only the more
264 ;; complex forms.  Basic data transfer is done later.
265
266 (define_expand "zero_extendqidi2"
267   [(set (match_operand:DI 0 "gpc_reg_operand" "")
268         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
269   "TARGET_POWERPC64"
270   "")
271
272 (define_insn ""
273   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
274         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
275   "TARGET_POWERPC64"
276   "@
277    lbz%U1%X1 %0,%1
278    rldicl %0,%1,0,56"
279   [(set_attr "type" "load,*")])
280
281 (define_insn ""
282   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
283         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
284                     (const_int 0)))
285    (clobber (match_scratch:DI 2 "=r"))]
286   "TARGET_POWERPC64"
287   "rldicl. %2,%1,0,56"
288   [(set_attr "type" "compare")])
289
290 (define_insn ""
291   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
292         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
293                     (const_int 0)))
294    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
295         (zero_extend:DI (match_dup 1)))]
296   "TARGET_POWERPC64"
297   "rldicl. %0,%1,0,56"
298   [(set_attr "type" "compare")])
299
300 (define_insn "extendqidi2"
301   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
302         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
303   "TARGET_POWERPC64"
304   "extsb %0,%1")
305
306 (define_insn ""
307   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
308         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
309                     (const_int 0)))
310    (clobber (match_scratch:DI 2 "=r"))]
311   "TARGET_POWERPC64"
312   "extsb. %2,%1"
313   [(set_attr "type" "compare")])
314
315 (define_insn ""
316   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
317         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
318                     (const_int 0)))
319    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
320         (sign_extend:DI (match_dup 1)))]
321   "TARGET_POWERPC64"
322   "extsb. %0,%1"
323   [(set_attr "type" "compare")])
324
325 (define_expand "zero_extendhidi2"
326   [(set (match_operand:DI 0 "gpc_reg_operand" "")
327         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
328   "TARGET_POWERPC64"
329   "")
330
331 (define_insn ""
332   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
333         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
334   "TARGET_POWERPC64"
335   "@
336    lhz%U1%X1 %0,%1
337    rldicl %0,%1,0,48"
338   [(set_attr "type" "load,*")])
339
340 (define_insn ""
341   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
342         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
343                     (const_int 0)))
344    (clobber (match_scratch:DI 2 "=r"))]
345   "TARGET_POWERPC64"
346   "rldicl. %2,%1,0,48"
347   [(set_attr "type" "compare")])
348
349 (define_insn ""
350   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
351         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
352                     (const_int 0)))
353    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
354         (zero_extend:DI (match_dup 1)))]
355   "TARGET_POWERPC64"
356   "rldicl. %0,%1,0,48"
357   [(set_attr "type" "compare")])
358
359 (define_expand "extendhidi2"
360   [(set (match_operand:DI 0 "gpc_reg_operand" "")
361         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
362   "TARGET_POWERPC64"
363   "")
364
365 (define_insn ""
366   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
367         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
368   "TARGET_POWERPC64"
369   "@
370    lha%U1%X1 %0,%1
371    extsh %0,%1"
372   [(set_attr "type" "load,*")])
373
374 (define_insn ""
375   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
376         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
377                     (const_int 0)))
378    (clobber (match_scratch:DI 2 "=r"))]
379   "TARGET_POWERPC64"
380   "extsh. %2,%1"
381   [(set_attr "type" "compare")])
382
383 (define_insn ""
384   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
385         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
386                     (const_int 0)))
387    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
388         (sign_extend:DI (match_dup 1)))]
389   "TARGET_POWERPC64"
390   "extsh. %0,%1"
391   [(set_attr "type" "compare")])
392
393 (define_expand "zero_extendsidi2"
394   [(set (match_operand:DI 0 "gpc_reg_operand" "")
395         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
396   "TARGET_POWERPC64"
397   "")
398
399 (define_insn ""
400   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
401         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
402   "TARGET_POWERPC64"
403   "@
404    lwz%U1%X1 %0,%1
405    rldicl %0,%1,0,32"
406   [(set_attr "type" "load,*")])
407
408 (define_insn ""
409   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
410         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
411                     (const_int 0)))
412    (clobber (match_scratch:DI 2 "=r"))]
413   "TARGET_POWERPC64"
414   "rldicl. %2,%1,0,32"
415   [(set_attr "type" "compare")])
416
417 (define_insn ""
418   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
419         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
420                     (const_int 0)))
421    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
422         (zero_extend:DI (match_dup 1)))]
423   "TARGET_POWERPC64"
424   "rldicl. %0,%1,0,32"
425   [(set_attr "type" "compare")])
426
427 (define_expand "extendsidi2"
428   [(set (match_operand:DI 0 "gpc_reg_operand" "")
429         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
430   "TARGET_POWERPC64"
431   "")
432
433 (define_insn ""
434   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
435         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
436   "TARGET_POWERPC64"
437   "@
438    lwa%U1%X1 %0,%1
439    extsw %0,%1"
440   [(set_attr "type" "load,*")])
441
442 (define_insn ""
443   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
444         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
445                     (const_int 0)))
446    (clobber (match_scratch:DI 2 "=r"))]
447   "TARGET_POWERPC64"
448   "extsw. %2,%1"
449   [(set_attr "type" "compare")])
450
451 (define_insn ""
452   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
453         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
454                     (const_int 0)))
455    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
456         (sign_extend:DI (match_dup 1)))]
457   "TARGET_POWERPC64"
458   "extsw. %0,%1"
459   [(set_attr "type" "compare")])
460
461 (define_expand "zero_extendqisi2"
462   [(set (match_operand:SI 0 "gpc_reg_operand" "")
463         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
464   ""
465   "")
466
467 (define_insn ""
468   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
469         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
470   ""
471   "@
472    lbz%U1%X1 %0,%1
473    {rlinm|rlwinm} %0,%1,0,0xff"
474   [(set_attr "type" "load,*")])
475
476 (define_insn ""
477   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
478         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
479                     (const_int 0)))
480    (clobber (match_scratch:SI 2 "=r"))]
481   ""
482   "{andil.|andi.} %2,%1,0xff"
483   [(set_attr "type" "compare")])
484
485 (define_insn ""
486   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
487         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
488                     (const_int 0)))
489    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
490         (zero_extend:SI (match_dup 1)))]
491   ""
492   "{andil.|andi.} %0,%1,0xff"
493   [(set_attr "type" "compare")])
494
495 (define_expand "extendqisi2"
496   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
497    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
498   ""
499   "
500 {
501   if (TARGET_POWERPC)
502     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
503   else if (TARGET_POWER)
504     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
505   else
506     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
507   DONE;
508 }")
509
510 (define_insn "extendqisi2_ppc"
511   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
512         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
513   "TARGET_POWERPC"
514   "extsb %0,%1")
515
516 (define_insn ""
517   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
518         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
519                     (const_int 0)))
520    (clobber (match_scratch:SI 2 "=r"))]
521   "TARGET_POWERPC"
522   "extsb. %2,%1"
523   [(set_attr "type" "compare")])
524
525 (define_insn ""
526   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
527         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
528                     (const_int 0)))
529    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
530         (sign_extend:SI (match_dup 1)))]
531   "TARGET_POWERPC"
532   "extsb. %0,%1"
533   [(set_attr "type" "compare")])
534
535 (define_expand "extendqisi2_power"
536   [(parallel [(set (match_dup 2)
537                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
538                               (const_int 24)))
539               (clobber (scratch:SI))])
540    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
541                    (ashiftrt:SI (match_dup 2)
542                                 (const_int 24)))
543               (clobber (scratch:SI))])]
544   "TARGET_POWER"
545   "
546 { operands[1] = gen_lowpart (SImode, operands[1]);
547   operands[2] = gen_reg_rtx (SImode); }")
548
549 (define_expand "extendqisi2_no_power"
550   [(set (match_dup 2)
551         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
552                    (const_int 24)))
553    (set (match_operand:SI 0 "gpc_reg_operand" "")
554         (ashiftrt:SI (match_dup 2)
555                      (const_int 24)))]
556   "! TARGET_POWER && ! TARGET_POWERPC"
557   "
558 { operands[1] = gen_lowpart (SImode, operands[1]);
559   operands[2] = gen_reg_rtx (SImode); }")
560
561 (define_expand "zero_extendqihi2"
562   [(set (match_operand:HI 0 "gpc_reg_operand" "")
563         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
564   ""
565   "")
566
567 (define_insn ""
568   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
569         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
570   ""
571   "@
572    lbz%U1%X1 %0,%1
573    {rlinm|rlwinm} %0,%1,0,0xff"
574   [(set_attr "type" "load,*")])
575
576 (define_insn ""
577   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
578         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
579                     (const_int 0)))
580    (clobber (match_scratch:HI 2 "=r"))]
581   ""
582   "{andil.|andi.} %2,%1,0xff"
583   [(set_attr "type" "compare")])
584
585 (define_insn ""
586   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
587         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
588                     (const_int 0)))
589    (set (match_operand:HI 0 "gpc_reg_operand" "=r")
590         (zero_extend:HI (match_dup 1)))]
591   ""
592   "{andil.|andi.} %0,%1,0xff"
593   [(set_attr "type" "compare")])
594
595 (define_expand "extendqihi2"
596   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
597    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
598   ""
599   "
600 {
601   if (TARGET_POWERPC)
602     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
603   else if (TARGET_POWER)
604     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
605   else
606     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
607   DONE;
608 }")
609
610 (define_insn "extendqihi2_ppc"
611   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
612         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
613   "TARGET_POWERPC"
614   "extsb %0,%1")
615
616 (define_insn ""
617   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
618         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
619                     (const_int 0)))
620    (clobber (match_scratch:HI 2 "=r"))]
621   "TARGET_POWERPC"
622   "extsb. %2,%1"
623   [(set_attr "type" "compare")])
624
625 (define_insn ""
626   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
627         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
628                     (const_int 0)))
629    (set (match_operand:HI 0 "gpc_reg_operand" "=r")
630         (sign_extend:HI (match_dup 1)))]
631   "TARGET_POWERPC"
632   "extsb. %0,%1"
633   [(set_attr "type" "compare")])
634
635 (define_expand "extendqihi2_power"
636   [(parallel [(set (match_dup 2)
637                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
638                               (const_int 24)))
639               (clobber (scratch:SI))])
640    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
641                    (ashiftrt:SI (match_dup 2)
642                                 (const_int 24)))
643               (clobber (scratch:SI))])]
644   "TARGET_POWER"
645   "
646 { operands[0] = gen_lowpart (SImode, operands[0]);
647   operands[1] = gen_lowpart (SImode, operands[1]);
648   operands[2] = gen_reg_rtx (SImode); }")
649
650 (define_expand "extendqihi2_no_power"
651   [(set (match_dup 2)
652         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
653                    (const_int 24)))
654    (set (match_operand:HI 0 "gpc_reg_operand" "")
655         (ashiftrt:SI (match_dup 2)
656                      (const_int 24)))]
657   "! TARGET_POWER && ! TARGET_POWERPC"
658   "
659 { operands[0] = gen_lowpart (SImode, operands[0]);
660   operands[1] = gen_lowpart (SImode, operands[1]);
661   operands[2] = gen_reg_rtx (SImode); }")
662
663 (define_expand "zero_extendhisi2"
664   [(set (match_operand:SI 0 "gpc_reg_operand" "")
665         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
666   ""
667   "")
668
669 (define_insn ""
670   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
671         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
672   ""
673   "@
674    lhz%U1%X1 %0,%1
675    {rlinm|rlwinm} %0,%1,0,0xffff"
676   [(set_attr "type" "load,*")])
677
678 (define_insn ""
679   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
680         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
681                     (const_int 0)))
682    (clobber (match_scratch:SI 2 "=r"))]
683   ""
684   "{andil.|andi.} %2,%1,0xffff"
685   [(set_attr "type" "compare")])
686
687 (define_insn ""
688   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
689         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
690                     (const_int 0)))
691    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
692         (zero_extend:SI (match_dup 1)))]
693   ""
694   "{andil.|andi.} %0,%1,0xffff"
695   [(set_attr "type" "compare")])
696
697 (define_expand "extendhisi2"
698   [(set (match_operand:SI 0 "gpc_reg_operand" "")
699         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
700   ""
701   "")
702
703 (define_insn ""
704   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
705         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
706   ""
707   "@
708    lha%U1%X1 %0,%1
709    {exts|extsh} %0,%1"
710   [(set_attr "type" "load,*")])
711
712 (define_insn ""
713   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
714         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
715                     (const_int 0)))
716    (clobber (match_scratch:SI 2 "=r"))]
717   ""
718   "{exts.|extsh.} %2,%1"
719   [(set_attr "type" "compare")])
720
721 (define_insn ""
722   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
723         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
724                     (const_int 0)))
725    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
726         (sign_extend:SI (match_dup 1)))]
727   ""
728   "{exts.|extsh.} %0,%1"
729   [(set_attr "type" "compare")])
730 \f
731 ;; Fixed-point arithmetic insns.
732
733 ;; Discourage ai/addic because of carry but provide it in an alternative
734 ;; allowing register zero as source.
735 (define_insn "addsi3"
736   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
737         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
738                  (match_operand:SI 2 "add_operand" "r,I,I,J")))]
739   ""
740   "@
741    {cax|add} %0,%1,%2
742    {cal %0,%2(%1)|addi %0,%1,%2}
743    {ai|addic} %0,%1,%2
744    {cau|addis} %0,%1,%u2")
745
746 (define_insn ""
747   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
748         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
749                              (match_operand:SI 2 "reg_or_short_operand" "r,I"))
750                     (const_int 0)))
751    (clobber (match_scratch:SI 3 "=r,r"))]
752   ""
753   "@
754    {cax.|add.} %3,%1,%2
755    {ai.|addic.} %3,%1,%2"
756   [(set_attr "type" "compare")])
757    
758 (define_insn ""
759   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
760         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
761                              (match_operand:SI 2 "reg_or_short_operand" "r,I"))
762                     (const_int 0)))
763    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
764         (plus:SI (match_dup 1) (match_dup 2)))]
765   ""
766   "@
767    {cax.|add.} %0,%1,%2
768    {ai.|addic.} %0,%1,%2"
769   [(set_attr "type" "compare")])
770    
771 ;; Split an add that we can't do in one insn into two insns, each of which
772 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
773 ;; add should be last in case the result gets used in an address.
774
775 (define_split
776   [(set (match_operand:SI 0 "gpc_reg_operand" "")
777         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
778                  (match_operand:SI 2 "non_add_cint_operand" "")))]
779   ""
780   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
781    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
782 "
783 {
784   int low = INTVAL (operands[2]) & 0xffff;
785   int high = (unsigned) INTVAL (operands[2]) >> 16;
786
787   if (low & 0x8000)
788     high++, low |= 0xffff0000;
789
790   operands[3] = gen_rtx (CONST_INT, VOIDmode, high << 16);
791   operands[4] = gen_rtx (CONST_INT, VOIDmode, low);
792 }")
793
794 (define_insn "one_cmplsi2"
795   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
796         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
797   ""
798   "nor %0,%1,%1")
799
800 (define_insn ""
801   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
802         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
803                     (const_int 0)))
804    (clobber (match_scratch:SI 2 "=r"))]
805   ""
806   "nor. %2,%1,%1"
807   [(set_attr "type" "compare")])
808
809 (define_insn ""
810   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
811         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
812                     (const_int 0)))
813    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
814         (not:SI (match_dup 1)))]
815   ""
816   "nor. %0,%2,%1"
817   [(set_attr "type" "compare")])
818
819 (define_insn ""
820   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
821         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
822                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
823   "! TARGET_POWERPC"
824   "{sf%I1|subf%I1c} %0,%2,%1")
825
826 (define_insn ""
827   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
828         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
829                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
830   "TARGET_POWERPC"
831   "@
832    subf %0,%2,%1
833    subfic %0,%2,%1")
834
835 (define_insn ""
836   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
837         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
838                               (match_operand:SI 2 "gpc_reg_operand" "r"))
839                     (const_int 0)))
840    (clobber (match_scratch:SI 3 "=r"))]
841   "! TARGET_POWERPC"
842   "{sf.|subfc.} %3,%2,%1"
843   [(set_attr "type" "compare")])
844
845 (define_insn ""
846   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
847         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
848                               (match_operand:SI 2 "gpc_reg_operand" "r"))
849                     (const_int 0)))
850    (clobber (match_scratch:SI 3 "=r"))]
851   "TARGET_POWERPC"
852   "subf. %3,%2,%1"
853   [(set_attr "type" "compare")])
854
855 (define_insn ""
856   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
857         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
858                               (match_operand:SI 2 "gpc_reg_operand" "r"))
859                     (const_int 0)))
860    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
861         (minus:SI (match_dup 1) (match_dup 2)))]
862   "! TARGET_POWERPC"
863   "{sf.|subfc.} %0,%2,%1"
864   [(set_attr "type" "compare")])
865
866 (define_insn ""
867   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
868         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
869                               (match_operand:SI 2 "gpc_reg_operand" "r"))
870                     (const_int 0)))
871    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
872         (minus:SI (match_dup 1) (match_dup 2)))]
873   "TARGET_POWERPC"
874   "subf. %0,%2,%1"
875   [(set_attr "type" "compare")])
876
877 (define_expand "subsi3"
878   [(set (match_operand:SI 0 "gpc_reg_operand" "")
879         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
880                   (match_operand:SI 2 "reg_or_cint_operand" "")))]
881   ""
882   "
883 {
884   if (GET_CODE (operands[2]) == CONST_INT)
885     {
886       emit_insn (gen_addsi3 (operands[0], operands[1],
887                              negate_rtx (SImode, operands[2])));
888       DONE;
889     }
890 }")
891
892 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
893 ;; instruction and some auxiliary computations.  Then we just have a single
894 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
895 ;; combine.
896
897 (define_expand "sminsi3"
898   [(set (match_dup 3)
899         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
900                                 (match_operand:SI 2 "reg_or_short_operand" ""))
901                          (const_int 0)
902                          (minus:SI (match_dup 2) (match_dup 1))))
903    (set (match_operand:SI 0 "gpc_reg_operand" "")
904         (minus:SI (match_dup 2) (match_dup 3)))]
905   "TARGET_POWER"
906   "
907 { operands[3] = gen_reg_rtx (SImode); }")
908
909 (define_split
910   [(set (match_operand:SI 0 "gpc_reg_operand" "")
911         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
912                  (match_operand:SI 2 "reg_or_short_operand" "")))
913    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
914   "TARGET_POWER"
915   [(set (match_dup 3)
916         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
917                          (const_int 0)
918                          (minus:SI (match_dup 2) (match_dup 1))))
919    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
920   "")
921
922 (define_expand "smaxsi3"
923   [(set (match_dup 3)
924         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
925                                 (match_operand:SI 2 "reg_or_short_operand" ""))
926                          (const_int 0)
927                          (minus:SI (match_dup 2) (match_dup 1))))
928    (set (match_operand:SI 0 "gpc_reg_operand" "")
929         (plus:SI (match_dup 3) (match_dup 1)))]
930   "TARGET_POWER"
931   "
932 { operands[3] = gen_reg_rtx (SImode); }")
933
934 (define_split
935   [(set (match_operand:SI 0 "gpc_reg_operand" "")
936         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
937                  (match_operand:SI 2 "reg_or_short_operand" "")))
938    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
939   "TARGET_POWER"
940   [(set (match_dup 3)
941         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
942                          (const_int 0)
943                          (minus:SI (match_dup 2) (match_dup 1))))
944    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
945   "")
946
947 (define_expand "uminsi3"
948   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
949                               (match_dup 5)))
950    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
951                               (match_dup 5)))
952    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
953                                        (const_int 0)
954                                        (minus:SI (match_dup 4) (match_dup 3))))
955    (set (match_operand:SI 0 "gpc_reg_operand" "")
956         (minus:SI (match_dup 2) (match_dup 3)))]
957   "TARGET_POWER"
958   "
959 {
960   operands[3] = gen_reg_rtx (SImode);
961   operands[4] = gen_reg_rtx (SImode);
962   operands[5] = GEN_INT (-2147483647 - 1);
963 }")
964
965 (define_expand "umaxsi3"
966   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
967                               (match_dup 5)))
968    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
969                               (match_dup 5)))
970    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
971                                        (const_int 0)
972                                        (minus:SI (match_dup 4) (match_dup 3))))
973    (set (match_operand:SI 0 "gpc_reg_operand" "")
974         (plus:SI (match_dup 3) (match_dup 1)))]
975   "TARGET_POWER"
976   "
977 {
978   operands[3] = gen_reg_rtx (SImode);
979   operands[4] = gen_reg_rtx (SImode);
980   operands[5] = GEN_INT (-2147483647 - 1);
981 }")
982
983 (define_insn ""
984   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
985         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
986                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
987                          (const_int 0)
988                          (minus:SI (match_dup 2) (match_dup 1))))]
989   "TARGET_POWER"
990   "doz%I2 %0,%1,%2")
991
992 (define_insn ""
993   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
994         (compare:CC
995          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
996                               (match_operand:SI 2 "reg_or_short_operand" "rI"))
997                           (const_int 0)
998                           (minus:SI (match_dup 2) (match_dup 1)))
999          (const_int 0)))
1000    (clobber (match_scratch:SI 3 "=r"))]
1001   "TARGET_POWER"
1002   "doz%I2. %3,%1,%2"
1003   [(set_attr "type" "delayed_compare")])
1004
1005 (define_insn ""
1006   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1007         (compare:CC
1008          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1009                               (match_operand:SI 2 "reg_or_short_operand" "rI"))
1010                           (const_int 0)
1011                           (minus:SI (match_dup 2) (match_dup 1)))
1012          (const_int 0)))
1013    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1014         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1015                          (const_int 0)
1016                          (minus:SI (match_dup 2) (match_dup 1))))]
1017   "TARGET_POWER"
1018   "doz%I2. %0,%1,%2"
1019   [(set_attr "type" "delayed_compare")])
1020
1021 ;; We don't need abs with condition code because such comparisons should
1022 ;; never be done.
1023 (define_expand "abssi2"
1024   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1025         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1026   ""
1027   "
1028 {
1029   if (!TARGET_POWER)
1030     {
1031       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1032       DONE;
1033     }
1034 }")
1035
1036 (define_insn "abssi2_power"
1037   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1038         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1039   "TARGET_POWER"
1040   "abs %0,%1")
1041
1042 (define_insn "abssi2_nopower"
1043   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1044         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1045    (clobber (match_scratch:SI 2 "=&r,&r"))]
1046   "!TARGET_POWER"
1047   "{srai|srawi} %2,%1,31\;xor %0,%2,%1\;subf %0,%2,%0"
1048   [(set_attr "length" "12")])
1049
1050 (define_split
1051   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1052         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1053    (clobber (match_scratch:SI 2 "=&r,&r"))]
1054   "!TARGET_POWER && reload_completed"
1055   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1056    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1057    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1058   "")
1059
1060 (define_insn ""
1061   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1062         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1063   "TARGET_POWER"
1064   "nabs %0,%1")
1065
1066 (define_insn ""
1067   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1068         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1069    (clobber (match_scratch:SI 2 "=&r,&r"))]
1070   "!TARGET_POWER"
1071   "{srai|srawi} %2,%1,31\;xor %0,%2,%1\;subf %0,%0,%2"
1072   [(set_attr "length" "12")])
1073
1074 (define_split
1075   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1076         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1077    (clobber (match_scratch:SI 2 "=&r,&r"))]
1078   "!TARGET_POWER && reload_completed"
1079   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1080    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1081    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1082   "")
1083
1084 (define_insn "negsi2"
1085   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1086         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1087   ""
1088   "neg %0,%1")
1089
1090 (define_insn ""
1091   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1092         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1093                     (const_int 0)))
1094    (clobber (match_scratch:SI 2 "=r"))]
1095   ""
1096   "neg. %2,%1"
1097   [(set_attr "type" "compare")])
1098
1099 (define_insn ""
1100   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
1101         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1102                     (const_int 0)))
1103    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1104         (neg:SI (match_dup 1)))]
1105   ""
1106   "neg. %0,%1"
1107   [(set_attr "type" "compare")])
1108
1109 (define_insn "ffssi2"
1110   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
1111         (ffs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1112   ""
1113   "neg %0,%1\;and %0,%0,%1\;{cntlz|cntlzw} %0,%0\;{sfi|subfic} %0,%0,32"
1114   [(set_attr "length" "16")])
1115
1116 (define_expand "mulsi3"
1117   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1118    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1119    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1120   ""
1121   "
1122 {
1123   if (TARGET_POWER)
1124     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1125   else
1126     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1127   DONE;
1128 }")
1129
1130 (define_insn "mulsi3_mq"
1131   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1132         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1133                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1134    (clobber (match_scratch:SI 3 "=q,q"))]
1135   "TARGET_POWER"
1136   "@
1137    {muls|mullw} %0,%1,%2
1138    {muli|mulli} %0,%1,%2"
1139    [(set_attr "type" "imul")])
1140
1141 (define_insn "mulsi3_no_mq"
1142   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1143         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1144                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1145   "! TARGET_POWER"
1146   "@
1147    mullw %0,%1,%2
1148    mulli %0,%1,%2"
1149    [(set_attr "type" "imul")])
1150
1151 (define_insn ""
1152   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1153         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1154                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1155                     (const_int 0)))
1156    (clobber (match_scratch:SI 3 "=r"))
1157    (clobber (match_scratch:SI 4 "=q"))]
1158   "TARGET_POWER"
1159   "{muls.|mullw.} %3,%1,%2"
1160   [(set_attr "type" "delayed_compare")])
1161
1162 (define_insn ""
1163   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1164         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1165                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1166                     (const_int 0)))
1167    (clobber (match_scratch:SI 3 "=r"))]
1168   "! TARGET_POWER"
1169   "mullw. %3,%1,%2"
1170   [(set_attr "type" "delayed_compare")])
1171
1172 (define_insn ""
1173   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1174         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1175                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1176                     (const_int 0)))
1177    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1178         (mult:SI (match_dup 1) (match_dup 2)))
1179    (clobber (match_scratch:SI 4 "=q"))]
1180   "TARGET_POWER"
1181   "{muls.|mullw.} %0,%1,%2"
1182   [(set_attr "type" "delayed_compare")])
1183
1184 (define_insn ""
1185   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1186         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1187                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1188                     (const_int 0)))
1189    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1190         (mult:SI (match_dup 1) (match_dup 2)))]
1191   "! TARGET_POWER"
1192   "mullw. %0,%1,%2"
1193   [(set_attr "type" "delayed_compare")])
1194
1195 ;; Operand 1 is divided by operand 2; quotient goes to operand
1196 ;; 0 and remainder to operand 3.
1197 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1198
1199 (define_expand "divmodsi4"
1200   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1201                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1202                            (match_operand:SI 2 "gpc_reg_operand" "")))
1203               (set (match_operand:SI 3 "gpc_reg_operand" "")
1204                    (mod:SI (match_dup 1) (match_dup 2)))])]
1205   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1206   "
1207 {
1208   if (! TARGET_POWER && ! TARGET_POWERPC)
1209     {
1210       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1211       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1212       emit_insn (gen_divss_call ());
1213       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1214       emit_move_insn (operands[3], gen_rtx (REG, SImode, 4));
1215       DONE;
1216     }
1217 }")
1218
1219 (define_insn ""
1220   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1221         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1222                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1223    (set (match_operand:SI 3 "gpc_reg_operand" "=q")
1224         (mod:SI (match_dup 1) (match_dup 2)))]
1225   "TARGET_POWER"
1226   "divs %0,%1,%2"
1227   [(set_attr "type" "idiv")])
1228
1229 (define_insn ""
1230   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1231         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1232                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1233   "TARGET_POWERPC"
1234   "divw %0,%1,%2"
1235   [(set_attr "type" "idiv")])
1236
1237 (define_expand "udivsi3"
1238   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1239         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1240                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1241   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1242   "
1243 {
1244   if (! TARGET_POWER && ! TARGET_POWERPC)
1245     {
1246       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1247       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1248       emit_insn (gen_quous_call ());
1249       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1250       DONE;
1251     }
1252 }")
1253
1254 (define_insn ""
1255   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1256         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1257                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1258   "TARGET_POWERPC"
1259   "divwu %0,%1,%2"
1260   [(set_attr "type" "idiv")])
1261
1262 ;; For powers of two we can do srai/aze for divide and then adjust for
1263 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1264 ;; used; for PowerPC, force operands into register and do a normal divide;
1265 ;; for AIX common-mode, use quoss call on register operands.
1266 (define_expand "divsi3"
1267   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1268         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1269                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1270   ""
1271   "
1272 {
1273   if (GET_CODE (operands[2]) == CONST_INT
1274       && exact_log2 (INTVAL (operands[2])) >= 0)
1275     ;
1276   else if (TARGET_POWER && ! TARGET_POWERPC)
1277     FAIL;
1278   else
1279     operands[2] = force_reg (SImode, operands[2]);
1280
1281   if (! TARGET_POWER && ! TARGET_POWERPC)
1282     {
1283       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1284       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1285       emit_insn (gen_quoss_call ());
1286       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1287       DONE;
1288     }
1289 }")
1290
1291 (define_expand "modsi3"
1292   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1293    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1294    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
1295   ""
1296   "
1297 {
1298   int i = exact_log2 (INTVAL (operands[2]));
1299   rtx temp1;
1300   rtx temp2;
1301
1302   if (GET_CODE (operands[2]) != CONST_INT || i < 0)
1303     FAIL;
1304
1305   temp1 = gen_reg_rtx (SImode);
1306   temp2 = gen_reg_rtx (SImode);
1307
1308   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
1309   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
1310   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
1311   DONE;
1312 }")
1313
1314 (define_insn ""
1315   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1316         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1317                 (match_operand:SI 2 "const_int_operand" "N")))]
1318   "exact_log2 (INTVAL (operands[2])) >= 0"
1319   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
1320   [(set_attr "length" "8")])
1321
1322 (define_insn ""
1323   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1324         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1325                             (match_operand:SI 2 "const_int_operand" "N"))
1326                     (const_int 0)))
1327    (clobber (match_scratch:SI 3 "=r"))]
1328   "exact_log2 (INTVAL (operands[2])) >= 0"
1329   "{srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3"
1330   [(set_attr "type" "compare")
1331    (set_attr "length" "8")])
1332
1333 (define_insn ""
1334   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1335         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1336                             (match_operand:SI 2 "const_int_operand" "N"))
1337                     (const_int 0)))
1338    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1339         (div:SI (match_dup 1) (match_dup 2)))]
1340   "exact_log2 (INTVAL (operands[2])) >= 0"
1341   "{srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0"
1342   [(set_attr "type" "compare")
1343    (set_attr "length" "8")])
1344
1345 (define_insn ""
1346   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1347         (udiv:SI
1348          (plus:DI (ashift:DI
1349                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
1350                    (const_int 32))
1351                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
1352          (match_operand:SI 3 "gpc_reg_operand" "r")))
1353    (set (match_operand:SI 2 "register_operand" "=*q")
1354         (umod:SI
1355          (plus:DI (ashift:DI
1356                    (zero_extend:DI (match_dup 1)) (const_int 32))
1357                   (zero_extend:DI (match_dup 4)))
1358          (match_dup 3)))]
1359   "TARGET_POWER"
1360   "div %0,%1,%3"
1361   [(set_attr "type" "idiv")])
1362
1363 ;; To do unsigned divide we handle the cases of the divisor looking like a
1364 ;; negative number.  If it is a constant that is less than 2**31, we don't
1365 ;; have to worry about the branches.  So make a few subroutines here.
1366 ;;
1367 ;; First comes the normal case.
1368 (define_expand "udivmodsi4_normal"
1369   [(set (match_dup 4) (const_int 0))
1370    (parallel [(set (match_operand:SI 0 "" "")
1371                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
1372                                                 (const_int 32))
1373                                      (zero_extend:DI (match_operand:SI 1 "" "")))
1374                             (match_operand:SI 2 "" "")))
1375               (set (match_operand:SI 3 "" "")
1376                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
1377                                                 (const_int 32))
1378                                      (zero_extend:DI (match_dup 1)))
1379                             (match_dup 2)))])]
1380   "TARGET_POWER"
1381   "
1382 { operands[4] = gen_reg_rtx (SImode); }")
1383
1384 ;; This handles the branches.
1385 (define_expand "udivmodsi4_tests"
1386   [(set (match_operand:SI 0 "" "") (const_int 0))
1387    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
1388    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
1389    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
1390                            (label_ref (match_operand:SI 4 "" "")) (pc)))
1391    (set (match_dup 0) (const_int 1))
1392    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
1393    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
1394    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
1395                            (label_ref (match_dup 4)) (pc)))]
1396   "TARGET_POWER"
1397   "
1398 { operands[5] = gen_reg_rtx (CCUNSmode);
1399   operands[6] = gen_reg_rtx (CCmode);
1400 }")
1401
1402 (define_expand "udivmodsi4"
1403   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1404                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1405                             (match_operand:SI 2 "reg_or_cint_operand" "")))
1406               (set (match_operand:SI 3 "gpc_reg_operand" "")
1407                    (umod:SI (match_dup 1) (match_dup 2)))])]
1408   ""
1409   "
1410 {
1411   rtx label = 0;
1412
1413   if (! TARGET_POWER)
1414     if (! TARGET_POWERPC)
1415       {
1416         emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1417         emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1418         emit_insn (gen_divus_call ());
1419         emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1420         emit_move_insn (operands[3], gen_rtx (REG, SImode, 4));
1421         DONE;
1422       }
1423     else
1424       FAIL;
1425
1426   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
1427     {
1428       operands[2] = force_reg (SImode, operands[2]);
1429       label = gen_label_rtx ();
1430       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
1431                                   operands[3], label));
1432     }
1433   else
1434     operands[2] = force_reg (SImode, operands[2]);
1435
1436   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
1437                                operands[3]));
1438   if (label)
1439     emit_label (label);
1440
1441   DONE;
1442 }")
1443
1444 ;; AIX architecture-independent common-mode multiply (DImode),
1445 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
1446 ;; R4; results in R3 and somtimes R4; link register always clobbered by bla
1447 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
1448 ;; assumed unused if generating common-mode, so ignore.
1449 (define_insn "mulh_call"
1450   [(set (reg:SI 3)
1451         (truncate:SI
1452          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
1453                                (sign_extend:DI (reg:SI 4)))
1454                       (const_int 32))))
1455    (clobber (match_scratch:SI 0 "=l"))]
1456   "! TARGET_POWER && ! TARGET_POWERPC"
1457   "bla __mulh")
1458
1459 (define_insn "mull_call"
1460   [(set (reg:DI 3)
1461         (mult:DI (sign_extend:DI (reg:SI 3))
1462                  (sign_extend:DI (reg:SI 4))))
1463    (clobber (match_scratch:SI 0 "=l"))
1464    (clobber (reg:SI 0))]
1465   "! TARGET_POWER && ! TARGET_POWERPC"
1466   "bla __mull")
1467
1468 (define_insn "divss_call"
1469   [(set (reg:SI 3)
1470         (div:SI (reg:SI 3) (reg:SI 4)))
1471    (set (reg:SI 4)
1472         (mod:SI (reg:SI 3) (reg:SI 4)))
1473    (clobber (match_scratch:SI 0 "=l"))
1474    (clobber (reg:SI 0))]
1475   "! TARGET_POWER && ! TARGET_POWERPC"
1476   "bla __divss")
1477
1478 (define_insn "divus_call"
1479   [(set (reg:SI 3)
1480         (udiv:SI (reg:SI 3) (reg:SI 4)))
1481    (set (reg:SI 4)
1482         (umod:SI (reg:SI 3) (reg:SI 4)))
1483    (clobber (match_scratch:SI 0 "=l"))
1484    (clobber (reg:SI 0))]
1485   "! TARGET_POWER && ! TARGET_POWERPC"
1486   "bla __divus")
1487
1488 (define_insn "quoss_call"
1489   [(set (reg:SI 3)
1490         (div:SI (reg:SI 3) (reg:SI 4)))
1491    (clobber (match_scratch:SI 0 "=l"))]
1492   "! TARGET_POWER && ! TARGET_POWERPC"
1493   "bla __quoss")
1494
1495 (define_insn "quous_call"
1496   [(set (reg:SI 3)
1497         (udiv:SI (reg:SI 3) (reg:SI 4)))
1498    (clobber (match_scratch:SI 0 "=l"))
1499    (clobber (reg:SI 0))]
1500   "! TARGET_POWER && ! TARGET_POWERPC"
1501   "bla __quous")
1502 \f
1503 (define_insn "andsi3"
1504   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1505         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1506                 (match_operand:SI 2 "and_operand" "?r,L,K,J")))
1507    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
1508   ""
1509   "@
1510    and %0,%1,%2
1511    {rlinm|rlwinm} %0,%1,0,%m2,%M2
1512    {andil.|andi.} %0,%1,%b2
1513    {andiu.|andis.} %0,%1,%u2")
1514
1515 (define_insn ""
1516   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x")
1517         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1518                             (match_operand:SI 2 "and_operand" "r,K,J,L"))
1519                     (const_int 0)))
1520    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1521   ""
1522   "@
1523    and. %3,%1,%2
1524    {andil.|andi.} %3,%1,%b2
1525    {andiu.|andis.} %3,%1,%u2
1526    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2"
1527   [(set_attr "type" "compare,compare,compare,delayed_compare")])
1528
1529 (define_insn ""
1530   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x")
1531         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1532                             (match_operand:SI 2 "and_operand" "r,K,J,L"))
1533                     (const_int 0)))
1534    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1535         (and:SI (match_dup 1) (match_dup 2)))]
1536   ""
1537   "@
1538    and. %0,%1,%2
1539    {andil.|andi.} %0,%1,%b2
1540    {andiu.|andis.} %0,%1,%u2
1541    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2"
1542   [(set_attr "type" "compare,compare,compare,delayed_compare")])
1543
1544 ;; Take a AND with a constant that cannot be done in a single insn and try to
1545 ;; split it into two insns.  This does not verify that the insns are valid
1546 ;; since this need not be done as combine will do it.
1547
1548 (define_split
1549   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1550         (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
1551                 (match_operand:SI 2 "non_and_cint_operand" "")))]
1552   ""
1553   [(set (match_dup 0) (and:SI (match_dup 1) (match_dup 3)))
1554    (set (match_dup 0) (and:SI (match_dup 0) (match_dup 4)))]
1555   "
1556 {
1557   int maskval = INTVAL (operands[2]);
1558   int i, transitions, last_bit_value;
1559   int orig = maskval, first_c = maskval, second_c;
1560
1561   /* We know that MASKVAL must have more than 2 bit-transitions.  Start at
1562      the low-order bit and count for the third transition.  When we get there,
1563      make a first mask that has everything to the left of that position
1564      a one.  Then make the second mask to turn off whatever else is needed.  */
1565
1566   for (i = 1, transitions = 0, last_bit_value = maskval & 1; i < 32; i++)
1567     {
1568       if (((maskval >>= 1) & 1) != last_bit_value)
1569         last_bit_value ^= 1, transitions++;
1570
1571       if (transitions > 2)
1572         {
1573           first_c |= (~0) << i;
1574           break;
1575         }
1576     }
1577
1578   second_c = orig | ~ first_c;
1579
1580   operands[3] = gen_rtx (CONST_INT, VOIDmode, first_c);
1581   operands[4] = gen_rtx (CONST_INT, VOIDmode, second_c);
1582 }")
1583
1584 (define_insn "iorsi3"
1585   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
1586         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
1587                 (match_operand:SI 2 "logical_operand" "r,K,J")))]
1588   ""
1589   "@
1590    or %0,%1,%2
1591    {oril|ori} %0,%1,%b2
1592    {oriu|oris} %0,%1,%u2")
1593
1594 (define_insn ""
1595   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1596         (compare:CC (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1597                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1598                     (const_int 0)))
1599    (clobber (match_scratch:SI 3 "=r"))]
1600   ""
1601   "or. %3,%1,%2"
1602   [(set_attr "type" "compare")])
1603
1604 (define_insn ""
1605   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1606         (compare:CC (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1607                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1608                     (const_int 0)))
1609    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1610         (ior:SI (match_dup 1) (match_dup 2)))]
1611   ""
1612   "or. %0,%1,%2"
1613   [(set_attr "type" "compare")])
1614
1615 ;; Split an IOR that we can't do in one insn into two insns, each of which
1616 ;; does one 16-bit part.  This is used by combine.
1617
1618 (define_split
1619   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1620         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
1621                 (match_operand:SI 2 "non_logical_cint_operand" "")))]
1622   ""
1623   [(set (match_dup 0) (ior:SI (match_dup 1) (match_dup 3)))
1624    (set (match_dup 0) (ior:SI (match_dup 0) (match_dup 4)))]
1625 "
1626 {
1627   operands[3] = gen_rtx (CONST_INT, VOIDmode,
1628                          INTVAL (operands[2]) & 0xffff0000);
1629   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
1630 }")
1631
1632 (define_insn "xorsi3"
1633   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
1634         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
1635                 (match_operand:SI 2 "logical_operand" "r,K,J")))]
1636   ""
1637   "@
1638    xor %0,%1,%2
1639    {xoril|xori} %0,%1,%b2
1640    {xoriu|xoris} %0,%1,%u2")
1641
1642 (define_insn ""
1643   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1644         (compare:CC (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1645                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1646                     (const_int 0)))
1647    (clobber (match_scratch:SI 3 "=r"))]
1648   ""
1649   "xor. %3,%1,%2"
1650   [(set_attr "type" "compare")])
1651
1652 (define_insn ""
1653   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1654         (compare:CC (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1655                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1656                     (const_int 0)))
1657    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1658         (xor:SI (match_dup 1) (match_dup 2)))]
1659   ""
1660   "xor. %0,%1,%2"
1661   [(set_attr "type" "compare")])
1662
1663 ;; Split an XOR that we can't do in one insn into two insns, each of which
1664 ;; does one 16-bit part.  This is used by combine.
1665
1666 (define_split
1667   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1668         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1669                 (match_operand:SI 2 "non_logical_cint_operand" "")))]
1670   ""
1671   [(set (match_dup 0) (xor:SI (match_dup 1) (match_dup 3)))
1672    (set (match_dup 0) (xor:SI (match_dup 0) (match_dup 4)))]
1673 "
1674 {
1675   operands[3] = gen_rtx (CONST_INT, VOIDmode,
1676                          INTVAL (operands[2]) & 0xffff0000);
1677   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
1678 }")
1679
1680 (define_insn ""
1681   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1682         (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1683                         (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1684    ""
1685    "eqv %0,%1,%2")
1686
1687 (define_insn ""
1688   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1689         (compare:CC (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1690                                     (match_operand:SI 2 "gpc_reg_operand" "r")))
1691                     (const_int 0)))
1692    (clobber (match_scratch:SI 3 "=r"))]
1693    ""
1694    "eqv. %3,%1,%2"
1695    [(set_attr "type" "compare")])
1696
1697 (define_insn ""
1698   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1699         (compare:CC (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1700                                     (match_operand:SI 2 "gpc_reg_operand" "r")))
1701                     (const_int 0)))
1702    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1703         (not:SI (xor:SI (match_dup 1) (match_dup 2))))]
1704    ""
1705    "eqv. %0,%1,%2"
1706    [(set_attr "type" "compare")])
1707
1708 (define_insn ""
1709   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1710         (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1711                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1712   ""
1713   "andc %0,%2,%1")
1714
1715 (define_insn ""
1716   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1717         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1718                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1719                     (const_int 0)))
1720    (clobber (match_scratch:SI 3 "=r"))]
1721   ""
1722   "andc. %3,%2,%1"
1723   [(set_attr "type" "compare")])
1724
1725 (define_insn ""
1726   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1727         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1728                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1729                     (const_int 0)))
1730    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1731         (and:SI (not:SI (match_dup 1)) (match_dup 2)))]
1732   ""
1733   "andc. %0,%2,%1"
1734   [(set_attr "type" "compare")])
1735
1736 (define_insn ""
1737   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1738         (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1739                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1740   ""
1741   "orc %0,%2,%1")
1742
1743 (define_insn ""
1744   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1745         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1746                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1747                     (const_int 0)))
1748    (clobber (match_scratch:SI 3 "=r"))]
1749   ""
1750   "orc. %3,%2,%1"
1751   [(set_attr "type" "compare")])
1752
1753 (define_insn ""
1754   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1755         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1756                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1757                     (const_int 0)))
1758    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1759         (ior:SI (not:SI (match_dup 1)) (match_dup 2)))]
1760   ""
1761   "orc. %0,%2,%1"
1762   [(set_attr "type" "compare")])
1763
1764 (define_insn ""
1765   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1766         (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1767                 (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1768   ""
1769   "nand %0,%1,%2")
1770
1771 (define_insn ""
1772   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1773         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1774                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1775                     (const_int 0)))
1776    (clobber (match_scratch:SI 3 "=r"))]
1777   ""
1778   "nand. %3,%1,%2"
1779   [(set_attr "type" "compare")])
1780
1781 (define_insn ""
1782   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1783         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1784                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1785                     (const_int 0)))
1786    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1787         (ior:SI (not:SI (match_dup 1)) (not:SI (match_dup 2))))]
1788   ""
1789   "nand. %0,%1,%2"
1790   [(set_attr "type" "compare")])
1791
1792 (define_insn ""
1793   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1794         (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1795                 (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1796   ""
1797   "nor %0,%1,%2")
1798
1799 (define_insn ""
1800   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1801         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1802                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1803                     (const_int 0)))
1804    (clobber (match_scratch:SI 3 "=r"))]
1805   ""
1806   "nor. %3,%1,%2"
1807   [(set_attr "type" "compare")])
1808
1809 (define_insn ""
1810   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1811         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1812                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1813                     (const_int 0)))
1814    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1815         (and:SI (not:SI (match_dup 1)) (not:SI (match_dup 2))))]
1816   ""
1817   "nor. %0,%1,%2"
1818   [(set_attr "type" "compare")])
1819
1820 ;; maskir insn.  We need four forms because things might be in arbitrary
1821 ;; orders.  Don't define forms that only set CR fields because these
1822 ;; would modify an input register.
1823
1824 (define_insn ""
1825   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1826         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1827                         (match_operand:SI 1 "gpc_reg_operand" "0"))
1828                 (and:SI (match_dup 2)
1829                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
1830   "TARGET_POWER"
1831   "maskir %0,%3,%2")
1832
1833 (define_insn ""
1834   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1835         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1836                         (match_operand:SI 1 "gpc_reg_operand" "0"))
1837                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1838                         (match_dup 2))))]
1839   "TARGET_POWER"
1840   "maskir %0,%3,%2")
1841
1842 (define_insn ""
1843   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1844         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
1845                         (match_operand:SI 3 "gpc_reg_operand" "r"))
1846                 (and:SI (not:SI (match_dup 2))
1847                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
1848   "TARGET_POWER"
1849   "maskir %0,%3,%2")
1850
1851 (define_insn ""
1852   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1853         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1854                         (match_operand:SI 2 "gpc_reg_operand" "r"))
1855                 (and:SI (not:SI (match_dup 2))
1856                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
1857   "TARGET_POWER"
1858   "maskir %0,%3,%2")
1859
1860 (define_insn ""
1861   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
1862         (compare:CC
1863          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1864                          (match_operand:SI 1 "gpc_reg_operand" "0"))
1865                  (and:SI (match_dup 2)
1866                          (match_operand:SI 3 "gpc_reg_operand" "r")))
1867          (const_int 0)))
1868    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1869         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
1870                 (and:SI (match_dup 2) (match_dup 3))))]
1871   "TARGET_POWER"
1872   "maskir. %0,%3,%2"
1873   [(set_attr "type" "compare")])
1874
1875 (define_insn ""
1876   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
1877         (compare:CC
1878          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1879                          (match_operand:SI 1 "gpc_reg_operand" "0"))
1880                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1881                          (match_dup 2)))
1882          (const_int 0)))
1883    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1884         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
1885                 (and:SI (match_dup 3) (match_dup 2))))]
1886   "TARGET_POWER"
1887   "maskir. %0,%3,%2"
1888   [(set_attr "type" "compare")])
1889
1890 (define_insn ""
1891   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
1892         (compare:CC
1893          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
1894                          (match_operand:SI 3 "gpc_reg_operand" "r"))
1895                  (and:SI (not:SI (match_dup 2))
1896                          (match_operand:SI 1 "gpc_reg_operand" "0")))
1897          (const_int 0)))
1898    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1899         (ior:SI (and:SI (match_dup 2) (match_dup 3))
1900                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
1901   "TARGET_POWER"
1902   "maskir. %0,%3,%2"
1903   [(set_attr "type" "compare")])
1904
1905 (define_insn ""
1906   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
1907         (compare:CC
1908          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1909                          (match_operand:SI 2 "gpc_reg_operand" "r"))
1910                  (and:SI (not:SI (match_dup 2))
1911                          (match_operand:SI 1 "gpc_reg_operand" "0")))
1912          (const_int 0)))
1913    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1914         (ior:SI (and:SI (match_dup 3) (match_dup 2))
1915                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
1916   "TARGET_POWER"
1917   "maskir. %0,%3,%2"
1918   [(set_attr "type" "compare")])
1919 \f
1920 ;; Rotate and shift insns, in all their variants.  These support shifts,
1921 ;; field inserts and extracts, and various combinations thereof.
1922 (define_insn "insv"
1923   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
1924                          (match_operand:SI 1 "const_int_operand" "i")
1925                          (match_operand:SI 2 "const_int_operand" "i"))
1926         (match_operand:SI 3 "gpc_reg_operand" "r"))]
1927   ""
1928   "*
1929 {
1930   int start = INTVAL (operands[2]) & 31;
1931   int size = INTVAL (operands[1]) & 31;
1932
1933   operands[4] = gen_rtx (CONST_INT, VOIDmode, 32 - start - size);
1934   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
1935   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
1936 }")
1937
1938 (define_insn ""
1939   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
1940                          (match_operand:SI 1 "const_int_operand" "i")
1941                          (match_operand:SI 2 "const_int_operand" "i"))
1942         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1943                    (match_operand:SI 4 "const_int_operand" "i")))]
1944   ""
1945   "*
1946 {
1947   int shift = INTVAL (operands[4]) & 31;
1948   int start = INTVAL (operands[2]) & 31;
1949   int size = INTVAL (operands[1]) & 31;
1950
1951   operands[4] = gen_rtx (CONST_INT, VOIDmode, (shift - start - size) & 31);
1952   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
1953   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
1954 }")
1955
1956 (define_insn ""
1957   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
1958                          (match_operand:SI 1 "const_int_operand" "i")
1959                          (match_operand:SI 2 "const_int_operand" "i"))
1960         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1961                      (match_operand:SI 4 "const_int_operand" "i")))]
1962   ""
1963   "*
1964 {
1965   int shift = INTVAL (operands[4]) & 31;
1966   int start = INTVAL (operands[2]) & 31;
1967   int size = INTVAL (operands[1]) & 31;
1968
1969   operands[4] = gen_rtx (CONST_INT, VOIDmode, (32 - shift - start - size) & 31);
1970   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
1971   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
1972 }")
1973
1974 (define_insn ""
1975   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
1976                          (match_operand:SI 1 "const_int_operand" "i")
1977                          (match_operand:SI 2 "const_int_operand" "i"))
1978         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1979                      (match_operand:SI 4 "const_int_operand" "i")))]
1980   ""
1981   "*
1982 {
1983   int shift = INTVAL (operands[4]) & 31;
1984   int start = INTVAL (operands[2]) & 31;
1985   int size = INTVAL (operands[1]) & 31;
1986
1987   operands[4] = gen_rtx (CONST_INT, VOIDmode, (32 - shift - start - size) & 31);
1988   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
1989   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
1990 }")
1991
1992 (define_insn ""
1993   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
1994                          (match_operand:SI 1 "const_int_operand" "i")
1995                          (match_operand:SI 2 "const_int_operand" "i"))
1996         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1997                          (match_operand:SI 4 "const_int_operand" "i")
1998                          (match_operand:SI 5 "const_int_operand" "i")))]
1999   "INTVAL (operands[4]) >= INTVAL (operands[1])"
2000   "*
2001 {
2002   int extract_start = INTVAL (operands[5]) & 31;
2003   int extract_size = INTVAL (operands[4]) & 31;
2004   int insert_start = INTVAL (operands[2]) & 31;
2005   int insert_size = INTVAL (operands[1]) & 31;
2006
2007 /* Align extract field with insert field */
2008   operands[5] = gen_rtx (CONST_INT, VOIDmode,
2009                          (extract_start + extract_size - insert_start - insert_size) & 31);
2010   operands[1] = gen_rtx (CONST_INT, VOIDmode, insert_start + insert_size - 1);
2011   return \"{rlimi|rlwimi} %0,%3,%5,%h2,%h1\";
2012 }")
2013
2014 (define_insn "extzv"
2015   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2016         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2017                          (match_operand:SI 2 "const_int_operand" "i")
2018                          (match_operand:SI 3 "const_int_operand" "i")))]
2019   ""
2020   "*
2021 {
2022   int start = INTVAL (operands[3]) & 31;
2023   int size = INTVAL (operands[2]) & 31;
2024
2025   if (start + size >= 32)
2026     operands[3] = const0_rtx;
2027   else
2028     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2029   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
2030 }")
2031
2032 (define_insn ""
2033   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2034         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2035                          (match_operand:SI 2 "const_int_operand" "i")
2036                          (match_operand:SI 3 "const_int_operand" "i"))
2037                     (const_int 0)))
2038    (clobber (match_scratch:SI 4 "=r"))]
2039   ""
2040   "*
2041 {
2042   int start = INTVAL (operands[3]) & 31;
2043   int size = INTVAL (operands[2]) & 31;
2044
2045   /* If the bitfield being tested fits in the upper or lower half of a
2046      word, it is possible to use andiu. or andil. to test it.  This is
2047      useful because the condition register set-use delay is smaller for
2048      andi[ul]. than for rlinm.  This doesn't work when the starting bit
2049      position is 0 because the LT and GT bits may be set wrong.  */
2050
2051   if ((start > 0 && start + size <= 16) || start >= 16)
2052     {
2053       operands[3] = gen_rtx (CONST_INT, VOIDmode,
2054                              ((1 << (16 - (start & 15)))
2055                               - (1 << (16 - (start & 15) - size))));
2056       if (start < 16)
2057         return \"{andiu.|andis.} %4,%1,%3\";
2058       else
2059         return \"{andil.|andi.} %4,%1,%3\";
2060     }
2061   
2062   if (start + size >= 32)
2063     operands[3] = const0_rtx;
2064   else
2065     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2066   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
2067 }"
2068   [(set_attr "type" "compare")])
2069
2070 (define_insn ""
2071   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2072         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2073                          (match_operand:SI 2 "const_int_operand" "i")
2074                          (match_operand:SI 3 "const_int_operand" "i"))
2075                     (const_int 0)))
2076    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2077         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
2078   ""
2079   "*
2080 {
2081   int start = INTVAL (operands[3]) & 31;
2082   int size = INTVAL (operands[2]) & 31;
2083
2084   if (start >= 16 && start + size == 32)
2085     {
2086       operands[3] = gen_rtx (CONST_INT, VOIDmode, (1 << (32 - start)) - 1);
2087       return \"{andil.|andi.} %0,%1,%3\";
2088     }
2089   
2090   if (start + size >= 32)
2091     operands[3] = const0_rtx;
2092   else
2093     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2094   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
2095 }"
2096   [(set_attr "type" "delayed_compare")])
2097
2098 (define_insn "rotlsi3"
2099   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2100         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2101                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2102   ""
2103   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
2104
2105 (define_insn ""
2106   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2107         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2108                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2109                     (const_int 0)))
2110    (clobber (match_scratch:SI 3 "=r"))]
2111   ""
2112   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff"
2113   [(set_attr "type" "delayed_compare")])
2114
2115 (define_insn ""
2116   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2117         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2118                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2119                     (const_int 0)))
2120    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2121         (rotate:SI (match_dup 1) (match_dup 2)))]
2122   ""
2123   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff"
2124   [(set_attr "type" "delayed_compare")])
2125
2126 (define_insn ""
2127   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2128         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2129                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2130                 (match_operand:SI 3 "mask_operand" "L")))]
2131   ""
2132   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
2133
2134 (define_insn ""
2135   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2136         (compare:CC (and:SI
2137                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2138                                 (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2139                      (match_operand:SI 3 "mask_operand" "L"))
2140                     (const_int 0)))
2141    (clobber (match_scratch:SI 4 "=r"))]
2142   ""
2143   "{rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3"
2144   [(set_attr "type" "delayed_compare")])
2145
2146 (define_insn ""
2147   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2148         (compare:CC (and:SI
2149                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2150                                 (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2151                      (match_operand:SI 3 "mask_operand" "L"))
2152                     (const_int 0)))
2153    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2154         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2155   ""
2156   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3"
2157   [(set_attr "type" "delayed_compare")])
2158
2159 (define_insn ""
2160   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2161         (zero_extend:SI
2162          (subreg:QI
2163           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2164                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
2165   ""
2166   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
2167
2168 (define_insn ""
2169   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2170         (compare:CC (zero_extend:SI
2171                      (subreg:QI
2172                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2173                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2174                     (const_int 0)))
2175    (clobber (match_scratch:SI 3 "=r"))]
2176   ""
2177   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff"
2178   [(set_attr "type" "delayed_compare")])
2179
2180 (define_insn ""
2181   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2182         (compare:CC (zero_extend:SI
2183                      (subreg:QI
2184                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2185                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2186                     (const_int 0)))
2187    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2188         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
2189   ""
2190   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff"
2191   [(set_attr "type" "delayed_compare")])
2192
2193 (define_insn ""
2194   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2195         (zero_extend:SI
2196          (subreg:HI
2197           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2198                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
2199   ""
2200   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
2201
2202 (define_insn ""
2203   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2204         (compare:CC (zero_extend:SI
2205                      (subreg:HI
2206                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2207                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2208                     (const_int 0)))
2209    (clobber (match_scratch:SI 3 "=r"))]
2210   ""
2211   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff"
2212   [(set_attr "type" "delayed_compare")])
2213
2214 (define_insn ""
2215   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2216         (compare:CC (zero_extend:SI
2217                      (subreg:HI
2218                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2219                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2220                     (const_int 0)))
2221    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2222         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
2223   ""
2224   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff"
2225   [(set_attr "type" "delayed_compare")])
2226
2227 ;; Note that we use "sle." instead of "sl." so that we can set
2228 ;; SHIFT_COUNT_TRUNCATED.
2229
2230 (define_expand "ashlsi3"
2231   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2232    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2233    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2234   ""
2235   "
2236 {
2237   if (TARGET_POWER)
2238     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
2239   else
2240     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
2241   DONE;
2242 }")
2243
2244 (define_insn "ashlsi3_power"
2245   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2246         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2247                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2248    (clobber (match_scratch:SI 3 "=q,X"))]
2249   "TARGET_POWER"
2250   "@
2251    sle %0,%1,%2
2252    {sli|slwi} %0,%1,%h2"
2253   [(set_attr "length" "8")])
2254
2255 (define_insn "ashlsi3_no_power"
2256   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2257         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2258                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2259   "! TARGET_POWER"
2260   "slw%I2 %0,%1,%h2"
2261   [(set_attr "length" "8")])
2262
2263 (define_insn ""
2264   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2265         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2266                                (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2267                     (const_int 0)))
2268    (clobber (match_scratch:SI 3 "=r,r"))
2269    (clobber (match_scratch:SI 4 "=q,X"))]
2270   "TARGET_POWER"
2271   "@
2272    sle. %3,%1,%2
2273    {sli.|slwi.} %3,%1,%h2"
2274   [(set_attr "type" "delayed_compare")])
2275
2276 (define_insn ""
2277   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2278         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2279                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2280                     (const_int 0)))
2281    (clobber (match_scratch:SI 3 "=r"))]
2282   "! TARGET_POWER"
2283   "slw%I2. %3,%1,%h2"
2284   [(set_attr "type" "delayed_compare")])
2285
2286 (define_insn ""
2287   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2288         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2289                                (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2290                     (const_int 0)))
2291    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2292         (ashift:SI (match_dup 1) (match_dup 2)))
2293    (clobber (match_scratch:SI 4 "=q,X"))]
2294   "TARGET_POWER"
2295   "@
2296    sle. %0,%1,%2
2297    {sli.|slwi.} %0,%1,%h2"
2298   [(set_attr "type" "delayed_compare")])
2299
2300 (define_insn ""
2301   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2302         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2303                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2304                     (const_int 0)))
2305    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2306         (ashift:SI (match_dup 1) (match_dup 2)))]
2307   "! TARGET_POWER"
2308   "slw%I2. %0,%1,%h2"
2309   [(set_attr "type" "delayed_compare")])
2310
2311 (define_insn ""
2312   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2313         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2314                            (match_operand:SI 2 "const_int_operand" "i"))
2315                 (match_operand:SI 3 "mask_operand" "L")))]
2316   "includes_lshift_p (operands[2], operands[3])"
2317   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
2318
2319 (define_insn ""
2320   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2321         (compare:CC
2322          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2323                             (match_operand:SI 2 "const_int_operand" "i"))
2324                  (match_operand:SI 3 "mask_operand" "L"))
2325          (const_int 0)))
2326    (clobber (match_scratch:SI 4 "=r"))]
2327   "includes_lshift_p (operands[2], operands[3])"
2328   "{rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3"
2329   [(set_attr "type" "delayed_compare")])
2330
2331 (define_insn ""
2332   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2333         (compare:CC
2334          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2335                             (match_operand:SI 2 "const_int_operand" "i"))
2336                  (match_operand:SI 3 "mask_operand" "L"))
2337          (const_int 0)))
2338    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2339         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2340   "includes_lshift_p (operands[2], operands[3])"
2341   "{rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3"
2342   [(set_attr "type" "delayed_compare")])
2343
2344 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
2345 ;; "sli x,x,0".
2346 (define_expand "lshrsi3"
2347   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2348    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2349    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2350   ""
2351   "
2352 {
2353   if (TARGET_POWER)
2354     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
2355   else
2356     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
2357   DONE;
2358 }")
2359
2360 (define_insn "lshrsi3_power"
2361   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2362         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2363                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2364    (clobber (match_scratch:SI 3 "=q,X"))]
2365   "TARGET_POWER"
2366   "@
2367   sre %0,%1,%2
2368   {s%A2i|s%A2wi} %0,%1,%h2")
2369
2370 (define_insn "lshrsi3_no_power"
2371   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2372         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2373                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2374   "! TARGET_POWER"
2375   "srw%I2 %0,%1,%h2")
2376
2377 (define_insn ""
2378   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2379         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2380                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2381                     (const_int 0)))
2382    (clobber (match_scratch:SI 3 "=r,r"))
2383    (clobber (match_scratch:SI 4 "=q,X"))]
2384   "TARGET_POWER"
2385   "@
2386   sre. %3,%1,%2
2387   {s%A2i.|s%A2wi.} %3,%1,%h2"
2388   [(set_attr "type" "delayed_compare")])
2389
2390 (define_insn ""
2391   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2392         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2393                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2394                     (const_int 0)))
2395    (clobber (match_scratch:SI 3 "=r"))]
2396   "! TARGET_POWER"
2397   "srw%I2. %3,%1,%h2"
2398   [(set_attr "type" "delayed_compare")])
2399
2400 (define_insn ""
2401   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2402         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2403                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2404                     (const_int 0)))
2405    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2406         (lshiftrt:SI (match_dup 1) (match_dup 2)))
2407    (clobber (match_scratch:SI 4 "=q,X"))]
2408   "TARGET_POWER"
2409   "@
2410   sre. %0,%1,%2
2411   {s%A2i.|s%A2wi.} %0,%1,%h2"
2412   [(set_attr "type" "delayed_compare")])
2413
2414 (define_insn ""
2415   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2416         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2417                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2418                     (const_int 0)))
2419    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2420         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
2421   "! TARGET_POWER"
2422   "srw%I2. %0,%1,%h2"
2423   [(set_attr "type" "delayed_compare")])
2424
2425 (define_insn ""
2426   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2427         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2428                              (match_operand:SI 2 "const_int_operand" "i"))
2429                 (match_operand:SI 3 "mask_operand" "L")))]
2430   "includes_rshift_p (operands[2], operands[3])"
2431   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
2432
2433 (define_insn ""
2434   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2435         (compare:CC
2436          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2437                               (match_operand:SI 2 "const_int_operand" "i"))
2438                  (match_operand:SI 3 "mask_operand" "L"))
2439          (const_int 0)))
2440    (clobber (match_scratch:SI 4 "=r"))]
2441   "includes_rshift_p (operands[2], operands[3])"
2442   "{rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3"
2443   [(set_attr "type" "delayed_compare")])
2444
2445 (define_insn ""
2446   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2447         (compare:CC
2448          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2449                               (match_operand:SI 2 "const_int_operand" "i"))
2450                  (match_operand:SI 3 "mask_operand" "L"))
2451          (const_int 0)))
2452    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2453         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2454   "includes_rshift_p (operands[2], operands[3])"
2455   "{rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3"
2456   [(set_attr "type" "delayed_compare")])
2457
2458 (define_insn ""
2459   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2460         (zero_extend:SI
2461          (subreg:QI
2462           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2463                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
2464   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2465   "{rlinm|rlwinm} %0,%1,%s2,0xff")
2466
2467 (define_insn ""
2468   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2469         (compare:CC
2470          (zero_extend:SI
2471           (subreg:QI
2472            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2473                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2474          (const_int 0)))
2475    (clobber (match_scratch:SI 3 "=r"))]
2476   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2477   "{rlinm.|rlwinm.} %3,%1,%s2,0xff"
2478   [(set_attr "type" "delayed_compare")])
2479
2480 (define_insn ""
2481   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2482         (compare:CC
2483          (zero_extend:SI
2484           (subreg:QI
2485            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2486                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2487          (const_int 0)))
2488    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2489         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
2490   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2491   "{rlinm.|rlwinm.} %0,%1,%s2,0xff"
2492   [(set_attr "type" "delayed_compare")])
2493
2494 (define_insn ""
2495   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2496         (zero_extend:SI
2497          (subreg:HI
2498           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2499                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
2500   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2501   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
2502
2503 (define_insn ""
2504   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2505         (compare:CC
2506          (zero_extend:SI
2507           (subreg:HI
2508            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2509                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2510          (const_int 0)))
2511    (clobber (match_scratch:SI 3 "=r"))]
2512   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2513   "{rlinm.|rlwinm.} %3,%1,%s2,0xffff"
2514   [(set_attr "type" "delayed_compare")])
2515
2516 (define_insn ""
2517   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2518         (compare:CC
2519          (zero_extend:SI
2520           (subreg:HI
2521            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2522                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2523          (const_int 0)))
2524    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2525         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
2526   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2527   "{rlinm.|rlwinm.} %0,%1,%s2,0xffff"
2528   [(set_attr "type" "delayed_compare")])
2529
2530 (define_insn ""
2531   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2532                          (const_int 1)
2533                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2534         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2535                      (const_int 31)))]
2536   "TARGET_POWER"
2537   "rrib %0,%1,%2")
2538
2539 (define_insn ""
2540   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2541                          (const_int 1)
2542                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2543         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2544                      (const_int 31)))]
2545   "TARGET_POWER"
2546   "rrib %0,%1,%2")
2547
2548 (define_insn ""
2549   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2550                          (const_int 1)
2551                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2552         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2553                          (const_int 1)
2554                          (const_int 0)))]
2555   "TARGET_POWER"
2556   "rrib %0,%1,%2")
2557
2558 (define_expand "ashrsi3"
2559   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2560         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
2561                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
2562   ""
2563   "
2564 {
2565   if (TARGET_POWER)
2566     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
2567   else
2568     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
2569   DONE;
2570 }")
2571
2572 (define_insn "ashrsi3_power"
2573   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2574         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2575                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2576    (clobber (match_scratch:SI 3 "=q,X"))]
2577   "TARGET_POWER"
2578   "@
2579    srea %0,%1,%2
2580    {srai|srawi} %0,%1,%h2")
2581
2582 (define_insn "ashrsi3_no_power"
2583   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2584         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2585                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2586   "! TARGET_POWER"
2587   "sraw%I2 %0,%1,%h2")
2588
2589 (define_insn ""
2590   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2591         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2592                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2593                     (const_int 0)))
2594    (clobber (match_scratch:SI 3 "=r,r"))
2595    (clobber (match_scratch:SI 4 "=q,X"))]
2596   "TARGET_POWER"
2597   "@
2598    srea. %3,%1,%2
2599    {srai.|srawi.} %3,%1,%h2"
2600   [(set_attr "type" "delayed_compare")])
2601
2602 (define_insn ""
2603   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2604         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2605                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2606                     (const_int 0)))
2607    (clobber (match_scratch:SI 3 "=r"))]
2608   "! TARGET_POWER"
2609   "sraw%I2. %3,%1,%h2"
2610   [(set_attr "type" "delayed_compare")])
2611
2612 (define_insn ""
2613   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2614         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2615                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2616                     (const_int 0)))
2617    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2618         (ashiftrt:SI (match_dup 1) (match_dup 2)))
2619    (clobber (match_scratch:SI 4 "=q,X"))]
2620   "TARGET_POWER"
2621   "@
2622    srea. %0,%1,%2
2623    {srai.|srawi.} %0,%1,%h2"
2624   [(set_attr "type" "delayed_compare")])
2625
2626 (define_insn ""
2627   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2628         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2629                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2630                     (const_int 0)))
2631    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2632         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
2633   "! TARGET_POWER"
2634   "sraw%I2. %0,%1,%h2"
2635   [(set_attr "type" "delayed_compare")])
2636 \f
2637 ;; Floating-point insns, excluding normal data motion.
2638 ;;
2639 ;; PowerPC has a full set of single-precision floating point instructions.
2640 ;;
2641 ;; For the POWER architecture, we pretend that we have both SFmode and
2642 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
2643 ;; The only conversions we will do will be when storing to memory.  In that
2644 ;; case, we will use the "frsp" instruction before storing.
2645 ;;
2646 ;; Note that when we store into a single-precision memory location, we need to
2647 ;; use the frsp insn first.  If the register being stored isn't dead, we
2648 ;; need a scratch register for the frsp.  But this is difficult when the store
2649 ;; is done by reload.  It is not incorrect to do the frsp on the register in
2650 ;; this case, we just lose precision that we would have otherwise gotten but
2651 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
2652
2653 (define_insn "extendsfdf2"
2654   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
2655         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2656   "TARGET_HARD_FLOAT"
2657   "*
2658 {
2659   if (REGNO (operands[0]) == REGNO (operands[1]))
2660     return \"\";
2661   else
2662     return \"fmr %0,%1\";
2663 }"
2664   [(set_attr "type" "fp")])
2665
2666 (define_insn "truncdfsf2"
2667   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2668         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
2669   "TARGET_HARD_FLOAT"
2670   "frsp %0,%1"
2671   [(set_attr "type" "fp")])
2672
2673 (define_insn "negsf2"
2674   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2675         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2676   "TARGET_HARD_FLOAT"
2677   "fneg %0,%1"
2678   [(set_attr "type" "fp")])
2679
2680 (define_insn "abssf2"
2681   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2682         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2683   "TARGET_HARD_FLOAT"
2684   "fabs %0,%1"
2685   [(set_attr "type" "fp")])
2686
2687 (define_insn ""
2688   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2689         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
2690   "TARGET_HARD_FLOAT"
2691   "fnabs %0,%1"
2692   [(set_attr "type" "fp")])
2693
2694 (define_expand "addsf3"
2695   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2696         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2697                  (match_operand:SF 2 "gpc_reg_operand" "")))]
2698   "TARGET_HARD_FLOAT"
2699   "")
2700
2701 (define_insn ""
2702   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2703         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2704                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2705   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2706   "fadds %0,%1,%2"
2707   [(set_attr "type" "fp")])
2708
2709 (define_insn ""
2710   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2711         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2712                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2713   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2714   "{fa|fadd} %0,%1,%2"
2715   [(set_attr "type" "fp")])
2716
2717 (define_expand "subsf3"
2718   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2719         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2720                   (match_operand:SF 2 "gpc_reg_operand" "")))]
2721   "TARGET_HARD_FLOAT"
2722   "")
2723
2724 (define_insn ""
2725   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2726         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2727                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
2728   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2729   "fsubs %0,%1,%2"
2730   [(set_attr "type" "fp")])
2731
2732 (define_insn ""
2733   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2734         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2735                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
2736   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2737   "{fs|fsub} %0,%1,%2"
2738   [(set_attr "type" "fp")])
2739
2740 (define_expand "mulsf3"
2741   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2742         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
2743                  (match_operand:SF 2 "gpc_reg_operand" "")))]
2744   "TARGET_HARD_FLOAT"
2745   "")
2746
2747 (define_insn ""
2748   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2749         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2750                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2751   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2752   "fmuls %0,%1,%2"
2753   [(set_attr "type" "fp")])
2754
2755 (define_insn ""
2756   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2757         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2758                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2759   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2760   "{fm|fmul} %0,%1,%2"
2761   [(set_attr "type" "fp")])
2762
2763 (define_expand "divsf3"
2764   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2765         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
2766                 (match_operand:SF 2 "gpc_reg_operand" "")))]
2767   "TARGET_HARD_FLOAT"
2768   "")
2769
2770 (define_insn ""
2771   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2772         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2773                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
2774   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2775   "fdivs %0,%1,%2"
2776   [(set_attr "type" "sdiv")])
2777
2778 (define_insn ""
2779   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2780         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2781                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
2782   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2783   "{fd|fdiv} %0,%1,%2"
2784   [(set_attr "type" "sdiv")])
2785
2786 (define_insn ""
2787   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2788         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2789                           (match_operand:SF 2 "gpc_reg_operand" "f"))
2790                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
2791   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2792   "fmadds %0,%1,%2,%3"
2793   [(set_attr "type" "fp")])
2794
2795 (define_insn ""
2796   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2797         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2798                           (match_operand:SF 2 "gpc_reg_operand" "f"))
2799                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
2800   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2801   "{fma|fmadd} %0,%1,%2,%3"
2802   [(set_attr "type" "fp")])
2803
2804 (define_insn ""
2805   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2806         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2807                            (match_operand:SF 2 "gpc_reg_operand" "f"))
2808                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
2809   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2810   "fmsubs %0,%1,%2,%3"
2811   [(set_attr "type" "fp")])
2812
2813 (define_insn ""
2814   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2815         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2816                            (match_operand:SF 2 "gpc_reg_operand" "f"))
2817                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
2818   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2819   "{fms|fmsub} %0,%1,%2,%3"
2820   [(set_attr "type" "fp")])
2821
2822 (define_insn ""
2823   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2824         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2825                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
2826                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
2827   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2828   "fnmadds %0,%1,%2,%3"
2829   [(set_attr "type" "fp")])
2830
2831 (define_insn ""
2832   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2833         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2834                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
2835                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
2836   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2837   "{fnma|fnmadd} %0,%1,%2,%3"
2838   [(set_attr "type" "fp")])
2839
2840 (define_insn ""
2841   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2842         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2843                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
2844                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
2845   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2846   "fnmsubs %0,%1,%2,%3"
2847   [(set_attr "type" "fp")])
2848
2849 (define_insn ""
2850   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2851         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2852                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
2853                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
2854   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2855   "{fnms|fnmsub} %0,%1,%2,%3"
2856   [(set_attr "type" "fp")])
2857
2858 (define_expand "sqrtsf2"
2859   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2860         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
2861   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT"
2862   "")
2863
2864 (define_insn ""
2865   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2866         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2867   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT"
2868   "fsqrts %0,%1"
2869   [(set_attr "type" "ssqrt")])
2870
2871 (define_insn ""
2872   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2873         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2874   "TARGET_POWER2 && TARGET_HARD_FLOAT"
2875   "fsqrt %0,%1"
2876   [(set_attr "type" "dsqrt")])
2877
2878 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
2879 ;; fsel instruction and some auxiliary computations.  Then we just have a
2880 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
2881 ;; combine.
2882 (define_expand "maxsf3"
2883   [(set (match_dup 3)
2884         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2885                   (match_operand:SF 2 "gpc_reg_operand" "")))
2886    (set (match_operand:SF 0 "gpc_reg_operand" "")
2887         (if_then_else:SF (ge (match_dup 3)
2888                              (const_int 0))
2889                          (match_dup 1)
2890                          (match_dup 2)))]
2891   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
2892   "
2893 { operands[3] = gen_reg_rtx (SFmode); }")
2894
2895 (define_split
2896   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2897         (smax:SF (match_operand:SF 1 "gpc_reg_operand" "")
2898                  (match_operand:SF 2 "gpc_reg_operand" "")))
2899    (clobber (match_operand:SF 3 "gpc_reg_operand" ""))]
2900   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
2901   [(set (match_dup 3)
2902         (minus:SF (match_dup 1) (match_dup 2)))
2903    (set (match_dup 0)
2904         (if_then_else:SF (ge (match_dup 3)
2905                              (const_int 0))
2906                          (match_dup 1)
2907                          (match_dup 2)))]
2908   "")
2909
2910 (define_expand "minsf3"
2911   [(set (match_dup 3)
2912         (minus:SF (match_operand:SF 2 "gpc_reg_operand" "")
2913                   (match_operand:SF 1 "gpc_reg_operand" "")))
2914    (set (match_operand:SF 0 "gpc_reg_operand" "")
2915         (if_then_else:SF (ge (match_dup 3)
2916                              (const_int 0))
2917                          (match_dup 1)
2918                          (match_dup 2)))]
2919   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
2920   "
2921 { operands[3] = gen_reg_rtx (SFmode); }")
2922
2923 (define_split
2924   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2925         (smin:SF (match_operand:SF 1 "gpc_reg_operand" "")
2926                  (match_operand:SF 2 "gpc_reg_operand" "")))
2927    (clobber (match_operand:SF 3 "gpc_reg_operand" ""))]
2928   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
2929   [(set (match_dup 3)
2930         (minus:SF (match_dup 2) (match_dup 1)))
2931    (set (match_dup 0)
2932         (if_then_else:SF (ge (match_dup 3)
2933                              (const_int 0))
2934                          (match_dup 1)
2935                          (match_dup 2)))]
2936   "")
2937
2938 (define_expand "movsfcc"
2939    [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2940          (if_then_else:SF (match_operand 1 "comparison_operator" "")
2941                           (match_operand:SF 2 "gpc_reg_operand" "f")
2942                           (match_operand:SF 3 "gpc_reg_operand" "f")))]
2943   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
2944   "
2945 {
2946   rtx temp, op0, op1;
2947   enum rtx_code code = GET_CODE (operands[1]);
2948   if (! rs6000_compare_fp_p)
2949     FAIL;
2950   switch (code)
2951     {
2952     case GE: case EQ: case NE:
2953       op0 = rs6000_compare_op0;
2954       op1 = rs6000_compare_op1;
2955       break;
2956     case GT:
2957       op0 = rs6000_compare_op1;
2958       op1 = rs6000_compare_op0;
2959       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
2960       break;
2961     case LE:
2962       op0 = rs6000_compare_op1;
2963       op1 = rs6000_compare_op0;
2964       break;
2965     case LT:
2966       op0 = rs6000_compare_op0;
2967       op1 = rs6000_compare_op1;
2968       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
2969       break;
2970     default:
2971       FAIL;
2972     }
2973   if (GET_MODE (rs6000_compare_op0) == DFmode)
2974     {
2975       temp = gen_reg_rtx (DFmode);
2976       emit_insn (gen_subdf3 (temp, op0, op1));
2977       emit_insn (gen_fseldfsf4 (operands[0], temp, operands[2], operands[3]));
2978       if (code == EQ)
2979         {
2980           emit_insn (gen_negdf2 (temp, temp));
2981           emit_insn (gen_fseldfsf4 (operands[0], temp, operands[0], operands[3]));
2982         }
2983       if (code == NE)
2984         {
2985           emit_insn (gen_negdf2 (temp, temp));
2986           emit_insn (gen_fseldfsf4 (operands[0], temp, operands[3], operands[0]));
2987         }
2988     }
2989   else
2990     {
2991       temp = gen_reg_rtx (SFmode);
2992       emit_insn (gen_subsf3 (temp, op0, op1));
2993       emit_insn (gen_fselsfsf4 (operands[0], temp, operands[2], operands[3]));
2994       if (code == EQ)
2995         {
2996           emit_insn (gen_negsf2 (temp, temp));
2997           emit_insn (gen_fselsfsf4 (operands[0], temp, operands[0], operands[3]));
2998         }
2999       if (code == NE)
3000         {
3001           emit_insn (gen_negsf2 (temp, temp));
3002           emit_insn (gen_fselsfsf4 (operands[0], temp, operands[3], operands[0]));
3003         }
3004     }
3005   DONE;
3006 }")
3007
3008 (define_insn "fselsfsf4"
3009   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3010         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
3011                              (const_int 0))
3012                          (match_operand:SF 2 "gpc_reg_operand" "f")
3013                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
3014   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3015   "fsel %0,%1,%2,%3"
3016   [(set_attr "type" "fp")])
3017
3018 (define_insn "fseldfsf4"
3019   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3020         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
3021                              (const_int 0))
3022                          (match_operand:SF 2 "gpc_reg_operand" "f")
3023                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
3024   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3025   "fsel %0,%1,%2,%3"
3026   [(set_attr "type" "fp")])
3027
3028 (define_insn "negdf2"
3029   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3030         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3031   "TARGET_HARD_FLOAT"
3032   "fneg %0,%1"
3033   [(set_attr "type" "fp")])
3034
3035 (define_insn "absdf2"
3036   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3037         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3038   "TARGET_HARD_FLOAT"
3039   "fabs %0,%1"
3040   [(set_attr "type" "fp")])
3041
3042 (define_insn ""
3043   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3044         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
3045   "TARGET_HARD_FLOAT"
3046   "fnabs %0,%1"
3047   [(set_attr "type" "fp")])
3048
3049 (define_insn "adddf3"
3050   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3051         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3052                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
3053   "TARGET_HARD_FLOAT"
3054   "{fa|fadd} %0,%1,%2"
3055   [(set_attr "type" "fp")])
3056
3057 (define_insn "subdf3"
3058   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3059         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
3060                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
3061   "TARGET_HARD_FLOAT"
3062   "{fs|fsub} %0,%1,%2"
3063   [(set_attr "type" "fp")])
3064
3065 (define_insn "muldf3"
3066   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3067         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3068                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
3069   "TARGET_HARD_FLOAT"
3070   "{fm|fmul} %0,%1,%2"
3071   [(set_attr "type" "dmul")])
3072
3073 (define_insn "divdf3"
3074   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3075         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
3076                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
3077   "TARGET_HARD_FLOAT"
3078   "{fd|fdiv} %0,%1,%2"
3079   [(set_attr "type" "ddiv")])
3080
3081 (define_insn ""
3082   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3083         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3084                           (match_operand:DF 2 "gpc_reg_operand" "f"))
3085                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
3086   "TARGET_HARD_FLOAT"
3087   "{fma|fmadd} %0,%1,%2,%3"
3088   [(set_attr "type" "dmul")])
3089
3090 (define_insn ""
3091   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3092         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3093                            (match_operand:DF 2 "gpc_reg_operand" "f"))
3094                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
3095   "TARGET_HARD_FLOAT"
3096   "{fms|fmsub} %0,%1,%2,%3"
3097   [(set_attr "type" "dmul")])
3098
3099 (define_insn ""
3100   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3101         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3102                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
3103                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
3104   "TARGET_HARD_FLOAT"
3105   "{fnma|fnmadd} %0,%1,%2,%3"
3106   [(set_attr "type" "dmul")])
3107
3108 (define_insn ""
3109   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3110         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3111                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
3112                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
3113   "TARGET_HARD_FLOAT"
3114   "{fnms|fnmsub} %0,%1,%2,%3"
3115   [(set_attr "type" "dmul")])
3116
3117 (define_insn "sqrtdf2"
3118   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3119         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3120   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT"
3121   "fsqrt %0,%1"
3122   [(set_attr "type" "dsqrt")])
3123
3124 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
3125 ;; fsel instruction and some auxiliary computations.  Then we just have a
3126 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
3127 ;; combine.
3128
3129 (define_expand "maxdf3"
3130   [(set (match_dup 3)
3131         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
3132                   (match_operand:DF 2 "gpc_reg_operand" "")))
3133    (set (match_operand:DF 0 "gpc_reg_operand" "")
3134         (if_then_else:DF (ge (match_dup 3)
3135                              (const_int 0))
3136                          (match_dup 1)
3137                          (match_dup 2)))]
3138   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3139   "
3140 { operands[3] = gen_reg_rtx (DFmode); }")
3141
3142 (define_split
3143   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3144         (smax:DF (match_operand:DF 1 "gpc_reg_operand" "")
3145                  (match_operand:DF 2 "gpc_reg_operand" "")))
3146    (clobber (match_operand:DF 3 "gpc_reg_operand" ""))]
3147   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3148   [(set (match_dup 3)
3149         (minus:DF (match_dup 1) (match_dup 2)))
3150    (set (match_dup 0)
3151         (if_then_else:DF (ge (match_dup 3)
3152                              (const_int 0))
3153                          (match_dup 1)
3154                          (match_dup 2)))]
3155   "")
3156
3157 (define_expand "mindf3"
3158   [(set (match_dup 3)
3159         (minus:DF (match_operand:DF 2 "gpc_reg_operand" "")
3160                   (match_operand:DF 1 "gpc_reg_operand" "")))
3161    (set (match_operand:DF 0 "gpc_reg_operand" "")
3162         (if_then_else:DF (ge (match_dup 3)
3163                              (const_int 0))
3164                          (match_dup 1)
3165                          (match_dup 2)))]
3166   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3167   "
3168 { operands[3] = gen_reg_rtx (DFmode); }")
3169
3170 (define_split
3171   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3172         (smin:DF (match_operand:DF 1 "gpc_reg_operand" "")
3173                  (match_operand:DF 2 "gpc_reg_operand" "")))
3174    (clobber (match_operand:DF 3 "gpc_reg_operand" ""))]
3175   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3176   [(set (match_dup 3)
3177         (minus:DF (match_dup 2) (match_dup 1)))
3178    (set (match_dup 0)
3179         (if_then_else:DF (ge (match_dup 3)
3180                              (const_int 0))
3181                          (match_dup 1)
3182                          (match_dup 2)))]
3183   "")
3184
3185 (define_expand "movdfcc"
3186    [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3187          (if_then_else:DF (match_operand 1 "comparison_operator" "")
3188                           (match_operand:DF 2 "gpc_reg_operand" "f")
3189                           (match_operand:DF 3 "gpc_reg_operand" "f")))]
3190   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3191   "
3192 {
3193   rtx temp, op0, op1;
3194   enum rtx_code code = GET_CODE (operands[1]);
3195   if (! rs6000_compare_fp_p)
3196     FAIL;
3197   switch (code)
3198     {
3199     case GE: case EQ: case NE:
3200       op0 = rs6000_compare_op0;
3201       op1 = rs6000_compare_op1;
3202       break;
3203     case GT:
3204       op0 = rs6000_compare_op1;
3205       op1 = rs6000_compare_op0;
3206       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3207       break;
3208     case LE:
3209       op0 = rs6000_compare_op1;
3210       op1 = rs6000_compare_op0;
3211       break;
3212     case LT:
3213       op0 = rs6000_compare_op0;
3214       op1 = rs6000_compare_op1;
3215       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3216       break;
3217     default:
3218       FAIL;
3219     }
3220   if (GET_MODE (rs6000_compare_op0) == DFmode)
3221     {
3222       temp = gen_reg_rtx (DFmode);
3223       emit_insn (gen_subdf3 (temp, op0, op1));
3224       emit_insn (gen_fseldfdf4 (operands[0], temp, operands[2], operands[3]));
3225       if (code == EQ)
3226         {
3227           emit_insn (gen_negdf2 (temp, temp));
3228           emit_insn (gen_fseldfdf4 (operands[0], temp, operands[0], operands[3]));
3229         }
3230       if (code == NE)
3231         {
3232           emit_insn (gen_negdf2 (temp, temp));
3233           emit_insn (gen_fseldfdf4 (operands[0], temp, operands[3], operands[0]));
3234         }
3235     }
3236   else
3237     {
3238       temp = gen_reg_rtx (SFmode);
3239       emit_insn (gen_subsf3 (temp, op0, op1));
3240       emit_insn (gen_fselsfdf4 (operands[0], temp, operands[2], operands[3]));
3241       if (code == EQ)
3242         {
3243           emit_insn (gen_negsf2 (temp, temp));
3244           emit_insn (gen_fselsfdf4 (operands[0], temp, operands[0], operands[3]));
3245         }
3246       if (code == NE)
3247         {
3248           emit_insn (gen_negsf2 (temp, temp));
3249           emit_insn (gen_fselsfdf4 (operands[0], temp, operands[3], operands[0]));
3250         }
3251     }
3252   DONE;
3253 }")
3254
3255 (define_insn "fseldfdf4"
3256   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3257         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
3258                              (const_int 0))
3259                          (match_operand:DF 2 "gpc_reg_operand" "f")
3260                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
3261   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3262   "fsel %0,%1,%2,%3"
3263   [(set_attr "type" "fp")])
3264
3265 (define_insn "fselsfdf4"
3266   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3267         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
3268                              (const_int 0))
3269                          (match_operand:DF 2 "gpc_reg_operand" "f")
3270                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
3271   "TARGET_PPC_GFXOPT"
3272   "fsel %0,%1,%2,%3"
3273   [(set_attr "type" "fp")])
3274 \f
3275 ;; Conversions to and from floating-point.
3276 (define_expand "floatsidf2"
3277   [(set (match_dup 2)
3278         (plus:DI (zero_extend:DI
3279                   (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3280                           (match_dup 3)))
3281                  (match_dup 4)))
3282    (set (match_operand:DF 0 "gpc_reg_operand" "")
3283         (minus:DF (subreg:DF (match_dup 2) 0)
3284                   (match_dup 5)))]
3285   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3286   "
3287 {
3288   operands[2] = gen_reg_rtx (DImode);
3289   operands[3] = gen_rtx (CONST_INT, VOIDmode, 0x80000000);
3290   operands[4] = immed_double_const (0, 0x43300000, DImode);
3291   operands[5] = force_reg (DFmode, immed_double_const (0x43300000,
3292                                                        0x80000000, DFmode));
3293 }")
3294
3295 (define_expand "floatunssidf2"
3296   [(set (match_dup 2)
3297         (plus:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
3298                  (match_dup 3)))
3299    (set (match_operand:DF 0 "gpc_reg_operand" "")
3300         (minus:DF (subreg:DF (match_dup 2) 0)
3301                   (match_dup 4)))]
3302   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3303   "
3304 {
3305   operands[2] = gen_reg_rtx (DImode);
3306   operands[3] = immed_double_const (0, 0x43300000, DImode);
3307   operands[4] = force_reg (DFmode, immed_double_const (0x43300000, 0, DFmode));
3308 }")
3309
3310 ;; For the above two cases, we always split.
3311 (define_split
3312   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3313         (plus:DI (zero_extend:DI
3314                   (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3315                           (match_operand:SI 2 "logical_operand" "")))
3316                  (match_operand:DI 3 "low_32_bit_operand" "")))]
3317   "reload_completed"
3318   [(set (match_dup 6) (xor:SI (match_dup 1) (match_dup 2)))
3319    (set (match_dup 4) (match_dup 5))]
3320   "
3321 { operands[4] = operand_subword (operands[0], 0, 0, DImode);
3322   operands[5] = operand_subword (operands[3], 0, 0, DImode);
3323   operands[6] = operand_subword (operands[0], 1, 0, DImode);
3324 }")
3325
3326 (define_insn ""
3327   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3328         (plus:DI (zero_extend:DI
3329                   (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
3330                           (match_operand:SI 2 "logical_operand" "rKJ")))
3331                  (match_operand:DI 3 "low_32_bit_operand" "n")))]
3332   ""
3333   "#"
3334   [(set_attr "length" "8")])
3335   
3336 (define_split
3337   [(set (match_operand:DI 0 "gpc_reg_operand" "=")
3338         (plus:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
3339                  (match_operand:DI 2 "low_32_bit_operand" "")))]
3340   "reload_completed"
3341   [(set (match_dup 3) (match_dup 4))
3342    (set (match_dup 5) (match_dup 1))]
3343   "
3344 { operands[3] = operand_subword (operands[0], 0, 0, DImode);
3345   operands[4] = operand_subword (operands[2], 0, 0, DImode);
3346   operands[5] = operand_subword (operands[0], 1, 0, DImode);
3347
3348   if (rtx_equal_p (operands[1], operands[5]))
3349     {
3350       emit_move_insn (operands[3], operands[4]);
3351       DONE;
3352     }
3353
3354   if (rtx_equal_p (operands[1], operands[3]))
3355     {
3356       rtx temp;
3357
3358       temp = operands[3]; operands[3] = operands[5]; operands[5] = temp;
3359       temp = operands[4]; operands[4] = operands[1]; operands[1] = temp;
3360     }
3361 }")
3362
3363 (define_insn ""
3364   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3365         (plus:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
3366                  (match_operand:DI 2 "low_32_bit_operand" "n")))]
3367   ""
3368   "#"
3369   [(set_attr "length" "8")])
3370
3371 (define_expand "fix_truncdfsi2"
3372   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3373         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))]
3374   "TARGET_HARD_FLOAT"
3375   "
3376 {
3377   if (TARGET_POWER2 || TARGET_POWERPC)
3378     {
3379       rtx stack_slot = assign_stack_temp (DImode, 8, 0),
3380         temp = gen_reg_rtx (DImode);
3381
3382       emit_insn (gen_fpcvtsi (temp, operands[1]));
3383       emit_move_insn (stack_slot, temp);
3384       emit_move_insn (operands[0],
3385                       operand_subword (stack_slot, 1, 0, DImode));
3386       DONE;
3387     }
3388   else
3389     {
3390       emit_insn (gen_trunc_call (operands[0], operands[1],
3391                                  gen_rtx (SYMBOL_REF, Pmode, RS6000_ITRUNC)));
3392       DONE;
3393     }
3394 }")
3395
3396 (define_insn "fpcvtsi"
3397   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
3398         (sign_extend:DI
3399          (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))))]
3400   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT"
3401   "{fcirz|fctiwz} %0,%1"
3402   [(set_attr "type" "fp")])
3403
3404 (define_expand "fixuns_truncdfsi2"
3405   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3406         (unsigned_fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))]
3407   "! TARGET_POWER2 && ! TARGET_POWERPC && TARGET_HARD_FLOAT"
3408   "
3409 {
3410   emit_insn (gen_trunc_call (operands[0], operands[1],
3411                              gen_rtx (SYMBOL_REF, Pmode, RS6000_UITRUNC)));
3412   DONE;
3413 }")
3414
3415 (define_expand "trunc_call"
3416   [(parallel [(set (match_operand:SI 0 "" "")
3417                    (fix:SI (match_operand:DF 1 "" "")))
3418               (use (match_operand:SI 2 "" ""))])]
3419   "TARGET_HARD_FLOAT"
3420   "
3421 {
3422   rtx insns = gen_trunc_call_rtl (operands[0], operands[1], operands[2]);
3423   rtx first = XVECEXP (insns, 0, 0);
3424   rtx last = XVECEXP (insns, 0, XVECLEN (insns, 0) - 1);
3425
3426   REG_NOTES (first) = gen_rtx (INSN_LIST, REG_LIBCALL, last,
3427                                REG_NOTES (first));
3428   REG_NOTES (last) = gen_rtx (INSN_LIST, REG_RETVAL, first, REG_NOTES (last));
3429
3430   emit_insn (insns);
3431   DONE;
3432 }")
3433
3434 (define_expand "trunc_call_rtl"
3435   [(set (reg:DF 33) (match_operand:DF 1 "gpc_reg_operand" ""))
3436    (use (reg:DF 33))
3437    (parallel [(set (reg:SI 3)
3438                    (call (mem:SI (match_operand 2 "" "")) (const_int 0)))
3439               (clobber (scratch:SI))])
3440    (set (match_operand:SI 0 "gpc_reg_operand" "")
3441         (reg:SI 3))]
3442   "TARGET_HARD_FLOAT"
3443   "
3444
3445   rs6000_trunc_used = 1;
3446 }")
3447
3448 (define_insn "floatdidf2"
3449   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3450         (float:DF (match_operand:DI 1 "gpc_reg_operand" "f")))]
3451   "TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3452   "fcfid %0,%1"
3453   [(set_attr "type" "fp")])
3454
3455 (define_insn "fix_truncdfdi2"
3456   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
3457         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
3458   "TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3459   "fctidz %0,%1"
3460   [(set_attr "type" "fp")])
3461 \f
3462 ;; Define the DImode operations that can be done in a small number
3463 ;; of instructions.
3464 (define_expand "adddi3"
3465   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3466         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
3467                  (match_operand:DI 2 "reg_or_short_operand" "")))]
3468   ""
3469   "
3470 {
3471   if (! TARGET_POWER && ! TARGET_POWERPC64
3472       && short_cint_operand (operands[2], DImode))
3473     FAIL;
3474 }")
3475
3476 (define_insn ""
3477   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3478         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
3479                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
3480   "TARGET_POWER && ! TARGET_POWERPC64"
3481   "@
3482    {a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2
3483    {ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1"
3484   [(set_attr "length" "8")])
3485
3486 (define_insn ""
3487   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3488         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
3489                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
3490   "! TARGET_POWER && ! TARGET_POWERPC64"
3491   "addc %L0,%L1,%L2\;adde %0,%1,%2"
3492   [(set_attr "length" "8")])
3493
3494 (define_expand "subdi3"
3495   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3496         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
3497                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
3498   ""
3499   "
3500 {
3501   if (! TARGET_POWER && ! TARGET_POWERPC64
3502       && short_cint_operand (operands[1], DImode))
3503     FAIL;
3504 }")
3505
3506 (define_insn ""
3507   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3508         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
3509                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
3510   "TARGET_POWER && ! TARGET_POWERPC64"
3511   "@
3512    {sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1
3513    {sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2"
3514   [(set_attr "length" "8")])
3515
3516 (define_insn ""
3517   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3518         (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3519                   (match_operand:DI 2 "gpc_reg_operand" "r")))]
3520   "! TARGET_POWER && ! TARGET_POWERPC64"
3521   "subfc %L0,%L2,%L1\;subfe %0,%2,%1"
3522   [(set_attr "length" "8")])
3523
3524 (define_expand "negdi2"
3525   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3526         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
3527   ""
3528   "")
3529
3530 (define_insn ""
3531   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3532         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
3533   "! TARGET_POWERPC64"
3534   "{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1"
3535   [(set_attr "length" "8")])
3536
3537 (define_expand "mulsidi3"
3538   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3539         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
3540                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
3541   ""
3542   "
3543 {
3544   if (! TARGET_POWER && ! TARGET_POWERPC)
3545     {
3546       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
3547       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
3548       emit_insn (gen_mull_call ());
3549       emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
3550                       gen_rtx (REG, SImode, 3));
3551       emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
3552                       gen_rtx (REG, SImode, 4));
3553       DONE;
3554     }
3555   else if (TARGET_POWER)
3556     {
3557       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
3558       DONE;
3559     }
3560 }")
3561
3562 (define_insn "mulsidi3_mq"
3563   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3564         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
3565                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
3566    (clobber (match_scratch:SI 3 "=q"))]
3567   "TARGET_POWER"
3568   "mul %0,%1,%2\;mfmq %L0"
3569   [(set_attr "type" "imul")
3570    (set_attr "length" "8")])
3571
3572 (define_insn ""
3573   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
3574         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
3575                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
3576   "TARGET_POWERPC && ! TARGET_POWERPC64"
3577   "mulhw %0,%1,%2\;mullw %L0,%1,%2"
3578   [(set_attr "type" "imul")
3579    (set_attr "length" "8")])
3580
3581 (define_expand "smulsi3_highpart"
3582   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3583         (truncate:SI
3584          (lshiftrt:DI (mult:DI (sign_extend:DI
3585                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3586                                (sign_extend:DI
3587                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3588                       (const_int 32))))]
3589   ""
3590   "
3591 {
3592   if (! TARGET_POWER && ! TARGET_POWERPC)
3593     {
3594       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
3595       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
3596       emit_insn (gen_mulh_call ());
3597       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
3598       DONE;
3599     }
3600   else if (TARGET_POWER)
3601     {
3602       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
3603       DONE;
3604     }
3605 }")
3606
3607 (define_insn "smulsi3_highpart_mq"
3608   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3609         (truncate:SI
3610          (lshiftrt:DI (mult:DI (sign_extend:DI
3611                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3612                                (sign_extend:DI
3613                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3614                       (const_int 32))))
3615    (clobber (match_scratch:SI 3 "=q"))]
3616   "TARGET_POWER"
3617   "mul %0,%1,%2"
3618   [(set_attr "type" "imul")])
3619
3620 (define_insn ""
3621   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3622         (truncate:SI
3623          (lshiftrt:DI (mult:DI (sign_extend:DI
3624                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3625                                (sign_extend:DI
3626                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3627                       (const_int 32))))]
3628   "TARGET_POWERPC"
3629   "mulhw %0,%1,%2"
3630   [(set_attr "type" "imul")])
3631
3632 (define_insn "umulsi3_highpart"
3633   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3634         (truncate:SI
3635          (lshiftrt:DI (mult:DI (zero_extend:DI
3636                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3637                                (zero_extend:DI
3638                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3639                       (const_int 32))))]
3640   "TARGET_POWERPC"
3641   "mulhwu %0,%1,%2"
3642   [(set_attr "type" "imul")])
3643
3644 ;; If operands 0 and 2 are in the same register, we have a problem.  But
3645 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
3646 ;; why we have the strange constraints below.
3647 (define_insn "ashldi3"
3648   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
3649         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
3650                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
3651    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
3652   "TARGET_POWER"
3653   "@
3654    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
3655    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
3656    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
3657    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
3658   [(set_attr "length" "8")])
3659
3660 (define_insn "lshrdi3"
3661   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r,r,&r")
3662         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
3663                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
3664    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
3665   "TARGET_POWER"
3666   "@
3667    {cal %0,0(0)|li %0,0}\;{s%A2i|s%A2wi} %L0,%1,%h2
3668    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
3669    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
3670    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
3671   [(set_attr "length" "8")])
3672
3673 ;; Shift by a variable amount is too complex to be worth open-coding.  We
3674 ;; just handle shifts by constants.
3675
3676 (define_expand "ashrdi3"
3677   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "")
3678                    (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
3679                                 (match_operand:SI 2 "general_operand" "")))
3680               (clobber (match_scratch:SI 3 ""))])]
3681   "TARGET_POWER"
3682   "
3683 { if (GET_CODE (operands[2]) != CONST_INT)
3684     FAIL;
3685 }")
3686
3687 (define_insn ""
3688   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3689         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
3690                      (match_operand:SI 2 "const_int_operand" "M,i")))
3691    (clobber (match_scratch:SI 3 "=X,q"))]
3692   "TARGET_POWER"
3693   "@
3694    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
3695    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
3696   [(set_attr "length" "8")])
3697 \f
3698 ;; PowerPC64 DImode operations.
3699
3700 (define_insn "ffsdi2"
3701   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
3702         (ffs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
3703   "TARGET_POWERPC64"
3704   "neg %0,%1\;and %0,%0,%1\;cntlzd %0,%0\;subfic %0,%0,64"
3705   [(set_attr "length" "16")])
3706
3707 (define_insn "muldi3"
3708   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3709         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
3710                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
3711   "TARGET_POWERPC64"
3712   "mulld %0,%1,%2"
3713    [(set_attr "type" "imul")])
3714
3715 (define_insn "smuldi3_highpart"
3716   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3717         (truncate:DI
3718          (lshiftrt:TI (mult:TI (sign_extend:TI
3719                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
3720                                (sign_extend:TI
3721                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
3722                       (const_int 64))))]
3723   "TARGET_POWERPC64"
3724   "mulhd %0,%1,%2"
3725   [(set_attr "type" "imul")])
3726
3727 (define_insn "umuldi3_highpart"
3728   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3729         (truncate:DI
3730          (lshiftrt:TI (mult:TI (zero_extend:TI
3731                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
3732                                (zero_extend:TI
3733                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
3734                       (const_int 64))))]
3735   "TARGET_POWERPC64"
3736   "mulhdu %0,%1,%2"
3737   [(set_attr "type" "imul")])
3738
3739 (define_insn "divdi3"
3740   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3741         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3742                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
3743   "TARGET_POWERPC64"
3744   "divd %0,%1,%2"
3745   [(set_attr "type" "idiv")])
3746
3747 (define_insn "udivdi3"
3748   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3749         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3750                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
3751   "TARGET_POWERPC64"
3752   "divdu %0,%1,%2"
3753   [(set_attr "type" "idiv")])
3754
3755 (define_insn "rotldi3"
3756   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3757         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3758                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
3759   "TARGET_POWERPC64"
3760   "rld%I2cl %0,%1,%h2,0")
3761
3762 (define_insn ""
3763   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
3764         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3765                                (match_operand:DI 2 "reg_or_cint_operand" "ri"))
3766                     (const_int 0)))
3767    (clobber (match_scratch:DI 3 "=r"))]
3768   "TARGET_POWERPC64"
3769   "rld%I2cl. %3,%1,%h2,0"
3770   [(set_attr "type" "delayed_compare")])
3771
3772 (define_insn ""
3773   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
3774         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3775                                (match_operand:DI 2 "reg_or_cint_operand" "ri"))
3776                     (const_int 0)))
3777    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3778         (rotate:DI (match_dup 1) (match_dup 2)))]
3779   "TARGET_POWERPC64"
3780   "rld%I2cl. %0,%1,%h2,0"
3781   [(set_attr "type" "delayed_compare")])
3782 \f
3783 ;; Now define ways of moving data around.
3784 ;;
3785 ;; For SI, we special-case integers that can't be loaded in one insn.  We
3786 ;; do the load 16-bits at a time.  We could do this by loading from memory,
3787 ;; and this is even supposed to be faster, but it is simpler not to get
3788 ;; integers in the TOC.
3789 (define_expand "movsi"
3790   [(set (match_operand:SI 0 "general_operand" "")
3791         (match_operand:SI 1 "any_operand" ""))]
3792   ""
3793   "
3794 {
3795   if (GET_CODE (operands[0]) != REG)
3796     operands[1] = force_reg (SImode, operands[1]);
3797
3798   if (CONSTANT_P (operands[1]) && GET_CODE (operands[1]) != CONST_INT
3799       && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1]))
3800     {
3801       /* If we are to limit the number of things we put in the TOC and
3802          this is a symbol plus a constant we can add in one insn,
3803          just put the sumbol in the TOC and add the constant.  Don't do
3804          this if reload is in progress.  */
3805       if (GET_CODE (operands[1]) == CONST
3806           && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
3807           && GET_CODE (XEXP (operands[1], 0)) == PLUS
3808           && add_operand (XEXP (XEXP (operands[1], 0), 1), SImode)
3809           && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
3810               || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
3811           && ! side_effects_p (operands[0]))
3812         {
3813           rtx sym = force_const_mem (SImode, XEXP (XEXP (operands[1], 0), 0));
3814           rtx other = XEXP (XEXP (operands[1], 0), 1);
3815
3816           emit_insn (gen_addsi3 (operands[0], force_reg (SImode, sym), other));
3817           DONE;
3818         }
3819
3820       operands[1] = force_const_mem (SImode, operands[1]);
3821       if (! memory_address_p (SImode, XEXP (operands[1], 0))
3822           && ! reload_in_progress)
3823         operands[1] = change_address (operands[1], SImode,
3824                                       XEXP (operands[1], 0));
3825     }
3826
3827   if (GET_CODE (operands[1]) == CONST_INT
3828       && (unsigned) (INTVAL (operands[1]) + 0x8000) >= 0x10000
3829       && (INTVAL (operands[1]) & 0xffff) != 0)
3830     {
3831       emit_move_insn (operands[0],
3832                       gen_rtx (CONST_INT, VOIDmode,
3833                                INTVAL (operands[1]) & 0xffff0000));
3834       emit_insn (gen_iorsi3 (operands[0], operands[0],
3835                              gen_rtx (CONST_INT, VOIDmode,
3836                                       INTVAL (operands[1]) & 0xffff)));
3837       DONE;
3838     }
3839 }")
3840
3841 (define_insn ""
3842   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*q,*c*l,*h")
3843         (match_operand:SI 1 "input_operand" "r,m,r,I,J,R,*h,r,r,0"))]
3844   "gpc_reg_operand (operands[0], SImode)
3845    || gpc_reg_operand (operands[1], SImode)"
3846   "@
3847    mr %0,%1
3848    {l%U1%X1|lwz%U1%X1} %0,%1
3849    {st%U0%X0|stw%U0%X0} %1,%0
3850    {lil|li} %0,%1
3851    {liu|lis} %0,%u1
3852    {cal|la} %0,%1(%*)
3853    mf%1 %0
3854    mt%0 %1
3855    mt%0 %1
3856    cror 0,0,0"
3857   [(set_attr "type" "*,load,*,*,*,*,*,*,mtjmpr,*")])
3858
3859 ;; Split a load of a large constant into the appropriate two-insn
3860 ;; sequence.
3861
3862 (define_split
3863   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3864         (match_operand:SI 1 "const_int_operand" ""))]
3865   "(unsigned) (INTVAL (operands[1]) + 0x8000) >= 0x10000
3866    && (INTVAL (operands[1]) & 0xffff) != 0"
3867   [(set (match_dup 0)
3868         (match_dup 2))
3869    (set (match_dup 0)
3870         (ior:SI (match_dup 0)
3871                 (match_dup 3)))]
3872   "
3873 {
3874   operands[2] = gen_rtx (CONST_INT, VOIDmode,
3875                          INTVAL (operands[1]) & 0xffff0000);
3876   operands[3] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[1]) & 0xffff);
3877 }")
3878
3879 (define_insn ""
3880   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
3881         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
3882                     (const_int 0)))
3883    (set (match_operand:SI 0 "gpc_reg_operand" "=r") (match_dup 1))]
3884   ""
3885   "mr. %0,%1"
3886   [(set_attr "type" "compare")])
3887 \f
3888 (define_expand "movhi"
3889   [(set (match_operand:HI 0 "general_operand" "")
3890         (match_operand:HI 1 "any_operand" ""))]
3891   ""
3892   "
3893 {
3894   if (GET_CODE (operands[0]) != REG)
3895     operands[1] = force_reg (HImode, operands[1]);
3896
3897   if (CONSTANT_P (operands[1]) && GET_CODE (operands[1]) != CONST_INT)
3898     {
3899       operands[1] = force_const_mem (HImode, operands[1]);
3900       if (! memory_address_p (HImode, XEXP (operands[1], 0))
3901           && ! reload_in_progress)
3902         operands[1] = change_address (operands[1], HImode,
3903                                       XEXP (operands[1], 0));
3904     }
3905 }")
3906
3907 (define_insn ""
3908   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
3909         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
3910   "gpc_reg_operand (operands[0], HImode)
3911    || gpc_reg_operand (operands[1], HImode)"
3912   "@
3913    mr %0,%1
3914    lhz%U1%X1 %0,%1
3915    sth%U0%X0 %1,%0
3916    {lil|li} %0,%w1
3917    mf%1 %0
3918    mt%0 %1
3919    mt%0 %1
3920    cror 0,0,0"
3921   [(set_attr "type" "*,load,*,*,*,*,mtjmpr,*")])
3922
3923 (define_expand "movqi"
3924   [(set (match_operand:QI 0 "general_operand" "")
3925         (match_operand:QI 1 "any_operand" ""))]
3926   ""
3927   "
3928 {
3929   if (GET_CODE (operands[0]) != REG)
3930     operands[1] = force_reg (QImode, operands[1]);
3931
3932   if (CONSTANT_P (operands[1]) && GET_CODE (operands[1]) != CONST_INT)
3933     {
3934       operands[1] = force_const_mem (QImode, operands[1]);
3935       if (! memory_address_p (QImode, XEXP (operands[1], 0))
3936           && ! reload_in_progress)
3937         operands[1] = change_address (operands[1], QImode,
3938                                       XEXP (operands[1], 0));
3939     }
3940 }")
3941
3942 (define_insn ""
3943   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
3944         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
3945   "gpc_reg_operand (operands[0], QImode)
3946    || gpc_reg_operand (operands[1], QImode)"
3947   "@
3948    mr %0,%1
3949    lbz%U1%X1 %0,%1
3950    stb%U0%X0 %1,%0
3951    {lil|li} %0,%1
3952    mf%1 %0
3953    mt%0 %1
3954    mt%0 %1
3955    cror 0,0,0"
3956   [(set_attr "type" "*,load,*,*,*,*,mtjmpr,*")])
3957 \f
3958 ;; Here is how to move condition codes around.  When we store CC data in
3959 ;; an integer register or memory, we store just the high-order 4 bits.
3960 ;; This lets us not shift in the most common case of CR0.
3961 (define_expand "movcc"
3962   [(set (match_operand:CC 0 "nonimmediate_operand" "")
3963         (match_operand:CC 1 "nonimmediate_operand" ""))]
3964   ""
3965   "")
3966
3967 (define_insn ""
3968   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,y,r,r,r,r,m")
3969         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,m,r"))]
3970   "register_operand (operands[0], CCmode)
3971    || register_operand (operands[1], CCmode)"
3972   "@
3973    mcrf %0,%1
3974    mtcrf 128,%1
3975    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
3976    mfcr %0
3977    mfcr %0\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
3978    mr %0,%1
3979    {l%U1%X1|lwz%U1%X1} %0,%1
3980    {st%U0%U1|stw%U0%U1} %1,%0"
3981   [(set_attr "type" "*,*,*,compare,*,*,load,*")
3982    (set_attr "length" "*,*,12,*,8,*,*,*")])
3983 \f
3984 ;; For floating-point, we normally deal with the floating-point registers
3985 ;; unless -msoft-float is used.  The sole exception is that parameter passing
3986 ;; can produce floating-point values in fixed-point registers.  Unless the
3987 ;; value is a simple constant or already in memory, we deal with this by
3988 ;; allocating memory and copying the value explicitly via that memory location.
3989 (define_expand "movsf"
3990   [(set (match_operand:SF 0 "nonimmediate_operand" "")
3991         (match_operand:SF 1 "any_operand" ""))]
3992   ""
3993   "
3994 {
3995   /* If we are called from reload, we might be getting a SUBREG of a hard
3996      reg.  So expand it.  */
3997   if (GET_CODE (operands[0]) == SUBREG
3998       && GET_CODE (SUBREG_REG (operands[0])) == REG
3999       && REGNO (SUBREG_REG (operands[0])) < FIRST_PSEUDO_REGISTER)
4000     operands[0] = alter_subreg (operands[0]);
4001   if (GET_CODE (operands[1]) == SUBREG
4002       && GET_CODE (SUBREG_REG (operands[1])) == REG
4003       && REGNO (SUBREG_REG (operands[1])) < FIRST_PSEUDO_REGISTER)
4004     operands[1] = alter_subreg (operands[1]);
4005
4006   if (TARGET_SOFT_FLOAT && GET_CODE (operands[0]) == MEM)
4007     operands[1] = force_reg (SFmode, operands[1]);
4008
4009   else if (TARGET_HARD_FLOAT)
4010     {
4011       if (GET_CODE (operands[1]) == REG && REGNO (operands[1]) < 32)
4012         {
4013           /* If this is a store to memory or another integer register do the
4014              move directly.  Otherwise store to a temporary stack slot and
4015              load from there into a floating point register.  */
4016
4017           if (GET_CODE (operands[0]) == MEM
4018               || (GET_CODE (operands[0]) == REG
4019                   && (REGNO (operands[0]) < 32
4020                       || (reload_in_progress
4021                           && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER))))
4022             {
4023               emit_move_insn (operand_subword (operands[0], 0, 0, SFmode),
4024                               operand_subword (operands[1], 0, 0, SFmode));
4025               DONE;
4026             }
4027           else
4028             {
4029               rtx stack_slot = assign_stack_temp (SFmode, 4, 0);
4030
4031               emit_move_insn (stack_slot, operands[1]);
4032               emit_move_insn (operands[0], stack_slot);
4033               DONE;
4034             }
4035         }
4036
4037       if (GET_CODE (operands[0]) == MEM)
4038         {
4039           /* If operands[1] is a register, it may have double-precision data
4040              in it, so truncate it to single precision.  We need not do
4041              this for POWERPC.  */
4042           if (! TARGET_POWERPC && GET_CODE (operands[1]) == REG)
4043             {
4044               rtx newreg = reload_in_progress ? operands[1] : gen_reg_rtx (SFmode);
4045               emit_insn (gen_truncdfsf2 (newreg,
4046                                          gen_rtx (SUBREG, DFmode, operands[1], 0)));
4047               operands[1] = newreg;
4048             }
4049
4050           operands[1] = force_reg (SFmode, operands[1]);
4051         }
4052
4053       if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) < 32)
4054         {
4055           if (GET_CODE (operands[1]) == MEM
4056 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && ! defined(REAL_IS_NOT_DOUBLE)
4057               || GET_CODE (operands[1]) == CONST_DOUBLE
4058 #endif
4059               || (GET_CODE (operands[1]) == REG
4060                   && (REGNO (operands[1]) < 32
4061                       || (reload_in_progress
4062                           && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER))))
4063             {
4064               emit_move_insn (operand_subword (operands[0], 0, 0, SFmode),
4065                               operand_subword (operands[1], 0, 0, SFmode));
4066               DONE;
4067             }
4068           else
4069             {
4070               rtx stack_slot = assign_stack_temp (SFmode, 4, 0);
4071
4072               emit_move_insn (stack_slot, operands[1]);
4073               emit_move_insn (operands[0], stack_slot);
4074               DONE;
4075             }
4076         }
4077     }
4078
4079   if (CONSTANT_P (operands[1]))
4080     {
4081       operands[1] = force_const_mem (SFmode, operands[1]);
4082       if (! memory_address_p (SFmode, XEXP (operands[1], 0))
4083           && ! reload_in_progress)
4084         operands[1] = change_address (operands[1], SFmode,
4085                                       XEXP (operands[1], 0));
4086     }
4087 }")
4088
4089 (define_split
4090   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4091         (match_operand:SF 1 "easy_fp_constant" ""))]
4092   "reload_completed && REGNO (operands[0]) <= 31"
4093   [(set (match_dup 2) (match_dup 3))]
4094   "
4095 { operands[2] = operand_subword (operands[0], 0, 0, SFmode);
4096   operands[3] = operand_subword (operands[1], 0, 0, SFmode); }")
4097   
4098 (define_insn ""
4099   [(set (match_operand:SF 0 "fp_reg_or_mem_operand" "=f,f,m")
4100         (match_operand:SF 1 "input_operand" "f,m,f"))]
4101   "(gpc_reg_operand (operands[0], SFmode)
4102    || gpc_reg_operand (operands[1], SFmode)) && TARGET_HARD_FLOAT"
4103   "@
4104    fmr %0,%1
4105    lfs%U1%X1 %0,%1
4106    stfs%U0%X0 %1,%0"
4107   [(set_attr "type" "fp,fpload,*")])
4108
4109 (define_insn ""
4110   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
4111         (match_operand:SF 1 "input_operand" "r,m,r,I,J,R"))]
4112   "(gpc_reg_operand (operands[0], SFmode)
4113    || gpc_reg_operand (operands[1], SFmode)) && TARGET_SOFT_FLOAT"
4114   "@
4115    mr %0,%1
4116    {l%U1%X1|lwz%U1%X1} %0,%1
4117    {st%U0%X0|stw%U0%X0} %1,%0
4118    {lil|li} %0,%1
4119    {liu|lis} %0,%u1
4120    {cal|la} %0,%1(%*)"
4121   [(set_attr "type" "*,load,*,*,*,*")])
4122
4123 \f
4124 (define_expand "movdf"
4125   [(set (match_operand:DF 0 "nonimmediate_operand" "")
4126         (match_operand:DF 1 "any_operand" ""))]
4127   ""
4128   "
4129 {
4130   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
4131     {
4132       emit_move_insn (operand_subword (operands[0], 1, 1, DFmode),
4133                       operand_subword_force (operands[1], 1, DFmode));
4134       emit_move_insn (operand_subword (operands[0], 0, 1, DFmode),
4135                       operand_subword_force (operands[1], 0, DFmode));
4136       DONE;
4137     }
4138
4139   if (GET_CODE (operands[0]) != REG)
4140     operands[1] = force_reg (DFmode, operands[1]);
4141
4142   if (CONSTANT_P (operands[1]) && ! easy_fp_constant (operands[1], DFmode))
4143     {
4144       operands[1] = force_const_mem (DFmode, operands[1]);
4145       if (! memory_address_p (DFmode, XEXP (operands[1], 0))
4146           && ! reload_in_progress)
4147         operands[1] = change_address (operands[1], DFmode,
4148                                       XEXP (operands[1], 0));
4149     }
4150 }")
4151
4152 (define_split
4153   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4154         (match_operand:DF 1 "easy_fp_constant" ""))]
4155   "reload_completed && REGNO (operands[0]) <= 31"
4156   [(set (match_dup 2) (match_dup 3))
4157    (set (match_dup 4) (match_dup 5))]
4158   "
4159 { operands[2] = operand_subword (operands[0], 0, 0, DFmode);
4160   operands[3] = operand_subword (operands[1], 0, 0, DFmode);
4161   operands[4] = operand_subword (operands[0], 1, 0, DFmode);
4162   operands[5] = operand_subword (operands[1], 1, 0, DFmode); }")
4163
4164 ;; Don't have reload use general registers to load a constant.  First,
4165 ;; it might not work if the output operand has is the equivalent of
4166 ;; a non-offsettable memref, but also it is less efficient than loading
4167 ;; the constant into an FP register, since it will probably be used there.
4168 ;; The "??" is a kludge until we can figure out a more reasonable way
4169 ;; of handling these non-offsettable values.
4170 (define_insn ""
4171   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,o,!r,f,f,m")
4172         (match_operand:DF 1 "input_operand" "r,o,r,G,f,m,f"))]
4173   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT
4174    && (register_operand (operands[0], DFmode)
4175        || register_operand (operands[1], DFmode))"
4176   "*
4177 {
4178   switch (which_alternative)
4179     {
4180     case 0:
4181       /* We normally copy the low-numbered register first.  However, if
4182          the first register operand 0 is the same as the second register of
4183          operand 1, we must copy in the opposite order.  */
4184       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
4185         return \"mr %L0,%L1\;mr %0,%1\";
4186       else
4187         return \"mr %0,%1\;mr %L0,%L1\";
4188     case 1:
4189       /* If the low-address word is used in the address, we must load it
4190          last.  Otherwise, load it first.  Note that we cannot have
4191          auto-increment in that case since the address register is known to be
4192          dead.  */
4193       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4194                              operands [1], 0))
4195         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
4196       else
4197         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
4198     case 2:
4199       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
4200     case 3:
4201       return \"#\";
4202     case 4:
4203       return \"fmr %0,%1\";
4204     case 5:
4205       return \"lfd%U1%X1 %0,%1\";
4206     case 6:
4207       return \"stfd%U0%X0 %1,%0\";
4208     }
4209 }"
4210   [(set_attr "type" "*,load,*,*,fp,fpload,*")
4211    (set_attr "length" "8,8,8,8,*,*,*")])
4212
4213 (define_insn ""
4214   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,o,r")
4215         (match_operand:DF 1 "input_operand" "r,o,r,G"))]
4216   "! TARGET_POWERPC64 && TARGET_SOFT_FLOAT
4217    && (register_operand (operands[0], DFmode)
4218        || register_operand (operands[1], DFmode))"
4219   "*
4220 {
4221   switch (which_alternative)
4222     {
4223     case 0:
4224       /* We normally copy the low-numbered register first.  However, if
4225          the first register operand 0 is the same as the second register of
4226          operand 1, we must copy in the opposite order.  */
4227       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
4228         return \"mr %L0,%L1\;mr %0,%1\";
4229       else
4230         return \"mr %0,%1\;mr %L0,%L1\";
4231     case 1:
4232       /* If the low-address word is used in the address, we must load it
4233          last.  Otherwise, load it first.  Note that we cannot have
4234          auto-increment in that case since the address register is known to be
4235          dead.  */
4236       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4237                              operands [1], 0))
4238         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
4239       else
4240         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
4241     case 2:
4242       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
4243     case 3:
4244       return \"#\";
4245     }
4246 }"
4247   [(set_attr "type" "*,load,*,*")
4248    (set_attr "length" "8,8,8,8")])
4249
4250 (define_insn ""
4251   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,o,!r,f,f,m")
4252         (match_operand:DF 1 "input_operand" "r,o,r,G,f,m,f"))]
4253   "TARGET_POWERPC64 && TARGET_HARD_FLOAT
4254    && (register_operand (operands[0], DFmode)
4255        || register_operand (operands[1], DFmode))"
4256   "@
4257    mr %0,%1
4258    ld%U1%X1 %0,%1
4259    sd%U0%X0 %1,%0
4260    #
4261    fmr %0,%1
4262    lfd%U1%X1 %0,%1
4263    stfd%U0%X0 %1,%0"
4264   [(set_attr "type" "*,load,*,*,fp,fpload,*")])
4265
4266 (define_insn ""
4267   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,o,r")
4268         (match_operand:DF 1 "input_operand" "r,o,r,G"))]
4269   "TARGET_POWERPC64 && TARGET_SOFT_FLOAT
4270    && (register_operand (operands[0], DFmode)
4271        || register_operand (operands[1], DFmode))"
4272   "@
4273    mr %0,%1
4274    ld%U1%X1 %0,%1
4275    sd%U0%X0 %1,%0
4276    #"
4277   [(set_attr "type" "*,load,*,*")])
4278 \f
4279 ;; Next come the multi-word integer load and store and the load and store
4280 ;; multiple insns.
4281 (define_expand "movdi"
4282   [(set (match_operand:DI 0 "general_operand" "")
4283         (match_operand:DI 1 "general_operand" ""))]
4284   ""
4285   "
4286 {
4287   if (GET_CODE (operands[1]) == CONST_DOUBLE
4288       || GET_CODE (operands[1]) == CONST_INT)
4289     {
4290       emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
4291                       operand_subword (operands[1], 0, 0, DImode));
4292       emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
4293                       operand_subword (operands[1], 1, 0, DImode));
4294       DONE;
4295     }
4296
4297   if (GET_CODE (operands[0]) == MEM)
4298     operands[1] = force_reg (DImode, operands[1]);
4299
4300       /* Stores between FPR and any non-FPR registers must go through a
4301          temporary stack slot.  */
4302
4303   if (GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == REG
4304       && ((FP_REGNO_P (REGNO (operands[0]))
4305            && ! FP_REGNO_P (REGNO (operands[1])))
4306           || (FP_REGNO_P (REGNO (operands[1]))
4307               && ! FP_REGNO_P (REGNO (operands[0])))))
4308     {
4309       rtx stack_slot = assign_stack_temp (DImode, 8, 0);
4310
4311       emit_move_insn (stack_slot, operands[1]);
4312       emit_move_insn (operands[0], stack_slot);
4313       DONE;
4314     }
4315 }")
4316
4317 (define_insn ""
4318   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,f,f,m")
4319         (match_operand:DI 1 "input_operand" "r,m,r,f,m,f"))]
4320   "! TARGET_POWERPC64 && (gpc_reg_operand (operands[0], DImode)
4321    || gpc_reg_operand (operands[1], DImode))"
4322   "*
4323 {
4324   switch (which_alternative)
4325     {
4326     case 0:
4327       /* We normally copy the low-numbered register first.  However, if
4328          the first register operand 0 is the same as the second register of
4329          operand 1, we must copy in the opposite order.  */
4330       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
4331         return \"mr %L0,%L1\;mr %0,%1\";
4332       else
4333         return \"mr %0,%1\;mr %L0,%L1\";
4334     case 1:
4335       /* If the low-address word is used in the address, we must load it
4336          last.  Otherwise, load it first.  Note that we cannot have
4337          auto-increment in that case since the address register is known to be
4338          dead.  */
4339       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4340                              operands [1], 0))
4341         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
4342       else
4343         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
4344     case 2:
4345       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
4346     case 3:
4347       return \"fmr %0,%1\";
4348     case 4:
4349       return \"lfd%U1%X1 %0,%1\";
4350     case 5:
4351       return \"stfd%U0%X0 %1,%0\";
4352     }
4353 }"
4354   [(set_attr "type" "*,load,*,fp,fpload,*")
4355    (set_attr "length" "8,8,8,*,*,*")])
4356
4357 (define_insn ""
4358   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,f,f,m,r,*h")
4359         (match_operand:DI 1 "input_operand" "r,m,r,I,J,R,f,m,f,*h,r"))]
4360   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], DImode)
4361    || gpc_reg_operand (operands[1], DImode))"
4362   "@
4363    mr %0,%1
4364    ld%U1%X1 %0,%1
4365    sd%U0%X0 %1,%0
4366    li %0,%1
4367    lis %0,%u1
4368    {cal|la} %0,%1(%*)
4369    fmr %0,%1
4370    lfd%U1%X1 %0,%1
4371    stfd%U0%X0 %1,%0
4372    mf%1 %0
4373    mt%0 %1"
4374   [(set_attr "type" "*,load,*,*,*,*,fp,fpload,*,*,mtjmpr")])
4375 \f
4376 ;; TImode is similar, except that we usually want to compute the address into
4377 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
4378 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
4379 (define_expand "movti"
4380   [(parallel [(set (match_operand:TI 0 "general_operand" "")
4381                    (match_operand:TI 1 "general_operand" ""))
4382               (clobber (scratch:SI))])]
4383   "TARGET_MULTIPLE || TARGET_POWERPC64"
4384   "
4385 {
4386   if (GET_CODE (operands[0]) == MEM)
4387     operands[1] = force_reg (TImode, operands[1]);
4388
4389   if (GET_CODE (operands[0]) == MEM
4390       && GET_CODE (XEXP (operands[0], 0)) != REG
4391       && ! reload_in_progress)
4392     operands[0] = change_address (operands[0], TImode,
4393                                   copy_addr_to_reg (XEXP (operands[0], 0)));
4394
4395   if (GET_CODE (operands[1]) == MEM
4396       && GET_CODE (XEXP (operands[1], 0)) != REG
4397       && ! reload_in_progress)
4398     operands[1] = change_address (operands[1], TImode,
4399                                   copy_addr_to_reg (XEXP (operands[1], 0)));
4400 }")
4401
4402 ;; We say that MQ is clobbered in the last alternative because the first
4403 ;; alternative would never get used otherwise since it would need a reload
4404 ;; while the 2nd alternative would not.  We put memory cases first so they
4405 ;; are preferred.  Otherwise, we'd try to reload the output instead of
4406 ;; giving the SCRATCH mq.
4407 (define_insn ""
4408   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
4409         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
4410    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
4411   "TARGET_MULTIPLE && TARGET_POWER && ! TARGET_POWERPC64
4412    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
4413   "*
4414 {
4415   switch (which_alternative)
4416     {
4417     default:
4418       abort ();
4419
4420     case 0:
4421       return \"{stsi|stswi} %1,%P0,16\";
4422
4423     case 1:
4424       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\;{st|stw} %Y1,%Y0\;{st|stw} %Z1,%Z0\";
4425
4426     case 2:
4427       /* Normally copy registers with lowest numbered register copied first.
4428          But copy in the other order if the first register of the output
4429          is the second, third, or fourth register in the input.  */
4430       if (REGNO (operands[0]) >= REGNO (operands[1]) + 1
4431           && REGNO (operands[0]) <= REGNO (operands[1]) + 3)
4432         return \"mr %Z0,%Z1\;mr %Y0,%Y1\;mr %L0,%L1\;mr %0,%1\";
4433       else
4434         return \"mr %0,%1\;mr %L0,%L1\;mr %Y0,%Y1\;mr %Z0,%Z1\";
4435     case 3:
4436       /* If the address is not used in the output, we can use lsi.  Otherwise,
4437          fall through to generating four loads.  */
4438       if (! reg_overlap_mentioned_p (operands[0], operands[1]))
4439         return \"{lsi|lswi} %0,%P1,16\";
4440       /* ... fall through ... */
4441     case 4:
4442       /* If the address register is the same as the register for the lowest-
4443          addressed word, load it last.  Similarly for the next two words.
4444          Otherwise load lowest address to highest.  */
4445       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4446                              operands[1], 0))
4447         return \"{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %0,%1\";
4448       else if (refers_to_regno_p (REGNO (operands[0]) + 1,
4449                                   REGNO (operands[0]) + 2, operands[1], 0))
4450         return \"{l|lwz} %0,%1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %L0,%L1\";
4451       else if (refers_to_regno_p (REGNO (operands[0]) + 2,
4452                                   REGNO (operands[0]) + 3, operands[1], 0))
4453         return \"{l|lwz} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Z0,%Z1\;{l|lwz} %Y0,%Y1\";
4454       else
4455         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\";
4456     }
4457 }"
4458   [(set_attr "type" "*,load,load,*,*")
4459    (set_attr "length" "*,16,16,*,16")])
4460
4461 (define_insn ""
4462   [(set (match_operand:TI 0 "reg_or_mem_operand" "=m,????r,????r")
4463         (match_operand:TI 1 "reg_or_mem_operand" "r,r,m"))
4464    (clobber (match_scratch:SI 2 "=X,X,X"))]
4465   "TARGET_MULTIPLE && !TARGET_POWER && ! TARGET_POWERPC64
4466    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
4467   "*
4468 {
4469   switch (which_alternative)
4470     {
4471     default:
4472       abort ();
4473
4474     case 0:
4475       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\;{st|stw} %Y1,%Y0\;{st|stw} %Z1,%Z0\";
4476
4477     case 1:
4478       /* Normally copy registers with lowest numbered register copied first.
4479          But copy in the other order if the first register of the output
4480          is the second, third, or fourth register in the input.  */
4481       if (REGNO (operands[0]) >= REGNO (operands[1]) + 1
4482           && REGNO (operands[0]) <= REGNO (operands[1]) + 3)
4483         return \"mr %Z0,%Z1\;mr %Y0,%Y1\;mr %L0,%L1\;mr %0,%1\";
4484       else
4485         return \"mr %0,%1\;mr %L0,%L1\;mr %Y0,%Y1\;mr %Z0,%Z1\";
4486     case 2:
4487       /* If the address register is the same as the register for the lowest-
4488          addressed word, load it last.  Similarly for the next two words.
4489          Otherwise load lowest address to highest.  */
4490       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4491                              operands[1], 0))
4492         return \"{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %0,%1\";
4493       else if (refers_to_regno_p (REGNO (operands[0]) + 1,
4494                                   REGNO (operands[0]) + 2, operands[1], 0))
4495         return \"{l|lwz} %0,%1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %L0,%L1\";
4496       else if (refers_to_regno_p (REGNO (operands[0]) + 2,
4497                                   REGNO (operands[0]) + 3, operands[1], 0))
4498         return \"{l|lwz} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Z0,%Z1\;{l|lwz} %Y0,%Y1\";
4499       else
4500         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\";
4501     }
4502 }"
4503   [(set_attr "type" "load,*,*")
4504    (set_attr "length" "16,16,16")])
4505
4506 (define_insn ""
4507   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,r,m")
4508         (match_operand:TI 1 "input_operand" "r,m,r"))]
4509   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
4510    || gpc_reg_operand (operands[1], TImode))"
4511   "*
4512 {
4513   switch (which_alternative)
4514     {
4515     case 0:
4516       /* We normally copy the low-numbered register first.  However, if
4517          the first register operand 0 is the same as the second register of
4518          operand 1, we must copy in the opposite order.  */
4519       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
4520         return \"mr %L0,%L1\;mr %0,%1\";
4521       else
4522         return \"mr %0,%1\;mr %L0,%L1\";
4523     case 1:
4524       /* If the low-address word is used in the address, we must load it
4525          last.  Otherwise, load it first.  Note that we cannot have
4526          auto-increment in that case since the address register is known to be
4527          dead.  */
4528       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4529                              operands [1], 0))
4530         return \"ld %L0,%L1\;ld %0,%1\";
4531       else
4532         return \"ld%U1 %0,%1\;ld %L0,%L1\";
4533     case 2:
4534       return \"std%U0 %1,%0\;std %L1,%L0\";
4535     }
4536 }"
4537   [(set_attr "type" "*,load,*")
4538    (set_attr "length" "8,8,8")])
4539 \f
4540 (define_expand "load_multiple"
4541   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
4542                           (match_operand:SI 1 "" ""))
4543                      (use (match_operand:SI 2 "" ""))])]
4544   "TARGET_MULTIPLE"
4545   "
4546 {
4547   int regno;
4548   int count;
4549   rtx from;
4550   int i;
4551
4552   /* Support only loading a constant number of fixed-point registers from
4553      memory and only bother with this if more than two; the machine
4554      doesn't support more than eight.  */
4555   if (GET_CODE (operands[2]) != CONST_INT
4556       || INTVAL (operands[2]) <= 2
4557       || INTVAL (operands[2]) > 8
4558       || GET_CODE (operands[1]) != MEM
4559       || GET_CODE (operands[0]) != REG
4560       || REGNO (operands[0]) >= 32)
4561     FAIL;
4562
4563   count = INTVAL (operands[2]);
4564   regno = REGNO (operands[0]);
4565
4566   operands[3] = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (count));
4567   from = force_reg (SImode, XEXP (operands[1], 0));
4568
4569   for (i = 0; i < count; i++)
4570     XVECEXP (operands[3], 0, i)
4571       = gen_rtx (SET, VOIDmode, gen_rtx (REG, SImode, regno + i),
4572                  gen_rtx (MEM, SImode, plus_constant (from, i * 4)));
4573 }")
4574
4575 (define_insn ""
4576   [(match_parallel 0 "load_multiple_operation"
4577                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
4578                          (match_operand:SI 2 "indirect_operand" "Q"))])]
4579   "TARGET_MULTIPLE"
4580   "*
4581 {
4582   /* We have to handle the case where the pseudo used to contain the address
4583      is assigned to one of the output registers.  In that case, do the
4584      lsi, but then load the correct value.  This is a bit of a mess, but is
4585      the best we can do.
4586      We set the length attribute to the maximum possible size (8 bytes).  */
4587   static char result[100];
4588   char newload[40];
4589   int i;
4590
4591   strcpy (result, \"{lsi|lswi} %1,%P2,%N0\");
4592   for (i = 0; i < XVECLEN (operands[0], 0); i++)
4593     if (refers_to_regno_p (REGNO (operands[1]) + i,
4594                            REGNO (operands[1]) + i + 1, operands[2], 0))
4595       {
4596         sprintf (newload, \"\;{l|lwz} %d,%d(%d)\",
4597                  REGNO (operands[1]) + i,
4598                  i * 4, REGNO (XEXP (operands[2], 0)));
4599         strcat (result, newload);
4600       }
4601
4602   return result;
4603 }"
4604   [(set_attr "type" "load")
4605    (set_attr "length" "8")])
4606 \f
4607
4608 (define_expand "store_multiple"
4609   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
4610                           (match_operand:SI 1 "" ""))
4611                      (clobber (scratch:SI))
4612                      (use (match_operand:SI 2 "" ""))])]
4613   "TARGET_MULTIPLE"
4614   "
4615 {
4616   int regno;
4617   int count;
4618   rtx to;
4619   int i;
4620
4621   /* Support only storing a constant number of fixed-point registers to
4622      memory and only bother with this if more than two; the machine
4623      doesn't support more than eight.  */
4624   if (GET_CODE (operands[2]) != CONST_INT
4625       || INTVAL (operands[2]) <= 2
4626       || INTVAL (operands[2]) > 8
4627       || GET_CODE (operands[0]) != MEM
4628       || GET_CODE (operands[1]) != REG
4629       || REGNO (operands[1]) >= 32)
4630     FAIL;
4631
4632   count = INTVAL (operands[2]);
4633   regno = REGNO (operands[1]);
4634
4635   operands[3] = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (count + 1));
4636   to = force_reg (SImode, XEXP (operands[0], 0));
4637
4638   XVECEXP (operands[3], 0, 0)
4639     = gen_rtx (SET, VOIDmode, gen_rtx (MEM, SImode, to), operands[1]);
4640   XVECEXP (operands[3], 0, 1) = gen_rtx (CLOBBER, VOIDmode,
4641                                                   gen_rtx (SCRATCH, SImode));
4642
4643   for (i = 1; i < count; i++)
4644     XVECEXP (operands[3], 0, i + 1)
4645       = gen_rtx (SET, VOIDmode,
4646                  gen_rtx (MEM, SImode, plus_constant (to, i * 4)),
4647                  gen_rtx (REG, SImode, regno + i));
4648 }")
4649
4650 (define_insn ""
4651   [(match_parallel 0 "store_multiple_operation"
4652                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
4653                          (match_operand:SI 2 "gpc_reg_operand" "r"))
4654                     (clobber (match_scratch:SI 3 "=q"))])]
4655   "TARGET_MULTIPLE && TARGET_POWER"
4656   "{stsi|stswi} %2,%P1,%O0")
4657
4658 (define_insn ""
4659   [(match_parallel 0 "store_multiple_operation"
4660                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
4661                          (match_operand:SI 2 "gpc_reg_operand" "r"))
4662                     (clobber (match_scratch:SI 3 "X"))])]
4663   "TARGET_MULTIPLE && !TARGET_POWER"
4664   "{stsi|stswi} %2,%P1,%O0")
4665 \f
4666 ;; Define insns that do load or store with update.  Some of these we can 
4667 ;; get by using pre-decrement or pre-increment, but the hardware can also
4668 ;; do cases where the increment is not the size of the object.
4669 ;;
4670 ;; In all these cases, we use operands 0 and 1 for the register being
4671 ;; incremented because those are the operands that local-alloc will
4672 ;; tie and these are the pair most likely to be tieable (and the ones
4673 ;; that will benefit the most).
4674
4675 (define_insn ""
4676   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
4677         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
4678                          (match_operand:DI 2 "reg_or_short_operand" "r,I"))))
4679    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
4680         (plus:DI (match_dup 1) (match_dup 2)))]
4681   "TARGET_POWERPC64"
4682   "@
4683    ldux %3,%0,%2
4684    ldu %3,%2(%0)"
4685   [(set_attr "type" "load")])
4686
4687 (define_insn ""
4688   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
4689         (sign_extend:DI
4690          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
4691                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
4692    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
4693         (plus:DI (match_dup 1) (match_dup 2)))]
4694   "TARGET_POWERPC64"
4695   "lwaux %3,%0,%2"
4696   [(set_attr "type" "load")])
4697
4698 (define_insn ""
4699   [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
4700                          (match_operand:DI 2 "reg_or_short_operand" "r,I")))
4701         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
4702    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
4703         (plus:DI (match_dup 1) (match_dup 2)))]
4704   "TARGET_POWERPC64"
4705   "@
4706    stdux %3,%0,%2
4707    stdu %3,%2(%0)")
4708
4709 (define_insn ""
4710   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
4711         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4712                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
4713    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4714         (plus:SI (match_dup 1) (match_dup 2)))]
4715   ""
4716   "@
4717    {lux|lwzux} %3,%0,%2
4718    {lu|lwzu} %3,%2(%0)"
4719   [(set_attr "type" "load")])
4720
4721 (define_insn ""
4722   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4723                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
4724         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
4725    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4726         (plus:SI (match_dup 1) (match_dup 2)))]
4727   ""
4728   "@
4729    {stux|stwux} %3,%0,%2
4730    {stu|stwu} %3,%2(%0)")
4731
4732 (define_insn ""
4733   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
4734         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4735                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
4736    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4737         (plus:SI (match_dup 1) (match_dup 2)))]
4738   ""
4739   "@
4740    lhzux %3,%0,%2
4741    lhzu %3,%2(%0)"
4742   [(set_attr "type" "load")])
4743
4744 (define_insn ""
4745   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
4746         (zero_extend:SI
4747          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4748                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
4749    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4750         (plus:SI (match_dup 1) (match_dup 2)))]
4751   ""
4752   "@
4753    lhzux %3,%0,%2
4754    lhzu %3,%2(%0)"
4755   [(set_attr "type" "load")])
4756
4757 (define_insn ""
4758   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
4759         (sign_extend:SI
4760          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4761                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
4762    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4763         (plus:SI (match_dup 1) (match_dup 2)))]
4764   ""
4765   "@
4766    lhaux %3,%0,%2
4767    lhau %3,%2(%0)"
4768   [(set_attr "type" "load")])
4769
4770 (define_insn ""
4771   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4772                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
4773         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
4774    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4775         (plus:SI (match_dup 1) (match_dup 2)))]
4776   ""
4777   "@
4778    sthux %3,%0,%2
4779    sthu %3,%2(%0)")
4780
4781 (define_insn ""
4782   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
4783         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4784                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
4785    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4786         (plus:SI (match_dup 1) (match_dup 2)))]
4787   ""
4788   "@
4789    lbzux %3,%0,%2
4790    lbzu %3,%2(%0)"
4791   [(set_attr "type" "load")])
4792
4793 (define_insn ""
4794   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
4795         (zero_extend:SI
4796          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4797                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
4798    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4799         (plus:SI (match_dup 1) (match_dup 2)))]
4800   ""
4801   "@
4802    lbzux %3,%0,%2
4803    lbzu %3,%2(%0)"
4804   [(set_attr "type" "load")])
4805
4806 (define_insn ""
4807   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4808                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
4809         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
4810    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4811         (plus:SI (match_dup 1) (match_dup 2)))]
4812   ""
4813   "@
4814    stbux %3,%0,%2
4815    stbu %3,%2(%0)")
4816
4817 (define_insn ""
4818   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
4819         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4820                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
4821    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4822         (plus:SI (match_dup 1) (match_dup 2)))]
4823   "TARGET_HARD_FLOAT"
4824   "@
4825    lfsux %3,%0,%2
4826    lfsu %3,%2(%0)"
4827   [(set_attr "type" "fpload")])
4828
4829 (define_insn ""
4830   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4831                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
4832         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
4833    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4834         (plus:SI (match_dup 1) (match_dup 2)))]
4835   "TARGET_HARD_FLOAT"
4836   "@
4837    stfsux %3,%0,%2
4838    stfsu %3,%2(%0)")
4839
4840 (define_insn ""
4841   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
4842         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4843                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
4844    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4845         (plus:SI (match_dup 1) (match_dup 2)))]
4846   "TARGET_HARD_FLOAT"
4847   "@
4848    lfdux %3,%0,%2
4849    lfdu %3,%2(%0)"
4850   [(set_attr "type" "fpload")])
4851
4852 (define_insn ""
4853   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
4854                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
4855         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
4856    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
4857         (plus:SI (match_dup 1) (match_dup 2)))]
4858   "TARGET_HARD_FLOAT"
4859   "@
4860    stfdux %3,%0,%2
4861    stfdu %3,%2(%0)")
4862
4863 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
4864
4865 (define_peephole
4866   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4867         (match_operand:DF 1 "memory_operand" ""))
4868    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
4869         (match_operand:DF 3 "memory_operand" ""))]
4870   "TARGET_POWER2
4871    && TARGET_HARD_FLOAT
4872    && registers_ok_for_quad_peep (operands[0], operands[2])
4873    && ! MEM_VOLATILE_P (operands[1]) && ! MEM_VOLATILE_P (operands[3])
4874    && addrs_ok_for_quad_peep (XEXP (operands[1], 0), XEXP (operands[3], 0))"
4875   "lfq%U1%X1 %0,%1")
4876
4877 (define_peephole
4878   [(set (match_operand:DF 0 "memory_operand" "")
4879         (match_operand:DF 1 "gpc_reg_operand" "f"))
4880    (set (match_operand:DF 2 "memory_operand" "")
4881         (match_operand:DF 3 "gpc_reg_operand" "f"))]
4882   "TARGET_POWER2
4883    && TARGET_HARD_FLOAT
4884    && registers_ok_for_quad_peep (operands[1], operands[3])
4885    && ! MEM_VOLATILE_P (operands[0]) && ! MEM_VOLATILE_P (operands[2])
4886    && addrs_ok_for_quad_peep (XEXP (operands[0], 0), XEXP (operands[2], 0))"
4887   "stfq%U0%X0 %1,%0")
4888 \f
4889 ;; Next come insns related to the calling sequence.
4890 ;;
4891 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
4892 ;; We move the back-chain and decrement the stack pointer.  
4893
4894 (define_expand "allocate_stack"
4895   [(set (reg:SI 1)
4896         (minus:SI (reg:SI 1) (match_operand:SI 0 "reg_or_short_operand" "")))]
4897   ""
4898   "
4899 { rtx chain = gen_reg_rtx (SImode);
4900   rtx stack_bot = gen_rtx (MEM, Pmode, stack_pointer_rtx);
4901
4902   emit_move_insn (chain, stack_bot);
4903   emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, operands[0]));
4904   emit_move_insn (stack_bot, chain);
4905   DONE;
4906 }")
4907
4908 ;; These patterns say how to save and restore the stack pointer.  We need not
4909 ;; save the stack pointer at function level since we are careful to
4910 ;; preserve the backchain.  At block level, we have to restore the backchain
4911 ;; when we restore the stack pointer.
4912 ;;
4913 ;; For nonlocal gotos, we must save both the stack pointer and its
4914 ;; backchain and restore both.  Note that in the nonlocal case, the
4915 ;; save area is a memory location.
4916
4917 (define_expand "save_stack_function"
4918   [(use (const_int 0))]
4919   ""
4920   "")
4921
4922 (define_expand "restore_stack_function"
4923   [(use (const_int 0))]
4924   ""
4925   "")
4926
4927 (define_expand "restore_stack_block"
4928   [(set (match_dup 2) (mem:SI (match_operand:SI 0 "register_operand" "")))
4929    (set (match_dup 0) (match_operand:SI 1 "register_operand" ""))
4930    (set (mem:SI (match_dup 0)) (match_dup 2))]
4931   ""
4932   "
4933 { operands[2] = gen_reg_rtx (SImode); }")
4934
4935 (define_expand "save_stack_nonlocal"
4936   [(match_operand:DI 0 "memory_operand" "")
4937    (match_operand:SI 1 "register_operand" "")]
4938   ""
4939   "
4940 {
4941   rtx temp = gen_reg_rtx (SImode);
4942
4943   /* Copy the backchain to the first word, sp to the second.  */
4944   emit_move_insn (temp, gen_rtx (MEM, SImode, operands[1]));
4945   emit_move_insn (operand_subword (operands[0], 0, 0, DImode), temp);
4946   emit_move_insn (operand_subword (operands[0], 1, 0, DImode), operands[1]);
4947   DONE;
4948 }")
4949                   
4950 (define_expand "restore_stack_nonlocal"
4951   [(match_operand:SI 0 "register_operand" "")
4952    (match_operand:DI 1 "memory_operand" "")]
4953   ""
4954   "
4955 {
4956   rtx temp = gen_reg_rtx (SImode);
4957
4958   /* Restore the backchain from the first word, sp from the second.  */
4959   emit_move_insn (temp, operand_subword (operands[1], 0, 0, DImode));
4960   emit_move_insn (operands[0], operand_subword (operands[1], 1, 0, DImode));
4961   emit_move_insn (gen_rtx (MEM, SImode, operands[0]), temp);
4962   DONE;
4963 }")
4964 \f
4965 ;; A function pointer is a pointer to a data area whose first word contains
4966 ;; the actual address of the function, whose second word contains a pointer
4967 ;; to its TOC, and whose third word contains a value to place in the static
4968 ;; chain register (r11).  Note that if we load the static chain, our 
4969 ;; "trampoline" need not have any executable code.
4970 ;;
4971 ;; operands[0] is an SImode pseudo in which we place the address of the
4972 ;;             function.
4973 ;; operands[1] is the address of data area of the function to call
4974
4975 (define_expand "call_via_ptr"
4976   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4977         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
4978    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
4979         (reg:SI 2))
4980    (set (reg:SI 2)
4981         (mem:SI (plus:SI (match_dup 1)
4982                          (const_int 4))))
4983    (set (reg:SI 11)
4984         (mem:SI (plus:SI (match_dup 1)
4985                          (const_int 8))))
4986    (use (reg:SI 2))
4987    (use (reg:SI 11))]
4988   ""
4989   "")
4990
4991 (define_expand "call"
4992   [(parallel [(call (mem:SI (match_operand:SI 0 "address_operand" ""))
4993                     (match_operand 1 "" ""))
4994               (clobber (scratch:SI))])]
4995   ""
4996   "
4997 {
4998   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
4999     abort ();
5000
5001   operands[0] = XEXP (operands[0], 0);
5002   if (GET_CODE (operands[0]) != SYMBOL_REF)
5003     {
5004 #ifndef USING_SVR4_H
5005       /* AIX function pointers are really pointers to a three word area */
5006       rtx temp = gen_reg_rtx (SImode);
5007
5008       emit_insn (gen_call_via_ptr (temp, force_reg (SImode, operands[0])));
5009       operands[0] = temp;
5010 #endif  /* !USING_SVR4_H */
5011     }
5012 }")
5013
5014 (define_expand "call_value"
5015   [(parallel [(set (match_operand 0 "" "")
5016                    (call (mem:SI (match_operand:SI 1 "address_operand" ""))
5017                          (match_operand 2 "" "")))
5018               (clobber (scratch:SI))])]
5019   ""
5020   "
5021 {
5022   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
5023     abort ();
5024
5025   operands[1] = XEXP (operands[1], 0);
5026   if (GET_CODE (operands[1]) != SYMBOL_REF)
5027     {
5028 #ifndef USING_SVR4_H
5029       /* AIX function pointers are really pointers to a three word area */
5030       rtx temp = gen_reg_rtx (SImode);
5031
5032       emit_insn (gen_call_via_ptr (temp, force_reg (SImode, operands[1])));
5033       operands[1] = temp;
5034 #endif  /* !USING_SVR4_H */
5035     }
5036 }")
5037
5038 ;; Call to function in current module.  No TOC pointer reload needed.
5039
5040 (define_insn ""
5041   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s"))
5042          (match_operand 1 "" "g"))
5043    (clobber (match_scratch:SI 2 "=l"))]
5044   ""
5045   "bl %z0")
5046
5047 ;; Call to function which may be in another module.  Restore the TOC
5048 ;; pointer (r2) after the call unless this is System V.
5049
5050 (define_insn ""
5051   [(call (mem:SI (match_operand:SI 0 "call_operand" "l,s"))
5052          (match_operand 1 "" "fg,fg"))
5053    (clobber (match_scratch:SI 2 "=l,l"))]
5054   ""
5055   "*
5056 {
5057 #ifndef USING_SVR4_H
5058   if (GET_CODE (operands[0]) == REG)
5059     return \"{brl|blrl}\;{l|lwz} 2,20(1)\";
5060
5061   return \"bl %z0\;%.\";
5062
5063 #else
5064   if (GET_CODE (operands[0]) == REG)
5065     return \"{brl|blrl}\";
5066
5067   return \"bl %z0\";
5068 #endif
5069 }"
5070   [(set_attr "length" "8")])
5071
5072 (define_insn ""
5073   [(set (match_operand 0 "" "=fg")
5074         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s"))
5075               (match_operand 2 "" "g")))
5076    (clobber (match_scratch:SI 3 "=l"))]
5077   ""
5078   "bl %z1")
5079
5080 (define_insn ""
5081   [(set (match_operand 0 "" "=fg,fg")
5082         (call (mem:SI (match_operand:SI 1 "call_operand" "l,s"))
5083               (match_operand 2 "" "fg,fg")))
5084    (clobber (match_scratch:SI 3 "=l,l"))]
5085   ""
5086   "*
5087 {
5088 #ifndef USING_SVR4_H
5089   if (GET_CODE (operands[1]) == REG)
5090     return \"{brl|blrl}\;{l|lwz} 2,20(1)\";
5091
5092   return \"bl %z1\;%.\";
5093
5094 #else
5095   if (GET_CODE (operands[1]) == REG)
5096     return \"{brl|blrl}\";
5097
5098   return \"bl %z1\";
5099 #endif
5100 }"
5101   [(set_attr "length" "8")])
5102
5103 ;; Call subroutine returning any type.
5104
5105 (define_expand "untyped_call"
5106   [(parallel [(call (match_operand 0 "" "")
5107                     (const_int 0))
5108               (match_operand 1 "" "")
5109               (match_operand 2 "" "")])]
5110   ""
5111   "
5112 {
5113   int i;
5114
5115   emit_call_insn (gen_call (operands[0], const0_rtx, NULL, const0_rtx));
5116
5117   for (i = 0; i < XVECLEN (operands[2], 0); i++)
5118     {
5119       rtx set = XVECEXP (operands[2], 0, i);
5120       emit_move_insn (SET_DEST (set), SET_SRC (set));
5121     }
5122
5123   /* The optimizer does not know that the call sets the function value
5124      registers we stored in the result block.  We avoid problems by
5125      claiming that all hard registers are used and clobbered at this
5126      point.  */
5127   emit_insn (gen_blockage ());
5128
5129   DONE;
5130 }")
5131
5132 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
5133 ;; all of memory.  This blocks insns from being moved across this point.
5134
5135 (define_insn "blockage"
5136   [(unspec_volatile [(const_int 0)] 0)]
5137   ""
5138   "")
5139 \f
5140 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
5141 ;; signed & unsigned, and one type of branch.  
5142 ;;
5143 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
5144 ;; insns, and branches.  We store the operands of compares until we see
5145 ;; how it is used.
5146 (define_expand "cmpsi"
5147   [(set (cc0)
5148         (compare (match_operand:SI 0 "gpc_reg_operand" "")
5149                  (match_operand:SI 1 "reg_or_short_operand" "")))]
5150   ""
5151   "
5152 {
5153   /* Take care of the possibility that operands[1] might be negative but
5154      this might be a logical operation.  That insn doesn't exist.  */
5155   if (GET_CODE (operands[1]) == CONST_INT
5156       && INTVAL (operands[1]) < 0)
5157     operands[1] = force_reg (SImode, operands[1]);
5158
5159   rs6000_compare_op0 = operands[0];
5160   rs6000_compare_op1 = operands[1];
5161   rs6000_compare_fp_p = 0;
5162   DONE;
5163 }")
5164
5165 (define_expand "cmpsf"
5166   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
5167                        (match_operand:SF 1 "gpc_reg_operand" "")))]
5168   "TARGET_HARD_FLOAT"
5169   "
5170 {
5171   rs6000_compare_op0 = operands[0];
5172   rs6000_compare_op1 = operands[1];
5173   rs6000_compare_fp_p = 1;
5174   DONE;
5175 }")
5176
5177 (define_expand "cmpdf"
5178   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
5179                        (match_operand:DF 1 "gpc_reg_operand" "")))]
5180   "TARGET_HARD_FLOAT"
5181   "
5182 {
5183   rs6000_compare_op0 = operands[0];
5184   rs6000_compare_op1 = operands[1];
5185   rs6000_compare_fp_p = 1;
5186   DONE;
5187 }")
5188
5189 (define_expand "beq"
5190   [(set (match_dup 2) (match_dup 1))
5191    (set (pc)
5192         (if_then_else (eq (match_dup 2)
5193                           (const_int 0))
5194                       (label_ref (match_operand 0 "" ""))
5195                       (pc)))]
5196   ""
5197   "
5198 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5199   operands[1] = gen_rtx (COMPARE, mode,
5200                          rs6000_compare_op0, rs6000_compare_op1);
5201   operands[2] = gen_reg_rtx (mode);
5202 }")
5203
5204 (define_expand "bne"
5205   [(set (match_dup 2) (match_dup 1))
5206    (set (pc)
5207         (if_then_else (ne (match_dup 2)
5208                           (const_int 0))
5209                       (label_ref (match_operand 0 "" ""))
5210                       (pc)))]
5211   ""
5212   "
5213 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5214   operands[1] = gen_rtx (COMPARE, mode,
5215                          rs6000_compare_op0, rs6000_compare_op1);
5216   operands[2] = gen_reg_rtx (mode);
5217 }")
5218
5219 (define_expand "blt"
5220   [(set (match_dup 2) (match_dup 1))
5221    (set (pc)
5222         (if_then_else (lt (match_dup 2)
5223                           (const_int 0))
5224                       (label_ref (match_operand 0 "" ""))
5225                       (pc)))]
5226   ""
5227   "
5228 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5229   operands[1] = gen_rtx (COMPARE, mode,
5230                          rs6000_compare_op0, rs6000_compare_op1);
5231   operands[2] = gen_reg_rtx (mode);
5232 }")
5233
5234 (define_expand "bgt"
5235   [(set (match_dup 2) (match_dup 1))
5236    (set (pc)
5237         (if_then_else (gt (match_dup 2)
5238                           (const_int 0))
5239                       (label_ref (match_operand 0 "" ""))
5240                       (pc)))]
5241   ""
5242   "
5243 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5244   operands[1] = gen_rtx (COMPARE, mode,
5245                          rs6000_compare_op0, rs6000_compare_op1);
5246   operands[2] = gen_reg_rtx (mode);
5247 }")
5248
5249 (define_expand "ble"
5250   [(set (match_dup 2) (match_dup 1))
5251    (set (pc)
5252         (if_then_else (le (match_dup 2)
5253                           (const_int 0))
5254                       (label_ref (match_operand 0 "" ""))
5255                       (pc)))]
5256   ""
5257   "
5258 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5259   operands[1] = gen_rtx (COMPARE, mode,
5260                          rs6000_compare_op0, rs6000_compare_op1);
5261   operands[2] = gen_reg_rtx (mode);
5262 }")
5263
5264 (define_expand "bge"
5265   [(set (match_dup 2) (match_dup 1))
5266    (set (pc)
5267         (if_then_else (ge (match_dup 2)
5268                           (const_int 0))
5269                       (label_ref (match_operand 0 "" ""))
5270                       (pc)))]
5271   ""
5272   "
5273 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5274   operands[1] = gen_rtx (COMPARE, mode,
5275                          rs6000_compare_op0, rs6000_compare_op1);
5276   operands[2] = gen_reg_rtx (mode);
5277 }")
5278
5279 (define_expand "bgtu"
5280   [(set (match_dup 2) (match_dup 1))
5281    (set (pc)
5282         (if_then_else (gtu (match_dup 2)
5283                            (const_int 0))
5284                       (label_ref (match_operand 0 "" ""))
5285                       (pc)))]
5286   ""
5287   "
5288 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5289                          rs6000_compare_op0, rs6000_compare_op1);
5290   operands[2] = gen_reg_rtx (CCUNSmode);
5291 }")
5292
5293 (define_expand "bltu"
5294   [(set (match_dup 2) (match_dup 1))
5295    (set (pc)
5296         (if_then_else (ltu (match_dup 2)
5297                            (const_int 0))
5298                       (label_ref (match_operand 0 "" ""))
5299                       (pc)))]
5300   ""
5301   "
5302 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5303                          rs6000_compare_op0, rs6000_compare_op1);
5304   operands[2] = gen_reg_rtx (CCUNSmode);
5305 }")
5306
5307 (define_expand "bgeu"
5308   [(set (match_dup 2) (match_dup 1))
5309    (set (pc)
5310         (if_then_else (geu (match_dup 2)
5311                            (const_int 0))
5312                       (label_ref (match_operand 0 "" ""))
5313                       (pc)))]
5314   ""
5315   "
5316 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5317                          rs6000_compare_op0, rs6000_compare_op1);
5318   operands[2] = gen_reg_rtx (CCUNSmode);
5319 }")
5320
5321 (define_expand "bleu"
5322   [(set (match_dup 2) (match_dup 1))
5323    (set (pc)
5324         (if_then_else (leu (match_dup 2)
5325                            (const_int 0))
5326                       (label_ref (match_operand 0 "" ""))
5327                       (pc)))]
5328   ""
5329   "
5330 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5331                          rs6000_compare_op0, rs6000_compare_op1);
5332   operands[2] = gen_reg_rtx (CCUNSmode);
5333 }")
5334
5335 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
5336 ;; For SEQ, likewise, except that comparisons with zero should be done
5337 ;; with an scc insns.  However, due to the order that combine see the
5338 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
5339 ;; the cases we don't want to handle.
5340 (define_expand "seq"
5341   [(set (match_dup 2) (match_dup 1))
5342    (set (match_operand:SI 0 "gpc_reg_operand" "")
5343         (eq:SI (match_dup 2) (const_int 0)))]
5344   ""
5345   "
5346 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5347   operands[1] = gen_rtx (COMPARE, mode,
5348                          rs6000_compare_op0, rs6000_compare_op1);
5349   operands[2] = gen_reg_rtx (mode);
5350 }")
5351
5352 (define_expand "sne"
5353   [(set (match_dup 2) (match_dup 1))
5354    (set (match_operand:SI 0 "gpc_reg_operand" "")
5355         (ne:SI (match_dup 2) (const_int 0)))]
5356   ""
5357   "
5358 { if (! rs6000_compare_fp_p)
5359     FAIL;
5360
5361   operands[1] = gen_rtx (COMPARE, CCFPmode,
5362                          rs6000_compare_op0, rs6000_compare_op1);
5363   operands[2] = gen_reg_rtx (CCFPmode);
5364 }")
5365
5366 ;; A > 0 is best done using the portable sequence, so fail in that case.
5367 (define_expand "sgt"
5368   [(set (match_dup 2) (match_dup 1))
5369    (set (match_operand:SI 0 "gpc_reg_operand" "")
5370         (gt:SI (match_dup 2) (const_int 0)))]
5371   ""
5372   "
5373 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5374
5375   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
5376     FAIL;
5377
5378   operands[1] = gen_rtx (COMPARE, mode,
5379                          rs6000_compare_op0, rs6000_compare_op1);
5380   operands[2] = gen_reg_rtx (mode);
5381 }")
5382
5383 ;; A < 0 is best done in the portable way for A an integer.
5384 (define_expand "slt"
5385   [(set (match_dup 2) (match_dup 1))
5386    (set (match_operand:SI 0 "gpc_reg_operand" "")
5387         (lt:SI (match_dup 2) (const_int 0)))]
5388   ""
5389   "
5390 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5391
5392   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
5393     FAIL;
5394
5395   operands[1] = gen_rtx (COMPARE, mode,
5396                          rs6000_compare_op0, rs6000_compare_op1);
5397   operands[2] = gen_reg_rtx (mode);
5398 }")
5399
5400 (define_expand "sge"
5401   [(set (match_dup 2) (match_dup 1))
5402    (set (match_operand:SI 0 "gpc_reg_operand" "")
5403         (ge:SI (match_dup 2) (const_int 0)))]
5404   ""
5405   "
5406 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5407   operands[1] = gen_rtx (COMPARE, mode,
5408                          rs6000_compare_op0, rs6000_compare_op1);
5409   operands[2] = gen_reg_rtx (mode);
5410 }")
5411
5412 ;; A <= 0 is best done the portable way for A an integer.
5413 (define_expand "sle"
5414   [(set (match_dup 2) (match_dup 1))
5415    (set (match_operand:SI 0 "gpc_reg_operand" "")
5416         (le:SI (match_dup 2) (const_int 0)))]
5417   ""
5418   "
5419 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5420
5421   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
5422     FAIL;
5423
5424   operands[1] = gen_rtx (COMPARE, mode,
5425                          rs6000_compare_op0, rs6000_compare_op1);
5426   operands[2] = gen_reg_rtx (mode);
5427 }")
5428
5429 (define_expand "sgtu"
5430   [(set (match_dup 2) (match_dup 1))
5431    (set (match_operand:SI 0 "gpc_reg_operand" "")
5432         (gtu:SI (match_dup 2) (const_int 0)))]
5433   ""
5434   "
5435 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5436                          rs6000_compare_op0, rs6000_compare_op1);
5437   operands[2] = gen_reg_rtx (CCUNSmode);
5438 }")
5439
5440 (define_expand "sltu"
5441   [(set (match_dup 2) (match_dup 1))
5442    (set (match_operand:SI 0 "gpc_reg_operand" "")
5443         (ltu:SI (match_dup 2) (const_int 0)))]
5444   ""
5445   "
5446 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5447                          rs6000_compare_op0, rs6000_compare_op1);
5448   operands[2] = gen_reg_rtx (CCUNSmode);
5449 }")
5450
5451 (define_expand "sgeu"
5452   [(set (match_dup 2) (match_dup 1))
5453    (set (match_operand:SI 0 "gpc_reg_operand" "")
5454         (geu:SI (match_dup 2) (const_int 0)))]
5455   ""
5456   "
5457 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5458                          rs6000_compare_op0, rs6000_compare_op1);
5459   operands[2] = gen_reg_rtx (CCUNSmode);
5460 }")
5461
5462 (define_expand "sleu"
5463   [(set (match_dup 2) (match_dup 1))
5464    (set (match_operand:SI 0 "gpc_reg_operand" "")
5465         (leu:SI (match_dup 2) (const_int 0)))]
5466   ""
5467   "
5468 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5469                          rs6000_compare_op0, rs6000_compare_op1);
5470   operands[2] = gen_reg_rtx (CCUNSmode);
5471 }")
5472 \f
5473 ;; Here are the actual compare insns.
5474 (define_insn ""
5475   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
5476         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
5477                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
5478   ""
5479   "{cmp%I2|cmpw%I2} %0,%1,%2"
5480   [(set_attr "type" "compare")])
5481
5482 ;; If we are comparing a register for equality with a large constant,
5483 ;; we can do this with an XOR followed by a compare.  But we need a scratch
5484 ;; register for the result of the XOR.
5485
5486 (define_split
5487   [(set (match_operand:CC 0 "cc_reg_operand" "")
5488         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
5489                     (match_operand:SI 2 "non_short_cint_operand" "")))
5490    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
5491   "find_single_use (operands[0], insn, 0)
5492    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
5493        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
5494   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
5495    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
5496   "
5497 {
5498   /* Get the constant we are comparing against, C,  and see what it looks like
5499      sign-extended to 16 bits.  Then see what constant could be XOR'ed
5500      with C to get the sign-extended value.  */
5501
5502   int c = INTVAL (operands[2]);
5503   int sextc = (c << 16) >> 16;
5504   int xorv = c ^ sextc;
5505
5506   operands[4] = gen_rtx (CONST_INT, VOIDmode, xorv);
5507   operands[5] = gen_rtx (CONST_INT, VOIDmode, sextc);
5508 }")
5509
5510 (define_insn ""
5511   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
5512         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
5513                        (match_operand:SI 2 "reg_or_u_short_operand" "rI")))]
5514   ""
5515   "{cmpl%I2|cmplw%I2} %0,%1,%W2"
5516   [(set_attr "type" "compare")])
5517
5518 ;; The following two insns don't exist as single insns, but if we provide
5519 ;; them, we can swap an add and compare, which will enable us to overlap more
5520 ;; of the required delay between a compare and branch.  We generate code for
5521 ;; them by splitting.
5522
5523 (define_insn ""
5524   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
5525         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
5526                     (match_operand:SI 2 "short_cint_operand" "i")))
5527    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
5528         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
5529   ""
5530   "#"
5531   [(set_attr "length" "8")])
5532    
5533 (define_insn ""
5534   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
5535         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
5536                        (match_operand:SI 2 "u_short_cint_operand" "i")))
5537    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
5538         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
5539   ""
5540   "#"
5541   [(set_attr "length" "8")])
5542    
5543 (define_split
5544   [(set (match_operand:CC 3 "cc_reg_operand" "")
5545         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
5546                     (match_operand:SI 2 "short_cint_operand" "")))
5547    (set (match_operand:SI 0 "gpc_reg_operand" "")
5548         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
5549   ""
5550   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
5551    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
5552
5553 (define_split
5554   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
5555         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
5556                        (match_operand:SI 2 "u_short_cint_operand" "")))
5557    (set (match_operand:SI 0 "gpc_reg_operand" "")
5558         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
5559   ""
5560   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
5561    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
5562
5563 (define_insn ""
5564   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
5565         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
5566                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
5567   "TARGET_HARD_FLOAT"
5568   "fcmpu %0,%1,%2"
5569   [(set_attr "type" "fpcompare")])
5570
5571 (define_insn ""
5572   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
5573         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
5574                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
5575   "TARGET_HARD_FLOAT"
5576   "fcmpu %0,%1,%2"
5577   [(set_attr "type" "fpcompare")])
5578 \f
5579 ;; Now we have the scc insns.  We can do some combinations because of the
5580 ;; way the machine works.
5581 ;;
5582 ;; Note that this is probably faster if we can put an insn between the
5583 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
5584 ;; cases the insns below which don't use an intermediate CR field will
5585 ;; be used instead.
5586 (define_insn ""
5587   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5588         (match_operator:SI 1 "scc_comparison_operator"
5589                            [(match_operand 2 "cc_reg_operand" "y")
5590                             (const_int 0)]))]
5591   ""
5592   "%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%J1,1"
5593   [(set_attr "length" "12")])
5594
5595 (define_insn ""
5596   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
5597         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
5598                                        [(match_operand 2 "cc_reg_operand" "y")
5599                                         (const_int 0)])
5600                     (const_int 0)))
5601    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
5602         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
5603   ""
5604   "%D1mfcr %3\;{rlinm.|rlwinm.} %3,%3,%J1,1"
5605   [(set_attr "type" "delayed_compare")
5606    (set_attr "length" "12")])
5607
5608 (define_insn ""
5609   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5610         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
5611                                       [(match_operand 2 "cc_reg_operand" "y")
5612                                        (const_int 0)])
5613                    (match_operand:SI 3 "const_int_operand" "n")))]
5614   ""
5615   "*
5616 {
5617   int is_bit = ccr_bit (operands[1], 1);
5618   int put_bit = 31 - (INTVAL (operands[3]) & 31);
5619   int count;
5620
5621   if (is_bit >= put_bit)
5622     count = is_bit - put_bit;
5623   else
5624     count = 32 - (put_bit - is_bit);
5625
5626   operands[4] = gen_rtx (CONST_INT, VOIDmode, count);
5627   operands[5] = gen_rtx (CONST_INT, VOIDmode, put_bit);
5628
5629   return \"%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
5630 }"
5631  [(set_attr "length" "12")])
5632
5633 (define_insn ""
5634   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
5635         (compare:CC
5636          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
5637                                        [(match_operand 2 "cc_reg_operand" "y")
5638                                         (const_int 0)])
5639                     (match_operand:SI 3 "const_int_operand" "n"))
5640          (const_int 0)))
5641    (set (match_operand:SI 4 "gpc_reg_operand" "=r")
5642         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
5643                    (match_dup 3)))]
5644   ""
5645   "*
5646 {
5647   int is_bit = ccr_bit (operands[1], 1);
5648   int put_bit = 31 - (INTVAL (operands[3]) & 31);
5649   int count;
5650
5651   if (is_bit >= put_bit)
5652     count = is_bit - put_bit;
5653   else
5654     count = 32 - (put_bit - is_bit);
5655
5656   operands[5] = gen_rtx (CONST_INT, VOIDmode, count);
5657   operands[6] = gen_rtx (CONST_INT, VOIDmode, put_bit);
5658
5659   return \"%D1mfcr %4\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
5660 }"
5661   [(set_attr "type" "delayed_compare")
5662    (set_attr "length" "12")])
5663
5664 ;; If we are comparing the result of two comparisons, this can be done
5665 ;; using creqv or crxor.
5666
5667 (define_insn ""
5668   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
5669         (compare:CCEQ (match_operator 1 "scc_comparison_operator"
5670                               [(match_operand 2 "cc_reg_operand" "y")
5671                                (const_int 0)])
5672                       (match_operator 3 "scc_comparison_operator"
5673                               [(match_operand 4 "cc_reg_operand" "y")
5674                                (const_int 0)])))]
5675   "REGNO (operands[2]) != REGNO (operands[4])"
5676   "*
5677 {
5678   enum rtx_code code1, code2;
5679
5680   code1 = GET_CODE (operands[1]);
5681   code2 = GET_CODE (operands[3]);
5682
5683   if ((code1 == EQ || code1 == LT || code1 == GT
5684        || code1 == LTU || code1 == GTU
5685        || (code1 != NE && GET_MODE (operands[2]) == CCFPmode))
5686       !=
5687       (code2 == EQ || code2 == LT || code2 == GT
5688        || code2 == LTU || code2 == GTU
5689        || (code2 != NE && GET_MODE (operands[4]) == CCFPmode)))
5690     return \"%C1%C3crxor %E0,%j1,%j3\";
5691   else
5692     return \"%C1%C3creqv %E0,%j1,%j3\";
5693 }"
5694   [(set_attr "length" "12")])
5695
5696 ;; There is a 3 cycle delay between consecutive mfcr instructions
5697 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
5698
5699 (define_peephole
5700   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5701         (match_operator:SI 1 "scc_comparison_operator"
5702                            [(match_operand 2 "cc_reg_operand" "y")
5703                             (const_int 0)]))
5704    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
5705         (match_operator:SI 4 "scc_comparison_operator"
5706                            [(match_operand 5 "cc_reg_operand" "y")
5707                             (const_int 0)]))]
5708    "REGNO (operands[2]) != REGNO (operands[5])"
5709    "%D1%D4mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
5710    [(set_attr "length" "20")])
5711
5712 ;; There are some scc insns that can be done directly, without a compare.
5713 ;; These are faster because they don't involve the communications between
5714 ;; the FXU and branch units.   In fact, we will be replacing all of the
5715 ;; integer scc insns here or in the portable methods in emit_store_flag.
5716 ;;
5717 ;; Also support (neg (scc ..)) since that construct is used to replace
5718 ;; branches, (plus (scc ..) ..) since that construct is common and
5719 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
5720 ;; cases where it is no more expensive than (neg (scc ..)).
5721
5722 ;; Have reload force a constant into a register for the simple insns that
5723 ;; otherwise won't accept constants.  We do this because it is faster than
5724 ;; the cmp/mfcr sequence we would otherwise generate.
5725
5726 (define_insn ""
5727   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
5728         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
5729                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I")))
5730    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
5731   ""
5732   "@
5733    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
5734    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
5735    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
5736    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
5737    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
5738   [(set_attr "length" "12,8,12,12,12")])
5739
5740 (define_insn ""
5741   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x")
5742         (compare:CC 
5743          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
5744                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
5745          (const_int 0)))
5746    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
5747         (eq:SI (match_dup 1) (match_dup 2)))
5748    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
5749   ""
5750   "@
5751    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
5752    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
5753    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
5754    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
5755    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0"
5756   [(set_attr "type" "compare")
5757    (set_attr "length" "12,8,12,12,12")])
5758
5759 ;; We have insns of the form shown by the first define_insn below.  If
5760 ;; there is something inside the comparison operation, we must split it.
5761 (define_split
5762   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5763         (plus:SI (match_operator 1 "comparison_operator"
5764                                  [(match_operand:SI 2 "" "")
5765                                   (match_operand:SI 3
5766                                                     "reg_or_cint_operand" "")])
5767                  (match_operand:SI 4 "gpc_reg_operand" "")))
5768    (clobber (match_operand:SI 5 "register_operand" ""))]
5769   "! gpc_reg_operand (operands[2], SImode)"
5770   [(set (match_dup 5) (match_dup 2))
5771    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
5772                                (match_dup 4)))])
5773
5774 (define_insn ""
5775   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
5776         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
5777                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
5778                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))
5779    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
5780   ""
5781   "@
5782    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
5783    {sfi|subfic} %4,%1,0\;{aze|addze} %0,%3
5784    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
5785    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
5786    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3"
5787   [(set_attr "length" "12,8,12,12,12")])
5788
5789 (define_insn ""
5790   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x")
5791         (compare:CC 
5792          (plus:SI
5793           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
5794                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
5795           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r"))
5796          (const_int 0)))
5797    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
5798   ""
5799   "@
5800    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
5801    {sfi|subfic} %4,%1,0\;{aze.|addze.} %0,%3
5802    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
5803    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
5804    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3"
5805   [(set_attr "type" "compare")
5806    (set_attr "length" "12,8,12,12,12")])
5807
5808 (define_insn ""
5809   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x,x,x,x")
5810         (compare:CC 
5811          (plus:SI
5812           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
5813                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
5814           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r"))
5815          (const_int 0)))
5816    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
5817         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
5818    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
5819   ""
5820   "@
5821    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
5822    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
5823    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
5824    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
5825    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3"
5826   [(set_attr "type" "compare")
5827    (set_attr "length" "12,8,12,12,12")])
5828
5829 (define_insn ""
5830   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
5831         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
5832                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))))]
5833   ""
5834   "@
5835    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
5836    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
5837    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
5838    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
5839    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
5840    [(set_attr "length" "12,8,12,12,12")])
5841
5842 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
5843 ;; since it nabs/sr is just as fast.
5844 (define_insn ""
5845   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5846         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
5847                      (const_int 31)))
5848    (clobber (match_scratch:SI 2 "=&r"))]
5849   "!TARGET_POWER"
5850   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
5851   [(set_attr "length" "8")])
5852
5853 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
5854 (define_insn ""
5855   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5856         (plus:SI (lshiftrt:SI
5857                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
5858                   (const_int 31))
5859                  (match_operand:SI 2 "gpc_reg_operand" "r")))
5860    (clobber (match_scratch:SI 3 "=&r"))]
5861   ""
5862   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
5863   [(set_attr "length" "8")])
5864
5865 (define_insn ""
5866   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
5867         (compare:CC
5868          (plus:SI (lshiftrt:SI
5869                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
5870                    (const_int 31))
5871                   (match_operand:SI 2 "gpc_reg_operand" "r"))
5872          (const_int 0)))
5873    (clobber (match_scratch:SI 3 "=&r"))]
5874   ""
5875   "{ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2"
5876   [(set_attr "type" "compare")
5877    (set_attr "length" "8")])
5878
5879 (define_insn ""
5880   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
5881         (compare:CC
5882          (plus:SI (lshiftrt:SI
5883                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
5884                    (const_int 31))
5885                   (match_operand:SI 2 "gpc_reg_operand" "r"))
5886          (const_int 0)))
5887    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
5888         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
5889                  (match_dup 2)))
5890    (clobber (match_scratch:SI 3 "=&r"))]
5891   ""
5892   "{ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2"
5893   [(set_attr "type" "compare")
5894    (set_attr "length" "8")])
5895
5896 (define_insn ""
5897   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5898         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5899                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
5900    (clobber (match_scratch:SI 3 "=r,X"))]
5901   "TARGET_POWER"
5902   "@
5903    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
5904    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
5905   [(set_attr "length" "12")])
5906
5907 (define_insn ""
5908   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x")
5909         (compare:CC
5910          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5911                 (match_operand:SI 2 "reg_or_short_operand" "r,O"))
5912          (const_int 0)))
5913    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5914         (le:SI (match_dup 1) (match_dup 2)))
5915    (clobber (match_scratch:SI 3 "=r,X"))]
5916   "TARGET_POWER"
5917   "@
5918    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
5919    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31"
5920   [(set_attr "type" "compare,delayed_compare")
5921    (set_attr "length" "12")])
5922
5923 (define_insn ""
5924   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5925         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5926                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
5927                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))
5928    (clobber (match_scratch:SI 4 "=&r,&r"))]
5929   "TARGET_POWER"
5930   "@
5931    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
5932    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze|addze} %0,%3"
5933   [(set_attr "length" "12")])
5934
5935 (define_insn ""
5936   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
5937         (compare:CC
5938          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5939                          (match_operand:SI 2 "reg_or_short_operand" "r,O"))
5940                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
5941          (const_int 0)))
5942    (clobber (match_scratch:SI 4 "=&r,&r"))]
5943   "TARGET_POWER"
5944   "@
5945    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
5946    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3"
5947   [(set_attr "type" "compare")
5948    (set_attr "length" "12")])
5949
5950 (define_insn ""
5951   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
5952         (compare:CC
5953          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5954                          (match_operand:SI 2 "reg_or_short_operand" "r,O"))
5955                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
5956          (const_int 0)))
5957    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5958         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
5959    (clobber (match_scratch:SI 4 "=&r,&r"))]
5960   "TARGET_POWER"
5961   "@
5962    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
5963    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %0,%3"
5964   [(set_attr "type" "compare")
5965    (set_attr "length" "12")])
5966
5967 (define_insn ""
5968   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5969         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5970                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
5971   "TARGET_POWER"
5972   "@
5973    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
5974    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
5975   [(set_attr "length" "12")])
5976
5977 (define_insn ""
5978   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5979         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5980                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
5981   ""
5982   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
5983   [(set_attr "length" "12")])
5984
5985 (define_insn ""
5986   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
5987         (compare:CC
5988          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5989                  (match_operand:SI 2 "reg_or_short_operand" "rI"))
5990          (const_int 0)))
5991    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
5992         (leu:SI (match_dup 1) (match_dup 2)))]
5993    ""
5994   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0"
5995   [(set_attr "type" "compare")
5996    (set_attr "length" "12")])
5997
5998 (define_insn ""
5999   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6000         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6001                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
6002                  (match_operand:SI 3 "gpc_reg_operand" "r")))
6003    (clobber (match_scratch:SI 4 "=&r"))]
6004   ""
6005   "{sf%I2|subf%I2c} %4,%1,%2\;{aze|addze} %0,%3"
6006   [(set_attr "length" "8")])
6007
6008 (define_insn ""
6009   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6010         (compare:CC
6011          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6012                           (match_operand:SI 2 "reg_or_short_operand" "rI"))
6013                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6014          (const_int 0)))
6015    (clobber (match_scratch:SI 4 "=&r"))]
6016   ""
6017   "{sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3"
6018   [(set_attr "type" "compare")
6019    (set_attr "length" "8")])
6020
6021 (define_insn ""
6022   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
6023         (compare:CC
6024          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6025                           (match_operand:SI 2 "reg_or_short_operand" "rI"))
6026                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6027          (const_int 0)))
6028    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6029         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6030    (clobber (match_scratch:SI 4 "=&r"))]
6031   ""
6032   "{sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %0,%3"
6033   [(set_attr "type" "compare")
6034    (set_attr "length" "8")])
6035
6036 (define_insn ""
6037   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6038         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6039                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
6040   ""
6041   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
6042    [(set_attr "length" "12")])
6043
6044 (define_insn ""
6045   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6046         (and:SI (neg:SI
6047                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6048                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
6049                 (match_operand:SI 3 "gpc_reg_operand" "r")))
6050    (clobber (match_scratch:SI 4 "=&r"))]
6051   ""
6052   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4"
6053   [(set_attr "length" "12")])
6054
6055 (define_insn ""
6056   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6057         (compare:CC
6058          (and:SI (neg:SI
6059                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6060                           (match_operand:SI 2 "reg_or_short_operand" "rI")))
6061                  (match_operand:SI 3 "gpc_reg_operand" "r"))
6062          (const_int 0)))
6063    (clobber (match_scratch:SI 4 "=&r"))]
6064   ""
6065   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4"
6066   [(set_attr "type" "compare")
6067    (set_attr "length" "12")])
6068
6069 (define_insn ""
6070   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
6071         (compare:CC
6072          (and:SI (neg:SI
6073                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6074                           (match_operand:SI 2 "reg_or_short_operand" "rI")))
6075                  (match_operand:SI 3 "gpc_reg_operand" "r"))
6076          (const_int 0)))
6077    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6078         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
6079    (clobber (match_scratch:SI 4 "=&r"))]
6080   ""
6081   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4"
6082   [(set_attr "type" "compare")
6083    (set_attr "length" "12")])
6084
6085 (define_insn ""
6086   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6087         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6088                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
6089   "TARGET_POWER"
6090   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
6091    [(set_attr "length" "12")])
6092
6093 (define_insn ""
6094   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
6095         (compare:CC
6096          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6097                 (match_operand:SI 2 "reg_or_short_operand" "rI"))
6098          (const_int 0)))
6099    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6100         (lt:SI (match_dup 1) (match_dup 2)))]
6101   "TARGET_POWER"
6102   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31"
6103   [(set_attr "type" "delayed_compare")
6104    (set_attr "length" "12")])
6105
6106 (define_insn ""
6107   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6108         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6109                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
6110                  (match_operand:SI 3 "gpc_reg_operand" "r")))
6111    (clobber (match_scratch:SI 4 "=&r"))]
6112   "TARGET_POWER"
6113   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze|addze} %0,%3"
6114   [(set_attr "length" "12")])
6115
6116 (define_insn ""
6117   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6118         (compare:CC
6119          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6120                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
6121                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6122          (const_int 0)))
6123    (clobber (match_scratch:SI 4 "=&r"))]
6124   "TARGET_POWER"
6125   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3"
6126   [(set_attr "type" "compare")
6127    (set_attr "length" "12")])
6128
6129 (define_insn ""
6130   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
6131         (compare:CC
6132          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6133                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
6134                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6135          (const_int 0)))
6136    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6137         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6138    (clobber (match_scratch:SI 4 "=&r"))]
6139   "TARGET_POWER"
6140   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %0,%3"
6141   [(set_attr "type" "compare")
6142    (set_attr "length" "12")])
6143
6144 (define_insn ""
6145   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6146         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6147                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
6148   "TARGET_POWER"
6149   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
6150   [(set_attr "length" "12")])
6151
6152 (define_insn ""
6153   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6154         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6155                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
6156   ""
6157   "@
6158    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg %0,%0
6159    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
6160   [(set_attr "length" "12")])
6161
6162 (define_insn ""
6163   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
6164         (compare:CC
6165          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6166                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6167          (const_int 0)))
6168    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6169         (ltu:SI (match_dup 1) (match_dup 2)))]
6170   ""
6171   "@
6172    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
6173    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0"
6174   [(set_attr "type" "compare")
6175    (set_attr "length" "12")])
6176
6177 (define_insn ""
6178   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
6179         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
6180                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,r,P,P"))
6181                  (match_operand:SI 3 "reg_or_short_operand" "r,I,r,I")))
6182    (clobber (match_scratch:SI 4 "=&r,r,&r,r"))]
6183   ""
6184   "@
6185   {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
6186   {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
6187   {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
6188   {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3"
6189  [(set_attr "length" "12")])
6190
6191 (define_insn ""
6192   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
6193         (compare:CC
6194          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6195                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6196                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6197          (const_int 0)))
6198    (clobber (match_scratch:SI 4 "=&r,&r"))]
6199   ""
6200   "@
6201    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
6202    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3"
6203   [(set_attr "type" "compare")
6204    (set_attr "length" "12")])
6205
6206 (define_insn ""
6207   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
6208         (compare:CC
6209          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6210                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6211                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6212          (const_int 0)))
6213    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6214         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6215    (clobber (match_scratch:SI 4 "=&r,&r"))]
6216   ""
6217   "@
6218    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3
6219    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
6220   [(set_attr "type" "compare")
6221    (set_attr "length" "12")])
6222
6223 (define_insn ""
6224   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6225         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6226                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
6227   ""
6228   "@
6229    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
6230    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
6231   [(set_attr "length" "8")])
6232
6233 (define_insn ""
6234   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6235         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6236                (match_operand:SI 2 "reg_or_short_operand" "rI")))
6237    (clobber (match_scratch:SI 3 "=r"))]
6238   "TARGET_POWER"
6239   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
6240    [(set_attr "length" "12")])
6241
6242 (define_insn ""
6243   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
6244         (compare:CC
6245          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6246                 (match_operand:SI 2 "reg_or_short_operand" "rI"))
6247          (const_int 0)))
6248    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6249         (ge:SI (match_dup 1) (match_dup 2)))
6250    (clobber (match_scratch:SI 3 "=r"))]
6251   "TARGET_POWER"
6252   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3"
6253   [(set_attr "type" "compare")
6254    (set_attr "length" "12")])
6255
6256 (define_insn ""
6257   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6258         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6259                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
6260                  (match_operand:SI 3 "gpc_reg_operand" "r")))
6261    (clobber (match_scratch:SI 4 "=&r"))]
6262   "TARGET_POWER"
6263   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3"
6264   [(set_attr "length" "12")])
6265
6266 (define_insn ""
6267   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6268         (compare:CC
6269          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6270                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
6271                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6272          (const_int 0)))
6273    (clobber (match_scratch:SI 4 "=&r"))]
6274   "TARGET_POWER"
6275   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3"
6276   [(set_attr "type" "compare")
6277    (set_attr "length" "12")])
6278
6279 (define_insn ""
6280   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
6281         (compare:CC
6282          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6283                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
6284                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6285          (const_int 0)))
6286    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6287         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6288    (clobber (match_scratch:SI 4 "=&r"))]
6289   "TARGET_POWER"
6290   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3"
6291   [(set_attr "type" "compare")
6292    (set_attr "length" "12")])
6293
6294 (define_insn ""
6295   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6296         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6297                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
6298   "TARGET_POWER"
6299   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
6300   [(set_attr "length" "12")])
6301
6302 ;; This is (and (neg (ge X (const_int 0))) Y).
6303 (define_insn ""
6304   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6305         (and:SI (neg:SI
6306                  (lshiftrt:SI
6307                   (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
6308                   (const_int 31)))
6309                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6310    (clobber (match_scratch:SI 3 "=&r"))]
6311   ""
6312   "{srai|srawi} %3,%1,31\;andc %0,%2,%3"
6313   [(set_attr "length" "8")])
6314
6315 (define_insn ""
6316   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6317         (compare:CC
6318          (and:SI (neg:SI
6319                   (lshiftrt:SI
6320                    (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
6321                    (const_int 31)))
6322                  (match_operand:SI 2 "gpc_reg_operand" "r"))
6323          (const_int 0)))
6324    (clobber (match_scratch:SI 3 "=&r"))]
6325   ""
6326   "{srai|srawi} %3,%1,31\;andc. %3,%2,%3"
6327   [(set_attr "type" "compare")
6328    (set_attr "length" "8")])
6329
6330 (define_insn ""
6331   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
6332         (compare:CC
6333          (and:SI (neg:SI
6334                   (lshiftrt:SI
6335                    (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
6336                    (const_int 31)))
6337                  (match_operand:SI 2 "gpc_reg_operand" "r"))
6338          (const_int 0)))
6339    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6340         (and:SI (neg:SI (lshiftrt:SI (not:SI (match_dup 1))
6341                                      (const_int 31)))
6342                 (match_dup 2)))
6343    (clobber (match_scratch:SI 3 "=&r"))]
6344   ""
6345   "{srai|srawi} %3,%1,31\;andc. %0,%2,%3"
6346   [(set_attr "type" "compare")
6347    (set_attr "length" "8")])
6348
6349 (define_insn ""
6350   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6351         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6352                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
6353   ""
6354   "@
6355    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
6356    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
6357   [(set_attr "length" "12")])
6358
6359 (define_insn ""
6360   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
6361         (compare:CC
6362          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6363                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6364          (const_int 0)))
6365    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6366         (geu:SI (match_dup 1) (match_dup 2)))]
6367   ""
6368   "@
6369    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
6370    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0"
6371   [(set_attr "type" "compare")
6372    (set_attr "length" "12")])
6373
6374 (define_insn ""
6375   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6376         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6377                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6378                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))
6379    (clobber (match_scratch:SI 4 "=&r,&r"))]
6380   ""
6381   "@
6382    {sf|subfc} %4,%2,%1\;{aze|addze} %0,%3
6383    {ai|addic} %4,%1,%n2\;{aze|addze} %0,%3"
6384   [(set_attr "length" "8")])
6385
6386 (define_insn ""
6387   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
6388         (compare:CC
6389          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6390                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6391                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6392          (const_int 0)))
6393    (clobber (match_scratch:SI 4 "=&r,&r"))]
6394   ""
6395   "@
6396    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
6397    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3"
6398   [(set_attr "type" "compare")
6399    (set_attr "length" "8")])
6400
6401 (define_insn ""
6402   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
6403         (compare:CC
6404          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6405                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6406                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6407          (const_int 0)))
6408    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6409         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6410    (clobber (match_scratch:SI 4 "=&r,&r"))]
6411   ""
6412   "@
6413    {sf|subfc} %4,%2,%1\;{aze.|addze.} %0,%3
6414    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3"
6415   [(set_attr "type" "compare")
6416    (set_attr "length" "8")])
6417
6418 (define_insn ""
6419   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6420         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6421                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
6422   ""
6423   "@
6424    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
6425    {sfi|subfic} %0,%1,-1\;a%I2 %0,%0,%2\;{sfe|subfe} %0,%0,%0"
6426   [(set_attr "length" "12")])
6427
6428 (define_insn ""
6429   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6430         (and:SI (neg:SI
6431                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6432                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
6433                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))
6434    (clobber (match_scratch:SI 4 "=&r,&r"))]
6435   ""
6436   "@
6437    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4
6438    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4"
6439   [(set_attr "length" "12")])
6440
6441 (define_insn ""
6442   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
6443         (compare:CC
6444          (and:SI (neg:SI
6445                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6446                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
6447                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6448          (const_int 0)))
6449    (clobber (match_scratch:SI 4 "=&r,&r"))]
6450   ""
6451   "@
6452    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
6453    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4"
6454   [(set_attr "type" "compare")
6455    (set_attr "length" "12")])
6456
6457 (define_insn ""
6458   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
6459         (compare:CC
6460          (and:SI (neg:SI
6461                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6462                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
6463                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6464          (const_int 0)))
6465    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6466         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
6467    (clobber (match_scratch:SI 4 "=&r,&r"))]
6468   ""
6469   "@
6470    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4
6471    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4"
6472   [(set_attr "type" "compare")
6473    (set_attr "length" "12")])
6474
6475 (define_insn ""
6476   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6477         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6478                (const_int 0)))]
6479   ""
6480   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
6481   [(set_attr "length" "12")])
6482
6483 (define_insn ""
6484   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
6485         (compare:CC
6486          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6487                 (const_int 0))
6488          (const_int 0)))
6489    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6490         (gt:SI (match_dup 1) (const_int 0)))]
6491   ""
6492   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31"
6493   [(set_attr "type" "delayed_compare")
6494    (set_attr "length" "12")])
6495
6496 (define_insn ""
6497   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6498         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6499                (match_operand:SI 2 "reg_or_short_operand" "r")))]
6500   "TARGET_POWER"
6501   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
6502   [(set_attr "length" "12")])
6503
6504 (define_insn ""
6505   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
6506         (compare:CC
6507          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6508                 (match_operand:SI 2 "reg_or_short_operand" "r"))
6509          (const_int 0)))
6510    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6511         (gt:SI (match_dup 1) (match_dup 2)))]
6512   "TARGET_POWER"
6513   "doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31"
6514   [(set_attr "type" "delayed_compare")
6515    (set_attr "length" "12")])
6516
6517 (define_insn ""
6518   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6519         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6520                         (const_int 0))
6521                  (match_operand:SI 2 "gpc_reg_operand" "r")))
6522    (clobber (match_scratch:SI 3 "=&r"))]
6523   ""
6524   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze|addze} %0,%2"
6525   [(set_attr "length" "12")])
6526
6527 (define_insn ""
6528   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6529         (compare:CC
6530          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6531                          (const_int 0))
6532                   (match_operand:SI 2 "gpc_reg_operand" "r"))
6533          (const_int 0)))
6534    (clobber (match_scratch:SI 3 "=&r"))]
6535   ""
6536   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %0,%2"
6537   [(set_attr "type" "compare")
6538    (set_attr "length" "12")])
6539
6540 (define_insn ""
6541   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
6542         (compare:CC
6543          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6544                          (const_int 0))
6545                   (match_operand:SI 2 "gpc_reg_operand" "r"))
6546          (const_int 0)))
6547    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6548         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
6549    (clobber (match_scratch:SI 3 "=&r"))]
6550   ""
6551   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2"
6552   [(set_attr "type" "compare")
6553    (set_attr "length" "12")])
6554
6555 (define_insn ""
6556   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6557         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6558                         (match_operand:SI 2 "reg_or_short_operand" "r"))
6559                  (match_operand:SI 3 "gpc_reg_operand" "r")))
6560    (clobber (match_scratch:SI 4 "=&r"))]
6561   "TARGET_POWER"
6562   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze|addze} %0,%3"
6563   [(set_attr "length" "12")])
6564
6565 (define_insn ""
6566   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6567         (compare:CC
6568          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6569                          (match_operand:SI 2 "reg_or_short_operand" "r"))
6570                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6571          (const_int 0)))
6572    (clobber (match_scratch:SI 4 "=&r"))]
6573   "TARGET_POWER"
6574   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3"
6575   [(set_attr "type" "compare")
6576    (set_attr "length" "12")])
6577
6578 (define_insn ""
6579   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
6580         (compare:CC
6581          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6582                          (match_operand:SI 2 "reg_or_short_operand" "r"))
6583                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6584          (const_int 0)))
6585    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6586         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6587    (clobber (match_scratch:SI 4 "=&r"))]
6588   "TARGET_POWER"
6589   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %0,%3"
6590   [(set_attr "type" "compare")
6591    (set_attr "length" "12")])
6592
6593 (define_insn ""
6594   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6595         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6596                        (const_int 0))))]
6597   ""
6598   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
6599   [(set_attr "length" "12")])
6600
6601 (define_insn ""
6602   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6603         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6604                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
6605   "TARGET_POWER"
6606   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
6607   [(set_attr "length" "12")])
6608
6609 (define_insn ""
6610   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6611         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6612                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
6613   ""
6614   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
6615   [(set_attr "length" "12")])
6616
6617 (define_insn ""
6618   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
6619         (compare:CC
6620          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6621                  (match_operand:SI 2 "reg_or_short_operand" "rI"))
6622          (const_int 0)))
6623    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6624         (gtu:SI (match_dup 1) (match_dup 2)))]
6625   ""
6626   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0"
6627   [(set_attr "type" "compare")
6628    (set_attr "length" "12")])
6629
6630 (define_insn ""
6631   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
6632         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
6633                          (match_operand:SI 2 "reg_or_short_operand" "I,r,rI"))
6634                  (match_operand:SI 3 "reg_or_short_operand" "r,r,I")))
6635    (clobber (match_scratch:SI 4 "=&r,&r,&r"))]
6636   ""
6637   "@
6638    {ai|addic} %4,%1,%k2\;{aze|addze} %0,%3
6639    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
6640    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3"
6641   [(set_attr "length" "8,12,12")])
6642
6643 (define_insn ""
6644   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
6645         (compare:CC
6646          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6647                           (match_operand:SI 2 "reg_or_short_operand" "I,r"))
6648                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6649          (const_int 0)))
6650    (clobber (match_scratch:SI 4 "=&r,&r"))]
6651   ""
6652   "@
6653    {ai|addic} %4,%1,%k2\;{aze.|addze.} %0,%3
6654    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
6655   [(set_attr "type" "compare")
6656    (set_attr "length" "8,12")])
6657
6658 (define_insn ""
6659   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
6660         (compare:CC
6661          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6662                           (match_operand:SI 2 "reg_or_short_operand" "I,r"))
6663                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6664          (const_int 0)))
6665    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6666         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6667    (clobber (match_scratch:SI 4 "=&r,&r"))]
6668   ""
6669   "@
6670    {ai|addic} %4,%1,%k2\;{aze.|addze.} %0,%3
6671    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
6672   [(set_attr "type" "compare")
6673    (set_attr "length" "8,12")])
6674
6675 (define_insn ""
6676   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6677         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6678                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
6679   ""
6680   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
6681   [(set_attr "length" "8")])
6682 \f
6683 ;; Define both directions of branch and return.  If we need a reload
6684 ;; register, we'd rather use CR0 since it is much easier to copy a
6685 ;; register CC value to there.
6686
6687 (define_insn ""
6688   [(set (pc)
6689         (if_then_else (match_operator 1 "branch_comparison_operator"
6690                                       [(match_operand 2
6691                                                       "cc_reg_operand" "x,?y")
6692                                        (const_int 0)])
6693                       (label_ref (match_operand 0 "" ""))
6694                       (pc)))]
6695   ""
6696   "*
6697 {
6698   if (get_attr_length (insn) == 8)
6699     return \"%C1bc %t1,%j1,%l0\";
6700   else
6701     return \"%C1bc %T1,%j1,$+8\;b %l0\";
6702 }"
6703   [(set_attr "type" "branch")])
6704
6705 (define_insn ""
6706   [(set (pc)
6707         (if_then_else (match_operator 0 "branch_comparison_operator"
6708                                       [(match_operand 1
6709                                                       "cc_reg_operand" "x,?y")
6710                                        (const_int 0)])
6711                       (return)
6712                       (pc)))]
6713   "direct_return ()"
6714   "{%C0bcr|%C0bclr} %t0,%j0"
6715   [(set_attr "length" "8")])
6716
6717 (define_insn ""
6718   [(set (pc)
6719         (if_then_else (match_operator 1 "branch_comparison_operator"
6720                                       [(match_operand 2
6721                                                       "cc_reg_operand" "x,?y")
6722                                        (const_int 0)])
6723                       (pc)
6724                       (label_ref (match_operand 0 "" ""))))]
6725   ""
6726   "*
6727 {
6728   if (get_attr_length (insn) == 8)
6729     return \"%C1bc %T1,%j1,%l0\";
6730   else
6731     return \"%C1bc %t1,%j1,$+8\;b %l0\";
6732 }"
6733   [(set_attr "type" "branch")])
6734
6735 (define_insn ""
6736   [(set (pc)
6737         (if_then_else (match_operator 0 "branch_comparison_operator"
6738                                       [(match_operand 1
6739                                                       "cc_reg_operand" "x,?y")
6740                                        (const_int 0)])
6741                       (pc)
6742                       (return)))]
6743   "direct_return ()"
6744   "{%C0bcr|%C0bclr} %T0,%j0"
6745   [(set_attr "length" "8")])
6746
6747 ;; Unconditional branch and return.
6748
6749 (define_insn "jump"
6750   [(set (pc)
6751         (label_ref (match_operand 0 "" "")))]
6752   ""
6753   "b %l0")
6754
6755 (define_insn "return"
6756   [(return)]
6757   "direct_return ()"
6758   "{br|blr}"
6759   [(set_attr "type" "jmpreg")])
6760
6761 (define_insn "indirect_jump"
6762   [(set (pc) (match_operand:SI 0 "register_operand" "c,l"))]
6763   ""
6764   "@
6765    bctr
6766    {br|blr}"
6767   [(set_attr "type" "jmpreg")])
6768
6769 ;; Table jump for switch statements:
6770 (define_expand "tablejump"
6771   [(set (match_dup 3)
6772         (plus:SI (match_operand:SI 0 "" "")
6773                  (match_dup 2)))
6774    (parallel [(set (pc) (match_dup 3))
6775               (use (label_ref (match_operand 1 "" "")))])]
6776   ""
6777   "
6778 { operands[0] = force_reg (SImode, operands[0]);
6779   operands[2] = force_reg (SImode, gen_rtx (LABEL_REF, VOIDmode, operands[1]));
6780   operands[3] = gen_reg_rtx (SImode);
6781 }")
6782
6783 (define_insn ""
6784   [(set (pc)
6785         (match_operand:SI 0 "register_operand" "c,l"))
6786    (use (label_ref (match_operand 1 "" "")))]
6787   ""
6788   "@
6789    bctr
6790    {br|blr}")
6791
6792 (define_insn "nop"
6793   [(const_int 0)]
6794   ""
6795   "{cror 0,0,0|nop}")
6796 \f
6797 ;; Define the subtract-one-and-jump insns, starting with the template 
6798 ;; so loop.c knows what to generate.
6799
6800 (define_expand "decrement_and_branchsi"
6801   [(parallel [(set (pc) (if_then_else (ne (match_operand:SI 0 "register_operand" "c")
6802                                           (const_int 1))
6803                                       (label_ref (match_operand 1 "" ""))
6804                                       (pc)))
6805               (set (match_dup 0) (plus:SI (match_dup 0) (const_int -1)))])]
6806   ""
6807   "")
6808
6809 ;; We need to be able to do this for any operand, including MEM, or we
6810 ;; will cause reload to blow up since we don't allow output reloads on
6811 ;; JUMP_INSNs. 
6812 (define_insn ""
6813   [(set (pc)
6814         (if_then_else (ne (match_operand:SI 1 "register_operand" "0,*r,*r")
6815                           (const_int 1))
6816                       (label_ref (match_operand 2 "" ""))
6817                       (pc)))
6818    (set (match_operand:SI 0 "register_operand" "=c,*r,m*q*c*l")
6819         (plus:SI (match_dup 1) (const_int -1)))
6820    (clobber (match_scratch:CC 3 "=X,&x,&x"))
6821    (clobber (match_scratch:SI 4 "=X,X,r"))]
6822   ""
6823   "*
6824 {
6825   if (which_alternative != 0)
6826     return \"#\";
6827   else if (get_attr_length (insn) == 8)
6828     return \"{bdn|bdnz} %l2\";
6829   else
6830     return \"bdz $+8\;b %l2\";
6831 }"
6832   [(set_attr "type" "branch")
6833    (set_attr "length" "*,12,16")])
6834                                
6835 ;; Similar, but we can use GE since we have a REG_NONNEG.
6836 (define_insn ""
6837   [(set (pc)
6838         (if_then_else (ge (match_operand:SI 1 "register_operand" "0,*r,*r")
6839                           (const_int 0))
6840                       (label_ref (match_operand 2 "" ""))
6841                       (pc)))
6842    (set (match_operand:SI 0 "register_operand" "=c,*r,m*q*c*l")
6843         (plus:SI (match_dup 1) (const_int -1)))
6844    (clobber (match_scratch:CC 3 "=X,&x,&X"))
6845    (clobber (match_scratch:SI 4 "=X,X,r"))]
6846   "find_reg_note (insn, REG_NONNEG, 0)"
6847   "*
6848 {
6849   if (which_alternative != 0)
6850     return \"#\";
6851   else if (get_attr_length (insn) == 8)
6852     return \"{bdn|bdnz} %l2\";
6853   else
6854     return \"bdz $+8\;b %l2\";
6855 }"
6856   [(set_attr "type" "branch")
6857    (set_attr "length" "*,12,16")])
6858                                
6859 (define_insn ""
6860   [(set (pc)
6861         (if_then_else (eq (match_operand:SI 1 "register_operand" "0,*r,*r")
6862                           (const_int 1))
6863                       (label_ref (match_operand 2 "" ""))
6864                       (pc)))
6865    (set (match_operand:SI 0 "register_operand" "=c,*r,m*q*c*l")
6866         (plus:SI (match_dup 1) (const_int -1)))
6867    (clobber (match_scratch:CC 3 "=X,&x,&x"))
6868    (clobber (match_scratch:SI 4 "=X,X,r"))]
6869   ""
6870   "*
6871 {
6872   if (which_alternative != 0)
6873     return \"#\";
6874   else if (get_attr_length (insn) == 8)
6875     return \"bdz %l2\";
6876   else
6877     return \"{bdn|bdnz} $+8\;b %l2\";
6878 }"
6879   [(set_attr "type" "branch")
6880    (set_attr "length" "*,12,16")])
6881
6882 (define_split
6883   [(set (pc)
6884         (if_then_else (match_operator 2 "comparison_operator"
6885                                       [(match_operand:SI 1 "gpc_reg_operand" "")
6886                                        (const_int 1)])
6887                       (match_operand 5 "" "")
6888                       (match_operand 6 "" "")))
6889    (set (match_operand:SI 0 "gpc_reg_operand" "")
6890         (plus:SI (match_dup 1) (const_int -1)))
6891    (clobber (match_scratch:CC 3 ""))
6892    (clobber (match_scratch:SI 4 ""))]
6893   "reload_completed"
6894   [(parallel [(set (match_dup 3)
6895                    (compare:CC (plus:SI (match_dup 1) (const_int -1))
6896                                (const_int 0)))
6897               (set (match_dup 0) (plus:SI (match_dup 1) (const_int -1)))])
6898    (set (pc) (if_then_else (match_dup 7) (match_dup 5) (match_dup 6)))]
6899   "
6900 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
6901                          const0_rtx); }")
6902
6903 (define_split
6904   [(set (pc)
6905         (if_then_else (match_operator 2 "comparison_operator"
6906                                       [(match_operand:SI 1 "gpc_reg_operand" "")
6907                                        (const_int 1)])
6908                       (match_operand 5 "" "")
6909                       (match_operand 6 "" "")))
6910    (set (match_operand:SI 0 "general_operand" "")
6911         (plus:SI (match_dup 1) (const_int -1)))
6912    (clobber (match_scratch:CC 3 ""))
6913    (clobber (match_scratch:SI 4 ""))]
6914   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
6915   [(parallel [(set (match_dup 3)
6916                    (compare:CC (plus:SI (match_dup 1) (const_int -1))
6917                                (const_int 0)))
6918               (set (match_dup 4) (plus:SI (match_dup 1) (const_int -1)))])
6919    (set (match_dup 0) (match_dup 4))
6920    (set (pc) (if_then_else (match_dup 7) (match_dup 5) (match_dup 6)))]
6921   "
6922 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
6923                          const0_rtx); }")