Debian Codegraph @

gcc/config/avr/avr-dimode.md

raw
1 ;; Support 64-bit operations for AVR 8-bit microcontrollers.
2 ;; Copyright (C) 1998-2025 Free Software Foundation, Inc.
3 ;; Contributed by Georg Lay ([email protected])
4 ;;
5 ;; This file is part of GCC.
6 ;;
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
10 ;; any later version.
11 ;;
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22
23 ;; The purpose of this file is to provide a light-weight DImode
24 ;; implementation for AVR. The trouble with DImode is that tree -> RTL
25 ;; lowering leads to really unpleasant code for operations that don't
26 ;; work byte-wise like NEG, PLUS, MINUS, etc. Defining optabs entries for
27 ;; them won't help because the optab machinery assumes these operations
28 ;; are cheap and does not check if a libgcc implementation is available.
29 ;;
30 ;; The DImode insns are all straight forward -- except movdi. The approach
31 ;; of this implementation is to provide DImode insns without the burden of
32 ;; introducing movdi.
33 ;;
34 ;; The caveat is that if there are insns for some mode, there must also be a
35 ;; respective move insn that describes reloads. Therefore, this
36 ;; implementation uses an accumulator-based model with two hard-coded,
37 ;; accumulator-like registers
38 ;;
39 ;; A[] = reg:DI 18
40 ;; B[] = reg:DI 10
41 ;;
42 ;; so that no DImode insn contains pseudos or needs reloading.
43
44 (define_constants
45 [(ACC_A 18)
46 (ACC_B 10)])
47
48 ;; Supported modes that are 8 bytes wide
49 (define_mode_iterator ALL8 [DI DQ UDQ DA UDA TA UTA])
50
51 (define_mode_iterator ALL8U [UDQ UDA UTA])
52 (define_mode_iterator ALL8S [ DQ DA TA])
53
54 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55 ;; Addition
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57
58 ;; "adddi3"
59 ;; "adddq3" "addudq3"
60 ;; "addda3" "adduda3"
61 ;; "addta3" "adduta3"
62 (define_expand "add<mode>3"
63 [(parallel [(match_operand:ALL8 0 "general_operand" "")
64 (match_operand:ALL8 1 "nop_general_operand")
65 (match_operand:ALL8 2 "nop_general_operand")])]
66 "avr_have_dimode"
67 {
68 rtx acc_a = gen_rtx_REG (<MODE>mode, ACC_A);
69
70 avr_fix_inputs (operands, 1 << 2, regmask (<MODE>mode, ACC_A));
71 emit_move_insn (acc_a, operands[1]);
72
73 if (DImode == <MODE>mode
74 && s8_operand (operands[2], VOIDmode))
75 {
76 emit_move_insn (gen_rtx_REG (QImode, REG_X), operands[2]);
77 emit_insn (gen_adddi3_const8_insn ());
78 }
79 else if (const_operand (operands[2], GET_MODE (operands[2])))
80 {
81 emit_insn (gen_add<mode>3_const_insn (operands[2]));
82 }
83 else
84 {
85 emit_move_insn (gen_rtx_REG (<MODE>mode, ACC_B), operands[2]);
86 emit_insn (gen_add<mode>3_insn ());
87 }
88
89 emit_move_insn (operands[0], acc_a);
90 DONE;
91 })
92
93 ;; "adddi3_insn"
94 ;; "adddq3_insn" "addudq3_insn"
95 ;; "addda3_insn" "adduda3_insn"
96 ;; "addta3_insn" "adduta3_insn"
97 (define_insn_and_split "add<mode>3_insn"
98 [(set (reg:ALL8 ACC_A)
99 (plus:ALL8 (reg:ALL8 ACC_A)
100 (reg:ALL8 ACC_B)))]
101 "avr_have_dimode"
102 "#"
103 "&& reload_completed"
104 [(parallel [(set (reg:ALL8 ACC_A)
105 (plus:ALL8 (reg:ALL8 ACC_A)
106 (reg:ALL8 ACC_B)))
107 (clobber (reg:CC REG_CC))])])
108
109 (define_insn "*add<mode>3_insn"
110 [(set (reg:ALL8 ACC_A)
111 (plus:ALL8 (reg:ALL8 ACC_A)
112 (reg:ALL8 ACC_B)))
113 (clobber (reg:CC REG_CC))]
114 "avr_have_dimode && reload_completed"
115 "%~call __adddi3"
116 [(set_attr "adjust_len" "call")])
117
118 (define_insn_and_split "adddi3_const8_insn"
119 [(set (reg:DI ACC_A)
120 (plus:DI (reg:DI ACC_A)
121 (sign_extend:DI (reg:QI REG_X))))]
122 "avr_have_dimode"
123 "#"
124 "&& reload_completed"
125 [(parallel [(set (reg:DI ACC_A)
126 (plus:DI (reg:DI ACC_A)
127 (sign_extend:DI (reg:QI REG_X))))
128 (clobber (reg:CC REG_CC))])])
129
130 (define_insn "*adddi3_const8_insn"
131 [(set (reg:DI ACC_A)
132 (plus:DI (reg:DI ACC_A)
133 (sign_extend:DI (reg:QI REG_X))))
134 (clobber (reg:CC REG_CC))]
135 "avr_have_dimode && reload_completed"
136 "%~call __adddi3_s8"
137 [(set_attr "adjust_len" "call")])
138
139 ;; "adddi3_const_insn"
140 ;; "adddq3_const_insn" "addudq3_const_insn"
141 ;; "addda3_const_insn" "adduda3_const_insn"
142 ;; "addta3_const_insn" "adduta3_const_insn"
143 (define_insn_and_split "add<mode>3_const_insn"
144 [(set (reg:ALL8 ACC_A)
145 (plus:ALL8 (reg:ALL8 ACC_A)
146 (match_operand:ALL8 0 "const_operand" "n Ynn")))]
147 "avr_have_dimode
148 && !s8_operand (operands[0], VOIDmode)"
149 "#"
150 "&& reload_completed"
151 [(parallel [(set (reg:ALL8 ACC_A)
152 (plus:ALL8 (reg:ALL8 ACC_A)
153 (match_dup 0)))
154 (clobber (reg:CC REG_CC))])])
155
156 (define_insn "*add<mode>3_const_insn"
157 [(set (reg:ALL8 ACC_A)
158 (plus:ALL8 (reg:ALL8 ACC_A)
159 (match_operand:ALL8 0 "const_operand" "n Ynn")))
160 (clobber (reg:CC REG_CC))]
161 "avr_have_dimode
162 && !s8_operand (operands[0], VOIDmode)
163 && reload_completed"
164 {
165 return avr_out_plus (insn, operands);
166 }
167 [(set_attr "adjust_len" "plus")])
168
169
170 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
171 ;; Subtraction
172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
173
174 ;; "subdi3"
175 ;; "subdq3" "subudq3"
176 ;; "subda3" "subuda3"
177 ;; "subta3" "subuta3"
178 (define_expand "sub<mode>3"
179 [(parallel [(match_operand:ALL8 0 "general_operand" "")
180 (match_operand:ALL8 1 "nop_general_operand")
181 (match_operand:ALL8 2 "nop_general_operand")])]
182 "avr_have_dimode"
183 {
184 rtx acc_a = gen_rtx_REG (<MODE>mode, ACC_A);
185
186 avr_fix_inputs (operands, 1 << 2, regmask (<MODE>mode, ACC_A));
187 emit_move_insn (acc_a, operands[1]);
188
189 if (const_operand (operands[2], GET_MODE (operands[2])))
190 {
191 emit_insn (gen_sub<mode>3_const_insn (operands[2]));
192 }
193 else
194 {
195 emit_move_insn (gen_rtx_REG (<MODE>mode, ACC_B), operands[2]);
196 emit_insn (gen_sub<mode>3_insn ());
197 }
198
199 emit_move_insn (operands[0], acc_a);
200 DONE;
201 })
202
203 ;; "subdi3_insn"
204 ;; "subdq3_insn" "subudq3_insn"
205 ;; "subda3_insn" "subuda3_insn"
206 ;; "subta3_insn" "subuta3_insn"
207 (define_insn_and_split "sub<mode>3_insn"
208 [(set (reg:ALL8 ACC_A)
209 (minus:ALL8 (reg:ALL8 ACC_A)
210 (reg:ALL8 ACC_B)))]
211 "avr_have_dimode"
212 "#"
213 "&& reload_completed"
214 [(parallel [(set (reg:ALL8 ACC_A)
215 (minus:ALL8 (reg:ALL8 ACC_A)
216 (reg:ALL8 ACC_B)))
217 (clobber (reg:CC REG_CC))])])
218
219 (define_insn "*sub<mode>3_insn"
220 [(set (reg:ALL8 ACC_A)
221 (minus:ALL8 (reg:ALL8 ACC_A)
222 (reg:ALL8 ACC_B)))
223 (clobber (reg:CC REG_CC))]
224 "avr_have_dimode && reload_completed"
225 "%~call __subdi3"
226 [(set_attr "adjust_len" "call")])
227
228 ;; "subdi3_const_insn"
229 ;; "subdq3_const_insn" "subudq3_const_insn"
230 ;; "subda3_const_insn" "subuda3_const_insn"
231 ;; "subta3_const_insn" "subuta3_const_insn"
232 (define_insn_and_split "sub<mode>3_const_insn"
233 [(set (reg:ALL8 ACC_A)
234 (minus:ALL8 (reg:ALL8 ACC_A)
235 (match_operand:ALL8 0 "const_operand" "n Ynn")))]
236 "avr_have_dimode"
237 "#"
238 "&& reload_completed"
239 [(parallel [(set (reg:ALL8 ACC_A)
240 (minus:ALL8 (reg:ALL8 ACC_A)
241 (match_dup 0)))
242 (clobber (reg:CC REG_CC))])])
243
244 (define_insn "*sub<mode>3_const_insn"
245 [(set (reg:ALL8 ACC_A)
246 (minus:ALL8 (reg:ALL8 ACC_A)
247 (match_operand:ALL8 0 "const_operand" "n Ynn")))
248 (clobber (reg:CC REG_CC))]
249 "avr_have_dimode && reload_completed"
250 {
251 return avr_out_plus (insn, operands);
252 }
253 [(set_attr "adjust_len" "plus")])
254
255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
256 ;; Signed Saturating Addition and Subtraction
257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
258
259 (define_expand "<code_stdname><mode>3"
260 [(set (match_operand:ALL8S 0 "general_operand" "")
261 (ss_addsub:ALL8S (match_operand:ALL8S 1 "nop_general_operand")
262 (match_operand:ALL8S 2 "nop_general_operand")))]
263 "avr_have_dimode"
264 {
265 rtx acc_a = gen_rtx_REG (<MODE>mode, ACC_A);
266
267 avr_fix_inputs (operands, 1 << 2, regmask (<MODE>mode, ACC_A));
268 emit_move_insn (acc_a, operands[1]);
269
270 if (const_operand (operands[2], GET_MODE (operands[2])))
271 {
272 emit_insn (gen_<code_stdname><mode>3_const_insn (operands[2]));
273 }
274 else
275 {
276 emit_move_insn (gen_rtx_REG (<MODE>mode, ACC_B), operands[2]);
277 emit_insn (gen_<code_stdname><mode>3_insn ());
278 }
279
280 emit_move_insn (operands[0], acc_a);
281 DONE;
282 })
283
284 (define_insn_and_split "<code_stdname><mode>3_insn"
285 [(set (reg:ALL8S ACC_A)
286 (ss_addsub:ALL8S (reg:ALL8S ACC_A)
287 (reg:ALL8S ACC_B)))]
288 "avr_have_dimode"
289 "#"
290 "&& reload_completed"
291 [(parallel [(set (reg:ALL8S ACC_A)
292 (ss_addsub:ALL8S (reg:ALL8S ACC_A)
293 (reg:ALL8S ACC_B)))
294 (clobber (reg:CC REG_CC))])])
295
296 (define_insn "*<code_stdname><mode>3_insn"
297 [(set (reg:ALL8S ACC_A)
298 (ss_addsub:ALL8S (reg:ALL8S ACC_A)
299 (reg:ALL8S ACC_B)))
300 (clobber (reg:CC REG_CC))]
301 "avr_have_dimode && reload_completed"
302 "%~call __<code_stdname><mode>3"
303 [(set_attr "adjust_len" "call")])
304
305 (define_insn_and_split "<code_stdname><mode>3_const_insn"
306 [(set (reg:ALL8S ACC_A)
307 (ss_addsub:ALL8S (reg:ALL8S ACC_A)
308 (match_operand:ALL8S 0 "const_operand" "n Ynn")))]
309 "avr_have_dimode"
310 "#"
311 "&& reload_completed"
312 [(parallel [(set (reg:ALL8S ACC_A)
313 (ss_addsub:ALL8S (reg:ALL8S ACC_A)
314 (match_dup 0)))
315 (clobber (reg:CC REG_CC))])])
316
317 (define_insn "*<code_stdname><mode>3_const_insn"
318 [(set (reg:ALL8S ACC_A)
319 (ss_addsub:ALL8S (reg:ALL8S ACC_A)
320 (match_operand:ALL8S 0 "const_operand" "n Ynn")))
321 (clobber (reg:CC REG_CC))]
322 "avr_have_dimode && reload_completed"
323 {
324 return avr_out_plus (insn, operands);
325 }
326 [(set_attr "adjust_len" "plus")])
327
328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
329 ;; Unsigned Saturating Addition and Subtraction
330 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
331
332 (define_expand "<code_stdname><mode>3"
333 [(set (match_operand:ALL8U 0 "general_operand" "")
334 (us_addsub:ALL8U (match_operand:ALL8U 1 "nop_general_operand")
335 (match_operand:ALL8U 2 "nop_general_operand")))]
336 "avr_have_dimode"
337 {
338 rtx acc_a = gen_rtx_REG (<MODE>mode, ACC_A);
339
340 avr_fix_inputs (operands, 1 << 2, regmask (<MODE>mode, ACC_A));
341 emit_move_insn (acc_a, operands[1]);
342
343 if (const_operand (operands[2], GET_MODE (operands[2])))
344 {
345 emit_insn (gen_<code_stdname><mode>3_const_insn (operands[2]));
346 }
347 else
348 {
349 emit_move_insn (gen_rtx_REG (<MODE>mode, ACC_B), operands[2]);
350 emit_insn (gen_<code_stdname><mode>3_insn ());
351 }
352
353 emit_move_insn (operands[0], acc_a);
354 DONE;
355 })
356
357 (define_insn_and_split "<code_stdname><mode>3_insn"
358 [(set (reg:ALL8U ACC_A)
359 (us_addsub:ALL8U (reg:ALL8U ACC_A)
360 (reg:ALL8U ACC_B)))]
361 "avr_have_dimode"
362 "#"
363 "&& reload_completed"
364 [(parallel [(set (reg:ALL8U ACC_A)
365 (us_addsub:ALL8U (reg:ALL8U ACC_A)
366 (reg:ALL8U ACC_B)))
367 (clobber (reg:CC REG_CC))])])
368
369 (define_insn "*<code_stdname><mode>3_insn"
370 [(set (reg:ALL8U ACC_A)
371 (us_addsub:ALL8U (reg:ALL8U ACC_A)
372 (reg:ALL8U ACC_B)))
373 (clobber (reg:CC REG_CC))]
374 "avr_have_dimode && reload_completed"
375 "%~call __<code_stdname><mode>3"
376 [(set_attr "adjust_len" "call")])
377
378 (define_insn_and_split "<code_stdname><mode>3_const_insn"
379 [(set (reg:ALL8U ACC_A)
380 (us_addsub:ALL8U (reg:ALL8U ACC_A)
381 (match_operand:ALL8U 0 "const_operand" "n Ynn")))]
382 "avr_have_dimode"
383 "#"
384 "&& reload_completed"
385 [(parallel [(set (reg:ALL8U ACC_A)
386 (us_addsub:ALL8U (reg:ALL8U ACC_A)
387 (match_operand:ALL8U 0 "const_operand" "n Ynn")))
388 (clobber (reg:CC REG_CC))])])
389
390 (define_insn "*<code_stdname><mode>3_const_insn"
391 [(set (reg:ALL8U ACC_A)
392 (us_addsub:ALL8U (reg:ALL8U ACC_A)
393 (match_operand:ALL8U 0 "const_operand" "n Ynn")))
394 (clobber (reg:CC REG_CC))]
395 "avr_have_dimode && reload_completed"
396 {
397 return avr_out_plus (insn, operands);
398 }
399 [(set_attr "adjust_len" "plus")])
400
401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
402 ;; Negation
403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
404
405 (define_expand "negdi2"
406 [(parallel [(match_operand:DI 0 "general_operand" "")
407 (match_operand:DI 1 "nop_general_operand")])]
408 "avr_have_dimode"
409 {
410 rtx acc_a = gen_rtx_REG (DImode, ACC_A);
411
412 emit_move_insn (acc_a, operands[1]);
413 emit_insn (gen_negdi2_insn ());
414 emit_move_insn (operands[0], acc_a);
415 DONE;
416 })
417
418 (define_insn_and_split "negdi2_insn"
419 [(set (reg:DI ACC_A)
420 (neg:DI (reg:DI ACC_A)))]
421 "avr_have_dimode"
422 "#"
423 "&& reload_completed"
424 [(parallel [(set (reg:DI ACC_A)
425 (neg:DI (reg:DI ACC_A)))
426 (clobber (reg:CC REG_CC))])])
427
428 (define_insn "*negdi2_insn"
429 [(set (reg:DI ACC_A)
430 (neg:DI (reg:DI ACC_A)))
431 (clobber (reg:CC REG_CC))]
432 "avr_have_dimode && reload_completed"
433 "%~call __negdi2"
434 [(set_attr "adjust_len" "call")])
435
436
437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
438 ;; Comparison
439 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
440
441 (define_expand "conditional_jump"
442 [(set (pc)
443 (if_then_else
444 (match_operator 0 "ordered_comparison_operator" [(reg:CC REG_CC)
445 (const_int 0)])
446 (label_ref (match_operand 1 "" ""))
447 (pc)))]
448 "avr_have_dimode")
449
450 ;; "cbranchdi4"
451 ;; "cbranchdq4" "cbranchudq4"
452 ;; "cbranchda4" "cbranchuda4"
453 ;; "cbranchta4" "cbranchuta4"
454 (define_expand "cbranch<mode>4"
455 [(set (pc)
456 (if_then_else (match_operator 0 "ordered_comparison_operator"
457 [(match_operand:ALL8 1 "register_operand")
458 (match_operand:ALL8 2 "nonmemory_operand")])
459 (label_ref (match_operand 3))
460 (pc)))]
461 "avr_have_dimode"
462 {
463 int icode = (int) GET_CODE (operands[0]);
464
465 targetm.canonicalize_comparison (&icode, &operands[1], &operands[2], false);
466 operands[0] = gen_rtx_fmt_ee ((rtx_code) icode,
467 VOIDmode, operands[1], operands[2]);
468
469 rtx acc_a = gen_rtx_REG (<MODE>mode, ACC_A);
470
471 avr_fix_inputs (operands, 1 << 2, regmask (<MODE>mode, ACC_A));
472 emit_move_insn (acc_a, operands[1]);
473
474 if (s8_operand (operands[2], VOIDmode))
475 {
476 emit_move_insn (gen_rtx_REG (QImode, REG_X), operands[2]);
477 emit_jump_insn (gen_cbranch_const8_di2_split (operands[0], operands[3]));
478 }
479 else if (const_operand (operands[2], GET_MODE (operands[2])))
480 {
481 emit_jump_insn (gen_cbranch_const_<mode>2_split (operands[0],
482 operands[2],
483 operands[3]));
484 }
485 else
486 {
487 emit_move_insn (gen_rtx_REG (<MODE>mode, ACC_B), operands[2]);
488 emit_jump_insn (gen_cbranch_<mode>2_split (operands[0], operands[3]));
489 }
490 DONE;
491 })
492
493 (define_insn_and_split "cbranch_<mode>2_split"
494 [(set (pc)
495 (if_then_else (match_operator 0 "ordered_comparison_operator"
496 [(reg:ALL8 ACC_A)
497 (reg:ALL8 ACC_B)])
498 (label_ref (match_operand 1))
499 (pc)))]
500 "avr_have_dimode"
501 "#"
502 "&& reload_completed"
503 [(const_int 0)]
504 {
505 emit_insn (gen_compare_<mode>2 ());
506 emit_jump_insn (gen_conditional_jump (operands[0], operands[1]));
507 DONE;
508 })
509
510 ;; "compare_di2"
511 ;; "compare_dq2" "compare_udq2"
512 ;; "compare_da2" "compare_uda2"
513 ;; "compare_ta2" "compare_uta2"
514 (define_insn "compare_<mode>2"
515 [(set (reg:CC REG_CC)
516 (compare:CC (reg:ALL8 ACC_A)
517 (reg:ALL8 ACC_B)))]
518 "reload_completed && avr_have_dimode"
519 "%~call __cmpdi2"
520 [(set_attr "adjust_len" "call")])
521
522 (define_insn_and_split "cbranch_const8_di2_split"
523 [(set (pc)
524 (if_then_else (match_operator 0 "ordered_comparison_operator"
525 [(reg:DI ACC_A)
526 (sign_extend:DI (reg:QI REG_X))])
527 (label_ref (match_operand 1 "" ""))
528 (pc)))]
529 "avr_have_dimode"
530 "#"
531 "&& reload_completed"
532 [(const_int 0)]
533 {
534 emit_insn (gen_compare_const8_di2 ());
535 emit_jump_insn (gen_conditional_jump (operands[0], operands[1]));
536 DONE;
537 })
538
539 (define_insn "compare_const8_di2"
540 [(set (reg:CC REG_CC)
541 (compare:CC (reg:DI ACC_A)
542 (sign_extend:DI (reg:QI REG_X))))]
543 "reload_completed && avr_have_dimode"
544 "%~call __cmpdi2_s8"
545 [(set_attr "adjust_len" "call")])
546
547 (define_insn_and_split "cbranch_const_<mode>2_split"
548 [(set (pc)
549 (if_then_else (match_operator 0 "ordered_comparison_operator"
550 [(reg:ALL8 ACC_A)
551 (match_operand:ALL8 1 "const_operand" "n Ynn")])
552 (label_ref (match_operand 2 "" ""))
553 (pc)))
554 (clobber (match_scratch:QI 3 "=&d"))]
555 "avr_have_dimode
556 && !s8_operand (operands[1], VOIDmode)"
557 "#"
558 "&& reload_completed"
559 [(const_int 0)]
560 {
561 emit_insn (gen_compare_const_<mode>2 (operands[1], operands[3]));
562 emit_jump_insn (gen_conditional_jump (operands[0], operands[2]));
563 DONE;
564 })
565
566
567 ;; "compare_const_di2"
568 ;; "compare_const_dq2" "compare_const_udq2"
569 ;; "compare_const_da2" "compare_const_uda2"
570 ;; "compare_const_ta2" "compare_const_uta2"
571 (define_insn "compare_const_<mode>2"
572 [(set (reg:CC REG_CC)
573 (compare:CC (reg:ALL8 ACC_A)
574 (match_operand:ALL8 0 "const_operand" "n Ynn")))
575 (clobber (match_operand:QI 1 "register_operand" "=&d"))]
576 "reload_completed
577 && avr_have_dimode
578 && !s8_operand (operands[0], VOIDmode)"
579 {
580 return avr_out_compare64 (insn, operands, NULL);
581 }
582 [(set_attr "adjust_len" "compare64")])
583
584
585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
586 ;; Shifts and Rotate
587 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
588
589 (define_code_iterator di_shifts
590 [ashift ashiftrt lshiftrt rotate])
591
592 ;; Shift functions from libgcc are called without defining these insns,
593 ;; but with them we can describe their reduced register footprint.
594
595 ;; "ashldi3" "ashrdi3" "lshrdi3" "rotldi3"
596 ;; "ashldq3" "ashrdq3" "lshrdq3" "rotldq3"
597 ;; "ashlda3" "ashrda3" "lshrda3" "rotlda3"
598 ;; "ashlta3" "ashrta3" "lshrta3" "rotlta3"
599 ;; "ashludq3" "ashrudq3" "lshrudq3" "rotludq3"
600 ;; "ashluda3" "ashruda3" "lshruda3" "rotluda3"
601 ;; "ashluta3" "ashruta3" "lshruta3" "rotluta3"
602 (define_expand "<code_stdname><mode>3"
603 [(parallel [(match_operand:ALL8 0 "general_operand" "")
604 (di_shifts:ALL8 (match_operand:ALL8 1 "nop_general_operand")
605 (match_operand:QI 2 "nop_general_operand"))])]
606 "avr_have_dimode"
607 {
608 rtx acc_a = gen_rtx_REG (<MODE>mode, ACC_A);
609
610 avr_fix_inputs (operands, 1 << 2, regmask (<MODE>mode, ACC_A));
611 emit_move_insn (acc_a, operands[1]);
612 emit_move_insn (gen_rtx_REG (QImode, 16), operands[2]);
613 emit_insn (gen_<code_stdname><mode>3_insn ());
614 emit_move_insn (operands[0], acc_a);
615 DONE;
616 })
617
618 ;; "ashldi3_insn" "ashrdi3_insn" "lshrdi3_insn" "rotldi3_insn"
619 ;; "ashldq3_insn" "ashrdq3_insn" "lshrdq3_insn" "rotldq3_insn"
620 ;; "ashlda3_insn" "ashrda3_insn" "lshrda3_insn" "rotlda3_insn"
621 ;; "ashlta3_insn" "ashrta3_insn" "lshrta3_insn" "rotlta3_insn"
622 ;; "ashludq3_insn" "ashrudq3_insn" "lshrudq3_insn" "rotludq3_insn"
623 ;; "ashluda3_insn" "ashruda3_insn" "lshruda3_insn" "rotluda3_insn"
624 ;; "ashluta3_insn" "ashruta3_insn" "lshruta3_insn" "rotluta3_insn"
625 (define_insn_and_split "<code_stdname><mode>3_insn"
626 [(set (reg:ALL8 ACC_A)
627 (di_shifts:ALL8 (reg:ALL8 ACC_A)
628 (reg:QI 16)))]
629 "avr_have_dimode"
630 "#"
631 "&& reload_completed"
632 [(parallel [(set (reg:ALL8 ACC_A)
633 (di_shifts:ALL8 (reg:ALL8 ACC_A)
634 (reg:QI 16)))
635 (clobber (reg:CC REG_CC))])])
636
637 (define_insn "*<code_stdname><mode>3_insn"
638 [(set (reg:ALL8 ACC_A)
639 (di_shifts:ALL8 (reg:ALL8 ACC_A)
640 (reg:QI 16)))
641 (clobber (reg:CC REG_CC))]
642 "avr_have_dimode && reload_completed"
643 "%~call __<code_stdname>di3"
644 [(set_attr "adjust_len" "call")])
645
646 ;; "umulsidi3"
647 ;; "mulsidi3"
648 (define_expand "<extend_u>mulsidi3"
649 [(parallel [(match_operand:DI 0 "register_operand" "")
650 (match_operand:SI 1 "nop_general_operand")
651 (match_operand:SI 2 "nop_general_operand")
652 ;; Just to mention the iterator
653 (clobber (any_extend:SI (match_dup 1)))])]
654 "avr_have_dimode
655 && AVR_HAVE_MUL"
656 {
657 avr_fix_inputs (operands, 1 << 2, regmask (SImode, 22));
658 emit_move_insn (gen_rtx_REG (SImode, 22), operands[1]);
659 emit_move_insn (gen_rtx_REG (SImode, 18), operands[2]);
660 emit_insn (gen_<extend_u>mulsidi3_insn());
661 // Use emit_move_insn and not open-coded expand because of missing movdi
662 emit_move_insn (operands[0], gen_rtx_REG (DImode, ACC_A));
663 DONE;
664 })
665
666 ;; "umulsidi3_insn"
667 ;; "mulsidi3_insn"
668
669 (define_insn_and_split "<extend_u>mulsidi3_insn"
670 [(set (reg:DI ACC_A)
671 (mult:DI (any_extend:DI (reg:SI 18))
672 (any_extend:DI (reg:SI 22))))
673 (clobber (reg:HI REG_X))
674 (clobber (reg:HI REG_Z))]
675 "avr_have_dimode
676 && AVR_HAVE_MUL"
677 "#"
678 "&& reload_completed"
679 [(parallel [(set (reg:DI ACC_A)
680 (mult:DI (any_extend:DI (reg:SI 18))
681 (any_extend:DI (reg:SI 22))))
682 (clobber (reg:HI REG_X))
683 (clobber (reg:HI REG_Z))
684 (clobber (reg:CC REG_CC))])])
685
686 (define_insn "*<extend_u>mulsidi3_insn"
687 [(set (reg:DI ACC_A)
688 (mult:DI (any_extend:DI (reg:SI 18))
689 (any_extend:DI (reg:SI 22))))
690 (clobber (reg:HI REG_X))
691 (clobber (reg:HI REG_Z))
692 (clobber (reg:CC REG_CC))]
693 "avr_have_dimode
694 && AVR_HAVE_MUL
695 && reload_completed"
696 "%~call __<extend_u>mulsidi3"
697 [(set_attr "adjust_len" "call")])