2007-01-03 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / config / xtensa / xtensa.md
blob6b48e86e1dced4aa4a36bcb3e7365a325857c601
1 ;; GCC machine description for Tensilica's Xtensa architecture.
2 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Bob Wilson (bwilson@tensilica.com) at Tensilica.
6 ;; This file is part of GCC.
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 2, or (at your option)
11 ;; any later version.
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.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING.  If not, write to the Free
20 ;; Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 ;; 02110-1301, USA.
24 (define_constants [
25   (A0_REG               0)
26   (A1_REG               1)
27   (A7_REG               7)
28   (A8_REG               8)
30   (UNSPEC_NOP           2)
31   (UNSPEC_PLT           3)
32   (UNSPEC_RET_ADDR      4)
33   (UNSPECV_SET_FP       1)
34   (UNSPECV_ENTRY        2)
37 ;; This code macro allows signed and unsigned widening multiplications
38 ;; to use the same template.
39 (define_code_macro any_extend [sign_extend zero_extend])
41 ;; <u> expands to an empty string when doing a signed operation and
42 ;; "u" when doing an unsigned operation.
43 (define_code_attr u [(sign_extend "") (zero_extend "u")])
45 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
46 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
48 ;; This code macro allows four integer min/max operations to be
49 ;; generated from one template.
50 (define_code_macro any_minmax [smin umin smax umax])
52 ;; <minmax> expands to the opcode name for any_minmax operations.
53 (define_code_attr minmax [(smin "min") (umin "minu")
54                           (smax "max") (umax "maxu")])
56 ;; This code macro allows all branch instructions to be generated from
57 ;; a single define_expand template.
58 (define_code_macro any_cond [eq ne gt ge lt le gtu geu ltu leu])
60 ;; This code macro is for setting a register from a comparison.
61 (define_code_macro any_scc [eq ne gt ge lt le])
63 ;; This code macro is for floating-point comparisons.
64 (define_code_macro any_scc_sf [eq lt le])
67 ;; Attributes.
69 (define_attr "type"
70   "unknown,jump,call,load,store,move,arith,multi,nop,farith,fmadd,fdiv,fsqrt,fconv,fload,fstore,mul16,mul32,div32,mac16,rsr,wsr"
71   (const_string "unknown"))
73 (define_attr "mode"
74   "unknown,none,QI,HI,SI,DI,SF,DF,BL"
75   (const_string "unknown"))
77 (define_attr "length" "" (const_int 1))
79 ;; Describe a user's asm statement.
80 (define_asm_attributes
81   [(set_attr "type" "multi")])
84 ;; Pipeline model.
86 ;; The Xtensa basically has simple 5-stage RISC pipeline.
87 ;; Most instructions complete in 1 cycle, and it is OK to assume that
88 ;; everything is fully pipelined.  The exceptions have special insn
89 ;; reservations in the pipeline description below.  The Xtensa can
90 ;; issue one instruction per cycle, so defining CPU units is unnecessary.
92 (define_insn_reservation "xtensa_any_insn" 1
93                          (eq_attr "type" "!load,fload,rsr,mul16,mul32,fmadd,fconv")
94                          "nothing")
96 (define_insn_reservation "xtensa_memory" 2
97                          (eq_attr "type" "load,fload")
98                          "nothing")
100 (define_insn_reservation "xtensa_sreg" 2
101                          (eq_attr "type" "rsr")
102                          "nothing")
104 (define_insn_reservation "xtensa_mul16" 2
105                          (eq_attr "type" "mul16")
106                          "nothing")
108 (define_insn_reservation "xtensa_mul32" 2
109                          (eq_attr "type" "mul32")
110                          "nothing")
112 (define_insn_reservation "xtensa_fmadd" 4
113                          (eq_attr "type" "fmadd")
114                          "nothing")
116 (define_insn_reservation "xtensa_fconv" 2
117                          (eq_attr "type" "fconv")
118                          "nothing")
120 ;; Include predicates and constraints.
122 (include "predicates.md")
123 (include "constraints.md")
126 ;; Addition.
128 (define_expand "adddi3"
129   [(set (match_operand:DI 0 "register_operand" "")
130         (plus:DI (match_operand:DI 1 "register_operand" "")
131                  (match_operand:DI 2 "register_operand" "")))]
132   ""
134   rtx srclo;
135   rtx dstlo = gen_lowpart (SImode, operands[0]);
136   rtx src1lo = gen_lowpart (SImode, operands[1]);
137   rtx src2lo = gen_lowpart (SImode, operands[2]);
139   rtx dsthi = gen_highpart (SImode, operands[0]);
140   rtx src1hi = gen_highpart (SImode, operands[1]);
141   rtx src2hi = gen_highpart (SImode, operands[2]);
143   /* Either source can be used for overflow checking, as long as it's
144      not clobbered by the first addition.  */
145   if (!rtx_equal_p (dstlo, src1lo))
146     srclo = src1lo;
147   else if (!rtx_equal_p (dstlo, src2lo))
148     srclo = src2lo;
149   else
150     {
151       srclo = gen_reg_rtx (SImode);
152       emit_move_insn (srclo, src1lo);
153     }
155   emit_insn (gen_addsi3 (dstlo, src1lo, src2lo));
156   emit_insn (gen_addsi3 (dsthi, src1hi, src2hi));
157   emit_insn (gen_adddi_carry (dsthi, dstlo, srclo));
158   DONE;
161 ;; Represent the add-carry operation as an atomic operation instead of
162 ;; expanding it to a conditional branch.  Otherwise, the edge
163 ;; profiling code breaks because inserting the count increment code
164 ;; causes a new jump insn to be added.
166 (define_insn "adddi_carry"
167   [(set (match_operand:SI 0 "register_operand" "+a")
168         (plus:SI (ltu:SI (match_operand:SI 1 "register_operand" "r")
169                          (match_operand:SI 2 "register_operand" "r"))
170                  (match_dup 0)))]
171   ""
172   "bgeu\t%1, %2, 0f\;addi\t%0, %0, 1\;0:"
173   [(set_attr "type"     "multi")
174    (set_attr "mode"     "SI")
175    (set_attr "length"   "6")])
177 (define_insn "addsi3"
178   [(set (match_operand:SI 0 "register_operand" "=D,D,a,a,a")
179         (plus:SI (match_operand:SI 1 "register_operand" "%d,d,r,r,r")
180                  (match_operand:SI 2 "add_operand" "d,O,r,J,N")))]
181   ""
182   "@
183    add.n\t%0, %1, %2
184    addi.n\t%0, %1, %d2
185    add\t%0, %1, %2
186    addi\t%0, %1, %d2
187    addmi\t%0, %1, %x2"
188   [(set_attr "type"     "arith,arith,arith,arith,arith")
189    (set_attr "mode"     "SI")
190    (set_attr "length"   "2,2,3,3,3")])
192 (define_insn "*addx"
193   [(set (match_operand:SI 0 "register_operand" "=a")
194         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
195                           (match_operand:SI 3 "addsubx_operand" "i"))
196                  (match_operand:SI 2 "register_operand" "r")))]
197   "TARGET_ADDX"
198   "addx%3\t%0, %1, %2"
199   [(set_attr "type"     "arith")
200    (set_attr "mode"     "SI")
201    (set_attr "length"   "3")])
203 (define_insn "addsf3"
204   [(set (match_operand:SF 0 "register_operand" "=f")
205         (plus:SF (match_operand:SF 1 "register_operand" "%f")
206                  (match_operand:SF 2 "register_operand" "f")))]
207   "TARGET_HARD_FLOAT"
208   "add.s\t%0, %1, %2"
209   [(set_attr "type"     "fmadd")
210    (set_attr "mode"     "SF")
211    (set_attr "length"   "3")])
214 ;; Subtraction.
216 (define_expand "subdi3"
217   [(set (match_operand:DI 0 "register_operand" "")
218         (minus:DI (match_operand:DI 1 "register_operand" "")
219                   (match_operand:DI 2 "register_operand" "")))]
220   ""
222   rtx dstlo = gen_lowpart (SImode, operands[0]);
223   rtx src1lo = gen_lowpart (SImode, operands[1]);
224   rtx src2lo = gen_lowpart (SImode, operands[2]);
226   rtx dsthi = gen_highpart (SImode, operands[0]);
227   rtx src1hi = gen_highpart (SImode, operands[1]);
228   rtx src2hi = gen_highpart (SImode, operands[2]);
230   emit_insn (gen_subsi3 (dsthi, src1hi, src2hi));
231   emit_insn (gen_subdi_carry (dsthi, src1lo, src2lo));
232   emit_insn (gen_subsi3 (dstlo, src1lo, src2lo));
233   DONE;
236 (define_insn "subdi_carry"
237   [(set (match_operand:SI 0 "register_operand" "+a")
238         (minus:SI (match_dup 0)
239                   (ltu:SI (match_operand:SI 1 "register_operand" "r")
240                           (match_operand:SI 2 "register_operand" "r"))))]
241   ""
242   "bgeu\t%1, %2, 0f\;addi\t%0, %0, -1\;0:"
243   [(set_attr "type"     "multi")
244    (set_attr "mode"     "SI")
245    (set_attr "length"   "6")])
247 (define_insn "subsi3"
248   [(set (match_operand:SI 0 "register_operand" "=a")
249         (minus:SI (match_operand:SI 1 "register_operand" "r")
250                   (match_operand:SI 2 "register_operand" "r")))]
251   ""
252   "sub\t%0, %1, %2"
253   [(set_attr "type"     "arith")
254    (set_attr "mode"     "SI")
255    (set_attr "length"   "3")])
257 (define_insn "*subx"
258   [(set (match_operand:SI 0 "register_operand" "=a")
259         (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
260                            (match_operand:SI 3 "addsubx_operand" "i"))
261                   (match_operand:SI 2 "register_operand" "r")))]
262   "TARGET_ADDX"
263   "subx%3\t%0, %1, %2"
264   [(set_attr "type"     "arith")
265    (set_attr "mode"     "SI")
266    (set_attr "length"   "3")])
268 (define_insn "subsf3"
269   [(set (match_operand:SF 0 "register_operand" "=f")
270         (minus:SF (match_operand:SF 1 "register_operand" "f")
271                   (match_operand:SF 2 "register_operand" "f")))]
272   "TARGET_HARD_FLOAT"
273   "sub.s\t%0, %1, %2"
274   [(set_attr "type"     "fmadd")
275    (set_attr "mode"     "SF")
276    (set_attr "length"   "3")])
279 ;; Multiplication.
281 (define_expand "<u>mulsidi3"
282   [(set (match_operand:DI 0 "register_operand")
283         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
284                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
285   "TARGET_MUL32_HIGH"
287   emit_insn (gen_mulsi3 (gen_lowpart (SImode, operands[0]),
288                          operands[1], operands[2]));
289   emit_insn (gen_<u>mulsi3_highpart (gen_highpart (SImode, operands[0]),
290                                      operands[1], operands[2]));
291   DONE;
294 (define_insn "<u>mulsi3_highpart"
295   [(set (match_operand:SI 0 "register_operand" "=a")
296         (truncate:SI
297          (lshiftrt:DI
298           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "%r"))
299                    (any_extend:DI (match_operand:SI 2 "register_operand" "r")))
300           (const_int 32))))]
301   "TARGET_MUL32_HIGH"
302   "mul<su>h\t%0, %1, %2"
303   [(set_attr "type"     "mul32")
304    (set_attr "mode"     "SI")
305    (set_attr "length"   "3")])
307 (define_insn "mulsi3"
308   [(set (match_operand:SI 0 "register_operand" "=a")
309         (mult:SI (match_operand:SI 1 "register_operand" "%r")
310                  (match_operand:SI 2 "register_operand" "r")))]
311   "TARGET_MUL32"
312   "mull\t%0, %1, %2"
313   [(set_attr "type"     "mul32")
314    (set_attr "mode"     "SI")
315    (set_attr "length"   "3")])
317 (define_insn "mulhisi3"
318   [(set (match_operand:SI 0 "register_operand" "=C,A")
319         (mult:SI (sign_extend:SI
320                   (match_operand:HI 1 "register_operand" "%r,r"))
321                  (sign_extend:SI
322                   (match_operand:HI 2 "register_operand" "r,r"))))]
323   "TARGET_MUL16 || TARGET_MAC16"
324   "@
325    mul16s\t%0, %1, %2
326    mul.aa.ll\t%1, %2"
327   [(set_attr "type"     "mul16,mac16")
328    (set_attr "mode"     "SI")
329    (set_attr "length"   "3,3")])
331 (define_insn "umulhisi3"
332   [(set (match_operand:SI 0 "register_operand" "=C,A")
333         (mult:SI (zero_extend:SI
334                   (match_operand:HI 1 "register_operand" "%r,r"))
335                  (zero_extend:SI
336                   (match_operand:HI 2 "register_operand" "r,r"))))]
337   "TARGET_MUL16 || TARGET_MAC16"
338   "@
339    mul16u\t%0, %1, %2
340    umul.aa.ll\t%1, %2"
341   [(set_attr "type"     "mul16,mac16")
342    (set_attr "mode"     "SI")
343    (set_attr "length"   "3,3")])
345 (define_insn "muladdhisi"
346   [(set (match_operand:SI 0 "register_operand" "=A")
347         (plus:SI (mult:SI (sign_extend:SI
348                            (match_operand:HI 1 "register_operand" "%r"))
349                           (sign_extend:SI
350                            (match_operand:HI 2 "register_operand" "r")))
351                  (match_operand:SI 3 "register_operand" "0")))]
352   "TARGET_MAC16"
353   "mula.aa.ll\t%1, %2"
354   [(set_attr "type"     "mac16")
355    (set_attr "mode"     "SI")
356    (set_attr "length"   "3")])
358 (define_insn "mulsubhisi"
359   [(set (match_operand:SI 0 "register_operand" "=A")
360         (minus:SI (match_operand:SI 1 "register_operand" "0")
361                   (mult:SI (sign_extend:SI
362                             (match_operand:HI 2 "register_operand" "%r"))
363                            (sign_extend:SI
364                             (match_operand:HI 3 "register_operand" "r")))))]
365   "TARGET_MAC16"
366   "muls.aa.ll\t%2, %3"
367   [(set_attr "type"     "mac16")
368    (set_attr "mode"     "SI")
369    (set_attr "length"   "3")])
371 (define_insn "mulsf3"
372   [(set (match_operand:SF 0 "register_operand" "=f")
373         (mult:SF (match_operand:SF 1 "register_operand" "%f")
374                  (match_operand:SF 2 "register_operand" "f")))]
375   "TARGET_HARD_FLOAT"
376   "mul.s\t%0, %1, %2"
377   [(set_attr "type"     "fmadd")
378    (set_attr "mode"     "SF")
379    (set_attr "length"   "3")])
381 (define_insn "muladdsf3"
382   [(set (match_operand:SF 0 "register_operand" "=f")
383         (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "%f")
384                           (match_operand:SF 2 "register_operand" "f"))
385                  (match_operand:SF 3 "register_operand" "0")))]
386   "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
387   "madd.s\t%0, %1, %2"
388   [(set_attr "type"     "fmadd")
389    (set_attr "mode"     "SF")
390    (set_attr "length"   "3")])
392 (define_insn "mulsubsf3"
393   [(set (match_operand:SF 0 "register_operand" "=f")
394         (minus:SF (match_operand:SF 1 "register_operand" "0")
395                   (mult:SF (match_operand:SF 2 "register_operand" "%f")
396                            (match_operand:SF 3 "register_operand" "f"))))]
397   "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
398   "msub.s\t%0, %2, %3"
399   [(set_attr "type"     "fmadd")
400    (set_attr "mode"     "SF")
401    (set_attr "length"   "3")])
404 ;; Division.
406 (define_insn "divsi3"
407   [(set (match_operand:SI 0 "register_operand" "=a")
408         (div:SI (match_operand:SI 1 "register_operand" "r")
409                 (match_operand:SI 2 "register_operand" "r")))]
410   "TARGET_DIV32"
411   "quos\t%0, %1, %2"
412   [(set_attr "type"     "div32")
413    (set_attr "mode"     "SI")
414    (set_attr "length"   "3")])
416 (define_insn "udivsi3"
417   [(set (match_operand:SI 0 "register_operand" "=a")
418         (udiv:SI (match_operand:SI 1 "register_operand" "r")
419                  (match_operand:SI 2 "register_operand" "r")))]
420   "TARGET_DIV32"
421   "quou\t%0, %1, %2"
422   [(set_attr "type"     "div32")
423    (set_attr "mode"     "SI")
424    (set_attr "length"   "3")])
426 (define_insn "divsf3"
427   [(set (match_operand:SF 0 "register_operand" "=f")
428         (div:SF (match_operand:SF 1 "register_operand" "f")
429                 (match_operand:SF 2 "register_operand" "f")))]
430   "TARGET_HARD_FLOAT_DIV"
431   "div.s\t%0, %1, %2"
432   [(set_attr "type"     "fdiv")
433    (set_attr "mode"     "SF")
434    (set_attr "length"   "3")])
436 (define_insn "*recipsf2"
437   [(set (match_operand:SF 0 "register_operand" "=f")
438         (div:SF (match_operand:SF 1 "const_float_1_operand" "")
439                 (match_operand:SF 2 "register_operand" "f")))]
440   "TARGET_HARD_FLOAT_RECIP && flag_unsafe_math_optimizations"
441   "recip.s\t%0, %2"
442   [(set_attr "type"     "fdiv")
443    (set_attr "mode"     "SF")
444    (set_attr "length"   "3")])
447 ;; Remainders.
449 (define_insn "modsi3"
450   [(set (match_operand:SI 0 "register_operand" "=a")
451         (mod:SI (match_operand:SI 1 "register_operand" "r")
452                 (match_operand:SI 2 "register_operand" "r")))]
453   "TARGET_DIV32"
454   "rems\t%0, %1, %2"
455   [(set_attr "type"     "div32")
456    (set_attr "mode"     "SI")
457    (set_attr "length"   "3")])
459 (define_insn "umodsi3"
460   [(set (match_operand:SI 0 "register_operand" "=a")
461         (umod:SI (match_operand:SI 1 "register_operand" "r")
462                  (match_operand:SI 2 "register_operand" "r")))]
463   "TARGET_DIV32"
464   "remu\t%0, %1, %2"
465   [(set_attr "type"     "div32")
466    (set_attr "mode"     "SI")
467    (set_attr "length"   "3")])
470 ;; Square roots.
472 (define_insn "sqrtsf2"
473   [(set (match_operand:SF 0 "register_operand" "=f")
474         (sqrt:SF (match_operand:SF 1 "register_operand" "f")))]
475   "TARGET_HARD_FLOAT_SQRT"
476   "sqrt.s\t%0, %1"
477   [(set_attr "type"     "fsqrt")
478    (set_attr "mode"     "SF")
479    (set_attr "length"   "3")])
481 (define_insn "*rsqrtsf2"
482   [(set (match_operand:SF 0 "register_operand" "=f")
483         (div:SF (match_operand:SF 1 "const_float_1_operand" "")
484                 (sqrt:SF (match_operand:SF 2 "register_operand" "f"))))]
485   "TARGET_HARD_FLOAT_RSQRT && flag_unsafe_math_optimizations"
486   "rsqrt.s\t%0, %2"
487   [(set_attr "type"     "fsqrt")
488    (set_attr "mode"     "SF")
489    (set_attr "length"   "3")])
492 ;; Absolute value.
494 (define_insn "abssi2"
495   [(set (match_operand:SI 0 "register_operand" "=a")
496         (abs:SI (match_operand:SI 1 "register_operand" "r")))]
497   "TARGET_ABS"
498   "abs\t%0, %1"
499   [(set_attr "type"     "arith")
500    (set_attr "mode"     "SI")
501    (set_attr "length"   "3")])
503 (define_insn "abssf2"
504   [(set (match_operand:SF 0 "register_operand" "=f")
505         (abs:SF (match_operand:SF 1 "register_operand" "f")))]
506   "TARGET_HARD_FLOAT"
507   "abs.s\t%0, %1"
508   [(set_attr "type"     "farith")
509    (set_attr "mode"     "SF")
510    (set_attr "length"   "3")])
513 ;; Min and max.
515 (define_insn "<code>si3"
516   [(set (match_operand:SI 0 "register_operand" "=a")
517         (any_minmax:SI (match_operand:SI 1 "register_operand" "%r")
518                        (match_operand:SI 2 "register_operand" "r")))]
519   "TARGET_MINMAX"
520   "<minmax>\t%0, %1, %2"
521   [(set_attr "type"     "arith")
522    (set_attr "mode"     "SI")
523    (set_attr "length"   "3")])
526 ;; Count leading/trailing zeros and find first bit.
528 (define_insn "clzsi2"
529   [(set (match_operand:SI 0 "register_operand" "=a")
530         (clz:SI (match_operand:SI 1 "register_operand" "r")))]
531   "TARGET_NSA"
532   "nsau\t%0, %1"
533   [(set_attr "type"     "arith")
534    (set_attr "mode"     "SI")
535    (set_attr "length"   "3")])
537 (define_expand "ctzsi2"
538   [(set (match_operand:SI 0 "register_operand" "")
539         (ctz:SI (match_operand:SI 1 "register_operand" "")))]
540   "TARGET_NSA"
542   rtx temp = gen_reg_rtx (SImode);
543   emit_insn (gen_negsi2 (temp, operands[1]));
544   emit_insn (gen_andsi3 (temp, temp, operands[1]));
545   emit_insn (gen_clzsi2 (temp, temp));
546   emit_insn (gen_negsi2 (temp, temp));
547   emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (31)));
548   DONE;
551 (define_expand "ffssi2"
552   [(set (match_operand:SI 0 "register_operand" "")
553         (ffs:SI (match_operand:SI 1 "register_operand" "")))]
554   "TARGET_NSA"
556   rtx temp = gen_reg_rtx (SImode);
557   emit_insn (gen_negsi2 (temp, operands[1]));
558   emit_insn (gen_andsi3 (temp, temp, operands[1]));
559   emit_insn (gen_clzsi2 (temp, temp));
560   emit_insn (gen_negsi2 (temp, temp));
561   emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (32)));
562   DONE;
566 ;; Negation and one's complement.
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")])
577 (define_expand "one_cmplsi2"
578   [(set (match_operand:SI 0 "register_operand" "")
579         (not:SI (match_operand:SI 1 "register_operand" "")))]
580   ""
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;
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")])
598 ;; Logical instructions.
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")])
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")])
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")])
633 ;; Zero-extend instructions.
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")])
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")])
658 ;; Sign-extend instructions.
660 (define_expand "extendhisi2"
661   [(set (match_operand:SI 0 "register_operand" "")
662         (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
663   ""
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;
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")])
683 (define_expand "extendqisi2"
684   [(set (match_operand:SI 0 "register_operand" "")
685         (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
686   ""
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;
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")])
705 ;; Field extract instructions.
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"
714   if (!sext_fldsz_operand (operands[2], SImode))
715     FAIL;
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;
722   emit_insn (gen_extv_internal (operands[0], operands[1],
723                                 operands[2], operands[3]));
724   DONE;
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"
734   int fldsz = INTVAL (operands[2]);
735   operands[2] = GEN_INT (fldsz - 1);
736   return "sext\t%0, %1, %2";
738   [(set_attr "type"     "arith")
739    (set_attr "mode"     "SI")
740    (set_attr "length"   "3")])
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   ""
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;
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   ""
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";
771   [(set_attr "type"     "arith")
772    (set_attr "mode"     "SI")
773    (set_attr "length"   "3")])
776 ;; Conversions.
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")])
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")])
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")])
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")])
815 ;; Data movement instructions.
817 ;; 64-bit Integer moves
819 (define_expand "movdi"
820   [(set (match_operand:DI 0 "nonimmed_operand" "")
821         (match_operand:DI 1 "general_operand" ""))]
822   ""
824   if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
825     operands[1] = force_const_mem (DImode, operands[1]);
827   if (!register_operand (operands[0], DImode)
828       && !register_operand (operands[1], DImode))
829     operands[1] = force_reg (DImode, operands[1]);
831   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
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))]
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     }
853 ;; 32-bit Integer moves
855 (define_expand "movsi"
856   [(set (match_operand:SI 0 "nonimmed_operand" "")
857         (match_operand:SI 1 "general_operand" ""))]
858   ""
860   if (xtensa_emit_move_sequence (operands, SImode))
861     DONE;
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, ACCLO
883    wsr\t%1, 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")])
888 ;; 16-bit Integer moves
890 (define_expand "movhi"
891   [(set (match_operand:HI 0 "nonimmed_operand" "")
892         (match_operand:HI 1 "general_operand" ""))]
893   ""
895   if (xtensa_emit_move_sequence (operands, HImode))
896     DONE;
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, ACCLO
911    wsr\t%1, 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")])
916 ;; 8-bit Integer moves
918 (define_expand "movqi"
919   [(set (match_operand:QI 0 "nonimmed_operand" "")
920         (match_operand:QI 1 "general_operand" ""))]
921   ""
923   if (xtensa_emit_move_sequence (operands, QImode))
924     DONE;
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, ACCLO
939    wsr\t%1, 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")])
944 ;; 32-bit floating point moves
946 (define_expand "movsf"
947   [(set (match_operand:SF 0 "nonimmed_operand" "")
948         (match_operand:SF 1 "general_operand" ""))]
949   ""
951   if (!TARGET_CONST16 && CONSTANT_P (operands[1]))
952     operands[1] = force_const_mem (SFmode, operands[1]);
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]);
962   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
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")])
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"
998   if (volatile_refs_p (PATTERN (insn)))
999     output_asm_insn ("memw", operands);
1000   return "lsiu\t%0, %1, %2";
1002   [(set_attr "type"     "fload")
1003    (set_attr "mode"     "SF")
1004    (set_attr "length"   "3")])
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"
1014   if (volatile_refs_p (PATTERN (insn)))
1015     output_asm_insn ("memw", operands);
1016   return "ssiu\t%2, %0, %1";
1018   [(set_attr "type"     "fstore")
1019    (set_attr "mode"     "SF")
1020    (set_attr "length"   "3")])
1022 ;; 64-bit floating point moves
1024 (define_expand "movdf"
1025   [(set (match_operand:DF 0 "nonimmed_operand" "")
1026         (match_operand:DF 1 "general_operand" ""))]
1027   ""
1029   if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
1030     operands[1] = force_const_mem (DFmode, operands[1]);
1032   if (!register_operand (operands[0], DFmode)
1033       && !register_operand (operands[1], DFmode))
1034     operands[1] = force_reg (DFmode, operands[1]);
1036   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
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))]
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     }
1058 ;; Block moves
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   ""
1067   if (!xtensa_expand_block_move (operands))
1068     FAIL;
1069   DONE;
1073 ;; Shift instructions.
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   ""
1081   operands[1] = xtensa_copy_incoming_a7 (operands[1]);
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")])
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")])
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   ""
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";
1123   [(set_attr "type"     "arith,arith")
1124    (set_attr "mode"     "SI")
1125    (set_attr "length"   "3,6")])
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")])
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")])
1152 ;; Comparisons.
1154 ;; Handle comparisons by stashing away the operands and then using that
1155 ;; information in the subsequent conditional branch.
1157 (define_expand "cmpsi"
1158   [(set (cc0)
1159         (compare:CC (match_operand:SI 0 "register_operand" "")
1160                     (match_operand:SI 1 "nonmemory_operand" "")))]
1161   ""
1163   branch_cmp[0] = operands[0];
1164   branch_cmp[1] = operands[1];
1165   branch_type = CMP_SI;
1166   DONE;
1169 (define_expand "cmpsf"
1170   [(set (cc0)
1171         (compare:CC (match_operand:SF 0 "register_operand" "")
1172                     (match_operand:SF 1 "register_operand" "")))]
1173   "TARGET_HARD_FLOAT"
1175   branch_cmp[0] = operands[0];
1176   branch_cmp[1] = operands[1];
1177   branch_type = CMP_SF;
1178   DONE;
1182 ;; Conditional branches.
1184 (define_expand "b<code>"
1185   [(set (pc)
1186         (if_then_else (any_cond (cc0) (const_int 0))
1187                       (label_ref (match_operand 0 "" ""))
1188                       (pc)))]
1189   ""
1191   xtensa_expand_conditional_branch (operands, <CODE>);
1192   DONE;
1195 ;; Branch patterns for standard integer comparisons
1197 (define_insn "*btrue"
1198   [(set (pc)
1199         (if_then_else (match_operator 3 "branch_operator"
1200                        [(match_operand:SI 0 "register_operand" "r,r")
1201                         (match_operand:SI 1 "branch_operand" "K,r")])
1202                       (label_ref (match_operand 2 "" ""))
1203                       (pc)))]
1204   ""
1206   return xtensa_emit_branch (false, which_alternative == 0, operands);
1208   [(set_attr "type"     "jump,jump")
1209    (set_attr "mode"     "none")
1210    (set_attr "length"   "3,3")])
1212 (define_insn "*bfalse"
1213   [(set (pc)
1214         (if_then_else (match_operator 3 "branch_operator"
1215                        [(match_operand:SI 0 "register_operand" "r,r")
1216                         (match_operand:SI 1 "branch_operand" "K,r")])
1217                       (pc)
1218                       (label_ref (match_operand 2 "" ""))))]
1219   ""
1221   return xtensa_emit_branch (true, which_alternative == 0, operands);
1223   [(set_attr "type"     "jump,jump")
1224    (set_attr "mode"     "none")
1225    (set_attr "length"   "3,3")])
1227 (define_insn "*ubtrue"
1228   [(set (pc)
1229         (if_then_else (match_operator 3 "ubranch_operator"
1230                        [(match_operand:SI 0 "register_operand" "r,r")
1231                         (match_operand:SI 1 "ubranch_operand" "L,r")])
1232                       (label_ref (match_operand 2 "" ""))
1233                       (pc)))]
1234   ""
1236   return xtensa_emit_branch (false, which_alternative == 0, operands);
1238   [(set_attr "type"     "jump,jump")
1239    (set_attr "mode"     "none")
1240    (set_attr "length"   "3,3")])
1242 (define_insn "*ubfalse"
1243   [(set (pc)
1244         (if_then_else (match_operator 3 "ubranch_operator"
1245                          [(match_operand:SI 0 "register_operand" "r,r")
1246                           (match_operand:SI 1 "ubranch_operand" "L,r")])
1247                       (pc)
1248                       (label_ref (match_operand 2 "" ""))))]
1249   ""
1251   return xtensa_emit_branch (true, which_alternative == 0, operands);
1253   [(set_attr "type"     "jump,jump")
1254    (set_attr "mode"     "none")
1255    (set_attr "length"   "3,3")])
1257 ;; Branch patterns for bit testing
1259 (define_insn "*bittrue"
1260   [(set (pc)
1261         (if_then_else (match_operator 3 "boolean_operator"
1262                         [(zero_extract:SI
1263                             (match_operand:SI 0 "register_operand" "r,r")
1264                             (const_int 1)
1265                             (match_operand:SI 1 "arith_operand" "J,r"))
1266                          (const_int 0)])
1267                       (label_ref (match_operand 2 "" ""))
1268                       (pc)))]
1269   ""
1271   return xtensa_emit_bit_branch (false, which_alternative == 0, operands);
1273   [(set_attr "type"     "jump")
1274    (set_attr "mode"     "none")
1275    (set_attr "length"   "3")])
1277 (define_insn "*bitfalse"
1278   [(set (pc)
1279         (if_then_else (match_operator 3 "boolean_operator"
1280                         [(zero_extract:SI
1281                             (match_operand:SI 0 "register_operand" "r,r")
1282                             (const_int 1)
1283                             (match_operand:SI 1 "arith_operand" "J,r"))
1284                          (const_int 0)])
1285                       (pc)
1286                       (label_ref (match_operand 2 "" ""))))]
1287   ""
1289   return xtensa_emit_bit_branch (true, which_alternative == 0, operands);
1291   [(set_attr "type"     "jump")
1292    (set_attr "mode"     "none")
1293    (set_attr "length"   "3")])
1295 (define_insn "*masktrue"
1296   [(set (pc)
1297         (if_then_else (match_operator 3 "boolean_operator"
1298                  [(and:SI (match_operand:SI 0 "register_operand" "r")
1299                           (match_operand:SI 1 "register_operand" "r"))
1300                   (const_int 0)])
1301                       (label_ref (match_operand 2 "" ""))
1302                       (pc)))]
1303   ""
1305   switch (GET_CODE (operands[3]))
1306     {
1307     case EQ:            return "bnone\t%0, %1, %2";
1308     case NE:            return "bany\t%0, %1, %2";
1309     default:            gcc_unreachable ();
1310     }
1312   [(set_attr "type"     "jump")
1313    (set_attr "mode"     "none")
1314    (set_attr "length"   "3")])
1316 (define_insn "*maskfalse"
1317   [(set (pc)
1318         (if_then_else (match_operator 3 "boolean_operator"
1319                  [(and:SI (match_operand:SI 0 "register_operand" "r")
1320                           (match_operand:SI 1 "register_operand" "r"))
1321                   (const_int 0)])
1322                       (pc)
1323                       (label_ref (match_operand 2 "" ""))))]
1324   ""
1326   switch (GET_CODE (operands[3]))
1327     {
1328     case EQ:            return "bany\t%0, %1, %2";
1329     case NE:            return "bnone\t%0, %1, %2";
1330     default:            gcc_unreachable ();
1331     }
1333   [(set_attr "type"     "jump")
1334    (set_attr "mode"     "none")
1335    (set_attr "length"   "3")])
1338 ;; Define the loop insns used by bct optimization to represent the
1339 ;; start and end of a zero-overhead loop (in loop.c).  This start
1340 ;; template generates the loop insn; the end template doesn't generate
1341 ;; any instructions since loop end is handled in hardware.
1343 (define_insn "zero_cost_loop_start"
1344   [(set (pc)
1345         (if_then_else (eq (match_operand:SI 0 "register_operand" "a")
1346                           (const_int 0))
1347                       (label_ref (match_operand 1 "" ""))
1348                       (pc)))
1349    (set (reg:SI 19)
1350         (plus:SI (match_dup 0) (const_int -1)))]
1351   ""
1352   "loopnez\t%0, %l1"
1353   [(set_attr "type"     "jump")
1354    (set_attr "mode"     "none")
1355    (set_attr "length"   "3")])
1357 (define_insn "zero_cost_loop_end"
1358   [(set (pc)
1359         (if_then_else (ne (reg:SI 19) (const_int 0))
1360                       (label_ref (match_operand 0 "" ""))
1361                       (pc)))
1362    (set (reg:SI 19)
1363         (plus:SI (reg:SI 19) (const_int -1)))]
1364   ""
1366     xtensa_emit_loop_end (insn, operands);
1367     return "";
1369   [(set_attr "type"     "jump")
1370    (set_attr "mode"     "none")
1371    (set_attr "length"   "0")])
1374 ;; Setting a register from a comparison.
1376 (define_expand "s<code>"
1377   [(set (match_operand:SI 0 "register_operand" "")
1378         (any_scc:SI (match_dup 1)
1379                     (match_dup 2)))]
1380   ""
1382   operands[1] = gen_rtx_<CODE> (SImode, branch_cmp[0], branch_cmp[1]);
1383   if (!xtensa_expand_scc (operands))
1384     FAIL;
1385   DONE;
1389 ;; Conditional moves.
1391 (define_expand "movsicc"
1392   [(set (match_operand:SI 0 "register_operand" "")
1393         (if_then_else:SI (match_operand 1 "comparison_operator" "")
1394                          (match_operand:SI 2 "register_operand" "")
1395                          (match_operand:SI 3 "register_operand" "")))]
1396   ""
1398   if (!xtensa_expand_conditional_move (operands, 0))
1399     FAIL;
1400   DONE;
1403 (define_expand "movsfcc"
1404   [(set (match_operand:SF 0 "register_operand" "")
1405         (if_then_else:SF (match_operand 1 "comparison_operator" "")
1406                          (match_operand:SF 2 "register_operand" "")
1407                          (match_operand:SF 3 "register_operand" "")))]
1408   ""
1410   if (!xtensa_expand_conditional_move (operands, 1))
1411     FAIL;
1412   DONE;
1415 (define_insn "movsicc_internal0"
1416   [(set (match_operand:SI 0 "register_operand" "=a,a")
1417         (if_then_else:SI (match_operator 4 "branch_operator"
1418                            [(match_operand:SI 1 "register_operand" "r,r")
1419                             (const_int 0)])
1420                          (match_operand:SI 2 "register_operand" "r,0")
1421                          (match_operand:SI 3 "register_operand" "0,r")))]
1422   ""
1424   return xtensa_emit_movcc (which_alternative == 1, false, false, operands);
1426   [(set_attr "type"     "move,move")
1427    (set_attr "mode"     "SI")
1428    (set_attr "length"   "3,3")])
1430 (define_insn "movsicc_internal1"
1431   [(set (match_operand:SI 0 "register_operand" "=a,a")
1432         (if_then_else:SI (match_operator 4 "boolean_operator"
1433                            [(match_operand:CC 1 "register_operand" "b,b")
1434                             (const_int 0)])
1435                          (match_operand:SI 2 "register_operand" "r,0")
1436                          (match_operand:SI 3 "register_operand" "0,r")))]
1437   "TARGET_BOOLEANS"
1439   return xtensa_emit_movcc (which_alternative == 1, false, true, operands);
1441   [(set_attr "type"     "move,move")
1442    (set_attr "mode"     "SI")
1443    (set_attr "length"   "3,3")])
1445 (define_insn "movsfcc_internal0"
1446   [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1447         (if_then_else:SF (match_operator 4 "branch_operator"
1448                            [(match_operand:SI 1 "register_operand" "r,r,r,r")
1449                             (const_int 0)])
1450                          (match_operand:SF 2 "register_operand" "r,0,f,0")
1451                          (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1452   ""
1454   return xtensa_emit_movcc ((which_alternative & 1) == 1,
1455                             which_alternative >= 2, false, operands);
1457   [(set_attr "type"     "move,move,move,move")
1458    (set_attr "mode"     "SF")
1459    (set_attr "length"   "3,3,3,3")])
1461 (define_insn "movsfcc_internal1"
1462   [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1463         (if_then_else:SF (match_operator 4 "boolean_operator"
1464                            [(match_operand:CC 1 "register_operand" "b,b,b,b")
1465                             (const_int 0)])
1466                          (match_operand:SF 2 "register_operand" "r,0,f,0")
1467                          (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1468   "TARGET_BOOLEANS"
1470   return xtensa_emit_movcc ((which_alternative & 1) == 1,
1471                             which_alternative >= 2, true, operands);
1473   [(set_attr "type"     "move,move,move,move")
1474    (set_attr "mode"     "SF")
1475    (set_attr "length"   "3,3,3,3")])
1478 ;; Floating-point comparisons.
1480 (define_insn "s<code>_sf"
1481   [(set (match_operand:CC 0 "register_operand" "=b")
1482         (any_scc_sf:CC (match_operand:SF 1 "register_operand" "f")
1483                        (match_operand:SF 2 "register_operand" "f")))]
1484   "TARGET_HARD_FLOAT"
1485   "o<code>.s\t%0, %1, %2"
1486   [(set_attr "type"     "farith")
1487    (set_attr "mode"     "BL")
1488    (set_attr "length"   "3")])
1491 ;; Unconditional branches.
1493 (define_insn "jump"
1494   [(set (pc)
1495         (label_ref (match_operand 0 "" "")))]
1496   ""
1497   "j\t%l0"
1498   [(set_attr "type"     "jump")
1499    (set_attr "mode"     "none")
1500    (set_attr "length"   "3")])
1502 (define_expand "indirect_jump"
1503   [(set (pc)
1504         (match_operand 0 "register_operand" ""))]
1505   ""
1507   rtx dest = operands[0];
1508   if (GET_CODE (dest) != REG || GET_MODE (dest) != Pmode)
1509     operands[0] = copy_to_mode_reg (Pmode, dest);
1511   emit_jump_insn (gen_indirect_jump_internal (dest));
1512   DONE;
1515 (define_insn "indirect_jump_internal"
1516   [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
1517   ""
1518   "jx\t%0"
1519   [(set_attr "type"     "jump")
1520    (set_attr "mode"     "none")
1521    (set_attr "length"   "3")])
1524 (define_expand "tablejump"
1525   [(use (match_operand:SI 0 "register_operand" ""))
1526    (use (label_ref (match_operand 1 "" "")))]
1527    ""
1529   rtx target = operands[0];
1530   if (flag_pic)
1531     {
1532       /* For PIC, the table entry is relative to the start of the table.  */
1533       rtx label = gen_reg_rtx (SImode);
1534       target = gen_reg_rtx (SImode);
1535       emit_move_insn (label, gen_rtx_LABEL_REF (SImode, operands[1]));
1536       emit_insn (gen_addsi3 (target, operands[0], label));
1537     }
1538   emit_jump_insn (gen_tablejump_internal (target, operands[1]));
1539   DONE;
1542 (define_insn "tablejump_internal"
1543   [(set (pc)
1544         (match_operand:SI 0 "register_operand" "r"))
1545    (use (label_ref (match_operand 1 "" "")))]
1546   ""
1547   "jx\t%0"
1548   [(set_attr "type"     "jump")
1549    (set_attr "mode"     "none")
1550    (set_attr "length"   "3")])
1553 ;; Function calls.
1555 (define_expand "sym_PLT"
1556   [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PLT))]
1557   ""
1558   "")
1560 (define_expand "call"
1561   [(call (match_operand 0 "memory_operand" "")
1562          (match_operand 1 "" ""))]
1563   ""
1565   rtx addr = XEXP (operands[0], 0);
1566   if (flag_pic && GET_CODE (addr) == SYMBOL_REF
1567       && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
1568     addr = gen_sym_PLT (addr);
1569   if (!call_insn_operand (addr, VOIDmode))
1570     XEXP (operands[0], 0) = copy_to_mode_reg (Pmode, addr);
1573 (define_insn "call_internal"
1574   [(call (mem (match_operand:SI 0 "call_insn_operand" "nir"))
1575          (match_operand 1 "" "i"))]
1576   ""
1578   return xtensa_emit_call (0, operands);
1580   [(set_attr "type"     "call")
1581    (set_attr "mode"     "none")
1582    (set_attr "length"   "3")])
1584 (define_expand "call_value"
1585   [(set (match_operand 0 "register_operand" "")
1586         (call (match_operand 1 "memory_operand" "")
1587               (match_operand 2 "" "")))]
1588   ""
1590   rtx addr = XEXP (operands[1], 0);
1591   if (flag_pic && GET_CODE (addr) == SYMBOL_REF
1592       && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
1593     addr = gen_sym_PLT (addr);
1594   if (!call_insn_operand (addr, VOIDmode))
1595     XEXP (operands[1], 0) = copy_to_mode_reg (Pmode, addr);
1598 (define_insn "call_value_internal"
1599    [(set (match_operand 0 "register_operand" "=a")
1600          (call (mem (match_operand:SI 1 "call_insn_operand" "nir"))
1601                (match_operand 2 "" "i")))]
1602   ""
1604   return xtensa_emit_call (1, operands);
1606   [(set_attr "type"     "call")
1607    (set_attr "mode"     "none")
1608    (set_attr "length"   "3")])
1610 (define_insn "entry"
1611   [(set (reg:SI A1_REG)
1612         (unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "i")
1613                              (match_operand:SI 1 "const_int_operand" "i")]
1614                             UNSPECV_ENTRY))]
1615   ""
1616   "entry\tsp, %1"
1617   [(set_attr "type"     "move")
1618    (set_attr "mode"     "SI")
1619    (set_attr "length"   "3")])
1621 (define_insn "return"
1622   [(return)
1623    (use (reg:SI A0_REG))]
1624   "reload_completed"
1626   return (TARGET_DENSITY ? "retw.n" : "retw");
1628   [(set_attr "type"     "jump")
1629    (set_attr "mode"     "none")
1630    (set_attr "length"   "2")])
1633 ;; Miscellaneous instructions.
1635 (define_expand "prologue"
1636   [(const_int 0)]
1637   ""
1639   xtensa_expand_prologue ();
1640   DONE;
1643 (define_expand "epilogue"
1644   [(return)]
1645   ""
1647   emit_jump_insn (gen_return ());
1648   DONE;
1651 (define_insn "nop"
1652   [(const_int 0)]
1653   ""
1655   return (TARGET_DENSITY ? "nop.n" : "nop");
1657   [(set_attr "type"     "nop")
1658    (set_attr "mode"     "none")
1659    (set_attr "length"   "3")])
1661 (define_expand "nonlocal_goto"
1662   [(match_operand:SI 0 "general_operand" "")
1663    (match_operand:SI 1 "general_operand" "")
1664    (match_operand:SI 2 "general_operand" "")
1665    (match_operand:SI 3 "" "")]
1666   ""
1668   xtensa_expand_nonlocal_goto (operands);
1669   DONE;
1672 ;; Setting up a frame pointer is tricky for Xtensa because GCC doesn't
1673 ;; know if a frame pointer is required until the reload pass, and
1674 ;; because there may be an incoming argument value in the hard frame
1675 ;; pointer register (a7).  If there is an incoming argument in that
1676 ;; register, the "set_frame_ptr" insn gets inserted immediately after
1677 ;; the insn that copies the incoming argument to a pseudo or to the
1678 ;; stack.  This serves several purposes here: (1) it keeps the
1679 ;; optimizer from copy-propagating or scheduling the use of a7 as an
1680 ;; incoming argument away from the beginning of the function; (2) we
1681 ;; can use a post-reload splitter to expand away the insn if a frame
1682 ;; pointer is not required, so that the post-reload scheduler can do
1683 ;; the right thing; and (3) it makes it easy for the prologue expander
1684 ;; to search for this insn to determine whether it should add a new insn
1685 ;; to set up the frame pointer.
1687 (define_insn "set_frame_ptr"
1688   [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
1689   ""
1691   if (frame_pointer_needed)
1692     return "mov\ta7, sp";
1693   return "";
1695   [(set_attr "type"     "move")
1696    (set_attr "mode"     "SI")
1697    (set_attr "length"   "3")])
1699 ;; Post-reload splitter to remove fp assignment when it's not needed.
1700 (define_split
1701   [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
1702   "reload_completed && !frame_pointer_needed"
1703   [(unspec [(const_int 0)] UNSPEC_NOP)]
1704   "")
1706 ;; The preceding splitter needs something to split the insn into;
1707 ;; things start breaking if the result is just a "use" so instead we
1708 ;; generate the following insn.
1709 (define_insn "*unspec_nop"
1710   [(unspec [(const_int 0)] UNSPEC_NOP)]
1711   ""
1712   ""
1713   [(set_attr "type"     "nop")
1714    (set_attr "mode"     "none")
1715    (set_attr "length"   "0")])
1717 ;; The fix_return_addr pattern sets the high 2 bits of an address in a
1718 ;; register to match the high bits of the current PC.
1719 (define_insn "fix_return_addr"
1720   [(set (match_operand:SI 0 "register_operand" "=a")
1721         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
1722                    UNSPEC_RET_ADDR))
1723    (clobber (match_scratch:SI 2 "=r"))
1724    (clobber (match_scratch:SI 3 "=r"))]
1725   ""
1726   "mov\t%2, a0\;call0\t0f\;.align\t4\;0:\;mov\t%3, a0\;mov\ta0, %2\;\
1727 srli\t%3, %3, 30\;slli\t%0, %1, 2\;ssai\t2\;src\t%0, %3, %0"
1728   [(set_attr "type"     "multi")
1729    (set_attr "mode"     "SI")
1730    (set_attr "length"   "24")])
1733 ;; Instructions for the Xtensa "boolean" option.
1735 (define_insn "*booltrue"
1736   [(set (pc)
1737         (if_then_else (match_operator 2 "boolean_operator"
1738                          [(match_operand:CC 0 "register_operand" "b")
1739                           (const_int 0)])
1740                       (label_ref (match_operand 1 "" ""))
1741                       (pc)))]
1742   "TARGET_BOOLEANS"
1744   if (GET_CODE (operands[2]) == EQ)
1745     return "bf\t%0, %1";
1746   else
1747     return "bt\t%0, %1";
1749   [(set_attr "type"     "jump")
1750    (set_attr "mode"     "none")
1751    (set_attr "length"   "3")])
1753 (define_insn "*boolfalse"
1754   [(set (pc)
1755         (if_then_else (match_operator 2 "boolean_operator"
1756                          [(match_operand:CC 0 "register_operand" "b")
1757                           (const_int 0)])
1758                       (pc)
1759                       (label_ref (match_operand 1 "" ""))))]
1760   "TARGET_BOOLEANS"
1762   if (GET_CODE (operands[2]) == EQ)
1763     return "bt\t%0, %1";
1764   else
1765     return "bf\t%0, %1";
1767   [(set_attr "type"     "jump")
1768    (set_attr "mode"     "none")
1769    (set_attr "length"   "3")])