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)
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
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])
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"))
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")])
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")
96 (define_insn_reservation "xtensa_memory" 2
97 (eq_attr "type" "load,fload")
100 (define_insn_reservation "xtensa_sreg" 2
101 (eq_attr "type" "rsr")
104 (define_insn_reservation "xtensa_mul16" 2
105 (eq_attr "type" "mul16")
108 (define_insn_reservation "xtensa_mul32" 2
109 (eq_attr "type" "mul32")
112 (define_insn_reservation "xtensa_fmadd" 4
113 (eq_attr "type" "fmadd")
116 (define_insn_reservation "xtensa_fconv" 2
117 (eq_attr "type" "fconv")
120 ;; Include predicates and constraints.
122 (include "predicates.md")
123 (include "constraints.md")
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" "")))]
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))
147 else if (!rtx_equal_p (dstlo, src2lo))
151 srclo = gen_reg_rtx (SImode);
152 emit_move_insn (srclo, src1lo);
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));
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"))
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")))]
188 [(set_attr "type" "arith,arith,arith,arith,arith")
189 (set_attr "mode" "SI")
190 (set_attr "length" "2,2,3,3,3")])
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")))]
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")))]
209 [(set_attr "type" "fmadd")
210 (set_attr "mode" "SF")
211 (set_attr "length" "3")])
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" "")))]
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));
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"))))]
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")))]
253 [(set_attr "type" "arith")
254 (set_attr "mode" "SI")
255 (set_attr "length" "3")])
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")))]
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")))]
274 [(set_attr "type" "fmadd")
275 (set_attr "mode" "SF")
276 (set_attr "length" "3")])
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"))))]
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]));
294 (define_insn "<u>mulsi3_highpart"
295 [(set (match_operand:SI 0 "register_operand" "=a")
298 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "%r"))
299 (any_extend:DI (match_operand:SI 2 "register_operand" "r")))
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")))]
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"))
322 (match_operand:HI 2 "register_operand" "r,r"))))]
323 "TARGET_MUL16 || TARGET_MAC16"
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"))
336 (match_operand:HI 2 "register_operand" "r,r"))))]
337 "TARGET_MUL16 || TARGET_MAC16"
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"))
350 (match_operand:HI 2 "register_operand" "r")))
351 (match_operand:SI 3 "register_operand" "0")))]
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"))
364 (match_operand:HI 3 "register_operand" "r")))))]
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")))]
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"
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"
399 [(set_attr "type" "fmadd")
400 (set_attr "mode" "SF")
401 (set_attr "length" "3")])
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")))]
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")))]
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"
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"
442 [(set_attr "type" "fdiv")
443 (set_attr "mode" "SF")
444 (set_attr "length" "3")])
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")))]
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")))]
465 [(set_attr "type" "div32")
466 (set_attr "mode" "SI")
467 (set_attr "length" "3")])
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"
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"
487 [(set_attr "type" "fsqrt")
488 (set_attr "mode" "SF")
489 (set_attr "length" "3")])
494 (define_insn "abssi2"
495 [(set (match_operand:SI 0 "register_operand" "=a")
496 (abs:SI (match_operand:SI 1 "register_operand" "r")))]
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")))]
508 [(set_attr "type" "farith")
509 (set_attr "mode" "SF")
510 (set_attr "length" "3")])
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")))]
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")))]
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" "")))]
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)));
551 (define_expand "ffssi2"
552 [(set (match_operand:SI 0 "register_operand" "")
553 (ffs:SI (match_operand:SI 1 "register_operand" "")))]
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)));
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")))]
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" "")))]
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]));
588 (define_insn "negsf2"
589 [(set (match_operand:SF 0 "register_operand" "=f")
590 (neg:SF (match_operand:SF 1 "register_operand" "f")))]
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")))]
606 extui\t%0, %1, 0, %K2
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")))]
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")))]
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")))]
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")))]
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" "")))]
665 if (sext_operand (operands[1], HImode))
666 emit_insn (gen_extendhisi2_internal (operands[0], operands[1]));
668 xtensa_extend_reg (operands[0], operands[1]);
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")))]
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" "")))]
689 emit_insn (gen_extendqisi2_internal (operands[0], operands[1]));
691 xtensa_extend_reg (operands[0], operands[1]);
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")))]
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" "")))]
714 if (!sext_fldsz_operand (operands[2], SImode))
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))
722 emit_insn (gen_extv_internal (operands[0], operands[1],
723 operands[2], operands[3]));
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")))]
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" "")))]
749 if (!extui_fldsz_operand (operands[2], SImode))
751 emit_insn (gen_extzv_internal (operands[0], operands[1],
752 operands[2], operands[3]));
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")))]
765 shift = (32 - (INTVAL (operands[2]) + INTVAL (operands[3]))) & 0x1f;
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")])
778 (define_insn "fix_truncsfsi2"
779 [(set (match_operand:SI 0 "register_operand" "=a")
780 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
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")))]
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")))]
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")))]
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" ""))]
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)"
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]))
848 tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
849 tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
853 ;; 32-bit Integer moves
855 (define_expand "movsi"
856 [(set (match_operand:SI 0 "nonimmed_operand" "")
857 (match_operand:SI 1 "general_operand" ""))]
860 if (xtensa_emit_move_sequence (operands, SImode))
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)"
878 const16\t%0, %t1\;const16\t%0, %b1
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" ""))]
895 if (xtensa_emit_move_sequence (operands, HImode))
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)"
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" ""))]
923 if (xtensa_emit_move_sequence (operands, QImode))
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)"
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" ""))]
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]))))"
982 const16\t%0, %t1\;const16\t%0, %b1
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")])
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"))))
995 (plus:SI (match_dup 1) (match_dup 2)))]
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"))
1011 (plus:SI (match_dup 0) (match_dup 1)))]
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" ""))]
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)"
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]))
1053 tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
1054 tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
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" ""))])]
1067 if (!xtensa_expand_block_move (operands))
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" "")))]
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")))]
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")))]
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")))]
1114 if (which_alternative == 0)
1116 if ((INTVAL (operands[2]) & 0x1f) < 16)
1117 return "srli\t%0, %1, %R2";
1119 return "extui\t%0, %1, %R2, %L2";
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")))]
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")))]
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")])
1154 ;; Handle comparisons by stashing away the operands and then using that
1155 ;; information in the subsequent conditional branch.
1157 (define_expand "cmpsi"
1159 (compare:CC (match_operand:SI 0 "register_operand" "")
1160 (match_operand:SI 1 "nonmemory_operand" "")))]
1163 branch_cmp[0] = operands[0];
1164 branch_cmp[1] = operands[1];
1165 branch_type = CMP_SI;
1169 (define_expand "cmpsf"
1171 (compare:CC (match_operand:SF 0 "register_operand" "")
1172 (match_operand:SF 1 "register_operand" "")))]
1175 branch_cmp[0] = operands[0];
1176 branch_cmp[1] = operands[1];
1177 branch_type = CMP_SF;
1182 ;; Conditional branches.
1184 (define_expand "b<code>"
1186 (if_then_else (any_cond (cc0) (const_int 0))
1187 (label_ref (match_operand 0 "" ""))
1191 xtensa_expand_conditional_branch (operands, <CODE>);
1195 ;; Branch patterns for standard integer comparisons
1197 (define_insn "*btrue"
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 "" ""))
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"
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")])
1218 (label_ref (match_operand 2 "" ""))))]
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"
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 "" ""))
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"
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")])
1248 (label_ref (match_operand 2 "" ""))))]
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"
1261 (if_then_else (match_operator 3 "boolean_operator"
1263 (match_operand:SI 0 "register_operand" "r,r")
1265 (match_operand:SI 1 "arith_operand" "J,r"))
1267 (label_ref (match_operand 2 "" ""))
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"
1279 (if_then_else (match_operator 3 "boolean_operator"
1281 (match_operand:SI 0 "register_operand" "r,r")
1283 (match_operand:SI 1 "arith_operand" "J,r"))
1286 (label_ref (match_operand 2 "" ""))))]
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"
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"))
1301 (label_ref (match_operand 2 "" ""))
1305 switch (GET_CODE (operands[3]))
1307 case EQ: return "bnone\t%0, %1, %2";
1308 case NE: return "bany\t%0, %1, %2";
1309 default: gcc_unreachable ();
1312 [(set_attr "type" "jump")
1313 (set_attr "mode" "none")
1314 (set_attr "length" "3")])
1316 (define_insn "*maskfalse"
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"))
1323 (label_ref (match_operand 2 "" ""))))]
1326 switch (GET_CODE (operands[3]))
1328 case EQ: return "bany\t%0, %1, %2";
1329 case NE: return "bnone\t%0, %1, %2";
1330 default: gcc_unreachable ();
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"
1345 (if_then_else (eq (match_operand:SI 0 "register_operand" "a")
1347 (label_ref (match_operand 1 "" ""))
1350 (plus:SI (match_dup 0) (const_int -1)))]
1353 [(set_attr "type" "jump")
1354 (set_attr "mode" "none")
1355 (set_attr "length" "3")])
1357 (define_insn "zero_cost_loop_end"
1359 (if_then_else (ne (reg:SI 19) (const_int 0))
1360 (label_ref (match_operand 0 "" ""))
1363 (plus:SI (reg:SI 19) (const_int -1)))]
1366 xtensa_emit_loop_end (insn, operands);
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)
1382 operands[1] = gen_rtx_<CODE> (SImode, branch_cmp[0], branch_cmp[1]);
1383 if (!xtensa_expand_scc (operands))
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" "")))]
1398 if (!xtensa_expand_conditional_move (operands, 0))
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" "")))]
1410 if (!xtensa_expand_conditional_move (operands, 1))
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")
1420 (match_operand:SI 2 "register_operand" "r,0")
1421 (match_operand:SI 3 "register_operand" "0,r")))]
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")
1435 (match_operand:SI 2 "register_operand" "r,0")
1436 (match_operand:SI 3 "register_operand" "0,r")))]
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")
1450 (match_operand:SF 2 "register_operand" "r,0,f,0")
1451 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
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")
1466 (match_operand:SF 2 "register_operand" "r,0,f,0")
1467 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
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")))]
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.
1495 (label_ref (match_operand 0 "" "")))]
1498 [(set_attr "type" "jump")
1499 (set_attr "mode" "none")
1500 (set_attr "length" "3")])
1502 (define_expand "indirect_jump"
1504 (match_operand 0 "register_operand" ""))]
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));
1515 (define_insn "indirect_jump_internal"
1516 [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
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 "" "")))]
1529 rtx target = operands[0];
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));
1538 emit_jump_insn (gen_tablejump_internal (target, operands[1]));
1542 (define_insn "tablejump_internal"
1544 (match_operand:SI 0 "register_operand" "r"))
1545 (use (label_ref (match_operand 1 "" "")))]
1548 [(set_attr "type" "jump")
1549 (set_attr "mode" "none")
1550 (set_attr "length" "3")])
1555 (define_expand "sym_PLT"
1556 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PLT))]
1560 (define_expand "call"
1561 [(call (match_operand 0 "memory_operand" "")
1562 (match_operand 1 "" ""))]
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"))]
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 "" "")))]
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")))]
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")]
1617 [(set_attr "type" "move")
1618 (set_attr "mode" "SI")
1619 (set_attr "length" "3")])
1621 (define_insn "return"
1623 (use (reg:SI A0_REG))]
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"
1639 xtensa_expand_prologue ();
1643 (define_expand "epilogue"
1647 emit_jump_insn (gen_return ());
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 "" "")]
1668 xtensa_expand_nonlocal_goto (operands);
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))]
1691 if (frame_pointer_needed)
1692 return "mov\ta7, sp";
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.
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)]
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)]
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")]
1723 (clobber (match_scratch:SI 2 "=r"))
1724 (clobber (match_scratch:SI 3 "=r"))]
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"
1737 (if_then_else (match_operator 2 "boolean_operator"
1738 [(match_operand:CC 0 "register_operand" "b")
1740 (label_ref (match_operand 1 "" ""))
1744 if (GET_CODE (operands[2]) == EQ)
1745 return "bf\t%0, %1";
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"
1755 (if_then_else (match_operator 2 "boolean_operator"
1756 [(match_operand:CC 0 "register_operand" "b")
1759 (label_ref (match_operand 1 "" ""))))]
1762 if (GET_CODE (operands[2]) == EQ)
1763 return "bt\t%0, %1";
1765 return "bf\t%0, %1";
1767 [(set_attr "type" "jump")
1768 (set_attr "mode" "none")
1769 (set_attr "length" "3")])