OSDN Git Service

* config/alpha/alpha.c (print_operand) [+]: Remove.
[pf3gnuchains/gcc-fork.git] / gcc / config / alpha / alpha.md
1 ;; Machine description for DEC Alpha for GNU C compiler
2 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
4 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5 ;;
6 ;; This file is part of GCC.
7 ;;
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12 ;;
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;; GNU General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING.  If not, write to
20 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;; Uses of UNSPEC in this file:
26
27 (define_constants
28   [(UNSPEC_ARG_HOME     0)
29    (UNSPEC_LDGP1        1)
30    (UNSPEC_INSXH        2)
31    (UNSPEC_MSKXH        3)
32    (UNSPEC_CVTQL        4)
33    (UNSPEC_CVTLQ        5)
34    (UNSPEC_UMK_LAUM     6)
35    (UNSPEC_UMK_LALM     7)
36    (UNSPEC_UMK_LAL      8)
37    (UNSPEC_UMK_LOAD_CIW 9)
38    (UNSPEC_LDGP2        10)
39    (UNSPEC_LITERAL      11)
40    (UNSPEC_LITUSE       12)
41    (UNSPEC_SIBCALL      13)
42    (UNSPEC_SYMBOL       14)
43
44    ;; TLS Support
45    (UNSPEC_TLSGD_CALL   15)
46    (UNSPEC_TLSLDM_CALL  16)
47    (UNSPEC_TLSGD        17)
48    (UNSPEC_TLSLDM       18)
49    (UNSPEC_DTPREL       19)
50    (UNSPEC_TPREL        20)
51    (UNSPEC_TP           21)
52
53    ;; Builtins
54    (UNSPEC_CMPBGE       22)
55    (UNSPEC_ZAP          23)
56    (UNSPEC_AMASK        24)
57    (UNSPEC_IMPLVER      25)
58    (UNSPEC_PERR         26)
59    (UNSPEC_COPYSIGN     27)
60
61    ;; Atomic operations
62    (UNSPEC_MB           28)
63    (UNSPEC_ATOMIC       31)
64    (UNSPEC_CMPXCHG      32)
65    (UNSPEC_XCHG         33)
66   ])
67
68 ;; UNSPEC_VOLATILE:
69
70 (define_constants
71   [(UNSPECV_IMB         0)
72    (UNSPECV_BLOCKAGE    1)
73    (UNSPECV_SETJMPR     2)      ; builtin_setjmp_receiver
74    (UNSPECV_LONGJMP     3)      ; builtin_longjmp
75    (UNSPECV_TRAPB       4)
76    (UNSPECV_PSPL        5)      ; prologue_stack_probe_loop
77    (UNSPECV_REALIGN     6)
78    (UNSPECV_EHR         7)      ; exception_receiver
79    (UNSPECV_MCOUNT      8)
80    (UNSPECV_FORCE_MOV   9)
81    (UNSPECV_LDGP1       10)
82    (UNSPECV_PLDGP2      11)     ; prologue ldgp
83    (UNSPECV_SET_TP      12)
84    (UNSPECV_RPCC        13)
85    (UNSPECV_SETJMPR_ER  14)     ; builtin_setjmp_receiver fragment
86    (UNSPECV_LL          15)     ; load-locked
87    (UNSPECV_SC          16)     ; store-conditional
88   ])
89
90 ;; Where necessary, the suffixes _le and _be are used to distinguish between
91 ;; little-endian and big-endian patterns.
92 ;;
93 ;; Note that the Unicos/Mk assembler does not support the following
94 ;; opcodes: mov, fmov, nop, fnop, unop.
95 \f
96 ;; Processor type -- this attribute must exactly match the processor_type
97 ;; enumeration in alpha.h.
98
99 (define_attr "tune" "ev4,ev5,ev6"
100   (const (symbol_ref "alpha_tune")))
101
102 ;; Define an insn type attribute.  This is used in function unit delay
103 ;; computations, among other purposes.  For the most part, we use the names
104 ;; defined in the EV4 documentation, but add a few that we have to know about
105 ;; separately.
106
107 (define_attr "type"
108   "ild,fld,ldsym,ist,fst,ibr,callpal,fbr,jsr,iadd,ilog,shift,icmov,fcmov,
109    icmp,imul,fadd,fmul,fcpys,fdiv,fsqrt,misc,mvi,ftoi,itof,mb,ld_l,st_c,
110    multi,none"
111   (const_string "iadd"))
112
113 ;; Describe a user's asm statement.
114 (define_asm_attributes
115   [(set_attr "type" "multi")])
116
117 ;; Define the operand size an insn operates on.  Used primarily by mul
118 ;; and div operations that have size dependent timings.
119
120 (define_attr "opsize" "si,di,udi"
121   (const_string "di"))
122
123 ;; The TRAP attribute marks instructions that may generate traps
124 ;; (which are imprecise and may need a trapb if software completion
125 ;; is desired).
126
127 (define_attr "trap" "no,yes"
128   (const_string "no"))
129
130 ;; The ROUND_SUFFIX attribute marks which instructions require a
131 ;; rounding-mode suffix.  The value NONE indicates no suffix,
132 ;; the value NORMAL indicates a suffix controlled by alpha_fprm.
133
134 (define_attr "round_suffix" "none,normal,c"
135   (const_string "none"))
136
137 ;; The TRAP_SUFFIX attribute marks instructions requiring a trap-mode suffix:
138 ;;   NONE       no suffix
139 ;;   SU         accepts only /su (cmpt et al)
140 ;;   SUI        accepts only /sui (cvtqt and cvtqs)
141 ;;   V_SV       accepts /v and /sv (cvtql only)
142 ;;   V_SV_SVI   accepts /v, /sv and /svi (cvttq only)
143 ;;   U_SU_SUI   accepts /u, /su and /sui (most fp instructions)
144 ;;
145 ;; The actual suffix emitted is controlled by alpha_fptm.
146
147 (define_attr "trap_suffix" "none,su,sui,v_sv,v_sv_svi,u_su_sui"
148   (const_string "none"))
149
150 ;; The length of an instruction sequence in bytes.
151
152 (define_attr "length" ""
153   (const_int 4))
154
155 ;; The USEGP attribute marks instructions that have relocations that use
156 ;; the GP.
157
158 (define_attr "usegp" "no,yes"
159   (cond [(eq_attr "type" "ldsym,jsr")
160            (const_string "yes")
161          (eq_attr "type" "ild,fld,ist,fst")
162            (symbol_ref "alpha_find_lo_sum_using_gp(insn)")
163         ]
164         (const_string "no")))
165
166 ;; The CANNOT_COPY attribute marks instructions with relocations that
167 ;; cannot easily be duplicated.  This includes insns with gpdisp relocs
168 ;; since they have to stay in 1-1 correspondence with one another.  This
169 ;; also includes jsr insns, since they must stay in correspondence with
170 ;; the immediately following gpdisp instructions.
171
172 (define_attr "cannot_copy" "false,true"
173   (const_string "false"))
174 \f
175 ;; Include scheduling descriptions.
176   
177 (include "ev4.md")
178 (include "ev5.md")
179 (include "ev6.md")
180
181 \f
182 ;; Operand and operator predicates and constraints
183
184 (include "predicates.md")
185 (include "constraints.md")
186
187 \f
188 ;; First define the arithmetic insns.  Note that the 32-bit forms also
189 ;; sign-extend.
190
191 ;; Handle 32-64 bit extension from memory to a floating point register
192 ;; specially, since this occurs frequently in int->double conversions.
193 ;;
194 ;; Note that while we must retain the =f case in the insn for reload's
195 ;; benefit, it should be eliminated after reload, so we should never emit
196 ;; code for that case.  But we don't reject the possibility.
197
198 (define_expand "extendsidi2"
199   [(set (match_operand:DI 0 "register_operand" "")
200         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))]
201   ""
202   "")
203
204 (define_insn "*cvtlq"
205   [(set (match_operand:DI 0 "register_operand" "=f")
206         (unspec:DI [(match_operand:SF 1 "reg_or_0_operand" "fG")]
207                    UNSPEC_CVTLQ))]
208   ""
209   "cvtlq %1,%0"
210   [(set_attr "type" "fadd")])
211
212 (define_insn "*extendsidi2_1"
213   [(set (match_operand:DI 0 "register_operand" "=r,r,!*f")
214         (sign_extend:DI
215           (match_operand:SI 1 "nonimmediate_operand" "r,m,m")))]
216   ""
217   "@
218    addl $31,%1,%0
219    ldl %0,%1
220    lds %0,%1\;cvtlq %0,%0"
221   [(set_attr "type" "iadd,ild,fld")
222    (set_attr "length" "*,*,8")])
223
224 (define_split
225   [(set (match_operand:DI 0 "hard_fp_register_operand" "")
226         (sign_extend:DI (match_operand:SI 1 "memory_operand" "")))]
227   "reload_completed"
228   [(set (match_dup 2) (match_dup 1))
229    (set (match_dup 0) (unspec:DI [(match_dup 2)] UNSPEC_CVTLQ))]
230 {
231   operands[1] = adjust_address (operands[1], SFmode, 0);
232   operands[2] = gen_rtx_REG (SFmode, REGNO (operands[0]));
233 })
234
235 ;; Optimize sign-extension of SImode loads.  This shows up in the wake of
236 ;; reload when converting fp->int.
237
238 (define_peephole2
239   [(set (match_operand:SI 0 "hard_int_register_operand" "")
240         (match_operand:SI 1 "memory_operand" ""))
241    (set (match_operand:DI 2 "hard_int_register_operand" "")
242         (sign_extend:DI (match_dup 0)))]
243   "true_regnum (operands[0]) == true_regnum (operands[2])
244    || peep2_reg_dead_p (2, operands[0])"
245   [(set (match_dup 2)
246         (sign_extend:DI (match_dup 1)))]
247   "")
248
249 ;; Don't say we have addsi3 if optimizing.  This generates better code.  We
250 ;; have the anonymous addsi3 pattern below in case combine wants to make it.
251 (define_expand "addsi3"
252   [(set (match_operand:SI 0 "register_operand" "")
253         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "")
254                  (match_operand:SI 2 "add_operand" "")))]
255   "! optimize"
256   "")
257
258 (define_insn "*addsi_internal"
259   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
260         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ,rJ,rJ")
261                  (match_operand:SI 2 "add_operand" "rI,O,K,L")))]
262   ""
263   "@
264    addl %r1,%2,%0
265    subl %r1,%n2,%0
266    lda %0,%2(%r1)
267    ldah %0,%h2(%r1)")
268
269 (define_split
270   [(set (match_operand:SI 0 "register_operand" "")
271         (plus:SI (match_operand:SI 1 "register_operand" "")
272                  (match_operand:SI 2 "const_int_operand" "")))]
273   "! add_operand (operands[2], SImode)"
274   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
275    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
276 {
277   HOST_WIDE_INT val = INTVAL (operands[2]);
278   HOST_WIDE_INT low = (val & 0xffff) - 2 * (val & 0x8000);
279   HOST_WIDE_INT rest = val - low;
280
281   operands[3] = GEN_INT (rest);
282   operands[4] = GEN_INT (low);
283 })
284
285 (define_insn "*addsi_se"
286   [(set (match_operand:DI 0 "register_operand" "=r,r")
287         (sign_extend:DI
288          (plus:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ")
289                   (match_operand:SI 2 "sext_add_operand" "rI,O"))))]
290   ""
291   "@
292    addl %r1,%2,%0
293    subl %r1,%n2,%0")
294
295 (define_insn "*addsi_se2"
296   [(set (match_operand:DI 0 "register_operand" "=r,r")
297         (sign_extend:DI
298          (subreg:SI (plus:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ")
299                              (match_operand:DI 2 "sext_add_operand" "rI,O"))
300                     0)))]
301   ""
302   "@
303    addl %r1,%2,%0
304    subl %r1,%n2,%0")
305
306 (define_split
307   [(set (match_operand:DI 0 "register_operand" "")
308         (sign_extend:DI
309          (plus:SI (match_operand:SI 1 "reg_not_elim_operand" "")
310                   (match_operand:SI 2 "const_int_operand" ""))))
311    (clobber (match_operand:SI 3 "reg_not_elim_operand" ""))]
312   "! sext_add_operand (operands[2], SImode) && INTVAL (operands[2]) > 0
313    && INTVAL (operands[2]) % 4 == 0"
314   [(set (match_dup 3) (match_dup 4))
315    (set (match_dup 0) (sign_extend:DI (plus:SI (mult:SI (match_dup 3)
316                                                         (match_dup 5))
317                                                (match_dup 1))))]
318 {
319   HOST_WIDE_INT val = INTVAL (operands[2]) / 4;
320   int mult = 4;
321
322   if (val % 2 == 0)
323     val /= 2, mult = 8;
324
325   operands[4] = GEN_INT (val);
326   operands[5] = GEN_INT (mult);
327 })
328
329 (define_split
330   [(set (match_operand:DI 0 "register_operand" "")
331         (sign_extend:DI
332          (plus:SI (match_operator:SI 1 "comparison_operator"
333                                      [(match_operand 2 "" "")
334                                       (match_operand 3 "" "")])
335                   (match_operand:SI 4 "add_operand" ""))))
336    (clobber (match_operand:DI 5 "register_operand" ""))]
337   ""
338   [(set (match_dup 5) (match_dup 6))
339    (set (match_dup 0) (sign_extend:DI (plus:SI (match_dup 7) (match_dup 4))))]
340 {
341   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[1]), DImode,
342                                 operands[2], operands[3]);
343   operands[7] = gen_lowpart (SImode, operands[5]);
344 })
345
346 (define_insn "addvsi3"
347   [(set (match_operand:SI 0 "register_operand" "=r,r")
348         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ")
349                  (match_operand:SI 2 "sext_add_operand" "rI,O")))
350    (trap_if (ne (plus:DI (sign_extend:DI (match_dup 1))
351                          (sign_extend:DI (match_dup 2)))
352                 (sign_extend:DI (plus:SI (match_dup 1)
353                                          (match_dup 2))))
354             (const_int 0))]
355   ""
356   "@
357    addlv %r1,%2,%0
358    sublv %r1,%n2,%0")
359
360 (define_expand "adddi3"
361   [(set (match_operand:DI 0 "register_operand" "")
362         (plus:DI (match_operand:DI 1 "register_operand" "")
363                  (match_operand:DI 2 "add_operand" "")))]
364   ""
365   "")
366
367 (define_insn "*adddi_er_lo16_dtp"
368   [(set (match_operand:DI 0 "register_operand" "=r")
369         (lo_sum:DI (match_operand:DI 1 "register_operand" "r")
370                    (match_operand:DI 2 "dtp16_symbolic_operand" "")))]
371   "HAVE_AS_TLS"
372   "lda %0,%2(%1)\t\t!dtprel")
373
374 (define_insn "*adddi_er_hi32_dtp"
375   [(set (match_operand:DI 0 "register_operand" "=r")
376         (plus:DI (match_operand:DI 1 "register_operand" "r")
377                  (high:DI (match_operand:DI 2 "dtp32_symbolic_operand" ""))))]
378   "HAVE_AS_TLS"
379   "ldah %0,%2(%1)\t\t!dtprelhi")
380
381 (define_insn "*adddi_er_lo32_dtp"
382   [(set (match_operand:DI 0 "register_operand" "=r")
383         (lo_sum:DI (match_operand:DI 1 "register_operand" "r")
384                    (match_operand:DI 2 "dtp32_symbolic_operand" "")))]
385   "HAVE_AS_TLS"
386   "lda %0,%2(%1)\t\t!dtprello")
387
388 (define_insn "*adddi_er_lo16_tp"
389   [(set (match_operand:DI 0 "register_operand" "=r")
390         (lo_sum:DI (match_operand:DI 1 "register_operand" "r")
391                    (match_operand:DI 2 "tp16_symbolic_operand" "")))]
392   "HAVE_AS_TLS"
393   "lda %0,%2(%1)\t\t!tprel")
394
395 (define_insn "*adddi_er_hi32_tp"
396   [(set (match_operand:DI 0 "register_operand" "=r")
397         (plus:DI (match_operand:DI 1 "register_operand" "r")
398                  (high:DI (match_operand:DI 2 "tp32_symbolic_operand" ""))))]
399   "HAVE_AS_TLS"
400   "ldah %0,%2(%1)\t\t!tprelhi")
401
402 (define_insn "*adddi_er_lo32_tp"
403   [(set (match_operand:DI 0 "register_operand" "=r")
404         (lo_sum:DI (match_operand:DI 1 "register_operand" "r")
405                    (match_operand:DI 2 "tp32_symbolic_operand" "")))]
406   "HAVE_AS_TLS"
407   "lda %0,%2(%1)\t\t!tprello")
408
409 (define_insn "*adddi_er_high_l"
410   [(set (match_operand:DI 0 "register_operand" "=r")
411         (plus:DI (match_operand:DI 1 "register_operand" "r")
412                  (high:DI (match_operand:DI 2 "local_symbolic_operand" ""))))]
413   "TARGET_EXPLICIT_RELOCS && reload_completed"
414   "ldah %0,%2(%1)\t\t!gprelhigh"
415   [(set_attr "usegp" "yes")])
416
417 (define_split
418   [(set (match_operand:DI 0 "register_operand" "")
419         (high:DI (match_operand:DI 1 "local_symbolic_operand" "")))]
420   "TARGET_EXPLICIT_RELOCS && reload_completed"
421   [(set (match_dup 0)
422         (plus:DI (match_dup 2) (high:DI (match_dup 1))))]
423   "operands[2] = pic_offset_table_rtx;")
424
425 ;; We used to expend quite a lot of effort choosing addq/subq/lda.
426 ;; With complications like
427 ;;
428 ;;   The NT stack unwind code can't handle a subq to adjust the stack
429 ;;   (that's a bug, but not one we can do anything about).  As of NT4.0 SP3,
430 ;;   the exception handling code will loop if a subq is used and an
431 ;;   exception occurs.
432 ;;
433 ;;   The 19980616 change to emit prologues as RTL also confused some
434 ;;   versions of GDB, which also interprets prologues.  This has been
435 ;;   fixed as of GDB 4.18, but it does not harm to unconditionally
436 ;;   use lda here.
437 ;;
438 ;; and the fact that the three insns schedule exactly the same, it's
439 ;; just not worth the effort.
440
441 (define_insn "*adddi_internal"
442   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
443         (plus:DI (match_operand:DI 1 "register_operand" "%r,r,r")
444                  (match_operand:DI 2 "add_operand" "r,K,L")))]
445   ""
446   "@
447    addq %1,%2,%0
448    lda %0,%2(%1)
449    ldah %0,%h2(%1)")
450
451 ;; ??? Allow large constants when basing off the frame pointer or some
452 ;; virtual register that may eliminate to the frame pointer.  This is
453 ;; done because register elimination offsets will change the hi/lo split,
454 ;; and if we split before reload, we will require additional instructions.
455
456 (define_insn "*adddi_fp_hack"
457   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
458         (plus:DI (match_operand:DI 1 "reg_no_subreg_operand" "r,r,r")
459                  (match_operand:DI 2 "const_int_operand" "K,L,n")))]
460   "NONSTRICT_REG_OK_FP_BASE_P (operands[1])
461    && INTVAL (operands[2]) >= 0
462    /* This is the largest constant an lda+ldah pair can add, minus
463       an upper bound on the displacement between SP and AP during
464       register elimination.  See INITIAL_ELIMINATION_OFFSET.  */
465    && INTVAL (operands[2])
466         < (0x7fff8000
467            - FIRST_PSEUDO_REGISTER * UNITS_PER_WORD
468            - ALPHA_ROUND(current_function_outgoing_args_size)
469            - (ALPHA_ROUND (get_frame_size ()
470                            + max_reg_num () * UNITS_PER_WORD
471                            + current_function_pretend_args_size)
472               - current_function_pretend_args_size))"
473   "@
474    lda %0,%2(%1)
475    ldah %0,%h2(%1)
476    #")
477
478 ;; Don't do this if we are adjusting SP since we don't want to do it
479 ;; in two steps.  Don't split FP sources for the reason listed above.
480 (define_split
481   [(set (match_operand:DI 0 "register_operand" "")
482         (plus:DI (match_operand:DI 1 "register_operand" "")
483                  (match_operand:DI 2 "const_int_operand" "")))]
484   "! add_operand (operands[2], DImode)
485    && operands[0] != stack_pointer_rtx
486    && operands[1] != frame_pointer_rtx
487    && operands[1] != arg_pointer_rtx"
488   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
489    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
490 {
491   HOST_WIDE_INT val = INTVAL (operands[2]);
492   HOST_WIDE_INT low = (val & 0xffff) - 2 * (val & 0x8000);
493   HOST_WIDE_INT rest = val - low;
494   rtx rest_rtx = GEN_INT (rest);
495
496   operands[4] = GEN_INT (low);
497   if (satisfies_constraint_L (rest_rtx))
498     operands[3] = rest_rtx;
499   else if (! no_new_pseudos)
500     {
501       operands[3] = gen_reg_rtx (DImode);
502       emit_move_insn (operands[3], operands[2]);
503       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
504       DONE;
505     }
506   else
507     FAIL;
508 })
509
510 (define_insn "*saddl"
511   [(set (match_operand:SI 0 "register_operand" "=r,r")
512         (plus:SI (mult:SI (match_operand:SI 1 "reg_not_elim_operand" "r,r")
513                           (match_operand:SI 2 "const48_operand" "I,I"))
514                  (match_operand:SI 3 "sext_add_operand" "rI,O")))]
515   ""
516   "@
517    s%2addl %1,%3,%0
518    s%2subl %1,%n3,%0")
519
520 (define_insn "*saddl_se"
521   [(set (match_operand:DI 0 "register_operand" "=r,r")
522         (sign_extend:DI
523          (plus:SI (mult:SI (match_operand:SI 1 "reg_not_elim_operand" "r,r")
524                            (match_operand:SI 2 "const48_operand" "I,I"))
525                   (match_operand:SI 3 "sext_add_operand" "rI,O"))))]
526   ""
527   "@
528    s%2addl %1,%3,%0
529    s%2subl %1,%n3,%0")
530
531 (define_split
532   [(set (match_operand:DI 0 "register_operand" "")
533         (sign_extend:DI
534          (plus:SI (mult:SI (match_operator:SI 1 "comparison_operator"
535                                               [(match_operand 2 "" "")
536                                                (match_operand 3 "" "")])
537                            (match_operand:SI 4 "const48_operand" ""))
538                   (match_operand:SI 5 "sext_add_operand" ""))))
539    (clobber (match_operand:DI 6 "reg_not_elim_operand" ""))]
540   ""
541   [(set (match_dup 6) (match_dup 7))
542    (set (match_dup 0)
543         (sign_extend:DI (plus:SI (mult:SI (match_dup 8) (match_dup 4))
544                                  (match_dup 5))))]
545 {
546   operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[1]), DImode,
547                                 operands[2], operands[3]);
548   operands[8] = gen_lowpart (SImode, operands[6]);
549 })
550
551 (define_insn "*saddq"
552   [(set (match_operand:DI 0 "register_operand" "=r,r")
553         (plus:DI (mult:DI (match_operand:DI 1 "reg_not_elim_operand" "r,r")
554                           (match_operand:DI 2 "const48_operand" "I,I"))
555                  (match_operand:DI 3 "sext_add_operand" "rI,O")))]
556   ""
557   "@
558    s%2addq %1,%3,%0
559    s%2subq %1,%n3,%0")
560
561 (define_insn "addvdi3"
562   [(set (match_operand:DI 0 "register_operand" "=r,r")
563         (plus:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ")
564                  (match_operand:DI 2 "sext_add_operand" "rI,O")))
565    (trap_if (ne (plus:TI (sign_extend:TI (match_dup 1))
566                          (sign_extend:TI (match_dup 2)))
567                 (sign_extend:TI (plus:DI (match_dup 1)
568                                          (match_dup 2))))
569             (const_int 0))]
570   ""
571   "@
572    addqv %r1,%2,%0
573    subqv %r1,%n2,%0")
574
575 (define_insn "negsi2"
576   [(set (match_operand:SI 0 "register_operand" "=r")
577         (neg:SI (match_operand:SI 1 "reg_or_8bit_operand" "rI")))]
578   ""
579   "subl $31,%1,%0")
580
581 (define_insn "*negsi_se"
582   [(set (match_operand:DI 0 "register_operand" "=r")
583         (sign_extend:DI (neg:SI
584                          (match_operand:SI 1 "reg_or_8bit_operand" "rI"))))]
585   ""
586   "subl $31,%1,%0")
587
588 (define_insn "negvsi2"
589   [(set (match_operand:SI 0 "register_operand" "=r")
590         (neg:SI (match_operand:SI 1 "register_operand" "r")))
591    (trap_if (ne (neg:DI (sign_extend:DI (match_dup 1)))
592                 (sign_extend:DI (neg:SI (match_dup 1))))
593             (const_int 0))]
594   ""
595   "sublv $31,%1,%0")
596
597 (define_insn "negdi2"
598   [(set (match_operand:DI 0 "register_operand" "=r")
599         (neg:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI")))]
600   ""
601   "subq $31,%1,%0")
602
603 (define_insn "negvdi2"
604   [(set (match_operand:DI 0 "register_operand" "=r")
605         (neg:DI (match_operand:DI 1 "register_operand" "r")))
606    (trap_if (ne (neg:TI (sign_extend:TI (match_dup 1)))
607                 (sign_extend:TI (neg:DI (match_dup 1))))
608             (const_int 0))]
609   ""
610   "subqv $31,%1,%0")
611
612 (define_expand "subsi3"
613   [(set (match_operand:SI 0 "register_operand" "")
614         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "")
615                   (match_operand:SI 2 "reg_or_8bit_operand" "")))]
616   "! optimize"
617   "")
618
619 (define_insn "*subsi_internal"
620   [(set (match_operand:SI 0 "register_operand" "=r")
621         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "rJ")
622                   (match_operand:SI 2 "reg_or_8bit_operand" "rI")))]
623   ""
624   "subl %r1,%2,%0")
625
626 (define_insn "*subsi_se"
627   [(set (match_operand:DI 0 "register_operand" "=r")
628         (sign_extend:DI (minus:SI (match_operand:SI 1 "reg_or_0_operand" "rJ")
629                                   (match_operand:SI 2 "reg_or_8bit_operand" "rI"))))]
630   ""
631   "subl %r1,%2,%0")
632
633 (define_insn "*subsi_se2"
634   [(set (match_operand:DI 0 "register_operand" "=r")
635         (sign_extend:DI
636          (subreg:SI (minus:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
637                               (match_operand:DI 2 "reg_or_8bit_operand" "rI"))
638                     0)))]
639   ""
640   "subl %r1,%2,%0")
641
642 (define_insn "subvsi3"
643   [(set (match_operand:SI 0 "register_operand" "=r")
644         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "rJ")
645                   (match_operand:SI 2 "reg_or_8bit_operand" "rI")))
646    (trap_if (ne (minus:DI (sign_extend:DI (match_dup 1))
647                           (sign_extend:DI (match_dup 2)))
648                 (sign_extend:DI (minus:SI (match_dup 1)
649                                           (match_dup 2))))
650             (const_int 0))]
651   ""
652   "sublv %r1,%2,%0")
653
654 (define_insn "subdi3"
655   [(set (match_operand:DI 0 "register_operand" "=r")
656         (minus:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
657                   (match_operand:DI 2 "reg_or_8bit_operand" "rI")))]
658   ""
659   "subq %r1,%2,%0")
660
661 (define_insn "*ssubl"
662   [(set (match_operand:SI 0 "register_operand" "=r")
663         (minus:SI (mult:SI (match_operand:SI 1 "reg_not_elim_operand" "r")
664                            (match_operand:SI 2 "const48_operand" "I"))
665                   (match_operand:SI 3 "reg_or_8bit_operand" "rI")))]
666   ""
667   "s%2subl %1,%3,%0")
668
669 (define_insn "*ssubl_se"
670   [(set (match_operand:DI 0 "register_operand" "=r")
671         (sign_extend:DI
672          (minus:SI (mult:SI (match_operand:SI 1 "reg_not_elim_operand" "r")
673                             (match_operand:SI 2 "const48_operand" "I"))
674                    (match_operand:SI 3 "reg_or_8bit_operand" "rI"))))]
675   ""
676   "s%2subl %1,%3,%0")
677
678 (define_insn "*ssubq"
679   [(set (match_operand:DI 0 "register_operand" "=r")
680         (minus:DI (mult:DI (match_operand:DI 1 "reg_not_elim_operand" "r")
681                            (match_operand:DI 2 "const48_operand" "I"))
682                   (match_operand:DI 3 "reg_or_8bit_operand" "rI")))]
683   ""
684   "s%2subq %1,%3,%0")
685
686 (define_insn "subvdi3"
687   [(set (match_operand:DI 0 "register_operand" "=r")
688         (minus:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
689                   (match_operand:DI 2 "reg_or_8bit_operand" "rI")))
690    (trap_if (ne (minus:TI (sign_extend:TI (match_dup 1))
691                           (sign_extend:TI (match_dup 2)))
692                 (sign_extend:TI (minus:DI (match_dup 1)
693                                           (match_dup 2))))
694             (const_int 0))]
695   ""
696   "subqv %r1,%2,%0")
697
698 ;; The Unicos/Mk assembler doesn't support mull.
699
700 (define_insn "mulsi3"
701   [(set (match_operand:SI 0 "register_operand" "=r")
702         (mult:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ")
703                  (match_operand:SI 2 "reg_or_8bit_operand" "rI")))]
704   "!TARGET_ABI_UNICOSMK"
705   "mull %r1,%2,%0"
706   [(set_attr "type" "imul")
707    (set_attr "opsize" "si")])
708
709 (define_insn "*mulsi_se"
710   [(set (match_operand:DI 0 "register_operand" "=r")
711         (sign_extend:DI
712           (mult:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ")
713                    (match_operand:SI 2 "reg_or_8bit_operand" "rI"))))]
714   "!TARGET_ABI_UNICOSMK"
715   "mull %r1,%2,%0"
716   [(set_attr "type" "imul")
717    (set_attr "opsize" "si")])
718
719 (define_insn "mulvsi3"
720   [(set (match_operand:SI 0 "register_operand" "=r")
721         (mult:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ")
722                  (match_operand:SI 2 "reg_or_8bit_operand" "rI")))
723    (trap_if (ne (mult:DI (sign_extend:DI (match_dup 1))
724                          (sign_extend:DI (match_dup 2)))
725                 (sign_extend:DI (mult:SI (match_dup 1)
726                                          (match_dup 2))))
727             (const_int 0))]
728   "!TARGET_ABI_UNICOSMK"
729   "mullv %r1,%2,%0"
730   [(set_attr "type" "imul")
731    (set_attr "opsize" "si")])
732
733 (define_insn "muldi3"
734   [(set (match_operand:DI 0 "register_operand" "=r")
735         (mult:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ")
736                  (match_operand:DI 2 "reg_or_8bit_operand" "rI")))]
737   ""
738   "mulq %r1,%2,%0"
739   [(set_attr "type" "imul")])
740
741 (define_insn "mulvdi3"
742   [(set (match_operand:DI 0 "register_operand" "=r")
743         (mult:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ")
744                  (match_operand:DI 2 "reg_or_8bit_operand" "rI")))
745    (trap_if (ne (mult:TI (sign_extend:TI (match_dup 1))
746                          (sign_extend:TI (match_dup 2)))
747                 (sign_extend:TI (mult:DI (match_dup 1)
748                                          (match_dup 2))))
749             (const_int 0))]
750   ""
751   "mulqv %r1,%2,%0"
752   [(set_attr "type" "imul")])
753
754 (define_expand "umuldi3_highpart"
755   [(set (match_operand:DI 0 "register_operand" "")
756         (truncate:DI
757          (lshiftrt:TI
758           (mult:TI (zero_extend:TI
759                      (match_operand:DI 1 "register_operand" ""))
760                    (match_operand:DI 2 "reg_or_8bit_operand" ""))
761           (const_int 64))))]
762   ""
763 {
764   if (REG_P (operands[2]))
765     operands[2] = gen_rtx_ZERO_EXTEND (TImode, operands[2]);
766 })
767
768 (define_insn "*umuldi3_highpart_reg"
769   [(set (match_operand:DI 0 "register_operand" "=r")
770         (truncate:DI
771          (lshiftrt:TI
772           (mult:TI (zero_extend:TI
773                      (match_operand:DI 1 "register_operand" "r"))
774                    (zero_extend:TI
775                      (match_operand:DI 2 "register_operand" "r")))
776           (const_int 64))))]
777   ""
778   "umulh %1,%2,%0"
779   [(set_attr "type" "imul")
780    (set_attr "opsize" "udi")])
781
782 (define_insn "*umuldi3_highpart_const"
783   [(set (match_operand:DI 0 "register_operand" "=r")
784         (truncate:DI
785          (lshiftrt:TI
786           (mult:TI (zero_extend:TI (match_operand:DI 1 "register_operand" "r"))
787                    (match_operand:TI 2 "cint8_operand" "I"))
788           (const_int 64))))]
789   ""
790   "umulh %1,%2,%0"
791   [(set_attr "type" "imul")
792    (set_attr "opsize" "udi")])
793 \f
794 ;; The divide and remainder operations take their inputs from r24 and
795 ;; r25, put their output in r27, and clobber r23 and r28 on all
796 ;; systems except Unicos/Mk. On Unicos, the standard library provides
797 ;; subroutines which use the standard calling convention and work on
798 ;; DImode operands.
799
800 ;; ??? Force sign-extension here because some versions of OSF/1 and
801 ;; Interix/NT don't do the right thing if the inputs are not properly
802 ;; sign-extended.  But Linux, for instance, does not have this
803 ;; problem.  Is it worth the complication here to eliminate the sign
804 ;; extension?
805
806 (define_expand "divsi3"
807   [(set (match_dup 3)
808         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
809    (set (match_dup 4)
810         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
811    (parallel [(set (match_dup 5)
812                    (sign_extend:DI (div:SI (match_dup 3) (match_dup 4))))
813               (clobber (reg:DI 23))
814               (clobber (reg:DI 28))])
815    (set (match_operand:SI 0 "nonimmediate_operand" "")
816         (subreg:SI (match_dup 5) 0))]
817   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
818 {
819   operands[3] = gen_reg_rtx (DImode);
820   operands[4] = gen_reg_rtx (DImode);
821   operands[5] = gen_reg_rtx (DImode);
822 })
823
824 (define_expand "udivsi3"
825   [(set (match_dup 3)
826         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
827    (set (match_dup 4)
828         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
829    (parallel [(set (match_dup 5)
830                    (sign_extend:DI (udiv:SI (match_dup 3) (match_dup 4))))
831               (clobber (reg:DI 23))
832               (clobber (reg:DI 28))])
833    (set (match_operand:SI 0 "nonimmediate_operand" "")
834         (subreg:SI (match_dup 5) 0))]
835   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
836 {
837   operands[3] = gen_reg_rtx (DImode);
838   operands[4] = gen_reg_rtx (DImode);
839   operands[5] = gen_reg_rtx (DImode);
840 })
841
842 (define_expand "modsi3"
843   [(set (match_dup 3)
844         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
845    (set (match_dup 4)
846         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
847    (parallel [(set (match_dup 5)
848                    (sign_extend:DI (mod:SI (match_dup 3) (match_dup 4))))
849               (clobber (reg:DI 23))
850               (clobber (reg:DI 28))])
851    (set (match_operand:SI 0 "nonimmediate_operand" "")
852         (subreg:SI (match_dup 5) 0))]
853   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
854 {
855   operands[3] = gen_reg_rtx (DImode);
856   operands[4] = gen_reg_rtx (DImode);
857   operands[5] = gen_reg_rtx (DImode);
858 })
859
860 (define_expand "umodsi3"
861   [(set (match_dup 3)
862         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
863    (set (match_dup 4)
864         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
865    (parallel [(set (match_dup 5)
866                    (sign_extend:DI (umod:SI (match_dup 3) (match_dup 4))))
867               (clobber (reg:DI 23))
868               (clobber (reg:DI 28))])
869    (set (match_operand:SI 0 "nonimmediate_operand" "")
870         (subreg:SI (match_dup 5) 0))]
871   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
872 {
873   operands[3] = gen_reg_rtx (DImode);
874   operands[4] = gen_reg_rtx (DImode);
875   operands[5] = gen_reg_rtx (DImode);
876 })
877
878 (define_expand "divdi3"
879   [(parallel [(set (match_operand:DI 0 "register_operand" "")
880                    (div:DI (match_operand:DI 1 "register_operand" "")
881                            (match_operand:DI 2 "register_operand" "")))
882               (clobber (reg:DI 23))
883               (clobber (reg:DI 28))])]
884   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
885   "")
886
887 (define_expand "udivdi3"
888   [(parallel [(set (match_operand:DI 0 "register_operand" "")
889                    (udiv:DI (match_operand:DI 1 "register_operand" "")
890                             (match_operand:DI 2 "register_operand" "")))
891               (clobber (reg:DI 23))
892               (clobber (reg:DI 28))])]
893   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
894   "")
895
896 (define_expand "moddi3"
897   [(use (match_operand:DI 0 "register_operand" ""))
898    (use (match_operand:DI 1 "register_operand" ""))
899    (use (match_operand:DI 2 "register_operand" ""))]
900   "!TARGET_ABI_OPEN_VMS"
901 {
902   if (TARGET_ABI_UNICOSMK)
903     emit_insn (gen_moddi3_umk (operands[0], operands[1], operands[2]));
904   else
905     emit_insn (gen_moddi3_dft (operands[0], operands[1], operands[2]));
906   DONE;
907 })
908
909 (define_expand "moddi3_dft"
910   [(parallel [(set (match_operand:DI 0 "register_operand" "")
911                    (mod:DI (match_operand:DI 1 "register_operand" "")
912                            (match_operand:DI 2 "register_operand" "")))
913               (clobber (reg:DI 23))
914               (clobber (reg:DI 28))])]
915   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
916   "")
917
918 ;; On Unicos/Mk, we do as the system's C compiler does:
919 ;; compute the quotient, multiply and subtract.
920
921 (define_expand "moddi3_umk"
922   [(use (match_operand:DI 0 "register_operand" ""))
923    (use (match_operand:DI 1 "register_operand" ""))
924    (use (match_operand:DI 2 "register_operand" ""))]
925   "TARGET_ABI_UNICOSMK"
926 {
927   rtx div, mul = gen_reg_rtx (DImode);
928
929   div = expand_binop (DImode, sdiv_optab, operands[1], operands[2],
930                       NULL_RTX, 0, OPTAB_LIB);
931   div = force_reg (DImode, div);
932   emit_insn (gen_muldi3 (mul, operands[2], div));
933   emit_insn (gen_subdi3 (operands[0], operands[1], mul));
934   DONE;
935 })
936
937 (define_expand "umoddi3"
938   [(use (match_operand:DI 0 "register_operand" ""))
939    (use (match_operand:DI 1 "register_operand" ""))
940    (use (match_operand:DI 2 "register_operand" ""))]
941   "! TARGET_ABI_OPEN_VMS"
942 {
943   if (TARGET_ABI_UNICOSMK)
944     emit_insn (gen_umoddi3_umk (operands[0], operands[1], operands[2]));
945   else
946     emit_insn (gen_umoddi3_dft (operands[0], operands[1], operands[2]));
947   DONE;
948 })
949
950 (define_expand "umoddi3_dft"
951   [(parallel [(set (match_operand:DI 0 "register_operand" "")
952                    (umod:DI (match_operand:DI 1 "register_operand" "")
953                             (match_operand:DI 2 "register_operand" "")))
954               (clobber (reg:DI 23))
955               (clobber (reg:DI 28))])]
956   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
957   "")
958
959 (define_expand "umoddi3_umk"
960   [(use (match_operand:DI 0 "register_operand" ""))
961    (use (match_operand:DI 1 "register_operand" ""))
962    (use (match_operand:DI 2 "register_operand" ""))]
963   "TARGET_ABI_UNICOSMK"
964 {
965   rtx div, mul = gen_reg_rtx (DImode);
966
967   div = expand_binop (DImode, udiv_optab, operands[1], operands[2],
968                       NULL_RTX, 1, OPTAB_LIB);
969   div = force_reg (DImode, div);
970   emit_insn (gen_muldi3 (mul, operands[2], div));
971   emit_insn (gen_subdi3 (operands[0], operands[1], mul));
972   DONE;
973 })
974
975 ;; Lengths of 8 for ldq $t12,__divq($gp); jsr $t9,($t12),__divq as
976 ;; expanded by the assembler.
977
978 (define_insn_and_split "*divmodsi_internal_er"
979   [(set (match_operand:DI 0 "register_operand" "=c")
980         (sign_extend:DI (match_operator:SI 3 "divmod_operator"
981                         [(match_operand:DI 1 "register_operand" "a")
982                          (match_operand:DI 2 "register_operand" "b")])))
983    (clobber (reg:DI 23))
984    (clobber (reg:DI 28))]
985   "TARGET_EXPLICIT_RELOCS && ! TARGET_ABI_OPEN_VMS"
986   "#"
987   "&& reload_completed"
988   [(parallel [(set (match_dup 0)
989                    (sign_extend:DI (match_dup 3)))
990               (use (match_dup 0))
991               (use (match_dup 4))
992               (clobber (reg:DI 23))
993               (clobber (reg:DI 28))])]
994 {
995   const char *str;
996   switch (GET_CODE (operands[3]))
997     {
998     case DIV: 
999       str = "__divl";
1000       break; 
1001     case UDIV:
1002       str = "__divlu";
1003       break;
1004     case MOD:
1005       str = "__reml";
1006       break;
1007     case UMOD:
1008       str = "__remlu";
1009       break;
1010     default:
1011       gcc_unreachable ();
1012     }
1013   operands[4] = GEN_INT (alpha_next_sequence_number++);
1014   emit_insn (gen_movdi_er_high_g (operands[0], pic_offset_table_rtx,
1015                                   gen_rtx_SYMBOL_REF (DImode, str),
1016                                   operands[4]));
1017 }
1018   [(set_attr "type" "jsr")
1019    (set_attr "length" "8")])
1020
1021 (define_insn "*divmodsi_internal_er_1"
1022   [(set (match_operand:DI 0 "register_operand" "=c")
1023         (sign_extend:DI (match_operator:SI 3 "divmod_operator"
1024                         [(match_operand:DI 1 "register_operand" "a")
1025                          (match_operand:DI 2 "register_operand" "b")])))
1026    (use (match_operand:DI 4 "register_operand" "c"))
1027    (use (match_operand 5 "const_int_operand" ""))
1028    (clobber (reg:DI 23))
1029    (clobber (reg:DI 28))]
1030   "TARGET_EXPLICIT_RELOCS && ! TARGET_ABI_OPEN_VMS"
1031   "jsr $23,($27),__%E3%j5"
1032   [(set_attr "type" "jsr")
1033    (set_attr "length" "4")])
1034
1035 (define_insn "*divmodsi_internal"
1036   [(set (match_operand:DI 0 "register_operand" "=c")
1037         (sign_extend:DI (match_operator:SI 3 "divmod_operator"
1038                         [(match_operand:DI 1 "register_operand" "a")
1039                          (match_operand:DI 2 "register_operand" "b")])))
1040    (clobber (reg:DI 23))
1041    (clobber (reg:DI 28))]
1042   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1043   "%E3 %1,%2,%0"
1044   [(set_attr "type" "jsr")
1045    (set_attr "length" "8")])
1046
1047 (define_insn_and_split "*divmoddi_internal_er"
1048   [(set (match_operand:DI 0 "register_operand" "=c")
1049         (match_operator:DI 3 "divmod_operator"
1050                         [(match_operand:DI 1 "register_operand" "a")
1051                          (match_operand:DI 2 "register_operand" "b")]))
1052    (clobber (reg:DI 23))
1053    (clobber (reg:DI 28))]
1054   "TARGET_EXPLICIT_RELOCS && ! TARGET_ABI_OPEN_VMS"
1055   "#"
1056   "&& reload_completed"
1057   [(parallel [(set (match_dup 0) (match_dup 3))
1058               (use (match_dup 0))
1059               (use (match_dup 4))
1060               (clobber (reg:DI 23))
1061               (clobber (reg:DI 28))])]
1062 {
1063   const char *str;
1064   switch (GET_CODE (operands[3]))
1065     {
1066     case DIV: 
1067       str = "__divq";
1068       break; 
1069     case UDIV:
1070       str = "__divqu";
1071       break;
1072     case MOD:
1073       str = "__remq";
1074       break;
1075     case UMOD:
1076       str = "__remqu";
1077       break;
1078     default:
1079       gcc_unreachable ();
1080     }
1081   operands[4] = GEN_INT (alpha_next_sequence_number++);
1082   emit_insn (gen_movdi_er_high_g (operands[0], pic_offset_table_rtx,
1083                                   gen_rtx_SYMBOL_REF (DImode, str),
1084                                   operands[4]));
1085 }
1086   [(set_attr "type" "jsr")
1087    (set_attr "length" "8")])
1088
1089 (define_insn "*divmoddi_internal_er_1"
1090   [(set (match_operand:DI 0 "register_operand" "=c")
1091         (match_operator:DI 3 "divmod_operator"
1092                         [(match_operand:DI 1 "register_operand" "a")
1093                          (match_operand:DI 2 "register_operand" "b")]))
1094    (use (match_operand:DI 4 "register_operand" "c"))
1095    (use (match_operand 5 "const_int_operand" ""))
1096    (clobber (reg:DI 23))
1097    (clobber (reg:DI 28))]
1098   "TARGET_EXPLICIT_RELOCS && ! TARGET_ABI_OPEN_VMS"
1099   "jsr $23,($27),__%E3%j5"
1100   [(set_attr "type" "jsr")
1101    (set_attr "length" "4")])
1102
1103 (define_insn "*divmoddi_internal"
1104   [(set (match_operand:DI 0 "register_operand" "=c")
1105         (match_operator:DI 3 "divmod_operator"
1106                         [(match_operand:DI 1 "register_operand" "a")
1107                          (match_operand:DI 2 "register_operand" "b")]))
1108    (clobber (reg:DI 23))
1109    (clobber (reg:DI 28))]
1110   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1111   "%E3 %1,%2,%0"
1112   [(set_attr "type" "jsr")
1113    (set_attr "length" "8")])
1114 \f
1115 ;; Next are the basic logical operations.  We only expose the DImode operations
1116 ;; to the rtl expanders, but SImode versions exist for combine as well as for
1117 ;; the atomic operation splitters.
1118
1119 (define_insn "*andsi_internal"
1120   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1121         (and:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ,rJ")
1122                 (match_operand:SI 2 "and_operand" "rI,N,MH")))]
1123   ""
1124   "@
1125    and %r1,%2,%0
1126    bic %r1,%N2,%0
1127    zapnot %r1,%m2,%0"
1128   [(set_attr "type" "ilog,ilog,shift")])
1129
1130 (define_insn "anddi3"
1131   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
1132         (and:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ,rJ")
1133                 (match_operand:DI 2 "and_operand" "rI,N,MH")))]
1134   ""
1135   "@
1136    and %r1,%2,%0
1137    bic %r1,%N2,%0
1138    zapnot %r1,%m2,%0"
1139   [(set_attr "type" "ilog,ilog,shift")])
1140
1141 ;; There are times when we can split an AND into two AND insns.  This occurs
1142 ;; when we can first clear any bytes and then clear anything else.  For
1143 ;; example "I & 0xffff07" is "(I & 0xffffff) & 0xffffffffffffff07".
1144 ;; Only do this when running on 64-bit host since the computations are
1145 ;; too messy otherwise.
1146
1147 (define_split
1148   [(set (match_operand:DI 0 "register_operand" "")
1149         (and:DI (match_operand:DI 1 "register_operand" "")
1150                 (match_operand:DI 2 "const_int_operand" "")))]
1151   "HOST_BITS_PER_WIDE_INT == 64 && ! and_operand (operands[2], DImode)"
1152   [(set (match_dup 0) (and:DI (match_dup 1) (match_dup 3)))
1153    (set (match_dup 0) (and:DI (match_dup 0) (match_dup 4)))]
1154 {
1155   unsigned HOST_WIDE_INT mask1 = INTVAL (operands[2]);
1156   unsigned HOST_WIDE_INT mask2 = mask1;
1157   int i;
1158
1159   /* For each byte that isn't all zeros, make it all ones.  */
1160   for (i = 0; i < 64; i += 8)
1161     if ((mask1 & ((HOST_WIDE_INT) 0xff << i)) != 0)
1162       mask1 |= (HOST_WIDE_INT) 0xff << i;
1163
1164   /* Now turn on any bits we've just turned off.  */
1165   mask2 |= ~ mask1;
1166
1167   operands[3] = GEN_INT (mask1);
1168   operands[4] = GEN_INT (mask2);
1169 })
1170
1171 (define_expand "zero_extendqihi2"
1172   [(set (match_operand:HI 0 "register_operand" "")
1173         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))]
1174   ""
1175 {
1176   if (! TARGET_BWX)
1177     operands[1] = force_reg (QImode, operands[1]);
1178 })
1179
1180 (define_insn "*zero_extendqihi2_bwx"
1181   [(set (match_operand:HI 0 "register_operand" "=r,r")
1182         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1183   "TARGET_BWX"
1184   "@
1185    and %1,0xff,%0
1186    ldbu %0,%1"
1187   [(set_attr "type" "ilog,ild")])
1188
1189 (define_insn "*zero_extendqihi2_nobwx"
1190   [(set (match_operand:HI 0 "register_operand" "=r")
1191         (zero_extend:HI (match_operand:QI 1 "register_operand" "r")))]
1192   "! TARGET_BWX"
1193   "and %1,0xff,%0"
1194   [(set_attr "type" "ilog")])
1195
1196 (define_expand "zero_extendqisi2"
1197   [(set (match_operand:SI 0 "register_operand" "")
1198         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))]
1199   ""
1200 {
1201   if (! TARGET_BWX)
1202     operands[1] = force_reg (QImode, operands[1]);
1203 })
1204
1205 (define_insn "*zero_extendqisi2_bwx"
1206   [(set (match_operand:SI 0 "register_operand" "=r,r")
1207         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1208   "TARGET_BWX"
1209   "@
1210    and %1,0xff,%0
1211    ldbu %0,%1"
1212   [(set_attr "type" "ilog,ild")])
1213
1214 (define_insn "*zero_extendqisi2_nobwx"
1215   [(set (match_operand:SI 0 "register_operand" "=r")
1216         (zero_extend:SI (match_operand:QI 1 "register_operand" "r")))]
1217   "! TARGET_BWX"
1218   "and %1,0xff,%0"
1219   [(set_attr "type" "ilog")])
1220
1221 (define_expand "zero_extendqidi2"
1222   [(set (match_operand:DI 0 "register_operand" "")
1223         (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "")))]
1224   ""
1225 {
1226   if (! TARGET_BWX)
1227     operands[1] = force_reg (QImode, operands[1]);
1228 })
1229
1230 (define_insn "*zero_extendqidi2_bwx"
1231   [(set (match_operand:DI 0 "register_operand" "=r,r")
1232         (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1233   "TARGET_BWX"
1234   "@
1235    and %1,0xff,%0
1236    ldbu %0,%1"
1237   [(set_attr "type" "ilog,ild")])
1238
1239 (define_insn "*zero_extendqidi2_nobwx"
1240   [(set (match_operand:DI 0 "register_operand" "=r")
1241         (zero_extend:DI (match_operand:QI 1 "register_operand" "r")))]
1242   "! TARGET_BWX"
1243   "and %1,0xff,%0"
1244   [(set_attr "type" "ilog")])
1245
1246 (define_expand "zero_extendhisi2"
1247   [(set (match_operand:SI 0 "register_operand" "")
1248         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
1249   ""
1250 {
1251   if (! TARGET_BWX)
1252     operands[1] = force_reg (HImode, operands[1]);
1253 })
1254
1255 (define_insn "*zero_extendhisi2_bwx"
1256   [(set (match_operand:SI 0 "register_operand" "=r,r")
1257         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
1258   "TARGET_BWX"
1259   "@
1260    zapnot %1,3,%0
1261    ldwu %0,%1"
1262   [(set_attr "type" "shift,ild")])
1263
1264 (define_insn "*zero_extendhisi2_nobwx"
1265   [(set (match_operand:SI 0 "register_operand" "=r")
1266         (zero_extend:SI (match_operand:HI 1 "register_operand" "r")))]
1267   "! TARGET_BWX"
1268   "zapnot %1,3,%0"
1269   [(set_attr "type" "shift")])
1270
1271 (define_expand "zero_extendhidi2"
1272   [(set (match_operand:DI 0 "register_operand" "")
1273         (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "")))]
1274   ""
1275 {
1276   if (! TARGET_BWX)
1277     operands[1] = force_reg (HImode, operands[1]);
1278 })
1279
1280 (define_insn "*zero_extendhidi2_bwx"
1281   [(set (match_operand:DI 0 "register_operand" "=r,r")
1282         (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
1283   "TARGET_BWX"
1284   "@
1285    zapnot %1,3,%0
1286    ldwu %0,%1"
1287   [(set_attr "type" "shift,ild")])
1288
1289 (define_insn "*zero_extendhidi2_nobwx"
1290   [(set (match_operand:DI 0 "register_operand" "=r")
1291         (zero_extend:DI (match_operand:HI 1 "register_operand" "r")))]
1292   ""
1293   "zapnot %1,3,%0"
1294   [(set_attr "type" "shift")])
1295
1296 (define_insn "zero_extendsidi2"
1297   [(set (match_operand:DI 0 "register_operand" "=r")
1298         (zero_extend:DI (match_operand:SI 1 "register_operand" "r")))]
1299   ""
1300   "zapnot %1,15,%0"
1301   [(set_attr "type" "shift")])
1302
1303 (define_insn "*andnotsi3"
1304   [(set (match_operand:SI 0 "register_operand" "=r")
1305         (and:SI (not:SI (match_operand:SI 1 "reg_or_8bit_operand" "rI"))
1306                 (match_operand:SI 2 "reg_or_0_operand" "rJ")))]
1307   ""
1308   "bic %r2,%1,%0"
1309   [(set_attr "type" "ilog")])
1310
1311 (define_insn "andnotdi3"
1312   [(set (match_operand:DI 0 "register_operand" "=r")
1313         (and:DI (not:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI"))
1314                 (match_operand:DI 2 "reg_or_0_operand" "rJ")))]
1315   ""
1316   "bic %r2,%1,%0"
1317   [(set_attr "type" "ilog")])
1318
1319 (define_insn "*iorsi_internal"
1320   [(set (match_operand:SI 0 "register_operand" "=r,r")
1321         (ior:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ")
1322                 (match_operand:SI 2 "or_operand" "rI,N")))]
1323   ""
1324   "@
1325    bis %r1,%2,%0
1326    ornot %r1,%N2,%0"
1327   [(set_attr "type" "ilog")])
1328
1329 (define_insn "iordi3"
1330   [(set (match_operand:DI 0 "register_operand" "=r,r")
1331         (ior:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ")
1332                 (match_operand:DI 2 "or_operand" "rI,N")))]
1333   ""
1334   "@
1335    bis %r1,%2,%0
1336    ornot %r1,%N2,%0"
1337   [(set_attr "type" "ilog")])
1338
1339 (define_insn "*one_cmplsi_internal"
1340   [(set (match_operand:SI 0 "register_operand" "=r")
1341         (not:SI (match_operand:SI 1 "reg_or_8bit_operand" "rI")))]
1342   ""
1343   "ornot $31,%1,%0"
1344   [(set_attr "type" "ilog")])
1345
1346 (define_insn "one_cmpldi2"
1347   [(set (match_operand:DI 0 "register_operand" "=r")
1348         (not:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI")))]
1349   ""
1350   "ornot $31,%1,%0"
1351   [(set_attr "type" "ilog")])
1352
1353 (define_insn "*iornotsi3"
1354   [(set (match_operand:SI 0 "register_operand" "=r")
1355         (ior:SI (not:SI (match_operand:SI 1 "reg_or_8bit_operand" "rI"))
1356                 (match_operand:SI 2 "reg_or_0_operand" "rJ")))]
1357   ""
1358   "ornot %r2,%1,%0"
1359   [(set_attr "type" "ilog")])
1360
1361 (define_insn "*iornotdi3"
1362   [(set (match_operand:DI 0 "register_operand" "=r")
1363         (ior:DI (not:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI"))
1364                 (match_operand:DI 2 "reg_or_0_operand" "rJ")))]
1365   ""
1366   "ornot %r2,%1,%0"
1367   [(set_attr "type" "ilog")])
1368
1369 (define_insn "*xorsi_internal"
1370   [(set (match_operand:SI 0 "register_operand" "=r,r")
1371         (xor:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ")
1372                 (match_operand:SI 2 "or_operand" "rI,N")))]
1373   ""
1374   "@
1375    xor %r1,%2,%0
1376    eqv %r1,%N2,%0"
1377   [(set_attr "type" "ilog")])
1378
1379 (define_insn "xordi3"
1380   [(set (match_operand:DI 0 "register_operand" "=r,r")
1381         (xor:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ")
1382                 (match_operand:DI 2 "or_operand" "rI,N")))]
1383   ""
1384   "@
1385    xor %r1,%2,%0
1386    eqv %r1,%N2,%0"
1387   [(set_attr "type" "ilog")])
1388
1389 (define_insn "*xornotsi3"
1390   [(set (match_operand:SI 0 "register_operand" "=r")
1391         (not:SI (xor:SI (match_operand:SI 1 "register_operand" "%rJ")
1392                         (match_operand:SI 2 "register_operand" "rI"))))]
1393   ""
1394   "eqv %r1,%2,%0"
1395   [(set_attr "type" "ilog")])
1396
1397 (define_insn "*xornotdi3"
1398   [(set (match_operand:DI 0 "register_operand" "=r")
1399         (not:DI (xor:DI (match_operand:DI 1 "register_operand" "%rJ")
1400                         (match_operand:DI 2 "register_operand" "rI"))))]
1401   ""
1402   "eqv %r1,%2,%0"
1403   [(set_attr "type" "ilog")])
1404 \f
1405 ;; Handle FFS and related insns iff we support CIX.
1406
1407 (define_expand "ffsdi2"
1408   [(set (match_dup 2)
1409         (ctz:DI (match_operand:DI 1 "register_operand" "")))
1410    (set (match_dup 3)
1411         (plus:DI (match_dup 2) (const_int 1)))
1412    (set (match_operand:DI 0 "register_operand" "")
1413         (if_then_else:DI (eq (match_dup 1) (const_int 0))
1414                          (const_int 0) (match_dup 3)))]
1415   "TARGET_CIX"
1416 {
1417   operands[2] = gen_reg_rtx (DImode);
1418   operands[3] = gen_reg_rtx (DImode);
1419 })
1420
1421 (define_insn "clzdi2"
1422   [(set (match_operand:DI 0 "register_operand" "=r")
1423         (clz:DI (match_operand:DI 1 "register_operand" "r")))]
1424   "TARGET_CIX"
1425   "ctlz %1,%0"
1426   [(set_attr "type" "mvi")])
1427
1428 (define_insn "ctzdi2"
1429   [(set (match_operand:DI 0 "register_operand" "=r")
1430         (ctz:DI (match_operand:DI 1 "register_operand" "r")))]
1431   "TARGET_CIX"
1432   "cttz %1,%0"
1433   [(set_attr "type" "mvi")])
1434
1435 (define_insn "popcountdi2"
1436   [(set (match_operand:DI 0 "register_operand" "=r")
1437         (popcount:DI (match_operand:DI 1 "register_operand" "r")))]
1438   "TARGET_CIX"
1439   "ctpop %1,%0"
1440   [(set_attr "type" "mvi")])
1441
1442 (define_expand "bswapsi2"
1443   [(set (match_operand:SI 0 "register_operand" "")
1444         (bswap:SI (match_operand:SI 1 "register_operand" "")))]
1445   "!optimize_size"
1446 {
1447   rtx t0, t1;
1448
1449   t0 = gen_reg_rtx (DImode);
1450   t1 = gen_reg_rtx (DImode);
1451
1452   emit_insn (gen_insxh (t0, gen_lowpart (DImode, operands[1]),
1453                         GEN_INT (32), GEN_INT (WORDS_BIG_ENDIAN ? 0 : 7)));
1454   emit_insn (gen_inswl_const (t1, gen_lowpart (HImode, operands[1]),
1455                               GEN_INT (24)));
1456   emit_insn (gen_iordi3 (t1, t0, t1));
1457   emit_insn (gen_lshrdi3 (t0, t1, GEN_INT (16)));
1458   emit_insn (gen_anddi3 (t1, t1, alpha_expand_zap_mask (0x5)));
1459   emit_insn (gen_anddi3 (t0, t0, alpha_expand_zap_mask (0xa)));
1460   emit_insn (gen_addsi3 (operands[0], gen_lowpart (SImode, t0),
1461                          gen_lowpart (SImode, t1)));
1462   DONE;
1463 })
1464
1465 (define_expand "bswapdi2"
1466   [(set (match_operand:DI 0 "register_operand" "")
1467         (bswap:DI (match_operand:DI 1 "register_operand" "")))]
1468   "!optimize_size"
1469 {
1470   rtx t0, t1;
1471
1472   t0 = gen_reg_rtx (DImode);
1473   t1 = gen_reg_rtx (DImode);
1474
1475   /* This method of shifting and masking is not specific to Alpha, but
1476      is only profitable on Alpha because of our handy byte zap insn.  */
1477
1478   emit_insn (gen_lshrdi3 (t0, operands[1], GEN_INT (32)));
1479   emit_insn (gen_ashldi3 (t1, operands[1], GEN_INT (32)));
1480   emit_insn (gen_iordi3 (t1, t0, t1));
1481
1482   emit_insn (gen_lshrdi3 (t0, t1, GEN_INT (16)));
1483   emit_insn (gen_ashldi3 (t1, t1, GEN_INT (16)));
1484   emit_insn (gen_anddi3 (t0, t0, alpha_expand_zap_mask (0xcc)));
1485   emit_insn (gen_anddi3 (t1, t1, alpha_expand_zap_mask (0x33)));
1486   emit_insn (gen_iordi3 (t1, t0, t1));
1487
1488   emit_insn (gen_lshrdi3 (t0, t1, GEN_INT (8)));
1489   emit_insn (gen_ashldi3 (t1, t1, GEN_INT (8)));
1490   emit_insn (gen_anddi3 (t0, t0, alpha_expand_zap_mask (0xaa)));
1491   emit_insn (gen_anddi3 (t1, t1, alpha_expand_zap_mask (0x55)));
1492   emit_insn (gen_iordi3 (operands[0], t0, t1));
1493   DONE;
1494 })
1495 \f
1496 ;; Next come the shifts and the various extract and insert operations.
1497
1498 (define_insn "ashldi3"
1499   [(set (match_operand:DI 0 "register_operand" "=r,r")
1500         (ashift:DI (match_operand:DI 1 "reg_or_0_operand" "rJ,rJ")
1501                    (match_operand:DI 2 "reg_or_6bit_operand" "P,rS")))]
1502   ""
1503 {
1504   switch (which_alternative)
1505     {
1506     case 0:
1507       if (operands[2] == const1_rtx)
1508         return "addq %r1,%r1,%0";
1509       else
1510         return "s%P2addq %r1,0,%0";
1511     case 1:
1512       return "sll %r1,%2,%0";
1513     default:
1514       gcc_unreachable ();
1515     }
1516 }
1517   [(set_attr "type" "iadd,shift")])
1518
1519 (define_insn "*ashldi_se"
1520   [(set (match_operand:DI 0 "register_operand" "=r")
1521         (sign_extend:DI
1522          (subreg:SI (ashift:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1523                                (match_operand:DI 2 "const_int_operand" "P"))
1524                     0)))]
1525   "INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 3"
1526 {
1527   if (operands[2] == const1_rtx)
1528     return "addl %r1,%r1,%0";
1529   else
1530     return "s%P2addl %r1,0,%0";
1531 }
1532   [(set_attr "type" "iadd")])
1533
1534 (define_insn "lshrdi3"
1535   [(set (match_operand:DI 0 "register_operand" "=r")
1536         (lshiftrt:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1537                      (match_operand:DI 2 "reg_or_6bit_operand" "rS")))]
1538   ""
1539   "srl %r1,%2,%0"
1540   [(set_attr "type" "shift")])
1541
1542 (define_insn "ashrdi3"
1543   [(set (match_operand:DI 0 "register_operand" "=r")
1544         (ashiftrt:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1545                      (match_operand:DI 2 "reg_or_6bit_operand" "rS")))]
1546   ""
1547   "sra %r1,%2,%0"
1548   [(set_attr "type" "shift")])
1549
1550 (define_expand "extendqihi2"
1551   [(set (match_dup 2)
1552         (ashift:DI (match_operand:QI 1 "some_operand" "")
1553                    (const_int 56)))
1554    (set (match_operand:HI 0 "register_operand" "")
1555         (ashiftrt:DI (match_dup 2)
1556                      (const_int 56)))]
1557   ""
1558 {
1559   if (TARGET_BWX)
1560     {
1561       emit_insn (gen_extendqihi2x (operands[0],
1562                                    force_reg (QImode, operands[1])));
1563       DONE;
1564     }
1565
1566  /* If we have an unaligned MEM, extend to DImode (which we do
1567      specially) and then copy to the result.  */
1568   if (unaligned_memory_operand (operands[1], HImode))
1569     {
1570       rtx temp = gen_reg_rtx (DImode);
1571
1572       emit_insn (gen_extendqidi2 (temp, operands[1]));
1573       emit_move_insn (operands[0], gen_lowpart (HImode, temp));
1574       DONE;
1575     }
1576
1577   operands[0] = gen_lowpart (DImode, operands[0]);
1578   operands[1] = gen_lowpart (DImode, force_reg (QImode, operands[1]));
1579   operands[2] = gen_reg_rtx (DImode);
1580 })
1581
1582 (define_insn "extendqidi2x"
1583   [(set (match_operand:DI 0 "register_operand" "=r")
1584         (sign_extend:DI (match_operand:QI 1 "register_operand" "r")))]
1585   "TARGET_BWX"
1586   "sextb %1,%0"
1587   [(set_attr "type" "shift")])
1588
1589 (define_insn "extendhidi2x"
1590   [(set (match_operand:DI 0 "register_operand" "=r")
1591         (sign_extend:DI (match_operand:HI 1 "register_operand" "r")))]
1592   "TARGET_BWX"
1593   "sextw %1,%0"
1594   [(set_attr "type" "shift")])
1595
1596 (define_insn "extendqisi2x"
1597   [(set (match_operand:SI 0 "register_operand" "=r")
1598         (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
1599   "TARGET_BWX"
1600   "sextb %1,%0"
1601   [(set_attr "type" "shift")])
1602
1603 (define_insn "extendhisi2x"
1604   [(set (match_operand:SI 0 "register_operand" "=r")
1605         (sign_extend:SI (match_operand:HI 1 "register_operand" "r")))]
1606   "TARGET_BWX"
1607   "sextw %1,%0"
1608   [(set_attr "type" "shift")])
1609
1610 (define_insn "extendqihi2x"
1611   [(set (match_operand:HI 0 "register_operand" "=r")
1612         (sign_extend:HI (match_operand:QI 1 "register_operand" "r")))]
1613   "TARGET_BWX"
1614   "sextb %1,%0"
1615   [(set_attr "type" "shift")])
1616
1617 (define_expand "extendqisi2"
1618   [(set (match_dup 2)
1619         (ashift:DI (match_operand:QI 1 "some_operand" "")
1620                    (const_int 56)))
1621    (set (match_operand:SI 0 "register_operand" "")
1622         (ashiftrt:DI (match_dup 2)
1623                      (const_int 56)))]
1624   ""
1625 {
1626   if (TARGET_BWX)
1627     {
1628       emit_insn (gen_extendqisi2x (operands[0],
1629                                    force_reg (QImode, operands[1])));
1630       DONE;
1631     }
1632
1633   /* If we have an unaligned MEM, extend to a DImode form of
1634      the result (which we do specially).  */
1635   if (unaligned_memory_operand (operands[1], QImode))
1636     {
1637       rtx temp = gen_reg_rtx (DImode);
1638
1639       emit_insn (gen_extendqidi2 (temp, operands[1]));
1640       emit_move_insn (operands[0], gen_lowpart (SImode, temp));
1641       DONE;
1642     }
1643
1644   operands[0] = gen_lowpart (DImode, operands[0]);
1645   operands[1] = gen_lowpart (DImode, force_reg (QImode, operands[1]));
1646   operands[2] = gen_reg_rtx (DImode);
1647 })
1648
1649 (define_expand "extendqidi2"
1650   [(set (match_dup 2)
1651         (ashift:DI (match_operand:QI 1 "some_operand" "")
1652                    (const_int 56)))
1653    (set (match_operand:DI 0 "register_operand" "")
1654         (ashiftrt:DI (match_dup 2)
1655                      (const_int 56)))]
1656   ""
1657 {
1658   if (TARGET_BWX)
1659     {
1660       emit_insn (gen_extendqidi2x (operands[0],
1661                                    force_reg (QImode, operands[1])));
1662       DONE;
1663     }
1664
1665   if (unaligned_memory_operand (operands[1], QImode))
1666     {
1667       rtx seq
1668         = gen_unaligned_extendqidi (operands[0],
1669                                     get_unaligned_address (operands[1], 1));
1670
1671       alpha_set_memflags (seq, operands[1]);
1672       emit_insn (seq);
1673       DONE;
1674     }
1675
1676   operands[1] = gen_lowpart (DImode, force_reg (QImode, operands[1]));
1677   operands[2] = gen_reg_rtx (DImode);
1678 })
1679
1680 (define_expand "extendhisi2"
1681   [(set (match_dup 2)
1682         (ashift:DI (match_operand:HI 1 "some_operand" "")
1683                    (const_int 48)))
1684    (set (match_operand:SI 0 "register_operand" "")
1685         (ashiftrt:DI (match_dup 2)
1686                      (const_int 48)))]
1687   ""
1688 {
1689   if (TARGET_BWX)
1690     {
1691       emit_insn (gen_extendhisi2x (operands[0],
1692                                    force_reg (HImode, operands[1])));
1693       DONE;
1694     }
1695
1696   /* If we have an unaligned MEM, extend to a DImode form of
1697      the result (which we do specially).  */
1698   if (unaligned_memory_operand (operands[1], HImode))
1699     {
1700       rtx temp = gen_reg_rtx (DImode);
1701
1702       emit_insn (gen_extendhidi2 (temp, operands[1]));
1703       emit_move_insn (operands[0], gen_lowpart (SImode, temp));
1704       DONE;
1705     }
1706
1707   operands[0] = gen_lowpart (DImode, operands[0]);
1708   operands[1] = gen_lowpart (DImode, force_reg (HImode, operands[1]));
1709   operands[2] = gen_reg_rtx (DImode);
1710 })
1711
1712 (define_expand "extendhidi2"
1713   [(set (match_dup 2)
1714         (ashift:DI (match_operand:HI 1 "some_operand" "")
1715                    (const_int 48)))
1716    (set (match_operand:DI 0 "register_operand" "")
1717         (ashiftrt:DI (match_dup 2)
1718                      (const_int 48)))]
1719   ""
1720 {
1721   if (TARGET_BWX)
1722     {
1723       emit_insn (gen_extendhidi2x (operands[0],
1724                                    force_reg (HImode, operands[1])));
1725       DONE;
1726     }
1727
1728   if (unaligned_memory_operand (operands[1], HImode))
1729     {
1730       rtx seq
1731         = gen_unaligned_extendhidi (operands[0],
1732                                     get_unaligned_address (operands[1], 2));
1733
1734       alpha_set_memflags (seq, operands[1]);
1735       emit_insn (seq);
1736       DONE;
1737     }
1738
1739   operands[1] = gen_lowpart (DImode, force_reg (HImode, operands[1]));
1740   operands[2] = gen_reg_rtx (DImode);
1741 })
1742
1743 ;; Here's how we sign extend an unaligned byte and halfword.  Doing this
1744 ;; as a pattern saves one instruction.  The code is similar to that for
1745 ;; the unaligned loads (see below).
1746 ;;
1747 ;; Operand 1 is the address + 1 (+2 for HI), operand 0 is the result.
1748 (define_expand "unaligned_extendqidi"
1749   [(use (match_operand:QI 0 "register_operand" ""))
1750    (use (match_operand:DI 1 "address_operand" ""))]
1751   ""
1752 {
1753   if (WORDS_BIG_ENDIAN)
1754     emit_insn (gen_unaligned_extendqidi_be (operands[0], operands[1]));
1755   else
1756     emit_insn (gen_unaligned_extendqidi_le (operands[0], operands[1]));
1757   DONE;
1758 })
1759
1760 (define_expand "unaligned_extendqidi_le"
1761   [(set (match_dup 2) (match_operand:DI 1 "address_operand" ""))
1762    (set (match_dup 3)
1763         (mem:DI (and:DI (plus:DI (match_dup 2) (const_int -1))
1764                         (const_int -8))))
1765    (set (match_dup 4)
1766         (ashift:DI (match_dup 3)
1767                    (minus:DI (const_int 64)
1768                              (ashift:DI
1769                               (and:DI (match_dup 2) (const_int 7))
1770                               (const_int 3)))))
1771    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
1772         (ashiftrt:DI (match_dup 4) (const_int 56)))]
1773   "! WORDS_BIG_ENDIAN"
1774 {
1775   operands[2] = gen_reg_rtx (DImode);
1776   operands[3] = gen_reg_rtx (DImode);
1777   operands[4] = gen_reg_rtx (DImode);
1778 })
1779
1780 (define_expand "unaligned_extendqidi_be"
1781   [(set (match_dup 2) (match_operand:DI 1 "address_operand" ""))
1782    (set (match_dup 3) (plus:DI (match_dup 2) (const_int -1)))
1783    (set (match_dup 4)
1784         (mem:DI (and:DI (match_dup 3)
1785                         (const_int -8))))
1786    (set (match_dup 5) (plus:DI (match_dup 2) (const_int -2)))
1787    (set (match_dup 6)
1788         (ashift:DI (match_dup 4)
1789                    (ashift:DI
1790                      (and:DI
1791                        (plus:DI (match_dup 5) (const_int 1))
1792                        (const_int 7))
1793                      (const_int 3))))
1794    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
1795         (ashiftrt:DI (match_dup 6) (const_int 56)))]
1796   "WORDS_BIG_ENDIAN"
1797 {
1798   operands[2] = gen_reg_rtx (DImode);
1799   operands[3] = gen_reg_rtx (DImode);
1800   operands[4] = gen_reg_rtx (DImode);
1801   operands[5] = gen_reg_rtx (DImode);
1802   operands[6] = gen_reg_rtx (DImode);
1803 })
1804
1805 (define_expand "unaligned_extendhidi"
1806   [(use (match_operand:QI 0 "register_operand" ""))
1807    (use (match_operand:DI 1 "address_operand" ""))]
1808   ""
1809 {
1810   operands[0] = gen_lowpart (DImode, operands[0]);
1811   emit_insn ((WORDS_BIG_ENDIAN
1812               ? gen_unaligned_extendhidi_be
1813               : gen_unaligned_extendhidi_le) (operands[0], operands[1]));
1814   DONE;
1815 })
1816
1817 (define_expand "unaligned_extendhidi_le"
1818   [(set (match_dup 2) (match_operand:DI 1 "address_operand" ""))
1819    (set (match_dup 3)
1820         (mem:DI (and:DI (plus:DI (match_dup 2) (const_int -2))
1821                         (const_int -8))))
1822    (set (match_dup 4)
1823         (ashift:DI (match_dup 3)
1824                    (minus:DI (const_int 64)
1825                              (ashift:DI
1826                               (and:DI (match_dup 2) (const_int 7))
1827                               (const_int 3)))))
1828    (set (match_operand:DI 0 "register_operand" "")
1829         (ashiftrt:DI (match_dup 4) (const_int 48)))]
1830   "! WORDS_BIG_ENDIAN"
1831 {
1832   operands[2] = gen_reg_rtx (DImode);
1833   operands[3] = gen_reg_rtx (DImode);
1834   operands[4] = gen_reg_rtx (DImode);
1835 })
1836
1837 (define_expand "unaligned_extendhidi_be"
1838   [(set (match_dup 2) (match_operand:DI 1 "address_operand" ""))
1839    (set (match_dup 3) (plus:DI (match_dup 2) (const_int -2)))
1840    (set (match_dup 4)
1841         (mem:DI (and:DI (match_dup 3)
1842                         (const_int -8))))
1843    (set (match_dup 5) (plus:DI (match_dup 2) (const_int -3)))
1844    (set (match_dup 6)
1845         (ashift:DI (match_dup 4)
1846                    (ashift:DI
1847                      (and:DI
1848                        (plus:DI (match_dup 5) (const_int 1))
1849                        (const_int 7))
1850                      (const_int 3))))
1851    (set (match_operand:DI 0 "register_operand" "")
1852         (ashiftrt:DI (match_dup 6) (const_int 48)))]
1853   "WORDS_BIG_ENDIAN"
1854 {
1855   operands[2] = gen_reg_rtx (DImode);
1856   operands[3] = gen_reg_rtx (DImode);
1857   operands[4] = gen_reg_rtx (DImode);
1858   operands[5] = gen_reg_rtx (DImode);
1859   operands[6] = gen_reg_rtx (DImode);
1860 })
1861
1862 (define_insn "*extxl_const"
1863   [(set (match_operand:DI 0 "register_operand" "=r")
1864         (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1865                          (match_operand:DI 2 "mode_width_operand" "n")
1866                          (match_operand:DI 3 "mul8_operand" "I")))]
1867   ""
1868   "ext%M2l %r1,%s3,%0"
1869   [(set_attr "type" "shift")])
1870
1871 (define_insn "extxl_le"
1872   [(set (match_operand:DI 0 "register_operand" "=r")
1873         (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1874                          (match_operand:DI 2 "mode_width_operand" "n")
1875                          (ashift:DI (match_operand:DI 3 "reg_or_8bit_operand" "rI")
1876                                     (const_int 3))))]
1877   "! WORDS_BIG_ENDIAN"
1878   "ext%M2l %r1,%3,%0"
1879   [(set_attr "type" "shift")])
1880
1881 (define_insn "extxl_be"
1882   [(set (match_operand:DI 0 "register_operand" "=r")
1883         (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1884                          (match_operand:DI 2 "mode_width_operand" "n")
1885                          (minus:DI
1886                            (const_int 56)
1887                            (ashift:DI
1888                              (match_operand:DI 3 "reg_or_8bit_operand" "rI")
1889                              (const_int 3)))))]
1890   "WORDS_BIG_ENDIAN"
1891   "ext%M2l %r1,%3,%0"
1892   [(set_attr "type" "shift")])
1893
1894 ;; Combine has some strange notion of preserving existing undefined behavior
1895 ;; in shifts larger than a word size.  So capture these patterns that it
1896 ;; should have turned into zero_extracts.
1897
1898 (define_insn "*extxl_1_le"
1899   [(set (match_operand:DI 0 "register_operand" "=r")
1900         (and:DI (lshiftrt:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1901                   (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1902                              (const_int 3)))
1903              (match_operand:DI 3 "mode_mask_operand" "n")))]
1904   "! WORDS_BIG_ENDIAN"
1905   "ext%U3l %1,%2,%0"
1906   [(set_attr "type" "shift")])
1907
1908 (define_insn "*extxl_1_be"
1909   [(set (match_operand:DI 0 "register_operand" "=r")
1910         (and:DI (lshiftrt:DI
1911                   (match_operand:DI 1 "reg_or_0_operand" "rJ")
1912                   (minus:DI (const_int 56)
1913                     (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1914                                (const_int 3))))
1915                 (match_operand:DI 3 "mode_mask_operand" "n")))]
1916   "WORDS_BIG_ENDIAN"
1917   "ext%U3l %1,%2,%0"
1918   [(set_attr "type" "shift")])
1919
1920 (define_insn "*extql_2_le"
1921   [(set (match_operand:DI 0 "register_operand" "=r")
1922         (lshiftrt:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1923           (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1924                      (const_int 3))))]
1925   "! WORDS_BIG_ENDIAN"
1926   "extql %1,%2,%0"
1927   [(set_attr "type" "shift")])
1928
1929 (define_insn "*extql_2_be"
1930   [(set (match_operand:DI 0 "register_operand" "=r")
1931         (lshiftrt:DI
1932           (match_operand:DI 1 "reg_or_0_operand" "rJ")
1933           (minus:DI (const_int 56)
1934                     (ashift:DI
1935                       (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1936                       (const_int 3)))))]
1937   "WORDS_BIG_ENDIAN"
1938   "extql %1,%2,%0"
1939   [(set_attr "type" "shift")])
1940
1941 (define_insn "extqh_le"
1942   [(set (match_operand:DI 0 "register_operand" "=r")
1943         (ashift:DI
1944          (match_operand:DI 1 "reg_or_0_operand" "rJ")
1945           (minus:DI (const_int 64)
1946                     (ashift:DI
1947                      (and:DI
1948                       (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1949                       (const_int 7))
1950                      (const_int 3)))))]
1951   "! WORDS_BIG_ENDIAN"
1952   "extqh %r1,%2,%0"
1953   [(set_attr "type" "shift")])
1954
1955 (define_insn "extqh_be"
1956   [(set (match_operand:DI 0 "register_operand" "=r")
1957         (ashift:DI
1958           (match_operand:DI 1 "reg_or_0_operand" "rJ")
1959           (ashift:DI
1960             (and:DI
1961               (plus:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1962                        (const_int 1))
1963               (const_int 7))
1964             (const_int 3))))]
1965   "WORDS_BIG_ENDIAN"
1966   "extqh %r1,%2,%0"
1967   [(set_attr "type" "shift")])
1968
1969 (define_insn "extlh_le"
1970   [(set (match_operand:DI 0 "register_operand" "=r")
1971         (ashift:DI
1972          (and:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1973                  (const_int 2147483647))
1974          (minus:DI (const_int 64)
1975                     (ashift:DI
1976                      (and:DI
1977                       (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1978                       (const_int 7))
1979                      (const_int 3)))))]
1980   "! WORDS_BIG_ENDIAN"
1981   "extlh %r1,%2,%0"
1982   [(set_attr "type" "shift")])
1983
1984 (define_insn "extlh_be"
1985   [(set (match_operand:DI 0 "register_operand" "=r")
1986         (and:DI
1987           (ashift:DI
1988             (match_operand:DI 1 "reg_or_0_operand" "rJ")
1989             (ashift:DI
1990               (and:DI
1991                 (plus:DI
1992                   (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1993                   (const_int 1))
1994                 (const_int 7))
1995               (const_int 3)))
1996           (const_int 2147483647)))]
1997   "WORDS_BIG_ENDIAN"
1998   "extlh %r1,%2,%0"
1999   [(set_attr "type" "shift")])
2000
2001 (define_insn "extwh_le"
2002   [(set (match_operand:DI 0 "register_operand" "=r")
2003         (ashift:DI
2004          (and:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
2005                  (const_int 65535))
2006          (minus:DI (const_int 64)
2007                     (ashift:DI
2008                      (and:DI
2009                       (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2010                       (const_int 7))
2011                      (const_int 3)))))]
2012   "! WORDS_BIG_ENDIAN"
2013   "extwh %r1,%2,%0"
2014   [(set_attr "type" "shift")])
2015
2016 (define_insn "extwh_be"
2017   [(set (match_operand:DI 0 "register_operand" "=r")
2018         (and:DI
2019           (ashift:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
2020                      (ashift:DI
2021                        (and:DI
2022                          (plus:DI
2023                            (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2024                            (const_int 1))
2025                          (const_int 7))
2026                        (const_int 3)))
2027           (const_int 65535)))]
2028   "WORDS_BIG_ENDIAN"
2029   "extwh %r1,%2,%0"
2030   [(set_attr "type" "shift")])
2031
2032 ;; This converts an extXl into an extXh with an appropriate adjustment
2033 ;; to the address calculation.
2034
2035 ;;(define_split
2036 ;;  [(set (match_operand:DI 0 "register_operand" "")
2037 ;;      (ashift:DI (zero_extract:DI (match_operand:DI 1 "register_operand" "")
2038 ;;                                  (match_operand:DI 2 "mode_width_operand" "")
2039 ;;                                  (ashift:DI (match_operand:DI 3 "" "")
2040 ;;                                             (const_int 3)))
2041 ;;                 (match_operand:DI 4 "const_int_operand" "")))
2042 ;;   (clobber (match_operand:DI 5 "register_operand" ""))]
2043 ;;  "INTVAL (operands[4]) == 64 - INTVAL (operands[2])"
2044 ;;  [(set (match_dup 5) (match_dup 6))
2045 ;;   (set (match_dup 0)
2046 ;;      (ashift:DI (zero_extract:DI (match_dup 1) (match_dup 2)
2047 ;;                                  (ashift:DI (plus:DI (match_dup 5)
2048 ;;                                                      (match_dup 7))
2049 ;;                                             (const_int 3)))
2050 ;;                 (match_dup 4)))]
2051 ;;  "
2052 ;;{
2053 ;;  operands[6] = plus_constant (operands[3],
2054 ;;                             INTVAL (operands[2]) / BITS_PER_UNIT);
2055 ;;  operands[7] = GEN_INT (- INTVAL (operands[2]) / BITS_PER_UNIT);
2056 ;;}")
2057
2058 (define_insn "*insbl_const"
2059   [(set (match_operand:DI 0 "register_operand" "=r")
2060         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" "r"))
2061                    (match_operand:DI 2 "mul8_operand" "I")))]
2062   ""
2063   "insbl %1,%s2,%0"
2064   [(set_attr "type" "shift")])
2065
2066 (define_insn "inswl_const"
2067   [(set (match_operand:DI 0 "register_operand" "=r")
2068         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" "r"))
2069                    (match_operand:DI 2 "mul8_operand" "I")))]
2070   ""
2071   "inswl %1,%s2,%0"
2072   [(set_attr "type" "shift")])
2073
2074 (define_insn "*insll_const"
2075   [(set (match_operand:DI 0 "register_operand" "=r")
2076         (ashift:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "r"))
2077                    (match_operand:DI 2 "mul8_operand" "I")))]
2078   ""
2079   "insll %1,%s2,%0"
2080   [(set_attr "type" "shift")])
2081
2082 (define_insn "insbl_le"
2083   [(set (match_operand:DI 0 "register_operand" "=r")
2084         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" "r"))
2085                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2086                               (const_int 3))))]
2087   "! WORDS_BIG_ENDIAN"
2088   "insbl %1,%2,%0"
2089   [(set_attr "type" "shift")])
2090
2091 (define_insn "insbl_be"
2092  [(set (match_operand:DI 0 "register_operand" "=r")
2093        (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" "r"))
2094          (minus:DI (const_int 56)
2095            (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2096                       (const_int 3)))))]
2097   "WORDS_BIG_ENDIAN"
2098   "insbl %1,%2,%0"
2099   [(set_attr "type" "shift")])
2100
2101 (define_insn "inswl_le"
2102   [(set (match_operand:DI 0 "register_operand" "=r")
2103         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" "r"))
2104                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2105                               (const_int 3))))]
2106   "! WORDS_BIG_ENDIAN"
2107   "inswl %1,%2,%0"
2108   [(set_attr "type" "shift")])
2109
2110 (define_insn "inswl_be"
2111   [(set (match_operand:DI 0 "register_operand" "=r")
2112         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" "r"))
2113           (minus:DI (const_int 56)
2114             (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2115                        (const_int 3)))))]
2116   "WORDS_BIG_ENDIAN"
2117   "inswl %1,%2,%0"
2118   [(set_attr "type" "shift")])
2119
2120 (define_insn "insll_le"
2121   [(set (match_operand:DI 0 "register_operand" "=r")
2122         (ashift:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "r"))
2123                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2124                               (const_int 3))))]
2125   "! WORDS_BIG_ENDIAN"
2126   "insll %1,%2,%0"
2127   [(set_attr "type" "shift")])
2128
2129 (define_insn "insll_be"
2130   [(set (match_operand:DI 0 "register_operand" "=r")
2131         (ashift:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "r"))
2132           (minus:DI (const_int 56)
2133             (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2134                        (const_int 3)))))]
2135   "WORDS_BIG_ENDIAN"
2136   "insll %1,%2,%0"
2137   [(set_attr "type" "shift")])
2138
2139 (define_insn "insql_le"
2140   [(set (match_operand:DI 0 "register_operand" "=r")
2141         (ashift:DI (match_operand:DI 1 "register_operand" "r")
2142                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2143                               (const_int 3))))]
2144   "! WORDS_BIG_ENDIAN"
2145   "insql %1,%2,%0"
2146   [(set_attr "type" "shift")])
2147
2148 (define_insn "insql_be"
2149   [(set (match_operand:DI 0 "register_operand" "=r")
2150         (ashift:DI (match_operand:DI 1 "register_operand" "r")
2151           (minus:DI (const_int 56)
2152             (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2153                        (const_int 3)))))]
2154   "WORDS_BIG_ENDIAN"
2155   "insql %1,%2,%0"
2156   [(set_attr "type" "shift")])
2157
2158 ;; Combine has this sometimes habit of moving the and outside of the
2159 ;; shift, making life more interesting.
2160
2161 (define_insn "*insxl"
2162   [(set (match_operand:DI 0 "register_operand" "=r")
2163         (and:DI (ashift:DI (match_operand:DI 1 "register_operand" "r")
2164                            (match_operand:DI 2 "mul8_operand" "I"))
2165                 (match_operand:DI 3 "immediate_operand" "i")))]
2166   "HOST_BITS_PER_WIDE_INT == 64
2167    && GET_CODE (operands[3]) == CONST_INT
2168    && (((unsigned HOST_WIDE_INT) 0xff << INTVAL (operands[2])
2169         == (unsigned HOST_WIDE_INT) INTVAL (operands[3]))
2170        || ((unsigned HOST_WIDE_INT) 0xffff << INTVAL (operands[2])
2171         == (unsigned HOST_WIDE_INT) INTVAL (operands[3]))
2172        || ((unsigned HOST_WIDE_INT) 0xffffffff << INTVAL (operands[2])
2173         == (unsigned HOST_WIDE_INT) INTVAL (operands[3])))"
2174 {
2175 #if HOST_BITS_PER_WIDE_INT == 64
2176   if ((unsigned HOST_WIDE_INT) 0xff << INTVAL (operands[2])
2177       == (unsigned HOST_WIDE_INT) INTVAL (operands[3]))
2178     return "insbl %1,%s2,%0";
2179   if ((unsigned HOST_WIDE_INT) 0xffff << INTVAL (operands[2])
2180       == (unsigned HOST_WIDE_INT) INTVAL (operands[3]))
2181     return "inswl %1,%s2,%0";
2182   if ((unsigned HOST_WIDE_INT) 0xffffffff << INTVAL (operands[2])
2183       == (unsigned HOST_WIDE_INT) INTVAL (operands[3]))
2184     return "insll %1,%s2,%0";
2185 #endif
2186   gcc_unreachable ();
2187 }
2188   [(set_attr "type" "shift")])
2189
2190 ;; We do not include the insXh insns because they are complex to express
2191 ;; and it does not appear that we would ever want to generate them.
2192 ;;
2193 ;; Since we need them for block moves, though, cop out and use unspec.
2194
2195 (define_insn "insxh"
2196   [(set (match_operand:DI 0 "register_operand" "=r")
2197         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
2198                     (match_operand:DI 2 "mode_width_operand" "n")
2199                     (match_operand:DI 3 "reg_or_8bit_operand" "rI")]
2200                    UNSPEC_INSXH))]
2201   ""
2202   "ins%M2h %1,%3,%0"
2203   [(set_attr "type" "shift")])
2204
2205 (define_insn "mskxl_le"
2206   [(set (match_operand:DI 0 "register_operand" "=r")
2207         (and:DI (not:DI (ashift:DI
2208                          (match_operand:DI 2 "mode_mask_operand" "n")
2209                          (ashift:DI
2210                           (match_operand:DI 3 "reg_or_8bit_operand" "rI")
2211                           (const_int 3))))
2212                 (match_operand:DI 1 "reg_or_0_operand" "rJ")))]
2213   "! WORDS_BIG_ENDIAN"
2214   "msk%U2l %r1,%3,%0"
2215   [(set_attr "type" "shift")])
2216
2217 (define_insn "mskxl_be"
2218   [(set (match_operand:DI 0 "register_operand" "=r")
2219         (and:DI (not:DI (ashift:DI
2220                           (match_operand:DI 2 "mode_mask_operand" "n")
2221                           (minus:DI (const_int 56)
2222                             (ashift:DI
2223                               (match_operand:DI 3 "reg_or_8bit_operand" "rI")
2224                               (const_int 3)))))
2225                 (match_operand:DI 1 "reg_or_0_operand" "rJ")))]
2226   "WORDS_BIG_ENDIAN"
2227   "msk%U2l %r1,%3,%0"
2228   [(set_attr "type" "shift")])
2229
2230 ;; We do not include the mskXh insns because it does not appear we would
2231 ;; ever generate one.
2232 ;;
2233 ;; Again, we do for block moves and we use unspec again.
2234
2235 (define_insn "mskxh"
2236   [(set (match_operand:DI 0 "register_operand" "=r")
2237         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
2238                     (match_operand:DI 2 "mode_width_operand" "n")
2239                     (match_operand:DI 3 "reg_or_8bit_operand" "rI")]
2240                    UNSPEC_MSKXH))]
2241   ""
2242   "msk%M2h %1,%3,%0"
2243   [(set_attr "type" "shift")])
2244
2245 ;; Prefer AND + NE over LSHIFTRT + AND.
2246
2247 (define_insn_and_split "*ze_and_ne"
2248   [(set (match_operand:DI 0 "register_operand" "=r")
2249         (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
2250                          (const_int 1)
2251                          (match_operand 2 "const_int_operand" "I")))]
2252   "(unsigned HOST_WIDE_INT) INTVAL (operands[2]) < 8"
2253   "#"
2254   "(unsigned HOST_WIDE_INT) INTVAL (operands[2]) < 8"
2255   [(set (match_dup 0)
2256         (and:DI (match_dup 1) (match_dup 3)))
2257    (set (match_dup 0)
2258         (ne:DI (match_dup 0) (const_int 0)))]
2259   "operands[3] = GEN_INT (1 << INTVAL (operands[2]));")
2260 \f
2261 ;; Floating-point operations.  All the double-precision insns can extend
2262 ;; from single, so indicate that.  The exception are the ones that simply
2263 ;; play with the sign bits; it's not clear what to do there.
2264
2265 (define_insn "abssf2"
2266   [(set (match_operand:SF 0 "register_operand" "=f")
2267         (abs:SF (match_operand:SF 1 "reg_or_0_operand" "fG")))]
2268   "TARGET_FP"
2269   "cpys $f31,%R1,%0"
2270   [(set_attr "type" "fcpys")])
2271
2272 (define_insn "*nabssf2"
2273   [(set (match_operand:SF 0 "register_operand" "=f")
2274         (neg:SF (abs:SF (match_operand:SF 1 "reg_or_0_operand" "fG"))))]
2275   "TARGET_FP"
2276   "cpysn $f31,%R1,%0"
2277   [(set_attr "type" "fadd")])
2278
2279 (define_insn "absdf2"
2280   [(set (match_operand:DF 0 "register_operand" "=f")
2281         (abs:DF (match_operand:DF 1 "reg_or_0_operand" "fG")))]
2282   "TARGET_FP"
2283   "cpys $f31,%R1,%0"
2284   [(set_attr "type" "fcpys")])
2285
2286 (define_insn "*nabsdf2"
2287   [(set (match_operand:DF 0 "register_operand" "=f")
2288         (neg:DF (abs:DF (match_operand:DF 1 "reg_or_0_operand" "fG"))))]
2289   "TARGET_FP"
2290   "cpysn $f31,%R1,%0"
2291   [(set_attr "type" "fadd")])
2292
2293 (define_expand "abstf2"
2294   [(parallel [(set (match_operand:TF 0 "register_operand" "")
2295                    (abs:TF (match_operand:TF 1 "reg_or_0_operand" "")))
2296               (use (match_dup 2))])]
2297   "TARGET_HAS_XFLOATING_LIBS"
2298 {
2299 #if HOST_BITS_PER_WIDE_INT >= 64
2300   operands[2] = force_reg (DImode, GEN_INT ((HOST_WIDE_INT) 1 << 63));
2301 #else
2302   operands[2] = force_reg (DImode, immed_double_const (0, 0x80000000, DImode));
2303 #endif
2304 })
2305
2306 (define_insn_and_split "*abstf_internal"
2307   [(set (match_operand:TF 0 "register_operand" "=r")
2308         (abs:TF (match_operand:TF 1 "reg_or_0_operand" "rG")))
2309    (use (match_operand:DI 2 "register_operand" "r"))]
2310   "TARGET_HAS_XFLOATING_LIBS"
2311   "#"
2312   "&& reload_completed"
2313   [(const_int 0)]
2314   "alpha_split_tfmode_frobsign (operands, gen_andnotdi3); DONE;")
2315
2316 (define_insn "negsf2"
2317   [(set (match_operand:SF 0 "register_operand" "=f")
2318         (neg:SF (match_operand:SF 1 "reg_or_0_operand" "fG")))]
2319   "TARGET_FP"
2320   "cpysn %R1,%R1,%0"
2321   [(set_attr "type" "fadd")])
2322
2323 (define_insn "negdf2"
2324   [(set (match_operand:DF 0 "register_operand" "=f")
2325         (neg:DF (match_operand:DF 1 "reg_or_0_operand" "fG")))]
2326   "TARGET_FP"
2327   "cpysn %R1,%R1,%0"
2328   [(set_attr "type" "fadd")])
2329
2330 (define_expand "negtf2"
2331   [(parallel [(set (match_operand:TF 0 "register_operand" "")
2332                    (neg:TF (match_operand:TF 1 "reg_or_0_operand" "")))
2333               (use (match_dup 2))])]
2334   "TARGET_HAS_XFLOATING_LIBS"
2335 {
2336 #if HOST_BITS_PER_WIDE_INT >= 64
2337   operands[2] = force_reg (DImode, GEN_INT ((HOST_WIDE_INT) 1 << 63));
2338 #else
2339   operands[2] = force_reg (DImode, immed_double_const (0, 0x80000000, DImode));
2340 #endif
2341 })
2342
2343 (define_insn_and_split "*negtf_internal"
2344   [(set (match_operand:TF 0 "register_operand" "=r")
2345         (neg:TF (match_operand:TF 1 "reg_or_0_operand" "rG")))
2346    (use (match_operand:DI 2 "register_operand" "r"))]
2347   "TARGET_HAS_XFLOATING_LIBS"
2348   "#"
2349   "&& reload_completed"
2350   [(const_int 0)]
2351   "alpha_split_tfmode_frobsign (operands, gen_xordi3); DONE;")
2352
2353 (define_insn "copysignsf3"
2354   [(set (match_operand:SF 0 "register_operand" "=f")
2355         (unspec:SF [(match_operand:SF 1 "reg_or_0_operand" "fG")
2356                     (match_operand:SF 2 "reg_or_0_operand" "fG")]
2357                    UNSPEC_COPYSIGN))]
2358   "TARGET_FP"
2359   "cpys %R2,%R1,%0"
2360   [(set_attr "type" "fadd")])
2361
2362 (define_insn "*ncopysignsf3"
2363   [(set (match_operand:SF 0 "register_operand" "=f")
2364         (neg:SF (unspec:SF [(match_operand:SF 1 "reg_or_0_operand" "fG")
2365                             (match_operand:SF 2 "reg_or_0_operand" "fG")]
2366                            UNSPEC_COPYSIGN)))]
2367   "TARGET_FP"
2368   "cpysn %R2,%R1,%0"
2369   [(set_attr "type" "fadd")])
2370
2371 (define_insn "copysigndf3"
2372   [(set (match_operand:DF 0 "register_operand" "=f")
2373         (unspec:DF [(match_operand:DF 1 "reg_or_0_operand" "fG")
2374                     (match_operand:DF 2 "reg_or_0_operand" "fG")]
2375                    UNSPEC_COPYSIGN))]
2376   "TARGET_FP"
2377   "cpys %R2,%R1,%0"
2378   [(set_attr "type" "fadd")])
2379
2380 (define_insn "*ncopysigndf3"
2381   [(set (match_operand:DF 0 "register_operand" "=f")
2382         (neg:DF (unspec:DF [(match_operand:DF 1 "reg_or_0_operand" "fG")
2383                             (match_operand:DF 2 "reg_or_0_operand" "fG")]
2384                            UNSPEC_COPYSIGN)))]
2385   "TARGET_FP"
2386   "cpysn %R2,%R1,%0"
2387   [(set_attr "type" "fadd")])
2388
2389 (define_insn "*addsf_ieee"
2390   [(set (match_operand:SF 0 "register_operand" "=&f")
2391         (plus:SF (match_operand:SF 1 "reg_or_0_operand" "%fG")
2392                  (match_operand:SF 2 "reg_or_0_operand" "fG")))]
2393   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2394   "add%,%/ %R1,%R2,%0"
2395   [(set_attr "type" "fadd")
2396    (set_attr "trap" "yes")
2397    (set_attr "round_suffix" "normal")
2398    (set_attr "trap_suffix" "u_su_sui")])
2399
2400 (define_insn "addsf3"
2401   [(set (match_operand:SF 0 "register_operand" "=f")
2402         (plus:SF (match_operand:SF 1 "reg_or_0_operand" "%fG")
2403                  (match_operand:SF 2 "reg_or_0_operand" "fG")))]
2404   "TARGET_FP"
2405   "add%,%/ %R1,%R2,%0"
2406   [(set_attr "type" "fadd")
2407    (set_attr "trap" "yes")
2408    (set_attr "round_suffix" "normal")
2409    (set_attr "trap_suffix" "u_su_sui")])
2410
2411 (define_insn "*adddf_ieee"
2412   [(set (match_operand:DF 0 "register_operand" "=&f")
2413         (plus:DF (match_operand:DF 1 "reg_or_0_operand" "%fG")
2414                  (match_operand:DF 2 "reg_or_0_operand" "fG")))]
2415   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2416   "add%-%/ %R1,%R2,%0"
2417   [(set_attr "type" "fadd")
2418    (set_attr "trap" "yes")
2419    (set_attr "round_suffix" "normal")
2420    (set_attr "trap_suffix" "u_su_sui")])
2421
2422 (define_insn "adddf3"
2423   [(set (match_operand:DF 0 "register_operand" "=f")
2424         (plus:DF (match_operand:DF 1 "reg_or_0_operand" "%fG")
2425                  (match_operand:DF 2 "reg_or_0_operand" "fG")))]
2426   "TARGET_FP"
2427   "add%-%/ %R1,%R2,%0"
2428   [(set_attr "type" "fadd")
2429    (set_attr "trap" "yes")
2430    (set_attr "round_suffix" "normal")
2431    (set_attr "trap_suffix" "u_su_sui")])
2432
2433 (define_insn "*adddf_ext1"
2434   [(set (match_operand:DF 0 "register_operand" "=f")
2435         (plus:DF (float_extend:DF
2436                   (match_operand:SF 1 "reg_or_0_operand" "fG"))
2437                  (match_operand:DF 2 "reg_or_0_operand" "fG")))]
2438   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2439   "add%-%/ %R1,%R2,%0"
2440   [(set_attr "type" "fadd")
2441    (set_attr "trap" "yes")
2442    (set_attr "round_suffix" "normal")
2443    (set_attr "trap_suffix" "u_su_sui")])
2444
2445 (define_insn "*adddf_ext2"
2446   [(set (match_operand:DF 0 "register_operand" "=f")
2447         (plus:DF (float_extend:DF
2448                   (match_operand:SF 1 "reg_or_0_operand" "%fG"))
2449                  (float_extend:DF
2450                   (match_operand:SF 2 "reg_or_0_operand" "fG"))))]
2451   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2452   "add%-%/ %R1,%R2,%0"
2453   [(set_attr "type" "fadd")
2454    (set_attr "trap" "yes")
2455    (set_attr "round_suffix" "normal")
2456    (set_attr "trap_suffix" "u_su_sui")])
2457
2458 (define_expand "addtf3"
2459   [(use (match_operand 0 "register_operand" ""))
2460    (use (match_operand 1 "general_operand" ""))
2461    (use (match_operand 2 "general_operand" ""))]
2462   "TARGET_HAS_XFLOATING_LIBS"
2463   "alpha_emit_xfloating_arith (PLUS, operands); DONE;")
2464
2465 ;; Define conversion operators between DFmode and SImode, using the cvtql
2466 ;; instruction.  To allow combine et al to do useful things, we keep the
2467 ;; operation as a unit until after reload, at which point we split the
2468 ;; instructions.
2469 ;;
2470 ;; Note that we (attempt to) only consider this optimization when the
2471 ;; ultimate destination is memory.  If we will be doing further integer
2472 ;; processing, it is cheaper to do the truncation in the int regs.
2473
2474 (define_insn "*cvtql"
2475   [(set (match_operand:SF 0 "register_operand" "=f")
2476         (unspec:SF [(match_operand:DI 1 "reg_or_0_operand" "fG")]
2477                    UNSPEC_CVTQL))]
2478   "TARGET_FP"
2479   "cvtql%/ %R1,%0"
2480   [(set_attr "type" "fadd")
2481    (set_attr "trap" "yes")
2482    (set_attr "trap_suffix" "v_sv")])
2483
2484 (define_insn_and_split "*fix_truncdfsi_ieee"
2485   [(set (match_operand:SI 0 "memory_operand" "=m")
2486         (subreg:SI
2487           (match_operator:DI 4 "fix_operator" 
2488             [(match_operand:DF 1 "reg_or_0_operand" "fG")]) 0))
2489    (clobber (match_scratch:DI 2 "=&f"))
2490    (clobber (match_scratch:SF 3 "=&f"))]
2491   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2492   "#"
2493   "&& reload_completed"
2494   [(set (match_dup 2) (match_op_dup 4 [(match_dup 1)]))
2495    (set (match_dup 3) (unspec:SF [(match_dup 2)] UNSPEC_CVTQL))
2496    (set (match_dup 5) (match_dup 3))]
2497 {
2498   operands[5] = adjust_address (operands[0], SFmode, 0);
2499 }
2500   [(set_attr "type" "fadd")
2501    (set_attr "trap" "yes")])
2502
2503 (define_insn_and_split "*fix_truncdfsi_internal"
2504   [(set (match_operand:SI 0 "memory_operand" "=m")
2505         (subreg:SI
2506           (match_operator:DI 3 "fix_operator" 
2507             [(match_operand:DF 1 "reg_or_0_operand" "fG")]) 0))
2508    (clobber (match_scratch:DI 2 "=f"))]
2509   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2510   "#"
2511   "&& reload_completed"
2512   [(set (match_dup 2) (match_op_dup 3 [(match_dup 1)]))
2513    (set (match_dup 4) (unspec:SF [(match_dup 2)] UNSPEC_CVTQL))
2514    (set (match_dup 5) (match_dup 4))]
2515 {
2516   operands[4] = gen_rtx_REG (SFmode, REGNO (operands[2]));
2517   operands[5] = adjust_address (operands[0], SFmode, 0);
2518 }
2519   [(set_attr "type" "fadd")
2520    (set_attr "trap" "yes")])
2521
2522 (define_insn "*fix_truncdfdi_ieee"
2523   [(set (match_operand:DI 0 "reg_no_subreg_operand" "=&f")
2524         (match_operator:DI 2 "fix_operator" 
2525           [(match_operand:DF 1 "reg_or_0_operand" "fG")]))]
2526   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2527   "cvt%-q%/ %R1,%0"
2528   [(set_attr "type" "fadd")
2529    (set_attr "trap" "yes")
2530    (set_attr "round_suffix" "c")
2531    (set_attr "trap_suffix" "v_sv_svi")])
2532
2533 (define_insn "*fix_truncdfdi2"
2534   [(set (match_operand:DI 0 "reg_no_subreg_operand" "=f")
2535         (match_operator:DI 2 "fix_operator" 
2536           [(match_operand:DF 1 "reg_or_0_operand" "fG")]))]
2537   "TARGET_FP"
2538   "cvt%-q%/ %R1,%0"
2539   [(set_attr "type" "fadd")
2540    (set_attr "trap" "yes")
2541    (set_attr "round_suffix" "c")
2542    (set_attr "trap_suffix" "v_sv_svi")])
2543
2544 (define_expand "fix_truncdfdi2"
2545   [(set (match_operand:DI 0 "reg_no_subreg_operand" "")
2546         (fix:DI (match_operand:DF 1 "reg_or_0_operand" "")))]
2547   "TARGET_FP"
2548   "")
2549
2550 (define_expand "fixuns_truncdfdi2"
2551   [(set (match_operand:DI 0 "reg_no_subreg_operand" "")
2552         (unsigned_fix:DI (match_operand:DF 1 "reg_or_0_operand" "")))]
2553   "TARGET_FP"
2554   "")
2555
2556 ;; Likewise between SFmode and SImode.
2557
2558 (define_insn_and_split "*fix_truncsfsi_ieee"
2559   [(set (match_operand:SI 0 "memory_operand" "=m")
2560         (subreg:SI
2561           (match_operator:DI 4 "fix_operator" 
2562             [(float_extend:DF
2563                (match_operand:SF 1 "reg_or_0_operand" "fG"))]) 0))
2564    (clobber (match_scratch:DI 2 "=&f"))
2565    (clobber (match_scratch:SF 3 "=&f"))]
2566   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2567   "#"
2568   "&& reload_completed"
2569   [(set (match_dup 2) (match_op_dup 4 [(float_extend:DF (match_dup 1))]))
2570    (set (match_dup 3) (unspec:SF [(match_dup 2)] UNSPEC_CVTQL))
2571    (set (match_dup 5) (match_dup 3))]
2572 {
2573   operands[5] = adjust_address (operands[0], SFmode, 0);
2574 }
2575   [(set_attr "type" "fadd")
2576    (set_attr "trap" "yes")])
2577
2578 (define_insn_and_split "*fix_truncsfsi_internal"
2579   [(set (match_operand:SI 0 "memory_operand" "=m")
2580         (subreg:SI
2581           (match_operator:DI 3 "fix_operator" 
2582             [(float_extend:DF
2583                (match_operand:SF 1 "reg_or_0_operand" "fG"))]) 0))
2584    (clobber (match_scratch:DI 2 "=f"))]
2585   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2586   "#"
2587   "&& reload_completed"
2588   [(set (match_dup 2) (match_op_dup 3 [(float_extend:DF (match_dup 1))]))
2589    (set (match_dup 4) (unspec:SF [(match_dup 2)] UNSPEC_CVTQL))
2590    (set (match_dup 5) (match_dup 4))]
2591 {
2592   operands[4] = gen_rtx_REG (SFmode, REGNO (operands[2]));
2593   operands[5] = adjust_address (operands[0], SFmode, 0);
2594 }
2595   [(set_attr "type" "fadd")
2596    (set_attr "trap" "yes")])
2597
2598 (define_insn "*fix_truncsfdi_ieee"
2599   [(set (match_operand:DI 0 "reg_no_subreg_operand" "=&f")
2600         (match_operator:DI 2 "fix_operator" 
2601           [(float_extend:DF (match_operand:SF 1 "reg_or_0_operand" "fG"))]))]
2602   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2603   "cvt%-q%/ %R1,%0"
2604   [(set_attr "type" "fadd")
2605    (set_attr "trap" "yes")
2606    (set_attr "round_suffix" "c")
2607    (set_attr "trap_suffix" "v_sv_svi")])
2608
2609 (define_insn "*fix_truncsfdi2"
2610   [(set (match_operand:DI 0 "reg_no_subreg_operand" "=f")
2611         (match_operator:DI 2 "fix_operator" 
2612           [(float_extend:DF (match_operand:SF 1 "reg_or_0_operand" "fG"))]))]
2613   "TARGET_FP"
2614   "cvt%-q%/ %R1,%0"
2615   [(set_attr "type" "fadd")
2616    (set_attr "trap" "yes")
2617    (set_attr "round_suffix" "c")
2618    (set_attr "trap_suffix" "v_sv_svi")])
2619
2620 (define_expand "fix_truncsfdi2"
2621   [(set (match_operand:DI 0 "reg_no_subreg_operand" "")
2622         (fix:DI (float_extend:DF (match_operand:SF 1 "reg_or_0_operand" ""))))]
2623   "TARGET_FP"
2624   "")
2625
2626 (define_expand "fixuns_truncsfdi2"
2627   [(set (match_operand:DI 0 "reg_no_subreg_operand" "")
2628         (unsigned_fix:DI
2629           (float_extend:DF (match_operand:SF 1 "reg_or_0_operand" ""))))]
2630   "TARGET_FP"
2631   "")
2632
2633 (define_expand "fix_trunctfdi2"
2634   [(use (match_operand:DI 0 "register_operand" ""))
2635    (use (match_operand:TF 1 "general_operand" ""))]
2636   "TARGET_HAS_XFLOATING_LIBS"
2637   "alpha_emit_xfloating_cvt (FIX, operands); DONE;")
2638
2639 (define_expand "fixuns_trunctfdi2"
2640   [(use (match_operand:DI 0 "register_operand" ""))
2641    (use (match_operand:TF 1 "general_operand" ""))]
2642   "TARGET_HAS_XFLOATING_LIBS"
2643   "alpha_emit_xfloating_cvt (UNSIGNED_FIX, operands); DONE;")
2644
2645 (define_insn "*floatdisf_ieee"
2646   [(set (match_operand:SF 0 "register_operand" "=&f")
2647         (float:SF (match_operand:DI 1 "reg_no_subreg_operand" "f")))]
2648   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2649   "cvtq%,%/ %1,%0"
2650   [(set_attr "type" "fadd")
2651    (set_attr "trap" "yes")
2652    (set_attr "round_suffix" "normal")
2653    (set_attr "trap_suffix" "sui")])
2654
2655 (define_insn "floatdisf2"
2656   [(set (match_operand:SF 0 "register_operand" "=f")
2657         (float:SF (match_operand:DI 1 "reg_no_subreg_operand" "f")))]
2658   "TARGET_FP"
2659   "cvtq%,%/ %1,%0"
2660   [(set_attr "type" "fadd")
2661    (set_attr "trap" "yes")
2662    (set_attr "round_suffix" "normal")
2663    (set_attr "trap_suffix" "sui")])
2664
2665 (define_insn_and_split "*floatsisf2_ieee"
2666   [(set (match_operand:SF 0 "register_operand" "=&f")
2667         (float:SF (match_operand:SI 1 "memory_operand" "m")))
2668    (clobber (match_scratch:DI 2 "=&f"))
2669    (clobber (match_scratch:SF 3 "=&f"))]
2670   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2671   "#"
2672   "&& reload_completed"
2673   [(set (match_dup 3) (match_dup 1))
2674    (set (match_dup 2) (unspec:DI [(match_dup 3)] UNSPEC_CVTLQ))
2675    (set (match_dup 0) (float:SF (match_dup 2)))]
2676 {
2677   operands[1] = adjust_address (operands[1], SFmode, 0);
2678 })
2679
2680 (define_insn_and_split "*floatsisf2"
2681   [(set (match_operand:SF 0 "register_operand" "=f")
2682         (float:SF (match_operand:SI 1 "memory_operand" "m")))]
2683   "TARGET_FP"
2684   "#"
2685   "&& reload_completed"
2686   [(set (match_dup 0) (match_dup 1))
2687    (set (match_dup 2) (unspec:DI [(match_dup 0)] UNSPEC_CVTLQ))
2688    (set (match_dup 0) (float:SF (match_dup 2)))]
2689 {
2690   operands[1] = adjust_address (operands[1], SFmode, 0);
2691   operands[2] = gen_rtx_REG (DImode, REGNO (operands[0]));
2692 })
2693
2694 (define_insn "*floatdidf_ieee"
2695   [(set (match_operand:DF 0 "register_operand" "=&f")
2696         (float:DF (match_operand:DI 1 "reg_no_subreg_operand" "f")))]
2697   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2698   "cvtq%-%/ %1,%0"
2699   [(set_attr "type" "fadd")
2700    (set_attr "trap" "yes")
2701    (set_attr "round_suffix" "normal")
2702    (set_attr "trap_suffix" "sui")])
2703
2704 (define_insn "floatdidf2"
2705   [(set (match_operand:DF 0 "register_operand" "=f")
2706         (float:DF (match_operand:DI 1 "reg_no_subreg_operand" "f")))]
2707   "TARGET_FP"
2708   "cvtq%-%/ %1,%0"
2709   [(set_attr "type" "fadd")
2710    (set_attr "trap" "yes")
2711    (set_attr "round_suffix" "normal")
2712    (set_attr "trap_suffix" "sui")])
2713
2714 (define_insn_and_split "*floatsidf2_ieee"
2715   [(set (match_operand:DF 0 "register_operand" "=&f")
2716         (float:DF (match_operand:SI 1 "memory_operand" "m")))
2717    (clobber (match_scratch:DI 2 "=&f"))
2718    (clobber (match_scratch:SF 3 "=&f"))]
2719   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2720   "#"
2721   "&& reload_completed"
2722   [(set (match_dup 3) (match_dup 1))
2723    (set (match_dup 2) (unspec:DI [(match_dup 3)] UNSPEC_CVTLQ))
2724    (set (match_dup 0) (float:DF (match_dup 2)))]
2725 {
2726   operands[1] = adjust_address (operands[1], SFmode, 0);
2727 })
2728
2729 (define_insn_and_split "*floatsidf2"
2730   [(set (match_operand:DF 0 "register_operand" "=f")
2731         (float:DF (match_operand:SI 1 "memory_operand" "m")))]
2732   "TARGET_FP"
2733   "#"
2734   "&& reload_completed"
2735   [(set (match_dup 3) (match_dup 1))
2736    (set (match_dup 2) (unspec:DI [(match_dup 3)] UNSPEC_CVTLQ))
2737    (set (match_dup 0) (float:DF (match_dup 2)))]
2738 {
2739   operands[1] = adjust_address (operands[1], SFmode, 0);
2740   operands[2] = gen_rtx_REG (DImode, REGNO (operands[0]));
2741   operands[3] = gen_rtx_REG (SFmode, REGNO (operands[0]));
2742 })
2743
2744 (define_expand "floatditf2"
2745   [(use (match_operand:TF 0 "register_operand" ""))
2746    (use (match_operand:DI 1 "general_operand" ""))]
2747   "TARGET_HAS_XFLOATING_LIBS"
2748   "alpha_emit_xfloating_cvt (FLOAT, operands); DONE;")
2749
2750 (define_expand "floatunsdisf2"
2751   [(use (match_operand:SF 0 "register_operand" ""))
2752    (use (match_operand:DI 1 "register_operand" ""))]
2753   "TARGET_FP"
2754   "alpha_emit_floatuns (operands); DONE;")
2755
2756 (define_expand "floatunsdidf2"
2757   [(use (match_operand:DF 0 "register_operand" ""))
2758    (use (match_operand:DI 1 "register_operand" ""))]
2759   "TARGET_FP"
2760   "alpha_emit_floatuns (operands); DONE;")
2761
2762 (define_expand "floatunsditf2"
2763   [(use (match_operand:TF 0 "register_operand" ""))
2764    (use (match_operand:DI 1 "general_operand" ""))]
2765   "TARGET_HAS_XFLOATING_LIBS"
2766   "alpha_emit_xfloating_cvt (UNSIGNED_FLOAT, operands); DONE;")
2767
2768 (define_expand "extendsfdf2"
2769   [(set (match_operand:DF 0 "register_operand" "")
2770         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "")))]
2771   "TARGET_FP"
2772 {
2773   if (alpha_fptm >= ALPHA_FPTM_SU)
2774     operands[1] = force_reg (SFmode, operands[1]);
2775 })
2776
2777 ;; The Unicos/Mk assembler doesn't support cvtst, but we've already
2778 ;; asserted that alpha_fptm == ALPHA_FPTM_N.
2779
2780 (define_insn "*extendsfdf2_ieee"
2781   [(set (match_operand:DF 0 "register_operand" "=&f")
2782         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
2783   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2784   "cvtsts %1,%0"
2785   [(set_attr "type" "fadd")
2786    (set_attr "trap" "yes")])
2787
2788 (define_insn "*extendsfdf2_internal"
2789   [(set (match_operand:DF 0 "register_operand" "=f,f,m")
2790         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "f,m,f")))]
2791   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2792   "@
2793    cpys %1,%1,%0
2794    ld%, %0,%1
2795    st%- %1,%0"
2796   [(set_attr "type" "fcpys,fld,fst")])
2797
2798 ;; Use register_operand for operand 1 to prevent compress_float_constant
2799 ;; from doing something silly.  When optimizing we'll put things back 
2800 ;; together anyway.
2801 (define_expand "extendsftf2"
2802   [(use (match_operand:TF 0 "register_operand" ""))
2803    (use (match_operand:SF 1 "register_operand" ""))]
2804   "TARGET_HAS_XFLOATING_LIBS"
2805 {
2806   rtx tmp = gen_reg_rtx (DFmode);
2807   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
2808   emit_insn (gen_extenddftf2 (operands[0], tmp));
2809   DONE;
2810 })
2811
2812 (define_expand "extenddftf2"
2813   [(use (match_operand:TF 0 "register_operand" ""))
2814    (use (match_operand:DF 1 "register_operand" ""))]
2815   "TARGET_HAS_XFLOATING_LIBS"
2816   "alpha_emit_xfloating_cvt (FLOAT_EXTEND, operands); DONE;")
2817
2818 (define_insn "*truncdfsf2_ieee"
2819   [(set (match_operand:SF 0 "register_operand" "=&f")
2820         (float_truncate:SF (match_operand:DF 1 "reg_or_0_operand" "fG")))]
2821   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2822   "cvt%-%,%/ %R1,%0"
2823   [(set_attr "type" "fadd")
2824    (set_attr "trap" "yes")
2825    (set_attr "round_suffix" "normal")
2826    (set_attr "trap_suffix" "u_su_sui")])
2827
2828 (define_insn "truncdfsf2"
2829   [(set (match_operand:SF 0 "register_operand" "=f")
2830         (float_truncate:SF (match_operand:DF 1 "reg_or_0_operand" "fG")))]
2831   "TARGET_FP"
2832   "cvt%-%,%/ %R1,%0"
2833   [(set_attr "type" "fadd")
2834    (set_attr "trap" "yes")
2835    (set_attr "round_suffix" "normal")
2836    (set_attr "trap_suffix" "u_su_sui")])
2837
2838 (define_expand "trunctfdf2"
2839   [(use (match_operand:DF 0 "register_operand" ""))
2840    (use (match_operand:TF 1 "general_operand" ""))]
2841   "TARGET_HAS_XFLOATING_LIBS"
2842   "alpha_emit_xfloating_cvt (FLOAT_TRUNCATE, operands); DONE;")
2843
2844 (define_expand "trunctfsf2"
2845   [(use (match_operand:SF 0 "register_operand" ""))
2846    (use (match_operand:TF 1 "general_operand" ""))]
2847   "TARGET_FP && TARGET_HAS_XFLOATING_LIBS"
2848 {
2849   rtx tmpf, sticky, arg, lo, hi;
2850
2851   tmpf = gen_reg_rtx (DFmode);
2852   sticky = gen_reg_rtx (DImode);
2853   arg = copy_to_mode_reg (TFmode, operands[1]);
2854   lo = gen_lowpart (DImode, arg);
2855   hi = gen_highpart (DImode, arg);
2856
2857   /* Convert the low word of the TFmode value into a sticky rounding bit,
2858      then or it into the low bit of the high word.  This leaves the sticky
2859      bit at bit 48 of the fraction, which is representable in DFmode,
2860      which prevents rounding error in the final conversion to SFmode.  */
2861
2862   emit_insn (gen_rtx_SET (VOIDmode, sticky,
2863                           gen_rtx_NE (DImode, lo, const0_rtx)));
2864   emit_insn (gen_iordi3 (hi, hi, sticky));
2865   emit_insn (gen_trunctfdf2 (tmpf, arg));
2866   emit_insn (gen_truncdfsf2 (operands[0], tmpf));
2867   DONE;
2868 })
2869
2870 (define_insn "*divsf3_ieee"
2871   [(set (match_operand:SF 0 "register_operand" "=&f")
2872         (div:SF (match_operand:SF 1 "reg_or_0_operand" "fG")
2873                 (match_operand:SF 2 "reg_or_0_operand" "fG")))]
2874   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2875   "div%,%/ %R1,%R2,%0"
2876   [(set_attr "type" "fdiv")
2877    (set_attr "opsize" "si")
2878    (set_attr "trap" "yes")
2879    (set_attr "round_suffix" "normal")
2880    (set_attr "trap_suffix" "u_su_sui")])
2881
2882 (define_insn "divsf3"
2883   [(set (match_operand:SF 0 "register_operand" "=f")
2884         (div:SF (match_operand:SF 1 "reg_or_0_operand" "fG")
2885                 (match_operand:SF 2 "reg_or_0_operand" "fG")))]
2886   "TARGET_FP"
2887   "div%,%/ %R1,%R2,%0"
2888   [(set_attr "type" "fdiv")
2889    (set_attr "opsize" "si")
2890    (set_attr "trap" "yes")
2891    (set_attr "round_suffix" "normal")
2892    (set_attr "trap_suffix" "u_su_sui")])
2893
2894 (define_insn "*divdf3_ieee"
2895   [(set (match_operand:DF 0 "register_operand" "=&f")
2896         (div:DF (match_operand:DF 1 "reg_or_0_operand" "fG")
2897                 (match_operand:DF 2 "reg_or_0_operand" "fG")))]
2898   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2899   "div%-%/ %R1,%R2,%0"
2900   [(set_attr "type" "fdiv")
2901    (set_attr "trap" "yes")
2902    (set_attr "round_suffix" "normal")
2903    (set_attr "trap_suffix" "u_su_sui")])
2904
2905 (define_insn "divdf3"
2906   [(set (match_operand:DF 0 "register_operand" "=f")
2907         (div:DF (match_operand:DF 1 "reg_or_0_operand" "fG")
2908                 (match_operand:DF 2 "reg_or_0_operand" "fG")))]
2909   "TARGET_FP"
2910   "div%-%/ %R1,%R2,%0"
2911   [(set_attr "type" "fdiv")
2912    (set_attr "trap" "yes")
2913    (set_attr "round_suffix" "normal")
2914    (set_attr "trap_suffix" "u_su_sui")])
2915
2916 (define_insn "*divdf_ext1"
2917   [(set (match_operand:DF 0 "register_operand" "=f")
2918         (div:DF (float_extend:DF (match_operand:SF 1 "reg_or_0_operand" "fG"))
2919                 (match_operand:DF 2 "reg_or_0_operand" "fG")))]
2920   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2921   "div%-%/ %R1,%R2,%0"
2922   [(set_attr "type" "fdiv")
2923    (set_attr "trap" "yes")
2924    (set_attr "round_suffix" "normal")
2925    (set_attr "trap_suffix" "u_su_sui")])
2926
2927 (define_insn "*divdf_ext2"
2928   [(set (match_operand:DF 0 "register_operand" "=f")
2929         (div:DF (match_operand:DF 1 "reg_or_0_operand" "fG")
2930                 (float_extend:DF
2931                  (match_operand:SF 2 "reg_or_0_operand" "fG"))))]
2932   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2933   "div%-%/ %R1,%R2,%0"
2934   [(set_attr "type" "fdiv")
2935    (set_attr "trap" "yes")
2936    (set_attr "round_suffix" "normal")
2937    (set_attr "trap_suffix" "u_su_sui")])
2938
2939 (define_insn "*divdf_ext3"
2940   [(set (match_operand:DF 0 "register_operand" "=f")
2941         (div:DF (float_extend:DF (match_operand:SF 1 "reg_or_0_operand" "fG"))
2942                 (float_extend:DF (match_operand:SF 2 "reg_or_0_operand" "fG"))))]
2943   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2944   "div%-%/ %R1,%R2,%0"
2945   [(set_attr "type" "fdiv")
2946    (set_attr "trap" "yes")
2947    (set_attr "round_suffix" "normal")
2948    (set_attr "trap_suffix" "u_su_sui")])
2949
2950 (define_expand "divtf3"
2951   [(use (match_operand 0 "register_operand" ""))
2952    (use (match_operand 1 "general_operand" ""))
2953    (use (match_operand 2 "general_operand" ""))]
2954   "TARGET_HAS_XFLOATING_LIBS"
2955   "alpha_emit_xfloating_arith (DIV, operands); DONE;")
2956
2957 (define_insn "*mulsf3_ieee"
2958   [(set (match_operand:SF 0 "register_operand" "=&f")
2959         (mult:SF (match_operand:SF 1 "reg_or_0_operand" "%fG")
2960                  (match_operand:SF 2 "reg_or_0_operand" "fG")))]
2961   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2962   "mul%,%/ %R1,%R2,%0"
2963   [(set_attr "type" "fmul")
2964    (set_attr "trap" "yes")
2965    (set_attr "round_suffix" "normal")
2966    (set_attr "trap_suffix" "u_su_sui")])
2967
2968 (define_insn "mulsf3"
2969   [(set (match_operand:SF 0 "register_operand" "=f")
2970         (mult:SF (match_operand:SF 1 "reg_or_0_operand" "%fG")
2971                  (match_operand:SF 2 "reg_or_0_operand" "fG")))]
2972   "TARGET_FP"
2973   "mul%,%/ %R1,%R2,%0"
2974   [(set_attr "type" "fmul")
2975    (set_attr "trap" "yes")
2976    (set_attr "round_suffix" "normal")
2977    (set_attr "trap_suffix" "u_su_sui")])
2978
2979 (define_insn "*muldf3_ieee"
2980   [(set (match_operand:DF 0 "register_operand" "=&f")
2981         (mult:DF (match_operand:DF 1 "reg_or_0_operand" "%fG")
2982                  (match_operand:DF 2 "reg_or_0_operand" "fG")))]
2983   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2984   "mul%-%/ %R1,%R2,%0"
2985   [(set_attr "type" "fmul")
2986    (set_attr "trap" "yes")
2987    (set_attr "round_suffix" "normal")
2988    (set_attr "trap_suffix" "u_su_sui")])
2989
2990 (define_insn "muldf3"
2991   [(set (match_operand:DF 0 "register_operand" "=f")
2992         (mult:DF (match_operand:DF 1 "reg_or_0_operand" "%fG")
2993                  (match_operand:DF 2 "reg_or_0_operand" "fG")))]
2994   "TARGET_FP"
2995   "mul%-%/ %R1,%R2,%0"
2996   [(set_attr "type" "fmul")
2997    (set_attr "trap" "yes")
2998    (set_attr "round_suffix" "normal")
2999    (set_attr "trap_suffix" "u_su_sui")])
3000
3001 (define_insn "*muldf_ext1"
3002   [(set (match_operand:DF 0 "register_operand" "=f")
3003         (mult:DF (float_extend:DF
3004                   (match_operand:SF 1 "reg_or_0_operand" "fG"))
3005                  (match_operand:DF 2 "reg_or_0_operand" "fG")))]
3006   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3007   "mul%-%/ %R1,%R2,%0"
3008   [(set_attr "type" "fmul")
3009    (set_attr "trap" "yes")
3010    (set_attr "round_suffix" "normal")
3011    (set_attr "trap_suffix" "u_su_sui")])
3012
3013 (define_insn "*muldf_ext2"
3014   [(set (match_operand:DF 0 "register_operand" "=f")
3015         (mult:DF (float_extend:DF
3016                   (match_operand:SF 1 "reg_or_0_operand" "%fG"))
3017                  (float_extend:DF
3018                   (match_operand:SF 2 "reg_or_0_operand" "fG"))))]
3019   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3020   "mul%-%/ %R1,%R2,%0"
3021   [(set_attr "type" "fmul")
3022    (set_attr "trap" "yes")
3023    (set_attr "round_suffix" "normal")
3024    (set_attr "trap_suffix" "u_su_sui")])
3025
3026 (define_expand "multf3"
3027   [(use (match_operand 0 "register_operand" ""))
3028    (use (match_operand 1 "general_operand" ""))
3029    (use (match_operand 2 "general_operand" ""))]
3030   "TARGET_HAS_XFLOATING_LIBS"
3031   "alpha_emit_xfloating_arith (MULT, operands); DONE;")
3032
3033 (define_insn "*subsf3_ieee"
3034   [(set (match_operand:SF 0 "register_operand" "=&f")
3035         (minus:SF (match_operand:SF 1 "reg_or_0_operand" "fG")
3036                   (match_operand:SF 2 "reg_or_0_operand" "fG")))]
3037   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
3038   "sub%,%/ %R1,%R2,%0"
3039   [(set_attr "type" "fadd")
3040    (set_attr "trap" "yes")
3041    (set_attr "round_suffix" "normal")
3042    (set_attr "trap_suffix" "u_su_sui")])
3043
3044 (define_insn "subsf3"
3045   [(set (match_operand:SF 0 "register_operand" "=f")
3046         (minus:SF (match_operand:SF 1 "reg_or_0_operand" "fG")
3047                   (match_operand:SF 2 "reg_or_0_operand" "fG")))]
3048   "TARGET_FP"
3049   "sub%,%/ %R1,%R2,%0"
3050   [(set_attr "type" "fadd")
3051    (set_attr "trap" "yes")
3052    (set_attr "round_suffix" "normal")
3053    (set_attr "trap_suffix" "u_su_sui")])
3054
3055 (define_insn "*subdf3_ieee"
3056   [(set (match_operand:DF 0 "register_operand" "=&f")
3057         (minus:DF (match_operand:DF 1 "reg_or_0_operand" "fG")
3058                   (match_operand:DF 2 "reg_or_0_operand" "fG")))]
3059   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
3060   "sub%-%/ %R1,%R2,%0"
3061   [(set_attr "type" "fadd")
3062    (set_attr "trap" "yes")
3063    (set_attr "round_suffix" "normal")
3064    (set_attr "trap_suffix" "u_su_sui")])
3065
3066 (define_insn "subdf3"
3067   [(set (match_operand:DF 0 "register_operand" "=f")
3068         (minus:DF (match_operand:DF 1 "reg_or_0_operand" "fG")
3069                   (match_operand:DF 2 "reg_or_0_operand" "fG")))]
3070   "TARGET_FP"
3071   "sub%-%/ %R1,%R2,%0"
3072   [(set_attr "type" "fadd")
3073    (set_attr "trap" "yes")
3074    (set_attr "round_suffix" "normal")
3075    (set_attr "trap_suffix" "u_su_sui")])
3076
3077 (define_insn "*subdf_ext1"
3078   [(set (match_operand:DF 0 "register_operand" "=f")
3079         (minus:DF (float_extend:DF
3080                    (match_operand:SF 1 "reg_or_0_operand" "fG"))
3081                   (match_operand:DF 2 "reg_or_0_operand" "fG")))]
3082   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3083   "sub%-%/ %R1,%R2,%0"
3084   [(set_attr "type" "fadd")
3085    (set_attr "trap" "yes")
3086    (set_attr "round_suffix" "normal")
3087    (set_attr "trap_suffix" "u_su_sui")])
3088
3089 (define_insn "*subdf_ext2"
3090   [(set (match_operand:DF 0 "register_operand" "=f")
3091         (minus:DF (match_operand:DF 1 "reg_or_0_operand" "fG")
3092                   (float_extend:DF
3093                    (match_operand:SF 2 "reg_or_0_operand" "fG"))))]
3094   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3095   "sub%-%/ %R1,%R2,%0"
3096   [(set_attr "type" "fadd")
3097    (set_attr "trap" "yes")
3098    (set_attr "round_suffix" "normal")
3099    (set_attr "trap_suffix" "u_su_sui")])
3100
3101 (define_insn "*subdf_ext3"
3102   [(set (match_operand:DF 0 "register_operand" "=f")
3103         (minus:DF (float_extend:DF
3104                    (match_operand:SF 1 "reg_or_0_operand" "fG"))
3105                   (float_extend:DF
3106                    (match_operand:SF 2 "reg_or_0_operand" "fG"))))]
3107   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3108   "sub%-%/ %R1,%R2,%0"
3109   [(set_attr "type" "fadd")
3110    (set_attr "trap" "yes")
3111    (set_attr "round_suffix" "normal")
3112    (set_attr "trap_suffix" "u_su_sui")])
3113
3114 (define_expand "subtf3"
3115   [(use (match_operand 0 "register_operand" ""))
3116    (use (match_operand 1 "general_operand" ""))
3117    (use (match_operand 2 "general_operand" ""))]
3118   "TARGET_HAS_XFLOATING_LIBS"
3119   "alpha_emit_xfloating_arith (MINUS, operands); DONE;")
3120
3121 (define_insn "*sqrtsf2_ieee"
3122   [(set (match_operand:SF 0 "register_operand" "=&f")
3123         (sqrt:SF (match_operand:SF 1 "reg_or_0_operand" "fG")))]
3124   "TARGET_FP && TARGET_FIX && alpha_fptm >= ALPHA_FPTM_SU"
3125   "sqrt%,%/ %R1,%0"
3126   [(set_attr "type" "fsqrt")
3127    (set_attr "opsize" "si")
3128    (set_attr "trap" "yes")
3129    (set_attr "round_suffix" "normal")
3130    (set_attr "trap_suffix" "u_su_sui")])
3131
3132 (define_insn "sqrtsf2"
3133   [(set (match_operand:SF 0 "register_operand" "=f")
3134         (sqrt:SF (match_operand:SF 1 "reg_or_0_operand" "fG")))]
3135   "TARGET_FP && TARGET_FIX"
3136   "sqrt%,%/ %R1,%0"
3137   [(set_attr "type" "fsqrt")
3138    (set_attr "opsize" "si")
3139    (set_attr "trap" "yes")
3140    (set_attr "round_suffix" "normal")
3141    (set_attr "trap_suffix" "u_su_sui")])
3142
3143 (define_insn "*sqrtdf2_ieee"
3144   [(set (match_operand:DF 0 "register_operand" "=&f")
3145         (sqrt:DF (match_operand:DF 1 "reg_or_0_operand" "fG")))]
3146   "TARGET_FP && TARGET_FIX && alpha_fptm >= ALPHA_FPTM_SU"
3147   "sqrt%-%/ %R1,%0"
3148   [(set_attr "type" "fsqrt")
3149    (set_attr "trap" "yes")
3150    (set_attr "round_suffix" "normal")
3151    (set_attr "trap_suffix" "u_su_sui")])
3152
3153 (define_insn "sqrtdf2"
3154   [(set (match_operand:DF 0 "register_operand" "=f")
3155         (sqrt:DF (match_operand:DF 1 "reg_or_0_operand" "fG")))]
3156   "TARGET_FP && TARGET_FIX"
3157   "sqrt%-%/ %R1,%0"
3158   [(set_attr "type" "fsqrt")
3159    (set_attr "trap" "yes")
3160    (set_attr "round_suffix" "normal")
3161    (set_attr "trap_suffix" "u_su_sui")])
3162 \f
3163 ;; Next are all the integer comparisons, and conditional moves and branches
3164 ;; and some of the related define_expand's and define_split's.
3165
3166 (define_insn "*setcc_internal"
3167   [(set (match_operand 0 "register_operand" "=r")
3168         (match_operator 1 "alpha_comparison_operator"
3169                            [(match_operand:DI 2 "register_operand" "r")
3170                             (match_operand:DI 3 "reg_or_8bit_operand" "rI")]))]
3171   "GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT
3172    && GET_MODE_SIZE (GET_MODE (operands[0])) <= 8
3173    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
3174   "cmp%C1 %2,%3,%0"
3175   [(set_attr "type" "icmp")])
3176
3177 ;; Yes, we can technically support reg_or_8bit_operand in operand 2,
3178 ;; but that's non-canonical rtl and allowing that causes inefficiencies
3179 ;; from cse on.
3180 (define_insn "*setcc_swapped_internal"
3181   [(set (match_operand 0 "register_operand" "=r")
3182         (match_operator 1 "alpha_swapped_comparison_operator"
3183                            [(match_operand:DI 2 "register_operand" "r")
3184                             (match_operand:DI 3 "reg_or_0_operand" "rJ")]))]
3185   "GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT
3186    && GET_MODE_SIZE (GET_MODE (operands[0])) <= 8
3187    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
3188   "cmp%c1 %r3,%2,%0"
3189   [(set_attr "type" "icmp")])
3190
3191 ;; Use match_operator rather than ne directly so that we can match
3192 ;; multiple integer modes.
3193 (define_insn "*setne_internal"
3194   [(set (match_operand 0 "register_operand" "=r")
3195         (match_operator 1 "signed_comparison_operator"
3196                           [(match_operand:DI 2 "register_operand" "r")
3197                            (const_int 0)]))]
3198   "GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT
3199    && GET_MODE_SIZE (GET_MODE (operands[0])) <= 8
3200    && GET_CODE (operands[1]) == NE
3201    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
3202   "cmpult $31,%2,%0"
3203   [(set_attr "type" "icmp")])
3204
3205 ;; The mode folding trick can't be used with const_int operands, since
3206 ;; reload needs to know the proper mode.
3207 ;;
3208 ;; Use add_operand instead of the more seemingly natural reg_or_8bit_operand
3209 ;; in order to create more pairs of constants.  As long as we're allowing
3210 ;; two constants at the same time, and will have to reload one of them...
3211
3212 (define_insn "*movqicc_internal"
3213   [(set (match_operand:QI 0 "register_operand" "=r,r,r,r")
3214         (if_then_else:QI
3215          (match_operator 2 "signed_comparison_operator"
3216                          [(match_operand:DI 3 "reg_or_0_operand" "rJ,rJ,J,J")
3217                           (match_operand:DI 4 "reg_or_0_operand" "J,J,rJ,rJ")])
3218          (match_operand:QI 1 "add_operand" "rI,0,rI,0")
3219          (match_operand:QI 5 "add_operand" "0,rI,0,rI")))]
3220   "(operands[3] == const0_rtx) ^ (operands[4] == const0_rtx)"
3221   "@
3222    cmov%C2 %r3,%1,%0
3223    cmov%D2 %r3,%5,%0
3224    cmov%c2 %r4,%1,%0
3225    cmov%d2 %r4,%5,%0"
3226   [(set_attr "type" "icmov")])
3227
3228 (define_insn "*movhicc_internal"
3229   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
3230         (if_then_else:HI
3231          (match_operator 2 "signed_comparison_operator"
3232                          [(match_operand:DI 3 "reg_or_0_operand" "rJ,rJ,J,J")
3233                           (match_operand:DI 4 "reg_or_0_operand" "J,J,rJ,rJ")])
3234          (match_operand:HI 1 "add_operand" "rI,0,rI,0")
3235          (match_operand:HI 5 "add_operand" "0,rI,0,rI")))]
3236   "(operands[3] == const0_rtx) ^ (operands[4] == const0_rtx)"
3237   "@
3238    cmov%C2 %r3,%1,%0
3239    cmov%D2 %r3,%5,%0
3240    cmov%c2 %r4,%1,%0
3241    cmov%d2 %r4,%5,%0"
3242   [(set_attr "type" "icmov")])
3243
3244 (define_insn "*movsicc_internal"
3245   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
3246         (if_then_else:SI
3247          (match_operator 2 "signed_comparison_operator"
3248                          [(match_operand:DI 3 "reg_or_0_operand" "rJ,rJ,J,J")
3249                           (match_operand:DI 4 "reg_or_0_operand" "J,J,rJ,rJ")])
3250          (match_operand:SI 1 "add_operand" "rI,0,rI,0")
3251          (match_operand:SI 5 "add_operand" "0,rI,0,rI")))]
3252   "(operands[3] == const0_rtx) ^ (operands[4] == const0_rtx)"
3253   "@
3254    cmov%C2 %r3,%1,%0
3255    cmov%D2 %r3,%5,%0
3256    cmov%c2 %r4,%1,%0
3257    cmov%d2 %r4,%5,%0"
3258   [(set_attr "type" "icmov")])
3259
3260 (define_insn "*movdicc_internal"
3261   [(set (match_operand:DI 0 "register_operand" "=r,r,r,r")
3262         (if_then_else:DI
3263          (match_operator 2 "signed_comparison_operator"
3264                          [(match_operand:DI 3 "reg_or_0_operand" "rJ,rJ,J,J")
3265                           (match_operand:DI 4 "reg_or_0_operand" "J,J,rJ,rJ")])
3266          (match_operand:DI 1 "add_operand" "rI,0,rI,0")
3267          (match_operand:DI 5 "add_operand" "0,rI,0,rI")))]
3268   "(operands[3] == const0_rtx) ^ (operands[4] == const0_rtx)"
3269   "@
3270    cmov%C2 %r3,%1,%0
3271    cmov%D2 %r3,%5,%0
3272    cmov%c2 %r4,%1,%0
3273    cmov%d2 %r4,%5,%0"
3274   [(set_attr "type" "icmov")])
3275
3276 (define_insn "*movqicc_lbc"
3277   [(set (match_operand:QI 0 "register_operand" "=r,r")
3278         (if_then_else:QI
3279          (eq (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3280                               (const_int 1)
3281                               (const_int 0))
3282              (const_int 0))
3283          (match_operand:QI 1 "reg_or_8bit_operand" "rI,0")
3284          (match_operand:QI 3 "reg_or_8bit_operand" "0,rI")))]
3285   ""
3286   "@
3287    cmovlbc %r2,%1,%0
3288    cmovlbs %r2,%3,%0"
3289   [(set_attr "type" "icmov")])
3290
3291 (define_insn "*movhicc_lbc"
3292   [(set (match_operand:HI 0 "register_operand" "=r,r")
3293         (if_then_else:HI
3294          (eq (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3295                               (const_int 1)
3296                               (const_int 0))
3297              (const_int 0))
3298          (match_operand:HI 1 "reg_or_8bit_operand" "rI,0")
3299          (match_operand:HI 3 "reg_or_8bit_operand" "0,rI")))]
3300   ""
3301   "@
3302    cmovlbc %r2,%1,%0
3303    cmovlbs %r2,%3,%0"
3304   [(set_attr "type" "icmov")])
3305
3306 (define_insn "*movsicc_lbc"
3307   [(set (match_operand:SI 0 "register_operand" "=r,r")
3308         (if_then_else:SI
3309          (eq (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3310                               (const_int 1)
3311                               (const_int 0))
3312              (const_int 0))
3313          (match_operand:SI 1 "reg_or_8bit_operand" "rI,0")
3314          (match_operand:SI 3 "reg_or_8bit_operand" "0,rI")))]
3315   ""
3316   "@
3317    cmovlbc %r2,%1,%0
3318    cmovlbs %r2,%3,%0"
3319   [(set_attr "type" "icmov")])
3320
3321 (define_insn "*movdicc_lbc"
3322   [(set (match_operand:DI 0 "register_operand" "=r,r")
3323         (if_then_else:DI
3324          (eq (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3325                               (const_int 1)
3326                               (const_int 0))
3327              (const_int 0))
3328          (match_operand:DI 1 "reg_or_8bit_operand" "rI,0")
3329          (match_operand:DI 3 "reg_or_8bit_operand" "0,rI")))]
3330   ""
3331   "@
3332    cmovlbc %r2,%1,%0
3333    cmovlbs %r2,%3,%0"
3334   [(set_attr "type" "icmov")])
3335
3336 (define_insn "*movqicc_lbs"
3337   [(set (match_operand:QI 0 "register_operand" "=r,r")
3338         (if_then_else:QI
3339          (ne (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3340                               (const_int 1)
3341                               (const_int 0))
3342              (const_int 0))
3343          (match_operand:QI 1 "reg_or_8bit_operand" "rI,0")
3344          (match_operand:QI 3 "reg_or_8bit_operand" "0,rI")))]
3345   ""
3346   "@
3347    cmovlbs %r2,%1,%0
3348    cmovlbc %r2,%3,%0"
3349   [(set_attr "type" "icmov")])
3350
3351 (define_insn "*movhicc_lbs"
3352   [(set (match_operand:HI 0 "register_operand" "=r,r")
3353         (if_then_else:HI
3354          (ne (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3355                               (const_int 1)
3356                               (const_int 0))
3357              (const_int 0))
3358          (match_operand:HI 1 "reg_or_8bit_operand" "rI,0")
3359          (match_operand:HI 3 "reg_or_8bit_operand" "0,rI")))]
3360   ""
3361   "@
3362    cmovlbs %r2,%1,%0
3363    cmovlbc %r2,%3,%0"
3364   [(set_attr "type" "icmov")])
3365
3366 (define_insn "*movsicc_lbs"
3367   [(set (match_operand:SI 0 "register_operand" "=r,r")
3368         (if_then_else:SI
3369          (ne (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3370                               (const_int 1)
3371                               (const_int 0))
3372              (const_int 0))
3373          (match_operand:SI 1 "reg_or_8bit_operand" "rI,0")
3374          (match_operand:SI 3 "reg_or_8bit_operand" "0,rI")))]
3375   ""
3376   "@
3377    cmovlbs %r2,%1,%0
3378    cmovlbc %r2,%3,%0"
3379   [(set_attr "type" "icmov")])
3380
3381 (define_insn "*movdicc_lbs"
3382   [(set (match_operand:DI 0 "register_operand" "=r,r")
3383         (if_then_else:DI
3384          (ne (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3385                               (const_int 1)
3386                               (const_int 0))
3387              (const_int 0))
3388          (match_operand:DI 1 "reg_or_8bit_operand" "rI,0")
3389          (match_operand:DI 3 "reg_or_8bit_operand" "0,rI")))]
3390   ""
3391   "@
3392    cmovlbs %r2,%1,%0
3393    cmovlbc %r2,%3,%0"
3394   [(set_attr "type" "icmov")])
3395
3396 ;; For ABS, we have two choices, depending on whether the input and output
3397 ;; registers are the same or not.
3398 (define_expand "absdi2"
3399   [(set (match_operand:DI 0 "register_operand" "")
3400         (abs:DI (match_operand:DI 1 "register_operand" "")))]
3401   ""
3402 {
3403   if (rtx_equal_p (operands[0], operands[1]))
3404     emit_insn (gen_absdi2_same (operands[0], gen_reg_rtx (DImode)));
3405   else
3406     emit_insn (gen_absdi2_diff (operands[0], operands[1]));
3407   DONE;
3408 })
3409
3410 (define_expand "absdi2_same"
3411   [(set (match_operand:DI 1 "register_operand" "")
3412         (neg:DI (match_operand:DI 0 "register_operand" "")))
3413    (set (match_dup 0)
3414         (if_then_else:DI (ge (match_dup 0) (const_int 0))
3415                          (match_dup 0)
3416                          (match_dup 1)))]
3417   ""
3418   "")
3419
3420 (define_expand "absdi2_diff"
3421   [(set (match_operand:DI 0 "register_operand" "")
3422         (neg:DI (match_operand:DI 1 "register_operand" "")))
3423    (set (match_dup 0)
3424         (if_then_else:DI (lt (match_dup 1) (const_int 0))
3425                          (match_dup 0)
3426                          (match_dup 1)))]
3427   ""
3428   "")
3429
3430 (define_split
3431   [(set (match_operand:DI 0 "register_operand" "")
3432         (abs:DI (match_dup 0)))
3433    (clobber (match_operand:DI 1 "register_operand" ""))]
3434   ""
3435   [(set (match_dup 1) (neg:DI (match_dup 0)))
3436    (set (match_dup 0) (if_then_else:DI (ge (match_dup 0) (const_int 0))
3437                                        (match_dup 0) (match_dup 1)))]
3438   "")
3439
3440 (define_split
3441   [(set (match_operand:DI 0 "register_operand" "")
3442         (abs:DI (match_operand:DI 1 "register_operand" "")))]
3443   "! rtx_equal_p (operands[0], operands[1])"
3444   [(set (match_dup 0) (neg:DI (match_dup 1)))
3445    (set (match_dup 0) (if_then_else:DI (lt (match_dup 1) (const_int 0))
3446                                        (match_dup 0) (match_dup 1)))]
3447   "")
3448
3449 (define_split
3450   [(set (match_operand:DI 0 "register_operand" "")
3451         (neg:DI (abs:DI (match_dup 0))))
3452    (clobber (match_operand:DI 1 "register_operand" ""))]
3453   ""
3454   [(set (match_dup 1) (neg:DI (match_dup 0)))
3455    (set (match_dup 0) (if_then_else:DI (le (match_dup 0) (const_int 0))
3456                                        (match_dup 0) (match_dup 1)))]
3457   "")
3458
3459 (define_split
3460   [(set (match_operand:DI 0 "register_operand" "")
3461         (neg:DI (abs:DI (match_operand:DI 1 "register_operand" ""))))]
3462   "! rtx_equal_p (operands[0], operands[1])"
3463   [(set (match_dup 0) (neg:DI (match_dup 1)))
3464    (set (match_dup 0) (if_then_else:DI (gt (match_dup 1) (const_int 0))
3465                                        (match_dup 0) (match_dup 1)))]
3466   "")
3467
3468 (define_insn "sminqi3"
3469   [(set (match_operand:QI 0 "register_operand" "=r")
3470         (smin:QI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
3471                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
3472   "TARGET_MAX"
3473   "minsb8 %r1,%2,%0"
3474   [(set_attr "type" "mvi")])
3475
3476 (define_insn "uminqi3"
3477   [(set (match_operand:QI 0 "register_operand" "=r")
3478         (umin:QI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
3479                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
3480   "TARGET_MAX"
3481   "minub8 %r1,%2,%0"
3482   [(set_attr "type" "mvi")])
3483
3484 (define_insn "smaxqi3"
3485   [(set (match_operand:QI 0 "register_operand" "=r")
3486         (smax:QI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
3487                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
3488   "TARGET_MAX"
3489   "maxsb8 %r1,%2,%0"
3490   [(set_attr "type" "mvi")])
3491
3492 (define_insn "umaxqi3"
3493   [(set (match_operand:QI 0 "register_operand" "=r")
3494         (umax:QI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
3495                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
3496   "TARGET_MAX"
3497   "maxub8 %r1,%2,%0"
3498   [(set_attr "type" "mvi")])
3499
3500 (define_insn "sminhi3"
3501   [(set (match_operand:HI 0 "register_operand" "=r")
3502         (smin:HI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
3503                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
3504   "TARGET_MAX"
3505   "minsw4 %r1,%2,%0"
3506   [(set_attr "type" "mvi")])
3507
3508 (define_insn "uminhi3"
3509   [(set (match_operand:HI 0 "register_operand" "=r")
3510         (umin:HI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
3511                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
3512   "TARGET_MAX"
3513   "minuw4 %r1,%2,%0"
3514   [(set_attr "type" "mvi")])
3515
3516 (define_insn "smaxhi3"
3517   [(set (match_operand:HI 0 "register_operand" "=r")
3518         (smax:HI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
3519                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
3520   "TARGET_MAX"
3521   "maxsw4 %r1,%2,%0"
3522   [(set_attr "type" "mvi")])
3523
3524 (define_insn "umaxhi3"
3525   [(set (match_operand:HI 0 "register_operand" "=r")
3526         (umax:HI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
3527                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
3528   "TARGET_MAX"
3529   "maxuw4 %r1,%2,%0"
3530   [(set_attr "type" "mvi")])
3531
3532 (define_expand "smaxdi3"
3533   [(set (match_dup 3)
3534         (le:DI (match_operand:DI 1 "reg_or_0_operand" "")
3535                (match_operand:DI 2 "reg_or_8bit_operand" "")))
3536    (set (match_operand:DI 0 "register_operand" "")
3537         (if_then_else:DI (eq (match_dup 3) (const_int 0))
3538                          (match_dup 1) (match_dup 2)))]
3539   ""
3540   { operands[3] = gen_reg_rtx (DImode); })
3541
3542 (define_split
3543   [(set (match_operand:DI 0 "register_operand" "")
3544         (smax:DI (match_operand:DI 1 "reg_or_0_operand" "")
3545                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
3546    (clobber (match_operand:DI 3 "register_operand" ""))]
3547   "operands[2] != const0_rtx"
3548   [(set (match_dup 3) (le:DI (match_dup 1) (match_dup 2)))
3549    (set (match_dup 0) (if_then_else:DI (eq (match_dup 3) (const_int 0))
3550                                        (match_dup 1) (match_dup 2)))]
3551   "")
3552
3553 (define_insn "*smax_const0"
3554   [(set (match_operand:DI 0 "register_operand" "=r")
3555         (smax:DI (match_operand:DI 1 "register_operand" "0")
3556                  (const_int 0)))]
3557   ""
3558   "cmovlt %0,0,%0"
3559   [(set_attr "type" "icmov")])
3560
3561 (define_expand "smindi3"
3562   [(set (match_dup 3)
3563         (lt:DI (match_operand:DI 1 "reg_or_0_operand" "")
3564                (match_operand:DI 2 "reg_or_8bit_operand" "")))
3565    (set (match_operand:DI 0 "register_operand" "")
3566         (if_then_else:DI (ne (match_dup 3) (const_int 0))
3567                          (match_dup 1) (match_dup 2)))]
3568   ""
3569   { operands[3] = gen_reg_rtx (DImode); })
3570
3571 (define_split
3572   [(set (match_operand:DI 0 "register_operand" "")
3573         (smin:DI (match_operand:DI 1 "reg_or_0_operand" "")
3574                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
3575    (clobber (match_operand:DI 3 "register_operand" ""))]
3576   "operands[2] != const0_rtx"
3577   [(set (match_dup 3) (lt:DI (match_dup 1) (match_dup 2)))
3578    (set (match_dup 0) (if_then_else:DI (ne (match_dup 3) (const_int 0))
3579                                        (match_dup 1) (match_dup 2)))]
3580   "")
3581
3582 (define_insn "*smin_const0"
3583   [(set (match_operand:DI 0 "register_operand" "=r")
3584         (smin:DI (match_operand:DI 1 "register_operand" "0")
3585                  (const_int 0)))]
3586   ""
3587   "cmovgt %0,0,%0"
3588   [(set_attr "type" "icmov")])
3589
3590 (define_expand "umaxdi3"
3591   [(set (match_dup 3)
3592         (leu:DI (match_operand:DI 1 "reg_or_0_operand" "")
3593                 (match_operand:DI 2 "reg_or_8bit_operand" "")))
3594    (set (match_operand:DI 0 "register_operand" "")
3595         (if_then_else:DI (eq (match_dup 3) (const_int 0))
3596                          (match_dup 1) (match_dup 2)))]
3597   ""
3598   "operands[3] = gen_reg_rtx (DImode);")
3599
3600 (define_split
3601   [(set (match_operand:DI 0 "register_operand" "")
3602         (umax:DI (match_operand:DI 1 "reg_or_0_operand" "")
3603                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
3604    (clobber (match_operand:DI 3 "register_operand" ""))]
3605   "operands[2] != const0_rtx"
3606   [(set (match_dup 3) (leu:DI (match_dup 1) (match_dup 2)))
3607    (set (match_dup 0) (if_then_else:DI (eq (match_dup 3) (const_int 0))
3608                                        (match_dup 1) (match_dup 2)))]
3609   "")
3610
3611 (define_expand "umindi3"
3612   [(set (match_dup 3)
3613         (ltu:DI (match_operand:DI 1 "reg_or_0_operand" "")
3614                 (match_operand:DI 2 "reg_or_8bit_operand" "")))
3615    (set (match_operand:DI 0 "register_operand" "")
3616         (if_then_else:DI (ne (match_dup 3) (const_int 0))
3617                          (match_dup 1) (match_dup 2)))]
3618   ""
3619   "operands[3] = gen_reg_rtx (DImode);")
3620
3621 (define_split
3622   [(set (match_operand:DI 0 "register_operand" "")
3623         (umin:DI (match_operand:DI 1 "reg_or_0_operand" "")
3624                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
3625    (clobber (match_operand:DI 3 "register_operand" ""))]
3626   "operands[2] != const0_rtx"
3627   [(set (match_dup 3) (ltu:DI (match_dup 1) (match_dup 2)))
3628    (set (match_dup 0) (if_then_else:DI (ne (match_dup 3) (const_int 0))
3629                                        (match_dup 1) (match_dup 2)))]
3630   "")
3631
3632 (define_insn "*bcc_normal"
3633   [(set (pc)
3634         (if_then_else
3635          (match_operator 1 "signed_comparison_operator"
3636                          [(match_operand:DI 2 "reg_or_0_operand" "rJ")
3637                           (const_int 0)])
3638          (label_ref (match_operand 0 "" ""))
3639          (pc)))]
3640   ""
3641   "b%C1 %r2,%0"
3642   [(set_attr "type" "ibr")])
3643
3644 (define_insn "*bcc_reverse"
3645   [(set (pc)
3646         (if_then_else
3647          (match_operator 1 "signed_comparison_operator"
3648                          [(match_operand:DI 2 "register_operand" "r")
3649                           (const_int 0)])
3650
3651          (pc)
3652          (label_ref (match_operand 0 "" ""))))]
3653   ""
3654   "b%c1 %2,%0"
3655   [(set_attr "type" "ibr")])
3656
3657 (define_insn "*blbs_normal"
3658   [(set (pc)
3659         (if_then_else
3660          (ne (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
3661                               (const_int 1)
3662                               (const_int 0))
3663              (const_int 0))
3664          (label_ref (match_operand 0 "" ""))
3665          (pc)))]
3666   ""
3667   "blbs %r1,%0"
3668   [(set_attr "type" "ibr")])
3669
3670 (define_insn "*blbc_normal"
3671   [(set (pc)
3672         (if_then_else
3673          (eq (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
3674                               (const_int 1)
3675                               (const_int 0))
3676              (const_int 0))
3677          (label_ref (match_operand 0 "" ""))
3678          (pc)))]
3679   ""
3680   "blbc %r1,%0"
3681   [(set_attr "type" "ibr")])
3682
3683 (define_split
3684   [(parallel
3685     [(set (pc)
3686           (if_then_else
3687            (match_operator 1 "comparison_operator"
3688                            [(zero_extract:DI (match_operand:DI 2 "register_operand" "")
3689                                              (const_int 1)
3690                                              (match_operand:DI 3 "const_int_operand" ""))
3691                             (const_int 0)])
3692            (label_ref (match_operand 0 "" ""))
3693            (pc)))
3694      (clobber (match_operand:DI 4 "register_operand" ""))])]
3695   "INTVAL (operands[3]) != 0"
3696   [(set (match_dup 4)
3697         (lshiftrt:DI (match_dup 2) (match_dup 3)))
3698    (set (pc)
3699         (if_then_else (match_op_dup 1
3700                                     [(zero_extract:DI (match_dup 4)
3701                                                       (const_int 1)
3702                                                       (const_int 0))
3703                                      (const_int 0)])
3704                       (label_ref (match_dup 0))
3705                       (pc)))]
3706   "")
3707 \f
3708 ;; The following are the corresponding floating-point insns.  Recall
3709 ;; we need to have variants that expand the arguments from SFmode
3710 ;; to DFmode.
3711
3712 (define_insn "*cmpdf_ieee"
3713   [(set (match_operand:DF 0 "register_operand" "=&f")
3714         (match_operator:DF 1 "alpha_fp_comparison_operator"
3715                            [(match_operand:DF 2 "reg_or_0_operand" "fG")
3716                             (match_operand:DF 3 "reg_or_0_operand" "fG")]))]
3717   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
3718   "cmp%-%C1%/ %R2,%R3,%0"
3719   [(set_attr "type" "fadd")
3720    (set_attr "trap" "yes")
3721    (set_attr "trap_suffix" "su")])
3722
3723 (define_insn "*cmpdf_internal"
3724   [(set (match_operand:DF 0 "register_operand" "=f")
3725         (match_operator:DF 1 "alpha_fp_comparison_operator"
3726                            [(match_operand:DF 2 "reg_or_0_operand" "fG")
3727                             (match_operand:DF 3 "reg_or_0_operand" "fG")]))]
3728   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3729   "cmp%-%C1%/ %R2,%R3,%0"
3730   [(set_attr "type" "fadd")
3731    (set_attr "trap" "yes")
3732    (set_attr "trap_suffix" "su")])
3733
3734 (define_insn "*cmpdf_ieee_ext1"
3735   [(set (match_operand:DF 0 "register_operand" "=&f")
3736         (match_operator:DF 1 "alpha_fp_comparison_operator"
3737                            [(float_extend:DF
3738                              (match_operand:SF 2 "reg_or_0_operand" "fG"))
3739                             (match_operand:DF 3 "reg_or_0_operand" "fG")]))]
3740   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
3741   "cmp%-%C1%/ %R2,%R3,%0"
3742   [(set_attr "type" "fadd")
3743    (set_attr "trap" "yes")
3744    (set_attr "trap_suffix" "su")])
3745
3746 (define_insn "*cmpdf_ext1"
3747   [(set (match_operand:DF 0 "register_operand" "=f")
3748         (match_operator:DF 1 "alpha_fp_comparison_operator"
3749                            [(float_extend:DF
3750                              (match_operand:SF 2 "reg_or_0_operand" "fG"))
3751                             (match_operand:DF 3 "reg_or_0_operand" "fG")]))]
3752   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3753   "cmp%-%C1%/ %R2,%R3,%0"
3754   [(set_attr "type" "fadd")
3755    (set_attr "trap" "yes")
3756    (set_attr "trap_suffix" "su")])
3757
3758 (define_insn "*cmpdf_ieee_ext2"
3759   [(set (match_operand:DF 0 "register_operand" "=&f")
3760         (match_operator:DF 1 "alpha_fp_comparison_operator"
3761                            [(match_operand:DF 2 "reg_or_0_operand" "fG")
3762                             (float_extend:DF
3763                              (match_operand:SF 3 "reg_or_0_operand" "fG"))]))]
3764   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
3765   "cmp%-%C1%/ %R2,%R3,%0"
3766   [(set_attr "type" "fadd")
3767    (set_attr "trap" "yes")
3768    (set_attr "trap_suffix" "su")])
3769
3770 (define_insn "*cmpdf_ext2"
3771   [(set (match_operand:DF 0 "register_operand" "=f")
3772         (match_operator:DF 1 "alpha_fp_comparison_operator"
3773                            [(match_operand:DF 2 "reg_or_0_operand" "fG")
3774                             (float_extend:DF
3775                              (match_operand:SF 3 "reg_or_0_operand" "fG"))]))]
3776   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3777   "cmp%-%C1%/ %R2,%R3,%0"
3778   [(set_attr "type" "fadd")
3779    (set_attr "trap" "yes")
3780    (set_attr "trap_suffix" "su")])
3781
3782 (define_insn "*cmpdf_ieee_ext3"
3783   [(set (match_operand:DF 0 "register_operand" "=&f")
3784         (match_operator:DF 1 "alpha_fp_comparison_operator"
3785                            [(float_extend:DF
3786                              (match_operand:SF 2 "reg_or_0_operand" "fG"))
3787                             (float_extend:DF
3788                              (match_operand:SF 3 "reg_or_0_operand" "fG"))]))]
3789   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
3790   "cmp%-%C1%/ %R2,%R3,%0"
3791   [(set_attr "type" "fadd")
3792    (set_attr "trap" "yes")
3793    (set_attr "trap_suffix" "su")])
3794
3795 (define_insn "*cmpdf_ext3"
3796   [(set (match_operand:DF 0 "register_operand" "=f")
3797         (match_operator:DF 1 "alpha_fp_comparison_operator"
3798                            [(float_extend:DF
3799                              (match_operand:SF 2 "reg_or_0_operand" "fG"))
3800                             (float_extend:DF
3801                              (match_operand:SF 3 "reg_or_0_operand" "fG"))]))]
3802   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3803   "cmp%-%C1%/ %R2,%R3,%0"
3804   [(set_attr "type" "fadd")
3805    (set_attr "trap" "yes")
3806    (set_attr "trap_suffix" "su")])
3807
3808 (define_insn "*movdfcc_internal"
3809   [(set (match_operand:DF 0 "register_operand" "=f,f")
3810         (if_then_else:DF
3811          (match_operator 3 "signed_comparison_operator"
3812                          [(match_operand:DF 4 "reg_or_0_operand" "fG,fG")
3813                           (match_operand:DF 2 "const0_operand" "G,G")])
3814          (match_operand:DF 1 "reg_or_0_operand" "fG,0")
3815          (match_operand:DF 5 "reg_or_0_operand" "0,fG")))]
3816   "TARGET_FP"
3817   "@
3818    fcmov%C3 %R4,%R1,%0
3819    fcmov%D3 %R4,%R5,%0"
3820   [(set_attr "type" "fcmov")])
3821
3822 (define_insn "*movsfcc_internal"
3823   [(set (match_operand:SF 0 "register_operand" "=f,f")
3824         (if_then_else:SF
3825          (match_operator 3 "signed_comparison_operator"
3826                          [(match_operand:DF 4 "reg_or_0_operand" "fG,fG")
3827                           (match_operand:DF 2 "const0_operand" "G,G")])
3828          (match_operand:SF 1 "reg_or_0_operand" "fG,0")
3829          (match_operand:SF 5 "reg_or_0_operand" "0,fG")))]
3830   "TARGET_FP"
3831   "@
3832    fcmov%C3 %R4,%R1,%0
3833    fcmov%D3 %R4,%R5,%0"
3834   [(set_attr "type" "fcmov")])
3835
3836 (define_insn "*movdfcc_ext1"
3837   [(set (match_operand:DF 0 "register_operand" "=f,f")
3838         (if_then_else:DF
3839          (match_operator 3 "signed_comparison_operator"
3840                          [(match_operand:DF 4 "reg_or_0_operand" "fG,fG")
3841                           (match_operand:DF 2 "const0_operand" "G,G")])
3842          (float_extend:DF (match_operand:SF 1 "reg_or_0_operand" "fG,0"))
3843          (match_operand:DF 5 "reg_or_0_operand" "0,fG")))]
3844   "TARGET_FP"
3845   "@
3846    fcmov%C3 %R4,%R1,%0
3847    fcmov%D3 %R4,%R5,%0"
3848   [(set_attr "type" "fcmov")])
3849
3850 (define_insn "*movdfcc_ext2"
3851   [(set (match_operand:DF 0 "register_operand" "=f,f")
3852         (if_then_else:DF
3853          (match_operator 3 "signed_comparison_operator"
3854                          [(float_extend:DF
3855                            (match_operand:SF 4 "reg_or_0_operand" "fG,fG"))
3856                           (match_operand:DF 2 "const0_operand" "G,G")])
3857          (match_operand:DF 1 "reg_or_0_operand" "fG,0")
3858          (match_operand:DF 5 "reg_or_0_operand" "0,fG")))]
3859   "TARGET_FP"
3860   "@
3861    fcmov%C3 %R4,%R1,%0
3862    fcmov%D3 %R4,%R5,%0"
3863   [(set_attr "type" "fcmov")])
3864
3865 (define_insn "*movdfcc_ext3"
3866   [(set (match_operand:SF 0 "register_operand" "=f,f")
3867         (if_then_else:SF
3868          (match_operator 3 "signed_comparison_operator"
3869                          [(float_extend:DF
3870                            (match_operand:SF 4 "reg_or_0_operand" "fG,fG"))
3871                           (match_operand:DF 2 "const0_operand" "G,G")])
3872          (match_operand:SF 1 "reg_or_0_operand" "fG,0")
3873          (match_operand:SF 5 "reg_or_0_operand" "0,fG")))]
3874   "TARGET_FP"
3875   "@
3876    fcmov%C3 %R4,%R1,%0
3877    fcmov%D3 %R4,%R5,%0"
3878   [(set_attr "type" "fcmov")])
3879
3880 (define_insn "*movdfcc_ext4"
3881   [(set (match_operand:DF 0 "register_operand" "=f,f")
3882         (if_then_else:DF
3883          (match_operator 3 "signed_comparison_operator"
3884                          [(float_extend:DF
3885                            (match_operand:SF 4 "reg_or_0_operand" "fG,fG"))
3886                           (match_operand:DF 2 "const0_operand" "G,G")])
3887          (float_extend:DF (match_operand:SF 1 "reg_or_0_operand" "fG,0"))
3888          (match_operand:DF 5 "reg_or_0_operand" "0,fG")))]
3889   "TARGET_FP"
3890   "@
3891    fcmov%C3 %R4,%R1,%0
3892    fcmov%D3 %R4,%R5,%0"
3893   [(set_attr "type" "fcmov")])
3894
3895 (define_expand "smaxdf3"
3896   [(set (match_dup 3)
3897         (le:DF (match_operand:DF 1 "reg_or_0_operand" "")
3898                (match_operand:DF 2 "reg_or_0_operand" "")))
3899    (set (match_operand:DF 0 "register_operand" "")
3900         (if_then_else:DF (eq (match_dup 3) (match_dup 4))
3901                          (match_dup 1) (match_dup 2)))]
3902   "TARGET_FP"
3903 {
3904   operands[3] = gen_reg_rtx (DFmode);
3905   operands[4] = CONST0_RTX (DFmode);
3906 })
3907
3908 (define_expand "smindf3"
3909   [(set (match_dup 3)
3910         (lt:DF (match_operand:DF 1 "reg_or_0_operand" "")
3911                (match_operand:DF 2 "reg_or_0_operand" "")))
3912    (set (match_operand:DF 0 "register_operand" "")
3913         (if_then_else:DF (ne (match_dup 3) (match_dup 4))
3914                          (match_dup 1) (match_dup 2)))]
3915   "TARGET_FP"
3916 {
3917   operands[3] = gen_reg_rtx (DFmode);
3918   operands[4] = CONST0_RTX (DFmode);
3919 })
3920
3921 (define_expand "smaxsf3"
3922   [(set (match_dup 3)
3923         (le:DF (float_extend:DF (match_operand:SF 1 "reg_or_0_operand" ""))
3924                (float_extend:DF (match_operand:SF 2 "reg_or_0_operand" ""))))
3925    (set (match_operand:SF 0 "register_operand" "")
3926         (if_then_else:SF (eq (match_dup 3) (match_dup 4))
3927                          (match_dup 1) (match_dup 2)))]
3928   "TARGET_FP"
3929 {
3930   operands[3] = gen_reg_rtx (DFmode);
3931   operands[4] = CONST0_RTX (DFmode);
3932 })
3933
3934 (define_expand "sminsf3"
3935   [(set (match_dup 3)
3936         (lt:DF (float_extend:DF (match_operand:SF 1 "reg_or_0_operand" ""))
3937                (float_extend:DF (match_operand:SF 2 "reg_or_0_operand" ""))))
3938    (set (match_operand:SF 0 "register_operand" "")
3939         (if_then_else:SF (ne (match_dup 3) (match_dup 4))
3940                       (match_dup 1) (match_dup 2)))]
3941   "TARGET_FP"
3942 {
3943   operands[3] = gen_reg_rtx (DFmode);
3944   operands[4] = CONST0_RTX (DFmode);
3945 })
3946
3947 (define_insn "*fbcc_normal"
3948   [(set (pc)
3949         (if_then_else
3950          (match_operator 1 "signed_comparison_operator"
3951                          [(match_operand:DF 2 "reg_or_0_operand" "fG")
3952                           (match_operand:DF 3 "const0_operand" "G")])
3953          (label_ref (match_operand 0 "" ""))
3954          (pc)))]
3955   "TARGET_FP"
3956   "fb%C1 %R2,%0"
3957   [(set_attr "type" "fbr")])
3958
3959 (define_insn "*fbcc_ext_normal"
3960   [(set (pc)
3961         (if_then_else
3962          (match_operator 1 "signed_comparison_operator"
3963                          [(float_extend:DF
3964                            (match_operand:SF 2 "reg_or_0_operand" "fG"))
3965                           (match_operand:DF 3 "const0_operand" "G")])
3966          (label_ref (match_operand 0 "" ""))
3967          (pc)))]
3968   "TARGET_FP"
3969   "fb%C1 %R2,%0"
3970   [(set_attr "type" "fbr")])
3971 \f
3972 ;; These are the main define_expand's used to make conditional branches
3973 ;; and compares.
3974
3975 (define_expand "cmpdf"
3976   [(set (cc0) (compare (match_operand:DF 0 "reg_or_0_operand" "")
3977                        (match_operand:DF 1 "reg_or_0_operand" "")))]
3978   "TARGET_FP"
3979 {
3980   alpha_compare.op0 = operands[0];
3981   alpha_compare.op1 = operands[1];
3982   alpha_compare.fp_p = 1;
3983   DONE;
3984 })
3985
3986 (define_expand "cmptf"
3987   [(set (cc0) (compare (match_operand:TF 0 "general_operand" "")
3988                        (match_operand:TF 1 "general_operand" "")))]
3989   "TARGET_HAS_XFLOATING_LIBS"
3990 {
3991   alpha_compare.op0 = operands[0];
3992   alpha_compare.op1 = operands[1];
3993   alpha_compare.fp_p = 1;
3994   DONE;
3995 })
3996
3997 (define_expand "cmpdi"
3998   [(set (cc0) (compare (match_operand:DI 0 "some_operand" "")
3999                        (match_operand:DI 1 "some_operand" "")))]
4000   ""
4001 {
4002   alpha_compare.op0 = operands[0];
4003   alpha_compare.op1 = operands[1];
4004   alpha_compare.fp_p = 0;
4005   DONE;
4006 })
4007
4008 (define_expand "beq"
4009   [(set (pc)
4010         (if_then_else (match_dup 1)
4011                       (label_ref (match_operand 0 "" ""))
4012                       (pc)))]
4013   ""
4014   "{ operands[1] = alpha_emit_conditional_branch (EQ); }")
4015
4016 (define_expand "bne"
4017   [(set (pc)
4018         (if_then_else (match_dup 1)
4019                       (label_ref (match_operand 0 "" ""))
4020                       (pc)))]
4021   ""
4022   "{ operands[1] = alpha_emit_conditional_branch (NE); }")
4023
4024 (define_expand "blt"
4025   [(set (pc)
4026         (if_then_else (match_dup 1)
4027                       (label_ref (match_operand 0 "" ""))
4028                       (pc)))]
4029   ""
4030   "{ operands[1] = alpha_emit_conditional_branch (LT); }")
4031
4032 (define_expand "ble"
4033   [(set (pc)
4034         (if_then_else (match_dup 1)
4035                       (label_ref (match_operand 0 "" ""))
4036                       (pc)))]
4037   ""
4038   "{ operands[1] = alpha_emit_conditional_branch (LE); }")
4039
4040 (define_expand "bgt"
4041   [(set (pc)
4042         (if_then_else (match_dup 1)
4043                       (label_ref (match_operand 0 "" ""))
4044                       (pc)))]
4045   ""
4046   "{ operands[1] = alpha_emit_conditional_branch (GT); }")
4047
4048 (define_expand "bge"
4049   [(set (pc)
4050         (if_then_else (match_dup 1)
4051                       (label_ref (match_operand 0 "" ""))
4052                       (pc)))]
4053   ""
4054   "{ operands[1] = alpha_emit_conditional_branch (GE); }")
4055
4056 (define_expand "bltu"
4057   [(set (pc)
4058         (if_then_else (match_dup 1)
4059                       (label_ref (match_operand 0 "" ""))
4060                       (pc)))]
4061   ""
4062   "{ operands[1] = alpha_emit_conditional_branch (LTU); }")
4063
4064 (define_expand "bleu"
4065   [(set (pc)
4066         (if_then_else (match_dup 1)
4067                       (label_ref (match_operand 0 "" ""))
4068                       (pc)))]
4069   ""
4070   "{ operands[1] = alpha_emit_conditional_branch (LEU); }")
4071
4072 (define_expand "bgtu"
4073   [(set (pc)
4074         (if_then_else (match_dup 1)
4075                       (label_ref (match_operand 0 "" ""))
4076                       (pc)))]
4077   ""
4078   "{ operands[1] = alpha_emit_conditional_branch (GTU); }")
4079
4080 (define_expand "bgeu"
4081   [(set (pc)
4082         (if_then_else (match_dup 1)
4083                       (label_ref (match_operand 0 "" ""))
4084                       (pc)))]
4085   ""
4086   "{ operands[1] = alpha_emit_conditional_branch (GEU); }")
4087
4088 (define_expand "bunordered"
4089   [(set (pc)
4090         (if_then_else (match_dup 1)
4091                       (label_ref (match_operand 0 "" ""))
4092                       (pc)))]
4093   ""
4094   "{ operands[1] = alpha_emit_conditional_branch (UNORDERED); }")
4095
4096 (define_expand "bordered"
4097   [(set (pc)
4098         (if_then_else (match_dup 1)
4099                       (label_ref (match_operand 0 "" ""))
4100                       (pc)))]
4101   ""
4102   "{ operands[1] = alpha_emit_conditional_branch (ORDERED); }")
4103
4104 (define_expand "seq"
4105   [(set (match_operand:DI 0 "register_operand" "")
4106         (match_dup 1))]
4107   ""
4108   "{ if ((operands[1] = alpha_emit_setcc (EQ)) == NULL_RTX) FAIL; }")
4109
4110 (define_expand "sne"
4111   [(set (match_operand:DI 0 "register_operand" "")
4112         (match_dup 1))]
4113   ""
4114   "{ if ((operands[1] = alpha_emit_setcc (NE)) == NULL_RTX) FAIL; }")
4115
4116 (define_expand "slt"
4117   [(set (match_operand:DI 0 "register_operand" "")
4118         (match_dup 1))]
4119   ""
4120   "{ if ((operands[1] = alpha_emit_setcc (LT)) == NULL_RTX) FAIL; }")
4121
4122 (define_expand "sle"
4123   [(set (match_operand:DI 0 "register_operand" "")
4124         (match_dup 1))]
4125   ""
4126   "{ if ((operands[1] = alpha_emit_setcc (LE)) == NULL_RTX) FAIL; }")
4127
4128 (define_expand "sgt"
4129   [(set (match_operand:DI 0 "register_operand" "")
4130         (match_dup 1))]
4131   ""
4132   "{ if ((operands[1] = alpha_emit_setcc (GT)) == NULL_RTX) FAIL; }")
4133
4134 (define_expand "sge"
4135   [(set (match_operand:DI 0 "register_operand" "")
4136         (match_dup 1))]
4137   ""
4138   "{ if ((operands[1] = alpha_emit_setcc (GE)) == NULL_RTX) FAIL; }")
4139
4140 (define_expand "sltu"
4141   [(set (match_operand:DI 0 "register_operand" "")
4142         (match_dup 1))]
4143   ""
4144   "{ if ((operands[1] = alpha_emit_setcc (LTU)) == NULL_RTX) FAIL; }")
4145
4146 (define_expand "sleu"
4147   [(set (match_operand:DI 0 "register_operand" "")
4148         (match_dup 1))]
4149   ""
4150   "{ if ((operands[1] = alpha_emit_setcc (LEU)) == NULL_RTX) FAIL; }")
4151
4152 (define_expand "sgtu"
4153   [(set (match_operand:DI 0 "register_operand" "")
4154         (match_dup 1))]
4155   ""
4156   "{ if ((operands[1] = alpha_emit_setcc (GTU)) == NULL_RTX) FAIL; }")
4157
4158 (define_expand "sgeu"
4159   [(set (match_operand:DI 0 "register_operand" "")
4160         (match_dup 1))]
4161   ""
4162   "{ if ((operands[1] = alpha_emit_setcc (GEU)) == NULL_RTX) FAIL; }")
4163
4164 (define_expand "sunordered"
4165   [(set (match_operand:DI 0 "register_operand" "")
4166         (match_dup 1))]
4167   ""
4168   "{ if ((operands[1] = alpha_emit_setcc (UNORDERED)) == NULL_RTX) FAIL; }")
4169
4170 (define_expand "sordered"
4171   [(set (match_operand:DI 0 "register_operand" "")
4172         (match_dup 1))]
4173   ""
4174   "{ if ((operands[1] = alpha_emit_setcc (ORDERED)) == NULL_RTX) FAIL; }")
4175 \f
4176 ;; These are the main define_expand's used to make conditional moves.
4177
4178 (define_expand "movsicc"
4179   [(set (match_operand:SI 0 "register_operand" "")
4180         (if_then_else:SI (match_operand 1 "comparison_operator" "")
4181                          (match_operand:SI 2 "reg_or_8bit_operand" "")
4182                          (match_operand:SI 3 "reg_or_8bit_operand" "")))]
4183   ""
4184 {
4185   if ((operands[1] = alpha_emit_conditional_move (operands[1], SImode)) == 0)
4186     FAIL;
4187 })
4188
4189 (define_expand "movdicc"
4190   [(set (match_operand:DI 0 "register_operand" "")
4191         (if_then_else:DI (match_operand 1 "comparison_operator" "")
4192                          (match_operand:DI 2 "reg_or_8bit_operand" "")
4193                          (match_operand:DI 3 "reg_or_8bit_operand" "")))]
4194   ""
4195 {
4196   if ((operands[1] = alpha_emit_conditional_move (operands[1], DImode)) == 0)
4197     FAIL;
4198 })
4199
4200 (define_expand "movsfcc"
4201   [(set (match_operand:SF 0 "register_operand" "")
4202         (if_then_else:SF (match_operand 1 "comparison_operator" "")
4203                          (match_operand:SF 2 "reg_or_8bit_operand" "")
4204                          (match_operand:SF 3 "reg_or_8bit_operand" "")))]
4205   ""
4206 {
4207   if ((operands[1] = alpha_emit_conditional_move (operands[1], SFmode)) == 0)
4208     FAIL;
4209 })
4210
4211 (define_expand "movdfcc"
4212   [(set (match_operand:DF 0 "register_operand" "")
4213         (if_then_else:DF (match_operand 1 "comparison_operator" "")
4214                          (match_operand:DF 2 "reg_or_8bit_operand" "")
4215                          (match_operand:DF 3 "reg_or_8bit_operand" "")))]
4216   ""
4217 {
4218   if ((operands[1] = alpha_emit_conditional_move (operands[1], DFmode)) == 0)
4219     FAIL;
4220 })
4221 \f
4222 ;; These define_split definitions are used in cases when comparisons have
4223 ;; not be stated in the correct way and we need to reverse the second
4224 ;; comparison.  For example, x >= 7 has to be done as x < 6 with the
4225 ;; comparison that tests the result being reversed.  We have one define_split
4226 ;; for each use of a comparison.  They do not match valid insns and need
4227 ;; not generate valid insns.
4228 ;;
4229 ;; We can also handle equality comparisons (and inequality comparisons in
4230 ;; cases where the resulting add cannot overflow) by doing an add followed by
4231 ;; a comparison with zero.  This is faster since the addition takes one
4232 ;; less cycle than a compare when feeding into a conditional move.
4233 ;; For this case, we also have an SImode pattern since we can merge the add
4234 ;; and sign extend and the order doesn't matter.
4235 ;;
4236 ;; We do not do this for floating-point, since it isn't clear how the "wrong"
4237 ;; operation could have been generated.
4238
4239 (define_split
4240   [(set (match_operand:DI 0 "register_operand" "")
4241         (if_then_else:DI
4242          (match_operator 1 "comparison_operator"
4243                          [(match_operand:DI 2 "reg_or_0_operand" "")
4244                           (match_operand:DI 3 "reg_or_cint_operand" "")])
4245          (match_operand:DI 4 "reg_or_cint_operand" "")
4246          (match_operand:DI 5 "reg_or_cint_operand" "")))
4247    (clobber (match_operand:DI 6 "register_operand" ""))]
4248   "operands[3] != const0_rtx"
4249   [(set (match_dup 6) (match_dup 7))
4250    (set (match_dup 0)
4251         (if_then_else:DI (match_dup 8) (match_dup 4) (match_dup 5)))]
4252 {
4253   enum rtx_code code = GET_CODE (operands[1]);
4254   int unsignedp = (code == GEU || code == LEU || code == GTU || code == LTU);
4255
4256   /* If we are comparing for equality with a constant and that constant
4257      appears in the arm when the register equals the constant, use the
4258      register since that is more likely to match (and to produce better code
4259      if both would).  */
4260
4261   if (code == EQ && GET_CODE (operands[3]) == CONST_INT
4262       && rtx_equal_p (operands[4], operands[3]))
4263     operands[4] = operands[2];
4264
4265   else if (code == NE && GET_CODE (operands[3]) == CONST_INT
4266            && rtx_equal_p (operands[5], operands[3]))
4267     operands[5] = operands[2];
4268
4269   if (code == NE || code == EQ
4270       || (extended_count (operands[2], DImode, unsignedp) >= 1
4271           && extended_count (operands[3], DImode, unsignedp) >= 1))
4272     {
4273       if (GET_CODE (operands[3]) == CONST_INT)
4274         operands[7] = gen_rtx_PLUS (DImode, operands[2],
4275                                     GEN_INT (- INTVAL (operands[3])));
4276       else
4277         operands[7] = gen_rtx_MINUS (DImode, operands[2], operands[3]);
4278
4279       operands[8] = gen_rtx_fmt_ee (code, VOIDmode, operands[6], const0_rtx);
4280     }
4281
4282   else if (code == EQ || code == LE || code == LT
4283            || code == LEU || code == LTU)
4284     {
4285       operands[7] = gen_rtx_fmt_ee (code, DImode, operands[2], operands[3]);
4286       operands[8] = gen_rtx_NE (VOIDmode, operands[6], const0_rtx);
4287     }
4288   else
4289     {
4290       operands[7] = gen_rtx_fmt_ee (reverse_condition (code), DImode,
4291                                     operands[2], operands[3]);
4292       operands[8] = gen_rtx_EQ (VOIDmode, operands[6], const0_rtx);
4293     }
4294 })
4295
4296 (define_split
4297   [(set (match_operand:DI 0 "register_operand" "")
4298         (if_then_else:DI
4299          (match_operator 1 "comparison_operator"
4300                          [(match_operand:SI 2 "reg_or_0_operand" "")
4301                           (match_operand:SI 3 "reg_or_cint_operand" "")])
4302          (match_operand:DI 4 "reg_or_8bit_operand" "")
4303          (match_operand:DI 5 "reg_or_8bit_operand" "")))
4304    (clobber (match_operand:DI 6 "register_operand" ""))]
4305   "operands[3] != const0_rtx
4306    && (GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)"
4307   [(set (match_dup 6) (match_dup 7))
4308    (set (match_dup 0)
4309         (if_then_else:DI (match_dup 8) (match_dup 4) (match_dup 5)))]
4310 {
4311   enum rtx_code code = GET_CODE (operands[1]);
4312   int unsignedp = (code == GEU || code == LEU || code == GTU || code == LTU);
4313   rtx tem;
4314
4315   if ((code != NE && code != EQ
4316        && ! (extended_count (operands[2], DImode, unsignedp) >= 1
4317              && extended_count (operands[3], DImode, unsignedp) >= 1)))
4318     FAIL;
4319
4320   if (GET_CODE (operands[3]) == CONST_INT)
4321     tem = gen_rtx_PLUS (SImode, operands[2],
4322                         GEN_INT (- INTVAL (operands[3])));
4323   else
4324     tem = gen_rtx_MINUS (SImode, operands[2], operands[3]);
4325
4326   operands[7] = gen_rtx_SIGN_EXTEND (DImode, tem);
4327   operands[8] = gen_rtx_fmt_ee (GET_CODE (operands[1]), VOIDmode,
4328                                 operands[6], const0_rtx);
4329 })
4330
4331 ;; Prefer to use cmp and arithmetic when possible instead of a cmove.
4332
4333 (define_split
4334   [(set (match_operand 0 "register_operand" "")
4335         (if_then_else (match_operator 1 "signed_comparison_operator"
4336                            [(match_operand:DI 2 "reg_or_0_operand" "")
4337                             (const_int 0)])
4338           (match_operand 3 "const_int_operand" "")
4339           (match_operand 4 "const_int_operand" "")))]
4340   ""
4341   [(const_int 0)]
4342 {
4343   if (alpha_split_conditional_move (GET_CODE (operands[1]), operands[0],
4344                                     operands[2], operands[3], operands[4]))
4345     DONE;
4346   else
4347     FAIL;
4348 })
4349
4350 ;; ??? Why combine is allowed to create such non-canonical rtl, I don't know.
4351 ;; Oh well, we match it in movcc, so it must be partially our fault.
4352 (define_split
4353   [(set (match_operand 0 "register_operand" "")
4354         (if_then_else (match_operator 1 "signed_comparison_operator"
4355                            [(const_int 0)
4356                             (match_operand:DI 2 "reg_or_0_operand" "")])
4357           (match_operand 3 "const_int_operand" "")
4358           (match_operand 4 "const_int_operand" "")))]
4359   ""
4360   [(const_int 0)]
4361 {
4362   if (alpha_split_conditional_move (swap_condition (GET_CODE (operands[1])),
4363                                     operands[0], operands[2], operands[3],
4364                                     operands[4]))
4365     DONE;
4366   else
4367     FAIL;
4368 })
4369
4370 (define_insn_and_split "*cmp_sadd_di"
4371   [(set (match_operand:DI 0 "register_operand" "=r")
4372         (plus:DI (if_then_else:DI
4373                    (match_operator 1 "alpha_zero_comparison_operator"
4374                      [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4375                       (const_int 0)])
4376                    (match_operand:DI 3 "const48_operand" "I")
4377                    (const_int 0))
4378                  (match_operand:DI 4 "sext_add_operand" "rIO")))
4379    (clobber (match_scratch:DI 5 "=r"))]
4380   ""
4381   "#"
4382   "! no_new_pseudos || reload_completed"
4383   [(set (match_dup 5)
4384         (match_op_dup:DI 1 [(match_dup 2) (const_int 0)]))
4385    (set (match_dup 0)
4386         (plus:DI (mult:DI (match_dup 5) (match_dup 3))
4387                  (match_dup 4)))]
4388 {
4389   if (! no_new_pseudos)
4390     operands[5] = gen_reg_rtx (DImode);
4391   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4392     operands[5] = operands[0];
4393 })
4394
4395 (define_insn_and_split "*cmp_sadd_si"
4396   [(set (match_operand:SI 0 "register_operand" "=r")
4397         (plus:SI (if_then_else:SI
4398                    (match_operator 1 "alpha_zero_comparison_operator"
4399                      [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4400                       (const_int 0)])
4401                    (match_operand:SI 3 "const48_operand" "I")
4402                    (const_int 0))
4403                  (match_operand:SI 4 "sext_add_operand" "rIO")))
4404    (clobber (match_scratch:SI 5 "=r"))]
4405   ""
4406   "#"
4407   "! no_new_pseudos || reload_completed"
4408   [(set (match_dup 5)
4409         (match_op_dup:SI 1 [(match_dup 2) (const_int 0)]))
4410    (set (match_dup 0)
4411         (plus:SI (mult:SI (match_dup 5) (match_dup 3))
4412                  (match_dup 4)))]
4413 {
4414   if (! no_new_pseudos)
4415     operands[5] = gen_reg_rtx (DImode);
4416   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4417     operands[5] = operands[0];
4418 })
4419
4420 (define_insn_and_split "*cmp_sadd_sidi"
4421   [(set (match_operand:DI 0 "register_operand" "=r")
4422         (sign_extend:DI
4423           (plus:SI (if_then_else:SI
4424                      (match_operator 1 "alpha_zero_comparison_operator"
4425                        [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4426                         (const_int 0)])
4427                      (match_operand:SI 3 "const48_operand" "I")
4428                      (const_int 0))
4429                    (match_operand:SI 4 "sext_add_operand" "rIO"))))
4430    (clobber (match_scratch:SI 5 "=r"))]
4431   ""
4432   "#"
4433   "! no_new_pseudos || reload_completed"
4434   [(set (match_dup 5)
4435         (match_op_dup:SI 1 [(match_dup 2) (const_int 0)]))
4436    (set (match_dup 0)
4437         (sign_extend:DI (plus:SI (mult:SI (match_dup 5) (match_dup 3))
4438                                  (match_dup 4))))]
4439 {
4440   if (! no_new_pseudos)
4441     operands[5] = gen_reg_rtx (DImode);
4442   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4443     operands[5] = operands[0];
4444 })
4445
4446 (define_insn_and_split "*cmp_ssub_di"
4447   [(set (match_operand:DI 0 "register_operand" "=r")
4448         (minus:DI (if_then_else:DI
4449                     (match_operator 1 "alpha_zero_comparison_operator"
4450                       [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4451                        (const_int 0)])
4452                     (match_operand:DI 3 "const48_operand" "I")
4453                     (const_int 0))
4454                   (match_operand:DI 4 "reg_or_8bit_operand" "rI")))
4455    (clobber (match_scratch:DI 5 "=r"))]
4456   ""
4457   "#"
4458   "! no_new_pseudos || reload_completed"
4459   [(set (match_dup 5)
4460         (match_op_dup:DI 1 [(match_dup 2) (const_int 0)]))
4461    (set (match_dup 0)
4462         (minus:DI (mult:DI (match_dup 5) (match_dup 3))
4463                   (match_dup 4)))]
4464 {
4465   if (! no_new_pseudos)
4466     operands[5] = gen_reg_rtx (DImode);
4467   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4468     operands[5] = operands[0];
4469 })
4470
4471 (define_insn_and_split "*cmp_ssub_si"
4472   [(set (match_operand:SI 0 "register_operand" "=r")
4473         (minus:SI (if_then_else:SI
4474                     (match_operator 1 "alpha_zero_comparison_operator"
4475                       [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4476                        (const_int 0)])
4477                     (match_operand:SI 3 "const48_operand" "I")
4478                     (const_int 0))
4479                   (match_operand:SI 4 "reg_or_8bit_operand" "rI")))
4480    (clobber (match_scratch:SI 5 "=r"))]
4481   ""
4482   "#"
4483   "! no_new_pseudos || reload_completed"
4484   [(set (match_dup 5)
4485         (match_op_dup:SI 1 [(match_dup 2) (const_int 0)]))
4486    (set (match_dup 0)
4487         (minus:SI (mult:SI (match_dup 5) (match_dup 3))
4488                  (match_dup 4)))]
4489 {
4490   if (! no_new_pseudos)
4491     operands[5] = gen_reg_rtx (DImode);
4492   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4493     operands[5] = operands[0];
4494 })
4495
4496 (define_insn_and_split "*cmp_ssub_sidi"
4497   [(set (match_operand:DI 0 "register_operand" "=r")
4498         (sign_extend:DI
4499           (minus:SI (if_then_else:SI
4500                       (match_operator 1 "alpha_zero_comparison_operator"
4501                         [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4502                          (const_int 0)])
4503                       (match_operand:SI 3 "const48_operand" "I")
4504                       (const_int 0))
4505                     (match_operand:SI 4 "reg_or_8bit_operand" "rI"))))
4506    (clobber (match_scratch:SI 5 "=r"))]
4507   ""
4508   "#"
4509   "! no_new_pseudos || reload_completed"
4510   [(set (match_dup 5)
4511         (match_op_dup:SI 1 [(match_dup 2) (const_int 0)]))
4512    (set (match_dup 0)
4513         (sign_extend:DI (minus:SI (mult:SI (match_dup 5) (match_dup 3))
4514                                   (match_dup 4))))]
4515 {
4516   if (! no_new_pseudos)
4517     operands[5] = gen_reg_rtx (DImode);
4518   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4519     operands[5] = operands[0];
4520 })
4521 \f
4522 ;; Here are the CALL and unconditional branch insns.  Calls on NT and OSF
4523 ;; work differently, so we have different patterns for each.
4524
4525 ;; On Unicos/Mk a call information word (CIW) must be generated for each
4526 ;; call. The CIW contains information about arguments passed in registers
4527 ;; and is stored in the caller's SSIB. Its offset relative to the beginning
4528 ;; of the SSIB is passed in $25. Handling this properly is quite complicated
4529 ;; in the presence of inlining since the CIWs for calls performed by the
4530 ;; inlined function must be stored in the SSIB of the function it is inlined
4531 ;; into as well. We encode the CIW in an unspec and append it to the list
4532 ;; of the CIWs for the current function only when the instruction for loading
4533 ;; $25 is generated.
4534
4535 (define_expand "call"
4536   [(use (match_operand:DI 0 "" ""))
4537    (use (match_operand 1 "" ""))
4538    (use (match_operand 2 "" ""))
4539    (use (match_operand 3 "" ""))]
4540   ""
4541 {
4542   if (TARGET_ABI_WINDOWS_NT)
4543     emit_call_insn (gen_call_nt (operands[0], operands[1]));
4544   else if (TARGET_ABI_OPEN_VMS)
4545     emit_call_insn (gen_call_vms (operands[0], operands[2]));
4546   else if (TARGET_ABI_UNICOSMK)
4547     emit_call_insn (gen_call_umk (operands[0], operands[2]));
4548   else
4549     emit_call_insn (gen_call_osf (operands[0], operands[1]));
4550   DONE;
4551 })
4552
4553 (define_expand "sibcall"
4554   [(parallel [(call (mem:DI (match_operand 0 "" ""))
4555                             (match_operand 1 "" ""))
4556               (unspec [(reg:DI 29)] UNSPEC_SIBCALL)])]
4557   "TARGET_ABI_OSF"
4558 {
4559   gcc_assert (GET_CODE (operands[0]) == MEM);
4560   operands[0] = XEXP (operands[0], 0);
4561 })
4562
4563 (define_expand "call_osf"
4564   [(parallel [(call (mem:DI (match_operand 0 "" ""))
4565                     (match_operand 1 "" ""))
4566               (use (reg:DI 29))
4567               (clobber (reg:DI 26))])]
4568   ""
4569 {
4570   gcc_assert (GET_CODE (operands[0]) == MEM);
4571
4572   operands[0] = XEXP (operands[0], 0);
4573   if (! call_operand (operands[0], Pmode))
4574     operands[0] = copy_to_mode_reg (Pmode, operands[0]);
4575 })
4576
4577 (define_expand "call_nt"
4578   [(parallel [(call (mem:DI (match_operand 0 "" ""))
4579                     (match_operand 1 "" ""))
4580               (clobber (reg:DI 26))])]
4581   ""
4582 {
4583   gcc_assert (GET_CODE (operands[0]) == MEM);
4584
4585   operands[0] = XEXP (operands[0], 0);
4586   if (GET_CODE (operands[0]) != SYMBOL_REF && GET_CODE (operands[0]) != REG)
4587     operands[0] = force_reg (DImode, operands[0]);
4588 })
4589
4590 ;; Calls on Unicos/Mk are always indirect.
4591 ;; op 0: symbol ref for called function
4592 ;; op 1: CIW for $25 represented by an unspec
4593
4594 (define_expand "call_umk"
4595    [(parallel [(call (mem:DI (match_operand 0 "" ""))
4596                      (match_operand 1 "" ""))
4597                (use (reg:DI 25))
4598                (clobber (reg:DI 26))])]
4599    ""
4600 {
4601   gcc_assert (GET_CODE (operands[0]) == MEM);
4602
4603   /* Always load the address of the called function into a register;
4604      load the CIW in $25.  */
4605
4606   operands[0] = XEXP (operands[0], 0);
4607   if (GET_CODE (operands[0]) != REG)
4608     operands[0] = force_reg (DImode, operands[0]);
4609
4610   emit_move_insn (gen_rtx_REG (DImode, 25), operands[1]);
4611 })
4612
4613 ;;
4614 ;; call openvms/alpha
4615 ;; op 0: symbol ref for called function
4616 ;; op 1: next_arg_reg (argument information value for R25)
4617 ;;
4618 (define_expand "call_vms"
4619   [(parallel [(call (mem:DI (match_operand 0 "" ""))
4620                     (match_operand 1 "" ""))
4621               (use (match_dup 2))
4622               (use (reg:DI 25))
4623               (use (reg:DI 26))
4624               (clobber (reg:DI 27))])]
4625   ""
4626 {
4627   gcc_assert (GET_CODE (operands[0]) == MEM);
4628
4629   operands[0] = XEXP (operands[0], 0);
4630
4631   /* Always load AI with argument information, then handle symbolic and
4632      indirect call differently.  Load RA and set operands[2] to PV in
4633      both cases.  */
4634
4635   emit_move_insn (gen_rtx_REG (DImode, 25), operands[1]);
4636   if (GET_CODE (operands[0]) == SYMBOL_REF)
4637     {
4638       alpha_need_linkage (XSTR (operands[0], 0), 0);
4639
4640       operands[2] = const0_rtx;
4641     }
4642   else
4643     {
4644       emit_move_insn (gen_rtx_REG (Pmode, 26),
4645                       gen_rtx_MEM (Pmode, plus_constant (operands[0], 8)));
4646       operands[2] = operands[0];
4647     }
4648
4649 })
4650
4651 (define_expand "call_value"
4652   [(use (match_operand 0 "" ""))
4653    (use (match_operand:DI 1 "" ""))
4654    (use (match_operand 2 "" ""))
4655    (use (match_operand 3 "" ""))
4656    (use (match_operand 4 "" ""))]
4657   ""
4658 {
4659   if (TARGET_ABI_WINDOWS_NT)
4660     emit_call_insn (gen_call_value_nt (operands[0], operands[1], operands[2]));
4661   else if (TARGET_ABI_OPEN_VMS)
4662     emit_call_insn (gen_call_value_vms (operands[0], operands[1],
4663                                         operands[3]));
4664   else if (TARGET_ABI_UNICOSMK)
4665     emit_call_insn (gen_call_value_umk (operands[0], operands[1],
4666                                         operands[3]));
4667   else
4668     emit_call_insn (gen_call_value_osf (operands[0], operands[1],
4669                                         operands[2]));
4670   DONE;
4671 })
4672
4673 (define_expand "sibcall_value"
4674   [(parallel [(set (match_operand 0 "" "")
4675                    (call (mem:DI (match_operand 1 "" ""))
4676                          (match_operand 2 "" "")))
4677               (unspec [(reg:DI 29)] UNSPEC_SIBCALL)])]
4678   "TARGET_ABI_OSF"
4679 {
4680   gcc_assert (GET_CODE (operands[1]) == MEM);
4681   operands[1] = XEXP (operands[1], 0);
4682 })
4683
4684 (define_expand "call_value_osf"
4685   [(parallel [(set (match_operand 0 "" "")
4686                    (call (mem:DI (match_operand 1 "" ""))
4687                          (match_operand 2 "" "")))
4688               (use (reg:DI 29))
4689               (clobber (reg:DI 26))])]
4690   ""
4691 {
4692   gcc_assert (GET_CODE (operands[1]) == MEM);
4693
4694   operands[1] = XEXP (operands[1], 0);
4695   if (! call_operand (operands[1], Pmode))
4696     operands[1] = copy_to_mode_reg (Pmode, operands[1]);
4697 })
4698
4699 (define_expand "call_value_nt"
4700   [(parallel [(set (match_operand 0 "" "")
4701                    (call (mem:DI (match_operand 1 "" ""))
4702                          (match_operand 2 "" "")))
4703               (clobber (reg:DI 26))])]
4704   ""
4705 {
4706   gcc_assert (GET_CODE (operands[1]) == MEM);
4707
4708   operands[1] = XEXP (operands[1], 0);
4709   if (GET_CODE (operands[1]) != SYMBOL_REF && GET_CODE (operands[1]) != REG)
4710     operands[1] = force_reg (DImode, operands[1]);
4711 })
4712
4713 (define_expand "call_value_vms"
4714   [(parallel [(set (match_operand 0 "" "")
4715                    (call (mem:DI (match_operand:DI 1 "" ""))
4716                          (match_operand 2 "" "")))
4717               (use (match_dup 3))
4718               (use (reg:DI 25))
4719               (use (reg:DI 26))
4720               (clobber (reg:DI 27))])]
4721   ""
4722 {
4723   gcc_assert (GET_CODE (operands[1]) == MEM);
4724
4725   operands[1] = XEXP (operands[1], 0);
4726
4727   /* Always load AI with argument information, then handle symbolic and
4728      indirect call differently.  Load RA and set operands[3] to PV in
4729      both cases.  */
4730
4731   emit_move_insn (gen_rtx_REG (DImode, 25), operands[2]);
4732   if (GET_CODE (operands[1]) == SYMBOL_REF)
4733     {
4734       alpha_need_linkage (XSTR (operands[1], 0), 0);
4735
4736       operands[3] = const0_rtx;
4737     }
4738   else
4739     {
4740       emit_move_insn (gen_rtx_REG (Pmode, 26),
4741                       gen_rtx_MEM (Pmode, plus_constant (operands[1], 8)));
4742       operands[3] = operands[1];
4743     }
4744 })
4745
4746 (define_expand "call_value_umk"
4747   [(parallel [(set (match_operand 0 "" "")
4748                    (call (mem:DI (match_operand 1 "" ""))
4749                          (match_operand 2 "" "")))
4750               (use (reg:DI 25))
4751               (clobber (reg:DI 26))])]
4752   ""
4753 {
4754   gcc_assert (GET_CODE (operands[1]) == MEM);
4755
4756   operands[1] = XEXP (operands[1], 0);
4757   if (GET_CODE (operands[1]) != REG)
4758     operands[1] = force_reg (DImode, operands[1]);
4759
4760   emit_move_insn (gen_rtx_REG (DImode, 25), operands[2]);
4761 })
4762
4763 (define_insn "*call_osf_1_er_noreturn"
4764   [(call (mem:DI (match_operand:DI 0 "call_operand" "c,R,s"))
4765          (match_operand 1 "" ""))
4766    (use (reg:DI 29))
4767    (clobber (reg:DI 26))]
4768   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF
4769    && find_reg_note (insn, REG_NORETURN, NULL_RTX)"
4770   "@
4771    jsr $26,($27),0
4772    bsr $26,%0\t\t!samegp
4773    ldq $27,%0($29)\t\t!literal!%#\;jsr $26,($27),%0\t\t!lituse_jsr!%#"
4774   [(set_attr "type" "jsr")
4775    (set_attr "length" "*,*,8")])
4776
4777 (define_insn "*call_osf_1_er"
4778   [(call (mem:DI (match_operand:DI 0 "call_operand" "c,R,s"))
4779          (match_operand 1 "" ""))
4780    (use (reg:DI 29))
4781    (clobber (reg:DI 26))]
4782   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4783   "@
4784    jsr $26,(%0),0\;ldah $29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*
4785    bsr $26,%0\t\t!samegp
4786    ldq $27,%0($29)\t\t!literal!%#\;jsr $26,($27),%0\t\t!lituse_jsr!%#\;ldah $29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*"
4787   [(set_attr "type" "jsr")
4788    (set_attr "length" "12,*,16")])
4789
4790 ;; We must use peep2 instead of a split because we need accurate life
4791 ;; information for $gp.  Consider the case of { bar(); while (1); }.
4792 (define_peephole2
4793   [(parallel [(call (mem:DI (match_operand:DI 0 "call_operand" ""))
4794                     (match_operand 1 "" ""))
4795               (use (reg:DI 29))
4796               (clobber (reg:DI 26))])]
4797   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF && reload_completed
4798    && ! samegp_function_operand (operands[0], Pmode)
4799    && (peep2_regno_dead_p (1, 29)
4800        || find_reg_note (insn, REG_NORETURN, NULL_RTX))"
4801   [(parallel [(call (mem:DI (match_dup 2))
4802                     (match_dup 1))
4803               (use (reg:DI 29))
4804               (use (match_dup 0))
4805               (use (match_dup 3))
4806               (clobber (reg:DI 26))])]
4807 {
4808   if (CONSTANT_P (operands[0]))
4809     {
4810       operands[2] = gen_rtx_REG (Pmode, 27);
4811       operands[3] = GEN_INT (alpha_next_sequence_number++);
4812       emit_insn (gen_movdi_er_high_g (operands[2], pic_offset_table_rtx,
4813                                       operands[0], operands[3]));
4814     }
4815   else
4816     {
4817       operands[2] = operands[0];
4818       operands[0] = const0_rtx;
4819       operands[3] = const0_rtx;
4820     }
4821 })
4822
4823 (define_peephole2
4824   [(parallel [(call (mem:DI (match_operand:DI 0 "call_operand" ""))
4825                     (match_operand 1 "" ""))
4826               (use (reg:DI 29))
4827               (clobber (reg:DI 26))])]
4828   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF && reload_completed
4829    && ! samegp_function_operand (operands[0], Pmode)
4830    && ! (peep2_regno_dead_p (1, 29)
4831          || find_reg_note (insn, REG_NORETURN, NULL_RTX))"
4832   [(parallel [(call (mem:DI (match_dup 2))
4833                     (match_dup 1))
4834               (set (match_dup 5)
4835                    (unspec:DI [(match_dup 5) (match_dup 3)] UNSPEC_LDGP1))
4836               (use (match_dup 0))
4837               (use (match_dup 4))
4838               (clobber (reg:DI 26))])
4839    (set (match_dup 5)
4840         (unspec:DI [(match_dup 5) (match_dup 3)] UNSPEC_LDGP2))]
4841 {
4842   if (CONSTANT_P (operands[0]))
4843     {
4844       operands[2] = gen_rtx_REG (Pmode, 27);
4845       operands[4] = GEN_INT (alpha_next_sequence_number++);
4846       emit_insn (gen_movdi_er_high_g (operands[2], pic_offset_table_rtx,
4847                                       operands[0], operands[4]));
4848     }
4849   else
4850     {
4851       operands[2] = operands[0];
4852       operands[0] = const0_rtx;
4853       operands[4] = const0_rtx;
4854     }
4855   operands[3] = GEN_INT (alpha_next_sequence_number++);
4856   operands[5] = pic_offset_table_rtx;
4857 })
4858
4859 (define_insn "*call_osf_2_er_nogp"
4860   [(call (mem:DI (match_operand:DI 0 "register_operand" "c"))
4861          (match_operand 1 "" ""))
4862    (use (reg:DI 29))
4863    (use (match_operand 2 "" ""))
4864    (use (match_operand 3 "const_int_operand" ""))
4865    (clobber (reg:DI 26))]
4866   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4867   "jsr $26,(%0),%2%J3"
4868   [(set_attr "type" "jsr")])
4869
4870 (define_insn "*call_osf_2_er"
4871   [(call (mem:DI (match_operand:DI 0 "register_operand" "c"))
4872          (match_operand 1 "" ""))
4873    (set (reg:DI 29)
4874         (unspec:DI [(reg:DI 29) (match_operand 4 "const_int_operand" "")]
4875                    UNSPEC_LDGP1))
4876    (use (match_operand 2 "" ""))
4877    (use (match_operand 3 "const_int_operand" ""))
4878    (clobber (reg:DI 26))]
4879   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4880   "jsr $26,(%0),%2%J3\;ldah $29,0($26)\t\t!gpdisp!%4"
4881   [(set_attr "type" "jsr")
4882    (set_attr "cannot_copy" "true")
4883    (set_attr "length" "8")])
4884
4885 (define_insn "*call_osf_1_noreturn"
4886   [(call (mem:DI (match_operand:DI 0 "call_operand" "c,R,s"))
4887          (match_operand 1 "" ""))
4888    (use (reg:DI 29))
4889    (clobber (reg:DI 26))]
4890   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF
4891    && find_reg_note (insn, REG_NORETURN, NULL_RTX)"
4892   "@
4893    jsr $26,($27),0
4894    bsr $26,$%0..ng
4895    jsr $26,%0"
4896   [(set_attr "type" "jsr")
4897    (set_attr "length" "*,*,8")])
4898
4899 (define_insn "*call_osf_1"
4900   [(call (mem:DI (match_operand:DI 0 "call_operand" "c,R,s"))
4901          (match_operand 1 "" ""))
4902    (use (reg:DI 29))
4903    (clobber (reg:DI 26))]
4904   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4905   "@
4906    jsr $26,($27),0\;ldgp $29,0($26)
4907    bsr $26,$%0..ng
4908    jsr $26,%0\;ldgp $29,0($26)"
4909   [(set_attr "type" "jsr")
4910    (set_attr "length" "12,*,16")])
4911
4912 (define_insn "*sibcall_osf_1_er"
4913   [(call (mem:DI (match_operand:DI 0 "symbolic_operand" "R,s"))
4914          (match_operand 1 "" ""))
4915    (unspec [(reg:DI 29)] UNSPEC_SIBCALL)]
4916   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4917   "@
4918    br $31,%0\t\t!samegp
4919    ldq $27,%0($29)\t\t!literal!%#\;jmp $31,($27),%0\t\t!lituse_jsr!%#"
4920   [(set_attr "type" "jsr")
4921    (set_attr "length" "*,8")])
4922
4923 ;; Note that the DEC assembler expands "jmp foo" with $at, which
4924 ;; doesn't do what we want.
4925 (define_insn "*sibcall_osf_1"
4926   [(call (mem:DI (match_operand:DI 0 "symbolic_operand" "R,s"))
4927          (match_operand 1 "" ""))
4928    (unspec [(reg:DI 29)] UNSPEC_SIBCALL)]
4929   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4930   "@
4931    br $31,$%0..ng
4932    lda $27,%0\;jmp $31,($27),%0"
4933   [(set_attr "type" "jsr")
4934    (set_attr "length" "*,8")])
4935
4936 (define_insn "*call_nt_1"
4937   [(call (mem:DI (match_operand:DI 0 "call_operand" "r,R,s"))
4938          (match_operand 1 "" ""))
4939    (clobber (reg:DI 26))]
4940   "TARGET_ABI_WINDOWS_NT"
4941   "@
4942    jsr $26,(%0)
4943    bsr $26,%0
4944    jsr $26,%0"
4945   [(set_attr "type" "jsr")
4946    (set_attr "length" "*,*,12")])
4947
4948 ; GAS relies on the order and position of instructions output below in order
4949 ; to generate relocs for VMS link to potentially optimize the call.
4950 ; Please do not molest.
4951 (define_insn "*call_vms_1"
4952   [(call (mem:DI (match_operand:DI 0 "call_operand" "r,s"))
4953          (match_operand 1 "" ""))
4954    (use (match_operand:DI 2 "nonmemory_operand" "r,n"))
4955    (use (reg:DI 25))
4956    (use (reg:DI 26))
4957    (clobber (reg:DI 27))]
4958   "TARGET_ABI_OPEN_VMS"
4959 {
4960   switch (which_alternative)
4961     {
4962     case 0:
4963         return "mov %2,$27\;jsr $26,0\;ldq $27,0($29)";
4964     case 1:
4965         operands [2] = alpha_use_linkage (operands [0], cfun->decl, 1, 0);
4966         operands [3] = alpha_use_linkage (operands [0], cfun->decl, 0, 0);
4967         return "ldq $26,%3\;ldq $27,%2\;jsr $26,%0\;ldq $27,0($29)";
4968     default:
4969       gcc_unreachable ();
4970     }
4971 }
4972   [(set_attr "type" "jsr")
4973    (set_attr "length" "12,16")])
4974
4975 (define_insn "*call_umk_1"
4976   [(call (mem:DI (match_operand:DI 0 "call_operand" "r"))
4977          (match_operand 1 "" ""))
4978    (use (reg:DI 25))
4979    (clobber (reg:DI 26))]
4980   "TARGET_ABI_UNICOSMK"
4981   "jsr $26,(%0)"
4982   [(set_attr "type" "jsr")])
4983
4984 ;; Call subroutine returning any type.
4985
4986 (define_expand "untyped_call"
4987   [(parallel [(call (match_operand 0 "" "")
4988                     (const_int 0))
4989               (match_operand 1 "" "")
4990               (match_operand 2 "" "")])]
4991   ""
4992 {
4993   int i;
4994
4995   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
4996
4997   for (i = 0; i < XVECLEN (operands[2], 0); i++)
4998     {
4999       rtx set = XVECEXP (operands[2], 0, i);
5000       emit_move_insn (SET_DEST (set), SET_SRC (set));
5001     }
5002
5003   /* The optimizer does not know that the call sets the function value
5004      registers we stored in the result block.  We avoid problems by
5005      claiming that all hard registers are used and clobbered at this
5006      point.  */
5007   emit_insn (gen_blockage ());
5008
5009   DONE;
5010 })
5011
5012 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
5013 ;; all of memory.  This blocks insns from being moved across this point.
5014
5015 (define_insn "blockage"
5016   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
5017   ""
5018   ""
5019   [(set_attr "length" "0")
5020    (set_attr "type" "none")])
5021
5022 (define_insn "jump"
5023   [(set (pc)
5024         (label_ref (match_operand 0 "" "")))]
5025   ""
5026   "br $31,%l0"
5027   [(set_attr "type" "ibr")])
5028
5029 (define_expand "return"
5030   [(return)]
5031   "direct_return ()"
5032   "")
5033
5034 (define_insn "*return_internal"
5035   [(return)]
5036   "reload_completed"
5037   "ret $31,($26),1"
5038   [(set_attr "type" "ibr")])
5039
5040 (define_insn "indirect_jump"
5041   [(set (pc) (match_operand:DI 0 "register_operand" "r"))]
5042   ""
5043   "jmp $31,(%0),0"
5044   [(set_attr "type" "ibr")])
5045
5046 (define_expand "tablejump"
5047   [(parallel [(set (pc)
5048                    (match_operand 0 "register_operand" ""))
5049               (use (label_ref:DI (match_operand 1 "" "")))])]
5050   ""
5051 {
5052   if (TARGET_ABI_WINDOWS_NT)
5053     {
5054       rtx dest = gen_reg_rtx (DImode);
5055       emit_insn (gen_extendsidi2 (dest, operands[0]));
5056       operands[0] = dest;
5057     }
5058   else if (TARGET_ABI_OSF)
5059     {
5060       rtx dest = gen_reg_rtx (DImode);
5061       emit_insn (gen_extendsidi2 (dest, operands[0]));
5062       emit_insn (gen_adddi3 (dest, pic_offset_table_rtx, dest));        
5063       operands[0] = dest;
5064     }
5065 })
5066
5067 (define_insn "*tablejump_osf_nt_internal"
5068   [(set (pc)
5069         (match_operand:DI 0 "register_operand" "r"))
5070    (use (label_ref:DI (match_operand 1 "" "")))]
5071   "(TARGET_ABI_OSF || TARGET_ABI_WINDOWS_NT)
5072    && alpha_tablejump_addr_vec (insn)"
5073 {
5074   operands[2] = alpha_tablejump_best_label (insn);
5075   return "jmp $31,(%0),%2";
5076 }
5077   [(set_attr "type" "ibr")])
5078
5079 (define_insn "*tablejump_internal"
5080   [(set (pc)
5081         (match_operand:DI 0 "register_operand" "r"))
5082    (use (label_ref (match_operand 1 "" "")))]
5083   ""
5084   "jmp $31,(%0),0"
5085   [(set_attr "type" "ibr")])
5086
5087 ;; Cache flush.  Used by INITIALIZE_TRAMPOLINE.  0x86 is PAL_imb, but we don't
5088 ;; want to have to include pal.h in our .s file.
5089 (define_insn "imb"
5090   [(unspec_volatile [(const_int 0)] UNSPECV_IMB)]
5091   ""
5092   "call_pal 0x86"
5093   [(set_attr "type" "callpal")])
5094
5095 ;; BUGCHK is documented common to OSF/1 and VMS PALcode.
5096 ;; NT does not document anything at 0x81 -- presumably it would generate
5097 ;; the equivalent of SIGILL, but this isn't that important.
5098 ;; ??? Presuming unicosmk uses either OSF/1 or VMS PALcode.
5099 (define_insn "trap"
5100   [(trap_if (const_int 1) (const_int 0))]
5101   "!TARGET_ABI_WINDOWS_NT"
5102   "call_pal 0x81"
5103   [(set_attr "type" "callpal")])
5104
5105 ;; For userland, we load the thread pointer from the TCB.
5106 ;; For the kernel, we load the per-cpu private value.
5107
5108 (define_insn "load_tp"
5109   [(set (match_operand:DI 0 "register_operand" "=v")
5110         (unspec:DI [(const_int 0)] UNSPEC_TP))]
5111   "TARGET_ABI_OSF"
5112 {
5113   if (TARGET_TLS_KERNEL)
5114     return "call_pal 0x32";
5115   else
5116     return "call_pal 0x9e";
5117 }
5118   [(set_attr "type" "callpal")])
5119
5120 ;; For completeness, and possibly a __builtin function, here's how to
5121 ;; set the thread pointer.  Since we don't describe enough of this
5122 ;; quantity for CSE, we have to use a volatile unspec, and then there's
5123 ;; not much point in creating an R16_REG register class.
5124
5125 (define_expand "set_tp"
5126   [(set (reg:DI 16) (match_operand:DI 0 "input_operand" ""))
5127    (unspec_volatile [(reg:DI 16)] UNSPECV_SET_TP)]
5128   "TARGET_ABI_OSF"
5129   "")
5130
5131 (define_insn "*set_tp"
5132   [(unspec_volatile [(reg:DI 16)] UNSPECV_SET_TP)]
5133   "TARGET_ABI_OSF"
5134 {
5135   if (TARGET_TLS_KERNEL)
5136     return "call_pal 0x31";
5137   else
5138     return "call_pal 0x9f";
5139 }
5140   [(set_attr "type" "callpal")])
5141 \f
5142 ;; Finally, we have the basic data motion insns.  The byte and word insns
5143 ;; are done via define_expand.  Start with the floating-point insns, since
5144 ;; they are simpler.
5145
5146 (define_insn "*movsf_nofix"
5147   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,*r,*r,m,m")
5148         (match_operand:SF 1 "input_operand" "fG,m,*rG,m,fG,*r"))]
5149   "TARGET_FPREGS && ! TARGET_FIX
5150    && (register_operand (operands[0], SFmode)
5151        || reg_or_0_operand (operands[1], SFmode))"
5152   "@
5153    cpys %R1,%R1,%0
5154    ld%, %0,%1
5155    bis $31,%r1,%0
5156    ldl %0,%1
5157    st%, %R1,%0
5158    stl %r1,%0"
5159   [(set_attr "type" "fcpys,fld,ilog,ild,fst,ist")])
5160
5161 (define_insn "*movsf_fix"
5162   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,*r,*r,m,m,f,*r")
5163         (match_operand:SF 1 "input_operand" "fG,m,*rG,m,fG,*r,*r,f"))]
5164   "TARGET_FPREGS && TARGET_FIX
5165    && (register_operand (operands[0], SFmode)
5166        || reg_or_0_operand (operands[1], SFmode))"
5167   "@
5168    cpys %R1,%R1,%0
5169    ld%, %0,%1
5170    bis $31,%r1,%0
5171    ldl %0,%1
5172    st%, %R1,%0
5173    stl %r1,%0
5174    itofs %1,%0
5175    ftois %1,%0"
5176   [(set_attr "type" "fcpys,fld,ilog,ild,fst,ist,itof,ftoi")])
5177
5178 (define_insn "*movsf_nofp"
5179   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,m")
5180         (match_operand:SF 1 "input_operand" "rG,m,r"))]
5181   "! TARGET_FPREGS
5182    && (register_operand (operands[0], SFmode)
5183        || reg_or_0_operand (operands[1], SFmode))"
5184   "@
5185    bis $31,%r1,%0
5186    ldl %0,%1
5187    stl %r1,%0"
5188   [(set_attr "type" "ilog,ild,ist")])
5189
5190 (define_insn "*movdf_nofix"
5191   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,*r,*r,m,m")
5192         (match_operand:DF 1 "input_operand" "fG,m,*rG,m,fG,*r"))]
5193   "TARGET_FPREGS && ! TARGET_FIX
5194    && (register_operand (operands[0], DFmode)
5195        || reg_or_0_operand (operands[1], DFmode))"
5196   "@
5197    cpys %R1,%R1,%0
5198    ld%- %0,%1
5199    bis $31,%r1,%0
5200    ldq %0,%1
5201    st%- %R1,%0
5202    stq %r1,%0"
5203   [(set_attr "type" "fcpys,fld,ilog,ild,fst,ist")])
5204
5205 (define_insn "*movdf_fix"
5206   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,*r,*r,m,m,f,*r")
5207         (match_operand:DF 1 "input_operand" "fG,m,*rG,m,fG,*r,*r,f"))]
5208   "TARGET_FPREGS && TARGET_FIX
5209    && (register_operand (operands[0], DFmode)
5210        || reg_or_0_operand (operands[1], DFmode))"
5211   "@
5212    cpys %R1,%R1,%0
5213    ld%- %0,%1
5214    bis $31,%r1,%0
5215    ldq %0,%1
5216    st%- %R1,%0
5217    stq %r1,%0
5218    itoft %1,%0
5219    ftoit %1,%0"
5220   [(set_attr "type" "fcpys,fld,ilog,ild,fst,ist,itof,ftoi")])
5221
5222 (define_insn "*movdf_nofp"
5223   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m")
5224         (match_operand:DF 1 "input_operand" "rG,m,r"))]
5225   "! TARGET_FPREGS
5226    && (register_operand (operands[0], DFmode)
5227        || reg_or_0_operand (operands[1], DFmode))"
5228   "@
5229    bis $31,%r1,%0
5230    ldq %0,%1
5231    stq %r1,%0"
5232   [(set_attr "type" "ilog,ild,ist")])
5233
5234 ;; Subregs suck for register allocation.  Pretend we can move TFmode
5235 ;; data between general registers until after reload.
5236
5237 (define_insn_and_split "*movtf_internal"
5238   [(set (match_operand:TF 0 "nonimmediate_operand" "=r,o")
5239         (match_operand:TF 1 "input_operand" "roG,rG"))]
5240   "register_operand (operands[0], TFmode)
5241    || reg_or_0_operand (operands[1], TFmode)"
5242   "#"
5243   "reload_completed"
5244   [(set (match_dup 0) (match_dup 2))
5245    (set (match_dup 1) (match_dup 3))]
5246 {
5247   alpha_split_tmode_pair (operands, TFmode, true); 
5248 })
5249
5250 (define_expand "movsf"
5251   [(set (match_operand:SF 0 "nonimmediate_operand" "")
5252         (match_operand:SF 1 "general_operand" ""))]
5253   ""
5254 {
5255   if (GET_CODE (operands[0]) == MEM
5256       && ! reg_or_0_operand (operands[1], SFmode))
5257     operands[1] = force_reg (SFmode, operands[1]);
5258 })
5259
5260 (define_expand "movdf"
5261   [(set (match_operand:DF 0 "nonimmediate_operand" "")
5262         (match_operand:DF 1 "general_operand" ""))]
5263   ""
5264 {
5265   if (GET_CODE (operands[0]) == MEM
5266       && ! reg_or_0_operand (operands[1], DFmode))
5267     operands[1] = force_reg (DFmode, operands[1]);
5268 })
5269
5270 (define_expand "movtf"
5271   [(set (match_operand:TF 0 "nonimmediate_operand" "")
5272         (match_operand:TF 1 "general_operand" ""))]
5273   ""
5274 {
5275   if (GET_CODE (operands[0]) == MEM
5276       && ! reg_or_0_operand (operands[1], TFmode))
5277     operands[1] = force_reg (TFmode, operands[1]);
5278 })
5279
5280 (define_insn "*movsi"
5281   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,r,m")
5282         (match_operand:SI 1 "input_operand" "rJ,K,L,n,m,rJ"))]
5283   "(TARGET_ABI_OSF || TARGET_ABI_UNICOSMK)
5284    && (register_operand (operands[0], SImode)
5285        || reg_or_0_operand (operands[1], SImode))"
5286   "@
5287    bis $31,%r1,%0
5288    lda %0,%1($31)
5289    ldah %0,%h1($31)
5290    #
5291    ldl %0,%1
5292    stl %r1,%0"
5293   [(set_attr "type" "ilog,iadd,iadd,multi,ild,ist")])
5294
5295 (define_insn "*movsi_nt_vms"
5296   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,r,r,m")
5297         (match_operand:SI 1 "input_operand" "rJ,K,L,s,n,m,rJ"))]
5298   "(TARGET_ABI_WINDOWS_NT || TARGET_ABI_OPEN_VMS)
5299     && (register_operand (operands[0], SImode)
5300         || reg_or_0_operand (operands[1], SImode))"
5301   "@
5302    bis $31,%1,%0
5303    lda %0,%1
5304    ldah %0,%h1
5305    lda %0,%1
5306    #
5307    ldl %0,%1
5308    stl %r1,%0"
5309   [(set_attr "type" "ilog,iadd,iadd,ldsym,multi,ild,ist")])
5310
5311 (define_insn "*movhi_nobwx"
5312   [(set (match_operand:HI 0 "register_operand" "=r,r")
5313         (match_operand:HI 1 "input_operand" "rJ,n"))]
5314   "! TARGET_BWX
5315    && (register_operand (operands[0], HImode)
5316        || register_operand (operands[1], HImode))"
5317   "@
5318    bis $31,%r1,%0
5319    lda %0,%L1($31)"
5320   [(set_attr "type" "ilog,iadd")])
5321
5322 (define_insn "*movhi_bwx"
5323   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,m")
5324         (match_operand:HI 1 "input_operand" "rJ,n,m,rJ"))]
5325   "TARGET_BWX
5326    && (register_operand (operands[0], HImode)
5327        || reg_or_0_operand (operands[1], HImode))"
5328   "@
5329    bis $31,%r1,%0
5330    lda %0,%L1($31)
5331    ldwu %0,%1
5332    stw %r1,%0"
5333   [(set_attr "type" "ilog,iadd,ild,ist")])
5334
5335 (define_insn "*movqi_nobwx"
5336   [(set (match_operand:QI 0 "register_operand" "=r,r")
5337         (match_operand:QI 1 "input_operand" "rJ,n"))]
5338   "! TARGET_BWX
5339    && (register_operand (operands[0], QImode)
5340        || register_operand (operands[1], QImode))"
5341   "@
5342    bis $31,%r1,%0
5343    lda %0,%L1($31)"
5344   [(set_attr "type" "ilog,iadd")])
5345
5346 (define_insn "*movqi_bwx"
5347   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,r,m")
5348         (match_operand:QI 1 "input_operand" "rJ,n,m,rJ"))]
5349   "TARGET_BWX
5350    && (register_operand (operands[0], QImode)
5351        || reg_or_0_operand (operands[1], QImode))"
5352   "@
5353    bis $31,%r1,%0
5354    lda %0,%L1($31)
5355    ldbu %0,%1
5356    stb %r1,%0"
5357   [(set_attr "type" "ilog,iadd,ild,ist")])
5358
5359 ;; We do two major things here: handle mem->mem and construct long
5360 ;; constants.
5361
5362 (define_expand "movsi"
5363   [(set (match_operand:SI 0 "nonimmediate_operand" "")
5364         (match_operand:SI 1 "general_operand" ""))]
5365   ""
5366 {
5367   if (alpha_expand_mov (SImode, operands))
5368     DONE;
5369 })
5370
5371 ;; Split a load of a large constant into the appropriate two-insn
5372 ;; sequence.
5373
5374 (define_split
5375   [(set (match_operand:SI 0 "register_operand" "")
5376         (match_operand:SI 1 "non_add_const_operand" ""))]
5377   ""
5378   [(const_int 0)]
5379 {
5380   if (alpha_split_const_mov (SImode, operands))
5381     DONE;
5382   else
5383     FAIL;
5384 })
5385
5386 ;; Split the load of an address into a four-insn sequence on Unicos/Mk.
5387 ;; Always generate a REG_EQUAL note for the last instruction to facilitate
5388 ;; optimizations. If the symbolic operand is a label_ref, generate REG_LABEL
5389 ;; notes and update LABEL_NUSES because this is not done automatically.
5390 ;; Labels may be incorrectly deleted if we don't do this.
5391 ;;
5392 ;; Describing what the individual instructions do correctly is too complicated
5393 ;; so use UNSPECs for each of the three parts of an address.
5394
5395 (define_split
5396   [(set (match_operand:DI 0 "register_operand" "")
5397         (match_operand:DI 1 "symbolic_operand" ""))]
5398   "TARGET_ABI_UNICOSMK && reload_completed"
5399   [(const_int 0)]
5400 {
5401   rtx insn1, insn2, insn3;
5402
5403   insn1 = emit_insn (gen_umk_laum (operands[0], operands[1]));
5404   emit_insn (gen_ashldi3 (operands[0], operands[0], GEN_INT (32)));
5405   insn2 = emit_insn (gen_umk_lalm (operands[0], operands[0], operands[1]));
5406   insn3 = emit_insn (gen_umk_lal (operands[0], operands[0], operands[1]));
5407   set_unique_reg_note (insn3, REG_EQUAL, operands[1]);
5408
5409   if (GET_CODE (operands[1]) == LABEL_REF)
5410     {
5411       rtx label;
5412
5413       label = XEXP (operands[1], 0);
5414       REG_NOTES (insn1) = gen_rtx_EXPR_LIST (REG_LABEL, label,
5415                                              REG_NOTES (insn1));
5416       REG_NOTES (insn2) = gen_rtx_EXPR_LIST (REG_LABEL, label,
5417                                              REG_NOTES (insn2));
5418       REG_NOTES (insn3) = gen_rtx_EXPR_LIST (REG_LABEL, label,
5419                                              REG_NOTES (insn3));
5420       LABEL_NUSES (label) += 3;
5421     }
5422   DONE;
5423 })
5424
5425 ;; Instructions for loading the three parts of an address on Unicos/Mk.
5426
5427 (define_insn "umk_laum"
5428   [(set (match_operand:DI 0 "register_operand" "=r")
5429         (unspec:DI [(match_operand:DI 1 "symbolic_operand" "")]
5430                    UNSPEC_UMK_LAUM))]
5431   "TARGET_ABI_UNICOSMK"
5432   "laum %r0,%t1($31)"
5433   [(set_attr "type" "iadd")])
5434
5435 (define_insn "umk_lalm"
5436   [(set (match_operand:DI 0 "register_operand" "=r")
5437         (plus:DI (match_operand:DI 1 "register_operand" "r")
5438                  (unspec:DI [(match_operand:DI 2 "symbolic_operand" "")]
5439                             UNSPEC_UMK_LALM)))] 
5440   "TARGET_ABI_UNICOSMK"
5441   "lalm %r0,%t2(%r1)"
5442   [(set_attr "type" "iadd")])
5443
5444 (define_insn "umk_lal"
5445   [(set (match_operand:DI 0 "register_operand" "=r")
5446         (plus:DI (match_operand:DI 1 "register_operand" "r")
5447                  (unspec:DI [(match_operand:DI 2 "symbolic_operand" "")]
5448                             UNSPEC_UMK_LAL)))]
5449   "TARGET_ABI_UNICOSMK"
5450   "lal %r0,%t2(%r1)"
5451   [(set_attr "type" "iadd")])
5452
5453 ;; Add a new call information word to the current function's list of CIWs
5454 ;; and load its index into $25. Doing it here ensures that the CIW will be
5455 ;; associated with the correct function even in the presence of inlining.
5456
5457 (define_insn "*umk_load_ciw"
5458   [(set (reg:DI 25)
5459         (unspec:DI [(match_operand 0 "" "")] UNSPEC_UMK_LOAD_CIW))]
5460   "TARGET_ABI_UNICOSMK"
5461 {
5462   operands[0] = unicosmk_add_call_info_word (operands[0]);
5463   return "lda $25,%0";
5464 }
5465   [(set_attr "type" "iadd")])
5466
5467 (define_insn "*movdi_er_low_l"
5468   [(set (match_operand:DI 0 "register_operand" "=r")
5469         (lo_sum:DI (match_operand:DI 1 "register_operand" "r")
5470                    (match_operand:DI 2 "local_symbolic_operand" "")))]
5471   "TARGET_EXPLICIT_RELOCS"
5472 {
5473   if (true_regnum (operands[1]) == 29)
5474     return "lda %0,%2(%1)\t\t!gprel";
5475   else
5476     return "lda %0,%2(%1)\t\t!gprellow";
5477 }
5478   [(set_attr "usegp" "yes")])
5479
5480 (define_split
5481   [(set (match_operand:DI 0 "register_operand" "")
5482         (match_operand:DI 1 "small_symbolic_operand" ""))]
5483   "TARGET_EXPLICIT_RELOCS && reload_completed"
5484   [(set (match_dup 0)
5485         (lo_sum:DI (match_dup 2) (match_dup 1)))]
5486   "operands[2] = pic_offset_table_rtx;")
5487
5488 (define_split
5489   [(set (match_operand:DI 0 "register_operand" "")
5490         (match_operand:DI 1 "local_symbolic_operand" ""))]
5491   "TARGET_EXPLICIT_RELOCS && reload_completed"
5492   [(set (match_dup 0)
5493         (plus:DI (match_dup 2) (high:DI (match_dup 1))))
5494    (set (match_dup 0)
5495         (lo_sum:DI (match_dup 0) (match_dup 1)))]
5496   "operands[2] = pic_offset_table_rtx;")
5497
5498 (define_split
5499   [(match_operand 0 "some_small_symbolic_operand" "")]
5500   ""
5501   [(match_dup 0)]
5502   "operands[0] = split_small_symbolic_operand (operands[0]);")
5503
5504 ;; Accepts any symbolic, not just global, since function calls that
5505 ;; don't go via bsr still use !literal in hopes of linker relaxation.
5506 (define_insn "movdi_er_high_g"
5507   [(set (match_operand:DI 0 "register_operand" "=r")
5508         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
5509                     (match_operand:DI 2 "symbolic_operand" "")
5510                     (match_operand 3 "const_int_operand" "")]
5511                    UNSPEC_LITERAL))]
5512   "TARGET_EXPLICIT_RELOCS"
5513 {
5514   if (INTVAL (operands[3]) == 0)
5515     return "ldq %0,%2(%1)\t\t!literal";
5516   else
5517     return "ldq %0,%2(%1)\t\t!literal!%3";
5518 }
5519   [(set_attr "type" "ldsym")])
5520
5521 (define_split
5522   [(set (match_operand:DI 0 "register_operand" "")
5523         (match_operand:DI 1 "global_symbolic_operand" ""))]
5524   "TARGET_EXPLICIT_RELOCS && reload_completed"
5525   [(set (match_dup 0)
5526         (unspec:DI [(match_dup 2)
5527                     (match_dup 1)
5528                     (const_int 0)] UNSPEC_LITERAL))]
5529   "operands[2] = pic_offset_table_rtx;")
5530
5531 (define_insn "movdi_er_tlsgd"
5532   [(set (match_operand:DI 0 "register_operand" "=r")
5533         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
5534                     (match_operand:DI 2 "symbolic_operand" "")
5535                     (match_operand 3 "const_int_operand" "")]
5536                    UNSPEC_TLSGD))]
5537   "HAVE_AS_TLS"
5538 {
5539   if (INTVAL (operands[3]) == 0)
5540     return "lda %0,%2(%1)\t\t!tlsgd";
5541   else
5542     return "lda %0,%2(%1)\t\t!tlsgd!%3";
5543 })
5544
5545 (define_insn "movdi_er_tlsldm"
5546   [(set (match_operand:DI 0 "register_operand" "=r")
5547         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
5548                     (match_operand 2 "const_int_operand" "")]
5549                    UNSPEC_TLSLDM))]
5550   "HAVE_AS_TLS"
5551 {
5552   if (INTVAL (operands[2]) == 0)
5553     return "lda %0,%&(%1)\t\t!tlsldm";
5554   else
5555     return "lda %0,%&(%1)\t\t!tlsldm!%2";
5556 })
5557
5558 (define_insn "*movdi_er_gotdtp"
5559   [(set (match_operand:DI 0 "register_operand" "=r")
5560         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
5561                     (match_operand:DI 2 "symbolic_operand" "")]
5562                    UNSPEC_DTPREL))]
5563   "HAVE_AS_TLS"
5564   "ldq %0,%2(%1)\t\t!gotdtprel"
5565   [(set_attr "type" "ild")
5566    (set_attr "usegp" "yes")])
5567
5568 (define_split
5569   [(set (match_operand:DI 0 "register_operand" "")
5570         (match_operand:DI 1 "gotdtp_symbolic_operand" ""))]
5571   "HAVE_AS_TLS && reload_completed"
5572   [(set (match_dup 0)
5573         (unspec:DI [(match_dup 2)
5574                     (match_dup 1)] UNSPEC_DTPREL))]
5575 {
5576   operands[1] = XVECEXP (XEXP (operands[1], 0), 0, 0);
5577   operands[2] = pic_offset_table_rtx;
5578 })
5579
5580 (define_insn "*movdi_er_gottp"
5581   [(set (match_operand:DI 0 "register_operand" "=r")
5582         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
5583                     (match_operand:DI 2 "symbolic_operand" "")]
5584                    UNSPEC_TPREL))]
5585   "HAVE_AS_TLS"
5586   "ldq %0,%2(%1)\t\t!gottprel"
5587   [(set_attr "type" "ild")
5588    (set_attr "usegp" "yes")])
5589
5590 (define_split
5591   [(set (match_operand:DI 0 "register_operand" "")
5592         (match_operand:DI 1 "gottp_symbolic_operand" ""))]
5593   "HAVE_AS_TLS && reload_completed"
5594   [(set (match_dup 0)
5595         (unspec:DI [(match_dup 2)
5596                     (match_dup 1)] UNSPEC_TPREL))]
5597 {
5598   operands[1] = XVECEXP (XEXP (operands[1], 0), 0, 0);
5599   operands[2] = pic_offset_table_rtx;
5600 })
5601
5602 (define_insn "*movdi_er_nofix"
5603   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,r,r,r,r,m,*f,*f,Q")
5604         (match_operand:DI 1 "input_operand" "rJ,K,L,T,s,n,m,rJ,*fJ,Q,*f"))]
5605   "TARGET_EXPLICIT_RELOCS && ! TARGET_FIX
5606    && (register_operand (operands[0], DImode)
5607        || reg_or_0_operand (operands[1], DImode))"
5608   "@
5609    mov %r1,%0
5610    lda %0,%1($31)
5611    ldah %0,%h1($31)
5612    #
5613    #
5614    #
5615    ldq%A1 %0,%1
5616    stq%A0 %r1,%0
5617    fmov %R1,%0
5618    ldt %0,%1
5619    stt %R1,%0"
5620   [(set_attr "type" "ilog,iadd,iadd,iadd,ldsym,multi,ild,ist,fcpys,fld,fst")
5621    (set_attr "usegp" "*,*,*,yes,*,*,*,*,*,*,*")])
5622
5623 ;; The 'U' constraint matches symbolic operands on Unicos/Mk. Those should
5624 ;; have been split up by the rules above but we shouldn't reject the
5625 ;; possibility of them getting through.
5626
5627 (define_insn "*movdi_nofix"
5628   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,r,r,r,r,m,*f,*f,Q")
5629         (match_operand:DI 1 "input_operand" "rJ,K,L,U,s,n,m,rJ,*fJ,Q,*f"))]
5630   "! TARGET_FIX
5631    && (register_operand (operands[0], DImode)
5632        || reg_or_0_operand (operands[1], DImode))"
5633   "@
5634    bis $31,%r1,%0
5635    lda %0,%1($31)
5636    ldah %0,%h1($31)
5637    laum %0,%t1($31)\;sll %0,32,%0\;lalm %0,%t1(%0)\;lal %0,%t1(%0)
5638    lda %0,%1
5639    #
5640    ldq%A1 %0,%1
5641    stq%A0 %r1,%0
5642    cpys %R1,%R1,%0
5643    ldt %0,%1
5644    stt %R1,%0"
5645   [(set_attr "type" "ilog,iadd,iadd,ldsym,ldsym,multi,ild,ist,fcpys,fld,fst")
5646    (set_attr "length" "*,*,*,16,*,*,*,*,*,*,*")])
5647
5648 (define_insn "*movdi_er_fix"
5649   [(set (match_operand:DI 0 "nonimmediate_operand"
5650                                 "=r,r,r,r,r,r,r, m, *f,*f, Q, r,*f")
5651         (match_operand:DI 1 "input_operand"
5652                                 "rJ,K,L,T,s,n,m,rJ,*fJ, Q,*f,*f, r"))]
5653   "TARGET_EXPLICIT_RELOCS && TARGET_FIX
5654    && (register_operand (operands[0], DImode)
5655        || reg_or_0_operand (operands[1], DImode))"
5656   "@
5657    mov %r1,%0
5658    lda %0,%1($31)
5659    ldah %0,%h1($31)
5660    #
5661    #
5662    #
5663    ldq%A1 %0,%1
5664    stq%A0 %r1,%0
5665    fmov %R1,%0
5666    ldt %0,%1
5667    stt %R1,%0
5668    ftoit %1,%0
5669    itoft %1,%0"
5670   [(set_attr "type" "ilog,iadd,iadd,iadd,ldsym,multi,ild,ist,fcpys,fld,fst,ftoi,itof")
5671    (set_attr "usegp" "*,*,*,yes,*,*,*,*,*,*,*,*,*")])
5672
5673 (define_insn "*movdi_fix"
5674   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,r,r,r,m,*f,*f,Q,r,*f")
5675         (match_operand:DI 1 "input_operand" "rJ,K,L,s,n,m,rJ,*fJ,Q,*f,*f,r"))]
5676   "! TARGET_EXPLICIT_RELOCS && TARGET_FIX
5677    && (register_operand (operands[0], DImode)
5678        || reg_or_0_operand (operands[1], DImode))"
5679   "@
5680    bis $31,%r1,%0
5681    lda %0,%1($31)
5682    ldah %0,%h1($31)
5683    lda %0,%1
5684    #
5685    ldq%A1 %0,%1
5686    stq%A0 %r1,%0
5687    cpys %R1,%R1,%0
5688    ldt %0,%1
5689    stt %R1,%0
5690    ftoit %1,%0
5691    itoft %1,%0"
5692   [(set_attr "type" "ilog,iadd,iadd,ldsym,multi,ild,ist,fcpys,fld,fst,ftoi,itof")])
5693
5694 ;; VMS needs to set up "vms_base_regno" for unwinding.  This move
5695 ;; often appears dead to the life analysis code, at which point we
5696 ;; die for emitting dead prologue instructions.  Force this live.
5697
5698 (define_insn "force_movdi"
5699   [(set (match_operand:DI 0 "register_operand" "=r")
5700         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")]
5701                             UNSPECV_FORCE_MOV))]
5702   ""
5703   "mov %1,%0"
5704   [(set_attr "type" "ilog")])
5705
5706 ;; We do three major things here: handle mem->mem, put 64-bit constants in
5707 ;; memory, and construct long 32-bit constants.
5708
5709 (define_expand "movdi"
5710   [(set (match_operand:DI 0 "nonimmediate_operand" "")
5711         (match_operand:DI 1 "general_operand" ""))]
5712   ""
5713 {
5714   if (alpha_expand_mov (DImode, operands))
5715     DONE;
5716 })
5717
5718 ;; Split a load of a large constant into the appropriate two-insn
5719 ;; sequence.
5720
5721 (define_split
5722   [(set (match_operand:DI 0 "register_operand" "")
5723         (match_operand:DI 1 "non_add_const_operand" ""))]
5724   ""
5725   [(const_int 0)]
5726 {
5727   if (alpha_split_const_mov (DImode, operands))
5728     DONE;
5729   else
5730     FAIL;
5731 })
5732
5733 ;; We need to prevent reload from splitting TImode moves, because it
5734 ;; might decide to overwrite a pointer with the value it points to.
5735 ;; In that case we have to do the loads in the appropriate order so
5736 ;; that the pointer is not destroyed too early.
5737
5738 (define_insn_and_split "*movti_internal"
5739   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o")
5740         (match_operand:TI 1 "input_operand" "roJ,rJ"))]
5741   "(register_operand (operands[0], TImode)
5742     /* Prevent rematerialization of constants.  */
5743     && ! CONSTANT_P (operands[1]))
5744    || reg_or_0_operand (operands[1], TImode)"
5745   "#"
5746   "reload_completed"
5747   [(set (match_dup 0) (match_dup 2))
5748    (set (match_dup 1) (match_dup 3))]
5749 {
5750   alpha_split_tmode_pair (operands, TImode, true);
5751 })
5752
5753 (define_expand "movti"
5754   [(set (match_operand:TI 0 "nonimmediate_operand" "")
5755         (match_operand:TI 1 "general_operand" ""))]
5756   ""
5757 {
5758   if (GET_CODE (operands[0]) == MEM
5759       && ! reg_or_0_operand (operands[1], TImode))
5760     operands[1] = force_reg (TImode, operands[1]);
5761
5762   if (operands[1] == const0_rtx)
5763     ;
5764   /* We must put 64-bit constants in memory.  We could keep the
5765      32-bit constants in TImode and rely on the splitter, but
5766      this doesn't seem to be worth the pain.  */
5767   else if (GET_CODE (operands[1]) == CONST_INT
5768            || GET_CODE (operands[1]) == CONST_DOUBLE)
5769     {
5770       rtx in[2], out[2], target;
5771
5772       gcc_assert (!no_new_pseudos);
5773
5774       split_double (operands[1], &in[0], &in[1]);
5775
5776       if (in[0] == const0_rtx)
5777         out[0] = const0_rtx;
5778       else
5779         {
5780           out[0] = gen_reg_rtx (DImode);
5781           emit_insn (gen_movdi (out[0], in[0]));
5782         }
5783
5784       if (in[1] == const0_rtx)
5785         out[1] = const0_rtx;
5786       else
5787         {
5788           out[1] = gen_reg_rtx (DImode);
5789           emit_insn (gen_movdi (out[1], in[1]));
5790         }
5791
5792       if (GET_CODE (operands[0]) != REG)
5793         target = gen_reg_rtx (TImode);
5794       else
5795         target = operands[0];
5796
5797       emit_insn (gen_movdi (gen_rtx_SUBREG (DImode, target, 0), out[0]));
5798       emit_insn (gen_movdi (gen_rtx_SUBREG (DImode, target, 8), out[1]));
5799
5800       if (target != operands[0])
5801         emit_insn (gen_rtx_SET (VOIDmode, operands[0], target));
5802
5803       DONE;
5804     }
5805 })
5806
5807 ;; These are the partial-word cases.
5808 ;;
5809 ;; First we have the code to load an aligned word.  Operand 0 is the register
5810 ;; in which to place the result.  It's mode is QImode or HImode.  Operand 1
5811 ;; is an SImode MEM at the low-order byte of the proper word.  Operand 2 is the
5812 ;; number of bits within the word that the value is.  Operand 3 is an SImode
5813 ;; scratch register.  If operand 0 is a hard register, operand 3 may be the
5814 ;; same register.  It is allowed to conflict with operand 1 as well.
5815
5816 (define_expand "aligned_loadqi"
5817   [(set (match_operand:SI 3 "register_operand" "")
5818         (match_operand:SI 1 "memory_operand" ""))
5819    (set (match_operand:DI 0 "register_operand" "")
5820         (zero_extract:DI (subreg:DI (match_dup 3) 0)
5821                          (const_int 8)
5822                          (match_operand:DI 2 "const_int_operand" "")))]
5823
5824   ""
5825   "")
5826
5827 (define_expand "aligned_loadhi"
5828   [(set (match_operand:SI 3 "register_operand" "")
5829         (match_operand:SI 1 "memory_operand" ""))
5830    (set (match_operand:DI 0 "register_operand" "")
5831         (zero_extract:DI (subreg:DI (match_dup 3) 0)
5832                          (const_int 16)
5833                          (match_operand:DI 2 "const_int_operand" "")))]
5834
5835   ""
5836   "")
5837
5838 ;; Similar for unaligned loads, where we use the sequence from the
5839 ;; Alpha Architecture manual. We have to distinguish between little-endian
5840 ;; and big-endian systems as the sequences are different.
5841 ;;
5842 ;; Operand 1 is the address.  Operands 2 and 3 are temporaries, where
5843 ;; operand 3 can overlap the input and output registers.
5844
5845 (define_expand "unaligned_loadqi"
5846   [(use (match_operand:DI 0 "register_operand" ""))
5847    (use (match_operand:DI 1 "address_operand" ""))
5848    (use (match_operand:DI 2 "register_operand" ""))
5849    (use (match_operand:DI 3 "register_operand" ""))]
5850   ""
5851 {
5852   if (WORDS_BIG_ENDIAN)
5853     emit_insn (gen_unaligned_loadqi_be (operands[0], operands[1],
5854                                         operands[2], operands[3]));
5855   else
5856     emit_insn (gen_unaligned_loadqi_le (operands[0], operands[1],
5857                                         operands[2], operands[3]));
5858   DONE;
5859 })
5860
5861 (define_expand "unaligned_loadqi_le"
5862   [(set (match_operand:DI 2 "register_operand" "")
5863         (mem:DI (and:DI (match_operand:DI 1 "address_operand" "")
5864                         (const_int -8))))
5865    (set (match_operand:DI 3 "register_operand" "")
5866         (match_dup 1))
5867    (set (match_operand:DI 0 "register_operand" "")
5868         (zero_extract:DI (match_dup 2)
5869                          (const_int 8)
5870                          (ashift:DI (match_dup 3) (const_int 3))))]
5871   "! WORDS_BIG_ENDIAN"
5872   "")
5873
5874 (define_expand "unaligned_loadqi_be"
5875   [(set (match_operand:DI 2 "register_operand" "")
5876         (mem:DI (and:DI (match_operand:DI 1 "address_operand" "")
5877                         (const_int -8))))
5878    (set (match_operand:DI 3 "register_operand" "")
5879         (match_dup 1))
5880    (set (match_operand:DI 0 "register_operand" "")
5881         (zero_extract:DI (match_dup 2)
5882                          (const_int 8)
5883                          (minus:DI
5884                            (const_int 56)
5885                            (ashift:DI (match_dup 3) (const_int 3)))))]
5886   "WORDS_BIG_ENDIAN"
5887   "")
5888
5889 (define_expand "unaligned_loadhi"
5890   [(use (match_operand:DI 0 "register_operand" ""))
5891    (use (match_operand:DI 1 "address_operand" ""))
5892    (use (match_operand:DI 2 "register_operand" ""))
5893    (use (match_operand:DI 3 "register_operand" ""))]
5894   ""
5895 {
5896   if (WORDS_BIG_ENDIAN)
5897     emit_insn (gen_unaligned_loadhi_be (operands[0], operands[1],
5898                                         operands[2], operands[3]));
5899   else
5900     emit_insn (gen_unaligned_loadhi_le (operands[0], operands[1],
5901                                         operands[2], operands[3]));
5902   DONE;
5903 })
5904
5905 (define_expand "unaligned_loadhi_le"
5906   [(set (match_operand:DI 2 "register_operand" "")
5907         (mem:DI (and:DI (match_operand:DI 1 "address_operand" "")
5908                         (const_int -8))))
5909    (set (match_operand:DI 3 "register_operand" "")
5910         (match_dup 1))
5911    (set (match_operand:DI 0 "register_operand" "")
5912         (zero_extract:DI (match_dup 2)
5913                          (const_int 16)
5914                          (ashift:DI (match_dup 3) (const_int 3))))]
5915   "! WORDS_BIG_ENDIAN"
5916   "")
5917
5918 (define_expand "unaligned_loadhi_be"
5919   [(set (match_operand:DI 2 "register_operand" "")
5920         (mem:DI (and:DI (match_operand:DI 1 "address_operand" "")
5921                         (const_int -8))))
5922    (set (match_operand:DI 3 "register_operand" "")
5923         (plus:DI (match_dup 1) (const_int 1)))
5924    (set (match_operand:DI 0 "register_operand" "")
5925         (zero_extract:DI (match_dup 2)
5926                          (const_int 16)
5927                          (minus:DI
5928                            (const_int 56)
5929                            (ashift:DI (match_dup 3) (const_int 3)))))]
5930   "WORDS_BIG_ENDIAN"
5931   "")
5932
5933 ;; Storing an aligned byte or word requires two temporaries.  Operand 0 is the
5934 ;; aligned SImode MEM.  Operand 1 is the register containing the
5935 ;; byte or word to store.  Operand 2 is the number of bits within the word that
5936 ;; the value should be placed.  Operands 3 and 4 are SImode temporaries.
5937
5938 (define_expand "aligned_store"
5939   [(set (match_operand:SI 3 "register_operand" "")
5940         (match_operand:SI 0 "memory_operand" ""))
5941    (set (subreg:DI (match_dup 3) 0)
5942         (and:DI (subreg:DI (match_dup 3) 0) (match_dup 5)))
5943    (set (subreg:DI (match_operand:SI 4 "register_operand" "") 0)
5944         (ashift:DI (zero_extend:DI (match_operand 1 "register_operand" ""))
5945                    (match_operand:DI 2 "const_int_operand" "")))
5946    (set (subreg:DI (match_dup 4) 0)
5947         (ior:DI (subreg:DI (match_dup 4) 0) (subreg:DI (match_dup 3) 0)))
5948    (set (match_dup 0) (match_dup 4))]
5949   ""
5950 {
5951   operands[5] = GEN_INT (~ (GET_MODE_MASK (GET_MODE (operands[1]))
5952                             << INTVAL (operands[2])));
5953 })
5954
5955 ;; For the unaligned byte and halfword cases, we use code similar to that
5956 ;; in the ;; Architecture book, but reordered to lower the number of registers
5957 ;; required.  Operand 0 is the address.  Operand 1 is the data to store.
5958 ;; Operands 2, 3, and 4 are DImode temporaries, where operands 2 and 4 may
5959 ;; be the same temporary, if desired.  If the address is in a register,
5960 ;; operand 2 can be that register.
5961
5962 (define_expand "unaligned_storeqi"
5963   [(use (match_operand:DI 0 "address_operand" ""))
5964    (use (match_operand:QI 1 "register_operand" ""))
5965    (use (match_operand:DI 2 "register_operand" ""))
5966    (use (match_operand:DI 3 "register_operand" ""))
5967    (use (match_operand:DI 4 "register_operand" ""))]
5968   ""
5969 {
5970   if (WORDS_BIG_ENDIAN)
5971     emit_insn (gen_unaligned_storeqi_be (operands[0], operands[1],
5972                                          operands[2], operands[3],
5973                                          operands[4]));
5974   else
5975     emit_insn (gen_unaligned_storeqi_le (operands[0], operands[1],
5976                                          operands[2], operands[3],
5977                                          operands[4]));
5978   DONE;
5979 })
5980
5981 (define_expand "unaligned_storeqi_le"
5982   [(set (match_operand:DI 3 "register_operand" "")
5983         (mem:DI (and:DI (match_operand:DI 0 "address_operand" "")
5984                         (const_int -8))))
5985    (set (match_operand:DI 2 "register_operand" "")
5986         (match_dup 0))
5987    (set (match_dup 3)
5988         (and:DI (not:DI (ashift:DI (const_int 255)
5989                                    (ashift:DI (match_dup 2) (const_int 3))))
5990                 (match_dup 3)))
5991    (set (match_operand:DI 4 "register_operand" "")
5992         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" ""))
5993                    (ashift:DI (match_dup 2) (const_int 3))))
5994    (set (match_dup 4) (ior:DI (match_dup 4) (match_dup 3)))
5995    (set (mem:DI (and:DI (match_dup 0) (const_int -8)))
5996         (match_dup 4))]
5997   "! WORDS_BIG_ENDIAN"
5998   "")
5999
6000 (define_expand "unaligned_storeqi_be"
6001   [(set (match_operand:DI 3 "register_operand" "")
6002         (mem:DI (and:DI (match_operand:DI 0 "address_operand" "")
6003                         (const_int -8))))
6004    (set (match_operand:DI 2 "register_operand" "")
6005         (match_dup 0))
6006    (set (match_dup 3)
6007         (and:DI (not:DI (ashift:DI (const_int 255)
6008                           (minus:DI (const_int 56)
6009                                     (ashift:DI (match_dup 2) (const_int 3)))))
6010                 (match_dup 3)))
6011    (set (match_operand:DI 4 "register_operand" "")
6012         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" ""))
6013                    (minus:DI (const_int 56)
6014                      (ashift:DI (match_dup 2) (const_int 3)))))
6015    (set (match_dup 4) (ior:DI (match_dup 4) (match_dup 3)))
6016    (set (mem:DI (and:DI (match_dup 0) (const_int -8)))
6017         (match_dup 4))]
6018   "WORDS_BIG_ENDIAN"
6019   "")
6020
6021 (define_expand "unaligned_storehi"
6022   [(use (match_operand:DI 0 "address_operand" ""))
6023    (use (match_operand:HI 1 "register_operand" ""))
6024    (use (match_operand:DI 2 "register_operand" ""))
6025    (use (match_operand:DI 3 "register_operand" ""))
6026    (use (match_operand:DI 4 "register_operand" ""))]
6027   ""
6028 {
6029   if (WORDS_BIG_ENDIAN)
6030     emit_insn (gen_unaligned_storehi_be (operands[0], operands[1],
6031                                          operands[2], operands[3],
6032                                          operands[4]));
6033   else
6034     emit_insn (gen_unaligned_storehi_le (operands[0], operands[1],
6035                                          operands[2], operands[3],
6036                                          operands[4]));
6037   DONE;
6038 })
6039
6040 (define_expand "unaligned_storehi_le"
6041   [(set (match_operand:DI 3 "register_operand" "")
6042         (mem:DI (and:DI (match_operand:DI 0 "address_operand" "")
6043                         (const_int -8))))
6044    (set (match_operand:DI 2 "register_operand" "")
6045         (match_dup 0))
6046    (set (match_dup 3)
6047         (and:DI (not:DI (ashift:DI (const_int 65535)
6048                                    (ashift:DI (match_dup 2) (const_int 3))))
6049                 (match_dup 3)))
6050    (set (match_operand:DI 4 "register_operand" "")
6051         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" ""))
6052                    (ashift:DI (match_dup 2) (const_int 3))))
6053    (set (match_dup 4) (ior:DI (match_dup 4) (match_dup 3)))
6054    (set (mem:DI (and:DI (match_dup 0) (const_int -8)))
6055         (match_dup 4))]
6056   "! WORDS_BIG_ENDIAN"
6057   "")
6058
6059 (define_expand "unaligned_storehi_be"
6060   [(set (match_operand:DI 3 "register_operand" "")
6061         (mem:DI (and:DI (match_operand:DI 0 "address_operand" "")
6062                         (const_int -8))))
6063    (set (match_operand:DI 2 "register_operand" "")
6064         (plus:DI (match_dup 0) (const_int 1)))
6065    (set (match_dup 3)
6066         (and:DI (not:DI (ashift:DI
6067                           (const_int 65535)
6068                           (minus:DI (const_int 56)
6069                                     (ashift:DI (match_dup 2) (const_int 3)))))
6070                 (match_dup 3)))
6071    (set (match_operand:DI 4 "register_operand" "")
6072         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" ""))
6073                    (minus:DI (const_int 56)
6074                              (ashift:DI (match_dup 2) (const_int 3)))))
6075    (set (match_dup 4) (ior:DI (match_dup 4) (match_dup 3)))
6076    (set (mem:DI (and:DI (match_dup 0) (const_int -8)))
6077         (match_dup 4))]
6078   "WORDS_BIG_ENDIAN"
6079   "")
6080 \f
6081 ;; Here are the define_expand's for QI and HI moves that use the above
6082 ;; patterns.  We have the normal sets, plus the ones that need scratch
6083 ;; registers for reload.
6084
6085 (define_expand "movqi"
6086   [(set (match_operand:QI 0 "nonimmediate_operand" "")
6087         (match_operand:QI 1 "general_operand" ""))]
6088   ""
6089 {
6090   if (TARGET_BWX
6091       ? alpha_expand_mov (QImode, operands)
6092       : alpha_expand_mov_nobwx (QImode, operands))
6093     DONE;
6094 })
6095
6096 (define_expand "movhi"
6097   [(set (match_operand:HI 0 "nonimmediate_operand" "")
6098         (match_operand:HI 1 "general_operand" ""))]
6099   ""
6100 {
6101   if (TARGET_BWX
6102       ? alpha_expand_mov (HImode, operands)
6103       : alpha_expand_mov_nobwx (HImode, operands))
6104     DONE;
6105 })
6106
6107 ;; Here are the versions for reload.  Note that in the unaligned cases
6108 ;; we know that the operand must not be a pseudo-register because stack
6109 ;; slots are always aligned references.
6110
6111 (define_expand "reload_inqi"
6112   [(parallel [(match_operand:QI 0 "register_operand" "=r")
6113               (match_operand:QI 1 "any_memory_operand" "m")
6114               (match_operand:TI 2 "register_operand" "=&r")])]
6115   "! TARGET_BWX"
6116 {
6117   rtx scratch, seq;
6118
6119   if (aligned_memory_operand (operands[1], QImode))
6120     {
6121       seq = gen_reload_inqi_help (operands[0], operands[1],
6122                                   gen_rtx_REG (SImode, REGNO (operands[2])));
6123     }
6124   else
6125     {
6126       rtx addr;
6127
6128       /* It is possible that one of the registers we got for operands[2]
6129          might coincide with that of operands[0] (which is why we made
6130          it TImode).  Pick the other one to use as our scratch.  */
6131       if (REGNO (operands[0]) == REGNO (operands[2]))
6132         scratch = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
6133       else
6134         scratch = gen_rtx_REG (DImode, REGNO (operands[2]));
6135
6136       addr = get_unaligned_address (operands[1], 0);
6137       operands[0] = gen_rtx_REG (DImode, REGNO (operands[0]));
6138       seq = gen_unaligned_loadqi (operands[0], addr, scratch, operands[0]);
6139       alpha_set_memflags (seq, operands[1]);
6140     }
6141   emit_insn (seq);
6142   DONE;
6143 })
6144
6145 (define_expand "reload_inhi"
6146   [(parallel [(match_operand:HI 0 "register_operand" "=r")
6147               (match_operand:HI 1 "any_memory_operand" "m")
6148               (match_operand:TI 2 "register_operand" "=&r")])]
6149   "! TARGET_BWX"
6150 {
6151   rtx scratch, seq;
6152
6153   if (aligned_memory_operand (operands[1], HImode))
6154     {
6155       seq = gen_reload_inhi_help (operands[0], operands[1],
6156                                   gen_rtx_REG (SImode, REGNO (operands[2])));
6157     }
6158   else
6159     {
6160       rtx addr;
6161
6162       /* It is possible that one of the registers we got for operands[2]
6163          might coincide with that of operands[0] (which is why we made
6164          it TImode).  Pick the other one to use as our scratch.  */
6165       if (REGNO (operands[0]) == REGNO (operands[2]))
6166         scratch = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
6167       else
6168         scratch = gen_rtx_REG (DImode, REGNO (operands[2]));
6169
6170       addr = get_unaligned_address (operands[1], 0);
6171       operands[0] = gen_rtx_REG (DImode, REGNO (operands[0]));
6172       seq = gen_unaligned_loadhi (operands[0], addr, scratch, operands[0]);
6173       alpha_set_memflags (seq, operands[1]);
6174     }
6175   emit_insn (seq);
6176   DONE;
6177 })
6178
6179 (define_expand "reload_outqi"
6180   [(parallel [(match_operand:QI 0 "any_memory_operand" "=m")
6181               (match_operand:QI 1 "register_operand" "r")
6182               (match_operand:TI 2 "register_operand" "=&r")])]
6183   "! TARGET_BWX"
6184 {
6185   if (aligned_memory_operand (operands[0], QImode))
6186     {
6187       emit_insn (gen_reload_outqi_help
6188                  (operands[0], operands[1],
6189                   gen_rtx_REG (SImode, REGNO (operands[2])),
6190                   gen_rtx_REG (SImode, REGNO (operands[2]) + 1)));
6191     }
6192   else
6193     {
6194       rtx addr = get_unaligned_address (operands[0], 0);
6195       rtx scratch1 = gen_rtx_REG (DImode, REGNO (operands[2]));
6196       rtx scratch2 = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
6197       rtx scratch3 = scratch1;
6198       rtx seq;
6199
6200       if (GET_CODE (addr) == REG)
6201         scratch1 = addr;
6202
6203       seq = gen_unaligned_storeqi (addr, operands[1], scratch1,
6204                                    scratch2, scratch3);
6205       alpha_set_memflags (seq, operands[0]);
6206       emit_insn (seq);
6207     }
6208   DONE;
6209 })
6210
6211 (define_expand "reload_outhi"
6212   [(parallel [(match_operand:HI 0 "any_memory_operand" "=m")
6213               (match_operand:HI 1 "register_operand" "r")
6214               (match_operand:TI 2 "register_operand" "=&r")])]
6215   "! TARGET_BWX"
6216 {
6217   if (aligned_memory_operand (operands[0], HImode))
6218     {
6219       emit_insn (gen_reload_outhi_help
6220                  (operands[0], operands[1],
6221                   gen_rtx_REG (SImode, REGNO (operands[2])),
6222                   gen_rtx_REG (SImode, REGNO (operands[2]) + 1)));
6223     }
6224   else
6225     {
6226       rtx addr = get_unaligned_address (operands[0], 0);
6227       rtx scratch1 = gen_rtx_REG (DImode, REGNO (operands[2]));
6228       rtx scratch2 = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
6229       rtx scratch3 = scratch1;
6230       rtx seq;
6231
6232       if (GET_CODE (addr) == REG)
6233         scratch1 = addr;
6234
6235       seq = gen_unaligned_storehi (addr, operands[1], scratch1,
6236                                    scratch2, scratch3);
6237       alpha_set_memflags (seq, operands[0]);
6238       emit_insn (seq);
6239     }
6240   DONE;
6241 })
6242
6243 ;; Helpers for the above.  The way reload is structured, we can't
6244 ;; always get a proper address for a stack slot during reload_foo
6245 ;; expansion, so we must delay our address manipulations until after.
6246
6247 (define_insn_and_split "reload_inqi_help"
6248   [(set (match_operand:QI 0 "register_operand" "=r")
6249         (match_operand:QI 1 "memory_operand" "m"))
6250    (clobber (match_operand:SI 2 "register_operand" "=r"))]
6251   "! TARGET_BWX && (reload_in_progress || reload_completed)"
6252   "#"
6253   "! TARGET_BWX && reload_completed"
6254   [(const_int 0)]
6255 {
6256   rtx aligned_mem, bitnum;
6257   get_aligned_mem (operands[1], &aligned_mem, &bitnum);
6258   operands[0] = gen_lowpart (DImode, operands[0]);
6259   emit_insn (gen_aligned_loadqi (operands[0], aligned_mem, bitnum,
6260                                  operands[2]));
6261   DONE;
6262 })
6263
6264 (define_insn_and_split "reload_inhi_help"
6265   [(set (match_operand:HI 0 "register_operand" "=r")
6266         (match_operand:HI 1 "memory_operand" "m"))
6267    (clobber (match_operand:SI 2 "register_operand" "=r"))]
6268   "! TARGET_BWX && (reload_in_progress || reload_completed)"
6269   "#"
6270   "! TARGET_BWX && reload_completed"
6271   [(const_int 0)]
6272 {
6273   rtx aligned_mem, bitnum;
6274   get_aligned_mem (operands[1], &aligned_mem, &bitnum);
6275   operands[0] = gen_lowpart (DImode, operands[0]);
6276   emit_insn (gen_aligned_loadhi (operands[0], aligned_mem, bitnum,
6277                                  operands[2]));
6278   DONE;
6279 })
6280
6281 (define_insn_and_split "reload_outqi_help"
6282   [(set (match_operand:QI 0 "memory_operand" "=m")
6283         (match_operand:QI 1 "register_operand" "r"))
6284    (clobber (match_operand:SI 2 "register_operand" "=r"))
6285    (clobber (match_operand:SI 3 "register_operand" "=r"))]
6286   "! TARGET_BWX && (reload_in_progress || reload_completed)"
6287   "#"
6288   "! TARGET_BWX && reload_completed"
6289   [(const_int 0)]
6290 {
6291   rtx aligned_mem, bitnum;
6292   get_aligned_mem (operands[0], &aligned_mem, &bitnum);
6293   emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
6294                                 operands[2], operands[3]));
6295   DONE;
6296 })
6297
6298 (define_insn_and_split "reload_outhi_help"
6299   [(set (match_operand:HI 0 "memory_operand" "=m")
6300         (match_operand:HI 1 "register_operand" "r"))
6301    (clobber (match_operand:SI 2 "register_operand" "=r"))
6302    (clobber (match_operand:SI 3 "register_operand" "=r"))]
6303   "! TARGET_BWX && (reload_in_progress || reload_completed)"
6304   "#"
6305   "! TARGET_BWX && reload_completed"
6306   [(const_int 0)]
6307 {
6308   rtx aligned_mem, bitnum;
6309   get_aligned_mem (operands[0], &aligned_mem, &bitnum);
6310   emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
6311                                 operands[2], operands[3]));
6312   DONE;
6313 })
6314 \f
6315 ;; Vector operations
6316
6317 (define_mode_macro VEC [V8QI V4HI V2SI])
6318
6319 (define_expand "mov<mode>"
6320   [(set (match_operand:VEC 0 "nonimmediate_operand" "")
6321         (match_operand:VEC 1 "general_operand" ""))]
6322   ""
6323 {
6324   if (alpha_expand_mov (<MODE>mode, operands))
6325     DONE;
6326 })
6327
6328 (define_split
6329   [(set (match_operand:VEC 0 "register_operand" "")
6330         (match_operand:VEC 1 "non_zero_const_operand" ""))]
6331   ""
6332   [(const_int 0)]
6333 {
6334   if (alpha_split_const_mov (<MODE>mode, operands))
6335     DONE;
6336   else
6337     FAIL;
6338 })
6339
6340
6341 (define_expand "movmisalign<mode>"
6342   [(set (match_operand:VEC 0 "nonimmediate_operand" "")
6343         (match_operand:VEC 1 "general_operand" ""))]
6344   ""
6345 {
6346   alpha_expand_movmisalign (<MODE>mode, operands);
6347   DONE;
6348 })
6349
6350 (define_insn "*mov<mode>_fix"
6351   [(set (match_operand:VEC 0 "nonimmediate_operand" "=r,r,r,m,*f,*f,m,r,*f")
6352         (match_operand:VEC 1 "input_operand" "rW,i,m,rW,*fW,m,*f,*f,r"))]
6353   "TARGET_FIX
6354    && (register_operand (operands[0], <MODE>mode)
6355        || reg_or_0_operand (operands[1], <MODE>mode))"
6356   "@
6357    bis $31,%r1,%0
6358    #
6359    ldq %0,%1
6360    stq %r1,%0
6361    cpys %R1,%R1,%0
6362    ldt %0,%1
6363    stt %R1,%0
6364    ftoit %1,%0
6365    itoft %1,%0"
6366   [(set_attr "type" "ilog,multi,ild,ist,fcpys,fld,fst,ftoi,itof")])
6367
6368 (define_insn "*mov<mode>_nofix"
6369   [(set (match_operand:VEC 0 "nonimmediate_operand" "=r,r,r,m,*f,*f,m")
6370         (match_operand:VEC 1 "input_operand" "rW,i,m,rW,*fW,m,*f"))]
6371   "! TARGET_FIX
6372    && (register_operand (operands[0], <MODE>mode)
6373        || reg_or_0_operand (operands[1], <MODE>mode))"
6374   "@
6375    bis $31,%r1,%0
6376    #
6377    ldq %0,%1
6378    stq %r1,%0
6379    cpys %R1,%R1,%0
6380    ldt %0,%1
6381    stt %R1,%0"
6382   [(set_attr "type" "ilog,multi,ild,ist,fcpys,fld,fst")])
6383
6384 (define_insn "uminv8qi3"
6385   [(set (match_operand:V8QI 0 "register_operand" "=r")
6386         (umin:V8QI (match_operand:V8QI 1 "reg_or_0_operand" "rW")
6387                    (match_operand:V8QI 2 "reg_or_0_operand" "rW")))]
6388   "TARGET_MAX"
6389   "minub8 %r1,%r2,%0"
6390   [(set_attr "type" "mvi")])
6391
6392 (define_insn "sminv8qi3"
6393   [(set (match_operand:V8QI 0 "register_operand" "=r")
6394         (smin:V8QI (match_operand:V8QI 1 "reg_or_0_operand" "rW")
6395                    (match_operand:V8QI 2 "reg_or_0_operand" "rW")))]
6396   "TARGET_MAX"
6397   "minsb8 %r1,%r2,%0"
6398   [(set_attr "type" "mvi")])
6399
6400 (define_insn "uminv4hi3"
6401   [(set (match_operand:V4HI 0 "register_operand" "=r")
6402         (umin:V4HI (match_operand:V4HI 1 "reg_or_0_operand" "rW")
6403                    (match_operand:V4HI 2 "reg_or_0_operand" "rW")))]
6404   "TARGET_MAX"
6405   "minuw4 %r1,%r2,%0"
6406   [(set_attr "type" "mvi")])
6407
6408 (define_insn "sminv4hi3"
6409   [(set (match_operand:V4HI 0 "register_operand" "=r")
6410         (smin:V4HI (match_operand:V4HI 1 "reg_or_0_operand" "rW")
6411                    (match_operand:V4HI 2 "reg_or_0_operand" "rW")))]
6412   "TARGET_MAX"
6413   "minsw4 %r1,%r2,%0"
6414   [(set_attr "type" "mvi")])
6415
6416 (define_insn "umaxv8qi3"
6417   [(set (match_operand:V8QI 0 "register_operand" "=r")
6418         (umax:V8QI (match_operand:V8QI 1 "reg_or_0_operand" "rW")
6419                    (match_operand:V8QI 2 "reg_or_0_operand" "rW")))]
6420   "TARGET_MAX"
6421   "maxub8 %r1,%r2,%0"
6422   [(set_attr "type" "mvi")])
6423
6424 (define_insn "smaxv8qi3"
6425   [(set (match_operand:V8QI 0 "register_operand" "=r")
6426         (smax:V8QI (match_operand:V8QI 1 "reg_or_0_operand" "rW")
6427                    (match_operand:V8QI 2 "reg_or_0_operand" "rW")))]
6428   "TARGET_MAX"
6429   "maxsb8 %r1,%r2,%0"
6430   [(set_attr "type" "mvi")])
6431
6432 (define_insn "umaxv4hi3"
6433   [(set (match_operand:V4HI 0 "register_operand" "=r")
6434         (umax:V4HI (match_operand:V4HI 1 "reg_or_0_operand" "rW")
6435                    (match_operand:V4HI 2 "reg_or_0_operand" "rW")))]
6436   "TARGET_MAX"
6437   "maxuw4 %r1,%r2,%0"
6438   [(set_attr "type" "mvi")])
6439
6440 (define_insn "smaxv4hi3"
6441   [(set (match_operand:V4HI 0 "register_operand" "=r")
6442         (smax:V4HI (match_operand:V4HI 1 "reg_or_0_operand" "rW")
6443                    (match_operand:V4HI 2 "reg_or_0_operand" "rW")))]
6444   "TARGET_MAX"
6445   "maxsw4 %r1,%r2,%0"
6446   [(set_attr "type" "mvi")])
6447
6448 (define_insn "one_cmpl<mode>2"
6449   [(set (match_operand:VEC 0 "register_operand" "=r")
6450         (not:VEC (match_operand:VEC 1 "register_operand" "r")))]
6451   ""
6452   "ornot $31,%1,%0"
6453   [(set_attr "type" "ilog")])
6454
6455 (define_insn "and<mode>3"
6456   [(set (match_operand:VEC 0 "register_operand" "=r")
6457         (and:VEC (match_operand:VEC 1 "register_operand" "r")
6458                  (match_operand:VEC 2 "register_operand" "r")))]
6459   ""
6460   "and %1,%2,%0"
6461   [(set_attr "type" "ilog")])
6462
6463 (define_insn "*andnot<mode>3"
6464   [(set (match_operand:VEC 0 "register_operand" "=r")
6465         (and:VEC (not:VEC (match_operand:VEC 1 "register_operand" "r"))
6466                  (match_operand:VEC 2 "register_operand" "r")))]
6467   ""
6468   "bic %2,%1,%0"
6469   [(set_attr "type" "ilog")])
6470
6471 (define_insn "ior<mode>3"
6472   [(set (match_operand:VEC 0 "register_operand" "=r")
6473         (ior:VEC (match_operand:VEC 1 "register_operand" "r")
6474                  (match_operand:VEC 2 "register_operand" "r")))]
6475   ""
6476   "bis %1,%2,%0"
6477   [(set_attr "type" "ilog")])
6478
6479 (define_insn "*iornot<mode>3"
6480   [(set (match_operand:VEC 0 "register_operand" "=r")
6481         (ior:VEC (not:DI (match_operand:VEC 1 "register_operand" "r"))
6482                  (match_operand:VEC 2 "register_operand" "r")))]
6483   ""
6484   "ornot %2,%1,%0"
6485   [(set_attr "type" "ilog")])
6486
6487 (define_insn "xor<mode>3"
6488   [(set (match_operand:VEC 0 "register_operand" "=r")
6489         (xor:VEC (match_operand:VEC 1 "register_operand" "r")
6490                  (match_operand:VEC 2 "register_operand" "r")))]
6491   ""
6492   "xor %1,%2,%0"
6493   [(set_attr "type" "ilog")])
6494
6495 (define_insn "*xornot<mode>3"
6496   [(set (match_operand:VEC 0 "register_operand" "=r")
6497         (not:VEC (xor:VEC (match_operand:VEC 1 "register_operand" "r")
6498                           (match_operand:VEC 2 "register_operand" "r"))))]
6499   ""
6500   "eqv %1,%2,%0"
6501   [(set_attr "type" "ilog")])
6502
6503 (define_expand "vec_shl_<mode>"
6504   [(set (match_operand:VEC 0 "register_operand" "")
6505         (ashift:DI (match_operand:VEC 1 "register_operand" "")
6506                    (match_operand:DI 2 "reg_or_6bit_operand" "")))]
6507   ""
6508 {
6509   operands[0] = gen_lowpart (DImode, operands[0]);
6510   operands[1] = gen_lowpart (DImode, operands[1]);
6511 })
6512
6513 (define_expand "vec_shr_<mode>"
6514   [(set (match_operand:VEC 0 "register_operand" "")
6515         (lshiftrt:DI (match_operand:VEC 1 "register_operand" "")
6516                      (match_operand:DI 2 "reg_or_6bit_operand" "")))]
6517   ""
6518 {
6519   operands[0] = gen_lowpart (DImode, operands[0]);
6520   operands[1] = gen_lowpart (DImode, operands[1]);
6521 })
6522 \f
6523 ;; Bit field extract patterns which use ext[wlq][lh]
6524
6525 (define_expand "extv"
6526   [(set (match_operand:DI 0 "register_operand" "")
6527         (sign_extract:DI (match_operand:QI 1 "memory_operand" "")
6528                          (match_operand:DI 2 "immediate_operand" "")
6529                          (match_operand:DI 3 "immediate_operand" "")))]
6530   ""
6531 {
6532   int ofs;
6533
6534   /* We can do 16, 32 and 64 bit fields, if aligned on byte boundaries.  */
6535   if (INTVAL (operands[3]) % 8 != 0
6536       || (INTVAL (operands[2]) != 16
6537           && INTVAL (operands[2]) != 32
6538           && INTVAL (operands[2]) != 64))
6539     FAIL;
6540
6541   /* From mips.md: extract_bit_field doesn't verify that our source
6542      matches the predicate, so we force it to be a MEM here.  */
6543   if (GET_CODE (operands[1]) != MEM)
6544     FAIL;
6545
6546   /* The bit number is relative to the mode of operand 1 which is
6547      usually QImode (this might actually be a bug in expmed.c). Note 
6548      that the bit number is negative in big-endian mode in this case.
6549      We have to convert that to the offset.  */
6550   if (WORDS_BIG_ENDIAN)
6551     ofs = GET_MODE_BITSIZE (GET_MODE (operands[1]))
6552           - INTVAL (operands[2]) - INTVAL (operands[3]);
6553   else
6554     ofs = INTVAL (operands[3]);
6555
6556   ofs = ofs / 8;
6557
6558   alpha_expand_unaligned_load (operands[0], operands[1],
6559                                INTVAL (operands[2]) / 8,
6560                                ofs, 1);
6561   DONE;
6562 })
6563
6564 (define_expand "extzv"
6565   [(set (match_operand:DI 0 "register_operand" "")
6566         (zero_extract:DI (match_operand:DI 1 "nonimmediate_operand" "")
6567                          (match_operand:DI 2 "immediate_operand" "")
6568                          (match_operand:DI 3 "immediate_operand" "")))]
6569   ""
6570 {
6571   /* We can do 8, 16, 32 and 64 bit fields, if aligned on byte boundaries.  */
6572   if (INTVAL (operands[3]) % 8 != 0
6573       || (INTVAL (operands[2]) != 8
6574           && INTVAL (operands[2]) != 16
6575           && INTVAL (operands[2]) != 32
6576           && INTVAL (operands[2]) != 64))
6577     FAIL;
6578
6579   if (GET_CODE (operands[1]) == MEM)
6580     {
6581       int ofs;
6582
6583       /* Fail 8-bit fields, falling back on a simple byte load.  */
6584       if (INTVAL (operands[2]) == 8)
6585         FAIL;
6586
6587       /* The bit number is relative to the mode of operand 1 which is
6588          usually QImode (this might actually be a bug in expmed.c). Note 
6589          that the bit number is negative in big-endian mode in this case.
6590          We have to convert that to the offset.  */
6591       if (WORDS_BIG_ENDIAN)
6592         ofs = GET_MODE_BITSIZE (GET_MODE (operands[1]))
6593               - INTVAL (operands[2]) - INTVAL (operands[3]);
6594       else
6595         ofs = INTVAL (operands[3]);
6596
6597       ofs = ofs / 8;
6598
6599       alpha_expand_unaligned_load (operands[0], operands[1],
6600                                    INTVAL (operands[2]) / 8,
6601                                    ofs, 0);
6602       DONE;
6603     }
6604 })
6605
6606 (define_expand "insv"
6607   [(set (zero_extract:DI (match_operand:QI 0 "memory_operand" "")
6608                          (match_operand:DI 1 "immediate_operand" "")
6609                          (match_operand:DI 2 "immediate_operand" ""))
6610         (match_operand:DI 3 "register_operand" ""))]
6611   ""
6612 {
6613   int ofs;
6614
6615   /* We can do 16, 32 and 64 bit fields, if aligned on byte boundaries.  */
6616   if (INTVAL (operands[2]) % 8 != 0
6617       || (INTVAL (operands[1]) != 16
6618           && INTVAL (operands[1]) != 32
6619           && INTVAL (operands[1]) != 64))
6620     FAIL;
6621
6622   /* From mips.md: store_bit_field doesn't verify that our source
6623      matches the predicate, so we force it to be a MEM here.  */
6624   if (GET_CODE (operands[0]) != MEM)
6625     FAIL;
6626
6627   /* The bit number is relative to the mode of operand 1 which is
6628      usually QImode (this might actually be a bug in expmed.c). Note 
6629      that the bit number is negative in big-endian mode in this case.
6630      We have to convert that to the offset.  */
6631   if (WORDS_BIG_ENDIAN)
6632     ofs = GET_MODE_BITSIZE (GET_MODE (operands[0]))
6633           - INTVAL (operands[1]) - INTVAL (operands[2]);
6634   else
6635     ofs = INTVAL (operands[2]);
6636
6637   ofs = ofs / 8;
6638
6639   alpha_expand_unaligned_store (operands[0], operands[3],
6640                                 INTVAL (operands[1]) / 8, ofs);
6641   DONE;
6642 })
6643
6644 ;; Block move/clear, see alpha.c for more details.
6645 ;; Argument 0 is the destination
6646 ;; Argument 1 is the source
6647 ;; Argument 2 is the length
6648 ;; Argument 3 is the alignment
6649
6650 (define_expand "movmemqi"
6651   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
6652                    (match_operand:BLK 1 "memory_operand" ""))
6653               (use (match_operand:DI 2 "immediate_operand" ""))
6654               (use (match_operand:DI 3 "immediate_operand" ""))])]
6655   ""
6656 {
6657   if (alpha_expand_block_move (operands))
6658     DONE;
6659   else
6660     FAIL;
6661 })
6662
6663 (define_expand "movmemdi"
6664   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
6665                    (match_operand:BLK 1 "memory_operand" ""))
6666               (use (match_operand:DI 2 "immediate_operand" ""))
6667               (use (match_operand:DI 3 "immediate_operand" ""))
6668               (use (match_dup 4))
6669               (clobber (reg:DI 25))
6670               (clobber (reg:DI 16))
6671               (clobber (reg:DI 17))
6672               (clobber (reg:DI 18))
6673               (clobber (reg:DI 19))
6674               (clobber (reg:DI 20))
6675               (clobber (reg:DI 26))
6676               (clobber (reg:DI 27))])]
6677   "TARGET_ABI_OPEN_VMS"
6678 {
6679   operands[4] = gen_rtx_SYMBOL_REF (Pmode, "OTS$MOVE");
6680   alpha_need_linkage (XSTR (operands[4], 0), 0);
6681 })
6682
6683 (define_insn "*movmemdi_1"
6684   [(set (match_operand:BLK 0 "memory_operand" "=m,=m")
6685         (match_operand:BLK 1 "memory_operand" "m,m"))
6686    (use (match_operand:DI 2 "nonmemory_operand" "r,i"))
6687    (use (match_operand:DI 3 "immediate_operand" ""))
6688    (use (match_operand:DI 4 "call_operand" "i,i"))
6689    (clobber (reg:DI 25))
6690    (clobber (reg:DI 16))
6691    (clobber (reg:DI 17))
6692    (clobber (reg:DI 18))
6693    (clobber (reg:DI 19))
6694    (clobber (reg:DI 20))
6695    (clobber (reg:DI 26))
6696    (clobber (reg:DI 27))]
6697   "TARGET_ABI_OPEN_VMS"
6698 {
6699   operands [5] = alpha_use_linkage (operands [4], cfun->decl, 0, 1);
6700   switch (which_alternative)
6701     {
6702     case 0:
6703         return "lda $16,%0\;bis $31,%2,$17\;lda $18,%1\;ldq $26,%5\;lda $25,3($31)\;jsr $26,%4\;ldq $27,0($29)";
6704     case 1:
6705         return "lda $16,%0\;lda $17,%2($31)\;lda $18,%1\;ldq $26,%5\;lda $25,3($31)\;jsr $26,%4\;ldq $27,0($29)";
6706     default:
6707       gcc_unreachable ();
6708     }
6709 }
6710   [(set_attr "type" "multi")
6711    (set_attr "length" "28")])
6712
6713 (define_expand "setmemqi"
6714   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
6715                    (match_operand 2 "const_int_operand" ""))
6716               (use (match_operand:DI 1 "immediate_operand" ""))
6717               (use (match_operand:DI 3 "immediate_operand" ""))])]
6718   ""
6719 {
6720   /* If value to set is not zero, use the library routine.  */
6721   if (operands[2] != const0_rtx)
6722     FAIL;
6723
6724   if (alpha_expand_block_clear (operands))
6725     DONE;
6726   else
6727     FAIL;
6728 })
6729
6730 (define_expand "setmemdi"
6731   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
6732                    (match_operand 2 "const_int_operand" ""))
6733               (use (match_operand:DI 1 "immediate_operand" ""))
6734               (use (match_operand:DI 3 "immediate_operand" ""))
6735               (use (match_dup 4))
6736               (clobber (reg:DI 25))
6737               (clobber (reg:DI 16))
6738               (clobber (reg:DI 17))
6739               (clobber (reg:DI 26))
6740               (clobber (reg:DI 27))])]
6741   "TARGET_ABI_OPEN_VMS"
6742 {
6743   /* If value to set is not zero, use the library routine.  */
6744   if (operands[2] != const0_rtx)
6745     FAIL;
6746
6747   operands[4] = gen_rtx_SYMBOL_REF (Pmode, "OTS$ZERO");
6748   alpha_need_linkage (XSTR (operands[4], 0), 0);
6749 })
6750
6751 (define_insn "*clrmemdi_1"
6752   [(set (match_operand:BLK 0 "memory_operand" "=m,=m")
6753                    (const_int 0))
6754    (use (match_operand:DI 1 "nonmemory_operand" "r,i"))
6755    (use (match_operand:DI 2 "immediate_operand" ""))
6756    (use (match_operand:DI 3 "call_operand" "i,i"))
6757    (clobber (reg:DI 25))
6758    (clobber (reg:DI 16))
6759    (clobber (reg:DI 17))
6760    (clobber (reg:DI 26))
6761    (clobber (reg:DI 27))]
6762   "TARGET_ABI_OPEN_VMS"
6763 {
6764   operands [4] = alpha_use_linkage (operands [3], cfun->decl, 0, 1);
6765   switch (which_alternative)
6766     {
6767     case 0:
6768         return "lda $16,%0\;bis $31,%1,$17\;ldq $26,%4\;lda $25,2($31)\;jsr $26,%3\;ldq $27,0($29)";
6769     case 1:
6770         return "lda $16,%0\;lda $17,%1($31)\;ldq $26,%4\;lda $25,2($31)\;jsr $26,%3\;ldq $27,0($29)";
6771     default:
6772       gcc_unreachable ();
6773     }
6774 }
6775   [(set_attr "type" "multi")
6776    (set_attr "length" "24")])
6777
6778 \f
6779 ;; Subroutine of stack space allocation.  Perform a stack probe.
6780 (define_expand "probe_stack"
6781   [(set (match_dup 1) (match_operand:DI 0 "const_int_operand" ""))]
6782   ""
6783 {
6784   operands[1] = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx,
6785                                                     INTVAL (operands[0])));
6786   MEM_VOLATILE_P (operands[1]) = 1;
6787
6788   operands[0] = const0_rtx;
6789 })
6790
6791 ;; This is how we allocate stack space.  If we are allocating a
6792 ;; constant amount of space and we know it is less than 4096
6793 ;; bytes, we need do nothing.
6794 ;;
6795 ;; If it is more than 4096 bytes, we need to probe the stack
6796 ;; periodically.
6797 (define_expand "allocate_stack"
6798   [(set (reg:DI 30)
6799         (plus:DI (reg:DI 30)
6800                  (match_operand:DI 1 "reg_or_cint_operand" "")))
6801    (set (match_operand:DI 0 "register_operand" "=r")
6802         (match_dup 2))]
6803   ""
6804 {
6805   if (GET_CODE (operands[1]) == CONST_INT
6806       && INTVAL (operands[1]) < 32768)
6807     {
6808       if (INTVAL (operands[1]) >= 4096)
6809         {
6810           /* We do this the same way as in the prologue and generate explicit
6811              probes.  Then we update the stack by the constant.  */
6812
6813           int probed = 4096;
6814
6815           emit_insn (gen_probe_stack (GEN_INT (- probed)));
6816           while (probed + 8192 < INTVAL (operands[1]))
6817             emit_insn (gen_probe_stack (GEN_INT (- (probed += 8192))));
6818
6819           if (probed + 4096 < INTVAL (operands[1]))
6820             emit_insn (gen_probe_stack (GEN_INT (- INTVAL(operands[1]))));
6821         }
6822
6823       operands[1] = GEN_INT (- INTVAL (operands[1]));
6824       operands[2] = virtual_stack_dynamic_rtx;
6825     }
6826   else
6827     {
6828       rtx out_label = 0;
6829       rtx loop_label = gen_label_rtx ();
6830       rtx want = gen_reg_rtx (Pmode);
6831       rtx tmp = gen_reg_rtx (Pmode);
6832       rtx memref;
6833
6834       emit_insn (gen_subdi3 (want, stack_pointer_rtx,
6835                              force_reg (Pmode, operands[1])));
6836       emit_insn (gen_adddi3 (tmp, stack_pointer_rtx, GEN_INT (-4096)));
6837
6838       if (GET_CODE (operands[1]) != CONST_INT)
6839         {
6840           out_label = gen_label_rtx ();
6841           emit_insn (gen_cmpdi (want, tmp));
6842           emit_jump_insn (gen_bgeu (out_label));
6843         }
6844
6845       emit_label (loop_label);
6846       memref = gen_rtx_MEM (DImode, tmp);
6847       MEM_VOLATILE_P (memref) = 1;
6848       emit_move_insn (memref, const0_rtx);
6849       emit_insn (gen_adddi3 (tmp, tmp, GEN_INT(-8192)));
6850       emit_insn (gen_cmpdi (tmp, want));
6851       emit_jump_insn (gen_bgtu (loop_label));
6852
6853       memref = gen_rtx_MEM (DImode, want);
6854       MEM_VOLATILE_P (memref) = 1;
6855       emit_move_insn (memref, const0_rtx);
6856
6857       if (out_label)
6858         emit_label (out_label);
6859
6860       emit_move_insn (stack_pointer_rtx, want);
6861       emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
6862       DONE;
6863     }
6864 })
6865
6866 ;; This is used by alpha_expand_prolog to do the same thing as above,
6867 ;; except we cannot at that time generate new basic blocks, so we hide
6868 ;; the loop in this one insn.
6869
6870 (define_insn "prologue_stack_probe_loop"
6871   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")
6872                      (match_operand:DI 1 "register_operand" "r")]
6873                     UNSPECV_PSPL)]
6874   ""
6875 {
6876   operands[2] = gen_label_rtx ();
6877   (*targetm.asm_out.internal_label) (asm_out_file, "L",
6878                              CODE_LABEL_NUMBER (operands[2]));
6879
6880   return "stq $31,-8192(%1)\;subq %0,1,%0\;lda %1,-8192(%1)\;bne %0,%l2";
6881 }
6882   [(set_attr "length" "16")
6883    (set_attr "type" "multi")])
6884
6885 (define_expand "prologue"
6886   [(clobber (const_int 0))]
6887   ""
6888 {
6889   alpha_expand_prologue ();
6890   DONE;
6891 })
6892
6893 ;; These take care of emitting the ldgp insn in the prologue. This will be
6894 ;; an lda/ldah pair and we want to align them properly.  So we have two
6895 ;; unspec_volatile insns, the first of which emits the ldgp assembler macro
6896 ;; and the second of which emits nothing.  However, both are marked as type
6897 ;; IADD (the default) so the alignment code in alpha.c does the right thing
6898 ;; with them.
6899
6900 (define_expand "prologue_ldgp"
6901   [(set (match_dup 0)
6902         (unspec_volatile:DI [(match_dup 1) (match_dup 2)] UNSPECV_LDGP1))
6903    (set (match_dup 0)
6904         (unspec_volatile:DI [(match_dup 0) (match_dup 2)] UNSPECV_PLDGP2))]
6905   ""
6906 {
6907   operands[0] = pic_offset_table_rtx;
6908   operands[1] = gen_rtx_REG (Pmode, 27);
6909   operands[2] = (TARGET_EXPLICIT_RELOCS
6910                  ? GEN_INT (alpha_next_sequence_number++)
6911                  : const0_rtx);
6912 })
6913
6914 (define_insn "*ldgp_er_1"
6915   [(set (match_operand:DI 0 "register_operand" "=r")
6916         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")
6917                              (match_operand 2 "const_int_operand" "")]
6918                             UNSPECV_LDGP1))]
6919   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6920   "ldah %0,0(%1)\t\t!gpdisp!%2"
6921   [(set_attr "cannot_copy" "true")])
6922
6923 (define_insn "*ldgp_er_2"
6924   [(set (match_operand:DI 0 "register_operand" "=r")
6925         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
6926                     (match_operand 2 "const_int_operand" "")]
6927                    UNSPEC_LDGP2))]
6928   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6929   "lda %0,0(%1)\t\t!gpdisp!%2"
6930   [(set_attr "cannot_copy" "true")])
6931
6932 (define_insn "*prologue_ldgp_er_2"
6933   [(set (match_operand:DI 0 "register_operand" "=r")
6934         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")
6935                              (match_operand 2 "const_int_operand" "")]
6936                             UNSPECV_PLDGP2))]
6937   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6938   "lda %0,0(%1)\t\t!gpdisp!%2\n$%~..ng:"
6939   [(set_attr "cannot_copy" "true")])
6940
6941 (define_insn "*prologue_ldgp_1"
6942   [(set (match_operand:DI 0 "register_operand" "=r")
6943         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")
6944                              (match_operand 2 "const_int_operand" "")]
6945                             UNSPECV_LDGP1))]
6946   ""
6947   "ldgp %0,0(%1)\n$%~..ng:"
6948   [(set_attr "cannot_copy" "true")])
6949
6950 (define_insn "*prologue_ldgp_2"
6951   [(set (match_operand:DI 0 "register_operand" "=r")
6952         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")
6953                              (match_operand 2 "const_int_operand" "")]
6954                             UNSPECV_PLDGP2))]
6955   ""
6956   "")
6957
6958 ;; The _mcount profiling hook has special calling conventions, and
6959 ;; does not clobber all the registers that a normal call would.  So
6960 ;; hide the fact this is a call at all.
6961
6962 (define_insn "prologue_mcount"
6963   [(unspec_volatile [(const_int 0)] UNSPECV_MCOUNT)]
6964   ""
6965 {
6966   if (TARGET_EXPLICIT_RELOCS)
6967     /* Note that we cannot use a lituse_jsr reloc, since _mcount
6968        cannot be called via the PLT.  */
6969     return "ldq $28,_mcount($29)\t\t!literal\;jsr $28,($28),_mcount";
6970   else
6971     return "lda $28,_mcount\;jsr $28,($28),_mcount";
6972 }
6973   [(set_attr "type" "multi")
6974    (set_attr "length" "8")])
6975
6976 (define_insn "init_fp"
6977   [(set (match_operand:DI 0 "register_operand" "=r")
6978         (match_operand:DI 1 "register_operand" "r"))
6979    (clobber (mem:BLK (match_operand:DI 2 "register_operand" "=r")))]
6980   ""
6981   "bis $31,%1,%0")
6982
6983 (define_expand "epilogue"
6984   [(return)]
6985   ""
6986 {
6987   alpha_expand_epilogue ();
6988 })
6989
6990 (define_expand "sibcall_epilogue"
6991   [(return)]
6992   "TARGET_ABI_OSF"
6993 {
6994   alpha_expand_epilogue ();
6995   DONE;
6996 })
6997
6998 (define_expand "builtin_longjmp"
6999   [(use (match_operand:DI 0 "register_operand" "r"))]
7000   "TARGET_ABI_OSF"
7001 {
7002   /* The elements of the buffer are, in order:  */
7003   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
7004   rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 8));
7005   rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 16));
7006   rtx pv = gen_rtx_REG (Pmode, 27);
7007
7008   /* This bit is the same as expand_builtin_longjmp.  */
7009   emit_move_insn (hard_frame_pointer_rtx, fp);
7010   emit_move_insn (pv, lab);
7011   emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
7012   emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
7013   emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
7014
7015   /* Load the label we are jumping through into $27 so that we know
7016      where to look for it when we get back to setjmp's function for
7017      restoring the gp.  */
7018   emit_jump_insn (gen_builtin_longjmp_internal (pv));
7019   emit_barrier ();
7020   DONE;
7021 })
7022
7023 ;; This is effectively a copy of indirect_jump, but constrained such
7024 ;; that register renaming cannot foil our cunning plan with $27.
7025 (define_insn "builtin_longjmp_internal"
7026   [(set (pc)
7027         (unspec_volatile [(match_operand:DI 0 "register_operand" "c")]
7028                          UNSPECV_LONGJMP))]
7029   ""
7030   "jmp $31,(%0),0"
7031   [(set_attr "type" "ibr")])
7032
7033 (define_expand "builtin_setjmp_receiver"
7034   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
7035   "TARGET_ABI_OSF"
7036   "")
7037
7038 (define_insn_and_split "*builtin_setjmp_receiver_1"
7039   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_SETJMPR)]
7040   "TARGET_ABI_OSF"
7041 {
7042   if (TARGET_EXPLICIT_RELOCS)
7043     return "#";
7044   else
7045     return "br $27,$LSJ%=\n$LSJ%=:\;ldgp $29,0($27)";
7046 }
7047   "&& TARGET_EXPLICIT_RELOCS && reload_completed"
7048   [(set (match_dup 1)
7049         (unspec_volatile:DI [(match_dup 2) (match_dup 3)] UNSPECV_LDGP1))
7050    (set (match_dup 1)
7051         (unspec:DI [(match_dup 1) (match_dup 3)] UNSPEC_LDGP2))]
7052 {
7053   if (prev_nonnote_insn (curr_insn) != XEXP (operands[0], 0))
7054     emit_insn (gen_rtx_UNSPEC_VOLATILE (VOIDmode, gen_rtvec (1, operands[0]),
7055                                         UNSPECV_SETJMPR_ER));
7056   operands[1] = pic_offset_table_rtx;
7057   operands[2] = gen_rtx_REG (Pmode, 27);
7058   operands[3] = GEN_INT (alpha_next_sequence_number++);
7059 }
7060   [(set_attr "length" "12")
7061    (set_attr "type" "multi")])
7062
7063 (define_insn "*builtin_setjmp_receiver_er_sl_1"
7064   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_SETJMPR_ER)]
7065   "TARGET_ABI_OSF && TARGET_EXPLICIT_RELOCS && TARGET_AS_CAN_SUBTRACT_LABELS"
7066   "lda $27,$LSJ%=-%l0($27)\n$LSJ%=:")
7067   
7068 (define_insn "*builtin_setjmp_receiver_er_1"
7069   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_SETJMPR_ER)]
7070   "TARGET_ABI_OSF && TARGET_EXPLICIT_RELOCS"
7071   "br $27,$LSJ%=\n$LSJ%=:"
7072   [(set_attr "type" "ibr")])
7073
7074 (define_expand "exception_receiver"
7075   [(unspec_volatile [(match_dup 0)] UNSPECV_EHR)]
7076   "TARGET_ABI_OSF"
7077 {
7078   if (TARGET_LD_BUGGY_LDGP)
7079     operands[0] = alpha_gp_save_rtx ();
7080   else
7081     operands[0] = const0_rtx;
7082 })
7083
7084 (define_insn "*exception_receiver_2"
7085   [(unspec_volatile [(match_operand:DI 0 "memory_operand" "m")] UNSPECV_EHR)]
7086   "TARGET_ABI_OSF && TARGET_LD_BUGGY_LDGP"
7087   "ldq $29,%0"
7088   [(set_attr "type" "ild")])
7089
7090 (define_insn_and_split "*exception_receiver_1"
7091   [(unspec_volatile [(const_int 0)] UNSPECV_EHR)]
7092   "TARGET_ABI_OSF"
7093 {
7094   if (TARGET_EXPLICIT_RELOCS)
7095     return "ldah $29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*";
7096   else
7097     return "ldgp $29,0($26)";
7098 }
7099   "&& TARGET_EXPLICIT_RELOCS && reload_completed"
7100   [(set (match_dup 0)
7101         (unspec_volatile:DI [(match_dup 1) (match_dup 2)] UNSPECV_LDGP1))
7102    (set (match_dup 0)
7103         (unspec:DI [(match_dup 0) (match_dup 2)] UNSPEC_LDGP2))]
7104 {
7105   operands[0] = pic_offset_table_rtx;
7106   operands[1] = gen_rtx_REG (Pmode, 26);
7107   operands[2] = GEN_INT (alpha_next_sequence_number++);
7108 }
7109   [(set_attr "length" "8")
7110    (set_attr "type" "multi")])
7111
7112 (define_expand "nonlocal_goto_receiver"
7113   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
7114    (set (reg:DI 27) (mem:DI (reg:DI 29)))
7115    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
7116    (use (reg:DI 27))]
7117   "TARGET_ABI_OPEN_VMS"
7118   "")
7119
7120 (define_insn "arg_home"
7121   [(unspec [(const_int 0)] UNSPEC_ARG_HOME)
7122    (use (reg:DI 1))
7123    (use (reg:DI 25))
7124    (use (reg:DI 16))
7125    (use (reg:DI 17))
7126    (use (reg:DI 18))
7127    (use (reg:DI 19))
7128    (use (reg:DI 20))
7129    (use (reg:DI 21))
7130    (use (reg:DI 48))
7131    (use (reg:DI 49))
7132    (use (reg:DI 50))
7133    (use (reg:DI 51))
7134    (use (reg:DI 52))
7135    (use (reg:DI 53))
7136    (clobber (mem:BLK (const_int 0)))
7137    (clobber (reg:DI 24))
7138    (clobber (reg:DI 25))
7139    (clobber (reg:DI 0))]
7140   "TARGET_ABI_OPEN_VMS"
7141   "lda $0,OTS$HOME_ARGS\;ldq $0,8($0)\;jsr $0,OTS$HOME_ARGS"
7142   [(set_attr "length" "16")
7143    (set_attr "type" "multi")])
7144
7145 ;; Load the CIW into r2 for calling __T3E_MISMATCH
7146
7147 (define_expand "umk_mismatch_args"
7148   [(set:DI (match_dup 1) (mem:DI (plus:DI (reg:DI 15) (const_int -16))))
7149    (set:DI (match_dup 2) (mem:DI (plus:DI (match_dup 1) (const_int -32))))
7150    (set:DI (reg:DI 1) (match_operand:DI 0 "const_int_operand" ""))
7151    (set:DI (match_dup 3) (plus:DI (mult:DI (reg:DI 25)
7152                                            (const_int 8))
7153                                   (match_dup 2)))
7154    (set:DI (reg:DI 2) (mem:DI (match_dup 3)))]
7155   "TARGET_ABI_UNICOSMK"
7156 {
7157   operands[1] = gen_reg_rtx (DImode);
7158   operands[2] = gen_reg_rtx (DImode);
7159   operands[3] = gen_reg_rtx (DImode);
7160 })
7161
7162 (define_insn "arg_home_umk"
7163   [(unspec [(const_int 0)] UNSPEC_ARG_HOME)
7164    (use (reg:DI 1))
7165    (use (reg:DI 2))
7166    (use (reg:DI 16))
7167    (use (reg:DI 17))
7168    (use (reg:DI 18))
7169    (use (reg:DI 19))
7170    (use (reg:DI 20))
7171    (use (reg:DI 21))
7172    (use (reg:DI 48))
7173    (use (reg:DI 49))
7174    (use (reg:DI 50))
7175    (use (reg:DI 51))
7176    (use (reg:DI 52))
7177    (use (reg:DI 53))
7178    (clobber (mem:BLK (const_int 0)))
7179    (parallel [
7180    (clobber (reg:DI 22))
7181    (clobber (reg:DI 23))
7182    (clobber (reg:DI 24))
7183    (clobber (reg:DI 0))
7184    (clobber (reg:DI 1))
7185    (clobber (reg:DI 2))
7186    (clobber (reg:DI 3))
7187    (clobber (reg:DI 4))
7188    (clobber (reg:DI 5))
7189    (clobber (reg:DI 6))
7190    (clobber (reg:DI 7))
7191    (clobber (reg:DI 8))])]
7192   "TARGET_ABI_UNICOSMK"
7193   "laum $4,__T3E_MISMATCH($31)\;sll $4,32,$4\;lalm $4,__T3E_MISMATCH($4)\;lal $4,__T3E_MISMATCH($4)\;jsr $3,($4)"
7194   [(set_attr "length" "16")
7195    (set_attr "type" "multi")])
7196
7197 ;; Prefetch data.  
7198 ;;
7199 ;; On EV4, these instructions are nops -- no load occurs.
7200 ;;
7201 ;; On EV5, these instructions act as a normal load, and thus can trap
7202 ;; if the address is invalid.  The OS may (or may not) handle this in
7203 ;; the entMM fault handler and suppress the fault.  If so, then this
7204 ;; has the effect of a read prefetch instruction.
7205 ;;
7206 ;; On EV6, these become official prefetch instructions.
7207
7208 (define_insn "prefetch"
7209   [(prefetch (match_operand:DI 0 "address_operand" "p")
7210              (match_operand:DI 1 "const_int_operand" "n")
7211              (match_operand:DI 2 "const_int_operand" "n"))]
7212   "TARGET_FIXUP_EV5_PREFETCH || alpha_cpu == PROCESSOR_EV6"
7213 {
7214   /* Interpret "no temporal locality" as this data should be evicted once
7215      it is used.  The "evict next" alternatives load the data into the cache
7216      and leave the LRU eviction counter pointing to that block.  */
7217   static const char * const alt[2][2] = {
7218     { 
7219       "ldq $31,%a0",            /* read, evict next */
7220       "ldl $31,%a0",            /* read, evict last */
7221     },
7222     {
7223       "ldt $f31,%a0",           /* write, evict next */
7224       "lds $f31,%a0",           /* write, evict last */
7225     }
7226   };
7227
7228   bool write = INTVAL (operands[1]) != 0;
7229   bool lru = INTVAL (operands[2]) != 0;
7230
7231   return alt[write][lru];
7232 }
7233   [(set_attr "type" "ild")])
7234
7235 ;; Close the trap shadow of preceding instructions.  This is generated
7236 ;; by alpha_reorg.
7237
7238 (define_insn "trapb"
7239   [(unspec_volatile [(const_int 0)] UNSPECV_TRAPB)]
7240   ""
7241   "trapb"
7242   [(set_attr "type" "misc")])
7243
7244 ;; No-op instructions used by machine-dependent reorg to preserve
7245 ;; alignment for instruction issue.
7246 ;; The Unicos/Mk assembler does not support these opcodes.
7247
7248 (define_insn "nop"
7249   [(const_int 0)]
7250   ""
7251   "bis $31,$31,$31"
7252   [(set_attr "type" "ilog")])
7253
7254 (define_insn "fnop"
7255   [(const_int 1)]
7256   "TARGET_FP"
7257   "cpys $f31,$f31,$f31"
7258   [(set_attr "type" "fcpys")])
7259
7260 (define_insn "unop"
7261   [(const_int 2)]
7262   ""
7263   "ldq_u $31,0($30)")
7264
7265 ;; On Unicos/Mk we use a macro for aligning code.
7266
7267 (define_insn "realign"
7268   [(unspec_volatile [(match_operand 0 "immediate_operand" "i")]
7269                     UNSPECV_REALIGN)]
7270   ""
7271 {
7272   if (TARGET_ABI_UNICOSMK)
7273     return "gcc@code@align %0";
7274   else
7275     return ".align %0 #realign";
7276 })
7277 \f
7278 ;; Instructions to be emitted from __builtins.
7279
7280 (define_insn "builtin_cmpbge"
7281   [(set (match_operand:DI 0 "register_operand" "=r")
7282         (unspec:DI [(match_operand:DI 1 "reg_or_0_operand" "rJ")
7283                     (match_operand:DI 2 "reg_or_8bit_operand" "rI")]
7284                    UNSPEC_CMPBGE))]
7285   ""
7286   "cmpbge %r1,%2,%0"
7287   ;; The EV6 data sheets list this as ILOG.  OTOH, EV6 doesn't 
7288   ;; actually differentiate between ILOG and ICMP in the schedule.
7289   [(set_attr "type" "icmp")])
7290
7291 (define_expand "builtin_extbl"
7292   [(match_operand:DI 0 "register_operand" "")
7293    (match_operand:DI 1 "reg_or_0_operand" "")
7294    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7295   ""
7296 {
7297   rtx (*gen) (rtx, rtx, rtx, rtx);
7298   if (WORDS_BIG_ENDIAN)
7299     gen = gen_extxl_be;
7300   else
7301     gen = gen_extxl_le;
7302   emit_insn ((*gen) (operands[0], operands[1], GEN_INT (8), operands[2]));
7303   DONE;
7304 })
7305
7306 (define_expand "builtin_extwl"
7307   [(match_operand:DI 0 "register_operand" "")
7308    (match_operand:DI 1 "reg_or_0_operand" "")
7309    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7310   ""
7311 {
7312   rtx (*gen) (rtx, rtx, rtx, rtx);
7313   if (WORDS_BIG_ENDIAN)
7314     gen = gen_extxl_be;
7315   else
7316     gen = gen_extxl_le;
7317   emit_insn ((*gen) (operands[0], operands[1], GEN_INT (16), operands[2]));
7318   DONE;
7319 })
7320
7321 (define_expand "builtin_extll"
7322   [(match_operand:DI 0 "register_operand" "")
7323    (match_operand:DI 1 "reg_or_0_operand" "")
7324    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7325   ""
7326 {
7327   rtx (*gen) (rtx, rtx, rtx, rtx);
7328   if (WORDS_BIG_ENDIAN)
7329     gen = gen_extxl_be;
7330   else
7331     gen = gen_extxl_le;
7332   emit_insn ((*gen) (operands[0], operands[1], GEN_INT (32), operands[2]));
7333   DONE;
7334 })
7335
7336 (define_expand "builtin_extql"
7337   [(match_operand:DI 0 "register_operand" "")
7338    (match_operand:DI 1 "reg_or_0_operand" "")
7339    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7340   ""
7341 {
7342   rtx (*gen) (rtx, rtx, rtx, rtx);
7343   if (WORDS_BIG_ENDIAN)
7344     gen = gen_extxl_be;
7345   else
7346     gen = gen_extxl_le;
7347   emit_insn ((*gen) (operands[0], operands[1], GEN_INT (64), operands[2]));
7348   DONE;
7349 })
7350
7351 (define_expand "builtin_extwh"
7352   [(match_operand:DI 0 "register_operand" "")
7353    (match_operand:DI 1 "reg_or_0_operand" "")
7354    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7355   ""
7356 {
7357   rtx (*gen) (rtx, rtx, rtx);
7358   if (WORDS_BIG_ENDIAN)
7359     gen = gen_extwh_be;
7360   else
7361     gen = gen_extwh_le;
7362   emit_insn ((*gen) (operands[0], operands[1], operands[2]));
7363   DONE;
7364 })
7365
7366 (define_expand "builtin_extlh"
7367   [(match_operand:DI 0 "register_operand" "")
7368    (match_operand:DI 1 "reg_or_0_operand" "")
7369    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7370   ""
7371 {
7372   rtx (*gen) (rtx, rtx, rtx);
7373   if (WORDS_BIG_ENDIAN)
7374     gen = gen_extlh_be;
7375   else
7376     gen = gen_extlh_le;
7377   emit_insn ((*gen) (operands[0], operands[1], operands[2]));
7378   DONE;
7379 })
7380
7381 (define_expand "builtin_extqh"
7382   [(match_operand:DI 0 "register_operand" "")
7383    (match_operand:DI 1 "reg_or_0_operand" "")
7384    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7385   ""
7386 {
7387   rtx (*gen) (rtx, rtx, rtx);
7388   if (WORDS_BIG_ENDIAN)
7389     gen = gen_extqh_be;
7390   else
7391     gen = gen_extqh_le;
7392   emit_insn ((*gen) (operands[0], operands[1], operands[2]));
7393   DONE;
7394 })
7395
7396 (define_expand "builtin_insbl"
7397   [(match_operand:DI 0 "register_operand" "")
7398    (match_operand:DI 1 "register_operand" "")
7399    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7400   ""
7401 {
7402   rtx (*gen) (rtx, rtx, rtx);
7403   if (WORDS_BIG_ENDIAN)
7404     gen = gen_insbl_be;
7405   else
7406     gen = gen_insbl_le;
7407   operands[1] = gen_lowpart (QImode, operands[1]);
7408   emit_insn ((*gen) (operands[0], operands[1], operands[2]));
7409   DONE;
7410 })
7411
7412 (define_expand "builtin_inswl"
7413   [(match_operand:DI 0 "register_operand" "")
7414    (match_operand:DI 1 "register_operand" "")
7415    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7416   ""
7417 {
7418   rtx (*gen) (rtx, rtx, rtx);
7419   if (WORDS_BIG_ENDIAN)
7420     gen = gen_inswl_be;
7421   else
7422     gen = gen_inswl_le;
7423   operands[1] = gen_lowpart (HImode, operands[1]);
7424   emit_insn ((*gen) (operands[0], operands[1], operands[2]));
7425   DONE;
7426 })
7427
7428 (define_expand "builtin_insll"
7429   [(match_operand:DI 0 "register_operand" "")
7430    (match_operand:DI 1 "register_operand" "")
7431    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7432   ""
7433 {
7434   rtx (*gen) (rtx, rtx, rtx);
7435   if (WORDS_BIG_ENDIAN)
7436     gen = gen_insll_be;
7437   else
7438     gen = gen_insll_le;
7439   operands[1] = gen_lowpart (SImode, operands[1]);
7440   emit_insn ((*gen) (operands[0], operands[1], operands[2]));
7441   emit_insn ((*gen) (operands[0], operands[1], operands[2]));
7442   DONE;
7443 })
7444
7445 (define_expand "builtin_insql"
7446   [(match_operand:DI 0 "register_operand" "")
7447    (match_operand:DI 1 "reg_or_0_operand" "")
7448    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7449   ""
7450 {
7451   rtx (*gen) (rtx, rtx, rtx);
7452   if (WORDS_BIG_ENDIAN)
7453     gen = gen_insql_be;
7454   else
7455     gen = gen_insql_le;
7456   emit_insn ((*gen) (operands[0], operands[1], operands[2]));
7457   DONE;
7458 })
7459
7460 (define_expand "builtin_inswh"
7461   [(match_operand:DI 0 "register_operand" "")
7462    (match_operand:DI 1 "register_operand" "")
7463    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7464   ""
7465 {
7466   emit_insn (gen_insxh (operands[0], operands[1], GEN_INT (16), operands[2]));
7467   DONE;
7468 })
7469
7470 (define_expand "builtin_inslh"
7471   [(match_operand:DI 0 "register_operand" "")
7472    (match_operand:DI 1 "register_operand" "")
7473    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7474   ""
7475 {
7476   emit_insn (gen_insxh (operands[0], operands[1], GEN_INT (32), operands[2]));
7477   DONE;
7478 })
7479
7480 (define_expand "builtin_insqh"
7481   [(match_operand:DI 0 "register_operand" "")
7482    (match_operand:DI 1 "register_operand" "")
7483    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7484   ""
7485 {
7486   emit_insn (gen_insxh (operands[0], operands[1], GEN_INT (64), operands[2]));
7487   DONE;
7488 })
7489
7490 (define_expand "builtin_mskbl"
7491   [(match_operand:DI 0 "register_operand" "")
7492    (match_operand:DI 1 "reg_or_0_operand" "")
7493    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7494   ""
7495 {
7496   rtx (*gen) (rtx, rtx, rtx, rtx);
7497   rtx mask;
7498   if (WORDS_BIG_ENDIAN)
7499     gen = gen_mskxl_be;
7500   else
7501     gen = gen_mskxl_le;
7502   mask = GEN_INT (0xff);
7503   emit_insn ((*gen) (operands[0], operands[1], mask, operands[2]));
7504   DONE;
7505 })
7506
7507 (define_expand "builtin_mskwl"
7508   [(match_operand:DI 0 "register_operand" "")
7509    (match_operand:DI 1 "reg_or_0_operand" "")
7510    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7511   ""
7512 {
7513   rtx (*gen) (rtx, rtx, rtx, rtx);
7514   rtx mask;
7515   if (WORDS_BIG_ENDIAN)
7516     gen = gen_mskxl_be;
7517   else
7518     gen = gen_mskxl_le;
7519   mask = GEN_INT (0xffff);
7520   emit_insn ((*gen) (operands[0], operands[1], mask, operands[2]));
7521   DONE;
7522 })
7523
7524 (define_expand "builtin_mskll"
7525   [(match_operand:DI 0 "register_operand" "")
7526    (match_operand:DI 1 "reg_or_0_operand" "")
7527    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7528   ""
7529 {
7530   rtx (*gen) (rtx, rtx, rtx, rtx);
7531   rtx mask;
7532   if (WORDS_BIG_ENDIAN)
7533     gen = gen_mskxl_be;
7534   else
7535     gen = gen_mskxl_le;
7536   mask = immed_double_const (0xffffffff, 0, DImode);
7537   emit_insn ((*gen) (operands[0], operands[1], mask, operands[2]));
7538   DONE;
7539 })
7540
7541 (define_expand "builtin_mskql"
7542   [(match_operand:DI 0 "register_operand" "")
7543    (match_operand:DI 1 "reg_or_0_operand" "")
7544    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7545   ""
7546 {
7547   rtx (*gen) (rtx, rtx, rtx, rtx);
7548   rtx mask;
7549   if (WORDS_BIG_ENDIAN)
7550     gen = gen_mskxl_be;
7551   else
7552     gen = gen_mskxl_le;
7553   mask = constm1_rtx;
7554   emit_insn ((*gen) (operands[0], operands[1], mask, operands[2]));
7555   DONE;
7556 })
7557
7558 (define_expand "builtin_mskwh"
7559   [(match_operand:DI 0 "register_operand" "")
7560    (match_operand:DI 1 "register_operand" "")
7561    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7562   ""
7563 {
7564   emit_insn (gen_mskxh (operands[0], operands[1], GEN_INT (16), operands[2]));
7565   DONE;
7566 })
7567
7568 (define_expand "builtin_msklh"
7569   [(match_operand:DI 0 "register_operand" "")
7570    (match_operand:DI 1 "register_operand" "")
7571    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7572   ""
7573 {
7574   emit_insn (gen_mskxh (operands[0], operands[1], GEN_INT (32), operands[2]));
7575   DONE;
7576 })
7577
7578 (define_expand "builtin_mskqh"
7579   [(match_operand:DI 0 "register_operand" "")
7580    (match_operand:DI 1 "register_operand" "")
7581    (match_operand:DI 2 "reg_or_8bit_operand" "")]
7582   ""
7583 {
7584   emit_insn (gen_mskxh (operands[0], operands[1], GEN_INT (64), operands[2]));
7585   DONE;
7586 })
7587
7588 (define_expand "builtin_zap"
7589   [(set (match_operand:DI 0 "register_operand" "")
7590         (and:DI (unspec:DI
7591                   [(match_operand:DI 2 "reg_or_cint_operand" "")]
7592                   UNSPEC_ZAP)
7593                 (match_operand:DI 1 "reg_or_cint_operand" "")))]
7594   ""
7595 {
7596   if (GET_CODE (operands[2]) == CONST_INT)
7597     {
7598       rtx mask = alpha_expand_zap_mask (INTVAL (operands[2]));
7599
7600       if (mask == const0_rtx)
7601         {
7602           emit_move_insn (operands[0], const0_rtx);
7603           DONE;
7604         }
7605       if (mask == constm1_rtx)
7606         {
7607           emit_move_insn (operands[0], operands[1]);
7608           DONE;
7609         }
7610
7611       operands[1] = force_reg (DImode, operands[1]);
7612       emit_insn (gen_anddi3 (operands[0], operands[1], mask));
7613       DONE;
7614     }
7615
7616   operands[1] = force_reg (DImode, operands[1]);
7617   operands[2] = gen_lowpart (QImode, operands[2]);
7618 })
7619
7620 (define_insn "*builtin_zap_1"
7621   [(set (match_operand:DI 0 "register_operand" "=r,r,r,r")
7622         (and:DI (unspec:DI
7623                   [(match_operand:QI 2 "reg_or_cint_operand" "n,n,r,r")]
7624                   UNSPEC_ZAP)
7625                 (match_operand:DI 1 "reg_or_cint_operand" "n,r,J,r")))]
7626   ""
7627   "@
7628    #
7629    #
7630    bis $31,$31,%0
7631    zap %r1,%2,%0"
7632   [(set_attr "type" "shift,shift,ilog,shift")])
7633
7634 (define_split
7635   [(set (match_operand:DI 0 "register_operand" "")
7636         (and:DI (unspec:DI
7637                   [(match_operand:QI 2 "const_int_operand" "")]
7638                   UNSPEC_ZAP)
7639                 (match_operand:DI 1 "const_int_operand" "")))]
7640   ""
7641   [(const_int 0)]
7642 {
7643   rtx mask = alpha_expand_zap_mask (INTVAL (operands[2]));
7644   if (HOST_BITS_PER_WIDE_INT >= 64 || GET_CODE (mask) == CONST_INT)
7645     operands[1] = gen_int_mode (INTVAL (operands[1]) & INTVAL (mask), DImode);
7646   else
7647     {
7648       HOST_WIDE_INT c_lo = INTVAL (operands[1]);
7649       HOST_WIDE_INT c_hi = (c_lo < 0 ? -1 : 0);
7650       operands[1] = immed_double_const (c_lo & CONST_DOUBLE_LOW (mask),
7651                                         c_hi & CONST_DOUBLE_HIGH (mask),
7652                                         DImode);
7653     }
7654   emit_move_insn (operands[0], operands[1]);
7655   DONE;
7656 })
7657
7658 (define_split
7659   [(set (match_operand:DI 0 "register_operand" "")
7660         (and:DI (unspec:DI
7661                   [(match_operand:QI 2 "const_int_operand" "")]
7662                   UNSPEC_ZAP)
7663                 (match_operand:DI 1 "register_operand" "")))]
7664   ""
7665   [(set (match_dup 0)
7666         (and:DI (match_dup 1) (match_dup 2)))]
7667 {
7668   operands[2] = alpha_expand_zap_mask (INTVAL (operands[2]));
7669   if (operands[2] == const0_rtx)
7670     {
7671       emit_move_insn (operands[0], const0_rtx);
7672       DONE;
7673     }
7674   if (operands[2] == constm1_rtx)
7675     {
7676       emit_move_insn (operands[0], operands[1]);
7677       DONE;
7678     }
7679 })
7680
7681 (define_expand "builtin_zapnot"
7682   [(set (match_operand:DI 0 "register_operand" "")
7683         (and:DI (unspec:DI
7684                   [(not:QI (match_operand:DI 2 "reg_or_cint_operand" ""))]
7685                   UNSPEC_ZAP)
7686                 (match_operand:DI 1 "reg_or_cint_operand" "")))]
7687   ""
7688 {
7689   if (GET_CODE (operands[2]) == CONST_INT)
7690     {
7691       rtx mask = alpha_expand_zap_mask (~ INTVAL (operands[2]));
7692
7693       if (mask == const0_rtx)
7694         {
7695           emit_move_insn (operands[0], const0_rtx);
7696           DONE;
7697         }
7698       if (mask == constm1_rtx)
7699         {
7700           emit_move_insn (operands[0], operands[1]);
7701           DONE;
7702         }
7703
7704       operands[1] = force_reg (DImode, operands[1]);
7705       emit_insn (gen_anddi3 (operands[0], operands[1], mask));
7706       DONE;
7707     }
7708
7709   operands[1] = force_reg (DImode, operands[1]);
7710   operands[2] = gen_lowpart (QImode, operands[2]);
7711 })
7712
7713 (define_insn "*builtin_zapnot_1"
7714   [(set (match_operand:DI 0 "register_operand" "=r")
7715         (and:DI (unspec:DI
7716                   [(not:QI (match_operand:QI 2 "register_operand" "r"))]
7717                   UNSPEC_ZAP)
7718                 (match_operand:DI 1 "reg_or_0_operand" "rJ")))]
7719   ""
7720   "zapnot %r1,%2,%0"
7721   [(set_attr "type" "shift")])
7722
7723 (define_insn "builtin_amask"
7724   [(set (match_operand:DI 0 "register_operand" "=r")
7725         (unspec:DI [(match_operand:DI 1 "reg_or_8bit_operand" "rI")]
7726                    UNSPEC_AMASK))]
7727   ""
7728   "amask %1,%0"
7729   [(set_attr "type" "ilog")])
7730
7731 (define_insn "builtin_implver"
7732   [(set (match_operand:DI 0 "register_operand" "=r")
7733         (unspec:DI [(const_int 0)] UNSPEC_IMPLVER))]
7734   ""
7735   "implver %0"
7736   [(set_attr "type" "ilog")])
7737
7738 (define_insn "builtin_rpcc"
7739   [(set (match_operand:DI 0 "register_operand" "=r")
7740         (unspec_volatile:DI [(const_int 0)] UNSPECV_RPCC))]
7741   ""
7742   "rpcc %0"
7743   [(set_attr "type" "ilog")])
7744
7745 (define_expand "builtin_minub8"
7746   [(match_operand:DI 0 "register_operand" "")
7747    (match_operand:DI 1 "reg_or_0_operand" "")
7748    (match_operand:DI 2 "reg_or_0_operand" "")]
7749   "TARGET_MAX"
7750 {
7751   alpha_expand_builtin_vector_binop (gen_uminv8qi3, V8QImode, operands[0],
7752                                      operands[1], operands[2]);
7753   DONE;
7754 })
7755
7756 (define_expand "builtin_minsb8"
7757   [(match_operand:DI 0 "register_operand" "")
7758    (match_operand:DI 1 "reg_or_0_operand" "")
7759    (match_operand:DI 2 "reg_or_0_operand" "")]
7760   "TARGET_MAX"
7761 {
7762   alpha_expand_builtin_vector_binop (gen_sminv8qi3, V8QImode, operands[0],
7763                                      operands[1], operands[2]);
7764   DONE;
7765 })
7766
7767 (define_expand "builtin_minuw4"
7768   [(match_operand:DI 0 "register_operand" "")
7769    (match_operand:DI 1 "reg_or_0_operand" "")
7770    (match_operand:DI 2 "reg_or_0_operand" "")]
7771   "TARGET_MAX"
7772 {
7773   alpha_expand_builtin_vector_binop (gen_uminv4hi3, V4HImode, operands[0],
7774                                      operands[1], operands[2]);
7775   DONE;
7776 })
7777
7778 (define_expand "builtin_minsw4"
7779   [(match_operand:DI 0 "register_operand" "")
7780    (match_operand:DI 1 "reg_or_0_operand" "")
7781    (match_operand:DI 2 "reg_or_0_operand" "")]
7782   "TARGET_MAX"
7783 {
7784   alpha_expand_builtin_vector_binop (gen_sminv4hi3, V4HImode, operands[0],
7785                                      operands[1], operands[2]);
7786   DONE;
7787 })
7788
7789 (define_expand "builtin_maxub8"
7790   [(match_operand:DI 0 "register_operand" "")
7791    (match_operand:DI 1 "reg_or_0_operand" "")
7792    (match_operand:DI 2 "reg_or_0_operand" "")]
7793   "TARGET_MAX"
7794 {
7795   alpha_expand_builtin_vector_binop (gen_umaxv8qi3, V8QImode, operands[0],
7796                                      operands[1], operands[2]);
7797   DONE;
7798 })
7799
7800 (define_expand "builtin_maxsb8"
7801   [(match_operand:DI 0 "register_operand" "")
7802    (match_operand:DI 1 "reg_or_0_operand" "")
7803    (match_operand:DI 2 "reg_or_0_operand" "")]
7804   "TARGET_MAX"
7805 {
7806   alpha_expand_builtin_vector_binop (gen_smaxv8qi3, V8QImode, operands[0],
7807                                      operands[1], operands[2]);
7808   DONE;
7809 })
7810
7811 (define_expand "builtin_maxuw4"
7812   [(match_operand:DI 0 "register_operand" "")
7813    (match_operand:DI 1 "reg_or_0_operand" "")
7814    (match_operand:DI 2 "reg_or_0_operand" "")]
7815   "TARGET_MAX"
7816 {
7817   alpha_expand_builtin_vector_binop (gen_umaxv4hi3, V4HImode, operands[0],
7818                                      operands[1], operands[2]);
7819   DONE;
7820 })
7821
7822 (define_expand "builtin_maxsw4"
7823   [(match_operand:DI 0 "register_operand" "")
7824    (match_operand:DI 1 "reg_or_0_operand" "")
7825    (match_operand:DI 2 "reg_or_0_operand" "")]
7826   "TARGET_MAX"
7827 {
7828   alpha_expand_builtin_vector_binop (gen_smaxv4hi3, V4HImode, operands[0],
7829                                      operands[1], operands[2]);
7830   DONE;
7831 })
7832
7833 (define_insn "builtin_perr"
7834   [(set (match_operand:DI 0 "register_operand" "=r")
7835         (unspec:DI [(match_operand:DI 1 "reg_or_0_operand" "%rJ")
7836                     (match_operand:DI 2 "reg_or_8bit_operand" "rJ")]
7837                    UNSPEC_PERR))]
7838   "TARGET_MAX"
7839   "perr %r1,%r2,%0"
7840   [(set_attr "type" "mvi")])
7841
7842 (define_expand "builtin_pklb"
7843   [(set (match_operand:DI 0 "register_operand" "")
7844         (vec_concat:V8QI
7845           (vec_concat:V4QI
7846             (truncate:V2QI (match_operand:DI 1 "register_operand" ""))
7847             (match_dup 2))
7848           (match_dup 3)))]
7849   "TARGET_MAX"
7850 {
7851   operands[0] = gen_lowpart (V8QImode, operands[0]);
7852   operands[1] = gen_lowpart (V2SImode, operands[1]);
7853   operands[2] = CONST0_RTX (V2QImode);
7854   operands[3] = CONST0_RTX (V4QImode);
7855 })
7856
7857 (define_insn "*pklb"
7858   [(set (match_operand:V8QI 0 "register_operand" "=r")
7859         (vec_concat:V8QI
7860           (vec_concat:V4QI
7861             (truncate:V2QI (match_operand:V2SI 1 "register_operand" "r"))
7862             (match_operand:V2QI 2 "const0_operand" ""))
7863           (match_operand:V4QI 3 "const0_operand" "")))]
7864   "TARGET_MAX"
7865   "pklb %r1,%0"
7866   [(set_attr "type" "mvi")])
7867
7868 (define_expand "builtin_pkwb"
7869   [(set (match_operand:DI 0 "register_operand" "")
7870         (vec_concat:V8QI
7871           (truncate:V4QI (match_operand:DI 1 "register_operand" ""))
7872           (match_dup 2)))]
7873   "TARGET_MAX"
7874 {
7875   operands[0] = gen_lowpart (V8QImode, operands[0]);
7876   operands[1] = gen_lowpart (V4HImode, operands[1]);
7877   operands[2] = CONST0_RTX (V4QImode);
7878 })
7879
7880 (define_insn "*pkwb"
7881   [(set (match_operand:V8QI 0 "register_operand" "=r")
7882         (vec_concat:V8QI
7883           (truncate:V4QI (match_operand:V4HI 1 "register_operand" "r"))
7884           (match_operand:V4QI 2 "const0_operand" "")))]
7885   "TARGET_MAX"
7886   "pkwb %r1,%0"
7887   [(set_attr "type" "mvi")])
7888
7889 (define_expand "builtin_unpkbl"
7890   [(set (match_operand:DI 0 "register_operand" "")
7891         (zero_extend:V2SI
7892           (vec_select:V2QI (match_operand:DI 1 "register_operand" "")
7893                            (parallel [(const_int 0) (const_int 1)]))))]
7894   "TARGET_MAX"
7895 {
7896   operands[0] = gen_lowpart (V2SImode, operands[0]);
7897   operands[1] = gen_lowpart (V8QImode, operands[1]);
7898 })
7899
7900 (define_insn "*unpkbl"
7901   [(set (match_operand:V2SI 0 "register_operand" "=r")
7902         (zero_extend:V2SI
7903           (vec_select:V2QI (match_operand:V8QI 1 "reg_or_0_operand" "rW")
7904                            (parallel [(const_int 0) (const_int 1)]))))]
7905   "TARGET_MAX"
7906   "unpkbl %r1,%0"
7907   [(set_attr "type" "mvi")])
7908
7909 (define_expand "builtin_unpkbw"
7910   [(set (match_operand:DI 0 "register_operand" "")
7911         (zero_extend:V4HI
7912           (vec_select:V4QI (match_operand:DI 1 "register_operand" "")
7913                            (parallel [(const_int 0)
7914                                       (const_int 1)
7915                                       (const_int 2)
7916                                       (const_int 3)]))))]
7917   "TARGET_MAX"
7918 {
7919   operands[0] = gen_lowpart (V4HImode, operands[0]);
7920   operands[1] = gen_lowpart (V8QImode, operands[1]);
7921 })
7922
7923 (define_insn "*unpkbw"
7924   [(set (match_operand:V4HI 0 "register_operand" "=r")
7925         (zero_extend:V4HI
7926           (vec_select:V4QI (match_operand:V8QI 1 "reg_or_0_operand" "rW")
7927                            (parallel [(const_int 0)
7928                                       (const_int 1)
7929                                       (const_int 2)
7930                                       (const_int 3)]))))]
7931   "TARGET_MAX"
7932   "unpkbw %r1,%0"
7933   [(set_attr "type" "mvi")])
7934 \f
7935 (include "sync.md")
7936 \f
7937 ;; The call patterns are at the end of the file because their
7938 ;; wildcard operand0 interferes with nice recognition.
7939
7940 (define_insn "*call_value_osf_1_er_noreturn"
7941   [(set (match_operand 0 "" "")
7942         (call (mem:DI (match_operand:DI 1 "call_operand" "c,R,s"))
7943               (match_operand 2 "" "")))
7944    (use (reg:DI 29))
7945    (clobber (reg:DI 26))]
7946   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF
7947    && find_reg_note (insn, REG_NORETURN, NULL_RTX)"
7948   "@
7949    jsr $26,($27),0
7950    bsr $26,%1\t\t!samegp
7951    ldq $27,%1($29)\t\t!literal!%#\;jsr $26,($27),%1\t\t!lituse_jsr!%#"
7952   [(set_attr "type" "jsr")
7953    (set_attr "length" "*,*,8")])
7954
7955 (define_insn "*call_value_osf_1_er"
7956   [(set (match_operand 0 "" "")
7957         (call (mem:DI (match_operand:DI 1 "call_operand" "c,R,s"))
7958               (match_operand 2 "" "")))
7959    (use (reg:DI 29))
7960    (clobber (reg:DI 26))]
7961   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
7962   "@
7963    jsr $26,(%1),0\;ldah $29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*
7964    bsr $26,%1\t\t!samegp
7965    ldq $27,%1($29)\t\t!literal!%#\;jsr $26,($27),0\t\t!lituse_jsr!%#\;ldah $29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*"
7966   [(set_attr "type" "jsr")
7967    (set_attr "length" "12,*,16")])
7968
7969 ;; We must use peep2 instead of a split because we need accurate life
7970 ;; information for $gp.  Consider the case of { bar(); while (1); }.
7971 (define_peephole2
7972   [(parallel [(set (match_operand 0 "" "")
7973                    (call (mem:DI (match_operand:DI 1 "call_operand" ""))
7974                          (match_operand 2 "" "")))
7975               (use (reg:DI 29))
7976               (clobber (reg:DI 26))])]
7977   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF && reload_completed
7978    && ! samegp_function_operand (operands[1], Pmode)
7979    && (peep2_regno_dead_p (1, 29)
7980        || find_reg_note (insn, REG_NORETURN, NULL_RTX))"
7981   [(parallel [(set (match_dup 0)
7982                    (call (mem:DI (match_dup 3))
7983                          (match_dup 2)))
7984               (use (reg:DI 29))
7985               (use (match_dup 1))
7986               (use (match_dup 4))
7987               (clobber (reg:DI 26))])]
7988 {
7989   if (CONSTANT_P (operands[1]))
7990     {
7991       operands[3] = gen_rtx_REG (Pmode, 27);
7992       operands[4] = GEN_INT (alpha_next_sequence_number++);
7993       emit_insn (gen_movdi_er_high_g (operands[3], pic_offset_table_rtx,
7994                                       operands[1], operands[4]));
7995     }
7996   else
7997     {
7998       operands[3] = operands[1];
7999       operands[1] = const0_rtx;
8000       operands[4] = const0_rtx;
8001     }
8002 })
8003
8004 (define_peephole2
8005   [(parallel [(set (match_operand 0 "" "")
8006                    (call (mem:DI (match_operand:DI 1 "call_operand" ""))
8007                          (match_operand 2 "" "")))
8008               (use (reg:DI 29))
8009               (clobber (reg:DI 26))])]
8010   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF && reload_completed
8011    && ! samegp_function_operand (operands[1], Pmode)
8012    && ! (peep2_regno_dead_p (1, 29)
8013          || find_reg_note (insn, REG_NORETURN, NULL_RTX))"
8014   [(parallel [(set (match_dup 0)
8015                    (call (mem:DI (match_dup 3))
8016                          (match_dup 2)))
8017               (set (match_dup 6)
8018                    (unspec:DI [(match_dup 6) (match_dup 4)] UNSPEC_LDGP1))
8019               (use (match_dup 1))
8020               (use (match_dup 5))
8021               (clobber (reg:DI 26))])
8022    (set (match_dup 6)
8023         (unspec:DI [(match_dup 6) (match_dup 4)] UNSPEC_LDGP2))]
8024 {
8025   if (CONSTANT_P (operands[1]))
8026     {
8027       operands[3] = gen_rtx_REG (Pmode, 27);
8028       operands[5] = GEN_INT (alpha_next_sequence_number++);
8029       emit_insn (gen_movdi_er_high_g (operands[3], pic_offset_table_rtx,
8030                                       operands[1], operands[5]));
8031     }
8032   else
8033     {
8034       operands[3] = operands[1];
8035       operands[1] = const0_rtx;
8036       operands[5] = const0_rtx;
8037     }
8038   operands[4] = GEN_INT (alpha_next_sequence_number++);
8039   operands[6] = pic_offset_table_rtx;
8040 })
8041
8042 (define_insn "*call_value_osf_2_er_nogp"
8043   [(set (match_operand 0 "" "")
8044         (call (mem:DI (match_operand:DI 1 "register_operand" "c"))
8045               (match_operand 2 "" "")))
8046    (use (reg:DI 29))
8047    (use (match_operand 3 "" ""))
8048    (use (match_operand 4 "" ""))
8049    (clobber (reg:DI 26))]
8050   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
8051   "jsr $26,(%1),%3%J4"
8052   [(set_attr "type" "jsr")])
8053
8054 (define_insn "*call_value_osf_2_er"
8055   [(set (match_operand 0 "" "")
8056         (call (mem:DI (match_operand:DI 1 "register_operand" "c"))
8057               (match_operand 2 "" "")))
8058    (set (reg:DI 29)
8059         (unspec:DI [(reg:DI 29) (match_operand 5 "const_int_operand" "")]
8060                    UNSPEC_LDGP1))
8061    (use (match_operand 3 "" ""))
8062    (use (match_operand 4 "" ""))
8063    (clobber (reg:DI 26))]
8064   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
8065   "jsr $26,(%1),%3%J4\;ldah $29,0($26)\t\t!gpdisp!%5"
8066   [(set_attr "type" "jsr")
8067    (set_attr "cannot_copy" "true")
8068    (set_attr "length" "8")])
8069
8070 (define_insn "*call_value_osf_1_noreturn"
8071   [(set (match_operand 0 "" "")
8072         (call (mem:DI (match_operand:DI 1 "call_operand" "c,R,s"))
8073               (match_operand 2 "" "")))
8074    (use (reg:DI 29))
8075    (clobber (reg:DI 26))]
8076   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF
8077    && find_reg_note (insn, REG_NORETURN, NULL_RTX)"
8078   "@
8079    jsr $26,($27),0
8080    bsr $26,$%1..ng
8081    jsr $26,%1"
8082   [(set_attr "type" "jsr")
8083    (set_attr "length" "*,*,8")])
8084
8085 (define_insn_and_split "call_value_osf_tlsgd"
8086   [(set (match_operand 0 "" "")
8087         (call (mem:DI (match_operand:DI 1 "symbolic_operand" ""))
8088               (const_int 0)))
8089    (unspec [(match_operand:DI 2 "const_int_operand" "")] UNSPEC_TLSGD_CALL)
8090    (use (reg:DI 29))
8091    (clobber (reg:DI 26))]
8092   "HAVE_AS_TLS"
8093   "#"
8094   "&& reload_completed"
8095   [(set (match_dup 3)
8096         (unspec:DI [(match_dup 5)
8097                     (match_dup 1)
8098                     (match_dup 2)] UNSPEC_LITERAL))
8099    (parallel [(set (match_dup 0)
8100                    (call (mem:DI (match_dup 3))
8101                          (const_int 0)))
8102               (set (match_dup 5)
8103                    (unspec:DI [(match_dup 5) (match_dup 4)] UNSPEC_LDGP1))
8104               (use (match_dup 1))
8105               (use (unspec [(match_dup 2)] UNSPEC_TLSGD_CALL))
8106               (clobber (reg:DI 26))])
8107    (set (match_dup 5)
8108         (unspec:DI [(match_dup 5) (match_dup 4)] UNSPEC_LDGP2))]
8109 {
8110   operands[3] = gen_rtx_REG (Pmode, 27);
8111   operands[4] = GEN_INT (alpha_next_sequence_number++);
8112   operands[5] = pic_offset_table_rtx;
8113 }
8114   [(set_attr "type" "multi")])
8115
8116 (define_insn_and_split "call_value_osf_tlsldm"
8117   [(set (match_operand 0 "" "")
8118         (call (mem:DI (match_operand:DI 1 "symbolic_operand" ""))
8119               (const_int 0)))
8120    (unspec [(match_operand:DI 2 "const_int_operand" "")] UNSPEC_TLSLDM_CALL)
8121    (use (reg:DI 29))
8122    (clobber (reg:DI 26))]
8123   "HAVE_AS_TLS"
8124   "#"
8125   "&& reload_completed"
8126   [(set (match_dup 3)
8127         (unspec:DI [(match_dup 5)
8128                     (match_dup 1)
8129                     (match_dup 2)] UNSPEC_LITERAL))
8130    (parallel [(set (match_dup 0)
8131                    (call (mem:DI (match_dup 3))
8132                          (const_int 0)))
8133               (set (match_dup 5)
8134                    (unspec:DI [(match_dup 5) (match_dup 4)] UNSPEC_LDGP1))
8135               (use (match_dup 1))
8136               (use (unspec [(match_dup 2)] UNSPEC_TLSLDM_CALL))
8137               (clobber (reg:DI 26))])
8138    (set (match_dup 5)
8139         (unspec:DI [(match_dup 5) (match_dup 4)] UNSPEC_LDGP2))]
8140 {
8141   operands[3] = gen_rtx_REG (Pmode, 27);
8142   operands[4] = GEN_INT (alpha_next_sequence_number++);
8143   operands[5] = pic_offset_table_rtx;
8144 }
8145   [(set_attr "type" "multi")])
8146
8147 (define_insn "*call_value_osf_1"
8148   [(set (match_operand 0 "" "")
8149         (call (mem:DI (match_operand:DI 1 "call_operand" "c,R,s"))
8150               (match_operand 2 "" "")))
8151    (use (reg:DI 29))
8152    (clobber (reg:DI 26))]
8153   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
8154   "@
8155    jsr $26,($27),0\;ldgp $29,0($26)
8156    bsr $26,$%1..ng
8157    jsr $26,%1\;ldgp $29,0($26)"
8158   [(set_attr "type" "jsr")
8159    (set_attr "length" "12,*,16")])
8160
8161 (define_insn "*sibcall_value_osf_1_er"
8162   [(set (match_operand 0 "" "")
8163         (call (mem:DI (match_operand:DI 1 "symbolic_operand" "R,s"))
8164               (match_operand 2 "" "")))
8165    (unspec [(reg:DI 29)] UNSPEC_SIBCALL)]
8166   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
8167   "@
8168    br $31,%1\t\t!samegp
8169    ldq $27,%1($29)\t\t!literal!%#\;jmp $31,($27),%1\t\t!lituse_jsr!%#"
8170   [(set_attr "type" "jsr")
8171    (set_attr "length" "*,8")])
8172
8173 (define_insn "*sibcall_value_osf_1"
8174   [(set (match_operand 0 "" "")
8175         (call (mem:DI (match_operand:DI 1 "symbolic_operand" "R,s"))
8176               (match_operand 2 "" "")))
8177    (unspec [(reg:DI 29)] UNSPEC_SIBCALL)]
8178   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
8179   "@
8180    br $31,$%1..ng
8181    lda $27,%1\;jmp $31,($27),%1"
8182   [(set_attr "type" "jsr")
8183    (set_attr "length" "*,8")])
8184
8185 (define_insn "*call_value_nt_1"
8186   [(set (match_operand 0 "" "")
8187         (call (mem:DI (match_operand:DI 1 "call_operand" "r,R,s"))
8188               (match_operand 2 "" "")))
8189    (clobber (reg:DI 26))]
8190   "TARGET_ABI_WINDOWS_NT"
8191   "@
8192    jsr $26,(%1)
8193    bsr $26,%1
8194    jsr $26,%1"
8195   [(set_attr "type" "jsr")
8196    (set_attr "length" "*,*,12")])
8197
8198 ; GAS relies on the order and position of instructions output below in order
8199 ; to generate relocs for VMS link to potentially optimize the call.
8200 ; Please do not molest.
8201 (define_insn "*call_value_vms_1"
8202   [(set (match_operand 0 "" "")
8203         (call (mem:DI (match_operand:DI 1 "call_operand" "r,s"))
8204               (match_operand 2 "" "")))
8205    (use (match_operand:DI 3 "nonmemory_operand" "r,n"))
8206    (use (reg:DI 25))
8207    (use (reg:DI 26))
8208    (clobber (reg:DI 27))]
8209   "TARGET_ABI_OPEN_VMS"
8210 {
8211   switch (which_alternative)
8212     {
8213     case 0:
8214         return "mov %3,$27\;jsr $26,0\;ldq $27,0($29)";
8215     case 1:
8216         operands [3] = alpha_use_linkage (operands [1], cfun->decl, 1, 0);
8217         operands [4] = alpha_use_linkage (operands [1], cfun->decl, 0, 0);
8218         return "ldq $26,%4\;ldq $27,%3\;jsr $26,%1\;ldq $27,0($29)";
8219     default:
8220       gcc_unreachable ();
8221     }
8222 }
8223   [(set_attr "type" "jsr")
8224    (set_attr "length" "12,16")])
8225
8226 (define_insn "*call_value_umk"
8227   [(set (match_operand 0 "" "")
8228         (call (mem:DI (match_operand:DI 1 "call_operand" "r"))
8229               (match_operand 2 "" "")))
8230    (use (reg:DI 25))
8231    (clobber (reg:DI 26))]
8232   "TARGET_ABI_UNICOSMK"
8233   "jsr $26,(%1)"
8234   [(set_attr "type" "jsr")])