OSDN Git Service

* config/xtensa/xtensa.c (xtensa_ld_opcodes, xtensa_st_opcodes): Delete.
[pf3gnuchains/gcc-fork.git] / gcc / config / xtensa / xtensa.md
1 ;; GCC machine description for Tensilica's Xtensa architecture.
2 ;; Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3 ;; Contributed by Bob Wilson (bwilson@tensilica.com) at Tensilica.
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 by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; 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 COPYING.  If not, write to the Free
19 ;; Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 ;; 02111-1307, USA.
21
22
23 (define_constants [
24   (A0_REG               0)
25   (A1_REG               1)
26   (A7_REG               7)
27   (A8_REG               8)
28
29   (UNSPEC_NSAU          1)
30   (UNSPEC_NOP           2)
31   (UNSPEC_PLT           3)
32   (UNSPEC_RET_ADDR      4)
33   (UNSPECV_SET_FP       1)
34   (UNSPECV_ENTRY        2)
35 ])
36
37 \f
38 ;; Attributes.
39
40 (define_attr "type"
41   "unknown,jump,call,load,store,move,arith,multi,nop,farith,fmadd,fdiv,fsqrt,fconv,fload,fstore,mul16,mul32,div32,mac16,rsr,wsr"
42   (const_string "unknown"))
43
44 (define_attr "mode"
45   "unknown,none,QI,HI,SI,DI,SF,DF,BL"
46   (const_string "unknown"))
47
48 (define_attr "length" "" (const_int 1))
49
50 ;; Describe a user's asm statement.
51 (define_asm_attributes
52   [(set_attr "type" "multi")])
53
54 \f
55 ;; Pipeline model.
56
57 ;; The Xtensa basically has simple 5-stage RISC pipeline.
58 ;; Most instructions complete in 1 cycle, and it is OK to assume that
59 ;; everything is fully pipelined.  The exceptions have special insn
60 ;; reservations in the pipeline description below.  The Xtensa can
61 ;; issue one instruction per cycle, so defining CPU units is unnecessary.
62
63 (define_insn_reservation "xtensa_any_insn" 1
64                          (eq_attr "type" "!load,fload,rsr,mul16,mul32,fmadd,fconv")
65                          "nothing")
66
67 (define_insn_reservation "xtensa_memory" 2
68                          (eq_attr "type" "load,fload")
69                          "nothing")
70
71 (define_insn_reservation "xtensa_sreg" 2
72                          (eq_attr "type" "rsr")
73                          "nothing")
74
75 (define_insn_reservation "xtensa_mul16" 2
76                          (eq_attr "type" "mul16")
77                          "nothing")
78
79 (define_insn_reservation "xtensa_mul32" 2
80                          (eq_attr "type" "mul32")
81                          "nothing")
82
83 (define_insn_reservation "xtensa_fmadd" 4
84                          (eq_attr "type" "fmadd")
85                          "nothing")
86
87 (define_insn_reservation "xtensa_fconv" 2
88                          (eq_attr "type" "fconv")
89                          "nothing")
90 \f
91 ;; Addition.
92
93 (define_expand "adddi3"
94   [(set (match_operand:DI 0 "register_operand" "")
95         (plus:DI (match_operand:DI 1 "register_operand" "")
96                  (match_operand:DI 2 "register_operand" "")))]
97   ""
98 {
99   rtx srclo;
100   rtx dstlo = gen_lowpart (SImode, operands[0]);
101   rtx src1lo = gen_lowpart (SImode, operands[1]);
102   rtx src2lo = gen_lowpart (SImode, operands[2]);
103
104   rtx dsthi = gen_highpart (SImode, operands[0]);
105   rtx src1hi = gen_highpart (SImode, operands[1]);
106   rtx src2hi = gen_highpart (SImode, operands[2]);
107
108   /* Either source can be used for overflow checking, as long as it's
109      not clobbered by the first addition.  */
110   if (!rtx_equal_p (dstlo, src1lo))
111     srclo = src1lo;
112   else if (!rtx_equal_p (dstlo, src2lo))
113     srclo = src2lo;
114   else
115     {
116       srclo = gen_reg_rtx (SImode);
117       emit_move_insn (srclo, src1lo);
118     }
119
120   emit_insn (gen_addsi3 (dstlo, src1lo, src2lo));
121   emit_insn (gen_addsi3 (dsthi, src1hi, src2hi));
122   emit_insn (gen_adddi_carry (dsthi, dstlo, srclo));
123   DONE;
124 })
125
126 ;; Represent the add-carry operation as an atomic operation instead of
127 ;; expanding it to a conditional branch.  Otherwise, the edge
128 ;; profiling code breaks because inserting the count increment code
129 ;; causes a new jump insn to be added.
130
131 (define_insn "adddi_carry"
132   [(set (match_operand:SI 0 "register_operand" "+a")
133         (plus:SI (ltu:SI (match_operand:SI 1 "register_operand" "r")
134                          (match_operand:SI 2 "register_operand" "r"))
135                  (match_dup 0)))]
136   ""
137   "bgeu\t%1, %2, 0f\;addi\t%0, %0, 1\;0:"
138   [(set_attr "type"     "multi")
139    (set_attr "mode"     "SI")
140    (set_attr "length"   "6")])
141
142 (define_insn "addsi3"
143   [(set (match_operand:SI 0 "register_operand" "=D,D,a,a,a")
144         (plus:SI (match_operand:SI 1 "register_operand" "%d,d,r,r,r")
145                  (match_operand:SI 2 "add_operand" "d,O,r,J,N")))]
146   ""
147   "@
148    add.n\t%0, %1, %2
149    addi.n\t%0, %1, %d2
150    add\t%0, %1, %2
151    addi\t%0, %1, %d2
152    addmi\t%0, %1, %x2"
153   [(set_attr "type"     "arith,arith,arith,arith,arith")
154    (set_attr "mode"     "SI")
155    (set_attr "length"   "2,2,3,3,3")])
156
157 (define_insn "*addx2"
158   [(set (match_operand:SI 0 "register_operand" "=a")
159         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
160                           (const_int 2))
161                  (match_operand:SI 2 "register_operand" "r")))]
162   "TARGET_ADDX"
163   "addx2\t%0, %1, %2"
164   [(set_attr "type"     "arith")
165    (set_attr "mode"     "SI")
166    (set_attr "length"   "3")])
167
168 (define_insn "*addx4"
169   [(set (match_operand:SI 0 "register_operand" "=a")
170         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
171                           (const_int 4))
172                  (match_operand:SI 2 "register_operand" "r")))]
173   "TARGET_ADDX"
174   "addx4\t%0, %1, %2"
175   [(set_attr "type"     "arith")
176    (set_attr "mode"     "SI")
177    (set_attr "length"   "3")])
178
179 (define_insn "*addx8"
180   [(set (match_operand:SI 0 "register_operand" "=a")
181         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
182                           (const_int 8))
183                  (match_operand:SI 2 "register_operand" "r")))]
184   "TARGET_ADDX"
185   "addx8\t%0, %1, %2"
186   [(set_attr "type"     "arith")
187    (set_attr "mode"     "SI")
188    (set_attr "length"   "3")])
189
190 (define_insn "addsf3"
191   [(set (match_operand:SF 0 "register_operand" "=f")
192         (plus:SF (match_operand:SF 1 "register_operand" "%f")
193                  (match_operand:SF 2 "register_operand" "f")))]
194   "TARGET_HARD_FLOAT"
195   "add.s\t%0, %1, %2"
196   [(set_attr "type"     "fmadd")
197    (set_attr "mode"     "SF")
198    (set_attr "length"   "3")])
199
200 \f
201 ;; Subtraction.
202
203 (define_expand "subdi3"
204   [(set (match_operand:DI 0 "register_operand" "")
205         (minus:DI (match_operand:DI 1 "register_operand" "")
206                   (match_operand:DI 2 "register_operand" "")))]
207   ""
208 {
209   rtx dstlo = gen_lowpart (SImode, operands[0]);
210   rtx src1lo = gen_lowpart (SImode, operands[1]);
211   rtx src2lo = gen_lowpart (SImode, operands[2]);
212
213   rtx dsthi = gen_highpart (SImode, operands[0]);
214   rtx src1hi = gen_highpart (SImode, operands[1]);
215   rtx src2hi = gen_highpart (SImode, operands[2]);
216
217   emit_insn (gen_subsi3 (dsthi, src1hi, src2hi));
218   emit_insn (gen_subdi_carry (dsthi, src1lo, src2lo));
219   emit_insn (gen_subsi3 (dstlo, src1lo, src2lo));
220   DONE;
221 })
222
223 (define_insn "subdi_carry"
224   [(set (match_operand:SI 0 "register_operand" "+a")
225         (minus:SI (match_dup 0)
226                   (ltu:SI (match_operand:SI 1 "register_operand" "r")
227                           (match_operand:SI 2 "register_operand" "r"))))]
228   ""
229   "bgeu\t%1, %2, 0f\;addi\t%0, %0, -1\;0:"
230   [(set_attr "type"     "multi")
231    (set_attr "mode"     "SI")
232    (set_attr "length"   "6")])
233
234 (define_insn "subsi3"
235   [(set (match_operand:SI 0 "register_operand" "=a")
236         (minus:SI (match_operand:SI 1 "register_operand" "r")
237                   (match_operand:SI 2 "register_operand" "r")))]
238   ""
239   "sub\t%0, %1, %2"
240   [(set_attr "type"     "arith")
241    (set_attr "mode"     "SI")
242    (set_attr "length"   "3")])
243
244 (define_insn "*subx2"
245   [(set (match_operand:SI 0 "register_operand" "=a")
246         (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
247                            (const_int 2))
248                   (match_operand:SI 2 "register_operand" "r")))]
249   "TARGET_ADDX"
250   "subx2\t%0, %1, %2"
251   [(set_attr "type"     "arith")
252    (set_attr "mode"     "SI")
253    (set_attr "length"   "3")])
254
255 (define_insn "*subx4"
256   [(set (match_operand:SI 0 "register_operand" "=a")
257         (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
258                            (const_int 4))
259                   (match_operand:SI 2 "register_operand" "r")))]
260   "TARGET_ADDX"
261   "subx4\t%0, %1, %2"
262   [(set_attr "type"     "arith")
263    (set_attr "mode"     "SI")
264    (set_attr "length"   "3")])
265
266 (define_insn "*subx8"
267   [(set (match_operand:SI 0 "register_operand" "=a")
268         (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
269                            (const_int 8))
270                   (match_operand:SI 2 "register_operand" "r")))]
271   "TARGET_ADDX"
272   "subx8\t%0, %1, %2"
273   [(set_attr "type"     "arith")
274    (set_attr "mode"     "SI")
275    (set_attr "length"   "3")])
276
277 (define_insn "subsf3"
278   [(set (match_operand:SF 0 "register_operand" "=f")
279         (minus:SF (match_operand:SF 1 "register_operand" "f")
280                   (match_operand:SF 2 "register_operand" "f")))]
281   "TARGET_HARD_FLOAT"
282   "sub.s\t%0, %1, %2"
283   [(set_attr "type"     "fmadd")
284    (set_attr "mode"     "SF")
285    (set_attr "length"   "3")])
286
287 \f
288 ;; Multiplication.
289
290 (define_insn "mulsi3"
291   [(set (match_operand:SI 0 "register_operand" "=a")
292         (mult:SI (match_operand:SI 1 "register_operand" "%r")
293                  (match_operand:SI 2 "register_operand" "r")))]
294   "TARGET_MUL32"
295   "mull\t%0, %1, %2"
296   [(set_attr "type"     "mul32")
297    (set_attr "mode"     "SI")
298    (set_attr "length"   "3")])
299
300 (define_insn "mulhisi3"
301   [(set (match_operand:SI 0 "register_operand" "=C,A")
302         (mult:SI (sign_extend:SI
303                   (match_operand:HI 1 "register_operand" "%r,r"))
304                  (sign_extend:SI
305                   (match_operand:HI 2 "register_operand" "r,r"))))]
306   "TARGET_MUL16 || TARGET_MAC16"
307   "@
308    mul16s\t%0, %1, %2
309    mul.aa.ll\t%1, %2"
310   [(set_attr "type"     "mul16,mac16")
311    (set_attr "mode"     "SI")
312    (set_attr "length"   "3,3")])
313
314 (define_insn "umulhisi3"
315   [(set (match_operand:SI 0 "register_operand" "=C,A")
316         (mult:SI (zero_extend:SI
317                   (match_operand:HI 1 "register_operand" "%r,r"))
318                  (zero_extend:SI
319                   (match_operand:HI 2 "register_operand" "r,r"))))]
320   "TARGET_MUL16 || TARGET_MAC16"
321   "@
322    mul16u\t%0, %1, %2
323    umul.aa.ll\t%1, %2"
324   [(set_attr "type"     "mul16,mac16")
325    (set_attr "mode"     "SI")
326    (set_attr "length"   "3,3")])
327
328 (define_insn "muladdhisi"
329   [(set (match_operand:SI 0 "register_operand" "=A")
330         (plus:SI (mult:SI (sign_extend:SI
331                            (match_operand:HI 1 "register_operand" "%r"))
332                           (sign_extend:SI
333                            (match_operand:HI 2 "register_operand" "r")))
334                  (match_operand:SI 3 "register_operand" "0")))]
335   "TARGET_MAC16"
336   "mula.aa.ll\t%1, %2"
337   [(set_attr "type"     "mac16")
338    (set_attr "mode"     "SI")
339    (set_attr "length"   "3")])
340
341 (define_insn "mulsubhisi"
342   [(set (match_operand:SI 0 "register_operand" "=A")
343         (minus:SI (match_operand:SI 1 "register_operand" "0")
344                   (mult:SI (sign_extend:SI
345                             (match_operand:HI 2 "register_operand" "%r"))
346                            (sign_extend:SI
347                             (match_operand:HI 3 "register_operand" "r")))))]
348   "TARGET_MAC16"
349   "muls.aa.ll\t%2, %3"
350   [(set_attr "type"     "mac16")
351    (set_attr "mode"     "SI")
352    (set_attr "length"   "3")])
353
354 (define_insn "mulsf3"
355   [(set (match_operand:SF 0 "register_operand" "=f")
356         (mult:SF (match_operand:SF 1 "register_operand" "%f")
357                  (match_operand:SF 2 "register_operand" "f")))]
358   "TARGET_HARD_FLOAT"
359   "mul.s\t%0, %1, %2"
360   [(set_attr "type"     "fmadd")
361    (set_attr "mode"     "SF")
362    (set_attr "length"   "3")])
363
364 (define_insn "muladdsf3"
365   [(set (match_operand:SF 0 "register_operand" "=f")
366         (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "%f")
367                           (match_operand:SF 2 "register_operand" "f"))
368                  (match_operand:SF 3 "register_operand" "0")))]
369   "TARGET_HARD_FLOAT && !TARGET_NO_FUSED_MADD"
370   "madd.s\t%0, %1, %2"
371   [(set_attr "type"     "fmadd")
372    (set_attr "mode"     "SF")
373    (set_attr "length"   "3")])
374
375 (define_insn "mulsubsf3"
376   [(set (match_operand:SF 0 "register_operand" "=f")
377         (minus:SF (match_operand:SF 1 "register_operand" "0")
378                   (mult:SF (match_operand:SF 2 "register_operand" "%f")
379                            (match_operand:SF 3 "register_operand" "f"))))]
380   "TARGET_HARD_FLOAT && !TARGET_NO_FUSED_MADD"
381   "msub.s\t%0, %2, %3"
382   [(set_attr "type"     "fmadd")
383    (set_attr "mode"     "SF")
384    (set_attr "length"   "3")])
385
386 \f
387 ;; Division.
388
389 (define_insn "divsi3"
390   [(set (match_operand:SI 0 "register_operand" "=a")
391         (div:SI (match_operand:SI 1 "register_operand" "r")
392                 (match_operand:SI 2 "register_operand" "r")))]
393   "TARGET_DIV32"
394   "quos\t%0, %1, %2"
395   [(set_attr "type"     "div32")
396    (set_attr "mode"     "SI")
397    (set_attr "length"   "3")])
398
399 (define_insn "udivsi3"
400   [(set (match_operand:SI 0 "register_operand" "=a")
401         (udiv:SI (match_operand:SI 1 "register_operand" "r")
402                  (match_operand:SI 2 "register_operand" "r")))]
403   "TARGET_DIV32"
404   "quou\t%0, %1, %2"
405   [(set_attr "type"     "div32")
406    (set_attr "mode"     "SI")
407    (set_attr "length"   "3")])
408
409 (define_insn "divsf3"
410   [(set (match_operand:SF 0 "register_operand" "=f")
411         (div:SF (match_operand:SF 1 "register_operand" "f")
412                 (match_operand:SF 2 "register_operand" "f")))]
413   "TARGET_HARD_FLOAT_DIV"
414   "div.s\t%0, %1, %2"
415   [(set_attr "type"     "fdiv")
416    (set_attr "mode"     "SF")
417    (set_attr "length"   "3")])
418
419 (define_insn "*recipsf2"
420   [(set (match_operand:SF 0 "register_operand" "=f")
421         (div:SF (match_operand:SF 1 "const_float_1_operand" "")
422                 (match_operand:SF 2 "register_operand" "f")))]
423   "TARGET_HARD_FLOAT_RECIP && flag_unsafe_math_optimizations"
424   "recip.s\t%0, %2"
425   [(set_attr "type"     "fdiv")
426    (set_attr "mode"     "SF")
427    (set_attr "length"   "3")])
428
429 \f
430 ;; Remainders.
431
432 (define_insn "modsi3"
433   [(set (match_operand:SI 0 "register_operand" "=a")
434         (mod:SI (match_operand:SI 1 "register_operand" "r")
435                 (match_operand:SI 2 "register_operand" "r")))]
436   "TARGET_DIV32"
437   "rems\t%0, %1, %2"
438   [(set_attr "type"     "div32")
439    (set_attr "mode"     "SI")
440    (set_attr "length"   "3")])
441
442 (define_insn "umodsi3"
443   [(set (match_operand:SI 0 "register_operand" "=a")
444         (umod:SI (match_operand:SI 1 "register_operand" "r")
445                  (match_operand:SI 2 "register_operand" "r")))]
446   "TARGET_DIV32"
447   "remu\t%0, %1, %2"
448   [(set_attr "type"     "div32")
449    (set_attr "mode"     "SI")
450    (set_attr "length"   "3")])
451
452 \f
453 ;; Square roots.
454
455 (define_insn "sqrtsf2"
456   [(set (match_operand:SF 0 "register_operand" "=f")
457         (sqrt:SF (match_operand:SF 1 "register_operand" "f")))]
458   "TARGET_HARD_FLOAT_SQRT"
459   "sqrt.s\t%0, %1"
460   [(set_attr "type"     "fsqrt")
461    (set_attr "mode"     "SF")
462    (set_attr "length"   "3")])
463
464 (define_insn "*rsqrtsf2"
465   [(set (match_operand:SF 0 "register_operand" "=f")
466         (div:SF (match_operand:SF 1 "const_float_1_operand" "")
467                 (sqrt:SF (match_operand:SF 2 "register_operand" "f"))))]
468   "TARGET_HARD_FLOAT_RSQRT && flag_unsafe_math_optimizations"
469   "rsqrt.s\t%0, %2"
470   [(set_attr "type"     "fsqrt")
471    (set_attr "mode"     "SF")
472    (set_attr "length"   "3")])
473
474 \f
475 ;; Absolute value.
476
477 (define_insn "abssi2"
478   [(set (match_operand:SI 0 "register_operand" "=a")
479         (abs:SI (match_operand:SI 1 "register_operand" "r")))]
480   "TARGET_ABS"
481   "abs\t%0, %1"
482   [(set_attr "type"     "arith")
483    (set_attr "mode"     "SI")
484    (set_attr "length"   "3")])
485
486 (define_insn "abssf2"
487   [(set (match_operand:SF 0 "register_operand" "=f")
488         (abs:SF (match_operand:SF 1 "register_operand" "f")))]
489   "TARGET_HARD_FLOAT"
490   "abs.s\t%0, %1"
491   [(set_attr "type"     "farith")
492    (set_attr "mode"     "SF")
493    (set_attr "length"   "3")])
494
495 \f
496 ;; Min and max.
497
498 (define_insn "sminsi3"
499   [(set (match_operand:SI 0 "register_operand" "=a")
500         (smin:SI (match_operand:SI 1 "register_operand" "%r")
501                  (match_operand:SI 2 "register_operand" "r")))]
502   "TARGET_MINMAX"
503   "min\t%0, %1, %2"
504   [(set_attr "type"     "arith")
505    (set_attr "mode"     "SI")
506    (set_attr "length"   "3")])
507
508 (define_insn "uminsi3"
509   [(set (match_operand:SI 0 "register_operand" "=a")
510         (umin:SI (match_operand:SI 1 "register_operand" "%r")
511                  (match_operand:SI 2 "register_operand" "r")))]
512   "TARGET_MINMAX"
513   "minu\t%0, %1, %2"
514   [(set_attr "type"     "arith")
515    (set_attr "mode"     "SI")
516    (set_attr "length"   "3")])
517
518 (define_insn "smaxsi3"
519   [(set (match_operand:SI 0 "register_operand" "=a")
520         (smax:SI (match_operand:SI 1 "register_operand" "%r")
521                  (match_operand:SI 2 "register_operand" "r")))]
522   "TARGET_MINMAX"
523   "max\t%0, %1, %2"
524   [(set_attr "type"     "arith")
525    (set_attr "mode"     "SI")
526    (set_attr "length"   "3")])
527
528 (define_insn "umaxsi3"
529   [(set (match_operand:SI 0 "register_operand" "=a")
530         (umax:SI (match_operand:SI 1 "register_operand" "%r")
531                  (match_operand:SI 2 "register_operand" "r")))]
532   "TARGET_MINMAX"
533   "maxu\t%0, %1, %2"
534   [(set_attr "type"     "arith")
535    (set_attr "mode"     "SI")
536    (set_attr "length"   "3")])
537
538 \f
539 ;; Find first bit.
540
541 (define_expand "ffssi2"
542   [(set (match_operand:SI 0 "register_operand" "")
543         (ffs:SI (match_operand:SI 1 "register_operand" "")))]
544   "TARGET_NSA"
545 {
546   rtx temp = gen_reg_rtx (SImode);
547   emit_insn (gen_negsi2 (temp, operands[1]));
548   emit_insn (gen_andsi3 (temp, temp, operands[1]));
549   emit_insn (gen_nsau (temp, temp));
550   emit_insn (gen_negsi2 (temp, temp));
551   emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (32)));
552   DONE;
553 })
554
555 ;; There is no RTL operator corresponding to NSAU.
556 (define_insn "nsau"
557   [(set (match_operand:SI 0 "register_operand" "=a")
558         (unspec:SI [(match_operand:SI 1 "register_operand" "r")] UNSPEC_NSAU))]
559   "TARGET_NSA"
560   "nsau\t%0, %1"
561   [(set_attr "type"     "arith")
562    (set_attr "mode"     "SI")
563    (set_attr "length"   "3")])
564
565 \f
566 ;; Negation and one's complement.
567
568 (define_insn "negsi2"
569   [(set (match_operand:SI 0 "register_operand" "=a")
570         (neg:SI (match_operand:SI 1 "register_operand" "r")))]
571   ""
572   "neg\t%0, %1"
573   [(set_attr "type"     "arith")
574    (set_attr "mode"     "SI")
575    (set_attr "length"   "3")])
576
577 (define_expand "one_cmplsi2"
578   [(set (match_operand:SI 0 "register_operand" "")
579         (not:SI (match_operand:SI 1 "register_operand" "")))]
580   ""
581 {
582   rtx temp = gen_reg_rtx (SImode);
583   emit_insn (gen_movsi (temp, constm1_rtx));
584   emit_insn (gen_xorsi3 (operands[0], temp, operands[1]));
585   DONE;
586 })
587
588 (define_insn "negsf2"
589   [(set (match_operand:SF 0 "register_operand" "=f")
590         (neg:SF (match_operand:SF 1 "register_operand" "f")))]
591   "TARGET_HARD_FLOAT"
592   "neg.s\t%0, %1"
593   [(set_attr "type"     "farith")
594    (set_attr "mode"     "SF")
595    (set_attr "length"   "3")])
596
597 \f
598 ;; Logical instructions.
599
600 (define_insn "andsi3"
601   [(set (match_operand:SI 0 "register_operand" "=a,a")
602         (and:SI (match_operand:SI 1 "register_operand" "%r,r")
603                 (match_operand:SI 2 "mask_operand" "P,r")))]
604   ""
605   "@
606    extui\t%0, %1, 0, %K2
607    and\t%0, %1, %2"
608   [(set_attr "type"     "arith,arith")
609    (set_attr "mode"     "SI")
610    (set_attr "length"   "3,3")])
611
612 (define_insn "iorsi3"
613   [(set (match_operand:SI 0 "register_operand" "=a")
614         (ior:SI (match_operand:SI 1 "register_operand" "%r")
615                 (match_operand:SI 2 "register_operand" "r")))]
616   ""
617   "or\t%0, %1, %2"
618   [(set_attr "type"     "arith")
619    (set_attr "mode"     "SI")
620    (set_attr "length"   "3")])
621
622 (define_insn "xorsi3"
623   [(set (match_operand:SI 0 "register_operand" "=a")
624         (xor:SI (match_operand:SI 1 "register_operand" "%r")
625                 (match_operand:SI 2 "register_operand" "r")))]
626   ""
627   "xor\t%0, %1, %2"
628   [(set_attr "type"     "arith")
629    (set_attr "mode"     "SI")
630    (set_attr "length"   "3")])
631
632 \f
633 ;; Zero-extend instructions.
634
635 (define_insn "zero_extendhisi2"
636   [(set (match_operand:SI 0 "register_operand" "=a,a")
637         (zero_extend:SI (match_operand:HI 1 "nonimmed_operand" "r,U")))]
638   ""
639   "@
640    extui\t%0, %1, 0, 16
641    l16ui\t%0, %1"
642   [(set_attr "type"     "arith,load")
643    (set_attr "mode"     "SI")
644    (set_attr "length"   "3,3")])
645
646 (define_insn "zero_extendqisi2"
647   [(set (match_operand:SI 0 "register_operand" "=a,a")
648         (zero_extend:SI (match_operand:QI 1 "nonimmed_operand" "r,U")))]
649   ""
650   "@
651    extui\t%0, %1, 0, 8
652    l8ui\t%0, %1"
653   [(set_attr "type"     "arith,load")
654    (set_attr "mode"     "SI")
655    (set_attr "length"   "3,3")])
656
657 \f
658 ;; Sign-extend instructions.
659
660 (define_expand "extendhisi2"
661   [(set (match_operand:SI 0 "register_operand" "")
662         (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
663   ""
664 {
665   if (sext_operand (operands[1], HImode))
666     emit_insn (gen_extendhisi2_internal (operands[0], operands[1]));
667   else
668     xtensa_extend_reg (operands[0], operands[1]);
669   DONE;
670 })
671
672 (define_insn "extendhisi2_internal"
673   [(set (match_operand:SI 0 "register_operand" "=B,a")
674         (sign_extend:SI (match_operand:HI 1 "sext_operand" "r,U")))]
675   ""
676   "@
677    sext\t%0, %1, 15
678    l16si\t%0, %1"
679   [(set_attr "type"     "arith,load")
680    (set_attr "mode"     "SI")
681    (set_attr "length"   "3,3")])
682
683 (define_expand "extendqisi2"
684   [(set (match_operand:SI 0 "register_operand" "")
685         (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
686   ""
687 {
688   if (TARGET_SEXT)
689     emit_insn (gen_extendqisi2_internal (operands[0], operands[1]));
690   else
691     xtensa_extend_reg (operands[0], operands[1]);
692   DONE;
693 })
694
695 (define_insn "extendqisi2_internal"
696   [(set (match_operand:SI 0 "register_operand" "=B")
697         (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
698   "TARGET_SEXT"
699   "sext\t%0, %1, 7"
700   [(set_attr "type"     "arith")
701    (set_attr "mode"     "SI")
702    (set_attr "length"   "3")])
703
704 \f
705 ;; Field extract instructions.
706
707 (define_expand "extv"
708   [(set (match_operand:SI 0 "register_operand" "")
709         (sign_extract:SI (match_operand:SI 1 "register_operand" "")
710                          (match_operand:SI 2 "const_int_operand" "")
711                          (match_operand:SI 3 "const_int_operand" "")))]
712   "TARGET_SEXT"
713 {
714   if (!sext_fldsz_operand (operands[2], SImode))
715     FAIL;
716
717   /* We could expand to a right shift followed by SEXT but that's
718      no better than the standard left and right shift sequence.  */
719   if (!lsbitnum_operand (operands[3], SImode))
720     FAIL;
721
722   emit_insn (gen_extv_internal (operands[0], operands[1],
723                                 operands[2], operands[3]));
724   DONE;
725 })
726
727 (define_insn "extv_internal"
728   [(set (match_operand:SI 0 "register_operand" "=a")
729         (sign_extract:SI (match_operand:SI 1 "register_operand" "r")
730                          (match_operand:SI 2 "sext_fldsz_operand" "i")
731                          (match_operand:SI 3 "lsbitnum_operand" "i")))]
732   "TARGET_SEXT"
733 {
734   int fldsz = INTVAL (operands[2]);
735   operands[2] = GEN_INT (fldsz - 1);
736   return "sext\t%0, %1, %2";
737 }
738   [(set_attr "type"     "arith")
739    (set_attr "mode"     "SI")
740    (set_attr "length"   "3")])
741
742 (define_expand "extzv"
743   [(set (match_operand:SI 0 "register_operand" "")
744         (zero_extract:SI (match_operand:SI 1 "register_operand" "")
745                          (match_operand:SI 2 "const_int_operand" "")
746                          (match_operand:SI 3 "const_int_operand" "")))]
747   ""
748 {
749   if (!extui_fldsz_operand (operands[2], SImode))
750     FAIL;
751   emit_insn (gen_extzv_internal (operands[0], operands[1],
752                                  operands[2], operands[3]));
753   DONE;
754 })
755
756 (define_insn "extzv_internal"
757   [(set (match_operand:SI 0 "register_operand" "=a")
758         (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
759                          (match_operand:SI 2 "extui_fldsz_operand" "i")
760                          (match_operand:SI 3 "const_int_operand" "i")))]
761   ""
762 {
763   int shift;
764   if (BITS_BIG_ENDIAN)
765     shift = (32 - (INTVAL (operands[2]) + INTVAL (operands[3]))) & 0x1f;
766   else
767     shift = INTVAL (operands[3]) & 0x1f;
768   operands[3] = GEN_INT (shift);
769   return "extui\t%0, %1, %3, %2";
770 }
771   [(set_attr "type"     "arith")
772    (set_attr "mode"     "SI")
773    (set_attr "length"   "3")])
774
775 \f
776 ;; Conversions.
777
778 (define_insn "fix_truncsfsi2"
779   [(set (match_operand:SI 0 "register_operand" "=a")
780         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
781   "TARGET_HARD_FLOAT"
782   "trunc.s\t%0, %1, 0"
783   [(set_attr "type"     "fconv")
784    (set_attr "mode"     "SF")
785    (set_attr "length"   "3")])
786
787 (define_insn "fixuns_truncsfsi2"
788   [(set (match_operand:SI 0 "register_operand" "=a")
789         (unsigned_fix:SI (match_operand:SF 1 "register_operand" "f")))]
790   "TARGET_HARD_FLOAT"
791   "utrunc.s\t%0, %1, 0"
792   [(set_attr "type"     "fconv")
793    (set_attr "mode"     "SF")
794    (set_attr "length"   "3")])
795
796 (define_insn "floatsisf2"
797   [(set (match_operand:SF 0 "register_operand" "=f")
798         (float:SF (match_operand:SI 1 "register_operand" "a")))]
799   "TARGET_HARD_FLOAT"
800   "float.s\t%0, %1, 0"
801   [(set_attr "type"     "fconv")
802    (set_attr "mode"     "SF")
803    (set_attr "length"   "3")])
804
805 (define_insn "floatunssisf2"
806   [(set (match_operand:SF 0 "register_operand" "=f")
807         (unsigned_float:SF (match_operand:SI 1 "register_operand" "a")))]
808   "TARGET_HARD_FLOAT"
809   "ufloat.s\t%0, %1, 0"
810   [(set_attr "type"     "fconv")
811    (set_attr "mode"     "SF")
812    (set_attr "length"   "3")])
813
814 \f
815 ;; Data movement instructions.
816
817 ;; 64-bit Integer moves
818
819 (define_expand "movdi"
820   [(set (match_operand:DI 0 "nonimmed_operand" "")
821         (match_operand:DI 1 "general_operand" ""))]
822   ""
823 {
824   if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
825     operands[1] = force_const_mem (DImode, operands[1]);
826
827   if (!register_operand (operands[0], DImode)
828       && !register_operand (operands[1], DImode))
829     operands[1] = force_reg (DImode, operands[1]);
830
831   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
832 })
833
834 (define_insn_and_split "movdi_internal"
835   [(set (match_operand:DI 0 "nonimmed_operand" "=a,W,a,a,U")
836         (match_operand:DI 1 "move_operand" "r,i,T,U,r"))]
837   "register_operand (operands[0], DImode)
838    || register_operand (operands[1], DImode)"
839   "#"
840   "reload_completed"
841   [(set (match_dup 0) (match_dup 2))
842    (set (match_dup 1) (match_dup 3))]
843 {
844   xtensa_split_operand_pair (operands, SImode);
845   if (reg_overlap_mentioned_p (operands[0], operands[3]))
846     {
847       rtx tmp;
848       tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
849       tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
850     }
851 })
852
853 ;; 32-bit Integer moves
854
855 (define_expand "movsi"
856   [(set (match_operand:SI 0 "nonimmed_operand" "")
857         (match_operand:SI 1 "general_operand" ""))]
858   ""
859 {
860   if (xtensa_emit_move_sequence (operands, SImode))
861     DONE;
862 })
863
864 (define_insn "movsi_internal"
865   [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,W,a,a,U,*a,*A")
866         (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,i,T,U,r,*A,*r"))]
867   "xtensa_valid_move (SImode, operands)"
868   "@
869    movi.n\t%0, %x1
870    mov.n\t%0, %1
871    mov.n\t%0, %1
872    %v1l32i.n\t%0, %1
873    %v0s32i.n\t%1, %0
874    %v0s32i.n\t%1, %0
875    mov\t%0, %1
876    movsp\t%0, %1
877    movi\t%0, %x1
878    const16\t%0, %t1\;const16\t%0, %b1
879    %v1l32r\t%0, %1
880    %v1l32i\t%0, %1
881    %v0s32i\t%1, %0
882    rsr\t%0, 16 # ACCLO
883    wsr\t%1, 16 # ACCLO"
884   [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,load,load,store,rsr,wsr")
885    (set_attr "mode"     "SI")
886    (set_attr "length"   "2,2,2,2,2,2,3,3,3,6,3,3,3,3,3")])
887
888 ;; 16-bit Integer moves
889
890 (define_expand "movhi"
891   [(set (match_operand:HI 0 "nonimmed_operand" "")
892         (match_operand:HI 1 "general_operand" ""))]
893   ""
894 {
895   if (xtensa_emit_move_sequence (operands, HImode))
896     DONE;
897 })
898
899 (define_insn "movhi_internal"
900   [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
901         (match_operand:HI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
902   "xtensa_valid_move (HImode, operands)"
903   "@
904    movi.n\t%0, %x1
905    mov.n\t%0, %1
906    mov\t%0, %1
907    movi\t%0, %x1
908    %v1l16ui\t%0, %1
909    %v0s16i\t%1, %0
910    rsr\t%0, 16 # ACCLO
911    wsr\t%1, 16 # ACCLO"
912   [(set_attr "type"     "move,move,move,move,load,store,rsr,wsr")
913    (set_attr "mode"     "HI")
914    (set_attr "length"   "2,2,3,3,3,3,3,3")])
915
916 ;; 8-bit Integer moves
917
918 (define_expand "movqi"
919   [(set (match_operand:QI 0 "nonimmed_operand" "")
920         (match_operand:QI 1 "general_operand" ""))]
921   ""
922 {
923   if (xtensa_emit_move_sequence (operands, QImode))
924     DONE;
925 })
926
927 (define_insn "movqi_internal"
928   [(set (match_operand:QI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
929         (match_operand:QI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
930   "xtensa_valid_move (QImode, operands)"
931   "@
932    movi.n\t%0, %x1
933    mov.n\t%0, %1
934    mov\t%0, %1
935    movi\t%0, %x1
936    %v1l8ui\t%0, %1
937    %v0s8i\t%1, %0
938    rsr\t%0, 16 # ACCLO
939    wsr\t%1, 16 # ACCLO"
940   [(set_attr "type"     "move,move,move,move,load,store,rsr,wsr")
941    (set_attr "mode"     "QI")
942    (set_attr "length"   "2,2,3,3,3,3,3,3")])
943
944 ;; 32-bit floating point moves
945
946 (define_expand "movsf"
947   [(set (match_operand:SF 0 "nonimmed_operand" "")
948         (match_operand:SF 1 "general_operand" ""))]
949   ""
950 {
951   if (!TARGET_CONST16 && CONSTANT_P (operands[1]))
952     operands[1] = force_const_mem (SFmode, operands[1]);
953
954   if ((!register_operand (operands[0], SFmode)
955        && !register_operand (operands[1], SFmode))
956       || (FP_REG_P (xt_true_regnum (operands[0]))
957           && !(reload_in_progress | reload_completed)
958           && (constantpool_mem_p (operands[1])
959               || CONSTANT_P (operands[1]))))
960     operands[1] = force_reg (SFmode, operands[1]);
961
962   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
963 })
964
965 (define_insn "movsf_internal"
966   [(set (match_operand:SF 0 "nonimmed_operand" "=f,f,U,D,D,R,a,f,a,W,a,a,U")
967         (match_operand:SF 1 "move_operand" "f,U,f,d,R,d,r,r,f,iF,T,U,r"))]
968   "((register_operand (operands[0], SFmode)
969      || register_operand (operands[1], SFmode))
970     && !(FP_REG_P (xt_true_regnum (operands[0]))
971          && (constantpool_mem_p (operands[1]) || CONSTANT_P (operands[1]))))"
972   "@
973    mov.s\t%0, %1
974    %v1lsi\t%0, %1
975    %v0ssi\t%1, %0
976    mov.n\t%0, %1
977    %v1l32i.n\t%0, %1
978    %v0s32i.n\t%1, %0
979    mov\t%0, %1
980    wfr\t%0, %1
981    rfr\t%0, %1
982    const16\t%0, %t1\;const16\t%0, %b1
983    %v1l32r\t%0, %1
984    %v1l32i\t%0, %1
985    %v0s32i\t%1, %0"
986   [(set_attr "type"     "farith,fload,fstore,move,load,store,move,farith,farith,move,load,load,store")
987    (set_attr "mode"     "SF")
988    (set_attr "length"   "3,3,3,2,2,2,3,3,3,6,3,3,3")])
989
990 (define_insn "*lsiu"
991   [(set (match_operand:SF 0 "register_operand" "=f")
992         (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "+a")
993                          (match_operand:SI 2 "fpmem_offset_operand" "i"))))
994    (set (match_dup 1)
995         (plus:SI (match_dup 1) (match_dup 2)))]
996   "TARGET_HARD_FLOAT"
997 {
998   if (volatile_refs_p (PATTERN (insn)))
999     output_asm_insn ("memw", operands);
1000   return "lsiu\t%0, %1, %2";
1001 }
1002   [(set_attr "type"     "fload")
1003    (set_attr "mode"     "SF")
1004    (set_attr "length"   "3")])
1005
1006 (define_insn "*ssiu"
1007   [(set (mem:SF (plus:SI (match_operand:SI 0 "register_operand" "+a")
1008                          (match_operand:SI 1 "fpmem_offset_operand" "i")))
1009         (match_operand:SF 2 "register_operand" "f"))
1010    (set (match_dup 0)
1011         (plus:SI (match_dup 0) (match_dup 1)))]
1012   "TARGET_HARD_FLOAT"
1013 {
1014   if (volatile_refs_p (PATTERN (insn)))
1015     output_asm_insn ("memw", operands);
1016   return "ssiu\t%2, %0, %1";
1017 }
1018   [(set_attr "type"     "fstore")
1019    (set_attr "mode"     "SF")
1020    (set_attr "length"   "3")])
1021
1022 ;; 64-bit floating point moves
1023
1024 (define_expand "movdf"
1025   [(set (match_operand:DF 0 "nonimmed_operand" "")
1026         (match_operand:DF 1 "general_operand" ""))]
1027   ""
1028 {
1029   if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
1030     operands[1] = force_const_mem (DFmode, operands[1]);
1031
1032   if (!register_operand (operands[0], DFmode)
1033       && !register_operand (operands[1], DFmode))
1034     operands[1] = force_reg (DFmode, operands[1]);
1035
1036   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1037 })
1038
1039 (define_insn_and_split "movdf_internal"
1040   [(set (match_operand:DF 0 "nonimmed_operand" "=a,W,a,a,U")
1041         (match_operand:DF 1 "move_operand" "r,iF,T,U,r"))]
1042   "register_operand (operands[0], DFmode)
1043    || register_operand (operands[1], DFmode)"
1044   "#"
1045   "reload_completed"
1046   [(set (match_dup 0) (match_dup 2))
1047    (set (match_dup 1) (match_dup 3))]
1048 {
1049   xtensa_split_operand_pair (operands, SFmode);
1050   if (reg_overlap_mentioned_p (operands[0], operands[3]))
1051     {
1052       rtx tmp;
1053       tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
1054       tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
1055     }
1056 })
1057
1058 ;; Block moves
1059
1060 (define_expand "movmemsi"
1061   [(parallel [(set (match_operand:BLK 0 "" "")
1062                    (match_operand:BLK 1 "" ""))
1063               (use (match_operand:SI 2 "arith_operand" ""))
1064               (use (match_operand:SI 3 "const_int_operand" ""))])]
1065   ""
1066 {
1067   if (!xtensa_expand_block_move (operands))
1068     FAIL;
1069   DONE;
1070 })
1071
1072 \f
1073 ;; Shift instructions.
1074
1075 (define_expand "ashlsi3"
1076   [(set (match_operand:SI 0 "register_operand" "")
1077         (ashift:SI (match_operand:SI 1 "register_operand" "")
1078                    (match_operand:SI 2 "arith_operand" "")))]
1079   ""
1080 {
1081   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1082 })
1083
1084 (define_insn "ashlsi3_internal"
1085   [(set (match_operand:SI 0 "register_operand" "=a,a")
1086         (ashift:SI (match_operand:SI 1 "register_operand" "r,r")
1087                    (match_operand:SI 2 "arith_operand" "J,r")))]
1088   ""      
1089   "@
1090    slli\t%0, %1, %R2
1091    ssl\t%2\;sll\t%0, %1"
1092   [(set_attr "type"     "arith,arith")
1093    (set_attr "mode"     "SI")
1094    (set_attr "length"   "3,6")])
1095
1096 (define_insn "ashrsi3"
1097   [(set (match_operand:SI 0 "register_operand" "=a,a")
1098         (ashiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1099                      (match_operand:SI 2 "arith_operand" "J,r")))]
1100   ""
1101   "@
1102    srai\t%0, %1, %R2
1103    ssr\t%2\;sra\t%0, %1"
1104   [(set_attr "type"     "arith,arith")
1105    (set_attr "mode"     "SI")
1106    (set_attr "length"   "3,6")])
1107
1108 (define_insn "lshrsi3"
1109   [(set (match_operand:SI 0 "register_operand" "=a,a")
1110         (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1111                      (match_operand:SI 2 "arith_operand" "J,r")))]
1112   ""
1113 {
1114   if (which_alternative == 0)
1115     {
1116       if ((INTVAL (operands[2]) & 0x1f) < 16)
1117         return "srli\t%0, %1, %R2";
1118       else
1119         return "extui\t%0, %1, %R2, %L2";
1120     }
1121   return "ssr\t%2\;srl\t%0, %1";
1122 }
1123   [(set_attr "type"     "arith,arith")
1124    (set_attr "mode"     "SI")
1125    (set_attr "length"   "3,6")])
1126
1127 (define_insn "rotlsi3"
1128   [(set (match_operand:SI 0 "register_operand" "=a,a")
1129         (rotate:SI (match_operand:SI 1 "register_operand" "r,r")
1130                      (match_operand:SI 2 "arith_operand" "J,r")))]
1131   ""
1132   "@
1133    ssai\t%L2\;src\t%0, %1, %1
1134    ssl\t%2\;src\t%0, %1, %1"
1135   [(set_attr "type"     "multi,multi")
1136    (set_attr "mode"     "SI")
1137    (set_attr "length"   "6,6")])
1138
1139 (define_insn "rotrsi3"
1140   [(set (match_operand:SI 0 "register_operand" "=a,a")
1141         (rotatert:SI (match_operand:SI 1 "register_operand" "r,r")
1142                      (match_operand:SI 2 "arith_operand" "J,r")))]
1143   ""
1144   "@
1145    ssai\t%R2\;src\t%0, %1, %1
1146    ssr\t%2\;src\t%0, %1, %1"
1147   [(set_attr "type"     "multi,multi")
1148    (set_attr "mode"     "SI")
1149    (set_attr "length"   "6,6")])
1150
1151 \f
1152 ;; Comparisons.
1153
1154 ;; Handle comparisons by stashing away the operands and then using that
1155 ;; information in the subsequent conditional branch.
1156
1157 (define_expand "cmpsi"
1158   [(set (cc0)
1159         (compare:CC (match_operand:SI 0 "register_operand" "")
1160                     (match_operand:SI 1 "nonmemory_operand" "")))]
1161   ""
1162 {
1163   branch_cmp[0] = operands[0];
1164   branch_cmp[1] = operands[1];
1165   branch_type = CMP_SI;
1166   DONE;
1167 })
1168
1169 (define_expand "tstsi"
1170   [(set (cc0)
1171         (match_operand:SI 0 "register_operand" ""))]
1172   ""
1173 {
1174   branch_cmp[0] = operands[0];
1175   branch_cmp[1] = const0_rtx;
1176   branch_type = CMP_SI;
1177   DONE;
1178 })
1179
1180 (define_expand "cmpsf"
1181   [(set (cc0)
1182         (compare:CC (match_operand:SF 0 "register_operand" "")
1183                     (match_operand:SF 1 "register_operand" "")))]
1184   "TARGET_HARD_FLOAT"
1185 {
1186   branch_cmp[0] = operands[0];
1187   branch_cmp[1] = operands[1];
1188   branch_type = CMP_SF;
1189   DONE;
1190 })
1191
1192 \f
1193 ;; Conditional branches.
1194
1195 (define_expand "beq"
1196   [(set (pc)
1197         (if_then_else (eq (cc0) (const_int 0))
1198                       (label_ref (match_operand 0 "" ""))
1199                       (pc)))]
1200   ""
1201 {
1202   xtensa_expand_conditional_branch (operands, EQ);
1203   DONE;
1204 })
1205
1206 (define_expand "bne"
1207   [(set (pc)
1208         (if_then_else (ne (cc0) (const_int 0))
1209                       (label_ref (match_operand 0 "" ""))
1210                       (pc)))]
1211   ""
1212 {
1213   xtensa_expand_conditional_branch (operands, NE);
1214   DONE;
1215 })
1216
1217 (define_expand "bgt"
1218   [(set (pc)
1219         (if_then_else (gt (cc0) (const_int 0))
1220                       (label_ref (match_operand 0 "" ""))
1221                       (pc)))]
1222   ""
1223 {
1224   xtensa_expand_conditional_branch (operands, GT);
1225   DONE;
1226 })
1227
1228 (define_expand "bge"
1229   [(set (pc)
1230         (if_then_else (ge (cc0) (const_int 0))
1231                       (label_ref (match_operand 0 "" ""))
1232                       (pc)))]
1233   ""
1234 {
1235   xtensa_expand_conditional_branch (operands, GE);
1236   DONE;
1237 })
1238
1239 (define_expand "blt"
1240   [(set (pc)
1241         (if_then_else (lt (cc0) (const_int 0))
1242                       (label_ref (match_operand 0 "" ""))
1243                       (pc)))]
1244   ""
1245 {
1246   xtensa_expand_conditional_branch (operands, LT);
1247   DONE;
1248 })
1249
1250 (define_expand "ble"
1251   [(set (pc)
1252         (if_then_else (le (cc0) (const_int 0))
1253                       (label_ref (match_operand 0 "" ""))
1254                       (pc)))]
1255   ""
1256 {
1257   xtensa_expand_conditional_branch (operands, LE);
1258   DONE;
1259 })
1260
1261 (define_expand "bgtu"
1262   [(set (pc)
1263         (if_then_else (gtu (cc0) (const_int 0))
1264                       (label_ref (match_operand 0 "" ""))
1265                       (pc)))]
1266   ""
1267 {
1268   xtensa_expand_conditional_branch (operands, GTU);
1269   DONE;
1270 })
1271
1272 (define_expand "bgeu"
1273   [(set (pc)
1274         (if_then_else (geu (cc0) (const_int 0))
1275                       (label_ref (match_operand 0 "" ""))
1276                       (pc)))]
1277   ""
1278 {
1279   xtensa_expand_conditional_branch (operands, GEU);
1280   DONE;
1281 })
1282
1283 (define_expand "bltu"
1284   [(set (pc)
1285         (if_then_else (ltu (cc0) (const_int 0))
1286                       (label_ref (match_operand 0 "" ""))
1287                       (pc)))]
1288   ""
1289 {
1290   xtensa_expand_conditional_branch (operands, LTU);
1291   DONE;
1292 })
1293
1294 (define_expand "bleu"
1295   [(set (pc)
1296         (if_then_else (leu (cc0) (const_int 0))
1297                       (label_ref (match_operand 0 "" ""))
1298                       (pc)))]
1299   ""
1300 {
1301   xtensa_expand_conditional_branch (operands, LEU);
1302   DONE;
1303 })
1304
1305 ;; Branch patterns for standard integer comparisons
1306
1307 (define_insn "*btrue"
1308   [(set (pc)
1309         (if_then_else (match_operator 3 "branch_operator"
1310                          [(match_operand:SI 0 "register_operand" "r,r")
1311                           (match_operand:SI 1 "branch_operand" "K,r")])
1312                       (label_ref (match_operand 2 "" ""))
1313                       (pc)))]
1314   ""
1315 {
1316   if (which_alternative == 1)
1317     {
1318       switch (GET_CODE (operands[3]))
1319         {
1320         case EQ:        return "beq\t%0, %1, %2";
1321         case NE:        return "bne\t%0, %1, %2";
1322         case LT:        return "blt\t%0, %1, %2";
1323         case GE:        return "bge\t%0, %1, %2";
1324         default:        break;
1325         }
1326     }
1327   else if (INTVAL (operands[1]) == 0)
1328     {
1329       switch (GET_CODE (operands[3]))
1330         {
1331         case EQ:        return (TARGET_DENSITY
1332                                 ? "beqz.n\t%0, %2"
1333                                 : "beqz\t%0, %2");
1334         case NE:        return (TARGET_DENSITY
1335                                 ? "bnez.n\t%0, %2"
1336                                 : "bnez\t%0, %2");
1337         case LT:        return "bltz\t%0, %2";
1338         case GE:        return "bgez\t%0, %2";
1339         default:        break;
1340         }
1341     }
1342   else
1343     {
1344       switch (GET_CODE (operands[3]))
1345         {
1346         case EQ:        return "beqi\t%0, %d1, %2";
1347         case NE:        return "bnei\t%0, %d1, %2";
1348         case LT:        return "blti\t%0, %d1, %2";
1349         case GE:        return "bgei\t%0, %d1, %2";
1350         default:        break;
1351         }
1352     }
1353   abort ();
1354   return "";
1355 }
1356   [(set_attr "type"     "jump,jump")
1357    (set_attr "mode"     "none")
1358    (set_attr "length"   "3,3")])
1359
1360 (define_insn "*bfalse"
1361   [(set (pc)
1362         (if_then_else (match_operator 3 "branch_operator"
1363                          [(match_operand:SI 0 "register_operand" "r,r")
1364                           (match_operand:SI 1 "branch_operand" "K,r")])
1365                       (pc)
1366                       (label_ref (match_operand 2 "" ""))))]
1367   ""
1368 {
1369   if (which_alternative == 1)
1370     {
1371       switch (GET_CODE (operands[3]))
1372         {
1373         case EQ:        return "bne\t%0, %1, %2";
1374         case NE:        return "beq\t%0, %1, %2";
1375         case LT:        return "bge\t%0, %1, %2";
1376         case GE:        return "blt\t%0, %1, %2";
1377         default:        break;
1378         }
1379     }
1380   else if (INTVAL (operands[1]) == 0)
1381     {
1382       switch (GET_CODE (operands[3]))
1383         {
1384         case EQ:        return (TARGET_DENSITY
1385                                 ? "bnez.n\t%0, %2"
1386                                 : "bnez\t%0, %2");
1387         case NE:        return (TARGET_DENSITY
1388                                 ? "beqz.n\t%0, %2"
1389                                 : "beqz\t%0, %2");
1390         case LT:        return "bgez\t%0, %2";
1391         case GE:        return "bltz\t%0, %2";
1392         default:        break;
1393         }
1394     }
1395   else
1396     {
1397       switch (GET_CODE (operands[3]))
1398         {
1399         case EQ:        return "bnei\t%0, %d1, %2";
1400         case NE:        return "beqi\t%0, %d1, %2";
1401         case LT:        return "bgei\t%0, %d1, %2";
1402         case GE:        return "blti\t%0, %d1, %2";
1403         default:        break;
1404         }
1405     }
1406   abort ();
1407   return "";
1408 }
1409   [(set_attr "type"     "jump,jump")
1410    (set_attr "mode"     "none")
1411    (set_attr "length"   "3,3")])
1412
1413 (define_insn "*ubtrue"
1414   [(set (pc)
1415         (if_then_else (match_operator 3 "ubranch_operator"
1416                          [(match_operand:SI 0 "register_operand" "r,r")
1417                           (match_operand:SI 1 "ubranch_operand" "L,r")])
1418                       (label_ref (match_operand 2 "" ""))
1419                       (pc)))]
1420   ""
1421 {
1422   if (which_alternative == 1)
1423     {
1424       switch (GET_CODE (operands[3]))
1425         {
1426         case LTU:       return "bltu\t%0, %1, %2";
1427         case GEU:       return "bgeu\t%0, %1, %2";
1428         default:        break;
1429         }
1430     }
1431   else
1432     {
1433       switch (GET_CODE (operands[3]))
1434         {
1435         case LTU:       return "bltui\t%0, %d1, %2";
1436         case GEU:       return "bgeui\t%0, %d1, %2";
1437         default:        break;
1438         }
1439     }
1440   abort ();
1441   return "";
1442 }
1443   [(set_attr "type"     "jump,jump")
1444    (set_attr "mode"     "none")
1445    (set_attr "length"   "3,3")])
1446
1447 (define_insn "*ubfalse"
1448   [(set (pc)
1449         (if_then_else (match_operator 3 "ubranch_operator"
1450                          [(match_operand:SI 0 "register_operand" "r,r")
1451                           (match_operand:SI 1 "ubranch_operand" "L,r")])
1452                       (pc)
1453                       (label_ref (match_operand 2 "" ""))))]
1454   ""
1455 {
1456   if (which_alternative == 1)
1457     {
1458       switch (GET_CODE (operands[3]))
1459         {
1460         case LTU:       return "bgeu\t%0, %1, %2";
1461         case GEU:       return "bltu\t%0, %1, %2";
1462         default:        break;
1463         }
1464     }
1465   else
1466     {
1467       switch (GET_CODE (operands[3]))
1468         {
1469         case LTU:       return "bgeui\t%0, %d1, %2";
1470         case GEU:       return "bltui\t%0, %d1, %2";
1471         default:        break;
1472         }
1473     }
1474   abort ();
1475   return "";
1476 }
1477   [(set_attr "type"     "jump,jump")
1478    (set_attr "mode"     "none")
1479    (set_attr "length"   "3,3")])
1480
1481 ;; Branch patterns for bit testing
1482
1483 (define_insn "*bittrue"
1484   [(set (pc)
1485         (if_then_else (match_operator 3 "boolean_operator"
1486                         [(zero_extract:SI
1487                             (match_operand:SI 0 "register_operand" "r,r")
1488                             (const_int 1)
1489                             (match_operand:SI 1 "arith_operand" "J,r"))
1490                          (const_int 0)])
1491                       (label_ref (match_operand 2 "" ""))
1492                       (pc)))]
1493   ""
1494 {
1495   if (which_alternative == 0)
1496     {
1497       unsigned bitnum = INTVAL(operands[1]) & 0x1f;
1498       operands[1] = GEN_INT(bitnum);
1499       switch (GET_CODE (operands[3]))
1500         {
1501         case EQ:        return "bbci\t%0, %d1, %2";
1502         case NE:        return "bbsi\t%0, %d1, %2";
1503         default:        break;
1504         }
1505     }
1506   else
1507     {
1508       switch (GET_CODE (operands[3]))
1509         {
1510         case EQ:        return "bbc\t%0, %1, %2";
1511         case NE:        return "bbs\t%0, %1, %2";
1512         default:        break;
1513         }
1514     }
1515   abort ();
1516   return "";
1517 }
1518   [(set_attr "type"     "jump")
1519    (set_attr "mode"     "none")
1520    (set_attr "length"   "3")])
1521
1522 (define_insn "*bitfalse"
1523   [(set (pc)
1524         (if_then_else (match_operator 3 "boolean_operator"
1525                         [(zero_extract:SI
1526                             (match_operand:SI 0 "register_operand" "r,r")
1527                             (const_int 1)
1528                             (match_operand:SI 1 "arith_operand" "J,r"))
1529                          (const_int 0)])
1530                       (pc)
1531                       (label_ref (match_operand 2 "" ""))))]
1532   ""
1533 {
1534   if (which_alternative == 0)
1535     {
1536       unsigned bitnum = INTVAL (operands[1]) & 0x1f;
1537       operands[1] = GEN_INT (bitnum);
1538       switch (GET_CODE (operands[3]))
1539         {
1540         case EQ:        return "bbsi\t%0, %d1, %2";
1541         case NE:        return "bbci\t%0, %d1, %2";
1542         default:        break;
1543         }
1544     }
1545   else
1546     {
1547       switch (GET_CODE (operands[3]))
1548         {
1549         case EQ:        return "bbs\t%0, %1, %2";
1550         case NE:        return "bbc\t%0, %1, %2";
1551         default:        break;
1552         }
1553     }
1554   abort ();
1555   return "";
1556 }
1557   [(set_attr "type"     "jump")
1558    (set_attr "mode"     "none")
1559    (set_attr "length"   "3")])
1560
1561 (define_insn "*masktrue"
1562   [(set (pc)
1563         (if_then_else (match_operator 3 "boolean_operator"
1564                  [(and:SI (match_operand:SI 0 "register_operand" "r")
1565                           (match_operand:SI 1 "register_operand" "r"))
1566                   (const_int 0)])
1567                       (label_ref (match_operand 2 "" ""))
1568                       (pc)))]
1569   ""
1570 {
1571   switch (GET_CODE (operands[3]))
1572     {
1573     case EQ:            return "bnone\t%0, %1, %2";
1574     case NE:            return "bany\t%0, %1, %2";
1575     default:            break;
1576     }
1577   abort ();
1578   return "";
1579 }
1580   [(set_attr "type"     "jump")
1581    (set_attr "mode"     "none")
1582    (set_attr "length"   "3")])
1583
1584 (define_insn "*maskfalse"
1585   [(set (pc)
1586         (if_then_else (match_operator 3 "boolean_operator"
1587                  [(and:SI (match_operand:SI 0 "register_operand" "r")
1588                           (match_operand:SI 1 "register_operand" "r"))
1589                   (const_int 0)])
1590                       (pc)
1591                       (label_ref (match_operand 2 "" ""))))]
1592   ""
1593 {
1594   switch (GET_CODE (operands[3]))
1595     {
1596     case EQ:            return "bany\t%0, %1, %2";
1597     case NE:            return "bnone\t%0, %1, %2";
1598     default:            break;
1599     }
1600   abort ();
1601   return "";
1602 }
1603   [(set_attr "type"     "jump")
1604    (set_attr "mode"     "none")
1605    (set_attr "length"   "3")])
1606
1607
1608 ;; Define the loop insns used by bct optimization to represent the
1609 ;; start and end of a zero-overhead loop (in loop.c).  This start
1610 ;; template generates the loop insn; the end template doesn't generate
1611 ;; any instructions since loop end is handled in hardware.
1612
1613 (define_insn "zero_cost_loop_start"
1614   [(set (pc)
1615         (if_then_else (eq (match_operand:SI 0 "register_operand" "a")
1616                           (const_int 0))
1617                       (label_ref (match_operand 1 "" ""))
1618                       (pc)))
1619    (set (reg:SI 19)
1620         (plus:SI (match_dup 0) (const_int -1)))]
1621   ""
1622   "loopnez\t%0, %l1"
1623   [(set_attr "type"     "jump")
1624    (set_attr "mode"     "none")
1625    (set_attr "length"   "3")])
1626
1627 (define_insn "zero_cost_loop_end"
1628   [(set (pc)
1629         (if_then_else (ne (reg:SI 19) (const_int 0))
1630                       (label_ref (match_operand 0 "" ""))
1631                       (pc)))
1632    (set (reg:SI 19)
1633         (plus:SI (reg:SI 19) (const_int -1)))]
1634   ""
1635 {
1636     xtensa_emit_loop_end (insn, operands);
1637     return "";
1638 }
1639   [(set_attr "type"     "jump")
1640    (set_attr "mode"     "none")
1641    (set_attr "length"   "0")])
1642
1643 \f
1644 ;; Setting a register from a comparison.
1645
1646 (define_expand "seq"
1647   [(set (match_operand:SI 0 "register_operand" "")
1648         (match_dup 1))]
1649   ""
1650 {
1651   operands[1] = gen_rtx_EQ (SImode, branch_cmp[0], branch_cmp[1]);
1652   if (!xtensa_expand_scc (operands))
1653     FAIL;
1654   DONE;
1655 })
1656
1657 (define_expand "sne"
1658   [(set (match_operand:SI 0 "register_operand" "")
1659         (match_dup 1))]
1660   ""
1661 {
1662   operands[1] = gen_rtx_NE (SImode, branch_cmp[0], branch_cmp[1]);
1663   if (!xtensa_expand_scc (operands))
1664     FAIL;
1665   DONE;
1666 })
1667
1668 (define_expand "sgt"
1669   [(set (match_operand:SI 0 "register_operand" "")
1670         (match_dup 1))]
1671   ""
1672 {
1673   operands[1] = gen_rtx_GT (SImode, branch_cmp[0], branch_cmp[1]);
1674   if (!xtensa_expand_scc (operands))
1675     FAIL;
1676   DONE;
1677 })
1678
1679 (define_expand "sge"
1680   [(set (match_operand:SI 0 "register_operand" "")
1681         (match_dup 1))]
1682   ""
1683 {
1684   operands[1] = gen_rtx_GE (SImode, branch_cmp[0], branch_cmp[1]);
1685   if (!xtensa_expand_scc (operands))
1686     FAIL;
1687   DONE;
1688 })
1689
1690 (define_expand "slt"
1691   [(set (match_operand:SI 0 "register_operand" "")
1692         (match_dup 1))]
1693   ""
1694 {
1695   operands[1] = gen_rtx_LT (SImode, branch_cmp[0], branch_cmp[1]);
1696   if (!xtensa_expand_scc (operands))
1697     FAIL;
1698   DONE;
1699 })
1700
1701 (define_expand "sle"
1702   [(set (match_operand:SI 0 "register_operand" "")
1703         (match_dup 1))]
1704   ""
1705 {
1706   operands[1] = gen_rtx_LE (SImode, branch_cmp[0], branch_cmp[1]);
1707   if (!xtensa_expand_scc (operands))
1708     FAIL;
1709   DONE;
1710 })
1711
1712 \f
1713 ;; Conditional moves.
1714
1715 (define_expand "movsicc"
1716   [(set (match_operand:SI 0 "register_operand" "")
1717         (if_then_else:SI (match_operand 1 "comparison_operator" "")
1718                          (match_operand:SI 2 "register_operand" "")
1719                          (match_operand:SI 3 "register_operand" "")))]
1720   ""
1721 {
1722   if (!xtensa_expand_conditional_move (operands, 0))
1723     FAIL;
1724   DONE;
1725 })
1726
1727 (define_expand "movsfcc"
1728   [(set (match_operand:SF 0 "register_operand" "")
1729         (if_then_else:SF (match_operand 1 "comparison_operator" "")
1730                          (match_operand:SF 2 "register_operand" "")
1731                          (match_operand:SF 3 "register_operand" "")))]
1732   ""
1733 {
1734   if (!xtensa_expand_conditional_move (operands, 1))
1735     FAIL;
1736   DONE;
1737 })
1738
1739 (define_insn "movsicc_internal0"
1740   [(set (match_operand:SI 0 "register_operand" "=a,a")
1741         (if_then_else:SI (match_operator 4 "branch_operator"
1742                            [(match_operand:SI 1 "register_operand" "r,r")
1743                             (const_int 0)])
1744                          (match_operand:SI 2 "register_operand" "r,0")
1745                          (match_operand:SI 3 "register_operand" "0,r")))]
1746   ""
1747 {
1748   if (which_alternative == 0)
1749     {
1750       switch (GET_CODE (operands[4]))
1751         {
1752         case EQ:        return "moveqz\t%0, %2, %1";
1753         case NE:        return "movnez\t%0, %2, %1";
1754         case LT:        return "movltz\t%0, %2, %1";
1755         case GE:        return "movgez\t%0, %2, %1";
1756         default:        break;
1757         }
1758     }
1759   else
1760     {
1761       switch (GET_CODE (operands[4]))
1762         {
1763         case EQ:        return "movnez\t%0, %3, %1";
1764         case NE:        return "moveqz\t%0, %3, %1";
1765         case LT:        return "movgez\t%0, %3, %1";
1766         case GE:        return "movltz\t%0, %3, %1";
1767         default:        break;
1768         }
1769     }
1770   abort ();
1771   return "";
1772 }
1773   [(set_attr "type"     "move,move")
1774    (set_attr "mode"     "SI")
1775    (set_attr "length"   "3,3")])
1776
1777 (define_insn "movsicc_internal1"
1778   [(set (match_operand:SI 0 "register_operand" "=a,a")
1779         (if_then_else:SI (match_operator 4 "boolean_operator"
1780                            [(match_operand:CC 1 "register_operand" "b,b")
1781                             (const_int 0)])
1782                          (match_operand:SI 2 "register_operand" "r,0")
1783                          (match_operand:SI 3 "register_operand" "0,r")))]
1784   "TARGET_BOOLEANS"
1785 {
1786   int isEq = (GET_CODE (operands[4]) == EQ);
1787   switch (which_alternative)
1788     {
1789     case 0:
1790       if (isEq) return "movf\t%0, %2, %1";
1791       return "movt\t%0, %2, %1";
1792     case 1:
1793       if (isEq) return "movt\t%0, %3, %1";
1794       return "movf\t%0, %3, %1";
1795     }
1796   abort ();
1797   return "";
1798 }
1799   [(set_attr "type"     "move,move")
1800    (set_attr "mode"     "SI")
1801    (set_attr "length"   "3,3")])
1802
1803 (define_insn "movsfcc_internal0"
1804   [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1805         (if_then_else:SF (match_operator 4 "branch_operator"
1806                            [(match_operand:SI 1 "register_operand" "r,r,r,r")
1807                             (const_int 0)])
1808                          (match_operand:SF 2 "register_operand" "r,0,f,0")
1809                          (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1810   ""
1811 {
1812   if (which_alternative == 0)
1813     {
1814       switch (GET_CODE (operands[4]))
1815         {
1816         case EQ:        return "moveqz\t%0, %2, %1";
1817         case NE:        return "movnez\t%0, %2, %1";
1818         case LT:        return "movltz\t%0, %2, %1";
1819         case GE:        return "movgez\t%0, %2, %1";
1820         default:        break;
1821         }
1822     }
1823   else if (which_alternative == 1)
1824     {
1825       switch (GET_CODE (operands[4]))
1826         {
1827         case EQ:        return "movnez\t%0, %3, %1";
1828         case NE:        return "moveqz\t%0, %3, %1";
1829         case LT:        return "movgez\t%0, %3, %1";
1830         case GE:        return "movltz\t%0, %3, %1";
1831         default:        break;
1832         }
1833     }
1834   else if (which_alternative == 2)
1835     {
1836       switch (GET_CODE (operands[4]))
1837         {
1838         case EQ:        return "moveqz.s %0, %2, %1";
1839         case NE:        return "movnez.s %0, %2, %1";
1840         case LT:        return "movltz.s %0, %2, %1";
1841         case GE:        return "movgez.s %0, %2, %1";
1842         default:        break;
1843         }
1844     }
1845   else if (which_alternative == 3)
1846     {
1847       switch (GET_CODE (operands[4]))
1848         {
1849         case EQ:        return "movnez.s %0, %3, %1";
1850         case NE:        return "moveqz.s %0, %3, %1";
1851         case LT:        return "movgez.s %0, %3, %1";
1852         case GE:        return "movltz.s %0, %3, %1";
1853         default:        break;
1854         }
1855     }
1856   abort ();
1857   return "";
1858 }
1859   [(set_attr "type"     "move,move,move,move")
1860    (set_attr "mode"     "SF")
1861    (set_attr "length"   "3,3,3,3")])
1862
1863 (define_insn "movsfcc_internal1"
1864   [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1865         (if_then_else:SF (match_operator 4 "boolean_operator"
1866                            [(match_operand:CC 1 "register_operand" "b,b,b,b")
1867                             (const_int 0)])
1868                          (match_operand:SF 2 "register_operand" "r,0,f,0")
1869                          (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1870   "TARGET_BOOLEANS"
1871 {
1872   int isEq = (GET_CODE (operands[4]) == EQ);
1873   switch (which_alternative)
1874     {
1875     case 0:
1876       if (isEq) return "movf\t%0, %2, %1";
1877       return "movt\t%0, %2, %1";
1878     case 1:
1879       if (isEq) return "movt\t%0, %3, %1";
1880       return "movf\t%0, %3, %1";
1881     case 2:
1882       if (isEq) return "movf.s\t%0, %2, %1";
1883       return "movt.s\t%0, %2, %1";
1884     case 3:
1885       if (isEq) return "movt.s\t%0, %3, %1";
1886       return "movf.s\t%0, %3, %1";
1887     }
1888   abort ();
1889   return "";
1890 }
1891   [(set_attr "type"     "move,move,move,move")
1892    (set_attr "mode"     "SF")
1893    (set_attr "length"   "3,3,3,3")])
1894
1895 \f
1896 ;; Floating-point comparisons.
1897
1898 (define_insn "seq_sf"
1899   [(set (match_operand:CC 0 "register_operand" "=b")
1900         (eq:CC (match_operand:SF 1 "register_operand" "f")
1901                (match_operand:SF 2 "register_operand" "f")))]
1902   "TARGET_HARD_FLOAT"
1903   "oeq.s\t%0, %1, %2"
1904   [(set_attr "type"     "farith")
1905    (set_attr "mode"     "BL")
1906    (set_attr "length"   "3")])
1907
1908 (define_insn "slt_sf"
1909   [(set (match_operand:CC 0 "register_operand" "=b")
1910         (lt:CC (match_operand:SF 1 "register_operand" "f")
1911                (match_operand:SF 2 "register_operand" "f")))]
1912   "TARGET_HARD_FLOAT"
1913   "olt.s\t%0, %1, %2"
1914   [(set_attr "type"     "farith")
1915    (set_attr "mode"     "BL")
1916    (set_attr "length"   "3")])
1917
1918 (define_insn "sle_sf"
1919   [(set (match_operand:CC 0 "register_operand" "=b")
1920         (le:CC (match_operand:SF 1 "register_operand" "f")
1921                (match_operand:SF 2 "register_operand" "f")))]
1922   "TARGET_HARD_FLOAT"
1923   "ole.s\t%0, %1, %2"
1924   [(set_attr "type"     "farith")
1925    (set_attr "mode"     "BL")
1926    (set_attr "length"   "3")])
1927
1928 \f
1929 ;; Unconditional branches.
1930
1931 (define_insn "jump"
1932   [(set (pc)
1933         (label_ref (match_operand 0 "" "")))]
1934   ""
1935   "j\t%l0"
1936   [(set_attr "type"     "jump")
1937    (set_attr "mode"     "none")
1938    (set_attr "length"   "3")])
1939
1940 (define_expand "indirect_jump"
1941   [(set (pc)
1942         (match_operand 0 "register_operand" ""))]
1943   ""
1944 {
1945   rtx dest = operands[0];
1946   if (GET_CODE (dest) != REG || GET_MODE (dest) != Pmode)
1947     operands[0] = copy_to_mode_reg (Pmode, dest);
1948
1949   emit_jump_insn (gen_indirect_jump_internal (dest));
1950   DONE;
1951 })
1952
1953 (define_insn "indirect_jump_internal"
1954   [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
1955   ""
1956   "jx\t%0"
1957   [(set_attr "type"     "jump")
1958    (set_attr "mode"     "none")
1959    (set_attr "length"   "3")])
1960
1961
1962 (define_expand "tablejump"
1963   [(use (match_operand:SI 0 "register_operand" ""))
1964    (use (label_ref (match_operand 1 "" "")))]
1965    ""
1966 {
1967   rtx target = operands[0];
1968   if (flag_pic)
1969     {
1970       /* For PIC, the table entry is relative to the start of the table.  */
1971       rtx label = gen_reg_rtx (SImode);
1972       target = gen_reg_rtx (SImode);
1973       emit_move_insn (label, gen_rtx_LABEL_REF (SImode, operands[1]));
1974       emit_insn (gen_addsi3 (target, operands[0], label));
1975     }
1976   emit_jump_insn (gen_tablejump_internal (target, operands[1]));
1977   DONE;
1978 })
1979
1980 (define_insn "tablejump_internal"
1981   [(set (pc)
1982         (match_operand:SI 0 "register_operand" "r"))
1983    (use (label_ref (match_operand 1 "" "")))]
1984   ""
1985   "jx\t%0"
1986   [(set_attr "type"     "jump")
1987    (set_attr "mode"     "none")
1988    (set_attr "length"   "3")])
1989
1990 \f
1991 ;; Function calls.
1992
1993 (define_expand "sym_PLT"
1994   [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PLT))]
1995   ""
1996   "")
1997
1998 (define_expand "call"
1999   [(call (match_operand 0 "memory_operand" "")
2000          (match_operand 1 "" ""))]
2001   ""
2002 {
2003   rtx addr = XEXP (operands[0], 0);
2004   if (flag_pic && GET_CODE (addr) == SYMBOL_REF
2005       && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
2006     addr = gen_sym_PLT (addr);
2007   if (!call_insn_operand (addr, VOIDmode))
2008     XEXP (operands[0], 0) = copy_to_mode_reg (Pmode, addr);
2009 })
2010
2011 (define_insn "call_internal"
2012   [(call (mem (match_operand:SI 0 "call_insn_operand" "n,i,r"))
2013          (match_operand 1 "" "i,i,i"))]
2014   ""
2015 {
2016   return xtensa_emit_call (0, operands);
2017 }
2018   [(set_attr "type"     "call")
2019    (set_attr "mode"     "none")
2020    (set_attr "length"   "3")])
2021
2022 (define_expand "call_value"
2023   [(set (match_operand 0 "register_operand" "")
2024         (call (match_operand 1 "memory_operand" "")
2025               (match_operand 2 "" "")))]
2026   ""
2027 {
2028   rtx addr = XEXP (operands[1], 0);
2029   if (flag_pic && GET_CODE (addr) == SYMBOL_REF
2030       && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
2031     addr = gen_sym_PLT (addr);
2032   if (!call_insn_operand (addr, VOIDmode))
2033     XEXP (operands[1], 0) = copy_to_mode_reg (Pmode, addr);
2034 })
2035
2036 ;; Cannot combine constraints for operand 0 into "afvb":
2037 ;; reload.c:find_reloads seems to assume that grouped constraints somehow
2038 ;; specify related register classes, and when they don't the constraints
2039 ;; fail to match.  By not grouping the constraints, we get the correct
2040 ;; behavior.
2041 (define_insn "call_value_internal"
2042    [(set (match_operand 0 "register_operand" "=af,af,af,v,v,v,b,b,b")
2043          (call (mem (match_operand:SI 1 "call_insn_operand"
2044                                         "n,i,r,n,i,r,n,i,r"))
2045                (match_operand 2 "" "i,i,i,i,i,i,i,i,i")))]
2046   ""
2047 {
2048   return xtensa_emit_call (1, operands);
2049 }
2050   [(set_attr "type"     "call")
2051    (set_attr "mode"     "none")
2052    (set_attr "length"   "3")])
2053
2054 (define_insn "entry"
2055   [(set (reg:SI A1_REG)
2056         (unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "i")
2057                              (match_operand:SI 1 "const_int_operand" "i")]
2058                             UNSPECV_ENTRY))]
2059   ""
2060 {
2061   if (frame_pointer_needed)
2062     output_asm_insn (".frame\ta7, %0", operands);
2063   else
2064     output_asm_insn (".frame\tsp, %0", operands);
2065   return "entry\tsp, %1";
2066 }
2067   [(set_attr "type"     "move")
2068    (set_attr "mode"     "SI")
2069    (set_attr "length"   "3")])
2070
2071 (define_insn "return"
2072   [(return)
2073    (use (reg:SI A0_REG))]
2074   "reload_completed"
2075 {
2076   return (TARGET_DENSITY ? "retw.n" : "retw");
2077 }
2078   [(set_attr "type"     "jump")
2079    (set_attr "mode"     "none")
2080    (set_attr "length"   "2")])
2081
2082 \f
2083 ;; Miscellaneous instructions.
2084
2085 (define_expand "prologue"
2086   [(const_int 0)]
2087   ""
2088 {
2089   xtensa_expand_prologue ();
2090   DONE;
2091 })
2092
2093 (define_expand "epilogue"
2094   [(return)]
2095   ""
2096 {
2097   emit_jump_insn (gen_return ());
2098   DONE;
2099 })
2100
2101 (define_insn "nop"
2102   [(const_int 0)]
2103   ""
2104 {
2105   return (TARGET_DENSITY ? "nop.n" : "nop");
2106 }
2107   [(set_attr "type"     "nop")
2108    (set_attr "mode"     "none")
2109    (set_attr "length"   "3")])
2110
2111 (define_expand "nonlocal_goto"
2112   [(match_operand:SI 0 "general_operand" "")
2113    (match_operand:SI 1 "general_operand" "")
2114    (match_operand:SI 2 "general_operand" "")
2115    (match_operand:SI 3 "" "")]
2116   ""
2117 {
2118   xtensa_expand_nonlocal_goto (operands);
2119   DONE;
2120 })
2121
2122 ;; Setting up a frame pointer is tricky for Xtensa because GCC doesn't
2123 ;; know if a frame pointer is required until the reload pass, and
2124 ;; because there may be an incoming argument value in the hard frame
2125 ;; pointer register (a7).  If there is an incoming argument in that
2126 ;; register, the "set_frame_ptr" insn gets inserted immediately after
2127 ;; the insn that copies the incoming argument to a pseudo or to the
2128 ;; stack.  This serves several purposes here: (1) it keeps the
2129 ;; optimizer from copy-propagating or scheduling the use of a7 as an
2130 ;; incoming argument away from the beginning of the function; (2) we
2131 ;; can use a post-reload splitter to expand away the insn if a frame
2132 ;; pointer is not required, so that the post-reload scheduler can do
2133 ;; the right thing; and (3) it makes it easy for the prologue expander
2134 ;; to search for this insn to determine whether it should add a new insn
2135 ;; to set up the frame pointer.
2136
2137 (define_insn "set_frame_ptr"
2138   [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
2139   ""
2140 {
2141   if (frame_pointer_needed)
2142     return "mov\ta7, sp";
2143   return "";
2144 }
2145   [(set_attr "type"     "move")
2146    (set_attr "mode"     "SI")
2147    (set_attr "length"   "3")])
2148
2149 ;; Post-reload splitter to remove fp assignment when it's not needed.
2150 (define_split
2151   [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
2152   "reload_completed && !frame_pointer_needed"
2153   [(unspec [(const_int 0)] UNSPEC_NOP)]
2154   "")
2155
2156 ;; The preceding splitter needs something to split the insn into;
2157 ;; things start breaking if the result is just a "use" so instead we
2158 ;; generate the following insn.
2159 (define_insn "*unspec_nop"
2160   [(unspec [(const_int 0)] UNSPEC_NOP)]
2161   ""
2162   ""
2163   [(set_attr "type"     "nop")
2164    (set_attr "mode"     "none")
2165    (set_attr "length"   "0")])
2166
2167 ;; The fix_return_addr pattern sets the high 2 bits of an address in a
2168 ;; register to match the high bits of the current PC.
2169 (define_insn "fix_return_addr"
2170   [(set (match_operand:SI 0 "register_operand" "=a")
2171         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
2172                    UNSPEC_RET_ADDR))
2173    (clobber (match_scratch:SI 2 "=r"))
2174    (clobber (match_scratch:SI 3 "=r"))]
2175   ""
2176   "mov\t%2, a0\;call0\t0f\;.align\t4\;0:\;mov\t%3, a0\;mov\ta0, %2\;\
2177 srli\t%3, %3, 30\;slli\t%0, %1, 2\;ssai\t2\;src\t%0, %3, %0"
2178   [(set_attr "type"     "multi")
2179    (set_attr "mode"     "SI")
2180    (set_attr "length"   "24")])
2181
2182 \f
2183 ;; Instructions for the Xtensa "boolean" option.
2184
2185 (define_insn "*booltrue"
2186   [(set (pc)
2187         (if_then_else (match_operator 2 "boolean_operator"
2188                          [(match_operand:CC 0 "register_operand" "b")
2189                           (const_int 0)])
2190                       (label_ref (match_operand 1 "" ""))
2191                       (pc)))]
2192   "TARGET_BOOLEANS"
2193 {
2194   if (GET_CODE (operands[2]) == EQ)
2195     return "bf\t%0, %1";
2196   else
2197     return "bt\t%0, %1";
2198 }
2199   [(set_attr "type"     "jump")
2200    (set_attr "mode"     "none")
2201    (set_attr "length"   "3")])
2202
2203 (define_insn "*boolfalse"
2204   [(set (pc)
2205         (if_then_else (match_operator 2 "boolean_operator"
2206                          [(match_operand:CC 0 "register_operand" "b")
2207                           (const_int 0)])
2208                       (pc)
2209                       (label_ref (match_operand 1 "" ""))))]
2210   "TARGET_BOOLEANS"
2211 {
2212   if (GET_CODE (operands[2]) == EQ)
2213     return "bt\t%0, %1";
2214   else
2215     return "bf\t%0, %1";
2216 }
2217   [(set_attr "type"     "jump")
2218    (set_attr "mode"     "none")
2219    (set_attr "length"   "3")])