Debian Codegraph @

gcc/config/avr/avr.md

raw
1 ;; Machine description for GNU compiler,
2 ;; for AVR 8-bit microcontrollers.
3 ;; Copyright (C) 1998-2025 Free Software Foundation, Inc.
4 ;; Contributed by Denis Chertykov ([email protected])
5
6 ;; This file is part of GCC.
7
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; any later version.
12
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3. If not see
20 ;; <http://www.gnu.org/licenses/>.
21
22 ;; Special characters after '%':
23 ;; A No effect (add 0).
24 ;; B Add 1 to REG number, MEM address or CONST_INT.
25 ;; C Add 2.
26 ;; D Add 3.
27 ;; E reg number in XEXP(x, 0).
28 ;; F Add 1 to reg number.
29 ;; I reg number in XEXP(XEXP(x, 0), 0).
30 ;; J Add 1 to reg number.
31 ;; j Branch condition.
32 ;; k Reverse branch condition.
33 ;;..m..Constant Direct Data memory address.
34 ;; i Print the SFR address equivalent of a CONST_INT or a CONST_INT
35 ;; RAM address. The resulting address is suitable to be used in IN/OUT.
36 ;; o Displacement for (mem (plus (reg) (const_int))) operands.
37 ;; p POST_INC or PRE_DEC address as a pointer (X, Y, Z)
38 ;; r POST_INC or PRE_DEC address as a register (r26, r28, r30)
39 ;; r Print a REG without the register prefix 'r'.
40 ;; T/T Print operand suitable for BLD/BST instruction, i.e. register and
41 ;; bit number. This gets 2 operands: The first %T gets a REG_P and
42 ;; just cashes the operand for the next %T. The second %T gets
43 ;; a CONST_INT that represents a bit position.
44 ;; Example: With %0 = (reg:HI 18) and %1 = (const_int 13)
45 ;; "%T0%T1" it will print "r19,5".
46 ;; Notice that you must not write a comma between %T0 and %T1.
47 ;; T/t Similar to above, but don't print the comma and the bit number.
48 ;; Example: With %0 = (reg:HI 18) and %1 = (const_int 13)
49 ;; "%T0%t1" it will print "r19".
50 ;;..x..Constant Direct Program memory address.
51 ;; ~ Output 'r' if not AVR_HAVE_JMP_CALL.
52 ;; ! Output 'e' if AVR_HAVE_EIJMP_EICALL.
53
54 ;; Used in avr.cc to avoid magic numbers for register numbers.
55 (define_constants
56 [(REG_0 0) (REG_1 1) (REG_2 2)
57 (REG_8 8) (REG_9 9) (REG_10 10) (REG_11 11)
58 (REG_12 12) (REG_13 13) (REG_14 14) (REG_15 15)
59 (REG_16 16) (REG_17 17) (REG_18 18) (REG_19 19)
60 (REG_20 20) (REG_21 21) (REG_22 22) (REG_23 23)
61 (REG_24 24) (REG_25 25) (REG_26 26) (REG_27 27)
62 (REG_28 28) (REG_29 29) (REG_30 30) (REG_31 31)
63 (REG_32 32) (REG_36 36)
64 ])
65
66 (define_constants
67 [(REG_X REG_26)
68 (REG_Y REG_28)
69 (REG_Z REG_30)
70 (REG_W REG_24)
71 (REG_SP REG_32)
72 (REG_CC REG_36)
73 (LPM_REGNO REG_0) ; implicit target register of LPM
74 (TMP_REGNO REG_0) ; temporary register r0
75 (ZERO_REGNO REG_1) ; zero register r1
76 ])
77
78 (define_constants
79 [(TMP_REGNO_TINY REG_16) ; r16 is temp register for AVR_TINY
80 (ZERO_REGNO_TINY REG_17) ; r17 is zero register for AVR_TINY
81 ])
82
83 (define_c_enum "unspec"
84 [UNSPEC_STRLEN
85 UNSPEC_CPYMEM
86 UNSPEC_INDEX_JMP
87 UNSPEC_NZB
88 UNSPEC_FMUL
89 UNSPEC_FMULS
90 UNSPEC_FMULSU
91 UNSPEC_INSERT_BITS
92 UNSPEC_ROUND
93 ])
94
95 (define_c_enum "unspecv"
96 [UNSPECV_PROLOGUE_SAVES
97 UNSPECV_EPILOGUE_RESTORES
98 UNSPECV_WRITE_SP
99 UNSPECV_GASISR
100 UNSPECV_GOTO_RECEIVER
101 UNSPECV_ENABLE_IRQS
102 UNSPECV_MEMORY_BARRIER
103 UNSPECV_NOP
104 UNSPECV_SLEEP
105 UNSPECV_WDR
106 UNSPECV_DELAY_CYCLES
107 ])
108
109 ;; Chunk numbers for __gcc_isr are hard-coded in GAS.
110 (define_constants
111 [(GASISR_Prologue 1)
112 (GASISR_Epilogue 2)
113 (GASISR_Done 0)
114 ])
115
116 (include "predicates.md")
117 (include "constraints.md")
118
119
120 (define_attr "type" "branch,branch1,arith,xcall"
121 (const_string "arith"))
122
123 ;; The size of instructions in bytes.
124 ;; XXX may depend from "cc"
125
126 (define_attr "length" ""
127 (cond [(eq_attr "type" "branch")
128 (if_then_else (and (ge (minus (pc) (match_dup 0))
129 (const_int -62))
130 (le (minus (pc) (match_dup 0))
131 (const_int 62)))
132 (const_int 1)
133 (if_then_else (and (ge (minus (pc) (match_dup 0))
134 (const_int -2044))
135 (le (minus (pc) (match_dup 0))
136 (const_int 2045)))
137 (const_int 2)
138 (const_int 3)))
139 (eq_attr "type" "branch1")
140 (if_then_else (and (ge (minus (pc) (match_dup 0))
141 (const_int -62))
142 (le (minus (pc) (match_dup 0))
143 (const_int 61)))
144 (const_int 2)
145 (if_then_else (and (ge (minus (pc) (match_dup 0))
146 (const_int -2044))
147 (le (minus (pc) (match_dup 0))
148 (const_int 2043)))
149 (const_int 3)
150 (const_int 4)))
151 (eq_attr "type" "xcall")
152 (if_then_else (match_test "!AVR_HAVE_JMP_CALL")
153 (const_int 1)
154 (const_int 2))]
155 (const_int 2)))
156
157 ;; Lengths of several insns are adjusted in avr.cc:adjust_insn_length().
158 ;; Following insn attribute tells if and how the adjustment has to be
159 ;; done:
160 ;; no No adjustment needed; attribute "length" is fine.
161 ;; Otherwise do special processing depending on the attribute.
162
163 (define_attr "adjust_len"
164 "out_bitop, plus, addto_sp, sext, extr, extr_not, plus_ext, sextr,
165 tsthi, tstpsi, tstsi, compare, compare64, call,
166 mov8, mov16, mov24, mov32, reload_in16, reload_in24, reload_in32,
167 ufract, sfract, round,
168 xload, fload, cpymem,
169 ashlqi, ashrqi, lshrqi,
170 ashlhi, ashrhi, lshrhi,
171 ashlsi, ashrsi, lshrsi,
172 ashlpsi, ashrpsi, lshrpsi,
173 add_lt0, add_ge0,
174 insert_bits, insv_notbit, insv, set_some,
175 add_set_ZN, add_set_N, cmp_uext, cmp_sext, cmp_lsr,
176 no"
177 (const_string "no"))
178
179 (define_attr "nzb"
180 "yes, no"
181 (const_string "no"))
182
183 ;; Flavours of instruction set architecture (ISA), used in enabled attribute
184
185 ;; mov : ISA has no MOVW movw : ISA has MOVW
186 ;; rjmp : ISA has no CALL/JMP jmp : ISA has CALL/JMP
187 ;; ijmp : ISA has no EICALL/EIJMP eijmp : ISA has EICALL/EIJMP
188 ;; lpm : ISA has no LPMX lpmx : ISA has LPMX
189 ;; elpm : ISA has ELPM but no ELPMX elpmx : ISA has ELPMX
190 ;; no_xmega: non-XMEGA core xmega : XMEGA core
191 ;; no_adiw: ISA has no ADIW, SBIW adiw : ISA has ADIW, SBIW
192 ;; no_mul: ISA has no MUL mul : ISA has [F]MUL[S[U]]
193
194 ;; The following ISA attributes are actually not architecture specific,
195 ;; but depend on (optimization) options. This is because the "enabled"
196 ;; attribut can't depend on more than one other attribute. This means
197 ;; that 3op must work for all ISAs, and hence a 'flat' attribue scheme
198 ;; can be used (as opposed to a true cartesian product).
199
200 ;; 3op : alternative is a 3-operand insn
201
202 (define_attr "isa"
203 "mov,movw, rjmp,jmp, ijmp,eijmp, lpm,lpmx, elpm,elpmx, no_xmega,xmega,
204 no_adiw,adiw, no_mul,mul,
205 3op,
206 standard"
207 (const_string "standard"))
208
209 (define_attr "enabled" ""
210 (if_then_else
211 (ior (eq_attr "isa" "standard")
212
213 (and (eq_attr "isa" "mov")
214 (match_test "!AVR_HAVE_MOVW"))
215
216 (and (eq_attr "isa" "movw")
217 (match_test "AVR_HAVE_MOVW"))
218
219 (and (eq_attr "isa" "rjmp")
220 (match_test "!AVR_HAVE_JMP_CALL"))
221
222 (and (eq_attr "isa" "jmp")
223 (match_test "AVR_HAVE_JMP_CALL"))
224
225 (and (eq_attr "isa" "ijmp")
226 (match_test "!AVR_HAVE_EIJMP_EICALL"))
227
228 (and (eq_attr "isa" "eijmp")
229 (match_test "AVR_HAVE_EIJMP_EICALL"))
230
231 (and (eq_attr "isa" "lpm")
232 (match_test "!AVR_HAVE_LPMX"))
233
234 (and (eq_attr "isa" "lpmx")
235 (match_test "AVR_HAVE_LPMX"))
236
237 (and (eq_attr "isa" "elpm")
238 (match_test "AVR_HAVE_ELPM && !AVR_HAVE_ELPMX"))
239
240 (and (eq_attr "isa" "elpmx")
241 (match_test "AVR_HAVE_ELPMX"))
242
243 (and (eq_attr "isa" "xmega")
244 (match_test "AVR_XMEGA"))
245
246 (and (eq_attr "isa" "no_xmega")
247 (match_test "!AVR_XMEGA"))
248
249 (and (eq_attr "isa" "adiw")
250 (match_test "AVR_HAVE_ADIW"))
251
252 (and (eq_attr "isa" "no_adiw")
253 (match_test "!AVR_HAVE_ADIW"))
254
255 (and (eq_attr "isa" "mul")
256 (match_test "AVR_HAVE_MUL"))
257
258 (and (eq_attr "isa" "no_mul")
259 (match_test "!AVR_HAVE_MUL"))
260
261 (and (eq_attr "isa" "3op")
262 (match_test "avr_shift_is_3op ()"))
263 )
264 (const_int 1)
265 (const_int 0)))
266
267
268 ;; Define mode iterators
269 (define_mode_iterator QIHI [QI HI])
270 (define_mode_iterator QIHI2 [QI HI])
271 (define_mode_iterator QISI [QI HI PSI SI])
272 (define_mode_iterator QISI2 [QI HI PSI SI])
273 (define_mode_iterator QIDI [QI HI PSI SI DI])
274 (define_mode_iterator QIPSI [QI HI PSI])
275 (define_mode_iterator HISI [HI PSI SI])
276 (define_mode_iterator HI_SI [HI SI])
277
278 ;; Ordered integral and fixed-point modes of specific sizes.
279 (define_mode_iterator ALL1 [QI QQ UQQ])
280 (define_mode_iterator ALL2 [HI HQ UHQ HA UHA])
281 (define_mode_iterator ALL4 [SI SQ USQ SA USA])
282 (define_mode_iterator ALL234 [HI SI PSI
283 HQ UHQ HA UHA
284 SQ USQ SA USA])
285
286 ;; Ordered signed integral and signed fixed-point modes of specific sizes.
287 (define_mode_iterator ALLs1 [QI QQ])
288 (define_mode_iterator ALLs2 [HI HQ HA])
289 (define_mode_iterator ALLs4 [SI SQ SA])
290 (define_mode_iterator ALLs234 [HI SI PSI
291 HQ HA SQ SA])
292
293 (define_mode_iterator ALLCC [CC CCN CCZN])
294
295 (define_mode_attr CCname [(CC "") (CCN "_N") (CCZN "_ZN")])
296
297 ;; All supported move-modes
298 (define_mode_iterator MOVMODE [QI QQ UQQ
299 HI HQ UHQ HA UHA
300 SI SQ USQ SA USA
301 SF PSI])
302
303 ;; Supported ordered modes that are 2, 3, 4 bytes wide
304 (define_mode_iterator ORDERED234 [HI SI PSI
305 HQ UHQ HA UHA
306 SQ USQ SA USA])
307
308 ;; Post-reload split of 3, 4 bytes wide moves.
309 (define_mode_iterator SPLIT34 [SI SF PSI
310 SQ USQ SA USA])
311
312 (define_mode_iterator SFDF [SF DF])
313
314 ;; Where the most significant bit is located.
315 (define_mode_attr MSB [(QI "7") (QQ "7") (UQQ "7")
316 (HI "15") (HQ "15") (UHQ "15") (HA "15") (UHA "15")
317 (PSI "23")
318 (SI "31") (SQ "31") (USQ "31") (SA "31") (USA "31")
319 (SF "31")])
320
321 ;; Where the most significant bit is located, as a constraint.
322 (define_mode_attr C_MSB [(QI "C07") (QQ "C07") (UQQ "C07")
323 (HI "C15") (HQ "C15") (UHQ "C15") (HA "C15") (UHA "C15")
324 (PSI "C23")
325 (SI "C31") (SQ "C31") (USQ "C31") (SA "C31") (USA "C31")
326 (SF "C31")])
327
328 ;; Size in bytes of the mode.
329 (define_mode_attr SIZE [(QI "1") (QQ "1") (UQQ "1")
330 (HI "2") (HQ "2") (UHQ "2") (HA "2") (UHA "2")
331 (PSI "3")
332 (SI "4") (SQ "4") (USQ "4") (SA "4") (USA "4") (SF "4")])
333
334 ;; Define code iterators
335 ;; Define two incarnations so that we can build the cartesian product.
336 (define_code_iterator any_extend [sign_extend zero_extend])
337 (define_code_iterator any_extend2 [sign_extend zero_extend])
338 (define_code_iterator any_extract [sign_extract zero_extract])
339 (define_code_iterator any_shiftrt [lshiftrt ashiftrt])
340 (define_code_iterator any_shift [lshiftrt ashiftrt ashift])
341 (define_code_iterator any_lshift [lshiftrt ashift]) ; logic shift
342
343 (define_code_iterator piaop [plus ior and])
344 (define_code_iterator pixop [plus ior xor])
345 (define_code_iterator bitop [xor ior and])
346 (define_code_iterator xior [xor ior])
347 (define_code_iterator eqne [eq ne])
348 (define_code_iterator gelt [ge lt])
349 (define_code_iterator eqnegtle [eq ne gt le])
350 (define_code_iterator cmp_signed [eq ne ge lt gt le])
351 (define_code_iterator op8_ZN [plus minus and ior xor ashift ashiftrt lshiftrt])
352
353 (define_code_iterator ss_addsub [ss_plus ss_minus])
354 (define_code_iterator us_addsub [us_plus us_minus])
355 (define_code_iterator ss_abs_neg [ss_abs ss_neg])
356
357 ;; Define code attributes
358 (define_code_attr extend_su
359 [(sign_extend "s")
360 (zero_extend "u")])
361
362 (define_code_attr extend_u
363 [(sign_extend "")
364 (zero_extend "u")])
365
366 (define_code_attr extend_s
367 [(sign_extend "s")
368 (zero_extend "")])
369
370 ;; Constrain input operand of widening multiply, i.e. MUL resp. MULS.
371 (define_code_attr mul_r_d
372 [(zero_extend "r")
373 (sign_extend "d")])
374
375 (define_code_attr abelian
376 [(ss_minus "") (us_minus "")
377 (ss_plus "%") (us_plus "%")])
378
379 (define_code_attr gelt_eqne
380 [(ge "eq")
381 (lt "ne")])
382
383 ;; Map RTX code to its standard insn name
384 (define_code_attr code_stdname
385 [(ashift "ashl")
386 (ashiftrt "ashr")
387 (lshiftrt "lshr")
388 (ior "ior")
389 (xor "xor")
390 (rotate "rotl")
391 (ss_plus "ssadd") (ss_minus "sssub") (ss_neg "ssneg") (ss_abs "ssabs")
392 (us_plus "usadd") (us_minus "ussub") (us_neg "usneg")
393 ])
394
395 ;;========================================================================
396 ;; The following is used by nonlocal_goto and setjmp.
397 ;; The receiver pattern will create no instructions since internally
398 ;; virtual_stack_vars = hard_frame_pointer + 1 so the RTL become R28=R28
399 ;; This avoids creating add/sub offsets in frame_pointer save/resore.
400 ;; The 'null' receiver also avoids problems with optimisation
401 ;; not recognising incoming jmp and removing code that resets frame_pointer.
402 ;; The code derived from builtins.cc.
403
404 (define_expand "nonlocal_goto_receiver"
405 [(set (reg:HI REG_Y)
406 (unspec_volatile:HI [(const_int 0)] UNSPECV_GOTO_RECEIVER))]
407 ""
408 {
409 rtx offset = gen_int_mode (targetm.starting_frame_offset (), Pmode);
410 emit_move_insn (virtual_stack_vars_rtx,
411 gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, offset));
412 // This might change the hard frame pointer in ways that aren't
413 // apparent to early optimization passes, so force a clobber.
414 emit_clobber (hard_frame_pointer_rtx);
415 DONE;
416 })
417
418
419 ;; Defining nonlocal_goto_receiver means we must also define this
420 ;; even though its function is identical to that in builtins.cc
421
422 (define_expand "nonlocal_goto"
423 [(use (match_operand 0 "general_operand"))
424 (use (match_operand 1 "general_operand"))
425 (use (match_operand 2 "general_operand"))
426 (use (match_operand 3 "general_operand"))]
427 ""
428 {
429 rtx r_label = copy_to_reg (operands[1]);
430 rtx r_fp = operands[3];
431 rtx r_sp = operands[2];
432
433 emit_clobber (gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode)));
434
435 emit_clobber (gen_rtx_MEM (BLKmode, hard_frame_pointer_rtx));
436
437 // PR64242: When r_sp is located in the frame, we must not
438 // change FP prior to reading r_sp. Hence copy r_fp to a
439 // local register (and hope that reload won't spill it).
440 rtx r_fp_reg = copy_to_reg (r_fp);
441 emit_stack_restore (SAVE_NONLOCAL, r_sp);
442
443 emit_move_insn (hard_frame_pointer_rtx, r_fp_reg);
444
445 emit_use (hard_frame_pointer_rtx);
446 emit_use (stack_pointer_rtx);
447
448 emit_indirect_jump (r_label);
449
450 DONE;
451 })
452
453 ;; "pushqi1"
454 ;; "pushqq1" "pushuqq1"
455 (define_insn "push<mode>1"
456 [(set (mem:ALL1 (post_dec:HI (reg:HI REG_SP)))
457 (match_operand:ALL1 0 "reg_or_0_operand" "r,Y00"))]
458 ""
459 "@
460 push %0
461 push __zero_reg__"
462 [(set_attr "length" "1,1")])
463
464 (define_insn "pushhi1_insn"
465 [(set (mem:HI (post_dec:HI (reg:HI REG_SP)))
466 (match_operand:HI 0 "reg_or_0_operand" "r,Y00"))]
467 ""
468 "@
469 push %B0\;push %A0
470 push __zero_reg__\;push __zero_reg__"
471 [(set_attr "length" "2")])
472
473 ;; All modes for a multi-byte push. We must include complex modes here too,
474 ;; lest emit_single_push_insn "helpfully" create the auto-inc itself.
475 (define_mode_iterator MPUSH
476 [CQI
477 HI CHI HA UHA HQ UHQ
478 SI CSI SA USA SQ USQ
479 DI CDI DA UDA DQ UDQ
480 TA UTA
481 SF DF SC DC
482 PSI])
483
484 (define_expand "push<mode>1"
485 [(match_operand:MPUSH 0 "" "")]
486 ""
487 {
488 if (MEM_P (operands[0])
489 && !ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (operands[0])))
490 {
491 // Avoid (subreg (mem)) for non-generic address spaces. Because
492 // of the poor addressing capabilities of these spaces it's better to
493 // load them in one chunk. And it avoids PR61443.
494
495 operands[0] = copy_to_mode_reg (<MODE>mode, operands[0]);
496 }
497 else if (REG_P (operands[0])
498 && VIRTUAL_REGISTER_P (operands[0]))
499 {
500 // Byte-wise pushing of virtual regs might result in something like
501 //
502 // (set (mem:QI (post_dec:HI (reg:HI 32 SP)))
503 // (subreg:QI (plus:HI (reg:HI 28)
504 // (const_int 17)) 0))
505 //
506 // after elimination. This cannot be handled by reload, cf. PR64452.
507 // Reload virtuals in one chunk. That way it's possible to reload
508 // above situation and finally
509 //
510 // (set (reg:HI **)
511 // (const_int 17))
512 // (set (reg:HI **)
513 // (plus:HI (reg:HI **)
514 // (reg:HI 28)))
515 // (set (mem:HI (post_dec:HI (reg:HI 32 SP))
516 // (reg:HI **)))
517
518 emit_insn (gen_pushhi1_insn (operands[0]));
519 DONE;
520 }
521
522 for (int i = GET_MODE_SIZE (<MODE>mode) - 1; i >= 0; --i)
523 {
524 rtx part = simplify_gen_subreg (QImode, operands[0], <MODE>mode, i);
525 if (part != const0_rtx)
526 part = force_reg (QImode, part);
527 emit_insn (gen_pushqi1 (part));
528 }
529 DONE;
530 })
531
532 ;; Notice a special-case when adding N to SP where N results in a
533 ;; zero REG_ARGS_SIZE. This is equivalent to a move from FP.
534 (define_split
535 [(set (reg:HI REG_SP)
536 (match_operand:HI 0 "register_operand" ""))]
537 "reload_completed
538 && frame_pointer_needed
539 && !cfun->calls_alloca
540 && find_reg_note (insn, REG_ARGS_SIZE, const0_rtx)
541 && REGNO (operands[0]) != REG_Y"
542 [(set (reg:HI REG_SP)
543 (reg:HI REG_Y))])
544
545 ;;========================================================================
546 ;; Move stuff around
547
548 ;; Expand helper for mov<mode>.
549 (define_expand "gen_load<mode>_libgcc"
550 [(set (match_dup 3)
551 (match_dup 2))
552 (set (reg:MOVMODE 22)
553 (match_operand:MOVMODE 1 "memory_operand"))
554 (set (match_operand:MOVMODE 0 "register_operand")
555 (reg:MOVMODE 22))]
556 "avr_load_libgcc_p (operands[1])"
557 {
558 operands[3] = gen_rtx_REG (HImode, REG_Z);
559 operands[2] = force_operand (XEXP (operands[1], 0), NULL_RTX);
560 operands[1] = replace_equiv_address (operands[1], operands[3]);
561 set_mem_addr_space (operands[1], ADDR_SPACE_FLASH);
562 })
563
564 ;; "load_qi_libgcc"
565 ;; "load_hi_libgcc"
566 ;; "load_psi_libgcc"
567 ;; "load_si_libgcc"
568 ;; "load_sf_libgcc"
569 (define_insn_and_split "load_<mode>_libgcc"
570 [(set (reg:MOVMODE 22)
571 (match_operand:MOVMODE 0 "memory_operand" "m"))]
572 "avr_load_libgcc_p (operands[0])
573 && REG_P (XEXP (operands[0], 0))
574 && REG_Z == REGNO (XEXP (operands[0], 0))"
575 "#"
576 "&& reload_completed"
577 [(parallel [(set (reg:MOVMODE 22)
578 (match_dup 0))
579 (clobber (reg:CC REG_CC))])])
580
581 (define_insn "*load_<mode>_libgcc"
582 [(set (reg:MOVMODE 22)
583 (match_operand:MOVMODE 0 "memory_operand" "m"))
584 (clobber (reg:CC REG_CC))]
585 "avr_load_libgcc_p (operands[0])
586 && REG_P (XEXP (operands[0], 0))
587 && REG_Z == REGNO (XEXP (operands[0], 0))
588 && reload_completed"
589 "%~call __load_<SIZE>"
590 [(set_attr "type" "xcall")])
591
592
593 ;; Inline load a __memx value when flash <= 64 KiB, or
594 ;; inline load a __flashx value.
595 (define_insn_and_split "fxmov<mode>_A"
596 [(set (match_operand:MOVMODE 0 "register_operand" "=r")
597 (match_operand:MOVMODE 1 "memory_operand" "m"))
598 (clobber (reg:HI REG_Z))]
599 "can_create_pseudo_p()
600 && REG_P (XEXP (operands[1], 0))
601 && (avr_load_libgcc_insn_p (insn, ADDR_SPACE_MEMX, false)
602 || avr_load_libgcc_insn_p (insn, ADDR_SPACE_FLASHX, false))"
603 { gcc_unreachable(); }
604 "&& 1"
605 [(scratch)]
606 {
607 // Split away the high part of the address. GCC's register allocator
608 // is not able to allocate segment registers and reload the resulting
609 // expressions. Notice that no address register can hold a PSImode.
610
611 addr_space_t as = MEM_ADDR_SPACE (operands[1]);
612 rtx addr = XEXP (operands[1], 0);
613 rtx hi8 = gen_reg_rtx (QImode);
614 rtx reg_z = gen_rtx_REG (HImode, REG_Z);
615
616 emit_move_insn (reg_z, simplify_gen_subreg (HImode, addr, PSImode, 0));
617 emit_move_insn (hi8, simplify_gen_subreg (QImode, addr, PSImode, 2));
618
619 rtx_insn *insn;
620 if (as == ADDR_SPACE_MEMX)
621 insn = emit_insn (gen_xmov<mode>_8 (operands[0], hi8));
622 else if (as == ADDR_SPACE_FLASHX)
623 insn = emit_insn (gen_fmov<mode> (operands[0], hi8));
624 else
625 gcc_unreachable ();
626
627 set_mem_addr_space (SET_SRC (single_set (insn)), as);
628 DONE;
629 })
630
631 ;; Move value from address space memx or flashx to a register
632 ;; These insns must be prior to respective generic move insn.
633
634 ;; "xmovqi_8"
635 ;; "xmovqq_8" "xmovuqq_8"
636 (define_insn "xmov<mode>_8"
637 [(set (match_operand:MOVMODE 0 "register_operand" "=&r,r")
638 (mem:MOVMODE (lo_sum:PSI (match_operand:QI 1 "register_operand" "r,r")
639 (reg:HI REG_Z))))]
640 "<SIZE> == 1
641 && avr_load_libgcc_insn_p (insn, ADDR_SPACE_MEMX, false)"
642 {
643 return avr_out_xload (insn, operands, NULL);
644 }
645 [(set_attr "length" "4,4")
646 (set_attr "adjust_len" "*,xload")
647 (set_attr "isa" "lpmx,lpm")])
648
649 ;; Load a value from __flashx inline.
650 (define_insn "fmov<mode>"
651 [(set (match_operand:MOVMODE 0 "register_operand" "=r")
652 (mem:MOVMODE (lo_sum:PSI (match_operand:QI 1 "register_operand" "r")
653 (reg:HI REG_Z))))
654 (clobber (reg:HI REG_Z))]
655 "avr_load_libgcc_insn_p (insn, ADDR_SPACE_FLASHX, false)"
656 {
657 return avr_out_fload (insn, operands, NULL);
658 }
659 [(set_attr "adjust_len" "fload")])
660
661
662 ;; Load a __memx or __flashx value per libgcc call.
663 ;; "fxloadqi_A" "fxloadqq_A" "fxloaduqq_A"
664 ;; "fxloadhi_A" "fxloadhq_A" "fxloaduhq_A" "fxloadha_A" "fxloaduha_A"
665 ;; "fxloadsi_A" "fxloadsq_A" "fxloadusq_A" "fxloadsa_A" "fxloadusa_A"
666 ;; "fxloadpsi_A"
667 ;; "fxloadsf_A"
668 (define_insn_and_split "fxload<mode>_A"
669 [(set (match_operand:MOVMODE 0 "register_operand" "=r")
670 (match_operand:MOVMODE 1 "memory_operand" "m"))
671 (clobber (reg:MOVMODE REG_22))
672 (clobber (reg:QI REG_21))
673 (clobber (reg:HI REG_Z))]
674 "can_create_pseudo_p()
675 && REG_P (XEXP (operands[1], 0))
676 && (avr_load_libgcc_insn_p (insn, ADDR_SPACE_MEMX, true)
677 || avr_load_libgcc_insn_p (insn, ADDR_SPACE_FLASHX, true))"
678 { gcc_unreachable(); }
679 "&& 1"
680 [(scratch)]
681 {
682 rtx addr = XEXP (operands[1], 0);
683 rtx reg_z = gen_rtx_REG (HImode, REG_Z);
684 rtx addr_hi8 = simplify_gen_subreg (QImode, addr, PSImode, 2);
685 addr_space_t as = MEM_ADDR_SPACE (operands[1]);
686
687 // Split the address to R21:Z
688 emit_move_insn (reg_z, simplify_gen_subreg (HImode, addr, PSImode, 0));
689 emit_move_insn (gen_rtx_REG (QImode, REG_21), addr_hi8);
690
691 // Load with code from libgcc.
692 rtx_insn *insn = emit_insn (gen_fxload_<mode>_libgcc ());
693 set_mem_addr_space (SET_SRC (single_set (insn)), as);
694
695 // Move to destination.
696 emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, REG_22));
697
698 DONE;
699 })
700
701 ;; R21:Z : 24-bit source address
702 ;; R22 : 1-4 byte output
703
704 ;; "fxload_qi_libgcc" "fxload_qq_libgcc" "fxload_uqq_libgcc"
705 ;; "fxload_hi_libgcc" "fxload_hq_libgcc" "fxload_uhq_libgcc" "fxload_ha_libgcc" "xload_uha_libgcc"
706 ;; "fxload_si_libgcc" "fxload_sq_libgcc" "fxload_usq_libgcc" "fxload_sa_libgcc" "xload_usa_libgcc"
707 ;; "fxload_sf_libgcc"
708 ;; "fxload_psi_libgcc"
709 (define_insn_and_split "fxload_<mode>_libgcc"
710 [(set (reg:MOVMODE REG_22)
711 (mem:MOVMODE (lo_sum:PSI (reg:QI REG_21)
712 (reg:HI REG_Z))))
713 (clobber (reg:QI REG_21))
714 (clobber (reg:HI REG_Z))]
715 "avr_load_libgcc_insn_p (insn, ADDR_SPACE_MEMX, true)
716 || avr_load_libgcc_insn_p (insn, ADDR_SPACE_FLASHX, true)"
717 "#"
718 "&& reload_completed"
719 [(parallel [(set (reg:MOVMODE REG_22)
720 (match_dup 0))
721 (clobber (reg:QI REG_21))
722 (clobber (reg:HI REG_Z))
723 (clobber (reg:CC REG_CC))])]
724 {
725 operands[0] = SET_SRC (single_set (curr_insn));
726 })
727
728 (define_insn "*fxload_<mode>_libgcc"
729 [(set (reg:MOVMODE REG_22)
730 (mem:MOVMODE (lo_sum:PSI (reg:QI REG_21)
731 (reg:HI REG_Z))))
732 (clobber (reg:QI REG_21))
733 (clobber (reg:HI REG_Z))
734 (clobber (reg:CC REG_CC))]
735 "reload_completed
736 && (avr_load_libgcc_insn_p (insn, ADDR_SPACE_MEMX, true)
737 || avr_load_libgcc_insn_p (insn, ADDR_SPACE_FLASHX, true))"
738 {
739 rtx src = SET_SRC (single_set (insn));
740 return avr_mem_memx_p (src)
741 ? "%~call __xload_<SIZE>"
742 : "%~call __fload_<SIZE>";
743 }
744 [(set_attr "type" "xcall")])
745
746
747 ;; General move expanders
748
749 ;; "movqi" "movqq" "movuqq"
750 ;; "movhi" "movhq" "movuhq" "movha" "movuha"
751 ;; "movsi" "movsq" "movusq" "movsa" "movusa"
752 ;; "movsf"
753 ;; "movpsi"
754 (define_expand "mov<mode>"
755 [(set (match_operand:MOVMODE 0 "nonimmediate_operand")
756 (match_operand:MOVMODE 1 "general_operand"))]
757 ""
758 {
759 rtx dest = operands[0];
760 rtx src = avr_eval_addr_attrib (operands[1]);
761
762 if (avr_mem_flash_p (dest))
763 DONE;
764
765 if (QImode == <MODE>mode
766 && SUBREG_P (src)
767 && CONSTANT_ADDRESS_P (SUBREG_REG (src))
768 && can_create_pseudo_p())
769 {
770 // store_bitfield may want to store a SYMBOL_REF or CONST in a
771 // structure that's represented as PSImode. As the upper 16 bits
772 // of PSImode cannot be expressed as an HImode subreg, the rhs is
773 // decomposed into QImode (word_mode) subregs of SYMBOL_REF,
774 // CONST or LABEL_REF; cf. PR71103.
775
776 rtx const_addr = SUBREG_REG (src);
777 operands[1] = src = copy_rtx (src);
778 SUBREG_REG (src) = copy_to_mode_reg (GET_MODE (const_addr), const_addr);
779 }
780
781 // One of the operands has to be in a register.
782 if (!register_operand (dest, <MODE>mode)
783 && !reg_or_0_operand (src, <MODE>mode))
784 {
785 operands[1] = src = copy_to_mode_reg (<MODE>mode, src);
786 }
787
788 // Let __flashx decay to __flash on devices <= 64 KiB.
789 if (avr_mem_flashx_p (src)
790 && ! AVR_HAVE_ELPM)
791 {
792 rtx addr = XEXP (src, 0);
793 addr = copy_to_mode_reg (Pmode, avr_word (addr, 0));
794 // replace_equiv_address() hickupps, so do it by hand.
795 operands[1] = src = gen_rtx_MEM (<MODE>mode, addr);
796 set_mem_addr_space (src, ADDR_SPACE_FLASH);
797 }
798
799 if (avr_mem_memx_p (src)
800 || avr_mem_flashx_p (src))
801 {
802 rtx addr = XEXP (src, 0);
803
804 if (!REG_P (addr))
805 src = replace_equiv_address (src, copy_to_mode_reg (PSImode, addr));
806
807 rtx dest2 = reg_overlap_mentioned_p (dest, lpm_addr_reg_rtx)
808 ? gen_reg_rtx (<MODE>mode)
809 : dest;
810
811 if (avr_load_libgcc_mem_p (src, ADDR_SPACE_MEMX, false)
812 || avr_load_libgcc_mem_p (src, ADDR_SPACE_FLASHX, false))
813 {
814 emit_insn (gen_fxmov<mode>_A (dest2, src));
815 }
816 else
817 {
818 rtx reg_22 = gen_rtx_REG (<MODE>mode, REG_22);
819 if (reg_overlap_mentioned_p (dest2, reg_22)
820 || reg_overlap_mentioned_p (dest2, all_regs_rtx[REG_21]))
821 dest2 = gen_reg_rtx (<MODE>mode);
822
823 emit_insn (gen_fxload<mode>_A (dest2, src));
824 }
825
826 if (dest2 != dest)
827 emit_move_insn (dest, dest2);
828
829 DONE;
830 }
831
832 if (avr_load_libgcc_p (src))
833 {
834 // For the small devices, do loads per libgcc call.
835 emit_insn (gen_gen_load<mode>_libgcc (dest, src));
836 DONE;
837 }
838 })
839
840 ;;========================================================================
841 ;; move byte
842 ;; The last alternative (any immediate constant to any register) is
843 ;; very expensive. It should be optimized by peephole2 if a scratch
844 ;; register is available, but then that register could just as well be
845 ;; allocated for the variable we are loading. But, most of NO_LD_REGS
846 ;; are call-saved registers, and most of LD_REGS are call-used registers,
847 ;; so this may still be a win for registers live across function calls.
848
849 (define_insn_and_split "mov<mode>_insn_split"
850 [(set (match_operand:ALL1 0 "nonimmediate_operand" "=r ,d ,Qm ,r ,q,r,*r")
851 (match_operand:ALL1 1 "nox_general_operand" "r Y00,n Ynn,r Y00,Qm,r,q,i"))]
852 "register_operand (operands[0], <MODE>mode)
853 || reg_or_0_operand (operands[1], <MODE>mode)"
854 "#"
855 "&& reload_completed"
856 [(parallel [(set (match_dup 0)
857 (match_dup 1))
858 (clobber (reg:CC REG_CC))])])
859
860 ;; "movqi_insn"
861 ;; "movqq_insn" "movuqq_insn"
862 (define_insn "mov<mode>_insn"
863 [(set (match_operand:ALL1 0 "nonimmediate_operand" "=r ,d ,Qm ,r ,q,r,*r")
864 (match_operand:ALL1 1 "nox_general_operand" "r Y00,n Ynn,r Y00,Qm,r,q,i"))
865 (clobber (reg:CC REG_CC))]
866 "(register_operand (operands[0], <MODE>mode)
867 || reg_or_0_operand (operands[1], <MODE>mode))
868 && reload_completed"
869 {
870 return output_movqi (insn, operands, NULL);
871 }
872 [(set_attr "length" "1,1,5,5,1,1,4")
873 (set_attr "adjust_len" "mov8")])
874
875 ;; This is used in peephole2 to optimize loading immediate constants
876 ;; if a scratch register from LD_REGS happens to be available.
877
878 ;; "*reload_inqi"
879 ;; "*reload_inqq" "*reload_inuqq"
880 (define_insn "*reload_in<mode>"
881 [(set (match_operand:ALL1 0 "register_operand" "=l")
882 (match_operand:ALL1 1 "const_operand" "i"))
883 (clobber (match_operand:QI 2 "register_operand" "=&d"))
884 (clobber (reg:CC REG_CC))]
885 "reload_completed"
886 "ldi %2,lo8(%1)
887 mov %0,%2"
888 [(set_attr "length" "2")])
889
890 (define_peephole2
891 [(match_scratch:QI 2 "d")
892 (parallel [(set (match_operand:ALL1 0 "l_register_operand" "")
893 (match_operand:ALL1 1 "const_operand" ""))
894 (clobber (reg:CC REG_CC))])]
895 ; No need for a clobber reg for 0x0, 0x01 or 0xff
896 "!satisfies_constraint_Y00 (operands[1])
897 && !satisfies_constraint_Y01 (operands[1])
898 && !satisfies_constraint_Ym1 (operands[1])"
899 [(parallel [(set (match_dup 0)
900 (match_dup 1))
901 (clobber (match_dup 2))
902 (clobber (reg:CC REG_CC))])])
903
904 ;;============================================================================
905 ;; move word (16 bit)
906
907 ;; Move register $1 to the Stack Pointer register SP.
908 ;; This insn is emit during function prologue/epilogue generation.
909 ;; $2 = 0: We know that IRQs are off
910 ;; $2 = 1: We know that IRQs are on
911 ;; $2 = 2: SP has 8 bits only, IRQ state does not matter
912 ;; $2 = -1: We don't know anything about IRQ on/off
913 ;; Always write SP via unspec, see PR50063
914
915 (define_insn "movhi_sp_r"
916 [(set (match_operand:HI 0 "stack_register_operand" "=q,q,q,q,q")
917 (unspec_volatile:HI [(match_operand:HI 1 "register_operand" "r,r,r,r,r")
918 (match_operand:HI 2 "const_int_operand" "L,P,N,K,LPN")]
919 UNSPECV_WRITE_SP))]
920 ""
921 "@
922 out %B0,%B1\;out %A0,%A1
923 cli\;out %B0,%B1\;sei\;out %A0,%A1
924 in __tmp_reg__,__SREG__\;cli\;out %B0,%B1\;out __SREG__,__tmp_reg__\;out %A0,%A1
925 out %A0,%A1
926 out %A0,%A1\;out %B0,%B1"
927 [(set_attr "length" "2,4,5,1,2")
928 (set_attr "isa" "no_xmega,no_xmega,no_xmega,*,xmega")])
929
930 (define_peephole2
931 [(match_scratch:QI 2 "d")
932 (parallel [(set (match_operand:ALL2 0 "l_register_operand" "")
933 (match_operand:ALL2 1 "const_or_immediate_operand" ""))
934 (clobber (reg:CC REG_CC))])]
935 "operands[1] != CONST0_RTX (<MODE>mode)"
936 [(parallel [(set (match_dup 0)
937 (match_dup 1))
938 (clobber (match_dup 2))
939 (clobber (reg:CC REG_CC))])])
940
941 ;; '*' because it is not used in rtl generation, only in above peephole
942 ;; "*reload_inhi"
943 ;; "*reload_inhq" "*reload_inuhq"
944 ;; "*reload_inha" "*reload_inuha"
945 (define_insn "*reload_in<mode>"
946 [(set (match_operand:ALL2 0 "l_register_operand" "=l")
947 (match_operand:ALL2 1 "immediate_operand" "i"))
948 (clobber (match_operand:QI 2 "register_operand" "=&d"))
949 (clobber (reg:CC REG_CC))]
950 "reload_completed"
951 {
952 return output_reload_inhi (operands, operands[2], NULL);
953 }
954 [(set_attr "length" "4")
955 (set_attr "adjust_len" "reload_in16")])
956
957 ;; "*movhi"
958 ;; "*movhq" "*movuhq"
959 ;; "*movha" "*movuha"
960 (define_insn_and_split "*mov<mode>_split"
961 [(set (match_operand:ALL2 0 "nonimmediate_operand" "=r,r ,r,m ,d,*r,q,r")
962 (match_operand:ALL2 1 "nox_general_operand" "r,Y00,m,r Y00,i,i ,r,q"))]
963 "register_operand (operands[0], <MODE>mode)
964 || reg_or_0_operand (operands[1], <MODE>mode)"
965 "#"
966 "&& reload_completed"
967 [(parallel [(set (match_dup 0)
968 (match_dup 1))
969 (clobber (reg:CC REG_CC))])])
970
971 (define_insn "*mov<mode>"
972 [(set (match_operand:ALL2 0 "nonimmediate_operand" "=r,r ,r,m ,d,*r,q,r")
973 (match_operand:ALL2 1 "nox_general_operand" "r,Y00,m,r Y00,i,i ,r,q"))
974 (clobber (reg:CC REG_CC))]
975 "(register_operand (operands[0], <MODE>mode)
976 || reg_or_0_operand (operands[1], <MODE>mode))
977 && reload_completed"
978 {
979 return output_movhi (insn, operands, NULL);
980 }
981 [(set_attr "length" "2,2,6,7,2,6,5,2")
982 (set_attr "adjust_len" "mov16")])
983
984 (define_peephole2 ; movw
985 [(parallel [(set (match_operand:ALL1 0 "even_register_operand" "")
986 (match_operand:ALL1 1 "even_register_operand" ""))
987 (clobber (reg:CC REG_CC))])
988 (parallel [(set (match_operand:ALL1 2 "odd_register_operand" "")
989 (match_operand:ALL1 3 "odd_register_operand" ""))
990 (clobber (reg:CC REG_CC))])]
991 "AVR_HAVE_MOVW
992 && REGNO (operands[0]) == REGNO (operands[2]) - 1
993 && REGNO (operands[1]) == REGNO (operands[3]) - 1"
994 [(parallel [(set (match_dup 4)
995 (match_dup 5))
996 (clobber (reg:CC REG_CC))])]
997 {
998 operands[4] = gen_rtx_REG (HImode, REGNO (operands[0]));
999 operands[5] = gen_rtx_REG (HImode, REGNO (operands[1]));
1000 })
1001
1002 (define_peephole2 ; movw_r
1003 [(parallel [(set (match_operand:ALL1 0 "odd_register_operand" "")
1004 (match_operand:ALL1 1 "odd_register_operand" ""))
1005 (clobber (reg:CC REG_CC))])
1006 (parallel [(set (match_operand:ALL1 2 "even_register_operand" "")
1007 (match_operand:ALL1 3 "even_register_operand" ""))
1008 (clobber (reg:CC REG_CC))])]
1009 "AVR_HAVE_MOVW
1010 && REGNO (operands[2]) == REGNO (operands[0]) - 1
1011 && REGNO (operands[3]) == REGNO (operands[1]) - 1"
1012 [(parallel [(set (match_dup 4)
1013 (match_dup 5))
1014 (clobber (reg:CC REG_CC))])]
1015 {
1016 operands[4] = gen_rtx_REG (HImode, REGNO (operands[2]));
1017 operands[5] = gen_rtx_REG (HImode, REGNO (operands[3]));
1018 })
1019
1020
1021 ;; Register alloc may expand a 3-operand arithmetic X = Y o CST as
1022 ;; X = CST
1023 ;; X o= Y
1024 ;; where it may be better to instead:
1025 ;; X = Y
1026 ;; X o= CST
1027 ;; because 1) the first insn may use MOVW for "X = Y", and 2) the
1028 ;; operation may be more efficient when performed with a constant,
1029 ;; for example when ADIW or SBIW can be used, or some bytes of
1030 ;; the constant are 0x00 or 0xff.
1031 (define_peephole2
1032 [(parallel [(set (match_operand:HISI 0 "d_register_operand")
1033 (match_operand:HISI 1 "const_int_operand"))
1034 (clobber (reg:CC REG_CC))])
1035 (parallel [(set (match_dup 0)
1036 (piaop:HISI (match_dup 0)
1037 (match_operand:HISI 2 "register_operand")))
1038 (clobber (scratch:QI))
1039 (clobber (reg:CC REG_CC))])]
1040 "! reg_overlap_mentioned_p (operands[0], operands[2])"
1041 [(parallel [(set (match_dup 0)
1042 (match_dup 2))
1043 (clobber (reg:CC REG_CC))])
1044 (parallel [(set (match_dup 0)
1045 (piaop:HISI (match_dup 0)
1046 (match_dup 1)))
1047 (clobber (scratch:QI))
1048 (clobber (reg:CC REG_CC))])])
1049
1050 ;; Same, but just for plus:HI without a scratch:QI.
1051 (define_peephole2
1052 [(parallel [(set (match_operand:HI 0 "d_register_operand")
1053 (match_operand:HI 1 "const_int_operand"))
1054 (clobber (reg:CC REG_CC))])
1055 (parallel [(set (match_dup 0)
1056 (plus:HI (match_dup 0)
1057 (match_operand:HI 2 "register_operand")))
1058 (clobber (reg:CC REG_CC))])]
1059 "! reg_overlap_mentioned_p (operands[0], operands[2])"
1060 [(parallel [(set (match_dup 0)
1061 (match_dup 2))
1062 (clobber (reg:CC REG_CC))])
1063 (parallel [(set (match_dup 0)
1064 (plus:HI (match_dup 0)
1065 (match_dup 1)))
1066 (clobber (reg:CC REG_CC))])])
1067
1068
1069 ;; Legitimate address and stuff allows way more addressing modes than
1070 ;; Reduced Tiny actually supports. Split them now so that we get
1071 ;; closer to real instructions which may result in some optimization
1072 ;; opportunities. This applies also to fake X + offset addressing.
1073 (define_split
1074 [(parallel [(set (match_operand:MOVMODE 0 "nonimmediate_operand")
1075 (match_operand:MOVMODE 1 "general_operand"))
1076 (clobber (reg:CC REG_CC))])]
1077 "reload_completed
1078 && (MEM_P (operands[0]) || MEM_P (operands[1]))"
1079 [(scratch)]
1080 {
1081 if (avropt_fuse_add > 0
1082 // Only split fake addressing for .split2 when we are before
1083 // pass .avr-fuse-add (which runs after proep).
1084 && ! epilogue_completed
1085 && avr_split_fake_addressing_move (curr_insn, operands))
1086 DONE;
1087
1088 // Splitting multi-byte load / stores into 1-byte such insns
1089 // provided non-volatile, addr-space = generic, no reg-overlap
1090 // and the resulting addressings are natively supported.
1091 if (avropt_split_ldst
1092 // Splitting too early may obfuscate some PRE_DEC / POST_INC
1093 // opportunities, thus only split after avr-fuse-add.
1094 && n_avr_fuse_add_executed > 0
1095 && GET_MODE_SIZE (<MODE>mode) > 1
1096 && avr_split_ldst (operands))
1097 DONE;
1098
1099 FAIL;
1100 })
1101
1102
1103 ;;==========================================================================
1104 ;; xpointer move (24 bit)
1105
1106 (define_peephole2 ; *reload_inpsi
1107 [(match_scratch:QI 2 "d")
1108 (parallel [(set (match_operand:PSI 0 "l_register_operand" "")
1109 (match_operand:PSI 1 "immediate_operand" ""))
1110 (clobber (reg:CC REG_CC))])
1111 (match_dup 2)]
1112 "operands[1] != const0_rtx
1113 && operands[1] != constm1_rtx"
1114 [(parallel [(set (match_dup 0)
1115 (match_dup 1))
1116 (clobber (match_dup 2))
1117 (clobber (reg:CC REG_CC))])])
1118
1119 ;; '*' because it is not used in rtl generation.
1120 (define_insn "*reload_inpsi"
1121 [(set (match_operand:PSI 0 "register_operand" "=r")
1122 (match_operand:PSI 1 "immediate_operand" "i"))
1123 (clobber (match_operand:QI 2 "register_operand" "=&d"))
1124 (clobber (reg:CC REG_CC))]
1125 "reload_completed"
1126 {
1127 return avr_out_reload_inpsi (operands, operands[2], NULL);
1128 }
1129 [(set_attr "length" "6")
1130 (set_attr "adjust_len" "reload_in24")])
1131
1132 (define_insn_and_split "*movpsi_split"
1133 [(set (match_operand:PSI 0 "nonimmediate_operand" "=r,r,r ,Qm,!d,r")
1134 (match_operand:PSI 1 "nox_general_operand" "r,L,Qm,rL,i ,i"))]
1135 "register_operand (operands[0], PSImode)
1136 || register_operand (operands[1], PSImode)
1137 || const0_rtx == operands[1]"
1138 "#"
1139 "&& reload_completed"
1140 [(parallel [(set (match_dup 0)
1141 (match_dup 1))
1142 (clobber (reg:CC REG_CC))])])
1143
1144 (define_insn "*movpsi"
1145 [(set (match_operand:PSI 0 "nonimmediate_operand" "=r,r,r ,Qm,!d,r")
1146 (match_operand:PSI 1 "nox_general_operand" "r,L,Qm,rL,i ,i"))
1147 (clobber (reg:CC REG_CC))]
1148 "(register_operand (operands[0], PSImode)
1149 || register_operand (operands[1], PSImode)
1150 || const0_rtx == operands[1])
1151 && reload_completed"
1152 {
1153 return avr_out_movpsi (insn, operands, NULL);
1154 }
1155 [(set_attr "length" "3,3,8,9,4,10")
1156 (set_attr "adjust_len" "mov24")])
1157
1158 ;;==========================================================================
1159 ;; move double word (32 bit)
1160
1161 (define_peephole2 ; *reload_insi
1162 [(match_scratch:QI 2 "d")
1163 (parallel [(set (match_operand:ALL4 0 "l_register_operand" "")
1164 (match_operand:ALL4 1 "immediate_operand" ""))
1165 (clobber (reg:CC REG_CC))])
1166 (match_dup 2)]
1167 "operands[1] != CONST0_RTX (<MODE>mode)"
1168 [(parallel [(set (match_dup 0)
1169 (match_dup 1))
1170 (clobber (match_dup 2))
1171 (clobber (reg:CC REG_CC))])])
1172
1173 ;; '*' because it is not used in rtl generation.
1174 ;; "*reload_insi"
1175 ;; "*reload_insq" "*reload_inusq"
1176 ;; "*reload_insa" "*reload_inusa"
1177 (define_insn "*reload_insi"
1178 [(set (match_operand:ALL4 0 "register_operand" "=r")
1179 (match_operand:ALL4 1 "immediate_operand" "n Ynn"))
1180 (clobber (match_operand:QI 2 "register_operand" "=&d"))
1181 (clobber (reg:CC REG_CC))]
1182 "reload_completed"
1183 {
1184 return output_reload_insisf (operands, operands[2], NULL);
1185 }
1186 [(set_attr "length" "8")
1187 (set_attr "adjust_len" "reload_in32")])
1188
1189
1190 ;; "*movsi"
1191 ;; "*movsq" "*movusq"
1192 ;; "*movsa" "*movusa"
1193 (define_insn_and_split "*mov<mode>_split"
1194 [(set (match_operand:ALL4 0 "nonimmediate_operand" "=r,r ,r ,Qm ,!d,r")
1195 (match_operand:ALL4 1 "nox_general_operand" "r,Y00,Qm,r Y00,i ,i"))]
1196 "register_operand (operands[0], <MODE>mode)
1197 || reg_or_0_operand (operands[1], <MODE>mode)"
1198 "#"
1199 "&& reload_completed"
1200 [(parallel [(set (match_dup 0)
1201 (match_dup 1))
1202 (clobber (reg:CC REG_CC))])])
1203
1204 (define_insn "*mov<mode>"
1205 [(set (match_operand:ALL4 0 "nonimmediate_operand" "=r,r ,r ,Qm ,!d,r")
1206 (match_operand:ALL4 1 "nox_general_operand" "r,Y00,Qm,r Y00,i ,i"))
1207 (clobber (reg:CC REG_CC))]
1208 "(register_operand (operands[0], <MODE>mode)
1209 || reg_or_0_operand (operands[1], <MODE>mode))
1210 && reload_completed"
1211 {
1212 return output_movsisf (insn, operands, NULL);
1213 }
1214 [(set_attr "length" "4,4,8,9,4,10")
1215 (set_attr "adjust_len" "mov32")])
1216
1217 ;; Setting just some bytes of a register when some of them are already known.
1218 ;; This is only needed for the lower regs, and when there is no scratch reg.
1219 (define_insn "set_some"
1220 [(match_parallel 0 "set_some_operation"
1221 [(use (match_operand:QI 1 "dreg_or_0_operand" "d Y00")) ; known d-reg or 0
1222 (use (match_operand:QI 2 "const_int_operand" "n")) ; known value of $1
1223 (use (match_operand:QI 3 "const_int_operand" "n")) ; regno
1224 (use (match_operand:QI 4 "const_int_operand" "n")) ; mode size of $3
1225 (clobber (reg:CC REG_CC))
1226 ;; 1...4 of these.
1227 (set (match_operand:QI 5 "register_operand" "=r")
1228 (match_operand:QI 6 "const_int_operand" "n"))])]
1229 "reload_completed"
1230 {
1231 return avr_out_set_some (insn, operands, nullptr);
1232 }
1233 [(set (attr "length")
1234 (symbol_ref "2 + 2 * (XVECLEN (operands[0], 0) - 5)"))
1235 (set_attr "adjust_len" "set_some")])
1236
1237
1238 ;; fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
1239 ;; move floating point numbers (32 bit)
1240
1241 (define_insn_and_split "*movsf_split"
1242 [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,r ,Qm,!d,r")
1243 (match_operand:SF 1 "nox_general_operand" "r,G,Qm,rG,F ,F"))]
1244 "register_operand (operands[0], SFmode)
1245 || reg_or_0_operand (operands[1], SFmode)"
1246 "#"
1247 "&& reload_completed"
1248 [(parallel [(set (match_dup 0)
1249 (match_dup 1))
1250 (clobber (reg:CC REG_CC))])])
1251
1252 (define_insn "*movsf"
1253 [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,r ,Qm,!d,r")
1254 (match_operand:SF 1 "nox_general_operand" "r,G,Qm,rG,F ,F"))
1255 (clobber (reg:CC REG_CC))]
1256 "(register_operand (operands[0], SFmode)
1257 || reg_or_0_operand (operands[1], SFmode))
1258 && reload_completed"
1259 {
1260 return output_movsisf (insn, operands, NULL);
1261 }
1262 [(set_attr "length" "4,4,8,9,4,10")
1263 (set_attr "adjust_len" "mov32")])
1264
1265 (define_peephole2 ; *reload_insf
1266 [(match_scratch:QI 2 "d")
1267 (parallel [(set (match_operand:SF 0 "l_register_operand" "")
1268 (match_operand:SF 1 "const_double_operand" ""))
1269 (clobber (reg:CC REG_CC))])
1270 (match_dup 2)]
1271 "operands[1] != CONST0_RTX (SFmode)"
1272 [(parallel [(set (match_dup 0)
1273 (match_dup 1))
1274 (clobber (match_dup 2))
1275 (clobber (reg:CC REG_CC))])])
1276
1277 ;; '*' because it is not used in rtl generation.
1278 (define_insn "*reload_insf"
1279 [(set (match_operand:SF 0 "register_operand" "=r")
1280 (match_operand:SF 1 "const_double_operand" "F"))
1281 (clobber (match_operand:QI 2 "register_operand" "=&d"))
1282 (clobber (reg:CC REG_CC))]
1283 "reload_completed"
1284 {
1285 return output_reload_insisf (operands, operands[2], NULL);
1286 }
1287 [(set_attr "length" "8")
1288 (set_attr "adjust_len" "reload_in32")])
1289
1290 ;;=========================================================================
1291 ;; move string (like memcpy)
1292
1293 (define_expand "cpymemhi"
1294 [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
1295 (match_operand:BLK 1 "memory_operand" ""))
1296 (use (match_operand:HI 2 "const_int_operand" ""))
1297 (use (match_operand:HI 3 "const_int_operand" ""))])]
1298 ""
1299 {
1300 if (avr_emit_cpymemhi (operands))
1301 DONE;
1302
1303 FAIL;
1304 })
1305
1306 (define_mode_attr CPYMEM_r_d [(QI "r")
1307 (HI "wd")])
1308
1309 ;; $0 : Address Space
1310 ;; $1, $2 : Loop register
1311 ;; R30 : source address
1312 ;; R26 : destination address
1313
1314 ;; "cpymem_qi"
1315 ;; "cpymem_hi"
1316 (define_insn_and_split "cpymem_<mode>"
1317 [(set (mem:BLK (reg:HI REG_X))
1318 (mem:BLK (reg:HI REG_Z)))
1319 (unspec [(match_operand:QI 0 "const_int_operand" "n")]
1320 UNSPEC_CPYMEM)
1321 (use (match_operand:QIHI 1 "register_operand" "<CPYMEM_r_d>"))
1322 (clobber (reg:HI REG_X))
1323 (clobber (reg:HI REG_Z))
1324 (clobber (reg:QI LPM_REGNO))
1325 (clobber (match_operand:QIHI 2 "register_operand" "=1"))]
1326 ""
1327 "#"
1328 "&& reload_completed"
1329 [(parallel [(set (mem:BLK (reg:HI REG_X))
1330 (mem:BLK (reg:HI REG_Z)))
1331 (unspec [(match_dup 0)]
1332 UNSPEC_CPYMEM)
1333 (use (match_dup 1))
1334 (clobber (reg:HI REG_X))
1335 (clobber (reg:HI REG_Z))
1336 (clobber (reg:QI LPM_REGNO))
1337 (clobber (match_dup 2))
1338 (clobber (reg:CC REG_CC))])])
1339
1340 (define_insn "*cpymem_<mode>"
1341 [(set (mem:BLK (reg:HI REG_X))
1342 (mem:BLK (reg:HI REG_Z)))
1343 (unspec [(match_operand:QI 0 "const_int_operand" "n")]
1344 UNSPEC_CPYMEM)
1345 (use (match_operand:QIHI 1 "register_operand" "<CPYMEM_r_d>"))
1346 (clobber (reg:HI REG_X))
1347 (clobber (reg:HI REG_Z))
1348 (clobber (reg:QI LPM_REGNO))
1349 (clobber (match_operand:QIHI 2 "register_operand" "=1"))
1350 (clobber (reg:CC REG_CC))]
1351 "reload_completed"
1352 {
1353 return avr_out_cpymem (insn, operands, NULL);
1354 }
1355 [(set_attr "adjust_len" "cpymem")])
1356
1357
1358 ;; $0 : 24-bit address space
1359 ;; $1 : RAMPZ RAM address
1360 ;; R24 : #bytes and loop register
1361 ;; R23:Z : 24-bit source address
1362 ;; R26 : 16-bit destination address
1363
1364 ;; "cpymemx_qi"
1365 ;; "cpymemx_hi"
1366
1367 (define_insn_and_split "cpymemx_<mode>"
1368 [(set (mem:BLK (reg:HI REG_X))
1369 ;; Spell out the address. IRA may try to spill
1370 ;; a hard reg when operands were used.
1371 (mem:BLK (lo_sum:PSI (reg:QI REG_23)
1372 (reg:HI REG_Z))))
1373 (unspec [(match_operand:QI 0 "const_int_operand" "n")]
1374 UNSPEC_CPYMEM)
1375 (use (reg:QIHI 24))
1376 (clobber (reg:HI REG_X))
1377 (clobber (reg:HI REG_Z))
1378 (clobber (reg:QI LPM_REGNO))
1379 (clobber (reg:HI 24))
1380 (clobber (reg:QI 23))
1381 (clobber (mem:QI (match_operand:QI 1 "io_address_operand" "n")))]
1382 ""
1383 "#"
1384 "&& reload_completed"
1385 [(parallel [(set (mem:BLK (reg:HI REG_X))
1386 (match_dup 2))
1387 (unspec [(match_dup 0)]
1388 UNSPEC_CPYMEM)
1389 (use (reg:QIHI 24))
1390 (clobber (reg:HI REG_X))
1391 (clobber (reg:HI REG_Z))
1392 (clobber (reg:QI LPM_REGNO))
1393 (clobber (reg:HI 24))
1394 (clobber (reg:QI 23))
1395 (clobber (mem:QI (match_dup 1)))
1396 (clobber (reg:CC REG_CC))])]
1397 {
1398 rtx xset = XVECEXP (PATTERN (curr_insn), 0, 0);
1399 operands[2] = SET_SRC (xset);
1400 })
1401
1402 (define_insn "*cpymemx_<mode>"
1403 [(set (mem:BLK (reg:HI REG_X))
1404 (mem:BLK (lo_sum:PSI (reg:QI REG_23)
1405 (reg:HI REG_Z))))
1406 (unspec [(match_operand:QI 0 "const_int_operand" "n")]
1407 UNSPEC_CPYMEM)
1408 (use (reg:QIHI 24))
1409 (clobber (reg:HI REG_X))
1410 (clobber (reg:HI REG_Z))
1411 (clobber (reg:QI LPM_REGNO))
1412 (clobber (reg:HI 24))
1413 (clobber (reg:QI 23))
1414 (clobber (mem:QI (match_operand:QI 1 "io_address_operand" "n")))
1415 (clobber (reg:CC REG_CC))]
1416 "reload_completed"
1417 {
1418 addr_space_t as = (addr_space_t) INTVAL (operands[0]);
1419 return as == ADDR_SPACE_MEMX
1420 ? "%~call __movmemx_<mode>"
1421 : "%~call __movmemf_<mode>";
1422 }
1423 [(set_attr "type" "xcall")])
1424
1425
1426 ;; =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2
1427 ;; memset (%0, %2, %1)
1428
1429 (define_expand "setmemhi"
1430 [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
1431 (match_operand 2 "const_int_operand" ""))
1432 (use (match_operand:HI 1 "const_int_operand" ""))
1433 (use (match_operand:HI 3 "const_int_operand" ""))
1434 (clobber (match_scratch:HI 5 ""))
1435 (clobber (match_dup 4))])]
1436 ""
1437 {
1438 // If value to set is not zero, use the library routine.
1439 if (operands[2] != const0_rtx)
1440 FAIL;
1441
1442 if (!CONST_INT_P (operands[1]))
1443 FAIL;
1444
1445 machine_mode mode = u8_operand (operands[1], VOIDmode) ? QImode : HImode;
1446 operands[4] = gen_rtx_SCRATCH (mode);
1447 operands[1] = copy_to_mode_reg (mode,
1448 gen_int_mode (INTVAL (operands[1]), mode));
1449 rtx addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
1450 operands[0] = gen_rtx_MEM (BLKmode, addr0);
1451 })
1452
1453
1454 (define_insn_and_split "*clrmemqi_split"
1455 [(set (mem:BLK (match_operand:HI 0 "register_operand" "e"))
1456 (const_int 0))
1457 (use (match_operand:QI 1 "register_operand" "r"))
1458 (use (match_operand:HI 2 "const_int_operand" "n"))
1459 (clobber (match_scratch:HI 3 "=0"))
1460 (clobber (match_scratch:QI 4 "=&1"))]
1461 ""
1462 "#"
1463 "&& reload_completed"
1464 [(parallel [(set (mem:BLK (match_dup 0))
1465 (const_int 0))
1466 (use (match_dup 1))
1467 (use (match_dup 2))
1468 (clobber (match_dup 3))
1469 (clobber (match_dup 4))
1470 (clobber (reg:CC REG_CC))])])
1471
1472 (define_insn "*clrmemqi"
1473 [(set (mem:BLK (match_operand:HI 0 "register_operand" "e"))
1474 (const_int 0))
1475 (use (match_operand:QI 1 "register_operand" "r"))
1476 (use (match_operand:HI 2 "const_int_operand" "n"))
1477 (clobber (match_scratch:HI 3 "=0"))
1478 (clobber (match_scratch:QI 4 "=&1"))
1479 (clobber (reg:CC REG_CC))]
1480 "reload_completed"
1481 "0:\;st %a0+,__zero_reg__\;dec %1\;brne 0b"
1482 [(set_attr "length" "3")])
1483
1484
1485 (define_insn_and_split "*clrmemhi_split"
1486 [(set (mem:BLK (match_operand:HI 0 "register_operand" "e,e"))
1487 (const_int 0))
1488 (use (match_operand:HI 1 "register_operand" "!w,d"))
1489 (use (match_operand:HI 2 "const_int_operand" "n,n"))
1490 (clobber (match_scratch:HI 3 "=0,0"))
1491 (clobber (match_scratch:HI 4 "=&1,&1"))]
1492 ""
1493 "#"
1494 "&& reload_completed"
1495 [(parallel [(set (mem:BLK (match_dup 0))
1496 (const_int 0))
1497 (use (match_dup 1))
1498 (use (match_dup 2))
1499 (clobber (match_dup 3))
1500 (clobber (match_dup 4))
1501 (clobber (reg:CC REG_CC))])]
1502 ""
1503 [(set_attr "isa" "adiw,*")])
1504
1505
1506 (define_insn "*clrmemhi"
1507 [(set (mem:BLK (match_operand:HI 0 "register_operand" "e,e"))
1508 (const_int 0))
1509 (use (match_operand:HI 1 "register_operand" "!w,d"))
1510 (use (match_operand:HI 2 "const_int_operand" "n,n"))
1511 (clobber (match_scratch:HI 3 "=0,0"))
1512 (clobber (match_scratch:HI 4 "=&1,&1"))
1513 (clobber (reg:CC REG_CC))]
1514 "reload_completed"
1515 "@
1516 0:\;st %a0+,__zero_reg__\;sbiw %A1,1\;brne 0b
1517 0:\;st %a0+,__zero_reg__\;subi %A1,1\;sbci %B1,0\;brne 0b"
1518 [(set_attr "length" "3,4")
1519 (set_attr "isa" "adiw,*")])
1520
1521 (define_expand "strlenhi"
1522 [(set (match_dup 4)
1523 (unspec:HI [(match_operand:BLK 1 "memory_operand" "")
1524 (match_operand:QI 2 "const_int_operand" "")
1525 (match_operand:HI 3 "immediate_operand" "")]
1526 UNSPEC_STRLEN))
1527 (set (match_dup 4)
1528 (plus:HI (match_dup 4)
1529 (const_int -1)))
1530 (parallel [(set (match_operand:HI 0 "register_operand" "")
1531 (minus:HI (match_dup 4)
1532 (match_dup 5)))
1533 (clobber (scratch:QI))])]
1534 ""
1535 {
1536 if (operands[2] != const0_rtx)
1537 FAIL;
1538 rtx addr = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
1539 operands[1] = gen_rtx_MEM (BLKmode, addr);
1540 operands[5] = addr;
1541 operands[4] = gen_reg_rtx (HImode);
1542 })
1543
1544 (define_insn_and_split "*strlenhi_split"
1545 [(set (match_operand:HI 0 "register_operand" "=e")
1546 (unspec:HI [(mem:BLK (match_operand:HI 1 "register_operand" "0"))
1547 (const_int 0)
1548 (match_operand:HI 2 "immediate_operand" "i")]
1549 UNSPEC_STRLEN))]
1550 ""
1551 "#"
1552 "&& reload_completed"
1553 [(parallel
1554 [(set (match_dup 0)
1555 (unspec:HI [(mem:BLK (match_dup 1))
1556 (const_int 0)
1557 (match_dup 2)]
1558 UNSPEC_STRLEN))
1559 (clobber (reg:CC REG_CC))])])
1560
1561 (define_insn "*strlenhi"
1562 [(set (match_operand:HI 0 "register_operand" "=e")
1563 (unspec:HI [(mem:BLK (match_operand:HI 1 "register_operand" "0"))
1564 (const_int 0)
1565 (match_operand:HI 2 "immediate_operand" "i")]
1566 UNSPEC_STRLEN))
1567 (clobber (reg:CC REG_CC))]
1568 "reload_completed"
1569 "0:\;ld __tmp_reg__,%a0+\;tst __tmp_reg__\;brne 0b"
1570 [(set_attr "length" "3")])
1571
1572 ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1573 ; add bytes
1574
1575 ;; "addqi3"
1576 ;; "addqq3" "adduqq3"
1577 (define_insn_and_split "add<mode>3"
1578 [(set (match_operand:ALL1 0 "register_operand" "=r,d ,r ,r ,r ,r")
1579 (plus:ALL1 (match_operand:ALL1 1 "register_operand" "%0,0 ,0 ,0 ,0 ,0")
1580 (match_operand:ALL1 2 "nonmemory_operand" "r,n Ynn,Y01,Ym1,Y02,Ym2")))]
1581 ""
1582 "#"
1583 "&& reload_completed"
1584 [(parallel [(set (match_dup 0)
1585 (plus:ALL1 (match_dup 1)
1586 (match_dup 2)))
1587 (clobber (reg:CC REG_CC))])])
1588
1589 (define_insn "*add<mode>3"
1590 [(set (match_operand:ALL1 0 "register_operand" "=r,d ,r ,r ,r ,r")
1591 (plus:ALL1 (match_operand:ALL1 1 "register_operand" "%0,0 ,0 ,0 ,0 ,0")
1592 (match_operand:ALL1 2 "nonmemory_operand" "r,n Ynn,Y01,Ym1,Y02,Ym2")))
1593 (clobber (reg:CC REG_CC))]
1594 "reload_completed"
1595 "@
1596 add %0,%2
1597 subi %0,lo8(-(%2))
1598 inc %0
1599 dec %0
1600 inc %0\;inc %0
1601 dec %0\;dec %0"
1602 [(set_attr "length" "1,1,1,1,2,2")])
1603
1604 ;; "addhi3"
1605 ;; "addhq3" "adduhq3"
1606 ;; "addha3" "adduha3"
1607 (define_expand "add<mode>3"
1608 [(set (match_operand:ALL2 0 "register_operand" "")
1609 (plus:ALL2 (match_operand:ALL2 1 "register_operand" "")
1610 (match_operand:ALL2 2 "nonmemory_or_const_operand" "")))]
1611 ""
1612 {
1613 if (CONST_INT_P (operands[2]))
1614 {
1615 operands[2] = gen_int_mode (INTVAL (operands[2]), HImode);
1616
1617 if (can_create_pseudo_p()
1618 && !stack_register_operand (operands[0], HImode)
1619 && !stack_register_operand (operands[1], HImode)
1620 && !d_register_operand (operands[0], HImode)
1621 && !d_register_operand (operands[1], HImode))
1622 {
1623 emit_insn (gen_addhi3_clobber (operands[0], operands[1], operands[2]));
1624 DONE;
1625 }
1626 }
1627
1628 if (CONST_FIXED_P (operands[2]))
1629 {
1630 emit_insn (gen_add<mode>3_clobber (operands[0], operands[1], operands[2]));
1631 DONE;
1632 }
1633 })
1634
1635
1636 (define_insn_and_split "*addhi3_zero_extend_split"
1637 [(set (match_operand:HI 0 "register_operand" "=r,*?r")
1638 (plus:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r ,0"))
1639 (match_operand:HI 2 "register_operand" "0 ,r")))]
1640 ""
1641 "#"
1642 "&& reload_completed"
1643 [(parallel [(set (match_dup 0)
1644 (plus:HI (zero_extend:HI (match_dup 1))
1645 (match_dup 2)))
1646 (clobber (reg:CC REG_CC))])])
1647
1648 (define_insn "*addhi3_zero_extend"
1649 [(set (match_operand:HI 0 "register_operand" "=r,*?r")
1650 (plus:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r ,0"))
1651 (match_operand:HI 2 "register_operand" "0 ,r")))
1652 (clobber (reg:CC REG_CC))]
1653 "reload_completed"
1654 "@
1655 add %A0,%1\;adc %B0,__zero_reg__
1656 add %A0,%A2\;mov %B0,%B2\;adc %B0,__zero_reg__"
1657 [(set_attr "length" "2,3")])
1658
1659 (define_insn_and_split "*addhi3_zero_extend1_split"
1660 [(set (match_operand:HI 0 "register_operand" "=r")
1661 (plus:HI (match_operand:HI 1 "register_operand" "0")
1662 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
1663 ""
1664 "#"
1665 "&& reload_completed"
1666 [(parallel [(set (match_dup 0)
1667 (plus:HI (match_dup 1)
1668 (zero_extend:HI (match_dup 2))))
1669 (clobber (reg:CC REG_CC))])])
1670
1671 (define_insn "*addhi3_zero_extend1"
1672 [(set (match_operand:HI 0 "register_operand" "=r")
1673 (plus:HI (match_operand:HI 1 "register_operand" "0")
1674 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))
1675 (clobber (reg:CC REG_CC))]
1676 "reload_completed"
1677 "add %A0,%2\;adc %B0,__zero_reg__"
1678 [(set_attr "length" "2")])
1679
1680 (define_insn_and_split "*addhi3_zero_extend.const_split"
1681 [(set (match_operand:HI 0 "register_operand" "=d")
1682 (plus:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
1683 (match_operand:HI 2 "const_m255_to_m1_operand" "Cn8")))]
1684 ""
1685 "#"
1686 "&& reload_completed"
1687 [(parallel [(set (match_dup 0)
1688 (plus:HI (zero_extend:HI (match_dup 1))
1689 (match_dup 2)))
1690 (clobber (reg:CC REG_CC))])])
1691
1692 (define_insn "*addhi3_zero_extend.const"
1693 [(set (match_operand:HI 0 "register_operand" "=d")
1694 (plus:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
1695 (match_operand:HI 2 "const_m255_to_m1_operand" "Cn8")))
1696 (clobber (reg:CC REG_CC))]
1697 "reload_completed"
1698 "subi %A0,%n2\;sbc %B0,%B0"
1699 [(set_attr "length" "2")])
1700
1701 ;; PR90616: Adding symbols that are aligned to 256 bytes can
1702 ;; save up to two instructions.
1703 (define_insn "*aligned_add_symbol"
1704 [(set (match_operand:HI 0 "register_operand" "=d")
1705 (plus:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
1706 (match_operand:HI 2 "const_0mod256_operand" "Cp8")))]
1707 ""
1708 {
1709 return REGNO (operands[0]) == REGNO (operands[1])
1710 ? "ldi %B0,hi8(%2)"
1711 : "mov %A0,%1\;ldi %B0,hi8(%2)";
1712 }
1713 [(set (attr "length")
1714 (symbol_ref ("2 - (REGNO (operands[0]) == REGNO (operands[1]))")))])
1715
1716 ;; Occurs when computing offsets into 16-bit arrays.
1717 ;; Saves up to 2 instructions.
1718 (define_insn_and_split "*addhi3_zero_extend.ashift1.split"
1719 [(set (match_operand:HI 0 "register_operand" "=r")
1720 (plus:HI (ashift:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
1721 (const_int 1))
1722 (match_operand:HI 2 "register_operand" "0")))]
1723 ""
1724 "#"
1725 "&& reload_completed"
1726 [(parallel [(set (match_dup 0)
1727 (plus:HI (ashift:HI (zero_extend:HI (match_dup 1))
1728 (const_int 1))
1729 (match_dup 2)))
1730 (clobber (reg:CC REG_CC))])])
1731
1732 (define_insn "*addhi3_zero_extend.ashift1"
1733 [(set (match_operand:HI 0 "register_operand" "=r")
1734 (plus:HI (ashift:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
1735 (const_int 1))
1736 (match_operand:HI 2 "register_operand" "0")))
1737 (clobber (reg:CC REG_CC))]
1738 "reload_completed"
1739 {
1740 return reg_overlap_mentioned_p (operands[1], operands[0])
1741 ? "mov __tmp_reg__,%1\;add %A0,__tmp_reg__\;adc %B0,__zero_reg__\;add %A0,__tmp_reg__\;adc %B0,__zero_reg__"
1742 : "add %A0,%1\;adc %B0,__zero_reg__\;add %A0,%1\;adc %B0,__zero_reg__";
1743 }
1744 [(set (attr "length")
1745 (symbol_ref ("4 + reg_overlap_mentioned_p (operands[1], operands[0])")))])
1746
1747
1748 (define_insn_and_split "*usum_widenqihi3_split"
1749 [(set (match_operand:HI 0 "register_operand" "=r")
1750 (plus:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1751 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
1752 ""
1753 "#"
1754 "&& reload_completed"
1755 [(parallel [(set (match_dup 0)
1756 (plus:HI (zero_extend:HI (match_dup 1))
1757 (zero_extend:HI (match_dup 2))))
1758 (clobber (reg:CC REG_CC))])])
1759
1760
1761 (define_insn "*usum_widenqihi3"
1762 [(set (match_operand:HI 0 "register_operand" "=r")
1763 (plus:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1764 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))
1765 (clobber (reg:CC REG_CC))]
1766 "reload_completed"
1767 "add %A0,%2\;clr %B0\;rol %B0"
1768 [(set_attr "length" "3")])
1769
1770 (define_insn_and_split "*udiff_widenqihi3_split"
1771 [(set (match_operand:HI 0 "register_operand" "=r")
1772 (minus:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
1773 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
1774 ""
1775 "#"
1776 "&& reload_completed"
1777 [(parallel [(set (match_dup 0)
1778 (minus:HI (zero_extend:HI (match_dup 1))
1779 (zero_extend:HI (match_dup 2))))
1780 (clobber (reg:CC REG_CC))])])
1781
1782 (define_insn "*udiff_widenqihi3"
1783 [(set (match_operand:HI 0 "register_operand" "=r")
1784 (minus:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
1785 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))
1786 (clobber (reg:CC REG_CC))]
1787 "reload_completed"
1788 "sub %A0,%2\;sbc %B0,%B0"
1789 [(set_attr "length" "2")])
1790
1791 (define_insn_and_split "*addhi3_sp"
1792 [(set (match_operand:HI 1 "stack_register_operand" "=q")
1793 (plus:HI (match_operand:HI 2 "stack_register_operand" "q")
1794 (match_operand:HI 0 "avr_sp_immediate_operand" "Csp")))]
1795 ""
1796 {
1797 return avr_out_addto_sp (operands, NULL);
1798 }
1799 ""
1800 [(const_int 0)]
1801 {
1802 // Do not attempt to split this pattern. This FAIL is necessary
1803 // to prevent the splitter from matching *add<ALL2>3_split, splitting
1804 // it, and then failing later because constraints don't match, as split
1805 // does not look at constraints.
1806 FAIL;
1807 }
1808 [(set_attr "length" "6")
1809 (set_attr "adjust_len" "addto_sp")])
1810
1811 ;; "*addhi3_split"
1812 ;; "*addhq3_split" "*adduhq3_split"
1813 ;; "*addha3_split" "*adduha3_split"
1814 (define_insn_and_split "*add<mode>3_split"
1815 [(set (match_operand:ALL2 0 "register_operand" "=??r,d,!w ,d")
1816 (plus:ALL2 (match_operand:ALL2 1 "register_operand" "%0,0,0 ,0")
1817 (match_operand:ALL2 2 "nonmemory_or_const_operand" "r,s,IJ YIJ,n Ynn")))]
1818 ""
1819 "#"
1820 "&& 1"
1821 [(parallel [(set (match_dup 0)
1822 (plus:ALL2 (match_dup 1)
1823 (match_dup 2)))
1824 (clobber (reg:CC REG_CC))])]
1825 {
1826 // Passes like combine and fwprop1 may remove the scratch from an
1827 // addhi3 insn. Add the scratch again because having a QImode
1828 // scratch reg available is better than spilling the operands in
1829 // the case when we don't get a d-regs register.
1830 if (! reload_completed
1831 && const_operand (operands[2], <MODE>mode)
1832 && ! stack_register_operand (operands[0], HImode)
1833 && ! stack_register_operand (operands[1], HImode))
1834 {
1835 emit (gen_add<mode>3_clobber (operands[0], operands[1], operands[2]));
1836 DONE;
1837 }
1838
1839 if (! reload_completed)
1840 FAIL;
1841 }
1842 [(set_attr "isa" "*,*,adiw,*")])
1843
1844 ;; "*addhi3"
1845 ;; "*addhq3" "*adduhq3"
1846 ;; "*addha3" "*adduha3"
1847 (define_insn "*add<mode>3"
1848 [(set (match_operand:ALL2 0 "register_operand" "=??r,d,!w ,d")
1849 (plus:ALL2 (match_operand:ALL2 1 "register_operand" "%0,0,0 ,0")
1850 (match_operand:ALL2 2 "nonmemory_or_const_operand" "r,s,IJ YIJ,n Ynn")))
1851 (clobber (reg:CC REG_CC))]
1852 "reload_completed"
1853 {
1854 return avr_out_plus (insn, operands);
1855 }
1856 [(set_attr "length" "2")
1857 (set_attr "isa" "*,*,adiw,*")
1858 (set_attr "adjust_len" "plus")])
1859
1860 ;; Adding a constant to NO_LD_REGS might have lead to a reload of
1861 ;; that constant to LD_REGS. We don't add a scratch to *addhi3
1862 ;; itself because that insn is special to reload.
1863
1864 (define_peephole2 ; addhi3_clobber
1865 [(parallel [(set (match_operand:ALL2 0 "d_register_operand" "")
1866 (match_operand:ALL2 1 "const_operand" ""))
1867 (clobber (reg:CC REG_CC))])
1868 (parallel [(set (match_operand:ALL2 2 "l_register_operand" "")
1869 (plus:ALL2 (match_dup 2)
1870 (match_dup 0)))
1871 (clobber (reg:CC REG_CC))])]
1872 "peep2_reg_dead_p (2, operands[0])"
1873 [(parallel [(set (match_dup 2)
1874 (plus:ALL2 (match_dup 2)
1875 (match_dup 1)))
1876 (clobber (match_dup 3))
1877 (clobber (reg:CC REG_CC))])]
1878 {
1879 operands[3] = simplify_gen_subreg (QImode, operands[0], <MODE>mode, 0);
1880 })
1881
1882 ;; Same, but with reload to NO_LD_REGS
1883 ;; Combine *reload_inhi with *addhi3
1884
1885 (define_peephole2 ; addhi3_clobber
1886 [(parallel [(set (match_operand:ALL2 0 "l_register_operand" "")
1887 (match_operand:ALL2 1 "const_operand" ""))
1888 (clobber (match_operand:QI 2 "d_register_operand" ""))
1889 (clobber (reg:CC REG_CC))])
1890 (parallel [(set (match_operand:ALL2 3 "l_register_operand" "")
1891 (plus:ALL2 (match_dup 3)
1892 (match_dup 0)))
1893 (clobber (reg:CC REG_CC))])]
1894 "peep2_reg_dead_p (2, operands[0])"
1895 [(parallel [(set (match_dup 3)
1896 (plus:ALL2 (match_dup 3)
1897 (match_dup 1)))
1898 (clobber (match_dup 2))
1899 (clobber (reg:CC REG_CC))])])
1900
1901 ;; "addhi3_clobber"
1902 ;; "addhq3_clobber" "adduhq3_clobber"
1903 ;; "addha3_clobber" "adduha3_clobber"
1904 (define_insn_and_split "add<mode>3_clobber"
1905 [(set (match_operand:ALL2 0 "register_operand" "=!w ,d ,r")
1906 (plus:ALL2 (match_operand:ALL2 1 "register_operand" "%0 ,0 ,0")
1907 (match_operand:ALL2 2 "const_operand" "IJ YIJ,n Ynn,n Ynn")))
1908 (clobber (match_scratch:QI 3 "=X ,X ,&d"))]
1909 ""
1910 "#"
1911 "&& reload_completed"
1912 [(parallel [(set (match_dup 0)
1913 (plus:ALL2 (match_dup 1)
1914 (match_dup 2)))
1915 (clobber (match_dup 3))
1916 (clobber (reg:CC REG_CC))])])
1917
1918 ;; "*addhi3_clobber"
1919 ;; "*addhq3_clobber" "*adduhq3_clobber"
1920 ;; "*addha3_clobber" "*adduha3_clobber"
1921 (define_insn "*add<mode>3_clobber"
1922 [(set (match_operand:ALL2 0 "register_operand" "=!w ,d ,r")
1923 (plus:ALL2 (match_operand:ALL2 1 "register_operand" "%0 ,0 ,0")
1924 (match_operand:ALL2 2 "const_operand" "IJ YIJ,n Ynn,n Ynn")))
1925 (clobber (match_scratch:QI 3 "=X ,X ,&d"))
1926 (clobber (reg:CC REG_CC))]
1927 "reload_completed"
1928 {
1929 return avr_out_plus (insn, operands);
1930 }
1931 [(set_attr "length" "4")
1932 (set_attr "adjust_len" "plus")])
1933
1934
1935 ;; "addsi3"
1936 ;; "addsq3" "addusq3"
1937 ;; "addsa3" "addusa3"
1938 (define_insn_and_split "add<mode>3"
1939 [(set (match_operand:ALL4 0 "register_operand" "=??r,d ,r")
1940 (plus:ALL4 (match_operand:ALL4 1 "register_operand" "%0,0 ,0")
1941 (match_operand:ALL4 2 "nonmemory_operand" "r,i ,n Ynn")))
1942 (clobber (match_scratch:QI 3 "=X,X ,&d"))]
1943 ""
1944 "#"
1945 "&& reload_completed"
1946 [(parallel [(set (match_dup 0)
1947 (plus:ALL4 (match_dup 1)
1948 (match_dup 2)))
1949 (clobber (match_dup 3))
1950 (clobber (reg:CC REG_CC))])])
1951
1952 (define_insn "*add<mode>3"
1953 [(set (match_operand:ALL4 0 "register_operand" "=??r,d ,r")
1954 (plus:ALL4 (match_operand:ALL4 1 "register_operand" "%0,0 ,0")
1955 (match_operand:ALL4 2 "nonmemory_operand" "r,i ,n Ynn")))
1956 (clobber (match_scratch:QI 3 "=X,X ,&d"))
1957 (clobber (reg:CC REG_CC))]
1958 "reload_completed"
1959 {
1960 return avr_out_plus (insn, operands);
1961 }
1962 [(set_attr "length" "4")
1963 (set_attr "adjust_len" "plus")])
1964
1965
1966 ;; "*addhi3.sign_extend.qi_split"
1967 ;; "*addpsi3.zero_extend.qi_split" "*addpsi3.sign_extend.qi_split"
1968 ;; "*addpsi3.zero_extend.hi_split" "*addpsi3.sign_extend.hi_split"
1969 ;; "*addsi3.zero_extend.qi_split" "*addsi3.sign_extend.qi_split"
1970 ;; "*addsi3.zero_extend.hi_split" "*addsi3.sign_extend.hi_split"
1971 ;; "*addsi3.zero_extend.psi_split" "*addsi3.sign_extend.psi_split"
1972 ;; The zero_extend:HI(QI) case is treated in an own insn as it can
1973 ;; more than just "r,r,0".
1974 (define_insn_and_split "*add<HISI:mode>3.<code>.<QIPSI:mode>_split"
1975 [(set (match_operand:HISI 0 "register_operand" "=r")
1976 (plus:HISI (any_extend:HISI (match_operand:QIPSI 1 "register_operand" "r"))
1977 (match_operand:HISI 2 "register_operand" "0")))]
1978 "<HISI:SIZE> > <QIPSI:SIZE>
1979 && (<HISI:SIZE> > 2 || <CODE> == SIGN_EXTEND)"
1980 "#"
1981 "&& reload_completed"
1982 [(parallel [(set (match_dup 0)
1983 (plus:HISI (any_extend:HISI (match_dup 1))
1984 (match_dup 2)))
1985 (clobber (reg:CC REG_CC))])])
1986
1987 ;; "*addhi3.sign_extend.qi"
1988 ;; "*addpsi3.zero_extend.qi" "*addpsi3.sign_extend.qi"
1989 ;; "*addpsi3.zero_extend.hi" "*addpsi3.sign_extend.hi"
1990 ;; "*addsi3.zero_extend.qi" "*addsi3.sign_extend.qi"
1991 ;; "*addsi3.zero_extend.hi" "*addsi3.sign_extend.hi"
1992 ;; "*addsi3.zero_extend.psi" "*addsi3.sign_extend.psi"
1993 (define_insn "*add<HISI:mode>3.<code>.<QIPSI:mode>"
1994 [(set (match_operand:HISI 0 "register_operand" "=r")
1995 (plus:HISI (any_extend:HISI (match_operand:QIPSI 1 "register_operand" "r"))
1996 (match_operand:HISI 2 "register_operand" "0")))
1997 (clobber (reg:CC REG_CC))]
1998 "reload_completed
1999 && <HISI:SIZE> > <QIPSI:SIZE>
2000 && (<HISI:SIZE> > 2 || <CODE> == SIGN_EXTEND)"
2001 {
2002 return avr_out_plus_ext (insn, operands, nullptr);
2003 }
2004 [(set (attr "length")
2005 (symbol_ref "<HISI:SIZE> + 3 * (<CODE> == SIGN_EXTEND)"))
2006 (set_attr "adjust_len" "plus_ext")])
2007
2008
2009 ;; "*subhi3.zero_extend.qi_split" "*subhi3.sign_extend.qi_split"
2010 ;; "*subpsi3.zero_extend.qi_split" "*subpsi3.sign_extend.qi_split"
2011 ;; "*subpsi3.zero_extend.hi_split" "*subpsi3.sign_extend.hi_split"
2012 ;; "*subsi3.zero_extend.qi_split" "*subsi3.sign_extend.qi_split"
2013 ;; "*subsi3.zero_extend.hi_split" "*subsi3.sign_extend.hi_split"
2014 ;; "*subsi3.zero_extend.psi_split" "*subsi3.sign_extend.psi_split"
2015 (define_insn_and_split "*sub<HISI:mode>3.<code>.<QIPSI:mode>_split"
2016 [(set (match_operand:HISI 0 "register_operand" "=r")
2017 (minus:HISI (match_operand:HISI 1 "register_operand" "0")
2018 (any_extend:HISI (match_operand:QIPSI 2 "register_operand" "r"))))]
2019 "<HISI:SIZE> > <QIPSI:SIZE>"
2020 "#"
2021 "&& reload_completed"
2022 [(parallel [(set (match_dup 0)
2023 (minus:HISI (match_dup 1)
2024 (any_extend:HISI (match_dup 2))))
2025 (clobber (reg:CC REG_CC))])])
2026
2027 ;; "*subhi3.zero_extend.qi" "*subhi3.sign_extend.qi"
2028 ;; "*subpsi3.zero_extend.qi" "*subpsi3.sign_extend.qi"
2029 ;; "*subpsi3.zero_extend.hi" "*subpsi3.sign_extend.hi"
2030 ;; "*subsi3.zero_extend.qi" "*subsi3.sign_extend.qi"
2031 ;; "*subsi3.zero_extend.hi" "*subsi3.sign_extend.hi"
2032 ;; "*subsi3.zero_extend.psi" "*subsi3.sign_extend.psi"
2033 (define_insn "*sub<HISI:mode>3.<code>.<QIPSI:mode>"
2034 [(set (match_operand:HISI 0 "register_operand" "=r")
2035 (minus:HISI (match_operand:HISI 1 "register_operand" "0")
2036 (any_extend:HISI (match_operand:QIPSI 2 "register_operand" "r"))))
2037 (clobber (reg:CC REG_CC))]
2038 "reload_completed
2039 && <HISI:SIZE> > <QIPSI:SIZE>"
2040 {
2041 return avr_out_plus_ext (insn, operands, nullptr);
2042 }
2043 [(set (attr "length")
2044 (symbol_ref "<HISI:SIZE> + 3 * (<CODE> == SIGN_EXTEND)"))
2045 (set_attr "adjust_len" "plus_ext")])
2046
2047
2048 (define_insn_and_split "addpsi3"
2049 [(set (match_operand:PSI 0 "register_operand" "=??r,d ,d,r")
2050 (plus:PSI (match_operand:PSI 1 "register_operand" "%0,0 ,0,0")
2051 (match_operand:PSI 2 "nonmemory_operand" "r,s ,n,n")))
2052 (clobber (match_scratch:QI 3 "=X,X ,X,&d"))]
2053 ""
2054 "#"
2055 "&& reload_completed"
2056 [(parallel [(set (match_dup 0)
2057 (plus:PSI (match_dup 1)
2058 (match_dup 2)))
2059 (clobber (match_dup 3 ))
2060 (clobber (reg:CC REG_CC))])])
2061
2062 (define_insn "*addpsi3"
2063 [(set (match_operand:PSI 0 "register_operand" "=??r,d ,d,r")
2064 (plus:PSI (match_operand:PSI 1 "register_operand" "%0,0 ,0,0")
2065 (match_operand:PSI 2 "nonmemory_operand" "r,s ,n,n")))
2066 (clobber (match_scratch:QI 3 "=X,X ,X,&d"))
2067 (clobber (reg:CC REG_CC))]
2068 "reload_completed"
2069 {
2070 return avr_out_plus (insn, operands);
2071 }
2072 [(set_attr "length" "3")
2073 (set_attr "adjust_len" "plus")])
2074
2075 (define_insn_and_split "subpsi3"
2076 [(set (match_operand:PSI 0 "register_operand" "=r")
2077 (minus:PSI (match_operand:PSI 1 "register_operand" "0")
2078 (match_operand:PSI 2 "register_operand" "r")))]
2079 ""
2080 "#"
2081 "&& reload_completed"
2082 [(parallel [(set (match_dup 0)
2083 (minus:PSI (match_dup 1)
2084 (match_dup 2)))
2085 (clobber (reg:CC REG_CC))])])
2086
2087 (define_insn "*subpsi3"
2088 [(set (match_operand:PSI 0 "register_operand" "=r")
2089 (minus:PSI (match_operand:PSI 1 "register_operand" "0")
2090 (match_operand:PSI 2 "register_operand" "r")))
2091 (clobber (reg:CC REG_CC))]
2092 "reload_completed"
2093 "sub %0,%2\;sbc %B0,%B2\;sbc %C0,%C2"
2094 [(set_attr "length" "3")])
2095
2096
2097 ;-----------------------------------------------------------------------------
2098 ; sub bytes
2099
2100 ;; "subqi3"
2101 ;; "subqq3" "subuqq3"
2102 (define_insn_and_split "sub<mode>3"
2103 [(set (match_operand:ALL1 0 "register_operand" "=??r,d ,r ,r ,r ,r")
2104 (minus:ALL1 (match_operand:ALL1 1 "register_operand" "0,0 ,0 ,0 ,0 ,0")
2105 (match_operand:ALL1 2 "nonmemory_or_const_operand" "r,n Ynn,Y01,Ym1,Y02,Ym2")))]
2106 ""
2107 "#"
2108 "&& reload_completed"
2109 [(parallel [(set (match_dup 0)
2110 (minus:ALL1 (match_dup 1)
2111 (match_dup 2)))
2112 (clobber (reg:CC REG_CC))])])
2113
2114 (define_insn "*sub<mode>3"
2115 [(set (match_operand:ALL1 0 "register_operand" "=??r,d ,r ,r ,r ,r")
2116 (minus:ALL1 (match_operand:ALL1 1 "register_operand" "0,0 ,0 ,0 ,0 ,0")
2117 (match_operand:ALL1 2 "nonmemory_or_const_operand" "r,n Ynn,Y01,Ym1,Y02,Ym2")))
2118 (clobber (reg:CC REG_CC))]
2119 "reload_completed"
2120 "@
2121 sub %0,%2
2122 subi %0,lo8(%2)
2123 dec %0
2124 inc %0
2125 dec %0\;dec %0
2126 inc %0\;inc %0"
2127 [(set_attr "length" "1,1,1,1,2,2")])
2128
2129 ;; "subhi3"
2130 ;; "subhq3" "subuhq3"
2131 ;; "subha3" "subuha3"
2132 (define_insn_and_split "sub<mode>3"
2133 [(set (match_operand:ALL2 0 "register_operand" "=??r,d ,*r")
2134 (minus:ALL2 (match_operand:ALL2 1 "register_operand" "0,0 ,0")
2135 (match_operand:ALL2 2 "nonmemory_or_const_operand" "r,i Ynn,Ynn")))
2136 (clobber (match_scratch:QI 3 "=X,X ,&d"))]
2137 ""
2138 "#"
2139 "&& reload_completed"
2140 [(parallel [(set (match_dup 0)
2141 (minus:ALL2 (match_dup 1)
2142 (match_dup 2)))
2143 (clobber (match_dup 3))
2144 (clobber (reg:CC REG_CC))])])
2145
2146 (define_insn "*sub<mode>3"
2147 [(set (match_operand:ALL2 0 "register_operand" "=??r,d ,*r")
2148 (minus:ALL2 (match_operand:ALL2 1 "register_operand" "0,0 ,0")
2149 (match_operand:ALL2 2 "nonmemory_or_const_operand" "r,i Ynn,Ynn")))
2150 (clobber (match_scratch:QI 3 "=X,X ,&d"))
2151 (clobber (reg:CC REG_CC))]
2152 "reload_completed"
2153 {
2154 return avr_out_plus (insn, operands);
2155 }
2156 [(set_attr "adjust_len" "plus")])
2157
2158
2159 ;; "subsi3"
2160 ;; "subsq3" "subusq3"
2161 ;; "subsa3" "subusa3"
2162 (define_insn_and_split "sub<mode>3"
2163 [(set (match_operand:ALL4 0 "register_operand" "=??r,d ,r")
2164 (minus:ALL4 (match_operand:ALL4 1 "register_operand" "0,0 ,0")
2165 (match_operand:ALL4 2 "nonmemory_or_const_operand" "r,n Ynn,Ynn")))
2166 (clobber (match_scratch:QI 3 "=X,X ,&d"))]
2167 ""
2168 "#"
2169 "&& reload_completed"
2170 [(parallel [(set (match_dup 0)
2171 (minus:ALL4 (match_dup 1)
2172 (match_dup 2)))
2173 (clobber (match_dup 3))
2174 (clobber (reg:CC REG_CC))])])
2175
2176 (define_insn "*sub<mode>3"
2177 [(set (match_operand:ALL4 0 "register_operand" "=??r,d ,r")
2178 (minus:ALL4 (match_operand:ALL4 1 "register_operand" "0,0 ,0")
2179 (match_operand:ALL4 2 "nonmemory_or_const_operand" "r,n Ynn,Ynn")))
2180 (clobber (match_scratch:QI 3 "=X,X ,&d"))
2181 (clobber (reg:CC REG_CC))]
2182 "reload_completed"
2183 {
2184 return avr_out_plus (insn, operands);
2185 }
2186 [(set_attr "adjust_len" "plus")])
2187
2188
2189 ;******************************************************************************
2190 ; mul
2191
2192 (define_expand "mulqi3"
2193 [(set (match_operand:QI 0 "register_operand" "")
2194 (mult:QI (match_operand:QI 1 "register_operand" "")
2195 (match_operand:QI 2 "register_operand" "")))]
2196 ""
2197 {
2198 if (!AVR_HAVE_MUL)
2199 {
2200 emit_insn (gen_mulqi3_call (operands[0], operands[1], operands[2]));
2201 DONE;
2202 }
2203 })
2204
2205 (define_insn_and_split "*mulqi3_enh_split"
2206 [(set (match_operand:QI 0 "register_operand" "=r")
2207 (mult:QI (match_operand:QI 1 "register_operand" "r")
2208 (match_operand:QI 2 "register_operand" "r")))]
2209 "AVR_HAVE_MUL"
2210 "#"
2211 "&& reload_completed"
2212 [(parallel [(set (match_dup 0)
2213 (mult:QI (match_dup 1)
2214 (match_dup 2)))
2215 (clobber (reg:CC REG_CC))])])
2216
2217 (define_insn "*mulqi3_enh"
2218 [(set (match_operand:QI 0 "register_operand" "=r")
2219 (mult:QI (match_operand:QI 1 "register_operand" "r")
2220 (match_operand:QI 2 "register_operand" "r")))
2221 (clobber (reg:CC REG_CC))]
2222 "AVR_HAVE_MUL && reload_completed"
2223 "mul %1,%2
2224 mov %0,r0
2225 clr r1"
2226 [(set_attr "length" "3")])
2227
2228 (define_expand "mulqi3_call"
2229 [(set (reg:QI 24) (match_operand:QI 1 "register_operand" ""))
2230 (set (reg:QI 22) (match_operand:QI 2 "register_operand" ""))
2231 (parallel [(set (reg:QI 24)
2232 (mult:QI (reg:QI 24) (reg:QI 22)))
2233 (clobber (reg:QI 22))])
2234 (set (match_operand:QI 0 "register_operand" "") (reg:QI 24))]
2235 ""
2236 {
2237 avr_fix_inputs (operands, 1 << 2, regmask (QImode, 24));
2238 })
2239
2240 (define_insn_and_split "*mulqi3_call_split"
2241 [(set (reg:QI 24) (mult:QI (reg:QI 24) (reg:QI 22)))
2242 (clobber (reg:QI 22))]
2243 "!AVR_HAVE_MUL"
2244 "#"
2245 "&& reload_completed"
2246 [(parallel [(set (reg:QI 24)
2247 (mult:QI (reg:QI 24) (reg:QI 22)))
2248 (clobber (reg:QI 22))
2249 (clobber (reg:CC REG_CC))])])
2250
2251 (define_insn "*mulqi3_call"
2252 [(set (reg:QI 24)
2253 (mult:QI (reg:QI 24) (reg:QI 22)))
2254 (clobber (reg:QI 22))
2255 (clobber (reg:CC REG_CC))]
2256 "!AVR_HAVE_MUL && reload_completed"
2257 "%~call __mulqi3"
2258 [(set_attr "type" "xcall")])
2259
2260 ;; "umulqi3_highpart"
2261 ;; "smulqi3_highpart"
2262
2263 (define_insn_and_split "<extend_su>mulqi3_highpart"
2264 [(set (match_operand:QI 0 "register_operand" "=r")
2265 (truncate:QI
2266 (lshiftrt:HI (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2267 (any_extend:HI (match_operand:QI 2 "register_operand" "<mul_r_d>")))
2268 (const_int 8))))]
2269 "AVR_HAVE_MUL"
2270 "#"
2271 "&& reload_completed"
2272 [(parallel [(set (match_dup 0)
2273 (truncate:QI
2274 (lshiftrt:HI (mult:HI (any_extend:HI (match_dup 1))
2275 (any_extend:HI (match_dup 2)))
2276 (const_int 8))))
2277 (clobber (reg:CC REG_CC))])])
2278
2279 (define_insn "*<extend_su>mulqi3_highpart"
2280 [(set (match_operand:QI 0 "register_operand" "=r")
2281 (truncate:QI
2282 (lshiftrt:HI (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2283 (any_extend:HI (match_operand:QI 2 "register_operand" "<mul_r_d>")))
2284 (const_int 8))))
2285 (clobber (reg:CC REG_CC))]
2286 "AVR_HAVE_MUL && reload_completed"
2287 "mul<extend_s> %1,%2
2288 mov %0,r1
2289 clr __zero_reg__"
2290 [(set_attr "length" "3")])
2291
2292
2293 ;; Used when expanding div or mod inline for some special values
2294 ;; *subqi3.msbit_split *subhi3.msbit_split
2295 ;; *subpsi3.msbit_split *subsi3.msbit_split
2296 (define_insn_and_split "*sub<mode>3.msbit_split"
2297 [(set (match_operand:QISI 0 "register_operand" "=r")
2298 (minus:QISI (match_operand:QISI 1 "register_operand" "0")
2299 (any_shiftrt:QISI (match_operand:QISI 2 "register_operand" "r")
2300 (match_operand:QI 3 "const<MSB>_operand" "<C_MSB>"))))]
2301 ""
2302 "#"
2303 "&& reload_completed"
2304 [; *sub<QISI:mode>3.lt0
2305 (parallel [(set (match_dup 0)
2306 (minus:QISI (match_dup 1)
2307 (lt:QISI (match_dup 2)
2308 (const_int 0))))
2309 (clobber (reg:CC REG_CC))])])
2310
2311 ;; *addqi3.msbit_split *addhi3.msbit_split
2312 ;; *addpsi3.msbit_split *addsi3.msbit_split
2313 (define_insn_and_split "*add<mode>3.msbit_split"
2314 [(set (match_operand:QISI 0 "register_operand" "=r")
2315 (plus:QISI (any_shiftrt:QISI (match_operand:QISI 1 "register_operand" "r")
2316 (match_operand:QI 2 "const<MSB>_operand" "<C_MSB>"))
2317 (match_operand:QISI 3 "register_operand" "0")))]
2318 ""
2319 "#"
2320 "&& reload_completed"
2321 [; *add<QISI:mode>3.lt0
2322 (parallel [(set (match_dup 0)
2323 (plus:QISI (lt:QISI (match_dup 1)
2324 (const_int 0))
2325 (match_dup 3)))
2326 (clobber (reg:CC REG_CC))])])
2327
2328 ;; *addhi3.sex.msbit_split
2329 ;; *addpsi3.sex.msbit_split *addsi3.sex.msbit_split
2330 (define_insn_and_split "*add<HISI:mode>3.sex.msbit_split"
2331 [(set (match_operand:HISI 0 "register_operand" "=r")
2332 (plus:HISI (any_shiftrt:HISI
2333 (sign_extend:HISI (match_operand:QIPSI 1 "register_operand" "r"))
2334 (match_operand:QI 2 "const<HISI:MSB>_operand" "<HISI:C_MSB>"))
2335 (match_operand:HISI 3 "register_operand" "0")))]
2336 "<HISI:SIZE> > <QIPSI:SIZE>"
2337 "#"
2338 "&& reload_completed"
2339 [; *add<QISI:mode>3.lt0
2340 (parallel [(set (match_dup 0)
2341 (plus:HISI (lt:HISI (match_dup 1)
2342 (const_int 0))
2343 (match_dup 3)))
2344 (clobber (reg:CC REG_CC))])])
2345
2346 ;; *subhi3.sex.msbit_split
2347 ;; *subpsi3.sex.msbit_split *subsi3.sex.msbit_split
2348 (define_insn_and_split "*sub<HISI:mode>3.sex.msbit_split"
2349 [(set (match_operand:HISI 0 "register_operand" "=r")
2350 (minus:HISI (match_operand:HISI 1 "register_operand" "0")
2351 (any_shiftrt:HISI
2352 (sign_extend:HISI (match_operand:QIPSI 2 "register_operand" "r"))
2353 (match_operand:QI 3 "const<HISI:MSB>_operand" "<HISI:C_MSB>"))))]
2354 "<HISI:SIZE> > <QIPSI:SIZE>"
2355 "#"
2356 "&& reload_completed"
2357 [; *sub<QISI:mode>3.lt0
2358 (parallel [(set (match_dup 0)
2359 (minus:HISI (match_dup 1)
2360 (lt:HISI (match_dup 2)
2361 (const_int 0))))
2362 (clobber (reg:CC REG_CC))])])
2363
2364 ;; *subqi3.lt0 *subqi3.ge0
2365 ;; *subhi3.lt0 *subhi3.ge0
2366 ;; *subpsi3.lt0 *subpsi3.ge0
2367 ;; *subsi3.lt0 *subsi3.ge0
2368 (define_insn "*sub<QISI:mode>3.<code>0"
2369 [(set (match_operand:QISI 0 "register_operand" "=r")
2370 (minus:QISI (match_operand:QISI 1 "register_operand" "0")
2371 (gelt:QISI (match_operand:QISI2 2 "register_operand" "r")
2372 (const_int 0))))
2373 (clobber (reg:CC REG_CC))]
2374 "reload_completed"
2375 {
2376 return avr_out_add_msb (insn, operands, <CODE>, nullptr);
2377 }
2378 [(set_attr "adjust_len" "add_<code>0")])
2379
2380 ;; *addqi3.lt0 *addqi3.ge0
2381 ;; *addhi3.lt0 *addhi3.ge0
2382 ;; *addpsi3.lt0 *addpsi3.ge0
2383 ;; *addsi3.lt0 *addsi3.ge0
2384 (define_insn "*add<QISI:mode>3.<code>0"
2385 [(set (match_operand:QISI 0 "register_operand" "=r")
2386 (plus:QISI (gelt:QISI (match_operand:QISI2 1 "register_operand" "r")
2387 (const_int 0))
2388 (match_operand:QISI 2 "register_operand" "0")))
2389 (clobber (reg:CC REG_CC))]
2390 "reload_completed"
2391 {
2392 return avr_out_add_msb (insn, operands, <CODE>, nullptr);
2393 }
2394 [(set_attr "adjust_len" "add_<code>0")])
2395
2396 ;; *addqi3.lt0_split *addqi3.ge0_split
2397 ;; *addhi3.lt0_split *addhi3.ge0_split
2398 ;; *addpsi3.lt0_split *addpsi3.ge0_split
2399 ;; *addsi3.lt0_split *addsi3.ge0_split
2400 (define_insn_and_split "*add<QISI:mode>3.<code>0_split"
2401 [(set (match_operand:QISI 0 "register_operand" "=r")
2402 (plus:QISI (gelt:QISI (match_operand:QISI2 1 "register_operand" "r")
2403 (const_int 0))
2404 (match_operand:QISI 2 "register_operand" "0")))]
2405 ""
2406 "#"
2407 "&& reload_completed"
2408 [; *add<QISI:mode>3.<code>0
2409 (parallel [(set (match_dup 0)
2410 (plus:QISI (gelt:QISI (match_dup 1)
2411 (const_int 0))
2412 (match_dup 2)))
2413 (clobber (reg:CC REG_CC))])])
2414
2415 ;; *subqi3.lt0_split *subqi3.ge0_split
2416 ;; *subhi3.lt0_split *subhi3.ge0_split
2417 ;; *subpsi3.lt0_split *subpsi3.ge0_split
2418 ;; *subsi3.lt0_split *subsi3.ge0_split
2419 (define_insn_and_split "*sub<QISI:mode>3.<code>0_split"
2420 [(set (match_operand:QISI 0 "register_operand" "=r")
2421 (minus:QISI (match_operand:QISI 1 "register_operand" "0")
2422 (gelt:QISI (match_operand:QISI2 2 "register_operand" "r")
2423 (const_int 0))))]
2424 ""
2425 "#"
2426 "&& reload_completed"
2427 [; *sub<QISI:mode>3.<code>0
2428 (parallel [(set (match_dup 0)
2429 (minus:QISI (match_dup 1)
2430 (gelt:QISI (match_dup 2)
2431 (const_int 0))))
2432 (clobber (reg:CC REG_CC))])])
2433
2434
2435 (define_insn_and_split "*umulqihi3.call_split"
2436 [(set (reg:HI 24)
2437 (mult:HI (zero_extend:HI (reg:QI 22))
2438 (zero_extend:HI (reg:QI 24))))
2439 (clobber (reg:QI 21))
2440 (clobber (reg:HI 22))]
2441 "!AVR_HAVE_MUL"
2442 "#"
2443 "&& reload_completed"
2444 [(parallel [(set (reg:HI 24)
2445 (mult:HI (zero_extend:HI (reg:QI 22))
2446 (zero_extend:HI (reg:QI 24))))
2447 (clobber (reg:QI 21))
2448 (clobber (reg:HI 22))
2449 (clobber (reg:CC REG_CC))])])
2450
2451 (define_insn "*umulqihi3.call"
2452 [(set (reg:HI 24)
2453 (mult:HI (zero_extend:HI (reg:QI 22))
2454 (zero_extend:HI (reg:QI 24))))
2455 (clobber (reg:QI 21))
2456 (clobber (reg:HI 22))
2457 (clobber (reg:CC REG_CC))]
2458 "!AVR_HAVE_MUL && reload_completed"
2459 "%~call __umulqihi3"
2460 [(set_attr "type" "xcall")])
2461
2462 ;; "umulqihi3"
2463 ;; "mulqihi3"
2464
2465 (define_insn_and_split "<extend_u>mulqihi3_split"
2466 [(set (match_operand:HI 0 "register_operand" "=r")
2467 (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2468 (any_extend:HI (match_operand:QI 2 "register_operand" "<mul_r_d>"))))]
2469 "AVR_HAVE_MUL"
2470 "#"
2471 "&& reload_completed"
2472 [(parallel [(set (match_dup 0)
2473 (mult:HI (any_extend:HI (match_dup 1))
2474 (any_extend:HI (match_dup 2))))
2475 (clobber (reg:CC REG_CC))])])
2476
2477 (define_insn "<extend_u>mulqihi3"
2478 [(set (match_operand:HI 0 "register_operand" "=r")
2479 (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2480 (any_extend:HI (match_operand:QI 2 "register_operand" "<mul_r_d>"))))
2481 (clobber (reg:CC REG_CC))]
2482 "AVR_HAVE_MUL && reload_completed"
2483 "mul<extend_s> %1,%2
2484 movw %0,r0
2485 clr __zero_reg__"
2486 [(set_attr "length" "3")])
2487
2488 (define_insn_and_split "usmulqihi3"
2489 [(set (match_operand:HI 0 "register_operand" "=r")
2490 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "a"))
2491 (sign_extend:HI (match_operand:QI 2 "register_operand" "a"))))]
2492 "AVR_HAVE_MUL"
2493 "#"
2494 "&& reload_completed"
2495 [(parallel [(set (match_dup 0)
2496 (mult:HI (zero_extend:HI (match_dup 1))
2497 (sign_extend:HI (match_dup 2))))
2498 (clobber (reg:CC REG_CC))])])
2499
2500 (define_insn "*usmulqihi3"
2501 [(set (match_operand:HI 0 "register_operand" "=r")
2502 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "a"))
2503 (sign_extend:HI (match_operand:QI 2 "register_operand" "a"))))
2504 (clobber (reg:CC REG_CC))]
2505 "AVR_HAVE_MUL && reload_completed"
2506 "mulsu %2,%1
2507 movw %0,r0
2508 clr __zero_reg__"
2509 [(set_attr "length" "3")])
2510
2511 ;; Above insn is not canonicalized by insn combine, so here is a version with
2512 ;; operands swapped.
2513 (define_insn_and_split "*sumulqihi3_split"
2514 [(set (match_operand:HI 0 "register_operand" "=r")
2515 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "a"))
2516 (zero_extend:HI (match_operand:QI 2 "register_operand" "a"))))]
2517 "AVR_HAVE_MUL"
2518 "#"
2519 "&& reload_completed"
2520 [(parallel [(set (match_dup 0)
2521 (mult:HI (sign_extend:HI (match_dup 1))
2522 (zero_extend:HI (match_dup 2))))
2523 (clobber (reg:CC REG_CC))])])
2524
2525 (define_insn "*sumulqihi3"
2526 [(set (match_operand:HI 0 "register_operand" "=r")
2527 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "a"))
2528 (zero_extend:HI (match_operand:QI 2 "register_operand" "a"))))
2529 (clobber (reg:CC REG_CC))]
2530 "AVR_HAVE_MUL && reload_completed"
2531 "mulsu %1,%2
2532 movw %0,r0
2533 clr __zero_reg__"
2534 [(set_attr "length" "3")])
2535
2536 ;; One-extend operand 1
2537
2538 (define_insn_and_split "*osmulqihi3_split"
2539 [(set (match_operand:HI 0 "register_operand" "=&r")
2540 (mult:HI (not:HI (zero_extend:HI (not:QI (match_operand:QI 1 "register_operand" "a"))))
2541 (sign_extend:HI (match_operand:QI 2 "register_operand" "a"))))]
2542 "AVR_HAVE_MUL"
2543 "#"
2544 "&& reload_completed"
2545 [(parallel [(set (match_dup 0)
2546 (mult:HI (not:HI (zero_extend:HI (not:QI (match_dup 1))))
2547 (sign_extend:HI (match_dup 2))))
2548 (clobber (reg:CC REG_CC))])])
2549
2550 (define_insn "*osmulqihi3"
2551 [(set (match_operand:HI 0 "register_operand" "=&r")
2552 (mult:HI (not:HI (zero_extend:HI (not:QI (match_operand:QI 1 "register_operand" "a"))))
2553 (sign_extend:HI (match_operand:QI 2 "register_operand" "a"))))
2554 (clobber (reg:CC REG_CC))]
2555 "AVR_HAVE_MUL && reload_completed"
2556 "mulsu %2,%1
2557 movw %0,r0
2558 sub %B0,%2
2559 clr __zero_reg__"
2560 [(set_attr "length" "4")])
2561
2562 (define_insn_and_split "*oumulqihi3_split"
2563 [(set (match_operand:HI 0 "register_operand" "=&r")
2564 (mult:HI (not:HI (zero_extend:HI (not:QI (match_operand:QI 1 "register_operand" "r"))))
2565 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
2566 "AVR_HAVE_MUL"
2567 "#"
2568 "&& reload_completed"
2569 [(parallel [(set (match_dup 0)
2570 (mult:HI (not:HI (zero_extend:HI (not:QI (match_dup 1))))
2571 (zero_extend:HI (match_dup 2))))
2572 (clobber (reg:CC REG_CC))])])
2573
2574 (define_insn "*oumulqihi3"
2575 [(set (match_operand:HI 0 "register_operand" "=&r")
2576 (mult:HI (not:HI (zero_extend:HI (not:QI (match_operand:QI 1 "register_operand" "r"))))
2577 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))
2578 (clobber (reg:CC REG_CC))]
2579 "AVR_HAVE_MUL && reload_completed"
2580 "mul %2,%1
2581 movw %0,r0
2582 sub %B0,%2
2583 clr __zero_reg__"
2584 [(set_attr "length" "4")])
2585
2586 ;******************************************************************************
2587 ; multiply-add/sub QI: $0 = $3 +/- $1*$2
2588 ;******************************************************************************
2589
2590 (define_insn_and_split "*maddqi4_split"
2591 [(set (match_operand:QI 0 "register_operand" "=r")
2592 (plus:QI (mult:QI (match_operand:QI 1 "register_operand" "r")
2593 (match_operand:QI 2 "register_operand" "r"))
2594 (match_operand:QI 3 "register_operand" "0")))]
2595
2596 "AVR_HAVE_MUL"
2597 "#"
2598 "&& reload_completed"
2599 [(parallel [(set (match_dup 0)
2600 (plus:QI (mult:QI (match_dup 1)
2601 (match_dup 2))
2602 (match_dup 3)))
2603 (clobber (reg:CC REG_CC))])])
2604
2605 (define_insn "*maddqi4"
2606 [(set (match_operand:QI 0 "register_operand" "=r")
2607 (plus:QI (mult:QI (match_operand:QI 1 "register_operand" "r")
2608 (match_operand:QI 2 "register_operand" "r"))
2609 (match_operand:QI 3 "register_operand" "0")))
2610 (clobber (reg:CC REG_CC))]
2611 "AVR_HAVE_MUL && reload_completed"
2612 "mul %1,%2
2613 add %A0,r0
2614 clr __zero_reg__"
2615 [(set_attr "length" "4")])
2616
2617 (define_insn_and_split "*msubqi4_split"
2618 [(set (match_operand:QI 0 "register_operand" "=r")
2619 (minus:QI (match_operand:QI 3 "register_operand" "0")
2620 (mult:QI (match_operand:QI 1 "register_operand" "r")
2621 (match_operand:QI 2 "register_operand" "r"))))]
2622 "AVR_HAVE_MUL"
2623 "#"
2624 "&& reload_completed"
2625 [(parallel [(set (match_dup 0)
2626 (minus:QI (match_dup 3)
2627 (mult:QI (match_dup 1)
2628 (match_dup 2))))
2629 (clobber (reg:CC REG_CC))])])
2630
2631 (define_insn "*msubqi4"
2632 [(set (match_operand:QI 0 "register_operand" "=r")
2633 (minus:QI (match_operand:QI 3 "register_operand" "0")
2634 (mult:QI (match_operand:QI 1 "register_operand" "r")
2635 (match_operand:QI 2 "register_operand" "r"))))
2636 (clobber (reg:CC REG_CC))]
2637 "AVR_HAVE_MUL && reload_completed"
2638 "mul %1,%2
2639 sub %A0,r0
2640 clr __zero_reg__"
2641 [(set_attr "length" "4")])
2642
2643 (define_insn_and_split "*maddqi4.const"
2644 [(set (match_operand:QI 0 "register_operand" "=r")
2645 (plus:QI (mult:QI (match_operand:QI 1 "register_operand" "r")
2646 (match_operand:QI 2 "const_int_operand" "n"))
2647 (match_operand:QI 3 "register_operand" "0")))
2648 (clobber (match_scratch:QI 4 "=&d"))]
2649 "AVR_HAVE_MUL"
2650 "#"
2651 "&& reload_completed"
2652 [(set (match_dup 4)
2653 (match_dup 2))
2654 ; *maddqi4
2655 (set (match_dup 0)
2656 (plus:QI (mult:QI (match_dup 1)
2657 (match_dup 4))
2658 (match_dup 3)))])
2659
2660 (define_insn_and_split "*msubqi4.const"
2661 [(set (match_operand:QI 0 "register_operand" "=r")
2662 (minus:QI (match_operand:QI 3 "register_operand" "0")
2663 (mult:QI (match_operand:QI 1 "register_operand" "r")
2664 (match_operand:QI 2 "const_int_operand" "n"))))
2665 (clobber (match_scratch:QI 4 "=&d"))]
2666 "AVR_HAVE_MUL"
2667 "#"
2668 "&& reload_completed"
2669 [(set (match_dup 4)
2670 (match_dup 2))
2671 ; *msubqi4
2672 (set (match_dup 0)
2673 (minus:QI (match_dup 3)
2674 (mult:QI (match_dup 1)
2675 (match_dup 4))))])
2676
2677
2678 ;******************************************************************************
2679 ; multiply-add/sub HI: $0 = $3 +/- $1*$2 with 8-bit values $1, $2
2680 ;******************************************************************************
2681
2682 ;; We don't use standard insns/expanders as they lead to cumbersome code for,
2683 ;; e.g,
2684 ;;
2685 ;; int foo (unsigned char z)
2686 ;; {
2687 ;; extern int aInt[];
2688 ;; return aInt[3*z+2];
2689 ;; }
2690 ;;
2691 ;; because the constant +4 then is added explicitely instead of consuming it
2692 ;; with the aInt symbol. Therefore, we rely on insn combine which takes costs
2693 ;; into account more accurately and doesn't do burte-force multiply-add/sub.
2694 ;; The implementational effort is the same so we are fine with that approach.
2695
2696
2697 ;; "*maddqihi4"
2698 ;; "*umaddqihi4"
2699 (define_insn_and_split "*<extend_u>maddqihi4_split"
2700 [(set (match_operand:HI 0 "register_operand" "=r")
2701 (plus:HI (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2702 (any_extend:HI (match_operand:QI 2 "register_operand" "<mul_r_d>")))
2703 (match_operand:HI 3 "register_operand" "0")))]
2704
2705 "AVR_HAVE_MUL"
2706 "#"
2707 "&& reload_completed"
2708 [(parallel [(set (match_dup 0)
2709 (plus:HI (mult:HI (any_extend:HI (match_dup 1))
2710 (any_extend:HI (match_dup 2)))
2711 (match_dup 3)))
2712 (clobber (reg:CC REG_CC))])])
2713
2714 (define_insn "*<extend_u>maddqihi4"
2715 [(set (match_operand:HI 0 "register_operand" "=r")
2716 (plus:HI (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2717 (any_extend:HI (match_operand:QI 2 "register_operand" "<mul_r_d>")))
2718 (match_operand:HI 3 "register_operand" "0")))
2719 (clobber (reg:CC REG_CC))]
2720 "AVR_HAVE_MUL && reload_completed"
2721 "mul<extend_s> %1,%2
2722 add %A0,r0
2723 adc %B0,r1
2724 clr __zero_reg__"
2725 [(set_attr "length" "4")])
2726
2727 ;; "*msubqihi4"
2728 ;; "*umsubqihi4"
2729 (define_insn_and_split "*<extend_u>msubqihi4_split"
2730 [(set (match_operand:HI 0 "register_operand" "=r")
2731 (minus:HI (match_operand:HI 3 "register_operand" "0")
2732 (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2733 (any_extend:HI (match_operand:QI 2 "register_operand" "<mul_r_d>")))))]
2734 "AVR_HAVE_MUL"
2735 "#"
2736 "&& reload_completed"
2737 [(parallel [(set (match_dup 0)
2738 (minus:HI (match_dup 3)
2739 (mult:HI (any_extend:HI (match_dup 1))
2740 (any_extend:HI (match_dup 2)))))
2741 (clobber (reg:CC REG_CC))])])
2742
2743 (define_insn "*<extend_u>msubqihi4"
2744 [(set (match_operand:HI 0 "register_operand" "=r")
2745 (minus:HI (match_operand:HI 3 "register_operand" "0")
2746 (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2747 (any_extend:HI (match_operand:QI 2 "register_operand" "<mul_r_d>")))))
2748 (clobber (reg:CC REG_CC))]
2749 "AVR_HAVE_MUL && reload_completed"
2750 "mul<extend_s> %1,%2
2751 sub %A0,r0
2752 sbc %B0,r1
2753 clr __zero_reg__"
2754 [(set_attr "length" "4")])
2755
2756 ;; "*usmaddqihi4"
2757 ;; "*sumaddqihi4"
2758 (define_insn_and_split "*<any_extend:extend_su><any_extend2:extend_su>msubqihi4_split"
2759 [(set (match_operand:HI 0 "register_operand" "=r")
2760 (plus:HI (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "a"))
2761 (any_extend2:HI (match_operand:QI 2 "register_operand" "a")))
2762 (match_operand:HI 3 "register_operand" "0")))]
2763 "AVR_HAVE_MUL
2764 && reload_completed
2765 && <any_extend:CODE> != <any_extend2:CODE>"
2766 "#"
2767 "&& reload_completed"
2768 [(parallel [(set (match_dup 0)
2769 (plus:HI (mult:HI (any_extend:HI (match_dup 1))
2770 (any_extend2:HI (match_dup 2)))
2771 (match_dup 3)))
2772 (clobber (reg:CC REG_CC))])])
2773
2774 (define_insn "*<any_extend:extend_su><any_extend2:extend_su>msubqihi4"
2775 [(set (match_operand:HI 0 "register_operand" "=r")
2776 (plus:HI (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "a"))
2777 (any_extend2:HI (match_operand:QI 2 "register_operand" "a")))
2778 (match_operand:HI 3 "register_operand" "0")))
2779 (clobber (reg:CC REG_CC))]
2780 "AVR_HAVE_MUL
2781 && reload_completed
2782 && <any_extend:CODE> != <any_extend2:CODE>"
2783 {
2784 output_asm_insn (<any_extend:CODE> == SIGN_EXTEND
2785 ? "mulsu %1,%2" : "mulsu %2,%1", operands);
2786
2787 return "add %A0,r0\;adc %B0,r1\;clr __zero_reg__";
2788 }
2789 [(set_attr "length" "4")])
2790
2791 ;; "*usmsubqihi4"
2792 ;; "*sumsubqihi4"
2793 (define_insn_and_split "*<any_extend:extend_su><any_extend2:extend_su>msubqihi4_split"
2794 [(set (match_operand:HI 0 "register_operand" "=r")
2795 (minus:HI (match_operand:HI 3 "register_operand" "0")
2796 (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "a"))
2797 (any_extend2:HI (match_operand:QI 2 "register_operand" "a")))))]
2798 "AVR_HAVE_MUL
2799 && reload_completed
2800 && <any_extend:CODE> != <any_extend2:CODE>"
2801 "#"
2802 "&& reload_completed"
2803 [(parallel [(set (match_dup 0)
2804 (minus:HI (match_dup 3)
2805 (mult:HI (any_extend:HI (match_dup 1))
2806 (any_extend2:HI (match_dup 2)))))
2807 (clobber (reg:CC REG_CC))])])
2808
2809 (define_insn "*<any_extend:extend_su><any_extend2:extend_su>msubqihi4"
2810 [(set (match_operand:HI 0 "register_operand" "=r")
2811 (minus:HI (match_operand:HI 3 "register_operand" "0")
2812 (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "a"))
2813 (any_extend2:HI (match_operand:QI 2 "register_operand" "a")))))
2814 (clobber (reg:CC REG_CC))]
2815 "AVR_HAVE_MUL
2816 && reload_completed
2817 && <any_extend:CODE> != <any_extend2:CODE>"
2818 {
2819 output_asm_insn (<any_extend:CODE> == SIGN_EXTEND
2820 ? "mulsu %1,%2" : "mulsu %2,%1", operands);
2821
2822 return "sub %A0,r0\;sbc %B0,r1\;clr __zero_reg__";
2823 }
2824 [(set_attr "length" "4")])
2825
2826 ;; Handle small constants
2827
2828 ;; Special case of a += 2*b as frequently seen with accesses to int arrays.
2829 ;; This is shorter, faster than MUL and has lower register pressure.
2830 ;; See also "*addhi3_zero_extend.ashift1".
2831 (define_insn_and_split "*umaddqihi4.2"
2832 [(set (match_operand:HI 0 "register_operand" "=r")
2833 (plus:HI (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
2834 (const_int 2))
2835 (match_operand:HI 2 "register_operand" "r")))]
2836 "!reload_completed
2837 && !reg_overlap_mentioned_p (operands[0], operands[1])"
2838 { gcc_unreachable(); }
2839 "&& 1"
2840 [(set (match_dup 0)
2841 (match_dup 2))
2842 ; *addhi3_zero_extend
2843 (set (match_dup 0)
2844 (plus:HI (zero_extend:HI (match_dup 1))
2845 (match_dup 0)))
2846 ; *addhi3_zero_extend
2847 (set (match_dup 0)
2848 (plus:HI (zero_extend:HI (match_dup 1))
2849 (match_dup 0)))])
2850
2851 ;; "umaddqihi4.uconst"
2852 ;; "maddqihi4.sconst"
2853 (define_insn_and_split "*<extend_u>maddqihi4.<extend_su>const"
2854 [(set (match_operand:HI 0 "register_operand" "=r")
2855 (plus:HI (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2856 (match_operand:HI 2 "<extend_su>8_operand" "n"))
2857 (match_operand:HI 3 "register_operand" "0")))
2858 (clobber (match_scratch:QI 4 "=&d"))]
2859 "AVR_HAVE_MUL"
2860 "#"
2861 "&& reload_completed"
2862 [(set (match_dup 4)
2863 (match_dup 2))
2864 ; *umaddqihi4 resp. *maddqihi4
2865 (set (match_dup 0)
2866 (plus:HI (mult:HI (any_extend:HI (match_dup 1))
2867 (any_extend:HI (match_dup 4)))
2868 (match_dup 3)))]
2869 {
2870 operands[2] = gen_int_mode (INTVAL (operands[2]), QImode);
2871 })
2872
2873 ;; "*umsubqihi4.uconst"
2874 ;; "*msubqihi4.sconst"
2875 (define_insn_and_split "*<extend_u>msubqihi4.<extend_su>const"
2876 [(set (match_operand:HI 0 "register_operand" "=r")
2877 (minus:HI (match_operand:HI 3 "register_operand" "0")
2878 (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2879 (match_operand:HI 2 "<extend_su>8_operand" "n"))))
2880 (clobber (match_scratch:QI 4 "=&d"))]
2881 "AVR_HAVE_MUL"
2882 "#"
2883 "&& reload_completed"
2884 [(set (match_dup 4)
2885 (match_dup 2))
2886 ; *umsubqihi4 resp. *msubqihi4
2887 (set (match_dup 0)
2888 (minus:HI (match_dup 3)
2889 (mult:HI (any_extend:HI (match_dup 1))
2890 (any_extend:HI (match_dup 4)))))]
2891 {
2892 operands[2] = gen_int_mode (INTVAL (operands[2]), QImode);
2893 })
2894
2895 ;; Same as the insn above, but combiner tries versions canonicalized to ASHIFT
2896 ;; for MULT with power of 2 and skips trying MULT insn above.
2897
2898 (define_insn_and_split "*umsubqihi4.uconst.ashift"
2899 [(set (match_operand:HI 0 "register_operand" "=r")
2900 (minus:HI (match_operand:HI 3 "register_operand" "0")
2901 (ashift:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
2902 (match_operand:HI 2 "const_2_to_7_operand" "n"))))
2903 (clobber (match_scratch:QI 4 "=&d"))]
2904 "AVR_HAVE_MUL"
2905 "#"
2906 "&& reload_completed"
2907 [(set (match_dup 4)
2908 (match_dup 2))
2909 ; *umsubqihi4
2910 (set (match_dup 0)
2911 (minus:HI (match_dup 3)
2912 (mult:HI (zero_extend:HI (match_dup 1))
2913 (zero_extend:HI (match_dup 4)))))]
2914 {
2915 operands[2] = gen_int_mode (1 << INTVAL (operands[2]), QImode);
2916 })
2917
2918 ;; Same as the insn above, but combiner tries versions canonicalized to ASHIFT
2919 ;; for MULT with power of 2 and skips trying MULT insn above. We omit 128
2920 ;; because this would require an extra pattern for just one value.
2921
2922 (define_insn_and_split "*msubqihi4.sconst.ashift"
2923 [(set (match_operand:HI 0 "register_operand" "=r")
2924 (minus:HI (match_operand:HI 3 "register_operand" "0")
2925 (ashift:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "d"))
2926 (match_operand:HI 2 "const_1_to_6_operand" "M"))))
2927 (clobber (match_scratch:QI 4 "=&d"))]
2928 "AVR_HAVE_MUL"
2929 "#"
2930 "&& reload_completed"
2931 [(set (match_dup 4)
2932 (match_dup 2))
2933 ; *smsubqihi4
2934 (set (match_dup 0)
2935 (minus:HI (match_dup 3)
2936 (mult:HI (sign_extend:HI (match_dup 1))
2937 (sign_extend:HI (match_dup 4)))))]
2938 {
2939 operands[2] = gen_int_mode (1 << INTVAL (operands[2]), QImode);
2940 })
2941
2942 ;; For signed/unsigned combinations that require narrow constraint "a"
2943 ;; just provide a pattern if signed/unsigned combination is actually needed.
2944
2945 (define_insn_and_split "*sumaddqihi4.uconst"
2946 [(set (match_operand:HI 0 "register_operand" "=r")
2947 (plus:HI (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "a"))
2948 (match_operand:HI 2 "u8_operand" "M"))
2949 (match_operand:HI 3 "register_operand" "0")))
2950 (clobber (match_scratch:QI 4 "=&a"))]
2951 "AVR_HAVE_MUL
2952 && !s8_operand (operands[2], VOIDmode)"
2953 "#"
2954 "&& reload_completed"
2955 [(set (match_dup 4)
2956 (match_dup 2))
2957 ; *sumaddqihi4
2958 (set (match_dup 0)
2959 (plus:HI (mult:HI (sign_extend:HI (match_dup 1))
2960 (zero_extend:HI (match_dup 4)))
2961 (match_dup 3)))]
2962 {
2963 operands[2] = gen_int_mode (INTVAL (operands[2]), QImode);
2964 })
2965
2966 (define_insn_and_split "*sumsubqihi4.uconst"
2967 [(set (match_operand:HI 0 "register_operand" "=r")
2968 (minus:HI (match_operand:HI 3 "register_operand" "0")
2969 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "a"))
2970 (match_operand:HI 2 "u8_operand" "M"))))
2971 (clobber (match_scratch:QI 4 "=&a"))]
2972 "AVR_HAVE_MUL
2973 && !s8_operand (operands[2], VOIDmode)"
2974 "#"
2975 "&& reload_completed"
2976 [(set (match_dup 4)
2977 (match_dup 2))
2978 ; *sumsubqihi4
2979 (set (match_dup 0)
2980 (minus:HI (match_dup 3)
2981 (mult:HI (sign_extend:HI (match_dup 1))
2982 (zero_extend:HI (match_dup 4)))))]
2983 {
2984 operands[2] = gen_int_mode (INTVAL (operands[2]), QImode);
2985 })
2986
2987 ;******************************************************************************
2988 ; mul HI: $1 = sign/zero-extend, $2 = small constant
2989 ;******************************************************************************
2990
2991 ;; "*muluqihi3.uconst"
2992 ;; "*mulsqihi3.sconst"
2993 (define_insn_and_split "*mul<extend_su>qihi3.<extend_su>const"
2994 [(set (match_operand:HI 0 "register_operand" "=r")
2995 (mult:HI (any_extend:HI (match_operand:QI 1 "register_operand" "<mul_r_d>"))
2996 (match_operand:HI 2 "<extend_su>8_operand" "n")))
2997 (clobber (match_scratch:QI 3 "=&d"))]
2998 "AVR_HAVE_MUL"
2999 "#"
3000 "&& reload_completed"
3001 [(set (match_dup 3)
3002 (match_dup 2))
3003 ; umulqihi3 resp. mulqihi3
3004 (set (match_dup 0)
3005 (mult:HI (any_extend:HI (match_dup 1))
3006 (any_extend:HI (match_dup 3))))]
3007 {
3008 operands[2] = gen_int_mode (INTVAL (operands[2]), QImode);
3009 })
3010
3011 (define_insn_and_split "*muluqihi3.sconst"
3012 [(set (match_operand:HI 0 "register_operand" "=r")
3013 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "a"))
3014 (match_operand:HI 2 "s8_operand" "n")))
3015 (clobber (match_scratch:QI 3 "=&a"))]
3016 "AVR_HAVE_MUL"
3017 "#"
3018 "&& reload_completed"
3019 [(set (match_dup 3)
3020 (match_dup 2))
3021 ; usmulqihi3
3022 (set (match_dup 0)
3023 (mult:HI (zero_extend:HI (match_dup 1))
3024 (sign_extend:HI (match_dup 3))))]
3025 {
3026 operands[2] = gen_int_mode (INTVAL (operands[2]), QImode);
3027 })
3028
3029 (define_insn_and_split "*mulsqihi3.uconst"
3030 [(set (match_operand:HI 0 "register_operand" "=r")
3031 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "a"))
3032 (match_operand:HI 2 "u8_operand" "M")))
3033 (clobber (match_scratch:QI 3 "=&a"))]
3034 "AVR_HAVE_MUL"
3035 "#"
3036 "&& reload_completed"
3037 [(set (match_dup 3)
3038 (match_dup 2))
3039 ; usmulqihi3
3040 (set (match_dup 0)
3041 (mult:HI (zero_extend:HI (match_dup 3))
3042 (sign_extend:HI (match_dup 1))))]
3043 {
3044 operands[2] = gen_int_mode (INTVAL (operands[2]), QImode);
3045 })
3046
3047 (define_insn_and_split "*mulsqihi3.oconst"
3048 [(set (match_operand:HI 0 "register_operand" "=&r")
3049 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "a"))
3050 (match_operand:HI 2 "o8_operand" "n")))
3051 (clobber (match_scratch:QI 3 "=&a"))]
3052 "AVR_HAVE_MUL"
3053 "#"
3054 "&& reload_completed"
3055 [(set (match_dup 3)
3056 (match_dup 2))
3057 ; *osmulqihi3
3058 (set (match_dup 0)
3059 (mult:HI (not:HI (zero_extend:HI (not:QI (match_dup 3))))
3060 (sign_extend:HI (match_dup 1))))]
3061 {
3062 operands[2] = gen_int_mode (INTVAL (operands[2]), QImode);
3063 })
3064
3065 ;; The EXTEND of $1 only appears in combine, we don't see it in expand so that
3066 ;; expand decides to use ASHIFT instead of MUL because ASHIFT costs are cheaper
3067 ;; at that time. Fix that.
3068 (define_insn_and_split "*ashiftqihi2.signx.1_split"
3069 [(set (match_operand:HI 0 "register_operand" "=r,*r")
3070 (ashift:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "0,r"))
3071 (const_int 1)))]
3072 ""
3073 "#"
3074 "&& reload_completed"
3075 [(parallel [(set (match_dup 0)
3076 (ashift:HI (sign_extend:HI (match_dup 1))
3077 (const_int 1)))
3078 (clobber (reg:CC REG_CC))])])
3079
3080 (define_insn "*ashiftqihi2.signx.1"
3081 [(set (match_operand:HI 0 "register_operand" "=r,*r")
3082 (ashift:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "0,r"))
3083 (const_int 1)))
3084 (clobber (reg:CC REG_CC)) ]
3085 "reload_completed"
3086 "@
3087 lsl %A0\;sbc %B0,%B0
3088 mov %A0,%1\;lsl %A0\;sbc %B0,%B0"
3089 [(set_attr "length" "2,3")])
3090
3091 (define_insn_and_split "*ashifthi3.signx.const"
3092 [(set (match_operand:HI 0 "register_operand" "=r")
3093 (ashift:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "d"))
3094 (match_operand:HI 2 "const_2_to_6_operand" "I")))
3095 (clobber (match_scratch:QI 3 "=&d"))]
3096 "AVR_HAVE_MUL"
3097 "#"
3098 "&& reload_completed"
3099 [(set (match_dup 3)
3100 (match_dup 2))
3101 ; mulqihi3
3102 (set (match_dup 0)
3103 (mult:HI (sign_extend:HI (match_dup 1))
3104 (sign_extend:HI (match_dup 3))))]
3105 {
3106 operands[2] = GEN_INT (1 << INTVAL (operands[2]));
3107 })
3108
3109 (define_insn_and_split "*ashifthi3.signx.const7"
3110 [(set (match_operand:HI 0 "register_operand" "=r")
3111 (ashift:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "a"))
3112 (const_int 7)))
3113 (clobber (match_scratch:QI 2 "=&a"))]
3114 "AVR_HAVE_MUL"
3115 "#"
3116 "&& reload_completed"
3117 [(set (match_dup 2)
3118 (match_dup 3))
3119 ; usmulqihi3
3120 (set (match_dup 0)
3121 (mult:HI (zero_extend:HI (match_dup 2))
3122 (sign_extend:HI (match_dup 1))))]
3123 {
3124 operands[3] = gen_int_mode (1 << 7, QImode);
3125 })
3126
3127 (define_insn_and_split "*ashifthi3.zerox.const"
3128 [(set (match_operand:HI 0 "register_operand" "=r")
3129 (ashift:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
3130 (match_operand:HI 2 "const_2_to_7_operand" "I")))
3131 (clobber (match_scratch:QI 3 "=&d"))]
3132 "AVR_HAVE_MUL"
3133 "#"
3134 "&& reload_completed"
3135 [(set (match_dup 3)
3136 (match_dup 2))
3137 ; umulqihi3
3138 (set (match_dup 0)
3139 (mult:HI (zero_extend:HI (match_dup 1))
3140 (zero_extend:HI (match_dup 3))))]
3141 {
3142 operands[2] = gen_int_mode (1 << INTVAL (operands[2]), QImode);
3143 })
3144
3145 ;******************************************************************************
3146 ; mul HI: $1 = sign-/zero-/one-extend, $2 = reg
3147 ;******************************************************************************
3148
3149 (define_insn_and_split "mulsqihi3"
3150 [(set (match_operand:HI 0 "register_operand" "=&r")
3151 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "a"))
3152 (match_operand:HI 2 "register_operand" "a")))]
3153 "AVR_HAVE_MUL"
3154 "#"
3155 "&& reload_completed"
3156 [(parallel [(set (match_dup 0)
3157 (mult:HI (sign_extend:HI (match_dup 1))
3158 (match_dup 2)))
3159 (clobber (reg:CC REG_CC))])])
3160
3161 (define_insn "*mulsqihi3"
3162 [(set (match_operand:HI 0 "register_operand" "=&r")
3163 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "a"))
3164 (match_operand:HI 2 "register_operand" "a")))
3165 (clobber (reg:CC REG_CC))]
3166 "AVR_HAVE_MUL && reload_completed"
3167 "mulsu %1,%A2
3168 movw %0,r0
3169 mul %1,%B2
3170 add %B0,r0
3171 clr __zero_reg__"
3172 [(set_attr "length" "5")])
3173
3174 (define_insn_and_split "muluqihi3"
3175 [(set (match_operand:HI 0 "register_operand" "=&r")
3176 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
3177 (match_operand:HI 2 "register_operand" "r")))]
3178 "AVR_HAVE_MUL"
3179 "#"
3180 "&& reload_completed"
3181 [(parallel [(set (match_dup 0)
3182 (mult:HI (zero_extend:HI (match_dup 1))
3183 (match_dup 2)))
3184 (clobber (reg:CC REG_CC))])])
3185
3186 (define_insn "*muluqihi3"
3187 [(set (match_operand:HI 0 "register_operand" "=&r")
3188 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
3189 (match_operand:HI 2 "register_operand" "r")))
3190 (clobber (reg:CC REG_CC))]
3191 "AVR_HAVE_MUL && reload_completed"
3192 "mul %1,%A2
3193 movw %0,r0
3194 mul %1,%B2
3195 add %B0,r0
3196 clr __zero_reg__"
3197 [(set_attr "length" "5")])
3198
3199 ;; one-extend operand 1
3200
3201 (define_insn_and_split "muloqihi3"
3202 [(set (match_operand:HI 0 "register_operand" "=&r")
3203 (mult:HI (not:HI (zero_extend:HI (not:QI (match_operand:QI 1 "register_operand" "r"))))
3204 (match_operand:HI 2 "register_operand" "r")))]
3205 "AVR_HAVE_MUL"
3206 "#"
3207 "&& reload_completed"
3208 [(parallel [(set (match_dup 0)
3209 (mult:HI (not:HI (zero_extend:HI (not:QI (match_dup 1))))
3210 (match_dup 2)))
3211 (clobber (reg:CC REG_CC))])])
3212
3213 (define_insn "*muloqihi3"
3214 [(set (match_operand:HI 0 "register_operand" "=&r")
3215 (mult:HI (not:HI (zero_extend:HI (not:QI (match_operand:QI 1 "register_operand" "r"))))
3216 (match_operand:HI 2 "register_operand" "r")))
3217 (clobber (reg:CC REG_CC))]
3218 "AVR_HAVE_MUL && reload_completed"
3219 "mul %1,%A2
3220 movw %0,r0
3221 mul %1,%B2
3222 add %B0,r0
3223 sub %B0,%A2
3224 clr __zero_reg__"
3225 [(set_attr "length" "6")])
3226
3227 ;******************************************************************************
3228
3229 (define_expand "mulhi3"
3230 [(set (match_operand:HI 0 "register_operand" "")
3231 (mult:HI (match_operand:HI 1 "register_operand" "")
3232 (match_operand:HI 2 "register_or_s9_operand" "")))]
3233 ""
3234 {
3235 if (!AVR_HAVE_MUL)
3236 {
3237 if (!register_operand (operands[2], HImode))
3238 operands[2] = force_reg (HImode, operands[2]);
3239
3240 emit_insn (gen_mulhi3_call (operands[0], operands[1], operands[2]));
3241 DONE;
3242 }
3243
3244 // For small constants we can do better by extending them on the fly.
3245 // The constant can be loaded in one instruction and the widening
3246 // multiplication is shorter. First try the unsigned variant because it
3247 // allows constraint "d" instead of "a" for the signed version. */
3248
3249 if (s9_operand (operands[2], HImode))
3250 {
3251 rtx reg = force_reg (QImode, gen_int_mode (INTVAL (operands[2]), QImode));
3252
3253 if (u8_operand (operands[2], HImode))
3254 {
3255 emit_insn (gen_muluqihi3 (operands[0], reg, operands[1]));
3256 }
3257 else if (s8_operand (operands[2], HImode))
3258 {
3259 emit_insn (gen_mulsqihi3 (operands[0], reg, operands[1]));
3260 }
3261 else
3262 {
3263 emit_insn (gen_muloqihi3 (operands[0], reg, operands[1]));
3264 }
3265
3266 DONE;
3267 }
3268
3269 if (!register_operand (operands[2], HImode))
3270 operands[2] = force_reg (HImode, operands[2]);
3271 })
3272
3273 (define_insn_and_split "*mulhi3_enh_split"
3274 [(set (match_operand:HI 0 "register_operand" "=&r")
3275 (mult:HI (match_operand:HI 1 "register_operand" "r")
3276 (match_operand:HI 2 "register_operand" "r")))]
3277 "AVR_HAVE_MUL"
3278 "#"
3279 "&& reload_completed"
3280 [(parallel [(set (match_dup 0)
3281 (mult:HI (match_dup 1)
3282 (match_dup 2)))
3283 (clobber (reg:CC REG_CC))])])
3284
3285 (define_insn "*mulhi3_enh"
3286 [(set (match_operand:HI 0 "register_operand" "=&r")
3287 (mult:HI (match_operand:HI 1 "register_operand" "r")
3288 (match_operand:HI 2 "register_operand" "r")))
3289 (clobber (reg:CC REG_CC))]
3290 "AVR_HAVE_MUL && reload_completed"
3291 {
3292 return REGNO (operands[1]) == REGNO (operands[2])
3293 ? "mul %A1,%A1\;movw %0,r0\;mul %A1,%B1\;add %B0,r0\;add %B0,r0\;clr r1"
3294 : "mul %A1,%A2\;movw %0,r0\;mul %A1,%B2\;add %B0,r0\;mul %B1,%A2\;add %B0,r0\;clr r1";
3295 }
3296 [(set (attr "length")
3297 (symbol_ref ("7 - (REGNO (operands[1]) == REGNO (operands[2]))")))])
3298
3299 (define_expand "mulhi3_call"
3300 [(set (reg:HI 24) (match_operand:HI 1 "register_operand" ""))
3301 (set (reg:HI 22) (match_operand:HI 2 "register_operand" ""))
3302 (parallel [(set (reg:HI 24)
3303 (mult:HI (reg:HI 24) (reg:HI 22)))
3304 (clobber (reg:HI 22))
3305 (clobber (reg:QI 21))])
3306 (set (match_operand:HI 0 "register_operand" "")
3307 (reg:HI 24))]
3308 ""
3309 {
3310 avr_fix_inputs (operands, (1 << 2), regmask (HImode, 24));
3311 })
3312
3313
3314 (define_insn_and_split "*mulhi3_call_split"
3315 [(set (reg:HI 24)
3316 (mult:HI (reg:HI 24) (reg:HI 22)))
3317 (clobber (reg:HI 22))
3318 (clobber (reg:QI 21))]
3319 "!AVR_HAVE_MUL"
3320 "#"
3321 "&& reload_completed"
3322 [(parallel [(set (reg:HI 24)
3323 (mult:HI (reg:HI 24) (reg:HI 22)))
3324 (clobber (reg:HI 22))
3325 (clobber (reg:QI 21))
3326 (clobber (reg:CC REG_CC))])])
3327
3328 (define_insn "*mulhi3_call"
3329 [(set (reg:HI 24)
3330 (mult:HI (reg:HI 24) (reg:HI 22)))
3331 (clobber (reg:HI 22))
3332 (clobber (reg:QI 21))
3333 (clobber (reg:CC REG_CC))]
3334 "!AVR_HAVE_MUL && reload_completed"
3335 "%~call __mulhi3"
3336 [(set_attr "type" "xcall")])
3337
3338 ;; To support widening multiplication with constant we postpone
3339 ;; expanding to the implicit library call until post combine and
3340 ;; prior to register allocation. Clobber all hard registers that
3341 ;; might be used by the (widening) multiply until it is split and
3342 ;; it's final register footprint is worked out.
3343
3344 (define_expand "mulsi3"
3345 [(parallel [(set (match_operand:SI 0 "register_operand" "")
3346 (mult:SI (match_operand:SI 1 "register_operand" "")
3347 (match_operand:SI 2 "nonmemory_operand" "")))
3348 (clobber (reg:HI 26))
3349 (clobber (reg:DI 18))])]
3350 "AVR_HAVE_MUL
3351 || (avropt_pr118012
3352 /* AVR_TINY passes args on the stack, so we cannot work
3353 around PR118012 like this. */
3354 && ! AVR_TINY)"
3355 {
3356 if (! AVR_HAVE_MUL)
3357 {
3358 emit (gen_gen_mulsi3_pr118012 (operands[0], operands[1], operands[2]));
3359 DONE;
3360 }
3361
3362 if (u16_operand (operands[2], SImode))
3363 {
3364 operands[2] = force_reg (HImode, gen_int_mode (INTVAL (operands[2]), HImode));
3365 emit_insn (gen_muluhisi3 (operands[0], operands[2], operands[1]));
3366 DONE;
3367 }
3368
3369 if (o16_operand (operands[2], SImode))
3370 {
3371 operands[2] = force_reg (HImode, gen_int_mode (INTVAL (operands[2]), HImode));
3372 emit_insn (gen_mulohisi3 (operands[0], operands[2], operands[1]));
3373 DONE;
3374 }
3375
3376 if (avr_emit3_fix_outputs (gen_mulsi3, operands, 1 << 0,
3377 regmask (DImode, 18) | regmask (HImode, 26)))
3378 DONE;
3379 })
3380
3381 ;; With PR118012, we do __mulsi3 as a transparent call, so insn combine
3382 ;; can transform (mult:SI (and:SI * (const_int 1))) into something
3383 ;; less toxic.
3384 (define_expand "gen_mulsi3_pr118012"
3385 [(parallel [(set (match_operand:SI 0 "register_operand")
3386 (mult:SI (match_operand:SI 1 "register_operand")
3387 (match_operand:SI 2 "nonmemory_operand")))
3388 (clobber (reg:HI 26))
3389 (clobber (reg:HI 30))
3390 (clobber (reg:DI 18))])]
3391 "avropt_pr118012
3392 && ! AVR_HAVE_MUL
3393 && ! AVR_TINY"
3394 {
3395 operands[2] = force_reg (SImode, operands[2]);
3396 if (avr_emit3_fix_outputs (gen_gen_mulsi3_pr118012, operands, 1 << 0,
3397 regmask (DImode, 18) | regmask (HImode, 26) | regmask (HImode, 30)))
3398 DONE;
3399 })
3400
3401 (define_insn_and_split "*mulsi3"
3402 [(set (match_operand:SI 0 "pseudo_register_operand" "=r")
3403 (mult:SI (match_operand:SI 1 "pseudo_register_operand" "r")
3404 (match_operand:SI 2 "pseudo_register_or_const_int_operand" "rn")))
3405 (clobber (reg:HI 26))
3406 (clobber (reg:DI 18))]
3407 "AVR_HAVE_MUL && !reload_completed"
3408 { gcc_unreachable(); }
3409 "&& 1"
3410 [(set (reg:SI 18)
3411 (match_dup 1))
3412 (set (reg:SI 22)
3413 (match_dup 2))
3414 (parallel [(set (reg:SI 22)
3415 (mult:SI (reg:SI 22)
3416 (reg:SI 18)))
3417 (clobber (reg:HI 26))])
3418 (set (match_dup 0)
3419 (reg:SI 22))]
3420 {
3421 if (u16_operand (operands[2], SImode))
3422 {
3423 operands[2] = force_reg (HImode, gen_int_mode (INTVAL (operands[2]), HImode));
3424 emit_insn (gen_muluhisi3 (operands[0], operands[2], operands[1]));
3425 DONE;
3426 }
3427
3428 if (o16_operand (operands[2], SImode))
3429 {
3430 operands[2] = force_reg (HImode, gen_int_mode (INTVAL (operands[2]), HImode));
3431 emit_insn (gen_mulohisi3 (operands[0], operands[2], operands[1]));
3432 DONE;
3433 }
3434 })
3435
3436 (define_insn_and_split "*mulsi3_pr118012"
3437 [(set (match_operand:SI 0 "pseudo_register_operand" "=r")
3438 (mult:SI (match_operand:SI 1 "pseudo_register_operand" "r")
3439 (match_operand:SI 2 "pseudo_register_operand" "r")))
3440 (clobber (reg:HI 26))
3441 (clobber (reg:HI 30))
3442 (clobber (reg:DI 18))]
3443 "avropt_pr118012
3444 && ! AVR_HAVE_MUL
3445 && ! AVR_TINY
3446 && ! reload_completed"
3447 { gcc_unreachable(); }
3448 "&& 1"
3449 [(set (reg:SI 18)
3450 (match_dup 1))
3451 (set (reg:SI 22)
3452 (match_dup 2))
3453 (parallel [(set (reg:SI 22)
3454 (mult:SI (reg:SI 22)
3455 (reg:SI 18)))
3456 (clobber (reg:SI 18))
3457 (clobber (reg:HI 26))
3458 (clobber (reg:HI 30))])
3459 (set (match_dup 0)
3460 (reg:SI 22))])
3461
3462
3463 ;; "muluqisi3"
3464 ;; "muluhisi3"
3465 (define_expand "mulu<mode>si3"
3466 [(parallel [(set (match_operand:SI 0 "pseudo_register_operand" "")
3467 (mult:SI (zero_extend:SI (match_operand:QIHI 1 "pseudo_register_operand" ""))
3468 (match_operand:SI 2 "pseudo_register_or_const_int_operand" "")))
3469 (clobber (reg:HI 26))
3470 (clobber (reg:DI 18))])]
3471 "AVR_HAVE_MUL"
3472 {
3473 avr_fix_inputs (operands, (1 << 1) | (1 << 2), -1u);
3474 if (avr_emit3_fix_outputs (gen_mulu<mode>si3, operands, 1 << 0,
3475 regmask (DImode, 18) | regmask (HImode, 26)))
3476 DONE;
3477 })
3478
3479 ;; "*muluqisi3"
3480 ;; "*muluhisi3"
3481 (define_insn_and_split "*mulu<mode>si3"
3482 [(set (match_operand:SI 0 "pseudo_register_operand" "=r")
3483 (mult:SI (zero_extend:SI (match_operand:QIHI 1 "pseudo_register_operand" "r"))
3484 (match_operand:SI 2 "pseudo_register_or_const_int_operand" "rn")))
3485 (clobber (reg:HI 26))
3486 (clobber (reg:DI 18))]
3487 "AVR_HAVE_MUL && !reload_completed"
3488 { gcc_unreachable(); }
3489 "&& 1"
3490 [(set (reg:HI 26)
3491 (match_dup 1))
3492 (set (reg:SI 18)
3493 (match_dup 2))
3494 (set (reg:SI 22)
3495 (mult:SI (zero_extend:SI (reg:HI 26))
3496 (reg:SI 18)))
3497 (set (match_dup 0)
3498 (reg:SI 22))]
3499 {
3500 // Do the QI -> HI extension explicitely before the multiplication.
3501 // Do the HI -> SI extension implicitely and after the multiplication.
3502
3503 if (QImode == <MODE>mode)
3504 operands[1] = gen_rtx_ZERO_EXTEND (HImode, operands[1]);
3505
3506 if (u16_operand (operands[2], SImode))
3507 {
3508 operands[1] = force_reg (HImode, operands[1]);
3509 operands[2] = force_reg (HImode, gen_int_mode (INTVAL (operands[2]), HImode));
3510 emit_insn (gen_umulhisi3 (operands[0], operands[1], operands[2]));
3511 DONE;
3512 }
3513 })
3514
3515 ;; "mulsqisi3"
3516 ;; "mulshisi3"
3517 (define_expand "muls<mode>si3"
3518 [(parallel [(set (match_operand:SI 0 "pseudo_register_operand" "")
3519 (mult:SI (sign_extend:SI (match_operand:QIHI 1 "pseudo_register_operand" ""))
3520 (match_operand:SI 2 "pseudo_register_or_const_int_operand" "")))
3521 (clobber (reg:HI 26))
3522 (clobber (reg:DI 18))])]
3523 "AVR_HAVE_MUL"
3524 {
3525 avr_fix_inputs (operands, (1 << 1) | (1 << 2), -1u);
3526 if (avr_emit3_fix_outputs (gen_muls<mode>si3, operands, 1 << 0,
3527 regmask (DImode, 18) | regmask (HImode, 26)))
3528 DONE;
3529 })
3530
3531 ;; "*mulsqisi3"
3532 ;; "*mulshisi3"
3533 (define_insn_and_split "*muls<mode>si3"
3534 [(set (match_operand:SI 0 "pseudo_register_operand" "=r")
3535 (mult:SI (sign_extend:SI (match_operand:QIHI 1 "pseudo_register_operand" "r"))
3536 (match_operand:SI 2 "pseudo_register_or_const_int_operand" "rn")))
3537 (clobber (reg:HI 26))
3538 (clobber (reg:DI 18))]
3539 "AVR_HAVE_MUL && !reload_completed"
3540 { gcc_unreachable(); }
3541 "&& 1"
3542 [(set (reg:HI 26)
3543 (match_dup 1))
3544 (set (reg:SI 18)
3545 (match_dup 2))
3546 (set (reg:SI 22)
3547 (mult:SI (sign_extend:SI (reg:HI 26))
3548 (reg:SI 18)))
3549 (set (match_dup 0)
3550 (reg:SI 22))]
3551 {
3552 // Do the QI -> HI extension explicitly before the multiplication.
3553 // Do the HI -> SI extension implicitly and after the multiplication.
3554
3555 if (QImode == <MODE>mode)
3556 operands[1] = gen_rtx_SIGN_EXTEND (HImode, operands[1]);
3557
3558 if (u16_operand (operands[2], SImode)
3559 || s16_operand (operands[2], SImode))
3560 {
3561 rtx xop2 = force_reg (HImode, gen_int_mode (INTVAL (operands[2]), HImode));
3562
3563 operands[1] = force_reg (HImode, operands[1]);
3564
3565 if (u16_operand (operands[2], SImode))
3566 emit_insn (gen_usmulhisi3 (operands[0], xop2, operands[1]));
3567 else
3568 emit_insn (gen_mulhisi3 (operands[0], operands[1], xop2));
3569
3570 DONE;
3571 }
3572 })
3573
3574 ;; One-extend operand 1
3575
3576 (define_expand "mulohisi3"
3577 [(parallel [(set (match_operand:SI 0 "pseudo_register_operand" "")
3578 (mult:SI (not:SI (zero_extend:SI
3579 (not:HI (match_operand:HI 1 "pseudo_register_operand" ""))))
3580 (match_operand:SI 2 "pseudo_register_or_const_int_operand" "")))
3581 (clobber (reg:HI 26))
3582 (clobber (reg:DI 18))])]
3583 "AVR_HAVE_MUL"
3584 {
3585 avr_fix_inputs (operands, (1 << 1) | (1 << 2), -1u);
3586 if (avr_emit3_fix_outputs (gen_mulohisi3, operands, 1 << 0,
3587 regmask (DImode, 18) | regmask (HImode, 26)))
3588 DONE;
3589 })
3590
3591 (define_insn_and_split "*mulohisi3"
3592 [(set (match_operand:SI 0 "pseudo_register_operand" "=r")
3593 (mult:SI (not:SI (zero_extend:SI
3594 (not:HI (match_operand:HI 1 "pseudo_register_operand" "r"))))
3595 (match_operand:SI 2 "pseudo_register_or_const_int_operand" "rn")))
3596 (clobber (reg:HI 26))
3597 (clobber (reg:DI 18))]
3598 "AVR_HAVE_MUL && !reload_completed"
3599 { gcc_unreachable(); }
3600 "&& 1"
3601 [(set (reg:HI 26)
3602 (match_dup 1))
3603 (set (reg:SI 18)
3604 (match_dup 2))
3605 (set (reg:SI 22)
3606 (mult:SI (not:SI (zero_extend:SI (not:HI (reg:HI 26))))
3607 (reg:SI 18)))
3608 (set (match_dup 0)
3609 (reg:SI 22))])
3610
3611 ;; "mulhisi3"
3612 ;; "umulhisi3"
3613 (define_expand "<extend_u>mulhisi3"
3614 [(parallel [(set (match_operand:SI 0 "register_operand" "")
3615 (mult:SI (any_extend:SI (match_operand:HI 1 "register_operand" ""))
3616 (any_extend:SI (match_operand:HI 2 "register_operand" ""))))
3617 (clobber (reg:HI 26))
3618 (clobber (reg:DI 18))])]
3619 "AVR_HAVE_MUL"
3620 {
3621 if (avr_emit3_fix_outputs (gen_<extend_u>mulhisi3, operands, 1 << 0,
3622 regmask (DImode, 18) | regmask (HImode, 26)))
3623 DONE;
3624 })
3625
3626 (define_expand "usmulhisi3"
3627 [(parallel [(set (match_operand:SI 0 "register_operand" "")
3628 (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" ""))
3629 (sign_extend:SI (match_operand:HI 2 "register_operand" ""))))
3630 (clobber (reg:HI 26))
3631 (clobber (reg:DI 18))])]
3632 "AVR_HAVE_MUL"
3633 {
3634 if (avr_emit3_fix_outputs (gen_usmulhisi3, operands, 1 << 0,
3635 regmask (DImode, 18) | regmask (HImode, 26)))
3636 DONE;
3637 })
3638
3639 ;; "*uumulqihisi3" "*uumulhiqisi3" "*uumulhihisi3" "*uumulqiqisi3"
3640 ;; "*usmulqihisi3" "*usmulhiqisi3" "*usmulhihisi3" "*usmulqiqisi3"
3641 ;; "*sumulqihisi3" "*sumulhiqisi3" "*sumulhihisi3" "*sumulqiqisi3"
3642 ;; "*ssmulqihisi3" "*ssmulhiqisi3" "*ssmulhihisi3" "*ssmulqiqisi3"
3643 (define_insn_and_split
3644 "*<any_extend:extend_su><any_extend2:extend_su>mul<QIHI:mode><QIHI2:mode>si3"
3645 [(set (match_operand:SI 0 "pseudo_register_operand" "=r")
3646 (mult:SI (any_extend:SI (match_operand:QIHI 1 "pseudo_register_operand" "r"))
3647 (any_extend2:SI (match_operand:QIHI2 2 "pseudo_register_operand" "r"))))
3648 (clobber (reg:HI 26))
3649 (clobber (reg:DI 18))]
3650 "AVR_HAVE_MUL && !reload_completed"
3651 { gcc_unreachable(); }
3652 "&& 1"
3653 [(set (reg:HI 18)
3654 (match_dup 1))
3655 (set (reg:HI 26)
3656 (match_dup 2))
3657 (set (reg:SI 22)
3658 (mult:SI (match_dup 3)
3659 (match_dup 4)))
3660 (set (match_dup 0)
3661 (reg:SI 22))]
3662 {
3663 rtx xop1 = operands[1];
3664 rtx xop2 = operands[2];
3665
3666 // Do the QI -> HI extension explicitly before the multiplication.
3667 // Do the HI -> SI extension implicitly and after the multiplication.
3668
3669 if (QImode == <QIHI:MODE>mode)
3670 xop1 = gen_rtx_fmt_e (<any_extend:CODE>, HImode, xop1);
3671
3672 if (QImode == <QIHI2:MODE>mode)
3673 xop2 = gen_rtx_fmt_e (<any_extend2:CODE>, HImode, xop2);
3674
3675 if (<any_extend:CODE> == <any_extend2:CODE>
3676 || <any_extend:CODE> == ZERO_EXTEND)
3677 {
3678 operands[1] = xop1;
3679 operands[2] = xop2;
3680 operands[3] = gen_rtx_fmt_e (<any_extend:CODE>, SImode, gen_rtx_REG (HImode, 18));
3681 operands[4] = gen_rtx_fmt_e (<any_extend2:CODE>, SImode, gen_rtx_REG (HImode, 26));
3682 }
3683 else
3684 {
3685 // <any_extend:CODE> = SIGN_EXTEND
3686 // <any_extend2:CODE> = ZERO_EXTEND
3687
3688 operands[1] = xop2;
3689 operands[2] = xop1;
3690 operands[3] = gen_rtx_ZERO_EXTEND (SImode, gen_rtx_REG (HImode, 18));
3691 operands[4] = gen_rtx_SIGN_EXTEND (SImode, gen_rtx_REG (HImode, 26));
3692 }
3693 })
3694
3695 ;; "smulhi3_highpart"
3696 ;; "umulhi3_highpart"
3697 (define_expand "<extend_su>mulhi3_highpart"
3698 [(set (reg:HI 18)
3699 (match_operand:HI 1 "nonmemory_operand" ""))
3700 (set (reg:HI 26)
3701 (match_operand:HI 2 "nonmemory_operand" ""))
3702 (parallel [(set (reg:HI 24)
3703 (truncate:HI (lshiftrt:SI (mult:SI (any_extend:SI (reg:HI 18))
3704 (any_extend:SI (reg:HI 26)))
3705 (const_int 16))))
3706 (clobber (reg:HI 22))])
3707 (set (match_operand:HI 0 "register_operand" "")
3708 (reg:HI 24))]
3709 "AVR_HAVE_MUL"
3710 {
3711 avr_fix_inputs (operands, 1 << 2, regmask (HImode, 18));
3712 })
3713
3714 (define_insn_and_split "*mulsi3_call_split"
3715 [(set (reg:SI 22)
3716 (mult:SI (reg:SI 22)
3717 (reg:SI 18)))
3718 (clobber (reg:HI 26))]
3719 "AVR_HAVE_MUL"
3720 "#"
3721 "&& reload_completed"
3722 [(parallel [(set (reg:SI 22)
3723 (mult:SI (reg:SI 22)
3724 (reg:SI 18)))
3725 (clobber (reg:HI 26))
3726 (clobber (reg:CC REG_CC))])])
3727
3728 (define_insn_and_split "*mulsi3_call_pr118012_split"
3729 [(set (reg:SI 22)
3730 (mult:SI (reg:SI 22)
3731 (reg:SI 18)))
3732 (clobber (reg:SI 18))
3733 (clobber (reg:HI 26))
3734 (clobber (reg:HI 30))]
3735 "avropt_pr118012
3736 && ! AVR_HAVE_MUL
3737 && ! AVR_TINY"
3738 "#"
3739 "&& reload_completed"
3740 [(parallel [(set (reg:SI 22)
3741 (mult:SI (reg:SI 22)
3742 (reg:SI 18)))
3743 (clobber (reg:SI 18))
3744 (clobber (reg:HI 26))
3745 (clobber (reg:HI 30))
3746 (clobber (reg:CC REG_CC))])])
3747
3748 (define_insn "*mulsi3_call"
3749 [(set (reg:SI 22)
3750 (mult:SI (reg:SI 22)
3751 (reg:SI 18)))
3752 (clobber (reg:HI 26))
3753 (clobber (reg:CC REG_CC))]
3754 "AVR_HAVE_MUL && reload_completed"
3755 "%~call __mulsi3"
3756 [(set_attr "type" "xcall")])
3757
3758 (define_insn "*mulsi3_call_pr118012"
3759 [(set (reg:SI 22)
3760 (mult:SI (reg:SI 22)
3761 (reg:SI 18)))
3762 (clobber (reg:SI 18))
3763 (clobber (reg:HI 26))
3764 (clobber (reg:HI 30))
3765 (clobber (reg:CC REG_CC))]
3766 "avropt_pr118012
3767 && ! AVR_HAVE_MUL
3768 && ! AVR_TINY
3769 && reload_completed"
3770 "%~call __mulsi3"
3771 [(set_attr "type" "xcall")])
3772
3773 ;; "*mulhisi3_call"
3774 ;; "*umulhisi3_call"
3775 (define_insn_and_split "*<extend_u>mulhisi3_call_split"
3776 [(set (reg:SI 22)
3777 (mult:SI (any_extend:SI (reg:HI 18))
3778 (any_extend:SI (reg:HI 26))))]
3779 "AVR_HAVE_MUL"
3780 "#"
3781 "&& reload_completed"
3782 [(parallel [(set (reg:SI 22)
3783 (mult:SI (any_extend:SI (reg:HI 18))
3784 (any_extend:SI (reg:HI 26))))
3785 (clobber (reg:CC REG_CC))])])
3786
3787 (define_insn "*<extend_u>mulhisi3_call"
3788 [(set (reg:SI 22)
3789 (mult:SI (any_extend:SI (reg:HI 18))
3790 (any_extend:SI (reg:HI 26))))
3791 (clobber (reg:CC REG_CC))]
3792 "AVR_HAVE_MUL && reload_completed"
3793 "%~call __<extend_u>mulhisi3"
3794 [(set_attr "type" "xcall")])
3795
3796 ;; "*umulhi3_highpart_call"
3797 ;; "*smulhi3_highpart_call"
3798 (define_insn_and_split "*<extend_su>mulhi3_highpart_call_split"
3799 [(set (reg:HI 24)
3800 (truncate:HI (lshiftrt:SI (mult:SI (any_extend:SI (reg:HI 18))
3801 (any_extend:SI (reg:HI 26)))
3802 (const_int 16))))
3803 (clobber (reg:HI 22))]
3804 "AVR_HAVE_MUL"
3805 "#"
3806 "&& reload_completed"
3807 [(parallel [(set (reg:HI 24)
3808 (truncate:HI (lshiftrt:SI (mult:SI (any_extend:SI (reg:HI 18))
3809 (any_extend:SI (reg:HI 26)))
3810 (const_int 16))))
3811 (clobber (reg:HI 22))
3812 (clobber (reg:CC REG_CC))])])
3813
3814 (define_insn "*<extend_su>mulhi3_highpart_call"
3815 [(set (reg:HI 24)
3816 (truncate:HI (lshiftrt:SI (mult:SI (any_extend:SI (reg:HI 18))
3817 (any_extend:SI (reg:HI 26)))
3818 (const_int 16))))
3819 (clobber (reg:HI 22))
3820 (clobber (reg:CC REG_CC))]
3821 "AVR_HAVE_MUL && reload_completed"
3822 "%~call __<extend_u>mulhisi3"
3823 [(set_attr "type" "xcall")])
3824
3825 (define_insn_and_split "*usmulhisi3_call_split"
3826 [(set (reg:SI 22)
3827 (mult:SI (zero_extend:SI (reg:HI 18))
3828 (sign_extend:SI (reg:HI 26))))]
3829 "AVR_HAVE_MUL"
3830 "#"
3831 "&& reload_completed"
3832 [(parallel [(set (reg:SI 22)
3833 (mult:SI (zero_extend:SI (reg:HI 18))
3834 (sign_extend:SI (reg:HI 26))))
3835 (clobber (reg:CC REG_CC))])])
3836
3837 (define_insn "*usmulhisi3_call"
3838 [(set (reg:SI 22)
3839 (mult:SI (zero_extend:SI (reg:HI 18))
3840 (sign_extend:SI (reg:HI 26))))
3841 (clobber (reg:CC REG_CC))]
3842 "AVR_HAVE_MUL && reload_completed"
3843 "%~call __usmulhisi3"
3844 [(set_attr "type" "xcall")])
3845
3846 (define_insn_and_split "*mul<extend_su>hisi3_call_split"
3847 [(set (reg:SI 22)
3848 (mult:SI (any_extend:SI (reg:HI 26))
3849 (reg:SI 18)))]
3850 "AVR_HAVE_MUL"
3851 "#"
3852 "&& reload_completed"
3853 [(parallel [(set (reg:SI 22)
3854 (mult:SI (any_extend:SI (reg:HI 26))
3855 (reg:SI 18)))
3856 (clobber (reg:CC REG_CC))])])
3857
3858 (define_insn "*mul<extend_su>hisi3_call"
3859 [(set (reg:SI 22)
3860 (mult:SI (any_extend:SI (reg:HI 26))
3861 (reg:SI 18)))
3862 (clobber (reg:CC REG_CC))]
3863 "AVR_HAVE_MUL && reload_completed"
3864 "%~call __mul<extend_su>hisi3"
3865 [(set_attr "type" "xcall")])
3866
3867 (define_insn_and_split "*mulohisi3_call_split"
3868 [(set (reg:SI 22)
3869 (mult:SI (not:SI (zero_extend:SI (not:HI (reg:HI 26))))
3870 (reg:SI 18)))]
3871 "AVR_HAVE_MUL"
3872 "#"
3873 "&& reload_completed"
3874 [(parallel [(set (reg:SI 22)
3875 (mult:SI (not:SI (zero_extend:SI (not:HI (reg:HI 26))))
3876 (reg:SI 18)))
3877 (clobber (reg:CC REG_CC))])])
3878
3879 (define_insn "*mulohisi3_call"
3880 [(set (reg:SI 22)
3881 (mult:SI (not:SI (zero_extend:SI (not:HI (reg:HI 26))))
3882 (reg:SI 18)))
3883 (clobber (reg:CC REG_CC))]
3884 "AVR_HAVE_MUL && reload_completed"
3885 "%~call __mulohisi3"
3886 [(set_attr "type" "xcall")])
3887
3888 ; / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / %
3889 ; divmod
3890
3891 ;; Generate lib1funcs.S calls ourselves, because:
3892 ;; - we know exactly which registers are clobbered (for QI and HI
3893 ;; modes, some of the call-used registers are preserved)
3894 ;; - we get both the quotient and the remainder at no extra cost
3895 ;; - we split the patterns only after the first CSE passes because
3896 ;; CSE has problems to operate on hard regs.
3897 ;;
3898 (define_insn_and_split "divmodqi4"
3899 [(set (match_operand:QI 0 "pseudo_register_operand")
3900 (div:QI (match_operand:QI 1 "pseudo_register_operand")
3901 (match_operand:QI 2 "pseudo_register_operand")))
3902 (set (match_operand:QI 3 "pseudo_register_operand")
3903 (mod:QI (match_dup 1) (match_dup 2)))
3904 (clobber (reg:QI 22))
3905 (clobber (reg:QI 23))
3906 (clobber (reg:QI 24))
3907 (clobber (reg:QI 25))]
3908 ""
3909 { gcc_unreachable(); }
3910 ""
3911 [(set (reg:QI 24) (match_dup 1))
3912 (set (reg:QI 22) (match_dup 2))
3913 (parallel [(set (reg:QI 24) (div:QI (reg:QI 24) (reg:QI 22)))
3914 (set (reg:QI 25) (mod:QI (reg:QI 24) (reg:QI 22)))
3915 (clobber (reg:QI 22))
3916 (clobber (reg:QI 23))])
3917 (set (match_dup 0) (reg:QI 24))
3918 (set (match_dup 3) (reg:QI 25))])
3919
3920 (define_insn_and_split "*divmodqi4_call_split"
3921 [(set (reg:QI 24) (div:QI (reg:QI 24) (reg:QI 22)))
3922 (set (reg:QI 25) (mod:QI (reg:QI 24) (reg:QI 22)))
3923 (clobber (reg:QI 22))
3924 (clobber (reg:QI 23))]
3925 ""
3926 "#"
3927 "&& reload_completed"
3928 [(parallel [(set (reg:QI 24) (div:QI (reg:QI 24) (reg:QI 22)))
3929 (set (reg:QI 25) (mod:QI (reg:QI 24) (reg:QI 22)))
3930 (clobber (reg:QI 22))
3931 (clobber (reg:QI 23))
3932 (clobber (reg:CC REG_CC))])])
3933
3934 (define_insn "*divmodqi4_call"
3935 [(set (reg:QI 24) (div:QI (reg:QI 24) (reg:QI 22)))
3936 (set (reg:QI 25) (mod:QI (reg:QI 24) (reg:QI 22)))
3937 (clobber (reg:QI 22))
3938 (clobber (reg:QI 23))
3939 (clobber (reg:CC REG_CC))]
3940 "reload_completed"
3941 "%~call __divmodqi4"
3942 [(set_attr "type" "xcall")])
3943
3944 (define_insn_and_split "udivmodqi4"
3945 [(set (match_operand:QI 0 "pseudo_register_operand")
3946 (udiv:QI (match_operand:QI 1 "pseudo_register_operand")
3947 (match_operand:QI 2 "pseudo_register_operand")))
3948 (set (match_operand:QI 3 "pseudo_register_operand")
3949 (umod:QI (match_dup 1) (match_dup 2)))
3950 (clobber (reg:QI 22))
3951 (clobber (reg:QI 23))
3952 (clobber (reg:QI 24))
3953 (clobber (reg:QI 25))]
3954 ""
3955 { gcc_unreachable(); }
3956 ""
3957 [(set (reg:QI 24) (match_dup 1))
3958 (set (reg:QI 22) (match_dup 2))
3959 (parallel [(set (reg:QI 24) (udiv:QI (reg:QI 24) (reg:QI 22)))
3960 (set (reg:QI 25) (umod:QI (reg:QI 24) (reg:QI 22)))
3961 (clobber (reg:QI 23))])
3962 (set (match_dup 0) (reg:QI 24))
3963 (set (match_dup 3) (reg:QI 25))])
3964
3965 (define_insn_and_split "*udivmodqi4_call_split"
3966 [(set (reg:QI 24) (udiv:QI (reg:QI 24) (reg:QI 22)))
3967 (set (reg:QI 25) (umod:QI (reg:QI 24) (reg:QI 22)))
3968 (clobber (reg:QI 23))]
3969 ""
3970 "#"
3971 "&& reload_completed"
3972 [(parallel [(set (reg:QI 24) (udiv:QI (reg:QI 24) (reg:QI 22)))
3973 (set (reg:QI 25) (umod:QI (reg:QI 24) (reg:QI 22)))
3974 (clobber (reg:QI 23))
3975 (clobber (reg:CC REG_CC))])])
3976
3977 (define_insn "*udivmodqi4_call"
3978 [(set (reg:QI 24) (udiv:QI (reg:QI 24) (reg:QI 22)))
3979 (set (reg:QI 25) (umod:QI (reg:QI 24) (reg:QI 22)))
3980 (clobber (reg:QI 23))
3981 (clobber (reg:CC REG_CC))]
3982 "reload_completed"
3983 "%~call __udivmodqi4"
3984 [(set_attr "type" "xcall")])
3985
3986 (define_insn_and_split "divmodhi4"
3987 [(set (match_operand:HI 0 "pseudo_register_operand")
3988 (div:HI (match_operand:HI 1 "pseudo_register_operand")
3989 (match_operand:HI 2 "pseudo_register_operand")))
3990 (set (match_operand:HI 3 "pseudo_register_operand")
3991 (mod:HI (match_dup 1) (match_dup 2)))
3992 (clobber (reg:QI 21))
3993 (clobber (reg:HI 22))
3994 (clobber (reg:HI 24))
3995 (clobber (reg:HI 26))]
3996 ""
3997 { gcc_unreachable(); }
3998 ""
3999 [(set (reg:HI 24) (match_dup 1))
4000 (set (reg:HI 22) (match_dup 2))
4001 (parallel [(set (reg:HI 22) (div:HI (reg:HI 24) (reg:HI 22)))
4002 (set (reg:HI 24) (mod:HI (reg:HI 24) (reg:HI 22)))
4003 (clobber (reg:HI 26))
4004 (clobber (reg:QI 21))])
4005 (set (match_dup 0) (reg:HI 22))
4006 (set (match_dup 3) (reg:HI 24))])
4007
4008 (define_insn_and_split "*divmodhi4_call_split"
4009 [(set (reg:HI 22) (div:HI (reg:HI 24) (reg:HI 22)))
4010 (set (reg:HI 24) (mod:HI (reg:HI 24) (reg:HI 22)))
4011 (clobber (reg:HI 26))
4012 (clobber (reg:QI 21))]
4013 ""
4014 "#"
4015 "&& reload_completed"
4016 [(parallel [(set (reg:HI 22) (div:HI (reg:HI 24) (reg:HI 22)))
4017 (set (reg:HI 24) (mod:HI (reg:HI 24) (reg:HI 22)))
4018 (clobber (reg:HI 26))
4019 (clobber (reg:QI 21))
4020 (clobber (reg:CC REG_CC))])])
4021
4022 (define_insn "*divmodhi4_call"
4023 [(set (reg:HI 22) (div:HI (reg:HI 24) (reg:HI 22)))
4024 (set (reg:HI 24) (mod:HI (reg:HI 24) (reg:HI 22)))
4025 (clobber (reg:HI 26))
4026 (clobber (reg:QI 21))
4027 (clobber (reg:CC REG_CC))]
4028 "reload_completed"
4029 "%~call __divmodhi4"
4030 [(set_attr "type" "xcall")])
4031
4032 (define_insn_and_split "udivmodhi4"
4033 [(set (match_operand:HI 0 "pseudo_register_operand")
4034 (udiv:HI (match_operand:HI 1 "pseudo_register_operand")
4035 (match_operand:HI 2 "pseudo_register_operand")))
4036 (set (match_operand:HI 3 "pseudo_register_operand")
4037 (umod:HI (match_dup 1) (match_dup 2)))
4038 (clobber (reg:QI 21))
4039 (clobber (reg:HI 22))
4040 (clobber (reg:HI 24))
4041 (clobber (reg:HI 26))]
4042 ""
4043 { gcc_unreachable(); }
4044 ""
4045 [(set (reg:HI 24) (match_dup 1))
4046 (set (reg:HI 22) (match_dup 2))
4047 (parallel [(set (reg:HI 22) (udiv:HI (reg:HI 24) (reg:HI 22)))
4048 (set (reg:HI 24) (umod:HI (reg:HI 24) (reg:HI 22)))
4049 (clobber (reg:HI 26))
4050 (clobber (reg:QI 21))])
4051 (set (match_dup 0) (reg:HI 22))
4052 (set (match_dup 3) (reg:HI 24))])
4053
4054 (define_insn_and_split "*udivmodhi4_call_split"
4055 [(set (reg:HI 22) (udiv:HI (reg:HI 24) (reg:HI 22)))
4056 (set (reg:HI 24) (umod:HI (reg:HI 24) (reg:HI 22)))
4057 (clobber (reg:HI 26))
4058 (clobber (reg:QI 21))]
4059 ""
4060 "#"
4061 "&& reload_completed"
4062 [(parallel [(set (reg:HI 22) (udiv:HI (reg:HI 24) (reg:HI 22)))
4063 (set (reg:HI 24) (umod:HI (reg:HI 24) (reg:HI 22)))
4064 (clobber (reg:HI 26))
4065 (clobber (reg:QI 21))
4066 (clobber (reg:CC REG_CC))])])
4067
4068 (define_insn "*udivmodhi4_call"
4069 [(set (reg:HI 22) (udiv:HI (reg:HI 24) (reg:HI 22)))
4070 (set (reg:HI 24) (umod:HI (reg:HI 24) (reg:HI 22)))
4071 (clobber (reg:HI 26))
4072 (clobber (reg:QI 21))
4073 (clobber (reg:CC REG_CC))
4074 ]
4075 "reload_completed"
4076 "%~call __udivmodhi4"
4077 [(set_attr "type" "xcall")])
4078
4079 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4080 ;; 24-bit multiply
4081
4082 ;; To support widening multiplication with constant we postpone
4083 ;; expanding to the implicit library call until post combine and
4084 ;; prior to register allocation. Clobber all hard registers that
4085 ;; might be used by the (widening) multiply until it is split and
4086 ;; it's final register footprint is worked out.
4087
4088 (define_expand "mulpsi3"
4089 [(parallel [(set (match_operand:PSI 0 "register_operand" "")
4090 (mult:PSI (match_operand:PSI 1 "register_operand" "")
4091 (match_operand:PSI 2 "nonmemory_operand" "")))
4092 (clobber (reg:HI 26))
4093 (clobber (reg:DI 18))])]
4094 "AVR_HAVE_MUL
4095 || (avropt_pr118012
4096 /* AVR_TINY passes args on the stack, so we cannot work
4097 around PR118012 like this. */
4098 && ! AVR_TINY)"
4099 {
4100 if (!AVR_HAVE_MUL)
4101 {
4102 operands[2] = force_reg (PSImode, operands[2]);
4103 }
4104 else if (s8_operand (operands[2], PSImode))
4105 {
4106 rtx reg = force_reg (QImode, gen_int_mode (INTVAL (operands[2]), QImode));
4107 emit_insn (gen_mulsqipsi3 (operands[0], reg, operands[1]));
4108 DONE;
4109 }
4110
4111 if (avr_emit3_fix_outputs (gen_mulpsi3, operands, 1u << 0,
4112 regmask (DImode, 18) | regmask (HImode, 26)))
4113 DONE;
4114 })
4115
4116 (define_insn_and_split "*umulqihipsi3_split"
4117 [(set (match_operand:PSI 0 "register_operand" "=&r")
4118 (mult:PSI (zero_extend:PSI (match_operand:QI 1 "register_operand" "r"))
4119 (zero_extend:PSI (match_operand:HI 2 "register_operand" "r"))))]
4120 "AVR_HAVE_MUL"
4121 "#"
4122 "&& reload_completed"
4123 [(parallel [(set (match_dup 0)
4124 (mult:PSI (zero_extend:PSI (match_dup 1))
4125 (zero_extend:PSI (match_dup 2))))
4126 (clobber (reg:CC REG_CC))])])
4127
4128 (define_insn "*umulqihipsi3"
4129 [(set (match_operand:PSI 0 "register_operand" "=&r")
4130 (mult:PSI (zero_extend:PSI (match_operand:QI 1 "register_operand" "r"))
4131 (zero_extend:PSI (match_operand:HI 2 "register_operand" "r"))))
4132 (clobber (reg:CC REG_CC))]
4133 "AVR_HAVE_MUL && reload_completed"
4134 "mul %1,%A2
4135 movw %A0,r0
4136 mul %1,%B2
4137 clr %C0
4138 add %B0,r0
4139 adc %C0,r1
4140 clr __zero_reg__"
4141 [(set_attr "length" "7")])
4142
4143 (define_insn_and_split "*umulhiqipsi3_split"
4144 [(set (match_operand:PSI 0 "register_operand" "=&r")
4145 (mult:PSI (zero_extend:PSI (match_operand:HI 2 "register_operand" "r"))
4146 (zero_extend:PSI (match_operand:QI 1 "register_operand" "r"))))]
4147 "AVR_HAVE_MUL"
4148 "#"
4149 "&& reload_completed"
4150 [(parallel [(set (match_dup 0)
4151 (mult:PSI (zero_extend:PSI (match_dup 2))
4152 (zero_extend:PSI (match_dup 1))))
4153 (clobber (reg:CC REG_CC))])])
4154
4155 (define_insn "*umulhiqipsi3"
4156 [(set (match_operand:PSI 0 "register_operand" "=&r")
4157 (mult:PSI (zero_extend:PSI (match_operand:HI 2 "register_operand" "r"))
4158 (zero_extend:PSI (match_operand:QI 1 "register_operand" "r"))))
4159 (clobber (reg:CC REG_CC))]
4160 "AVR_HAVE_MUL && reload_completed"
4161 "mul %1,%A2
4162 movw %A0,r0
4163 mul %1,%B2
4164 add %B0,r0
4165 mov %C0,r1
4166 clr __zero_reg__
4167 adc %C0,__zero_reg__"
4168 [(set_attr "length" "7")])
4169
4170 (define_expand "mulsqipsi3"
4171 [(parallel [(set (match_operand:PSI 0 "pseudo_register_operand" "")
4172 (mult:PSI (sign_extend:PSI (match_operand:QI 1 "pseudo_register_operand" ""))
4173 (match_operand:PSI 2 "pseudo_register_or_const_int_operand""")))
4174 (clobber (reg:HI 26))
4175 (clobber (reg:DI 18))])]
4176 "AVR_HAVE_MUL"
4177 {
4178 avr_fix_inputs (operands, (1 << 1) | (1 << 2), -1u);
4179 if (avr_emit3_fix_outputs (gen_mulsqipsi3, operands, 1 << 0,
4180 regmask (DImode, 18) | regmask (HImode, 26)))
4181 DONE;
4182 })
4183
4184 (define_insn_and_split "*mulsqipsi3"
4185 [(set (match_operand:PSI 0 "pseudo_register_operand" "=r")
4186 (mult:PSI (sign_extend:PSI (match_operand:QI 1 "pseudo_register_operand" "r"))
4187 (match_operand:PSI 2 "pseudo_register_or_const_int_operand" "rn")))
4188 (clobber (reg:HI 26))
4189 (clobber (reg:DI 18))]
4190 "AVR_HAVE_MUL && !reload_completed"
4191 { gcc_unreachable(); }
4192 "&& 1"
4193 [(set (reg:QI 25)
4194 (match_dup 1))
4195 (set (reg:PSI 22)
4196 (match_dup 2))
4197 (set (reg:PSI 18)
4198 (mult:PSI (sign_extend:PSI (reg:QI 25))
4199 (reg:PSI 22)))
4200 (set (match_dup 0)
4201 (reg:PSI 18))])
4202
4203 (define_insn_and_split "*mulpsi3"
4204 [(set (match_operand:PSI 0 "pseudo_register_operand" "=r")
4205 (mult:PSI (match_operand:PSI 1 "pseudo_register_operand" "r")
4206 (match_operand:PSI 2 "pseudo_register_or_const_int_operand" "rn")))
4207 (clobber (reg:HI 26))
4208 (clobber (reg:DI 18))]
4209 "!reload_completed
4210 && (AVR_HAVE_MUL
4211 || (avropt_pr118012 && !AVR_TINY))"
4212 { gcc_unreachable(); }
4213 "&& 1"
4214 [(set (reg:PSI 18)
4215 (match_dup 1))
4216 (set (reg:PSI 22)
4217 (match_dup 2))
4218 (parallel [(set (reg:PSI 22)
4219 (mult:PSI (reg:PSI 22)
4220 (reg:PSI 18)))
4221 (clobber (match_dup 3))
4222 (clobber (match_dup 4))
4223 (clobber (match_dup 5))])
4224 (set (match_dup 0)
4225 (reg:PSI 22))]
4226 {
4227 if (AVR_HAVE_MUL)
4228 {
4229 operands[3] = gen_rtx_REG (QImode, REG_21);
4230 operands[4] = gen_rtx_REG (QImode, REG_25);
4231 operands[5] = gen_rtx_REG (HImode, REG_26);
4232 }
4233 else
4234 {
4235 operands[3] = gen_rtx_REG (SImode, REG_18);
4236 operands[4] = gen_rtx_SCRATCH (QImode);
4237 operands[5] = gen_rtx_SCRATCH (HImode);
4238 }
4239
4240 if (!AVR_HAVE_MUL)
4241 {
4242 operands[2] = force_reg (PSImode, operands[2]);
4243 }
4244 else if (s8_operand (operands[2], PSImode))
4245 {
4246 rtx reg = force_reg (QImode, gen_int_mode (INTVAL (operands[2]), QImode));
4247 emit_insn (gen_mulsqipsi3 (operands[0], reg, operands[1]));
4248 DONE;
4249 }
4250 })
4251
4252 (define_insn_and_split "*mulsqipsi3.libgcc_split"
4253 [(set (reg:PSI 18)
4254 (mult:PSI (sign_extend:PSI (reg:QI 25))
4255 (reg:PSI 22)))]
4256 "AVR_HAVE_MUL"
4257 "#"
4258 "&& reload_completed"
4259 [(parallel [(set (reg:PSI 18)
4260 (mult:PSI (sign_extend:PSI (reg:QI 25))
4261 (reg:PSI 22)))
4262 (clobber (reg:CC REG_CC))])])
4263
4264 (define_insn "*mulsqipsi3.libgcc"
4265 [(set (reg:PSI 18)
4266 (mult:PSI (sign_extend:PSI (reg:QI 25))
4267 (reg:PSI 22)))
4268 (clobber (reg:CC REG_CC))]
4269 "AVR_HAVE_MUL && reload_completed"
4270 "%~call __mulsqipsi3"
4271 [(set_attr "type" "xcall")])
4272
4273 (define_insn_and_split "*mulpsi3.libgcc_split"
4274 [(set (reg:PSI 22)
4275 (mult:PSI (reg:PSI 22)
4276 (reg:PSI 18)))
4277 (clobber (reg:QI 21))
4278 (clobber (reg:QI 25))
4279 (clobber (reg:HI 26))]
4280 "AVR_HAVE_MUL"
4281 "#"
4282 "&& reload_completed"
4283 [(parallel [(set (reg:PSI 22)
4284 (mult:PSI (reg:PSI 22)
4285 (reg:PSI 18)))
4286 (clobber (reg:QI 21))
4287 (clobber (reg:QI 25))
4288 (clobber (reg:HI 26))
4289 (clobber (reg:CC REG_CC))])])
4290
4291 (define_insn "*mulpsi3.libgcc"
4292 [(set (reg:PSI 22)
4293 (mult:PSI (reg:PSI 22)
4294 (reg:PSI 18)))
4295 (clobber (reg:QI 21))
4296 (clobber (reg:QI 25))
4297 (clobber (reg:HI 26))
4298 (clobber (reg:CC REG_CC))]
4299 "AVR_HAVE_MUL && reload_completed"
4300 "%~call __mulpsi3"
4301 [(set_attr "type" "xcall")])
4302
4303 (define_insn_and_split "*mulpsi3-nomul.libgcc_split"
4304 [(set (reg:PSI 22)
4305 (mult:PSI (reg:PSI 22)
4306 (reg:PSI 18)))
4307 (clobber (reg:SI 18))
4308 (clobber (scratch:QI))
4309 (clobber (scratch:HI))]
4310 "!AVR_HAVE_MUL && avropt_pr118012 && !AVR_TINY"
4311 "#"
4312 "&& reload_completed"
4313 [(parallel [(set (reg:PSI 22)
4314 (mult:PSI (reg:PSI 22)
4315 (reg:PSI 18)))
4316 (clobber (reg:SI 18))
4317 (clobber (scratch:QI))
4318 (clobber (scratch:HI))
4319 (clobber (reg:CC REG_CC))])])
4320
4321 (define_insn "*mulpsi3-nomul.libgcc"
4322 [(set (reg:PSI 22)
4323 (mult:PSI (reg:PSI 22)
4324 (reg:PSI 18)))
4325 (clobber (reg:SI 18))
4326 (clobber (scratch:QI))
4327 (clobber (scratch:HI))
4328 (clobber (reg:CC REG_CC))]
4329 "reload_completed
4330 && !AVR_HAVE_MUL && avropt_pr118012 && !AVR_TINY"
4331 "%~call __mulpsi3"
4332 [(set_attr "type" "xcall")])
4333
4334
4335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4336 ;; 24-bit signed/unsigned division and modulo.
4337 ;; Notice that the libgcc implementation return the quotient in R22
4338 ;; and the remainder in R18 whereas the 32-bit [u]divmodsi4
4339 ;; implementation works the other way round.
4340
4341 (define_insn_and_split "divmodpsi4"
4342 [(set (match_operand:PSI 0 "pseudo_register_operand")
4343 (div:PSI (match_operand:PSI 1 "pseudo_register_operand")
4344 (match_operand:PSI 2 "pseudo_register_operand")))
4345 (set (match_operand:PSI 3 "pseudo_register_operand")
4346 (mod:PSI (match_dup 1)
4347 (match_dup 2)))
4348 (clobber (reg:DI 18))
4349 (clobber (reg:QI 26))]
4350 ""
4351 { gcc_unreachable(); }
4352 ""
4353 [(set (reg:PSI 22) (match_dup 1))
4354 (set (reg:PSI 18) (match_dup 2))
4355 (parallel [(set (reg:PSI 22) (div:PSI (reg:PSI 22) (reg:PSI 18)))
4356 (set (reg:PSI 18) (mod:PSI (reg:PSI 22) (reg:PSI 18)))
4357 (clobber (reg:QI 21))
4358 (clobber (reg:QI 25))
4359 (clobber (reg:QI 26))])
4360 (set (match_dup 0) (reg:PSI 22))
4361 (set (match_dup 3) (reg:PSI 18))])
4362
4363 (define_insn_and_split "*divmodpsi4_call_split"
4364 [(set (reg:PSI 22) (div:PSI (reg:PSI 22) (reg:PSI 18)))
4365 (set (reg:PSI 18) (mod:PSI (reg:PSI 22) (reg:PSI 18)))
4366 (clobber (reg:QI 21))
4367 (clobber (reg:QI 25))
4368 (clobber (reg:QI 26))]
4369 ""
4370 "#"
4371 "&& reload_completed"
4372 [(parallel [(set (reg:PSI 22) (div:PSI (reg:PSI 22) (reg:PSI 18)))
4373 (set (reg:PSI 18) (mod:PSI (reg:PSI 22) (reg:PSI 18)))
4374 (clobber (reg:QI 21))
4375 (clobber (reg:QI 25))
4376 (clobber (reg:QI 26))
4377 (clobber (reg:CC REG_CC))])])
4378
4379 (define_insn "*divmodpsi4_call"
4380 [(set (reg:PSI 22) (div:PSI (reg:PSI 22) (reg:PSI 18)))
4381 (set (reg:PSI 18) (mod:PSI (reg:PSI 22) (reg:PSI 18)))
4382 (clobber (reg:QI 21))
4383 (clobber (reg:QI 25))
4384 (clobber (reg:QI 26))
4385 (clobber (reg:CC REG_CC))]
4386 "reload_completed"
4387 "%~call __divmodpsi4"
4388 [(set_attr "type" "xcall")])
4389
4390 (define_insn_and_split "udivmodpsi4"
4391 [(set (match_operand:PSI 0 "pseudo_register_operand")
4392 (udiv:PSI (match_operand:PSI 1 "pseudo_register_operand")
4393 (match_operand:PSI 2 "pseudo_register_operand")))
4394 (set (match_operand:PSI 3 "pseudo_register_operand")
4395 (umod:PSI (match_dup 1)
4396 (match_dup 2)))
4397 (clobber (reg:DI 18))
4398 (clobber (reg:QI 26))]
4399 ""
4400 { gcc_unreachable(); }
4401 ""
4402 [(set (reg:PSI 22) (match_dup 1))
4403 (set (reg:PSI 18) (match_dup 2))
4404 (parallel [(set (reg:PSI 22) (udiv:PSI (reg:PSI 22) (reg:PSI 18)))
4405 (set (reg:PSI 18) (umod:PSI (reg:PSI 22) (reg:PSI 18)))
4406 (clobber (reg:QI 21))
4407 (clobber (reg:QI 25))
4408 (clobber (reg:QI 26))])
4409 (set (match_dup 0) (reg:PSI 22))
4410 (set (match_dup 3) (reg:PSI 18))])
4411
4412 (define_insn_and_split "*udivmodpsi4_call_split"
4413 [(set (reg:PSI 22) (udiv:PSI (reg:PSI 22) (reg:PSI 18)))
4414 (set (reg:PSI 18) (umod:PSI (reg:PSI 22) (reg:PSI 18)))
4415 (clobber (reg:QI 21))
4416 (clobber (reg:QI 25))
4417 (clobber (reg:QI 26))]
4418 ""
4419 "#"
4420 "&& reload_completed"
4421 [(parallel [(set (reg:PSI 22) (udiv:PSI (reg:PSI 22) (reg:PSI 18)))
4422 (set (reg:PSI 18) (umod:PSI (reg:PSI 22) (reg:PSI 18)))
4423 (clobber (reg:QI 21))
4424 (clobber (reg:QI 25))
4425 (clobber (reg:QI 26))
4426 (clobber (reg:CC REG_CC))])])
4427
4428 (define_insn "*udivmodpsi4_call"
4429 [(set (reg:PSI 22) (udiv:PSI (reg:PSI 22) (reg:PSI 18)))
4430 (set (reg:PSI 18) (umod:PSI (reg:PSI 22) (reg:PSI 18)))
4431 (clobber (reg:QI 21))
4432 (clobber (reg:QI 25))
4433 (clobber (reg:QI 26))
4434 (clobber (reg:CC REG_CC))]
4435 "reload_completed"
4436 "%~call __udivmodpsi4"
4437 [(set_attr "type" "xcall")])
4438
4439 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4440
4441 (define_insn_and_split "divmodsi4"
4442 [(set (match_operand:SI 0 "pseudo_register_operand")
4443 (div:SI (match_operand:SI 1 "pseudo_register_operand")
4444 (match_operand:SI 2 "pseudo_register_operand")))
4445 (set (match_operand:SI 3 "pseudo_register_operand")
4446 (mod:SI (match_dup 1)
4447 (match_dup 2)))
4448 (clobber (reg:SI 18))
4449 (clobber (reg:SI 22))
4450 (clobber (reg:HI 26))
4451 (clobber (reg:HI 30))]
4452 ""
4453 { gcc_unreachable(); }
4454 ""
4455 [(set (reg:SI 22) (match_dup 1))
4456 (set (reg:SI 18) (match_dup 2))
4457 (parallel [(set (reg:SI 18) (div:SI (reg:SI 22) (reg:SI 18)))
4458 (set (reg:SI 22) (mod:SI (reg:SI 22) (reg:SI 18)))
4459 (clobber (reg:HI 26))
4460 (clobber (reg:HI 30))])
4461 (set (match_dup 0) (reg:SI 18))
4462 (set (match_dup 3) (reg:SI 22))])
4463
4464 (define_insn_and_split "*divmodsi4_call_split"
4465 [(set (reg:SI 18) (div:SI (reg:SI 22) (reg:SI 18)))
4466 (set (reg:SI 22) (mod:SI (reg:SI 22) (reg:SI 18)))
4467 (clobber (reg:HI 26))
4468 (clobber (reg:HI 30))]
4469 ""
4470 "#"
4471 "&& reload_completed"
4472 [(parallel [(set (reg:SI 18) (div:SI (reg:SI 22) (reg:SI 18)))
4473 (set (reg:SI 22) (mod:SI (reg:SI 22) (reg:SI 18)))
4474 (clobber (reg:HI 26))
4475 (clobber (reg:HI 30))
4476 (clobber (reg:CC REG_CC))])])
4477
4478 (define_insn "*divmodsi4_call"
4479 [(set (reg:SI 18) (div:SI (reg:SI 22) (reg:SI 18)))
4480 (set (reg:SI 22) (mod:SI (reg:SI 22) (reg:SI 18)))
4481 (clobber (reg:HI 26))
4482 (clobber (reg:HI 30))
4483 (clobber (reg:CC REG_CC))]
4484 "reload_completed"
4485 "%~call __divmodsi4"
4486 [(set_attr "type" "xcall")])
4487
4488 (define_insn_and_split "udivmodsi4"
4489 [(set (match_operand:SI 0 "pseudo_register_operand")
4490 (udiv:SI (match_operand:SI 1 "pseudo_register_operand")
4491 (match_operand:SI 2 "pseudo_register_operand")))
4492 (set (match_operand:SI 3 "pseudo_register_operand")
4493 (umod:SI (match_dup 1)
4494 (match_dup 2)))
4495 (clobber (reg:SI 18))
4496 (clobber (reg:SI 22))
4497 (clobber (reg:HI 26))
4498 (clobber (reg:HI 30))]
4499 ""
4500 { gcc_unreachable(); }
4501 ""
4502 [(set (reg:SI 22) (match_dup 1))
4503 (set (reg:SI 18) (match_dup 2))
4504 (parallel [(set (reg:SI 18) (udiv:SI (reg:SI 22) (reg:SI 18)))
4505 (set (reg:SI 22) (umod:SI (reg:SI 22) (reg:SI 18)))
4506 (clobber (reg:HI 26))
4507 (clobber (reg:HI 30))])
4508 (set (match_dup 0) (reg:SI 18))
4509 (set (match_dup 3) (reg:SI 22))])
4510
4511 (define_insn_and_split "*udivmodsi4_call_split"
4512 [(set (reg:SI 18) (udiv:SI (reg:SI 22) (reg:SI 18)))
4513 (set (reg:SI 22) (umod:SI (reg:SI 22) (reg:SI 18)))
4514 (clobber (reg:HI 26))
4515 (clobber (reg:HI 30))]
4516 ""
4517 "#"
4518 "&& reload_completed"
4519 [(parallel [(set (reg:SI 18) (udiv:SI (reg:SI 22) (reg:SI 18)))
4520 (set (reg:SI 22) (umod:SI (reg:SI 22) (reg:SI 18)))
4521 (clobber (reg:HI 26))
4522 (clobber (reg:HI 30))
4523 (clobber (reg:CC REG_CC))])])
4524
4525 (define_insn "*udivmodsi4_call"
4526 [(set (reg:SI 18) (udiv:SI (reg:SI 22) (reg:SI 18)))
4527 (set (reg:SI 22) (umod:SI (reg:SI 22) (reg:SI 18)))
4528 (clobber (reg:HI 26))
4529 (clobber (reg:HI 30))
4530 (clobber (reg:CC REG_CC))]
4531 "reload_completed"
4532 "%~call __udivmodsi4"
4533 [(set_attr "type" "xcall")])
4534
4535 ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
4536 ; and
4537
4538 (define_insn_and_split "andqi3"
4539 [(set (match_operand:QI 0 "register_operand" "=??r,d,*l ,r")
4540 (and:QI (match_operand:QI 1 "register_operand" "%0,0,0 ,r")
4541 (match_operand:QI 2 "nonmemory_operand" "r,i,Ca1,Cb1")))]
4542 ""
4543 "#"
4544 "&& reload_completed"
4545 [(parallel [(set (match_dup 0)
4546 (and:QI (match_dup 1)
4547 (match_dup 2)))
4548 (clobber (reg:CC REG_CC))])])
4549
4550 (define_insn "*andqi3"
4551 [(set (match_operand:QI 0 "register_operand" "=??r,d,*l ,r")
4552 (and:QI (match_operand:QI 1 "register_operand" "%0,0,0 ,r")
4553 (match_operand:QI 2 "nonmemory_operand" "r,i,Ca1,Cb1")))
4554 (clobber (reg:CC REG_CC))]
4555 "reload_completed"
4556 "@
4557 and %0,%2
4558 andi %0,lo8(%2)
4559 * return avr_out_bitop (insn, operands, NULL);
4560 * return avr_out_insv (insn, operands, NULL);"
4561 [(set_attr "length" "1,1,2,3")
4562 (set_attr "adjust_len" "*,*,out_bitop,insv")])
4563
4564 (define_insn_and_split "andhi3"
4565 [(set (match_operand:HI 0 "register_operand" "=??r,d,d,r ,r ,r")
4566 (and:HI (match_operand:HI 1 "register_operand" "%0,0,0,0 ,r ,0")
4567 (match_operand:HI 2 "nonmemory_operand" "r,s,n,Ca2,Cb2,n")))
4568 (clobber (match_scratch:QI 3 "=X,X,X,X ,X ,&d"))]
4569 ""
4570 "#"
4571 "&& reload_completed"
4572 [(parallel [(set (match_dup 0)
4573 (and:HI (match_dup 1)
4574 (match_dup 2)))
4575 (clobber (match_dup 3))
4576 (clobber (reg:CC REG_CC))])])
4577
4578 (define_insn "*andhi3"
4579 [(set (match_operand:HI 0 "register_operand" "=??r,d,d,r ,r ,r")
4580 (and:HI (match_operand:HI 1 "register_operand" "%0,0,0,0 ,r ,0")
4581 (match_operand:HI 2 "nonmemory_operand" "r,s,n,Ca2,Cb2,n")))
4582 (clobber (match_scratch:QI 3 "=X,X,X,X ,X ,&d"))
4583 (clobber (reg:CC REG_CC))]
4584 "reload_completed"
4585 {
4586 if (which_alternative == 0)
4587 return "and %A0,%A2\;and %B0,%B2";
4588 else if (which_alternative == 1)
4589 return "andi %A0,lo8(%2)\;andi %B0,hi8(%2)";
4590 else if (which_alternative == 4)
4591 return avr_out_insv (insn, operands, NULL);
4592
4593 return avr_out_bitop (insn, operands, NULL);
4594 }
4595 [(set_attr "length" "2,2,2,4,4,4")
4596 (set_attr "adjust_len" "*,*,out_bitop,out_bitop,insv,out_bitop")])
4597
4598 (define_insn_and_split "andpsi3"
4599 [(set (match_operand:PSI 0 "register_operand" "=??r,d,r ,r ,r")
4600 (and:PSI (match_operand:PSI 1 "register_operand" "%0,0,0 ,r ,0")
4601 (match_operand:PSI 2 "nonmemory_operand" "r,n,Ca3,Cb3,n")))
4602 (clobber (match_scratch:QI 3 "=X,X,X ,X ,&d"))]
4603 ""
4604 "#"
4605 "&& reload_completed"
4606 [(parallel [(set (match_dup 0)
4607 (and:PSI (match_dup 1)
4608 (match_dup 2)))
4609 (clobber (match_dup 3))
4610 (clobber (reg:CC REG_CC))])])
4611
4612 (define_insn "*andpsi3"
4613 [(set (match_operand:PSI 0 "register_operand" "=??r,d,r ,r ,r")
4614 (and:PSI (match_operand:PSI 1 "register_operand" "%0,0,0 ,r ,0")
4615 (match_operand:PSI 2 "nonmemory_operand" "r,n,Ca3,Cb3,n")))
4616 (clobber (match_scratch:QI 3 "=X,X,X ,X ,&d"))
4617 (clobber (reg:CC REG_CC))]
4618 "reload_completed"
4619 {
4620 if (which_alternative == 0)
4621 return "and %A0,%A2" CR_TAB
4622 "and %B0,%B2" CR_TAB
4623 "and %C0,%C2";
4624
4625 if (which_alternative == 3)
4626 return avr_out_insv (insn, operands, NULL);
4627
4628 return avr_out_bitop (insn, operands, NULL);
4629 }
4630 [(set_attr "length" "3,3,6,5,6")
4631 (set_attr "adjust_len" "*,out_bitop,out_bitop,insv,out_bitop")])
4632
4633 (define_insn_and_split "andsi3"
4634 [(set (match_operand:SI 0 "register_operand" "=??r,d,r ,r ,r")
4635 (and:SI (match_operand:SI 1 "register_operand" "%0,0,0 ,r ,0")
4636 (match_operand:SI 2 "nonmemory_operand" "r,n,Ca4,Cb4,n")))
4637 (clobber (match_scratch:QI 3 "=X,X,X ,X ,&d"))]
4638 ""
4639 "#"
4640 "&& reload_completed"
4641 [(parallel [(set (match_dup 0)
4642 (and:SI (match_dup 1)
4643 (match_dup 2)))
4644 (clobber (match_dup 3))
4645 (clobber (reg:CC REG_CC))])])
4646
4647 (define_insn "*andsi3"
4648 [(set (match_operand:SI 0 "register_operand" "=??r,d,r ,r ,r")
4649 (and:SI (match_operand:SI 1 "register_operand" "%0,0,0 ,r ,0")
4650 (match_operand:SI 2 "nonmemory_operand" "r,n,Ca4,Cb4,n")))
4651 (clobber (match_scratch:QI 3 "=X,X,X ,X ,&d"))
4652 (clobber (reg:CC REG_CC))]
4653 "reload_completed"
4654 {
4655 if (which_alternative == 0)
4656 return "and %0,%2" CR_TAB
4657 "and %B0,%B2" CR_TAB
4658 "and %C0,%C2" CR_TAB
4659 "and %D0,%D2";
4660
4661 if (which_alternative == 3)
4662 return avr_out_insv (insn, operands, NULL);
4663
4664 return avr_out_bitop (insn, operands, NULL);
4665 }
4666 [(set_attr "length" "4,4,8,6,8")
4667 (set_attr "adjust_len" "*,out_bitop,out_bitop,insv,out_bitop")])
4668
4669 (define_peephole2 ; andi
4670 [(parallel [(set (match_operand:QI 0 "d_register_operand" "")
4671 (and:QI (match_dup 0)
4672 (match_operand:QI 1 "const_int_operand" "")))
4673 (clobber (reg:CC REG_CC))])
4674 (parallel [(set (match_dup 0)
4675 (and:QI (match_dup 0)
4676 (match_operand:QI 2 "const_int_operand" "")))
4677 (clobber (reg:CC REG_CC))])]
4678 ""
4679 [(parallel [(set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))
4680 (clobber (reg:CC REG_CC))])]
4681 {
4682 operands[1] = GEN_INT (INTVAL (operands[1]) & INTVAL (operands[2]));
4683 })
4684
4685 ;;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4686 ;; ior
4687
4688 (define_insn_and_split "iorqi3"
4689 [(set (match_operand:QI 0 "register_operand" "=??r,d,*l")
4690 (ior:QI (match_operand:QI 1 "register_operand" "%0,0,0")
4691 (match_operand:QI 2 "nonmemory_operand" "r,i,Co1")))]
4692 ""
4693 "#"
4694 "&& reload_completed"
4695 [(parallel [(set (match_dup 0)
4696 (ior:QI (match_dup 1)
4697 (match_dup 2)))
4698 (clobber (reg:CC REG_CC))])])
4699
4700 (define_insn "*iorqi3"
4701 [(set (match_operand:QI 0 "register_operand" "=??r,d,*l")
4702 (ior:QI (match_operand:QI 1 "register_operand" "%0,0,0")
4703 (match_operand:QI 2 "nonmemory_operand" "r,i,Co1")))
4704 (clobber (reg:CC REG_CC))]
4705 "reload_completed"
4706 "@
4707 or %0,%2
4708 ori %0,lo8(%2)
4709 * return avr_out_bitop (insn, operands, NULL);"
4710 [(set_attr "length" "1,1,2")])
4711
4712 (define_insn_and_split "iorhi3"
4713 [(set (match_operand:HI 0 "register_operand" "=??r,d,d,r ,r")
4714 (ior:HI (match_operand:HI 1 "register_operand" "%0,0,0,0 ,0")
4715 (match_operand:HI 2 "nonmemory_operand" "r,s,n,Co2,n")))
4716 (clobber (match_scratch:QI 3 "=X,X,X,X ,&d"))]
4717 ""
4718 "#"
4719 "&& reload_completed"
4720 [(parallel [(set (match_dup 0)
4721 (ior:HI (match_dup 1)
4722 (match_dup 2)))
4723 (clobber (match_dup 3))
4724 (clobber (reg:CC REG_CC))])])
4725
4726 (define_insn "*iorhi3"
4727 [(set (match_operand:HI 0 "register_operand" "=??r,d,d,r ,r")
4728 (ior:HI (match_operand:HI 1 "register_operand" "%0,0,0,0 ,0")
4729 (match_operand:HI 2 "nonmemory_operand" "r,s,n,Co2,n")))
4730 (clobber (match_scratch:QI 3 "=X,X,X,X ,&d"))
4731 (clobber (reg:CC REG_CC))]
4732 "reload_completed"
4733 {
4734 if (which_alternative == 0)
4735 return "or %A0,%A2\;or %B0,%B2";
4736 else if (which_alternative == 1)
4737 return "ori %A0,lo8(%2)\;ori %B0,hi8(%2)";
4738
4739 return avr_out_bitop (insn, operands, NULL);
4740 }
4741 [(set_attr "length" "2,2,2,4,4")
4742 (set_attr "adjust_len" "*,*,out_bitop,out_bitop,out_bitop")])
4743
4744 (define_insn_and_split "iorpsi3"
4745 [(set (match_operand:PSI 0 "register_operand" "=??r,d,r ,r")
4746 (ior:PSI (match_operand:PSI 1 "register_operand" "%0,0,0 ,0")
4747 (match_operand:PSI 2 "nonmemory_operand" "r,n,Co3,n")))
4748 (clobber (match_scratch:QI 3 "=X,X,X ,&d"))]
4749 ""
4750 "#"
4751 "&& reload_completed"
4752 [(parallel [(set (match_dup 0)
4753 (ior:PSI (match_dup 1)
4754 (match_dup 2)))
4755 (clobber (match_dup 3))
4756 (clobber (reg:CC REG_CC))])])
4757
4758 (define_insn "*iorpsi3"
4759 [(set (match_operand:PSI 0 "register_operand" "=??r,d,r ,r")
4760 (ior:PSI (match_operand:PSI 1 "register_operand" "%0,0,0 ,0")
4761 (match_operand:PSI 2 "nonmemory_operand" "r,n,Co3,n")))
4762 (clobber (match_scratch:QI 3 "=X,X,X ,&d"))
4763 (clobber (reg:CC REG_CC))]
4764 "reload_completed"
4765 {
4766 if (which_alternative == 0)
4767 return "or %A0,%A2" CR_TAB
4768 "or %B0,%B2" CR_TAB
4769 "or %C0,%C2";
4770
4771 return avr_out_bitop (insn, operands, NULL);
4772 }
4773 [(set_attr "length" "3,3,6,6")
4774 (set_attr "adjust_len" "*,out_bitop,out_bitop,out_bitop")])
4775
4776 (define_insn_and_split "iorsi3"
4777 [(set (match_operand:SI 0 "register_operand" "=??r,d,r ,r")
4778 (ior:SI (match_operand:SI 1 "register_operand" "%0,0,0 ,0")
4779 (match_operand:SI 2 "nonmemory_operand" "r,n,Co4,n")))
4780 (clobber (match_scratch:QI 3 "=X,X,X ,&d"))]
4781 ""
4782 "#"
4783 "&& reload_completed"
4784 [(parallel [(set (match_dup 0)
4785 (ior:SI (match_dup 1)
4786 (match_dup 2)))
4787 (clobber (match_dup 3))
4788 (clobber (reg:CC REG_CC))])])
4789
4790 (define_insn "*iorsi3"
4791 [(set (match_operand:SI 0 "register_operand" "=??r,d,r ,r")
4792 (ior:SI (match_operand:SI 1 "register_operand" "%0,0,0 ,0")
4793 (match_operand:SI 2 "nonmemory_operand" "r,n,Co4,n")))
4794 (clobber (match_scratch:QI 3 "=X,X,X ,&d"))
4795 (clobber (reg:CC REG_CC))]
4796 "reload_completed"
4797 {
4798 if (which_alternative == 0)
4799 return "or %0,%2" CR_TAB
4800 "or %B0,%B2" CR_TAB
4801 "or %C0,%C2" CR_TAB
4802 "or %D0,%D2";
4803
4804 return avr_out_bitop (insn, operands, NULL);
4805 }
4806 [(set_attr "length" "4,4,8,8")
4807 (set_attr "adjust_len" "*,out_bitop,out_bitop,out_bitop")])
4808
4809 ;;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4810 ;; xor
4811
4812 (define_insn_and_split "xorqi3"
4813 [(set (match_operand:QI 0 "register_operand" "=r")
4814 (xor:QI (match_operand:QI 1 "register_operand" "%0")
4815 (match_operand:QI 2 "register_operand" "r")))]
4816 ""
4817 "#"
4818 "&& reload_completed"
4819 [(parallel [(set (match_dup 0)
4820 (xor:QI (match_dup 1)
4821 (match_dup 2)))
4822 (clobber (reg:CC REG_CC))])])
4823
4824 (define_insn "*xorqi3"
4825 [(set (match_operand:QI 0 "register_operand" "=r")
4826 (xor:QI (match_operand:QI 1 "register_operand" "%0")
4827 (match_operand:QI 2 "register_operand" "r")))
4828 (clobber (reg:CC REG_CC))]
4829 "reload_completed"
4830 "eor %0,%2"
4831 [(set_attr "length" "1")])
4832
4833 (define_insn_and_split "xorhi3"
4834 [(set (match_operand:HI 0 "register_operand" "=??r,r ,d ,r")
4835 (xor:HI (match_operand:HI 1 "register_operand" "%0,0 ,0 ,0")
4836 (match_operand:HI 2 "nonmemory_operand" "r,Cx2,CX2,n")))
4837 (clobber (match_scratch:QI 3 "=X,X ,X ,&d"))]
4838 ""
4839 "#"
4840 "&& reload_completed"
4841 [(parallel [(set (match_dup 0)
4842 (xor:HI (match_dup 1)
4843 (match_dup 2)))
4844 (clobber (match_dup 3))
4845 (clobber (reg:CC REG_CC))])])
4846
4847 (define_insn "*xorhi3"
4848 [(set (match_operand:HI 0 "register_operand" "=??r,r ,d ,r")
4849 (xor:HI (match_operand:HI 1 "register_operand" "%0,0 ,0 ,0")
4850 (match_operand:HI 2 "nonmemory_operand" "r,Cx2,CX2,n")))
4851 (clobber (match_scratch:QI 3 "=X,X ,X ,&d"))
4852 (clobber (reg:CC REG_CC))]
4853 "reload_completed"
4854 {
4855 if (which_alternative == 0)
4856 return "eor %A0,%A2\;eor %B0,%B2";
4857
4858 return avr_out_bitop (insn, operands, NULL);
4859 }
4860 [(set_attr "length" "2,2,4,4")
4861 (set_attr "adjust_len" "*,out_bitop,out_bitop,out_bitop")])
4862
4863 (define_insn_and_split "xorpsi3"
4864 [(set (match_operand:PSI 0 "register_operand" "=??r,r ,d ,r")
4865 (xor:PSI (match_operand:PSI 1 "register_operand" "%0,0 ,0 ,0")
4866 (match_operand:PSI 2 "nonmemory_operand" "r,Cx3,CX3,n")))
4867 (clobber (match_scratch:QI 3 "=X,X ,X ,&d"))]
4868 ""
4869 "#"
4870 "&& reload_completed"
4871 [(parallel [(set (match_dup 0)
4872 (xor:PSI (match_dup 1)
4873 (match_dup 2)))
4874 (clobber (match_dup 3))
4875 (clobber (reg:CC REG_CC))])])
4876
4877 (define_insn "*xorpsi3"
4878 [(set (match_operand:PSI 0 "register_operand" "=??r,r ,d ,r")
4879 (xor:PSI (match_operand:PSI 1 "register_operand" "%0,0 ,0 ,0")
4880 (match_operand:PSI 2 "nonmemory_operand" "r,Cx3,CX3,n")))
4881 (clobber (match_scratch:QI 3 "=X,X ,X ,&d"))
4882 (clobber (reg:CC REG_CC))]
4883 "reload_completed"
4884 {
4885 if (which_alternative == 0)
4886 return "eor %A0,%A2" CR_TAB
4887 "eor %B0,%B2" CR_TAB
4888 "eor %C0,%C2";
4889
4890 return avr_out_bitop (insn, operands, NULL);
4891 }
4892 [(set_attr "length" "3,6,6,6")
4893 (set_attr "adjust_len" "*,out_bitop,out_bitop,out_bitop")])
4894
4895 (define_insn_and_split "xorsi3"
4896 [(set (match_operand:SI 0 "register_operand" "=??r,r ,d ,r")
4897 (xor:SI (match_operand:SI 1 "register_operand" "%0,0 ,0 ,0")
4898 (match_operand:SI 2 "nonmemory_operand" "r,Cx4,CX4,n")))
4899 (clobber (match_scratch:QI 3 "=X,X ,X ,&d"))]
4900 ""
4901 "#"
4902 "&& reload_completed"
4903 [(parallel [(set (match_dup 0)
4904 (xor:SI (match_dup 1)
4905 (match_dup 2)))
4906 (clobber (match_dup 3))
4907 (clobber (reg:CC REG_CC))])])
4908
4909 (define_insn "*xorsi3"
4910 [(set (match_operand:SI 0 "register_operand" "=??r,r ,d ,r")
4911 (xor:SI (match_operand:SI 1 "register_operand" "%0,0 ,0 ,0")
4912 (match_operand:SI 2 "nonmemory_operand" "r,Cx4,CX4,n")))
4913 (clobber (match_scratch:QI 3 "=X,X ,X ,&d"))
4914 (clobber (reg:CC REG_CC))]
4915 "reload_completed"
4916 {
4917 if (which_alternative == 0)
4918 return "eor %0,%2" CR_TAB
4919 "eor %B0,%B2" CR_TAB
4920 "eor %C0,%C2" CR_TAB
4921 "eor %D0,%D2";
4922
4923 return avr_out_bitop (insn, operands, NULL);
4924 }
4925 [(set_attr "length" "4,8,8,8")
4926 (set_attr "adjust_len" "*,out_bitop,out_bitop,out_bitop")])
4927
4928
4929 (define_split
4930 [(set (match_operand:SPLIT34 0 "register_operand")
4931 (match_operand:SPLIT34 1 "register_operand"))]
4932 "optimize
4933 && reload_completed"
4934 [(set (match_dup 2) (match_dup 3))
4935 (set (match_dup 4) (match_dup 5))]
4936 {
4937 machine_mode mode_hi = <SIZE> == 4 ? HImode : QImode;
4938 bool lo_first = REGNO (operands[0]) < REGNO (operands[1]);
4939 rtx dst_lo = simplify_gen_subreg (HImode, operands[0], <MODE>mode, 0);
4940 rtx src_lo = simplify_gen_subreg (HImode, operands[1], <MODE>mode, 0);
4941 rtx dst_hi = simplify_gen_subreg (mode_hi, operands[0], <MODE>mode, 2);
4942 rtx src_hi = simplify_gen_subreg (mode_hi, operands[1], <MODE>mode, 2);
4943
4944 operands[2] = lo_first ? dst_lo : dst_hi;
4945 operands[3] = lo_first ? src_lo : src_hi;
4946 operands[4] = lo_first ? dst_hi : dst_lo;
4947 operands[5] = lo_first ? src_hi : src_lo;
4948 })
4949
4950 (define_split
4951 [(set (match_operand:HI 0 "register_operand")
4952 (match_operand:HI 1 "reg_or_0_operand"))]
4953 "optimize
4954 && reload_completed
4955 && GENERAL_REG_P (operands[0])
4956 && (operands[1] == const0_rtx || GENERAL_REG_P (operands[1]))
4957 && (!AVR_HAVE_MOVW
4958 || const0_rtx == operands[1])"
4959 [(set (match_dup 2) (match_dup 3))
4960 (set (match_dup 4) (match_dup 5))]
4961 {
4962 operands[2] = simplify_gen_subreg (QImode, operands[0], HImode, 1);
4963 operands[3] = simplify_gen_subreg (QImode, operands[1], HImode, 1);
4964 operands[4] = simplify_gen_subreg (QImode, operands[0], HImode, 0);
4965 operands[5] = simplify_gen_subreg (QImode, operands[1], HImode, 0);
4966 })
4967
4968 ;; Split andhi3, andpsi3, andsi3.
4969 ;; Split iorhi3, iorpsi3, iorsi3.
4970 ;; Split xorhi3, xorpsi3, xorsi3.
4971 (define_split
4972 [(parallel [(set (match_operand:HISI 0 "register_operand")
4973 (bitop:HISI (match_dup 0)
4974 (match_operand:HISI 1 "register_operand")))
4975 (clobber (scratch:QI))
4976 (clobber (reg:CC REG_CC))])]
4977 "optimize
4978 && reload_completed"
4979 [(const_int 1)]
4980 {
4981 for (int i = 0; i < <SIZE>; i++)
4982 {
4983 rtx dst = simplify_gen_subreg (QImode, operands[0], <MODE>mode, i);
4984 rtx src = simplify_gen_subreg (QImode, operands[1], <MODE>mode, i);
4985 emit_insn (gen_<code>qi3 (dst, dst, src));
4986 }
4987 DONE;
4988 })
4989
4990 ;; If $0 = $0 <op> const requires a QI scratch, and d-reg $1 dies after
4991 ;; the first insn, then we can replace
4992 ;; $0 = $1
4993 ;; $0 = $0 <op> const
4994 ;; by
4995 ;; $1 = $1 <op> const
4996 ;; $0 = $1
4997 ;; This transforms constraint alternative "r,0,n,&d" of the first operation
4998 ;; to alternative "d,0,n,X".
4999 ;; "*addhi3_clobber" "*addpsi3" "*addsi3"
5000 ;; "*addhq3" "*adduhq3" "*addha3" "*adduha3"
5001 ;; "*addsq3" "*addusq3" "*addsa3" "*addusa3"
5002 ;; "*iorhi3" "*iorpsi3" "*iorsi3"
5003 ;; "*andhi3" "*andpsi3" "*andsi3"
5004 (define_peephole2
5005 [(parallel [(set (match_operand:ORDERED234 0 "register_operand")
5006 (match_operand:ORDERED234 1 "d_register_operand"))
5007 (clobber (reg:CC REG_CC))])
5008 (parallel [(set (match_dup 0)
5009 (piaop:ORDERED234 (match_dup 0)
5010 (match_operand:ORDERED234 2 "const_operand")))
5011 ; A d-reg as scratch tells that this insn is expensive, and
5012 ; that $0 is not a d-register: l-reg or something like SI:14 etc.
5013 (clobber (match_operand:QI 3 "d_register_operand"))
5014 (clobber (reg:CC REG_CC))])]
5015 "peep2_reg_dead_p (1, operands[1])"
5016 [(parallel [(set (match_dup 1)
5017 (piaop:ORDERED234 (match_dup 1)
5018 (match_dup 2)))
5019 (clobber (scratch:QI))
5020 (clobber (reg:CC REG_CC))])
5021 ; Unfortunately, the following insn misses a REG_DEAD note for $1,
5022 ; so this peep2 works only once.
5023 (parallel [(set (match_dup 0)
5024 (match_dup 1))
5025 (clobber (reg:CC REG_CC))])])
5026
5027
5028 ;; For operations like X o= CST, regalloc may spill l-reg X to a d-reg:
5029 ;; D = X
5030 ;; D o= CST
5031 ;; X = D
5032 ;; where it is better to instead
5033 ;; D = CST
5034 ;; X o= D
5035 (define_peephole2
5036 [; Move l-reg to d-reg for the purpose of BITOP.
5037 (parallel [(set (match_operand:ALL1 0 "d_register_operand")
5038 (match_operand:ALL1 1 "l_register_operand"))
5039 (clobber (reg:CC REG_CC))])
5040 (parallel [(set (match_dup 0)
5041 (bitop:ALL1 (match_dup 0)
5042 (match_operand:ALL1 2 "const_operand")))
5043 (clobber (reg:CC REG_CC))])
5044 ; Move d-reg result back to l-reg.
5045 (parallel [(set (match_dup 1)
5046 (match_dup 0))
5047 (clobber (reg:CC REG_CC))])]
5048 "peep2_reg_dead_p (3, operands[0])"
5049 [; "movqi_insn"
5050 (parallel [(set (match_dup 0)
5051 (match_dup 2))
5052 (clobber (reg:CC REG_CC))])
5053 (parallel [(set (match_dup 1)
5054 (bitop:ALL1 (match_dup 1)
5055 (match_dup 0)))
5056 (clobber (reg:CC REG_CC))])])
5057
5058
5059 ;; swap swap swap swap swap swap swap swap swap swap swap swap swap swap swap
5060 ;; swap
5061
5062 (define_expand "rotlqi3"
5063 [(set (match_operand:QI 0 "register_operand" "")
5064 (rotate:QI (match_operand:QI 1 "register_operand" "")
5065 (match_operand:QI 2 "const_0_to_7_operand" "")))]
5066 ""
5067 {
5068 if (!CONST_INT_P (operands[2]))
5069 FAIL;
5070
5071 operands[2] = gen_int_mode (INTVAL (operands[2]) & 7, QImode);
5072 })
5073
5074 ;; Expander used by __builtin_avr_swap
5075 (define_expand "rotlqi3_4"
5076 [(set (match_operand:QI 0 "register_operand" "")
5077 (rotate:QI (match_operand:QI 1 "register_operand" "")
5078 (const_int 4)))])
5079
5080 (define_insn_and_split "*rotlqi3_split"
5081 [(set (match_operand:QI 0 "register_operand" "=r,r,r ,r ,r ,r ,r ,r")
5082 (rotate:QI (match_operand:QI 1 "register_operand" "0,0,0 ,0 ,0 ,0 ,0 ,0")
5083 (match_operand:QI 2 "const_0_to_7_operand" "P,K,C03,C04,C05,C06,C07,L")))]
5084 ""
5085 "#"
5086 "&& reload_completed"
5087 [(parallel [(set (match_dup 0)
5088 (rotate:QI (match_dup 1)
5089 (match_dup 2)))
5090 (clobber (reg:CC REG_CC))])])
5091
5092 (define_insn "*rotlqi3"
5093 [(set (match_operand:QI 0 "register_operand" "=r,r,r ,r ,r ,r ,r ,r")
5094 (rotate:QI (match_operand:QI 1 "register_operand" "0,0,0 ,0 ,0 ,0 ,0 ,0")
5095 (match_operand:QI 2 "const_0_to_7_operand" "P,K,C03,C04,C05,C06,C07,L")))
5096 (clobber (reg:CC REG_CC))]
5097 "reload_completed"
5098 "@
5099 lsl %0\;adc %0,__zero_reg__
5100 lsl %0\;adc %0,__zero_reg__\;lsl %0\;adc %0,__zero_reg__
5101 swap %0\;bst %0,0\;ror %0\;bld %0,7
5102 swap %0
5103 swap %0\;lsl %0\;adc %0,__zero_reg__
5104 swap %0\;lsl %0\;adc %0,__zero_reg__\;lsl %0\;adc %0,__zero_reg__
5105 bst %0,0\;ror %0\;bld %0,7
5106 " ; empty
5107 [(set_attr "length" "2,4,4,1,3,5,3,0")])
5108
5109 ;; Split all rotates of HI,SI and PSImode registers where rotation is by
5110 ;; a whole number of bytes. The split creates the appropriate moves and
5111 ;; considers all overlap situations.
5112
5113 ;; HImode does not need scratch. Use attribute for this constraint.
5114
5115 (define_mode_attr rotx [(SI "&r,&r,X") (PSI "&r,&r,X") (HI "X,X,X")])
5116 (define_mode_attr rotsmode [(SI "HI") (PSI "QI") (HI "QI")])
5117
5118 ;; "rotlhi3"
5119 ;; "rotlpsi3"
5120 ;; "rotlsi3"
5121 (define_expand "rotl<mode>3"
5122 [(parallel [(set (match_operand:HISI 0 "register_operand" "")
5123 (rotate:HISI (match_operand:HISI 1 "register_operand" "")
5124 (match_operand:HISI 2 "const_int_operand" "")))
5125 (clobber (match_dup 3))])]
5126 ""
5127 {
5128 if (!CONST_INT_P (operands[2]))
5129 FAIL;
5130
5131 int offset = INTVAL (operands[2]);
5132
5133 if (0 == offset % 8)
5134 {
5135 if (AVR_HAVE_MOVW && 0 == offset % 16)
5136 operands[3] = gen_rtx_SCRATCH (<rotsmode>mode);
5137 else
5138 operands[3] = gen_rtx_SCRATCH (QImode);
5139 }
5140 else if (offset == 1
5141 || offset == <MSB>)
5142 {
5143 // Support rotate left/right by 1.
5144
5145 emit_move_insn (operands[0],
5146 gen_rtx_ROTATE (<MODE>mode, operands[1], operands[2]));
5147 DONE;
5148 }
5149 else
5150 FAIL;
5151 })
5152
5153 (define_insn_and_split "*rotlhi2.1_split"
5154 [(set (match_operand:HI 0 "register_operand" "=r")
5155 (rotate:HI (match_operand:HI 1 "register_operand" "0")
5156 (const_int 1)))]
5157 ""
5158 "#"
5159 "&& reload_completed"
5160 [(parallel [(set (match_dup 0)
5161 (rotate:HI (match_dup 1)
5162 (const_int 1)))
5163 (clobber (reg:CC REG_CC))])])
5164
5165 (define_insn "*rotlhi2.1"
5166 [(set (match_operand:HI 0 "register_operand" "=r")
5167 (rotate:HI (match_operand:HI 1 "register_operand" "0")
5168 (const_int 1)))
5169 (clobber (reg:CC REG_CC))]
5170 "reload_completed"
5171 "lsl %A0\;rol %B0\;adc %A0,__zero_reg__"
5172 [(set_attr "length" "3")])
5173
5174 (define_insn_and_split "*rotlhi2.15_split"
5175 [(set (match_operand:HI 0 "register_operand" "=r")
5176 (rotate:HI (match_operand:HI 1 "register_operand" "0")
5177 (const_int 15)))]
5178 ""
5179 "#"
5180 "&& reload_completed"
5181 [(parallel [(set (match_dup 0)
5182 (rotate:HI (match_dup 1)
5183 (const_int 15)))
5184 (clobber (reg:CC REG_CC))])])
5185
5186 (define_insn "*rotlhi2.15"
5187 [(set (match_operand:HI 0 "register_operand" "=r")
5188 (rotate:HI (match_operand:HI 1 "register_operand" "0")
5189 (const_int 15)))
5190 (clobber (reg:CC REG_CC))]
5191 "reload_completed"
5192 "bst %A0,0\;ror %B0\;ror %A0\;bld %B0,7"
5193 [(set_attr "length" "4")])
5194
5195 (define_insn_and_split "*rotlpsi2.1_split"
5196 [(set (match_operand:PSI 0 "register_operand" "=r")
5197 (rotate:PSI (match_operand:PSI 1 "register_operand" "0")
5198 (const_int 1)))]
5199 ""
5200 "#"
5201 "&& reload_completed"
5202 [(parallel [(set (match_dup 0)
5203 (rotate:PSI (match_dup 1)
5204 (const_int 1)))
5205 (clobber (reg:CC REG_CC))])])
5206
5207 (define_insn "*rotlpsi2.1"
5208 [(set (match_operand:PSI 0 "register_operand" "=r")
5209 (rotate:PSI (match_operand:PSI 1 "register_operand" "0")
5210 (const_int 1)))
5211 (clobber (reg:CC REG_CC))]
5212 "reload_completed"
5213 "lsl %A0\;rol %B0\;rol %C0\;adc %A0,__zero_reg__"
5214 [(set_attr "length" "4")])
5215
5216 (define_insn_and_split "*rotlpsi2.23_split"
5217 [(set (match_operand:PSI 0 "register_operand" "=r")
5218 (rotate:PSI (match_operand:PSI 1 "register_operand" "0")
5219 (const_int 23)))]
5220 ""
5221 "#"
5222 "&& reload_completed"
5223 [(parallel [(set (match_dup 0)
5224 (rotate:PSI (match_dup 1)
5225 (const_int 23)))
5226 (clobber (reg:CC REG_CC))])])
5227
5228 (define_insn "*rotlpsi2.23"
5229 [(set (match_operand:PSI 0 "register_operand" "=r")
5230 (rotate:PSI (match_operand:PSI 1 "register_operand" "0")
5231 (const_int 23)))
5232 (clobber (reg:CC REG_CC))]
5233 "reload_completed"
5234 "bst %A0,0\;ror %C0\;ror %B0\;ror %A0\;bld %C0,7"
5235 [(set_attr "length" "5")])
5236
5237 (define_insn_and_split "*rotlsi2.1_split"
5238 [(set (match_operand:SI 0 "register_operand" "=r")
5239 (rotate:SI (match_operand:SI 1 "register_operand" "0")
5240 (const_int 1)))]
5241 ""
5242 "#"
5243 "&& reload_completed"
5244 [(parallel [(set (match_dup 0)
5245 (rotate:SI (match_dup 1)
5246 (const_int 1)))
5247 (clobber (reg:CC REG_CC))])])
5248
5249 (define_insn "*rotlsi2.1"
5250 [(set (match_operand:SI 0 "register_operand" "=r")
5251 (rotate:SI (match_operand:SI 1 "register_operand" "0")
5252 (const_int 1)))
5253 (clobber (reg:CC REG_CC))]
5254 "reload_completed"
5255 "lsl %A0\;rol %B0\;rol %C0\;rol %D0\;adc %A0,__zero_reg__"
5256 [(set_attr "length" "5")])
5257
5258 (define_insn_and_split "*rotlsi2.31_split"
5259 [(set (match_operand:SI 0 "register_operand" "=r")
5260 (rotate:SI (match_operand:SI 1 "register_operand" "0")
5261 (const_int 31)))]
5262 ""
5263 "#"
5264 "&& reload_completed"
5265 [(parallel [(set (match_dup 0)
5266 (rotate:SI (match_dup 1)
5267 (const_int 31)))
5268 (clobber (reg:CC REG_CC))])])
5269
5270 (define_insn "*rotlsi2.31"
5271 [(set (match_operand:SI 0 "register_operand" "=r")
5272 (rotate:SI (match_operand:SI 1 "register_operand" "0")
5273 (const_int 31)))
5274 (clobber (reg:CC REG_CC))]
5275 "reload_completed"
5276 "bst %A0,0\;ror %D0\;ror %C0\;ror %B0\;ror %A0\;bld %D0,7"
5277 [(set_attr "length" "6")])
5278
5279 ;; Overlapping non-HImode registers often (but not always) need a scratch.
5280 ;; The best we can do is use early clobber alternative "#&r" so that
5281 ;; completely non-overlapping operands dont get a scratch but # so register
5282 ;; allocation does not prefer non-overlapping.
5283
5284
5285 ;; Split word aligned rotates using scratch that is mode dependent.
5286
5287 ;; "*rotwhi"
5288 ;; "*rotwsi"
5289 (define_insn_and_split "*rotw<mode>"
5290 [(set (match_operand:HISI 0 "register_operand" "=r,r,#&r")
5291 (rotate:HISI (match_operand:HISI 1 "register_operand" "0,r,r")
5292 (match_operand 2 "const_int_operand" "n,n,n")))
5293 (clobber (match_scratch:<rotsmode> 3 "=<rotx>"))]
5294 "AVR_HAVE_MOVW
5295 && CONST_INT_P (operands[2])
5296 && <SIZE> % 2 == 0
5297 && 0 == INTVAL (operands[2]) % 16"
5298 "#"
5299 "&& reload_completed"
5300 [(const_int 0)]
5301 {
5302 avr_rotate_bytes (operands);
5303 DONE;
5304 })
5305
5306
5307 ;; Split byte aligned rotates using scratch that is always QI mode.
5308
5309 ;; "*rotbhi"
5310 ;; "*rotbpsi"
5311 ;; "*rotbsi"
5312 (define_insn_and_split "*rotb<mode>"
5313 [(set (match_operand:HISI 0 "register_operand" "=r,r,#&r")
5314 (rotate:HISI (match_operand:HISI 1 "register_operand" "0,r,r")
5315 (match_operand 2 "const_int_operand" "n,n,n")))
5316 (clobber (match_scratch:QI 3 "=<rotx>"))]
5317 "CONST_INT_P (operands[2])
5318 && (8 == INTVAL (operands[2]) % 16
5319 || ((!AVR_HAVE_MOVW
5320 || <SIZE> % 2 != 0)
5321 && 0 == INTVAL (operands[2]) % 16))"
5322 "#"
5323 "&& reload_completed"
5324 [(const_int 0)]
5325 {
5326 avr_rotate_bytes (operands);
5327 DONE;
5328 })
5329
5330
5331 ;;<< << << << << << << << << << << << << << << << << << << << << << << << << <<
5332 ;; arithmetic shift left
5333
5334 ;; Work around PR120423: Transform left shift of a paradoxical subreg
5335 ;; into left shift of the zero-extended entity.
5336 (define_split ; PR120423
5337 [(set (match_operand:HISI 0 "register_operand")
5338 (ashift:HISI (subreg:HISI (match_operand:QIPSI 1 "nonimmediate_operand")
5339 0)
5340 (match_operand:QI 2 "const_int_operand")))]
5341 "!reload_completed
5342 && !avropt_lra_p
5343 && <HISI:SIZE> > <QIPSI:SIZE>"
5344 [(set (match_dup 4)
5345 (zero_extend:HISI (match_dup 5)))
5346 (set (match_dup 0)
5347 (ashift:HISI (match_dup 4)
5348 (match_dup 2)))]
5349 {
5350 operands[4] = gen_reg_rtx (<HISI:MODE>mode);
5351 operands[5] = force_reg (<QIPSI:MODE>mode, operands[1]);
5352 })
5353
5354 ;; Similar happens for PR116389.
5355 (define_split ; PR116389
5356 [(set (match_operand:HISI 0 "register_operand")
5357 (subreg:HISI (match_operand:QIPSI 1 "nonimmediate_operand")
5358 0))]
5359 "!reload_completed
5360 && !avropt_lra_p
5361 && <HISI:SIZE> > <QIPSI:SIZE>"
5362 [(set (match_dup 0)
5363 (zero_extend:HISI (match_dup 2)))]
5364 {
5365 operands[2] = force_reg (<QIPSI:MODE>mode, operands[1]);
5366 })
5367
5368
5369 ;; "ashlqi3"
5370 ;; "ashlqq3" "ashluqq3"
5371 (define_expand "ashl<mode>3"
5372 [(set (match_operand:ALL1 0 "register_operand" "")
5373 (ashift:ALL1 (match_operand:ALL1 1 "register_operand" "")
5374 (match_operand:QI 2 "nop_general_operand" "")))])
5375
5376 (define_split ; ashlqi3_const4
5377 [(set (match_operand:ALL1 0 "d_register_operand" "")
5378 (ashift:ALL1 (match_dup 0)
5379 (const_int 4)))]
5380 ""
5381 [(set (match_dup 1)
5382 (rotate:QI (match_dup 1)
5383 (const_int 4)))
5384 (set (match_dup 1)
5385 (and:QI (match_dup 1)
5386 (const_int -16)))]
5387 {
5388 operands[1] = avr_to_int_mode (operands[0]);
5389 })
5390
5391 (define_split ; ashlqi3_const5
5392 [(set (match_operand:ALL1 0 "d_register_operand" "")
5393 (ashift:ALL1 (match_dup 0)
5394 (const_int 5)))]
5395 ""
5396 [(set (match_dup 1) (rotate:QI (match_dup 1) (const_int 4)))
5397 (set (match_dup 1) (ashift:QI (match_dup 1) (const_int 1)))
5398 (set (match_dup 1) (and:QI (match_dup 1) (const_int -32)))]
5399 {
5400 operands[1] = avr_to_int_mode (operands[0]);
5401 })
5402
5403 (define_split ; ashlqi3_const6
5404 [(set (match_operand:ALL1 0 "d_register_operand" "")
5405 (ashift:ALL1 (match_dup 0)
5406 (const_int 6)))]
5407 ""
5408 [(set (match_dup 1) (rotate:QI (match_dup 1) (const_int 4)))
5409 (set (match_dup 1) (ashift:QI (match_dup 1) (const_int 2)))
5410 (set (match_dup 1) (and:QI (match_dup 1) (const_int -64)))]
5411 {
5412 operands[1] = avr_to_int_mode (operands[0]);
5413 })
5414
5415 ;; "*ashlqi3"
5416 ;; "*ashlqq3" "*ashluqq3"
5417 (define_insn_and_split "*ashl<mode>3_split"
5418 [(set (match_operand:ALL1 0 "register_operand" "=r,r ,r ,r,r")
5419 (ashift:ALL1 (match_operand:ALL1 1 "register_operand" "0,0 ,r ,0,0")
5420 (match_operand:QI 2 "nop_general_operand" "r,LPK,C07 C06,n,Qm")))]
5421 ""
5422 "#"
5423 "&& reload_completed"
5424 [(parallel [(set (match_dup 0)
5425 (ashift:ALL1 (match_dup 1)
5426 (match_dup 2)))
5427 (clobber (reg:CC REG_CC))])])
5428
5429 (define_insn "*ashl<mode>3"
5430 [(set (match_operand:ALL1 0 "register_operand" "=r,r ,r ,r,r")
5431 (ashift:ALL1 (match_operand:ALL1 1 "register_operand" "0,0 ,r ,0,0")
5432 (match_operand:QI 2 "nop_general_operand" "r,LPK,C07 C06,n,Qm")))
5433 (clobber (reg:CC REG_CC))]
5434 "reload_completed"
5435 {
5436 return ashlqi3_out (insn, operands, NULL);
5437 }
5438 [(set_attr "length" "9")
5439 (set_attr "adjust_len" "ashlqi")])
5440
5441 ;; "ashlhi3"
5442 ;; "ashlhq3" "ashluhq3"
5443 ;; "ashlha3" "ashluha3"
5444 (define_insn_and_split "ashl<mode>3"
5445 [(set (match_operand:ALL2 0 "register_operand" "=r,r ,r ,r ,r,r")
5446 (ashift:ALL2 (match_operand:ALL2 1 "register_operand" "0,0 ,r ,r ,0,0")
5447 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C7c C15,C2l,n,Qm")))]
5448 ""
5449 "#"
5450 "&& reload_completed"
5451 [(parallel [(set (match_dup 0)
5452 (ashift:ALL2 (match_dup 1)
5453 (match_dup 2)))
5454 (clobber (reg:CC REG_CC))])]
5455 ""
5456 [(set_attr "isa" "*,*,*,3op,*,*")])
5457
5458 ;; "*ashlhi3"
5459 ;; "*ashlhq3" "*ashluhq3"
5460 ;; "*ashlha3" "*ashluha3"
5461 (define_insn "*ashl<mode>3"
5462 [(set (match_operand:ALL2 0 "register_operand" "=r,r ,r ,r ,r,r")
5463 (ashift:ALL2 (match_operand:ALL2 1 "register_operand" "0,0 ,r ,r ,0,0")
5464 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C7c C15,C2l,n,Qm")))
5465 (clobber (reg:CC REG_CC))]
5466 "reload_completed"
5467 {
5468 return ashlhi3_out (insn, operands, NULL);
5469 }
5470 [(set_attr "isa" "*,*,*,3op,*,*")
5471 (set_attr "length" "10")
5472 (set_attr "adjust_len" "ashlhi")])
5473
5474
5475 ;; Insns like the following are generated when (implicitly) extending 8-bit shifts
5476 ;; like char1 = char2 << char3. Only the low-byte is needed in that situation.
5477
5478 ;; "*ashluqihiqi3"
5479 ;; "*ashlsqihiqi3"
5480 (define_insn_and_split "*ashl<extend_su>qihiqi3"
5481 [(set (match_operand:QI 0 "register_operand" "=r")
5482 (subreg:QI (ashift:HI (any_extend:HI (match_operand:QI 1 "register_operand" "0"))
5483 (match_operand:QI 2 "register_operand" "r"))
5484 0))]
5485 ""
5486 "#"
5487 ""
5488 [(set (match_dup 0)
5489 (ashift:QI (match_dup 1)
5490 (match_dup 2)))])
5491
5492 ;; ??? Combiner does not recognize that it could split the following insn;
5493 ;; presumably because he has no register handy?
5494
5495 ;; "*ashluqihiqi3.mem"
5496 ;; "*ashlsqihiqi3.mem"
5497 (define_insn_and_split "*ashl<extend_su>qihiqi3.mem"
5498 [(set (match_operand:QI 0 "memory_operand" "=m")
5499 (subreg:QI (ashift:HI (any_extend:HI (match_operand:QI 1 "register_operand" "r"))
5500 (match_operand:QI 2 "register_operand" "r"))
5501 0))]
5502 "!reload_completed"
5503 { gcc_unreachable(); }
5504 "&& 1"
5505 [(set (match_dup 3)
5506 (ashift:QI (match_dup 1)
5507 (match_dup 2)))
5508 (set (match_dup 0)
5509 (match_dup 3))]
5510 {
5511 operands[3] = gen_reg_rtx (QImode);
5512 })
5513
5514 ;; Similar.
5515
5516 (define_insn_and_split "*ashlhiqi3"
5517 [(set (match_operand:QI 0 "nonimmediate_operand" "=r")
5518 (subreg:QI (ashift:HI (match_operand:HI 1 "register_operand" "0")
5519 (match_operand:QI 2 "register_operand" "r")) 0))]
5520 "!reload_completed"
5521 { gcc_unreachable(); }
5522 "&& 1"
5523 [(set (match_dup 4)
5524 (ashift:QI (match_dup 3)
5525 (match_dup 2)))
5526 (set (match_dup 0)
5527 (match_dup 4))]
5528 {
5529 operands[3] = simplify_gen_subreg (QImode, operands[1], HImode, 0);
5530 operands[4] = gen_reg_rtx (QImode);
5531 })
5532
5533 ;; High part of 16-bit shift is unused after the instruction:
5534 ;; No need to compute it, map to 8-bit shift.
5535
5536 (define_peephole2
5537 [(parallel [(set (match_operand:HI 0 "register_operand" "")
5538 (ashift:HI (match_dup 0)
5539 (match_operand:QI 1 "register_operand" "")))
5540 (clobber (reg:CC REG_CC))])]
5541 ""
5542 [(parallel [(set (match_dup 2)
5543 (ashift:QI (match_dup 2)
5544 (match_dup 1)))
5545 (clobber (reg:CC REG_CC))])
5546 (clobber (match_dup 3))]
5547 {
5548 operands[3] = simplify_gen_subreg (QImode, operands[0], HImode, 1);
5549
5550 if (!peep2_reg_dead_p (1, operands[3]))
5551 FAIL;
5552
5553 operands[2] = simplify_gen_subreg (QImode, operands[0], HImode, 0);
5554 })
5555
5556
5557 ;; "ashlsi3"
5558 ;; "ashlsq3" "ashlusq3"
5559 ;; "ashlsa3" "ashlusa3"
5560 (define_insn_and_split "ashl<mode>3"
5561 [(set (match_operand:ALL4 0 "register_operand" "=r,r ,r ,r ,r,r")
5562 (ashift:ALL4 (match_operand:ALL4 1 "register_operand" "0,0 ,r ,r ,0,0")
5563 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C4L,C4l,n,Qm")))]
5564 ""
5565 "#"
5566 "&& reload_completed"
5567 [(parallel [(set (match_dup 0)
5568 (ashift:ALL4 (match_dup 1)
5569 (match_dup 2)))
5570 (clobber (reg:CC REG_CC))])]
5571 ""
5572 [(set_attr "isa" "*,*,*,3op,*,*")])
5573
5574 (define_insn "*ashl<mode>3"
5575 [(set (match_operand:ALL4 0 "register_operand" "=r,r ,r ,r ,r,r")
5576 (ashift:ALL4 (match_operand:ALL4 1 "register_operand" "0,0 ,r ,r ,0,0")
5577 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C4L,C4l,n,Qm")))
5578 (clobber (reg:CC REG_CC))]
5579 "reload_completed"
5580 {
5581 return ashlsi3_out (insn, operands, NULL);
5582 }
5583 [(set_attr "isa" "*,*,*,3op,*,*")
5584 (set_attr "length" "12")
5585 (set_attr "adjust_len" "ashlsi")])
5586
5587 ;; Optimize if a scratch register from LD_REGS happens to be available.
5588
5589 (define_peephole2 ; ashlqi3_l_const4
5590 [(parallel [(set (match_operand:ALL1 0 "l_register_operand" "")
5591 (ashift:ALL1 (match_dup 0)
5592 (const_int 4)))
5593 (clobber (reg:CC REG_CC))])
5594 (match_scratch:QI 1 "d")]
5595 ""
5596 [(parallel [(set (match_dup 2) (rotate:QI (match_dup 2) (const_int 4)))
5597 (clobber (reg:CC REG_CC))])
5598 (parallel [(set (match_dup 1) (const_int -16))
5599 (clobber (reg:CC REG_CC))])
5600 (parallel [(set (match_dup 2) (and:QI (match_dup 2) (match_dup 1)))
5601 (clobber (reg:CC REG_CC))])]
5602 {
5603 operands[2] = avr_to_int_mode (operands[0]);
5604 })
5605
5606 (define_peephole2 ; ashlqi3_l_const5
5607 [(parallel [(set (match_operand:ALL1 0 "l_register_operand" "")
5608 (ashift:ALL1 (match_dup 0)
5609 (const_int 5)))
5610 (clobber (reg:CC REG_CC))])
5611 (match_scratch:QI 1 "d")]
5612 ""
5613 [(parallel [(set (match_dup 2) (rotate:QI (match_dup 2) (const_int 4)))
5614 (clobber (reg:CC REG_CC))])
5615 (parallel [(set (match_dup 2) (ashift:QI (match_dup 2) (const_int 1)))
5616 (clobber (reg:CC REG_CC))])
5617 (parallel [(set (match_dup 1) (const_int -32))
5618 (clobber (reg:CC REG_CC))])
5619 (parallel [(set (match_dup 2) (and:QI (match_dup 2) (match_dup 1)))
5620 (clobber (reg:CC REG_CC))])]
5621 {
5622 operands[2] = avr_to_int_mode (operands[0]);
5623 })
5624
5625 (define_peephole2 ; ashlqi3_l_const6
5626 [(parallel [(set (match_operand:ALL1 0 "l_register_operand" "")
5627 (ashift:ALL1 (match_dup 0)
5628 (const_int 6)))
5629 (clobber (reg:CC REG_CC))])
5630 (match_scratch:QI 1 "d")]
5631 ""
5632 [(parallel [(set (match_dup 2) (rotate:QI (match_dup 2) (const_int 4)))
5633 (clobber (reg:CC REG_CC))])
5634 (parallel [(set (match_dup 2) (ashift:QI (match_dup 2) (const_int 2)))
5635 (clobber (reg:CC REG_CC))])
5636 (parallel [(set (match_dup 1) (const_int -64))
5637 (clobber (reg:CC REG_CC))])
5638 (parallel [(set (match_dup 2) (and:QI (match_dup 2) (match_dup 1)))
5639 (clobber (reg:CC REG_CC))])]
5640 {
5641 operands[2] = avr_to_int_mode (operands[0]);
5642 })
5643
5644 ;; Endow 2-byte shift with a scratch if available.
5645 (define_peephole2 ; *ashlhi3_const *ashrhi3_const *lshrhi3_const
5646 [(match_scratch:QI 3 "d")
5647 (parallel [(set (match_operand:ALL2 0 "register_operand")
5648 (any_shift:ALL2 (match_operand:ALL2 1 "register_operand")
5649 (match_operand:QI 2 "const_int_operand")))
5650 (clobber (reg:CC REG_CC))])
5651 ;; Don't allow $3 to overlap with $0.
5652 (match_dup 3)]
5653 ""
5654 [(parallel [(set (match_dup 0)
5655 (any_shift:ALL2 (match_dup 1)
5656 (match_dup 2)))
5657 (clobber (match_dup 3))
5658 (clobber (reg:CC REG_CC))])])
5659
5660 ;; "*ashlhi3_const"
5661 ;; "*ashlhq3_const" "*ashluhq3_const"
5662 ;; "*ashlha3_const" "*ashluha3_const"
5663 (define_insn "*ashl<mode>3_const"
5664 [(set (match_operand:ALL2 0 "register_operand" "=r ,r ,r ,r ,r")
5665 (ashift:ALL2 (match_operand:ALL2 1 "register_operand" "0 ,r ,r ,r ,0")
5666 (match_operand:QI 2 "const_int_operand" "LPK,O C7c C15,C05 C06,C2l,n")))
5667 (clobber (match_scratch:QI 3 "=X ,X ,&d ,&d ,&d"))
5668 (clobber (reg:CC REG_CC))]
5669 "reload_completed"
5670 {
5671 return ashlhi3_out (insn, operands, NULL);
5672 }
5673 [(set_attr "isa" "*,*,mul,3op,*")
5674 (set_attr "length" "10")
5675 (set_attr "adjust_len" "ashlhi")])
5676
5677 (define_code_attr constr_split_suffix
5678 [(ashift "l")
5679 (ashiftrt "a")
5680 (lshiftrt "r")])
5681
5682 ;; Split shift into a byte shift and a residual bit shift (without scratch)
5683 (define_split
5684 [(parallel [(set (match_operand:ALL234 0 "register_operand")
5685 (any_shift:ALL234 (match_operand:ALL234 1 "register_operand")
5686 (match_operand:QI 2 "const_int_operand")))
5687 (clobber (reg:CC REG_CC))])]
5688 "avropt_split_bit_shift
5689 && n_avr_fuse_add_executed >= 1
5690 && satisfies_constraint_C<SIZE><constr_split_suffix> (operands[2])"
5691 [(parallel [(set (match_dup 0)
5692 (any_shift:ALL234 (match_dup 1)
5693 (match_dup 3)))
5694 (clobber (scratch:QI))
5695 (clobber (reg:CC REG_CC))])
5696 (parallel [(set (match_dup 0)
5697 (any_shift:ALL234 (match_dup 0)
5698 (match_dup 4)))
5699 (clobber (reg:CC REG_CC))])]
5700 {
5701 int offset = INTVAL (operands[2]);
5702 if (avr_split_shift (operands, NULL_RTX, <CODE>))
5703 DONE;
5704 else if (offset <= 8)
5705 FAIL;
5706 operands[3] = GEN_INT (offset & ~7);
5707 operands[4] = GEN_INT (offset & 7);
5708 })
5709
5710 ;; Split shift into a byte shift and a residual bit shift (with scratch)
5711 (define_split
5712 [(parallel [(set (match_operand:ALL234 0 "register_operand")
5713 (any_shift:ALL234 (match_operand:ALL234 1 "register_operand")
5714 (match_operand:QI 2 "const_int_operand")))
5715 (clobber (match_operand:QI 3 "scratch_or_dreg_operand"))
5716 (clobber (reg:CC REG_CC))])]
5717 "avropt_split_bit_shift
5718 && n_avr_fuse_add_executed >= 1
5719 && satisfies_constraint_C<SIZE><constr_split_suffix> (operands[2])"
5720 [(parallel [(set (match_dup 0)
5721 (any_shift:ALL234 (match_dup 1)
5722 (match_dup 4)))
5723 (clobber (scratch:QI))
5724 (clobber (reg:CC REG_CC))])
5725 (parallel [(set (match_dup 0)
5726 (any_shift:ALL234 (match_dup 0)
5727 (match_dup 5)))
5728 (clobber (match_dup 3))
5729 (clobber (reg:CC REG_CC))])]
5730 {
5731 int offset = INTVAL (operands[2]);
5732 if (avr_split_shift (operands, operands[3], <CODE>))
5733 DONE;
5734 else if (offset <= 8)
5735 FAIL;
5736 operands[4] = GEN_INT (offset & ~7);
5737 operands[5] = GEN_INT (offset & 7);
5738 })
5739
5740
5741 ;; Endow 4-byte shift with a scratch if available.
5742 (define_peephole2 ; *ashrsi3_const *lshrsi3_const *ashlsi3_const
5743 [(match_scratch:QI 3 "d")
5744 (parallel [(set (match_operand:ALL4 0 "register_operand")
5745 (any_shift:ALL4 (match_operand:ALL4 1 "register_operand")
5746 (match_operand:QI 2 "const_int_operand")))
5747 (clobber (reg:CC REG_CC))])
5748 ;; $3 must not overlap with the output of the insn above.
5749 (match_dup 3)]
5750 ""
5751 [(parallel [(set (match_dup 0)
5752 (any_shift:ALL4 (match_dup 1)
5753 (match_dup 2)))
5754 (clobber (match_dup 3))
5755 (clobber (reg:CC REG_CC))])])
5756
5757
5758 ;; "*ashlsi3_const"
5759 ;; "*ashlsq3_const" "*ashlusq3_const"
5760 ;; "*ashlsa3_const" "*ashlusa3_const"
5761 (define_insn "*ashl<mode>3_const"
5762 [(set (match_operand:ALL4 0 "register_operand" "=r ,r ,r ,r")
5763 (ashift:ALL4 (match_operand:ALL4 1 "register_operand" "0 ,r ,r ,0")
5764 (match_operand:QI 2 "const_int_operand" "LP,O C4L,C4l,n")))
5765 (clobber (match_operand:QI 3 "scratch_or_dreg_operand" "=X ,X ,&d ,&d"))
5766 (clobber (reg:CC REG_CC))]
5767 "reload_completed"
5768 {
5769 return ashlsi3_out (insn, operands, NULL);
5770 }
5771 [(set_attr "isa" "*,*,3op,*")
5772 (set_attr "length" "10")
5773 (set_attr "adjust_len" "ashlsi")])
5774
5775 (define_expand "ashlpsi3"
5776 [(parallel [(set (match_operand:PSI 0 "register_operand" "")
5777 (ashift:PSI (match_operand:PSI 1 "register_operand" "")
5778 (match_operand:QI 2 "nonmemory_operand" "")))
5779 (clobber (scratch:QI))])]
5780 ""
5781 {
5782 if (AVR_HAVE_MUL
5783 && CONST_INT_P (operands[2]))
5784 {
5785 if (IN_RANGE (INTVAL (operands[2]), 3, 6))
5786 {
5787 rtx xoffset = force_reg (QImode, gen_int_mode (1 << INTVAL (operands[2]), QImode));
5788 emit_insn (gen_mulsqipsi3 (operands[0], xoffset, operands[1]));
5789 DONE;
5790 }
5791 else if (optimize_insn_for_speed_p ()
5792 && INTVAL (operands[2]) != 16
5793 && IN_RANGE (INTVAL (operands[2]), 9, 22))
5794 {
5795 rtx xoffset = force_reg (PSImode, gen_int_mode (1 << INTVAL (operands[2]), PSImode));
5796 emit_insn (gen_mulpsi3 (operands[0], operands[1], xoffset));
5797 DONE;
5798 }
5799 }
5800 })
5801
5802 (define_insn_and_split "*ashlpsi3_split"
5803 [(set (match_operand:PSI 0 "register_operand" "=r,r,r ,r ,r")
5804 (ashift:PSI (match_operand:PSI 1 "register_operand" "0,0,r ,r ,0")
5805 (match_operand:QI 2 "nonmemory_operand" "r,P,O C15 C23,C3l,n")))
5806 (clobber (match_scratch:QI 3 "=X,X,X ,&d ,&d"))]
5807 ""
5808 "#"
5809 "&& reload_completed"
5810 [(parallel [(set (match_dup 0)
5811 (ashift:PSI (match_dup 1)
5812 (match_dup 2)))
5813 (clobber (match_dup 3))
5814 (clobber (reg:CC REG_CC))])]
5815 ""
5816 [(set_attr "isa" "*,*,*,3op,*")])
5817
5818 (define_insn "*ashlpsi3"
5819 [(set (match_operand:PSI 0 "register_operand" "=r,r,r ,r ,r")
5820 (ashift:PSI (match_operand:PSI 1 "register_operand" "0,0,r ,r ,0")
5821 (match_operand:QI 2 "nonmemory_operand" "r,P,O C15 C23,C3l,n")))
5822 ; "X&d" since the insn may be a split of a 4-byte shift without scratch.
5823 (clobber (match_scratch:QI 3 "=X,X,X ,X&d,X&d"))
5824 (clobber (reg:CC REG_CC))]
5825 "reload_completed"
5826 {
5827 return avr_out_ashlpsi3 (insn, operands, NULL);
5828 }
5829 [(set_attr "isa" "*,*,*,3op,*")
5830 (set_attr "adjust_len" "ashlpsi")])
5831
5832 ;; Seen in PSI loads from __flashx tables.
5833 (define_insn_and_split "*ashlqi.1.zextpsi_split"
5834 [(set (match_operand:PSI 0 "register_operand" "=r")
5835 (zero_extend:PSI
5836 (ashift:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
5837 (const_int 1))))]
5838 ""
5839 "#"
5840 "&& reload_completed"
5841 [(parallel [(set (match_dup 2)
5842 (const_int 0))
5843 (clobber (reg:CC REG_CC))])
5844 (parallel [(set (match_dup 3)
5845 (const_int 0))
5846 (clobber (reg:CC REG_CC))])
5847 (parallel [(set (match_dup 4)
5848 (ashift:HI (match_dup 4)
5849 (const_int 1)))
5850 (clobber (reg:CC REG_CC))])]
5851 {
5852 operands[2] = avr_byte (operands[0], 2);
5853 operands[3] = avr_byte (operands[0], 1);
5854 operands[4] = avr_word (operands[0], 0);
5855 })
5856
5857 ;; >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
5858 ;; arithmetic shift right
5859
5860 ;; "ashrqi3"
5861 ;; "ashrqq3" "ashruqq3"
5862 (define_insn_and_split "ashr<mode>3"
5863 [(set (match_operand:ALL1 0 "register_operand" "=r,r ,r ,r")
5864 (ashiftrt:ALL1 (match_operand:ALL1 1 "register_operand" "0,0 ,r ,0")
5865 (match_operand:QI 2 "nop_general_operand" "r,LPK C03 C04 C05,C06 C07,Qm")))]
5866 ""
5867 "#"
5868 "&& reload_completed"
5869 [(parallel [(set (match_dup 0)
5870 (ashiftrt:ALL1 (match_dup 1)
5871 (match_dup 2)))
5872 (clobber (reg:CC REG_CC))])])
5873
5874 (define_insn "*ashr<mode>3"
5875 [(set (match_operand:ALL1 0 "register_operand" "=r,r ,r ,r")
5876 (ashiftrt:ALL1 (match_operand:ALL1 1 "register_operand" "0,0 ,r ,0")
5877 (match_operand:QI 2 "nop_general_operand" "r,LPK C03 C04 C05,C06 C07,Qm")))
5878 (clobber (reg:CC REG_CC))]
5879 "reload_completed"
5880 {
5881 return ashrqi3_out (insn, operands, NULL);
5882 }
5883 [(set_attr "length" "9")
5884 (set_attr "adjust_len" "ashrqi")])
5885
5886 ;; "ashrhi3"
5887 ;; "ashrhq3" "ashruhq3"
5888 ;; "ashrha3" "ashruha3"
5889 (define_insn_and_split "ashr<mode>3"
5890 [(set (match_operand:ALL2 0 "register_operand" "=r,r ,r ,r ,r,r")
5891 (ashiftrt:ALL2 (match_operand:ALL2 1 "register_operand" "0,0 ,r ,r ,0,0")
5892 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C07 C14 C15,C2a,n,Qm")))]
5893 ""
5894 "#"
5895 "&& reload_completed"
5896 [(parallel [(set (match_dup 0)
5897 (ashiftrt:ALL2 (match_dup 1)
5898 (match_dup 2)))
5899 (clobber (reg:CC REG_CC))])]
5900 ""
5901 [(set_attr "isa" "*,*,*,3op,*,*")])
5902
5903 ;; "*ashrhi3"
5904 ;; "*ashrhq3" "*ashruhq3"
5905 ;; "*ashrha3" "*ashruha3"
5906 (define_insn "*ashr<mode>3"
5907 [(set (match_operand:ALL2 0 "register_operand" "=r,r ,r ,r ,r,r")
5908 (ashiftrt:ALL2 (match_operand:ALL2 1 "register_operand" "0,0 ,r ,r ,0,0")
5909 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C07 C14 C15,C2a,n,Qm")))
5910 (clobber (reg:CC REG_CC))]
5911 "reload_completed"
5912 {
5913 return ashrhi3_out (insn, operands, NULL);
5914 }
5915 [(set_attr "isa" "*,*,*,3op,*,*")
5916 (set_attr "length" "10")
5917 (set_attr "adjust_len" "ashrhi")])
5918
5919 (define_insn_and_split "ashrpsi3"
5920 [(set (match_operand:PSI 0 "register_operand" "=r,r ,r ,r ,r")
5921 (ashiftrt:PSI (match_operand:PSI 1 "register_operand" "0,0 ,r ,r ,0")
5922 (match_operand:QI 2 "nonmemory_operand" "r,PK,O C15 C22 C23,C3a,n")))
5923 (clobber (match_scratch:QI 3 "=X,X ,X ,&d ,&d"))]
5924 ""
5925 "#"
5926 "&& reload_completed"
5927 [(parallel [(set (match_dup 0)
5928 (ashiftrt:PSI (match_dup 1)
5929 (match_dup 2)))
5930 (clobber (match_dup 3))
5931 (clobber (reg:CC REG_CC))])]
5932 ""
5933 [(set_attr "isa" "*,*,*,3op,*")])
5934
5935 (define_insn "*ashrpsi3"
5936 [(set (match_operand:PSI 0 "register_operand" "=r,r ,r ,r ,r")
5937 (ashiftrt:PSI (match_operand:PSI 1 "register_operand" "0,0 ,r ,r ,0")
5938 (match_operand:QI 2 "nonmemory_operand" "r,PK,O C15 C22 C23,C3a,n")))
5939 ; "X&d" since the insn may be a split of a 4-byte shift without scratch.
5940 (clobber (match_scratch:QI 3 "=X,X ,X ,X&d,X&d"))
5941 (clobber (reg:CC REG_CC))]
5942 "reload_completed"
5943 {
5944 return avr_out_ashrpsi3 (insn, operands, NULL);
5945 }
5946 [(set_attr "isa" "*,*,*,3op,*")
5947 (set_attr "adjust_len" "ashrpsi")])
5948
5949 ;; "ashrsi3"
5950 ;; "ashrsq3" "ashrusq3"
5951 ;; "ashrsa3" "ashrusa3"
5952 (define_insn_and_split "ashr<mode>3"
5953 [(set (match_operand:ALL4 0 "register_operand" "=r,r ,r ,r ,r,r")
5954 (ashiftrt:ALL4 (match_operand:ALL4 1 "register_operand" "0,0 ,r ,r ,0,0")
5955 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C15 C30 C31,C4a,n,Qm")))]
5956 ""
5957 "#"
5958 "&& reload_completed"
5959 [(parallel [(set (match_dup 0)
5960 (ashiftrt:ALL4 (match_dup 1)
5961 (match_dup 2)))
5962 (clobber (reg:CC REG_CC))])]
5963 ""
5964 [(set_attr "isa" "*,*,*,3op,*,*")])
5965
5966 (define_insn "*ashr<mode>3"
5967 [(set (match_operand:ALL4 0 "register_operand" "=r,r ,r ,r ,r,r")
5968 (ashiftrt:ALL4 (match_operand:ALL4 1 "register_operand" "0,0 ,r ,r ,0,0")
5969 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C15 C30 C31,C4a,n,Qm")))
5970 (clobber (reg:CC REG_CC))]
5971 "reload_completed"
5972 {
5973 return ashrsi3_out (insn, operands, NULL);
5974 }
5975 [(set_attr "isa" "*,*,*,3op,*,*")
5976 (set_attr "length" "12")
5977 (set_attr "adjust_len" "ashrsi")])
5978
5979
5980 ;; "*ashrhi3_const"
5981 ;; "*ashrhq3_const" "*ashruhq3_const"
5982 ;; "*ashrha3_const" "*ashruha3_const"
5983 (define_insn "*ashr<mode>3_const"
5984 [(set (match_operand:ALL2 0 "register_operand" "=r ,r ,r ,r")
5985 (ashiftrt:ALL2 (match_operand:ALL2 1 "register_operand" "0 ,r ,r ,0")
5986 (match_operand:QI 2 "const_int_operand" "LPK,O C07 C14 C15,C2a,n")))
5987 (clobber (match_scratch:QI 3 "=X ,X ,&d ,&d"))
5988 (clobber (reg:CC REG_CC))]
5989 "reload_completed"
5990 {
5991 return ashrhi3_out (insn, operands, NULL);
5992 }
5993 [(set_attr "isa" "*,*,3op,*")
5994 (set_attr "length" "10")
5995 (set_attr "adjust_len" "ashrhi")])
5996
5997
5998 ;; "*ashrsi3_const"
5999 ;; "*ashrsq3_const" "*ashrusq3_const"
6000 ;; "*ashrsa3_const" "*ashrusa3_const"
6001 (define_insn "*ashr<mode>3_const"
6002 [(set (match_operand:ALL4 0 "register_operand" "=r ,r ,r ,r")
6003 (ashiftrt:ALL4 (match_operand:ALL4 1 "register_operand" "0 ,r ,r ,0")
6004 (match_operand:QI 2 "const_int_operand" "LP,O C15 C30 C31,C4a,n")))
6005 (clobber (match_operand:QI 3 "scratch_or_dreg_operand" "=X ,X ,&d ,&d"))
6006 (clobber (reg:CC REG_CC))]
6007 "reload_completed"
6008 {
6009 return ashrsi3_out (insn, operands, NULL);
6010 }
6011 [(set_attr "isa" "*,*,3op,*")
6012 (set_attr "length" "10")
6013 (set_attr "adjust_len" "ashrsi")])
6014
6015 ;; >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
6016 ;; logical shift right
6017
6018 ;; "lshrqi3"
6019 ;; "lshrqq3" "lshruqq3"
6020 (define_expand "lshr<mode>3"
6021 [(set (match_operand:ALL1 0 "register_operand" "")
6022 (lshiftrt:ALL1 (match_operand:ALL1 1 "register_operand" "")
6023 (match_operand:QI 2 "nop_general_operand" "")))])
6024
6025 (define_split ; lshrqi3_const4
6026 [(set (match_operand:ALL1 0 "d_register_operand" "")
6027 (lshiftrt:ALL1 (match_dup 0)
6028 (const_int 4)))]
6029 ""
6030 [(set (match_dup 1)
6031 (rotate:QI (match_dup 1)
6032 (const_int 4)))
6033 (set (match_dup 1)
6034 (and:QI (match_dup 1)
6035 (const_int 15)))]
6036 {
6037 operands[1] = avr_to_int_mode (operands[0]);
6038 })
6039
6040 (define_split ; lshrqi3_const5
6041 [(set (match_operand:ALL1 0 "d_register_operand" "")
6042 (lshiftrt:ALL1 (match_dup 0)
6043 (const_int 5)))]
6044 ""
6045 [(set (match_dup 1) (rotate:QI (match_dup 1) (const_int 4)))
6046 (set (match_dup 1) (lshiftrt:QI (match_dup 1) (const_int 1)))
6047 (set (match_dup 1) (and:QI (match_dup 1) (const_int 7)))]
6048 {
6049 operands[1] = avr_to_int_mode (operands[0]);
6050 })
6051
6052 (define_split ; lshrqi3_const6
6053 [(set (match_operand:QI 0 "d_register_operand" "")
6054 (lshiftrt:QI (match_dup 0)
6055 (const_int 6)))]
6056 ""
6057 [(set (match_dup 1) (rotate:QI (match_dup 1) (const_int 4)))
6058 (set (match_dup 1) (lshiftrt:QI (match_dup 1) (const_int 2)))
6059 (set (match_dup 1) (and:QI (match_dup 1) (const_int 3)))]
6060 {
6061 operands[1] = avr_to_int_mode (operands[0]);
6062 })
6063
6064 ;; "*lshrqi3"
6065 ;; "*lshrqq3"
6066 ;; "*lshruqq3"
6067 (define_insn_and_split "*lshr<mode>3_split"
6068 [(set (match_operand:ALL1 0 "register_operand" "=r,r ,r ,r,r")
6069 (lshiftrt:ALL1 (match_operand:ALL1 1 "register_operand" "0,0 ,r ,0,0")
6070 (match_operand:QI 2 "nop_general_operand" "r,LPK,C07 C06,n,Qm")))]
6071 ""
6072 "#"
6073 "&& reload_completed"
6074 [(parallel [(set (match_dup 0)
6075 (lshiftrt:ALL1 (match_dup 1)
6076 (match_dup 2)))
6077 (clobber (reg:CC REG_CC))])])
6078
6079 (define_insn "*lshr<mode>3"
6080 [(set (match_operand:ALL1 0 "register_operand" "=r,r ,r ,r,r")
6081 (lshiftrt:ALL1 (match_operand:ALL1 1 "register_operand" "0,0 ,r ,0,0")
6082 (match_operand:QI 2 "nop_general_operand" "r,LPK,C07 C06,n,Qm")))
6083 (clobber (reg:CC REG_CC))]
6084 "reload_completed"
6085 {
6086 return lshrqi3_out (insn, operands, NULL);
6087 }
6088 [(set_attr "adjust_len" "lshrqi")])
6089
6090 ;; "lshrhi3"
6091 ;; "lshrhq3" "lshruhq3"
6092 ;; "lshrha3" "lshruha3"
6093 (define_insn_and_split "lshr<mode>3"
6094 [(set (match_operand:ALL2 0 "register_operand" "=r,r ,r ,r ,r,r")
6095 (lshiftrt:ALL2 (match_operand:ALL2 1 "register_operand" "0,0 ,r ,r ,0,0")
6096 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C7c C15,C2r,n,Qm")))]
6097 ""
6098 "#"
6099 "&& reload_completed"
6100 [(parallel [(set (match_dup 0)
6101 (lshiftrt:ALL2 (match_dup 1)
6102 (match_dup 2)))
6103 (clobber (reg:CC REG_CC))])]
6104 ""
6105 [(set_attr "isa" "*,*,*,3op,*,*")])
6106
6107 (define_insn "*lshr<mode>3"
6108 [(set (match_operand:ALL2 0 "register_operand" "=r,r ,r ,r ,r,r")
6109 (lshiftrt:ALL2 (match_operand:ALL2 1 "register_operand" "0,0 ,r ,r ,0,0")
6110 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C7c C15,C2r,n,Qm")))
6111 (clobber (reg:CC REG_CC))]
6112 "reload_completed"
6113 {
6114 return lshrhi3_out (insn, operands, NULL);
6115 }
6116 [(set_attr "isa" "*,*,*,3op,*,*")
6117 (set_attr "adjust_len" "lshrhi")])
6118
6119 (define_insn_and_split "lshrpsi3"
6120 [(set (match_operand:PSI 0 "register_operand" "=r,r ,r ,r ,r")
6121 (lshiftrt:PSI (match_operand:PSI 1 "register_operand" "0,0 ,r ,r ,0")
6122 (match_operand:QI 2 "nonmemory_operand" "r,PK,O C15 C23,C3r,n")))
6123 (clobber (match_scratch:QI 3 "=X,X ,X ,&d ,&d"))]
6124 ""
6125 "#"
6126 "&& reload_completed"
6127 [(parallel [(set (match_dup 0)
6128 (lshiftrt:PSI (match_dup 1)
6129 (match_dup 2)))
6130 (clobber (match_dup 3))
6131 (clobber (reg:CC REG_CC))])]
6132 ""
6133 [(set_attr "isa" "*,*,*,3op,*")])
6134
6135 (define_insn "*lshrpsi3"
6136 [(set (match_operand:PSI 0 "register_operand" "=r,r ,r ,r ,r")
6137 (lshiftrt:PSI (match_operand:PSI 1 "register_operand" "0,0 ,r ,r ,0")
6138 (match_operand:QI 2 "nonmemory_operand" "r,PK,O C15 C23,C3r,n")))
6139 ; "X&d" since the insn may be a split of a 4-byte shift without scratch.
6140 (clobber (match_scratch:QI 3 "=X,X ,X ,X&d,X&d"))
6141 (clobber (reg:CC REG_CC))]
6142 "reload_completed"
6143 {
6144 return avr_out_lshrpsi3 (insn, operands, NULL);
6145 }
6146 [(set_attr "isa" "*,*,*,3op,*")
6147 (set_attr "adjust_len" "lshrpsi")])
6148
6149 ;; "lshrsi3"
6150 ;; "lshrsq3" "lshrusq3"
6151 ;; "lshrsa3" "lshrusa3"
6152 (define_insn_and_split "lshr<mode>3"
6153 [(set (match_operand:ALL4 0 "register_operand" "=r,r ,r ,r ,r,r")
6154 (lshiftrt:ALL4 (match_operand:ALL4 1 "register_operand" "0,0 ,r ,r ,0,0")
6155 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C4R,C4r,n,Qm")))]
6156 ""
6157 "#"
6158 "&& reload_completed"
6159 [(parallel [(set (match_dup 0)
6160 (lshiftrt:ALL4 (match_dup 1)
6161 (match_dup 2)))
6162 (clobber (reg:CC REG_CC))])]
6163 ""
6164 [(set_attr "isa" "*,*,*,3op,*,*")])
6165
6166 (define_insn "*lshr<mode>3"
6167 [(set (match_operand:ALL4 0 "register_operand" "=r,r ,r ,r ,r,r")
6168 (lshiftrt:ALL4 (match_operand:ALL4 1 "register_operand" "0,0 ,r ,r ,0,0")
6169 (match_operand:QI 2 "nop_general_operand" "r,LPK,O C4R,C4r,n,Qm")))
6170 (clobber (reg:CC REG_CC))]
6171 "reload_completed"
6172 {
6173 return lshrsi3_out (insn, operands, NULL);
6174 }
6175 [(set_attr "isa" "*,*,*,3op,*,*")
6176 (set_attr "adjust_len" "lshrsi")])
6177
6178 ;; Optimize if a scratch register from LD_REGS happens to be available.
6179
6180 (define_peephole2 ; lshrqi3_l_const4
6181 [(parallel [(set (match_operand:ALL1 0 "l_register_operand" "")
6182 (lshiftrt:ALL1 (match_dup 0)
6183 (const_int 4)))
6184 (clobber (reg:CC REG_CC))])
6185 (match_scratch:QI 1 "d")]
6186 ""
6187 [(parallel [(set (match_dup 2) (rotate:QI (match_dup 2) (const_int 4)))
6188 (clobber (reg:CC REG_CC))])
6189 (parallel [(set (match_dup 1) (const_int 15))
6190 (clobber (reg:CC REG_CC))])
6191 (parallel [(set (match_dup 2) (and:QI (match_dup 2) (match_dup 1)))
6192 (clobber (reg:CC REG_CC))])]
6193 {
6194 operands[2] = avr_to_int_mode (operands[0]);
6195 })
6196
6197 (define_peephole2 ; lshrqi3_l_const5
6198 [(parallel [(set (match_operand:ALL1 0 "l_register_operand" "")
6199 (lshiftrt:ALL1 (match_dup 0)
6200 (const_int 5)))
6201 (clobber (reg:CC REG_CC))])
6202 (match_scratch:QI 1 "d")]
6203 ""
6204 [(parallel [(set (match_dup 2) (rotate:QI (match_dup 2) (const_int 4)))
6205 (clobber (reg:CC REG_CC))])
6206 (parallel [(set (match_dup 2) (lshiftrt:QI (match_dup 2) (const_int 1)))
6207 (clobber (reg:CC REG_CC))])
6208 (parallel [(set (match_dup 1) (const_int 7))
6209 (clobber (reg:CC REG_CC))])
6210 (parallel [(set (match_dup 2) (and:QI (match_dup 2) (match_dup 1)))
6211 (clobber (reg:CC REG_CC))])]
6212 {
6213 operands[2] = avr_to_int_mode (operands[0]);
6214 })
6215
6216 (define_peephole2 ; lshrqi3_l_const6
6217 [(parallel [(set (match_operand:ALL1 0 "l_register_operand" "")
6218 (lshiftrt:ALL1 (match_dup 0)
6219 (const_int 6)))
6220 (clobber (reg:CC REG_CC))])
6221 (match_scratch:QI 1 "d")]
6222 ""
6223 [(parallel [(set (match_dup 2) (rotate:QI (match_dup 2) (const_int 4)))
6224 (clobber (reg:CC REG_CC))])
6225 (parallel [(set (match_dup 2) (lshiftrt:QI (match_dup 2) (const_int 2)))
6226 (clobber (reg:CC REG_CC))])
6227 (parallel [(set (match_dup 1) (const_int 3))
6228 (clobber (reg:CC REG_CC))])
6229 (parallel [(set (match_dup 2) (and:QI (match_dup 2) (match_dup 1)))
6230 (clobber (reg:CC REG_CC))])]
6231 {
6232 operands[2] = avr_to_int_mode (operands[0]);
6233 })
6234
6235
6236 ;; "*lshrhi3_const"
6237 ;; "*lshrhq3_const" "*lshruhq3_const"
6238 ;; "*lshrha3_const" "*lshruha3_const"
6239 (define_insn "*lshr<mode>3_const"
6240 [(set (match_operand:ALL2 0 "register_operand" "=r ,r ,r ,r")
6241 (lshiftrt:ALL2 (match_operand:ALL2 1 "register_operand" "0 ,r ,r ,0")
6242 (match_operand:QI 2 "const_int_operand" "LPK,O C7c C15,C2r,n")))
6243 (clobber (match_scratch:QI 3 "=X ,X ,&d ,&d"))
6244 (clobber (reg:CC REG_CC))]
6245 "reload_completed"
6246 {
6247 return lshrhi3_out (insn, operands, NULL);
6248 }
6249 [(set_attr "isa" "*,*,3op,*")
6250 (set_attr "adjust_len" "lshrhi")])
6251
6252
6253 ;; "*lshrsi3_const"
6254 ;; "*lshrsq3_const" "*lshrusq3_const"
6255 ;; "*lshrsa3_const" "*lshrusa3_const"
6256 (define_insn "*lshr<mode>3_const"
6257 [(set (match_operand:ALL4 0 "register_operand" "=r ,r ,r ,r")
6258 (lshiftrt:ALL4 (match_operand:ALL4 1 "register_operand" "0 ,r ,r ,0")
6259 (match_operand:QI 2 "const_int_operand" "LP,O C4R,C4r,n")))
6260 (clobber (match_operand:QI 3 "scratch_or_dreg_operand" "=X ,X ,&d ,&d"))
6261 (clobber (reg:CC REG_CC))]
6262 "reload_completed"
6263 {
6264 return lshrsi3_out (insn, operands, NULL);
6265 }
6266 [(set_attr "isa" "*,*,3op,*")
6267 (set_attr "adjust_len" "lshrsi")])
6268
6269 ;; abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x)
6270 ;; abs
6271
6272 (define_insn_and_split "absqi2"
6273 [(set (match_operand:QI 0 "register_operand" "=r")
6274 (abs:QI (match_operand:QI 1 "register_operand" "0")))]
6275 ""
6276 "#"
6277 "&& reload_completed"
6278 [(parallel [(set (match_dup 0)
6279 (abs:QI (match_dup 1)))
6280 (clobber (reg:CC REG_CC))])])
6281
6282 (define_insn "*absqi2"
6283 [(set (match_operand:QI 0 "register_operand" "=r")
6284 (abs:QI (match_operand:QI 1 "register_operand" "0")))
6285 (clobber (reg:CC REG_CC))]
6286 "reload_completed"
6287 "sbrc %0,7
6288 neg %0"
6289 [(set_attr "length" "2")])
6290
6291
6292 (define_insn_and_split "abssf2"
6293 [(set (match_operand:SF 0 "register_operand" "=d,r")
6294 (abs:SF (match_operand:SF 1 "register_operand" "0,0")))]
6295 ""
6296 "#"
6297 "&& reload_completed"
6298 [(parallel [(set (match_dup 0)
6299 (abs:SF (match_dup 1)))
6300 (clobber (reg:CC REG_CC))])])
6301
6302 (define_insn "*abssf2"
6303 [(set (match_operand:SF 0 "register_operand" "=d,r")
6304 (abs:SF (match_operand:SF 1 "register_operand" "0,0")))
6305 (clobber (reg:CC REG_CC))]
6306 "reload_completed"
6307 "@
6308 andi %D0,0x7f
6309 clt\;bld %D0,7"
6310 [(set_attr "length" "1,2")])
6311
6312 ;; 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x
6313 ;; neg
6314
6315 (define_insn_and_split "negqi2"
6316 [(set (match_operand:QI 0 "register_operand" "=r")
6317 (neg:QI (match_operand:QI 1 "register_operand" "0")))]
6318 ""
6319 "#"
6320 "&& reload_completed"
6321 [(parallel [(set (match_dup 0)
6322 (neg:QI (match_dup 1)))
6323 (clobber (reg:CC REG_CC))])])
6324
6325 (define_insn "*negqi2"
6326 [(set (match_operand:QI 0 "register_operand" "=r")
6327 (neg:QI (match_operand:QI 1 "register_operand" "0")))
6328 (clobber (reg:CC REG_CC))]
6329 "reload_completed"
6330 "neg %0"
6331 [(set_attr "length" "1")])
6332
6333 (define_insn_and_split "*negqihi2_split"
6334 [(set (match_operand:HI 0 "register_operand" "=r")
6335 (neg:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "0"))))]
6336 ""
6337 "#"
6338 "&& reload_completed"
6339 [(parallel [(set (match_dup 0)
6340 (neg:HI (sign_extend:HI (match_dup 1))))
6341 (clobber (reg:CC REG_CC))])])
6342
6343 (define_insn "*negqihi2"
6344 [(set (match_operand:HI 0 "register_operand" "=r")
6345 (neg:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "0"))))
6346 (clobber (reg:CC REG_CC))]
6347 "reload_completed"
6348 "clr %B0\;neg %A0\;brge .+2\;com %B0"
6349 [(set_attr "length" "4")])
6350
6351 (define_insn_and_split "neghi2"
6352 [(set (match_operand:HI 0 "register_operand" "=r,&r")
6353 (neg:HI (match_operand:HI 1 "register_operand" "0,r")))]
6354 ""
6355 "#"
6356 "&& reload_completed"
6357 [(parallel [(set (match_dup 0)
6358 (neg:HI (match_dup 1)))
6359 (clobber (reg:CC REG_CC))])])
6360
6361 (define_insn "*neghi2"
6362 [(set (match_operand:HI 0 "register_operand" "=r,&r")
6363 (neg:HI (match_operand:HI 1 "register_operand" "0,r")))
6364 (clobber (reg:CC REG_CC))]
6365 "reload_completed"
6366 "@
6367 neg %B0\;neg %A0\;sbc %B0,__zero_reg__
6368 clr %A0\;clr %B0\;sub %A0,%A1\;sbc %B0,%B1"
6369 [(set_attr "length" "3,4")])
6370
6371 (define_insn_and_split "negpsi2"
6372 [(set (match_operand:PSI 0 "register_operand" "=!d,r,&r")
6373 (neg:PSI (match_operand:PSI 1 "register_operand" "0,0,r")))]
6374 ""
6375 "#"
6376 "&& reload_completed"
6377 [(parallel [(set (match_dup 0)
6378 (neg:PSI (match_dup 1)))
6379 (clobber (reg:CC REG_CC))])])
6380
6381 (define_insn "*negpsi2"
6382 [(set (match_operand:PSI 0 "register_operand" "=!d,r,&r")
6383 (neg:PSI (match_operand:PSI 1 "register_operand" "0,0,r")))
6384 (clobber (reg:CC REG_CC))]
6385 "reload_completed"
6386 "@
6387 com %C0\;com %B0\;neg %A0\;sbci %B0,-1\;sbci %C0,-1
6388 com %C0\;com %B0\;com %A0\;adc %A0,__zero_reg__\;adc %B0,__zero_reg__\;adc %C0,__zero_reg__
6389 clr %A0\;clr %B0\;clr %C0\;sub %A0,%A1\;sbc %B0,%B1\;sbc %C0,%C1"
6390 [(set_attr "length" "5,6,6")])
6391
6392 (define_insn_and_split "negsi2"
6393 [(set (match_operand:SI 0 "register_operand" "=!d,r,&r,&r")
6394 (neg:SI (match_operand:SI 1 "register_operand" "0,0,r ,r")))]
6395 ""
6396 "#"
6397 "&& reload_completed"
6398 [(parallel [(set (match_dup 0)
6399 (neg:SI (match_dup 1)))
6400 (clobber (reg:CC REG_CC))])]
6401 ""
6402 [(set_attr "isa" "*,*,mov,movw")])
6403
6404 (define_insn "*negsi2.libgcc"
6405 [(set (reg:SI REG_22)
6406 (neg:SI (reg:SI REG_22)))
6407 (clobber (reg:CC REG_CC))]
6408 "reload_completed
6409 && optimize_size"
6410 "%~call __negsi2"
6411 [(set_attr "type" "xcall")])
6412
6413 (define_insn "*negsi2"
6414 [(set (match_operand:SI 0 "register_operand" "=!d,r,&r,&r")
6415 (neg:SI (match_operand:SI 1 "register_operand" "0,0,r ,r")))
6416 (clobber (reg:CC REG_CC))]
6417 "reload_completed"
6418 "@
6419 com %D0\;com %C0\;com %B0\;neg %A0\;sbci %B0,lo8(-1)\;sbci %C0,lo8(-1)\;sbci %D0,lo8(-1)
6420 com %D0\;com %C0\;com %B0\;com %A0\;adc %A0,__zero_reg__\;adc %B0,__zero_reg__\;adc %C0,__zero_reg__\;adc %D0,__zero_reg__
6421 clr %A0\;clr %B0\;clr %C0\;clr %D0\;sub %A0,%A1\;sbc %B0,%B1\;sbc %C0,%C1\;sbc %D0,%D1
6422 clr %A0\;clr %B0\;movw %C0,%A0\;sub %A0,%A1\;sbc %B0,%B1\;sbc %C0,%C1\;sbc %D0,%D1"
6423 [(set_attr "length" "7,8,8,7")
6424 (set_attr "isa" "*,*,mov,movw")])
6425
6426 (define_insn_and_split "negsf2"
6427 [(set (match_operand:SF 0 "register_operand" "=d,r")
6428 (neg:SF (match_operand:SF 1 "register_operand" "0,0")))]
6429 ""
6430 "#"
6431 "&& reload_completed"
6432 [(parallel [(set (match_dup 0)
6433 (neg:SF (match_dup 1)))
6434 (clobber (reg:CC REG_CC))])])
6435
6436 (define_insn "*negsf2"
6437 [(set (match_operand:SF 0 "register_operand" "=d,r")
6438 (neg:SF (match_operand:SF 1 "register_operand" "0,0")))
6439 (clobber (reg:CC REG_CC))]
6440 "reload_completed"
6441 "@
6442 subi %D0,0x80
6443 bst %D0,7\;com %D0\;bld %D0,7\;com %D0"
6444 [(set_attr "length" "1,4")])
6445
6446 ;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6447 ;; not
6448
6449 (define_insn_and_split "one_cmplqi2"
6450 [(set (match_operand:QI 0 "register_operand" "=r")
6451 (not:QI (match_operand:QI 1 "register_operand" "0")))]
6452 ""
6453 "#"
6454 "&& reload_completed"
6455 [(parallel [(set (match_dup 0)
6456 (not:QI (match_dup 1)))
6457 (clobber (reg:CC REG_CC))])])
6458
6459 (define_insn "*one_cmplqi2"
6460 [(set (match_operand:QI 0 "register_operand" "=r")
6461 (not:QI (match_operand:QI 1 "register_operand" "0")))
6462 (clobber (reg:CC REG_CC))]
6463 "reload_completed"
6464 "com %0"
6465 [(set_attr "length" "1")])
6466
6467 (define_insn_and_split "one_cmplhi2"
6468 [(set (match_operand:HI 0 "register_operand" "=r")
6469 (not:HI (match_operand:HI 1 "register_operand" "0")))]
6470 ""
6471 "#"
6472 "&& reload_completed"
6473 [(parallel [(set (match_dup 0)
6474 (not:HI (match_dup 1)))
6475 (clobber (reg:CC REG_CC))])])
6476
6477 (define_insn "*one_cmplhi2"
6478 [(set (match_operand:HI 0 "register_operand" "=r")
6479 (not:HI (match_operand:HI 1 "register_operand" "0")))
6480 (clobber (reg:CC REG_CC))]
6481 "reload_completed"
6482 "com %0
6483 com %B0"
6484 [(set_attr "length" "2")])
6485
6486 (define_insn_and_split "one_cmplpsi2"
6487 [(set (match_operand:PSI 0 "register_operand" "=r")
6488 (not:PSI (match_operand:PSI 1 "register_operand" "0")))]
6489 ""
6490 "#"
6491 "&& reload_completed"
6492 [(parallel [(set (match_dup 0)
6493 (not:PSI (match_dup 1)))
6494 (clobber (reg:CC REG_CC))])])
6495
6496 (define_insn "*one_cmplpsi2"
6497 [(set (match_operand:PSI 0 "register_operand" "=r")
6498 (not:PSI (match_operand:PSI 1 "register_operand" "0")))
6499 (clobber (reg:CC REG_CC))]
6500 "reload_completed"
6501 "com %0\;com %B0\;com %C0"
6502 [(set_attr "length" "3")])
6503
6504 (define_insn_and_split "one_cmplsi2"
6505 [(set (match_operand:SI 0 "register_operand" "=r")
6506 (not:SI (match_operand:SI 1 "register_operand" "0")))]
6507 ""
6508 "#"
6509 "&& reload_completed"
6510 [(parallel [(set (match_dup 0)
6511 (not:SI (match_dup 1)))
6512 (clobber (reg:CC REG_CC))])])
6513
6514 (define_insn "*one_cmplsi2"
6515 [(set (match_operand:SI 0 "register_operand" "=r")
6516 (not:SI (match_operand:SI 1 "register_operand" "0")))
6517 (clobber (reg:CC REG_CC))]
6518 "reload_completed"
6519 "com %0
6520 com %B0
6521 com %C0
6522 com %D0"
6523 [(set_attr "length" "4")])
6524
6525 ;; xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x
6526 ;; sign extend
6527
6528 ;; We keep combiner from inserting hard registers into the input of sign- and
6529 ;; zero-extends. A hard register in the input operand is not wanted because
6530 ;; 32-bit multiply patterns clobber some hard registers and extends with a
6531 ;; hard register that overlaps these clobbers won't be combined to a widening
6532 ;; multiplication. There is no need for combine to propagate hard registers,
6533 ;; register allocation can do it just as well.
6534
6535 (define_insn_and_split "extendqihi2"
6536 [(set (match_operand:HI 0 "register_operand" "=r,r")
6537 (sign_extend:HI (match_operand:QI 1 "combine_pseudo_register_operand" "0,*r")))]
6538 ""
6539 "#"
6540 "&& reload_completed"
6541 [(parallel [(set (match_dup 0)
6542 (sign_extend:HI (match_dup 1)))
6543 (clobber (reg:CC REG_CC))])])
6544
6545 (define_insn "*extendqihi2"
6546 [(set (match_operand:HI 0 "register_operand" "=r,r")
6547 (sign_extend:HI (match_operand:QI 1 "combine_pseudo_register_operand" "0,*r")))
6548 (clobber (reg:CC REG_CC))]
6549 "reload_completed"
6550 {
6551 return avr_out_sign_extend (insn, operands, NULL);
6552 }
6553 [(set_attr "length" "3,4")
6554 (set_attr "adjust_len" "sext")])
6555
6556 (define_insn_and_split "extendqipsi2"
6557 [(set (match_operand:PSI 0 "register_operand" "=r,r")
6558 (sign_extend:PSI (match_operand:QI 1 "combine_pseudo_register_operand" "0,*r")))]
6559 ""
6560 "#"
6561 "&& reload_completed"
6562 [(parallel [(set (match_dup 0)
6563 (sign_extend:PSI (match_dup 1)))
6564 (clobber (reg:CC REG_CC))])])
6565
6566 (define_insn "*extendqipsi2"
6567 [(set (match_operand:PSI 0 "register_operand" "=r,r")
6568 (sign_extend:PSI (match_operand:QI 1 "combine_pseudo_register_operand" "0,*r")))
6569 (clobber (reg:CC REG_CC))]
6570 "reload_completed"
6571 {
6572 return avr_out_sign_extend (insn, operands, NULL);
6573 }
6574 [(set_attr "length" "4,5")
6575 (set_attr "adjust_len" "sext")])
6576
6577 (define_insn_and_split "extendqisi2"
6578 [(set (match_operand:SI 0 "register_operand" "=r,r")
6579 (sign_extend:SI (match_operand:QI 1 "combine_pseudo_register_operand" "0,*r")))]
6580 ""
6581 "#"
6582 "&& reload_completed"
6583 [(parallel [(set (match_dup 0)
6584 (sign_extend:SI (match_dup 1)))
6585 (clobber (reg:CC REG_CC))])])
6586
6587 (define_insn "*extendqisi2"
6588 [(set (match_operand:SI 0 "register_operand" "=r,r")
6589 (sign_extend:SI (match_operand:QI 1 "combine_pseudo_register_operand" "0,*r")))
6590 (clobber (reg:CC REG_CC))]
6591 "reload_completed"
6592 {
6593 return avr_out_sign_extend (insn, operands, NULL);
6594 }
6595 [(set_attr "length" "5,6")
6596 (set_attr "adjust_len" "sext")])
6597
6598 (define_insn_and_split "extendhipsi2"
6599 [(set (match_operand:PSI 0 "register_operand" "=r,r")
6600 (sign_extend:PSI (match_operand:HI 1 "combine_pseudo_register_operand" "0,*r")))]
6601 ""
6602 "#"
6603 "&& reload_completed"
6604 [(parallel [(set (match_dup 0)
6605 (sign_extend:PSI (match_dup 1)))
6606 (clobber (reg:CC REG_CC))])])
6607
6608 (define_insn "*extendhipsi2"
6609 [(set (match_operand:PSI 0 "register_operand" "=r,r")
6610 (sign_extend:PSI (match_operand:HI 1 "combine_pseudo_register_operand" "0,*r")))
6611 (clobber (reg:CC REG_CC))]
6612 "reload_completed"
6613 {
6614 return avr_out_sign_extend (insn, operands, NULL);
6615 }
6616 [(set_attr "length" "3,5")
6617 (set_attr "adjust_len" "sext")])
6618
6619 (define_insn_and_split "extendhisi2"
6620 [(set (match_operand:SI 0 "register_operand" "=r,r")
6621 (sign_extend:SI (match_operand:HI 1 "combine_pseudo_register_operand" "0,*r")))]
6622 ""
6623 "#"
6624 "&& reload_completed"
6625 [(parallel [(set (match_dup 0)
6626 (sign_extend:SI (match_dup 1)))
6627 (clobber (reg:CC REG_CC))])])
6628
6629 (define_insn "*extendhisi2"
6630 [(set (match_operand:SI 0 "register_operand" "=r,r")
6631 (sign_extend:SI (match_operand:HI 1 "combine_pseudo_register_operand" "0,*r")))
6632 (clobber (reg:CC REG_CC))]
6633 "reload_completed"
6634 {
6635 return avr_out_sign_extend (insn, operands, NULL);
6636 }
6637 [(set_attr "length" "4,6")
6638 (set_attr "adjust_len" "sext")])
6639
6640 (define_insn_and_split "extendpsisi2"
6641 [(set (match_operand:SI 0 "register_operand" "=r")
6642 (sign_extend:SI (match_operand:PSI 1 "combine_pseudo_register_operand" "0")))]
6643 ""
6644 "#"
6645 "&& reload_completed"
6646 [(parallel [(set (match_dup 0)
6647 (sign_extend:SI (match_dup 1)))
6648 (clobber (reg:CC REG_CC))])])
6649
6650 (define_insn "*extendpsisi2"
6651 [(set (match_operand:SI 0 "register_operand" "=r")
6652 (sign_extend:SI (match_operand:PSI 1 "combine_pseudo_register_operand" "0")))
6653 (clobber (reg:CC REG_CC))]
6654 "reload_completed"
6655 {
6656 return avr_out_sign_extend (insn, operands, NULL);
6657 }
6658 [(set_attr "length" "3")
6659 (set_attr "adjust_len" "sext")])
6660
6661 ;; xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x
6662 ;; zero extend
6663
6664 (define_insn_and_split "zero_extendqihi2"
6665 [(set (match_operand:HI 0 "register_operand" "=r")
6666 (zero_extend:HI (match_operand:QI 1 "combine_pseudo_register_operand" "r")))]
6667 ""
6668 "#"
6669 "reload_completed"
6670 [(set (match_dup 2) (match_dup 1))
6671 (set (match_dup 3) (const_int 0))]
6672 {
6673 unsigned int low_off = subreg_lowpart_offset (QImode, HImode);
6674 unsigned int high_off = subreg_highpart_offset (QImode, HImode);
6675
6676 operands[2] = simplify_gen_subreg (QImode, operands[0], HImode, low_off);
6677 operands[3] = simplify_gen_subreg (QImode, operands[0], HImode, high_off);
6678 })
6679
6680 (define_insn_and_split "zero_extendqipsi2"
6681 [(set (match_operand:PSI 0 "register_operand" "=r")
6682 (zero_extend:PSI (match_operand:QI 1 "combine_pseudo_register_operand" "r")))]
6683 ""
6684 "#"
6685 "reload_completed"
6686 [(set (match_dup 2) (match_dup 1))
6687 (set (match_dup 3) (const_int 0))
6688 (set (match_dup 4) (const_int 0))]
6689 {
6690 operands[2] = simplify_gen_subreg (QImode, operands[0], PSImode, 0);
6691 operands[3] = simplify_gen_subreg (QImode, operands[0], PSImode, 1);
6692 operands[4] = simplify_gen_subreg (QImode, operands[0], PSImode, 2);
6693 })
6694
6695 (define_insn_and_split "zero_extendqisi2"
6696 [(set (match_operand:SI 0 "register_operand" "=r")
6697 (zero_extend:SI (match_operand:QI 1 "combine_pseudo_register_operand" "r")))]
6698 ""
6699 "#"
6700 "reload_completed"
6701 [(set (match_dup 2) (zero_extend:HI (match_dup 1)))
6702 (set (match_dup 3) (const_int 0))]
6703 {
6704 unsigned int low_off = subreg_lowpart_offset (HImode, SImode);
6705 unsigned int high_off = subreg_highpart_offset (HImode, SImode);
6706
6707 operands[2] = simplify_gen_subreg (HImode, operands[0], SImode, low_off);
6708 operands[3] = simplify_gen_subreg (HImode, operands[0], SImode, high_off);
6709 })
6710
6711 (define_insn_and_split "zero_extendhipsi2"
6712 [(set (match_operand:PSI 0 "register_operand" "=r")
6713 (zero_extend:PSI (match_operand:HI 1 "combine_pseudo_register_operand" "r")))]
6714 ""
6715 "#"
6716 "reload_completed"
6717 [(set (match_dup 2) (match_dup 1))
6718 (set (match_dup 3) (const_int 0))]
6719 {
6720 operands[2] = simplify_gen_subreg (HImode, operands[0], PSImode, 0);
6721 operands[3] = simplify_gen_subreg (QImode, operands[0], PSImode, 2);
6722 })
6723
6724 (define_insn_and_split "n_extendhipsi2"
6725 [(set (match_operand:PSI 0 "register_operand" "=r,r,d,r")
6726 (lo_sum:PSI (match_operand:QI 1 "const_int_operand" "L,P,n,n")
6727 (match_operand:HI 2 "register_operand" "r,r,r,r")))
6728 (clobber (match_scratch:QI 3 "=X,X,X,&d"))]
6729 ""
6730 "#"
6731 "reload_completed"
6732 [(set (match_dup 4) (match_dup 2))
6733 (set (match_dup 3) (match_dup 6))
6734 ; no-op move in the case where no scratch is needed
6735 (set (match_dup 5) (match_dup 3))]
6736 {
6737 operands[4] = simplify_gen_subreg (HImode, operands[0], PSImode, 0);
6738 operands[5] = simplify_gen_subreg (QImode, operands[0], PSImode, 2);
6739 operands[6] = operands[1];
6740
6741 if (GET_CODE (operands[3]) == SCRATCH)
6742 operands[3] = operands[5];
6743 })
6744
6745 (define_insn_and_split "zero_extendhisi2"
6746 [(set (match_operand:SI 0 "register_operand" "=r")
6747 (zero_extend:SI (match_operand:HI 1 "combine_pseudo_register_operand" "r")))]
6748 ""
6749 "#"
6750 "reload_completed"
6751 [(set (match_dup 2) (match_dup 1))
6752 (set (match_dup 3) (const_int 0))]
6753 {
6754 unsigned int low_off = subreg_lowpart_offset (HImode, SImode);
6755 unsigned int high_off = subreg_highpart_offset (HImode, SImode);
6756
6757 operands[2] = simplify_gen_subreg (HImode, operands[0], SImode, low_off);
6758 operands[3] = simplify_gen_subreg (HImode, operands[0], SImode, high_off);
6759 })
6760
6761 (define_insn_and_split "zero_extendpsisi2"
6762 [(set (match_operand:SI 0 "register_operand" "=r")
6763 (zero_extend:SI (match_operand:PSI 1 "combine_pseudo_register_operand" "r")))]
6764 ""
6765 "#"
6766 "reload_completed"
6767 [(set (match_dup 2) (match_dup 1))
6768 (set (match_dup 3) (const_int 0))]
6769 {
6770 operands[2] = simplify_gen_subreg (PSImode, operands[0], SImode, 0);
6771 operands[3] = simplify_gen_subreg (QImode, operands[0], SImode, 3);
6772 })
6773
6774 (define_insn_and_split "zero_extendqidi2"
6775 [(set (match_operand:DI 0 "register_operand" "=r")
6776 (zero_extend:DI (match_operand:QI 1 "register_operand" "r")))]
6777 ""
6778 "#"
6779 "reload_completed"
6780 [(set (match_dup 2) (zero_extend:SI (match_dup 1)))
6781 (set (match_dup 3) (const_int 0))]
6782 {
6783 unsigned int low_off = subreg_lowpart_offset (SImode, DImode);
6784 unsigned int high_off = subreg_highpart_offset (SImode, DImode);
6785
6786 operands[2] = simplify_gen_subreg (SImode, operands[0], DImode, low_off);
6787 operands[3] = simplify_gen_subreg (SImode, operands[0], DImode, high_off);
6788 })
6789
6790 (define_insn_and_split "zero_extendhidi2"
6791 [(set (match_operand:DI 0 "register_operand" "=r")
6792 (zero_extend:DI (match_operand:HI 1 "register_operand" "r")))]
6793 ""
6794 "#"
6795 "reload_completed"
6796 [(set (match_dup 2) (zero_extend:SI (match_dup 1)))
6797 (set (match_dup 3) (const_int 0))]
6798 {
6799 unsigned int low_off = subreg_lowpart_offset (SImode, DImode);
6800 unsigned int high_off = subreg_highpart_offset (SImode, DImode);
6801
6802 operands[2] = simplify_gen_subreg (SImode, operands[0], DImode, low_off);
6803 operands[3] = simplify_gen_subreg (SImode, operands[0], DImode, high_off);
6804 })
6805
6806 (define_insn_and_split "zero_extendsidi2"
6807 [(set (match_operand:DI 0 "register_operand" "=r")
6808 (zero_extend:DI (match_operand:SI 1 "register_operand" "r")))]
6809 ""
6810 "#"
6811 "reload_completed"
6812 [(set (match_dup 2) (match_dup 1))
6813 (set (match_dup 3) (const_int 0))]
6814 {
6815 unsigned int low_off = subreg_lowpart_offset (SImode, DImode);
6816 unsigned int high_off = subreg_highpart_offset (SImode, DImode);
6817
6818 operands[2] = simplify_gen_subreg (SImode, operands[0], DImode, low_off);
6819 operands[3] = simplify_gen_subreg (SImode, operands[0], DImode, high_off);
6820 })
6821
6822 ;;<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>
6823 ;; compare
6824
6825 ;; "*swapped_tstqi" "*swapped_tstqq"
6826 (define_insn "*swapped_tst<mode>"
6827 [(set (reg:CC REG_CC)
6828 (compare:CC (match_operand:ALLs1 0 "const0_operand" "Y00")
6829 (match_operand:ALLs1 1 "register_operand" "r")))]
6830 "reload_completed"
6831 "cp __zero_reg__,%1"
6832 [(set_attr "length" "1")])
6833
6834
6835 ;; "*swapped_tsthi" "*swapped_tsthq" "*swapped_tstha"
6836 (define_insn "*swapped_tst<mode>"
6837 [(set (reg:CC REG_CC)
6838 (compare:CC (match_operand:ALLs2 0 "const0_operand" "Y00")
6839 (match_operand:ALLs2 1 "register_operand" "r")))]
6840 "reload_completed"
6841 "cp __zero_reg__,%A1
6842 cpc __zero_reg__,%B1"
6843 [(set_attr "length" "2")])
6844
6845
6846 (define_insn "*swapped_tstpsi"
6847 [(set (reg:CC REG_CC)
6848 (compare:CC (const_int 0)
6849 (match_operand:PSI 0 "register_operand" "r")))]
6850 "reload_completed"
6851 "cp __zero_reg__,%A0\;cpc __zero_reg__,%B0\;cpc __zero_reg__,%C0"
6852 [(set_attr "length" "3")])
6853
6854
6855 ;; "*swapped_tstsi" "*swapped_tstsq" "*swapped_tstsa"
6856 (define_insn "*swapped_tst<mode>"
6857 [(set (reg:CC REG_CC)
6858 (compare:CC (match_operand:ALLs4 0 "const0_operand" "Y00")
6859 (match_operand:ALLs4 1 "register_operand" "r")))]
6860 "reload_completed"
6861 "cp __zero_reg__,%A1
6862 cpc __zero_reg__,%B1
6863 cpc __zero_reg__,%C1
6864 cpc __zero_reg__,%D1"
6865 [(set_attr "length" "4")])
6866
6867
6868 ;; "cmpqi3"
6869 ;; "cmpqq3" "cmpuqq3"
6870 (define_insn "cmp<mode>3"
6871 [(set (reg:CC REG_CC)
6872 (compare:CC (match_operand:ALL1 0 "register_operand" "d,r ,r")
6873 (match_operand:ALL1 1 "nonmemory_operand" "i,Y00,r")))]
6874 "reload_completed"
6875 "@
6876 cpi %0,lo8(%1)
6877 cp %0,__zero_reg__
6878 cp %0,%1"
6879 [(set_attr "length" "1,1,1")])
6880
6881
6882 ;; May be generated by "*cbranch<HISI:mode>.<code><QIPSI:mode>.0/1".
6883 (define_insn "*cmp<HISI:mode>.<code><QIPSI:mode>.0"
6884 [(set (reg:CC REG_CC)
6885 (compare:CC (any_extend:HISI (match_operand:QIPSI 0 "register_operand" "r"))
6886 (match_operand:HISI 1 "register_operand" "r")))]
6887 "reload_completed
6888 && <HISI:SIZE> > <QIPSI:SIZE>"
6889 {
6890 return avr_out_cmp_ext (operands, <CODE>, nullptr);
6891 }
6892 [(set_attr "adjust_len" "cmp_<extend_su>ext")])
6893
6894 ;; Swapped version of the above.
6895 ;; May be generated by "*cbranch<HISI:mode>.<code><QIPSI:mode>.0/1".
6896 (define_insn "*cmp<HISI:mode>.<code><QIPSI:mode>.1"
6897 [(set (reg:CC REG_CC)
6898 (compare:CC (match_operand:HISI 0 "register_operand" "r")
6899 (any_extend:HISI (match_operand:QIPSI 1 "register_operand" "r"))))]
6900 "reload_completed
6901 && <HISI:SIZE> > <QIPSI:SIZE>"
6902 {
6903 return avr_out_cmp_ext (operands, <CODE>, nullptr);
6904 }
6905 [(set_attr "adjust_len" "cmp_<extend_su>ext")])
6906
6907
6908 ;; "cmphi3"
6909 ;; "cmphq3" "cmpuhq3"
6910 ;; "cmpha3" "cmpuha3"
6911 (define_insn "cmp<mode>3"
6912 [(set (reg:CC REG_CC)
6913 (compare:CC (match_operand:ALL2 0 "register_operand" "!w ,r ,r,d ,r ,d ,r")
6914 (match_operand:ALL2 1 "nonmemory_operand" "Y00,Y00,r,s ,s ,M YMM,n Ynn")))
6915 (clobber (match_scratch:QI 2 "=X ,X ,X,&d,&d,X ,&d"))]
6916 "reload_completed"
6917 {
6918 switch (which_alternative)
6919 {
6920 case 0:
6921 case 1:
6922 return avr_out_tsthi (insn, operands, NULL);
6923
6924 case 2:
6925 return "cp %A0,%A1\;cpc %B0,%B1";
6926
6927 case 3:
6928 if (<MODE>mode != HImode)
6929 break;
6930 return reg_unused_after (insn, operands[0])
6931 ? "subi %A0,lo8(%1)\;sbci %B0,hi8(%1)"
6932 : "ldi %2,hi8(%1)\;cpi %A0,lo8(%1)\;cpc %B0,%2";
6933
6934 case 4:
6935 if (<MODE>mode != HImode)
6936 break;
6937 return "ldi %2,lo8(%1)\;cp %A0,%2\;ldi %2,hi8(%1)\;cpc %B0,%2";
6938 }
6939
6940 return avr_out_compare (insn, operands, NULL);
6941 }
6942 [(set_attr "length" "2,2,2,3,4,2,4")
6943 (set_attr "isa" "adiw,*,*,*,*,*,*")
6944 (set_attr "adjust_len" "tsthi,tsthi,*,*,*,compare,compare")])
6945
6946 (define_insn "*cmppsi"
6947 [(set (reg:CC REG_CC)
6948 (compare:CC (match_operand:PSI 0 "register_operand" "r,r,d ,r ,d,r")
6949 (match_operand:PSI 1 "nonmemory_operand" "L,r,s ,s ,M,n")))
6950 (clobber (match_scratch:QI 2 "=X,X,&d,&d ,X,&d"))]
6951 "reload_completed"
6952 {
6953 switch (which_alternative)
6954 {
6955 case 0:
6956 return avr_out_tstpsi (insn, operands, NULL);
6957
6958 case 1:
6959 return "cp %A0,%A1\;cpc %B0,%B1\;cpc %C0,%C1";
6960
6961 case 2:
6962 return reg_unused_after (insn, operands[0])
6963 ? "subi %A0,lo8(%1)\;sbci %B0,hi8(%1)\;sbci %C0,hh8(%1)"
6964 : "cpi %A0,lo8(%1)\;ldi %2,hi8(%1)\;cpc %B0,%2\;ldi %2,hh8(%1)\;cpc %C0,%2";
6965
6966 case 3:
6967 return "ldi %2,lo8(%1)\;cp %A0,%2\;ldi %2,hi8(%1)\;cpc %B0,%2\;ldi %2,hh8(%1)\;cpc %C0,%2";
6968 }
6969
6970 return avr_out_compare (insn, operands, NULL);
6971 }
6972 [(set_attr "length" "3,3,5,6,3,7")
6973 (set_attr "adjust_len" "tstpsi,*,*,*,compare,compare")])
6974
6975 ;; "*cmpsi"
6976 ;; "*cmpsq" "*cmpusq"
6977 ;; "*cmpsa" "*cmpusa"
6978 (define_insn "*cmp<mode>"
6979 [(set (reg:CC REG_CC)
6980 (compare:CC (match_operand:ALL4 0 "register_operand" "r ,r ,d ,r")
6981 (match_operand:ALL4 1 "nonmemory_operand" "Y00,r ,M YMM,n Ynn")))
6982 (clobber (match_scratch:QI 2 "=X ,X ,X ,&d"))]
6983 "reload_completed"
6984 {
6985 if (0 == which_alternative)
6986 return avr_out_tstsi (insn, operands, NULL);
6987 else if (1 == which_alternative)
6988 return "cp %A0,%A1\;cpc %B0,%B1\;cpc %C0,%C1\;cpc %D0,%D1";
6989
6990 return avr_out_compare (insn, operands, NULL);
6991 }
6992 [(set_attr "length" "4,4,4,8")
6993 (set_attr "adjust_len" "tstsi,*,compare,compare")])
6994
6995
6996 ;; "*cmphi_lsr"
6997 ;; "*cmpsi_lsr"
6998 ;; "*cmppsi_lsr"
6999 (define_insn_and_split "*cmp<mode>_lsr"
7000 [(set (reg:CC REG_CC)
7001 (compare:CC (lshiftrt:HISI (match_operand:HISI 0 "register_operand" "r")
7002 (match_operand:QI 1 "const_8_16_24_operand" "n"))
7003 (const_int 0)))
7004 (clobber (scratch:QI))]
7005 "reload_completed"
7006 {
7007 return avr_out_cmp_lsr (insn, operands, NULL);
7008 }
7009 "&& 1"
7010 [;; "cmpqi3"
7011 (set (reg:CC REG_CC)
7012 (compare:CC (match_dup 0)
7013 (const_int 0)))]
7014 {
7015 // When the comparison is just one byte, then cmpqi3.
7016 if (INTVAL (operands[1]) / 8 == <SIZE> - 1)
7017 operands[0] = simplify_gen_subreg (QImode, operands[0], <MODE>mode, <SIZE> - 1);
7018 else
7019 FAIL;
7020 }
7021 [(set_attr "adjust_len" "cmp_lsr")])
7022
7023
7024 ;; A helper for avr_pass_ifelse::avr_rest_of_handle_ifelse().
7025 (define_expand "gen_compare<mode>"
7026 [(parallel [(set (reg:CC REG_CC)
7027 (compare:CC (match_operand:HISI 0 "register_operand")
7028 (match_operand:HISI 1 "const_int_operand")))
7029 (clobber (match_operand:QI 2 "scratch_operand"))])])
7030
7031 (define_expand "gen_move_clobbercc"
7032 [(parallel [(set (match_operand 0)
7033 (match_operand 1))
7034 (clobber (reg:CC REG_CC))])])
7035
7036 (define_expand "gen_move_clobbercc_scratch"
7037 [(parallel [(set (match_operand 0)
7038 (match_operand 1))
7039 (clobber (match_operand 2))
7040 (clobber (reg:CC REG_CC))])])
7041
7042 ;; ----------------------------------------------------------------------
7043 ;; JUMP INSTRUCTIONS
7044 ;; ----------------------------------------------------------------------
7045 ;; Conditional jump instructions
7046
7047 (define_expand "cbranch<mode>4"
7048 [(set (pc)
7049 (if_then_else (match_operator 0 "ordered_comparison_operator"
7050 [(match_operand:ALL1 1 "register_operand")
7051 (match_operand:ALL1 2 "nonmemory_operand")])
7052 (label_ref (match_operand 3))
7053 (pc)))]
7054 ""
7055 {
7056 int icode = (int) GET_CODE (operands[0]);
7057
7058 targetm.canonicalize_comparison (&icode, &operands[1], &operands[2], false);
7059 PUT_CODE (operands[0], (rtx_code) icode);
7060 })
7061
7062 (define_expand "cbranch<mode>4"
7063 [(parallel
7064 [(set (pc)
7065 (if_then_else (match_operator 0 "ordered_comparison_operator"
7066 [(match_operand:ALL234 1 "register_operand")
7067 (match_operand:ALL234 2 "nonmemory_operand")])
7068 (label_ref (match_operand 3))
7069 (pc)))
7070 (clobber (match_scratch:QI 4))])]
7071 ""
7072 {
7073 int icode = (int) GET_CODE (operands[0]);
7074
7075 targetm.canonicalize_comparison (&icode, &operands[1], &operands[2], false);
7076 PUT_CODE (operands[0], (rtx_code) icode);
7077 })
7078
7079
7080 ;; "cbranchqi4_insn"
7081 ;; "cbranchqq4_insn" "cbranchuqq4_insn"
7082 (define_insn_and_split "cbranch<mode>4_insn"
7083 [(set (pc)
7084 (if_then_else (match_operator 0 "ordered_comparison_operator"
7085 [(match_operand:ALL1 1 "register_operand" "r ,r,d")
7086 (match_operand:ALL1 2 "nonmemory_operand" "Y00,r,i")])
7087 (label_ref (match_operand 3))
7088 (pc)))]
7089 ""
7090 "#"
7091 "reload_completed"
7092 [(set (reg:CC REG_CC)
7093 (compare:CC (match_dup 1) (match_dup 2)))
7094 (set (pc)
7095 (if_then_else (match_op_dup 0
7096 [(reg:CC REG_CC) (const_int 0)])
7097 (label_ref (match_dup 3))
7098 (pc)))])
7099
7100 ;; "cbranchsi4_insn"
7101 ;; "cbranchsq4_insn" "cbranchusq4_insn" "cbranchsa4_insn" "cbranchusa4_insn"
7102 (define_insn_and_split "cbranch<mode>4_insn"
7103 [(set (pc)
7104 (if_then_else
7105 (match_operator 0 "ordered_comparison_operator"
7106 [(match_operand:ALL4 1 "register_operand" "r ,r,d ,r")
7107 (match_operand:ALL4 2 "nonmemory_operand" "Y00,r,M YMM ,n Ynn")])
7108 (label_ref (match_operand 3))
7109 (pc)))
7110 (clobber (match_scratch:QI 4 "=X ,X,X ,&d"))]
7111 ""
7112 "#"
7113 "reload_completed"
7114 [(parallel [(set (reg:CC REG_CC)
7115 (compare:CC (match_dup 1) (match_dup 2)))
7116 (clobber (match_dup 4))])
7117 (set (pc)
7118 (if_then_else (match_op_dup 0
7119 [(reg:CC REG_CC) (const_int 0)])
7120 (label_ref (match_dup 3))
7121 (pc)))]
7122 {
7123 // Unsigned >= 256^n and < 256^n can be performed by testing the
7124 // higher bytes against 0 (*cmpsi_lsr).
7125 avr_maybe_cmp_lsr (operands);
7126 })
7127
7128 ;; "cbranchpsi4_insn"
7129 (define_insn_and_split "cbranchpsi4_insn"
7130 [(set (pc)
7131 (if_then_else
7132 (match_operator 0 "ordered_comparison_operator"
7133 [(match_operand:PSI 1 "register_operand" "r,r,d ,r ,d,r")
7134 (match_operand:PSI 2 "nonmemory_operand" "L,r,s ,s ,M,n")])
7135 (label_ref (match_operand 3))
7136 (pc)))
7137 (clobber (match_scratch:QI 4 "=X,X,&d,&d,X,&d"))]
7138 ""
7139 "#"
7140 "reload_completed"
7141 [(parallel [(set (reg:CC REG_CC)
7142 (compare:CC (match_dup 1) (match_dup 2)))
7143 (clobber (match_dup 4))])
7144 (set (pc)
7145 (if_then_else (match_op_dup 0
7146 [(reg:CC REG_CC) (const_int 0)])
7147 (label_ref (match_dup 3))
7148 (pc)))]
7149 {
7150 // Unsigned >= 256^n and < 256^n can be performed by testing the
7151 // higher bytes against 0 (*cmppsi_lsr).
7152 avr_maybe_cmp_lsr (operands);
7153 })
7154
7155 ;; "cbranchhi4_insn"
7156 ;; "cbranchhq4_insn" "cbranchuhq4_insn" "cbranchha4_insn" "cbranchuha4_insn"
7157 (define_insn_and_split "cbranch<mode>4_insn"
7158 [(set (pc)
7159 (if_then_else
7160 (match_operator 0 "ordered_comparison_operator"
7161 [(match_operand:ALL2 1 "register_operand" "!w ,r ,r,d ,r ,d ,r")
7162 (match_operand:ALL2 2 "nonmemory_operand" "Y00,Y00,r,s ,s ,M YMM,n Ynn")])
7163 (label_ref (match_operand 3))
7164 (pc)))
7165 (clobber (match_scratch:QI 4 "=X ,X ,X,&d,&d,X ,&d"))]
7166 ""
7167 "#"
7168 "reload_completed"
7169 [(parallel [(set (reg:CC REG_CC)
7170 (compare:CC (match_dup 1) (match_dup 2)))
7171 (clobber (match_dup 4))])
7172 (set (pc)
7173 (if_then_else (match_op_dup 0
7174 [(reg:CC REG_CC) (const_int 0)])
7175 (label_ref (match_dup 3))
7176 (pc)))]
7177 {
7178 // Unsigned >= 256 and < 256 can be performed by testing the
7179 // high byte against 0 (*cmphi_lsr).
7180 avr_maybe_cmp_lsr (operands);
7181 })
7182
7183
7184 ;; Combiner pattern to compare sign- or zero-extended register against
7185 ;; a wider register, like comparing uint8_t against uint16_t.
7186 (define_insn_and_split "*cbranch<HISI:mode>.<code><QIPSI:mode>.0"
7187 [(set (pc)
7188 (if_then_else (match_operator 0 "ordered_comparison_operator"
7189 [(any_extend:HISI (match_operand:QIPSI 1 "register_operand" "r"))
7190 (match_operand:HISI 2 "register_operand" "r")])
7191 (label_ref (match_operand 3))
7192 (pc)))]
7193 "optimize
7194 && <HISI:SIZE> > <QIPSI:SIZE>"
7195 "#"
7196 "&& reload_completed"
7197 [; "*cmp<HISI:mode>.<code><QIPSI:mode>.0"
7198 (set (reg:CC REG_CC)
7199 (compare:CC (match_dup 1)
7200 (match_dup 2)))
7201 ; "branch"
7202 (set (pc)
7203 (if_then_else (match_op_dup 0 [(reg:CC REG_CC)
7204 (const_int 0)])
7205 (label_ref (match_dup 3))
7206 (pc)))]
7207 {
7208 operands[1] = gen_rtx_<CODE> (<HISI:MODE>mode, operands[1]);
7209 if (difficult_comparison_operator (operands[0], VOIDmode))
7210 {
7211 PUT_CODE (operands[0], swap_condition (GET_CODE (operands[0])));
7212 std::swap (operands[1], operands[2]);
7213 }
7214 })
7215
7216 ;; Same combiner pattern, but with swapped operands.
7217 (define_insn_and_split "*cbranch<HISI:mode>.<code><QIPSI:mode>.0"
7218 [(set (pc)
7219 (if_then_else (match_operator 0 "ordered_comparison_operator"
7220 [(match_operand:HISI 1 "register_operand" "r")
7221 (any_extend:HISI (match_operand:QIPSI 2 "register_operand" "r"))])
7222 (label_ref (match_operand 3))
7223 (pc)))]
7224 "optimize
7225 && <HISI:SIZE> > <QIPSI:SIZE>"
7226 "#"
7227 "&& reload_completed"
7228 [; "*cmp<HISI:mode>.<code><QIPSI:mode>.0"
7229 (set (reg:CC REG_CC)
7230 (compare:CC (match_dup 1)
7231 (match_dup 2)))
7232 ; "branch"
7233 (set (pc)
7234 (if_then_else (match_op_dup 0 [(reg:CC REG_CC)
7235 (const_int 0)])
7236 (label_ref (match_dup 3))
7237 (pc)))]
7238 {
7239 operands[2] = gen_rtx_<CODE> (<HISI:MODE>mode, operands[2]);
7240 if (difficult_comparison_operator (operands[0], VOIDmode))
7241 {
7242 PUT_CODE (operands[0], swap_condition (GET_CODE (operands[0])));
7243 std::swap (operands[1], operands[2]);
7244 }
7245 })
7246
7247
7248 ;; Try optimize decrement-and-branch. When we have an addition followed
7249 ;; by a comparison of the result against zero, we can output the addition
7250 ;; in such a way that SREG.N and SREG.Z are set according to the result.
7251 ;; The comparisons are split2 from their cbranch insns and before
7252 ;; peephole2 patterns like for swapped_tst and sbrx_branch have been applied.
7253
7254 ;; We do NOT use cmpelim / SELECT_CC_MODE because it has many shortcomings
7255 ;; and is by no means equipollent to the removed cc0 framework -- at least
7256 ;; with regard to the avr backend: Whether or not the result of a comparison
7257 ;; can be obtained as a byproduct of an operation might depend on the
7258 ;; availability of a scratch register: There are cases where we need a
7259 ;; scratch register to optimize away a comparison, and where the operation
7260 ;; without a comparison does not require a scratch. With the peep2 approach
7261 ;; below, we can get a scratch from the peep2 framework without increasing
7262 ;; the register pressure, whereas cmpelim doesn't offer such a feature.
7263 ;; When no scratch is available, then we just don't perform the optimizaton,
7264 ;; i.e. the comparison against 0 won't be optimized away, which is preferred
7265 ;; over increasing the register pressure -- in many cases without reason --
7266 ;; which might result in additional spills.
7267 ;; What we definitely do not want is to pop a scratch without need, and
7268 ;; in some arithmetic insn we won't know whether it might also be considered
7269 ;; for CCmode generation, at least not prior to register allocation:
7270 ;; CCmode only comes into existence after register allocation.
7271 ;; cmpelim has more shortcomings, for example some comparisons may not
7272 ;; be available, and it does not handle several of the forms supported below,
7273 ;; just to mention two. A solution for the former would be to return VOIDmode
7274 ;; in SELECT_CC_MODE, but cmpelim doesn't handle that. Anyway, it's pointless
7275 ;; to speculate about how other shortcomings could be fixed when the scratch
7276 ;; problem is unsoved in cmpelim.
7277 ;; Apart from that, compare-elim.cc lists some demands that are not
7278 ;; compatible with this bachend. For example, it assumes that when an insn
7279 ;; can set the condition code, it is always of the form compare:CCM, i.e.
7280 ;; all comparisons are supported. This is not the case for AVR, see the
7281 ;; peep2 conditions below. There is no way (at least not a documented one)
7282 ;; to express that in SELECT_CC_MODE.
7283 ;; Apart from that passes running before register allocation (and thus
7284 ;; before split2) have #ifdef SELECT_CC_MODE, and nowhere there is an
7285 ;; explanation on how to handle that.
7286 ;; Skipping cmpelim is accomplished by not defining TARGET_FLAGS_REGNUM.
7287
7288 ;; Note: reload1.cc::do_output_reload() does not support output reloads
7289 ;; for JUMP_INSNs, hence letting combine doing decrement-and-branch might
7290 ;; run into an ICE. Doing reloads by hand is too painful, hence, stick with
7291 ;; RTL peepholes for now.
7292
7293 (define_expand "gen_add_for_<code>_<mode>"
7294 [;; "*add.for.cczn.<mode>"
7295 (parallel [(set (reg:CCZN REG_CC)
7296 (compare:CCZN (plus:HISI (match_operand:HISI 0 "register_operand")
7297 (match_operand:HISI 1 "const_int_operand"))
7298 (const_int 0)))
7299 (set (match_dup 0)
7300 (plus:HISI (match_dup 0)
7301 (match_dup 1)))
7302 (clobber (match_operand:QI 3))])
7303 ;; "branch_ZN"
7304 (set (pc)
7305 (if_then_else (eqnegtle (reg:CCZN REG_CC)
7306 (const_int 0))
7307 (label_ref (match_dup 2))
7308 (pc)))])
7309
7310 (define_expand "gen_add_for_<code>_<mode>"
7311 [;; "*add.for.ccn.<mode>"
7312 (parallel [(set (reg:CCN REG_CC)
7313 (compare:CCN (plus:HISI (match_operand:HISI 0 "register_operand")
7314 (match_operand:HISI 1 "nonmemory_operand"))
7315 (const_int 0)))
7316 (set (match_dup 0)
7317 (plus:HISI (match_dup 0)
7318 (match_dup 1)))
7319 (clobber (match_operand:QI 3))])
7320 ;; "branch_N"
7321 (set (pc)
7322 (if_then_else (gelt (reg:CCN REG_CC)
7323 (const_int 0))
7324 (label_ref (match_dup 2))
7325 (pc)))])
7326
7327
7328 ;; 1/3: Additions without a scratch register.
7329 (define_peephole2
7330 [(parallel [(set (match_operand:HISI 0 "register_operand")
7331 (plus:HISI (match_dup 0)
7332 (match_operand:HISI 1 "nonmemory_operand")))
7333 (clobber (reg:CC REG_CC))])
7334 (parallel [(set (reg:CC REG_CC)
7335 (compare:CC (match_dup 0)
7336 (match_operand:HISI 3 "const0_operand")))
7337 (clobber (scratch:QI))])
7338 (set (pc)
7339 (if_then_else (cmp_signed (reg:CC REG_CC)
7340 (const_int 0))
7341 (label_ref (match_operand 2))
7342 (pc)))]
7343 "// Multi-byte reg-reg additions only set the N flag.
7344 (<CODE> == GE || <CODE> == LT || ! REG_P (operands[1]))
7345 // Needs a const or a d-reg.
7346 && (REG_P (operands[1]) || d_register_operand (operands[0], <MODE>mode))
7347 && peep2_regno_dead_p (3, REG_CC)"
7348 [(scratch)]
7349 {
7350 emit (gen_gen_add_for_<code>_<mode> (operands[0], operands[1], operands[2],
7351 gen_rtx_SCRATCH (QImode)));
7352 DONE;
7353 })
7354
7355 ;; 2/3: Additions with a scratch register from the insn.
7356 (define_peephole2
7357 [(parallel [(set (match_operand:HISI 0 "register_operand")
7358 (plus:HISI (match_dup 0)
7359 (match_operand:HISI 1 "nonmemory_operand")))
7360 (clobber (match_operand:QI 3 "scratch_or_dreg_operand"))
7361 (clobber (reg:CC REG_CC))])
7362 (parallel [(set (reg:CC REG_CC)
7363 (compare:CC (match_dup 0)
7364 (match_operand:HISI 4 "const0_operand")))
7365 (clobber (scratch:QI))])
7366 (set (pc)
7367 (if_then_else (cmp_signed (reg:CC REG_CC)
7368 (const_int 0))
7369 (label_ref (match_operand 2))
7370 (pc)))]
7371 "// Multi-byte reg-reg additions only set the N flag.
7372 (<CODE> == GE || <CODE> == LT || ! REG_P (operands[1]))
7373 && peep2_regno_dead_p (3, REG_CC)"
7374 [(scratch)]
7375 {
7376 rtx scratch = operands[3];
7377
7378 // We need either a d-register or a scratch register
7379 // when $1 is not a register.
7380 if (! REG_P (operands[1])
7381 && ! REG_P (scratch)
7382 && ! d_register_operand (operands[0], <MODE>mode))
7383 FAIL;
7384
7385 emit (gen_gen_add_for_<code>_<mode> (operands[0], operands[1], operands[2],
7386 scratch));
7387 DONE;
7388 })
7389
7390 ;; 3/3: Additions with a scratch register from peephole2.
7391 (define_peephole2
7392 [(match_scratch:QI 3 "d")
7393 (parallel [(set (match_operand:HISI 0 "register_operand")
7394 (plus:HISI (match_dup 0)
7395 (match_operand:HISI 1 "const_int_operand")))
7396 (clobber (reg:CC REG_CC))])
7397 (parallel [(set (reg:CC REG_CC)
7398 (compare:CC (match_dup 0)
7399 (match_operand:HISI 4 "const0_operand")))
7400 (clobber (scratch:QI))])
7401 (set (pc)
7402 (if_then_else (cmp_signed (reg:CC REG_CC)
7403 (const_int 0))
7404 (label_ref (match_operand 2))
7405 (pc)))]
7406 "peep2_regno_dead_p (3, REG_CC)"
7407 [(scratch)]
7408 {
7409 emit (gen_gen_add_for_<code>_<mode> (operands[0], operands[1], operands[2],
7410 operands[3]));
7411 DONE;
7412 })
7413
7414 ;; Result of the above three peepholes is an addition that also
7415 ;; performs a signed comparison (of the result) against zero.
7416 ;; FIXME: Using (match_dup 0) instead of operands[3/4] makes rnregs
7417 ;; barf in regrename.cc::merge_overlapping_regs(). For now, use the
7418 ;; fix from PR50788: Constrain as "0".
7419
7420 ;; "*add.for.cczn.hi" "*add.for.cczn.psi" "*add.for.cczn.si"
7421 (define_insn "*add.for.cczn.<mode>"
7422 [(set (reg:CCZN REG_CC)
7423 (compare:CCZN
7424 (plus:HISI (match_operand:HISI 3 "register_operand" "0 ,0")
7425 (match_operand:HISI 1 "const_int_operand" "n ,n"))
7426 (const_int 0)))
7427 (set (match_operand:HISI 0 "register_operand" "=d ,r")
7428 (plus:HISI (match_operand:HISI 4 "register_operand" "0 ,0")
7429 (match_operand:HISI 5 "const_int_operand" "1 ,1")))
7430 (clobber (match_scratch:QI 2 "=X ,&d"))]
7431 "reload_completed"
7432 {
7433 return avr_out_plus_set_ZN (operands, nullptr);
7434 }
7435 [(set (attr "length")
7436 (symbol_ref "<SIZE> * (1 + REG_P (operands[2]))"))
7437 (set_attr "adjust_len" "add_set_ZN")])
7438
7439 ;; "*add.for.ccn.hi" "*add.for.ccn.psi" "*add.for.ccn.si"
7440 (define_insn "*add.for.ccn.<mode>"
7441 [(set (reg:CCN REG_CC)
7442 (compare:CCN
7443 (plus:HISI (match_operand:HISI 3 "register_operand" "0 ,0 ,0")
7444 (match_operand:HISI 1 "nonmemory_operand" "n ,n ,r"))
7445 (const_int 0)))
7446 (set (match_operand:HISI 0 "register_operand" "=d ,r ,r")
7447 (plus:HISI (match_operand:HISI 4 "register_operand" "0 ,0 ,0")
7448 (match_operand:HISI 5 "nonmemory_operand" "1 ,1 ,1")))
7449 (clobber (match_scratch:QI 2 "=X ,&d,X"))]
7450 "reload_completed"
7451 {
7452 return avr_out_plus_set_N (operands, nullptr);
7453 }
7454 [(set (attr "length")
7455 (symbol_ref "<SIZE> * (1 + REG_P (operands[2]))"))
7456 (set_attr "adjust_len" "add_set_N")])
7457
7458
7459 ;; 1/3: Subtractions with REG subtrahend set Z and N in a meaningful way.
7460 ;; The QI and PSI cases are handled below because they don't have a scratch:QI.
7461 (define_peephole2
7462 [(parallel [(set (match_operand:HI_SI 0 "register_operand")
7463 (minus:HI_SI (match_dup 0)
7464 (match_operand:HI_SI 1 "register_operand")))
7465 (clobber (scratch:QI))
7466 (clobber (reg:CC REG_CC))])
7467 (parallel [(set (reg:CC REG_CC)
7468 (compare:CC (match_dup 0)
7469 (match_operand:HI_SI 3 "const0_operand")))
7470 (clobber (scratch:QI))])
7471 (set (pc)
7472 (if_then_else (cmp_signed (reg:CC REG_CC)
7473 (const_int 0))
7474 (label_ref (match_operand 2))
7475 (pc)))]
7476 "peep2_regno_dead_p (3, REG_CC)"
7477 [;; "*sub.for.cczn.<mode>"
7478 (parallel [(set (reg:CCZN REG_CC)
7479 (compare:CCZN (minus:HI_SI (match_dup 0)
7480 (match_dup 1))
7481 (const_int 0)))
7482 (set (match_dup 0)
7483 (minus:HI_SI (match_dup 0)
7484 (match_dup 1)))])
7485 ;; "branch_ZN"
7486 (set (pc)
7487 (if_then_else (cmp_signed (reg:CCZN REG_CC)
7488 (const_int 0))
7489 (label_ref (match_dup 2))
7490 (pc)))])
7491
7492 ;; 2/3: Subtractions with a PSImode REG: no scratch:QI.
7493 (define_peephole2
7494 [(parallel [(set (match_operand:PSI 0 "register_operand")
7495 (minus:PSI (match_dup 0)
7496 (match_operand:PSI 1 "register_operand")))
7497 (clobber (reg:CC REG_CC))])
7498 (parallel [(set (reg:CC REG_CC)
7499 (compare:CC (match_dup 0)
7500 (match_operand:PSI 3 "const0_operand")))
7501 (clobber (scratch:QI))])
7502 (set (pc)
7503 (if_then_else (cmp_signed (reg:CC REG_CC)
7504 (const_int 0))
7505 (label_ref (match_operand 2))
7506 (pc)))]
7507 "peep2_regno_dead_p (3, REG_CC)"
7508 [;; "*sub.for.cczn.psi"
7509 (parallel [(set (reg:CCZN REG_CC)
7510 (compare:CCZN (minus:PSI (match_dup 0)
7511 (match_dup 1))
7512 (const_int 0)))
7513 (set (match_dup 0)
7514 (minus:PSI (match_dup 0)
7515 (match_dup 1)))])
7516 ;; "branch_ZN"
7517 (set (pc)
7518 (if_then_else (cmp_signed (reg:CCZN REG_CC)
7519 (const_int 0))
7520 (label_ref (match_dup 2))
7521 (pc)))])
7522
7523 ;; 3/3: Subtractions that extend the subtrahend.
7524 (define_peephole2
7525 [(parallel [(set (match_operand:HISI 0 "register_operand")
7526 (minus:HISI (match_dup 0)
7527 (any_extend:HISI (match_operand:QIPSI 1 "register_operand"))))
7528 (clobber (reg:CC REG_CC))])
7529 (parallel [(set (reg:CC REG_CC)
7530 (compare:CC (match_dup 0)
7531 (match_operand:HISI 3 "const0_operand")))
7532 (clobber (scratch:QI))])
7533 (set (pc)
7534 (if_then_else (cmp_signed (reg:CC REG_CC)
7535 (const_int 0))
7536 (label_ref (match_operand 2))
7537 (pc)))]
7538 "<HISI:SIZE> > <QIPSI:SIZE>
7539 && peep2_regno_dead_p (3, REG_CC)"
7540 [;; "*sub-extend<QIPSI:mode>.for.cczn.<HISI:mode>"
7541 (parallel [(set (reg:CCZN REG_CC)
7542 (compare:CCZN (minus:HISI (match_dup 0)
7543 (any_extend:HISI (match_dup 1)))
7544 (const_int 0)))
7545 (set (match_dup 0)
7546 (minus:HISI (match_dup 0)
7547 (any_extend:HISI (match_dup 1))))])
7548 ;; "branch_ZN"
7549 (set (pc)
7550 (if_then_else (cmp_signed (reg:CCZN REG_CC)
7551 (const_int 0))
7552 (label_ref (match_dup 2))
7553 (pc)))])
7554
7555 ;; "*sub.for.cczn.hi"
7556 ;; "*sub.for.cczn.psi"
7557 ;; "*sub.for.cczn.si"
7558 (define_insn "*sub.for.cczn.<mode>"
7559 [(set (reg:CCZN REG_CC)
7560 (compare:CCZN (minus:HISI (match_operand:HISI 3 "register_operand" "1")
7561 (match_operand:HISI 4 "register_operand" "2"))
7562 (const_int 0)))
7563 (set (match_operand:HISI 0 "register_operand" "=r")
7564 (minus:HISI (match_operand:HISI 1 "register_operand" "0")
7565 (match_operand:HISI 2 "register_operand" "r")))]
7566 "reload_completed"
7567 {
7568 return avr_out_plus_ext (insn, operands, nullptr);
7569 }
7570 [(set_attr "length" "<SIZE>")])
7571
7572
7573 (define_insn "*sub-extend<QIPSI:mode>.for.cczn.<HISI:mode>"
7574 [(set (reg:CCZN REG_CC)
7575 (compare:CCZN (minus:HISI (match_operand:HISI 3 "register_operand" "0")
7576 (any_extend:HISI
7577 (match_operand:QIPSI 4 "register_operand" "2")))
7578 (const_int 0)))
7579 (set (match_operand:HISI 0 "register_operand" "=r")
7580 (minus:HISI (match_operand:HISI 1 "register_operand" "0")
7581 (any_extend:HISI (match_operand:QIPSI 2 "register_operand" "r"))))]
7582 "reload_completed
7583 && <HISI:SIZE> > <QIPSI:SIZE>"
7584 {
7585 return avr_out_plus_ext (insn, operands, nullptr);
7586 }
7587 [(set (attr "length")
7588 (symbol_ref "<HISI:SIZE> + 3 * (<CODE> == SIGN_EXTEND)"))])
7589
7590
7591 ;; Operations other that PLUS can set the condition code in
7592 ;; a meaningful way, too.
7593
7594 ;; 1/1 Left shift sets the N bit.
7595 (define_peephole2
7596 [(parallel [(set (match_operand:HISI 0 "register_operand")
7597 (ashift:HISI (match_dup 0)
7598 (const_int 1)))
7599 (clobber (match_operand:QI 3 "scratch_operand"))
7600 (clobber (reg:CC REG_CC))])
7601 (parallel [(set (reg:CC REG_CC)
7602 (compare:CC (match_dup 0)
7603 (const_int 0)))
7604 (clobber (scratch:QI))])
7605 (set (pc)
7606 (if_then_else (gelt (reg:CC REG_CC)
7607 (const_int 0))
7608 (label_ref (match_operand 2))
7609 (pc)))]
7610 "peep2_regno_dead_p (3, REG_CC)"
7611 [;; "*ashift.for.ccn.<mode>"
7612 (parallel [(set (reg:CCN REG_CC)
7613 (compare:CCN (ashift:HISI (match_dup 0)
7614 (const_int 1))
7615 (const_int 0)))
7616 (set (match_dup 0)
7617 (ashift:HISI (match_dup 0)
7618 (const_int 1)))])
7619 ;; "branch_N"
7620 (set (pc)
7621 (if_then_else (gelt (reg:CCN REG_CC)
7622 (const_int 0))
7623 (label_ref (match_operand 2))
7624 (pc)))])
7625
7626 (define_insn "*ashift.for.ccn.<mode>"
7627 [(set (reg:CCN REG_CC)
7628 (compare:CCN (ashift:HISI (match_operand:HISI 2 "register_operand" "0")
7629 (const_int 1))
7630 (const_int 0)))
7631 (set (match_operand:HISI 0 "register_operand" "=r")
7632 (ashift:HISI (match_operand:HISI 1 "register_operand" "0")
7633 (const_int 1)))]
7634 "reload_completed"
7635 {
7636 output_asm_insn ("lsl %A0", operands);
7637 output_asm_insn ("rol %B0", operands);
7638 if (<SIZE> >= 3) output_asm_insn ("rol %C0", operands);
7639 if (<SIZE> >= 4) output_asm_insn ("rol %D0", operands);
7640 return "";
7641 }
7642 [(set_attr "length" "<SIZE>")])
7643
7644
7645 ;; 1/1 QImode operations that set Z and N in a meaningful way.
7646 (define_peephole2
7647 [(parallel [(set (match_operand:QI 0 "register_operand")
7648 (match_operator:QI 2 "op8_ZN_operator" [(match_dup 0)
7649 (match_operand:QI 1)]))
7650 (clobber (reg:CC REG_CC))])
7651 (set (reg:CC REG_CC)
7652 (compare:CC (match_dup 0)
7653 (match_operand:QI 4 "const0_operand")))
7654 (set (pc)
7655 (if_then_else (cmp_signed (reg:CC REG_CC)
7656 (const_int 0))
7657 (label_ref (match_operand 3))
7658 (pc)))]
7659 "peep2_regno_dead_p (3, REG_CC)"
7660 [;; "*op8.for.cczn.<code>"
7661 (parallel [(set (reg:CCZN REG_CC)
7662 (compare:CCZN (match_op_dup 2 [(match_dup 0)
7663 (match_dup 1)])
7664 (const_int 0)))
7665 (set (match_dup 0)
7666 (match_op_dup 2 [(match_dup 0)
7667 (match_dup 1)]))])
7668 ;; "branch_ZN"
7669 (set (pc)
7670 (if_then_else (cmp_signed (reg:CCZN REG_CC)
7671 (const_int 0))
7672 (label_ref (match_operand 3))
7673 (pc)))])
7674
7675 ;; Constraints and predicate for the insn below. This is what op8_ZN_operator
7676 ;; allows. Constraints are written in such a way that all cases have two
7677 ;; alternatives (shifts, XOR and MINUS have effectively just one alternative).
7678 ;; Note again that due to nregs, match_dup's won't work.
7679 (define_code_attr c0_op8
7680 [(xor "r,r") (minus "r,r") (ashift "r,r") (ashiftrt "r,r") (lshiftrt "r,r")
7681 (and "d,r") (ior "d,r") (plus "d,r")])
7682
7683 (define_code_attr c2_op8
7684 [(xor "r,r") (minus "r,r") (and "n,r") (ior "n,r") (plus "n,r P N K Cm2")
7685 (ashift "P K,C03") (ashiftrt "P K,C03") (lshiftrt "P K,C03")])
7686
7687 (define_code_attr p2_op8
7688 [(ashift "const_1_to_3") (ashiftrt "const_1_to_3") (lshiftrt "const_1_to_3")
7689 (xor "register") (minus "register")
7690 (plus "nonmemory") (and "nonmemory") (ior "nonmemory")])
7691
7692 ;; Result of the peephole2 above: An 8-bit operation that sets Z and N.
7693 ;; The allowed operations are: PLUS, MINUS, AND, IOR, XOR and SHIFTs
7694 ;; with operands according to op8_ZN_operator.
7695 (define_insn "*op8.for.cczn.<code>"
7696 [(set (reg:CCZN REG_CC)
7697 (compare:CCZN (op8_ZN:QI (match_operand:QI 3 "register_operand" "0,0")
7698 (match_operand:QI 4 "<p2_op8>_operand" "2,2"))
7699 (const_int 0)))
7700 (set (match_operand:QI 0 "register_operand" "=<c0_op8>")
7701 (op8_ZN:QI (match_operand:QI 1 "register_operand" "0,0")
7702 (match_operand:QI 2 "<p2_op8>_operand" "<c2_op8>")))]
7703 "reload_completed"
7704 {
7705 return avr_out_op8_set_ZN (<CODE>, operands, nullptr);
7706 }
7707 [(set (attr "length")
7708 (symbol_ref "avr_len_op8_set_ZN (<CODE>, operands)"))])
7709
7710
7711 ;; Test a single bit in a QI/HI/SImode register.
7712 ;; Combine will create zero-extract patterns for single-bit tests.
7713 ;; Permit any mode in source pattern by using VOIDmode.
7714
7715 (define_insn_and_split "sbrx_branch<mode>_split"
7716 [(set (pc)
7717 (if_then_else
7718 (match_operator 0 "eqne_operator"
7719 [(zero_extract:QIDI
7720 (match_operand:VOID 1 "register_operand" "r")
7721 (const_int 1)
7722 (match_operand 2 "const_int_operand" "n"))
7723 (const_int 0)])
7724 (label_ref (match_operand 3 "" ""))
7725 (pc)))]
7726 ""
7727 "#"
7728 "&& reload_completed"
7729 [(parallel [(set (pc)
7730 (if_then_else
7731 (match_op_dup 0
7732 [(zero_extract:QIDI
7733 (match_dup 1)
7734 (const_int 1)
7735 (match_dup 2))
7736 (const_int 0)])
7737 (label_ref (match_dup 3))
7738 (pc)))
7739 (clobber (reg:CC REG_CC))])])
7740
7741 (define_insn "*sbrx_branch<mode>"
7742 [(set (pc)
7743 (if_then_else
7744 (match_operator 0 "eqne_operator"
7745 [(zero_extract:QIDI
7746 (match_operand:VOID 1 "register_operand" "r")
7747 (const_int 1)
7748 (match_operand 2 "const_int_operand" "n"))
7749 (const_int 0)])
7750 (label_ref (match_operand 3 "" ""))
7751 (pc)))
7752 (clobber (reg:CC REG_CC))]
7753 "reload_completed"
7754 {
7755 return avr_out_sbxx_branch (insn, operands);
7756 }
7757 [(set (attr "length")
7758 (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
7759 (le (minus (pc) (match_dup 3)) (const_int 2046)))
7760 (const_int 2)
7761 (if_then_else (match_test "!AVR_HAVE_JMP_CALL")
7762 (const_int 2)
7763 (const_int 4))))])
7764
7765 ;; Same test based on bitwise AND. Keep this in case gcc changes patterns
7766 ;; or for text peepholes.
7767 ;; Fixme - bitwise Mask will not work for DImode
7768
7769 (define_insn_and_split "*sbrx_and_branch<mode>_split"
7770 [(set (pc)
7771 (if_then_else
7772 (match_operator 0 "eqne_operator"
7773 [(and:QISI
7774 (match_operand:QISI 1 "register_operand" "r")
7775 (match_operand:QISI 2 "single_one_operand" "n"))
7776 (const_int 0)])
7777 (label_ref (match_operand 3 "" ""))
7778 (pc)))]
7779 ""
7780 "#"
7781 "&& reload_completed"
7782 [(parallel [(set (pc)
7783 (if_then_else (match_op_dup 0 [(and:QISI (match_dup 1)
7784 (match_dup 2))
7785 (const_int 0)])
7786 (label_ref (match_dup 3))
7787 (pc)))
7788 (clobber (reg:CC REG_CC))])])
7789
7790 (define_insn "*sbrx_and_branch<mode>"
7791 [(set (pc)
7792 (if_then_else
7793 (match_operator 0 "eqne_operator"
7794 [(and:QISI
7795 (match_operand:QISI 1 "register_operand" "r")
7796 (match_operand:QISI 2 "single_one_operand" "n"))
7797 (const_int 0)])
7798 (label_ref (match_operand 3 "" ""))
7799 (pc)))
7800 (clobber (reg:CC REG_CC))]
7801 "reload_completed"
7802 {
7803 HOST_WIDE_INT bitnumber;
7804 bitnumber = exact_log2 (GET_MODE_MASK (<MODE>mode) & INTVAL (operands[2]));
7805 operands[2] = GEN_INT (bitnumber);
7806 return avr_out_sbxx_branch (insn, operands);
7807 }
7808 [(set (attr "length")
7809 (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
7810 (le (minus (pc) (match_dup 3)) (const_int 2046)))
7811 (const_int 2)
7812 (if_then_else (match_test "!AVR_HAVE_JMP_CALL")
7813 (const_int 2)
7814 (const_int 4))))])
7815
7816
7817 ;; Convert sign tests to bit 7 tests that match the above insns.
7818 (define_peephole2 ; "*sbrx_branch<mode>"
7819 [(set (reg:CC REG_CC)
7820 (compare:CC (match_operand:ALLs1 0 "register_operand")
7821 (match_operand:ALLs1 1 "const0_operand")))
7822 (set (pc)
7823 (if_then_else (gelt (reg:CC REG_CC)
7824 (const_int 0))
7825 (label_ref (match_operand 2))
7826 (pc)))]
7827 "peep2_regno_dead_p (2, REG_CC)"
7828 [(parallel [(set (pc)
7829 (if_then_else (<gelt_eqne> (zero_extract:HI (match_dup 0)
7830 (const_int 1)
7831 (match_dup 1))
7832 (const_int 0))
7833 (label_ref (match_dup 2))
7834 (pc)))
7835 (clobber (reg:CC REG_CC))])]
7836 {
7837 operands[0] = avr_to_int_mode (operands[0]);
7838 operands[1] = GEN_INT (<MSB>);
7839 })
7840
7841 ;; Convert sign tests to bit 15/23/31 tests that match the above insns.
7842 (define_peephole2 ; "*sbrx_branch<mode>"
7843 [(parallel [(set (reg:CC REG_CC)
7844 (compare:CC (match_operand:ALLs234 0 "register_operand")
7845 (match_operand:ALLs234 1 "const0_operand")))
7846 (clobber (match_operand:QI 3 "scratch_operand"))])
7847 (set (pc)
7848 (if_then_else (gelt (reg:CC REG_CC)
7849 (const_int 0))
7850 (label_ref (match_operand 2))
7851 (pc)))]
7852 "peep2_regno_dead_p (2, REG_CC)"
7853 [(parallel [(set (pc)
7854 (if_then_else (<gelt_eqne> (zero_extract:HI (match_dup 0)
7855 (const_int 1)
7856 (match_dup 1))
7857 (const_int 0))
7858 (label_ref (match_dup 2))
7859 (pc)))
7860 (clobber (reg:CC REG_CC))])]
7861 {
7862 operands[0] = avr_to_int_mode (operands[0]);
7863 operands[1] = GEN_INT (<MSB>);
7864 })
7865
7866
7867 ;; ************************************************************************
7868 ;; Implementation of conditional jumps here.
7869 ;; Compare with 0 (test) jumps
7870 ;; ************************************************************************
7871
7872 ;; "branch"
7873 ;; "branch_N"
7874 ;; "branch_ZN"
7875 (define_insn "branch<CCname>"
7876 [(set (pc)
7877 (if_then_else (match_operator 1 "ordered_comparison_operator"
7878 [(reg:ALLCC REG_CC)
7879 (const_int 0)])
7880 (label_ref (match_operand 0))
7881 (pc)))]
7882 "reload_completed"
7883 {
7884 return avr_cond_branch (insn, operands);
7885 }
7886 [(set (attr "type")
7887 (if_then_else
7888 (match_test "simple_comparison_operator (operands[1], VOIDmode)")
7889 (const_string "branch")
7890 (const_string "branch1")))])
7891
7892
7893 ;; **************************************************************************
7894 ;; Unconditional and other jump instructions.
7895
7896 (define_insn "jump"
7897 [(set (pc)
7898 (label_ref (match_operand 0 "" "")))]
7899 ""
7900 {
7901 return AVR_HAVE_JMP_CALL && get_attr_length (insn) != 1
7902 ? "jmp %x0"
7903 : "rjmp %x0";
7904 }
7905 [(set (attr "length")
7906 (if_then_else (match_operand 0 "symbol_ref_operand" "")
7907 (if_then_else (match_test "!AVR_HAVE_JMP_CALL")
7908 (const_int 1)
7909 (const_int 2))
7910 (if_then_else (and (ge (minus (pc) (match_dup 0)) (const_int -2047))
7911 (le (minus (pc) (match_dup 0)) (const_int 2047)))
7912 (const_int 1)
7913 (const_int 2))))])
7914
7915 ;; call
7916
7917 ;; Operand 1 not used on the AVR.
7918 ;; Operand 2 is 1 for tail-call, 0 otherwise.
7919 (define_expand "call"
7920 [(parallel[(call (match_operand:HI 0 "call_insn_operand" "")
7921 (match_operand:HI 1 "general_operand" ""))
7922 (use (const_int 0))])])
7923
7924 ;; Operand 1 not used on the AVR.
7925 ;; Operand 2 is 1 for tail-call, 0 otherwise.
7926 (define_expand "sibcall"
7927 [(parallel[(call (match_operand:HI 0 "call_insn_operand" "")
7928 (match_operand:HI 1 "general_operand" ""))
7929 (use (const_int 1))])])
7930
7931 ;; call value
7932
7933 ;; Operand 2 not used on the AVR.
7934 ;; Operand 3 is 1 for tail-call, 0 otherwise.
7935 (define_expand "call_value"
7936 [(parallel[(set (match_operand 0 "register_operand" "")
7937 (call (match_operand:HI 1 "call_insn_operand" "")
7938 (match_operand:HI 2 "general_operand" "")))
7939 (use (const_int 0))])])
7940
7941 ;; Operand 2 not used on the AVR.
7942 ;; Operand 3 is 1 for tail-call, 0 otherwise.
7943 (define_expand "sibcall_value"
7944 [(parallel[(set (match_operand 0 "register_operand" "")
7945 (call (match_operand:HI 1 "call_insn_operand" "")
7946 (match_operand:HI 2 "general_operand" "")))
7947 (use (const_int 1))])])
7948
7949 (define_insn "call_insn"
7950 [(parallel[(call (mem:HI (match_operand:HI 0 "nonmemory_operand" "z,s,z,s"))
7951 (match_operand:HI 1 "general_operand" "X,X,X,X"))
7952 (use (match_operand:HI 2 "const_int_operand" "L,L,P,P"))])]
7953 ;; Operand 1 not used on the AVR.
7954 ;; Operand 2 is 1 for tail-call, 0 otherwise.
7955 ""
7956 "@
7957 %!icall
7958 %~call %x0
7959 %!ijmp
7960 %~jmp %x0"
7961 [(set_attr "length" "1,*,1,*")
7962 (set_attr "adjust_len" "*,call,*,call")])
7963
7964 (define_insn "call_value_insn"
7965 [(parallel[(set (match_operand 0 "register_operand" "=r,r,r,r")
7966 (call (mem:HI (match_operand:HI 1 "nonmemory_operand" "z,s,z,s"))
7967 (match_operand:HI 2 "general_operand" "X,X,X,X")))
7968 (use (match_operand:HI 3 "const_int_operand" "L,L,P,P"))])]
7969 ;; Operand 2 not used on the AVR.
7970 ;; Operand 3 is 1 for tail-call, 0 otherwise.
7971 ""
7972 "@
7973 %!icall
7974 %~call %x1
7975 %!ijmp
7976 %~jmp %x1"
7977 [(set_attr "length" "1,*,1,*")
7978 (set_attr "adjust_len" "*,call,*,call")])
7979
7980 (define_insn "nop"
7981 [(const_int 0)]
7982 ""
7983 "nop"
7984 [(set_attr "length" "1")])
7985
7986 ; indirect jump
7987
7988 (define_expand "indirect_jump"
7989 [(set (pc)
7990 (match_operand:HI 0 "nonmemory_operand" ""))]
7991 ""
7992 {
7993 if (!AVR_HAVE_JMP_CALL && !register_operand (operands[0], HImode))
7994 {
7995 operands[0] = copy_to_mode_reg (HImode, operands[0]);
7996 }
7997 })
7998
7999 ; indirect jump
8000 (define_insn "*indirect_jump"
8001 [(set (pc)
8002 (match_operand:HI 0 "nonmemory_operand" "i,i,!z,*r,z"))]
8003 ""
8004 "@
8005 rjmp %x0
8006 jmp %x0
8007 ijmp
8008 push %A0\;push %B0\;ret
8009 eijmp"
8010 [(set_attr "length" "1,2,1,3,1")
8011 (set_attr "isa" "rjmp,jmp,ijmp,ijmp,eijmp")])
8012
8013 ;; table jump
8014 ;; For entries in jump table see avr_output_addr_vec.
8015
8016 ;; Table made from
8017 ;; "rjmp .L<n>" instructions for <= 8K devices
8018 ;; ".word gs(.L<n>)" addresses for > 8K devices
8019 (define_insn_and_split "*tablejump_split"
8020 [(set (pc)
8021 (unspec:HI [(match_operand:HI 0 "register_operand" "!z,*r,z")]
8022 UNSPEC_INDEX_JMP))
8023 (use (label_ref (match_operand 1 "" "")))
8024 (clobber (match_operand:HI 2 "scratch_operand" "=X,X,0"))
8025 (clobber (const_int 0))]
8026 "!AVR_HAVE_EIJMP_EICALL"
8027 "#"
8028 "&& reload_completed"
8029 [(parallel [(set (pc)
8030 (unspec:HI [(match_dup 0)]
8031 UNSPEC_INDEX_JMP))
8032 (use (label_ref (match_dup 1)))
8033 (clobber (match_dup 2))
8034 (clobber (const_int 0))
8035 (clobber (reg:CC REG_CC))])]
8036 ""
8037 [(set_attr "isa" "rjmp,rjmp,jmp")])
8038
8039 (define_insn "*tablejump"
8040 [(set (pc)
8041 (unspec:HI [(match_operand:HI 0 "register_operand" "!z,*r,z")]
8042 UNSPEC_INDEX_JMP))
8043 (use (label_ref (match_operand 1 "" "")))
8044 (clobber (match_operand:HI 2 "scratch_operand" "=X,X,0"))
8045 (clobber (const_int 0))
8046 (clobber (reg:CC REG_CC))]
8047 "!AVR_HAVE_EIJMP_EICALL && reload_completed"
8048 "@
8049 ijmp
8050 push %A0\;push %B0\;ret
8051 jmp __tablejump2__"
8052 [(set_attr "length" "1,3,2")
8053 (set_attr "isa" "rjmp,rjmp,jmp")])
8054
8055 (define_insn_and_split "*tablejump.3byte-pc_split"
8056 [(set (pc)
8057 (unspec:HI [(reg:HI REG_Z)]
8058 UNSPEC_INDEX_JMP))
8059 (use (label_ref (match_operand 0 "" "")))
8060 (clobber (reg:HI REG_Z))
8061 (clobber (reg:QI 24))]
8062 "AVR_HAVE_EIJMP_EICALL"
8063 "#"
8064 "&& reload_completed"
8065 [(parallel [(set (pc)
8066 (unspec:HI [(reg:HI REG_Z)]
8067 UNSPEC_INDEX_JMP))
8068 (use (label_ref (match_dup 0)))
8069 (clobber (reg:HI REG_Z))
8070 (clobber (reg:QI 24))
8071 (clobber (reg:CC REG_CC))])]
8072 ""
8073 [(set_attr "isa" "eijmp")])
8074
8075
8076 (define_insn "*tablejump.3byte-pc"
8077 [(set (pc)
8078 (unspec:HI [(reg:HI REG_Z)]
8079 UNSPEC_INDEX_JMP))
8080 (use (label_ref (match_operand 0 "" "")))
8081 (clobber (reg:HI REG_Z))
8082 (clobber (reg:QI 24))
8083 (clobber (reg:CC REG_CC))]
8084 "AVR_HAVE_EIJMP_EICALL && reload_completed"
8085 "clr r24\;subi r30,pm_lo8(-(%0))\;sbci r31,pm_hi8(-(%0))\;sbci r24,pm_hh8(-(%0))\;jmp __tablejump2__"
8086 [(set_attr "length" "6")
8087 (set_attr "isa" "eijmp")])
8088
8089
8090 ;; FIXME: casesi comes up with an SImode switch value $0 which
8091 ;; is quite some overhead because most code would use HI or
8092 ;; even QI. We add an AVR specific pass .avr-casesi which
8093 ;; tries to recover from the superfluous extension to SImode.
8094 ;;
8095 ;; Using "tablejump" could be a way out, but this also does
8096 ;; not perform in a satisfying manner as the middle end will
8097 ;; already multiply the table index by 2. Note that this
8098 ;; multiplication is performed by libgcc's __tablejump2__.
8099 ;; The multiplication there, however, runs *after* the table
8100 ;; start (a byte address) has been added, not before it like
8101 ;; "tablejump" will do.
8102 ;;
8103 ;; The preferred solution would be to let the middle ends pass
8104 ;; down information on the index as an additional casesi operand.
8105 ;;
8106 ;; If this expander is changed, you'll likely have to go through
8107 ;; "casesi_<mode>_sequence" (used to recog + extract casesi
8108 ;; sequences in pass .avr-casesi) and propagate all adjustments
8109 ;; also to that pattern and the code of the extra pass.
8110
8111 (define_expand "casesi"
8112 [(parallel [(set (match_dup 5)
8113 (plus:SI (match_operand:SI 0 "register_operand")
8114 (match_operand:SI 1 "const_int_operand")))
8115 (clobber (scratch:QI))])
8116
8117 (parallel [(set (pc)
8118 (if_then_else (gtu (match_dup 5)
8119 (match_operand:SI 2 "const_int_operand"))
8120 (label_ref (match_operand 4))
8121 (pc)))
8122 (clobber (scratch:QI))])
8123
8124 (set (match_dup 7)
8125 (match_dup 6))
8126
8127 (parallel [(set (pc)
8128 (unspec:HI [(match_dup 7)] UNSPEC_INDEX_JMP))
8129 (use (label_ref (match_dup 3)))
8130 (clobber (match_dup 8))
8131 (clobber (match_dup 9))])]
8132 ""
8133 {
8134 operands[1] = simplify_unary_operation (NEG, SImode, operands[1], SImode);
8135 operands[5] = gen_reg_rtx (SImode);
8136 operands[6] = simplify_gen_subreg (HImode, operands[5], SImode, 0);
8137
8138 if (AVR_HAVE_EIJMP_EICALL)
8139 {
8140 operands[7] = gen_rtx_REG (HImode, REG_Z);
8141 operands[8] = gen_rtx_REG (HImode, REG_Z);
8142 operands[9] = all_regs_rtx[24];
8143 }
8144 else
8145 {
8146 operands[6] = gen_rtx_PLUS (HImode, operands[6],
8147 gen_rtx_LABEL_REF (VOIDmode, operands[3]));
8148 if (AVR_HAVE_JMP_CALL)
8149 {
8150 operands[7] = gen_rtx_REG (HImode, REG_Z);
8151 operands[8] = gen_rtx_REG (HImode, REG_Z);
8152 }
8153 else
8154 {
8155 operands[7] = gen_reg_rtx (HImode);
8156 operands[8] = gen_rtx_SCRATCH (HImode);
8157 }
8158 operands[9] = const0_rtx;
8159 }
8160 })
8161
8162
8163 ;; This insn is used only for easy operand extraction.
8164 ;; The elements must match an extension to SImode plus
8165 ;; a sequence generated by casesi above.
8166
8167 ;; "casesi_qi_sequence"
8168 ;; "casesi_hi_sequence"
8169 (define_insn "casesi_<mode>_sequence"
8170 [(set (match_operand:SI 0 "register_operand")
8171 (match_operator:SI 10 "extend_operator"
8172 [(match_operand:QIHI 11 "register_operand")]))
8173
8174 ;; What follows is a matcher for code from casesi.
8175 ;; We keep the same operand numbering (except for $10 and $11
8176 ;; which don't appear in casesi).
8177 (parallel [(set (match_operand:SI 5 "register_operand")
8178 (plus:SI (match_dup 0)
8179 (match_operand:SI 1 "const_int_operand")))
8180 (clobber (scratch:QI))])
8181
8182 (parallel [(set (pc)
8183 (if_then_else (gtu (match_dup 5)
8184 (match_operand:SI 2 "const_int_operand"))
8185 (label_ref (match_operand 4))
8186 (pc)))
8187 (clobber (scratch:QI))])
8188
8189 (set (match_operand:HI 7 "register_operand")
8190 (match_operand:HI 6))
8191
8192 (parallel [(set (pc)
8193 (unspec:HI [(match_dup 7)] UNSPEC_INDEX_JMP))
8194 (use (label_ref (match_operand 3)))
8195 (clobber (match_operand:HI 8))
8196 (clobber (match_operand:QI 9))])]
8197 "optimize
8198 && avr_casei_sequence_check_operands (operands)"
8199 { gcc_unreachable(); }
8200 )
8201
8202
8203 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8204 ;; Clear/set/test a single bit in I/O address space.
8205
8206 (define_insn "*cbi"
8207 [(set (mem:QI (match_operand 0 "low_io_address_operand" "i"))
8208 (and:QI (mem:QI (match_dup 0))
8209 (match_operand:QI 1 "single_zero_operand" "n")))]
8210 ""
8211 {
8212 operands[2] = GEN_INT (exact_log2 (~INTVAL (operands[1]) & 0xff));
8213 return "cbi %i0,%2";
8214 }
8215 [(set_attr "length" "1")])
8216
8217 (define_insn "*sbi"
8218 [(set (mem:QI (match_operand 0 "low_io_address_operand" "i"))
8219 (ior:QI (mem:QI (match_dup 0))
8220 (match_operand:QI 1 "single_one_operand" "n")))]
8221 ""
8222 {
8223 operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1]) & 0xff));
8224 return "sbi %i0,%2";
8225 }
8226 [(set_attr "length" "1")])
8227
8228 ;; Lower half of the I/O space - use sbic/sbis directly.
8229 (define_insn_and_split "*sbix_branch_split"
8230 [(set (pc)
8231 (if_then_else
8232 (match_operator 0 "eqne_operator"
8233 [(zero_extract:QIHI
8234 (mem:QI (match_operand 1 "low_io_address_operand" "i"))
8235 (const_int 1)
8236 (match_operand 2 "const_int_operand" "n"))
8237 (const_int 0)])
8238 (label_ref (match_operand 3 "" ""))
8239 (pc)))]
8240 ""
8241 "#"
8242 "&& reload_completed"
8243 [(parallel [(set (pc)
8244 (if_then_else
8245 (match_operator 0 "eqne_operator"
8246 [(zero_extract:QIHI
8247 (mem:QI (match_dup 1))
8248 (const_int 1)
8249 (match_dup 2))
8250 (const_int 0)])
8251 (label_ref (match_dup 3))
8252 (pc)))
8253 (clobber (reg:CC REG_CC))])])
8254
8255 (define_insn "*sbix_branch"
8256 [(set (pc)
8257 (if_then_else
8258 (match_operator 0 "eqne_operator"
8259 [(zero_extract:QIHI
8260 (mem:QI (match_operand 1 "low_io_address_operand" "i"))
8261 (const_int 1)
8262 (match_operand 2 "const_int_operand" "n"))
8263 (const_int 0)])
8264 (label_ref (match_operand 3 "" ""))
8265 (pc)))
8266 (clobber (reg:CC REG_CC))]
8267 "reload_completed"
8268 {
8269 return avr_out_sbxx_branch (insn, operands);
8270 }
8271 [(set (attr "length")
8272 (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
8273 (le (minus (pc) (match_dup 3)) (const_int 2046)))
8274 (const_int 2)
8275 (if_then_else (match_test "!AVR_HAVE_JMP_CALL")
8276 (const_int 2)
8277 (const_int 4))))])
8278
8279 ;; Tests of bit 7 are pessimized to sign tests, so we need this too...
8280 (define_insn_and_split "*sbix_branch_bit7_split"
8281 [(set (pc)
8282 (if_then_else
8283 (match_operator 0 "gelt_operator"
8284 [(mem:QI (match_operand 1 "low_io_address_operand" "i"))
8285 (const_int 0)])
8286 (label_ref (match_operand 2 "" ""))
8287 (pc)))]
8288 ""
8289 "#"
8290 "&& reload_completed"
8291 [(parallel [(set (pc)
8292 (if_then_else
8293 (match_operator 0 "gelt_operator"
8294 [(mem:QI (match_dup 1))
8295 (const_int 0)])
8296 (label_ref (match_dup 2))
8297 (pc)))
8298 (clobber (reg:CC REG_CC))])])
8299
8300 (define_insn "*sbix_branch_bit7"
8301 [(set (pc)
8302 (if_then_else
8303 (match_operator 0 "gelt_operator"
8304 [(mem:QI (match_operand 1 "low_io_address_operand" "i"))
8305 (const_int 0)])
8306 (label_ref (match_operand 2 "" ""))
8307 (pc)))
8308 (clobber (reg:CC REG_CC))]
8309 "reload_completed"
8310 {
8311 operands[3] = operands[2];
8312 operands[2] = GEN_INT (7);
8313 return avr_out_sbxx_branch (insn, operands);
8314 }
8315 [(set (attr "length")
8316 (if_then_else (and (ge (minus (pc) (match_dup 2)) (const_int -2046))
8317 (le (minus (pc) (match_dup 2)) (const_int 2046)))
8318 (const_int 2)
8319 (if_then_else (match_test "!AVR_HAVE_JMP_CALL")
8320 (const_int 2)
8321 (const_int 4))))])
8322
8323 ;; Upper half of the I/O space - read port to __tmp_reg__ and use sbrc/sbrs.
8324 (define_insn_and_split "*sbix_branch_tmp_split"
8325 [(set (pc)
8326 (if_then_else
8327 (match_operator 0 "eqne_operator"
8328 [(zero_extract:QIHI
8329 (mem:QI (match_operand 1 "high_io_address_operand" "n"))
8330 (const_int 1)
8331 (match_operand 2 "const_int_operand" "n"))
8332 (const_int 0)])
8333 (label_ref (match_operand 3 "" ""))
8334 (pc)))]
8335 ""
8336 "#"
8337 "&& reload_completed"
8338 [(parallel [(set (pc)
8339 (if_then_else
8340 (match_operator 0 "eqne_operator"
8341 [(zero_extract:QIHI
8342 (mem:QI (match_dup 1))
8343 (const_int 1)
8344 (match_dup 2))
8345 (const_int 0)])
8346 (label_ref (match_dup 3))
8347 (pc)))
8348 (clobber (reg:CC REG_CC))])])
8349
8350 (define_insn "*sbix_branch_tmp"
8351 [(set (pc)
8352 (if_then_else
8353 (match_operator 0 "eqne_operator"
8354 [(zero_extract:QIHI
8355 (mem:QI (match_operand 1 "high_io_address_operand" "n"))
8356 (const_int 1)
8357 (match_operand 2 "const_int_operand" "n"))
8358 (const_int 0)])
8359 (label_ref (match_operand 3 "" ""))
8360 (pc)))
8361 (clobber (reg:CC REG_CC))]
8362 "reload_completed"
8363 {
8364 return avr_out_sbxx_branch (insn, operands);
8365 }
8366 [(set (attr "length")
8367 (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
8368 (le (minus (pc) (match_dup 3)) (const_int 2045)))
8369 (const_int 3)
8370 (if_then_else (match_test "!AVR_HAVE_JMP_CALL")
8371 (const_int 3)
8372 (const_int 5))))])
8373
8374 (define_insn_and_split "*sbix_branch_tmp_bit7_split"
8375 [(set (pc)
8376 (if_then_else
8377 (match_operator 0 "gelt_operator"
8378 [(mem:QI (match_operand 1 "high_io_address_operand" "n"))
8379 (const_int 0)])
8380 (label_ref (match_operand 2 "" ""))
8381 (pc)))]
8382 ""
8383 "#"
8384 "&& reload_completed"
8385 [(parallel [(set (pc)
8386 (if_then_else
8387 (match_operator 0 "gelt_operator"
8388 [(mem:QI (match_dup 1))
8389 (const_int 0)])
8390 (label_ref (match_dup 2))
8391 (pc)))
8392 (clobber (reg:CC REG_CC))])])
8393
8394 (define_insn "*sbix_branch_tmp_bit7"
8395 [(set (pc)
8396 (if_then_else
8397 (match_operator 0 "gelt_operator"
8398 [(mem:QI (match_operand 1 "high_io_address_operand" "n"))
8399 (const_int 0)])
8400 (label_ref (match_operand 2 "" ""))
8401 (pc)))
8402 (clobber (reg:CC REG_CC))]
8403 "reload_completed"
8404 {
8405 operands[3] = operands[2];
8406 operands[2] = GEN_INT (7);
8407 return avr_out_sbxx_branch (insn, operands);
8408 }
8409 [(set (attr "length")
8410 (if_then_else (and (ge (minus (pc) (match_dup 2)) (const_int -2046))
8411 (le (minus (pc) (match_dup 2)) (const_int 2045)))
8412 (const_int 3)
8413 (if_then_else (match_test "!AVR_HAVE_JMP_CALL")
8414 (const_int 3)
8415 (const_int 5))))])
8416
8417 ;; ************************* Peepholes ********************************
8418
8419 (define_peephole ; "*dec-and-branchsi!=-1.d.clobber"
8420 [(parallel [(set (match_operand:SI 0 "d_register_operand" "")
8421 (plus:SI (match_dup 0)
8422 (const_int -1)))
8423 (clobber (scratch:QI))
8424 (clobber (reg:CC REG_CC))])
8425 (parallel [(set (reg:CC REG_CC)
8426 (compare:CC (match_dup 0)
8427 (const_int -1)))
8428 (clobber (match_operand:QI 1 "scratch_or_dreg_operand"))])
8429 (set (pc)
8430 (if_then_else (eqne (reg:CC REG_CC)
8431 (const_int 0))
8432 (label_ref (match_operand 2))
8433 (pc)))]
8434 "dead_or_set_regno_p (insn, REG_CC)"
8435 {
8436 if (avr_adiw_reg_p (operands[0]))
8437 output_asm_insn ("sbiw %0,1" CR_TAB
8438 "sbc %C0,__zero_reg__" CR_TAB
8439 "sbc %D0,__zero_reg__", operands);
8440 else
8441 output_asm_insn ("subi %A0,1" CR_TAB
8442 "sbc %B0,__zero_reg__" CR_TAB
8443 "sbc %C0,__zero_reg__" CR_TAB
8444 "sbc %D0,__zero_reg__", operands);
8445
8446 int jump_mode = avr_jump_mode (operands[2], insn, 3 - avr_adiw_reg_p (operands[0]));
8447 const char *op = ((EQ == <CODE>) ^ (jump_mode == 1)) ? "brcc" : "brcs";
8448 operands[1] = gen_rtx_CONST_STRING (VOIDmode, op);
8449
8450 switch (jump_mode)
8451 {
8452 case 1: return "%1 %2";
8453 case 2: return "%1 .+2\;rjmp %2";
8454 case 3: return "%1 .+4\;jmp %2";
8455 }
8456
8457 gcc_unreachable();
8458 return "";
8459 })
8460
8461 (define_peephole ; "*dec-and-branchhi!=-1"
8462 [(parallel [(set (match_operand:HI 0 "d_register_operand" "")
8463 (plus:HI (match_dup 0)
8464 (const_int -1)))
8465 (clobber (reg:CC REG_CC))])
8466 (parallel [(set (reg:CC REG_CC)
8467 (compare:CC (match_dup 0)
8468 (const_int -1)))
8469 (clobber (match_operand:QI 1 "d_register_operand" ""))])
8470 (set (pc)
8471 (if_then_else (eqne (reg:CC REG_CC)
8472 (const_int 0))
8473 (label_ref (match_operand 2))
8474 (pc)))]
8475 "dead_or_set_regno_p (insn, REG_CC)"
8476 {
8477 if (avr_adiw_reg_p (operands[0]))
8478 output_asm_insn ("sbiw %0,1", operands);
8479 else
8480 output_asm_insn ("subi %A0,1" CR_TAB
8481 "sbc %B0,__zero_reg__", operands);
8482
8483 int jump_mode = avr_jump_mode (operands[2], insn, 1 - avr_adiw_reg_p (operands[0]));
8484 const char *op = ((EQ == <CODE>) ^ (jump_mode == 1)) ? "brcc" : "brcs";
8485 operands[1] = gen_rtx_CONST_STRING (VOIDmode, op);
8486
8487 switch (jump_mode)
8488 {
8489 case 1: return "%1 %2";
8490 case 2: return "%1 .+2\;rjmp %2";
8491 case 3: return "%1 .+4\;jmp %2";
8492 }
8493
8494 gcc_unreachable();
8495 return "";
8496 })
8497
8498 ;; Same as above but with clobber flavour of addhi3
8499 (define_peephole ; "*dec-and-branchhi!=-1.d.clobber"
8500 [(parallel [(set (match_operand:HI 0 "d_register_operand" "")
8501 (plus:HI (match_dup 0)
8502 (const_int -1)))
8503 (clobber (scratch:QI))
8504 (clobber (reg:CC REG_CC))])
8505 (parallel [(set (reg:CC REG_CC)
8506 (compare:CC (match_dup 0)
8507 (const_int -1)))
8508 (clobber (match_operand:QI 1 "scratch_or_dreg_operand"))])
8509 (set (pc)
8510 (if_then_else (eqne (reg:CC REG_CC)
8511 (const_int 0))
8512 (label_ref (match_operand 2))
8513 (pc)))]
8514 "dead_or_set_regno_p (insn, REG_CC)"
8515 {
8516 if (avr_adiw_reg_p (operands[0]))
8517 output_asm_insn ("sbiw %0,1", operands);
8518 else
8519 output_asm_insn ("subi %A0,1" CR_TAB
8520 "sbc %B0,__zero_reg__", operands);
8521
8522 int jump_mode = avr_jump_mode (operands[2], insn, 1 - avr_adiw_reg_p (operands[0]));
8523 const char *op = ((EQ == <CODE>) ^ (jump_mode == 1)) ? "brcc" : "brcs";
8524 operands[1] = gen_rtx_CONST_STRING (VOIDmode, op);
8525
8526 switch (jump_mode)
8527 {
8528 case 1: return "%1 %2";
8529 case 2: return "%1 .+2\;rjmp %2";
8530 case 3: return "%1 .+4\;jmp %2";
8531 }
8532
8533 gcc_unreachable();
8534 return "";
8535 })
8536
8537 ;; Same as above but with clobber flavour of addhi3
8538 (define_peephole ; "*dec-and-branchhi!=-1.l.clobber"
8539 [(parallel [(set (match_operand:HI 0 "l_register_operand" "")
8540 (plus:HI (match_dup 0)
8541 (const_int -1)))
8542 (clobber (match_operand:QI 3 "d_register_operand" ""))
8543 (clobber (reg:CC REG_CC))])
8544 (parallel [(set (reg:CC REG_CC)
8545 (compare:CC (match_dup 0)
8546 (const_int -1)))
8547 (clobber (match_operand:QI 1 "d_register_operand" ""))])
8548 (set (pc)
8549 (if_then_else (eqne (reg:CC REG_CC)
8550 (const_int 0))
8551 (label_ref (match_operand 2))
8552 (pc)))]
8553 "dead_or_set_regno_p (insn, REG_CC)"
8554 {
8555 output_asm_insn ("ldi %3,1" CR_TAB
8556 "sub %A0,%3" CR_TAB
8557 "sbc %B0,__zero_reg__", operands);
8558
8559 int jump_mode = avr_jump_mode (operands[2], insn, 2);
8560 const char *op = ((EQ == <CODE>) ^ (jump_mode == 1)) ? "brcc" : "brcs";
8561 operands[1] = gen_rtx_CONST_STRING (VOIDmode, op);
8562
8563 switch (jump_mode)
8564 {
8565 case 1: return "%1 %2";
8566 case 2: return "%1 .+2\;rjmp %2";
8567 case 3: return "%1 .+4\;jmp %2";
8568 }
8569
8570 gcc_unreachable();
8571 return "";
8572 })
8573
8574 (define_peephole ; "*dec-and-branchqi!=-1"
8575 [(parallel [(set (match_operand:QI 0 "d_register_operand" "")
8576 (plus:QI (match_dup 0)
8577 (const_int -1)))
8578 (clobber (reg:CC REG_CC))])
8579 (set (reg:CC REG_CC)
8580 (compare:CC (match_dup 0)
8581 (const_int -1)))
8582 (set (pc)
8583 (if_then_else (eqne (reg:CC REG_CC)
8584 (const_int 0))
8585 (label_ref (match_operand 1))
8586 (pc)))]
8587 "dead_or_set_regno_p (insn, REG_CC)"
8588 {
8589 output_asm_insn ("subi %A0,1", operands);
8590
8591 int jump_mode = avr_jump_mode (operands[1], insn);
8592 const char *op = ((EQ == <CODE>) ^ (jump_mode == 1)) ? "brcc" : "brcs";
8593 operands[0] = gen_rtx_CONST_STRING (VOIDmode, op);
8594
8595 switch (jump_mode)
8596 {
8597 case 1: return "%0 %1";
8598 case 2: return "%0 .+2\;rjmp %1";
8599 case 3: return "%0 .+4\;jmp %1";
8600 }
8601
8602 gcc_unreachable();
8603 return "";
8604 })
8605
8606
8607 (define_peephole ; "*cpse.eq"
8608 [(set (reg:CC REG_CC)
8609 (compare:CC (match_operand:ALL1 1 "register_operand" "r,r")
8610 (match_operand:ALL1 2 "reg_or_0_operand" "r,Y00")))
8611 (set (pc)
8612 (if_then_else (eq (reg:CC REG_CC)
8613 (const_int 0))
8614 (label_ref (match_operand 0))
8615 (pc)))]
8616 "jump_over_one_insn_p (insn, operands[0])
8617 && dead_or_set_regno_p (insn, REG_CC)"
8618 "@
8619 cpse %1,%2
8620 cpse %1,__zero_reg__")
8621
8622 ;; This peephole avoids code like
8623 ;;
8624 ;; TST Rn ; cmpqi3
8625 ;; BREQ .+2 ; branch
8626 ;; RJMP .Lm
8627 ;;
8628 ;; Notice that the peephole is always shorter than cmpqi + branch.
8629 ;; The reason to write it as peephole is that sequences like
8630 ;;
8631 ;; AND Rm, Rn
8632 ;; BRNE .La
8633 ;;
8634 ;; shall not be superseeded. With a respective combine pattern
8635 ;; the latter sequence would be
8636 ;;
8637 ;; AND Rm, Rn
8638 ;; CPSE Rm, __zero_reg__
8639 ;; RJMP .La
8640 ;;
8641 ;; and thus longer and slower and not easy to be rolled back.
8642
8643 (define_peephole ; "*cpse.ne"
8644 [(set (reg:CC REG_CC)
8645 (compare:CC (match_operand:ALL1 1 "register_operand")
8646 (match_operand:ALL1 2 "reg_or_0_operand")))
8647 (set (pc)
8648 (if_then_else (ne (reg:CC REG_CC)
8649 (const_int 0))
8650 (label_ref (match_operand 0))
8651 (pc)))]
8652 "(!AVR_HAVE_JMP_CALL
8653 || !TARGET_SKIP_BUG)
8654 && dead_or_set_regno_p (insn, REG_CC)"
8655 {
8656 if (operands[2] == CONST0_RTX (<MODE>mode))
8657 operands[2] = zero_reg_rtx;
8658
8659 return 3 == avr_jump_mode (operands[0], insn)
8660 ? "cpse %1,%2\;jmp %0"
8661 : "cpse %1,%2\;rjmp %0";
8662 })
8663
8664 ;;pppppppppppppppppppppppppppppppppppppppppppppppppppp
8665 ;;prologue/epilogue support instructions
8666
8667 (define_insn "popqi"
8668 [(set (match_operand:QI 0 "register_operand" "=r")
8669 (mem:QI (pre_inc:HI (reg:HI REG_SP))))]
8670 ""
8671 "pop %0"
8672 [(set_attr "length" "1")])
8673
8674 ;; Enable Interrupts
8675 (define_expand "enable_interrupt"
8676 [(clobber (const_int 0))]
8677 ""
8678 {
8679 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
8680 MEM_VOLATILE_P (mem) = 1;
8681 emit_insn (gen_cli_sei (const1_rtx, mem));
8682 DONE;
8683 })
8684
8685 ;; Disable Interrupts
8686 (define_expand "disable_interrupt"
8687 [(clobber (const_int 0))]
8688 ""
8689 {
8690 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
8691 MEM_VOLATILE_P (mem) = 1;
8692 emit_insn (gen_cli_sei (const0_rtx, mem));
8693 DONE;
8694 })
8695
8696 (define_insn "cli_sei"
8697 [(unspec_volatile [(match_operand:QI 0 "const_int_operand" "L,P")]
8698 UNSPECV_ENABLE_IRQS)
8699 (set (match_operand:BLK 1 "" "")
8700 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))]
8701 ""
8702 "@
8703 cli
8704 sei"
8705 [(set_attr "length" "1")])
8706
8707 ;; Library prologue saves
8708 (define_insn "call_prologue_saves"
8709 [(unspec_volatile:HI [(const_int 0)] UNSPECV_PROLOGUE_SAVES)
8710 (match_operand:HI 0 "immediate_operand" "i,i")
8711 (set (reg:HI REG_SP)
8712 (minus:HI (reg:HI REG_SP)
8713 (match_operand:HI 1 "immediate_operand" "i,i")))
8714 (use (reg:HI REG_X))
8715 (clobber (reg:HI REG_Z))
8716 (clobber (reg:CC REG_CC))]
8717 ""
8718 "ldi r30,lo8(gs(1f))
8719 ldi r31,hi8(gs(1f))
8720 %~jmp __prologue_saves__+((18 - %0) * 2)
8721 1:"
8722 [(set_attr "length" "5,6")
8723 (set_attr "isa" "rjmp,jmp")])
8724
8725 ; epilogue restores using library
8726 (define_insn "epilogue_restores"
8727 [(unspec_volatile:QI [(const_int 0)] UNSPECV_EPILOGUE_RESTORES)
8728 (set (reg:HI REG_Y)
8729 (plus:HI (reg:HI REG_Y)
8730 (match_operand:HI 0 "immediate_operand" "i,i")))
8731 (set (reg:HI REG_SP)
8732 (plus:HI (reg:HI REG_Y)
8733 (match_dup 0)))
8734 (clobber (reg:QI REG_Z))
8735 (clobber (reg:CC REG_CC))]
8736 ""
8737 "ldi r30, lo8(%0)
8738 %~jmp __epilogue_restores__ + ((18 - %0) * 2)"
8739 [(set_attr "length" "2,3")
8740 (set_attr "isa" "rjmp,jmp")])
8741
8742
8743 ;; $0 = Chunk: 1 = Prologue, 2 = Epilogue
8744 ;; $1 = Register as printed by chunk 0 (Done) in final postscan.
8745 (define_expand "gasisr"
8746 [(parallel [(unspec_volatile [(match_operand:QI 0 "const_int_operand")
8747 (match_operand:QI 1 "const_int_operand")]
8748 UNSPECV_GASISR)
8749 (set (reg:HI REG_SP)
8750 (unspec_volatile:HI [(reg:HI REG_SP)] UNSPECV_GASISR))
8751 (set (match_dup 2)
8752 (unspec_volatile:BLK [(match_dup 2)]
8753 UNSPECV_MEMORY_BARRIER))
8754 (clobber (reg:CC REG_CC))])]
8755 "avropt_gasisr_prologues"
8756 {
8757 operands[2] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
8758 MEM_VOLATILE_P (operands[2]) = 1;
8759 })
8760
8761 (define_insn "*gasisr"
8762 [(unspec_volatile [(match_operand:QI 0 "const_int_operand" "P,K")
8763 (match_operand:QI 1 "const_int_operand" "n,n")]
8764 UNSPECV_GASISR)
8765 (set (reg:HI REG_SP)
8766 (unspec_volatile:HI [(reg:HI REG_SP)] UNSPECV_GASISR))
8767 (set (match_operand:BLK 2)
8768 (unspec_volatile:BLK [(match_dup 2)] UNSPECV_MEMORY_BARRIER))
8769 (clobber (reg:CC REG_CC))]
8770 "avropt_gasisr_prologues"
8771 "__gcc_isr %0"
8772 [(set_attr "length" "6,5")])
8773
8774
8775 ; return
8776 (define_insn "return"
8777 [(return)]
8778 "reload_completed && avr_simple_epilogue ()"
8779 "ret"
8780 [(set_attr "length" "1")])
8781
8782 (define_insn "return_from_epilogue"
8783 [(return)]
8784 "reload_completed
8785 && cfun->machine
8786 && !(cfun->machine->is_interrupt || cfun->machine->is_signal)
8787 && !cfun->machine->is_naked"
8788 "ret"
8789 [(set_attr "length" "1")])
8790
8791 (define_insn "return_from_interrupt_epilogue"
8792 [(return)]
8793 "reload_completed
8794 && cfun->machine
8795 && (cfun->machine->is_interrupt || cfun->machine->is_signal)
8796 && !cfun->machine->is_naked"
8797 "reti"
8798 [(set_attr "length" "1")])
8799
8800 (define_insn "return_from_naked_epilogue"
8801 [(return)]
8802 "reload_completed
8803 && cfun->machine
8804 && cfun->machine->is_naked"
8805 ""
8806 [(set_attr "length" "0")])
8807
8808 (define_expand "prologue"
8809 [(const_int 0)]
8810 ""
8811 {
8812 avr_expand_prologue ();
8813 DONE;
8814 })
8815
8816 (define_expand "epilogue"
8817 [(const_int 0)]
8818 ""
8819 {
8820 avr_expand_epilogue (false /* sibcall_p */);
8821 DONE;
8822 })
8823
8824 (define_expand "sibcall_epilogue"
8825 [(const_int 0)]
8826 ""
8827 {
8828 avr_expand_epilogue (true /* sibcall_p */);
8829 DONE;
8830 })
8831
8832 ;; Some instructions resp. instruction sequences available
8833 ;; via builtins.
8834
8835 (define_insn_and_split "delay_cycles_1"
8836 [(unspec_volatile [(match_operand:QI 0 "const_int_operand" "n")
8837 (const_int 1)]
8838 UNSPECV_DELAY_CYCLES)
8839 (set (match_operand:BLK 1 "" "")
8840 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8841 (clobber (match_scratch:QI 2 "=&d"))]
8842 ""
8843 "#"
8844 "&& reload_completed"
8845 [(parallel [(unspec_volatile [(match_dup 0)
8846 (const_int 1)]
8847 UNSPECV_DELAY_CYCLES)
8848 (set (match_dup 1)
8849 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8850 (clobber (match_dup 2))
8851 (clobber (reg:CC REG_CC))])])
8852
8853 (define_insn "*delay_cycles_1"
8854 [(unspec_volatile [(match_operand:QI 0 "const_int_operand" "n")
8855 (const_int 1)]
8856 UNSPECV_DELAY_CYCLES)
8857 (set (match_operand:BLK 1 "" "")
8858 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8859 (clobber (match_scratch:QI 2 "=&d"))
8860 (clobber (reg:CC REG_CC))]
8861 "reload_completed"
8862 "ldi %2,lo8(%0)
8863 1: dec %2
8864 brne 1b"
8865 [(set_attr "length" "3")])
8866
8867 (define_insn_and_split "delay_cycles_2"
8868 [(unspec_volatile [(match_operand:HI 0 "const_int_operand" "n,n")
8869 (const_int 2)]
8870 UNSPECV_DELAY_CYCLES)
8871 (set (match_operand:BLK 1 "" "")
8872 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8873 (clobber (match_scratch:HI 2 "=&w,&d"))]
8874 ""
8875 "#"
8876 "&& reload_completed"
8877 [(parallel [(unspec_volatile [(match_dup 0)
8878 (const_int 2)]
8879 UNSPECV_DELAY_CYCLES)
8880 (set (match_dup 1)
8881 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8882 (clobber (match_dup 2))
8883 (clobber (reg:CC REG_CC))])]
8884 ""
8885 [(set_attr "isa" "adiw,no_adiw")])
8886
8887 (define_insn "*delay_cycles_2"
8888 [(unspec_volatile [(match_operand:HI 0 "const_int_operand" "n,n")
8889 (const_int 2)]
8890 UNSPECV_DELAY_CYCLES)
8891 (set (match_operand:BLK 1 "" "")
8892 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8893 (clobber (match_scratch:HI 2 "=&w,&d"))
8894 (clobber (reg:CC REG_CC))]
8895 "reload_completed"
8896 "@
8897 ldi %A2,lo8(%0)\;ldi %B2,hi8(%0)\n1: sbiw %A2,1\;brne 1b
8898 ldi %A2,lo8(%0)\;ldi %B2,hi8(%0)\n1: subi %A2,1\;sbci %B2,0\;brne 1b"
8899 [(set_attr "length" "4,5")
8900 (set_attr "isa" "adiw,no_adiw")])
8901
8902 (define_insn_and_split "delay_cycles_3"
8903 [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "n")
8904 (const_int 3)]
8905 UNSPECV_DELAY_CYCLES)
8906 (set (match_operand:BLK 1 "" "")
8907 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8908 (clobber (match_scratch:QI 2 "=&d"))
8909 (clobber (match_scratch:QI 3 "=&d"))
8910 (clobber (match_scratch:QI 4 "=&d"))]
8911 ""
8912 "#"
8913 "&& reload_completed"
8914 [(parallel [(unspec_volatile [(match_dup 0)
8915 (const_int 3)]
8916 UNSPECV_DELAY_CYCLES)
8917 (set (match_dup 1)
8918 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8919 (clobber (match_dup 2))
8920 (clobber (match_dup 3))
8921 (clobber (match_dup 4))
8922 (clobber (reg:CC REG_CC))])])
8923
8924 (define_insn "*delay_cycles_3"
8925 [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "n")
8926 (const_int 3)]
8927 UNSPECV_DELAY_CYCLES)
8928 (set (match_operand:BLK 1 "" "")
8929 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8930 (clobber (match_scratch:QI 2 "=&d"))
8931 (clobber (match_scratch:QI 3 "=&d"))
8932 (clobber (match_scratch:QI 4 "=&d"))
8933 (clobber (reg:CC REG_CC))]
8934 "reload_completed"
8935 "ldi %2,lo8(%0)
8936 ldi %3,hi8(%0)
8937 ldi %4,hlo8(%0)
8938 1: subi %2,1
8939 sbci %3,0
8940 sbci %4,0
8941 brne 1b"
8942 [(set_attr "length" "7")])
8943
8944 (define_insn_and_split "delay_cycles_4"
8945 [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "n")
8946 (const_int 4)]
8947 UNSPECV_DELAY_CYCLES)
8948 (set (match_operand:BLK 1 "" "")
8949 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8950 (clobber (match_scratch:QI 2 "=&d"))
8951 (clobber (match_scratch:QI 3 "=&d"))
8952 (clobber (match_scratch:QI 4 "=&d"))
8953 (clobber (match_scratch:QI 5 "=&d"))]
8954 ""
8955 "#"
8956 "&& reload_completed"
8957 [(parallel [(unspec_volatile [(match_dup 0)
8958 (const_int 4)]
8959 UNSPECV_DELAY_CYCLES)
8960 (set (match_dup 1)
8961 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8962 (clobber (match_dup 2))
8963 (clobber (match_dup 3))
8964 (clobber (match_dup 4))
8965 (clobber (match_dup 5))
8966 (clobber (reg:CC REG_CC))])])
8967
8968 (define_insn "*delay_cycles_4"
8969 [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "n")
8970 (const_int 4)]
8971 UNSPECV_DELAY_CYCLES)
8972 (set (match_operand:BLK 1 "" "")
8973 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))
8974 (clobber (match_scratch:QI 2 "=&d"))
8975 (clobber (match_scratch:QI 3 "=&d"))
8976 (clobber (match_scratch:QI 4 "=&d"))
8977 (clobber (match_scratch:QI 5 "=&d"))
8978 (clobber (reg:CC REG_CC))]
8979 "reload_completed"
8980 "ldi %2,lo8(%0)
8981 ldi %3,hi8(%0)
8982 ldi %4,hlo8(%0)
8983 ldi %5,hhi8(%0)
8984 1: subi %2,1
8985 sbci %3,0
8986 sbci %4,0
8987 sbci %5,0
8988 brne 1b"
8989 [(set_attr "length" "9")])
8990
8991
8992 ;; __builtin_avr_insert_bits
8993
8994 (define_insn_and_split "insert_bits"
8995 [(set (match_operand:QI 0 "register_operand" "=r ,d ,r")
8996 (unspec:QI [(match_operand:SI 1 "const_int_operand" "C0f,Cxf,C0f")
8997 (match_operand:QI 2 "register_operand" "r ,r ,r")
8998 (match_operand:QI 3 "nonmemory_operand" "n ,0 ,0")]
8999 UNSPEC_INSERT_BITS))]
9000 ""
9001 "#"
9002 "&& reload_completed"
9003 [(parallel [(set (match_dup 0)
9004 (unspec:QI [(match_dup 1)
9005 (match_dup 2)
9006 (match_dup 3)]
9007 UNSPEC_INSERT_BITS))
9008 (clobber (reg:CC REG_CC))])])
9009
9010 (define_insn "*insert_bits"
9011 [(set (match_operand:QI 0 "register_operand" "=r ,d ,r")
9012 (unspec:QI [(match_operand:SI 1 "const_int_operand" "C0f,Cxf,C0f")
9013 (match_operand:QI 2 "register_operand" "r ,r ,r")
9014 (match_operand:QI 3 "nonmemory_operand" "n ,0 ,0")]
9015 UNSPEC_INSERT_BITS))
9016 (clobber (reg:CC REG_CC))]
9017 "reload_completed"
9018 {
9019 return avr_out_insert_bits (operands, NULL);
9020 }
9021 [(set_attr "adjust_len" "insert_bits")])
9022
9023
9024 ;; __builtin_avr_mask1
9025
9026 (define_expand "gen_mask1"
9027 [(parallel [(match_operand:QI 0 "register_operand")
9028 (match_operand 1 "const_int_operand")
9029 (match_operand:QI 2 "register_operand")])]
9030 ""
9031 {
9032 switch (INTVAL (operands[1]) & 0xff)
9033 {
9034 case 0x01:
9035 emit (gen_mask1_0x01_split (operands[0], operands[2]));
9036 break;
9037 case 0x80:
9038 emit (gen_mask1_0x80_split (operands[0], operands[2]));
9039 break;
9040 case 0xfe:
9041 emit (gen_mask1_0xfe_split (operands[0], operands[2]));
9042 break;
9043 case 0x7f:
9044 // Sequences like below don't work for 0x7f because
9045 // there is no ASL instruction.
9046 emit (gen_mask1_0x80_split (operands[0], operands[2]));
9047 emit (gen_one_cmplqi2 (operands[0], operands[0]));
9048 break;
9049 default:
9050 gcc_unreachable();
9051 }
9052 DONE;
9053 })
9054
9055 (define_insn_and_split "mask1_0x01_split"
9056 [(set (match_operand:QI 0 "register_operand" "=&d")
9057 (ashift:QI (const_int 1)
9058 (and:QI (match_operand:QI 1 "register_operand" "r")
9059 (const_int 7))))]
9060 ""
9061 "#"
9062 "&& reload_completed"
9063 [(parallel [(set (match_dup 0)
9064 (rotate:QI (const_int 1)
9065 (match_dup 1)))
9066 (clobber (reg:CC REG_CC))])])
9067
9068 (define_insn "*mask1_0x01"
9069 [(set (match_operand:QI 0 "register_operand" "=&d")
9070 (rotate:QI (const_int 1)
9071 (match_operand:QI 1 "register_operand" "r")))
9072 (clobber (reg:CC REG_CC))]
9073 "reload_completed"
9074 {
9075 return "ldi %0,1" CR_TAB
9076 "sbrc %1,1" CR_TAB
9077 "ldi %0,4" CR_TAB
9078 "sbrc %1,0" CR_TAB
9079 "lsl %0" CR_TAB
9080 "sbrc %1,2" CR_TAB
9081 "swap %0";
9082 }
9083 [(set_attr "length" "7")])
9084
9085
9086 ;; Use a representation as chosen by insn combine.
9087 (define_insn_and_split "mask1_0x80_split"
9088 [(set (match_operand:QI 0 "register_operand" "=&d")
9089 (subreg:QI (ashiftrt:HI (const_int 128)
9090 (and:QI (match_operand:QI 1 "register_operand" "r")
9091 (const_int 7)))
9092 0))]
9093 ""
9094 "#"
9095 "&& reload_completed"
9096 [(parallel [(set (match_dup 0)
9097 (rotatert:QI (const_int -128)
9098 (match_dup 1)))
9099 (clobber (reg:CC REG_CC))])])
9100
9101 (define_insn "*mask1_0x80"
9102 [(set (match_operand:QI 0 "register_operand" "=&d")
9103 (rotatert:QI (const_int -128)
9104 (match_operand:QI 1 "register_operand" "r")))
9105 (clobber (reg:CC REG_CC))]
9106 "reload_completed"
9107 {
9108 return "ldi %0,0x80" CR_TAB
9109 "sbrc %1,1" CR_TAB
9110 "ldi %0,0x20" CR_TAB
9111 "sbrc %1,0" CR_TAB
9112 "lsr %0" CR_TAB
9113 "sbrc %1,2" CR_TAB
9114 "swap %0";
9115 }
9116 [(set_attr "length" "7")])
9117
9118 (define_insn_and_split ""
9119 [(set (match_operand:QI 0 "register_operand" "=&d")
9120 (not:QI (rotate:QI (const_int -2)
9121 (and:QI (match_operand:QI 1 "register_operand" "r")
9122 (const_int 7)))))]
9123 ""
9124 "#"
9125 "&& reload_completed"
9126 [(parallel [(set (match_dup 0)
9127 (rotate:QI (const_int 1)
9128 (match_dup 1)))
9129 (clobber (reg:CC REG_CC))])])
9130
9131 (define_insn_and_split "mask1_0xfe_split"
9132 [(set (match_operand:QI 0 "register_operand" "=&d")
9133 (rotate:QI (const_int -2)
9134 (and:QI (match_operand:QI 1 "register_operand" "r")
9135 (const_int 7))))]
9136 ""
9137 "#"
9138 "&& reload_completed"
9139 [(parallel [(set (match_dup 0)
9140 (rotate:QI (const_int -2)
9141 (match_dup 1)))
9142 (clobber (reg:CC REG_CC))])])
9143
9144 (define_insn "*mask1_0xfe"
9145 [(set (match_operand:QI 0 "register_operand" "=&d")
9146 (rotate:QI (const_int -2)
9147 (match_operand:QI 1 "register_operand" "r")))
9148 (clobber (reg:CC REG_CC))]
9149 "reload_completed"
9150 {
9151 return "ldi %0,0xfd" CR_TAB
9152 "sbrc %1,1" CR_TAB
9153 "ldi %0,0xf7" CR_TAB
9154 "sbrs %1,0" CR_TAB
9155 "asr %0" CR_TAB
9156 "sbrc %1,2" CR_TAB
9157 "swap %0";
9158 }
9159 [(set_attr "length" "7")])
9160
9161
9162 ;; __builtin_avr_flash_segment
9163
9164 ;; Just a helper for the next "official" expander.
9165
9166 (define_expand "flash_segment1"
9167 [(set (match_operand:QI 0 "register_operand" "")
9168 (subreg:QI (match_operand:PSI 1 "register_operand" "")
9169 2))
9170 (set (pc)
9171 (if_then_else (ge (match_dup 0)
9172 (const_int 0))
9173 (label_ref (match_operand 2 "" ""))
9174 (pc)))
9175 (set (match_dup 0)
9176 (const_int -1))])
9177
9178 (define_insn_and_split "*flash_segment1"
9179 [(set (pc)
9180 (if_then_else (ge (match_operand:QI 0 "register_operand" "")
9181 (const_int 0))
9182 (label_ref (match_operand 1 "" ""))
9183 (pc)))]
9184 ""
9185 "#"
9186 "reload_completed"
9187 [(set (reg:CC REG_CC)
9188 (compare:CC (match_dup 0) (const_int 0)))
9189 (set (pc)
9190 (if_then_else (ge (reg:CC REG_CC) (const_int 0))
9191 (label_ref (match_dup 1))
9192 (pc)))]
9193 "")
9194
9195 (define_expand "flash_segment"
9196 [(parallel [(match_operand:QI 0 "register_operand" "")
9197 (match_operand:PSI 1 "register_operand" "")])]
9198 ""
9199 {
9200 rtx label = gen_label_rtx ();
9201 emit (gen_flash_segment1 (operands[0], operands[1], label));
9202 emit_label (label);
9203 DONE;
9204 })
9205
9206 ;; Actually, it's too late now to work out address spaces known at compiletime.
9207 ;; Best place would be to fold ADDR_SPACE_CONVERT_EXPR in avr_fold_builtin.
9208 ;; However, avr_addr_space_convert can add some built-in knowledge for PSTR
9209 ;; so that ADDR_SPACE_CONVERT_EXPR in the built-in must not be resolved.
9210
9211 (define_insn_and_split "*split.flash_segment"
9212 [(set (match_operand:QI 0 "register_operand" "=d")
9213 (subreg:QI (lo_sum:PSI (match_operand:QI 1 "nonmemory_operand" "ri")
9214 (match_operand:HI 2 "register_operand" "r"))
9215 2))]
9216 ""
9217 { gcc_unreachable(); }
9218 ""
9219 [(set (match_dup 0)
9220 (match_dup 1))])
9221
9222
9223 ;; Parity
9224
9225 ;; Postpone expansion of 16-bit parity to libgcc call until after combine for
9226 ;; better 8-bit parity recognition.
9227
9228 (define_expand "parityhi2"
9229 [(parallel [(set (match_operand:HI 0 "register_operand" "")
9230 (parity:HI (match_operand:HI 1 "register_operand" "")))
9231 (clobber (reg:HI 24))])])
9232
9233 (define_insn_and_split "*parityhi2"
9234 [(set (match_operand:HI 0 "register_operand" "=r")
9235 (parity:HI (match_operand:HI 1 "register_operand" "r")))
9236 (clobber (reg:HI 24))]
9237 "!reload_completed"
9238 { gcc_unreachable(); }
9239 "&& 1"
9240 [(set (reg:HI 24)
9241 (match_dup 1))
9242 (set (reg:HI 24)
9243 (parity:HI (reg:HI 24)))
9244 (set (match_dup 0)
9245 (reg:HI 24))])
9246
9247 (define_insn_and_split "*parityqihi2.1"
9248 [(set (match_operand:HI 0 "register_operand" "=r")
9249 (zero_extend:HI
9250 (parity:QI (match_operand:QI 1 "register_operand" "r"))))
9251 (clobber (reg:HI 24))]
9252 "!reload_completed"
9253 { gcc_unreachable(); }
9254 "&& 1"
9255 [(set (reg:QI 24)
9256 (match_dup 1))
9257 (set (reg:HI 24)
9258 (zero_extend:HI (parity:QI (reg:QI 24))))
9259 (set (match_dup 0)
9260 (reg:HI 24))])
9261
9262 (define_insn_and_split "*parityqihi2.2"
9263 [(set (match_operand:HI 0 "register_operand" "=r")
9264 (parity:HI (match_operand:QI 1 "register_operand" "r")))
9265 (clobber (reg:HI 24))]
9266 "!reload_completed"
9267 { gcc_unreachable(); }
9268 "&& 1"
9269 [(set (reg:QI 24)
9270 (match_dup 1))
9271 (set (reg:HI 24)
9272 (zero_extend:HI (parity:QI (reg:QI 24))))
9273 (set (match_dup 0)
9274 (reg:HI 24))])
9275
9276 (define_expand "paritysi2"
9277 [(set (reg:SI 22)
9278 (match_operand:SI 1 "register_operand" ""))
9279 (set (reg:HI 24)
9280 (truncate:HI (parity:SI (reg:SI 22))))
9281 (set (match_dup 2)
9282 (reg:HI 24))
9283 (set (match_operand:SI 0 "register_operand" "")
9284 (zero_extend:SI (match_dup 2)))]
9285 ""
9286 {
9287 operands[2] = gen_reg_rtx (HImode);
9288 })
9289
9290 (define_insn_and_split "*parityhi2.libgcc_split"
9291 [(set (reg:HI 24)
9292 (parity:HI (reg:HI 24)))]
9293 ""
9294 "#"
9295 "&& reload_completed"
9296 [(parallel [(set (reg:HI 24)
9297 (parity:HI (reg:HI 24)))
9298 (clobber (reg:CC REG_CC))])])
9299
9300 (define_insn "*parityhi2.libgcc"
9301 [(set (reg:HI 24)
9302 (parity:HI (reg:HI 24)))
9303 (clobber (reg:CC REG_CC))]
9304 "reload_completed"
9305 "%~call __parityhi2"
9306 [(set_attr "type" "xcall")])
9307
9308 (define_insn_and_split "*parityqihi2.libgcc_split"
9309 [(set (reg:HI 24)
9310 (zero_extend:HI (parity:QI (reg:QI 24))))]
9311 ""
9312 "#"
9313 "&& reload_completed"
9314 [(parallel [(set (reg:HI 24)
9315 (zero_extend:HI (parity:QI (reg:QI 24))))
9316 (clobber (reg:CC REG_CC))])])
9317
9318 (define_insn "*parityqihi2.libgcc"
9319 [(set (reg:HI 24)
9320 (zero_extend:HI (parity:QI (reg:QI 24))))
9321 (clobber (reg:CC REG_CC))]
9322 "reload_completed"
9323 "%~call __parityqi2"
9324 [(set_attr "type" "xcall")])
9325
9326 (define_insn_and_split "*paritysihi2.libgcc_split"
9327 [(set (reg:HI 24)
9328 (truncate:HI (parity:SI (reg:SI 22))))]
9329 ""
9330 "#"
9331 "&& reload_completed"
9332 [(parallel [(set (reg:HI 24)
9333 (truncate:HI (parity:SI (reg:SI 22))))
9334 (clobber (reg:CC REG_CC))])])
9335
9336 (define_insn "*paritysihi2.libgcc"
9337 [(set (reg:HI 24)
9338 (truncate:HI (parity:SI (reg:SI 22))))
9339 (clobber (reg:CC REG_CC))]
9340 "reload_completed"
9341 "%~call __paritysi2"
9342 [(set_attr "type" "xcall")])
9343
9344
9345 ;; Popcount
9346
9347 (define_expand "popcounthi2"
9348 [(set (reg:HI 24)
9349 (match_operand:HI 1 "register_operand" ""))
9350 (set (reg:HI 24)
9351 (popcount:HI (reg:HI 24)))
9352 (set (match_operand:HI 0 "register_operand" "")
9353 (reg:HI 24))]
9354 ""
9355 "")
9356
9357 (define_expand "popcountsi2"
9358 [(set (reg:SI 22)
9359 (match_operand:SI 1 "register_operand" ""))
9360 (set (reg:HI 24)
9361 (truncate:HI (popcount:SI (reg:SI 22))))
9362 (set (match_dup 2)
9363 (reg:HI 24))
9364 (set (match_operand:SI 0 "register_operand" "")
9365 (zero_extend:SI (match_dup 2)))]
9366 ""
9367 {
9368 operands[2] = gen_reg_rtx (HImode);
9369 })
9370
9371 (define_insn_and_split "*popcounthi2.split8"
9372 [(set (reg:HI 24)
9373 (zero_extend:HI (popcount:QI (match_operand:QI 0 "register_operand"))))]
9374 "! reload_completed"
9375 { gcc_unreachable(); }
9376 "&& 1"
9377 [(set (reg:QI 24)
9378 (match_dup 0))
9379 (set (reg:QI 24)
9380 (popcount:QI (reg:QI 24)))
9381 (set (reg:QI 25)
9382 (const_int 0))])
9383
9384 (define_insn_and_split "*popcounthi2.libgcc_split"
9385 [(set (reg:HI 24)
9386 (popcount:HI (reg:HI 24)))]
9387 ""
9388 "#"
9389 "&& reload_completed"
9390 [(parallel [(set (reg:HI 24)
9391 (popcount:HI (reg:HI 24)))
9392 (clobber (reg:CC REG_CC))])])
9393
9394 (define_insn "*popcounthi2.libgcc"
9395 [(set (reg:HI 24)
9396 (popcount:HI (reg:HI 24)))
9397 (clobber (reg:CC REG_CC))]
9398 "reload_completed"
9399 "%~call __popcounthi2"
9400 [(set_attr "type" "xcall")])
9401
9402 (define_insn_and_split "*popcountsi2.libgcc_split"
9403 [(set (reg:HI 24)
9404 (truncate:HI (popcount:SI (reg:SI 22))))]
9405 ""
9406 "#"
9407 "&& reload_completed"
9408 [(parallel [(set (reg:HI 24)
9409 (truncate:HI (popcount:SI (reg:SI 22))))
9410 (clobber (reg:CC REG_CC))])])
9411
9412 (define_insn "*popcountsi2.libgcc"
9413 [(set (reg:HI 24)
9414 (truncate:HI (popcount:SI (reg:SI 22))))
9415 (clobber (reg:CC REG_CC))]
9416 "reload_completed"
9417 "%~call __popcountsi2"
9418 [(set_attr "type" "xcall")])
9419
9420 (define_insn_and_split "*popcountqi2.libgcc_split"
9421 [(set (reg:QI 24)
9422 (popcount:QI (reg:QI 24)))]
9423 ""
9424 "#"
9425 "&& reload_completed"
9426 [(parallel [(set (reg:QI 24)
9427 (popcount:QI (reg:QI 24)))
9428 (clobber (reg:CC REG_CC))])])
9429
9430 (define_insn "*popcountqi2.libgcc"
9431 [(set (reg:QI 24)
9432 (popcount:QI (reg:QI 24)))
9433 (clobber (reg:CC REG_CC))]
9434 "reload_completed"
9435 "%~call __popcountqi2"
9436 [(set_attr "type" "xcall")])
9437
9438 (define_insn_and_split "*popcountqihi2.libgcc"
9439 [(set (reg:HI 24)
9440 (zero_extend:HI (popcount:QI (reg:QI 24))))]
9441 ""
9442 "#"
9443 ""
9444 [(set (reg:QI 24)
9445 (popcount:QI (reg:QI 24)))
9446 (set (reg:QI 25)
9447 (const_int 0))])
9448
9449 ;; Count Leading Zeros
9450
9451 (define_expand "clzhi2"
9452 [(set (reg:HI 24)
9453 (match_operand:HI 1 "register_operand" ""))
9454 (parallel [(set (reg:HI 24)
9455 (clz:HI (reg:HI 24)))
9456 (clobber (reg:QI 26))])
9457 (set (match_operand:HI 0 "register_operand" "")
9458 (reg:HI 24))])
9459
9460 (define_expand "clzsi2"
9461 [(set (reg:SI 22)
9462 (match_operand:SI 1 "register_operand" ""))
9463 (parallel [(set (reg:HI 24)
9464 (truncate:HI (clz:SI (reg:SI 22))))
9465 (clobber (reg:QI 26))])
9466 (set (match_dup 2)
9467 (reg:HI 24))
9468 (set (match_operand:SI 0 "register_operand" "")
9469 (zero_extend:SI (match_dup 2)))]
9470 ""
9471 {
9472 operands[2] = gen_reg_rtx (HImode);
9473 })
9474
9475 (define_insn_and_split "*clzhi2.libgcc_split"
9476 [(set (reg:HI 24)
9477 (clz:HI (reg:HI 24)))
9478 (clobber (reg:QI 26))]
9479 ""
9480 "#"
9481 "&& reload_completed"
9482 [(parallel [(set (reg:HI 24)
9483 (clz:HI (reg:HI 24)))
9484 (clobber (reg:QI 26))
9485 (clobber (reg:CC REG_CC))])])
9486
9487 (define_insn "*clzhi2.libgcc"
9488 [(set (reg:HI 24)
9489 (clz:HI (reg:HI 24)))
9490 (clobber (reg:QI 26))
9491 (clobber (reg:CC REG_CC))]
9492 "reload_completed"
9493 "%~call __clzhi2"
9494 [(set_attr "type" "xcall")])
9495
9496 (define_insn_and_split "*clzsihi2.libgcc_split"
9497 [(set (reg:HI 24)
9498 (truncate:HI (clz:SI (reg:SI 22))))
9499 (clobber (reg:QI 26))]
9500 ""
9501 "#"
9502 "&& reload_completed"
9503 [(parallel [(set (reg:HI 24)
9504 (truncate:HI (clz:SI (reg:SI 22))))
9505 (clobber (reg:QI 26))
9506 (clobber (reg:CC REG_CC))])])
9507
9508 (define_insn "*clzsihi2.libgcc"
9509 [(set (reg:HI 24)
9510 (truncate:HI (clz:SI (reg:SI 22))))
9511 (clobber (reg:QI 26))
9512 (clobber (reg:CC REG_CC))]
9513 "reload_completed"
9514 "%~call __clzsi2"
9515 [(set_attr "type" "xcall")])
9516
9517 ;; Count Trailing Zeros
9518
9519 (define_expand "ctzhi2"
9520 [(set (reg:HI 24)
9521 (match_operand:HI 1 "register_operand" ""))
9522 (parallel [(set (reg:HI 24)
9523 (ctz:HI (reg:HI 24)))
9524 (clobber (reg:QI 26))])
9525 (set (match_operand:HI 0 "register_operand" "")
9526 (reg:HI 24))])
9527
9528 (define_expand "ctzsi2"
9529 [(set (reg:SI 22)
9530 (match_operand:SI 1 "register_operand" ""))
9531 (parallel [(set (reg:HI 24)
9532 (truncate:HI (ctz:SI (reg:SI 22))))
9533 (clobber (reg:QI 22))
9534 (clobber (reg:QI 26))])
9535 (set (match_dup 2)
9536 (reg:HI 24))
9537 (set (match_operand:SI 0 "register_operand" "")
9538 (zero_extend:SI (match_dup 2)))]
9539 ""
9540 {
9541 operands[2] = gen_reg_rtx (HImode);
9542 })
9543
9544 (define_insn_and_split "*ctzhi2.libgcc_split"
9545 [(set (reg:HI 24)
9546 (ctz:HI (reg:HI 24)))
9547 (clobber (reg:QI 26))]
9548 ""
9549 "#"
9550 "&& reload_completed"
9551 [(parallel [(set (reg:HI 24)
9552 (ctz:HI (reg:HI 24)))
9553 (clobber (reg:QI 26))
9554 (clobber (reg:CC REG_CC))])])
9555
9556 (define_insn "*ctzhi2.libgcc"
9557 [(set (reg:HI 24)
9558 (ctz:HI (reg:HI 24)))
9559 (clobber (reg:QI 26))
9560 (clobber (reg:CC REG_CC))]
9561 "reload_completed"
9562 "%~call __ctzhi2"
9563 [(set_attr "type" "xcall")])
9564
9565 (define_insn_and_split "*ctzsihi2.libgcc_split"
9566 [(set (reg:HI 24)
9567 (truncate:HI (ctz:SI (reg:SI 22))))
9568 (clobber (reg:QI 22))
9569 (clobber (reg:QI 26))]
9570 ""
9571 "#"
9572 "&& reload_completed"
9573 [(parallel [(set (reg:HI 24)
9574 (truncate:HI (ctz:SI (reg:SI 22))))
9575 (clobber (reg:QI 22))
9576 (clobber (reg:QI 26))
9577 (clobber (reg:CC REG_CC))])])
9578
9579 (define_insn "*ctzsihi2.libgcc"
9580 [(set (reg:HI 24)
9581 (truncate:HI (ctz:SI (reg:SI 22))))
9582 (clobber (reg:QI 22))
9583 (clobber (reg:QI 26))
9584 (clobber (reg:CC REG_CC))]
9585 "reload_completed"
9586 "%~call __ctzsi2"
9587 [(set_attr "type" "xcall")])
9588
9589 ;; Find First Set
9590
9591 (define_expand "ffshi2"
9592 [(set (reg:HI 24)
9593 (match_operand:HI 1 "register_operand" ""))
9594 (parallel [(set (reg:HI 24)
9595 (ffs:HI (reg:HI 24)))
9596 (clobber (reg:QI 26))])
9597 (set (match_operand:HI 0 "register_operand" "")
9598 (reg:HI 24))])
9599
9600 (define_expand "ffssi2"
9601 [(set (reg:SI 22)
9602 (match_operand:SI 1 "register_operand" ""))
9603 (parallel [(set (reg:HI 24)
9604 (truncate:HI (ffs:SI (reg:SI 22))))
9605 (clobber (reg:QI 22))
9606 (clobber (reg:QI 26))])
9607 (set (match_dup 2)
9608 (reg:HI 24))
9609 (set (match_operand:SI 0 "register_operand" "")
9610 (zero_extend:SI (match_dup 2)))]
9611 ""
9612 {
9613 operands[2] = gen_reg_rtx (HImode);
9614 })
9615
9616 (define_insn_and_split "*ffshi2.libgcc_split"
9617 [(set (reg:HI 24)
9618 (ffs:HI (reg:HI 24)))
9619 (clobber (reg:QI 26))]
9620 ""
9621 "#"
9622 "&& reload_completed"
9623 [(parallel [(set (reg:HI 24)
9624 (ffs:HI (reg:HI 24)))
9625 (clobber (reg:QI 26))
9626 (clobber (reg:CC REG_CC))])])
9627
9628 (define_insn "*ffshi2.libgcc"
9629 [(set (reg:HI 24)
9630 (ffs:HI (reg:HI 24)))
9631 (clobber (reg:QI 26))
9632 (clobber (reg:CC REG_CC))]
9633 "reload_completed"
9634 "%~call __ffshi2"
9635 [(set_attr "type" "xcall")])
9636
9637 (define_insn_and_split "*ffssihi2.libgcc_split"
9638 [(set (reg:HI 24)
9639 (truncate:HI (ffs:SI (reg:SI 22))))
9640 (clobber (reg:QI 22))
9641 (clobber (reg:QI 26))]
9642 ""
9643 "#"
9644 "&& reload_completed"
9645 [(parallel [(set (reg:HI 24)
9646 (truncate:HI (ffs:SI (reg:SI 22))))
9647 (clobber (reg:QI 22))
9648 (clobber (reg:QI 26))
9649 (clobber (reg:CC REG_CC))])])
9650
9651 (define_insn "*ffssihi2.libgcc"
9652 [(set (reg:HI 24)
9653 (truncate:HI (ffs:SI (reg:SI 22))))
9654 (clobber (reg:QI 22))
9655 (clobber (reg:QI 26))
9656 (clobber (reg:CC REG_CC))]
9657 "reload_completed"
9658 "%~call __ffssi2"
9659 [(set_attr "type" "xcall")])
9660
9661 ;; Copysign
9662
9663 (define_insn "copysignsf3"
9664 [(set (match_operand:SF 0 "register_operand" "=r")
9665 (copysign:SF (match_operand:SF 1 "register_operand" "0")
9666 (match_operand:SF 2 "nonmemory_operand" "rF")))]
9667 ""
9668 {
9669 if (const_double_operand (operands[2], SFmode))
9670 {
9671 rtx xmsb = simplify_gen_subreg (QImode, operands[2], SFmode, 3);
9672 return INTVAL (xmsb) < 0 ? "set\;bld %D0,7" : "clt\;bld %D0,7";
9673 }
9674 return "bst %D2,7\;bld %D0,7";
9675 }
9676 [(set_attr "length" "2")])
9677
9678 ;; Swap Bytes (change byte-endianness)
9679
9680 (define_expand "bswapsi2"
9681 [(set (reg:SI 22)
9682 (match_operand:SI 1 "register_operand" ""))
9683 (set (reg:SI 22)
9684 (bswap:SI (reg:SI 22)))
9685 (set (match_operand:SI 0 "register_operand" "")
9686 (reg:SI 22))])
9687
9688 (define_insn_and_split "*bswapsi2.libgcc_split"
9689 [(set (reg:SI 22)
9690 (bswap:SI (reg:SI 22)))]
9691 ""
9692 "#"
9693 "&& reload_completed"
9694 [(parallel [(set (reg:SI 22)
9695 (bswap:SI (reg:SI 22)))
9696 (clobber (reg:CC REG_CC))])])
9697
9698 (define_insn "*bswapsi2.libgcc"
9699 [(set (reg:SI 22)
9700 (bswap:SI (reg:SI 22)))
9701 (clobber (reg:CC REG_CC))]
9702 "reload_completed"
9703 "%~call __bswapsi2"
9704 [(set_attr "type" "xcall")])
9705
9706
9707 ;; CPU instructions
9708
9709 ;; NOP taking 1 or 2 Ticks
9710 (define_expand "nopv"
9711 [(parallel [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "")]
9712 UNSPECV_NOP)
9713 (set (match_dup 1)
9714 (unspec_volatile:BLK [(match_dup 1)]
9715 UNSPECV_MEMORY_BARRIER))])]
9716 ""
9717 {
9718 operands[1] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
9719 MEM_VOLATILE_P (operands[1]) = 1;
9720 })
9721
9722 (define_insn "*nopv"
9723 [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "P,K")]
9724 UNSPECV_NOP)
9725 (set (match_operand:BLK 1 "" "")
9726 (unspec_volatile:BLK [(match_dup 1)] UNSPECV_MEMORY_BARRIER))]
9727 ""
9728 "@
9729 nop
9730 rjmp ."
9731 [(set_attr "length" "1")])
9732
9733 ;; SLEEP
9734 (define_expand "sleep"
9735 [(parallel [(unspec_volatile [(const_int 0)] UNSPECV_SLEEP)
9736 (set (match_dup 0)
9737 (unspec_volatile:BLK [(match_dup 0)]
9738 UNSPECV_MEMORY_BARRIER))])]
9739 ""
9740 {
9741 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
9742 MEM_VOLATILE_P (operands[0]) = 1;
9743 })
9744
9745 (define_insn "*sleep"
9746 [(unspec_volatile [(const_int 0)] UNSPECV_SLEEP)
9747 (set (match_operand:BLK 0 "" "")
9748 (unspec_volatile:BLK [(match_dup 0)] UNSPECV_MEMORY_BARRIER))]
9749 ""
9750 "sleep"
9751 [(set_attr "length" "1")])
9752
9753 ;; WDR
9754 (define_expand "wdr"
9755 [(parallel [(unspec_volatile [(const_int 0)] UNSPECV_WDR)
9756 (set (match_dup 0)
9757 (unspec_volatile:BLK [(match_dup 0)]
9758 UNSPECV_MEMORY_BARRIER))])]
9759 ""
9760 {
9761 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
9762 MEM_VOLATILE_P (operands[0]) = 1;
9763 })
9764
9765 (define_insn "*wdr"
9766 [(unspec_volatile [(const_int 0)] UNSPECV_WDR)
9767 (set (match_operand:BLK 0 "" "")
9768 (unspec_volatile:BLK [(match_dup 0)] UNSPECV_MEMORY_BARRIER))]
9769 ""
9770 "wdr"
9771 [(set_attr "length" "1")])
9772
9773 ;; FMUL
9774 (define_expand "fmul"
9775 [(set (reg:QI 24)
9776 (match_operand:QI 1 "register_operand" ""))
9777 (set (reg:QI 25)
9778 (match_operand:QI 2 "register_operand" ""))
9779 (parallel [(set (reg:HI 22)
9780 (unspec:HI [(reg:QI 24)
9781 (reg:QI 25)] UNSPEC_FMUL))
9782 (clobber (reg:HI 24))])
9783 (set (match_operand:HI 0 "register_operand" "")
9784 (reg:HI 22))]
9785 ""
9786 {
9787 if (AVR_HAVE_MUL)
9788 {
9789 emit_insn (gen_fmul_insn (operand0, operand1, operand2));
9790 DONE;
9791 }
9792 avr_fix_inputs (operands, 1 << 2, regmask (QImode, 24));
9793 })
9794
9795 (define_insn_and_split "fmul_insn"
9796 [(set (match_operand:HI 0 "register_operand" "=r")
9797 (unspec:HI [(match_operand:QI 1 "register_operand" "a")
9798 (match_operand:QI 2 "register_operand" "a")]
9799 UNSPEC_FMUL))]
9800 "AVR_HAVE_MUL"
9801 "#"
9802 "&& reload_completed"
9803 [(parallel [(set (match_dup 0)
9804 (unspec:HI [(match_dup 1)
9805 (match_dup 2)]
9806 UNSPEC_FMUL))
9807 (clobber (reg:CC REG_CC))])])
9808
9809 (define_insn "*fmul_insn"
9810 [(set (match_operand:HI 0 "register_operand" "=r")
9811 (unspec:HI [(match_operand:QI 1 "register_operand" "a")
9812 (match_operand:QI 2 "register_operand" "a")]
9813 UNSPEC_FMUL))
9814 (clobber (reg:CC REG_CC))]
9815 "AVR_HAVE_MUL && reload_completed"
9816 "fmul %1,%2
9817 movw %0,r0
9818 clr __zero_reg__"
9819 [(set_attr "length" "3")])
9820
9821 (define_insn_and_split "*fmul.call_split"
9822 [(set (reg:HI 22)
9823 (unspec:HI [(reg:QI 24)
9824 (reg:QI 25)] UNSPEC_FMUL))
9825 (clobber (reg:HI 24))]
9826 "!AVR_HAVE_MUL"
9827 "#"
9828 "&& reload_completed"
9829 [(parallel [(set (reg:HI 22)
9830 (unspec:HI [(reg:QI 24)
9831 (reg:QI 25)] UNSPEC_FMUL))
9832 (clobber (reg:HI 24))
9833 (clobber (reg:CC REG_CC))])])
9834
9835 (define_insn "*fmul.call"
9836 [(set (reg:HI 22)
9837 (unspec:HI [(reg:QI 24)
9838 (reg:QI 25)] UNSPEC_FMUL))
9839 (clobber (reg:HI 24))
9840 (clobber (reg:CC REG_CC))]
9841 "!AVR_HAVE_MUL && reload_completed"
9842 "%~call __fmul"
9843 [(set_attr "type" "xcall")])
9844
9845 ;; FMULS
9846 (define_expand "fmuls"
9847 [(set (reg:QI 24)
9848 (match_operand:QI 1 "register_operand" ""))
9849 (set (reg:QI 25)
9850 (match_operand:QI 2 "register_operand" ""))
9851 (parallel [(set (reg:HI 22)
9852 (unspec:HI [(reg:QI 24)
9853 (reg:QI 25)] UNSPEC_FMULS))
9854 (clobber (reg:HI 24))])
9855 (set (match_operand:HI 0 "register_operand" "")
9856 (reg:HI 22))]
9857 ""
9858 {
9859 if (AVR_HAVE_MUL)
9860 {
9861 emit_insn (gen_fmuls_insn (operand0, operand1, operand2));
9862 DONE;
9863 }
9864 avr_fix_inputs (operands, 1 << 2, regmask (QImode, 24));
9865 })
9866
9867 (define_insn_and_split "fmuls_insn"
9868 [(set (match_operand:HI 0 "register_operand" "=r")
9869 (unspec:HI [(match_operand:QI 1 "register_operand" "a")
9870 (match_operand:QI 2 "register_operand" "a")]
9871 UNSPEC_FMULS))]
9872 "AVR_HAVE_MUL"
9873 "#"
9874 "&& reload_completed"
9875 [(parallel [(set (match_dup 0)
9876 (unspec:HI [(match_dup 1)
9877 (match_dup 2)]
9878 UNSPEC_FMULS))
9879 (clobber (reg:CC REG_CC))])])
9880
9881 (define_insn "*fmuls_insn"
9882 [(set (match_operand:HI 0 "register_operand" "=r")
9883 (unspec:HI [(match_operand:QI 1 "register_operand" "a")
9884 (match_operand:QI 2 "register_operand" "a")]
9885 UNSPEC_FMULS))
9886 (clobber (reg:CC REG_CC))]
9887 "AVR_HAVE_MUL && reload_completed"
9888 "fmuls %1,%2
9889 movw %0,r0
9890 clr __zero_reg__"
9891 [(set_attr "length" "3")])
9892
9893 (define_insn_and_split "*fmuls.call_split"
9894 [(set (reg:HI 22)
9895 (unspec:HI [(reg:QI 24)
9896 (reg:QI 25)] UNSPEC_FMULS))
9897 (clobber (reg:HI 24))]
9898 "!AVR_HAVE_MUL"
9899 "#"
9900 "&& reload_completed"
9901 [(parallel [(set (reg:HI 22)
9902 (unspec:HI [(reg:QI 24)
9903 (reg:QI 25)] UNSPEC_FMULS))
9904 (clobber (reg:HI 24))
9905 (clobber (reg:CC REG_CC))])])
9906
9907 (define_insn "*fmuls.call"
9908 [(set (reg:HI 22)
9909 (unspec:HI [(reg:QI 24)
9910 (reg:QI 25)] UNSPEC_FMULS))
9911 (clobber (reg:HI 24))
9912 (clobber (reg:CC REG_CC))]
9913 "!AVR_HAVE_MUL && reload_completed"
9914 "%~call __fmuls"
9915 [(set_attr "type" "xcall")])
9916
9917 ;; FMULSU
9918 (define_expand "fmulsu"
9919 [(set (reg:QI 24)
9920 (match_operand:QI 1 "register_operand" ""))
9921 (set (reg:QI 25)
9922 (match_operand:QI 2 "register_operand" ""))
9923 (parallel [(set (reg:HI 22)
9924 (unspec:HI [(reg:QI 24)
9925 (reg:QI 25)] UNSPEC_FMULSU))
9926 (clobber (reg:HI 24))])
9927 (set (match_operand:HI 0 "register_operand" "")
9928 (reg:HI 22))]
9929 ""
9930 {
9931 if (AVR_HAVE_MUL)
9932 {
9933 emit_insn (gen_fmulsu_insn (operand0, operand1, operand2));
9934 DONE;
9935 }
9936 avr_fix_inputs (operands, 1 << 2, regmask (QImode, 24));
9937 })
9938
9939 (define_insn_and_split "fmulsu_insn"
9940 [(set (match_operand:HI 0 "register_operand" "=r")
9941 (unspec:HI [(match_operand:QI 1 "register_operand" "a")
9942 (match_operand:QI 2 "register_operand" "a")]
9943 UNSPEC_FMULSU))]
9944 "AVR_HAVE_MUL"
9945 "#"
9946 "&& reload_completed"
9947 [(parallel [(set (match_dup 0)
9948 (unspec:HI [(match_dup 1)
9949 (match_dup 2)]
9950 UNSPEC_FMULSU))
9951 (clobber (reg:CC REG_CC))])])
9952
9953 (define_insn "*fmulsu_insn"
9954 [(set (match_operand:HI 0 "register_operand" "=r")
9955 (unspec:HI [(match_operand:QI 1 "register_operand" "a")
9956 (match_operand:QI 2 "register_operand" "a")]
9957 UNSPEC_FMULSU))
9958 (clobber (reg:CC REG_CC))]
9959 "AVR_HAVE_MUL && reload_completed"
9960 "fmulsu %1,%2
9961 movw %0,r0
9962 clr __zero_reg__"
9963 [(set_attr "length" "3")])
9964
9965 (define_insn_and_split "*fmulsu.call_split"
9966 [(set (reg:HI 22)
9967 (unspec:HI [(reg:QI 24)
9968 (reg:QI 25)] UNSPEC_FMULSU))
9969 (clobber (reg:HI 24))]
9970 "!AVR_HAVE_MUL"
9971 "#"
9972 "&& reload_completed"
9973 [(parallel [(set (reg:HI 22)
9974 (unspec:HI [(reg:QI 24)
9975 (reg:QI 25)] UNSPEC_FMULSU))
9976 (clobber (reg:HI 24))
9977 (clobber (reg:CC REG_CC))])])
9978
9979 (define_insn "*fmulsu.call"
9980 [(set (reg:HI 22)
9981 (unspec:HI [(reg:QI 24)
9982 (reg:QI 25)] UNSPEC_FMULSU))
9983 (clobber (reg:HI 24))
9984 (clobber (reg:CC REG_CC))]
9985 "!AVR_HAVE_MUL && reload_completed"
9986 "%~call __fmulsu"
9987 [(set_attr "type" "xcall")
9988 ])
9989
9990
9991 ;; Some combiner patterns dealing with bits.
9992 ;; See PR42210
9993
9994 ;; Move bit $3.0 into bit $0.$4
9995 (define_insn "*movbitqi.1-6.a"
9996 [(set (match_operand:QI 0 "register_operand" "=r")
9997 (ior:QI (and:QI (match_operand:QI 1 "register_operand" "0")
9998 (match_operand:QI 2 "single_zero_operand" "n"))
9999 (and:QI (ashift:QI (match_operand:QI 3 "register_operand" "r")
10000 (match_operand:QI 4 "const_0_to_7_operand" "n"))
10001 (match_operand:QI 5 "single_one_operand" "n"))))]
10002 "INTVAL (operands[4]) == exact_log2 (~INTVAL (operands[2]) & 0xff)
10003 && INTVAL (operands[4]) == exact_log2 (INTVAL (operands[5]) & 0xff)"
10004 "bst %3,0\;bld %0,%4"
10005 [(set_attr "length" "2")])
10006
10007 ;; Move bit $3.0 into bit $0.$4
10008 ;; Variation of above. Unfortunately, there is no canonicalized representation
10009 ;; of moving around bits. So what we see here depends on how user writes down
10010 ;; bit manipulations.
10011 (define_insn "*movbitqi.1-6.b"
10012 [(set (match_operand:QI 0 "register_operand" "=r")
10013 (ior:QI (and:QI (match_operand:QI 1 "register_operand" "0")
10014 (match_operand:QI 2 "single_zero_operand" "n"))
10015 (ashift:QI (and:QI (match_operand:QI 3 "register_operand" "r")
10016 (const_int 1))
10017 (match_operand:QI 4 "const_0_to_7_operand" "n"))))]
10018 "INTVAL (operands[4]) == exact_log2 (~INTVAL (operands[2]) & 0xff)"
10019 "bst %3,0\;bld %0,%4"
10020 [(set_attr "length" "2")])
10021
10022 ;; Move bit $3.x into bit $0.x.
10023 (define_insn "*movbit<mode>.0-6"
10024 [(set (match_operand:QISI 0 "register_operand" "=r")
10025 (ior:QISI (and:QISI (match_operand:QISI 1 "register_operand" "0")
10026 (match_operand:QISI 2 "single_zero_operand" "n"))
10027 (and:QISI (match_operand:QISI 3 "register_operand" "r")
10028 (match_operand:QISI 4 "single_one_operand" "n"))))]
10029 "GET_MODE_MASK(<MODE>mode)
10030 == (GET_MODE_MASK(<MODE>mode) & (INTVAL(operands[2]) ^ INTVAL(operands[4])))"
10031 {
10032 auto bitmask = GET_MODE_MASK (<MODE>mode) & UINTVAL (operands[4]);
10033 operands[4] = GEN_INT (exact_log2 (bitmask));
10034 return "bst %T3%T4" CR_TAB "bld %T0%T4";
10035 }
10036 [(set_attr "length" "2")])
10037
10038 ;; Move bit $2.0 into bit $0.7.
10039 ;; For bit 7, combiner generates slightly different pattern
10040 (define_insn "*movbitqi.7"
10041 [(set (match_operand:QI 0 "register_operand" "=r")
10042 (ior:QI (and:QI (match_operand:QI 1 "register_operand" "0")
10043 (const_int 127))
10044 (ashift:QI (match_operand:QI 2 "register_operand" "r")
10045 (const_int 7))))]
10046 ""
10047 "bst %2,0\;bld %0,7"
10048 [(set_attr "length" "2")])
10049
10050 ;; Combiner transforms above four pattern into ZERO_EXTRACT if it sees MEM
10051 ;; and input/output match. We provide a special pattern for this, because
10052 ;; in contrast to a IN/BST/BLD/OUT sequence we need less registers and the
10053 ;; operation on I/O is atomic.
10054 (define_insn "*insv.io"
10055 [(set (zero_extract:QI (mem:QI (match_operand 0 "low_io_address_operand" "i,i,i"))
10056 (const_int 1)
10057 (match_operand:QI 1 "const_0_to_7_operand" "n,n,n"))
10058 (match_operand:QI 2 "nonmemory_operand" "L,P,r"))]
10059 ""
10060 "@
10061 cbi %i0,%1
10062 sbi %i0,%1
10063 sbrc %2,0\;sbi %i0,%1\;sbrs %2,0\;cbi %i0,%1"
10064 [(set_attr "length" "1,1,4")])
10065
10066 (define_insn "*insv.not.io"
10067 [(set (zero_extract:QI (mem:QI (match_operand 0 "low_io_address_operand" "i"))
10068 (const_int 1)
10069 (match_operand:QI 1 "const_0_to_7_operand" "n"))
10070 (not:QI (match_operand:QI 2 "register_operand" "r")))]
10071 ""
10072 "sbrs %2,0\;sbi %i0,%1\;sbrc %2,0\;cbi %i0,%1"
10073 [(set_attr "length" "4")])
10074
10075 ;; The insv expander.
10076 ;; We only support 1-bit inserts
10077 (define_expand "insv"
10078 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "")
10079 (match_operand:QI 1 "const1_operand" "") ; width
10080 (match_operand:QI 2 "const_0_to_7_operand" "")) ; pos
10081 (match_operand:QI 3 "nonmemory_operand" ""))]
10082 "optimize")
10083
10084 ;; Some more patterns to support moving around one bit which can be accomplished
10085 ;; by BST + BLD in most situations. Unfortunately, there is no canonical
10086 ;; representation, and we just implement some more cases that are not too
10087 ;; complicated.
10088
10089 ;; Insert bit $2.0 into $0.$1
10090 (define_insn_and_split "*insv.reg_split"
10091 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "+r,d,d,l,l")
10092 (const_int 1)
10093 (match_operand:QI 1 "const_0_to_7_operand" "n,n,n,n,n"))
10094 (match_operand:QI 2 "nonmemory_operand" "r,L,P,L,P"))]
10095 ""
10096 "#"
10097 "&& reload_completed"
10098 [(parallel [(set (zero_extract:QI (match_dup 0)
10099 (const_int 1)
10100 (match_dup 1))
10101 (match_dup 2))
10102 (clobber (reg:CC REG_CC))])])
10103
10104 (define_insn "*insv.reg"
10105 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "+r,d,d,l,l")
10106 (const_int 1)
10107 (match_operand:QI 1 "const_0_to_7_operand" "n,n,n,n,n"))
10108 (match_operand:QI 2 "nonmemory_operand" "r,L,P,L,P"))
10109 (clobber (reg:CC REG_CC))]
10110 "reload_completed"
10111 "@
10112 bst %2,0\;bld %0,%1
10113 andi %0,lo8(~(1<<%1))
10114 ori %0,lo8(1<<%1)
10115 clt\;bld %0,%1
10116 set\;bld %0,%1"
10117 [(set_attr "length" "2,1,1,2,2")])
10118
10119 ;; Insert bit $2.$3 into $0.$1
10120 (define_insn "*insv.extract"
10121 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "+r")
10122 (const_int 1)
10123 (match_operand:QI 1 "const_0_to_7_operand" "n"))
10124 (any_extract:QI (match_operand:QI 2 "register_operand" "r")
10125 (const_int 1)
10126 (match_operand:QI 3 "const_0_to_7_operand" "n")))]
10127 ""
10128 "bst %2,%3\;bld %0,%1"
10129 [(set_attr "length" "2")])
10130
10131 ;; Insert bit $2.$3 into $0.$1
10132 (define_insn "*insv.shiftrt"
10133 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "+r")
10134 (const_int 1)
10135 (match_operand:QI 1 "const_0_to_7_operand" "n"))
10136 (any_shiftrt:QI (match_operand:QI 2 "register_operand" "r")
10137 (match_operand:QI 3 "const_0_to_7_operand" "n")))]
10138 ""
10139 "bst %2,%3\;bld %0,%1"
10140 [(set_attr "length" "2")])
10141
10142 ;; Same, but with a NOT inverting the source bit.
10143 ;; Insert bit ~$2.$3 into $0.$1
10144 (define_insn "insv_notbit"
10145 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "+r")
10146 (const_int 1)
10147 (match_operand:QI 1 "const_0_to_7_operand" "n"))
10148 (not:QI (zero_extract:QI (match_operand:QI 2 "register_operand" "r")
10149 (const_int 1)
10150 (match_operand:QI 3 "const_0_to_7_operand" "n"))))
10151 (clobber (reg:CC REG_CC))]
10152 "reload_completed"
10153 {
10154 return avr_out_insert_notbit (insn, operands, NULL);
10155 }
10156 [(set_attr "adjust_len" "insv_notbit")])
10157
10158 ;; Insert bit ~$2.$3 into $0.$1
10159 (define_insn_and_split "*insv.not-shiftrt_split"
10160 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "+r")
10161 (const_int 1)
10162 (match_operand:QI 1 "const_0_to_7_operand" "n"))
10163 (not:QI (any_shiftrt:QI (match_operand:QI 2 "register_operand" "r")
10164 (match_operand:QI 3 "const_0_to_7_operand" "n"))))]
10165 ""
10166 "#"
10167 "&& reload_completed"
10168 [(scratch)]
10169 {
10170 emit (gen_insv_notbit (operands[0], operands[1], operands[2], operands[3]));
10171 DONE;
10172 })
10173
10174 ;; Insert bit ~$2.0 into $0.$1
10175 (define_insn_and_split "*insv.xor1-bit.0_split"
10176 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "+r")
10177 (const_int 1)
10178 (match_operand:QI 1 "const_0_to_7_operand" "n"))
10179 (xor:QI (match_operand:QI 2 "register_operand" "r")
10180 (const_int 1)))]
10181 ""
10182 "#"
10183 "&& reload_completed"
10184 [(scratch)]
10185 {
10186 emit (gen_insv_notbit (operands[0], operands[1], operands[2], const0_rtx));
10187 DONE;
10188 })
10189
10190 ;; Insert bit ~$2.0 into $0.$1
10191 (define_insn_and_split "*insv.not-bit.0_split"
10192 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "+r")
10193 (const_int 1)
10194 (match_operand:QI 1 "const_0_to_7_operand" "n"))
10195 (not:QI (match_operand:QI 2 "register_operand" "r")))]
10196 ""
10197 "#"
10198 "&& reload_completed"
10199 [(scratch)]
10200 {
10201 emit (gen_insv_notbit (operands[0], operands[1], operands[2], const0_rtx));
10202 DONE;
10203 })
10204
10205 ;; Insert bit ~$2.7 into $0.$1
10206 (define_insn_and_split "*insv.not-bit.7_split"
10207 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "+r")
10208 (const_int 1)
10209 (match_operand:QI 1 "const_0_to_7_operand" "n"))
10210 (ge:QI (match_operand:QI 2 "register_operand" "r")
10211 (const_int 0)))]
10212 ""
10213 "#"
10214 "&& reload_completed"
10215 [(scratch)]
10216 {
10217 emit (gen_insv_notbit (operands[0], operands[1], operands[2], GEN_INT(7)));
10218 DONE;
10219 })
10220
10221 ;; Insert bit ~$2.$3 into $0.$1
10222 (define_insn_and_split "*insv.xor-extract_split"
10223 [(set (zero_extract:QI (match_operand:QI 0 "register_operand" "+r")
10224 (const_int 1)
10225 (match_operand:QI 1 "const_0_to_7_operand" "n"))
10226 (any_extract:QI (xor:QI (match_operand:QI 2 "register_operand" "r")
10227 (match_operand:QI 4 "const_int_operand" "n"))
10228 (const_int 1)
10229 (match_operand:QI 3 "const_0_to_7_operand" "n")))]
10230 "INTVAL (operands[4]) & (1 << INTVAL (operands[3]))"
10231 "#"
10232 "&& reload_completed"
10233 [(scratch)]
10234 {
10235 emit (gen_insv_notbit (operands[0], operands[1], operands[2], operands[3]));
10236 DONE;
10237 })
10238
10239
10240 ;; "*iorsi.ashift" "*iorpsi.ashift" "*iorhi.ashift"
10241 ;; "*xorsi.ashift" "*xorpsi.ashift" "*xorhi.ashift"
10242 ;; "*iorsi.lshiftrt" "*iorpsi.lshiftrt" "*iorhi.lshiftrt"
10243 ;; "*xorsi.lshiftrt" "*xorpsi.lshiftrt" "*xorhi.lshiftrt"
10244 (define_insn_and_split "*<xior:code><mode>.<any_lshift:code>"
10245 [(set (match_operand:HISI 0 "register_operand" "=r")
10246 (xior:HISI (any_lshift:HISI (match_operand:HISI 1 "register_operand" "r")
10247 (match_operand:QI 3 "const_8_16_24_operand" "n"))
10248 (match_operand:HISI 2 "register_operand" "0")))]
10249 "INTVAL (operands[3]) <= <MSB>"
10250 "#"
10251 "&& reload_completed"
10252 [(scratch)]
10253 {
10254 avr_emit_xior_with_shift (curr_insn, operands, INTVAL (operands[3]));
10255 DONE;
10256 })
10257
10258 ;; Some combine patterns that try to fix bad code when a value is composed
10259 ;; from byte parts like in PR27663.
10260 ;; The patterns give some release but the code still is not optimal,
10261 ;; in particular when subreg lowering (-fsplit-wide-types) is turned on.
10262 ;; That switch obfuscates things here and in many other places.
10263
10264 ;; "*iorsiqi.0" "*iorpsiqi.0" "*iorhiqi.0"
10265 ;; "*iorsihi.0" "*iorpsihi.0" "*iorsipsi.0"
10266 ;; "*xorsiqi.0" "*xorpsiqi.0" "*xorhiqi.0"
10267 ;; "*xorsihi.0" "*xorpsihi.0" "*xorsipsi.0"
10268 (define_insn_and_split "*<code><HISI:mode><QIPSI:mode>.0"
10269 [(set (match_operand:HISI 0 "register_operand" "=r")
10270 (xior:HISI (zero_extend:HISI (match_operand:QIPSI 1 "register_operand" "r"))
10271 (match_operand:HISI 2 "register_operand" "0")))]
10272 "<HISI:SIZE> > <QIPSI:SIZE>"
10273 "#"
10274 "&& reload_completed"
10275 [(scratch)]
10276 {
10277 avr_emit_xior_with_shift (curr_insn, operands, 0);
10278 DONE;
10279 })
10280
10281
10282 ;; "*iorsiqi.ashift" "*iorpsiqi.ashift" "*iorhiqi.ashift"
10283 ;; "*iorsihi.ashift" "*iorpsihi.ashift" "*iorsipsi.ashift"
10284 ;; "*xorsiqi.ashift" "*xorpsiqi.ashift" "*xorhiqi.ashift"
10285 ;; "*xorsihi.ashift" "*xorpsihi.ashift" "*xorsipsi.ashift"
10286 ;; "*iorsiqi.lshiftrt" "*iorpsiqi.lshiftrt" "*iorhiqi.lshiftrt"
10287 ;; "*iorsihi.lshiftrt" "*iorpsihi.lshiftrt" "*iorsipsi.lshiftrt"
10288 ;; "*xorsiqi.lshiftrt" "*xorpsiqi.lshiftrt" "*xorhiqi.lshiftrt"
10289 ;; "*xorsihi.lshiftrt" "*xorpsihi.lshiftrt" "*xorsipsi.lshiftrt"
10290 (define_insn_and_split "*<xior:code><HISI:mode><QIPSI:mode>.<any_lshift:code>"
10291 [(set (match_operand:HISI 0 "register_operand" "=r")
10292 (xior:HISI (any_lshift:HISI (zero_extend:HISI (match_operand:QIPSI 1 "register_operand" "r"))
10293 (match_operand:QI 3 "const_8_16_24_operand" "n"))
10294 (match_operand:HISI 2 "register_operand" "0")))]
10295 "<HISI:SIZE> > <QIPSI:SIZE>
10296 && INTVAL (operands[3]) <= <HISI:MSB>"
10297 "#"
10298 "&& reload_completed"
10299 [(scratch)]
10300 {
10301 avr_emit_xior_with_shift (curr_insn, operands, INTVAL (operands[3]));
10302 DONE;
10303 })
10304
10305
10306 (define_insn_and_split "*iorhi3.ashift8-ext.zerox"
10307 [(set (match_operand:HI 0 "register_operand" "=r,r")
10308 (ior:HI (ashift:HI (any_extend:HI
10309 (match_operand:QI 1 "register_operand" "r,r"))
10310 (const_int 8))
10311 (zero_extend:HI (match_operand:QI 2 "register_operand" "0,r"))))]
10312 "optimize"
10313 { gcc_unreachable(); }
10314 "&& reload_completed"
10315 [(set (match_dup 1) (xor:QI (match_dup 1) (match_dup 2)))
10316 (set (match_dup 2) (xor:QI (match_dup 2) (match_dup 1)))
10317 (set (match_dup 1) (xor:QI (match_dup 1) (match_dup 2)))]
10318 {
10319 rtx hi = simplify_gen_subreg (QImode, operands[0], HImode, 1);
10320 rtx lo = simplify_gen_subreg (QImode, operands[0], HImode, 0);
10321
10322 if (!reg_overlap_mentioned_p (hi, operands[2]))
10323 {
10324 emit_move_insn (hi, operands[1]);
10325 emit_move_insn (lo, operands[2]);
10326 DONE;
10327 }
10328 else if (!reg_overlap_mentioned_p (lo, operands[1]))
10329 {
10330 emit_move_insn (lo, operands[2]);
10331 emit_move_insn (hi, operands[1]);
10332 DONE;
10333 }
10334
10335 gcc_assert (REGNO (operands[1]) == REGNO (operands[0]));
10336 gcc_assert (REGNO (operands[2]) == 1 + REGNO (operands[0]));
10337 })
10338
10339 (define_insn_and_split "*iorhi3.ashift8-ext.reg"
10340 [(set (match_operand:HI 0 "register_operand" "=r")
10341 (ior:HI (ashift:HI (any_extend:HI
10342 (match_operand:QI 1 "register_operand" "r"))
10343 (const_int 8))
10344 (match_operand:HI 2 "register_operand" "0")))]
10345 "optimize"
10346 { gcc_unreachable(); }
10347 "&& reload_completed"
10348 [(set (match_dup 3)
10349 (ior:QI (match_dup 4)
10350 (match_dup 1)))]
10351 {
10352 operands[3] = simplify_gen_subreg (QImode, operands[0], HImode, 1);
10353 operands[4] = simplify_gen_subreg (QImode, operands[2], HImode, 1);
10354 })
10355
10356 (define_insn_and_split "*iorhi3.ashift8-reg.zerox"
10357 [(set (match_operand:HI 0 "register_operand" "=r")
10358 (ior:HI (ashift:HI (match_operand:HI 1 "register_operand" "r")
10359 (const_int 8))
10360 (zero_extend:HI (match_operand:QI 2 "register_operand" "0"))))]
10361 "optimize"
10362 { gcc_unreachable(); }
10363 "&& reload_completed"
10364 [(set (match_dup 3)
10365 (match_dup 4))]
10366 {
10367 operands[3] = simplify_gen_subreg (QImode, operands[0], HImode, 1);
10368 operands[4] = simplify_gen_subreg (QImode, operands[1], HImode, 0);
10369 })
10370
10371
10372 (define_peephole2
10373 [(parallel [(set (match_operand:QI 0 "register_operand")
10374 (const_int 0))
10375 (clobber (reg:CC REG_CC))])
10376 (parallel [(set (match_dup 0)
10377 (ior:QI (match_dup 0)
10378 (match_operand:QI 1 "register_operand")))
10379 (clobber (reg:CC REG_CC))])]
10380 ""
10381 [(parallel [(set (match_dup 0)
10382 (match_dup 1))
10383 (clobber (reg:CC REG_CC))])])
10384
10385
10386 ;; Swapping both comparison and branch condition. This can turn difficult
10387 ;; branches to easy ones. And in some cases, a comparison against one can
10388 ;; be turned into a comparison against zero.
10389
10390 (define_peephole2 ; "*swapped_tst<mode>"
10391 [(parallel [(set (reg:CC REG_CC)
10392 (compare:CC (match_operand:ALLs234 1 "register_operand")
10393 (match_operand:ALLs234 2 "const_operand")))
10394 (clobber (match_operand:QI 3 "scratch_operand"))])
10395 (set (pc)
10396 (if_then_else (match_operator 0 "ordered_comparison_operator"
10397 [(reg:CC REG_CC)
10398 (const_int 0)])
10399 (label_ref (match_operand 4))
10400 (pc)))]
10401 "peep2_regno_dead_p (2, REG_CC)"
10402 [(set (reg:CC REG_CC)
10403 (compare:CC (match_dup 2)
10404 (match_dup 1)))
10405 ; "branch"
10406 (set (pc)
10407 (if_then_else (match_op_dup 0 [(reg:CC REG_CC)
10408 (const_int 0)])
10409 (label_ref (match_dup 4))
10410 (pc)))]
10411 {
10412 rtx xval = avr_to_int_mode (operands[2]);
10413 rtx_code code = GET_CODE (operands[0]);
10414
10415 if (code == GT && xval == const0_rtx)
10416 code = LT;
10417 else if (code == GE && xval == const1_rtx)
10418 code = LT;
10419 else if (code == LE && xval == const0_rtx)
10420 code = GE;
10421 else if (code == LT && xval == const1_rtx)
10422 code = GE;
10423 else
10424 FAIL;
10425
10426 operands[2] = CONST0_RTX (<MODE>mode);
10427 PUT_CODE (operands[0], code);
10428 })
10429
10430 ;; Same, but for 8-bit modes which have no scratch reg.
10431 (define_peephole2 ; "*swapped_tst<mode>"
10432 [(set (reg:CC REG_CC)
10433 (compare:CC (match_operand:ALLs1 1 "register_operand")
10434 (match_operand:ALLs1 2 "const_operand")))
10435 (set (pc)
10436 (if_then_else (match_operator 0 "ordered_comparison_operator"
10437 [(reg:CC REG_CC)
10438 (const_int 0)])
10439 (label_ref (match_operand 4))
10440 (pc)))]
10441 "peep2_regno_dead_p (2, REG_CC)"
10442 [(set (reg:CC REG_CC)
10443 (compare:CC (match_dup 2)
10444 (match_dup 1)))
10445 ; "branch"
10446 (set (pc)
10447 (if_then_else (match_op_dup 0 [(reg:CC REG_CC)
10448 (const_int 0)])
10449 (label_ref (match_dup 4))
10450 (pc)))]
10451 {
10452 rtx xval = avr_to_int_mode (operands[2]);
10453 rtx_code code = GET_CODE (operands[0]);
10454
10455 if (code == GT && xval == const0_rtx)
10456 code = LT;
10457 else if (code == GE && xval == const1_rtx)
10458 code = LT;
10459 else if (code == LE && xval == const0_rtx)
10460 code = GE;
10461 else if (code == LT && xval == const1_rtx)
10462 code = GE;
10463 else
10464 FAIL;
10465
10466 operands[2] = CONST0_RTX (<MODE>mode);
10467 PUT_CODE (operands[0], code);
10468 })
10469
10470
10471 (define_expand "extzv<mode>"
10472 [(set (match_operand:QI 0 "register_operand")
10473 (zero_extract:QI (match_operand:QISI 1 "register_operand")
10474 (match_operand:QI 2 "const1_operand")
10475 (match_operand:QI 3 "const_0_to_<MSB>_operand")))])
10476
10477 (define_insn_and_split "*extzv<mode>_split"
10478 [(set (match_operand:QI 0 "register_operand" "=r")
10479 (zero_extract:QI (match_operand:QISI 1 "reg_or_low_io_operand" "r Yil")
10480 (const_int 1)
10481 (match_operand:QI 2 "const_0_to_<MSB>_operand" "n")))]
10482 ""
10483 "#"
10484 "&& reload_completed"
10485 [(parallel [(set (match_dup 0)
10486 (zero_extract:QI (match_dup 1)
10487 (const_int 1)
10488 (match_dup 2)))
10489 (clobber (reg:CC REG_CC))])]
10490 {
10491 if (! MEM_P (operands[1]))
10492 {
10493 int bitno = INTVAL (operands[2]);
10494 operands[1] = simplify_gen_subreg (QImode, operands[1], <MODE>mode, bitno / 8);
10495 operands[2] = GEN_INT (bitno % 8);
10496 }
10497 })
10498
10499 (define_insn "*extzv<mode>"
10500 [(set (match_operand:QI 0 "register_operand" "=r")
10501 (zero_extract:QI (match_operand:QISI 1 "reg_or_low_io_operand" "r Yil")
10502 (const_int 1)
10503 (match_operand:QI 2 "const_0_to_<MSB>_operand" "n")))
10504 (clobber (reg:CC REG_CC))]
10505 "reload_completed"
10506 {
10507 return avr_out_extr (insn, operands, nullptr);
10508 }
10509 [(set_attr "adjust_len" "extr")])
10510
10511
10512 (define_insn_and_split "*extzv.qihi1"
10513 [(set (match_operand:HI 0 "register_operand" "=r")
10514 (zero_extract:HI (match_operand:QIHI 1 "register_operand" "r")
10515 (const_int 1)
10516 (match_operand:QI 2 "const_0_to_<MSB>_operand" "n")))]
10517 ""
10518 "#"
10519 ""
10520 [(set (match_dup 3)
10521 (zero_extract:QI (match_dup 1)
10522 (const_int 1)
10523 (match_dup 2)))
10524 (set (match_dup 4)
10525 (const_int 0))]
10526 {
10527 operands[3] = simplify_gen_subreg (QImode, operands[0], HImode, 0);
10528 operands[4] = simplify_gen_subreg (QImode, operands[0], HImode, 1);
10529 })
10530
10531 (define_insn_and_split "*extzv.not_split"
10532 [(set (match_operand:QI 0 "register_operand" "=r")
10533 (zero_extract:QI (not:QI (match_operand:QI 1 "reg_or_low_io_operand" "r Yil"))
10534 (const_int 1)
10535 (match_operand:QI 2 "const_0_to_7_operand" "n")))]
10536 ""
10537 "#"
10538 "&& reload_completed"
10539 [(parallel [(set (match_dup 0)
10540 (zero_extract:QI (not:QI (match_dup 1))
10541 (const_int 1)
10542 (match_dup 2)))
10543 (clobber (reg:CC REG_CC))])])
10544
10545 (define_insn "*extzv.not"
10546 [(set (match_operand:QI 0 "register_operand" "=r")
10547 (zero_extract:QI (not:QI (match_operand:QI 1 "reg_or_low_io_operand" "r Yil"))
10548 (const_int 1)
10549 (match_operand:QI 2 "const_0_to_7_operand" "n")))
10550 (clobber (reg:CC REG_CC))]
10551 "reload_completed"
10552 {
10553 return avr_out_extr_not (insn, operands, nullptr);
10554 }
10555 [(set_attr "adjust_len" "extr_not")])
10556
10557 (define_insn_and_split "*extzv.subreg.<mode>"
10558 [(set (match_operand:QI 0 "register_operand" "=r")
10559 (subreg:QI (zero_extract:HISI (match_operand:HISI 1 "register_operand" "r")
10560 (const_int 1)
10561 (match_operand:QI 2 "const_0_to_<MSB>_operand" "n"))
10562 0))]
10563 "! reload_completed"
10564 { gcc_unreachable(); }
10565 "&& 1"
10566 [; "*extzv<mode>_split"
10567 (set (match_dup 0)
10568 (zero_extract:QI (match_dup 1)
10569 (const_int 1)
10570 (match_dup 2)))])
10571
10572 ;; Possible subreg bytes.
10573 (define_int_iterator SuReB [0 1 2 3])
10574
10575 (define_insn_and_split "*extzv.<mode>.subreg<SuReB>"
10576 [(set (match_operand:QI 0 "register_operand" "=r")
10577 (zero_extract:QI (subreg:QI
10578 (and:HISI (match_operand:HISI 1 "register_operand" "r")
10579 (match_operand:HISI 2 "single_one_operand" "n"))
10580 SuReB)
10581 (const_int 1)
10582 (match_operand:QI 3 "const_0_to_7_operand" "n")))]
10583 "! reload_completed
10584 && IN_RANGE (UINTVAL(operands[2]) & GET_MODE_MASK(<MODE>mode),
10585 1U << (8 * <SuReB>), 0x80U << (8 * <SuReB>))
10586 && exact_log2 (UINTVAL(operands[2]) & GET_MODE_MASK(<MODE>mode))
10587 == 8 * <SuReB> + INTVAL (operands[3])"
10588 { gcc_unreachable(); }
10589 "&& 1"
10590 [; "*extzv<mode>_split"
10591 (set (match_dup 0)
10592 (zero_extract:QI (match_dup 1)
10593 (const_int 1)
10594 (match_dup 4)))]
10595 {
10596 operands[4] = plus_constant (QImode, operands[3], 8 * <SuReB>);
10597 })
10598
10599
10600 (define_insn_and_split "*extzv.xor"
10601 [(set (match_operand:QI 0 "register_operand")
10602 (zero_extract:QI (xor:QI (match_operand:QI 1 "reg_or_low_io_operand")
10603 (match_operand:QI 2 "single_one_operand"))
10604 (const_int 1)
10605 (match_operand:QI 3 "const_0_to_7_operand")))]
10606 "! reload_completed
10607 && ((1 << INTVAL (operands[3])) & INTVAL (operands[2])) != 0"
10608 { gcc_unreachable(); }
10609 "&& 1"
10610 [; "*extzv.not_split"
10611 (set (match_dup 0)
10612 (zero_extract:QI (not:QI (match_dup 1))
10613 (const_int 1)
10614 (match_dup 3)))])
10615
10616
10617 (define_insn_and_split "*extzv<mode>.ge"
10618 [(set (match_operand:QI 0 "register_operand" "=r")
10619 (ge:QI (match_operand:QISI 1 "reg_or_low_io_operand" "r Yil")
10620 (match_operand:QISI 2 "const0_operand" "Y00")))]
10621 ""
10622 "#"
10623 "reload_completed"
10624 [; "*extzv.not"
10625 (parallel [(set (match_dup 0)
10626 (zero_extract:QI (not:QI (match_dup 1))
10627 (const_int 1)
10628 (const_int 7)))
10629 (clobber (reg:CC REG_CC))])]
10630 {
10631 if (! MEM_P (operands[1]))
10632 {
10633 int msb = <SIZE> - 1;
10634 operands[1] = simplify_gen_subreg (QImode, operands[1], <MODE>mode, msb);
10635 }
10636 })
10637
10638 (define_insn_and_split "*neg.ashiftrt<mode>.msb"
10639 [(set (match_operand:QI 0 "register_operand" "=r")
10640 (neg:QI (subreg:QI
10641 (ashiftrt:QISI (match_operand:QISI 1 "register_operand" "r")
10642 (match_operand:QI 2 "const<MSB>_operand" "n"))
10643 0)))]
10644 "! reload_completed"
10645 { gcc_unreachable(); }
10646 "&& 1"
10647 [; "*extzv<mode>_split"
10648 (set (match_dup 0)
10649 (zero_extract:QI (match_dup 1)
10650 (const_int 1)
10651 (match_dup 2)))])
10652
10653 (define_insn_and_split "*extzv.io.lsr7"
10654 [(set (match_operand:QI 0 "register_operand")
10655 (lshiftrt:QI (match_operand:QI 1 "reg_or_low_io_operand")
10656 (const_int 7)))]
10657 "! reload_completed"
10658 { gcc_unreachable(); }
10659 "&& 1"
10660 [; "*extzv_split"
10661 (set (match_dup 0)
10662 (zero_extract:QI (match_dup 1)
10663 (const_int 1)
10664 (const_int 7)))])
10665
10666 ;; This insn serves as a combine bridge because insn combine will only
10667 ;; combine so much (3) insns at most. It's not actually an open coded
10668 ;; bit-insertion but just a part of it. It may occur in other contexts
10669 ;; than INSV though, and in such a case the code may be worse than without
10670 ;; this pattern. We still have to emit code for it in that case because
10671 ;; we cannot roll back.
10672 (define_insn_and_split "*insv.any_shift.<mode>_split"
10673 [(set (match_operand:QISI 0 "register_operand" "=r")
10674 (and:QISI (any_shift:QISI (match_operand:QISI 1 "register_operand" "r")
10675 (match_operand:QI 2 "const_0_to_<MSB>_operand" "n"))
10676 (match_operand:QISI 3 "single_one_operand" "n")))]
10677 ""
10678 "#"
10679 "&& reload_completed"
10680 [(parallel [(set (match_dup 0)
10681 (and:QISI (any_shift:QISI (match_dup 1)
10682 (match_dup 2))
10683 (match_dup 3)))
10684 (clobber (reg:CC REG_CC))])])
10685
10686 (define_insn "*insv.any_shift.<mode>"
10687 [(set (match_operand:QISI 0 "register_operand" "=r")
10688 (and:QISI (any_shift:QISI (match_operand:QISI 1 "register_operand" "r")
10689 (match_operand:QI 2 "const_0_to_<MSB>_operand" "n"))
10690 (match_operand:QISI 3 "single_one_operand" "n")))
10691 (clobber (reg:CC REG_CC))]
10692 "reload_completed"
10693 {
10694 return avr_out_insv (insn, operands, nullptr);
10695 }
10696 [(set_attr "adjust_len" "insv")])
10697
10698
10699 (define_insn_and_split "*extzv.<mode>hi2"
10700 [(set (match_operand:HI 0 "register_operand" "=r")
10701 (zero_extend:HI
10702 (zero_extract:QI (match_operand:QISI 1 "register_operand" "r")
10703 (const_int 1)
10704 (match_operand:QI 2 "const_0_to_<MSB>_operand" "n"))))]
10705 "! reload_completed"
10706 { gcc_unreachable(); }
10707 "&& 1"
10708 [; "*extzv<mode>_split"
10709 (set (match_dup 3)
10710 (zero_extract:QI (match_dup 1)
10711 (const_int 1)
10712 (match_dup 2)))
10713 (set (match_dup 4)
10714 (const_int 0))]
10715 {
10716 operands[3] = simplify_gen_subreg (QImode, operands[0], HImode, 0);
10717 operands[4] = simplify_gen_subreg (QImode, operands[0], HImode, 1);
10718 })
10719
10720 ;; ??? do_store_flag emits a hard-coded right shift to extract a bit without
10721 ;; even considering rtx_costs, extzv, or a bit-test. See PR 55181 for an example.
10722 (define_insn_and_split "*extract.subreg.bit"
10723 [(set (match_operand:QI 0 "register_operand" "=r")
10724 (and:QI (subreg:QI
10725 (any_shiftrt:HISI (match_operand:HISI 1 "register_operand" "r")
10726 (match_operand:QI 2 "const_0_to_<MSB>_operand" "n"))
10727 0)
10728 (const_int 1)))]
10729 "! reload_completed"
10730 { gcc_unreachable(); }
10731 "&& 1"
10732 [;; "*extzv<mode>_split"
10733 (set (match_dup 0)
10734 (zero_extract:QI (match_dup 1)
10735 (const_int 1)
10736 (match_dup 2)))])
10737
10738
10739 (define_insn_and_split "*sextr.<QISI:mode>.<QISI2:mode>_split"
10740 [(set (match_operand:QISI 0 "register_operand" "=r")
10741 (sign_extract:QISI (match_operand:QISI2 1 "register_operand" "r")
10742 (const_int 1)
10743 (match_operand:QI 2 "const0_operand" "L")))]
10744 ""
10745 "#"
10746 "&& reload_completed"
10747 [(parallel [(set (match_dup 0)
10748 (sign_extract:QISI (match_dup 1)
10749 (const_int 1)
10750 (match_dup 2)))
10751 (clobber (reg:CC REG_CC))])])
10752
10753 (define_insn "*sextr.<QISI:mode>.<QISI2:mode>"
10754 [(set (match_operand:QISI 0 "register_operand" "=r")
10755 (sign_extract:QISI (match_operand:QISI2 1 "register_operand" "r")
10756 (const_int 1)
10757 (match_operand:QI 2 "const0_operand" "L")))
10758 (clobber (reg:CC REG_CC))]
10759 "reload_completed"
10760 {
10761 return avr_out_sextr (insn, operands, NULL);
10762 }
10763 [(set_attr "adjust_len" "sextr")])
10764
10765
10766 (define_insn_and_split "*neg.zextr-to-sextr.<HISI:mode>.<QISI:mode>"
10767 [(set (match_operand:HISI 0 "register_operand")
10768 (neg:HISI (zero_extend:HISI
10769 (zero_extract:QIPSI (match_operand:QISI 1 "register_operand")
10770 (const_int 1)
10771 (match_operand:QI 2 "const0_operand")))))]
10772 "avropt_pr118012
10773 && <HISI:SIZE> > <QIPSI:SIZE>
10774 && ! reload_completed"
10775 { gcc_unreachable (); }
10776 "&& 1"
10777 [(set (match_dup 0)
10778 (sign_extract:HISI (match_dup 1)
10779 (const_int 1)
10780 (match_dup 2)))])
10781
10782
10783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10784 ;; PR118012: match.pd's
10785 ;;
10786 ;; /* (zero_one == 0) ? y : z <op> y -> ((typeof(y))zero_one * z) <op> y */
10787 ;; /* (zero_one != 0) ? z <op> y : y -> ((typeof(y))zero_one * z) <op> y */
10788 ;;
10789 ;; introduces a crazy "optimization" that transforms code like
10790 ;;
10791 ;; if (b & 1)
10792 ;; c ^= a;
10793 ;; to
10794 ;;
10795 ;; u = extract_bit0 (b);
10796 ;; v = zero_extend (u);
10797 ;; w = NEG v;
10798 ;; x = a AND w
10799 ;; c ^= x
10800 ;;
10801 ;; or even to
10802 ;;
10803 ;; u = extract_bit0 (b);
10804 ;; v = a MULT u
10805 ;; c ^= v
10806 ;;
10807 ;; even on machines that don't have MUL instructions or that
10808 ;; have to perform the multiplication by means of a libgcc call.
10809 ;; Try to fix that below. Notice that on AVR_TINY no MUL insn is
10810 ;; available since is is performed as a libgcc call from which we
10811 ;; cannot roll back. With !AVR_HAVR_MULMUL it's a transparent call
10812 ;; from avr.md so we can get rid of that at least.
10813
10814 ;; Map
10815 ;; $0 = ((sign_extract ($1.0)) AND $3) <op> $4
10816 ;; to
10817 ;; $0 = $4
10818 ;; if ($1.0 == 0)
10819 ;; goto L
10820 ;; $0 <op>= $3
10821 ;; L:;
10822 (define_insn_and_split "*pixop-to-skip.<QISI:mode>"
10823 [(set (match_operand:QISI 0 "register_operand")
10824 (pixop:QISI (and:QISI (sign_extract:QISI (match_operand:QISI2 1 "register_operand")
10825 (const_int 1)
10826 (match_operand:QI 2 "const0_operand"))
10827 (match_operand:QISI 3 "nonmemory_operand"))
10828 (match_operand:QISI 4 "register_operand")))]
10829 "avropt_pr118012
10830 && ! reload_completed"
10831 { gcc_unreachable (); }
10832 "&& 1"
10833 [(scratch)]
10834 {
10835 avr_emit_skip_pixop (<pixop:CODE>, operands[0], operands[4], operands[3],
10836 EQ, operands[1], 0);
10837 DONE;
10838 })
10839
10840 ;; Map
10841 ;; $0 = (($1 AND 1) MULT $2) o $3
10842 ;; to
10843 ;; $0 = $3
10844 ;; if ($1.0 == 0)
10845 ;; goto L
10846 ;; $0 o= $2
10847 ;; L:;
10848 (define_insn_and_split "*mul.and1-to-skip.<mode>"
10849 [(set (match_operand:QISI 0 "register_operand")
10850 (pixop:QISI (mult:QISI (and:QISI (match_operand:QISI 1 "register_operand")
10851 (const_int 1))
10852 (match_operand:QISI 2 "nonmemory_operand"))
10853 (match_operand:QISI 3 "register_operand")))]
10854 "avropt_pr118012
10855 && ! reload_completed"
10856 { gcc_unreachable (); }
10857 "&& 1"
10858 [(scratch)]
10859 {
10860 avr_emit_skip_pixop (<CODE>, operands[0], operands[3], operands[2],
10861 EQ, operands[1], 0);
10862 DONE;
10863 })
10864
10865 (define_insn_and_split "*mul.ext.and1-to-skip.<HISI:mode>"
10866 [(set (match_operand:HISI 0 "register_operand")
10867 (pixop:HISI (mult:HISI (any_extend:HISI (and:QIPSI (match_operand:QIPSI 1 "register_operand")
10868 (const_int 1)))
10869 (match_operand:HISI 2 "nonmemory_operand"))
10870 (match_operand:HISI 3 "register_operand")))]
10871 "avropt_pr118012
10872 && <HISI:SIZE> > <QIPSI:SIZE>
10873 && ! reload_completed"
10874 { gcc_unreachable (); }
10875 "&& 1"
10876 [(scratch)]
10877 {
10878 avr_emit_skip_pixop (<pixop:CODE>, operands[0], operands[3], operands[2],
10879 EQ, operands[1], 0);
10880 DONE;
10881 })
10882
10883 ;; Like the one above, but where $2 was a power of 2 and MULT has been
10884 ;; transformed to ASHIFT (PR118360).
10885 (define_insn_and_split "*shl.ext.and1-to-skip.<HISI:mode>"
10886 [(set (match_operand:HISI 0 "register_operand")
10887 (pixop:HISI (ashift:HISI (any_extend:HISI (and:QIPSI (match_operand:QIPSI 1 "register_operand")
10888 (const_int 1)))
10889 (match_operand:QI 2 "const_int_operand"))
10890 (match_operand:HISI 3 "register_operand")))]
10891 "avropt_pr118012
10892 && <HISI:SIZE> > <QIPSI:SIZE>
10893 && ! reload_completed"
10894 { gcc_unreachable (); }
10895 "&& 1"
10896 [(scratch)]
10897 {
10898 rtx op2 = gen_int_mode (1u << INTVAL (operands[2]), <HISI:MODE>mode);
10899 avr_emit_skip_pixop (<pixop:CODE>, operands[0], operands[3], op2,
10900 EQ, operands[1], 0);
10901 DONE;
10902 })
10903
10904 (define_insn_and_split "*shl.and-to-skip.<mode>"
10905 [(set (match_operand:HISI 0 "register_operand")
10906 (pixop:HISI (and:HISI (ashift:HISI (match_operand:HISI 1 "register_operand")
10907 (match_operand:QI 4 "const_0_to_<MSB>_operand"))
10908 (match_operand:HISI 2 "single_one_operand"))
10909 (match_operand:HISI 3 "register_operand")))]
10910 "avropt_pr118012
10911 && exact_log2 (UINTVAL (operands[2]) & GET_MODE_MASK (<MODE>mode))
10912 == INTVAL (operands[4])
10913 && ! reload_completed"
10914 { gcc_unreachable (); }
10915 "&& 1"
10916 [(scratch)]
10917 {
10918 avr_emit_skip_pixop (<CODE>, operands[0], operands[3], operands[2],
10919 EQ, operands[1], 0);
10920 DONE;
10921 })
10922
10923
10924 ;; Map
10925 ;; $0 = ($1 AND 1) MULT $2
10926 ;; to
10927 ;; $0 = $2
10928 ;; if ($1.0 != 0)
10929 ;; goto L
10930 ;; $0 = 0
10931 ;; L:;
10932 (define_insn_and_split "*map.mul.and1-to-skip.<QISI:mode>"
10933 [(set (match_operand:QISI 0 "register_operand")
10934 (mult:QISI (and:QISI (match_operand:QISI2 1 "register_operand")
10935 (const_int 1))
10936 (match_operand:QISI 2 "nonmemory_operand")))]
10937 "avropt_pr118012
10938 && ! reload_completed"
10939 { gcc_unreachable (); }
10940 "&& 1"
10941 [(scratch)]
10942 {
10943 avr_emit_skip_clear (operands[0], operands[2], NE, operands[1], 0);
10944 DONE;
10945 })
10946
10947 (define_insn_and_split "*map.mul.and1-to-skip.<mode>"
10948 [(set (match_operand:QISI 0 "register_operand")
10949 (mult:QISI (and:QISI (match_operand:QISI 1 "register_operand")
10950 (const_int 1))
10951 (match_operand:QISI 2 "nonmemory_operand")))]
10952 "avropt_pr118012
10953 && ! reload_completed"
10954 { gcc_unreachable (); }
10955 "&& 1"
10956 [(scratch)]
10957 {
10958 avr_emit_skip_clear (operands[0], operands[2], NE, operands[1], 0);
10959 DONE;
10960 })
10961
10962 (define_insn_and_split "*map.mul.ext.and1-to-skip.<HISI:mode>"
10963 [(set (match_operand:HISI 0 "register_operand")
10964 (mult:HISI (any_extend:HISI (and:QIPSI (match_operand:QIPSI 1 "register_operand")
10965 (const_int 1)))
10966 (match_operand:HISI 2 "nonmemory_operand")))]
10967 "avropt_pr118012
10968 && <HISI:SIZE> > <QIPSI:SIZE>
10969 && ! reload_completed"
10970 { gcc_unreachable (); }
10971 "&& 1"
10972 [(scratch)]
10973 {
10974 avr_emit_skip_clear (operands[0], operands[2], NE, operands[1], 0);
10975 DONE;
10976 })
10977
10978 ;; Similar, but the MULT has been turned to ASHIFT.
10979 (define_insn_and_split "*map.shl.ext.and1-to-skip.<HISI:mode>"
10980 [(set (match_operand:HISI 0 "register_operand")
10981 (ashift:HISI (any_extend:HISI (and:QIPSI (match_operand:QIPSI 1 "register_operand")
10982 (const_int 1)))
10983 (match_operand:QI 2 "const_0_to_<HISI:MSB>_operand")))]
10984 "avropt_pr118012
10985 && <HISI:SIZE> > <QIPSI:SIZE>
10986 && ! reload_completed"
10987 { gcc_unreachable (); }
10988 "&& 1"
10989 [(scratch)]
10990 {
10991 rtx op2 = gen_int_mode (1u << INTVAL (operands[2]), <HISI:MODE>mode);
10992 avr_emit_skip_clear (operands[0], op2, NE, operands[1], 0);
10993 DONE;
10994 })
10995
10996
10997 ;; Map
10998 ;; $0 = sign_extract($1.0) AND $3
10999 ;; to
11000 ;; $0 = $3
11001 ;; if ($1.0 != 0)
11002 ;; goto L
11003 ;; $0 = 0
11004 ;; L:;
11005 (define_insn_and_split "*map.and1-to-skip.<QISI:mode>"
11006 [(set (match_operand:QISI 0 "register_operand")
11007 (and:QISI (sign_extract:QISI (match_operand:QISI2 1 "register_operand")
11008 (const_int 1)
11009 (match_operand:QI 2 "const0_operand"))
11010 (match_operand:QISI 3 "nonmemory_operand")))]
11011 "avropt_pr118012
11012 && ! reload_completed"
11013 { gcc_unreachable (); }
11014 "&& 1"
11015 [(scratch)]
11016 {
11017 avr_emit_skip_clear (operands[0], operands[3], NE, operands[1], 0);
11018 DONE;
11019 })
11020
11021 ;; Patterns for -muse-nonzero-bits use nonzero_bits() in their condition,
11022 ;; which makes possible some more optimizations.
11023 ;; Since combine may add clobber of REG_CC, we must make sure that there are
11024 ;; no other routes to synthesize such patterns. We use an UNSPEC for that.
11025 ;; As insns are not supposed to use stuff like nonzero_bits() in their
11026 ;; condition, we split the insns right after reload. For CFG reasons we have
11027 ;; to do the splits by hand in avr_pass_split_nzb. All insns that must be
11028 ;; split by that pass must have insn attribute "nzb" set to "yes". Moreover,
11029 ;; the insns to split must be single_sets and must not touch control flow.
11030
11031 (define_code_attr nzb_constr_rdr [(and "r") (ior "d") (xor "r")])
11032 (define_code_attr nzb_use1_nnr [(and "n") (ior "n") (xor "r")])
11033
11034 (define_insn_and_split "*nzb=1.<code>.zerox_split"
11035 [(set (match_operand:QI 0 "register_operand")
11036 (bitop:QI (zero_extract:QI (match_operand:QI 1 "register_operand")
11037 (const_int 1)
11038 (match_operand:QI 2 "const_0_to_7_operand"))
11039 (match_operand:QI 3 "register_operand")))]
11040 "optimize && avropt_use_nonzero_bits
11041 && !reload_completed
11042 && (<CODE> == IOR || <CODE> == XOR
11043 || nonzero_bits (operands[3], QImode) == 1)"
11044 { gcc_unreachable (); }
11045 "optimize && avropt_use_nonzero_bits
11046 && !reload_completed"
11047 [(parallel [(set (match_dup 0)
11048 (bitop:QI (zero_extract:QI (match_dup 1)
11049 (const_int 1)
11050 (match_dup 2))
11051 (unspec:QI [(match_dup 3)
11052 ] UNSPEC_NZB)))
11053 (use (const_int 1))
11054 (clobber (reg:CC REG_CC))])]
11055 ""
11056 [(set_attr "nzb" "yes")])
11057
11058 (define_insn "*nzb=1.<code>.zerox"
11059 [(set (match_operand:QI 0 "register_operand" "=<nzb_constr_rdr>")
11060 (bitop:QI (zero_extract:QI (match_operand:QI 1 "register_operand" "r")
11061 (const_int 1)
11062 (match_operand:QI 2 "const_0_to_7_operand" "n"))
11063 (unspec:QI [(match_operand:QI 3 "register_operand" "0")
11064 ] UNSPEC_NZB)))
11065 (use (match_operand:QI 4 "nonmemory_operand" "<nzb_use1_nnr>"))
11066 (clobber (reg:CC REG_CC))]
11067 "optimize && avropt_use_nonzero_bits"
11068 {
11069 if (<CODE> == AND)
11070 return "sbrs %1,%2\;clr %0";
11071 else if (<CODE> == IOR)
11072 return "sbrc %1,%2\;ori %0,1";
11073 else if (<CODE> == XOR)
11074 return "sbrc %1,%2\;eor %0,%4";
11075 else
11076 gcc_unreachable ();
11077 }
11078 [(set_attr "length" "2")])
11079
11080 (define_insn_and_split "*nzb=1.<code>.lsr_split"
11081 [(set (match_operand:QI 0 "register_operand")
11082 (bitop:QI (lshiftrt:QI (match_operand:QI 1 "register_operand")
11083 (match_operand:QI 2 "const_0_to_7_operand"))
11084 (match_operand:QI 3 "register_operand")))]
11085 "optimize && avropt_use_nonzero_bits
11086 && !reload_completed
11087 && avr_nonzero_bits_lsr_operands_p (<CODE>, operands)"
11088 { gcc_unreachable (); }
11089 "optimize && avropt_use_nonzero_bits
11090 && !reload_completed"
11091 [(parallel [(set (match_dup 0)
11092 (bitop:QI (zero_extract:QI (match_dup 1)
11093 (const_int 1)
11094 (match_dup 2))
11095 (unspec:QI [(match_dup 3)
11096 ] UNSPEC_NZB)))
11097 (use (const_int 1))
11098 (clobber (reg:CC REG_CC))])]
11099 ""
11100 [(set_attr "nzb" "yes")])
11101
11102 (define_insn_and_split "*nzb=1.<code>.zerox.not_split"
11103 [(set (match_operand:QI 0 "register_operand")
11104 (bitop:QI (zero_extract:QI (xor:QI (match_operand:QI 1 "register_operand")
11105 (match_operand:QI 4 "const_int_operand"))
11106 (const_int 1)
11107 (match_operand:QI 2 "const_0_to_7_operand"))
11108 (match_operand:QI 3 "register_operand")))]
11109 "optimize && avropt_use_nonzero_bits
11110 && !reload_completed
11111 && INTVAL (operands[2]) == exact_log2 (0xff & INTVAL (operands[4]))
11112 && (<CODE> == IOR
11113 || nonzero_bits (operands[3], QImode) == 1)"
11114 { gcc_unreachable (); }
11115 "optimize && avropt_use_nonzero_bits
11116 && !reload_completed"
11117 ; "*nzb=1.<code>.zerox.not"
11118 [(parallel [(set (match_dup 0)
11119 (bitop:QI (zero_extract:QI (not:QI (match_dup 1))
11120 (const_int 1)
11121 (match_dup 2))
11122 (unspec:QI [(match_dup 3)
11123 ] UNSPEC_NZB)))
11124 (use (const_int 1))
11125 (clobber (reg:CC REG_CC))])]
11126 ""
11127 [(set_attr "nzb" "yes")])
11128
11129 (define_insn_and_split "*nzb=1.<code>.lsr.not_split"
11130 [(set (match_operand:QI 0 "register_operand")
11131 (bitop:QI (lshiftrt:QI (xor:QI (match_operand:QI 1 "register_operand")
11132 (match_operand:QI 4 "const_int_operand"))
11133 (match_operand:QI 2 "const_0_to_7_operand"))
11134 (match_operand:QI 3 "register_operand")))]
11135 "optimize && avropt_use_nonzero_bits
11136 && !reload_completed
11137 && INTVAL (operands[2]) == exact_log2 (0xff & INTVAL (operands[4]))
11138 && avr_nonzero_bits_lsr_operands_p (<CODE>, operands)"
11139 { gcc_unreachable (); }
11140 "optimize && avropt_use_nonzero_bits
11141 && !reload_completed"
11142 ; "*nzb=1.<code>.zerox.not"
11143 [(parallel [(set (match_dup 0)
11144 (bitop:QI (zero_extract:QI (not:QI (match_dup 1))
11145 (const_int 1)
11146 (match_dup 2))
11147 (unspec:QI [(match_dup 3)
11148 ] UNSPEC_NZB)))
11149 (use (const_int 1))
11150 (clobber (reg:CC REG_CC))])]
11151 ""
11152 [(set_attr "nzb" "yes")])
11153
11154 (define_insn_and_split "*nzb=1.<code>.ge0_split"
11155 [(set (match_operand:QI 0 "register_operand")
11156 (bitop:QI (ge:QI (match_operand:QI 1 "register_operand")
11157 (const_int 0))
11158 (match_operand:QI 2 "register_operand")))]
11159 "optimize && avropt_use_nonzero_bits
11160 && !reload_completed
11161 && (<CODE> == IOR || <CODE> == XOR
11162 || nonzero_bits (operands[2], QImode) == 1)"
11163 { gcc_unreachable (); }
11164 "optimize && avropt_use_nonzero_bits
11165 && !reload_completed"
11166 ; "*nzb=1.<code>.zerox.not"
11167 [(parallel [(set (match_dup 0)
11168 (bitop:QI (zero_extract:QI (not:QI (match_dup 1))
11169 (const_int 1)
11170 (const_int 7))
11171 (unspec:QI [(match_dup 2)
11172 ] UNSPEC_NZB)))
11173 (use (const_int 1))
11174 (clobber (reg:CC REG_CC))])]
11175 ""
11176 [(set_attr "nzb" "yes")])
11177
11178 (define_insn "*nzb=1.<code>.zerox.not"
11179 [(set (match_operand:QI 0 "register_operand" "=<nzb_constr_rdr>")
11180 (bitop:QI (zero_extract:QI (not:QI (match_operand:QI 1 "register_operand" "r"))
11181 (const_int 1)
11182 (match_operand:QI 2 "const_0_to_7_operand" "n"))
11183 (unspec:QI [(match_operand:QI 3 "register_operand" "0")
11184 ] UNSPEC_NZB)))
11185 (use (match_operand:QI 4 "nonmemory_operand" "<nzb_use1_nnr>"))
11186 (clobber (reg:CC REG_CC))]
11187 "optimize && avropt_use_nonzero_bits"
11188 {
11189 if (<CODE> == AND)
11190 return "sbrc %1,%2\;clr %0";
11191 else if (<CODE> == IOR)
11192 return "sbrs %1,%2\;ori %0,1";
11193 else if (<CODE> == XOR)
11194 return "sbrs %1,%2\;eor %0,%4";
11195 else
11196 gcc_unreachable ();
11197 }
11198 [(set_attr "length" "2")])
11199
11200 (define_insn_and_split "*nzb=1.ior.ashift_split"
11201 [(set (match_operand:QI 0 "register_operand" "=d")
11202 (ior:QI (ashift:QI (match_operand:QI 1 "register_operand" "r")
11203 (match_operand:QI 2 "const_0_to_7_operand" "n"))
11204 (match_operand:QI 3 "register_operand" "0")))]
11205 "optimize && avropt_use_nonzero_bits
11206 && !reload_completed
11207 && nonzero_bits (operands[1], QImode) == 1"
11208 { gcc_unreachable (); }
11209 "optimize && avropt_use_nonzero_bits
11210 && !reload_completed"
11211 [(parallel [(set (match_dup 0)
11212 (unspec:QI [(ior:QI (ashift:QI (match_dup 1)
11213 (match_dup 2))
11214 (match_dup 3))
11215 ] UNSPEC_NZB))
11216 (clobber (reg:CC REG_CC))])]
11217 ""
11218 [(set_attr "nzb" "yes")])
11219
11220 (define_insn "*nzb=1.ior.ashift"
11221 [(set (match_operand:QI 0 "register_operand" "=d")
11222 (unspec:QI [(ior:QI (ashift:QI (match_operand:QI 1 "register_operand" "r")
11223 (match_operand:QI 2 "const_0_to_7_operand" "n"))
11224 (match_operand:QI 3 "register_operand" "0"))
11225 ] UNSPEC_NZB))
11226 (clobber (reg:CC REG_CC))]
11227 "optimize && avropt_use_nonzero_bits"
11228 "sbrc %1,0\;ori %0,1<<%2"
11229 [(set_attr "length" "2")])
11230
11231
11232 ;; Work around PR115307: Early passes expand isinf/f/l to a bloat.
11233 ;; These passes do not consider costs, and there is no way to
11234 ;; hook in or otherwise disable the generated bloat.
11235
11236 ;; isinfsf2 isinfdf2
11237 (define_expand "isinf<mode>2"
11238 [(parallel [(match_operand:HI 0)
11239 (match_operand:SFDF 1)])]
11240 ""
11241 {
11242 FAIL;
11243 })
11244
11245
11246 ;; Fixed-point instructions
11247 (include "avr-fixed.md")
11248
11249 ;; Operations on 64-bit registers
11250 (include "avr-dimode.md")