1 ;; GCC machine description for Tensilica's Xtensa architecture.
2 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Bob Wilson (bwilson@tensilica.com) at Tensilica.
6 ;; This file is part of GCC.
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 ;; License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING. If not, write to the Free
20 ;; Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
37 ;; This code macro allows signed and unsigned widening multiplications
38 ;; to use the same template.
39 (define_code_macro any_extend [sign_extend zero_extend])
41 ;; <u> expands to an empty string when doing a signed operation and
42 ;; "u" when doing an unsigned operation.
43 (define_code_attr u [(sign_extend "") (zero_extend "u")])
45 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
46 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
52 "unknown,jump,call,load,store,move,arith,multi,nop,farith,fmadd,fdiv,fsqrt,fconv,fload,fstore,mul16,mul32,div32,mac16,rsr,wsr"
53 (const_string "unknown"))
56 "unknown,none,QI,HI,SI,DI,SF,DF,BL"
57 (const_string "unknown"))
59 (define_attr "length" "" (const_int 1))
61 ;; Describe a user's asm statement.
62 (define_asm_attributes
63 [(set_attr "type" "multi")])
68 ;; The Xtensa basically has simple 5-stage RISC pipeline.
69 ;; Most instructions complete in 1 cycle, and it is OK to assume that
70 ;; everything is fully pipelined. The exceptions have special insn
71 ;; reservations in the pipeline description below. The Xtensa can
72 ;; issue one instruction per cycle, so defining CPU units is unnecessary.
74 (define_insn_reservation "xtensa_any_insn" 1
75 (eq_attr "type" "!load,fload,rsr,mul16,mul32,fmadd,fconv")
78 (define_insn_reservation "xtensa_memory" 2
79 (eq_attr "type" "load,fload")
82 (define_insn_reservation "xtensa_sreg" 2
83 (eq_attr "type" "rsr")
86 (define_insn_reservation "xtensa_mul16" 2
87 (eq_attr "type" "mul16")
90 (define_insn_reservation "xtensa_mul32" 2
91 (eq_attr "type" "mul32")
94 (define_insn_reservation "xtensa_fmadd" 4
95 (eq_attr "type" "fmadd")
98 (define_insn_reservation "xtensa_fconv" 2
99 (eq_attr "type" "fconv")
102 ;; Include predicate definitions
104 (include "predicates.md")
109 (define_expand "adddi3"
110 [(set (match_operand:DI 0 "register_operand" "")
111 (plus:DI (match_operand:DI 1 "register_operand" "")
112 (match_operand:DI 2 "register_operand" "")))]
116 rtx dstlo = gen_lowpart (SImode, operands[0]);
117 rtx src1lo = gen_lowpart (SImode, operands[1]);
118 rtx src2lo = gen_lowpart (SImode, operands[2]);
120 rtx dsthi = gen_highpart (SImode, operands[0]);
121 rtx src1hi = gen_highpart (SImode, operands[1]);
122 rtx src2hi = gen_highpart (SImode, operands[2]);
124 /* Either source can be used for overflow checking, as long as it's
125 not clobbered by the first addition. */
126 if (!rtx_equal_p (dstlo, src1lo))
128 else if (!rtx_equal_p (dstlo, src2lo))
132 srclo = gen_reg_rtx (SImode);
133 emit_move_insn (srclo, src1lo);
136 emit_insn (gen_addsi3 (dstlo, src1lo, src2lo));
137 emit_insn (gen_addsi3 (dsthi, src1hi, src2hi));
138 emit_insn (gen_adddi_carry (dsthi, dstlo, srclo));
142 ;; Represent the add-carry operation as an atomic operation instead of
143 ;; expanding it to a conditional branch. Otherwise, the edge
144 ;; profiling code breaks because inserting the count increment code
145 ;; causes a new jump insn to be added.
147 (define_insn "adddi_carry"
148 [(set (match_operand:SI 0 "register_operand" "+a")
149 (plus:SI (ltu:SI (match_operand:SI 1 "register_operand" "r")
150 (match_operand:SI 2 "register_operand" "r"))
153 "bgeu\t%1, %2, 0f\;addi\t%0, %0, 1\;0:"
154 [(set_attr "type" "multi")
155 (set_attr "mode" "SI")
156 (set_attr "length" "6")])
158 (define_insn "addsi3"
159 [(set (match_operand:SI 0 "register_operand" "=D,D,a,a,a")
160 (plus:SI (match_operand:SI 1 "register_operand" "%d,d,r,r,r")
161 (match_operand:SI 2 "add_operand" "d,O,r,J,N")))]
169 [(set_attr "type" "arith,arith,arith,arith,arith")
170 (set_attr "mode" "SI")
171 (set_attr "length" "2,2,3,3,3")])
173 (define_insn "*addx2"
174 [(set (match_operand:SI 0 "register_operand" "=a")
175 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
177 (match_operand:SI 2 "register_operand" "r")))]
180 [(set_attr "type" "arith")
181 (set_attr "mode" "SI")
182 (set_attr "length" "3")])
184 (define_insn "*addx4"
185 [(set (match_operand:SI 0 "register_operand" "=a")
186 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
188 (match_operand:SI 2 "register_operand" "r")))]
191 [(set_attr "type" "arith")
192 (set_attr "mode" "SI")
193 (set_attr "length" "3")])
195 (define_insn "*addx8"
196 [(set (match_operand:SI 0 "register_operand" "=a")
197 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
199 (match_operand:SI 2 "register_operand" "r")))]
202 [(set_attr "type" "arith")
203 (set_attr "mode" "SI")
204 (set_attr "length" "3")])
206 (define_insn "addsf3"
207 [(set (match_operand:SF 0 "register_operand" "=f")
208 (plus:SF (match_operand:SF 1 "register_operand" "%f")
209 (match_operand:SF 2 "register_operand" "f")))]
212 [(set_attr "type" "fmadd")
213 (set_attr "mode" "SF")
214 (set_attr "length" "3")])
219 (define_expand "subdi3"
220 [(set (match_operand:DI 0 "register_operand" "")
221 (minus:DI (match_operand:DI 1 "register_operand" "")
222 (match_operand:DI 2 "register_operand" "")))]
225 rtx dstlo = gen_lowpart (SImode, operands[0]);
226 rtx src1lo = gen_lowpart (SImode, operands[1]);
227 rtx src2lo = gen_lowpart (SImode, operands[2]);
229 rtx dsthi = gen_highpart (SImode, operands[0]);
230 rtx src1hi = gen_highpart (SImode, operands[1]);
231 rtx src2hi = gen_highpart (SImode, operands[2]);
233 emit_insn (gen_subsi3 (dsthi, src1hi, src2hi));
234 emit_insn (gen_subdi_carry (dsthi, src1lo, src2lo));
235 emit_insn (gen_subsi3 (dstlo, src1lo, src2lo));
239 (define_insn "subdi_carry"
240 [(set (match_operand:SI 0 "register_operand" "+a")
241 (minus:SI (match_dup 0)
242 (ltu:SI (match_operand:SI 1 "register_operand" "r")
243 (match_operand:SI 2 "register_operand" "r"))))]
245 "bgeu\t%1, %2, 0f\;addi\t%0, %0, -1\;0:"
246 [(set_attr "type" "multi")
247 (set_attr "mode" "SI")
248 (set_attr "length" "6")])
250 (define_insn "subsi3"
251 [(set (match_operand:SI 0 "register_operand" "=a")
252 (minus:SI (match_operand:SI 1 "register_operand" "r")
253 (match_operand:SI 2 "register_operand" "r")))]
256 [(set_attr "type" "arith")
257 (set_attr "mode" "SI")
258 (set_attr "length" "3")])
260 (define_insn "*subx2"
261 [(set (match_operand:SI 0 "register_operand" "=a")
262 (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
264 (match_operand:SI 2 "register_operand" "r")))]
267 [(set_attr "type" "arith")
268 (set_attr "mode" "SI")
269 (set_attr "length" "3")])
271 (define_insn "*subx4"
272 [(set (match_operand:SI 0 "register_operand" "=a")
273 (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
275 (match_operand:SI 2 "register_operand" "r")))]
278 [(set_attr "type" "arith")
279 (set_attr "mode" "SI")
280 (set_attr "length" "3")])
282 (define_insn "*subx8"
283 [(set (match_operand:SI 0 "register_operand" "=a")
284 (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
286 (match_operand:SI 2 "register_operand" "r")))]
289 [(set_attr "type" "arith")
290 (set_attr "mode" "SI")
291 (set_attr "length" "3")])
293 (define_insn "subsf3"
294 [(set (match_operand:SF 0 "register_operand" "=f")
295 (minus:SF (match_operand:SF 1 "register_operand" "f")
296 (match_operand:SF 2 "register_operand" "f")))]
299 [(set_attr "type" "fmadd")
300 (set_attr "mode" "SF")
301 (set_attr "length" "3")])
306 (define_expand "<u>mulsidi3"
307 [(set (match_operand:DI 0 "register_operand")
308 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
309 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
312 emit_insn (gen_mulsi3 (gen_lowpart (SImode, operands[0]),
313 operands[1], operands[2]));
314 emit_insn (gen_<u>mulsi3_highpart (gen_highpart (SImode, operands[0]),
315 operands[1], operands[2]));
319 (define_insn "<u>mulsi3_highpart"
320 [(set (match_operand:SI 0 "register_operand" "=a")
323 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "%r"))
324 (any_extend:DI (match_operand:SI 2 "register_operand" "r")))
327 "mul<su>h\t%0, %1, %2"
328 [(set_attr "type" "mul32")
329 (set_attr "mode" "SI")
330 (set_attr "length" "3")])
332 (define_insn "mulsi3"
333 [(set (match_operand:SI 0 "register_operand" "=a")
334 (mult:SI (match_operand:SI 1 "register_operand" "%r")
335 (match_operand:SI 2 "register_operand" "r")))]
338 [(set_attr "type" "mul32")
339 (set_attr "mode" "SI")
340 (set_attr "length" "3")])
342 (define_insn "mulhisi3"
343 [(set (match_operand:SI 0 "register_operand" "=C,A")
344 (mult:SI (sign_extend:SI
345 (match_operand:HI 1 "register_operand" "%r,r"))
347 (match_operand:HI 2 "register_operand" "r,r"))))]
348 "TARGET_MUL16 || TARGET_MAC16"
352 [(set_attr "type" "mul16,mac16")
353 (set_attr "mode" "SI")
354 (set_attr "length" "3,3")])
356 (define_insn "umulhisi3"
357 [(set (match_operand:SI 0 "register_operand" "=C,A")
358 (mult:SI (zero_extend:SI
359 (match_operand:HI 1 "register_operand" "%r,r"))
361 (match_operand:HI 2 "register_operand" "r,r"))))]
362 "TARGET_MUL16 || TARGET_MAC16"
366 [(set_attr "type" "mul16,mac16")
367 (set_attr "mode" "SI")
368 (set_attr "length" "3,3")])
370 (define_insn "muladdhisi"
371 [(set (match_operand:SI 0 "register_operand" "=A")
372 (plus:SI (mult:SI (sign_extend:SI
373 (match_operand:HI 1 "register_operand" "%r"))
375 (match_operand:HI 2 "register_operand" "r")))
376 (match_operand:SI 3 "register_operand" "0")))]
379 [(set_attr "type" "mac16")
380 (set_attr "mode" "SI")
381 (set_attr "length" "3")])
383 (define_insn "mulsubhisi"
384 [(set (match_operand:SI 0 "register_operand" "=A")
385 (minus:SI (match_operand:SI 1 "register_operand" "0")
386 (mult:SI (sign_extend:SI
387 (match_operand:HI 2 "register_operand" "%r"))
389 (match_operand:HI 3 "register_operand" "r")))))]
392 [(set_attr "type" "mac16")
393 (set_attr "mode" "SI")
394 (set_attr "length" "3")])
396 (define_insn "mulsf3"
397 [(set (match_operand:SF 0 "register_operand" "=f")
398 (mult:SF (match_operand:SF 1 "register_operand" "%f")
399 (match_operand:SF 2 "register_operand" "f")))]
402 [(set_attr "type" "fmadd")
403 (set_attr "mode" "SF")
404 (set_attr "length" "3")])
406 (define_insn "muladdsf3"
407 [(set (match_operand:SF 0 "register_operand" "=f")
408 (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "%f")
409 (match_operand:SF 2 "register_operand" "f"))
410 (match_operand:SF 3 "register_operand" "0")))]
411 "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
413 [(set_attr "type" "fmadd")
414 (set_attr "mode" "SF")
415 (set_attr "length" "3")])
417 (define_insn "mulsubsf3"
418 [(set (match_operand:SF 0 "register_operand" "=f")
419 (minus:SF (match_operand:SF 1 "register_operand" "0")
420 (mult:SF (match_operand:SF 2 "register_operand" "%f")
421 (match_operand:SF 3 "register_operand" "f"))))]
422 "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
424 [(set_attr "type" "fmadd")
425 (set_attr "mode" "SF")
426 (set_attr "length" "3")])
431 (define_insn "divsi3"
432 [(set (match_operand:SI 0 "register_operand" "=a")
433 (div:SI (match_operand:SI 1 "register_operand" "r")
434 (match_operand:SI 2 "register_operand" "r")))]
437 [(set_attr "type" "div32")
438 (set_attr "mode" "SI")
439 (set_attr "length" "3")])
441 (define_insn "udivsi3"
442 [(set (match_operand:SI 0 "register_operand" "=a")
443 (udiv:SI (match_operand:SI 1 "register_operand" "r")
444 (match_operand:SI 2 "register_operand" "r")))]
447 [(set_attr "type" "div32")
448 (set_attr "mode" "SI")
449 (set_attr "length" "3")])
451 (define_insn "divsf3"
452 [(set (match_operand:SF 0 "register_operand" "=f")
453 (div:SF (match_operand:SF 1 "register_operand" "f")
454 (match_operand:SF 2 "register_operand" "f")))]
455 "TARGET_HARD_FLOAT_DIV"
457 [(set_attr "type" "fdiv")
458 (set_attr "mode" "SF")
459 (set_attr "length" "3")])
461 (define_insn "*recipsf2"
462 [(set (match_operand:SF 0 "register_operand" "=f")
463 (div:SF (match_operand:SF 1 "const_float_1_operand" "")
464 (match_operand:SF 2 "register_operand" "f")))]
465 "TARGET_HARD_FLOAT_RECIP && flag_unsafe_math_optimizations"
467 [(set_attr "type" "fdiv")
468 (set_attr "mode" "SF")
469 (set_attr "length" "3")])
474 (define_insn "modsi3"
475 [(set (match_operand:SI 0 "register_operand" "=a")
476 (mod:SI (match_operand:SI 1 "register_operand" "r")
477 (match_operand:SI 2 "register_operand" "r")))]
480 [(set_attr "type" "div32")
481 (set_attr "mode" "SI")
482 (set_attr "length" "3")])
484 (define_insn "umodsi3"
485 [(set (match_operand:SI 0 "register_operand" "=a")
486 (umod:SI (match_operand:SI 1 "register_operand" "r")
487 (match_operand:SI 2 "register_operand" "r")))]
490 [(set_attr "type" "div32")
491 (set_attr "mode" "SI")
492 (set_attr "length" "3")])
497 (define_insn "sqrtsf2"
498 [(set (match_operand:SF 0 "register_operand" "=f")
499 (sqrt:SF (match_operand:SF 1 "register_operand" "f")))]
500 "TARGET_HARD_FLOAT_SQRT"
502 [(set_attr "type" "fsqrt")
503 (set_attr "mode" "SF")
504 (set_attr "length" "3")])
506 (define_insn "*rsqrtsf2"
507 [(set (match_operand:SF 0 "register_operand" "=f")
508 (div:SF (match_operand:SF 1 "const_float_1_operand" "")
509 (sqrt:SF (match_operand:SF 2 "register_operand" "f"))))]
510 "TARGET_HARD_FLOAT_RSQRT && flag_unsafe_math_optimizations"
512 [(set_attr "type" "fsqrt")
513 (set_attr "mode" "SF")
514 (set_attr "length" "3")])
519 (define_insn "abssi2"
520 [(set (match_operand:SI 0 "register_operand" "=a")
521 (abs:SI (match_operand:SI 1 "register_operand" "r")))]
524 [(set_attr "type" "arith")
525 (set_attr "mode" "SI")
526 (set_attr "length" "3")])
528 (define_insn "abssf2"
529 [(set (match_operand:SF 0 "register_operand" "=f")
530 (abs:SF (match_operand:SF 1 "register_operand" "f")))]
533 [(set_attr "type" "farith")
534 (set_attr "mode" "SF")
535 (set_attr "length" "3")])
540 (define_insn "sminsi3"
541 [(set (match_operand:SI 0 "register_operand" "=a")
542 (smin:SI (match_operand:SI 1 "register_operand" "%r")
543 (match_operand:SI 2 "register_operand" "r")))]
546 [(set_attr "type" "arith")
547 (set_attr "mode" "SI")
548 (set_attr "length" "3")])
550 (define_insn "uminsi3"
551 [(set (match_operand:SI 0 "register_operand" "=a")
552 (umin:SI (match_operand:SI 1 "register_operand" "%r")
553 (match_operand:SI 2 "register_operand" "r")))]
556 [(set_attr "type" "arith")
557 (set_attr "mode" "SI")
558 (set_attr "length" "3")])
560 (define_insn "smaxsi3"
561 [(set (match_operand:SI 0 "register_operand" "=a")
562 (smax:SI (match_operand:SI 1 "register_operand" "%r")
563 (match_operand:SI 2 "register_operand" "r")))]
566 [(set_attr "type" "arith")
567 (set_attr "mode" "SI")
568 (set_attr "length" "3")])
570 (define_insn "umaxsi3"
571 [(set (match_operand:SI 0 "register_operand" "=a")
572 (umax:SI (match_operand:SI 1 "register_operand" "%r")
573 (match_operand:SI 2 "register_operand" "r")))]
576 [(set_attr "type" "arith")
577 (set_attr "mode" "SI")
578 (set_attr "length" "3")])
581 ;; Count leading/trailing zeros and find first bit.
583 (define_insn "clzsi2"
584 [(set (match_operand:SI 0 "register_operand" "=a")
585 (clz:SI (match_operand:SI 1 "register_operand" "r")))]
588 [(set_attr "type" "arith")
589 (set_attr "mode" "SI")
590 (set_attr "length" "3")])
592 (define_expand "ctzsi2"
593 [(set (match_operand:SI 0 "register_operand" "")
594 (ctz:SI (match_operand:SI 1 "register_operand" "")))]
597 rtx temp = gen_reg_rtx (SImode);
598 emit_insn (gen_negsi2 (temp, operands[1]));
599 emit_insn (gen_andsi3 (temp, temp, operands[1]));
600 emit_insn (gen_clzsi2 (temp, temp));
601 emit_insn (gen_negsi2 (temp, temp));
602 emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (31)));
606 (define_expand "ffssi2"
607 [(set (match_operand:SI 0 "register_operand" "")
608 (ffs:SI (match_operand:SI 1 "register_operand" "")))]
611 rtx temp = gen_reg_rtx (SImode);
612 emit_insn (gen_negsi2 (temp, operands[1]));
613 emit_insn (gen_andsi3 (temp, temp, operands[1]));
614 emit_insn (gen_clzsi2 (temp, temp));
615 emit_insn (gen_negsi2 (temp, temp));
616 emit_insn (gen_addsi3 (operands[0], temp, GEN_INT (32)));
621 ;; Negation and one's complement.
623 (define_insn "negsi2"
624 [(set (match_operand:SI 0 "register_operand" "=a")
625 (neg:SI (match_operand:SI 1 "register_operand" "r")))]
628 [(set_attr "type" "arith")
629 (set_attr "mode" "SI")
630 (set_attr "length" "3")])
632 (define_expand "one_cmplsi2"
633 [(set (match_operand:SI 0 "register_operand" "")
634 (not:SI (match_operand:SI 1 "register_operand" "")))]
637 rtx temp = gen_reg_rtx (SImode);
638 emit_insn (gen_movsi (temp, constm1_rtx));
639 emit_insn (gen_xorsi3 (operands[0], temp, operands[1]));
643 (define_insn "negsf2"
644 [(set (match_operand:SF 0 "register_operand" "=f")
645 (neg:SF (match_operand:SF 1 "register_operand" "f")))]
648 [(set_attr "type" "farith")
649 (set_attr "mode" "SF")
650 (set_attr "length" "3")])
653 ;; Logical instructions.
655 (define_insn "andsi3"
656 [(set (match_operand:SI 0 "register_operand" "=a,a")
657 (and:SI (match_operand:SI 1 "register_operand" "%r,r")
658 (match_operand:SI 2 "mask_operand" "P,r")))]
661 extui\t%0, %1, 0, %K2
663 [(set_attr "type" "arith,arith")
664 (set_attr "mode" "SI")
665 (set_attr "length" "3,3")])
667 (define_insn "iorsi3"
668 [(set (match_operand:SI 0 "register_operand" "=a")
669 (ior:SI (match_operand:SI 1 "register_operand" "%r")
670 (match_operand:SI 2 "register_operand" "r")))]
673 [(set_attr "type" "arith")
674 (set_attr "mode" "SI")
675 (set_attr "length" "3")])
677 (define_insn "xorsi3"
678 [(set (match_operand:SI 0 "register_operand" "=a")
679 (xor:SI (match_operand:SI 1 "register_operand" "%r")
680 (match_operand:SI 2 "register_operand" "r")))]
683 [(set_attr "type" "arith")
684 (set_attr "mode" "SI")
685 (set_attr "length" "3")])
688 ;; Zero-extend instructions.
690 (define_insn "zero_extendhisi2"
691 [(set (match_operand:SI 0 "register_operand" "=a,a")
692 (zero_extend:SI (match_operand:HI 1 "nonimmed_operand" "r,U")))]
697 [(set_attr "type" "arith,load")
698 (set_attr "mode" "SI")
699 (set_attr "length" "3,3")])
701 (define_insn "zero_extendqisi2"
702 [(set (match_operand:SI 0 "register_operand" "=a,a")
703 (zero_extend:SI (match_operand:QI 1 "nonimmed_operand" "r,U")))]
708 [(set_attr "type" "arith,load")
709 (set_attr "mode" "SI")
710 (set_attr "length" "3,3")])
713 ;; Sign-extend instructions.
715 (define_expand "extendhisi2"
716 [(set (match_operand:SI 0 "register_operand" "")
717 (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
720 if (sext_operand (operands[1], HImode))
721 emit_insn (gen_extendhisi2_internal (operands[0], operands[1]));
723 xtensa_extend_reg (operands[0], operands[1]);
727 (define_insn "extendhisi2_internal"
728 [(set (match_operand:SI 0 "register_operand" "=B,a")
729 (sign_extend:SI (match_operand:HI 1 "sext_operand" "r,U")))]
734 [(set_attr "type" "arith,load")
735 (set_attr "mode" "SI")
736 (set_attr "length" "3,3")])
738 (define_expand "extendqisi2"
739 [(set (match_operand:SI 0 "register_operand" "")
740 (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
744 emit_insn (gen_extendqisi2_internal (operands[0], operands[1]));
746 xtensa_extend_reg (operands[0], operands[1]);
750 (define_insn "extendqisi2_internal"
751 [(set (match_operand:SI 0 "register_operand" "=B")
752 (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
755 [(set_attr "type" "arith")
756 (set_attr "mode" "SI")
757 (set_attr "length" "3")])
760 ;; Field extract instructions.
762 (define_expand "extv"
763 [(set (match_operand:SI 0 "register_operand" "")
764 (sign_extract:SI (match_operand:SI 1 "register_operand" "")
765 (match_operand:SI 2 "const_int_operand" "")
766 (match_operand:SI 3 "const_int_operand" "")))]
769 if (!sext_fldsz_operand (operands[2], SImode))
772 /* We could expand to a right shift followed by SEXT but that's
773 no better than the standard left and right shift sequence. */
774 if (!lsbitnum_operand (operands[3], SImode))
777 emit_insn (gen_extv_internal (operands[0], operands[1],
778 operands[2], operands[3]));
782 (define_insn "extv_internal"
783 [(set (match_operand:SI 0 "register_operand" "=a")
784 (sign_extract:SI (match_operand:SI 1 "register_operand" "r")
785 (match_operand:SI 2 "sext_fldsz_operand" "i")
786 (match_operand:SI 3 "lsbitnum_operand" "i")))]
789 int fldsz = INTVAL (operands[2]);
790 operands[2] = GEN_INT (fldsz - 1);
791 return "sext\t%0, %1, %2";
793 [(set_attr "type" "arith")
794 (set_attr "mode" "SI")
795 (set_attr "length" "3")])
797 (define_expand "extzv"
798 [(set (match_operand:SI 0 "register_operand" "")
799 (zero_extract:SI (match_operand:SI 1 "register_operand" "")
800 (match_operand:SI 2 "const_int_operand" "")
801 (match_operand:SI 3 "const_int_operand" "")))]
804 if (!extui_fldsz_operand (operands[2], SImode))
806 emit_insn (gen_extzv_internal (operands[0], operands[1],
807 operands[2], operands[3]));
811 (define_insn "extzv_internal"
812 [(set (match_operand:SI 0 "register_operand" "=a")
813 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
814 (match_operand:SI 2 "extui_fldsz_operand" "i")
815 (match_operand:SI 3 "const_int_operand" "i")))]
820 shift = (32 - (INTVAL (operands[2]) + INTVAL (operands[3]))) & 0x1f;
822 shift = INTVAL (operands[3]) & 0x1f;
823 operands[3] = GEN_INT (shift);
824 return "extui\t%0, %1, %3, %2";
826 [(set_attr "type" "arith")
827 (set_attr "mode" "SI")
828 (set_attr "length" "3")])
833 (define_insn "fix_truncsfsi2"
834 [(set (match_operand:SI 0 "register_operand" "=a")
835 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
838 [(set_attr "type" "fconv")
839 (set_attr "mode" "SF")
840 (set_attr "length" "3")])
842 (define_insn "fixuns_truncsfsi2"
843 [(set (match_operand:SI 0 "register_operand" "=a")
844 (unsigned_fix:SI (match_operand:SF 1 "register_operand" "f")))]
846 "utrunc.s\t%0, %1, 0"
847 [(set_attr "type" "fconv")
848 (set_attr "mode" "SF")
849 (set_attr "length" "3")])
851 (define_insn "floatsisf2"
852 [(set (match_operand:SF 0 "register_operand" "=f")
853 (float:SF (match_operand:SI 1 "register_operand" "a")))]
856 [(set_attr "type" "fconv")
857 (set_attr "mode" "SF")
858 (set_attr "length" "3")])
860 (define_insn "floatunssisf2"
861 [(set (match_operand:SF 0 "register_operand" "=f")
862 (unsigned_float:SF (match_operand:SI 1 "register_operand" "a")))]
864 "ufloat.s\t%0, %1, 0"
865 [(set_attr "type" "fconv")
866 (set_attr "mode" "SF")
867 (set_attr "length" "3")])
870 ;; Data movement instructions.
872 ;; 64-bit Integer moves
874 (define_expand "movdi"
875 [(set (match_operand:DI 0 "nonimmed_operand" "")
876 (match_operand:DI 1 "general_operand" ""))]
879 if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
880 operands[1] = force_const_mem (DImode, operands[1]);
882 if (!register_operand (operands[0], DImode)
883 && !register_operand (operands[1], DImode))
884 operands[1] = force_reg (DImode, operands[1]);
886 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
889 (define_insn_and_split "movdi_internal"
890 [(set (match_operand:DI 0 "nonimmed_operand" "=a,W,a,a,U")
891 (match_operand:DI 1 "move_operand" "r,i,T,U,r"))]
892 "register_operand (operands[0], DImode)
893 || register_operand (operands[1], DImode)"
896 [(set (match_dup 0) (match_dup 2))
897 (set (match_dup 1) (match_dup 3))]
899 xtensa_split_operand_pair (operands, SImode);
900 if (reg_overlap_mentioned_p (operands[0], operands[3]))
903 tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
904 tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
908 ;; 32-bit Integer moves
910 (define_expand "movsi"
911 [(set (match_operand:SI 0 "nonimmed_operand" "")
912 (match_operand:SI 1 "general_operand" ""))]
915 if (xtensa_emit_move_sequence (operands, SImode))
919 (define_insn "movsi_internal"
920 [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,W,a,a,U,*a,*A")
921 (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,i,T,U,r,*A,*r"))]
922 "xtensa_valid_move (SImode, operands)"
933 const16\t%0, %t1\;const16\t%0, %b1
939 [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,load,load,store,rsr,wsr")
940 (set_attr "mode" "SI")
941 (set_attr "length" "2,2,2,2,2,2,3,3,3,6,3,3,3,3,3")])
943 ;; 16-bit Integer moves
945 (define_expand "movhi"
946 [(set (match_operand:HI 0 "nonimmed_operand" "")
947 (match_operand:HI 1 "general_operand" ""))]
950 if (xtensa_emit_move_sequence (operands, HImode))
954 (define_insn "movhi_internal"
955 [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
956 (match_operand:HI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
957 "xtensa_valid_move (HImode, operands)"
967 [(set_attr "type" "move,move,move,move,load,store,rsr,wsr")
968 (set_attr "mode" "HI")
969 (set_attr "length" "2,2,3,3,3,3,3,3")])
971 ;; 8-bit Integer moves
973 (define_expand "movqi"
974 [(set (match_operand:QI 0 "nonimmed_operand" "")
975 (match_operand:QI 1 "general_operand" ""))]
978 if (xtensa_emit_move_sequence (operands, QImode))
982 (define_insn "movqi_internal"
983 [(set (match_operand:QI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
984 (match_operand:QI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
985 "xtensa_valid_move (QImode, operands)"
995 [(set_attr "type" "move,move,move,move,load,store,rsr,wsr")
996 (set_attr "mode" "QI")
997 (set_attr "length" "2,2,3,3,3,3,3,3")])
999 ;; 32-bit floating point moves
1001 (define_expand "movsf"
1002 [(set (match_operand:SF 0 "nonimmed_operand" "")
1003 (match_operand:SF 1 "general_operand" ""))]
1006 if (!TARGET_CONST16 && CONSTANT_P (operands[1]))
1007 operands[1] = force_const_mem (SFmode, operands[1]);
1009 if ((!register_operand (operands[0], SFmode)
1010 && !register_operand (operands[1], SFmode))
1011 || (FP_REG_P (xt_true_regnum (operands[0]))
1012 && !(reload_in_progress | reload_completed)
1013 && (constantpool_mem_p (operands[1])
1014 || CONSTANT_P (operands[1]))))
1015 operands[1] = force_reg (SFmode, operands[1]);
1017 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1020 (define_insn "movsf_internal"
1021 [(set (match_operand:SF 0 "nonimmed_operand" "=f,f,U,D,D,R,a,f,a,W,a,a,U")
1022 (match_operand:SF 1 "move_operand" "f,U,f,d,R,d,r,r,f,iF,T,U,r"))]
1023 "((register_operand (operands[0], SFmode)
1024 || register_operand (operands[1], SFmode))
1025 && !(FP_REG_P (xt_true_regnum (operands[0]))
1026 && (constantpool_mem_p (operands[1]) || CONSTANT_P (operands[1]))))"
1037 const16\t%0, %t1\;const16\t%0, %b1
1041 [(set_attr "type" "farith,fload,fstore,move,load,store,move,farith,farith,move,load,load,store")
1042 (set_attr "mode" "SF")
1043 (set_attr "length" "3,3,3,2,2,2,3,3,3,6,3,3,3")])
1045 (define_insn "*lsiu"
1046 [(set (match_operand:SF 0 "register_operand" "=f")
1047 (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "+a")
1048 (match_operand:SI 2 "fpmem_offset_operand" "i"))))
1050 (plus:SI (match_dup 1) (match_dup 2)))]
1053 if (volatile_refs_p (PATTERN (insn)))
1054 output_asm_insn ("memw", operands);
1055 return "lsiu\t%0, %1, %2";
1057 [(set_attr "type" "fload")
1058 (set_attr "mode" "SF")
1059 (set_attr "length" "3")])
1061 (define_insn "*ssiu"
1062 [(set (mem:SF (plus:SI (match_operand:SI 0 "register_operand" "+a")
1063 (match_operand:SI 1 "fpmem_offset_operand" "i")))
1064 (match_operand:SF 2 "register_operand" "f"))
1066 (plus:SI (match_dup 0) (match_dup 1)))]
1069 if (volatile_refs_p (PATTERN (insn)))
1070 output_asm_insn ("memw", operands);
1071 return "ssiu\t%2, %0, %1";
1073 [(set_attr "type" "fstore")
1074 (set_attr "mode" "SF")
1075 (set_attr "length" "3")])
1077 ;; 64-bit floating point moves
1079 (define_expand "movdf"
1080 [(set (match_operand:DF 0 "nonimmed_operand" "")
1081 (match_operand:DF 1 "general_operand" ""))]
1084 if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
1085 operands[1] = force_const_mem (DFmode, operands[1]);
1087 if (!register_operand (operands[0], DFmode)
1088 && !register_operand (operands[1], DFmode))
1089 operands[1] = force_reg (DFmode, operands[1]);
1091 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1094 (define_insn_and_split "movdf_internal"
1095 [(set (match_operand:DF 0 "nonimmed_operand" "=a,W,a,a,U")
1096 (match_operand:DF 1 "move_operand" "r,iF,T,U,r"))]
1097 "register_operand (operands[0], DFmode)
1098 || register_operand (operands[1], DFmode)"
1101 [(set (match_dup 0) (match_dup 2))
1102 (set (match_dup 1) (match_dup 3))]
1104 xtensa_split_operand_pair (operands, SFmode);
1105 if (reg_overlap_mentioned_p (operands[0], operands[3]))
1108 tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
1109 tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
1115 (define_expand "movmemsi"
1116 [(parallel [(set (match_operand:BLK 0 "" "")
1117 (match_operand:BLK 1 "" ""))
1118 (use (match_operand:SI 2 "arith_operand" ""))
1119 (use (match_operand:SI 3 "const_int_operand" ""))])]
1122 if (!xtensa_expand_block_move (operands))
1128 ;; Shift instructions.
1130 (define_expand "ashlsi3"
1131 [(set (match_operand:SI 0 "register_operand" "")
1132 (ashift:SI (match_operand:SI 1 "register_operand" "")
1133 (match_operand:SI 2 "arith_operand" "")))]
1136 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1139 (define_insn "ashlsi3_internal"
1140 [(set (match_operand:SI 0 "register_operand" "=a,a")
1141 (ashift:SI (match_operand:SI 1 "register_operand" "r,r")
1142 (match_operand:SI 2 "arith_operand" "J,r")))]
1146 ssl\t%2\;sll\t%0, %1"
1147 [(set_attr "type" "arith,arith")
1148 (set_attr "mode" "SI")
1149 (set_attr "length" "3,6")])
1151 (define_insn "ashrsi3"
1152 [(set (match_operand:SI 0 "register_operand" "=a,a")
1153 (ashiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1154 (match_operand:SI 2 "arith_operand" "J,r")))]
1158 ssr\t%2\;sra\t%0, %1"
1159 [(set_attr "type" "arith,arith")
1160 (set_attr "mode" "SI")
1161 (set_attr "length" "3,6")])
1163 (define_insn "lshrsi3"
1164 [(set (match_operand:SI 0 "register_operand" "=a,a")
1165 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1166 (match_operand:SI 2 "arith_operand" "J,r")))]
1169 if (which_alternative == 0)
1171 if ((INTVAL (operands[2]) & 0x1f) < 16)
1172 return "srli\t%0, %1, %R2";
1174 return "extui\t%0, %1, %R2, %L2";
1176 return "ssr\t%2\;srl\t%0, %1";
1178 [(set_attr "type" "arith,arith")
1179 (set_attr "mode" "SI")
1180 (set_attr "length" "3,6")])
1182 (define_insn "rotlsi3"
1183 [(set (match_operand:SI 0 "register_operand" "=a,a")
1184 (rotate:SI (match_operand:SI 1 "register_operand" "r,r")
1185 (match_operand:SI 2 "arith_operand" "J,r")))]
1188 ssai\t%L2\;src\t%0, %1, %1
1189 ssl\t%2\;src\t%0, %1, %1"
1190 [(set_attr "type" "multi,multi")
1191 (set_attr "mode" "SI")
1192 (set_attr "length" "6,6")])
1194 (define_insn "rotrsi3"
1195 [(set (match_operand:SI 0 "register_operand" "=a,a")
1196 (rotatert:SI (match_operand:SI 1 "register_operand" "r,r")
1197 (match_operand:SI 2 "arith_operand" "J,r")))]
1200 ssai\t%R2\;src\t%0, %1, %1
1201 ssr\t%2\;src\t%0, %1, %1"
1202 [(set_attr "type" "multi,multi")
1203 (set_attr "mode" "SI")
1204 (set_attr "length" "6,6")])
1209 ;; Handle comparisons by stashing away the operands and then using that
1210 ;; information in the subsequent conditional branch.
1212 (define_expand "cmpsi"
1214 (compare:CC (match_operand:SI 0 "register_operand" "")
1215 (match_operand:SI 1 "nonmemory_operand" "")))]
1218 branch_cmp[0] = operands[0];
1219 branch_cmp[1] = operands[1];
1220 branch_type = CMP_SI;
1224 (define_expand "tstsi"
1226 (match_operand:SI 0 "register_operand" ""))]
1229 branch_cmp[0] = operands[0];
1230 branch_cmp[1] = const0_rtx;
1231 branch_type = CMP_SI;
1235 (define_expand "cmpsf"
1237 (compare:CC (match_operand:SF 0 "register_operand" "")
1238 (match_operand:SF 1 "register_operand" "")))]
1241 branch_cmp[0] = operands[0];
1242 branch_cmp[1] = operands[1];
1243 branch_type = CMP_SF;
1248 ;; Conditional branches.
1250 (define_expand "beq"
1252 (if_then_else (eq (cc0) (const_int 0))
1253 (label_ref (match_operand 0 "" ""))
1257 xtensa_expand_conditional_branch (operands, EQ);
1261 (define_expand "bne"
1263 (if_then_else (ne (cc0) (const_int 0))
1264 (label_ref (match_operand 0 "" ""))
1268 xtensa_expand_conditional_branch (operands, NE);
1272 (define_expand "bgt"
1274 (if_then_else (gt (cc0) (const_int 0))
1275 (label_ref (match_operand 0 "" ""))
1279 xtensa_expand_conditional_branch (operands, GT);
1283 (define_expand "bge"
1285 (if_then_else (ge (cc0) (const_int 0))
1286 (label_ref (match_operand 0 "" ""))
1290 xtensa_expand_conditional_branch (operands, GE);
1294 (define_expand "blt"
1296 (if_then_else (lt (cc0) (const_int 0))
1297 (label_ref (match_operand 0 "" ""))
1301 xtensa_expand_conditional_branch (operands, LT);
1305 (define_expand "ble"
1307 (if_then_else (le (cc0) (const_int 0))
1308 (label_ref (match_operand 0 "" ""))
1312 xtensa_expand_conditional_branch (operands, LE);
1316 (define_expand "bgtu"
1318 (if_then_else (gtu (cc0) (const_int 0))
1319 (label_ref (match_operand 0 "" ""))
1323 xtensa_expand_conditional_branch (operands, GTU);
1327 (define_expand "bgeu"
1329 (if_then_else (geu (cc0) (const_int 0))
1330 (label_ref (match_operand 0 "" ""))
1334 xtensa_expand_conditional_branch (operands, GEU);
1338 (define_expand "bltu"
1340 (if_then_else (ltu (cc0) (const_int 0))
1341 (label_ref (match_operand 0 "" ""))
1345 xtensa_expand_conditional_branch (operands, LTU);
1349 (define_expand "bleu"
1351 (if_then_else (leu (cc0) (const_int 0))
1352 (label_ref (match_operand 0 "" ""))
1356 xtensa_expand_conditional_branch (operands, LEU);
1360 ;; Branch patterns for standard integer comparisons
1362 (define_insn "*btrue"
1364 (if_then_else (match_operator 3 "branch_operator"
1365 [(match_operand:SI 0 "register_operand" "r,r")
1366 (match_operand:SI 1 "branch_operand" "K,r")])
1367 (label_ref (match_operand 2 "" ""))
1371 if (which_alternative == 1)
1373 switch (GET_CODE (operands[3]))
1375 case EQ: return "beq\t%0, %1, %2";
1376 case NE: return "bne\t%0, %1, %2";
1377 case LT: return "blt\t%0, %1, %2";
1378 case GE: return "bge\t%0, %1, %2";
1379 default: gcc_unreachable ();
1382 else if (INTVAL (operands[1]) == 0)
1384 switch (GET_CODE (operands[3]))
1386 case EQ: return (TARGET_DENSITY
1389 case NE: return (TARGET_DENSITY
1392 case LT: return "bltz\t%0, %2";
1393 case GE: return "bgez\t%0, %2";
1394 default: gcc_unreachable ();
1399 switch (GET_CODE (operands[3]))
1401 case EQ: return "beqi\t%0, %d1, %2";
1402 case NE: return "bnei\t%0, %d1, %2";
1403 case LT: return "blti\t%0, %d1, %2";
1404 case GE: return "bgei\t%0, %d1, %2";
1405 default: gcc_unreachable ();
1410 [(set_attr "type" "jump,jump")
1411 (set_attr "mode" "none")
1412 (set_attr "length" "3,3")])
1414 (define_insn "*bfalse"
1416 (if_then_else (match_operator 3 "branch_operator"
1417 [(match_operand:SI 0 "register_operand" "r,r")
1418 (match_operand:SI 1 "branch_operand" "K,r")])
1420 (label_ref (match_operand 2 "" ""))))]
1423 if (which_alternative == 1)
1425 switch (GET_CODE (operands[3]))
1427 case EQ: return "bne\t%0, %1, %2";
1428 case NE: return "beq\t%0, %1, %2";
1429 case LT: return "bge\t%0, %1, %2";
1430 case GE: return "blt\t%0, %1, %2";
1431 default: gcc_unreachable ();
1434 else if (INTVAL (operands[1]) == 0)
1436 switch (GET_CODE (operands[3]))
1438 case EQ: return (TARGET_DENSITY
1441 case NE: return (TARGET_DENSITY
1444 case LT: return "bgez\t%0, %2";
1445 case GE: return "bltz\t%0, %2";
1446 default: gcc_unreachable ();
1451 switch (GET_CODE (operands[3]))
1453 case EQ: return "bnei\t%0, %d1, %2";
1454 case NE: return "beqi\t%0, %d1, %2";
1455 case LT: return "bgei\t%0, %d1, %2";
1456 case GE: return "blti\t%0, %d1, %2";
1457 default: gcc_unreachable ();
1462 [(set_attr "type" "jump,jump")
1463 (set_attr "mode" "none")
1464 (set_attr "length" "3,3")])
1466 (define_insn "*ubtrue"
1468 (if_then_else (match_operator 3 "ubranch_operator"
1469 [(match_operand:SI 0 "register_operand" "r,r")
1470 (match_operand:SI 1 "ubranch_operand" "L,r")])
1471 (label_ref (match_operand 2 "" ""))
1475 if (which_alternative == 1)
1477 switch (GET_CODE (operands[3]))
1479 case LTU: return "bltu\t%0, %1, %2";
1480 case GEU: return "bgeu\t%0, %1, %2";
1481 default: gcc_unreachable ();
1486 switch (GET_CODE (operands[3]))
1488 case LTU: return "bltui\t%0, %d1, %2";
1489 case GEU: return "bgeui\t%0, %d1, %2";
1490 default: gcc_unreachable ();
1495 [(set_attr "type" "jump,jump")
1496 (set_attr "mode" "none")
1497 (set_attr "length" "3,3")])
1499 (define_insn "*ubfalse"
1501 (if_then_else (match_operator 3 "ubranch_operator"
1502 [(match_operand:SI 0 "register_operand" "r,r")
1503 (match_operand:SI 1 "ubranch_operand" "L,r")])
1505 (label_ref (match_operand 2 "" ""))))]
1508 if (which_alternative == 1)
1510 switch (GET_CODE (operands[3]))
1512 case LTU: return "bgeu\t%0, %1, %2";
1513 case GEU: return "bltu\t%0, %1, %2";
1514 default: gcc_unreachable ();
1519 switch (GET_CODE (operands[3]))
1521 case LTU: return "bgeui\t%0, %d1, %2";
1522 case GEU: return "bltui\t%0, %d1, %2";
1523 default: gcc_unreachable ();
1528 [(set_attr "type" "jump,jump")
1529 (set_attr "mode" "none")
1530 (set_attr "length" "3,3")])
1532 ;; Branch patterns for bit testing
1534 (define_insn "*bittrue"
1536 (if_then_else (match_operator 3 "boolean_operator"
1538 (match_operand:SI 0 "register_operand" "r,r")
1540 (match_operand:SI 1 "arith_operand" "J,r"))
1542 (label_ref (match_operand 2 "" ""))
1546 if (which_alternative == 0)
1548 unsigned bitnum = INTVAL(operands[1]) & 0x1f;
1549 operands[1] = GEN_INT(bitnum);
1550 switch (GET_CODE (operands[3]))
1552 case EQ: return "bbci\t%0, %d1, %2";
1553 case NE: return "bbsi\t%0, %d1, %2";
1554 default: gcc_unreachable ();
1559 switch (GET_CODE (operands[3]))
1561 case EQ: return "bbc\t%0, %1, %2";
1562 case NE: return "bbs\t%0, %1, %2";
1563 default: gcc_unreachable ();
1568 [(set_attr "type" "jump")
1569 (set_attr "mode" "none")
1570 (set_attr "length" "3")])
1572 (define_insn "*bitfalse"
1574 (if_then_else (match_operator 3 "boolean_operator"
1576 (match_operand:SI 0 "register_operand" "r,r")
1578 (match_operand:SI 1 "arith_operand" "J,r"))
1581 (label_ref (match_operand 2 "" ""))))]
1584 if (which_alternative == 0)
1586 unsigned bitnum = INTVAL (operands[1]) & 0x1f;
1587 operands[1] = GEN_INT (bitnum);
1588 switch (GET_CODE (operands[3]))
1590 case EQ: return "bbsi\t%0, %d1, %2";
1591 case NE: return "bbci\t%0, %d1, %2";
1592 default: gcc_unreachable ();
1597 switch (GET_CODE (operands[3]))
1599 case EQ: return "bbs\t%0, %1, %2";
1600 case NE: return "bbc\t%0, %1, %2";
1601 default: gcc_unreachable ();
1606 [(set_attr "type" "jump")
1607 (set_attr "mode" "none")
1608 (set_attr "length" "3")])
1610 (define_insn "*masktrue"
1612 (if_then_else (match_operator 3 "boolean_operator"
1613 [(and:SI (match_operand:SI 0 "register_operand" "r")
1614 (match_operand:SI 1 "register_operand" "r"))
1616 (label_ref (match_operand 2 "" ""))
1620 switch (GET_CODE (operands[3]))
1622 case EQ: return "bnone\t%0, %1, %2";
1623 case NE: return "bany\t%0, %1, %2";
1624 default: gcc_unreachable ();
1627 [(set_attr "type" "jump")
1628 (set_attr "mode" "none")
1629 (set_attr "length" "3")])
1631 (define_insn "*maskfalse"
1633 (if_then_else (match_operator 3 "boolean_operator"
1634 [(and:SI (match_operand:SI 0 "register_operand" "r")
1635 (match_operand:SI 1 "register_operand" "r"))
1638 (label_ref (match_operand 2 "" ""))))]
1641 switch (GET_CODE (operands[3]))
1643 case EQ: return "bany\t%0, %1, %2";
1644 case NE: return "bnone\t%0, %1, %2";
1645 default: gcc_unreachable ();
1648 [(set_attr "type" "jump")
1649 (set_attr "mode" "none")
1650 (set_attr "length" "3")])
1653 ;; Define the loop insns used by bct optimization to represent the
1654 ;; start and end of a zero-overhead loop (in loop.c). This start
1655 ;; template generates the loop insn; the end template doesn't generate
1656 ;; any instructions since loop end is handled in hardware.
1658 (define_insn "zero_cost_loop_start"
1660 (if_then_else (eq (match_operand:SI 0 "register_operand" "a")
1662 (label_ref (match_operand 1 "" ""))
1665 (plus:SI (match_dup 0) (const_int -1)))]
1668 [(set_attr "type" "jump")
1669 (set_attr "mode" "none")
1670 (set_attr "length" "3")])
1672 (define_insn "zero_cost_loop_end"
1674 (if_then_else (ne (reg:SI 19) (const_int 0))
1675 (label_ref (match_operand 0 "" ""))
1678 (plus:SI (reg:SI 19) (const_int -1)))]
1681 xtensa_emit_loop_end (insn, operands);
1684 [(set_attr "type" "jump")
1685 (set_attr "mode" "none")
1686 (set_attr "length" "0")])
1689 ;; Setting a register from a comparison.
1691 (define_expand "seq"
1692 [(set (match_operand:SI 0 "register_operand" "")
1696 operands[1] = gen_rtx_EQ (SImode, branch_cmp[0], branch_cmp[1]);
1697 if (!xtensa_expand_scc (operands))
1702 (define_expand "sne"
1703 [(set (match_operand:SI 0 "register_operand" "")
1707 operands[1] = gen_rtx_NE (SImode, branch_cmp[0], branch_cmp[1]);
1708 if (!xtensa_expand_scc (operands))
1713 (define_expand "sgt"
1714 [(set (match_operand:SI 0 "register_operand" "")
1718 operands[1] = gen_rtx_GT (SImode, branch_cmp[0], branch_cmp[1]);
1719 if (!xtensa_expand_scc (operands))
1724 (define_expand "sge"
1725 [(set (match_operand:SI 0 "register_operand" "")
1729 operands[1] = gen_rtx_GE (SImode, branch_cmp[0], branch_cmp[1]);
1730 if (!xtensa_expand_scc (operands))
1735 (define_expand "slt"
1736 [(set (match_operand:SI 0 "register_operand" "")
1740 operands[1] = gen_rtx_LT (SImode, branch_cmp[0], branch_cmp[1]);
1741 if (!xtensa_expand_scc (operands))
1746 (define_expand "sle"
1747 [(set (match_operand:SI 0 "register_operand" "")
1751 operands[1] = gen_rtx_LE (SImode, branch_cmp[0], branch_cmp[1]);
1752 if (!xtensa_expand_scc (operands))
1758 ;; Conditional moves.
1760 (define_expand "movsicc"
1761 [(set (match_operand:SI 0 "register_operand" "")
1762 (if_then_else:SI (match_operand 1 "comparison_operator" "")
1763 (match_operand:SI 2 "register_operand" "")
1764 (match_operand:SI 3 "register_operand" "")))]
1767 if (!xtensa_expand_conditional_move (operands, 0))
1772 (define_expand "movsfcc"
1773 [(set (match_operand:SF 0 "register_operand" "")
1774 (if_then_else:SF (match_operand 1 "comparison_operator" "")
1775 (match_operand:SF 2 "register_operand" "")
1776 (match_operand:SF 3 "register_operand" "")))]
1779 if (!xtensa_expand_conditional_move (operands, 1))
1784 (define_insn "movsicc_internal0"
1785 [(set (match_operand:SI 0 "register_operand" "=a,a")
1786 (if_then_else:SI (match_operator 4 "branch_operator"
1787 [(match_operand:SI 1 "register_operand" "r,r")
1789 (match_operand:SI 2 "register_operand" "r,0")
1790 (match_operand:SI 3 "register_operand" "0,r")))]
1793 if (which_alternative == 0)
1795 switch (GET_CODE (operands[4]))
1797 case EQ: return "moveqz\t%0, %2, %1";
1798 case NE: return "movnez\t%0, %2, %1";
1799 case LT: return "movltz\t%0, %2, %1";
1800 case GE: return "movgez\t%0, %2, %1";
1801 default: gcc_unreachable ();
1806 switch (GET_CODE (operands[4]))
1808 case EQ: return "movnez\t%0, %3, %1";
1809 case NE: return "moveqz\t%0, %3, %1";
1810 case LT: return "movgez\t%0, %3, %1";
1811 case GE: return "movltz\t%0, %3, %1";
1812 default: gcc_unreachable ();
1817 [(set_attr "type" "move,move")
1818 (set_attr "mode" "SI")
1819 (set_attr "length" "3,3")])
1821 (define_insn "movsicc_internal1"
1822 [(set (match_operand:SI 0 "register_operand" "=a,a")
1823 (if_then_else:SI (match_operator 4 "boolean_operator"
1824 [(match_operand:CC 1 "register_operand" "b,b")
1826 (match_operand:SI 2 "register_operand" "r,0")
1827 (match_operand:SI 3 "register_operand" "0,r")))]
1830 int isEq = (GET_CODE (operands[4]) == EQ);
1831 switch (which_alternative)
1834 if (isEq) return "movf\t%0, %2, %1";
1835 return "movt\t%0, %2, %1";
1837 if (isEq) return "movt\t%0, %3, %1";
1838 return "movf\t%0, %3, %1";
1843 [(set_attr "type" "move,move")
1844 (set_attr "mode" "SI")
1845 (set_attr "length" "3,3")])
1847 (define_insn "movsfcc_internal0"
1848 [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1849 (if_then_else:SF (match_operator 4 "branch_operator"
1850 [(match_operand:SI 1 "register_operand" "r,r,r,r")
1852 (match_operand:SF 2 "register_operand" "r,0,f,0")
1853 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1856 switch (which_alternative)
1859 switch (GET_CODE (operands[4]))
1861 case EQ: return "moveqz\t%0, %2, %1";
1862 case NE: return "movnez\t%0, %2, %1";
1863 case LT: return "movltz\t%0, %2, %1";
1864 case GE: return "movgez\t%0, %2, %1";
1865 default: gcc_unreachable ();
1869 switch (GET_CODE (operands[4]))
1871 case EQ: return "movnez\t%0, %3, %1";
1872 case NE: return "moveqz\t%0, %3, %1";
1873 case LT: return "movgez\t%0, %3, %1";
1874 case GE: return "movltz\t%0, %3, %1";
1875 default: gcc_unreachable ();
1879 switch (GET_CODE (operands[4]))
1881 case EQ: return "moveqz.s %0, %2, %1";
1882 case NE: return "movnez.s %0, %2, %1";
1883 case LT: return "movltz.s %0, %2, %1";
1884 case GE: return "movgez.s %0, %2, %1";
1885 default: gcc_unreachable ();
1889 switch (GET_CODE (operands[4]))
1891 case EQ: return "movnez.s %0, %3, %1";
1892 case NE: return "moveqz.s %0, %3, %1";
1893 case LT: return "movgez.s %0, %3, %1";
1894 case GE: return "movltz.s %0, %3, %1";
1895 default: gcc_unreachable ();
1903 [(set_attr "type" "move,move,move,move")
1904 (set_attr "mode" "SF")
1905 (set_attr "length" "3,3,3,3")])
1907 (define_insn "movsfcc_internal1"
1908 [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
1909 (if_then_else:SF (match_operator 4 "boolean_operator"
1910 [(match_operand:CC 1 "register_operand" "b,b,b,b")
1912 (match_operand:SF 2 "register_operand" "r,0,f,0")
1913 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
1916 int isEq = (GET_CODE (operands[4]) == EQ);
1917 switch (which_alternative)
1920 if (isEq) return "movf\t%0, %2, %1";
1921 return "movt\t%0, %2, %1";
1923 if (isEq) return "movt\t%0, %3, %1";
1924 return "movf\t%0, %3, %1";
1926 if (isEq) return "movf.s\t%0, %2, %1";
1927 return "movt.s\t%0, %2, %1";
1929 if (isEq) return "movt.s\t%0, %3, %1";
1930 return "movf.s\t%0, %3, %1";
1935 [(set_attr "type" "move,move,move,move")
1936 (set_attr "mode" "SF")
1937 (set_attr "length" "3,3,3,3")])
1940 ;; Floating-point comparisons.
1942 (define_insn "seq_sf"
1943 [(set (match_operand:CC 0 "register_operand" "=b")
1944 (eq:CC (match_operand:SF 1 "register_operand" "f")
1945 (match_operand:SF 2 "register_operand" "f")))]
1948 [(set_attr "type" "farith")
1949 (set_attr "mode" "BL")
1950 (set_attr "length" "3")])
1952 (define_insn "slt_sf"
1953 [(set (match_operand:CC 0 "register_operand" "=b")
1954 (lt:CC (match_operand:SF 1 "register_operand" "f")
1955 (match_operand:SF 2 "register_operand" "f")))]
1958 [(set_attr "type" "farith")
1959 (set_attr "mode" "BL")
1960 (set_attr "length" "3")])
1962 (define_insn "sle_sf"
1963 [(set (match_operand:CC 0 "register_operand" "=b")
1964 (le:CC (match_operand:SF 1 "register_operand" "f")
1965 (match_operand:SF 2 "register_operand" "f")))]
1968 [(set_attr "type" "farith")
1969 (set_attr "mode" "BL")
1970 (set_attr "length" "3")])
1973 ;; Unconditional branches.
1977 (label_ref (match_operand 0 "" "")))]
1980 [(set_attr "type" "jump")
1981 (set_attr "mode" "none")
1982 (set_attr "length" "3")])
1984 (define_expand "indirect_jump"
1986 (match_operand 0 "register_operand" ""))]
1989 rtx dest = operands[0];
1990 if (GET_CODE (dest) != REG || GET_MODE (dest) != Pmode)
1991 operands[0] = copy_to_mode_reg (Pmode, dest);
1993 emit_jump_insn (gen_indirect_jump_internal (dest));
1997 (define_insn "indirect_jump_internal"
1998 [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
2001 [(set_attr "type" "jump")
2002 (set_attr "mode" "none")
2003 (set_attr "length" "3")])
2006 (define_expand "tablejump"
2007 [(use (match_operand:SI 0 "register_operand" ""))
2008 (use (label_ref (match_operand 1 "" "")))]
2011 rtx target = operands[0];
2014 /* For PIC, the table entry is relative to the start of the table. */
2015 rtx label = gen_reg_rtx (SImode);
2016 target = gen_reg_rtx (SImode);
2017 emit_move_insn (label, gen_rtx_LABEL_REF (SImode, operands[1]));
2018 emit_insn (gen_addsi3 (target, operands[0], label));
2020 emit_jump_insn (gen_tablejump_internal (target, operands[1]));
2024 (define_insn "tablejump_internal"
2026 (match_operand:SI 0 "register_operand" "r"))
2027 (use (label_ref (match_operand 1 "" "")))]
2030 [(set_attr "type" "jump")
2031 (set_attr "mode" "none")
2032 (set_attr "length" "3")])
2037 (define_expand "sym_PLT"
2038 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PLT))]
2042 (define_expand "call"
2043 [(call (match_operand 0 "memory_operand" "")
2044 (match_operand 1 "" ""))]
2047 rtx addr = XEXP (operands[0], 0);
2048 if (flag_pic && GET_CODE (addr) == SYMBOL_REF
2049 && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
2050 addr = gen_sym_PLT (addr);
2051 if (!call_insn_operand (addr, VOIDmode))
2052 XEXP (operands[0], 0) = copy_to_mode_reg (Pmode, addr);
2055 (define_insn "call_internal"
2056 [(call (mem (match_operand:SI 0 "call_insn_operand" "n,i,r"))
2057 (match_operand 1 "" "i,i,i"))]
2060 return xtensa_emit_call (0, operands);
2062 [(set_attr "type" "call")
2063 (set_attr "mode" "none")
2064 (set_attr "length" "3")])
2066 (define_expand "call_value"
2067 [(set (match_operand 0 "register_operand" "")
2068 (call (match_operand 1 "memory_operand" "")
2069 (match_operand 2 "" "")))]
2072 rtx addr = XEXP (operands[1], 0);
2073 if (flag_pic && GET_CODE (addr) == SYMBOL_REF
2074 && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr)))
2075 addr = gen_sym_PLT (addr);
2076 if (!call_insn_operand (addr, VOIDmode))
2077 XEXP (operands[1], 0) = copy_to_mode_reg (Pmode, addr);
2080 ;; Cannot combine constraints for operand 0 into "afvb":
2081 ;; reload.c:find_reloads seems to assume that grouped constraints somehow
2082 ;; specify related register classes, and when they don't the constraints
2083 ;; fail to match. By not grouping the constraints, we get the correct
2085 (define_insn "call_value_internal"
2086 [(set (match_operand 0 "register_operand" "=af,af,af,v,v,v,b,b,b")
2087 (call (mem (match_operand:SI 1 "call_insn_operand"
2088 "n,i,r,n,i,r,n,i,r"))
2089 (match_operand 2 "" "i,i,i,i,i,i,i,i,i")))]
2092 return xtensa_emit_call (1, operands);
2094 [(set_attr "type" "call")
2095 (set_attr "mode" "none")
2096 (set_attr "length" "3")])
2098 (define_insn "entry"
2099 [(set (reg:SI A1_REG)
2100 (unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "i")
2101 (match_operand:SI 1 "const_int_operand" "i")]
2105 [(set_attr "type" "move")
2106 (set_attr "mode" "SI")
2107 (set_attr "length" "3")])
2109 (define_insn "return"
2111 (use (reg:SI A0_REG))]
2114 return (TARGET_DENSITY ? "retw.n" : "retw");
2116 [(set_attr "type" "jump")
2117 (set_attr "mode" "none")
2118 (set_attr "length" "2")])
2121 ;; Miscellaneous instructions.
2123 (define_expand "prologue"
2127 xtensa_expand_prologue ();
2131 (define_expand "epilogue"
2135 emit_jump_insn (gen_return ());
2143 return (TARGET_DENSITY ? "nop.n" : "nop");
2145 [(set_attr "type" "nop")
2146 (set_attr "mode" "none")
2147 (set_attr "length" "3")])
2149 (define_expand "nonlocal_goto"
2150 [(match_operand:SI 0 "general_operand" "")
2151 (match_operand:SI 1 "general_operand" "")
2152 (match_operand:SI 2 "general_operand" "")
2153 (match_operand:SI 3 "" "")]
2156 xtensa_expand_nonlocal_goto (operands);
2160 ;; Setting up a frame pointer is tricky for Xtensa because GCC doesn't
2161 ;; know if a frame pointer is required until the reload pass, and
2162 ;; because there may be an incoming argument value in the hard frame
2163 ;; pointer register (a7). If there is an incoming argument in that
2164 ;; register, the "set_frame_ptr" insn gets inserted immediately after
2165 ;; the insn that copies the incoming argument to a pseudo or to the
2166 ;; stack. This serves several purposes here: (1) it keeps the
2167 ;; optimizer from copy-propagating or scheduling the use of a7 as an
2168 ;; incoming argument away from the beginning of the function; (2) we
2169 ;; can use a post-reload splitter to expand away the insn if a frame
2170 ;; pointer is not required, so that the post-reload scheduler can do
2171 ;; the right thing; and (3) it makes it easy for the prologue expander
2172 ;; to search for this insn to determine whether it should add a new insn
2173 ;; to set up the frame pointer.
2175 (define_insn "set_frame_ptr"
2176 [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
2179 if (frame_pointer_needed)
2180 return "mov\ta7, sp";
2183 [(set_attr "type" "move")
2184 (set_attr "mode" "SI")
2185 (set_attr "length" "3")])
2187 ;; Post-reload splitter to remove fp assignment when it's not needed.
2189 [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
2190 "reload_completed && !frame_pointer_needed"
2191 [(unspec [(const_int 0)] UNSPEC_NOP)]
2194 ;; The preceding splitter needs something to split the insn into;
2195 ;; things start breaking if the result is just a "use" so instead we
2196 ;; generate the following insn.
2197 (define_insn "*unspec_nop"
2198 [(unspec [(const_int 0)] UNSPEC_NOP)]
2201 [(set_attr "type" "nop")
2202 (set_attr "mode" "none")
2203 (set_attr "length" "0")])
2205 ;; The fix_return_addr pattern sets the high 2 bits of an address in a
2206 ;; register to match the high bits of the current PC.
2207 (define_insn "fix_return_addr"
2208 [(set (match_operand:SI 0 "register_operand" "=a")
2209 (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
2211 (clobber (match_scratch:SI 2 "=r"))
2212 (clobber (match_scratch:SI 3 "=r"))]
2214 "mov\t%2, a0\;call0\t0f\;.align\t4\;0:\;mov\t%3, a0\;mov\ta0, %2\;\
2215 srli\t%3, %3, 30\;slli\t%0, %1, 2\;ssai\t2\;src\t%0, %3, %0"
2216 [(set_attr "type" "multi")
2217 (set_attr "mode" "SI")
2218 (set_attr "length" "24")])
2221 ;; Instructions for the Xtensa "boolean" option.
2223 (define_insn "*booltrue"
2225 (if_then_else (match_operator 2 "boolean_operator"
2226 [(match_operand:CC 0 "register_operand" "b")
2228 (label_ref (match_operand 1 "" ""))
2232 if (GET_CODE (operands[2]) == EQ)
2233 return "bf\t%0, %1";
2235 return "bt\t%0, %1";
2237 [(set_attr "type" "jump")
2238 (set_attr "mode" "none")
2239 (set_attr "length" "3")])
2241 (define_insn "*boolfalse"
2243 (if_then_else (match_operator 2 "boolean_operator"
2244 [(match_operand:CC 0 "register_operand" "b")
2247 (label_ref (match_operand 1 "" ""))))]
2250 if (GET_CODE (operands[2]) == EQ)
2251 return "bt\t%0, %1";
2253 return "bf\t%0, %1";
2255 [(set_attr "type" "jump")
2256 (set_attr "mode" "none")
2257 (set_attr "length" "3")])