f529ad875e363d30aac628607bb033dc1f670c58
[platform/upstream/gcc.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 91-96, 1997 Free Software Foundation, Inc.
3 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
4
5 ;; This file is part of GNU CC.
6
7 ;; GNU CC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
11
12 ;; GNU CC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU CC; see the file COPYING.  If not, write to
19 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
21
22 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
23 \f
24 ;; Define an insn type attribute.  This is used in function unit delay
25 ;; computations.
26 (define_attr "type" "integer,load,store,fpload,fpstore,imul,idiv,branch,compare,delayed_compare,fpcompare,mtjmpr,fp,dmul,sdiv,ddiv,ssqrt,dsqrt,jmpreg"
27   (const_string "integer"))
28
29 ;; Length (in bytes).
30 (define_attr "length" ""
31   (if_then_else (eq_attr "type" "branch")
32                 (if_then_else (and (ge (minus (pc) (match_dup 0))
33                                        (const_int -32768))
34                                    (lt (minus (pc) (match_dup 0))
35                                        (const_int 32767)))
36                               (const_int 8)
37                               (const_int 12))
38                 (const_int 4)))
39
40 ;; Processor type -- this attribute must exactly match the processor_type
41 ;; enumeration in rs6000.h.
42
43 (define_attr "cpu" "rios1,rios2,mpccore,ppc403,ppc601,ppc603,ppc604,ppc620"
44   (const (symbol_ref "rs6000_cpu_attr")))
45
46 ; (define_function_unit NAME MULTIPLICITY SIMULTANEITY
47 ;                       TEST READY-DELAY ISSUE-DELAY [CONFLICT-LIST])
48
49 ; Load/Store Unit -- pure PowerPC only
50 ; (POWER and 601 use Integer Unit)
51 (define_function_unit "lsu" 1 0
52   (and (eq_attr "type" "load")
53        (eq_attr "cpu" "mpccore,ppc603,ppc604,ppc620"))
54   2 1)
55
56 (define_function_unit "lsu" 1 0
57   (and (eq_attr "type" "store,fpstore")
58        (eq_attr "cpu" "mpccore,ppc603,ppc604,ppc620"))
59   1 1)
60
61 (define_function_unit "lsu" 1 0
62   (and (eq_attr "type" "fpload")
63        (eq_attr "cpu" "mpccore,ppc603"))
64   2 1)
65
66 (define_function_unit "lsu" 1 0
67   (and (eq_attr "type" "fpload")
68        (eq_attr "cpu" "ppc604,ppc620"))
69   3 1)
70
71 (define_function_unit "iu" 1 0
72   (and (eq_attr "type" "load")
73        (eq_attr "cpu" "rios1,ppc403,ppc601"))
74   2 1)
75
76 (define_function_unit "iu" 1 0
77   (and (eq_attr "type" "store,fpstore")
78        (eq_attr "cpu" "rios1,ppc403,ppc601"))
79   1 1)
80
81 (define_function_unit "fpu" 1 0
82   (and (eq_attr "type" "fpstore")
83        (eq_attr "cpu" "rios1,ppc601"))
84   0 1)
85
86 (define_function_unit "iu" 1 0
87   (and (eq_attr "type" "fpload")
88        (eq_attr "cpu" "rios1"))
89   2 1)
90
91 (define_function_unit "iu" 1 0
92   (and (eq_attr "type" "fpload")
93        (eq_attr "cpu" "ppc601"))
94   3 1)
95
96 (define_function_unit "iu2" 2 0
97   (and (eq_attr "type" "load,fpload")
98        (eq_attr "cpu" "rios2"))
99   2 1)
100
101 (define_function_unit "iu2" 2 0
102   (and (eq_attr "type" "store,fpstore")
103        (eq_attr "cpu" "rios2"))
104   1 1)
105
106 ; Integer Unit (RIOS1, PPC601, PPC603)
107 (define_function_unit "iu" 1 0
108   (and (eq_attr "type" "integer")
109        (eq_attr "cpu" "rios1,mpccore,ppc403,ppc601,ppc603"))
110   1 1)
111
112 (define_function_unit "iu" 1 0
113   (and (eq_attr "type" "imul")
114        (eq_attr "cpu" "ppc403"))
115   4 4)
116
117 (define_function_unit "iu" 1 0
118   (and (eq_attr "type" "imul")
119        (eq_attr "cpu" "rios1,ppc601,ppc603"))
120   5 5)
121
122 (define_function_unit "iu" 1 0
123   (and (eq_attr "type" "idiv")
124        (eq_attr "cpu" "rios1"))
125   19 19)
126
127 (define_function_unit "iu" 1 0
128   (and (eq_attr "type" "idiv")
129        (eq_attr "cpu" "ppc403"))
130   33 33)
131
132 (define_function_unit "iu" 1 0
133   (and (eq_attr "type" "idiv")
134        (eq_attr "cpu" "ppc601"))
135   36 36)
136
137 (define_function_unit "iu" 1 0
138   (and (eq_attr "type" "idiv")
139        (eq_attr "cpu" "ppc603"))
140   37 36)
141
142 ; RIOS2 has two integer units: a primary one which can perform all
143 ; operations and a secondary one which is fed in lock step with the first
144 ; and can perform "simple" integer operations.  
145 ; To catch this we define a 'dummy' imuldiv-unit that is also needed
146 ; for the complex insns. 
147 (define_function_unit "iu2" 2 0
148   (and (eq_attr "type" "integer")
149        (eq_attr "cpu" "rios2"))
150   1 1)
151
152 (define_function_unit "iu2" 2 0
153   (and (eq_attr "type" "imul")
154        (eq_attr "cpu" "rios2"))
155   2 2)
156
157 (define_function_unit "iu2" 2 0
158   (and (eq_attr "type" "idiv")
159        (eq_attr "cpu" "rios2"))
160   13 13)
161
162 (define_function_unit "imuldiv" 1 0
163   (and (eq_attr "type" "imul")
164        (eq_attr "cpu" "rios2"))
165   2 2)
166
167 (define_function_unit "imuldiv" 1 0
168   (and (eq_attr "type" "idiv")
169        (eq_attr "cpu" "rios2"))
170   13 13)
171
172 ; MPCCORE has separate IMUL/IDIV unit for multicycle instructions
173 ; Divide latency varies greatly from 2-11, use 6 as average
174 (define_function_unit "imuldiv" 1 0
175   (and (eq_attr "type" "imul")
176        (eq_attr "cpu" "mpccore"))
177   2 1)
178
179 (define_function_unit "imuldiv" 1 0
180   (and (eq_attr "type" "idiv")
181        (eq_attr "cpu" "mpccore"))
182   6 6)
183
184 ; PPC604 has two units that perform integer operations
185 ; and one unit for divide/multiply operations (and move
186 ; from/to spr).
187 (define_function_unit "iu2" 2 0
188   (and (eq_attr "type" "integer")
189        (eq_attr "cpu" "ppc604,ppc620"))
190   1 1)
191
192 (define_function_unit "imuldiv" 1 0
193   (and (eq_attr "type" "imul")
194        (eq_attr "cpu" "ppc604,ppc620"))
195   4 2)
196
197 (define_function_unit "imuldiv" 1 0
198   (and (eq_attr "type" "idiv")
199        (eq_attr "cpu" "ppc604,ppc620"))
200   20 19)
201
202 ; compare is done on integer unit, but feeds insns which
203 ; execute on the branch unit.
204 (define_function_unit "iu" 1 0   
205   (and (eq_attr "type" "compare")
206        (eq_attr "cpu" "rios1"))
207   4 1)
208
209 (define_function_unit "iu" 1 0   
210   (and (eq_attr "type" "delayed_compare")
211        (eq_attr "cpu" "rios1"))
212   5 1)
213
214 (define_function_unit "iu" 1 0
215   (and (eq_attr "type" "compare,delayed_compare")
216        (eq_attr "cpu" "mpccore,ppc403,ppc601,ppc603,ppc604,ppc620"))
217   3 1)
218
219 (define_function_unit "iu2" 2 0   
220   (and (eq_attr "type" "compare,delayed_compare")
221        (eq_attr "cpu" "rios2"))
222   3 1)
223
224 (define_function_unit "iu2" 2 0
225   (and (eq_attr "type" "compare,delayed_compare")
226        (eq_attr "cpu" "ppc604,ppc620"))
227   1 1)
228
229 ; fp compare uses fp unit
230 (define_function_unit "fpu" 1 0
231   (and (eq_attr "type" "fpcompare")
232        (eq_attr "cpu" "rios1"))
233   9 1)
234
235 ; rios1 and rios2 have different fpcompare delays
236 (define_function_unit "fpu2" 2 0
237   (and (eq_attr "type" "fpcompare")
238        (eq_attr "cpu" "rios2"))
239   5 1)
240
241 ; on ppc601 and ppc603, fpcompare takes also 2 cycles from
242 ; the integer unit
243 ; here we do not define delays, just occupy the unit. The dependencies
244 ; will be assigned by the fpcompare definition in the fpu.
245 (define_function_unit "iu" 1 0
246   (and (eq_attr "type" "fpcompare")
247        (eq_attr "cpu" "ppc601,ppc603"))
248   0 2)
249
250 ; fp compare uses fp unit
251 (define_function_unit "fpu" 1 0
252   (and (eq_attr "type" "fpcompare")
253        (eq_attr "cpu" "ppc601,ppc603,ppc604,ppc620"))
254   5 1)
255
256 (define_function_unit "fpu" 1 0
257   (and (eq_attr "type" "fpcompare")
258        (eq_attr "cpu" "mpccore"))
259   1 1)
260
261 (define_function_unit "bpu" 1 0
262   (and (eq_attr "type" "mtjmpr")
263        (eq_attr "cpu" "rios1,rios2"))
264   5 1)
265
266 (define_function_unit "bpu" 1 0
267   (and (eq_attr "type" "mtjmpr")
268        (eq_attr "cpu" "mpccore,ppc403,ppc601,ppc603,ppc604,ppc620"))
269   4 1)
270
271 ; all jumps/branches are executing on the bpu, in 1 cycle, for all machines.
272 (define_function_unit "bpu" 1 0
273   (eq_attr "type" "jmpreg")
274   1 1)
275
276 (define_function_unit "bpu" 1 0
277   (eq_attr "type" "branch")
278   1 1)
279
280 ; Floating Point Unit
281 (define_function_unit "fpu" 1 0
282   (and (eq_attr "type" "fp,dmul")
283        (eq_attr "cpu" "rios1"))
284   2 1)
285
286 (define_function_unit "fpu" 1 0
287   (and (eq_attr "type" "fp")
288        (eq_attr "cpu" "mpccore"))
289   4 4)
290
291 (define_function_unit "fpu" 1 0
292   (and (eq_attr "type" "fp")
293        (eq_attr "cpu" "ppc601"))
294   4 1)
295
296 (define_function_unit "fpu" 1 0
297   (and (eq_attr "type" "fp")
298        (eq_attr "cpu" "ppc603,ppc604,ppc620"))
299   3 1)
300
301 (define_function_unit "fpu" 1 0
302   (and (eq_attr "type" "dmul")
303        (eq_attr "cpu" "mpccore"))
304   5 5)
305
306 (define_function_unit "fpu" 1 0
307   (and (eq_attr "type" "dmul")
308        (eq_attr "cpu" "ppc601"))
309   5 2)
310
311 ; is this true?
312 (define_function_unit "fpu" 1 0
313   (and (eq_attr "type" "dmul")
314        (eq_attr "cpu" "ppc603"))
315   4 2)
316
317 (define_function_unit "fpu" 1 0
318   (and (eq_attr "type" "dmul")
319        (eq_attr "cpu" "ppc604,ppc620"))
320   3 1)
321
322 (define_function_unit "fpu" 1 0
323   (and (eq_attr "type" "sdiv,ddiv")
324        (eq_attr "cpu" "rios1"))
325   19 19)
326
327 (define_function_unit "fpu" 1 0
328   (and (eq_attr "type" "sdiv")
329        (eq_attr "cpu" "ppc601"))
330   17 17)
331
332 (define_function_unit "fpu" 1 0
333   (and (eq_attr "type" "sdiv")
334        (eq_attr "cpu" "mpccore"))
335   10 10)
336
337 (define_function_unit "fpu" 1 0
338   (and (eq_attr "type" "sdiv")
339        (eq_attr "cpu" "ppc603,ppc604,ppc620"))
340   18 18)
341
342 (define_function_unit "fpu" 1 0
343   (and (eq_attr "type" "ddiv")
344        (eq_attr "cpu" "mpccore"))
345   17 17)
346
347 (define_function_unit "fpu" 1 0
348   (and (eq_attr "type" "ddiv")
349        (eq_attr "cpu" "ppc601,ppc604,ppc620"))
350   31 31)
351
352 (define_function_unit "fpu" 1 0
353   (and (eq_attr "type" "ddiv")
354        (eq_attr "cpu" "ppc603"))
355   33 33)
356
357 (define_function_unit "fpu" 1 0
358   (and (eq_attr "type" "ssqrt")
359        (eq_attr "cpu" "ppc620"))
360   31 31)
361
362 (define_function_unit "fpu" 1 0
363   (and (eq_attr "type" "dsqrt")
364        (eq_attr "cpu" "ppc620"))
365   31 31)
366
367 ; RIOS2 has two symmetric FPUs.
368 (define_function_unit "fpu2" 2 0
369   (and (eq_attr "type" "fp")
370        (eq_attr "cpu" "rios2"))
371   2 1)
372
373 (define_function_unit "fpu2" 2 0
374   (and (eq_attr "type" "dmul")
375        (eq_attr "cpu" "rios2"))
376   2 1)
377
378 (define_function_unit "fpu2" 2 0
379   (and (eq_attr "type" "sdiv,ddiv")
380        (eq_attr "cpu" "rios2"))
381   17 17)
382
383 (define_function_unit "fpu2" 2 0
384   (and (eq_attr "type" "ssqrt,dsqrt")
385        (eq_attr "cpu" "rios2"))
386   26 26)
387
388 \f
389 ;; Start with fixed-point load and store insns.  Here we put only the more
390 ;; complex forms.  Basic data transfer is done later.
391
392 (define_expand "zero_extendqidi2"
393   [(set (match_operand:DI 0 "gpc_reg_operand" "")
394         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
395   "TARGET_POWERPC64"
396   "")
397
398 (define_insn ""
399   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
400         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
401   "TARGET_POWERPC64"
402   "@
403    lbz%U1%X1 %0,%1
404    rldicl %0,%1,0,56"
405   [(set_attr "type" "load,*")])
406
407 (define_insn ""
408   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
409         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
410                     (const_int 0)))
411    (clobber (match_scratch:DI 2 "=r"))]
412   "TARGET_POWERPC64"
413   "rldicl. %2,%1,0,56"
414   [(set_attr "type" "compare")])
415
416 (define_insn ""
417   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
418         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
419                     (const_int 0)))
420    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
421         (zero_extend:DI (match_dup 1)))]
422   "TARGET_POWERPC64"
423   "rldicl. %0,%1,0,56"
424   [(set_attr "type" "compare")])
425
426 (define_insn "extendqidi2"
427   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
428         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
429   "TARGET_POWERPC64"
430   "extsb %0,%1")
431
432 (define_insn ""
433   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
434         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
435                     (const_int 0)))
436    (clobber (match_scratch:DI 2 "=r"))]
437   "TARGET_POWERPC64"
438   "extsb. %2,%1"
439   [(set_attr "type" "compare")])
440
441 (define_insn ""
442   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
443         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
444                     (const_int 0)))
445    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
446         (sign_extend:DI (match_dup 1)))]
447   "TARGET_POWERPC64"
448   "extsb. %0,%1"
449   [(set_attr "type" "compare")])
450
451 (define_expand "zero_extendhidi2"
452   [(set (match_operand:DI 0 "gpc_reg_operand" "")
453         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
454   "TARGET_POWERPC64"
455   "")
456
457 (define_insn ""
458   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
459         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
460   "TARGET_POWERPC64"
461   "@
462    lhz%U1%X1 %0,%1
463    rldicl %0,%1,0,48"
464   [(set_attr "type" "load,*")])
465
466 (define_insn ""
467   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
468         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
469                     (const_int 0)))
470    (clobber (match_scratch:DI 2 "=r"))]
471   "TARGET_POWERPC64"
472   "rldicl. %2,%1,0,48"
473   [(set_attr "type" "compare")])
474
475 (define_insn ""
476   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
477         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
478                     (const_int 0)))
479    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
480         (zero_extend:DI (match_dup 1)))]
481   "TARGET_POWERPC64"
482   "rldicl. %0,%1,0,48"
483   [(set_attr "type" "compare")])
484
485 (define_expand "extendhidi2"
486   [(set (match_operand:DI 0 "gpc_reg_operand" "")
487         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
488   "TARGET_POWERPC64"
489   "")
490
491 (define_insn ""
492   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
493         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
494   "TARGET_POWERPC64"
495   "@
496    lha%U1%X1 %0,%1
497    extsh %0,%1"
498   [(set_attr "type" "load,*")])
499
500 (define_insn ""
501   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
502         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
503                     (const_int 0)))
504    (clobber (match_scratch:DI 2 "=r"))]
505   "TARGET_POWERPC64"
506   "extsh. %2,%1"
507   [(set_attr "type" "compare")])
508
509 (define_insn ""
510   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
511         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
512                     (const_int 0)))
513    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
514         (sign_extend:DI (match_dup 1)))]
515   "TARGET_POWERPC64"
516   "extsh. %0,%1"
517   [(set_attr "type" "compare")])
518
519 (define_expand "zero_extendsidi2"
520   [(set (match_operand:DI 0 "gpc_reg_operand" "")
521         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
522   "TARGET_POWERPC64"
523   "")
524
525 (define_insn ""
526   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
527         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
528   "TARGET_POWERPC64"
529   "@
530    lwz%U1%X1 %0,%1
531    rldicl %0,%1,0,32"
532   [(set_attr "type" "load,*")])
533
534 (define_insn ""
535   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
536         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
537                     (const_int 0)))
538    (clobber (match_scratch:DI 2 "=r"))]
539   "TARGET_POWERPC64"
540   "rldicl. %2,%1,0,32"
541   [(set_attr "type" "compare")])
542
543 (define_insn ""
544   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
545         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
546                     (const_int 0)))
547    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
548         (zero_extend:DI (match_dup 1)))]
549   "TARGET_POWERPC64"
550   "rldicl. %0,%1,0,32"
551   [(set_attr "type" "compare")])
552
553 (define_expand "extendsidi2"
554   [(set (match_operand:DI 0 "gpc_reg_operand" "")
555         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
556   "TARGET_POWERPC64"
557   "")
558
559 (define_insn ""
560   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
561         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
562   "TARGET_POWERPC64"
563   "@
564    lwa%U1%X1 %0,%1
565    extsw %0,%1"
566   [(set_attr "type" "load,*")])
567
568 (define_insn ""
569   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
570         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
571                     (const_int 0)))
572    (clobber (match_scratch:DI 2 "=r"))]
573   "TARGET_POWERPC64"
574   "extsw. %2,%1"
575   [(set_attr "type" "compare")])
576
577 (define_insn ""
578   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
579         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
580                     (const_int 0)))
581    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
582         (sign_extend:DI (match_dup 1)))]
583   "TARGET_POWERPC64"
584   "extsw. %0,%1"
585   [(set_attr "type" "compare")])
586
587 (define_expand "zero_extendqisi2"
588   [(set (match_operand:SI 0 "gpc_reg_operand" "")
589         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
590   ""
591   "")
592
593 (define_insn ""
594   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
595         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
596   ""
597   "@
598    lbz%U1%X1 %0,%1
599    {rlinm|rlwinm} %0,%1,0,0xff"
600   [(set_attr "type" "load,*")])
601
602 (define_insn ""
603   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
604         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
605                     (const_int 0)))
606    (clobber (match_scratch:SI 2 "=r"))]
607   ""
608   "{andil.|andi.} %2,%1,0xff"
609   [(set_attr "type" "compare")])
610
611 (define_insn ""
612   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
613         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
614                     (const_int 0)))
615    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
616         (zero_extend:SI (match_dup 1)))]
617   ""
618   "{andil.|andi.} %0,%1,0xff"
619   [(set_attr "type" "compare")])
620
621 (define_expand "extendqisi2"
622   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
623    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
624   ""
625   "
626 {
627   if (TARGET_POWERPC)
628     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
629   else if (TARGET_POWER)
630     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
631   else
632     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
633   DONE;
634 }")
635
636 (define_insn "extendqisi2_ppc"
637   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
638         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
639   "TARGET_POWERPC"
640   "extsb %0,%1")
641
642 (define_insn ""
643   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
644         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
645                     (const_int 0)))
646    (clobber (match_scratch:SI 2 "=r"))]
647   "TARGET_POWERPC"
648   "extsb. %2,%1"
649   [(set_attr "type" "compare")])
650
651 (define_insn ""
652   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
653         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
654                     (const_int 0)))
655    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
656         (sign_extend:SI (match_dup 1)))]
657   "TARGET_POWERPC"
658   "extsb. %0,%1"
659   [(set_attr "type" "compare")])
660
661 (define_expand "extendqisi2_power"
662   [(parallel [(set (match_dup 2)
663                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
664                               (const_int 24)))
665               (clobber (scratch:SI))])
666    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
667                    (ashiftrt:SI (match_dup 2)
668                                 (const_int 24)))
669               (clobber (scratch:SI))])]
670   "TARGET_POWER"
671   "
672 { operands[1] = gen_lowpart (SImode, operands[1]);
673   operands[2] = gen_reg_rtx (SImode); }")
674
675 (define_expand "extendqisi2_no_power"
676   [(set (match_dup 2)
677         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
678                    (const_int 24)))
679    (set (match_operand:SI 0 "gpc_reg_operand" "")
680         (ashiftrt:SI (match_dup 2)
681                      (const_int 24)))]
682   "! TARGET_POWER && ! TARGET_POWERPC"
683   "
684 { operands[1] = gen_lowpart (SImode, operands[1]);
685   operands[2] = gen_reg_rtx (SImode); }")
686
687 (define_expand "zero_extendqihi2"
688   [(set (match_operand:HI 0 "gpc_reg_operand" "")
689         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
690   ""
691   "")
692
693 (define_insn ""
694   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
695         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
696   ""
697   "@
698    lbz%U1%X1 %0,%1
699    {rlinm|rlwinm} %0,%1,0,0xff"
700   [(set_attr "type" "load,*")])
701
702 (define_insn ""
703   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
704         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
705                     (const_int 0)))
706    (clobber (match_scratch:HI 2 "=r"))]
707   ""
708   "{andil.|andi.} %2,%1,0xff"
709   [(set_attr "type" "compare")])
710
711 (define_insn ""
712   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
713         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
714                     (const_int 0)))
715    (set (match_operand:HI 0 "gpc_reg_operand" "=r")
716         (zero_extend:HI (match_dup 1)))]
717   ""
718   "{andil.|andi.} %0,%1,0xff"
719   [(set_attr "type" "compare")])
720
721 (define_expand "extendqihi2"
722   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
723    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
724   ""
725   "
726 {
727   if (TARGET_POWERPC)
728     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
729   else if (TARGET_POWER)
730     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
731   else
732     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
733   DONE;
734 }")
735
736 (define_insn "extendqihi2_ppc"
737   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
738         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
739   "TARGET_POWERPC"
740   "extsb %0,%1")
741
742 (define_insn ""
743   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
744         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
745                     (const_int 0)))
746    (clobber (match_scratch:HI 2 "=r"))]
747   "TARGET_POWERPC"
748   "extsb. %2,%1"
749   [(set_attr "type" "compare")])
750
751 (define_insn ""
752   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
753         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
754                     (const_int 0)))
755    (set (match_operand:HI 0 "gpc_reg_operand" "=r")
756         (sign_extend:HI (match_dup 1)))]
757   "TARGET_POWERPC"
758   "extsb. %0,%1"
759   [(set_attr "type" "compare")])
760
761 (define_expand "extendqihi2_power"
762   [(parallel [(set (match_dup 2)
763                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
764                               (const_int 24)))
765               (clobber (scratch:SI))])
766    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
767                    (ashiftrt:SI (match_dup 2)
768                                 (const_int 24)))
769               (clobber (scratch:SI))])]
770   "TARGET_POWER"
771   "
772 { operands[0] = gen_lowpart (SImode, operands[0]);
773   operands[1] = gen_lowpart (SImode, operands[1]);
774   operands[2] = gen_reg_rtx (SImode); }")
775
776 (define_expand "extendqihi2_no_power"
777   [(set (match_dup 2)
778         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
779                    (const_int 24)))
780    (set (match_operand:HI 0 "gpc_reg_operand" "")
781         (ashiftrt:SI (match_dup 2)
782                      (const_int 24)))]
783   "! TARGET_POWER && ! TARGET_POWERPC"
784   "
785 { operands[0] = gen_lowpart (SImode, operands[0]);
786   operands[1] = gen_lowpart (SImode, operands[1]);
787   operands[2] = gen_reg_rtx (SImode); }")
788
789 (define_expand "zero_extendhisi2"
790   [(set (match_operand:SI 0 "gpc_reg_operand" "")
791         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
792   ""
793   "")
794
795 (define_insn ""
796   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
797         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
798   ""
799   "@
800    lhz%U1%X1 %0,%1
801    {rlinm|rlwinm} %0,%1,0,0xffff"
802   [(set_attr "type" "load,*")])
803
804 (define_insn ""
805   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
806         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
807                     (const_int 0)))
808    (clobber (match_scratch:SI 2 "=r"))]
809   ""
810   "{andil.|andi.} %2,%1,0xffff"
811   [(set_attr "type" "compare")])
812
813 (define_insn ""
814   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
815         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
816                     (const_int 0)))
817    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
818         (zero_extend:SI (match_dup 1)))]
819   ""
820   "{andil.|andi.} %0,%1,0xffff"
821   [(set_attr "type" "compare")])
822
823 (define_expand "extendhisi2"
824   [(set (match_operand:SI 0 "gpc_reg_operand" "")
825         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
826   ""
827   "")
828
829 (define_insn ""
830   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
831         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
832   ""
833   "@
834    lha%U1%X1 %0,%1
835    {exts|extsh} %0,%1"
836   [(set_attr "type" "load,*")])
837
838 (define_insn ""
839   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
840         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
841                     (const_int 0)))
842    (clobber (match_scratch:SI 2 "=r"))]
843   ""
844   "{exts.|extsh.} %2,%1"
845   [(set_attr "type" "compare")])
846
847 (define_insn ""
848   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
849         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
850                     (const_int 0)))
851    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
852         (sign_extend:SI (match_dup 1)))]
853   ""
854   "{exts.|extsh.} %0,%1"
855   [(set_attr "type" "compare")])
856 \f
857 ;; Fixed-point arithmetic insns.
858
859 ;; Discourage ai/addic because of carry but provide it in an alternative
860 ;; allowing register zero as source.
861 (define_expand "addsi3"
862   [(set (match_operand:SI 0 "gpc_reg_operand" "")
863         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
864                  (match_operand:SI 2 "reg_or_cint_operand" "")))]
865   ""
866   "
867 {
868   if (GET_CODE (operands[2]) == CONST_INT && !add_operand (operands[2], SImode))
869     {
870       rtx tmp = ((reload_in_progress || reload_completed
871                   || rtx_equal_p (operands[0], operands[1]))
872                  ? operands[0] : gen_reg_rtx (SImode));
873
874       HOST_WIDE_INT low = INTVAL (operands[2]) & 0xffff;
875       HOST_WIDE_INT high = INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff);
876
877       if (low & 0x8000)
878         high += 0x10000, low |= ((HOST_WIDE_INT) -1) << 16;
879
880       emit_insn (gen_addsi3 (tmp, operands[1], GEN_INT (high)));
881       emit_insn (gen_addsi3 (operands[0], tmp, GEN_INT (low)));
882       DONE;
883     }
884 }")
885
886 (define_insn "*addsi3_internal1"
887   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
888         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
889                  (match_operand:SI 2 "add_operand" "r,I,I,J")))]
890   ""
891   "@
892    {cax|add} %0,%1,%2
893    {cal %0,%2(%1)|addi %0,%1,%2}
894    {ai|addic} %0,%1,%2
895    {cau|addis} %0,%1,%v2"
896   [(set_attr "length" "4,4,4,4")])
897
898 (define_insn "*addsi3_internal2"
899   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
900         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
901                              (match_operand:SI 2 "reg_or_short_operand" "r,I"))
902                     (const_int 0)))
903    (clobber (match_scratch:SI 3 "=r,r"))]
904   ""
905   "@
906    {cax.|add.} %3,%1,%2
907    {ai.|addic.} %3,%1,%2"
908   [(set_attr "type" "compare")])
909
910 (define_insn "*addsi3_internal3"
911   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
912         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
913                              (match_operand:SI 2 "reg_or_short_operand" "r,I"))
914                     (const_int 0)))
915    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
916         (plus:SI (match_dup 1) (match_dup 2)))]
917   ""
918   "@
919    {cax.|add.} %0,%1,%2
920    {ai.|addic.} %0,%1,%2"
921   [(set_attr "type" "compare")])
922
923 ;; Split an add that we can't do in one insn into two insns, each of which
924 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
925 ;; add should be last in case the result gets used in an address.
926
927 (define_split
928   [(set (match_operand:SI 0 "gpc_reg_operand" "")
929         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
930                  (match_operand:SI 2 "non_add_cint_operand" "")))]
931   ""
932   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
933    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
934 "
935 {
936   HOST_WIDE_INT low = INTVAL (operands[2]) & 0xffff;
937   HOST_WIDE_INT high = INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff);
938
939   if (low & 0x8000)
940     high += 0x10000, low |= ((HOST_WIDE_INT) -1) << 16;
941
942   operands[3] = GEN_INT (high);
943   operands[4] = GEN_INT (low);
944 }")
945
946 (define_insn "one_cmplsi2"
947   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
948         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
949   ""
950   "nor %0,%1,%1")
951
952 (define_insn ""
953   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
954         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
955                     (const_int 0)))
956    (clobber (match_scratch:SI 2 "=r"))]
957   ""
958   "nor. %2,%1,%1"
959   [(set_attr "type" "compare")])
960
961 (define_insn ""
962   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
963         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
964                     (const_int 0)))
965    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
966         (not:SI (match_dup 1)))]
967   ""
968   "nor. %0,%1,%1"
969   [(set_attr "type" "compare")])
970
971 (define_insn ""
972   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
973         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
974                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
975   "! TARGET_POWERPC"
976   "{sf%I1|subf%I1c} %0,%2,%1")
977
978 (define_insn ""
979   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
980         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
981                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
982   "TARGET_POWERPC"
983   "@
984    subf %0,%2,%1
985    subfic %0,%2,%1")
986
987 (define_insn ""
988   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
989         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
990                               (match_operand:SI 2 "gpc_reg_operand" "r"))
991                     (const_int 0)))
992    (clobber (match_scratch:SI 3 "=r"))]
993   "! TARGET_POWERPC"
994   "{sf.|subfc.} %3,%2,%1"
995   [(set_attr "type" "compare")])
996
997 (define_insn ""
998   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
999         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1000                               (match_operand:SI 2 "gpc_reg_operand" "r"))
1001                     (const_int 0)))
1002    (clobber (match_scratch:SI 3 "=r"))]
1003   "TARGET_POWERPC"
1004   "subf. %3,%2,%1"
1005   [(set_attr "type" "compare")])
1006
1007 (define_insn ""
1008   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1009         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1010                               (match_operand:SI 2 "gpc_reg_operand" "r"))
1011                     (const_int 0)))
1012    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1013         (minus:SI (match_dup 1) (match_dup 2)))]
1014   "! TARGET_POWERPC"
1015   "{sf.|subfc.} %0,%2,%1"
1016   [(set_attr "type" "compare")])
1017
1018 (define_insn ""
1019   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1020         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1021                               (match_operand:SI 2 "gpc_reg_operand" "r"))
1022                     (const_int 0)))
1023    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1024         (minus:SI (match_dup 1) (match_dup 2)))]
1025   "TARGET_POWERPC"
1026   "subf. %0,%2,%1"
1027   [(set_attr "type" "compare")])
1028
1029 (define_expand "subsi3"
1030   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1031         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
1032                   (match_operand:SI 2 "reg_or_cint_operand" "")))]
1033   ""
1034   "
1035 {
1036   if (GET_CODE (operands[2]) == CONST_INT)
1037     {
1038       emit_insn (gen_addsi3 (operands[0], operands[1],
1039                              negate_rtx (SImode, operands[2])));
1040       DONE;
1041     }
1042 }")
1043
1044 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1045 ;; instruction and some auxiliary computations.  Then we just have a single
1046 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1047 ;; combine.
1048
1049 (define_expand "sminsi3"
1050   [(set (match_dup 3)
1051         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1052                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1053                          (const_int 0)
1054                          (minus:SI (match_dup 2) (match_dup 1))))
1055    (set (match_operand:SI 0 "gpc_reg_operand" "")
1056         (minus:SI (match_dup 2) (match_dup 3)))]
1057   "TARGET_POWER"
1058   "
1059 { operands[3] = gen_reg_rtx (SImode); }")
1060
1061 (define_split
1062   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1063         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1064                  (match_operand:SI 2 "reg_or_short_operand" "")))
1065    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1066   "TARGET_POWER"
1067   [(set (match_dup 3)
1068         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1069                          (const_int 0)
1070                          (minus:SI (match_dup 2) (match_dup 1))))
1071    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1072   "")
1073
1074 (define_expand "smaxsi3"
1075   [(set (match_dup 3)
1076         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1077                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1078                          (const_int 0)
1079                          (minus:SI (match_dup 2) (match_dup 1))))
1080    (set (match_operand:SI 0 "gpc_reg_operand" "")
1081         (plus:SI (match_dup 3) (match_dup 1)))]
1082   "TARGET_POWER"
1083   "
1084 { operands[3] = gen_reg_rtx (SImode); }")
1085
1086 (define_split
1087   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1088         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1089                  (match_operand:SI 2 "reg_or_short_operand" "")))
1090    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1091   "TARGET_POWER"
1092   [(set (match_dup 3)
1093         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1094                          (const_int 0)
1095                          (minus:SI (match_dup 2) (match_dup 1))))
1096    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1097   "")
1098
1099 (define_expand "uminsi3"
1100   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1101                               (match_dup 5)))
1102    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1103                               (match_dup 5)))
1104    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1105                                        (const_int 0)
1106                                        (minus:SI (match_dup 4) (match_dup 3))))
1107    (set (match_operand:SI 0 "gpc_reg_operand" "")
1108         (minus:SI (match_dup 2) (match_dup 3)))]
1109   "TARGET_POWER"
1110   "
1111 {
1112   operands[3] = gen_reg_rtx (SImode);
1113   operands[4] = gen_reg_rtx (SImode);
1114   operands[5] = GEN_INT (-2147483647 - 1);
1115 }")
1116
1117 (define_expand "umaxsi3"
1118   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1119                               (match_dup 5)))
1120    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1121                               (match_dup 5)))
1122    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1123                                        (const_int 0)
1124                                        (minus:SI (match_dup 4) (match_dup 3))))
1125    (set (match_operand:SI 0 "gpc_reg_operand" "")
1126         (plus:SI (match_dup 3) (match_dup 1)))]
1127   "TARGET_POWER"
1128   "
1129 {
1130   operands[3] = gen_reg_rtx (SImode);
1131   operands[4] = gen_reg_rtx (SImode);
1132   operands[5] = GEN_INT (-2147483647 - 1);
1133 }")
1134
1135 (define_insn ""
1136   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1137         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1138                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1139                          (const_int 0)
1140                          (minus:SI (match_dup 2) (match_dup 1))))]
1141   "TARGET_POWER"
1142   "doz%I2 %0,%1,%2")
1143
1144 (define_insn ""
1145   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1146         (compare:CC
1147          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1148                               (match_operand:SI 2 "reg_or_short_operand" "rI"))
1149                           (const_int 0)
1150                           (minus:SI (match_dup 2) (match_dup 1)))
1151          (const_int 0)))
1152    (clobber (match_scratch:SI 3 "=r"))]
1153   "TARGET_POWER"
1154   "doz%I2. %3,%1,%2"
1155   [(set_attr "type" "delayed_compare")])
1156
1157 (define_insn ""
1158   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1159         (compare:CC
1160          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1161                               (match_operand:SI 2 "reg_or_short_operand" "rI"))
1162                           (const_int 0)
1163                           (minus:SI (match_dup 2) (match_dup 1)))
1164          (const_int 0)))
1165    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1166         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1167                          (const_int 0)
1168                          (minus:SI (match_dup 2) (match_dup 1))))]
1169   "TARGET_POWER"
1170   "doz%I2. %0,%1,%2"
1171   [(set_attr "type" "delayed_compare")])
1172
1173 ;; We don't need abs with condition code because such comparisons should
1174 ;; never be done.
1175 (define_expand "abssi2"
1176   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1177         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1178   ""
1179   "
1180 {
1181   if (!TARGET_POWER)
1182     {
1183       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1184       DONE;
1185     }
1186 }")
1187
1188 (define_insn "abssi2_power"
1189   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1190         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1191   "TARGET_POWER"
1192   "abs %0,%1")
1193
1194 (define_insn "abssi2_nopower"
1195   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1196         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1197    (clobber (match_scratch:SI 2 "=&r,&r"))]
1198   "!TARGET_POWER"
1199   "*
1200 {
1201   return (TARGET_POWERPC)
1202     ? \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;subf %0,%2,%0\"
1203     : \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;{sf|subfc} %0,%2,%0\";
1204 }"
1205   [(set_attr "length" "12")])
1206
1207 (define_split
1208   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1209         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1210    (clobber (match_scratch:SI 2 "=&r,&r"))]
1211   "!TARGET_POWER && reload_completed"
1212   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1213    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1214    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1215   "")
1216
1217 (define_insn ""
1218   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1219         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1220   "TARGET_POWER"
1221   "nabs %0,%1")
1222
1223 (define_insn ""
1224   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1225         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1226    (clobber (match_scratch:SI 2 "=&r,&r"))]
1227   "!TARGET_POWER"
1228   "*
1229 {
1230   return (TARGET_POWERPC)
1231     ? \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;subf %0,%0,%2\"
1232     : \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;{sf|subfc} %0,%0,%2\";
1233 }"
1234   [(set_attr "length" "12")])
1235
1236 (define_split
1237   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1238         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1239    (clobber (match_scratch:SI 2 "=&r,&r"))]
1240   "!TARGET_POWER && reload_completed"
1241   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1242    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1243    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1244   "")
1245
1246 (define_insn "negsi2"
1247   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1248         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1249   ""
1250   "neg %0,%1")
1251
1252 (define_insn ""
1253   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1254         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1255                     (const_int 0)))
1256    (clobber (match_scratch:SI 2 "=r"))]
1257   ""
1258   "neg. %2,%1"
1259   [(set_attr "type" "compare")])
1260
1261 (define_insn ""
1262   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
1263         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1264                     (const_int 0)))
1265    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1266         (neg:SI (match_dup 1)))]
1267   ""
1268   "neg. %0,%1"
1269   [(set_attr "type" "compare")])
1270
1271 (define_insn "ffssi2"
1272   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
1273         (ffs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1274   ""
1275   "neg %0,%1\;and %0,%0,%1\;{cntlz|cntlzw} %0,%0\;{sfi|subfic} %0,%0,32"
1276   [(set_attr "length" "16")])
1277
1278 (define_expand "mulsi3"
1279   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1280    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1281    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1282   ""
1283   "
1284 {
1285   if (TARGET_POWER)
1286     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1287   else
1288     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1289   DONE;
1290 }")
1291
1292 (define_insn "mulsi3_mq"
1293   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1294         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1295                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1296    (clobber (match_scratch:SI 3 "=q,q"))]
1297   "TARGET_POWER"
1298   "@
1299    {muls|mullw} %0,%1,%2
1300    {muli|mulli} %0,%1,%2"
1301    [(set_attr "type" "imul")])
1302
1303 (define_insn "mulsi3_no_mq"
1304   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1305         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1306                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1307   "! TARGET_POWER"
1308   "@
1309    {muls|mullw} %0,%1,%2
1310    {muli|mulli} %0,%1,%2"
1311    [(set_attr "type" "imul")])
1312
1313 (define_insn ""
1314   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1315         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1316                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1317                     (const_int 0)))
1318    (clobber (match_scratch:SI 3 "=r"))
1319    (clobber (match_scratch:SI 4 "=q"))]
1320   "TARGET_POWER"
1321   "{muls.|mullw.} %3,%1,%2"
1322   [(set_attr "type" "delayed_compare")])
1323
1324 (define_insn ""
1325   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1326         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1327                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1328                     (const_int 0)))
1329    (clobber (match_scratch:SI 3 "=r"))]
1330   "! TARGET_POWER"
1331   "{muls.|mullw.} %3,%1,%2"
1332   [(set_attr "type" "delayed_compare")])
1333
1334 (define_insn ""
1335   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1336         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1337                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1338                     (const_int 0)))
1339    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1340         (mult:SI (match_dup 1) (match_dup 2)))
1341    (clobber (match_scratch:SI 4 "=q"))]
1342   "TARGET_POWER"
1343   "{muls.|mullw.} %0,%1,%2"
1344   [(set_attr "type" "delayed_compare")])
1345
1346 (define_insn ""
1347   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1348         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1349                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1350                     (const_int 0)))
1351    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1352         (mult:SI (match_dup 1) (match_dup 2)))]
1353   "! TARGET_POWER"
1354   "{muls.|mullw.} %0,%1,%2"
1355   [(set_attr "type" "delayed_compare")])
1356
1357 ;; Operand 1 is divided by operand 2; quotient goes to operand
1358 ;; 0 and remainder to operand 3.
1359 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1360
1361 (define_expand "divmodsi4"
1362   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1363                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1364                            (match_operand:SI 2 "gpc_reg_operand" "")))
1365               (set (match_operand:SI 3 "gpc_reg_operand" "")
1366                    (mod:SI (match_dup 1) (match_dup 2)))])]
1367   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1368   "
1369 {
1370   if (! TARGET_POWER && ! TARGET_POWERPC)
1371     {
1372       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1373       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1374       emit_insn (gen_divss_call ());
1375       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1376       emit_move_insn (operands[3], gen_rtx (REG, SImode, 4));
1377       DONE;
1378     }
1379 }")
1380
1381 (define_insn ""
1382   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1383         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1384                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1385    (set (match_operand:SI 3 "gpc_reg_operand" "=q")
1386         (mod:SI (match_dup 1) (match_dup 2)))]
1387   "TARGET_POWER"
1388   "divs %0,%1,%2"
1389   [(set_attr "type" "idiv")])
1390
1391 (define_insn ""
1392   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1393         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1394                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1395   "TARGET_POWERPC"
1396   "divw %0,%1,%2"
1397   [(set_attr "type" "idiv")])
1398
1399 (define_expand "udivsi3"
1400   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1401         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1402                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1403   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1404   "
1405 {
1406   if (! TARGET_POWER && ! TARGET_POWERPC)
1407     {
1408       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1409       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1410       emit_insn (gen_quous_call ());
1411       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1412       DONE;
1413     }
1414 }")
1415
1416 (define_insn ""
1417   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1418         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1419                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1420   "TARGET_POWERPC"
1421   "divwu %0,%1,%2"
1422   [(set_attr "type" "idiv")])
1423
1424 ;; For powers of two we can do srai/aze for divide and then adjust for
1425 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1426 ;; used; for PowerPC, force operands into register and do a normal divide;
1427 ;; for AIX common-mode, use quoss call on register operands.
1428 (define_expand "divsi3"
1429   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1430         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1431                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1432   ""
1433   "
1434 {
1435   if (GET_CODE (operands[2]) == CONST_INT
1436       && exact_log2 (INTVAL (operands[2])) >= 0)
1437     ;
1438   else if (TARGET_POWERPC)
1439     operands[2] = force_reg (SImode, operands[2]);
1440   else if (TARGET_POWER)
1441     FAIL;
1442   else
1443     {
1444       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1445       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1446       emit_insn (gen_quoss_call ());
1447       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1448       DONE;
1449     }
1450 }")
1451
1452 (define_expand "modsi3"
1453   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1454    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1455    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
1456   ""
1457   "
1458 {
1459   int i = exact_log2 (INTVAL (operands[2]));
1460   rtx temp1;
1461   rtx temp2;
1462
1463   if (GET_CODE (operands[2]) != CONST_INT || i < 0)
1464     FAIL;
1465
1466   temp1 = gen_reg_rtx (SImode);
1467   temp2 = gen_reg_rtx (SImode);
1468
1469   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
1470   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
1471   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
1472   DONE;
1473 }")
1474
1475 (define_insn ""
1476   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1477         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1478                 (match_operand:SI 2 "const_int_operand" "N")))]
1479   "exact_log2 (INTVAL (operands[2])) >= 0"
1480   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
1481   [(set_attr "length" "8")])
1482
1483 (define_insn ""
1484   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1485         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1486                             (match_operand:SI 2 "const_int_operand" "N"))
1487                     (const_int 0)))
1488    (clobber (match_scratch:SI 3 "=r"))]
1489   "exact_log2 (INTVAL (operands[2])) >= 0"
1490   "{srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3"
1491   [(set_attr "type" "compare")
1492    (set_attr "length" "8")])
1493
1494 (define_insn ""
1495   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1496         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1497                             (match_operand:SI 2 "const_int_operand" "N"))
1498                     (const_int 0)))
1499    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1500         (div:SI (match_dup 1) (match_dup 2)))]
1501   "exact_log2 (INTVAL (operands[2])) >= 0"
1502   "{srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0"
1503   [(set_attr "type" "compare")
1504    (set_attr "length" "8")])
1505
1506 (define_insn ""
1507   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1508         (udiv:SI
1509          (plus:DI (ashift:DI
1510                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
1511                    (const_int 32))
1512                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
1513          (match_operand:SI 3 "gpc_reg_operand" "r")))
1514    (set (match_operand:SI 2 "register_operand" "=*q")
1515         (umod:SI
1516          (plus:DI (ashift:DI
1517                    (zero_extend:DI (match_dup 1)) (const_int 32))
1518                   (zero_extend:DI (match_dup 4)))
1519          (match_dup 3)))]
1520   "TARGET_POWER"
1521   "div %0,%1,%3"
1522   [(set_attr "type" "idiv")])
1523
1524 ;; To do unsigned divide we handle the cases of the divisor looking like a
1525 ;; negative number.  If it is a constant that is less than 2**31, we don't
1526 ;; have to worry about the branches.  So make a few subroutines here.
1527 ;;
1528 ;; First comes the normal case.
1529 (define_expand "udivmodsi4_normal"
1530   [(set (match_dup 4) (const_int 0))
1531    (parallel [(set (match_operand:SI 0 "" "")
1532                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
1533                                                 (const_int 32))
1534                                      (zero_extend:DI (match_operand:SI 1 "" "")))
1535                             (match_operand:SI 2 "" "")))
1536               (set (match_operand:SI 3 "" "")
1537                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
1538                                                 (const_int 32))
1539                                      (zero_extend:DI (match_dup 1)))
1540                             (match_dup 2)))])]
1541   "TARGET_POWER"
1542   "
1543 { operands[4] = gen_reg_rtx (SImode); }")
1544
1545 ;; This handles the branches.
1546 (define_expand "udivmodsi4_tests"
1547   [(set (match_operand:SI 0 "" "") (const_int 0))
1548    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
1549    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
1550    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
1551                            (label_ref (match_operand:SI 4 "" "")) (pc)))
1552    (set (match_dup 0) (const_int 1))
1553    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
1554    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
1555    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
1556                            (label_ref (match_dup 4)) (pc)))]
1557   "TARGET_POWER"
1558   "
1559 { operands[5] = gen_reg_rtx (CCUNSmode);
1560   operands[6] = gen_reg_rtx (CCmode);
1561 }")
1562
1563 (define_expand "udivmodsi4"
1564   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1565                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1566                             (match_operand:SI 2 "reg_or_cint_operand" "")))
1567               (set (match_operand:SI 3 "gpc_reg_operand" "")
1568                    (umod:SI (match_dup 1) (match_dup 2)))])]
1569   ""
1570   "
1571 {
1572   rtx label = 0;
1573
1574   if (! TARGET_POWER)
1575     if (! TARGET_POWERPC)
1576       {
1577         emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1578         emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1579         emit_insn (gen_divus_call ());
1580         emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1581         emit_move_insn (operands[3], gen_rtx (REG, SImode, 4));
1582         DONE;
1583       }
1584     else
1585       FAIL;
1586
1587   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
1588     {
1589       operands[2] = force_reg (SImode, operands[2]);
1590       label = gen_label_rtx ();
1591       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
1592                                   operands[3], label));
1593     }
1594   else
1595     operands[2] = force_reg (SImode, operands[2]);
1596
1597   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
1598                                operands[3]));
1599   if (label)
1600     emit_label (label);
1601
1602   DONE;
1603 }")
1604
1605 ;; AIX architecture-independent common-mode multiply (DImode),
1606 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
1607 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
1608 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
1609 ;; assumed unused if generating common-mode, so ignore.
1610 (define_insn "mulh_call"
1611   [(set (reg:SI 3)
1612         (truncate:SI
1613          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
1614                                (sign_extend:DI (reg:SI 4)))
1615                       (const_int 32))))
1616    (clobber (match_scratch:SI 0 "=l"))]
1617   "! TARGET_POWER && ! TARGET_POWERPC"
1618   "bla __mulh"
1619   [(set_attr "type" "imul")])
1620
1621 (define_insn "mull_call"
1622   [(set (reg:DI 3)
1623         (mult:DI (sign_extend:DI (reg:SI 3))
1624                  (sign_extend:DI (reg:SI 4))))
1625    (clobber (match_scratch:SI 0 "=l"))
1626    (clobber (reg:SI 0))]
1627   "! TARGET_POWER && ! TARGET_POWERPC"
1628   "bla __mull"
1629   [(set_attr "type" "imul")])
1630
1631 (define_insn "divss_call"
1632   [(set (reg:SI 3)
1633         (div:SI (reg:SI 3) (reg:SI 4)))
1634    (set (reg:SI 4)
1635         (mod:SI (reg:SI 3) (reg:SI 4)))
1636    (clobber (match_scratch:SI 0 "=l"))
1637    (clobber (reg:SI 0))]
1638   "! TARGET_POWER && ! TARGET_POWERPC"
1639   "bla __divss"
1640   [(set_attr "type" "idiv")])
1641
1642 (define_insn "divus_call"
1643   [(set (reg:SI 3)
1644         (udiv:SI (reg:SI 3) (reg:SI 4)))
1645    (set (reg:SI 4)
1646         (umod:SI (reg:SI 3) (reg:SI 4)))
1647    (clobber (match_scratch:SI 0 "=l"))
1648    (clobber (reg:SI 0))
1649    (clobber (match_scratch:CC 1 "=x"))
1650    (clobber (reg:CC 69))]
1651   "! TARGET_POWER && ! TARGET_POWERPC"
1652   "bla __divus"
1653   [(set_attr "type" "idiv")])
1654
1655 (define_insn "quoss_call"
1656   [(set (reg:SI 3)
1657         (div:SI (reg:SI 3) (reg:SI 4)))
1658    (clobber (match_scratch:SI 0 "=l"))]
1659   "! TARGET_POWER && ! TARGET_POWERPC"
1660   "bla __quoss"
1661   [(set_attr "type" "idiv")])
1662
1663 (define_insn "quous_call"
1664   [(set (reg:SI 3)
1665         (udiv:SI (reg:SI 3) (reg:SI 4)))
1666    (clobber (match_scratch:SI 0 "=l"))
1667    (clobber (reg:SI 0))
1668    (clobber (match_scratch:CC 1 "=x"))
1669    (clobber (reg:CC 69))]
1670   "! TARGET_POWER && ! TARGET_POWERPC"
1671   "bla __quous"
1672   [(set_attr "type" "idiv")])
1673 \f
1674 ;; Logical instructions
1675 (define_insn "andsi3"
1676   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1677         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1678                 (match_operand:SI 2 "and_operand" "?r,L,K,J")))
1679    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
1680   ""
1681   "@
1682    and %0,%1,%2
1683    {rlinm|rlwinm} %0,%1,0,%m2,%M2
1684    {andil.|andi.} %0,%1,%b2
1685    {andiu.|andis.} %0,%1,%u2"
1686   [(set_attr "length" "4,4,4,4")])
1687
1688 (define_insn "*andsi3_internal2"
1689   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x")
1690         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1691                             (match_operand:SI 2 "and_operand" "r,K,J,L"))
1692                     (const_int 0)))
1693    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1694   ""
1695   "@
1696    and. %3,%1,%2
1697    {andil.|andi.} %3,%1,%b2
1698    {andiu.|andis.} %3,%1,%u2
1699    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2"
1700   [(set_attr "type" "compare,compare,compare,delayed_compare")])
1701
1702 (define_insn "*andsi3_internal3"
1703   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x")
1704         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1705                             (match_operand:SI 2 "and_operand" "r,K,J,L"))
1706                     (const_int 0)))
1707    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1708         (and:SI (match_dup 1) (match_dup 2)))]
1709   ""
1710   "@
1711    and. %0,%1,%2
1712    {andil.|andi.} %0,%1,%b2
1713    {andiu.|andis.} %0,%1,%u2
1714    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2"
1715   [(set_attr "type" "compare,compare,compare,delayed_compare")])
1716
1717 (define_expand "iorsi3"
1718   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1719         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
1720                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1721   ""
1722   "
1723 {
1724   if (GET_CODE (operands[2]) == CONST_INT
1725       && !logical_operand (operands[2], SImode))
1726     {
1727       HOST_WIDE_INT value = INTVAL (operands[2]);
1728       rtx tmp = ((reload_in_progress || reload_completed
1729                   || rtx_equal_p (operands[0], operands[1]))
1730                  ? operands[0] : gen_reg_rtx (SImode));
1731
1732       emit_insn (gen_iorsi3 (tmp, operands[1], GEN_INT (value & 0xffff0000)));
1733       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0x0000ffff)));
1734       DONE;
1735     }
1736 }")
1737
1738 (define_insn "*iorsi3_internal1"
1739   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
1740         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
1741                 (match_operand:SI 2 "logical_operand" "r,K,J")))]
1742   ""
1743   "@
1744    or %0,%1,%2
1745    {oril|ori} %0,%1,%b2
1746    {oriu|oris} %0,%1,%u2"
1747   [(set_attr "length" "4,4,4")])
1748
1749 (define_insn "*iorsi3_internal2"
1750   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1751         (compare:CC (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1752                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1753                     (const_int 0)))
1754    (clobber (match_scratch:SI 3 "=r"))]
1755   ""
1756   "or. %3,%1,%2"
1757   [(set_attr "type" "compare")])
1758
1759 (define_insn "*iorsi3_internal3"
1760   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1761         (compare:CC (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1762                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1763                     (const_int 0)))
1764    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1765         (ior:SI (match_dup 1) (match_dup 2)))]
1766   ""
1767   "or. %0,%1,%2"
1768   [(set_attr "type" "compare")])
1769
1770 (define_expand "xorsi3"
1771   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1772         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1773                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1774   ""
1775   "
1776 {
1777   if (GET_CODE (operands[2]) == CONST_INT
1778       && !logical_operand (operands[2], SImode))
1779     {
1780       HOST_WIDE_INT value = INTVAL (operands[2]);
1781       rtx tmp = ((reload_in_progress || reload_completed
1782                   || rtx_equal_p (operands[0], operands[1]))
1783                  ? operands[0] : gen_reg_rtx (SImode));
1784
1785       emit_insn (gen_xorsi3 (tmp, operands[1], GEN_INT (value & 0xffff0000)));
1786       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0x0000ffff)));
1787       DONE;
1788     }
1789 }")
1790
1791 (define_insn "*xorsi3_internal1"
1792   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
1793         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
1794                 (match_operand:SI 2 "logical_operand" "r,K,J")))]
1795   ""
1796   "@
1797    xor %0,%1,%2
1798    {xoril|xori} %0,%1,%b2
1799    {xoriu|xoris} %0,%1,%u2"
1800   [(set_attr "length" "4,4,4")])
1801
1802 (define_insn "*xorsi3_internal2"
1803   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1804         (compare:CC (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1805                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1806                     (const_int 0)))
1807    (clobber (match_scratch:SI 3 "=r"))]
1808   ""
1809   "xor. %3,%1,%2"
1810   [(set_attr "type" "compare")])
1811
1812 (define_insn "*xorsi3_internal3"
1813   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1814         (compare:CC (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1815                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1816                     (const_int 0)))
1817    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1818         (xor:SI (match_dup 1) (match_dup 2)))]
1819   ""
1820   "xor. %0,%1,%2"
1821   [(set_attr "type" "compare")])
1822
1823 (define_insn "*eqv_internal1"
1824   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1825         (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1826                         (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1827    ""
1828    "eqv %0,%1,%2")
1829
1830 (define_insn "*eqv_internal2"
1831   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1832         (compare:CC (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1833                                     (match_operand:SI 2 "gpc_reg_operand" "r")))
1834                     (const_int 0)))
1835    (clobber (match_scratch:SI 3 "=r"))]
1836    ""
1837    "eqv. %3,%1,%2"
1838    [(set_attr "type" "compare")])
1839
1840 (define_insn "*eqv_internal3"
1841   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1842         (compare:CC (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1843                                     (match_operand:SI 2 "gpc_reg_operand" "r")))
1844                     (const_int 0)))
1845    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1846         (not:SI (xor:SI (match_dup 1) (match_dup 2))))]
1847    ""
1848    "eqv. %0,%1,%2"
1849    [(set_attr "type" "compare")])
1850
1851 (define_insn "*andc_internal1"
1852   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1853         (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1854                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1855   ""
1856   "andc %0,%2,%1")
1857
1858 (define_insn "*andc_internal2"
1859   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1860         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1861                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1862                     (const_int 0)))
1863    (clobber (match_scratch:SI 3 "=r"))]
1864   ""
1865   "andc. %3,%2,%1"
1866   [(set_attr "type" "compare")])
1867
1868 (define_insn "*andc_internal3"
1869   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1870         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1871                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1872                     (const_int 0)))
1873    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1874         (and:SI (not:SI (match_dup 1)) (match_dup 2)))]
1875   ""
1876   "andc. %0,%2,%1"
1877   [(set_attr "type" "compare")])
1878
1879 (define_insn "*iorc_internal1"
1880   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1881         (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1882                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1883   ""
1884   "orc %0,%2,%1")
1885
1886 (define_insn "*iorc_internal2"
1887   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1888         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1889                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1890                     (const_int 0)))
1891    (clobber (match_scratch:SI 3 "=r"))]
1892   ""
1893   "orc. %3,%2,%1"
1894   [(set_attr "type" "compare")])
1895
1896 (define_insn "*iorc_internal3"
1897   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1898         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1899                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1900                     (const_int 0)))
1901    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1902         (ior:SI (not:SI (match_dup 1)) (match_dup 2)))]
1903   ""
1904   "orc. %0,%2,%1"
1905   [(set_attr "type" "compare")])
1906
1907 (define_insn "*nand_internal1"
1908   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1909         (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1910                 (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1911   ""
1912   "nand %0,%1,%2")
1913
1914 (define_insn "*nand_internal2"
1915   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1916         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1917                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1918                     (const_int 0)))
1919    (clobber (match_scratch:SI 3 "=r"))]
1920   ""
1921   "nand. %3,%1,%2"
1922   [(set_attr "type" "compare")])
1923
1924 (define_insn "*nand_internal3"
1925   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1926         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1927                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1928                     (const_int 0)))
1929    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1930         (ior:SI (not:SI (match_dup 1)) (not:SI (match_dup 2))))]
1931   ""
1932   "nand. %0,%1,%2"
1933   [(set_attr "type" "compare")])
1934
1935 (define_insn "*nor_internal1"
1936   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1937         (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1938                 (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1939   ""
1940   "nor %0,%1,%2")
1941
1942 (define_insn "*nor_internal2"
1943   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1944         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1945                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1946                     (const_int 0)))
1947    (clobber (match_scratch:SI 3 "=r"))]
1948   ""
1949   "nor. %3,%1,%2"
1950   [(set_attr "type" "compare")])
1951
1952 (define_insn "*nor_internal3"
1953   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1954         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1955                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1956                     (const_int 0)))
1957    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1958         (and:SI (not:SI (match_dup 1)) (not:SI (match_dup 2))))]
1959   ""
1960   "nor. %0,%1,%2"
1961   [(set_attr "type" "compare")])
1962
1963 ;; maskir insn.  We need four forms because things might be in arbitrary
1964 ;; orders.  Don't define forms that only set CR fields because these
1965 ;; would modify an input register.
1966
1967 (define_insn "*maskir_internal1"
1968   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1969         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1970                         (match_operand:SI 1 "gpc_reg_operand" "0"))
1971                 (and:SI (match_dup 2)
1972                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
1973   "TARGET_POWER"
1974   "maskir %0,%3,%2")
1975
1976 (define_insn "*maskir_internal2"
1977   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1978         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1979                         (match_operand:SI 1 "gpc_reg_operand" "0"))
1980                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1981                         (match_dup 2))))]
1982   "TARGET_POWER"
1983   "maskir %0,%3,%2")
1984
1985 (define_insn "*maskir_internal3"
1986   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1987         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
1988                         (match_operand:SI 3 "gpc_reg_operand" "r"))
1989                 (and:SI (not:SI (match_dup 2))
1990                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
1991   "TARGET_POWER"
1992   "maskir %0,%3,%2")
1993
1994 (define_insn "*maskir_internal4"
1995   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1996         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1997                         (match_operand:SI 2 "gpc_reg_operand" "r"))
1998                 (and:SI (not:SI (match_dup 2))
1999                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2000   "TARGET_POWER"
2001   "maskir %0,%3,%2")
2002
2003 (define_insn "*maskir_internal5"
2004   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2005         (compare:CC
2006          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2007                          (match_operand:SI 1 "gpc_reg_operand" "0"))
2008                  (and:SI (match_dup 2)
2009                          (match_operand:SI 3 "gpc_reg_operand" "r")))
2010          (const_int 0)))
2011    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2012         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2013                 (and:SI (match_dup 2) (match_dup 3))))]
2014   "TARGET_POWER"
2015   "maskir. %0,%3,%2"
2016   [(set_attr "type" "compare")])
2017
2018 (define_insn "*maskir_internal6"
2019   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2020         (compare:CC
2021          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2022                          (match_operand:SI 1 "gpc_reg_operand" "0"))
2023                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2024                          (match_dup 2)))
2025          (const_int 0)))
2026    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2027         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2028                 (and:SI (match_dup 3) (match_dup 2))))]
2029   "TARGET_POWER"
2030   "maskir. %0,%3,%2"
2031   [(set_attr "type" "compare")])
2032
2033 (define_insn "*maskir_internal7"
2034   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2035         (compare:CC
2036          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2037                          (match_operand:SI 3 "gpc_reg_operand" "r"))
2038                  (and:SI (not:SI (match_dup 2))
2039                          (match_operand:SI 1 "gpc_reg_operand" "0")))
2040          (const_int 0)))
2041    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2042         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2043                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2044   "TARGET_POWER"
2045   "maskir. %0,%3,%2"
2046   [(set_attr "type" "compare")])
2047
2048 (define_insn "*maskir_internal8"
2049   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2050         (compare:CC
2051          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2052                          (match_operand:SI 2 "gpc_reg_operand" "r"))
2053                  (and:SI (not:SI (match_dup 2))
2054                          (match_operand:SI 1 "gpc_reg_operand" "0")))
2055          (const_int 0)))
2056    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2057         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2058                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2059   "TARGET_POWER"
2060   "maskir. %0,%3,%2"
2061   [(set_attr "type" "compare")])
2062 \f
2063 ;; Rotate and shift insns, in all their variants.  These support shifts,
2064 ;; field inserts and extracts, and various combinations thereof.
2065 (define_expand "insv"
2066   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2067                          (match_operand:SI 1 "const_int_operand" "i")
2068                          (match_operand:SI 2 "const_int_operand" "i"))
2069         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2070   ""
2071   "
2072 {
2073   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2074      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2075      compiler if the address of the structure is taken later.  */
2076   if (GET_CODE (operands[0]) == SUBREG
2077       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2078     FAIL;
2079 }")
2080
2081 (define_insn ""
2082   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2083                          (match_operand:SI 1 "const_int_operand" "i")
2084                          (match_operand:SI 2 "const_int_operand" "i"))
2085         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2086   ""
2087   "*
2088 {
2089   int start = INTVAL (operands[2]) & 31;
2090   int size = INTVAL (operands[1]) & 31;
2091
2092   operands[4] = gen_rtx (CONST_INT, VOIDmode, 32 - start - size);
2093   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2094   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2095 }")
2096
2097 (define_insn ""
2098   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2099                          (match_operand:SI 1 "const_int_operand" "i")
2100                          (match_operand:SI 2 "const_int_operand" "i"))
2101         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2102                    (match_operand:SI 4 "const_int_operand" "i")))]
2103   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2104   "*
2105 {
2106   int shift = INTVAL (operands[4]) & 31;
2107   int start = INTVAL (operands[2]) & 31;
2108   int size = INTVAL (operands[1]) & 31;
2109
2110   operands[4] = gen_rtx (CONST_INT, VOIDmode, shift - start - size);
2111   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2112   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2113 }")
2114
2115 (define_insn ""
2116   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2117                          (match_operand:SI 1 "const_int_operand" "i")
2118                          (match_operand:SI 2 "const_int_operand" "i"))
2119         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2120                      (match_operand:SI 4 "const_int_operand" "i")))]
2121   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2122   "*
2123 {
2124   int shift = INTVAL (operands[4]) & 31;
2125   int start = INTVAL (operands[2]) & 31;
2126   int size = INTVAL (operands[1]) & 31;
2127
2128   operands[4] = gen_rtx (CONST_INT, VOIDmode, 32 - shift - start - size);
2129   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2130   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2131 }")
2132
2133 (define_insn ""
2134   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2135                          (match_operand:SI 1 "const_int_operand" "i")
2136                          (match_operand:SI 2 "const_int_operand" "i"))
2137         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2138                      (match_operand:SI 4 "const_int_operand" "i")))]
2139   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2140   "*
2141 {
2142   int shift = INTVAL (operands[4]) & 31;
2143   int start = INTVAL (operands[2]) & 31;
2144   int size = INTVAL (operands[1]) & 31;
2145
2146   operands[4] = gen_rtx (CONST_INT, VOIDmode, 32 - shift - start - size);
2147   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2148   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2149 }")
2150
2151 (define_insn ""
2152   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2153                          (match_operand:SI 1 "const_int_operand" "i")
2154                          (match_operand:SI 2 "const_int_operand" "i"))
2155         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2156                          (match_operand:SI 4 "const_int_operand" "i")
2157                          (match_operand:SI 5 "const_int_operand" "i")))]
2158   "INTVAL (operands[4]) >= INTVAL (operands[1])"
2159   "*
2160 {
2161   int extract_start = INTVAL (operands[5]) & 31;
2162   int extract_size = INTVAL (operands[4]) & 31;
2163   int insert_start = INTVAL (operands[2]) & 31;
2164   int insert_size = INTVAL (operands[1]) & 31;
2165
2166 /* Align extract field with insert field */
2167   operands[5] = gen_rtx (CONST_INT, VOIDmode,
2168                          extract_start + extract_size - insert_start - insert_size);
2169   operands[1] = gen_rtx (CONST_INT, VOIDmode, insert_start + insert_size - 1);
2170   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
2171 }")
2172
2173 (define_insn ""
2174   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
2175                          (match_operand:DI 1 "const_int_operand" "i")
2176                          (match_operand:DI 2 "const_int_operand" "i"))
2177         (match_operand:DI 3 "gpc_reg_operand" "r"))]
2178   "TARGET_POWERPC64"
2179   "*
2180 {
2181   int start = INTVAL (operands[2]) & 63;
2182   int size = INTVAL (operands[1]) & 63;
2183
2184   operands[2] = gen_rtx (CONST_INT, VOIDmode, 64 - start - size);
2185   return \"rldimi %0,%3,%H2,%H1\";
2186 }")
2187
2188 (define_expand "extzv"
2189   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2190         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2191                          (match_operand:SI 2 "const_int_operand" "i")
2192                          (match_operand:SI 3 "const_int_operand" "i")))]
2193   ""
2194   "
2195 {
2196   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2197      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2198      compiler if the address of the structure is taken later.  */
2199   if (GET_CODE (operands[0]) == SUBREG
2200       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2201     FAIL;
2202 }")
2203
2204 (define_insn ""
2205   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2206         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2207                          (match_operand:SI 2 "const_int_operand" "i")
2208                          (match_operand:SI 3 "const_int_operand" "i")))]
2209   ""
2210   "*
2211 {
2212   int start = INTVAL (operands[3]) & 31;
2213   int size = INTVAL (operands[2]) & 31;
2214
2215   if (start + size >= 32)
2216     operands[3] = const0_rtx;
2217   else
2218     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2219   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
2220 }")
2221
2222 (define_insn ""
2223   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2224         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2225                          (match_operand:SI 2 "const_int_operand" "i")
2226                          (match_operand:SI 3 "const_int_operand" "i"))
2227                     (const_int 0)))
2228    (clobber (match_scratch:SI 4 "=r"))]
2229   ""
2230   "*
2231 {
2232   int start = INTVAL (operands[3]) & 31;
2233   int size = INTVAL (operands[2]) & 31;
2234
2235   /* If the bitfield being tested fits in the upper or lower half of a
2236      word, it is possible to use andiu. or andil. to test it.  This is
2237      useful because the condition register set-use delay is smaller for
2238      andi[ul]. than for rlinm.  This doesn't work when the starting bit
2239      position is 0 because the LT and GT bits may be set wrong.  */
2240
2241   if ((start > 0 && start + size <= 16) || start >= 16)
2242     {
2243       operands[3] = gen_rtx (CONST_INT, VOIDmode,
2244                              ((1 << (16 - (start & 15)))
2245                               - (1 << (16 - (start & 15) - size))));
2246       if (start < 16)
2247         return \"{andiu.|andis.} %4,%1,%3\";
2248       else
2249         return \"{andil.|andi.} %4,%1,%3\";
2250     }
2251
2252   if (start + size >= 32)
2253     operands[3] = const0_rtx;
2254   else
2255     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2256   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
2257 }"
2258   [(set_attr "type" "compare")])
2259
2260 (define_insn ""
2261   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2262         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2263                          (match_operand:SI 2 "const_int_operand" "i")
2264                          (match_operand:SI 3 "const_int_operand" "i"))
2265                     (const_int 0)))
2266    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2267         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
2268   ""
2269   "*
2270 {
2271   int start = INTVAL (operands[3]) & 31;
2272   int size = INTVAL (operands[2]) & 31;
2273
2274   if (start >= 16 && start + size == 32)
2275     {
2276       operands[3] = gen_rtx (CONST_INT, VOIDmode, (1 << (32 - start)) - 1);
2277       return \"{andil.|andi.} %0,%1,%3\";
2278     }
2279
2280   if (start + size >= 32)
2281     operands[3] = const0_rtx;
2282   else
2283     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2284   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
2285 }"
2286   [(set_attr "type" "delayed_compare")])
2287
2288 (define_insn ""
2289   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2290         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
2291                          (match_operand:DI 2 "const_int_operand" "i")
2292                          (match_operand:DI 3 "const_int_operand" "i")))]
2293   "TARGET_POWERPC64"
2294   "*
2295 {
2296   int start = INTVAL (operands[3]) & 63;
2297   int size = INTVAL (operands[2]) & 63;
2298
2299   if (start + size >= 64)
2300     operands[3] = const0_rtx;
2301   else
2302     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2303   operands[2] = gen_rtx (CONST_INT, VOIDmode, 64 - size);
2304   return \"rldicl %0,%1,%3,%2\";
2305 }")
2306
2307 (define_insn ""
2308   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
2309         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
2310                          (match_operand:DI 2 "const_int_operand" "i")
2311                          (match_operand:DI 3 "const_int_operand" "i"))
2312                     (const_int 0)))
2313    (clobber (match_scratch:DI 4 "=r"))]
2314   "TARGET_POWERPC64"
2315   "*
2316 {
2317   int start = INTVAL (operands[3]) & 63;
2318   int size = INTVAL (operands[2]) & 63;
2319
2320   if (start + size >= 64)
2321     operands[3] = const0_rtx;
2322   else
2323     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2324   operands[2] = gen_rtx (CONST_INT, VOIDmode, 64 - size);
2325   return \"rldicl. %4,%1,%3,%2\";
2326 }")
2327
2328 (define_insn ""
2329   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
2330         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
2331                          (match_operand:DI 2 "const_int_operand" "i")
2332                          (match_operand:DI 3 "const_int_operand" "i"))
2333                     (const_int 0)))
2334    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
2335         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
2336   "TARGET_POWERPC64"
2337   "*
2338 {
2339   int start = INTVAL (operands[3]) & 63;
2340   int size = INTVAL (operands[2]) & 63;
2341
2342   if (start + size >= 64)
2343     operands[3] = const0_rtx;
2344   else
2345     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2346   operands[2] = gen_rtx (CONST_INT, VOIDmode, 64 - size);
2347   return \"rldicl. %0,%1,%3,%2\";
2348 }")
2349
2350 (define_insn "rotlsi3"
2351   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2352         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2353                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2354   ""
2355   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
2356
2357 (define_insn ""
2358   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2359         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2360                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2361                     (const_int 0)))
2362    (clobber (match_scratch:SI 3 "=r"))]
2363   ""
2364   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff"
2365   [(set_attr "type" "delayed_compare")])
2366
2367 (define_insn ""
2368   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2369         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2370                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2371                     (const_int 0)))
2372    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2373         (rotate:SI (match_dup 1) (match_dup 2)))]
2374   ""
2375   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff"
2376   [(set_attr "type" "delayed_compare")])
2377
2378 (define_insn ""
2379   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2380         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2381                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2382                 (match_operand:SI 3 "mask_operand" "L")))]
2383   ""
2384   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
2385
2386 (define_insn ""
2387   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2388         (compare:CC (and:SI
2389                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2390                                 (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2391                      (match_operand:SI 3 "mask_operand" "L"))
2392                     (const_int 0)))
2393    (clobber (match_scratch:SI 4 "=r"))]
2394   ""
2395   "{rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3"
2396   [(set_attr "type" "delayed_compare")])
2397
2398 (define_insn ""
2399   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2400         (compare:CC (and:SI
2401                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2402                                 (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2403                      (match_operand:SI 3 "mask_operand" "L"))
2404                     (const_int 0)))
2405    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2406         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2407   ""
2408   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3"
2409   [(set_attr "type" "delayed_compare")])
2410
2411 (define_insn ""
2412   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2413         (zero_extend:SI
2414          (subreg:QI
2415           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2416                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
2417   ""
2418   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
2419
2420 (define_insn ""
2421   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2422         (compare:CC (zero_extend:SI
2423                      (subreg:QI
2424                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2425                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2426                     (const_int 0)))
2427    (clobber (match_scratch:SI 3 "=r"))]
2428   ""
2429   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff"
2430   [(set_attr "type" "delayed_compare")])
2431
2432 (define_insn ""
2433   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2434         (compare:CC (zero_extend:SI
2435                      (subreg:QI
2436                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2437                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2438                     (const_int 0)))
2439    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2440         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
2441   ""
2442   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff"
2443   [(set_attr "type" "delayed_compare")])
2444
2445 (define_insn ""
2446   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2447         (zero_extend:SI
2448          (subreg:HI
2449           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2450                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
2451   ""
2452   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
2453
2454 (define_insn ""
2455   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2456         (compare:CC (zero_extend:SI
2457                      (subreg:HI
2458                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2459                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2460                     (const_int 0)))
2461    (clobber (match_scratch:SI 3 "=r"))]
2462   ""
2463   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff"
2464   [(set_attr "type" "delayed_compare")])
2465
2466 (define_insn ""
2467   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2468         (compare:CC (zero_extend:SI
2469                      (subreg:HI
2470                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2471                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2472                     (const_int 0)))
2473    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2474         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
2475   ""
2476   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff"
2477   [(set_attr "type" "delayed_compare")])
2478
2479 ;; Note that we use "sle." instead of "sl." so that we can set
2480 ;; SHIFT_COUNT_TRUNCATED.
2481
2482 (define_expand "ashlsi3"
2483   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2484    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2485    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2486   ""
2487   "
2488 {
2489   if (TARGET_POWER)
2490     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
2491   else
2492     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
2493   DONE;
2494 }")
2495
2496 (define_insn "ashlsi3_power"
2497   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2498         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2499                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2500    (clobber (match_scratch:SI 3 "=q,X"))]
2501   "TARGET_POWER"
2502   "@
2503    sle %0,%1,%2
2504    {sli|slwi} %0,%1,%h2"
2505   [(set_attr "length" "8")])
2506
2507 (define_insn "ashlsi3_no_power"
2508   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2509         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2510                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2511   "! TARGET_POWER"
2512   "{sl|slw}%I2 %0,%1,%h2"
2513   [(set_attr "length" "8")])
2514
2515 (define_insn ""
2516   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2517         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2518                                (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2519                     (const_int 0)))
2520    (clobber (match_scratch:SI 3 "=r,r"))
2521    (clobber (match_scratch:SI 4 "=q,X"))]
2522   "TARGET_POWER"
2523   "@
2524    sle. %3,%1,%2
2525    {sli.|slwi.} %3,%1,%h2"
2526   [(set_attr "type" "delayed_compare")])
2527
2528 (define_insn ""
2529   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2530         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2531                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2532                     (const_int 0)))
2533    (clobber (match_scratch:SI 3 "=r"))]
2534   "! TARGET_POWER"
2535   "{sl|slw}%I2. %3,%1,%h2"
2536   [(set_attr "type" "delayed_compare")])
2537
2538 (define_insn ""
2539   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2540         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2541                                (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2542                     (const_int 0)))
2543    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2544         (ashift:SI (match_dup 1) (match_dup 2)))
2545    (clobber (match_scratch:SI 4 "=q,X"))]
2546   "TARGET_POWER"
2547   "@
2548    sle. %0,%1,%2
2549    {sli.|slwi.} %0,%1,%h2"
2550   [(set_attr "type" "delayed_compare")])
2551
2552 (define_insn ""
2553   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2554         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2555                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2556                     (const_int 0)))
2557    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2558         (ashift:SI (match_dup 1) (match_dup 2)))]
2559   "! TARGET_POWER"
2560   "{sl|slw}%I2. %0,%1,%h2"
2561   [(set_attr "type" "delayed_compare")])
2562
2563 (define_insn ""
2564   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2565         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2566                            (match_operand:SI 2 "const_int_operand" "i"))
2567                 (match_operand:SI 3 "mask_operand" "L")))]
2568   "includes_lshift_p (operands[2], operands[3])"
2569   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
2570
2571 (define_insn ""
2572   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2573         (compare:CC
2574          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2575                             (match_operand:SI 2 "const_int_operand" "i"))
2576                  (match_operand:SI 3 "mask_operand" "L"))
2577          (const_int 0)))
2578    (clobber (match_scratch:SI 4 "=r"))]
2579   "includes_lshift_p (operands[2], operands[3])"
2580   "{rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3"
2581   [(set_attr "type" "delayed_compare")])
2582
2583 (define_insn ""
2584   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2585         (compare:CC
2586          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2587                             (match_operand:SI 2 "const_int_operand" "i"))
2588                  (match_operand:SI 3 "mask_operand" "L"))
2589          (const_int 0)))
2590    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2591         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2592   "includes_lshift_p (operands[2], operands[3])"
2593   "{rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3"
2594   [(set_attr "type" "delayed_compare")])
2595
2596 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
2597 ;; "sli x,x,0".
2598 (define_expand "lshrsi3"
2599   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2600    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2601    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2602   ""
2603   "
2604 {
2605   if (TARGET_POWER)
2606     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
2607   else
2608     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
2609   DONE;
2610 }")
2611
2612 (define_insn "lshrsi3_power"
2613   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2614         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
2615                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
2616    (clobber (match_scratch:SI 3 "=q,X,X"))]
2617   "TARGET_POWER"
2618   "@
2619   sre %0,%1,%2
2620   mr %0,%1
2621   {s%A2i|s%A2wi} %0,%1,%h2")
2622
2623 (define_insn "lshrsi3_no_power"
2624   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2625         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2626                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
2627   "! TARGET_POWER"
2628   "@
2629   mr %0,%1
2630   {sr|srw}%I2 %0,%1,%h2")
2631
2632 (define_insn ""
2633   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x")
2634         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
2635                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i"))
2636                     (const_int 0)))
2637    (clobber (match_scratch:SI 3 "=r,X,r"))
2638    (clobber (match_scratch:SI 4 "=q,X,X"))]
2639   "TARGET_POWER"
2640   "@
2641   sre. %3,%1,%2
2642   mr. %1,%1
2643   {s%A2i.|s%A2wi.} %3,%1,%h2"
2644   [(set_attr "type" "delayed_compare")])
2645
2646 (define_insn ""
2647   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2648         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2649                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri"))
2650                     (const_int 0)))
2651    (clobber (match_scratch:SI 3 "=X,r"))]
2652   "! TARGET_POWER"
2653   "@
2654    mr. %1,%1
2655    {sr|srw}%I2. %3,%1,%h2"
2656   [(set_attr "type" "delayed_compare")])
2657
2658 (define_insn ""
2659   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x")
2660         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
2661                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i"))
2662                     (const_int 0)))
2663    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2664         (lshiftrt:SI (match_dup 1) (match_dup 2)))
2665    (clobber (match_scratch:SI 4 "=q,X,X"))]
2666   "TARGET_POWER"
2667   "@
2668   sre. %0,%1,%2
2669   mr. %0,%1
2670   {s%A2i.|s%A2wi.} %0,%1,%h2"
2671   [(set_attr "type" "delayed_compare")])
2672
2673 (define_insn ""
2674   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2675         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2676                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri"))
2677                     (const_int 0)))
2678    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2679         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
2680   "! TARGET_POWER"
2681   "@
2682    mr. %0,%1
2683    {sr|srw}%I2. %0,%1,%h2"
2684   [(set_attr "type" "delayed_compare")])
2685
2686 (define_insn ""
2687   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2688         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2689                              (match_operand:SI 2 "const_int_operand" "i"))
2690                 (match_operand:SI 3 "mask_operand" "L")))]
2691   "includes_rshift_p (operands[2], operands[3])"
2692   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
2693
2694 (define_insn ""
2695   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2696         (compare:CC
2697          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2698                               (match_operand:SI 2 "const_int_operand" "i"))
2699                  (match_operand:SI 3 "mask_operand" "L"))
2700          (const_int 0)))
2701    (clobber (match_scratch:SI 4 "=r"))]
2702   "includes_rshift_p (operands[2], operands[3])"
2703   "{rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3"
2704   [(set_attr "type" "delayed_compare")])
2705
2706 (define_insn ""
2707   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2708         (compare:CC
2709          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2710                               (match_operand:SI 2 "const_int_operand" "i"))
2711                  (match_operand:SI 3 "mask_operand" "L"))
2712          (const_int 0)))
2713    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2714         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2715   "includes_rshift_p (operands[2], operands[3])"
2716   "{rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3"
2717   [(set_attr "type" "delayed_compare")])
2718
2719 (define_insn ""
2720   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2721         (zero_extend:SI
2722          (subreg:QI
2723           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2724                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
2725   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2726   "{rlinm|rlwinm} %0,%1,%s2,0xff")
2727
2728 (define_insn ""
2729   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2730         (compare:CC
2731          (zero_extend:SI
2732           (subreg:QI
2733            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2734                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2735          (const_int 0)))
2736    (clobber (match_scratch:SI 3 "=r"))]
2737   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2738   "{rlinm.|rlwinm.} %3,%1,%s2,0xff"
2739   [(set_attr "type" "delayed_compare")])
2740
2741 (define_insn ""
2742   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2743         (compare:CC
2744          (zero_extend:SI
2745           (subreg:QI
2746            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2747                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2748          (const_int 0)))
2749    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2750         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
2751   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2752   "{rlinm.|rlwinm.} %0,%1,%s2,0xff"
2753   [(set_attr "type" "delayed_compare")])
2754
2755 (define_insn ""
2756   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2757         (zero_extend:SI
2758          (subreg:HI
2759           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2760                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
2761   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2762   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
2763
2764 (define_insn ""
2765   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2766         (compare:CC
2767          (zero_extend:SI
2768           (subreg:HI
2769            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2770                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2771          (const_int 0)))
2772    (clobber (match_scratch:SI 3 "=r"))]
2773   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2774   "{rlinm.|rlwinm.} %3,%1,%s2,0xffff"
2775   [(set_attr "type" "delayed_compare")])
2776
2777 (define_insn ""
2778   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2779         (compare:CC
2780          (zero_extend:SI
2781           (subreg:HI
2782            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2783                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2784          (const_int 0)))
2785    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2786         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
2787   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2788   "{rlinm.|rlwinm.} %0,%1,%s2,0xffff"
2789   [(set_attr "type" "delayed_compare")])
2790
2791 (define_insn ""
2792   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2793                          (const_int 1)
2794                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2795         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2796                      (const_int 31)))]
2797   "TARGET_POWER"
2798   "rrib %0,%1,%2")
2799
2800 (define_insn ""
2801   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2802                          (const_int 1)
2803                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2804         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2805                      (const_int 31)))]
2806   "TARGET_POWER"
2807   "rrib %0,%1,%2")
2808
2809 (define_insn ""
2810   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2811                          (const_int 1)
2812                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2813         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2814                          (const_int 1)
2815                          (const_int 0)))]
2816   "TARGET_POWER"
2817   "rrib %0,%1,%2")
2818
2819 (define_expand "ashrsi3"
2820   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2821         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
2822                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
2823   ""
2824   "
2825 {
2826   if (TARGET_POWER)
2827     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
2828   else
2829     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
2830   DONE;
2831 }")
2832
2833 (define_insn "ashrsi3_power"
2834   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2835         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2836                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2837    (clobber (match_scratch:SI 3 "=q,X"))]
2838   "TARGET_POWER"
2839   "@
2840    srea %0,%1,%2
2841    {srai|srawi} %0,%1,%h2")
2842
2843 (define_insn "ashrsi3_no_power"
2844   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2845         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2846                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2847   "! TARGET_POWER"
2848   "{sra|sraw}%I2 %0,%1,%h2")
2849
2850 (define_insn ""
2851   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2852         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2853                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2854                     (const_int 0)))
2855    (clobber (match_scratch:SI 3 "=r,r"))
2856    (clobber (match_scratch:SI 4 "=q,X"))]
2857   "TARGET_POWER"
2858   "@
2859    srea. %3,%1,%2
2860    {srai.|srawi.} %3,%1,%h2"
2861   [(set_attr "type" "delayed_compare")])
2862
2863 (define_insn ""
2864   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2865         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2866                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2867                     (const_int 0)))
2868    (clobber (match_scratch:SI 3 "=r"))]
2869   "! TARGET_POWER"
2870   "{sra|sraw}%I2. %3,%1,%h2"
2871   [(set_attr "type" "delayed_compare")])
2872
2873 (define_insn ""
2874   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2875         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2876                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2877                     (const_int 0)))
2878    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2879         (ashiftrt:SI (match_dup 1) (match_dup 2)))
2880    (clobber (match_scratch:SI 4 "=q,X"))]
2881   "TARGET_POWER"
2882   "@
2883    srea. %0,%1,%2
2884    {srai.|srawi.} %0,%1,%h2"
2885   [(set_attr "type" "delayed_compare")])
2886
2887 (define_insn ""
2888   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2889         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2890                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2891                     (const_int 0)))
2892    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2893         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
2894   "! TARGET_POWER"
2895   "{sra|sraw}%I2. %0,%1,%h2"
2896   [(set_attr "type" "delayed_compare")])
2897 \f
2898 ;; Floating-point insns, excluding normal data motion.
2899 ;;
2900 ;; PowerPC has a full set of single-precision floating point instructions.
2901 ;;
2902 ;; For the POWER architecture, we pretend that we have both SFmode and
2903 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
2904 ;; The only conversions we will do will be when storing to memory.  In that
2905 ;; case, we will use the "frsp" instruction before storing.
2906 ;;
2907 ;; Note that when we store into a single-precision memory location, we need to
2908 ;; use the frsp insn first.  If the register being stored isn't dead, we
2909 ;; need a scratch register for the frsp.  But this is difficult when the store
2910 ;; is done by reload.  It is not incorrect to do the frsp on the register in
2911 ;; this case, we just lose precision that we would have otherwise gotten but
2912 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
2913
2914 (define_insn "extendsfdf2"
2915   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
2916         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2917   "TARGET_HARD_FLOAT"
2918   "*
2919 {
2920   if (REGNO (operands[0]) == REGNO (operands[1]))
2921     return \"\";
2922   else
2923     return \"fmr %0,%1\";
2924 }"
2925   [(set_attr "type" "fp")])
2926
2927 (define_insn "truncdfsf2"
2928   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2929         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
2930   "TARGET_HARD_FLOAT"
2931   "frsp %0,%1"
2932   [(set_attr "type" "fp")])
2933
2934 (define_insn "aux_truncdfsf2"
2935   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2936         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] 0))]
2937   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2938   "frsp %0,%1"
2939   [(set_attr "type" "fp")])
2940
2941 (define_insn "negsf2"
2942   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2943         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2944   "TARGET_HARD_FLOAT"
2945   "fneg %0,%1"
2946   [(set_attr "type" "fp")])
2947
2948 (define_insn "abssf2"
2949   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2950         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2951   "TARGET_HARD_FLOAT"
2952   "fabs %0,%1"
2953   [(set_attr "type" "fp")])
2954
2955 (define_insn ""
2956   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2957         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
2958   "TARGET_HARD_FLOAT"
2959   "fnabs %0,%1"
2960   [(set_attr "type" "fp")])
2961
2962 (define_expand "addsf3"
2963   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2964         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2965                  (match_operand:SF 2 "gpc_reg_operand" "")))]
2966   "TARGET_HARD_FLOAT"
2967   "")
2968
2969 (define_insn ""
2970   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2971         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2972                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2973   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2974   "fadds %0,%1,%2"
2975   [(set_attr "type" "fp")])
2976
2977 (define_insn ""
2978   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2979         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2980                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2981   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2982   "{fa|fadd} %0,%1,%2"
2983   [(set_attr "type" "fp")])
2984
2985 (define_expand "subsf3"
2986   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2987         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2988                   (match_operand:SF 2 "gpc_reg_operand" "")))]
2989   "TARGET_HARD_FLOAT"
2990   "")
2991
2992 (define_insn ""
2993   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2994         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2995                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
2996   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2997   "fsubs %0,%1,%2"
2998   [(set_attr "type" "fp")])
2999
3000 (define_insn ""
3001   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3002         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
3003                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
3004   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3005   "{fs|fsub} %0,%1,%2"
3006   [(set_attr "type" "fp")])
3007
3008 (define_expand "mulsf3"
3009   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3010         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
3011                  (match_operand:SF 2 "gpc_reg_operand" "")))]
3012   "TARGET_HARD_FLOAT"
3013   "")
3014
3015 (define_insn ""
3016   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3017         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3018                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
3019   "TARGET_POWERPC && TARGET_HARD_FLOAT"
3020   "fmuls %0,%1,%2"
3021   [(set_attr "type" "fp")])
3022
3023 (define_insn ""
3024   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3025         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3026                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
3027   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3028   "{fm|fmul} %0,%1,%2"
3029   [(set_attr "type" "dmul")])
3030
3031 (define_expand "divsf3"
3032   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3033         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
3034                 (match_operand:SF 2 "gpc_reg_operand" "")))]
3035   "TARGET_HARD_FLOAT"
3036   "")
3037
3038 (define_insn ""
3039   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3040         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
3041                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
3042   "TARGET_POWERPC && TARGET_HARD_FLOAT"
3043   "fdivs %0,%1,%2"
3044   [(set_attr "type" "sdiv")])
3045
3046 (define_insn ""
3047   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3048         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
3049                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
3050   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3051   "{fd|fdiv} %0,%1,%2"
3052   [(set_attr "type" "ddiv")])
3053
3054 (define_insn ""
3055   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3056         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3057                           (match_operand:SF 2 "gpc_reg_operand" "f"))
3058                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
3059   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3060   "fmadds %0,%1,%2,%3"
3061   [(set_attr "type" "fp")])
3062
3063 (define_insn ""
3064   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3065         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3066                           (match_operand:SF 2 "gpc_reg_operand" "f"))
3067                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
3068   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3069   "{fma|fmadd} %0,%1,%2,%3"
3070   [(set_attr "type" "dmul")])
3071
3072 (define_insn ""
3073   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3074         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3075                            (match_operand:SF 2 "gpc_reg_operand" "f"))
3076                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
3077   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3078   "fmsubs %0,%1,%2,%3"
3079   [(set_attr "type" "fp")])
3080
3081 (define_insn ""
3082   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3083         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3084                            (match_operand:SF 2 "gpc_reg_operand" "f"))
3085                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
3086   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3087   "{fms|fmsub} %0,%1,%2,%3"
3088   [(set_attr "type" "dmul")])
3089
3090 (define_insn ""
3091   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3092         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3093                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
3094                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
3095   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3096   "fnmadds %0,%1,%2,%3"
3097   [(set_attr "type" "fp")])
3098
3099 (define_insn ""
3100   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3101         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3102                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
3103                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
3104   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3105   "{fnma|fnmadd} %0,%1,%2,%3"
3106   [(set_attr "type" "dmul")])
3107
3108 (define_insn ""
3109   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3110         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3111                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
3112                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
3113   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3114   "fnmsubs %0,%1,%2,%3"
3115   [(set_attr "type" "fp")])
3116
3117 (define_insn ""
3118   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3119         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3120                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
3121                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
3122   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3123   "{fnms|fnmsub} %0,%1,%2,%3"
3124   [(set_attr "type" "dmul")])
3125
3126 (define_expand "sqrtsf2"
3127   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3128         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
3129   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT"
3130   "")
3131
3132 (define_insn ""
3133   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3134         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
3135   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT"
3136   "fsqrts %0,%1"
3137   [(set_attr "type" "ssqrt")])
3138
3139 (define_insn ""
3140   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3141         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
3142   "TARGET_POWER2 && TARGET_HARD_FLOAT"
3143   "fsqrt %0,%1"
3144   [(set_attr "type" "dsqrt")])
3145
3146 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
3147 ;; fsel instruction and some auxiliary computations.  Then we just have a
3148 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
3149 ;; combine.
3150 (define_expand "maxsf3"
3151   [(set (match_dup 3)
3152         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
3153                   (match_operand:SF 2 "gpc_reg_operand" "")))
3154    (set (match_operand:SF 0 "gpc_reg_operand" "")
3155         (if_then_else:SF (ge (match_dup 3)
3156                              (const_int 0))
3157                          (match_dup 1)
3158                          (match_dup 2)))]
3159   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3160   "
3161 { operands[3] = gen_reg_rtx (SFmode); }")
3162
3163 (define_split
3164   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3165         (smax:SF (match_operand:SF 1 "gpc_reg_operand" "")
3166                  (match_operand:SF 2 "gpc_reg_operand" "")))
3167    (clobber (match_operand:SF 3 "gpc_reg_operand" ""))]
3168   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3169   [(set (match_dup 3)
3170         (minus:SF (match_dup 1) (match_dup 2)))
3171    (set (match_dup 0)
3172         (if_then_else:SF (ge (match_dup 3)
3173                              (const_int 0))
3174                          (match_dup 1)
3175                          (match_dup 2)))]
3176   "")
3177
3178 (define_expand "minsf3"
3179   [(set (match_dup 3)
3180         (minus:SF (match_operand:SF 2 "gpc_reg_operand" "")
3181                   (match_operand:SF 1 "gpc_reg_operand" "")))
3182    (set (match_operand:SF 0 "gpc_reg_operand" "")
3183         (if_then_else:SF (ge (match_dup 3)
3184                              (const_int 0))
3185                          (match_dup 1)
3186                          (match_dup 2)))]
3187   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3188   "
3189 { operands[3] = gen_reg_rtx (SFmode); }")
3190
3191 (define_split
3192   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3193         (smin:SF (match_operand:SF 1 "gpc_reg_operand" "")
3194                  (match_operand:SF 2 "gpc_reg_operand" "")))
3195    (clobber (match_operand:SF 3 "gpc_reg_operand" ""))]
3196   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3197   [(set (match_dup 3)
3198         (minus:SF (match_dup 2) (match_dup 1)))
3199    (set (match_dup 0)
3200         (if_then_else:SF (ge (match_dup 3)
3201                              (const_int 0))
3202                          (match_dup 1)
3203                          (match_dup 2)))]
3204   "")
3205
3206 (define_expand "movsfcc"
3207    [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3208          (if_then_else:SF (match_operand 1 "comparison_operator" "")
3209                           (match_operand:SF 2 "gpc_reg_operand" "f")
3210                           (match_operand:SF 3 "gpc_reg_operand" "f")))]
3211   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3212   "
3213 {
3214   rtx temp, op0, op1;
3215   enum rtx_code code = GET_CODE (operands[1]);
3216   if (! rs6000_compare_fp_p)
3217     FAIL;
3218   switch (code)
3219     {
3220     case GE: case EQ: case NE:
3221       op0 = rs6000_compare_op0;
3222       op1 = rs6000_compare_op1;
3223       break;
3224     case GT:
3225       op0 = rs6000_compare_op1;
3226       op1 = rs6000_compare_op0;
3227       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3228       break;
3229     case LE:
3230       op0 = rs6000_compare_op1;
3231       op1 = rs6000_compare_op0;
3232       break;
3233     case LT:
3234       op0 = rs6000_compare_op0;
3235       op1 = rs6000_compare_op1;
3236       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3237       break;
3238     default:
3239       FAIL;
3240     }
3241   if (GET_MODE (rs6000_compare_op0) == DFmode)
3242     {
3243       temp = gen_reg_rtx (DFmode);
3244       emit_insn (gen_subdf3 (temp, op0, op1));
3245       emit_insn (gen_fseldfsf4 (operands[0], temp, operands[2], operands[3]));
3246       if (code == EQ)
3247         {
3248           emit_insn (gen_negdf2 (temp, temp));
3249           emit_insn (gen_fseldfsf4 (operands[0], temp, operands[0], operands[3]));
3250         }
3251       if (code == NE)
3252         {
3253           emit_insn (gen_negdf2 (temp, temp));
3254           emit_insn (gen_fseldfsf4 (operands[0], temp, operands[3], operands[0]));
3255         }
3256     }
3257   else
3258     {
3259       temp = gen_reg_rtx (SFmode);
3260       emit_insn (gen_subsf3 (temp, op0, op1));
3261       emit_insn (gen_fselsfsf4 (operands[0], temp, operands[2], operands[3]));
3262       if (code == EQ)
3263         {
3264           emit_insn (gen_negsf2 (temp, temp));
3265           emit_insn (gen_fselsfsf4 (operands[0], temp, operands[0], operands[3]));
3266         }
3267       if (code == NE)
3268         {
3269           emit_insn (gen_negsf2 (temp, temp));
3270           emit_insn (gen_fselsfsf4 (operands[0], temp, operands[3], operands[0]));
3271         }
3272     }
3273   DONE;
3274 }")
3275
3276 (define_insn "fselsfsf4"
3277   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3278         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
3279                              (const_int 0))
3280                          (match_operand:SF 2 "gpc_reg_operand" "f")
3281                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
3282   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3283   "fsel %0,%1,%2,%3"
3284   [(set_attr "type" "fp")])
3285
3286 (define_insn "fseldfsf4"
3287   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3288         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
3289                              (const_int 0))
3290                          (match_operand:SF 2 "gpc_reg_operand" "f")
3291                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
3292   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3293   "fsel %0,%1,%2,%3"
3294   [(set_attr "type" "fp")])
3295
3296 (define_insn "negdf2"
3297   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3298         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3299   "TARGET_HARD_FLOAT"
3300   "fneg %0,%1"
3301   [(set_attr "type" "fp")])
3302
3303 (define_insn "absdf2"
3304   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3305         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3306   "TARGET_HARD_FLOAT"
3307   "fabs %0,%1"
3308   [(set_attr "type" "fp")])
3309
3310 (define_insn ""
3311   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3312         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
3313   "TARGET_HARD_FLOAT"
3314   "fnabs %0,%1"
3315   [(set_attr "type" "fp")])
3316
3317 (define_insn "adddf3"
3318   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3319         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3320                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
3321   "TARGET_HARD_FLOAT"
3322   "{fa|fadd} %0,%1,%2"
3323   [(set_attr "type" "fp")])
3324
3325 (define_insn "subdf3"
3326   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3327         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
3328                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
3329   "TARGET_HARD_FLOAT"
3330   "{fs|fsub} %0,%1,%2"
3331   [(set_attr "type" "fp")])
3332
3333 (define_insn "muldf3"
3334   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3335         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3336                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
3337   "TARGET_HARD_FLOAT"
3338   "{fm|fmul} %0,%1,%2"
3339   [(set_attr "type" "dmul")])
3340
3341 (define_insn "divdf3"
3342   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3343         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
3344                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
3345   "TARGET_HARD_FLOAT"
3346   "{fd|fdiv} %0,%1,%2"
3347   [(set_attr "type" "ddiv")])
3348
3349 (define_insn ""
3350   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3351         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3352                           (match_operand:DF 2 "gpc_reg_operand" "f"))
3353                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
3354   "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3355   "{fma|fmadd} %0,%1,%2,%3"
3356   [(set_attr "type" "dmul")])
3357
3358 (define_insn ""
3359   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3360         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3361                            (match_operand:DF 2 "gpc_reg_operand" "f"))
3362                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
3363   "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3364   "{fms|fmsub} %0,%1,%2,%3"
3365   [(set_attr "type" "dmul")])
3366
3367 (define_insn ""
3368   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3369         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3370                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
3371                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
3372   "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3373   "{fnma|fnmadd} %0,%1,%2,%3"
3374   [(set_attr "type" "dmul")])
3375
3376 (define_insn ""
3377   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3378         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3379                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
3380                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
3381   "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
3382   "{fnms|fnmsub} %0,%1,%2,%3"
3383   [(set_attr "type" "dmul")])
3384
3385 (define_insn "sqrtdf2"
3386   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3387         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3388   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT"
3389   "fsqrt %0,%1"
3390   [(set_attr "type" "dsqrt")])
3391
3392 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
3393 ;; fsel instruction and some auxiliary computations.  Then we just have a
3394 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
3395 ;; combine.
3396
3397 (define_expand "maxdf3"
3398   [(set (match_dup 3)
3399         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
3400                   (match_operand:DF 2 "gpc_reg_operand" "")))
3401    (set (match_operand:DF 0 "gpc_reg_operand" "")
3402         (if_then_else:DF (ge (match_dup 3)
3403                              (const_int 0))
3404                          (match_dup 1)
3405                          (match_dup 2)))]
3406   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3407   "
3408 { operands[3] = gen_reg_rtx (DFmode); }")
3409
3410 (define_split
3411   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3412         (smax:DF (match_operand:DF 1 "gpc_reg_operand" "")
3413                  (match_operand:DF 2 "gpc_reg_operand" "")))
3414    (clobber (match_operand:DF 3 "gpc_reg_operand" ""))]
3415   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3416   [(set (match_dup 3)
3417         (minus:DF (match_dup 1) (match_dup 2)))
3418    (set (match_dup 0)
3419         (if_then_else:DF (ge (match_dup 3)
3420                              (const_int 0))
3421                          (match_dup 1)
3422                          (match_dup 2)))]
3423   "")
3424
3425 (define_expand "mindf3"
3426   [(set (match_dup 3)
3427         (minus:DF (match_operand:DF 2 "gpc_reg_operand" "")
3428                   (match_operand:DF 1 "gpc_reg_operand" "")))
3429    (set (match_operand:DF 0 "gpc_reg_operand" "")
3430         (if_then_else:DF (ge (match_dup 3)
3431                              (const_int 0))
3432                          (match_dup 1)
3433                          (match_dup 2)))]
3434   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3435   "
3436 { operands[3] = gen_reg_rtx (DFmode); }")
3437
3438 (define_split
3439   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3440         (smin:DF (match_operand:DF 1 "gpc_reg_operand" "")
3441                  (match_operand:DF 2 "gpc_reg_operand" "")))
3442    (clobber (match_operand:DF 3 "gpc_reg_operand" ""))]
3443   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3444   [(set (match_dup 3)
3445         (minus:DF (match_dup 2) (match_dup 1)))
3446    (set (match_dup 0)
3447         (if_then_else:DF (ge (match_dup 3)
3448                              (const_int 0))
3449                          (match_dup 1)
3450                          (match_dup 2)))]
3451   "")
3452
3453 (define_expand "movdfcc"
3454    [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3455          (if_then_else:DF (match_operand 1 "comparison_operator" "")
3456                           (match_operand:DF 2 "gpc_reg_operand" "f")
3457                           (match_operand:DF 3 "gpc_reg_operand" "f")))]
3458   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3459   "
3460 {
3461   rtx temp, op0, op1;
3462   enum rtx_code code = GET_CODE (operands[1]);
3463   if (! rs6000_compare_fp_p)
3464     FAIL;
3465   switch (code)
3466     {
3467     case GE: case EQ: case NE:
3468       op0 = rs6000_compare_op0;
3469       op1 = rs6000_compare_op1;
3470       break;
3471     case GT:
3472       op0 = rs6000_compare_op1;
3473       op1 = rs6000_compare_op0;
3474       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3475       break;
3476     case LE:
3477       op0 = rs6000_compare_op1;
3478       op1 = rs6000_compare_op0;
3479       break;
3480     case LT:
3481       op0 = rs6000_compare_op0;
3482       op1 = rs6000_compare_op1;
3483       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3484       break;
3485     default:
3486       FAIL;
3487     }
3488   if (GET_MODE (rs6000_compare_op0) == DFmode)
3489     {
3490       temp = gen_reg_rtx (DFmode);
3491       emit_insn (gen_subdf3 (temp, op0, op1));
3492       emit_insn (gen_fseldfdf4 (operands[0], temp, operands[2], operands[3]));
3493       if (code == EQ)
3494         {
3495           emit_insn (gen_negdf2 (temp, temp));
3496           emit_insn (gen_fseldfdf4 (operands[0], temp, operands[0], operands[3]));
3497         }
3498       if (code == NE)
3499         {
3500           emit_insn (gen_negdf2 (temp, temp));
3501           emit_insn (gen_fseldfdf4 (operands[0], temp, operands[3], operands[0]));
3502         }
3503     }
3504   else
3505     {
3506       temp = gen_reg_rtx (SFmode);
3507       emit_insn (gen_subsf3 (temp, op0, op1));
3508       emit_insn (gen_fselsfdf4 (operands[0], temp, operands[2], operands[3]));
3509       if (code == EQ)
3510         {
3511           emit_insn (gen_negsf2 (temp, temp));
3512           emit_insn (gen_fselsfdf4 (operands[0], temp, operands[0], operands[3]));
3513         }
3514       if (code == NE)
3515         {
3516           emit_insn (gen_negsf2 (temp, temp));
3517           emit_insn (gen_fselsfdf4 (operands[0], temp, operands[3], operands[0]));
3518         }
3519     }
3520   DONE;
3521 }")
3522
3523 (define_insn "fseldfdf4"
3524   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3525         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
3526                              (const_int 0))
3527                          (match_operand:DF 2 "gpc_reg_operand" "f")
3528                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
3529   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3530   "fsel %0,%1,%2,%3"
3531   [(set_attr "type" "fp")])
3532
3533 (define_insn "fselsfdf4"
3534   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3535         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
3536                              (const_int 0))
3537                          (match_operand:DF 2 "gpc_reg_operand" "f")
3538                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
3539   "TARGET_PPC_GFXOPT"
3540   "fsel %0,%1,%2,%3"
3541   [(set_attr "type" "fp")])
3542 \f
3543 ;; Conversions to and from floating-point.
3544
3545 (define_expand "floatsidf2"
3546   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
3547                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
3548               (use (match_dup 2))
3549               (use (match_dup 3))
3550               (clobber (match_dup 4))
3551               (clobber (match_dup 5))
3552               (clobber (reg:DF 76))])]
3553   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3554   "
3555 {
3556   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
3557   operands[3] = force_reg (DFmode, rs6000_float_const (\"4503601774854144\", DFmode));
3558   operands[4] = gen_reg_rtx (SImode);
3559   operands[5] = gen_reg_rtx (Pmode);
3560 }")
3561
3562 (define_insn "*floatsidf2_internal"
3563   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
3564         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
3565    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
3566    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
3567    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
3568    (clobber (match_operand:SI 5 "gpc_reg_operand" "=b"))
3569    (clobber (reg:DF 76))]
3570   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3571   "#"
3572   [(set_attr "length" "24")])
3573
3574 (define_split
3575   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3576         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
3577    (use (match_operand:SI 2 "gpc_reg_operand" ""))
3578    (use (match_operand:DF 3 "gpc_reg_operand" ""))
3579    (clobber (match_operand:SI 4 "gpc_reg_operand" ""))
3580    (clobber (match_operand:SI 5 "gpc_reg_operand" ""))
3581    (clobber (reg:DF 76))]
3582   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3583   [(set (match_dup 4)
3584         (xor:SI (match_dup 1)
3585                 (match_dup 6)))
3586    (set (match_dup 5)
3587         (unspec [(const_int 0)] 11))
3588    (set (match_dup 7)
3589         (unspec [(match_dup 4)
3590                  (match_dup 5)] 12))    ;; low word
3591    (set (match_dup 7)
3592         (unspec [(match_dup 2)
3593                  (match_dup 5)
3594                  (match_dup 7)] 13))    ;; high word
3595    (set (match_dup 0)
3596         (unspec [(match_dup 7)
3597                  (match_dup 5)] 14))
3598    (set (match_dup 0)
3599         (minus:DF (match_dup 0)
3600                   (match_dup 3)))]
3601   "
3602 {
3603   operands[6] = GEN_INT (0x80000000);
3604   operands[7] = gen_rtx (REG, DFmode, FPMEM_REGNUM);
3605 }")
3606
3607 (define_expand "floatunssidf2"
3608   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
3609                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
3610               (use (match_dup 2))
3611               (use (match_dup 3))
3612               (clobber (match_dup 4))
3613               (clobber (reg:DF 76))])]
3614   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3615   "
3616 {
3617   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
3618   operands[3] = force_reg (DFmode, rs6000_float_const (\"4503599627370496\", DFmode));
3619   operands[4] = gen_reg_rtx (Pmode);
3620 }")
3621
3622 (define_insn "*floatunssidf2_internal"
3623   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
3624         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
3625    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
3626    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
3627    (clobber (match_operand:SI 4 "gpc_reg_operand" "=b"))
3628    (clobber (reg:DF 76))]
3629   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3630   "#"
3631   [(set_attr "length" "20")])
3632
3633 (define_split
3634   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3635         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
3636    (use (match_operand:SI 2 "gpc_reg_operand" ""))
3637    (use (match_operand:DF 3 "gpc_reg_operand" ""))
3638    (clobber (match_operand:SI 4 "gpc_reg_operand" "=b"))
3639    (clobber (reg:DF 76))]
3640   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3641   [(set (match_dup 4)
3642         (unspec [(const_int 0)] 11))
3643    (set (match_dup 5)
3644         (unspec [(match_dup 1)
3645                  (match_dup 4)] 12))    ;; low word
3646    (set (match_dup 5)
3647         (unspec [(match_dup 2)
3648                  (match_dup 4)
3649                  (match_dup 5)] 13))    ;; high word
3650    (set (match_dup 0)
3651         (unspec [(match_dup 5)
3652                  (reg:SI 1)] 14))
3653    (set (match_dup 0)
3654         (minus:DF (match_dup 0)
3655                   (match_dup 3)))]
3656   "operands[5] = gen_rtx (REG, DFmode, FPMEM_REGNUM);")
3657
3658 ;; Load up scratch register with base address + offset if needed
3659 (define_insn "*floatsidf2_loadaddr"
3660   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
3661         (unspec [(const_int 0)] 11))]
3662   "TARGET_HARD_FLOAT"
3663   "*
3664 {
3665   if (rs6000_fpmem_offset > 32760)
3666     {
3667       rtx xop[3];
3668
3669       xop[0] = operands[0];
3670       xop[1] = (frame_pointer_needed) ? frame_pointer_rtx : stack_pointer_rtx;
3671       xop[2] = GEN_INT ((rs6000_fpmem_offset >> 16) + ((rs6000_fpmem_offset & 0x8000) >> 15));
3672       output_asm_insn (\"{cau|addis} %0,%1,%2\", xop);
3673     }
3674   else if (rs6000_fpmem_offset < 0)
3675     abort ();
3676
3677   return \"\";
3678 }"
3679   [(set_attr "length" "4")])
3680
3681 (define_insn "*floatsidf2_store1"
3682   [(set (reg:DF 76)
3683         (unspec [(match_operand:SI 0 "gpc_reg_operand" "r")
3684                  (match_operand:SI 1 "gpc_reg_operand" "r")] 12))]
3685   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3686   "*
3687 {
3688   rtx indx;
3689
3690   if (rs6000_fpmem_offset > 32760)
3691     indx = operands[1];
3692   else if (frame_pointer_needed)
3693     indx = frame_pointer_rtx;
3694   else
3695     indx = stack_pointer_rtx;
3696
3697   operands[2] = gen_rtx (MEM, SImode,
3698                          gen_rtx (PLUS, Pmode,
3699                                   indx,
3700                                   GEN_INT ((((rs6000_fpmem_offset & 0xffff) ^ 0x8000) - 0x8000)
3701                                            + ((WORDS_BIG_ENDIAN != 0) * 4))));
3702
3703   return \"{st|stw} %0,%2\";
3704 }"
3705   [(set_attr "type" "store")])
3706
3707 (define_insn "*floatsidf2_store2"
3708   [(set (reg:DF 76)
3709         (unspec [(match_operand:SI 0 "gpc_reg_operand" "r")
3710                  (match_operand:SI 1 "gpc_reg_operand" "r")
3711                  (reg:DF 76)] 13))]
3712   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3713   "*
3714 {
3715   rtx indx;
3716
3717   if (rs6000_fpmem_offset > 32760)
3718     indx = operands[1];
3719   else if (frame_pointer_needed)
3720     indx = frame_pointer_rtx;
3721   else
3722     indx = stack_pointer_rtx;
3723
3724   operands[2] = gen_rtx (MEM, SImode,
3725                          gen_rtx (PLUS, Pmode,
3726                                   indx,
3727                                   GEN_INT ((((rs6000_fpmem_offset & 0xffff) ^ 0x8000) - 0x8000)
3728                                            + ((WORDS_BIG_ENDIAN == 0) * 4))));
3729
3730   return \"{st|stw} %0,%2\";
3731 }"
3732   [(set_attr "type" "store")])
3733
3734 (define_insn "*floatsidf2_load"
3735   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3736         (unspec [(reg:DF 76)
3737                  (match_operand:SI 1 "gpc_reg_operand" "b")] 14))]
3738   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3739   "*
3740 {
3741   rtx indx;
3742   HOST_WIDE_INT offset = rs6000_fpmem_offset;
3743
3744   if (rs6000_fpmem_offset > 32760)
3745     {
3746       indx = operands[1];
3747       offset = (((offset & 0xffff) ^ 0x8000) - 0x8000);
3748     }
3749   else if (frame_pointer_needed)
3750     indx = frame_pointer_rtx;
3751   else
3752     indx = stack_pointer_rtx;
3753
3754   operands[2] = gen_rtx (MEM, SImode,
3755                          gen_rtx (PLUS, Pmode, indx, GEN_INT (offset)));
3756
3757   return \"lfd %0,%2\";
3758 }"
3759   [(set_attr "type" "fpload")])
3760
3761 (define_expand "fix_truncdfsi2"
3762   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
3763                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
3764               (clobber (match_dup 2))
3765               (clobber (match_dup 3))
3766               (clobber (match_dup 4))])]
3767   "TARGET_HARD_FLOAT"
3768   "
3769 {
3770   if (!TARGET_POWER2 && !TARGET_POWERPC)
3771     {
3772       emit_insn (gen_trunc_call (operands[0], operands[1],
3773                                  gen_rtx (SYMBOL_REF, Pmode, RS6000_ITRUNC)));
3774       DONE;
3775     }
3776
3777   operands[2] = gen_reg_rtx (DImode);
3778   operands[3] = gen_reg_rtx (Pmode);
3779   operands[4] = gen_rtx (REG, DImode, FPMEM_REGNUM);
3780 }")
3781
3782 (define_insn "*fix_truncdfsi2_internal"
3783   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3784         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
3785    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
3786    (clobber (match_operand:SI 3 "gpc_reg_operand" "=b"))
3787    (clobber (reg:DI 76))]
3788   "TARGET_HARD_FLOAT"
3789   "#"
3790   [(set_attr "length" "12")])
3791
3792 (define_split
3793   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3794         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
3795    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
3796    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))
3797    (clobber (reg:DI 76))]
3798   "TARGET_HARD_FLOAT"
3799   [(set (match_dup 2)
3800         (sign_extend:DI (fix:SI (match_operand:DF 1 "gpc_reg_operand" ""))))
3801    (set (match_dup 3)
3802         (unspec [(const_int 0)] 11))
3803    (set (match_dup 4)
3804         (unspec [(match_dup 2)
3805                  (match_dup 3)] 15))
3806    (set (match_operand:SI 0 "gpc_reg_operand" "")
3807         (unspec [(match_dup 4)
3808                  (match_dup 3)] 16))]
3809   "operands[4] = gen_rtx (REG, DImode, FPMEM_REGNUM);")
3810
3811 (define_insn "*fctiwz"
3812   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
3813         (sign_extend:DI (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))))]
3814   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT"
3815   "{fcirz|fctiwz} %0,%1"
3816   [(set_attr "type" "fp")])
3817
3818 (define_insn "*fix_truncdfsi2_store"
3819   [(set (reg:DI 76)
3820         (unspec [(match_operand:DI 0 "gpc_reg_operand" "f")
3821                  (match_operand:SI 1 "gpc_reg_operand" "b")] 15))]
3822   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT"
3823   "*
3824 {
3825   rtx indx;
3826
3827   if (rs6000_fpmem_offset > 32760)
3828     indx = operands[1];
3829   else if (frame_pointer_needed)
3830     indx = frame_pointer_rtx;
3831   else
3832     indx = stack_pointer_rtx;
3833
3834   operands[2] = gen_rtx (MEM, DFmode,
3835                          gen_rtx (PLUS, Pmode,
3836                                   indx,
3837                                   GEN_INT ((((rs6000_fpmem_offset & 0xffff)
3838                                              ^ 0x8000) - 0x8000))));
3839
3840   return \"stfd %0,%w2\";
3841 }"
3842   [(set_attr "type" "fpstore")])
3843
3844 (define_insn "*fix_truncdfsi2_load"
3845   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3846         (unspec [(reg:DI 76)
3847                  (match_operand:SI 1 "gpc_reg_operand" "b")] 16))]
3848   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT"
3849   "*
3850 {
3851   rtx indx;
3852
3853   if (rs6000_fpmem_offset > 32760)
3854     indx = operands[1];
3855   else if (frame_pointer_needed)
3856     indx = frame_pointer_rtx;
3857   else
3858     indx = stack_pointer_rtx;
3859
3860   operands[2] = gen_rtx (MEM, DFmode,
3861                          gen_rtx (PLUS, Pmode,
3862                                   indx,
3863                                   GEN_INT ((((rs6000_fpmem_offset & 0xffff) ^ 0x8000) - 0x8000)
3864                                            + ((WORDS_BIG_ENDIAN) ? 4 : 0))));
3865
3866   return \"{l|lwz} %0,%2\";
3867 }"
3868   [(set_attr "type" "load")])
3869
3870 (define_expand "fixuns_truncdfsi2"
3871   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3872         (unsigned_fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))]
3873   "! TARGET_POWER2 && ! TARGET_POWERPC && TARGET_HARD_FLOAT"
3874   "
3875 {
3876   emit_insn (gen_trunc_call (operands[0], operands[1],
3877                              gen_rtx (SYMBOL_REF, Pmode, RS6000_UITRUNC)));
3878   DONE;
3879 }")
3880
3881 (define_expand "trunc_call"
3882   [(parallel [(set (match_operand:SI 0 "" "")
3883                    (fix:SI (match_operand:DF 1 "" "")))
3884               (use (match_operand:SI 2 "" ""))])]
3885   "TARGET_HARD_FLOAT"
3886   "
3887 {
3888   rtx insns = gen_trunc_call_rtl (operands[0], operands[1], operands[2]);
3889   rtx first = XVECEXP (insns, 0, 0);
3890   rtx last = XVECEXP (insns, 0, XVECLEN (insns, 0) - 1);
3891
3892   REG_NOTES (first) = gen_rtx (INSN_LIST, REG_LIBCALL, last,
3893                                REG_NOTES (first));
3894   REG_NOTES (last) = gen_rtx (INSN_LIST, REG_RETVAL, first, REG_NOTES (last));
3895
3896   emit_insn (insns);
3897   DONE;
3898 }")
3899
3900 (define_expand "trunc_call_rtl"
3901   [(set (reg:DF 33) (match_operand:DF 1 "gpc_reg_operand" ""))
3902    (use (reg:DF 33))
3903    (parallel [(set (reg:SI 3)
3904                    (call (mem:SI (match_operand 2 "" "")) (const_int 0)))
3905               (use (const_int 0))
3906               (clobber (scratch:SI))])
3907    (set (match_operand:SI 0 "gpc_reg_operand" "")
3908         (reg:SI 3))]
3909   "TARGET_HARD_FLOAT"
3910   "
3911 {
3912   rs6000_trunc_used = 1;
3913 }")
3914
3915 (define_insn "floatdidf2"
3916   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3917         (float:DF (match_operand:DI 1 "gpc_reg_operand" "f")))]
3918   "TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3919   "fcfid %0,%1"
3920   [(set_attr "type" "fp")])
3921
3922 (define_insn "fix_truncdfdi2"
3923   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
3924         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
3925   "TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3926   "fctidz %0,%1"
3927   [(set_attr "type" "fp")])
3928 \f
3929 ;; Define the DImode operations that can be done in a small number
3930 ;; of instructions.  The & constraints are to prevent the register
3931 ;; allocator from allocating registers that overlap with the inputs
3932 ;; (for example, having an input in 7,8 and an output in 6,7).  We
3933 ;; also allow for the the output being the same as one of the inputs.
3934
3935 (define_insn "*adddi3_noppc64"
3936   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
3937         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
3938                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
3939   "! TARGET_POWERPC64"
3940   "*
3941 {
3942   if (WORDS_BIG_ENDIAN)
3943     return (GET_CODE (operands[2])) != CONST_INT
3944             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
3945             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
3946   else
3947     return (GET_CODE (operands[2])) != CONST_INT
3948             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
3949             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
3950 }"
3951   [(set_attr "length" "8")])
3952
3953 (define_insn "*subdi3_noppc64"
3954   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
3955         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
3956                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
3957   "! TARGET_POWERPC64"
3958   "*
3959 {
3960   if (WORDS_BIG_ENDIAN)
3961     return (GET_CODE (operands[1]) != CONST_INT)
3962             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
3963             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
3964   else
3965     return (GET_CODE (operands[1]) != CONST_INT)
3966             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
3967             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
3968 }"
3969   [(set_attr "length" "8")])
3970
3971 (define_insn "*negdi2_noppc64"
3972   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
3973         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
3974   "! TARGET_POWERPC64"
3975   "*
3976 {
3977   return (WORDS_BIG_ENDIAN)
3978     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
3979     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
3980 }"
3981   [(set_attr "length" "8")])
3982
3983 (define_expand "mulsidi3"
3984   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3985         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
3986                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
3987   ""
3988   "
3989 {
3990   if (! TARGET_POWER && ! TARGET_POWERPC)
3991     {
3992       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
3993       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
3994       emit_insn (gen_mull_call ());
3995       if (WORDS_BIG_ENDIAN)
3996         emit_move_insn (operands[0], gen_rtx (REG, DImode, 3));
3997       else
3998         {
3999           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
4000                           gen_rtx (REG, SImode, 3));
4001           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
4002                           gen_rtx (REG, SImode, 4));
4003         }
4004       DONE;
4005     }
4006   else if (TARGET_POWER)
4007     {
4008       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
4009       DONE;
4010     }
4011 }")
4012
4013 (define_insn "mulsidi3_mq"
4014   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4015         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
4016                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
4017    (clobber (match_scratch:SI 3 "=q"))]
4018   "TARGET_POWER"
4019   "mul %0,%1,%2\;mfmq %L0"
4020   [(set_attr "type" "imul")
4021    (set_attr "length" "8")])
4022
4023 (define_insn "*mulsidi3_powerpc"
4024   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
4025         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
4026                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
4027   "TARGET_POWERPC && ! TARGET_POWERPC64"
4028   "*
4029 {
4030   return (WORDS_BIG_ENDIAN)
4031     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
4032     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
4033 }"
4034   [(set_attr "type" "imul")
4035    (set_attr "length" "8")])
4036
4037 (define_split
4038   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4039         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
4040                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
4041   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
4042   [(set (match_dup 3)
4043         (truncate:SI
4044          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
4045                                (sign_extend:DI (match_dup 2)))
4046                       (const_int 32))))
4047    (set (match_dup 4)
4048         (mult:SI (match_dup 1)
4049                  (match_dup 2)))]
4050   "
4051 {
4052   int endian = (WORDS_BIG_ENDIAN == 0);
4053   operands[3] = operand_subword (operands[0], endian, 0, DImode);
4054   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
4055 }")
4056
4057 (define_insn "umulsidi3"
4058   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
4059         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
4060                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
4061   "TARGET_POWERPC && ! TARGET_POWERPC64"
4062   "*
4063 {
4064   return (WORDS_BIG_ENDIAN)
4065     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
4066     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
4067 }"
4068   [(set_attr "type" "imul")
4069    (set_attr "length" "8")])
4070
4071 (define_split
4072   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4073         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
4074                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
4075   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
4076   [(set (match_dup 3)
4077         (truncate:SI
4078          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
4079                                (zero_extend:DI (match_dup 2)))
4080                       (const_int 32))))
4081    (set (match_dup 4)
4082         (mult:SI (match_dup 1)
4083                  (match_dup 2)))]
4084   "
4085 {
4086   int endian = (WORDS_BIG_ENDIAN == 0);
4087   operands[3] = operand_subword (operands[0], endian, 0, DImode);
4088   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
4089 }")
4090
4091 (define_expand "smulsi3_highpart"
4092   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4093         (truncate:SI
4094          (lshiftrt:DI (mult:DI (sign_extend:DI
4095                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
4096                                (sign_extend:DI
4097                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
4098                       (const_int 32))))]
4099   ""
4100   "
4101 {
4102   if (! TARGET_POWER && ! TARGET_POWERPC)
4103     {
4104       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
4105       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
4106       emit_insn (gen_mulh_call ());
4107       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
4108       DONE;
4109     }
4110   else if (TARGET_POWER)
4111     {
4112       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
4113       DONE;
4114     }
4115 }")
4116
4117 (define_insn "smulsi3_highpart_mq"
4118   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4119         (truncate:SI
4120          (lshiftrt:DI (mult:DI (sign_extend:DI
4121                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
4122                                (sign_extend:DI
4123                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
4124                       (const_int 32))))
4125    (clobber (match_scratch:SI 3 "=q"))]
4126   "TARGET_POWER"
4127   "mul %0,%1,%2"
4128   [(set_attr "type" "imul")])
4129
4130 (define_insn ""
4131   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4132         (truncate:SI
4133          (lshiftrt:DI (mult:DI (sign_extend:DI
4134                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
4135                                (sign_extend:DI
4136                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
4137                       (const_int 32))))]
4138   "TARGET_POWERPC"
4139   "mulhw %0,%1,%2"
4140   [(set_attr "type" "imul")])
4141
4142 (define_insn "umulsi3_highpart"
4143   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4144         (truncate:SI
4145          (lshiftrt:DI (mult:DI (zero_extend:DI
4146                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
4147                                (zero_extend:DI
4148                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
4149                       (const_int 32))))]
4150   "TARGET_POWERPC"
4151   "mulhwu %0,%1,%2"
4152   [(set_attr "type" "imul")])
4153
4154 ;; If operands 0 and 2 are in the same register, we have a problem.  But
4155 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
4156 ;; why we have the strange constraints below.
4157 (define_insn "ashldi3_power"
4158   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
4159         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
4160                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
4161    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
4162   "TARGET_POWER"
4163   "@
4164    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
4165    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
4166    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
4167    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
4168   [(set_attr "length" "8")])
4169
4170 (define_insn "lshrdi3_power"
4171   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r,r,&r")
4172         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
4173                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
4174    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
4175   "TARGET_POWER"
4176   "@
4177    {cal %0,0(0)|li %0,0}\;{s%A2i|s%A2wi} %L0,%1,%h2
4178    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
4179    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
4180    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
4181   [(set_attr "length" "8")])
4182
4183 ;; Shift by a variable amount is too complex to be worth open-coding.  We
4184 ;; just handle shifts by constants.
4185 (define_insn "ashrdi3_power"
4186   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
4187         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
4188                      (match_operand:SI 2 "const_int_operand" "M,i")))
4189    (clobber (match_scratch:SI 3 "=X,q"))]
4190   "TARGET_POWER"
4191   "@
4192    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
4193    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
4194   [(set_attr "length" "8")])
4195 \f
4196 ;; PowerPC64 DImode operations.
4197
4198 (define_expand "adddi3"
4199   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4200         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
4201                  (match_operand:DI 2 "add_operand" "")))]
4202   ""
4203   "
4204 {
4205   if (! TARGET_POWERPC64 && non_short_cint_operand (operands[2], DImode))
4206     FAIL;
4207 }")
4208
4209 ;; Discourage ai/addic because of carry but provide it in an alternative
4210 ;; allowing register zero as source.
4211
4212 (define_insn ""
4213   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,?r,r")
4214         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,b,r,b")
4215                  (match_operand:DI 2 "add_operand" "r,I,I,J")))]
4216   "TARGET_POWERPC64"
4217   "@
4218    add %0,%1,%2
4219    addi %0,%1,%2
4220    addic %0,%1,%2
4221    addis %0,%1,%v2")
4222
4223 (define_insn ""
4224   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
4225         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
4226                              (match_operand:DI 2 "reg_or_short_operand" "r,I"))
4227                     (const_int 0)))
4228    (clobber (match_scratch:DI 3 "=r,r"))]
4229   "TARGET_POWERPC64"
4230   "@
4231    add. %3,%1,%2
4232    addic. %3,%1,%2"
4233   [(set_attr "type" "compare")])
4234
4235 (define_insn ""
4236   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
4237         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
4238                              (match_operand:DI 2 "reg_or_short_operand" "r,I"))
4239                     (const_int 0)))
4240    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4241         (plus:DI (match_dup 1) (match_dup 2)))]
4242   "TARGET_POWERPC64"
4243   "@
4244    add. %0,%1,%2
4245    addic. %0,%1,%2"
4246   [(set_attr "type" "compare")])
4247
4248 ;; Split an add that we can't do in one insn into two insns, each of which
4249 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
4250 ;; add should be last in case the result gets used in an address.
4251
4252 (define_split
4253   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4254         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
4255                  (match_operand:DI 2 "non_add_cint_operand" "")))]
4256   "TARGET_POWERPC64"
4257   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
4258    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
4259 "
4260 {
4261   HOST_WIDE_INT low = INTVAL (operands[2]) & 0xffff;
4262   HOST_WIDE_INT high = INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff);
4263
4264   if (low & 0x8000)
4265     high+=0x10000, low |= ((HOST_WIDE_INT) -1) << 16;
4266
4267   operands[3] = GEN_INT (high);
4268   operands[4] = GEN_INT (low);
4269 }")
4270
4271 (define_insn "one_cmpldi2"
4272   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4273         (not:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
4274   "TARGET_POWERPC64"
4275   "nor %0,%1,%1")
4276
4277 (define_insn ""
4278   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4279         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4280                     (const_int 0)))
4281    (clobber (match_scratch:DI 2 "=r"))]
4282   "TARGET_POWERPC64"
4283   "nor. %2,%1,%1"
4284   [(set_attr "type" "compare")])
4285
4286 (define_insn ""
4287   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
4288         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4289                     (const_int 0)))
4290    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4291         (not:DI (match_dup 1)))]
4292   "TARGET_POWERPC64"
4293   "nor. %0,%1,%1"
4294   [(set_attr "type" "compare")])
4295
4296 (define_insn ""
4297   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4298         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
4299                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
4300   "TARGET_POWERPC64"
4301   "@
4302    subf %0,%2,%1
4303    subfic %0,%2,%1")
4304
4305 (define_insn ""
4306   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4307         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4308                               (match_operand:DI 2 "gpc_reg_operand" "r"))
4309                     (const_int 0)))
4310    (clobber (match_scratch:DI 3 "=r"))]
4311   "TARGET_POWERPC64"
4312   "subf. %3,%2,%1"
4313   [(set_attr "type" "compare")])
4314
4315 (define_insn ""
4316   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4317         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4318                               (match_operand:DI 2 "gpc_reg_operand" "r"))
4319                     (const_int 0)))
4320    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4321         (minus:DI (match_dup 1) (match_dup 2)))]
4322   "TARGET_POWERPC64"
4323   "subf. %0,%2,%1"
4324   [(set_attr "type" "compare")])
4325
4326 (define_expand "subdi3"
4327   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4328         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "")
4329                   (match_operand:DI 2 "reg_or_cint_operand" "")))]
4330   ""
4331   "
4332 {
4333   if (GET_CODE (operands[2]) == CONST_INT)
4334     {
4335       emit_insn (gen_adddi3 (operands[0], operands[1],
4336                              negate_rtx (DImode, operands[2])));
4337       DONE;
4338     }
4339 }")
4340
4341 (define_insn "absdi2"
4342   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
4343         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
4344    (clobber (match_scratch:DI 2 "=&r,&r"))]
4345   "TARGET_POWERPC64"
4346   "sradi %2,%1,31\;xor %0,%2,%1\;subf %0,%2,%0"
4347   [(set_attr "length" "12")])
4348
4349 (define_split
4350   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
4351         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
4352    (clobber (match_scratch:DI 2 "=&r,&r"))]
4353   "TARGET_POWERPC64 && reload_completed"
4354   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 31)))
4355    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
4356    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
4357   "")
4358
4359 (define_insn ""
4360   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
4361         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
4362    (clobber (match_scratch:DI 2 "=&r,&r"))]
4363   "TARGET_POWERPC64"
4364   "sradi %2,%1,31\;xor %0,%2,%1\;subf %0,%0,%2"
4365   [(set_attr "length" "12")])
4366
4367 (define_split
4368   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
4369         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
4370    (clobber (match_scratch:DI 2 "=&r,&r"))]
4371   "TARGET_POWERPC64 && reload_completed"
4372   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 31)))
4373    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
4374    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
4375   "")
4376
4377 (define_expand "negdi2"
4378   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4379         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
4380   ""
4381   "")
4382
4383 (define_insn ""
4384   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4385         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
4386   "TARGET_POWERPC64"
4387   "neg %0,%1")
4388
4389 (define_insn ""
4390   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4391         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4392                     (const_int 0)))
4393    (clobber (match_scratch:DI 2 "=r"))]
4394   "TARGET_POWERPC64"
4395   "neg. %2,%1"
4396   [(set_attr "type" "compare")])
4397
4398 (define_insn ""
4399   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
4400         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4401                     (const_int 0)))
4402    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4403         (neg:DI (match_dup 1)))]
4404   "TARGET_POWERPC64"
4405   "neg. %0,%1"
4406   [(set_attr "type" "compare")])
4407
4408 (define_insn "ffsdi2"
4409   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
4410         (ffs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
4411   "TARGET_POWERPC64"
4412   "neg %0,%1\;and %0,%0,%1\;cntlzd %0,%0\;subfic %0,%0,64"
4413   [(set_attr "length" "16")])
4414
4415 (define_insn "muldi3"
4416   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4417         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4418                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
4419   "TARGET_POWERPC64"
4420   "mulld %0,%1,%2"
4421    [(set_attr "type" "imul")])
4422
4423 (define_insn "smuldi3_highpart"
4424   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4425         (truncate:DI
4426          (lshiftrt:TI (mult:TI (sign_extend:TI
4427                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
4428                                (sign_extend:TI
4429                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
4430                       (const_int 64))))]
4431   "TARGET_POWERPC64"
4432   "mulhd %0,%1,%2"
4433   [(set_attr "type" "imul")])
4434
4435 (define_insn "umuldi3_highpart"
4436   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4437         (truncate:DI
4438          (lshiftrt:TI (mult:TI (zero_extend:TI
4439                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
4440                                (zero_extend:TI
4441                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
4442                       (const_int 64))))]
4443   "TARGET_POWERPC64"
4444   "mulhdu %0,%1,%2"
4445   [(set_attr "type" "imul")])
4446
4447 (define_expand "divdi3"
4448   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4449         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
4450                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
4451   "TARGET_POWERPC64"
4452   "
4453 {
4454   if (GET_CODE (operands[2]) == CONST_INT
4455       && exact_log2 (INTVAL (operands[2])) >= 0)
4456     ;
4457   else
4458     operands[2] = force_reg (DImode, operands[2]);
4459 }")
4460
4461 (define_expand "moddi3"
4462   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
4463    (use (match_operand:DI 1 "gpc_reg_operand" ""))
4464    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
4465   "TARGET_POWERPC64"
4466   "
4467 {
4468   int i = exact_log2 (INTVAL (operands[2]));
4469   rtx temp1;
4470   rtx temp2;
4471
4472   if (GET_CODE (operands[2]) != CONST_INT || i < 0)
4473     FAIL;
4474
4475   temp1 = gen_reg_rtx (DImode);
4476   temp2 = gen_reg_rtx (DImode);
4477
4478   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
4479   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
4480   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
4481   DONE;
4482 }")
4483
4484 (define_insn ""
4485   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4486         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4487                 (match_operand:DI 2 "const_int_operand" "N")))]
4488   "TARGET_POWERPC64 && exact_log2 (INTVAL (operands[2])) >= 0"
4489   "sradi %0,%1,%p2\;addze %0,%0"
4490   [(set_attr "length" "8")])
4491
4492 (define_insn ""
4493   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4494         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4495                             (match_operand:DI 2 "const_int_operand" "N"))
4496                     (const_int 0)))
4497    (clobber (match_scratch:DI 3 "=r"))]
4498   "TARGET_POWERPC64 && exact_log2 (INTVAL (operands[2])) >= 0"
4499   "sradi %3,%1,%p2\;addze. %3,%3"
4500   [(set_attr "type" "compare")
4501    (set_attr "length" "8")])
4502
4503 (define_insn ""
4504   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4505         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4506                             (match_operand:DI 2 "const_int_operand" "N"))
4507                     (const_int 0)))
4508    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4509         (div:DI (match_dup 1) (match_dup 2)))]
4510   "TARGET_POWERPC64 && exact_log2 (INTVAL (operands[2])) >= 0"
4511   "sradi %0,%1,%p2\;addze. %0,%0"
4512   [(set_attr "type" "compare")
4513    (set_attr "length" "8")])
4514
4515 (define_insn ""
4516   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4517         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4518                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
4519   "TARGET_POWERPC64"
4520   "divd %0,%1,%2"
4521   [(set_attr "type" "idiv")])
4522
4523 (define_insn "udivdi3"
4524   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4525         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4526                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
4527   "TARGET_POWERPC64"
4528   "divdu %0,%1,%2"
4529   [(set_attr "type" "idiv")])
4530
4531 (define_insn "rotldi3"
4532   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4533         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4534                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
4535   "TARGET_POWERPC64"
4536   "rld%I2cl %0,%1,%H2,0")
4537
4538 (define_insn ""
4539   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4540         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4541                                (match_operand:DI 2 "reg_or_cint_operand" "ri"))
4542                     (const_int 0)))
4543    (clobber (match_scratch:DI 3 "=r"))]
4544   "TARGET_POWERPC64"
4545   "rld%I2cl. %3,%1,%H2,0"
4546   [(set_attr "type" "delayed_compare")])
4547
4548 (define_insn ""
4549   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4550         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4551                                (match_operand:DI 2 "reg_or_cint_operand" "ri"))
4552                     (const_int 0)))
4553    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4554         (rotate:DI (match_dup 1) (match_dup 2)))]
4555   "TARGET_POWERPC64"
4556   "rld%I2cl. %0,%1,%H2,0"
4557   [(set_attr "type" "delayed_compare")])
4558
4559 (define_expand "ashldi3"
4560   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4561         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
4562                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
4563   "TARGET_POWERPC64 || TARGET_POWER"
4564   "
4565 {
4566   if (TARGET_POWERPC64)
4567     ;
4568   else if (TARGET_POWER)
4569     {
4570       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
4571       DONE;
4572     }
4573   else
4574     FAIL;
4575 }")
4576
4577 (define_insn ""
4578   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4579         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4580                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4581   "TARGET_POWERPC64"
4582   "sld%I2 %0,%1,%H2"
4583   [(set_attr "length" "8")])
4584   
4585 (define_insn ""
4586   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4587         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4588                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4589                     (const_int 0)))
4590    (clobber (match_scratch:DI 3 "=r"))]
4591   "TARGET_POWERPC64"
4592   "sld%I2. %3,%1,%H2"
4593   [(set_attr "type" "delayed_compare")])
4594   
4595 (define_insn ""
4596   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4597         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4598                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4599                     (const_int 0)))
4600    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4601         (ashift:DI (match_dup 1) (match_dup 2)))]
4602   "TARGET_POWERPC64"
4603   "sld%I2. %0,%1,%H2"
4604   [(set_attr "type" "delayed_compare")])
4605
4606 (define_expand "lshrdi3"
4607   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4608         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
4609                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4610   "TARGET_POWERPC64 || TARGET_POWER"
4611   "
4612 {
4613   if (TARGET_POWERPC64)
4614     ;
4615   else if (TARGET_POWER)
4616     {
4617       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
4618       DONE;
4619     }
4620   else
4621     FAIL;
4622 }")
4623
4624 (define_insn ""
4625   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4626         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4627                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4628   "TARGET_POWERPC64"
4629   "srd%I2 %0,%1,%H2")
4630
4631 (define_insn ""
4632   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4633         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4634                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4635                     (const_int 0)))
4636    (clobber (match_scratch:DI 3 "=r"))]
4637   "TARGET_POWERPC64"
4638   "srd%I2. %3,%1,%H2"
4639   [(set_attr "type" "delayed_compare")])
4640
4641 (define_insn ""
4642   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4643         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4644                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4645                     (const_int 0)))
4646    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4647         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
4648   "TARGET_POWERPC64"
4649   "srd%I2. %0,%1,%H2"
4650   [(set_attr "type" "delayed_compare")])
4651
4652 (define_expand "ashrdi3"
4653   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4654         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
4655                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4656   "TARGET_POWERPC64 || TARGET_POWER"
4657   "
4658 {
4659   if (TARGET_POWERPC64)
4660     ;
4661   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
4662     {
4663       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
4664       DONE;
4665     }
4666   else
4667     FAIL;
4668 }")
4669
4670 (define_insn ""
4671   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4672         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4673                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4674   "TARGET_POWERPC64"
4675   "srad%I2 %0,%1,%H2")
4676
4677 (define_insn ""
4678   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4679         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4680                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4681                     (const_int 0)))
4682    (clobber (match_scratch:DI 3 "=r"))]
4683   "TARGET_POWERPC64"
4684   "srad%I2. %3,%1,%H2"
4685   [(set_attr "type" "delayed_compare")])
4686
4687 (define_insn ""
4688   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4689         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4690                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4691                     (const_int 0)))
4692    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4693         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
4694   "TARGET_POWERPC64"
4695   "srad%I2. %0,%1,%H2"
4696   [(set_attr "type" "delayed_compare")])
4697
4698 (define_insn "anddi3"
4699   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
4700         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
4701                 (match_operand:DI 2 "and_operand" "?r,K,J")))
4702    (clobber (match_scratch:CC 3 "=X,x,x"))]
4703   "TARGET_POWERPC64"
4704   "@
4705    and %0,%1,%2
4706    andi. %0,%1,%b2
4707    andis. %0,%1,%u2")
4708
4709 (define_insn ""
4710   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x")
4711         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
4712                             (match_operand:DI 2 "and_operand" "r,K,J"))
4713                     (const_int 0)))
4714    (clobber (match_scratch:DI 3 "=r,r,r"))]
4715   "TARGET_POWERPC64"
4716   "@
4717    and. %3,%1,%2
4718    andi. %3,%1,%b2
4719    andis. %3,%1,%u2"
4720   [(set_attr "type" "compare,compare,compare")])
4721
4722 (define_insn ""
4723   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x")
4724         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
4725                             (match_operand:DI 2 "and_operand" "r,K,J"))
4726                     (const_int 0)))
4727    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
4728         (and:DI (match_dup 1) (match_dup 2)))]
4729   "TARGET_POWERPC64"
4730   "@
4731    and. %0,%1,%2
4732    andi. %0,%1,%b2
4733    andis. %0,%1,%u2"
4734   [(set_attr "type" "compare,compare,compare")])
4735
4736 ;; Take a AND with a constant that cannot be done in a single insn and try to
4737 ;; split it into two insns.  This does not verify that the insns are valid
4738 ;; since this need not be done as combine will do it.
4739
4740 (define_split
4741   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4742         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
4743                 (match_operand:DI 2 "non_and_cint_operand" "")))]
4744   "TARGET_POWERPC64"
4745   [(set (match_dup 0) (and:DI (match_dup 1) (match_dup 3)))
4746    (set (match_dup 0) (and:DI (match_dup 0) (match_dup 4)))]
4747   "
4748 {
4749   int maskval = INTVAL (operands[2]);
4750   int i, transitions, last_bit_value;
4751   int orig = maskval, first_c = maskval, second_c;
4752
4753   /* We know that MASKVAL must have more than 2 bit-transitions.  Start at
4754      the low-order bit and count for the third transition.  When we get there,
4755      make a first mask that has everything to the left of that position
4756      a one.  Then make the second mask to turn off whatever else is needed.  */
4757
4758   for (i = 1, transitions = 0, last_bit_value = maskval & 1; i < 32; i++)
4759     {
4760       if (((maskval >>= 1) & 1) != last_bit_value)
4761         last_bit_value ^= 1, transitions++;
4762
4763       if (transitions > 2)
4764         {
4765           first_c |= (~0) << i;
4766           break;
4767         }
4768     }
4769
4770   second_c = orig | ~ first_c;
4771
4772   operands[3] = gen_rtx (CONST_INT, VOIDmode, first_c);
4773   operands[4] = gen_rtx (CONST_INT, VOIDmode, second_c);
4774 }")
4775
4776 (define_insn "iordi3"
4777   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
4778         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
4779                 (match_operand:DI 2 "logical_operand" "r,K,J")))]
4780   "TARGET_POWERPC64"
4781   "@
4782    or %0,%1,%2
4783    ori %0,%1,%b2
4784    oris %0,%1,%u2")
4785
4786 (define_insn ""
4787   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4788         (compare:CC (ior:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4789                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4790                     (const_int 0)))
4791    (clobber (match_scratch:DI 3 "=r"))]
4792   "TARGET_POWERPC64"
4793   "or. %3,%1,%2"
4794   [(set_attr "type" "compare")])
4795
4796 (define_insn ""
4797   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4798         (compare:CC (ior:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4799                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4800                     (const_int 0)))
4801    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4802         (ior:DI (match_dup 1) (match_dup 2)))]
4803   "TARGET_POWERPC64"
4804   "or. %0,%1,%2"
4805   [(set_attr "type" "compare")])
4806
4807 ;; Split an IOR that we can't do in one insn into two insns, each of which
4808 ;; does one 16-bit part.  This is used by combine.
4809
4810 (define_split
4811   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4812         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
4813                 (match_operand:DI 2 "non_logical_cint_operand" "")))]
4814   "TARGET_POWERPC64"
4815   [(set (match_dup 0) (ior:DI (match_dup 1) (match_dup 3)))
4816    (set (match_dup 0) (ior:DI (match_dup 0) (match_dup 4)))]
4817 "
4818 {
4819   operands[3] = gen_rtx (CONST_INT, VOIDmode,
4820                          INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
4821   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
4822 }")
4823
4824 (define_insn "xordi3"
4825   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
4826         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
4827                 (match_operand:DI 2 "logical_operand" "r,K,J")))]
4828   "TARGET_POWERPC64"
4829   "@
4830    xor %0,%1,%2
4831    xori %0,%1,%b2
4832    xoris %0,%1,%u2")
4833
4834 (define_insn ""
4835   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4836         (compare:CC (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4837                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4838                     (const_int 0)))
4839    (clobber (match_scratch:DI 3 "=r"))]
4840   "TARGET_POWERPC64"
4841   "xor. %3,%1,%2"
4842   [(set_attr "type" "compare")])
4843
4844 (define_insn ""
4845   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4846         (compare:CC (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4847                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4848                     (const_int 0)))
4849    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4850         (xor:DI (match_dup 1) (match_dup 2)))]
4851   "TARGET_POWERPC64"
4852   "xor. %0,%1,%2"
4853   [(set_attr "type" "compare")])
4854
4855 ;; Split an XOR that we can't do in one insn into two insns, each of which
4856 ;; does one 16-bit part.  This is used by combine.
4857
4858 (define_split
4859   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4860         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
4861                 (match_operand:DI 2 "non_logical_cint_operand" "")))]
4862   "TARGET_POWERPC64"
4863   [(set (match_dup 0) (xor:DI (match_dup 1) (match_dup 3)))
4864    (set (match_dup 0) (xor:DI (match_dup 0) (match_dup 4)))]
4865 "
4866 {
4867   operands[3] = gen_rtx (CONST_INT, VOIDmode,
4868                          INTVAL (operands[2]) & 0xffff0000);
4869   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
4870 }")
4871
4872 (define_insn ""
4873   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4874         (not:DI (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4875                         (match_operand:DI 2 "gpc_reg_operand" "r"))))]
4876    "TARGET_POWERPC64"
4877    "eqv %0,%1,%2")
4878
4879 (define_insn ""
4880   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4881         (compare:CC (not:DI (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4882                                     (match_operand:DI 2 "gpc_reg_operand" "r")))
4883                     (const_int 0)))
4884    (clobber (match_scratch:DI 3 "=r"))]
4885    "TARGET_POWERPC64"
4886    "eqv. %3,%1,%2"
4887    [(set_attr "type" "compare")])
4888
4889 (define_insn ""
4890   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4891         (compare:CC (not:DI (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4892                                     (match_operand:DI 2 "gpc_reg_operand" "r")))
4893                     (const_int 0)))
4894    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4895         (not:DI (xor:DI (match_dup 1) (match_dup 2))))]
4896    "TARGET_POWERPC64"
4897    "eqv. %0,%1,%2"
4898    [(set_attr "type" "compare")])
4899
4900 (define_insn ""
4901   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4902         (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4903                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
4904   "TARGET_POWERPC64"
4905   "andc %0,%2,%1")
4906
4907 (define_insn ""
4908   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4909         (compare:CC (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4910                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4911                     (const_int 0)))
4912    (clobber (match_scratch:DI 3 "=r"))]
4913   "TARGET_POWERPC64"
4914   "andc. %3,%2,%1"
4915   [(set_attr "type" "compare")])
4916
4917 (define_insn ""
4918   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4919         (compare:CC (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4920                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4921                     (const_int 0)))
4922    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4923         (and:DI (not:DI (match_dup 1)) (match_dup 2)))]
4924   "TARGET_POWERPC64"
4925   "andc. %0,%2,%1"
4926   [(set_attr "type" "compare")])
4927
4928 (define_insn ""
4929   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4930         (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4931                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
4932   "TARGET_POWERPC64"
4933   "orc %0,%2,%1")
4934
4935 (define_insn ""
4936   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4937         (compare:CC (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4938                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4939                     (const_int 0)))
4940    (clobber (match_scratch:DI 3 "=r"))]
4941   "TARGET_POWERPC64"
4942   "orc. %3,%2,%1"
4943   [(set_attr "type" "compare")])
4944
4945 (define_insn ""
4946   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4947         (compare:CC (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4948                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4949                     (const_int 0)))
4950    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4951         (ior:DI (not:DI (match_dup 1)) (match_dup 2)))]
4952   "TARGET_POWERPC64"
4953   "orc. %0,%2,%1"
4954   [(set_attr "type" "compare")])
4955
4956 (define_insn ""
4957   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4958         (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4959                 (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))))]
4960   "TARGET_POWERPC64"
4961   "nand %0,%1,%2")
4962
4963 (define_insn ""
4964   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4965         (compare:CC (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4966                             (not:DI (match_operand:DI 2 "gpc_reg_operand" "r")))
4967                     (const_int 0)))
4968    (clobber (match_scratch:DI 3 "=r"))]
4969   "TARGET_POWERPC64"
4970   "nand. %3,%1,%2"
4971   [(set_attr "type" "compare")])
4972
4973 (define_insn ""
4974   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4975         (compare:CC (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4976                             (not:DI (match_operand:DI 2 "gpc_reg_operand" "r")))
4977                     (const_int 0)))
4978    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4979         (ior:DI (not:DI (match_dup 1)) (not:DI (match_dup 2))))]
4980   "TARGET_POWERPC64"
4981   "nand. %0,%1,%2"
4982   [(set_attr "type" "compare")])
4983
4984 (define_insn ""
4985   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4986         (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4987                 (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))))]
4988   "TARGET_POWERPC64"
4989   "nor %0,%1,%2")
4990
4991 (define_insn ""
4992   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4993         (compare:CC (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4994                             (not:DI (match_operand:DI 2 "gpc_reg_operand" "r")))
4995                     (const_int 0)))
4996    (clobber (match_scratch:DI 3 "=r"))]
4997   "TARGET_POWERPC64"
4998   "nor. %3,%1,%2"
4999   [(set_attr "type" "compare")])
5000
5001 (define_insn ""
5002   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
5003         (compare:CC (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
5004                             (not:DI (match_operand:DI 2 "gpc_reg_operand" "r")))
5005                     (const_int 0)))
5006    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
5007         (and:DI (not:DI (match_dup 1)) (not:DI (match_dup 2))))]
5008   "TARGET_POWERPC64"
5009   "nor. %0,%1,%2"
5010   [(set_attr "type" "compare")])
5011 \f
5012 ;; Now define ways of moving data around.
5013
5014 ;; Elf specific ways of loading addresses for non-PIC code.
5015 ;; The output of this could be r0, but we limit it to base
5016 ;; registers, since almost all uses of this will need it
5017 ;; in a base register shortly.
5018 (define_insn "elf_high"
5019   [(set (match_operand:SI 0 "register_operand" "=b")
5020         (high:SI (match_operand 1 "" "")))]
5021   "TARGET_ELF && !TARGET_64BIT"
5022   "{cau|addis} %0,0,%1@ha")
5023
5024 (define_insn "elf_low"
5025   [(set (match_operand:SI 0 "register_operand" "=r")
5026         (lo_sum:SI (match_operand:SI 1 "register_operand" "b")
5027                    (match_operand 2 "" "")))]
5028    "TARGET_ELF && !TARGET_64BIT"
5029    "{cal %0,%a2@l(%1)|addi %0,%1,%2@l}")
5030
5031 ;; Set up a register with a value from the GOT table
5032
5033 (define_expand "movsi_got"
5034   [(set (match_operand:SI 0 "register_operand" "")
5035         (unspec [(match_operand:SI 1 "got_operand" "")
5036                  (match_dup 2)] 8))]
5037   "(DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) && flag_pic == 1"
5038   "
5039 {
5040   if (GET_CODE (operands[1]) == CONST)
5041     {
5042       rtx offset = const0_rtx;
5043       HOST_WIDE_INT value;
5044
5045       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
5046       value = INTVAL (offset);
5047       if (value != 0)
5048         {
5049           rtx tmp = ((reload_in_progress || reload_completed)
5050                      ? operands[0]
5051                      : gen_reg_rtx (Pmode));
5052           emit_insn (gen_movsi_got (tmp, operands[1]));
5053           emit_insn (gen_addsi3 (operands[0], tmp, offset));
5054           DONE;
5055         }
5056     }
5057
5058   operands[2] = rs6000_got_register (operands[1]);
5059 }")
5060
5061 (define_insn "*movsi_got_internal"
5062   [(set (match_operand:SI 0 "register_operand" "=r")
5063         (unspec [(match_operand:SI 1 "got_no_const_operand" "")
5064                  (match_operand:SI 2 "register_operand" "b")] 8))]
5065   "(DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) && flag_pic == 1"
5066   "{l|lwz} %0,%a1@got(%2)"
5067   [(set_attr "type" "load")])
5068
5069 ;; For SI, we special-case integers that can't be loaded in one insn.  We
5070 ;; do the load 16-bits at a time.  We could do this by loading from memory,
5071 ;; and this is even supposed to be faster, but it is simpler not to get
5072 ;; integers in the TOC.
5073 (define_expand "movsi"
5074   [(set (match_operand:SI 0 "general_operand" "")
5075         (match_operand:SI 1 "any_operand" ""))]
5076   ""
5077   "
5078 {
5079   if (GET_CODE (operands[0]) != REG)
5080     operands[1] = force_reg (SImode, operands[1]);
5081
5082   /* Convert a move of a CONST_DOUBLE into a CONST_INT */
5083   if (GET_CODE (operands[1]) == CONST_DOUBLE)
5084     operands[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
5085
5086   /* Use default pattern for address of ELF small data */
5087   if (TARGET_ELF
5088       && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5089       && (GET_CODE (operands[1]) == SYMBOL_REF || GET_CODE (operands[1]) == CONST)
5090       && small_data_operand (operands[1], SImode))
5091     {
5092       emit_insn (gen_rtx (SET, VOIDmode, operands[0], operands[1]));
5093       DONE;
5094     }
5095
5096   if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5097       && flag_pic == 1 && got_operand (operands[1], SImode))
5098     {
5099       emit_insn (gen_movsi_got (operands[0], operands[1]));
5100       DONE;
5101     }
5102
5103   if (TARGET_ELF && TARGET_NO_TOC && !TARGET_64BIT
5104       && !flag_pic
5105       && CONSTANT_P (operands[1])
5106       && GET_CODE (operands[1]) != HIGH
5107       && GET_CODE (operands[1]) != CONST_INT)
5108     {
5109       rtx target = (reload_completed || reload_in_progress)
5110                         ? operands[0] : gen_reg_rtx (SImode);
5111
5112       /* If this is a function address on -mcall-aixdesc or -mcall-nt,
5113          convert it to the address of the descriptor.  */
5114       if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
5115           && GET_CODE (operands[1]) == SYMBOL_REF
5116           && XSTR (operands[1], 0)[0] == '.')
5117         {
5118           char *name = XSTR (operands[1], 0);
5119           rtx new_ref;
5120           while (*name == '.')
5121             name++;
5122           new_ref = gen_rtx (SYMBOL_REF, Pmode, name);
5123           CONSTANT_POOL_ADDRESS_P (new_ref) = CONSTANT_POOL_ADDRESS_P (operands[1]);
5124           SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]);
5125           SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
5126           operands[1] = new_ref;
5127         }
5128
5129       emit_insn (gen_elf_high (target, operands[1]));
5130       emit_insn (gen_elf_low (operands[0], target, operands[1]));
5131       DONE;
5132     }
5133
5134   if (GET_CODE (operands[1]) == CONST
5135       && DEFAULT_ABI == ABI_NT
5136       && !side_effects_p (operands[0]))
5137     {
5138       rtx const_term = const0_rtx;
5139       rtx sym = eliminate_constant_term (XEXP (operands[1], 0), &const_term);
5140       if (sym && GET_CODE (const_term) == CONST_INT
5141           && (GET_CODE (sym) == SYMBOL_REF || GET_CODE (sym) == LABEL_REF))
5142         {
5143           unsigned HOST_WIDE_INT value = INTVAL (const_term);
5144           int new_reg_p = (flag_expensive_optimizations
5145                            && !reload_completed
5146                            && !reload_in_progress);
5147           rtx tmp1 = (new_reg_p && value != 0) ? gen_reg_rtx (SImode) : operands[0];
5148
5149           emit_insn (gen_movsi (tmp1, sym));
5150           if (INTVAL (const_term) != 0)
5151             emit_insn (gen_addsi3 (operands[0], tmp1, GEN_INT (value)));
5152           DONE;
5153         }
5154       else
5155         fatal_insn (\"bad address\", operands[1]);
5156     }
5157
5158   if ((!TARGET_WINDOWS_NT || DEFAULT_ABI != ABI_NT)
5159       && CONSTANT_P (operands[1])
5160       && GET_CODE (operands[1]) != CONST_INT
5161       && GET_CODE (operands[1]) != HIGH
5162       && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1]))
5163     {
5164       /* Emit a USE operation so that the constant isn't deleted if
5165          expensive optimizations are turned on because nobody
5166          references it.  This should only be done for operands that
5167          contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
5168          This should not be done for operands that contain LABEL_REFs.
5169          For now, we just handle the obvious case.  */
5170       if (GET_CODE (operands[1]) != LABEL_REF)
5171         emit_insn (gen_rtx (USE, VOIDmode, operands[1]));
5172
5173       /* If we are to limit the number of things we put in the TOC and
5174          this is a symbol plus a constant we can add in one insn,
5175          just put the symbol in the TOC and add the constant.  Don't do
5176          this if reload is in progress.  */
5177       if (GET_CODE (operands[1]) == CONST
5178           && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
5179           && GET_CODE (XEXP (operands[1], 0)) == PLUS
5180           && add_operand (XEXP (XEXP (operands[1], 0), 1), SImode)
5181           && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
5182               || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
5183           && ! side_effects_p (operands[0]))
5184         {
5185           rtx sym = force_const_mem (SImode, XEXP (XEXP (operands[1], 0), 0));
5186           rtx other = XEXP (XEXP (operands[1], 0), 1);
5187
5188           emit_insn (gen_addsi3 (operands[0], force_reg (SImode, sym), other));
5189           DONE;
5190         }
5191
5192       operands[1] = force_const_mem (SImode, operands[1]);
5193       if (! memory_address_p (SImode, XEXP (operands[1], 0))
5194           && ! reload_in_progress)
5195         operands[1] = change_address (operands[1], SImode,
5196                                       XEXP (operands[1], 0));
5197     }
5198 }")
5199
5200 (define_insn ""
5201   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,r,m,r,r,r,r,r,*q,*c*l,*h")
5202         (match_operand:SI 1 "input_operand" "r,S,T,U,m,r,I,J,n,R,*h,r,r,0"))]
5203   "gpc_reg_operand (operands[0], SImode)
5204    || gpc_reg_operand (operands[1], SImode)"
5205   "@
5206    mr %0,%1
5207    {l|lwz} %0,[toc]%1(2)
5208    {l|lwz} %0,[toc]%l1(2)
5209    {cal|la} %0,%a1
5210    {l%U1%X1|lwz%U1%X1} %0,%1
5211    {st%U0%X0|stw%U0%X0} %1,%0
5212    {lil|li} %0,%1
5213    {liu|lis} %0,%v1
5214    #
5215    {cal|la} %0,%1(%*)
5216    mf%1 %0
5217    mt%0 %1
5218    mt%0 %1
5219    cror 0,0,0"
5220   [(set_attr "type" "*,load,load,*,load,store,*,*,*,*,*,*,mtjmpr,*")
5221    (set_attr "length" "4,4,4,4,4,4,4,4,8,4,4,4,4,4")])
5222
5223 ;; Split a load of a large constant into the appropriate two-insn
5224 ;; sequence.
5225
5226 (define_split
5227   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5228         (match_operand:SI 1 "const_int_operand" ""))]
5229   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
5230    && (INTVAL (operands[1]) & 0xffff) != 0"
5231   [(set (match_dup 0)
5232         (match_dup 2))
5233    (set (match_dup 0)
5234         (ior:SI (match_dup 0)
5235                 (match_dup 3)))]
5236   "
5237 {
5238   operands[2] = gen_rtx (CONST_INT, VOIDmode,
5239                          INTVAL (operands[1]) & 0xffff0000);
5240   operands[3] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[1]) & 0xffff);
5241 }")
5242
5243 (define_insn ""
5244   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
5245         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
5246                     (const_int 0)))
5247    (set (match_operand:SI 0 "gpc_reg_operand" "=r") (match_dup 1))]
5248   ""
5249   "mr. %0,%1"
5250   [(set_attr "type" "compare")])
5251 \f
5252 (define_expand "movhi"
5253   [(set (match_operand:HI 0 "general_operand" "")
5254         (match_operand:HI 1 "any_operand" ""))]
5255   ""
5256   "
5257 {
5258   if (GET_CODE (operands[0]) != REG)
5259     operands[1] = force_reg (HImode, operands[1]);
5260
5261   if (CONSTANT_P (operands[1]) && GET_CODE (operands[1]) != CONST_INT)
5262     {
5263       operands[1] = force_const_mem (HImode, operands[1]);
5264       if (! memory_address_p (HImode, XEXP (operands[1], 0))
5265           && ! reload_in_progress)
5266         operands[1] = change_address (operands[1], HImode,
5267                                       XEXP (operands[1], 0));
5268     }
5269 }")
5270
5271 (define_insn ""
5272   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
5273         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
5274   "gpc_reg_operand (operands[0], HImode)
5275    || gpc_reg_operand (operands[1], HImode)"
5276   "@
5277    mr %0,%1
5278    lhz%U1%X1 %0,%1
5279    sth%U0%X0 %1,%0
5280    {lil|li} %0,%w1
5281    mf%1 %0
5282    mt%0 %1
5283    mt%0 %1
5284    cror 0,0,0"
5285   [(set_attr "type" "*,load,store,*,*,*,mtjmpr,*")])
5286
5287 (define_expand "movqi"
5288   [(set (match_operand:QI 0 "general_operand" "")
5289         (match_operand:QI 1 "any_operand" ""))]
5290   ""
5291   "
5292 {
5293   if (GET_CODE (operands[0]) != REG)
5294     operands[1] = force_reg (QImode, operands[1]);
5295
5296   if (CONSTANT_P (operands[1]) && GET_CODE (operands[1]) != CONST_INT)
5297     {
5298       operands[1] = force_const_mem (QImode, operands[1]);
5299       if (! memory_address_p (QImode, XEXP (operands[1], 0))
5300           && ! reload_in_progress)
5301         operands[1] = change_address (operands[1], QImode,
5302                                       XEXP (operands[1], 0));
5303     }
5304 }")
5305
5306 (define_insn ""
5307   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
5308         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
5309   "gpc_reg_operand (operands[0], QImode)
5310    || gpc_reg_operand (operands[1], QImode)"
5311   "@
5312    mr %0,%1
5313    lbz%U1%X1 %0,%1
5314    stb%U0%X0 %1,%0
5315    {lil|li} %0,%1
5316    mf%1 %0
5317    mt%0 %1
5318    mt%0 %1
5319    cror 0,0,0"
5320   [(set_attr "type" "*,load,store,*,*,*,mtjmpr,*")])
5321 \f
5322 ;; Here is how to move condition codes around.  When we store CC data in
5323 ;; an integer register or memory, we store just the high-order 4 bits.
5324 ;; This lets us not shift in the most common case of CR0.
5325 (define_expand "movcc"
5326   [(set (match_operand:CC 0 "nonimmediate_operand" "")
5327         (match_operand:CC 1 "nonimmediate_operand" ""))]
5328   ""
5329   "")
5330
5331 (define_insn ""
5332   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,y,r,r,r,r,m")
5333         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,m,r"))]
5334   "register_operand (operands[0], CCmode)
5335    || register_operand (operands[1], CCmode)"
5336   "@
5337    mcrf %0,%1
5338    mtcrf 128,%1
5339    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
5340    mfcr %0
5341    mfcr %0\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
5342    mr %0,%1
5343    {l%U1%X1|lwz%U1%X1} %0,%1
5344    {st%U0%U1|stw%U0%U1} %1,%0"
5345   [(set_attr "type" "*,*,*,compare,*,*,load,store")
5346    (set_attr "length" "*,*,12,*,8,*,*,*")])
5347 \f
5348 ;; For floating-point, we normally deal with the floating-point registers
5349 ;; unless -msoft-float is used.  The sole exception is that parameter passing
5350 ;; can produce floating-point values in fixed-point registers.  Unless the
5351 ;; value is a simple constant or already in memory, we deal with this by
5352 ;; allocating memory and copying the value explicitly via that memory location.
5353 (define_expand "movsf"
5354   [(set (match_operand:SF 0 "nonimmediate_operand" "")
5355         (match_operand:SF 1 "any_operand" ""))]
5356   ""
5357   "
5358 {
5359   /* If we are called from reload, we might be getting a SUBREG of a hard
5360      reg.  So expand it.  */
5361   if (GET_CODE (operands[0]) == SUBREG
5362       && GET_CODE (SUBREG_REG (operands[0])) == REG
5363       && REGNO (SUBREG_REG (operands[0])) < FIRST_PSEUDO_REGISTER)
5364     operands[0] = alter_subreg (operands[0]);
5365   if (GET_CODE (operands[1]) == SUBREG
5366       && GET_CODE (SUBREG_REG (operands[1])) == REG
5367       && REGNO (SUBREG_REG (operands[1])) < FIRST_PSEUDO_REGISTER)
5368     operands[1] = alter_subreg (operands[1]);
5369
5370   if (TARGET_SOFT_FLOAT && GET_CODE (operands[0]) == MEM)
5371     operands[1] = force_reg (SFmode, operands[1]);
5372
5373   else if (TARGET_HARD_FLOAT)
5374     {
5375       if (GET_CODE (operands[1]) == REG && REGNO (operands[1]) < 32)
5376         {
5377           /* If this is a store to memory or another integer register do the
5378              move directly.  Otherwise store to a temporary stack slot and
5379              load from there into a floating point register.  */
5380
5381           if (GET_CODE (operands[0]) == MEM
5382               || (GET_CODE (operands[0]) == REG
5383                   && (REGNO (operands[0]) < 32
5384                       || (reload_in_progress
5385                           && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER))))
5386             {
5387               emit_move_insn (operand_subword (operands[0], 0, 0, SFmode),
5388                               operand_subword (operands[1], 0, 0, SFmode));
5389               DONE;
5390             }
5391           else
5392             {
5393               rtx stack_slot = assign_stack_temp (SFmode, 4, 0);
5394
5395               emit_move_insn (stack_slot, operands[1]);
5396               emit_move_insn (operands[0], stack_slot);
5397               DONE;
5398             }
5399         }
5400
5401       if (GET_CODE (operands[0]) == MEM)
5402         {
5403           /* If operands[1] is a register, it may have double-precision data
5404              in it, so truncate it to single precision.  We need not do
5405              this for POWERPC.  */
5406           if (! TARGET_POWERPC && TARGET_HARD_FLOAT
5407               && GET_CODE (operands[1]) == REG)
5408             {
5409               rtx newreg
5410                 = reload_in_progress ? operands[1] : gen_reg_rtx (SFmode);
5411               emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
5412               operands[1] = newreg;
5413             }
5414
5415           operands[1] = force_reg (SFmode, operands[1]);
5416         }
5417
5418       if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) < 32)
5419         {
5420           if (GET_CODE (operands[1]) == MEM
5421 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && ! defined(REAL_IS_NOT_DOUBLE)
5422               || GET_CODE (operands[1]) == CONST_DOUBLE
5423 #endif
5424               || (GET_CODE (operands[1]) == REG
5425                   && (REGNO (operands[1]) < 32
5426                       || (reload_in_progress
5427                           && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER))))
5428             {
5429               emit_move_insn (operand_subword (operands[0], 0, 0, SFmode),
5430                               operand_subword (operands[1], 0, 0, SFmode));
5431               DONE;
5432             }
5433           else
5434             {
5435               rtx stack_slot = assign_stack_temp (SFmode, 4, 0);
5436
5437               emit_move_insn (stack_slot, operands[1]);
5438               emit_move_insn (operands[0], stack_slot);
5439               DONE;
5440             }
5441         }
5442     }
5443
5444   if (CONSTANT_P (operands[1]) && TARGET_HARD_FLOAT)
5445     {
5446       operands[1] = force_const_mem (SFmode, operands[1]);
5447       if (! memory_address_p (SFmode, XEXP (operands[1], 0))
5448           && ! reload_in_progress)
5449         operands[1] = change_address (operands[1], SFmode,
5450                                       XEXP (operands[1], 0));
5451     }
5452 }")
5453
5454 (define_split
5455   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5456         (match_operand:SF 1 "const_double_operand" ""))]
5457   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], SFmode) <= 1
5458    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
5459        || (GET_CODE (operands[0]) == SUBREG
5460            && GET_CODE (SUBREG_REG (operands[0])) == REG
5461            && REGNO (SUBREG_REG (operands[0])) <= 31))"
5462   [(set (match_dup 2) (match_dup 3))]
5463   "
5464 {
5465   long l;
5466   REAL_VALUE_TYPE rv;
5467
5468   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
5469   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
5470
5471   operands[2] = operand_subword (operands[0], 0, 0, SFmode);
5472   operands[3] = GEN_INT(l);
5473 }")
5474
5475 (define_split
5476   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5477         (match_operand:SF 1 "const_double_operand" ""))]
5478   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], SFmode) == 2
5479    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
5480        || (GET_CODE (operands[0]) == SUBREG
5481            && GET_CODE (SUBREG_REG (operands[0])) == REG
5482            && REGNO (SUBREG_REG (operands[0])) <= 31))"
5483   [(set (match_dup 2) (match_dup 3))
5484    (set (match_dup 2) (ior:SI (match_dup 2) (match_dup 4)))]
5485   "
5486 {
5487   long l;
5488   REAL_VALUE_TYPE rv;
5489
5490   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
5491   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
5492
5493   operands[2] = operand_subword (operands[0], 0, 0, SFmode);
5494   operands[3] = GEN_INT(l & 0xffff0000);
5495   operands[4] = GEN_INT(l & 0x0000ffff);
5496 }")
5497
5498 (define_insn "*movsf_hardfloat"
5499   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,m,!r,!r")
5500         (match_operand:SF 1 "input_operand" "f,m,f,G,Fn"))]
5501   "(gpc_reg_operand (operands[0], SFmode)
5502    || gpc_reg_operand (operands[1], SFmode)) && TARGET_HARD_FLOAT"
5503   "@
5504    fmr %0,%1
5505    lfs%U1%X1 %0,%1
5506    stfs%U0%X0 %1,%0
5507    #
5508    #"
5509   [(set_attr "type" "fp,fpload,fpstore,*,*")
5510    (set_attr "length" "4,4,4,4,8")])
5511
5512 (define_insn "*movsf_softfloat"
5513   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,r")
5514         (match_operand:SF 1 "input_operand" "r,m,r,I,J,R,G,Fn"))]
5515   "(gpc_reg_operand (operands[0], SFmode)
5516    || gpc_reg_operand (operands[1], SFmode)) && TARGET_SOFT_FLOAT"
5517   "@
5518    mr %0,%1
5519    {l%U1%X1|lwz%U1%X1} %0,%1
5520    {st%U0%X0|stw%U0%X0} %1,%0
5521    {lil|li} %0,%1
5522    {liu|lis} %0,%v1
5523    {cal|la} %0,%1(%*)
5524    #
5525    #"
5526   [(set_attr "type" "*,load,store,*,*,*,*,*")
5527    (set_attr "length" "4,4,4,4,4,4,4,8")])
5528
5529 \f
5530 (define_expand "movdf"
5531   [(set (match_operand:DF 0 "nonimmediate_operand" "")
5532         (match_operand:DF 1 "any_operand" ""))]
5533   ""
5534   "
5535 {
5536   if (GET_CODE (operands[0]) != REG)
5537     operands[1] = force_reg (DFmode, operands[1]);
5538
5539       /* Stores between FPR and any non-FPR registers must go through a
5540          temporary stack slot.  */
5541
5542   if (TARGET_POWERPC64
5543       && GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == REG
5544       && ((FP_REGNO_P (REGNO (operands[0]))
5545            && ! FP_REGNO_P (REGNO (operands[1])))
5546           || (FP_REGNO_P (REGNO (operands[1]))
5547               && ! FP_REGNO_P (REGNO (operands[0])))))
5548     {
5549       rtx stack_slot = assign_stack_temp (DFmode, 8, 0);
5550
5551       emit_move_insn (stack_slot, operands[1]);
5552       emit_move_insn (operands[0], stack_slot);
5553       DONE;
5554     }
5555
5556   if (CONSTANT_P (operands[1]) && ! easy_fp_constant (operands[1], DFmode))
5557     {
5558       operands[1] = force_const_mem (DFmode, operands[1]);
5559       if (! memory_address_p (DFmode, XEXP (operands[1], 0))
5560           && ! reload_in_progress)
5561         operands[1] = change_address (operands[1], DFmode,
5562                                       XEXP (operands[1], 0));
5563     }
5564 }")
5565
5566 (define_split
5567   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5568         (match_operand:DF 1 "const_int_operand" ""))]
5569   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], DFmode) <= 1
5570    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
5571        || (GET_CODE (operands[0]) == SUBREG
5572            && GET_CODE (SUBREG_REG (operands[0])) == REG
5573            && REGNO (SUBREG_REG (operands[0])) <= 31))"
5574   [(set (match_dup 2) (match_dup 4))
5575    (set (match_dup 3) (match_dup 1))]
5576   "
5577 {
5578   int endian = (WORDS_BIG_ENDIAN == 0);
5579   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
5580   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
5581   operands[4] = (INTVAL (operands[1]) & 0x80000000) ? constm1_rtx : const0_rtx;
5582 }")
5583
5584 (define_split
5585   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5586         (match_operand:DF 1 "const_int_operand" ""))]
5587   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], DFmode) >= 2
5588    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
5589        || (GET_CODE (operands[0]) == SUBREG
5590            && GET_CODE (SUBREG_REG (operands[0])) == REG
5591            && REGNO (SUBREG_REG (operands[0])) <= 31))"
5592   [(set (match_dup 3) (match_dup 5))
5593    (set (match_dup 2) (match_dup 4))
5594    (set (match_dup 3) (ior:SI (match_dup 3) (match_dup 6)))]
5595   "
5596 {
5597   HOST_WIDE_INT value = INTVAL (operands[1]);
5598   int endian = (WORDS_BIG_ENDIAN == 0);
5599   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
5600   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
5601   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
5602   operands[5] = GEN_INT (value & 0xffff0000);
5603   operands[6] = GEN_INT (value & 0x0000ffff);
5604 }")
5605
5606 (define_split
5607   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5608         (match_operand:DF 1 "const_double_operand" ""))]
5609   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], DFmode) <= 2
5610    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
5611        || (GET_CODE (operands[0]) == SUBREG
5612            && GET_CODE (SUBREG_REG (operands[0])) == REG
5613            && REGNO (SUBREG_REG (operands[0])) <= 31))"
5614   [(set (match_dup 2) (match_dup 4))
5615    (set (match_dup 3) (match_dup 5))]
5616   "
5617 {
5618   int endian = (WORDS_BIG_ENDIAN == 0);
5619   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
5620   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
5621
5622 #ifdef HOST_WORDS_BIG_ENDIAN
5623   operands[4] = GEN_INT (CONST_DOUBLE_LOW  (operands[1]));
5624   operands[5] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
5625 #else
5626   operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
5627   operands[5] = GEN_INT (CONST_DOUBLE_LOW  (operands[1]));
5628 #endif
5629 }")
5630
5631 (define_split
5632   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5633         (match_operand:DF 1 "const_double_operand" ""))]
5634   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], DFmode) == 3
5635    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
5636        || (GET_CODE (operands[0]) == SUBREG
5637            && GET_CODE (SUBREG_REG (operands[0])) == REG
5638            && REGNO (SUBREG_REG (operands[0])) <= 31))"
5639   [(set (match_dup 2) (match_dup 4))
5640    (set (match_dup 3) (match_dup 5))
5641    (set (match_dup 2) (ior:SI (match_dup 2) (match_dup 6)))]
5642   "
5643 {
5644   HOST_WIDE_INT high;
5645   HOST_WIDE_INT low;
5646   int endian = (WORDS_BIG_ENDIAN == 0);
5647   rtx high_reg = operand_subword (operands[0], endian, 0, DFmode);
5648   rtx low_reg  = operand_subword (operands[0], 1 - endian, 0, DFmode);
5649
5650 #ifdef HOST_WORDS_BIG_ENDIAN
5651   high = CONST_DOUBLE_LOW  (operands[1]);
5652   low  = CONST_DOUBLE_HIGH (operands[1]);
5653 #else
5654   high = CONST_DOUBLE_HIGH (operands[1]);
5655   low  = CONST_DOUBLE_LOW  (operands[1]);
5656 #endif
5657
5658   if (((unsigned HOST_WIDE_INT) (low + 0x8000) < 0x10000)
5659       || (low & 0xffff) == 0)
5660     {
5661       operands[2] = high_reg;
5662       operands[3] = low_reg;
5663       operands[4] = GEN_INT (high & 0xffff0000);
5664       operands[5] = GEN_INT (low);
5665       operands[6] = GEN_INT (high & 0x0000ffff);
5666     }
5667   else
5668     {
5669       operands[2] = low_reg;
5670       operands[3] = high_reg;
5671       operands[4] = GEN_INT (low & 0xffff0000);
5672       operands[5] = GEN_INT (high);
5673       operands[6] = GEN_INT (low & 0x0000ffff);
5674     }
5675 }")
5676
5677 (define_split
5678   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5679         (match_operand:DF 1 "const_double_operand" ""))]
5680   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], DFmode) >= 4
5681    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
5682        || (GET_CODE (operands[0]) == SUBREG
5683            && GET_CODE (SUBREG_REG (operands[0])) == REG
5684            && REGNO (SUBREG_REG (operands[0])) <= 31))"
5685   [(set (match_dup 2) (match_dup 4))
5686    (set (match_dup 3) (match_dup 5))
5687    (set (match_dup 2) (ior:SI (match_dup 2) (match_dup 6)))
5688    (set (match_dup 3) (ior:SI (match_dup 3) (match_dup 7)))]
5689   "
5690 {
5691   HOST_WIDE_INT high = CONST_DOUBLE_HIGH (operands[1]);
5692   HOST_WIDE_INT low  = CONST_DOUBLE_LOW  (operands[1]);
5693   int endian = (WORDS_BIG_ENDIAN == 0);
5694
5695   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
5696   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
5697   operands[4] = GEN_INT (high & 0xffff0000);
5698   operands[5] = GEN_INT (low  & 0xffff0000);
5699   operands[6] = GEN_INT (high & 0x0000ffff);
5700   operands[7] = GEN_INT (low  & 0x0000ffff);
5701 }")
5702
5703 (define_split
5704   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5705         (match_operand:DF 1 "easy_fp_constant" ""))]
5706   "TARGET_64BIT && reload_completed
5707    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
5708        || (GET_CODE (operands[0]) == SUBREG
5709            && GET_CODE (SUBREG_REG (operands[0])) == REG
5710            && REGNO (SUBREG_REG (operands[0])) <= 31))"
5711   [(set (match_dup 2) (subreg:DI (match_dup 1) 0))]
5712   "
5713 { operands[2] = gen_lowpart (DImode, operands[0]); }")
5714
5715 ;; Don't have reload use general registers to load a constant.  First,
5716 ;; it might not work if the output operand has is the equivalent of
5717 ;; a non-offsettable memref, but also it is less efficient than loading
5718 ;; the constant into an FP register, since it will probably be used there.
5719 ;; The "??" is a kludge until we can figure out a more reasonable way
5720 ;; of handling these non-offsettable values.
5721 (define_insn "*movdf_hardfloat32"
5722   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,o,!r,!r,!r,f,f,m")
5723         (match_operand:DF 1 "input_operand" "r,o,r,G,H,F,f,m,f"))]
5724   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT
5725    && (register_operand (operands[0], DFmode)
5726        || register_operand (operands[1], DFmode))"
5727   "*
5728 {
5729   switch (which_alternative)
5730     {
5731     case 0:
5732       /* We normally copy the low-numbered register first.  However, if
5733          the first register operand 0 is the same as the second register of
5734          operand 1, we must copy in the opposite order.  */
5735       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
5736         return \"mr %L0,%L1\;mr %0,%1\";
5737       else
5738         return \"mr %0,%1\;mr %L0,%L1\";
5739     case 1:
5740       /* If the low-address word is used in the address, we must load it
5741          last.  Otherwise, load it first.  Note that we cannot have
5742          auto-increment in that case since the address register is known to be
5743          dead.  */
5744       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
5745                              operands [1], 0))
5746         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
5747       else
5748         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
5749     case 2:
5750       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
5751     case 3:
5752     case 4:
5753     case 5:
5754       return \"#\";
5755     case 6:
5756       return \"fmr %0,%1\";
5757     case 7:
5758       return \"lfd%U1%X1 %0,%1\";
5759     case 8:
5760       return \"stfd%U0%X0 %1,%0\";
5761     }
5762 }"
5763   [(set_attr "type" "*,load,store,*,*,*,fp,fpload,fpstore")
5764    (set_attr "length" "8,8,8,8,12,16,*,*,*")])
5765
5766 (define_insn "*movdf_softfloat32"
5767   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,o,r,r,r")
5768         (match_operand:DF 1 "input_operand" "r,o,r,G,H,F"))]
5769   "! TARGET_POWERPC64 && TARGET_SOFT_FLOAT
5770    && (register_operand (operands[0], DFmode)
5771        || register_operand (operands[1], DFmode))"
5772   "*
5773 {
5774   switch (which_alternative)
5775     {
5776     case 0:
5777       /* We normally copy the low-numbered register first.  However, if
5778          the first register operand 0 is the same as the second register of
5779          operand 1, we must copy in the opposite order.  */
5780       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
5781         return \"mr %L0,%L1\;mr %0,%1\";
5782       else
5783         return \"mr %0,%1\;mr %L0,%L1\";
5784     case 1:
5785       /* If the low-address word is used in the address, we must load it
5786          last.  Otherwise, load it first.  Note that we cannot have
5787          auto-increment in that case since the address register is known to be
5788          dead.  */
5789       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
5790                              operands [1], 0))
5791         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
5792       else
5793         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
5794     case 2:
5795       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
5796     case 3:
5797     case 4:
5798     case 5:
5799       return \"#\";
5800     }
5801 }"
5802   [(set_attr "type" "*,load,store,*,*,*")
5803    (set_attr "length" "8,8,8,8,12,16")])
5804
5805 (define_insn "*movdf_hardfloat64"
5806   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,o,!r,!r,!r,f,f,m")
5807         (match_operand:DF 1 "input_operand" "r,o,r,G,H,F,f,m,f"))]
5808   "TARGET_POWERPC64 && TARGET_HARD_FLOAT
5809    && (register_operand (operands[0], DFmode)
5810        || register_operand (operands[1], DFmode))"
5811   "@
5812    mr %0,%1
5813    ld%U1%X1 %0,%1
5814    std%U0%X0 %1,%0
5815    #
5816    #
5817    #
5818    fmr %0,%1
5819    lfd%U1%X1 %0,%1
5820    stfd%U0%X0 %1,%0"
5821   [(set_attr "type" "*,load,store,*,*,*,fp,fpload,fpstore")
5822    (set_attr "length" "4,4,4,8,12,16,4,4,4")])
5823
5824 (define_insn "*movdf_softfloat64"
5825   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,o,r,r,r")
5826         (match_operand:DF 1 "input_operand" "r,o,r,G,H,F"))]
5827   "TARGET_POWERPC64 && TARGET_SOFT_FLOAT
5828    && (register_operand (operands[0], DFmode)
5829        || register_operand (operands[1], DFmode))"
5830   "@
5831    mr %0,%1
5832    ld%U1%X1 %0,%1
5833    std%U0%X0 %1,%0
5834    #
5835    #
5836    #"
5837   [(set_attr "type" "*,load,store,*,*,*")
5838    (set_attr "length" "*,*,*,8,12,16")])
5839 \f
5840 ;; Next come the multi-word integer load and store and the load and store
5841 ;; multiple insns.
5842 (define_expand "movdi"
5843   [(set (match_operand:DI 0 "general_operand" "")
5844         (match_operand:DI 1 "any_operand" ""))]
5845   ""
5846   "
5847 {
5848   if (GET_CODE (operands[0]) != REG)
5849     operands[1] = force_reg (DImode, operands[1]);
5850
5851   if (TARGET_64BIT
5852       && (GET_CODE (operands[1]) == CONST_DOUBLE
5853           || GET_CODE (operands[1]) == CONST_INT))
5854     {
5855       HOST_WIDE_INT low;
5856       HOST_WIDE_INT high;
5857
5858       if (GET_CODE (operands[1]) == CONST_DOUBLE)
5859         {
5860           low = CONST_DOUBLE_LOW (operands[1]);
5861           high = CONST_DOUBLE_HIGH (operands[1]);
5862         }
5863       else
5864 #if HOST_BITS_PER_WIDE_INT == 32
5865         {
5866           low = INTVAL (operands[1]);
5867           high = (low < 0) ? ~0 : 0;
5868         }
5869 #else
5870         {
5871           low = INTVAL (operands[1]) & 0xffffffff;
5872           high = (HOST_WIDE_INT) INTVAL (operands[1]) >> 32;
5873         }
5874 #endif
5875
5876         if (high)
5877           {
5878             emit_move_insn (operands[0], GEN_INT (high));
5879             emit_insn (gen_ashldi3 (operands[0], operands[0], GEN_INT(32)));
5880             if (low)
5881               {
5882                 HOST_WIDE_INT low_low = low & 0xffff;
5883                 HOST_WIDE_INT low_high = low & (~ (HOST_WIDE_INT) 0xffff);
5884                 if (low_high)
5885                   emit_insn (gen_iordi3 (operands[0], operands[0],
5886                                          GEN_INT (low_high)));
5887                 if (low_low)
5888                   emit_insn (gen_iordi3 (operands[0], operands[0],
5889                                          GEN_INT (low_low)));
5890               }
5891               DONE;
5892           }
5893     }
5894
5895       /* Stores between FPR and any non-FPR registers must go through a
5896          temporary stack slot.  */
5897
5898   if (GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == REG
5899       && ((FP_REGNO_P (REGNO (operands[0]))
5900            && ! FP_REGNO_P (REGNO (operands[1])))
5901           || (FP_REGNO_P (REGNO (operands[1]))
5902               && ! FP_REGNO_P (REGNO (operands[0])))))
5903     {
5904       rtx stack_slot = assign_stack_temp (DImode, 8, 0);
5905
5906       emit_move_insn (stack_slot, operands[1]);
5907       emit_move_insn (operands[0], stack_slot);
5908       DONE;
5909     }
5910 }")
5911
5912 (define_insn "*movdi_32"
5913   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,f,f,m,r,r,r,r,r")
5914         (match_operand:DI 1 "input_operand" "r,m,r,f,m,f,IJK,n,G,H,F"))]
5915   "TARGET_32BIT
5916    && (gpc_reg_operand (operands[0], DImode)
5917        || gpc_reg_operand (operands[1], DImode))"
5918   "*
5919 {
5920   switch (which_alternative)
5921     {
5922     case 0:
5923       /* We normally copy the low-numbered register first.  However, if
5924          the first register operand 0 is the same as the second register of
5925          operand 1, we must copy in the opposite order.  */
5926       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
5927         return \"mr %L0,%L1\;mr %0,%1\";
5928       else
5929         return \"mr %0,%1\;mr %L0,%L1\";
5930     case 1:
5931       /* If the low-address word is used in the address, we must load it
5932          last.  Otherwise, load it first.  Note that we cannot have
5933          auto-increment in that case since the address register is known to be
5934          dead.  */
5935       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
5936                              operands [1], 0))
5937         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
5938       else
5939         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
5940     case 2:
5941       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
5942     case 3:
5943       return \"fmr %0,%1\";
5944     case 4:
5945       return \"lfd%U1%X1 %0,%1\";
5946     case 5:
5947       return \"stfd%U0%X0 %1,%0\";
5948     case 6:
5949     case 7:
5950     case 8:
5951     case 9:
5952     case 10:
5953       return \"#\";
5954     }
5955 }"
5956   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*,*,*")
5957    (set_attr "length" "8,8,8,*,*,*,8,12,8,12,16")])
5958
5959 (define_split
5960   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5961         (match_operand:DI 1 "const_int_operand" ""))]
5962   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], DImode) <= 1"
5963   [(set (match_dup 2) (match_dup 4))
5964    (set (match_dup 3) (match_dup 1))]
5965   "
5966 {
5967   operands[2] = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN == 0);
5968   operands[3] = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN != 0);
5969   operands[4] = (INTVAL (operands[1]) & 0x80000000) ? constm1_rtx : const0_rtx;
5970 }")
5971
5972 (define_split
5973   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5974         (match_operand:DI 1 "const_int_operand" ""))]
5975   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], DImode) >= 2"
5976   [(set (match_dup 3) (match_dup 5))
5977    (set (match_dup 2) (match_dup 4))
5978    (set (match_dup 3) (ior:SI (match_dup 3) (match_dup 6)))]
5979   "
5980 {
5981   HOST_WIDE_INT value = INTVAL (operands[1]);
5982   operands[2] = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN == 0);
5983   operands[3] = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN != 0);
5984   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
5985   operands[5] = GEN_INT (value & 0xffff0000);
5986   operands[6] = GEN_INT (value & 0x0000ffff);
5987 }")
5988
5989 (define_split
5990   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5991         (match_operand:DI 1 "const_double_operand" ""))]
5992   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], DImode) <= 2"
5993   [(set (match_dup 2) (match_dup 4))
5994    (set (match_dup 3) (match_dup 5))]
5995   "
5996 {
5997   operands[2] = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN == 0);
5998   operands[3] = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN != 0);
5999   operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
6000   operands[5] = GEN_INT (CONST_DOUBLE_LOW  (operands[1]));
6001 }")
6002
6003 (define_split
6004   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6005         (match_operand:DI 1 "const_double_operand" ""))]
6006   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], DImode) == 3"
6007   [(set (match_dup 2) (match_dup 4))
6008    (set (match_dup 3) (match_dup 5))
6009    (set (match_dup 2) (ior:SI (match_dup 2) (match_dup 6)))]
6010   "
6011 {
6012   HOST_WIDE_INT high = CONST_DOUBLE_HIGH (operands[1]);
6013   HOST_WIDE_INT low  = CONST_DOUBLE_LOW  (operands[1]);
6014   rtx high_reg = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN == 0);
6015   rtx low_reg  = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN != 0);
6016
6017   if (((unsigned HOST_WIDE_INT) (low + 0x8000) < 0x10000)
6018       || (low & 0xffff) == 0)
6019     {
6020       operands[2] = high_reg;
6021       operands[3] = low_reg;
6022       operands[4] = GEN_INT (high & 0xffff0000);
6023       operands[5] = GEN_INT (low);
6024       operands[6] = GEN_INT (high & 0x0000ffff);
6025     }
6026   else
6027     {
6028       operands[2] = low_reg;
6029       operands[3] = high_reg;
6030       operands[4] = GEN_INT (low & 0xffff0000);
6031       operands[5] = GEN_INT (high);
6032       operands[6] = GEN_INT (low & 0x0000ffff);
6033     }
6034 }")
6035
6036 (define_split
6037   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6038         (match_operand:DI 1 "const_double_operand" ""))]
6039   "TARGET_32BIT && reload_completed && num_insns_constant (operands[1], DImode) >= 4"
6040   [(set (match_dup 2) (match_dup 4))
6041    (set (match_dup 3) (match_dup 5))
6042    (set (match_dup 2) (ior:SI (match_dup 2) (match_dup 6)))
6043    (set (match_dup 3) (ior:SI (match_dup 3) (match_dup 7)))]
6044   "
6045 {
6046   HOST_WIDE_INT high = CONST_DOUBLE_HIGH (operands[1]);
6047   HOST_WIDE_INT low  = CONST_DOUBLE_LOW  (operands[1]);
6048
6049   operands[2] = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN == 0);
6050   operands[3] = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN != 0);
6051   operands[4] = GEN_INT (high & 0xffff0000);
6052   operands[5] = GEN_INT (low  & 0xffff0000);
6053   operands[6] = GEN_INT (high & 0x0000ffff);
6054   operands[7] = GEN_INT (low  & 0x0000ffff);
6055 }")
6056
6057 (define_insn "*movdi_64"
6058   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,f,f,m,r,*h,*h")
6059         (match_operand:DI 1 "input_operand" "r,m,r,I,J,nF,R,f,m,f,*h,r,0"))]
6060   "TARGET_64BIT
6061    && (gpc_reg_operand (operands[0], DImode)
6062        || gpc_reg_operand (operands[1], DImode))"
6063   "@
6064    mr %0,%1
6065    ld%U1%X1 %0,%1
6066    std%U0%X0 %1,%0
6067    li %0,%1
6068    lis %0,%v1
6069    #
6070    {cal|la} %0,%1(%*)
6071    fmr %0,%1
6072    lfd%U1%X1 %0,%1
6073    stfd%U0%X0 %1,%0
6074    mf%1 %0
6075    mt%0 %1
6076    cror 0,0,0"
6077   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,*,mtjmpr,*")
6078    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
6079
6080 ;; Split a load of a large constant into the appropriate five-instruction
6081 ;; sequence.  The expansion in movdi tries to perform the minimum number of
6082 ;; steps, but here we have to handle anything in a constant number of insns.
6083
6084 (define_split
6085   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6086         (match_operand:DI 1 "const_double_operand" ""))]
6087   "TARGET_64BIT && num_insns_constant (operands[1], DImode) > 1"
6088   [(set (match_dup 0)
6089         (match_dup 2))
6090    (set (match_dup 0)
6091         (ior:DI (match_dup 0)
6092                 (match_dup 3)))
6093    (set (match_dup 0)
6094         (ashift:DI (match_dup 0)
6095                    (const_int 32)))
6096    (set (match_dup 0)
6097         (ior:DI (match_dup 0)
6098                 (match_dup 4)))
6099    (set (match_dup 0)
6100         (ior:DI (match_dup 0)
6101                 (match_dup 5)))]
6102   "
6103 {
6104   HOST_WIDE_INT low;
6105   HOST_WIDE_INT high;
6106
6107   if (GET_CODE (operands[1]) == CONST_DOUBLE)
6108     {
6109       low = CONST_DOUBLE_LOW (operands[1]);
6110       high = CONST_DOUBLE_HIGH (operands[1]);
6111     }
6112   else
6113 #if HOST_BITS_PER_WIDE_INT == 32
6114     {
6115       low = INTVAL (operands[1]);
6116       high = (low < 0) ? ~0 : 0;
6117     }
6118 #else
6119     {
6120       low = INTVAL (operands[1]) & 0xffffffff;
6121       high = (HOST_WIDE_INT) INTVAL (operands[1]) >> 32;
6122     }
6123 #endif
6124
6125   if ((high + 0x8000) < 0x10000
6126       && ((low & 0xffff) == 0 || (low & (~ (HOST_WIDE_INT) 0xffff)) == 0))
6127     FAIL;
6128
6129   operands[2] = GEN_INT (high & (~ (HOST_WIDE_INT) 0xffff));
6130   operands[3] = GEN_INT (high & 0xffff);
6131   operands[4] = GEN_INT (low & (~ (HOST_WIDE_INT) 0xffff));
6132   operands[5] = GEN_INT (low & 0xffff);
6133 }")
6134
6135 (define_insn ""
6136   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
6137         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
6138                     (const_int 0)))
6139    (set (match_operand:DI 0 "gpc_reg_operand" "=r") (match_dup 1))]
6140   "TARGET_POWERPC64"
6141   "mr. %0,%1"
6142   [(set_attr "type" "compare")])
6143 \f
6144 ;; TImode is similar, except that we usually want to compute the address into
6145 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
6146 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
6147 (define_expand "movti"
6148   [(parallel [(set (match_operand:TI 0 "general_operand" "")
6149                    (match_operand:TI 1 "general_operand" ""))
6150               (clobber (scratch:SI))])]
6151   "TARGET_STRING || TARGET_POWERPC64"
6152   "
6153 {
6154   if (GET_CODE (operands[0]) == MEM)
6155     operands[1] = force_reg (TImode, operands[1]);
6156
6157   if (GET_CODE (operands[0]) == MEM
6158       && GET_CODE (XEXP (operands[0], 0)) != REG
6159       && ! reload_in_progress)
6160     operands[0] = change_address (operands[0], TImode,
6161                                   copy_addr_to_reg (XEXP (operands[0], 0)));
6162
6163   if (GET_CODE (operands[1]) == MEM
6164       && GET_CODE (XEXP (operands[1], 0)) != REG
6165       && ! reload_in_progress)
6166     operands[1] = change_address (operands[1], TImode,
6167                                   copy_addr_to_reg (XEXP (operands[1], 0)));
6168 }")
6169
6170 ;; We say that MQ is clobbered in the last alternative because the first
6171 ;; alternative would never get used otherwise since it would need a reload
6172 ;; while the 2nd alternative would not.  We put memory cases first so they
6173 ;; are preferred.  Otherwise, we'd try to reload the output instead of
6174 ;; giving the SCRATCH mq.
6175 (define_insn ""
6176   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
6177         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
6178    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
6179   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
6180    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
6181   "*
6182 {
6183   switch (which_alternative)
6184     {
6185     default:
6186       abort ();
6187
6188     case 0:
6189       return \"{stsi|stswi} %1,%P0,16\";
6190
6191     case 1:
6192       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\;{st|stw} %Y1,%Y0\;{st|stw} %Z1,%Z0\";
6193
6194     case 2:
6195       /* Normally copy registers with lowest numbered register copied first.
6196          But copy in the other order if the first register of the output
6197          is the second, third, or fourth register in the input.  */
6198       if (REGNO (operands[0]) >= REGNO (operands[1]) + 1
6199           && REGNO (operands[0]) <= REGNO (operands[1]) + 3)
6200         return \"mr %Z0,%Z1\;mr %Y0,%Y1\;mr %L0,%L1\;mr %0,%1\";
6201       else
6202         return \"mr %0,%1\;mr %L0,%L1\;mr %Y0,%Y1\;mr %Z0,%Z1\";
6203     case 3:
6204       /* If the address is not used in the output, we can use lsi.  Otherwise,
6205          fall through to generating four loads.  */
6206       if (! reg_overlap_mentioned_p (operands[0], operands[1]))
6207         return \"{lsi|lswi} %0,%P1,16\";
6208       /* ... fall through ... */
6209     case 4:
6210       /* If the address register is the same as the register for the lowest-
6211          addressed word, load it last.  Similarly for the next two words.
6212          Otherwise load lowest address to highest.  */
6213       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
6214                              operands[1], 0))
6215         return \"{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %0,%1\";
6216       else if (refers_to_regno_p (REGNO (operands[0]) + 1,
6217                                   REGNO (operands[0]) + 2, operands[1], 0))
6218         return \"{l|lwz} %0,%1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %L0,%L1\";
6219       else if (refers_to_regno_p (REGNO (operands[0]) + 2,
6220                                   REGNO (operands[0]) + 3, operands[1], 0))
6221         return \"{l|lwz} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Z0,%Z1\;{l|lwz} %Y0,%Y1\";
6222       else
6223         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\";
6224     }
6225 }"
6226   [(set_attr "type" "store,store,*,load,load")
6227    (set_attr "length" "*,16,16,*,16")])
6228
6229 (define_insn ""
6230   [(set (match_operand:TI 0 "reg_or_mem_operand" "=m,????r,????r")
6231         (match_operand:TI 1 "reg_or_mem_operand" "r,r,m"))
6232    (clobber (match_scratch:SI 2 "=X,X,X"))]
6233   "TARGET_STRING && !TARGET_POWER && ! TARGET_POWERPC64
6234    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
6235   "*
6236 {
6237   switch (which_alternative)
6238     {
6239     default:
6240       abort ();
6241
6242     case 0:
6243       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\;{st|stw} %Y1,%Y0\;{st|stw} %Z1,%Z0\";
6244
6245     case 1:
6246       /* Normally copy registers with lowest numbered register copied first.
6247          But copy in the other order if the first register of the output
6248          is the second, third, or fourth register in the input.  */
6249       if (REGNO (operands[0]) >= REGNO (operands[1]) + 1
6250           && REGNO (operands[0]) <= REGNO (operands[1]) + 3)
6251         return \"mr %Z0,%Z1\;mr %Y0,%Y1\;mr %L0,%L1\;mr %0,%1\";
6252       else
6253         return \"mr %0,%1\;mr %L0,%L1\;mr %Y0,%Y1\;mr %Z0,%Z1\";
6254     case 2:
6255       /* If the address register is the same as the register for the lowest-
6256          addressed word, load it last.  Similarly for the next two words.
6257          Otherwise load lowest address to highest.  */
6258       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
6259                              operands[1], 0))
6260         return \"{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %0,%1\";
6261       else if (refers_to_regno_p (REGNO (operands[0]) + 1,
6262                                   REGNO (operands[0]) + 2, operands[1], 0))
6263         return \"{l|lwz} %0,%1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %L0,%L1\";
6264       else if (refers_to_regno_p (REGNO (operands[0]) + 2,
6265                                   REGNO (operands[0]) + 3, operands[1], 0))
6266         return \"{l|lwz} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Z0,%Z1\;{l|lwz} %Y0,%Y1\";
6267       else
6268         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\";
6269     }
6270 }"
6271   [(set_attr "type" "store,*,load")
6272    (set_attr "length" "16,16,16")])
6273
6274 (define_insn ""
6275   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,r,m")
6276         (match_operand:TI 1 "input_operand" "r,m,r"))]
6277   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
6278    || gpc_reg_operand (operands[1], TImode))"
6279   "*
6280 {
6281   switch (which_alternative)
6282     {
6283     case 0:
6284       /* We normally copy the low-numbered register first.  However, if
6285          the first register operand 0 is the same as the second register of
6286          operand 1, we must copy in the opposite order.  */
6287       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
6288         return \"mr %L0,%L1\;mr %0,%1\";
6289       else
6290         return \"mr %0,%1\;mr %L0,%L1\";
6291     case 1:
6292       /* If the low-address word is used in the address, we must load it
6293          last.  Otherwise, load it first.  Note that we cannot have
6294          auto-increment in that case since the address register is known to be
6295          dead.  */
6296       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
6297                              operands [1], 0))
6298         return \"ld %L0,%L1\;ld %0,%1\";
6299       else
6300         return \"ld%U1 %0,%1\;ld %L0,%L1\";
6301     case 2:
6302       return \"std%U0 %1,%0\;std %L1,%L0\";
6303     }
6304 }"
6305   [(set_attr "type" "*,load,store")
6306    (set_attr "length" "8,8,8")])
6307 \f
6308 (define_expand "load_multiple"
6309   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
6310                           (match_operand:SI 1 "" ""))
6311                      (use (match_operand:SI 2 "" ""))])]
6312   "TARGET_STRING"
6313   "
6314 {
6315   int regno;
6316   int count;
6317   rtx from;
6318   int i;
6319
6320   /* Support only loading a constant number of fixed-point registers from
6321      memory and only bother with this if more than two; the machine
6322      doesn't support more than eight.  */
6323   if (GET_CODE (operands[2]) != CONST_INT
6324       || INTVAL (operands[2]) <= 2
6325       || INTVAL (operands[2]) > 8
6326       || GET_CODE (operands[1]) != MEM
6327       || GET_CODE (operands[0]) != REG
6328       || REGNO (operands[0]) >= 32)
6329     FAIL;
6330
6331   count = INTVAL (operands[2]);
6332   regno = REGNO (operands[0]);
6333
6334   operands[3] = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (count));
6335   from = force_reg (SImode, XEXP (operands[1], 0));
6336
6337   for (i = 0; i < count; i++)
6338     XVECEXP (operands[3], 0, i)
6339       = gen_rtx (SET, VOIDmode, gen_rtx (REG, SImode, regno + i),
6340                  change_address (operands[1], SImode,
6341                                  plus_constant (from, i * 4)));
6342 }")
6343
6344 (define_insn ""
6345   [(match_parallel 0 "load_multiple_operation"
6346                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
6347                          (mem:SI (match_operand:SI 2 "register_operand" "b")))])]
6348   "TARGET_STRING"
6349   "*
6350 {
6351   /* We have to handle the case where the pseudo used to contain the address
6352      is assigned to one of the output registers.  */
6353   int i, j;
6354   int words = XVECLEN (operands[0], 0);
6355   rtx xop[10];
6356
6357   if (XVECLEN (operands[0], 0) == 1)
6358     return \"{l|lwz} %1,0(%2)\";
6359
6360   for (i = 0; i < words; i++)
6361     if (refers_to_regno_p (REGNO (operands[1]) + i,
6362                            REGNO (operands[1]) + i + 1, operands[2], 0))
6363       {
6364         if (i == words-1)
6365           {
6366             xop[0] = operands[1];
6367             xop[1] = operands[2];
6368             xop[2] = GEN_INT (4 * (words-1));
6369             output_asm_insn (\"{lsi|lswi} %0,%1,%2\;{l|lwz} %1,%2(%1)\", xop);
6370             return \"\";
6371           }
6372         else if (i == 0)
6373           {
6374             xop[0] = operands[1];
6375             xop[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
6376             xop[2] = GEN_INT (4 * (words-1));
6377             output_asm_insn (\"{cal %0,4(%0)|addi %0,%0,4}\;{lsi|lswi} %1,%0,%2\;{l|lwz} %0,-4(%0)\", xop);
6378             return \"\";
6379           }
6380         else
6381           {
6382             for (j = 0; j < words; j++)
6383               if (j != i)
6384                 {
6385                   xop[0] = gen_rtx (REG, SImode, REGNO (operands[1]) + j);
6386                   xop[1] = operands[2];
6387                   xop[2] = GEN_INT (j * 4);
6388                   output_asm_insn (\"{l|lwz} %0,%2(%1)\", xop);
6389                 }
6390             xop[0] = operands[2];
6391             xop[1] = GEN_INT (i * 4);
6392             output_asm_insn (\"{l|lwz} %0,%1(%0)\", xop);
6393             return \"\";
6394           }
6395       }
6396
6397   return \"{lsi|lswi} %1,%2,%N0\";
6398 }"
6399   [(set_attr "type" "load")
6400    (set_attr "length" "32")])
6401
6402 \f
6403 (define_expand "store_multiple"
6404   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
6405                           (match_operand:SI 1 "" ""))
6406                      (clobber (scratch:SI))
6407                      (use (match_operand:SI 2 "" ""))])]
6408   "TARGET_STRING"
6409   "
6410 {
6411   int regno;
6412   int count;
6413   rtx to;
6414   int i;
6415
6416   /* Support only storing a constant number of fixed-point registers to
6417      memory and only bother with this if more than two; the machine
6418      doesn't support more than eight.  */
6419   if (GET_CODE (operands[2]) != CONST_INT
6420       || INTVAL (operands[2]) <= 2
6421       || INTVAL (operands[2]) > 8
6422       || GET_CODE (operands[0]) != MEM
6423       || GET_CODE (operands[1]) != REG
6424       || REGNO (operands[1]) >= 32)
6425     FAIL;
6426
6427   count = INTVAL (operands[2]);
6428   regno = REGNO (operands[1]);
6429
6430   operands[3] = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (count + 1));
6431   to = force_reg (SImode, XEXP (operands[0], 0));
6432
6433   XVECEXP (operands[3], 0, 0)
6434     = gen_rtx (SET, VOIDmode, change_address (operands[0], SImode, to),
6435                operands[1]);
6436   XVECEXP (operands[3], 0, 1) = gen_rtx (CLOBBER, VOIDmode,
6437                                                   gen_rtx (SCRATCH, SImode));
6438
6439   for (i = 1; i < count; i++)
6440     XVECEXP (operands[3], 0, i + 1)
6441       = gen_rtx (SET, VOIDmode,
6442                  change_address (operands[0], SImode,
6443                                  plus_constant (to, i * 4)),
6444                  gen_rtx (REG, SImode, regno + i));
6445 }")
6446
6447 (define_insn ""
6448   [(match_parallel 0 "store_multiple_operation"
6449                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
6450                          (match_operand:SI 2 "gpc_reg_operand" "r"))
6451                     (clobber (match_scratch:SI 3 "=q"))])]
6452   "TARGET_STRING && TARGET_POWER"
6453   "{stsi|stswi} %2,%P1,%O0"
6454   [(set_attr "type" "store")])
6455
6456 (define_insn ""
6457   [(match_parallel 0 "store_multiple_operation"
6458                    [(set (mem:SI (match_operand:SI 1 "register_operand" "b"))
6459                          (match_operand:SI 2 "gpc_reg_operand" "r"))
6460                     (clobber (match_scratch:SI 3 "X"))])]
6461   "TARGET_STRING && !TARGET_POWER"
6462   "{stsi|stswi} %2,%1,%O0"
6463   [(set_attr "type" "store")])
6464
6465 \f
6466 ;; String/block move insn.
6467 ;; Argument 0 is the destination
6468 ;; Argument 1 is the source
6469 ;; Argument 2 is the length
6470 ;; Argument 3 is the alignment
6471
6472 (define_expand "movstrsi"
6473   [(parallel [(set (match_operand:BLK 0 "" "")
6474                    (match_operand:BLK 1 "" ""))
6475               (use (match_operand:SI 2 "" ""))
6476               (use (match_operand:SI 3 "" ""))])]
6477   ""
6478   "
6479 {
6480   if (expand_block_move (operands))
6481     DONE;
6482   else
6483     FAIL;
6484 }")
6485
6486 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
6487 ;; register allocator doesn't have a clue about allocating 8 word registers
6488 (define_expand "movstrsi_8reg"
6489   [(parallel [(set (match_operand 0 "" "")
6490                    (match_operand 1 "" ""))
6491               (use (match_operand 2 "" ""))
6492               (use (match_operand 3 "" ""))
6493               (clobber (reg:SI  5))
6494               (clobber (reg:SI  6))
6495               (clobber (reg:SI  7))
6496               (clobber (reg:SI  8))
6497               (clobber (reg:SI  9))
6498               (clobber (reg:SI 10))
6499               (clobber (reg:SI 11))
6500               (clobber (reg:SI 12))
6501               (clobber (match_scratch:SI 4 ""))])]
6502   "TARGET_STRING"
6503   "")
6504
6505 (define_insn ""
6506   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6507         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6508    (use (match_operand:SI 2 "immediate_operand" "i"))
6509    (use (match_operand:SI 3 "immediate_operand" "i"))
6510    (clobber (match_operand:SI 4 "register_operand" "=r"))
6511    (clobber (reg:SI  6))
6512    (clobber (reg:SI  7))
6513    (clobber (reg:SI  8))
6514    (clobber (reg:SI  9))
6515    (clobber (reg:SI 10))
6516    (clobber (reg:SI 11))
6517    (clobber (reg:SI 12))
6518    (clobber (match_scratch:SI 5 "=q"))]
6519   "TARGET_STRING && TARGET_POWER
6520    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32) || INTVAL (operands[2]) == 0)
6521    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
6522    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
6523    && REGNO (operands[4]) == 5"
6524   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6525   [(set_attr "type" "load")
6526    (set_attr "length" "8")])
6527
6528 (define_insn ""
6529   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6530         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6531    (use (match_operand:SI 2 "immediate_operand" "i"))
6532    (use (match_operand:SI 3 "immediate_operand" "i"))
6533    (clobber (match_operand:SI 4 "register_operand" "=r"))
6534    (clobber (reg:SI  6))
6535    (clobber (reg:SI  7))
6536    (clobber (reg:SI  8))
6537    (clobber (reg:SI  9))
6538    (clobber (reg:SI 10))
6539    (clobber (reg:SI 11))
6540    (clobber (reg:SI 12))
6541    (clobber (match_scratch:SI 5 "X"))]
6542   "TARGET_STRING && !TARGET_POWER
6543    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32) || INTVAL (operands[2]) == 0)
6544    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
6545    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
6546    && REGNO (operands[4]) == 5"
6547   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6548   [(set_attr "type" "load")
6549    (set_attr "length" "8")])
6550
6551 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
6552 ;; register allocator doesn't have a clue about allocating 6 word registers
6553 (define_expand "movstrsi_6reg"
6554   [(parallel [(set (match_operand 0 "" "")
6555                    (match_operand 1 "" ""))
6556               (use (match_operand 2 "" ""))
6557               (use (match_operand 3 "" ""))
6558               (clobber (reg:SI  7))
6559               (clobber (reg:SI  8))
6560               (clobber (reg:SI  9))
6561               (clobber (reg:SI 10))
6562               (clobber (reg:SI 11))
6563               (clobber (reg:SI 12))
6564               (clobber (match_scratch:SI 4 ""))])]
6565   "TARGET_STRING"
6566   "")
6567
6568 (define_insn ""
6569   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6570         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6571    (use (match_operand:SI 2 "immediate_operand" "i"))
6572    (use (match_operand:SI 3 "immediate_operand" "i"))
6573    (clobber (match_operand:SI 4 "register_operand" "=r"))
6574    (clobber (reg:SI  8))
6575    (clobber (reg:SI  9))
6576    (clobber (reg:SI 10))
6577    (clobber (reg:SI 11))
6578    (clobber (reg:SI 12))
6579    (clobber (match_scratch:SI 5 "=q"))]
6580   "TARGET_STRING && TARGET_POWER
6581    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
6582    && (REGNO (operands[0]) < 7 || REGNO (operands[0]) > 12)
6583    && (REGNO (operands[1]) < 7 || REGNO (operands[1]) > 12)
6584    && REGNO (operands[4]) == 7"
6585   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6586   [(set_attr "type" "load")
6587    (set_attr "length" "8")])
6588
6589 (define_insn ""
6590   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6591         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6592    (use (match_operand:SI 2 "immediate_operand" "i"))
6593    (use (match_operand:SI 3 "immediate_operand" "i"))
6594    (clobber (match_operand:SI 4 "register_operand" "=r"))
6595    (clobber (reg:SI  8))
6596    (clobber (reg:SI  9))
6597    (clobber (reg:SI 10))
6598    (clobber (reg:SI 11))
6599    (clobber (reg:SI 12))
6600    (clobber (match_scratch:SI 5 "X"))]
6601   "TARGET_STRING && !TARGET_POWER
6602    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
6603    && (REGNO (operands[0]) < 7 || REGNO (operands[0]) > 12)
6604    && (REGNO (operands[1]) < 7 || REGNO (operands[1]) > 12)
6605    && REGNO (operands[4]) == 7"
6606   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6607   [(set_attr "type" "load")
6608    (set_attr "length" "8")])
6609
6610 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill problems
6611 ;; with TImode
6612 (define_expand "movstrsi_4reg"
6613   [(parallel [(set (match_operand 0 "" "")
6614                    (match_operand 1 "" ""))
6615               (use (match_operand 2 "" ""))
6616               (use (match_operand 3 "" ""))
6617               (clobber (reg:SI  9))
6618               (clobber (reg:SI 10))
6619               (clobber (reg:SI 11))
6620               (clobber (reg:SI 12))
6621               (clobber (match_scratch:SI 4 ""))])]
6622   "TARGET_STRING"
6623   "")
6624
6625 (define_insn ""
6626   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6627         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6628    (use (match_operand:SI 2 "immediate_operand" "i"))
6629    (use (match_operand:SI 3 "immediate_operand" "i"))
6630    (clobber (match_operand:SI 4 "register_operand" "=r"))
6631    (clobber (reg:SI 10))
6632    (clobber (reg:SI 11))
6633    (clobber (reg:SI 12))
6634    (clobber (match_scratch:SI 5 "=q"))]
6635   "TARGET_STRING && TARGET_POWER
6636    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
6637    && (REGNO (operands[0]) < 9 || REGNO (operands[0]) > 12)
6638    && (REGNO (operands[1]) < 9 || REGNO (operands[1]) > 12)
6639    && REGNO (operands[4]) == 9"
6640   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6641   [(set_attr "type" "load")
6642    (set_attr "length" "8")])
6643
6644 (define_insn ""
6645   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6646         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6647    (use (match_operand:SI 2 "immediate_operand" "i"))
6648    (use (match_operand:SI 3 "immediate_operand" "i"))
6649    (clobber (match_operand:SI 4 "register_operand" "=r"))
6650    (clobber (reg:SI 10))
6651    (clobber (reg:SI 11))
6652    (clobber (reg:SI 12))
6653    (clobber (match_scratch:SI 5 "X"))]
6654   "TARGET_STRING && !TARGET_POWER
6655    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
6656    && (REGNO (operands[0]) < 9 || REGNO (operands[0]) > 12)
6657    && (REGNO (operands[1]) < 9 || REGNO (operands[1]) > 12)
6658    && REGNO (operands[4]) == 9"
6659   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6660   [(set_attr "type" "load")
6661    (set_attr "length" "8")])
6662
6663 ;; Move up to 8 bytes at a time.
6664 (define_expand "movstrsi_2reg"
6665   [(parallel [(set (match_operand 0 "" "")
6666                    (match_operand 1 "" ""))
6667               (use (match_operand 2 "" ""))
6668               (use (match_operand 3 "" ""))
6669               (clobber (match_scratch:DI 4 ""))
6670               (clobber (match_scratch:SI 5 ""))])]
6671   "TARGET_STRING && !TARGET_64BIT"
6672   "")
6673
6674 (define_insn ""
6675   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6676         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6677    (use (match_operand:SI 2 "immediate_operand" "i"))
6678    (use (match_operand:SI 3 "immediate_operand" "i"))
6679    (clobber (match_scratch:DI 4 "=&r"))
6680    (clobber (match_scratch:SI 5 "=q"))]
6681   "TARGET_STRING && TARGET_POWER && !TARGET_64BIT
6682    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
6683   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6684   [(set_attr "type" "load")
6685    (set_attr "length" "8")])
6686
6687 (define_insn ""
6688   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6689         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6690    (use (match_operand:SI 2 "immediate_operand" "i"))
6691    (use (match_operand:SI 3 "immediate_operand" "i"))
6692    (clobber (match_scratch:DI 4 "=&r"))
6693    (clobber (match_scratch:SI 5 "X"))]
6694   "TARGET_STRING && !TARGET_POWER && !TARGET_64BIT
6695    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
6696   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6697   [(set_attr "type" "load")
6698    (set_attr "length" "8")])
6699
6700 ;; Move up to 4 bytes at a time.
6701 (define_expand "movstrsi_1reg"
6702   [(parallel [(set (match_operand 0 "" "")
6703                    (match_operand 1 "" ""))
6704               (use (match_operand 2 "" ""))
6705               (use (match_operand 3 "" ""))
6706               (clobber (match_scratch:SI 4 ""))
6707               (clobber (match_scratch:SI 5 ""))])]
6708   "TARGET_STRING"
6709   "")
6710
6711 (define_insn ""
6712   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6713         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6714    (use (match_operand:SI 2 "immediate_operand" "i"))
6715    (use (match_operand:SI 3 "immediate_operand" "i"))
6716    (clobber (match_scratch:SI 4 "=&r"))
6717    (clobber (match_scratch:SI 5 "=q"))]
6718   "TARGET_STRING && TARGET_POWER
6719    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
6720   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6721   [(set_attr "type" "load")
6722    (set_attr "length" "8")])
6723
6724 (define_insn ""
6725   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6726         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6727    (use (match_operand:SI 2 "immediate_operand" "i"))
6728    (use (match_operand:SI 3 "immediate_operand" "i"))
6729    (clobber (match_scratch:SI 4 "=&r"))
6730    (clobber (match_scratch:SI 5 "X"))]
6731   "TARGET_STRING && !TARGET_POWER
6732    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
6733   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6734   [(set_attr "type" "load")
6735    (set_attr "length" "8")])
6736
6737 \f
6738 ;; Define insns that do load or store with update.  Some of these we can
6739 ;; get by using pre-decrement or pre-increment, but the hardware can also
6740 ;; do cases where the increment is not the size of the object.
6741 ;;
6742 ;; In all these cases, we use operands 0 and 1 for the register being
6743 ;; incremented because those are the operands that local-alloc will
6744 ;; tie and these are the pair most likely to be tieable (and the ones
6745 ;; that will benefit the most).
6746
6747 (define_insn "*movdi_update1"
6748   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
6749         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
6750                          (match_operand:DI 2 "reg_or_short_operand" "r,I"))))
6751    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
6752         (plus:DI (match_dup 1) (match_dup 2)))]
6753   "TARGET_POWERPC64 && TARGET_UPDATE"
6754   "@
6755    ldux %3,%0,%2
6756    ldu %3,%2(%0)"
6757   [(set_attr "type" "load")])
6758
6759 (define_insn "*movdi_update2"
6760   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
6761         (sign_extend:DI
6762          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
6763                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
6764    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
6765         (plus:DI (match_dup 1) (match_dup 2)))]
6766   "TARGET_POWERPC64"
6767   "lwaux %3,%0,%2"
6768   [(set_attr "type" "load")])
6769
6770 (define_insn "movdi_update"
6771   [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
6772                          (match_operand:DI 2 "reg_or_short_operand" "r,I")))
6773         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
6774    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
6775         (plus:DI (match_dup 1) (match_dup 2)))]
6776   "TARGET_POWERPC64 && TARGET_UPDATE"
6777   "@
6778    stdux %3,%0,%2
6779    stdu %3,%2(%0)"
6780   [(set_attr "type" "store")])
6781
6782 (define_insn "*movsi_update1"
6783   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
6784         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6785                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6786    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6787         (plus:SI (match_dup 1) (match_dup 2)))]
6788   ""
6789   "@
6790    {lux|lwzux} %3,%0,%2
6791    {lu|lwzu} %3,%2(%0)"
6792   [(set_attr "type" "load")])
6793
6794 (define_insn "movsi_update"
6795   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6796                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6797         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6798    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6799         (plus:SI (match_dup 1) (match_dup 2)))]
6800   "TARGET_UPDATE"
6801   "@
6802    {stux|stwux} %3,%0,%2
6803    {stu|stwu} %3,%2(%0)"
6804   [(set_attr "type" "store")])
6805
6806 (define_insn "*movhi_update"
6807   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
6808         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6809                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6810    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6811         (plus:SI (match_dup 1) (match_dup 2)))]
6812   "TARGET_UPDATE"
6813   "@
6814    lhzux %3,%0,%2
6815    lhzu %3,%2(%0)"
6816   [(set_attr "type" "load")])
6817
6818 (define_insn "*movhi_update2"
6819   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
6820         (zero_extend:SI
6821          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6822                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
6823    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6824         (plus:SI (match_dup 1) (match_dup 2)))]
6825   "TARGET_UPDATE"
6826   "@
6827    lhzux %3,%0,%2
6828    lhzu %3,%2(%0)"
6829   [(set_attr "type" "load")])
6830
6831 (define_insn "*movhi_update3"
6832   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
6833         (sign_extend:SI
6834          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6835                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
6836    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6837         (plus:SI (match_dup 1) (match_dup 2)))]
6838   "TARGET_UPDATE"
6839   "@
6840    lhaux %3,%0,%2
6841    lhau %3,%2(%0)"
6842   [(set_attr "type" "load")])
6843
6844 (define_insn "*movhi_update4"
6845   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6846                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6847         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
6848    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6849         (plus:SI (match_dup 1) (match_dup 2)))]
6850   "TARGET_UPDATE"
6851   "@
6852    sthux %3,%0,%2
6853    sthu %3,%2(%0)"
6854   [(set_attr "type" "store")])
6855
6856 (define_insn "*movqi_update1"
6857   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
6858         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6859                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6860    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6861         (plus:SI (match_dup 1) (match_dup 2)))]
6862   "TARGET_UPDATE"
6863   "@
6864    lbzux %3,%0,%2
6865    lbzu %3,%2(%0)"
6866   [(set_attr "type" "load")])
6867
6868 (define_insn "*movqi_update2"
6869   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
6870         (zero_extend:SI
6871          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6872                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
6873    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6874         (plus:SI (match_dup 1) (match_dup 2)))]
6875   "TARGET_UPDATE"
6876   "@
6877    lbzux %3,%0,%2
6878    lbzu %3,%2(%0)"
6879   [(set_attr "type" "load")])
6880
6881 (define_insn "*movqi_update3"
6882   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6883                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6884         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
6885    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6886         (plus:SI (match_dup 1) (match_dup 2)))]
6887   "TARGET_UPDATE"
6888   "@
6889    stbux %3,%0,%2
6890    stbu %3,%2(%0)"
6891   [(set_attr "type" "store")])
6892
6893 (define_insn "*movsf_update1"
6894   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
6895         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6896                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6897    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6898         (plus:SI (match_dup 1) (match_dup 2)))]
6899   "TARGET_HARD_FLOAT && TARGET_UPDATE"
6900   "@
6901    lfsux %3,%0,%2
6902    lfsu %3,%2(%0)"
6903   [(set_attr "type" "fpload")])
6904
6905 (define_insn "*movsf_update2"
6906   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6907                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6908         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
6909    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6910         (plus:SI (match_dup 1) (match_dup 2)))]
6911   "TARGET_HARD_FLOAT && TARGET_UPDATE"
6912   "@
6913    stfsux %3,%0,%2
6914    stfsu %3,%2(%0)"
6915   [(set_attr "type" "fpstore")])
6916
6917 (define_insn "*movsf_update3"
6918   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
6919         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6920                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6921    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6922         (plus:SI (match_dup 1) (match_dup 2)))]
6923   "TARGET_SOFT_FLOAT && TARGET_UPDATE"
6924   "@
6925    {lux|lwzux} %3,%0,%2
6926    {lu|lwzu} %3,%2(%0)"
6927   [(set_attr "type" "load")])
6928
6929 (define_insn "*movsf_update4"
6930   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6931                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6932         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
6933    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6934         (plus:SI (match_dup 1) (match_dup 2)))]
6935   "TARGET_SOFT_FLOAT && TARGET_UPDATE"
6936   "@
6937    {stux|stwux} %3,%0,%2
6938    {stu|stwu} %3,%2(%0)"
6939   [(set_attr "type" "store")])
6940
6941 (define_insn "*movdf_update1"
6942   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
6943         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6944                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6945    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6946         (plus:SI (match_dup 1) (match_dup 2)))]
6947   "TARGET_HARD_FLOAT && TARGET_UPDATE"
6948   "@
6949    lfdux %3,%0,%2
6950    lfdu %3,%2(%0)"
6951   [(set_attr "type" "fpload")])
6952
6953 (define_insn "*movdf_update2"
6954   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6955                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6956         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
6957    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6958         (plus:SI (match_dup 1) (match_dup 2)))]
6959   "TARGET_HARD_FLOAT && TARGET_UPDATE"
6960   "@
6961    stfdux %3,%0,%2
6962    stfdu %3,%2(%0)"
6963   [(set_attr "type" "fpstore")])
6964
6965 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
6966
6967 (define_peephole
6968   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6969         (match_operand:DF 1 "memory_operand" ""))
6970    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
6971         (match_operand:DF 3 "memory_operand" ""))]
6972   "TARGET_POWER2
6973    && TARGET_HARD_FLOAT
6974    && registers_ok_for_quad_peep (operands[0], operands[2])
6975    && ! MEM_VOLATILE_P (operands[1]) && ! MEM_VOLATILE_P (operands[3])
6976    && addrs_ok_for_quad_peep (XEXP (operands[1], 0), XEXP (operands[3], 0))"
6977   "lfq%U1%X1 %0,%1")
6978
6979 (define_peephole
6980   [(set (match_operand:DF 0 "memory_operand" "")
6981         (match_operand:DF 1 "gpc_reg_operand" "f"))
6982    (set (match_operand:DF 2 "memory_operand" "")
6983         (match_operand:DF 3 "gpc_reg_operand" "f"))]
6984   "TARGET_POWER2
6985    && TARGET_HARD_FLOAT
6986    && registers_ok_for_quad_peep (operands[1], operands[3])
6987    && ! MEM_VOLATILE_P (operands[0]) && ! MEM_VOLATILE_P (operands[2])
6988    && addrs_ok_for_quad_peep (XEXP (operands[0], 0), XEXP (operands[2], 0))"
6989   "stfq%U0%X0 %1,%0")
6990 \f
6991 ;; Next come insns related to the calling sequence.
6992 ;;
6993 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
6994 ;; We move the back-chain and decrement the stack pointer.
6995
6996 (define_expand "allocate_stack"
6997   [(set (reg:SI 1)
6998         (minus:SI (reg:SI 1) (match_operand:SI 0 "reg_or_short_operand" "")))]
6999   ""
7000   "
7001 { rtx chain = gen_reg_rtx (Pmode);
7002   rtx stack_bot = gen_rtx (MEM, Pmode, stack_pointer_rtx);
7003   rtx neg_op0;
7004
7005   emit_move_insn (chain, stack_bot);
7006
7007   /* Under Windows NT, we need to add stack probes for large/variable allocations,
7008      so do it via a call to the external function alloca, instead of doing it
7009      inline.  */
7010   if (DEFAULT_ABI == ABI_NT
7011       && (GET_CODE (operands[0]) != CONST_INT || INTVAL (operands[0]) > 4096))
7012     {
7013       rtx tmp = gen_reg_rtx (SImode);
7014       emit_library_call_value (gen_rtx (SYMBOL_REF, Pmode, \"__allocate_stack\"),
7015                                tmp, 0, SImode, 1, operands[0], Pmode);
7016       emit_insn (gen_set_sp (tmp));
7017       DONE;
7018     }
7019
7020   if (GET_CODE (operands[0]) != CONST_INT
7021       || INTVAL (operands[0]) < -32767
7022       || INTVAL (operands[0]) > 32768)
7023     {
7024       neg_op0 = gen_reg_rtx (Pmode);
7025       if (TARGET_32BIT)
7026         emit_insn (gen_negsi2 (neg_op0, operands[0]));
7027       else
7028         emit_insn (gen_negdi2 (neg_op0, operands[0]));
7029     }
7030   else
7031     neg_op0 = GEN_INT (- INTVAL (operands[0]));
7032
7033   if (TARGET_UPDATE)
7034     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_update))
7035                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
7036
7037   else
7038     {
7039       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
7040                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
7041       emit_move_insn (gen_rtx (MEM, (TARGET_32BIT) ? SImode : DImode,
7042                                stack_pointer_rtx),
7043                       chain);
7044     }
7045   DONE;
7046 }")
7047
7048 ;; Marker to indicate that the stack pointer was changed under NT in
7049 ;; ways not known to the compiler
7050
7051 (define_insn "set_sp"
7052   [(set (reg:SI 1)
7053         (unspec [(match_operand:SI 0 "register_operand" "r")] 7))]
7054   ""
7055   ""
7056   [(set_attr "length" "0")])
7057
7058 ;; These patterns say how to save and restore the stack pointer.  We need not
7059 ;; save the stack pointer at function level since we are careful to
7060 ;; preserve the backchain.  At block level, we have to restore the backchain
7061 ;; when we restore the stack pointer.
7062 ;;
7063 ;; For nonlocal gotos, we must save both the stack pointer and its
7064 ;; backchain and restore both.  Note that in the nonlocal case, the
7065 ;; save area is a memory location.
7066
7067 (define_expand "save_stack_function"
7068   [(use (const_int 0))]
7069   ""
7070   "")
7071
7072 (define_expand "restore_stack_function"
7073   [(use (const_int 0))]
7074   ""
7075   "")
7076
7077 (define_expand "restore_stack_block"
7078   [(set (match_dup 2) (mem:SI (match_operand:SI 0 "register_operand" "")))
7079    (set (match_dup 0) (match_operand:SI 1 "register_operand" ""))
7080    (set (mem:SI (match_dup 0)) (match_dup 2))]
7081   ""
7082   "
7083 { operands[2] = gen_reg_rtx (SImode); }")
7084
7085 (define_expand "save_stack_nonlocal"
7086   [(match_operand:DI 0 "memory_operand" "")
7087    (match_operand:SI 1 "register_operand" "")]
7088   ""
7089   "
7090 {
7091   rtx temp = gen_reg_rtx (SImode);
7092
7093   /* Copy the backchain to the first word, sp to the second.  */
7094   emit_move_insn (temp, gen_rtx (MEM, SImode, operands[1]));
7095   emit_move_insn (operand_subword (operands[0], 0, 0, DImode), temp);
7096   emit_move_insn (operand_subword (operands[0], 1, 0, DImode), operands[1]);
7097   DONE;
7098 }")
7099
7100 (define_expand "restore_stack_nonlocal"
7101   [(match_operand:SI 0 "register_operand" "")
7102    (match_operand:DI 1 "memory_operand" "")]
7103   ""
7104   "
7105 {
7106   rtx temp = gen_reg_rtx (SImode);
7107
7108   /* Restore the backchain from the first word, sp from the second.  */
7109   emit_move_insn (temp, operand_subword (operands[1], 0, 0, DImode));
7110   emit_move_insn (operands[0], operand_subword (operands[1], 1, 0, DImode));
7111   emit_move_insn (gen_rtx (MEM, SImode, operands[0]), temp);
7112   DONE;
7113 }")
7114
7115 ;; If we have -mmiminal-toc, we need to reload r30 after a nonlocal goto.
7116
7117 (define_insn "nonlocal_goto_receiver"
7118   [(unspec_volatile [(const_int 0)] 1)]
7119   "TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0"
7120   "*
7121 {
7122   rs6000_output_load_toc_table (asm_out_file, 30);
7123   return \"\";
7124 }"
7125   [(set_attr "type" "load")])
7126 \f
7127 ;; A function pointer under AIX is a pointer to a data area whose first word
7128 ;; contains the actual address of the function, whose second word contains a
7129 ;; pointer to its TOC, and whose third word contains a value to place in the
7130 ;; static chain register (r11).  Note that if we load the static chain, our
7131 ;; "trampoline" need not have any executable code.
7132 ;;
7133 ;; operands[0] is a register pointing to the 3 word descriptor (aka, the function address)
7134 ;; operands[1] is the stack size to clean up
7135 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument (must be 0 for AIX)
7136 ;; operands[3] is location to store the TOC
7137 ;; operands[4] is the TOC register
7138 ;; operands[5] is the static chain register
7139 ;;
7140 ;; We do not break this into separate insns, so that the scheduler will not try
7141 ;; to move the load of the new TOC before any loads from the TOC.
7142
7143 (define_insn "call_indirect_aix"
7144   [(call (mem:SI (match_operand:SI 0 "register_operand" "b"))
7145          (match_operand 1 "const_int_operand" "n"))
7146    (use (match_operand 2 "const_int_operand" "n"))
7147    (use (match_operand 3 "offsettable_addr_operand" "p"))
7148    (use (match_operand 4 "register_operand" "r"))
7149    (clobber (match_operand 5 "register_operand" "=r"))
7150    (clobber (match_scratch:SI 6 "=&r"))
7151    (clobber (match_scratch:SI 7 "=l"))]
7152   "DEFAULT_ABI == ABI_AIX
7153    && (INTVAL (operands[2]) == CALL_NORMAL || (INTVAL (operands[2]) & CALL_LONG) != 0)"
7154   "{st|stw} %4,%a3\;{l|lwz} %6,0(%0)\;{l|lwz} %4,4(%0)\;mt%7 %6\;{l|lwz} %5,8(%0)\;{brl|blrl}\;{l|lwz} %4,%a3"
7155   [(set_attr "type" "load")
7156    (set_attr "length" "28")])
7157
7158 (define_insn "call_value_indirect_aix"
7159   [(set (match_operand 0 "register_operand" "fg")
7160         (call (mem:SI (match_operand:SI 1 "register_operand" "b"))
7161               (match_operand 2 "const_int_operand" "n")))
7162    (use (match_operand 3 "const_int_operand" "n"))
7163    (use (match_operand 4 "offsettable_addr_operand" "p"))
7164    (use (match_operand 5 "register_operand" "r"))
7165    (clobber (match_operand 6 "register_operand" "=r"))
7166    (clobber (match_scratch:SI 7 "=&r"))
7167    (clobber (match_scratch:SI 8 "=l"))]
7168   "DEFAULT_ABI == ABI_AIX
7169    && (INTVAL (operands[3]) == CALL_NORMAL || (INTVAL (operands[3]) & CALL_LONG) != 0)"
7170   "{st|stw} %5,%a4\;{l|lwz} %7,0(%1)\;{l|lwz} %5,4(%1);\;mt%8 %7\;{l|lwz} %6,8(%1)\;{brl|blrl}\;{l|lwz} %5,%a4"
7171   [(set_attr "type" "load")
7172    (set_attr "length" "28")])
7173
7174 ;; A function pointer undef NT is a pointer to a data area whose first word
7175 ;; contains the actual address of the function, whose second word contains a
7176 ;; pointer to its TOC.  The static chain is not stored under NT, which means
7177 ;; that we need a trampoline.
7178 ;;
7179 ;; operands[0] is an SImode pseudo in which we place the address of the function.
7180 ;; operands[1] is the stack size to clean up
7181 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument (must be 0 for NT)
7182 ;; operands[3] is location to store the TOC
7183 ;; operands[4] is the TOC register
7184 ;;
7185 ;; We do not break this into separate insns, so that the scheduler will not try
7186 ;; to move the load of the new TOC before any loads from the TOC.
7187
7188 (define_insn "call_indirect_nt"
7189   [(call (mem:SI (match_operand:SI 0 "register_operand" "b"))
7190          (match_operand 1 "const_int_operand" "n"))
7191    (use (match_operand 2 "const_int_operand" "n"))
7192    (use (match_operand 3 "offsettable_addr_operand" "p"))
7193    (use (match_operand 4 "register_operand" "r"))
7194    (clobber (match_scratch:SI 5 "=&r"))
7195    (clobber (match_scratch:SI 6 "=l"))]
7196   "DEFAULT_ABI == ABI_NT
7197    && (INTVAL (operands[2]) == CALL_NORMAL || (INTVAL (operands[2]) & CALL_LONG) != 0)"
7198   "{st|stw} %4,%a3\;{l|lwz} %5,0(%0)\;{l|lwz} %4,4(%0)\;mt%6 %5\;{brl|blrl}\;{l|lwz} %4,%a3"
7199   [(set_attr "type" "load")
7200    (set_attr "length" "24")])
7201
7202 (define_insn "call_value_indirect_nt"
7203   [(set (match_operand 0 "register_operand" "fg")
7204         (call (mem:SI (match_operand:SI 1 "register_operand" "b"))
7205               (match_operand 2 "const_int_operand" "n")))
7206    (use (match_operand 3 "const_int_operand" "n"))
7207    (use (match_operand 4 "offsettable_addr_operand" "p"))
7208    (use (match_operand 5 "register_operand" "r"))
7209    (clobber (match_scratch:SI 6 "=&r"))
7210    (clobber (match_scratch:SI 7 "=l"))]
7211   "DEFAULT_ABI == ABI_NT
7212    && (INTVAL (operands[3]) == CALL_NORMAL || (INTVAL (operands[3]) & CALL_LONG) != 0)"
7213   "{st|stw} %5,%a4\;{l|lwz} %6,0(%1)\;{l|lwz} %5,4(%1)\;mt%7 %6\;{brl|blrl}\;{l|lwz} %5,%a4"
7214   [(set_attr "type" "load")
7215    (set_attr "length" "24")])
7216
7217 ;; A function pointer under System V is just a normal pointer
7218 ;; operands[0] is the function pointer
7219 ;; operands[1] is the stack size to clean up
7220 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument which indicates how to set cr1
7221
7222 (define_insn "call_indirect_sysv"
7223   [(call (mem:SI (match_operand:SI 0 "register_operand" "l,l"))
7224          (match_operand 1 "const_int_operand" "n,n"))
7225    (use (match_operand 2 "const_int_operand" "O,n"))
7226    (clobber (match_scratch:SI 3 "=l,l"))]
7227   "DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS || DEFAULT_ABI == ABI_AIX_NODESC"
7228   "*
7229 {
7230   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
7231     output_asm_insn (\"crxor 6,6,6\", operands);
7232
7233   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
7234     output_asm_insn (\"creqv 6,6,6\", operands);
7235
7236   return \"{brl|blrl}\";
7237 }"
7238   [(set_attr "type" "jmpreg")
7239    (set_attr "length" "4,8")])
7240
7241 (define_insn "call_value_indirect_sysv"
7242   [(set (match_operand 0 "register_operand" "=fg,fg")
7243         (call (mem:SI (match_operand:SI 1 "register_operand" "l,l"))
7244               (match_operand 2 "const_int_operand" "n,n")))
7245    (use (match_operand 3 "const_int_operand" "O,n"))
7246    (clobber (match_scratch:SI 4 "=l,l"))]
7247   "DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS || DEFAULT_ABI == ABI_AIX_NODESC"
7248   "*
7249 {
7250   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
7251     output_asm_insn (\"crxor 6,6,6\", operands);
7252
7253   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
7254     output_asm_insn (\"creqv 6,6,6\", operands);
7255
7256   return \"{brl|blrl}\";
7257 }"
7258   [(set_attr "type" "jmpreg")
7259    (set_attr "length" "4,8")])
7260
7261 ;; Now the definitions for the call and call_value insns
7262 (define_expand "call"
7263   [(parallel [(call (mem:SI (match_operand:SI 0 "address_operand" ""))
7264                     (match_operand 1 "" ""))
7265               (use (match_operand 2 "" ""))
7266               (clobber (scratch:SI))])]
7267   ""
7268   "
7269 {
7270   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
7271     abort ();
7272
7273   operands[0] = XEXP (operands[0], 0);
7274
7275   /* Convert NT DLL imports into an indirect call.  */
7276   if (GET_CODE (operands[0]) == SYMBOL_REF
7277       && (INTVAL (operands[2]) & CALL_NT_DLLIMPORT) != 0)
7278     {
7279       operands[0] = rs6000_dll_import_ref (operands[0]);
7280       operands[2] = GEN_INT ((int)CALL_NORMAL);
7281     }
7282
7283   if (GET_CODE (operands[0]) != SYMBOL_REF
7284       || (INTVAL (operands[2]) & CALL_LONG) != 0)
7285     {
7286       if (INTVAL (operands[2]) & CALL_LONG)
7287         operands[0] = rs6000_longcall_ref (operands[0]);
7288
7289       if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_AIX_NODESC || DEFAULT_ABI == ABI_SOLARIS)
7290         emit_call_insn (gen_call_indirect_sysv (force_reg (Pmode, operands[0]),
7291                                                 operands[1], operands[2]));
7292       else
7293         {
7294           rtx toc_reg = gen_rtx (REG, Pmode, 2);
7295           rtx toc_addr = RS6000_SAVE_TOC;
7296
7297           if (DEFAULT_ABI == ABI_AIX)
7298             {
7299               /* AIX function pointers are really pointers to a three word area */
7300               rtx static_chain = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
7301               emit_call_insn (gen_call_indirect_aix (force_reg (Pmode, operands[0]),
7302                                                      operands[1], operands[2],
7303                                                      toc_addr, toc_reg, static_chain));
7304             }
7305           else if (DEFAULT_ABI == ABI_NT)
7306             {
7307               /* NT function pointers are really pointers to a two word area */
7308               emit_call_insn (gen_call_indirect_nt (force_reg (Pmode, operands[0]),
7309                                                     operands[1], operands[2],
7310                                                     toc_addr, toc_reg));
7311             }
7312           else
7313             abort ();
7314         }
7315       DONE;
7316     }
7317 }")
7318
7319 (define_expand "call_value"
7320   [(parallel [(set (match_operand 0 "" "")
7321                    (call (mem:SI (match_operand:SI 1 "address_operand" ""))
7322                          (match_operand 2 "" "")))
7323               (use (match_operand 3 "" ""))
7324               (clobber (scratch:SI))])]
7325   ""
7326   "
7327 {
7328   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
7329     abort ();
7330
7331   operands[1] = XEXP (operands[1], 0);
7332
7333   /* Convert NT DLL imports into an indirect call.  */
7334   if (GET_CODE (operands[1]) == SYMBOL_REF
7335       && (INTVAL (operands[3]) & CALL_NT_DLLIMPORT) != 0)
7336     {
7337       operands[1] = rs6000_dll_import_ref (operands[1]);
7338       operands[3] = GEN_INT ((int)CALL_NORMAL);
7339     }
7340
7341   if (GET_CODE (operands[1]) != SYMBOL_REF
7342       || (INTVAL (operands[3]) & CALL_LONG) != 0)
7343     {
7344       if (INTVAL (operands[2]) & CALL_LONG)
7345         operands[1] = rs6000_longcall_ref (operands[1]);
7346
7347       if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_AIX_NODESC || DEFAULT_ABI == ABI_SOLARIS)
7348         emit_call_insn (gen_call_value_indirect_sysv (operands[0], operands[1],
7349                                                       operands[2], operands[3]));
7350       else
7351         {
7352           rtx toc_reg = gen_rtx (REG, Pmode, 2);
7353           rtx toc_addr = RS6000_SAVE_TOC;
7354
7355           if (DEFAULT_ABI == ABI_AIX)
7356             {
7357               /* AIX function pointers are really pointers to a three word area */
7358               rtx static_chain = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
7359               emit_call_insn (gen_call_value_indirect_aix (operands[0],
7360                                                            force_reg (Pmode, operands[1]),
7361                                                            operands[2], operands[3],
7362                                                            toc_addr, toc_reg, static_chain));
7363             }
7364           else if (DEFAULT_ABI == ABI_NT)
7365             {
7366               /* NT function pointers are really pointers to a two word area */
7367               emit_call_insn (gen_call_value_indirect_nt (operands[0],
7368                                                           force_reg (Pmode, operands[1]),
7369                                                           operands[2], operands[3],
7370                                                           toc_addr, toc_reg));
7371             }
7372           else
7373             abort ();
7374         }
7375       DONE;
7376     }
7377 }")
7378
7379 ;; Call to function in current module.  No TOC pointer reload needed.
7380 ;; Operand2 is non-zero if we are using the V.4 calling sequence and
7381 ;; either the function was not prototyped, or it was prototyped as a
7382 ;; variable argument function.  It is > 0 if FP registers were passed
7383 ;; and < 0 if they were not.
7384
7385 (define_insn ""
7386   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
7387          (match_operand 1 "" "g,g"))
7388    (use (match_operand:SI 2 "immediate_operand" "O,n"))
7389    (clobber (match_scratch:SI 3 "=l,l"))]
7390   "(INTVAL (operands[2]) & CALL_LONG) == 0"
7391   "*
7392 {
7393   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
7394     output_asm_insn (\"crxor 6,6,6\", operands);
7395
7396   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
7397     output_asm_insn (\"creqv 6,6,6\", operands);
7398
7399   return \"bl %z0\";
7400 }"
7401   [(set_attr "type" "branch")
7402    (set_attr "length" "4,8")])
7403
7404 ;; Call to function which may be in another module.  Restore the TOC
7405 ;; pointer (r2) after the call unless this is System V.
7406 ;; Operand2 is non-zero if we are using the V.4 calling sequence and
7407 ;; either the function was not prototyped, or it was prototyped as a
7408 ;; variable argument function.  It is > 0 if FP registers were passed
7409 ;; and < 0 if they were not.
7410
7411 (define_insn ""
7412   [(call (mem:SI (match_operand:SI 0 "call_operand" "s,s"))
7413          (match_operand 1 "" "fg,fg"))
7414    (use (match_operand:SI 2 "immediate_operand" "O,n"))
7415    (clobber (match_scratch:SI 3 "=l,l"))]
7416   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
7417    && (INTVAL (operands[2]) & CALL_LONG) == 0"
7418   "*
7419 {
7420   /* Indirect calls should go through call_indirect */
7421   if (GET_CODE (operands[0]) == REG)
7422     abort ();
7423
7424   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
7425     output_asm_insn (\"crxor 6,6,6\", operands);
7426
7427   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
7428     output_asm_insn (\"creqv 6,6,6\", operands);
7429
7430   return (TARGET_WINDOWS_NT) ? \"bl %z0\;.znop %z0\" : \"bl %z0\;%.\";
7431 }"
7432   [(set_attr "type" "branch")
7433    (set_attr "length" "8,12")])
7434
7435 (define_insn ""
7436   [(call (mem:SI (match_operand:SI 0 "call_operand" "s,s"))
7437          (match_operand 1 "" "fg,fg"))
7438    (use (match_operand:SI 2 "immediate_operand" "O,n"))
7439    (clobber (match_scratch:SI 3 "=l,l"))]
7440   "(DEFAULT_ABI == ABI_AIX_NODESC || DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
7441    && (INTVAL (operands[2]) & CALL_LONG) == 0"
7442   "*
7443 {
7444   /* Indirect calls should go through call_indirect */
7445   if (GET_CODE (operands[0]) == REG)
7446     abort ();
7447
7448   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
7449     output_asm_insn (\"crxor 6,6,6\", operands);
7450
7451   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
7452     output_asm_insn (\"creqv 6,6,6\", operands);
7453
7454   return (flag_pic == 1) ? \"bl %z0@plt\" : \"bl %z0\";
7455 }"
7456   [(set_attr "type" "branch")
7457    (set_attr "length" "4,8")])
7458
7459 (define_insn ""
7460   [(set (match_operand 0 "" "=fg,fg")
7461         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
7462               (match_operand 2 "" "g,g")))
7463    (use (match_operand:SI 3 "immediate_operand" "O,n"))
7464    (clobber (match_scratch:SI 4 "=l,l"))]
7465   "(INTVAL (operands[3]) & CALL_LONG) == 0"
7466   "*
7467 {
7468   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
7469     output_asm_insn (\"crxor 6,6,6\", operands);
7470
7471   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
7472     output_asm_insn (\"creqv 6,6,6\", operands);
7473
7474   return \"bl %z1\";
7475 }"
7476   [(set_attr "type" "branch")
7477    (set_attr "length" "4,8")])
7478
7479 (define_insn ""
7480   [(set (match_operand 0 "" "=fg,fg")
7481         (call (mem:SI (match_operand:SI 1 "call_operand" "s,s"))
7482               (match_operand 2 "" "fg,fg")))
7483    (use (match_operand:SI 3 "immediate_operand" "O,n"))
7484    (clobber (match_scratch:SI 4 "=l,l"))]
7485   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
7486    && (INTVAL (operands[3]) & CALL_LONG) == 0"
7487   "*
7488 {
7489   /* This should be handled by call_value_indirect */
7490   if (GET_CODE (operands[1]) == REG)
7491     abort ();
7492
7493   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
7494     output_asm_insn (\"crxor 6,6,6\", operands);
7495
7496   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
7497     output_asm_insn (\"creqv 6,6,6\", operands);
7498
7499   return (TARGET_WINDOWS_NT) ? \"bl %z1\;.znop %z1\" : \"bl %z1\;%.\";
7500 }"
7501   [(set_attr "type" "branch")
7502    (set_attr "length" "8,12")])
7503
7504 (define_insn ""
7505   [(set (match_operand 0 "" "=fg,fg")
7506         (call (mem:SI (match_operand:SI 1 "call_operand" "s,s"))
7507               (match_operand 2 "" "fg,fg")))
7508    (use (match_operand:SI 3 "immediate_operand" "O,n"))
7509    (clobber (match_scratch:SI 4 "=l,l"))]
7510   "(DEFAULT_ABI == ABI_AIX_NODESC || DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
7511    && (INTVAL (operands[3]) & CALL_LONG) == 0"
7512   "*
7513 {
7514   /* This should be handled by call_value_indirect */
7515   if (GET_CODE (operands[1]) == REG)
7516     abort ();
7517
7518   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
7519     output_asm_insn (\"crxor 6,6,6\", operands);
7520
7521   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
7522     output_asm_insn (\"creqv 6,6,6\", operands);
7523
7524   return (flag_pic == 1) ? \"bl %z1@plt\" : \"bl %z1\";
7525 }"
7526   [(set_attr "type" "branch")
7527    (set_attr "length" "4,8")])
7528
7529 ;; Call subroutine returning any type.
7530 (define_expand "untyped_call"
7531   [(parallel [(call (match_operand 0 "" "")
7532                     (const_int 0))
7533               (match_operand 1 "" "")
7534               (match_operand 2 "" "")])]
7535   ""
7536   "
7537 {
7538   int i;
7539
7540   emit_call_insn (gen_call (operands[0], const0_rtx, const0_rtx, const0_rtx));
7541
7542   for (i = 0; i < XVECLEN (operands[2], 0); i++)
7543     {
7544       rtx set = XVECEXP (operands[2], 0, i);
7545       emit_move_insn (SET_DEST (set), SET_SRC (set));
7546     }
7547
7548   /* The optimizer does not know that the call sets the function value
7549      registers we stored in the result block.  We avoid problems by
7550      claiming that all hard registers are used and clobbered at this
7551      point.  */
7552   emit_insn (gen_blockage ());
7553
7554   DONE;
7555 }")
7556
7557 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
7558 ;; all of memory.  This blocks insns from being moved across this point.
7559
7560 (define_insn "blockage"
7561   [(unspec_volatile [(const_int 0)] 0)]
7562   ""
7563   "")
7564
7565 ;; V.4 specific code to initialize the PIC register
7566
7567 (define_insn "init_v4_pic"
7568   [(set (match_operand:SI 0 "register_operand" "=l")
7569         (unspec [(const_int 0)] 7))]
7570   "DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS"
7571   "bl _GLOBAL_OFFSET_TABLE_@local-4"
7572   [(set_attr "type" "branch")
7573    (set_attr "length" "4")])
7574
7575 \f
7576 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
7577 ;; signed & unsigned, and one type of branch.
7578 ;;
7579 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
7580 ;; insns, and branches.  We store the operands of compares until we see
7581 ;; how it is used.
7582 (define_expand "cmpsi"
7583   [(set (cc0)
7584         (compare (match_operand:SI 0 "gpc_reg_operand" "")
7585                  (match_operand:SI 1 "reg_or_short_operand" "")))]
7586   ""
7587   "
7588 {
7589   /* Take care of the possibility that operands[1] might be negative but
7590      this might be a logical operation.  That insn doesn't exist.  */
7591   if (GET_CODE (operands[1]) == CONST_INT
7592       && INTVAL (operands[1]) < 0)
7593     operands[1] = force_reg (SImode, operands[1]);
7594
7595   rs6000_compare_op0 = operands[0];
7596   rs6000_compare_op1 = operands[1];
7597   rs6000_compare_fp_p = 0;
7598   DONE;
7599 }")
7600
7601 (define_expand "cmpdi"
7602   [(set (cc0)
7603         (compare (match_operand:DI 0 "gpc_reg_operand" "")
7604                  (match_operand:DI 1 "reg_or_short_operand" "")))]
7605   "TARGET_POWERPC64"
7606   "
7607 {
7608   /* Take care of the possibility that operands[1] might be negative but
7609      this might be a logical operation.  That insn doesn't exist.  */
7610   if (GET_CODE (operands[1]) == CONST_INT
7611       && INTVAL (operands[1]) < 0)
7612     operands[1] = force_reg (DImode, operands[1]);
7613
7614   rs6000_compare_op0 = operands[0];
7615   rs6000_compare_op1 = operands[1];
7616   rs6000_compare_fp_p = 0;
7617   DONE;
7618 }")
7619
7620 (define_expand "cmpsf"
7621   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
7622                        (match_operand:SF 1 "gpc_reg_operand" "")))]
7623   "TARGET_HARD_FLOAT"
7624   "
7625 {
7626   rs6000_compare_op0 = operands[0];
7627   rs6000_compare_op1 = operands[1];
7628   rs6000_compare_fp_p = 1;
7629   DONE;
7630 }")
7631
7632 (define_expand "cmpdf"
7633   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
7634                        (match_operand:DF 1 "gpc_reg_operand" "")))]
7635   "TARGET_HARD_FLOAT"
7636   "
7637 {
7638   rs6000_compare_op0 = operands[0];
7639   rs6000_compare_op1 = operands[1];
7640   rs6000_compare_fp_p = 1;
7641   DONE;
7642 }")
7643
7644 (define_expand "beq"
7645   [(set (match_dup 2) (match_dup 1))
7646    (set (pc)
7647         (if_then_else (eq (match_dup 2)
7648                           (const_int 0))
7649                       (label_ref (match_operand 0 "" ""))
7650                       (pc)))]
7651   ""
7652   "
7653 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7654   operands[1] = gen_rtx (COMPARE, mode,
7655                          rs6000_compare_op0, rs6000_compare_op1);
7656   operands[2] = gen_reg_rtx (mode);
7657 }")
7658
7659 (define_expand "bne"
7660   [(set (match_dup 2) (match_dup 1))
7661    (set (pc)
7662         (if_then_else (ne (match_dup 2)
7663                           (const_int 0))
7664                       (label_ref (match_operand 0 "" ""))
7665                       (pc)))]
7666   ""
7667   "
7668 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7669   operands[1] = gen_rtx (COMPARE, mode,
7670                          rs6000_compare_op0, rs6000_compare_op1);
7671   operands[2] = gen_reg_rtx (mode);
7672 }")
7673
7674 (define_expand "blt"
7675   [(set (match_dup 2) (match_dup 1))
7676    (set (pc)
7677         (if_then_else (lt (match_dup 2)
7678                           (const_int 0))
7679                       (label_ref (match_operand 0 "" ""))
7680                       (pc)))]
7681   ""
7682   "
7683 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7684   operands[1] = gen_rtx (COMPARE, mode,
7685                          rs6000_compare_op0, rs6000_compare_op1);
7686   operands[2] = gen_reg_rtx (mode);
7687 }")
7688
7689 (define_expand "bgt"
7690   [(set (match_dup 2) (match_dup 1))
7691    (set (pc)
7692         (if_then_else (gt (match_dup 2)
7693                           (const_int 0))
7694                       (label_ref (match_operand 0 "" ""))
7695                       (pc)))]
7696   ""
7697   "
7698 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7699   operands[1] = gen_rtx (COMPARE, mode,
7700                          rs6000_compare_op0, rs6000_compare_op1);
7701   operands[2] = gen_reg_rtx (mode);
7702 }")
7703
7704 (define_expand "ble"
7705   [(set (match_dup 2) (match_dup 1))
7706    (set (pc)
7707         (if_then_else (le (match_dup 2)
7708                           (const_int 0))
7709                       (label_ref (match_operand 0 "" ""))
7710                       (pc)))]
7711   ""
7712   "
7713 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7714   operands[1] = gen_rtx (COMPARE, mode,
7715                          rs6000_compare_op0, rs6000_compare_op1);
7716   operands[2] = gen_reg_rtx (mode);
7717 }")
7718
7719 (define_expand "bge"
7720   [(set (match_dup 2) (match_dup 1))
7721    (set (pc)
7722         (if_then_else (ge (match_dup 2)
7723                           (const_int 0))
7724                       (label_ref (match_operand 0 "" ""))
7725                       (pc)))]
7726   ""
7727   "
7728 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7729   operands[1] = gen_rtx (COMPARE, mode,
7730                          rs6000_compare_op0, rs6000_compare_op1);
7731   operands[2] = gen_reg_rtx (mode);
7732 }")
7733
7734 (define_expand "bgtu"
7735   [(set (match_dup 2) (match_dup 1))
7736    (set (pc)
7737         (if_then_else (gtu (match_dup 2)
7738                            (const_int 0))
7739                       (label_ref (match_operand 0 "" ""))
7740                       (pc)))]
7741   ""
7742   "
7743 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7744                          rs6000_compare_op0, rs6000_compare_op1);
7745   operands[2] = gen_reg_rtx (CCUNSmode);
7746 }")
7747
7748 (define_expand "bltu"
7749   [(set (match_dup 2) (match_dup 1))
7750    (set (pc)
7751         (if_then_else (ltu (match_dup 2)
7752                            (const_int 0))
7753                       (label_ref (match_operand 0 "" ""))
7754                       (pc)))]
7755   ""
7756   "
7757 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7758                          rs6000_compare_op0, rs6000_compare_op1);
7759   operands[2] = gen_reg_rtx (CCUNSmode);
7760 }")
7761
7762 (define_expand "bgeu"
7763   [(set (match_dup 2) (match_dup 1))
7764    (set (pc)
7765         (if_then_else (geu (match_dup 2)
7766                            (const_int 0))
7767                       (label_ref (match_operand 0 "" ""))
7768                       (pc)))]
7769   ""
7770   "
7771 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7772                          rs6000_compare_op0, rs6000_compare_op1);
7773   operands[2] = gen_reg_rtx (CCUNSmode);
7774 }")
7775
7776 (define_expand "bleu"
7777   [(set (match_dup 2) (match_dup 1))
7778    (set (pc)
7779         (if_then_else (leu (match_dup 2)
7780                            (const_int 0))
7781                       (label_ref (match_operand 0 "" ""))
7782                       (pc)))]
7783   ""
7784   "
7785 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7786                          rs6000_compare_op0, rs6000_compare_op1);
7787   operands[2] = gen_reg_rtx (CCUNSmode);
7788 }")
7789
7790 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
7791 ;; For SEQ, likewise, except that comparisons with zero should be done
7792 ;; with an scc insns.  However, due to the order that combine see the
7793 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
7794 ;; the cases we don't want to handle.
7795 (define_expand "seq"
7796   [(set (match_dup 2) (match_dup 1))
7797    (set (match_operand:SI 0 "gpc_reg_operand" "")
7798         (eq:SI (match_dup 2) (const_int 0)))]
7799   ""
7800   "
7801 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7802   operands[1] = gen_rtx (COMPARE, mode,
7803                          rs6000_compare_op0, rs6000_compare_op1);
7804   operands[2] = gen_reg_rtx (mode);
7805 }")
7806
7807 (define_expand "sne"
7808   [(set (match_dup 2) (match_dup 1))
7809    (set (match_operand:SI 0 "gpc_reg_operand" "")
7810         (ne:SI (match_dup 2) (const_int 0)))]
7811   ""
7812   "
7813 { if (! rs6000_compare_fp_p)
7814     FAIL;
7815
7816   operands[1] = gen_rtx (COMPARE, CCFPmode,
7817                          rs6000_compare_op0, rs6000_compare_op1);
7818   operands[2] = gen_reg_rtx (CCFPmode);
7819 }")
7820
7821 ;; A > 0 is best done using the portable sequence, so fail in that case.
7822 (define_expand "sgt"
7823   [(set (match_dup 2) (match_dup 1))
7824    (set (match_operand:SI 0 "gpc_reg_operand" "")
7825         (gt:SI (match_dup 2) (const_int 0)))]
7826   ""
7827   "
7828 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7829
7830   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
7831     FAIL;
7832
7833   operands[1] = gen_rtx (COMPARE, mode,
7834                          rs6000_compare_op0, rs6000_compare_op1);
7835   operands[2] = gen_reg_rtx (mode);
7836 }")
7837
7838 ;; A < 0 is best done in the portable way for A an integer.
7839 (define_expand "slt"
7840   [(set (match_dup 2) (match_dup 1))
7841    (set (match_operand:SI 0 "gpc_reg_operand" "")
7842         (lt:SI (match_dup 2) (const_int 0)))]
7843   ""
7844   "
7845 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7846
7847   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
7848     FAIL;
7849
7850   operands[1] = gen_rtx (COMPARE, mode,
7851                          rs6000_compare_op0, rs6000_compare_op1);
7852   operands[2] = gen_reg_rtx (mode);
7853 }")
7854
7855 (define_expand "sge"
7856   [(set (match_dup 2) (match_dup 1))
7857    (set (match_operand:SI 0 "gpc_reg_operand" "")
7858         (ge:SI (match_dup 2) (const_int 0)))]
7859   ""
7860   "
7861 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7862   operands[1] = gen_rtx (COMPARE, mode,
7863                          rs6000_compare_op0, rs6000_compare_op1);
7864   operands[2] = gen_reg_rtx (mode);
7865 }")
7866
7867 ;; A <= 0 is best done the portable way for A an integer.
7868 (define_expand "sle"
7869   [(set (match_dup 2) (match_dup 1))
7870    (set (match_operand:SI 0 "gpc_reg_operand" "")
7871         (le:SI (match_dup 2) (const_int 0)))]
7872   ""
7873   "
7874 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7875
7876   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
7877     FAIL;
7878
7879   operands[1] = gen_rtx (COMPARE, mode,
7880                          rs6000_compare_op0, rs6000_compare_op1);
7881   operands[2] = gen_reg_rtx (mode);
7882 }")
7883
7884 (define_expand "sgtu"
7885   [(set (match_dup 2) (match_dup 1))
7886    (set (match_operand:SI 0 "gpc_reg_operand" "")
7887         (gtu:SI (match_dup 2) (const_int 0)))]
7888   ""
7889   "
7890 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7891                          rs6000_compare_op0, rs6000_compare_op1);
7892   operands[2] = gen_reg_rtx (CCUNSmode);
7893 }")
7894
7895 (define_expand "sltu"
7896   [(set (match_dup 2) (match_dup 1))
7897    (set (match_operand:SI 0 "gpc_reg_operand" "")
7898         (ltu:SI (match_dup 2) (const_int 0)))]
7899   ""
7900   "
7901 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7902                          rs6000_compare_op0, rs6000_compare_op1);
7903   operands[2] = gen_reg_rtx (CCUNSmode);
7904 }")
7905
7906 (define_expand "sgeu"
7907   [(set (match_dup 2) (match_dup 1))
7908    (set (match_operand:SI 0 "gpc_reg_operand" "")
7909         (geu:SI (match_dup 2) (const_int 0)))]
7910   ""
7911   "
7912 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7913                          rs6000_compare_op0, rs6000_compare_op1);
7914   operands[2] = gen_reg_rtx (CCUNSmode);
7915 }")
7916
7917 (define_expand "sleu"
7918   [(set (match_dup 2) (match_dup 1))
7919    (set (match_operand:SI 0 "gpc_reg_operand" "")
7920         (leu:SI (match_dup 2) (const_int 0)))]
7921   ""
7922   "
7923 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7924                          rs6000_compare_op0, rs6000_compare_op1);
7925   operands[2] = gen_reg_rtx (CCUNSmode);
7926 }")
7927 \f
7928 ;; Here are the actual compare insns.
7929 (define_insn ""
7930   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
7931         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
7932                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
7933   ""
7934   "{cmp%I2|cmpw%I2} %0,%1,%2"
7935   [(set_attr "type" "compare")])
7936
7937 (define_insn ""
7938   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
7939         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
7940                     (match_operand:DI 2 "reg_or_short_operand" "rI")))]
7941   "TARGET_POWERPC64"
7942   "cmpd%I2 %0,%1,%2"
7943   [(set_attr "type" "compare")])
7944
7945 ;; If we are comparing a register for equality with a large constant,
7946 ;; we can do this with an XOR followed by a compare.  But we need a scratch
7947 ;; register for the result of the XOR.
7948
7949 (define_split
7950   [(set (match_operand:CC 0 "cc_reg_operand" "")
7951         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7952                     (match_operand:SI 2 "non_short_cint_operand" "")))
7953    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
7954   "find_single_use (operands[0], insn, 0)
7955    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
7956        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
7957   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
7958    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
7959   "
7960 {
7961   /* Get the constant we are comparing against, C,  and see what it looks like
7962      sign-extended to 16 bits.  Then see what constant could be XOR'ed
7963      with C to get the sign-extended value.  */
7964
7965   int c = INTVAL (operands[2]);
7966   int sextc = (c << 16) >> 16;
7967   int xorv = c ^ sextc;
7968
7969   operands[4] = gen_rtx (CONST_INT, VOIDmode, xorv);
7970   operands[5] = gen_rtx (CONST_INT, VOIDmode, sextc);
7971 }")
7972
7973 (define_insn ""
7974   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
7975         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
7976                        (match_operand:SI 2 "reg_or_u_short_operand" "rI")))]
7977   ""
7978   "{cmpl%I2|cmplw%I2} %0,%1,%W2"
7979   [(set_attr "type" "compare")])
7980
7981 (define_insn ""
7982   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
7983         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
7984                        (match_operand:DI 2 "reg_or_u_short_operand" "rI")))]
7985   ""
7986   "cmpld%I2 %0,%1,%W2"
7987   [(set_attr "type" "compare")])
7988
7989 ;; The following two insns don't exist as single insns, but if we provide
7990 ;; them, we can swap an add and compare, which will enable us to overlap more
7991 ;; of the required delay between a compare and branch.  We generate code for
7992 ;; them by splitting.
7993
7994 (define_insn ""
7995   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
7996         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
7997                     (match_operand:SI 2 "short_cint_operand" "i")))
7998    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
7999         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
8000   ""
8001   "#"
8002   [(set_attr "length" "8")])
8003
8004 (define_insn ""
8005   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
8006         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
8007                        (match_operand:SI 2 "u_short_cint_operand" "i")))
8008    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8009         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
8010   ""
8011   "#"
8012   [(set_attr "length" "8")])
8013
8014 (define_split
8015   [(set (match_operand:CC 3 "cc_reg_operand" "")
8016         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
8017                     (match_operand:SI 2 "short_cint_operand" "")))
8018    (set (match_operand:SI 0 "gpc_reg_operand" "")
8019         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
8020   ""
8021   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
8022    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
8023
8024 (define_split
8025   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
8026         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
8027                        (match_operand:SI 2 "u_short_cint_operand" "")))
8028    (set (match_operand:SI 0 "gpc_reg_operand" "")
8029         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
8030   ""
8031   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
8032    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
8033
8034 (define_insn ""
8035   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
8036         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
8037                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
8038   "TARGET_HARD_FLOAT"
8039   "fcmpu %0,%1,%2"
8040   [(set_attr "type" "fpcompare")])
8041
8042 (define_insn ""
8043   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
8044         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
8045                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
8046   "TARGET_HARD_FLOAT"
8047   "fcmpu %0,%1,%2"
8048   [(set_attr "type" "fpcompare")])
8049 \f
8050 ;; Now we have the scc insns.  We can do some combinations because of the
8051 ;; way the machine works.
8052 ;;
8053 ;; Note that this is probably faster if we can put an insn between the
8054 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
8055 ;; cases the insns below which don't use an intermediate CR field will
8056 ;; be used instead.
8057 (define_insn ""
8058   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8059         (match_operator:SI 1 "scc_comparison_operator"
8060                            [(match_operand 2 "cc_reg_operand" "y")
8061                             (const_int 0)]))]
8062   ""
8063   "%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%J1,1"
8064   [(set_attr "length" "12")])
8065
8066 (define_insn ""
8067   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8068         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
8069                                        [(match_operand 2 "cc_reg_operand" "y")
8070                                         (const_int 0)])
8071                     (const_int 0)))
8072    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
8073         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
8074   ""
8075   "%D1mfcr %3\;{rlinm.|rlwinm.} %3,%3,%J1,1"
8076   [(set_attr "type" "delayed_compare")
8077    (set_attr "length" "12")])
8078
8079 (define_insn ""
8080   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8081         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
8082                                       [(match_operand 2 "cc_reg_operand" "y")
8083                                        (const_int 0)])
8084                    (match_operand:SI 3 "const_int_operand" "n")))]
8085   ""
8086   "*
8087 {
8088   int is_bit = ccr_bit (operands[1], 1);
8089   int put_bit = 31 - (INTVAL (operands[3]) & 31);
8090   int count;
8091
8092   if (is_bit >= put_bit)
8093     count = is_bit - put_bit;
8094   else
8095     count = 32 - (put_bit - is_bit);
8096
8097   operands[4] = gen_rtx (CONST_INT, VOIDmode, count);
8098   operands[5] = gen_rtx (CONST_INT, VOIDmode, put_bit);
8099
8100   return \"%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
8101 }"
8102  [(set_attr "length" "12")])
8103
8104 (define_insn ""
8105   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8106         (compare:CC
8107          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
8108                                        [(match_operand 2 "cc_reg_operand" "y")
8109                                         (const_int 0)])
8110                     (match_operand:SI 3 "const_int_operand" "n"))
8111          (const_int 0)))
8112    (set (match_operand:SI 4 "gpc_reg_operand" "=r")
8113         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
8114                    (match_dup 3)))]
8115   ""
8116   "*
8117 {
8118   int is_bit = ccr_bit (operands[1], 1);
8119   int put_bit = 31 - (INTVAL (operands[3]) & 31);
8120   int count;
8121
8122   if (is_bit >= put_bit)
8123     count = is_bit - put_bit;
8124   else
8125     count = 32 - (put_bit - is_bit);
8126
8127   operands[5] = gen_rtx (CONST_INT, VOIDmode, count);
8128   operands[6] = gen_rtx (CONST_INT, VOIDmode, put_bit);
8129
8130   return \"%D1mfcr %4\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
8131 }"
8132   [(set_attr "type" "delayed_compare")
8133    (set_attr "length" "12")])
8134
8135 ;; If we are comparing the result of two comparisons, this can be done
8136 ;; using creqv or crxor.
8137
8138 (define_insn ""
8139   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
8140         (compare:CCEQ (match_operator 1 "scc_comparison_operator"
8141                               [(match_operand 2 "cc_reg_operand" "y")
8142                                (const_int 0)])
8143                       (match_operator 3 "scc_comparison_operator"
8144                               [(match_operand 4 "cc_reg_operand" "y")
8145                                (const_int 0)])))]
8146   "REGNO (operands[2]) != REGNO (operands[4])"
8147   "*
8148 {
8149   enum rtx_code code1, code2;
8150
8151   code1 = GET_CODE (operands[1]);
8152   code2 = GET_CODE (operands[3]);
8153
8154   if ((code1 == EQ || code1 == LT || code1 == GT
8155        || code1 == LTU || code1 == GTU
8156        || (code1 != NE && GET_MODE (operands[2]) == CCFPmode))
8157       !=
8158       (code2 == EQ || code2 == LT || code2 == GT
8159        || code2 == LTU || code2 == GTU
8160        || (code2 != NE && GET_MODE (operands[4]) == CCFPmode)))
8161     return \"%C1%C3crxor %E0,%j1,%j3\";
8162   else
8163     return \"%C1%C3creqv %E0,%j1,%j3\";
8164 }"
8165   [(set_attr "length" "12")])
8166
8167 ;; There is a 3 cycle delay between consecutive mfcr instructions
8168 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
8169
8170 (define_peephole
8171   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8172         (match_operator:SI 1 "scc_comparison_operator"
8173                            [(match_operand 2 "cc_reg_operand" "y")
8174                             (const_int 0)]))
8175    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
8176         (match_operator:SI 4 "scc_comparison_operator"
8177                            [(match_operand 5 "cc_reg_operand" "y")
8178                             (const_int 0)]))]
8179    "REGNO (operands[2]) != REGNO (operands[5])"
8180    "%D1%D4mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
8181    [(set_attr "length" "20")])
8182
8183 ;; There are some scc insns that can be done directly, without a compare.
8184 ;; These are faster because they don't involve the communications between
8185 ;; the FXU and branch units.   In fact, we will be replacing all of the
8186 ;; integer scc insns here or in the portable methods in emit_store_flag.
8187 ;;
8188 ;; Also support (neg (scc ..)) since that construct is used to replace
8189 ;; branches, (plus (scc ..) ..) since that construct is common and
8190 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
8191 ;; cases where it is no more expensive than (neg (scc ..)).
8192
8193 ;; Have reload force a constant into a register for the simple insns that
8194 ;; otherwise won't accept constants.  We do this because it is faster than
8195 ;; the cmp/mfcr sequence we would otherwise generate.
8196
8197 (define_insn ""
8198   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
8199         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
8200                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I")))
8201    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
8202   ""
8203   "@
8204    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
8205    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
8206    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
8207    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
8208    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
8209   [(set_attr "length" "12,8,12,12,12")])
8210
8211 (define_insn ""
8212   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x")
8213         (compare:CC
8214          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
8215                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
8216          (const_int 0)))
8217    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
8218         (eq:SI (match_dup 1) (match_dup 2)))
8219    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
8220   ""
8221   "@
8222    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
8223    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
8224    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
8225    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
8226    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0"
8227   [(set_attr "type" "compare")
8228    (set_attr "length" "12,8,12,12,12")])
8229
8230 ;; We have insns of the form shown by the first define_insn below.  If
8231 ;; there is something inside the comparison operation, we must split it.
8232 (define_split
8233   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8234         (plus:SI (match_operator 1 "comparison_operator"
8235                                  [(match_operand:SI 2 "" "")
8236                                   (match_operand:SI 3
8237                                                     "reg_or_cint_operand" "")])
8238                  (match_operand:SI 4 "gpc_reg_operand" "")))
8239    (clobber (match_operand:SI 5 "register_operand" ""))]
8240   "! gpc_reg_operand (operands[2], SImode)"
8241   [(set (match_dup 5) (match_dup 2))
8242    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
8243                                (match_dup 4)))])
8244
8245 (define_insn ""
8246   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
8247         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
8248                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
8249                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))
8250    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
8251   ""
8252   "@
8253    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
8254    {sfi|subfic} %4,%1,0\;{aze|addze} %0,%3
8255    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
8256    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
8257    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3"
8258   [(set_attr "length" "12,8,12,12,12")])
8259
8260 (define_insn ""
8261   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x")
8262         (compare:CC
8263          (plus:SI
8264           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
8265                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
8266           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r"))
8267          (const_int 0)))
8268    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
8269   ""
8270   "@
8271    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
8272    {sfi|subfic} %4,%1,0\;{aze.|addze.} %0,%3
8273    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
8274    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
8275    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3"
8276   [(set_attr "type" "compare")
8277    (set_attr "length" "12,8,12,12,12")])
8278
8279 (define_insn ""
8280   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x,x,x,x")
8281         (compare:CC
8282          (plus:SI
8283           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
8284                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
8285           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r"))
8286          (const_int 0)))
8287    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
8288         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8289    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
8290   ""
8291   "@
8292    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
8293    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
8294    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
8295    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
8296    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3"
8297   [(set_attr "type" "compare")
8298    (set_attr "length" "12,8,12,12,12")])
8299
8300 (define_insn ""
8301   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
8302         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
8303                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))))]
8304   ""
8305   "@
8306    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
8307    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
8308    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
8309    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
8310    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
8311    [(set_attr "length" "12,8,12,12,12")])
8312
8313 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
8314 ;; since it nabs/sr is just as fast.
8315 (define_insn ""
8316   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8317         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
8318                      (const_int 31)))
8319    (clobber (match_scratch:SI 2 "=&r"))]
8320   "!TARGET_POWER"
8321   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
8322   [(set_attr "length" "8")])
8323
8324 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
8325 (define_insn ""
8326   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8327         (plus:SI (lshiftrt:SI
8328                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
8329                   (const_int 31))
8330                  (match_operand:SI 2 "gpc_reg_operand" "r")))
8331    (clobber (match_scratch:SI 3 "=&r"))]
8332   ""
8333   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
8334   [(set_attr "length" "8")])
8335
8336 (define_insn ""
8337   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8338         (compare:CC
8339          (plus:SI (lshiftrt:SI
8340                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
8341                    (const_int 31))
8342                   (match_operand:SI 2 "gpc_reg_operand" "r"))
8343          (const_int 0)))
8344    (clobber (match_scratch:SI 3 "=&r"))]
8345   ""
8346   "{ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2"
8347   [(set_attr "type" "compare")
8348    (set_attr "length" "8")])
8349
8350 (define_insn ""
8351   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
8352         (compare:CC
8353          (plus:SI (lshiftrt:SI
8354                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
8355                    (const_int 31))
8356                   (match_operand:SI 2 "gpc_reg_operand" "r"))
8357          (const_int 0)))
8358    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8359         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
8360                  (match_dup 2)))
8361    (clobber (match_scratch:SI 3 "=&r"))]
8362   ""
8363   "{ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2"
8364   [(set_attr "type" "compare")
8365    (set_attr "length" "8")])
8366
8367 (define_insn ""
8368   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8369         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8370                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
8371    (clobber (match_scratch:SI 3 "=r,X"))]
8372   "TARGET_POWER"
8373   "@
8374    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
8375    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
8376   [(set_attr "length" "12")])
8377
8378 (define_insn ""
8379   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x")
8380         (compare:CC
8381          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8382                 (match_operand:SI 2 "reg_or_short_operand" "r,O"))
8383          (const_int 0)))
8384    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8385         (le:SI (match_dup 1) (match_dup 2)))
8386    (clobber (match_scratch:SI 3 "=r,X"))]
8387   "TARGET_POWER"
8388   "@
8389    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
8390    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31"
8391   [(set_attr "type" "compare,delayed_compare")
8392    (set_attr "length" "12")])
8393
8394 (define_insn ""
8395   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8396         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8397                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
8398                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))
8399    (clobber (match_scratch:SI 4 "=&r,&r"))]
8400   "TARGET_POWER"
8401   "@
8402    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
8403    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze|addze} %0,%3"
8404   [(set_attr "length" "12")])
8405
8406 (define_insn ""
8407   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
8408         (compare:CC
8409          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8410                          (match_operand:SI 2 "reg_or_short_operand" "r,O"))
8411                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8412          (const_int 0)))
8413    (clobber (match_scratch:SI 4 "=&r,&r"))]
8414   "TARGET_POWER"
8415   "@
8416    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
8417    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3"
8418   [(set_attr "type" "compare")
8419    (set_attr "length" "12")])
8420
8421 (define_insn ""
8422   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
8423         (compare:CC
8424          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8425                          (match_operand:SI 2 "reg_or_short_operand" "r,O"))
8426                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8427          (const_int 0)))
8428    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8429         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8430    (clobber (match_scratch:SI 4 "=&r,&r"))]
8431   "TARGET_POWER"
8432   "@
8433    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
8434    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %0,%3"
8435   [(set_attr "type" "compare")
8436    (set_attr "length" "12")])
8437
8438 (define_insn ""
8439   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8440         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8441                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
8442   "TARGET_POWER"
8443   "@
8444    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
8445    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
8446   [(set_attr "length" "12")])
8447
8448 (define_insn ""
8449   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8450         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8451                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
8452   ""
8453   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
8454   [(set_attr "length" "12")])
8455
8456 (define_insn ""
8457   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
8458         (compare:CC
8459          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8460                  (match_operand:SI 2 "reg_or_short_operand" "rI"))
8461          (const_int 0)))
8462    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8463         (leu:SI (match_dup 1) (match_dup 2)))]
8464    ""
8465   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0"
8466   [(set_attr "type" "compare")
8467    (set_attr "length" "12")])
8468
8469 (define_insn ""
8470   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8471         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8472                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
8473                  (match_operand:SI 3 "gpc_reg_operand" "r")))
8474    (clobber (match_scratch:SI 4 "=&r"))]
8475   ""
8476   "{sf%I2|subf%I2c} %4,%1,%2\;{aze|addze} %0,%3"
8477   [(set_attr "length" "8")])
8478
8479 (define_insn ""
8480   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8481         (compare:CC
8482          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8483                           (match_operand:SI 2 "reg_or_short_operand" "rI"))
8484                   (match_operand:SI 3 "gpc_reg_operand" "r"))
8485          (const_int 0)))
8486    (clobber (match_scratch:SI 4 "=&r"))]
8487   ""
8488   "{sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3"
8489   [(set_attr "type" "compare")
8490    (set_attr "length" "8")])
8491
8492 (define_insn ""
8493   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
8494         (compare:CC
8495          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8496                           (match_operand:SI 2 "reg_or_short_operand" "rI"))
8497                   (match_operand:SI 3 "gpc_reg_operand" "r"))
8498          (const_int 0)))
8499    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8500         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8501    (clobber (match_scratch:SI 4 "=&r"))]
8502   ""
8503   "{sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %0,%3"
8504   [(set_attr "type" "compare")
8505    (set_attr "length" "8")])
8506
8507 (define_insn ""
8508   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8509         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8510                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
8511   ""
8512   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
8513    [(set_attr "length" "12")])
8514
8515 (define_insn ""
8516   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8517         (and:SI (neg:SI
8518                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8519                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
8520                 (match_operand:SI 3 "gpc_reg_operand" "r")))
8521    (clobber (match_scratch:SI 4 "=&r"))]
8522   ""
8523   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4"
8524   [(set_attr "length" "12")])
8525
8526 (define_insn ""
8527   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8528         (compare:CC
8529          (and:SI (neg:SI
8530                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8531                           (match_operand:SI 2 "reg_or_short_operand" "rI")))
8532                  (match_operand:SI 3 "gpc_reg_operand" "r"))
8533          (const_int 0)))
8534    (clobber (match_scratch:SI 4 "=&r"))]
8535   ""
8536   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4"
8537   [(set_attr "type" "compare")
8538    (set_attr "length" "12")])
8539
8540 (define_insn ""
8541   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
8542         (compare:CC
8543          (and:SI (neg:SI
8544                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8545                           (match_operand:SI 2 "reg_or_short_operand" "rI")))
8546                  (match_operand:SI 3 "gpc_reg_operand" "r"))
8547          (const_int 0)))
8548    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8549         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
8550    (clobber (match_scratch:SI 4 "=&r"))]
8551   ""
8552   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4"
8553   [(set_attr "type" "compare")
8554    (set_attr "length" "12")])
8555
8556 (define_insn ""
8557   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8558         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8559                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
8560   "TARGET_POWER"
8561   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
8562    [(set_attr "length" "12")])
8563
8564 (define_insn ""
8565   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
8566         (compare:CC
8567          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8568                 (match_operand:SI 2 "reg_or_short_operand" "rI"))
8569          (const_int 0)))
8570    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8571         (lt:SI (match_dup 1) (match_dup 2)))]
8572   "TARGET_POWER"
8573   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31"
8574   [(set_attr "type" "delayed_compare")
8575    (set_attr "length" "12")])
8576
8577 (define_insn ""
8578   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8579         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8580                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
8581                  (match_operand:SI 3 "gpc_reg_operand" "r")))
8582    (clobber (match_scratch:SI 4 "=&r"))]
8583   "TARGET_POWER"
8584   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze|addze} %0,%3"
8585   [(set_attr "length" "12")])
8586
8587 (define_insn ""
8588   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8589         (compare:CC
8590          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8591                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
8592                   (match_operand:SI 3 "gpc_reg_operand" "r"))
8593          (const_int 0)))
8594    (clobber (match_scratch:SI 4 "=&r"))]
8595   "TARGET_POWER"
8596   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3"
8597   [(set_attr "type" "compare")
8598    (set_attr "length" "12")])
8599
8600 (define_insn ""
8601   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
8602         (compare:CC
8603          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8604                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
8605                   (match_operand:SI 3 "gpc_reg_operand" "r"))
8606          (const_int 0)))
8607    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8608         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8609    (clobber (match_scratch:SI 4 "=&r"))]
8610   "TARGET_POWER"
8611   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %0,%3"
8612   [(set_attr "type" "compare")
8613    (set_attr "length" "12")])
8614
8615 (define_insn ""
8616   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8617         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8618                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
8619   "TARGET_POWER"
8620   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
8621   [(set_attr "length" "12")])
8622
8623 (define_insn ""
8624   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8625         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8626                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
8627   ""
8628   "@
8629    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg %0,%0
8630    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
8631   [(set_attr "length" "12")])
8632
8633 (define_insn ""
8634   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
8635         (compare:CC
8636          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8637                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8638          (const_int 0)))
8639    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8640         (ltu:SI (match_dup 1) (match_dup 2)))]
8641   ""
8642   "@
8643    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
8644    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0"
8645   [(set_attr "type" "compare")
8646    (set_attr "length" "12")])
8647
8648 (define_insn ""
8649   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
8650         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
8651                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,r,P,P"))
8652                  (match_operand:SI 3 "reg_or_short_operand" "r,I,r,I")))
8653    (clobber (match_scratch:SI 4 "=&r,r,&r,r"))]
8654   ""
8655   "@
8656   {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
8657   {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
8658   {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
8659   {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3"
8660  [(set_attr "length" "12")])
8661
8662 (define_insn ""
8663   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
8664         (compare:CC
8665          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8666                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8667                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8668          (const_int 0)))
8669    (clobber (match_scratch:SI 4 "=&r,&r"))]
8670   ""
8671   "@
8672    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
8673    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3"
8674   [(set_attr "type" "compare")
8675    (set_attr "length" "12")])
8676
8677 (define_insn ""
8678   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
8679         (compare:CC
8680          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8681                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8682                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8683          (const_int 0)))
8684    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8685         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8686    (clobber (match_scratch:SI 4 "=&r,&r"))]
8687   ""
8688   "@
8689    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3
8690    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
8691   [(set_attr "type" "compare")
8692    (set_attr "length" "12")])
8693
8694 (define_insn ""
8695   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8696         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8697                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
8698   ""
8699   "@
8700    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
8701    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
8702   [(set_attr "length" "8")])
8703
8704 (define_insn ""
8705   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8706         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8707                (match_operand:SI 2 "reg_or_short_operand" "rI")))
8708    (clobber (match_scratch:SI 3 "=r"))]
8709   "TARGET_POWER"
8710   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
8711    [(set_attr "length" "12")])
8712
8713 (define_insn ""
8714   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
8715         (compare:CC
8716          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8717                 (match_operand:SI 2 "reg_or_short_operand" "rI"))
8718          (const_int 0)))
8719    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8720         (ge:SI (match_dup 1) (match_dup 2)))
8721    (clobber (match_scratch:SI 3 "=r"))]
8722   "TARGET_POWER"
8723   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3"
8724   [(set_attr "type" "compare")
8725    (set_attr "length" "12")])
8726
8727 (define_insn ""
8728   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8729         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8730                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
8731                  (match_operand:SI 3 "gpc_reg_operand" "r")))
8732    (clobber (match_scratch:SI 4 "=&r"))]
8733   "TARGET_POWER"
8734   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3"
8735   [(set_attr "length" "12")])
8736
8737 (define_insn ""
8738   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8739         (compare:CC
8740          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8741                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
8742                   (match_operand:SI 3 "gpc_reg_operand" "r"))
8743          (const_int 0)))
8744    (clobber (match_scratch:SI 4 "=&r"))]
8745   "TARGET_POWER"
8746   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3"
8747   [(set_attr "type" "compare")
8748    (set_attr "length" "12")])
8749
8750 (define_insn ""
8751   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
8752         (compare:CC
8753          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8754                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
8755                   (match_operand:SI 3 "gpc_reg_operand" "r"))
8756          (const_int 0)))
8757    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8758         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8759    (clobber (match_scratch:SI 4 "=&r"))]
8760   "TARGET_POWER"
8761   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3"
8762   [(set_attr "type" "compare")
8763    (set_attr "length" "12")])
8764
8765 (define_insn ""
8766   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8767         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8768                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
8769   "TARGET_POWER"
8770   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
8771   [(set_attr "length" "12")])
8772
8773 ;; This is (and (neg (ge X (const_int 0))) Y).
8774 (define_insn ""
8775   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8776         (and:SI (neg:SI
8777                  (lshiftrt:SI
8778                   (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
8779                   (const_int 31)))
8780                 (match_operand:SI 2 "gpc_reg_operand" "r")))
8781    (clobber (match_scratch:SI 3 "=&r"))]
8782   ""
8783   "{srai|srawi} %3,%1,31\;andc %0,%2,%3"
8784   [(set_attr "length" "8")])
8785
8786 (define_insn ""
8787   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8788         (compare:CC
8789          (and:SI (neg:SI
8790                   (lshiftrt:SI
8791                    (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
8792                    (const_int 31)))
8793                  (match_operand:SI 2 "gpc_reg_operand" "r"))
8794          (const_int 0)))
8795    (clobber (match_scratch:SI 3 "=&r"))]
8796   ""
8797   "{srai|srawi} %3,%1,31\;andc. %3,%2,%3"
8798   [(set_attr "type" "compare")
8799    (set_attr "length" "8")])
8800
8801 (define_insn ""
8802   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
8803         (compare:CC
8804          (and:SI (neg:SI
8805                   (lshiftrt:SI
8806                    (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
8807                    (const_int 31)))
8808                  (match_operand:SI 2 "gpc_reg_operand" "r"))
8809          (const_int 0)))
8810    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8811         (and:SI (neg:SI (lshiftrt:SI (not:SI (match_dup 1))
8812                                      (const_int 31)))
8813                 (match_dup 2)))
8814    (clobber (match_scratch:SI 3 "=&r"))]
8815   ""
8816   "{srai|srawi} %3,%1,31\;andc. %0,%2,%3"
8817   [(set_attr "type" "compare")
8818    (set_attr "length" "8")])
8819
8820 (define_insn ""
8821   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8822         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8823                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
8824   ""
8825   "@
8826    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
8827    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
8828   [(set_attr "length" "12")])
8829
8830 (define_insn ""
8831   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
8832         (compare:CC
8833          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8834                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8835          (const_int 0)))
8836    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8837         (geu:SI (match_dup 1) (match_dup 2)))]
8838   ""
8839   "@
8840    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
8841    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0"
8842   [(set_attr "type" "compare")
8843    (set_attr "length" "12")])
8844
8845 (define_insn ""
8846   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8847         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8848                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8849                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))
8850    (clobber (match_scratch:SI 4 "=&r,&r"))]
8851   ""
8852   "@
8853    {sf|subfc} %4,%2,%1\;{aze|addze} %0,%3
8854    {ai|addic} %4,%1,%n2\;{aze|addze} %0,%3"
8855   [(set_attr "length" "8")])
8856
8857 (define_insn ""
8858   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
8859         (compare:CC
8860          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8861                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8862                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8863          (const_int 0)))
8864    (clobber (match_scratch:SI 4 "=&r,&r"))]
8865   ""
8866   "@
8867    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
8868    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3"
8869   [(set_attr "type" "compare")
8870    (set_attr "length" "8")])
8871
8872 (define_insn ""
8873   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
8874         (compare:CC
8875          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8876                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8877                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8878          (const_int 0)))
8879    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8880         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8881    (clobber (match_scratch:SI 4 "=&r,&r"))]
8882   ""
8883   "@
8884    {sf|subfc} %4,%2,%1\;{aze.|addze.} %0,%3
8885    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3"
8886   [(set_attr "type" "compare")
8887    (set_attr "length" "8")])
8888
8889 (define_insn ""
8890   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8891         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8892                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
8893   ""
8894   "@
8895    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
8896    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
8897   [(set_attr "length" "12")])
8898
8899 (define_insn ""
8900   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8901         (and:SI (neg:SI
8902                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8903                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
8904                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))
8905    (clobber (match_scratch:SI 4 "=&r,&r"))]
8906   ""
8907   "@
8908    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4
8909    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4"
8910   [(set_attr "length" "12")])
8911
8912 (define_insn ""
8913   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
8914         (compare:CC
8915          (and:SI (neg:SI
8916                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8917                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
8918                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8919          (const_int 0)))
8920    (clobber (match_scratch:SI 4 "=&r,&r"))]
8921   ""
8922   "@
8923    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
8924    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4"
8925   [(set_attr "type" "compare")
8926    (set_attr "length" "12")])
8927
8928 (define_insn ""
8929   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
8930         (compare:CC
8931          (and:SI (neg:SI
8932                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8933                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
8934                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8935          (const_int 0)))
8936    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8937         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
8938    (clobber (match_scratch:SI 4 "=&r,&r"))]
8939   ""
8940   "@
8941    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4
8942    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4"
8943   [(set_attr "type" "compare")
8944    (set_attr "length" "12")])
8945
8946 (define_insn ""
8947   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8948         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8949                (const_int 0)))]
8950   ""
8951   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
8952   [(set_attr "length" "12")])
8953
8954 (define_insn ""
8955   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
8956         (compare:CC
8957          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8958                 (const_int 0))
8959          (const_int 0)))
8960    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8961         (gt:SI (match_dup 1) (const_int 0)))]
8962   ""
8963   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31"
8964   [(set_attr "type" "delayed_compare")
8965    (set_attr "length" "12")])
8966
8967 (define_insn ""
8968   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8969         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8970                (match_operand:SI 2 "reg_or_short_operand" "r")))]
8971   "TARGET_POWER"
8972   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
8973   [(set_attr "length" "12")])
8974
8975 (define_insn ""
8976   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
8977         (compare:CC
8978          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8979                 (match_operand:SI 2 "reg_or_short_operand" "r"))
8980          (const_int 0)))
8981    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8982         (gt:SI (match_dup 1) (match_dup 2)))]
8983   "TARGET_POWER"
8984   "doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31"
8985   [(set_attr "type" "delayed_compare")
8986    (set_attr "length" "12")])
8987
8988 (define_insn ""
8989   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8990         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8991                         (const_int 0))
8992                  (match_operand:SI 2 "gpc_reg_operand" "r")))
8993    (clobber (match_scratch:SI 3 "=&r"))]
8994   ""
8995   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze|addze} %0,%2"
8996   [(set_attr "length" "12")])
8997
8998 (define_insn ""
8999   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
9000         (compare:CC
9001          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9002                          (const_int 0))
9003                   (match_operand:SI 2 "gpc_reg_operand" "r"))
9004          (const_int 0)))
9005    (clobber (match_scratch:SI 3 "=&r"))]
9006   ""
9007   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %0,%2"
9008   [(set_attr "type" "compare")
9009    (set_attr "length" "12")])
9010
9011 (define_insn ""
9012   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
9013         (compare:CC
9014          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9015                          (const_int 0))
9016                   (match_operand:SI 2 "gpc_reg_operand" "r"))
9017          (const_int 0)))
9018    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
9019         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
9020    (clobber (match_scratch:SI 3 "=&r"))]
9021   ""
9022   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2"
9023   [(set_attr "type" "compare")
9024    (set_attr "length" "12")])
9025
9026 (define_insn ""
9027   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9028         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9029                         (match_operand:SI 2 "reg_or_short_operand" "r"))
9030                  (match_operand:SI 3 "gpc_reg_operand" "r")))
9031    (clobber (match_scratch:SI 4 "=&r"))]
9032   "TARGET_POWER"
9033   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze|addze} %0,%3"
9034   [(set_attr "length" "12")])
9035
9036 (define_insn ""
9037   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
9038         (compare:CC
9039          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9040                          (match_operand:SI 2 "reg_or_short_operand" "r"))
9041                   (match_operand:SI 3 "gpc_reg_operand" "r"))
9042          (const_int 0)))
9043    (clobber (match_scratch:SI 4 "=&r"))]
9044   "TARGET_POWER"
9045   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3"
9046   [(set_attr "type" "compare")
9047    (set_attr "length" "12")])
9048
9049 (define_insn ""
9050   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
9051         (compare:CC
9052          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9053                          (match_operand:SI 2 "reg_or_short_operand" "r"))
9054                   (match_operand:SI 3 "gpc_reg_operand" "r"))
9055          (const_int 0)))
9056    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
9057         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
9058    (clobber (match_scratch:SI 4 "=&r"))]
9059   "TARGET_POWER"
9060   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %0,%3"
9061   [(set_attr "type" "compare")
9062    (set_attr "length" "12")])
9063
9064 (define_insn ""
9065   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9066         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9067                        (const_int 0))))]
9068   ""
9069   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
9070   [(set_attr "length" "12")])
9071
9072 (define_insn ""
9073   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9074         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9075                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
9076   "TARGET_POWER"
9077   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
9078   [(set_attr "length" "12")])
9079
9080 (define_insn ""
9081   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9082         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9083                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
9084   ""
9085   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
9086   [(set_attr "length" "12")])
9087
9088 (define_insn ""
9089   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
9090         (compare:CC
9091          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9092                  (match_operand:SI 2 "reg_or_short_operand" "rI"))
9093          (const_int 0)))
9094    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
9095         (gtu:SI (match_dup 1) (match_dup 2)))]
9096   ""
9097   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0"
9098   [(set_attr "type" "compare")
9099    (set_attr "length" "12")])
9100
9101 (define_insn ""
9102   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
9103         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
9104                          (match_operand:SI 2 "reg_or_short_operand" "I,r,rI"))
9105                  (match_operand:SI 3 "reg_or_short_operand" "r,r,I")))
9106    (clobber (match_scratch:SI 4 "=&r,&r,&r"))]
9107   ""
9108   "@
9109    {ai|addic} %4,%1,%k2\;{aze|addze} %0,%3
9110    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
9111    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3"
9112   [(set_attr "length" "8,12,12")])
9113
9114 (define_insn ""
9115   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
9116         (compare:CC
9117          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
9118                           (match_operand:SI 2 "reg_or_short_operand" "I,r"))
9119                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9120          (const_int 0)))
9121    (clobber (match_scratch:SI 4 "=&r,&r"))]
9122   ""
9123   "@
9124    {ai|addic} %4,%1,%k2\;{aze.|addze.} %0,%3
9125    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
9126   [(set_attr "type" "compare")
9127    (set_attr "length" "8,12")])
9128
9129 (define_insn ""
9130   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
9131         (compare:CC
9132          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
9133                           (match_operand:SI 2 "reg_or_short_operand" "I,r"))
9134                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9135          (const_int 0)))
9136    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
9137         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
9138    (clobber (match_scratch:SI 4 "=&r,&r"))]
9139   ""
9140   "@
9141    {ai|addic} %4,%1,%k2\;{aze.|addze.} %0,%3
9142    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
9143   [(set_attr "type" "compare")
9144    (set_attr "length" "8,12")])
9145
9146 (define_insn ""
9147   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9148         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9149                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
9150   ""
9151   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
9152   [(set_attr "length" "8")])
9153 \f
9154 ;; Define both directions of branch and return.  If we need a reload
9155 ;; register, we'd rather use CR0 since it is much easier to copy a
9156 ;; register CC value to there.
9157
9158 (define_insn ""
9159   [(set (pc)
9160         (if_then_else (match_operator 1 "branch_comparison_operator"
9161                                       [(match_operand 2
9162                                                       "cc_reg_operand" "x,?y")
9163                                        (const_int 0)])
9164                       (label_ref (match_operand 0 "" ""))
9165                       (pc)))]
9166   ""
9167   "*
9168 {
9169   if (get_attr_length (insn) == 8)
9170     return \"%C1bc %t1,%j1,%l0\";
9171   else
9172     return \"%C1bc %T1,%j1,%$+8\;b %l0\";
9173
9174 }"
9175   [(set_attr "type" "branch")])
9176
9177 (define_insn ""
9178   [(set (pc)
9179         (if_then_else (match_operator 0 "branch_comparison_operator"
9180                                       [(match_operand 1
9181                                                       "cc_reg_operand" "x,?y")
9182                                        (const_int 0)])
9183                       (return)
9184                       (pc)))]
9185   "direct_return ()"
9186   "{%C0bcr|%C0bclr} %t0,%j0"
9187   [(set_attr "type" "branch")
9188    (set_attr "length" "8")])
9189
9190 (define_insn ""
9191   [(set (pc)
9192         (if_then_else (match_operator 1 "branch_comparison_operator"
9193                                       [(match_operand 2
9194                                                       "cc_reg_operand" "x,?y")
9195                                        (const_int 0)])
9196                       (pc)
9197                       (label_ref (match_operand 0 "" ""))))]
9198   ""
9199   "*
9200 {
9201   if (get_attr_length (insn) == 8)
9202     return \"%C1bc %T1,%j1,%l0\";
9203   else
9204     return \"%C1bc %t1,%j1,%$+8\;b %l0\";
9205 }"
9206   [(set_attr "type" "branch")])
9207
9208 (define_insn ""
9209   [(set (pc)
9210         (if_then_else (match_operator 0 "branch_comparison_operator"
9211                                       [(match_operand 1
9212                                                       "cc_reg_operand" "x,?y")
9213                                        (const_int 0)])
9214                       (pc)
9215                       (return)))]
9216   "direct_return ()"
9217   "{%C0bcr|%C0bclr} %T0,%j0"
9218   [(set_attr "type" "branch")
9219    (set_attr "length" "8")])
9220
9221 ;; Unconditional branch and return.
9222
9223 (define_insn "jump"
9224   [(set (pc)
9225         (label_ref (match_operand 0 "" "")))]
9226   ""
9227   "b %l0"
9228   [(set_attr "type" "branch")])
9229
9230 (define_insn "return"
9231   [(return)]
9232   "direct_return ()"
9233   "{br|blr}"
9234   [(set_attr "type" "jmpreg")])
9235
9236 (define_insn "indirect_jump"
9237   [(set (pc) (match_operand:SI 0 "register_operand" "c,l"))]
9238   ""
9239   "@
9240    bctr
9241    {br|blr}"
9242   [(set_attr "type" "jmpreg")])
9243
9244 (define_insn ""
9245   [(set (pc) (match_operand:DI 0 "register_operand" "c,l"))]
9246   "TARGET_POWERPC64"
9247   "@
9248    bctr
9249    {br|blr}"
9250   [(set_attr "type" "jmpreg")])
9251
9252 ;; Table jump for switch statements:
9253 (define_expand "tablejump"
9254   [(use (match_operand 0 "" ""))
9255    (use (label_ref (match_operand 1 "" "")))]
9256   ""
9257   "
9258 {
9259   if (TARGET_32BIT)
9260     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
9261   else
9262     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
9263   DONE;
9264 }")
9265
9266 (define_expand "tablejumpsi"
9267   [(set (match_dup 3)
9268         (plus:SI (match_operand:SI 0 "" "")
9269                  (match_dup 2)))
9270    (parallel [(set (pc) (match_dup 3))
9271               (use (label_ref (match_operand 1 "" "")))])]
9272   ""
9273   "
9274 { operands[0] = force_reg (SImode, operands[0]);
9275   operands[2] = force_reg (SImode, gen_rtx (LABEL_REF, VOIDmode, operands[1]));
9276   operands[3] = gen_reg_rtx (SImode);
9277 }")
9278
9279 (define_expand "tablejumpdi"
9280   [(set (match_dup 3)
9281         (plus:DI (match_operand:DI 0 "" "")
9282                  (match_dup 2)))
9283    (parallel [(set (pc) (match_dup 3))
9284               (use (label_ref (match_operand 1 "" "")))])]
9285   ""
9286   "
9287 { operands[0] = force_reg (DImode, operands[0]);
9288   operands[2] = force_reg (DImode, gen_rtx (LABEL_REF, VOIDmode, operands[1]));
9289   operands[3] = gen_reg_rtx (DImode);
9290 }")
9291
9292 (define_insn ""
9293   [(set (pc)
9294         (match_operand:SI 0 "register_operand" "c,l"))
9295    (use (label_ref (match_operand 1 "" "")))]
9296   ""
9297   "@
9298    bctr
9299    {br|blr}"
9300   [(set_attr "type" "jmpreg")])
9301
9302 (define_insn ""
9303   [(set (pc)
9304         (match_operand:DI 0 "register_operand" "c,l"))
9305    (use (label_ref (match_operand 1 "" "")))]
9306   "TARGET_POWERPC64"
9307   "@
9308    bctr
9309    {br|blr}"
9310   [(set_attr "type" "jmpreg")])
9311
9312 (define_insn "nop"
9313   [(const_int 0)]
9314   ""
9315   "{cror 0,0,0|nop}")
9316 \f
9317 ;; Define the subtract-one-and-jump insns, starting with the template
9318 ;; so loop.c knows what to generate.
9319
9320 (define_expand "decrement_and_branch_on_count"
9321   [(parallel [(set (pc) (if_then_else (ne (match_operand:SI 0 "register_operand" "")
9322                                           (const_int 1))
9323                                       (label_ref (match_operand 1 "" ""))
9324                                       (pc)))
9325               (set (match_dup 0)
9326                    (plus:SI (match_dup 0)
9327                             (const_int -1)))
9328               (clobber (match_scratch:CC 2 ""))
9329               (clobber (match_scratch:SI 3 ""))])]
9330   ""
9331   "")
9332
9333 ;; We need to be able to do this for any operand, including MEM, or we
9334 ;; will cause reload to blow up since we don't allow output reloads on
9335 ;; JUMP_INSNs.
9336 ;; In order that the length attribute is calculated correctly, the
9337 ;; label MUST be operand 0.
9338
9339 (define_insn ""
9340   [(set (pc)
9341         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r")
9342                           (const_int 1))
9343                       (label_ref (match_operand 0 "" ""))
9344                       (pc)))
9345    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
9346         (plus:SI (match_dup 1)
9347                  (const_int -1)))
9348    (clobber (match_scratch:CC 3 "=X,&x,&x"))
9349    (clobber (match_scratch:SI 4 "=X,X,r"))]
9350   ""
9351   "*
9352 {
9353   if (which_alternative != 0)
9354     return \"#\";
9355   else if (get_attr_length (insn) == 8)
9356     return \"{bdn|bdnz} %l0\";
9357   else
9358     return \"bdz %$+8\;b %l0\";
9359 }"
9360   [(set_attr "type" "branch")
9361    (set_attr "length" "*,12,16")])
9362
9363 (define_insn ""
9364   [(set (pc)
9365         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r")
9366                           (const_int 1))
9367                       (pc)
9368                       (label_ref (match_operand 0 "" ""))))
9369    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
9370         (plus:SI (match_dup 1)
9371                  (const_int -1)))
9372    (clobber (match_scratch:CC 3 "=X,&x,&x"))
9373    (clobber (match_scratch:SI 4 "=X,X,r"))]
9374   ""
9375   "*
9376 {
9377   if (which_alternative != 0)
9378     return \"#\";
9379   else if (get_attr_length (insn) == 8)
9380     return \"bdz %l0\";
9381   else
9382     return \"{bdn|bdnz} %$+8\;b %l0\";
9383 }"
9384   [(set_attr "type" "branch")
9385    (set_attr "length" "*,12,16")])
9386
9387 ;; Similar, but we can use GE since we have a REG_NONNEG.
9388 (define_insn ""
9389   [(set (pc)
9390         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r")
9391                           (const_int 0))
9392                       (label_ref (match_operand 0 "" ""))
9393                       (pc)))
9394    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
9395         (plus:SI (match_dup 1)
9396                  (const_int -1)))
9397    (clobber (match_scratch:CC 3 "=X,&x,&X"))
9398    (clobber (match_scratch:SI 4 "=X,X,r"))]
9399   "find_reg_note (insn, REG_NONNEG, 0)"
9400   "*
9401 {
9402   if (which_alternative != 0)
9403     return \"#\";
9404   else if (get_attr_length (insn) == 8)
9405     return \"{bdn|bdnz} %l0\";
9406   else
9407     return \"bdz %$+8\;b %l0\";
9408 }"
9409   [(set_attr "type" "branch")
9410    (set_attr "length" "*,12,16")])
9411
9412 (define_insn ""
9413   [(set (pc)
9414         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r")
9415                           (const_int 0))
9416                       (pc)
9417                       (label_ref (match_operand 0 "" ""))))
9418    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
9419         (plus:SI (match_dup 1)
9420                  (const_int -1)))
9421    (clobber (match_scratch:CC 3 "=X,&x,&X"))
9422    (clobber (match_scratch:SI 4 "=X,X,r"))]
9423   "find_reg_note (insn, REG_NONNEG, 0)"
9424   "*
9425 {
9426   if (which_alternative != 0)
9427     return \"#\";
9428   else if (get_attr_length (insn) == 8)
9429     return \"bdz %l0\";
9430   else
9431     return \"{bdn|bdnz} %$+8\;b %l0\";
9432 }"
9433   [(set_attr "type" "branch")
9434    (set_attr "length" "*,12,16")])
9435
9436 (define_insn ""
9437   [(set (pc)
9438         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r")
9439                           (const_int 1))
9440                       (label_ref (match_operand 0 "" ""))
9441                       (pc)))
9442    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
9443         (plus:SI (match_dup 1)
9444                  (const_int -1)))
9445    (clobber (match_scratch:CC 3 "=X,&x,&x"))
9446    (clobber (match_scratch:SI 4 "=X,X,r"))]
9447   ""
9448   "*
9449 {
9450   if (which_alternative != 0)
9451     return \"#\";
9452   else if (get_attr_length (insn) == 8)
9453     return \"bdz %l0\";
9454   else
9455     return \"{bdn|bdnz} %$+8\;b %l0\";
9456 }"
9457   [(set_attr "type" "branch")
9458    (set_attr "length" "*,12,16")])
9459
9460 (define_insn ""
9461   [(set (pc)
9462         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r")
9463                           (const_int 1))
9464                       (pc)
9465                       (label_ref (match_operand 0 "" ""))))
9466    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
9467         (plus:SI (match_dup 1)
9468                  (const_int -1)))
9469    (clobber (match_scratch:CC 3 "=X,&x,&x"))
9470    (clobber (match_scratch:SI 4 "=X,X,r"))]
9471   ""
9472   "*
9473 {
9474   if (which_alternative != 0)
9475     return \"#\";
9476   else if (get_attr_length (insn) == 8)
9477     return \"{bdn|bdnz} %l0\";
9478   else
9479     return \"bdz %$+8\;b %l0\";
9480 }"
9481   [(set_attr "type" "branch")
9482    (set_attr "length" "*,12,16")])
9483
9484 (define_split
9485   [(set (pc)
9486         (if_then_else (match_operator 2 "comparison_operator"
9487                                       [(match_operand:SI 1 "gpc_reg_operand" "")
9488                                        (const_int 1)])
9489                       (match_operand 5 "" "")
9490                       (match_operand 6 "" "")))
9491    (set (match_operand:SI 0 "gpc_reg_operand" "")
9492         (plus:SI (match_dup 1)
9493                  (const_int -1)))
9494    (clobber (match_scratch:CC 3 ""))
9495    (clobber (match_scratch:SI 4 ""))]
9496   "reload_completed"
9497   [(parallel [(set (match_dup 3)
9498                    (compare:CC (plus:SI (match_dup 1)
9499                                         (const_int -1))
9500                                (const_int 0)))
9501               (set (match_dup 0)
9502                    (plus:SI (match_dup 1)
9503                             (const_int -1)))])
9504    (set (pc) (if_then_else (match_dup 7)
9505                            (match_dup 5)
9506                            (match_dup 6)))]
9507   "
9508 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
9509                          const0_rtx); }")
9510
9511 (define_split
9512   [(set (pc)
9513         (if_then_else (match_operator 2 "comparison_operator"
9514                                       [(match_operand:SI 1 "gpc_reg_operand" "")
9515                                        (const_int 1)])
9516                       (match_operand 5 "" "")
9517                       (match_operand 6 "" "")))
9518    (set (match_operand:SI 0 "general_operand" "")
9519         (plus:SI (match_dup 1) (const_int -1)))
9520    (clobber (match_scratch:CC 3 ""))
9521    (clobber (match_scratch:SI 4 ""))]
9522   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
9523   [(parallel [(set (match_dup 3)
9524                    (compare:CC (plus:SI (match_dup 1)
9525                                         (const_int -1))
9526                                (const_int 0)))
9527               (set (match_dup 4)
9528                    (plus:SI (match_dup 1)
9529                             (const_int -1)))])
9530    (set (match_dup 0)
9531         (match_dup 4))
9532    (set (pc) (if_then_else (match_dup 7)
9533                            (match_dup 5)
9534                            (match_dup 6)))]
9535   "
9536 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
9537                          const0_rtx); }")