OSDN Git Service

PR target/26481
[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 (include "constraints.md")
130
131 (include "darwin.md")
132
133 \f
134 ;; Mode macros
135
136 ; This mode macro allows :GPR to be used to indicate the allowable size
137 ; of whole values in GPRs.
138 (define_mode_macro GPR [SI (DI "TARGET_POWERPC64")])
139
140 ; Any supported integer mode.
141 (define_mode_macro INT [QI HI SI DI TI])
142
143 ; Any supported integer mode that fits in one register.
144 (define_mode_macro INT1 [QI HI SI (DI "TARGET_POWERPC64")])
145
146 ; extend modes for DImode
147 (define_mode_macro QHSI [QI HI SI])
148
149 ; SImode or DImode, even if DImode doesn't fit in GPRs.
150 (define_mode_macro SDI [SI DI])
151
152 ; The size of a pointer.  Also, the size of the value that a record-condition
153 ; (one with a '.') will compare.
154 (define_mode_macro P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
155
156 ; Any hardware-supported floating-point mode
157 (define_mode_macro FP [(SF "TARGET_HARD_FLOAT")
158   (DF "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)")
159   (TF "!TARGET_IEEEQUAD
160    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128")])
161
162 ; Various instructions that come in SI and DI forms.
163 ; A generic w/d attribute, for things like cmpw/cmpd.
164 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
165
166 ; DImode bits
167 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
168
169 \f
170 ;; Start with fixed-point load and store insns.  Here we put only the more
171 ;; complex forms.  Basic data transfer is done later.
172
173 (define_expand "zero_extend<mode>di2"
174   [(set (match_operand:DI 0 "gpc_reg_operand" "")
175         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
176   "TARGET_POWERPC64"
177   "")
178
179 (define_insn "*zero_extend<mode>di2_internal1"
180   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
181         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
182   "TARGET_POWERPC64"
183   "@
184    l<wd>z%U1%X1 %0,%1
185    rldicl %0,%1,0,<dbits>"
186   [(set_attr "type" "load,*")])
187
188 (define_insn "*zero_extend<mode>di2_internal2"
189   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
190         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
191                     (const_int 0)))
192    (clobber (match_scratch:DI 2 "=r,r"))]
193   "TARGET_64BIT"
194   "@
195    rldicl. %2,%1,0,<dbits>
196    #"
197   [(set_attr "type" "compare")
198    (set_attr "length" "4,8")])
199
200 (define_split
201   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
202         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
203                     (const_int 0)))
204    (clobber (match_scratch:DI 2 ""))]
205   "TARGET_POWERPC64 && reload_completed"
206   [(set (match_dup 2)
207         (zero_extend:DI (match_dup 1)))
208    (set (match_dup 0)
209         (compare:CC (match_dup 2)
210                     (const_int 0)))]
211   "")
212
213 (define_insn "*zero_extend<mode>di2_internal3"
214   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
215         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
216                     (const_int 0)))
217    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
218         (zero_extend:DI (match_dup 1)))]
219   "TARGET_64BIT"
220   "@
221    rldicl. %0,%1,0,<dbits>
222    #"
223   [(set_attr "type" "compare")
224    (set_attr "length" "4,8")])
225
226 (define_split
227   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
228         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
229                     (const_int 0)))
230    (set (match_operand:DI 0 "gpc_reg_operand" "")
231         (zero_extend:DI (match_dup 1)))]
232   "TARGET_POWERPC64 && reload_completed"
233   [(set (match_dup 0)
234         (zero_extend:DI (match_dup 1)))
235    (set (match_dup 2)
236         (compare:CC (match_dup 0)
237                     (const_int 0)))]
238   "")
239
240 (define_insn "extendqidi2"
241   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
242         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
243   "TARGET_POWERPC64"
244   "extsb %0,%1")
245
246 (define_insn ""
247   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
248         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
249                     (const_int 0)))
250    (clobber (match_scratch:DI 2 "=r,r"))]
251   "TARGET_64BIT"
252   "@
253    extsb. %2,%1
254    #"
255   [(set_attr "type" "compare")
256    (set_attr "length" "4,8")])
257
258 (define_split
259   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
260         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
261                     (const_int 0)))
262    (clobber (match_scratch:DI 2 ""))]
263   "TARGET_POWERPC64 && reload_completed"
264   [(set (match_dup 2)
265         (sign_extend:DI (match_dup 1)))
266    (set (match_dup 0)
267         (compare:CC (match_dup 2)
268                     (const_int 0)))]
269   "")
270
271 (define_insn ""
272   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
273         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
274                     (const_int 0)))
275    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
276         (sign_extend:DI (match_dup 1)))]
277   "TARGET_64BIT"
278   "@
279    extsb. %0,%1
280    #"
281   [(set_attr "type" "compare")
282    (set_attr "length" "4,8")])
283
284 (define_split
285   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
286         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
287                     (const_int 0)))
288    (set (match_operand:DI 0 "gpc_reg_operand" "")
289         (sign_extend:DI (match_dup 1)))]
290   "TARGET_POWERPC64 && reload_completed"
291   [(set (match_dup 0)
292         (sign_extend:DI (match_dup 1)))
293    (set (match_dup 2)
294         (compare:CC (match_dup 0)
295                     (const_int 0)))]
296   "")
297
298 (define_expand "extendhidi2"
299   [(set (match_operand:DI 0 "gpc_reg_operand" "")
300         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
301   "TARGET_POWERPC64"
302   "")
303
304 (define_insn ""
305   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
306         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
307   "TARGET_POWERPC64"
308   "@
309    lha%U1%X1 %0,%1
310    extsh %0,%1"
311   [(set_attr "type" "load_ext,*")])
312
313 (define_insn ""
314   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
315         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
316                     (const_int 0)))
317    (clobber (match_scratch:DI 2 "=r,r"))]
318   "TARGET_64BIT"
319   "@
320    extsh. %2,%1
321    #"
322   [(set_attr "type" "compare")
323    (set_attr "length" "4,8")])
324
325 (define_split
326   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
327         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
328                     (const_int 0)))
329    (clobber (match_scratch:DI 2 ""))]
330   "TARGET_POWERPC64 && reload_completed"
331   [(set (match_dup 2)
332         (sign_extend:DI (match_dup 1)))
333    (set (match_dup 0)
334         (compare:CC (match_dup 2)
335                     (const_int 0)))]
336   "")
337
338 (define_insn ""
339   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
340         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
341                     (const_int 0)))
342    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
343         (sign_extend:DI (match_dup 1)))]
344   "TARGET_64BIT"
345   "@
346    extsh. %0,%1
347    #"
348   [(set_attr "type" "compare")
349    (set_attr "length" "4,8")])
350
351 (define_split
352   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
353         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
354                     (const_int 0)))
355    (set (match_operand:DI 0 "gpc_reg_operand" "")
356         (sign_extend:DI (match_dup 1)))]
357   "TARGET_POWERPC64 && reload_completed"
358   [(set (match_dup 0)
359         (sign_extend:DI (match_dup 1)))
360    (set (match_dup 2)
361         (compare:CC (match_dup 0)
362                     (const_int 0)))]
363   "")
364
365 (define_expand "extendsidi2"
366   [(set (match_operand:DI 0 "gpc_reg_operand" "")
367         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
368   "TARGET_POWERPC64"
369   "")
370
371 (define_insn ""
372   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
373         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
374   "TARGET_POWERPC64"
375   "@
376    lwa%U1%X1 %0,%1
377    extsw %0,%1"
378   [(set_attr "type" "load_ext,*")])
379
380 (define_insn ""
381   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
382         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
383                     (const_int 0)))
384    (clobber (match_scratch:DI 2 "=r,r"))]
385   "TARGET_64BIT"
386   "@
387    extsw. %2,%1
388    #"
389   [(set_attr "type" "compare")
390    (set_attr "length" "4,8")])
391
392 (define_split
393   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
394         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
395                     (const_int 0)))
396    (clobber (match_scratch:DI 2 ""))]
397   "TARGET_POWERPC64 && reload_completed"
398   [(set (match_dup 2)
399         (sign_extend:DI (match_dup 1)))
400    (set (match_dup 0)
401         (compare:CC (match_dup 2)
402                     (const_int 0)))]
403   "")
404
405 (define_insn ""
406   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
407         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
408                     (const_int 0)))
409    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
410         (sign_extend:DI (match_dup 1)))]
411   "TARGET_64BIT"
412   "@
413    extsw. %0,%1
414    #"
415   [(set_attr "type" "compare")
416    (set_attr "length" "4,8")])
417
418 (define_split
419   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
420         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
421                     (const_int 0)))
422    (set (match_operand:DI 0 "gpc_reg_operand" "")
423         (sign_extend:DI (match_dup 1)))]
424   "TARGET_POWERPC64 && reload_completed"
425   [(set (match_dup 0)
426         (sign_extend:DI (match_dup 1)))
427    (set (match_dup 2)
428         (compare:CC (match_dup 0)
429                     (const_int 0)))]
430   "")
431
432 (define_expand "zero_extendqisi2"
433   [(set (match_operand:SI 0 "gpc_reg_operand" "")
434         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
435   ""
436   "")
437
438 (define_insn ""
439   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
440         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
441   ""
442   "@
443    lbz%U1%X1 %0,%1
444    {rlinm|rlwinm} %0,%1,0,0xff"
445   [(set_attr "type" "load,*")])
446
447 (define_insn ""
448   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
449         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
450                     (const_int 0)))
451    (clobber (match_scratch:SI 2 "=r,r"))]
452   ""
453   "@
454    {andil.|andi.} %2,%1,0xff
455    #"
456   [(set_attr "type" "compare")
457    (set_attr "length" "4,8")])
458
459 (define_split
460   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
461         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
462                     (const_int 0)))
463    (clobber (match_scratch:SI 2 ""))]
464   "reload_completed"
465   [(set (match_dup 2)
466         (zero_extend:SI (match_dup 1)))
467    (set (match_dup 0)
468         (compare:CC (match_dup 2)
469                     (const_int 0)))]
470   "")
471
472 (define_insn ""
473   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
474         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
475                     (const_int 0)))
476    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
477         (zero_extend:SI (match_dup 1)))]
478   ""
479   "@
480    {andil.|andi.} %0,%1,0xff
481    #"
482   [(set_attr "type" "compare")
483    (set_attr "length" "4,8")])
484
485 (define_split
486   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
487         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
488                     (const_int 0)))
489    (set (match_operand:SI 0 "gpc_reg_operand" "")
490         (zero_extend:SI (match_dup 1)))]
491   "reload_completed"
492   [(set (match_dup 0)
493         (zero_extend:SI (match_dup 1)))
494    (set (match_dup 2)
495         (compare:CC (match_dup 0)
496                     (const_int 0)))]
497   "")
498
499 (define_expand "extendqisi2"
500   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
501    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
502   ""
503   "
504 {
505   if (TARGET_POWERPC)
506     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
507   else if (TARGET_POWER)
508     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
509   else
510     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
511   DONE;
512 }")
513
514 (define_insn "extendqisi2_ppc"
515   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
516         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
517   "TARGET_POWERPC"
518   "extsb %0,%1")
519
520 (define_insn ""
521   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
522         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
523                     (const_int 0)))
524    (clobber (match_scratch:SI 2 "=r,r"))]
525   "TARGET_POWERPC"
526   "@
527    extsb. %2,%1
528    #"
529   [(set_attr "type" "compare")
530    (set_attr "length" "4,8")])
531
532 (define_split
533   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
534         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
535                     (const_int 0)))
536    (clobber (match_scratch:SI 2 ""))]
537   "TARGET_POWERPC && reload_completed"
538   [(set (match_dup 2)
539         (sign_extend:SI (match_dup 1)))
540    (set (match_dup 0)
541         (compare:CC (match_dup 2)
542                     (const_int 0)))]
543   "")
544
545 (define_insn ""
546   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
547         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
548                     (const_int 0)))
549    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
550         (sign_extend:SI (match_dup 1)))]
551   "TARGET_POWERPC"
552   "@
553    extsb. %0,%1
554    #"
555   [(set_attr "type" "compare")
556    (set_attr "length" "4,8")])
557
558 (define_split
559   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
560         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
561                     (const_int 0)))
562    (set (match_operand:SI 0 "gpc_reg_operand" "")
563         (sign_extend:SI (match_dup 1)))]
564   "TARGET_POWERPC && reload_completed"
565   [(set (match_dup 0)
566         (sign_extend:SI (match_dup 1)))
567    (set (match_dup 2)
568         (compare:CC (match_dup 0)
569                     (const_int 0)))]
570   "")
571
572 (define_expand "extendqisi2_power"
573   [(parallel [(set (match_dup 2)
574                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
575                               (const_int 24)))
576               (clobber (scratch:SI))])
577    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
578                    (ashiftrt:SI (match_dup 2)
579                                 (const_int 24)))
580               (clobber (scratch:SI))])]
581   "TARGET_POWER"
582   "
583 { operands[1] = gen_lowpart (SImode, operands[1]);
584   operands[2] = gen_reg_rtx (SImode); }")
585
586 (define_expand "extendqisi2_no_power"
587   [(set (match_dup 2)
588         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
589                    (const_int 24)))
590    (set (match_operand:SI 0 "gpc_reg_operand" "")
591         (ashiftrt:SI (match_dup 2)
592                      (const_int 24)))]
593   "! TARGET_POWER && ! TARGET_POWERPC"
594   "
595 { operands[1] = gen_lowpart (SImode, operands[1]);
596   operands[2] = gen_reg_rtx (SImode); }")
597
598 (define_expand "zero_extendqihi2"
599   [(set (match_operand:HI 0 "gpc_reg_operand" "")
600         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
601   ""
602   "")
603
604 (define_insn ""
605   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
606         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
607   ""
608   "@
609    lbz%U1%X1 %0,%1
610    {rlinm|rlwinm} %0,%1,0,0xff"
611   [(set_attr "type" "load,*")])
612
613 (define_insn ""
614   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
615         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
616                     (const_int 0)))
617    (clobber (match_scratch:HI 2 "=r,r"))]
618   ""
619   "@
620    {andil.|andi.} %2,%1,0xff
621    #"
622   [(set_attr "type" "compare")
623    (set_attr "length" "4,8")])
624
625 (define_split
626   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
627         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
628                     (const_int 0)))
629    (clobber (match_scratch:HI 2 ""))]
630   "reload_completed"
631   [(set (match_dup 2)
632         (zero_extend:HI (match_dup 1)))
633    (set (match_dup 0)
634         (compare:CC (match_dup 2)
635                     (const_int 0)))]
636   "")
637
638 (define_insn ""
639   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
640         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
641                     (const_int 0)))
642    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
643         (zero_extend:HI (match_dup 1)))]
644   ""
645   "@
646    {andil.|andi.} %0,%1,0xff
647    #"
648   [(set_attr "type" "compare")
649    (set_attr "length" "4,8")])
650
651 (define_split
652   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
653         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
654                     (const_int 0)))
655    (set (match_operand:HI 0 "gpc_reg_operand" "")
656         (zero_extend:HI (match_dup 1)))]
657   "reload_completed"
658   [(set (match_dup 0)
659         (zero_extend:HI (match_dup 1)))
660    (set (match_dup 2)
661         (compare:CC (match_dup 0)
662                     (const_int 0)))]
663   "")
664
665 (define_expand "extendqihi2"
666   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
667    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
668   ""
669   "
670 {
671   if (TARGET_POWERPC)
672     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
673   else if (TARGET_POWER)
674     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
675   else
676     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
677   DONE;
678 }")
679
680 (define_insn "extendqihi2_ppc"
681   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
682         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
683   "TARGET_POWERPC"
684   "extsb %0,%1")
685
686 (define_insn ""
687   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
688         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
689                     (const_int 0)))
690    (clobber (match_scratch:HI 2 "=r,r"))]
691   "TARGET_POWERPC"
692   "@
693    extsb. %2,%1
694    #"
695   [(set_attr "type" "compare")
696    (set_attr "length" "4,8")])
697
698 (define_split
699   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
700         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
701                     (const_int 0)))
702    (clobber (match_scratch:HI 2 ""))]
703   "TARGET_POWERPC && reload_completed"
704   [(set (match_dup 2)
705         (sign_extend:HI (match_dup 1)))
706    (set (match_dup 0)
707         (compare:CC (match_dup 2)
708                     (const_int 0)))]
709   "")
710
711 (define_insn ""
712   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
713         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
714                     (const_int 0)))
715    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
716         (sign_extend:HI (match_dup 1)))]
717   "TARGET_POWERPC"
718   "@
719    extsb. %0,%1
720    #"
721   [(set_attr "type" "compare")
722    (set_attr "length" "4,8")])
723
724 (define_split
725   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
726         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
727                     (const_int 0)))
728    (set (match_operand:HI 0 "gpc_reg_operand" "")
729         (sign_extend:HI (match_dup 1)))]
730   "TARGET_POWERPC && reload_completed"
731   [(set (match_dup 0)
732         (sign_extend:HI (match_dup 1)))
733    (set (match_dup 2)
734         (compare:CC (match_dup 0)
735                     (const_int 0)))]
736   "")
737
738 (define_expand "extendqihi2_power"
739   [(parallel [(set (match_dup 2)
740                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
741                               (const_int 24)))
742               (clobber (scratch:SI))])
743    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
744                    (ashiftrt:SI (match_dup 2)
745                                 (const_int 24)))
746               (clobber (scratch:SI))])]
747   "TARGET_POWER"
748   "
749 { operands[0] = gen_lowpart (SImode, operands[0]);
750   operands[1] = gen_lowpart (SImode, operands[1]);
751   operands[2] = gen_reg_rtx (SImode); }")
752
753 (define_expand "extendqihi2_no_power"
754   [(set (match_dup 2)
755         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
756                    (const_int 24)))
757    (set (match_operand:HI 0 "gpc_reg_operand" "")
758         (ashiftrt:SI (match_dup 2)
759                      (const_int 24)))]
760   "! TARGET_POWER && ! TARGET_POWERPC"
761   "
762 { operands[0] = gen_lowpart (SImode, operands[0]);
763   operands[1] = gen_lowpart (SImode, operands[1]);
764   operands[2] = gen_reg_rtx (SImode); }")
765
766 (define_expand "zero_extendhisi2"
767   [(set (match_operand:SI 0 "gpc_reg_operand" "")
768         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
769   ""
770   "")
771
772 (define_insn ""
773   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
774         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
775   ""
776   "@
777    lhz%U1%X1 %0,%1
778    {rlinm|rlwinm} %0,%1,0,0xffff"
779   [(set_attr "type" "load,*")])
780
781 (define_insn ""
782   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
783         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
784                     (const_int 0)))
785    (clobber (match_scratch:SI 2 "=r,r"))]
786   ""
787   "@
788    {andil.|andi.} %2,%1,0xffff
789    #"
790   [(set_attr "type" "compare")
791    (set_attr "length" "4,8")])
792
793 (define_split
794   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
795         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
796                     (const_int 0)))
797    (clobber (match_scratch:SI 2 ""))]
798   "reload_completed"
799   [(set (match_dup 2)
800         (zero_extend:SI (match_dup 1)))
801    (set (match_dup 0)
802         (compare:CC (match_dup 2)
803                     (const_int 0)))]
804   "")
805
806 (define_insn ""
807   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
808         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
809                     (const_int 0)))
810    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
811         (zero_extend:SI (match_dup 1)))]
812   ""
813   "@
814    {andil.|andi.} %0,%1,0xffff
815    #"
816   [(set_attr "type" "compare")
817    (set_attr "length" "4,8")])
818
819 (define_split
820   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
821         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
822                     (const_int 0)))
823    (set (match_operand:SI 0 "gpc_reg_operand" "")
824         (zero_extend:SI (match_dup 1)))]
825   "reload_completed"
826   [(set (match_dup 0)
827         (zero_extend:SI (match_dup 1)))
828    (set (match_dup 2)
829         (compare:CC (match_dup 0)
830                     (const_int 0)))]
831   "")
832
833 (define_expand "extendhisi2"
834   [(set (match_operand:SI 0 "gpc_reg_operand" "")
835         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
836   ""
837   "")
838
839 (define_insn ""
840   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
841         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
842   ""
843   "@
844    lha%U1%X1 %0,%1
845    {exts|extsh} %0,%1"
846   [(set_attr "type" "load_ext,*")])
847
848 (define_insn ""
849   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
850         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
851                     (const_int 0)))
852    (clobber (match_scratch:SI 2 "=r,r"))]
853   ""
854   "@
855    {exts.|extsh.} %2,%1
856    #"
857   [(set_attr "type" "compare")
858    (set_attr "length" "4,8")])
859
860 (define_split
861   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
862         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
863                     (const_int 0)))
864    (clobber (match_scratch:SI 2 ""))]
865   "reload_completed"
866   [(set (match_dup 2)
867         (sign_extend:SI (match_dup 1)))
868    (set (match_dup 0)
869         (compare:CC (match_dup 2)
870                     (const_int 0)))]
871   "")
872
873 (define_insn ""
874   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
875         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
876                     (const_int 0)))
877    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
878         (sign_extend:SI (match_dup 1)))]
879   ""
880   "@
881    {exts.|extsh.} %0,%1
882    #"
883   [(set_attr "type" "compare")
884    (set_attr "length" "4,8")])
885 \f
886 ;; IBM 405 and 440 half-word multiplication operations.
887
888 (define_insn "*macchwc"
889   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
890         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
891                                        (match_operand:SI 2 "gpc_reg_operand" "r")
892                                        (const_int 16))
893                                       (sign_extend:SI
894                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
895                              (match_operand:SI 4 "gpc_reg_operand" "0"))
896                     (const_int 0)))
897    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
898         (plus:SI (mult:SI (ashiftrt:SI
899                            (match_dup 2)
900                            (const_int 16))
901                           (sign_extend:SI
902                            (match_dup 1)))
903                  (match_dup 4)))]
904   "TARGET_MULHW"
905   "macchw. %0, %1, %2"
906   [(set_attr "type" "imul3")])
907
908 (define_insn "*macchw"
909   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
910         (plus:SI (mult:SI (ashiftrt:SI
911                            (match_operand:SI 2 "gpc_reg_operand" "r")
912                            (const_int 16))
913                           (sign_extend:SI
914                            (match_operand:HI 1 "gpc_reg_operand" "r")))
915                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
916   "TARGET_MULHW"
917   "macchw %0, %1, %2"
918   [(set_attr "type" "imul3")])
919
920 (define_insn "*macchwuc"
921   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
922         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
923                                        (match_operand:SI 2 "gpc_reg_operand" "r")
924                                        (const_int 16))
925                                       (zero_extend:SI
926                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
927                              (match_operand:SI 4 "gpc_reg_operand" "0"))
928                     (const_int 0)))
929    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
930         (plus:SI (mult:SI (lshiftrt:SI
931                            (match_dup 2)
932                            (const_int 16))
933                           (zero_extend:SI
934                            (match_dup 1)))
935                  (match_dup 4)))]
936   "TARGET_MULHW"
937   "macchwu. %0, %1, %2"
938   [(set_attr "type" "imul3")])
939
940 (define_insn "*macchwu"
941   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
942         (plus:SI (mult:SI (lshiftrt:SI
943                            (match_operand:SI 2 "gpc_reg_operand" "r")
944                            (const_int 16))
945                           (zero_extend:SI
946                            (match_operand:HI 1 "gpc_reg_operand" "r")))
947                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
948   "TARGET_MULHW"
949   "macchwu %0, %1, %2"
950   [(set_attr "type" "imul3")])
951
952 (define_insn "*machhwc"
953   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
954         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
955                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
956                                        (const_int 16))
957                                       (ashiftrt:SI
958                                        (match_operand:SI 2 "gpc_reg_operand" "r")
959                                        (const_int 16)))
960                              (match_operand:SI 4 "gpc_reg_operand" "0"))
961                     (const_int 0)))
962    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
963         (plus:SI (mult:SI (ashiftrt:SI
964                            (match_dup 1)
965                            (const_int 16))
966                           (ashiftrt:SI
967                            (match_dup 2)
968                            (const_int 16)))
969                  (match_dup 4)))]
970   "TARGET_MULHW"
971   "machhw. %0, %1, %2"
972   [(set_attr "type" "imul3")])
973
974 (define_insn "*machhw"
975   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
976         (plus:SI (mult:SI (ashiftrt:SI
977                            (match_operand:SI 1 "gpc_reg_operand" "%r")
978                            (const_int 16))
979                           (ashiftrt:SI
980                            (match_operand:SI 2 "gpc_reg_operand" "r")
981                            (const_int 16)))
982                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
983   "TARGET_MULHW"
984   "machhw %0, %1, %2"
985   [(set_attr "type" "imul3")])
986
987 (define_insn "*machhwuc"
988   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
989         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
990                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
991                                        (const_int 16))
992                                       (lshiftrt:SI
993                                        (match_operand:SI 2 "gpc_reg_operand" "r")
994                                        (const_int 16)))
995                              (match_operand:SI 4 "gpc_reg_operand" "0"))
996                     (const_int 0)))
997    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
998         (plus:SI (mult:SI (lshiftrt:SI
999                            (match_dup 1)
1000                            (const_int 16))
1001                           (lshiftrt:SI
1002                            (match_dup 2)
1003                            (const_int 16)))
1004                  (match_dup 4)))]
1005   "TARGET_MULHW"
1006   "machhwu. %0, %1, %2"
1007   [(set_attr "type" "imul3")])
1008
1009 (define_insn "*machhwu"
1010   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1011         (plus:SI (mult:SI (lshiftrt:SI
1012                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1013                            (const_int 16))
1014                           (lshiftrt:SI
1015                            (match_operand:SI 2 "gpc_reg_operand" "r")
1016                            (const_int 16)))
1017                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1018   "TARGET_MULHW"
1019   "machhwu %0, %1, %2"
1020   [(set_attr "type" "imul3")])
1021
1022 (define_insn "*maclhwc"
1023   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1024         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1025                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1026                                       (sign_extend:SI
1027                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1028                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1029                     (const_int 0)))
1030    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1031         (plus:SI (mult:SI (sign_extend:SI
1032                            (match_dup 1))
1033                           (sign_extend:SI
1034                            (match_dup 2)))
1035                  (match_dup 4)))]
1036   "TARGET_MULHW"
1037   "maclhw. %0, %1, %2"
1038   [(set_attr "type" "imul3")])
1039
1040 (define_insn "*maclhw"
1041   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1042         (plus:SI (mult:SI (sign_extend:SI
1043                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1044                           (sign_extend:SI
1045                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1046                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1047   "TARGET_MULHW"
1048   "maclhw %0, %1, %2"
1049   [(set_attr "type" "imul3")])
1050
1051 (define_insn "*maclhwuc"
1052   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1053         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1054                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1055                                       (zero_extend:SI
1056                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1057                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1058                     (const_int 0)))
1059    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1060         (plus:SI (mult:SI (zero_extend:SI
1061                            (match_dup 1))
1062                           (zero_extend:SI
1063                            (match_dup 2)))
1064                  (match_dup 4)))]
1065   "TARGET_MULHW"
1066   "maclhwu. %0, %1, %2"
1067   [(set_attr "type" "imul3")])
1068
1069 (define_insn "*maclhwu"
1070   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1071         (plus:SI (mult:SI (zero_extend:SI
1072                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1073                           (zero_extend:SI
1074                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1075                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1076   "TARGET_MULHW"
1077   "maclhwu %0, %1, %2"
1078   [(set_attr "type" "imul3")])
1079
1080 (define_insn "*nmacchwc"
1081   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1082         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1083                               (mult:SI (ashiftrt:SI
1084                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1085                                         (const_int 16))
1086                                        (sign_extend:SI
1087                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1088                     (const_int 0)))
1089    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1090         (minus:SI (match_dup 4)
1091                   (mult:SI (ashiftrt:SI
1092                             (match_dup 2)
1093                             (const_int 16))
1094                            (sign_extend:SI
1095                             (match_dup 1)))))]
1096   "TARGET_MULHW"
1097   "nmacchw. %0, %1, %2"
1098   [(set_attr "type" "imul3")])
1099
1100 (define_insn "*nmacchw"
1101   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1102         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1103                   (mult:SI (ashiftrt:SI
1104                             (match_operand:SI 2 "gpc_reg_operand" "r")
1105                             (const_int 16))
1106                            (sign_extend:SI
1107                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1108   "TARGET_MULHW"
1109   "nmacchw %0, %1, %2"
1110   [(set_attr "type" "imul3")])
1111
1112 (define_insn "*nmachhwc"
1113   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1114         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1115                               (mult:SI (ashiftrt:SI
1116                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1117                                         (const_int 16))
1118                                        (ashiftrt:SI
1119                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1120                                         (const_int 16))))
1121                     (const_int 0)))
1122    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1123         (minus:SI (match_dup 4)
1124                   (mult:SI (ashiftrt:SI
1125                             (match_dup 1)
1126                             (const_int 16))
1127                            (ashiftrt:SI
1128                             (match_dup 2)
1129                             (const_int 16)))))]
1130   "TARGET_MULHW"
1131   "nmachhw. %0, %1, %2"
1132   [(set_attr "type" "imul3")])
1133
1134 (define_insn "*nmachhw"
1135   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1136         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1137                   (mult:SI (ashiftrt:SI
1138                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1139                             (const_int 16))
1140                            (ashiftrt:SI
1141                             (match_operand:SI 2 "gpc_reg_operand" "r")
1142                             (const_int 16)))))]
1143   "TARGET_MULHW"
1144   "nmachhw %0, %1, %2"
1145   [(set_attr "type" "imul3")])
1146
1147 (define_insn "*nmaclhwc"
1148   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1149         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1150                               (mult:SI (sign_extend:SI
1151                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1152                                        (sign_extend:SI
1153                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1154                     (const_int 0)))
1155    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1156         (minus:SI (match_dup 4)
1157                   (mult:SI (sign_extend:SI
1158                             (match_dup 1))
1159                            (sign_extend:SI
1160                             (match_dup 2)))))]
1161   "TARGET_MULHW"
1162   "nmaclhw. %0, %1, %2"
1163   [(set_attr "type" "imul3")])
1164
1165 (define_insn "*nmaclhw"
1166   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1167         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1168                   (mult:SI (sign_extend:SI
1169                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1170                            (sign_extend:SI
1171                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1172   "TARGET_MULHW"
1173   "nmaclhw %0, %1, %2"
1174   [(set_attr "type" "imul3")])
1175
1176 (define_insn "*mulchwc"
1177   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1178         (compare:CC (mult:SI (ashiftrt:SI
1179                               (match_operand:SI 2 "gpc_reg_operand" "r")
1180                               (const_int 16))
1181                              (sign_extend:SI
1182                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1183                     (const_int 0)))
1184    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1185         (mult:SI (ashiftrt:SI
1186                   (match_dup 2)
1187                   (const_int 16))
1188                  (sign_extend:SI
1189                   (match_dup 1))))]
1190   "TARGET_MULHW"
1191   "mulchw. %0, %1, %2"
1192   [(set_attr "type" "imul3")])
1193
1194 (define_insn "*mulchw"
1195   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1196         (mult:SI (ashiftrt:SI
1197                   (match_operand:SI 2 "gpc_reg_operand" "r")
1198                   (const_int 16))
1199                  (sign_extend:SI
1200                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1201   "TARGET_MULHW"
1202   "mulchw %0, %1, %2"
1203   [(set_attr "type" "imul3")])
1204
1205 (define_insn "*mulchwuc"
1206   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1207         (compare:CC (mult:SI (lshiftrt:SI
1208                               (match_operand:SI 2 "gpc_reg_operand" "r")
1209                               (const_int 16))
1210                              (zero_extend:SI
1211                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1212                     (const_int 0)))
1213    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1214         (mult:SI (lshiftrt:SI
1215                   (match_dup 2)
1216                   (const_int 16))
1217                  (zero_extend:SI
1218                   (match_dup 1))))]
1219   "TARGET_MULHW"
1220   "mulchwu. %0, %1, %2"
1221   [(set_attr "type" "imul3")])
1222
1223 (define_insn "*mulchwu"
1224   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1225         (mult:SI (lshiftrt:SI
1226                   (match_operand:SI 2 "gpc_reg_operand" "r")
1227                   (const_int 16))
1228                  (zero_extend:SI
1229                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1230   "TARGET_MULHW"
1231   "mulchwu %0, %1, %2"
1232   [(set_attr "type" "imul3")])
1233
1234 (define_insn "*mulhhwc"
1235   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1236         (compare:CC (mult:SI (ashiftrt:SI
1237                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1238                               (const_int 16))
1239                              (ashiftrt:SI
1240                               (match_operand:SI 2 "gpc_reg_operand" "r")
1241                               (const_int 16)))
1242                     (const_int 0)))
1243    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1244         (mult:SI (ashiftrt:SI
1245                   (match_dup 1)
1246                   (const_int 16))
1247                  (ashiftrt:SI
1248                   (match_dup 2)
1249                   (const_int 16))))]
1250   "TARGET_MULHW"
1251   "mulhhw. %0, %1, %2"
1252   [(set_attr "type" "imul3")])
1253
1254 (define_insn "*mulhhw"
1255   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1256         (mult:SI (ashiftrt:SI
1257                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1258                   (const_int 16))
1259                  (ashiftrt:SI
1260                   (match_operand:SI 2 "gpc_reg_operand" "r")
1261                   (const_int 16))))]
1262   "TARGET_MULHW"
1263   "mulhhw %0, %1, %2"
1264   [(set_attr "type" "imul3")])
1265
1266 (define_insn "*mulhhwuc"
1267   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1268         (compare:CC (mult:SI (lshiftrt:SI
1269                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1270                               (const_int 16))
1271                              (lshiftrt:SI
1272                               (match_operand:SI 2 "gpc_reg_operand" "r")
1273                               (const_int 16)))
1274                     (const_int 0)))
1275    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1276         (mult:SI (lshiftrt:SI
1277                   (match_dup 1)
1278                   (const_int 16))
1279                  (lshiftrt:SI
1280                   (match_dup 2)
1281                   (const_int 16))))]
1282   "TARGET_MULHW"
1283   "mulhhwu. %0, %1, %2"
1284   [(set_attr "type" "imul3")])
1285
1286 (define_insn "*mulhhwu"
1287   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1288         (mult:SI (lshiftrt:SI
1289                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1290                   (const_int 16))
1291                  (lshiftrt:SI
1292                   (match_operand:SI 2 "gpc_reg_operand" "r")
1293                   (const_int 16))))]
1294   "TARGET_MULHW"
1295   "mulhhwu %0, %1, %2"
1296   [(set_attr "type" "imul3")])
1297
1298 (define_insn "*mullhwc"
1299   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1300         (compare:CC (mult:SI (sign_extend:SI
1301                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1302                              (sign_extend:SI
1303                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1304                     (const_int 0)))
1305    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1306         (mult:SI (sign_extend:SI
1307                   (match_dup 1))
1308                  (sign_extend:SI
1309                   (match_dup 2))))]
1310   "TARGET_MULHW"
1311   "mullhw. %0, %1, %2"
1312   [(set_attr "type" "imul3")])
1313
1314 (define_insn "*mullhw"
1315   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1316         (mult:SI (sign_extend:SI
1317                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1318                  (sign_extend:SI
1319                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1320   "TARGET_MULHW"
1321   "mullhw %0, %1, %2"
1322   [(set_attr "type" "imul3")])
1323
1324 (define_insn "*mullhwuc"
1325   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1326         (compare:CC (mult:SI (zero_extend:SI
1327                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1328                              (zero_extend:SI
1329                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1330                     (const_int 0)))
1331    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1332         (mult:SI (zero_extend:SI
1333                   (match_dup 1))
1334                  (zero_extend:SI
1335                   (match_dup 2))))]
1336   "TARGET_MULHW"
1337   "mullhwu. %0, %1, %2"
1338   [(set_attr "type" "imul3")])
1339
1340 (define_insn "*mullhwu"
1341   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1342         (mult:SI (zero_extend:SI
1343                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1344                  (zero_extend:SI
1345                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1346   "TARGET_MULHW"
1347   "mullhwu %0, %1, %2"
1348   [(set_attr "type" "imul3")])
1349 \f
1350 ;; IBM 405 and 440 string-search dlmzb instruction support.
1351 (define_insn "dlmzb"
1352   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1353         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1354                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1355                    UNSPEC_DLMZB_CR))
1356    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1357         (unspec:SI [(match_dup 1)
1358                     (match_dup 2)]
1359                    UNSPEC_DLMZB))]
1360   "TARGET_DLMZB"
1361   "dlmzb. %0, %1, %2")
1362
1363 (define_expand "strlensi"
1364   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1365         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1366                     (match_operand:QI 2 "const_int_operand" "")
1367                     (match_operand 3 "const_int_operand" "")]
1368                    UNSPEC_DLMZB_STRLEN))
1369    (clobber (match_scratch:CC 4 "=x"))]
1370   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1371 {
1372   rtx result = operands[0];
1373   rtx src = operands[1];
1374   rtx search_char = operands[2];
1375   rtx align = operands[3];
1376   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1377   rtx loop_label, end_label, mem, cr0, cond;
1378   if (search_char != const0_rtx
1379       || GET_CODE (align) != CONST_INT
1380       || INTVAL (align) < 8)
1381         FAIL;
1382   word1 = gen_reg_rtx (SImode);
1383   word2 = gen_reg_rtx (SImode);
1384   scratch_dlmzb = gen_reg_rtx (SImode);
1385   scratch_string = gen_reg_rtx (Pmode);
1386   loop_label = gen_label_rtx ();
1387   end_label = gen_label_rtx ();
1388   addr = force_reg (Pmode, XEXP (src, 0));
1389   emit_move_insn (scratch_string, addr);
1390   emit_label (loop_label);
1391   mem = change_address (src, SImode, scratch_string);
1392   emit_move_insn (word1, mem);
1393   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1394   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1395   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1396   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1397   emit_jump_insn (gen_rtx_SET (VOIDmode,
1398                                pc_rtx,
1399                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1400                                                      cond,
1401                                                      gen_rtx_LABEL_REF
1402                                                        (VOIDmode,
1403                                                         end_label),
1404                                                      pc_rtx)));
1405   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1406   emit_jump_insn (gen_rtx_SET (VOIDmode,
1407                                pc_rtx,
1408                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1409   emit_barrier ();
1410   emit_label (end_label);
1411   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1412   emit_insn (gen_subsi3 (result, scratch_string, addr));
1413   emit_insn (gen_subsi3 (result, result, const1_rtx));
1414   DONE;
1415 })
1416 \f
1417 (define_split
1418   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1419         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1420                     (const_int 0)))
1421    (set (match_operand:SI 0 "gpc_reg_operand" "")
1422         (sign_extend:SI (match_dup 1)))]
1423   "reload_completed"
1424   [(set (match_dup 0)
1425         (sign_extend:SI (match_dup 1)))
1426    (set (match_dup 2)
1427         (compare:CC (match_dup 0)
1428                     (const_int 0)))]
1429   "")
1430
1431 ;; Fixed-point arithmetic insns.
1432
1433 (define_expand "add<mode>3"
1434   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1435         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1436                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1437   ""
1438 {
1439   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1440     {
1441       if (non_short_cint_operand (operands[2], DImode))
1442         FAIL;
1443     }
1444   else if (GET_CODE (operands[2]) == CONST_INT
1445            && ! add_operand (operands[2], <MODE>mode))
1446     {
1447       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
1448                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1449
1450       HOST_WIDE_INT val = INTVAL (operands[2]);
1451       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1452       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1453
1454       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1455         FAIL;
1456
1457       /* The ordering here is important for the prolog expander.
1458          When space is allocated from the stack, adding 'low' first may
1459          produce a temporary deallocation (which would be bad).  */
1460       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1461       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1462       DONE;
1463     }
1464 })
1465
1466 ;; Discourage ai/addic because of carry but provide it in an alternative
1467 ;; allowing register zero as source.
1468 (define_insn "*add<mode>3_internal1"
1469   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1470         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1471                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1472   ""
1473   "@
1474    {cax|add} %0,%1,%2
1475    {cal %0,%2(%1)|addi %0,%1,%2}
1476    {ai|addic} %0,%1,%2
1477    {cau|addis} %0,%1,%v2"
1478   [(set_attr "length" "4,4,4,4")])
1479
1480 (define_insn "addsi3_high"
1481   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1482         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1483                  (high:SI (match_operand 2 "" ""))))]
1484   "TARGET_MACHO && !TARGET_64BIT"
1485   "{cau|addis} %0,%1,ha16(%2)"
1486   [(set_attr "length" "4")])
1487
1488 (define_insn "*add<mode>3_internal2"
1489   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1490         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1491                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1492                     (const_int 0)))
1493    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1494   ""
1495   "@
1496    {cax.|add.} %3,%1,%2
1497    {ai.|addic.} %3,%1,%2
1498    #
1499    #"
1500   [(set_attr "type" "fast_compare,compare,compare,compare")
1501    (set_attr "length" "4,4,8,8")])
1502
1503 (define_split
1504   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1505         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1506                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1507                     (const_int 0)))
1508    (clobber (match_scratch:GPR 3 ""))]
1509   "reload_completed"
1510   [(set (match_dup 3)
1511         (plus:GPR (match_dup 1)
1512                  (match_dup 2)))
1513    (set (match_dup 0)
1514         (compare:CC (match_dup 3)
1515                     (const_int 0)))]
1516   "")
1517
1518 (define_insn "*add<mode>3_internal3"
1519   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1520         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1521                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1522                     (const_int 0)))
1523    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1524         (plus:P (match_dup 1)
1525                 (match_dup 2)))]
1526   ""
1527   "@
1528    {cax.|add.} %0,%1,%2
1529    {ai.|addic.} %0,%1,%2
1530    #
1531    #"
1532   [(set_attr "type" "fast_compare,compare,compare,compare")
1533    (set_attr "length" "4,4,8,8")])
1534
1535 (define_split
1536   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1537         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1538                             (match_operand:P 2 "reg_or_short_operand" ""))
1539                     (const_int 0)))
1540    (set (match_operand:P 0 "gpc_reg_operand" "")
1541         (plus:P (match_dup 1) (match_dup 2)))]
1542   "reload_completed"
1543   [(set (match_dup 0)
1544         (plus:P (match_dup 1)
1545                 (match_dup 2)))
1546    (set (match_dup 3)
1547         (compare:CC (match_dup 0)
1548                     (const_int 0)))]
1549   "")
1550
1551 ;; Split an add that we can't do in one insn into two insns, each of which
1552 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1553 ;; add should be last in case the result gets used in an address.
1554
1555 (define_split
1556   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1557         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1558                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1559   ""
1560   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1561    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
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 || satisfies_constraint_L (GEN_INT (rest)))
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)))