1 ;; GCC machine description for Tensilica's Xtensa architecture.
2 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Bob Wilson (bwilson@tensilica.com) at Tensilica.
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 3, 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 COPYING3. If not see
20 ;; <http://www.gnu.org/licenses/>.
41 ;; This code iterator allows signed and unsigned widening multiplications
42 ;; to use the same template.
43 (define_code_iterator any_extend [sign_extend zero_extend])
45 ;; <u> expands to an empty string when doing a signed operation and
46 ;; "u" when doing an unsigned operation.
47 (define_code_attr u [(sign_extend "") (zero_extend "u")])
49 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
50 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
52 ;; This code iterator allows four integer min/max operations to be
53 ;; generated from one template.
54 (define_code_iterator any_minmax [smin umin smax umax])
56 ;; <minmax> expands to the opcode name for any_minmax operations.
57 (define_code_attr minmax [(smin "min") (umin "minu")
58 (smax "max") (umax "maxu")])
60 ;; This code iterator allows all branch instructions to be generated from
61 ;; a single define_expand template.
62 (define_code_iterator any_cond [eq ne gt ge lt le gtu geu ltu leu
63 uneq ltgt ungt unge unlt unle
66 ;; This code iterator is for setting a register from a comparison.
67 (define_code_iterator any_scc [eq ne gt ge lt le])
69 ;; This code iterator is for floating-point comparisons.
70 (define_code_iterator any_scc_sf [eq lt le uneq unlt unle unordered])
71 (define_code_attr scc_sf [(eq "oeq") (lt "olt") (le "ole")
72 (uneq "ueq") (unlt "ult") (unle "ule")
75 ;; This iterator and attribute allow to combine most atomic operations.
76 (define_code_iterator ATOMIC [and ior xor plus minus mult])
77 (define_code_attr atomic [(and "and") (ior "ior") (xor "xor")
78 (plus "add") (minus "sub") (mult "nand")])
80 ;; This mode iterator allows the HI and QI patterns to be defined from
82 (define_mode_iterator HQI [HI QI])
88 "unknown,jump,call,load,store,move,arith,multi,nop,farith,fmadd,fdiv,fsqrt,fconv,fload,fstore,mul16,mul32,div32,mac16,rsr,wsr,entry"
89 (const_string "unknown"))
92 "unknown,none,QI,HI,SI,DI,SF,DF,BL"
93 (const_string "unknown"))
95 (define_attr "length" "" (const_int 1))
97 ;; Describe a user's asm statement.
98 (define_asm_attributes
99 [(set_attr "type" "multi")])
104 ;; The Xtensa basically has simple 5-stage RISC pipeline.
105 ;; Most instructions complete in 1 cycle, and it is OK to assume that
106 ;; everything is fully pipelined. The exceptions have special insn
107 ;; reservations in the pipeline description below. The Xtensa can
108 ;; issue one instruction per cycle, so defining CPU units is unnecessary.
110 (define_insn_reservation "xtensa_any_insn" 1
111 (eq_attr "type" "!load,fload,rsr,mul16,mul32,fmadd,fconv")
114 (define_insn_reservation "xtensa_memory" 2
115 (eq_attr "type" "load,fload")
118 (define_insn_reservation "xtensa_sreg" 2
119 (eq_attr "type" "rsr")
122 (define_insn_reservation "xtensa_mul16" 2
123 (eq_attr "type" "mul16")
126 (define_insn_reservation "xtensa_mul32" 2
127 (eq_attr "type" "mul32")
130 (define_insn_reservation "xtensa_fmadd" 4
131 (eq_attr "type" "fmadd")
134 (define_insn_reservation "xtensa_fconv" 2
135 (eq_attr "type" "fconv")
138 ;; Include predicates and constraints.
140 (include "predicates.md")
141 (include "constraints.md")
146 (define_insn "addsi3"
147 [(set (match_operand:SI 0 "register_operand" "=D,D,a,a,a")
148 (plus:SI (match_operand:SI 1 "register_operand" "%d,d,r,r,r")
149 (match_operand:SI 2 "add_operand" "d,O,r,J,N")))]
157 [(set_attr "type" "arith,arith,arith,arith,arith")
158 (set_attr "mode" "SI")
159 (set_attr "length" "2,2,3,3,3")])
162 [(set (match_operand:SI 0 "register_operand" "=a")
163 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
164 (match_operand:SI 3 "addsubx_operand" "i"))
165 (match_operand:SI 2 "register_operand" "r")))]
168 [(set_attr "type" "arith")
169 (set_attr "mode" "SI")
170 (set_attr "length" "3")])
172 (define_insn "addsf3"
173 [(set (match_operand:SF 0 "register_operand" "=f")
174 (plus:SF (match_operand:SF 1 "register_operand" "%f")
175 (match_operand:SF 2 "register_operand" "f")))]
178 [(set_attr "type" "fmadd")
179 (set_attr "mode" "SF")
180 (set_attr "length" "3")])
185 (define_insn "subsi3"
186 [(set (match_operand:SI 0 "register_operand" "=a")
187 (minus:SI (match_operand:SI 1 "register_operand" "r")
188 (match_operand:SI 2 "register_operand" "r")))]
191 [(set_attr "type" "arith")
192 (set_attr "mode" "SI")
193 (set_attr "length" "3")])
196 [(set (match_operand:SI 0 "register_operand" "=a")
197 (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
198 (match_operand:SI 3 "addsubx_operand" "i"))
199 (match_operand:SI 2 "register_operand" "r")))]
202 [(set_attr "type" "arith")
203 (set_attr "mode" "SI")
204 (set_attr "length" "3")])
206 (define_insn "subsf3"
207 [(set (match_operand:SF 0 "register_operand" "=f")
208 (minus:SF (match_operand:SF 1 "register_operand" "f")
209 (match_operand:SF 2 "register_operand" "f")))]
212 [(set_attr "type" "fmadd")
213 (set_attr "mode" "SF")
214 (set_attr "length" "3")])
219 (define_expand "<u>mulsidi3"
220 [(set (match_operand:DI 0 "register_operand")
221 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
222 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
225 emit_insn (gen_mulsi3 (gen_lowpart (SImode, operands[0]),
226 operands[1], operands[2]));
227 emit_insn (gen_<u>mulsi3_highpart (gen_highpart (SImode, operands[0]),
228 operands[1], operands[2]));
232 (define_insn "<u>mulsi3_highpart"
233 [(set (match_operand:SI 0 "register_operand" "=a")
236 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "%r"))
237 (any_extend:DI (match_operand:SI 2 "register_operand" "r")))
240 "mul<su>h\t%0, %1, %2"
241 [(set_attr "type" "mul32")
242 (set_attr "mode" "SI")
243 (set_attr "length" "3")])
245 (define_insn "mulsi3"
246 [(set (match_operand:SI 0 "register_operand" "=a")
247 (mult:SI (match_operand:SI 1 "register_operand" "%r")
248 (match_operand:SI 2 "register_operand" "r")))]
251 [(set_attr "type" "mul32")
252 (set_attr "mode" "SI")
253 (set_attr "length" "3")])
255 (define_insn "mulhisi3"
256 [(set (match_operand:SI 0 "register_operand" "=C,A")
257 (mult:SI (sign_extend:SI
258 (match_operand:HI 1 "register_operand" "%r,r"))
260 (match_operand:HI 2 "register_operand" "r,r"))))]
261 "TARGET_MUL16 || TARGET_MAC16"
265 [(set_attr "type" "mul16,mac16")
266 (set_attr "mode" "SI")
267 (set_attr "length" "3,3")])
269 (define_insn "umulhisi3"
270 [(set (match_operand:SI 0 "register_operand" "=C,A")
271 (mult:SI (zero_extend:SI
272 (match_operand:HI 1 "register_operand" "%r,r"))
274 (match_operand:HI 2 "register_operand" "r,r"))))]
275 "TARGET_MUL16 || TARGET_MAC16"
279 [(set_attr "type" "mul16,mac16")
280 (set_attr "mode" "SI")
281 (set_attr "length" "3,3")])
283 (define_insn "muladdhisi"
284 [(set (match_operand:SI 0 "register_operand" "=A")
285 (plus:SI (mult:SI (sign_extend:SI
286 (match_operand:HI 1 "register_operand" "%r"))
288 (match_operand:HI 2 "register_operand" "r")))
289 (match_operand:SI 3 "register_operand" "0")))]
292 [(set_attr "type" "mac16")
293 (set_attr "mode" "SI")
294 (set_attr "length" "3")])
296 (define_insn "mulsubhisi"
297 [(set (match_operand:SI 0 "register_operand" "=A")
298 (minus:SI (match_operand:SI 1 "register_operand" "0")
299 (mult:SI (sign_extend:SI
300 (match_operand:HI 2 "register_operand" "%r"))
302 (match_operand:HI 3 "register_operand" "r")))))]
305 [(set_attr "type" "mac16")
306 (set_attr "mode" "SI")
307 (set_attr "length" "3")])
309 (define_insn "mulsf3"
310 [(set (match_operand:SF 0 "register_operand" "=f")
311 (mult:SF (match_operand:SF 1 "register_operand" "%f")
312 (match_operand:SF 2 "register_operand" "f")))]
315 [(set_attr "type" "fmadd")
316 (set_attr "mode" "SF")
317 (set_attr "length" "3")])
319 (define_insn "muladdsf3"
320 [(set (match_operand:SF 0 "register_operand" "=f")
321 (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "%f")
322 (match_operand:SF 2 "register_operand" "f"))
323 (match_operand:SF 3 "register_operand" "0")))]
324 "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
326 [(set_attr "type" "fmadd")
327 (set_attr "mode" "SF")
328 (set_attr "length" "3")])
330 (define_insn "mulsubsf3"
331 [(set (match_operand:SF 0 "register_operand" "=f")
332 (minus:SF (match_operand:SF 1 "register_operand" "0")
333 (mult:SF (match_operand:SF 2 "register_operand" "%f")
334 (match_operand:SF 3 "register_operand" "f"))))]
335 "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
337 [(set_attr "type" "fmadd")
338 (set_attr "mode" "SF")
339 (set_attr "length" "3")])
344 (define_insn "divsi3"
345 [(set (match_operand:SI 0 "register_operand" "=a")
346 (div:SI (match_operand:SI 1 "register_operand" "r")
347 (match_operand:SI 2 "register_operand" "r")))]
350 [(set_attr "type" "div32")
351 (set_attr "mode" "SI")
352 (set_attr "length" "3")])
354 (define_insn "udivsi3"
355 [(set (match_operand:SI 0 "register_operand" "=a")
356 (udiv:SI (match_operand:SI 1 "register_operand" "r")
357 (match_operand:SI 2 "register_operand" "r")))]
360 [(set_attr "type" "div32")
361 (set_attr "mode" "SI")
362 (set_attr "length" "3")])
364 (define_insn "divsf3"
365 [(set (match_operand:SF 0 "register_operand" "=f")
366 (div:SF (match_operand:SF 1 "register_operand" "f")
367 (match_operand:SF 2 "register_operand" "f")))]
368 "TARGET_HARD_FLOAT_DIV"
370 [(set_attr "type" "fdiv")
371 (set_attr "mode" "SF")
372 (set_attr "length" "3")])
374 (define_insn "*recipsf2"
375 [(set (match_operand:SF 0 "register_operand" "=f")
376 (div:SF (match_operand:SF 1 "const_float_1_operand" "")
377 (match_operand:SF 2 "register_operand" "f")))]
378 "TARGET_HARD_FLOAT_RECIP && flag_unsafe_math_optimizations"
380 [(set_attr "type" "fdiv")
381 (set_attr "mode" "SF")
382 (set_attr "length" "3")])
387 (define_insn "modsi3"
388 [(set (match_operand:SI 0 "register_operand" "=a")
389 (mod:SI (match_operand:SI 1 "register_operand" "r")
390 (match_operand:SI 2 "register_operand" "r")))]
393 [(set_attr "type" "div32")
394 (set_attr "mode" "SI")
395 (set_attr "length" "3")])
397 (define_insn "umodsi3"
398 [(set (match_operand:SI 0 "register_operand" "=a")
399 (umod:SI (match_operand:SI 1 "register_operand" "r")
400 (match_operand:SI 2 "register_operand" "r")))]
403 [(set_attr "type" "div32")
404 (set_attr "mode" "SI")
405 (set_attr "length" "3")])
410 (define_insn "sqrtsf2"
411 [(set (match_operand:SF 0 "register_operand" "=f")
412 (sqrt:SF (match_operand:SF 1 "register_operand" "f")))]
413 "TARGET_HARD_FLOAT_SQRT"
415 [(set_attr "type" "fsqrt")
416 (set_attr "mode" "SF")
417 (set_attr "length" "3")])
419 (define_insn "*rsqrtsf2"
420 [(set (match_operand:SF 0 "register_operand" "=f")
421 (div:SF (match_operand:SF 1 "const_float_1_operand" "")
422 (sqrt:SF (match_operand:SF 2 "register_operand" "f"))))]
423 "TARGET_HARD_FLOAT_RSQRT && flag_unsafe_math_optimizations"
425 [(set_attr "type" "fsqrt")
426 (set_attr "mode" "SF")
427 (set_attr "length" "3")])
432 (define_insn "abssi2"
433 [(set (match_operand:SI 0 "register_operand" "=a")
434 (abs:SI (match_operand:SI 1 "register_operand" "r")))]
437 [(set_attr "type" "arith")
438 (set_attr "mode" "SI")
439 (set_attr "length" "3")])
441 (define_insn "abssf2"
442 [(set (match_operand:SF 0 "register_operand" "=f")
443 (abs:SF (match_operand:SF 1 "register_operand" "f")))]
446 [(set_attr "type" "farith")
447 (set_attr "mode" "SF")
448 (set_attr "length" "3")])
453 (define_insn "<code>si3"
454 [(set (match_operand:SI 0 "register_operand" "=a")
455 (any_minmax:SI (match_operand:SI 1 "register_operand" "%r")
456 (match_operand:SI 2 "register_operand" "r")))]
458 "<minmax>\t%0, %1, %2"
459 [(set_attr "type" "arith")
460 (set_attr "mode" "SI")
461 (set_attr "length" "3")])
464 ;; Count leading/trailing zeros and find first bit.
466 (define_insn "clzsi2"
467 [(set (match_operand:SI 0 "register_operand" "=a")
468 (clz:SI (match_operand:SI 1 "register_operand" "r")))]
471 [(set_attr "type" "arith")
472 (set_attr "mode" "SI")
473 (set_attr "length" "3")])
475 (define_expand "ctzsi2"
476 [(set (match_operand:SI 0 "register_operand" "")
477 (ctz:SI (match_operand:SI 1 "register_operand" "")))]
480 rtx temp = gen_reg_rtx (SImode);
481 emit_insn (gen_negsi2 (temp, operands[1]));
482 emit_insn (gen_andsi3 (temp, temp, operands[1]));
483 emit_insn (gen_clzsi2 (temp, temp));
484 emit_insn (gen_negsi2 (temp, temp));
485 emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (31)));
489 (define_expand "ffssi2"
490 [(set (match_operand:SI 0 "register_operand" "")
491 (ffs:SI (match_operand:SI 1 "register_operand" "")))]
494 rtx temp = gen_reg_rtx (SImode);
495 emit_insn (gen_negsi2 (temp, operands[1]));
496 emit_insn (gen_andsi3 (temp, temp, operands[1]));
497 emit_insn (gen_clzsi2 (temp, temp));
498 emit_insn (gen_negsi2 (temp, temp));
499 emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (32)));
504 ;; Negation and one's complement.
506 (define_insn "negsi2"
507 [(set (match_operand:SI 0 "register_operand" "=a")
508 (neg:SI (match_operand:SI 1 "register_operand" "r")))]
511 [(set_attr "type" "arith")
512 (set_attr "mode" "SI")
513 (set_attr "length" "3")])
515 (define_expand "one_cmplsi2"
516 [(set (match_operand:SI 0 "register_operand" "")
517 (not:SI (match_operand:SI 1 "register_operand" "")))]
520 rtx temp = gen_reg_rtx (SImode);
521 emit_insn (gen_movsi (temp, constm1_rtx));
522 emit_insn (gen_xorsi3 (operands[0], temp, operands[1]));
526 (define_insn "negsf2"
527 [(set (match_operand:SF 0 "register_operand" "=f")
528 (neg:SF (match_operand:SF 1 "register_operand" "f")))]
531 [(set_attr "type" "farith")
532 (set_attr "mode" "SF")
533 (set_attr "length" "3")])
536 ;; Logical instructions.
538 (define_insn "andsi3"
539 [(set (match_operand:SI 0 "register_operand" "=a,a")
540 (and:SI (match_operand:SI 1 "register_operand" "%r,r")
541 (match_operand:SI 2 "mask_operand" "P,r")))]
544 extui\t%0, %1, 0, %K2
546 [(set_attr "type" "arith,arith")
547 (set_attr "mode" "SI")
548 (set_attr "length" "3,3")])
550 (define_insn "iorsi3"
551 [(set (match_operand:SI 0 "register_operand" "=a")
552 (ior:SI (match_operand:SI 1 "register_operand" "%r")
553 (match_operand:SI 2 "register_operand" "r")))]
556 [(set_attr "type" "arith")
557 (set_attr "mode" "SI")
558 (set_attr "length" "3")])
560 (define_insn "xorsi3"
561 [(set (match_operand:SI 0 "register_operand" "=a")
562 (xor:SI (match_operand:SI 1 "register_operand" "%r")
563 (match_operand:SI 2 "register_operand" "r")))]
566 [(set_attr "type" "arith")
567 (set_attr "mode" "SI")
568 (set_attr "length" "3")])
571 ;; Zero-extend instructions.
573 (define_insn "zero_extendhisi2"
574 [(set (match_operand:SI 0 "register_operand" "=a,a")
575 (zero_extend:SI (match_operand:HI 1 "nonimmed_operand" "r,U")))]
580 [(set_attr "type" "arith,load")
581 (set_attr "mode" "SI")
582 (set_attr "length" "3,3")])
584 (define_insn "zero_extendqisi2"
585 [(set (match_operand:SI 0 "register_operand" "=a,a")
586 (zero_extend:SI (match_operand:QI 1 "nonimmed_operand" "r,U")))]
591 [(set_attr "type" "arith,load")
592 (set_attr "mode" "SI")
593 (set_attr "length" "3,3")])
596 ;; Sign-extend instructions.
598 (define_expand "extendhisi2"
599 [(set (match_operand:SI 0 "register_operand" "")
600 (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
603 if (sext_operand (operands[1], HImode))
604 emit_insn (gen_extendhisi2_internal (operands[0], operands[1]));
606 xtensa_extend_reg (operands[0], operands[1]);
610 (define_insn "extendhisi2_internal"
611 [(set (match_operand:SI 0 "register_operand" "=B,a")
612 (sign_extend:SI (match_operand:HI 1 "sext_operand" "r,U")))]
617 [(set_attr "type" "arith,load")
618 (set_attr "mode" "SI")
619 (set_attr "length" "3,3")])
621 (define_expand "extendqisi2"
622 [(set (match_operand:SI 0 "register_operand" "")
623 (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
627 emit_insn (gen_extendqisi2_internal (operands[0], operands[1]));
629 xtensa_extend_reg (operands[0], operands[1]);
633 (define_insn "extendqisi2_internal"
634 [(set (match_operand:SI 0 "register_operand" "=B")
635 (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
638 [(set_attr "type" "arith")
639 (set_attr "mode" "SI")
640 (set_attr "length" "3")])
643 ;; Field extract instructions.
645 (define_expand "extv"
646 [(set (match_operand:SI 0 "register_operand" "")
647 (sign_extract:SI (match_operand:SI 1 "register_operand" "")
648 (match_operand:SI 2 "const_int_operand" "")
649 (match_operand:SI 3 "const_int_operand" "")))]
652 if (!sext_fldsz_operand (operands[2], SImode))
655 /* We could expand to a right shift followed by SEXT but that's
656 no better than the standard left and right shift sequence. */
657 if (!lsbitnum_operand (operands[3], SImode))
660 emit_insn (gen_extv_internal (operands[0], operands[1],
661 operands[2], operands[3]));
665 (define_insn "extv_internal"
666 [(set (match_operand:SI 0 "register_operand" "=a")
667 (sign_extract:SI (match_operand:SI 1 "register_operand" "r")
668 (match_operand:SI 2 "sext_fldsz_operand" "i")
669 (match_operand:SI 3 "lsbitnum_operand" "i")))]
672 int fldsz = INTVAL (operands[2]);
673 operands[2] = GEN_INT (fldsz - 1);
674 return "sext\t%0, %1, %2";
676 [(set_attr "type" "arith")
677 (set_attr "mode" "SI")
678 (set_attr "length" "3")])
680 (define_expand "extzv"
681 [(set (match_operand:SI 0 "register_operand" "")
682 (zero_extract:SI (match_operand:SI 1 "register_operand" "")
683 (match_operand:SI 2 "const_int_operand" "")
684 (match_operand:SI 3 "const_int_operand" "")))]
687 if (!extui_fldsz_operand (operands[2], SImode))
689 emit_insn (gen_extzv_internal (operands[0], operands[1],
690 operands[2], operands[3]));
694 (define_insn "extzv_internal"
695 [(set (match_operand:SI 0 "register_operand" "=a")
696 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
697 (match_operand:SI 2 "extui_fldsz_operand" "i")
698 (match_operand:SI 3 "const_int_operand" "i")))]
703 shift = (32 - (INTVAL (operands[2]) + INTVAL (operands[3]))) & 0x1f;
705 shift = INTVAL (operands[3]) & 0x1f;
706 operands[3] = GEN_INT (shift);
707 return "extui\t%0, %1, %3, %2";
709 [(set_attr "type" "arith")
710 (set_attr "mode" "SI")
711 (set_attr "length" "3")])
716 (define_insn "fix_truncsfsi2"
717 [(set (match_operand:SI 0 "register_operand" "=a")
718 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
721 [(set_attr "type" "fconv")
722 (set_attr "mode" "SF")
723 (set_attr "length" "3")])
725 (define_insn "fixuns_truncsfsi2"
726 [(set (match_operand:SI 0 "register_operand" "=a")
727 (unsigned_fix:SI (match_operand:SF 1 "register_operand" "f")))]
729 "utrunc.s\t%0, %1, 0"
730 [(set_attr "type" "fconv")
731 (set_attr "mode" "SF")
732 (set_attr "length" "3")])
734 (define_insn "floatsisf2"
735 [(set (match_operand:SF 0 "register_operand" "=f")
736 (float:SF (match_operand:SI 1 "register_operand" "a")))]
739 [(set_attr "type" "fconv")
740 (set_attr "mode" "SF")
741 (set_attr "length" "3")])
743 (define_insn "floatunssisf2"
744 [(set (match_operand:SF 0 "register_operand" "=f")
745 (unsigned_float:SF (match_operand:SI 1 "register_operand" "a")))]
747 "ufloat.s\t%0, %1, 0"
748 [(set_attr "type" "fconv")
749 (set_attr "mode" "SF")
750 (set_attr "length" "3")])
753 ;; Data movement instructions.
755 ;; 64-bit Integer moves
757 (define_expand "movdi"
758 [(set (match_operand:DI 0 "nonimmed_operand" "")
759 (match_operand:DI 1 "general_operand" ""))]
762 if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
763 operands[1] = force_const_mem (DImode, operands[1]);
765 if (!register_operand (operands[0], DImode)
766 && !register_operand (operands[1], DImode))
767 operands[1] = force_reg (DImode, operands[1]);
769 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
772 (define_insn_and_split "movdi_internal"
773 [(set (match_operand:DI 0 "nonimmed_operand" "=a,W,a,a,U")
774 (match_operand:DI 1 "move_operand" "r,i,T,U,r"))]
775 "register_operand (operands[0], DImode)
776 || register_operand (operands[1], DImode)"
779 [(set (match_dup 0) (match_dup 2))
780 (set (match_dup 1) (match_dup 3))]
782 xtensa_split_operand_pair (operands, SImode);
783 if (reg_overlap_mentioned_p (operands[0], operands[3]))
786 tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
787 tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
791 ;; 32-bit Integer moves
793 (define_expand "movsi"
794 [(set (match_operand:SI 0 "nonimmed_operand" "")
795 (match_operand:SI 1 "general_operand" ""))]
798 if (xtensa_emit_move_sequence (operands, SImode))
802 (define_insn "movsi_internal"
803 [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,W,a,a,U,*a,*A")
804 (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,i,T,U,r,*A,*r"))]
805 "xtensa_valid_move (SImode, operands)"
816 const16\t%0, %t1\;const16\t%0, %b1
822 [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,load,load,store,rsr,wsr")
823 (set_attr "mode" "SI")
824 (set_attr "length" "2,2,2,2,2,2,3,3,3,6,3,3,3,3,3")])
826 ;; 16-bit Integer moves
828 (define_expand "movhi"
829 [(set (match_operand:HI 0 "nonimmed_operand" "")
830 (match_operand:HI 1 "general_operand" ""))]
833 if (xtensa_emit_move_sequence (operands, HImode))
837 (define_insn "movhi_internal"
838 [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
839 (match_operand:HI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
840 "xtensa_valid_move (HImode, operands)"
850 [(set_attr "type" "move,move,move,move,load,store,rsr,wsr")
851 (set_attr "mode" "HI")
852 (set_attr "length" "2,2,3,3,3,3,3,3")])
854 ;; 8-bit Integer moves
856 (define_expand "movqi"
857 [(set (match_operand:QI 0 "nonimmed_operand" "")
858 (match_operand:QI 1 "general_operand" ""))]
861 if (xtensa_emit_move_sequence (operands, QImode))
865 (define_insn "movqi_internal"
866 [(set (match_operand:QI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
867 (match_operand:QI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
868 "xtensa_valid_move (QImode, operands)"
878 [(set_attr "type" "move,move,move,move,load,store,rsr,wsr")
879 (set_attr "mode" "QI")
880 (set_attr "length" "2,2,3,3,3,3,3,3")])
882 ;; 32-bit floating point moves
884 (define_expand "movsf"
885 [(set (match_operand:SF 0 "nonimmed_operand" "")
886 (match_operand:SF 1 "general_operand" ""))]
889 if (!TARGET_CONST16 && CONSTANT_P (operands[1]))
890 operands[1] = force_const_mem (SFmode, operands[1]);
892 if ((!register_operand (operands[0], SFmode)
893 && !register_operand (operands[1], SFmode))
894 || (FP_REG_P (xt_true_regnum (operands[0]))
895 && !(reload_in_progress | reload_completed)
896 && (constantpool_mem_p (operands[1])
897 || CONSTANT_P (operands[1]))))
898 operands[1] = force_reg (SFmode, operands[1]);
900 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
903 (define_insn "movsf_internal"
904 [(set (match_operand:SF 0 "nonimmed_operand" "=f,f,U,D,D,R,a,f,a,W,a,a,U")
905 (match_operand:SF 1 "move_operand" "f,U,f,d,R,d,r,r,f,iF,T,U,r"))]
906 "((register_operand (operands[0], SFmode)
907 || register_operand (operands[1], SFmode))
908 && !(FP_REG_P (xt_true_regnum (operands[0]))
909 && (constantpool_mem_p (operands[1]) || CONSTANT_P (operands[1]))))"
920 const16\t%0, %t1\;const16\t%0, %b1
924 [(set_attr "type" "farith,fload,fstore,move,load,store,move,farith,farith,move,load,load,store")
925 (set_attr "mode" "SF")
926 (set_attr "length" "3,3,3,2,2,2,3,3,3,6,3,3,3")])
929 [(set (match_operand:SF 0 "register_operand" "=f")
930 (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "+a")
931 (match_operand:SI 2 "fpmem_offset_operand" "i"))))
933 (plus:SI (match_dup 1) (match_dup 2)))]
936 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
937 output_asm_insn ("memw", operands);
938 return "lsiu\t%0, %1, %2";
940 [(set_attr "type" "fload")
941 (set_attr "mode" "SF")
942 (set_attr "length" "3")])
945 [(set (mem:SF (plus:SI (match_operand:SI 0 "register_operand" "+a")
946 (match_operand:SI 1 "fpmem_offset_operand" "i")))
947 (match_operand:SF 2 "register_operand" "f"))
949 (plus:SI (match_dup 0) (match_dup 1)))]
952 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
953 output_asm_insn ("memw", operands);
954 return "ssiu\t%2, %0, %1";
956 [(set_attr "type" "fstore")
957 (set_attr "mode" "SF")
958 (set_attr "length" "3")])
960 ;; 64-bit floating point moves
962 (define_expand "movdf"
963 [(set (match_operand:DF 0 "nonimmed_operand" "")
964 (match_operand:DF 1 "general_operand" ""))]
967 if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
968 operands[1] = force_const_mem (DFmode, operands[1]);
970 if (!register_operand (operands[0], DFmode)
971 && !register_operand (operands[1], DFmode))
972 operands[1] = force_reg (DFmode, operands[1]);
974 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
977 (define_insn_and_split "movdf_internal"
978 [(set (match_operand:DF 0 "nonimmed_operand" "=a,W,a,a,U")
979 (match_operand:DF 1 "move_operand" "r,iF,T,U,r"))]
980 "register_operand (operands[0], DFmode)
981 || register_operand (operands[1], DFmode)"
984 [(set (match_dup 0) (match_dup 2))
985 (set (match_dup 1) (match_dup 3))]
987 xtensa_split_operand_pair (operands, SFmode);
988 if (reg_overlap_mentioned_p (operands[0], operands[3]))
991 tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
992 tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
998 (define_expand "movmemsi"
999 [(parallel [(set (match_operand:BLK 0 "" "")
1000 (match_operand:BLK 1 "" ""))
1001 (use (match_operand:SI 2 "arith_operand" ""))
1002 (use (match_operand:SI 3 "const_int_operand" ""))])]
1005 if (!xtensa_expand_block_move (operands))
1011 ;; Shift instructions.
1013 (define_expand "ashlsi3"
1014 [(set (match_operand:SI 0 "register_operand" "")
1015 (ashift:SI (match_operand:SI 1 "register_operand" "")
1016 (match_operand:SI 2 "arith_operand" "")))]
1019 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1022 (define_insn "ashlsi3_internal"
1023 [(set (match_operand:SI 0 "register_operand" "=a,a")
1024 (ashift:SI (match_operand:SI 1 "register_operand" "r,r")
1025 (match_operand:SI 2 "arith_operand" "J,r")))]
1029 ssl\t%2\;sll\t%0, %1"
1030 [(set_attr "type" "arith,arith")
1031 (set_attr "mode" "SI")
1032 (set_attr "length" "3,6")])
1034 (define_insn "ashrsi3"
1035 [(set (match_operand:SI 0 "register_operand" "=a,a")
1036 (ashiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1037 (match_operand:SI 2 "arith_operand" "J,r")))]
1041 ssr\t%2\;sra\t%0, %1"
1042 [(set_attr "type" "arith,arith")
1043 (set_attr "mode" "SI")
1044 (set_attr "length" "3,6")])
1046 (define_insn "lshrsi3"
1047 [(set (match_operand:SI 0 "register_operand" "=a,a")
1048 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1049 (match_operand:SI 2 "arith_operand" "J,r")))]
1052 if (which_alternative == 0)
1054 if ((INTVAL (operands[2]) & 0x1f) < 16)
1055 return "srli\t%0, %1, %R2";
1057 return "extui\t%0, %1, %R2, %L2";
1059 return "ssr\t%2\;srl\t%0, %1";
1061 [(set_attr "type" "arith,arith")
1062 (set_attr "mode" "SI")
1063 (set_attr "length" "3,6")])
1065 (define_insn "rotlsi3"
1066 [(set (match_operand:SI 0 "register_operand" "=a,a")
1067 (rotate:SI (match_operand:SI 1 "register_operand" "r,r")
1068 (match_operand:SI 2 "arith_operand" "J,r")))]
1071 ssai\t%L2\;src\t%0, %1, %1
1072 ssl\t%2\;src\t%0, %1, %1"
1073 [(set_attr "type" "multi,multi")
1074 (set_attr "mode" "SI")
1075 (set_attr "length" "6,6")])
1077 (define_insn "rotrsi3"
1078 [(set (match_operand:SI 0 "register_operand" "=a,a")
1079 (rotatert:SI (match_operand:SI 1 "register_operand" "r,r")
1080 (match_operand:SI 2 "arith_operand" "J,r")))]
1083 ssai\t%R2\;src\t%0, %1, %1
1084 ssr\t%2\;src\t%0, %1, %1"
1085 [(set_attr "type" "multi,multi")
1086 (set_attr "mode" "SI")
1087 (set_attr "length" "6,6")])
1092 ;; Handle comparisons by stashing away the operands and then using that
1093 ;; information in the subsequent conditional branch.
1095 (define_expand "cmpsi"
1097 (compare:CC (match_operand:SI 0 "register_operand" "")
1098 (match_operand:SI 1 "nonmemory_operand" "")))]
1101 branch_cmp[0] = operands[0];
1102 branch_cmp[1] = operands[1];
1103 branch_type = CMP_SI;
1107 (define_expand "cmpsf"
1109 (compare:CC (match_operand:SF 0 "register_operand" "")
1110 (match_operand:SF 1 "register_operand" "")))]
1113 branch_cmp[0] = operands[0];
1114 branch_cmp[1] = operands[1];
1115 branch_type = CMP_SF;
1120 ;; Conditional branches.
1122 (define_expand "b<code>"
1124 (if_then_else (any_cond (cc0) (const_int 0))
1125 (label_ref (match_operand 0 "" ""))
1129 xtensa_expand_conditional_branch (operands, <CODE>);
1133 ;; Branch patterns for standard integer comparisons
1135 (define_insn "*btrue"
1137 (if_then_else (match_operator 3 "branch_operator"
1138 [(match_operand:SI 0 "register_operand" "r,r")
1139 (match_operand:SI 1 "branch_operand" "K,r")])
1140 (label_ref (match_operand 2 "" ""))
1144 return xtensa_emit_branch (false, which_alternative == 0, operands);
1146 [(set_attr "type" "jump,jump")
1147 (set_attr "mode" "none")
1148 (set_attr "length" "3,3")])
1150 (define_insn "*bfalse"
1152 (if_then_else (match_operator 3 "branch_operator"
1153 [(match_operand:SI 0 "register_operand" "r,r")
1154 (match_operand:SI 1 "branch_operand" "K,r")])
1156 (label_ref (match_operand 2 "" ""))))]
1159 return xtensa_emit_branch (true, which_alternative == 0, operands);
1161 [(set_attr "type" "jump,jump")
1162 (set_attr "mode" "none")
1163 (set_attr "length" "3,3")])
1165 (define_insn "*ubtrue"
1167 (if_then_else (match_operator 3 "ubranch_operator"
1168 [(match_operand:SI 0 "register_operand" "r,r")
1169 (match_operand:SI 1 "ubranch_operand" "L,r")])
1170 (label_ref (match_operand 2 "" ""))
1174 return xtensa_emit_branch (false, which_alternative == 0, operands);
1176 [(set_attr "type" "jump,jump")
1177 (set_attr "mode" "none")
1178 (set_attr "length" "3,3")])
1180 (define_insn "*ubfalse"
1182 (if_then_else (match_operator 3 "ubranch_operator"
1183 [(match_operand:SI 0 "register_operand" "r,r")
1184 (match_operand:SI 1 "ubranch_operand" "L,r")])
1186 (label_ref (match_operand 2 "" ""))))]
1189 return xtensa_emit_branch (true, which_alternative == 0, operands);
1191 [(set_attr "type" "jump,jump")
1192 (set_attr "mode" "none")
1193 (set_attr "length" "3,3")])
1195 ;; Branch patterns for bit testing
1197 (define_insn "*bittrue"
1199 (if_then_else (match_operator 3 "boolean_operator"
1201 (match_operand:SI 0 "register_operand" "r,r")
1203 (match_operand:SI 1 "arith_operand" "J,r"))
1205 (label_ref (match_operand 2 "" ""))
1209 return xtensa_emit_bit_branch (false, which_alternative == 0, operands);
1211 [(set_attr "type" "jump")
1212 (set_attr "mode" "none")
1213 (set_attr "length" "3")])
1215 (define_insn "*bitfalse"
1217 (if_then_else (match_operator 3 "boolean_operator"
1219 (match_operand:SI 0 "register_operand" "r,r")
1221 (match_operand:SI 1 "arith_operand" "J,r"))
1224 (label_ref (match_operand 2 "" ""))))]
1227 return xtensa_emit_bit_branch (true, which_alternative == 0, operands);
1229 [(set_attr "type" "jump")
1230 (set_attr "mode" "none")
1231 (set_attr "length" "3")])
1233 (define_insn "*masktrue"
1235 (if_then_else (match_operator 3 "boolean_operator"
1236 [(and:SI (match_operand:SI 0 "register_operand" "r")
1237 (match_operand:SI 1 "register_operand" "r"))
1239 (label_ref (match_operand 2 "" ""))
1243 switch (GET_CODE (operands[3]))
1245 case EQ: return "bnone\t%0, %1, %2";
1246 case NE: return "bany\t%0, %1, %2";
1247 default: gcc_unreachable ();
1250 [(set_attr "type" "jump")
1251 (set_attr "mode" "none")
1252 (set_attr "length" "3")])
1254 (define_insn "*maskfalse"
1256 (if_then_else (match_operator 3 "boolean_operator"
1257 [(and:SI (match_operand:SI 0 "register_operand" "r")
1258 (match_operand:SI 1 "register_operand" "r"))
1261 (label_ref (match_operand 2 "" ""))))]
1264 switch (GET_CODE (operands[3]))
1266 case EQ: return "bany\t%0, %1, %2";
1267 case NE: return "bnone\t%0, %1, %2";
1268 default: gcc_unreachable ();
1271 [(set_attr "type" "jump")
1272 (set_attr "mode" "none")
1273 (set_attr "length" "3")])
1276 ;; Define the loop insns used by bct optimization to represent the
1277 ;; start and end of a zero-overhead loop (in loop.c). This start
1278 ;; template generates the loop insn; the end template doesn't generate
1279 ;; any instructions since loop end is handled in hardware.
1281 (define_insn "zero_cost_loop_start"
1283 (if_then_else (eq (match_operand:SI 0 "register_operand" "a")
1285 (label_ref (match_operand 1 "" ""))
1288 (plus:SI (match_dup 0) (const_int -1)))]
1291 [(set_attr "type" "jump")
1292 (set_attr "mode" "none")
1293 (set_attr "length" "3")])
1295 (define_insn "zero_cost_loop_end"
1297 (if_then_else (ne (reg:SI 19) (const_int 0))
1298 (label_ref (match_operand 0 "" ""))
1301 (plus:SI (reg:SI 19) (const_int -1)))]
1304 xtensa_emit_loop_end (insn, operands);
1307 [(set_attr "type" "jump")
1308 (set_attr "mode" "none")
1309 (set_attr "length" "0")])
1312 ;; Setting a register from a comparison.
1314 (define_expand "s<code>"
1315 [(set (match_operand:SI 0 "register_operand" "")
1316 (any_scc:SI (match_dup 1)
1320 operands[1] = gen_rtx_<CODE> (SImode, branch_cmp[0], branch_cmp[1]);
1321 if (!xtensa_expand_scc (operands))
1327 ;; Conditional moves.
1329 (define_expand "movsicc"
1330 [(set (match_operand:SI 0 "register_operand" "")
1331 (if_then_else:SI (match_operand 1 "comparison_operator" "")
1332 (match_operand:SI 2 "register_operand" "")
1333 (match_operand:SI 3 "register_operand" "")))]
1336 if (!xtensa_expand_conditional_move (operands, 0))
1341 (define_expand "movsfcc"
1342 [(set (match_operand:SF 0 "register_operand" "")
1343 (if_then_else:SF (match_operand 1 "comparison_operator" "")
1344 (match_operand:SF 2 "register_operand" "")
1345 (match_operand:SF 3 "register_operand" "")))]
1348 if (!xtensa_expand_conditional_move (operands, 1))
1353 (define_insn "movsicc_internal0"
1354 [(set (match_operand:SI 0 "register_operand" "=a,a")
1355 (if_then_else:SI (match_operator 4 "branch_operator"
1356 [(match_operand:SI 1 "register_operand" "r,r")
1358 (match_operand:SI 2 "register_operand" "r,0")
1359 (match_operand:SI 3 "register_operand" "0,r")))]
1362 return xtensa_emit_movcc (which_alternative == 1, false, false, operands);
1364 [(set_attr "type" "move,move")
1365 (set_attr "mode" "SI")
1366 (set_attr "length" "3,3")])
1368 (define_insn "movsicc_internal1"
1369 [(set (match_operand:SI 0 "register_operand" "=a,a")
1370 (if_then_else:SI (match_operator 4 "boolean_operator"
1371 [(match_operand:CC 1 "register_operand" "b,b")
1373 (match_operand:SI 2 "register_operand" "r,0")
1374 (match_operand:SI 3 "register_operand" "0,r")))]
1377 return xtensa_emit_movcc (which_alternative == 1, false, true, operands);
1379 [(set_attr "type" "move,move")
1380 (set_attr "mode" "SI")
1381 (set_attr "length" "3,3")])
1383 (define_insn "movsfcc_internal0"
1384 [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1385 (if_then_else:SF (match_operator 4 "branch_operator"
1386 [(match_operand:SI 1 "register_operand" "r,r,r,r")
1388 (match_operand:SF 2 "register_operand" "r,0,f,0")
1389 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1392 return xtensa_emit_movcc ((which_alternative & 1) == 1,
1393 which_alternative >= 2, false, operands);
1395 [(set_attr "type" "move,move,move,move")
1396 (set_attr "mode" "SF")
1397 (set_attr "length" "3,3,3,3")])
1399 (define_insn "movsfcc_internal1"
1400 [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1401 (if_then_else:SF (match_operator 4 "boolean_operator"
1402 [(match_operand:CC 1 "register_operand" "b,b,b,b")
1404 (match_operand:SF 2 "register_operand" "r,0,f,0")
1405 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1408 return xtensa_emit_movcc ((which_alternative & 1) == 1,
1409 which_alternative >= 2, true, operands);
1411 [(set_attr "type" "move,move,move,move")
1412 (set_attr "mode" "SF")
1413 (set_attr "length" "3,3,3,3")])
1416 ;; Floating-point comparisons.
1418 (define_insn "s<code>_sf"
1419 [(set (match_operand:CC 0 "register_operand" "=b")
1420 (any_scc_sf:CC (match_operand:SF 1 "register_operand" "f")
1421 (match_operand:SF 2 "register_operand" "f")))]
1423 "<scc_sf>.s\t%0, %1, %2"
1424 [(set_attr "type" "farith")
1425 (set_attr "mode" "BL")
1426 (set_attr "length" "3")])
1429 ;; Unconditional branches.
1433 (label_ref (match_operand 0 "" "")))]
1436 [(set_attr "type" "jump")
1437 (set_attr "mode" "none")
1438 (set_attr "length" "3")])
1440 (define_expand "indirect_jump"
1442 (match_operand 0 "register_operand" ""))]
1445 rtx dest = operands[0];
1446 if (GET_CODE (dest) != REG || GET_MODE (dest) != Pmode)
1447 operands[0] = copy_to_mode_reg (Pmode, dest);
1449 emit_jump_insn (gen_indirect_jump_internal (dest));
1453 (define_insn "indirect_jump_internal"
1454 [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
1457 [(set_attr "type" "jump")
1458 (set_attr "mode" "none")
1459 (set_attr "length" "3")])
1462 (define_expand "tablejump"
1463 [(use (match_operand:SI 0 "register_operand" ""))
1464 (use (label_ref (match_operand 1 "" "")))]
1467 rtx target = operands[0];
1470 /* For PIC, the table entry is relative to the start of the table. */
1471 rtx label = gen_reg_rtx (SImode);
1472 target = gen_reg_rtx (SImode);
1473 emit_move_insn (label, gen_rtx_LABEL_REF (SImode, operands[1]));
1474 emit_insn (gen_addsi3 (target, operands[0], label));
1476 emit_jump_insn (gen_tablejump_internal (target, operands[1]));
1480 (define_insn "tablejump_internal"
1482 (match_operand:SI 0 "register_operand" "r"))
1483 (use (label_ref (match_operand 1 "" "")))]
1486 [(set_attr "type" "jump")
1487 (set_attr "mode" "none")
1488 (set_attr "length" "3")])
1493 (define_expand "sym_PLT"
1494 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PLT))]
1498 (define_expand "call"
1499 [(call (match_operand 0 "memory_operand" "")
1500 (match_operand 1 "" ""))]
1503 rtx addr = XEXP (operands[0], 0);
1504 if (flag_pic && GET_CODE (addr) == SYMBOL_REF
1505 && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
1506 addr = gen_sym_PLT (addr);
1507 if (!call_insn_operand (addr, VOIDmode))
1508 XEXP (operands[0], 0) = copy_to_mode_reg (Pmode, addr);
1511 (define_insn "call_internal"
1512 [(call (mem (match_operand:SI 0 "call_insn_operand" "nir"))
1513 (match_operand 1 "" "i"))]
1516 return xtensa_emit_call (0, operands);
1518 [(set_attr "type" "call")
1519 (set_attr "mode" "none")
1520 (set_attr "length" "3")])
1522 (define_expand "call_value"
1523 [(set (match_operand 0 "register_operand" "")
1524 (call (match_operand 1 "memory_operand" "")
1525 (match_operand 2 "" "")))]
1528 rtx addr = XEXP (operands[1], 0);
1529 if (flag_pic && GET_CODE (addr) == SYMBOL_REF
1530 && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
1531 addr = gen_sym_PLT (addr);
1532 if (!call_insn_operand (addr, VOIDmode))
1533 XEXP (operands[1], 0) = copy_to_mode_reg (Pmode, addr);
1536 (define_insn "call_value_internal"
1537 [(set (match_operand 0 "register_operand" "=a")
1538 (call (mem (match_operand:SI 1 "call_insn_operand" "nir"))
1539 (match_operand 2 "" "i")))]
1542 return xtensa_emit_call (1, operands);
1544 [(set_attr "type" "call")
1545 (set_attr "mode" "none")
1546 (set_attr "length" "3")])
1548 (define_insn "entry"
1549 [(set (reg:SI A1_REG)
1550 (unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "i")]
1554 [(set_attr "type" "entry")
1555 (set_attr "mode" "SI")
1556 (set_attr "length" "3")])
1558 (define_insn "return"
1560 (use (reg:SI A0_REG))]
1563 return (TARGET_DENSITY ? "retw.n" : "retw");
1565 [(set_attr "type" "jump")
1566 (set_attr "mode" "none")
1567 (set_attr "length" "2")])
1570 ;; Miscellaneous instructions.
1572 (define_expand "prologue"
1576 xtensa_expand_prologue ();
1580 (define_expand "epilogue"
1584 emit_jump_insn (gen_return ());
1592 return (TARGET_DENSITY ? "nop.n" : "nop");
1594 [(set_attr "type" "nop")
1595 (set_attr "mode" "none")
1596 (set_attr "length" "3")])
1598 (define_expand "nonlocal_goto"
1599 [(match_operand:SI 0 "general_operand" "")
1600 (match_operand:SI 1 "general_operand" "")
1601 (match_operand:SI 2 "general_operand" "")
1602 (match_operand:SI 3 "" "")]
1605 xtensa_expand_nonlocal_goto (operands);
1609 ;; Stuff an address into the return address register along with the window
1610 ;; size in the high bits. Because we don't have the window size of the
1611 ;; previous frame, assume the function called out with a CALL8 since that
1612 ;; is what compilers always use. Note: __builtin_frob_return_addr has
1613 ;; already been applied to the handler, but the generic version doesn't
1614 ;; allow us to frob it quite enough, so we just frob here.
1616 (define_insn_and_split "eh_return"
1617 [(set (reg:SI A0_REG)
1618 (unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")]
1620 (clobber (match_scratch:SI 1 "=r"))]
1624 [(set (match_dup 1) (ashift:SI (match_dup 0) (const_int 2)))
1625 (set (match_dup 1) (plus:SI (match_dup 1) (const_int 2)))
1626 (set (reg:SI A0_REG) (rotatert:SI (match_dup 1) (const_int 2)))]
1629 ;; Setting up a frame pointer is tricky for Xtensa because GCC doesn't
1630 ;; know if a frame pointer is required until the reload pass, and
1631 ;; because there may be an incoming argument value in the hard frame
1632 ;; pointer register (a7). If there is an incoming argument in that
1633 ;; register, the "set_frame_ptr" insn gets inserted immediately after
1634 ;; the insn that copies the incoming argument to a pseudo or to the
1635 ;; stack. This serves several purposes here: (1) it keeps the
1636 ;; optimizer from copy-propagating or scheduling the use of a7 as an
1637 ;; incoming argument away from the beginning of the function; (2) we
1638 ;; can use a post-reload splitter to expand away the insn if a frame
1639 ;; pointer is not required, so that the post-reload scheduler can do
1640 ;; the right thing; and (3) it makes it easy for the prologue expander
1641 ;; to search for this insn to determine whether it should add a new insn
1642 ;; to set up the frame pointer.
1644 (define_insn "set_frame_ptr"
1645 [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
1648 if (frame_pointer_needed)
1649 return "mov\ta7, sp";
1652 [(set_attr "type" "move")
1653 (set_attr "mode" "SI")
1654 (set_attr "length" "3")])
1656 ;; Post-reload splitter to remove fp assignment when it's not needed.
1658 [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
1659 "reload_completed && !frame_pointer_needed"
1660 [(unspec [(const_int 0)] UNSPEC_NOP)]
1663 ;; The preceding splitter needs something to split the insn into;
1664 ;; things start breaking if the result is just a "use" so instead we
1665 ;; generate the following insn.
1666 (define_insn "*unspec_nop"
1667 [(unspec [(const_int 0)] UNSPEC_NOP)]
1670 [(set_attr "type" "nop")
1671 (set_attr "mode" "none")
1672 (set_attr "length" "0")])
1675 ;; Instructions for the Xtensa "boolean" option.
1677 (define_insn "*booltrue"
1679 (if_then_else (match_operator 2 "boolean_operator"
1680 [(match_operand:CC 0 "register_operand" "b")
1682 (label_ref (match_operand 1 "" ""))
1686 if (GET_CODE (operands[2]) == EQ)
1687 return "bf\t%0, %1";
1689 return "bt\t%0, %1";
1691 [(set_attr "type" "jump")
1692 (set_attr "mode" "none")
1693 (set_attr "length" "3")])
1695 (define_insn "*boolfalse"
1697 (if_then_else (match_operator 2 "boolean_operator"
1698 [(match_operand:CC 0 "register_operand" "b")
1701 (label_ref (match_operand 1 "" ""))))]
1704 if (GET_CODE (operands[2]) == EQ)
1705 return "bt\t%0, %1";
1707 return "bf\t%0, %1";
1709 [(set_attr "type" "jump")
1710 (set_attr "mode" "none")
1711 (set_attr "length" "3")])
1714 ;; Atomic operations
1716 (define_expand "memory_barrier"
1717 [(set (mem:BLK (match_dup 0))
1718 (unspec_volatile:BLK [(mem:BLK (match_dup 0))] UNSPECV_MEMW))]
1721 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (SImode));
1722 MEM_VOLATILE_P (operands[0]) = 1;
1725 (define_insn "*memory_barrier"
1726 [(set (match_operand:BLK 0 "" "")
1727 (unspec_volatile:BLK [(match_operand:BLK 1 "" "")] UNSPECV_MEMW))]
1730 [(set_attr "type" "unknown")
1731 (set_attr "mode" "none")
1732 (set_attr "length" "3")])
1734 ;; sync_lock_release is only implemented for SImode.
1735 ;; For other modes, just use the default of a store with a memory_barrier.
1736 (define_insn "sync_lock_releasesi"
1737 [(set (match_operand:SI 0 "mem_operand" "=U")
1739 [(match_operand:SI 1 "register_operand" "r")]
1741 "TARGET_RELEASE_SYNC"
1743 [(set_attr "type" "store")
1744 (set_attr "mode" "SI")
1745 (set_attr "length" "3")])
1747 (define_insn "sync_compare_and_swapsi"
1749 [(set (match_operand:SI 0 "register_operand" "=a")
1750 (match_operand:SI 1 "mem_operand" "+U"))
1754 (match_operand:SI 2 "register_operand" "r")
1755 (match_operand:SI 3 "register_operand" "0")]
1758 "wsr\t%2, SCOMPARE1\;s32c1i\t%3, %1"
1759 [(set_attr "type" "multi")
1760 (set_attr "mode" "SI")
1761 (set_attr "length" "6")])
1763 (define_expand "sync_compare_and_swap<mode>"
1765 [(set (match_operand:HQI 0 "register_operand" "")
1766 (match_operand:HQI 1 "mem_operand" ""))
1768 (unspec_volatile:HQI
1770 (match_operand:HQI 2 "register_operand" "")
1771 (match_operand:HQI 3 "register_operand" "")]
1775 xtensa_expand_compare_and_swap (operands[0], operands[1],
1776 operands[2], operands[3]);
1780 (define_expand "sync_lock_test_and_set<mode>"
1781 [(match_operand:HQI 0 "register_operand")
1782 (match_operand:HQI 1 "memory_operand")
1783 (match_operand:HQI 2 "register_operand")]
1786 xtensa_expand_atomic (SET, operands[0], operands[1], operands[2], false);
1790 (define_expand "sync_<atomic><mode>"
1791 [(set (match_operand:HQI 0 "memory_operand")
1792 (ATOMIC:HQI (match_dup 0)
1793 (match_operand:HQI 1 "register_operand")))]
1796 xtensa_expand_atomic (<CODE>, NULL_RTX, operands[0], operands[1], false);
1800 (define_expand "sync_old_<atomic><mode>"
1801 [(set (match_operand:HQI 0 "register_operand")
1802 (match_operand:HQI 1 "memory_operand"))
1804 (ATOMIC:HQI (match_dup 1)
1805 (match_operand:HQI 2 "register_operand")))]
1808 xtensa_expand_atomic (<CODE>, operands[0], operands[1], operands[2], false);
1812 (define_expand "sync_new_<atomic><mode>"
1813 [(set (match_operand:HQI 0 "register_operand")
1814 (ATOMIC:HQI (match_operand:HQI 1 "memory_operand")
1815 (match_operand:HQI 2 "register_operand")))
1816 (set (match_dup 1) (ATOMIC:HQI (match_dup 1) (match_dup 2)))]
1819 xtensa_expand_atomic (<CODE>, operands[0], operands[1], operands[2], true);