OSDN Git Service

Revert:
[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, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc.
5 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6
7 ;; This file is part of GCC.
8
9 ;; GCC is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 3, or (at your
12 ;; option) any later version.
13
14 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
15 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
17 ;; License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GCC; see the file COPYING3.  If not see
21 ;; <http://www.gnu.org/licenses/>.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;;
26 ;; REGNOS
27 ;;
28
29 (define_constants
30   [(MQ_REGNO                    64)
31    (LR_REGNO                    65)
32    (CTR_REGNO                   66)
33    (CR0_REGNO                   68)
34    (CR1_REGNO                   69)
35    (CR2_REGNO                   70)
36    (CR3_REGNO                   71)
37    (CR4_REGNO                   72)
38    (CR5_REGNO                   73)
39    (CR6_REGNO                   74)
40    (CR7_REGNO                   75)
41    (MAX_CR_REGNO                75)
42    (XER_REGNO                   76)
43    (FIRST_ALTIVEC_REGNO         77)
44    (LAST_ALTIVEC_REGNO          108)
45    (VRSAVE_REGNO                109)
46    (VSCR_REGNO                  110)
47    (SPE_ACC_REGNO               111)
48    (SPEFSCR_REGNO               112)
49    (SFP_REGNO                   113)
50   ])
51
52 ;;
53 ;; UNSPEC usage
54 ;;
55
56 (define_constants
57   [(UNSPEC_FRSP                 0)      ; frsp for POWER machines
58    (UNSPEC_TIE                  5)      ; tie stack contents and stack pointer
59    (UNSPEC_TOCPTR               6)      ; address of a word pointing to the TOC
60    (UNSPEC_TOC                  7)      ; address of the TOC (more-or-less)
61    (UNSPEC_MOVSI_GOT            8)
62    (UNSPEC_MV_CR_OV             9)      ; move_from_CR_ov_bit
63    (UNSPEC_FCTIWZ               10)
64    (UNSPEC_FRIM                 11)
65    (UNSPEC_FRIN                 12)
66    (UNSPEC_FRIP                 13)
67    (UNSPEC_FRIZ                 14)
68    (UNSPEC_LD_MPIC              15)     ; load_macho_picbase
69    (UNSPEC_MPIC_CORRECT         16)     ; macho_correct_pic
70    (UNSPEC_TLSGD                17)
71    (UNSPEC_TLSLD                18)
72    (UNSPEC_MOVESI_FROM_CR       19)
73    (UNSPEC_MOVESI_TO_CR         20)
74    (UNSPEC_TLSDTPREL            21)
75    (UNSPEC_TLSDTPRELHA          22)
76    (UNSPEC_TLSDTPRELLO          23)
77    (UNSPEC_TLSGOTDTPREL         24)
78    (UNSPEC_TLSTPREL             25)
79    (UNSPEC_TLSTPRELHA           26)
80    (UNSPEC_TLSTPRELLO           27)
81    (UNSPEC_TLSGOTTPREL          28)
82    (UNSPEC_TLSTLS               29)
83    (UNSPEC_FIX_TRUNC_TF         30)     ; fadd, rounding towards zero
84    (UNSPEC_MV_CR_GT             31)     ; move_from_CR_gt_bit
85    (UNSPEC_STFIWX               32)
86    (UNSPEC_POPCNTB              33)
87    (UNSPEC_FRES                 34)
88    (UNSPEC_SP_SET               35)
89    (UNSPEC_SP_TEST              36)
90    (UNSPEC_SYNC                 37)
91    (UNSPEC_LWSYNC               38)
92    (UNSPEC_ISYNC                39)
93    (UNSPEC_SYNC_OP              40)
94    (UNSPEC_ATOMIC               41)
95    (UNSPEC_CMPXCHG              42)
96    (UNSPEC_XCHG                 43)
97    (UNSPEC_AND                  44)
98    (UNSPEC_DLMZB                45)
99    (UNSPEC_DLMZB_CR             46)
100    (UNSPEC_DLMZB_STRLEN         47)
101    (UNSPEC_RSQRT                48)
102    (UNSPEC_TOCREL               49)
103    (UNSPEC_MACHOPIC_OFFSET      50)
104   ])
105
106 ;;
107 ;; UNSPEC_VOLATILE usage
108 ;;
109
110 (define_constants
111   [(UNSPECV_BLOCK               0)
112    (UNSPECV_LL                  1)      ; load-locked
113    (UNSPECV_SC                  2)      ; store-conditional
114    (UNSPECV_EH_RR               9)      ; eh_reg_restore
115   ])
116 \f
117 ;; Define an insn type attribute.  This is used in function unit delay
118 ;; computations.
119 (define_attr "type" "integer,two,three,load,load_ext,load_ext_u,load_ext_ux,load_ux,load_u,store,store_ux,store_u,fpload,fpload_ux,fpload_u,fpstore,fpstore_ux,fpstore_u,vecload,vecstore,imul,imul2,imul3,lmul,idiv,ldiv,insert_word,branch,cmp,fast_compare,compare,var_delayed_compare,delayed_compare,imul_compare,lmul_compare,fpcompare,cr_logical,delayed_cr,mfcr,mfcrf,mtcr,mfjmpr,mtjmpr,fp,fpsimple,dmul,sdiv,ddiv,ssqrt,dsqrt,jmpreg,brinc,vecsimple,veccomplex,vecdiv,veccmp,veccmpsimple,vecperm,vecfloat,vecfdiv,isync,sync,load_l,store_c,shift,trap,insert_dword,var_shift_rotate,cntlz,exts,mffgpr,mftgpr"
120   (const_string "integer"))
121
122 ;; Define floating point instruction sub-types for use with Xfpu.md
123 (define_attr "fp_type" "fp_default,fp_addsub_s,fp_addsub_d,fp_mul_s,fp_mul_d,fp_div_s,fp_div_d,fp_maddsub_s,fp_maddsub_d,fp_sqrt_s,fp_sqrt_d" (const_string "fp_default"))
124
125 ;; Length (in bytes).
126 ; '(pc)' in the following doesn't include the instruction itself; it is
127 ; calculated as if the instruction had zero size.
128 (define_attr "length" ""
129   (if_then_else (eq_attr "type" "branch")
130                 (if_then_else (and (ge (minus (match_dup 0) (pc))
131                                        (const_int -32768))
132                                    (lt (minus (match_dup 0) (pc))
133                                        (const_int 32764)))
134                               (const_int 4)
135                               (const_int 8))
136                 (const_int 4)))
137
138 ;; Processor type -- this attribute must exactly match the processor_type
139 ;; enumeration in rs6000.h.
140
141 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,ppce300c2,ppce300c3,ppce500mc,power4,power5,power6,cell"
142   (const (symbol_ref "rs6000_cpu_attr")))
143
144
145 ;; If this instruction is microcoded on the CELL processor
146 ; The default for load extended, the recorded instructions and rotate/shifts by a variable is always microcoded
147 (define_attr "cell_micro" "not,conditional,always"
148   (if_then_else (eq_attr "type" "compare,delayed_compare,imul_compare,lmul_compare,load_ext,load_ext_ux,var_shift_rotate,var_delayed_compare")
149                 (const_string "always")
150                 (const_string "not")))
151
152 (automata_option "ndfa")
153
154 (include "rios1.md")
155 (include "rios2.md")
156 (include "rs64.md")
157 (include "mpc.md")
158 (include "40x.md")
159 (include "440.md")
160 (include "603.md")
161 (include "6xx.md")
162 (include "7xx.md")
163 (include "7450.md")
164 (include "8540.md")
165 (include "e300c2c3.md")
166 (include "e500mc.md")
167 (include "power4.md")
168 (include "power5.md")
169 (include "power6.md")
170 (include "cell.md")
171 (include "xfpu.md")
172
173 (include "predicates.md")
174 (include "constraints.md")
175
176 (include "darwin.md")
177
178 \f
179 ;; Mode iterators
180
181 ; This mode iterator allows :GPR to be used to indicate the allowable size
182 ; of whole values in GPRs.
183 (define_mode_iterator GPR [SI (DI "TARGET_POWERPC64")])
184
185 ; Any supported integer mode.
186 (define_mode_iterator INT [QI HI SI DI TI])
187
188 ; Any supported integer mode that fits in one register.
189 (define_mode_iterator INT1 [QI HI SI (DI "TARGET_POWERPC64")])
190
191 ; extend modes for DImode
192 (define_mode_iterator QHSI [QI HI SI])
193
194 ; SImode or DImode, even if DImode doesn't fit in GPRs.
195 (define_mode_iterator SDI [SI DI])
196
197 ; The size of a pointer.  Also, the size of the value that a record-condition
198 ; (one with a '.') will compare.
199 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
200
201 ; Any hardware-supported floating-point mode
202 (define_mode_iterator FP [
203   (SF "TARGET_HARD_FLOAT 
204    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) || TARGET_E500_SINGLE)")
205   (DF "TARGET_HARD_FLOAT 
206    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)")
207   (TF "!TARGET_IEEEQUAD
208    && TARGET_HARD_FLOAT
209    && (TARGET_FPRS || TARGET_E500_DOUBLE)
210    && TARGET_LONG_DOUBLE_128")
211   (DD "TARGET_DFP")
212   (TD "TARGET_DFP")])
213
214 ; Various instructions that come in SI and DI forms.
215 ; A generic w/d attribute, for things like cmpw/cmpd.
216 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
217
218 ; DImode bits
219 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
220
221 \f
222 ;; Start with fixed-point load and store insns.  Here we put only the more
223 ;; complex forms.  Basic data transfer is done later.
224
225 (define_expand "zero_extend<mode>di2"
226   [(set (match_operand:DI 0 "gpc_reg_operand" "")
227         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
228   "TARGET_POWERPC64"
229   "")
230
231 (define_insn "*zero_extend<mode>di2_internal1"
232   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
233         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
234   "TARGET_POWERPC64"
235   "@
236    l<wd>z%U1%X1 %0,%1
237    rldicl %0,%1,0,<dbits>"
238   [(set_attr "type" "load,*")])
239
240 (define_insn "*zero_extend<mode>di2_internal2"
241   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
242         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
243                     (const_int 0)))
244    (clobber (match_scratch:DI 2 "=r,r"))]
245   "TARGET_64BIT"
246   "@
247    rldicl. %2,%1,0,<dbits>
248    #"
249   [(set_attr "type" "compare")
250    (set_attr "length" "4,8")])
251
252 (define_split
253   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
254         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
255                     (const_int 0)))
256    (clobber (match_scratch:DI 2 ""))]
257   "TARGET_POWERPC64 && reload_completed"
258   [(set (match_dup 2)
259         (zero_extend:DI (match_dup 1)))
260    (set (match_dup 0)
261         (compare:CC (match_dup 2)
262                     (const_int 0)))]
263   "")
264
265 (define_insn "*zero_extend<mode>di2_internal3"
266   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
267         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
268                     (const_int 0)))
269    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
270         (zero_extend:DI (match_dup 1)))]
271   "TARGET_64BIT"
272   "@
273    rldicl. %0,%1,0,<dbits>
274    #"
275   [(set_attr "type" "compare")
276    (set_attr "length" "4,8")])
277
278 (define_split
279   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
280         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
281                     (const_int 0)))
282    (set (match_operand:DI 0 "gpc_reg_operand" "")
283         (zero_extend:DI (match_dup 1)))]
284   "TARGET_POWERPC64 && reload_completed"
285   [(set (match_dup 0)
286         (zero_extend:DI (match_dup 1)))
287    (set (match_dup 2)
288         (compare:CC (match_dup 0)
289                     (const_int 0)))]
290   "")
291
292 (define_insn "extendqidi2"
293   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
294         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
295   "TARGET_POWERPC64"
296   "extsb %0,%1"
297   [(set_attr "type" "exts")])
298
299 (define_insn ""
300   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
301         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
302                     (const_int 0)))
303    (clobber (match_scratch:DI 2 "=r,r"))]
304   "TARGET_64BIT"
305   "@
306    extsb. %2,%1
307    #"
308   [(set_attr "type" "compare")
309    (set_attr "length" "4,8")])
310
311 (define_split
312   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
313         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
314                     (const_int 0)))
315    (clobber (match_scratch:DI 2 ""))]
316   "TARGET_POWERPC64 && reload_completed"
317   [(set (match_dup 2)
318         (sign_extend:DI (match_dup 1)))
319    (set (match_dup 0)
320         (compare:CC (match_dup 2)
321                     (const_int 0)))]
322   "")
323
324 (define_insn ""
325   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
326         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
327                     (const_int 0)))
328    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
329         (sign_extend:DI (match_dup 1)))]
330   "TARGET_64BIT"
331   "@
332    extsb. %0,%1
333    #"
334   [(set_attr "type" "compare")
335    (set_attr "length" "4,8")])
336
337 (define_split
338   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
339         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
340                     (const_int 0)))
341    (set (match_operand:DI 0 "gpc_reg_operand" "")
342         (sign_extend:DI (match_dup 1)))]
343   "TARGET_POWERPC64 && reload_completed"
344   [(set (match_dup 0)
345         (sign_extend:DI (match_dup 1)))
346    (set (match_dup 2)
347         (compare:CC (match_dup 0)
348                     (const_int 0)))]
349   "")
350
351 (define_expand "extendhidi2"
352   [(set (match_operand:DI 0 "gpc_reg_operand" "")
353         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
354   "TARGET_POWERPC64"
355   "")
356
357 (define_insn ""
358   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
359         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
360   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
361   "@
362    lha%U1%X1 %0,%1
363    extsh %0,%1"
364   [(set_attr "type" "load_ext,exts")])
365
366 (define_insn ""
367   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
368         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
369   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
370   "extsh %0,%1"
371   [(set_attr "type" "exts")])
372
373 (define_insn ""
374   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
375         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
376                     (const_int 0)))
377    (clobber (match_scratch:DI 2 "=r,r"))]
378   "TARGET_64BIT"
379   "@
380    extsh. %2,%1
381    #"
382   [(set_attr "type" "compare")
383    (set_attr "length" "4,8")])
384
385 (define_split
386   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
387         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
388                     (const_int 0)))
389    (clobber (match_scratch:DI 2 ""))]
390   "TARGET_POWERPC64 && reload_completed"
391   [(set (match_dup 2)
392         (sign_extend:DI (match_dup 1)))
393    (set (match_dup 0)
394         (compare:CC (match_dup 2)
395                     (const_int 0)))]
396   "")
397
398 (define_insn ""
399   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
400         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
401                     (const_int 0)))
402    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
403         (sign_extend:DI (match_dup 1)))]
404   "TARGET_64BIT"
405   "@
406    extsh. %0,%1
407    #"
408   [(set_attr "type" "compare")
409    (set_attr "length" "4,8")])
410
411 (define_split
412   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
413         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
414                     (const_int 0)))
415    (set (match_operand:DI 0 "gpc_reg_operand" "")
416         (sign_extend:DI (match_dup 1)))]
417   "TARGET_POWERPC64 && reload_completed"
418   [(set (match_dup 0)
419         (sign_extend:DI (match_dup 1)))
420    (set (match_dup 2)
421         (compare:CC (match_dup 0)
422                     (const_int 0)))]
423   "")
424
425 (define_expand "extendsidi2"
426   [(set (match_operand:DI 0 "gpc_reg_operand" "")
427         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
428   "TARGET_POWERPC64"
429   "")
430
431 (define_insn ""
432   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
433         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
434   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
435   "@
436    lwa%U1%X1 %0,%1
437    extsw %0,%1"
438   [(set_attr "type" "load_ext,exts")])
439
440 (define_insn ""
441   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
442         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
443   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
444   "extsw %0,%1"
445   [(set_attr "type" "exts")])
446
447 (define_insn ""
448   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
449         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
450                     (const_int 0)))
451    (clobber (match_scratch:DI 2 "=r,r"))]
452   "TARGET_64BIT"
453   "@
454    extsw. %2,%1
455    #"
456   [(set_attr "type" "compare")
457    (set_attr "length" "4,8")])
458
459 (define_split
460   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
461         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
462                     (const_int 0)))
463    (clobber (match_scratch:DI 2 ""))]
464   "TARGET_POWERPC64 && reload_completed"
465   [(set (match_dup 2)
466         (sign_extend:DI (match_dup 1)))
467    (set (match_dup 0)
468         (compare:CC (match_dup 2)
469                     (const_int 0)))]
470   "")
471
472 (define_insn ""
473   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
474         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
475                     (const_int 0)))
476    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
477         (sign_extend:DI (match_dup 1)))]
478   "TARGET_64BIT"
479   "@
480    extsw. %0,%1
481    #"
482   [(set_attr "type" "compare")
483    (set_attr "length" "4,8")])
484
485 (define_split
486   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
487         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
488                     (const_int 0)))
489    (set (match_operand:DI 0 "gpc_reg_operand" "")
490         (sign_extend:DI (match_dup 1)))]
491   "TARGET_POWERPC64 && reload_completed"
492   [(set (match_dup 0)
493         (sign_extend:DI (match_dup 1)))
494    (set (match_dup 2)
495         (compare:CC (match_dup 0)
496                     (const_int 0)))]
497   "")
498
499 (define_expand "zero_extendqisi2"
500   [(set (match_operand:SI 0 "gpc_reg_operand" "")
501         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
502   ""
503   "")
504
505 (define_insn ""
506   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
507         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
508   ""
509   "@
510    lbz%U1%X1 %0,%1
511    {rlinm|rlwinm} %0,%1,0,0xff"
512   [(set_attr "type" "load,*")])
513
514 (define_insn ""
515   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
516         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
517                     (const_int 0)))
518    (clobber (match_scratch:SI 2 "=r,r"))]
519   ""
520   "@
521    {andil.|andi.} %2,%1,0xff
522    #"
523   [(set_attr "type" "compare")
524    (set_attr "length" "4,8")])
525
526 (define_split
527   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
528         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
529                     (const_int 0)))
530    (clobber (match_scratch:SI 2 ""))]
531   "reload_completed"
532   [(set (match_dup 2)
533         (zero_extend:SI (match_dup 1)))
534    (set (match_dup 0)
535         (compare:CC (match_dup 2)
536                     (const_int 0)))]
537   "")
538
539 (define_insn ""
540   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
541         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
542                     (const_int 0)))
543    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
544         (zero_extend:SI (match_dup 1)))]
545   ""
546   "@
547    {andil.|andi.} %0,%1,0xff
548    #"
549   [(set_attr "type" "compare")
550    (set_attr "length" "4,8")])
551
552 (define_split
553   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
554         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
555                     (const_int 0)))
556    (set (match_operand:SI 0 "gpc_reg_operand" "")
557         (zero_extend:SI (match_dup 1)))]
558   "reload_completed"
559   [(set (match_dup 0)
560         (zero_extend:SI (match_dup 1)))
561    (set (match_dup 2)
562         (compare:CC (match_dup 0)
563                     (const_int 0)))]
564   "")
565
566 (define_expand "extendqisi2"
567   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
568    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
569   ""
570   "
571 {
572   if (TARGET_POWERPC)
573     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
574   else if (TARGET_POWER)
575     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
576   else
577     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
578   DONE;
579 }")
580
581 (define_insn "extendqisi2_ppc"
582   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
583         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
584   "TARGET_POWERPC"
585   "extsb %0,%1"
586   [(set_attr "type" "exts")])
587
588 (define_insn ""
589   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
590         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
591                     (const_int 0)))
592    (clobber (match_scratch:SI 2 "=r,r"))]
593   "TARGET_POWERPC"
594   "@
595    extsb. %2,%1
596    #"
597   [(set_attr "type" "compare")
598    (set_attr "length" "4,8")])
599
600 (define_split
601   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
602         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
603                     (const_int 0)))
604    (clobber (match_scratch:SI 2 ""))]
605   "TARGET_POWERPC && reload_completed"
606   [(set (match_dup 2)
607         (sign_extend:SI (match_dup 1)))
608    (set (match_dup 0)
609         (compare:CC (match_dup 2)
610                     (const_int 0)))]
611   "")
612
613 (define_insn ""
614   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
615         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
616                     (const_int 0)))
617    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
618         (sign_extend:SI (match_dup 1)))]
619   "TARGET_POWERPC"
620   "@
621    extsb. %0,%1
622    #"
623   [(set_attr "type" "compare")
624    (set_attr "length" "4,8")])
625
626 (define_split
627   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
628         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
629                     (const_int 0)))
630    (set (match_operand:SI 0 "gpc_reg_operand" "")
631         (sign_extend:SI (match_dup 1)))]
632   "TARGET_POWERPC && reload_completed"
633   [(set (match_dup 0)
634         (sign_extend:SI (match_dup 1)))
635    (set (match_dup 2)
636         (compare:CC (match_dup 0)
637                     (const_int 0)))]
638   "")
639
640 (define_expand "extendqisi2_power"
641   [(parallel [(set (match_dup 2)
642                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
643                               (const_int 24)))
644               (clobber (scratch:SI))])
645    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
646                    (ashiftrt:SI (match_dup 2)
647                                 (const_int 24)))
648               (clobber (scratch:SI))])]
649   "TARGET_POWER"
650   "
651 { operands[1] = gen_lowpart (SImode, operands[1]);
652   operands[2] = gen_reg_rtx (SImode); }")
653
654 (define_expand "extendqisi2_no_power"
655   [(set (match_dup 2)
656         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
657                    (const_int 24)))
658    (set (match_operand:SI 0 "gpc_reg_operand" "")
659         (ashiftrt:SI (match_dup 2)
660                      (const_int 24)))]
661   "! TARGET_POWER && ! TARGET_POWERPC"
662   "
663 { operands[1] = gen_lowpart (SImode, operands[1]);
664   operands[2] = gen_reg_rtx (SImode); }")
665
666 (define_expand "zero_extendqihi2"
667   [(set (match_operand:HI 0 "gpc_reg_operand" "")
668         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
669   ""
670   "")
671
672 (define_insn ""
673   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
674         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
675   ""
676   "@
677    lbz%U1%X1 %0,%1
678    {rlinm|rlwinm} %0,%1,0,0xff"
679   [(set_attr "type" "load,*")])
680
681 (define_insn ""
682   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
683         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
684                     (const_int 0)))
685    (clobber (match_scratch:HI 2 "=r,r"))]
686   ""
687   "@
688    {andil.|andi.} %2,%1,0xff
689    #"
690   [(set_attr "type" "compare")
691    (set_attr "length" "4,8")])
692
693 (define_split
694   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
695         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
696                     (const_int 0)))
697    (clobber (match_scratch:HI 2 ""))]
698   "reload_completed"
699   [(set (match_dup 2)
700         (zero_extend:HI (match_dup 1)))
701    (set (match_dup 0)
702         (compare:CC (match_dup 2)
703                     (const_int 0)))]
704   "")
705
706 (define_insn ""
707   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
708         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
709                     (const_int 0)))
710    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
711         (zero_extend:HI (match_dup 1)))]
712   ""
713   "@
714    {andil.|andi.} %0,%1,0xff
715    #"
716   [(set_attr "type" "compare")
717    (set_attr "length" "4,8")])
718
719 (define_split
720   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
721         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
722                     (const_int 0)))
723    (set (match_operand:HI 0 "gpc_reg_operand" "")
724         (zero_extend:HI (match_dup 1)))]
725   "reload_completed"
726   [(set (match_dup 0)
727         (zero_extend:HI (match_dup 1)))
728    (set (match_dup 2)
729         (compare:CC (match_dup 0)
730                     (const_int 0)))]
731   "")
732
733 (define_expand "extendqihi2"
734   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
735    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
736   ""
737   "
738 {
739   if (TARGET_POWERPC)
740     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
741   else if (TARGET_POWER)
742     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
743   else
744     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
745   DONE;
746 }")
747
748 (define_insn "extendqihi2_ppc"
749   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
750         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
751   "TARGET_POWERPC"
752   "extsb %0,%1"
753   [(set_attr "type" "exts")])
754
755 (define_insn ""
756   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
757         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
758                     (const_int 0)))
759    (clobber (match_scratch:HI 2 "=r,r"))]
760   "TARGET_POWERPC"
761   "@
762    extsb. %2,%1
763    #"
764   [(set_attr "type" "compare")
765    (set_attr "length" "4,8")])
766
767 (define_split
768   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
769         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
770                     (const_int 0)))
771    (clobber (match_scratch:HI 2 ""))]
772   "TARGET_POWERPC && reload_completed"
773   [(set (match_dup 2)
774         (sign_extend:HI (match_dup 1)))
775    (set (match_dup 0)
776         (compare:CC (match_dup 2)
777                     (const_int 0)))]
778   "")
779
780 (define_insn ""
781   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
782         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
783                     (const_int 0)))
784    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
785         (sign_extend:HI (match_dup 1)))]
786   "TARGET_POWERPC"
787   "@
788    extsb. %0,%1
789    #"
790   [(set_attr "type" "compare")
791    (set_attr "length" "4,8")])
792
793 (define_split
794   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
795         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
796                     (const_int 0)))
797    (set (match_operand:HI 0 "gpc_reg_operand" "")
798         (sign_extend:HI (match_dup 1)))]
799   "TARGET_POWERPC && reload_completed"
800   [(set (match_dup 0)
801         (sign_extend:HI (match_dup 1)))
802    (set (match_dup 2)
803         (compare:CC (match_dup 0)
804                     (const_int 0)))]
805   "")
806
807 (define_expand "extendqihi2_power"
808   [(parallel [(set (match_dup 2)
809                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
810                               (const_int 24)))
811               (clobber (scratch:SI))])
812    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
813                    (ashiftrt:SI (match_dup 2)
814                                 (const_int 24)))
815               (clobber (scratch:SI))])]
816   "TARGET_POWER"
817   "
818 { operands[0] = gen_lowpart (SImode, operands[0]);
819   operands[1] = gen_lowpart (SImode, operands[1]);
820   operands[2] = gen_reg_rtx (SImode); }")
821
822 (define_expand "extendqihi2_no_power"
823   [(set (match_dup 2)
824         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
825                    (const_int 24)))
826    (set (match_operand:HI 0 "gpc_reg_operand" "")
827         (ashiftrt:SI (match_dup 2)
828                      (const_int 24)))]
829   "! TARGET_POWER && ! TARGET_POWERPC"
830   "
831 { operands[0] = gen_lowpart (SImode, operands[0]);
832   operands[1] = gen_lowpart (SImode, operands[1]);
833   operands[2] = gen_reg_rtx (SImode); }")
834
835 (define_expand "zero_extendhisi2"
836   [(set (match_operand:SI 0 "gpc_reg_operand" "")
837         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
838   ""
839   "")
840
841 (define_insn ""
842   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
843         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
844   ""
845   "@
846    lhz%U1%X1 %0,%1
847    {rlinm|rlwinm} %0,%1,0,0xffff"
848   [(set_attr "type" "load,*")])
849
850 (define_insn ""
851   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
852         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
853                     (const_int 0)))
854    (clobber (match_scratch:SI 2 "=r,r"))]
855   ""
856   "@
857    {andil.|andi.} %2,%1,0xffff
858    #"
859   [(set_attr "type" "compare")
860    (set_attr "length" "4,8")])
861
862 (define_split
863   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
864         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
865                     (const_int 0)))
866    (clobber (match_scratch:SI 2 ""))]
867   "reload_completed"
868   [(set (match_dup 2)
869         (zero_extend:SI (match_dup 1)))
870    (set (match_dup 0)
871         (compare:CC (match_dup 2)
872                     (const_int 0)))]
873   "")
874
875 (define_insn ""
876   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
877         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
878                     (const_int 0)))
879    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
880         (zero_extend:SI (match_dup 1)))]
881   ""
882   "@
883    {andil.|andi.} %0,%1,0xffff
884    #"
885   [(set_attr "type" "compare")
886    (set_attr "length" "4,8")])
887
888 (define_split
889   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
890         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
891                     (const_int 0)))
892    (set (match_operand:SI 0 "gpc_reg_operand" "")
893         (zero_extend:SI (match_dup 1)))]
894   "reload_completed"
895   [(set (match_dup 0)
896         (zero_extend:SI (match_dup 1)))
897    (set (match_dup 2)
898         (compare:CC (match_dup 0)
899                     (const_int 0)))]
900   "")
901
902 (define_expand "extendhisi2"
903   [(set (match_operand:SI 0 "gpc_reg_operand" "")
904         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
905   ""
906   "")
907
908 (define_insn ""
909   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
910         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
911   "rs6000_gen_cell_microcode"
912   "@
913    lha%U1%X1 %0,%1
914    {exts|extsh} %0,%1"
915   [(set_attr "type" "load_ext,exts")])
916
917 (define_insn ""
918   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
919         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
920   "!rs6000_gen_cell_microcode"
921   "{exts|extsh} %0,%1"
922   [(set_attr "type" "exts")])
923
924 (define_insn ""
925   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
926         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
927                     (const_int 0)))
928    (clobber (match_scratch:SI 2 "=r,r"))]
929   ""
930   "@
931    {exts.|extsh.} %2,%1
932    #"
933   [(set_attr "type" "compare")
934    (set_attr "length" "4,8")])
935
936 (define_split
937   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
938         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
939                     (const_int 0)))
940    (clobber (match_scratch:SI 2 ""))]
941   "reload_completed"
942   [(set (match_dup 2)
943         (sign_extend:SI (match_dup 1)))
944    (set (match_dup 0)
945         (compare:CC (match_dup 2)
946                     (const_int 0)))]
947   "")
948
949 (define_insn ""
950   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
951         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
952                     (const_int 0)))
953    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
954         (sign_extend:SI (match_dup 1)))]
955   ""
956   "@
957    {exts.|extsh.} %0,%1
958    #"
959   [(set_attr "type" "compare")
960    (set_attr "length" "4,8")])
961 \f
962 ;; IBM 405, 440 and 464 half-word multiplication operations.
963
964 (define_insn "*macchwc"
965   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
966         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
967                                        (match_operand:SI 2 "gpc_reg_operand" "r")
968                                        (const_int 16))
969                                       (sign_extend:SI
970                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
971                              (match_operand:SI 4 "gpc_reg_operand" "0"))
972                     (const_int 0)))
973    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
974         (plus:SI (mult:SI (ashiftrt:SI
975                            (match_dup 2)
976                            (const_int 16))
977                           (sign_extend:SI
978                            (match_dup 1)))
979                  (match_dup 4)))]
980   "TARGET_MULHW"
981   "macchw. %0, %1, %2"
982   [(set_attr "type" "imul3")])
983
984 (define_insn "*macchw"
985   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
986         (plus:SI (mult:SI (ashiftrt:SI
987                            (match_operand:SI 2 "gpc_reg_operand" "r")
988                            (const_int 16))
989                           (sign_extend:SI
990                            (match_operand:HI 1 "gpc_reg_operand" "r")))
991                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
992   "TARGET_MULHW"
993   "macchw %0, %1, %2"
994   [(set_attr "type" "imul3")])
995
996 (define_insn "*macchwuc"
997   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
998         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
999                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1000                                        (const_int 16))
1001                                       (zero_extend:SI
1002                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1003                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1004                     (const_int 0)))
1005    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1006         (plus:SI (mult:SI (lshiftrt:SI
1007                            (match_dup 2)
1008                            (const_int 16))
1009                           (zero_extend:SI
1010                            (match_dup 1)))
1011                  (match_dup 4)))]
1012   "TARGET_MULHW"
1013   "macchwu. %0, %1, %2"
1014   [(set_attr "type" "imul3")])
1015
1016 (define_insn "*macchwu"
1017   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1018         (plus:SI (mult:SI (lshiftrt:SI
1019                            (match_operand:SI 2 "gpc_reg_operand" "r")
1020                            (const_int 16))
1021                           (zero_extend:SI
1022                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1023                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1024   "TARGET_MULHW"
1025   "macchwu %0, %1, %2"
1026   [(set_attr "type" "imul3")])
1027
1028 (define_insn "*machhwc"
1029   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1030         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1031                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1032                                        (const_int 16))
1033                                       (ashiftrt:SI
1034                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1035                                        (const_int 16)))
1036                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1037                     (const_int 0)))
1038    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1039         (plus:SI (mult:SI (ashiftrt:SI
1040                            (match_dup 1)
1041                            (const_int 16))
1042                           (ashiftrt:SI
1043                            (match_dup 2)
1044                            (const_int 16)))
1045                  (match_dup 4)))]
1046   "TARGET_MULHW"
1047   "machhw. %0, %1, %2"
1048   [(set_attr "type" "imul3")])
1049
1050 (define_insn "*machhw"
1051   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1052         (plus:SI (mult:SI (ashiftrt:SI
1053                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1054                            (const_int 16))
1055                           (ashiftrt:SI
1056                            (match_operand:SI 2 "gpc_reg_operand" "r")
1057                            (const_int 16)))
1058                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1059   "TARGET_MULHW"
1060   "machhw %0, %1, %2"
1061   [(set_attr "type" "imul3")])
1062
1063 (define_insn "*machhwuc"
1064   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1065         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1066                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1067                                        (const_int 16))
1068                                       (lshiftrt:SI
1069                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1070                                        (const_int 16)))
1071                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1072                     (const_int 0)))
1073    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1074         (plus:SI (mult:SI (lshiftrt:SI
1075                            (match_dup 1)
1076                            (const_int 16))
1077                           (lshiftrt:SI
1078                            (match_dup 2)
1079                            (const_int 16)))
1080                  (match_dup 4)))]
1081   "TARGET_MULHW"
1082   "machhwu. %0, %1, %2"
1083   [(set_attr "type" "imul3")])
1084
1085 (define_insn "*machhwu"
1086   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1087         (plus:SI (mult:SI (lshiftrt:SI
1088                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1089                            (const_int 16))
1090                           (lshiftrt:SI
1091                            (match_operand:SI 2 "gpc_reg_operand" "r")
1092                            (const_int 16)))
1093                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1094   "TARGET_MULHW"
1095   "machhwu %0, %1, %2"
1096   [(set_attr "type" "imul3")])
1097
1098 (define_insn "*maclhwc"
1099   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1100         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1101                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1102                                       (sign_extend:SI
1103                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1104                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1105                     (const_int 0)))
1106    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1107         (plus:SI (mult:SI (sign_extend:SI
1108                            (match_dup 1))
1109                           (sign_extend:SI
1110                            (match_dup 2)))
1111                  (match_dup 4)))]
1112   "TARGET_MULHW"
1113   "maclhw. %0, %1, %2"
1114   [(set_attr "type" "imul3")])
1115
1116 (define_insn "*maclhw"
1117   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1118         (plus:SI (mult:SI (sign_extend:SI
1119                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1120                           (sign_extend:SI
1121                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1122                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1123   "TARGET_MULHW"
1124   "maclhw %0, %1, %2"
1125   [(set_attr "type" "imul3")])
1126
1127 (define_insn "*maclhwuc"
1128   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1129         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1130                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1131                                       (zero_extend:SI
1132                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1133                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1134                     (const_int 0)))
1135    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1136         (plus:SI (mult:SI (zero_extend:SI
1137                            (match_dup 1))
1138                           (zero_extend:SI
1139                            (match_dup 2)))
1140                  (match_dup 4)))]
1141   "TARGET_MULHW"
1142   "maclhwu. %0, %1, %2"
1143   [(set_attr "type" "imul3")])
1144
1145 (define_insn "*maclhwu"
1146   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1147         (plus:SI (mult:SI (zero_extend:SI
1148                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1149                           (zero_extend:SI
1150                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1151                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1152   "TARGET_MULHW"
1153   "maclhwu %0, %1, %2"
1154   [(set_attr "type" "imul3")])
1155
1156 (define_insn "*nmacchwc"
1157   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1158         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1159                               (mult:SI (ashiftrt:SI
1160                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1161                                         (const_int 16))
1162                                        (sign_extend:SI
1163                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1164                     (const_int 0)))
1165    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1166         (minus:SI (match_dup 4)
1167                   (mult:SI (ashiftrt:SI
1168                             (match_dup 2)
1169                             (const_int 16))
1170                            (sign_extend:SI
1171                             (match_dup 1)))))]
1172   "TARGET_MULHW"
1173   "nmacchw. %0, %1, %2"
1174   [(set_attr "type" "imul3")])
1175
1176 (define_insn "*nmacchw"
1177   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1178         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1179                   (mult:SI (ashiftrt:SI
1180                             (match_operand:SI 2 "gpc_reg_operand" "r")
1181                             (const_int 16))
1182                            (sign_extend:SI
1183                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1184   "TARGET_MULHW"
1185   "nmacchw %0, %1, %2"
1186   [(set_attr "type" "imul3")])
1187
1188 (define_insn "*nmachhwc"
1189   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1190         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1191                               (mult:SI (ashiftrt:SI
1192                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1193                                         (const_int 16))
1194                                        (ashiftrt:SI
1195                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1196                                         (const_int 16))))
1197                     (const_int 0)))
1198    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1199         (minus:SI (match_dup 4)
1200                   (mult:SI (ashiftrt:SI
1201                             (match_dup 1)
1202                             (const_int 16))
1203                            (ashiftrt:SI
1204                             (match_dup 2)
1205                             (const_int 16)))))]
1206   "TARGET_MULHW"
1207   "nmachhw. %0, %1, %2"
1208   [(set_attr "type" "imul3")])
1209
1210 (define_insn "*nmachhw"
1211   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1212         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1213                   (mult:SI (ashiftrt:SI
1214                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1215                             (const_int 16))
1216                            (ashiftrt:SI
1217                             (match_operand:SI 2 "gpc_reg_operand" "r")
1218                             (const_int 16)))))]
1219   "TARGET_MULHW"
1220   "nmachhw %0, %1, %2"
1221   [(set_attr "type" "imul3")])
1222
1223 (define_insn "*nmaclhwc"
1224   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1225         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1226                               (mult:SI (sign_extend:SI
1227                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1228                                        (sign_extend:SI
1229                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1230                     (const_int 0)))
1231    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1232         (minus:SI (match_dup 4)
1233                   (mult:SI (sign_extend:SI
1234                             (match_dup 1))
1235                            (sign_extend:SI
1236                             (match_dup 2)))))]
1237   "TARGET_MULHW"
1238   "nmaclhw. %0, %1, %2"
1239   [(set_attr "type" "imul3")])
1240
1241 (define_insn "*nmaclhw"
1242   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1243         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1244                   (mult:SI (sign_extend:SI
1245                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1246                            (sign_extend:SI
1247                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1248   "TARGET_MULHW"
1249   "nmaclhw %0, %1, %2"
1250   [(set_attr "type" "imul3")])
1251
1252 (define_insn "*mulchwc"
1253   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1254         (compare:CC (mult:SI (ashiftrt:SI
1255                               (match_operand:SI 2 "gpc_reg_operand" "r")
1256                               (const_int 16))
1257                              (sign_extend:SI
1258                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1259                     (const_int 0)))
1260    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1261         (mult:SI (ashiftrt:SI
1262                   (match_dup 2)
1263                   (const_int 16))
1264                  (sign_extend:SI
1265                   (match_dup 1))))]
1266   "TARGET_MULHW"
1267   "mulchw. %0, %1, %2"
1268   [(set_attr "type" "imul3")])
1269
1270 (define_insn "*mulchw"
1271   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1272         (mult:SI (ashiftrt:SI
1273                   (match_operand:SI 2 "gpc_reg_operand" "r")
1274                   (const_int 16))
1275                  (sign_extend:SI
1276                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1277   "TARGET_MULHW"
1278   "mulchw %0, %1, %2"
1279   [(set_attr "type" "imul3")])
1280
1281 (define_insn "*mulchwuc"
1282   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1283         (compare:CC (mult:SI (lshiftrt:SI
1284                               (match_operand:SI 2 "gpc_reg_operand" "r")
1285                               (const_int 16))
1286                              (zero_extend:SI
1287                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1288                     (const_int 0)))
1289    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1290         (mult:SI (lshiftrt:SI
1291                   (match_dup 2)
1292                   (const_int 16))
1293                  (zero_extend:SI
1294                   (match_dup 1))))]
1295   "TARGET_MULHW"
1296   "mulchwu. %0, %1, %2"
1297   [(set_attr "type" "imul3")])
1298
1299 (define_insn "*mulchwu"
1300   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1301         (mult:SI (lshiftrt:SI
1302                   (match_operand:SI 2 "gpc_reg_operand" "r")
1303                   (const_int 16))
1304                  (zero_extend:SI
1305                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1306   "TARGET_MULHW"
1307   "mulchwu %0, %1, %2"
1308   [(set_attr "type" "imul3")])
1309
1310 (define_insn "*mulhhwc"
1311   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1312         (compare:CC (mult:SI (ashiftrt:SI
1313                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1314                               (const_int 16))
1315                              (ashiftrt:SI
1316                               (match_operand:SI 2 "gpc_reg_operand" "r")
1317                               (const_int 16)))
1318                     (const_int 0)))
1319    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1320         (mult:SI (ashiftrt:SI
1321                   (match_dup 1)
1322                   (const_int 16))
1323                  (ashiftrt:SI
1324                   (match_dup 2)
1325                   (const_int 16))))]
1326   "TARGET_MULHW"
1327   "mulhhw. %0, %1, %2"
1328   [(set_attr "type" "imul3")])
1329
1330 (define_insn "*mulhhw"
1331   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1332         (mult:SI (ashiftrt:SI
1333                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1334                   (const_int 16))
1335                  (ashiftrt:SI
1336                   (match_operand:SI 2 "gpc_reg_operand" "r")
1337                   (const_int 16))))]
1338   "TARGET_MULHW"
1339   "mulhhw %0, %1, %2"
1340   [(set_attr "type" "imul3")])
1341
1342 (define_insn "*mulhhwuc"
1343   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1344         (compare:CC (mult:SI (lshiftrt:SI
1345                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1346                               (const_int 16))
1347                              (lshiftrt:SI
1348                               (match_operand:SI 2 "gpc_reg_operand" "r")
1349                               (const_int 16)))
1350                     (const_int 0)))
1351    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1352         (mult:SI (lshiftrt:SI
1353                   (match_dup 1)
1354                   (const_int 16))
1355                  (lshiftrt:SI
1356                   (match_dup 2)
1357                   (const_int 16))))]
1358   "TARGET_MULHW"
1359   "mulhhwu. %0, %1, %2"
1360   [(set_attr "type" "imul3")])
1361
1362 (define_insn "*mulhhwu"
1363   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1364         (mult:SI (lshiftrt:SI
1365                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1366                   (const_int 16))
1367                  (lshiftrt:SI
1368                   (match_operand:SI 2 "gpc_reg_operand" "r")
1369                   (const_int 16))))]
1370   "TARGET_MULHW"
1371   "mulhhwu %0, %1, %2"
1372   [(set_attr "type" "imul3")])
1373
1374 (define_insn "*mullhwc"
1375   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1376         (compare:CC (mult:SI (sign_extend:SI
1377                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1378                              (sign_extend:SI
1379                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1380                     (const_int 0)))
1381    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1382         (mult:SI (sign_extend:SI
1383                   (match_dup 1))
1384                  (sign_extend:SI
1385                   (match_dup 2))))]
1386   "TARGET_MULHW"
1387   "mullhw. %0, %1, %2"
1388   [(set_attr "type" "imul3")])
1389
1390 (define_insn "*mullhw"
1391   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1392         (mult:SI (sign_extend:SI
1393                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1394                  (sign_extend:SI
1395                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1396   "TARGET_MULHW"
1397   "mullhw %0, %1, %2"
1398   [(set_attr "type" "imul3")])
1399
1400 (define_insn "*mullhwuc"
1401   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1402         (compare:CC (mult:SI (zero_extend:SI
1403                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1404                              (zero_extend:SI
1405                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1406                     (const_int 0)))
1407    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1408         (mult:SI (zero_extend:SI
1409                   (match_dup 1))
1410                  (zero_extend:SI
1411                   (match_dup 2))))]
1412   "TARGET_MULHW"
1413   "mullhwu. %0, %1, %2"
1414   [(set_attr "type" "imul3")])
1415
1416 (define_insn "*mullhwu"
1417   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1418         (mult:SI (zero_extend:SI
1419                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1420                  (zero_extend:SI
1421                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1422   "TARGET_MULHW"
1423   "mullhwu %0, %1, %2"
1424   [(set_attr "type" "imul3")])
1425 \f
1426 ;; IBM 405, 440 and 464 string-search dlmzb instruction support.
1427 (define_insn "dlmzb"
1428   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1429         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1430                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1431                    UNSPEC_DLMZB_CR))
1432    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1433         (unspec:SI [(match_dup 1)
1434                     (match_dup 2)]
1435                    UNSPEC_DLMZB))]
1436   "TARGET_DLMZB"
1437   "dlmzb. %0, %1, %2")
1438
1439 (define_expand "strlensi"
1440   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1441         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1442                     (match_operand:QI 2 "const_int_operand" "")
1443                     (match_operand 3 "const_int_operand" "")]
1444                    UNSPEC_DLMZB_STRLEN))
1445    (clobber (match_scratch:CC 4 "=x"))]
1446   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1447 {
1448   rtx result = operands[0];
1449   rtx src = operands[1];
1450   rtx search_char = operands[2];
1451   rtx align = operands[3];
1452   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1453   rtx loop_label, end_label, mem, cr0, cond;
1454   if (search_char != const0_rtx
1455       || GET_CODE (align) != CONST_INT
1456       || INTVAL (align) < 8)
1457         FAIL;
1458   word1 = gen_reg_rtx (SImode);
1459   word2 = gen_reg_rtx (SImode);
1460   scratch_dlmzb = gen_reg_rtx (SImode);
1461   scratch_string = gen_reg_rtx (Pmode);
1462   loop_label = gen_label_rtx ();
1463   end_label = gen_label_rtx ();
1464   addr = force_reg (Pmode, XEXP (src, 0));
1465   emit_move_insn (scratch_string, addr);
1466   emit_label (loop_label);
1467   mem = change_address (src, SImode, scratch_string);
1468   emit_move_insn (word1, mem);
1469   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1470   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1471   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1472   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1473   emit_jump_insn (gen_rtx_SET (VOIDmode,
1474                                pc_rtx,
1475                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1476                                                      cond,
1477                                                      gen_rtx_LABEL_REF
1478                                                        (VOIDmode,
1479                                                         end_label),
1480                                                      pc_rtx)));
1481   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1482   emit_jump_insn (gen_rtx_SET (VOIDmode,
1483                                pc_rtx,
1484                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1485   emit_barrier ();
1486   emit_label (end_label);
1487   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1488   emit_insn (gen_subsi3 (result, scratch_string, addr));
1489   emit_insn (gen_subsi3 (result, result, const1_rtx));
1490   DONE;
1491 })
1492 \f
1493 (define_split
1494   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1495         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1496                     (const_int 0)))
1497    (set (match_operand:SI 0 "gpc_reg_operand" "")
1498         (sign_extend:SI (match_dup 1)))]
1499   "reload_completed"
1500   [(set (match_dup 0)
1501         (sign_extend:SI (match_dup 1)))
1502    (set (match_dup 2)
1503         (compare:CC (match_dup 0)
1504                     (const_int 0)))]
1505   "")
1506
1507 ;; Fixed-point arithmetic insns.
1508
1509 (define_expand "add<mode>3"
1510   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1511         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1512                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1513   ""
1514 {
1515   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1516     {
1517       if (non_short_cint_operand (operands[2], DImode))
1518         FAIL;
1519     }
1520   else if (GET_CODE (operands[2]) == CONST_INT
1521            && ! add_operand (operands[2], <MODE>mode))
1522     {
1523       rtx tmp = ((!can_create_pseudo_p ()
1524                   || rtx_equal_p (operands[0], operands[1]))
1525                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1526
1527       HOST_WIDE_INT val = INTVAL (operands[2]);
1528       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1529       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1530
1531       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1532         FAIL;
1533
1534       /* The ordering here is important for the prolog expander.
1535          When space is allocated from the stack, adding 'low' first may
1536          produce a temporary deallocation (which would be bad).  */
1537       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1538       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1539       DONE;
1540     }
1541 })
1542
1543 ;; Discourage ai/addic because of carry but provide it in an alternative
1544 ;; allowing register zero as source.
1545 (define_insn "*add<mode>3_internal1"
1546   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1547         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1548                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1549   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1550   "@
1551    {cax|add} %0,%1,%2
1552    {cal %0,%2(%1)|addi %0,%1,%2}
1553    {ai|addic} %0,%1,%2
1554    {cau|addis} %0,%1,%v2"
1555   [(set_attr "length" "4,4,4,4")])
1556
1557 (define_insn "addsi3_high"
1558   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1559         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1560                  (high:SI (match_operand 2 "" ""))))]
1561   "TARGET_MACHO && !TARGET_64BIT"
1562   "{cau|addis} %0,%1,ha16(%2)"
1563   [(set_attr "length" "4")])
1564
1565 (define_insn "*add<mode>3_internal2"
1566   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1567         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1568                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1569                     (const_int 0)))
1570    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1571   ""
1572   "@
1573    {cax.|add.} %3,%1,%2
1574    {ai.|addic.} %3,%1,%2
1575    #
1576    #"
1577   [(set_attr "type" "fast_compare,compare,compare,compare")
1578    (set_attr "length" "4,4,8,8")])
1579
1580 (define_split
1581   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1582         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1583                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1584                     (const_int 0)))
1585    (clobber (match_scratch:GPR 3 ""))]
1586   "reload_completed"
1587   [(set (match_dup 3)
1588         (plus:GPR (match_dup 1)
1589                  (match_dup 2)))
1590    (set (match_dup 0)
1591         (compare:CC (match_dup 3)
1592                     (const_int 0)))]
1593   "")
1594
1595 (define_insn "*add<mode>3_internal3"
1596   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1597         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1598                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1599                     (const_int 0)))
1600    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1601         (plus:P (match_dup 1)
1602                 (match_dup 2)))]
1603   ""
1604   "@
1605    {cax.|add.} %0,%1,%2
1606    {ai.|addic.} %0,%1,%2
1607    #
1608    #"
1609   [(set_attr "type" "fast_compare,compare,compare,compare")
1610    (set_attr "length" "4,4,8,8")])
1611
1612 (define_split
1613   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1614         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1615                             (match_operand:P 2 "reg_or_short_operand" ""))
1616                     (const_int 0)))
1617    (set (match_operand:P 0 "gpc_reg_operand" "")
1618         (plus:P (match_dup 1) (match_dup 2)))]
1619   "reload_completed"
1620   [(set (match_dup 0)
1621         (plus:P (match_dup 1)
1622                 (match_dup 2)))
1623    (set (match_dup 3)
1624         (compare:CC (match_dup 0)
1625                     (const_int 0)))]
1626   "")
1627
1628 ;; Split an add that we can't do in one insn into two insns, each of which
1629 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1630 ;; add should be last in case the result gets used in an address.
1631
1632 (define_split
1633   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1634         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1635                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1636   ""
1637   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1638    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1639 {
1640   HOST_WIDE_INT val = INTVAL (operands[2]);
1641   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1642   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1643
1644   operands[4] = GEN_INT (low);
1645   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1646     operands[3] = GEN_INT (rest);
1647   else if (can_create_pseudo_p ())
1648     {
1649       operands[3] = gen_reg_rtx (DImode);
1650       emit_move_insn (operands[3], operands[2]);
1651       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1652       DONE;
1653     }
1654   else
1655     FAIL;
1656 })
1657
1658 (define_insn "one_cmpl<mode>2"
1659   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1660         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1661   ""
1662   "nor %0,%1,%1")
1663
1664 (define_insn ""
1665   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1666         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1667                     (const_int 0)))
1668    (clobber (match_scratch:P 2 "=r,r"))]
1669   ""
1670   "@
1671    nor. %2,%1,%1
1672    #"
1673   [(set_attr "type" "compare")
1674    (set_attr "length" "4,8")])
1675
1676 (define_split
1677   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1678         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1679                     (const_int 0)))
1680    (clobber (match_scratch:P 2 ""))]
1681   "reload_completed"
1682   [(set (match_dup 2)
1683         (not:P (match_dup 1)))
1684    (set (match_dup 0)
1685         (compare:CC (match_dup 2)
1686                     (const_int 0)))]
1687   "")
1688
1689 (define_insn ""
1690   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1691         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1692                     (const_int 0)))
1693    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1694         (not:P (match_dup 1)))]
1695   ""
1696   "@
1697    nor. %0,%1,%1
1698    #"
1699   [(set_attr "type" "compare")
1700    (set_attr "length" "4,8")])
1701
1702 (define_split
1703   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1704         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1705                     (const_int 0)))
1706    (set (match_operand:P 0 "gpc_reg_operand" "")
1707         (not:P (match_dup 1)))]
1708   "reload_completed"
1709   [(set (match_dup 0)
1710         (not:P (match_dup 1)))
1711    (set (match_dup 2)
1712         (compare:CC (match_dup 0)
1713                     (const_int 0)))]
1714   "")
1715
1716 (define_insn ""
1717   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1718         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1719                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1720   "! TARGET_POWERPC"
1721   "{sf%I1|subf%I1c} %0,%2,%1")
1722
1723 (define_insn ""
1724   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1725         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1726                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1727   "TARGET_POWERPC"
1728   "@
1729    subf %0,%2,%1
1730    subfic %0,%2,%1")
1731
1732 (define_insn ""
1733   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1734         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1735                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1736                     (const_int 0)))
1737    (clobber (match_scratch:SI 3 "=r,r"))]
1738   "! TARGET_POWERPC"
1739   "@
1740    {sf.|subfc.} %3,%2,%1
1741    #"
1742   [(set_attr "type" "compare")
1743    (set_attr "length" "4,8")])
1744
1745 (define_insn ""
1746   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1747         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1748                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1749                     (const_int 0)))
1750    (clobber (match_scratch:P 3 "=r,r"))]
1751   "TARGET_POWERPC"
1752   "@
1753    subf. %3,%2,%1
1754    #"
1755   [(set_attr "type" "fast_compare")
1756    (set_attr "length" "4,8")])
1757
1758 (define_split
1759   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1760         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1761                              (match_operand:P 2 "gpc_reg_operand" ""))
1762                     (const_int 0)))
1763    (clobber (match_scratch:P 3 ""))]
1764   "reload_completed"
1765   [(set (match_dup 3)
1766         (minus:P (match_dup 1)
1767                   (match_dup 2)))
1768    (set (match_dup 0)
1769         (compare:CC (match_dup 3)
1770                     (const_int 0)))]
1771   "")
1772
1773 (define_insn ""
1774   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1775         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1776                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1777                     (const_int 0)))
1778    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1779         (minus:SI (match_dup 1) (match_dup 2)))]
1780   "! TARGET_POWERPC"
1781   "@
1782    {sf.|subfc.} %0,%2,%1
1783    #"
1784   [(set_attr "type" "compare")
1785    (set_attr "length" "4,8")])
1786
1787 (define_insn ""
1788   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1789         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1790                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1791                     (const_int 0)))
1792    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1793         (minus:P (match_dup 1)
1794                   (match_dup 2)))]
1795   "TARGET_POWERPC"
1796   "@
1797    subf. %0,%2,%1
1798    #"
1799   [(set_attr "type" "fast_compare")
1800    (set_attr "length" "4,8")])
1801
1802 (define_split
1803   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1804         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1805                              (match_operand:P 2 "gpc_reg_operand" ""))
1806                     (const_int 0)))
1807    (set (match_operand:P 0 "gpc_reg_operand" "")
1808         (minus:P (match_dup 1)
1809                   (match_dup 2)))]
1810   "reload_completed"
1811   [(set (match_dup 0)
1812         (minus:P (match_dup 1)
1813                   (match_dup 2)))
1814    (set (match_dup 3)
1815         (compare:CC (match_dup 0)
1816                     (const_int 0)))]
1817   "")
1818
1819 (define_expand "sub<mode>3"
1820   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1821         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1822                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1823   ""
1824   "
1825 {
1826   if (GET_CODE (operands[2]) == CONST_INT)
1827     {
1828       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1829                                  negate_rtx (<MODE>mode, operands[2])));
1830       DONE;
1831     }
1832 }")
1833
1834 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1835 ;; instruction and some auxiliary computations.  Then we just have a single
1836 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1837 ;; combine.
1838
1839 (define_expand "sminsi3"
1840   [(set (match_dup 3)
1841         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1842                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1843                          (const_int 0)
1844                          (minus:SI (match_dup 2) (match_dup 1))))
1845    (set (match_operand:SI 0 "gpc_reg_operand" "")
1846         (minus:SI (match_dup 2) (match_dup 3)))]
1847   "TARGET_POWER || TARGET_ISEL"
1848   "
1849 {
1850   if (TARGET_ISEL)
1851     {
1852       operands[2] = force_reg (SImode, operands[2]);
1853       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1854       DONE;
1855     }
1856
1857   operands[3] = gen_reg_rtx (SImode);
1858 }")
1859
1860 (define_split
1861   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1862         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1863                  (match_operand:SI 2 "reg_or_short_operand" "")))
1864    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1865   "TARGET_POWER"
1866   [(set (match_dup 3)
1867         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1868                          (const_int 0)
1869                          (minus:SI (match_dup 2) (match_dup 1))))
1870    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1871   "")
1872
1873 (define_expand "smaxsi3"
1874   [(set (match_dup 3)
1875         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1876                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1877                          (const_int 0)
1878                          (minus:SI (match_dup 2) (match_dup 1))))
1879    (set (match_operand:SI 0 "gpc_reg_operand" "")
1880         (plus:SI (match_dup 3) (match_dup 1)))]
1881   "TARGET_POWER || TARGET_ISEL"
1882   "
1883 {
1884   if (TARGET_ISEL)
1885     {
1886       operands[2] = force_reg (SImode, operands[2]);
1887       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1888       DONE;
1889     }
1890   operands[3] = gen_reg_rtx (SImode);
1891 }")
1892
1893 (define_split
1894   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1895         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1896                  (match_operand:SI 2 "reg_or_short_operand" "")))
1897    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1898   "TARGET_POWER"
1899   [(set (match_dup 3)
1900         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1901                          (const_int 0)
1902                          (minus:SI (match_dup 2) (match_dup 1))))
1903    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1904   "")
1905
1906 (define_expand "uminsi3"
1907   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1908                               (match_dup 5)))
1909    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1910                               (match_dup 5)))
1911    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1912                                        (const_int 0)
1913                                        (minus:SI (match_dup 4) (match_dup 3))))
1914    (set (match_operand:SI 0 "gpc_reg_operand" "")
1915         (minus:SI (match_dup 2) (match_dup 3)))]
1916   "TARGET_POWER || TARGET_ISEL"
1917   "
1918 {
1919   if (TARGET_ISEL)
1920     {
1921       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1922       DONE;
1923     }
1924   operands[3] = gen_reg_rtx (SImode);
1925   operands[4] = gen_reg_rtx (SImode);
1926   operands[5] = GEN_INT (-2147483647 - 1);
1927 }")
1928
1929 (define_expand "umaxsi3"
1930   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1931                               (match_dup 5)))
1932    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1933                               (match_dup 5)))
1934    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1935                                        (const_int 0)
1936                                        (minus:SI (match_dup 4) (match_dup 3))))
1937    (set (match_operand:SI 0 "gpc_reg_operand" "")
1938         (plus:SI (match_dup 3) (match_dup 1)))]
1939   "TARGET_POWER || TARGET_ISEL"
1940   "
1941 {
1942   if (TARGET_ISEL)
1943     {
1944       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1945       DONE;
1946     }
1947   operands[3] = gen_reg_rtx (SImode);
1948   operands[4] = gen_reg_rtx (SImode);
1949   operands[5] = GEN_INT (-2147483647 - 1);
1950 }")
1951
1952 (define_insn ""
1953   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1954         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1955                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1956                          (const_int 0)
1957                          (minus:SI (match_dup 2) (match_dup 1))))]
1958   "TARGET_POWER"
1959   "doz%I2 %0,%1,%2")
1960
1961 (define_insn ""
1962   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1963         (compare:CC
1964          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1965                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1966                           (const_int 0)
1967                           (minus:SI (match_dup 2) (match_dup 1)))
1968          (const_int 0)))
1969    (clobber (match_scratch:SI 3 "=r,r"))]
1970   "TARGET_POWER"
1971   "@
1972    doz%I2. %3,%1,%2
1973    #"
1974   [(set_attr "type" "delayed_compare")
1975    (set_attr "length" "4,8")])
1976
1977 (define_split
1978   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1979         (compare:CC
1980          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1981                               (match_operand:SI 2 "reg_or_short_operand" ""))
1982                           (const_int 0)
1983                           (minus:SI (match_dup 2) (match_dup 1)))
1984          (const_int 0)))
1985    (clobber (match_scratch:SI 3 ""))]
1986   "TARGET_POWER && reload_completed"
1987   [(set (match_dup 3)
1988         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1989                           (const_int 0)
1990                           (minus:SI (match_dup 2) (match_dup 1))))
1991    (set (match_dup 0)
1992         (compare:CC (match_dup 3)
1993                     (const_int 0)))]
1994   "")
1995
1996 (define_insn ""
1997   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1998         (compare:CC
1999          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
2000                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
2001                           (const_int 0)
2002                           (minus:SI (match_dup 2) (match_dup 1)))
2003          (const_int 0)))
2004    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2005         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2006                          (const_int 0)
2007                          (minus:SI (match_dup 2) (match_dup 1))))]
2008   "TARGET_POWER"
2009   "@
2010    doz%I2. %0,%1,%2
2011    #"
2012   [(set_attr "type" "delayed_compare")
2013    (set_attr "length" "4,8")])
2014
2015 (define_split
2016   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2017         (compare:CC
2018          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
2019                               (match_operand:SI 2 "reg_or_short_operand" ""))
2020                           (const_int 0)
2021                           (minus:SI (match_dup 2) (match_dup 1)))
2022          (const_int 0)))
2023    (set (match_operand:SI 0 "gpc_reg_operand" "")
2024         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2025                          (const_int 0)
2026                          (minus:SI (match_dup 2) (match_dup 1))))]
2027   "TARGET_POWER && reload_completed"
2028   [(set (match_dup 0)
2029         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2030                          (const_int 0)
2031                          (minus:SI (match_dup 2) (match_dup 1))))
2032    (set (match_dup 3)
2033         (compare:CC (match_dup 0)
2034                     (const_int 0)))]
2035   "")
2036
2037 ;; We don't need abs with condition code because such comparisons should
2038 ;; never be done.
2039 (define_expand "abssi2"
2040   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2041         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2042   ""
2043   "
2044 {
2045   if (TARGET_ISEL)
2046     {
2047       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
2048       DONE;
2049     }
2050   else if (! TARGET_POWER)
2051     {
2052       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
2053       DONE;
2054     }
2055 }")
2056
2057 (define_insn "*abssi2_power"
2058   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2059         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2060   "TARGET_POWER"
2061   "abs %0,%1")
2062
2063 (define_insn_and_split "abssi2_isel"
2064   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2065         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
2066    (clobber (match_scratch:SI 2 "=&b"))
2067    (clobber (match_scratch:CC 3 "=y"))]
2068   "TARGET_ISEL"
2069   "#"
2070   "&& reload_completed"
2071   [(set (match_dup 2) (neg:SI (match_dup 1)))
2072    (set (match_dup 3)
2073         (compare:CC (match_dup 1)
2074                     (const_int 0)))
2075    (set (match_dup 0)
2076         (if_then_else:SI (ge (match_dup 3)
2077                              (const_int 0))
2078                          (match_dup 1)
2079                          (match_dup 2)))]
2080   "")
2081
2082 (define_insn_and_split "abssi2_nopower"
2083   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2084         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
2085    (clobber (match_scratch:SI 2 "=&r,&r"))]
2086   "! TARGET_POWER && ! TARGET_ISEL"
2087   "#"
2088   "&& reload_completed"
2089   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2090    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2091    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
2092   "")
2093
2094 (define_insn "*nabs_power"
2095   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2096         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
2097   "TARGET_POWER"
2098   "nabs %0,%1")
2099
2100 (define_insn_and_split "*nabs_nopower"
2101   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2102         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
2103    (clobber (match_scratch:SI 2 "=&r,&r"))]
2104   "! TARGET_POWER"
2105   "#"
2106   "&& reload_completed"
2107   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2108    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2109    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
2110   "")
2111
2112 (define_expand "neg<mode>2"
2113   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2114         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2115   ""
2116   "")
2117
2118 (define_insn "*neg<mode>2_internal"
2119   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2120         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2121   ""
2122   "neg %0,%1")
2123
2124 (define_insn ""
2125   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2126         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2127                     (const_int 0)))
2128    (clobber (match_scratch:P 2 "=r,r"))]
2129   ""
2130   "@
2131    neg. %2,%1
2132    #"
2133   [(set_attr "type" "fast_compare")
2134    (set_attr "length" "4,8")])
2135
2136 (define_split
2137   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2138         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2139                     (const_int 0)))
2140    (clobber (match_scratch:P 2 ""))]
2141   "reload_completed"
2142   [(set (match_dup 2)
2143         (neg:P (match_dup 1)))
2144    (set (match_dup 0)
2145         (compare:CC (match_dup 2)
2146                     (const_int 0)))]
2147   "")
2148
2149 (define_insn ""
2150   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2151         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2152                     (const_int 0)))
2153    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2154         (neg:P (match_dup 1)))]
2155   ""
2156   "@
2157    neg. %0,%1
2158    #"
2159   [(set_attr "type" "fast_compare")
2160    (set_attr "length" "4,8")])
2161
2162 (define_split
2163   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2164         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2165                     (const_int 0)))
2166    (set (match_operand:P 0 "gpc_reg_operand" "")
2167         (neg:P (match_dup 1)))]
2168   "reload_completed"
2169   [(set (match_dup 0)
2170         (neg:P (match_dup 1)))
2171    (set (match_dup 2)
2172         (compare:CC (match_dup 0)
2173                     (const_int 0)))]
2174   "")
2175
2176 (define_insn "clz<mode>2"
2177   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2178         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2179   ""
2180   "{cntlz|cntlz<wd>} %0,%1"
2181   [(set_attr "type" "cntlz")])
2182
2183 (define_expand "ctz<mode>2"
2184   [(set (match_dup 2)
2185         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2186    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2187                                           (match_dup 2)))
2188               (clobber (scratch:CC))])
2189    (set (match_dup 4) (clz:GPR (match_dup 3)))
2190    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2191         (minus:GPR (match_dup 5) (match_dup 4)))]
2192   ""
2193   {
2194      operands[2] = gen_reg_rtx (<MODE>mode);
2195      operands[3] = gen_reg_rtx (<MODE>mode);
2196      operands[4] = gen_reg_rtx (<MODE>mode);
2197      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2198   })
2199
2200 (define_expand "ffs<mode>2"
2201   [(set (match_dup 2)
2202         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2203    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2204                                           (match_dup 2)))
2205               (clobber (scratch:CC))])
2206    (set (match_dup 4) (clz:GPR (match_dup 3)))
2207    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2208         (minus:GPR (match_dup 5) (match_dup 4)))]
2209   ""
2210   {
2211      operands[2] = gen_reg_rtx (<MODE>mode);
2212      operands[3] = gen_reg_rtx (<MODE>mode);
2213      operands[4] = gen_reg_rtx (<MODE>mode);
2214      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2215   })
2216
2217 (define_insn "popcntb<mode>2"
2218   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2219         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2220                      UNSPEC_POPCNTB))]
2221   "TARGET_POPCNTB"
2222   "popcntb %0,%1")
2223
2224 (define_expand "popcount<mode>2"
2225   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2226         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2227   "TARGET_POPCNTB"
2228   {
2229     rs6000_emit_popcount (operands[0], operands[1]);
2230     DONE;
2231   })
2232
2233 (define_expand "parity<mode>2"
2234   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2235         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2236   "TARGET_POPCNTB"
2237   {
2238     rs6000_emit_parity (operands[0], operands[1]);
2239     DONE;
2240   })
2241
2242 (define_insn "bswapsi2"
2243   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2244         (bswap:SI (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2245   ""
2246   "@
2247    {lbrx|lwbrx} %0,%y1
2248    {stbrx|stwbrx} %1,%y0
2249    #"
2250   [(set_attr "length" "4,4,12")])
2251
2252 (define_split
2253   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2254         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2255   "reload_completed"
2256   [(set (match_dup 0)
2257         (rotate:SI (match_dup 1) (const_int 8)))
2258    (set (zero_extract:SI (match_dup 0)
2259                          (const_int 8)
2260                          (const_int 0))
2261         (match_dup 1))
2262    (set (zero_extract:SI (match_dup 0)
2263                          (const_int 8)
2264                          (const_int 16))
2265         (rotate:SI (match_dup 1)
2266                    (const_int 16)))]
2267   "")
2268
2269 (define_expand "mulsi3"
2270   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2271    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2272    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2273   ""
2274   "
2275 {
2276   if (TARGET_POWER)
2277     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2278   else
2279     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2280   DONE;
2281 }")
2282
2283 (define_insn "mulsi3_mq"
2284   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2285         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2286                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2287    (clobber (match_scratch:SI 3 "=q,q"))]
2288   "TARGET_POWER"
2289   "@
2290    {muls|mullw} %0,%1,%2
2291    {muli|mulli} %0,%1,%2"
2292    [(set (attr "type")
2293       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2294                 (const_string "imul3")
2295              (match_operand:SI 2 "short_cint_operand" "")
2296                 (const_string "imul2")]
2297         (const_string "imul")))])
2298
2299 (define_insn "mulsi3_no_mq"
2300   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2301         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2302                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2303   "! TARGET_POWER"
2304   "@
2305    {muls|mullw} %0,%1,%2
2306    {muli|mulli} %0,%1,%2"
2307    [(set (attr "type")
2308       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2309                 (const_string "imul3")
2310              (match_operand:SI 2 "short_cint_operand" "")
2311                 (const_string "imul2")]
2312         (const_string "imul")))])
2313
2314 (define_insn "*mulsi3_mq_internal1"
2315   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2316         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2317                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2318                     (const_int 0)))
2319    (clobber (match_scratch:SI 3 "=r,r"))
2320    (clobber (match_scratch:SI 4 "=q,q"))]
2321   "TARGET_POWER"
2322   "@
2323    {muls.|mullw.} %3,%1,%2
2324    #"
2325   [(set_attr "type" "imul_compare")
2326    (set_attr "length" "4,8")])
2327
2328 (define_split
2329   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2330         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2331                              (match_operand:SI 2 "gpc_reg_operand" ""))
2332                     (const_int 0)))
2333    (clobber (match_scratch:SI 3 ""))
2334    (clobber (match_scratch:SI 4 ""))]
2335   "TARGET_POWER && reload_completed"
2336   [(parallel [(set (match_dup 3)
2337         (mult:SI (match_dup 1) (match_dup 2)))
2338    (clobber (match_dup 4))])
2339    (set (match_dup 0)
2340         (compare:CC (match_dup 3)
2341                     (const_int 0)))]
2342   "")
2343
2344 (define_insn "*mulsi3_no_mq_internal1"
2345   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2346         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2347                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2348                     (const_int 0)))
2349    (clobber (match_scratch:SI 3 "=r,r"))]
2350   "! TARGET_POWER"
2351   "@
2352    {muls.|mullw.} %3,%1,%2
2353    #"
2354   [(set_attr "type" "imul_compare")
2355    (set_attr "length" "4,8")])
2356
2357 (define_split
2358   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2359         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2360                              (match_operand:SI 2 "gpc_reg_operand" ""))
2361                     (const_int 0)))
2362    (clobber (match_scratch:SI 3 ""))]
2363   "! TARGET_POWER && reload_completed"
2364   [(set (match_dup 3)
2365         (mult:SI (match_dup 1) (match_dup 2)))
2366    (set (match_dup 0)
2367         (compare:CC (match_dup 3)
2368                     (const_int 0)))]
2369   "")
2370
2371 (define_insn "*mulsi3_mq_internal2"
2372   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2373         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2374                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2375                     (const_int 0)))
2376    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2377         (mult:SI (match_dup 1) (match_dup 2)))
2378    (clobber (match_scratch:SI 4 "=q,q"))]
2379   "TARGET_POWER"
2380   "@
2381    {muls.|mullw.} %0,%1,%2
2382    #"
2383   [(set_attr "type" "imul_compare")
2384    (set_attr "length" "4,8")])
2385
2386 (define_split
2387   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2388         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2389                              (match_operand:SI 2 "gpc_reg_operand" ""))
2390                     (const_int 0)))
2391    (set (match_operand:SI 0 "gpc_reg_operand" "")
2392         (mult:SI (match_dup 1) (match_dup 2)))
2393    (clobber (match_scratch:SI 4 ""))]
2394   "TARGET_POWER && reload_completed"
2395   [(parallel [(set (match_dup 0)
2396         (mult:SI (match_dup 1) (match_dup 2)))
2397    (clobber (match_dup 4))])
2398    (set (match_dup 3)
2399         (compare:CC (match_dup 0)
2400                     (const_int 0)))]
2401   "")
2402
2403 (define_insn "*mulsi3_no_mq_internal2"
2404   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2405         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2406                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2407                     (const_int 0)))
2408    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2409         (mult:SI (match_dup 1) (match_dup 2)))]
2410   "! TARGET_POWER"
2411   "@
2412    {muls.|mullw.} %0,%1,%2
2413    #"
2414   [(set_attr "type" "imul_compare")
2415    (set_attr "length" "4,8")])
2416
2417 (define_split
2418   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2419         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2420                              (match_operand:SI 2 "gpc_reg_operand" ""))
2421                     (const_int 0)))
2422    (set (match_operand:SI 0 "gpc_reg_operand" "")
2423         (mult:SI (match_dup 1) (match_dup 2)))]
2424   "! TARGET_POWER && reload_completed"
2425   [(set (match_dup 0)
2426         (mult:SI (match_dup 1) (match_dup 2)))
2427    (set (match_dup 3)
2428         (compare:CC (match_dup 0)
2429                     (const_int 0)))]
2430   "")
2431
2432 ;; Operand 1 is divided by operand 2; quotient goes to operand
2433 ;; 0 and remainder to operand 3.
2434 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2435
2436 (define_expand "divmodsi4"
2437   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2438                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2439                            (match_operand:SI 2 "gpc_reg_operand" "")))
2440               (set (match_operand:SI 3 "register_operand" "")
2441                    (mod:SI (match_dup 1) (match_dup 2)))])]
2442   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2443   "
2444 {
2445   if (! TARGET_POWER && ! TARGET_POWERPC)
2446     {
2447       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2448       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2449       emit_insn (gen_divss_call ());
2450       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2451       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2452       DONE;
2453     }
2454 }")
2455
2456 (define_insn "*divmodsi4_internal"
2457   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2458         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2459                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2460    (set (match_operand:SI 3 "register_operand" "=q")
2461         (mod:SI (match_dup 1) (match_dup 2)))]
2462   "TARGET_POWER"
2463   "divs %0,%1,%2"
2464   [(set_attr "type" "idiv")])
2465
2466 (define_expand "udiv<mode>3"
2467   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2468         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2469                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
2470   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2471   "
2472 {
2473   if (! TARGET_POWER && ! TARGET_POWERPC)
2474     {
2475       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2476       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2477       emit_insn (gen_quous_call ());
2478       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2479       DONE;
2480     }
2481   else if (TARGET_POWER)
2482     {
2483       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2484       DONE;
2485     }
2486 }")
2487
2488 (define_insn "udivsi3_mq"
2489   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2490         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2491                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2492    (clobber (match_scratch:SI 3 "=q"))]
2493   "TARGET_POWERPC && TARGET_POWER"
2494   "divwu %0,%1,%2"
2495   [(set_attr "type" "idiv")])
2496
2497 (define_insn "*udivsi3_no_mq"
2498   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2499         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2500                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2501   "TARGET_POWERPC && ! TARGET_POWER"
2502   "div<wd>u %0,%1,%2"
2503    [(set (attr "type")
2504       (cond [(match_operand:SI 0 "" "")
2505                 (const_string "idiv")]
2506         (const_string "ldiv")))])
2507
2508
2509 ;; For powers of two we can do srai/aze for divide and then adjust for
2510 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2511 ;; used; for PowerPC, force operands into register and do a normal divide;
2512 ;; for AIX common-mode, use quoss call on register operands.
2513 (define_expand "div<mode>3"
2514   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2515         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2516                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2517   ""
2518   "
2519 {
2520   if (GET_CODE (operands[2]) == CONST_INT
2521       && INTVAL (operands[2]) > 0
2522       && exact_log2 (INTVAL (operands[2])) >= 0)
2523     ;
2524   else if (TARGET_POWERPC)
2525     {
2526       operands[2] = force_reg (<MODE>mode, operands[2]);
2527       if (TARGET_POWER)
2528         {
2529           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2530           DONE;
2531         }
2532     }
2533   else if (TARGET_POWER)
2534     FAIL;
2535   else
2536     {
2537       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2538       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2539       emit_insn (gen_quoss_call ());
2540       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2541       DONE;
2542     }
2543 }")
2544
2545 (define_insn "divsi3_mq"
2546   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2547         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2548                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2549    (clobber (match_scratch:SI 3 "=q"))]
2550   "TARGET_POWERPC && TARGET_POWER"
2551   "divw %0,%1,%2"
2552   [(set_attr "type" "idiv")])
2553
2554 (define_insn "*div<mode>3_no_mq"
2555   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2556         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2557                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2558   "TARGET_POWERPC && ! TARGET_POWER"
2559   "div<wd> %0,%1,%2"
2560   [(set (attr "type")
2561      (cond [(match_operand:SI 0 "" "")
2562                 (const_string "idiv")]
2563         (const_string "ldiv")))])
2564
2565 (define_expand "mod<mode>3"
2566   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2567    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2568    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2569   ""
2570   "
2571 {
2572   int i;
2573   rtx temp1;
2574   rtx temp2;
2575
2576   if (GET_CODE (operands[2]) != CONST_INT
2577       || INTVAL (operands[2]) <= 0
2578       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2579     FAIL;
2580
2581   temp1 = gen_reg_rtx (<MODE>mode);
2582   temp2 = gen_reg_rtx (<MODE>mode);
2583
2584   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2585   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2586   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2587   DONE;
2588 }")
2589
2590 (define_insn ""
2591   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2592         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2593                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2594   ""
2595   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
2596   [(set_attr "type" "two")
2597    (set_attr "length" "8")])
2598
2599 (define_insn ""
2600   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2601         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2602                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2603                     (const_int 0)))
2604    (clobber (match_scratch:P 3 "=r,r"))]
2605   ""
2606   "@
2607    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
2608    #"
2609   [(set_attr "type" "compare")
2610    (set_attr "length" "8,12")
2611    (set_attr "cell_micro" "not")])
2612
2613 (define_split
2614   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2615         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2616                              (match_operand:GPR 2 "exact_log2_cint_operand"
2617                               ""))
2618                     (const_int 0)))
2619    (clobber (match_scratch:GPR 3 ""))]
2620   "reload_completed"
2621   [(set (match_dup 3)
2622         (div:<MODE> (match_dup 1) (match_dup 2)))
2623    (set (match_dup 0)
2624         (compare:CC (match_dup 3)
2625                     (const_int 0)))]
2626   "")
2627
2628 (define_insn ""
2629   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2630         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2631                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2632                     (const_int 0)))
2633    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2634         (div:P (match_dup 1) (match_dup 2)))]
2635   ""
2636   "@
2637    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
2638    #"
2639   [(set_attr "type" "compare")
2640    (set_attr "length" "8,12")
2641    (set_attr "cell_micro" "not")])
2642
2643 (define_split
2644   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2645         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2646                              (match_operand:GPR 2 "exact_log2_cint_operand"
2647                               ""))
2648                     (const_int 0)))
2649    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2650         (div:GPR (match_dup 1) (match_dup 2)))]
2651   "reload_completed"
2652   [(set (match_dup 0)
2653         (div:<MODE> (match_dup 1) (match_dup 2)))
2654    (set (match_dup 3)
2655         (compare:CC (match_dup 0)
2656                     (const_int 0)))]
2657   "")
2658
2659 (define_insn ""
2660   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2661         (udiv:SI
2662          (plus:DI (ashift:DI
2663                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2664                    (const_int 32))
2665                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2666          (match_operand:SI 3 "gpc_reg_operand" "r")))
2667    (set (match_operand:SI 2 "register_operand" "=*q")
2668         (umod:SI
2669          (plus:DI (ashift:DI
2670                    (zero_extend:DI (match_dup 1)) (const_int 32))
2671                   (zero_extend:DI (match_dup 4)))
2672          (match_dup 3)))]
2673   "TARGET_POWER"
2674   "div %0,%1,%3"
2675   [(set_attr "type" "idiv")])
2676
2677 ;; To do unsigned divide we handle the cases of the divisor looking like a
2678 ;; negative number.  If it is a constant that is less than 2**31, we don't
2679 ;; have to worry about the branches.  So make a few subroutines here.
2680 ;;
2681 ;; First comes the normal case.
2682 (define_expand "udivmodsi4_normal"
2683   [(set (match_dup 4) (const_int 0))
2684    (parallel [(set (match_operand:SI 0 "" "")
2685                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2686                                                 (const_int 32))
2687                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2688                             (match_operand:SI 2 "" "")))
2689               (set (match_operand:SI 3 "" "")
2690                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2691                                                 (const_int 32))
2692                                      (zero_extend:DI (match_dup 1)))
2693                             (match_dup 2)))])]
2694   "TARGET_POWER"
2695   "
2696 { operands[4] = gen_reg_rtx (SImode); }")
2697
2698 ;; This handles the branches.
2699 (define_expand "udivmodsi4_tests"
2700   [(set (match_operand:SI 0 "" "") (const_int 0))
2701    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2702    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2703    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2704                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2705    (set (match_dup 0) (const_int 1))
2706    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2707    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2708    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2709                            (label_ref (match_dup 4)) (pc)))]
2710   "TARGET_POWER"
2711   "
2712 { operands[5] = gen_reg_rtx (CCUNSmode);
2713   operands[6] = gen_reg_rtx (CCmode);
2714 }")
2715
2716 (define_expand "udivmodsi4"
2717   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2718                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2719                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2720               (set (match_operand:SI 3 "gpc_reg_operand" "")
2721                    (umod:SI (match_dup 1) (match_dup 2)))])]
2722   ""
2723   "
2724 {
2725   rtx label = 0;
2726
2727   if (! TARGET_POWER)
2728     {
2729       if (! TARGET_POWERPC)
2730         {
2731           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2732           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2733           emit_insn (gen_divus_call ());
2734           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2735           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2736           DONE;
2737         }
2738       else
2739         FAIL;
2740     }
2741
2742   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2743     {
2744       operands[2] = force_reg (SImode, operands[2]);
2745       label = gen_label_rtx ();
2746       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2747                                   operands[3], label));
2748     }
2749   else
2750     operands[2] = force_reg (SImode, operands[2]);
2751
2752   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2753                                operands[3]));
2754   if (label)
2755     emit_label (label);
2756
2757   DONE;
2758 }")
2759
2760 ;; AIX architecture-independent common-mode multiply (DImode),
2761 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2762 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2763 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2764 ;; assumed unused if generating common-mode, so ignore.
2765 (define_insn "mulh_call"
2766   [(set (reg:SI 3)
2767         (truncate:SI
2768          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2769                                (sign_extend:DI (reg:SI 4)))
2770                       (const_int 32))))
2771    (clobber (reg:SI LR_REGNO))]
2772   "! TARGET_POWER && ! TARGET_POWERPC"
2773   "bla __mulh"
2774   [(set_attr "type" "imul")])
2775
2776 (define_insn "mull_call"
2777   [(set (reg:DI 3)
2778         (mult:DI (sign_extend:DI (reg:SI 3))
2779                  (sign_extend:DI (reg:SI 4))))
2780    (clobber (reg:SI LR_REGNO))
2781    (clobber (reg:SI 0))]
2782   "! TARGET_POWER && ! TARGET_POWERPC"
2783   "bla __mull"
2784   [(set_attr "type" "imul")])
2785
2786 (define_insn "divss_call"
2787   [(set (reg:SI 3)
2788         (div:SI (reg:SI 3) (reg:SI 4)))
2789    (set (reg:SI 4)
2790         (mod:SI (reg:SI 3) (reg:SI 4)))
2791    (clobber (reg:SI LR_REGNO))
2792    (clobber (reg:SI 0))]
2793   "! TARGET_POWER && ! TARGET_POWERPC"
2794   "bla __divss"
2795   [(set_attr "type" "idiv")])
2796
2797 (define_insn "divus_call"
2798   [(set (reg:SI 3)
2799         (udiv:SI (reg:SI 3) (reg:SI 4)))
2800    (set (reg:SI 4)
2801         (umod:SI (reg:SI 3) (reg:SI 4)))
2802    (clobber (reg:SI LR_REGNO))
2803    (clobber (reg:SI 0))
2804    (clobber (match_scratch:CC 0 "=x"))
2805    (clobber (reg:CC CR1_REGNO))]
2806   "! TARGET_POWER && ! TARGET_POWERPC"
2807   "bla __divus"
2808   [(set_attr "type" "idiv")])
2809
2810 (define_insn "quoss_call"
2811   [(set (reg:SI 3)
2812         (div:SI (reg:SI 3) (reg:SI 4)))
2813    (clobber (reg:SI LR_REGNO))]
2814   "! TARGET_POWER && ! TARGET_POWERPC"
2815   "bla __quoss"
2816   [(set_attr "type" "idiv")])
2817
2818 (define_insn "quous_call"
2819   [(set (reg:SI 3)
2820         (udiv:SI (reg:SI 3) (reg:SI 4)))
2821    (clobber (reg:SI LR_REGNO))
2822    (clobber (reg:SI 0))
2823    (clobber (match_scratch:CC 0 "=x"))
2824    (clobber (reg:CC CR1_REGNO))]
2825   "! TARGET_POWER && ! TARGET_POWERPC"
2826   "bla __quous"
2827   [(set_attr "type" "idiv")])
2828 \f
2829 ;; Logical instructions
2830 ;; The logical instructions are mostly combined by using match_operator,
2831 ;; but the plain AND insns are somewhat different because there is no
2832 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2833 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2834
2835 (define_expand "andsi3"
2836   [(parallel
2837     [(set (match_operand:SI 0 "gpc_reg_operand" "")
2838           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2839                   (match_operand:SI 2 "and_operand" "")))
2840      (clobber (match_scratch:CC 3 ""))])]
2841   ""
2842   "")
2843
2844 (define_insn "andsi3_mc"
2845   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2846         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2847                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2848    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2849   "rs6000_gen_cell_microcode"
2850   "@
2851    and %0,%1,%2
2852    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2853    {andil.|andi.} %0,%1,%b2
2854    {andiu.|andis.} %0,%1,%u2"
2855   [(set_attr "type" "*,*,compare,compare")])
2856
2857 (define_insn "andsi3_nomc"
2858   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2859         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2860                 (match_operand:SI 2 "and_operand" "?r,T")))
2861    (clobber (match_scratch:CC 3 "=X,X"))]
2862   "!rs6000_gen_cell_microcode"
2863   "@
2864    and %0,%1,%2
2865    {rlinm|rlwinm} %0,%1,0,%m2,%M2")
2866
2867 (define_insn "andsi3_internal0_nomc"
2868   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2869         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2870                 (match_operand:SI 2 "and_operand" "?r,T")))]
2871   "!rs6000_gen_cell_microcode"
2872   "@
2873    and %0,%1,%2
2874    {rlinm|rlwinm} %0,%1,0,%m2,%M2")
2875
2876
2877 ;; Note to set cr's other than cr0 we do the and immediate and then
2878 ;; the test again -- this avoids a mfcr which on the higher end
2879 ;; machines causes an execution serialization
2880
2881 (define_insn "*andsi3_internal2_mc"
2882   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2883         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2884                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2885                     (const_int 0)))
2886    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2887    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2888   "TARGET_32BIT && rs6000_gen_cell_microcode"
2889   "@
2890    and. %3,%1,%2
2891    {andil.|andi.} %3,%1,%b2
2892    {andiu.|andis.} %3,%1,%u2
2893    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2894    #
2895    #
2896    #
2897    #"
2898   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2899    (set_attr "length" "4,4,4,4,8,8,8,8")])
2900
2901 (define_insn "*andsi3_internal3_mc"
2902   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2903         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2904                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2905                     (const_int 0)))
2906    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2907    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2908   "TARGET_64BIT && rs6000_gen_cell_microcode"
2909   "@
2910    #
2911    {andil.|andi.} %3,%1,%b2
2912    {andiu.|andis.} %3,%1,%u2
2913    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2914    #
2915    #
2916    #
2917    #"
2918   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2919    (set_attr "length" "8,4,4,4,8,8,8,8")])
2920
2921 (define_split
2922   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2923         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2924                              (match_operand:GPR 2 "and_operand" ""))
2925                     (const_int 0)))
2926    (clobber (match_scratch:GPR 3 ""))
2927    (clobber (match_scratch:CC 4 ""))]
2928   "reload_completed"
2929   [(parallel [(set (match_dup 3)
2930                    (and:<MODE> (match_dup 1)
2931                                (match_dup 2)))
2932               (clobber (match_dup 4))])
2933    (set (match_dup 0)
2934         (compare:CC (match_dup 3)
2935                     (const_int 0)))]
2936   "")
2937
2938 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2939 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2940
2941 (define_split
2942   [(set (match_operand:CC 0 "cc_reg_operand" "")
2943         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2944                             (match_operand:SI 2 "gpc_reg_operand" ""))
2945                     (const_int 0)))
2946    (clobber (match_scratch:SI 3 ""))
2947    (clobber (match_scratch:CC 4 ""))]
2948   "TARGET_POWERPC64 && reload_completed"
2949   [(parallel [(set (match_dup 3)
2950                    (and:SI (match_dup 1)
2951                            (match_dup 2)))
2952               (clobber (match_dup 4))])
2953    (set (match_dup 0)
2954         (compare:CC (match_dup 3)
2955                     (const_int 0)))]
2956   "")
2957
2958 (define_insn "*andsi3_internal4"
2959   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2960         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2961                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2962                     (const_int 0)))
2963    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2964         (and:SI (match_dup 1)
2965                 (match_dup 2)))
2966    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2967   "TARGET_32BIT && rs6000_gen_cell_microcode"
2968   "@
2969    and. %0,%1,%2
2970    {andil.|andi.} %0,%1,%b2
2971    {andiu.|andis.} %0,%1,%u2
2972    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2973    #
2974    #
2975    #
2976    #"
2977   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2978    (set_attr "length" "4,4,4,4,8,8,8,8")])
2979
2980 (define_insn "*andsi3_internal5_mc"
2981   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2982         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2983                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2984                     (const_int 0)))
2985    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2986         (and:SI (match_dup 1)
2987                 (match_dup 2)))
2988    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2989   "TARGET_64BIT && rs6000_gen_cell_microcode"
2990   "@
2991    #
2992    {andil.|andi.} %0,%1,%b2
2993    {andiu.|andis.} %0,%1,%u2
2994    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2995    #
2996    #
2997    #
2998    #"
2999   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
3000    (set_attr "length" "8,4,4,4,8,8,8,8")])
3001
3002 (define_insn "*andsi3_internal5_nomc"
3003   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y,??y,??y,?y")
3004         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
3005                             (match_operand:SI 2 "and_operand" "r,r,K,L,T"))
3006                     (const_int 0)))
3007    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
3008         (and:SI (match_dup 1)
3009                 (match_dup 2)))
3010    (clobber (match_scratch:CC 4 "=X,X,x,x,X"))]
3011   "TARGET_64BIT && !rs6000_gen_cell_microcode"
3012   "#"
3013   [(set_attr "type" "compare")
3014    (set_attr "length" "8,8,8,8,8")])
3015
3016 (define_split
3017   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3018         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3019                             (match_operand:SI 2 "and_operand" ""))
3020                     (const_int 0)))
3021    (set (match_operand:SI 0 "gpc_reg_operand" "")
3022         (and:SI (match_dup 1)
3023                 (match_dup 2)))
3024    (clobber (match_scratch:CC 4 ""))]
3025   "reload_completed"
3026   [(parallel [(set (match_dup 0)
3027                    (and:SI (match_dup 1)
3028                            (match_dup 2)))
3029               (clobber (match_dup 4))])
3030    (set (match_dup 3)
3031         (compare:CC (match_dup 0)
3032                     (const_int 0)))]
3033   "")
3034
3035 (define_split
3036   [(set (match_operand:CC 3 "cc_reg_operand" "")
3037         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3038                             (match_operand:SI 2 "gpc_reg_operand" ""))
3039                     (const_int 0)))
3040    (set (match_operand:SI 0 "gpc_reg_operand" "")
3041         (and:SI (match_dup 1)
3042                 (match_dup 2)))
3043    (clobber (match_scratch:CC 4 ""))]
3044   "TARGET_POWERPC64 && reload_completed"
3045   [(parallel [(set (match_dup 0)
3046                    (and:SI (match_dup 1)
3047                            (match_dup 2)))
3048               (clobber (match_dup 4))])
3049    (set (match_dup 3)
3050         (compare:CC (match_dup 0)
3051                     (const_int 0)))]
3052   "")
3053
3054 ;; Handle the PowerPC64 rlwinm corner case
3055
3056 (define_insn_and_split "*andsi3_internal6"
3057   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3058         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3059                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
3060   "TARGET_POWERPC64"
3061   "#"
3062   "TARGET_POWERPC64"
3063   [(set (match_dup 0)
3064         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
3065                 (match_dup 4)))
3066    (set (match_dup 0)
3067         (rotate:SI (match_dup 0) (match_dup 5)))]
3068   "
3069 {
3070   int mb = extract_MB (operands[2]);
3071   int me = extract_ME (operands[2]);
3072   operands[3] = GEN_INT (me + 1);
3073   operands[5] = GEN_INT (32 - (me + 1));
3074   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3075 }"
3076   [(set_attr "length" "8")])
3077
3078 (define_expand "iorsi3"
3079   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3080         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3081                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3082   ""
3083   "
3084 {
3085   if (GET_CODE (operands[2]) == CONST_INT
3086       && ! logical_operand (operands[2], SImode))
3087     {
3088       HOST_WIDE_INT value = INTVAL (operands[2]);
3089       rtx tmp = ((!can_create_pseudo_p ()
3090                   || rtx_equal_p (operands[0], operands[1]))
3091                  ? operands[0] : gen_reg_rtx (SImode));
3092
3093       emit_insn (gen_iorsi3 (tmp, operands[1],
3094                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3095       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3096       DONE;
3097     }
3098 }")
3099
3100 (define_expand "xorsi3"
3101   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3102         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3103                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3104   ""
3105   "
3106 {
3107   if (GET_CODE (operands[2]) == CONST_INT
3108       && ! logical_operand (operands[2], SImode))
3109     {
3110       HOST_WIDE_INT value = INTVAL (operands[2]);
3111       rtx tmp = ((!can_create_pseudo_p ()
3112                   || rtx_equal_p (operands[0], operands[1]))
3113                  ? operands[0] : gen_reg_rtx (SImode));
3114
3115       emit_insn (gen_xorsi3 (tmp, operands[1],
3116                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3117       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3118       DONE;
3119     }
3120 }")
3121
3122 (define_insn "*boolsi3_internal1"
3123   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3124         (match_operator:SI 3 "boolean_or_operator"
3125          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3126           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3127   ""
3128   "@
3129    %q3 %0,%1,%2
3130    {%q3il|%q3i} %0,%1,%b2
3131    {%q3iu|%q3is} %0,%1,%u2")
3132
3133 (define_insn "*boolsi3_internal2"
3134   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3135         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3136          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3137           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3138          (const_int 0)))
3139    (clobber (match_scratch:SI 3 "=r,r"))]
3140   "TARGET_32BIT"
3141   "@
3142    %q4. %3,%1,%2
3143    #"
3144   [(set_attr "type" "compare")
3145    (set_attr "length" "4,8")])
3146
3147 (define_split
3148   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3149         (compare:CC (match_operator:SI 4 "boolean_operator"
3150          [(match_operand:SI 1 "gpc_reg_operand" "")
3151           (match_operand:SI 2 "gpc_reg_operand" "")])
3152          (const_int 0)))
3153    (clobber (match_scratch:SI 3 ""))]
3154   "TARGET_32BIT && reload_completed"
3155   [(set (match_dup 3) (match_dup 4))
3156    (set (match_dup 0)
3157         (compare:CC (match_dup 3)
3158                     (const_int 0)))]
3159   "")
3160
3161 (define_insn "*boolsi3_internal3"
3162   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3163         (compare:CC (match_operator:SI 4 "boolean_operator"
3164          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3165           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3166          (const_int 0)))
3167    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3168         (match_dup 4))]
3169   "TARGET_32BIT"
3170   "@
3171    %q4. %0,%1,%2
3172    #"
3173   [(set_attr "type" "compare")
3174    (set_attr "length" "4,8")])
3175
3176 (define_split
3177   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3178         (compare:CC (match_operator:SI 4 "boolean_operator"
3179          [(match_operand:SI 1 "gpc_reg_operand" "")
3180           (match_operand:SI 2 "gpc_reg_operand" "")])
3181          (const_int 0)))
3182    (set (match_operand:SI 0 "gpc_reg_operand" "")
3183         (match_dup 4))]
3184   "TARGET_32BIT && reload_completed"
3185   [(set (match_dup 0) (match_dup 4))
3186    (set (match_dup 3)
3187         (compare:CC (match_dup 0)
3188                     (const_int 0)))]
3189   "")
3190
3191 ;; Split a logical operation that we can't do in one insn into two insns,
3192 ;; each of which does one 16-bit part.  This is used by combine.
3193
3194 (define_split
3195   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3196         (match_operator:SI 3 "boolean_or_operator"
3197          [(match_operand:SI 1 "gpc_reg_operand" "")
3198           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3199   ""
3200   [(set (match_dup 0) (match_dup 4))
3201    (set (match_dup 0) (match_dup 5))]
3202 "
3203 {
3204   rtx i;
3205   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3206   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3207                                 operands[1], i);
3208   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3209   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3210                                 operands[0], i);
3211 }")
3212
3213 (define_insn "*boolcsi3_internal1"
3214   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3215         (match_operator:SI 3 "boolean_operator"
3216          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3217           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3218   ""
3219   "%q3 %0,%2,%1")
3220
3221 (define_insn "*boolcsi3_internal2"
3222   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3223         (compare:CC (match_operator:SI 4 "boolean_operator"
3224          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3225           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3226          (const_int 0)))
3227    (clobber (match_scratch:SI 3 "=r,r"))]
3228   "TARGET_32BIT"
3229   "@
3230    %q4. %3,%2,%1
3231    #"
3232   [(set_attr "type" "compare")
3233    (set_attr "length" "4,8")])
3234
3235 (define_split
3236   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3237         (compare:CC (match_operator:SI 4 "boolean_operator"
3238          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3239           (match_operand:SI 2 "gpc_reg_operand" "")])
3240          (const_int 0)))
3241    (clobber (match_scratch:SI 3 ""))]
3242   "TARGET_32BIT && reload_completed"
3243   [(set (match_dup 3) (match_dup 4))
3244    (set (match_dup 0)
3245         (compare:CC (match_dup 3)
3246                     (const_int 0)))]
3247   "")
3248
3249 (define_insn "*boolcsi3_internal3"
3250   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3251         (compare:CC (match_operator:SI 4 "boolean_operator"
3252          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3253           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3254          (const_int 0)))
3255    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3256         (match_dup 4))]
3257   "TARGET_32BIT"
3258   "@
3259    %q4. %0,%2,%1
3260    #"
3261   [(set_attr "type" "compare")
3262    (set_attr "length" "4,8")])
3263
3264 (define_split
3265   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3266         (compare:CC (match_operator:SI 4 "boolean_operator"
3267          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3268           (match_operand:SI 2 "gpc_reg_operand" "")])
3269          (const_int 0)))
3270    (set (match_operand:SI 0 "gpc_reg_operand" "")
3271         (match_dup 4))]
3272   "TARGET_32BIT && reload_completed"
3273   [(set (match_dup 0) (match_dup 4))
3274    (set (match_dup 3)
3275         (compare:CC (match_dup 0)
3276                     (const_int 0)))]
3277   "")
3278