OSDN Git Service

* alpha.md (fp cmp): Replicate patterns for ALPHA_TP_INSN.
[pf3gnuchains/gcc-fork.git] / gcc / config / alpha / alpha.md
1 ;; Machine description for DEC Alpha for GNU C compiler
2 ;; Copyright (C) 1992, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
3 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
4
5 ;; This file is part of GNU CC.
6
7 ;; GNU CC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
11
12 ;; GNU CC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU CC; see the file COPYING.  If not, write to
19 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
21
22 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
23
24 ;; Uses of UNSPEC in this file:
25 ;;
26 ;;      0       arg_home
27 ;;      1       cttz
28 ;;      2       insxh
29 ;;      3       mskxh
30 ;;      4       cvtlq
31 ;;      5       cvtql
32 ;;      
33 ;; UNSPEC_VOLATILE:
34 ;;
35 ;;      0       imb
36 ;;      1       blockage
37 ;;      2       builtin_setjmp_receiver
38 ;;      3       builtin_longjmp
39 ;;      4       trapb
40 ;;      5       prologue_stack_probe_loop
41 \f
42 ;; Processor type -- this attribute must exactly match the processor_type
43 ;; enumeration in alpha.h.
44
45 (define_attr "cpu" "ev4,ev5,ev6"
46   (const (symbol_ref "alpha_cpu")))
47
48 ;; Define an insn type attribute.  This is used in function unit delay
49 ;; computations, among other purposes.  For the most part, we use the names
50 ;; defined in the EV4 documentation, but add a few that we have to know about
51 ;; separately.
52
53 (define_attr "type"
54   "ild,fld,ldsym,ist,fst,ibr,fbr,jsr,iadd,ilog,shift,icmov,fcmov,icmp,imul,fadd,fmul,fcpys,fdiv,fsqrt,misc,mvi,ftoi,itof"
55   (const_string "iadd"))
56
57 ;; Define the operand size an insn operates on.  Used primarily by mul
58 ;; and div operations that have size dependant timings.
59
60 (define_attr "opsize" "si,di,udi" (const_string "di"))
61
62 ;; The TRAP_TYPE attribute marks instructions that may generate traps
63 ;; (which are imprecise and may need a trapb if software completion
64 ;; is desired).
65
66 (define_attr "trap" "no,yes" (const_string "no"))
67
68 ;; The length of an instruction sequence in bytes.
69
70 (define_attr "length" "" (const_int 4))
71 \f
72 ;; On EV4 there are two classes of resources to consider: resources needed
73 ;; to issue, and resources needed to execute.  IBUS[01] are in the first
74 ;; category.  ABOX, BBOX, EBOX, FBOX, IMUL & FDIV make up the second.
75 ;; (There are a few other register-like resources, but ...)
76
77 ; First, describe all of the issue constraints with single cycle delays.
78 ; All insns need a bus, but all except loads require one or the other.
79 (define_function_unit "ev4_ibus0" 1 0
80   (and (eq_attr "cpu" "ev4")
81        (eq_attr "type" "fst,fbr,iadd,imul,ilog,shift,icmov,icmp"))
82   1 1)
83
84 (define_function_unit "ev4_ibus1" 1 0
85   (and (eq_attr "cpu" "ev4")
86        (eq_attr "type" "ist,ibr,jsr,fadd,fcmov,fcpys,fmul,fdiv,misc"))
87   1 1)
88
89 ; Memory delivers its result in three cycles.  Actually return one and
90 ; take care of this in adjust_cost, since we want to handle user-defined
91 ; memory latencies.
92 (define_function_unit "ev4_abox" 1 0
93   (and (eq_attr "cpu" "ev4")
94        (eq_attr "type" "ild,fld,ldsym,ist,fst"))
95   1 1)
96
97 ; Branches have no delay cost, but do tie up the unit for two cycles.
98 (define_function_unit "ev4_bbox" 1 1
99   (and (eq_attr "cpu" "ev4")
100        (eq_attr "type" "ibr,fbr,jsr"))
101   2 2)
102
103 ; Arithmetic insns are normally have their results available after
104 ; two cycles.  There are a number of exceptions.  They are encoded in
105 ; ADJUST_COST.  Some of the other insns have similar exceptions.
106 (define_function_unit "ev4_ebox" 1 0
107   (and (eq_attr "cpu" "ev4")
108        (eq_attr "type" "iadd,ilog,shift,icmov,icmp,misc"))
109   2 1)
110
111 (define_function_unit "imul" 1 0
112   (and (eq_attr "cpu" "ev4")
113        (and (eq_attr "type" "imul")
114             (eq_attr "opsize" "si")))
115   21 19)
116
117 (define_function_unit "imul" 1 0
118   (and (eq_attr "cpu" "ev4")
119        (and (eq_attr "type" "imul")
120             (eq_attr "opsize" "!si")))
121   23 21)
122
123 (define_function_unit "ev4_fbox" 1 0
124   (and (eq_attr "cpu" "ev4")
125        (eq_attr "type" "fadd,fmul,fcpys,fcmov"))
126   6 1)
127
128 (define_function_unit "fdiv" 1 0
129   (and (eq_attr "cpu" "ev4")
130        (and (eq_attr "type" "fdiv")
131             (eq_attr "opsize" "si")))
132   34 30)
133
134 (define_function_unit "fdiv" 1 0
135   (and (eq_attr "cpu" "ev4")
136        (and (eq_attr "type" "fdiv")
137             (eq_attr "opsize" "di")))
138   63 59)
139 \f
140 ;; EV5 scheduling.  EV5 can issue 4 insns per clock.
141 ;;
142 ;; EV5 has two asymetric integer units.  Model this with E0 & E1 along
143 ;; with the combined resource EBOX.
144
145 (define_function_unit "ev5_ebox" 2 0
146   (and (eq_attr "cpu" "ev5")
147        (eq_attr "type" "!fbr,fcmov,fadd,fmul,fcpys,fdiv"))
148   1 1)
149
150 ; Memory takes at least 2 clocks.  Return one from here and fix up with
151 ; user-defined latencies in adjust_cost.
152 ; ??? How to: "An instruction of class LD cannot be issued in the _second_
153 ; cycle after an instruction of class ST is issued."
154 (define_function_unit "ev5_ebox" 2 0
155   (and (eq_attr "cpu" "ev5")
156        (eq_attr "type" "ild,fld,ldsym"))
157   1 1)
158
159 ; Stores, shifts, multiplies can only issue to E0
160 (define_function_unit "ev5_e0" 1 0
161   (and (eq_attr "cpu" "ev5")
162        (eq_attr "type" "ist,fst,shift,imul"))
163   1 1)
164
165 ; Motion video insns also issue only to E0, and take two ticks.
166 (define_function_unit "ev5_e0" 1 0
167   (and (eq_attr "cpu" "ev5")
168        (eq_attr "type" "mvi"))
169   2 1)
170
171 ; Conditional moves always take 2 ticks.
172 (define_function_unit "ev5_ebox" 2 0
173   (and (eq_attr "cpu" "ev5")
174        (eq_attr "type" "icmov"))
175   2 1)
176
177 ; Branches can only issue to E1
178 (define_function_unit "ev5_e1" 1 0
179   (and (eq_attr "cpu" "ev5")
180        (eq_attr "type" "ibr,jsr"))
181   1 1)
182
183 ; Multiplies also use the integer multiplier.
184 ; ??? How to: "No instruction can be issued to pipe E0 exactly two
185 ; cycles before an integer multiplication completes."
186 (define_function_unit "imul" 1 0
187   (and (eq_attr "cpu" "ev5")
188        (and (eq_attr "type" "imul")
189             (eq_attr "opsize" "si")))
190   8 4)
191
192 (define_function_unit "imul" 1 0
193   (and (eq_attr "cpu" "ev5")
194        (and (eq_attr "type" "imul")
195             (eq_attr "opsize" "di")))
196   12 8)
197
198 (define_function_unit "imul" 1 0
199   (and (eq_attr "cpu" "ev5")
200        (and (eq_attr "type" "imul")
201             (eq_attr "opsize" "udi")))
202   14 8)
203
204 ;; Similarly for the FPU we have two asymetric units.  But fcpys can issue
205 ;; on either so we have to play the game again.
206
207 (define_function_unit "ev5_fbox" 2 0
208   (and (eq_attr "cpu" "ev5")
209        (eq_attr "type" "fadd,fcmov,fmul,fcpys,fbr,fdiv"))
210   4 1)
211   
212 (define_function_unit "ev5_fm" 1 0
213   (and (eq_attr "cpu" "ev5")
214        (eq_attr "type" "fmul"))
215   4 1)
216
217 ; Add and cmov as you would expect; fbr never produces a result;
218 ; fdiv issues through fa to the divider, 
219 (define_function_unit "ev5_fa" 1 0
220   (and (eq_attr "cpu" "ev5")
221        (eq_attr "type" "fadd,fcmov,fbr,fdiv"))
222   4 1)
223
224 ; ??? How to: "No instruction can be issued to pipe FA exactly five
225 ; cycles before a floating point divide completes."
226 (define_function_unit "fdiv" 1 0
227   (and (eq_attr "cpu" "ev5")
228        (and (eq_attr "type" "fdiv")
229             (eq_attr "opsize" "si")))
230   15 15)                                ; 15 to 31 data dependant
231
232 (define_function_unit "fdiv" 1 0
233   (and (eq_attr "cpu" "ev5")
234        (and (eq_attr "type" "fdiv")
235             (eq_attr "opsize" "di")))
236   22 22)                                ; 22 to 60 data dependant
237 \f
238 ;; EV6 scheduling.  EV6 can issue 4 insns per clock.
239 ;;
240 ;; EV6 has two symmetric pairs ("clusters") of two asymetric integer units
241 ;; ("upper" and "lower"), yielding pipe names U0, U1, L0, L1.
242
243 ;; Conditional moves decompose into two independant primitives, each 
244 ;; taking one cycle.  Since ev6 is out-of-order, we can't see anything
245 ;; but two cycles.
246 (define_function_unit "ev6_ebox" 4 0
247   (and (eq_attr "cpu" "ev6")
248        (eq_attr "type" "icmov"))
249   2 1)
250
251 (define_function_unit "ev6_ebox" 4 0
252   (and (eq_attr "cpu" "ev6")
253        (eq_attr "type" "!fbr,fcmov,fadd,fmul,fcpys,fdiv,fsqrt"))
254   1 1)
255
256 ;; Integer loads take at least 3 clocks, and only issue to lower units.
257 ;; Return one from here and fix up with user-defined latencies in adjust_cost.
258 (define_function_unit "ev6_l" 2 0
259   (and (eq_attr "cpu" "ev6")
260        (eq_attr "type" "ild,ldsym,ist,fst"))
261   1 1)
262
263 ;; FP loads take at least 4 clocks.  Return two from here...
264 (define_function_unit "ev6_l" 2 0
265   (and (eq_attr "cpu" "ev6")
266        (eq_attr "type" "fld"))
267   2 1)
268
269 ;; Motion video insns also issue only to U0, and take three ticks.
270 (define_function_unit "ev6_u0" 1 0
271   (and (eq_attr "cpu" "ev6")
272        (eq_attr "type" "mvi"))
273   3 1)
274
275 (define_function_unit "ev6_u" 2 0
276   (and (eq_attr "cpu" "ev6")
277        (eq_attr "type" "mvi"))
278   3 1)
279
280 ;; Shifts issue to either upper pipe.
281 (define_function_unit "ev6_u" 2 0
282   (and (eq_attr "cpu" "ev6")
283        (eq_attr "type" "shift"))
284   1 1)
285
286 ;; Multiplies issue only to U1, and all take 7 ticks.
287 ;; Rather than create a new function unit just for U1, reuse IMUL
288 (define_function_unit "imul" 1 0
289   (and (eq_attr "cpu" "ev6")
290        (eq_attr "type" "imul"))
291   7 1)
292
293 (define_function_unit "ev6_u" 2 0
294   (and (eq_attr "cpu" "ev6")
295        (eq_attr "type" "imul"))
296   7 1)
297
298 ;; Branches issue to either upper pipe
299 (define_function_unit "ev6_u" 2 0
300   (and (eq_attr "cpu" "ev6")
301        (eq_attr "type" "ibr"))
302   3 1)
303
304 ;; Calls only issue to L0.
305 (define_function_unit "ev6_l0" 1 0
306   (and (eq_attr "cpu" "ev6")
307        (eq_attr "type" "jsr"))
308   1 1)
309
310 (define_function_unit "ev6_l" 2 0
311   (and (eq_attr "cpu" "ev6")
312        (eq_attr "type" "jsr"))
313   1 1)
314
315 ;; Ftoi/itof only issue to lower pipes
316 (define_function_unit "ev6_l" 2 0
317   (and (eq_attr "cpu" "ev6")
318        (eq_attr "type" "ftoi"))
319   3 1)
320
321 (define_function_unit "ev6_l" 2 0
322   (and (eq_attr "cpu" "ev6")
323        (eq_attr "type" "itof"))
324   4 1)
325
326 ;; For the FPU we are very similar to EV5, except there's no insn that
327 ;; can issue to fm & fa, so we get to leave that out.
328   
329 (define_function_unit "ev6_fm" 1 0
330   (and (eq_attr "cpu" "ev6")
331        (eq_attr "type" "fmul"))
332   4 1)
333
334 (define_function_unit "ev6_fa" 1 0
335   (and (eq_attr "cpu" "ev6")
336        (eq_attr "type" "fadd,fcpys,fbr,fdiv,fsqrt"))
337   4 1)
338
339 (define_function_unit "ev6_fa" 1 0
340   (and (eq_attr "cpu" "ev6")
341        (eq_attr "type" "fcmov"))
342   8 1)
343
344 (define_function_unit "fdiv" 1 0
345   (and (eq_attr "cpu" "ev6")
346        (and (eq_attr "type" "fdiv")
347             (eq_attr "opsize" "si")))
348   12 10)
349
350 (define_function_unit "fdiv" 1 0
351   (and (eq_attr "cpu" "ev6")
352        (and (eq_attr "type" "fdiv")
353             (eq_attr "opsize" "di")))
354   15 13)
355
356 (define_function_unit "fsqrt" 1 0
357   (and (eq_attr "cpu" "ev6")
358        (and (eq_attr "type" "fsqrt")
359             (eq_attr "opsize" "si")))
360   16 14)
361
362 (define_function_unit "fsqrt" 1 0
363   (and (eq_attr "cpu" "ev6")
364        (and (eq_attr "type" "fsqrt")
365             (eq_attr "opsize" "di")))
366   32 30)
367
368 ; ??? The FPU communicates with memory and the integer register file
369 ; via two fp store units.  We need a slot in the fst immediately, and
370 ; a slot in LOW after the operand data is ready.  At which point the
371 ; data may be moved either to the store queue or the integer register
372 ; file and the insn retired.
373
374 \f
375 ;; First define the arithmetic insns.  Note that the 32-bit forms also
376 ;; sign-extend.
377
378 ;; Handle 32-64 bit extension from memory to a floating point register
379 ;; specially, since this ocurrs frequently in int->double conversions.
380 ;; This is done with a define_split after reload converting the plain
381 ;; sign-extension into a load+unspec, which of course results in lds+cvtlq.
382 ;;
383 ;; Note that while we must retain the =f case in the insn for reload's
384 ;; benefit, it should be eliminated after reload, so we should never emit
385 ;; code for that case.  But we don't reject the possibility.
386
387 (define_insn "extendsidi2"
388   [(set (match_operand:DI 0 "register_operand" "=r,r,?f")
389         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "r,m,m")))]
390   ""
391   "@
392    addl %1,$31,%0
393    ldl %0,%1
394    lds %0,%1\;cvtlq %0,%0"
395   [(set_attr "type" "iadd,ild,fld")
396    (set_attr "length" "*,*,8")])
397
398 ;; Due to issues with CLASS_CANNOT_CHANGE_SIZE, we cannot use a subreg here.
399 (define_split
400   [(set (match_operand:DI 0 "hard_fp_register_operand" "")
401         (sign_extend:DI (match_operand:SI 1 "memory_operand" "")))]
402   "reload_completed"
403   [(set (match_dup 2) (match_dup 1))
404    (set (match_dup 0) (unspec:DI [(match_dup 2)] 4))]
405   "operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]));")
406
407 (define_insn ""
408   [(set (match_operand:DI 0 "register_operand" "=f")
409         (unspec:DI [(match_operand:SI 1 "register_operand" "f")] 4))]
410   ""
411   "cvtlq %1,%0"
412   [(set_attr "type" "fadd")])
413
414 ;; Do addsi3 the way expand_binop would do if we didn't have one.  This
415 ;; generates better code.  We have the anonymous addsi3 pattern below in
416 ;; case combine wants to make it.
417 (define_expand "addsi3"
418   [(set (match_operand:SI 0 "register_operand" "")
419         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "")
420                  (match_operand:SI 2 "add_operand" "")))]
421   ""
422   "
423 { emit_insn (gen_rtx_SET (VOIDmode, gen_lowpart (DImode, operands[0]),
424                           gen_rtx_PLUS (DImode,
425                                         gen_lowpart (DImode, operands[1]),
426                                         gen_lowpart (DImode, operands[2]))));
427   DONE;
428 } ")
429
430 (define_insn ""
431   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
432         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ,rJ,rJ")
433                  (match_operand:SI 2 "add_operand" "rI,O,K,L")))]
434   ""
435   "@
436    addl %r1,%2,%0
437    subl %r1,%n2,%0
438    lda %0,%2(%r1)
439    ldah %0,%h2(%r1)")
440
441 (define_split
442   [(set (match_operand:SI 0 "register_operand" "")
443         (plus:SI (match_operand:SI 1 "register_operand" "")
444                  (match_operand:SI 2 "const_int_operand" "")))]
445   "! add_operand (operands[2], SImode)"
446   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
447    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
448   "
449 {
450   HOST_WIDE_INT val = INTVAL (operands[2]);
451   HOST_WIDE_INT low = (val & 0xffff) - 2 * (val & 0x8000);
452   HOST_WIDE_INT rest = val - low;
453
454   operands[3] = GEN_INT (rest);
455   operands[4] = GEN_INT (low);
456 }")
457
458 (define_insn ""
459   [(set (match_operand:DI 0 "register_operand" "=r,r")
460         (sign_extend:DI
461          (plus:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ")
462                   (match_operand:SI 2 "sext_add_operand" "rI,O"))))]
463   ""
464   "@
465    addl %r1,%2,%0
466    subl %r1,%n2,%0")
467
468 (define_split
469   [(set (match_operand:DI 0 "register_operand" "")
470         (sign_extend:DI
471          (plus:SI (match_operand:SI 1 "register_operand" "")
472                   (match_operand:SI 2 "const_int_operand" ""))))
473    (clobber (match_operand:SI 3 "register_operand" ""))]
474   "! sext_add_operand (operands[2], SImode) && INTVAL (operands[2]) > 0
475    && INTVAL (operands[2]) % 4 == 0"
476   [(set (match_dup 3) (match_dup 4))
477    (set (match_dup 0) (sign_extend:DI (plus:SI (mult:SI (match_dup 3)
478                                                         (match_dup 5))
479                                                (match_dup 1))))]
480   "
481 {
482   HOST_WIDE_INT val = INTVAL (operands[2]) / 4;
483   int mult = 4;
484
485   if (val % 2 == 0)
486     val /= 2, mult = 8;
487
488   operands[4] = GEN_INT (val);
489   operands[5] = GEN_INT (mult);
490 }")
491
492 (define_split
493   [(set (match_operand:DI 0 "register_operand" "")
494         (sign_extend:DI
495          (plus:SI (match_operator:SI 1 "comparison_operator"
496                                      [(match_operand 2 "" "")
497                                       (match_operand 3 "" "")])
498                   (match_operand:SI 4 "add_operand" ""))))
499    (clobber (match_operand:DI 5 "register_operand" ""))]
500   ""
501   [(set (match_dup 5) (match_dup 6))
502    (set (match_dup 0) (sign_extend:DI (plus:SI (match_dup 7) (match_dup 4))))]
503   "
504 {
505   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[1]), DImode,
506                                 operands[2], operands[3]);
507   operands[7] = gen_lowpart (SImode, operands[5]);
508 }")
509
510 (define_insn "adddi3"
511   [(set (match_operand:DI 0 "register_operand" "=r,r,r,r")
512         (plus:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ,rJ,rJ")
513                  (match_operand:DI 2 "add_operand" "rI,O,K,L")))]
514   ""
515   "@
516    addq %r1,%2,%0
517    subq %r1,%n2,%0
518    lda %0,%2(%r1)
519    ldah %0,%h2(%r1)")
520
521 ;; Don't do this if we are adjusting SP since we don't want to do
522 ;; it in two steps. 
523 (define_split
524   [(set (match_operand:DI 0 "register_operand" "")
525         (plus:DI (match_operand:DI 1 "register_operand" "")
526                  (match_operand:DI 2 "const_int_operand" "")))]
527   "! add_operand (operands[2], DImode)
528    && REGNO (operands[0]) != STACK_POINTER_REGNUM"
529   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
530    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
531   "
532 {
533   HOST_WIDE_INT val = INTVAL (operands[2]);
534   HOST_WIDE_INT low = (val & 0xffff) - 2 * (val & 0x8000);
535   HOST_WIDE_INT rest = val - low;
536
537   operands[3] = GEN_INT (rest);
538   operands[4] = GEN_INT (low);
539 }")
540
541 (define_insn ""
542   [(set (match_operand:SI 0 "register_operand" "=r,r")
543         (plus:SI (mult:SI (match_operand:SI 1 "reg_or_0_operand" "rJ,rJ")
544                           (match_operand:SI 2 "const48_operand" "I,I"))
545                  (match_operand:SI 3 "sext_add_operand" "rI,O")))]
546   ""
547   "@
548    s%2addl %r1,%3,%0
549    s%2subl %r1,%n3,%0")
550
551 (define_insn ""
552   [(set (match_operand:DI 0 "register_operand" "=r,r")
553         (sign_extend:DI
554          (plus:SI (mult:SI (match_operand:SI 1 "reg_or_0_operand" "rJ,rJ")
555                            (match_operand:SI 2 "const48_operand" "I,I"))
556                   (match_operand:SI 3 "sext_add_operand" "rI,O"))))]
557   ""
558   "@
559    s%2addl %r1,%3,%0
560    s%2subl %r1,%n3,%0")
561
562 (define_split
563   [(set (match_operand:DI 0 "register_operand" "")
564         (sign_extend:DI
565          (plus:SI (mult:SI (match_operator:SI 1 "comparison_operator"
566                                               [(match_operand 2 "" "")
567                                                (match_operand 3 "" "")])
568                            (match_operand:SI 4 "const48_operand" ""))
569                   (match_operand:SI 5 "add_operand" ""))))
570    (clobber (match_operand:DI 6 "register_operand" ""))]
571   ""
572   [(set (match_dup 6) (match_dup 7))
573    (set (match_dup 0)
574         (sign_extend:DI (plus:SI (mult:SI (match_dup 8) (match_dup 4))
575                                  (match_dup 5))))]
576   "
577 {
578   operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[1]), DImode,
579                                 operands[2], operands[3]);
580   operands[8] = gen_lowpart (SImode, operands[6]);
581 }")
582
583 (define_insn ""
584   [(set (match_operand:DI 0 "register_operand" "=r,r")
585         (plus:DI (mult:DI (match_operand:DI 1 "reg_or_0_operand" "rJ,rJ")
586                           (match_operand:DI 2 "const48_operand" "I,I"))
587                  (match_operand:DI 3 "reg_or_8bit_operand" "rI,O")))]
588   ""
589   "@
590    s%2addq %r1,%3,%0
591    s%2subq %1,%n3,%0")
592
593 ;; These variants of the above insns can occur if the third operand
594 ;; is the frame pointer.  This is a kludge, but there doesn't
595 ;; seem to be a way around it.  Only recognize them while reloading.
596
597 (define_insn ""
598   [(set (match_operand:DI 0 "some_operand" "=&r")
599         (plus:DI (plus:DI (match_operand:DI 1 "some_operand" "r")
600                           (match_operand:DI 2 "some_operand" "r"))
601                  (match_operand:DI 3 "some_operand" "rIOKL")))]
602   "reload_in_progress"
603   "#")
604
605 (define_split
606   [(set (match_operand:DI 0 "register_operand" "")
607         (plus:DI (plus:DI (match_operand:DI 1 "register_operand" "")
608                           (match_operand:DI 2 "register_operand" ""))
609                  (match_operand:DI 3 "add_operand" "")))]
610   "reload_completed"
611   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
612    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
613   "")
614                                            
615 (define_insn ""
616   [(set (match_operand:SI 0 "some_operand" "=&r")
617         (plus:SI (plus:SI (mult:SI (match_operand:SI 1 "some_operand" "rJ")
618                                    (match_operand:SI 2 "const48_operand" "I"))
619                           (match_operand:SI 3 "some_operand" "r"))
620                  (match_operand:SI 4 "some_operand" "rIOKL")))]
621   "reload_in_progress"
622   "#")
623
624 (define_split
625   [(set (match_operand:SI 0 "register_operand" "r")
626         (plus:SI (plus:SI (mult:SI (match_operand:SI 1 "reg_or_0_operand" "")
627                                    (match_operand:SI 2 "const48_operand" ""))
628                           (match_operand:SI 3 "register_operand" ""))
629                  (match_operand:SI 4 "add_operand" "rIOKL")))]
630   "reload_completed"
631   [(set (match_dup 0)
632         (plus:SI (mult:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
633    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
634   "")
635
636 (define_insn ""
637   [(set (match_operand:DI 0 "some_operand" "=&r")
638         (sign_extend:DI
639          (plus:SI (plus:SI
640                    (mult:SI (match_operand:SI 1 "some_operand" "rJ")
641                             (match_operand:SI 2 "const48_operand" "I"))
642                    (match_operand:SI 3 "some_operand" "r"))
643                   (match_operand:SI 4 "some_operand" "rIOKL"))))]
644   "reload_in_progress"
645   "#")
646
647 (define_split
648   [(set (match_operand:DI 0 "register_operand" "")
649         (sign_extend:DI
650          (plus:SI (plus:SI
651                    (mult:SI (match_operand:SI 1 "reg_or_0_operand" "")
652                             (match_operand:SI 2 "const48_operand" ""))
653                    (match_operand:SI 3 "register_operand" ""))
654                   (match_operand:SI 4 "add_operand" ""))))]
655   "reload_completed"
656   [(set (match_dup 5)
657         (plus:SI (mult:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
658    (set (match_dup 0) (sign_extend:DI (plus:SI (match_dup 5) (match_dup 4))))]
659   "
660 { operands[5] = gen_lowpart (SImode, operands[0]);
661 }")
662
663 (define_insn ""
664   [(set (match_operand:DI 0 "some_operand" "=&r")
665         (plus:DI (plus:DI (mult:DI (match_operand:DI 1 "some_operand" "rJ")
666                                    (match_operand:DI 2 "const48_operand" "I"))
667                           (match_operand:DI 3 "some_operand" "r"))
668                  (match_operand:DI 4 "some_operand" "rIOKL")))]
669   "reload_in_progress"
670   "#")
671
672 (define_split
673   [(set (match_operand:DI 0 "register_operand" "=")
674         (plus:DI (plus:DI (mult:DI (match_operand:DI 1 "reg_or_0_operand" "")
675                                    (match_operand:DI 2 "const48_operand" ""))
676                           (match_operand:DI 3 "register_operand" ""))
677                  (match_operand:DI 4 "add_operand" "")))]
678   "reload_completed"
679   [(set (match_dup 0)
680         (plus:DI (mult:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
681    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
682   "")
683
684 (define_insn "negsi2"
685   [(set (match_operand:SI 0 "register_operand" "=r")
686         (neg:SI (match_operand:SI 1 "reg_or_8bit_operand" "rI")))]
687   ""
688   "subl $31,%1,%0")
689
690 (define_insn ""
691   [(set (match_operand:DI 0 "register_operand" "=r")
692         (sign_extend:DI (neg:SI
693                          (match_operand:SI 1 "reg_or_8bit_operand" "rI"))))]
694   ""
695   "subl $31,%1,%0")
696
697 (define_insn "negdi2"
698   [(set (match_operand:DI 0 "register_operand" "=r")
699         (neg:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI")))]
700   ""
701   "subq $31,%1,%0")
702
703 (define_expand "subsi3"
704   [(set (match_operand:SI 0 "register_operand" "")
705         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "")
706                   (match_operand:SI 2 "reg_or_8bit_operand" "")))]
707   ""
708   "
709 { emit_insn (gen_rtx_SET (VOIDmode, gen_lowpart (DImode, operands[0]),
710                           gen_rtx_MINUS (DImode,
711                                          gen_lowpart (DImode, operands[1]),
712                                          gen_lowpart (DImode, operands[2]))));
713   DONE;
714 } ")
715
716 (define_insn ""
717   [(set (match_operand:SI 0 "register_operand" "=r")
718         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "rJ")
719                   (match_operand:SI 2 "reg_or_8bit_operand" "rI")))]
720   ""
721   "subl %r1,%2,%0")
722
723 (define_insn ""
724   [(set (match_operand:DI 0 "register_operand" "=r")
725         (sign_extend:DI (minus:SI (match_operand:SI 1 "reg_or_0_operand" "rJ")
726                                   (match_operand:SI 2 "reg_or_8bit_operand" "rI"))))]
727   ""
728   "subl %r1,%2,%0")
729
730 (define_insn "subdi3"
731   [(set (match_operand:DI 0 "register_operand" "=r")
732         (minus:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
733                   (match_operand:DI 2 "reg_or_8bit_operand" "rI")))]
734   ""
735   "subq %r1,%2,%0")
736
737 (define_insn ""
738   [(set (match_operand:SI 0 "register_operand" "=r")
739         (minus:SI (mult:SI (match_operand:SI 1 "reg_or_0_operand" "rJ")
740                            (match_operand:SI 2 "const48_operand" "I"))
741                   (match_operand:SI 3 "reg_or_8bit_operand" "rI")))]
742   ""
743   "s%2subl %r1,%3,%0")
744
745 (define_insn ""
746   [(set (match_operand:DI 0 "register_operand" "=r")
747         (sign_extend:DI
748          (minus:SI (mult:SI (match_operand:SI 1 "reg_or_0_operand" "rJ")
749                             (match_operand:SI 2 "const48_operand" "I"))
750                    (match_operand:SI 3 "reg_or_8bit_operand" "rI"))))]
751   ""
752   "s%2subl %r1,%3,%0")
753
754 (define_insn ""
755   [(set (match_operand:DI 0 "register_operand" "=r")
756         (minus:DI (mult:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
757                            (match_operand:DI 2 "const48_operand" "I"))
758                   (match_operand:DI 3 "reg_or_8bit_operand" "rI")))]
759   ""
760   "s%2subq %r1,%3,%0")
761
762 (define_insn "mulsi3"
763   [(set (match_operand:SI 0 "register_operand" "=r")
764         (mult:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ")
765                  (match_operand:SI 2 "reg_or_0_operand" "rJ")))]
766   ""
767   "mull %r1,%r2,%0"
768   [(set_attr "type" "imul")
769    (set_attr "opsize" "si")])
770
771 (define_insn ""
772   [(set (match_operand:DI 0 "register_operand" "=r")
773         (sign_extend:DI (mult:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ")
774                                  (match_operand:SI 2 "reg_or_0_operand" "rJ"))))]
775   ""
776   "mull %r1,%r2,%0"
777   [(set_attr "type" "imul")
778    (set_attr "opsize" "si")])
779
780 (define_insn "muldi3"
781   [(set (match_operand:DI 0 "register_operand" "=r")
782         (mult:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ")
783                  (match_operand:DI 2 "reg_or_0_operand" "rJ")))]
784   ""
785   "mulq %r1,%r2,%0"
786   [(set_attr "type" "imul")])
787
788 (define_insn "umuldi3_highpart"
789   [(set (match_operand:DI 0 "register_operand" "=r")
790         (truncate:DI
791          (lshiftrt:TI
792           (mult:TI (zero_extend:TI (match_operand:DI 1 "register_operand" "r"))
793                    (zero_extend:TI (match_operand:DI 2 "register_operand" "r")))
794           (const_int 64))))]
795   ""
796   "umulh %1,%2,%0"
797   [(set_attr "type" "imul")
798    (set_attr "opsize" "udi")])
799
800 (define_insn ""
801   [(set (match_operand:DI 0 "register_operand" "=r")
802         (truncate:DI
803          (lshiftrt:TI
804           (mult:TI (zero_extend:TI (match_operand:DI 1 "register_operand" "r"))
805                    (match_operand:TI 2 "cint8_operand" "I"))
806           (const_int 64))))]
807   ""
808   "umulh %1,%2,%0"
809   [(set_attr "type" "imul")
810    (set_attr "opsize" "udi")])
811 \f
812 ;; The divide and remainder operations always take their inputs from
813 ;; r24 and r25, put their output in r27, and clobber r23 and r28.
814
815 ;; ??? Force sign-extension here because some versions of OSF/1 don't
816 ;; do the right thing if the inputs are not properly sign-extended.
817 ;; But Linux, for instance, does not have this problem.  Is it worth
818 ;; the complication here to eliminate the sign extension?
819
820 (define_expand "divsi3"
821   [(set (reg:DI 24)
822         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
823    (set (reg:DI 25)
824         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
825    (parallel [(set (reg:DI 27)
826                    (sign_extend:DI (div:SI (reg:DI 24) (reg:DI 25))))
827               (clobber (reg:DI 23))
828               (clobber (reg:DI 28))])
829    (set (match_operand:SI 0 "general_operand" "")
830         (subreg:SI (reg:DI 27) 0))]
831   "!TARGET_OPEN_VMS"
832   "")
833
834 (define_expand "udivsi3"
835   [(set (reg:DI 24)
836         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
837    (set (reg:DI 25)
838         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
839    (parallel [(set (reg:DI 27)
840                    (sign_extend:DI (udiv:SI (reg:DI 24) (reg:DI 25))))
841               (clobber (reg:DI 23))
842               (clobber (reg:DI 28))])
843    (set (match_operand:SI 0 "general_operand" "")
844         (subreg:SI (reg:DI 27) 0))]
845   "!TARGET_OPEN_VMS"
846   "")
847
848 (define_expand "modsi3"
849   [(set (reg:DI 24)
850         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
851    (set (reg:DI 25)
852         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
853    (parallel [(set (reg:DI 27)
854                    (sign_extend:DI (mod:SI (reg:DI 24) (reg:DI 25))))
855               (clobber (reg:DI 23))
856               (clobber (reg:DI 28))])
857    (set (match_operand:SI 0 "general_operand" "")
858         (subreg:SI (reg:DI 27) 0))]
859   "!TARGET_OPEN_VMS"
860   "")
861
862 (define_expand "umodsi3"
863   [(set (reg:DI 24)
864         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
865    (set (reg:DI 25)
866         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
867    (parallel [(set (reg:DI 27)
868                    (sign_extend:DI (umod:SI (reg:DI 24) (reg:DI 25))))
869               (clobber (reg:DI 23))
870               (clobber (reg:DI 28))])
871    (set (match_operand:SI 0 "general_operand" "")
872         (subreg:SI (reg:DI 27) 0))]
873   "!TARGET_OPEN_VMS"
874   "")
875
876 (define_expand "divdi3"
877   [(set (reg:DI 24) (match_operand:DI 1 "input_operand" ""))
878    (set (reg:DI 25) (match_operand:DI 2 "input_operand" ""))
879    (parallel [(set (reg:DI 27)
880                    (div:DI (reg:DI 24)
881                            (reg:DI 25)))
882               (clobber (reg:DI 23))
883               (clobber (reg:DI 28))])
884    (set (match_operand:DI 0 "general_operand" "")
885         (reg:DI 27))]
886   "!TARGET_OPEN_VMS"
887   "")
888
889 (define_expand "udivdi3"
890   [(set (reg:DI 24) (match_operand:DI 1 "input_operand" ""))
891    (set (reg:DI 25) (match_operand:DI 2 "input_operand" ""))
892    (parallel [(set (reg:DI 27)
893                    (udiv:DI (reg:DI 24)
894                             (reg:DI 25)))
895               (clobber (reg:DI 23))
896               (clobber (reg:DI 28))])
897    (set (match_operand:DI 0 "general_operand" "")
898         (reg:DI 27))]
899   "!TARGET_OPEN_VMS"
900   "")
901
902 (define_expand "moddi3"
903   [(set (reg:DI 24) (match_operand:DI 1 "input_operand" ""))
904    (set (reg:DI 25) (match_operand:DI 2 "input_operand" ""))
905    (parallel [(set (reg:DI 27)
906                    (mod:DI (reg:DI 24)
907                            (reg:DI 25)))
908               (clobber (reg:DI 23))
909               (clobber (reg:DI 28))])
910    (set (match_operand:DI 0 "general_operand" "")
911         (reg:DI 27))]
912   "!TARGET_OPEN_VMS"
913   "")
914
915 (define_expand "umoddi3"
916   [(set (reg:DI 24) (match_operand:DI 1 "input_operand" ""))
917    (set (reg:DI 25) (match_operand:DI 2 "input_operand" ""))
918    (parallel [(set (reg:DI 27)
919                    (umod:DI (reg:DI 24)
920                             (reg:DI 25)))
921               (clobber (reg:DI 23))
922               (clobber (reg:DI 28))])
923    (set (match_operand:DI 0 "general_operand" "")
924         (reg:DI 27))]
925   "!TARGET_OPEN_VMS"
926   "")
927
928 ;; Lengths of 8 for ldq $t12,__divq($gp); jsr $t9,($t12),__divq as
929 ;; expanded by the assembler.
930 (define_insn ""
931   [(set (reg:DI 27)
932         (sign_extend:DI (match_operator:SI 1 "divmod_operator"
933                         [(reg:DI 24) (reg:DI 25)])))
934    (clobber (reg:DI 23))
935    (clobber (reg:DI 28))]
936   "!TARGET_OPEN_VMS"
937   "%E1 $24,$25,$27"
938   [(set_attr "type" "jsr")
939    (set_attr "length" "8")])
940
941 (define_insn ""
942   [(set (reg:DI 27)
943         (match_operator:DI 1 "divmod_operator"
944                         [(reg:DI 24) (reg:DI 25)]))
945    (clobber (reg:DI 23))
946    (clobber (reg:DI 28))]
947   "!TARGET_OPEN_VMS"
948   "%E1 $24,$25,$27"
949   [(set_attr "type" "jsr")
950    (set_attr "length" "8")])
951 \f
952 ;; Next are the basic logical operations.  These only exist in DImode.
953
954 (define_insn "anddi3"
955   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
956         (and:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ,rJ")
957                 (match_operand:DI 2 "and_operand" "rI,N,MH")))]
958   ""
959   "@
960    and %r1,%2,%0
961    bic %r1,%N2,%0
962    zapnot %r1,%m2,%0"
963   [(set_attr "type" "ilog,ilog,shift")])
964
965 ;; There are times when we can split an AND into two AND insns.  This occurs
966 ;; when we can first clear any bytes and then clear anything else.  For
967 ;; example "I & 0xffff07" is "(I & 0xffffff) & 0xffffffffffffff07".
968 ;; Only do this when running on 64-bit host since the computations are
969 ;; too messy otherwise.
970
971 (define_split
972   [(set (match_operand:DI 0 "register_operand" "")
973         (and:DI (match_operand:DI 1 "register_operand" "")
974                 (match_operand:DI 2 "const_int_operand" "")))]
975   "HOST_BITS_PER_WIDE_INT == 64 && ! and_operand (operands[2], DImode)"
976   [(set (match_dup 0) (and:DI (match_dup 1) (match_dup 3)))
977    (set (match_dup 0) (and:DI (match_dup 0) (match_dup 4)))]
978   "
979 {
980   unsigned HOST_WIDE_INT mask1 = INTVAL (operands[2]);
981   unsigned HOST_WIDE_INT mask2 = mask1;
982   int i;
983
984   /* For each byte that isn't all zeros, make it all ones.  */
985   for (i = 0; i < 64; i += 8)
986     if ((mask1 & ((HOST_WIDE_INT) 0xff << i)) != 0)
987       mask1 |= (HOST_WIDE_INT) 0xff << i;
988
989   /* Now turn on any bits we've just turned off.  */
990   mask2 |= ~ mask1;
991
992   operands[3] = GEN_INT (mask1);
993   operands[4] = GEN_INT (mask2);
994 }")
995
996 (define_insn "zero_extendqihi2"
997   [(set (match_operand:HI 0 "register_operand" "=r")
998         (zero_extend:HI (match_operand:QI 1 "register_operand" "r")))]
999   ""
1000   "and %1,0xff,%0"
1001   [(set_attr "type" "ilog")])
1002
1003 (define_insn ""
1004   [(set (match_operand:SI 0 "register_operand" "=r,r")
1005         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1006   "TARGET_BWX"
1007   "@
1008    and %1,0xff,%0
1009    ldbu %0,%1"
1010   [(set_attr "type" "ilog,ild")])
1011
1012 (define_insn ""
1013   [(set (match_operand:SI 0 "register_operand" "=r")
1014         (zero_extend:SI (match_operand:QI 1 "register_operand" "r")))]
1015   "! TARGET_BWX"
1016   "and %1,0xff,%0"
1017   [(set_attr "type" "ilog")])
1018
1019 (define_expand "zero_extendqisi2"
1020   [(set (match_operand:SI 0 "register_operand" "")
1021         (zero_extend:SI (match_operand:QI 1 "register_operand" "")))]
1022   ""
1023   "")
1024
1025 (define_insn ""
1026   [(set (match_operand:DI 0 "register_operand" "=r,r")
1027         (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1028   "TARGET_BWX"
1029   "@
1030    and %1,0xff,%0
1031    ldbu %0,%1"
1032   [(set_attr "type" "ilog,ild")])
1033
1034 (define_insn ""
1035   [(set (match_operand:DI 0 "register_operand" "=r")
1036         (zero_extend:DI (match_operand:QI 1 "register_operand" "r")))]
1037   "! TARGET_BWX"
1038   "and %1,0xff,%0"
1039   [(set_attr "type" "ilog")])
1040   
1041 (define_expand "zero_extendqidi2"
1042   [(set (match_operand:DI 0 "register_operand" "")
1043         (zero_extend:DI (match_operand:QI 1 "register_operand" "")))]
1044   ""
1045   "")
1046   
1047 (define_insn ""
1048   [(set (match_operand:SI 0 "register_operand" "=r,r")
1049         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
1050   "TARGET_BWX"
1051   "@
1052    zapnot %1,3,%0
1053    ldwu %0,%1"
1054   [(set_attr "type" "shift,ild")])
1055
1056 (define_insn ""
1057   [(set (match_operand:SI 0 "register_operand" "=r")
1058         (zero_extend:SI (match_operand:HI 1 "register_operand" "r")))]
1059   "! TARGET_BWX"
1060   "zapnot %1,3,%0"
1061   [(set_attr "type" "shift")])
1062
1063 (define_expand "zero_extendhisi2"
1064   [(set (match_operand:SI 0 "register_operand" "")
1065         (zero_extend:SI (match_operand:HI 1 "register_operand" "")))]
1066   ""
1067   "")
1068
1069 (define_insn ""
1070   [(set (match_operand:DI 0 "register_operand" "=r,r")
1071         (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
1072   "TARGET_BWX"
1073   "@
1074    zapnot %1,3,%0
1075    ldwu %0,%1"
1076   [(set_attr "type" "shift,ild")])
1077
1078 (define_insn ""
1079   [(set (match_operand:DI 0 "register_operand" "=r")
1080         (zero_extend:DI (match_operand:HI 1 "register_operand" "r")))]
1081   ""
1082   "zapnot %1,3,%0"
1083   [(set_attr "type" "shift")])
1084
1085 (define_expand "zero_extendhidi2"
1086   [(set (match_operand:DI 0 "register_operand" "")
1087         (zero_extend:DI (match_operand:HI 1 "register_operand" "")))]
1088   ""
1089   "")
1090
1091 (define_insn "zero_extendsidi2"
1092   [(set (match_operand:DI 0 "register_operand" "=r")
1093         (zero_extend:DI (match_operand:SI 1 "register_operand" "r")))]
1094   ""
1095   "zapnot %1,15,%0"
1096   [(set_attr "type" "shift")])
1097
1098 (define_insn  ""
1099   [(set (match_operand:DI 0 "register_operand" "=r")
1100         (and:DI (not:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI"))
1101                 (match_operand:DI 2 "reg_or_0_operand" "rJ")))]
1102   ""
1103   "bic %r2,%1,%0"
1104   [(set_attr "type" "ilog")])
1105
1106 (define_insn "iordi3"
1107   [(set (match_operand:DI 0 "register_operand" "=r,r")
1108         (ior:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ")
1109                 (match_operand:DI 2 "or_operand" "rI,N")))]
1110   ""
1111   "@
1112    bis %r1,%2,%0
1113    ornot %r1,%N2,%0"
1114   [(set_attr "type" "ilog")])
1115
1116 (define_insn "one_cmpldi2"
1117   [(set (match_operand:DI 0 "register_operand" "=r")
1118         (not:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI")))]
1119   ""
1120   "ornot $31,%1,%0"
1121   [(set_attr "type" "ilog")])
1122
1123 (define_insn ""
1124   [(set (match_operand:DI 0 "register_operand" "=r")
1125         (ior:DI (not:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI"))
1126                 (match_operand:DI 2 "reg_or_0_operand" "rJ")))]
1127   ""
1128   "ornot %r2,%1,%0"
1129   [(set_attr "type" "ilog")])
1130
1131 (define_insn "xordi3"
1132   [(set (match_operand:DI 0 "register_operand" "=r,r")
1133         (xor:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ")
1134                 (match_operand:DI 2 "or_operand" "rI,N")))]
1135   ""
1136   "@
1137    xor %r1,%2,%0
1138    eqv %r1,%N2,%0"
1139   [(set_attr "type" "ilog")])
1140
1141 (define_insn ""
1142   [(set (match_operand:DI 0 "register_operand" "=r")
1143         (not:DI (xor:DI (match_operand:DI 1 "register_operand" "%rJ")
1144                         (match_operand:DI 2 "register_operand" "rI"))))]
1145   ""
1146   "eqv %r1,%2,%0"
1147   [(set_attr "type" "ilog")])
1148 \f
1149 ;; Handle the FFS insn if we support CIX. 
1150
1151 (define_expand "ffsdi2"
1152   [(set (match_dup 2)
1153         (unspec [(match_operand:DI 1 "register_operand" "")] 1))
1154    (set (match_dup 3)
1155         (plus:DI (match_dup 2) (const_int 1)))
1156    (set (match_operand:DI 0 "register_operand" "")
1157         (if_then_else:DI (eq (match_dup 1) (const_int 0))
1158                          (const_int 0) (match_dup 3)))]
1159   "TARGET_CIX"
1160   "
1161 {
1162   operands[2] = gen_reg_rtx (DImode);
1163   operands[3] = gen_reg_rtx (DImode);
1164 }")
1165
1166 (define_insn ""
1167   [(set (match_operand:DI 0 "register_operand" "=r")
1168         (unspec [(match_operand:DI 1 "register_operand" "r")] 1))]
1169   "TARGET_CIX"
1170   "cttz %1,%0"
1171   ; ev6 calls all mvi and cttz/ctlz/popc class imisc, so just 
1172   ; reuse the existing type name.
1173   [(set_attr "type" "mvi")])
1174 \f
1175 ;; Next come the shifts and the various extract and insert operations.
1176
1177 (define_insn "ashldi3"
1178   [(set (match_operand:DI 0 "register_operand" "=r,r")
1179         (ashift:DI (match_operand:DI 1 "reg_or_0_operand" "rJ,rJ")
1180                    (match_operand:DI 2 "reg_or_6bit_operand" "P,rS")))]
1181   ""
1182   "*
1183 {
1184   switch (which_alternative)
1185     {
1186     case 0:
1187       if (operands[2] == const1_rtx)
1188         return \"addq %r1,%r1,%0\";
1189       else
1190         return \"s%P2addq %r1,0,%0\";
1191     case 1:
1192       return \"sll %r1,%2,%0\";
1193     default:
1194       abort();
1195     }
1196 }"
1197   [(set_attr "type" "iadd,shift")])
1198
1199 ;; ??? The following pattern is made by combine, but earlier phases
1200 ;; (specifically flow) can't handle it.  This occurs in jump.c.  Deal
1201 ;; with this in a better way at some point.
1202 ;;(define_insn ""
1203 ;;  [(set (match_operand:DI 0 "register_operand" "=r")
1204 ;;      (sign_extend:DI
1205 ;;       (subreg:SI (ashift:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1206 ;;                             (match_operand:DI 2 "const_int_operand" "P"))
1207 ;;                  0)))]
1208 ;;  "INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 3"
1209 ;;  "*
1210 ;;{
1211 ;;  if (operands[2] == const1_rtx)
1212 ;;    return \"addl %r1,%r1,%0\";
1213 ;;  else
1214 ;;    return \"s%P2addl %r1,0,%0\";
1215 ;; }"
1216 ;;  [(set_attr "type" "iadd")])
1217                           
1218 (define_insn "lshrdi3"
1219   [(set (match_operand:DI 0 "register_operand" "=r")
1220         (lshiftrt:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1221                      (match_operand:DI 2 "reg_or_6bit_operand" "rS")))]
1222   ""
1223   "srl %r1,%2,%0"
1224   [(set_attr "type" "shift")])
1225
1226 (define_insn "ashrdi3"
1227   [(set (match_operand:DI 0 "register_operand" "=r")
1228         (ashiftrt:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1229                      (match_operand:DI 2 "reg_or_6bit_operand" "rS")))]
1230   ""
1231   "sra %r1,%2,%0"
1232   [(set_attr "type" "shift")])
1233
1234 (define_expand "extendqihi2"
1235   [(set (match_dup 2)
1236         (ashift:DI (match_operand:QI 1 "some_operand" "")
1237                    (const_int 56)))
1238    (set (match_operand:HI 0 "register_operand" "")
1239         (ashiftrt:DI (match_dup 2)
1240                      (const_int 56)))]
1241   ""
1242   "
1243 {
1244   if (TARGET_BWX)
1245     {
1246       emit_insn (gen_extendqihi2x (operands[0],
1247                                    force_reg (QImode, operands[1])));
1248       DONE;
1249     }
1250  
1251  /* If we have an unaligned MEM, extend to DImode (which we do
1252      specially) and then copy to the result.  */
1253   if (unaligned_memory_operand (operands[1], HImode))
1254     {
1255       rtx temp = gen_reg_rtx (DImode);
1256
1257       emit_insn (gen_extendqidi2 (temp, operands[1]));
1258       emit_move_insn (operands[0], gen_lowpart (HImode, temp));
1259       DONE;
1260     }
1261
1262   operands[0] = gen_lowpart (DImode, operands[0]);
1263   operands[1] = gen_lowpart (DImode, force_reg (QImode, operands[1]));
1264   operands[2] = gen_reg_rtx (DImode);
1265 }")
1266
1267 (define_insn "extendqidi2x"
1268   [(set (match_operand:DI 0 "register_operand" "=r")
1269         (sign_extend:DI (match_operand:QI 1 "register_operand" "r")))]
1270   "TARGET_BWX"
1271   "sextb %1,%0"
1272   [(set_attr "type" "shift")])
1273
1274 (define_insn "extendhidi2x"
1275   [(set (match_operand:DI 0 "register_operand" "=r")
1276         (sign_extend:DI (match_operand:HI 1 "register_operand" "r")))]
1277   "TARGET_BWX"
1278   "sextw %1,%0"
1279   [(set_attr "type" "shift")])
1280
1281 (define_insn "extendqisi2x"
1282   [(set (match_operand:SI 0 "register_operand" "=r")
1283         (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
1284   "TARGET_BWX"
1285   "sextb %1,%0"
1286   [(set_attr "type" "shift")])
1287
1288 (define_insn "extendhisi2x"
1289   [(set (match_operand:SI 0 "register_operand" "=r")
1290         (sign_extend:SI (match_operand:HI 1 "register_operand" "r")))]
1291   "TARGET_BWX"
1292   "sextw %1,%0"
1293   [(set_attr "type" "shift")])
1294
1295 (define_insn "extendqihi2x"
1296   [(set (match_operand:HI 0 "register_operand" "=r")
1297         (sign_extend:HI (match_operand:QI 1 "register_operand" "r")))]
1298   "TARGET_BWX"
1299   "sextb %1,%0"
1300   [(set_attr "type" "shift")])
1301
1302 (define_expand "extendqisi2"
1303   [(set (match_dup 2)
1304         (ashift:DI (match_operand:QI 1 "some_operand" "")
1305                    (const_int 56)))
1306    (set (match_operand:SI 0 "register_operand" "")
1307         (ashiftrt:DI (match_dup 2)
1308                      (const_int 56)))]
1309   ""
1310   "
1311 {
1312   if (TARGET_BWX)
1313     {
1314       emit_insn (gen_extendqisi2x (operands[0],
1315                                    force_reg (QImode, operands[1])));
1316       DONE;
1317     }
1318
1319   /* If we have an unaligned MEM, extend to a DImode form of
1320      the result (which we do specially).  */
1321   if (unaligned_memory_operand (operands[1], QImode))
1322     {
1323       rtx temp = gen_reg_rtx (DImode);
1324
1325       emit_insn (gen_extendqidi2 (temp, operands[1]));
1326       emit_move_insn (operands[0], gen_lowpart (SImode, temp));
1327       DONE;
1328     }
1329
1330   operands[0] = gen_lowpart (DImode, operands[0]);
1331   operands[1] = gen_lowpart (DImode, force_reg (QImode, operands[1]));
1332   operands[2] = gen_reg_rtx (DImode);
1333 }")
1334
1335 (define_expand "extendqidi2"
1336   [(set (match_dup 2)
1337         (ashift:DI (match_operand:QI 1 "some_operand" "")
1338                    (const_int 56)))
1339    (set (match_operand:DI 0 "register_operand" "")
1340         (ashiftrt:DI (match_dup 2)
1341                      (const_int 56)))]
1342   ""
1343   "
1344 {
1345   if (TARGET_BWX)
1346     {
1347       emit_insn (gen_extendqidi2x (operands[0],
1348                                    force_reg (QImode, operands[1])));
1349       DONE;
1350     }
1351
1352   if (unaligned_memory_operand (operands[1], QImode))
1353     {
1354       rtx seq
1355         = gen_unaligned_extendqidi (operands[0],
1356                                     get_unaligned_address (operands[1], 1));
1357
1358       alpha_set_memflags (seq, operands[1]);
1359       emit_insn (seq);
1360       DONE;
1361     }
1362
1363   operands[1] = gen_lowpart (DImode, force_reg (QImode, operands[1]));
1364   operands[2] = gen_reg_rtx (DImode);
1365 }")
1366
1367 (define_expand "extendhisi2"
1368   [(set (match_dup 2)
1369         (ashift:DI (match_operand:HI 1 "some_operand" "")
1370                    (const_int 48)))
1371    (set (match_operand:SI 0 "register_operand" "")
1372         (ashiftrt:DI (match_dup 2)
1373                      (const_int 48)))]
1374   ""
1375   "
1376 {
1377   if (TARGET_BWX)
1378     {
1379       emit_insn (gen_extendhisi2x (operands[0],
1380                                    force_reg (HImode, operands[1])));
1381       DONE;
1382     }
1383
1384   /* If we have an unaligned MEM, extend to a DImode form of
1385      the result (which we do specially).  */
1386   if (unaligned_memory_operand (operands[1], HImode))
1387     {
1388       rtx temp = gen_reg_rtx (DImode);
1389
1390       emit_insn (gen_extendhidi2 (temp, operands[1]));
1391       emit_move_insn (operands[0], gen_lowpart (SImode, temp));
1392       DONE;
1393     }
1394
1395   operands[0] = gen_lowpart (DImode, operands[0]);
1396   operands[1] = gen_lowpart (DImode, force_reg (HImode, operands[1]));
1397   operands[2] = gen_reg_rtx (DImode);
1398 }")
1399
1400 (define_expand "extendhidi2"
1401   [(set (match_dup 2)
1402         (ashift:DI (match_operand:HI 1 "some_operand" "")
1403                    (const_int 48)))
1404    (set (match_operand:DI 0 "register_operand" "")
1405         (ashiftrt:DI (match_dup 2)
1406                      (const_int 48)))]
1407   ""
1408   "
1409 {
1410   if (TARGET_BWX)
1411     {
1412       emit_insn (gen_extendhidi2x (operands[0],
1413                                    force_reg (HImode, operands[1])));
1414       DONE;
1415     }
1416
1417   if (unaligned_memory_operand (operands[1], HImode))
1418     {
1419       rtx seq
1420         = gen_unaligned_extendhidi (operands[0],
1421                                     get_unaligned_address (operands[1], 2));
1422
1423       alpha_set_memflags (seq, operands[1]);
1424       emit_insn (seq);
1425       DONE;
1426     }
1427
1428   operands[1] = gen_lowpart (DImode, force_reg (HImode, operands[1]));
1429   operands[2] = gen_reg_rtx (DImode);
1430 }")
1431
1432 ;; Here's how we sign extend an unaligned byte and halfword.  Doing this
1433 ;; as a pattern saves one instruction.  The code is similar to that for
1434 ;; the unaligned loads (see below).
1435 ;;
1436 ;; Operand 1 is the address + 1 (+2 for HI), operand 0 is the result.
1437 (define_expand "unaligned_extendqidi"
1438   [(set (match_dup 2) (match_operand:DI 1 "address_operand" ""))
1439    (set (match_dup 3)
1440         (mem:DI (and:DI (plus:DI (match_dup 2) (const_int -1))
1441                         (const_int -8))))
1442    (set (match_dup 4)
1443         (ashift:DI (match_dup 3)
1444                    (minus:DI (const_int 56)
1445                              (ashift:DI
1446                               (and:DI (plus:DI (match_dup 2) (const_int -1))
1447                                       (const_int 7))
1448                               (const_int 3)))))
1449    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
1450         (ashiftrt:DI (match_dup 4) (const_int 56)))]
1451   ""
1452   "
1453 { operands[2] = gen_reg_rtx (DImode);
1454   operands[3] = gen_reg_rtx (DImode);
1455   operands[4] = gen_reg_rtx (DImode);
1456 }")
1457
1458 (define_expand "unaligned_extendhidi"
1459   [(set (match_dup 2) (match_operand:DI 1 "address_operand" ""))
1460    (set (match_dup 3)
1461         (mem:DI (and:DI (plus:DI (match_dup 2) (const_int -2))
1462                         (const_int -8))))
1463    (set (match_dup 4)
1464         (ashift:DI (match_dup 3)
1465                    (minus:DI (const_int 56)
1466                              (ashift:DI
1467                               (and:DI (plus:DI (match_dup 2) (const_int -1))
1468                                       (const_int 7))
1469                               (const_int 3)))))
1470    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
1471         (ashiftrt:DI (match_dup 4) (const_int 48)))]
1472   ""
1473   "
1474 { operands[2] = gen_reg_rtx (DImode);
1475   operands[3] = gen_reg_rtx (DImode);
1476   operands[4] = gen_reg_rtx (DImode);
1477 }")
1478
1479 (define_insn ""
1480   [(set (match_operand:DI 0 "register_operand" "=r")
1481         (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1482                          (match_operand:DI 2 "mode_width_operand" "n")
1483                          (match_operand:DI 3 "mul8_operand" "I")))]
1484   ""
1485   "ext%M2l %r1,%s3,%0"
1486   [(set_attr "type" "shift")])
1487
1488 (define_insn "extxl"
1489   [(set (match_operand:DI 0 "register_operand" "=r")
1490         (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1491                          (match_operand:DI 2 "mode_width_operand" "n")
1492                          (ashift:DI (match_operand:DI 3 "reg_or_8bit_operand" "rI")
1493                                     (const_int 3))))]
1494   ""
1495   "ext%M2l %r1,%3,%0"
1496   [(set_attr "type" "shift")])
1497
1498 (define_insn "extqh"
1499   [(set (match_operand:DI 0 "register_operand" "=r")
1500         (ashift:DI
1501          (match_operand:DI 1 "reg_or_0_operand" "rJ")
1502           (minus:DI (const_int 56)
1503                     (ashift:DI
1504                      (and:DI
1505                       (plus:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1506                                (const_int -1))
1507                       (const_int 7))
1508                      (const_int 3)))))]
1509   ""
1510   "extqh %r1,%2,%0"
1511   [(set_attr "type" "shift")])
1512
1513 (define_insn "extlh"
1514   [(set (match_operand:DI 0 "register_operand" "=r")
1515         (ashift:DI
1516          (and:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1517                  (const_int 2147483647))
1518          (minus:DI (const_int 56)
1519                     (ashift:DI
1520                      (and:DI
1521                       (plus:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1522                                (const_int -1))
1523                       (const_int 7))
1524                      (const_int 3)))))]
1525   ""
1526   "extlh %r1,%2,%0"
1527   [(set_attr "type" "shift")])
1528
1529 (define_insn "extwh"
1530   [(set (match_operand:DI 0 "register_operand" "=r")
1531         (ashift:DI
1532          (and:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1533                  (const_int 65535))
1534          (minus:DI (const_int 56)
1535                     (ashift:DI
1536                      (and:DI
1537                       (plus:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1538                                (const_int -1))
1539                       (const_int 7))
1540                      (const_int 3)))))]
1541   ""
1542   "extwh %r1,%2,%0"
1543   [(set_attr "type" "shift")])
1544
1545 ;; This converts an extXl into an extXh with an appropriate adjustment
1546 ;; to the address calculation.
1547
1548 ;;(define_split
1549 ;;  [(set (match_operand:DI 0 "register_operand" "")
1550 ;;      (ashift:DI (zero_extract:DI (match_operand:DI 1 "register_operand" "")
1551 ;;                                  (match_operand:DI 2 "mode_width_operand" "")
1552 ;;                                  (ashift:DI (match_operand:DI 3 "" "")
1553 ;;                                             (const_int 3)))
1554 ;;                 (match_operand:DI 4 "const_int_operand" "")))
1555 ;;   (clobber (match_operand:DI 5 "register_operand" ""))]
1556 ;;  "INTVAL (operands[4]) == 64 - INTVAL (operands[2])"
1557 ;;  [(set (match_dup 5) (match_dup 6))
1558 ;;   (set (match_dup 0)
1559 ;;      (ashift:DI (zero_extract:DI (match_dup 1) (match_dup 2)
1560 ;;                                  (ashift:DI (plus:DI (match_dup 5)
1561 ;;                                                      (match_dup 7))
1562 ;;                                             (const_int 3)))
1563 ;;                 (match_dup 4)))]
1564 ;;  "
1565 ;;{
1566 ;;  operands[6] = plus_constant (operands[3], 
1567 ;;                             INTVAL (operands[2]) / BITS_PER_UNIT);
1568 ;;  operands[7] = GEN_INT (- INTVAL (operands[2]) / BITS_PER_UNIT);
1569 ;;}")
1570   
1571 (define_insn ""
1572   [(set (match_operand:DI 0 "register_operand" "=r")
1573         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" "r"))
1574                    (match_operand:DI 2 "mul8_operand" "I")))]
1575   ""
1576   "insbl %1,%s2,%0"
1577   [(set_attr "type" "shift")])
1578
1579 (define_insn ""
1580   [(set (match_operand:DI 0 "register_operand" "=r")
1581         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" "r"))
1582                    (match_operand:DI 2 "mul8_operand" "I")))]
1583   ""
1584   "inswl %1,%s2,%0"
1585   [(set_attr "type" "shift")])
1586
1587 (define_insn ""
1588   [(set (match_operand:DI 0 "register_operand" "=r")
1589         (ashift:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "r"))
1590                    (match_operand:DI 2 "mul8_operand" "I")))]
1591   ""
1592   "insll %1,%s2,%0"
1593   [(set_attr "type" "shift")])
1594
1595 (define_insn "insbl"
1596   [(set (match_operand:DI 0 "register_operand" "=r")
1597         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" "r"))
1598                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1599                               (const_int 3))))]
1600   ""
1601   "insbl %1,%2,%0"
1602   [(set_attr "type" "shift")])
1603
1604 (define_insn "inswl"
1605   [(set (match_operand:DI 0 "register_operand" "=r")
1606         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" "r"))
1607                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1608                               (const_int 3))))]
1609   ""
1610   "inswl %1,%2,%0"
1611   [(set_attr "type" "shift")])
1612
1613 (define_insn "insll"
1614   [(set (match_operand:DI 0 "register_operand" "=r")
1615         (ashift:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "r"))
1616                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1617                               (const_int 3))))]
1618   ""
1619   "insll %1,%2,%0"
1620   [(set_attr "type" "shift")])
1621
1622 (define_insn "insql"
1623   [(set (match_operand:DI 0 "register_operand" "=r")
1624         (ashift:DI (match_operand:DI 1 "register_operand" "r")
1625                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1626                               (const_int 3))))]
1627   ""
1628   "insql %1,%2,%0"
1629   [(set_attr "type" "shift")])
1630
1631 ;; Combine has this sometimes habit of moving the and outside of the
1632 ;; shift, making life more interesting.
1633
1634 (define_insn ""
1635   [(set (match_operand:DI 0 "register_operand" "=r")
1636         (and:DI (ashift:DI (match_operand:DI 1 "register_operand" "r")
1637                            (match_operand:DI 2 "mul8_operand" "I"))
1638                 (match_operand:DI 3 "immediate_operand" "i")))]
1639   "HOST_BITS_PER_WIDE_INT == 64
1640    && GET_CODE (operands[3]) == CONST_INT
1641    && (((unsigned HOST_WIDE_INT) 0xff << INTVAL (operands[2])
1642         == INTVAL (operands[3]))
1643        || ((unsigned HOST_WIDE_INT) 0xffff << INTVAL (operands[2])
1644         == INTVAL (operands[3]))
1645        || ((unsigned HOST_WIDE_INT) 0xffffffff << INTVAL (operands[2])
1646         == INTVAL (operands[3])))"
1647   "*
1648 {
1649 #if HOST_BITS_PER_WIDE_INT == 64
1650   if ((unsigned HOST_WIDE_INT) 0xff << INTVAL (operands[2])
1651       == INTVAL (operands[3]))
1652     return \"insbl %1,%s2,%0\";
1653   if ((unsigned HOST_WIDE_INT) 0xffff << INTVAL (operands[2])
1654       == INTVAL (operands[3]))
1655     return \"inswl %1,%s2,%0\";
1656   if ((unsigned HOST_WIDE_INT) 0xffffffff << INTVAL (operands[2])
1657       == INTVAL (operands[3]))
1658     return \"insll %1,%s2,%0\";
1659 #endif
1660   abort();
1661 }"
1662   [(set_attr "type" "shift")])
1663
1664 ;; We do not include the insXh insns because they are complex to express
1665 ;; and it does not appear that we would ever want to generate them.
1666 ;;
1667 ;; Since we need them for block moves, though, cop out and use unspec.
1668
1669 (define_insn "insxh"
1670   [(set (match_operand:DI 0 "register_operand" "=r")
1671         (unspec [(match_operand:DI 1 "register_operand" "r")
1672                  (match_operand:DI 2 "mode_width_operand" "n")
1673                  (match_operand:DI 3 "reg_or_8bit_operand" "rI")] 2))]
1674   ""
1675   "ins%M2h %1,%3,%0"
1676   [(set_attr "type" "shift")])
1677
1678 (define_insn "mskxl"
1679   [(set (match_operand:DI 0 "register_operand" "=r")
1680         (and:DI (not:DI (ashift:DI
1681                          (match_operand:DI 2 "mode_mask_operand" "n")
1682                          (ashift:DI
1683                           (match_operand:DI 3 "reg_or_8bit_operand" "rI")
1684                           (const_int 3))))
1685                 (match_operand:DI 1 "reg_or_0_operand" "rJ")))]
1686   ""
1687   "msk%U2l %r1,%3,%0"
1688   [(set_attr "type" "shift")])
1689
1690 ;; We do not include the mskXh insns because it does not appear we would
1691 ;; ever generate one.
1692 ;;
1693 ;; Again, we do for block moves and we use unspec again.
1694
1695 (define_insn "mskxh"
1696   [(set (match_operand:DI 0 "register_operand" "=r")
1697         (unspec [(match_operand:DI 1 "register_operand" "r")
1698                  (match_operand:DI 2 "mode_width_operand" "n")
1699                  (match_operand:DI 3 "reg_or_8bit_operand" "rI")] 3))]
1700   ""
1701   "msk%M2h %1,%3,%0"
1702   [(set_attr "type" "shift")])
1703 \f
1704 ;; Floating-point operations.  All the double-precision insns can extend
1705 ;; from single, so indicate that.  The exception are the ones that simply
1706 ;; play with the sign bits; it's not clear what to do there.
1707
1708 (define_insn "abssf2"
1709   [(set (match_operand:SF 0 "register_operand" "=f")
1710         (abs:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")))]
1711   "TARGET_FP"
1712   "cpys $f31,%R1,%0"
1713   [(set_attr "type" "fcpys")])
1714
1715 (define_insn "absdf2"
1716   [(set (match_operand:DF 0 "register_operand" "=f")
1717         (abs:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
1718   "TARGET_FP"
1719   "cpys $f31,%R1,%0"
1720   [(set_attr "type" "fcpys")])
1721
1722 (define_insn "negsf2"
1723   [(set (match_operand:SF 0 "register_operand" "=f")
1724         (neg:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")))]
1725   "TARGET_FP"
1726   "cpysn %R1,%R1,%0"
1727   [(set_attr "type" "fadd")])
1728
1729 (define_insn "negdf2"
1730   [(set (match_operand:DF 0 "register_operand" "=f")
1731         (neg:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
1732   "TARGET_FP"
1733   "cpysn %R1,%R1,%0"
1734   [(set_attr "type" "fadd")])
1735
1736 (define_insn ""
1737   [(set (match_operand:SF 0 "register_operand" "=&f")
1738         (plus:SF (match_operand:SF 1 "reg_or_fp0_operand" "%fG")
1739                  (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
1740   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
1741   "add%,%)%& %R1,%R2,%0"
1742   [(set_attr "type" "fadd")
1743    (set_attr "trap" "yes")])
1744
1745 (define_insn "addsf3"
1746   [(set (match_operand:SF 0 "register_operand" "=f")
1747         (plus:SF (match_operand:SF 1 "reg_or_fp0_operand" "%fG")
1748                  (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
1749   "TARGET_FP"
1750   "add%,%)%& %R1,%R2,%0"
1751   [(set_attr "type" "fadd")
1752    (set_attr "trap" "yes")])
1753
1754 (define_insn ""
1755   [(set (match_operand:DF 0 "register_operand" "=&f")
1756         (plus:DF (match_operand:DF 1 "reg_or_fp0_operand" "%fG")
1757                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
1758   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
1759   "add%-%)%& %R1,%R2,%0"
1760   [(set_attr "type" "fadd")
1761    (set_attr "trap" "yes")])
1762
1763 (define_insn "adddf3"
1764   [(set (match_operand:DF 0 "register_operand" "=f")
1765         (plus:DF (match_operand:DF 1 "reg_or_fp0_operand" "%fG")
1766                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
1767   "TARGET_FP"
1768   "add%-%)%& %R1,%R2,%0"
1769   [(set_attr "type" "fadd")
1770    (set_attr "trap" "yes")])
1771
1772 (define_insn ""
1773   [(set (match_operand:DF 0 "register_operand" "=f")
1774         (plus:DF (float_extend:DF
1775                   (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
1776                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
1777   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
1778   "add%-%)%& %R1,%R2,%0"
1779   [(set_attr "type" "fadd")
1780    (set_attr "trap" "yes")])
1781
1782 (define_insn ""
1783   [(set (match_operand:DF 0 "register_operand" "=f")
1784         (plus:DF (float_extend:DF
1785                   (match_operand:SF 1 "reg_or_fp0_operand" "%fG"))
1786                  (float_extend:DF
1787                   (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
1788   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
1789   "add%-%)%& %R1,%R2,%0"
1790   [(set_attr "type" "fadd")
1791    (set_attr "trap" "yes")])
1792
1793 ;; Define conversion operators between DFmode and SImode, using the cvtql
1794 ;; instruction.  To allow combine et al to do useful things, we keep the
1795 ;; operation as a unit until after reload, at which point we split the
1796 ;; instructions.
1797 ;;
1798 ;; Note that we (attempt to) only consider this optimization when the
1799 ;; ultimate destination is memory.  If we will be doing further integer
1800 ;; processing, it is cheaper to do the truncation in the int regs.
1801
1802 (define_insn "*cvtql"
1803   [(set (match_operand:SI 0 "register_operand" "=f")
1804         (unspec:SI [(match_operand:DI 1 "reg_or_fp0_operand" "fG")] 5))]
1805   "TARGET_FP"
1806   "cvtql%` %R1,%0"
1807   [(set_attr "type" "fadd")
1808    (set_attr "trap" "yes")])
1809
1810 (define_split
1811   [(set (match_operand:SI 0 "memory_operand" "")
1812         (subreg:SI (fix:DI (match_operand:DF 1 "reg_or_fp0_operand" "")) 0))
1813    (clobber (match_scratch:DI 2 ""))
1814    (clobber (match_scratch:SI 3 ""))]
1815   "TARGET_FP && reload_completed"
1816   [(set (match_dup 2) (fix:DI (match_dup 1)))
1817    (set (match_dup 3) (unspec:SI [(match_dup 2)] 5))
1818    (set (match_dup 0) (match_dup 3))]
1819   "")
1820
1821 (define_split
1822   [(set (match_operand:SI 0 "memory_operand" "")
1823         (subreg:SI (fix:DI (match_operand:DF 1 "reg_or_fp0_operand" "")) 0))
1824    (clobber (match_scratch:DI 2 ""))]
1825   "TARGET_FP && reload_completed"
1826   [(set (match_dup 2) (fix:DI (match_dup 1)))
1827    (set (match_dup 3) (unspec:SI [(match_dup 2)] 5))
1828    (set (match_dup 0) (match_dup 3))]
1829   ;; Due to REG_CANNOT_CHANGE_SIZE issues, we cannot simply use SUBREG.
1830   "operands[3] = gen_rtx_REG (SImode, REGNO (operands[2]));")
1831
1832 (define_insn ""
1833   [(set (match_operand:SI 0 "memory_operand" "=m")
1834         (subreg:SI (fix:DI (match_operand:DF 1 "reg_or_fp0_operand" "fG")) 0))
1835    (clobber (match_scratch:DI 2 "=&f"))
1836    (clobber (match_scratch:SI 3 "=&f"))]
1837   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
1838   "#"
1839   [(set_attr "type" "fadd")
1840    (set_attr "trap" "yes")])
1841
1842 (define_insn ""
1843   [(set (match_operand:SI 0 "memory_operand" "=m")
1844         (subreg:SI (fix:DI (match_operand:DF 1 "reg_or_fp0_operand" "fG")) 0))
1845    (clobber (match_scratch:DI 2 "=f"))]
1846   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
1847   "#"
1848   [(set_attr "type" "fadd")
1849    (set_attr "trap" "yes")])
1850
1851 (define_insn ""
1852   [(set (match_operand:DI 0 "register_operand" "=&f")
1853         (fix:DI (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
1854   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
1855   "cvt%-q%(c %R1,%0"
1856   [(set_attr "type" "fadd")
1857    (set_attr "trap" "yes")])
1858
1859 (define_insn "fix_truncdfdi2"
1860   [(set (match_operand:DI 0 "register_operand" "=f")
1861         (fix:DI (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
1862   "TARGET_FP"
1863   "cvt%-q%(c %R1,%0"
1864   [(set_attr "type" "fadd")
1865    (set_attr "trap" "yes")])
1866
1867 ;; Likewise between SFmode and SImode.
1868
1869 (define_split
1870   [(set (match_operand:SI 0 "memory_operand" "")
1871         (subreg:SI (fix:DI (float_extend:DF
1872                  (match_operand:SF 1 "reg_or_fp0_operand" ""))) 0))
1873    (clobber (match_scratch:DI 2 ""))
1874    (clobber (match_scratch:SI 3 ""))]
1875   "TARGET_FP && reload_completed"
1876   [(set (match_dup 2) (fix:DI (float_extend:DF (match_dup 1))))
1877    (set (match_dup 3) (unspec:SI [(match_dup 2)] 5))
1878    (set (match_dup 0) (match_dup 3))]
1879   "")
1880
1881 (define_split
1882   [(set (match_operand:SI 0 "memory_operand" "")
1883         (subreg:SI (fix:DI (float_extend:DF
1884                  (match_operand:SF 1 "reg_or_fp0_operand" ""))) 0))
1885    (clobber (match_scratch:DI 2 ""))]
1886   "TARGET_FP && reload_completed"
1887   [(set (match_dup 2) (fix:DI (float_extend:DF (match_dup 1))))
1888    (set (match_dup 3) (unspec:SI [(match_dup 2)] 5))
1889    (set (match_dup 0) (match_dup 3))]
1890   ;; Due to REG_CANNOT_CHANGE_SIZE issues, we cannot simply use SUBREG.
1891   "operands[3] = gen_rtx_REG (SImode, REGNO (operands[2]));")
1892
1893 (define_insn ""
1894   [(set (match_operand:SI 0 "memory_operand" "=m")
1895         (subreg:SI (fix:DI (float_extend:DF
1896                  (match_operand:SF 1 "reg_or_fp0_operand" "fG"))) 0))
1897    (clobber (match_scratch:DI 2 "=&f"))
1898    (clobber (match_scratch:SI 3 "=&f"))]
1899   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
1900   "#"
1901   [(set_attr "type" "fadd")
1902    (set_attr "trap" "yes")])
1903
1904 (define_insn ""
1905   [(set (match_operand:SI 0 "memory_operand" "=m")
1906         (subreg:SI (fix:DI (float_extend:DF
1907                  (match_operand:SF 1 "reg_or_fp0_operand" "fG"))) 0))
1908    (clobber (match_scratch:DI 2 "=f"))]
1909   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
1910   "#"
1911   [(set_attr "type" "fadd")
1912    (set_attr "trap" "yes")])
1913
1914 (define_insn ""
1915   [(set (match_operand:DI 0 "register_operand" "=&f")
1916         (fix:DI (float_extend:DF
1917                  (match_operand:SF 1 "reg_or_fp0_operand" "fG"))))]
1918   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
1919   "cvt%-q%(c %R1,%0"
1920   [(set_attr "type" "fadd")
1921    (set_attr "trap" "yes")])
1922
1923 (define_insn "fix_truncsfdi2"
1924   [(set (match_operand:DI 0 "register_operand" "=f")
1925         (fix:DI (float_extend:DF
1926                  (match_operand:SF 1 "reg_or_fp0_operand" "fG"))))]
1927   "TARGET_FP"
1928   "cvt%-q%(c %R1,%0"
1929   [(set_attr "type" "fadd")
1930    (set_attr "trap" "yes")])
1931
1932 (define_insn ""
1933   [(set (match_operand:SF 0 "register_operand" "=&f")
1934         (float:SF (match_operand:DI 1 "register_operand" "f")))]
1935   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
1936   "cvtq%,%+%& %1,%0"
1937   [(set_attr "type" "fadd")
1938    (set_attr "trap" "yes")])
1939
1940 (define_insn "floatdisf2"
1941   [(set (match_operand:SF 0 "register_operand" "=f")
1942         (float:SF (match_operand:DI 1 "register_operand" "f")))]
1943   "TARGET_FP"
1944   "cvtq%,%+%& %1,%0"
1945   [(set_attr "type" "fadd")
1946    (set_attr "trap" "yes")])
1947
1948 (define_insn ""
1949   [(set (match_operand:DF 0 "register_operand" "=&f")
1950         (float:DF (match_operand:DI 1 "register_operand" "f")))]
1951   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
1952   "cvtq%-%+%& %1,%0"
1953   [(set_attr "type" "fadd")
1954    (set_attr "trap" "yes")])
1955
1956 (define_insn "floatdidf2"
1957   [(set (match_operand:DF 0 "register_operand" "=f")
1958         (float:DF (match_operand:DI 1 "register_operand" "f")))]
1959   "TARGET_FP"
1960   "cvtq%-%+%& %1,%0"
1961   [(set_attr "type" "fadd")
1962    (set_attr "trap" "yes")])
1963
1964 (define_expand "extendsfdf2"
1965   [(use (match_operand:DF 0 "register_operand" ""))
1966    (use (match_operand:SF 1 "nonimmediate_operand" ""))]
1967   "TARGET_FP"
1968 "
1969 {
1970   if (alpha_tp == ALPHA_TP_INSN)
1971     emit_insn (gen_extendsfdf2_tp (operands[0],
1972                                    force_reg (SFmode, operands[1])));
1973   else
1974     emit_insn (gen_extendsfdf2_no_tp (operands[0], operands[1]));
1975
1976   DONE;
1977 }")
1978 ;; FIXME
1979 (define_insn "extendsfdf2_tp"
1980   [(set (match_operand:DF 0 "register_operand" "=&f")
1981         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
1982   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
1983   "cvtsts %1,%0"
1984   [(set_attr "type" "fadd")
1985    (set_attr "trap" "yes")])
1986
1987 (define_insn "extendsfdf2_no_tp"
1988   [(set (match_operand:DF 0 "register_operand" "=f,f,m")
1989         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "f,m,f")))]
1990   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
1991   "@
1992    cpys %1,%1,%0
1993    ld%, %0,%1
1994    st%- %1,%0"
1995   [(set_attr "type" "fcpys,fld,fst")
1996    (set_attr "trap" "yes")])
1997
1998 (define_insn ""
1999   [(set (match_operand:SF 0 "register_operand" "=&f")
2000         (float_truncate:SF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
2001   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2002   "cvt%-%,%)%& %R1,%0"
2003   [(set_attr "type" "fadd")
2004    (set_attr "trap" "yes")])
2005
2006 (define_insn "truncdfsf2"
2007   [(set (match_operand:SF 0 "register_operand" "=f")
2008         (float_truncate:SF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
2009   "TARGET_FP"
2010   "cvt%-%,%)%& %R1,%0"
2011   [(set_attr "type" "fadd")
2012    (set_attr "trap" "yes")])
2013
2014 (define_insn ""
2015   [(set (match_operand:SF 0 "register_operand" "=&f")
2016         (div:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")
2017                 (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2018   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2019   "div%,%)%& %R1,%R2,%0"
2020   [(set_attr "type" "fdiv")
2021    (set_attr "opsize" "si")
2022    (set_attr "trap" "yes")])
2023
2024 (define_insn "divsf3"
2025   [(set (match_operand:SF 0 "register_operand" "=f")
2026         (div:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")
2027                 (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2028   "TARGET_FP"
2029   "div%,%)%& %R1,%R2,%0"
2030   [(set_attr "type" "fdiv")
2031    (set_attr "opsize" "si")
2032    (set_attr "trap" "yes")])
2033
2034 (define_insn ""
2035   [(set (match_operand:DF 0 "register_operand" "=&f")
2036         (div:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
2037                 (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2038   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2039   "div%-%)%& %R1,%R2,%0"
2040   [(set_attr "type" "fdiv")
2041    (set_attr "trap" "yes")])
2042
2043 (define_insn "divdf3"
2044   [(set (match_operand:DF 0 "register_operand" "=f")
2045         (div:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
2046                 (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2047   "TARGET_FP"
2048   "div%-%)%& %R1,%R2,%0"
2049   [(set_attr "type" "fdiv")
2050    (set_attr "trap" "yes")])
2051
2052 (define_insn ""
2053   [(set (match_operand:DF 0 "register_operand" "=f")
2054         (div:DF (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
2055                 (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2056   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2057   "div%-%)%& %R1,%R2,%0"
2058   [(set_attr "type" "fdiv")
2059    (set_attr "trap" "yes")])
2060
2061 (define_insn ""
2062   [(set (match_operand:DF 0 "register_operand" "=f")
2063         (div:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
2064                 (float_extend:DF
2065                  (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
2066   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2067   "div%-%)%& %R1,%R2,%0"
2068   [(set_attr "type" "fdiv")
2069    (set_attr "trap" "yes")])
2070
2071 (define_insn ""
2072   [(set (match_operand:DF 0 "register_operand" "=f")
2073         (div:DF (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
2074                 (float_extend:DF (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
2075   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2076   "div%-%)%& %R1,%R2,%0"
2077   [(set_attr "type" "fdiv")
2078    (set_attr "trap" "yes")])
2079
2080 (define_insn ""
2081   [(set (match_operand:SF 0 "register_operand" "=&f")
2082         (mult:SF (match_operand:SF 1 "reg_or_fp0_operand" "%fG")
2083                  (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2084   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2085   "mul%,%)%& %R1,%R2,%0"
2086   [(set_attr "type" "fmul")
2087    (set_attr "trap" "yes")])
2088
2089 (define_insn "mulsf3"
2090   [(set (match_operand:SF 0 "register_operand" "=f")
2091         (mult:SF (match_operand:SF 1 "reg_or_fp0_operand" "%fG")
2092                  (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2093   "TARGET_FP"
2094   "mul%,%)%& %R1,%R2,%0"
2095   [(set_attr "type" "fmul")
2096    (set_attr "trap" "yes")])
2097
2098 (define_insn ""
2099   [(set (match_operand:DF 0 "register_operand" "=&f")
2100         (mult:DF (match_operand:DF 1 "reg_or_fp0_operand" "%fG")
2101                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2102   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2103   "mul%-%)%& %R1,%R2,%0"
2104   [(set_attr "type" "fmul")
2105    (set_attr "trap" "yes")])
2106
2107 (define_insn "muldf3"
2108   [(set (match_operand:DF 0 "register_operand" "=f")
2109         (mult:DF (match_operand:DF 1 "reg_or_fp0_operand" "%fG")
2110                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2111   "TARGET_FP"
2112   "mul%-%)%& %R1,%R2,%0"
2113   [(set_attr "type" "fmul")
2114    (set_attr "trap" "yes")])
2115
2116 (define_insn ""
2117   [(set (match_operand:DF 0 "register_operand" "=f")
2118         (mult:DF (float_extend:DF
2119                   (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
2120                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2121   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2122   "mul%-%)%& %R1,%R2,%0"
2123   [(set_attr "type" "fmul")
2124    (set_attr "trap" "yes")])
2125
2126 (define_insn ""
2127   [(set (match_operand:DF 0 "register_operand" "=f")
2128         (mult:DF (float_extend:DF
2129                   (match_operand:SF 1 "reg_or_fp0_operand" "%fG"))
2130                  (float_extend:DF
2131                   (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
2132   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2133   "mul%-%)%& %R1,%R2,%0"
2134   [(set_attr "type" "fmul")
2135    (set_attr "trap" "yes")])
2136
2137 (define_insn ""
2138   [(set (match_operand:SF 0 "register_operand" "=&f")
2139         (minus:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")
2140                   (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2141   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2142   "sub%,%)%& %R1,%R2,%0"
2143   [(set_attr "type" "fadd")
2144    (set_attr "trap" "yes")])
2145
2146 (define_insn "subsf3"
2147   [(set (match_operand:SF 0 "register_operand" "=f")
2148         (minus:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")
2149                   (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2150   "TARGET_FP"
2151   "sub%,%)%& %R1,%R2,%0"
2152   [(set_attr "type" "fadd")
2153    (set_attr "trap" "yes")])
2154
2155 (define_insn ""
2156   [(set (match_operand:DF 0 "register_operand" "=&f")
2157         (minus:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
2158                   (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2159   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2160   "sub%-%)%& %R1,%R2,%0"
2161   [(set_attr "type" "fadd")
2162    (set_attr "trap" "yes")])
2163
2164 (define_insn "subdf3"
2165   [(set (match_operand:DF 0 "register_operand" "=f")
2166         (minus:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
2167                   (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2168   "TARGET_FP"
2169   "sub%-%)%& %R1,%R2,%0"
2170   [(set_attr "type" "fadd")
2171    (set_attr "trap" "yes")])
2172
2173 (define_insn ""
2174   [(set (match_operand:DF 0 "register_operand" "=f")
2175         (minus:DF (float_extend:DF
2176                    (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
2177                   (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2178   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2179   "sub%-%)%& %R1,%R2,%0"
2180   [(set_attr "type" "fadd")
2181    (set_attr "trap" "yes")])
2182
2183 (define_insn ""
2184   [(set (match_operand:DF 0 "register_operand" "=f")
2185         (minus:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
2186                   (float_extend:DF
2187                    (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
2188   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2189   "sub%-%)%& %R1,%R2,%0"
2190   [(set_attr "type" "fadd")
2191    (set_attr "trap" "yes")])
2192
2193 (define_insn ""
2194   [(set (match_operand:DF 0 "register_operand" "=f")
2195         (minus:DF (float_extend:DF
2196                    (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
2197                   (float_extend:DF
2198                    (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
2199   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2200   "sub%-%)%& %R1,%R2,%0"
2201   [(set_attr "type" "fadd")
2202    (set_attr "trap" "yes")])
2203
2204 (define_insn ""
2205   [(set (match_operand:SF 0 "register_operand" "=&f")
2206         (sqrt:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")))]
2207   "TARGET_FP && TARGET_CIX && alpha_tp == ALPHA_TP_INSN"
2208   "sqrt%,%)%& %R1,%0"
2209   [(set_attr "type" "fsqrt")
2210    (set_attr "opsize" "si")
2211    (set_attr "trap" "yes")])
2212
2213 (define_insn "sqrtsf2"
2214   [(set (match_operand:SF 0 "register_operand" "=f")
2215         (sqrt:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")))]
2216   "TARGET_FP && TARGET_CIX"
2217   "sqrt%,%)%& %R1,%0"
2218   [(set_attr "type" "fsqrt")
2219    (set_attr "opsize" "si")
2220    (set_attr "trap" "yes")])
2221
2222 (define_insn ""
2223   [(set (match_operand:DF 0 "register_operand" "=&f")
2224         (sqrt:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
2225   "TARGET_FP && TARGET_CIX && alpha_tp == ALPHA_TP_INSN"
2226   "sqrt%-%)%& %R1,%0"
2227   [(set_attr "type" "fsqrt")
2228    (set_attr "trap" "yes")])
2229
2230 (define_insn "sqrtdf2"
2231   [(set (match_operand:DF 0 "register_operand" "=f")
2232         (sqrt:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
2233   "TARGET_FP && TARGET_CIX"
2234   "sqrt%-%)%& %1,%0"
2235   [(set_attr "type" "fsqrt")
2236    (set_attr "trap" "yes")])
2237 \f
2238 ;; Next are all the integer comparisons, and conditional moves and branches
2239 ;; and some of the related define_expand's and define_split's.
2240
2241 (define_insn ""
2242   [(set (match_operand:DI 0 "register_operand" "=r")
2243         (match_operator:DI 1 "alpha_comparison_operator"
2244                            [(match_operand:DI 2 "reg_or_0_operand" "rJ")
2245                             (match_operand:DI 3 "reg_or_8bit_operand" "rI")]))]
2246   ""
2247   "cmp%C1 %r2,%3,%0"
2248   [(set_attr "type" "icmp")])
2249
2250 (define_insn ""
2251   [(set (match_operand:DI 0 "register_operand" "=r")
2252         (match_operator:DI 1 "alpha_swapped_comparison_operator"
2253                            [(match_operand:DI 2 "reg_or_8bit_operand" "rI")
2254                             (match_operand:DI 3 "reg_or_0_operand" "rJ")]))]
2255   ""
2256   "cmp%c1 %r3,%2,%0"
2257   [(set_attr "type" "icmp")])
2258
2259 ;; This pattern exists so conditional moves of SImode values are handled.
2260 ;; Comparisons are still done in DImode though.
2261
2262 (define_insn ""
2263   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
2264         (if_then_else:DI
2265          (match_operator 2 "signed_comparison_operator"
2266                          [(match_operand:DI 3 "reg_or_0_operand" "rJ,rJ,J,J")
2267                           (match_operand:DI 4 "reg_or_0_operand" "J,J,rJ,rJ")])
2268          (match_operand:SI 1 "reg_or_8bit_operand" "rI,0,rI,0")
2269          (match_operand:SI 5 "reg_or_8bit_operand" "0,rI,0,rI")))]
2270   "operands[3] == const0_rtx || operands[4] == const0_rtx"
2271   "@
2272    cmov%C2 %r3,%1,%0
2273    cmov%D2 %r3,%5,%0
2274    cmov%c2 %r4,%1,%0
2275    cmov%d2 %r4,%5,%0"
2276   [(set_attr "type" "icmov")])
2277
2278 (define_insn ""
2279   [(set (match_operand:DI 0 "register_operand" "=r,r,r,r")
2280         (if_then_else:DI
2281          (match_operator 2 "signed_comparison_operator"
2282                          [(match_operand:DI 3 "reg_or_0_operand" "rJ,rJ,J,J")
2283                           (match_operand:DI 4 "reg_or_0_operand" "J,J,rJ,rJ")])
2284          (match_operand:DI 1 "reg_or_8bit_operand" "rI,0,rI,0")
2285          (match_operand:DI 5 "reg_or_8bit_operand" "0,rI,0,rI")))]
2286   "operands[3] == const0_rtx || operands[4] == const0_rtx"
2287   "@
2288    cmov%C2 %r3,%1,%0
2289    cmov%D2 %r3,%5,%0
2290    cmov%c2 %r4,%1,%0
2291    cmov%d2 %r4,%5,%0"
2292   [(set_attr "type" "icmov")])
2293
2294 (define_insn ""
2295   [(set (match_operand:DI 0 "register_operand" "=r,r")
2296         (if_then_else:DI
2297          (eq (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
2298                               (const_int 1)
2299                               (const_int 0))
2300              (const_int 0))
2301          (match_operand:DI 1 "reg_or_8bit_operand" "rI,0")
2302          (match_operand:DI 3 "reg_or_8bit_operand" "0,rI")))]
2303   ""
2304   "@
2305    cmovlbc %r2,%1,%0
2306    cmovlbs %r2,%3,%0"
2307   [(set_attr "type" "icmov")])
2308
2309 (define_insn ""
2310   [(set (match_operand:DI 0 "register_operand" "=r,r")
2311         (if_then_else:DI
2312          (ne (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
2313                               (const_int 1)
2314                               (const_int 0))
2315              (const_int 0))
2316          (match_operand:DI 1 "reg_or_8bit_operand" "rI,0")
2317          (match_operand:DI 3 "reg_or_8bit_operand" "0,rI")))]
2318   ""
2319   "@
2320    cmovlbs %r2,%1,%0
2321    cmovlbc %r2,%3,%0"
2322   [(set_attr "type" "icmov")])
2323
2324 ;; This form is added since combine thinks that an IF_THEN_ELSE with both
2325 ;; arms constant is a single insn, so it won't try to form it if combine
2326 ;; knows they are really two insns.  This occurs in divides by powers
2327 ;; of two.
2328
2329 (define_insn ""
2330   [(set (match_operand:DI 0 "register_operand" "=r")
2331         (if_then_else:DI
2332          (match_operator 2 "signed_comparison_operator"
2333                          [(match_operand:DI 3 "reg_or_0_operand" "rJ")
2334                           (const_int 0)])
2335          (plus:DI (match_dup 0)
2336                   (match_operand:DI 1 "reg_or_8bit_operand" "rI"))
2337          (match_dup 0)))
2338    (clobber (match_scratch:DI 4 "=&r"))]
2339   ""
2340   "addq %0,%1,%4\;cmov%C2 %r3,%4,%0"
2341   [(set_attr "type" "icmov")
2342    (set_attr "length" "8")])
2343
2344 (define_split
2345   [(set (match_operand:DI 0 "register_operand" "")
2346         (if_then_else:DI
2347          (match_operator 2 "signed_comparison_operator"
2348                          [(match_operand:DI 3 "reg_or_0_operand" "")
2349                           (const_int 0)])
2350          (plus:DI (match_dup 0)
2351                   (match_operand:DI 1 "reg_or_8bit_operand" ""))
2352          (match_dup 0)))
2353    (clobber (match_operand:DI 4 "register_operand" ""))]
2354   ""
2355   [(set (match_dup 4) (plus:DI (match_dup 0) (match_dup 1)))
2356    (set (match_dup 0) (if_then_else:DI (match_op_dup 2
2357                                                      [(match_dup 3)
2358                                                       (const_int 0)])
2359                                        (match_dup 4) (match_dup 0)))]
2360   "")
2361
2362 (define_split
2363   [(parallel
2364     [(set (match_operand:DI 0 "register_operand" "")
2365           (if_then_else:DI
2366            (match_operator 1 "comparison_operator"
2367                            [(zero_extract:DI (match_operand:DI 2 "register_operand" "")
2368                                              (const_int 1)
2369                                              (match_operand:DI 3 "const_int_operand" ""))
2370                             (const_int 0)])
2371            (match_operand:DI 4 "reg_or_8bit_operand" "")
2372            (match_operand:DI 5 "reg_or_8bit_operand" "")))
2373      (clobber (match_operand:DI 6 "register_operand" ""))])]
2374   "INTVAL (operands[3]) != 0"
2375   [(set (match_dup 6)
2376         (lshiftrt:DI (match_dup 2) (match_dup 3)))
2377    (set (match_dup 0)
2378         (if_then_else:DI (match_op_dup 1
2379                                        [(zero_extract:DI (match_dup 6)
2380                                                          (const_int 1)
2381                                                          (const_int 0))
2382                                         (const_int 0)])
2383                          (match_dup 4)
2384                          (match_dup 5)))]
2385   "")
2386
2387 ;; For ABS, we have two choices, depending on whether the input and output
2388 ;; registers are the same or not.
2389 (define_expand "absdi2"
2390   [(set (match_operand:DI 0 "register_operand" "")
2391         (abs:DI (match_operand:DI 1 "register_operand" "")))]
2392   ""
2393   "
2394 { if (rtx_equal_p (operands[0], operands[1]))
2395     emit_insn (gen_absdi2_same (operands[0], gen_reg_rtx (DImode)));
2396   else
2397     emit_insn (gen_absdi2_diff (operands[0], operands[1]));
2398
2399   DONE;
2400 }")
2401
2402 (define_expand "absdi2_same"
2403   [(set (match_operand:DI 1 "register_operand" "")
2404         (neg:DI (match_operand:DI 0 "register_operand" "")))
2405    (set (match_dup 0)
2406         (if_then_else:DI (ge (match_dup 0) (const_int 0))
2407                          (match_dup 0)
2408                          (match_dup 1)))]
2409   ""
2410   "")
2411
2412 (define_expand "absdi2_diff"
2413   [(set (match_operand:DI 0 "register_operand" "")
2414         (neg:DI (match_operand:DI 1 "register_operand" "")))
2415    (set (match_dup 0)
2416         (if_then_else:DI (lt (match_dup 1) (const_int 0))
2417                          (match_dup 0)
2418                          (match_dup 1)))]
2419   ""
2420   "")
2421
2422 (define_split
2423   [(set (match_operand:DI 0 "register_operand" "")
2424         (abs:DI (match_dup 0)))
2425    (clobber (match_operand:DI 2 "register_operand" ""))]
2426   ""
2427   [(set (match_dup 1) (neg:DI (match_dup 0)))
2428    (set (match_dup 0) (if_then_else:DI (ge (match_dup 0) (const_int 0))
2429                                        (match_dup 0) (match_dup 1)))]
2430   "")
2431
2432 (define_split
2433   [(set (match_operand:DI 0 "register_operand" "")
2434         (abs:DI (match_operand:DI 1 "register_operand" "")))]
2435   "! rtx_equal_p (operands[0], operands[1])"
2436   [(set (match_dup 0) (neg:DI (match_dup 1)))
2437    (set (match_dup 0) (if_then_else:DI (lt (match_dup 1) (const_int 0))
2438                                        (match_dup 0) (match_dup 1)))]
2439   "")
2440
2441 (define_split
2442   [(set (match_operand:DI 0 "register_operand" "")
2443         (neg:DI (abs:DI (match_dup 0))))
2444    (clobber (match_operand:DI 2 "register_operand" ""))]
2445   ""
2446   [(set (match_dup 1) (neg:DI (match_dup 0)))
2447    (set (match_dup 0) (if_then_else:DI (le (match_dup 0) (const_int 0))
2448                                        (match_dup 0) (match_dup 1)))]
2449   "")
2450
2451 (define_split
2452   [(set (match_operand:DI 0 "register_operand" "")
2453         (neg:DI (abs:DI (match_operand:DI 1 "register_operand" ""))))]
2454   "! rtx_equal_p (operands[0], operands[1])"
2455   [(set (match_dup 0) (neg:DI (match_dup 1)))
2456    (set (match_dup 0) (if_then_else:DI (gt (match_dup 1) (const_int 0))
2457                                        (match_dup 0) (match_dup 1)))]
2458   "")
2459
2460 (define_insn "sminqi3"
2461   [(set (match_operand:QI 0 "register_operand" "=r")
2462         (smin:SI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
2463                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
2464   "TARGET_MAX"
2465   "minsb8 %r1,%2,%0"
2466   [(set_attr "type" "mvi")])
2467
2468 (define_insn "uminqi3"
2469   [(set (match_operand:QI 0 "register_operand" "=r")
2470         (umin:SI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
2471                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
2472   "TARGET_MAX"
2473   "minub8 %r1,%2,%0"
2474   [(set_attr "type" "mvi")])
2475
2476 (define_insn "smaxqi3"
2477   [(set (match_operand:QI 0 "register_operand" "=r")
2478         (smax:SI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
2479                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
2480   "TARGET_MAX"
2481   "maxsb8 %r1,%2,%0"
2482   [(set_attr "type" "mvi")])
2483
2484 (define_insn "umaxqi3"
2485   [(set (match_operand:QI 0 "register_operand" "=r")
2486         (umax:SI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
2487                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
2488   "TARGET_MAX"
2489   "maxub8 %r1,%2,%0"
2490   [(set_attr "type" "mvi")])
2491
2492 (define_insn "sminhi3"
2493   [(set (match_operand:HI 0 "register_operand" "=r")
2494         (smin:SI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
2495                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
2496   "TARGET_MAX"
2497   "minsw4 %r1,%2,%0"
2498   [(set_attr "type" "mvi")])
2499
2500 (define_insn "uminhi3"
2501   [(set (match_operand:HI 0 "register_operand" "=r")
2502         (umin:SI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
2503                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
2504   "TARGET_MAX"
2505   "minuw4 %r1,%2,%0"
2506   [(set_attr "type" "mvi")])
2507
2508 (define_insn "smaxhi3"
2509   [(set (match_operand:HI 0 "register_operand" "=r")
2510         (smax:SI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
2511                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
2512   "TARGET_MAX"
2513   "maxsw4 %r1,%2,%0"
2514   [(set_attr "type" "mvi")])
2515
2516 (define_insn "umaxhi3"
2517   [(set (match_operand:HI 0 "register_operand" "=r")
2518         (umax:SI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
2519                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
2520   "TARGET_MAX"
2521   "maxuw4 %r1,%2,%0"
2522   [(set_attr "type" "shift")])
2523
2524 (define_expand "smaxdi3"
2525   [(set (match_dup 3)
2526         (le:DI (match_operand:DI 1 "reg_or_0_operand" "")
2527                (match_operand:DI 2 "reg_or_8bit_operand" "")))
2528    (set (match_operand:DI 0 "register_operand" "")
2529         (if_then_else:DI (eq (match_dup 3) (const_int 0))
2530                          (match_dup 1) (match_dup 2)))]
2531   ""
2532   "
2533 { operands[3] = gen_reg_rtx (DImode);
2534 }")
2535
2536 (define_split
2537   [(set (match_operand:DI 0 "register_operand" "")
2538         (smax:DI (match_operand:DI 1 "reg_or_0_operand" "")
2539                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
2540    (clobber (match_operand:DI 3 "register_operand" ""))]
2541   "operands[2] != const0_rtx"
2542   [(set (match_dup 3) (le:DI (match_dup 1) (match_dup 2)))
2543    (set (match_dup 0) (if_then_else:DI (eq (match_dup 3) (const_int 0))
2544                                        (match_dup 1) (match_dup 2)))]
2545   "")
2546
2547 (define_insn ""
2548   [(set (match_operand:DI 0 "register_operand" "=r")
2549         (smax:DI (match_operand:DI 1 "register_operand" "0")
2550                  (const_int 0)))]
2551   ""
2552   "cmovlt %0,0,%0"
2553   [(set_attr "type" "icmov")])
2554
2555 (define_expand "smindi3"
2556   [(set (match_dup 3)
2557         (lt:DI (match_operand:DI 1 "reg_or_0_operand" "")
2558                (match_operand:DI 2 "reg_or_8bit_operand" "")))
2559    (set (match_operand:DI 0 "register_operand" "")
2560         (if_then_else:DI (ne (match_dup 3) (const_int 0))
2561                          (match_dup 1) (match_dup 2)))]
2562   ""
2563   "
2564 { operands[3] = gen_reg_rtx (DImode);
2565 }")
2566
2567 (define_split
2568   [(set (match_operand:DI 0 "register_operand" "")
2569         (smin:DI (match_operand:DI 1 "reg_or_0_operand" "")
2570                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
2571    (clobber (match_operand:DI 3 "register_operand" ""))]
2572   "operands[2] != const0_rtx"
2573   [(set (match_dup 3) (lt:DI (match_dup 1) (match_dup 2)))
2574    (set (match_dup 0) (if_then_else:DI (ne (match_dup 3) (const_int 0))
2575                                        (match_dup 1) (match_dup 2)))]
2576   "")
2577
2578 (define_insn ""
2579   [(set (match_operand:DI 0 "register_operand" "=r")
2580         (smin:DI (match_operand:DI 1 "register_operand" "0")
2581                  (const_int 0)))]
2582   ""
2583   "cmovgt %0,0,%0"
2584   [(set_attr "type" "icmov")])
2585
2586 (define_expand "umaxdi3"
2587   [(set (match_dup 3) 
2588         (leu:DI (match_operand:DI 1 "reg_or_0_operand" "")
2589                 (match_operand:DI 2 "reg_or_8bit_operand" "")))
2590    (set (match_operand:DI 0 "register_operand" "")
2591         (if_then_else:DI (eq (match_dup 3) (const_int 0))
2592                          (match_dup 1) (match_dup 2)))]
2593   ""
2594   "
2595 { operands[3] = gen_reg_rtx (DImode);
2596 }")
2597
2598 (define_split
2599   [(set (match_operand:DI 0 "register_operand" "")
2600         (umax:DI (match_operand:DI 1 "reg_or_0_operand" "")
2601                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
2602    (clobber (match_operand:DI 3 "register_operand" ""))]
2603   "operands[2] != const0_rtx"
2604   [(set (match_dup 3) (leu:DI (match_dup 1) (match_dup 2)))
2605    (set (match_dup 0) (if_then_else:DI (eq (match_dup 3) (const_int 0))
2606                                        (match_dup 1) (match_dup 2)))]
2607   "")
2608
2609 (define_expand "umindi3"
2610   [(set (match_dup 3)
2611         (ltu:DI (match_operand:DI 1 "reg_or_0_operand" "")
2612                 (match_operand:DI 2 "reg_or_8bit_operand" "")))
2613    (set (match_operand:DI 0 "register_operand" "")
2614         (if_then_else:DI (ne (match_dup 3) (const_int 0))
2615                          (match_dup 1) (match_dup 2)))]
2616   ""
2617   "
2618 { operands[3] = gen_reg_rtx (DImode);
2619 }")
2620
2621 (define_split
2622   [(set (match_operand:DI 0 "register_operand" "")
2623         (umin:DI (match_operand:DI 1 "reg_or_0_operand" "")
2624                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
2625    (clobber (match_operand:DI 3 "register_operand" ""))]
2626   "operands[2] != const0_rtx"
2627   [(set (match_dup 3) (ltu:DI (match_dup 1) (match_dup 2)))
2628    (set (match_dup 0) (if_then_else:DI (ne (match_dup 3) (const_int 0))
2629                                        (match_dup 1) (match_dup 2)))]
2630   "")
2631
2632 (define_insn ""
2633   [(set (pc)
2634         (if_then_else
2635          (match_operator 1 "signed_comparison_operator"
2636                          [(match_operand:DI 2 "reg_or_0_operand" "rJ")
2637                           (const_int 0)])
2638          (label_ref (match_operand 0 "" ""))
2639          (pc)))]
2640   ""
2641   "b%C1 %r2,%0"
2642   [(set_attr "type" "ibr")])
2643
2644 (define_insn ""
2645   [(set (pc)
2646         (if_then_else
2647          (match_operator 1 "signed_comparison_operator"
2648                          [(const_int 0)
2649                           (match_operand:DI 2 "register_operand" "r")])
2650          (label_ref (match_operand 0 "" ""))
2651          (pc)))]
2652   ""
2653   "b%c1 %2,%0"
2654   [(set_attr "type" "ibr")])
2655
2656 (define_insn ""
2657   [(set (pc)
2658         (if_then_else
2659          (ne (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
2660                               (const_int 1)
2661                               (const_int 0))
2662              (const_int 0))
2663          (label_ref (match_operand 0 "" ""))
2664          (pc)))]
2665   ""
2666   "blbs %r1,%0"
2667   [(set_attr "type" "ibr")])
2668
2669 (define_insn ""
2670   [(set (pc)
2671         (if_then_else
2672          (eq (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
2673                               (const_int 1)
2674                               (const_int 0))
2675              (const_int 0))
2676          (label_ref (match_operand 0 "" ""))
2677          (pc)))]
2678   ""
2679   "blbc %r1,%0"
2680   [(set_attr "type" "ibr")])
2681
2682 (define_split
2683   [(parallel
2684     [(set (pc)
2685           (if_then_else
2686            (match_operator 1 "comparison_operator"
2687                            [(zero_extract:DI (match_operand:DI 2 "register_operand" "")
2688                                              (const_int 1)
2689                                              (match_operand:DI 3 "const_int_operand" ""))
2690                             (const_int 0)])
2691            (label_ref (match_operand 0 "" ""))
2692            (pc)))
2693      (clobber (match_operand:DI 4 "register_operand" ""))])]
2694   "INTVAL (operands[3]) != 0"
2695   [(set (match_dup 4)
2696         (lshiftrt:DI (match_dup 2) (match_dup 3)))
2697    (set (pc)
2698         (if_then_else (match_op_dup 1
2699                                     [(zero_extract:DI (match_dup 4)
2700                                                       (const_int 1)
2701                                                       (const_int 0))
2702                                      (const_int 0)])
2703                       (label_ref (match_dup 0))
2704                       (pc)))]
2705   "")
2706 \f
2707 ;; The following are the corresponding floating-point insns.  Recall
2708 ;; we need to have variants that expand the arguments from SF mode
2709 ;; to DFmode.
2710
2711 (define_insn ""
2712   [(set (match_operand:DF 0 "register_operand" "=&f")
2713         (match_operator:DF 1 "alpha_comparison_operator"
2714                            [(match_operand:DF 2 "reg_or_fp0_operand" "fG")
2715                             (match_operand:DF 3 "reg_or_fp0_operand" "fG")]))]
2716   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2717   "cmp%-%C1%' %R2,%R3,%0"
2718   [(set_attr "type" "fadd")
2719    (set_attr "trap" "yes")])
2720
2721 (define_insn ""
2722   [(set (match_operand:DF 0 "register_operand" "=f")
2723         (match_operator:DF 1 "alpha_comparison_operator"
2724                            [(match_operand:DF 2 "reg_or_fp0_operand" "fG")
2725                             (match_operand:DF 3 "reg_or_fp0_operand" "fG")]))]
2726   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2727   "cmp%-%C1%' %R2,%R3,%0"
2728   [(set_attr "type" "fadd")
2729    (set_attr "trap" "yes")])
2730
2731 (define_insn ""
2732   [(set (match_operand:DF 0 "register_operand" "=&f")
2733         (match_operator:DF 1 "alpha_comparison_operator"
2734                            [(float_extend:DF
2735                              (match_operand:SF 2 "reg_or_fp0_operand" "fG"))
2736                             (match_operand:DF 3 "reg_or_fp0_operand" "fG")]))]
2737   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2738   "cmp%-%C1%' %R2,%R3,%0"
2739   [(set_attr "type" "fadd")
2740    (set_attr "trap" "yes")])
2741
2742 (define_insn ""
2743   [(set (match_operand:DF 0 "register_operand" "=f")
2744         (match_operator:DF 1 "alpha_comparison_operator"
2745                            [(float_extend:DF
2746                              (match_operand:SF 2 "reg_or_fp0_operand" "fG"))
2747                             (match_operand:DF 3 "reg_or_fp0_operand" "fG")]))]
2748   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2749   "cmp%-%C1%' %R2,%R3,%0"
2750   [(set_attr "type" "fadd")
2751    (set_attr "trap" "yes")])
2752
2753 (define_insn ""
2754   [(set (match_operand:DF 0 "register_operand" "=&f")
2755         (match_operator:DF 1 "alpha_comparison_operator"
2756                            [(match_operand:DF 2 "reg_or_fp0_operand" "fG")
2757                             (float_extend:DF
2758                              (match_operand:SF 3 "reg_or_fp0_operand" "fG"))]))]
2759   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2760   "cmp%-%C1%' %R2,%R3,%0"
2761   [(set_attr "type" "fadd")
2762    (set_attr "trap" "yes")])
2763
2764 (define_insn ""
2765   [(set (match_operand:DF 0 "register_operand" "=f")
2766         (match_operator:DF 1 "alpha_comparison_operator"
2767                            [(match_operand:DF 2 "reg_or_fp0_operand" "fG")
2768                             (float_extend:DF
2769                              (match_operand:SF 3 "reg_or_fp0_operand" "fG"))]))]
2770   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2771   "cmp%-%C1%' %R2,%R3,%0"
2772   [(set_attr "type" "fadd")
2773    (set_attr "trap" "yes")])
2774
2775 (define_insn ""
2776   [(set (match_operand:DF 0 "register_operand" "=&f")
2777         (match_operator:DF 1 "alpha_comparison_operator"
2778                            [(float_extend:DF
2779                              (match_operand:SF 2 "reg_or_fp0_operand" "fG"))
2780                             (float_extend:DF
2781                              (match_operand:SF 3 "reg_or_fp0_operand" "fG"))]))]
2782   "TARGET_FP && alpha_tp == ALPHA_TP_INSN"
2783   "cmp%-%C1%' %R2,%R3,%0"
2784   [(set_attr "type" "fadd")
2785    (set_attr "trap" "yes")])
2786
2787 (define_insn ""
2788   [(set (match_operand:DF 0 "register_operand" "=f")
2789         (match_operator:DF 1 "alpha_comparison_operator"
2790                            [(float_extend:DF
2791                              (match_operand:SF 2 "reg_or_fp0_operand" "fG"))
2792                             (float_extend:DF
2793                              (match_operand:SF 3 "reg_or_fp0_operand" "fG"))]))]
2794   "TARGET_FP && alpha_tp != ALPHA_TP_INSN"
2795   "cmp%-%C1%' %R2,%R3,%0"
2796   [(set_attr "type" "fadd")
2797    (set_attr "trap" "yes")])
2798
2799 (define_insn ""
2800   [(set (match_operand:DF 0 "register_operand" "=f,f")
2801         (if_then_else:DF 
2802          (match_operator 3 "signed_comparison_operator"
2803                          [(match_operand:DF 4 "reg_or_fp0_operand" "fG,fG")
2804                           (match_operand:DF 2 "fp0_operand" "G,G")])
2805          (match_operand:DF 1 "reg_or_fp0_operand" "fG,0")
2806          (match_operand:DF 5 "reg_or_fp0_operand" "0,fG")))]
2807   "TARGET_FP"
2808   "@
2809    fcmov%C3 %R4,%R1,%0
2810    fcmov%D3 %R4,%R5,%0"
2811   [(set_attr "type" "fcmov")])
2812
2813 (define_insn ""
2814   [(set (match_operand:SF 0 "register_operand" "=f,f")
2815         (if_then_else:SF 
2816          (match_operator 3 "signed_comparison_operator"
2817                          [(match_operand:DF 4 "reg_or_fp0_operand" "fG,fG")
2818                           (match_operand:DF 2 "fp0_operand" "G,G")])
2819          (match_operand:SF 1 "reg_or_fp0_operand" "fG,0")
2820          (match_operand:SF 5 "reg_or_fp0_operand" "0,fG")))]
2821   "TARGET_FP"
2822   "@
2823    fcmov%C3 %R4,%R1,%0
2824    fcmov%D3 %R4,%R5,%0"
2825   [(set_attr "type" "fcmov")])
2826
2827 (define_insn ""
2828   [(set (match_operand:DF 0 "register_operand" "=f,f")
2829         (if_then_else:DF 
2830          (match_operator 3 "signed_comparison_operator"
2831                          [(match_operand:DF 4 "reg_or_fp0_operand" "fG,fG")
2832                           (match_operand:DF 2 "fp0_operand" "G,G")])
2833          (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" "fG,0"))
2834          (match_operand:DF 5 "reg_or_fp0_operand" "0,fG")))]
2835   "TARGET_FP"
2836   "@
2837    fcmov%C3 %R4,%R1,%0
2838    fcmov%D3 %R4,%R5,%0"
2839   [(set_attr "type" "fcmov")])
2840
2841 (define_insn ""
2842   [(set (match_operand:DF 0 "register_operand" "=f,f")
2843         (if_then_else:DF 
2844          (match_operator 3 "signed_comparison_operator"
2845                          [(float_extend:DF 
2846                            (match_operand:SF 4 "reg_or_fp0_operand" "fG,fG"))
2847                           (match_operand:DF 2 "fp0_operand" "G,G")])
2848          (match_operand:DF 1 "reg_or_fp0_operand" "fG,0")
2849          (match_operand:DF 5 "reg_or_fp0_operand" "0,fG")))]
2850   "TARGET_FP"
2851   "@
2852    fcmov%C3 %R4,%R1,%0
2853    fcmov%D3 %R4,%R5,%0"
2854   [(set_attr "type" "fcmov")])
2855
2856 (define_insn ""
2857   [(set (match_operand:SF 0 "register_operand" "=f,f")
2858         (if_then_else:SF 
2859          (match_operator 3 "signed_comparison_operator"
2860                          [(float_extend:DF
2861                            (match_operand:SF 4 "reg_or_fp0_operand" "fG,fG"))
2862                           (match_operand:DF 2 "fp0_operand" "G,G")])
2863          (match_operand:SF 1 "reg_or_fp0_operand" "fG,0")
2864          (match_operand:SF 5 "reg_or_fp0_operand" "0,fG")))]
2865   "TARGET_FP"
2866   "@
2867    fcmov%C3 %R4,%R1,%0
2868    fcmov%D3 %R4,%R5,%0"
2869   [(set_attr "type" "fcmov")])
2870
2871 (define_insn ""
2872   [(set (match_operand:DF 0 "register_operand" "=f,f")
2873         (if_then_else:DF 
2874          (match_operator 3 "signed_comparison_operator"
2875                          [(float_extend:DF
2876                            (match_operand:SF 4 "reg_or_fp0_operand" "fG,fG"))
2877                           (match_operand:DF 2 "fp0_operand" "G,G")])
2878          (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" "fG,0"))
2879          (match_operand:DF 5 "reg_or_fp0_operand" "0,fG")))]
2880   "TARGET_FP"
2881   "@
2882    fcmov%C3 %R4,%R1,%0
2883    fcmov%D3 %R4,%R5,%0"
2884   [(set_attr "type" "fcmov")])
2885
2886 (define_expand "maxdf3"
2887   [(set (match_dup 3)
2888         (le:DF (match_operand:DF 1 "reg_or_fp0_operand" "")
2889                (match_operand:DF 2 "reg_or_fp0_operand" "")))
2890    (set (match_operand:DF 0 "register_operand" "")
2891         (if_then_else:DF (eq (match_dup 3) (match_dup 4))
2892                          (match_dup 1) (match_dup 2)))]
2893   "TARGET_FP"
2894   "
2895 { operands[3] = gen_reg_rtx (DFmode);
2896   operands[4] = CONST0_RTX (DFmode);
2897 }")
2898
2899 (define_expand "mindf3"
2900   [(set (match_dup 3)
2901         (lt:DF (match_operand:DF 1 "reg_or_fp0_operand" "")
2902                (match_operand:DF 2 "reg_or_fp0_operand" "")))
2903    (set (match_operand:DF 0 "register_operand" "")
2904         (if_then_else:DF (ne (match_dup 3) (match_dup 4))
2905                          (match_dup 1) (match_dup 2)))]
2906   "TARGET_FP"
2907   "
2908 { operands[3] = gen_reg_rtx (DFmode);
2909   operands[4] = CONST0_RTX (DFmode);
2910 }")
2911
2912 (define_expand "maxsf3"
2913   [(set (match_dup 3)
2914         (le:DF (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" ""))
2915                (float_extend:DF (match_operand:SF 2 "reg_or_fp0_operand" ""))))
2916    (set (match_operand:SF 0 "register_operand" "")
2917         (if_then_else:SF (eq (match_dup 3) (match_dup 4))
2918                          (match_dup 1) (match_dup 2)))]
2919   "TARGET_FP"
2920   "
2921 { operands[3] = gen_reg_rtx (DFmode);
2922   operands[4] = CONST0_RTX (DFmode);
2923 }")
2924
2925 (define_expand "minsf3"
2926   [(set (match_dup 3)
2927         (lt:DF (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" ""))
2928                (float_extend:DF (match_operand:SF 2 "reg_or_fp0_operand" ""))))
2929    (set (match_operand:SF 0 "register_operand" "")
2930         (if_then_else:SF (ne (match_dup 3) (match_dup 4))
2931                       (match_dup 1) (match_dup 2)))]
2932   "TARGET_FP"
2933   "
2934 { operands[3] = gen_reg_rtx (DFmode);
2935   operands[4] = CONST0_RTX (DFmode);
2936 }")
2937
2938 (define_insn ""
2939   [(set (pc)
2940         (if_then_else
2941          (match_operator 1 "signed_comparison_operator"
2942                          [(match_operand:DF 2 "reg_or_fp0_operand" "fG")
2943                           (match_operand:DF 3 "fp0_operand" "G")])
2944          (label_ref (match_operand 0 "" ""))
2945          (pc)))]
2946   "TARGET_FP"
2947   "fb%C1 %R2,%0"
2948   [(set_attr "type" "fbr")])
2949
2950 (define_insn ""
2951   [(set (pc)
2952         (if_then_else
2953          (match_operator 1 "signed_comparison_operator"
2954                          [(float_extend:DF
2955                            (match_operand:SF 2 "reg_or_fp0_operand" "fG"))
2956                           (match_operand:DF 3 "fp0_operand" "G")])
2957          (label_ref (match_operand 0 "" ""))
2958          (pc)))]
2959   "TARGET_FP"
2960   "fb%C1 %R2,%0"
2961   [(set_attr "type" "fbr")])
2962 \f
2963 ;; These are the main define_expand's used to make conditional branches
2964 ;; and compares.
2965
2966 (define_expand "cmpdf"
2967   [(set (cc0) (compare (match_operand:DF 0 "reg_or_fp0_operand" "")
2968                        (match_operand:DF 1 "reg_or_fp0_operand" "")))]
2969   "TARGET_FP"
2970   "
2971 {
2972   alpha_compare_op0 = operands[0];
2973   alpha_compare_op1 = operands[1];
2974   alpha_compare_fp_p = 1;
2975   DONE;
2976 }")
2977
2978 (define_expand "cmpdi"
2979   [(set (cc0) (compare (match_operand:DI 0 "reg_or_0_operand" "")
2980                        (match_operand:DI 1 "reg_or_8bit_operand" "")))]
2981   ""
2982   "
2983 {
2984   alpha_compare_op0 = operands[0];
2985   alpha_compare_op1 = operands[1];
2986   alpha_compare_fp_p = 0;
2987   DONE;
2988 }")
2989
2990 (define_expand "beq"
2991   [(set (pc)
2992         (if_then_else (match_dup 1)
2993                       (label_ref (match_operand 0 "" ""))
2994                       (pc)))]
2995   ""
2996   "{ operands[1] = alpha_emit_conditional_branch (EQ); }")
2997
2998 (define_expand "bne"
2999   [(set (pc)
3000         (if_then_else (match_dup 1)
3001                       (label_ref (match_operand 0 "" ""))
3002                       (pc)))]
3003   ""
3004   "{ operands[1] = alpha_emit_conditional_branch (NE); }")
3005
3006 (define_expand "blt"
3007   [(set (pc)
3008         (if_then_else (match_dup 1)
3009                       (label_ref (match_operand 0 "" ""))
3010                       (pc)))]
3011   ""
3012   "{ operands[1] = alpha_emit_conditional_branch (LT); }")
3013
3014 (define_expand "ble"
3015   [(set (pc)
3016         (if_then_else (match_dup 1)
3017                       (label_ref (match_operand 0 "" ""))
3018                       (pc)))]
3019   ""
3020   "{ operands[1] = alpha_emit_conditional_branch (LE); }")
3021
3022 (define_expand "bgt"
3023   [(set (pc)
3024         (if_then_else (match_dup 1)
3025                       (label_ref (match_operand 0 "" ""))
3026                       (pc)))]
3027   ""
3028   "{ operands[1] = alpha_emit_conditional_branch (GT); }")
3029
3030 (define_expand "bge"
3031   [(set (pc)
3032         (if_then_else (match_dup 1)
3033                       (label_ref (match_operand 0 "" ""))
3034                       (pc)))]
3035   ""
3036   "{ operands[1] = alpha_emit_conditional_branch (GE); }")
3037
3038 (define_expand "bltu"
3039   [(set (pc)
3040         (if_then_else (match_dup 1)
3041                       (label_ref (match_operand 0 "" ""))
3042                       (pc)))]
3043   ""
3044   "{ operands[1] = alpha_emit_conditional_branch (LTU); }")
3045
3046 (define_expand "bleu"
3047   [(set (pc)
3048         (if_then_else (match_dup 1)
3049                       (label_ref (match_operand 0 "" ""))
3050                       (pc)))]
3051   ""
3052   "{ operands[1] = alpha_emit_conditional_branch (LEU); }")
3053
3054 (define_expand "bgtu"
3055   [(set (pc)
3056         (if_then_else (match_dup 1)
3057                       (label_ref (match_operand 0 "" ""))
3058                       (pc)))]
3059   ""
3060   "{ operands[1] = alpha_emit_conditional_branch (GTU); }")
3061
3062 (define_expand "bgeu"
3063   [(set (pc)
3064         (if_then_else (match_dup 1)
3065                       (label_ref (match_operand 0 "" ""))
3066                       (pc)))]
3067   ""
3068   "{ operands[1] = alpha_emit_conditional_branch (GEU); }")
3069
3070 (define_expand "seq"
3071   [(set (match_operand:DI 0 "register_operand" "")
3072         (match_dup 1))]
3073   ""
3074   "
3075 {
3076   if (alpha_compare_fp_p)
3077     FAIL;
3078
3079   operands[1] = gen_rtx_EQ (DImode, alpha_compare_op0, alpha_compare_op1);
3080 }")
3081
3082 (define_expand "sne"
3083   [(set (match_operand:DI 0 "register_operand" "")
3084         (match_dup 1))
3085    (set (match_dup 0) (xor:DI (match_dup 0) (const_int 1)))]
3086   ""
3087   "
3088 {
3089   if (alpha_compare_fp_p)
3090     FAIL;
3091
3092   operands[1] = gen_rtx_EQ (DImode, alpha_compare_op0, alpha_compare_op1);
3093 }")
3094
3095 (define_expand "slt"
3096   [(set (match_operand:DI 0 "register_operand" "")
3097         (match_dup 1))]
3098   ""
3099   "
3100 {
3101   if (alpha_compare_fp_p)
3102     FAIL;
3103
3104   operands[1] = gen_rtx_LT (DImode, alpha_compare_op0, alpha_compare_op1);
3105 }")
3106
3107 (define_expand "sle"
3108   [(set (match_operand:DI 0 "register_operand" "")
3109         (match_dup 1))]
3110   ""
3111   "
3112 {
3113   if (alpha_compare_fp_p)
3114     FAIL;
3115
3116   operands[1] = gen_rtx_LE (DImode, alpha_compare_op0, alpha_compare_op1);
3117 }")
3118
3119 (define_expand "sgt"
3120   [(set (match_operand:DI 0 "register_operand" "")
3121         (match_dup 1))]
3122   ""
3123   "
3124 {
3125   if (alpha_compare_fp_p)
3126     FAIL;
3127
3128   operands[1] = gen_rtx_LT (DImode, force_reg (DImode, alpha_compare_op1),
3129                             alpha_compare_op0);
3130 }")
3131
3132 (define_expand "sge"
3133   [(set (match_operand:DI 0 "register_operand" "")
3134         (match_dup 1))]
3135   ""
3136   "
3137 {
3138   if (alpha_compare_fp_p)
3139     FAIL;
3140
3141   operands[1] = gen_rtx_LE (DImode, force_reg (DImode, alpha_compare_op1),
3142                             alpha_compare_op0);
3143 }")
3144
3145 (define_expand "sltu"
3146   [(set (match_operand:DI 0 "register_operand" "")
3147         (match_dup 1))]
3148   ""
3149   "
3150 {
3151   if (alpha_compare_fp_p)
3152     FAIL;
3153
3154   operands[1] = gen_rtx_LTU (DImode, alpha_compare_op0, alpha_compare_op1);
3155 }")
3156
3157 (define_expand "sleu"
3158   [(set (match_operand:DI 0 "register_operand" "")
3159         (match_dup 1))]
3160   ""
3161   "
3162 {
3163   if (alpha_compare_fp_p)
3164     FAIL;
3165
3166   operands[1] = gen_rtx_LEU (DImode, alpha_compare_op0, alpha_compare_op1);
3167 }")
3168
3169 (define_expand "sgtu"
3170   [(set (match_operand:DI 0 "register_operand" "")
3171         (match_dup 1))]
3172   ""
3173   "
3174 {
3175   if (alpha_compare_fp_p)
3176     FAIL;
3177
3178   operands[1] = gen_rtx_LTU (DImode, force_reg (DImode, alpha_compare_op1),
3179                              alpha_compare_op0);
3180 }")
3181
3182 (define_expand "sgeu"
3183   [(set (match_operand:DI 0 "register_operand" "")
3184         (match_dup 1))]
3185   ""
3186   "
3187 {
3188   if (alpha_compare_fp_p)
3189     FAIL;
3190
3191   operands[1] = gen_rtx_LEU (DImode, force_reg (DImode, alpha_compare_op1),
3192                              alpha_compare_op0);
3193 }")
3194 \f
3195 ;; These are the main define_expand's used to make conditional moves.
3196
3197 (define_expand "movsicc"
3198   [(set (match_operand:SI 0 "register_operand" "")
3199         (if_then_else:DI (match_operand 1 "comparison_operator" "")
3200                          (match_operand:SI 2 "reg_or_8bit_operand" "")
3201                          (match_operand:SI 3 "reg_or_8bit_operand" "")))]
3202   ""
3203   "
3204 {
3205   if ((operands[1] = alpha_emit_conditional_move (operands[1], SImode)) == 0)
3206     FAIL;
3207 }")
3208
3209 (define_expand "movdicc"
3210   [(set (match_operand:DI 0 "register_operand" "")
3211         (if_then_else:DI (match_operand 1 "comparison_operator" "")
3212                          (match_operand:DI 2 "reg_or_8bit_operand" "")
3213                          (match_operand:DI 3 "reg_or_8bit_operand" "")))]
3214   ""
3215   "
3216 {
3217   if ((operands[1] = alpha_emit_conditional_move (operands[1], DImode)) == 0)
3218     FAIL;
3219 }")
3220
3221 (define_expand "movsfcc"
3222   [(set (match_operand:SF 0 "register_operand" "")
3223         (if_then_else:SF (match_operand 1 "comparison_operator" "")
3224                          (match_operand:SF 2 "reg_or_8bit_operand" "")
3225                          (match_operand:SF 3 "reg_or_8bit_operand" "")))]
3226   ""
3227   "
3228 {
3229   if ((operands[1] = alpha_emit_conditional_move (operands[1], SFmode)) == 0)
3230     FAIL;
3231 }")
3232
3233 (define_expand "movdfcc"
3234   [(set (match_operand:DF 0 "register_operand" "")
3235         (if_then_else:DF (match_operand 1 "comparison_operator" "")
3236                          (match_operand:DF 2 "reg_or_8bit_operand" "")
3237                          (match_operand:DF 3 "reg_or_8bit_operand" "")))]
3238   ""
3239   "
3240 {
3241   if ((operands[1] = alpha_emit_conditional_move (operands[1], DFmode)) == 0)
3242     FAIL;
3243 }")
3244 \f
3245 ;; These define_split definitions are used in cases when comparisons have
3246 ;; not be stated in the correct way and we need to reverse the second
3247 ;; comparison.  For example, x >= 7 has to be done as x < 6 with the
3248 ;; comparison that tests the result being reversed.  We have one define_split
3249 ;; for each use of a comparison.  They do not match valid insns and need
3250 ;; not generate valid insns.
3251 ;;
3252 ;; We can also handle equality comparisons (and inequality comparisons in
3253 ;; cases where the resulting add cannot overflow) by doing an add followed by
3254 ;; a comparison with zero.  This is faster since the addition takes one
3255 ;; less cycle than a compare when feeding into a conditional move.
3256 ;; For this case, we also have an SImode pattern since we can merge the add
3257 ;; and sign extend and the order doesn't matter.
3258 ;;
3259 ;; We do not do this for floating-point, since it isn't clear how the "wrong"
3260 ;; operation could have been generated.
3261
3262 (define_split
3263   [(set (match_operand:DI 0 "register_operand" "")
3264         (if_then_else:DI
3265          (match_operator 1 "comparison_operator"
3266                          [(match_operand:DI 2 "reg_or_0_operand" "")
3267                           (match_operand:DI 3 "reg_or_cint_operand" "")])
3268          (match_operand:DI 4 "reg_or_cint_operand" "")
3269          (match_operand:DI 5 "reg_or_cint_operand" "")))
3270    (clobber (match_operand:DI 6 "register_operand" ""))]
3271   "operands[3] != const0_rtx"
3272   [(set (match_dup 6) (match_dup 7))
3273    (set (match_dup 0)
3274         (if_then_else:DI (match_dup 8) (match_dup 4) (match_dup 5)))]
3275   "
3276 { enum rtx_code code = GET_CODE (operands[1]);
3277   int unsignedp = (code == GEU || code == LEU || code == GTU || code == LTU);
3278
3279   /* If we are comparing for equality with a constant and that constant
3280      appears in the arm when the register equals the constant, use the
3281      register since that is more likely to match (and to produce better code
3282      if both would).  */
3283
3284   if (code == EQ && GET_CODE (operands[3]) == CONST_INT
3285       && rtx_equal_p (operands[4], operands[3]))
3286     operands[4] = operands[2];
3287
3288   else if (code == NE && GET_CODE (operands[3]) == CONST_INT
3289            && rtx_equal_p (operands[5], operands[3]))
3290     operands[5] = operands[2];
3291
3292   if (code == NE || code == EQ
3293       || (extended_count (operands[2], DImode, unsignedp) >= 1
3294           && extended_count (operands[3], DImode, unsignedp) >= 1))
3295     {
3296       if (GET_CODE (operands[3]) == CONST_INT)
3297         operands[7] = gen_rtx_PLUS (DImode, operands[2],
3298                                     GEN_INT (- INTVAL (operands[3])));
3299       else
3300         operands[7] = gen_rtx_MINUS (DImode, operands[2], operands[3]);
3301
3302       operands[8] = gen_rtx_fmt_ee (code, VOIDmode, operands[6], const0_rtx);
3303     }
3304
3305   else if (code == EQ || code == LE || code == LT
3306            || code == LEU || code == LTU)
3307     {
3308       operands[7] = gen_rtx_fmt_ee (code, DImode, operands[2], operands[3]);
3309       operands[8] = gen_rtx_NE (VOIDmode, operands[6], const0_rtx);
3310     }
3311   else
3312     {
3313       operands[7] = gen_rtx_fmt_ee (reverse_condition (code), DImode,
3314                                     operands[2], operands[3]);
3315       operands[8] = gen_rtx_EQ (VOIDmode, operands[6], const0_rtx);
3316     }
3317 }")
3318
3319 (define_split
3320   [(set (match_operand:DI 0 "register_operand" "")
3321         (if_then_else:DI
3322          (match_operator 1 "comparison_operator"
3323                          [(match_operand:SI 2 "reg_or_0_operand" "")
3324                           (match_operand:SI 3 "reg_or_cint_operand" "")])
3325          (match_operand:DI 4 "reg_or_8bit_operand" "")
3326          (match_operand:DI 5 "reg_or_8bit_operand" "")))
3327    (clobber (match_operand:DI 6 "register_operand" ""))]
3328   "operands[3] != const0_rtx
3329    && (GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)"
3330   [(set (match_dup 6) (match_dup 7))
3331    (set (match_dup 0)
3332         (if_then_else:DI (match_dup 8) (match_dup 4) (match_dup 5)))]
3333   "
3334 { enum rtx_code code = GET_CODE (operands[1]);
3335   int unsignedp = (code == GEU || code == LEU || code == GTU || code == LTU);
3336   rtx tem;
3337
3338   if ((code != NE && code != EQ
3339        && ! (extended_count (operands[2], DImode, unsignedp) >= 1
3340              && extended_count (operands[3], DImode, unsignedp) >= 1)))
3341     FAIL;
3342  
3343   if (GET_CODE (operands[3]) == CONST_INT)
3344     tem = gen_rtx_PLUS (SImode, operands[2],
3345                         GEN_INT (- INTVAL (operands[3])));
3346   else
3347     tem = gen_rtx_MINUS (SImode, operands[2], operands[3]);
3348
3349   operands[7] = gen_rtx_SIGN_EXTEND (DImode, tem);
3350   operands[8] = gen_rtx_fmt_ee (GET_CODE (operands[1]), VOIDmode,
3351                                 operands[6], const0_rtx);
3352 }")
3353
3354 (define_split
3355   [(set (pc)
3356         (if_then_else
3357          (match_operator 1 "comparison_operator"
3358                          [(match_operand:DI 2 "reg_or_0_operand" "")
3359                           (match_operand:DI 3 "reg_or_cint_operand" "")])
3360          (label_ref (match_operand 0 "" ""))
3361          (pc)))
3362    (clobber (match_operand:DI 4 "register_operand" ""))]
3363   "operands[3] != const0_rtx"
3364   [(set (match_dup 4) (match_dup 5))
3365    (set (pc) (if_then_else (match_dup 6) (label_ref (match_dup 0)) (pc)))]
3366   "
3367 { enum rtx_code code = GET_CODE (operands[1]);
3368   int unsignedp = (code == GEU || code == LEU || code == GTU || code == LTU);
3369
3370   if (code == NE || code == EQ
3371       || (extended_count (operands[2], DImode, unsignedp) >= 1
3372           && extended_count (operands[3], DImode, unsignedp) >= 1))
3373     {
3374       if (GET_CODE (operands[3]) == CONST_INT)
3375         operands[5] = gen_rtx_PLUS (DImode, operands[2],
3376                                     GEN_INT (- INTVAL (operands[3])));
3377       else
3378         operands[5] = gen_rtx_MINUS (DImode, operands[2], operands[3]);
3379
3380       operands[6] = gen_rtx_fmt_ee (code, VOIDmode, operands[4], const0_rtx);
3381     }
3382
3383   else if (code == EQ || code == LE || code == LT
3384            || code == LEU || code == LTU)
3385     {
3386       operands[5] = gen_rtx_fmt_ee (code, DImode, operands[2], operands[3]);
3387       operands[6] = gen_rtx_NE (VOIDmode, operands[4], const0_rtx);
3388     }
3389   else
3390     {
3391       operands[5] = gen_rtx_fmt_ee (reverse_condition (code), DImode,
3392                                     operands[2], operands[3]);
3393       operands[6] = gen_rtx_EQ (VOIDmode, operands[4], const0_rtx);
3394     }
3395 }")
3396
3397 (define_split
3398   [(set (pc)
3399         (if_then_else
3400          (match_operator 1 "comparison_operator"
3401                          [(match_operand:SI 2 "reg_or_0_operand" "")
3402                           (match_operand:SI 3 "const_int_operand" "")])
3403          (label_ref (match_operand 0 "" ""))
3404          (pc)))
3405    (clobber (match_operand:DI 4 "register_operand" ""))]
3406   "operands[3] != const0_rtx
3407    && (GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)"
3408   [(set (match_dup 4) (match_dup 5))
3409    (set (pc) (if_then_else (match_dup 6) (label_ref (match_dup 0)) (pc)))]
3410   "
3411 { rtx tem;
3412
3413   if (GET_CODE (operands[3]) == CONST_INT)
3414     tem = gen_rtx_PLUS (SImode, operands[2],
3415                         GEN_INT (- INTVAL (operands[3])));
3416   else
3417     tem = gen_rtx_MINUS (SImode, operands[2], operands[3]);
3418   
3419   operands[5] = gen_rtx_SIGN_EXTEND (DImode, tem);
3420   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[1]), VOIDmode,
3421                                 operands[4], const0_rtx);
3422 }")
3423
3424 ;; We can convert such things as "a > 0xffff" to "t = a & ~ 0xffff; t != 0".
3425 ;; This eliminates one, and sometimes two, insns when the AND can be done
3426 ;; with a ZAP.
3427 (define_split
3428   [(set (match_operand:DI 0 "register_operand" "")
3429         (match_operator 1 "comparison_operator"
3430                         [(match_operand:DI 2 "register_operand" "")
3431                          (match_operand:DI 3 "const_int_operand" "")]))
3432    (clobber (match_operand:DI 4 "register_operand" ""))]
3433   "exact_log2 (INTVAL (operands[3]) + 1) >= 0
3434    && (GET_CODE (operands[1]) == GTU
3435        || GET_CODE (operands[1]) == LEU
3436        || ((GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == LE)
3437            && extended_count (operands[2], DImode, 1) > 0))"
3438   [(set (match_dup 4) (and:DI (match_dup 2) (match_dup 5)))
3439    (set (match_dup 0) (match_dup 6))]
3440   "
3441 {
3442   operands[5] = GEN_INT (~ INTVAL (operands[3]));
3443   operands[6] = gen_rtx_fmt_ee (((GET_CODE (operands[1]) == GTU
3444                                   || GET_CODE (operands[1]) == GT)
3445                                  ? NE : EQ),
3446                                 DImode, operands[4], const0_rtx);
3447 }")
3448 \f
3449 ;; Here are the CALL and unconditional branch insns.  Calls on NT and OSF
3450 ;; work differently, so we have different patterns for each.
3451
3452 (define_expand "call"
3453   [(use (match_operand:DI 0 "" ""))
3454    (use (match_operand 1 "" ""))
3455    (use (match_operand 2 "" ""))
3456    (use (match_operand 3 "" ""))]
3457   ""
3458   "
3459 { if (TARGET_WINDOWS_NT)
3460     emit_call_insn (gen_call_nt (operands[0], operands[1]));
3461   else if (TARGET_OPEN_VMS)
3462     emit_call_insn (gen_call_vms (operands[0], operands[2]));
3463   else
3464     emit_call_insn (gen_call_osf (operands[0], operands[1]));
3465
3466   DONE;
3467 }")
3468
3469 (define_expand "call_osf"
3470   [(parallel [(call (mem:DI (match_operand 0 "" ""))
3471                     (match_operand 1 "" ""))
3472               (clobber (reg:DI 27))
3473               (clobber (reg:DI 26))])]
3474   ""
3475   "
3476 { if (GET_CODE (operands[0]) != MEM)
3477     abort ();
3478
3479   operands[0] = XEXP (operands[0], 0);
3480
3481   if (GET_CODE (operands[0]) != SYMBOL_REF
3482       && ! (GET_CODE (operands[0]) == REG && REGNO (operands[0]) == 27))
3483     {
3484       rtx tem = gen_rtx_REG (DImode, 27);
3485       emit_move_insn (tem, operands[0]);
3486       operands[0] = tem;
3487     }
3488 }")
3489
3490 (define_expand "call_nt"
3491   [(parallel [(call (mem:DI (match_operand 0 "" ""))
3492                     (match_operand 1 "" ""))
3493               (clobber (reg:DI 26))])]
3494   ""
3495   "
3496 { if (GET_CODE (operands[0]) != MEM)
3497     abort ();
3498
3499   operands[0] = XEXP (operands[0], 0);
3500   if (GET_CODE (operands[0]) != SYMBOL_REF && GET_CODE (operands[0]) != REG)
3501     operands[0] = force_reg (DImode, operands[0]);
3502 }")
3503
3504 ;;
3505 ;; call openvms/alpha
3506 ;; op 0: symbol ref for called function
3507 ;; op 1: next_arg_reg (argument information value for R25)
3508 ;;
3509 (define_expand "call_vms"
3510   [(parallel [(call (mem:DI (match_operand 0 "" ""))
3511                     (match_operand 1 "" ""))
3512               (use (match_dup 2))
3513               (use (reg:DI 25))
3514               (use (reg:DI 26))
3515               (clobber (reg:DI 27))])]
3516   ""
3517   "
3518 { if (GET_CODE (operands[0]) != MEM)
3519     abort ();
3520
3521   operands[0] = XEXP (operands[0], 0);
3522
3523   /* Always load AI with argument information, then handle symbolic and
3524      indirect call differently.  Load RA and set operands[2] to PV in
3525      both cases.  */
3526
3527   emit_move_insn (gen_rtx_REG (DImode, 25), operands[1]);
3528   if (GET_CODE (operands[0]) == SYMBOL_REF)
3529     {
3530       extern char *savealloc ();
3531       char *linksym, *symbol = XSTR (operands[0], 0);
3532       rtx linkage;
3533
3534       if (*symbol == '*')
3535         symbol++;
3536       linksym = savealloc (strlen (symbol) + 6);
3537
3538       alpha_need_linkage (symbol, 0);
3539
3540       linksym[0] = '$';
3541       strcpy (linksym+1, symbol);
3542       strcat (linksym, \"..lk\");
3543       linkage = gen_rtx_SYMBOL_REF (Pmode, linksym);
3544
3545       emit_move_insn (gen_rtx_REG (Pmode, 26), gen_rtx_MEM (Pmode, linkage));
3546
3547       operands[2]
3548         = validize_mem (gen_rtx_MEM (Pmode, plus_constant (linkage, 8)));
3549     }
3550   else
3551     {
3552       emit_move_insn (gen_rtx_REG (Pmode, 26),
3553                       gen_rtx_MEM (Pmode, plus_constant (operands[0], 8)));
3554
3555       operands[2] = operands[0];
3556     }
3557
3558 }")
3559
3560 (define_expand "call_value"
3561   [(use (match_operand 0 "" ""))
3562    (use (match_operand:DI 1 "" ""))
3563    (use (match_operand 2 "" ""))
3564    (use (match_operand 3 "" ""))
3565    (use (match_operand 4 "" ""))]
3566   ""
3567   "
3568 { if (TARGET_WINDOWS_NT)
3569     emit_call_insn (gen_call_value_nt (operands[0], operands[1], operands[2]));
3570   else if (TARGET_OPEN_VMS)
3571     emit_call_insn (gen_call_value_vms (operands[0], operands[1],
3572                                         operands[3]));
3573   else
3574     emit_call_insn (gen_call_value_osf (operands[0], operands[1],
3575                                         operands[2]));
3576   DONE;
3577 }")
3578
3579 (define_expand "call_value_osf"
3580   [(parallel [(set (match_operand 0 "" "")
3581                    (call (mem:DI (match_operand 1 "" ""))
3582                          (match_operand 2 "" "")))
3583               (clobber (reg:DI 27))
3584               (clobber (reg:DI 26))])]
3585   ""
3586   "
3587 { if (GET_CODE (operands[1]) != MEM)
3588     abort ();
3589
3590   operands[1] = XEXP (operands[1], 0);
3591
3592   if (GET_CODE (operands[1]) != SYMBOL_REF
3593       && ! (GET_CODE (operands[1]) == REG && REGNO (operands[1]) == 27))
3594     {
3595       rtx tem = gen_rtx_REG (DImode, 27);
3596       emit_move_insn (tem, operands[1]);
3597       operands[1] = tem;
3598     }
3599 }")
3600
3601 (define_expand "call_value_nt"
3602   [(parallel [(set (match_operand 0 "" "")
3603                    (call (mem:DI (match_operand 1 "" ""))
3604                          (match_operand 2 "" "")))
3605               (clobber (reg:DI 26))])]
3606   ""
3607   "
3608 { if (GET_CODE (operands[1]) != MEM)
3609     abort ();
3610
3611   operands[1] = XEXP (operands[1], 0);
3612   if (GET_CODE (operands[0]) != SYMBOL_REF && GET_CODE (operands[0]) != REG)
3613     operands[1] = force_reg (DImode, operands[1]);
3614 }")
3615
3616 (define_expand "call_value_vms"
3617   [(parallel [(set (match_operand 0 "" "")
3618                    (call (mem:DI (match_operand:DI 1 "" ""))
3619                          (match_operand 2 "" "")))
3620               (use (match_dup 3))
3621               (use (reg:DI 25))
3622               (use (reg:DI 26))
3623               (clobber (reg:DI 27))])]
3624   ""
3625   "
3626 { if (GET_CODE (operands[1]) != MEM)
3627     abort ();
3628
3629   operands[1] = XEXP (operands[1], 0);
3630
3631   /* Always load AI with argument information, then handle symbolic and
3632      indirect call differently.  Load RA and set operands[3] to PV in
3633      both cases.  */
3634
3635   emit_move_insn (gen_rtx_REG (DImode, 25), operands[2]);
3636   if (GET_CODE (operands[1]) == SYMBOL_REF)
3637     {
3638       extern char *savealloc ();
3639       char *linksym, *symbol = XSTR (operands[1], 0);
3640       rtx linkage;
3641
3642       if (*symbol == '*')
3643         symbol++;
3644       linksym = savealloc (strlen (symbol) + 6);
3645
3646       alpha_need_linkage (symbol, 0);
3647       linksym[0] = '$';
3648       strcpy (linksym+1, symbol);
3649       strcat (linksym, \"..lk\");
3650       linkage = gen_rtx_SYMBOL_REF (Pmode, linksym);
3651
3652       emit_move_insn (gen_rtx_REG (Pmode, 26), gen_rtx_MEM (Pmode, linkage));
3653
3654       operands[3]
3655         = validize_mem (gen_rtx_MEM (Pmode, plus_constant (linkage, 8)));
3656     }
3657   else
3658     {
3659       emit_move_insn (gen_rtx_REG (Pmode, 26),
3660                       gen_rtx_MEM (Pmode, plus_constant (operands[1], 8)));
3661
3662       operands[3] = operands[1];
3663     }
3664 }")
3665
3666 (define_insn ""
3667   [(call (mem:DI (match_operand:DI 0 "call_operand" "r,R,i"))
3668          (match_operand 1 "" ""))
3669    (clobber (reg:DI 27))
3670    (clobber (reg:DI 26))]
3671   "! TARGET_WINDOWS_NT && ! TARGET_OPEN_VMS"
3672   "@
3673    jsr $26,($27),0\;ldgp $29,0($26)
3674    bsr $26,$%0..ng
3675    jsr $26,%0\;ldgp $29,0($26)"
3676   [(set_attr "type" "jsr")
3677    (set_attr "length" "12,*,12")])
3678       
3679 (define_insn ""
3680   [(call (mem:DI (match_operand:DI 0 "call_operand" "r,R,i"))
3681          (match_operand 1 "" ""))
3682    (clobber (reg:DI 26))]
3683   "TARGET_WINDOWS_NT"
3684   "@
3685    jsr $26,(%0)
3686    bsr $26,%0
3687    jsr $26,%0"
3688   [(set_attr "type" "jsr")
3689    (set_attr "length" "*,*,12")])
3690       
3691 (define_insn ""
3692   [(call (mem:DI (match_operand:DI 0 "call_operand" "r,i"))
3693          (match_operand 1 "" ""))
3694    (use (match_operand:DI 2 "general_operand" "r,m"))
3695    (use (reg:DI 25))
3696    (use (reg:DI 26))
3697    (clobber (reg:DI 27))]
3698   "TARGET_OPEN_VMS"
3699   "@
3700    bis %2,%2,$27\;jsr $26,0\;ldq $27,0($29)
3701    ldq $27,%2\;jsr $26,%0\;ldq $27,0($29)"
3702   [(set_attr "type" "jsr")
3703    (set_attr "length" "12,16")])
3704
3705 (define_insn ""
3706   [(set (match_operand 0 "register_operand" "=rf,rf,rf")
3707         (call (mem:DI (match_operand:DI 1 "call_operand" "r,R,i"))
3708               (match_operand 2 "" "")))
3709    (clobber (reg:DI 27))
3710    (clobber (reg:DI 26))]
3711   "! TARGET_WINDOWS_NT && ! TARGET_OPEN_VMS"
3712   "@
3713    jsr $26,($27),0\;ldgp $29,0($26)
3714    bsr $26,$%1..ng
3715    jsr $26,%1\;ldgp $29,0($26)"
3716   [(set_attr "type" "jsr")
3717    (set_attr "length" "12,*,12")])
3718
3719 (define_insn ""
3720   [(set (match_operand 0 "register_operand" "=rf,rf,rf")
3721         (call (mem:DI (match_operand:DI 1 "call_operand" "r,R,i"))
3722               (match_operand 2 "" "")))
3723    (clobber (reg:DI 26))]
3724   "TARGET_WINDOWS_NT"
3725   "@
3726    jsr $26,(%1)
3727    bsr $26,%1
3728    jsr $26,%1"
3729   [(set_attr "type" "jsr")
3730    (set_attr "length" "*,*,12")])
3731
3732 (define_insn ""
3733   [(set (match_operand 0 "register_operand" "")
3734         (call (mem:DI (match_operand:DI 1 "call_operand" "r,i"))
3735               (match_operand 2 "" "")))
3736    (use (match_operand:DI 3 "general_operand" "r,m"))
3737    (use (reg:DI 25))
3738    (use (reg:DI 26))
3739    (clobber (reg:DI 27))]
3740   "TARGET_OPEN_VMS"
3741   "@
3742    bis %3,%3,$27\;jsr $26,0\;ldq $27,0($29)
3743    ldq $27,%3\;jsr $26,%1\;ldq $27,0($29)"
3744   [(set_attr "type" "jsr")
3745    (set_attr "length" "12,16")])
3746
3747 ;; Call subroutine returning any type.
3748
3749 (define_expand "untyped_call"
3750   [(parallel [(call (match_operand 0 "" "")
3751                     (const_int 0))
3752               (match_operand 1 "" "")
3753               (match_operand 2 "" "")])]
3754   ""
3755   "
3756 {
3757   int i;
3758
3759   emit_call_insn (gen_call (operands[0], const0_rtx, NULL, const0_rtx));
3760
3761   for (i = 0; i < XVECLEN (operands[2], 0); i++)
3762     {
3763       rtx set = XVECEXP (operands[2], 0, i);
3764       emit_move_insn (SET_DEST (set), SET_SRC (set));
3765     }
3766
3767   /* The optimizer does not know that the call sets the function value
3768      registers we stored in the result block.  We avoid problems by
3769      claiming that all hard registers are used and clobbered at this
3770      point.  */
3771   emit_insn (gen_blockage ());
3772
3773   DONE;
3774 }")
3775
3776 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
3777 ;; all of memory.  This blocks insns from being moved across this point.
3778
3779 (define_insn "blockage"
3780   [(unspec_volatile [(const_int 0)] 1)]
3781   ""
3782   ""
3783   [(set_attr "length" "0")])
3784
3785 (define_insn "jump"
3786   [(set (pc)
3787         (label_ref (match_operand 0 "" "")))]
3788   ""
3789   "br $31,%l0"
3790   [(set_attr "type" "ibr")])
3791
3792 (define_insn "return"
3793   [(return)]
3794   "direct_return ()"
3795   "ret $31,($26),1"
3796   [(set_attr "type" "ibr")])
3797
3798 ;; Use a different pattern for functions which have non-trivial
3799 ;; epilogues so as not to confuse jump and reorg.
3800 (define_insn "return_internal"
3801   [(use (reg:DI 26))
3802    (return)]
3803   ""
3804   "ret $31,($26),1"
3805   [(set_attr "type" "ibr")])
3806
3807 (define_insn "indirect_jump"
3808   [(set (pc) (match_operand:DI 0 "register_operand" "r"))]
3809   ""
3810   "jmp $31,(%0),0"
3811   [(set_attr "type" "ibr")])
3812
3813 (define_insn "nop"
3814   [(const_int 0)]
3815   ""
3816   "nop"
3817   [(set_attr "type" "ilog")])
3818
3819 (define_expand "tablejump"
3820   [(use (match_operand:SI 0 "register_operand" ""))
3821    (use (match_operand:SI 1 "" ""))]
3822   ""
3823   "
3824 {
3825   if (TARGET_WINDOWS_NT)
3826     emit_jump_insn (gen_tablejump_nt (operands[0], operands[1]));
3827   else if (TARGET_OPEN_VMS)
3828     emit_jump_insn (gen_tablejump_vms (operands[0], operands[1]));
3829   else
3830     emit_jump_insn (gen_tablejump_osf (operands[0], operands[1]));
3831
3832   DONE;
3833 }")
3834
3835 (define_expand "tablejump_osf"
3836   [(set (match_dup 3)
3837         (sign_extend:DI (match_operand:SI 0 "register_operand" "")))
3838    (parallel [(set (pc)
3839                    (plus:DI (match_dup 3)
3840                             (label_ref:DI (match_operand 1 "" ""))))
3841               (clobber (match_scratch:DI 2 "=r"))])]
3842   ""
3843   "
3844 { operands[3] = gen_reg_rtx (DImode); }")
3845
3846 (define_expand "tablejump_nt"
3847   [(set (match_dup 3)
3848         (sign_extend:DI (match_operand:SI 0 "register_operand" "")))
3849    (parallel [(set (pc)
3850                    (match_dup 3))
3851               (use (label_ref (match_operand 1 "" "")))])]
3852   ""
3853   "
3854 { operands[3] = gen_reg_rtx (DImode); }")
3855
3856 ;;
3857 ;; tablejump, openVMS way
3858 ;; op 0: offset
3859 ;; op 1: label preceding jump-table
3860 ;;
3861 (define_expand "tablejump_vms"
3862   [(set (match_dup 2)
3863       (match_operand:DI 0 "register_operand" ""))
3864         (set (pc)
3865         (plus:DI (match_dup 2)
3866                 (label_ref:DI (match_operand 1 "" ""))))]
3867   ""
3868   "
3869 { operands[2] = gen_reg_rtx (DImode); }")
3870
3871 (define_insn ""
3872   [(set (pc)
3873         (plus:DI (match_operand:DI 0 "register_operand" "r")
3874                  (label_ref:DI (match_operand 1 "" ""))))
3875    (clobber (match_scratch:DI 2 "=r"))]
3876   "! TARGET_WINDOWS_NT && ! TARGET_OPEN_VMS && next_active_insn (insn) != 0
3877    && GET_CODE (PATTERN (next_active_insn (insn))) == ADDR_DIFF_VEC
3878    && PREV_INSN (next_active_insn (insn)) == operands[1]"
3879   "*
3880 { rtx best_label = 0;
3881   rtx jump_table_insn = next_active_insn (operands[1]);
3882
3883   if (GET_CODE (jump_table_insn) == JUMP_INSN
3884       && GET_CODE (PATTERN (jump_table_insn)) == ADDR_DIFF_VEC)
3885     {
3886       rtx jump_table = PATTERN (jump_table_insn);
3887       int n_labels = XVECLEN (jump_table, 1);
3888       int best_count = -1;
3889       int i, j;
3890
3891       for (i = 0; i < n_labels; i++)
3892         {
3893           int count = 1;
3894
3895           for (j = i + 1; j < n_labels; j++)
3896             if (XEXP (XVECEXP (jump_table, 1, i), 0)
3897                 == XEXP (XVECEXP (jump_table, 1, j), 0))
3898               count++;
3899
3900           if (count > best_count)
3901             best_count = count, best_label = XVECEXP (jump_table, 1, i);
3902         }
3903     }
3904
3905   if (best_label)
3906     {
3907       operands[3] = best_label;
3908       return \"addq %0,$29,%2\;jmp $31,(%2),%3\";
3909     }
3910   else
3911     return \"addq %0,$29,%2\;jmp $31,(%2),0\";
3912 }"
3913   [(set_attr "type" "ibr")
3914    (set_attr "length" "8")])
3915
3916 (define_insn ""
3917   [(set (pc)
3918         (match_operand:DI 0 "register_operand" "r"))
3919    (use (label_ref (match_operand 1 "" "")))]
3920   "TARGET_WINDOWS_NT && next_active_insn (insn) != 0
3921    && GET_CODE (PATTERN (next_active_insn (insn))) == ADDR_DIFF_VEC
3922    && PREV_INSN (next_active_insn (insn)) == operands[1]"
3923   "*
3924 { rtx best_label = 0;
3925   rtx jump_table_insn = next_active_insn (operands[1]);
3926
3927   if (GET_CODE (jump_table_insn) == JUMP_INSN
3928       && GET_CODE (PATTERN (jump_table_insn)) == ADDR_DIFF_VEC)
3929     {
3930       rtx jump_table = PATTERN (jump_table_insn);
3931       int n_labels = XVECLEN (jump_table, 1);
3932       int best_count = -1;
3933       int i, j;
3934
3935       for (i = 0; i < n_labels; i++)
3936         {
3937           int count = 1;
3938
3939           for (j = i + 1; j < n_labels; j++)
3940             if (XEXP (XVECEXP (jump_table, 1, i), 0)
3941                 == XEXP (XVECEXP (jump_table, 1, j), 0))
3942               count++;
3943
3944           if (count > best_count)
3945             best_count = count, best_label = XVECEXP (jump_table, 1, i);
3946         }
3947     }
3948
3949   if (best_label)
3950     {
3951       operands[2] = best_label;
3952       return \"jmp $31,(%0),%2\";
3953     }
3954   else
3955     return \"jmp $31,(%0),0\";
3956 }"
3957   [(set_attr "type" "ibr")])
3958
3959 ;;
3960 ;; op 0 is table offset
3961 ;; op 1 is table label
3962 ;;
3963
3964 (define_insn ""
3965   [(set (pc)
3966         (plus:DI (match_operand 0 "register_operand" "r")
3967                 (label_ref (match_operand 1 "" ""))))]
3968   "TARGET_OPEN_VMS"
3969   "jmp $31,(%0),0"
3970   [(set_attr "type" "ibr")])
3971
3972 ;; Cache flush.  Used by INITIALIZE_TRAMPOLINE.  0x86 is PAL_imb, but we don't
3973 ;; want to have to include pal.h in our .s file.
3974 ;;
3975 ;; Technically the type for call_pal is jsr, but we use that for determining
3976 ;; if we need a GP.  Use ibr instead since it has the same EV5 scheduling
3977 ;; characteristics.
3978 (define_insn "imb"
3979   [(unspec_volatile [(const_int 0)] 0)]
3980   ""
3981   "call_pal 0x86"
3982   [(set_attr "type" "ibr")])
3983 \f
3984 ;; Finally, we have the basic data motion insns.  The byte and word insns
3985 ;; are done via define_expand.  Start with the floating-point insns, since
3986 ;; they are simpler.
3987
3988 (define_insn ""
3989   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,m,f,f,f,m")
3990         (match_operand:SF 1 "input_operand" "rG,m,rG,f,G,m,fG"))]
3991   "! TARGET_CIX
3992    && (register_operand (operands[0], SFmode)
3993        || reg_or_fp0_operand (operands[1], SFmode))"
3994   "@
3995    bis %r1,%r1,%0
3996    ldl %0,%1
3997    stl %r1,%0
3998    cpys %1,%1,%0
3999    cpys $f31,$f31,%0
4000    ld%, %0,%1
4001    st%, %R1,%0"
4002   [(set_attr "type" "ilog,ild,ist,fcpys,fcpys,fld,fst")])
4003
4004 (define_insn ""
4005   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,m,f,f,f,m,f,*r")
4006         (match_operand:SF 1 "input_operand" "rG,m,rG,f,G,m,fG,r,*f"))]
4007   "TARGET_CIX
4008    && (register_operand (operands[0], SFmode)
4009        || reg_or_fp0_operand (operands[1], SFmode))"
4010   "@
4011    bis %r1,%r1,%0
4012    ldl %0,%1
4013    stl %r1,%0
4014    cpys %1,%1,%0
4015    cpys $f31,$f31,%0
4016    ld%, %0,%1
4017    st%, %R1,%0
4018    itofs %1,%0
4019    ftois %1,%0"
4020   [(set_attr "type" "ilog,ild,ist,fcpys,fcpys,fld,fst,itof,ftoi")])
4021
4022 (define_insn ""
4023   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,f,f,f,m")
4024         (match_operand:DF 1 "input_operand" "rG,m,rG,f,G,m,fG"))]
4025   "! TARGET_CIX
4026    && (register_operand (operands[0], DFmode)
4027        || reg_or_fp0_operand (operands[1], DFmode))"
4028   "@
4029    bis %r1,%r1,%0
4030    ldq %0,%1
4031    stq %r1,%0
4032    cpys %1,%1,%0
4033    cpys $f31,$f31,%0
4034    ld%- %0,%1
4035    st%- %R1,%0"
4036   [(set_attr "type" "ilog,ild,ist,fcpys,fcpys,fld,fst")])
4037
4038 (define_insn ""
4039   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,f,f,f,m,f,*r")
4040         (match_operand:DF 1 "input_operand" "rG,m,rG,f,G,m,fG,r,*f"))]
4041   "TARGET_CIX
4042    && (register_operand (operands[0], DFmode)
4043        || reg_or_fp0_operand (operands[1], DFmode))"
4044   "@
4045    bis %r1,%r1,%0
4046    ldq %0,%1
4047    stq %r1,%0
4048    cpys %1,%1,%0
4049    cpys $f31,$f31,%0
4050    ld%- %0,%1
4051    st%- %R1,%0
4052    itoft %1,%0
4053    ftoit %1,%0"
4054   [(set_attr "type" "ilog,ild,ist,fcpys,fcpys,fld,fst,itof,ftoi")])
4055
4056 (define_expand "movsf"
4057   [(set (match_operand:SF 0 "nonimmediate_operand" "")
4058         (match_operand:SF 1 "general_operand" ""))]
4059   ""
4060   "
4061 {
4062   if (GET_CODE (operands[0]) == MEM
4063       && ! reg_or_fp0_operand (operands[1], SFmode))
4064     operands[1] = force_reg (SFmode, operands[1]);
4065 }")
4066
4067 (define_expand "movdf"
4068   [(set (match_operand:DF 0 "nonimmediate_operand" "")
4069         (match_operand:DF 1 "general_operand" ""))]
4070   ""
4071   "
4072 {
4073   if (GET_CODE (operands[0]) == MEM
4074       && ! reg_or_fp0_operand (operands[1], DFmode))
4075     operands[1] = force_reg (DFmode, operands[1]);
4076 }")
4077
4078 (define_insn ""
4079   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,r,r,m,f,f,f,m")
4080         (match_operand:SI 1 "input_operand" "r,J,I,K,L,m,rJ,f,J,m,fG"))]
4081   "! TARGET_WINDOWS_NT && ! TARGET_OPEN_VMS && ! TARGET_CIX
4082    && (register_operand (operands[0], SImode)
4083        || reg_or_0_operand (operands[1], SImode))"
4084   "@
4085    bis %1,%1,%0
4086    bis $31,$31,%0
4087    bis $31,%1,%0
4088    lda %0,%1
4089    ldah %0,%h1
4090    ldl %0,%1
4091    stl %r1,%0
4092    cpys %1,%1,%0
4093    cpys $f31,$f31,%0
4094    ld%, %0,%1
4095    st%, %R1,%0"
4096   [(set_attr "type" "ilog,ilog,ilog,iadd,iadd,ild,ist,fcpys,fcpys,fld,fst")])
4097
4098 (define_insn ""
4099   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,r,r,m,f,f,f,m,r,*f")
4100         (match_operand:SI 1 "input_operand" "r,J,I,K,L,m,rJ,f,J,m,fG,f,*r"))]
4101   "! TARGET_WINDOWS_NT && ! TARGET_OPEN_VMS && TARGET_CIX
4102    && (register_operand (operands[0], SImode)
4103        || reg_or_0_operand (operands[1], SImode))"
4104   "@
4105    bis %1,%1,%0
4106    bis $31,$31,%0
4107    bis $31,%1,%0
4108    lda %0,%1
4109    ldah %0,%h1
4110    ldl %0,%1
4111    stl %r1,%0
4112    cpys %1,%1,%0
4113    cpys $f31,$f31,%0
4114    ld%, %0,%1
4115    st%, %R1,%0
4116    ftois %1,%0
4117    itofs %1,%0"
4118   [(set_attr "type" "ilog,ilog,ilog,iadd,iadd,ild,ist,fcpys,fcpys,fld,fst,ftoi,itof")])
4119
4120 (define_insn ""
4121   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,r,r,r,m,f,f,f,m")
4122         (match_operand:SI 1 "input_operand" "r,J,I,K,L,s,m,rJ,f,J,m,fG"))]
4123   "(TARGET_WINDOWS_NT || TARGET_OPEN_VMS)
4124     && (register_operand (operands[0], SImode)
4125         || reg_or_0_operand (operands[1], SImode))"
4126   "@
4127    bis %1,%1,%0
4128    bis $31,$31,%0
4129    bis $31,%1,%0
4130    lda %0,%1
4131    ldah %0,%h1
4132    lda %0,%1
4133    ldl %0,%1
4134    stl %r1,%0
4135    cpys %1,%1,%0
4136    cpys $f31,$f31,%0
4137    ld%, %0,%1
4138    st%, %R1,%0"
4139   [(set_attr "type" "ilog,ilog,ilog,iadd,iadd,ldsym,ild,ist,fcpys,fcpys,fld,fst")])
4140
4141 (define_insn ""
4142   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,r,f,f")
4143         (match_operand:HI 1 "input_operand" "r,J,I,n,f,J"))]
4144   "! TARGET_BWX
4145    && (register_operand (operands[0], HImode)
4146        || register_operand (operands[1], HImode))"
4147   "@
4148    bis %1,%1,%0
4149    bis $31,$31,%0
4150    bis $31,%1,%0
4151    lda %0,%L1
4152    cpys %1,%1,%0
4153    cpys $f31,$f31,%0"
4154   [(set_attr "type" "ilog,ilog,ilog,iadd,fcpys,fcpys")])
4155
4156 (define_insn ""
4157   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,r,r,m,f,f")
4158         (match_operand:HI 1 "input_operand" "r,J,I,n,m,rJ,f,J"))]
4159   "TARGET_BWX
4160    && (register_operand (operands[0], HImode)
4161        || reg_or_0_operand (operands[1], HImode))"
4162   "@
4163    bis %1,%1,%0
4164    bis $31,$31,%0
4165    bis $31,%1,%0
4166    lda %0,%L1
4167    ldwu %0,%1
4168    stw %r1,%0
4169    cpys %1,%1,%0
4170    cpys $f31,$f31,%0"
4171   [(set_attr "type" "ilog,ilog,ilog,iadd,ild,ist,fcpys,fcpys")])
4172
4173 (define_insn ""
4174   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,r,r,f,f")
4175         (match_operand:QI 1 "input_operand" "r,J,I,n,f,J"))]
4176   "! TARGET_BWX
4177    && (register_operand (operands[0], QImode)
4178        || register_operand (operands[1], QImode))"
4179   "@
4180    bis %1,%1,%0
4181    bis $31,$31,%0
4182    bis $31,%1,%0
4183    lda %0,%L1
4184    cpys %1,%1,%0
4185    cpys $f31,$f31,%0"
4186   [(set_attr "type" "ilog,ilog,ilog,iadd,fcpys,fcpys")])
4187
4188 (define_insn ""
4189   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,r,r,r,m,f,f")
4190         (match_operand:QI 1 "input_operand" "r,J,I,n,m,rJ,f,J"))]
4191   "TARGET_BWX
4192    && (register_operand (operands[0], QImode)
4193        || reg_or_0_operand (operands[1], QImode))"
4194   "@
4195    bis %1,%1,%0
4196    bis $31,$31,%0
4197    bis $31,%1,%0
4198    lda %0,%L1
4199    ldbu %0,%1
4200    stb %r1,%0
4201    cpys %1,%1,%0
4202    cpys $f31,$f31,%0"
4203   [(set_attr "type" "ilog,ilog,ilog,iadd,ild,ist,fcpys,fcpys")])
4204
4205 ;; We do two major things here: handle mem->mem and construct long
4206 ;; constants.
4207
4208 (define_expand "movsi"
4209   [(set (match_operand:SI 0 "general_operand" "")
4210         (match_operand:SI 1 "general_operand" ""))]
4211   ""
4212   "
4213 {
4214   if (GET_CODE (operands[0]) == MEM
4215       && ! reg_or_0_operand (operands[1], SImode))
4216     operands[1] = force_reg (SImode, operands[1]);
4217
4218   if (! CONSTANT_P (operands[1]) || input_operand (operands[1], SImode))
4219     ;
4220   else if (GET_CODE (operands[1]) == CONST_INT)
4221     {
4222       operands[1]
4223         = alpha_emit_set_const (operands[0], SImode, INTVAL (operands[1]), 3);
4224       if (rtx_equal_p (operands[0], operands[1]))
4225         DONE;
4226     }
4227 }")
4228
4229 ;; Split a load of a large constant into the appropriate two-insn
4230 ;; sequence.
4231
4232 (define_split
4233   [(set (match_operand:SI 0 "register_operand" "")
4234         (match_operand:SI 1 "const_int_operand" ""))]
4235   "! add_operand (operands[1], SImode)"
4236   [(set (match_dup 0) (match_dup 2))
4237    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
4238   "
4239 { rtx tem
4240     = alpha_emit_set_const (operands[0], SImode, INTVAL (operands[1]), 2);
4241
4242   if (tem == operands[0])
4243     DONE;
4244   else
4245     FAIL;
4246 }")
4247
4248 (define_insn ""
4249   [(set (match_operand:DI 0 "general_operand" "=r,r,r,r,r,r,r,m,f,f,f,Q")
4250         (match_operand:DI 1 "input_operand" "r,J,I,K,L,s,m,rJ,f,J,Q,fG"))]
4251   "! TARGET_CIX
4252    && (register_operand (operands[0], DImode)
4253        || reg_or_0_operand (operands[1], DImode))"
4254   "@
4255    bis %1,%1,%0
4256    bis $31,$31,%0
4257    bis $31,%1,%0
4258    lda %0,%1
4259    ldah %0,%h1
4260    lda %0,%1
4261    ldq%A1 %0,%1
4262    stq%A0 %r1,%0
4263    cpys %1,%1,%0
4264    cpys $f31,$f31,%0
4265    ldt %0,%1
4266    stt %R1,%0"
4267   [(set_attr "type" "ilog,ilog,ilog,iadd,iadd,ldsym,ild,ist,fcpys,fcpys,fld,fst")])
4268
4269 (define_insn ""
4270   [(set (match_operand:DI 0 "general_operand" "=r,r,r,r,r,r,r,m,f,f,f,Q,r,*f")
4271         (match_operand:DI 1 "input_operand" "r,J,I,K,L,s,m,rJ,f,J,Q,fG,f,*r"))]
4272   "TARGET_CIX
4273    && (register_operand (operands[0], DImode)
4274        || reg_or_0_operand (operands[1], DImode))"
4275   "@
4276    bis %1,%1,%0
4277    bis $31,$31,%0
4278    bis $31,%1,%0
4279    lda %0,%1
4280    ldah %0,%h1
4281    lda %0,%1
4282    ldq%A1 %0,%1
4283    stq%A0 %r1,%0
4284    cpys %1,%1,%0
4285    cpys $f31,$f31,%0
4286    ldt %0,%1
4287    stt %R1,%0
4288    ftoit %1,%0
4289    itoft %1,%0"
4290   [(set_attr "type" "ilog,ilog,ilog,iadd,iadd,ldsym,ild,ist,fcpys,fcpys,fld,fst,ftoi,itof")])
4291
4292 ;; We do three major things here: handle mem->mem, put 64-bit constants in
4293 ;; memory, and construct long 32-bit constants.
4294
4295 (define_expand "movdi"
4296   [(set (match_operand:DI 0 "general_operand" "")
4297         (match_operand:DI 1 "general_operand" ""))]
4298   ""
4299   "
4300 {
4301   rtx tem;
4302
4303   if (GET_CODE (operands[0]) == MEM
4304       && ! reg_or_0_operand (operands[1], DImode))
4305     operands[1] = force_reg (DImode, operands[1]);
4306
4307   if (! CONSTANT_P (operands[1]) || input_operand (operands[1], DImode))
4308     ;
4309   else if (GET_CODE (operands[1]) == CONST_INT
4310            && (tem = alpha_emit_set_const (operands[0], DImode,
4311                                            INTVAL (operands[1]), 3)) != 0)
4312     {
4313       if (rtx_equal_p (tem, operands[0]))
4314         DONE;
4315       else
4316         operands[1] = tem;
4317     }
4318   else if (CONSTANT_P (operands[1]))
4319     {
4320       if (TARGET_BUILD_CONSTANTS)
4321         {
4322 #if HOST_BITS_PER_WIDE_INT == 64
4323           HOST_WIDE_INT i;
4324
4325           if (GET_CODE (operands[1]) == CONST_INT)
4326             i = INTVAL (operands[1]);
4327           else if (GET_CODE (operands[1]) == CONST_DOUBLE)
4328             i = CONST_DOUBLE_LOW (operands[1]);
4329           else
4330             abort();
4331           
4332           tem = alpha_emit_set_long_const (operands[0], i);
4333           if (rtx_equal_p (tem, operands[0]))
4334             DONE;
4335           else
4336             operands[1] = tem;
4337 #else
4338           abort();
4339 #endif
4340         }
4341       else
4342         {
4343           operands[1] = force_const_mem (DImode, operands[1]);
4344           if (reload_in_progress)
4345             {
4346               emit_move_insn (operands[0], XEXP (operands[1], 0));
4347               operands[1] = copy_rtx (operands[1]);
4348               XEXP (operands[1], 0) = operands[0];
4349             }
4350           else
4351             operands[1] = validize_mem (operands[1]);
4352         }
4353     }
4354   else
4355     abort ();
4356 }")
4357
4358 ;; Split a load of a large constant into the appropriate two-insn
4359 ;; sequence.
4360
4361 (define_split
4362   [(set (match_operand:DI 0 "register_operand" "")
4363         (match_operand:DI 1 "const_int_operand" ""))]
4364   "! add_operand (operands[1], DImode)"
4365   [(set (match_dup 0) (match_dup 2))
4366    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
4367   "
4368 { rtx tem
4369     = alpha_emit_set_const (operands[0], DImode, INTVAL (operands[1]), 2);
4370
4371   if (tem == operands[0])
4372     DONE;
4373   else
4374     FAIL;
4375 }")
4376
4377 ;; These are the partial-word cases.
4378 ;;
4379 ;; First we have the code to load an aligned word.  Operand 0 is the register
4380 ;; in which to place the result.  It's mode is QImode or HImode.  Operand 1
4381 ;; is an SImode MEM at the low-order byte of the proper word.  Operand 2 is the
4382 ;; number of bits within the word that the value is.  Operand 3 is an SImode
4383 ;; scratch register.  If operand 0 is a hard register, operand 3 may be the
4384 ;; same register.  It is allowed to conflict with operand 1 as well.
4385
4386 (define_expand "aligned_loadqi"
4387   [(set (match_operand:SI 3 "register_operand" "")
4388         (match_operand:SI 1 "memory_operand" ""))
4389    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
4390         (zero_extract:DI (subreg:DI (match_dup 3) 0)
4391                          (const_int 8)
4392                          (match_operand:DI 2 "const_int_operand" "")))]
4393          
4394   ""
4395   "")
4396   
4397 (define_expand "aligned_loadhi"
4398   [(set (match_operand:SI 3 "register_operand" "")
4399         (match_operand:SI 1 "memory_operand" ""))
4400    (set (subreg:DI (match_operand:HI 0 "register_operand" "") 0)
4401         (zero_extract:DI (subreg:DI (match_dup 3) 0)
4402                          (const_int 16)
4403                          (match_operand:DI 2 "const_int_operand" "")))]
4404          
4405   ""
4406   "")
4407   
4408 ;; Similar for unaligned loads, where we use the sequence from the
4409 ;; Alpha Architecture manual.
4410 ;;
4411 ;; Operand 1 is the address.  Operands 2 and 3 are temporaries, where
4412 ;; operand 3 can overlap the input and output registers.
4413
4414 (define_expand "unaligned_loadqi"
4415   [(set (match_operand:DI 2 "register_operand" "")
4416         (mem:DI (and:DI (match_operand:DI 1 "address_operand" "")
4417                         (const_int -8))))
4418    (set (match_operand:DI 3 "register_operand" "")
4419         (match_dup 1))
4420    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
4421         (zero_extract:DI (match_dup 2)
4422                          (const_int 8)
4423                          (ashift:DI (match_dup 3) (const_int 3))))]
4424   ""
4425   "")
4426
4427 (define_expand "unaligned_loadhi"
4428   [(set (match_operand:DI 2 "register_operand" "")
4429         (mem:DI (and:DI (match_operand:DI 1 "address_operand" "")
4430                         (const_int -8))))
4431    (set (match_operand:DI 3 "register_operand" "")
4432         (match_dup 1))
4433    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
4434         (zero_extract:DI (match_dup 2)
4435                          (const_int 16)
4436                          (ashift:DI (match_dup 3) (const_int 3))))]
4437   ""
4438   "")
4439
4440 ;; Storing an aligned byte or word requires two temporaries.  Operand 0 is the
4441 ;; aligned SImode MEM.  Operand 1 is the register containing the 
4442 ;; byte or word to store.  Operand 2 is the number of bits within the word that
4443 ;; the value should be placed.  Operands 3 and 4 are SImode temporaries.
4444
4445 (define_expand "aligned_store"
4446   [(set (match_operand:SI 3 "register_operand" "")
4447         (match_operand:SI 0 "memory_operand" ""))
4448    (set (subreg:DI (match_dup 3) 0)
4449         (and:DI (subreg:DI (match_dup 3) 0) (match_dup 5)))
4450    (set (subreg:DI (match_operand:SI 4 "register_operand" "") 0)
4451         (ashift:DI (zero_extend:DI (match_operand 1 "register_operand" ""))
4452                    (match_operand:DI 2 "const_int_operand" "")))
4453    (set (subreg:DI (match_dup 4) 0)
4454         (ior:DI (subreg:DI (match_dup 4) 0) (subreg:DI (match_dup 3) 0)))
4455    (set (match_dup 0) (match_dup 4))]
4456   ""
4457   "
4458 { operands[5] = GEN_INT (~ (GET_MODE_MASK (GET_MODE (operands[1]))
4459                             << INTVAL (operands[2])));
4460 }")
4461
4462 ;; For the unaligned byte and halfword cases, we use code similar to that
4463 ;; in the ;; Architecture book, but reordered to lower the number of registers
4464 ;; required.  Operand 0 is the address.  Operand 1 is the data to store.
4465 ;; Operands 2, 3, and 4 are DImode temporaries, where operands 2 and 4 may
4466 ;; be the same temporary, if desired.  If the address is in a register,
4467 ;; operand 2 can be that register.
4468
4469 (define_expand "unaligned_storeqi"
4470   [(set (match_operand:DI 3 "register_operand" "")
4471         (mem:DI (and:DI (match_operand:DI 0 "address_operand" "")
4472                         (const_int -8))))
4473    (set (match_operand:DI 2 "register_operand" "")
4474         (match_dup 0))
4475    (set (match_dup 3)
4476         (and:DI (not:DI (ashift:DI (const_int 255)
4477                                    (ashift:DI (match_dup 2) (const_int 3))))
4478                 (match_dup 3)))
4479    (set (match_operand:DI 4 "register_operand" "")
4480         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" ""))
4481                    (ashift:DI (match_dup 2) (const_int 3))))
4482    (set (match_dup 4) (ior:DI (match_dup 4) (match_dup 3)))
4483    (set (mem:DI (and:DI (match_dup 0) (const_int -8)))
4484         (match_dup 4))]
4485   ""
4486   "")
4487
4488 (define_expand "unaligned_storehi"
4489   [(set (match_operand:DI 3 "register_operand" "")
4490         (mem:DI (and:DI (match_operand:DI 0 "address_operand" "")
4491                         (const_int -8))))
4492    (set (match_operand:DI 2 "register_operand" "")
4493         (match_dup 0))
4494    (set (match_dup 3)
4495         (and:DI (not:DI (ashift:DI (const_int 65535)
4496                                    (ashift:DI (match_dup 2) (const_int 3))))
4497                 (match_dup 3)))
4498    (set (match_operand:DI 4 "register_operand" "")
4499         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" ""))
4500                    (ashift:DI (match_dup 2) (const_int 3))))
4501    (set (match_dup 4) (ior:DI (match_dup 4) (match_dup 3)))
4502    (set (mem:DI (and:DI (match_dup 0) (const_int -8)))
4503         (match_dup 4))]
4504   ""
4505   "")
4506 \f
4507 ;; Here are the define_expand's for QI and HI moves that use the above
4508 ;; patterns.  We have the normal sets, plus the ones that need scratch
4509 ;; registers for reload.
4510
4511 (define_expand "movqi"
4512   [(set (match_operand:QI 0 "general_operand" "")
4513         (match_operand:QI 1 "general_operand" ""))]
4514   ""
4515   "
4516 {
4517   if (TARGET_BWX)
4518     {
4519       if (GET_CODE (operands[0]) == MEM
4520           && ! reg_or_0_operand (operands[1], QImode))
4521         operands[1] = force_reg (QImode, operands[1]);
4522
4523       if (GET_CODE (operands[1]) == CONST_INT
4524                && ! input_operand (operands[1], QImode))
4525         {
4526           operands[1] = alpha_emit_set_const (operands[0], QImode,
4527                                               INTVAL (operands[1]), 3);
4528
4529           if (rtx_equal_p (operands[0], operands[1]))
4530             DONE;
4531         }
4532
4533       goto def;
4534     }
4535
4536   /* If the output is not a register, the input must be.  */
4537   if (GET_CODE (operands[0]) == MEM)
4538     operands[1] = force_reg (QImode, operands[1]);
4539
4540   /* Handle four memory cases, unaligned and aligned for either the input
4541      or the output.  The only case where we can be called during reload is
4542      for aligned loads; all other cases require temporaries.  */
4543
4544   if (GET_CODE (operands[1]) == MEM
4545       || (GET_CODE (operands[1]) == SUBREG
4546           && GET_CODE (SUBREG_REG (operands[1])) == MEM)
4547       || (reload_in_progress && GET_CODE (operands[1]) == REG
4548           && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER)
4549       || (reload_in_progress && GET_CODE (operands[1]) == SUBREG
4550           && GET_CODE (SUBREG_REG (operands[1])) == REG
4551           && REGNO (SUBREG_REG (operands[1])) >= FIRST_PSEUDO_REGISTER))
4552     {
4553       if (aligned_memory_operand (operands[1], QImode))
4554         {
4555           rtx aligned_mem, bitnum;
4556           rtx scratch = (reload_in_progress
4557                          ? gen_rtx_REG (SImode, REGNO (operands[0]))
4558                          : gen_reg_rtx (SImode));
4559
4560           get_aligned_mem (operands[1], &aligned_mem, &bitnum);
4561
4562           emit_insn (gen_aligned_loadqi (operands[0], aligned_mem, bitnum,
4563                                          scratch));
4564         }
4565       else
4566         {
4567           /* Don't pass these as parameters since that makes the generated
4568              code depend on parameter evaluation order which will cause
4569              bootstrap failures.  */
4570
4571           rtx temp1 = gen_reg_rtx (DImode);
4572           rtx temp2 = gen_reg_rtx (DImode);
4573           rtx seq
4574             = gen_unaligned_loadqi (operands[0],
4575                                     get_unaligned_address (operands[1], 0),
4576                                     temp1, temp2);
4577
4578           alpha_set_memflags (seq, operands[1]);
4579           emit_insn (seq);
4580         }
4581
4582       DONE;
4583     }
4584
4585   else if (GET_CODE (operands[0]) == MEM
4586            || (GET_CODE (operands[0]) == SUBREG 
4587                && GET_CODE (SUBREG_REG (operands[0])) == MEM)
4588            || (reload_in_progress && GET_CODE (operands[0]) == REG
4589                && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER)
4590            || (reload_in_progress && GET_CODE (operands[0]) == SUBREG
4591                && GET_CODE (SUBREG_REG (operands[0])) == REG
4592                && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER))
4593     {
4594       if (aligned_memory_operand (operands[0], QImode))
4595         {
4596           rtx aligned_mem, bitnum;
4597           rtx temp1 = gen_reg_rtx (SImode);
4598           rtx temp2 = gen_reg_rtx (SImode);
4599
4600           get_aligned_mem (operands[0], &aligned_mem, &bitnum);
4601
4602           emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
4603                                         temp1, temp2));
4604         }
4605       else
4606         {
4607           rtx temp1 = gen_reg_rtx (DImode);
4608           rtx temp2 = gen_reg_rtx (DImode);
4609           rtx temp3 = gen_reg_rtx (DImode);
4610           rtx seq
4611             = gen_unaligned_storeqi (get_unaligned_address (operands[0], 0),
4612                                            operands[1], temp1, temp2, temp3);
4613
4614           alpha_set_memflags (seq, operands[0]);
4615           emit_insn (seq);
4616         }
4617       DONE;
4618     }
4619  def:;
4620 }")
4621
4622 (define_expand "movhi"
4623   [(set (match_operand:HI 0 "general_operand" "")
4624         (match_operand:HI 1 "general_operand" ""))]
4625   ""
4626   "
4627 {
4628   if (TARGET_BWX)
4629     {
4630       if (GET_CODE (operands[0]) == MEM
4631           && ! reg_or_0_operand (operands[1], HImode))
4632         operands[1] = force_reg (HImode, operands[1]);
4633
4634       if (GET_CODE (operands[1]) == CONST_INT
4635                && ! input_operand (operands[1], HImode))
4636         {
4637           operands[1] = alpha_emit_set_const (operands[0], HImode,
4638                                               INTVAL (operands[1]), 3);
4639
4640           if (rtx_equal_p (operands[0], operands[1]))
4641             DONE;
4642         }
4643
4644       goto def;
4645     }
4646
4647   /* If the output is not a register, the input must be.  */
4648   if (GET_CODE (operands[0]) == MEM)
4649     operands[1] = force_reg (HImode, operands[1]);
4650
4651   /* Handle four memory cases, unaligned and aligned for either the input
4652      or the output.  The only case where we can be called during reload is
4653      for aligned loads; all other cases require temporaries.  */
4654
4655   if (GET_CODE (operands[1]) == MEM
4656       || (GET_CODE (operands[1]) == SUBREG
4657           && GET_CODE (SUBREG_REG (operands[1])) == MEM)
4658       || (reload_in_progress && GET_CODE (operands[1]) == REG
4659           && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER)
4660       || (reload_in_progress && GET_CODE (operands[1]) == SUBREG
4661           && GET_CODE (SUBREG_REG (operands[1])) == REG
4662           && REGNO (SUBREG_REG (operands[1])) >= FIRST_PSEUDO_REGISTER))
4663     {
4664       if (aligned_memory_operand (operands[1], HImode))
4665         {
4666           rtx aligned_mem, bitnum;
4667           rtx scratch = (reload_in_progress
4668                          ? gen_rtx_REG (SImode, REGNO (operands[0]))
4669                          : gen_reg_rtx (SImode));
4670
4671           get_aligned_mem (operands[1], &aligned_mem, &bitnum);
4672
4673           emit_insn (gen_aligned_loadhi (operands[0], aligned_mem, bitnum,
4674                                          scratch));
4675         }
4676       else
4677         {
4678           /* Don't pass these as parameters since that makes the generated
4679              code depend on parameter evaluation order which will cause
4680              bootstrap failures.  */
4681
4682           rtx temp1 = gen_reg_rtx (DImode);
4683           rtx temp2 = gen_reg_rtx (DImode);
4684           rtx seq
4685             = gen_unaligned_loadhi (operands[0],
4686                                     get_unaligned_address (operands[1], 0),
4687                                     temp1, temp2);
4688
4689           alpha_set_memflags (seq, operands[1]);
4690           emit_insn (seq);
4691         }
4692
4693       DONE;
4694     }
4695
4696   else if (GET_CODE (operands[0]) == MEM
4697            || (GET_CODE (operands[0]) == SUBREG 
4698                && GET_CODE (SUBREG_REG (operands[0])) == MEM)
4699            || (reload_in_progress && GET_CODE (operands[0]) == REG
4700                && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER)
4701            || (reload_in_progress && GET_CODE (operands[0]) == SUBREG
4702                && GET_CODE (SUBREG_REG (operands[0])) == REG
4703                && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER))
4704     {
4705       if (aligned_memory_operand (operands[0], HImode))
4706         {
4707           rtx aligned_mem, bitnum;
4708           rtx temp1 = gen_reg_rtx (SImode);
4709           rtx temp2 = gen_reg_rtx (SImode);
4710
4711           get_aligned_mem (operands[0], &aligned_mem, &bitnum);
4712
4713           emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
4714                                         temp1, temp2));
4715         }
4716       else
4717         {
4718           rtx temp1 = gen_reg_rtx (DImode);
4719           rtx temp2 = gen_reg_rtx (DImode);
4720           rtx temp3 = gen_reg_rtx (DImode);
4721           rtx seq
4722             = gen_unaligned_storehi (get_unaligned_address (operands[0], 0),
4723                                      operands[1], temp1, temp2, temp3);
4724
4725           alpha_set_memflags (seq, operands[0]);
4726           emit_insn (seq);
4727         }
4728
4729       DONE;
4730     }
4731  def:;
4732 }")
4733
4734 ;; Here are the versions for reload.  Note that in the unaligned cases
4735 ;; we know that the operand must not be a pseudo-register because stack
4736 ;; slots are always aligned references.
4737
4738 (define_expand "reload_inqi"
4739   [(parallel [(match_operand:QI 0 "register_operand" "=r")
4740               (match_operand:QI 1 "unaligned_memory_operand" "m")
4741               (match_operand:TI 2 "register_operand" "=&r")])]
4742   "! TARGET_BWX"
4743   "
4744 {
4745   rtx addr = get_unaligned_address (operands[1], 0);
4746
4747   /* It is possible that one of the registers we got for operands[2]
4748      might coincide with that of operands[0] (which is why we made
4749      it TImode).  Pick the other one to use as our scratch.  */
4750   rtx scratch = gen_rtx_REG (DImode,
4751                              REGNO (operands[0]) == REGNO (operands[2]) 
4752                              ? REGNO (operands[2]) + 1 : REGNO (operands[2]));
4753
4754   rtx seq = gen_unaligned_loadqi (operands[0], addr, scratch,
4755                                   gen_rtx_REG (DImode, REGNO (operands[0])));
4756
4757   alpha_set_memflags (seq, operands[1]);
4758   emit_insn (seq);
4759   DONE;
4760 }")
4761
4762 (define_expand "reload_inhi"
4763   [(parallel [(match_operand:HI 0 "register_operand" "=r")
4764               (match_operand:HI 1 "unaligned_memory_operand" "m")
4765               (match_operand:TI 2 "register_operand" "=&r")])]
4766   "! TARGET_BWX"
4767   "
4768 {
4769   rtx addr = get_unaligned_address (operands[1], 0);
4770
4771   /* It is possible that one of the registers we got for operands[2]
4772      might coincide with that of operands[0] (which is why we made
4773      it TImode).  Pick the other one to use as our scratch.  */
4774   rtx scratch = gen_rtx_REG (DImode,
4775                              REGNO (operands[0]) == REGNO (operands[2]) 
4776                              ? REGNO (operands[2]) + 1 : REGNO (operands[2]));
4777
4778   rtx seq = gen_unaligned_loadhi (operands[0], addr, scratch,
4779                                   gen_rtx_REG (DImode, REGNO (operands[0])));
4780
4781   alpha_set_memflags (seq, operands[1]);
4782   emit_insn (seq);
4783   DONE;
4784 }")
4785
4786 (define_expand "reload_outqi"
4787   [(parallel [(match_operand:QI 0 "any_memory_operand" "=m")
4788               (match_operand:QI 1 "register_operand" "r")
4789               (match_operand:TI 2 "register_operand" "=&r")])]
4790   "! TARGET_BWX"
4791   "
4792 {
4793   if (aligned_memory_operand (operands[0], QImode))
4794     {
4795       rtx aligned_mem, bitnum;
4796
4797       get_aligned_mem (operands[0], &aligned_mem, &bitnum);
4798
4799       emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
4800                                     gen_rtx_REG (SImode, REGNO (operands[2])),
4801                                     gen_rtx_REG (SImode,
4802                                                  REGNO (operands[2]) + 1)));
4803     }
4804   else
4805     {
4806       rtx addr = get_unaligned_address (operands[0], 0);
4807       rtx scratch1 = gen_rtx_REG (DImode, REGNO (operands[2]));
4808       rtx scratch2 = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
4809       rtx scratch3 = scratch1;
4810       rtx seq;
4811
4812       if (GET_CODE (addr) == REG)
4813         scratch1 = addr;
4814
4815       seq = gen_unaligned_storeqi (addr, operands[1], scratch1,
4816                                    scratch2, scratch3);
4817       alpha_set_memflags (seq, operands[0]);
4818       emit_insn (seq);
4819     }
4820
4821   DONE;
4822 }")
4823
4824 (define_expand "reload_outhi"
4825   [(parallel [(match_operand:HI 0 "any_memory_operand" "=m")
4826               (match_operand:HI 1 "register_operand" "r")
4827               (match_operand:TI 2 "register_operand" "=&r")])]
4828   "! TARGET_BWX"
4829   "
4830 {
4831   if (aligned_memory_operand (operands[0], HImode))
4832     {
4833       rtx aligned_mem, bitnum;
4834
4835       get_aligned_mem (operands[0], &aligned_mem, &bitnum);
4836
4837       emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
4838                                     gen_rtx_REG (SImode, REGNO (operands[2])),
4839                                     gen_rtx_REG (SImode,
4840                                                  REGNO (operands[2]) + 1)));
4841     }
4842   else
4843     {
4844       rtx addr = get_unaligned_address (operands[0], 0);
4845       rtx scratch1 = gen_rtx_REG (DImode, REGNO (operands[2]));
4846       rtx scratch2 = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
4847       rtx scratch3 = scratch1;
4848       rtx seq;
4849
4850       if (GET_CODE (addr) == REG)
4851         scratch1 = addr;
4852
4853       seq = gen_unaligned_storehi (addr, operands[1], scratch1,
4854                                    scratch2, scratch3);
4855       alpha_set_memflags (seq, operands[0]);
4856       emit_insn (seq);
4857     }
4858
4859   DONE;
4860 }")
4861 \f
4862 ;; Bit field extract patterns which use ext[wlq][lh]
4863
4864 (define_expand "extv"
4865   [(set (match_operand:DI 0 "register_operand" "")
4866         (sign_extract:DI (match_operand:QI 1 "memory_operand" "")
4867                          (match_operand:DI 2 "immediate_operand" "")
4868                          (match_operand:DI 3 "immediate_operand" "")))]
4869   ""
4870   "
4871 {
4872   /* We can do 16, 32 and 64 bit fields, if aligned on byte boundaries.  */
4873   if (INTVAL (operands[3]) % 8 != 0
4874       || (INTVAL (operands[2]) != 16
4875           && INTVAL (operands[2]) != 32
4876           && INTVAL (operands[2]) != 64))
4877     FAIL;
4878
4879   /* From mips.md: extract_bit_field doesn't verify that our source
4880      matches the predicate, so we force it to be a MEM here.  */
4881   if (GET_CODE (operands[1]) != MEM)
4882     FAIL;
4883
4884   alpha_expand_unaligned_load (operands[0], operands[1],
4885                                INTVAL (operands[2]) / 8,
4886                                INTVAL (operands[3]) / 8, 1);
4887   DONE;
4888 }")
4889
4890 (define_expand "extzv"
4891   [(set (match_operand:DI 0 "register_operand" "")
4892         (zero_extract:DI (match_operand:DI 1 "general_operand" "")
4893                          (match_operand:DI 2 "immediate_operand" "")
4894                          (match_operand:DI 3 "immediate_operand" "")))]
4895   ""
4896   "
4897 {
4898   /* We can do 8, 16, 32 and 64 bit fields, if aligned on byte boundaries.  */
4899   if (INTVAL (operands[3]) % 8 != 0
4900       || (INTVAL (operands[2]) != 8
4901           && INTVAL (operands[2]) != 16
4902           && INTVAL (operands[2]) != 32
4903           && INTVAL (operands[2]) != 64))
4904     FAIL;
4905
4906   if (GET_CODE (operands[1]) == MEM)
4907     {
4908       /* Fail 8 bit fields, falling back on a simple byte load.  */
4909       if (INTVAL (operands[2]) == 8)
4910         FAIL;
4911
4912       alpha_expand_unaligned_load (operands[0], operands[1],
4913                                    INTVAL (operands[2]) / 8,
4914                                    INTVAL (operands[3]) / 8, 0);
4915       DONE;
4916     }
4917 }")
4918
4919 (define_expand "insv"
4920   [(set (zero_extract:DI (match_operand:QI 0 "memory_operand" "")
4921                          (match_operand:DI 1 "immediate_operand" "")
4922                          (match_operand:DI 2 "immediate_operand" ""))
4923         (match_operand:DI 3 "register_operand" ""))]
4924   ""
4925   "
4926 {
4927   /* We can do 16, 32 and 64 bit fields, if aligned on byte boundaries.  */
4928   if (INTVAL (operands[2]) % 8 != 0
4929       || (INTVAL (operands[1]) != 16
4930           && INTVAL (operands[1]) != 32
4931           && INTVAL (operands[1]) != 64))
4932     FAIL;
4933
4934   /* From mips.md: store_bit_field doesn't verify that our source
4935      matches the predicate, so we force it to be a MEM here.  */
4936   if (GET_CODE (operands[0]) != MEM)
4937     FAIL;
4938
4939   alpha_expand_unaligned_store (operands[0], operands[3],
4940                                 INTVAL (operands[1]) / 8,
4941                                 INTVAL (operands[2]) / 8);
4942   DONE;
4943 }")
4944
4945
4946
4947 ;; Block move/clear, see alpha.c for more details.
4948 ;; Argument 0 is the destination
4949 ;; Argument 1 is the source
4950 ;; Argument 2 is the length
4951 ;; Argument 3 is the alignment
4952
4953 (define_expand "movstrqi"
4954   [(parallel [(set (match_operand:BLK 0 "general_operand" "")
4955                    (match_operand:BLK 1 "general_operand" ""))
4956               (use (match_operand:DI 2 "immediate_operand" ""))
4957               (use (match_operand:DI 3 "immediate_operand" ""))])]
4958   ""
4959   "
4960 {
4961   if (alpha_expand_block_move (operands))
4962     DONE;
4963   else
4964     FAIL;
4965 }")
4966
4967 (define_expand "clrstrqi"
4968   [(parallel [(set (match_operand:BLK 0 "general_operand" "")
4969                    (const_int 0))
4970               (use (match_operand:DI 1 "immediate_operand" ""))
4971               (use (match_operand:DI 2 "immediate_operand" ""))])]
4972   ""
4973   "
4974 {
4975   if (alpha_expand_block_clear (operands))
4976     DONE;
4977   else
4978     FAIL;
4979 }")
4980 \f
4981 ;; Subroutine of stack space allocation.  Perform a stack probe.
4982 (define_expand "probe_stack"
4983   [(set (match_dup 1) (match_operand:DI 0 "const_int_operand" ""))]
4984   ""
4985   "
4986 {
4987   operands[1] = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx,
4988                                                     INTVAL (operands[0])));
4989   MEM_VOLATILE_P (operands[1]) = 1;
4990
4991   operands[0] = const0_rtx;
4992 }")
4993
4994 ;; This is how we allocate stack space.  If we are allocating a
4995 ;; constant amount of space and we know it is less than 4096
4996 ;; bytes, we need do nothing.
4997 ;;
4998 ;; If it is more than 4096 bytes, we need to probe the stack
4999 ;; periodically. 
5000 (define_expand "allocate_stack"
5001   [(set (reg:DI 30)
5002         (plus:DI (reg:DI 30)
5003                  (match_operand:DI 1 "reg_or_cint_operand" "")))
5004    (set (match_operand:DI 0 "register_operand" "=r")
5005         (match_dup 2))]
5006   ""
5007   "
5008 {
5009   if (GET_CODE (operands[1]) == CONST_INT
5010       && INTVAL (operands[1]) < 32768)
5011     {
5012       if (INTVAL (operands[1]) >= 4096)
5013         {
5014           /* We do this the same way as in the prologue and generate explicit
5015              probes.  Then we update the stack by the constant.  */
5016
5017           int probed = 4096;
5018
5019           emit_insn (gen_probe_stack (GEN_INT (- probed)));
5020           while (probed + 8192 < INTVAL (operands[1]))
5021             emit_insn (gen_probe_stack (GEN_INT (- (probed += 8192))));
5022
5023           if (probed + 4096 < INTVAL (operands[1]))
5024             emit_insn (gen_probe_stack (GEN_INT (- INTVAL(operands[1]))));
5025         }
5026
5027       operands[1] = GEN_INT (- INTVAL (operands[1]));
5028       operands[2] = virtual_stack_dynamic_rtx;
5029     }
5030   else
5031     {
5032       rtx out_label = 0;
5033       rtx loop_label = gen_label_rtx ();
5034       rtx want = gen_reg_rtx (Pmode);
5035       rtx tmp = gen_reg_rtx (Pmode);
5036       rtx memref;
5037
5038       emit_insn (gen_subdi3 (want, stack_pointer_rtx,
5039                              force_reg (Pmode, operands[1])));
5040       emit_insn (gen_adddi3 (tmp, stack_pointer_rtx, GEN_INT (-4096)));
5041
5042       if (GET_CODE (operands[1]) != CONST_INT)
5043         {
5044           out_label = gen_label_rtx ();
5045           emit_insn (gen_cmpdi (want, tmp));
5046           emit_jump_insn (gen_bgeu (out_label));
5047         }
5048
5049       emit_label (loop_label);
5050       memref = gen_rtx_MEM (DImode, tmp);
5051       MEM_VOLATILE_P (memref) = 1;
5052       emit_move_insn (memref, const0_rtx);
5053       emit_insn (gen_adddi3 (tmp, tmp, GEN_INT(-8192)));
5054       emit_insn (gen_cmpdi (tmp, want));
5055       emit_jump_insn (gen_bgtu (loop_label));
5056       if (obey_regdecls)
5057         gen_rtx_USE (VOIDmode, tmp);
5058
5059       memref = gen_rtx_MEM (DImode, want);
5060       MEM_VOLATILE_P (memref) = 1;
5061       emit_move_insn (memref, const0_rtx);
5062
5063       if (out_label)
5064         emit_label (out_label);
5065
5066       emit_move_insn (stack_pointer_rtx, want);
5067       emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
5068       DONE;
5069     }
5070 }")
5071
5072 ;; This is used by alpha_expand_prolog to do the same thing as above,
5073 ;; except we cannot at that time generate new basic blocks, so we hide
5074 ;; the loop in this one insn.
5075
5076 (define_insn "prologue_stack_probe_loop"
5077   [(unspec_volatile [(match_operand 0 "register_operand" "r")
5078                      (match_operand 1 "register_operand" "r")] 5)]
5079   ""
5080   "*
5081 {
5082   static int label_no;
5083   int count_regno = REGNO (operands[0]);
5084   int ptr_regno = REGNO (operands[1]);
5085   char label[64];
5086
5087   /* Ho hum, output the hard way to get the label at the beginning of
5088      the line.  Wish there were a magic char you could get
5089      asm_output_printf to do that.  Then we could use %= as well and
5090      get rid of the label_no bits here too.  */
5091
5092   ASM_GENERATE_INTERNAL_LABEL (label, \"LSC\", label_no);
5093   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, \"LSC\", label_no++);
5094
5095   fprintf (asm_out_file, \"\\tstq $31,-8192($%d)\\n\", ptr_regno);
5096   fprintf (asm_out_file, \"\\tsubq $%d,1,$%d\\n\", count_regno, count_regno);
5097   fprintf (asm_out_file, \"\\tlda $%d,-8192($%d)\\n\", ptr_regno, ptr_regno);
5098   fprintf (asm_out_file, \"\\tbne $%d,\", count_regno);
5099   assemble_name (asm_out_file, label);
5100   putc ('\\n', asm_out_file);
5101
5102   return \"\";
5103 }"
5104   [(set_attr "length" "16")])
5105
5106 (define_expand "prologue"
5107   [(clobber (const_int 0))]
5108   ""
5109   "alpha_expand_prologue (); DONE;")
5110
5111 (define_insn "init_fp"
5112   [(set (match_operand:DI 0 "register_operand" "r")
5113         (match_operand:DI 1 "register_operand" "r"))
5114    (clobber (mem:BLK (match_operand:DI 2 "register_operand" "r")))]
5115   ""
5116   "bis %1,%1,%0")
5117
5118 (define_expand "epilogue"
5119   [(clobber (const_int 0))]
5120   ""
5121   "alpha_expand_epilogue (); DONE;")
5122
5123 (define_expand "builtin_longjmp"
5124   [(unspec_volatile [(match_operand 0 "register_operand" "r")] 3)]
5125   "! TARGET_OPEN_VMS && ! TARGET_WINDOWS_NT"
5126   "
5127 {
5128   /* The elements of the buffer are, in order:  */
5129   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
5130   rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 8));
5131   rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 16));
5132   rtx pv = gen_rtx_REG (Pmode, 27);
5133
5134   /* This bit is the same as expand_builtin_longjmp.  */
5135   emit_move_insn (hard_frame_pointer_rtx, fp);
5136   emit_move_insn (pv, lab);
5137   emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
5138   emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
5139   emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
5140
5141   /* Load the label we are jumping through into $27 so that we know
5142      where to look for it when we get back to setjmp's function for
5143      restoring the gp.  */
5144   emit_indirect_jump (pv);
5145 }")
5146
5147 (define_insn "builtin_setjmp_receiver"
5148   [(unspec_volatile [(match_operand 0 "" "")] 2)]
5149   "! TARGET_OPEN_VMS && ! TARGET_WINDOWS_NT && TARGET_AS_CAN_SUBTRACT_LABELS"
5150   "\\n$LSJ%=:\;ldgp $29,$LSJ%=-%l0($27)"
5151   [(set_attr "length" "8")])
5152
5153 (define_insn ""
5154   [(unspec_volatile [(match_operand 0 "" "")] 2)]
5155   "! TARGET_OPEN_VMS && ! TARGET_WINDOWS_NT"
5156   "br $27,$LSJ%=\\n$LSJ%=:\;ldgp $29,0($27)"
5157   [(set_attr "length" "12")])
5158
5159 (define_expand "nonlocal_goto_receiver"
5160   [(unspec_volatile [(const_int 0)] 1)
5161    (set (reg:DI 27) (mem:DI (reg:DI 29)))
5162    (unspec_volatile [(const_int 0)] 1)
5163    (use (reg:DI 27))]
5164   "TARGET_OPEN_VMS"
5165   "")
5166
5167 (define_insn "arg_home"
5168   [(unspec [(const_int 0)] 0)
5169    (use (reg:DI 1))
5170    (use (reg:DI 25))
5171    (use (reg:DI 16))
5172    (use (reg:DI 17))
5173    (use (reg:DI 18))
5174    (use (reg:DI 19))
5175    (use (reg:DI 20))
5176    (use (reg:DI 21))
5177    (use (reg:DI 48))
5178    (use (reg:DI 49))
5179    (use (reg:DI 50))
5180    (use (reg:DI 51))
5181    (use (reg:DI 52))
5182    (use (reg:DI 53))
5183    (clobber (mem:BLK (const_int 0)))
5184    (clobber (reg:DI 24))
5185    (clobber (reg:DI 25))
5186    (clobber (reg:DI 0))]
5187   "TARGET_OPEN_VMS"
5188   "lda $0,OTS$HOME_ARGS\;ldq $0,8($0)\;jsr $0,OTS$HOME_ARGS"
5189   [(set_attr "length" "16")])
5190
5191 ;; Close the trap shadow of preceeding instructions.  This is generated
5192 ;; by alpha_reorg.
5193
5194 (define_insn "trapb"
5195   [(unspec_volatile [(const_int 0)] 4)]
5196   ""
5197   "trapb"
5198   [(set_attr "type" "misc")])
5199 \f
5200 ;; Peepholes go at the end.
5201
5202 ;; Optimize sign-extension of SImode loads.  This shows up in the wake of
5203 ;; reload when converting fp->int.
5204 ;;
5205 ;; ??? What to do now that we actually care about the packing and
5206 ;; alignment of instructions?  Perhaps reload can be enlightened, or
5207 ;; the peephole pass moved up after reload but before sched2?
5208 ;
5209 ;(define_peephole
5210 ;  [(set (match_operand:SI 0 "register_operand" "=r")
5211 ;        (match_operand:SI 1 "memory_operand" "m"))
5212 ;   (set (match_operand:DI 2 "register_operand" "=r")
5213 ;        (sign_extend:DI (match_dup 0)))]
5214 ;  "dead_or_set_p (insn, operands[0])"
5215 ;  "ldl %2,%1")
5216 ;
5217 ;(define_peephole
5218 ;  [(set (match_operand:SI 0 "register_operand" "=r")
5219 ;        (match_operand:SI 1 "hard_fp_register_operand" "f"))
5220 ;   (set (match_operand:DI 2 "register_operand" "=r")
5221 ;        (sign_extend:DI (match_dup 0)))]
5222 ;  "TARGET_CIX && dead_or_set_p (insn, operands[0])"
5223 ;  "ftois %1,%2")