1 ;; GCC machine description for Tensilica's Xtensa architecture.
2 ;; Copyright (C) 2001-2023 Free Software Foundation, Inc.
3 ;; Contributed by Bob Wilson (bwilson@tensilica.com) at Tensilica.
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 ;; License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
30 (define_c_enum "unspec" [
46 (define_c_enum "unspecv" [
56 ;; This code iterator allows signed and unsigned widening multiplications
57 ;; to use the same template.
58 (define_code_iterator any_extend [sign_extend zero_extend])
60 ;; <u> expands to an empty string when doing a signed operation and
61 ;; "u" when doing an unsigned operation.
62 (define_code_attr u [(sign_extend "") (zero_extend "u")])
64 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
65 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
67 ;; This code iterator allows four integer min/max operations to be
68 ;; generated from one template.
69 (define_code_iterator any_minmax [smin umin smax umax])
71 ;; <minmax> expands to the opcode name for any_minmax operations.
72 (define_code_attr minmax [(smin "min") (umin "minu")
73 (smax "max") (umax "maxu")])
75 ;; This code iterator is for floating-point comparisons.
76 (define_code_iterator any_scc_sf [eq lt le uneq unlt unle unordered])
77 (define_code_attr scc_sf [(eq "oeq") (lt "olt") (le "ole")
78 (uneq "ueq") (unlt "ult") (unle "ule")
81 ;; This iterator and attribute allow to combine most atomic operations.
82 (define_code_iterator ATOMIC [and ior xor plus minus mult])
83 (define_code_attr atomic [(and "and") (ior "ior") (xor "xor")
84 (plus "add") (minus "sub") (mult "nand")])
86 ;; This mode iterator allows the HI and QI patterns to be defined from
88 (define_mode_iterator HQI [HI QI])
94 "unknown,jump,call,load,store,move,arith,multi,nop,farith,fmadd,fconv,fload,fstore,mul16,mul32,div32,mac16,rsr,wsr,entry,trap"
95 (const_string "unknown"))
98 "unknown,none,QI,HI,SI,DI,SF,DF,BL"
99 (const_string "unknown"))
101 (define_attr "length" "" (const_int 1))
103 ;; Describe a user's asm statement.
104 (define_asm_attributes
105 [(set_attr "type" "multi")
106 (set_attr "mode" "none")
107 (set_attr "length" "3")]) ;; Should be the maximum possible length
108 ;; of a single machine instruction.
113 ;; The Xtensa basically has simple 5-stage RISC pipeline.
114 ;; Most instructions complete in 1 cycle, and it is OK to assume that
115 ;; everything is fully pipelined. The exceptions have special insn
116 ;; reservations in the pipeline description below. The Xtensa can
117 ;; issue one instruction per cycle, so defining CPU units is unnecessary.
119 (define_insn_reservation "xtensa_any_insn" 1
120 (eq_attr "type" "!load,fload,rsr,mul16,mul32,fmadd,fconv")
123 (define_insn_reservation "xtensa_memory" 2
124 (eq_attr "type" "load,fload")
127 (define_insn_reservation "xtensa_sreg" 2
128 (eq_attr "type" "rsr")
131 (define_insn_reservation "xtensa_mul16" 2
132 (eq_attr "type" "mul16")
135 (define_insn_reservation "xtensa_mul32" 2
136 (eq_attr "type" "mul32")
139 (define_insn_reservation "xtensa_fmadd" 4
140 (eq_attr "type" "fmadd")
143 (define_insn_reservation "xtensa_fconv" 2
144 (eq_attr "type" "fconv")
147 ;; Include predicates and constraints.
149 (include "predicates.md")
150 (include "constraints.md")
155 (define_insn "addsi3"
156 [(set (match_operand:SI 0 "register_operand" "=D,D,a,a,a")
157 (plus:SI (match_operand:SI 1 "register_operand" "%d,d,r,r,r")
158 (match_operand:SI 2 "add_operand" "d,O,r,J,N")))]
166 [(set_attr "type" "arith,arith,arith,arith,arith")
167 (set_attr "mode" "SI")
168 (set_attr "length" "2,2,3,3,3")])
170 (define_insn "*addsubx"
171 [(set (match_operand:SI 0 "register_operand" "=a")
172 (match_operator:SI 4 "addsub_operator"
173 [(ashift:SI (match_operand:SI 1 "register_operand" "r")
174 (match_operand:SI 3 "addsubx_operand" "i"))
175 (match_operand:SI 2 "register_operand" "r")]))]
178 operands[3] = GEN_INT (1 << INTVAL (operands[3]));
179 switch (GET_CODE (operands[4]))
182 return "addx%3\t%0, %1, %2";
184 return "subx%3\t%0, %1, %2";
189 [(set_attr "type" "arith")
190 (set_attr "mode" "SI")
191 (set_attr "length" "3")])
193 (define_expand "adddi3"
194 [(set (match_operand:DI 0 "register_operand")
195 (plus:DI (match_operand:DI 1 "register_operand")
196 (match_operand:DI 2 "register_operand")))]
199 rtx lo_dest, hi_dest, lo_op0, hi_op0, lo_op1, hi_op1;
200 rtx_code_label *label;
201 if (rtx_equal_p (operands[0], operands[1])
202 || rtx_equal_p (operands[0], operands[2])
203 || ! REG_P (operands[1]) || ! REG_P (operands[2]))
205 lo_dest = gen_lowpart (SImode, operands[0]);
206 hi_dest = gen_highpart (SImode, operands[0]);
207 lo_op0 = gen_lowpart (SImode, operands[1]);
208 hi_op0 = gen_highpart (SImode, operands[1]);
209 lo_op1 = gen_lowpart (SImode, operands[2]);
210 hi_op1 = gen_highpart (SImode, operands[2]);
211 emit_insn (gen_addsi3 (hi_dest, hi_op0, hi_op1));
212 emit_insn (gen_addsi3 (lo_dest, lo_op0, lo_op1));
213 emit_cmp_and_jump_insns (lo_dest,
214 (REGNO (operands[1]) < REGNO (operands[2])
215 ? lo_op1 : lo_op0), GEU, const0_rtx,
216 SImode, true, label = gen_label_rtx ());
217 emit_insn (gen_addsi3 (hi_dest, hi_dest, const1_rtx));
222 (define_insn "addsf3"
223 [(set (match_operand:SF 0 "register_operand" "=f")
224 (plus:SF (match_operand:SF 1 "register_operand" "%f")
225 (match_operand:SF 2 "register_operand" "f")))]
228 [(set_attr "type" "fmadd")
229 (set_attr "mode" "SF")
230 (set_attr "length" "3")])
235 (define_insn "subsi3"
236 [(set (match_operand:SI 0 "register_operand" "=a")
237 (minus:SI (match_operand:SI 1 "register_operand" "r")
238 (match_operand:SI 2 "register_operand" "r")))]
241 [(set_attr "type" "arith")
242 (set_attr "mode" "SI")
243 (set_attr "length" "3")])
245 (define_insn_and_split "*subsi3_from_const"
246 [(set (match_operand:SI 0 "register_operand" "=a")
247 (minus:SI (match_operand:SI 1 "const_int_operand" "i")
248 (match_operand:SI 2 "register_operand" "r")))]
249 "xtensa_simm8 (-INTVAL (operands[1]))
250 || xtensa_simm8x256 (-INTVAL (operands[1]))"
254 (plus:SI (match_dup 2)
257 (neg:SI (match_dup 0)))]
259 operands[1] = GEN_INT (-INTVAL (operands[1]));
261 [(set_attr "type" "arith")
262 (set_attr "mode" "SI")
264 (if_then_else (match_test "TARGET_DENSITY
265 && xtensa_m1_or_1_thru_15 (-INTVAL (operands[1]))")
269 (define_expand "subdi3"
270 [(set (match_operand:DI 0 "register_operand")
271 (minus:DI (match_operand:DI 1 "register_operand")
272 (match_operand:DI 2 "register_operand")))]
275 rtx lo_dest, hi_dest, lo_op0, hi_op0, lo_op1, hi_op1;
276 rtx_code_label *label;
277 lo_dest = gen_lowpart (SImode, operands[0]);
278 hi_dest = gen_highpart (SImode, operands[0]);
279 lo_op0 = gen_lowpart (SImode, operands[1]);
280 hi_op0 = gen_highpart (SImode, operands[1]);
281 lo_op1 = gen_lowpart (SImode, operands[2]);
282 hi_op1 = gen_highpart (SImode, operands[2]);
283 emit_insn (gen_subsi3 (hi_dest, hi_op0, hi_op1));
284 emit_cmp_and_jump_insns (lo_op0, lo_op1, GEU, const0_rtx,
285 SImode, true, label = gen_label_rtx ());
286 emit_insn (gen_addsi3 (hi_dest, hi_dest, constm1_rtx));
288 emit_insn (gen_subsi3 (lo_dest, lo_op0, lo_op1));
292 (define_insn "subsf3"
293 [(set (match_operand:SF 0 "register_operand" "=f")
294 (minus:SF (match_operand:SF 1 "register_operand" "f")
295 (match_operand:SF 2 "register_operand" "f")))]
298 [(set_attr "type" "fmadd")
299 (set_attr "mode" "SF")
300 (set_attr "length" "3")])
305 (define_expand "mulsidi3"
306 [(set (match_operand:DI 0 "register_operand")
307 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand"))
308 (sign_extend:DI (match_operand:SI 2 "register_operand"))))]
311 rtx temp = gen_reg_rtx (SImode);
312 emit_insn (gen_mulsi3 (temp, operands[1], operands[2]));
313 emit_insn (gen_mulsi3_highpart (gen_highpart (SImode, operands[0]),
314 operands[1], operands[2]));
315 emit_insn (gen_movsi (gen_lowpart (SImode, operands[0]), temp));
319 (define_expand "umulsidi3"
320 [(set (match_operand:DI 0 "register_operand")
321 (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand"))
322 (zero_extend:DI (match_operand:SI 2 "register_operand"))))]
325 if (TARGET_MUL32_HIGH)
327 rtx temp = gen_reg_rtx (SImode);
328 emit_insn (gen_mulsi3 (temp, operands[1], operands[2]));
329 emit_insn (gen_umulsi3_highpart (gen_highpart (SImode, operands[0]),
330 operands[1], operands[2]));
331 emit_insn (gen_movsi (gen_lowpart (SImode, operands[0]), temp));
334 emit_library_call_value (gen_rtx_SYMBOL_REF (Pmode, "__umulsidi3"),
335 operands[0], LCT_NORMAL, DImode,
337 operands[2], SImode);
341 (define_insn "<u>mulsi3_highpart"
342 [(set (match_operand:SI 0 "register_operand" "=a")
345 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "%r"))
346 (any_extend:DI (match_operand:SI 2 "register_operand" "r")))
349 "mul<su>h\t%0, %1, %2"
350 [(set_attr "type" "mul32")
351 (set_attr "mode" "SI")
352 (set_attr "length" "3")])
354 (define_insn "mulsi3"
355 [(set (match_operand:SI 0 "register_operand" "=a")
356 (mult:SI (match_operand:SI 1 "register_operand" "%r")
357 (match_operand:SI 2 "register_operand" "r")))]
360 [(set_attr "type" "mul32")
361 (set_attr "mode" "SI")
362 (set_attr "length" "3")])
364 (define_insn "<u>mulhisi3"
365 [(set (match_operand:SI 0 "register_operand" "=C,A")
366 (mult:SI (any_extend:SI
367 (match_operand:HI 1 "register_operand" "%r,r"))
369 (match_operand:HI 2 "register_operand" "r,r"))))]
370 "TARGET_MUL16 || TARGET_MAC16"
372 mul16<su>\t%0, %1, %2
373 <u>mul.aa.ll\t%1, %2"
374 [(set_attr "type" "mul16,mac16")
375 (set_attr "mode" "SI")
376 (set_attr "length" "3,3")])
378 (define_insn "muladdhisi"
379 [(set (match_operand:SI 0 "register_operand" "=A")
380 (plus:SI (mult:SI (sign_extend:SI
381 (match_operand:HI 1 "register_operand" "%r"))
383 (match_operand:HI 2 "register_operand" "r")))
384 (match_operand:SI 3 "register_operand" "0")))]
387 [(set_attr "type" "mac16")
388 (set_attr "mode" "SI")
389 (set_attr "length" "3")])
391 (define_insn "mulsubhisi"
392 [(set (match_operand:SI 0 "register_operand" "=A")
393 (minus:SI (match_operand:SI 1 "register_operand" "0")
394 (mult:SI (sign_extend:SI
395 (match_operand:HI 2 "register_operand" "%r"))
397 (match_operand:HI 3 "register_operand" "r")))))]
400 [(set_attr "type" "mac16")
401 (set_attr "mode" "SI")
402 (set_attr "length" "3")])
404 (define_insn "mulsf3"
405 [(set (match_operand:SF 0 "register_operand" "=f")
406 (mult:SF (match_operand:SF 1 "register_operand" "%f")
407 (match_operand:SF 2 "register_operand" "f")))]
410 [(set_attr "type" "fmadd")
411 (set_attr "mode" "SF")
412 (set_attr "length" "3")])
414 (define_insn "fmasf4"
415 [(set (match_operand:SF 0 "register_operand" "=f")
416 (fma:SF (match_operand:SF 1 "register_operand" "f")
417 (match_operand:SF 2 "register_operand" "f")
418 (match_operand:SF 3 "register_operand" "0")))]
421 [(set_attr "type" "fmadd")
422 (set_attr "mode" "SF")
423 (set_attr "length" "3")])
425 ;; Note that (C - A*B) = (-A*B + C)
426 (define_insn "fnmasf4"
427 [(set (match_operand:SF 0 "register_operand" "=f")
428 (fma:SF (neg:SF (match_operand:SF 1 "register_operand" "f"))
429 (match_operand:SF 2 "register_operand" "f")
430 (match_operand:SF 3 "register_operand" "0")))]
433 [(set_attr "type" "fmadd")
434 (set_attr "mode" "SF")
435 (set_attr "length" "3")])
440 (define_insn "divsi3"
441 [(set (match_operand:SI 0 "register_operand" "=a")
442 (div:SI (match_operand:SI 1 "register_operand" "r")
443 (match_operand:SI 2 "register_operand" "r")))]
446 [(set_attr "type" "div32")
447 (set_attr "mode" "SI")
448 (set_attr "length" "3")])
450 (define_insn "udivsi3"
451 [(set (match_operand:SI 0 "register_operand" "=a")
452 (udiv:SI (match_operand:SI 1 "register_operand" "r")
453 (match_operand:SI 2 "register_operand" "r")))]
456 [(set_attr "type" "div32")
457 (set_attr "mode" "SI")
458 (set_attr "length" "3")])
463 (define_insn "modsi3"
464 [(set (match_operand:SI 0 "register_operand" "=a")
465 (mod:SI (match_operand:SI 1 "register_operand" "r")
466 (match_operand:SI 2 "register_operand" "r")))]
469 [(set_attr "type" "div32")
470 (set_attr "mode" "SI")
471 (set_attr "length" "3")])
473 (define_insn "umodsi3"
474 [(set (match_operand:SI 0 "register_operand" "=a")
475 (umod:SI (match_operand:SI 1 "register_operand" "r")
476 (match_operand:SI 2 "register_operand" "r")))]
479 [(set_attr "type" "div32")
480 (set_attr "mode" "SI")
481 (set_attr "length" "3")])
486 (define_insn "abssi2"
487 [(set (match_operand:SI 0 "register_operand" "=a")
488 (abs:SI (match_operand:SI 1 "register_operand" "r")))]
491 [(set_attr "type" "arith")
492 (set_attr "mode" "SI")
493 (set_attr "length" "3")])
495 (define_insn "abssf2"
496 [(set (match_operand:SF 0 "register_operand" "=f")
497 (abs:SF (match_operand:SF 1 "register_operand" "f")))]
500 [(set_attr "type" "farith")
501 (set_attr "mode" "SF")
502 (set_attr "length" "3")])
507 (define_insn "<code>si3"
508 [(set (match_operand:SI 0 "register_operand" "=a")
509 (any_minmax:SI (match_operand:SI 1 "register_operand" "%r")
510 (match_operand:SI 2 "register_operand" "r")))]
512 "<minmax>\t%0, %1, %2"
513 [(set_attr "type" "arith")
514 (set_attr "mode" "SI")
515 (set_attr "length" "3")])
520 (define_insn_and_split "*xtensa_clamps"
521 [(set (match_operand:SI 0 "register_operand" "=a")
522 (smax:SI (smin:SI (match_operand:SI 1 "register_operand" "r")
523 (match_operand:SI 2 "const_int_operand" "i"))
524 (match_operand:SI 3 "const_int_operand" "i")))]
525 "TARGET_MINMAX && TARGET_CLAMPS
526 && xtensa_match_CLAMPS_imms_p (operands[3], operands[2])"
530 (smin:SI (smax:SI (match_dup 1)
534 [(set_attr "type" "arith")
535 (set_attr "mode" "SI")
536 (set_attr "length" "3")])
538 (define_insn "*xtensa_clamps"
539 [(set (match_operand:SI 0 "register_operand" "=a")
540 (smin:SI (smax:SI (match_operand:SI 1 "register_operand" "r")
541 (match_operand:SI 2 "const_int_operand" "i"))
542 (match_operand:SI 3 "const_int_operand" "i")))]
543 "TARGET_MINMAX && TARGET_CLAMPS
544 && xtensa_match_CLAMPS_imms_p (operands[2], operands[3])"
546 static char result[64];
547 sprintf (result, "clamps\t%%0, %%1, %d", floor_log2 (-INTVAL (operands[2])));
550 [(set_attr "type" "arith")
551 (set_attr "mode" "SI")
552 (set_attr "length" "3")])
555 ;; Count redundant leading sign bits and leading/trailing zeros,
556 ;; and find first bit.
558 (define_insn "clrsbsi2"
559 [(set (match_operand:SI 0 "register_operand" "=a")
560 (clrsb:SI (match_operand:SI 1 "register_operand" "r")))]
563 [(set_attr "type" "arith")
564 (set_attr "mode" "SI")
565 (set_attr "length" "3")])
567 (define_insn "clzsi2"
568 [(set (match_operand:SI 0 "register_operand" "=a")
569 (clz:SI (match_operand:SI 1 "register_operand" "r")))]
572 [(set_attr "type" "arith")
573 (set_attr "mode" "SI")
574 (set_attr "length" "3")])
576 (define_expand "ctzsi2"
577 [(set (match_operand:SI 0 "register_operand" "")
578 (ctz:SI (match_operand:SI 1 "register_operand" "")))]
581 rtx temp = gen_reg_rtx (SImode);
582 emit_insn (gen_negsi2 (temp, operands[1]));
583 emit_insn (gen_andsi3 (temp, temp, operands[1]));
584 emit_insn (gen_clzsi2 (temp, temp));
585 emit_move_insn (operands[0], GEN_INT (31));
586 emit_insn (gen_subsi3 (operands[0], operands[0], temp));
590 (define_expand "ffssi2"
591 [(set (match_operand:SI 0 "register_operand" "")
592 (ffs:SI (match_operand:SI 1 "register_operand" "")))]
595 rtx temp = gen_reg_rtx (SImode);
596 emit_insn (gen_negsi2 (temp, operands[1]));
597 emit_insn (gen_andsi3 (temp, temp, operands[1]));
598 emit_insn (gen_clzsi2 (temp, temp));
599 emit_move_insn (operands[0], GEN_INT (32));
600 emit_insn (gen_subsi3 (operands[0], operands[0], temp));
607 (define_insn "bswaphi2"
608 [(set (match_operand:HI 0 "register_operand" "=a")
609 (bswap:HI (match_operand:HI 1 "register_operand" "r")))
610 (clobber (match_scratch:HI 2 "=&a"))]
612 "extui\t%2, %1, 8, 8\;slli\t%0, %1, 8\;or\t%0, %0, %2"
613 [(set_attr "type" "arith")
614 (set_attr "mode" "HI")
615 (set_attr "length" "9")])
617 (define_expand "bswapsi2"
618 [(set (match_operand:SI 0 "register_operand" "")
619 (bswap:SI (match_operand:SI 1 "register_operand" "")))]
620 "!optimize_debug && optimize > 1"
622 /* GIMPLE manual byte-swapping recognition is now activated.
623 For both built-in and manual bswaps, emit corresponding library call
624 if optimizing for size, or a series of dedicated machine instructions
627 emit_library_call_value (optab_libfunc (bswap_optab, SImode),
628 operands[0], LCT_NORMAL, SImode,
629 operands[1], SImode);
631 emit_insn (gen_bswapsi2_internal (operands[0], operands[1]));
635 (define_insn "bswapsi2_internal"
636 [(set (match_operand:SI 0 "register_operand" "=a,&a")
637 (bswap:SI (match_operand:SI 1 "register_operand" "0,r")))
638 (clobber (match_scratch:SI 2 "=&a,X"))]
639 "!optimize_debug && optimize > 1 && !optimize_size"
641 rtx_insn *prev_insn = prev_nonnote_nondebug_insn (insn);
642 const char *init = "ssai\t8\;";
643 static char result[128];
644 if (prev_insn && NONJUMP_INSN_P (prev_insn))
646 rtx x = PATTERN (prev_insn);
647 if (GET_CODE (x) == PARALLEL && XVECLEN (x, 0) == 2
648 && GET_CODE (XVECEXP (x, 0, 0)) == SET
649 && GET_CODE (XVECEXP (x, 0, 1)) == CLOBBER)
651 x = XEXP (XVECEXP (x, 0, 0), 1);
652 if (GET_CODE (x) == BSWAP && GET_MODE (x) == SImode)
657 (which_alternative == 0)
658 ? "%s" "srli\t%%2, %%1, 16\;src\t%%2, %%2, %%1\;src\t%%2, %%2, %%2\;src\t%%0, %%1, %%2"
659 : "%s" "srli\t%%0, %%1, 16\;src\t%%0, %%0, %%1\;src\t%%0, %%0, %%0\;src\t%%0, %%1, %%0",
663 [(set_attr "type" "arith,arith")
664 (set_attr "mode" "SI")
665 (set_attr "length" "15,15")])
667 (define_expand "bswapdi2"
668 [(set (match_operand:DI 0 "register_operand" "")
669 (bswap:DI (match_operand:DI 1 "register_operand" "")))]
670 "!optimize_debug && optimize > 1 && optimize_size"
672 /* Replace with a single DImode library call.
673 Without this, two SImode library calls are emitted. */
674 emit_library_call_value (optab_libfunc (bswap_optab, DImode),
675 operands[0], LCT_NORMAL, DImode,
676 operands[1], DImode);
681 ;; Negation and one's complement.
683 (define_insn "negsi2"
684 [(set (match_operand:SI 0 "register_operand" "=a")
685 (neg:SI (match_operand:SI 1 "register_operand" "r")))]
688 [(set_attr "type" "arith")
689 (set_attr "mode" "SI")
690 (set_attr "length" "3")])
692 (define_insn_and_split "one_cmplsi2"
693 [(set (match_operand:SI 0 "register_operand" "=a")
694 (not:SI (match_operand:SI 1 "register_operand" "r")))]
697 "&& can_create_pseudo_p ()"
701 (xor:SI (match_dup 1)
704 operands[2] = gen_reg_rtx (SImode);
706 [(set_attr "type" "arith")
707 (set_attr "mode" "SI")
709 (if_then_else (match_test "TARGET_DENSITY")
713 (define_insn "negsf2"
714 [(set (match_operand:SF 0 "register_operand" "=f")
715 (neg:SF (match_operand:SF 1 "register_operand" "f")))]
718 [(set_attr "type" "farith")
719 (set_attr "mode" "SF")
720 (set_attr "length" "3")])
723 ;; Logical instructions.
725 (define_insn "andsi3"
726 [(set (match_operand:SI 0 "register_operand" "=a,a")
727 (and:SI (match_operand:SI 1 "register_operand" "%r,r")
728 (match_operand:SI 2 "mask_operand" "P,r")))]
731 extui\t%0, %1, 0, %K2
733 [(set_attr "type" "arith,arith")
734 (set_attr "mode" "SI")
735 (set_attr "length" "3,3")])
737 (define_insn_and_split "*andsi3_bitcmpl"
738 [(set (match_operand:SI 0 "register_operand" "=a")
739 (and:SI (not:SI (match_operand:SI 1 "register_operand" "r"))
740 (match_operand:SI 2 "register_operand" "r")))]
743 "&& can_create_pseudo_p ()"
745 (and:SI (match_dup 1)
748 (xor:SI (match_dup 3)
751 operands[3] = gen_reg_rtx (SImode);
753 [(set_attr "type" "arith")
754 (set_attr "mode" "SI")
755 (set_attr "length" "6")])
757 (define_insn_and_split "*andsi3_const_pow2_minus_one"
758 [(set (match_operand:SI 0 "register_operand" "=a")
759 (and:SI (match_operand:SI 1 "register_operand" "r")
760 (match_operand:SI 2 "const_int_operand" "i")))]
761 "IN_RANGE (exact_log2 (INTVAL (operands[2]) + 1), 17, 31)"
765 (ashift:SI (match_dup 1)
768 (lshiftrt:SI (match_dup 0)
771 operands[2] = GEN_INT (32 - floor_log2 (INTVAL (operands[2]) + 1));
773 [(set_attr "type" "arith")
774 (set_attr "mode" "SI")
776 (if_then_else (match_test "TARGET_DENSITY
777 && INTVAL (operands[2]) == 0x7FFFFFFF")
781 (define_insn_and_split "*andsi3_const_negative_pow2"
782 [(set (match_operand:SI 0 "register_operand" "=a")
783 (and:SI (match_operand:SI 1 "register_operand" "r")
784 (match_operand:SI 2 "const_int_operand" "i")))]
785 "IN_RANGE (exact_log2 (-INTVAL (operands[2])), 12, 31)"
789 (lshiftrt:SI (match_dup 1)
792 (ashift:SI (match_dup 0)
795 operands[2] = GEN_INT (floor_log2 (-INTVAL (operands[2])));
797 [(set_attr "type" "arith")
798 (set_attr "mode" "SI")
799 (set_attr "length" "6")])
801 (define_insn_and_split "*andsi3_const_shifted_mask"
802 [(set (match_operand:SI 0 "register_operand" "=a")
803 (and:SI (match_operand:SI 1 "register_operand" "r")
804 (match_operand:SI 2 "shifted_mask_operand" "i")))]
805 "! xtensa_simm12b (INTVAL (operands[2]))"
809 (zero_extract:SI (match_dup 1)
813 (ashift:SI (match_dup 0)
816 HOST_WIDE_INT mask = INTVAL (operands[2]);
817 int shift = ctz_hwi (mask);
818 int mask_size = floor_log2 (((uint32_t)mask >> shift) + 1);
819 int mask_pos = shift;
821 mask_pos = (32 - (mask_size + shift)) & 0x1f;
822 operands[2] = GEN_INT (shift);
823 operands[3] = GEN_INT (mask_size);
824 operands[4] = GEN_INT (mask_pos);
826 [(set_attr "type" "arith")
827 (set_attr "mode" "SI")
829 (if_then_else (match_test "TARGET_DENSITY
830 && ctz_hwi (INTVAL (operands[2])) == 1")
834 (define_insn "iorsi3"
835 [(set (match_operand:SI 0 "register_operand" "=a")
836 (ior:SI (match_operand:SI 1 "register_operand" "%r")
837 (match_operand:SI 2 "register_operand" "r")))]
840 [(set_attr "type" "arith")
841 (set_attr "mode" "SI")
842 (set_attr "length" "3")])
844 (define_expand "xorsi3"
845 [(set (match_operand:SI 0 "register_operand")
846 (xor:SI (match_operand:SI 1 "register_operand")
847 (match_operand:SI 2 "nonmemory_operand")))]
850 if (register_operand (operands[2], SImode))
851 emit_insn (gen_xorsi3_internal (operands[0], operands[1],
855 rtx (*gen_op)(rtx, rtx, rtx);
857 && CONST_INT_P (operands[2])
858 && INTVAL (operands[2]) == -2147483648L)
861 gen_op = gen_xorsi3_internal;
862 emit_insn (gen_op (operands[0], operands[1],
863 force_reg (SImode, operands[2])));
868 (define_insn "xorsi3_internal"
869 [(set (match_operand:SI 0 "register_operand" "=a")
870 (xor:SI (match_operand:SI 1 "register_operand" "%r")
871 (match_operand:SI 2 "register_operand" "r")))]
874 [(set_attr "type" "arith")
875 (set_attr "mode" "SI")
876 (set_attr "length" "3")])
878 (define_insn_and_split "*splice_bits"
879 [(set (match_operand:SI 0 "register_operand" "=a")
880 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "r")
881 (match_operand:SI 3 "const_int_operand" "i"))
882 (and:SI (match_operand:SI 2 "register_operand" "r")
883 (match_operand:SI 4 "const_int_operand" "i"))))]
885 "!optimize_debug && optimize
886 && INTVAL (operands[3]) + INTVAL (operands[4]) == -1
887 && (exact_log2 (INTVAL (operands[3]) + 1) > 16
888 || exact_log2 (INTVAL (operands[4]) + 1) > 16)"
890 "&& can_create_pseudo_p ()"
892 (ashift:SI (match_dup 1)
895 (lshiftrt:SI (match_dup 2)
898 (ior:SI (lshiftrt:SI (match_dup 5)
900 (ashift:SI (match_dup 6)
904 if (INTVAL (operands[3]) < 0)
907 x = operands[1], operands[1] = operands[2], operands[2] = x;
908 x = operands[3], operands[3] = operands[4], operands[4] = x;
910 shift = floor_log2 (INTVAL (operands[3]) + 1);
911 operands[3] = GEN_INT (shift);
912 operands[4] = GEN_INT (32 - shift);
913 operands[5] = gen_reg_rtx (SImode);
914 operands[6] = gen_reg_rtx (SImode);
916 [(set_attr "type" "arith")
917 (set_attr "mode" "SI")
919 (if_then_else (match_test "TARGET_DENSITY
920 && (INTVAL (operands[3]) == 0x7FFFFFFF
921 || INTVAL (operands[4]) == 0x7FFFFFFF)")
926 ;; Zero-extend instructions.
928 (define_insn "zero_extendhisi2"
929 [(set (match_operand:SI 0 "register_operand" "=a,a")
930 (zero_extend:SI (match_operand:HI 1 "nonimmed_operand" "r,U")))]
935 [(set_attr "type" "arith,load")
936 (set_attr "mode" "SI")
937 (set_attr "length" "3,3")])
939 (define_insn "zero_extendqisi2"
940 [(set (match_operand:SI 0 "register_operand" "=a,a")
941 (zero_extend:SI (match_operand:QI 1 "nonimmed_operand" "r,U")))]
946 [(set_attr "type" "arith,load")
947 (set_attr "mode" "SI")
948 (set_attr "length" "3,3")])
951 ;; Sign-extend instructions.
953 (define_expand "extendhisi2"
954 [(set (match_operand:SI 0 "register_operand" "")
955 (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
958 if (sext_operand (operands[1], HImode))
959 emit_insn (gen_extendhisi2_internal (operands[0], operands[1]));
961 xtensa_extend_reg (operands[0], operands[1]);
965 (define_insn "extendhisi2_internal"
966 [(set (match_operand:SI 0 "register_operand" "=B,a")
967 (sign_extend:SI (match_operand:HI 1 "sext_operand" "r,U")))]
972 [(set_attr "type" "arith,load")
973 (set_attr "mode" "SI")
974 (set_attr "length" "3,3")])
976 (define_expand "extendqisi2"
977 [(set (match_operand:SI 0 "register_operand" "")
978 (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
982 emit_insn (gen_extendqisi2_internal (operands[0], operands[1]));
984 xtensa_extend_reg (operands[0], operands[1]);
988 (define_insn "extendqisi2_internal"
989 [(set (match_operand:SI 0 "register_operand" "=B")
990 (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
993 [(set_attr "type" "arith")
994 (set_attr "mode" "SI")
995 (set_attr "length" "3")])
998 ;; Field extract instructions.
1000 (define_expand "extvsi"
1001 [(set (match_operand:SI 0 "register_operand" "")
1002 (sign_extract:SI (match_operand:SI 1 "register_operand" "")
1003 (match_operand:SI 2 "const_int_operand" "")
1004 (match_operand:SI 3 "const_int_operand" "")))]
1007 if (!sext_fldsz_operand (operands[2], SImode))
1010 /* We could expand to a right shift followed by SEXT but that's
1011 no better than the standard left and right shift sequence. */
1012 if (!lsbitnum_operand (operands[3], SImode))
1015 emit_insn (gen_extvsi_internal (operands[0], operands[1],
1016 operands[2], operands[3]));
1020 (define_insn "extvsi_internal"
1021 [(set (match_operand:SI 0 "register_operand" "=a")
1022 (sign_extract:SI (match_operand:SI 1 "register_operand" "r")
1023 (match_operand:SI 2 "sext_fldsz_operand" "i")
1024 (match_operand:SI 3 "lsbitnum_operand" "i")))]
1027 int fldsz = INTVAL (operands[2]);
1028 operands[2] = GEN_INT (fldsz - 1);
1029 return "sext\t%0, %1, %2";
1031 [(set_attr "type" "arith")
1032 (set_attr "mode" "SI")
1033 (set_attr "length" "3")])
1035 (define_expand "extzvsi"
1036 [(set (match_operand:SI 0 "register_operand" "")
1037 (zero_extract:SI (match_operand:SI 1 "register_operand" "")
1038 (match_operand:SI 2 "const_int_operand" "")
1039 (match_operand:SI 3 "const_int_operand" "")))]
1042 if (!extui_fldsz_operand (operands[2], SImode))
1044 emit_insn (gen_extzvsi_internal (operands[0], operands[1],
1045 operands[2], operands[3]));
1049 (define_insn "extzvsi_internal"
1050 [(set (match_operand:SI 0 "register_operand" "=a")
1051 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
1052 (match_operand:SI 2 "extui_fldsz_operand" "i")
1053 (match_operand:SI 3 "const_int_operand" "i")))]
1057 if (BITS_BIG_ENDIAN)
1058 shift = (32 - (INTVAL (operands[2]) + INTVAL (operands[3]))) & 0x1f;
1060 shift = INTVAL (operands[3]) & 0x1f;
1061 operands[3] = GEN_INT (shift);
1062 return "extui\t%0, %1, %3, %2";
1064 [(set_attr "type" "arith")
1065 (set_attr "mode" "SI")
1066 (set_attr "length" "3")])
1068 (define_insn_and_split "*extzvsi-1bit_ashlsi3"
1069 [(set (match_operand:SI 0 "register_operand" "=a")
1070 (and:SI (match_operator:SI 4 "logical_shift_operator"
1071 [(match_operand:SI 1 "register_operand" "r")
1072 (match_operand:SI 2 "const_int_operand" "i")])
1073 (match_operand:SI 3 "const_int_operand" "i")))]
1074 "exact_log2 (INTVAL (operands[3])) > 0"
1078 (zero_extract:SI (match_dup 1)
1082 (ashift:SI (match_dup 0)
1085 int pos = INTVAL (operands[2]), shift = floor_log2 (INTVAL (operands[3]));
1086 switch (GET_CODE (operands[4]))
1097 if (BITS_BIG_ENDIAN)
1098 pos = (32 - (1 + pos)) & 0x1f;
1099 operands[2] = GEN_INT (pos);
1100 operands[3] = GEN_INT (shift);
1102 [(set_attr "type" "arith")
1103 (set_attr "mode" "SI")
1104 (set (attr "length")
1105 (if_then_else (match_test "TARGET_DENSITY && INTVAL (operands[3]) == 2")
1109 (define_insn_and_split "*extzvsi-1bit_addsubx"
1110 [(set (match_operand:SI 0 "register_operand" "=a")
1111 (match_operator:SI 5 "addsub_operator"
1112 [(and:SI (match_operator:SI 6 "logical_shift_operator"
1113 [(match_operand:SI 1 "register_operand" "r")
1114 (match_operand:SI 3 "const_int_operand" "i")])
1115 (match_operand:SI 4 "const_int_operand" "i"))
1116 (match_operand:SI 2 "register_operand" "r")]))]
1118 && IN_RANGE (exact_log2 (INTVAL (operands[4])), 1, 3)"
1122 (zero_extract:SI (match_dup 1)
1127 [(ashift:SI (match_dup 0)
1131 int pos = INTVAL (operands[3]), shift = floor_log2 (INTVAL (operands[4]));
1132 switch (GET_CODE (operands[6]))
1143 if (BITS_BIG_ENDIAN)
1144 pos = (32 - (1 + pos)) & 0x1f;
1145 operands[3] = GEN_INT (pos);
1146 operands[4] = GEN_INT (shift);
1148 [(set_attr "type" "arith")
1149 (set_attr "mode" "SI")
1150 (set_attr "length" "6")])
1155 (define_insn "fix_truncsfsi2"
1156 [(set (match_operand:SI 0 "register_operand" "=a")
1157 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
1159 "trunc.s\t%0, %1, 0"
1160 [(set_attr "type" "fconv")
1161 (set_attr "mode" "SF")
1162 (set_attr "length" "3")])
1164 (define_insn "fixuns_truncsfsi2"
1165 [(set (match_operand:SI 0 "register_operand" "=a")
1166 (unsigned_fix:SI (match_operand:SF 1 "register_operand" "f")))]
1168 "utrunc.s\t%0, %1, 0"
1169 [(set_attr "type" "fconv")
1170 (set_attr "mode" "SF")
1171 (set_attr "length" "3")])
1173 (define_insn "floatsisf2"
1174 [(set (match_operand:SF 0 "register_operand" "=f")
1175 (float:SF (match_operand:SI 1 "register_operand" "a")))]
1177 "float.s\t%0, %1, 0"
1178 [(set_attr "type" "fconv")
1179 (set_attr "mode" "SF")
1180 (set_attr "length" "3")])
1182 (define_insn "floatunssisf2"
1183 [(set (match_operand:SF 0 "register_operand" "=f")
1184 (unsigned_float:SF (match_operand:SI 1 "register_operand" "a")))]
1186 "ufloat.s\t%0, %1, 0"
1187 [(set_attr "type" "fconv")
1188 (set_attr "mode" "SF")
1189 (set_attr "length" "3")])
1192 ;; Data movement instructions.
1194 ;; 64-bit Integer moves
1196 (define_expand "movdi"
1197 [(set (match_operand:DI 0 "nonimmed_operand" "")
1198 (match_operand:DI 1 "general_operand" ""))]
1201 if (CONSTANT_P (operands[1]))
1203 /* Split in halves if 64-bit Const-to-Reg moves
1204 because of offering further optimization opportunities. */
1205 if (register_operand (operands[0], DImode))
1207 rtx ops[4] = { operands[0], operands[1] };
1208 xtensa_split_DI_reg_imm (ops);
1209 emit_move_insn (ops[0], ops[1]);
1210 emit_move_insn (ops[2], ops[3]);
1214 if (!TARGET_CONST16)
1215 operands[1] = force_const_mem (DImode, operands[1]);
1218 if (!register_operand (operands[0], DImode)
1219 && !register_operand (operands[1], DImode))
1220 operands[1] = force_reg (DImode, operands[1]);
1222 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1225 (define_insn_and_split "movdi_internal"
1226 [(set (match_operand:DI 0 "nonimmed_operand" "=a,W,a,a,U")
1227 (match_operand:DI 1 "move_operand" "r,i,T,U,r"))]
1228 "register_operand (operands[0], DImode)
1229 || register_operand (operands[1], DImode)"
1231 "&& reload_completed"
1232 [(set (match_dup 0) (match_dup 2))
1233 (set (match_dup 1) (match_dup 3))]
1235 xtensa_split_operand_pair (operands, SImode);
1236 if (reg_overlap_mentioned_p (operands[0], operands[3]))
1239 tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
1240 tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
1245 [(set (match_operand:DI 0 "register_operand")
1246 (match_operand:DI 1 "const_int_operand"))]
1247 "!TARGET_CONST16 && !TARGET_AUTO_LITPOOLS
1248 && ! xtensa_split1_finished_p ()"
1254 xtensa_split_DI_reg_imm (operands);
1257 ;; 32-bit Integer moves
1259 (define_expand "movsi"
1260 [(set (match_operand:SI 0 "nonimmed_operand" "")
1261 (match_operand:SI 1 "general_operand" ""))]
1264 if (xtensa_emit_move_sequence (operands, SImode))
1268 (define_insn "movsi_internal"
1269 [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,a,W,a,a,U,*a,*A")
1270 (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,Y,i,T,U,r,*A,*r"))]
1271 "xtensa_valid_move (SImode, operands)"
1283 const16\t%0, %t1\;const16\t%0, %b1
1289 [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,move,load,load,store,rsr,wsr")
1290 (set_attr "mode" "SI")
1291 (set_attr "length" "2,2,2,2,2,2,3,3,3,3,6,3,3,3,3,3")])
1294 [(set (match_operand:SI 0 "register_operand")
1295 (match_operand:SI 1 "const_int_operand"))]
1296 "!TARGET_CONST16 && !TARGET_AUTO_LITPOOLS
1297 && ! xtensa_split1_finished_p ()
1298 && ! xtensa_simm12b (INTVAL (operands[1]))"
1302 operands[1] = force_const_mem (SImode, operands[1]);
1306 [(set (match_operand:SI 0 "register_operand")
1307 (match_operand:SI 1 "constantpool_operand"))]
1308 "! optimize_debug && reload_completed"
1311 rtx x = avoid_constant_pool_reference (operands[1]);
1312 if (! CONST_INT_P (x))
1314 if (! xtensa_constantsynth (operands[0], INTVAL (x)))
1315 emit_move_insn (operands[0], x);
1319 ;; 16-bit Integer moves
1321 (define_expand "movhi"
1322 [(set (match_operand:HI 0 "nonimmed_operand" "")
1323 (match_operand:HI 1 "general_operand" ""))]
1326 if (xtensa_emit_move_sequence (operands, HImode))
1330 (define_insn "movhi_internal"
1331 [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,a,U,*a,*A")
1332 (match_operand:HI 1 "move_operand" "M,d,r,I,Y,U,r,*A,*r"))]
1333 "xtensa_valid_move (HImode, operands)"
1344 [(set_attr "type" "move,move,move,move,move,load,store,rsr,wsr")
1345 (set_attr "mode" "HI")
1346 (set_attr "length" "2,2,3,3,3,3,3,3,3")])
1348 ;; 8-bit Integer moves
1350 (define_expand "movqi"
1351 [(set (match_operand:QI 0 "nonimmed_operand" "")
1352 (match_operand:QI 1 "general_operand" ""))]
1355 if (xtensa_emit_move_sequence (operands, QImode))
1359 (define_insn "movqi_internal"
1360 [(set (match_operand:QI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
1361 (match_operand:QI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
1362 "xtensa_valid_move (QImode, operands)"
1372 [(set_attr "type" "move,move,move,move,load,store,rsr,wsr")
1373 (set_attr "mode" "QI")
1374 (set_attr "length" "2,2,3,3,3,3,3,3")])
1376 ;; Sub-word reloads from the constant pool.
1378 (define_expand "reload<mode>_literal"
1379 [(parallel [(match_operand:HQI 0 "register_operand" "=r")
1380 (match_operand:HQI 1 "constantpool_operand" "")
1381 (match_operand:SI 2 "register_operand" "=&r")])]
1385 unsigned word_off, byte_off;
1387 if (MEM_P (operands[1]))
1395 gcc_assert (GET_CODE (operands[1]) == SUBREG);
1396 lit = SUBREG_REG (operands[1]);
1397 word_off = SUBREG_BYTE (operands[1]) & ~(UNITS_PER_WORD - 1);
1398 byte_off = SUBREG_BYTE (operands[1]) - word_off;
1401 lit = adjust_address (lit, SImode, word_off);
1402 scratch = operands[2];
1403 emit_insn (gen_movsi (scratch, lit));
1404 emit_insn (gen_mov<mode> (operands[0],
1405 gen_rtx_SUBREG (<MODE>mode, scratch, byte_off)));
1410 ;; 32-bit floating point moves
1412 (define_expand "movsf"
1413 [(set (match_operand:SF 0 "nonimmed_operand" "")
1414 (match_operand:SF 1 "general_operand" ""))]
1417 if (!TARGET_CONST16 && !TARGET_AUTO_LITPOOLS && CONSTANT_P (operands[1]))
1418 operands[1] = force_const_mem (SFmode, operands[1]);
1420 if ((!register_operand (operands[0], SFmode)
1421 && !register_operand (operands[1], SFmode))
1422 || (FP_REG_P (xt_true_regnum (operands[0]))
1423 && !(reload_in_progress | reload_completed)
1424 && (constantpool_mem_p (operands[1])
1425 || CONSTANT_P (operands[1]))))
1426 operands[1] = force_reg (SFmode, operands[1]);
1428 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1431 (define_insn "movsf_internal"
1432 [(set (match_operand:SF 0 "nonimmed_operand" "=f,f,U,D,D,R,a,f,a,a,W,a,a,U")
1433 (match_operand:SF 1 "move_operand" "f,U,f,d,R,d,r,r,f,Y,iF,T,U,r"))]
1434 "((register_operand (operands[0], SFmode)
1435 || register_operand (operands[1], SFmode))
1436 && !(FP_REG_P (xt_true_regnum (operands[0]))
1437 && (constantpool_mem_p (operands[1]) || CONSTANT_P (operands[1]))))"
1449 const16\t%0, %t1\;const16\t%0, %b1
1453 [(set_attr "type" "farith,fload,fstore,move,load,store,move,farith,farith,move,move,load,load,store")
1454 (set_attr "mode" "SF")
1455 (set_attr "length" "3,3,3,2,2,2,3,3,3,3,6,3,3,3")])
1457 (define_insn "*lsiu"
1458 [(set (match_operand:SF 0 "register_operand" "=f")
1459 (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "+a")
1460 (match_operand:SI 2 "fpmem_offset_operand" "i"))))
1462 (plus:SI (match_dup 1) (match_dup 2)))]
1463 "TARGET_HARD_FLOAT && !TARGET_HARD_FLOAT_POSTINC"
1465 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
1466 output_asm_insn ("memw", operands);
1467 return "lsiu\t%0, %1, %2";
1469 [(set_attr "type" "fload")
1470 (set_attr "mode" "SF")
1471 (set_attr "length" "3")])
1473 (define_insn "*ssiu"
1474 [(set (mem:SF (plus:SI (match_operand:SI 0 "register_operand" "+a")
1475 (match_operand:SI 1 "fpmem_offset_operand" "i")))
1476 (match_operand:SF 2 "register_operand" "f"))
1478 (plus:SI (match_dup 0) (match_dup 1)))]
1479 "TARGET_HARD_FLOAT && !TARGET_HARD_FLOAT_POSTINC"
1481 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
1482 output_asm_insn ("memw", operands);
1483 return "ssiu\t%2, %0, %1";
1485 [(set_attr "type" "fstore")
1486 (set_attr "mode" "SF")
1487 (set_attr "length" "3")])
1489 (define_insn "*lsip"
1490 [(set (match_operand:SF 0 "register_operand" "=f")
1491 (mem:SF (match_operand:SI 1 "register_operand" "+a")))
1493 (plus:SI (match_dup 1)
1494 (match_operand:SI 2 "fpmem_offset_operand" "i")))]
1495 "TARGET_HARD_FLOAT && TARGET_HARD_FLOAT_POSTINC"
1497 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
1498 output_asm_insn ("memw", operands);
1499 return "lsip\t%0, %1, %2";
1501 [(set_attr "type" "fload")
1502 (set_attr "mode" "SF")
1503 (set_attr "length" "3")])
1505 (define_insn "*ssip"
1506 [(set (mem:SF (match_operand:SI 0 "register_operand" "+a"))
1507 (match_operand:SF 1 "register_operand" "f"))
1509 (plus:SI (match_dup 0)
1510 (match_operand:SI 2 "fpmem_offset_operand" "i")))]
1511 "TARGET_HARD_FLOAT && TARGET_HARD_FLOAT_POSTINC"
1513 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
1514 output_asm_insn ("memw", operands);
1515 return "ssip\t%1, %0, %2";
1517 [(set_attr "type" "fstore")
1518 (set_attr "mode" "SF")
1519 (set_attr "length" "3")])
1522 [(set (match_operand:SF 0 "register_operand")
1523 (match_operand:SF 1 "constantpool_operand"))]
1524 "! optimize_debug && reload_completed"
1527 rtx x = avoid_constant_pool_reference (operands[1]);
1529 HOST_WIDE_INT value;
1530 if (! CONST_DOUBLE_P (x) || GET_MODE (x) != SFmode)
1532 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l);
1533 x = gen_rtx_REG (SImode, REGNO (operands[0]));
1535 if (! xtensa_constantsynth (x, value))
1536 emit_move_insn (x, GEN_INT (value));
1540 ;; 64-bit floating point moves
1542 (define_expand "movdf"
1543 [(set (match_operand:DF 0 "nonimmed_operand" "")
1544 (match_operand:DF 1 "general_operand" ""))]
1547 if (CONSTANT_P (operands[1]) && !TARGET_CONST16 && !TARGET_AUTO_LITPOOLS)
1548 operands[1] = force_const_mem (DFmode, operands[1]);
1550 if (!register_operand (operands[0], DFmode)
1551 && !register_operand (operands[1], DFmode))
1552 operands[1] = force_reg (DFmode, operands[1]);
1554 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1557 (define_insn_and_split "movdf_internal"
1558 [(set (match_operand:DF 0 "nonimmed_operand" "=a,a,W,a,a,U")
1559 (match_operand:DF 1 "move_operand" "r,Y,iF,T,U,r"))]
1560 "register_operand (operands[0], DFmode)
1561 || register_operand (operands[1], DFmode)"
1563 "&& reload_completed"
1564 [(set (match_dup 0) (match_dup 2))
1565 (set (match_dup 1) (match_dup 3))]
1567 xtensa_split_operand_pair (operands, SFmode);
1568 if (reg_overlap_mentioned_p (operands[0], operands[3]))
1571 tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
1572 tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
1578 (define_expand "cpymemsi"
1579 [(parallel [(set (match_operand:BLK 0 "" "")
1580 (match_operand:BLK 1 "" ""))
1581 (use (match_operand:SI 2 "arith_operand" ""))
1582 (use (match_operand:SI 3 "const_int_operand" ""))])]
1585 if (!xtensa_expand_block_move (operands))
1592 (define_expand "setmemsi"
1593 [(match_operand:BLK 0 "memory_operand")
1594 (match_operand:SI 1 "")
1595 (match_operand:SI 2 "")
1596 (match_operand:SI 3 "const_int_operand")]
1597 "!optimize_debug && optimize"
1599 if (xtensa_expand_block_set (operands))
1605 ;; Shift instructions.
1607 (define_expand "ashlsi3"
1608 [(set (match_operand:SI 0 "register_operand" "")
1609 (ashift:SI (match_operand:SI 1 "register_operand" "")
1610 (match_operand:SI 2 "arith_operand" "")))]
1613 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1616 (define_insn "ashlsi3_internal"
1617 [(set (match_operand:SI 0 "register_operand" "=a,a")
1618 (ashift:SI (match_operand:SI 1 "register_operand" "r,r")
1619 (match_operand:SI 2 "arith_operand" "J,r")))]
1623 ssl\t%2\;sll\t%0, %1"
1624 [(set_attr "type" "arith,arith")
1625 (set_attr "mode" "SI")
1626 (set_attr "length" "3,6")])
1629 [(set (match_operand:SI 0 "register_operand")
1630 (ashift:SI (match_operand:SI 1 "register_operand")
1634 (plus:SI (match_dup 1)
1637 (define_insn "ashrsi3"
1638 [(set (match_operand:SI 0 "register_operand" "=a,a")
1639 (ashiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1640 (match_operand:SI 2 "arith_operand" "J,r")))]
1644 ssr\t%2\;sra\t%0, %1"
1645 [(set_attr "type" "arith,arith")
1646 (set_attr "mode" "SI")
1647 (set_attr "length" "3,6")])
1649 (define_insn "lshrsi3"
1650 [(set (match_operand:SI 0 "register_operand" "=a,a")
1651 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1652 (match_operand:SI 2 "arith_operand" "J,r")))]
1655 if (which_alternative == 0)
1657 if ((INTVAL (operands[2]) & 0x1f) < 16)
1658 return "srli\t%0, %1, %R2";
1660 return "extui\t%0, %1, %R2, %L2";
1662 return "ssr\t%2\;srl\t%0, %1";
1664 [(set_attr "type" "arith,arith")
1665 (set_attr "mode" "SI")
1666 (set_attr "length" "3,6")])
1668 (define_insn "*shift_per_byte"
1669 [(set (match_operand:SI 0 "register_operand" "=a")
1670 (match_operator:SI 3 "xtensa_shift_per_byte_operator"
1671 [(match_operand:SI 1 "register_operand" "r")
1672 (ashift:SI (match_operand:SI 2 "register_operand" "r")
1674 "!optimize_debug && optimize"
1676 switch (GET_CODE (operands[3]))
1678 case ASHIFT: return "ssa8b\t%2\;sll\t%0, %1";
1679 case ASHIFTRT: return "ssa8l\t%2\;sra\t%0, %1";
1680 case LSHIFTRT: return "ssa8l\t%2\;srl\t%0, %1";
1681 default: gcc_unreachable ();
1684 [(set_attr "type" "arith")
1685 (set_attr "mode" "SI")
1686 (set_attr "length" "6")])
1688 (define_insn_and_split "*shift_per_byte_omit_AND_0"
1689 [(set (match_operand:SI 0 "register_operand" "=a")
1690 (match_operator:SI 4 "xtensa_shift_per_byte_operator"
1691 [(match_operand:SI 1 "register_operand" "r")
1692 (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1694 (match_operand:SI 3 "const_int_operand" "i"))]))]
1695 "!optimize_debug && optimize
1696 && (INTVAL (operands[3]) & 0x1f) == 3 << 3"
1702 (ashift:SI (match_dup 2)
1705 [(set_attr "type" "arith")
1706 (set_attr "mode" "SI")
1707 (set_attr "length" "6")])
1709 (define_insn_and_split "*shift_per_byte_omit_AND_1"
1710 [(set (match_operand:SI 0 "register_operand" "=a")
1711 (match_operator:SI 4 "xtensa_shift_per_byte_operator"
1712 [(match_operand:SI 1 "register_operand" "r")
1713 (neg:SI (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1715 (match_operand:SI 3 "const_int_operand" "i")))]))]
1716 "!optimize_debug && optimize
1717 && (INTVAL (operands[3]) & 0x1f) == 3 << 3"
1719 "&& can_create_pseudo_p ()"
1721 (neg:SI (match_dup 2)))
1725 (ashift:SI (match_dup 5)
1728 operands[5] = gen_reg_rtx (SImode);
1730 [(set_attr "type" "arith")
1731 (set_attr "mode" "SI")
1732 (set_attr "length" "9")])
1734 (define_insn "*shlrd_reg"
1735 [(set (match_operand:SI 0 "register_operand" "=a")
1736 (match_operator:SI 6 "xtensa_bit_join_operator"
1737 [(match_operator:SI 4 "logical_shift_operator"
1738 [(match_operand:SI 1 "register_operand" "r")
1739 (match_operand:SI 3 "register_operand" "r")])
1740 (match_operator:SI 5 "logical_shift_operator"
1741 [(match_operand:SI 2 "register_operand" "r")
1742 (neg:SI (match_dup 3))])]))]
1743 "!optimize_debug && optimize
1744 && xtensa_shlrd_which_direction (operands[4], operands[5]) != UNKNOWN"
1746 switch (xtensa_shlrd_which_direction (operands[4], operands[5]))
1748 case ASHIFT: return "ssl\t%3\;src\t%0, %1, %2";
1749 case LSHIFTRT: return "ssr\t%3\;src\t%0, %2, %1";
1750 default: gcc_unreachable ();
1753 [(set_attr "type" "arith")
1754 (set_attr "mode" "SI")
1755 (set_attr "length" "6")])
1757 (define_insn_and_split "*shlrd_reg"
1758 [(set (match_operand:SI 0 "register_operand" "=a")
1759 (match_operator:SI 6 "xtensa_bit_join_operator"
1760 [(match_operator:SI 4 "logical_shift_operator"
1761 [(match_operand:SI 1 "register_operand" "r")
1762 (neg:SI (match_operand:SI 3 "register_operand" "r"))])
1763 (match_operator:SI 5 "logical_shift_operator"
1764 [(match_operand:SI 2 "register_operand" "r")
1766 "!optimize_debug && optimize
1767 && xtensa_shlrd_which_direction (operands[5], operands[4]) != UNKNOWN"
1777 (neg:SI (match_dup 3))])]))]
1779 [(set_attr "type" "arith")
1780 (set_attr "mode" "SI")
1781 (set_attr "length" "6")])
1784 (define_insn "*shlrd_const"
1785 [(set (match_operand:SI 0 "register_operand" "=a")
1786 (match_operator:SI 7 "xtensa_bit_join_operator"
1787 [(match_operator:SI 5 "logical_shift_operator"
1788 [(match_operand:SI 1 "register_operand" "r")
1789 (match_operand:SI 3 "const_int_operand" "i")])
1790 (match_operator:SI 6 "logical_shift_operator"
1791 [(match_operand:SI 2 "register_operand" "r")
1792 (match_operand:SI 4 "const_int_operand" "i")])]))]
1793 "!optimize_debug && optimize
1794 && xtensa_shlrd_which_direction (operands[5], operands[6]) != UNKNOWN
1795 && IN_RANGE (INTVAL (operands[3]), 1, 31)
1796 && IN_RANGE (INTVAL (operands[4]), 1, 31)
1797 && INTVAL (operands[3]) + INTVAL (operands[4]) == 32"
1799 switch (xtensa_shlrd_which_direction (operands[5], operands[6]))
1801 case ASHIFT: return "ssai\t%L3\;src\t%0, %1, %2";
1802 case LSHIFTRT: return "ssai\t%R3\;src\t%0, %2, %1";
1803 default: gcc_unreachable ();
1806 [(set_attr "type" "arith")
1807 (set_attr "mode" "SI")
1808 (set_attr "length" "6")])
1810 (define_insn "*shlrd_per_byte"
1811 [(set (match_operand:SI 0 "register_operand" "=a")
1812 (match_operator:SI 6 "xtensa_bit_join_operator"
1813 [(match_operator:SI 4 "logical_shift_operator"
1814 [(match_operand:SI 1 "register_operand" "r")
1815 (ashift:SI (match_operand:SI 2 "register_operand" "r")
1817 (match_operator:SI 5 "logical_shift_operator"
1818 [(match_operand:SI 3 "register_operand" "r")
1819 (neg:SI (ashift:SI (match_dup 2)
1820 (const_int 3)))])]))]
1821 "!optimize_debug && optimize
1822 && xtensa_shlrd_which_direction (operands[4], operands[5]) != UNKNOWN"
1824 switch (xtensa_shlrd_which_direction (operands[4], operands[5]))
1826 case ASHIFT: return "ssa8b\t%2\;src\t%0, %1, %3";
1827 case LSHIFTRT: return "ssa8l\t%2\;src\t%0, %3, %1";
1828 default: gcc_unreachable ();
1831 [(set_attr "type" "arith")
1832 (set_attr "mode" "SI")
1833 (set_attr "length" "6")])
1835 (define_insn_and_split "*shlrd_per_byte_omit_AND"
1836 [(set (match_operand:SI 0 "register_operand" "=a")
1837 (match_operator:SI 7 "xtensa_bit_join_operator"
1838 [(match_operator:SI 5 "logical_shift_operator"
1839 [(match_operand:SI 1 "register_operand" "r")
1840 (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1842 (match_operand:SI 4 "const_int_operand" "i"))])
1843 (match_operator:SI 6 "logical_shift_operator"
1844 [(match_operand:SI 3 "register_operand" "r")
1845 (neg:SI (and:SI (ashift:SI (match_dup 2)
1847 (match_dup 4)))])]))]
1848 "!optimize_debug && optimize
1849 && xtensa_shlrd_which_direction (operands[5], operands[6]) != UNKNOWN
1850 && (INTVAL (operands[4]) & 0x1f) == 3 << 3"
1857 (ashift:SI (match_dup 2)
1861 (neg:SI (ashift:SI (match_dup 2)
1862 (const_int 3)))])]))]
1864 [(set_attr "type" "arith")
1865 (set_attr "mode" "SI")
1866 (set_attr "length" "6")])
1868 (define_insn "rotlsi3"
1869 [(set (match_operand:SI 0 "register_operand" "=a,a")
1870 (rotate:SI (match_operand:SI 1 "register_operand" "r,r")
1871 (match_operand:SI 2 "arith_operand" "J,r")))]
1874 ssai\t%L2\;src\t%0, %1, %1
1875 ssl\t%2\;src\t%0, %1, %1"
1876 [(set_attr "type" "multi,multi")
1877 (set_attr "mode" "SI")
1878 (set_attr "length" "6,6")])
1880 (define_insn "rotrsi3"
1881 [(set (match_operand:SI 0 "register_operand" "=a,a")
1882 (rotatert:SI (match_operand:SI 1 "register_operand" "r,r")
1883 (match_operand:SI 2 "arith_operand" "J,r")))]
1886 ssai\t%R2\;src\t%0, %1, %1
1887 ssr\t%2\;src\t%0, %1, %1"
1888 [(set_attr "type" "multi,multi")
1889 (set_attr "mode" "SI")
1890 (set_attr "length" "6,6")])
1895 ;; Conditional branches.
1897 (define_expand "cbranchsi4"
1898 [(match_operator 0 "comparison_operator"
1899 [(match_operand:SI 1 "register_operand")
1900 (match_operand:SI 2 "nonmemory_operand")])
1901 (match_operand 3 "")]
1904 xtensa_expand_conditional_branch (operands, SImode);
1908 (define_expand "cbranchsf4"
1909 [(match_operator 0 "comparison_operator"
1910 [(match_operand:SF 1 "register_operand")
1911 (match_operand:SF 2 "register_operand")])
1912 (match_operand 3 "")]
1915 xtensa_expand_conditional_branch (operands, SFmode);
1919 ;; Branch patterns for standard integer comparisons
1921 (define_insn "*btrue"
1923 (if_then_else (match_operator 3 "branch_operator"
1924 [(match_operand:SI 0 "register_operand" "r,r")
1925 (match_operand:SI 1 "branch_operand" "K,?r")])
1926 (label_ref (match_operand 2 "" ""))
1930 return xtensa_emit_branch (which_alternative == 0, operands);
1932 [(set_attr "type" "jump,jump")
1933 (set_attr "mode" "none")
1934 (set (attr "length")
1935 (if_then_else (match_test "TARGET_DENSITY
1936 && CONST_INT_P (operands[1])
1937 && INTVAL (operands[1]) == 0
1938 && (GET_CODE (operands[3]) == EQ
1939 || GET_CODE (operands[3]) == NE)")
1943 (define_insn_and_split "*btrue_INT_MIN"
1945 (if_then_else (match_operator 2 "boolean_operator"
1946 [(match_operand:SI 0 "register_operand" "r")
1947 (const_int -2147483648)])
1948 (label_ref (match_operand 1 ""))
1952 "&& can_create_pseudo_p ()"
1954 (abs:SI (match_dup 0)))
1956 (if_then_else (match_op_dup 2
1957 [(zero_extract:SI (match_dup 3)
1961 (label_ref (match_dup 1))
1964 operands[3] = gen_reg_rtx (SImode);
1965 operands[4] = GEN_INT (BITS_BIG_ENDIAN ? 0 : 31);
1966 operands[2] = gen_rtx_fmt_ee (reverse_condition (GET_CODE (operands[2])),
1967 VOIDmode, XEXP (operands[2], 0),
1970 [(set_attr "type" "jump")
1971 (set_attr "mode" "none")
1972 (set_attr "length" "6")])
1974 (define_insn "*ubtrue"
1976 (if_then_else (match_operator 3 "ubranch_operator"
1977 [(match_operand:SI 0 "register_operand" "r,r")
1978 (match_operand:SI 1 "ubranch_operand" "L,r")])
1979 (label_ref (match_operand 2 "" ""))
1983 return xtensa_emit_branch (which_alternative == 0, operands);
1985 [(set_attr "type" "jump,jump")
1986 (set_attr "mode" "none")
1987 (set_attr "length" "3,3")])
1989 ;; Branch patterns for bit testing
1991 (define_insn "*bittrue"
1993 (if_then_else (match_operator 3 "boolean_operator"
1994 [(zero_extract:SI (match_operand:SI 0 "register_operand" "r,r")
1996 (match_operand:SI 1 "arith_operand" "J,r"))
1998 (label_ref (match_operand 2 "" ""))
2002 static char result[64];
2004 switch (GET_CODE (operands[3]))
2006 case EQ: op = 'c'; break;
2007 case NE: op = 's'; break;
2008 default: gcc_unreachable ();
2010 if (which_alternative == 0)
2012 operands[1] = GEN_INT (INTVAL (operands[1]) & 0x1f);
2013 sprintf (result, "bb%ci\t%%0, %%d1, %%2", op);
2016 sprintf (result, "bb%c\t%%0, %%1, %%2", op);
2019 [(set_attr "type" "jump")
2020 (set_attr "mode" "none")
2021 (set_attr "length" "3")])
2023 (define_insn "*masktrue"
2025 (if_then_else (match_operator 3 "boolean_operator"
2026 [(and:SI (match_operand:SI 0 "register_operand" "r")
2027 (match_operand:SI 1 "register_operand" "r"))
2029 (label_ref (match_operand 2 "" ""))
2033 switch (GET_CODE (operands[3]))
2035 case EQ: return "bnone\t%0, %1, %2";
2036 case NE: return "bany\t%0, %1, %2";
2037 default: gcc_unreachable ();
2040 [(set_attr "type" "jump")
2041 (set_attr "mode" "none")
2042 (set_attr "length" "3")])
2044 (define_insn "*masktrue_bitcmpl"
2046 (if_then_else (match_operator 3 "boolean_operator"
2047 [(and:SI (not:SI (match_operand:SI 0 "register_operand" "r"))
2048 (match_operand:SI 1 "register_operand" "r"))
2050 (label_ref (match_operand 2 "" ""))
2054 switch (GET_CODE (operands[3]))
2056 case EQ: return "ball\t%0, %1, %2";
2057 case NE: return "bnall\t%0, %1, %2";
2058 default: gcc_unreachable ();
2061 [(set_attr "type" "jump")
2062 (set_attr "mode" "none")
2063 (set_attr "length" "3")])
2065 (define_insn_and_split "*masktrue_const_bitcmpl"
2067 (if_then_else (match_operator 3 "boolean_operator"
2068 [(and:SI (not:SI (match_operand:SI 0 "register_operand" "r"))
2069 (match_operand:SI 1 "const_int_operand" "i"))
2071 (label_ref (match_operand 2 "" ""))
2073 "exact_log2 (INTVAL (operands[1])) < 0"
2075 "&& can_create_pseudo_p ()"
2079 (if_then_else (match_op_dup 3
2080 [(and:SI (not:SI (match_dup 0))
2083 (label_ref (match_dup 2))
2086 operands[4] = gen_reg_rtx (SImode);
2088 [(set_attr "type" "jump")
2089 (set_attr "mode" "none")
2090 (set (attr "length")
2091 (if_then_else (match_test "TARGET_DENSITY
2092 && IN_RANGE (INTVAL (operands[1]), -32, 95)")
2094 (if_then_else (match_test "xtensa_simm12b (INTVAL (operands[1]))")
2100 (if_then_else (match_operator 2 "boolean_operator"
2101 [(subreg:HQI (not:SI (match_operand:SI 0 "register_operand")) 0)
2103 (label_ref (match_operand 1 ""))
2107 (if_then_else (match_op_dup 2
2108 [(and:SI (not:SI (match_dup 0))
2111 (label_ref (match_dup 1))
2114 operands[3] = GEN_INT ((1 << GET_MODE_BITSIZE (<MODE>mode)) - 1);
2119 (if_then_else (match_operator 2 "boolean_operator"
2120 [(subreg:HI (not:SI (match_operand:SI 0 "register_operand")) 2)
2122 (label_ref (match_operand 1 ""))
2126 (if_then_else (match_op_dup 2
2127 [(and:SI (not:SI (match_dup 0))
2130 (label_ref (match_dup 1))
2135 (if_then_else (match_operator 2 "boolean_operator"
2136 [(subreg:QI (not:SI (match_operand:SI 0 "register_operand")) 3)
2138 (label_ref (match_operand 1 ""))
2142 (if_then_else (match_op_dup 2
2143 [(and:SI (not:SI (match_dup 0))
2146 (label_ref (match_dup 1))
2149 (define_insn_and_split "*masktrue_const_pow2_minus_one"
2151 (if_then_else (match_operator 4 "boolean_operator"
2152 [(and:SI (match_operand:SI 0 "register_operand" "r")
2153 (match_operand:SI 1 "const_int_operand" "i"))
2154 (match_operand:SI 2 "const_int_operand" "i")])
2155 (label_ref (match_operand 3 "" ""))
2157 "IN_RANGE (exact_log2 (INTVAL (operands[1]) + 1), 17, 31)
2158 /* && (~INTVAL (operands[1]) & INTVAL (operands[2])) == 0 // can be omitted */
2159 && xtensa_b4const_or_zero (INTVAL (operands[2]) << (32 - floor_log2 (INTVAL (operands[1]) + 1)))"
2161 "&& can_create_pseudo_p ()"
2163 (ashift:SI (match_dup 0)
2166 (if_then_else (match_op_dup 4
2169 (label_ref (match_dup 3))
2172 int shift = 32 - floor_log2 (INTVAL (operands[1]) + 1);
2173 operands[1] = GEN_INT (shift);
2174 operands[2] = GEN_INT (INTVAL (operands[2]) << shift);
2175 operands[5] = gen_reg_rtx (SImode);
2177 [(set_attr "type" "jump")
2178 (set_attr "mode" "none")
2179 (set (attr "length")
2180 (if_then_else (match_test "(TARGET_DENSITY && INTVAL (operands[1]) == 0x7FFFFFFF)
2181 && INTVAL (operands[2]) == 0")
2183 (if_then_else (match_test "TARGET_DENSITY
2184 && (INTVAL (operands[1]) == 0x7FFFFFFF
2185 || INTVAL (operands[2]) == 0)")
2189 (define_insn_and_split "*masktrue_const_negative_pow2"
2191 (if_then_else (match_operator 4 "boolean_operator"
2192 [(and:SI (match_operand:SI 0 "register_operand" "r")
2193 (match_operand:SI 1 "const_int_operand" "i"))
2194 (match_operand:SI 2 "const_int_operand" "i")])
2195 (label_ref (match_operand 3 "" ""))
2197 "IN_RANGE (exact_log2 (-INTVAL (operands[1])), 1, 30)
2198 /* && (~INTVAL (operands[1]) & INTVAL (operands[2])) == 0 // can be omitted */
2199 && xtensa_b4const_or_zero (INTVAL (operands[2]) >> floor_log2 (-INTVAL (operands[1])))"
2201 "&& can_create_pseudo_p ()"
2203 (lshiftrt:SI (match_dup 0)
2206 (if_then_else (match_op_dup 4
2209 (label_ref (match_dup 3))
2212 int shift = floor_log2 (-INTVAL (operands[1]));
2213 operands[1] = GEN_INT (shift);
2214 operands[2] = GEN_INT (INTVAL (operands[2]) >> shift);
2215 operands[5] = gen_reg_rtx (SImode);
2217 [(set_attr "type" "jump")
2218 (set_attr "mode" "none")
2219 (set (attr "length")
2220 (if_then_else (match_test "TARGET_DENSITY && INTVAL (operands[2]) == 0")
2224 (define_insn_and_split "*masktrue_const_shifted_mask"
2226 (if_then_else (match_operator 4 "boolean_operator"
2227 [(and:SI (match_operand:SI 0 "register_operand" "r")
2228 (match_operand:SI 1 "shifted_mask_operand" "i"))
2229 (match_operand:SI 2 "const_int_operand" "i")])
2230 (label_ref (match_operand 3 "" ""))
2232 "/* (INTVAL (operands[2]) & ((1 << ctz_hwi (INTVAL (operands[1]))) - 1)) == 0 // can be omitted
2233 && */ xtensa_b4const_or_zero ((uint32_t)INTVAL (operands[2]) >> ctz_hwi (INTVAL (operands[1])))"
2235 "&& can_create_pseudo_p ()"
2237 (zero_extract:SI (match_dup 0)
2241 (if_then_else (match_op_dup 4
2244 (label_ref (match_dup 3))
2247 HOST_WIDE_INT mask = INTVAL (operands[1]);
2248 int shift = ctz_hwi (mask);
2249 int mask_size = floor_log2 (((uint32_t)mask >> shift) + 1);
2250 int mask_pos = shift;
2251 if (BITS_BIG_ENDIAN)
2252 mask_pos = (32 - (mask_size + shift)) & 0x1f;
2253 operands[1] = GEN_INT (mask_pos);
2254 operands[2] = GEN_INT ((uint32_t)INTVAL (operands[2]) >> shift);
2255 operands[5] = GEN_INT (mask_size);
2256 operands[6] = gen_reg_rtx (SImode);
2258 [(set_attr "type" "jump")
2259 (set_attr "mode" "none")
2260 (set (attr "length")
2261 (if_then_else (match_test "TARGET_DENSITY
2262 && (uint32_t)INTVAL (operands[2]) >> ctz_hwi (INTVAL (operands[1])) == 0")
2267 ;; Zero-overhead looping support.
2269 ;; Define the loop insns used by bct optimization to represent the
2270 ;; start and end of a zero-overhead loop. This start template generates
2271 ;; the loop insn; the end template doesn't generate any instructions since
2272 ;; loop end is handled in hardware.
2274 (define_insn "zero_cost_loop_start"
2276 (if_then_else (ne (match_operand:SI 2 "register_operand" "0")
2278 (label_ref (match_operand 1 "" ""))
2280 (set (match_operand:SI 0 "register_operand" "=a")
2281 (plus:SI (match_dup 0)
2283 (unspec [(const_int 0)] UNSPEC_LSETUP_START)]
2284 "TARGET_LOOPS && optimize"
2285 "loop\t%0, %l1_LEND"
2286 [(set_attr "type" "jump")
2287 (set_attr "mode" "none")
2288 (set_attr "length" "3")])
2290 (define_insn "zero_cost_loop_end"
2292 (if_then_else (ne (match_operand:SI 2 "nonimmediate_operand" "0,0")
2294 (label_ref (match_operand 1 "" ""))
2296 (set (match_operand:SI 0 "nonimmediate_operand" "=a,m")
2297 (plus:SI (match_dup 0)
2299 (unspec [(const_int 0)] UNSPEC_LSETUP_END)
2300 (clobber (match_scratch:SI 3 "=X,&r"))]
2301 "TARGET_LOOPS && optimize"
2303 [(set_attr "type" "jump")
2304 (set_attr "mode" "none")
2305 (set_attr "length" "0")])
2307 (define_insn "loop_end"
2309 (if_then_else (ne (match_operand:SI 2 "register_operand" "0")
2311 (label_ref (match_operand 1 "" ""))
2313 (set (match_operand:SI 0 "register_operand" "=a")
2314 (plus:SI (match_dup 0)
2316 (unspec [(const_int 0)] UNSPEC_LSETUP_END)]
2317 "TARGET_LOOPS && optimize"
2319 xtensa_emit_loop_end (insn, operands);
2322 [(set_attr "type" "jump")
2323 (set_attr "mode" "none")
2324 (set_attr "length" "0")])
2328 (if_then_else (ne (match_operand:SI 0 "nonimmediate_operand" "")
2330 (label_ref (match_operand 1 "" ""))
2332 (set (match_operand:SI 2 "nonimmediate_operand" "")
2333 (plus:SI (match_dup 0)
2335 (unspec [(const_int 0)] UNSPEC_LSETUP_END)
2336 (clobber (match_scratch 3))]
2337 "TARGET_LOOPS && optimize && reload_completed"
2340 if (!REG_P (operands[0]))
2344 /* Fallback into a normal conditional branch insn. */
2345 emit_move_insn (operands[3], operands[0]);
2346 emit_insn (gen_addsi3 (operands[3], operands[3], constm1_rtx));
2347 emit_move_insn (operands[0], operands[3]);
2348 test = gen_rtx_NE (VOIDmode, operands[3], const0_rtx);
2349 emit_jump_insn (gen_cbranchsi4 (test, operands[3],
2350 const0_rtx, operands[1]));
2354 emit_jump_insn (gen_loop_end (operands[0], operands[1], operands[2]));
2360 ; operand 0 is the loop count pseudo register
2361 ; operand 1 is the label to jump to at the top of the loop
2362 (define_expand "doloop_end"
2363 [(parallel [(set (pc) (if_then_else
2364 (ne (match_operand:SI 0 "" "")
2366 (label_ref (match_operand 1 "" ""))
2369 (plus:SI (match_dup 0)
2371 (unspec [(const_int 0)] UNSPEC_LSETUP_END)
2372 (clobber (match_dup 2))])] ; match_scratch
2373 "TARGET_LOOPS && optimize"
2375 /* The loop optimizer doesn't check the predicates... */
2376 if (GET_MODE (operands[0]) != SImode)
2378 operands[2] = gen_rtx_SCRATCH (SImode);
2382 ;; Setting a register from a comparison.
2384 (define_expand "cstoresi4"
2385 [(match_operand:SI 0 "register_operand")
2386 (match_operator 1 "xtensa_cstoresi_operator"
2387 [(match_operand:SI 2 "register_operand")
2388 (match_operand:SI 3 "nonmemory_operand")])]
2391 if (!xtensa_expand_scc (operands, SImode))
2397 [(set (match_operand:SI 0 "register_operand" "=a")
2398 (lt:SI (match_operand:SI 1 "register_operand" "r")
2399 (match_operand:SI 2 "register_operand" "r")))]
2402 [(set_attr "type" "arith")
2403 (set_attr "mode" "SI")
2404 (set_attr "length" "3")])
2406 (define_insn "saltu"
2407 [(set (match_operand:SI 0 "register_operand" "=a")
2408 (ltu:SI (match_operand:SI 1 "register_operand" "r")
2409 (match_operand:SI 2 "register_operand" "r")))]
2412 [(set_attr "type" "arith")
2413 (set_attr "mode" "SI")
2414 (set_attr "length" "3")])
2416 (define_expand "cstoresf4"
2417 [(match_operand:SI 0 "register_operand")
2418 (match_operator:SI 1 "comparison_operator"
2419 [(match_operand:SF 2 "register_operand")
2420 (match_operand:SF 3 "register_operand")])]
2423 if (!xtensa_expand_scc (operands, SFmode))
2430 ;; Conditional moves.
2432 (define_expand "movsicc"
2433 [(set (match_operand:SI 0 "register_operand" "")
2434 (if_then_else:SI (match_operand 1 "comparison_operator" "")
2435 (match_operand:SI 2 "register_operand" "")
2436 (match_operand:SI 3 "register_operand" "")))]
2439 if (!xtensa_expand_conditional_move (operands, 0))
2444 (define_expand "movsfcc"
2445 [(set (match_operand:SF 0 "register_operand" "")
2446 (if_then_else:SF (match_operand 1 "comparison_operator" "")
2447 (match_operand:SF 2 "register_operand" "")
2448 (match_operand:SF 3 "register_operand" "")))]
2451 if (!xtensa_expand_conditional_move (operands, 1))
2456 (define_insn "movsicc_internal0"
2457 [(set (match_operand:SI 0 "register_operand" "=a,a")
2458 (if_then_else:SI (match_operator 4 "branch_operator"
2459 [(match_operand:SI 1 "register_operand" "r,r")
2461 (match_operand:SI 2 "register_operand" "r,0")
2462 (match_operand:SI 3 "register_operand" "0,r")))]
2465 return xtensa_emit_movcc (which_alternative == 1, false, false, operands);
2467 [(set_attr "type" "move,move")
2468 (set_attr "mode" "SI")
2469 (set_attr "length" "3,3")])
2471 (define_insn "movsicc_internal1"
2472 [(set (match_operand:SI 0 "register_operand" "=a,a")
2473 (if_then_else:SI (match_operator 4 "boolean_operator"
2474 [(match_operand:CC 1 "register_operand" "b,b")
2476 (match_operand:SI 2 "register_operand" "r,0")
2477 (match_operand:SI 3 "register_operand" "0,r")))]
2480 return xtensa_emit_movcc (which_alternative == 1, false, true, operands);
2482 [(set_attr "type" "move,move")
2483 (set_attr "mode" "SI")
2484 (set_attr "length" "3,3")])
2486 (define_insn "movsfcc_internal0"
2487 [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
2488 (if_then_else:SF (match_operator 4 "branch_operator"
2489 [(match_operand:SI 1 "register_operand" "r,r,r,r")
2491 (match_operand:SF 2 "register_operand" "r,0,f,0")
2492 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
2495 return xtensa_emit_movcc ((which_alternative & 1) == 1,
2496 which_alternative >= 2, false, operands);
2498 [(set_attr "type" "move,move,move,move")
2499 (set_attr "mode" "SF")
2500 (set_attr "length" "3,3,3,3")])
2502 (define_insn "movsfcc_internal1"
2503 [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
2504 (if_then_else:SF (match_operator 4 "boolean_operator"
2505 [(match_operand:CC 1 "register_operand" "b,b,b,b")
2507 (match_operand:SF 2 "register_operand" "r,0,f,0")
2508 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
2511 return xtensa_emit_movcc ((which_alternative & 1) == 1,
2512 which_alternative >= 2, true, operands);
2514 [(set_attr "type" "move,move,move,move")
2515 (set_attr "mode" "SF")
2516 (set_attr "length" "3,3,3,3")])
2519 ;; Floating-point comparisons.
2521 (define_insn "s<code>_sf"
2522 [(set (match_operand:CC 0 "register_operand" "=b")
2523 (any_scc_sf:CC (match_operand:SF 1 "register_operand" "f")
2524 (match_operand:SF 2 "register_operand" "f")))]
2526 "<scc_sf>.s\t%0, %1, %2"
2527 [(set_attr "type" "farith")
2528 (set_attr "mode" "BL")
2529 (set_attr "length" "3")])
2532 ;; Unconditional branches.
2536 (label_ref (match_operand 0 "" "")))]
2539 [(set_attr "type" "jump")
2540 (set_attr "mode" "none")
2541 (set_attr "length" "3")])
2543 (define_expand "indirect_jump"
2545 (match_operand 0 "register_operand" ""))]
2548 rtx dest = operands[0];
2549 if (GET_CODE (dest) != REG || GET_MODE (dest) != Pmode)
2550 operands[0] = copy_to_mode_reg (Pmode, dest);
2552 emit_jump_insn (gen_indirect_jump_internal (dest));
2556 (define_insn "indirect_jump_internal"
2557 [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
2560 [(set_attr "type" "jump")
2561 (set_attr "mode" "none")
2562 (set_attr "length" "3")])
2565 (define_expand "tablejump"
2566 [(use (match_operand:SI 0 "register_operand" ""))
2567 (use (label_ref (match_operand 1 "" "")))]
2570 rtx target = operands[0];
2573 /* For PIC, the table entry is relative to the start of the table. */
2574 rtx label = gen_reg_rtx (SImode);
2575 target = gen_reg_rtx (SImode);
2576 emit_move_insn (label, gen_rtx_LABEL_REF (SImode, operands[1]));
2577 emit_insn (gen_addsi3 (target, operands[0], label));
2579 emit_jump_insn (gen_tablejump_internal (target, operands[1]));
2583 (define_insn "tablejump_internal"
2585 (match_operand:SI 0 "register_operand" "r"))
2586 (use (label_ref (match_operand 1 "" "")))]
2589 [(set_attr "type" "jump")
2590 (set_attr "mode" "none")
2591 (set_attr "length" "3")])
2596 (define_expand "sym_PLT"
2597 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PLT))]
2601 (define_expand "call"
2602 [(call (match_operand 0 "memory_operand" "")
2603 (match_operand 1 "" ""))]
2606 xtensa_expand_call (0, operands);
2610 (define_insn "call_internal"
2611 [(call (mem (match_operand:SI 0 "call_insn_operand" "nir"))
2612 (match_operand 1 "" "i"))]
2613 "!SIBLING_CALL_P (insn)"
2615 return xtensa_emit_call (0, operands);
2617 [(set_attr "type" "call")
2618 (set_attr "mode" "none")
2619 (set_attr "length" "3")])
2621 (define_expand "call_value"
2622 [(set (match_operand 0 "register_operand" "")
2623 (call (match_operand 1 "memory_operand" "")
2624 (match_operand 2 "" "")))]
2627 xtensa_expand_call (1, operands);
2631 (define_insn "call_value_internal"
2632 [(set (match_operand 0 "register_operand" "=a")
2633 (call (mem (match_operand:SI 1 "call_insn_operand" "nir"))
2634 (match_operand 2 "" "i")))]
2635 "!SIBLING_CALL_P (insn)"
2637 return xtensa_emit_call (1, operands);
2639 [(set_attr "type" "call")
2640 (set_attr "mode" "none")
2641 (set_attr "length" "3")])
2643 (define_expand "sibcall"
2644 [(call (match_operand 0 "memory_operand" "")
2645 (match_operand 1 "" ""))]
2646 "!TARGET_WINDOWED_ABI"
2648 xtensa_expand_call (0, operands);
2652 (define_insn "sibcall_internal"
2653 [(call (mem:SI (match_operand:SI 0 "call_insn_operand" "nic"))
2654 (match_operand 1 "" "i"))]
2655 "!TARGET_WINDOWED_ABI && SIBLING_CALL_P (insn)"
2657 return xtensa_emit_sibcall (0, operands);
2659 [(set_attr "type" "call")
2660 (set_attr "mode" "none")
2661 (set_attr "length" "3")])
2663 (define_expand "sibcall_value"
2664 [(set (match_operand 0 "register_operand" "")
2665 (call (match_operand 1 "memory_operand" "")
2666 (match_operand 2 "" "")))]
2667 "!TARGET_WINDOWED_ABI"
2669 xtensa_expand_call (1, operands);
2673 (define_insn "sibcall_value_internal"
2674 [(set (match_operand 0 "register_operand" "=a")
2675 (call (mem:SI (match_operand:SI 1 "call_insn_operand" "nic"))
2676 (match_operand 2 "" "i")))]
2677 "!TARGET_WINDOWED_ABI && SIBLING_CALL_P (insn)"
2679 return xtensa_emit_sibcall (1, operands);
2681 [(set_attr "type" "call")
2682 (set_attr "mode" "none")
2683 (set_attr "length" "3")])
2685 (define_expand "untyped_call"
2686 [(parallel [(call (match_operand 0 "")
2688 (match_operand 1 "")
2689 (match_operand 2 "")])]
2694 emit_call_insn (gen_call (operands[0], const0_rtx));
2696 for (i = 0; i < XVECLEN (operands[2], 0); i++)
2698 rtx set = XVECEXP (operands[2], 0, i);
2699 emit_move_insn (SET_DEST (set), SET_SRC (set));
2702 emit_insn (gen_blockage ());
2706 (define_insn "entry"
2707 [(set (reg:SI A1_REG)
2708 (unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "i")]
2712 [(set_attr "type" "entry")
2713 (set_attr "mode" "SI")
2714 (set_attr "length" "3")])
2716 (define_insn "return"
2718 (use (reg:SI A0_REG))]
2719 "xtensa_use_return_instruction_p ()"
2721 return TARGET_WINDOWED_ABI ?
2722 (TARGET_DENSITY ? "retw.n" : "retw") :
2723 (TARGET_DENSITY ? "ret.n" : "ret");
2725 [(set_attr "type" "jump")
2726 (set_attr "mode" "none")
2727 (set (attr "length")
2728 (if_then_else (match_test "TARGET_DENSITY")
2733 ;; Miscellaneous instructions.
2735 ;; In windowed ABI stack pointer adjustment must happen before any access
2736 ;; to the space allocated on stack is allowed, otherwise register spill
2737 ;; area may be clobbered. That's what frame blockage is supposed to enforce.
2739 (define_expand "allocate_stack"
2740 [(set (match_operand 0 "nonimmed_operand")
2741 (minus (reg A1_REG) (match_operand 1 "add_operand")))
2743 (minus (reg A1_REG) (match_dup 1)))]
2744 "TARGET_WINDOWED_ABI"
2746 if (CONST_INT_P (operands[1]))
2748 rtx neg_op0 = GEN_INT (-INTVAL (operands[1]));
2749 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
2753 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx,
2756 emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
2757 emit_insn (gen_frame_blockage ());
2761 (define_expand "prologue"
2765 xtensa_expand_prologue ();
2769 (define_expand "epilogue"
2773 xtensa_expand_epilogue (false);
2777 (define_expand "sibcall_epilogue"
2779 "!TARGET_WINDOWED_ABI"
2781 xtensa_expand_epilogue (true);
2789 return (TARGET_DENSITY ? "nop.n" : "nop");
2791 [(set_attr "type" "nop")
2792 (set_attr "mode" "none")
2793 (set (attr "length")
2794 (if_then_else (match_test "TARGET_DENSITY")
2798 (define_expand "nonlocal_goto"
2799 [(match_operand:SI 0 "general_operand" "")
2800 (match_operand:SI 1 "general_operand" "")
2801 (match_operand:SI 2 "general_operand" "")
2802 (match_operand:SI 3 "" "")]
2803 "TARGET_WINDOWED_ABI"
2805 xtensa_expand_nonlocal_goto (operands);
2809 ;; Stuff an address into the return address register along with the window
2810 ;; size in the high bits. Because we don't have the window size of the
2811 ;; previous frame, assume the function called out with a CALL8 since that
2812 ;; is what compilers always use. Note: __builtin_frob_return_addr has
2813 ;; already been applied to the handler, but the generic version doesn't
2814 ;; allow us to frob it quite enough, so we just frob here.
2816 (define_expand "eh_return"
2817 [(use (match_operand 0 "general_operand"))]
2820 if (TARGET_WINDOWED_ABI)
2821 emit_insn (gen_eh_set_a0_windowed (operands[0]));
2823 emit_insn (gen_eh_set_a0_call0 (operands[0]));
2827 (define_insn_and_split "eh_set_a0_windowed"
2828 [(set (reg:SI A0_REG)
2829 (unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")]
2831 (clobber (match_scratch:SI 1 "=r"))]
2835 [(set (match_dup 1) (ashift:SI (match_dup 0) (const_int 2)))
2836 (set (match_dup 1) (plus:SI (match_dup 1) (const_int 2)))
2837 (set (reg:SI A0_REG) (rotatert:SI (match_dup 1) (const_int 2)))]
2840 (define_insn_and_split "eh_set_a0_call0"
2841 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
2843 (clobber (match_scratch:SI 1 "=r"))]
2849 xtensa_set_return_address (operands[0], operands[1]);
2853 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
2854 ;; all of memory. This blocks insns from being moved across this point.
2856 (define_insn "blockage"
2857 [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
2860 [(set_attr "type" "nop")
2861 (set_attr "mode" "none")
2862 (set_attr "length" "0")])
2864 ;; Do not schedule instructions accessing memory before this point.
2866 (define_expand "frame_blockage"
2868 (unspec:BLK [(match_dup 1)] UNSPEC_FRAME_BLOCKAGE))]
2871 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
2872 MEM_VOLATILE_P (operands[0]) = 1;
2873 operands[1] = stack_pointer_rtx;
2876 (define_insn "*frame_blockage"
2877 [(set (match_operand:BLK 0 "" "")
2878 (unspec:BLK [(match_operand:SI 1 "" "")] UNSPEC_FRAME_BLOCKAGE))]
2881 [(set_attr "type" "nop")
2882 (set_attr "mode" "none")
2883 (set_attr "length" "0")])
2886 [(trap_if (const_int 1) (const_int 0))]
2890 return "break\t1, 15";
2892 return (TARGET_DENSITY ? "ill.n" : "ill");
2894 [(set_attr "type" "trap")
2895 (set_attr "mode" "none")
2896 (set (attr "length")
2897 (if_then_else (match_test "!TARGET_DEBUG && TARGET_DENSITY")
2901 ;; Setting up a frame pointer is tricky for Xtensa because GCC doesn't
2902 ;; know if a frame pointer is required until the reload pass, and
2903 ;; because there may be an incoming argument value in the hard frame
2904 ;; pointer register (a7). If there is an incoming argument in that
2905 ;; register, the "set_frame_ptr" insn gets inserted immediately after
2906 ;; the insn that copies the incoming argument to a pseudo or to the
2907 ;; stack. This serves several purposes here: (1) it keeps the
2908 ;; optimizer from copy-propagating or scheduling the use of a7 as an
2909 ;; incoming argument away from the beginning of the function; (2) we
2910 ;; can use a post-reload splitter to expand away the insn if a frame
2911 ;; pointer is not required, so that the post-reload scheduler can do
2912 ;; the right thing; and (3) it makes it easy for the prologue expander
2913 ;; to search for this insn to determine whether it should add a new insn
2914 ;; to set up the frame pointer.
2916 (define_insn "set_frame_ptr"
2917 [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
2920 if (frame_pointer_needed)
2921 return (TARGET_DENSITY ? "mov.n\ta7, sp" : "mov\ta7, sp");
2924 [(set_attr "type" "move")
2925 (set_attr "mode" "SI")
2926 (set (attr "length")
2927 (if_then_else (match_test "TARGET_DENSITY")
2931 ;; Post-reload splitter to remove fp assignment when it's not needed.
2933 [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
2934 "reload_completed && !frame_pointer_needed"
2935 [(unspec [(const_int 0)] UNSPEC_NOP)]
2938 ;; The preceding splitter needs something to split the insn into;
2939 ;; things start breaking if the result is just a "use" so instead we
2940 ;; generate the following insn.
2941 (define_insn "*unspec_nop"
2942 [(unspec [(const_int 0)] UNSPEC_NOP)]
2945 [(set_attr "type" "nop")
2946 (set_attr "mode" "none")
2947 (set_attr "length" "0")])
2952 (define_expand "sym_TPOFF"
2953 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_TPOFF))]
2957 (define_expand "sym_DTPOFF"
2958 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_DTPOFF))]
2962 (define_insn "get_thread_pointersi"
2963 [(set (match_operand:SI 0 "register_operand" "=a")
2964 (unspec:SI [(const_int 0)] UNSPEC_TP))]
2966 "rur\t%0, THREADPTR"
2967 [(set_attr "type" "rsr")
2968 (set_attr "mode" "SI")
2969 (set_attr "length" "3")])
2971 (define_insn "set_thread_pointersi"
2972 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
2975 "wur\t%0, THREADPTR"
2976 [(set_attr "type" "wsr")
2977 (set_attr "mode" "SI")
2978 (set_attr "length" "3")])
2980 (define_insn "tls_func"
2981 [(set (match_operand:SI 0 "register_operand" "=a")
2982 (unspec:SI [(match_operand:SI 1 "tls_symbol_operand" "")]
2984 "TARGET_THREADPTR && HAVE_AS_TLS"
2985 "movi\t%0, %1@TLSFUNC"
2986 [(set_attr "type" "load")
2987 (set_attr "mode" "SI")
2988 (set_attr "length" "3")])
2990 (define_insn "tls_arg"
2991 [(set (match_operand:SI 0 "register_operand" "=a")
2992 (unspec:SI [(match_operand:SI 1 "tls_symbol_operand" "")]
2994 "TARGET_THREADPTR && HAVE_AS_TLS"
2995 "movi\t%0, %1@TLSARG"
2996 [(set_attr "type" "load")
2997 (set_attr "mode" "SI")
2998 (set_attr "length" "3")])
3000 (define_insn "tls_call"
3001 [(set (match_operand:SI 0 "register_operand" "=a")
3002 (call (mem:SI (unspec:SI [(match_operand:SI 1 "register_operand" "r")
3003 (match_operand:SI 2 "tls_symbol_operand" "")]
3005 (match_operand 3 "" "i")))]
3006 "TARGET_THREADPTR && HAVE_AS_TLS"
3008 if (TARGET_WINDOWED_ABI)
3009 return "callx8.tls %1, %2@TLSCALL";
3011 return "callx0.tls %1, %2@TLSCALL";
3013 [(set_attr "type" "call")
3014 (set_attr "mode" "none")
3015 (set_attr "length" "3")])
3018 ;; Instructions for the Xtensa "boolean" option.
3020 (define_insn "*booltrue"
3022 (if_then_else (match_operator 2 "boolean_operator"
3023 [(match_operand:CC 0 "register_operand" "b")
3025 (label_ref (match_operand 1 "" ""))
3029 if (GET_CODE (operands[2]) == EQ)
3030 return "bf\t%0, %1";
3032 return "bt\t%0, %1";
3034 [(set_attr "type" "jump")
3035 (set_attr "mode" "none")
3036 (set_attr "length" "3")])
3038 (define_insn "*boolfalse"
3040 (if_then_else (match_operator 2 "boolean_operator"
3041 [(match_operand:CC 0 "register_operand" "b")
3044 (label_ref (match_operand 1 "" ""))))]
3047 if (GET_CODE (operands[2]) == EQ)
3048 return "bt\t%0, %1";
3050 return "bf\t%0, %1";
3052 [(set_attr "type" "jump")
3053 (set_attr "mode" "none")
3054 (set_attr "length" "3")])
3057 ;; Atomic operations
3059 (define_expand "memory_barrier"
3061 (unspec:BLK [(match_dup 0)] UNSPEC_MEMW))]
3064 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
3065 MEM_VOLATILE_P (operands[0]) = 1;
3068 (define_insn "*memory_barrier"
3069 [(set (match_operand:BLK 0 "" "")
3070 (unspec:BLK [(match_dup 0)] UNSPEC_MEMW))]
3073 [(set_attr "type" "unknown")
3074 (set_attr "mode" "none")
3075 (set_attr "length" "3")])
3077 ;; sync_lock_release is only implemented for SImode.
3078 ;; For other modes, just use the default of a store with a memory_barrier.
3079 (define_insn "sync_lock_releasesi"
3080 [(set (match_operand:SI 0 "mem_operand" "=U")
3082 [(match_operand:SI 1 "register_operand" "r")]
3084 "TARGET_RELEASE_SYNC"
3086 [(set_attr "type" "store")
3087 (set_attr "mode" "SI")
3088 (set_attr "length" "3")])
3090 (define_insn "sync_compare_and_swapsi"
3092 [(set (match_operand:SI 0 "register_operand" "=a")
3093 (match_operand:SI 1 "mem_operand" "+U"))
3097 (match_operand:SI 2 "register_operand" "r")
3098 (match_operand:SI 3 "register_operand" "0")]
3101 "wsr\t%2, SCOMPARE1\;s32c1i\t%3, %1"
3102 [(set_attr "type" "multi")
3103 (set_attr "mode" "SI")
3104 (set_attr "length" "6")])
3106 (define_expand "sync_compare_and_swap<mode>"
3108 [(set (match_operand:HQI 0 "register_operand" "")
3109 (match_operand:HQI 1 "mem_operand" ""))
3111 (unspec_volatile:HQI
3113 (match_operand:HQI 2 "register_operand" "")
3114 (match_operand:HQI 3 "register_operand" "")]
3118 xtensa_expand_compare_and_swap (operands[0], operands[1],
3119 operands[2], operands[3]);
3123 (define_expand "sync_lock_test_and_set<mode>"
3124 [(match_operand:HQI 0 "register_operand")
3125 (match_operand:HQI 1 "memory_operand")
3126 (match_operand:HQI 2 "register_operand")]
3129 xtensa_expand_atomic (SET, operands[0], operands[1], operands[2], false);
3133 (define_expand "sync_<atomic><mode>"
3134 [(set (match_operand:HQI 0 "memory_operand")
3135 (ATOMIC:HQI (match_dup 0)
3136 (match_operand:HQI 1 "register_operand")))]
3139 xtensa_expand_atomic (<CODE>, NULL_RTX, operands[0], operands[1], false);
3143 (define_expand "sync_old_<atomic><mode>"
3144 [(set (match_operand:HQI 0 "register_operand")
3145 (match_operand:HQI 1 "memory_operand"))
3147 (ATOMIC:HQI (match_dup 1)
3148 (match_operand:HQI 2 "register_operand")))]
3151 xtensa_expand_atomic (<CODE>, operands[0], operands[1], operands[2], false);
3155 (define_expand "sync_new_<atomic><mode>"
3156 [(set (match_operand:HQI 0 "register_operand")
3157 (ATOMIC:HQI (match_operand:HQI 1 "memory_operand")
3158 (match_operand:HQI 2 "register_operand")))
3159 (set (match_dup 1) (ATOMIC:HQI (match_dup 1) (match_dup 2)))]
3162 xtensa_expand_atomic (<CODE>, operands[0], operands[1], operands[2], true);
3166 (define_insn_and_split "*round_up_to_even"
3167 [(set (match_operand:SI 0 "register_operand" "=a")
3168 (and:SI (plus:SI (match_operand:SI 1 "register_operand" "r")
3173 "can_create_pseudo_p ()"
3175 (and:SI (match_dup 1)
3178 (plus:SI (match_dup 2)
3181 operands[2] = gen_reg_rtx (SImode);
3183 [(set_attr "type" "arith")
3184 (set_attr "mode" "SI")
3185 (set (attr "length")
3186 (if_then_else (match_test "TARGET_DENSITY")
3190 (define_insn_and_split "*signed_ge_zero"
3191 [(set (match_operand:SI 0 "register_operand" "=a")
3192 (ge:SI (match_operand:SI 1 "register_operand" "r")
3198 (ashiftrt:SI (match_dup 1)
3201 (plus:SI (match_dup 0)
3204 [(set_attr "type" "arith")
3205 (set_attr "mode" "SI")
3206 (set (attr "length")
3207 (if_then_else (match_test "TARGET_DENSITY")
3211 (define_insn_and_split "eq_zero_NSA"
3212 [(set (match_operand:SI 0 "register_operand" "=a")
3213 (eq:SI (match_operand:SI 1 "register_operand" "r")
3219 (clz:SI (match_dup 1)))
3221 (lshiftrt:SI (match_dup 0)
3224 [(set_attr "type" "move")
3225 (set_attr "mode" "SI")
3226 (set_attr "length" "6")])
3228 (define_insn_and_split "eqne_zero"
3229 [(set (match_operand:SI 0 "register_operand" "=a,&a")
3230 (match_operator:SI 2 "boolean_operator"
3231 [(match_operand:SI 1 "register_operand" "0,r")
3233 (clobber (match_scratch:SI 3 "=&a,X"))]
3236 "&& reload_completed"
3239 enum rtx_code code = GET_CODE (operands[2]);
3240 int same_p = REGNO (operands[0]) == REGNO (operands[1]);
3241 emit_move_insn (same_p ? operands[3] : operands[0],
3242 code == EQ ? constm1_rtx : const1_rtx);
3243 emit_insn (gen_movsicc_internal0 (operands[0], operands[1],
3244 same_p ? operands[3] : operands[1],
3246 gen_rtx_fmt_ee (same_p ? NE : EQ,
3251 emit_insn (gen_addsi3 (operands[0], operands[0], const1_rtx));
3254 [(set_attr "type" "move")
3255 (set_attr "mode" "SI")
3256 (set (attr "length")
3257 (if_then_else (match_test "GET_CODE (operands[2]) == EQ")
3258 (if_then_else (match_test "TARGET_DENSITY")
3261 (if_then_else (match_test "TARGET_DENSITY")
3265 (define_insn_and_split "*eqne_zero_masked_bits"
3266 [(set (match_operand:SI 0 "register_operand" "=a")
3267 (match_operator 3 "boolean_operator"
3268 [(and:SI (match_operand:SI 1 "register_operand" "r")
3269 (match_operand:SI 2 "const_int_operand" "i"))
3271 "IN_RANGE (exact_log2 (INTVAL (operands[2]) + 1), 17, 31)
3272 || IN_RANGE (exact_log2 (-INTVAL (operands[2])), 1, 30)"
3277 HOST_WIDE_INT mask = INTVAL (operands[2]);
3279 enum rtx_code code = GET_CODE (operands[3]);
3280 if (IN_RANGE (n = exact_log2 (mask + 1), 17, 31))
3281 emit_insn (gen_ashlsi3 (operands[0], operands[1], GEN_INT (32 - n)));
3283 emit_insn (gen_lshrsi3 (operands[0], operands[1],
3284 GEN_INT (floor_log2 (-mask))));
3285 if (TARGET_NSA && code == EQ)
3286 emit_insn (gen_eq_zero_NSA (operands[0], operands[0]));
3288 emit_insn (gen_eqne_zero (operands[0], operands[0],
3289 gen_rtx_fmt_ee (code, VOIDmode,
3290 operands[0], const0_rtx)));
3294 (define_insn_and_split "*eqne_INT_MIN"
3295 [(set (match_operand:SI 0 "register_operand" "=a")
3296 (match_operator:SI 2 "boolean_operator"
3297 [(match_operand:SI 1 "register_operand" "r")
3298 (const_int -2147483648)]))]
3304 emit_insn (gen_abssi2 (operands[0], operands[1]));
3305 if (GET_CODE (operands[2]) == EQ)
3306 emit_insn (gen_lshrsi3 (operands[0], operands[0], GEN_INT (31)));
3309 emit_insn (gen_ashrsi3 (operands[0], operands[0], GEN_INT (31)));
3310 emit_insn (gen_addsi3 (operands[0], operands[0], const1_rtx));
3314 [(set_attr "type" "move")
3315 (set_attr "mode" "SI")
3316 (set (attr "length")
3317 (if_then_else (match_test "GET_CODE (operands[2]) == EQ")
3319 (if_then_else (match_test "TARGET_DENSITY")
3324 [(set (match_operand:SI 0 "register_operand")
3325 (match_operand:SI 6 "reload_operand"))
3326 (set (match_operand:SI 1 "register_operand")
3327 (match_operand:SI 7 "reload_operand"))
3328 (set (match_operand:SF 2 "register_operand")
3329 (match_operand:SF 4 "register_operand"))
3330 (set (match_operand:SF 3 "register_operand")
3331 (match_operand:SF 5 "register_operand"))]
3332 "REGNO (operands[0]) == REGNO (operands[4])
3333 && REGNO (operands[1]) == REGNO (operands[5])
3334 && peep2_reg_dead_p (4, operands[0])
3335 && peep2_reg_dead_p (4, operands[1])"
3343 CLEAR_HARD_REG_SET (regs);
3344 for (i = 0; i <= 3; ++i)
3345 if (TEST_HARD_REG_BIT (regs, REGNO (operands[i])))
3348 SET_HARD_REG_BIT (regs, REGNO (operands[i]));
3349 operands[6] = gen_rtx_MEM (SFmode, XEXP (operands[6], 0));
3350 operands[7] = gen_rtx_MEM (SFmode, XEXP (operands[7], 0));
3354 [(clobber (match_operand 0 "register_operand"))]
3355 "HARD_REGISTER_P (operands[0])
3356 && COMPLEX_MODE_P (GET_MODE (operands[0]))"
3359 auto_sbitmap bmp (FIRST_PSEUDO_REGISTER);
3361 rtx reg = gen_rtx_REG (SImode, 0), dest;
3363 sbitmap_iterator iter;
3364 bitmap_set_range (bmp, REGNO (operands[0]), REG_NREGS (operands[0]));
3365 for (insn = next_nonnote_nondebug_insn_bb (curr_insn);
3366 insn; insn = next_nonnote_nondebug_insn_bb (insn))
3367 if (NONJUMP_INSN_P (insn))
3369 EXECUTE_IF_SET_IN_BITMAP (bmp, 2, regno, iter)
3371 set_regno_raw (reg, regno, REG_NREGS (reg));
3372 if (reg_referenced_p (reg, PATTERN (insn)))
3375 if (GET_CODE (PATTERN (insn)) == SET
3376 || GET_CODE (PATTERN (insn)) == CLOBBER)
3378 dest = SET_DEST (PATTERN (insn));
3379 if (REG_P (dest) && HARD_REGISTER_P (dest))
3380 bitmap_clear_range (bmp, REGNO (dest), REG_NREGS (dest));
3381 else if (SUBREG_P (dest)
3382 && HARD_REGISTER_P (SUBREG_REG (dest)))
3384 struct subreg_info info;
3385 subreg_get_info (regno = REGNO (SUBREG_REG (dest)),
3386 GET_MODE (SUBREG_REG (dest)),
3387 SUBREG_BYTE (dest), GET_MODE (dest),
3389 if (!info.representable_p)
3391 bitmap_clear_range (bmp, regno + info.offset, info.nregs);
3394 if (bitmap_empty_p (bmp))
3397 else if (CALL_P (insn))
3398 EXECUTE_IF_SET_IN_BITMAP (bmp, 2, regno, iter)
3399 if (call_used_or_fixed_reg_p (regno))
3407 [(set (match_operand:SI 0 "register_operand")
3408 (match_operand:SI 1 "const_int_operand"))
3410 (plus:SI (match_dup 0)
3411 (match_operand:SI 2 "const_int_operand")))
3412 (set (match_operand:SI 3 "register_operand")
3413 (plus:SI (match_operand:SI 4 "register_operand")
3415 "IN_RANGE (INTVAL (operands[1]) + INTVAL (operands[2]),
3416 (-128 - 32768), (127 + 32512))
3417 && REGNO (operands[0]) != REGNO (operands[3])
3418 && REGNO (operands[0]) != REGNO (operands[4])
3419 && peep2_reg_dead_p (3, operands[0])"
3421 (plus:SI (match_dup 4)
3424 (plus:SI (match_dup 3)
3427 HOST_WIDE_INT value = INTVAL (operands[1]) + INTVAL (operands[2]);
3433 imm1 = value & ~255;
3434 imm0 = value - imm1 - 128;
3435 operands[1] = GEN_INT (imm0);
3436 operands[2] = GEN_INT (imm1);
3440 [(set (match_operand 0 "register_operand")
3441 (match_operand 1 "register_operand"))]
3442 "REG_NREGS (operands[0]) == 1 && GP_REG_P (REGNO (operands[0]))
3443 && REG_NREGS (operands[1]) == 1 && GP_REG_P (REGNO (operands[1]))
3444 && peep2_reg_dead_p (1, operands[1])"
3447 basic_block bb = BLOCK_FOR_INSN (curr_insn);
3448 rtx_insn *head = BB_HEAD (bb), *insn;
3449 rtx dest = operands[0], src = operands[1], pattern, t_dest, dest_orig;
3450 for (insn = PREV_INSN (curr_insn);
3451 insn && insn != head;
3452 insn = PREV_INSN (insn))
3455 else if (INSN_P (insn))
3457 if (GET_CODE (pattern = PATTERN (insn)) == SET
3458 && REG_P (t_dest = SET_DEST (pattern))
3459 && REG_NREGS (t_dest) == 1
3460 && REGNO (t_dest) == REGNO (src))
3462 dest_orig = SET_DEST (pattern);
3463 SET_DEST (pattern) = gen_rtx_REG (GET_MODE (t_dest),
3465 extract_insn (insn);
3466 if (!constrain_operands (true, get_enabled_alternatives (insn)))
3468 SET_DEST (pattern) = dest_orig;
3471 df_insn_rescan (insn);
3474 if (reg_overlap_mentioned_p (dest, pattern)
3475 || reg_overlap_mentioned_p (src, pattern)
3476 || set_of (dest, insn)
3477 || set_of (src, insn))