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/>.
48 ;; This code iterator allows signed and unsigned widening multiplications
49 ;; to use the same template.
50 (define_code_iterator any_extend [sign_extend zero_extend])
52 ;; <u> expands to an empty string when doing a signed operation and
53 ;; "u" when doing an unsigned operation.
54 (define_code_attr u [(sign_extend "") (zero_extend "u")])
56 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
57 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
59 ;; This code iterator allows four integer min/max operations to be
60 ;; generated from one template.
61 (define_code_iterator any_minmax [smin umin smax umax])
63 ;; <minmax> expands to the opcode name for any_minmax operations.
64 (define_code_attr minmax [(smin "min") (umin "minu")
65 (smax "max") (umax "maxu")])
67 ;; This code iterator allows all branch instructions to be generated from
68 ;; a single define_expand template.
69 (define_code_iterator any_cond [eq ne gt ge lt le gtu geu ltu leu
70 uneq ltgt ungt unge unlt unle
73 ;; This code iterator is for setting a register from a comparison.
74 (define_code_iterator any_scc [eq ne gt ge lt le])
76 ;; This code iterator is for floating-point comparisons.
77 (define_code_iterator any_scc_sf [eq lt le uneq unlt unle unordered])
78 (define_code_attr scc_sf [(eq "oeq") (lt "olt") (le "ole")
79 (uneq "ueq") (unlt "ult") (unle "ule")
82 ;; This iterator and attribute allow to combine most atomic operations.
83 (define_code_iterator ATOMIC [and ior xor plus minus mult])
84 (define_code_attr atomic [(and "and") (ior "ior") (xor "xor")
85 (plus "add") (minus "sub") (mult "nand")])
87 ;; This mode iterator allows the HI and QI patterns to be defined from
89 (define_mode_iterator HQI [HI QI])
95 "unknown,jump,call,load,store,move,arith,multi,nop,farith,fmadd,fdiv,fsqrt,fconv,fload,fstore,mul16,mul32,div32,mac16,rsr,wsr,entry"
96 (const_string "unknown"))
99 "unknown,none,QI,HI,SI,DI,SF,DF,BL"
100 (const_string "unknown"))
102 (define_attr "length" "" (const_int 1))
104 ;; Describe a user's asm statement.
105 (define_asm_attributes
106 [(set_attr "type" "multi")])
111 ;; The Xtensa basically has simple 5-stage RISC pipeline.
112 ;; Most instructions complete in 1 cycle, and it is OK to assume that
113 ;; everything is fully pipelined. The exceptions have special insn
114 ;; reservations in the pipeline description below. The Xtensa can
115 ;; issue one instruction per cycle, so defining CPU units is unnecessary.
117 (define_insn_reservation "xtensa_any_insn" 1
118 (eq_attr "type" "!load,fload,rsr,mul16,mul32,fmadd,fconv")
121 (define_insn_reservation "xtensa_memory" 2
122 (eq_attr "type" "load,fload")
125 (define_insn_reservation "xtensa_sreg" 2
126 (eq_attr "type" "rsr")
129 (define_insn_reservation "xtensa_mul16" 2
130 (eq_attr "type" "mul16")
133 (define_insn_reservation "xtensa_mul32" 2
134 (eq_attr "type" "mul32")
137 (define_insn_reservation "xtensa_fmadd" 4
138 (eq_attr "type" "fmadd")
141 (define_insn_reservation "xtensa_fconv" 2
142 (eq_attr "type" "fconv")
145 ;; Include predicates and constraints.
147 (include "predicates.md")
148 (include "constraints.md")
153 (define_insn "addsi3"
154 [(set (match_operand:SI 0 "register_operand" "=D,D,a,a,a")
155 (plus:SI (match_operand:SI 1 "register_operand" "%d,d,r,r,r")
156 (match_operand:SI 2 "add_operand" "d,O,r,J,N")))]
164 [(set_attr "type" "arith,arith,arith,arith,arith")
165 (set_attr "mode" "SI")
166 (set_attr "length" "2,2,3,3,3")])
169 [(set (match_operand:SI 0 "register_operand" "=a")
170 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
171 (match_operand:SI 3 "addsubx_operand" "i"))
172 (match_operand:SI 2 "register_operand" "r")))]
175 [(set_attr "type" "arith")
176 (set_attr "mode" "SI")
177 (set_attr "length" "3")])
179 (define_insn "addsf3"
180 [(set (match_operand:SF 0 "register_operand" "=f")
181 (plus:SF (match_operand:SF 1 "register_operand" "%f")
182 (match_operand:SF 2 "register_operand" "f")))]
185 [(set_attr "type" "fmadd")
186 (set_attr "mode" "SF")
187 (set_attr "length" "3")])
192 (define_insn "subsi3"
193 [(set (match_operand:SI 0 "register_operand" "=a")
194 (minus:SI (match_operand:SI 1 "register_operand" "r")
195 (match_operand:SI 2 "register_operand" "r")))]
198 [(set_attr "type" "arith")
199 (set_attr "mode" "SI")
200 (set_attr "length" "3")])
203 [(set (match_operand:SI 0 "register_operand" "=a")
204 (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
205 (match_operand:SI 3 "addsubx_operand" "i"))
206 (match_operand:SI 2 "register_operand" "r")))]
209 [(set_attr "type" "arith")
210 (set_attr "mode" "SI")
211 (set_attr "length" "3")])
213 (define_insn "subsf3"
214 [(set (match_operand:SF 0 "register_operand" "=f")
215 (minus:SF (match_operand:SF 1 "register_operand" "f")
216 (match_operand:SF 2 "register_operand" "f")))]
219 [(set_attr "type" "fmadd")
220 (set_attr "mode" "SF")
221 (set_attr "length" "3")])
226 (define_expand "<u>mulsidi3"
227 [(set (match_operand:DI 0 "register_operand")
228 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
229 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
232 rtx temp = gen_reg_rtx (SImode);
233 emit_insn (gen_mulsi3 (temp, operands[1], operands[2]));
234 emit_insn (gen_<u>mulsi3_highpart (gen_highpart (SImode, operands[0]),
235 operands[1], operands[2]));
236 emit_insn (gen_movsi (gen_lowpart (SImode, operands[0]), temp));
240 (define_insn "<u>mulsi3_highpart"
241 [(set (match_operand:SI 0 "register_operand" "=a")
244 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "%r"))
245 (any_extend:DI (match_operand:SI 2 "register_operand" "r")))
248 "mul<su>h\t%0, %1, %2"
249 [(set_attr "type" "mul32")
250 (set_attr "mode" "SI")
251 (set_attr "length" "3")])
253 (define_insn "mulsi3"
254 [(set (match_operand:SI 0 "register_operand" "=a")
255 (mult:SI (match_operand:SI 1 "register_operand" "%r")
256 (match_operand:SI 2 "register_operand" "r")))]
259 [(set_attr "type" "mul32")
260 (set_attr "mode" "SI")
261 (set_attr "length" "3")])
263 (define_insn "mulhisi3"
264 [(set (match_operand:SI 0 "register_operand" "=C,A")
265 (mult:SI (sign_extend:SI
266 (match_operand:HI 1 "register_operand" "%r,r"))
268 (match_operand:HI 2 "register_operand" "r,r"))))]
269 "TARGET_MUL16 || TARGET_MAC16"
273 [(set_attr "type" "mul16,mac16")
274 (set_attr "mode" "SI")
275 (set_attr "length" "3,3")])
277 (define_insn "umulhisi3"
278 [(set (match_operand:SI 0 "register_operand" "=C,A")
279 (mult:SI (zero_extend:SI
280 (match_operand:HI 1 "register_operand" "%r,r"))
282 (match_operand:HI 2 "register_operand" "r,r"))))]
283 "TARGET_MUL16 || TARGET_MAC16"
287 [(set_attr "type" "mul16,mac16")
288 (set_attr "mode" "SI")
289 (set_attr "length" "3,3")])
291 (define_insn "muladdhisi"
292 [(set (match_operand:SI 0 "register_operand" "=A")
293 (plus:SI (mult:SI (sign_extend:SI
294 (match_operand:HI 1 "register_operand" "%r"))
296 (match_operand:HI 2 "register_operand" "r")))
297 (match_operand:SI 3 "register_operand" "0")))]
300 [(set_attr "type" "mac16")
301 (set_attr "mode" "SI")
302 (set_attr "length" "3")])
304 (define_insn "mulsubhisi"
305 [(set (match_operand:SI 0 "register_operand" "=A")
306 (minus:SI (match_operand:SI 1 "register_operand" "0")
307 (mult:SI (sign_extend:SI
308 (match_operand:HI 2 "register_operand" "%r"))
310 (match_operand:HI 3 "register_operand" "r")))))]
313 [(set_attr "type" "mac16")
314 (set_attr "mode" "SI")
315 (set_attr "length" "3")])
317 (define_insn "mulsf3"
318 [(set (match_operand:SF 0 "register_operand" "=f")
319 (mult:SF (match_operand:SF 1 "register_operand" "%f")
320 (match_operand:SF 2 "register_operand" "f")))]
323 [(set_attr "type" "fmadd")
324 (set_attr "mode" "SF")
325 (set_attr "length" "3")])
327 (define_insn "muladdsf3"
328 [(set (match_operand:SF 0 "register_operand" "=f")
329 (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "%f")
330 (match_operand:SF 2 "register_operand" "f"))
331 (match_operand:SF 3 "register_operand" "0")))]
332 "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
334 [(set_attr "type" "fmadd")
335 (set_attr "mode" "SF")
336 (set_attr "length" "3")])
338 (define_insn "mulsubsf3"
339 [(set (match_operand:SF 0 "register_operand" "=f")
340 (minus:SF (match_operand:SF 1 "register_operand" "0")
341 (mult:SF (match_operand:SF 2 "register_operand" "%f")
342 (match_operand:SF 3 "register_operand" "f"))))]
343 "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
345 [(set_attr "type" "fmadd")
346 (set_attr "mode" "SF")
347 (set_attr "length" "3")])
352 (define_insn "divsi3"
353 [(set (match_operand:SI 0 "register_operand" "=a")
354 (div:SI (match_operand:SI 1 "register_operand" "r")
355 (match_operand:SI 2 "register_operand" "r")))]
358 [(set_attr "type" "div32")
359 (set_attr "mode" "SI")
360 (set_attr "length" "3")])
362 (define_insn "udivsi3"
363 [(set (match_operand:SI 0 "register_operand" "=a")
364 (udiv:SI (match_operand:SI 1 "register_operand" "r")
365 (match_operand:SI 2 "register_operand" "r")))]
368 [(set_attr "type" "div32")
369 (set_attr "mode" "SI")
370 (set_attr "length" "3")])
372 (define_insn "divsf3"
373 [(set (match_operand:SF 0 "register_operand" "=f")
374 (div:SF (match_operand:SF 1 "register_operand" "f")
375 (match_operand:SF 2 "register_operand" "f")))]
376 "TARGET_HARD_FLOAT_DIV"
378 [(set_attr "type" "fdiv")
379 (set_attr "mode" "SF")
380 (set_attr "length" "3")])
382 (define_insn "*recipsf2"
383 [(set (match_operand:SF 0 "register_operand" "=f")
384 (div:SF (match_operand:SF 1 "const_float_1_operand" "")
385 (match_operand:SF 2 "register_operand" "f")))]
386 "TARGET_HARD_FLOAT_RECIP && flag_unsafe_math_optimizations"
388 [(set_attr "type" "fdiv")
389 (set_attr "mode" "SF")
390 (set_attr "length" "3")])
395 (define_insn "modsi3"
396 [(set (match_operand:SI 0 "register_operand" "=a")
397 (mod:SI (match_operand:SI 1 "register_operand" "r")
398 (match_operand:SI 2 "register_operand" "r")))]
401 [(set_attr "type" "div32")
402 (set_attr "mode" "SI")
403 (set_attr "length" "3")])
405 (define_insn "umodsi3"
406 [(set (match_operand:SI 0 "register_operand" "=a")
407 (umod:SI (match_operand:SI 1 "register_operand" "r")
408 (match_operand:SI 2 "register_operand" "r")))]
411 [(set_attr "type" "div32")
412 (set_attr "mode" "SI")
413 (set_attr "length" "3")])
418 (define_insn "sqrtsf2"
419 [(set (match_operand:SF 0 "register_operand" "=f")
420 (sqrt:SF (match_operand:SF 1 "register_operand" "f")))]
421 "TARGET_HARD_FLOAT_SQRT"
423 [(set_attr "type" "fsqrt")
424 (set_attr "mode" "SF")
425 (set_attr "length" "3")])
427 (define_insn "*rsqrtsf2"
428 [(set (match_operand:SF 0 "register_operand" "=f")
429 (div:SF (match_operand:SF 1 "const_float_1_operand" "")
430 (sqrt:SF (match_operand:SF 2 "register_operand" "f"))))]
431 "TARGET_HARD_FLOAT_RSQRT && flag_unsafe_math_optimizations"
433 [(set_attr "type" "fsqrt")
434 (set_attr "mode" "SF")
435 (set_attr "length" "3")])
440 (define_insn "abssi2"
441 [(set (match_operand:SI 0 "register_operand" "=a")
442 (abs:SI (match_operand:SI 1 "register_operand" "r")))]
445 [(set_attr "type" "arith")
446 (set_attr "mode" "SI")
447 (set_attr "length" "3")])
449 (define_insn "abssf2"
450 [(set (match_operand:SF 0 "register_operand" "=f")
451 (abs:SF (match_operand:SF 1 "register_operand" "f")))]
454 [(set_attr "type" "farith")
455 (set_attr "mode" "SF")
456 (set_attr "length" "3")])
461 (define_insn "<code>si3"
462 [(set (match_operand:SI 0 "register_operand" "=a")
463 (any_minmax:SI (match_operand:SI 1 "register_operand" "%r")
464 (match_operand:SI 2 "register_operand" "r")))]
466 "<minmax>\t%0, %1, %2"
467 [(set_attr "type" "arith")
468 (set_attr "mode" "SI")
469 (set_attr "length" "3")])
472 ;; Count leading/trailing zeros and find first bit.
474 (define_insn "clzsi2"
475 [(set (match_operand:SI 0 "register_operand" "=a")
476 (clz:SI (match_operand:SI 1 "register_operand" "r")))]
479 [(set_attr "type" "arith")
480 (set_attr "mode" "SI")
481 (set_attr "length" "3")])
483 (define_expand "ctzsi2"
484 [(set (match_operand:SI 0 "register_operand" "")
485 (ctz:SI (match_operand:SI 1 "register_operand" "")))]
488 rtx temp = gen_reg_rtx (SImode);
489 emit_insn (gen_negsi2 (temp, operands[1]));
490 emit_insn (gen_andsi3 (temp, temp, operands[1]));
491 emit_insn (gen_clzsi2 (temp, temp));
492 emit_insn (gen_negsi2 (temp, temp));
493 emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (31)));
497 (define_expand "ffssi2"
498 [(set (match_operand:SI 0 "register_operand" "")
499 (ffs:SI (match_operand:SI 1 "register_operand" "")))]
502 rtx temp = gen_reg_rtx (SImode);
503 emit_insn (gen_negsi2 (temp, operands[1]));
504 emit_insn (gen_andsi3 (temp, temp, operands[1]));
505 emit_insn (gen_clzsi2 (temp, temp));
506 emit_insn (gen_negsi2 (temp, temp));
507 emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (32)));
512 ;; Negation and one's complement.
514 (define_insn "negsi2"
515 [(set (match_operand:SI 0 "register_operand" "=a")
516 (neg:SI (match_operand:SI 1 "register_operand" "r")))]
519 [(set_attr "type" "arith")
520 (set_attr "mode" "SI")
521 (set_attr "length" "3")])
523 (define_expand "one_cmplsi2"
524 [(set (match_operand:SI 0 "register_operand" "")
525 (not:SI (match_operand:SI 1 "register_operand" "")))]
528 rtx temp = gen_reg_rtx (SImode);
529 emit_insn (gen_movsi (temp, constm1_rtx));
530 emit_insn (gen_xorsi3 (operands[0], temp, operands[1]));
534 (define_insn "negsf2"
535 [(set (match_operand:SF 0 "register_operand" "=f")
536 (neg:SF (match_operand:SF 1 "register_operand" "f")))]
539 [(set_attr "type" "farith")
540 (set_attr "mode" "SF")
541 (set_attr "length" "3")])
544 ;; Logical instructions.
546 (define_insn "andsi3"
547 [(set (match_operand:SI 0 "register_operand" "=a,a")
548 (and:SI (match_operand:SI 1 "register_operand" "%r,r")
549 (match_operand:SI 2 "mask_operand" "P,r")))]
552 extui\t%0, %1, 0, %K2
554 [(set_attr "type" "arith,arith")
555 (set_attr "mode" "SI")
556 (set_attr "length" "3,3")])
558 (define_insn "iorsi3"
559 [(set (match_operand:SI 0 "register_operand" "=a")
560 (ior:SI (match_operand:SI 1 "register_operand" "%r")
561 (match_operand:SI 2 "register_operand" "r")))]
564 [(set_attr "type" "arith")
565 (set_attr "mode" "SI")
566 (set_attr "length" "3")])
568 (define_insn "xorsi3"
569 [(set (match_operand:SI 0 "register_operand" "=a")
570 (xor:SI (match_operand:SI 1 "register_operand" "%r")
571 (match_operand:SI 2 "register_operand" "r")))]
574 [(set_attr "type" "arith")
575 (set_attr "mode" "SI")
576 (set_attr "length" "3")])
579 ;; Zero-extend instructions.
581 (define_insn "zero_extendhisi2"
582 [(set (match_operand:SI 0 "register_operand" "=a,a")
583 (zero_extend:SI (match_operand:HI 1 "nonimmed_operand" "r,U")))]
588 [(set_attr "type" "arith,load")
589 (set_attr "mode" "SI")
590 (set_attr "length" "3,3")])
592 (define_insn "zero_extendqisi2"
593 [(set (match_operand:SI 0 "register_operand" "=a,a")
594 (zero_extend:SI (match_operand:QI 1 "nonimmed_operand" "r,U")))]
599 [(set_attr "type" "arith,load")
600 (set_attr "mode" "SI")
601 (set_attr "length" "3,3")])
604 ;; Sign-extend instructions.
606 (define_expand "extendhisi2"
607 [(set (match_operand:SI 0 "register_operand" "")
608 (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
611 if (sext_operand (operands[1], HImode))
612 emit_insn (gen_extendhisi2_internal (operands[0], operands[1]));
614 xtensa_extend_reg (operands[0], operands[1]);
618 (define_insn "extendhisi2_internal"
619 [(set (match_operand:SI 0 "register_operand" "=B,a")
620 (sign_extend:SI (match_operand:HI 1 "sext_operand" "r,U")))]
625 [(set_attr "type" "arith,load")
626 (set_attr "mode" "SI")
627 (set_attr "length" "3,3")])
629 (define_expand "extendqisi2"
630 [(set (match_operand:SI 0 "register_operand" "")
631 (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
635 emit_insn (gen_extendqisi2_internal (operands[0], operands[1]));
637 xtensa_extend_reg (operands[0], operands[1]);
641 (define_insn "extendqisi2_internal"
642 [(set (match_operand:SI 0 "register_operand" "=B")
643 (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
646 [(set_attr "type" "arith")
647 (set_attr "mode" "SI")
648 (set_attr "length" "3")])
651 ;; Field extract instructions.
653 (define_expand "extv"
654 [(set (match_operand:SI 0 "register_operand" "")
655 (sign_extract:SI (match_operand:SI 1 "register_operand" "")
656 (match_operand:SI 2 "const_int_operand" "")
657 (match_operand:SI 3 "const_int_operand" "")))]
660 if (!sext_fldsz_operand (operands[2], SImode))
663 /* We could expand to a right shift followed by SEXT but that's
664 no better than the standard left and right shift sequence. */
665 if (!lsbitnum_operand (operands[3], SImode))
668 emit_insn (gen_extv_internal (operands[0], operands[1],
669 operands[2], operands[3]));
673 (define_insn "extv_internal"
674 [(set (match_operand:SI 0 "register_operand" "=a")
675 (sign_extract:SI (match_operand:SI 1 "register_operand" "r")
676 (match_operand:SI 2 "sext_fldsz_operand" "i")
677 (match_operand:SI 3 "lsbitnum_operand" "i")))]
680 int fldsz = INTVAL (operands[2]);
681 operands[2] = GEN_INT (fldsz - 1);
682 return "sext\t%0, %1, %2";
684 [(set_attr "type" "arith")
685 (set_attr "mode" "SI")
686 (set_attr "length" "3")])
688 (define_expand "extzv"
689 [(set (match_operand:SI 0 "register_operand" "")
690 (zero_extract:SI (match_operand:SI 1 "register_operand" "")
691 (match_operand:SI 2 "const_int_operand" "")
692 (match_operand:SI 3 "const_int_operand" "")))]
695 if (!extui_fldsz_operand (operands[2], SImode))
697 emit_insn (gen_extzv_internal (operands[0], operands[1],
698 operands[2], operands[3]));
702 (define_insn "extzv_internal"
703 [(set (match_operand:SI 0 "register_operand" "=a")
704 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
705 (match_operand:SI 2 "extui_fldsz_operand" "i")
706 (match_operand:SI 3 "const_int_operand" "i")))]
711 shift = (32 - (INTVAL (operands[2]) + INTVAL (operands[3]))) & 0x1f;
713 shift = INTVAL (operands[3]) & 0x1f;
714 operands[3] = GEN_INT (shift);
715 return "extui\t%0, %1, %3, %2";
717 [(set_attr "type" "arith")
718 (set_attr "mode" "SI")
719 (set_attr "length" "3")])
724 (define_insn "fix_truncsfsi2"
725 [(set (match_operand:SI 0 "register_operand" "=a")
726 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
729 [(set_attr "type" "fconv")
730 (set_attr "mode" "SF")
731 (set_attr "length" "3")])
733 (define_insn "fixuns_truncsfsi2"
734 [(set (match_operand:SI 0 "register_operand" "=a")
735 (unsigned_fix:SI (match_operand:SF 1 "register_operand" "f")))]
737 "utrunc.s\t%0, %1, 0"
738 [(set_attr "type" "fconv")
739 (set_attr "mode" "SF")
740 (set_attr "length" "3")])
742 (define_insn "floatsisf2"
743 [(set (match_operand:SF 0 "register_operand" "=f")
744 (float:SF (match_operand:SI 1 "register_operand" "a")))]
747 [(set_attr "type" "fconv")
748 (set_attr "mode" "SF")
749 (set_attr "length" "3")])
751 (define_insn "floatunssisf2"
752 [(set (match_operand:SF 0 "register_operand" "=f")
753 (unsigned_float:SF (match_operand:SI 1 "register_operand" "a")))]
755 "ufloat.s\t%0, %1, 0"
756 [(set_attr "type" "fconv")
757 (set_attr "mode" "SF")
758 (set_attr "length" "3")])
761 ;; Data movement instructions.
763 ;; 64-bit Integer moves
765 (define_expand "movdi"
766 [(set (match_operand:DI 0 "nonimmed_operand" "")
767 (match_operand:DI 1 "general_operand" ""))]
770 if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
771 operands[1] = force_const_mem (DImode, operands[1]);
773 if (!register_operand (operands[0], DImode)
774 && !register_operand (operands[1], DImode))
775 operands[1] = force_reg (DImode, operands[1]);
777 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
780 (define_insn_and_split "movdi_internal"
781 [(set (match_operand:DI 0 "nonimmed_operand" "=a,W,a,a,U")
782 (match_operand:DI 1 "move_operand" "r,i,T,U,r"))]
783 "register_operand (operands[0], DImode)
784 || register_operand (operands[1], DImode)"
787 [(set (match_dup 0) (match_dup 2))
788 (set (match_dup 1) (match_dup 3))]
790 xtensa_split_operand_pair (operands, SImode);
791 if (reg_overlap_mentioned_p (operands[0], operands[3]))
794 tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
795 tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
799 ;; 32-bit Integer moves
801 (define_expand "movsi"
802 [(set (match_operand:SI 0 "nonimmed_operand" "")
803 (match_operand:SI 1 "general_operand" ""))]
806 if (xtensa_emit_move_sequence (operands, SImode))
810 (define_insn "movsi_internal"
811 [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,W,a,a,U,*a,*A")
812 (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,i,T,U,r,*A,*r"))]
813 "xtensa_valid_move (SImode, operands)"
824 const16\t%0, %t1\;const16\t%0, %b1
830 [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,load,load,store,rsr,wsr")
831 (set_attr "mode" "SI")
832 (set_attr "length" "2,2,2,2,2,2,3,3,3,6,3,3,3,3,3")])
834 ;; 16-bit Integer moves
836 (define_expand "movhi"
837 [(set (match_operand:HI 0 "nonimmed_operand" "")
838 (match_operand:HI 1 "general_operand" ""))]
841 if (xtensa_emit_move_sequence (operands, HImode))
845 (define_insn "movhi_internal"
846 [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
847 (match_operand:HI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
848 "xtensa_valid_move (HImode, operands)"
858 [(set_attr "type" "move,move,move,move,load,store,rsr,wsr")
859 (set_attr "mode" "HI")
860 (set_attr "length" "2,2,3,3,3,3,3,3")])
862 ;; 8-bit Integer moves
864 (define_expand "movqi"
865 [(set (match_operand:QI 0 "nonimmed_operand" "")
866 (match_operand:QI 1 "general_operand" ""))]
869 if (xtensa_emit_move_sequence (operands, QImode))
873 (define_insn "movqi_internal"
874 [(set (match_operand:QI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
875 (match_operand:QI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
876 "xtensa_valid_move (QImode, operands)"
886 [(set_attr "type" "move,move,move,move,load,store,rsr,wsr")
887 (set_attr "mode" "QI")
888 (set_attr "length" "2,2,3,3,3,3,3,3")])
890 ;; Sub-word reloads from the constant pool.
892 (define_expand "reload<mode>_literal"
893 [(parallel [(match_operand:HQI 0 "register_operand" "=r")
894 (match_operand:HQI 1 "constantpool_operand" "")
895 (match_operand:SI 2 "register_operand" "=&r")])]
899 unsigned word_off, byte_off;
901 gcc_assert (GET_CODE (operands[1]) == SUBREG);
902 lit = SUBREG_REG (operands[1]);
903 scratch = operands[2];
904 word_off = SUBREG_BYTE (operands[1]) & ~(UNITS_PER_WORD - 1);
905 byte_off = SUBREG_BYTE (operands[1]) - word_off;
907 lit = adjust_address (lit, SImode, word_off);
908 emit_insn (gen_movsi (scratch, lit));
909 emit_insn (gen_mov<mode> (operands[0],
910 gen_rtx_SUBREG (<MODE>mode, scratch, byte_off)));
915 ;; 32-bit floating point moves
917 (define_expand "movsf"
918 [(set (match_operand:SF 0 "nonimmed_operand" "")
919 (match_operand:SF 1 "general_operand" ""))]
922 if (!TARGET_CONST16 && CONSTANT_P (operands[1]))
923 operands[1] = force_const_mem (SFmode, operands[1]);
925 if ((!register_operand (operands[0], SFmode)
926 && !register_operand (operands[1], SFmode))
927 || (FP_REG_P (xt_true_regnum (operands[0]))
928 && !(reload_in_progress | reload_completed)
929 && (constantpool_mem_p (operands[1])
930 || CONSTANT_P (operands[1]))))
931 operands[1] = force_reg (SFmode, operands[1]);
933 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
936 (define_insn "movsf_internal"
937 [(set (match_operand:SF 0 "nonimmed_operand" "=f,f,U,D,D,R,a,f,a,W,a,a,U")
938 (match_operand:SF 1 "move_operand" "f,U,f,d,R,d,r,r,f,iF,T,U,r"))]
939 "((register_operand (operands[0], SFmode)
940 || register_operand (operands[1], SFmode))
941 && !(FP_REG_P (xt_true_regnum (operands[0]))
942 && (constantpool_mem_p (operands[1]) || CONSTANT_P (operands[1]))))"
953 const16\t%0, %t1\;const16\t%0, %b1
957 [(set_attr "type" "farith,fload,fstore,move,load,store,move,farith,farith,move,load,load,store")
958 (set_attr "mode" "SF")
959 (set_attr "length" "3,3,3,2,2,2,3,3,3,6,3,3,3")])
962 [(set (match_operand:SF 0 "register_operand" "=f")
963 (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "+a")
964 (match_operand:SI 2 "fpmem_offset_operand" "i"))))
966 (plus:SI (match_dup 1) (match_dup 2)))]
969 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
970 output_asm_insn ("memw", operands);
971 return "lsiu\t%0, %1, %2";
973 [(set_attr "type" "fload")
974 (set_attr "mode" "SF")
975 (set_attr "length" "3")])
978 [(set (mem:SF (plus:SI (match_operand:SI 0 "register_operand" "+a")
979 (match_operand:SI 1 "fpmem_offset_operand" "i")))
980 (match_operand:SF 2 "register_operand" "f"))
982 (plus:SI (match_dup 0) (match_dup 1)))]
985 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
986 output_asm_insn ("memw", operands);
987 return "ssiu\t%2, %0, %1";
989 [(set_attr "type" "fstore")
990 (set_attr "mode" "SF")
991 (set_attr "length" "3")])
993 ;; 64-bit floating point moves
995 (define_expand "movdf"
996 [(set (match_operand:DF 0 "nonimmed_operand" "")
997 (match_operand:DF 1 "general_operand" ""))]
1000 if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
1001 operands[1] = force_const_mem (DFmode, operands[1]);
1003 if (!register_operand (operands[0], DFmode)
1004 && !register_operand (operands[1], DFmode))
1005 operands[1] = force_reg (DFmode, operands[1]);
1007 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1010 (define_insn_and_split "movdf_internal"
1011 [(set (match_operand:DF 0 "nonimmed_operand" "=a,W,a,a,U")
1012 (match_operand:DF 1 "move_operand" "r,iF,T,U,r"))]
1013 "register_operand (operands[0], DFmode)
1014 || register_operand (operands[1], DFmode)"
1017 [(set (match_dup 0) (match_dup 2))
1018 (set (match_dup 1) (match_dup 3))]
1020 xtensa_split_operand_pair (operands, SFmode);
1021 if (reg_overlap_mentioned_p (operands[0], operands[3]))
1024 tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
1025 tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
1031 (define_expand "movmemsi"
1032 [(parallel [(set (match_operand:BLK 0 "" "")
1033 (match_operand:BLK 1 "" ""))
1034 (use (match_operand:SI 2 "arith_operand" ""))
1035 (use (match_operand:SI 3 "const_int_operand" ""))])]
1038 if (!xtensa_expand_block_move (operands))
1044 ;; Shift instructions.
1046 (define_expand "ashlsi3"
1047 [(set (match_operand:SI 0 "register_operand" "")
1048 (ashift:SI (match_operand:SI 1 "register_operand" "")
1049 (match_operand:SI 2 "arith_operand" "")))]
1052 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1055 (define_insn "ashlsi3_internal"
1056 [(set (match_operand:SI 0 "register_operand" "=a,a")
1057 (ashift:SI (match_operand:SI 1 "register_operand" "r,r")
1058 (match_operand:SI 2 "arith_operand" "J,r")))]
1062 ssl\t%2\;sll\t%0, %1"
1063 [(set_attr "type" "arith,arith")
1064 (set_attr "mode" "SI")
1065 (set_attr "length" "3,6")])
1067 (define_insn "ashrsi3"
1068 [(set (match_operand:SI 0 "register_operand" "=a,a")
1069 (ashiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1070 (match_operand:SI 2 "arith_operand" "J,r")))]
1074 ssr\t%2\;sra\t%0, %1"
1075 [(set_attr "type" "arith,arith")
1076 (set_attr "mode" "SI")
1077 (set_attr "length" "3,6")])
1079 (define_insn "lshrsi3"
1080 [(set (match_operand:SI 0 "register_operand" "=a,a")
1081 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1082 (match_operand:SI 2 "arith_operand" "J,r")))]
1085 if (which_alternative == 0)
1087 if ((INTVAL (operands[2]) & 0x1f) < 16)
1088 return "srli\t%0, %1, %R2";
1090 return "extui\t%0, %1, %R2, %L2";
1092 return "ssr\t%2\;srl\t%0, %1";
1094 [(set_attr "type" "arith,arith")
1095 (set_attr "mode" "SI")
1096 (set_attr "length" "3,6")])
1098 (define_insn "rotlsi3"
1099 [(set (match_operand:SI 0 "register_operand" "=a,a")
1100 (rotate:SI (match_operand:SI 1 "register_operand" "r,r")
1101 (match_operand:SI 2 "arith_operand" "J,r")))]
1104 ssai\t%L2\;src\t%0, %1, %1
1105 ssl\t%2\;src\t%0, %1, %1"
1106 [(set_attr "type" "multi,multi")
1107 (set_attr "mode" "SI")
1108 (set_attr "length" "6,6")])
1110 (define_insn "rotrsi3"
1111 [(set (match_operand:SI 0 "register_operand" "=a,a")
1112 (rotatert:SI (match_operand:SI 1 "register_operand" "r,r")
1113 (match_operand:SI 2 "arith_operand" "J,r")))]
1116 ssai\t%R2\;src\t%0, %1, %1
1117 ssr\t%2\;src\t%0, %1, %1"
1118 [(set_attr "type" "multi,multi")
1119 (set_attr "mode" "SI")
1120 (set_attr "length" "6,6")])
1125 ;; Handle comparisons by stashing away the operands and then using that
1126 ;; information in the subsequent conditional branch.
1128 (define_expand "cmpsi"
1130 (compare:CC (match_operand:SI 0 "register_operand" "")
1131 (match_operand:SI 1 "nonmemory_operand" "")))]
1134 branch_cmp[0] = operands[0];
1135 branch_cmp[1] = operands[1];
1136 branch_type = CMP_SI;
1140 (define_expand "cmpsf"
1142 (compare:CC (match_operand:SF 0 "register_operand" "")
1143 (match_operand:SF 1 "register_operand" "")))]
1146 branch_cmp[0] = operands[0];
1147 branch_cmp[1] = operands[1];
1148 branch_type = CMP_SF;
1153 ;; Conditional branches.
1155 (define_expand "b<code>"
1157 (if_then_else (any_cond (cc0) (const_int 0))
1158 (label_ref (match_operand 0 "" ""))
1162 xtensa_expand_conditional_branch (operands, <CODE>);
1166 ;; Branch patterns for standard integer comparisons
1168 (define_insn "*btrue"
1170 (if_then_else (match_operator 3 "branch_operator"
1171 [(match_operand:SI 0 "register_operand" "r,r")
1172 (match_operand:SI 1 "branch_operand" "K,r")])
1173 (label_ref (match_operand 2 "" ""))
1177 return xtensa_emit_branch (false, which_alternative == 0, operands);
1179 [(set_attr "type" "jump,jump")
1180 (set_attr "mode" "none")
1181 (set_attr "length" "3,3")])
1183 (define_insn "*bfalse"
1185 (if_then_else (match_operator 3 "branch_operator"
1186 [(match_operand:SI 0 "register_operand" "r,r")
1187 (match_operand:SI 1 "branch_operand" "K,r")])
1189 (label_ref (match_operand 2 "" ""))))]
1192 return xtensa_emit_branch (true, which_alternative == 0, operands);
1194 [(set_attr "type" "jump,jump")
1195 (set_attr "mode" "none")
1196 (set_attr "length" "3,3")])
1198 (define_insn "*ubtrue"
1200 (if_then_else (match_operator 3 "ubranch_operator"
1201 [(match_operand:SI 0 "register_operand" "r,r")
1202 (match_operand:SI 1 "ubranch_operand" "L,r")])
1203 (label_ref (match_operand 2 "" ""))
1207 return xtensa_emit_branch (false, which_alternative == 0, operands);
1209 [(set_attr "type" "jump,jump")
1210 (set_attr "mode" "none")
1211 (set_attr "length" "3,3")])
1213 (define_insn "*ubfalse"
1215 (if_then_else (match_operator 3 "ubranch_operator"
1216 [(match_operand:SI 0 "register_operand" "r,r")
1217 (match_operand:SI 1 "ubranch_operand" "L,r")])
1219 (label_ref (match_operand 2 "" ""))))]
1222 return xtensa_emit_branch (true, which_alternative == 0, operands);
1224 [(set_attr "type" "jump,jump")
1225 (set_attr "mode" "none")
1226 (set_attr "length" "3,3")])
1228 ;; Branch patterns for bit testing
1230 (define_insn "*bittrue"
1232 (if_then_else (match_operator 3 "boolean_operator"
1234 (match_operand:SI 0 "register_operand" "r,r")
1236 (match_operand:SI 1 "arith_operand" "J,r"))
1238 (label_ref (match_operand 2 "" ""))
1242 return xtensa_emit_bit_branch (false, which_alternative == 0, operands);
1244 [(set_attr "type" "jump")
1245 (set_attr "mode" "none")
1246 (set_attr "length" "3")])
1248 (define_insn "*bitfalse"
1250 (if_then_else (match_operator 3 "boolean_operator"
1252 (match_operand:SI 0 "register_operand" "r,r")
1254 (match_operand:SI 1 "arith_operand" "J,r"))
1257 (label_ref (match_operand 2 "" ""))))]
1260 return xtensa_emit_bit_branch (true, which_alternative == 0, operands);
1262 [(set_attr "type" "jump")
1263 (set_attr "mode" "none")
1264 (set_attr "length" "3")])
1266 (define_insn "*masktrue"
1268 (if_then_else (match_operator 3 "boolean_operator"
1269 [(and:SI (match_operand:SI 0 "register_operand" "r")
1270 (match_operand:SI 1 "register_operand" "r"))
1272 (label_ref (match_operand 2 "" ""))
1276 switch (GET_CODE (operands[3]))
1278 case EQ: return "bnone\t%0, %1, %2";
1279 case NE: return "bany\t%0, %1, %2";
1280 default: gcc_unreachable ();
1283 [(set_attr "type" "jump")
1284 (set_attr "mode" "none")
1285 (set_attr "length" "3")])
1287 (define_insn "*maskfalse"
1289 (if_then_else (match_operator 3 "boolean_operator"
1290 [(and:SI (match_operand:SI 0 "register_operand" "r")
1291 (match_operand:SI 1 "register_operand" "r"))
1294 (label_ref (match_operand 2 "" ""))))]
1297 switch (GET_CODE (operands[3]))
1299 case EQ: return "bany\t%0, %1, %2";
1300 case NE: return "bnone\t%0, %1, %2";
1301 default: gcc_unreachable ();
1304 [(set_attr "type" "jump")
1305 (set_attr "mode" "none")
1306 (set_attr "length" "3")])
1309 ;; Define the loop insns used by bct optimization to represent the
1310 ;; start and end of a zero-overhead loop (in loop.c). This start
1311 ;; template generates the loop insn; the end template doesn't generate
1312 ;; any instructions since loop end is handled in hardware.
1314 (define_insn "zero_cost_loop_start"
1316 (if_then_else (eq (match_operand:SI 0 "register_operand" "a")
1318 (label_ref (match_operand 1 "" ""))
1321 (plus:SI (match_dup 0) (const_int -1)))]
1324 [(set_attr "type" "jump")
1325 (set_attr "mode" "none")
1326 (set_attr "length" "3")])
1328 (define_insn "zero_cost_loop_end"
1330 (if_then_else (ne (reg:SI 19) (const_int 0))
1331 (label_ref (match_operand 0 "" ""))
1334 (plus:SI (reg:SI 19) (const_int -1)))]
1337 xtensa_emit_loop_end (insn, operands);
1340 [(set_attr "type" "jump")
1341 (set_attr "mode" "none")
1342 (set_attr "length" "0")])
1345 ;; Setting a register from a comparison.
1347 (define_expand "s<code>"
1348 [(set (match_operand:SI 0 "register_operand" "")
1349 (any_scc:SI (match_dup 1)
1353 operands[1] = gen_rtx_<CODE> (SImode, branch_cmp[0], branch_cmp[1]);
1354 if (!xtensa_expand_scc (operands))
1360 ;; Conditional moves.
1362 (define_expand "movsicc"
1363 [(set (match_operand:SI 0 "register_operand" "")
1364 (if_then_else:SI (match_operand 1 "comparison_operator" "")
1365 (match_operand:SI 2 "register_operand" "")
1366 (match_operand:SI 3 "register_operand" "")))]
1369 if (!xtensa_expand_conditional_move (operands, 0))
1374 (define_expand "movsfcc"
1375 [(set (match_operand:SF 0 "register_operand" "")
1376 (if_then_else:SF (match_operand 1 "comparison_operator" "")
1377 (match_operand:SF 2 "register_operand" "")
1378 (match_operand:SF 3 "register_operand" "")))]
1381 if (!xtensa_expand_conditional_move (operands, 1))
1386 (define_insn "movsicc_internal0"
1387 [(set (match_operand:SI 0 "register_operand" "=a,a")
1388 (if_then_else:SI (match_operator 4 "branch_operator"
1389 [(match_operand:SI 1 "register_operand" "r,r")
1391 (match_operand:SI 2 "register_operand" "r,0")
1392 (match_operand:SI 3 "register_operand" "0,r")))]
1395 return xtensa_emit_movcc (which_alternative == 1, false, false, operands);
1397 [(set_attr "type" "move,move")
1398 (set_attr "mode" "SI")
1399 (set_attr "length" "3,3")])
1401 (define_insn "movsicc_internal1"
1402 [(set (match_operand:SI 0 "register_operand" "=a,a")
1403 (if_then_else:SI (match_operator 4 "boolean_operator"
1404 [(match_operand:CC 1 "register_operand" "b,b")
1406 (match_operand:SI 2 "register_operand" "r,0")
1407 (match_operand:SI 3 "register_operand" "0,r")))]
1410 return xtensa_emit_movcc (which_alternative == 1, false, true, operands);
1412 [(set_attr "type" "move,move")
1413 (set_attr "mode" "SI")
1414 (set_attr "length" "3,3")])
1416 (define_insn "movsfcc_internal0"
1417 [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1418 (if_then_else:SF (match_operator 4 "branch_operator"
1419 [(match_operand:SI 1 "register_operand" "r,r,r,r")
1421 (match_operand:SF 2 "register_operand" "r,0,f,0")
1422 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1425 return xtensa_emit_movcc ((which_alternative & 1) == 1,
1426 which_alternative >= 2, false, operands);
1428 [(set_attr "type" "move,move,move,move")
1429 (set_attr "mode" "SF")
1430 (set_attr "length" "3,3,3,3")])
1432 (define_insn "movsfcc_internal1"
1433 [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1434 (if_then_else:SF (match_operator 4 "boolean_operator"
1435 [(match_operand:CC 1 "register_operand" "b,b,b,b")
1437 (match_operand:SF 2 "register_operand" "r,0,f,0")
1438 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1441 return xtensa_emit_movcc ((which_alternative & 1) == 1,
1442 which_alternative >= 2, true, operands);
1444 [(set_attr "type" "move,move,move,move")
1445 (set_attr "mode" "SF")
1446 (set_attr "length" "3,3,3,3")])
1449 ;; Floating-point comparisons.
1451 (define_insn "s<code>_sf"
1452 [(set (match_operand:CC 0 "register_operand" "=b")
1453 (any_scc_sf:CC (match_operand:SF 1 "register_operand" "f")
1454 (match_operand:SF 2 "register_operand" "f")))]
1456 "<scc_sf>.s\t%0, %1, %2"
1457 [(set_attr "type" "farith")
1458 (set_attr "mode" "BL")
1459 (set_attr "length" "3")])
1462 ;; Unconditional branches.
1466 (label_ref (match_operand 0 "" "")))]
1469 [(set_attr "type" "jump")
1470 (set_attr "mode" "none")
1471 (set_attr "length" "3")])
1473 (define_expand "indirect_jump"
1475 (match_operand 0 "register_operand" ""))]
1478 rtx dest = operands[0];
1479 if (GET_CODE (dest) != REG || GET_MODE (dest) != Pmode)
1480 operands[0] = copy_to_mode_reg (Pmode, dest);
1482 emit_jump_insn (gen_indirect_jump_internal (dest));
1486 (define_insn "indirect_jump_internal"
1487 [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
1490 [(set_attr "type" "jump")
1491 (set_attr "mode" "none")
1492 (set_attr "length" "3")])
1495 (define_expand "tablejump"
1496 [(use (match_operand:SI 0 "register_operand" ""))
1497 (use (label_ref (match_operand 1 "" "")))]
1500 rtx target = operands[0];
1503 /* For PIC, the table entry is relative to the start of the table. */
1504 rtx label = gen_reg_rtx (SImode);
1505 target = gen_reg_rtx (SImode);
1506 emit_move_insn (label, gen_rtx_LABEL_REF (SImode, operands[1]));
1507 emit_insn (gen_addsi3 (target, operands[0], label));
1509 emit_jump_insn (gen_tablejump_internal (target, operands[1]));
1513 (define_insn "tablejump_internal"
1515 (match_operand:SI 0 "register_operand" "r"))
1516 (use (label_ref (match_operand 1 "" "")))]
1519 [(set_attr "type" "jump")
1520 (set_attr "mode" "none")
1521 (set_attr "length" "3")])
1526 (define_expand "sym_PLT"
1527 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PLT))]
1531 (define_expand "call"
1532 [(call (match_operand 0 "memory_operand" "")
1533 (match_operand 1 "" ""))]
1536 rtx addr = XEXP (operands[0], 0);
1537 if (flag_pic && GET_CODE (addr) == SYMBOL_REF
1538 && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
1539 addr = gen_sym_PLT (addr);
1540 if (!call_insn_operand (addr, VOIDmode))
1541 XEXP (operands[0], 0) = copy_to_mode_reg (Pmode, addr);
1544 (define_insn "call_internal"
1545 [(call (mem (match_operand:SI 0 "call_insn_operand" "nir"))
1546 (match_operand 1 "" "i"))]
1549 return xtensa_emit_call (0, operands);
1551 [(set_attr "type" "call")
1552 (set_attr "mode" "none")
1553 (set_attr "length" "3")])
1555 (define_expand "call_value"
1556 [(set (match_operand 0 "register_operand" "")
1557 (call (match_operand 1 "memory_operand" "")
1558 (match_operand 2 "" "")))]
1561 rtx addr = XEXP (operands[1], 0);
1562 if (flag_pic && GET_CODE (addr) == SYMBOL_REF
1563 && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
1564 addr = gen_sym_PLT (addr);
1565 if (!call_insn_operand (addr, VOIDmode))
1566 XEXP (operands[1], 0) = copy_to_mode_reg (Pmode, addr);
1569 (define_insn "call_value_internal"
1570 [(set (match_operand 0 "register_operand" "=a")
1571 (call (mem (match_operand:SI 1 "call_insn_operand" "nir"))
1572 (match_operand 2 "" "i")))]
1575 return xtensa_emit_call (1, operands);
1577 [(set_attr "type" "call")
1578 (set_attr "mode" "none")
1579 (set_attr "length" "3")])
1581 (define_insn "entry"
1582 [(set (reg:SI A1_REG)
1583 (unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "i")]
1587 [(set_attr "type" "entry")
1588 (set_attr "mode" "SI")
1589 (set_attr "length" "3")])
1591 (define_insn "return"
1593 (use (reg:SI A0_REG))]
1596 return (TARGET_DENSITY ? "retw.n" : "retw");
1598 [(set_attr "type" "jump")
1599 (set_attr "mode" "none")
1600 (set_attr "length" "2")])
1603 ;; Miscellaneous instructions.
1605 (define_expand "prologue"
1609 xtensa_expand_prologue ();
1613 (define_expand "epilogue"
1617 emit_jump_insn (gen_return ());
1625 return (TARGET_DENSITY ? "nop.n" : "nop");
1627 [(set_attr "type" "nop")
1628 (set_attr "mode" "none")
1629 (set_attr "length" "3")])
1631 (define_expand "nonlocal_goto"
1632 [(match_operand:SI 0 "general_operand" "")
1633 (match_operand:SI 1 "general_operand" "")
1634 (match_operand:SI 2 "general_operand" "")
1635 (match_operand:SI 3 "" "")]
1638 xtensa_expand_nonlocal_goto (operands);
1642 ;; Stuff an address into the return address register along with the window
1643 ;; size in the high bits. Because we don't have the window size of the
1644 ;; previous frame, assume the function called out with a CALL8 since that
1645 ;; is what compilers always use. Note: __builtin_frob_return_addr has
1646 ;; already been applied to the handler, but the generic version doesn't
1647 ;; allow us to frob it quite enough, so we just frob here.
1649 (define_insn_and_split "eh_return"
1650 [(set (reg:SI A0_REG)
1651 (unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")]
1653 (clobber (match_scratch:SI 1 "=r"))]
1657 [(set (match_dup 1) (ashift:SI (match_dup 0) (const_int 2)))
1658 (set (match_dup 1) (plus:SI (match_dup 1) (const_int 2)))
1659 (set (reg:SI A0_REG) (rotatert:SI (match_dup 1) (const_int 2)))]
1662 ;; Setting up a frame pointer is tricky for Xtensa because GCC doesn't
1663 ;; know if a frame pointer is required until the reload pass, and
1664 ;; because there may be an incoming argument value in the hard frame
1665 ;; pointer register (a7). If there is an incoming argument in that
1666 ;; register, the "set_frame_ptr" insn gets inserted immediately after
1667 ;; the insn that copies the incoming argument to a pseudo or to the
1668 ;; stack. This serves several purposes here: (1) it keeps the
1669 ;; optimizer from copy-propagating or scheduling the use of a7 as an
1670 ;; incoming argument away from the beginning of the function; (2) we
1671 ;; can use a post-reload splitter to expand away the insn if a frame
1672 ;; pointer is not required, so that the post-reload scheduler can do
1673 ;; the right thing; and (3) it makes it easy for the prologue expander
1674 ;; to search for this insn to determine whether it should add a new insn
1675 ;; to set up the frame pointer.
1677 (define_insn "set_frame_ptr"
1678 [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
1681 if (frame_pointer_needed)
1682 return "mov\ta7, sp";
1685 [(set_attr "type" "move")
1686 (set_attr "mode" "SI")
1687 (set_attr "length" "3")])
1689 ;; Post-reload splitter to remove fp assignment when it's not needed.
1691 [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
1692 "reload_completed && !frame_pointer_needed"
1693 [(unspec [(const_int 0)] UNSPEC_NOP)]
1696 ;; The preceding splitter needs something to split the insn into;
1697 ;; things start breaking if the result is just a "use" so instead we
1698 ;; generate the following insn.
1699 (define_insn "*unspec_nop"
1700 [(unspec [(const_int 0)] UNSPEC_NOP)]
1703 [(set_attr "type" "nop")
1704 (set_attr "mode" "none")
1705 (set_attr "length" "0")])
1710 (define_expand "sym_TPOFF"
1711 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_TPOFF))]
1715 (define_expand "sym_DTPOFF"
1716 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_DTPOFF))]
1720 (define_insn "load_tp"
1721 [(set (match_operand:SI 0 "register_operand" "=a")
1722 (unspec:SI [(const_int 0)] UNSPEC_TP))]
1724 "rur\t%0, THREADPTR"
1725 [(set_attr "type" "rsr")
1726 (set_attr "mode" "SI")
1727 (set_attr "length" "3")])
1729 (define_insn "set_tp"
1730 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
1733 "wur\t%0, THREADPTR"
1734 [(set_attr "type" "wsr")
1735 (set_attr "mode" "SI")
1736 (set_attr "length" "3")])
1738 (define_insn "tls_func"
1739 [(set (match_operand:SI 0 "register_operand" "=a")
1740 (unspec:SI [(match_operand:SI 1 "tls_symbol_operand" "")]
1742 "TARGET_THREADPTR && HAVE_AS_TLS"
1743 "movi\t%0, %1@TLSFUNC"
1744 [(set_attr "type" "load")
1745 (set_attr "mode" "SI")
1746 (set_attr "length" "3")])
1748 (define_insn "tls_arg"
1749 [(set (match_operand:SI 0 "register_operand" "=a")
1750 (unspec:SI [(match_operand:SI 1 "tls_symbol_operand" "")]
1752 "TARGET_THREADPTR && HAVE_AS_TLS"
1753 "movi\t%0, %1@TLSARG"
1754 [(set_attr "type" "load")
1755 (set_attr "mode" "SI")
1756 (set_attr "length" "3")])
1758 (define_insn "tls_call"
1759 [(set (match_operand:SI 0 "register_operand" "=a")
1760 (call (mem:SI (unspec:SI [(match_operand:SI 1 "register_operand" "r")
1761 (match_operand:SI 2 "tls_symbol_operand" "")]
1763 (match_operand 3 "" "i")))]
1764 "TARGET_THREADPTR && HAVE_AS_TLS"
1765 "callx8.tls %1, %2@TLSCALL"
1766 [(set_attr "type" "call")
1767 (set_attr "mode" "none")
1768 (set_attr "length" "3")])
1771 ;; Instructions for the Xtensa "boolean" option.
1773 (define_insn "*booltrue"
1775 (if_then_else (match_operator 2 "boolean_operator"
1776 [(match_operand:CC 0 "register_operand" "b")
1778 (label_ref (match_operand 1 "" ""))
1782 if (GET_CODE (operands[2]) == EQ)
1783 return "bf\t%0, %1";
1785 return "bt\t%0, %1";
1787 [(set_attr "type" "jump")
1788 (set_attr "mode" "none")
1789 (set_attr "length" "3")])
1791 (define_insn "*boolfalse"
1793 (if_then_else (match_operator 2 "boolean_operator"
1794 [(match_operand:CC 0 "register_operand" "b")
1797 (label_ref (match_operand 1 "" ""))))]
1800 if (GET_CODE (operands[2]) == EQ)
1801 return "bt\t%0, %1";
1803 return "bf\t%0, %1";
1805 [(set_attr "type" "jump")
1806 (set_attr "mode" "none")
1807 (set_attr "length" "3")])
1810 ;; Atomic operations
1812 (define_expand "memory_barrier"
1813 [(set (mem:BLK (match_dup 0))
1814 (unspec_volatile:BLK [(mem:BLK (match_dup 0))] UNSPECV_MEMW))]
1817 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (SImode));
1818 MEM_VOLATILE_P (operands[0]) = 1;
1821 (define_insn "*memory_barrier"
1822 [(set (match_operand:BLK 0 "" "")
1823 (unspec_volatile:BLK [(match_operand:BLK 1 "" "")] UNSPECV_MEMW))]
1826 [(set_attr "type" "unknown")
1827 (set_attr "mode" "none")
1828 (set_attr "length" "3")])
1830 ;; sync_lock_release is only implemented for SImode.
1831 ;; For other modes, just use the default of a store with a memory_barrier.
1832 (define_insn "sync_lock_releasesi"
1833 [(set (match_operand:SI 0 "mem_operand" "=U")
1835 [(match_operand:SI 1 "register_operand" "r")]
1837 "TARGET_RELEASE_SYNC"
1839 [(set_attr "type" "store")
1840 (set_attr "mode" "SI")
1841 (set_attr "length" "3")])
1843 (define_insn "sync_compare_and_swapsi"
1845 [(set (match_operand:SI 0 "register_operand" "=a")
1846 (match_operand:SI 1 "mem_operand" "+U"))
1850 (match_operand:SI 2 "register_operand" "r")
1851 (match_operand:SI 3 "register_operand" "0")]
1854 "wsr\t%2, SCOMPARE1\;s32c1i\t%3, %1"
1855 [(set_attr "type" "multi")
1856 (set_attr "mode" "SI")
1857 (set_attr "length" "6")])
1859 (define_expand "sync_compare_and_swap<mode>"
1861 [(set (match_operand:HQI 0 "register_operand" "")
1862 (match_operand:HQI 1 "mem_operand" ""))
1864 (unspec_volatile:HQI
1866 (match_operand:HQI 2 "register_operand" "")
1867 (match_operand:HQI 3 "register_operand" "")]
1871 xtensa_expand_compare_and_swap (operands[0], operands[1],
1872 operands[2], operands[3]);
1876 (define_expand "sync_lock_test_and_set<mode>"
1877 [(match_operand:HQI 0 "register_operand")
1878 (match_operand:HQI 1 "memory_operand")
1879 (match_operand:HQI 2 "register_operand")]
1882 xtensa_expand_atomic (SET, operands[0], operands[1], operands[2], false);
1886 (define_expand "sync_<atomic><mode>"
1887 [(set (match_operand:HQI 0 "memory_operand")
1888 (ATOMIC:HQI (match_dup 0)
1889 (match_operand:HQI 1 "register_operand")))]
1892 xtensa_expand_atomic (<CODE>, NULL_RTX, operands[0], operands[1], false);
1896 (define_expand "sync_old_<atomic><mode>"
1897 [(set (match_operand:HQI 0 "register_operand")
1898 (match_operand:HQI 1 "memory_operand"))
1900 (ATOMIC:HQI (match_dup 1)
1901 (match_operand:HQI 2 "register_operand")))]
1904 xtensa_expand_atomic (<CODE>, operands[0], operands[1], operands[2], false);
1908 (define_expand "sync_new_<atomic><mode>"
1909 [(set (match_operand:HQI 0 "register_operand")
1910 (ATOMIC:HQI (match_operand:HQI 1 "memory_operand")
1911 (match_operand:HQI 2 "register_operand")))
1912 (set (match_dup 1) (ATOMIC:HQI (match_dup 1) (match_dup 2)))]
1915 xtensa_expand_atomic (<CODE>, operands[0], operands[1], operands[2], true);