1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
;; Machine description for GNU compiler,
;; for Atmel AVR micro controllers.
;; Copyright (C) 1998 - 2011
;; Free Software Foundation, Inc.
;; Contributed by Georg Lay (avr@gjlay.de)
;;
;; This file is part of GCC.
;;
;; GCC is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; GCC is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GCC; see the file COPYING3. If not see
;; <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The purpose of this file is to provide a light-weight DImode
;; implementation for AVR. The trouble with DImode is that tree -> RTL
;; lowering leads to really unpleasant code for operations that don't
;; work byte-wise like NEG, PLUS, MINUS, etc. Defining optabs entries for
;; them won't help because the optab machinery assumes these operations
;; are cheap and does not check if a libgcc implementation is available.
;;
;; The DImode insns are all straight forward -- except movdi. The approach
;; of this implementation is to provide DImode insns without the burden of
;; introducing movdi.
;;
;; The caveat is that if there are insns for some mode, there must also be a
;; respective move insn that describes reloads. Therefore, this
;; implementation uses an accumulator-based model with two hard-coded,
;; accumulator-like registers
;;
;; A[] = reg:DI 18
;; B[] = reg:DI 10
;;
;; so that no DImode insn contains pseudos or needs reloading.
(define_constants
[(ACC_A 18)
(ACC_B 10)])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Addition
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define_expand "adddi3"
[(parallel [(match_operand:DI 0 "general_operand" "")
(match_operand:DI 1 "general_operand" "")
(match_operand:DI 2 "general_operand" "")])]
"avr_have_dimode"
{
rtx acc_a = gen_rtx_REG (DImode, ACC_A);
emit_move_insn (acc_a, operands[1]);
if (s8_operand (operands[2], VOIDmode))
{
emit_move_insn (gen_rtx_REG (QImode, REG_X), operands[2]);
emit_insn (gen_adddi3_const8_insn ());
}
else if (CONST_INT_P (operands[2])
|| CONST_DOUBLE_P (operands[2]))
{
emit_insn (gen_adddi3_const_insn (operands[2]));
}
else
{
emit_move_insn (gen_rtx_REG (DImode, ACC_B), operands[2]);
emit_insn (gen_adddi3_insn ());
}
emit_move_insn (operands[0], acc_a);
DONE;
})
(define_insn "adddi3_insn"
[(set (reg:DI ACC_A)
(plus:DI (reg:DI ACC_A)
(reg:DI ACC_B)))]
"avr_have_dimode"
"%~call __adddi3"
[(set_attr "adjust_len" "call")
(set_attr "cc" "clobber")])
(define_insn "adddi3_const8_insn"
[(set (reg:DI ACC_A)
(plus:DI (reg:DI ACC_A)
(sign_extend:DI (reg:QI REG_X))))]
"avr_have_dimode"
"%~call __adddi3_s8"
[(set_attr "adjust_len" "call")
(set_attr "cc" "clobber")])
(define_insn "adddi3_const_insn"
[(set (reg:DI ACC_A)
(plus:DI (reg:DI ACC_A)
(match_operand:DI 0 "const_double_operand" "n")))]
"avr_have_dimode
&& !s8_operand (operands[0], VOIDmode)"
{
return avr_out_plus64 (operands[0], NULL);
}
[(set_attr "adjust_len" "plus64")
(set_attr "cc" "clobber")])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Subtraction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define_expand "subdi3"
[(parallel [(match_operand:DI 0 "general_operand" "")
(match_operand:DI 1 "general_operand" "")
(match_operand:DI 2 "general_operand" "")])]
"avr_have_dimode"
{
rtx acc_a = gen_rtx_REG (DImode, ACC_A);
emit_move_insn (acc_a, operands[1]);
emit_move_insn (gen_rtx_REG (DImode, ACC_B), operands[2]);
emit_insn (gen_subdi3_insn ());
emit_move_insn (operands[0], acc_a);
DONE;
})
(define_insn "subdi3_insn"
[(set (reg:DI ACC_A)
(minus:DI (reg:DI ACC_A)
(reg:DI ACC_B)))]
"avr_have_dimode"
"%~call __subdi3"
[(set_attr "adjust_len" "call")
(set_attr "cc" "set_czn")])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Negation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define_expand "negdi2"
[(parallel [(match_operand:DI 0 "general_operand" "")
(match_operand:DI 1 "general_operand" "")])]
"avr_have_dimode"
{
rtx acc_a = gen_rtx_REG (DImode, ACC_A);
emit_move_insn (acc_a, operands[1]);
emit_insn (gen_negdi2_insn ());
emit_move_insn (operands[0], acc_a);
DONE;
})
(define_insn "negdi2_insn"
[(set (reg:DI ACC_A)
(neg:DI (reg:DI ACC_A)))]
"avr_have_dimode"
"%~call __negdi2"
[(set_attr "adjust_len" "call")
(set_attr "cc" "clobber")])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Comparison
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define_expand "conditional_jump"
[(set (pc)
(if_then_else
(match_operator 0 "ordered_comparison_operator" [(cc0)
(const_int 0)])
(label_ref (match_operand 1 "" ""))
(pc)))]
"avr_have_dimode")
(define_expand "cbranchdi4"
[(parallel [(match_operand:DI 1 "register_operand" "")
(match_operand:DI 2 "nonmemory_operand" "")
(match_operator 0 "ordered_comparison_operator" [(cc0)
(const_int 0)])
(label_ref (match_operand 3 "" ""))])]
"avr_have_dimode"
{
rtx acc_a = gen_rtx_REG (DImode, ACC_A);
emit_move_insn (acc_a, operands[1]);
if (s8_operand (operands[2], VOIDmode))
{
emit_move_insn (gen_rtx_REG (QImode, REG_X), operands[2]);
emit_insn (gen_compare_const8_di2 ());
}
else if (CONST_INT_P (operands[2])
|| CONST_DOUBLE_P (operands[2]))
{
emit_insn (gen_compare_const_di2 (operands[2]));
}
else
{
emit_move_insn (gen_rtx_REG (DImode, ACC_B), operands[2]);
emit_insn (gen_compare_di2 ());
}
emit_jump_insn (gen_conditional_jump (operands[0], operands[3]));
DONE;
})
(define_insn "compare_di2"
[(set (cc0)
(compare (reg:DI ACC_A)
(reg:DI ACC_B)))]
"avr_have_dimode"
"%~call __cmpdi2"
[(set_attr "adjust_len" "call")
(set_attr "cc" "compare")])
(define_insn "compare_const8_di2"
[(set (cc0)
(compare (reg:DI ACC_A)
(sign_extend:DI (reg:QI REG_X))))]
"avr_have_dimode"
"%~call __cmpdi2_s8"
[(set_attr "adjust_len" "call")
(set_attr "cc" "compare")])
(define_insn "compare_const_di2"
[(set (cc0)
(compare (reg:DI ACC_A)
(match_operand:DI 0 "const_double_operand" "n")))
(clobber (match_scratch:QI 1 "=&d"))]
"avr_have_dimode
&& !s8_operand (operands[0], VOIDmode)"
{
return avr_out_compare64 (insn, operands, NULL);
}
[(set_attr "adjust_len" "compare64")
(set_attr "cc" "compare")])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Shifts and Rotate
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define_code_iterator di_shifts
[ashift ashiftrt lshiftrt rotate])
;; Shift functions from libgcc are called without defining these insns,
;; but with them we can describe their reduced register footprint.
;; "ashldi3"
;; "ashrdi3"
;; "lshrdi3"
;; "rotldi3"
(define_expand "<code_stdname>di3"
[(parallel [(match_operand:DI 0 "general_operand" "")
(di_shifts:DI (match_operand:DI 1 "general_operand" "")
(match_operand:QI 2 "general_operand" ""))])]
"avr_have_dimode"
{
rtx acc_a = gen_rtx_REG (DImode, ACC_A);
emit_move_insn (acc_a, operands[1]);
emit_move_insn (gen_rtx_REG (QImode, 16), operands[2]);
emit_insn (gen_<code_stdname>di3_insn ());
emit_move_insn (operands[0], acc_a);
DONE;
})
(define_insn "<code_stdname>di3_insn"
[(set (reg:DI ACC_A)
(di_shifts:DI (reg:DI ACC_A)
(reg:QI 16)))]
"avr_have_dimode"
"%~call __<code_stdname>di3"
[(set_attr "adjust_len" "call")
(set_attr "cc" "clobber")])
|