OSDN Git Service

(nonlocal_goto_receiver): New pattern.
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 91-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_insn "addsi3"
862   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
863         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
864                  (match_operand:SI 2 "add_operand" "r,I,I,J")))]
865   ""
866   "@
867    {cax|add} %0,%1,%2
868    {cal %0,%2(%1)|addi %0,%1,%2}
869    {ai|addic} %0,%1,%2
870    {cau|addis} %0,%1,%v2")
871
872 (define_insn ""
873   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
874         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
875                              (match_operand:SI 2 "reg_or_short_operand" "r,I"))
876                     (const_int 0)))
877    (clobber (match_scratch:SI 3 "=r,r"))]
878   ""
879   "@
880    {cax.|add.} %3,%1,%2
881    {ai.|addic.} %3,%1,%2"
882   [(set_attr "type" "compare")])
883
884 (define_insn ""
885   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
886         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
887                              (match_operand:SI 2 "reg_or_short_operand" "r,I"))
888                     (const_int 0)))
889    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
890         (plus:SI (match_dup 1) (match_dup 2)))]
891   ""
892   "@
893    {cax.|add.} %0,%1,%2
894    {ai.|addic.} %0,%1,%2"
895   [(set_attr "type" "compare")])
896
897 ;; Split an add that we can't do in one insn into two insns, each of which
898 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
899 ;; add should be last in case the result gets used in an address.
900
901 (define_split
902   [(set (match_operand:SI 0 "gpc_reg_operand" "")
903         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
904                  (match_operand:SI 2 "non_add_cint_operand" "")))]
905   ""
906   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
907    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
908 "
909 {
910   HOST_WIDE_INT low = INTVAL (operands[2]) & 0xffff;
911   HOST_WIDE_INT high = INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff);
912
913   if (low & 0x8000)
914     high += 0x10000, low |= ((HOST_WIDE_INT) -1) << 16;
915
916   operands[3] = GEN_INT (high);
917   operands[4] = GEN_INT (low);
918 }")
919
920 (define_insn "one_cmplsi2"
921   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
922         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
923   ""
924   "nor %0,%1,%1")
925
926 (define_insn ""
927   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
928         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
929                     (const_int 0)))
930    (clobber (match_scratch:SI 2 "=r"))]
931   ""
932   "nor. %2,%1,%1"
933   [(set_attr "type" "compare")])
934
935 (define_insn ""
936   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
937         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
938                     (const_int 0)))
939    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
940         (not:SI (match_dup 1)))]
941   ""
942   "nor. %0,%1,%1"
943   [(set_attr "type" "compare")])
944
945 (define_insn ""
946   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
947         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
948                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
949   "! TARGET_POWERPC"
950   "{sf%I1|subf%I1c} %0,%2,%1")
951
952 (define_insn ""
953   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
954         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
955                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
956   "TARGET_POWERPC"
957   "@
958    subf %0,%2,%1
959    subfic %0,%2,%1")
960
961 (define_insn ""
962   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
963         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
964                               (match_operand:SI 2 "gpc_reg_operand" "r"))
965                     (const_int 0)))
966    (clobber (match_scratch:SI 3 "=r"))]
967   "! TARGET_POWERPC"
968   "{sf.|subfc.} %3,%2,%1"
969   [(set_attr "type" "compare")])
970
971 (define_insn ""
972   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
973         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
974                               (match_operand:SI 2 "gpc_reg_operand" "r"))
975                     (const_int 0)))
976    (clobber (match_scratch:SI 3 "=r"))]
977   "TARGET_POWERPC"
978   "subf. %3,%2,%1"
979   [(set_attr "type" "compare")])
980
981 (define_insn ""
982   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
983         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
984                               (match_operand:SI 2 "gpc_reg_operand" "r"))
985                     (const_int 0)))
986    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
987         (minus:SI (match_dup 1) (match_dup 2)))]
988   "! TARGET_POWERPC"
989   "{sf.|subfc.} %0,%2,%1"
990   [(set_attr "type" "compare")])
991
992 (define_insn ""
993   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
994         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
995                               (match_operand:SI 2 "gpc_reg_operand" "r"))
996                     (const_int 0)))
997    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
998         (minus:SI (match_dup 1) (match_dup 2)))]
999   "TARGET_POWERPC"
1000   "subf. %0,%2,%1"
1001   [(set_attr "type" "compare")])
1002
1003 (define_expand "subsi3"
1004   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1005         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
1006                   (match_operand:SI 2 "reg_or_cint_operand" "")))]
1007   ""
1008   "
1009 {
1010   if (GET_CODE (operands[2]) == CONST_INT)
1011     {
1012       emit_insn (gen_addsi3 (operands[0], operands[1],
1013                              negate_rtx (SImode, operands[2])));
1014       DONE;
1015     }
1016 }")
1017
1018 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1019 ;; instruction and some auxiliary computations.  Then we just have a single
1020 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1021 ;; combine.
1022
1023 (define_expand "sminsi3"
1024   [(set (match_dup 3)
1025         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1026                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1027                          (const_int 0)
1028                          (minus:SI (match_dup 2) (match_dup 1))))
1029    (set (match_operand:SI 0 "gpc_reg_operand" "")
1030         (minus:SI (match_dup 2) (match_dup 3)))]
1031   "TARGET_POWER"
1032   "
1033 { operands[3] = gen_reg_rtx (SImode); }")
1034
1035 (define_split
1036   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1037         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1038                  (match_operand:SI 2 "reg_or_short_operand" "")))
1039    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1040   "TARGET_POWER"
1041   [(set (match_dup 3)
1042         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1043                          (const_int 0)
1044                          (minus:SI (match_dup 2) (match_dup 1))))
1045    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1046   "")
1047
1048 (define_expand "smaxsi3"
1049   [(set (match_dup 3)
1050         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1051                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1052                          (const_int 0)
1053                          (minus:SI (match_dup 2) (match_dup 1))))
1054    (set (match_operand:SI 0 "gpc_reg_operand" "")
1055         (plus:SI (match_dup 3) (match_dup 1)))]
1056   "TARGET_POWER"
1057   "
1058 { operands[3] = gen_reg_rtx (SImode); }")
1059
1060 (define_split
1061   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1062         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1063                  (match_operand:SI 2 "reg_or_short_operand" "")))
1064    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1065   "TARGET_POWER"
1066   [(set (match_dup 3)
1067         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1068                          (const_int 0)
1069                          (minus:SI (match_dup 2) (match_dup 1))))
1070    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1071   "")
1072
1073 (define_expand "uminsi3"
1074   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1075                               (match_dup 5)))
1076    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1077                               (match_dup 5)))
1078    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1079                                        (const_int 0)
1080                                        (minus:SI (match_dup 4) (match_dup 3))))
1081    (set (match_operand:SI 0 "gpc_reg_operand" "")
1082         (minus:SI (match_dup 2) (match_dup 3)))]
1083   "TARGET_POWER"
1084   "
1085 {
1086   operands[3] = gen_reg_rtx (SImode);
1087   operands[4] = gen_reg_rtx (SImode);
1088   operands[5] = GEN_INT (-2147483647 - 1);
1089 }")
1090
1091 (define_expand "umaxsi3"
1092   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1093                               (match_dup 5)))
1094    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1095                               (match_dup 5)))
1096    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1097                                        (const_int 0)
1098                                        (minus:SI (match_dup 4) (match_dup 3))))
1099    (set (match_operand:SI 0 "gpc_reg_operand" "")
1100         (plus:SI (match_dup 3) (match_dup 1)))]
1101   "TARGET_POWER"
1102   "
1103 {
1104   operands[3] = gen_reg_rtx (SImode);
1105   operands[4] = gen_reg_rtx (SImode);
1106   operands[5] = GEN_INT (-2147483647 - 1);
1107 }")
1108
1109 (define_insn ""
1110   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1111         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1112                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1113                          (const_int 0)
1114                          (minus:SI (match_dup 2) (match_dup 1))))]
1115   "TARGET_POWER"
1116   "doz%I2 %0,%1,%2")
1117
1118 (define_insn ""
1119   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1120         (compare:CC
1121          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1122                               (match_operand:SI 2 "reg_or_short_operand" "rI"))
1123                           (const_int 0)
1124                           (minus:SI (match_dup 2) (match_dup 1)))
1125          (const_int 0)))
1126    (clobber (match_scratch:SI 3 "=r"))]
1127   "TARGET_POWER"
1128   "doz%I2. %3,%1,%2"
1129   [(set_attr "type" "delayed_compare")])
1130
1131 (define_insn ""
1132   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1133         (compare:CC
1134          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1135                               (match_operand:SI 2 "reg_or_short_operand" "rI"))
1136                           (const_int 0)
1137                           (minus:SI (match_dup 2) (match_dup 1)))
1138          (const_int 0)))
1139    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1140         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1141                          (const_int 0)
1142                          (minus:SI (match_dup 2) (match_dup 1))))]
1143   "TARGET_POWER"
1144   "doz%I2. %0,%1,%2"
1145   [(set_attr "type" "delayed_compare")])
1146
1147 ;; We don't need abs with condition code because such comparisons should
1148 ;; never be done.
1149 (define_expand "abssi2"
1150   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1151         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1152   ""
1153   "
1154 {
1155   if (!TARGET_POWER)
1156     {
1157       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1158       DONE;
1159     }
1160 }")
1161
1162 (define_insn "abssi2_power"
1163   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1164         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1165   "TARGET_POWER"
1166   "abs %0,%1")
1167
1168 (define_insn "abssi2_nopower"
1169   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1170         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1171    (clobber (match_scratch:SI 2 "=&r,&r"))]
1172   "!TARGET_POWER"
1173   "*
1174 {
1175   return (TARGET_POWERPC)
1176     ? \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;subf %0,%2,%0\"
1177     : \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;{sf|subfc} %0,%2,%0\";
1178 }"
1179   [(set_attr "length" "12")])
1180
1181 (define_split
1182   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1183         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1184    (clobber (match_scratch:SI 2 "=&r,&r"))]
1185   "!TARGET_POWER && reload_completed"
1186   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1187    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1188    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1189   "")
1190
1191 (define_insn ""
1192   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1193         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1194   "TARGET_POWER"
1195   "nabs %0,%1")
1196
1197 (define_insn ""
1198   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1199         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1200    (clobber (match_scratch:SI 2 "=&r,&r"))]
1201   "!TARGET_POWER"
1202   "*
1203 {
1204   return (TARGET_POWERPC)
1205     ? \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;subf %0,%0,%2\"
1206     : \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;{sf|subfc} %0,%0,%2\";
1207 }"
1208   [(set_attr "length" "12")])
1209
1210 (define_split
1211   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1212         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1213    (clobber (match_scratch:SI 2 "=&r,&r"))]
1214   "!TARGET_POWER && reload_completed"
1215   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1216    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1217    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1218   "")
1219
1220 (define_insn "negsi2"
1221   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1222         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1223   ""
1224   "neg %0,%1")
1225
1226 (define_insn ""
1227   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1228         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1229                     (const_int 0)))
1230    (clobber (match_scratch:SI 2 "=r"))]
1231   ""
1232   "neg. %2,%1"
1233   [(set_attr "type" "compare")])
1234
1235 (define_insn ""
1236   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
1237         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1238                     (const_int 0)))
1239    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1240         (neg:SI (match_dup 1)))]
1241   ""
1242   "neg. %0,%1"
1243   [(set_attr "type" "compare")])
1244
1245 (define_insn "ffssi2"
1246   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
1247         (ffs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1248   ""
1249   "neg %0,%1\;and %0,%0,%1\;{cntlz|cntlzw} %0,%0\;{sfi|subfic} %0,%0,32"
1250   [(set_attr "length" "16")])
1251
1252 (define_expand "mulsi3"
1253   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1254    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1255    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1256   ""
1257   "
1258 {
1259   if (TARGET_POWER)
1260     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1261   else
1262     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1263   DONE;
1264 }")
1265
1266 (define_insn "mulsi3_mq"
1267   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1268         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1269                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1270    (clobber (match_scratch:SI 3 "=q,q"))]
1271   "TARGET_POWER"
1272   "@
1273    {muls|mullw} %0,%1,%2
1274    {muli|mulli} %0,%1,%2"
1275    [(set_attr "type" "imul")])
1276
1277 (define_insn "mulsi3_no_mq"
1278   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1279         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1280                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1281   "! TARGET_POWER"
1282   "@
1283    {muls|mullw} %0,%1,%2
1284    {muli|mulli} %0,%1,%2"
1285    [(set_attr "type" "imul")])
1286
1287 (define_insn ""
1288   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1289         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1290                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1291                     (const_int 0)))
1292    (clobber (match_scratch:SI 3 "=r"))
1293    (clobber (match_scratch:SI 4 "=q"))]
1294   "TARGET_POWER"
1295   "{muls.|mullw.} %3,%1,%2"
1296   [(set_attr "type" "delayed_compare")])
1297
1298 (define_insn ""
1299   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1300         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1301                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1302                     (const_int 0)))
1303    (clobber (match_scratch:SI 3 "=r"))]
1304   "! TARGET_POWER"
1305   "{muls.|mullw.} %3,%1,%2"
1306   [(set_attr "type" "delayed_compare")])
1307
1308 (define_insn ""
1309   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1310         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1311                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1312                     (const_int 0)))
1313    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1314         (mult:SI (match_dup 1) (match_dup 2)))
1315    (clobber (match_scratch:SI 4 "=q"))]
1316   "TARGET_POWER"
1317   "{muls.|mullw.} %0,%1,%2"
1318   [(set_attr "type" "delayed_compare")])
1319
1320 (define_insn ""
1321   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1322         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1323                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1324                     (const_int 0)))
1325    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1326         (mult:SI (match_dup 1) (match_dup 2)))]
1327   "! TARGET_POWER"
1328   "{muls.|mullw.} %0,%1,%2"
1329   [(set_attr "type" "delayed_compare")])
1330
1331 ;; Operand 1 is divided by operand 2; quotient goes to operand
1332 ;; 0 and remainder to operand 3.
1333 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1334
1335 (define_expand "divmodsi4"
1336   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1337                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1338                            (match_operand:SI 2 "gpc_reg_operand" "")))
1339               (set (match_operand:SI 3 "gpc_reg_operand" "")
1340                    (mod:SI (match_dup 1) (match_dup 2)))])]
1341   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1342   "
1343 {
1344   if (! TARGET_POWER && ! TARGET_POWERPC)
1345     {
1346       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1347       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1348       emit_insn (gen_divss_call ());
1349       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1350       emit_move_insn (operands[3], gen_rtx (REG, SImode, 4));
1351       DONE;
1352     }
1353 }")
1354
1355 (define_insn ""
1356   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1357         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1358                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1359    (set (match_operand:SI 3 "gpc_reg_operand" "=q")
1360         (mod:SI (match_dup 1) (match_dup 2)))]
1361   "TARGET_POWER"
1362   "divs %0,%1,%2"
1363   [(set_attr "type" "idiv")])
1364
1365 (define_insn ""
1366   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1367         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1368                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1369   "TARGET_POWERPC"
1370   "divw %0,%1,%2"
1371   [(set_attr "type" "idiv")])
1372
1373 (define_expand "udivsi3"
1374   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1375         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1376                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1377   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1378   "
1379 {
1380   if (! TARGET_POWER && ! TARGET_POWERPC)
1381     {
1382       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1383       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1384       emit_insn (gen_quous_call ());
1385       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1386       DONE;
1387     }
1388 }")
1389
1390 (define_insn ""
1391   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1392         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1393                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1394   "TARGET_POWERPC"
1395   "divwu %0,%1,%2"
1396   [(set_attr "type" "idiv")])
1397
1398 ;; For powers of two we can do srai/aze for divide and then adjust for
1399 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1400 ;; used; for PowerPC, force operands into register and do a normal divide;
1401 ;; for AIX common-mode, use quoss call on register operands.
1402 (define_expand "divsi3"
1403   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1404         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1405                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1406   ""
1407   "
1408 {
1409   if (GET_CODE (operands[2]) == CONST_INT
1410       && exact_log2 (INTVAL (operands[2])) >= 0)
1411     ;
1412   else if (TARGET_POWERPC)
1413     operands[2] = force_reg (SImode, operands[2]);
1414   else if (TARGET_POWER)
1415     FAIL;
1416   else
1417     {
1418       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1419       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1420       emit_insn (gen_quoss_call ());
1421       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1422       DONE;
1423     }
1424 }")
1425
1426 (define_expand "modsi3"
1427   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1428    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1429    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
1430   ""
1431   "
1432 {
1433   int i = exact_log2 (INTVAL (operands[2]));
1434   rtx temp1;
1435   rtx temp2;
1436
1437   if (GET_CODE (operands[2]) != CONST_INT || i < 0)
1438     FAIL;
1439
1440   temp1 = gen_reg_rtx (SImode);
1441   temp2 = gen_reg_rtx (SImode);
1442
1443   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
1444   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
1445   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
1446   DONE;
1447 }")
1448
1449 (define_insn ""
1450   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1451         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1452                 (match_operand:SI 2 "const_int_operand" "N")))]
1453   "exact_log2 (INTVAL (operands[2])) >= 0"
1454   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
1455   [(set_attr "length" "8")])
1456
1457 (define_insn ""
1458   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1459         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1460                             (match_operand:SI 2 "const_int_operand" "N"))
1461                     (const_int 0)))
1462    (clobber (match_scratch:SI 3 "=r"))]
1463   "exact_log2 (INTVAL (operands[2])) >= 0"
1464   "{srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3"
1465   [(set_attr "type" "compare")
1466    (set_attr "length" "8")])
1467
1468 (define_insn ""
1469   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1470         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1471                             (match_operand:SI 2 "const_int_operand" "N"))
1472                     (const_int 0)))
1473    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1474         (div:SI (match_dup 1) (match_dup 2)))]
1475   "exact_log2 (INTVAL (operands[2])) >= 0"
1476   "{srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0"
1477   [(set_attr "type" "compare")
1478    (set_attr "length" "8")])
1479
1480 (define_insn ""
1481   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1482         (udiv:SI
1483          (plus:DI (ashift:DI
1484                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
1485                    (const_int 32))
1486                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
1487          (match_operand:SI 3 "gpc_reg_operand" "r")))
1488    (set (match_operand:SI 2 "register_operand" "=*q")
1489         (umod:SI
1490          (plus:DI (ashift:DI
1491                    (zero_extend:DI (match_dup 1)) (const_int 32))
1492                   (zero_extend:DI (match_dup 4)))
1493          (match_dup 3)))]
1494   "TARGET_POWER"
1495   "div %0,%1,%3"
1496   [(set_attr "type" "idiv")])
1497
1498 ;; To do unsigned divide we handle the cases of the divisor looking like a
1499 ;; negative number.  If it is a constant that is less than 2**31, we don't
1500 ;; have to worry about the branches.  So make a few subroutines here.
1501 ;;
1502 ;; First comes the normal case.
1503 (define_expand "udivmodsi4_normal"
1504   [(set (match_dup 4) (const_int 0))
1505    (parallel [(set (match_operand:SI 0 "" "")
1506                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
1507                                                 (const_int 32))
1508                                      (zero_extend:DI (match_operand:SI 1 "" "")))
1509                             (match_operand:SI 2 "" "")))
1510               (set (match_operand:SI 3 "" "")
1511                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
1512                                                 (const_int 32))
1513                                      (zero_extend:DI (match_dup 1)))
1514                             (match_dup 2)))])]
1515   "TARGET_POWER"
1516   "
1517 { operands[4] = gen_reg_rtx (SImode); }")
1518
1519 ;; This handles the branches.
1520 (define_expand "udivmodsi4_tests"
1521   [(set (match_operand:SI 0 "" "") (const_int 0))
1522    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
1523    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
1524    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
1525                            (label_ref (match_operand:SI 4 "" "")) (pc)))
1526    (set (match_dup 0) (const_int 1))
1527    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
1528    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
1529    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
1530                            (label_ref (match_dup 4)) (pc)))]
1531   "TARGET_POWER"
1532   "
1533 { operands[5] = gen_reg_rtx (CCUNSmode);
1534   operands[6] = gen_reg_rtx (CCmode);
1535 }")
1536
1537 (define_expand "udivmodsi4"
1538   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1539                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1540                             (match_operand:SI 2 "reg_or_cint_operand" "")))
1541               (set (match_operand:SI 3 "gpc_reg_operand" "")
1542                    (umod:SI (match_dup 1) (match_dup 2)))])]
1543   ""
1544   "
1545 {
1546   rtx label = 0;
1547
1548   if (! TARGET_POWER)
1549     if (! TARGET_POWERPC)
1550       {
1551         emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1552         emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1553         emit_insn (gen_divus_call ());
1554         emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1555         emit_move_insn (operands[3], gen_rtx (REG, SImode, 4));
1556         DONE;
1557       }
1558     else
1559       FAIL;
1560
1561   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
1562     {
1563       operands[2] = force_reg (SImode, operands[2]);
1564       label = gen_label_rtx ();
1565       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
1566                                   operands[3], label));
1567     }
1568   else
1569     operands[2] = force_reg (SImode, operands[2]);
1570
1571   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
1572                                operands[3]));
1573   if (label)
1574     emit_label (label);
1575
1576   DONE;
1577 }")
1578
1579 ;; AIX architecture-independent common-mode multiply (DImode),
1580 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
1581 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
1582 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
1583 ;; assumed unused if generating common-mode, so ignore.
1584 (define_insn "mulh_call"
1585   [(set (reg:SI 3)
1586         (truncate:SI
1587          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
1588                                (sign_extend:DI (reg:SI 4)))
1589                       (const_int 32))))
1590    (clobber (match_scratch:SI 0 "=l"))]
1591   "! TARGET_POWER && ! TARGET_POWERPC"
1592   "bla __mulh"
1593   [(set_attr "type" "imul")])
1594
1595 (define_insn "mull_call"
1596   [(set (reg:DI 3)
1597         (mult:DI (sign_extend:DI (reg:SI 3))
1598                  (sign_extend:DI (reg:SI 4))))
1599    (clobber (match_scratch:SI 0 "=l"))
1600    (clobber (reg:SI 0))]
1601   "! TARGET_POWER && ! TARGET_POWERPC"
1602   "bla __mull"
1603   [(set_attr "type" "imul")])
1604
1605 (define_insn "divss_call"
1606   [(set (reg:SI 3)
1607         (div:SI (reg:SI 3) (reg:SI 4)))
1608    (set (reg:SI 4)
1609         (mod:SI (reg:SI 3) (reg:SI 4)))
1610    (clobber (match_scratch:SI 0 "=l"))
1611    (clobber (reg:SI 0))]
1612   "! TARGET_POWER && ! TARGET_POWERPC"
1613   "bla __divss"
1614   [(set_attr "type" "idiv")])
1615
1616 (define_insn "divus_call"
1617   [(set (reg:SI 3)
1618         (udiv:SI (reg:SI 3) (reg:SI 4)))
1619    (set (reg:SI 4)
1620         (umod:SI (reg:SI 3) (reg:SI 4)))
1621    (clobber (match_scratch:SI 0 "=l"))
1622    (clobber (reg:SI 0))
1623    (clobber (match_scratch:CC 1 "=x"))
1624    (clobber (reg:CC 69))]
1625   "! TARGET_POWER && ! TARGET_POWERPC"
1626   "bla __divus"
1627   [(set_attr "type" "idiv")])
1628
1629 (define_insn "quoss_call"
1630   [(set (reg:SI 3)
1631         (div:SI (reg:SI 3) (reg:SI 4)))
1632    (clobber (match_scratch:SI 0 "=l"))]
1633   "! TARGET_POWER && ! TARGET_POWERPC"
1634   "bla __quoss"
1635   [(set_attr "type" "idiv")])
1636
1637 (define_insn "quous_call"
1638   [(set (reg:SI 3)
1639         (udiv:SI (reg:SI 3) (reg:SI 4)))
1640    (clobber (match_scratch:SI 0 "=l"))
1641    (clobber (reg:SI 0))
1642    (clobber (match_scratch:CC 1 "=x"))
1643    (clobber (reg:CC 69))]
1644   "! TARGET_POWER && ! TARGET_POWERPC"
1645   "bla __quous"
1646   [(set_attr "type" "idiv")])
1647 \f
1648 (define_insn "andsi3"
1649   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1650         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1651                 (match_operand:SI 2 "and_operand" "?r,L,K,J")))
1652    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
1653   ""
1654   "@
1655    and %0,%1,%2
1656    {rlinm|rlwinm} %0,%1,0,%m2,%M2
1657    {andil.|andi.} %0,%1,%b2
1658    {andiu.|andis.} %0,%1,%u2")
1659
1660 (define_insn ""
1661   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x")
1662         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1663                             (match_operand:SI 2 "and_operand" "r,K,J,L"))
1664                     (const_int 0)))
1665    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1666   ""
1667   "@
1668    and. %3,%1,%2
1669    {andil.|andi.} %3,%1,%b2
1670    {andiu.|andis.} %3,%1,%u2
1671    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2"
1672   [(set_attr "type" "compare,compare,compare,delayed_compare")])
1673
1674 (define_insn ""
1675   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x")
1676         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1677                             (match_operand:SI 2 "and_operand" "r,K,J,L"))
1678                     (const_int 0)))
1679    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1680         (and:SI (match_dup 1) (match_dup 2)))]
1681   ""
1682   "@
1683    and. %0,%1,%2
1684    {andil.|andi.} %0,%1,%b2
1685    {andiu.|andis.} %0,%1,%u2
1686    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2"
1687   [(set_attr "type" "compare,compare,compare,delayed_compare")])
1688
1689 ;; Take a AND with a constant that cannot be done in a single insn and try to
1690 ;; split it into two insns.  This does not verify that the insns are valid
1691 ;; since this need not be done as combine will do it.
1692
1693 (define_split
1694   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1695         (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
1696                 (match_operand:SI 2 "non_and_cint_operand" "")))]
1697   ""
1698   [(set (match_dup 0) (and:SI (match_dup 1) (match_dup 3)))
1699    (set (match_dup 0) (and:SI (match_dup 0) (match_dup 4)))]
1700   "
1701 {
1702   int maskval = INTVAL (operands[2]);
1703   int i, transitions, last_bit_value;
1704   int orig = maskval, first_c = maskval, second_c;
1705
1706   /* We know that MASKVAL must have more than 2 bit-transitions.  Start at
1707      the low-order bit and count for the third transition.  When we get there,
1708      make a first mask that has everything to the left of that position
1709      a one.  Then make the second mask to turn off whatever else is needed.  */
1710
1711   for (i = 1, transitions = 0, last_bit_value = maskval & 1; i < 32; i++)
1712     {
1713       if (((maskval >>= 1) & 1) != last_bit_value)
1714         last_bit_value ^= 1, transitions++;
1715
1716       if (transitions > 2)
1717         {
1718           first_c |= (~0) << i;
1719           break;
1720         }
1721     }
1722
1723   second_c = orig | ~ first_c;
1724
1725   operands[3] = gen_rtx (CONST_INT, VOIDmode, first_c);
1726   operands[4] = gen_rtx (CONST_INT, VOIDmode, second_c);
1727 }")
1728
1729 (define_insn "iorsi3"
1730   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
1731         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
1732                 (match_operand:SI 2 "logical_operand" "r,K,J")))]
1733   ""
1734   "@
1735    or %0,%1,%2
1736    {oril|ori} %0,%1,%b2
1737    {oriu|oris} %0,%1,%u2")
1738
1739 (define_insn ""
1740   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1741         (compare:CC (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1742                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1743                     (const_int 0)))
1744    (clobber (match_scratch:SI 3 "=r"))]
1745   ""
1746   "or. %3,%1,%2"
1747   [(set_attr "type" "compare")])
1748
1749 (define_insn ""
1750   [(set (match_operand:CC 3 "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    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1755         (ior:SI (match_dup 1) (match_dup 2)))]
1756   ""
1757   "or. %0,%1,%2"
1758   [(set_attr "type" "compare")])
1759
1760 ;; Split an IOR that we can't do in one insn into two insns, each of which
1761 ;; does one 16-bit part.  This is used by combine.
1762
1763 (define_split
1764   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1765         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
1766                 (match_operand:SI 2 "non_logical_cint_operand" "")))]
1767   ""
1768   [(set (match_dup 0) (ior:SI (match_dup 1) (match_dup 3)))
1769    (set (match_dup 0) (ior:SI (match_dup 0) (match_dup 4)))]
1770 "
1771 {
1772   operands[3] = gen_rtx (CONST_INT, VOIDmode,
1773                          INTVAL (operands[2]) & 0xffff0000);
1774   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
1775 }")
1776
1777 (define_insn "xorsi3"
1778   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
1779         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
1780                 (match_operand:SI 2 "logical_operand" "r,K,J")))]
1781   ""
1782   "@
1783    xor %0,%1,%2
1784    {xoril|xori} %0,%1,%b2
1785    {xoriu|xoris} %0,%1,%u2")
1786
1787 (define_insn ""
1788   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1789         (compare:CC (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1790                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1791                     (const_int 0)))
1792    (clobber (match_scratch:SI 3 "=r"))]
1793   ""
1794   "xor. %3,%1,%2"
1795   [(set_attr "type" "compare")])
1796
1797 (define_insn ""
1798   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1799         (compare:CC (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1800                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1801                     (const_int 0)))
1802    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1803         (xor:SI (match_dup 1) (match_dup 2)))]
1804   ""
1805   "xor. %0,%1,%2"
1806   [(set_attr "type" "compare")])
1807
1808 ;; Split an XOR that we can't do in one insn into two insns, each of which
1809 ;; does one 16-bit part.  This is used by combine.
1810
1811 (define_split
1812   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1813         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1814                 (match_operand:SI 2 "non_logical_cint_operand" "")))]
1815   ""
1816   [(set (match_dup 0) (xor:SI (match_dup 1) (match_dup 3)))
1817    (set (match_dup 0) (xor:SI (match_dup 0) (match_dup 4)))]
1818 "
1819 {
1820   operands[3] = gen_rtx (CONST_INT, VOIDmode,
1821                          INTVAL (operands[2]) & 0xffff0000);
1822   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
1823 }")
1824
1825 (define_insn ""
1826   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1827         (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1828                         (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1829    ""
1830    "eqv %0,%1,%2")
1831
1832 (define_insn ""
1833   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1834         (compare:CC (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1835                                     (match_operand:SI 2 "gpc_reg_operand" "r")))
1836                     (const_int 0)))
1837    (clobber (match_scratch:SI 3 "=r"))]
1838    ""
1839    "eqv. %3,%1,%2"
1840    [(set_attr "type" "compare")])
1841
1842 (define_insn ""
1843   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1844         (compare:CC (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1845                                     (match_operand:SI 2 "gpc_reg_operand" "r")))
1846                     (const_int 0)))
1847    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1848         (not:SI (xor:SI (match_dup 1) (match_dup 2))))]
1849    ""
1850    "eqv. %0,%1,%2"
1851    [(set_attr "type" "compare")])
1852
1853 (define_insn ""
1854   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1855         (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1856                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1857   ""
1858   "andc %0,%2,%1")
1859
1860 (define_insn ""
1861   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1862         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1863                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1864                     (const_int 0)))
1865    (clobber (match_scratch:SI 3 "=r"))]
1866   ""
1867   "andc. %3,%2,%1"
1868   [(set_attr "type" "compare")])
1869
1870 (define_insn ""
1871   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1872         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1873                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1874                     (const_int 0)))
1875    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1876         (and:SI (not:SI (match_dup 1)) (match_dup 2)))]
1877   ""
1878   "andc. %0,%2,%1"
1879   [(set_attr "type" "compare")])
1880
1881 (define_insn ""
1882   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1883         (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1884                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1885   ""
1886   "orc %0,%2,%1")
1887
1888 (define_insn ""
1889   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1890         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1891                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1892                     (const_int 0)))
1893    (clobber (match_scratch:SI 3 "=r"))]
1894   ""
1895   "orc. %3,%2,%1"
1896   [(set_attr "type" "compare")])
1897
1898 (define_insn ""
1899   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1900         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1901                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1902                     (const_int 0)))
1903    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1904         (ior:SI (not:SI (match_dup 1)) (match_dup 2)))]
1905   ""
1906   "orc. %0,%2,%1"
1907   [(set_attr "type" "compare")])
1908
1909 (define_insn ""
1910   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1911         (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1912                 (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1913   ""
1914   "nand %0,%1,%2")
1915
1916 (define_insn ""
1917   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1918         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1919                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1920                     (const_int 0)))
1921    (clobber (match_scratch:SI 3 "=r"))]
1922   ""
1923   "nand. %3,%1,%2"
1924   [(set_attr "type" "compare")])
1925
1926 (define_insn ""
1927   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1928         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1929                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1930                     (const_int 0)))
1931    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1932         (ior:SI (not:SI (match_dup 1)) (not:SI (match_dup 2))))]
1933   ""
1934   "nand. %0,%1,%2"
1935   [(set_attr "type" "compare")])
1936
1937 (define_insn ""
1938   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1939         (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1940                 (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1941   ""
1942   "nor %0,%1,%2")
1943
1944 (define_insn ""
1945   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1946         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1947                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1948                     (const_int 0)))
1949    (clobber (match_scratch:SI 3 "=r"))]
1950   ""
1951   "nor. %3,%1,%2"
1952   [(set_attr "type" "compare")])
1953
1954 (define_insn ""
1955   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1956         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1957                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1958                     (const_int 0)))
1959    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1960         (and:SI (not:SI (match_dup 1)) (not:SI (match_dup 2))))]
1961   ""
1962   "nor. %0,%1,%2"
1963   [(set_attr "type" "compare")])
1964
1965 ;; maskir insn.  We need four forms because things might be in arbitrary
1966 ;; orders.  Don't define forms that only set CR fields because these
1967 ;; would modify an input register.
1968
1969 (define_insn ""
1970   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1971         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1972                         (match_operand:SI 1 "gpc_reg_operand" "0"))
1973                 (and:SI (match_dup 2)
1974                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
1975   "TARGET_POWER"
1976   "maskir %0,%3,%2")
1977
1978 (define_insn ""
1979   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1980         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1981                         (match_operand:SI 1 "gpc_reg_operand" "0"))
1982                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1983                         (match_dup 2))))]
1984   "TARGET_POWER"
1985   "maskir %0,%3,%2")
1986
1987 (define_insn ""
1988   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1989         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
1990                         (match_operand:SI 3 "gpc_reg_operand" "r"))
1991                 (and:SI (not:SI (match_dup 2))
1992                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
1993   "TARGET_POWER"
1994   "maskir %0,%3,%2")
1995
1996 (define_insn ""
1997   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1998         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1999                         (match_operand:SI 2 "gpc_reg_operand" "r"))
2000                 (and:SI (not:SI (match_dup 2))
2001                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2002   "TARGET_POWER"
2003   "maskir %0,%3,%2")
2004
2005 (define_insn ""
2006   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2007         (compare:CC
2008          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2009                          (match_operand:SI 1 "gpc_reg_operand" "0"))
2010                  (and:SI (match_dup 2)
2011                          (match_operand:SI 3 "gpc_reg_operand" "r")))
2012          (const_int 0)))
2013    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2014         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2015                 (and:SI (match_dup 2) (match_dup 3))))]
2016   "TARGET_POWER"
2017   "maskir. %0,%3,%2"
2018   [(set_attr "type" "compare")])
2019
2020 (define_insn ""
2021   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2022         (compare:CC
2023          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2024                          (match_operand:SI 1 "gpc_reg_operand" "0"))
2025                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2026                          (match_dup 2)))
2027          (const_int 0)))
2028    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2029         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2030                 (and:SI (match_dup 3) (match_dup 2))))]
2031   "TARGET_POWER"
2032   "maskir. %0,%3,%2"
2033   [(set_attr "type" "compare")])
2034
2035 (define_insn ""
2036   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2037         (compare:CC
2038          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2039                          (match_operand:SI 3 "gpc_reg_operand" "r"))
2040                  (and:SI (not:SI (match_dup 2))
2041                          (match_operand:SI 1 "gpc_reg_operand" "0")))
2042          (const_int 0)))
2043    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2044         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2045                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2046   "TARGET_POWER"
2047   "maskir. %0,%3,%2"
2048   [(set_attr "type" "compare")])
2049
2050 (define_insn ""
2051   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2052         (compare:CC
2053          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2054                          (match_operand:SI 2 "gpc_reg_operand" "r"))
2055                  (and:SI (not:SI (match_dup 2))
2056                          (match_operand:SI 1 "gpc_reg_operand" "0")))
2057          (const_int 0)))
2058    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2059         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2060                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2061   "TARGET_POWER"
2062   "maskir. %0,%3,%2"
2063   [(set_attr "type" "compare")])
2064 \f
2065 ;; Rotate and shift insns, in all their variants.  These support shifts,
2066 ;; field inserts and extracts, and various combinations thereof.
2067 (define_expand "insv"
2068   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2069                          (match_operand:SI 1 "const_int_operand" "i")
2070                          (match_operand:SI 2 "const_int_operand" "i"))
2071         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2072   ""
2073   "
2074 {
2075   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2076      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2077      compiler if the address of the structure is taken later.  */
2078   if (GET_CODE (operands[0]) == SUBREG
2079       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2080     FAIL;
2081 }")
2082
2083 (define_insn ""
2084   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2085                          (match_operand:SI 1 "const_int_operand" "i")
2086                          (match_operand:SI 2 "const_int_operand" "i"))
2087         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2088   ""
2089   "*
2090 {
2091   int start = INTVAL (operands[2]) & 31;
2092   int size = INTVAL (operands[1]) & 31;
2093
2094   operands[4] = gen_rtx (CONST_INT, VOIDmode, 32 - start - size);
2095   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2096   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2097 }")
2098
2099 (define_insn ""
2100   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2101                          (match_operand:SI 1 "const_int_operand" "i")
2102                          (match_operand:SI 2 "const_int_operand" "i"))
2103         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2104                    (match_operand:SI 4 "const_int_operand" "i")))]
2105   ""
2106   "*
2107 {
2108   int shift = INTVAL (operands[4]) & 31;
2109   int start = INTVAL (operands[2]) & 31;
2110   int size = INTVAL (operands[1]) & 31;
2111
2112   operands[4] = gen_rtx (CONST_INT, VOIDmode, shift - start - size);
2113   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2114   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2115 }")
2116
2117 (define_insn ""
2118   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2119                          (match_operand:SI 1 "const_int_operand" "i")
2120                          (match_operand:SI 2 "const_int_operand" "i"))
2121         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2122                      (match_operand:SI 4 "const_int_operand" "i")))]
2123   ""
2124   "*
2125 {
2126   int shift = INTVAL (operands[4]) & 31;
2127   int start = INTVAL (operands[2]) & 31;
2128   int size = INTVAL (operands[1]) & 31;
2129
2130   operands[4] = gen_rtx (CONST_INT, VOIDmode, 32 - shift - start - size);
2131   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2132   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2133 }")
2134
2135 (define_insn ""
2136   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2137                          (match_operand:SI 1 "const_int_operand" "i")
2138                          (match_operand:SI 2 "const_int_operand" "i"))
2139         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2140                      (match_operand:SI 4 "const_int_operand" "i")))]
2141   ""
2142   "*
2143 {
2144   int shift = INTVAL (operands[4]) & 31;
2145   int start = INTVAL (operands[2]) & 31;
2146   int size = INTVAL (operands[1]) & 31;
2147
2148   operands[4] = gen_rtx (CONST_INT, VOIDmode, 32 - shift - start - size);
2149   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2150   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2151 }")
2152
2153 (define_insn ""
2154   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2155                          (match_operand:SI 1 "const_int_operand" "i")
2156                          (match_operand:SI 2 "const_int_operand" "i"))
2157         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2158                          (match_operand:SI 4 "const_int_operand" "i")
2159                          (match_operand:SI 5 "const_int_operand" "i")))]
2160   "INTVAL (operands[4]) >= INTVAL (operands[1])"
2161   "*
2162 {
2163   int extract_start = INTVAL (operands[5]) & 31;
2164   int extract_size = INTVAL (operands[4]) & 31;
2165   int insert_start = INTVAL (operands[2]) & 31;
2166   int insert_size = INTVAL (operands[1]) & 31;
2167
2168 /* Align extract field with insert field */
2169   operands[5] = gen_rtx (CONST_INT, VOIDmode,
2170                          extract_start + extract_size - insert_start - insert_size);
2171   operands[1] = gen_rtx (CONST_INT, VOIDmode, insert_start + insert_size - 1);
2172   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
2173 }")
2174
2175 (define_insn ""
2176   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
2177                          (match_operand:DI 1 "const_int_operand" "i")
2178                          (match_operand:DI 2 "const_int_operand" "i"))
2179         (match_operand:DI 3 "gpc_reg_operand" "r"))]
2180   "TARGET_POWERPC64"
2181   "*
2182 {
2183   int start = INTVAL (operands[2]) & 63;
2184   int size = INTVAL (operands[1]) & 63;
2185
2186   operands[2] = gen_rtx (CONST_INT, VOIDmode, 64 - start - size);
2187   return \"rldimi %0,%3,%H2,%H1\";
2188 }")
2189
2190 (define_expand "extzv"
2191   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2192         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2193                          (match_operand:SI 2 "const_int_operand" "i")
2194                          (match_operand:SI 3 "const_int_operand" "i")))]
2195   ""
2196   "
2197 {
2198   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2199      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2200      compiler if the address of the structure is taken later.  */
2201   if (GET_CODE (operands[0]) == SUBREG
2202       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2203     FAIL;
2204 }")
2205
2206 (define_insn ""
2207   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2208         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2209                          (match_operand:SI 2 "const_int_operand" "i")
2210                          (match_operand:SI 3 "const_int_operand" "i")))]
2211   ""
2212   "*
2213 {
2214   int start = INTVAL (operands[3]) & 31;
2215   int size = INTVAL (operands[2]) & 31;
2216
2217   if (start + size >= 32)
2218     operands[3] = const0_rtx;
2219   else
2220     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2221   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
2222 }")
2223
2224 (define_insn ""
2225   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2226         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2227                          (match_operand:SI 2 "const_int_operand" "i")
2228                          (match_operand:SI 3 "const_int_operand" "i"))
2229                     (const_int 0)))
2230    (clobber (match_scratch:SI 4 "=r"))]
2231   ""
2232   "*
2233 {
2234   int start = INTVAL (operands[3]) & 31;
2235   int size = INTVAL (operands[2]) & 31;
2236
2237   /* If the bitfield being tested fits in the upper or lower half of a
2238      word, it is possible to use andiu. or andil. to test it.  This is
2239      useful because the condition register set-use delay is smaller for
2240      andi[ul]. than for rlinm.  This doesn't work when the starting bit
2241      position is 0 because the LT and GT bits may be set wrong.  */
2242
2243   if ((start > 0 && start + size <= 16) || start >= 16)
2244     {
2245       operands[3] = gen_rtx (CONST_INT, VOIDmode,
2246                              ((1 << (16 - (start & 15)))
2247                               - (1 << (16 - (start & 15) - size))));
2248       if (start < 16)
2249         return \"{andiu.|andis.} %4,%1,%3\";
2250       else
2251         return \"{andil.|andi.} %4,%1,%3\";
2252     }
2253
2254   if (start + size >= 32)
2255     operands[3] = const0_rtx;
2256   else
2257     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2258   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
2259 }"
2260   [(set_attr "type" "compare")])
2261
2262 (define_insn ""
2263   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2264         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2265                          (match_operand:SI 2 "const_int_operand" "i")
2266                          (match_operand:SI 3 "const_int_operand" "i"))
2267                     (const_int 0)))
2268    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2269         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
2270   ""
2271   "*
2272 {
2273   int start = INTVAL (operands[3]) & 31;
2274   int size = INTVAL (operands[2]) & 31;
2275
2276   if (start >= 16 && start + size == 32)
2277     {
2278       operands[3] = gen_rtx (CONST_INT, VOIDmode, (1 << (32 - start)) - 1);
2279       return \"{andil.|andi.} %0,%1,%3\";
2280     }
2281
2282   if (start + size >= 32)
2283     operands[3] = const0_rtx;
2284   else
2285     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2286   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
2287 }"
2288   [(set_attr "type" "delayed_compare")])
2289
2290 (define_insn ""
2291   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2292         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
2293                          (match_operand:DI 2 "const_int_operand" "i")
2294                          (match_operand:DI 3 "const_int_operand" "i")))]
2295   "TARGET_POWERPC64"
2296   "*
2297 {
2298   int start = INTVAL (operands[3]) & 63;
2299   int size = INTVAL (operands[2]) & 63;
2300
2301   if (start + size >= 64)
2302     operands[3] = const0_rtx;
2303   else
2304     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2305   operands[2] = gen_rtx (CONST_INT, VOIDmode, 64 - size);
2306   return \"rldicl %0,%1,%3,%2\";
2307 }")
2308
2309 (define_insn ""
2310   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
2311         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
2312                          (match_operand:DI 2 "const_int_operand" "i")
2313                          (match_operand:DI 3 "const_int_operand" "i"))
2314                     (const_int 0)))
2315    (clobber (match_scratch:DI 4 "=r"))]
2316   "TARGET_POWERPC64"
2317   "*
2318 {
2319   int start = INTVAL (operands[3]) & 63;
2320   int size = INTVAL (operands[2]) & 63;
2321
2322   if (start + size >= 64)
2323     operands[3] = const0_rtx;
2324   else
2325     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2326   operands[2] = gen_rtx (CONST_INT, VOIDmode, 64 - size);
2327   return \"rldicl. %4,%1,%3,%2\";
2328 }")
2329
2330 (define_insn ""
2331   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
2332         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
2333                          (match_operand:DI 2 "const_int_operand" "i")
2334                          (match_operand:DI 3 "const_int_operand" "i"))
2335                     (const_int 0)))
2336    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
2337         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
2338   "TARGET_POWERPC64"
2339   "*
2340 {
2341   int start = INTVAL (operands[3]) & 63;
2342   int size = INTVAL (operands[2]) & 63;
2343
2344   if (start + size >= 64)
2345     operands[3] = const0_rtx;
2346   else
2347     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2348   operands[2] = gen_rtx (CONST_INT, VOIDmode, 64 - size);
2349   return \"rldicl. %0,%1,%3,%2\";
2350 }")
2351
2352 (define_insn "rotlsi3"
2353   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2354         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2355                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2356   ""
2357   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
2358
2359 (define_insn ""
2360   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2361         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2362                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2363                     (const_int 0)))
2364    (clobber (match_scratch:SI 3 "=r"))]
2365   ""
2366   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff"
2367   [(set_attr "type" "delayed_compare")])
2368
2369 (define_insn ""
2370   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2371         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2372                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2373                     (const_int 0)))
2374    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2375         (rotate:SI (match_dup 1) (match_dup 2)))]
2376   ""
2377   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff"
2378   [(set_attr "type" "delayed_compare")])
2379
2380 (define_insn ""
2381   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2382         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2383                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2384                 (match_operand:SI 3 "mask_operand" "L")))]
2385   ""
2386   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
2387
2388 (define_insn ""
2389   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2390         (compare:CC (and:SI
2391                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2392                                 (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2393                      (match_operand:SI 3 "mask_operand" "L"))
2394                     (const_int 0)))
2395    (clobber (match_scratch:SI 4 "=r"))]
2396   ""
2397   "{rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3"
2398   [(set_attr "type" "delayed_compare")])
2399
2400 (define_insn ""
2401   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2402         (compare:CC (and:SI
2403                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2404                                 (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2405                      (match_operand:SI 3 "mask_operand" "L"))
2406                     (const_int 0)))
2407    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2408         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2409   ""
2410   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3"
2411   [(set_attr "type" "delayed_compare")])
2412
2413 (define_insn ""
2414   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2415         (zero_extend:SI
2416          (subreg:QI
2417           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2418                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
2419   ""
2420   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
2421
2422 (define_insn ""
2423   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2424         (compare:CC (zero_extend:SI
2425                      (subreg:QI
2426                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2427                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2428                     (const_int 0)))
2429    (clobber (match_scratch:SI 3 "=r"))]
2430   ""
2431   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff"
2432   [(set_attr "type" "delayed_compare")])
2433
2434 (define_insn ""
2435   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2436         (compare:CC (zero_extend:SI
2437                      (subreg:QI
2438                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2439                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2440                     (const_int 0)))
2441    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2442         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
2443   ""
2444   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff"
2445   [(set_attr "type" "delayed_compare")])
2446
2447 (define_insn ""
2448   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2449         (zero_extend:SI
2450          (subreg:HI
2451           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2452                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
2453   ""
2454   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
2455
2456 (define_insn ""
2457   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2458         (compare:CC (zero_extend:SI
2459                      (subreg:HI
2460                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2461                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2462                     (const_int 0)))
2463    (clobber (match_scratch:SI 3 "=r"))]
2464   ""
2465   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff"
2466   [(set_attr "type" "delayed_compare")])
2467
2468 (define_insn ""
2469   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2470         (compare:CC (zero_extend:SI
2471                      (subreg:HI
2472                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2473                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2474                     (const_int 0)))
2475    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2476         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
2477   ""
2478   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff"
2479   [(set_attr "type" "delayed_compare")])
2480
2481 ;; Note that we use "sle." instead of "sl." so that we can set
2482 ;; SHIFT_COUNT_TRUNCATED.
2483
2484 (define_expand "ashlsi3"
2485   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2486    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2487    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2488   ""
2489   "
2490 {
2491   if (TARGET_POWER)
2492     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
2493   else
2494     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
2495   DONE;
2496 }")
2497
2498 (define_insn "ashlsi3_power"
2499   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2500         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2501                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2502    (clobber (match_scratch:SI 3 "=q,X"))]
2503   "TARGET_POWER"
2504   "@
2505    sle %0,%1,%2
2506    {sli|slwi} %0,%1,%h2"
2507   [(set_attr "length" "8")])
2508
2509 (define_insn "ashlsi3_no_power"
2510   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2511         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2512                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2513   "! TARGET_POWER"
2514   "{sl|slw}%I2 %0,%1,%h2"
2515   [(set_attr "length" "8")])
2516
2517 (define_insn ""
2518   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2519         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2520                                (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2521                     (const_int 0)))
2522    (clobber (match_scratch:SI 3 "=r,r"))
2523    (clobber (match_scratch:SI 4 "=q,X"))]
2524   "TARGET_POWER"
2525   "@
2526    sle. %3,%1,%2
2527    {sli.|slwi.} %3,%1,%h2"
2528   [(set_attr "type" "delayed_compare")])
2529
2530 (define_insn ""
2531   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2532         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2533                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2534                     (const_int 0)))
2535    (clobber (match_scratch:SI 3 "=r"))]
2536   "! TARGET_POWER"
2537   "{sl|slw}%I2. %3,%1,%h2"
2538   [(set_attr "type" "delayed_compare")])
2539
2540 (define_insn ""
2541   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2542         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2543                                (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2544                     (const_int 0)))
2545    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2546         (ashift:SI (match_dup 1) (match_dup 2)))
2547    (clobber (match_scratch:SI 4 "=q,X"))]
2548   "TARGET_POWER"
2549   "@
2550    sle. %0,%1,%2
2551    {sli.|slwi.} %0,%1,%h2"
2552   [(set_attr "type" "delayed_compare")])
2553
2554 (define_insn ""
2555   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2556         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2557                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2558                     (const_int 0)))
2559    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2560         (ashift:SI (match_dup 1) (match_dup 2)))]
2561   "! TARGET_POWER"
2562   "{sl|slw}%I2. %0,%1,%h2"
2563   [(set_attr "type" "delayed_compare")])
2564
2565 (define_insn ""
2566   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2567         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2568                            (match_operand:SI 2 "const_int_operand" "i"))
2569                 (match_operand:SI 3 "mask_operand" "L")))]
2570   "includes_lshift_p (operands[2], operands[3])"
2571   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
2572
2573 (define_insn ""
2574   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2575         (compare:CC
2576          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2577                             (match_operand:SI 2 "const_int_operand" "i"))
2578                  (match_operand:SI 3 "mask_operand" "L"))
2579          (const_int 0)))
2580    (clobber (match_scratch:SI 4 "=r"))]
2581   "includes_lshift_p (operands[2], operands[3])"
2582   "{rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3"
2583   [(set_attr "type" "delayed_compare")])
2584
2585 (define_insn ""
2586   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2587         (compare:CC
2588          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2589                             (match_operand:SI 2 "const_int_operand" "i"))
2590                  (match_operand:SI 3 "mask_operand" "L"))
2591          (const_int 0)))
2592    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2593         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2594   "includes_lshift_p (operands[2], operands[3])"
2595   "{rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3"
2596   [(set_attr "type" "delayed_compare")])
2597
2598 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
2599 ;; "sli x,x,0".
2600 (define_expand "lshrsi3"
2601   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2602    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2603    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2604   ""
2605   "
2606 {
2607   if (TARGET_POWER)
2608     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
2609   else
2610     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
2611   DONE;
2612 }")
2613
2614 (define_insn "lshrsi3_power"
2615   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2616         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
2617                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
2618    (clobber (match_scratch:SI 3 "=q,X,X"))]
2619   "TARGET_POWER"
2620   "@
2621   sre %0,%1,%2
2622   mr %0,%1
2623   {s%A2i|s%A2wi} %0,%1,%h2")
2624
2625 (define_insn "lshrsi3_no_power"
2626   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2627         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2628                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
2629   "! TARGET_POWER"
2630   "@
2631   mr %0,%1
2632   {sr|srw}%I2 %0,%1,%h2")
2633
2634 (define_insn ""
2635   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x")
2636         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
2637                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i"))
2638                     (const_int 0)))
2639    (clobber (match_scratch:SI 3 "=r,X,r"))
2640    (clobber (match_scratch:SI 4 "=q,X,X"))]
2641   "TARGET_POWER"
2642   "@
2643   sre. %3,%1,%2
2644   mr. %1,%1
2645   {s%A2i.|s%A2wi.} %3,%1,%h2"
2646   [(set_attr "type" "delayed_compare")])
2647
2648 (define_insn ""
2649   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2650         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2651                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri"))
2652                     (const_int 0)))
2653    (clobber (match_scratch:SI 3 "=X,r"))]
2654   "! TARGET_POWER"
2655   "@
2656    mr. %1,%1
2657    {sr|srw}%I2. %3,%1,%h2"
2658   [(set_attr "type" "delayed_compare")])
2659
2660 (define_insn ""
2661   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x")
2662         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
2663                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i"))
2664                     (const_int 0)))
2665    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2666         (lshiftrt:SI (match_dup 1) (match_dup 2)))
2667    (clobber (match_scratch:SI 4 "=q,X,X"))]
2668   "TARGET_POWER"
2669   "@
2670   sre. %0,%1,%2
2671   mr. %0,%1
2672   {s%A2i.|s%A2wi.} %0,%1,%h2"
2673   [(set_attr "type" "delayed_compare")])
2674
2675 (define_insn ""
2676   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2677         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2678                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri"))
2679                     (const_int 0)))
2680    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2681         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
2682   "! TARGET_POWER"
2683   "@
2684    mr. %0,%1
2685    {sr|srw}%I2. %0,%1,%h2"
2686   [(set_attr "type" "delayed_compare")])
2687
2688 (define_insn ""
2689   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2690         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2691                              (match_operand:SI 2 "const_int_operand" "i"))
2692                 (match_operand:SI 3 "mask_operand" "L")))]
2693   "includes_rshift_p (operands[2], operands[3])"
2694   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
2695
2696 (define_insn ""
2697   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2698         (compare:CC
2699          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2700                               (match_operand:SI 2 "const_int_operand" "i"))
2701                  (match_operand:SI 3 "mask_operand" "L"))
2702          (const_int 0)))
2703    (clobber (match_scratch:SI 4 "=r"))]
2704   "includes_rshift_p (operands[2], operands[3])"
2705   "{rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3"
2706   [(set_attr "type" "delayed_compare")])
2707
2708 (define_insn ""
2709   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2710         (compare:CC
2711          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2712                               (match_operand:SI 2 "const_int_operand" "i"))
2713                  (match_operand:SI 3 "mask_operand" "L"))
2714          (const_int 0)))
2715    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2716         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2717   "includes_rshift_p (operands[2], operands[3])"
2718   "{rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3"
2719   [(set_attr "type" "delayed_compare")])
2720
2721 (define_insn ""
2722   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2723         (zero_extend:SI
2724          (subreg:QI
2725           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2726                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
2727   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2728   "{rlinm|rlwinm} %0,%1,%s2,0xff")
2729
2730 (define_insn ""
2731   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2732         (compare:CC
2733          (zero_extend:SI
2734           (subreg:QI
2735            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2736                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2737          (const_int 0)))
2738    (clobber (match_scratch:SI 3 "=r"))]
2739   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2740   "{rlinm.|rlwinm.} %3,%1,%s2,0xff"
2741   [(set_attr "type" "delayed_compare")])
2742
2743 (define_insn ""
2744   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2745         (compare:CC
2746          (zero_extend:SI
2747           (subreg:QI
2748            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2749                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2750          (const_int 0)))
2751    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2752         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
2753   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2754   "{rlinm.|rlwinm.} %0,%1,%s2,0xff"
2755   [(set_attr "type" "delayed_compare")])
2756
2757 (define_insn ""
2758   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2759         (zero_extend:SI
2760          (subreg:HI
2761           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2762                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
2763   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2764   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
2765
2766 (define_insn ""
2767   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2768         (compare:CC
2769          (zero_extend:SI
2770           (subreg:HI
2771            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2772                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2773          (const_int 0)))
2774    (clobber (match_scratch:SI 3 "=r"))]
2775   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2776   "{rlinm.|rlwinm.} %3,%1,%s2,0xffff"
2777   [(set_attr "type" "delayed_compare")])
2778
2779 (define_insn ""
2780   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2781         (compare:CC
2782          (zero_extend:SI
2783           (subreg:HI
2784            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2785                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2786          (const_int 0)))
2787    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2788         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
2789   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2790   "{rlinm.|rlwinm.} %0,%1,%s2,0xffff"
2791   [(set_attr "type" "delayed_compare")])
2792
2793 (define_insn ""
2794   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2795                          (const_int 1)
2796                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2797         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2798                      (const_int 31)))]
2799   "TARGET_POWER"
2800   "rrib %0,%1,%2")
2801
2802 (define_insn ""
2803   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2804                          (const_int 1)
2805                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2806         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2807                      (const_int 31)))]
2808   "TARGET_POWER"
2809   "rrib %0,%1,%2")
2810
2811 (define_insn ""
2812   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2813                          (const_int 1)
2814                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2815         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2816                          (const_int 1)
2817                          (const_int 0)))]
2818   "TARGET_POWER"
2819   "rrib %0,%1,%2")
2820
2821 (define_expand "ashrsi3"
2822   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2823         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
2824                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
2825   ""
2826   "
2827 {
2828   if (TARGET_POWER)
2829     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
2830   else
2831     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
2832   DONE;
2833 }")
2834
2835 (define_insn "ashrsi3_power"
2836   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2837         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2838                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2839    (clobber (match_scratch:SI 3 "=q,X"))]
2840   "TARGET_POWER"
2841   "@
2842    srea %0,%1,%2
2843    {srai|srawi} %0,%1,%h2")
2844
2845 (define_insn "ashrsi3_no_power"
2846   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2847         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2848                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2849   "! TARGET_POWER"
2850   "{sra|sraw}%I2 %0,%1,%h2")
2851
2852 (define_insn ""
2853   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2854         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2855                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2856                     (const_int 0)))
2857    (clobber (match_scratch:SI 3 "=r,r"))
2858    (clobber (match_scratch:SI 4 "=q,X"))]
2859   "TARGET_POWER"
2860   "@
2861    srea. %3,%1,%2
2862    {srai.|srawi.} %3,%1,%h2"
2863   [(set_attr "type" "delayed_compare")])
2864
2865 (define_insn ""
2866   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2867         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2868                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2869                     (const_int 0)))
2870    (clobber (match_scratch:SI 3 "=r"))]
2871   "! TARGET_POWER"
2872   "{sra|sraw}%I2. %3,%1,%h2"
2873   [(set_attr "type" "delayed_compare")])
2874
2875 (define_insn ""
2876   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2877         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2878                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2879                     (const_int 0)))
2880    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2881         (ashiftrt:SI (match_dup 1) (match_dup 2)))
2882    (clobber (match_scratch:SI 4 "=q,X"))]
2883   "TARGET_POWER"
2884   "@
2885    srea. %0,%1,%2
2886    {srai.|srawi.} %0,%1,%h2"
2887   [(set_attr "type" "delayed_compare")])
2888
2889 (define_insn ""
2890   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2891         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2892                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2893                     (const_int 0)))
2894    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2895         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
2896   "! TARGET_POWER"
2897   "{sra|sraw}%I2. %0,%1,%h2"
2898   [(set_attr "type" "delayed_compare")])
2899 \f
2900 ;; Floating-point insns, excluding normal data motion.
2901 ;;
2902 ;; PowerPC has a full set of single-precision floating point instructions.
2903 ;;
2904 ;; For the POWER architecture, we pretend that we have both SFmode and
2905 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
2906 ;; The only conversions we will do will be when storing to memory.  In that
2907 ;; case, we will use the "frsp" instruction before storing.
2908 ;;
2909 ;; Note that when we store into a single-precision memory location, we need to
2910 ;; use the frsp insn first.  If the register being stored isn't dead, we
2911 ;; need a scratch register for the frsp.  But this is difficult when the store
2912 ;; is done by reload.  It is not incorrect to do the frsp on the register in
2913 ;; this case, we just lose precision that we would have otherwise gotten but
2914 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
2915
2916 (define_insn "extendsfdf2"
2917   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
2918         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2919   "TARGET_HARD_FLOAT"
2920   "*
2921 {
2922   if (REGNO (operands[0]) == REGNO (operands[1]))
2923     return \"\";
2924   else
2925     return \"fmr %0,%1\";
2926 }"
2927   [(set_attr "type" "fp")])
2928
2929 (define_insn "truncdfsf2"
2930   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2931         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
2932   "TARGET_HARD_FLOAT"
2933   "frsp %0,%1"
2934   [(set_attr "type" "fp")])
2935
2936 (define_insn "aux_truncdfsf2"
2937   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2938         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] 0))]
2939   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2940   "frsp %0,%1"
2941   [(set_attr "type" "fp")])
2942
2943 (define_insn "negsf2"
2944   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2945         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2946   "TARGET_HARD_FLOAT"
2947   "fneg %0,%1"
2948   [(set_attr "type" "fp")])
2949
2950 (define_insn "abssf2"
2951   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2952         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2953   "TARGET_HARD_FLOAT"
2954   "fabs %0,%1"
2955   [(set_attr "type" "fp")])
2956
2957 (define_insn ""
2958   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2959         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
2960   "TARGET_HARD_FLOAT"
2961   "fnabs %0,%1"
2962   [(set_attr "type" "fp")])
2963
2964 (define_expand "addsf3"
2965   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2966         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2967                  (match_operand:SF 2 "gpc_reg_operand" "")))]
2968   "TARGET_HARD_FLOAT"
2969   "")
2970
2971 (define_insn ""
2972   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2973         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2974                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2975   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2976   "fadds %0,%1,%2"
2977   [(set_attr "type" "fp")])
2978
2979 (define_insn ""
2980   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2981         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2982                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2983   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2984   "{fa|fadd} %0,%1,%2"
2985   [(set_attr "type" "fp")])
2986
2987 (define_expand "subsf3"
2988   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2989         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2990                   (match_operand:SF 2 "gpc_reg_operand" "")))]
2991   "TARGET_HARD_FLOAT"
2992   "")
2993
2994 (define_insn ""
2995   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2996         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2997                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
2998   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2999   "fsubs %0,%1,%2"
3000   [(set_attr "type" "fp")])
3001
3002 (define_insn ""
3003   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3004         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
3005                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
3006   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3007   "{fs|fsub} %0,%1,%2"
3008   [(set_attr "type" "fp")])
3009
3010 (define_expand "mulsf3"
3011   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3012         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
3013                  (match_operand:SF 2 "gpc_reg_operand" "")))]
3014   "TARGET_HARD_FLOAT"
3015   "")
3016
3017 (define_insn ""
3018   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3019         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3020                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
3021   "TARGET_POWERPC && TARGET_HARD_FLOAT"
3022   "fmuls %0,%1,%2"
3023   [(set_attr "type" "fp")])
3024
3025 (define_insn ""
3026   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3027         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3028                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
3029   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3030   "{fm|fmul} %0,%1,%2"
3031   [(set_attr "type" "dmul")])
3032
3033 (define_expand "divsf3"
3034   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3035         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
3036                 (match_operand:SF 2 "gpc_reg_operand" "")))]
3037   "TARGET_HARD_FLOAT"
3038   "")
3039
3040 (define_insn ""
3041   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3042         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
3043                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
3044   "TARGET_POWERPC && TARGET_HARD_FLOAT"
3045   "fdivs %0,%1,%2"
3046   [(set_attr "type" "sdiv")])
3047
3048 (define_insn ""
3049   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3050         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
3051                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
3052   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3053   "{fd|fdiv} %0,%1,%2"
3054   [(set_attr "type" "ddiv")])
3055
3056 (define_insn ""
3057   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3058         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3059                           (match_operand:SF 2 "gpc_reg_operand" "f"))
3060                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
3061   "TARGET_POWERPC && TARGET_HARD_FLOAT"
3062   "fmadds %0,%1,%2,%3"
3063   [(set_attr "type" "fp")])
3064
3065 (define_insn ""
3066   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3067         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3068                           (match_operand:SF 2 "gpc_reg_operand" "f"))
3069                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
3070   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3071   "{fma|fmadd} %0,%1,%2,%3"
3072   [(set_attr "type" "dmul")])
3073
3074 (define_insn ""
3075   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3076         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3077                            (match_operand:SF 2 "gpc_reg_operand" "f"))
3078                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
3079   "TARGET_POWERPC && TARGET_HARD_FLOAT"
3080   "fmsubs %0,%1,%2,%3"
3081   [(set_attr "type" "fp")])
3082
3083 (define_insn ""
3084   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3085         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3086                            (match_operand:SF 2 "gpc_reg_operand" "f"))
3087                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
3088   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3089   "{fms|fmsub} %0,%1,%2,%3"
3090   [(set_attr "type" "dmul")])
3091
3092 (define_insn ""
3093   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3094         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3095                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
3096                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
3097   "TARGET_POWERPC && TARGET_HARD_FLOAT"
3098   "fnmadds %0,%1,%2,%3"
3099   [(set_attr "type" "fp")])
3100
3101 (define_insn ""
3102   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3103         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3104                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
3105                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
3106   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3107   "{fnma|fnmadd} %0,%1,%2,%3"
3108   [(set_attr "type" "dmul")])
3109
3110 (define_insn ""
3111   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3112         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3113                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
3114                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
3115   "TARGET_POWERPC && TARGET_HARD_FLOAT"
3116   "fnmsubs %0,%1,%2,%3"
3117   [(set_attr "type" "fp")])
3118
3119 (define_insn ""
3120   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3121         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3122                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
3123                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
3124   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3125   "{fnms|fnmsub} %0,%1,%2,%3"
3126   [(set_attr "type" "dmul")])
3127
3128 (define_expand "sqrtsf2"
3129   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3130         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
3131   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT"
3132   "")
3133
3134 (define_insn ""
3135   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3136         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
3137   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT"
3138   "fsqrts %0,%1"
3139   [(set_attr "type" "ssqrt")])
3140
3141 (define_insn ""
3142   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3143         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
3144   "TARGET_POWER2 && TARGET_HARD_FLOAT"
3145   "fsqrt %0,%1"
3146   [(set_attr "type" "dsqrt")])
3147
3148 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
3149 ;; fsel instruction and some auxiliary computations.  Then we just have a
3150 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
3151 ;; combine.
3152 (define_expand "maxsf3"
3153   [(set (match_dup 3)
3154         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
3155                   (match_operand:SF 2 "gpc_reg_operand" "")))
3156    (set (match_operand:SF 0 "gpc_reg_operand" "")
3157         (if_then_else:SF (ge (match_dup 3)
3158                              (const_int 0))
3159                          (match_dup 1)
3160                          (match_dup 2)))]
3161   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3162   "
3163 { operands[3] = gen_reg_rtx (SFmode); }")
3164
3165 (define_split
3166   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3167         (smax:SF (match_operand:SF 1 "gpc_reg_operand" "")
3168                  (match_operand:SF 2 "gpc_reg_operand" "")))
3169    (clobber (match_operand:SF 3 "gpc_reg_operand" ""))]
3170   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3171   [(set (match_dup 3)
3172         (minus:SF (match_dup 1) (match_dup 2)))
3173    (set (match_dup 0)
3174         (if_then_else:SF (ge (match_dup 3)
3175                              (const_int 0))
3176                          (match_dup 1)
3177                          (match_dup 2)))]
3178   "")
3179
3180 (define_expand "minsf3"
3181   [(set (match_dup 3)
3182         (minus:SF (match_operand:SF 2 "gpc_reg_operand" "")
3183                   (match_operand:SF 1 "gpc_reg_operand" "")))
3184    (set (match_operand:SF 0 "gpc_reg_operand" "")
3185         (if_then_else:SF (ge (match_dup 3)
3186                              (const_int 0))
3187                          (match_dup 1)
3188                          (match_dup 2)))]
3189   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3190   "
3191 { operands[3] = gen_reg_rtx (SFmode); }")
3192
3193 (define_split
3194   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3195         (smin:SF (match_operand:SF 1 "gpc_reg_operand" "")
3196                  (match_operand:SF 2 "gpc_reg_operand" "")))
3197    (clobber (match_operand:SF 3 "gpc_reg_operand" ""))]
3198   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3199   [(set (match_dup 3)
3200         (minus:SF (match_dup 2) (match_dup 1)))
3201    (set (match_dup 0)
3202         (if_then_else:SF (ge (match_dup 3)
3203                              (const_int 0))
3204                          (match_dup 1)
3205                          (match_dup 2)))]
3206   "")
3207
3208 (define_expand "movsfcc"
3209    [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3210          (if_then_else:SF (match_operand 1 "comparison_operator" "")
3211                           (match_operand:SF 2 "gpc_reg_operand" "f")
3212                           (match_operand:SF 3 "gpc_reg_operand" "f")))]
3213   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3214   "
3215 {
3216   rtx temp, op0, op1;
3217   enum rtx_code code = GET_CODE (operands[1]);
3218   if (! rs6000_compare_fp_p)
3219     FAIL;
3220   switch (code)
3221     {
3222     case GE: case EQ: case NE:
3223       op0 = rs6000_compare_op0;
3224       op1 = rs6000_compare_op1;
3225       break;
3226     case GT:
3227       op0 = rs6000_compare_op1;
3228       op1 = rs6000_compare_op0;
3229       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3230       break;
3231     case LE:
3232       op0 = rs6000_compare_op1;
3233       op1 = rs6000_compare_op0;
3234       break;
3235     case LT:
3236       op0 = rs6000_compare_op0;
3237       op1 = rs6000_compare_op1;
3238       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3239       break;
3240     default:
3241       FAIL;
3242     }
3243   if (GET_MODE (rs6000_compare_op0) == DFmode)
3244     {
3245       temp = gen_reg_rtx (DFmode);
3246       emit_insn (gen_subdf3 (temp, op0, op1));
3247       emit_insn (gen_fseldfsf4 (operands[0], temp, operands[2], operands[3]));
3248       if (code == EQ)
3249         {
3250           emit_insn (gen_negdf2 (temp, temp));
3251           emit_insn (gen_fseldfsf4 (operands[0], temp, operands[0], operands[3]));
3252         }
3253       if (code == NE)
3254         {
3255           emit_insn (gen_negdf2 (temp, temp));
3256           emit_insn (gen_fseldfsf4 (operands[0], temp, operands[3], operands[0]));
3257         }
3258     }
3259   else
3260     {
3261       temp = gen_reg_rtx (SFmode);
3262       emit_insn (gen_subsf3 (temp, op0, op1));
3263       emit_insn (gen_fselsfsf4 (operands[0], temp, operands[2], operands[3]));
3264       if (code == EQ)
3265         {
3266           emit_insn (gen_negsf2 (temp, temp));
3267           emit_insn (gen_fselsfsf4 (operands[0], temp, operands[0], operands[3]));
3268         }
3269       if (code == NE)
3270         {
3271           emit_insn (gen_negsf2 (temp, temp));
3272           emit_insn (gen_fselsfsf4 (operands[0], temp, operands[3], operands[0]));
3273         }
3274     }
3275   DONE;
3276 }")
3277
3278 (define_insn "fselsfsf4"
3279   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3280         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
3281                              (const_int 0))
3282                          (match_operand:SF 2 "gpc_reg_operand" "f")
3283                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
3284   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3285   "fsel %0,%1,%2,%3"
3286   [(set_attr "type" "fp")])
3287
3288 (define_insn "fseldfsf4"
3289   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3290         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
3291                              (const_int 0))
3292                          (match_operand:SF 2 "gpc_reg_operand" "f")
3293                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
3294   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3295   "fsel %0,%1,%2,%3"
3296   [(set_attr "type" "fp")])
3297
3298 (define_insn "negdf2"
3299   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3300         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3301   "TARGET_HARD_FLOAT"
3302   "fneg %0,%1"
3303   [(set_attr "type" "fp")])
3304
3305 (define_insn "absdf2"
3306   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3307         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3308   "TARGET_HARD_FLOAT"
3309   "fabs %0,%1"
3310   [(set_attr "type" "fp")])
3311
3312 (define_insn ""
3313   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3314         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
3315   "TARGET_HARD_FLOAT"
3316   "fnabs %0,%1"
3317   [(set_attr "type" "fp")])
3318
3319 (define_insn "adddf3"
3320   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3321         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3322                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
3323   "TARGET_HARD_FLOAT"
3324   "{fa|fadd} %0,%1,%2"
3325   [(set_attr "type" "fp")])
3326
3327 (define_insn "subdf3"
3328   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3329         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
3330                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
3331   "TARGET_HARD_FLOAT"
3332   "{fs|fsub} %0,%1,%2"
3333   [(set_attr "type" "fp")])
3334
3335 (define_insn "muldf3"
3336   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3337         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3338                  (match