OSDN Git Service

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