Debian Codegraph @

gcc/config/xtensa/xtensa.md

raw
1 ;; GCC machine description for Tensilica's Xtensa architecture.
2 ;; Copyright (C) 2001-2025 Free Software Foundation, Inc.
3 ;; Contributed by Bob Wilson ([email protected]) at Tensilica.
4
5 ;; This file is part of GCC.
6
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)
10 ;; any later version.
11
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.
16
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/>.
20
21
22 (define_constants [
23 (A0_REG 0)
24 (A1_REG 1)
25 (A7_REG 7)
26 (A8_REG 8)
27 (A9_REG 9)
28 ])
29
30 (define_c_enum "unspec" [
31 UNSPEC_NOP
32 UNSPEC_PLT
33 UNSPEC_RET_ADDR
34 UNSPEC_TPOFF
35 UNSPEC_DTPOFF
36 UNSPEC_TLS_FUNC
37 UNSPEC_TLS_ARG
38 UNSPEC_TLS_CALL
39 UNSPEC_TP
40 UNSPEC_MEMW
41 UNSPEC_LSETUP_START
42 UNSPEC_LSETUP_END
43 UNSPEC_FRAME_BLOCKAGE
44 ])
45
46 (define_c_enum "unspecv" [
47 UNSPECV_SET_FP
48 UNSPECV_ENTRY
49 UNSPECV_S32RI
50 UNSPECV_S32C1I
51 UNSPECV_EH_RETURN
52 UNSPECV_SET_TP
53 UNSPECV_BLOCKAGE
54 ])
55
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])
59
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")])
63
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")])
66
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])
70
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")])
74
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")
79 (unordered "un")])
80
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")])
85
86 ;; This mode iterator allows the HI and QI patterns to be defined from
87 ;; the same template.
88 (define_mode_iterator HQI [HI QI])
89
90 ;; This mode iterator allows the SI and HI patterns to be defined from
91 ;; the same template.
92 (define_mode_iterator SHI [SI HI])
93
94 ;; This iterator and attribute allow signed/unsigned FP truncations to be
95 ;; generated from one template.
96 (define_code_iterator any_fix [fix unsigned_fix])
97 (define_code_attr m_fix [(fix "trunc") (unsigned_fix "utrunc")])
98 (define_code_attr s_fix [(fix "") (unsigned_fix "uns")])
99
100 ;; This iterator and attribute allow signed/unsigned FP conversions to be
101 ;; generated from one template.
102 (define_code_iterator any_float [float unsigned_float])
103 (define_code_attr m_float [(float "float") (unsigned_float "ufloat")])
104 (define_code_attr s_float [(float "") (unsigned_float "uns")])
105
106
107 ;; Attributes.
108
109 (define_attr "type"
110 "unknown,jump,call,load,store,move,arith,multi,nop,farith,fmadd,fconv,fload,fstore,mul16,mul32,div32,mac16,rsr,wsr,entry,trap"
111 (const_string "unknown"))
112
113 (define_attr "mode"
114 "unknown,none,QI,HI,SI,DI,SF,DF,BL"
115 (const_string "unknown"))
116
117 (define_attr "length" "" (const_int 1))
118
119 ;; Describe a user's asm statement.
120 (define_asm_attributes
121 [(set_attr "type" "multi")
122 (set_attr "mode" "none")
123 (set_attr "length" "3")]) ;; Should be the maximum possible length
124 ;; of a single machine instruction.
125
126
127 ;; Pipeline model.
128
129 ;; The Xtensa basically has simple 5-stage RISC pipeline.
130 ;; Most instructions complete in 1 cycle, and it is OK to assume that
131 ;; everything is fully pipelined. The exceptions have special insn
132 ;; reservations in the pipeline description below. The Xtensa can
133 ;; issue one instruction per cycle, so defining CPU units is unnecessary.
134
135 (define_insn_reservation "xtensa_any_insn" 1
136 (eq_attr "type" "!load,fload,rsr,mul16,mul32,fmadd,fconv")
137 "nothing")
138
139 (define_insn_reservation "xtensa_memory" 2
140 (eq_attr "type" "load,fload")
141 "nothing")
142
143 (define_insn_reservation "xtensa_sreg" 2
144 (eq_attr "type" "rsr")
145 "nothing")
146
147 (define_insn_reservation "xtensa_mul16" 2
148 (eq_attr "type" "mul16")
149 "nothing")
150
151 (define_insn_reservation "xtensa_mul32" 2
152 (eq_attr "type" "mul32")
153 "nothing")
154
155 (define_insn_reservation "xtensa_fmadd" 4
156 (eq_attr "type" "fmadd")
157 "nothing")
158
159 (define_insn_reservation "xtensa_fconv" 2
160 (eq_attr "type" "fconv")
161 "nothing")
162
163 ;; Include predicates and constraints.
164
165 (include "predicates.md")
166 (include "constraints.md")
167
168
169 ;; Addition.
170
171 (define_insn "addsi3"
172 [(set (match_operand:SI 0 "register_operand" "=D,D,a,a,a")
173 (plus:SI (match_operand:SI 1 "register_operand" "%d,d,r,r,r")
174 (match_operand:SI 2 "add_operand" "d,O,r,J,N")))]
175 ""
176 "@
177 add.n\t%0, %1, %2
178 addi.n\t%0, %1, %d2
179 add\t%0, %1, %2
180 addi\t%0, %1, %d2
181 addmi\t%0, %1, %x2"
182 [(set_attr "type" "arith,arith,arith,arith,arith")
183 (set_attr "mode" "SI")
184 (set_attr "length" "2,2,3,3,3")])
185
186 (define_insn "*addsubx"
187 [(set (match_operand:SI 0 "register_operand" "=a")
188 (match_operator:SI 4 "addsub_operator"
189 [(ashift:SI (match_operand:SI 1 "register_operand" "r")
190 (match_operand:SI 3 "addsubx_operand" "i"))
191 (match_operand:SI 2 "register_operand" "r")]))]
192 "TARGET_ADDX"
193 {
194 operands[3] = GEN_INT (1 << INTVAL (operands[3]));
195 return GET_CODE (operands[4]) == PLUS
196 ? "addx%3\t%0, %1, %2" : "subx%3\t%0, %1, %2";
197 }
198 [(set_attr "type" "arith")
199 (set_attr "mode" "SI")
200 (set_attr "length" "3")])
201
202 (define_split
203 [(set (match_operand:SI 0 "register_operand")
204 (plus:SI (ashift:SI (match_operand:SI 1 "register_operand")
205 (match_operand:SI 3 "addsubx_operand"))
206 (match_operand:SI 2 "const_int_operand")))]
207 "TARGET_ADDX && can_create_pseudo_p ()"
208 [(set (match_dup 0)
209 (plus:SI (ashift:SI (match_dup 1)
210 (match_dup 3))
211 (match_dup 2)))]
212 {
213 operands[2] = force_reg (SImode, operands[2]);
214 })
215
216 (define_expand "adddi3"
217 [(set (match_operand:DI 0 "register_operand")
218 (plus:DI (match_operand:DI 1 "register_operand")
219 (match_operand:DI 2 "register_operand")))]
220 ""
221 {
222 rtx lo_dest, hi_dest, lo_op0, hi_op0, lo_op1, hi_op1;
223 rtx_code_label *label;
224 if (rtx_equal_p (operands[0], operands[1])
225 || rtx_equal_p (operands[0], operands[2])
226 || ! REG_P (operands[1]) || ! REG_P (operands[2]))
227 FAIL;
228 lo_dest = gen_lowpart (SImode, operands[0]);
229 hi_dest = gen_highpart (SImode, operands[0]);
230 lo_op0 = gen_lowpart (SImode, operands[1]);
231 hi_op0 = gen_highpart (SImode, operands[1]);
232 lo_op1 = gen_lowpart (SImode, operands[2]);
233 hi_op1 = gen_highpart (SImode, operands[2]);
234 emit_insn (gen_addsi3 (hi_dest, hi_op0, hi_op1));
235 emit_insn (gen_addsi3 (lo_dest, lo_op0, lo_op1));
236 emit_cmp_and_jump_insns (lo_dest,
237 (REGNO (operands[1]) < REGNO (operands[2])
238 ? lo_op1 : lo_op0), GEU, const0_rtx,
239 SImode, true, label = gen_label_rtx ());
240 emit_insn (gen_addsi3 (hi_dest, hi_dest, const1_rtx));
241 emit_label (label);
242 DONE;
243 })
244
245 (define_insn "addsf3"
246 [(set (match_operand:SF 0 "register_operand" "=f")
247 (plus:SF (match_operand:SF 1 "register_operand" "%f")
248 (match_operand:SF 2 "register_operand" "f")))]
249 "TARGET_HARD_FLOAT"
250 "add.s\t%0, %1, %2"
251 [(set_attr "type" "fmadd")
252 (set_attr "mode" "SF")
253 (set_attr "length" "3")])
254
255
256 ;; Subtraction.
257
258 (define_insn "subsi3"
259 [(set (match_operand:SI 0 "register_operand" "=a")
260 (minus:SI (match_operand:SI 1 "register_operand" "r")
261 (match_operand:SI 2 "register_operand" "r")))]
262 ""
263 "sub\t%0, %1, %2"
264 [(set_attr "type" "arith")
265 (set_attr "mode" "SI")
266 (set_attr "length" "3")])
267
268 (define_insn_and_split "*subsi3_from_const"
269 [(set (match_operand:SI 0 "register_operand" "=a")
270 (minus:SI (match_operand:SI 1 "const_int_operand" "i")
271 (match_operand:SI 2 "register_operand" "r")))]
272 "xtensa_simm8 (-INTVAL (operands[1]))
273 || xtensa_simm8x256 (-INTVAL (operands[1]))"
274 "#"
275 "&& 1"
276 [(set (match_dup 0)
277 (plus:SI (match_dup 2)
278 (match_dup 1)))
279 (set (match_dup 0)
280 (neg:SI (match_dup 0)))]
281 {
282 operands[1] = GEN_INT (-INTVAL (operands[1]));
283 }
284 [(set_attr "type" "arith")
285 (set_attr "mode" "SI")
286 (set (attr "length")
287 (if_then_else (match_test "TARGET_DENSITY
288 && xtensa_m1_or_1_thru_15 (-INTVAL (operands[1]))")
289 (const_int 5)
290 (const_int 6)))])
291
292 (define_expand "subdi3"
293 [(set (match_operand:DI 0 "register_operand")
294 (minus:DI (match_operand:DI 1 "register_operand")
295 (match_operand:DI 2 "register_operand")))]
296 ""
297 {
298 rtx lo_dest, hi_dest, lo_op0, hi_op0, lo_op1, hi_op1;
299 rtx_code_label *label;
300 lo_dest = gen_lowpart (SImode, operands[0]);
301 hi_dest = gen_highpart (SImode, operands[0]);
302 lo_op0 = gen_lowpart (SImode, operands[1]);
303 hi_op0 = gen_highpart (SImode, operands[1]);
304 lo_op1 = gen_lowpart (SImode, operands[2]);
305 hi_op1 = gen_highpart (SImode, operands[2]);
306 emit_insn (gen_subsi3 (hi_dest, hi_op0, hi_op1));
307 emit_cmp_and_jump_insns (lo_op0, lo_op1, GEU, const0_rtx,
308 SImode, true, label = gen_label_rtx ());
309 emit_insn (gen_addsi3 (hi_dest, hi_dest, constm1_rtx));
310 emit_label (label);
311 emit_insn (gen_subsi3 (lo_dest, lo_op0, lo_op1));
312 DONE;
313 })
314
315 (define_insn "subsf3"
316 [(set (match_operand:SF 0 "register_operand" "=f")
317 (minus:SF (match_operand:SF 1 "register_operand" "f")
318 (match_operand:SF 2 "register_operand" "f")))]
319 "TARGET_HARD_FLOAT"
320 "sub.s\t%0, %1, %2"
321 [(set_attr "type" "fmadd")
322 (set_attr "mode" "SF")
323 (set_attr "length" "3")])
324
325
326 ;; Multiplication.
327
328 (define_expand "mulsidi3"
329 [(set (match_operand:DI 0 "register_operand")
330 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand"))
331 (sign_extend:DI (match_operand:SI 2 "register_operand"))))]
332 "TARGET_MUL32_HIGH"
333 {
334 rtx temp = gen_reg_rtx (SImode);
335 emit_insn (gen_mulsi3 (temp, operands[1], operands[2]));
336 emit_insn (gen_mulsi3_highpart (gen_highpart (SImode, operands[0]),
337 operands[1], operands[2]));
338 emit_insn (gen_movsi (gen_lowpart (SImode, operands[0]), temp));
339 DONE;
340 })
341
342 (define_expand "umulsidi3"
343 [(set (match_operand:DI 0 "register_operand")
344 (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand"))
345 (zero_extend:DI (match_operand:SI 2 "register_operand"))))]
346 ""
347 {
348 if (TARGET_MUL32_HIGH)
349 {
350 rtx temp = gen_reg_rtx (SImode);
351 emit_insn (gen_mulsi3 (temp, operands[1], operands[2]));
352 emit_insn (gen_umulsi3_highpart (gen_highpart (SImode, operands[0]),
353 operands[1], operands[2]));
354 emit_insn (gen_movsi (gen_lowpart (SImode, operands[0]), temp));
355 }
356 else
357 emit_library_call_value (gen_rtx_SYMBOL_REF (Pmode, "__umulsidi3"),
358 operands[0], LCT_NORMAL, DImode,
359 operands[1], SImode,
360 operands[2], SImode);
361 DONE;
362 })
363
364 (define_insn "<u>mulsi3_highpart"
365 [(set (match_operand:SI 0 "register_operand" "=a")
366 (truncate:SI
367 (lshiftrt:DI
368 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "%r"))
369 (any_extend:DI (match_operand:SI 2 "register_operand" "r")))
370 (const_int 32))))]
371 "TARGET_MUL32_HIGH"
372 "mul<su>h\t%0, %1, %2"
373 [(set_attr "type" "mul32")
374 (set_attr "mode" "SI")
375 (set_attr "length" "3")])
376
377 (define_insn "mulsi3"
378 [(set (match_operand:SI 0 "register_operand" "=a")
379 (mult:SI (match_operand:SI 1 "register_operand" "%r")
380 (match_operand:SI 2 "register_operand" "r")))]
381 "TARGET_MUL32"
382 "mull\t%0, %1, %2"
383 [(set_attr "type" "mul32")
384 (set_attr "mode" "SI")
385 (set_attr "length" "3")])
386
387 (define_insn "<u>mulhisi3"
388 [(set (match_operand:SI 0 "register_operand" "=C,A")
389 (mult:SI (any_extend:SI
390 (match_operand:HI 1 "register_operand" "%r,r"))
391 (any_extend:SI
392 (match_operand:HI 2 "register_operand" "r,r"))))]
393 "TARGET_MUL16 || TARGET_MAC16"
394 "@
395 mul16<su>\t%0, %1, %2
396 <u>mul.aa.ll\t%1, %2"
397 [(set_attr "type" "mul16,mac16")
398 (set_attr "mode" "SI")
399 (set_attr "length" "3,3")])
400
401 (define_insn "muladdhisi"
402 [(set (match_operand:SI 0 "register_operand" "=A")
403 (plus:SI (mult:SI (sign_extend:SI
404 (match_operand:HI 1 "register_operand" "%r"))
405 (sign_extend:SI
406 (match_operand:HI 2 "register_operand" "r")))
407 (match_operand:SI 3 "register_operand" "0")))]
408 "TARGET_MAC16"
409 "mula.aa.ll\t%1, %2"
410 [(set_attr "type" "mac16")
411 (set_attr "mode" "SI")
412 (set_attr "length" "3")])
413
414 (define_insn "mulsubhisi"
415 [(set (match_operand:SI 0 "register_operand" "=A")
416 (minus:SI (match_operand:SI 1 "register_operand" "0")
417 (mult:SI (sign_extend:SI
418 (match_operand:HI 2 "register_operand" "%r"))
419 (sign_extend:SI
420 (match_operand:HI 3 "register_operand" "r")))))]
421 "TARGET_MAC16"
422 "muls.aa.ll\t%2, %3"
423 [(set_attr "type" "mac16")
424 (set_attr "mode" "SI")
425 (set_attr "length" "3")])
426
427 (define_insn "mulsf3"
428 [(set (match_operand:SF 0 "register_operand" "=f")
429 (mult:SF (match_operand:SF 1 "register_operand" "%f")
430 (match_operand:SF 2 "register_operand" "f")))]
431 "TARGET_HARD_FLOAT"
432 "mul.s\t%0, %1, %2"
433 [(set_attr "type" "fmadd")
434 (set_attr "mode" "SF")
435 (set_attr "length" "3")])
436
437 (define_insn "fmasf4"
438 [(set (match_operand:SF 0 "register_operand" "=f")
439 (fma:SF (match_operand:SF 1 "register_operand" "f")
440 (match_operand:SF 2 "register_operand" "f")
441 (match_operand:SF 3 "register_operand" "0")))]
442 "TARGET_HARD_FLOAT"
443 "madd.s\t%0, %1, %2"
444 [(set_attr "type" "fmadd")
445 (set_attr "mode" "SF")
446 (set_attr "length" "3")])
447
448 ;; Note that (C - A*B) = (-A*B + C)
449 (define_insn "fnmasf4"
450 [(set (match_operand:SF 0 "register_operand" "=f")
451 (fma:SF (neg:SF (match_operand:SF 1 "register_operand" "f"))
452 (match_operand:SF 2 "register_operand" "f")
453 (match_operand:SF 3 "register_operand" "0")))]
454 "TARGET_HARD_FLOAT"
455 "msub.s\t%0, %1, %2"
456 [(set_attr "type" "fmadd")
457 (set_attr "mode" "SF")
458 (set_attr "length" "3")])
459
460
461 ;; Division.
462
463 (define_insn "divsi3"
464 [(set (match_operand:SI 0 "register_operand" "=a")
465 (div:SI (match_operand:SI 1 "register_operand" "r")
466 (match_operand:SI 2 "register_operand" "r")))]
467 "TARGET_DIV32"
468 "quos\t%0, %1, %2"
469 [(set_attr "type" "div32")
470 (set_attr "mode" "SI")
471 (set_attr "length" "3")])
472
473 (define_insn "udivsi3"
474 [(set (match_operand:SI 0 "register_operand" "=a")
475 (udiv:SI (match_operand:SI 1 "register_operand" "r")
476 (match_operand:SI 2 "register_operand" "r")))]
477 "TARGET_DIV32"
478 "quou\t%0, %1, %2"
479 [(set_attr "type" "div32")
480 (set_attr "mode" "SI")
481 (set_attr "length" "3")])
482
483
484 ;; Remainders.
485
486 (define_insn "modsi3"
487 [(set (match_operand:SI 0 "register_operand" "=a")
488 (mod:SI (match_operand:SI 1 "register_operand" "r")
489 (match_operand:SI 2 "register_operand" "r")))]
490 "TARGET_DIV32"
491 "rems\t%0, %1, %2"
492 [(set_attr "type" "div32")
493 (set_attr "mode" "SI")
494 (set_attr "length" "3")])
495
496 (define_insn "umodsi3"
497 [(set (match_operand:SI 0 "register_operand" "=a")
498 (umod:SI (match_operand:SI 1 "register_operand" "r")
499 (match_operand:SI 2 "register_operand" "r")))]
500 "TARGET_DIV32"
501 "remu\t%0, %1, %2"
502 [(set_attr "type" "div32")
503 (set_attr "mode" "SI")
504 (set_attr "length" "3")])
505
506
507 ;; Absolute value.
508
509 (define_insn "abssi2"
510 [(set (match_operand:SI 0 "register_operand" "=a")
511 (abs:SI (match_operand:SI 1 "register_operand" "r")))]
512 "TARGET_ABS"
513 "abs\t%0, %1"
514 [(set_attr "type" "arith")
515 (set_attr "mode" "SI")
516 (set_attr "length" "3")])
517
518 (define_insn "abssf2"
519 [(set (match_operand:SF 0 "register_operand" "=f")
520 (abs:SF (match_operand:SF 1 "register_operand" "f")))]
521 "TARGET_HARD_FLOAT"
522 "abs.s\t%0, %1"
523 [(set_attr "type" "farith")
524 (set_attr "mode" "SF")
525 (set_attr "length" "3")])
526
527
528 ;; Min and max.
529
530 (define_insn "<code>si3"
531 [(set (match_operand:SI 0 "register_operand" "=a")
532 (any_minmax:SI (match_operand:SI 1 "register_operand" "%r")
533 (match_operand:SI 2 "register_operand" "r")))]
534 "TARGET_MINMAX"
535 "<minmax>\t%0, %1, %2"
536 [(set_attr "type" "arith")
537 (set_attr "mode" "SI")
538 (set_attr "length" "3")])
539
540
541 ;; Signed clamp.
542
543 (define_insn "*xtensa_clamps"
544 [(set (match_operand:SI 0 "register_operand" "=a")
545 (match_operator:SI 5 "xtensa_sminmax_operator"
546 [(match_operator:SI 4 "xtensa_sminmax_operator"
547 [(match_operand:SI 1 "register_operand" "r")
548 (match_operand:SI 2 "const_int_operand" "i")])
549 (match_operand:SI 3 "const_int_operand" "i")]))]
550 "TARGET_MINMAX && TARGET_CLAMPS
551 && INTVAL (operands[2]) + INTVAL (operands[3]) == -1
552 && ((GET_CODE (operands[5]) == SMIN && GET_CODE (operands[4]) == SMAX
553 && IN_RANGE (exact_log2 (-INTVAL (operands[2])), 7, 22))
554 || (GET_CODE (operands[5]) == SMAX && GET_CODE (operands[4]) == SMIN
555 && IN_RANGE (exact_log2 (-INTVAL (operands[3])), 7, 22)))"
556 {
557 static char result[64];
558 rtx bound = operands[GET_CODE (operands[4]) == SMAX ? 2 : 3];
559 sprintf (result, "clamps\t%%0, %%1, %d", floor_log2 (-INTVAL (bound)));
560 return result;
561 }
562 [(set_attr "type" "arith")
563 (set_attr "mode" "SI")
564 (set_attr "length" "3")])
565
566
567 ;; Count redundant leading sign bits and leading/trailing zeros,
568 ;; and find first bit.
569
570 (define_insn "clrsbsi2"
571 [(set (match_operand:SI 0 "register_operand" "=a")
572 (clrsb:SI (match_operand:SI 1 "register_operand" "r")))]
573 "TARGET_NSA"
574 "nsa\t%0, %1"
575 [(set_attr "type" "arith")
576 (set_attr "mode" "SI")
577 (set_attr "length" "3")])
578
579 (define_insn "clzsi2"
580 [(set (match_operand:SI 0 "register_operand" "=a")
581 (clz:SI (match_operand:SI 1 "register_operand" "r")))]
582 "TARGET_NSA"
583 "nsau\t%0, %1"
584 [(set_attr "type" "arith")
585 (set_attr "mode" "SI")
586 (set_attr "length" "3")])
587
588 (define_expand "ctzsi2"
589 [(set (match_operand:SI 0 "register_operand" "")
590 (ctz:SI (match_operand:SI 1 "register_operand" "")))]
591 "TARGET_NSA"
592 {
593 rtx temp = gen_reg_rtx (SImode);
594 emit_insn (gen_negsi2 (temp, operands[1]));
595 emit_insn (gen_andsi3 (temp, temp, operands[1]));
596 emit_insn (gen_clzsi2 (temp, temp));
597 emit_move_insn (operands[0], GEN_INT (31));
598 emit_insn (gen_subsi3 (operands[0], operands[0], temp));
599 DONE;
600 })
601
602 (define_expand "ffssi2"
603 [(set (match_operand:SI 0 "register_operand" "")
604 (ffs:SI (match_operand:SI 1 "register_operand" "")))]
605 "TARGET_NSA"
606 {
607 rtx temp = gen_reg_rtx (SImode);
608 emit_insn (gen_negsi2 (temp, operands[1]));
609 emit_insn (gen_andsi3 (temp, temp, operands[1]));
610 emit_insn (gen_clzsi2 (temp, temp));
611 emit_move_insn (operands[0], GEN_INT (32));
612 emit_insn (gen_subsi3 (operands[0], operands[0], temp));
613 DONE;
614 })
615
616
617 ;; Byte swap.
618
619 (define_insn "bswaphi2"
620 [(set (match_operand:HI 0 "register_operand" "=a")
621 (bswap:HI (match_operand:HI 1 "register_operand" "r")))
622 (clobber (match_scratch:HI 2 "=&a"))]
623 ""
624 "extui\t%2, %1, 8, 8\;slli\t%0, %1, 8\;or\t%0, %0, %2"
625 [(set_attr "type" "arith")
626 (set_attr "mode" "HI")
627 (set_attr "length" "9")])
628
629 (define_expand "bswapsi2"
630 [(set (match_operand:SI 0 "register_operand" "")
631 (bswap:SI (match_operand:SI 1 "register_operand" "")))]
632 "!optimize_debug && optimize > 1"
633 {
634 /* GIMPLE manual byte-swapping recognition is now activated.
635 For both built-in and manual bswaps, emit corresponding library call
636 if optimizing for size, or a series of dedicated machine instructions
637 if otherwise. */
638 if (optimize_size)
639 emit_library_call_value (optab_libfunc (bswap_optab, SImode),
640 operands[0], LCT_NORMAL, SImode,
641 operands[1], SImode);
642 else
643 emit_insn (gen_bswapsi2_internal (operands[0], operands[1]));
644 DONE;
645 })
646
647 (define_insn "bswapsi2_internal"
648 [(set (match_operand:SI 0 "register_operand" "=a,&a")
649 (bswap:SI (match_operand:SI 1 "register_operand" "0,r")))
650 (clobber (match_scratch:SI 2 "=&a,X"))]
651 "!optimize_debug && optimize > 1 && !optimize_size"
652 {
653 rtx_insn *prev_insn = prev_nonnote_nondebug_insn (insn);
654 const char *init = "ssai\t8\;";
655 static char result[128];
656 if (prev_insn && NONJUMP_INSN_P (prev_insn))
657 {
658 rtx x = PATTERN (prev_insn);
659 if (GET_CODE (x) == PARALLEL && XVECLEN (x, 0) == 2
660 && GET_CODE (XVECEXP (x, 0, 0)) == SET
661 && GET_CODE (XVECEXP (x, 0, 1)) == CLOBBER)
662 {
663 x = XEXP (XVECEXP (x, 0, 0), 1);
664 if (GET_CODE (x) == BSWAP && GET_MODE (x) == SImode)
665 init = "";
666 }
667 }
668 sprintf (result,
669 (which_alternative == 0)
670 ? "%s" "srli\t%%2, %%1, 16\;src\t%%2, %%2, %%1\;src\t%%2, %%2, %%2\;src\t%%0, %%1, %%2"
671 : "%s" "srli\t%%0, %%1, 16\;src\t%%0, %%0, %%1\;src\t%%0, %%0, %%0\;src\t%%0, %%1, %%0",
672 init);
673 return result;
674 }
675 [(set_attr "type" "arith,arith")
676 (set_attr "mode" "SI")
677 (set_attr "length" "15,15")])
678
679 (define_expand "bswapdi2"
680 [(set (match_operand:DI 0 "register_operand" "")
681 (bswap:DI (match_operand:DI 1 "register_operand" "")))]
682 "!optimize_debug && optimize > 1 && optimize_size"
683 {
684 /* Replace with a single DImode library call.
685 Without this, two SImode library calls are emitted. */
686 emit_library_call_value (optab_libfunc (bswap_optab, DImode),
687 operands[0], LCT_NORMAL, DImode,
688 operands[1], DImode);
689 DONE;
690 })
691
692
693 ;; Negation and one's complement.
694
695 (define_insn "negsi2"
696 [(set (match_operand:SI 0 "register_operand" "=a")
697 (neg:SI (match_operand:SI 1 "register_operand" "r")))]
698 ""
699 "neg\t%0, %1"
700 [(set_attr "type" "arith")
701 (set_attr "mode" "SI")
702 (set_attr "length" "3")])
703
704 (define_insn_and_split "one_cmplsi2"
705 [(set (match_operand:SI 0 "register_operand" "=a")
706 (not:SI (match_operand:SI 1 "register_operand" "r")))]
707 ""
708 "#"
709 "&& can_create_pseudo_p ()"
710 [(set (match_dup 2)
711 (const_int -1))
712 (set (match_dup 0)
713 (xor:SI (match_dup 1)
714 (match_dup 2)))]
715 {
716 operands[2] = gen_reg_rtx (SImode);
717 }
718 [(set_attr "type" "arith")
719 (set_attr "mode" "SI")
720 (set (attr "length")
721 (if_then_else (match_test "TARGET_DENSITY")
722 (const_int 5)
723 (const_int 6)))])
724
725 (define_insn "negsf2"
726 [(set (match_operand:SF 0 "register_operand" "=f")
727 (neg:SF (match_operand:SF 1 "register_operand" "f")))]
728 "TARGET_HARD_FLOAT"
729 "neg.s\t%0, %1"
730 [(set_attr "type" "farith")
731 (set_attr "mode" "SF")
732 (set_attr "length" "3")])
733
734
735 ;; Logical instructions.
736
737 (define_insn "andsi3"
738 [(set (match_operand:SI 0 "register_operand" "=a,a")
739 (and:SI (match_operand:SI 1 "register_operand" "%r,r")
740 (match_operand:SI 2 "mask_operand" "P,r")))]
741 ""
742 "@
743 extui\t%0, %1, 0, %K2
744 and\t%0, %1, %2"
745 [(set_attr "type" "arith,arith")
746 (set_attr "mode" "SI")
747 (set_attr "length" "3,3")])
748
749 (define_insn_and_split "*andsi3_bitcmpl"
750 [(set (match_operand:SI 0 "register_operand" "=a")
751 (and:SI (not:SI (match_operand:SI 1 "register_operand" "r"))
752 (match_operand:SI 2 "register_operand" "r")))]
753 ""
754 "#"
755 "&& can_create_pseudo_p ()"
756 [(set (match_dup 3)
757 (and:SI (match_dup 1)
758 (match_dup 2)))
759 (set (match_dup 0)
760 (xor:SI (match_dup 3)
761 (match_dup 2)))]
762 {
763 operands[3] = gen_reg_rtx (SImode);
764 }
765 [(set_attr "type" "arith")
766 (set_attr "mode" "SI")
767 (set_attr "length" "6")])
768
769 (define_insn_and_split "*andsi3_const_pow2_minus_one"
770 [(set (match_operand:SI 0 "register_operand" "=a")
771 (and:SI (match_operand:SI 1 "register_operand" "r")
772 (match_operand:SI 2 "const_int_operand" "i")))]
773 "IN_RANGE (exact_log2 (INTVAL (operands[2]) + 1), 17, 31)"
774 "#"
775 "&& 1"
776 [(set (match_dup 0)
777 (ashift:SI (match_dup 1)
778 (match_dup 2)))
779 (set (match_dup 0)
780 (lshiftrt:SI (match_dup 0)
781 (match_dup 2)))]
782 {
783 operands[2] = GEN_INT (32 - floor_log2 (INTVAL (operands[2]) + 1));
784 }
785 [(set_attr "type" "arith")
786 (set_attr "mode" "SI")
787 (set (attr "length")
788 (if_then_else (match_test "TARGET_DENSITY
789 && INTVAL (operands[2]) == 0x7FFFFFFF")
790 (const_int 5)
791 (const_int 6)))])
792
793 (define_insn_and_split "*andsi3_const_negative_pow2"
794 [(set (match_operand:SI 0 "register_operand" "=a")
795 (and:SI (match_operand:SI 1 "register_operand" "r")
796 (match_operand:SI 2 "const_int_operand" "i")))]
797 "IN_RANGE (exact_log2 (-INTVAL (operands[2])), 12, 31)"
798 "#"
799 "&& 1"
800 [(set (match_dup 0)
801 (lshiftrt:SI (match_dup 1)
802 (match_dup 2)))
803 (set (match_dup 0)
804 (ashift:SI (match_dup 0)
805 (match_dup 2)))]
806 {
807 operands[2] = GEN_INT (floor_log2 (-INTVAL (operands[2])));
808 }
809 [(set_attr "type" "arith")
810 (set_attr "mode" "SI")
811 (set_attr "length" "6")])
812
813 (define_insn_and_split "*andsi3_const_shifted_mask"
814 [(set (match_operand:SI 0 "register_operand" "=a")
815 (and:SI (match_operand:SI 1 "register_operand" "r")
816 (match_operand:SI 2 "shifted_mask_operand" "i")))]
817 "! xtensa_simm12b (INTVAL (operands[2]))"
818 "#"
819 "&& 1"
820 [(set (match_dup 0)
821 (zero_extract:SI (match_dup 1)
822 (match_dup 3)
823 (match_dup 4)))
824 (set (match_dup 0)
825 (ashift:SI (match_dup 0)
826 (match_dup 2)))]
827 {
828 HOST_WIDE_INT mask = INTVAL (operands[2]);
829 int shift = ctz_hwi (mask);
830 int mask_size = floor_log2 (((uint32_t)mask >> shift) + 1);
831 int mask_pos = shift;
832 if (BITS_BIG_ENDIAN)
833 mask_pos = (32 - (mask_size + shift)) & 0x1f;
834 operands[2] = GEN_INT (shift);
835 operands[3] = GEN_INT (mask_size);
836 operands[4] = GEN_INT (mask_pos);
837 }
838 [(set_attr "type" "arith")
839 (set_attr "mode" "SI")
840 (set (attr "length")
841 (if_then_else (match_test "TARGET_DENSITY
842 && ctz_hwi (INTVAL (operands[2])) == 1")
843 (const_int 5)
844 (const_int 6)))])
845
846 (define_insn "iorsi3"
847 [(set (match_operand:SI 0 "register_operand" "=a")
848 (ior:SI (match_operand:SI 1 "register_operand" "%r")
849 (match_operand:SI 2 "register_operand" "r")))]
850 ""
851 "or\t%0, %1, %2"
852 [(set_attr "type" "arith")
853 (set_attr "mode" "SI")
854 (set_attr "length" "3")])
855
856 (define_expand "xorsi3"
857 [(set (match_operand:SI 0 "register_operand")
858 (xor:SI (match_operand:SI 1 "register_operand")
859 (match_operand:SI 2 "nonmemory_operand")))]
860 ""
861 {
862 if (register_operand (operands[2], SImode))
863 emit_insn (gen_xorsi3_internal (operands[0], operands[1],
864 operands[2]));
865 else
866 {
867 rtx (*gen_op)(rtx, rtx, rtx);
868 if (TARGET_DENSITY
869 && CONST_INT_P (operands[2])
870 && INTVAL (operands[2]) == -2147483648L)
871 gen_op = gen_addsi3;
872 else
873 gen_op = gen_xorsi3_internal;
874 emit_insn (gen_op (operands[0], operands[1],
875 force_reg (SImode, operands[2])));
876 }
877 DONE;
878 })
879
880 (define_insn "xorsi3_internal"
881 [(set (match_operand:SI 0 "register_operand" "=a")
882 (xor:SI (match_operand:SI 1 "register_operand" "%r")
883 (match_operand:SI 2 "register_operand" "r")))]
884 ""
885 "xor\t%0, %1, %2"
886 [(set_attr "type" "arith")
887 (set_attr "mode" "SI")
888 (set_attr "length" "3")])
889
890 (define_insn_and_split "*splice_bits"
891 [(set (match_operand:SI 0 "register_operand" "=a")
892 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "r")
893 (match_operand:SI 3 "const_int_operand" "i"))
894 (and:SI (match_operand:SI 2 "register_operand" "r")
895 (match_operand:SI 4 "const_int_operand" "i"))))]
896
897 "!optimize_debug && optimize
898 && INTVAL (operands[3]) + INTVAL (operands[4]) == -1
899 && (exact_log2 (INTVAL (operands[3]) + 1) > 16
900 || exact_log2 (INTVAL (operands[4]) + 1) > 16)"
901 "#"
902 "&& can_create_pseudo_p ()"
903 [(set (match_dup 5)
904 (ashift:SI (match_dup 1)
905 (match_dup 4)))
906 (set (match_dup 6)
907 (lshiftrt:SI (match_dup 2)
908 (match_dup 3)))
909 (set (match_dup 0)
910 (ior:SI (lshiftrt:SI (match_dup 5)
911 (match_dup 4))
912 (ashift:SI (match_dup 6)
913 (match_dup 3))))]
914 {
915 int shift;
916 if (INTVAL (operands[3]) < 0)
917 {
918 rtx x;
919 x = operands[1], operands[1] = operands[2], operands[2] = x;
920 x = operands[3], operands[3] = operands[4], operands[4] = x;
921 }
922 shift = floor_log2 (INTVAL (operands[3]) + 1);
923 operands[3] = GEN_INT (shift);
924 operands[4] = GEN_INT (32 - shift);
925 operands[5] = gen_reg_rtx (SImode);
926 operands[6] = gen_reg_rtx (SImode);
927 }
928 [(set_attr "type" "arith")
929 (set_attr "mode" "SI")
930 (set (attr "length")
931 (if_then_else (match_test "TARGET_DENSITY
932 && (INTVAL (operands[3]) == 0x7FFFFFFF
933 || INTVAL (operands[4]) == 0x7FFFFFFF)")
934 (const_int 11)
935 (const_int 12)))])
936
937
938 ;; Zero-extend instructions.
939
940 (define_insn "zero_extendhisi2"
941 [(set (match_operand:SI 0 "register_operand" "=a,a")
942 (zero_extend:SI (match_operand:HI 1 "nonimmed_operand" "r,U")))]
943 ""
944 "@
945 extui\t%0, %1, 0, 16
946 %v1l16ui\t%0, %1"
947 [(set_attr "type" "arith,load")
948 (set_attr "mode" "SI")
949 (set_attr "length" "3,3")])
950
951 (define_insn "zero_extendqisi2"
952 [(set (match_operand:SI 0 "register_operand" "=a,a")
953 (zero_extend:SI (match_operand:QI 1 "nonimmed_operand" "r,U")))]
954 ""
955 "@
956 extui\t%0, %1, 0, 8
957 %v1l8ui\t%0, %1"
958 [(set_attr "type" "arith,load")
959 (set_attr "mode" "SI")
960 (set_attr "length" "3,3")])
961
962
963 ;; Sign-extend instructions.
964
965 (define_expand "extendhisi2"
966 [(set (match_operand:SI 0 "register_operand" "")
967 (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
968 ""
969 {
970 if (sext_operand (operands[1], HImode))
971 emit_insn (gen_extendhisi2_internal (operands[0], operands[1]));
972 else
973 xtensa_extend_reg (operands[0], operands[1]);
974 DONE;
975 })
976
977 (define_insn "extendhisi2_internal"
978 [(set (match_operand:SI 0 "register_operand" "=B,a")
979 (sign_extend:SI (match_operand:HI 1 "sext_operand" "r,U")))]
980 ""
981 "@
982 sext\t%0, %1, 15
983 %v1l16si\t%0, %1"
984 [(set_attr "type" "arith,load")
985 (set_attr "mode" "SI")
986 (set_attr "length" "3,3")])
987
988 (define_expand "extendqisi2"
989 [(set (match_operand:SI 0 "register_operand" "")
990 (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
991 ""
992 {
993 if (TARGET_SEXT)
994 emit_insn (gen_extendqisi2_internal (operands[0], operands[1]));
995 else
996 xtensa_extend_reg (operands[0], operands[1]);
997 DONE;
998 })
999
1000 (define_insn "extendqisi2_internal"
1001 [(set (match_operand:SI 0 "register_operand" "=B")
1002 (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
1003 "TARGET_SEXT"
1004 "sext\t%0, %1, 7"
1005 [(set_attr "type" "arith")
1006 (set_attr "mode" "SI")
1007 (set_attr "length" "3")])
1008
1009
1010 ;; Field extract instructions.
1011
1012 (define_expand "extvsi"
1013 [(set (match_operand:SI 0 "register_operand" "")
1014 (sign_extract:SI (match_operand:SI 1 "register_operand" "")
1015 (match_operand:SI 2 "const_int_operand" "")
1016 (match_operand:SI 3 "const_int_operand" "")))]
1017 "TARGET_SEXT"
1018 {
1019 if (!sext_fldsz_operand (operands[2], SImode))
1020 FAIL;
1021
1022 /* We could expand to a right shift followed by SEXT but that's
1023 no better than the standard left and right shift sequence. */
1024 if (!lsbitnum_operand (operands[3], SImode))
1025 FAIL;
1026
1027 emit_insn (gen_extvsi_internal (operands[0], operands[1],
1028 operands[2], operands[3]));
1029 DONE;
1030 })
1031
1032 (define_insn "extvsi_internal"
1033 [(set (match_operand:SI 0 "register_operand" "=a")
1034 (sign_extract:SI (match_operand:SI 1 "register_operand" "r")
1035 (match_operand:SI 2 "sext_fldsz_operand" "i")
1036 (match_operand:SI 3 "lsbitnum_operand" "i")))]
1037 "TARGET_SEXT"
1038 {
1039 int fldsz = INTVAL (operands[2]);
1040 operands[2] = GEN_INT (fldsz - 1);
1041 return "sext\t%0, %1, %2";
1042 }
1043 [(set_attr "type" "arith")
1044 (set_attr "mode" "SI")
1045 (set_attr "length" "3")])
1046
1047 (define_expand "extzvsi"
1048 [(set (match_operand:SI 0 "register_operand" "")
1049 (zero_extract:SI (match_operand:SI 1 "register_operand" "")
1050 (match_operand:SI 2 "const_int_operand" "")
1051 (match_operand:SI 3 "const_int_operand" "")))]
1052 ""
1053 {
1054 if (!extui_fldsz_operand (operands[2], SImode))
1055 FAIL;
1056 emit_insn (gen_extzvsi_internal (operands[0], operands[1],
1057 operands[2], operands[3]));
1058 DONE;
1059 })
1060
1061 (define_insn "extzvsi_internal"
1062 [(set (match_operand:SI 0 "register_operand" "=a")
1063 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
1064 (match_operand:SI 2 "extui_fldsz_operand" "i")
1065 (match_operand:SI 3 "const_int_operand" "i")))]
1066 ""
1067 {
1068 int shift;
1069 if (BITS_BIG_ENDIAN)
1070 shift = (32 - (INTVAL (operands[2]) + INTVAL (operands[3]))) & 0x1f;
1071 else
1072 shift = INTVAL (operands[3]) & 0x1f;
1073 operands[3] = GEN_INT (shift);
1074 return "extui\t%0, %1, %3, %2";
1075 }
1076 [(set_attr "type" "arith")
1077 (set_attr "mode" "SI")
1078 (set_attr "length" "3")])
1079
1080 (define_insn_and_split "*extzvsi-1bit_ashlsi3"
1081 [(set (match_operand:SI 0 "register_operand" "=a")
1082 (and:SI (match_operator:SI 4 "logical_shift_operator"
1083 [(match_operand:SI 1 "register_operand" "r")
1084 (match_operand:SI 2 "const_int_operand" "i")])
1085 (match_operand:SI 3 "const_int_operand" "i")))]
1086 "exact_log2 (INTVAL (operands[3])) > 0"
1087 "#"
1088 "&& 1"
1089 [(set (match_dup 0)
1090 (zero_extract:SI (match_dup 1)
1091 (const_int 1)
1092 (match_dup 2)))
1093 (set (match_dup 0)
1094 (ashift:SI (match_dup 0)
1095 (match_dup 3)))]
1096 {
1097 int pos = INTVAL (operands[2]), shift = floor_log2 (INTVAL (operands[3]));
1098 pos = GET_CODE (operands[4]) == ASHIFT ? shift - pos : shift + pos;
1099 if (BITS_BIG_ENDIAN)
1100 pos = (32 - (1 + pos)) & 0x1f;
1101 operands[2] = GEN_INT (pos);
1102 operands[3] = GEN_INT (shift);
1103 }
1104 [(set_attr "type" "arith")
1105 (set_attr "mode" "SI")
1106 (set (attr "length")
1107 (if_then_else (match_test "TARGET_DENSITY && INTVAL (operands[3]) == 2")
1108 (const_int 5)
1109 (const_int 6)))])
1110
1111 (define_insn_and_split "*extzvsi-1bit_addsubx"
1112 [(set (match_operand:SI 0 "register_operand" "=&a")
1113 (match_operator:SI 5 "addsub_operator"
1114 [(and:SI (match_operator:SI 6 "logical_shift_operator"
1115 [(match_operand:SI 1 "register_operand" "r0")
1116 (match_operand:SI 3 "const_int_operand" "i")])
1117 (match_operand:SI 4 "const_int_operand" "i"))
1118 (match_operand:SI 2 "register_operand" "r")]))]
1119 "TARGET_ADDX
1120 && IN_RANGE (exact_log2 (INTVAL (operands[4])), 1, 3)"
1121 "#"
1122 "&& reload_completed"
1123 [(set (match_dup 0)
1124 (zero_extract:SI (match_dup 1)
1125 (const_int 1)
1126 (match_dup 3)))
1127 (set (match_dup 0)
1128 (match_op_dup 5
1129 [(ashift:SI (match_dup 0)
1130 (match_dup 4))
1131 (match_dup 2)]))]
1132 {
1133 int pos = INTVAL (operands[3]), shift = floor_log2 (INTVAL (operands[4]));
1134 pos = GET_CODE (operands[6]) == ASHIFT ? shift - pos : shift + pos;
1135 if (BITS_BIG_ENDIAN)
1136 pos = (32 - (1 + pos)) & 0x1f;
1137 operands[3] = GEN_INT (pos);
1138 operands[4] = GEN_INT (shift);
1139 }
1140 [(set_attr "type" "arith")
1141 (set_attr "mode" "SI")
1142 (set_attr "length" "6")])
1143
1144
1145 ;; Conversions.
1146
1147 (define_insn "fix<s_fix>_truncsfsi2"
1148 [(set (match_operand:SI 0 "register_operand" "=a")
1149 (any_fix:SI (match_operand:SF 1 "register_operand" "f")))]
1150 "TARGET_HARD_FLOAT"
1151 "<m_fix>.s\t%0, %1, 0"
1152 [(set_attr "type" "fconv")
1153 (set_attr "mode" "SF")
1154 (set_attr "length" "3")])
1155
1156 (define_insn "*fix<s_fix>_truncsfsi2_2x"
1157 [(set (match_operand:SI 0 "register_operand" "=a")
1158 (any_fix:SI (plus:SF (match_operand:SF 1 "register_operand" "f")
1159 (match_dup 1))))]
1160 "TARGET_HARD_FLOAT"
1161 "<m_fix>.s\t%0, %1, 1"
1162 [(set_attr "type" "fconv")
1163 (set_attr "mode" "SF")
1164 (set_attr "length" "3")])
1165
1166 (define_insn "*fix<s_fix>_truncsfsi2_scaled"
1167 [(set (match_operand:SI 0 "register_operand" "=a")
1168 (any_fix:SI (mult:SF (match_operand:SF 1 "register_operand" "f")
1169 (match_operand:SF 2 "fix_scaling_operand" "F"))))]
1170 "TARGET_HARD_FLOAT"
1171 {
1172 static char result[64];
1173 sprintf (result, "<m_fix>.s\t%%0, %%1, %d",
1174 REAL_EXP (CONST_DOUBLE_REAL_VALUE (operands[2])) - 1);
1175 return result;
1176 }
1177 [(set_attr "type" "fconv")
1178 (set_attr "mode" "SF")
1179 (set_attr "length" "3")])
1180
1181 (define_insn "float<s_float>sisf2"
1182 [(set (match_operand:SF 0 "register_operand" "=f")
1183 (any_float:SF (match_operand:SI 1 "register_operand" "a")))]
1184 "TARGET_HARD_FLOAT"
1185 "<m_float>.s\t%0, %1, 0"
1186 [(set_attr "type" "fconv")
1187 (set_attr "mode" "SF")
1188 (set_attr "length" "3")])
1189
1190 (define_insn "*float<s_float>sisf2_scaled"
1191 [(set (match_operand:SF 0 "register_operand" "=f")
1192 (mult:SF (any_float:SF (match_operand:SI 1 "register_operand" "a"))
1193 (match_operand:SF 2 "float_scaling_operand" "F")))]
1194 "TARGET_HARD_FLOAT"
1195 {
1196 static char result[64];
1197 sprintf (result, "<m_float>.s\t%%0, %%1, %d",
1198 1 - REAL_EXP (CONST_DOUBLE_REAL_VALUE (operands[2])));
1199 return result;
1200 }
1201 [(set_attr "type" "fconv")
1202 (set_attr "mode" "SF")
1203 (set_attr "length" "3")])
1204
1205
1206 ;; Data movement instructions.
1207
1208 ;; 64-bit Integer moves
1209
1210 (define_expand "movdi"
1211 [(set (match_operand:DI 0 "nonimmed_operand" "")
1212 (match_operand:DI 1 "general_operand" ""))]
1213 ""
1214 {
1215 if (CONSTANT_P (operands[1]))
1216 {
1217 /* Split in halves if 64-bit Const-to-Reg moves
1218 because of offering further optimization opportunities. */
1219 if (register_operand (operands[0], DImode))
1220 {
1221 rtx ops[4] = { operands[0], operands[1] };
1222 xtensa_split_DI_reg_imm (ops);
1223 emit_move_insn (ops[0], ops[1]);
1224 emit_move_insn (ops[2], ops[3]);
1225 DONE;
1226 }
1227
1228 if (!TARGET_CONST16)
1229 operands[1] = force_const_mem (DImode, operands[1]);
1230 }
1231
1232 if (!register_operand (operands[0], DImode)
1233 && !register_operand (operands[1], DImode))
1234 operands[1] = force_reg (DImode, operands[1]);
1235
1236 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1237 })
1238
1239 (define_insn_and_split "movdi_internal"
1240 [(set (match_operand:DI 0 "nonimmed_operand" "=a,W,a,a,U")
1241 (match_operand:DI 1 "move_operand" "r,i,T,U,r"))]
1242 "register_operand (operands[0], DImode)
1243 || register_operand (operands[1], DImode)"
1244 "#"
1245 "&& reload_completed"
1246 [(set (match_dup 0) (match_dup 2))
1247 (set (match_dup 1) (match_dup 3))]
1248 {
1249 xtensa_split_operand_pair (operands, SImode);
1250 if (reg_overlap_mentioned_p (operands[0], operands[3]))
1251 {
1252 std::swap (operands[0], operands[1]);
1253 std::swap (operands[2], operands[3]);
1254 }
1255 })
1256
1257 (define_split
1258 [(set (match_operand:DI 0 "register_operand")
1259 (match_operand:DI 1 "const_int_operand"))]
1260 "!TARGET_CONST16
1261 && ! xtensa_split1_finished_p ()"
1262 [(set (match_dup 0)
1263 (match_dup 1))
1264 (set (match_dup 2)
1265 (match_dup 3))]
1266 {
1267 xtensa_split_DI_reg_imm (operands);
1268 })
1269
1270 ;; 32-bit Integer moves
1271
1272 (define_expand "movsi"
1273 [(set (match_operand:SI 0 "nonimmed_operand" "")
1274 (match_operand:SI 1 "general_operand" ""))]
1275 ""
1276 {
1277 if (xtensa_emit_move_sequence (operands, SImode))
1278 DONE;
1279 })
1280
1281 (define_insn "movsi_internal"
1282 [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,a,W,a,a,U,*a,*A")
1283 (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,Y,i,T,U,r,*A,*r"))]
1284 "xtensa_valid_move (SImode, operands)"
1285 "@
1286 movi.n\t%0, %x1
1287 mov.n\t%0, %1
1288 mov.n\t%0, %1
1289 %v1l32i.n\t%0, %1
1290 %v0s32i.n\t%1, %0
1291 %v0s32i.n\t%1, %0
1292 mov\t%0, %1
1293 movsp\t%0, %1
1294 movi\t%0, %x1
1295 movi\t%0, %1
1296 const16\t%0, %t1\;const16\t%0, %b1
1297 %v1l32r\t%0, %1
1298 %v1l32i\t%0, %1
1299 %v0s32i\t%1, %0
1300 rsr\t%0, ACCLO
1301 wsr\t%1, ACCLO"
1302 [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,move,load,load,store,rsr,wsr")
1303 (set_attr "mode" "SI")
1304 (set_attr "length" "2,2,2,2,2,2,3,3,3,3,6,3,3,3,3,3")])
1305
1306 (define_split
1307 [(set (match_operand:SHI 0 "register_operand")
1308 (match_operand:SHI 1 "const_int_operand"))]
1309 "!TARGET_CONST16 && !TARGET_AUTO_LITPOOLS
1310 && ! xtensa_split1_finished_p ()
1311 && ! xtensa_simm12b (INTVAL (operands[1]))"
1312 [(set (match_dup 0)
1313 (match_dup 1))]
1314 {
1315 operands[1] = force_const_mem (<MODE>mode, operands[1]);
1316 })
1317
1318 (define_split
1319 [(set (match_operand:SHI 0 "register_operand")
1320 (match_operand:SHI 1 "constantpool_operand"))]
1321 "!optimize_debug && reload_completed"
1322 [(const_int 0)]
1323 {
1324 if (xtensa_constantsynth (operands[0], operands[1]))
1325 DONE;
1326 FAIL;
1327 })
1328
1329 (define_split
1330 [(set (match_operand:SHI 0 "register_operand")
1331 (match_operand:SHI 1 "const_int_operand"))]
1332 "!optimize_debug && reload_completed
1333 && !TARGET_CONST16 && TARGET_AUTO_LITPOOLS
1334 && ! xtensa_simm12b (INTVAL (operands[1]))"
1335 [(const_int 0)]
1336 {
1337 if (xtensa_constantsynth (operands[0], operands[1]))
1338 DONE;
1339 FAIL;
1340 })
1341
1342 ;; 16-bit Integer moves
1343
1344 (define_expand "movhi"
1345 [(set (match_operand:HI 0 "nonimmed_operand" "")
1346 (match_operand:HI 1 "general_operand" ""))]
1347 ""
1348 {
1349 if (xtensa_emit_move_sequence (operands, HImode))
1350 DONE;
1351 })
1352
1353 (define_insn "movhi_internal"
1354 [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,a,a,U,*a,*A")
1355 (match_operand:HI 1 "move_operand" "M,d,r,I,Y,T,U,r,*A,*r"))]
1356 "xtensa_valid_move (HImode, operands)"
1357 "@
1358 movi.n\t%0, %x1
1359 mov.n\t%0, %1
1360 mov\t%0, %1
1361 movi\t%0, %x1
1362 movi\t%0, %1
1363 %v1l32r\t%0, %1
1364 %v1l16ui\t%0, %1
1365 %v0s16i\t%1, %0
1366 rsr\t%0, ACCLO
1367 wsr\t%1, ACCLO"
1368 [(set_attr "type" "move,move,move,move,move,load,load,store,rsr,wsr")
1369 (set_attr "mode" "HI")
1370 (set_attr "length" "2,2,3,3,3,3,3,3,3,3")])
1371
1372 ;; 8-bit Integer moves
1373
1374 (define_expand "movqi"
1375 [(set (match_operand:QI 0 "nonimmed_operand" "")
1376 (match_operand:QI 1 "general_operand" ""))]
1377 ""
1378 {
1379 if (xtensa_emit_move_sequence (operands, QImode))
1380 DONE;
1381 })
1382
1383 (define_insn "movqi_internal"
1384 [(set (match_operand:QI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
1385 (match_operand:QI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
1386 "xtensa_valid_move (QImode, operands)"
1387 "@
1388 movi.n\t%0, %x1
1389 mov.n\t%0, %1
1390 mov\t%0, %1
1391 movi\t%0, %x1
1392 %v1l8ui\t%0, %1
1393 %v0s8i\t%1, %0
1394 rsr\t%0, ACCLO
1395 wsr\t%1, ACCLO"
1396 [(set_attr "type" "move,move,move,move,load,store,rsr,wsr")
1397 (set_attr "mode" "QI")
1398 (set_attr "length" "2,2,3,3,3,3,3,3")])
1399
1400 ;; Sub-word reloads from the constant pool.
1401
1402 (define_expand "reload<mode>_literal"
1403 [(parallel [(match_operand:HQI 0 "register_operand" "=r")
1404 (match_operand:HQI 1 "constantpool_operand" "")
1405 (match_operand:SI 2 "register_operand" "=&r")])]
1406 ""
1407 {
1408 rtx lit, scratch;
1409 unsigned word_off, byte_off;
1410
1411 if (MEM_P (operands[1]))
1412 {
1413 lit = operands[1];
1414 word_off = 0;
1415 byte_off = 0;
1416 }
1417 else
1418 {
1419 gcc_assert (SUBREG_P (operands[1]));
1420 lit = SUBREG_REG (operands[1]);
1421 word_off = SUBREG_BYTE (operands[1]) & ~(UNITS_PER_WORD - 1);
1422 byte_off = SUBREG_BYTE (operands[1]) - word_off;
1423 }
1424
1425 lit = adjust_address (lit, SImode, word_off);
1426 scratch = operands[2];
1427 emit_insn (gen_movsi (scratch, lit));
1428 emit_insn (gen_mov<mode> (operands[0],
1429 gen_rtx_SUBREG (<MODE>mode, scratch, byte_off)));
1430
1431 DONE;
1432 })
1433
1434 ;; 32-bit floating point moves
1435
1436 (define_expand "movsf"
1437 [(set (match_operand:SF 0 "nonimmed_operand" "")
1438 (match_operand:SF 1 "general_operand" ""))]
1439 ""
1440 {
1441 if (!TARGET_CONST16 && !TARGET_AUTO_LITPOOLS && CONSTANT_P (operands[1]))
1442 operands[1] = force_const_mem (SFmode, operands[1]);
1443
1444 if ((!register_operand (operands[0], SFmode)
1445 && !register_operand (operands[1], SFmode))
1446 || (FP_REG_P (xt_true_regnum (operands[0]))
1447 && can_create_pseudo_p ()
1448 && (constantpool_mem_p (operands[1])
1449 || CONSTANT_P (operands[1]))))
1450 operands[1] = force_reg (SFmode, operands[1]);
1451
1452 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1453 })
1454
1455 (define_insn "movsf_internal"
1456 [(set (match_operand:SF 0 "nonimmed_operand" "=f,f,^U,D,a,D,R,a,f,a,a,W,a,U")
1457 (match_operand:SF 1 "move_operand" "f,^U,f,d,T,R,d,r,r,f,Y,iF,U,r"))]
1458 "((register_operand (operands[0], SFmode)
1459 || register_operand (operands[1], SFmode))
1460 && !(FP_REG_P (xt_true_regnum (operands[0]))
1461 && (constantpool_mem_p (operands[1]) || CONSTANT_P (operands[1]))))"
1462 "@
1463 mov.s\t%0, %1
1464 %v1lsi\t%0, %1
1465 %v0ssi\t%1, %0
1466 mov.n\t%0, %1
1467 %v1l32r\t%0, %1
1468 %v1l32i.n\t%0, %1
1469 %v0s32i.n\t%1, %0
1470 mov\t%0, %1
1471 wfr\t%0, %1
1472 rfr\t%0, %1
1473 movi\t%0, %y1
1474 const16\t%0, %t1\;const16\t%0, %b1
1475 %v1l32i\t%0, %1
1476 %v0s32i\t%1, %0"
1477 [(set_attr "type" "farith,fload,fstore,move,load,load,store,move,farith,farith,move,move,load,store")
1478 (set_attr "mode" "SF")
1479 (set_attr "length" "3,3,3,2,3,2,2,3,3,3,3,6,3,3")])
1480
1481 (define_insn "*lsiu"
1482 [(set (match_operand:SF 0 "register_operand" "=f")
1483 (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "+a")
1484 (match_operand:SI 2 "fpmem_offset_operand" "i"))))
1485 (set (match_dup 1)
1486 (plus:SI (match_dup 1) (match_dup 2)))]
1487 "TARGET_HARD_FLOAT && !TARGET_HARD_FLOAT_POSTINC"
1488 {
1489 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
1490 output_asm_insn ("memw", operands);
1491 return "lsiu\t%0, %1, %2";
1492 }
1493 [(set_attr "type" "fload")
1494 (set_attr "mode" "SF")
1495 (set_attr "length" "3")])
1496
1497 (define_insn "*ssiu"
1498 [(set (mem:SF (plus:SI (match_operand:SI 0 "register_operand" "+a")
1499 (match_operand:SI 1 "fpmem_offset_operand" "i")))
1500 (match_operand:SF 2 "register_operand" "f"))
1501 (set (match_dup 0)
1502 (plus:SI (match_dup 0) (match_dup 1)))]
1503 "TARGET_HARD_FLOAT && !TARGET_HARD_FLOAT_POSTINC"
1504 {
1505 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
1506 output_asm_insn ("memw", operands);
1507 return "ssiu\t%2, %0, %1";
1508 }
1509 [(set_attr "type" "fstore")
1510 (set_attr "mode" "SF")
1511 (set_attr "length" "3")])
1512
1513 (define_insn "*lsip"
1514 [(set (match_operand:SF 0 "register_operand" "=f")
1515 (mem:SF (match_operand:SI 1 "register_operand" "+a")))
1516 (set (match_dup 1)
1517 (plus:SI (match_dup 1)
1518 (match_operand:SI 2 "fpmem_offset_operand" "i")))]
1519 "TARGET_HARD_FLOAT && TARGET_HARD_FLOAT_POSTINC"
1520 {
1521 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
1522 output_asm_insn ("memw", operands);
1523 return "lsip\t%0, %1, %2";
1524 }
1525 [(set_attr "type" "fload")
1526 (set_attr "mode" "SF")
1527 (set_attr "length" "3")])
1528
1529 (define_insn "*ssip"
1530 [(set (mem:SF (match_operand:SI 0 "register_operand" "+a"))
1531 (match_operand:SF 1 "register_operand" "f"))
1532 (set (match_dup 0)
1533 (plus:SI (match_dup 0)
1534 (match_operand:SI 2 "fpmem_offset_operand" "i")))]
1535 "TARGET_HARD_FLOAT && TARGET_HARD_FLOAT_POSTINC"
1536 {
1537 if (TARGET_SERIALIZE_VOLATILE && volatile_refs_p (PATTERN (insn)))
1538 output_asm_insn ("memw", operands);
1539 return "ssip\t%1, %0, %2";
1540 }
1541 [(set_attr "type" "fstore")
1542 (set_attr "mode" "SF")
1543 (set_attr "length" "3")])
1544
1545 (define_split
1546 [(set (match_operand:SF 0 "register_operand")
1547 (match_operand 1 "constantpool_operand"))]
1548 "!optimize_debug && reload_completed"
1549 [(const_int 0)]
1550 {
1551 if (xtensa_constantsynth (operands[0], operands[1]))
1552 DONE;
1553 FAIL;
1554 })
1555
1556 (define_split
1557 [(set (match_operand:SF 0 "register_operand")
1558 (match_operand 1 "const_double_operand"))]
1559 "!optimize_debug && reload_completed
1560 && !TARGET_CONST16 && TARGET_AUTO_LITPOOLS"
1561 [(const_int 0)]
1562 {
1563 if (xtensa_constantsynth (operands[0], operands[1]))
1564 DONE;
1565 FAIL;
1566 })
1567
1568 ;; 64-bit floating point moves
1569
1570 (define_expand "movdf"
1571 [(set (match_operand:DF 0 "nonimmed_operand" "")
1572 (match_operand:DF 1 "general_operand" ""))]
1573 ""
1574 {
1575 if (CONSTANT_P (operands[1]) && !TARGET_CONST16 && !TARGET_AUTO_LITPOOLS)
1576 operands[1] = force_const_mem (DFmode, operands[1]);
1577
1578 if (!register_operand (operands[0], DFmode)
1579 && !register_operand (operands[1], DFmode))
1580 operands[1] = force_reg (DFmode, operands[1]);
1581
1582 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1583 })
1584
1585 (define_insn_and_split "movdf_internal"
1586 [(set (match_operand:DF 0 "nonimmed_operand" "=a,a,W,a,a,U")
1587 (match_operand:DF 1 "move_operand" "r,Y,iF,T,U,r"))]
1588 "register_operand (operands[0], DFmode)
1589 || register_operand (operands[1], DFmode)"
1590 "#"
1591 "&& reload_completed"
1592 [(set (match_dup 0) (match_dup 2))
1593 (set (match_dup 1) (match_dup 3))]
1594 {
1595 xtensa_split_operand_pair (operands, SFmode);
1596 if (reg_overlap_mentioned_p (operands[0], operands[3]))
1597 {
1598 std::swap (operands[0], operands[1]);
1599 std::swap (operands[2], operands[3]);
1600 }
1601 })
1602
1603 ;; Block moves
1604
1605 (define_expand "cpymemsi"
1606 [(parallel [(set (match_operand:BLK 0 "" "")
1607 (match_operand:BLK 1 "" ""))
1608 (use (match_operand:SI 2 "arith_operand" ""))
1609 (use (match_operand:SI 3 "const_int_operand" ""))])]
1610 ""
1611 {
1612 if (!xtensa_expand_block_move (operands))
1613 FAIL;
1614 DONE;
1615 })
1616
1617 ;; Block sets
1618
1619 (define_expand "setmemsi"
1620 [(match_operand:BLK 0 "memory_operand")
1621 (match_operand:SI 1 "")
1622 (match_operand:SI 2 "")
1623 (match_operand:SI 3 "const_int_operand")]
1624 "!optimize_debug && optimize"
1625 {
1626 if (xtensa_expand_block_set (operands))
1627 DONE;
1628 FAIL;
1629 })
1630
1631
1632 ;; Shift instructions.
1633
1634 (define_expand "ashlsi3"
1635 [(set (match_operand:SI 0 "register_operand" "")
1636 (ashift:SI (match_operand:SI 1 "register_operand" "")
1637 (match_operand:SI 2 "arith_operand" "")))]
1638 ""
1639 {
1640 operands[1] = xtensa_copy_incoming_a7 (operands[1]);
1641 })
1642
1643 (define_insn "ashlsi3_internal"
1644 [(set (match_operand:SI 0 "register_operand" "=a,a")
1645 (ashift:SI (match_operand:SI 1 "register_operand" "r,r")
1646 (match_operand:SI 2 "arith_operand" "J,r")))]
1647 ""
1648 "@
1649 slli\t%0, %1, %R2
1650 ssl\t%2\;sll\t%0, %1"
1651 [(set_attr "type" "arith,arith")
1652 (set_attr "mode" "SI")
1653 (set_attr "length" "3,6")])
1654
1655 (define_split
1656 [(set (match_operand:SI 0 "register_operand")
1657 (ashift:SI (match_operand:SI 1 "register_operand")
1658 (const_int 1)))]
1659 "TARGET_DENSITY"
1660 [(set (match_dup 0)
1661 (plus:SI (match_dup 1)
1662 (match_dup 1)))])
1663
1664 (define_insn "ashrsi3"
1665 [(set (match_operand:SI 0 "register_operand" "=a,a")
1666 (ashiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1667 (match_operand:SI 2 "arith_operand" "J,r")))]
1668 ""
1669 "@
1670 srai\t%0, %1, %R2
1671 ssr\t%2\;sra\t%0, %1"
1672 [(set_attr "type" "arith,arith")
1673 (set_attr "mode" "SI")
1674 (set_attr "length" "3,6")])
1675
1676 (define_insn "lshrsi3"
1677 [(set (match_operand:SI 0 "register_operand" "=a,a")
1678 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
1679 (match_operand:SI 2 "arith_operand" "J,r")))]
1680 ""
1681 {
1682 if (which_alternative == 0)
1683 {
1684 if ((INTVAL (operands[2]) & 0x1f) < 16)
1685 return "srli\t%0, %1, %R2";
1686 else
1687 return "extui\t%0, %1, %R2, %L2";
1688 }
1689 return "ssr\t%2\;srl\t%0, %1";
1690 }
1691 [(set_attr "type" "arith,arith")
1692 (set_attr "mode" "SI")
1693 (set_attr "length" "3,6")])
1694
1695 (define_insn "*shift_per_byte"
1696 [(set (match_operand:SI 0 "register_operand" "=a")
1697 (match_operator:SI 3 "xtensa_shift_per_byte_operator"
1698 [(match_operand:SI 1 "register_operand" "r")
1699 (ashift:SI (match_operand:SI 2 "register_operand" "r")
1700 (const_int 3))]))]
1701 "!optimize_debug && optimize"
1702 {
1703 switch (GET_CODE (operands[3]))
1704 {
1705 case ASHIFT: return "ssa8b\t%2\;sll\t%0, %1";
1706 case ASHIFTRT: return "ssa8l\t%2\;sra\t%0, %1";
1707 case LSHIFTRT: return "ssa8l\t%2\;srl\t%0, %1";
1708 default: gcc_unreachable ();
1709 }
1710 }
1711 [(set_attr "type" "arith")
1712 (set_attr "mode" "SI")
1713 (set_attr "length" "6")])
1714
1715 (define_insn_and_split "*shift_per_byte_omit_AND_0"
1716 [(set (match_operand:SI 0 "register_operand" "=a")
1717 (match_operator:SI 4 "xtensa_shift_per_byte_operator"
1718 [(match_operand:SI 1 "register_operand" "r")
1719 (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1720 (const_int 3))
1721 (match_operand:SI 3 "const_int_operand" "i"))]))]
1722 "!optimize_debug && optimize
1723 && (INTVAL (operands[3]) & 0x1f) == 3 << 3"
1724 "#"
1725 "&& 1"
1726 [(set (match_dup 0)
1727 (match_op_dup 4
1728 [(match_dup 1)
1729 (ashift:SI (match_dup 2)
1730 (const_int 3))]))]
1731 ""
1732 [(set_attr "type" "arith")
1733 (set_attr "mode" "SI")
1734 (set_attr "length" "6")])
1735
1736 (define_insn_and_split "*shift_per_byte_omit_AND_1"
1737 [(set (match_operand:SI 0 "register_operand" "=a")
1738 (match_operator:SI 4 "xtensa_shift_per_byte_operator"
1739 [(match_operand:SI 1 "register_operand" "r")
1740 (neg:SI (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1741 (const_int 3))
1742 (match_operand:SI 3 "const_int_operand" "i")))]))]
1743 "!optimize_debug && optimize
1744 && (INTVAL (operands[3]) & 0x1f) == 3 << 3"
1745 "#"
1746 "&& can_create_pseudo_p ()"
1747 [(set (match_dup 5)
1748 (neg:SI (match_dup 2)))
1749 (set (match_dup 0)
1750 (match_op_dup 4
1751 [(match_dup 1)
1752 (ashift:SI (match_dup 5)
1753 (const_int 3))]))]
1754 {
1755 operands[5] = gen_reg_rtx (SImode);
1756 }
1757 [(set_attr "type" "arith")
1758 (set_attr "mode" "SI")
1759 (set_attr "length" "9")])
1760
1761 (define_insn "*shlrd_reg"
1762 [(set (match_operand:SI 0 "register_operand" "=a")
1763 (match_operator:SI 6 "xtensa_bit_join_operator"
1764 [(match_operator:SI 4 "logical_shift_operator"
1765 [(match_operand:SI 1 "register_operand" "r")
1766 (match_operand:SI 3 "register_operand" "r")])
1767 (match_operator:SI 5 "logical_shift_operator"
1768 [(match_operand:SI 2 "register_operand" "r")
1769 (neg:SI (match_dup 3))])]))]
1770 "!optimize_debug && optimize
1771 && xtensa_shlrd_which_direction (operands[4], operands[5]) != UNKNOWN"
1772 {
1773 switch (xtensa_shlrd_which_direction (operands[4], operands[5]))
1774 {
1775 case ASHIFT: return "ssl\t%3\;src\t%0, %1, %2";
1776 case LSHIFTRT: return "ssr\t%3\;src\t%0, %2, %1";
1777 default: gcc_unreachable ();
1778 }
1779 }
1780 [(set_attr "type" "arith")
1781 (set_attr "mode" "SI")
1782 (set_attr "length" "6")])
1783
1784 (define_insn_and_split "*shlrd_reg"
1785 [(set (match_operand:SI 0 "register_operand" "=a")
1786 (match_operator:SI 6 "xtensa_bit_join_operator"
1787 [(match_operator:SI 4 "logical_shift_operator"
1788 [(match_operand:SI 1 "register_operand" "r")
1789 (neg:SI (match_operand:SI 3 "register_operand" "r"))])
1790 (match_operator:SI 5 "logical_shift_operator"
1791 [(match_operand:SI 2 "register_operand" "r")
1792 (match_dup 3)])]))]
1793 "!optimize_debug && optimize
1794 && xtensa_shlrd_which_direction (operands[5], operands[4]) != UNKNOWN"
1795 "#"
1796 "&& 1"
1797 [(set (match_dup 0)
1798 (match_op_dup 6
1799 [(match_op_dup 5
1800 [(match_dup 2)
1801 (match_dup 3)])
1802 (match_op_dup 4
1803 [(match_dup 1)
1804 (neg:SI (match_dup 3))])]))]
1805 ""
1806 [(set_attr "type" "arith")
1807 (set_attr "mode" "SI")
1808 (set_attr "length" "6")])
1809
1810
1811 (define_insn "*shlrd_const"
1812 [(set (match_operand:SI 0 "register_operand" "=a")
1813 (match_operator:SI 7 "xtensa_bit_join_operator"
1814 [(match_operator:SI 5 "logical_shift_operator"
1815 [(match_operand:SI 1 "register_operand" "r")
1816 (match_operand:SI 3 "const_int_operand" "i")])
1817 (match_operator:SI 6 "logical_shift_operator"
1818 [(match_operand:SI 2 "register_operand" "r")
1819 (match_operand:SI 4 "const_int_operand" "i")])]))]
1820 "!optimize_debug && optimize
1821 && xtensa_shlrd_which_direction (operands[5], operands[6]) != UNKNOWN
1822 && IN_RANGE (INTVAL (operands[3]), 1, 31)
1823 && IN_RANGE (INTVAL (operands[4]), 1, 31)
1824 && INTVAL (operands[3]) + INTVAL (operands[4]) == 32"
1825 {
1826 switch (xtensa_shlrd_which_direction (operands[5], operands[6]))
1827 {
1828 case ASHIFT: return "ssai\t%L3\;src\t%0, %1, %2";
1829 case LSHIFTRT: return "ssai\t%R3\;src\t%0, %2, %1";
1830 default: gcc_unreachable ();
1831 }
1832 }
1833 [(set_attr "type" "arith")
1834 (set_attr "mode" "SI")
1835 (set_attr "length" "6")])
1836
1837 (define_insn "*shlrd_per_byte"
1838 [(set (match_operand:SI 0 "register_operand" "=a")
1839 (match_operator:SI 6 "xtensa_bit_join_operator"
1840 [(match_operator:SI 4 "logical_shift_operator"
1841 [(match_operand:SI 1 "register_operand" "r")
1842 (ashift:SI (match_operand:SI 2 "register_operand" "r")
1843 (const_int 3))])
1844 (match_operator:SI 5 "logical_shift_operator"
1845 [(match_operand:SI 3 "register_operand" "r")
1846 (neg:SI (ashift:SI (match_dup 2)
1847 (const_int 3)))])]))]
1848 "!optimize_debug && optimize
1849 && xtensa_shlrd_which_direction (operands[4], operands[5]) != UNKNOWN"
1850 {
1851 switch (xtensa_shlrd_which_direction (operands[4], operands[5]))
1852 {
1853 case ASHIFT: return "ssa8b\t%2\;src\t%0, %1, %3";
1854 case LSHIFTRT: return "ssa8l\t%2\;src\t%0, %3, %1";
1855 default: gcc_unreachable ();
1856 }
1857 }
1858 [(set_attr "type" "arith")
1859 (set_attr "mode" "SI")
1860 (set_attr "length" "6")])
1861
1862 (define_insn_and_split "*shlrd_per_byte_omit_AND"
1863 [(set (match_operand:SI 0 "register_operand" "=a")
1864 (match_operator:SI 7 "xtensa_bit_join_operator"
1865 [(match_operator:SI 5 "logical_shift_operator"
1866 [(match_operand:SI 1 "register_operand" "r")
1867 (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1868 (const_int 3))
1869 (match_operand:SI 4 "const_int_operand" "i"))])
1870 (match_operator:SI 6 "logical_shift_operator"
1871 [(match_operand:SI 3 "register_operand" "r")
1872 (neg:SI (and:SI (ashift:SI (match_dup 2)
1873 (const_int 3))
1874 (match_dup 4)))])]))]
1875 "!optimize_debug && optimize
1876 && xtensa_shlrd_which_direction (operands[5], operands[6]) != UNKNOWN
1877 && (INTVAL (operands[4]) & 0x1f) == 3 << 3"
1878 "#"
1879 "&& 1"
1880 [(set (match_dup 0)
1881 (match_op_dup 7
1882 [(match_op_dup 5
1883 [(match_dup 1)
1884 (ashift:SI (match_dup 2)
1885 (const_int 3))])
1886 (match_op_dup 6
1887 [(match_dup 3)
1888 (neg:SI (ashift:SI (match_dup 2)
1889 (const_int 3)))])]))]
1890 ""
1891 [(set_attr "type" "arith")
1892 (set_attr "mode" "SI")
1893 (set_attr "length" "6")])
1894
1895 (define_insn "rotlsi3"
1896 [(set (match_operand:SI 0 "register_operand" "=a,a")
1897 (rotate:SI (match_operand:SI 1 "register_operand" "r,r")
1898 (match_operand:SI 2 "arith_operand" "J,r")))]
1899 ""
1900 "@
1901 ssai\t%L2\;src\t%0, %1, %1
1902 ssl\t%2\;src\t%0, %1, %1"
1903 [(set_attr "type" "multi,multi")
1904 (set_attr "mode" "SI")
1905 (set_attr "length" "6,6")])
1906
1907 (define_insn "rotrsi3"
1908 [(set (match_operand:SI 0 "register_operand" "=a,a")
1909 (rotatert:SI (match_operand:SI 1 "register_operand" "r,r")
1910 (match_operand:SI 2 "arith_operand" "J,r")))]
1911 ""
1912 "@
1913 ssai\t%R2\;src\t%0, %1, %1
1914 ssr\t%2\;src\t%0, %1, %1"
1915 [(set_attr "type" "multi,multi")
1916 (set_attr "mode" "SI")
1917 (set_attr "length" "6,6")])
1918
1919
1920 ;; Comparisons.
1921
1922 ;; Conditional branches.
1923
1924 (define_expand "cbranchsi4"
1925 [(match_operator 0 "comparison_operator"
1926 [(match_operand:SI 1 "register_operand")
1927 (match_operand:SI 2 "nonmemory_operand")])
1928 (match_operand 3 "")]
1929 ""
1930 {
1931 xtensa_expand_conditional_branch (operands, SImode);
1932 DONE;
1933 })
1934
1935 (define_expand "cbranchsf4"
1936 [(match_operator 0 "comparison_operator"
1937 [(match_operand:SF 1 "register_operand")
1938 (match_operand:SF 2 "register_operand")])
1939 (match_operand 3 "")]
1940 "TARGET_HARD_FLOAT"
1941 {
1942 xtensa_expand_conditional_branch (operands, SFmode);
1943 DONE;
1944 })
1945
1946 ;; Branch patterns for standard integer comparisons
1947
1948 (define_insn "*btrue"
1949 [(set (pc)
1950 (if_then_else (match_operator 3 "branch_operator"
1951 [(match_operand:SI 0 "register_operand" "r,r")
1952 (match_operand:SI 1 "branch_operand" "K,?r")])
1953 (label_ref (match_operand 2 "" ""))
1954 (pc)))]
1955 ""
1956 {
1957 return xtensa_emit_branch (which_alternative == 0, operands);
1958 }
1959 [(set_attr "type" "jump,jump")
1960 (set_attr "mode" "none")
1961 (set (attr "length")
1962 (if_then_else (match_test "TARGET_DENSITY
1963 && CONST_INT_P (operands[1])
1964 && INTVAL (operands[1]) == 0
1965 && (GET_CODE (operands[3]) == EQ
1966 || GET_CODE (operands[3]) == NE)")
1967 (const_int 2)
1968 (const_int 3)))])
1969
1970 (define_insn_and_split "*btrue_INT_MIN"
1971 [(set (pc)
1972 (if_then_else (match_operator 2 "boolean_operator"
1973 [(match_operand:SI 0 "register_operand" "r")
1974 (const_int -2147483648)])
1975 (label_ref (match_operand 1 ""))
1976 (pc)))]
1977 "TARGET_ABS"
1978 "#"
1979 "&& can_create_pseudo_p ()"
1980 [(set (match_dup 3)
1981 (abs:SI (match_dup 0)))
1982 (set (pc)
1983 (if_then_else (match_op_dup 2
1984 [(zero_extract:SI (match_dup 3)
1985 (const_int 1)
1986 (match_dup 4))
1987 (const_int 0)])
1988 (label_ref (match_dup 1))
1989 (pc)))]
1990 {
1991 operands[3] = gen_reg_rtx (SImode);
1992 operands[4] = GEN_INT (BITS_BIG_ENDIAN ? 0 : 31);
1993 operands[2] = gen_rtx_fmt_ee (reverse_condition (GET_CODE (operands[2])),
1994 VOIDmode, XEXP (operands[2], 0),
1995 const0_rtx);
1996 }
1997 [(set_attr "type" "jump")
1998 (set_attr "mode" "none")
1999 (set_attr "length" "6")])
2000
2001 (define_insn "*ubtrue"
2002 [(set (pc)
2003 (if_then_else (match_operator 3 "ubranch_operator"
2004 [(match_operand:SI 0 "register_operand" "r,r")
2005 (match_operand:SI 1 "ubranch_operand" "L,r")])
2006 (label_ref (match_operand 2 "" ""))
2007 (pc)))]
2008 ""
2009 {
2010 return xtensa_emit_branch (which_alternative == 0, operands);
2011 }
2012 [(set_attr "type" "jump,jump")
2013 (set_attr "mode" "none")
2014 (set_attr "length" "3,3")])
2015
2016 ;; Branch patterns for bit testing
2017
2018 (define_insn "*bittrue"
2019 [(set (pc)
2020 (if_then_else (match_operator 3 "boolean_operator"
2021 [(zero_extract:SI (match_operand:SI 0 "register_operand" "r,r")
2022 (const_int 1)
2023 (match_operand:SI 1 "arith_operand" "J,r"))
2024 (const_int 0)])
2025 (label_ref (match_operand 2 "" ""))
2026 (pc)))]
2027 ""
2028 {
2029 static char result[64];
2030 char op;
2031 switch (GET_CODE (operands[3]))
2032 {
2033 case EQ: op = 'c'; break;
2034 case NE: op = 's'; break;
2035 default: gcc_unreachable ();
2036 }
2037 if (which_alternative == 0)
2038 {
2039 operands[1] = GEN_INT (INTVAL (operands[1]) & 0x1f);
2040 sprintf (result, "bb%ci\t%%0, %%d1, %%2", op);
2041 }
2042 else
2043 sprintf (result, "bb%c\t%%0, %%1, %%2", op);
2044 return result;
2045 }
2046 [(set_attr "type" "jump")
2047 (set_attr "mode" "none")
2048 (set_attr "length" "3")])
2049
2050 (define_insn "*masktrue"
2051 [(set (pc)
2052 (if_then_else (match_operator 3 "boolean_operator"
2053 [(and:SI (match_operand:SI 0 "register_operand" "r")
2054 (match_operand:SI 1 "register_operand" "r"))
2055 (const_int 0)])
2056 (label_ref (match_operand 2 "" ""))
2057 (pc)))]
2058 ""
2059 {
2060 switch (GET_CODE (operands[3]))
2061 {
2062 case EQ: return "bnone\t%0, %1, %2";
2063 case NE: return "bany\t%0, %1, %2";
2064 default: gcc_unreachable ();
2065 }
2066 }
2067 [(set_attr "type" "jump")
2068 (set_attr "mode" "none")
2069 (set_attr "length" "3")])
2070
2071 (define_insn "*masktrue_bitcmpl"
2072 [(set (pc)
2073 (if_then_else (match_operator 3 "boolean_operator"
2074 [(and:SI (not:SI (match_operand:SI 0 "register_operand" "r"))
2075 (match_operand:SI 1 "register_operand" "r"))
2076 (const_int 0)])
2077 (label_ref (match_operand 2 "" ""))
2078 (pc)))]
2079 ""
2080 {
2081 switch (GET_CODE (operands[3]))
2082 {
2083 case EQ: return "ball\t%0, %1, %2";
2084 case NE: return "bnall\t%0, %1, %2";
2085 default: gcc_unreachable ();
2086 }
2087 }
2088 [(set_attr "type" "jump")
2089 (set_attr "mode" "none")
2090 (set_attr "length" "3")])
2091
2092 (define_insn_and_split "*masktrue_const_bitcmpl"
2093 [(set (pc)
2094 (if_then_else (match_operator 3 "boolean_operator"
2095 [(and:SI (not:SI (match_operand:SI 0 "register_operand" "r"))
2096 (match_operand:SI 1 "const_int_operand" "i"))
2097 (const_int 0)])
2098 (label_ref (match_operand 2 "" ""))
2099 (pc)))]
2100 "exact_log2 (INTVAL (operands[1])) < 0"
2101 "#"
2102 "&& can_create_pseudo_p ()"
2103 [(set (match_dup 4)
2104 (match_dup 1))
2105 (set (pc)
2106 (if_then_else (match_op_dup 3
2107 [(and:SI (not:SI (match_dup 0))
2108 (match_dup 4))
2109 (const_int 0)])
2110 (label_ref (match_dup 2))
2111 (pc)))]
2112 {
2113 operands[4] = gen_reg_rtx (SImode);
2114 }
2115 [(set_attr "type" "jump")
2116 (set_attr "mode" "none")
2117 (set (attr "length")
2118 (if_then_else (match_test "TARGET_DENSITY
2119 && IN_RANGE (INTVAL (operands[1]), -32, 95)")
2120 (const_int 5)
2121 (if_then_else (match_test "xtensa_simm12b (INTVAL (operands[1]))")
2122 (const_int 6)
2123 (const_int 10))))])
2124
2125 (define_split
2126 [(set (pc)
2127 (if_then_else (match_operator 2 "boolean_operator"
2128 [(match_operator 3 "subreg_HQI_lowpart_operator"
2129 [(not:SI (match_operand:SI 0 "register_operand"))])
2130 (const_int 0)])
2131 (label_ref (match_operand 1 ""))
2132 (pc)))]
2133 ""
2134 [(set (pc)
2135 (if_then_else (match_op_dup 2
2136 [(and:SI (not:SI (match_dup 0))
2137 (match_dup 3))
2138 (const_int 0)])
2139 (label_ref (match_dup 1))
2140 (pc)))]
2141 {
2142 operands[3] = GEN_INT ((1 << GET_MODE_BITSIZE (GET_MODE (operands[3]))) - 1);
2143 })
2144
2145 (define_insn_and_split "*masktrue_const_pow2_minus_one"
2146 [(set (pc)
2147 (if_then_else (match_operator 4 "boolean_operator"
2148 [(and:SI (match_operand:SI 0 "register_operand" "r")
2149 (match_operand:SI 1 "const_int_operand" "i"))
2150 (match_operand:SI 2 "const_int_operand" "i")])
2151 (label_ref (match_operand 3 "" ""))
2152 (pc)))]
2153 "IN_RANGE (exact_log2 (INTVAL (operands[1]) + 1), 17, 31)
2154 /* && (~INTVAL (operands[1]) & INTVAL (operands[2])) == 0 // can be omitted */
2155 && xtensa_b4const_or_zero (INTVAL (operands[2]) << (32 - floor_log2 (INTVAL (operands[1]) + 1)))"
2156 "#"
2157 "&& can_create_pseudo_p ()"
2158 [(set (match_dup 5)
2159 (ashift:SI (match_dup 0)
2160 (match_dup 1)))
2161 (set (pc)
2162 (if_then_else (match_op_dup 4
2163 [(match_dup 5)
2164 (match_dup 2)])
2165 (label_ref (match_dup 3))
2166 (pc)))]
2167 {
2168 int shift = 32 - floor_log2 (INTVAL (operands[1]) + 1);
2169 operands[1] = GEN_INT (shift);
2170 operands[2] = GEN_INT (INTVAL (operands[2]) << shift);
2171 operands[5] = gen_reg_rtx (SImode);
2172 }
2173 [(set_attr "type" "jump")
2174 (set_attr "mode" "none")
2175 (set (attr "length")
2176 (if_then_else (match_test "(TARGET_DENSITY && INTVAL (operands[1]) == 0x7FFFFFFF)
2177 && INTVAL (operands[2]) == 0")
2178 (const_int 4)
2179 (if_then_else (match_test "TARGET_DENSITY
2180 && (INTVAL (operands[1]) == 0x7FFFFFFF
2181 || INTVAL (operands[2]) == 0)")
2182 (const_int 5)
2183 (const_int 6))))])
2184
2185 (define_insn_and_split "*masktrue_const_negative_pow2"
2186 [(set (pc)
2187 (if_then_else (match_operator 4 "boolean_operator"
2188 [(and:SI (match_operand:SI 0 "register_operand" "r")
2189 (match_operand:SI 1 "const_int_operand" "i"))
2190 (match_operand:SI 2 "const_int_operand" "i")])
2191 (label_ref (match_operand 3 "" ""))
2192 (pc)))]
2193 "IN_RANGE (exact_log2 (-INTVAL (operands[1])), 1, 30)
2194 /* && (~INTVAL (operands[1]) & INTVAL (operands[2])) == 0 // can be omitted */
2195 && xtensa_b4const_or_zero (INTVAL (operands[2]) >> floor_log2 (-INTVAL (operands[1])))"
2196 "#"
2197 "&& can_create_pseudo_p ()"
2198 [(set (match_dup 5)
2199 (lshiftrt:SI (match_dup 0)
2200 (match_dup 1)))
2201 (set (pc)
2202 (if_then_else (match_op_dup 4
2203 [(match_dup 5)
2204 (match_dup 2)])
2205 (label_ref (match_dup 3))
2206 (pc)))]
2207 {
2208 int shift = floor_log2 (-INTVAL (operands[1]));
2209 operands[1] = GEN_INT (shift);
2210 operands[2] = GEN_INT (INTVAL (operands[2]) >> shift);
2211 operands[5] = gen_reg_rtx (SImode);
2212 }
2213 [(set_attr "type" "jump")
2214 (set_attr "mode" "none")
2215 (set (attr "length")
2216 (if_then_else (match_test "TARGET_DENSITY && INTVAL (operands[2]) == 0")
2217 (const_int 5)
2218 (const_int 6)))])
2219
2220 (define_insn_and_split "*masktrue_const_shifted_mask"
2221 [(set (pc)
2222 (if_then_else (match_operator 4 "boolean_operator"
2223 [(and:SI (match_operand:SI 0 "register_operand" "r")
2224 (match_operand:SI 1 "shifted_mask_operand" "i"))
2225 (match_operand:SI 2 "const_int_operand" "i")])
2226 (label_ref (match_operand 3 "" ""))
2227 (pc)))]
2228 "/* (INTVAL (operands[2]) & ((1 << ctz_hwi (INTVAL (operands[1]))) - 1)) == 0 // can be omitted
2229 && */ xtensa_b4const_or_zero ((uint32_t)INTVAL (operands[2]) >> ctz_hwi (INTVAL (operands[1])))"
2230 "#"
2231 "&& can_create_pseudo_p ()"
2232 [(set (match_dup 6)
2233 (zero_extract:SI (match_dup 0)
2234 (match_dup 5)
2235 (match_dup 1)))
2236 (set (pc)
2237 (if_then_else (match_op_dup 4
2238 [(match_dup 6)
2239 (match_dup 2)])
2240 (label_ref (match_dup 3))
2241 (pc)))]
2242 {
2243 HOST_WIDE_INT mask = INTVAL (operands[1]);
2244 int shift = ctz_hwi (mask);
2245 int mask_size = floor_log2 (((uint32_t)mask >> shift) + 1);
2246 int mask_pos = shift;
2247 if (BITS_BIG_ENDIAN)
2248 mask_pos = (32 - (mask_size + shift)) & 0x1f;
2249 operands[1] = GEN_INT (mask_pos);
2250 operands[2] = GEN_INT ((uint32_t)INTVAL (operands[2]) >> shift);
2251 operands[5] = GEN_INT (mask_size);
2252 operands[6] = gen_reg_rtx (SImode);
2253 }
2254 [(set_attr "type" "jump")
2255 (set_attr "mode" "none")
2256 (set (attr "length")
2257 (if_then_else (match_test "TARGET_DENSITY
2258 && (uint32_t)INTVAL (operands[2]) >> ctz_hwi (INTVAL (operands[1])) == 0")
2259 (const_int 5)
2260 (const_int 6)))])
2261
2262
2263 ;; Zero-overhead looping support.
2264
2265 ;; Define the loop insns used by bct optimization to represent the
2266 ;; start and end of a zero-overhead loop. This start template generates
2267 ;; the loop insn; the end template doesn't generate any instructions since
2268 ;; loop end is handled in hardware.
2269
2270 (define_insn "zero_cost_loop_start"
2271 [(set (pc)
2272 (if_then_else (ne (match_operand:SI 2 "register_operand" "0")
2273 (const_int 1))
2274 (label_ref (match_operand 1 "" ""))
2275 (pc)))
2276 (set (match_operand:SI 0 "register_operand" "=a")
2277 (plus:SI (match_dup 0)
2278 (const_int -1)))
2279 (unspec [(const_int 0)] UNSPEC_LSETUP_START)]
2280 "TARGET_LOOPS && optimize"
2281 "loop\t%0, %l1_LEND"
2282 [(set_attr "type" "jump")
2283 (set_attr "mode" "none")
2284 (set_attr "length" "3")])
2285
2286 (define_insn "zero_cost_loop_end"
2287 [(set (pc)
2288 (if_then_else (ne (match_operand:SI 2 "nonimmediate_operand" "0,0")
2289 (const_int 1))
2290 (label_ref (match_operand 1 "" ""))
2291 (pc)))
2292 (set (match_operand:SI 0 "nonimmediate_operand" "=a,m")
2293 (plus:SI (match_dup 0)
2294 (const_int -1)))
2295 (unspec [(const_int 0)] UNSPEC_LSETUP_END)
2296 (clobber (match_scratch:SI 3 "=X,&r"))]
2297 "TARGET_LOOPS && optimize"
2298 "#"
2299 [(set_attr "type" "jump")
2300 (set_attr "mode" "none")
2301 (set_attr "length" "0")])
2302
2303 (define_insn "loop_end"
2304 [(set (pc)
2305 (if_then_else (ne (match_operand:SI 2 "register_operand" "0")
2306 (const_int 1))
2307 (label_ref (match_operand 1 "" ""))
2308 (pc)))
2309 (set (match_operand:SI 0 "register_operand" "=a")
2310 (plus:SI (match_dup 0)
2311 (const_int -1)))
2312 (unspec [(const_int 0)] UNSPEC_LSETUP_END)]
2313 "TARGET_LOOPS && optimize"
2314 {
2315 xtensa_emit_loop_end (insn, operands);
2316 return "";
2317 }
2318 [(set_attr "type" "jump")
2319 (set_attr "mode" "none")
2320 (set_attr "length" "0")])
2321
2322 (define_split
2323 [(set (pc)
2324 (if_then_else (ne (match_operand:SI 0 "nonimmediate_operand" "")
2325 (const_int 1))
2326 (label_ref (match_operand 1 "" ""))
2327 (pc)))
2328 (set (match_operand:SI 2 "nonimmediate_operand" "")
2329 (plus:SI (match_dup 0)
2330 (const_int -1)))
2331 (unspec [(const_int 0)] UNSPEC_LSETUP_END)
2332 (clobber (match_scratch 3))]
2333 "TARGET_LOOPS && optimize && reload_completed"
2334 [(const_int 0)]
2335 {
2336 if (!REG_P (operands[0]))
2337 {
2338 rtx test;
2339
2340 /* Fallback into a normal conditional branch insn. */
2341 emit_move_insn (operands[3], operands[0]);
2342 emit_insn (gen_addsi3 (operands[3], operands[3], constm1_rtx));
2343 emit_move_insn (operands[0], operands[3]);
2344 test = gen_rtx_NE (VOIDmode, operands[3], const0_rtx);
2345 emit_jump_insn (gen_cbranchsi4 (test, operands[3],
2346 const0_rtx, operands[1]));
2347 }
2348 else
2349 {
2350 emit_jump_insn (gen_loop_end (operands[0], operands[1], operands[2]));
2351 }
2352
2353 DONE;
2354 })
2355
2356 ; operand 0 is the loop count pseudo register
2357 ; operand 1 is the label to jump to at the top of the loop
2358 (define_expand "doloop_end"
2359 [(parallel [(set (pc) (if_then_else
2360 (ne (match_operand:SI 0 "" "")
2361 (const_int 1))
2362 (label_ref (match_operand 1 "" ""))
2363 (pc)))
2364 (set (match_dup 0)
2365 (plus:SI (match_dup 0)
2366 (const_int -1)))
2367 (unspec [(const_int 0)] UNSPEC_LSETUP_END)])]
2368 "TARGET_LOOPS && optimize"
2369 {
2370 /* The loop optimizer doesn't check the predicates... */
2371 if (GET_MODE (operands[0]) != SImode)
2372 FAIL;
2373 })
2374
2375
2376 ;; Setting a register from a comparison.
2377
2378 (define_expand "cstoresi4"
2379 [(match_operand:SI 0 "register_operand")
2380 (match_operator 1 "xtensa_cstoresi_operator"
2381 [(match_operand:SI 2 "register_operand")
2382 (match_operand:SI 3 "nonmemory_operand")])]
2383 ""
2384 {
2385 if (!xtensa_expand_scc (operands, SImode))
2386 FAIL;
2387 DONE;
2388 })
2389
2390 (define_insn "salt"
2391 [(set (match_operand:SI 0 "register_operand" "=a")
2392 (lt:SI (match_operand:SI 1 "register_operand" "r")
2393 (match_operand:SI 2 "register_operand" "r")))]
2394 "TARGET_SALT"
2395 "salt\t%0, %1, %2"
2396 [(set_attr "type" "arith")
2397 (set_attr "mode" "SI")
2398 (set_attr "length" "3")])
2399
2400 (define_insn "saltu"
2401 [(set (match_operand:SI 0 "register_operand" "=a")
2402 (ltu:SI (match_operand:SI 1 "register_operand" "r")
2403 (match_operand:SI 2 "register_operand" "r")))]
2404 "TARGET_SALT"
2405 "saltu\t%0, %1, %2"
2406 [(set_attr "type" "arith")
2407 (set_attr "mode" "SI")
2408 (set_attr "length" "3")])
2409
2410 (define_expand "cstoresf4"
2411 [(match_operand:SI 0 "register_operand")
2412 (match_operator:SI 1 "comparison_operator"
2413 [(match_operand:SF 2 "register_operand")
2414 (match_operand:SF 3 "register_operand")])]
2415 "TARGET_HARD_FLOAT"
2416 {
2417 if (!xtensa_expand_scc (operands, SFmode))
2418 FAIL;
2419 DONE;
2420 })
2421
2422
2423
2424 ;; Conditional moves.
2425
2426 (define_expand "movsicc"
2427 [(set (match_operand:SI 0 "register_operand" "")
2428 (if_then_else:SI (match_operand 1 "comparison_operator" "")
2429 (match_operand:SI 2 "register_operand" "")
2430 (match_operand:SI 3 "register_operand" "")))]
2431 ""
2432 {
2433 if (!xtensa_expand_conditional_move (operands, 0))
2434 FAIL;
2435 DONE;
2436 })
2437
2438 (define_expand "movsfcc"
2439 [(set (match_operand:SF 0 "register_operand" "")
2440 (if_then_else:SF (match_operand 1 "comparison_operator" "")
2441 (match_operand:SF 2 "register_operand" "")
2442 (match_operand:SF 3 "register_operand" "")))]
2443 ""
2444 {
2445 if (!xtensa_expand_conditional_move (operands, 1))
2446 FAIL;
2447 DONE;
2448 })
2449
2450 (define_insn "movsicc_internal0"
2451 [(set (match_operand:SI 0 "register_operand" "=a,a")
2452 (if_then_else:SI (match_operator 4 "branch_operator"
2453 [(match_operand:SI 1 "register_operand" "r,r")
2454 (const_int 0)])
2455 (match_operand:SI 2 "register_operand" "r,0")
2456 (match_operand:SI 3 "register_operand" "0,r")))]
2457 ""
2458 {
2459 return xtensa_emit_movcc (which_alternative == 1, false, false, operands);
2460 }
2461 [(set_attr "type" "move,move")
2462 (set_attr "mode" "SI")
2463 (set_attr "length" "3,3")])
2464
2465 (define_insn "movsicc_internal1"
2466 [(set (match_operand:SI 0 "register_operand" "=a,a")
2467 (if_then_else:SI (match_operator 4 "boolean_operator"
2468 [(match_operand:CC 1 "register_operand" "b,b")
2469 (const_int 0)])
2470 (match_operand:SI 2 "register_operand" "r,0")
2471 (match_operand:SI 3 "register_operand" "0,r")))]
2472 "TARGET_BOOLEANS"
2473 {
2474 return xtensa_emit_movcc (which_alternative == 1, false, true, operands);
2475 }
2476 [(set_attr "type" "move,move")
2477 (set_attr "mode" "SI")
2478 (set_attr "length" "3,3")])
2479
2480 (define_insn "movsfcc_internal0"
2481 [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
2482 (if_then_else:SF (match_operator 4 "branch_operator"
2483 [(match_operand:SI 1 "register_operand" "r,r,r,r")
2484 (const_int 0)])
2485 (match_operand:SF 2 "register_operand" "r,0,f,0")
2486 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
2487 ""
2488 {
2489 return xtensa_emit_movcc ((which_alternative & 1) == 1,
2490 which_alternative >= 2, false, operands);
2491 }
2492 [(set_attr "type" "move,move,move,move")
2493 (set_attr "mode" "SF")
2494 (set_attr "length" "3,3,3,3")])
2495
2496 (define_insn "movsfcc_internal1"
2497 [(set (match_operand:SF 0 "register_operand" "=a,a,f,f")
2498 (if_then_else:SF (match_operator 4 "boolean_operator"
2499 [(match_operand:CC 1 "register_operand" "b,b,b,b")
2500 (const_int 0)])
2501 (match_operand:SF 2 "register_operand" "r,0,f,0")
2502 (match_operand:SF 3 "register_operand" "0,r,0,f")))]
2503 "TARGET_BOOLEANS"
2504 {
2505 return xtensa_emit_movcc ((which_alternative & 1) == 1,
2506 which_alternative >= 2, true, operands);
2507 }
2508 [(set_attr "type" "move,move,move,move")
2509 (set_attr "mode" "SF")
2510 (set_attr "length" "3,3,3,3")])
2511
2512
2513 ;; Floating-point comparisons.
2514
2515 (define_insn "s<code>_sf"
2516 [(set (match_operand:CC 0 "register_operand" "=b")
2517 (any_scc_sf:CC (match_operand:SF 1 "register_operand" "f")
2518 (match_operand:SF 2 "register_operand" "f")))]
2519 "TARGET_HARD_FLOAT"
2520 "<scc_sf>.s\t%0, %1, %2"
2521 [(set_attr "type" "farith")
2522 (set_attr "mode" "BL")
2523 (set_attr "length" "3")])
2524
2525
2526 ;; Unconditional branches.
2527
2528 (define_insn "jump"
2529 [(set (pc)
2530 (label_ref (match_operand 0 "" "")))]
2531 ""
2532 "j\t%l0"
2533 [(set_attr "type" "jump")
2534 (set_attr "mode" "none")
2535 (set_attr "length" "3")])
2536
2537 (define_expand "indirect_jump"
2538 [(set (pc)
2539 (match_operand 0 "register_operand" ""))]
2540 ""
2541 {
2542 rtx dest = operands[0];
2543 if (! REG_P (dest) || GET_MODE (dest) != Pmode)
2544 operands[0] = copy_to_mode_reg (Pmode, dest);
2545
2546 emit_jump_insn (gen_indirect_jump_internal (dest));
2547 DONE;
2548 })
2549
2550 (define_insn "indirect_jump_internal"
2551 [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
2552 ""
2553 "jx\t%0"
2554 [(set_attr "type" "jump")
2555 (set_attr "mode" "none")
2556 (set_attr "length" "3")])
2557
2558
2559 (define_expand "tablejump"
2560 [(use (match_operand:SI 0 "register_operand" ""))
2561 (use (label_ref (match_operand 1 "" "")))]
2562 ""
2563 {
2564 rtx target = operands[0];
2565 if (flag_pic)
2566 {
2567 /* For PIC, the table entry is relative to the start of the table. */
2568 rtx label = gen_reg_rtx (SImode);
2569 target = gen_reg_rtx (SImode);
2570 emit_move_insn (label, gen_rtx_LABEL_REF (SImode, operands[1]));
2571 emit_insn (gen_addsi3 (target, operands[0], label));
2572 }
2573 emit_jump_insn (gen_tablejump_internal (target, operands[1]));
2574 DONE;
2575 })
2576
2577 (define_insn "tablejump_internal"
2578 [(set (pc)
2579 (match_operand:SI 0 "register_operand" "r"))
2580 (use (label_ref (match_operand 1 "" "")))]
2581 ""
2582 "jx\t%0"
2583 [(set_attr "type" "jump")
2584 (set_attr "mode" "none")
2585 (set_attr "length" "3")])
2586
2587
2588 ;; Function calls.
2589
2590 (define_expand "sym_PLT"
2591 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PLT))]
2592 ""
2593 "")
2594
2595 (define_expand "call"
2596 [(call (match_operand 0 "memory_operand" "")
2597 (match_operand 1 "" ""))]
2598 ""
2599 {
2600 xtensa_expand_call (0, operands);
2601 DONE;
2602 })
2603
2604 (define_insn "call_internal"
2605 [(call (mem (match_operand:SI 0 "call_insn_operand" "nir"))
2606 (match_operand 1 "" "i"))]
2607 "!SIBLING_CALL_P (insn)"
2608 {
2609 return xtensa_emit_call (0, operands);
2610 }
2611 [(set_attr "type" "call")
2612 (set_attr "mode" "none")
2613 (set_attr "length" "3")])
2614
2615 (define_expand "call_value"
2616 [(set (match_operand 0 "register_operand" "")
2617 (call (match_operand 1 "memory_operand" "")
2618 (match_operand 2 "" "")))]
2619 ""
2620 {
2621 xtensa_expand_call (1, operands);
2622 DONE;
2623 })
2624
2625 (define_insn "call_value_internal"
2626 [(set (match_operand 0 "register_operand" "=a")
2627 (call (mem (match_operand:SI 1 "call_insn_operand" "nir"))
2628 (match_operand 2 "" "i")))]
2629 "!SIBLING_CALL_P (insn)"
2630 {
2631 return xtensa_emit_call (1, operands);
2632 }
2633 [(set_attr "type" "call")
2634 (set_attr "mode" "none")
2635 (set_attr "length" "3")])
2636
2637 (define_expand "sibcall"
2638 [(call (match_operand 0 "memory_operand" "")
2639 (match_operand 1 "" ""))]
2640 "!TARGET_WINDOWED_ABI"
2641 {
2642 xtensa_expand_call (0, operands);
2643 DONE;
2644 })
2645
2646 (define_insn "sibcall_internal"
2647 [(call (mem:SI (match_operand:SI 0 "call_insn_operand" "nic"))
2648 (match_operand 1 "" "i"))]
2649 "!TARGET_WINDOWED_ABI && SIBLING_CALL_P (insn)"
2650 {
2651 return xtensa_emit_sibcall (0, operands);
2652 }
2653 [(set_attr "type" "call")
2654 (set_attr "mode" "none")
2655 (set_attr "length" "3")])
2656
2657 (define_expand "sibcall_value"
2658 [(set (match_operand 0 "register_operand" "")
2659 (call (match_operand 1 "memory_operand" "")
2660 (match_operand 2 "" "")))]
2661 "!TARGET_WINDOWED_ABI"
2662 {
2663 xtensa_expand_call (1, operands);
2664 DONE;
2665 })
2666
2667 (define_insn "sibcall_value_internal"
2668 [(set (match_operand 0 "register_operand" "=a")
2669 (call (mem:SI (match_operand:SI 1 "call_insn_operand" "nic"))
2670 (match_operand 2 "" "i")))]
2671 "!TARGET_WINDOWED_ABI && SIBLING_CALL_P (insn)"
2672 {
2673 return xtensa_emit_sibcall (1, operands);
2674 }
2675 [(set_attr "type" "call")
2676 (set_attr "mode" "none")
2677 (set_attr "length" "3")])
2678
2679 (define_expand "untyped_call"
2680 [(parallel [(call (match_operand 0 "")
2681 (const_int 0))
2682 (match_operand 1 "")
2683 (match_operand 2 "")])]
2684 ""
2685 {
2686 int i;
2687
2688 emit_call_insn (gen_call (operands[0], const0_rtx));
2689
2690 for (i = 0; i < XVECLEN (operands[2], 0); i++)
2691 {
2692 rtx set = XVECEXP (operands[2], 0, i);
2693 emit_move_insn (SET_DEST (set), SET_SRC (set));
2694 }
2695
2696 emit_insn (gen_blockage ());
2697 DONE;
2698 })
2699
2700 (define_insn "entry"
2701 [(set (reg:SI A1_REG)
2702 (unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "i")]
2703 UNSPECV_ENTRY))]
2704 ""
2705 "entry\tsp, %0"
2706 [(set_attr "type" "entry")
2707 (set_attr "mode" "SI")
2708 (set_attr "length" "3")])
2709
2710 (define_insn "return"
2711 [(return)
2712 (use (reg:SI A0_REG))]
2713 "reload_completed
2714 && (TARGET_WINDOWED_ABI
2715 || compute_frame_size (get_frame_size ()) == 0
2716 || epilogue_completed)"
2717 {
2718 return TARGET_WINDOWED_ABI ?
2719 (TARGET_DENSITY ? "retw.n" : "retw") :
2720 (TARGET_DENSITY ? "ret.n" : "ret");
2721 }
2722 [(set_attr "type" "jump")
2723 (set_attr "mode" "none")
2724 (set (attr "length")
2725 (if_then_else (match_test "TARGET_DENSITY")
2726 (const_int 2)
2727 (const_int 3)))])
2728
2729
2730 ;; Miscellaneous instructions.
2731
2732 ;; In windowed ABI stack pointer adjustment must happen before any access
2733 ;; to the space allocated on stack is allowed, otherwise register spill
2734 ;; area may be clobbered. That's what frame blockage is supposed to enforce.
2735
2736 (define_expand "allocate_stack"
2737 [(set (match_operand 0 "nonimmed_operand")
2738 (minus (reg A1_REG) (match_operand 1 "add_operand")))
2739 (set (reg A1_REG)
2740 (minus (reg A1_REG) (match_dup 1)))]
2741 "TARGET_WINDOWED_ABI"
2742 {
2743 if (CONST_INT_P (operands[1]))
2744 {
2745 rtx neg_op0 = GEN_INT (-INTVAL (operands[1]));
2746 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
2747 }
2748 else
2749 {
2750 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx,
2751 operands[1]));
2752 }
2753 emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
2754 emit_insn (gen_frame_blockage ());
2755 DONE;
2756 })
2757
2758 (define_expand "prologue"
2759 [(const_int 0)]
2760 ""
2761 {
2762 xtensa_expand_prologue ();
2763 DONE;
2764 })
2765
2766 (define_expand "epilogue"
2767 [(return)]
2768 ""
2769 {
2770 xtensa_expand_epilogue ();
2771 emit_jump_insn (gen_return ());
2772 DONE;
2773 })
2774
2775 (define_expand "sibcall_epilogue"
2776 [(return)]
2777 "!TARGET_WINDOWED_ABI"
2778 {
2779 xtensa_expand_epilogue ();
2780 emit_use (gen_rtx_REG (SImode, A0_REG));
2781 DONE;
2782 })
2783
2784 (define_insn "nop"
2785 [(const_int 0)]
2786 ""
2787 {
2788 return (TARGET_DENSITY ? "nop.n" : "nop");
2789 }
2790 [(set_attr "type" "nop")
2791 (set_attr "mode" "none")
2792 (set (attr "length")
2793 (if_then_else (match_test "TARGET_DENSITY")
2794 (const_int 2)
2795 (const_int 3)))])
2796
2797 (define_expand "nonlocal_goto"
2798 [(match_operand:SI 0 "general_operand" "")
2799 (match_operand:SI 1 "general_operand" "")
2800 (match_operand:SI 2 "general_operand" "")
2801 (match_operand:SI 3 "" "")]
2802 "TARGET_WINDOWED_ABI"
2803 {
2804 xtensa_expand_nonlocal_goto (operands);
2805 DONE;
2806 })
2807
2808 ;; Stuff an address into the return address register along with the window
2809 ;; size in the high bits. Because we don't have the window size of the
2810 ;; previous frame, assume the function called out with a CALL8 since that
2811 ;; is what compilers always use. Note: __builtin_frob_return_addr has
2812 ;; already been applied to the handler, but the generic version doesn't
2813 ;; allow us to frob it quite enough, so we just frob here.
2814
2815 (define_expand "eh_return"
2816 [(use (match_operand 0 "general_operand"))]
2817 ""
2818 {
2819 if (TARGET_WINDOWED_ABI)
2820 emit_insn (gen_eh_set_a0_windowed (operands[0]));
2821 else
2822 emit_insn (gen_eh_set_a0_call0 (operands[0]));
2823 DONE;
2824 })
2825
2826 (define_insn_and_split "eh_set_a0_windowed"
2827 [(set (reg:SI A0_REG)
2828 (unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")]
2829 UNSPECV_EH_RETURN))
2830 (clobber (match_scratch:SI 1 "=r"))]
2831 ""
2832 "#"
2833 "reload_completed"
2834 [(set (match_dup 1) (ashift:SI (match_dup 0) (const_int 2)))
2835 (set (match_dup 1) (plus:SI (match_dup 1) (const_int 2)))
2836 (set (reg:SI A0_REG) (rotatert:SI (match_dup 1) (const_int 2)))]
2837 "")
2838
2839 (define_insn_and_split "eh_set_a0_call0"
2840 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
2841 UNSPECV_EH_RETURN)
2842 (clobber (match_scratch:SI 1 "=r"))]
2843 ""
2844 "#"
2845 "reload_completed"
2846 [(const_int 0)]
2847 {
2848 xtensa_set_return_address (operands[0], operands[1]);
2849 DONE;
2850 })
2851
2852 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
2853 ;; all of memory. This blocks insns from being moved across this point.
2854
2855 (define_insn "blockage"
2856 [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
2857 ""
2858 ""
2859 [(set_attr "type" "nop")
2860 (set_attr "mode" "none")
2861 (set_attr "length" "0")])
2862
2863 ;; Do not schedule instructions accessing memory before this point.
2864
2865 (define_expand "frame_blockage"
2866 [(set (match_dup 0)
2867 (unspec:BLK [(match_dup 1)] UNSPEC_FRAME_BLOCKAGE))]
2868 ""
2869 {
2870 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
2871 MEM_VOLATILE_P (operands[0]) = 1;
2872 operands[1] = stack_pointer_rtx;
2873 })
2874
2875 (define_insn "*frame_blockage"
2876 [(set (match_operand:BLK 0 "" "")
2877 (unspec:BLK [(match_operand:SI 1 "" "")] UNSPEC_FRAME_BLOCKAGE))]
2878 ""
2879 ""
2880 [(set_attr "type" "nop")
2881 (set_attr "mode" "none")
2882 (set_attr "length" "0")])
2883
2884 (define_insn "trap"
2885 [(trap_if (const_int 1) (const_int 0))]
2886 ""
2887 {
2888 if (TARGET_DEBUG)
2889 return "break\t1, 15";
2890 else
2891 return (TARGET_DENSITY ? "ill.n" : "ill");
2892 }
2893 [(set_attr "type" "trap")
2894 (set_attr "mode" "none")
2895 (set (attr "length")
2896 (if_then_else (match_test "!TARGET_DEBUG && TARGET_DENSITY")
2897 (const_int 2)
2898 (const_int 3)))])
2899
2900 ;; Setting up a frame pointer is tricky for Xtensa because GCC doesn't
2901 ;; know if a frame pointer is required until the reload pass, and
2902 ;; because there may be an incoming argument value in the hard frame
2903 ;; pointer register (a7). If there is an incoming argument in that
2904 ;; register, the "set_frame_ptr" insn gets inserted immediately after
2905 ;; the insn that copies the incoming argument to a pseudo or to the
2906 ;; stack. This serves several purposes here: (1) it keeps the
2907 ;; optimizer from copy-propagating or scheduling the use of a7 as an
2908 ;; incoming argument away from the beginning of the function; (2) we
2909 ;; can use a post-reload splitter to expand away the insn if a frame
2910 ;; pointer is not required, so that the post-reload scheduler can do
2911 ;; the right thing; and (3) it makes it easy for the prologue expander
2912 ;; to search for this insn to determine whether it should add a new insn
2913 ;; to set up the frame pointer.
2914
2915 (define_insn "set_frame_ptr"
2916 [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
2917 ""
2918 {
2919 if (frame_pointer_needed)
2920 return (TARGET_DENSITY ? "mov.n\ta7, sp" : "mov\ta7, sp");
2921 return "";
2922 }
2923 [(set_attr "type" "move")
2924 (set_attr "mode" "SI")
2925 (set (attr "length")
2926 (if_then_else (match_test "TARGET_DENSITY")
2927 (const_int 2)
2928 (const_int 3)))])
2929
2930 ;; Post-reload splitter to remove fp assignment when it's not needed.
2931 (define_split
2932 [(set (reg:SI A7_REG) (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_FP))]
2933 "reload_completed && !frame_pointer_needed"
2934 [(unspec [(const_int 0)] UNSPEC_NOP)]
2935 "")
2936
2937 ;; The preceding splitter needs something to split the insn into;
2938 ;; things start breaking if the result is just a "use" so instead we
2939 ;; generate the following insn.
2940 (define_insn "*unspec_nop"
2941 [(unspec [(const_int 0)] UNSPEC_NOP)]
2942 ""
2943 ""
2944 [(set_attr "type" "nop")
2945 (set_attr "mode" "none")
2946 (set_attr "length" "0")])
2947
2948
2949 ;; TLS support
2950
2951 (define_expand "sym_TPOFF"
2952 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_TPOFF))]
2953 ""
2954 "")
2955
2956 (define_expand "sym_DTPOFF"
2957 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_DTPOFF))]
2958 ""
2959 "")
2960
2961 (define_insn "get_thread_pointersi"
2962 [(set (match_operand:SI 0 "register_operand" "=a")
2963 (unspec:SI [(const_int 0)] UNSPEC_TP))]
2964 "TARGET_THREADPTR"
2965 "rur\t%0, THREADPTR"
2966 [(set_attr "type" "rsr")
2967 (set_attr "mode" "SI")
2968 (set_attr "length" "3")])
2969
2970 (define_insn "set_thread_pointersi"
2971 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
2972 UNSPECV_SET_TP)]
2973 "TARGET_THREADPTR"
2974 "wur\t%0, THREADPTR"
2975 [(set_attr "type" "wsr")
2976 (set_attr "mode" "SI")
2977 (set_attr "length" "3")])
2978
2979 (define_insn "tls_func"
2980 [(set (match_operand:SI 0 "register_operand" "=a")
2981 (unspec:SI [(match_operand:SI 1 "tls_symbol_operand" "")]
2982 UNSPEC_TLS_FUNC))]
2983 "TARGET_THREADPTR && HAVE_AS_TLS"
2984 "movi\t%0, %1@TLSFUNC"
2985 [(set_attr "type" "load")
2986 (set_attr "mode" "SI")
2987 (set_attr "length" "3")])
2988
2989 (define_insn "tls_arg"
2990 [(set (match_operand:SI 0 "register_operand" "=a")
2991 (unspec:SI [(match_operand:SI 1 "tls_symbol_operand" "")]
2992 UNSPEC_TLS_ARG))]
2993 "TARGET_THREADPTR && HAVE_AS_TLS"
2994 "movi\t%0, %1@TLSARG"
2995 [(set_attr "type" "load")
2996 (set_attr "mode" "SI")
2997 (set_attr "length" "3")])
2998
2999 (define_insn "tls_call"
3000 [(set (match_operand:SI 0 "register_operand" "=a")
3001 (call (mem:SI (unspec:SI [(match_operand:SI 1 "register_operand" "r")
3002 (match_operand:SI 2 "tls_symbol_operand" "")]
3003 UNSPEC_TLS_CALL))
3004 (match_operand 3 "" "i")))]
3005 "TARGET_THREADPTR && HAVE_AS_TLS"
3006 {
3007 if (TARGET_WINDOWED_ABI)
3008 return "callx8.tls %1, %2@TLSCALL";
3009 else
3010 return "callx0.tls %1, %2@TLSCALL";
3011 }
3012 [(set_attr "type" "call")
3013 (set_attr "mode" "none")
3014 (set_attr "length" "3")])
3015
3016
3017 ;; Instructions for the Xtensa "boolean" option.
3018
3019 (define_insn "*booltrue"
3020 [(set (pc)
3021 (if_then_else (match_operator 2 "boolean_operator"
3022 [(match_operand:CC 0 "register_operand" "b")
3023 (const_int 0)])
3024 (label_ref (match_operand 1 "" ""))
3025 (pc)))]
3026 "TARGET_BOOLEANS"
3027 {
3028 if (GET_CODE (operands[2]) == EQ)
3029 return "bf\t%0, %1";
3030 else
3031 return "bt\t%0, %1";
3032 }
3033 [(set_attr "type" "jump")
3034 (set_attr "mode" "none")
3035 (set_attr "length" "3")])
3036
3037 (define_insn "*boolfalse"
3038 [(set (pc)
3039 (if_then_else (match_operator 2 "boolean_operator"
3040 [(match_operand:CC 0 "register_operand" "b")
3041 (const_int 0)])
3042 (pc)
3043 (label_ref (match_operand 1 "" ""))))]
3044 "TARGET_BOOLEANS"
3045 {
3046 if (GET_CODE (operands[2]) == EQ)
3047 return "bt\t%0, %1";
3048 else
3049 return "bf\t%0, %1";
3050 }
3051 [(set_attr "type" "jump")
3052 (set_attr "mode" "none")
3053 (set_attr "length" "3")])
3054
3055
3056 ;; Atomic operations
3057
3058 (define_expand "memory_barrier"
3059 [(set (match_dup 0)
3060 (unspec:BLK [(match_dup 0)] UNSPEC_MEMW))]
3061 ""
3062 {
3063 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
3064 MEM_VOLATILE_P (operands[0]) = 1;
3065 })
3066
3067 (define_insn "*memory_barrier"
3068 [(set (match_operand:BLK 0 "" "")
3069 (unspec:BLK [(match_dup 0)] UNSPEC_MEMW))]
3070 ""
3071 "memw"
3072 [(set_attr "type" "unknown")
3073 (set_attr "mode" "none")
3074 (set_attr "length" "3")])
3075
3076 ;; sync_lock_release is only implemented for SImode.
3077 ;; For other modes, just use the default of a store with a memory_barrier.
3078 (define_insn "sync_lock_releasesi"
3079 [(set (match_operand:SI 0 "mem_operand" "=U")
3080 (unspec_volatile:SI
3081 [(match_operand:SI 1 "register_operand" "r")]
3082 UNSPECV_S32RI))]
3083 "TARGET_RELEASE_SYNC"
3084 "s32ri\t%1, %0"
3085 [(set_attr "type" "store")
3086 (set_attr "mode" "SI")
3087 (set_attr "length" "3")])
3088
3089 (define_insn "sync_compare_and_swapsi"
3090 [(parallel
3091 [(set (match_operand:SI 0 "register_operand" "=a")
3092 (match_operand:SI 1 "mem_operand" "+U"))
3093 (set (match_dup 1)
3094 (unspec_volatile:SI
3095 [(match_dup 1)
3096 (match_operand:SI 2 "register_operand" "r")
3097 (match_operand:SI 3 "register_operand" "0")]
3098 UNSPECV_S32C1I))])]
3099 "TARGET_S32C1I"
3100 "wsr\t%2, SCOMPARE1\;s32c1i\t%3, %1"
3101 [(set_attr "type" "multi")
3102 (set_attr "mode" "SI")
3103 (set_attr "length" "6")])
3104
3105 (define_expand "sync_compare_and_swap<mode>"
3106 [(parallel
3107 [(set (match_operand:HQI 0 "register_operand" "")
3108 (match_operand:HQI 1 "mem_operand" ""))
3109 (set (match_dup 1)
3110 (unspec_volatile:HQI
3111 [(match_dup 1)
3112 (match_operand:HQI 2 "register_operand" "")
3113 (match_operand:HQI 3 "register_operand" "")]
3114 UNSPECV_S32C1I))])]
3115 "TARGET_S32C1I"
3116 {
3117 xtensa_expand_compare_and_swap (operands[0], operands[1],
3118 operands[2], operands[3]);
3119 DONE;
3120 })
3121
3122 (define_expand "sync_lock_test_and_set<mode>"
3123 [(match_operand:HQI 0 "register_operand")
3124 (match_operand:HQI 1 "memory_operand")
3125 (match_operand:HQI 2 "register_operand")]
3126 "TARGET_S32C1I"
3127 {
3128 xtensa_expand_atomic (SET, operands[0], operands[1], operands[2], false);
3129 DONE;
3130 })
3131
3132 (define_expand "sync_<atomic><mode>"
3133 [(set (match_operand:HQI 0 "memory_operand")
3134 (ATOMIC:HQI (match_dup 0)
3135 (match_operand:HQI 1 "register_operand")))]
3136 "TARGET_S32C1I"
3137 {
3138 xtensa_expand_atomic (<CODE>, NULL_RTX, operands[0], operands[1], false);
3139 DONE;
3140 })
3141
3142 (define_expand "sync_old_<atomic><mode>"
3143 [(set (match_operand:HQI 0 "register_operand")
3144 (match_operand:HQI 1 "memory_operand"))
3145 (set (match_dup 1)
3146 (ATOMIC:HQI (match_dup 1)
3147 (match_operand:HQI 2 "register_operand")))]
3148 "TARGET_S32C1I"
3149 {
3150 xtensa_expand_atomic (<CODE>, operands[0], operands[1], operands[2], false);
3151 DONE;
3152 })
3153
3154 (define_expand "sync_new_<atomic><mode>"
3155 [(set (match_operand:HQI 0 "register_operand")
3156 (ATOMIC:HQI (match_operand:HQI 1 "memory_operand")
3157 (match_operand:HQI 2 "register_operand")))
3158 (set (match_dup 1) (ATOMIC:HQI (match_dup 1) (match_dup 2)))]
3159 "TARGET_S32C1I"
3160 {
3161 xtensa_expand_atomic (<CODE>, operands[0], operands[1], operands[2], true);
3162 DONE;
3163 })
3164
3165 (define_insn_and_split "*round_up_to_even"
3166 [(set (match_operand:SI 0 "register_operand" "=a")
3167 (and:SI (plus:SI (match_operand:SI 1 "register_operand" "r")
3168 (const_int 1))
3169 (const_int -2)))]
3170 ""
3171 "#"
3172 "can_create_pseudo_p ()"
3173 [(set (match_dup 2)
3174 (and:SI (match_dup 1)
3175 (const_int 1)))
3176 (set (match_dup 0)
3177 (plus:SI (match_dup 2)
3178 (match_dup 1)))]
3179 {
3180 operands[2] = gen_reg_rtx (SImode);
3181 }
3182 [(set_attr "type" "arith")
3183 (set_attr "mode" "SI")
3184 (set (attr "length")
3185 (if_then_else (match_test "TARGET_DENSITY")
3186 (const_int 5)
3187 (const_int 6)))])
3188
3189 (define_insn_and_split "*signed_ge_zero"
3190 [(set (match_operand:SI 0 "register_operand" "=a")
3191 (ge:SI (match_operand:SI 1 "register_operand" "r")
3192 (const_int 0)))]
3193 ""
3194 "#"
3195 ""
3196 [(set (match_dup 0)
3197 (ashiftrt:SI (match_dup 1)
3198 (const_int 31)))
3199 (set (match_dup 0)
3200 (plus:SI (match_dup 0)
3201 (const_int 1)))]
3202 ""
3203 [(set_attr "type" "arith")
3204 (set_attr "mode" "SI")
3205 (set (attr "length")
3206 (if_then_else (match_test "TARGET_DENSITY")
3207 (const_int 5)
3208 (const_int 6)))])
3209
3210 (define_insn_and_split "eq_zero_NSA"
3211 [(set (match_operand:SI 0 "register_operand" "=a")
3212 (eq:SI (match_operand:SI 1 "register_operand" "r")
3213 (const_int 0)))]
3214 "TARGET_NSA"
3215 "#"
3216 "&& 1"
3217 [(set (match_dup 0)
3218 (clz:SI (match_dup 1)))
3219 (set (match_dup 0)
3220 (lshiftrt:SI (match_dup 0)
3221 (const_int 5)))]
3222 ""
3223 [(set_attr "type" "move")
3224 (set_attr "mode" "SI")
3225 (set_attr "length" "6")])
3226
3227 (define_insn_and_split "eqne_zero"
3228 [(set (match_operand:SI 0 "register_operand" "=a,&a")
3229 (match_operator:SI 2 "boolean_operator"
3230 [(match_operand:SI 1 "register_operand" "0,r")
3231 (const_int 0)]))
3232 (clobber (match_scratch:SI 3 "=&a,X"))]
3233 ""
3234 "#"
3235 "&& reload_completed"
3236 [(const_int 0)]
3237 {
3238 enum rtx_code code = GET_CODE (operands[2]);
3239 int same_p = REGNO (operands[0]) == REGNO (operands[1]);
3240 emit_move_insn (same_p ? operands[3] : operands[0],
3241 code == EQ ? constm1_rtx : const1_rtx);
3242 emit_insn (gen_movsicc_internal0 (operands[0], operands[1],
3243 same_p ? operands[3] : operands[1],
3244 operands[0],
3245 gen_rtx_fmt_ee (same_p ? NE : EQ,
3246 VOIDmode,
3247 operands[1],
3248 const0_rtx)));
3249 if (code == EQ)
3250 emit_insn (gen_addsi3 (operands[0], operands[0], const1_rtx));
3251 DONE;
3252 }
3253 [(set_attr "type" "move")
3254 (set_attr "mode" "SI")
3255 (set (attr "length")
3256 (if_then_else (match_test "GET_CODE (operands[2]) == EQ")
3257 (if_then_else (match_test "TARGET_DENSITY")
3258 (const_int 7)
3259 (const_int 9))
3260 (if_then_else (match_test "TARGET_DENSITY")
3261 (const_int 5)
3262 (const_int 6))))])
3263
3264 (define_insn_and_split "*eqne_zero_masked_bits"
3265 [(set (match_operand:SI 0 "register_operand" "=a")
3266 (match_operator:SI 3 "boolean_operator"
3267 [(and:SI (match_operand:SI 1 "register_operand" "r")
3268 (match_operand:SI 2 "const_int_operand" "i"))
3269 (const_int 0)]))]
3270 "IN_RANGE (exact_log2 (INTVAL (operands[2]) + 1), 17, 31)
3271 || IN_RANGE (exact_log2 (-INTVAL (operands[2])), 1, 30)"
3272 "#"
3273 "&& 1"
3274 [(const_int 0)]
3275 {
3276 HOST_WIDE_INT mask = INTVAL (operands[2]);
3277 int n;
3278 enum rtx_code code = GET_CODE (operands[3]);
3279 if (IN_RANGE (n = exact_log2 (mask + 1), 17, 31))
3280 emit_insn (gen_ashlsi3 (operands[0], operands[1], GEN_INT (32 - n)));
3281 else
3282 emit_insn (gen_lshrsi3 (operands[0], operands[1],
3283 GEN_INT (floor_log2 (-mask))));
3284 if (TARGET_NSA && code == EQ)
3285 emit_insn (gen_eq_zero_NSA (operands[0], operands[0]));
3286 else
3287 emit_insn (gen_eqne_zero (operands[0], operands[0],
3288 gen_rtx_fmt_ee (code, VOIDmode,
3289 operands[0], const0_rtx)));
3290 DONE;
3291 })
3292
3293 (define_insn_and_split "*eqne_INT_MIN"
3294 [(set (match_operand:SI 0 "register_operand" "=a")
3295 (match_operator:SI 2 "boolean_operator"
3296 [(match_operand:SI 1 "register_operand" "r")
3297 (const_int -2147483648)]))]
3298 "TARGET_ABS"
3299 "#"
3300 "&& 1"
3301 [(const_int 0)]
3302 {
3303 emit_insn (gen_abssi2 (operands[0], operands[1]));
3304 if (GET_CODE (operands[2]) == EQ)
3305 emit_insn (gen_lshrsi3 (operands[0], operands[0], GEN_INT (31)));
3306 else
3307 {
3308 emit_insn (gen_ashrsi3 (operands[0], operands[0], GEN_INT (31)));
3309 emit_insn (gen_addsi3 (operands[0], operands[0], const1_rtx));
3310 }
3311 DONE;
3312 }
3313 [(set_attr "type" "move")
3314 (set_attr "mode" "SI")
3315 (set (attr "length")
3316 (if_then_else (match_test "GET_CODE (operands[2]) == EQ")
3317 (const_int 6)
3318 (if_then_else (match_test "TARGET_DENSITY")
3319 (const_int 8)
3320 (const_int 9))))])
3321
3322 (define_peephole2
3323 [(set (match_operand:SI 0 "register_operand")
3324 (match_operand:SI 6 "reload_operand"))
3325 (set (match_operand:SI 1 "register_operand")
3326 (match_operand:SI 7 "reload_operand"))
3327 (set (match_operand:SF 2 "register_operand")
3328 (match_operand:SF 4 "register_operand"))
3329 (set (match_operand:SF 3 "register_operand")
3330 (match_operand:SF 5 "register_operand"))]
3331 "REGNO (operands[0]) == REGNO (operands[4])
3332 && REGNO (operands[1]) == REGNO (operands[5])
3333 && peep2_reg_dead_p (4, operands[0])
3334 && peep2_reg_dead_p (4, operands[1])"
3335 [(set (match_dup 2)
3336 (match_dup 6))
3337 (set (match_dup 3)
3338 (match_dup 7))]
3339 {
3340 HARD_REG_SET regs;
3341 int i;
3342 CLEAR_HARD_REG_SET (regs);
3343 for (i = 0; i <= 3; ++i)
3344 if (TEST_HARD_REG_BIT (regs, REGNO (operands[i])))
3345 FAIL;
3346 else
3347 SET_HARD_REG_BIT (regs, REGNO (operands[i]));
3348 operands[6] = gen_rtx_MEM (SFmode, XEXP (operands[6], 0));
3349 operands[7] = gen_rtx_MEM (SFmode, XEXP (operands[7], 0));
3350 })
3351
3352 (define_split
3353 [(clobber (match_operand 0 "register_operand"))]
3354 "HARD_REGISTER_P (operands[0])
3355 && COMPLEX_MODE_P (GET_MODE (operands[0]))"
3356 [(const_int 0)]
3357 {
3358 auto_sbitmap bmp (FIRST_PSEUDO_REGISTER);
3359 rtx_insn *insn;
3360 rtx reg = gen_rtx_REG (SImode, 0), dest;
3361 unsigned int regno;
3362 sbitmap_iterator iter;
3363 bitmap_set_range (bmp, REGNO (operands[0]), REG_NREGS (operands[0]));
3364 for (insn = next_nonnote_nondebug_insn_bb (curr_insn);
3365 insn; insn = next_nonnote_nondebug_insn_bb (insn))
3366 if (NONJUMP_INSN_P (insn))
3367 {
3368 EXECUTE_IF_SET_IN_BITMAP (bmp, 2, regno, iter)
3369 {
3370 set_regno_raw (reg, regno, REG_NREGS (reg));
3371 if (reg_referenced_p (reg, PATTERN (insn)))
3372 goto ABORT;
3373 }
3374 if (GET_CODE (PATTERN (insn)) == SET
3375 || GET_CODE (PATTERN (insn)) == CLOBBER)
3376 {
3377 dest = SET_DEST (PATTERN (insn));
3378 if (REG_P (dest) && HARD_REGISTER_P (dest))
3379 bitmap_clear_range (bmp, REGNO (dest), REG_NREGS (dest));
3380 else if (SUBREG_P (dest)
3381 && HARD_REGISTER_P (SUBREG_REG (dest)))
3382 {
3383 struct subreg_info info;
3384 subreg_get_info (regno = REGNO (SUBREG_REG (dest)),
3385 GET_MODE (SUBREG_REG (dest)),
3386 SUBREG_BYTE (dest), GET_MODE (dest),
3387 &info);
3388 if (!info.representable_p)
3389 break;
3390 bitmap_clear_range (bmp, regno + info.offset, info.nregs);
3391 }
3392 }
3393 if (bitmap_empty_p (bmp))
3394 goto FALLTHRU;
3395 }
3396 else if (CALL_P (insn))
3397 EXECUTE_IF_SET_IN_BITMAP (bmp, 2, regno, iter)
3398 if (call_used_or_fixed_reg_p (regno))
3399 goto ABORT;
3400 ABORT:
3401 FAIL;
3402 FALLTHRU:;
3403 })
3404
3405 (define_peephole2
3406 [(set (match_operand:SI 0 "register_operand")
3407 (match_operand:SI 1 "const_int_operand"))
3408 (set (match_dup 0)
3409 (plus:SI (match_dup 0)
3410 (match_operand:SI 2 "const_int_operand")))
3411 (set (match_operand:SI 3 "register_operand")
3412 (plus:SI (match_operand:SI 4 "register_operand")
3413 (match_dup 0)))]
3414 "IN_RANGE (INTVAL (operands[1]) + INTVAL (operands[2]),
3415 (-128 - 32768), (127 + 32512))
3416 && REGNO (operands[0]) != REGNO (operands[3])
3417 && REGNO (operands[0]) != REGNO (operands[4])
3418 && peep2_reg_dead_p (3, operands[0])"
3419 [(set (match_dup 3)
3420 (plus:SI (match_dup 4)
3421 (match_dup 1)))
3422 (set (match_dup 3)
3423 (plus:SI (match_dup 3)
3424 (match_dup 2)))]
3425 {
3426 HOST_WIDE_INT value = INTVAL (operands[1]) + INTVAL (operands[2]);
3427 int imm0, imm1;
3428 value += 128;
3429 if (value > 32512)
3430 imm1 = 32512;
3431 else
3432 imm1 = value & ~255;
3433 imm0 = value - imm1 - 128;
3434 operands[1] = GEN_INT (imm0);
3435 operands[2] = GEN_INT (imm1);
3436 })
3437
3438 (define_peephole2
3439 [(set (match_operand 0 "register_operand")
3440 (match_operand 1 "register_operand"))]
3441 "REG_NREGS (operands[0]) == 1 && GP_REG_P (REGNO (operands[0]))
3442 && REG_NREGS (operands[1]) == 1 && GP_REG_P (REGNO (operands[1]))
3443 && peep2_reg_dead_p (1, operands[1])"
3444 [(const_int 0)]
3445 {
3446 basic_block bb = BLOCK_FOR_INSN (curr_insn);
3447 rtx_insn *head = BB_HEAD (bb), *insn;
3448 rtx dest = operands[0], src = operands[1], pattern, t_dest, dest_orig;
3449 for (insn = PREV_INSN (curr_insn);
3450 insn && insn != head;
3451 insn = PREV_INSN (insn))
3452 if (CALL_P (insn))
3453 break;
3454 else if (INSN_P (insn))
3455 {
3456 if (GET_CODE (pattern = PATTERN (insn)) == SET
3457 && REG_P (t_dest = SET_DEST (pattern))
3458 && REG_NREGS (t_dest) == 1
3459 && REGNO (t_dest) == REGNO (src))
3460 {
3461 dest_orig = SET_DEST (pattern);
3462 SET_DEST (pattern) = gen_rtx_REG (GET_MODE (t_dest),
3463 REGNO (dest));
3464 extract_insn (insn);
3465 if (!constrain_operands (true, get_enabled_alternatives (insn)))
3466 {
3467 SET_DEST (pattern) = dest_orig;
3468 goto ABORT;
3469 }
3470 df_insn_rescan (insn);
3471 goto FALLTHRU;
3472 }
3473 if (reg_overlap_mentioned_p (dest, pattern)
3474 || reg_overlap_mentioned_p (src, pattern)
3475 || set_of (dest, insn)
3476 || set_of (src, insn))
3477 break;
3478 }
3479 ABORT:
3480 FAIL;
3481 FALLTHRU:;
3482 })