OSDN Git Service

74c7a0a6f6053ed92612a48665c933c909441ccf
[pf3gnuchains/gcc-fork.git] / gcc / config / bfin / bfin.md
1 ;;- Machine description for Blackfin for GNU compiler
2 ;;  Copyright 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
3 ;;  Contributed by Analog Devices.
4
5 ;; This file is part of GCC.
6
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 3, or (at your
10 ;; option) any later version.
11
12 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15 ;; License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3.  If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ; operand punctuation marks:
22 ;
23 ;     X -- integer value printed as log2
24 ;     Y -- integer value printed as log2(~value) - for bitclear
25 ;     h -- print half word register, low part
26 ;     d -- print half word register, high part
27 ;     D -- print operand as dregs pairs
28 ;     w -- print operand as accumulator register word (a0w, a1w)
29 ;     H -- high part of double mode operand
30 ;     T -- byte register representation Oct. 02 2001
31
32 ; constant operand classes
33 ;
34 ;     J   2**N       5bit imm scaled
35 ;     Ks7 -64 .. 63  signed 7bit imm
36 ;     Ku5 0..31      unsigned 5bit imm
37 ;     Ks4 -8 .. 7    signed 4bit imm
38 ;     Ks3 -4 .. 3    signed 3bit imm
39 ;     Ku3 0 .. 7     unsigned 3bit imm
40 ;     Pn  0, 1, 2    constants 0, 1 or 2, corresponding to n
41 ;
42 ; register operands
43 ;     d  (r0..r7)
44 ;     a  (p0..p5,fp,sp)
45 ;     e  (a0, a1)
46 ;     b  (i0..i3)
47 ;     f  (m0..m3)
48 ;     v  (b0..b3)
49 ;     c  (i0..i3,m0..m3) CIRCREGS
50 ;     C  (CC)            CCREGS
51 ;     t  (lt0,lt1)
52 ;     k  (lc0,lc1)
53 ;     u  (lb0,lb1)
54 ;
55
56 ;; Define constants for hard registers.
57
58 (define_constants
59   [(REG_R0 0)
60    (REG_R1 1)
61    (REG_R2 2)
62    (REG_R3 3)
63    (REG_R4 4)
64    (REG_R5 5)
65    (REG_R6 6)
66    (REG_R7 7)
67
68    (REG_P0 8)
69    (REG_P1 9)
70    (REG_P2 10)
71    (REG_P3 11)
72    (REG_P4 12)
73    (REG_P5 13)
74    (REG_P6 14)
75    (REG_P7 15)
76
77    (REG_SP 14)
78    (REG_FP 15)
79
80    (REG_I0 16)
81    (REG_I1 17)
82    (REG_I2 18)
83    (REG_I3 19)
84
85    (REG_B0 20)
86    (REG_B1 21)
87    (REG_B2 22)
88    (REG_B3 23)
89
90    (REG_L0 24)
91    (REG_L1 25)
92    (REG_L2 26)
93    (REG_L3 27)
94
95    (REG_M0 28)
96    (REG_M1 29)
97    (REG_M2 30)
98    (REG_M3 31)
99
100    (REG_A0 32)
101    (REG_A1 33)
102
103    (REG_CC 34)
104    (REG_RETS 35)
105    (REG_RETI 36)
106    (REG_RETX 37)
107    (REG_RETN 38)
108    (REG_RETE 39)
109
110    (REG_ASTAT 40)
111    (REG_SEQSTAT 41)
112    (REG_USP 42)
113
114    (REG_ARGP 43)
115
116    (REG_LT0 44)
117    (REG_LT1 45)
118    (REG_LC0 46)
119    (REG_LC1 47)
120    (REG_LB0 48)
121    (REG_LB1 49)])
122
123 ;; Constants used in UNSPECs and UNSPEC_VOLATILEs.
124
125 (define_constants
126   [(UNSPEC_CBRANCH_TAKEN 0)
127    (UNSPEC_CBRANCH_NOPS 1)
128    (UNSPEC_RETURN 2)
129    (UNSPEC_MOVE_PIC 3)
130    (UNSPEC_LIBRARY_OFFSET 4)
131    (UNSPEC_PUSH_MULTIPLE 5)
132    ;; Multiply or MAC with extra CONST_INT operand specifying the macflag
133    (UNSPEC_MUL_WITH_FLAG 6)
134    (UNSPEC_MAC_WITH_FLAG 7)
135    (UNSPEC_MOVE_FDPIC 8)
136    (UNSPEC_FUNCDESC_GOT17M4 9)
137    (UNSPEC_LSETUP_END 10)
138    ;; Distinguish a 32-bit version of an insn from a 16-bit version.
139    (UNSPEC_32BIT 11)
140    (UNSPEC_NOP 12)
141    (UNSPEC_ONES 13)
142    (UNSPEC_ATOMIC 14)])
143
144 (define_constants
145   [(UNSPEC_VOLATILE_CSYNC 1)
146    (UNSPEC_VOLATILE_SSYNC 2)
147    (UNSPEC_VOLATILE_LOAD_FUNCDESC 3)
148    (UNSPEC_VOLATILE_STORE_EH_HANDLER 4)
149    (UNSPEC_VOLATILE_DUMMY 5)
150    (UNSPEC_VOLATILE_STALL 6)])
151
152 (define_constants
153   [(MACFLAG_NONE 0)
154    (MACFLAG_T 1)
155    (MACFLAG_FU 2)
156    (MACFLAG_TFU 3)
157    (MACFLAG_IS 4)
158    (MACFLAG_IU 5)
159    (MACFLAG_W32 6)
160    (MACFLAG_M 7)
161    (MACFLAG_IS_M 8)
162    (MACFLAG_S2RND 9)
163    (MACFLAG_ISS2 10)
164    (MACFLAG_IH 11)])
165
166 (define_attr "type"
167   "move,movcc,mvi,mcld,mcst,dsp32,dsp32shiftimm,mult,alu0,shft,brcc,br,call,misc,sync,compare,dummy,stall"
168   (const_string "misc"))
169
170 (define_attr "addrtype" "32bit,preg,spreg,ireg"
171   (cond [(and (eq_attr "type" "mcld")
172               (and (match_operand 0 "dp_register_operand" "")
173                    (match_operand 1 "mem_p_address_operand" "")))
174            (const_string "preg")
175          (and (eq_attr "type" "mcld")
176               (and (match_operand 0 "dp_register_operand" "")
177                    (match_operand 1 "mem_spfp_address_operand" "")))
178            (const_string "spreg")
179          (and (eq_attr "type" "mcld")
180               (and (match_operand 0 "dp_register_operand" "")
181                    (match_operand 1 "mem_i_address_operand" "")))
182            (const_string "ireg")
183          (and (eq_attr "type" "mcst")
184               (and (match_operand 1 "dp_register_operand" "")
185                    (match_operand 0 "mem_p_address_operand" "")))
186            (const_string "preg")
187          (and (eq_attr "type" "mcst")
188               (and (match_operand 1 "dp_register_operand" "")
189                    (match_operand 0 "mem_spfp_address_operand" "")))
190            (const_string "spreg")
191          (and (eq_attr "type" "mcst")
192               (and (match_operand 1 "dp_register_operand" "")
193                    (match_operand 0 "mem_i_address_operand" "")))
194            (const_string "ireg")]
195         (const_string "32bit")))
196
197 (define_attr "storereg" "preg,other"
198   (cond [(and (eq_attr "type" "mcst")
199               (match_operand 1 "p_register_operand" ""))
200            (const_string "preg")]
201         (const_string "other")))
202
203 ;; Scheduling definitions
204
205 (define_automaton "bfin")
206
207 (define_cpu_unit "slot0" "bfin")
208 (define_cpu_unit "slot1" "bfin")
209 (define_cpu_unit "slot2" "bfin")
210
211 ;; Three units used to enforce parallel issue restrictions:
212 ;; only one of the 16-bit slots can use a P register in an address,
213 ;; and only one them can be a store.
214 (define_cpu_unit "store" "bfin")
215 (define_cpu_unit "pregs" "bfin")
216
217 ;; A dummy unit used to delay scheduling of loads after a conditional
218 ;; branch.
219 (define_cpu_unit "load" "bfin")
220
221 ;; A logical unit used to work around anomaly 05000074.
222 (define_cpu_unit "anomaly_05000074" "bfin")
223
224 (define_reservation "core" "slot0+slot1+slot2")
225
226 (define_insn_reservation "alu" 1
227   (eq_attr "type" "move,movcc,mvi,alu0,shft,brcc,br,call,misc,sync,compare")
228   "core")
229
230 (define_insn_reservation "imul" 3
231   (eq_attr "type" "mult")
232   "core*3")
233
234 (define_insn_reservation "dsp32" 1
235   (eq_attr "type" "dsp32")
236   "slot0")
237
238 (define_insn_reservation "dsp32shiftimm" 1
239   (and (eq_attr "type" "dsp32shiftimm")
240        (eq (symbol_ref "ENABLE_WA_05000074")
241            (const_int 0)))
242   "slot0")
243
244 (define_insn_reservation "dsp32shiftimm_anomaly_05000074" 1
245   (and (eq_attr "type" "dsp32shiftimm")
246        (ne (symbol_ref "ENABLE_WA_05000074")
247            (const_int 0)))
248   "slot0+anomaly_05000074")
249
250 (define_insn_reservation "load32" 1
251   (and (not (eq_attr "seq_insns" "multi"))
252        (and (eq_attr "type" "mcld") (eq_attr "addrtype" "32bit")))
253   "core+load")
254
255 (define_insn_reservation "loadp" 1
256   (and (not (eq_attr "seq_insns" "multi"))
257        (and (eq_attr "type" "mcld") (eq_attr "addrtype" "preg")))
258   "slot1+pregs+load")
259
260 (define_insn_reservation "loadsp" 1
261   (and (not (eq_attr "seq_insns" "multi"))
262        (and (eq_attr "type" "mcld") (eq_attr "addrtype" "spreg")))
263   "slot1+pregs")
264
265 (define_insn_reservation "loadi" 1
266   (and (not (eq_attr "seq_insns" "multi"))
267        (and (eq_attr "type" "mcld") (eq_attr "addrtype" "ireg")))
268   "(slot1|slot2)+load")
269
270 (define_insn_reservation "store32" 1
271   (and (not (eq_attr "seq_insns" "multi"))
272        (and (eq_attr "type" "mcst") (eq_attr "addrtype" "32bit")))
273   "core")
274
275 (define_insn_reservation "storep" 1
276   (and (and (not (eq_attr "seq_insns" "multi"))
277             (and (eq_attr "type" "mcst")
278                  (ior (eq_attr "addrtype" "preg")
279                       (eq_attr "addrtype" "spreg"))))
280        (ior (eq (symbol_ref "ENABLE_WA_05000074")
281                 (const_int 0))
282             (eq_attr "storereg" "other")))
283   "slot1+pregs+store")
284
285 (define_insn_reservation "storep_anomaly_05000074" 1
286   (and (and (not (eq_attr "seq_insns" "multi"))
287             (and (eq_attr "type" "mcst")
288                  (ior (eq_attr "addrtype" "preg")
289                       (eq_attr "addrtype" "spreg"))))
290        (and (ne (symbol_ref "ENABLE_WA_05000074")
291                 (const_int 0))
292             (eq_attr "storereg" "preg")))
293   "slot1+anomaly_05000074+pregs+store")
294
295 (define_insn_reservation "storei" 1
296   (and (and (not (eq_attr "seq_insns" "multi"))
297             (and (eq_attr "type" "mcst") (eq_attr "addrtype" "ireg")))
298        (ior (eq (symbol_ref "ENABLE_WA_05000074")
299                 (const_int 0))
300             (eq_attr "storereg" "other")))
301   "(slot1|slot2)+store")
302
303 (define_insn_reservation "storei_anomaly_05000074" 1
304   (and (and (not (eq_attr "seq_insns" "multi"))
305             (and (eq_attr "type" "mcst") (eq_attr "addrtype" "ireg")))
306        (and (ne (symbol_ref "ENABLE_WA_05000074")
307                 (const_int 0))
308             (eq_attr "storereg" "preg")))
309   "((slot1+anomaly_05000074)|slot2)+store")
310
311 (define_insn_reservation "multi" 2
312   (eq_attr "seq_insns" "multi")
313   "core")
314
315 (define_insn_reservation "load_stall1" 1
316   (and (eq_attr "type" "stall")
317        (match_operand 0 "const1_operand" ""))
318   "core+load*2")
319
320 (define_insn_reservation "load_stall3" 1
321   (and (eq_attr "type" "stall")
322        (match_operand 0 "const3_operand" ""))
323   "core+load*4")
324
325 (absence_set "slot0" "slot1,slot2")
326 (absence_set "slot1" "slot2")
327
328 ;; Make sure genautomata knows about the maximum latency that can be produced
329 ;; by the adjust_cost function.
330 (define_insn_reservation "dummy" 5
331   (eq_attr "type" "dummy")
332   "core")
333 \f
334 ;; Operand and operator predicates
335
336 (include "predicates.md")
337 (include "constraints.md")
338 \f
339 ;;; FRIO branches have been optimized for code density
340 ;;; this comes at a slight cost of complexity when
341 ;;; a compiler needs to generate branches in the general
342 ;;; case.  In order to generate the correct branching
343 ;;; mechanisms the compiler needs keep track of instruction
344 ;;; lengths.  The follow table describes how to count instructions
345 ;;; for the FRIO architecture.
346 ;;;
347 ;;; unconditional br are 12-bit imm pcrelative branches *2
348 ;;; conditional   br are 10-bit imm pcrelative branches *2
349 ;;; brcc 10-bit:
350 ;;;   1024 10-bit imm *2 is 2048 (-1024..1022)
351 ;;; br 12-bit  :
352 ;;;   4096 12-bit imm *2 is 8192 (-4096..4094)
353 ;;; NOTE : For brcc we generate instructions such as
354 ;;;   if cc jmp; jump.[sl] offset
355 ;;;   offset of jump.[sl] is from the jump instruction but
356 ;;;     gcc calculates length from the if cc jmp instruction
357 ;;;     furthermore gcc takes the end address of the branch instruction
358 ;;;     as (pc) for a forward branch
359 ;;;     hence our range is (-4094, 4092) instead of (-4096, 4094) for a br
360 ;;;
361 ;;; The way the (pc) rtx works in these calculations is somewhat odd;
362 ;;; for backward branches it's the address of the current instruction,
363 ;;; for forward branches it's the previously known address of the following
364 ;;; instruction - we have to take this into account by reducing the range
365 ;;; for a forward branch.
366
367 ;; Lengths for type "mvi" insns are always defined by the instructions
368 ;; themselves.
369 (define_attr "length" ""
370   (cond [(eq_attr "type" "mcld")
371          (if_then_else (match_operand 1 "effective_address_32bit_p" "")
372                        (const_int 4) (const_int 2))
373
374          (eq_attr "type" "mcst")
375          (if_then_else (match_operand 0 "effective_address_32bit_p" "")
376                        (const_int 4) (const_int 2))
377
378          (eq_attr "type" "move") (const_int 2)
379
380          (eq_attr "type" "dsp32") (const_int 4)
381          (eq_attr "type" "dsp32shiftimm") (const_int 4)
382          (eq_attr "type" "call")  (const_int 4)
383
384          (eq_attr "type" "br")
385          (if_then_else (and
386                           (le (minus (match_dup 0) (pc)) (const_int 4092))
387                           (ge (minus (match_dup 0) (pc)) (const_int -4096)))
388                   (const_int 2)
389                   (const_int 4))
390
391          (eq_attr "type" "brcc")
392          (cond [(and
393                     (le (minus (match_dup 3) (pc)) (const_int 1020))
394                     (ge (minus (match_dup 3) (pc)) (const_int -1024)))
395                   (const_int 2)
396                 (and
397                     (le (minus (match_dup 3) (pc)) (const_int 4092))
398                     (ge (minus (match_dup 3) (pc)) (const_int -4094)))
399                   (const_int 4)]
400                (const_int 6))
401         ]
402
403         (const_int 2)))
404
405 ;; Classify the insns into those that are one instruction and those that
406 ;; are more than one in sequence.
407 (define_attr "seq_insns" "single,multi"
408   (const_string "single"))
409
410 ;; Describe a user's asm statement.
411 (define_asm_attributes
412   [(set_attr "type" "misc")
413    (set_attr "seq_insns" "multi")
414    (set_attr "length" "4")])
415
416 ;; Conditional moves
417
418 (define_expand "movsicc"
419   [(set (match_operand:SI 0 "register_operand" "")
420         (if_then_else:SI (match_operand 1 "comparison_operator" "")
421                          (match_operand:SI 2 "register_operand" "")
422                          (match_operand:SI 3 "register_operand" "")))]
423   ""
424 {
425   operands[1] = bfin_gen_compare (operands[1], SImode);
426 })
427
428 (define_insn "*movsicc_insn1"
429   [(set (match_operand:SI 0 "register_operand" "=da,da,da")
430         (if_then_else:SI
431             (eq:BI (match_operand:BI 3 "register_operand" "C,C,C")
432                 (const_int 0))
433             (match_operand:SI 1 "register_operand" "da,0,da")
434             (match_operand:SI 2 "register_operand" "0,da,da")))]
435   ""
436   "@
437     if !cc %0 =%1; /* movsicc-1a */
438     if cc %0 =%2; /* movsicc-1b */
439     if !cc %0 =%1; if cc %0=%2; /* movsicc-1 */"
440   [(set_attr "length" "2,2,4")
441    (set_attr "type" "movcc")
442    (set_attr "seq_insns" "*,*,multi")])
443
444 (define_insn "*movsicc_insn2"
445   [(set (match_operand:SI 0 "register_operand" "=da,da,da")
446         (if_then_else:SI
447             (ne:BI (match_operand:BI 3 "register_operand" "C,C,C")
448                 (const_int 0))
449             (match_operand:SI 1 "register_operand" "0,da,da")
450             (match_operand:SI 2 "register_operand" "da,0,da")))]
451   ""
452   "@
453    if !cc %0 =%2; /* movsicc-2b */
454    if cc %0 =%1; /* movsicc-2a */
455    if cc %0 =%1; if !cc %0=%2; /* movsicc-1 */"
456   [(set_attr "length" "2,2,4")
457    (set_attr "type" "movcc")
458    (set_attr "seq_insns" "*,*,multi")])
459
460 ;; Insns to load HIGH and LO_SUM
461
462 (define_insn "movsi_high"
463   [(set (match_operand:SI 0 "register_operand" "=x")
464         (high:SI (match_operand:SI 1 "immediate_operand" "i")))]
465   "reload_completed"
466   "%d0 = %d1;"
467   [(set_attr "type" "mvi")
468    (set_attr "length" "4")])
469
470 (define_insn "movstricthi_high"
471   [(set (match_operand:SI 0 "register_operand" "+x")
472         (ior:SI (and:SI (match_dup 0) (const_int 65535))
473                 (match_operand:SI 1 "immediate_operand" "i")))]
474   "reload_completed"
475   "%d0 = %d1;"
476   [(set_attr "type" "mvi")
477    (set_attr "length" "4")])
478
479 (define_insn "movsi_low"
480   [(set (match_operand:SI 0 "register_operand" "=x")
481         (lo_sum:SI (match_operand:SI 1 "register_operand" "0")
482                    (match_operand:SI 2 "immediate_operand" "i")))]
483   "reload_completed"
484   "%h0 = %h2;"
485   [(set_attr "type" "mvi")
486    (set_attr "length" "4")])
487
488 (define_insn "movsi_high_pic"
489   [(set (match_operand:SI 0 "register_operand" "=x")
490         (high:SI (unspec:SI [(match_operand:SI 1 "" "")]
491                             UNSPEC_MOVE_PIC)))]
492   ""
493   "%d0 = %1@GOT_LOW;"
494   [(set_attr "type" "mvi")
495    (set_attr "length" "4")])
496
497 (define_insn "movsi_low_pic"
498   [(set (match_operand:SI 0 "register_operand" "=x")
499         (lo_sum:SI (match_operand:SI 1 "register_operand" "0")
500                    (unspec:SI [(match_operand:SI 2 "" "")]
501                               UNSPEC_MOVE_PIC)))]
502   ""
503   "%h0 = %h2@GOT_HIGH;"
504   [(set_attr "type" "mvi")
505    (set_attr "length" "4")])
506
507 ;;; Move instructions
508
509 (define_insn_and_split "movdi_insn"
510   [(set (match_operand:DI 0 "nonimmediate_operand" "=x,mx,r")
511         (match_operand:DI 1 "general_operand" "iFx,r,mx"))]
512   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) == REG"
513   "#"
514   "reload_completed"
515   [(set (match_dup 2) (match_dup 3))
516    (set (match_dup 4) (match_dup 5))]
517 {
518   rtx lo_half[2], hi_half[2];
519   split_di (operands, 2, lo_half, hi_half);
520
521   if (reg_overlap_mentioned_p (lo_half[0], hi_half[1]))
522     {
523       operands[2] = hi_half[0];
524       operands[3] = hi_half[1];
525       operands[4] = lo_half[0];
526       operands[5] = lo_half[1];
527     }
528   else
529     {
530       operands[2] = lo_half[0];
531       operands[3] = lo_half[1];
532       operands[4] = hi_half[0];
533       operands[5] = hi_half[1];
534     }
535 })
536
537 (define_insn "movbi"
538   [(set (match_operand:BI 0 "nonimmediate_operand" "=x,x,d,md,C,d,C,P1")
539         (match_operand:BI 1 "general_operand" "x,xKs3,md,d,d,C,P0,P1"))]
540
541   ""
542   "@
543    %0 = %1;
544    %0 = %1 (X);
545    %0 = B %1 (Z)%!
546    B %0 = %1;
547    CC = %1;
548    %0 = CC;
549    CC = R0 < R0;
550    CC = R0 == R0;"
551   [(set_attr "type" "move,mvi,mcld,mcst,compare,compare,compare,compare")
552    (set_attr "length" "2,2,*,*,2,2,2,2")
553    (set_attr "seq_insns" "*,*,*,*,*,*,*,*")])
554
555 (define_insn "movpdi"
556   [(set (match_operand:PDI 0 "nonimmediate_operand" "=e,<,e")
557         (match_operand:PDI 1 "general_operand" " e,e,>"))]
558   ""
559   "@
560    %0 = %1;
561    %0 = %x1; %0 = %w1;
562    %w0 = %1; %x0 = %1;"
563   [(set_attr "type" "move,mcst,mcld")
564    (set_attr "seq_insns" "*,multi,multi")])
565
566 (define_insn "load_accumulator"
567   [(set (match_operand:PDI 0 "register_operand" "=e")
568         (sign_extend:PDI (match_operand:SI 1 "register_operand" "d")))]
569   ""
570   "%0 = %1;"
571   [(set_attr "type" "move")])
572
573 (define_insn_and_split "load_accumulator_pair"
574   [(set (match_operand:V2PDI 0 "register_operand" "=e")
575         (sign_extend:V2PDI (vec_concat:V2SI
576                             (match_operand:SI 1 "register_operand" "d")
577                             (match_operand:SI 2 "register_operand" "d"))))]
578   ""
579   "#"
580   "reload_completed"
581   [(set (match_dup 3) (sign_extend:PDI (match_dup 1)))
582    (set (match_dup 4) (sign_extend:PDI (match_dup 2)))]
583 {
584   operands[3] = gen_rtx_REG (PDImode, REGNO (operands[0]));
585   operands[4] = gen_rtx_REG (PDImode, REGNO (operands[0]) + 1);
586 })
587
588 (define_insn "*pushsi_insn"
589   [(set (mem:SI (pre_dec:SI (reg:SI REG_SP)))
590         (match_operand:SI 0 "register_operand" "xy"))]
591   ""
592   "[--SP] = %0;"
593   [(set_attr "type" "mcst")
594    (set_attr "addrtype" "32bit")
595    (set_attr "length" "2")])
596
597 (define_insn "*popsi_insn"
598   [(set (match_operand:SI 0 "register_operand" "=d,xy")
599         (mem:SI (post_inc:SI (reg:SI REG_SP))))]
600   ""
601   "%0 = [SP++]%!"
602   [(set_attr "type" "mcld")
603    (set_attr "addrtype" "preg,32bit")
604    (set_attr "length" "2")])
605
606 ;; The first alternative is used to make reload choose a limited register
607 ;; class when faced with a movsi_insn that had its input operand replaced
608 ;; with a PLUS.  We generally require fewer secondary reloads this way.
609
610 (define_insn "*movsi_insn"
611   [(set (match_operand:SI 0 "nonimmediate_operand" "=da,x,da,y,da,x,x,x,da,mr")
612         (match_operand:SI 1 "general_operand" "da,x,y,da,xKs7,xKsh,xKuh,ix,mr,da"))]
613   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) == REG"
614  "@
615    %0 = %1;
616    %0 = %1;
617    %0 = %1;
618    %0 = %1;
619    %0 = %1 (X);
620    %0 = %1 (X);
621    %0 = %1 (Z);
622    #
623    %0 = %1%!
624    %0 = %1%!"
625   [(set_attr "type" "move,move,move,move,mvi,mvi,mvi,*,mcld,mcst")
626    (set_attr "length" "2,2,2,2,2,4,4,*,*,*")])
627
628 (define_insn "*movsi_insn32"
629   [(set (match_operand:SI 0 "register_operand" "=d,d")
630         (unspec:SI [(match_operand:SI 1 "nonmemory_operand" "d,P0")] UNSPEC_32BIT))]
631   ""
632  "@
633    %0 = ROT %1 BY 0%!
634    %0 = %0 -|- %0%!"
635   [(set_attr "type" "dsp32shiftimm,dsp32")])
636
637 (define_split
638   [(set (match_operand:SI 0 "d_register_operand" "")
639         (const_int 0))]
640   "splitting_for_sched && !optimize_size"
641   [(set (match_dup 0) (unspec:SI [(const_int 0)] UNSPEC_32BIT))])
642
643 (define_split
644   [(set (match_operand:SI 0 "d_register_operand" "")
645         (match_operand:SI 1 "d_register_operand" ""))]
646   "splitting_for_sched && !optimize_size"
647   [(set (match_dup 0) (unspec:SI [(match_dup 1)] UNSPEC_32BIT))])
648
649 (define_insn_and_split "*movv2hi_insn"
650   [(set (match_operand:V2HI 0 "nonimmediate_operand" "=da,da,d,dm")
651         (match_operand:V2HI 1 "general_operand" "i,di,md,d"))]
652
653   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) == REG"
654   "@
655    #
656    %0 = %1;
657    %0 = %1%!
658    %0 = %1%!"
659   "reload_completed && GET_CODE (operands[1]) == CONST_VECTOR"
660   [(set (match_dup 0) (high:SI (match_dup 2)))
661    (set (match_dup 0) (lo_sum:SI (match_dup 0) (match_dup 3)))]
662 {
663   HOST_WIDE_INT intval = INTVAL (XVECEXP (operands[1], 0, 1)) << 16;
664   intval |= INTVAL (XVECEXP (operands[1], 0, 0)) & 0xFFFF;
665
666   operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));
667   operands[2] = operands[3] = GEN_INT (trunc_int_for_mode (intval, SImode));
668 }
669   [(set_attr "type" "move,move,mcld,mcst")
670    (set_attr "length" "2,2,*,*")])
671
672 (define_insn "*movhi_insn"
673   [(set (match_operand:HI 0 "nonimmediate_operand" "=x,da,x,d,mr")
674         (match_operand:HI 1 "general_operand" "x,xKs7,xKsh,mr,d"))]
675   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) == REG"
676 {
677   static const char *templates[] = {
678     "%0 = %1;",
679     "%0 = %1 (X);",
680     "%0 = %1 (X);",
681     "%0 = W %1 (X)%!",
682     "W %0 = %1%!",
683     "%h0 = W %1%!",
684     "W %0 = %h1%!"
685   };
686   int alt = which_alternative;
687   rtx mem = (MEM_P (operands[0]) ? operands[0]
688              : MEM_P (operands[1]) ? operands[1] : NULL_RTX);
689   if (mem && bfin_dsp_memref_p (mem))
690     alt += 2;
691   return templates[alt];
692 }
693   [(set_attr "type" "move,mvi,mvi,mcld,mcst")
694    (set_attr "length" "2,2,4,*,*")])
695
696 (define_insn "*movqi_insn"
697   [(set (match_operand:QI 0 "nonimmediate_operand" "=x,da,x,d,mr")
698         (match_operand:QI 1 "general_operand" "x,xKs7,xKsh,mr,d"))]
699   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) == REG"
700   "@
701    %0 = %1;
702    %0 = %1 (X);
703    %0 = %1 (X);
704    %0 = B %1 (X)%!
705    B %0 = %1%!"
706   [(set_attr "type" "move,mvi,mvi,mcld,mcst")
707    (set_attr "length" "2,2,4,*,*")])
708
709 (define_insn "*movsf_insn"
710   [(set (match_operand:SF 0 "nonimmediate_operand" "=x,x,da,mr")
711         (match_operand:SF 1 "general_operand" "x,Fx,mr,da"))]
712   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) == REG"
713   "@
714    %0 = %1;
715    #
716    %0 = %1%!
717    %0 = %1%!"
718   [(set_attr "type" "move,*,mcld,mcst")])
719
720 (define_insn_and_split "movdf_insn"
721   [(set (match_operand:DF 0 "nonimmediate_operand" "=x,mx,r")
722         (match_operand:DF 1 "general_operand" "iFx,r,mx"))]
723   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) == REG"
724   "#"
725   "reload_completed"
726   [(set (match_dup 2) (match_dup 3))
727    (set (match_dup 4) (match_dup 5))]
728 {
729   rtx lo_half[2], hi_half[2];
730   split_di (operands, 2, lo_half, hi_half);
731
732   if (reg_overlap_mentioned_p (lo_half[0], hi_half[1]))
733     {
734       operands[2] = hi_half[0];
735       operands[3] = hi_half[1];
736       operands[4] = lo_half[0];
737       operands[5] = lo_half[1];
738     }
739   else
740     {
741       operands[2] = lo_half[0];
742       operands[3] = lo_half[1];
743       operands[4] = hi_half[0];
744       operands[5] = hi_half[1];
745     }
746 })
747
748 ;; Storing halfwords.
749 (define_insn "*movsi_insv"
750   [(set (zero_extract:SI (match_operand 0 "register_operand" "+d,x")
751                          (const_int 16)
752                          (const_int 16))
753         (match_operand:SI 1 "nonmemory_operand" "d,n"))]
754   ""
755   "@
756    %d0 = %h1 << 0%!
757    %d0 = %1;"
758   [(set_attr "type" "dsp32shiftimm,mvi")])
759
760 (define_expand "insv"
761   [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "")
762                          (match_operand:SI 1 "immediate_operand" "")
763                          (match_operand:SI 2 "immediate_operand" ""))
764         (match_operand:SI 3 "nonmemory_operand" ""))]
765   ""
766 {
767   if (INTVAL (operands[1]) != 16 || INTVAL (operands[2]) != 16)
768     FAIL;
769
770   /* From mips.md: insert_bit_field doesn't verify that our source
771      matches the predicate, so check it again here.  */
772   if (! register_operand (operands[0], VOIDmode))
773     FAIL;
774 })
775
776 ;; This is the main "hook" for PIC code.  When generating
777 ;; PIC, movsi is responsible for determining when the source address
778 ;; needs PIC relocation and appropriately calling legitimize_pic_address
779 ;; to perform the actual relocation.
780
781 (define_expand "movsi"
782   [(set (match_operand:SI 0 "nonimmediate_operand" "")
783         (match_operand:SI 1 "general_operand" ""))]
784   ""
785 {
786   if (expand_move (operands, SImode))
787     DONE;
788 })
789
790 (define_expand "movv2hi"
791   [(set (match_operand:V2HI 0 "nonimmediate_operand" "")
792         (match_operand:V2HI 1 "general_operand" ""))]
793   ""
794   "expand_move (operands, V2HImode);")
795
796 (define_expand "movdi"
797   [(set (match_operand:DI 0 "nonimmediate_operand" "")
798         (match_operand:DI 1 "general_operand" ""))]
799   ""
800   "expand_move (operands, DImode);")
801
802 (define_expand "movsf"
803  [(set (match_operand:SF 0 "nonimmediate_operand" "")
804        (match_operand:SF 1 "general_operand" ""))]
805   ""
806   "expand_move (operands, SFmode);")
807
808 (define_expand "movdf"
809  [(set (match_operand:DF 0 "nonimmediate_operand" "")
810        (match_operand:DF 1 "general_operand" ""))]
811   ""
812   "expand_move (operands, DFmode);")
813
814 (define_expand "movhi"
815   [(set (match_operand:HI 0 "nonimmediate_operand" "")
816         (match_operand:HI 1 "general_operand" ""))]
817   ""
818   "expand_move (operands, HImode);")
819
820 (define_expand "movqi"
821   [(set (match_operand:QI 0 "nonimmediate_operand" "")
822         (match_operand:QI 1 "general_operand" ""))]
823   ""
824   " expand_move (operands, QImode); ")
825
826 ;; Some define_splits to break up SI/SFmode loads of immediate constants.
827
828 (define_split
829   [(set (match_operand:SI 0 "register_operand" "")
830         (match_operand:SI 1 "symbolic_or_const_operand" ""))]
831   "reload_completed
832    /* Always split symbolic operands; split integer constants that are
833       too large for a single instruction.  */
834    && (GET_CODE (operands[1]) != CONST_INT
835        || (INTVAL (operands[1]) < -32768
836            || INTVAL (operands[1]) >= 65536
837            || (INTVAL (operands[1]) >= 32768 && PREG_P (operands[0]))))"
838   [(set (match_dup 0) (high:SI (match_dup 1)))
839    (set (match_dup 0) (lo_sum:SI (match_dup 0) (match_dup 1)))]
840 {
841   if (GET_CODE (operands[1]) == CONST_INT
842       && split_load_immediate (operands))
843     DONE;
844   /* ??? Do something about TARGET_LOW_64K.  */
845 })
846
847 (define_split
848   [(set (match_operand:SF 0 "register_operand" "")
849         (match_operand:SF 1 "immediate_operand" ""))]
850   "reload_completed"
851   [(set (match_dup 2) (high:SI (match_dup 3)))
852    (set (match_dup 2) (lo_sum:SI (match_dup 2) (match_dup 3)))]
853 {
854   long values;
855   REAL_VALUE_TYPE value;
856
857   gcc_assert (GET_CODE (operands[1]) == CONST_DOUBLE);
858
859   REAL_VALUE_FROM_CONST_DOUBLE (value, operands[1]);
860   REAL_VALUE_TO_TARGET_SINGLE (value, values);
861
862   operands[2] = gen_rtx_REG (SImode, true_regnum (operands[0]));
863   operands[3] = GEN_INT (trunc_int_for_mode (values, SImode));
864   if (values >= -32768 && values < 65536)
865     {
866       emit_move_insn (operands[2], operands[3]);
867       DONE;
868     }
869   if (split_load_immediate (operands + 2))
870     DONE;
871 })
872
873 ;; Sadly, this can't be a proper named movstrict pattern, since the compiler
874 ;; expects to be able to use registers for operand 1.
875 ;; Note that the asm instruction is defined by the manual to take an unsigned
876 ;; constant, but it doesn't matter to the assembler, and the compiler only
877 ;; deals with sign-extended constants.  Hence "Ksh".
878 (define_insn "movstricthi_1"
879   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+x"))
880         (match_operand:HI 1 "immediate_operand" "Ksh"))]
881   ""
882   "%h0 = %1;"
883   [(set_attr "type" "mvi")
884    (set_attr "length" "4")])
885
886 ;; Sign and zero extensions
887
888 (define_insn_and_split "extendhisi2"
889   [(set (match_operand:SI 0 "register_operand" "=d, d")
890         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "d, m")))]
891   ""
892   "@
893    %0 = %h1 (X);
894    %0 = W %h1 (X)%!"
895   "reload_completed && bfin_dsp_memref_p (operands[1])"
896   [(set (match_dup 2) (match_dup 1))
897    (set (match_dup 0) (sign_extend:SI (match_dup 2)))]
898 {
899   operands[2] = gen_lowpart (HImode, operands[0]);
900 }
901   [(set_attr "type" "alu0,mcld")])
902
903 (define_insn_and_split "zero_extendhisi2"
904   [(set (match_operand:SI 0 "register_operand" "=d, d")
905         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "d, m")))]
906   ""
907   "@
908    %0 = %h1 (Z);
909    %0 = W %h1 (Z)%!"
910   "reload_completed && bfin_dsp_memref_p (operands[1])"
911   [(set (match_dup 2) (match_dup 1))
912    (set (match_dup 0) (zero_extend:SI (match_dup 2)))]
913 {
914   operands[2] = gen_lowpart (HImode, operands[0]);
915 }
916   [(set_attr "type" "alu0,mcld")])
917
918 (define_insn "zero_extendbisi2"
919   [(set (match_operand:SI 0 "register_operand" "=d")
920         (zero_extend:SI (match_operand:BI 1 "nonimmediate_operand" "C")))]
921   ""
922   "%0 = %1;"
923   [(set_attr "type" "compare")])
924
925 (define_insn "extendqihi2"
926   [(set (match_operand:HI 0 "register_operand" "=d, d")
927         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "m, d")))]
928   ""
929   "@
930    %0 = B %1 (X)%!
931    %0 = %T1 (X);"
932   [(set_attr "type" "mcld,alu0")])
933
934 (define_insn "extendqisi2"
935   [(set (match_operand:SI 0 "register_operand" "=d, d")
936         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "m, d")))]
937   ""
938   "@
939    %0 = B %1 (X)%!
940    %0 = %T1 (X);"
941   [(set_attr "type" "mcld,alu0")])
942
943
944 (define_insn "zero_extendqihi2"
945   [(set (match_operand:HI 0 "register_operand" "=d, d")
946         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "m, d")))]
947   ""
948   "@
949    %0 = B %1 (Z)%!
950    %0 = %T1 (Z);"
951   [(set_attr "type" "mcld,alu0")])
952
953
954 (define_insn "zero_extendqisi2"
955   [(set (match_operand:SI 0 "register_operand" "=d, d")
956         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "m, d")))]
957   ""
958   "@
959    %0 = B %1 (Z)%!
960    %0 = %T1 (Z);"
961   [(set_attr "type" "mcld,alu0")])
962
963 ;; DImode logical operations
964
965 (define_code_iterator any_logical [and ior xor])
966 (define_code_attr optab [(and "and")
967                          (ior "ior")
968                          (xor "xor")])
969 (define_code_attr op [(and "&")
970                       (ior "|")
971                       (xor "^")])
972 (define_code_attr high_result [(and "0")
973                                (ior "%H1")
974                                (xor "%H1")])
975
976 ;; Keep this pattern around to avoid generating NO_CONFLICT blocks.
977 (define_expand "<optab>di3"
978   [(set (match_operand:DI 0 "register_operand" "=d")
979         (any_logical:DI (match_operand:DI 1 "register_operand" "0")
980                         (match_operand:DI 2 "general_operand" "d")))]
981   ""
982 {
983   rtx hi_half[3], lo_half[3];
984   enum insn_code icode = CODE_FOR_<optab>si3;
985   if (!reg_overlap_mentioned_p (operands[0], operands[1])
986       && !reg_overlap_mentioned_p (operands[0], operands[2]))
987     emit_clobber (operands[0]);
988   split_di (operands, 3, lo_half, hi_half);
989   if (!(*insn_data[icode].operand[2].predicate) (lo_half[2], SImode))
990     lo_half[2] = force_reg (SImode, lo_half[2]);
991   emit_insn (GEN_FCN (icode) (lo_half[0], lo_half[1], lo_half[2]));
992   if (!(*insn_data[icode].operand[2].predicate) (hi_half[2], SImode))
993     hi_half[2] = force_reg (SImode, hi_half[2]);
994   emit_insn (GEN_FCN (icode) (hi_half[0], hi_half[1], hi_half[2]));
995   DONE;
996 })
997
998 (define_insn "zero_extendqidi2"
999   [(set (match_operand:DI 0 "register_operand" "=d")
1000         (zero_extend:DI (match_operand:QI 1 "register_operand" "d")))]
1001   ""
1002   "%0 = %T1 (Z);\\n\\t%H0 = 0;"
1003   [(set_attr "length" "4")
1004    (set_attr "seq_insns" "multi")])
1005
1006 (define_insn "zero_extendhidi2"
1007   [(set (match_operand:DI 0 "register_operand" "=d")
1008         (zero_extend:DI (match_operand:HI 1 "register_operand" "d")))]
1009   ""
1010   "%0 = %h1 (Z);\\n\\t%H0 = 0;"
1011   [(set_attr "length" "4")
1012    (set_attr "seq_insns" "multi")])
1013
1014 (define_insn_and_split "extendsidi2"
1015   [(set (match_operand:DI 0 "register_operand" "=d")
1016         (sign_extend:DI (match_operand:SI 1 "register_operand" "d")))]
1017   ""
1018   "#"
1019   "reload_completed"
1020   [(set (match_dup 3) (match_dup 1))
1021    (set (match_dup 3) (ashiftrt:SI (match_dup 3) (const_int 31)))]
1022 {
1023   split_di (operands, 1, operands + 2, operands + 3);
1024   if (REGNO (operands[0]) != REGNO (operands[1]))
1025     emit_move_insn (operands[2], operands[1]);
1026 })
1027
1028 (define_insn_and_split "extendqidi2"
1029   [(set (match_operand:DI 0 "register_operand" "=d")
1030         (sign_extend:DI (match_operand:QI 1 "register_operand" "d")))]
1031   ""
1032   "#"
1033   "reload_completed"
1034   [(set (match_dup 2) (sign_extend:SI (match_dup 1)))
1035    (set (match_dup 3) (sign_extend:SI (match_dup 1)))
1036    (set (match_dup 3) (ashiftrt:SI (match_dup 3) (const_int 31)))]
1037 {
1038   split_di (operands, 1, operands + 2, operands + 3);
1039 })
1040
1041 (define_insn_and_split "extendhidi2"
1042   [(set (match_operand:DI 0 "register_operand" "=d")
1043         (sign_extend:DI (match_operand:HI 1 "register_operand" "d")))]
1044   ""
1045   "#"
1046   "reload_completed"
1047   [(set (match_dup 2) (sign_extend:SI (match_dup 1)))
1048    (set (match_dup 3) (sign_extend:SI (match_dup 1)))
1049    (set (match_dup 3) (ashiftrt:SI (match_dup 3) (const_int 31)))]
1050 {
1051   split_di (operands, 1, operands + 2, operands + 3);
1052 })
1053
1054 ;; DImode arithmetic operations
1055
1056 (define_insn "add_with_carry"
1057   [(set (match_operand:SI 0 "register_operand" "=d,d")
1058         (plus:SI (match_operand:SI 1 "register_operand" "%0,d")
1059                  (match_operand:SI 2 "nonmemory_operand" "Ks7,d")))
1060    (set (match_operand:BI 3 "register_operand" "=C,C")
1061         (ltu:BI (not:SI (match_dup 1)) (match_dup 2)))]
1062   ""
1063   "@
1064    %0 += %2; cc = ac0;
1065    %0 = %1 + %2; cc = ac0;"
1066   [(set_attr "type" "alu0")
1067    (set_attr "length" "4")
1068    (set_attr "seq_insns" "multi")])
1069
1070 (define_insn "sub_with_carry"
1071   [(set (match_operand:SI 0 "register_operand" "=d")
1072         (minus:SI (match_operand:SI 1 "register_operand" "%d")
1073                   (match_operand:SI 2 "nonmemory_operand" "d")))
1074    (set (match_operand:BI 3 "register_operand" "=C")
1075         (leu:BI (match_dup 2) (match_dup 1)))]
1076   ""
1077   "%0 = %1 - %2; cc = ac0;"
1078   [(set_attr "type" "alu0")
1079    (set_attr "length" "4")
1080    (set_attr "seq_insns" "multi")])
1081
1082 (define_expand "adddi3"
1083   [(set (match_operand:DI 0 "register_operand" "")
1084         (plus:DI (match_operand:DI 1 "register_operand" "")
1085                  (match_operand:DI 2 "nonmemory_operand" "")))
1086    (clobber (match_scratch:SI 3 ""))
1087    (clobber (reg:CC 34))]
1088   ""
1089 {
1090   rtx xops[8];
1091   xops[0] = gen_lowpart (SImode, operands[0]);
1092   xops[1] = simplify_gen_subreg (SImode, operands[0], DImode, 4);
1093   xops[2] = gen_lowpart (SImode, operands[1]);
1094   xops[3] = simplify_gen_subreg (SImode, operands[1], DImode, 4);
1095   xops[4] = gen_lowpart (SImode, operands[2]);
1096   xops[5] = simplify_gen_subreg (SImode, operands[2], DImode, 4);
1097   xops[6] = gen_reg_rtx (SImode);
1098   xops[7] = gen_rtx_REG (BImode, REG_CC);
1099   if (!register_operand (xops[4], SImode)
1100       && (GET_CODE (xops[4]) != CONST_INT
1101           || !satisfies_constraint_Ks7 (xops[4])))
1102     xops[4] = force_reg (SImode, xops[4]);
1103   if (!reg_overlap_mentioned_p (operands[0], operands[1])
1104       && !reg_overlap_mentioned_p (operands[0], operands[2]))
1105     emit_clobber (operands[0]);
1106   emit_insn (gen_add_with_carry (xops[0], xops[2], xops[4], xops[7]));
1107   emit_insn (gen_movbisi (xops[6], xops[7]));
1108   if (!register_operand (xops[5], SImode)
1109       && (GET_CODE (xops[5]) != CONST_INT
1110           || !satisfies_constraint_Ks7 (xops[5])))
1111     xops[5] = force_reg (SImode, xops[5]);
1112   if (xops[5] != const0_rtx)
1113     emit_insn (gen_addsi3 (xops[1], xops[3], xops[5]));
1114   else
1115     emit_move_insn (xops[1], xops[3]);
1116   emit_insn (gen_addsi3 (xops[1], xops[1], xops[6]));
1117   DONE;
1118 })
1119
1120 (define_expand "subdi3"
1121   [(set (match_operand:DI 0 "register_operand" "")
1122         (minus:DI (match_operand:DI 1 "register_operand" "")
1123                   (match_operand:DI 2 "register_operand" "")))
1124    (clobber (reg:CC 34))]
1125   ""
1126 {
1127   rtx xops[8];
1128   xops[0] = gen_lowpart (SImode, operands[0]);
1129   xops[1] = simplify_gen_subreg (SImode, operands[0], DImode, 4);
1130   xops[2] = gen_lowpart (SImode, operands[1]);
1131   xops[3] = simplify_gen_subreg (SImode, operands[1], DImode, 4);
1132   xops[4] = gen_lowpart (SImode, operands[2]);
1133   xops[5] = simplify_gen_subreg (SImode, operands[2], DImode, 4);
1134   xops[6] = gen_reg_rtx (SImode);
1135   xops[7] = gen_rtx_REG (BImode, REG_CC);
1136   if (!reg_overlap_mentioned_p (operands[0], operands[1])
1137       && !reg_overlap_mentioned_p (operands[0], operands[2]))
1138     emit_clobber (operands[0]);
1139   emit_insn (gen_sub_with_carry (xops[0], xops[2], xops[4], xops[7]));
1140   emit_insn (gen_notbi (xops[7], xops[7]));
1141   emit_insn (gen_movbisi (xops[6], xops[7]));
1142   emit_insn (gen_subsi3 (xops[1], xops[3], xops[5]));
1143   emit_insn (gen_subsi3 (xops[1], xops[1], xops[6]));
1144   DONE;
1145 })
1146
1147 ;; Combined shift/add instructions
1148
1149 (define_insn ""
1150   [(set (match_operand:SI 0 "register_operand" "=a,d")
1151         (ashift:SI (plus:SI (match_operand:SI 1 "register_operand" "%0,0")
1152                             (match_operand:SI 2 "register_operand" "a,d"))
1153                    (match_operand:SI 3 "pos_scale_operand" "P1P2,P1P2")))]
1154   ""
1155   "%0 = (%0 + %2) << %3;" /* "shadd %0,%2,%3;" */
1156   [(set_attr "type" "alu0")])
1157
1158 (define_insn ""
1159   [(set (match_operand:SI 0 "register_operand" "=a")
1160         (plus:SI (match_operand:SI 1 "register_operand" "a")
1161                  (mult:SI (match_operand:SI 2 "register_operand" "a")
1162                           (match_operand:SI 3 "scale_by_operand" "i"))))]
1163   ""
1164   "%0 = %1 + (%2 << %X3);"
1165   [(set_attr "type" "alu0")])
1166
1167 (define_insn ""
1168   [(set (match_operand:SI 0 "register_operand" "=a")
1169         (plus:SI (match_operand:SI 1 "register_operand" "a")
1170                  (ashift:SI (match_operand:SI 2 "register_operand" "a")
1171                             (match_operand:SI 3 "pos_scale_operand" "i"))))]
1172   ""
1173   "%0 = %1 + (%2 << %3);"
1174   [(set_attr "type" "alu0")])
1175
1176 (define_insn ""
1177   [(set (match_operand:SI 0 "register_operand" "=a")
1178         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "a")
1179                           (match_operand:SI 2 "scale_by_operand" "i"))
1180                  (match_operand:SI 3 "register_operand" "a")))]
1181   ""
1182   "%0 = %3 + (%1 << %X2);"
1183   [(set_attr "type" "alu0")])
1184
1185 (define_insn ""
1186   [(set (match_operand:SI 0 "register_operand" "=a")
1187         (plus:SI (ashift:SI (match_operand:SI 1 "register_operand" "a")
1188                             (match_operand:SI 2 "pos_scale_operand" "i"))
1189                  (match_operand:SI 3 "register_operand" "a")))]
1190   ""
1191   "%0 = %3 + (%1 << %2);"
1192   [(set_attr "type" "alu0")])
1193
1194 (define_insn "mulhisi3"
1195   [(set (match_operand:SI 0 "register_operand" "=d")
1196         (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%d"))
1197                  (sign_extend:SI (match_operand:HI 2 "register_operand" "d"))))]
1198   ""
1199   "%0 = %h1 * %h2 (IS)%!"
1200   [(set_attr "type" "dsp32")])
1201
1202 (define_insn "umulhisi3"
1203   [(set (match_operand:SI 0 "register_operand" "=d")
1204         (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "%d"))
1205                  (zero_extend:SI (match_operand:HI 2 "register_operand" "d"))))]
1206   ""
1207   "%0 = %h1 * %h2 (FU)%!"
1208   [(set_attr "type" "dsp32")])
1209
1210 (define_insn "usmulhisi3"
1211   [(set (match_operand:SI 0 "register_operand" "=W")
1212         (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "W"))
1213                  (sign_extend:SI (match_operand:HI 2 "register_operand" "W"))))]
1214   ""
1215   "%0 = %h2 * %h1 (IS,M)%!"
1216   [(set_attr "type" "dsp32")])
1217
1218 ;; The processor also supports ireg += mreg or ireg -= mreg, but these
1219 ;; are unusable if we don't ensure that the corresponding lreg is zero.
1220 ;; The same applies to the add/subtract constant versions involving
1221 ;; iregs
1222
1223 (define_insn "addsi3"
1224   [(set (match_operand:SI 0 "register_operand" "=ad,a,d")
1225         (plus:SI (match_operand:SI 1 "register_operand" "%0, a,d")
1226                  (match_operand:SI 2 "reg_or_7bit_operand" "Ks7, a,d")))]
1227   ""
1228   "@
1229    %0 += %2;
1230    %0 = %1 + %2;
1231    %0 = %1 + %2;"
1232   [(set_attr "type" "alu0")
1233    (set_attr "length" "2,2,2")])
1234
1235 (define_insn "ssaddsi3"
1236   [(set (match_operand:SI 0 "register_operand" "=d")
1237         (ss_plus:SI (match_operand:SI 1 "register_operand" "d")
1238                     (match_operand:SI 2 "register_operand" "d")))]
1239   ""
1240   "%0 = %1 + %2 (S)%!"
1241   [(set_attr "type" "dsp32")])
1242
1243 (define_insn "subsi3"
1244   [(set (match_operand:SI 0 "register_operand" "=da,d,a")
1245         (minus:SI (match_operand:SI 1 "register_operand" "0,d,0")
1246                   (match_operand:SI 2 "reg_or_neg7bit_operand" "KN7,d,a")))]
1247   ""
1248 {
1249   static const char *const strings_subsi3[] = {
1250     "%0 += -%2;",
1251     "%0 = %1 - %2;",
1252     "%0 -= %2;",
1253   };
1254
1255   if (CONSTANT_P (operands[2]) && INTVAL (operands[2]) < 0) {
1256      rtx tmp_op = operands[2];
1257      operands[2] = GEN_INT (-INTVAL (operands[2]));
1258      output_asm_insn ("%0 += %2;", operands);
1259      operands[2] = tmp_op;
1260      return "";
1261   }
1262
1263   return strings_subsi3[which_alternative];
1264 }
1265   [(set_attr "type" "alu0")])
1266
1267 (define_insn "sssubsi3"
1268   [(set (match_operand:SI 0 "register_operand" "=d")
1269         (ss_minus:SI (match_operand:SI 1 "register_operand" "d")
1270                      (match_operand:SI 2 "register_operand" "d")))]
1271   ""
1272   "%0 = %1 - %2 (S)%!"
1273   [(set_attr "type" "dsp32")])
1274
1275 ;; Accumulator addition
1276
1277 (define_insn "addpdi3"
1278   [(set (match_operand:PDI 0 "register_operand" "=A")
1279         (ss_plus:PDI (match_operand:PDI 1 "register_operand" "%0")
1280                      (match_operand:PDI 2 "nonmemory_operand" "B")))]
1281   ""
1282   "A0 += A1%!"
1283   [(set_attr "type" "dsp32")])
1284
1285 (define_insn "sum_of_accumulators"
1286   [(set (match_operand:SI 0 "register_operand" "=d")
1287         (ss_truncate:SI
1288          (ss_plus:PDI (match_operand:PDI 2 "register_operand" "1")
1289                       (match_operand:PDI 3 "register_operand" "B"))))
1290    (set (match_operand:PDI 1 "register_operand" "=A")
1291          (ss_plus:PDI (match_dup 2) (match_dup 3)))]
1292   ""
1293   "%0 = (A0 += A1)%!"
1294   [(set_attr "type" "dsp32")])
1295
1296 (define_insn "us_truncpdisi2"
1297   [(set (match_operand:SI 0 "register_operand" "=D,W")
1298         (us_truncate:SI (match_operand:PDI 1 "register_operand" "A,B")))]
1299   ""
1300   "%0 = %1 (FU)%!"
1301   [(set_attr "type" "dsp32")])
1302
1303 ;; Bit test instructions
1304
1305 (define_insn "*not_bittst"
1306  [(set (match_operand:BI 0 "register_operand" "=C")
1307        (eq:BI (zero_extract:SI (match_operand:SI 1 "register_operand" "d")
1308                                (const_int 1)
1309                                (match_operand:SI 2 "immediate_operand" "Ku5"))
1310               (const_int 0)))]
1311  ""
1312  "cc = !BITTST (%1,%2);"
1313   [(set_attr "type" "alu0")])
1314
1315 (define_insn "*bittst"
1316  [(set (match_operand:BI 0 "register_operand" "=C")
1317        (ne:BI (zero_extract:SI (match_operand:SI 1 "register_operand" "d")
1318                                (const_int 1)
1319                                (match_operand:SI 2 "immediate_operand" "Ku5"))
1320                 (const_int 0)))]
1321  ""
1322  "cc = BITTST (%1,%2);"
1323   [(set_attr "type" "alu0")])
1324
1325 (define_insn_and_split "*bit_extract"
1326   [(set (match_operand:SI 0 "register_operand" "=d")
1327         (zero_extract:SI (match_operand:SI 1 "register_operand" "d")
1328                          (const_int 1)
1329                          (match_operand:SI 2 "immediate_operand" "Ku5")))
1330    (clobber (reg:BI REG_CC))]
1331   ""
1332   "#"
1333   ""
1334   [(set (reg:BI REG_CC)
1335         (ne:BI (zero_extract:SI (match_dup 1) (const_int 1) (match_dup 2))
1336                (const_int 0)))
1337    (set (match_dup 0)
1338         (ne:SI (reg:BI REG_CC) (const_int 0)))])
1339
1340 (define_insn_and_split "*not_bit_extract"
1341   [(set (match_operand:SI 0 "register_operand" "=d")
1342         (zero_extract:SI (not:SI (match_operand:SI 1 "register_operand" "d"))
1343                          (const_int 1)
1344                          (match_operand:SI 2 "immediate_operand" "Ku5")))
1345    (clobber (reg:BI REG_CC))]
1346   ""
1347   "#"
1348   ""
1349   [(set (reg:BI REG_CC)
1350         (eq:BI (zero_extract:SI (match_dup 1) (const_int 1) (match_dup 2))
1351                (const_int 0)))
1352    (set (match_dup 0)
1353         (ne:SI (reg:BI REG_CC) (const_int 0)))])
1354
1355 (define_insn "*andsi_insn"
1356   [(set (match_operand:SI 0 "register_operand" "=d,d,d,d")
1357         (and:SI (match_operand:SI 1 "register_operand" "%0,d,d,d")
1358                 (match_operand:SI 2 "rhs_andsi3_operand" "L,M1,M2,d")))]
1359   ""
1360   "@
1361    BITCLR (%0,%Y2);
1362    %0 = %T1 (Z);
1363    %0 = %h1 (Z);
1364    %0 = %1 & %2;"
1365   [(set_attr "type" "alu0")])
1366
1367 (define_expand "andsi3"
1368   [(set (match_operand:SI 0 "register_operand" "")
1369         (and:SI (match_operand:SI 1 "register_operand" "")
1370                 (match_operand:SI 2 "general_operand" "")))]
1371   ""
1372 {
1373   if (highbits_operand (operands[2], SImode))
1374     {
1375       operands[2] = GEN_INT (exact_log2 (-INTVAL (operands[2])));
1376       emit_insn (gen_ashrsi3 (operands[0], operands[1], operands[2]));
1377       emit_insn (gen_ashlsi3 (operands[0], operands[0], operands[2]));
1378       DONE;
1379     }
1380   if (! rhs_andsi3_operand (operands[2], SImode))
1381     operands[2] = force_reg (SImode, operands[2]);
1382 })
1383
1384 (define_insn "iorsi3"
1385   [(set (match_operand:SI 0 "register_operand" "=d,d")
1386         (ior:SI (match_operand:SI 1 "register_operand" "%0,d")
1387                 (match_operand:SI 2 "regorlog2_operand" "J,d")))]
1388   ""
1389   "@
1390    BITSET (%0, %X2);
1391    %0 = %1 | %2;"
1392   [(set_attr "type" "alu0")])
1393
1394 (define_insn "xorsi3"
1395   [(set (match_operand:SI 0 "register_operand" "=d,d")
1396         (xor:SI (match_operand:SI 1 "register_operand" "%0,d")
1397                   (match_operand:SI 2 "regorlog2_operand" "J,d")))]
1398   ""
1399   "@
1400    BITTGL (%0, %X2);
1401    %0 = %1 ^ %2;"
1402   [(set_attr "type" "alu0")])
1403
1404 (define_insn "ones"
1405   [(set (match_operand:HI 0 "register_operand" "=d")
1406         (unspec:HI [(match_operand:SI 1 "register_operand" "d")]
1407                 UNSPEC_ONES))]
1408   ""
1409   "%h0 = ONES %1;"
1410   [(set_attr "type" "alu0")])
1411
1412 (define_insn "smaxsi3"
1413   [(set (match_operand:SI 0 "register_operand" "=d")
1414         (smax:SI (match_operand:SI 1 "register_operand" "d")
1415                  (match_operand:SI 2 "register_operand" "d")))]
1416   ""
1417   "%0 = max(%1,%2)%!"
1418   [(set_attr "type" "dsp32")])
1419
1420 (define_insn "sminsi3"
1421   [(set (match_operand:SI 0 "register_operand" "=d")
1422         (smin:SI (match_operand:SI 1 "register_operand" "d")
1423                  (match_operand:SI 2 "register_operand" "d")))]
1424   ""
1425   "%0 = min(%1,%2)%!"
1426   [(set_attr "type" "dsp32")])
1427
1428 (define_insn "abssi2"
1429   [(set (match_operand:SI 0 "register_operand" "=d")
1430         (abs:SI (match_operand:SI 1 "register_operand" "d")))]
1431   ""
1432   "%0 = abs %1%!"
1433   [(set_attr "type" "dsp32")])
1434
1435 (define_insn "ssabssi2"
1436   [(set (match_operand:SI 0 "register_operand" "=d")
1437         (ss_abs:SI (match_operand:SI 1 "register_operand" "d")))]
1438   ""
1439   "%0 = abs %1%!"
1440   [(set_attr "type" "dsp32")])
1441
1442 (define_insn "negsi2"
1443   [(set (match_operand:SI 0 "register_operand" "=d")
1444         (neg:SI (match_operand:SI 1 "register_operand" "d")))]
1445   ""
1446   "%0 = -%1;"
1447   [(set_attr "type" "alu0")])
1448
1449 (define_insn "ssnegsi2"
1450   [(set (match_operand:SI 0 "register_operand" "=d")
1451         (ss_neg:SI (match_operand:SI 1 "register_operand" "d")))]
1452   ""
1453   "%0 = -%1 (S)%!"
1454   [(set_attr "type" "dsp32")])
1455
1456 (define_insn "one_cmplsi2"
1457   [(set (match_operand:SI 0 "register_operand" "=d")
1458         (not:SI (match_operand:SI 1 "register_operand" "d")))]
1459   ""
1460   "%0 = ~%1;"
1461   [(set_attr "type" "alu0")])
1462
1463 (define_insn "signbitssi2"
1464   [(set (match_operand:HI 0 "register_operand" "=d")
1465         (if_then_else:HI
1466          (lt (match_operand:SI 1 "register_operand" "d") (const_int 0))
1467          (clz:HI (not:SI (match_dup 1)))
1468          (clz:HI (match_dup 1))))]
1469   ""
1470   "%h0 = signbits %1%!"
1471   [(set_attr "type" "dsp32")])
1472
1473 (define_insn "ssroundsi2"
1474   [(set (match_operand:HI 0 "register_operand" "=d")
1475         (truncate:HI
1476          (lshiftrt:SI (ss_plus:SI (match_operand:SI 1 "register_operand" "d")
1477                                   (const_int 32768))
1478                       (const_int 16))))]
1479   ""
1480   "%h0 = %1 (RND)%!"
1481   [(set_attr "type" "dsp32")])
1482
1483 (define_insn "smaxhi3"
1484   [(set (match_operand:HI 0 "register_operand" "=d")
1485         (smax:HI (match_operand:HI 1 "register_operand" "d")
1486                  (match_operand:HI 2 "register_operand" "d")))]
1487   ""
1488   "%0 = max(%1,%2) (V)%!"
1489   [(set_attr "type" "dsp32")])
1490
1491 (define_insn "sminhi3"
1492   [(set (match_operand:HI 0 "register_operand" "=d")
1493         (smin:HI (match_operand:HI 1 "register_operand" "d")
1494                  (match_operand:HI 2 "register_operand" "d")))]
1495   ""
1496   "%0 = min(%1,%2) (V)%!"
1497   [(set_attr "type" "dsp32")])
1498
1499 (define_insn "abshi2"
1500   [(set (match_operand:HI 0 "register_operand" "=d")
1501         (abs:HI (match_operand:HI 1 "register_operand" "d")))]
1502   ""
1503   "%0 = abs %1 (V)%!"
1504   [(set_attr "type" "dsp32")])
1505
1506 (define_insn "neghi2"
1507   [(set (match_operand:HI 0 "register_operand" "=d")
1508         (neg:HI (match_operand:HI 1 "register_operand" "d")))]
1509   ""
1510   "%0 = -%1;"
1511   [(set_attr "type" "alu0")])
1512
1513 (define_insn "ssneghi2"
1514   [(set (match_operand:HI 0 "register_operand" "=d")
1515         (ss_neg:HI (match_operand:HI 1 "register_operand" "d")))]
1516   ""
1517   "%0 = -%1 (V)%!"
1518   [(set_attr "type" "dsp32")])
1519
1520 (define_insn "signbitshi2"
1521   [(set (match_operand:HI 0 "register_operand" "=d")
1522         (if_then_else:HI
1523          (lt (match_operand:HI 1 "register_operand" "d") (const_int 0))
1524          (clz:HI (not:HI (match_dup 1)))
1525          (clz:HI (match_dup 1))))]
1526   ""
1527   "%h0 = signbits %h1%!"
1528   [(set_attr "type" "dsp32")])
1529
1530 (define_insn "mulsi3"
1531   [(set (match_operand:SI 0 "register_operand" "=d")
1532         (mult:SI (match_operand:SI 1 "register_operand" "%0")
1533                  (match_operand:SI 2 "register_operand" "d")))]
1534   ""
1535   "%0 *= %2;"
1536   [(set_attr "type" "mult")])
1537
1538 (define_expand "umulsi3_highpart"
1539   [(parallel
1540     [(set (match_operand:SI 0 "register_operand" "")
1541           (truncate:SI
1542            (lshiftrt:DI
1543             (mult:DI (zero_extend:DI
1544                       (match_operand:SI 1 "nonimmediate_operand" ""))
1545                      (zero_extend:DI
1546                       (match_operand:SI 2 "register_operand" "")))
1547             (const_int 32))))
1548      (clobber (reg:PDI REG_A0))
1549      (clobber (reg:PDI REG_A1))])]
1550   ""
1551 {
1552   if (!optimize_size)
1553     {
1554       rtx a1reg = gen_rtx_REG (PDImode, REG_A1);
1555       rtx a0reg = gen_rtx_REG (PDImode, REG_A0);
1556       emit_insn (gen_flag_macinit1hi (a1reg,
1557                                       gen_lowpart (HImode, operands[1]),
1558                                       gen_lowpart (HImode, operands[2]),
1559                                       GEN_INT (MACFLAG_FU)));
1560       emit_insn (gen_lshrpdi3 (a1reg, a1reg, GEN_INT (16)));
1561       emit_insn (gen_flag_mul_macv2hi_parts_acconly (a0reg, a1reg,
1562                                                      gen_lowpart (V2HImode, operands[1]),
1563                                                      gen_lowpart (V2HImode, operands[2]),
1564                                                      const1_rtx, const1_rtx,
1565                                                      const1_rtx, const0_rtx, a1reg,
1566                                                      const0_rtx, GEN_INT (MACFLAG_FU),
1567                                                      GEN_INT (MACFLAG_FU)));
1568       emit_insn (gen_flag_machi_parts_acconly (a1reg,
1569                                                gen_lowpart (V2HImode, operands[2]),
1570                                                gen_lowpart (V2HImode, operands[1]),
1571                                                const1_rtx, const0_rtx,
1572                                                a1reg, const0_rtx, GEN_INT (MACFLAG_FU)));
1573       emit_insn (gen_lshrpdi3 (a1reg, a1reg, GEN_INT (16)));
1574       emit_insn (gen_addpdi3 (a0reg, a0reg, a1reg));
1575       emit_insn (gen_us_truncpdisi2 (operands[0], a0reg));
1576     }
1577   else
1578     {
1579       rtx umulsi3_highpart_libfunc
1580         = init_one_libfunc ("__umulsi3_highpart");
1581
1582       emit_library_call_value (umulsi3_highpart_libfunc,
1583                                operands[0], LCT_NORMAL, SImode,
1584                                2, operands[1], SImode, operands[2], SImode);
1585     }
1586   DONE;
1587 })
1588
1589 (define_expand "smulsi3_highpart"
1590   [(parallel
1591     [(set (match_operand:SI 0 "register_operand" "")
1592           (truncate:SI
1593            (lshiftrt:DI
1594             (mult:DI (sign_extend:DI
1595                       (match_operand:SI 1 "nonimmediate_operand" ""))
1596                      (sign_extend:DI
1597                       (match_operand:SI 2 "register_operand" "")))
1598             (const_int 32))))
1599      (clobber (reg:PDI REG_A0))
1600      (clobber (reg:PDI REG_A1))])]
1601   ""
1602 {
1603   if (!optimize_size)
1604     {
1605       rtx a1reg = gen_rtx_REG (PDImode, REG_A1);
1606       rtx a0reg = gen_rtx_REG (PDImode, REG_A0);
1607       emit_insn (gen_flag_macinit1hi (a1reg,
1608                                       gen_lowpart (HImode, operands[1]),
1609                                       gen_lowpart (HImode, operands[2]),
1610                                       GEN_INT (MACFLAG_FU)));
1611       emit_insn (gen_lshrpdi3 (a1reg, a1reg, GEN_INT (16)));
1612       emit_insn (gen_flag_mul_macv2hi_parts_acconly (a0reg, a1reg,
1613                                                      gen_lowpart (V2HImode, operands[1]),
1614                                                      gen_lowpart (V2HImode, operands[2]),
1615                                                      const1_rtx, const1_rtx,
1616                                                      const1_rtx, const0_rtx, a1reg,
1617                                                      const0_rtx, GEN_INT (MACFLAG_IS),
1618                                                      GEN_INT (MACFLAG_IS_M)));
1619       emit_insn (gen_flag_machi_parts_acconly (a1reg,
1620                                                gen_lowpart (V2HImode, operands[2]),
1621                                                gen_lowpart (V2HImode, operands[1]),
1622                                                const1_rtx, const0_rtx,
1623                                                a1reg, const0_rtx, GEN_INT (MACFLAG_IS_M)));
1624       emit_insn (gen_ashrpdi3 (a1reg, a1reg, GEN_INT (16)));
1625       emit_insn (gen_sum_of_accumulators (operands[0], a0reg, a0reg, a1reg));
1626     }
1627   else
1628     {
1629       rtx smulsi3_highpart_libfunc
1630         = init_one_libfunc ("__smulsi3_highpart");
1631
1632       emit_library_call_value (smulsi3_highpart_libfunc,
1633                                operands[0], LCT_NORMAL, SImode,
1634                                2, operands[1], SImode, operands[2], SImode);
1635     }
1636   DONE;
1637 })
1638
1639 (define_expand "ashlsi3"
1640   [(set (match_operand:SI 0 "register_operand" "")
1641         (ashift:SI (match_operand:SI 1 "register_operand" "")
1642                    (match_operand:SI 2 "nonmemory_operand" "")))]
1643   ""
1644 {
1645  if (GET_CODE (operands[2]) == CONST_INT
1646      && ((unsigned HOST_WIDE_INT) INTVAL (operands[2])) > 31)
1647    {
1648      emit_insn (gen_movsi (operands[0], const0_rtx));
1649      DONE;
1650    }
1651 })
1652
1653 (define_insn_and_split "*ashlsi3_insn"
1654   [(set (match_operand:SI 0 "register_operand" "=d,d,a,a,a")
1655         (ashift:SI (match_operand:SI 1 "register_operand" "0,d,a,a,a")
1656                    (match_operand:SI 2 "nonmemory_operand" "dKu5,Ku5,P1,P2,?P3P4")))]
1657   ""
1658   "@
1659    %0 <<= %2;
1660    %0 = %1 << %2%!
1661    %0 = %1 + %1;
1662    %0 = %1 << %2;
1663    #"
1664   "PREG_P (operands[0]) && INTVAL (operands[2]) > 2"
1665   [(set (match_dup 0) (ashift:SI (match_dup 1) (const_int 2)))
1666    (set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 3)))]
1667   "operands[3] = GEN_INT (INTVAL (operands[2]) - 2);"
1668   [(set_attr "type" "shft,dsp32shiftimm,shft,shft,*")])
1669
1670 (define_insn "ashrsi3"
1671   [(set (match_operand:SI 0 "register_operand" "=d,d")
1672         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,d")
1673                      (match_operand:SI 2 "nonmemory_operand" "dKu5,Ku5")))]
1674   ""
1675   "@
1676    %0 >>>= %2;
1677    %0 = %1 >>> %2%!"
1678   [(set_attr "type" "shft,dsp32shiftimm")])
1679
1680 (define_insn "rotl16"
1681   [(set (match_operand:SI 0 "register_operand" "=d")
1682         (rotate:SI (match_operand:SI 1 "register_operand" "d")
1683                    (const_int 16)))]
1684   ""
1685   "%0 = PACK (%h1, %d1)%!"
1686   [(set_attr "type" "dsp32")])
1687
1688 (define_expand "rotlsi3"
1689   [(set (match_operand:SI 0 "register_operand" "")
1690         (rotate:SI (match_operand:SI 1 "register_operand" "")
1691                    (match_operand:SI 2 "immediate_operand" "")))]
1692   ""
1693 {
1694   if (INTVAL (operands[2]) != 16)
1695     FAIL;
1696 })
1697
1698 (define_expand "rotrsi3"
1699   [(set (match_operand:SI 0 "register_operand" "")
1700         (rotatert:SI (match_operand:SI 1 "register_operand" "")
1701                      (match_operand:SI 2 "immediate_operand" "")))]
1702   ""
1703 {
1704   if (INTVAL (operands[2]) != 16)
1705     FAIL;
1706   emit_insn (gen_rotl16 (operands[0], operands[1]));
1707   DONE;
1708 })
1709
1710
1711 (define_insn "ror_one"
1712   [(set (match_operand:SI 0 "register_operand" "=d")
1713         (ior:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "d") (const_int 1))
1714                 (ashift:SI (zero_extend:SI (reg:BI REG_CC)) (const_int 31))))
1715    (set (reg:BI REG_CC)
1716         (zero_extract:BI (match_dup 1) (const_int 1) (const_int 0)))]
1717   ""
1718   "%0 = ROT %1 BY -1%!"
1719   [(set_attr "type" "dsp32shiftimm")])
1720
1721 (define_insn "rol_one"
1722   [(set (match_operand:SI 0 "register_operand" "+d")
1723         (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "d") (const_int 1))
1724                 (zero_extend:SI (reg:BI REG_CC))))
1725    (set (reg:BI REG_CC)
1726         (zero_extract:BI (match_dup 1) (const_int 31) (const_int 0)))]
1727   ""
1728   "%0 = ROT %1 BY 1%!"
1729   [(set_attr "type" "dsp32shiftimm")])
1730
1731 (define_expand "lshrdi3"
1732   [(set (match_operand:DI 0 "register_operand" "")
1733         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
1734                      (match_operand:DI 2 "general_operand" "")))]
1735   ""
1736 {
1737   rtx lo_half[2], hi_half[2];
1738       
1739   if (operands[2] != const1_rtx)
1740     FAIL;
1741   if (! rtx_equal_p (operands[0], operands[1]))
1742     emit_move_insn (operands[0], operands[1]);
1743
1744   split_di (operands, 2, lo_half, hi_half);
1745
1746   emit_move_insn (bfin_cc_rtx, const0_rtx);
1747   emit_insn (gen_ror_one (hi_half[0], hi_half[0]));
1748   emit_insn (gen_ror_one (lo_half[0], lo_half[0]));
1749   DONE;
1750 })
1751
1752 (define_expand "ashrdi3"
1753   [(set (match_operand:DI 0 "register_operand" "")
1754         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
1755                      (match_operand:DI 2 "general_operand" "")))]
1756   ""
1757 {
1758   rtx lo_half[2], hi_half[2];
1759       
1760   if (operands[2] != const1_rtx)
1761     FAIL;
1762   if (! rtx_equal_p (operands[0], operands[1]))
1763     emit_move_insn (operands[0], operands[1]);
1764
1765   split_di (operands, 2, lo_half, hi_half);
1766
1767   emit_insn (gen_compare_lt (gen_rtx_REG (BImode, REG_CC),
1768                              hi_half[1], const0_rtx));
1769   emit_insn (gen_ror_one (hi_half[0], hi_half[0]));
1770   emit_insn (gen_ror_one (lo_half[0], lo_half[0]));
1771   DONE;
1772 })
1773
1774 (define_expand "ashldi3"
1775   [(set (match_operand:DI 0 "register_operand" "")
1776         (ashift:DI (match_operand:DI 1 "register_operand" "")
1777                    (match_operand:DI 2 "general_operand" "")))]
1778   ""
1779 {
1780   rtx lo_half[2], hi_half[2];
1781       
1782   if (operands[2] != const1_rtx)
1783     FAIL;
1784   if (! rtx_equal_p (operands[0], operands[1]))
1785     emit_move_insn (operands[0], operands[1]);
1786
1787   split_di (operands, 2, lo_half, hi_half);
1788
1789   emit_move_insn (bfin_cc_rtx, const0_rtx);
1790   emit_insn (gen_rol_one (lo_half[0], lo_half[0]));
1791   emit_insn (gen_rol_one (hi_half[0], hi_half[0]));
1792   DONE;
1793 })
1794
1795 (define_insn "lshrsi3"
1796   [(set (match_operand:SI 0 "register_operand" "=d,d,a")
1797         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0,d,a")
1798                      (match_operand:SI 2 "nonmemory_operand" "dKu5,Ku5,P1P2")))]
1799   ""
1800   "@
1801    %0 >>= %2;
1802    %0 = %1 >> %2%!
1803    %0 = %1 >> %2;"
1804   [(set_attr "type" "shft,dsp32shiftimm,shft")])
1805
1806 (define_insn "lshrpdi3"
1807   [(set (match_operand:PDI 0 "register_operand" "=e")
1808         (lshiftrt:PDI (match_operand:PDI 1 "register_operand" "0")
1809                       (match_operand:SI 2 "nonmemory_operand" "Ku5")))]
1810   ""
1811   "%0 = %1 >> %2%!"
1812   [(set_attr "type" "dsp32shiftimm")])
1813
1814 (define_insn "ashrpdi3"
1815   [(set (match_operand:PDI 0 "register_operand" "=e")
1816         (ashiftrt:PDI (match_operand:PDI 1 "register_operand" "0")
1817                       (match_operand:SI 2 "nonmemory_operand" "Ku5")))]
1818   ""
1819   "%0 = %1 >>> %2%!"
1820   [(set_attr "type" "dsp32shiftimm")])
1821
1822 ;; A pattern to reload the equivalent of
1823 ;;   (set (Dreg) (plus (FP) (large_constant)))
1824 ;; or
1825 ;;   (set (dagreg) (plus (FP) (arbitrary_constant))) 
1826 ;; using a scratch register
1827 (define_expand "reload_insi"
1828   [(parallel [(set (match_operand:SI 0 "register_operand" "=w")
1829                    (match_operand:SI 1 "fp_plus_const_operand" ""))
1830               (clobber (match_operand:SI 2 "register_operand" "=&a"))])]
1831   ""
1832 {
1833   rtx fp_op = XEXP (operands[1], 0);
1834   rtx const_op = XEXP (operands[1], 1);
1835   rtx primary = operands[0];
1836   rtx scratch = operands[2];
1837
1838   emit_move_insn (scratch, const_op);
1839   emit_insn (gen_addsi3 (scratch, scratch, fp_op));
1840   emit_move_insn (primary, scratch);
1841   DONE;
1842 })
1843
1844 (define_insn "reload_inpdi"
1845   [(set (match_operand:PDI 0 "register_operand" "=e")
1846         (match_operand:PDI 1 "memory_operand" "m"))
1847    (clobber (match_operand:SI 2 "register_operand" "=d"))]
1848   ""
1849 {
1850   rtx xops[4];
1851   xops[0] = operands[0];
1852   xops[1] = operands[2];
1853   split_di (operands + 1, 1, xops + 2, xops + 3);
1854   output_asm_insn ("%1 = %2;", xops);
1855   output_asm_insn ("%w0 = %1;", xops);
1856   output_asm_insn ("%1 = %3;", xops);
1857   output_asm_insn ("%x0 = %1;", xops);
1858   return "";
1859 }
1860  [(set_attr "seq_insns" "multi")
1861   (set_attr "type" "mcld")
1862   (set_attr "length" "12")])
1863
1864 (define_insn "reload_outpdi"
1865   [(set (match_operand:PDI 0 "memory_operand" "=m")
1866         (match_operand:PDI 1 "register_operand" "e"))
1867    (clobber (match_operand:SI 2 "register_operand" "=d"))]
1868   ""
1869 {
1870   rtx xops[4];
1871   xops[0] = operands[1];
1872   xops[1] = operands[2];
1873   split_di (operands, 1, xops + 2, xops + 3);
1874   output_asm_insn ("%1 = %w0;", xops);
1875   output_asm_insn ("%2 = %1;", xops);
1876   output_asm_insn ("%1 = %x0;", xops);
1877   output_asm_insn ("%3 = %1;", xops);
1878   return "";
1879 }
1880  [(set_attr "seq_insns" "multi")
1881   (set_attr "type" "mcld")
1882   (set_attr "length" "12")])
1883
1884 ;; Jump instructions
1885
1886 (define_insn "jump"
1887   [(set (pc)
1888         (label_ref (match_operand 0 "" "")))]
1889   ""
1890 {
1891   if (get_attr_length (insn) == 2)
1892     return "jump.s %0;";
1893   else
1894     return "jump.l %0;";
1895 }
1896   [(set_attr "type" "br")])
1897
1898 (define_insn "indirect_jump"
1899   [(set (pc)
1900         (match_operand:SI 0 "register_operand" "a"))]
1901   ""
1902   "jump (%0);"
1903   [(set_attr "type" "misc")])
1904
1905 (define_expand "tablejump"
1906   [(parallel [(set (pc) (match_operand:SI 0 "register_operand" "a"))
1907               (use (label_ref (match_operand 1 "" "")))])]
1908   ""
1909 {
1910   /* In PIC mode, the table entries are stored PC relative.
1911      Convert the relative address to an absolute address.  */
1912   if (flag_pic)
1913     {
1914       rtx op1 = gen_rtx_LABEL_REF (Pmode, operands[1]);
1915
1916       operands[0] = expand_simple_binop (Pmode, PLUS, operands[0],
1917                                          op1, NULL_RTX, 0, OPTAB_DIRECT);
1918     }
1919 })
1920
1921 (define_insn "*tablejump_internal"
1922   [(set (pc) (match_operand:SI 0 "register_operand" "a"))
1923    (use (label_ref (match_operand 1 "" "")))]
1924   ""
1925   "jump (%0);"
1926   [(set_attr "type" "misc")])
1927
1928 ;;  Hardware loop
1929
1930 ; operand 0 is the loop count pseudo register
1931 ; operand 1 is the number of loop iterations or 0 if it is unknown
1932 ; operand 2 is the maximum number of loop iterations
1933 ; operand 3 is the number of levels of enclosed loops
1934 ; operand 4 is the label to jump to at the top of the loop
1935 (define_expand "doloop_end"
1936   [(parallel [(set (pc) (if_then_else
1937                           (ne (match_operand:SI 0 "" "")
1938                               (const_int 1))
1939                           (label_ref (match_operand 4 "" ""))
1940                           (pc)))
1941               (set (match_dup 0)
1942                    (plus:SI (match_dup 0)
1943                             (const_int -1)))
1944               (unspec [(const_int 0)] UNSPEC_LSETUP_END)
1945               (clobber (match_scratch:SI 5 ""))])]
1946   ""
1947 {
1948   /* The loop optimizer doesn't check the predicates... */
1949   if (GET_MODE (operands[0]) != SImode)
1950     FAIL;
1951   /* Due to limitations in the hardware (an initial loop count of 0
1952      does not loop 2^32 times) we must avoid to generate a hardware
1953      loops when we cannot rule out this case.  */
1954   if (!flag_unsafe_loop_optimizations
1955       && (unsigned HOST_WIDE_INT) INTVAL (operands[2]) >= 0xFFFFFFFF)
1956     FAIL;
1957   bfin_hardware_loop ();
1958 })
1959
1960 (define_insn "loop_end"
1961   [(set (pc)
1962         (if_then_else (ne (match_operand:SI 0 "nonimmediate_operand" "+a*d,*b*v*f,m")
1963                           (const_int 1))
1964                       (label_ref (match_operand 1 "" ""))
1965                       (pc)))
1966    (set (match_dup 0)
1967         (plus (match_dup 0)
1968               (const_int -1)))
1969    (unspec [(const_int 0)] UNSPEC_LSETUP_END)
1970    (clobber (match_scratch:SI 2 "=X,&r,&r"))]
1971   ""
1972   "@
1973    /* loop end %0 %l1 */
1974    #
1975    #"
1976   [(set_attr "length" "6,10,14")])
1977
1978 (define_split
1979   [(set (pc)
1980         (if_then_else (ne (match_operand:SI 0 "nondp_reg_or_memory_operand" "")
1981                           (const_int 1))
1982                       (label_ref (match_operand 1 "" ""))
1983                       (pc)))
1984    (set (match_dup 0)
1985         (plus (match_dup 0)
1986               (const_int -1)))
1987    (unspec [(const_int 0)] UNSPEC_LSETUP_END)
1988    (clobber (match_scratch:SI 2 "=&r"))]
1989   "splitting_loops"
1990   [(set (match_dup 2) (match_dup 0))
1991    (set (match_dup 2) (plus:SI (match_dup 2) (const_int -1)))
1992    (set (match_dup 0) (match_dup 2))
1993    (set (reg:BI REG_CC) (eq:BI (match_dup 2) (const_int 0)))
1994    (set (pc)
1995         (if_then_else (eq (reg:BI REG_CC)
1996                           (const_int 0))
1997                       (label_ref (match_dup 1))
1998                       (pc)))]
1999   "")
2000
2001 (define_insn "lsetup_with_autoinit"
2002   [(set (match_operand:SI 0 "lt_register_operand" "=t")
2003         (label_ref (match_operand 1 "" "")))
2004    (set (match_operand:SI 2 "lb_register_operand" "=u")
2005         (label_ref (match_operand 3 "" "")))
2006    (set (match_operand:SI 4 "lc_register_operand" "=k")
2007         (match_operand:SI 5 "register_operand" "a"))]
2008   ""
2009   "LSETUP (%1, %3) %4 = %5;"
2010   [(set_attr "length" "4")])
2011
2012 (define_insn "lsetup_without_autoinit"
2013   [(set (match_operand:SI 0 "lt_register_operand" "=t")
2014         (label_ref (match_operand 1 "" "")))
2015    (set (match_operand:SI 2 "lb_register_operand" "=u")
2016         (label_ref (match_operand 3 "" "")))
2017    (use (match_operand:SI 4 "lc_register_operand" "k"))]
2018   ""
2019   "LSETUP (%1, %3) %4;"
2020   [(set_attr "length" "4")])
2021
2022 ;;  Call instructions..
2023
2024 ;; The explicit MEM inside the UNSPEC prevents the compiler from moving
2025 ;; the load before a branch after a NULL test, or before a store that
2026 ;; initializes a function descriptor.
2027
2028 (define_insn_and_split "load_funcdescsi"
2029   [(set (match_operand:SI 0 "register_operand" "=a")
2030         (unspec_volatile:SI [(mem:SI (match_operand:SI 1 "address_operand" "p"))]
2031                             UNSPEC_VOLATILE_LOAD_FUNCDESC))]
2032   ""
2033   "#"
2034   "reload_completed"
2035   [(set (match_dup 0) (mem:SI (match_dup 1)))])
2036
2037 (define_expand "call"
2038   [(parallel [(call (match_operand:SI 0 "" "")
2039                     (match_operand 1 "" ""))
2040               (use (match_operand 2 "" ""))])]
2041   ""
2042 {
2043   bfin_expand_call (NULL_RTX, operands[0], operands[1], operands[2], 0);
2044   DONE;
2045 })
2046
2047 (define_expand "sibcall"
2048   [(parallel [(call (match_operand:SI 0 "" "")
2049                     (match_operand 1 "" ""))
2050               (use (match_operand 2 "" ""))
2051               (return)])]
2052   ""
2053 {
2054   bfin_expand_call (NULL_RTX, operands[0], operands[1], operands[2], 1);
2055   DONE;
2056 })
2057
2058 (define_expand "call_value"
2059   [(parallel [(set (match_operand 0 "register_operand" "")
2060                    (call (match_operand:SI 1 "" "")
2061                          (match_operand 2 "" "")))
2062               (use (match_operand 3 "" ""))])]
2063   ""
2064 {
2065   bfin_expand_call (operands[0], operands[1], operands[2], operands[3], 0);
2066   DONE;
2067 })
2068
2069 (define_expand "sibcall_value"
2070   [(parallel [(set (match_operand 0 "register_operand" "")
2071                    (call (match_operand:SI 1 "" "")
2072                          (match_operand 2 "" "")))
2073               (use (match_operand 3 "" ""))
2074               (return)])]
2075   ""
2076 {
2077   bfin_expand_call (operands[0], operands[1], operands[2], operands[3], 1);
2078   DONE;
2079 })
2080
2081 (define_insn "*call_symbol_fdpic"
2082   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "Q"))
2083          (match_operand 1 "general_operand" "g"))
2084    (use (match_operand:SI 2 "register_operand" "Z"))
2085    (use (match_operand 3 "" ""))
2086    (clobber (reg:SI REG_RETS))]
2087   "! SIBLING_CALL_P (insn)
2088    && GET_CODE (operands[0]) == SYMBOL_REF
2089    && !bfin_longcall_p (operands[0], INTVAL (operands[3]))"
2090   "call %0;"
2091   [(set_attr "type" "call")
2092    (set_attr "length" "4")])
2093
2094 (define_insn "*sibcall_symbol_fdpic"
2095   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "Q"))
2096          (match_operand 1 "general_operand" "g"))
2097    (use (match_operand:SI 2 "register_operand" "Z"))
2098    (use (match_operand 3 "" ""))
2099    (return)]
2100   "SIBLING_CALL_P (insn)
2101    && GET_CODE (operands[0]) == SYMBOL_REF
2102    && !bfin_longcall_p (operands[0], INTVAL (operands[3]))"
2103   "jump.l %0;"
2104   [(set_attr "type" "br")
2105    (set_attr "length" "4")])
2106
2107 (define_insn "*call_value_symbol_fdpic"
2108   [(set (match_operand 0 "register_operand" "=d")
2109         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "Q"))
2110               (match_operand 2 "general_operand" "g")))
2111    (use (match_operand:SI 3 "register_operand" "Z"))
2112    (use (match_operand 4 "" ""))
2113    (clobber (reg:SI REG_RETS))]
2114   "! SIBLING_CALL_P (insn)
2115    && GET_CODE (operands[1]) == SYMBOL_REF
2116    && !bfin_longcall_p (operands[1], INTVAL (operands[4]))"
2117   "call %1;"
2118   [(set_attr "type" "call")
2119    (set_attr "length" "4")])
2120
2121 (define_insn "*sibcall_value_symbol_fdpic"
2122   [(set (match_operand 0 "register_operand" "=d")
2123          (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "Q"))
2124                (match_operand 2 "general_operand" "g")))
2125    (use (match_operand:SI 3 "register_operand" "Z"))
2126    (use (match_operand 4 "" ""))
2127    (return)]
2128   "SIBLING_CALL_P (insn)
2129    && GET_CODE (operands[1]) == SYMBOL_REF
2130    && !bfin_longcall_p (operands[1], INTVAL (operands[4]))"
2131   "jump.l %1;"
2132   [(set_attr "type" "br")
2133    (set_attr "length" "4")])
2134
2135 (define_insn "*call_insn_fdpic"
2136   [(call (mem:SI (match_operand:SI 0 "register_no_elim_operand" "Y"))
2137          (match_operand 1 "general_operand" "g"))
2138    (use (match_operand:SI 2 "register_operand" "Z"))
2139    (use (match_operand 3 "" ""))
2140    (clobber (reg:SI REG_RETS))]
2141   "! SIBLING_CALL_P (insn)"
2142   "call (%0);"
2143   [(set_attr "type" "call")
2144    (set_attr "length" "2")])
2145
2146 (define_insn "*sibcall_insn_fdpic"
2147   [(call (mem:SI (match_operand:SI 0 "register_no_elim_operand" "Y"))
2148          (match_operand 1 "general_operand" "g"))
2149    (use (match_operand:SI 2 "register_operand" "Z"))
2150    (use (match_operand 3 "" ""))
2151    (return)]
2152   "SIBLING_CALL_P (insn)"
2153   "jump (%0);"
2154   [(set_attr "type" "br")
2155    (set_attr "length" "2")])
2156
2157 (define_insn "*call_value_insn_fdpic"
2158   [(set (match_operand 0 "register_operand" "=d")
2159         (call (mem:SI (match_operand:SI 1 "register_no_elim_operand" "Y"))
2160               (match_operand 2 "general_operand" "g")))
2161    (use (match_operand:SI 3 "register_operand" "Z"))
2162    (use (match_operand 4 "" ""))
2163    (clobber (reg:SI REG_RETS))]
2164   "! SIBLING_CALL_P (insn)"
2165   "call (%1);"
2166   [(set_attr "type" "call")
2167    (set_attr "length" "2")])
2168
2169 (define_insn "*sibcall_value_insn_fdpic"
2170   [(set (match_operand 0 "register_operand" "=d")
2171          (call (mem:SI (match_operand:SI 1 "register_no_elim_operand" "Y"))
2172                (match_operand 2 "general_operand" "g")))
2173    (use (match_operand:SI 3 "register_operand" "Z"))
2174    (use (match_operand 4 "" ""))
2175    (return)]
2176   "SIBLING_CALL_P (insn)"
2177   "jump (%1);"
2178   [(set_attr "type" "br")
2179    (set_attr "length" "2")])
2180
2181 (define_insn "*call_symbol"
2182   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "Q"))
2183          (match_operand 1 "general_operand" "g"))
2184    (use (match_operand 2 "" ""))
2185    (clobber (reg:SI REG_RETS))]
2186   "! SIBLING_CALL_P (insn)
2187    && (!TARGET_ID_SHARED_LIBRARY || TARGET_LEAF_ID_SHARED_LIBRARY)
2188    && GET_CODE (operands[0]) == SYMBOL_REF
2189    && !bfin_longcall_p (operands[0], INTVAL (operands[2]))"
2190   "call %0;"
2191   [(set_attr "type" "call")
2192    (set_attr "length" "4")])
2193
2194 (define_insn "*sibcall_symbol"
2195   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "Q"))
2196          (match_operand 1 "general_operand" "g"))
2197    (use (match_operand 2 "" ""))
2198    (return)]
2199   "SIBLING_CALL_P (insn)
2200    && (!TARGET_ID_SHARED_LIBRARY || TARGET_LEAF_ID_SHARED_LIBRARY)
2201    && GET_CODE (operands[0]) == SYMBOL_REF
2202    && !bfin_longcall_p (operands[0], INTVAL (operands[2]))"
2203   "jump.l %0;"
2204   [(set_attr "type" "br")
2205    (set_attr "length" "4")])
2206
2207 (define_insn "*call_value_symbol"
2208   [(set (match_operand 0 "register_operand" "=d")
2209         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "Q"))
2210               (match_operand 2 "general_operand" "g")))
2211    (use (match_operand 3 "" ""))
2212    (clobber (reg:SI REG_RETS))]
2213   "! SIBLING_CALL_P (insn)
2214    && (!TARGET_ID_SHARED_LIBRARY || TARGET_LEAF_ID_SHARED_LIBRARY)
2215    && GET_CODE (operands[1]) == SYMBOL_REF
2216    && !bfin_longcall_p (operands[1], INTVAL (operands[3]))"
2217   "call %1;"
2218   [(set_attr "type" "call")
2219    (set_attr "length" "4")])
2220
2221 (define_insn "*sibcall_value_symbol"
2222   [(set (match_operand 0 "register_operand" "=d")
2223          (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "Q"))
2224                (match_operand 2 "general_operand" "g")))
2225    (use (match_operand 3 "" ""))
2226    (return)]
2227   "SIBLING_CALL_P (insn)
2228    && (!TARGET_ID_SHARED_LIBRARY || TARGET_LEAF_ID_SHARED_LIBRARY)
2229    && GET_CODE (operands[1]) == SYMBOL_REF
2230    && !bfin_longcall_p (operands[1], INTVAL (operands[3]))"
2231   "jump.l %1;"
2232   [(set_attr "type" "br")
2233    (set_attr "length" "4")])
2234
2235 (define_insn "*call_insn"
2236   [(call (mem:SI (match_operand:SI 0 "register_no_elim_operand" "a"))
2237          (match_operand 1 "general_operand" "g"))
2238    (use (match_operand 2 "" ""))
2239    (clobber (reg:SI REG_RETS))]
2240   "! SIBLING_CALL_P (insn)"
2241   "call (%0);"
2242   [(set_attr "type" "call")
2243    (set_attr "length" "2")])
2244
2245 (define_insn "*sibcall_insn"
2246   [(call (mem:SI (match_operand:SI 0 "register_no_elim_operand" "z"))
2247          (match_operand 1 "general_operand" "g"))
2248    (use (match_operand 2 "" ""))
2249    (return)]
2250   "SIBLING_CALL_P (insn)"
2251   "jump (%0);"
2252   [(set_attr "type" "br")
2253    (set_attr "length" "2")])
2254
2255 (define_insn "*call_value_insn"
2256   [(set (match_operand 0 "register_operand" "=d")
2257         (call (mem:SI (match_operand:SI 1 "register_no_elim_operand" "a"))
2258               (match_operand 2 "general_operand" "g")))
2259    (use (match_operand 3 "" ""))
2260    (clobber (reg:SI REG_RETS))]
2261   "! SIBLING_CALL_P (insn)"
2262   "call (%1);"
2263   [(set_attr "type" "call")
2264    (set_attr "length" "2")])
2265
2266 (define_insn "*sibcall_value_insn"
2267   [(set (match_operand 0 "register_operand" "=d")
2268          (call (mem:SI (match_operand:SI 1 "register_no_elim_operand" "z"))
2269                (match_operand 2 "general_operand" "g")))
2270    (use (match_operand 3 "" ""))
2271    (return)]
2272   "SIBLING_CALL_P (insn)"
2273   "jump (%1);"
2274   [(set_attr "type" "br")
2275    (set_attr "length" "2")])
2276
2277 ;; Block move patterns
2278
2279 ;; We cheat.  This copies one more word than operand 2 indicates.
2280
2281 (define_insn "rep_movsi"
2282   [(set (match_operand:SI 0 "register_operand" "=&a")
2283         (plus:SI (plus:SI (match_operand:SI 3 "register_operand" "0")
2284                           (ashift:SI (match_operand:SI 2 "register_operand" "a")
2285                                      (const_int 2)))
2286                  (const_int 4)))
2287    (set (match_operand:SI 1 "register_operand" "=&b")
2288         (plus:SI (plus:SI (match_operand:SI 4 "register_operand" "1")
2289                           (ashift:SI (match_dup 2) (const_int 2)))
2290                  (const_int 4)))
2291    (set (mem:BLK (match_dup 3))
2292         (mem:BLK (match_dup 4)))
2293    (use (match_dup 2))
2294    (clobber (match_scratch:HI 5 "=&d"))
2295    (clobber (reg:SI REG_LT1))
2296    (clobber (reg:SI REG_LC1))
2297    (clobber (reg:SI REG_LB1))]
2298   ""
2299   "%5 = [%4++]; lsetup (1f, 1f) LC1 = %2; 1: MNOP || [%3++] = %5 || %5 = [%4++]; [%3++] = %5;"
2300   [(set_attr "type" "misc")
2301    (set_attr "length" "16")
2302    (set_attr "seq_insns" "multi")])
2303
2304 (define_insn "rep_movhi"
2305   [(set (match_operand:SI 0 "register_operand" "=&a")
2306         (plus:SI (plus:SI (match_operand:SI 3 "register_operand" "0")
2307                           (ashift:SI (match_operand:SI 2 "register_operand" "a")
2308                                      (const_int 1)))
2309                  (const_int 2)))
2310    (set (match_operand:SI 1 "register_operand" "=&b")
2311         (plus:SI (plus:SI (match_operand:SI 4 "register_operand" "1")
2312                           (ashift:SI (match_dup 2) (const_int 1)))
2313                  (const_int 2)))
2314    (set (mem:BLK (match_dup 3))
2315         (mem:BLK (match_dup 4)))
2316    (use (match_dup 2))
2317    (clobber (match_scratch:HI 5 "=&d"))
2318    (clobber (reg:SI REG_LT1))
2319    (clobber (reg:SI REG_LC1))
2320    (clobber (reg:SI REG_LB1))]
2321   ""
2322   "%h5 = W[%4++]; lsetup (1f, 1f) LC1 = %2; 1: MNOP || W [%3++] = %5 || %h5 = W [%4++]; W [%3++] = %5;"
2323   [(set_attr "type" "misc")
2324    (set_attr "length" "16")
2325    (set_attr "seq_insns" "multi")])
2326
2327 (define_expand "movmemsi"
2328   [(match_operand:BLK 0 "general_operand" "")
2329    (match_operand:BLK 1 "general_operand" "")
2330    (match_operand:SI 2 "const_int_operand" "")
2331    (match_operand:SI 3 "const_int_operand" "")]
2332   ""
2333 {
2334   if (bfin_expand_movmem (operands[0], operands[1], operands[2], operands[3]))
2335     DONE;
2336   FAIL;
2337 })
2338
2339 ;; Conditional branch patterns
2340 ;; The Blackfin has only few condition codes: eq, lt, lte, ltu, leu
2341
2342 (define_insn "compare_eq"
2343   [(set (match_operand:BI 0 "register_operand" "=C,C")
2344         (eq:BI (match_operand:SI 1 "register_operand" "d,a")
2345                (match_operand:SI 2 "reg_or_const_int_operand" "dKs3,aKs3")))]
2346   ""
2347   "cc =%1==%2;"
2348   [(set_attr "type" "compare")])
2349
2350 (define_insn "compare_ne"
2351   [(set (match_operand:BI 0 "register_operand" "=C,C")
2352         (ne:BI (match_operand:SI 1 "register_operand" "d,a")
2353                (match_operand:SI 2 "reg_or_const_int_operand" "dKs3,aKs3")))]
2354   "0"
2355   "cc =%1!=%2;"
2356   [(set_attr "type" "compare")])
2357
2358 (define_insn "compare_lt"
2359   [(set (match_operand:BI 0 "register_operand" "=C,C")
2360         (lt:BI (match_operand:SI 1 "register_operand" "d,a")
2361                (match_operand:SI 2 "reg_or_const_int_operand" "dKs3,aKs3")))]
2362   ""
2363   "cc =%1<%2;"
2364   [(set_attr "type" "compare")])
2365
2366 (define_insn "compare_le"
2367   [(set (match_operand:BI 0 "register_operand" "=C,C")
2368         (le:BI (match_operand:SI 1 "register_operand" "d,a")
2369                (match_operand:SI 2 "reg_or_const_int_operand" "dKs3,aKs3")))]
2370   ""
2371   "cc =%1<=%2;"
2372   [(set_attr "type" "compare")])
2373
2374 (define_insn "compare_leu"
2375   [(set (match_operand:BI 0 "register_operand" "=C,C")
2376         (leu:BI (match_operand:SI 1 "register_operand" "d,a")
2377                 (match_operand:SI 2 "reg_or_const_int_operand" "dKu3,aKu3")))]
2378   ""
2379   "cc =%1<=%2 (iu);"
2380   [(set_attr "type" "compare")])
2381
2382 (define_insn "compare_ltu"
2383   [(set (match_operand:BI 0 "register_operand" "=C,C")
2384         (ltu:BI (match_operand:SI 1 "register_operand" "d,a")
2385                 (match_operand:SI 2 "reg_or_const_int_operand" "dKu3,aKu3")))]
2386   ""
2387   "cc =%1<%2 (iu);"
2388   [(set_attr "type" "compare")])
2389
2390 ;; Same as above, but and CC with the overflow bit generated by the first
2391 ;; multiplication.
2392 (define_insn "flag_mul_macv2hi_parts_acconly_andcc0"
2393   [(set (match_operand:PDI 0 "register_operand" "=B,e,e")
2394         (unspec:PDI [(vec_select:HI
2395                       (match_operand:V2HI 2 "register_operand" "d,d,d")
2396                       (parallel [(match_operand 4 "const01_operand" "P0P1,P0P1,P0P1")]))
2397                      (vec_select:HI
2398                       (match_operand:V2HI 3 "register_operand" "d,d,d")
2399                       (parallel [(match_operand 6 "const01_operand" "P0P1,P0P1,P0P1")]))
2400                      (match_operand 10 "const_int_operand" "PB,PA,PA")]
2401                     UNSPEC_MUL_WITH_FLAG))
2402    (set (match_operand:PDI 1 "register_operand" "=B,e,e")
2403         (unspec:PDI [(vec_select:HI
2404                       (match_dup 2)
2405                       (parallel [(match_operand 5 "const01_operand" "P0P1,P0P1,P0P1")]))
2406                      (vec_select:HI
2407                       (match_dup 3)
2408                       (parallel [(match_operand 7 "const01_operand" "P0P1,P0P1,P0P1")]))
2409                      (match_operand:PDI 8 "register_operand" "1,1,1")
2410                      (match_operand 9 "const01_operand" "P0P1,P0P1,P0P1")
2411                      (match_operand 11 "const_int_operand" "PA,PB,PA")]
2412                     UNSPEC_MAC_WITH_FLAG))
2413    (set (reg:BI REG_CC)
2414         (and:BI (reg:BI REG_CC)
2415                 (unspec:BI [(vec_select:HI (match_dup 2) (parallel [(match_dup 4)]))
2416                             (vec_select:HI (match_dup 3) (parallel [(match_dup 6)]))
2417                             (match_dup 10)]
2418                            UNSPEC_MUL_WITH_FLAG)))]
2419   "MACFLAGS_MATCH_P (INTVAL (operands[10]), INTVAL (operands[11]))"
2420 {
2421   rtx xops[6];
2422   const char *templates[] = {
2423     "%0 = %h2 * %h3, %1 %b4 %h2 * %h3 %M5;\n\tCC &= %v0;",
2424     "%0 = %d2 * %h3, %1 %b4 %h2 * %h3 %M5;\n\tCC &= %v0;",
2425     "%0 = %h2 * %h3, %1 %b4 %d2 * %h3 %M5;\n\tCC &= %v0;",
2426     "%0 = %d2 * %h3, %1 %b4 %d2 * %h3 %M5;\n\tCC &= %v0;",
2427     "%0 = %h2 * %d3, %1 %b4 %h2 * %h3 %M5;\n\tCC &= %v0;",
2428     "%0 = %d2 * %d3, %1 %b4 %h2 * %h3 %M5;\n\tCC &= %v0;",
2429     "%0 = %h2 * %d3, %1 %b4 %d2 * %h3 %M5;\n\tCC &= %v0;",
2430     "%0 = %d2 * %d3, %1 %b4 %d2 * %h3 %M5;\n\tCC &= %v0;",
2431     "%0 = %h2 * %h3, %1 %b4 %h2 * %d3 %M5;\n\tCC &= %v0;",
2432     "%0 = %d2 * %h3, %1 %b4 %h2 * %d3 %M5;\n\tCC &= %v0;",
2433     "%0 = %h2 * %h3, %1 %b4 %d2 * %d3 %M5;\n\tCC &= %v0;",
2434     "%0 = %d2 * %h3, %1 %b4 %d2 * %d3 %M5;\n\tCC &= %v0;",
2435     "%0 = %h2 * %d3, %1 %b4 %h2 * %d3 %M5;\n\tCC &= %v0;",
2436     "%0 = %d2 * %d3, %1 %b4 %h2 * %d3 %M5;\n\tCC &= %v0;",
2437     "%0 = %h2 * %d3, %1 %b4 %d2 * %d3 %M5;\n\tCC &= %v0;",
2438     "%0 = %d2 * %d3, %1 %b4 %d2 * %d3 %M5;\n\tCC &= %v0;" };
2439   int alt = (INTVAL (operands[4]) + (INTVAL (operands[5]) << 1)
2440              + (INTVAL (operands[6]) << 2)  + (INTVAL (operands[7]) << 3));
2441   xops[0] = operands[0];
2442   xops[1] = operands[1];
2443   xops[2] = operands[2];
2444   xops[3] = operands[3];
2445   xops[4] = operands[9];
2446   xops[5] = which_alternative == 0 ? operands[10] : operands[11];
2447   output_asm_insn (templates[alt], xops);
2448   return "";
2449 }
2450   [(set_attr "type" "misc")
2451    (set_attr "length" "6")
2452    (set_attr "seq_insns" "multi")])
2453
2454 (define_expand "cbranchsi4"
2455   [(set (pc)
2456         (if_then_else (match_operator 0 "ordered_comparison_operator"
2457                        [(match_operand:SI 1 "register_operand" "")
2458                         (match_operand:SI 2 "reg_or_const_int_operand" "")])
2459                    (label_ref (match_operand 3 "" ""))
2460                    (pc)))]
2461   ""
2462 {
2463   rtx bi_compare = bfin_gen_compare (operands[0], SImode);
2464   emit_jump_insn (gen_cbranchbi4 (bi_compare, bfin_cc_rtx, CONST0_RTX (BImode),
2465                                   operands[3]));
2466   DONE;
2467 })
2468
2469 (define_insn "cbranchbi4"
2470   [(set (pc)
2471         (if_then_else
2472          (match_operator 0 "bfin_bimode_comparison_operator"
2473                          [(match_operand:BI 1 "register_operand" "C")
2474                           (match_operand:BI 2 "immediate_operand" "P0")])
2475          (label_ref (match_operand 3 "" ""))
2476          (pc)))]
2477   ""
2478 {
2479   asm_conditional_branch (insn, operands, 0, 0);
2480   return "";
2481 }
2482   [(set_attr "type" "brcc")])
2483
2484 ;; Special cbranch patterns to deal with the speculative load problem - see
2485 ;; bfin_reorg for details.
2486
2487 (define_insn "cbranch_predicted_taken"
2488   [(set (pc)
2489         (if_then_else
2490          (match_operator 0 "bfin_bimode_comparison_operator"
2491                          [(match_operand:BI 1 "register_operand" "C")
2492                           (match_operand:BI 2 "immediate_operand" "P0")])
2493          (label_ref (match_operand 3 "" ""))
2494          (pc)))
2495    (unspec [(const_int 0)] UNSPEC_CBRANCH_TAKEN)]
2496   ""
2497 {
2498   asm_conditional_branch (insn, operands, 0, 1);
2499   return "";
2500 }
2501   [(set_attr "type" "brcc")])
2502
2503 (define_insn "cbranch_with_nops"
2504   [(set (pc)
2505         (if_then_else
2506          (match_operator 0 "bfin_bimode_comparison_operator"
2507                          [(match_operand:BI 1 "register_operand" "C")
2508                           (match_operand:BI 2 "immediate_operand" "P0")])
2509          (label_ref (match_operand 3 "" ""))
2510          (pc)))
2511    (unspec [(match_operand 4 "immediate_operand" "")] UNSPEC_CBRANCH_NOPS)]
2512   "reload_completed"
2513 {
2514   asm_conditional_branch (insn, operands, INTVAL (operands[4]), 0);
2515   return "";
2516 }
2517   [(set_attr "type" "brcc")
2518    (set_attr "length" "8")])
2519
2520 ;; setcc insns.
2521
2522 (define_expand "cstorebi4"
2523   [(set (match_dup 4)
2524         (match_operator:BI 1 "bfin_bimode_comparison_operator"
2525                        [(match_operand:BI 2 "register_operand" "")
2526                         (match_operand:BI 3 "reg_or_const_int_operand" "")]))
2527    (set (match_operand:SI 0 "register_operand" "")
2528        (ne:SI (match_dup 4) (const_int 0)))]
2529   ""
2530 {
2531   /* It could be expanded as a movbisi instruction, but the portable
2532      alternative produces better code.  */
2533   if (GET_CODE (operands[1]) == NE)
2534     FAIL;
2535
2536   operands[4] = bfin_cc_rtx;
2537 })
2538
2539 (define_expand "cstoresi4"
2540   [(set (match_operand:SI 0 "register_operand")
2541         (match_operator:SI 1 "ordered_comparison_operator"
2542                        [(match_operand:SI 2 "register_operand" "")
2543                         (match_operand:SI 3 "reg_or_const_int_operand" "")]))]
2544   ""
2545 {
2546   rtx bi_compare, test;
2547
2548   if (!bfin_direct_comparison_operator (operands[1], SImode))
2549     {
2550       if (!register_operand (operands[3], SImode)
2551           || GET_CODE (operands[1]) == NE)
2552         FAIL;
2553       test = gen_rtx_fmt_ee (swap_condition (GET_CODE (operands[1])),
2554                              SImode, operands[3], operands[2]);
2555     }
2556   else
2557     test = operands[1];
2558
2559   bi_compare = bfin_gen_compare (test, SImode);
2560   gcc_assert (GET_CODE (bi_compare) == NE);
2561   emit_insn (gen_movbisi (operands[0], bfin_cc_rtx));
2562   DONE;
2563 })
2564
2565 (define_insn "nop"
2566   [(const_int 0)]
2567   ""
2568   "nop;")
2569
2570 ;; A nop which stays there when emitted.
2571 (define_insn "forced_nop"
2572   [(unspec [(const_int 0)] UNSPEC_NOP)]
2573   ""
2574   "nop;")
2575
2576 (define_insn "mnop"
2577   [(unspec [(const_int 0)] UNSPEC_32BIT)]
2578   ""
2579   "mnop%!"
2580   [(set_attr "type" "dsp32")])
2581
2582 ;;;;;;;;;;;;;;;;;;;;   CC2dreg   ;;;;;;;;;;;;;;;;;;;;;;;;;
2583 (define_insn "movsibi"
2584   [(set (match_operand:BI 0 "register_operand" "=C")
2585         (ne:BI (match_operand:SI 1 "register_operand" "d")
2586                (const_int 0)))]
2587   ""
2588   "CC = %1;"
2589   [(set_attr "length" "2")])
2590
2591 (define_insn_and_split "movbisi"
2592   [(set (match_operand:SI 0 "register_operand" "=d")
2593         (ne:SI (match_operand:BI 1 "register_operand" "C")
2594                (const_int 0)))]
2595   ""
2596   "#"
2597   ""
2598   [(set (match_operand:SI 0 "register_operand" "")
2599         (zero_extend:SI (match_operand:BI 1 "register_operand" "")))]
2600   "")
2601
2602 (define_insn "notbi"
2603   [(set (match_operand:BI 0 "register_operand" "=C")
2604         (eq:BI (match_operand:BI 1 "register_operand" " 0")
2605                (const_int 0)))]
2606   ""
2607   "%0 = ! %0;"    /*  NOT CC;"  */
2608   [(set_attr "type" "compare")])
2609
2610 ;; Vector and DSP insns
2611
2612 (define_insn ""
2613   [(set (match_operand:SI 0 "register_operand" "=d")
2614         (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "d")
2615                            (const_int 24))
2616                 (lshiftrt:SI (match_operand:SI 2 "register_operand" "d")
2617                              (const_int 8))))]
2618   ""
2619   "%0 = ALIGN8(%1, %2)%!"
2620   [(set_attr "type" "dsp32")])
2621
2622 (define_insn ""
2623   [(set (match_operand:SI 0 "register_operand" "=d")
2624         (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "d")
2625                            (const_int 16))
2626                 (lshiftrt:SI (match_operand:SI 2 "register_operand" "d")
2627                              (const_int 16))))]
2628   ""
2629   "%0 = ALIGN16(%1, %2)%!"
2630   [(set_attr "type" "dsp32")])
2631
2632 (define_insn ""
2633   [(set (match_operand:SI 0 "register_operand" "=d")
2634         (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "d")
2635                            (const_int 8))
2636                 (lshiftrt:SI (match_operand:SI 2 "register_operand" "d")
2637                              (const_int 24))))]
2638   ""
2639   "%0 = ALIGN24(%1, %2)%!"
2640   [(set_attr "type" "dsp32")])
2641
2642 ;; Prologue and epilogue.
2643
2644 (define_expand "prologue"
2645   [(const_int 1)]
2646   ""
2647   "bfin_expand_prologue (); DONE;")
2648
2649 (define_expand "epilogue"
2650   [(const_int 1)]
2651   ""
2652   "bfin_expand_epilogue (1, 0, 0); DONE;")
2653
2654 (define_expand "sibcall_epilogue"
2655   [(const_int 1)]
2656   ""
2657   "bfin_expand_epilogue (0, 0, 1); DONE;")
2658
2659 (define_expand "eh_return"
2660   [(use (match_operand:SI 0 "register_operand" ""))]
2661   ""
2662 {
2663   emit_insn (gen_eh_store_handler (EH_RETURN_HANDLER_RTX, operands[0]));
2664   emit_jump_insn (gen_eh_return_internal ());
2665   emit_barrier ();
2666   DONE;
2667 })
2668
2669 (define_insn "eh_store_handler"
2670   [(unspec_volatile [(match_operand:SI 1 "register_operand" "da")]
2671                     UNSPEC_VOLATILE_STORE_EH_HANDLER)
2672    (clobber (match_operand:SI 0 "memory_operand" "=m"))]
2673   ""
2674   "%0 = %1%!"
2675   [(set_attr "type" "mcst")])
2676
2677 (define_insn_and_split "eh_return_internal"
2678   [(eh_return)]
2679   ""
2680   "#"
2681   "epilogue_completed"
2682   [(const_int 1)]
2683   "bfin_expand_epilogue (1, 1, 0); DONE;")
2684
2685 (define_insn "link"
2686   [(set (mem:SI (plus:SI (reg:SI REG_SP) (const_int -4))) (reg:SI REG_RETS))
2687    (set (mem:SI (plus:SI (reg:SI REG_SP) (const_int -8))) (reg:SI REG_FP))
2688    (set (reg:SI REG_FP)
2689         (plus:SI (reg:SI REG_SP) (const_int -8)))
2690    (set (reg:SI REG_SP)
2691         (plus:SI (reg:SI REG_SP) (match_operand:SI 0 "immediate_operand" "i")))]
2692   ""
2693   "LINK %Z0;"
2694   [(set_attr "length" "4")])
2695
2696 (define_insn "unlink"
2697   [(set (reg:SI REG_FP) (mem:SI (reg:SI REG_FP)))
2698    (set (reg:SI REG_RETS) (mem:SI (plus:SI (reg:SI REG_FP) (const_int 4))))
2699    (set (reg:SI REG_SP) (plus:SI (reg:SI REG_FP) (const_int 8)))]
2700   ""
2701   "UNLINK;"
2702   [(set_attr "length" "4")])
2703
2704 ;; This pattern is slightly clumsy.  The stack adjust must be the final SET in
2705 ;; the pattern, otherwise dwarf2out becomes very confused about which reg goes
2706 ;; where on the stack, since it goes through all elements of the parallel in
2707 ;; sequence.
2708 (define_insn "push_multiple"
2709   [(match_parallel 0 "push_multiple_operation"
2710     [(unspec [(match_operand:SI 1 "immediate_operand" "i")] UNSPEC_PUSH_MULTIPLE)])]
2711   ""
2712 {
2713   output_push_multiple (insn, operands);
2714   return "";
2715 })
2716
2717 (define_insn "pop_multiple"
2718   [(match_parallel 0 "pop_multiple_operation"
2719     [(set (reg:SI REG_SP)
2720           (plus:SI (reg:SI REG_SP) (match_operand:SI 1 "immediate_operand" "i")))])]
2721   ""
2722 {
2723   output_pop_multiple (insn, operands);
2724   return "";
2725 })
2726
2727 (define_insn "return_internal"
2728   [(return)
2729    (use (match_operand 0 "register_operand" ""))]
2730   "reload_completed"
2731 {
2732   switch (REGNO (operands[0]))
2733     {
2734     case REG_RETX:
2735       return "rtx;";
2736     case REG_RETN:
2737       return "rtn;";
2738     case REG_RETI:
2739       return "rti;";
2740     case REG_RETS:
2741       return "rts;";
2742     }
2743   gcc_unreachable ();
2744 })
2745
2746 ;; When used at a location where CC contains 1, causes a speculative load
2747 ;; that is later cancelled.  This is used for certain workarounds in
2748 ;; interrupt handler prologues.
2749 (define_insn "dummy_load"
2750   [(unspec_volatile [(match_operand 0 "register_operand" "a")
2751                      (match_operand 1 "register_operand" "C")]
2752                     UNSPEC_VOLATILE_DUMMY)]
2753   ""
2754   "if cc jump 4;\n\tr7 = [%0];"
2755  [(set_attr "type" "misc")
2756   (set_attr "length" "4")
2757   (set_attr "seq_insns" "multi")])
2758
2759 ;; A placeholder insn inserted before the final scheduling pass.  It is used
2760 ;; to improve scheduling of loads when workarounds for speculative loads are
2761 ;; needed, by not placing them in the first few cycles after a conditional
2762 ;; branch.
2763 (define_insn "stall"
2764   [(unspec_volatile [(match_operand 0 "const_int_operand" "P1P3")]
2765                     UNSPEC_VOLATILE_STALL)]
2766   ""
2767   ""
2768   [(set_attr "type" "stall")])
2769
2770 (define_insn "csync"
2771   [(unspec_volatile [(const_int 0)] UNSPEC_VOLATILE_CSYNC)]
2772   ""
2773   "csync;"
2774   [(set_attr "type" "sync")])
2775
2776 (define_insn "ssync"
2777   [(unspec_volatile [(const_int 0)] UNSPEC_VOLATILE_SSYNC)]
2778   ""
2779   "ssync;"
2780   [(set_attr "type" "sync")])
2781
2782 (define_insn "trap"
2783   [(trap_if (const_int 1) (const_int 3))]
2784   ""
2785   "excpt 3;"
2786   [(set_attr "type" "misc")
2787    (set_attr "length" "2")])
2788
2789 (define_insn "trapifcc"
2790   [(trap_if (reg:BI REG_CC) (const_int 3))]
2791   ""
2792   "if !cc jump 4 (bp); excpt 3;"
2793   [(set_attr "type" "misc")
2794    (set_attr "length" "4")
2795    (set_attr "seq_insns" "multi")])
2796
2797 ;;; Vector instructions
2798
2799 ;; First, all sorts of move variants
2800
2801 (define_insn "movhiv2hi_low"
2802   [(set (match_operand:V2HI 0 "register_operand" "=d")
2803         (vec_concat:V2HI
2804          (match_operand:HI 2 "register_operand" "d")
2805          (vec_select:HI (match_operand:V2HI 1 "register_operand" "0")
2806                         (parallel [(const_int 1)]))))]
2807   ""
2808   "%h0 = %h2 << 0%!"
2809   [(set_attr "type" "dsp32shiftimm")])
2810
2811 (define_insn "movhiv2hi_high"
2812   [(set (match_operand:V2HI 0 "register_operand" "=d")
2813         (vec_concat:V2HI
2814          (vec_select:HI (match_operand:V2HI 1 "register_operand" "0")
2815                         (parallel [(const_int 0)]))
2816          (match_operand:HI 2 "register_operand" "d")))]
2817   ""
2818   "%d0 = %h2 << 0%!"
2819   [(set_attr "type" "dsp32shiftimm")])
2820
2821 ;; No earlyclobber on alternative two since our sequence ought to be safe.
2822 ;; The order of operands is intentional to match the VDSP builtin (high word
2823 ;; is passed first).
2824 (define_insn_and_split "composev2hi"
2825   [(set (match_operand:V2HI 0 "register_operand" "=d,d")
2826         (vec_concat:V2HI (match_operand:HI 2 "register_operand" "0,d")
2827                          (match_operand:HI 1 "register_operand" "d,d")))]
2828   ""
2829   "@
2830    %d0 = %h1 << 0%!
2831    #"
2832   "reload_completed"
2833   [(set (match_dup 0)
2834         (vec_concat:V2HI
2835          (vec_select:HI (match_dup 0) (parallel [(const_int 0)]))
2836          (match_dup 1)))
2837    (set (match_dup 0)
2838         (vec_concat:V2HI
2839          (match_dup 2)
2840          (vec_select:HI (match_dup 0) (parallel [(const_int 1)]))))]
2841   ""
2842   [(set_attr "type" "dsp32shiftimm")])
2843
2844 ; Like composev2hi, but operating on elements of V2HI vectors.
2845 ; Useful on its own, and as a combiner bridge for the multiply and
2846 ; mac patterns.
2847 (define_insn "packv2hi"
2848   [(set (match_operand:V2HI 0 "register_operand" "=d,d,d,d,d,d,d,d")
2849         (vec_concat:V2HI (vec_select:HI
2850                           (match_operand:V2HI 1 "register_operand" "0,0,d,d,d,d,d,d")
2851                           (parallel [(match_operand 3 "const01_operand" "P0,P0,P0,P1,P0,P1,P0,P1")]))
2852                          (vec_select:HI
2853                           (match_operand:V2HI 2 "register_operand" "d,d,0,0,d,d,d,d")
2854                           (parallel [(match_operand 4 "const01_operand" "P0,P1,P1,P1,P0,P0,P1,P1")]))))]
2855   ""
2856   "@
2857    %d0 = %h2 << 0%!
2858    %d0 = %d2 << 0%!
2859    %h0 = %h1 << 0%!
2860    %h0 = %d1 << 0%!
2861    %0 = PACK (%h2,%h1)%!
2862    %0 = PACK (%h2,%d1)%!
2863    %0 = PACK (%d2,%h1)%!
2864    %0 = PACK (%d2,%d1)%!"
2865   [(set_attr "type" "dsp32shiftimm,dsp32shiftimm,dsp32shiftimm,dsp32shiftimm,dsp32,dsp32,dsp32,dsp32")])
2866
2867 (define_insn "movv2hi_hi"
2868   [(set (match_operand:HI 0 "register_operand" "=d,d,d")
2869         (vec_select:HI (match_operand:V2HI 1 "register_operand" "0,d,d")
2870                        (parallel [(match_operand 2 "const01_operand" "P0,P0,P1")])))]
2871   ""
2872   "@
2873    /* optimized out */
2874    %h0 = %h1 << 0%!
2875    %h0 = %d1 << 0%!"
2876   [(set_attr "type" "dsp32shiftimm")])
2877
2878 (define_expand "movv2hi_hi_low"
2879   [(set (match_operand:HI 0 "register_operand" "")
2880         (vec_select:HI (match_operand:V2HI 1 "register_operand" "")
2881                        (parallel [(const_int 0)])))]
2882   ""
2883   "")
2884
2885 (define_expand "movv2hi_hi_high"
2886   [(set (match_operand:HI 0 "register_operand" "")
2887         (vec_select:HI (match_operand:V2HI 1 "register_operand" "")
2888                        (parallel [(const_int 1)])))]
2889   ""
2890   "")
2891
2892 ;; Unusual arithmetic operations on 16-bit registers.
2893
2894 (define_code_iterator sp_or_sm [ss_plus ss_minus])
2895 (define_code_attr spm_string [(ss_plus "+") (ss_minus "-")])
2896 (define_code_attr spm_name [(ss_plus "add") (ss_minus "sub")])
2897
2898 (define_insn "ss<spm_name>hi3"
2899   [(set (match_operand:HI 0 "register_operand" "=d")
2900         (sp_or_sm:HI (match_operand:HI 1 "register_operand" "d")
2901                     (match_operand:HI 2 "register_operand" "d")))]
2902   ""
2903   "%h0 = %h1 <spm_string>  %h2 (S)%!"
2904   [(set_attr "type" "dsp32")])
2905
2906 (define_insn "ss<spm_name>hi3_parts"
2907   [(set (match_operand:HI 0 "register_operand" "=d")
2908         (sp_or_sm:HI (vec_select:HI
2909                       (match_operand:V2HI 1 "register_operand" "d")
2910                       (parallel [(match_operand 3 "const01_operand" "P0P1")]))
2911                      (vec_select:HI
2912                       (match_operand:V2HI 2 "register_operand" "d")
2913                       (parallel [(match_operand 4 "const01_operand" "P0P1")]))))]
2914    ""
2915 {
2916   const char *templates[] = {
2917     "%h0 = %h1 <spm_string> %h2 (S)%!",
2918     "%h0 = %d1 <spm_string> %h2 (S)%!",
2919     "%h0 = %h1 <spm_string> %d2 (S)%!",
2920     "%h0 = %d1 <spm_string> %d2 (S)%!" };
2921   int alt = INTVAL (operands[3]) + (INTVAL (operands[4]) << 1);
2922   return templates[alt];
2923 }
2924   [(set_attr "type" "dsp32")])
2925
2926 (define_insn "ss<spm_name>hi3_low_parts"
2927   [(set (match_operand:V2HI 0 "register_operand" "=d")
2928         (vec_concat:V2HI
2929          (vec_select:HI (match_operand:V2HI 1 "register_operand" "0")
2930                         (parallel [(const_int 0)]))
2931          (sp_or_sm:HI (vec_select:HI
2932                        (match_operand:V2HI 2 "register_operand" "d")
2933                        (parallel [(match_operand 4 "const01_operand" "P0P1")]))
2934                       (vec_select:HI
2935                        (match_operand:V2HI 3 "register_operand" "d")
2936                        (parallel [(match_operand 5 "const01_operand" "P0P1")])))))]
2937    ""
2938 {
2939   const char *templates[] = {
2940     "%h0 = %h2 <spm_string> %h3 (S)%!",
2941     "%h0 = %d2 <spm_string> %h3 (S)%!",
2942     "%h0 = %h2 <spm_string> %d3 (S)%!",
2943     "%h0 = %d2 <spm_string> %d3 (S)%!" };
2944   int alt = INTVAL (operands[4]) + (INTVAL (operands[5]) << 1);
2945   return templates[alt];
2946 }
2947   [(set_attr "type" "dsp32")])
2948
2949 (define_insn "ss<spm_name>hi3_high_parts"
2950   [(set (match_operand:V2HI 0 "register_operand" "=d")
2951         (vec_concat:V2HI
2952          (sp_or_sm:HI (vec_select:HI
2953                        (match_operand:V2HI 2 "register_operand" "d")
2954                        (parallel [(match_operand 4 "const01_operand" "P0P1")]))
2955                       (vec_select:HI
2956                        (match_operand:V2HI 3 "register_operand" "d")
2957                        (parallel [(match_operand 5 "const01_operand" "P0P1")])))
2958          (vec_select:HI (match_operand:V2HI 1 "register_operand" "0")
2959                         (parallel [(const_int 1)]))))]
2960    ""
2961 {
2962   const char *templates[] = {
2963     "%d0 = %h2 <spm_string> %h3 (S)%!",
2964     "%d0 = %d2 <spm_string> %h3 (S)%!",
2965     "%d0 = %h2 <spm_string> %d3 (S)%!",
2966     "%d0 = %d2 <spm_string> %d3 (S)%!" };
2967   int alt = INTVAL (operands[4]) + (INTVAL (operands[5]) << 1);
2968   return templates[alt];
2969 }
2970   [(set_attr "type" "dsp32")])
2971
2972 ;; V2HI vector insns
2973
2974 (define_insn "addv2hi3"
2975   [(set (match_operand:V2HI 0 "register_operand" "=d")
2976         (plus:V2HI (match_operand:V2HI 1 "register_operand" "d")
2977                    (match_operand:V2HI 2 "register_operand" "d")))]
2978   ""
2979   "%0 = %1 +|+ %2%!"
2980   [(set_attr "type" "dsp32")])
2981
2982 (define_insn "ssaddv2hi3"
2983   [(set (match_operand:V2HI 0 "register_operand" "=d")
2984         (ss_plus:V2HI (match_operand:V2HI 1 "register_operand" "d")
2985                       (match_operand:V2HI 2 "register_operand" "d")))]
2986   ""
2987   "%0 = %1 +|+ %2 (S)%!"
2988   [(set_attr "type" "dsp32")])
2989
2990 (define_insn "subv2hi3"
2991   [(set (match_operand:V2HI 0 "register_operand" "=d")
2992         (minus:V2HI (match_operand:V2HI 1 "register_operand" "d")
2993                    (match_operand:V2HI 2 "register_operand" "d")))]
2994   ""
2995   "%0 = %1 -|- %2%!"
2996   [(set_attr "type" "dsp32")])
2997
2998 (define_insn "sssubv2hi3"
2999   [(set (match_operand:V2HI 0 "register_operand" "=d")
3000         (ss_minus:V2HI (match_operand:V2HI 1 "register_operand" "d")
3001                        (match_operand:V2HI 2 "register_operand" "d")))]
3002   ""
3003   "%0 = %1 -|- %2 (S)%!"
3004   [(set_attr "type" "dsp32")])
3005
3006 (define_insn "addsubv2hi3"
3007   [(set (match_operand:V2HI 0 "register_operand" "=d")
3008         (vec_concat:V2HI
3009          (plus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3010                                  (parallel [(const_int 0)]))
3011                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3012                                  (parallel [(const_int 0)])))
3013          (minus:HI (vec_select:HI (match_dup 1) (parallel [(const_int 1)]))
3014                    (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3015   ""
3016   "%0 = %1 +|- %2%!"
3017   [(set_attr "type" "dsp32")])
3018
3019 (define_insn "subaddv2hi3"
3020   [(set (match_operand:V2HI 0 "register_operand" "=d")
3021         (vec_concat:V2HI
3022          (minus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3023                                   (parallel [(const_int 0)]))
3024                    (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3025                                   (parallel [(const_int 0)])))
3026          (plus:HI (vec_select:HI (match_dup 1) (parallel [(const_int 1)]))
3027                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3028   ""
3029   "%0 = %1 -|+ %2%!"
3030   [(set_attr "type" "dsp32")])
3031
3032 (define_insn "ssaddsubv2hi3"
3033   [(set (match_operand:V2HI 0 "register_operand" "=d")
3034         (vec_concat:V2HI
3035          (ss_plus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3036                                     (parallel [(const_int 0)]))
3037                      (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3038                                     (parallel [(const_int 0)])))
3039          (ss_minus:HI (vec_select:HI (match_dup 1) (parallel [(const_int 1)]))
3040                       (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3041   ""
3042   "%0 = %1 +|- %2 (S)%!"
3043   [(set_attr "type" "dsp32")])
3044
3045 (define_insn "sssubaddv2hi3"
3046   [(set (match_operand:V2HI 0 "register_operand" "=d")
3047         (vec_concat:V2HI
3048          (ss_minus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3049                                      (parallel [(const_int 0)]))
3050                       (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3051                                      (parallel [(const_int 0)])))
3052          (ss_plus:HI (vec_select:HI (match_dup 1) (parallel [(const_int 1)]))
3053                      (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3054   ""
3055   "%0 = %1 -|+ %2 (S)%!"
3056   [(set_attr "type" "dsp32")])
3057
3058 (define_insn "sublohiv2hi3"
3059   [(set (match_operand:HI 0 "register_operand" "=d")
3060         (minus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3061                                  (parallel [(const_int 1)]))
3062                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3063                                  (parallel [(const_int 0)]))))]
3064   ""
3065   "%h0 = %d1 - %h2%!"
3066   [(set_attr "type" "dsp32")])
3067
3068 (define_insn "subhilov2hi3"
3069   [(set (match_operand:HI 0 "register_operand" "=d")
3070         (minus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3071                                  (parallel [(const_int 0)]))
3072                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3073                                  (parallel [(const_int 1)]))))]
3074   ""
3075   "%h0 = %h1 - %d2%!"
3076   [(set_attr "type" "dsp32")])
3077
3078 (define_insn "sssublohiv2hi3"
3079   [(set (match_operand:HI 0 "register_operand" "=d")
3080         (ss_minus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3081                                     (parallel [(const_int 1)]))
3082                      (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3083                                     (parallel [(const_int 0)]))))]
3084   ""
3085   "%h0 = %d1 - %h2 (S)%!"
3086   [(set_attr "type" "dsp32")])
3087
3088 (define_insn "sssubhilov2hi3"
3089   [(set (match_operand:HI 0 "register_operand" "=d")
3090         (ss_minus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3091                                     (parallel [(const_int 0)]))
3092                      (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3093                                     (parallel [(const_int 1)]))))]
3094   ""
3095   "%h0 = %h1 - %d2 (S)%!"
3096   [(set_attr "type" "dsp32")])
3097
3098 (define_insn "addlohiv2hi3"
3099   [(set (match_operand:HI 0 "register_operand" "=d")
3100         (plus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3101                                 (parallel [(const_int 1)]))
3102                  (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3103                                 (parallel [(const_int 0)]))))]
3104   ""
3105   "%h0 = %d1 + %h2%!"
3106   [(set_attr "type" "dsp32")])
3107
3108 (define_insn "addhilov2hi3"
3109   [(set (match_operand:HI 0 "register_operand" "=d")
3110         (plus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3111                                 (parallel [(const_int 0)]))
3112                  (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3113                                 (parallel [(const_int 1)]))))]
3114   ""
3115   "%h0 = %h1 + %d2%!"
3116   [(set_attr "type" "dsp32")])
3117
3118 (define_insn "ssaddlohiv2hi3"
3119   [(set (match_operand:HI 0 "register_operand" "=d")
3120         (ss_plus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3121                                    (parallel [(const_int 1)]))
3122                     (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3123                                    (parallel [(const_int 0)]))))]
3124   ""
3125   "%h0 = %d1 + %h2 (S)%!"
3126   [(set_attr "type" "dsp32")])
3127
3128 (define_insn "ssaddhilov2hi3"
3129   [(set (match_operand:HI 0 "register_operand" "=d")
3130         (ss_plus:HI (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3131                                    (parallel [(const_int 0)]))
3132                     (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3133                                    (parallel [(const_int 1)]))))]
3134   ""
3135   "%h0 = %h1 + %d2 (S)%!"
3136   [(set_attr "type" "dsp32")])
3137
3138 (define_insn "sminv2hi3"
3139   [(set (match_operand:V2HI 0 "register_operand" "=d")
3140         (smin:V2HI (match_operand:V2HI 1 "register_operand" "d")
3141                    (match_operand:V2HI 2 "register_operand" "d")))]
3142   ""
3143   "%0 = MIN (%1, %2) (V)%!"
3144   [(set_attr "type" "dsp32")])
3145
3146 (define_insn "smaxv2hi3"
3147   [(set (match_operand:V2HI 0 "register_operand" "=d")
3148         (smax:V2HI (match_operand:V2HI 1 "register_operand" "d")
3149                    (match_operand:V2HI 2 "register_operand" "d")))]
3150   ""
3151   "%0 = MAX (%1, %2) (V)%!"
3152   [(set_attr "type" "dsp32")])
3153
3154 ;; Multiplications.
3155
3156 ;; The Blackfin allows a lot of different options, and we need many patterns to
3157 ;; cover most of the hardware's abilities.
3158 ;; There are a few simple patterns using MULT rtx codes, but most of them use
3159 ;; an unspec with a const_int operand that determines which flag to use in the
3160 ;; instruction.
3161 ;; There are variants for single and parallel multiplications.
3162 ;; There are variants which just use 16-bit lowparts as inputs, and variants
3163 ;; which allow the user to choose just which halves to use as input values.
3164 ;; There are variants which set D registers, variants which set accumulators,
3165 ;; variants which set both, some of them optionally using the accumulators as
3166 ;; inputs for multiply-accumulate operations.
3167
3168 (define_insn "flag_mulhi"
3169   [(set (match_operand:HI 0 "register_operand" "=d")
3170         (unspec:HI [(match_operand:HI 1 "register_operand" "d")
3171                     (match_operand:HI 2 "register_operand" "d")
3172                     (match_operand 3 "const_int_operand" "n")]
3173                    UNSPEC_MUL_WITH_FLAG))]
3174   ""
3175   "%h0 = %h1 * %h2 %M3%!"
3176   [(set_attr "type" "dsp32")])
3177
3178 (define_insn "flag_mulhi_parts"
3179   [(set (match_operand:HI 0 "register_operand" "=d")
3180         (unspec:HI [(vec_select:HI
3181                      (match_operand:V2HI 1 "register_operand" "d")
3182                      (parallel [(match_operand 3 "const01_operand" "P0P1")]))
3183                     (vec_select:HI
3184                      (match_operand:V2HI 2 "register_operand" "d")
3185                      (parallel [(match_operand 4 "const01_operand" "P0P1")]))
3186                     (match_operand 5 "const_int_operand" "n")]
3187                    UNSPEC_MUL_WITH_FLAG))]
3188   ""
3189 {
3190   const char *templates[] = {
3191     "%h0 = %h1 * %h2 %M5%!",
3192     "%h0 = %d1 * %h2 %M5%!",
3193     "%h0 = %h1 * %d2 %M5%!",
3194     "%h0 = %d1 * %d2 %M5%!" };
3195   int alt = INTVAL (operands[3]) + (INTVAL (operands[4]) << 1);
3196   return templates[alt];
3197 }
3198   [(set_attr "type" "dsp32")])
3199
3200 (define_insn "flag_mulhisi"
3201   [(set (match_operand:SI 0 "register_operand" "=d")
3202         (unspec:SI [(match_operand:HI 1 "register_operand" "d")
3203                     (match_operand:HI 2 "register_operand" "d")
3204                     (match_operand 3 "const_int_operand" "n")]
3205                    UNSPEC_MUL_WITH_FLAG))]
3206   ""
3207   "%0 = %h1 * %h2 %M3%!"
3208   [(set_attr "type" "dsp32")])
3209
3210 (define_insn "flag_mulhisi_parts"
3211   [(set (match_operand:SI 0 "register_operand" "=d")
3212         (unspec:SI [(vec_select:HI
3213                      (match_operand:V2HI 1 "register_operand" "d")
3214                      (parallel [(match_operand 3 "const01_operand" "P0P1")]))
3215                     (vec_select:HI
3216                      (match_operand:V2HI 2 "register_operand" "d")
3217                      (parallel [(match_operand 4 "const01_operand" "P0P1")]))
3218                     (match_operand 5 "const_int_operand" "n")]
3219                    UNSPEC_MUL_WITH_FLAG))]
3220   ""
3221 {
3222   const char *templates[] = {
3223     "%0 = %h1 * %h2 %M5%!",
3224     "%0 = %d1 * %h2 %M5%!",
3225     "%0 = %h1 * %d2 %M5%!",
3226     "%0 = %d1 * %d2 %M5%!" };
3227   int alt = INTVAL (operands[3]) + (INTVAL (operands[4]) << 1);
3228   return templates[alt];
3229 }
3230   [(set_attr "type" "dsp32")])
3231
3232 ;; Three alternatives here to cover all possible allocations:
3233 ;; 0. mac flag is usable only for accumulator 1 - use A1 and odd DREG
3234 ;; 1. mac flag is usable for accumulator 0 - use A0 and even DREG
3235 ;; 2. mac flag is usable in any accumulator - use A1 and odd DREG
3236 ;; Other patterns which don't have a DREG destination can collapse cases
3237 ;; 1 and 2 into one.
3238 (define_insn "flag_machi"
3239   [(set (match_operand:HI 0 "register_operand" "=W,D,W")
3240         (unspec:HI [(match_operand:HI 2 "register_operand" "d,d,d")
3241                     (match_operand:HI 3 "register_operand" "d,d,d")
3242                     (match_operand 4 "register_operand" "1,1,1")
3243                     (match_operand 5 "const01_operand" "P0P1,P0P1,P0P1")
3244                     (match_operand 6 "const_int_operand" "PB,PA,PA")]
3245                    UNSPEC_MAC_WITH_FLAG))
3246    (set (match_operand:PDI 1 "register_operand" "=B,A,B")
3247         (unspec:PDI [(match_dup 1) (match_dup 2) (match_dup 3)
3248                      (match_dup 4) (match_dup 5)]
3249                     UNSPEC_MAC_WITH_FLAG))]
3250   ""
3251   "%h0 = (%1 %b5 %h2 * %h3) %M6%!"
3252   [(set_attr "type" "dsp32")])
3253
3254 (define_insn "flag_machi_acconly"
3255   [(set (match_operand:PDI 0 "register_operand" "=B,e")
3256         (unspec:PDI [(match_operand:HI 1 "register_operand" "d,d")
3257                      (match_operand:HI 2 "register_operand" "d,d")
3258                      (match_operand 3 "register_operand" "0,0")
3259                      (match_operand 4 "const01_operand" "P0P1,P0P1")
3260                      (match_operand 5 "const_int_operand" "PB,PA")]
3261                     UNSPEC_MAC_WITH_FLAG))]
3262   ""
3263   "%0 %b4 %h1 * %h2 %M5%!"
3264   [(set_attr "type" "dsp32")])
3265
3266 (define_insn "flag_machi_parts_acconly"
3267   [(set (match_operand:PDI 0 "register_operand" "=B,e")
3268         (unspec:PDI [(vec_select:HI
3269                       (match_operand:V2HI 1 "register_operand" "d,d")
3270                       (parallel [(match_operand 3 "const01_operand" "P0P1,P0P1")]))
3271                      (vec_select:HI
3272                       (match_operand:V2HI 2 "register_operand" "d,d")
3273                       (parallel [(match_operand 4 "const01_operand" "P0P1,P0P1")]))
3274                      (match_operand:PDI 5 "register_operand" "0,0")
3275                      (match_operand 6 "const01_operand" "P0P1,P0P1")
3276                      (match_operand 7 "const_int_operand" "PB,PA")]
3277                     UNSPEC_MAC_WITH_FLAG))]
3278   ""
3279 {
3280   const char *templates[] = {
3281     "%0 %b6 %h1 * %h2 %M7%!",
3282     "%0 %b6 %d1 * %h2 %M7%!",
3283     "%0 %b6 %h1 * %d2 %M7%!",
3284     "%0 %b6 %d1 * %d2 %M7%!"
3285   };
3286   int alt = INTVAL (operands[3]) + (INTVAL (operands[4]) << 1);
3287   return templates[alt];
3288 }
3289   [(set_attr "type" "dsp32")])
3290
3291 (define_insn "flag_macinithi"
3292   [(set (match_operand:HI 0 "register_operand" "=W,D,W")
3293         (unspec:HI [(match_operand:HI 1 "register_operand" "d,d,d")
3294                     (match_operand:HI 2 "register_operand" "d,d,d")
3295                     (match_operand 3 "const_int_operand" "PB,PA,PA")]
3296                    UNSPEC_MAC_WITH_FLAG))
3297    (set (match_operand:PDI 4 "register_operand" "=B,A,B")
3298         (unspec:PDI [(match_dup 1) (match_dup 2) (match_dup 3)]
3299                     UNSPEC_MAC_WITH_FLAG))]
3300   ""
3301   "%h0 = (%4 = %h1 * %h2) %M3%!"
3302   [(set_attr "type" "dsp32")])
3303
3304 (define_insn "flag_macinit1hi"
3305   [(set (match_operand:PDI 0 "register_operand" "=B,e")
3306         (unspec:PDI [(match_operand:HI 1 "register_operand" "d,d")
3307                      (match_operand:HI 2 "register_operand" "d,d")
3308                      (match_operand 3 "const_int_operand" "PB,PA")]
3309                     UNSPEC_MAC_WITH_FLAG))]
3310   ""
3311   "%0 = %h1 * %h2 %M3%!"
3312   [(set_attr "type" "dsp32")])
3313
3314 (define_insn "mulv2hi3"
3315   [(set (match_operand:V2HI 0 "register_operand" "=d")
3316         (mult:V2HI (match_operand:V2HI 1 "register_operand" "d")
3317                    (match_operand:V2HI 2 "register_operand" "d")))]
3318   ""
3319   "%h0 = %h1 * %h2, %d0 = %d1 * %d2 (IS)%!"
3320   [(set_attr "type" "dsp32")])
3321
3322 (define_insn "flag_mulv2hi"
3323   [(set (match_operand:V2HI 0 "register_operand" "=d")
3324         (unspec:V2HI [(match_operand:V2HI 1 "register_operand" "d")
3325                       (match_operand:V2HI 2 "register_operand" "d")
3326                       (match_operand 3 "const_int_operand" "n")]
3327                      UNSPEC_MUL_WITH_FLAG))]
3328   ""
3329   "%h0 = %h1 * %h2, %d0 = %d1 * %d2 %M3%!"
3330   [(set_attr "type" "dsp32")])
3331
3332 (define_insn "flag_mulv2hi_parts"
3333   [(set (match_operand:V2HI 0 "register_operand" "=d")
3334         (unspec:V2HI [(vec_concat:V2HI
3335                        (vec_select:HI
3336                         (match_operand:V2HI 1 "register_operand" "d")
3337                         (parallel [(match_operand 3 "const01_operand" "P0P1")]))
3338                        (vec_select:HI
3339                         (match_dup 1)
3340                         (parallel [(match_operand 4 "const01_operand" "P0P1")])))
3341                       (vec_concat:V2HI
3342                        (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3343                         (parallel [(match_operand 5 "const01_operand" "P0P1")]))
3344                        (vec_select:HI (match_dup 2)
3345                         (parallel [(match_operand 6 "const01_operand" "P0P1")])))
3346                       (match_operand 7 "const_int_operand" "n")]
3347                      UNSPEC_MUL_WITH_FLAG))]
3348   ""
3349 {
3350   const char *templates[] = {
3351     "%h0 = %h1 * %h2, %d0 = %h1 * %h2 %M7%!",
3352     "%h0 = %d1 * %h2, %d0 = %h1 * %h2 %M7%!",
3353     "%h0 = %h1 * %h2, %d0 = %d1 * %h2 %M7%!",
3354     "%h0 = %d1 * %h2, %d0 = %d1 * %h2 %M7%!",
3355     "%h0 = %h1 * %d2, %d0 = %h1 * %h2 %M7%!",
3356     "%h0 = %d1 * %d2, %d0 = %h1 * %h2 %M7%!",
3357     "%h0 = %h1 * %d2, %d0 = %d1 * %h2 %M7%!",
3358     "%h0 = %d1 * %d2, %d0 = %d1 * %h2 %M7%!",
3359     "%h0 = %h1 * %h2, %d0 = %h1 * %d2 %M7%!",
3360     "%h0 = %d1 * %h2, %d0 = %h1 * %d2 %M7%!",
3361     "%h0 = %h1 * %h2, %d0 = %d1 * %d2 %M7%!",
3362     "%h0 = %d1 * %h2, %d0 = %d1 * %d2 %M7%!",
3363     "%h0 = %h1 * %d2, %d0 = %h1 * %d2 %M7%!",
3364     "%h0 = %d1 * %d2, %d0 = %h1 * %d2 %M7%!",
3365     "%h0 = %h1 * %d2, %d0 = %d1 * %d2 %M7%!",
3366     "%h0 = %d1 * %d2, %d0 = %d1 * %d2 %M7%!" };
3367   int alt = (INTVAL (operands[3]) + (INTVAL (operands[4]) << 1)
3368              + (INTVAL (operands[5]) << 2)  + (INTVAL (operands[6]) << 3));
3369   return templates[alt];
3370 }
3371   [(set_attr "type" "dsp32")])
3372
3373 ;; A slightly complicated pattern.
3374 ;; Operand 0 is the halfword output; operand 11 is the accumulator output
3375 ;; Halfword inputs are operands 1 and 2; operands 3, 4, 5 and 6 specify which
3376 ;; parts of these 2x16 bit registers to use.
3377 ;; Operand 7 is the accumulator input.
3378 ;; Operands 8/9 specify whether low/high parts are mac (0) or msu (1)
3379 ;; Operand 10 is the macflag to be used.
3380 (define_insn "flag_macv2hi_parts"
3381   [(set (match_operand:V2HI 0 "register_operand" "=d")
3382         (unspec:V2HI [(vec_concat:V2HI
3383                        (vec_select:HI
3384                         (match_operand:V2HI 1 "register_operand" "d")
3385                         (parallel [(match_operand 3 "const01_operand" "P0P1")]))
3386                        (vec_select:HI
3387                         (match_dup 1)
3388                         (parallel [(match_operand 4 "const01_operand" "P0P1")])))
3389                       (vec_concat:V2HI
3390                        (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3391                         (parallel [(match_operand 5 "const01_operand" "P0P1")]))
3392                        (vec_select:HI (match_dup 2)
3393                         (parallel [(match_operand 6 "const01_operand" "P0P1")])))
3394                       (match_operand:V2PDI 7 "register_operand" "e")
3395                       (match_operand 8 "const01_operand" "P0P1")
3396                       (match_operand 9 "const01_operand" "P0P1")
3397                       (match_operand 10 "const_int_operand" "n")]
3398                      UNSPEC_MAC_WITH_FLAG))
3399    (set (match_operand:V2PDI 11 "register_operand" "=e")
3400         (unspec:V2PDI [(vec_concat:V2HI
3401                         (vec_select:HI (match_dup 1) (parallel [(match_dup 3)]))
3402                         (vec_select:HI (match_dup 1) (parallel [(match_dup 4)])))
3403                        (vec_concat:V2HI
3404                         (vec_select:HI (match_dup 2) (parallel [(match_dup 5)]))
3405                         (vec_select:HI (match_dup 2) (parallel [(match_dup 5)])))
3406                        (match_dup 7) (match_dup 8) (match_dup 9) (match_dup 10)]
3407                       UNSPEC_MAC_WITH_FLAG))]
3408   ""
3409 {
3410   const char *templates[] = {
3411     "%h0 = (A0 %b8 %h1 * %h2), %d0 = (A1 %b9 %h1 * %h2) %M10%!",
3412     "%h0 = (A0 %b8 %d1 * %h2), %d0 = (A1 %b9 %h1 * %h2) %M10%!",
3413     "%h0 = (A0 %b8 %h1 * %h2), %d0 = (A1 %b9 %d1 * %h2) %M10%!",
3414     "%h0 = (A0 %b8 %d1 * %h2), %d0 = (A1 %b9 %d1 * %h2) %M10%!",
3415     "%h0 = (A0 %b8 %h1 * %d2), %d0 = (A1 %b9 %h1 * %h2) %M10%!",
3416     "%h0 = (A0 %b8 %d1 * %d2), %d0 = (A1 %b9 %h1 * %h2) %M10%!",
3417     "%h0 = (A0 %b8 %h1 * %d2), %d0 = (A1 %b9 %d1 * %h2) %M10%!",
3418     "%h0 = (A0 %b8 %d1 * %d2), %d0 = (A1 %b9 %d1 * %h2) %M10%!",
3419     "%h0 = (A0 %b8 %h1 * %h2), %d0 = (A1 %b9 %h1 * %d2) %M10%!",
3420     "%h0 = (A0 %b8 %d1 * %h2), %d0 = (A1 %b9 %h1 * %d2) %M10%!",
3421     "%h0 = (A0 %b8 %h1 * %h2), %d0 = (A1 %b9 %d1 * %d2) %M10%!",
3422     "%h0 = (A0 %b8 %d1 * %h2), %d0 = (A1 %b9 %d1 * %d2) %M10%!",
3423     "%h0 = (A0 %b8 %h1 * %d2), %d0 = (A1 %b9 %h1 * %d2) %M10%!",
3424     "%h0 = (A0 %b8 %d1 * %d2), %d0 = (A1 %b9 %h1 * %d2) %M10%!",
3425     "%h0 = (A0 %b8 %h1 * %d2), %d0 = (A1 %b9 %d1 * %d2) %M10%!",
3426     "%h0 = (A0 %b8 %d1 * %d2), %d0 = (A1 %b9 %d1 * %d2) %M10%!" };
3427   int alt = (INTVAL (operands[3]) + (INTVAL (operands[4]) << 1)
3428              + (INTVAL (operands[5]) << 2)  + (INTVAL (operands[6]) << 3));
3429   return templates[alt];
3430 }
3431   [(set_attr "type" "dsp32")])
3432
3433 (define_insn "flag_macv2hi_parts_acconly"
3434   [(set (match_operand:V2PDI 0 "register_operand" "=e")
3435         (unspec:V2PDI [(vec_concat:V2HI
3436                         (vec_select:HI
3437                          (match_operand:V2HI 1 "register_operand" "d")
3438                          (parallel [(match_operand 3 "const01_operand" "P0P1")]))
3439                         (vec_select:HI
3440                          (match_dup 1)
3441                          (parallel [(match_operand 4 "const01_operand" "P0P1")])))
3442                        (vec_concat:V2HI
3443                         (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3444                                        (parallel [(match_operand 5 "const01_operand" "P0P1")]))
3445                         (vec_select:HI (match_dup 2)
3446                                        (parallel [(match_operand 6 "const01_operand" "P0P1")])))
3447                        (match_operand:V2PDI 7 "register_operand" "e")
3448                        (match_operand 8 "const01_operand" "P0P1")
3449                        (match_operand 9 "const01_operand" "P0P1")
3450                        (match_operand 10 "const_int_operand" "n")]
3451                       UNSPEC_MAC_WITH_FLAG))]
3452   ""
3453 {
3454   const char *templates[] = {
3455     "A0 %b8 %h1 * %h2, A1 %b9 %h1 * %h2 %M10%!",
3456     "A0 %b8 %d1 * %h2, A1 %b9 %h1 * %h2 %M10%!",
3457     "A0 %b8 %h1 * %h2, A1 %b9 %d1 * %h2 %M10%!",
3458     "A0 %b8 %d1 * %h2, A1 %b9 %d1 * %h2 %M10%!",
3459     "A0 %b8 %h1 * %d2, A1 %b9 %h1 * %h2 %M10%!",
3460     "A0 %b8 %d1 * %d2, A1 %b9 %h1 * %h2 %M10%!",
3461     "A0 %b8 %h1 * %d2, A1 %b9 %d1 * %h2 %M10%!",
3462     "A0 %b8 %d1 * %d2, A1 %b9 %d1 * %h2 %M10%!",
3463     "A0 %b8 %h1 * %h2, A1 %b9 %h1 * %d2 %M10%!",
3464     "A0 %b8 %d1 * %h2, A1 %b9 %h1 * %d2 %M10%!",
3465     "A0 %b8 %h1 * %h2, A1 %b9 %d1 * %d2 %M10%!",
3466     "A0 %b8 %d1 * %h2, A1 %b9 %d1 * %d2 %M10%!",
3467     "A0 %b8 %h1 * %d2, A1 %b9 %h1 * %d2 %M10%!",
3468     "A0 %b8 %d1 * %d2, A1 %b9 %h1 * %d2 %M10%!",
3469     "A0 %b8 %h1 * %d2, A1 %b9 %d1 * %d2 %M10%!",
3470     "A0 %b8 %d1 * %d2, A1 %b9 %d1 * %d2 %M10%!" };
3471   int alt = (INTVAL (operands[3]) + (INTVAL (operands[4]) << 1)
3472              + (INTVAL (operands[5]) << 2)  + (INTVAL (operands[6]) << 3));
3473   return templates[alt];
3474 }
3475   [(set_attr "type" "dsp32")])
3476
3477 ;; Same as above, but initializing the accumulators and therefore a couple fewer
3478 ;; necessary operands.
3479 (define_insn "flag_macinitv2hi_parts"
3480   [(set (match_operand:V2HI 0 "register_operand" "=d")
3481         (unspec:V2HI [(vec_concat:V2HI
3482                        (vec_select:HI
3483                         (match_operand:V2HI 1 "register_operand" "d")
3484                         (parallel [(match_operand 3 "const01_operand" "P0P1")]))
3485                        (vec_select:HI
3486                         (match_dup 1)
3487                         (parallel [(match_operand 4 "const01_operand" "P0P1")])))
3488                       (vec_concat:V2HI
3489                        (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3490                         (parallel [(match_operand 5 "const01_operand" "P0P1")]))
3491                        (vec_select:HI (match_dup 2)
3492                         (parallel [(match_operand 6 "const01_operand" "P0P1")])))
3493                       (match_operand 7 "const_int_operand" "n")]
3494                      UNSPEC_MAC_WITH_FLAG))
3495    (set (match_operand:V2PDI 8 "register_operand" "=e")
3496         (unspec:V2PDI [(vec_concat:V2HI
3497                         (vec_select:HI (match_dup 1) (parallel [(match_dup 3)]))
3498                         (vec_select:HI (match_dup 1) (parallel [(match_dup 4)])))
3499                        (vec_concat:V2HI
3500                         (vec_select:HI (match_dup 2) (parallel [(match_dup 5)]))
3501                         (vec_select:HI (match_dup 2) (parallel [(match_dup 5)])))
3502                        (match_dup 7)]
3503                       UNSPEC_MAC_WITH_FLAG))]
3504   ""
3505 {
3506   const char *templates[] = {
3507     "%h0 = (A0 = %h1 * %h2), %d0 = (A1 = %h1 * %h2) %M7%!",
3508     "%h0 = (A0 = %d1 * %h2), %d0 = (A1 = %h1 * %h2) %M7%!",
3509     "%h0 = (A0 = %h1 * %h2), %d0 = (A1 = %d1 * %h2) %M7%!",
3510     "%h0 = (A0 = %d1 * %h2), %d0 = (A1 = %d1 * %h2) %M7%!",
3511     "%h0 = (A0 = %h1 * %d2), %d0 = (A1 = %h1 * %h2) %M7%!",
3512     "%h0 = (A0 = %d1 * %d2), %d0 = (A1 = %h1 * %h2) %M7%!",
3513     "%h0 = (A0 = %h1 * %d2), %d0 = (A1 = %d1 * %h2) %M7%!",
3514     "%h0 = (A0 = %d1 * %d2), %d0 = (A1 = %d1 * %h2) %M7%!",
3515     "%h0 = (A0 = %h1 * %h2), %d0 = (A1 = %h1 * %d2) %M7%!",
3516     "%h0 = (A0 = %d1 * %h2), %d0 = (A1 = %h1 * %d2) %M7%!",
3517     "%h0 = (A0 = %h1 * %h2), %d0 = (A1 = %d1 * %d2) %M7%!",
3518     "%h0 = (A0 = %d1 * %h2), %d0 = (A1 = %d1 * %d2) %M7%!",
3519     "%h0 = (A0 = %h1 * %d2), %d0 = (A1 = %h1 * %d2) %M7%!",
3520     "%h0 = (A0 = %d1 * %d2), %d0 = (A1 = %h1 * %d2) %M7%!",
3521     "%h0 = (A0 = %h1 * %d2), %d0 = (A1 = %d1 * %d2) %M7%!",
3522     "%h0 = (A0 = %d1 * %d2), %d0 = (A1 = %d1 * %d2) %M7%!" };
3523   int alt = (INTVAL (operands[3]) + (INTVAL (operands[4]) << 1)
3524              + (INTVAL (operands[5]) << 2)  + (INTVAL (operands[6]) << 3));
3525   return templates[alt];
3526 }
3527   [(set_attr "type" "dsp32")])
3528
3529 (define_insn "flag_macinit1v2hi_parts"
3530   [(set (match_operand:V2PDI 0 "register_operand" "=e")
3531         (unspec:V2PDI [(vec_concat:V2HI
3532                        (vec_select:HI
3533                         (match_operand:V2HI 1 "register_operand" "d")
3534                         (parallel [(match_operand 3 "const01_operand" "P0P1")]))
3535                        (vec_select:HI
3536                         (match_dup 1)
3537                         (parallel [(match_operand 4 "const01_operand" "P0P1")])))
3538                       (vec_concat:V2HI
3539                        (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3540                         (parallel [(match_operand 5 "const01_operand" "P0P1")]))
3541                        (vec_select:HI (match_dup 2)
3542                         (parallel [(match_operand 6 "const01_operand" "P0P1")])))
3543                       (match_operand 7 "const_int_operand" "n")]
3544                      UNSPEC_MAC_WITH_FLAG))]
3545   ""
3546 {
3547   const char *templates[] = {
3548     "A0 = %h1 * %h2, A1 = %h1 * %h2 %M7%!",
3549     "A0 = %d1 * %h2, A1 = %h1 * %h2 %M7%!",
3550     "A0 = %h1 * %h2, A1 = %d1 * %h2 %M7%!",
3551     "A0 = %d1 * %h2, A1 = %d1 * %h2 %M7%!",
3552     "A0 = %h1 * %d2, A1 = %h1 * %h2 %M7%!",
3553     "A0 = %d1 * %d2, A1 = %h1 * %h2 %M7%!",
3554     "A0 = %h1 * %d2, A1 = %d1 * %h2 %M7%!",
3555     "A0 = %d1 * %d2, A1 = %d1 * %h2 %M7%!",
3556     "A0 = %h1 * %h2, A1 = %h1 * %d2 %M7%!",
3557     "A0 = %d1 * %h2, A1 = %h1 * %d2 %M7%!",
3558     "A0 = %h1 * %h2, A1 = %d1 * %d2 %M7%!",
3559     "A0 = %d1 * %h2, A1 = %d1 * %d2 %M7%!",
3560     "A0 = %h1 * %d2, A1 = %h1 * %d2 %M7%!",
3561     "A0 = %d1 * %d2, A1 = %h1 * %d2 %M7%!",
3562     "A0 = %h1 * %d2, A1 = %d1 * %d2 %M7%!",
3563     "A0 = %d1 * %d2, A1 = %d1 * %d2 %M7%!" };
3564   int alt = (INTVAL (operands[3]) + (INTVAL (operands[4]) << 1)
3565              + (INTVAL (operands[5]) << 2)  + (INTVAL (operands[6]) << 3));
3566   return templates[alt];
3567 }
3568   [(set_attr "type" "dsp32")])
3569
3570 ;; A mixture of multiply and multiply-accumulate for when we only want to
3571 ;; initialize one part.
3572 (define_insn "flag_mul_macv2hi_parts_acconly"
3573   [(set (match_operand:PDI 0 "register_operand" "=B,e,e")
3574         (unspec:PDI [(vec_select:HI
3575                       (match_operand:V2HI 2 "register_operand" "d,d,d")
3576                       (parallel [(match_operand 4 "const01_operand" "P0P1,P0P1,P0P1")]))
3577                      (vec_select:HI
3578                       (match_operand:V2HI 3 "register_operand" "d,d,d")
3579                       (parallel [(match_operand 6 "const01_operand" "P0P1,P0P1,P0P1")]))
3580                      (match_operand 10 "const_int_operand" "PB,PA,PA")]
3581                     UNSPEC_MUL_WITH_FLAG))
3582    (set (match_operand:PDI 1 "register_operand" "=B,e,e")
3583         (unspec:PDI [(vec_select:HI
3584                       (match_dup 2)
3585                       (parallel [(match_operand 5 "const01_operand" "P0P1,P0P1,P0P1")]))
3586                      (vec_select:HI
3587                       (match_dup 3)
3588                       (parallel [(match_operand 7 "const01_operand" "P0P1,P0P1,P0P1")]))
3589                      (match_operand:PDI 8 "register_operand" "1,1,1")
3590                      (match_operand 9 "const01_operand" "P0P1,P0P1,P0P1")
3591                      (match_operand 11 "const_int_operand" "PA,PB,PA")]
3592                     UNSPEC_MAC_WITH_FLAG))]
3593   "MACFLAGS_MATCH_P (INTVAL (operands[10]), INTVAL (operands[11]))"
3594 {
3595   rtx xops[6];
3596   const char *templates[] = {
3597     "%0 = %h2 * %h3, %1 %b4 %h2 * %h3 %M5%!",
3598     "%0 = %d2 * %h3, %1 %b4 %h2 * %h3 %M5%!",
3599     "%0 = %h2 * %h3, %1 %b4 %d2 * %h3 %M5%!",
3600     "%0 = %d2 * %h3, %1 %b4 %d2 * %h3 %M5%!",
3601     "%0 = %h2 * %d3, %1 %b4 %h2 * %h3 %M5%!",
3602     "%0 = %d2 * %d3, %1 %b4 %h2 * %h3 %M5%!",
3603     "%0 = %h2 * %d3, %1 %b4 %d2 * %h3 %M5%!",
3604     "%0 = %d2 * %d3, %1 %b4 %d2 * %h3 %M5%!",
3605     "%0 = %h2 * %h3, %1 %b4 %h2 * %d3 %M5%!",
3606     "%0 = %d2 * %h3, %1 %b4 %h2 * %d3 %M5%!",
3607     "%0 = %h2 * %h3, %1 %b4 %d2 * %d3 %M5%!",
3608     "%0 = %d2 * %h3, %1 %b4 %d2 * %d3 %M5%!",
3609     "%0 = %h2 * %d3, %1 %b4 %h2 * %d3 %M5%!",
3610     "%0 = %d2 * %d3, %1 %b4 %h2 * %d3 %M5%!",
3611     "%0 = %h2 * %d3, %1 %b4 %d2 * %d3 %M5%!",
3612     "%0 = %d2 * %d3, %1 %b4 %d2 * %d3 %M5%!" };
3613   int alt = (INTVAL (operands[4]) + (INTVAL (operands[5]) << 1)
3614              + (INTVAL (operands[6]) << 2)  + (INTVAL (operands[7]) << 3));
3615   xops[0] = operands[0];
3616   xops[1] = operands[1];
3617   xops[2] = operands[2];
3618   xops[3] = operands[3];
3619   xops[4] = operands[9];
3620   xops[5] = which_alternative == 0 ? operands[10] : operands[11];
3621   output_asm_insn (templates[alt], xops);
3622   return "";
3623 }
3624   [(set_attr "type" "dsp32")])
3625
3626
3627 (define_code_iterator s_or_u [sign_extend zero_extend])
3628 (define_code_attr su_optab [(sign_extend "mul")
3629                             (zero_extend "umul")])
3630 (define_code_attr su_modifier [(sign_extend "IS")
3631                                (zero_extend "FU")])
3632
3633 (define_insn "<su_optab>hisi_ll"
3634   [(set (match_operand:SI 0 "register_operand" "=d")
3635         (mult:SI (s_or_u:SI
3636                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "%d")
3637                                  (parallel [(const_int 0)])))
3638                  (s_or_u:SI
3639                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3640                                  (parallel [(const_int 0)])))))]
3641   ""
3642   "%0 = %h1 * %h2 (<su_modifier>)%!"
3643   [(set_attr "type" "dsp32")])
3644
3645 (define_insn "<su_optab>hisi_lh"
3646   [(set (match_operand:SI 0 "register_operand" "=d")
3647         (mult:SI (s_or_u:SI
3648                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3649                                  (parallel [(const_int 0)])))
3650                  (s_or_u:SI
3651                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3652                                  (parallel [(const_int 1)])))))]
3653   ""
3654   "%0 = %h1 * %d2 (<su_modifier>)%!"
3655   [(set_attr "type" "dsp32")])
3656
3657 (define_insn "<su_optab>hisi_hl"
3658   [(set (match_operand:SI 0 "register_operand" "=d")
3659         (mult:SI (s_or_u:SI
3660                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3661                                  (parallel [(const_int 1)])))
3662                  (s_or_u:SI
3663                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3664                                  (parallel [(const_int 0)])))))]
3665   ""
3666   "%0 = %d1 * %h2 (<su_modifier>)%!"
3667   [(set_attr "type" "dsp32")])
3668
3669 (define_insn "<su_optab>hisi_hh"
3670   [(set (match_operand:SI 0 "register_operand" "=d")
3671         (mult:SI (s_or_u:SI
3672                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "%d")
3673                                  (parallel [(const_int 1)])))
3674                  (s_or_u:SI
3675                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3676                                  (parallel [(const_int 1)])))))]
3677   ""
3678   "%0 = %d1 * %d2 (<su_modifier>)%!"
3679   [(set_attr "type" "dsp32")])
3680
3681 ;; Additional variants for signed * unsigned multiply.
3682
3683 (define_insn "usmulhisi_ull"
3684   [(set (match_operand:SI 0 "register_operand" "=W")
3685         (mult:SI (zero_extend:SI
3686                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "%d")
3687                                  (parallel [(const_int 0)])))
3688                  (sign_extend:SI
3689                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3690                                  (parallel [(const_int 0)])))))]
3691   ""
3692   "%0 = %h2 * %h1 (IS,M)%!"
3693   [(set_attr "type" "dsp32")])
3694
3695 (define_insn "usmulhisi_ulh"
3696   [(set (match_operand:SI 0 "register_operand" "=W")
3697         (mult:SI (zero_extend:SI
3698                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3699                                  (parallel [(const_int 0)])))
3700                  (sign_extend:SI
3701                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3702                                  (parallel [(const_int 1)])))))]
3703   ""
3704   "%0 = %d2 * %h1 (IS,M)%!"
3705   [(set_attr "type" "dsp32")])
3706
3707 (define_insn "usmulhisi_uhl"
3708   [(set (match_operand:SI 0 "register_operand" "=W")
3709         (mult:SI (zero_extend:SI
3710                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d")
3711                                  (parallel [(const_int 1)])))
3712                  (sign_extend:SI
3713                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3714                                  (parallel [(const_int 0)])))))]
3715   ""
3716   "%0 = %h2 * %d1 (IS,M)%!"
3717   [(set_attr "type" "dsp32")])
3718
3719 (define_insn "usmulhisi_uhh"
3720   [(set (match_operand:SI 0 "register_operand" "=W")
3721         (mult:SI (zero_extend:SI
3722                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "%d")
3723                                  (parallel [(const_int 1)])))
3724                  (sign_extend:SI
3725                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d")
3726                                  (parallel [(const_int 1)])))))]
3727   ""
3728   "%0 = %d2 * %d1 (IS,M)%!"
3729   [(set_attr "type" "dsp32")])
3730
3731 ;; Parallel versions of these operations.  First, normal signed or unsigned
3732 ;; multiplies.
3733
3734 (define_insn "<su_optab>hisi_ll_lh"
3735   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3736         (mult:SI (s_or_u:SI
3737                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3738                                  (parallel [(const_int 0)])))
3739                  (s_or_u:SI
3740                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3741                                  (parallel [(const_int 0)])))))
3742    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3743         (mult:SI (s_or_u:SI
3744                   (vec_select:HI (match_dup 1) (parallel [(const_int 0)])))
3745                  (s_or_u:SI
3746                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3747   ""
3748   "%0 = %h1 * %h2, %3 = %h1 * %d2 (<su_modifier>)%!"
3749   [(set_attr "type" "dsp32")])
3750
3751 (define_insn "<su_optab>hisi_ll_hl"
3752   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3753         (mult:SI (s_or_u:SI
3754                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3755                                  (parallel [(const_int 0)])))
3756                  (s_or_u:SI
3757                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3758                                  (parallel [(const_int 0)])))))
3759    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3760         (mult:SI (s_or_u:SI
3761                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
3762                  (s_or_u:SI
3763                   (vec_select:HI (match_dup 2) (parallel [(const_int 0)])))))]
3764   ""
3765   "%0 = %h1 * %h2, %3 = %d1 * %h2 (<su_modifier>)%!"
3766   [(set_attr "type" "dsp32")])
3767
3768 (define_insn "<su_optab>hisi_ll_hh"
3769   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3770         (mult:SI (s_or_u:SI
3771                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3772                                  (parallel [(const_int 0)])))
3773                  (s_or_u:SI
3774                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3775                                  (parallel [(const_int 0)])))))
3776    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3777         (mult:SI (s_or_u:SI
3778                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
3779                  (s_or_u:SI
3780                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3781   ""
3782   "%0 = %h1 * %h2, %3 = %d1 * %d2 (<su_modifier>)%!"
3783   [(set_attr "type" "dsp32")])
3784
3785 (define_insn "<su_optab>hisi_lh_hl"
3786   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3787         (mult:SI (s_or_u:SI
3788                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3789                                  (parallel [(const_int 0)])))
3790                  (s_or_u:SI
3791                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3792                                  (parallel [(const_int 1)])))))
3793    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3794         (mult:SI (s_or_u:SI
3795                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
3796                  (s_or_u:SI
3797                   (vec_select:HI (match_dup 2) (parallel [(const_int 0)])))))]
3798   ""
3799   "%0 = %h1 * %d2, %3 = %d1 * %h2 (<su_modifier>)%!"
3800   [(set_attr "type" "dsp32")])
3801
3802 (define_insn "<su_optab>hisi_lh_hh"
3803   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3804         (mult:SI (s_or_u:SI
3805                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3806                                  (parallel [(const_int 0)])))
3807                  (s_or_u:SI
3808                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3809                                  (parallel [(const_int 1)])))))
3810    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3811         (mult:SI (s_or_u:SI
3812                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
3813                  (s_or_u:SI
3814                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3815   ""
3816   "%0 = %h1 * %d2, %3 = %d1 * %d2 (<su_modifier>)%!"
3817   [(set_attr "type" "dsp32")])
3818
3819 (define_insn "<su_optab>hisi_hl_hh"
3820   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3821         (mult:SI (s_or_u:SI
3822                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3823                                  (parallel [(const_int 1)])))
3824                  (s_or_u:SI
3825                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3826                                  (parallel [(const_int 0)])))))
3827    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3828         (mult:SI (s_or_u:SI
3829                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
3830                  (s_or_u:SI
3831                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3832   ""
3833   "%0 = %d1 * %h2, %3 = %d1 * %d2 (<su_modifier>)%!"
3834   [(set_attr "type" "dsp32")])
3835
3836 ;; Special signed * unsigned variants.
3837
3838 (define_insn "usmulhisi_ll_lul"
3839   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3840         (mult:SI (sign_extend:SI
3841                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3842                                  (parallel [(const_int 0)])))
3843                  (sign_extend:SI
3844                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3845                                  (parallel [(const_int 0)])))))
3846    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3847         (mult:SI (sign_extend:SI
3848                   (vec_select:HI (match_dup 1) (parallel [(const_int 0)])))
3849                  (zero_extend:SI
3850                   (vec_select:HI (match_dup 2) (parallel [(const_int 0)])))))]
3851   ""
3852   "%0 = %h1 * %h2, %3 = %h1 * %h2 (IS,M)%!"
3853   [(set_attr "type" "dsp32")])
3854
3855 (define_insn "usmulhisi_ll_luh"
3856   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3857         (mult:SI (sign_extend:SI
3858                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3859                                  (parallel [(const_int 0)])))
3860                  (sign_extend:SI
3861                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3862                                  (parallel [(const_int 0)])))))
3863    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3864         (mult:SI (sign_extend:SI
3865                   (vec_select:HI (match_dup 1) (parallel [(const_int 0)])))
3866                  (zero_extend:SI
3867                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3868   ""
3869   "%0 = %h1 * %h2, %3 = %h1 * %d2 (IS,M)%!"
3870   [(set_attr "type" "dsp32")])
3871
3872 (define_insn "usmulhisi_ll_hul"
3873   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3874         (mult:SI (sign_extend:SI
3875                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3876                                  (parallel [(const_int 0)])))
3877                  (sign_extend:SI
3878                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3879                                  (parallel [(const_int 0)])))))
3880    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3881         (mult:SI (sign_extend:SI
3882                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
3883                  (zero_extend:SI
3884                   (vec_select:HI (match_dup 2) (parallel [(const_int 0)])))))]
3885   ""
3886   "%0 = %h1 * %h2, %3 = %d1 * %h2 (IS,M)%!"
3887   [(set_attr "type" "dsp32")])
3888
3889 (define_insn "usmulhisi_ll_huh"
3890   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3891         (mult:SI (sign_extend:SI
3892                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3893                                  (parallel [(const_int 0)])))
3894                  (sign_extend:SI
3895                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3896                                  (parallel [(const_int 0)])))))
3897    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3898         (mult:SI (sign_extend:SI
3899                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
3900                  (zero_extend:SI
3901                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3902   ""
3903   "%0 = %h1 * %h2, %3 = %d1 * %d2 (IS,M)%!"
3904   [(set_attr "type" "dsp32")])
3905
3906 (define_insn "usmulhisi_lh_lul"
3907   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3908         (mult:SI (sign_extend:SI
3909                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3910                                  (parallel [(const_int 0)])))
3911                  (sign_extend:SI
3912                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3913                                  (parallel [(const_int 1)])))))
3914    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3915         (mult:SI (sign_extend:SI
3916                   (vec_select:HI (match_dup 1) (parallel [(const_int 0)])))
3917                  (zero_extend:SI
3918                   (vec_select:HI (match_dup 2) (parallel [(const_int 0)])))))]
3919   ""
3920   "%0 = %h1 * %d2, %3 = %h1 * %h2 (IS,M)%!"
3921   [(set_attr "type" "dsp32")])
3922
3923 (define_insn "usmulhisi_lh_luh"
3924   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3925         (mult:SI (sign_extend:SI
3926                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3927                                  (parallel [(const_int 0)])))
3928                  (sign_extend:SI
3929                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3930                                  (parallel [(const_int 1)])))))
3931    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3932         (mult:SI (sign_extend:SI
3933                   (vec_select:HI (match_dup 1) (parallel [(const_int 0)])))
3934                  (zero_extend:SI
3935                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3936   ""
3937   "%0 = %h1 * %d2, %3 = %h1 * %d2 (IS,M)%!"
3938   [(set_attr "type" "dsp32")])
3939
3940 (define_insn "usmulhisi_lh_hul"
3941   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3942         (mult:SI (sign_extend:SI
3943                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3944                                  (parallel [(const_int 0)])))
3945                  (sign_extend:SI
3946                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3947                                  (parallel [(const_int 1)])))))
3948    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3949         (mult:SI (sign_extend:SI
3950                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
3951                  (zero_extend:SI
3952                   (vec_select:HI (match_dup 2) (parallel [(const_int 0)])))))]
3953   ""
3954   "%0 = %h1 * %d2, %3 = %d1 * %h2 (IS,M)%!"
3955   [(set_attr "type" "dsp32")])
3956
3957 (define_insn "usmulhisi_lh_huh"
3958   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3959         (mult:SI (sign_extend:SI
3960                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3961                                  (parallel [(const_int 0)])))
3962                  (sign_extend:SI
3963                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3964                                  (parallel [(const_int 1)])))))
3965    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3966         (mult:SI (sign_extend:SI
3967                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
3968                  (zero_extend:SI
3969                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
3970   ""
3971   "%0 = %h1 * %d2, %3 = %d1 * %d2 (IS,M)%!"
3972   [(set_attr "type" "dsp32")])
3973
3974 (define_insn "usmulhisi_hl_lul"
3975   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3976         (mult:SI (sign_extend:SI
3977                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3978                                  (parallel [(const_int 1)])))
3979                  (sign_extend:SI
3980                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3981                                  (parallel [(const_int 0)])))))
3982    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
3983         (mult:SI (sign_extend:SI
3984                   (vec_select:HI (match_dup 1) (parallel [(const_int 0)])))
3985                  (zero_extend:SI
3986                   (vec_select:HI (match_dup 2) (parallel [(const_int 0)])))))]
3987   ""
3988   "%0 = %d1 * %h2, %3 = %h1 * %h2 (IS,M)%!"
3989   [(set_attr "type" "dsp32")])
3990
3991 (define_insn "usmulhisi_hl_luh"
3992   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
3993         (mult:SI (sign_extend:SI
3994                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
3995                                  (parallel [(const_int 1)])))
3996                  (sign_extend:SI
3997                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
3998                                  (parallel [(const_int 0)])))))
3999    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
4000         (mult:SI (sign_extend:SI
4001                   (vec_select:HI (match_dup 1) (parallel [(const_int 0)])))
4002                  (zero_extend:SI
4003                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
4004   ""
4005   "%0 = %d1 * %h2, %3 = %h1 * %d2 (IS,M)%!"
4006   [(set_attr "type" "dsp32")])
4007
4008 (define_insn "usmulhisi_hl_hul"
4009   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
4010         (mult:SI (sign_extend:SI
4011                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
4012                                  (parallel [(const_int 1)])))
4013                  (sign_extend:SI
4014                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
4015                                  (parallel [(const_int 0)])))))
4016    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
4017         (mult:SI (sign_extend:SI
4018                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
4019                  (zero_extend:SI
4020                   (vec_select:HI (match_dup 2) (parallel [(const_int 0)])))))]
4021   ""
4022   "%0 = %d1 * %h2, %3 = %d1 * %h2 (IS,M)%!"
4023   [(set_attr "type" "dsp32")])
4024
4025 (define_insn "usmulhisi_hl_huh"
4026   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
4027         (mult:SI (sign_extend:SI
4028                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
4029                                  (parallel [(const_int 1)])))
4030                  (sign_extend:SI
4031                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
4032                                  (parallel [(const_int 0)])))))
4033    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
4034         (mult:SI (sign_extend:SI
4035                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
4036                  (zero_extend:SI
4037                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
4038   ""
4039   "%0 = %d1 * %h2, %3 = %d1 * %d2 (IS,M)%!"
4040   [(set_attr "type" "dsp32")])
4041
4042 (define_insn "usmulhisi_hh_lul"
4043   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
4044         (mult:SI (sign_extend:SI
4045                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
4046                                  (parallel [(const_int 1)])))
4047                  (sign_extend:SI
4048                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
4049                                  (parallel [(const_int 1)])))))
4050    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
4051         (mult:SI (sign_extend:SI
4052                   (vec_select:HI (match_dup 1) (parallel [(const_int 0)])))
4053                  (zero_extend:SI
4054                   (vec_select:HI (match_dup 2) (parallel [(const_int 0)])))))]
4055   ""
4056   "%0 = %d1 * %d2, %3 = %h1 * %h2 (IS,M)%!"
4057   [(set_attr "type" "dsp32")])
4058
4059 (define_insn "usmulhisi_hh_luh"
4060   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
4061         (mult:SI (sign_extend:SI
4062                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
4063                                  (parallel [(const_int 1)])))
4064                  (sign_extend:SI
4065                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
4066                                  (parallel [(const_int 1)])))))
4067    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
4068         (mult:SI (sign_extend:SI
4069                   (vec_select:HI (match_dup 1) (parallel [(const_int 0)])))
4070                  (zero_extend:SI
4071                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
4072   ""
4073   "%0 = %d1 * %d2, %3 = %h1 * %d2 (IS,M)%!"
4074   [(set_attr "type" "dsp32")])
4075
4076 (define_insn "usmulhisi_hh_hul"
4077   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
4078         (mult:SI (sign_extend:SI
4079                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
4080                                  (parallel [(const_int 1)])))
4081                  (sign_extend:SI
4082                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
4083                                  (parallel [(const_int 1)])))))
4084    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
4085         (mult:SI (sign_extend:SI
4086                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
4087                  (zero_extend:SI
4088                   (vec_select:HI (match_dup 2) (parallel [(const_int 0)])))))]
4089   ""
4090   "%0 = %d1 * %d2, %3 = %d1 * %h2 (IS,M)%!"
4091   [(set_attr "type" "dsp32")])
4092
4093 (define_insn "usmulhisi_hh_huh"
4094   [(set (match_operand:SI 0 "register_operand" "=q0,q2,q4,q6")
4095         (mult:SI (sign_extend:SI
4096                   (vec_select:HI (match_operand:V2HI 1 "register_operand" "d,d,d,d")
4097                                  (parallel [(const_int 1)])))
4098                  (sign_extend:SI
4099                   (vec_select:HI (match_operand:V2HI 2 "register_operand" "d,d,d,d")
4100                                  (parallel [(const_int 1)])))))
4101    (set (match_operand:SI 3 "register_operand" "=q1,q3,q5,q7")
4102         (mult:SI (sign_extend:SI
4103                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
4104                  (zero_extend:SI
4105                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))))]
4106   ""
4107   "%0 = %d1 * %d2, %3 = %d1 * %d2 (IS,M)%!"
4108   [(set_attr "type" "dsp32")])
4109
4110 ;; Vector neg/abs.
4111
4112 (define_insn "ssnegv2hi2"
4113   [(set (match_operand:V2HI 0 "register_operand" "=d")
4114         (ss_neg:V2HI (match_operand:V2HI 1 "register_operand" "d")))]
4115   ""
4116   "%0 = - %1 (V)%!"
4117   [(set_attr "type" "dsp32")])
4118
4119 (define_insn "ssabsv2hi2"
4120   [(set (match_operand:V2HI 0 "register_operand" "=d")
4121         (ss_abs:V2HI (match_operand:V2HI 1 "register_operand" "d")))]
4122   ""
4123   "%0 = ABS %1 (V)%!"
4124   [(set_attr "type" "dsp32")])
4125
4126 ;; Shifts.
4127
4128 (define_insn "ssashiftv2hi3"
4129   [(set (match_operand:V2HI 0 "register_operand" "=d,d,d")
4130         (if_then_else:V2HI
4131          (lt (match_operand:HI 2 "vec_shift_operand" "d,Ku4,Ks4") (const_int 0))
4132          (ashiftrt:V2HI (match_operand:V2HI 1 "register_operand" "d,d,d")
4133                         (match_dup 2))
4134          (ss_ashift:V2HI (match_dup 1) (match_dup 2))))]
4135   ""
4136   "@
4137    %0 = ASHIFT %1 BY %h2 (V, S)%!
4138    %0 = %1 << %2 (V,S)%!
4139    %0 = %1 >>> %N2 (V,S)%!"
4140   [(set_attr "type" "dsp32,dsp32shiftimm,dsp32shiftimm")])
4141
4142 (define_insn "ssashifthi3"
4143   [(set (match_operand:HI 0 "register_operand" "=d,d,d")
4144         (if_then_else:HI
4145          (lt (match_operand:HI 2 "vec_shift_operand" "d,Ku4,Ks4") (const_int 0))
4146          (ashiftrt:HI (match_operand:HI 1 "register_operand" "d,d,d")
4147                       (match_dup 2))
4148          (ss_ashift:HI (match_dup 1) (match_dup 2))))]
4149   ""
4150   "@
4151    %0 = ASHIFT %1 BY %h2 (V, S)%!
4152    %0 = %1 << %2 (V,S)%!
4153    %0 = %1 >>> %N2 (V,S)%!"
4154   [(set_attr "type" "dsp32,dsp32shiftimm,dsp32shiftimm")])
4155
4156 (define_insn "ssashiftsi3"
4157   [(set (match_operand:SI 0 "register_operand" "=d,d,d")
4158         (if_then_else:SI
4159          (lt (match_operand:HI 2 "reg_or_const_int_operand" "d,Ku5,Ks5") (const_int 0))
4160          (ashiftrt:SI (match_operand:HI 1 "register_operand" "d,d,d")
4161                       (match_dup 2))
4162          (ss_ashift:SI (match_dup 1) (match_dup 2))))]
4163   ""
4164   "@
4165    %0 = ASHIFT %1 BY %h2 (S)%!
4166    %0 = %1 << %2 (S)%!
4167    %0 = %1 >>> %N2 (S)%!"
4168   [(set_attr "type" "dsp32,dsp32shiftimm,dsp32shiftimm")])
4169
4170 (define_insn "lshiftv2hi3"
4171   [(set (match_operand:V2HI 0 "register_operand" "=d,d,d")
4172         (if_then_else:V2HI
4173          (lt (match_operand:HI 2 "vec_shift_operand" "d,Ku4,Ks4") (const_int 0))
4174          (lshiftrt:V2HI (match_operand:V2HI 1 "register_operand" "d,d,d")
4175                         (match_dup 2))
4176          (ashift:V2HI (match_dup 1) (match_dup 2))))]
4177   ""
4178   "@
4179    %0 = LSHIFT %1 BY %h2 (V)%!
4180    %0 = %1 << %2 (V)%!
4181    %0 = %1 >> %N2 (V)%!"
4182   [(set_attr "type" "dsp32,dsp32shiftimm,dsp32shiftimm")])
4183
4184 (define_insn "lshifthi3"
4185   [(set (match_operand:HI 0 "register_operand" "=d,d,d")
4186         (if_then_else:HI
4187          (lt (match_operand:HI 2 "vec_shift_operand" "d,Ku4,Ks4") (const_int 0))
4188          (lshiftrt:HI (match_operand:HI 1 "register_operand" "d,d,d")
4189                       (match_dup 2))
4190          (ashift:HI (match_dup 1) (match_dup 2))))]
4191   ""
4192   "@
4193    %0 = LSHIFT %1 BY %h2 (V)%!
4194    %0 = %1 << %2 (V)%!
4195    %0 = %1 >> %N2 (V)%!"
4196   [(set_attr "type" "dsp32,dsp32shiftimm,dsp32shiftimm")])
4197
4198 ;; Load without alignment exception (masking off low bits)
4199
4200 (define_insn "loadbytes"
4201   [(set (match_operand:SI 0 "register_operand" "=d")
4202         (mem:SI (and:SI (match_operand:SI 1 "register_operand" "b")
4203                         (const_int -4))))]
4204   ""
4205   "DISALGNEXCPT || %0 = [%1];"
4206   [(set_attr "type" "mcld")
4207    (set_attr "length" "8")])
4208
4209 (include "sync.md")