OSDN Git Service

* configure.ac: Add HAVE_AS_TLS check for Xtensa.
[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, 2005, 2006, 2007, 2008
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Bob Wilson (bwilson@tensilica.com) at Tensilica.
5
6 ;; This file is part of GCC.
7
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; any later version.
12
13 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16 ;; License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3.  If not see
20 ;; <http://www.gnu.org/licenses/>.
21
22
23 (define_constants [
24   (A0_REG               0)
25   (A1_REG               1)
26   (A7_REG               7)
27   (A8_REG               8)
28
29   (UNSPEC_NOP           2)
30   (UNSPEC_PLT           3)
31   (UNSPEC_RET_ADDR      4)
32   (UNSPEC_TPOFF         5)
33   (UNSPEC_DTPOFF        6)
34   (UNSPEC_TLS_FUNC      7)
35   (UNSPEC_TLS_ARG       8)
36   (UNSPEC_TLS_CALL      9)
37   (UNSPEC_TP            10)
38
39   (UNSPECV_SET_FP       1)
40   (UNSPECV_ENTRY        2)
41   (UNSPECV_MEMW         3)
42   (UNSPECV_S32RI        4)
43   (UNSPECV_S32C1I       5)
44   (UNSPECV_EH_RETURN    6)
45   (UNSPECV_SET_TP       7)
46 ])
47
48 ;; This code iterator allows signed and unsigned widening multiplications
49 ;; to use the same template.
50 (define_code_iterator any_extend [sign_extend zero_extend])
51
52 ;; <u> expands to an empty string when doing a signed operation and
53 ;; "u" when doing an unsigned operation.
54 (define_code_attr u [(sign_extend "") (zero_extend "u")])
55
56 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
57 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
58
59 ;; This code iterator allows four integer min/max operations to be
60 ;; generated from one template.
61 (define_code_iterator any_minmax [smin umin smax umax])
62
63 ;; <minmax> expands to the opcode name for any_minmax operations.
64 (define_code_attr minmax [(smin "min") (umin "minu")
65                           (smax "max") (umax "maxu")])
66
67 ;; This code iterator allows all branch instructions to be generated from
68 ;; a single define_expand template.
69 (define_code_iterator any_cond [eq ne gt ge lt le gtu geu ltu leu
70                                 uneq ltgt ungt unge unlt unle
71                                 unordered ordered])
72
73 ;; This code iterator is for setting a register from a comparison.
74 (define_code_iterator any_scc [eq ne gt ge lt le])
75
76 ;; This code iterator is for floating-point comparisons.
77 (define_code_iterator any_scc_sf [eq lt le uneq unlt unle unordered])
78 (define_code_attr scc_sf [(eq "oeq") (lt "olt") (le "ole") 
79                           (uneq "ueq") (unlt "ult") (unle "ule")
80                           (unordered "un")])
81
82 ;; This iterator and attribute allow to combine most atomic operations.
83 (define_code_iterator ATOMIC [and ior xor plus minus mult])
84 (define_code_attr atomic [(and "and") (ior "ior") (xor "xor") 
85                           (plus "add") (minus "sub") (mult "nand")])
86
87 ;; This mode iterator allows the HI and QI patterns to be defined from
88 ;; the same template.
89 (define_mode_iterator HQI [HI QI])
90
91 \f
92 ;; Attributes.
93
94 (define_attr "type"
95   "unknown,jump,call,load,store,move,arith,multi,nop,farith,fmadd,fdiv,fsqrt,fconv,fload,fstore,mul16,mul32,div32,mac16,rsr,wsr,entry"
96   (const_string "unknown"))
97
98 (define_attr "mode"
99   "unknown,none,QI,HI,SI,DI,SF,DF,BL"
100   (const_string "unknown"))
101
102 (define_attr "length" "" (const_int 1))
103
104 ;; Describe a user's asm statement.
105 (define_asm_attributes
106   [(set_attr "type" "multi")])
107
108 \f
109 ;; Pipeline model.
110
111 ;; The Xtensa basically has simple 5-stage RISC pipeline.
112 ;; Most instructions complete in 1 cycle, and it is OK to assume that
113 ;; everything is fully pipelined.  The exceptions have special insn
114 ;; reservations in the pipeline description below.  The Xtensa can
115 ;; issue one instruction per cycle, so defining CPU units is unnecessary.
116
117 (define_insn_reservation "xtensa_any_insn" 1
118                          (eq_attr "type" "!load,fload,rsr,mul16,mul32,fmadd,fconv")
119                          "nothing")
120
121 (define_insn_reservation "xtensa_memory" 2
122                          (eq_attr "type" "load,fload")
123                          "nothing")
124
125 (define_insn_reservation "xtensa_sreg" 2
126                          (eq_attr "type" "rsr")
127                          "nothing")
128
129 (define_insn_reservation "xtensa_mul16" 2
130                          (eq_attr "type" "mul16")
131                          "nothing")
132
133 (define_insn_reservation "xtensa_mul32" 2
134                          (eq_attr "type" "mul32")
135                          "nothing")
136
137 (define_insn_reservation "xtensa_fmadd" 4
138                          (eq_attr "type" "fmadd")
139                          "nothing")
140
141 (define_insn_reservation "xtensa_fconv" 2
142                          (eq_attr "type" "fconv")
143                          "nothing")
144 \f
145 ;; Include predicates and constraints.
146
147 (include "predicates.md")
148 (include "constraints.md")
149
150 \f
151 ;; Addition.
152
153 (define_insn "addsi3"
154   [(set (match_operand:SI 0 "register_operand" "=D,D,a,a,a")
155         (plus:SI (match_operand:SI 1 "register_operand" "%d,d,r,r,r")
156                  (match_operand:SI 2 "add_operand" "d,O,r,J,N")))]
157   ""
158   "@
159    add.n\t%0, %1, %2
160    addi.n\t%0, %1, %d2
161    add\t%0, %1, %2
162    addi\t%0, %1, %d2
163    addmi\t%0, %1, %x2"
164   [(set_attr "type"     "arith,arith,arith,arith,arith")
165    (set_attr "mode"     "SI")
166    (set_attr "length"   "2,2,3,3,3")])
167
168 (define_insn "*addx"
169   [(set (match_operand:SI 0 "register_operand" "=a")
170         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
171                           (match_operand:SI 3 "addsubx_operand" "i"))
172                  (match_operand:SI 2 "register_operand" "r")))]
173   "TARGET_ADDX"
174   "addx%3\t%0, %1, %2"
175   [(set_attr "type"     "arith")
176    (set_attr "mode"     "SI")
177    (set_attr "length"   "3")])
178
179 (define_insn "addsf3"
180   [(set (match_operand:SF 0 "register_operand" "=f")
181         (plus:SF (match_operand:SF 1 "register_operand" "%f")
182                  (match_operand:SF 2 "register_operand" "f")))]
183   "TARGET_HARD_FLOAT"
184   "add.s\t%0, %1, %2"
185   [(set_attr "type"     "fmadd")
186    (set_attr "mode"     "SF")
187    (set_attr "length"   "3")])
188
189 \f
190 ;; Subtraction.
191
192 (define_insn "subsi3"
193   [(set (match_operand:SI 0 "register_operand" "=a")
194         (minus:SI (match_operand:SI 1 "register_operand" "r")
195                   (match_operand:SI 2 "register_operand" "r")))]
196   ""
197   "sub\t%0, %1, %2"
198   [(set_attr "type"     "arith")
199    (set_attr "mode"     "SI")
200    (set_attr "length"   "3")])
201
202 (define_insn "*subx"
203   [(set (match_operand:SI 0 "register_operand" "=a")
204         (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
205                            (match_operand:SI 3 "addsubx_operand" "i"))
206                   (match_operand:SI 2 "register_operand" "r")))]
207   "TARGET_ADDX"
208   "subx%3\t%0, %1, %2"
209   [(set_attr "type"     "arith")
210    (set_attr "mode"     "SI")
211    (set_attr "length"   "3")])
212
213 (define_insn "subsf3"
214   [(set (match_operand:SF 0 "register_operand" "=f")
215         (minus:SF (match_operand:SF 1 "register_operand" "f")
216                   (match_operand:SF 2 "register_operand" "f")))]
217   "TARGET_HARD_FLOAT"
218   "sub.s\t%0, %1, %2"
219   [(set_attr "type"     "fmadd")
220    (set_attr "mode"     "SF")
221    (set_attr "length"   "3")])
222
223 \f
224 ;; Multiplication.
225
226 (define_expand "<u>mulsidi3"
227   [(set (match_operand:DI 0 "register_operand")
228         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
229                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
230   "TARGET_MUL32_HIGH"
231 {
232   rtx temp = gen_reg_rtx (SImode);
233   emit_insn (gen_mulsi3 (temp, operands[1], operands[2]));
234   emit_insn (gen_<u>mulsi3_highpart (gen_highpart (SImode, operands[0]),
235                                      operands[1], operands[2]));
236   emit_insn (gen_movsi (gen_lowpart (SImode, operands[0]), temp));
237   DONE;
238 })
239
240 (define_insn "<u>mulsi3_highpart"
241   [(set (match_operand:SI 0 "register_operand" "=a")
242         (truncate:SI
243          (lshiftrt:DI
244           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "%r"))
245                    (any_extend:DI (match_operand:SI 2 "register_operand" "r")))
246           (const_int 32))))]
247   "TARGET_MUL32_HIGH"
248   "mul<su>h\t%0, %1, %2"
249   [(set_attr "type"     "mul32")
250    (set_attr "mode"     "SI")
251    (set_attr "length"   "3")])
252
253 (define_insn "mulsi3"
254   [(set (match_operand:SI 0 "register_operand" "=a")
255         (mult:SI (match_operand:SI 1 "register_operand" "%r")
256                  (match_operand:SI 2 "register_operand" "r")))]
257   "TARGET_MUL32"
258   "mull\t%0, %1, %2"
259   [(set_attr "type"     "mul32")
260    (set_attr "mode"     "SI")
261    (set_attr "length"   "3")])
262
263 (define_insn "mulhisi3"
264   [(set (match_operand:SI 0 "register_operand" "=C,A")
265         (mult:SI (sign_extend:SI
266                   (match_operand:HI 1 "register_operand" "%r,r"))
267                  (sign_extend:SI
268                   (match_operand:HI 2 "register_operand" "r,r"))))]
269   "TARGET_MUL16 || TARGET_MAC16"
270   "@
271    mul16s\t%0, %1, %2
272    mul.aa.ll\t%1, %2"
273   [(set_attr "type"     "mul16,mac16")
274    (set_attr "mode"     "SI")
275    (set_attr "length"   "3,3")])
276
277 (define_insn "umulhisi3"
278   [(set (match_operand:SI 0 "register_operand" "=C,A")
279         (mult:SI (zero_extend:SI
280                   (match_operand:HI 1 "register_operand" "%r,r"))
281                  (zero_extend:SI
282                   (match_operand:HI 2 "register_operand" "r,r"))))]
283   "TARGET_MUL16 || TARGET_MAC16"
284   "@
285    mul16u\t%0, %1, %2
286    umul.aa.ll\t%1, %2"
287   [(set_attr "type"     "mul16,mac16")
288    (set_attr "mode"     "SI")
289    (set_attr "length"   "3,3")])
290
291 (define_insn "muladdhisi"
292   [(set (match_operand:SI 0 "register_operand" "=A")
293         (plus:SI (mult:SI (sign_extend:SI
294                            (match_operand:HI 1 "register_operand" "%r"))
295                           (sign_extend:SI
296                            (match_operand:HI 2 "register_operand" "r")))
297                  (match_operand:SI 3 "register_operand" "0")))]
298   "TARGET_MAC16"
299   "mula.aa.ll\t%1, %2"
300   [(set_attr "type"     "mac16")
301    (set_attr "mode"     "SI")
302    (set_attr "length"   "3")])
303
304 (define_insn "mulsubhisi"
305   [(set (match_operand:SI 0 "register_operand" "=A")
306         (minus:SI (match_operand:SI 1 "register_operand" "0")
307                   (mult:SI (sign_extend:SI
308                             (match_operand:HI 2 "register_operand" "%r"))
309                            (sign_extend:SI
310                             (match_operand:HI 3 "register_operand" "r")))))]
311   "TARGET_MAC16"
312   "muls.aa.ll\t%2, %3"
313   [(set_attr "type"     "mac16")
314    (set_attr "mode"     "SI")
315    (set_attr "length"   "3")])
316
317 (define_insn "mulsf3"
318   [(set (match_operand:SF 0 "register_operand" "=f")
319         (mult:SF (match_operand:SF 1 "register_operand" "%f")
320                  (match_operand:SF 2 "register_operand" "f")))]
321   "TARGET_HARD_FLOAT"
322   "mul.s\t%0, %1, %2"
323   [(set_attr "type"     "fmadd")
324    (set_attr "mode"     "SF")
325    (set_attr "length"   "3")])
326
327 (define_insn "muladdsf3"
328   [(set (match_operand:SF 0 "register_operand" "=f")
329         (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "%f")
330                           (match_operand:SF 2 "register_operand" "f"))
331                  (match_operand:SF 3 "register_operand" "0")))]
332   "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
333   "madd.s\t%0, %1, %2"
334   [(set_attr "type"     "fmadd")
335    (set_attr "mode"     "SF")
336    (set_attr "length"   "3")])
337
338 (define_insn "mulsubsf3"
339   [(set (match_operand:SF 0 "register_operand" "=f")
340         (minus:SF (match_operand:SF 1 "register_operand" "0")
341                   (mult:SF (match_operand:SF 2 "register_operand" "%f")
342                            (match_operand:SF 3 "register_operand" "f"))))]
343   "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
344   "msub.s\t%0, %2, %3"
345   [(set_attr "type"     "fmadd")
346    (set_attr "mode"     "SF")
347    (set_attr "length"   "3")])
348
349 \f
350 ;; Division.
351
352 (define_insn "divsi3"
353   [(set (match_operand:SI 0 "register_operand" "=a")
354         (div:SI (match_operand:SI 1 "register_operand" "r")
355                 (match_operand:SI 2 "register_operand" "r")))]
356   "TARGET_DIV32"
357   "quos\t%0, %1, %2"
358   [(set_attr "type"     "div32")
359    (set_attr "mode"     "SI")
360    (set_attr "length"   "3")])
361
362 (define_insn "udivsi3"
363   [(set (match_operand:SI 0 "register_operand" "=a")
364         (udiv:SI (match_operand:SI 1 "register_operand" "r")
365                  (match_operand:SI 2 "register_operand" "r")))]
366   "TARGET_DIV32"
367   "quou\t%0, %1, %2"
368   [(set_attr "type"     "div32")
369    (set_attr "mode"     "SI")
370    (set_attr "length"   "3")])
371
372 (define_insn "divsf3"
373   [(set (match_operand:SF 0 "register_operand" "=f")
374         (div:SF (match_operand:SF 1 "register_operand" "f")
375                 (match_operand:SF 2 "register_operand" "f")))]
376   "TARGET_HARD_FLOAT_DIV"
377   "div.s\t%0, %1, %2"
378   [(set_attr "type"     "fdiv")
379    (set_attr "mode"     "SF")
380    (set_attr "length"   "3")])
381
382 (define_insn "*recipsf2"
383   [(set (match_operand:SF 0 "register_operand" "=f")
384         (div:SF (match_operand:SF 1 "const_float_1_operand" "")
385                 (match_operand:SF 2 "register_operand" "f")))]
386   "TARGET_HARD_FLOAT_RECIP && flag_unsafe_math_optimizations"
387   "recip.s\t%0, %2"
388   [(set_attr "type"     "fdiv")
389    (set_attr "mode"     "SF")
390    (set_attr "length"   "3")])
391
392 \f
393 ;; Remainders.
394
395 (define_insn "modsi3"
396   [(set (match_operand:SI 0 "register_operand" "=a")
397         (mod:SI (match_operand:SI 1 "register_operand" "r")
398                 (match_operand:SI 2 "register_operand" "r")))]
399   "TARGET_DIV32"
400   "rems\t%0, %1, %2"
401   [(set_attr "type"     "div32")
402    (set_attr "mode"     "SI")
403    (set_attr "length"   "3")])
404
405 (define_insn "umodsi3"
406   [(set (match_operand:SI 0 "register_operand" "=a")
407         (umod:SI (match_operand:SI 1 "register_operand" "r")
408                  (match_operand:SI 2 "register_operand" "r")))]
409   "TARGET_DIV32"
410   "remu\t%0, %1, %2"
411   [(set_attr "type"     "div32")
412    (set_attr "mode"     "SI")
413    (set_attr "length"   "3")])
414
415 \f
416 ;; Square roots.
417
418 (define_insn "sqrtsf2"
419   [(set (match_operand:SF 0 "register_operand" "=f")
420         (sqrt:SF (match_operand:SF 1 "register_operand" "f")))]
421   "TARGET_HARD_FLOAT_SQRT"
422   "sqrt.s\t%0, %1"
423   [(set_attr "type"     "fsqrt")
424    (set_attr "mode"     "SF")
425    (set_attr "length"   "3")])
426
427 (define_insn "*rsqrtsf2"
428   [(set (match_operand:SF 0 "register_operand" "=f")
429         (div:SF (match_operand:SF 1 "const_float_1_operand" "")
430                 (sqrt:SF (match_operand:SF 2 "register_operand" "f"))))]
431   "TARGET_HARD_FLOAT_RSQRT && flag_unsafe_math_optimizations"
432   "rsqrt.s\t%0, %2"
433   [(set_attr "type"     "fsqrt")
434    (set_attr "mode"     "SF")
435    (set_attr "length"   "3")])
436
437 \f
438 ;; Absolute value.
439
440 (define_insn "abssi2"
441   [(set (match_operand:SI 0 "register_operand" "=a")
442         (abs:SI (match_operand:SI 1 "register_operand" "r")))]
443   "TARGET_ABS"
444   "abs\t%0, %1"
445   [(set_attr "type"     "arith")
446    (set_attr "mode"     "SI")
447    (set_attr "length"   "3")])
448
449 (define_insn "abssf2"
450   [(set (match_operand:SF 0 "register_operand" "=f")
451         (abs:SF (match_operand:SF 1 "register_operand" "f")))]
452   "TARGET_HARD_FLOAT"
453   "abs.s\t%0, %1"
454   [(set_attr "type"     "farith")
455    (set_attr "mode"     "SF")
456    (set_attr "length"   "3")])
457
458 \f
459 ;; Min and max.
460
461 (define_insn "<code>si3"
462   [(set (match_operand:SI 0 "register_operand" "=a")
463         (any_minmax:SI (match_operand:SI 1 "register_operand" "%r")
464                        (match_operand:SI 2 "register_operand" "r")))]
465   "TARGET_MINMAX"
466   "<minmax>\t%0, %1, %2"
467   [(set_attr "type"     "arith")
468    (set_attr "mode"     "SI")
469    (set_attr "length"   "3")])
470
471 \f
472 ;; Count leading/trailing zeros and find first bit.
473
474 (define_insn "clzsi2"
475   [(set (match_operand:SI 0 "register_operand" "=a")
476         (clz:SI (match_operand:SI 1 "register_operand" "r")))]
477   "TARGET_NSA"
478   "nsau\t%0, %1"
479   [(set_attr "type"     "arith")
480    (set_attr "mode"     "SI")
481    (set_attr "length"   "3")])
482
483 (define_expand "ctzsi2"
484   [(set (match_operand:SI 0 "register_operand" "")
485         (ctz:SI (match_operand:SI 1 "register_operand" "")))]
486   "TARGET_NSA"
487 {
488   rtx temp = gen_reg_rtx (SImode);
489   emit_insn (gen_negsi2 (temp, operands[1]));
490   emit_insn (gen_andsi3 (temp, temp, operands[1]));
491   emit_insn (gen_clzsi2 (temp, temp));
492   emit_insn (gen_negsi2 (temp, temp));
493   emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (31)));
494   DONE;
495 })
496
497 (define_expand "ffssi2"
498   [(set (match_operand:SI 0 "register_operand" "")
499         (ffs:SI (match_operand:SI 1 "register_operand" "")))]
500   "TARGET_NSA"
501 {
502   rtx temp = gen_reg_rtx (SImode);
503   emit_insn (gen_negsi2 (temp, operands[1]));
504   emit_insn (gen_andsi3 (temp, temp, operands[1]));
505   emit_insn (gen_clzsi2 (temp, temp));
506   emit_insn (gen_negsi2 (temp, temp));
507   emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (32)));
508   DONE;
509 })
510
511 \f
512 ;; Negation and one's complement.
513
514 (define_insn "negsi2"
515   [(set (match_operand:SI 0 "register_operand" "=a")
516         (neg:SI (match_operand:SI 1 "register_operand" "r")))]
517   ""
518   "neg\t%0, %1"
519   [(set_attr "type"     "arith")
520    (set_attr "mode"     "SI")
521    (set_attr "length"   "3")])
522
523 (define_expand "one_cmplsi2"
524   [(set (match_operand:SI 0 "register_operand" "")
525         (not:SI (match_operand:SI 1 "register_operand" "")))]
526   ""
527 {
528   rtx temp = gen_reg_rtx (SImode);
529   emit_insn (gen_movsi (temp, constm1_rtx));
530   emit_insn (gen_xorsi3 (operands[0], temp, operands[1]));
531   DONE;
532 })
533
534 (define_insn "negsf2"
535   [(set (match_operand:SF 0 "register_operand" "=f")
536         (neg:SF (match_operand:SF 1 "register_operand" "f")))]
537   "TARGET_HARD_FLOAT"
538   "neg.s\t%0, %1"
539   [(set_attr "type"     "farith")
540    (set_attr "mode"     "SF")
541    (set_attr "length"   "3")])
542
543 \f
544 ;; Logical instructions.
545
546 (define_insn "andsi3"
547   [(set (match_operand:SI 0 "register_operand" "=a,a")
548         (and:SI (match_operand:SI 1 "register_operand" "%r,r")
549                 (match_operand:SI 2 "mask_operand" "P,r")))]
550   ""
551   "@
552    extui\t%0, %1, 0, %K2
553    and\t%0, %1, %2"
554   [(set_attr "type"     "arith,arith")
555    (set_attr "mode"     "SI")
556    (set_attr "length"   "3,3")])
557
558 (define_insn "iorsi3"
559   [(set (match_operand:SI 0 "register_operand" "=a")
560         (ior:SI (match_operand:SI 1 "register_operand" "%r")
561                 (match_operand:SI 2 "register_operand" "r")))]
562   ""
563   "or\t%0, %1, %2"
564   [(set_attr "type"     "arith")
565    (set_attr "mode"     "SI")
566    (set_attr "length"   "3")])
567
568 (define_insn "xorsi3"
569   [(set (match_operand:SI 0 "register_operand" "=a")
570         (xor:SI (match_operand:SI 1 "register_operand" "%r")
571                 (match_operand:SI 2 "register_operand" "r")))]
572   ""
573   "xor\t%0, %1, %2"
574   [(set_attr "type"     "arith")
575    (set_attr "mode"     "SI")
576    (set_attr "length"   "3")])
577
578 \f
579 ;; Zero-extend instructions.
580
581 (define_insn "zero_extendhisi2"
582   [(set (match_operand:SI 0 "register_operand" "=a,a")
583         (zero_extend:SI (match_operand:HI 1 "nonimmed_operand" "r,U")))]
584   ""
585   "@
586    extui\t%0, %1, 0, 16
587    l16ui\t%0, %1"
588   [(set_attr "type"     "arith,load")
589    (set_attr "mode"     "SI")
590    (set_attr "length"   "3,3")])
591
592 (define_insn "zero_extendqisi2"
593   [(set (match_operand:SI 0 "register_operand" "=a,a")
594         (zero_extend:SI (match_operand:QI 1 "nonimmed_operand" "r,U")))]
595   ""
596   "@
597    extui\t%0, %1, 0, 8
598    l8ui\t%0, %1"
599   [(set_attr "type"     "arith,load")
600    (set_attr "mode"     "SI")
601    (set_attr "length"   "3,3")])
602
603 \f
604 ;; Sign-extend instructions.
605
606 (define_expand "extendhisi2"
607   [(set (match_operand:SI 0 "register_operand" "")
608         (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
609   ""
610 {
611   if (sext_operand (operands[1], HImode))
612     emit_insn (gen_extendhisi2_internal (operands[0], operands[1]));
613   else
614     xtensa_extend_reg (operands[0], operands[1]);
615   DONE;
616 })
617
618 (define_insn "extendhisi2_internal"
619   [(set (match_operand:SI 0 "register_operand" "=B,a")
620         (sign_extend:SI (match_operand:HI 1 "sext_operand" "r,U")))]
621   ""
622   "@
623    sext\t%0, %1, 15
624    l16si\t%0, %1"
625   [(set_attr "type"     "arith,load")
626    (set_attr "mode"     "SI")
627    (set_attr "length"   "3,3")])
628
629 (define_expand "extendqisi2"
630   [(set (match_operand:SI 0 "register_operand" "")
631         (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
632   ""
633 {
634   if (TARGET_SEXT)
635     emit_insn (gen_extendqisi2_internal (operands[0], operands[1]));
636   else
637     xtensa_extend_reg (operands[0], operands[1]);
638   DONE;
639 })
640
641 (define_insn "extendqisi2_internal"
642   [(set (match_operand:SI 0 "register_operand" "=B")
643         (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
644   "TARGET_SEXT"
645   "sext\t%0, %1, 7"
646   [(set_attr "type"     "arith")
647    (set_attr "mode"     "SI")
648    (set_attr "length"   "3")])
649
650 \f
651 ;; Field extract instructions.
652
653 (define_expand "extv"
654   [(set (match_operand:SI 0 "register_operand" "")
655         (sign_extract:SI (match_operand:SI 1 "register_operand" "")
656                          (match_operand:SI 2 "const_int_operand" "")
657                          (match_operand:SI 3 "const_int_operand" "")))]
658   "TARGET_SEXT"
659 {
660   if (!sext_fldsz_operand (operands[2], SImode))
661     FAIL;
662
663   /* We could expand to a right shift followed by SEXT but that's
664      no better than the standard left and right shift sequence.  */
665   if (!lsbitnum_operand (operands[3], SImode))
666     FAIL;
667
668   emit_insn (gen_extv_internal (operands[0], operands[1],
669                                 operands[2], operands[3]));
670   DONE;
671 })
672
673 (define_insn "extv_internal"
674   [(set (match_operand:SI 0 "register_operand" "=a")
675         (sign_extract:SI (match_operand:SI 1 "register_operand" "r")
676                          (match_operand:SI 2 "sext_fldsz_operand" "i")
677                          (match_operand:SI 3 "lsbitnum_operand" "i")))]
678   "TARGET_SEXT"
679 {
680   int fldsz = INTVAL (operands[2]);
681   operands[2] = GEN_INT (fldsz - 1);
682   return "sext\t%0, %1, %2";
683 }
684   [(set_attr "type"     "arith")
685    (set_attr "mode"     "SI")
686    (set_attr "length"   "3")])
687
688 (define_expand "extzv"
689   [(set (match_operand:SI 0 "register_operand" "")
690         (zero_extract:SI (match_operand:SI 1 "register_operand" "")
691                          (match_operand:SI 2 "const_int_operand" "")
692                          (match_operand:SI 3 "const_int_operand" "")))]
693   ""
694 {
695   if (!extui_fldsz_operand (operands[2], SImode))
696     FAIL;
697   emit_insn (gen_extzv_internal (operands[0], operands[1],
698                                  operands[2], operands[3]));
699   DONE;
700 })
701
702 (define_insn "extzv_internal"
703   [(set (match_operand:SI 0 "register_operand" "=a")
704         (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
705                          (match_operand:SI 2 "extui_fldsz_operand" "i")
706                          (match_operand:SI 3 "const_int_operand" "i")))]
707   ""
708 {
709   int shift;
710   if (BITS_BIG_ENDIAN)
711     shift = (32 - (INTVAL (operands[2]) + INTVAL (operands[3]))) & 0x1f;
712   else
713     shift = INTVAL (operands[3]) & 0x1f;
714   operands[3] = GEN_INT (shift);
715   return "extui\t%0, %1, %3, %2";
716 }
717   [(set_attr "type"     "arith")
718    (set_attr "mode"     "SI")
719    (set_attr "length"   "3")])
720
721 \f
722 ;; Conversions.
723
724 (define_insn "fix_truncsfsi2"
725   [(set (match_operand:SI 0 "register_operand" "=a")
726         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
727   "TARGET_HARD_FLOAT"
728   "trunc.s\t%0, %1, 0"
729   [(set_attr "type"     "fconv")
730    (set_attr "mode"     "SF")
731    (set_attr "length"   "3")])
732
733 (define_insn "fixuns_truncsfsi2"
734   [(set (match_operand:SI 0 "register_operand" "=a")
735         (unsigned_fix:SI (match_operand:SF 1 "register_operand" "f")))]
736   "TARGET_HARD_FLOAT"
737   "utrunc.s\t%0, %1, 0"
738   [(set_attr "type"     "fconv")
739    (set_attr "mode"     "SF")
740    (set_attr "length"   "3")])
741
742 (define_insn "floatsisf2"
743   [(set (match_operand:SF 0 "register_operand" "=f")
744         (float:SF (match_operand:SI 1 "register_operand" "a")))]
745   "TARGET_HARD_FLOAT"
746   "float.s\t%0, %1, 0"
747   [(set_attr "type"     "fconv")
748    (set_attr "mode"     "SF")
749    (set_attr "length"   "3")])
750
751 (define_insn "floatunssisf2"
752   [(set (match_operand:SF 0 "register_operand" "=f")
753         (unsigned_float:SF (match_operand:SI 1 "register_operand" "a")))]
754   "TARGET_HARD_FLOAT"
755   "ufloat.s\t%0, %1, 0"
756   [(set_attr "type"     "fconv")
757    (set_attr "mode"     "SF")
758    (set_attr "length"   "3")])
759
760 \f
761 ;; Data movement instructions.
762
763 ;; 64-bit Integer moves
764
765 (define_expand "movdi"
766   [(set (match_operand:DI 0 "nonimmed_operand" "")
767         (match_operand:DI 1 "general_operand" ""))]
768   ""
769 {
770   if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
771     operands[1] = force_const_mem (DImode, operands[1]);
772
773   if (!register_operand (operands[0], DImode)
774       && !register_operand (operands[1], DImode))
775     operands[1] = force_reg (DImode, operands[1]);
776
777   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
778 })
779
780 (define_insn_and_split "movdi_internal"
781   [(set (match_operand:DI 0 "nonimmed_operand" "=a,W,a,a,U")
782         (match_operand:DI 1 "move_operand" "r,i,T,U,r"))]
783   "register_operand (operands[0], DImode)
784    || register_operand (operands[1], DImode)"
785   "#"
786   "reload_completed"
787   [(set (match_dup 0) (match_dup 2))
788    (set (match_dup 1) (match_dup 3))]
789 {
790   xtensa_split_operand_pair (operands, SImode);
791   if (reg_overlap_mentioned_p (operands[0], operands[3]))
792     {
793       rtx tmp;
794       tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
795       tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
796     }
797 })
798
799 ;; 32-bit Integer moves
800
801 (define_expand "movsi"
802   [(set (match_operand:SI 0 "nonimmed_operand" "")
803         (match_operand:SI 1 "general_operand" ""))]
804   ""
805 {
806   if (xtensa_emit_move_sequence (operands, SImode))
807     DONE;
808 })
809
810 (define_insn "movsi_internal"
811   [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,W,a,a,U,*a,*A")
812         (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,i,T,U,r,*A,*r"))]
813   "xtensa_valid_move (SImode, operands)"
814   "@
815    movi.n\t%0, %x1
816    mov.n\t%0, %1
817    mov.n\t%0, %1
818    %v1l32i.n\t%0, %1
819    %v0s32i.n\t%1, %0
820    %v0s32i.n\t%1, %0
821    mov\t%0, %1
822    movsp\t%0, %1
823    movi\t%0, %x1
824    const16\t%0, %t1\;const16\t%0, %b1
825    %v1l32r\t%0, %1
826    %v1l32i\t%0, %1
827    %v0s32i\t%1, %0
828    rsr\t%0, ACCLO
829    wsr\t%1, ACCLO"
830   [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,load,load,store,rsr,wsr")
831    (set_attr "mode"     "SI")
832    (set_attr "length"   "2,2,2,2,2,2,3,3,3,6,3,3,3,3,3")])
833
834 ;; 16-bit Integer moves
835
836 (define_expand "movhi"
837   [(set (match_operand:HI 0 "nonimmed_operand" "")
838         (match_operand:HI 1 "general_operand" ""))]
839   ""
840 {
841   if (xtensa_emit_move_sequence (operands, HImode))
842     DONE;
843 })
844
845 (define_insn "movhi_internal"
846   [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
847         (match_operand:HI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
848   "xtensa_valid_move (HImode, operands)"
849   "@
850    movi.n\t%0, %x1
851    mov.n\t%0, %1
852    mov\t%0, %1
853    movi\t%0, %x1
854    %v1l16ui\t%0, %1
855    %v0s16i\t%1, %0
856    rsr\t%0, ACCLO
857    wsr\t%1, ACCLO"
858   [(set_attr "type"     "move,move,move,move,load,store,rsr,wsr")
859    (set_attr "mode"     "HI")
860    (set_attr "length"   "2,2,3,3,3,3,3,3")])
861
862 ;; 8-bit Integer moves
863
864 (define_expand "movqi"
865   [(set (match_operand:QI 0 "nonimmed_operand" "")
866         (match_operand:QI 1 "general_operand" ""))]
867   ""
868 {
869   if (xtensa_emit_move_sequence (operands, QImode))
870     DONE;
871 })
872
873 (define_insn "movqi_internal"
874   [(set (match_operand:QI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
875         (match_operand:QI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
876   "xtensa_valid_move (QImode, operands)"
877   "@
878    movi.n\t%0, %x1
879    mov.n\t%0, %1
880    mov\t%0, %1
881    movi\t%0, %x1
882    %v1l8ui\t%0, %1
883    %v0s8i\t%1, %0
884    rsr\t%0, ACCLO
885    wsr\t%1, ACCLO"
886   [(set_attr "type"     "move,move,move,move,load,store,rsr,wsr")
887    (set_attr "mode"     "QI")
888    (set_attr "length"   "2,2,3,3,3,3,3,3")])
889
890 ;; Sub-word reloads from the constant pool.
891
892 (define_expand "reload<mode>_literal"
893   [(parallel [(match_operand:HQI 0 "register_operand" "=r")
894               (match_operand:HQI 1 "constantpool_operand" "")
895               (match_operand:SI 2 "register_operand" "=&r")])]
896   ""
897 {
898   rtx lit, scratch;
899   unsigned word_off, byte_off;
900
901   gcc_assert (GET_CODE (operands[1]) == SUBREG);
902   lit = SUBREG_REG (operands[1]);
903   scratch = operands[2];
904   word_off = SUBREG_BYTE (operands[1]) & ~(UNITS_PER_WORD - 1);
905   byte_off = SUBREG_BYTE (operands[1]) - word_off;
906
907   lit = adjust_address (lit, SImode, word_off);
908   emit_insn (gen_movsi (scratch, lit));
909   emit_insn (gen_mov<mode> (operands[0],
910                             gen_rtx_SUBREG (<MODE>mode, scratch, byte_off)));
911
912   DONE;
913 })
914
915 ;; 32-bit floating point moves
916
917 (define_expand "movsf"
918   [(set (match_operand:SF 0 "nonimmed_operand" "")
919         (match_operand:SF 1 "general_operand" ""))]
920   ""
921 {
922   if (!TARGET_CONST16 && CONSTANT_P (operands[1]))
923     operands[1] = force_const_mem (SFmode, operands[1]);
924
925   if ((!register_operand (operands[0], SFmode)
926        && !register_operand (operands[1], SFmode))
927       || (FP_REG_P (xt_true_regnum (operands[0]))
928           && !(reload_in_progress | reload_completed)
929           && (constantpool_mem_p (operands[1])
930               || CONSTANT_P (operands[1]))))
931     operands[1] = force_reg (SFmode, operands[1]);
932
933   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
934 })
935
936 (define_insn "movsf_internal"
937   [(set (match_operand:SF 0 "nonimmed_operand" "=f,f,U,D,D,R,a,f,a,W,a,a,U")
938         (match_operand:SF 1 "move_operand" "f,U,f,d,R,d,r,r,f,iF,T,U,r"))]
939   "((register_operand (operands[0], SFmode)
940      || register_operand (operands[1], SFmode))
941     && !(FP_REG_P (xt_true_regnum (operands[0]))
942          && (constantpool_mem_p (operands[1]) || CONSTANT_P (operands[1]))))"
943   "@
944    mov.s\t%0, %1
945    %v1lsi\t%0, %1
946    %v0ssi\t%1, %0
947    mov.n\t%0, %1
948    %v1l32i.n\t%0, %1
949    %v0s32i.n\t%1, %0
950    mov\t%0, %1
951    wfr\t%0, %1
952    rfr\t%0, %1
953    const16\t%0, %t1\;const16\t%0, %b1
954    %v1l32r\t%0, %1
955    %v1l32i\t%0, %1
956    %v0s32i\t%1, %0"
957   [(set_attr "type"     "farith,fload,fstore,move,load,store,move,farith,farith,move,load,load,store")
958    (set_attr "mode"     "SF")
959    (set_attr "length"   "3,3,3,2,2,2,3,3,3,6,3,3,3")])
960
961 (define_insn "*lsiu"
962   [(set (match_operand:SF 0 "register_operand" "=f")
963         (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "+a")
964                          (match_operand:SI 2 "fpmem_offset_operand" "i"))))
965    (set (match_dup 1)
966         (plus:SI (match_dup 1) (match_dup 2)))]
967   "TARGET_HARD_FLOAT"
968 {
969   if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
970     output_asm_insn ("memw", operands);
971   return "lsiu\t%0, %1, %2";
972 }
973   [(set_attr "type"     "fload")
974    (set_attr "mode"     "SF")
975    (set_attr "length"   "3")])
976
977 (define_insn "*ssiu"
978   [(set (mem:SF (plus:SI (match_operand:SI 0 "register_operand" "+a")
979                          (match_operand:SI 1 "fpmem_offset_operand" "i")))
980         (match_operand:SF 2 "register_operand" "f"))
981    (set (match_dup 0)
982         (plus:SI (match_dup 0) (match_dup 1)))]
983   "TARGET_HARD_FLOAT"
984 {
985   if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
986     output_asm_insn ("memw", operands);
987   return "ssiu\t%2, %0, %1";
988 }
989   [(set_attr "type"     "fstore")
990    (set_attr "mode"     "SF")
991    (set_attr "length"   "3")])
992
993 ;; 64-bit floating point moves
994
995 (define_expand "movdf"
996   [(set (match_operand:DF 0 "nonimmed_operand" "")
997         (match_operand:DF 1 "general_operand" ""))]
998   ""
999 {
1000   if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
1001     operands[1] = force_const_mem (DFmode, operands[1]);
1002
1003   if (!register_operand (operands[0], DFmode)
1004       && !register_operand (operands[1], DFmode))
1005     operands[1] = force_reg (DFmode, operands[1]);
1006
1007   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1008 })
1009
1010 (define_insn_and_split "movdf_internal"
1011   [(set (match_operand:DF 0 "nonimmed_operand" "=a,W,a,a,U")
1012         (match_operand:DF 1 "move_operand" "r,iF,T,U,r"))]
1013   "register_operand (operands[0], DFmode)
1014    || register_operand (operands[1], DFmode)"
1015   "#"
1016   "reload_completed"
1017   [(set (match_dup 0) (match_dup 2))
1018    (set (match_dup 1) (match_dup 3))]
1019 {
1020   xtensa_split_operand_pair (operands, SFmode);
1021   if (reg_overlap_mentioned_p (operands[0], operands[3]))
1022     {
1023       rtx tmp;
1024       tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
1025       tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
1026     }
1027 })
1028
1029 ;; Block moves
1030
1031 (define_expand "movmemsi"
1032   [(parallel [(set (match_operand:BLK 0 "" "")
1033                    (match_operand:BLK 1 "" ""))
1034               (use (match_operand:SI 2 "arith_operand" ""))
1035               (use (match_operand:SI 3 "const_int_operand" ""))])]
1036   ""
1037 {
1038   if (!xtensa_expand_block_move (operands))
1039     FAIL;
1040   DONE;
1041 })
1042
1043 \f
1044 ;; Shift instructions.
1045
1046 (define_expand "ashlsi3"
1047   [(set (match_operand:SI 0 "register_operand" "")
1048         (ashift:SI (match_operand:SI 1 "register_operand" "")
1049                    (match_operand:SI 2 "arith_operand" "")))]
1050   ""
1051 {
1052   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1053 })
1054
1055 (define_insn "ashlsi3_internal"
1056   [(set (match_operand:SI 0 "register_operand" "=a,a")
1057         (ashift:SI (match_operand:SI 1 "register_operand" "r,r")
1058                    (match_operand:SI 2 "arith_operand" "J,r")))]
1059   ""      
1060   "@
1061    slli\t%0, %1, %R2
1062    ssl\t%2\;sll\t%0, %1"
1063   [(set_attr "type"     "arith,arith")
1064    (set_attr "mode"     "SI")
1065    (set_attr "length"   "3,6")])
1066
1067 (define_insn "ashrsi3"
1068   [(set (match_operand:SI 0 "register_operand" "=a,a")
1069         (ashiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1070                      (match_operand:SI 2 "arith_operand" "J,r")))]
1071   ""
1072   "@
1073    srai\t%0, %1, %R2
1074    ssr\t%2\;sra\t%0, %1"
1075   [(set_attr "type"     "arith,arith")
1076    (set_attr "mode"     "SI")
1077    (set_attr "length"   "3,6")])
1078
1079 (define_insn "lshrsi3"
1080   [(set (match_operand:SI 0 "register_operand" "=a,a")
1081         (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1082                      (match_operand:SI 2 "arith_operand" "J,r")))]
1083   ""
1084 {
1085   if (which_alternative == 0)
1086     {
1087       if ((INTVAL (operands[2]) & 0x1f) < 16)
1088         return "srli\t%0, %1, %R2";
1089       else
1090         return "extui\t%0, %1, %R2, %L2";
1091     }
1092   return "ssr\t%2\;srl\t%0, %1";
1093 }
1094   [(set_attr "type"     "arith,arith")
1095    (set_attr "mode"     "SI")
1096    (set_attr "length"   "3,6")])
1097
1098 (define_insn "rotlsi3"
1099   [(set (match_operand:SI 0 "register_operand" "=a,a")
1100         (rotate:SI (match_operand:SI 1 "register_operand" "r,r")
1101                      (match_operand:SI 2 "arith_operand" "J,r")))]
1102   ""
1103   "@
1104    ssai\t%L2\;src\t%0, %1, %1
1105    ssl\t%2\;src\t%0, %1, %1"
1106   [(set_attr "type"     "multi,multi")
1107    (set_attr "mode"     "SI")
1108    (set_attr "length"   "6,6")])
1109
1110 (define_insn "rotrsi3"
1111   [(set (match_operand:SI 0 "register_operand" "=a,a")
1112         (rotatert:SI (match_operand:SI 1 "register_operand" "r,r")
1113                      (match_operand:SI 2 "arith_operand" "J,r")))]
1114   ""
1115   "@
1116    ssai\t%R2\;src\t%0, %1, %1
1117    ssr\t%2\;src\t%0, %1, %1"
1118   [(set_attr "type"     "multi,multi")
1119    (set_attr "mode"     "SI")
1120    (set_attr "length"   "6,6")])
1121
1122 \f
1123 ;; Comparisons.
1124
1125 ;; Handle comparisons by stashing away the operands and then using that
1126 ;; information in the subsequent conditional branch.
1127
1128 (define_expand "cmpsi"
1129   [(set (cc0)
1130         (compare:CC (match_operand:SI 0 "register_operand" "")
1131                     (match_operand:SI 1 "nonmemory_operand" "")))]
1132   ""
1133 {
1134   branch_cmp[0] = operands[0];
1135   branch_cmp[1] = operands[1];
1136   branch_type = CMP_SI;
1137   DONE;
1138 })
1139
1140 (define_expand "cmpsf"
1141   [(set (cc0)
1142         (compare:CC (match_operand:SF 0 "register_operand" "")
1143                     (match_operand:SF 1 "register_operand" "")))]
1144   "TARGET_HARD_FLOAT"
1145 {
1146   branch_cmp[0] = operands[0];
1147   branch_cmp[1] = operands[1];
1148   branch_type = CMP_SF;
1149   DONE;
1150 })
1151
1152 \f
1153 ;; Conditional branches.
1154
1155 (define_expand "b<code>"
1156   [(set (pc)
1157         (if_then_else (any_cond (cc0) (const_int 0))
1158                       (label_ref (match_operand 0 "" ""))
1159                       (pc)))]
1160   ""
1161 {
1162   xtensa_expand_conditional_branch (operands, <CODE>);
1163   DONE;
1164 })
1165
1166 ;; Branch patterns for standard integer comparisons
1167
1168 (define_insn "*btrue"
1169   [(set (pc)
1170         (if_then_else (match_operator 3 "branch_operator"
1171                        [(match_operand:SI 0 "register_operand" "r,r")
1172                         (match_operand:SI 1 "branch_operand" "K,r")])
1173                       (label_ref (match_operand 2 "" ""))
1174                       (pc)))]
1175   ""
1176 {
1177   return xtensa_emit_branch (false, which_alternative == 0, operands);
1178 }
1179   [(set_attr "type"     "jump,jump")
1180    (set_attr "mode"     "none")
1181    (set_attr "length"   "3,3")])
1182
1183 (define_insn "*bfalse"
1184   [(set (pc)
1185         (if_then_else (match_operator 3 "branch_operator"
1186                        [(match_operand:SI 0 "register_operand" "r,r")
1187                         (match_operand:SI 1 "branch_operand" "K,r")])
1188                       (pc)
1189                       (label_ref (match_operand 2 "" ""))))]
1190   ""
1191 {
1192   return xtensa_emit_branch (true, which_alternative == 0, operands);
1193 }
1194   [(set_attr "type"     "jump,jump")
1195    (set_attr "mode"     "none")
1196    (set_attr "length"   "3,3")])
1197
1198 (define_insn "*ubtrue"
1199   [(set (pc)
1200         (if_then_else (match_operator 3 "ubranch_operator"
1201                        [(match_operand:SI 0 "register_operand" "r,r")
1202                         (match_operand:SI 1 "ubranch_operand" "L,r")])
1203                       (label_ref (match_operand 2 "" ""))
1204                       (pc)))]
1205   ""
1206 {
1207   return xtensa_emit_branch (false, which_alternative == 0, operands);
1208 }
1209   [(set_attr "type"     "jump,jump")
1210    (set_attr "mode"     "none")
1211    (set_attr "length"   "3,3")])
1212
1213 (define_insn "*ubfalse"
1214   [(set (pc)
1215         (if_then_else (match_operator 3 "ubranch_operator"
1216                          [(match_operand:SI 0 "register_operand" "r,r")
1217                           (match_operand:SI 1 "ubranch_operand" "L,r")])
1218                       (pc)
1219                       (label_ref (match_operand 2 "" ""))))]
1220   ""
1221 {
1222   return xtensa_emit_branch (true, which_alternative == 0, operands);
1223 }
1224   [(set_attr "type"     "jump,jump")
1225    (set_attr "mode"     "none")
1226    (set_attr "length"   "3,3")])
1227
1228 ;; Branch patterns for bit testing
1229
1230 (define_insn "*bittrue"
1231   [(set (pc)
1232         (if_then_else (match_operator 3 "boolean_operator"
1233                         [(zero_extract:SI
1234                             (match_operand:SI 0 "register_operand" "r,r")
1235                             (const_int 1)
1236                             (match_operand:SI 1 "arith_operand" "J,r"))
1237                          (const_int 0)])
1238                       (label_ref (match_operand 2 "" ""))
1239                       (pc)))]
1240   ""
1241 {
1242   return xtensa_emit_bit_branch (false, which_alternative == 0, operands);
1243 }
1244   [(set_attr "type"     "jump")
1245    (set_attr "mode"     "none")
1246    (set_attr "length"   "3")])
1247
1248 (define_insn "*bitfalse"
1249   [(set (pc)
1250         (if_then_else (match_operator 3 "boolean_operator"
1251                         [(zero_extract:SI
1252                             (match_operand:SI 0 "register_operand" "r,r")
1253                             (const_int 1)
1254                             (match_operand:SI 1 "arith_operand" "J,r"))
1255                          (const_int 0)])
1256                       (pc)
1257                       (label_ref (match_operand 2 "" ""))))]
1258   ""
1259 {
1260   return xtensa_emit_bit_branch (true, which_alternative == 0, operands);
1261 }
1262   [(set_attr "type"     "jump")
1263    (set_attr "mode"     "none")
1264    (set_attr "length"   "3")])
1265
1266 (define_insn "*masktrue"
1267   [(set (pc)
1268         (if_then_else (match_operator 3 "boolean_operator"
1269                  [(and:SI (match_operand:SI 0 "register_operand" "r")
1270                           (match_operand:SI 1 "register_operand" "r"))
1271                   (const_int 0)])
1272                       (label_ref (match_operand 2 "" ""))
1273                       (pc)))]
1274   ""
1275 {
1276   switch (GET_CODE (operands[3]))
1277     {
1278     case EQ:            return "bnone\t%0, %1, %2";
1279     case NE:            return "bany\t%0, %1, %2";
1280     default:            gcc_unreachable ();
1281     }
1282 }
1283   [(set_attr "type"     "jump")
1284    (set_attr "mode"     "none")
1285    (set_attr "length"   "3")])
1286
1287 (define_insn "*maskfalse"
1288   [(set (pc)
1289         (if_then_else (match_operator 3 "boolean_operator"
1290                  [(and:SI (match_operand:SI 0 "register_operand" "r")
1291                           (match_operand:SI 1 "register_operand" "r"))
1292                   (const_int 0)])
1293                       (pc)
1294                       (label_ref (match_operand 2 "" ""))))]
1295   ""
1296 {
1297   switch (GET_CODE (operands[3]))
1298     {
1299     case EQ:            return "bany\t%0, %1, %2";
1300     case NE:            return "bnone\t%0, %1, %2";
1301     default:            gcc_unreachable ();
1302     }
1303 }
1304   [(set_attr "type"     "jump")
1305    (set_attr "mode"     "none")
1306    (set_attr "length"   "3")])
1307
1308
1309 ;; Define the loop insns used by bct optimization to represent the
1310 ;; start and end of a zero-overhead loop (in loop.c).  This start
1311 ;; template generates the loop insn; the end template doesn't generate
1312 ;; any instructions since loop end is handled in hardware.
1313
1314 (define_insn "zero_cost_loop_start"
1315   [(set (pc)
1316         (if_then_else (eq (match_operand:SI 0 "register_operand" "a")
1317                           (const_int 0))
1318                       (label_ref (match_operand 1 "" ""))
1319                       (pc)))
1320    (set (reg:SI 19)
1321         (plus:SI (match_dup 0) (const_int -1)))]
1322   ""
1323   "loopnez\t%0, %l1"
1324   [(set_attr "type"     "jump")
1325    (set_attr "mode"     "none")
1326    (set_attr "length"   "3")])
1327
1328 (define_insn "zero_cost_loop_end"
1329   [(set (pc)
1330         (if_then_else (ne (reg:SI 19) (const_int 0))
1331                       (label_ref (match_operand 0 "" ""))
1332                       (pc)))
1333    (set (reg:SI 19)
1334         (plus:SI (reg:SI 19) (const_int -1)))]
1335   ""
1336 {
1337     xtensa_emit_loop_end (insn, operands);
1338     return "";
1339 }
1340   [(set_attr "type"     "jump")
1341    (set_attr "mode"     "none")
1342    (set_attr "length"   "0")])
1343
1344 \f
1345 ;; Setting a register from a comparison.
1346
1347 (define_expand "s<code>"
1348   [(set (match_operand:SI 0 "register_operand" "")
1349         (any_scc:SI (match_dup 1)
1350                     (match_dup 2)))]
1351   ""
1352 {
1353   operands[1] = gen_rtx_<CODE> (SImode, branch_cmp[0], branch_cmp[1]);
1354   if (!xtensa_expand_scc (operands))
1355     FAIL;
1356   DONE;
1357 })
1358
1359 \f
1360 ;; Conditional moves.
1361
1362 (define_expand "movsicc"
1363   [(set (match_operand:SI 0 "register_operand" "")
1364         (if_then_else:SI (match_operand 1 "comparison_operator" "")
1365                          (match_operand:SI 2 "register_operand" "")
1366                          (match_operand:SI 3 "register_operand" "")))]
1367   ""
1368 {
1369   if (!xtensa_expand_conditional_move (operands, 0))
1370     FAIL;
1371   DONE;
1372 })
1373
1374 (define_expand "movsfcc"
1375   [(set (match_operand:SF 0 "register_operand" "")
1376         (if_then_else:SF (match_operand 1 "comparison_operator" "")
1377                          (match_operand:SF 2 "register_operand" "")
1378                          (match_operand:SF 3 "register_operand" "")))]
1379   ""
1380 {
1381   if (!xtensa_expand_conditional_move (operands, 1))
1382     FAIL;
1383   DONE;
1384 })
1385
1386 (define_insn "movsicc_internal0"
1387   [(set (match_operand:SI 0 "register_operand" "=a,a")
1388         (if_then_else:SI (match_operator 4 "branch_operator"
1389                            [(match_operand:SI 1 "register_operand" "r,r")
1390                             (const_int 0)])
1391                          (match_operand:SI 2 "register_operand" "r,0")
1392                          (match_operand:SI 3 "register_operand" "0,r")))]
1393   ""
1394 {
1395   return xtensa_emit_movcc (which_alternative == 1, false, false, operands);
1396 }
1397   [(set_attr "type"     "move,move")
1398    (set_attr "mode"     "SI")
1399    (set_attr "length"   "3,3")])
1400
1401 (define_insn "movsicc_internal1"
1402   [(set (match_operand:SI 0 "register_operand" "=a,a")
1403         (if_then_else:SI (match_operator 4 "boolean_operator"
1404                            [(match_operand:CC 1 "register_operand" "b,b")
1405                             (const_int 0)])
1406                          (match_operand:SI 2 "register_operand" "r,0")
1407                          (match_operand:SI 3 "register_operand" "0,r")))]
1408   "TARGET_BOOLEANS"
1409 {
1410   return xtensa_emit_movcc (which_alternative == 1, false, true, operands);
1411 }
1412   [(set_attr "type"     "move,move")
1413    (set_attr "mode"     "SI")
1414    (set_attr "length"   "3,3")])
1415
1416 (define_insn "movsfcc_internal0"
1417   [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1418         (if_then_else:SF (match_operator 4 "branch_operator"
1419                            [(match_operand:SI 1 "register_operand" "r,r,r,r")
1420                             (const_int 0)])
1421                          (match_operand:SF 2 "register_operand" "r,0,f,0")
1422                          (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1423   ""
1424 {
1425   return xtensa_emit_movcc ((which_alternative & 1) == 1,
1426                             which_alternative >= 2, false, operands);
1427 }
1428   [(set_attr "type"     "move,move,move,move")
1429    (set_attr "mode"     "SF")
1430    (set_attr "length"   "3,3,3,3")])
1431
1432 (define_insn "movsfcc_internal1"
1433   [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1434         (if_then_else:SF (match_operator 4 "boolean_operator"
1435                            [(match_operand:CC 1 "register_operand" "b,b,b,b")
1436                             (const_int 0)])
1437                          (match_operand:SF 2 "register_operand" "r,0,f,0")
1438                          (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1439   "TARGET_BOOLEANS"
1440 {
1441   return xtensa_emit_movcc ((which_alternative & 1) == 1,
1442                             which_alternative >= 2, true, operands);
1443 }
1444   [(set_attr "type"     "move,move,move,move")
1445    (set_attr "mode"     "SF")
1446    (set_attr "length"   "3,3,3,3")])
1447
1448 \f
1449 ;; Floating-point comparisons.
1450
1451 (define_insn "s<code>_sf"
1452   [(set (match_operand:CC 0 "register_operand" "=b")
1453         (any_scc_sf:CC (match_operand:SF 1 "register_operand" "f")
1454                        (match_operand:SF 2 "register_operand" "f")))]
1455   "TARGET_HARD_FLOAT"
1456   "<scc_sf>.s\t%0, %1, %2"
1457   [(set_attr "type"     "farith")
1458    (set_attr "mode"     "BL")
1459    (set_attr "length"   "3")])
1460
1461 \f
1462 ;; Unconditional branches.
1463
1464 (define_insn "jump"
1465   [(set (pc)
1466         (label_ref (match_operand 0 "" "")))]
1467   ""
1468   "j\t%l0"
1469   [(set_attr "type"     "jump")
1470    (set_attr "mode"     "none")
1471    (set_attr "length"   "3")])
1472
1473 (define_expand "indirect_jump"
1474   [(set (pc)
1475         (match_operand 0 "register_operand" ""))]
1476   ""
1477 {
1478   rtx dest = operands[0];
1479   if (GET_CODE (dest) != REG || GET_MODE (dest) != Pmode)
1480     operands[0] = copy_to_mode_reg (Pmode, dest);
1481
1482   emit_jump_insn (gen_indirect_jump_internal (dest));
1483   DONE;
1484 })
1485
1486 (define_insn "indirect_jump_internal"
1487   [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
1488   ""
1489   "jx\t%0"
1490   [(set_attr "type"     "jump")
1491    (set_attr "mode"     "none")
1492    (set_attr "length"   "3")])
1493
1494
1495 (define_expand "tablejump"
1496   [(use (match_operand:SI 0 "register_operand" ""))
1497    (use (label_ref (match_operand 1 "" "")))]
1498    ""
1499 {
1500   rtx target = operands[0];
1501   if (flag_pic)
1502     {
1503       /* For PIC, the table entry is relative to the start of the table.  */
1504       rtx label = gen_reg_rtx (SImode);
1505       target = gen_reg_rtx (SImode);
1506       emit_move_insn (label, gen_rtx_LABEL_REF (SImode, operands[1]));
1507       emit_insn (gen_addsi3 (target, operands[0], label));
1508     }
1509   emit_jump_insn (gen_tablejump_internal (target, operands[1]));
1510   DONE;
1511 })
1512
1513 (define_insn "tablejump_internal"
1514   [(set (pc)
1515         (match_operand:SI 0 "register_operand" "r"))
1516    (use (label_ref (match_operand 1 "" "")))]
1517   ""
1518   "jx\t%0"
1519   [(set_attr "type"     "jump")
1520    (set_attr "mode"     "none")
1521    (set_attr "length"   "3")])
1522
1523 \f
1524 ;; Function calls.
1525
1526 (define_expand "sym_PLT"
1527   [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PLT))]
1528   ""
1529   "")
1530
1531 (define_expand "call"
1532   [(call (match_operand 0 "memory_operand" "")
1533          (match_operand 1 "" ""))]
1534   ""
1535 {
1536   rtx addr = XEXP (operands[0], 0);
1537   if (flag_pic && GET_CODE (addr) == SYMBOL_REF
1538       && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
1539     addr = gen_sym_PLT (addr);
1540   if (!call_insn_operand (addr, VOIDmode))
1541     XEXP (operands[0], 0) = copy_to_mode_reg (Pmode, addr);
1542 })
1543
1544 (define_insn "call_internal"
1545   [(call (mem (match_operand:SI 0 "call_insn_operand" "nir"))
1546          (match_operand 1 "" "i"))]
1547   ""
1548 {
1549   return xtensa_emit_call (0, operands);
1550 }
1551   [(set_attr "type"     "call")
1552    (set_attr "mode"     "none")
1553    (set_attr "length"   "3")])
1554
1555 (define_expand "call_value"
1556   [(set (match_operand 0 "register_operand" "")
1557         (call (match_operand 1 "memory_operand" "")
1558               (match_operand 2 "" "")))]
1559   ""
1560 {
1561   rtx addr = XEXP (operands[1], 0);
1562   if (flag_pic && GET_CODE (addr) == SYMBOL_REF
1563       && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
1564     addr = gen_sym_PLT (addr);
1565   if (!call_insn_operand (addr, VOIDmode))
1566     XEXP (operands[1], 0) = copy_to_mode_reg (Pmode, addr);
1567 })
1568
1569 (define_insn "call_value_internal"
1570   [(set (match_operand 0 "register_operand" "=a")
1571         (call (mem (match_operand:SI 1 "call_insn_operand" "nir"))
1572               (match_operand 2 "" "i")))]
1573   ""
1574 {
1575   return xtensa_emit_call (1, operands);
1576 }
1577   [(set_attr "type"     "call")
1578    (set_attr "mode"     "none")
1579    (set_attr "length"   "3")])
1580
1581 (define_insn "entry"
1582   [(set (reg:SI A1_REG)
1583         (unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "i")]
1584                             UNSPECV_ENTRY))]
1585   ""
1586   "entry\tsp, %0"
1587   [(set_attr "type"     "entry")
1588    (set_attr "mode"     "SI")
1589    (set_attr "length"   "3")])
1590
1591 (define_insn "return"
1592   [(return)
1593    (use (reg:SI A0_REG))]
1594   "reload_completed"
1595 {
1596   return (TARGET_DENSITY ? "retw.n" : "retw");
1597 }
1598   [(set_attr "type"     "jump")
1599    (set_attr "mode"     "none")
1600    (set_attr "length"   "2")])
1601
1602 \f
1603 ;; Miscellaneous instructions.
1604
1605 (define_expand "prologue"
1606   [(const_int 0)]
1607   ""
1608 {
1609   xtensa_expand_prologue ();
1610   DONE;
1611 })
1612
1613 (define_expand "epilogue"
1614   [(return)]
1615   ""
1616 {
1617   emit_jump_insn (gen_return ());
1618   DONE;
1619 })
1620
1621 (define_insn "nop"
1622   [(const_int 0)]
1623   ""
1624 {
1625   return (TARGET_DENSITY ? "nop.n" : "nop");
1626 }
1627   [(set_attr "type"     "nop")
1628    (set_attr "mode"     "none")
1629    (set_attr "length"   "3")])
1630
1631 (define_expand "nonlocal_goto"
1632   [(match_operand:SI 0 "general_operand" "")
1633    (match_operand:SI 1 "general_operand" "")
1634    (match_operand:SI 2 "general_operand" "")
1635    (match_operand:SI 3 "" "")]
1636   ""
1637 {
1638   xtensa_expand_nonlocal_goto (operands);
1639   DONE;
1640 })
1641
1642 ;; Stuff an address into the return address register along with the window
1643 ;; size in the high bits.  Because we don't have the window size of the
1644 ;; previous frame, assume the function called out with a CALL8 since that
1645 ;; is what compilers always use.  Note: __builtin_frob_return_addr has
1646 ;; already been applied to the handler, but the generic version doesn't
1647 ;; allow us to frob it quite enough, so we just frob here.
1648
1649 (define_insn_and_split "eh_return"
1650   [(set (reg:SI A0_REG)
1651         (unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")]
1652                             UNSPECV_EH_RETURN))
1653    (clobber (match_scratch:SI 1 "=r"))]
1654   ""
1655   "#"
1656   "reload_completed"
1657   [(set (match_dup 1) (ashift:SI (match_dup 0) (const_int 2)))
1658    (set (match_dup 1) (plus:SI (match_dup 1) (const_int 2)))
1659    (set (reg:SI A0_REG) (rotatert:SI (match_dup 1) (const_int 2)))]
1660   "")
1661
1662 ;; Setting up a frame pointer is tricky for Xtensa because GCC doesn't
1663 ;; know if a frame pointer is required until the reload pass, and
1664 ;; because there may be an incoming argument value in the hard frame
1665 ;; pointer register (a7).  If there is an incoming argument in that
1666 ;; register, the "set_frame_ptr" insn gets inserted immediately after
1667 ;; the insn that copies the incoming argument to a pseudo or to the
1668 ;; stack.  This serves several purposes here: (1) it keeps the
1669 ;; optimizer from copy-propagating or scheduling the use of a7 as an
1670 ;; incoming argument away from the beginning of the function; (2) we
1671 ;; can use a post-reload splitter to expand away the insn if a frame
1672 ;; pointer is not required, so that the post-reload scheduler can do
1673 ;; the right thing; and (3) it makes it easy for the prologue expander
1674 ;; to search for this insn to determine whether it should add a new insn
1675 ;; to set up the frame pointer.
1676
1677 (define_insn "set_frame_ptr"
1678   [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
1679   ""
1680 {
1681   if (frame_pointer_needed)
1682     return "mov\ta7, sp";
1683   return "";
1684 }
1685   [(set_attr "type"     "move")
1686    (set_attr "mode"     "SI")
1687    (set_attr "length"   "3")])
1688
1689 ;; Post-reload splitter to remove fp assignment when it's not needed.
1690 (define_split
1691   [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
1692   "reload_completed && !frame_pointer_needed"
1693   [(unspec [(const_int 0)] UNSPEC_NOP)]
1694   "")
1695
1696 ;; The preceding splitter needs something to split the insn into;
1697 ;; things start breaking if the result is just a "use" so instead we
1698 ;; generate the following insn.
1699 (define_insn "*unspec_nop"
1700   [(unspec [(const_int 0)] UNSPEC_NOP)]
1701   ""
1702   ""
1703   [(set_attr "type"     "nop")
1704    (set_attr "mode"     "none")
1705    (set_attr "length"   "0")])
1706
1707 \f
1708 ;; TLS support
1709
1710 (define_expand "sym_TPOFF"
1711   [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_TPOFF))]
1712   ""
1713   "")
1714
1715 (define_expand "sym_DTPOFF"
1716   [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_DTPOFF))]
1717   ""
1718   "")
1719
1720 (define_insn "load_tp"
1721   [(set (match_operand:SI 0 "register_operand" "=a")
1722         (unspec:SI [(const_int 0)] UNSPEC_TP))]
1723   "TARGET_THREADPTR"
1724   "rur\t%0, THREADPTR"
1725   [(set_attr "type"     "rsr")
1726    (set_attr "mode"     "SI")
1727    (set_attr "length"   "3")])
1728
1729 (define_insn "set_tp"
1730   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
1731                     UNSPECV_SET_TP)]
1732   "TARGET_THREADPTR"
1733   "wur\t%0, THREADPTR"
1734   [(set_attr "type"     "wsr")
1735    (set_attr "mode"     "SI")
1736    (set_attr "length"   "3")])
1737
1738 (define_insn "tls_func"
1739   [(set (match_operand:SI 0 "register_operand" "=a")
1740         (unspec:SI [(match_operand:SI 1 "tls_symbol_operand" "")]
1741                    UNSPEC_TLS_FUNC))]
1742   "TARGET_THREADPTR && HAVE_AS_TLS"
1743   "movi\t%0, %1@TLSFUNC"
1744   [(set_attr "type"     "load")
1745    (set_attr "mode"     "SI")
1746    (set_attr "length"   "3")])
1747
1748 (define_insn "tls_arg"
1749   [(set (match_operand:SI 0 "register_operand" "=a")
1750         (unspec:SI [(match_operand:SI 1 "tls_symbol_operand" "")]
1751                    UNSPEC_TLS_ARG))]
1752   "TARGET_THREADPTR && HAVE_AS_TLS"
1753   "movi\t%0, %1@TLSARG"
1754   [(set_attr "type"     "load")
1755    (set_attr "mode"     "SI")
1756    (set_attr "length"   "3")])
1757
1758 (define_insn "tls_call"
1759   [(set (match_operand:SI 0 "register_operand" "=a")
1760         (call (mem:SI (unspec:SI [(match_operand:SI 1 "register_operand" "r")
1761                                   (match_operand:SI 2 "tls_symbol_operand" "")]
1762                                   UNSPEC_TLS_CALL))
1763               (match_operand 3 "" "i")))]
1764   "TARGET_THREADPTR && HAVE_AS_TLS"
1765   "callx8.tls %1, %2@TLSCALL"
1766   [(set_attr "type"     "call")
1767    (set_attr "mode"     "none")
1768    (set_attr "length"   "3")])
1769
1770 \f
1771 ;; Instructions for the Xtensa "boolean" option.
1772
1773 (define_insn "*booltrue"
1774   [(set (pc)
1775         (if_then_else (match_operator 2 "boolean_operator"
1776                          [(match_operand:CC 0 "register_operand" "b")
1777                           (const_int 0)])
1778                       (label_ref (match_operand 1 "" ""))
1779                       (pc)))]
1780   "TARGET_BOOLEANS"
1781 {
1782   if (GET_CODE (operands[2]) == EQ)
1783     return "bf\t%0, %1";
1784   else
1785     return "bt\t%0, %1";
1786 }
1787   [(set_attr "type"     "jump")
1788    (set_attr "mode"     "none")
1789    (set_attr "length"   "3")])
1790
1791 (define_insn "*boolfalse"
1792   [(set (pc)
1793         (if_then_else (match_operator 2 "boolean_operator"
1794                          [(match_operand:CC 0 "register_operand" "b")
1795                           (const_int 0)])
1796                       (pc)
1797                       (label_ref (match_operand 1 "" ""))))]
1798   "TARGET_BOOLEANS"
1799 {
1800   if (GET_CODE (operands[2]) == EQ)
1801     return "bt\t%0, %1";
1802   else
1803     return "bf\t%0, %1";
1804 }
1805   [(set_attr "type"     "jump")
1806    (set_attr "mode"     "none")
1807    (set_attr "length"   "3")])
1808
1809 \f
1810 ;; Atomic operations
1811
1812 (define_expand "memory_barrier"
1813   [(set (mem:BLK (match_dup 0))
1814         (unspec_volatile:BLK [(mem:BLK (match_dup 0))] UNSPECV_MEMW))]
1815   ""
1816 {
1817   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (SImode));
1818   MEM_VOLATILE_P (operands[0]) = 1;
1819 })
1820
1821 (define_insn "*memory_barrier"
1822   [(set (match_operand:BLK 0 "" "")
1823         (unspec_volatile:BLK [(match_operand:BLK 1 "" "")] UNSPECV_MEMW))]
1824   ""
1825   "memw"
1826   [(set_attr "type"     "unknown")
1827    (set_attr "mode"     "none")
1828    (set_attr "length"   "3")])
1829
1830 ;; sync_lock_release is only implemented for SImode.
1831 ;; For other modes, just use the default of a store with a memory_barrier.
1832 (define_insn "sync_lock_releasesi"
1833   [(set (match_operand:SI 0 "mem_operand" "=U")
1834         (unspec_volatile:SI
1835           [(match_operand:SI 1 "register_operand" "r")]
1836           UNSPECV_S32RI))]
1837   "TARGET_RELEASE_SYNC"
1838   "s32ri\t%1, %0"
1839   [(set_attr "type"     "store")
1840    (set_attr "mode"     "SI")
1841    (set_attr "length"   "3")])
1842
1843 (define_insn "sync_compare_and_swapsi"
1844   [(parallel
1845     [(set (match_operand:SI 0 "register_operand" "=a")
1846           (match_operand:SI 1 "mem_operand" "+U"))
1847      (set (match_dup 1)
1848           (unspec_volatile:SI
1849             [(match_dup 1)
1850              (match_operand:SI 2 "register_operand" "r")
1851              (match_operand:SI 3 "register_operand" "0")]
1852             UNSPECV_S32C1I))])]
1853   "TARGET_S32C1I"
1854   "wsr\t%2, SCOMPARE1\;s32c1i\t%3, %1"
1855   [(set_attr "type"     "multi")
1856    (set_attr "mode"     "SI")
1857    (set_attr "length"   "6")])
1858
1859 (define_expand "sync_compare_and_swap<mode>"
1860   [(parallel
1861     [(set (match_operand:HQI 0 "register_operand" "")
1862           (match_operand:HQI 1 "mem_operand" ""))
1863      (set (match_dup 1)
1864           (unspec_volatile:HQI
1865             [(match_dup 1)
1866              (match_operand:HQI 2 "register_operand" "")
1867              (match_operand:HQI 3 "register_operand" "")]
1868             UNSPECV_S32C1I))])]
1869   "TARGET_S32C1I"
1870 {
1871   xtensa_expand_compare_and_swap (operands[0], operands[1],
1872                                   operands[2], operands[3]);
1873   DONE;
1874 })
1875
1876 (define_expand "sync_lock_test_and_set<mode>"
1877   [(match_operand:HQI 0 "register_operand")
1878    (match_operand:HQI 1 "memory_operand")
1879    (match_operand:HQI 2 "register_operand")]
1880   "TARGET_S32C1I"
1881 {
1882   xtensa_expand_atomic (SET, operands[0], operands[1], operands[2], false);
1883   DONE;
1884 })
1885
1886 (define_expand "sync_<atomic><mode>"
1887   [(set (match_operand:HQI 0 "memory_operand")
1888         (ATOMIC:HQI (match_dup 0)
1889                     (match_operand:HQI 1 "register_operand")))]
1890   "TARGET_S32C1I"
1891 {
1892   xtensa_expand_atomic (<CODE>, NULL_RTX, operands[0], operands[1], false);
1893   DONE;
1894 })
1895
1896 (define_expand "sync_old_<atomic><mode>"
1897   [(set (match_operand:HQI 0 "register_operand")
1898         (match_operand:HQI 1 "memory_operand"))
1899    (set (match_dup 1)
1900         (ATOMIC:HQI (match_dup 1)
1901                     (match_operand:HQI 2 "register_operand")))]
1902   "TARGET_S32C1I"
1903 {
1904   xtensa_expand_atomic (<CODE>, operands[0], operands[1], operands[2], false);
1905   DONE;
1906 })
1907
1908 (define_expand "sync_new_<atomic><mode>"
1909   [(set (match_operand:HQI 0 "register_operand")
1910         (ATOMIC:HQI (match_operand:HQI 1 "memory_operand")
1911                     (match_operand:HQI 2 "register_operand"))) 
1912    (set (match_dup 1) (ATOMIC:HQI (match_dup 1) (match_dup 2)))]
1913   "TARGET_S32C1I"
1914 {
1915   xtensa_expand_atomic (<CODE>, operands[0], operands[1], operands[2], true);
1916   DONE;
1917 })