OSDN Git Service

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