cb4c823af0dc4c6bdf20f864e5960b6537ac16a2
[openwrt.git] / toolchain / gcc / patches / 4.3.5 / 930-avr32_support.patch
1 --- a/gcc/builtins.c
2 +++ b/gcc/builtins.c
3 @@ -10779,7 +10779,7 @@ validate_arglist (const_tree callexpr, .
4
5 do
6 {
7 - code = va_arg (ap, enum tree_code);
8 + code = va_arg (ap, int);
9 switch (code)
10 {
11 case 0:
12 --- a/gcc/calls.c
13 +++ b/gcc/calls.c
14 @@ -3496,7 +3496,7 @@ emit_library_call_value_1 (int retval, r
15 for (; count < nargs; count++)
16 {
17 rtx val = va_arg (p, rtx);
18 - enum machine_mode mode = va_arg (p, enum machine_mode);
19 + enum machine_mode mode = va_arg (p, int);
20
21 /* We cannot convert the arg value to the mode the library wants here;
22 must do it earlier where we know the signedness of the arg. */
23 --- /dev/null
24 +++ b/gcc/config/avr32/avr32.c
25 @@ -0,0 +1,8018 @@
26 +/*
27 + Target hooks and helper functions for AVR32.
28 + Copyright 2003,2004,2005,2006,2007,2008,2009,2010 Atmel Corporation.
29 +
30 + This file is part of GCC.
31 +
32 + This program is free software; you can redistribute it and/or modify
33 + it under the terms of the GNU General Public License as published by
34 + the Free Software Foundation; either version 2 of the License, or
35 + (at your option) any later version.
36 +
37 + This program is distributed in the hope that it will be useful,
38 + but WITHOUT ANY WARRANTY; without even the implied warranty of
39 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 + GNU General Public License for more details.
41 +
42 + You should have received a copy of the GNU General Public License
43 + along with this program; if not, write to the Free Software
44 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
45 +
46 +#include "config.h"
47 +#include "system.h"
48 +#include "coretypes.h"
49 +#include "tm.h"
50 +#include "rtl.h"
51 +#include "tree.h"
52 +#include "obstack.h"
53 +#include "regs.h"
54 +#include "hard-reg-set.h"
55 +#include "real.h"
56 +#include "insn-config.h"
57 +#include "conditions.h"
58 +#include "output.h"
59 +#include "insn-attr.h"
60 +#include "flags.h"
61 +#include "reload.h"
62 +#include "function.h"
63 +#include "expr.h"
64 +#include "optabs.h"
65 +#include "toplev.h"
66 +#include "recog.h"
67 +#include "ggc.h"
68 +#include "except.h"
69 +#include "c-pragma.h"
70 +#include "integrate.h"
71 +#include "tm_p.h"
72 +#include "langhooks.h"
73 +#include "hooks.h"
74 +#include "df.h"
75 +
76 +#include "target.h"
77 +#include "target-def.h"
78 +
79 +#include <ctype.h>
80 +
81 +
82 +
83 +/* Global variables. */
84 +typedef struct minipool_node Mnode;
85 +typedef struct minipool_fixup Mfix;
86 +
87 +/* Obstack for minipool constant handling. */
88 +static struct obstack minipool_obstack;
89 +static char *minipool_startobj;
90 +static rtx minipool_vector_label;
91 +
92 +/* True if we are currently building a constant table. */
93 +int making_const_table;
94 +
95 +tree fndecl_attribute_args = NULL_TREE;
96 +
97 +
98 +/* Function prototypes. */
99 +static unsigned long avr32_isr_value (tree);
100 +static unsigned long avr32_compute_func_type (void);
101 +static tree avr32_handle_isr_attribute (tree *, tree, tree, int, bool *);
102 +static tree avr32_handle_acall_attribute (tree *, tree, tree, int, bool *);
103 +static tree avr32_handle_fndecl_attribute (tree * node, tree name, tree args,
104 + int flags, bool * no_add_attrs);
105 +static void avr32_reorg (void);
106 +bool avr32_return_in_msb (tree type);
107 +bool avr32_vector_mode_supported (enum machine_mode mode);
108 +static void avr32_init_libfuncs (void);
109 +static void avr32_file_end (void);
110 +static void flashvault_decl_list_add (unsigned int vector_num, const char *name);
111 +
112 +
113 +
114 +static void
115 +avr32_add_gc_roots (void)
116 +{
117 + gcc_obstack_init (&minipool_obstack);
118 + minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
119 +}
120 +
121 +
122 +/* List of all known AVR32 parts */
123 +static const struct part_type_s avr32_part_types[] = {
124 + /* name, part_type, architecture type, macro */
125 + {"none", PART_TYPE_AVR32_NONE, ARCH_TYPE_AVR32_AP, "__AVR32__"},
126 + {"ap7000", PART_TYPE_AVR32_AP7000, ARCH_TYPE_AVR32_AP, "__AVR32_AP7000__"},
127 + {"ap7001", PART_TYPE_AVR32_AP7001, ARCH_TYPE_AVR32_AP, "__AVR32_AP7001__"},
128 + {"ap7002", PART_TYPE_AVR32_AP7002, ARCH_TYPE_AVR32_AP, "__AVR32_AP7002__"},
129 + {"ap7200", PART_TYPE_AVR32_AP7200, ARCH_TYPE_AVR32_AP, "__AVR32_AP7200__"},
130 + {"uc3a0128", PART_TYPE_AVR32_UC3A0128, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A0128__"},
131 + {"uc3a0256", PART_TYPE_AVR32_UC3A0256, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A0256__"},
132 + {"uc3a0512", PART_TYPE_AVR32_UC3A0512, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A0512__"},
133 + {"uc3a0512es", PART_TYPE_AVR32_UC3A0512ES, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3A0512ES__"},
134 + {"uc3a1128", PART_TYPE_AVR32_UC3A1128, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A1128__"},
135 + {"uc3a1256", PART_TYPE_AVR32_UC3A1256, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A1256__"},
136 + {"uc3a1512", PART_TYPE_AVR32_UC3A1512, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A1512__"},
137 + {"uc3a1512es", PART_TYPE_AVR32_UC3A1512ES, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3A1512ES__"},
138 + {"uc3a3revd", PART_TYPE_AVR32_UC3A3REVD, ARCH_TYPE_AVR32_UCR2NOMUL, "__AVR32_UC3A3256S__"},
139 + {"uc3a364", PART_TYPE_AVR32_UC3A364, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A364__"},
140 + {"uc3a364s", PART_TYPE_AVR32_UC3A364S, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A364S__"},
141 + {"uc3a3128", PART_TYPE_AVR32_UC3A3128, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A3128__"},
142 + {"uc3a3128s", PART_TYPE_AVR32_UC3A3128S, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A3128S__"},
143 + {"uc3a3256", PART_TYPE_AVR32_UC3A3256, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A3256__"},
144 + {"uc3a3256s", PART_TYPE_AVR32_UC3A3256S, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A3256S__"},
145 + {"uc3b064", PART_TYPE_AVR32_UC3B064, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B064__"},
146 + {"uc3b0128", PART_TYPE_AVR32_UC3B0128, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B0128__"},
147 + {"uc3b0256", PART_TYPE_AVR32_UC3B0256, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B0256__"},
148 + {"uc3b0256es", PART_TYPE_AVR32_UC3B0256ES, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B0256ES__"},
149 + {"uc3b0512", PART_TYPE_AVR32_UC3B0512, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3B0512__"},
150 + {"uc3b0512revc", PART_TYPE_AVR32_UC3B0512REVC, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3B0512REVC__"},
151 + {"uc3b164", PART_TYPE_AVR32_UC3B164, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B164__"},
152 + {"uc3b1128", PART_TYPE_AVR32_UC3B1128, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B1128__"},
153 + {"uc3b1256", PART_TYPE_AVR32_UC3B1256, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B1256__"},
154 + {"uc3b1256es", PART_TYPE_AVR32_UC3B1256ES, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B1256ES__"},
155 + {"uc3b1512", PART_TYPE_AVR32_UC3B1512, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3B1512__"},
156 + {"uc3b1512revc", PART_TYPE_AVR32_UC3B1512REVC, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3B1512REVC__"},
157 + {"uc3c0512crevc", PART_TYPE_AVR32_UC3C0512CREVC, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C0512CREVC__"},
158 + {"uc3c1512crevc", PART_TYPE_AVR32_UC3C1512CREVC, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C1512CREVC__"},
159 + {"uc3c2512crevc", PART_TYPE_AVR32_UC3C2512CREVC, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C2512CREVC__"},
160 + {"uc3l0256", PART_TYPE_AVR32_UC3L0256, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3L0256__"},
161 + {"uc3l0128", PART_TYPE_AVR32_UC3L0128, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3L0128__"},
162 + {"uc3l064", PART_TYPE_AVR32_UC3L064, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3L064__"},
163 + {"uc3l032", PART_TYPE_AVR32_UC3L032, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3L032__"},
164 + {"uc3l016", PART_TYPE_AVR32_UC3L016, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3L016__"},
165 + {"uc3l064revb", PART_TYPE_AVR32_UC3L064, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3L064REVB__"},
166 + {"uc3c064c", PART_TYPE_AVR32_UC3C064C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C064C__"},
167 + {"uc3c0128c", PART_TYPE_AVR32_UC3C0128C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C0128C__"},
168 + {"uc3c0256c", PART_TYPE_AVR32_UC3C0256C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C0256C__"},
169 + {"uc3c0512c", PART_TYPE_AVR32_UC3C0512C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C0512C__"},
170 + {"uc3c164c", PART_TYPE_AVR32_UC3C164C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C164C__"},
171 + {"uc3c1128c", PART_TYPE_AVR32_UC3C1128C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C1128C__"},
172 + {"uc3c1256c", PART_TYPE_AVR32_UC3C1256C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C1256C__"},
173 + {"uc3c1512c", PART_TYPE_AVR32_UC3C1512C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C1512C__"},
174 + {"uc3c264c", PART_TYPE_AVR32_UC3C264C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C264C__"},
175 + {"uc3c2128c", PART_TYPE_AVR32_UC3C2128C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C2128C__"},
176 + {"uc3c2256c", PART_TYPE_AVR32_UC3C2256C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C2256C__"},
177 + {"uc3c2512c", PART_TYPE_AVR32_UC3C2512C, ARCH_TYPE_AVR32_UCR3FP, "__AVR32_UC3C2512C__"},
178 + {"mxt768e", PART_TYPE_AVR32_MXT768E, ARCH_TYPE_AVR32_UCR3, "__AVR32_MXT768E__"},
179 + {NULL, 0, 0, NULL}
180 +};
181 +
182 +/* List of all known AVR32 architectures */
183 +static const struct arch_type_s avr32_arch_types[] = {
184 + /* name, architecture type, microarchitecture type, feature flags, macro */
185 + {"ap", ARCH_TYPE_AVR32_AP, UARCH_TYPE_AVR32B,
186 + (FLAG_AVR32_HAS_DSP
187 + | FLAG_AVR32_HAS_SIMD
188 + | FLAG_AVR32_HAS_UNALIGNED_WORD
189 + | FLAG_AVR32_HAS_BRANCH_PRED | FLAG_AVR32_HAS_RETURN_STACK
190 + | FLAG_AVR32_HAS_CACHES),
191 + "__AVR32_AP__"},
192 + {"ucr1", ARCH_TYPE_AVR32_UCR1, UARCH_TYPE_AVR32A,
193 + (FLAG_AVR32_HAS_DSP | FLAG_AVR32_HAS_RMW),
194 + "__AVR32_UC__=1"},
195 + {"ucr2", ARCH_TYPE_AVR32_UCR2, UARCH_TYPE_AVR32A,
196 + (FLAG_AVR32_HAS_DSP | FLAG_AVR32_HAS_RMW
197 + | FLAG_AVR32_HAS_V2_INSNS),
198 + "__AVR32_UC__=2"},
199 + {"ucr2nomul", ARCH_TYPE_AVR32_UCR2NOMUL, UARCH_TYPE_AVR32A,
200 + (FLAG_AVR32_HAS_DSP | FLAG_AVR32_HAS_RMW
201 + | FLAG_AVR32_HAS_V2_INSNS | FLAG_AVR32_HAS_NO_MUL_INSNS),
202 + "__AVR32_UC__=2"},
203 + {"ucr3", ARCH_TYPE_AVR32_UCR3, UARCH_TYPE_AVR32A,
204 + (FLAG_AVR32_HAS_DSP | FLAG_AVR32_HAS_RMW
205 + | FLAG_AVR32_HAS_V2_INSNS),
206 + "__AVR32_UC__=3"},
207 + {"ucr3fp", ARCH_TYPE_AVR32_UCR3FP, UARCH_TYPE_AVR32A,
208 + (FLAG_AVR32_HAS_DSP | FLAG_AVR32_HAS_RMW | FLAG_AVR32_HAS_FPU
209 + | FLAG_AVR32_HAS_V2_INSNS),
210 + "__AVR32_UC__=3"},
211 + {NULL, 0, 0, 0, NULL}
212 +};
213 +
214 +/* Default arch name */
215 +const char *avr32_arch_name = "none";
216 +const char *avr32_part_name = "none";
217 +
218 +const struct part_type_s *avr32_part;
219 +const struct arch_type_s *avr32_arch;
220 +
221 +
222 +/* FIXME: needs to use GC. */
223 +struct flashvault_decl_list
224 +{
225 + struct flashvault_decl_list *next;
226 + unsigned int vector_num;
227 + const char *name;
228 +};
229 +
230 +static struct flashvault_decl_list *flashvault_decl_list_head = NULL;
231 +
232 +
233 +/* Set default target_flags. */
234 +#undef TARGET_DEFAULT_TARGET_FLAGS
235 +#define TARGET_DEFAULT_TARGET_FLAGS \
236 + (MASK_HAS_ASM_ADDR_PSEUDOS | MASK_MD_REORG_OPTIMIZATION | MASK_COND_EXEC_BEFORE_RELOAD)
237 +
238 +void
239 +avr32_optimization_options (int level, int size)
240 +{
241 + if (AVR32_ALWAYS_PIC)
242 + flag_pic = 1;
243 +
244 + /* Enable section anchors if optimization is enabled. */
245 + if (level > 0 || size)
246 + flag_section_anchors = 1;
247 +}
248 +
249 +
250 +/* Override command line options */
251 +void
252 +avr32_override_options (void)
253 +{
254 + const struct part_type_s *part;
255 + const struct arch_type_s *arch;
256 +
257 + /*Add backward compability*/
258 + if (strcmp ("uc", avr32_arch_name)== 0)
259 + {
260 + fprintf (stderr, "Warning: Deprecated arch `%s' specified. "
261 + "Please use '-march=ucr1' instead. "
262 + "Converting to arch 'ucr1'\n",
263 + avr32_arch_name);
264 + avr32_arch_name="ucr1";
265 + }
266 +
267 + /* Check if arch type is set. */
268 + for (arch = avr32_arch_types; arch->name; arch++)
269 + {
270 + if (strcmp (arch->name, avr32_arch_name) == 0)
271 + break;
272 + }
273 + avr32_arch = arch;
274 +
275 + if (!arch->name && strcmp("none", avr32_arch_name) != 0)
276 + {
277 + fprintf (stderr, "Unknown arch `%s' specified\n"
278 + "Known arch names:\n"
279 + "\tuc (deprecated)\n",
280 + avr32_arch_name);
281 + for (arch = avr32_arch_types; arch->name; arch++)
282 + fprintf (stderr, "\t%s\n", arch->name);
283 + avr32_arch = &avr32_arch_types[ARCH_TYPE_AVR32_AP];
284 + }
285 +
286 + /* Check if part type is set. */
287 + for (part = avr32_part_types; part->name; part++)
288 + if (strcmp (part->name, avr32_part_name) == 0)
289 + break;
290 +
291 + avr32_part = part;
292 + if (!part->name)
293 + {
294 + fprintf (stderr, "Unknown part `%s' specified\nKnown part names:\n",
295 + avr32_part_name);
296 + for (part = avr32_part_types; part->name; part++)
297 + {
298 + if (strcmp("none", part->name) != 0)
299 + fprintf (stderr, "\t%s\n", part->name);
300 + }
301 + /* Set default to NONE*/
302 + avr32_part = &avr32_part_types[PART_TYPE_AVR32_NONE];
303 + }
304 +
305 + /* NB! option -march= overrides option -mpart
306 + * if both are used at the same time */
307 + if (!arch->name)
308 + avr32_arch = &avr32_arch_types[avr32_part->arch_type];
309 +
310 + /* If optimization level is two or greater, then align start of loops to a
311 + word boundary since this will allow folding the first insn of the loop.
312 + Do this only for targets supporting branch prediction. */
313 + if (optimize >= 2 && TARGET_BRANCH_PRED)
314 + align_loops = 2;
315 +
316 +
317 + /* Enable fast-float library if unsafe math optimizations
318 + are used. */
319 + if (flag_unsafe_math_optimizations)
320 + target_flags |= MASK_FAST_FLOAT;
321 +
322 + /* Check if we should set avr32_imm_in_const_pool
323 + based on if caches are present or not. */
324 + if ( avr32_imm_in_const_pool == -1 )
325 + {
326 + if ( TARGET_CACHES )
327 + avr32_imm_in_const_pool = 1;
328 + else
329 + avr32_imm_in_const_pool = 0;
330 + }
331 +
332 + if (TARGET_NO_PIC)
333 + flag_pic = 0;
334 + avr32_add_gc_roots ();
335 +}
336 +
337 +
338 +/*
339 +If defined, a function that outputs the assembler code for entry to a
340 +function. The prologue is responsible for setting up the stack frame,
341 +initializing the frame pointer register, saving registers that must be
342 +saved, and allocating size additional bytes of storage for the
343 +local variables. size is an integer. file is a stdio
344 +stream to which the assembler code should be output.
345 +
346 +The label for the beginning of the function need not be output by this
347 +macro. That has already been done when the macro is run.
348 +
349 +To determine which registers to save, the macro can refer to the array
350 +regs_ever_live: element r is nonzero if hard register
351 +r is used anywhere within the function. This implies the function
352 +prologue should save register r, provided it is not one of the
353 +call-used registers. (TARGET_ASM_FUNCTION_EPILOGUE must likewise use
354 +regs_ever_live.)
355 +
356 +On machines that have ``register windows'', the function entry code does
357 +not save on the stack the registers that are in the windows, even if
358 +they are supposed to be preserved by function calls; instead it takes
359 +appropriate steps to ``push'' the register stack, if any non-call-used
360 +registers are used in the function.
361 +
362 +On machines where functions may or may not have frame-pointers, the
363 +function entry code must vary accordingly; it must set up the frame
364 +pointer if one is wanted, and not otherwise. To determine whether a
365 +frame pointer is in wanted, the macro can refer to the variable
366 +frame_pointer_needed. The variable's value will be 1 at run
367 +time in a function that needs a frame pointer. (see Elimination).
368 +
369 +The function entry code is responsible for allocating any stack space
370 +required for the function. This stack space consists of the regions
371 +listed below. In most cases, these regions are allocated in the
372 +order listed, with the last listed region closest to the top of the
373 +stack (the lowest address if STACK_GROWS_DOWNWARD is defined, and
374 +the highest address if it is not defined). You can use a different order
375 +for a machine if doing so is more convenient or required for
376 +compatibility reasons. Except in cases where required by standard
377 +or by a debugger, there is no reason why the stack layout used by GCC
378 +need agree with that used by other compilers for a machine.
379 +*/
380 +
381 +#undef TARGET_ASM_FUNCTION_PROLOGUE
382 +#define TARGET_ASM_FUNCTION_PROLOGUE avr32_target_asm_function_prologue
383 +
384 +#undef TARGET_ASM_FILE_END
385 +#define TARGET_ASM_FILE_END avr32_file_end
386 +
387 +#undef TARGET_DEFAULT_SHORT_ENUMS
388 +#define TARGET_DEFAULT_SHORT_ENUMS hook_bool_void_false
389 +
390 +#undef TARGET_PROMOTE_FUNCTION_ARGS
391 +#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
392 +
393 +#undef TARGET_PROMOTE_FUNCTION_RETURN
394 +#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
395 +
396 +#undef TARGET_PROMOTE_PROTOTYPES
397 +#define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
398 +
399 +#undef TARGET_MUST_PASS_IN_STACK
400 +#define TARGET_MUST_PASS_IN_STACK avr32_must_pass_in_stack
401 +
402 +#undef TARGET_PASS_BY_REFERENCE
403 +#define TARGET_PASS_BY_REFERENCE avr32_pass_by_reference
404 +
405 +#undef TARGET_STRICT_ARGUMENT_NAMING
406 +#define TARGET_STRICT_ARGUMENT_NAMING avr32_strict_argument_naming
407 +
408 +#undef TARGET_VECTOR_MODE_SUPPORTED_P
409 +#define TARGET_VECTOR_MODE_SUPPORTED_P avr32_vector_mode_supported
410 +
411 +#undef TARGET_RETURN_IN_MEMORY
412 +#define TARGET_RETURN_IN_MEMORY avr32_return_in_memory
413 +
414 +#undef TARGET_RETURN_IN_MSB
415 +#define TARGET_RETURN_IN_MSB avr32_return_in_msb
416 +
417 +#undef TARGET_ENCODE_SECTION_INFO
418 +#define TARGET_ENCODE_SECTION_INFO avr32_encode_section_info
419 +
420 +#undef TARGET_ARG_PARTIAL_BYTES
421 +#define TARGET_ARG_PARTIAL_BYTES avr32_arg_partial_bytes
422 +
423 +#undef TARGET_STRIP_NAME_ENCODING
424 +#define TARGET_STRIP_NAME_ENCODING avr32_strip_name_encoding
425 +
426 +#define streq(string1, string2) (strcmp (string1, string2) == 0)
427 +
428 +#undef TARGET_NARROW_VOLATILE_BITFIELD
429 +#define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
430 +
431 +#undef TARGET_ATTRIBUTE_TABLE
432 +#define TARGET_ATTRIBUTE_TABLE avr32_attribute_table
433 +
434 +#undef TARGET_COMP_TYPE_ATTRIBUTES
435 +#define TARGET_COMP_TYPE_ATTRIBUTES avr32_comp_type_attributes
436 +
437 +
438 +#undef TARGET_RTX_COSTS
439 +#define TARGET_RTX_COSTS avr32_rtx_costs
440 +
441 +#undef TARGET_CANNOT_FORCE_CONST_MEM
442 +#define TARGET_CANNOT_FORCE_CONST_MEM avr32_cannot_force_const_mem
443 +
444 +#undef TARGET_ASM_INTEGER
445 +#define TARGET_ASM_INTEGER avr32_assemble_integer
446 +
447 +#undef TARGET_FUNCTION_VALUE
448 +#define TARGET_FUNCTION_VALUE avr32_function_value
449 +
450 +#undef TARGET_MIN_ANCHOR_OFFSET
451 +#define TARGET_MIN_ANCHOR_OFFSET (0)
452 +
453 +#undef TARGET_MAX_ANCHOR_OFFSET
454 +#define TARGET_MAX_ANCHOR_OFFSET ((1 << 15) - 1)
455 +#undef TARGET_SECONDARY_RELOAD
456 +#define TARGET_SECONDARY_RELOAD avr32_secondary_reload
457 +
458 +enum reg_class
459 +avr32_secondary_reload (bool in_p, rtx x, enum reg_class class,
460 + enum machine_mode mode, secondary_reload_info *sri)
461 +{
462 +
463 + if ( avr32_rmw_memory_operand (x, mode) )
464 + {
465 + if (!in_p)
466 + sri->icode = CODE_FOR_reload_out_rmw_memory_operand;
467 + else
468 + sri->icode = CODE_FOR_reload_in_rmw_memory_operand;
469 + }
470 + return NO_REGS;
471 +
472 +}
473 +/*
474 + * Switches to the appropriate section for output of constant pool
475 + * entry x in mode. You can assume that x is some kind of constant in
476 + * RTL. The argument mode is redundant except in the case of a
477 + * const_int rtx. Select the section by calling readonly_data_ section
478 + * or one of the alternatives for other sections. align is the
479 + * constant alignment in bits.
480 + *
481 + * The default version of this function takes care of putting symbolic
482 + * constants in flag_ pic mode in data_section and everything else in
483 + * readonly_data_section.
484 + */
485 +//#undef TARGET_ASM_SELECT_RTX_SECTION
486 +//#define TARGET_ASM_SELECT_RTX_SECTION avr32_select_rtx_section
487 +
488 +
489 +/*
490 + * If non-null, this hook performs a target-specific pass over the
491 + * instruction stream. The compiler will run it at all optimization
492 + * levels, just before the point at which it normally does
493 + * delayed-branch scheduling.
494 + *
495 + * The exact purpose of the hook varies from target to target. Some
496 + * use it to do transformations that are necessary for correctness,
497 + * such as laying out in-function constant pools or avoiding hardware
498 + * hazards. Others use it as an opportunity to do some
499 + * machine-dependent optimizations.
500 + *
501 + * You need not implement the hook if it has nothing to do. The
502 + * default definition is null.
503 + */
504 +#undef TARGET_MACHINE_DEPENDENT_REORG
505 +#define TARGET_MACHINE_DEPENDENT_REORG avr32_reorg
506 +
507 +/* Target hook for assembling integer objects.
508 + Need to handle integer vectors */
509 +static bool
510 +avr32_assemble_integer (rtx x, unsigned int size, int aligned_p)
511 +{
512 + if (avr32_vector_mode_supported (GET_MODE (x)))
513 + {
514 + int i, units;
515 +
516 + if (GET_CODE (x) != CONST_VECTOR)
517 + abort ();
518 +
519 + units = CONST_VECTOR_NUNITS (x);
520 +
521 + switch (GET_MODE (x))
522 + {
523 + case V2HImode:
524 + size = 2;
525 + break;
526 + case V4QImode:
527 + size = 1;
528 + break;
529 + default:
530 + abort ();
531 + }
532 +
533 + for (i = 0; i < units; i++)
534 + {
535 + rtx elt;
536 +
537 + elt = CONST_VECTOR_ELT (x, i);
538 + assemble_integer (elt, size, i == 0 ? 32 : size * BITS_PER_UNIT, 1);
539 + }
540 +
541 + return true;
542 + }
543 +
544 + return default_assemble_integer (x, size, aligned_p);
545 +}
546 +
547 +
548 +/*
549 + * This target hook describes the relative costs of RTL expressions.
550 + *
551 + * The cost may depend on the precise form of the expression, which is
552 + * available for examination in x, and the rtx code of the expression
553 + * in which it is contained, found in outer_code. code is the
554 + * expression code--redundant, since it can be obtained with GET_CODE
555 + * (x).
556 + *
557 + * In implementing this hook, you can use the construct COSTS_N_INSNS
558 + * (n) to specify a cost equal to n fast instructions.
559 + *
560 + * On entry to the hook, *total contains a default estimate for the
561 + * cost of the expression. The hook should modify this value as
562 + * necessary. Traditionally, the default costs are COSTS_N_INSNS (5)
563 + * for multiplications, COSTS_N_INSNS (7) for division and modulus
564 + * operations, and COSTS_N_INSNS (1) for all other operations.
565 + *
566 + * When optimizing for code size, i.e. when optimize_size is non-zero,
567 + * this target hook should be used to estimate the relative size cost
568 + * of an expression, again relative to COSTS_N_INSNS.
569 + *
570 + * The hook returns true when all subexpressions of x have been
571 + * processed, and false when rtx_cost should recurse.
572 + */
573 +
574 +/* Worker routine for avr32_rtx_costs. */
575 +static inline int
576 +avr32_rtx_costs_1 (rtx x, enum rtx_code code ATTRIBUTE_UNUSED,
577 + enum rtx_code outer ATTRIBUTE_UNUSED)
578 +{
579 + enum machine_mode mode = GET_MODE (x);
580 +
581 + switch (GET_CODE (x))
582 + {
583 + case MEM:
584 + /* Using pre decrement / post increment memory operations on the
585 + avr32_uc architecture means that two writebacks must be performed
586 + and hence two cycles are needed. */
587 + if (!optimize_size
588 + && GET_MODE_SIZE (mode) <= 2 * UNITS_PER_WORD
589 + && TARGET_ARCH_UC
590 + && (GET_CODE (XEXP (x, 0)) == PRE_DEC
591 + || GET_CODE (XEXP (x, 0)) == POST_INC))
592 + return COSTS_N_INSNS (5);
593 +
594 + /* Memory costs quite a lot for the first word, but subsequent words
595 + load at the equivalent of a single insn each. */
596 + if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
597 + return COSTS_N_INSNS (3 + (GET_MODE_SIZE (mode) / UNITS_PER_WORD));
598 +
599 + return COSTS_N_INSNS (4);
600 + case SYMBOL_REF:
601 + case CONST:
602 + /* These are valid for the pseudo insns: lda.w and call which operates
603 + on direct addresses. We assume that the cost of a lda.w is the same
604 + as the cost of a ld.w insn. */
605 + return (outer == SET) ? COSTS_N_INSNS (4) : COSTS_N_INSNS (1);
606 + case DIV:
607 + case MOD:
608 + case UDIV:
609 + case UMOD:
610 + return optimize_size ? COSTS_N_INSNS (1) : COSTS_N_INSNS (16);
611 +
612 + case ROTATE:
613 + case ROTATERT:
614 + if (mode == TImode)
615 + return COSTS_N_INSNS (100);
616 +
617 + if (mode == DImode)
618 + return COSTS_N_INSNS (10);
619 + return COSTS_N_INSNS (4);
620 + case ASHIFT:
621 + case LSHIFTRT:
622 + case ASHIFTRT:
623 + case NOT:
624 + if (mode == TImode)
625 + return COSTS_N_INSNS (10);
626 +
627 + if (mode == DImode)
628 + return COSTS_N_INSNS (4);
629 + return COSTS_N_INSNS (1);
630 + case PLUS:
631 + case MINUS:
632 + case NEG:
633 + case COMPARE:
634 + case ABS:
635 + if (GET_MODE_CLASS (mode) == MODE_FLOAT)
636 + return COSTS_N_INSNS (100);
637 +
638 + if (mode == TImode)
639 + return COSTS_N_INSNS (50);
640 +
641 + if (mode == DImode)
642 + return COSTS_N_INSNS (2);
643 + return COSTS_N_INSNS (1);
644 +
645 + case MULT:
646 + {
647 + if (GET_MODE_CLASS (mode) == MODE_FLOAT)
648 + return COSTS_N_INSNS (300);
649 +
650 + if (mode == TImode)
651 + return COSTS_N_INSNS (16);
652 +
653 + if (mode == DImode)
654 + return COSTS_N_INSNS (4);
655 +
656 + if (mode == HImode)
657 + return COSTS_N_INSNS (2);
658 +
659 + return COSTS_N_INSNS (3);
660 + }
661 + case IF_THEN_ELSE:
662 + if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC)
663 + return COSTS_N_INSNS (4);
664 + return COSTS_N_INSNS (1);
665 + case SIGN_EXTEND:
666 + case ZERO_EXTEND:
667 + /* Sign/Zero extensions of registers cost quite much since these
668 + instrcutions only take one register operand which means that gcc
669 + often must insert some move instrcutions */
670 + if (mode == QImode || mode == HImode)
671 + return (COSTS_N_INSNS (GET_CODE (XEXP (x, 0)) == MEM ? 0 : 1));
672 + return COSTS_N_INSNS (4);
673 + case UNSPEC:
674 + /* divmod operations */
675 + if (XINT (x, 1) == UNSPEC_UDIVMODSI4_INTERNAL
676 + || XINT (x, 1) == UNSPEC_DIVMODSI4_INTERNAL)
677 + {
678 + return optimize_size ? COSTS_N_INSNS (1) : COSTS_N_INSNS (16);
679 + }
680 + /* Fallthrough */
681 + default:
682 + return COSTS_N_INSNS (1);
683 + }
684 +}
685 +
686 +
687 +static bool
688 +avr32_rtx_costs (rtx x, int code, int outer_code, int *total)
689 +{
690 + *total = avr32_rtx_costs_1 (x, code, outer_code);
691 + return true;
692 +}
693 +
694 +
695 +bool
696 +avr32_cannot_force_const_mem (rtx x ATTRIBUTE_UNUSED)
697 +{
698 + /* Do not want symbols in the constant pool when compiling pic or if using
699 + address pseudo instructions. */
700 + return ((flag_pic || TARGET_HAS_ASM_ADDR_PSEUDOS)
701 + && avr32_find_symbol (x) != NULL_RTX);
702 +}
703 +
704 +
705 +/* Table of machine attributes. */
706 +const struct attribute_spec avr32_attribute_table[] = {
707 + /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
708 + /* Interrupt Service Routines have special prologue and epilogue
709 + requirements. */
710 + {"isr", 0, 1, false, false, false, avr32_handle_isr_attribute},
711 + {"interrupt", 0, 1, false, false, false, avr32_handle_isr_attribute},
712 + {"acall", 0, 1, false, true, true, avr32_handle_acall_attribute},
713 + {"naked", 0, 0, true, false, false, avr32_handle_fndecl_attribute},
714 + {"rmw_addressable", 0, 0, true, false, false, NULL},
715 + {"flashvault", 0, 1, true, false, false, avr32_handle_fndecl_attribute},
716 + {"flashvault_impl", 0, 1, true, false, false, avr32_handle_fndecl_attribute},
717 + {NULL, 0, 0, false, false, false, NULL}
718 +};
719 +
720 +
721 +typedef struct
722 +{
723 + const char *const arg;
724 + const unsigned long return_value;
725 +}
726 +isr_attribute_arg;
727 +
728 +
729 +static const isr_attribute_arg isr_attribute_args[] = {
730 + {"FULL", AVR32_FT_ISR_FULL},
731 + {"full", AVR32_FT_ISR_FULL},
732 + {"HALF", AVR32_FT_ISR_HALF},
733 + {"half", AVR32_FT_ISR_HALF},
734 + {"NONE", AVR32_FT_ISR_NONE},
735 + {"none", AVR32_FT_ISR_NONE},
736 + {"UNDEF", AVR32_FT_ISR_NONE},
737 + {"undef", AVR32_FT_ISR_NONE},
738 + {"SWI", AVR32_FT_ISR_NONE},
739 + {"swi", AVR32_FT_ISR_NONE},
740 + {NULL, AVR32_FT_ISR_NONE}
741 +};
742 +
743 +
744 +/* Returns the (interrupt) function type of the current
745 + function, or AVR32_FT_UNKNOWN if the type cannot be determined. */
746 +static unsigned long
747 +avr32_isr_value (tree argument)
748 +{
749 + const isr_attribute_arg *ptr;
750 + const char *arg;
751 +
752 + /* No argument - default to ISR_NONE. */
753 + if (argument == NULL_TREE)
754 + return AVR32_FT_ISR_NONE;
755 +
756 + /* Get the value of the argument. */
757 + if (TREE_VALUE (argument) == NULL_TREE
758 + || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
759 + return AVR32_FT_UNKNOWN;
760 +
761 + arg = TREE_STRING_POINTER (TREE_VALUE (argument));
762 +
763 + /* Check it against the list of known arguments. */
764 + for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
765 + if (streq (arg, ptr->arg))
766 + return ptr->return_value;
767 +
768 + /* An unrecognized interrupt type. */
769 + return AVR32_FT_UNKNOWN;
770 +}
771 +
772 +
773 +/*
774 +These hooks specify assembly directives for creating certain kinds
775 +of integer object. The TARGET_ASM_BYTE_OP directive creates a
776 +byte-sized object, the TARGET_ASM_ALIGNED_HI_OP one creates an
777 +aligned two-byte object, and so on. Any of the hooks may be
778 +NULL, indicating that no suitable directive is available.
779 +
780 +The compiler will print these strings at the start of a new line,
781 +followed immediately by the object's initial value. In most cases,
782 +the string should contain a tab, a pseudo-op, and then another tab.
783 +*/
784 +#undef TARGET_ASM_BYTE_OP
785 +#define TARGET_ASM_BYTE_OP "\t.byte\t"
786 +#undef TARGET_ASM_ALIGNED_HI_OP
787 +#define TARGET_ASM_ALIGNED_HI_OP "\t.align 1\n\t.short\t"
788 +#undef TARGET_ASM_ALIGNED_SI_OP
789 +#define TARGET_ASM_ALIGNED_SI_OP "\t.align 2\n\t.int\t"
790 +#undef TARGET_ASM_ALIGNED_DI_OP
791 +#define TARGET_ASM_ALIGNED_DI_OP NULL
792 +#undef TARGET_ASM_ALIGNED_TI_OP
793 +#define TARGET_ASM_ALIGNED_TI_OP NULL
794 +#undef TARGET_ASM_UNALIGNED_HI_OP
795 +#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
796 +#undef TARGET_ASM_UNALIGNED_SI_OP
797 +#define TARGET_ASM_UNALIGNED_SI_OP "\t.int\t"
798 +#undef TARGET_ASM_UNALIGNED_DI_OP
799 +#define TARGET_ASM_UNALIGNED_DI_OP NULL
800 +#undef TARGET_ASM_UNALIGNED_TI_OP
801 +#define TARGET_ASM_UNALIGNED_TI_OP NULL
802 +
803 +#undef TARGET_ASM_OUTPUT_MI_THUNK
804 +#define TARGET_ASM_OUTPUT_MI_THUNK avr32_output_mi_thunk
805 +
806 +#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
807 +#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
808 +
809 +
810 +static void
811 +avr32_output_mi_thunk (FILE * file,
812 + tree thunk ATTRIBUTE_UNUSED,
813 + HOST_WIDE_INT delta,
814 + HOST_WIDE_INT vcall_offset, tree function)
815 + {
816 + int mi_delta = delta;
817 + int this_regno =
818 + (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function) ?
819 + INTERNAL_REGNUM (11) : INTERNAL_REGNUM (12));
820 +
821 +
822 + if (!avr32_const_ok_for_constraint_p (mi_delta, 'I', "Is21")
823 + || vcall_offset)
824 + {
825 + fputs ("\tpushm\tlr\n", file);
826 + }
827 +
828 +
829 + if (mi_delta != 0)
830 + {
831 + if (avr32_const_ok_for_constraint_p (mi_delta, 'I', "Is21"))
832 + {
833 + fprintf (file, "\tsub\t%s, %d\n", reg_names[this_regno], -mi_delta);
834 + }
835 + else
836 + {
837 + /* Immediate is larger than k21 we must make us a temp register by
838 + pushing a register to the stack. */
839 + fprintf (file, "\tmov\tlr, lo(%d)\n", mi_delta);
840 + fprintf (file, "\torh\tlr, hi(%d)\n", mi_delta);
841 + fprintf (file, "\tadd\t%s, lr\n", reg_names[this_regno]);
842 + }
843 + }
844 +
845 +
846 + if (vcall_offset != 0)
847 + {
848 + fprintf (file, "\tld.w\tlr, %s[0]\n", reg_names[this_regno]);
849 + fprintf (file, "\tld.w\tlr, lr[%i]\n", (int) vcall_offset);
850 + fprintf (file, "\tadd\t%s, lr\n", reg_names[this_regno]);
851 + }
852 +
853 +
854 + if (!avr32_const_ok_for_constraint_p (mi_delta, 'I', "Is21")
855 + || vcall_offset)
856 + {
857 + fputs ("\tpopm\tlr\n", file);
858 + }
859 +
860 + /* Jump to the function. We assume that we can use an rjmp since the
861 + function to jump to is local and probably not too far away from
862 + the thunk. If this assumption proves to be wrong we could implement
863 + this jump by calculating the offset between the jump source and destination
864 + and put this in the constant pool and then perform an add to pc.
865 + This would also be legitimate PIC code. But for now we hope that an rjmp
866 + will be sufficient...
867 + */
868 + fputs ("\trjmp\t", file);
869 + assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0));
870 + fputc ('\n', file);
871 + }
872 +
873 +
874 +/* Implements target hook vector_mode_supported. */
875 +bool
876 +avr32_vector_mode_supported (enum machine_mode mode)
877 +{
878 + if ((mode == V2HImode) || (mode == V4QImode))
879 + return true;
880 +
881 + return false;
882 +}
883 +
884 +
885 +#undef TARGET_INIT_LIBFUNCS
886 +#define TARGET_INIT_LIBFUNCS avr32_init_libfuncs
887 +
888 +#undef TARGET_INIT_BUILTINS
889 +#define TARGET_INIT_BUILTINS avr32_init_builtins
890 +
891 +#undef TARGET_EXPAND_BUILTIN
892 +#define TARGET_EXPAND_BUILTIN avr32_expand_builtin
893 +
894 +tree int_ftype_int, int_ftype_void, short_ftype_short, void_ftype_int_int,
895 + void_ftype_ptr_int;
896 +tree void_ftype_int, void_ftype_ulong, void_ftype_void, int_ftype_ptr_int;
897 +tree short_ftype_short, int_ftype_int_short, int_ftype_short_short,
898 + short_ftype_short_short;
899 +tree int_ftype_int_int, longlong_ftype_int_short, longlong_ftype_short_short;
900 +tree void_ftype_int_int_int_int_int, void_ftype_int_int_int;
901 +tree longlong_ftype_int_int, void_ftype_int_int_longlong;
902 +tree int_ftype_int_int_int, longlong_ftype_longlong_int_short;
903 +tree longlong_ftype_longlong_short_short, int_ftype_int_short_short;
904 +
905 +#define def_builtin(NAME, TYPE, CODE) \
906 + add_builtin_function ((NAME), (TYPE), (CODE), \
907 + BUILT_IN_MD, NULL, NULL_TREE)
908 +
909 +#define def_mbuiltin(MASK, NAME, TYPE, CODE) \
910 + do \
911 + { \
912 + if ((MASK)) \
913 + add_builtin_function ((NAME), (TYPE), (CODE), \
914 + BUILT_IN_MD, NULL, NULL_TREE); \
915 + } \
916 + while (0)
917 +
918 +struct builtin_description
919 +{
920 + const unsigned int mask;
921 + const enum insn_code icode;
922 + const char *const name;
923 + const int code;
924 + const enum rtx_code comparison;
925 + const unsigned int flag;
926 + const tree *ftype;
927 +};
928 +
929 +static const struct builtin_description bdesc_2arg[] = {
930 +
931 +#define DSP_BUILTIN(code, builtin, ftype) \
932 + { 1, CODE_FOR_##code, "__builtin_" #code , \
933 + AVR32_BUILTIN_##builtin, 0, 0, ftype }
934 +
935 + DSP_BUILTIN (mulsathh_h, MULSATHH_H, &short_ftype_short_short),
936 + DSP_BUILTIN (mulsathh_w, MULSATHH_W, &int_ftype_short_short),
937 + DSP_BUILTIN (mulsatrndhh_h, MULSATRNDHH_H, &short_ftype_short_short),
938 + DSP_BUILTIN (mulsatrndwh_w, MULSATRNDWH_W, &int_ftype_int_short),
939 + DSP_BUILTIN (mulsatwh_w, MULSATWH_W, &int_ftype_int_short),
940 + DSP_BUILTIN (satadd_h, SATADD_H, &short_ftype_short_short),
941 + DSP_BUILTIN (satsub_h, SATSUB_H, &short_ftype_short_short),
942 + DSP_BUILTIN (satadd_w, SATADD_W, &int_ftype_int_int),
943 + DSP_BUILTIN (satsub_w, SATSUB_W, &int_ftype_int_int),
944 + DSP_BUILTIN (mulwh_d, MULWH_D, &longlong_ftype_int_short),
945 + DSP_BUILTIN (mulnwh_d, MULNWH_D, &longlong_ftype_int_short)
946 +};
947 +
948 +
949 +void
950 +avr32_init_builtins (void)
951 +{
952 + unsigned int i;
953 + const struct builtin_description *d;
954 + tree endlink = void_list_node;
955 + tree int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
956 + tree longlong_endlink =
957 + tree_cons (NULL_TREE, long_long_integer_type_node, endlink);
958 + tree short_endlink =
959 + tree_cons (NULL_TREE, short_integer_type_node, endlink);
960 + tree void_endlink = tree_cons (NULL_TREE, void_type_node, endlink);
961 +
962 + /* int func (int) */
963 + int_ftype_int = build_function_type (integer_type_node, int_endlink);
964 +
965 + /* short func (short) */
966 + short_ftype_short
967 + = build_function_type (short_integer_type_node, short_endlink);
968 +
969 + /* short func (short, short) */
970 + short_ftype_short_short
971 + = build_function_type (short_integer_type_node,
972 + tree_cons (NULL_TREE, short_integer_type_node,
973 + short_endlink));
974 +
975 + /* long long func (long long, short, short) */
976 + longlong_ftype_longlong_short_short
977 + = build_function_type (long_long_integer_type_node,
978 + tree_cons (NULL_TREE, long_long_integer_type_node,
979 + tree_cons (NULL_TREE,
980 + short_integer_type_node,
981 + short_endlink)));
982 +
983 + /* long long func (short, short) */
984 + longlong_ftype_short_short
985 + = build_function_type (long_long_integer_type_node,
986 + tree_cons (NULL_TREE, short_integer_type_node,
987 + short_endlink));
988 +
989 + /* int func (int, int) */
990 + int_ftype_int_int
991 + = build_function_type (integer_type_node,
992 + tree_cons (NULL_TREE, integer_type_node,
993 + int_endlink));
994 +
995 + /* long long func (int, int) */
996 + longlong_ftype_int_int
997 + = build_function_type (long_long_integer_type_node,
998 + tree_cons (NULL_TREE, integer_type_node,
999 + int_endlink));
1000 +
1001 + /* long long int func (long long, int, short) */
1002 + longlong_ftype_longlong_int_short
1003 + = build_function_type (long_long_integer_type_node,
1004 + tree_cons (NULL_TREE, long_long_integer_type_node,
1005 + tree_cons (NULL_TREE, integer_type_node,
1006 + short_endlink)));
1007 +
1008 + /* long long int func (int, short) */
1009 + longlong_ftype_int_short
1010 + = build_function_type (long_long_integer_type_node,
1011 + tree_cons (NULL_TREE, integer_type_node,
1012 + short_endlink));
1013 +
1014 + /* int func (int, short, short) */
1015 + int_ftype_int_short_short
1016 + = build_function_type (integer_type_node,
1017 + tree_cons (NULL_TREE, integer_type_node,
1018 + tree_cons (NULL_TREE,
1019 + short_integer_type_node,
1020 + short_endlink)));
1021 +
1022 + /* int func (short, short) */
1023 + int_ftype_short_short
1024 + = build_function_type (integer_type_node,
1025 + tree_cons (NULL_TREE, short_integer_type_node,
1026 + short_endlink));
1027 +
1028 + /* int func (int, short) */
1029 + int_ftype_int_short
1030 + = build_function_type (integer_type_node,
1031 + tree_cons (NULL_TREE, integer_type_node,
1032 + short_endlink));
1033 +
1034 + /* void func (int, int) */
1035 + void_ftype_int_int
1036 + = build_function_type (void_type_node,
1037 + tree_cons (NULL_TREE, integer_type_node,
1038 + int_endlink));
1039 +
1040 + /* void func (int, int, int) */
1041 + void_ftype_int_int_int
1042 + = build_function_type (void_type_node,
1043 + tree_cons (NULL_TREE, integer_type_node,
1044 + tree_cons (NULL_TREE, integer_type_node,
1045 + int_endlink)));
1046 +
1047 + /* void func (int, int, long long) */
1048 + void_ftype_int_int_longlong
1049 + = build_function_type (void_type_node,
1050 + tree_cons (NULL_TREE, integer_type_node,
1051 + tree_cons (NULL_TREE, integer_type_node,
1052 + longlong_endlink)));
1053 +
1054 + /* void func (int, int, int, int, int) */
1055 + void_ftype_int_int_int_int_int
1056 + = build_function_type (void_type_node,
1057 + tree_cons (NULL_TREE, integer_type_node,
1058 + tree_cons (NULL_TREE, integer_type_node,
1059 + tree_cons (NULL_TREE,
1060 + integer_type_node,
1061 + tree_cons
1062 + (NULL_TREE,
1063 + integer_type_node,
1064 + int_endlink)))));
1065 +
1066 + /* void func (void *, int) */
1067 + void_ftype_ptr_int
1068 + = build_function_type (void_type_node,
1069 + tree_cons (NULL_TREE, ptr_type_node, int_endlink));
1070 +
1071 + /* void func (int) */
1072 + void_ftype_int = build_function_type (void_type_node, int_endlink);
1073 +
1074 + /* void func (ulong) */
1075 + void_ftype_ulong = build_function_type_list (void_type_node,
1076 + long_unsigned_type_node, NULL_TREE);
1077 +
1078 + /* void func (void) */
1079 + void_ftype_void = build_function_type (void_type_node, void_endlink);
1080 +
1081 + /* int func (void) */
1082 + int_ftype_void = build_function_type (integer_type_node, void_endlink);
1083 +
1084 + /* int func (void *, int) */
1085 + int_ftype_ptr_int
1086 + = build_function_type (integer_type_node,
1087 + tree_cons (NULL_TREE, ptr_type_node, int_endlink));
1088 +
1089 + /* int func (int, int, int) */
1090 + int_ftype_int_int_int
1091 + = build_function_type (integer_type_node,
1092 + tree_cons (NULL_TREE, integer_type_node,
1093 + tree_cons (NULL_TREE, integer_type_node,
1094 + int_endlink)));
1095 +
1096 + /* Initialize avr32 builtins. */
1097 + def_builtin ("__builtin_mfsr", int_ftype_int, AVR32_BUILTIN_MFSR);
1098 + def_builtin ("__builtin_mtsr", void_ftype_int_int, AVR32_BUILTIN_MTSR);
1099 + def_builtin ("__builtin_mfdr", int_ftype_int, AVR32_BUILTIN_MFDR);
1100 + def_builtin ("__builtin_mtdr", void_ftype_int_int, AVR32_BUILTIN_MTDR);
1101 + def_builtin ("__builtin_cache", void_ftype_ptr_int, AVR32_BUILTIN_CACHE);
1102 + def_builtin ("__builtin_sync", void_ftype_int, AVR32_BUILTIN_SYNC);
1103 + def_builtin ("__builtin_ssrf", void_ftype_int, AVR32_BUILTIN_SSRF);
1104 + def_builtin ("__builtin_csrf", void_ftype_int, AVR32_BUILTIN_CSRF);
1105 + def_builtin ("__builtin_tlbr", void_ftype_void, AVR32_BUILTIN_TLBR);
1106 + def_builtin ("__builtin_tlbs", void_ftype_void, AVR32_BUILTIN_TLBS);
1107 + def_builtin ("__builtin_tlbw", void_ftype_void, AVR32_BUILTIN_TLBW);
1108 + def_builtin ("__builtin_breakpoint", void_ftype_void,
1109 + AVR32_BUILTIN_BREAKPOINT);
1110 + def_builtin ("__builtin_xchg", int_ftype_ptr_int, AVR32_BUILTIN_XCHG);
1111 + def_builtin ("__builtin_ldxi", int_ftype_ptr_int, AVR32_BUILTIN_LDXI);
1112 + def_builtin ("__builtin_bswap_16", short_ftype_short,
1113 + AVR32_BUILTIN_BSWAP16);
1114 + def_builtin ("__builtin_bswap_32", int_ftype_int, AVR32_BUILTIN_BSWAP32);
1115 + def_builtin ("__builtin_cop", void_ftype_int_int_int_int_int,
1116 + AVR32_BUILTIN_COP);
1117 + def_builtin ("__builtin_mvcr_w", int_ftype_int_int, AVR32_BUILTIN_MVCR_W);
1118 + def_builtin ("__builtin_mvrc_w", void_ftype_int_int_int,
1119 + AVR32_BUILTIN_MVRC_W);
1120 + def_builtin ("__builtin_mvcr_d", longlong_ftype_int_int,
1121 + AVR32_BUILTIN_MVCR_D);
1122 + def_builtin ("__builtin_mvrc_d", void_ftype_int_int_longlong,
1123 + AVR32_BUILTIN_MVRC_D);
1124 + def_builtin ("__builtin_sats", int_ftype_int_int_int, AVR32_BUILTIN_SATS);
1125 + def_builtin ("__builtin_satu", int_ftype_int_int_int, AVR32_BUILTIN_SATU);
1126 + def_builtin ("__builtin_satrnds", int_ftype_int_int_int,
1127 + AVR32_BUILTIN_SATRNDS);
1128 + def_builtin ("__builtin_satrndu", int_ftype_int_int_int,
1129 + AVR32_BUILTIN_SATRNDU);
1130 + def_builtin ("__builtin_musfr", void_ftype_int, AVR32_BUILTIN_MUSFR);
1131 + def_builtin ("__builtin_mustr", int_ftype_void, AVR32_BUILTIN_MUSTR);
1132 + def_builtin ("__builtin_macsathh_w", int_ftype_int_short_short,
1133 + AVR32_BUILTIN_MACSATHH_W);
1134 + def_builtin ("__builtin_macwh_d", longlong_ftype_longlong_int_short,
1135 + AVR32_BUILTIN_MACWH_D);
1136 + def_builtin ("__builtin_machh_d", longlong_ftype_longlong_short_short,
1137 + AVR32_BUILTIN_MACHH_D);
1138 + def_builtin ("__builtin_mems", void_ftype_ptr_int, AVR32_BUILTIN_MEMS);
1139 + def_builtin ("__builtin_memt", void_ftype_ptr_int, AVR32_BUILTIN_MEMT);
1140 + def_builtin ("__builtin_memc", void_ftype_ptr_int, AVR32_BUILTIN_MEMC);
1141 + def_builtin ("__builtin_sleep", void_ftype_int, AVR32_BUILTIN_SLEEP);
1142 + def_builtin ("__builtin_avr32_delay_cycles", void_ftype_int, AVR32_BUILTIN_DELAY_CYCLES);
1143 +
1144 + /* Add all builtins that are more or less simple operations on two
1145 + operands. */
1146 + for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
1147 + {
1148 + /* Use one of the operands; the target can have a different mode for
1149 + mask-generating compares. */
1150 +
1151 + if (d->name == 0)
1152 + continue;
1153 +
1154 + def_mbuiltin (d->mask, d->name, *(d->ftype), d->code);
1155 + }
1156 +}
1157 +
1158 +
1159 +/* Subroutine of avr32_expand_builtin to take care of binop insns. */
1160 +static rtx
1161 +avr32_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
1162 +{
1163 + rtx pat;
1164 + tree arg0 = CALL_EXPR_ARG (exp,0);
1165 + tree arg1 = CALL_EXPR_ARG (exp,1);
1166 + rtx op0 = expand_normal (arg0);
1167 + rtx op1 = expand_normal (arg1);
1168 + enum machine_mode tmode = insn_data[icode].operand[0].mode;
1169 + enum machine_mode mode0 = insn_data[icode].operand[1].mode;
1170 + enum machine_mode mode1 = insn_data[icode].operand[2].mode;
1171 +
1172 + if (!target
1173 + || GET_MODE (target) != tmode
1174 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1175 + target = gen_reg_rtx (tmode);
1176 +
1177 + /* In case the insn wants input operands in modes different from the
1178 + result, abort. */
1179 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1180 + {
1181 + /* If op0 is already a reg we must cast it to the correct mode. */
1182 + if (REG_P (op0))
1183 + op0 = convert_to_mode (mode0, op0, 1);
1184 + else
1185 + op0 = copy_to_mode_reg (mode0, op0);
1186 + }
1187 + if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
1188 + {
1189 + /* If op1 is already a reg we must cast it to the correct mode. */
1190 + if (REG_P (op1))
1191 + op1 = convert_to_mode (mode1, op1, 1);
1192 + else
1193 + op1 = copy_to_mode_reg (mode1, op1);
1194 + }
1195 + pat = GEN_FCN (icode) (target, op0, op1);
1196 + if (!pat)
1197 + return 0;
1198 + emit_insn (pat);
1199 + return target;
1200 +}
1201 +
1202 +
1203 +/* Expand an expression EXP that calls a built-in function,
1204 + with result going to TARGET if that's convenient
1205 + (and in mode MODE if that's convenient).
1206 + SUBTARGET may be used as the target for computing one of EXP's operands.
1207 + IGNORE is nonzero if the value is to be ignored. */
1208 +rtx
1209 +avr32_expand_builtin (tree exp,
1210 + rtx target,
1211 + rtx subtarget ATTRIBUTE_UNUSED,
1212 + enum machine_mode mode ATTRIBUTE_UNUSED,
1213 + int ignore ATTRIBUTE_UNUSED)
1214 +{
1215 + const struct builtin_description *d;
1216 + unsigned int i;
1217 + enum insn_code icode = 0;
1218 + tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
1219 + tree arg0, arg1, arg2;
1220 + rtx op0, op1, op2, pat;
1221 + enum machine_mode tmode, mode0, mode1;
1222 + enum machine_mode arg0_mode;
1223 + int fcode = DECL_FUNCTION_CODE (fndecl);
1224 +
1225 + switch (fcode)
1226 + {
1227 + default:
1228 + break;
1229 +
1230 + case AVR32_BUILTIN_SATS:
1231 + case AVR32_BUILTIN_SATU:
1232 + case AVR32_BUILTIN_SATRNDS:
1233 + case AVR32_BUILTIN_SATRNDU:
1234 + {
1235 + const char *fname;
1236 + switch (fcode)
1237 + {
1238 + default:
1239 + case AVR32_BUILTIN_SATS:
1240 + icode = CODE_FOR_sats;
1241 + fname = "sats";
1242 + break;
1243 + case AVR32_BUILTIN_SATU:
1244 + icode = CODE_FOR_satu;
1245 + fname = "satu";
1246 + break;
1247 + case AVR32_BUILTIN_SATRNDS:
1248 + icode = CODE_FOR_satrnds;
1249 + fname = "satrnds";
1250 + break;
1251 + case AVR32_BUILTIN_SATRNDU:
1252 + icode = CODE_FOR_satrndu;
1253 + fname = "satrndu";
1254 + break;
1255 + }
1256 +
1257 + arg0 = CALL_EXPR_ARG (exp,0);
1258 + arg1 = CALL_EXPR_ARG (exp,1);
1259 + arg2 = CALL_EXPR_ARG (exp,2);
1260 + op0 = expand_normal (arg0);
1261 + op1 = expand_normal (arg1);
1262 + op2 = expand_normal (arg2);
1263 +
1264 + tmode = insn_data[icode].operand[0].mode;
1265 +
1266 +
1267 + if (target == 0
1268 + || GET_MODE (target) != tmode
1269 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1270 + target = gen_reg_rtx (tmode);
1271 +
1272 +
1273 + if (!(*insn_data[icode].operand[0].predicate) (op0, GET_MODE (op0)))
1274 + {
1275 + op0 = copy_to_mode_reg (insn_data[icode].operand[0].mode, op0);
1276 + }
1277 +
1278 + if (!(*insn_data[icode].operand[1].predicate) (op1, SImode))
1279 + {
1280 + error ("Parameter 2 to __builtin_%s should be a constant number.",
1281 + fname);
1282 + return NULL_RTX;
1283 + }
1284 +
1285 + if (!(*insn_data[icode].operand[1].predicate) (op2, SImode))
1286 + {
1287 + error ("Parameter 3 to __builtin_%s should be a constant number.",
1288 + fname);
1289 + return NULL_RTX;
1290 + }
1291 +
1292 + emit_move_insn (target, op0);
1293 + pat = GEN_FCN (icode) (target, op1, op2);
1294 + if (!pat)
1295 + return 0;
1296 + emit_insn (pat);
1297 +
1298 + return target;
1299 + }
1300 + case AVR32_BUILTIN_MUSTR:
1301 + icode = CODE_FOR_mustr;
1302 + tmode = insn_data[icode].operand[0].mode;
1303 +
1304 + if (target == 0
1305 + || GET_MODE (target) != tmode
1306 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1307 + target = gen_reg_rtx (tmode);
1308 + pat = GEN_FCN (icode) (target);
1309 + if (!pat)
1310 + return 0;
1311 + emit_insn (pat);
1312 + return target;
1313 +
1314 + case AVR32_BUILTIN_MFSR:
1315 + icode = CODE_FOR_mfsr;
1316 + arg0 = CALL_EXPR_ARG (exp,0);
1317 + op0 = expand_normal (arg0);
1318 + tmode = insn_data[icode].operand[0].mode;
1319 + mode0 = insn_data[icode].operand[1].mode;
1320 +
1321 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1322 + {
1323 + error ("Parameter 1 to __builtin_mfsr must be a constant number");
1324 + }
1325 +
1326 + if (target == 0
1327 + || GET_MODE (target) != tmode
1328 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1329 + target = gen_reg_rtx (tmode);
1330 + pat = GEN_FCN (icode) (target, op0);
1331 + if (!pat)
1332 + return 0;
1333 + emit_insn (pat);
1334 + return target;
1335 + case AVR32_BUILTIN_MTSR:
1336 + icode = CODE_FOR_mtsr;
1337 + arg0 = CALL_EXPR_ARG (exp,0);
1338 + arg1 = CALL_EXPR_ARG (exp,1);
1339 + op0 = expand_normal (arg0);
1340 + op1 = expand_normal (arg1);
1341 + mode0 = insn_data[icode].operand[0].mode;
1342 + mode1 = insn_data[icode].operand[1].mode;
1343 +
1344 + if (!(*insn_data[icode].operand[0].predicate) (op0, mode0))
1345 + {
1346 + error ("Parameter 1 to __builtin_mtsr must be a constant number");
1347 + return gen_reg_rtx (mode0);
1348 + }
1349 + if (!(*insn_data[icode].operand[1].predicate) (op1, mode1))
1350 + op1 = copy_to_mode_reg (mode1, op1);
1351 + pat = GEN_FCN (icode) (op0, op1);
1352 + if (!pat)
1353 + return 0;
1354 + emit_insn (pat);
1355 + return NULL_RTX;
1356 + case AVR32_BUILTIN_MFDR:
1357 + icode = CODE_FOR_mfdr;
1358 + arg0 = CALL_EXPR_ARG (exp,0);
1359 + op0 = expand_normal (arg0);
1360 + tmode = insn_data[icode].operand[0].mode;
1361 + mode0 = insn_data[icode].operand[1].mode;
1362 +
1363 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1364 + {
1365 + error ("Parameter 1 to __builtin_mfdr must be a constant number");
1366 + }
1367 +
1368 + if (target == 0
1369 + || GET_MODE (target) != tmode
1370 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1371 + target = gen_reg_rtx (tmode);
1372 + pat = GEN_FCN (icode) (target, op0);
1373 + if (!pat)
1374 + return 0;
1375 + emit_insn (pat);
1376 + return target;
1377 + case AVR32_BUILTIN_MTDR:
1378 + icode = CODE_FOR_mtdr;
1379 + arg0 = CALL_EXPR_ARG (exp,0);
1380 + arg1 = CALL_EXPR_ARG (exp,1);
1381 + op0 = expand_normal (arg0);
1382 + op1 = expand_normal (arg1);
1383 + mode0 = insn_data[icode].operand[0].mode;
1384 + mode1 = insn_data[icode].operand[1].mode;
1385 +
1386 + if (!(*insn_data[icode].operand[0].predicate) (op0, mode0))
1387 + {
1388 + error ("Parameter 1 to __builtin_mtdr must be a constant number");
1389 + return gen_reg_rtx (mode0);
1390 + }
1391 + if (!(*insn_data[icode].operand[1].predicate) (op1, mode1))
1392 + op1 = copy_to_mode_reg (mode1, op1);
1393 + pat = GEN_FCN (icode) (op0, op1);
1394 + if (!pat)
1395 + return 0;
1396 + emit_insn (pat);
1397 + return NULL_RTX;
1398 + case AVR32_BUILTIN_CACHE:
1399 + icode = CODE_FOR_cache;
1400 + arg0 = CALL_EXPR_ARG (exp,0);
1401 + arg1 = CALL_EXPR_ARG (exp,1);
1402 + op0 = expand_normal (arg0);
1403 + op1 = expand_normal (arg1);
1404 + mode0 = insn_data[icode].operand[0].mode;
1405 + mode1 = insn_data[icode].operand[1].mode;
1406 +
1407 + if (!(*insn_data[icode].operand[1].predicate) (op1, mode1))
1408 + {
1409 + error ("Parameter 2 to __builtin_cache must be a constant number");
1410 + return gen_reg_rtx (mode1);
1411 + }
1412 +
1413 + if (!(*insn_data[icode].operand[0].predicate) (op0, mode0))
1414 + op0 = copy_to_mode_reg (mode0, op0);
1415 +
1416 + pat = GEN_FCN (icode) (op0, op1);
1417 + if (!pat)
1418 + return 0;
1419 + emit_insn (pat);
1420 + return NULL_RTX;
1421 + case AVR32_BUILTIN_SYNC:
1422 + case AVR32_BUILTIN_MUSFR:
1423 + case AVR32_BUILTIN_SSRF:
1424 + case AVR32_BUILTIN_CSRF:
1425 + {
1426 + const char *fname;
1427 + switch (fcode)
1428 + {
1429 + default:
1430 + case AVR32_BUILTIN_SYNC:
1431 + icode = CODE_FOR_sync;
1432 + fname = "sync";
1433 + break;
1434 + case AVR32_BUILTIN_MUSFR:
1435 + icode = CODE_FOR_musfr;
1436 + fname = "musfr";
1437 + break;
1438 + case AVR32_BUILTIN_SSRF:
1439 + icode = CODE_FOR_ssrf;
1440 + fname = "ssrf";
1441 + break;
1442 + case AVR32_BUILTIN_CSRF:
1443 + icode = CODE_FOR_csrf;
1444 + fname = "csrf";
1445 + break;
1446 + }
1447 +
1448 + arg0 = CALL_EXPR_ARG (exp,0);
1449 + op0 = expand_normal (arg0);
1450 + mode0 = insn_data[icode].operand[0].mode;
1451 +
1452 + if (!(*insn_data[icode].operand[0].predicate) (op0, mode0))
1453 + {
1454 + if (icode == CODE_FOR_musfr)
1455 + op0 = copy_to_mode_reg (mode0, op0);
1456 + else
1457 + {
1458 + error ("Parameter to __builtin_%s is illegal.", fname);
1459 + return gen_reg_rtx (mode0);
1460 + }
1461 + }
1462 + pat = GEN_FCN (icode) (op0);
1463 + if (!pat)
1464 + return 0;
1465 + emit_insn (pat);
1466 + return NULL_RTX;
1467 + }
1468 + case AVR32_BUILTIN_TLBR:
1469 + icode = CODE_FOR_tlbr;
1470 + pat = GEN_FCN (icode) (NULL_RTX);
1471 + if (!pat)
1472 + return 0;
1473 + emit_insn (pat);
1474 + return NULL_RTX;
1475 + case AVR32_BUILTIN_TLBS:
1476 + icode = CODE_FOR_tlbs;
1477 + pat = GEN_FCN (icode) (NULL_RTX);
1478 + if (!pat)
1479 + return 0;
1480 + emit_insn (pat);
1481 + return NULL_RTX;
1482 + case AVR32_BUILTIN_TLBW:
1483 + icode = CODE_FOR_tlbw;
1484 + pat = GEN_FCN (icode) (NULL_RTX);
1485 + if (!pat)
1486 + return 0;
1487 + emit_insn (pat);
1488 + return NULL_RTX;
1489 + case AVR32_BUILTIN_BREAKPOINT:
1490 + icode = CODE_FOR_breakpoint;
1491 + pat = GEN_FCN (icode) (NULL_RTX);
1492 + if (!pat)
1493 + return 0;
1494 + emit_insn (pat);
1495 + return NULL_RTX;
1496 + case AVR32_BUILTIN_XCHG:
1497 + icode = CODE_FOR_sync_lock_test_and_setsi;
1498 + arg0 = CALL_EXPR_ARG (exp,0);
1499 + arg1 = CALL_EXPR_ARG (exp,1);
1500 + op0 = expand_normal (arg0);
1501 + op1 = expand_normal (arg1);
1502 + tmode = insn_data[icode].operand[0].mode;
1503 + mode0 = insn_data[icode].operand[1].mode;
1504 + mode1 = insn_data[icode].operand[2].mode;
1505 +
1506 + if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
1507 + {
1508 + op1 = copy_to_mode_reg (mode1, op1);
1509 + }
1510 +
1511 + op0 = force_reg (GET_MODE (op0), op0);
1512 + op0 = gen_rtx_MEM (GET_MODE (op0), op0);
1513 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1514 + {
1515 + error
1516 + ("Parameter 1 to __builtin_xchg must be a pointer to an integer.");
1517 + }
1518 +
1519 + if (target == 0
1520 + || GET_MODE (target) != tmode
1521 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1522 + target = gen_reg_rtx (tmode);
1523 + pat = GEN_FCN (icode) (target, op0, op1);
1524 + if (!pat)
1525 + return 0;
1526 + emit_insn (pat);
1527 + return target;
1528 + case AVR32_BUILTIN_LDXI:
1529 + icode = CODE_FOR_ldxi;
1530 + arg0 = CALL_EXPR_ARG (exp,0);
1531 + arg1 = CALL_EXPR_ARG (exp,1);
1532 + arg2 = CALL_EXPR_ARG (exp,2);
1533 + op0 = expand_normal (arg0);
1534 + op1 = expand_normal (arg1);
1535 + op2 = expand_normal (arg2);
1536 + tmode = insn_data[icode].operand[0].mode;
1537 + mode0 = insn_data[icode].operand[1].mode;
1538 + mode1 = insn_data[icode].operand[2].mode;
1539 +
1540 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1541 + {
1542 + op0 = copy_to_mode_reg (mode0, op0);
1543 + }
1544 +
1545 + if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
1546 + {
1547 + op1 = copy_to_mode_reg (mode1, op1);
1548 + }
1549 +
1550 + if (!(*insn_data[icode].operand[3].predicate) (op2, SImode))
1551 + {
1552 + error
1553 + ("Parameter 3 to __builtin_ldxi must be a valid extract shift operand: (0|8|16|24)");
1554 + return gen_reg_rtx (mode0);
1555 + }
1556 +
1557 + if (target == 0
1558 + || GET_MODE (target) != tmode
1559 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1560 + target = gen_reg_rtx (tmode);
1561 + pat = GEN_FCN (icode) (target, op0, op1, op2);
1562 + if (!pat)
1563 + return 0;
1564 + emit_insn (pat);
1565 + return target;
1566 + case AVR32_BUILTIN_BSWAP16:
1567 + {
1568 + icode = CODE_FOR_bswap_16;
1569 + arg0 = CALL_EXPR_ARG (exp,0);
1570 + arg0_mode = TYPE_MODE (TREE_TYPE (arg0));
1571 + mode0 = insn_data[icode].operand[1].mode;
1572 + if (arg0_mode != mode0)
1573 + arg0 = build1 (NOP_EXPR,
1574 + (*lang_hooks.types.type_for_mode) (mode0, 0), arg0);
1575 +
1576 + op0 = expand_expr (arg0, NULL_RTX, HImode, 0);
1577 + tmode = insn_data[icode].operand[0].mode;
1578 +
1579 +
1580 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1581 + {
1582 + if ( CONST_INT_P (op0) )
1583 + {
1584 + HOST_WIDE_INT val = ( ((INTVAL (op0)&0x00ff) << 8) |
1585 + ((INTVAL (op0)&0xff00) >> 8) );
1586 + /* Sign extend 16-bit value to host wide int */
1587 + val <<= (HOST_BITS_PER_WIDE_INT - 16);
1588 + val >>= (HOST_BITS_PER_WIDE_INT - 16);
1589 + op0 = GEN_INT(val);
1590 + if (target == 0
1591 + || GET_MODE (target) != tmode
1592 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1593 + target = gen_reg_rtx (tmode);
1594 + emit_move_insn(target, op0);
1595 + return target;
1596 + }
1597 + else
1598 + op0 = copy_to_mode_reg (mode0, op0);
1599 + }
1600 +
1601 + if (target == 0
1602 + || GET_MODE (target) != tmode
1603 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1604 + {
1605 + target = gen_reg_rtx (tmode);
1606 + }
1607 +
1608 +
1609 + pat = GEN_FCN (icode) (target, op0);
1610 + if (!pat)
1611 + return 0;
1612 + emit_insn (pat);
1613 +
1614 + return target;
1615 + }
1616 + case AVR32_BUILTIN_BSWAP32:
1617 + {
1618 + icode = CODE_FOR_bswap_32;
1619 + arg0 = CALL_EXPR_ARG (exp,0);
1620 + op0 = expand_normal (arg0);
1621 + tmode = insn_data[icode].operand[0].mode;
1622 + mode0 = insn_data[icode].operand[1].mode;
1623 +
1624 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1625 + {
1626 + if ( CONST_INT_P (op0) )
1627 + {
1628 + HOST_WIDE_INT val = ( ((INTVAL (op0)&0x000000ff) << 24) |
1629 + ((INTVAL (op0)&0x0000ff00) << 8) |
1630 + ((INTVAL (op0)&0x00ff0000) >> 8) |
1631 + ((INTVAL (op0)&0xff000000) >> 24) );
1632 + /* Sign extend 32-bit value to host wide int */
1633 + val <<= (HOST_BITS_PER_WIDE_INT - 32);
1634 + val >>= (HOST_BITS_PER_WIDE_INT - 32);
1635 + op0 = GEN_INT(val);
1636 + if (target == 0
1637 + || GET_MODE (target) != tmode
1638 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1639 + target = gen_reg_rtx (tmode);
1640 + emit_move_insn(target, op0);
1641 + return target;
1642 + }
1643 + else
1644 + op0 = copy_to_mode_reg (mode0, op0);
1645 + }
1646 +
1647 + if (target == 0
1648 + || GET_MODE (target) != tmode
1649 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1650 + target = gen_reg_rtx (tmode);
1651 +
1652 +
1653 + pat = GEN_FCN (icode) (target, op0);
1654 + if (!pat)
1655 + return 0;
1656 + emit_insn (pat);
1657 +
1658 + return target;
1659 + }
1660 + case AVR32_BUILTIN_MVCR_W:
1661 + case AVR32_BUILTIN_MVCR_D:
1662 + {
1663 + arg0 = CALL_EXPR_ARG (exp,0);
1664 + arg1 = CALL_EXPR_ARG (exp,1);
1665 + op0 = expand_normal (arg0);
1666 + op1 = expand_normal (arg1);
1667 +
1668 + if (fcode == AVR32_BUILTIN_MVCR_W)
1669 + icode = CODE_FOR_mvcrsi;
1670 + else
1671 + icode = CODE_FOR_mvcrdi;
1672 +
1673 + tmode = insn_data[icode].operand[0].mode;
1674 +
1675 + if (target == 0
1676 + || GET_MODE (target) != tmode
1677 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1678 + target = gen_reg_rtx (tmode);
1679 +
1680 + if (!(*insn_data[icode].operand[1].predicate) (op0, SImode))
1681 + {
1682 + error
1683 + ("Parameter 1 to __builtin_cop is not a valid coprocessor number.");
1684 + error ("Number should be between 0 and 7.");
1685 + return NULL_RTX;
1686 + }
1687 +
1688 + if (!(*insn_data[icode].operand[2].predicate) (op1, SImode))
1689 + {
1690 + error
1691 + ("Parameter 2 to __builtin_cop is not a valid coprocessor register number.");
1692 + error ("Number should be between 0 and 15.");
1693 + return NULL_RTX;
1694 + }
1695 +
1696 + pat = GEN_FCN (icode) (target, op0, op1);
1697 + if (!pat)
1698 + return 0;
1699 + emit_insn (pat);
1700 +
1701 + return target;
1702 + }
1703 + case AVR32_BUILTIN_MACSATHH_W:
1704 + case AVR32_BUILTIN_MACWH_D:
1705 + case AVR32_BUILTIN_MACHH_D:
1706 + {
1707 + arg0 = CALL_EXPR_ARG (exp,0);
1708 + arg1 = CALL_EXPR_ARG (exp,1);
1709 + arg2 = CALL_EXPR_ARG (exp,2);
1710 + op0 = expand_normal (arg0);
1711 + op1 = expand_normal (arg1);
1712 + op2 = expand_normal (arg2);
1713 +
1714 + icode = ((fcode == AVR32_BUILTIN_MACSATHH_W) ? CODE_FOR_macsathh_w :
1715 + (fcode == AVR32_BUILTIN_MACWH_D) ? CODE_FOR_macwh_d :
1716 + CODE_FOR_machh_d);
1717 +
1718 + tmode = insn_data[icode].operand[0].mode;
1719 + mode0 = insn_data[icode].operand[1].mode;
1720 + mode1 = insn_data[icode].operand[2].mode;
1721 +
1722 +
1723 + if (!target
1724 + || GET_MODE (target) != tmode
1725 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1726 + target = gen_reg_rtx (tmode);
1727 +
1728 + if (!(*insn_data[icode].operand[0].predicate) (op0, tmode))
1729 + {
1730 + /* If op0 is already a reg we must cast it to the correct mode. */
1731 + if (REG_P (op0))
1732 + op0 = convert_to_mode (tmode, op0, 1);
1733 + else
1734 + op0 = copy_to_mode_reg (tmode, op0);
1735 + }
1736 +
1737 + if (!(*insn_data[icode].operand[1].predicate) (op1, mode0))
1738 + {
1739 + /* If op1 is already a reg we must cast it to the correct mode. */
1740 + if (REG_P (op1))
1741 + op1 = convert_to_mode (mode0, op1, 1);
1742 + else
1743 + op1 = copy_to_mode_reg (mode0, op1);
1744 + }
1745 +
1746 + if (!(*insn_data[icode].operand[2].predicate) (op2, mode1))
1747 + {
1748 + /* If op1 is already a reg we must cast it to the correct mode. */
1749 + if (REG_P (op2))
1750 + op2 = convert_to_mode (mode1, op2, 1);
1751 + else
1752 + op2 = copy_to_mode_reg (mode1, op2);
1753 + }
1754 +
1755 + emit_move_insn (target, op0);
1756 +
1757 + pat = GEN_FCN (icode) (target, op1, op2);
1758 + if (!pat)
1759 + return 0;
1760 + emit_insn (pat);
1761 + return target;
1762 + }
1763 + case AVR32_BUILTIN_MVRC_W:
1764 + case AVR32_BUILTIN_MVRC_D:
1765 + {
1766 + arg0 = CALL_EXPR_ARG (exp,0);
1767 + arg1 = CALL_EXPR_ARG (exp,1);
1768 + arg2 = CALL_EXPR_ARG (exp,2);
1769 + op0 = expand_normal (arg0);
1770 + op1 = expand_normal (arg1);
1771 + op2 = expand_normal (arg2);
1772 +
1773 + if (fcode == AVR32_BUILTIN_MVRC_W)
1774 + icode = CODE_FOR_mvrcsi;
1775 + else
1776 + icode = CODE_FOR_mvrcdi;
1777 +
1778 + if (!(*insn_data[icode].operand[0].predicate) (op0, SImode))
1779 + {
1780 + error ("Parameter 1 is not a valid coprocessor number.");
1781 + error ("Number should be between 0 and 7.");
1782 + return NULL_RTX;
1783 + }
1784 +
1785 + if (!(*insn_data[icode].operand[1].predicate) (op1, SImode))
1786 + {
1787 + error ("Parameter 2 is not a valid coprocessor register number.");
1788 + error ("Number should be between 0 and 15.");
1789 + return NULL_RTX;
1790 + }
1791 +
1792 + if (GET_CODE (op2) == CONST_INT
1793 + || GET_CODE (op2) == CONST
1794 + || GET_CODE (op2) == SYMBOL_REF || GET_CODE (op2) == LABEL_REF)
1795 + {
1796 + op2 = force_const_mem (insn_data[icode].operand[2].mode, op2);
1797 + }
1798 +
1799 + if (!(*insn_data[icode].operand[2].predicate) (op2, GET_MODE (op2)))
1800 + op2 = copy_to_mode_reg (insn_data[icode].operand[2].mode, op2);
1801 +
1802 +
1803 + pat = GEN_FCN (icode) (op0, op1, op2);
1804 + if (!pat)
1805 + return 0;
1806 + emit_insn (pat);
1807 +
1808 + return NULL_RTX;
1809 + }
1810 + case AVR32_BUILTIN_COP:
1811 + {
1812 + rtx op3, op4;
1813 + tree arg3, arg4;
1814 + icode = CODE_FOR_cop;
1815 + arg0 = CALL_EXPR_ARG (exp,0);
1816 + arg1 = CALL_EXPR_ARG (exp,1);
1817 + arg2 = CALL_EXPR_ARG (exp,2);
1818 + arg3 = CALL_EXPR_ARG (exp,3);
1819 + arg4 = CALL_EXPR_ARG (exp,4);
1820 + op0 = expand_normal (arg0);
1821 + op1 = expand_normal (arg1);
1822 + op2 = expand_normal (arg2);
1823 + op3 = expand_normal (arg3);
1824 + op4 = expand_normal (arg4);
1825 +
1826 + if (!(*insn_data[icode].operand[0].predicate) (op0, SImode))
1827 + {
1828 + error
1829 + ("Parameter 1 to __builtin_cop is not a valid coprocessor number.");
1830 + error ("Number should be between 0 and 7.");
1831 + return NULL_RTX;
1832 + }
1833 +
1834 + if (!(*insn_data[icode].operand[1].predicate) (op1, SImode))
1835 + {
1836 + error
1837 + ("Parameter 2 to __builtin_cop is not a valid coprocessor register number.");
1838 + error ("Number should be between 0 and 15.");
1839 + return NULL_RTX;
1840 + }
1841 +
1842 + if (!(*insn_data[icode].operand[2].predicate) (op2, SImode))
1843 + {
1844 + error
1845 + ("Parameter 3 to __builtin_cop is not a valid coprocessor register number.");
1846 + error ("Number should be between 0 and 15.");
1847 + return NULL_RTX;
1848 + }
1849 +
1850 + if (!(*insn_data[icode].operand[3].predicate) (op3, SImode))
1851 + {
1852 + error
1853 + ("Parameter 4 to __builtin_cop is not a valid coprocessor register number.");
1854 + error ("Number should be between 0 and 15.");
1855 + return NULL_RTX;
1856 + }
1857 +
1858 + if (!(*insn_data[icode].operand[4].predicate) (op4, SImode))
1859 + {
1860 + error
1861 + ("Parameter 5 to __builtin_cop is not a valid coprocessor operation.");
1862 + error ("Number should be between 0 and 127.");
1863 + return NULL_RTX;
1864 + }
1865 +
1866 + pat = GEN_FCN (icode) (op0, op1, op2, op3, op4);
1867 + if (!pat)
1868 + return 0;
1869 + emit_insn (pat);
1870 +
1871 + return target;
1872 + }
1873 +
1874 + case AVR32_BUILTIN_MEMS:
1875 + case AVR32_BUILTIN_MEMC:
1876 + case AVR32_BUILTIN_MEMT:
1877 + {
1878 + if (!TARGET_RMW)
1879 + error ("Trying to use __builtin_mem(s/c/t) when target does not support RMW insns.");
1880 +
1881 + switch (fcode) {
1882 + case AVR32_BUILTIN_MEMS:
1883 + icode = CODE_FOR_iorsi3;
1884 + break;
1885 + case AVR32_BUILTIN_MEMC:
1886 + icode = CODE_FOR_andsi3;
1887 + break;
1888 + case AVR32_BUILTIN_MEMT:
1889 + icode = CODE_FOR_xorsi3;
1890 + break;
1891 + }
1892 + arg0 = CALL_EXPR_ARG (exp,0);
1893 + arg1 = CALL_EXPR_ARG (exp,1);
1894 + op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
1895 + if ( GET_CODE (op0) == SYMBOL_REF )
1896 + // This symbol must be RMW addressable
1897 + SYMBOL_REF_FLAGS (op0) |= (1 << SYMBOL_FLAG_RMW_ADDR_SHIFT);
1898 + op0 = gen_rtx_MEM(SImode, op0);
1899 + op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
1900 + mode0 = insn_data[icode].operand[1].mode;
1901 +
1902 +
1903 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1904 + {
1905 + error ("Parameter 1 to __builtin_mem(s/c/t) must be a Ks15<<2 address or a rmw addressable symbol.");
1906 + }
1907 +
1908 + if ( !CONST_INT_P (op1)
1909 + || INTVAL (op1) > 31
1910 + || INTVAL (op1) < 0 )
1911 + error ("Parameter 2 to __builtin_mem(s/c/t) must be a constant between 0 and 31.");
1912 +
1913 + if ( fcode == AVR32_BUILTIN_MEMC )
1914 + op1 = GEN_INT((~(1 << INTVAL(op1)))&0xffffffff);
1915 + else
1916 + op1 = GEN_INT((1 << INTVAL(op1))&0xffffffff);
1917 + pat = GEN_FCN (icode) (op0, op0, op1);
1918 + if (!pat)
1919 + return 0;
1920 + emit_insn (pat);
1921 + return op0;
1922 + }
1923 +
1924 + case AVR32_BUILTIN_SLEEP:
1925 + {
1926 + arg0 = CALL_EXPR_ARG (exp, 0);
1927 + op0 = expand_normal (arg0);
1928 + int intval = INTVAL(op0);
1929 +
1930 + /* Check if the argument if integer and if the value of integer
1931 + is greater than 0. */
1932 +
1933 + if (!CONSTANT_P (op0))
1934 + error ("Parameter 1 to __builtin_sleep() is not a valid integer.");
1935 + if (intval < 0 )
1936 + error ("Parameter 1 to __builtin_sleep() should be an integer greater than 0.");
1937 +
1938 + int strncmpval = strncmp (avr32_part_name,"uc3l", 4);
1939 +
1940 + /* Check if op0 is less than 7 for uc3l* and less than 6 for other
1941 + devices. By this check we are avoiding if operand is less than
1942 + 256. For more devices, add more such checks. */
1943 +
1944 + if ( strncmpval == 0 && intval >= 7)
1945 + error ("Parameter 1 to __builtin_sleep() should be less than or equal to 7.");
1946 + else if ( strncmp != 0 && intval >= 6)
1947 + error ("Parameter 1 to __builtin_sleep() should be less than or equal to 6.");
1948 +
1949 + emit_insn (gen_sleep(op0));
1950 + return target;
1951 +
1952 + }
1953 + case AVR32_BUILTIN_DELAY_CYCLES:
1954 + {
1955 + arg0 = CALL_EXPR_ARG (exp, 0);
1956 + op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
1957 +
1958 + if (TARGET_ARCH_AP)
1959 + error (" __builtin_avr32_delay_cycles() not supported for \'%s\' architecture.", avr32_arch_name);
1960 + if (!CONSTANT_P (op0))
1961 + error ("Parameter 1 to __builtin_avr32_delay_cycles() should be an integer.");
1962 + emit_insn (gen_delay_cycles (op0));
1963 + return 0;
1964 +
1965 + }
1966 +
1967 + }
1968 +
1969 + for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
1970 + if (d->code == fcode)
1971 + return avr32_expand_binop_builtin (d->icode, exp, target);
1972 +
1973 +
1974 + /* @@@ Should really do something sensible here. */
1975 + return NULL_RTX;
1976 +}
1977 +
1978 +
1979 +/* Handle an "interrupt" or "isr" attribute;
1980 + arguments as in struct attribute_spec.handler. */
1981 +static tree
1982 +avr32_handle_isr_attribute (tree * node, tree name, tree args,
1983 + int flags, bool * no_add_attrs)
1984 +{
1985 + if (DECL_P (*node))
1986 + {
1987 + if (TREE_CODE (*node) != FUNCTION_DECL)
1988 + {
1989 + warning (OPT_Wattributes,"`%s' attribute only applies to functions",
1990 + IDENTIFIER_POINTER (name));
1991 + *no_add_attrs = true;
1992 + }
1993 + /* FIXME: the argument if any is checked for type attributes; should it
1994 + be checked for decl ones? */
1995 + }
1996 + else
1997 + {
1998 + if (TREE_CODE (*node) == FUNCTION_TYPE
1999 + || TREE_CODE (*node) == METHOD_TYPE)
2000 + {
2001 + if (avr32_isr_value (args) == AVR32_FT_UNKNOWN)
2002 + {
2003 + warning (OPT_Wattributes,"`%s' attribute ignored", IDENTIFIER_POINTER (name));
2004 + *no_add_attrs = true;
2005 + }
2006 + }
2007 + else if (TREE_CODE (*node) == POINTER_TYPE
2008 + && (TREE_CODE (TREE_TYPE (*node)) == FUNCTION_TYPE
2009 + || TREE_CODE (TREE_TYPE (*node)) == METHOD_TYPE)
2010 + && avr32_isr_value (args) != AVR32_FT_UNKNOWN)
2011 + {
2012 + *node = build_variant_type_copy (*node);
2013 + TREE_TYPE (*node) = build_type_attribute_variant
2014 + (TREE_TYPE (*node),
2015 + tree_cons (name, args, TYPE_ATTRIBUTES (TREE_TYPE (*node))));
2016 + *no_add_attrs = true;
2017 + }
2018 + else
2019 + {
2020 + /* Possibly pass this attribute on from the type to a decl. */
2021 + if (flags & ((int) ATTR_FLAG_DECL_NEXT
2022 + | (int) ATTR_FLAG_FUNCTION_NEXT
2023 + | (int) ATTR_FLAG_ARRAY_NEXT))
2024 + {
2025 + *no_add_attrs = true;
2026 + return tree_cons (name, args, NULL_TREE);
2027 + }
2028 + else
2029 + {
2030 + warning (OPT_Wattributes,"`%s' attribute ignored", IDENTIFIER_POINTER (name));
2031 + }
2032 + }
2033 + }
2034 +
2035 + return NULL_TREE;
2036 +}
2037 +
2038 +
2039 +/* Handle an attribute requiring a FUNCTION_DECL;
2040 + arguments as in struct attribute_spec.handler. */
2041 +static tree
2042 +avr32_handle_fndecl_attribute (tree * node, tree name,
2043 + tree args,
2044 + int flags ATTRIBUTE_UNUSED,
2045 + bool * no_add_attrs)
2046 +{
2047 + if (TREE_CODE (*node) != FUNCTION_DECL)
2048 + {
2049 + warning (OPT_Wattributes,"%qs attribute only applies to functions",
2050 + IDENTIFIER_POINTER (name));
2051 + *no_add_attrs = true;
2052 + return NULL_TREE;
2053 + }
2054 +
2055 + fndecl_attribute_args = args;
2056 + if (args == NULL_TREE)
2057 + return NULL_TREE;
2058 +
2059 + tree value = TREE_VALUE (args);
2060 + if (TREE_CODE (value) != INTEGER_CST)
2061 + {
2062 + warning (OPT_Wattributes,
2063 + "argument of %qs attribute is not an integer constant",
2064 + IDENTIFIER_POINTER (name));
2065 + *no_add_attrs = true;
2066 + }
2067 +
2068 + return NULL_TREE;
2069 +}
2070 +
2071 +
2072 +/* Handle an acall attribute;
2073 + arguments as in struct attribute_spec.handler. */
2074 +
2075 +static tree
2076 +avr32_handle_acall_attribute (tree * node, tree name,
2077 + tree args ATTRIBUTE_UNUSED,
2078 + int flags ATTRIBUTE_UNUSED, bool * no_add_attrs)
2079 +{
2080 + if (TREE_CODE (*node) == FUNCTION_TYPE || TREE_CODE (*node) == METHOD_TYPE)
2081 + {
2082 + warning (OPT_Wattributes,"`%s' attribute not yet supported...",
2083 + IDENTIFIER_POINTER (name));
2084 + *no_add_attrs = true;
2085 + return NULL_TREE;
2086 + }
2087 +
2088 + warning (OPT_Wattributes,"`%s' attribute only applies to functions",
2089 + IDENTIFIER_POINTER (name));
2090 + *no_add_attrs = true;
2091 + return NULL_TREE;
2092 +}
2093 +
2094 +
2095 +bool
2096 +avr32_flashvault_call(tree decl)
2097 +{
2098 + tree attributes;
2099 + tree fv_attribute;
2100 + tree vector_tree;
2101 + unsigned int vector;
2102 +
2103 + if (decl && TREE_CODE (decl) == FUNCTION_DECL)
2104 + {
2105 + attributes = DECL_ATTRIBUTES(decl);
2106 + fv_attribute = lookup_attribute ("flashvault", attributes);
2107 + if (fv_attribute != NULL_TREE)
2108 + {
2109 + /* Get attribute parameter, for the function vector number. */
2110 + /*
2111 + There is probably an easier, standard way to retrieve the
2112 + attribute parameter which needs to be done here.
2113 + */
2114 + vector_tree = TREE_VALUE(fv_attribute);
2115 + if (vector_tree != NULL_TREE)
2116 + {
2117 + vector = (unsigned int)TREE_INT_CST_LOW(TREE_VALUE(vector_tree));
2118 + fprintf (asm_out_file,
2119 + "\tmov\tr8, lo(%i)\t# Load vector number for sscall.\n",
2120 + vector);
2121 + }
2122 +
2123 + fprintf (asm_out_file,
2124 + "\tsscall\t# Secure system call.\n");
2125 +
2126 + return true;
2127 + }
2128 + }
2129 +
2130 + return false;
2131 +}
2132 +
2133 +
2134 +static bool has_attribute_p (tree decl, const char *name)
2135 +{
2136 + if (decl && TREE_CODE (decl) == FUNCTION_DECL)
2137 + {
2138 + return (lookup_attribute (name, DECL_ATTRIBUTES(decl)) != NULL_TREE);
2139 + }
2140 + return NULL_TREE;
2141 +}
2142 +
2143 +
2144 +/* Return 0 if the attributes for two types are incompatible, 1 if they
2145 + are compatible, and 2 if they are nearly compatible (which causes a
2146 + warning to be generated). */
2147 +static int
2148 +avr32_comp_type_attributes (tree type1, tree type2)
2149 +{
2150 + bool acall1, acall2, isr1, isr2, naked1, naked2, fv1, fv2, fvimpl1, fvimpl2;
2151 +
2152 + /* Check for mismatch of non-default calling convention. */
2153 + if (TREE_CODE (type1) != FUNCTION_TYPE)
2154 + return 1;
2155 +
2156 + /* Check for mismatched call attributes. */
2157 + acall1 = lookup_attribute ("acall", TYPE_ATTRIBUTES (type1)) != NULL;
2158 + acall2 = lookup_attribute ("acall", TYPE_ATTRIBUTES (type2)) != NULL;
2159 + naked1 = lookup_attribute ("naked", TYPE_ATTRIBUTES (type1)) != NULL;
2160 + naked2 = lookup_attribute ("naked", TYPE_ATTRIBUTES (type2)) != NULL;
2161 + fv1 = lookup_attribute ("flashvault", TYPE_ATTRIBUTES (type1)) != NULL;
2162 + fv2 = lookup_attribute ("flashvault", TYPE_ATTRIBUTES (type2)) != NULL;
2163 + fvimpl1 = lookup_attribute ("flashvault_impl", TYPE_ATTRIBUTES (type1)) != NULL;
2164 + fvimpl2 = lookup_attribute ("flashvault_impl", TYPE_ATTRIBUTES (type2)) != NULL;
2165 + isr1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL;
2166 + if (!isr1)
2167 + isr1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL;
2168 +
2169 + isr2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL;
2170 + if (!isr2)
2171 + isr2 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL;
2172 +
2173 + if ((acall1 && isr2)
2174 + || (acall2 && isr1)
2175 + || (naked1 && isr2)
2176 + || (naked2 && isr1)
2177 + || (fv1 && isr2)
2178 + || (fv2 && isr1)
2179 + || (fvimpl1 && isr2)
2180 + || (fvimpl2 && isr1)
2181 + || (fv1 && fvimpl2)
2182 + || (fv2 && fvimpl1)
2183 + )
2184 + return 0;
2185 +
2186 + return 1;
2187 +}
2188 +
2189 +
2190 +/* Computes the type of the current function. */
2191 +static unsigned long
2192 +avr32_compute_func_type (void)
2193 +{
2194 + unsigned long type = AVR32_FT_UNKNOWN;
2195 + tree a;
2196 + tree attr;
2197 +
2198 + if (TREE_CODE (current_function_decl) != FUNCTION_DECL)
2199 + abort ();
2200 +
2201 + /* Decide if the current function is volatile. Such functions never
2202 + return, and many memory cycles can be saved by not storing register
2203 + values that will never be needed again. This optimization was added to
2204 + speed up context switching in a kernel application. */
2205 + if (optimize > 0
2206 + && TREE_NOTHROW (current_function_decl)
2207 + && TREE_THIS_VOLATILE (current_function_decl))
2208 + type |= AVR32_FT_VOLATILE;
2209 +
2210 + if (cfun->static_chain_decl != NULL)
2211 + type |= AVR32_FT_NESTED;
2212 +
2213 + attr = DECL_ATTRIBUTES (current_function_decl);
2214 +
2215 + a = lookup_attribute ("isr", attr);
2216 + if (a == NULL_TREE)
2217 + a = lookup_attribute ("interrupt", attr);
2218 +
2219 + if (a == NULL_TREE)
2220 + type |= AVR32_FT_NORMAL;
2221 + else
2222 + type |= avr32_isr_value (TREE_VALUE (a));
2223 +
2224 +
2225 + a = lookup_attribute ("acall", attr);
2226 + if (a != NULL_TREE)
2227 + type |= AVR32_FT_ACALL;
2228 +
2229 + a = lookup_attribute ("naked", attr);
2230 + if (a != NULL_TREE)
2231 + type |= AVR32_FT_NAKED;
2232 +
2233 + a = lookup_attribute ("flashvault", attr);
2234 + if (a != NULL_TREE)
2235 + type |= AVR32_FT_FLASHVAULT;
2236 +
2237 + a = lookup_attribute ("flashvault_impl", attr);
2238 + if (a != NULL_TREE)
2239 + type |= AVR32_FT_FLASHVAULT_IMPL;
2240 +
2241 + return type;
2242 +}
2243 +
2244 +
2245 +/* Returns the type of the current function. */
2246 +static unsigned long
2247 +avr32_current_func_type (void)
2248 +{
2249 + if (AVR32_FUNC_TYPE (cfun->machine->func_type) == AVR32_FT_UNKNOWN)
2250 + cfun->machine->func_type = avr32_compute_func_type ();
2251 +
2252 + return cfun->machine->func_type;
2253 +}
2254 +
2255 +
2256 +/*
2257 +This target hook should return true if we should not pass type solely
2258 +in registers. The file expr.h defines a definition that is usually appropriate,
2259 +refer to expr.h for additional documentation.
2260 +*/
2261 +bool
2262 +avr32_must_pass_in_stack (enum machine_mode mode ATTRIBUTE_UNUSED, tree type)
2263 +{
2264 + if (type && AGGREGATE_TYPE_P (type)
2265 + /* If the alignment is less than the size then pass in the struct on
2266 + the stack. */
2267 + && ((unsigned int) TYPE_ALIGN_UNIT (type) <
2268 + (unsigned int) int_size_in_bytes (type))
2269 + /* If we support unaligned word accesses then structs of size 4 and 8
2270 + can have any alignment and still be passed in registers. */
2271 + && !(TARGET_UNALIGNED_WORD
2272 + && (int_size_in_bytes (type) == 4
2273 + || int_size_in_bytes (type) == 8))
2274 + /* Double word structs need only a word alignment. */
2275 + && !(int_size_in_bytes (type) == 8 && TYPE_ALIGN_UNIT (type) >= 4))
2276 + return true;
2277 +
2278 + if (type && AGGREGATE_TYPE_P (type)
2279 + /* Structs of size 3,5,6,7 are always passed in registers. */
2280 + && (int_size_in_bytes (type) == 3
2281 + || int_size_in_bytes (type) == 5
2282 + || int_size_in_bytes (type) == 6 || int_size_in_bytes (type) == 7))
2283 + return true;
2284 +
2285 +
2286 + return (type && TREE_ADDRESSABLE (type));
2287 +}
2288 +
2289 +
2290 +bool
2291 +avr32_strict_argument_naming (CUMULATIVE_ARGS * ca ATTRIBUTE_UNUSED)
2292 +{
2293 + return true;
2294 +}
2295 +
2296 +
2297 +/*
2298 + This target hook should return true if an argument at the position indicated
2299 + by cum should be passed by reference. This predicate is queried after target
2300 + independent reasons for being passed by reference, such as TREE_ADDRESSABLE (type).
2301 +
2302 + If the hook returns true, a copy of that argument is made in memory and a
2303 + pointer to the argument is passed instead of the argument itself. The pointer
2304 + is passed in whatever way is appropriate for passing a pointer to that type.
2305 +*/
2306 +bool
2307 +avr32_pass_by_reference (CUMULATIVE_ARGS * cum ATTRIBUTE_UNUSED,
2308 + enum machine_mode mode ATTRIBUTE_UNUSED,
2309 + tree type, bool named ATTRIBUTE_UNUSED)
2310 +{
2311 + return (type && (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST));
2312 +}
2313 +
2314 +
2315 +static int
2316 +avr32_arg_partial_bytes (CUMULATIVE_ARGS * pcum ATTRIBUTE_UNUSED,
2317 + enum machine_mode mode ATTRIBUTE_UNUSED,
2318 + tree type ATTRIBUTE_UNUSED,
2319 + bool named ATTRIBUTE_UNUSED)
2320 +{
2321 + return 0;
2322 +}
2323 +
2324 +
2325 +struct gcc_target targetm = TARGET_INITIALIZER;
2326 +
2327 +/*
2328 + Table used to convert from register number in the assembler instructions and
2329 + the register numbers used in gcc.
2330 +*/
2331 +const int avr32_function_arg_reglist[] = {
2332 + INTERNAL_REGNUM (12),
2333 + INTERNAL_REGNUM (11),
2334 + INTERNAL_REGNUM (10),
2335 + INTERNAL_REGNUM (9),
2336 + INTERNAL_REGNUM (8)
2337 +};
2338 +
2339 +
2340 +rtx avr32_compare_op0 = NULL_RTX;
2341 +rtx avr32_compare_op1 = NULL_RTX;
2342 +rtx avr32_compare_operator = NULL_RTX;
2343 +rtx avr32_acc_cache = NULL_RTX;
2344 +
2345 +
2346 +/*
2347 + Returns nonzero if it is allowed to store a value of mode mode in hard
2348 + register number regno.
2349 +*/
2350 +int
2351 +avr32_hard_regno_mode_ok (int regnr, enum machine_mode mode)
2352 +{
2353 + switch (mode)
2354 + {
2355 + case DImode: /* long long */
2356 + case DFmode: /* double */
2357 + case SCmode: /* __complex__ float */
2358 + case CSImode: /* __complex__ int */
2359 + if (regnr < 4)
2360 + { /* long long int not supported in r12, sp, lr or pc. */
2361 + return 0;
2362 + }
2363 + else
2364 + {
2365 + /* long long int has to be referred in even registers. */
2366 + if (regnr % 2)
2367 + return 0;
2368 + else
2369 + return 1;
2370 + }
2371 + case CDImode: /* __complex__ long long */
2372 + case DCmode: /* __complex__ double */
2373 + case TImode: /* 16 bytes */
2374 + if (regnr < 7)
2375 + return 0;
2376 + else if (regnr % 2)
2377 + return 0;
2378 + else
2379 + return 1;
2380 + default:
2381 + return 1;
2382 + }
2383 +}
2384 +
2385 +
2386 +int
2387 +avr32_rnd_operands (rtx add, rtx shift)
2388 +{
2389 + if (GET_CODE (shift) == CONST_INT &&
2390 + GET_CODE (add) == CONST_INT && INTVAL (shift) > 0)
2391 + {
2392 + if ((1 << (INTVAL (shift) - 1)) == INTVAL (add))
2393 + return TRUE;
2394 + }
2395 +
2396 + return FALSE;
2397 +}
2398 +
2399 +
2400 +int
2401 +avr32_const_ok_for_constraint_p (HOST_WIDE_INT value, char c, const char *str)
2402 +{
2403 + switch (c)
2404 + {
2405 + case 'K':
2406 + case 'I':
2407 + {
2408 + HOST_WIDE_INT min_value = 0, max_value = 0;
2409 + char size_str[3];
2410 + int const_size;
2411 +
2412 + size_str[0] = str[2];
2413 + size_str[1] = str[3];
2414 + size_str[2] = '\0';
2415 + const_size = atoi (size_str);
2416 +
2417 + if (toupper (str[1]) == 'U')
2418 + {
2419 + min_value = 0;
2420 + max_value = (1 << const_size) - 1;
2421 + }
2422 + else if (toupper (str[1]) == 'S')
2423 + {
2424 + min_value = -(1 << (const_size - 1));
2425 + max_value = (1 << (const_size - 1)) - 1;
2426 + }
2427 +
2428 + if (c == 'I')
2429 + {
2430 + value = -value;
2431 + }
2432 +
2433 + if (value >= min_value && value <= max_value)
2434 + {
2435 + return 1;
2436 + }
2437 + break;
2438 + }
2439 + case 'M':
2440 + return avr32_mask_upper_bits_operand (GEN_INT (value), VOIDmode);
2441 + case 'J':
2442 + return avr32_hi16_immediate_operand (GEN_INT (value), VOIDmode);
2443 + case 'O':
2444 + return one_bit_set_operand (GEN_INT (value), VOIDmode);
2445 + case 'N':
2446 + return one_bit_cleared_operand (GEN_INT (value), VOIDmode);
2447 + case 'L':
2448 + /* The lower 16-bits are set. */
2449 + return ((value & 0xffff) == 0xffff) ;
2450 + }
2451 +
2452 + return 0;
2453 +}
2454 +
2455 +
2456 +/* Compute mask of registers which needs saving upon function entry. */
2457 +static unsigned long
2458 +avr32_compute_save_reg_mask (int push)
2459 +{
2460 + unsigned long func_type;
2461 + unsigned int save_reg_mask = 0;
2462 + unsigned int reg;
2463 +
2464 + func_type = avr32_current_func_type ();
2465 +
2466 + if (IS_INTERRUPT (func_type))
2467 + {
2468 + unsigned int max_reg = 12;
2469 +
2470 + /* Get the banking scheme for the interrupt */
2471 + switch (func_type)
2472 + {
2473 + case AVR32_FT_ISR_FULL:
2474 + max_reg = 0;
2475 + break;
2476 + case AVR32_FT_ISR_HALF:
2477 + max_reg = 7;
2478 + break;
2479 + case AVR32_FT_ISR_NONE:
2480 + max_reg = 12;
2481 + break;
2482 + }
2483 +
2484 + /* Interrupt functions must not corrupt any registers, even call
2485 + clobbered ones. If this is a leaf function we can just examine the
2486 + registers used by the RTL, but otherwise we have to assume that
2487 + whatever function is called might clobber anything, and so we have
2488 + to save all the call-clobbered registers as well. */
2489 +
2490 + /* Need not push the registers r8-r12 for AVR32A architectures, as this
2491 + is automatially done in hardware. We also do not have any shadow
2492 + registers. */
2493 + if (TARGET_UARCH_AVR32A)
2494 + {
2495 + max_reg = 7;
2496 + func_type = AVR32_FT_ISR_NONE;
2497 + }
2498 +
2499 + /* All registers which are used and are not shadowed must be saved. */
2500 + for (reg = 0; reg <= max_reg; reg++)
2501 + if (df_regs_ever_live_p (INTERNAL_REGNUM (reg))
2502 + || (!current_function_is_leaf
2503 + && call_used_regs[INTERNAL_REGNUM (reg)]))
2504 + save_reg_mask |= (1 << reg);
2505 +
2506 + /* Check LR */
2507 + if ((df_regs_ever_live_p (LR_REGNUM)
2508 + || !current_function_is_leaf || frame_pointer_needed)
2509 + /* Only non-shadowed register models */
2510 + && (func_type == AVR32_FT_ISR_NONE))
2511 + save_reg_mask |= (1 << ASM_REGNUM (LR_REGNUM));
2512 +
2513 + /* Make sure that the GOT register is pushed. */
2514 + if (max_reg >= ASM_REGNUM (PIC_OFFSET_TABLE_REGNUM)
2515 + && current_function_uses_pic_offset_table)
2516 + save_reg_mask |= (1 << ASM_REGNUM (PIC_OFFSET_TABLE_REGNUM));
2517 +
2518 + }
2519 + else
2520 + {
2521 + int use_pushm = optimize_size;
2522 +
2523 + /* In the normal case we only need to save those registers which are
2524 + call saved and which are used by this function. */
2525 + for (reg = 0; reg <= 7; reg++)
2526 + if (df_regs_ever_live_p (INTERNAL_REGNUM (reg))
2527 + && !call_used_regs[INTERNAL_REGNUM (reg)])
2528 + save_reg_mask |= (1 << reg);
2529 +
2530 + /* Make sure that the GOT register is pushed. */
2531 + if (current_function_uses_pic_offset_table)
2532 + save_reg_mask |= (1 << ASM_REGNUM (PIC_OFFSET_TABLE_REGNUM));
2533 +
2534 +
2535 + /* If we optimize for size and do not have anonymous arguments: use
2536 + pushm/popm always. */
2537 + if (use_pushm)
2538 + {
2539 + if ((save_reg_mask & (1 << 0))
2540 + || (save_reg_mask & (1 << 1))
2541 + || (save_reg_mask & (1 << 2)) || (save_reg_mask & (1 << 3)))
2542 + save_reg_mask |= 0xf;
2543 +
2544 + if ((save_reg_mask & (1 << 4))
2545 + || (save_reg_mask & (1 << 5))
2546 + || (save_reg_mask & (1 << 6)) || (save_reg_mask & (1 << 7)))
2547 + save_reg_mask |= 0xf0;
2548 +
2549 + if ((save_reg_mask & (1 << 8)) || (save_reg_mask & (1 << 9)))
2550 + save_reg_mask |= 0x300;
2551 + }
2552 +
2553 +
2554 + /* Check LR */
2555 + if ((df_regs_ever_live_p (LR_REGNUM)
2556 + || !current_function_is_leaf
2557 + || (optimize_size
2558 + && save_reg_mask
2559 + && !current_function_calls_eh_return)
2560 + || frame_pointer_needed)
2561 + && !IS_FLASHVAULT (func_type))
2562 + {
2563 + if (push
2564 + /* Never pop LR into PC for functions which
2565 + calls __builtin_eh_return, since we need to
2566 + fix the SP after the restoring of the registers
2567 + and before returning. */
2568 + || current_function_calls_eh_return)
2569 + {
2570 + /* Push/Pop LR */
2571 + save_reg_mask |= (1 << ASM_REGNUM (LR_REGNUM));
2572 + }
2573 + else
2574 + {
2575 + /* Pop PC */
2576 + save_reg_mask |= (1 << ASM_REGNUM (PC_REGNUM));
2577 + }
2578 + }
2579 + }
2580 +
2581 +
2582 + /* Save registers so the exception handler can modify them. */
2583 + if (current_function_calls_eh_return)
2584 + {
2585 + unsigned int i;
2586 +
2587 + for (i = 0;; i++)
2588 + {
2589 + reg = EH_RETURN_DATA_REGNO (i);
2590 + if (reg == INVALID_REGNUM)
2591 + break;
2592 + save_reg_mask |= 1 << ASM_REGNUM (reg);
2593 + }
2594 + }
2595 +
2596 + return save_reg_mask;
2597 +}
2598 +
2599 +
2600 +/* Compute total size in bytes of all saved registers. */
2601 +static int
2602 +avr32_get_reg_mask_size (int reg_mask)
2603 +{
2604 + int reg, size;
2605 + size = 0;
2606 +
2607 + for (reg = 0; reg <= 15; reg++)
2608 + if (reg_mask & (1 << reg))
2609 + size += 4;
2610 +
2611 + return size;
2612 +}
2613 +
2614 +
2615 +/* Get a register from one of the registers which are saved onto the stack
2616 + upon function entry. */
2617 +static int
2618 +avr32_get_saved_reg (int save_reg_mask)
2619 +{
2620 + unsigned int reg;
2621 +
2622 + /* Find the first register which is saved in the saved_reg_mask */
2623 + for (reg = 0; reg <= 15; reg++)
2624 + if (save_reg_mask & (1 << reg))
2625 + return reg;
2626 +
2627 + return -1;
2628 +}
2629 +
2630 +
2631 +/* Return 1 if it is possible to return using a single instruction. */
2632 +int
2633 +avr32_use_return_insn (int iscond)
2634 +{
2635 + unsigned int func_type = avr32_current_func_type ();
2636 + unsigned long saved_int_regs;
2637 +
2638 + /* Never use a return instruction before reload has run. */
2639 + if (!reload_completed)
2640 + return 0;
2641 +
2642 + /* Must adjust the stack for vararg functions. */
2643 + if (current_function_args_info.uses_anonymous_args)
2644 + return 0;
2645 +
2646 + /* If there a stack adjstment. */
2647 + if (get_frame_size ())
2648 + return 0;
2649 +
2650 + saved_int_regs = avr32_compute_save_reg_mask (TRUE);
2651 +
2652 + /* Conditional returns can not be performed in one instruction if we need
2653 + to restore registers from the stack */
2654 + if (iscond && saved_int_regs)
2655 + return 0;
2656 +
2657 + /* Conditional return can not be used for interrupt handlers. */
2658 + if (iscond && IS_INTERRUPT (func_type))
2659 + return 0;
2660 +
2661 + /* For interrupt handlers which needs to pop registers */
2662 + if (saved_int_regs && IS_INTERRUPT (func_type))
2663 + return 0;
2664 +
2665 +
2666 + /* If there are saved registers but the LR isn't saved, then we need two
2667 + instructions for the return. */
2668 + if (saved_int_regs && !(saved_int_regs & (1 << ASM_REGNUM (LR_REGNUM))))
2669 + return 0;
2670 +
2671 +
2672 + return 1;
2673 +}
2674 +
2675 +
2676 +/* Generate some function prologue info in the assembly file. */
2677 +void
2678 +avr32_target_asm_function_prologue (FILE * f, HOST_WIDE_INT frame_size)
2679 +{
2680 + unsigned long func_type = avr32_current_func_type ();
2681 +
2682 + if (IS_NAKED (func_type))
2683 + fprintf (f,
2684 + "\t# Function is naked: Prologue and epilogue provided by programmer\n");
2685 +
2686 + if (IS_FLASHVAULT (func_type))
2687 + {
2688 + fprintf(f,
2689 + "\t.ident \"flashvault\"\n\t# Function is defined with flashvault attribute.\n");
2690 + }
2691 +
2692 + if (IS_FLASHVAULT_IMPL (func_type))
2693 + {
2694 + fprintf(f,
2695 + "\t.ident \"flashvault\"\n\t# Function is defined with flashvault_impl attribute.\n");
2696 +
2697 + /* Save information on flashvault function declaration. */
2698 + tree fv_attribute = lookup_attribute ("flashvault_impl", DECL_ATTRIBUTES(current_function_decl));
2699 + if (fv_attribute != NULL_TREE)
2700 + {
2701 + tree vector_tree = TREE_VALUE(fv_attribute);
2702 + if (vector_tree != NULL_TREE)
2703 + {
2704 + unsigned int vector_num;
2705 + const char * name;
2706 +
2707 + vector_num = (unsigned int) TREE_INT_CST_LOW (TREE_VALUE (vector_tree));
2708 +
2709 + name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2710 +
2711 + flashvault_decl_list_add (vector_num, name);
2712 + }
2713 + }
2714 + }
2715 +
2716 + if (IS_INTERRUPT (func_type))
2717 + {
2718 + switch (func_type)
2719 + {
2720 + case AVR32_FT_ISR_FULL:
2721 + fprintf (f,
2722 + "\t# Interrupt Function: Fully shadowed register file\n");
2723 + break;
2724 + case AVR32_FT_ISR_HALF:
2725 + fprintf (f,
2726 + "\t# Interrupt Function: Half shadowed register file\n");
2727 + break;
2728 + default:
2729 + case AVR32_FT_ISR_NONE:
2730 + fprintf (f, "\t# Interrupt Function: No shadowed register file\n");
2731 + break;
2732 + }
2733 + }
2734 +
2735 +
2736 + fprintf (f, "\t# args = %i, frame = %li, pretend = %i\n",
2737 + current_function_args_size, frame_size,
2738 + current_function_pretend_args_size);
2739 +
2740 + fprintf (f, "\t# frame_needed = %i, leaf_function = %i\n",
2741 + frame_pointer_needed, current_function_is_leaf);
2742 +
2743 + fprintf (f, "\t# uses_anonymous_args = %i\n",
2744 + current_function_args_info.uses_anonymous_args);
2745 +
2746 + if (current_function_calls_eh_return)
2747 + fprintf (f, "\t# Calls __builtin_eh_return.\n");
2748 +
2749 +}
2750 +
2751 +
2752 +/* Generate and emit an insn that we will recognize as a pushm or stm.
2753 + Unfortunately, since this insn does not reflect very well the actual
2754 + semantics of the operation, we need to annotate the insn for the benefit
2755 + of DWARF2 frame unwind information. */
2756 +
2757 +int avr32_convert_to_reglist16 (int reglist8_vect);
2758 +
2759 +static rtx
2760 +emit_multi_reg_push (int reglist, int usePUSHM)
2761 +{
2762 + rtx insn;
2763 + rtx dwarf;
2764 + rtx tmp;
2765 + rtx reg;
2766 + int i;
2767 + int nr_regs;
2768 + int index = 0;
2769 +
2770 + if (usePUSHM)
2771 + {
2772 + insn = emit_insn (gen_pushm (gen_rtx_CONST_INT (SImode, reglist)));
2773 + reglist = avr32_convert_to_reglist16 (reglist);
2774 + }
2775 + else
2776 + {
2777 + insn = emit_insn (gen_stm (stack_pointer_rtx,
2778 + gen_rtx_CONST_INT (SImode, reglist),
2779 + gen_rtx_CONST_INT (SImode, 1)));
2780 + }
2781 +
2782 + nr_regs = avr32_get_reg_mask_size (reglist) / 4;
2783 + dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (nr_regs + 1));
2784 +
2785 + for (i = 15; i >= 0; i--)
2786 + {
2787 + if (reglist & (1 << i))
2788 + {
2789 + reg = gen_rtx_REG (SImode, INTERNAL_REGNUM (i));
2790 + tmp = gen_rtx_SET (VOIDmode,
2791 + gen_rtx_MEM (SImode,
2792 + plus_constant (stack_pointer_rtx,
2793 + 4 * index)), reg);
2794 + RTX_FRAME_RELATED_P (tmp) = 1;
2795 + XVECEXP (dwarf, 0, 1 + index++) = tmp;
2796 + }
2797 + }
2798 +
2799 + tmp = gen_rtx_SET (SImode,
2800 + stack_pointer_rtx,
2801 + gen_rtx_PLUS (SImode,
2802 + stack_pointer_rtx,
2803 + GEN_INT (-4 * nr_regs)));
2804 + RTX_FRAME_RELATED_P (tmp) = 1;
2805 + XVECEXP (dwarf, 0, 0) = tmp;
2806 + REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, dwarf,
2807 + REG_NOTES (insn));
2808 + return insn;
2809 +}
2810 +
2811 +rtx
2812 +avr32_gen_load_multiple (rtx * regs, int count, rtx from,
2813 + int write_back, int in_struct_p, int scalar_p)
2814 +{
2815 +
2816 + rtx result;
2817 + int i = 0, j;
2818 +
2819 + result =
2820 + gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + (write_back ? 1 : 0)));
2821 +
2822 + if (write_back)
2823 + {
2824 + XVECEXP (result, 0, 0)
2825 + = gen_rtx_SET (GET_MODE (from), from,
2826 + plus_constant (from, count * 4));
2827 + i = 1;
2828 + count++;
2829 + }
2830 +
2831 +
2832 + for (j = 0; i < count; i++, j++)
2833 + {
2834 + rtx unspec;
2835 + rtx mem = gen_rtx_MEM (SImode, plus_constant (from, j * 4));
2836 + MEM_IN_STRUCT_P (mem) = in_struct_p;
2837 + MEM_SCALAR_P (mem) = scalar_p;
2838 + unspec = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, mem), UNSPEC_LDM);
2839 + XVECEXP (result, 0, i) = gen_rtx_SET (VOIDmode, regs[j], unspec);
2840 + }
2841 +
2842 + return result;
2843 +}
2844 +
2845 +
2846 +rtx
2847 +avr32_gen_store_multiple (rtx * regs, int count, rtx to,
2848 + int in_struct_p, int scalar_p)
2849 +{
2850 + rtx result;
2851 + int i = 0, j;
2852 +
2853 + result = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
2854 +
2855 + for (j = 0; i < count; i++, j++)
2856 + {
2857 + rtx mem = gen_rtx_MEM (SImode, plus_constant (to, j * 4));
2858 + MEM_IN_STRUCT_P (mem) = in_struct_p;
2859 + MEM_SCALAR_P (mem) = scalar_p;
2860 + XVECEXP (result, 0, i)
2861 + = gen_rtx_SET (VOIDmode, mem,
2862 + gen_rtx_UNSPEC (VOIDmode,
2863 + gen_rtvec (1, regs[j]),
2864 + UNSPEC_STORE_MULTIPLE));
2865 + }
2866 +
2867 + return result;
2868 +}
2869 +
2870 +
2871 +/* Move a block of memory if it is word aligned or we support unaligned
2872 + word memory accesses. The size must be maximum 64 bytes. */
2873 +int
2874 +avr32_gen_movmemsi (rtx * operands)
2875 +{
2876 + HOST_WIDE_INT bytes_to_go;
2877 + rtx src, dst;
2878 + rtx st_src, st_dst;
2879 + int src_offset = 0, dst_offset = 0;
2880 + int block_size;
2881 + int dst_in_struct_p, src_in_struct_p;
2882 + int dst_scalar_p, src_scalar_p;
2883 + int unaligned;
2884 +
2885 + if (GET_CODE (operands[2]) != CONST_INT
2886 + || GET_CODE (operands[3]) != CONST_INT
2887 + || INTVAL (operands[2]) > 64
2888 + || ((INTVAL (operands[3]) & 3) && !TARGET_UNALIGNED_WORD))
2889 + return 0;
2890 +
2891 + unaligned = (INTVAL (operands[3]) & 3) != 0;
2892 +
2893 + block_size = 4;
2894 +
2895 + st_dst = XEXP (operands[0], 0);
2896 + st_src = XEXP (operands[1], 0);
2897 +
2898 + dst_in_struct_p = MEM_IN_STRUCT_P (operands[0]);
2899 + dst_scalar_p = MEM_SCALAR_P (operands[0]);
2900 + src_in_struct_p = MEM_IN_STRUCT_P (operands[1]);
2901 + src_scalar_p = MEM_SCALAR_P (operands[1]);
2902 +
2903 + dst = copy_to_mode_reg (SImode, st_dst);
2904 + src = copy_to_mode_reg (SImode, st_src);
2905 +
2906 + bytes_to_go = INTVAL (operands[2]);
2907 +
2908 + while (bytes_to_go)
2909 + {
2910 + enum machine_mode move_mode;
2911 + /* (Seems to be a problem with reloads for the movti pattern so this is
2912 + disabled until that problem is resolved)
2913 + UPDATE: Problem seems to be solved now.... */
2914 + if (bytes_to_go >= GET_MODE_SIZE (TImode) && !unaligned
2915 + /* Do not emit ldm/stm for UC3 as ld.d/st.d is more optimal. */
2916 + && !TARGET_ARCH_UC)
2917 + move_mode = TImode;
2918 + else if ((bytes_to_go >= GET_MODE_SIZE (DImode)) && !unaligned)
2919 + move_mode = DImode;
2920 + else if (bytes_to_go >= GET_MODE_SIZE (SImode))
2921 + move_mode = SImode;
2922 + else
2923 + move_mode = QImode;
2924 +
2925 + {
2926 + rtx src_mem;
2927 + rtx dst_mem = gen_rtx_MEM (move_mode,
2928 + gen_rtx_PLUS (SImode, dst,
2929 + GEN_INT (dst_offset)));
2930 + dst_offset += GET_MODE_SIZE (move_mode);
2931 + if ( 0 /* This causes an error in GCC. Think there is
2932 + something wrong in the gcse pass which causes REQ_EQUIV notes
2933 + to be wrong so disabling it for now. */
2934 + && move_mode == TImode
2935 + && INTVAL (operands[2]) > GET_MODE_SIZE (TImode) )
2936 + {
2937 + src_mem = gen_rtx_MEM (move_mode,
2938 + gen_rtx_POST_INC (SImode, src));
2939 + }
2940 + else
2941 + {
2942 + src_mem = gen_rtx_MEM (move_mode,
2943 + gen_rtx_PLUS (SImode, src,
2944 + GEN_INT (src_offset)));
2945 + src_offset += GET_MODE_SIZE (move_mode);
2946 + }
2947 +
2948 + bytes_to_go -= GET_MODE_SIZE (move_mode);
2949 +
2950 + MEM_IN_STRUCT_P (dst_mem) = dst_in_struct_p;
2951 + MEM_SCALAR_P (dst_mem) = dst_scalar_p;
2952 +
2953 + MEM_IN_STRUCT_P (src_mem) = src_in_struct_p;
2954 + MEM_SCALAR_P (src_mem) = src_scalar_p;
2955 + emit_move_insn (dst_mem, src_mem);
2956 +
2957 + }
2958 + }
2959 +
2960 + return 1;
2961 +}
2962 +
2963 +
2964 +/* Expand the prologue instruction. */
2965 +void
2966 +avr32_expand_prologue (void)
2967 +{
2968 + rtx insn, dwarf;
2969 + unsigned long saved_reg_mask;
2970 + int reglist8 = 0;
2971 +
2972 + /* Naked functions do not have a prologue. */
2973 + if (IS_NAKED (avr32_current_func_type ()))
2974 + return;
2975 +
2976 + saved_reg_mask = avr32_compute_save_reg_mask (TRUE);
2977 +
2978 + if (saved_reg_mask)
2979 + {
2980 + /* Must push used registers. */
2981 +
2982 + /* Should we use POPM or LDM? */
2983 + int usePUSHM = TRUE;
2984 + reglist8 = 0;
2985 + if (((saved_reg_mask & (1 << 0)) ||
2986 + (saved_reg_mask & (1 << 1)) ||
2987 + (saved_reg_mask & (1 << 2)) || (saved_reg_mask & (1 << 3))))
2988 + {
2989 + /* One of R0-R3 should at least be pushed. */
2990 + if (((saved_reg_mask & (1 << 0)) &&
2991 + (saved_reg_mask & (1 << 1)) &&
2992 + (saved_reg_mask & (1 << 2)) && (saved_reg_mask & (1 << 3))))
2993 + {
2994 + /* All should be pushed. */
2995 + reglist8 |= 0x01;
2996 + }
2997 + else
2998 + {
2999 + usePUSHM = FALSE;
3000 + }
3001 + }
3002 +
3003 + if (((saved_reg_mask & (1 << 4)) ||
3004 + (saved_reg_mask & (1 << 5)) ||
3005 + (saved_reg_mask & (1 << 6)) || (saved_reg_mask & (1 << 7))))
3006 + {
3007 + /* One of R4-R7 should at least be pushed */
3008 + if (((saved_reg_mask & (1 << 4)) &&
3009 + (saved_reg_mask & (1 << 5)) &&
3010 + (saved_reg_mask & (1 << 6)) && (saved_reg_mask & (1 << 7))))
3011 + {
3012 + if (usePUSHM)
3013 + /* All should be pushed */
3014 + reglist8 |= 0x02;
3015 + }
3016 + else
3017 + {
3018 + usePUSHM = FALSE;
3019 + }
3020 + }
3021 +
3022 + if (((saved_reg_mask & (1 << 8)) || (saved_reg_mask & (1 << 9))))
3023 + {
3024 + /* One of R8-R9 should at least be pushed. */
3025 + if (((saved_reg_mask & (1 << 8)) && (saved_reg_mask & (1 << 9))))
3026 + {
3027 + if (usePUSHM)
3028 + /* All should be pushed. */
3029 + reglist8 |= 0x04;
3030 + }
3031 + else
3032 + {
3033 + usePUSHM = FALSE;
3034 + }
3035 + }
3036 +
3037 + if (saved_reg_mask & (1 << 10))
3038 + reglist8 |= 0x08;
3039 +
3040 + if (saved_reg_mask & (1 << 11))
3041 + reglist8 |= 0x10;
3042 +
3043 + if (saved_reg_mask & (1 << 12))
3044 + reglist8 |= 0x20;
3045 +
3046 + if ((saved_reg_mask & (1 << ASM_REGNUM (LR_REGNUM)))
3047 + && !IS_FLASHVAULT (avr32_current_func_type ()))
3048 + {
3049 + /* Push LR */
3050 + reglist8 |= 0x40;
3051 + }
3052 +
3053 + if (usePUSHM)
3054 + {
3055 + insn = emit_multi_reg_push (reglist8, TRUE);
3056 + }
3057 + else
3058 + {
3059 + insn = emit_multi_reg_push (saved_reg_mask, FALSE);
3060 + }
3061 + RTX_FRAME_RELATED_P (insn) = 1;
3062 +
3063 + /* Prevent this instruction from being scheduled after any other
3064 + instructions. */
3065 + emit_insn (gen_blockage ());
3066 + }
3067 +
3068 + /* Set frame pointer */
3069 + if (frame_pointer_needed)
3070 + {
3071 + insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
3072 + RTX_FRAME_RELATED_P (insn) = 1;
3073 + }
3074 +
3075 + if (get_frame_size () > 0)
3076 + {
3077 + if (avr32_const_ok_for_constraint_p (get_frame_size (), 'K', "Ks21"))
3078 + {
3079 + insn = emit_insn (gen_rtx_SET (SImode,
3080 + stack_pointer_rtx,
3081 + gen_rtx_PLUS (SImode,
3082 + stack_pointer_rtx,
3083 + gen_rtx_CONST_INT
3084 + (SImode,
3085 + -get_frame_size
3086 + ()))));
3087 + RTX_FRAME_RELATED_P (insn) = 1;
3088 + }
3089 + else
3090 + {
3091 + /* Immediate is larger than k21 We must either check if we can use
3092 + one of the pushed reegisters as temporary storage or we must
3093 + make us a temp register by pushing a register to the stack. */
3094 + rtx temp_reg, const_pool_entry, insn;
3095 + if (saved_reg_mask)
3096 + {
3097 + temp_reg =
3098 + gen_rtx_REG (SImode,
3099 + INTERNAL_REGNUM (avr32_get_saved_reg
3100 + (saved_reg_mask)));
3101 + }
3102 + else
3103 + {
3104 + temp_reg = gen_rtx_REG (SImode, INTERNAL_REGNUM (7));
3105 + emit_move_insn (gen_rtx_MEM
3106 + (SImode,
3107 + gen_rtx_PRE_DEC (SImode, stack_pointer_rtx)),
3108 + temp_reg);
3109 + }
3110 +
3111 + const_pool_entry =
3112 + force_const_mem (SImode,
3113 + gen_rtx_CONST_INT (SImode, get_frame_size ()));
3114 + emit_move_insn (temp_reg, const_pool_entry);
3115 +
3116 + insn = emit_insn (gen_rtx_SET (SImode,
3117 + stack_pointer_rtx,
3118 + gen_rtx_MINUS (SImode,
3119 + stack_pointer_rtx,
3120 + temp_reg)));
3121 +
3122 + dwarf = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
3123 + gen_rtx_PLUS (SImode, stack_pointer_rtx,
3124 + GEN_INT (-get_frame_size ())));
3125 + REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3126 + dwarf, REG_NOTES (insn));
3127 + RTX_FRAME_RELATED_P (insn) = 1;
3128 +
3129 + if (!saved_reg_mask)
3130 + {
3131 + insn =
3132 + emit_move_insn (temp_reg,
3133 + gen_rtx_MEM (SImode,
3134 + gen_rtx_POST_INC (SImode,
3135 + gen_rtx_REG
3136 + (SImode,
3137 + 13))));
3138 + }
3139 +
3140 + /* Mark the temp register as dead */
3141 + REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_DEAD, temp_reg,
3142 + REG_NOTES (insn));
3143 +
3144 +
3145 + }
3146 +
3147 + /* Prevent the the stack adjustment to be scheduled after any
3148 + instructions using the frame pointer. */
3149 + emit_insn (gen_blockage ());
3150 + }
3151 +
3152 + /* Load GOT */
3153 + if (flag_pic)
3154 + {
3155 + avr32_load_pic_register ();
3156 +
3157 + /* gcc does not know that load or call instructions might use the pic
3158 + register so it might schedule these instructions before the loading
3159 + of the pic register. To avoid this emit a barrier for now. TODO!
3160 + Find out a better way to let gcc know which instructions might use
3161 + the pic register. */
3162 + emit_insn (gen_blockage ());
3163 + }
3164 + return;
3165 +}
3166 +
3167 +
3168 +void
3169 +avr32_set_return_address (rtx source, rtx scratch)
3170 +{
3171 + rtx addr;
3172 + unsigned long saved_regs;
3173 +
3174 + saved_regs = avr32_compute_save_reg_mask (TRUE);
3175 +
3176 + if (!(saved_regs & (1 << ASM_REGNUM (LR_REGNUM))))
3177 + emit_move_insn (gen_rtx_REG (Pmode, LR_REGNUM), source);
3178 + else
3179 + {
3180 + if (frame_pointer_needed)
3181 + addr = gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM);
3182 + else
3183 + if (avr32_const_ok_for_constraint_p (get_frame_size (), 'K', "Ks16"))
3184 + {
3185 + addr = plus_constant (stack_pointer_rtx, get_frame_size ());
3186 + }
3187 + else
3188 + {
3189 + emit_insn (gen_movsi (scratch, GEN_INT (get_frame_size ())));
3190 + addr = scratch;
3191 + }
3192 + emit_move_insn (gen_rtx_MEM (Pmode, addr), source);
3193 + }
3194 +}
3195 +
3196 +
3197 +/* Return the length of INSN. LENGTH is the initial length computed by
3198 + attributes in the machine-description file. */
3199 +int
3200 +avr32_adjust_insn_length (rtx insn ATTRIBUTE_UNUSED,
3201 + int length ATTRIBUTE_UNUSED)
3202 +{
3203 + return length;
3204 +}
3205 +
3206 +
3207 +void
3208 +avr32_output_return_instruction (int single_ret_inst ATTRIBUTE_UNUSED,
3209 + int iscond ATTRIBUTE_UNUSED,
3210 + rtx cond ATTRIBUTE_UNUSED, rtx r12_imm)
3211 +{
3212 +
3213 + unsigned long saved_reg_mask;
3214 + int insert_ret = TRUE;
3215 + int reglist8 = 0;
3216 + int stack_adjustment = get_frame_size ();
3217 + unsigned int func_type = avr32_current_func_type ();
3218 + FILE *f = asm_out_file;
3219 +
3220 + /* Naked functions does not have an epilogue */
3221 + if (IS_NAKED (func_type))
3222 + return;
3223 +
3224 + saved_reg_mask = avr32_compute_save_reg_mask (FALSE);
3225 +
3226 + /* Reset frame pointer */
3227 + if (stack_adjustment > 0)
3228 + {
3229 + if (avr32_const_ok_for_constraint_p (stack_adjustment, 'I', "Is21"))
3230 + {
3231 + fprintf (f, "\tsub\tsp, %i # Reset Frame Pointer\n",
3232 + -stack_adjustment);
3233 + }
3234 + else
3235 + {
3236 + /* TODO! Is it safe to use r8 as scratch?? */
3237 + fprintf (f, "\tmov\tr8, lo(%i) # Reset Frame Pointer\n",
3238 + -stack_adjustment);
3239 + fprintf (f, "\torh\tr8, hi(%i) # Reset Frame Pointer\n",
3240 + -stack_adjustment);
3241 + fprintf (f, "\tadd\tsp, r8 # Reset Frame Pointer\n");
3242 + }
3243 + }
3244 +
3245 + if (saved_reg_mask)
3246 + {
3247 + /* Must pop used registers */
3248 +
3249 + /* Should we use POPM or LDM? */
3250 + int usePOPM = TRUE;
3251 + if (((saved_reg_mask & (1 << 0)) ||
3252 + (saved_reg_mask & (1 << 1)) ||
3253 + (saved_reg_mask & (1 << 2)) || (saved_reg_mask & (1 << 3))))
3254 + {
3255 + /* One of R0-R3 should at least be popped */
3256 + if (((saved_reg_mask & (1 << 0)) &&
3257 + (saved_reg_mask & (1 << 1)) &&
3258 + (saved_reg_mask & (1 << 2)) && (saved_reg_mask & (1 << 3))))
3259 + {
3260 + /* All should be popped */
3261 + reglist8 |= 0x01;
3262 + }
3263 + else
3264 + {
3265 + usePOPM = FALSE;
3266 + }
3267 + }
3268 +
3269 + if (((saved_reg_mask & (1 << 4)) ||
3270 + (saved_reg_mask & (1 << 5)) ||
3271 + (saved_reg_mask & (1 << 6)) || (saved_reg_mask & (1 << 7))))
3272 + {
3273 + /* One of R0-R3 should at least be popped */
3274 + if (((saved_reg_mask & (1 << 4)) &&
3275 + (saved_reg_mask & (1 << 5)) &&
3276 + (saved_reg_mask & (1 << 6)) && (saved_reg_mask & (1 << 7))))
3277 + {
3278 + if (usePOPM)
3279 + /* All should be popped */
3280 + reglist8 |= 0x02;
3281 + }
3282 + else
3283 + {
3284 + usePOPM = FALSE;
3285 + }
3286 + }
3287 +
3288 + if (((saved_reg_mask & (1 << 8)) || (saved_reg_mask & (1 << 9))))
3289 + {
3290 + /* One of R8-R9 should at least be pushed */
3291 + if (((saved_reg_mask & (1 << 8)) && (saved_reg_mask & (1 << 9))))
3292 + {
3293 + if (usePOPM)
3294 + /* All should be pushed */
3295 + reglist8 |= 0x04;
3296 + }
3297 + else
3298 + {
3299 + usePOPM = FALSE;
3300 + }
3301 + }
3302 +
3303 + if (saved_reg_mask & (1 << 10))
3304 + reglist8 |= 0x08;
3305 +
3306 + if (saved_reg_mask & (1 << 11))
3307 + reglist8 |= 0x10;
3308 +
3309 + if (saved_reg_mask & (1 << 12))
3310 + reglist8 |= 0x20;
3311 +
3312 + if (saved_reg_mask & (1 << ASM_REGNUM (LR_REGNUM)))
3313 + /* Pop LR */
3314 + reglist8 |= 0x40;
3315 +
3316 + if ((saved_reg_mask & (1 << ASM_REGNUM (PC_REGNUM)))
3317 + && !IS_FLASHVAULT_IMPL (func_type))
3318 + /* Pop LR into PC. */
3319 + reglist8 |= 0x80;
3320 +
3321 + if (usePOPM)
3322 + {
3323 + char reglist[64]; /* 64 bytes should be enough... */
3324 + avr32_make_reglist8 (reglist8, (char *) reglist);
3325 +
3326 + if (reglist8 & 0x80)
3327 + /* This instruction is also a return */
3328 + insert_ret = FALSE;
3329 +
3330 + if (r12_imm && !insert_ret)
3331 + fprintf (f, "\tpopm\t%s, r12=%li\n", reglist, INTVAL (r12_imm));
3332 + else
3333 + fprintf (f, "\tpopm\t%s\n", reglist);
3334 +
3335 + }
3336 + else
3337 + {
3338 + char reglist[64]; /* 64 bytes should be enough... */
3339 + avr32_make_reglist16 (saved_reg_mask, (char *) reglist);
3340 + if (saved_reg_mask & (1 << ASM_REGNUM (PC_REGNUM)))
3341 + /* This instruction is also a return */
3342 + insert_ret = FALSE;
3343 +
3344 + if (r12_imm && !insert_ret)
3345 + fprintf (f, "\tldm\tsp++, %s, r12=%li\n", reglist,
3346 + INTVAL (r12_imm));
3347 + else
3348 + fprintf (f, "\tldm\tsp++, %s\n", reglist);
3349 +
3350 + }
3351 +
3352 + }
3353 +
3354 + /* Stack adjustment for exception handler. */
3355 + if (current_function_calls_eh_return)
3356 + fprintf (f, "\tadd\tsp, r%d\n", ASM_REGNUM (EH_RETURN_STACKADJ_REGNO));
3357 +
3358 +
3359 + if (IS_INTERRUPT (func_type))
3360 + {
3361 + fprintf (f, "\trete\n");
3362 + }
3363 + else if (IS_FLASHVAULT (func_type))
3364 + {
3365 + /* Normal return from Secure System call, increment SS_RAR before
3366 + returning. Use R8 as scratch. */
3367 + fprintf (f,
3368 + "\t# Normal return from sscall.\n"
3369 + "\t# Increment SS_RAR before returning.\n"
3370 + "\t# Use R8 as scratch.\n"
3371 + "\tmfsr\tr8, 440\n"
3372 + "\tsub\tr8, -2\n"
3373 + "\tmtsr\t440, r8\n"
3374 + "\tretss\n");
3375 + }
3376 + else if (insert_ret)
3377 + {
3378 + if (r12_imm)
3379 + fprintf (f, "\tretal\t%li\n", INTVAL (r12_imm));
3380 + else
3381 + fprintf (f, "\tretal\tr12\n");
3382 + }
3383 +}
3384 +
3385 +void
3386 +avr32_make_reglist16 (int reglist16_vect, char *reglist16_string)
3387 +{
3388 + int i;
3389 + bool first_reg = true;
3390 + /* Make sure reglist16_string is empty. */
3391 + reglist16_string[0] = '\0';
3392 +
3393 + for (i = 0; i < 16; ++i)
3394 + {
3395 + if (reglist16_vect & (1 << i))
3396 + {
3397 + first_reg == true ? first_reg = false : strcat(reglist16_string,", ");
3398 + strcat (reglist16_string, reg_names[INTERNAL_REGNUM (i)]);
3399 + }
3400 + }
3401 +}
3402 +
3403 +int
3404 +avr32_convert_to_reglist16 (int reglist8_vect)
3405 +{
3406 + int reglist16_vect = 0;
3407 + if (reglist8_vect & 0x1)
3408 + reglist16_vect |= 0xF;
3409 + if (reglist8_vect & 0x2)
3410 + reglist16_vect |= 0xF0;
3411 + if (reglist8_vect & 0x4)
3412 + reglist16_vect |= 0x300;
3413 + if (reglist8_vect & 0x8)
3414 + reglist16_vect |= 0x400;
3415 + if (reglist8_vect & 0x10)
3416 + reglist16_vect |= 0x800;
3417 + if (reglist8_vect & 0x20)
3418 + reglist16_vect |= 0x1000;
3419 + if (reglist8_vect & 0x40)
3420 + reglist16_vect |= 0x4000;
3421 + if (reglist8_vect & 0x80)
3422 + reglist16_vect |= 0x8000;
3423 +
3424 + return reglist16_vect;
3425 +}
3426 +
3427 +void
3428 +avr32_make_reglist8 (int reglist8_vect, char *reglist8_string)
3429 +{
3430 + /* Make sure reglist8_string is empty. */
3431 + reglist8_string[0] = '\0';
3432 +
3433 + if (reglist8_vect & 0x1)
3434 + strcpy (reglist8_string, "r0-r3");
3435 + if (reglist8_vect & 0x2)
3436 + strlen (reglist8_string) ? strcat (reglist8_string, ", r4-r7") :
3437 + strcpy (reglist8_string, "r4-r7");
3438 + if (reglist8_vect & 0x4)
3439 + strlen (reglist8_string) ? strcat (reglist8_string, ", r8-r9") :
3440 + strcpy (reglist8_string, "r8-r9");
3441 + if (reglist8_vect & 0x8)
3442 + strlen (reglist8_string) ? strcat (reglist8_string, ", r10") :
3443 + strcpy (reglist8_string, "r10");
3444 + if (reglist8_vect & 0x10)
3445 + strlen (reglist8_string) ? strcat (reglist8_string, ", r11") :
3446 + strcpy (reglist8_string, "r11");
3447 + if (reglist8_vect & 0x20)
3448 + strlen (reglist8_string) ? strcat (reglist8_string, ", r12") :
3449 + strcpy (reglist8_string, "r12");
3450 + if (reglist8_vect & 0x40)
3451 + strlen (reglist8_string) ? strcat (reglist8_string, ", lr") :
3452 + strcpy (reglist8_string, "lr");
3453 + if (reglist8_vect & 0x80)
3454 + strlen (reglist8_string) ? strcat (reglist8_string, ", pc") :
3455 + strcpy (reglist8_string, "pc");
3456 +}
3457 +
3458 +
3459 +int
3460 +avr32_eh_return_data_regno (int n)
3461 +{
3462 + if (n >= 0 && n <= 3)
3463 + return 8 + n;
3464 + else
3465 + return INVALID_REGNUM;
3466 +}
3467 +
3468 +
3469 +/* Compute the distance from register FROM to register TO.
3470 + These can be the arg pointer, the frame pointer or
3471 + the stack pointer.
3472 + Typical stack layout looks like this:
3473 +
3474 + old stack pointer -> | |
3475 + ----
3476 + | | \
3477 + | | saved arguments for
3478 + | | vararg functions
3479 + arg_pointer -> | | /
3480 + --
3481 + | | \
3482 + | | call saved
3483 + | | registers
3484 + | | /
3485 + frame ptr -> --
3486 + | | \
3487 + | | local
3488 + | | variables
3489 + stack ptr --> | | /
3490 + --
3491 + | | \
3492 + | | outgoing
3493 + | | arguments
3494 + | | /
3495 + --
3496 +
3497 + For a given funciton some or all of these stack compomnents
3498 + may not be needed, giving rise to the possibility of
3499 + eliminating some of the registers.
3500 +
3501 + The values returned by this function must reflect the behaviour
3502 + of avr32_expand_prologue() and avr32_compute_save_reg_mask().
3503 +
3504 + The sign of the number returned reflects the direction of stack
3505 + growth, so the values are positive for all eliminations except
3506 + from the soft frame pointer to the hard frame pointer. */
3507 +int
3508 +avr32_initial_elimination_offset (int from, int to)
3509 +{
3510 + int i;
3511 + int call_saved_regs = 0;
3512 + unsigned long saved_reg_mask;
3513 + unsigned int local_vars = get_frame_size ();
3514 +
3515 + saved_reg_mask = avr32_compute_save_reg_mask (TRUE);
3516 +
3517 + for (i = 0; i < 16; ++i)
3518 + {
3519 + if (saved_reg_mask & (1 << i))
3520 + call_saved_regs += 4;
3521 + }
3522 +
3523 + switch (from)
3524 + {
3525 + case ARG_POINTER_REGNUM:
3526 + switch (to)
3527 + {
3528 + case STACK_POINTER_REGNUM:
3529 + return call_saved_regs + local_vars;
3530 + case FRAME_POINTER_REGNUM:
3531 + return call_saved_regs;
3532 + default:
3533 + abort ();
3534 + }
3535 + case FRAME_POINTER_REGNUM:
3536 + switch (to)
3537 + {
3538 + case STACK_POINTER_REGNUM:
3539 + return local_vars;
3540 + default:
3541 + abort ();
3542 + }
3543 + default:
3544 + abort ();
3545 + }
3546 +}
3547 +
3548 +
3549 +/*
3550 + Returns a rtx used when passing the next argument to a function.
3551 + avr32_init_cumulative_args() and avr32_function_arg_advance() sets which
3552 + register to use.
3553 +*/
3554 +rtx
3555 +avr32_function_arg (CUMULATIVE_ARGS * cum, enum machine_mode mode,
3556 + tree type, int named)
3557 +{
3558 + int index = -1;
3559 + //unsigned long func_type = avr32_current_func_type ();
3560 + //int last_reg_index = (IS_FLASHVAULT(func_type) || IS_FLASHVAULT_IMPL(func_type) || cum->flashvault_func ? LAST_CUM_REG_INDEX - 1 : LAST_CUM_REG_INDEX);
3561 + int last_reg_index = (cum->flashvault_func ? LAST_CUM_REG_INDEX - 1 : LAST_CUM_REG_INDEX);
3562 +
3563 + HOST_WIDE_INT arg_size, arg_rsize;
3564 + if (type)
3565 + {
3566 + arg_size = int_size_in_bytes (type);
3567 + }
3568 + else
3569 + {
3570 + arg_size = GET_MODE_SIZE (mode);
3571 + }
3572 + arg_rsize = PUSH_ROUNDING (arg_size);
3573 +
3574 + /*
3575 + The last time this macro is called, it is called with mode == VOIDmode,
3576 + and its result is passed to the call or call_value pattern as operands 2
3577 + and 3 respectively. */
3578 + if (mode == VOIDmode)
3579 + {
3580 + return gen_rtx_CONST_INT (SImode, 22); /* ToDo: fixme. */
3581 + }
3582 +
3583 + if ((*targetm.calls.must_pass_in_stack) (mode, type) || !named)
3584 + {
3585 + return NULL_RTX;
3586 + }
3587 +
3588 + if (arg_rsize == 8)
3589 + {
3590 + /* use r11:r10 or r9:r8. */
3591 + if (!(GET_USED_INDEX (cum, 1) || GET_USED_INDEX (cum, 2)))
3592 + index = 1;
3593 + else if ((last_reg_index == 4) &&
3594 + !(GET_USED_INDEX (cum, 3) || GET_USED_INDEX (cum, 4)))
3595 + index = 3;
3596 + else
3597 + index = -1;
3598 + }
3599 + else if (arg_rsize == 4)
3600 + { /* Use first available register */
3601 + index = 0;
3602 + while (index <= last_reg_index && GET_USED_INDEX (cum, index))
3603 + index++;
3604 + if (index > last_reg_index)
3605 + index = -1;
3606 + }
3607 +
3608 + SET_REG_INDEX (cum, index);
3609 +
3610 + if (GET_REG_INDEX (cum) >= 0)
3611 + return gen_rtx_REG (mode, avr32_function_arg_reglist[GET_REG_INDEX (cum)]);
3612 +
3613 + return NULL_RTX;
3614 +}
3615 +
3616 +
3617 +/* Set the register used for passing the first argument to a function. */
3618 +void
3619 +avr32_init_cumulative_args (CUMULATIVE_ARGS * cum,
3620 + tree fntype ATTRIBUTE_UNUSED,
3621 + rtx libname ATTRIBUTE_UNUSED,
3622 + tree fndecl)
3623 +{
3624 + /* Set all registers as unused. */
3625 + SET_INDEXES_UNUSED (cum);
3626 +
3627 + /* Reset uses_anonymous_args */
3628 + cum->uses_anonymous_args = 0;
3629 +
3630 + /* Reset size of stack pushed arguments */
3631 + cum->stack_pushed_args_size = 0;
3632 +
3633 + cum->flashvault_func = (fndecl && (has_attribute_p (fndecl,"flashvault") || has_attribute_p (fndecl,"flashvault_impl")));
3634 +}
3635 +
3636 +
3637 +/*
3638 + Set register used for passing the next argument to a function. Only the
3639 + Scratch Registers are used.
3640 +
3641 + number name
3642 + 15 r15 PC
3643 + 14 r14 LR
3644 + 13 r13 _SP_________
3645 + FIRST_CUM_REG 12 r12 _||_
3646 + 10 r11 ||
3647 + 11 r10 _||_ Scratch Registers
3648 + 8 r9 ||
3649 + LAST_SCRATCH_REG 9 r8 _\/_________
3650 + 6 r7 /\
3651 + 7 r6 ||
3652 + 4 r5 ||
3653 + 5 r4 ||
3654 + 2 r3 ||
3655 + 3 r2 ||
3656 + 0 r1 ||
3657 + 1 r0 _||_________
3658 +
3659 +*/
3660 +void
3661 +avr32_function_arg_advance (CUMULATIVE_ARGS * cum, enum machine_mode mode,
3662 + tree type, int named ATTRIBUTE_UNUSED)
3663 +{
3664 + HOST_WIDE_INT arg_size, arg_rsize;
3665 +
3666 + if (type)
3667 + {
3668 + arg_size = int_size_in_bytes (type);
3669 + }
3670 + else
3671 + {
3672 + arg_size = GET_MODE_SIZE (mode);
3673 + }
3674 + arg_rsize = PUSH_ROUNDING (arg_size);
3675 +
3676 + /* If the argument had to be passed in stack, no register is used. */
3677 + if ((*targetm.calls.must_pass_in_stack) (mode, type))
3678 + {
3679 + cum->stack_pushed_args_size += PUSH_ROUNDING (int_size_in_bytes (type));
3680 + return;
3681 + }
3682 +
3683 + /* Mark the used registers as "used". */
3684 + if (GET_REG_INDEX (cum) >= 0)
3685 + {
3686 + SET_USED_INDEX (cum, GET_REG_INDEX (cum));
3687 + if (arg_rsize == 8)
3688 + {
3689 + SET_USED_INDEX (cum, (GET_REG_INDEX (cum) + 1));
3690 + }
3691 + }
3692 + else
3693 + {
3694 + /* Had to use stack */
3695 + cum->stack_pushed_args_size += arg_rsize;
3696 + }
3697 +}
3698 +
3699 +
3700 +/*
3701 + Defines witch direction to go to find the next register to use if the
3702 + argument is larger then one register or for arguments shorter than an
3703 + int which is not promoted, such as the last part of structures with
3704 + size not a multiple of 4. */
3705 +enum direction
3706 +avr32_function_arg_padding (enum machine_mode mode ATTRIBUTE_UNUSED,
3707 + tree type)
3708 +{
3709 + /* Pad upward for all aggregates except byte and halfword sized aggregates
3710 + which can be passed in registers. */
3711 + if (type
3712 + && AGGREGATE_TYPE_P (type)
3713 + && (int_size_in_bytes (type) != 1)
3714 + && !((int_size_in_bytes (type) == 2)
3715 + && TYPE_ALIGN_UNIT (type) >= 2)
3716 + && (int_size_in_bytes (type) & 0x3))
3717 + {
3718 + return upward;
3719 + }
3720 +
3721 + return downward;
3722 +}
3723 +
3724 +
3725 +/* Return a rtx used for the return value from a function call. */
3726 +rtx
3727 +avr32_function_value (tree type, tree func, bool outgoing ATTRIBUTE_UNUSED)
3728 +{
3729 + if (avr32_return_in_memory (type, func))
3730 + return NULL_RTX;
3731 +
3732 + if (int_size_in_bytes (type) <= 4)
3733 + {
3734 + enum machine_mode mode = TYPE_MODE (type);
3735 + int unsignedp = 0;
3736 + PROMOTE_FUNCTION_MODE (mode, unsignedp, type);
3737 + return gen_rtx_REG (mode, RET_REGISTER);
3738 + }
3739 + else if (int_size_in_bytes (type) <= 8)
3740 + return gen_rtx_REG (TYPE_MODE (type), INTERNAL_REGNUM (11));
3741 +
3742 + return NULL_RTX;
3743 +}
3744 +
3745 +
3746 +/* Return a rtx used for the return value from a library function call. */
3747 +rtx
3748 +avr32_libcall_value (enum machine_mode mode)
3749 +{
3750 +
3751 + if (GET_MODE_SIZE (mode) <= 4)
3752 + return gen_rtx_REG (mode, RET_REGISTER);
3753 + else if (GET_MODE_SIZE (mode) <= 8)
3754 + return gen_rtx_REG (mode, INTERNAL_REGNUM (11));
3755 + else
3756 + return NULL_RTX;
3757 +}
3758 +
3759 +
3760 +/* Return TRUE if X references a SYMBOL_REF. */
3761 +int
3762 +symbol_mentioned_p (rtx x)
3763 +{
3764 + const char *fmt;
3765 + int i;
3766 +
3767 + if (GET_CODE (x) == SYMBOL_REF)
3768 + return 1;
3769 +
3770 + fmt = GET_RTX_FORMAT (GET_CODE (x));
3771 +
3772 + for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
3773 + {
3774 + if (fmt[i] == 'E')
3775 + {
3776 + int j;
3777 +
3778 + for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3779 + if (symbol_mentioned_p (XVECEXP (x, i, j)))
3780 + return 1;
3781 + }
3782 + else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i)))
3783 + return 1;
3784 + }
3785 +
3786 + return 0;
3787 +}
3788 +
3789 +
3790 +/* Return TRUE if X references a LABEL_REF. */
3791 +int
3792 +label_mentioned_p (rtx x)
3793 +{
3794 + const char *fmt;
3795 + int i;
3796 +
3797 + if (GET_CODE (x) == LABEL_REF)
3798 + return 1;
3799 +
3800 + fmt = GET_RTX_FORMAT (GET_CODE (x));
3801 + for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
3802 + {
3803 + if (fmt[i] == 'E')
3804 + {
3805 + int j;
3806 +
3807 + for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3808 + if (label_mentioned_p (XVECEXP (x, i, j)))
3809 + return 1;
3810 + }
3811 + else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i)))
3812 + return 1;
3813 + }
3814 +
3815 + return 0;
3816 +}
3817 +
3818 +
3819 +/* Return TRUE if X contains a MEM expression. */
3820 +int
3821 +mem_mentioned_p (rtx x)
3822 +{
3823 + const char *fmt;
3824 + int i;
3825 +
3826 + if (MEM_P (x))
3827 + return 1;
3828 +
3829 + fmt = GET_RTX_FORMAT (GET_CODE (x));
3830 + for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
3831 + {
3832 + if (fmt[i] == 'E')
3833 + {
3834 + int j;
3835 +
3836 + for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3837 + if (mem_mentioned_p (XVECEXP (x, i, j)))
3838 + return 1;
3839 + }
3840 + else if (fmt[i] == 'e' && mem_mentioned_p (XEXP (x, i)))
3841 + return 1;
3842 + }
3843 +
3844 + return 0;
3845 +}
3846 +
3847 +
3848 +int
3849 +avr32_legitimate_pic_operand_p (rtx x)
3850 +{
3851 +
3852 + /* We can't have const, this must be broken down to a symbol. */
3853 + if (GET_CODE (x) == CONST)
3854 + return FALSE;
3855 +
3856 + /* Can't access symbols or labels via the constant pool either */
3857 + if ((GET_CODE (x) == SYMBOL_REF
3858 + && CONSTANT_POOL_ADDRESS_P (x)
3859 + && (symbol_mentioned_p (get_pool_constant (x))
3860 + || label_mentioned_p (get_pool_constant (x)))))
3861 + return FALSE;
3862 +
3863 + return TRUE;
3864 +}
3865 +
3866 +
3867 +rtx
3868 +legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED,
3869 + rtx reg)
3870 +{
3871 +
3872 + if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
3873 + {
3874 + int subregs = 0;
3875 +
3876 + if (reg == 0)
3877 + {
3878 + if (!can_create_pseudo_p ())
3879 + abort ();
3880 + else
3881 + reg = gen_reg_rtx (Pmode);
3882 +
3883 + subregs = 1;
3884 + }
3885 +
3886 + emit_move_insn (reg, orig);
3887 +
3888 + /* Only set current function as using pic offset table if flag_pic is
3889 + set. This is because this function is also used if
3890 + TARGET_HAS_ASM_ADDR_PSEUDOS is set. */
3891 + if (flag_pic)
3892 + current_function_uses_pic_offset_table = 1;
3893 +
3894 + /* Put a REG_EQUAL note on this insn, so that it can be optimized by
3895 + loop. */
3896 + return reg;
3897 + }
3898 + else if (GET_CODE (orig) == CONST)
3899 + {
3900 + rtx base, offset;
3901 +
3902 + if (flag_pic
3903 + && GET_CODE (XEXP (orig, 0)) == PLUS
3904 + && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3905 + return orig;
3906 +
3907 + if (reg == 0)
3908 + {
3909 + if (!can_create_pseudo_p ())
3910 + abort ();
3911 + else
3912 + reg = gen_reg_rtx (Pmode);
3913 + }
3914 +
3915 + if (GET_CODE (XEXP (orig, 0)) == PLUS)
3916 + {
3917 + base =
3918 + legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
3919 + offset =
3920 + legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
3921 + base == reg ? 0 : reg);
3922 + }
3923 + else
3924 + abort ();
3925 +
3926 + if (GET_CODE (offset) == CONST_INT)
3927 + {
3928 + /* The base register doesn't really matter, we only want to test
3929 + the index for the appropriate mode. */
3930 + if (!avr32_const_ok_for_constraint_p (INTVAL (offset), 'I', "Is21"))
3931 + {
3932 + if (can_create_pseudo_p ())
3933 + offset = force_reg (Pmode, offset);
3934 + else
3935 + abort ();
3936 + }
3937 +
3938 + if (GET_CODE (offset) == CONST_INT)
3939 + return plus_constant (base, INTVAL (offset));
3940 + }
3941 +
3942 + return gen_rtx_PLUS (Pmode, base, offset);
3943 + }
3944 +
3945 + return orig;
3946 +}
3947 +
3948 +
3949 +/* Generate code to load the PIC register. */
3950 +void
3951 +avr32_load_pic_register (void)
3952 +{
3953 + rtx l1, pic_tmp;
3954 + rtx global_offset_table;
3955 +
3956 + if ((current_function_uses_pic_offset_table == 0) || TARGET_NO_INIT_GOT)
3957 + return;
3958 +
3959 + if (!flag_pic)
3960 + abort ();
3961 +
3962 + l1 = gen_label_rtx ();
3963 +
3964 + global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3965 + pic_tmp =
3966 + gen_rtx_CONST (Pmode,
3967 + gen_rtx_MINUS (SImode, gen_rtx_LABEL_REF (Pmode, l1),
3968 + global_offset_table));
3969 + emit_insn (gen_pic_load_addr
3970 + (pic_offset_table_rtx, force_const_mem (SImode, pic_tmp)));
3971 + emit_insn (gen_pic_compute_got_from_pc (pic_offset_table_rtx, l1));
3972 +
3973 + /* Need to emit this whether or not we obey regdecls, since setjmp/longjmp
3974 + can cause life info to screw up. */
3975 + emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3976 +}
3977 +
3978 +
3979 +/* This hook should return true if values of type type are returned at the most
3980 + significant end of a register (in other words, if they are padded at the
3981 + least significant end). You can assume that type is returned in a register;
3982 + the caller is required to check this. Note that the register provided by
3983 + FUNCTION_VALUE must be able to hold the complete return value. For example,
3984 + if a 1-, 2- or 3-byte structure is returned at the most significant end of a
3985 + 4-byte register, FUNCTION_VALUE should provide an SImode rtx. */
3986 +bool
3987 +avr32_return_in_msb (tree type ATTRIBUTE_UNUSED)
3988 +{
3989 + /* if ( AGGREGATE_TYPE_P (type) ) if ((int_size_in_bytes(type) == 1) ||
3990 + ((int_size_in_bytes(type) == 2) && TYPE_ALIGN_UNIT(type) >= 2)) return
3991 + false; else return true; */
3992 +
3993 + return false;
3994 +}
3995 +
3996 +
3997 +/*
3998 + Returns one if a certain function value is going to be returned in memory
3999 + and zero if it is going to be returned in a register.
4000 +
4001 + BLKmode and all other modes that is larger than 64 bits are returned in
4002 + memory.
4003 +*/
4004 +bool
4005 +avr32_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
4006 +{
4007 + if (TYPE_MODE (type) == VOIDmode)
4008 + return false;
4009 +
4010 + if (int_size_in_bytes (type) > (2 * UNITS_PER_WORD)
4011 + || int_size_in_bytes (type) == -1)
4012 + {
4013 + return true;
4014 + }
4015 +
4016 + /* If we have an aggregate then use the same mechanism as when checking if
4017 + it should be passed on the stack. */
4018 + if (type
4019 + && AGGREGATE_TYPE_P (type)
4020 + && (*targetm.calls.must_pass_in_stack) (TYPE_MODE (type), type))
4021 + return true;
4022 +
4023 + return false;
4024 +}
4025 +
4026 +
4027 +/* Output the constant part of the trampoline.
4028 + lddpc r0, pc[0x8:e] ; load static chain register
4029 + lddpc pc, pc[0x8:e] ; jump to subrutine
4030 + .long 0 ; Address to static chain,
4031 + ; filled in by avr32_initialize_trampoline()
4032 + .long 0 ; Address to subrutine,
4033 + ; filled in by avr32_initialize_trampoline()
4034 +*/
4035 +void
4036 +avr32_trampoline_template (FILE * file)
4037 +{
4038 + fprintf (file, "\tlddpc r0, pc[8]\n");
4039 + fprintf (file, "\tlddpc pc, pc[8]\n");
4040 + /* make room for the address of the static chain. */
4041 + fprintf (file, "\t.long\t0\n");
4042 + /* make room for the address to the subrutine. */
4043 + fprintf (file, "\t.long\t0\n");
4044 +}
4045 +
4046 +
4047 +/* Initialize the variable parts of a trampoline. */
4048 +void
4049 +avr32_initialize_trampoline (rtx addr, rtx fnaddr, rtx static_chain)
4050 +{
4051 + /* Store the address to the static chain. */
4052 + emit_move_insn (gen_rtx_MEM
4053 + (SImode, plus_constant (addr, TRAMPOLINE_SIZE - 4)),
4054 + static_chain);
4055 +
4056 + /* Store the address to the function. */
4057 + emit_move_insn (gen_rtx_MEM (SImode, plus_constant (addr, TRAMPOLINE_SIZE)),
4058 + fnaddr);
4059 +
4060 + emit_insn (gen_cache (gen_rtx_REG (SImode, 13),
4061 + gen_rtx_CONST_INT (SImode,
4062 + AVR32_CACHE_INVALIDATE_ICACHE)));
4063 +}
4064 +
4065 +
4066 +/* Return nonzero if X is valid as an addressing register. */
4067 +int
4068 +avr32_address_register_rtx_p (rtx x, int strict_p)
4069 +{
4070 + int regno;
4071 +
4072 + if (!register_operand(x, GET_MODE(x)))
4073 + return 0;
4074 +
4075 + /* If strict we require the register to be a hard register. */
4076 + if (strict_p
4077 + && !REG_P(x))
4078 + return 0;
4079 +
4080 + regno = REGNO (x);
4081 +
4082 + if (strict_p)
4083 + return REGNO_OK_FOR_BASE_P (regno);
4084 +
4085 + return (regno <= LAST_REGNUM || regno >= FIRST_PSEUDO_REGISTER);
4086 +}
4087 +
4088 +
4089 +/* Return nonzero if INDEX is valid for an address index operand. */
4090 +int
4091 +avr32_legitimate_index_p (enum machine_mode mode, rtx index, int strict_p)
4092 +{
4093 + enum rtx_code code = GET_CODE (index);
4094 +
4095 + if (GET_MODE_SIZE (mode) > 8)
4096 + return 0;
4097 +
4098 + /* Standard coprocessor addressing modes. */
4099 + if (code == CONST_INT)
4100 + {
4101 + return CONST_OK_FOR_CONSTRAINT_P (INTVAL (index), 'K', "Ks16");
4102 + }
4103 +
4104 + if (avr32_address_register_rtx_p (index, strict_p))
4105 + return 1;
4106 +
4107 + if (code == MULT)
4108 + {
4109 + rtx xiop0 = XEXP (index, 0);
4110 + rtx xiop1 = XEXP (index, 1);
4111 + return ((avr32_address_register_rtx_p (xiop0, strict_p)
4112 + && power_of_two_operand (xiop1, SImode)
4113 + && (INTVAL (xiop1) <= 8))
4114 + || (avr32_address_register_rtx_p (xiop1, strict_p)
4115 + && power_of_two_operand (xiop0, SImode)
4116 + && (INTVAL (xiop0) <= 8)));
4117 + }
4118 + else if (code == ASHIFT)
4119 + {
4120 + rtx op = XEXP (index, 1);
4121 +
4122 + return (avr32_address_register_rtx_p (XEXP (index, 0), strict_p)
4123 + && GET_CODE (op) == CONST_INT
4124 + && INTVAL (op) > 0 && INTVAL (op) <= 3);
4125 + }
4126 +
4127 + return 0;
4128 +}
4129 +
4130 +
4131 +/*
4132 + Used in the GO_IF_LEGITIMATE_ADDRESS macro. Returns a nonzero value if
4133 + the RTX x is a legitimate memory address.
4134 +
4135 + Returns NO_REGS if the address is not legatime, GENERAL_REGS or ALL_REGS
4136 + if it is.
4137 +*/
4138 +
4139 +
4140 +/* Forward declaration */
4141 +int is_minipool_label (rtx label);
4142 +
4143 +int
4144 +avr32_legitimate_address (enum machine_mode mode, rtx x, int strict)
4145 +{
4146 +
4147 + switch (GET_CODE (x))
4148 + {
4149 + case REG:
4150 + return avr32_address_register_rtx_p (x, strict);
4151 + case CONST_INT:
4152 + return ((mode==SImode) && TARGET_RMW_ADDRESSABLE_DATA
4153 + && CONST_OK_FOR_CONSTRAINT_P(INTVAL(x), 'K', "Ks17"));
4154 + case CONST:
4155 + {
4156 + rtx label = avr32_find_symbol (x);
4157 + if (label
4158 + &&
4159 + (/*
4160 + If we enable (const (plus (symbol_ref ...))) type constant
4161 + pool entries we must add support for it in the predicates and
4162 + in the minipool generation in avr32_reorg().
4163 + (CONSTANT_POOL_ADDRESS_P (label)
4164 + && !(flag_pic
4165 + && (symbol_mentioned_p (get_pool_constant (label))
4166 + || label_mentioned_p (get_pool_constant (label)))))
4167 + ||*/
4168 + ((GET_CODE (label) == LABEL_REF)
4169 + && GET_CODE (XEXP (label, 0)) == CODE_LABEL
4170 + && is_minipool_label (XEXP (label, 0)))
4171 + /*|| ((GET_CODE (label) == SYMBOL_REF)
4172 + && mode == SImode
4173 + && SYMBOL_REF_RMW_ADDR(label))*/))
4174 + {
4175 + return TRUE;
4176 + }
4177 + }
4178 + break;
4179 + case LABEL_REF:
4180 + if (GET_CODE (XEXP (x, 0)) == CODE_LABEL
4181 + && is_minipool_label (XEXP (x, 0)))
4182 + {
4183 + return TRUE;
4184 + }
4185 + break;
4186 + case SYMBOL_REF:
4187 + {
4188 + if (CONSTANT_POOL_ADDRESS_P (x)
4189 + && !(flag_pic
4190 + && (symbol_mentioned_p (get_pool_constant (x))
4191 + || label_mentioned_p (get_pool_constant (x)))))
4192 + return TRUE;
4193 + else if (SYMBOL_REF_RCALL_FUNCTION_P (x)
4194 + || (mode == SImode
4195 + && SYMBOL_REF_RMW_ADDR (x)))
4196 + return TRUE;
4197 + break;
4198 + }
4199 + case PRE_DEC: /* (pre_dec (...)) */
4200 + case POST_INC: /* (post_inc (...)) */
4201 + return avr32_address_register_rtx_p (XEXP (x, 0), strict);
4202 + case PLUS: /* (plus (...) (...)) */
4203 + {
4204 + rtx xop0 = XEXP (x, 0);
4205 + rtx xop1 = XEXP (x, 1);
4206 +
4207 + return ((avr32_address_register_rtx_p (xop0, strict)
4208 + && avr32_legitimate_index_p (mode, xop1, strict))
4209 + || (avr32_address_register_rtx_p (xop1, strict)
4210 + && avr32_legitimate_index_p (mode, xop0, strict)));
4211 + }
4212 + default:
4213 + break;
4214 + }
4215 +
4216 + return FALSE;
4217 +}
4218 +
4219 +
4220 +int
4221 +avr32_const_ok_for_move (HOST_WIDE_INT c)
4222 +{
4223 + if ( TARGET_V2_INSNS )
4224 + return ( avr32_const_ok_for_constraint_p (c, 'K', "Ks21")
4225 + /* movh instruction */
4226 + || avr32_hi16_immediate_operand (GEN_INT(c), VOIDmode) );
4227 + else
4228 + return avr32_const_ok_for_constraint_p (c, 'K', "Ks21");
4229 +}
4230 +
4231 +
4232 +int
4233 +avr32_const_double_immediate (rtx value)
4234 +{
4235 + HOST_WIDE_INT hi, lo;
4236 +
4237 + if (GET_CODE (value) != CONST_DOUBLE)
4238 + return FALSE;
4239 +
4240 + if (SCALAR_FLOAT_MODE_P (GET_MODE (value)))
4241 + {
4242 + HOST_WIDE_INT target_float[2];
4243 + hi = lo = 0;
4244 + real_to_target (target_float, CONST_DOUBLE_REAL_VALUE (value),
4245 + GET_MODE (value));
4246 + lo = target_float[0];
4247 + hi = target_float[1];
4248 + }
4249 + else
4250 + {
4251 + hi = CONST_DOUBLE_HIGH (value);
4252 + lo = CONST_DOUBLE_LOW (value);
4253 + }
4254 +
4255 + if (avr32_const_ok_for_constraint_p (lo, 'K', "Ks21")
4256 + && (GET_MODE (value) == SFmode
4257 + || avr32_const_ok_for_constraint_p (hi, 'K', "Ks21")))
4258 + {
4259 + return TRUE;
4260 + }
4261 +
4262 + return FALSE;
4263 +}
4264 +
4265 +
4266 +int
4267 +avr32_legitimate_constant_p (rtx x)
4268 +{
4269 + switch (GET_CODE (x))
4270 + {
4271 + case CONST_INT:
4272 + /* Check if we should put large immediate into constant pool
4273 + or load them directly with mov/orh.*/
4274 + if (!avr32_imm_in_const_pool)
4275 + return 1;
4276 +
4277 + return avr32_const_ok_for_move (INTVAL (x));
4278 + case CONST_DOUBLE:
4279 + /* Check if we should put large immediate into constant pool
4280 + or load them directly with mov/orh.*/
4281 + if (!avr32_imm_in_const_pool)
4282 + return 1;
4283 +
4284 + if (GET_MODE (x) == SFmode
4285 + || GET_MODE (x) == DFmode || GET_MODE (x) == DImode)
4286 + return avr32_const_double_immediate (x);
4287 + else
4288 + return 0;
4289 + case LABEL_REF:
4290 + case SYMBOL_REF:
4291 + return avr32_find_symbol (x) && (flag_pic || TARGET_HAS_ASM_ADDR_PSEUDOS);
4292 + case CONST:
4293 + case HIGH:
4294 + case CONST_VECTOR:
4295 + return 0;
4296 + default:
4297 + printf ("%s():\n", __FUNCTION__);
4298 + debug_rtx (x);
4299 + return 1;
4300 + }
4301 +}
4302 +
4303 +
4304 +/* Strip any special encoding from labels */
4305 +const char *
4306 +avr32_strip_name_encoding (const char *name)
4307 +{
4308 + const char *stripped = name;
4309 +
4310 + while (1)
4311 + {
4312 + switch (stripped[0])
4313 + {
4314 + case '#':
4315 + stripped = strchr (name + 1, '#') + 1;
4316 + break;
4317 + case '*':
4318 + stripped = &stripped[1];
4319 + break;
4320 + default:
4321 + return stripped;
4322 + }
4323 + }
4324 +}
4325 +
4326 +
4327 +
4328 +/* Do anything needed before RTL is emitted for each function. */
4329 +static struct machine_function *
4330 +avr32_init_machine_status (void)
4331 +{
4332 + struct machine_function *machine;
4333 + machine =
4334 + (machine_function *) ggc_alloc_cleared (sizeof (machine_function));
4335 +
4336 +#if AVR32_FT_UNKNOWN != 0
4337 + machine->func_type = AVR32_FT_UNKNOWN;
4338 +#endif
4339 +
4340 + machine->minipool_label_head = 0;
4341 + machine->minipool_label_tail = 0;
4342 + machine->ifcvt_after_reload = 0;
4343 + return machine;
4344 +}
4345 +
4346 +
4347 +void
4348 +avr32_init_expanders (void)
4349 +{
4350 + /* Arrange to initialize and mark the machine per-function status. */
4351 + init_machine_status = avr32_init_machine_status;
4352 +}
4353 +
4354 +
4355 +/* Return an RTX indicating where the return address to the
4356 + calling function can be found. */
4357 +rtx
4358 +avr32_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
4359 +{
4360 + if (count != 0)
4361 + return NULL_RTX;
4362 +
4363 + return get_hard_reg_initial_val (Pmode, LR_REGNUM);
4364 +}
4365 +
4366 +
4367 +void
4368 +avr32_encode_section_info (tree decl, rtx rtl, int first)
4369 +{
4370 + default_encode_section_info(decl, rtl, first);
4371 +
4372 + if ( TREE_CODE (decl) == VAR_DECL
4373 + && (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
4374 + && (lookup_attribute ("rmw_addressable", DECL_ATTRIBUTES (decl))
4375 + || TARGET_RMW_ADDRESSABLE_DATA) ){
4376 + if ( !TARGET_RMW || flag_pic )
4377 + return;
4378 + // {
4379 + // warning ("Using RMW addressable data with an arch that does not support RMW instructions.");
4380 + // return;
4381 + // }
4382 + //
4383 + //if ( flag_pic )
4384 + // {
4385 + // warning ("Using RMW addressable data with together with -fpic switch. Can not use RMW instruction when compiling with -fpic.");
4386 + // return;
4387 + // }
4388 + SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= (1 << SYMBOL_FLAG_RMW_ADDR_SHIFT);
4389 + }
4390 +}
4391 +
4392 +
4393 +void
4394 +avr32_asm_output_label (FILE * stream, const char *name)
4395 +{
4396 + name = avr32_strip_name_encoding (name);
4397 +
4398 + /* Print the label. */
4399 + assemble_name (stream, name);
4400 + fprintf (stream, ":\n");
4401 +}
4402 +
4403 +
4404 +void
4405 +avr32_asm_weaken_label (FILE * stream, const char *name)
4406 +{
4407 + fprintf (stream, "\t.weak ");
4408 + assemble_name (stream, name);
4409 + fprintf (stream, "\n");
4410 +}
4411 +
4412 +
4413 +/*
4414 + Checks if a labelref is equal to a reserved word in the assembler. If it is,
4415 + insert a '_' before the label name.
4416 +*/
4417 +void
4418 +avr32_asm_output_labelref (FILE * stream, const char *name)
4419 +{
4420 + int verbatim = FALSE;
4421 + const char *stripped = name;
4422 + int strip_finished = FALSE;
4423 +
4424 + while (!strip_finished)
4425 + {
4426 + switch (stripped[0])
4427 + {
4428 + case '#':
4429 + stripped = strchr (name + 1, '#') + 1;
4430 + break;
4431 + case '*':
4432 + stripped = &stripped[1];
4433 + verbatim = TRUE;
4434 + break;
4435 + default:
4436 + strip_finished = TRUE;
4437 + break;
4438 + }
4439 + }
4440 +
4441 + if (verbatim)
4442 + fputs (stripped, stream);
4443 + else
4444 + asm_fprintf (stream, "%U%s", stripped);
4445 +}
4446 +
4447 +
4448 +/*
4449 + Check if the comparison in compare_exp is redundant
4450 + for the condition given in next_cond given that the
4451 + needed flags are already set by an earlier instruction.
4452 + Uses cc_prev_status to check this.
4453 +
4454 + Returns NULL_RTX if the compare is not redundant
4455 + or the new condition to use in the conditional
4456 + instruction if the compare is redundant.
4457 +*/
4458 +static rtx
4459 +is_compare_redundant (rtx compare_exp, rtx next_cond)
4460 +{
4461 + int z_flag_valid = FALSE;
4462 + int n_flag_valid = FALSE;
4463 + rtx new_cond;
4464 +
4465 + if (GET_CODE (compare_exp) != COMPARE
4466 + && GET_CODE (compare_exp) != AND)
4467 + return NULL_RTX;
4468 +
4469 +
4470 + if (rtx_equal_p (cc_prev_status.mdep.value, compare_exp))
4471 + {
4472 + /* cc0 already contains the correct comparison -> delete cmp insn */
4473 + return next_cond;
4474 + }
4475 +
4476 + if (GET_MODE (compare_exp) != SImode)
4477 + return NULL_RTX;
4478 +
4479 + switch (cc_prev_status.mdep.flags)
4480 + {
4481 + case CC_SET_VNCZ:
4482 + case CC_SET_NCZ:
4483 + n_flag_valid = TRUE;
4484 + case CC_SET_CZ:
4485 + case CC_SET_Z:
4486 + z_flag_valid = TRUE;
4487 + }
4488 +
4489 + if (cc_prev_status.mdep.value
4490 + && GET_CODE (compare_exp) == COMPARE
4491 + && REG_P (XEXP (compare_exp, 0))
4492 + && REGNO (XEXP (compare_exp, 0)) == REGNO (cc_prev_status.mdep.value)
4493 + && GET_CODE (XEXP (compare_exp, 1)) == CONST_INT
4494 + && next_cond != NULL_RTX)
4495 + {
4496 + if (INTVAL (XEXP (compare_exp, 1)) == 0
4497 + && z_flag_valid
4498 + && (GET_CODE (next_cond) == EQ || GET_CODE (next_cond) == NE))
4499 + /* We can skip comparison Z flag is already reflecting ops[0] */
4500 + return next_cond;
4501 + else if (n_flag_valid
4502 + && ((INTVAL (XEXP (compare_exp, 1)) == 0
4503 + && (GET_CODE (next_cond) == GE
4504 + || GET_CODE (next_cond) == LT))
4505 + || (INTVAL (XEXP (compare_exp, 1)) == -1
4506 + && (GET_CODE (next_cond) == GT
4507 + || GET_CODE (next_cond) == LE))))
4508 + {
4509 + /* We can skip comparison N flag is already reflecting ops[0],
4510 + which means that we can use the mi/pl conditions to check if
4511 + ops[0] is GE or LT 0. */
4512 + if ((GET_CODE (next_cond) == GE) || (GET_CODE (next_cond) == GT))
4513 + new_cond =
4514 + gen_rtx_UNSPEC (GET_MODE (next_cond), gen_rtvec (2, cc0_rtx, const0_rtx),
4515 + UNSPEC_COND_PL);
4516 + else
4517 + new_cond =
4518 + gen_rtx_UNSPEC (GET_MODE (next_cond), gen_rtvec (2, cc0_rtx, const0_rtx),
4519 + UNSPEC_COND_MI);
4520 + return new_cond;
4521 + }
4522 + }
4523 + return NULL_RTX;
4524 +}
4525 +
4526 +
4527 +/* Updates cc_status. */
4528 +void
4529 +avr32_notice_update_cc (rtx exp, rtx insn)
4530 +{
4531 + enum attr_cc attr_cc = get_attr_cc (insn);
4532 +
4533 + if ( attr_cc == CC_SET_Z_IF_NOT_V2 )
4534 + {
4535 + if (TARGET_V2_INSNS)
4536 + attr_cc = CC_NONE;
4537 + else
4538 + attr_cc = CC_SET_Z;
4539 + }
4540 +
4541 + switch (attr_cc)
4542 + {
4543 + case CC_CALL_SET:
4544 + CC_STATUS_INIT;
4545 + /* Check if the function call returns a value in r12 */
4546 + if (REG_P (recog_data.operand[0])
4547 + && REGNO (recog_data.operand[0]) == RETVAL_REGNUM)
4548 + {
4549 + cc_status.flags = 0;
4550 + cc_status.mdep.value =
4551 + gen_rtx_COMPARE (SImode, recog_data.operand[0], const0_rtx);
4552 + cc_status.mdep.flags = CC_SET_VNCZ;
4553 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4554 +
4555 + }
4556 + break;
4557 + case CC_COMPARE:
4558 + {
4559 + /* Check that compare will not be optimized away if so nothing should
4560 + be done */
4561 + rtx compare_exp = SET_SRC (exp);
4562 + /* Check if we have a tst expression. If so convert it to a
4563 + compare with 0. */
4564 + if ( REG_P (SET_SRC (exp)) )
4565 + compare_exp = gen_rtx_COMPARE (GET_MODE (SET_SRC (exp)),
4566 + SET_SRC (exp),
4567 + const0_rtx);
4568 +
4569 + if (!next_insn_emits_cmp (insn)
4570 + && (is_compare_redundant (compare_exp, get_next_insn_cond (insn)) == NULL_RTX))
4571 + {
4572 +
4573 + /* Reset the nonstandard flag */
4574 + CC_STATUS_INIT;
4575 + cc_status.flags = 0;
4576 + cc_status.mdep.value = compare_exp;
4577 + cc_status.mdep.flags = CC_SET_VNCZ;
4578 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4579 + }
4580 + }
4581 + break;
4582 + case CC_CMP_COND_INSN:
4583 + {
4584 + /* Conditional insn that emit the compare itself. */
4585 + rtx cmp;
4586 + rtx cmp_op0, cmp_op1;
4587 + rtx cond;
4588 + rtx dest;
4589 + rtx next_insn = next_nonnote_insn (insn);
4590 +
4591 + if ( GET_CODE (exp) == COND_EXEC )
4592 + {
4593 + cmp_op0 = XEXP (COND_EXEC_TEST (exp), 0);
4594 + cmp_op1 = XEXP (COND_EXEC_TEST (exp), 1);
4595 + cond = COND_EXEC_TEST (exp);
4596 + dest = SET_DEST (COND_EXEC_CODE (exp));
4597 + }
4598 + else
4599 + {
4600 + /* If then else conditional. compare operands are in operands
4601 + 4 and 5. */
4602 + cmp_op0 = recog_data.operand[4];
4603 + cmp_op1 = recog_data.operand[5];
4604 + cond = recog_data.operand[1];
4605 + dest = SET_DEST (exp);
4606 + }
4607 +
4608 + if ( GET_CODE (cmp_op0) == AND )
4609 + cmp = cmp_op0;
4610 + else
4611 + cmp = gen_rtx_COMPARE (GET_MODE (cmp_op0),
4612 + cmp_op0,
4613 + cmp_op1);
4614 +
4615 + /* Check if the conditional insns updates a register present
4616 + in the comparison, if so then we must reset the cc_status. */
4617 + if (REG_P (dest)
4618 + && (reg_mentioned_p (dest, cmp_op0)
4619 + || reg_mentioned_p (dest, cmp_op1))
4620 + && GET_CODE (exp) != COND_EXEC )
4621 + {
4622 + CC_STATUS_INIT;
4623 + }
4624 + else if (is_compare_redundant (cmp, cond) == NULL_RTX)
4625 + {
4626 + /* Reset the nonstandard flag */
4627 + CC_STATUS_INIT;
4628 + if ( GET_CODE (cmp_op0) == AND )
4629 + {
4630 + cc_status.flags = CC_INVERTED;
4631 + cc_status.mdep.flags = CC_SET_Z;
4632 + }
4633 + else
4634 + {
4635 + cc_status.flags = 0;
4636 + cc_status.mdep.flags = CC_SET_VNCZ;
4637 + }
4638 + cc_status.mdep.value = cmp;
4639 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4640 + }
4641 +
4642 +
4643 + /* Check if we have a COND_EXEC insn which updates one
4644 + of the registers in the compare status. */
4645 + if (REG_P (dest)
4646 + && (reg_mentioned_p (dest, cmp_op0)
4647 + || reg_mentioned_p (dest, cmp_op1))
4648 + && GET_CODE (exp) == COND_EXEC )
4649 + cc_status.mdep.cond_exec_cmp_clobbered = 1;
4650 +
4651 + if ( cc_status.mdep.cond_exec_cmp_clobbered
4652 + && GET_CODE (exp) == COND_EXEC
4653 + && next_insn != NULL
4654 + && INSN_P (next_insn)
4655 + && !(GET_CODE (PATTERN (next_insn)) == COND_EXEC
4656 + && rtx_equal_p (XEXP (COND_EXEC_TEST (PATTERN (next_insn)), 0), cmp_op0)
4657 + && rtx_equal_p (XEXP (COND_EXEC_TEST (PATTERN (next_insn)), 1), cmp_op1)
4658 + && (GET_CODE (COND_EXEC_TEST (PATTERN (next_insn))) == GET_CODE (cond)
4659 + || GET_CODE (COND_EXEC_TEST (PATTERN (next_insn))) == reverse_condition (GET_CODE (cond)))) )
4660 + {
4661 + /* We have a sequence of conditional insns where the compare status has been clobbered
4662 + since the compare no longer reflects the content of the values to compare. */
4663 + CC_STATUS_INIT;
4664 + cc_status.mdep.cond_exec_cmp_clobbered = 1;
4665 + }
4666 +
4667 + }
4668 + break;
4669 + case CC_BLD:
4670 + /* Bit load is kind of like an inverted testsi, because the Z flag is
4671 + inverted */
4672 + CC_STATUS_INIT;
4673 + cc_status.flags = CC_INVERTED;
4674 + cc_status.mdep.value = SET_SRC (exp);
4675 + cc_status.mdep.flags = CC_SET_Z;
4676 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4677 + break;
4678 + case CC_NONE:
4679 + /* Insn does not affect CC at all. Check if the instruction updates
4680 + some of the register currently reflected in cc0 */
4681 +
4682 + if ((GET_CODE (exp) == SET)
4683 + && (cc_status.value1 || cc_status.value2 || cc_status.mdep.value)
4684 + && (reg_mentioned_p (SET_DEST (exp), cc_status.value1)
4685 + || reg_mentioned_p (SET_DEST (exp), cc_status.value2)
4686 + || reg_mentioned_p (SET_DEST (exp), cc_status.mdep.value)))
4687 + {
4688 + CC_STATUS_INIT;
4689 + }
4690 +
4691 + /* If this is a parallel we must step through each of the parallel
4692 + expressions */
4693 + if (GET_CODE (exp) == PARALLEL)
4694 + {
4695 + int i;
4696 + for (i = 0; i < XVECLEN (exp, 0); ++i)
4697 + {
4698 + rtx vec_exp = XVECEXP (exp, 0, i);
4699 + if ((GET_CODE (vec_exp) == SET)
4700 + && (cc_status.value1 || cc_status.value2
4701 + || cc_status.mdep.value)
4702 + && (reg_mentioned_p (SET_DEST (vec_exp), cc_status.value1)
4703 + || reg_mentioned_p (SET_DEST (vec_exp),
4704 + cc_status.value2)
4705 + || reg_mentioned_p (SET_DEST (vec_exp),
4706 + cc_status.mdep.value)))
4707 + {
4708 + CC_STATUS_INIT;
4709 + }
4710 + }
4711 + }
4712 +
4713 + /* Check if we have memory opartions with post_inc or pre_dec on the
4714 + register currently reflected in cc0 */
4715 + if (GET_CODE (exp) == SET
4716 + && GET_CODE (SET_SRC (exp)) == MEM
4717 + && (GET_CODE (XEXP (SET_SRC (exp), 0)) == POST_INC
4718 + || GET_CODE (XEXP (SET_SRC (exp), 0)) == PRE_DEC)
4719 + &&
4720 + (reg_mentioned_p
4721 + (XEXP (XEXP (SET_SRC (exp), 0), 0), cc_status.value1)
4722 + || reg_mentioned_p (XEXP (XEXP (SET_SRC (exp), 0), 0),
4723 + cc_status.value2)
4724 + || reg_mentioned_p (XEXP (XEXP (SET_SRC (exp), 0), 0),
4725 + cc_status.mdep.value)))
4726 + CC_STATUS_INIT;
4727 +
4728 + if (GET_CODE (exp) == SET
4729 + && GET_CODE (SET_DEST (exp)) == MEM
4730 + && (GET_CODE (XEXP (SET_DEST (exp), 0)) == POST_INC
4731 + || GET_CODE (XEXP (SET_DEST (exp), 0)) == PRE_DEC)
4732 + &&
4733 + (reg_mentioned_p
4734 + (XEXP (XEXP (SET_DEST (exp), 0), 0), cc_status.value1)
4735 + || reg_mentioned_p (XEXP (XEXP (SET_DEST (exp), 0), 0),
4736 + cc_status.value2)
4737 + || reg_mentioned_p (XEXP (XEXP (SET_DEST (exp), 0), 0),
4738 + cc_status.mdep.value)))
4739 + CC_STATUS_INIT;
4740 + break;
4741 +
4742 + case CC_SET_VNCZ:
4743 + CC_STATUS_INIT;
4744 + cc_status.mdep.value = recog_data.operand[0];
4745 + cc_status.mdep.flags = CC_SET_VNCZ;
4746 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4747 + break;
4748 +
4749 + case CC_SET_NCZ:
4750 + CC_STATUS_INIT;
4751 + cc_status.mdep.value = recog_data.operand[0];
4752 + cc_status.mdep.flags = CC_SET_NCZ;
4753 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4754 + break;
4755 +
4756 + case CC_SET_CZ:
4757 + CC_STATUS_INIT;
4758 + cc_status.mdep.value = recog_data.operand[0];
4759 + cc_status.mdep.flags = CC_SET_CZ;
4760 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4761 + break;
4762 +
4763 + case CC_SET_Z:
4764 + CC_STATUS_INIT;
4765 + cc_status.mdep.value = recog_data.operand[0];
4766 + cc_status.mdep.flags = CC_SET_Z;
4767 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4768 + break;
4769 +
4770 + case CC_CLOBBER:
4771 + CC_STATUS_INIT;
4772 + break;
4773 +
4774 + default:
4775 + CC_STATUS_INIT;
4776 + }
4777 +}
4778 +
4779 +
4780 +/*
4781 + Outputs to stdio stream stream the assembler syntax for an instruction
4782 + operand x. x is an RTL expression.
4783 +*/
4784 +void
4785 +avr32_print_operand (FILE * stream, rtx x, int code)
4786 +{
4787 + int error = 0;
4788 +
4789 + if ( code == '?' )
4790 + {
4791 + /* Predicable instruction, print condition code */
4792 +
4793 + /* If the insn should not be conditional then do nothing. */
4794 + if ( current_insn_predicate == NULL_RTX )
4795 + return;
4796 +
4797 + /* Set x to the predicate to force printing
4798 + the condition later on. */
4799 + x = current_insn_predicate;
4800 +
4801 + /* Reverse condition if useing bld insn. */
4802 + if ( GET_CODE (XEXP(current_insn_predicate,0)) == AND )
4803 + x = reversed_condition (current_insn_predicate);
4804 + }
4805 + else if ( code == '!' )
4806 + {
4807 + /* Output compare for conditional insn if needed. */
4808 + rtx new_cond;
4809 + gcc_assert ( current_insn_predicate != NULL_RTX );
4810 + new_cond = avr32_output_cmp(current_insn_predicate,
4811 + GET_MODE(XEXP(current_insn_predicate,0)),
4812 + XEXP(current_insn_predicate,0),
4813 + XEXP(current_insn_predicate,1));
4814 +
4815 + /* Check if the new condition is a special avr32 condition
4816 + specified using UNSPECs. If so we must handle it differently. */
4817 + if ( GET_CODE (new_cond) == UNSPEC )
4818 + {
4819 + current_insn_predicate =
4820 + gen_rtx_UNSPEC (CCmode,
4821 + gen_rtvec (2,
4822 + XEXP(current_insn_predicate,0),
4823 + XEXP(current_insn_predicate,1)),
4824 + XINT (new_cond, 1));
4825 + }
4826 + else
4827 + {
4828 + PUT_CODE(current_insn_predicate, GET_CODE(new_cond));
4829 + }
4830 + return;
4831 + }
4832 +
4833 + switch (GET_CODE (x))
4834 + {
4835 + case UNSPEC:
4836 + switch (XINT (x, 1))
4837 + {
4838 + case UNSPEC_COND_PL:
4839 + if (code == 'i')
4840 + fputs ("mi", stream);
4841 + else
4842 + fputs ("pl", stream);
4843 + break;
4844 + case UNSPEC_COND_MI:
4845 + if (code == 'i')
4846 + fputs ("pl", stream);
4847 + else
4848 + fputs ("mi", stream);
4849 + break;
4850 + default:
4851 + error = 1;
4852 + }
4853 + break;
4854 + case EQ:
4855 + if (code == 'i')
4856 + fputs ("ne", stream);
4857 + else
4858 + fputs ("eq", stream);
4859 + break;
4860 + case NE:
4861 + if (code == 'i')
4862 + fputs ("eq", stream);
4863 + else
4864 + fputs ("ne", stream);
4865 + break;
4866 + case GT:
4867 + if (code == 'i')
4868 + fputs ("le", stream);
4869 + else
4870 + fputs ("gt", stream);
4871 + break;
4872 + case GTU:
4873 + if (code == 'i')
4874 + fputs ("ls", stream);
4875 + else
4876 + fputs ("hi", stream);
4877 + break;
4878 + case LT:
4879 + if (code == 'i')
4880 + fputs ("ge", stream);
4881 + else
4882 + fputs ("lt", stream);
4883 + break;
4884 + case LTU:
4885 + if (code == 'i')
4886 + fputs ("hs", stream);
4887 + else
4888 + fputs ("lo", stream);
4889 + break;
4890 + case GE:
4891 + if (code == 'i')
4892 + fputs ("lt", stream);
4893 + else
4894 + fputs ("ge", stream);
4895 + break;
4896 + case GEU:
4897 + if (code == 'i')
4898 + fputs ("lo", stream);
4899 + else
4900 + fputs ("hs", stream);
4901 + break;
4902 + case LE:
4903 + if (code == 'i')
4904 + fputs ("gt", stream);
4905 + else
4906 + fputs ("le", stream);
4907 + break;
4908 + case LEU:
4909 + if (code == 'i')
4910 + fputs ("hi", stream);
4911 + else
4912 + fputs ("ls", stream);
4913 + break;
4914 + case CONST_INT:
4915 + {
4916 + HOST_WIDE_INT value = INTVAL (x);
4917 +
4918 + switch (code)
4919 + {
4920 + case 'm':
4921 + if ( HOST_BITS_PER_WIDE_INT > BITS_PER_WORD )
4922 + {
4923 + /* A const_int can be used to represent DImode constants. */
4924 + value >>= BITS_PER_WORD;
4925 + }
4926 + /* We might get a const_int immediate for setting a DI register,
4927 + we then must then return the correct sign extended DI. The most
4928 + significant word is just a sign extension. */
4929 + else if (value < 0)
4930 + value = -1;
4931 + else
4932 + value = 0;
4933 + break;
4934 + case 'i':
4935 + value++;
4936 + break;
4937 + case 'p':
4938 + {
4939 + /* Set to bit position of first bit set in immediate */
4940 + int i, bitpos = 32;
4941 + for (i = 0; i < 32; i++)
4942 + if (value & (1 << i))
4943 + {
4944 + bitpos = i;
4945 + break;
4946 + }
4947 + value = bitpos;
4948 + }
4949 + break;
4950 + case 'z':
4951 + {
4952 + /* Set to bit position of first bit cleared in immediate */
4953 + int i, bitpos = 32;
4954 + for (i = 0; i < 32; i++)
4955 + if (!(value & (1 << i)))
4956 + {
4957 + bitpos = i;
4958 + break;
4959 + }
4960 + value = bitpos;
4961 + }
4962 + break;
4963 + case 'r':
4964 + {
4965 + /* Reglist 8 */
4966 + char op[50];
4967 + op[0] = '\0';
4968 +
4969 + if (value & 0x01)
4970 + strcpy (op, "r0-r3");
4971 + if (value & 0x02)
4972 + strlen (op) ? strcat (op, ", r4-r7") : strcpy (op,"r4-r7");
4973 + if (value & 0x04)
4974 + strlen (op) ? strcat (op, ", r8-r9") : strcpy (op,"r8-r9");
4975 + if (value & 0x08)
4976 + strlen (op) ? strcat (op, ", r10") : strcpy (op,"r10");
4977 + if (value & 0x10)
4978 + strlen (op) ? strcat (op, ", r11") : strcpy (op,"r11");
4979 + if (value & 0x20)
4980 + strlen (op) ? strcat (op, ", r12") : strcpy (op,"r12");
4981 + if (value & 0x40)
4982 + strlen (op) ? strcat (op, ", lr") : strcpy (op, "lr");
4983 + if (value & 0x80)
4984 + strlen (op) ? strcat (op, ", pc") : strcpy (op, "pc");
4985 +
4986 + fputs (op, stream);
4987 + return;
4988 + }
4989 + case 's':
4990 + {
4991 + /* Reglist 16 */
4992 + char reglist16_string[100];
4993 + int i;
4994 + bool first_reg = true;
4995 + reglist16_string[0] = '\0';
4996 +
4997 + for (i = 0; i < 16; ++i)
4998 + {
4999 + if (value & (1 << i))
5000 + {
5001 + first_reg == true ? first_reg = false : strcat(reglist16_string,", ");
5002 + strcat(reglist16_string,reg_names[INTERNAL_REGNUM(i)]);
5003 + }
5004 + }
5005 + fputs (reglist16_string, stream);
5006 + return;
5007 + }
5008 + case 'h':
5009 + /* Print halfword part of word */
5010 + fputs (value ? "b" : "t", stream);
5011 + return;
5012 + }
5013 +
5014 + /* Print Value */
5015 + fprintf (stream, "%d", value);
5016 + break;
5017 + }
5018 + case CONST_DOUBLE:
5019 + {
5020 + HOST_WIDE_INT hi, lo;
5021 + if (SCALAR_FLOAT_MODE_P (GET_MODE (x)))
5022 + {
5023 + HOST_WIDE_INT target_float[2];
5024 + hi = lo = 0;
5025 + real_to_target (target_float, CONST_DOUBLE_REAL_VALUE (x),
5026 + GET_MODE (x));
5027 + /* For doubles the most significant part starts at index 0. */
5028 + if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
5029 + {
5030 + hi = target_float[0];
5031 + lo = target_float[1];
5032 + }
5033 + else
5034 + {
5035 + lo = target_float[0];
5036 + }
5037 + }
5038 + else
5039 + {
5040 + hi = CONST_DOUBLE_HIGH (x);
5041 + lo = CONST_DOUBLE_LOW (x);
5042 + }
5043 +
5044 + if (code == 'm')
5045 + fprintf (stream, "%ld", hi);
5046 + else
5047 + fprintf (stream, "%ld", lo);
5048 +
5049 + break;
5050 + }
5051 + case CONST:
5052 + output_addr_const (stream, XEXP (XEXP (x, 0), 0));
5053 + fprintf (stream, "+%ld", INTVAL (XEXP (XEXP (x, 0), 1)));
5054 + break;
5055 + case REG:
5056 + /* Swap register name if the register is DImode or DFmode. */
5057 + if (GET_MODE (x) == DImode || GET_MODE (x) == DFmode)
5058 + {
5059 + /* Double register must have an even numbered address */
5060 + gcc_assert (!(REGNO (x) % 2));
5061 + if (code == 'm')
5062 + fputs (reg_names[true_regnum (x)], stream);
5063 + else
5064 + fputs (reg_names[true_regnum (x) + 1], stream);
5065 + }
5066 + else if (GET_MODE (x) == TImode)
5067 + {
5068 + switch (code)
5069 + {
5070 + case 'T':
5071 + fputs (reg_names[true_regnum (x)], stream);
5072 + break;
5073 + case 'U':
5074 + fputs (reg_names[true_regnum (x) + 1], stream);
5075 + break;
5076 + case 'L':
5077 + fputs (reg_names[true_regnum (x) + 2], stream);
5078 + break;
5079 + case 'B':
5080 + fputs (reg_names[true_regnum (x) + 3], stream);
5081 + break;
5082 + default:
5083 + fprintf (stream, "%s, %s, %s, %s",
5084 + reg_names[true_regnum (x) + 3],
5085 + reg_names[true_regnum (x) + 2],
5086 + reg_names[true_regnum (x) + 1],
5087 + reg_names[true_regnum (x)]);
5088 + break;
5089 + }
5090 + }
5091 + else
5092 + {
5093 + fputs (reg_names[true_regnum (x)], stream);
5094 + }
5095 + break;
5096 + case CODE_LABEL:
5097 + case LABEL_REF:
5098 + case SYMBOL_REF:
5099 + output_addr_const (stream, x);
5100 + break;
5101 + case MEM:
5102 + switch (GET_CODE (XEXP (x, 0)))
5103 + {
5104 + case LABEL_REF:
5105 + case SYMBOL_REF:
5106 + output_addr_const (stream, XEXP (x, 0));
5107 + break;
5108 + case MEM:
5109 + switch (GET_CODE (XEXP (XEXP (x, 0), 0)))
5110 + {
5111 + case SYMBOL_REF:
5112 + output_addr_const (stream, XEXP (XEXP (x, 0), 0));
5113 + break;
5114 + default:
5115 + error = 1;
5116 + break;
5117 + }
5118 + break;
5119 + case REG:
5120 + avr32_print_operand (stream, XEXP (x, 0), 0);
5121 + if (code != 'p')
5122 + fputs ("[0]", stream);
5123 + break;
5124 + case PRE_DEC:
5125 + fputs ("--", stream);
5126 + avr32_print_operand (stream, XEXP (XEXP (x, 0), 0), 0);
5127 + break;
5128 + case POST_INC:
5129 + avr32_print_operand (stream, XEXP (XEXP (x, 0), 0), 0);
5130 + fputs ("++", stream);
5131 + break;
5132 + case PLUS:
5133 + {
5134 + rtx op0 = XEXP (XEXP (x, 0), 0);
5135 + rtx op1 = XEXP (XEXP (x, 0), 1);
5136 + rtx base = NULL_RTX, offset = NULL_RTX;
5137 +
5138 + if (avr32_address_register_rtx_p (op0, 1))
5139 + {
5140 + base = op0;
5141 + offset = op1;
5142 + }
5143 + else if (avr32_address_register_rtx_p (op1, 1))
5144 + {
5145 + /* Operands are switched. */
5146 + base = op1;
5147 + offset = op0;
5148 + }
5149 +
5150 + gcc_assert (base && offset
5151 + && avr32_address_register_rtx_p (base, 1)
5152 + && avr32_legitimate_index_p (GET_MODE (x), offset,
5153 + 1));
5154 +
5155 + avr32_print_operand (stream, base, 0);
5156 + fputs ("[", stream);
5157 + avr32_print_operand (stream, offset, 0);
5158 + fputs ("]", stream);
5159 + break;
5160 + }
5161 + case CONST:
5162 + output_addr_const (stream, XEXP (XEXP (XEXP (x, 0), 0), 0));
5163 + fprintf (stream, " + %ld",
5164 + INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)));
5165 + break;
5166 + case CONST_INT:
5167 + avr32_print_operand (stream, XEXP (x, 0), 0);
5168 + break;
5169 + default:
5170 + error = 1;
5171 + }
5172 + break;
5173 + case MULT:
5174 + {
5175 + int value = INTVAL (XEXP (x, 1));
5176 +
5177 + /* Convert immediate in multiplication into a shift immediate */
5178 + switch (value)
5179 + {
5180 + case 2:
5181 + value = 1;
5182 + break;
5183 + case 4:
5184 + value = 2;
5185 + break;
5186 + case 8:
5187 + value = 3;
5188 + break;
5189 + default:
5190 + value = 0;
5191 + }
5192 + fprintf (stream, "%s << %i", reg_names[true_regnum (XEXP (x, 0))],
5193 + value);
5194 + break;
5195 + }
5196 + case ASHIFT:
5197 + if (GET_CODE (XEXP (x, 1)) == CONST_INT)
5198 + fprintf (stream, "%s << %i", reg_names[true_regnum (XEXP (x, 0))],
5199 + (int) INTVAL (XEXP (x, 1)));
5200 + else if (REG_P (XEXP (x, 1)))
5201 + fprintf (stream, "%s << %s", reg_names[true_regnum (XEXP (x, 0))],
5202 + reg_names[true_regnum (XEXP (x, 1))]);
5203 + else
5204 + {
5205 + error = 1;
5206 + }
5207 + break;
5208 + case LSHIFTRT:
5209 + if (GET_CODE (XEXP (x, 1)) == CONST_INT)
5210 + fprintf (stream, "%s >> %i", reg_names[true_regnum (XEXP (x, 0))],
5211 + (int) INTVAL (XEXP (x, 1)));
5212 + else if (REG_P (XEXP (x, 1)))
5213 + fprintf (stream, "%s >> %s", reg_names[true_regnum (XEXP (x, 0))],
5214 + reg_names[true_regnum (XEXP (x, 1))]);
5215 + else
5216 + {
5217 + error = 1;
5218 + }
5219 + fprintf (stream, ">>");
5220 + break;
5221 + case PARALLEL:
5222 + {
5223 + /* Load store multiple */
5224 + int i;
5225 + int count = XVECLEN (x, 0);
5226 + int reglist16 = 0;
5227 + char reglist16_string[100];
5228 +
5229 + for (i = 0; i < count; ++i)
5230 + {
5231 + rtx vec_elm = XVECEXP (x, 0, i);
5232 + if (GET_MODE (vec_elm) != SET)
5233 + {
5234 + debug_rtx (vec_elm);
5235 + internal_error ("Unknown element in parallel expression!");
5236 + }
5237 + if (GET_MODE (XEXP (vec_elm, 0)) == REG)
5238 + {
5239 + /* Load multiple */
5240 + reglist16 |= 1 << ASM_REGNUM (REGNO (XEXP (vec_elm, 0)));
5241 + }
5242 + else
5243 + {
5244 + /* Store multiple */
5245 + reglist16 |= 1 << ASM_REGNUM (REGNO (XEXP (vec_elm, 1)));
5246 + }
5247 + }
5248 +
5249 + avr32_make_reglist16 (reglist16, reglist16_string);
5250 + fputs (reglist16_string, stream);
5251 +
5252 + break;
5253 + }
5254 +
5255 + case PLUS:
5256 + {
5257 + rtx op0 = XEXP (x, 0);
5258 + rtx op1 = XEXP (x, 1);
5259 + rtx base = NULL_RTX, offset = NULL_RTX;
5260 +
5261 + if (avr32_address_register_rtx_p (op0, 1))
5262 + {
5263 + base = op0;
5264 + offset = op1;
5265 + }
5266 + else if (avr32_address_register_rtx_p (op1, 1))
5267 + {
5268 + /* Operands are switched. */
5269 + base = op1;
5270 + offset = op0;
5271 + }
5272 +
5273 + gcc_assert (base && offset
5274 + && avr32_address_register_rtx_p (base, 1)
5275 + && avr32_legitimate_index_p (GET_MODE (x), offset, 1));
5276 +
5277 + avr32_print_operand (stream, base, 0);
5278 + fputs ("[", stream);
5279 + avr32_print_operand (stream, offset, 0);
5280 + fputs ("]", stream);
5281 + break;
5282 + }
5283 +
5284 + default:
5285 + error = 1;
5286 + }
5287 +
5288 + if (error)
5289 + {
5290 + debug_rtx (x);
5291 + internal_error ("Illegal expression for avr32_print_operand");
5292 + }
5293 +}
5294 +
5295 +rtx
5296 +avr32_get_note_reg_equiv (rtx insn)
5297 +{
5298 + rtx note;
5299 +
5300 + note = find_reg_note (insn, REG_EQUIV, NULL_RTX);
5301 +
5302 + if (note != NULL_RTX)
5303 + return XEXP (note, 0);
5304 + else
5305 + return NULL_RTX;
5306 +}
5307 +
5308 +
5309 +/*
5310 + Outputs to stdio stream stream the assembler syntax for an instruction
5311 + operand that is a memory reference whose address is x. x is an RTL
5312 + expression.
5313 +
5314 + ToDo: fixme.
5315 +*/
5316 +void
5317 +avr32_print_operand_address (FILE * stream, rtx x)
5318 +{
5319 + fprintf (stream, "(%d) /* address */", REGNO (x));
5320 +}
5321 +
5322 +
5323 +/* Return true if _GLOBAL_OFFSET_TABLE_ symbol is mentioned. */
5324 +bool
5325 +avr32_got_mentioned_p (rtx addr)
5326 +{
5327 + if (GET_CODE (addr) == MEM)
5328 + addr = XEXP (addr, 0);
5329 + while (GET_CODE (addr) == CONST)
5330 + addr = XEXP (addr, 0);
5331 + if (GET_CODE (addr) == SYMBOL_REF)
5332 + {
5333 + return streq (XSTR (addr, 0), "_GLOBAL_OFFSET_TABLE_");
5334 + }
5335 + if (GET_CODE (addr) == PLUS || GET_CODE (addr) == MINUS)
5336 + {
5337 + bool l1, l2;
5338 +
5339 + l1 = avr32_got_mentioned_p (XEXP (addr, 0));
5340 + l2 = avr32_got_mentioned_p (XEXP (addr, 1));
5341 + return l1 || l2;
5342 + }
5343 + return false;
5344 +}
5345 +
5346 +
5347 +/* Find the symbol in an address expression. */
5348 +rtx
5349 +avr32_find_symbol (rtx addr)
5350 +{
5351 + if (GET_CODE (addr) == MEM)
5352 + addr = XEXP (addr, 0);
5353 +
5354 + while (GET_CODE (addr) == CONST)
5355 + addr = XEXP (addr, 0);
5356 +
5357 + if (GET_CODE (addr) == SYMBOL_REF || GET_CODE (addr) == LABEL_REF)
5358 + return addr;
5359 + if (GET_CODE (addr) == PLUS)
5360 + {
5361 + rtx l1, l2;
5362 +
5363 + l1 = avr32_find_symbol (XEXP (addr, 0));
5364 + l2 = avr32_find_symbol (XEXP (addr, 1));
5365 + if (l1 != NULL_RTX && l2 == NULL_RTX)
5366 + return l1;
5367 + else if (l1 == NULL_RTX && l2 != NULL_RTX)
5368 + return l2;
5369 + }
5370 +
5371 + return NULL_RTX;
5372 +}
5373 +
5374 +
5375 +/* Routines for manipulation of the constant pool. */
5376 +
5377 +/* AVR32 instructions cannot load a large constant directly into a
5378 + register; they have to come from a pc relative load. The constant
5379 + must therefore be placed in the addressable range of the pc
5380 + relative load. Depending on the precise pc relative load
5381 + instruction the range is somewhere between 256 bytes and 4k. This
5382 + means that we often have to dump a constant inside a function, and
5383 + generate code to branch around it.
5384 +
5385 + It is important to minimize this, since the branches will slow
5386 + things down and make the code larger.
5387 +
5388 + Normally we can hide the table after an existing unconditional
5389 + branch so that there is no interruption of the flow, but in the
5390 + worst case the code looks like this:
5391 +
5392 + lddpc rn, L1
5393 + ...
5394 + rjmp L2
5395 + align
5396 + L1: .long value
5397 + L2:
5398 + ...
5399 +
5400 + lddpc rn, L3
5401 + ...
5402 + rjmp L4
5403 + align
5404 + L3: .long value
5405 + L4:
5406 + ...
5407 +
5408 + We fix this by performing a scan after scheduling, which notices
5409 + which instructions need to have their operands fetched from the
5410 + constant table and builds the table.
5411 +
5412 + The algorithm starts by building a table of all the constants that
5413 + need fixing up and all the natural barriers in the function (places
5414 + where a constant table can be dropped without breaking the flow).
5415 + For each fixup we note how far the pc-relative replacement will be
5416 + able to reach and the offset of the instruction into the function.
5417 +
5418 + Having built the table we then group the fixes together to form
5419 + tables that are as large as possible (subject to addressing
5420 + constraints) and emit each table of constants after the last
5421 + barrier that is within range of all the instructions in the group.
5422 + If a group does not contain a barrier, then we forcibly create one
5423 + by inserting a jump instruction into the flow. Once the table has
5424 + been inserted, the insns are then modified to reference the
5425 + relevant entry in the pool.
5426 +
5427 + Possible enhancements to the algorithm (not implemented) are:
5428 +
5429 + 1) For some processors and object formats, there may be benefit in
5430 + aligning the pools to the start of cache lines; this alignment
5431 + would need to be taken into account when calculating addressability
5432 + of a pool. */
5433 +
5434 +/* These typedefs are located at the start of this file, so that
5435 + they can be used in the prototypes there. This comment is to
5436 + remind readers of that fact so that the following structures
5437 + can be understood more easily.
5438 +
5439 + typedef struct minipool_node Mnode;
5440 + typedef struct minipool_fixup Mfix; */
5441 +
5442 +struct minipool_node
5443 +{
5444 + /* Doubly linked chain of entries. */
5445 + Mnode *next;
5446 + Mnode *prev;
5447 + /* The maximum offset into the code that this entry can be placed. While
5448 + pushing fixes for forward references, all entries are sorted in order of
5449 + increasing max_address. */
5450 + HOST_WIDE_INT max_address;
5451 + /* Similarly for an entry inserted for a backwards ref. */
5452 + HOST_WIDE_INT min_address;
5453 + /* The number of fixes referencing this entry. This can become zero if we
5454 + "unpush" an entry. In this case we ignore the entry when we come to
5455 + emit the code. */
5456 + int refcount;
5457 + /* The offset from the start of the minipool. */
5458 + HOST_WIDE_INT offset;
5459 + /* The value in table. */
5460 + rtx value;
5461 + /* The mode of value. */
5462 + enum machine_mode mode;
5463 + /* The size of the value. */
5464 + int fix_size;
5465 +};
5466 +
5467 +
5468 +struct minipool_fixup
5469 +{
5470 + Mfix *next;
5471 + rtx insn;
5472 + HOST_WIDE_INT address;
5473 + rtx *loc;
5474 + enum machine_mode mode;
5475 + int fix_size;
5476 + rtx value;
5477 + Mnode *minipool;
5478 + HOST_WIDE_INT forwards;
5479 + HOST_WIDE_INT backwards;
5480 +};
5481 +
5482 +
5483 +/* Fixes less than a word need padding out to a word boundary. */
5484 +#define MINIPOOL_FIX_SIZE(mode, value) \
5485 + (IS_FORCE_MINIPOOL(value) ? 0 : \
5486 + (GET_MODE_SIZE ((mode)) >= 4 ? GET_MODE_SIZE ((mode)) : 4))
5487 +
5488 +#define IS_FORCE_MINIPOOL(x) \
5489 + (GET_CODE(x) == UNSPEC && \
5490 + XINT(x, 1) == UNSPEC_FORCE_MINIPOOL)
5491 +
5492 +static Mnode *minipool_vector_head;
5493 +static Mnode *minipool_vector_tail;
5494 +
5495 +/* The linked list of all minipool fixes required for this function. */
5496 +Mfix *minipool_fix_head;
5497 +Mfix *minipool_fix_tail;
5498 +/* The fix entry for the current minipool, once it has been placed. */
5499 +Mfix *minipool_barrier;
5500 +
5501 +
5502 +/* Determines if INSN is the start of a jump table. Returns the end
5503 + of the TABLE or NULL_RTX. */
5504 +static rtx
5505 +is_jump_table (rtx insn)
5506 +{
5507 + rtx table;
5508 +
5509 + if (GET_CODE (insn) == JUMP_INSN
5510 + && JUMP_LABEL (insn) != NULL
5511 + && ((table = next_real_insn (JUMP_LABEL (insn)))
5512 + == next_real_insn (insn))
5513 + && table != NULL
5514 + && GET_CODE (table) == JUMP_INSN
5515 + && (GET_CODE (PATTERN (table)) == ADDR_VEC
5516 + || GET_CODE (PATTERN (table)) == ADDR_DIFF_VEC))
5517 + return table;
5518 +
5519 + return NULL_RTX;
5520 +}
5521 +
5522 +
5523 +static HOST_WIDE_INT
5524 +get_jump_table_size (rtx insn)
5525 +{
5526 + /* ADDR_VECs only take room if read-only data does into the text section. */
5527 + if (JUMP_TABLES_IN_TEXT_SECTION
5528 +#if !defined(READONLY_DATA_SECTION_ASM_OP)
5529 + || 1
5530 +#endif
5531 + )
5532 + {
5533 + rtx body = PATTERN (insn);
5534 + int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0;
5535 +
5536 + return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, elt);
5537 + }
5538 +
5539 + return 0;
5540 +}
5541 +
5542 +
5543 +/* Move a minipool fix MP from its current location to before MAX_MP.
5544 + If MAX_MP is NULL, then MP doesn't need moving, but the addressing
5545 + constraints may need updating. */
5546 +static Mnode *
5547 +move_minipool_fix_forward_ref (Mnode * mp, Mnode * max_mp,
5548 + HOST_WIDE_INT max_address)
5549 +{
5550 + /* This should never be true and the code below assumes these are
5551 + different. */
5552 + if (mp == max_mp)
5553 + abort ();
5554 +
5555 + if (max_mp == NULL)
5556 + {
5557 + if (max_address < mp->max_address)
5558 + mp->max_address = max_address;
5559 + }
5560 + else
5561 + {
5562 + if (max_address > max_mp->max_address - mp->fix_size)
5563 + mp->max_address = max_mp->max_address - mp->fix_size;
5564 + else
5565 + mp->max_address = max_address;
5566 +
5567 + /* Unlink MP from its current position. Since max_mp is non-null,
5568 + mp->prev must be non-null. */
5569 + mp->prev->next = mp->next;
5570 + if (mp->next != NULL)
5571 + mp->next->prev = mp->prev;
5572 + else
5573 + minipool_vector_tail = mp->prev;
5574 +
5575 + /* Re-insert it before MAX_MP. */
5576 + mp->next = max_mp;
5577 + mp->prev = max_mp->prev;
5578 + max_mp->prev = mp;
5579 +
5580 + if (mp->prev != NULL)
5581 + mp->prev->next = mp;
5582 + else
5583 + minipool_vector_head = mp;
5584 + }
5585 +
5586 + /* Save the new entry. */
5587 + max_mp = mp;
5588 +
5589 + /* Scan over the preceding entries and adjust their addresses as required.
5590 + */
5591 + while (mp->prev != NULL
5592 + && mp->prev->max_address > mp->max_address - mp->prev->fix_size)
5593 + {
5594 + mp->prev->max_address = mp->max_address - mp->prev->fix_size;
5595 + mp = mp->prev;
5596 + }
5597 +
5598 + return max_mp;
5599 +}
5600 +
5601 +
5602 +/* Add a constant to the minipool for a forward reference. Returns the
5603 + node added or NULL if the constant will not fit in this pool. */
5604 +static Mnode *
5605 +add_minipool_forward_ref (Mfix * fix)
5606 +{
5607 + /* If set, max_mp is the first pool_entry that has a lower constraint than
5608 + the one we are trying to add. */
5609 + Mnode *max_mp = NULL;
5610 + HOST_WIDE_INT max_address = fix->address + fix->forwards;
5611 + Mnode *mp;
5612 +
5613 + /* If this fix's address is greater than the address of the first entry,
5614 + then we can't put the fix in this pool. We subtract the size of the
5615 + current fix to ensure that if the table is fully packed we still have
5616 + enough room to insert this value by suffling the other fixes forwards. */
5617 + if (minipool_vector_head &&
5618 + fix->address >= minipool_vector_head->max_address - fix->fix_size)
5619 + return NULL;
5620 +
5621 + /* Scan the pool to see if a constant with the same value has already been
5622 + added. While we are doing this, also note the location where we must
5623 + insert the constant if it doesn't already exist. */
5624 + for (mp = minipool_vector_head; mp != NULL; mp = mp->next)
5625 + {
5626 + if (GET_CODE (fix->value) == GET_CODE (mp->value)
5627 + && fix->mode == mp->mode
5628 + && (GET_CODE (fix->value) != CODE_LABEL
5629 + || (CODE_LABEL_NUMBER (fix->value)
5630 + == CODE_LABEL_NUMBER (mp->value)))
5631 + && rtx_equal_p (fix->value, mp->value))
5632 + {
5633 + /* More than one fix references this entry. */
5634 + mp->refcount++;
5635 + return move_minipool_fix_forward_ref (mp, max_mp, max_address);
5636 + }
5637 +
5638 + /* Note the insertion point if necessary. */
5639 + if (max_mp == NULL && mp->max_address > max_address)
5640 + max_mp = mp;
5641 +
5642 + }
5643 +
5644 + /* The value is not currently in the minipool, so we need to create a new
5645 + entry for it. If MAX_MP is NULL, the entry will be put on the end of
5646 + the list since the placement is less constrained than any existing
5647 + entry. Otherwise, we insert the new fix before MAX_MP and, if
5648 + necessary, adjust the constraints on the other entries. */
5649 + mp = xmalloc (sizeof (*mp));
5650 + mp->fix_size = fix->fix_size;
5651 + mp->mode = fix->mode;
5652 + mp->value = fix->value;
5653 + mp->refcount = 1;
5654 + /* Not yet required for a backwards ref. */
5655 + mp->min_address = -65536;
5656 +
5657 + if (max_mp == NULL)
5658 + {
5659 + mp->max_address = max_address;
5660 + mp->next = NULL;
5661 + mp->prev = minipool_vector_tail;
5662 +
5663 + if (mp->prev == NULL)
5664 + {
5665 + minipool_vector_head = mp;
5666 + minipool_vector_label = gen_label_rtx ();
5667 + }
5668 + else
5669 + mp->prev->next = mp;
5670 +
5671 + minipool_vector_tail = mp;
5672 + }
5673 + else
5674 + {
5675 + if (max_address > max_mp->max_address - mp->fix_size)
5676 + mp->max_address = max_mp->max_address - mp->fix_size;
5677 + else
5678 + mp->max_address = max_address;
5679 +
5680 + mp->next = max_mp;
5681 + mp->prev = max_mp->prev;
5682 + max_mp->prev = mp;
5683 + if (mp->prev != NULL)
5684 + mp->prev->next = mp;
5685 + else
5686 + minipool_vector_head = mp;
5687 + }
5688 +
5689 + /* Save the new entry. */
5690 + max_mp = mp;
5691 +
5692 + /* Scan over the preceding entries and adjust their addresses as required.
5693 + */
5694 + while (mp->prev != NULL
5695 + && mp->prev->max_address > mp->max_address - mp->prev->fix_size)
5696 + {
5697 + mp->prev->max_address = mp->max_address - mp->prev->fix_size;
5698 + mp = mp->prev;
5699 + }
5700 +
5701 + return max_mp;
5702 +}
5703 +
5704 +
5705 +static Mnode *
5706 +move_minipool_fix_backward_ref (Mnode * mp, Mnode * min_mp,
5707 + HOST_WIDE_INT min_address)
5708 +{
5709 + HOST_WIDE_INT offset;
5710 +
5711 + /* This should never be true, and the code below assumes these are
5712 + different. */
5713 + if (mp == min_mp)
5714 + abort ();
5715 +
5716 + if (min_mp == NULL)
5717 + {
5718 + if (min_address > mp->min_address)
5719 + mp->min_address = min_address;
5720 + }
5721 + else
5722 + {
5723 + /* We will adjust this below if it is too loose. */
5724 + mp->min_address = min_address;
5725 +
5726 + /* Unlink MP from its current position. Since min_mp is non-null,
5727 + mp->next must be non-null. */
5728 + mp->next->prev = mp->prev;
5729 + if (mp->prev != NULL)
5730 + mp->prev->next = mp->next;
5731 + else
5732 + minipool_vector_head = mp->next;
5733 +
5734 + /* Reinsert it after MIN_MP. */
5735 + mp->prev = min_mp;
5736 + mp->next = min_mp->next;
5737 + min_mp->next = mp;
5738 + if (mp->next != NULL)
5739 + mp->next->prev = mp;
5740 + else
5741 + minipool_vector_tail = mp;
5742 + }
5743 +
5744 + min_mp = mp;
5745 +
5746 + offset = 0;
5747 + for (mp = minipool_vector_head; mp != NULL; mp = mp->next)
5748 + {
5749 + mp->offset = offset;
5750 + if (mp->refcount > 0)
5751 + offset += mp->fix_size;
5752 +
5753 + if (mp->next && mp->next->min_address < mp->min_address + mp->fix_size)
5754 + mp->next->min_address = mp->min_address + mp->fix_size;
5755 + }
5756 +
5757 + return min_mp;
5758 +}
5759 +
5760 +
5761 +/* Add a constant to the minipool for a backward reference. Returns the
5762 + node added or NULL if the constant will not fit in this pool.
5763 +
5764 + Note that the code for insertion for a backwards reference can be
5765 + somewhat confusing because the calculated offsets for each fix do
5766 + not take into account the size of the pool (which is still under
5767 + construction. */
5768 +static Mnode *
5769 +add_minipool_backward_ref (Mfix * fix)
5770 +{
5771 + /* If set, min_mp is the last pool_entry that has a lower constraint than
5772 + the one we are trying to add. */
5773 + Mnode *min_mp = NULL;
5774 + /* This can be negative, since it is only a constraint. */
5775 + HOST_WIDE_INT min_address = fix->address - fix->backwards;
5776 + Mnode *mp;
5777 +
5778 + /* If we can't reach the current pool from this insn, or if we can't insert
5779 + this entry at the end of the pool without pushing other fixes out of
5780 + range, then we don't try. This ensures that we can't fail later on. */
5781 + if (min_address >= minipool_barrier->address
5782 + || (minipool_vector_tail->min_address + fix->fix_size
5783 + >= minipool_barrier->address))
5784 + return NULL;
5785 +
5786 + /* Scan the pool to see if a constant with the same value has already been
5787 + added. While we are doing this, also note the location where we must
5788 + insert the constant if it doesn't already exist. */
5789 + for (mp = minipool_vector_tail; mp != NULL; mp = mp->prev)
5790 + {
5791 + if (GET_CODE (fix->value) == GET_CODE (mp->value)
5792 + && fix->mode == mp->mode
5793 + && (GET_CODE (fix->value) != CODE_LABEL
5794 + || (CODE_LABEL_NUMBER (fix->value)
5795 + == CODE_LABEL_NUMBER (mp->value)))
5796 + && rtx_equal_p (fix->value, mp->value)
5797 + /* Check that there is enough slack to move this entry to the end
5798 + of the table (this is conservative). */
5799 + && (mp->max_address
5800 + > (minipool_barrier->address
5801 + + minipool_vector_tail->offset
5802 + + minipool_vector_tail->fix_size)))
5803 + {
5804 + mp->refcount++;
5805 + return move_minipool_fix_backward_ref (mp, min_mp, min_address);
5806 + }
5807 +
5808 + if (min_mp != NULL)
5809 + mp->min_address += fix->fix_size;
5810 + else
5811 + {
5812 + /* Note the insertion point if necessary. */
5813 + if (mp->min_address < min_address)
5814 + {
5815 + min_mp = mp;
5816 + }
5817 + else if (mp->max_address
5818 + < minipool_barrier->address + mp->offset + fix->fix_size)
5819 + {
5820 + /* Inserting before this entry would push the fix beyond its
5821 + maximum address (which can happen if we have re-located a
5822 + forwards fix); force the new fix to come after it. */
5823 + min_mp = mp;
5824 + min_address = mp->min_address + fix->fix_size;
5825 + }
5826 + }
5827 + }
5828 +
5829 + /* We need to create a new entry. */
5830 + mp = xmalloc (sizeof (*mp));
5831 + mp->fix_size = fix->fix_size;
5832 + mp->mode = fix->mode;
5833 + mp->value = fix->value;
5834 + mp->refcount = 1;
5835 + mp->max_address = minipool_barrier->address + 65536;
5836 +
5837 + mp->min_address = min_address;
5838 +
5839 + if (min_mp == NULL)
5840 + {
5841 + mp->prev = NULL;
5842 + mp->next = minipool_vector_head;
5843 +
5844 + if (mp->next == NULL)
5845 + {
5846 + minipool_vector_tail = mp;
5847 + minipool_vector_label = gen_label_rtx ();
5848 + }
5849 + else
5850 + mp->next->prev = mp;
5851 +
5852 + minipool_vector_head = mp;
5853 + }
5854 + else
5855 + {
5856 + mp->next = min_mp->next;
5857 + mp->prev = min_mp;
5858 + min_mp->next = mp;
5859 +
5860 + if (mp->next != NULL)
5861 + mp->next->prev = mp;
5862 + else
5863 + minipool_vector_tail = mp;
5864 + }
5865 +
5866 + /* Save the new entry. */
5867 + min_mp = mp;
5868 +
5869 + if (mp->prev)
5870 + mp = mp->prev;
5871 + else
5872 + mp->offset = 0;
5873 +
5874 + /* Scan over the following entries and adjust their offsets. */
5875 + while (mp->next != NULL)
5876 + {
5877 + if (mp->next->min_address < mp->min_address + mp->fix_size)
5878 + mp->next->min_address = mp->min_address + mp->fix_size;
5879 +
5880 + if (mp->refcount)
5881 + mp->next->offset = mp->offset + mp->fix_size;
5882 + else
5883 + mp->next->offset = mp->offset;
5884 +
5885 + mp = mp->next;
5886 + }
5887 +
5888 + return min_mp;
5889 +}
5890 +
5891 +
5892 +static void
5893 +assign_minipool_offsets (Mfix * barrier)
5894 +{
5895 + HOST_WIDE_INT offset = 0;
5896 + Mnode *mp;
5897 +
5898 + minipool_barrier = barrier;
5899 +
5900 + for (mp = minipool_vector_head; mp != NULL; mp = mp->next)
5901 + {
5902 + mp->offset = offset;
5903 +
5904 + if (mp->refcount > 0)
5905 + offset += mp->fix_size;
5906 + }
5907 +}
5908 +
5909 +
5910 +/* Print a symbolic form of X to the debug file, F. */
5911 +static void
5912 +avr32_print_value (FILE * f, rtx x)
5913 +{
5914 + switch (GET_CODE (x))
5915 + {
5916 + case CONST_INT:
5917 + fprintf (f, "0x%x", (int) INTVAL (x));
5918 + return;
5919 +
5920 + case CONST_DOUBLE:
5921 + fprintf (f, "<0x%lx,0x%lx>", (long) XWINT (x, 2), (long) XWINT (x, 3));
5922 + return;
5923 +
5924 + case CONST_VECTOR:
5925 + {
5926 + int i;
5927 +
5928 + fprintf (f, "<");
5929 + for (i = 0; i < CONST_VECTOR_NUNITS (x); i++)
5930 + {
5931 + fprintf (f, "0x%x", (int) INTVAL (CONST_VECTOR_ELT (x, i)));
5932 + if (i < (CONST_VECTOR_NUNITS (x) - 1))
5933 + fputc (',', f);
5934 + }
5935 + fprintf (f, ">");
5936 + }
5937 + return;
5938 +
5939 + case CONST_STRING:
5940 + fprintf (f, "\"%s\"", XSTR (x, 0));
5941 + return;
5942 +
5943 + case SYMBOL_REF:
5944 + fprintf (f, "`%s'", XSTR (x, 0));
5945 + return;
5946 +
5947 + case LABEL_REF:
5948 + fprintf (f, "L%d", INSN_UID (XEXP (x, 0)));
5949 + return;
5950 +
5951 + case CONST:
5952 + avr32_print_value (f, XEXP (x, 0));
5953 + return;
5954 +
5955 + case PLUS:
5956 + avr32_print_value (f, XEXP (x, 0));
5957 + fprintf (f, "+");
5958 + avr32_print_value (f, XEXP (x, 1));
5959 + return;
5960 +
5961 + case PC:
5962 + fprintf (f, "pc");
5963 + return;
5964 +
5965 + default:
5966 + fprintf (f, "????");
5967 + return;
5968 + }
5969 +}
5970 +
5971 +
5972 +int
5973 +is_minipool_label (rtx label)
5974 +{
5975 + minipool_labels *cur_mp_label = cfun->machine->minipool_label_head;
5976 +
5977 + if (GET_CODE (label) != CODE_LABEL)
5978 + return FALSE;
5979 +
5980 + while (cur_mp_label)
5981 + {
5982 + if (CODE_LABEL_NUMBER (label)
5983 + == CODE_LABEL_NUMBER (cur_mp_label->label))
5984 + return TRUE;
5985 + cur_mp_label = cur_mp_label->next;
5986 + }
5987 + return FALSE;
5988 +}
5989 +
5990 +
5991 +static void
5992 +new_minipool_label (rtx label)
5993 +{
5994 + if (!cfun->machine->minipool_label_head)
5995 + {
5996 + cfun->machine->minipool_label_head =
5997 + ggc_alloc (sizeof (minipool_labels));
5998 + cfun->machine->minipool_label_tail = cfun->machine->minipool_label_head;
5999 + cfun->machine->minipool_label_head->label = label;
6000 + cfun->machine->minipool_label_head->next = 0;
6001 + cfun->machine->minipool_label_head->prev = 0;
6002 + }
6003 + else
6004 + {
6005 + cfun->machine->minipool_label_tail->next =
6006 + ggc_alloc (sizeof (minipool_labels));
6007 + cfun->machine->minipool_label_tail->next->label = label;
6008 + cfun->machine->minipool_label_tail->next->next = 0;
6009 + cfun->machine->minipool_label_tail->next->prev =
6010 + cfun->machine->minipool_label_tail;
6011 + cfun->machine->minipool_label_tail =
6012 + cfun->machine->minipool_label_tail->next;
6013 + }
6014 +}
6015 +
6016 +
6017 +/* Output the literal table */
6018 +static void
6019 +dump_minipool (rtx scan)
6020 +{
6021 + Mnode *mp;
6022 + Mnode *nmp;
6023 +
6024 + if (dump_file)
6025 + fprintf (dump_file,
6026 + ";; Emitting minipool after insn %u; address %ld; align %d (bytes)\n",
6027 + INSN_UID (scan), (unsigned long) minipool_barrier->address, 4);
6028 +
6029 + scan = emit_insn_after (gen_consttable_start (), scan);
6030 + scan = emit_insn_after (gen_align_4 (), scan);
6031 + scan = emit_label_after (minipool_vector_label, scan);
6032 + new_minipool_label (minipool_vector_label);
6033 +
6034 + for (mp = minipool_vector_head; mp != NULL; mp = nmp)
6035 + {
6036 + if (mp->refcount > 0)
6037 + {
6038 + if (dump_file)
6039 + {
6040 + fprintf (dump_file,
6041 + ";; Offset %u, min %ld, max %ld ",
6042 + (unsigned) mp->offset, (unsigned long) mp->min_address,
6043 + (unsigned long) mp->max_address);
6044 + avr32_print_value (dump_file, mp->value);
6045 + fputc ('\n', dump_file);
6046 + }
6047 +
6048 + switch (mp->fix_size)
6049 + {
6050 +#ifdef HAVE_consttable_4
6051 + case 4:
6052 + scan = emit_insn_after (gen_consttable_4 (mp->value), scan);
6053 + break;
6054 +
6055 +#endif
6056 +#ifdef HAVE_consttable_8
6057 + case 8:
6058 + scan = emit_insn_after (gen_consttable_8 (mp->value), scan);
6059 + break;
6060 +
6061 +#endif
6062 +#ifdef HAVE_consttable_16
6063 + case 16:
6064 + scan = emit_insn_after (gen_consttable_16 (mp->value), scan);
6065 + break;
6066 +
6067 +#endif
6068 + case 0:
6069 + /* This can happen for force-minipool entries which just are
6070 + there to force the minipool to be generate. */
6071 + break;
6072 + default:
6073 + abort ();
6074 + break;
6075 + }
6076 + }
6077 +
6078 + nmp = mp->next;
6079 + free (mp);
6080 + }
6081 +
6082 + minipool_vector_head = minipool_vector_tail = NULL;
6083 + scan = emit_insn_after (gen_consttable_end (), scan);
6084 + scan = emit_barrier_after (scan);
6085 +}
6086 +
6087 +
6088 +/* Return the cost of forcibly inserting a barrier after INSN. */
6089 +static int
6090 +avr32_barrier_cost (rtx insn)
6091 +{
6092 + /* Basing the location of the pool on the loop depth is preferable, but at
6093 + the moment, the basic block information seems to be corrupt by this
6094 + stage of the compilation. */
6095 + int base_cost = 50;
6096 + rtx next = next_nonnote_insn (insn);
6097 +
6098 + if (next != NULL && GET_CODE (next) == CODE_LABEL)
6099 + base_cost -= 20;
6100 +
6101 + switch (GET_CODE (insn))
6102 + {
6103 + case CODE_LABEL:
6104 + /* It will always be better to place the table before the label, rather
6105 + than after it. */
6106 + return 50;
6107 +
6108 + case INSN:
6109 + case CALL_INSN:
6110 + return base_cost;
6111 +
6112 + case JUMP_INSN:
6113 + return base_cost - 10;
6114 +
6115 + default:
6116 + return base_cost + 10;
6117 + }
6118 +}
6119 +
6120 +
6121 +/* Find the best place in the insn stream in the range
6122 + (FIX->address,MAX_ADDRESS) to forcibly insert a minipool barrier.
6123 + Create the barrier by inserting a jump and add a new fix entry for
6124 + it. */
6125 +static Mfix *
6126 +create_fix_barrier (Mfix * fix, HOST_WIDE_INT max_address)
6127 +{
6128 + HOST_WIDE_INT count = 0;
6129 + rtx barrier;
6130 + rtx from = fix->insn;
6131 + rtx selected = from;
6132 + int selected_cost;
6133 + HOST_WIDE_INT selected_address;
6134 + Mfix *new_fix;
6135 + HOST_WIDE_INT max_count = max_address - fix->address;
6136 + rtx label = gen_label_rtx ();
6137 +
6138 + selected_cost = avr32_barrier_cost (from);
6139 + selected_address = fix->address;
6140 +
6141 + while (from && count < max_count)
6142 + {
6143 + rtx tmp;
6144 + int new_cost;
6145 +
6146 + /* This code shouldn't have been called if there was a natural barrier
6147 + within range. */
6148 + if (GET_CODE (from) == BARRIER)
6149 + abort ();
6150 +
6151 + /* Count the length of this insn. */
6152 + count += get_attr_length (from);
6153 +
6154 + /* If there is a jump table, add its length. */
6155 + tmp = is_jump_table (from);
6156 + if (tmp != NULL)
6157 + {
6158 + count += get_jump_table_size (tmp);
6159 +
6160 + /* Jump tables aren't in a basic block, so base the cost on the
6161 + dispatch insn. If we select this location, we will still put
6162 + the pool after the table. */
6163 + new_cost = avr32_barrier_cost (from);
6164 +
6165 + if (count < max_count && new_cost <= selected_cost)
6166 + {
6167 + selected = tmp;
6168 + selected_cost = new_cost;
6169 + selected_address = fix->address + count;
6170 + }
6171 +
6172 + /* Continue after the dispatch table. */
6173 + from = NEXT_INSN (tmp);
6174 + continue;
6175 + }
6176 +
6177 + new_cost = avr32_barrier_cost (from);
6178 +
6179 + if (count < max_count && new_cost <= selected_cost)
6180 + {
6181 + selected = from;
6182 + selected_cost = new_cost;
6183 + selected_address = fix->address + count;
6184 + }
6185 +
6186 + from = NEXT_INSN (from);
6187 + }
6188 +
6189 + /* Create a new JUMP_INSN that branches around a barrier. */
6190 + from = emit_jump_insn_after (gen_jump (label), selected);
6191 + JUMP_LABEL (from) = label;
6192 + barrier = emit_barrier_after (from);
6193 + emit_label_after (label, barrier);
6194 +
6195 + /* Create a minipool barrier entry for the new barrier. */
6196 + new_fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (*new_fix));
6197 + new_fix->insn = barrier;
6198 + new_fix->address = selected_address;
6199 + new_fix->next = fix->next;
6200 + fix->next = new_fix;
6201 +
6202 + return new_fix;
6203 +}
6204 +
6205 +
6206 +/* Record that there is a natural barrier in the insn stream at
6207 + ADDRESS. */
6208 +static void
6209 +push_minipool_barrier (rtx insn, HOST_WIDE_INT address)
6210 +{
6211 + Mfix *fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (*fix));
6212 +
6213 + fix->insn = insn;
6214 + fix->address = address;
6215 +
6216 + fix->next = NULL;
6217 + if (minipool_fix_head != NULL)
6218 + minipool_fix_tail->next = fix;
6219 + else
6220 + minipool_fix_head = fix;
6221 +
6222 + minipool_fix_tail = fix;
6223 +}
6224 +
6225 +
6226 +/* Record INSN, which will need fixing up to load a value from the
6227 + minipool. ADDRESS is the offset of the insn since the start of the
6228 + function; LOC is a pointer to the part of the insn which requires
6229 + fixing; VALUE is the constant that must be loaded, which is of type
6230 + MODE. */
6231 +static void
6232 +push_minipool_fix (rtx insn, HOST_WIDE_INT address, rtx * loc,
6233 + enum machine_mode mode, rtx value)
6234 +{
6235 + Mfix *fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (*fix));
6236 + rtx body = PATTERN (insn);
6237 +
6238 + fix->insn = insn;
6239 + fix->address = address;
6240 + fix->loc = loc;
6241 + fix->mode = mode;
6242 + fix->fix_size = MINIPOOL_FIX_SIZE (mode, value);
6243 + fix->value = value;
6244 +
6245 + if (GET_CODE (body) == PARALLEL)
6246 + {
6247 + /* Mcall : Ks16 << 2 */
6248 + fix->forwards = ((1 << 15) - 1) << 2;
6249 + fix->backwards = (1 << 15) << 2;
6250 + }
6251 + else if (GET_CODE (body) == SET
6252 + && GET_MODE_SIZE (GET_MODE (SET_DEST (body))) == 4)
6253 + {
6254 + if (optimize_size)
6255 + {
6256 + /* Lddpc : Ku7 << 2 */
6257 + fix->forwards = ((1 << 7) - 1) << 2;
6258 + fix->backwards = 0;
6259 + }
6260 + else
6261 + {
6262 + /* Ld.w : Ks16 */
6263 + fix->forwards = ((1 << 15) - 4);
6264 + fix->backwards = (1 << 15);
6265 + }
6266 + }
6267 + else if (GET_CODE (body) == SET
6268 + && GET_MODE_SIZE (GET_MODE (SET_DEST (body))) == 8)
6269 + {
6270 + /* Ld.d : Ks16 */
6271 + fix->forwards = ((1 << 15) - 4);
6272 + fix->backwards = (1 << 15);
6273 + }
6274 + else if (GET_CODE (body) == UNSPEC_VOLATILE
6275 + && XINT (body, 1) == VUNSPEC_MVRC)
6276 + {
6277 + /* Coprocessor load */
6278 + /* Ldc : Ku8 << 2 */
6279 + fix->forwards = ((1 << 8) - 1) << 2;
6280 + fix->backwards = 0;
6281 + }
6282 + else
6283 + {
6284 + /* Assume worst case which is lddpc insn. */
6285 + fix->forwards = ((1 << 7) - 1) << 2;
6286 + fix->backwards = 0;
6287 + }
6288 +
6289 + fix->minipool = NULL;
6290 +
6291 + /* If an insn doesn't have a range defined for it, then it isn't expecting
6292 + to be reworked by this code. Better to abort now than to generate duff
6293 + assembly code. */
6294 + if (fix->forwards == 0 && fix->backwards == 0)
6295 + abort ();
6296 +
6297 + if (dump_file)
6298 + {
6299 + fprintf (dump_file,
6300 + ";; %smode fixup for i%d; addr %lu, range (%ld,%ld): ",
6301 + GET_MODE_NAME (mode),
6302 + INSN_UID (insn), (unsigned long) address,
6303 + -1 * (long) fix->backwards, (long) fix->forwards);
6304 + avr32_print_value (dump_file, fix->value);
6305 + fprintf (dump_file, "\n");
6306 + }
6307 +
6308 + /* Add it to the chain of fixes. */
6309 + fix->next = NULL;
6310 +
6311 + if (minipool_fix_head != NULL)
6312 + minipool_fix_tail->next = fix;
6313 + else
6314 + minipool_fix_head = fix;
6315 +
6316 + minipool_fix_tail = fix;
6317 +}
6318 +
6319 +
6320 +/* Scan INSN and note any of its operands that need fixing.
6321 + If DO_PUSHES is false we do not actually push any of the fixups
6322 + needed. The function returns TRUE is any fixups were needed/pushed.
6323 + This is used by avr32_memory_load_p() which needs to know about loads
6324 + of constants that will be converted into minipool loads. */
6325 +static bool
6326 +note_invalid_constants (rtx insn, HOST_WIDE_INT address, int do_pushes)
6327 +{
6328 + bool result = false;
6329 + int opno;
6330 +
6331 + extract_insn (insn);
6332 +
6333 + if (!constrain_operands (1))
6334 + fatal_insn_not_found (insn);
6335 +
6336 + if (recog_data.n_alternatives == 0)
6337 + return false;
6338 +
6339 + /* Fill in recog_op_alt with information about the constraints of this
6340 + insn. */
6341 + preprocess_constraints ();
6342 +
6343 + for (opno = 0; opno < recog_data.n_operands; opno++)
6344 + {
6345 + rtx op;
6346 +
6347 + /* Things we need to fix can only occur in inputs. */
6348 + if (recog_data.operand_type[opno] != OP_IN)
6349 + continue;
6350 +
6351 + op = recog_data.operand[opno];
6352 +
6353 + if (avr32_const_pool_ref_operand (op, GET_MODE (op)))
6354 + {
6355 + if (do_pushes)
6356 + {
6357 + rtx cop = avoid_constant_pool_reference (op);
6358 +
6359 + /* Casting the address of something to a mode narrower than a
6360 + word can cause avoid_constant_pool_reference() to return the
6361 + pool reference itself. That's no good to us here. Lets
6362 + just hope that we can use the constant pool value directly.
6363 + */
6364 + if (op == cop)
6365 + cop = get_pool_constant (XEXP (op, 0));
6366 +
6367 + push_minipool_fix (insn, address,
6368 + recog_data.operand_loc[opno],
6369 + recog_data.operand_mode[opno], cop);
6370 + }
6371 +
6372 + result = true;
6373 + }
6374 + else if (TARGET_HAS_ASM_ADDR_PSEUDOS
6375 + && avr32_address_operand (op, GET_MODE (op)))
6376 + {
6377 + /* Handle pseudo instructions using a direct address. These pseudo
6378 + instructions might need entries in the constant pool and we must
6379 + therefor create a constant pool for them, in case the
6380 + assembler/linker needs to insert entries. */
6381 + if (do_pushes)
6382 + {
6383 + /* Push a dummy constant pool entry so that the .cpool
6384 + directive should be inserted on the appropriate place in the
6385 + code even if there are no real constant pool entries. This
6386 + is used by the assembler and linker to know where to put
6387 + generated constant pool entries. */
6388 + push_minipool_fix (insn, address,
6389 + recog_data.operand_loc[opno],
6390 + recog_data.operand_mode[opno],
6391 + gen_rtx_UNSPEC (VOIDmode,
6392 + gen_rtvec (1, const0_rtx),
6393 + UNSPEC_FORCE_MINIPOOL));
6394 + result = true;
6395 + }
6396 + }
6397 + }
6398 + return result;
6399 +}
6400 +
6401 +
6402 +static int
6403 +avr32_insn_is_cast (rtx insn)
6404 +{
6405 +
6406 + if (NONJUMP_INSN_P (insn)
6407 + && GET_CODE (PATTERN (insn)) == SET
6408 + && (GET_CODE (SET_SRC (PATTERN (insn))) == ZERO_EXTEND
6409 + || GET_CODE (SET_SRC (PATTERN (insn))) == SIGN_EXTEND)
6410 + && REG_P (XEXP (SET_SRC (PATTERN (insn)), 0))
6411 + && REG_P (SET_DEST (PATTERN (insn))))
6412 + return true;
6413 + return false;
6414 +}
6415 +
6416 +
6417 +/* Replace all occurances of reg FROM with reg TO in X. */
6418 +rtx
6419 +avr32_replace_reg (rtx x, rtx from, rtx to)
6420 +{
6421 + int i, j;
6422 + const char *fmt;
6423 +
6424 + gcc_assert ( REG_P (from) && REG_P (to) );
6425 +
6426 + /* Allow this function to make replacements in EXPR_LISTs. */
6427 + if (x == 0)
6428 + return 0;
6429 +
6430 + if (rtx_equal_p (x, from))
6431 + return to;
6432 +
6433 + if (GET_CODE (x) == SUBREG)
6434 + {
6435 + rtx new = avr32_replace_reg (SUBREG_REG (x), from, to);
6436 +
6437 + if (GET_CODE (new) == CONST_INT)
6438 + {
6439 + x = simplify_subreg (GET_MODE (x), new,
6440 + GET_MODE (SUBREG_REG (x)),
6441 + SUBREG_BYTE (x));
6442 + gcc_assert (x);
6443 + }
6444 + else
6445 + SUBREG_REG (x) = new;
6446 +
6447 + return x;
6448 + }
6449 + else if (GET_CODE (x) == ZERO_EXTEND)
6450 + {
6451 + rtx new = avr32_replace_reg (XEXP (x, 0), from, to);
6452 +
6453 + if (GET_CODE (new) == CONST_INT)
6454 + {
6455 + x = simplify_unary_operation (ZERO_EXTEND, GET_MODE (x),
6456 + new, GET_MODE (XEXP (x, 0)));
6457 + gcc_assert (x);
6458 + }
6459 + else
6460 + XEXP (x, 0) = new;
6461 +
6462 + return x;
6463 + }
6464 +
6465 + fmt = GET_RTX_FORMAT (GET_CODE (x));
6466 + for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
6467 + {
6468 + if (fmt[i] == 'e')
6469 + XEXP (x, i) = avr32_replace_reg (XEXP (x, i), from, to);
6470 + else if (fmt[i] == 'E')
6471 + for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6472 + XVECEXP (x, i, j) = avr32_replace_reg (XVECEXP (x, i, j), from, to);
6473 + }
6474 +
6475 + return x;
6476 +}
6477 +
6478 +
6479 +/* FIXME: The level of nesting in this function is way too deep. It needs to be
6480 + torn apart. */
6481 +static void
6482 +avr32_reorg_optimization (void)
6483 +{
6484 + rtx first = get_first_nonnote_insn ();
6485 + rtx insn;
6486 +
6487 + if (TARGET_MD_REORG_OPTIMIZATION && (optimize_size || (optimize > 0)))
6488 + {
6489 +
6490 + /* Scan through all insns looking for cast operations. */
6491 + if (dump_file)
6492 + {
6493 + fprintf (dump_file, ";; Deleting redundant cast operations:\n");
6494 + }
6495 + for (insn = first; insn; insn = NEXT_INSN (insn))
6496 + {
6497 + rtx reg, src_reg, scan;
6498 + enum machine_mode mode;
6499 + int unused_cast;
6500 + rtx label_ref;
6501 +
6502 + if (avr32_insn_is_cast (insn)
6503 + && (GET_MODE (XEXP (SET_SRC (PATTERN (insn)), 0)) == QImode
6504 + || GET_MODE (XEXP (SET_SRC (PATTERN (insn)), 0)) == HImode))
6505 + {
6506 + mode = GET_MODE (XEXP (SET_SRC (PATTERN (insn)), 0));
6507 + reg = SET_DEST (PATTERN (insn));
6508 + src_reg = XEXP (SET_SRC (PATTERN (insn)), 0);
6509 + }
6510 + else
6511 + {
6512 + continue;
6513 + }
6514 +
6515 + unused_cast = false;
6516 + label_ref = NULL_RTX;
6517 + for (scan = NEXT_INSN (insn); scan; scan = NEXT_INSN (scan))
6518 + {
6519 + /* Check if we have reached the destination of a simple
6520 + conditional jump which we have already scanned past. If so,
6521 + we can safely continue scanning. */
6522 + if (LABEL_P (scan) && label_ref != NULL_RTX)
6523 + {
6524 + if (CODE_LABEL_NUMBER (scan) ==
6525 + CODE_LABEL_NUMBER (XEXP (label_ref, 0)))
6526 + label_ref = NULL_RTX;
6527 + else
6528 + break;
6529 + }
6530 +
6531 + if (!INSN_P (scan))
6532 + continue;
6533 +
6534 + /* For conditional jumps we can manage to keep on scanning if
6535 + we meet the destination label later on before any new jump
6536 + insns occure. */
6537 + if (GET_CODE (scan) == JUMP_INSN)
6538 + {
6539 + if (any_condjump_p (scan) && label_ref == NULL_RTX)
6540 + label_ref = condjump_label (scan);
6541 + else
6542 + break;
6543 + }
6544 +
6545 + /* Check if we have a call and the register is used as an argument. */
6546 + if (CALL_P (scan)
6547 + && find_reg_fusage (scan, USE, reg) )
6548 + break;
6549 +
6550 + if (!reg_mentioned_p (reg, PATTERN (scan)))
6551 + continue;
6552 +
6553 + /* Check if casted register is used in this insn */
6554 + if ((regno_use_in (REGNO (reg), PATTERN (scan)) != NULL_RTX)
6555 + && (GET_MODE (regno_use_in (REGNO (reg), PATTERN (scan))) ==
6556 + GET_MODE (reg)))
6557 + {
6558 + /* If not used in the source to the set or in a memory
6559 + expression in the destiantion then the register is used
6560 + as a destination and is really dead. */
6561 + if (single_set (scan)
6562 + && GET_CODE (PATTERN (scan)) == SET
6563 + && REG_P (SET_DEST (PATTERN (scan)))
6564 + && !regno_use_in (REGNO (reg), SET_SRC (PATTERN (scan)))
6565 + && label_ref == NULL_RTX)
6566 + {
6567 + unused_cast = true;
6568 + }
6569 + break;
6570 + }
6571 +
6572 + /* Check if register is dead or set in this insn */
6573 + if (dead_or_set_p (scan, reg))
6574 + {
6575 + unused_cast = true;
6576 + break;
6577 + }
6578 + }
6579 +
6580 + /* Check if we have unresolved conditional jumps */
6581 + if (label_ref != NULL_RTX)
6582 + continue;
6583 +
6584 + if (unused_cast)
6585 + {
6586 + if (REGNO (reg) == REGNO (XEXP (SET_SRC (PATTERN (insn)), 0)))
6587 + {
6588 + /* One operand cast, safe to delete */
6589 + if (dump_file)
6590 + {
6591 + fprintf (dump_file,
6592 + ";; INSN %i removed, casted register %i value not used.\n",
6593 + INSN_UID (insn), REGNO (reg));
6594 + }
6595 + SET_INSN_DELETED (insn);
6596 + /* Force the instruction to be recognized again */
6597 + INSN_CODE (insn) = -1;
6598 + }
6599 + else
6600 + {
6601 + /* Two operand cast, which really could be substituted with
6602 + a move, if the source register is dead after the cast
6603 + insn and then the insn which sets the source register
6604 + could instead directly set the destination register for
6605 + the cast. As long as there are no insns in between which
6606 + uses the register. */
6607 + rtx link = NULL_RTX;
6608 + rtx set;
6609 + rtx src_reg = XEXP (SET_SRC (PATTERN (insn)), 0);
6610 + unused_cast = false;
6611 +
6612 + if (!find_reg_note (insn, REG_DEAD, src_reg))
6613 + continue;
6614 +
6615 + /* Search for the insn which sets the source register */
6616 + for (scan = PREV_INSN (insn);
6617 + scan && GET_CODE (scan) != CODE_LABEL;
6618 + scan = PREV_INSN (scan))
6619 + {
6620 + if (! INSN_P (scan))
6621 + continue;
6622 +
6623 + set = single_set (scan);
6624 + // Fix for bug #11763 : the following if condition
6625 + // has been modified and else part is included to
6626 + // set the link to NULL_RTX.
6627 + // if (set && rtx_equal_p (src_reg, SET_DEST (set)))
6628 + if (set && (REGNO(src_reg) == REGNO(SET_DEST(set))))
6629 + {
6630 + if (rtx_equal_p (src_reg, SET_DEST (set)))
6631 + {
6632 + link = scan;
6633 + break;
6634 + }
6635 + else
6636 + {
6637 + link = NULL_RTX;
6638 + break;
6639 + }
6640 + }
6641 + }
6642 +
6643 +
6644 + /* Found no link or link is a call insn where we can not
6645 + change the destination register */
6646 + if (link == NULL_RTX || CALL_P (link))
6647 + continue;
6648 +
6649 + /* Scan through all insn between link and insn */
6650 + for (scan = NEXT_INSN (link); scan; scan = NEXT_INSN (scan))
6651 + {
6652 + /* Don't try to trace forward past a CODE_LABEL if we
6653 + haven't seen INSN yet. Ordinarily, we will only
6654 + find the setting insn in LOG_LINKS if it is in the
6655 + same basic block. However, cross-jumping can insert
6656 + code labels in between the load and the call, and
6657 + can result in situations where a single call insn
6658 + may have two targets depending on where we came
6659 + from. */
6660 +
6661 + if (GET_CODE (scan) == CODE_LABEL)
6662 + break;
6663 +
6664 + if (!INSN_P (scan))
6665 + continue;
6666 +
6667 + /* Don't try to trace forward past a JUMP. To optimize
6668 + safely, we would have to check that all the
6669 + instructions at the jump destination did not use REG.
6670 + */
6671 +
6672 + if (GET_CODE (scan) == JUMP_INSN)
6673 + {
6674 + break;
6675 + }
6676 +
6677 + if (!reg_mentioned_p (src_reg, PATTERN (scan)))
6678 + continue;
6679 +
6680 + /* We have reached the cast insn */
6681 + if (scan == insn)
6682 + {
6683 + /* We can remove cast and replace the destination
6684 + register of the link insn with the destination
6685 + of the cast */
6686 + if (dump_file)
6687 + {
6688 + fprintf (dump_file,
6689 + ";; INSN %i removed, casted value unused. "
6690 + "Destination of removed cast operation: register %i, folded into INSN %i.\n",
6691 + INSN_UID (insn), REGNO (reg),
6692 + INSN_UID (link));
6693 + }
6694 + /* Update link insn */
6695 + SET_DEST (PATTERN (link)) =
6696 + gen_rtx_REG (mode, REGNO (reg));
6697 + /* Force the instruction to be recognized again */
6698 + INSN_CODE (link) = -1;
6699 +
6700 + /* Delete insn */
6701 + SET_INSN_DELETED (insn);
6702 + /* Force the instruction to be recognized again */
6703 + INSN_CODE (insn) = -1;
6704 + break;
6705 + }
6706 + }
6707 + }
6708 + }
6709 + }
6710 + }
6711 +
6712 + if (TARGET_MD_REORG_OPTIMIZATION && (optimize_size || (optimize > 0)))
6713 + {
6714 +
6715 + /* Scan through all insns looking for shifted add operations */
6716 + if (dump_file)
6717 + {
6718 + fprintf (dump_file,
6719 + ";; Deleting redundant shifted add operations:\n");
6720 + }
6721 + for (insn = first; insn; insn = NEXT_INSN (insn))
6722 + {
6723 + rtx reg, mem_expr, scan, op0, op1;
6724 + int add_only_used_as_pointer;
6725 +
6726 + if (INSN_P (insn)
6727 + && GET_CODE (PATTERN (insn)) == SET
6728 + && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
6729 + && (GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 0)) == MULT
6730 + || GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 0)) == ASHIFT)
6731 + && GET_CODE (XEXP (XEXP (SET_SRC (PATTERN (insn)), 0), 1)) ==
6732 + CONST_INT && REG_P (SET_DEST (PATTERN (insn)))
6733 + && REG_P (XEXP (SET_SRC (PATTERN (insn)), 1))
6734 + && REG_P (XEXP (XEXP (SET_SRC (PATTERN (insn)), 0), 0)))
6735 + {
6736 + reg = SET_DEST (PATTERN (insn));
6737 + mem_expr = SET_SRC (PATTERN (insn));
6738 + op0 = XEXP (XEXP (mem_expr, 0), 0);
6739 + op1 = XEXP (mem_expr, 1);
6740 + }
6741 + else
6742 + {
6743 + continue;
6744 + }
6745 +
6746 + /* Scan forward the check if the result of the shifted add
6747 + operation is only used as an address in memory operations and
6748 + that the operands to the shifted add are not clobbered. */
6749 + add_only_used_as_pointer = false;
6750 + for (scan = NEXT_INSN (insn); scan; scan = NEXT_INSN (scan))
6751 + {
6752 + if (!INSN_P (scan))
6753 + continue;
6754 +
6755 + /* Don't try to trace forward past a JUMP or CALL. To optimize
6756 + safely, we would have to check that all the instructions at
6757 + the jump destination did not use REG. */
6758 +
6759 + if (GET_CODE (scan) == JUMP_INSN)
6760 + {
6761 + break;
6762 + }
6763 +
6764 + /* If used in a call insn then we cannot optimize it away */
6765 + if (CALL_P (scan) && find_regno_fusage (scan, USE, REGNO (reg)))
6766 + break;
6767 +
6768 + /* If any of the operands of the shifted add are clobbered we
6769 + cannot optimize the shifted adda away */
6770 + if ((reg_set_p (op0, scan) && (REGNO (op0) != REGNO (reg)))
6771 + || (reg_set_p (op1, scan) && (REGNO (op1) != REGNO (reg))))
6772 + break;
6773 +
6774 + if (!reg_mentioned_p (reg, PATTERN (scan)))
6775 + continue;
6776 +
6777 + /* If used any other place than as a pointer or as the
6778 + destination register we failed */
6779 + if (!(single_set (scan)
6780 + && GET_CODE (PATTERN (scan)) == SET
6781 + && ((MEM_P (SET_DEST (PATTERN (scan)))
6782 + && REG_P (XEXP (SET_DEST (PATTERN (scan)), 0))
6783 + && REGNO (XEXP (SET_DEST (PATTERN (scan)), 0)) == REGNO (reg))
6784 + || (MEM_P (SET_SRC (PATTERN (scan)))
6785 + && REG_P (XEXP (SET_SRC (PATTERN (scan)), 0))
6786 + && REGNO (XEXP
6787 + (SET_SRC (PATTERN (scan)), 0)) == REGNO (reg))))
6788 + && !(GET_CODE (PATTERN (scan)) == SET
6789 + && REG_P (SET_DEST (PATTERN (scan)))
6790 + && !regno_use_in (REGNO (reg),
6791 + SET_SRC (PATTERN (scan)))))
6792 + break;
6793 +
6794 + /* We cannot replace the pointer in TImode insns
6795 + as these has a differene addressing mode than the other
6796 + memory insns. */
6797 + if ( GET_MODE (SET_DEST (PATTERN (scan))) == TImode )
6798 + break;
6799 +
6800 + /* Check if register is dead or set in this insn */
6801 + if (dead_or_set_p (scan, reg))
6802 + {
6803 + add_only_used_as_pointer = true;
6804 + break;
6805 + }
6806 + }
6807 +
6808 + if (add_only_used_as_pointer)
6809 + {
6810 + /* Lets delete the add insn and replace all memory references
6811 + which uses the pointer with the full expression. */
6812 + if (dump_file)
6813 + {
6814 + fprintf (dump_file,
6815 + ";; Deleting INSN %i since address expression can be folded into all "
6816 + "memory references using this expression\n",
6817 + INSN_UID (insn));
6818 + }
6819 + SET_INSN_DELETED (insn);
6820 + /* Force the instruction to be recognized again */
6821 + INSN_CODE (insn) = -1;
6822 +
6823 + for (scan = NEXT_INSN (insn); scan; scan = NEXT_INSN (scan))
6824 + {
6825 + if (!INSN_P (scan))
6826 + continue;
6827 +
6828 + if (!reg_mentioned_p (reg, PATTERN (scan)))
6829 + continue;
6830 +
6831 + /* If used any other place than as a pointer or as the
6832 + destination register we failed */
6833 + if ((single_set (scan)
6834 + && GET_CODE (PATTERN (scan)) == SET
6835 + && ((MEM_P (SET_DEST (PATTERN (scan)))
6836 + && REG_P (XEXP (SET_DEST (PATTERN (scan)), 0))
6837 + && REGNO (XEXP (SET_DEST (PATTERN (scan)), 0)) ==
6838 + REGNO (reg)) || (MEM_P (SET_SRC (PATTERN (scan)))
6839 + &&
6840 + REG_P (XEXP
6841 + (SET_SRC (PATTERN (scan)),
6842 + 0))
6843 + &&
6844 + REGNO (XEXP
6845 + (SET_SRC (PATTERN (scan)),
6846 + 0)) == REGNO (reg)))))
6847 + {
6848 + if (dump_file)
6849 + {
6850 + fprintf (dump_file,
6851 + ";; Register %i replaced by indexed address in INSN %i\n",
6852 + REGNO (reg), INSN_UID (scan));
6853 + }
6854 + if (MEM_P (SET_DEST (PATTERN (scan))))
6855 + XEXP (SET_DEST (PATTERN (scan)), 0) = mem_expr;
6856 + else
6857 + XEXP (SET_SRC (PATTERN (scan)), 0) = mem_expr;
6858 + }
6859 +
6860 + /* Check if register is dead or set in this insn */
6861 + if (dead_or_set_p (scan, reg))
6862 + {
6863 + break;
6864 + }
6865 +
6866 + }
6867 + }
6868 + }
6869 + }
6870 +
6871 +
6872 + if (TARGET_MD_REORG_OPTIMIZATION && (optimize_size || (optimize > 0)))
6873 + {
6874 +
6875 + /* Scan through all insns looking for conditional register to
6876 + register move operations */
6877 + if (dump_file)
6878 + {
6879 + fprintf (dump_file,
6880 + ";; Folding redundant conditional move operations:\n");
6881 + }
6882 + for (insn = first; insn; insn = next_nonnote_insn (insn))
6883 + {
6884 + rtx src_reg, dst_reg, scan, test;
6885 +
6886 + if (INSN_P (insn)
6887 + && GET_CODE (PATTERN (insn)) == COND_EXEC
6888 + && GET_CODE (COND_EXEC_CODE (PATTERN (insn))) == SET
6889 + && REG_P (SET_SRC (COND_EXEC_CODE (PATTERN (insn))))
6890 + && REG_P (SET_DEST (COND_EXEC_CODE (PATTERN (insn))))
6891 + && find_reg_note (insn, REG_DEAD, SET_SRC (COND_EXEC_CODE (PATTERN (insn)))))
6892 + {
6893 + src_reg = SET_SRC (COND_EXEC_CODE (PATTERN (insn)));
6894 + dst_reg = SET_DEST (COND_EXEC_CODE (PATTERN (insn)));
6895 + test = COND_EXEC_TEST (PATTERN (insn));
6896 + }
6897 + else
6898 + {
6899 + continue;
6900 + }
6901 +
6902 + /* Scan backward through the rest of insns in this if-then or if-else
6903 + block and check if we can fold the move into another of the conditional
6904 + insns in the same block. */
6905 + scan = prev_nonnote_insn (insn);
6906 + while (INSN_P (scan)
6907 + && GET_CODE (PATTERN (scan)) == COND_EXEC
6908 + && rtx_equal_p (COND_EXEC_TEST (PATTERN (scan)), test))
6909 + {
6910 + rtx pattern = COND_EXEC_CODE (PATTERN (scan));
6911 + if ( GET_CODE (pattern) == PARALLEL )
6912 + pattern = XVECEXP (pattern, 0, 0);
6913 +
6914 + if ( reg_set_p (src_reg, pattern) )
6915 + {
6916 + /* Fold in the destination register for the cond. move
6917 + into this insn. */
6918 + SET_DEST (pattern) = dst_reg;
6919 + if (dump_file)
6920 + {
6921 + fprintf (dump_file,
6922 + ";; Deleting INSN %i since this operation can be folded into INSN %i\n",
6923 + INSN_UID (insn), INSN_UID (scan));
6924 + }
6925 +
6926 + /* Scan and check if any of the insns in between uses the src_reg. We
6927 + must then replace it with the dst_reg. */
6928 + while ( (scan = next_nonnote_insn (scan)) != insn ){
6929 + avr32_replace_reg (scan, src_reg, dst_reg);
6930 + }
6931 + /* Delete the insn. */
6932 + SET_INSN_DELETED (insn);
6933 +
6934 + /* Force the instruction to be recognized again */
6935 + INSN_CODE (insn) = -1;
6936 + break;
6937 + }
6938 +
6939 + /* If the destination register is used but not set in this insn
6940 + we cannot fold. */
6941 + if ( reg_mentioned_p (dst_reg, pattern) )
6942 + break;
6943 +
6944 + scan = prev_nonnote_insn (scan);
6945 + }
6946 + }
6947 + }
6948 +
6949 +}
6950 +
6951 +
6952 +/* Exported to toplev.c.
6953 +
6954 + Do a final pass over the function, just before delayed branch
6955 + scheduling. */
6956 +static void
6957 +avr32_reorg (void)
6958 +{
6959 + rtx insn;
6960 + HOST_WIDE_INT address = 0;
6961 + Mfix *fix;
6962 +
6963 + minipool_fix_head = minipool_fix_tail = NULL;
6964 +
6965 + /* The first insn must always be a note, or the code below won't scan it
6966 + properly. */
6967 + insn = get_insns ();
6968 + if (GET_CODE (insn) != NOTE)
6969 + abort ();
6970 +
6971 + /* Scan all the insns and record the operands that will need fixing. */
6972 + for (insn = next_nonnote_insn (insn); insn; insn = next_nonnote_insn (insn))
6973 + {
6974 + if (GET_CODE (insn) == BARRIER)
6975 + push_minipool_barrier (insn, address);
6976 + else if (INSN_P (insn))
6977 + {
6978 + rtx table;
6979 +
6980 + note_invalid_constants (insn, address, true);
6981 + address += get_attr_length (insn);
6982 +
6983 + /* If the insn is a vector jump, add the size of the table and skip
6984 + the table. */
6985 + if ((table = is_jump_table (insn)) != NULL)
6986 + {
6987 + address += get_jump_table_size (table);
6988 + insn = table;
6989 + }
6990 + }
6991 + }
6992 +
6993 + fix = minipool_fix_head;
6994 +
6995 + /* Now scan the fixups and perform the required changes. */
6996 + while (fix)
6997 + {
6998 + Mfix *ftmp;
6999 + Mfix *fdel;
7000 + Mfix *last_added_fix;
7001 + Mfix *last_barrier = NULL;
7002 + Mfix *this_fix;
7003 +
7004 + /* Skip any further barriers before the next fix. */
7005 + while (fix && GET_CODE (fix->insn) == BARRIER)
7006 + fix = fix->next;
7007 +
7008 + /* No more fixes. */
7009 + if (fix == NULL)
7010 + break;
7011 +
7012 + last_added_fix = NULL;
7013 +
7014 + for (ftmp = fix; ftmp; ftmp = ftmp->next)
7015 + {
7016 + if (GET_CODE (ftmp->insn) == BARRIER)
7017 + {
7018 + if (ftmp->address >= minipool_vector_head->max_address)
7019 + break;
7020 +
7021 + last_barrier = ftmp;
7022 + }
7023 + else if ((ftmp->minipool = add_minipool_forward_ref (ftmp)) == NULL)
7024 + break;
7025 +
7026 + last_added_fix = ftmp; /* Keep track of the last fix added.
7027 + */
7028 + }
7029 +
7030 + /* If we found a barrier, drop back to that; any fixes that we could
7031 + have reached but come after the barrier will now go in the next
7032 + mini-pool. */
7033 + if (last_barrier != NULL)
7034 + {
7035 + /* Reduce the refcount for those fixes that won't go into this pool
7036 + after all. */
7037 + for (fdel = last_barrier->next;
7038 + fdel && fdel != ftmp; fdel = fdel->next)
7039 + {
7040 + fdel->minipool->refcount--;
7041 + fdel->minipool = NULL;
7042 + }
7043 +
7044 + ftmp = last_barrier;
7045 + }
7046 + else
7047 + {
7048 + /* ftmp is first fix that we can't fit into this pool and there no
7049 + natural barriers that we could use. Insert a new barrier in the
7050 + code somewhere between the previous fix and this one, and
7051 + arrange to jump around it. */
7052 + HOST_WIDE_INT max_address;
7053 +
7054 + /* The last item on the list of fixes must be a barrier, so we can
7055 + never run off the end of the list of fixes without last_barrier
7056 + being set. */
7057 + if (ftmp == NULL)
7058 + abort ();
7059 +
7060 + max_address = minipool_vector_head->max_address;
7061 + /* Check that there isn't another fix that is in range that we
7062 + couldn't fit into this pool because the pool was already too
7063 + large: we need to put the pool before such an instruction. */
7064 + if (ftmp->address < max_address)
7065 + max_address = ftmp->address;
7066 +
7067 + last_barrier = create_fix_barrier (last_added_fix, max_address);
7068 + }
7069 +
7070 + assign_minipool_offsets (last_barrier);
7071 +
7072 + while (ftmp)
7073 + {
7074 + if (GET_CODE (ftmp->insn) != BARRIER
7075 + && ((ftmp->minipool = add_minipool_backward_ref (ftmp))
7076 + == NULL))
7077 + break;
7078 +
7079 + ftmp = ftmp->next;
7080 + }
7081 +
7082 + /* Scan over the fixes we have identified for this pool, fixing them up
7083 + and adding the constants to the pool itself. */
7084 + for (this_fix = fix; this_fix && ftmp != this_fix;
7085 + this_fix = this_fix->next)
7086 + if (GET_CODE (this_fix->insn) != BARRIER
7087 + /* Do nothing for entries present just to force the insertion of
7088 + a minipool. */
7089 + && !IS_FORCE_MINIPOOL (this_fix->value))
7090 + {
7091 + rtx addr = plus_constant (gen_rtx_LABEL_REF (VOIDmode,
7092 + minipool_vector_label),
7093 + this_fix->minipool->offset);
7094 + *this_fix->loc = gen_rtx_MEM (this_fix->mode, addr);
7095 + }
7096 +
7097 + dump_minipool (last_barrier->insn);
7098 + fix = ftmp;
7099 + }
7100 +
7101 + /* Free the minipool memory. */
7102 + obstack_free (&minipool_obstack, minipool_startobj);
7103 +
7104 + avr32_reorg_optimization ();
7105 +}
7106 +
7107 +
7108 +/* Hook for doing some final scanning of instructions. Does nothing yet...*/
7109 +void
7110 +avr32_final_prescan_insn (rtx insn ATTRIBUTE_UNUSED,
7111 + rtx * opvec ATTRIBUTE_UNUSED,
7112 + int noperands ATTRIBUTE_UNUSED)
7113 +{
7114 + return;
7115 +}
7116 +
7117 +
7118 +/* Function for changing the condition on the next instruction,
7119 + should be used when emmiting compare instructions and
7120 + the condition of the next instruction needs to change.
7121 +*/
7122 +int
7123 +set_next_insn_cond (rtx cur_insn, rtx new_cond)
7124 +{
7125 + rtx next_insn = next_nonnote_insn (cur_insn);
7126 + if ((next_insn != NULL_RTX)
7127 + && (INSN_P (next_insn)))
7128 + {
7129 + if ((GET_CODE (PATTERN (next_insn)) == SET)
7130 + && (GET_CODE (SET_SRC (PATTERN (next_insn))) == IF_THEN_ELSE))
7131 + {
7132 + /* Branch instructions */
7133 + XEXP (SET_SRC (PATTERN (next_insn)), 0) = new_cond;
7134 + /* Force the instruction to be recognized again */
7135 + INSN_CODE (next_insn) = -1;
7136 + return TRUE;
7137 + }
7138 + else if ((GET_CODE (PATTERN (next_insn)) == SET)
7139 + && avr32_comparison_operator (SET_SRC (PATTERN (next_insn)),
7140 + GET_MODE (SET_SRC (PATTERN (next_insn)))))
7141 + {
7142 + /* scc with no compare */
7143 + SET_SRC (PATTERN (next_insn)) = new_cond;
7144 + /* Force the instruction to be recognized again */
7145 + INSN_CODE (next_insn) = -1;
7146 + return TRUE;
7147 + }
7148 + else if (GET_CODE (PATTERN (next_insn)) == COND_EXEC)
7149 + {
7150 + if ( GET_CODE (new_cond) == UNSPEC )
7151 + {
7152 + COND_EXEC_TEST (PATTERN (next_insn)) =
7153 + gen_rtx_UNSPEC (CCmode,
7154 + gen_rtvec (2,
7155 + XEXP (COND_EXEC_TEST (PATTERN (next_insn)), 0),
7156 + XEXP (COND_EXEC_TEST (PATTERN (next_insn)), 1)),
7157 + XINT (new_cond, 1));
7158 + }
7159 + else
7160 + {
7161 + PUT_CODE(COND_EXEC_TEST (PATTERN (next_insn)), GET_CODE(new_cond));
7162 + }
7163 + }
7164 + }
7165 +
7166 + return FALSE;
7167 +}
7168 +
7169 +
7170 +/* Function for obtaining the condition for the next instruction after cur_insn.
7171 +*/
7172 +rtx
7173 +get_next_insn_cond (rtx cur_insn)
7174 +{
7175 + rtx next_insn = next_nonnote_insn (cur_insn);
7176 + rtx cond = NULL_RTX;
7177 + if (next_insn != NULL_RTX
7178 + && INSN_P (next_insn))
7179 + {
7180 + if ((GET_CODE (PATTERN (next_insn)) == SET)
7181 + && (GET_CODE (SET_SRC (PATTERN (next_insn))) == IF_THEN_ELSE))
7182 + {
7183 + /* Branch and cond if then else instructions */
7184 + cond = XEXP (SET_SRC (PATTERN (next_insn)), 0);
7185 + }
7186 + else if ((GET_CODE (PATTERN (next_insn)) == SET)
7187 + && avr32_comparison_operator (SET_SRC (PATTERN (next_insn)),
7188 + GET_MODE (SET_SRC (PATTERN (next_insn)))))
7189 + {
7190 + /* scc with no compare */
7191 + cond = SET_SRC (PATTERN (next_insn));
7192 + }
7193 + else if (GET_CODE (PATTERN (next_insn)) == COND_EXEC)
7194 + {
7195 + cond = COND_EXEC_TEST (PATTERN (next_insn));
7196 + }
7197 + }
7198 + return cond;
7199 +}
7200 +
7201 +
7202 +/* Check if the next insn is a conditional insn that will emit a compare
7203 + for itself.
7204 +*/
7205 +rtx
7206 +next_insn_emits_cmp (rtx cur_insn)
7207 +{
7208 + rtx next_insn = next_nonnote_insn (cur_insn);
7209 + rtx cond = NULL_RTX;
7210 + if (next_insn != NULL_RTX
7211 + && INSN_P (next_insn))
7212 + {
7213 + if ( ((GET_CODE (PATTERN (next_insn)) == SET)
7214 + && (GET_CODE (SET_SRC (PATTERN (next_insn))) == IF_THEN_ELSE)
7215 + && (XEXP (XEXP (SET_SRC (PATTERN (next_insn)), 0),0) != cc0_rtx))
7216 + || GET_CODE (PATTERN (next_insn)) == COND_EXEC )
7217 + return TRUE;
7218 + }
7219 + return FALSE;
7220 +}
7221 +
7222 +
7223 +rtx
7224 +avr32_output_cmp (rtx cond, enum machine_mode mode, rtx op0, rtx op1)
7225 +{
7226 +
7227 + rtx new_cond = NULL_RTX;
7228 + rtx ops[2];
7229 + rtx compare_pattern;
7230 + ops[0] = op0;
7231 + ops[1] = op1;
7232 +
7233 + if ( GET_CODE (op0) == AND )
7234 + compare_pattern = op0;
7235 + else
7236 + compare_pattern = gen_rtx_COMPARE (mode, op0, op1);
7237 +
7238 + new_cond = is_compare_redundant (compare_pattern, cond);
7239 +
7240 + if (new_cond != NULL_RTX)
7241 + return new_cond;
7242 +
7243 + /* Check if we are inserting a bit-load instead of a compare. */
7244 + if ( GET_CODE (op0) == AND )
7245 + {
7246 + ops[0] = XEXP (op0, 0);
7247 + ops[1] = XEXP (op0, 1);
7248 + output_asm_insn ("bld\t%0, %p1", ops);
7249 + return cond;
7250 + }
7251 +
7252 + /* Insert compare */
7253 + switch (mode)
7254 + {
7255 + case QImode:
7256 + output_asm_insn ("cp.b\t%0, %1", ops);
7257 + break;
7258 + case HImode:
7259 + output_asm_insn ("cp.h\t%0, %1", ops);
7260 + break;
7261 + case SImode:
7262 + output_asm_insn ("cp.w\t%0, %1", ops);
7263 + break;
7264 + case DImode:
7265 + if (GET_CODE (op1) != REG)
7266 + output_asm_insn ("cp.w\t%0, %1\ncpc\t%m0", ops);
7267 + else
7268 + output_asm_insn ("cp.w\t%0, %1\ncpc\t%m0, %m1", ops);
7269 + break;
7270 + default:
7271 + internal_error ("Unknown comparison mode");
7272 + break;
7273 + }
7274 +
7275 + return cond;
7276 +}
7277 +
7278 +
7279 +int
7280 +avr32_load_multiple_operation (rtx op,
7281 + enum machine_mode mode ATTRIBUTE_UNUSED)
7282 +{
7283 + int count = XVECLEN (op, 0);
7284 + unsigned int dest_regno;
7285 + rtx src_addr;
7286 + rtx elt;
7287 + int i = 1, base = 0;
7288 +
7289 + if (count <= 1 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
7290 + return 0;
7291 +
7292 + /* Check to see if this might be a write-back. */
7293 + if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
7294 + {
7295 + i++;
7296 + base = 1;
7297 +
7298 + /* Now check it more carefully. */
7299 + if (GET_CODE (SET_DEST (elt)) != REG
7300 + || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
7301 + || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
7302 + || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 1) * 4)
7303 + return 0;
7304 + }
7305 +
7306 + /* Perform a quick check so we don't blow up below. */
7307 + if (count <= 1
7308 + || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
7309 + || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != REG
7310 + || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != UNSPEC)
7311 + return 0;
7312 +
7313 + dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, i - 1)));
7314 + src_addr = XEXP (SET_SRC (XVECEXP (op, 0, i - 1)), 0);
7315 +
7316 + for (; i < count; i++)
7317 + {
7318 + elt = XVECEXP (op, 0, i);
7319 +
7320 + if (GET_CODE (elt) != SET
7321 + || GET_CODE (SET_DEST (elt)) != REG
7322 + || GET_MODE (SET_DEST (elt)) != SImode
7323 + || GET_CODE (SET_SRC (elt)) != UNSPEC)
7324 + return 0;
7325 + }
7326 +
7327 + return 1;
7328 +}
7329 +
7330 +
7331 +int
7332 +avr32_store_multiple_operation (rtx op,
7333 + enum machine_mode mode ATTRIBUTE_UNUSED)
7334 +{
7335 + int count = XVECLEN (op, 0);
7336 + int src_regno;
7337 + rtx dest_addr;
7338 + rtx elt;
7339 + int i = 1;
7340 +
7341 + if (count <= 1 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
7342 + return 0;
7343 +
7344 + /* Perform a quick check so we don't blow up below. */
7345 + if (count <= i
7346 + || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
7347 + || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != MEM
7348 + || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != UNSPEC)
7349 + return 0;
7350 +
7351 + src_regno = REGNO (SET_SRC (XVECEXP (op, 0, i - 1)));
7352 + dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, i - 1)), 0);
7353 +
7354 + for (; i < count; i++)
7355 + {
7356 + elt = XVECEXP (op, 0, i);
7357 +
7358 + if (GET_CODE (elt) != SET
7359 + || GET_CODE (SET_DEST (elt)) != MEM
7360 + || GET_MODE (SET_DEST (elt)) != SImode
7361 + || GET_CODE (SET_SRC (elt)) != UNSPEC)
7362 + return 0;
7363 + }
7364 +
7365 + return 1;
7366 +}
7367 +
7368 +
7369 +int
7370 +avr32_valid_macmac_bypass (rtx insn_out, rtx insn_in)
7371 +{
7372 + /* Check if they use the same accumulator */
7373 + if (rtx_equal_p
7374 + (SET_DEST (PATTERN (insn_out)), SET_DEST (PATTERN (insn_in))))
7375 + {
7376 + return TRUE;
7377 + }
7378 +
7379 + return FALSE;
7380 +}
7381 +
7382 +
7383 +int
7384 +avr32_valid_mulmac_bypass (rtx insn_out, rtx insn_in)
7385 +{
7386 + /*
7387 + Check if the mul instruction produces the accumulator for the mac
7388 + instruction. */
7389 + if (rtx_equal_p
7390 + (SET_DEST (PATTERN (insn_out)), SET_DEST (PATTERN (insn_in))))
7391 + {
7392 + return TRUE;
7393 + }
7394 + return FALSE;
7395 +}
7396 +
7397 +
7398 +int
7399 +avr32_store_bypass (rtx insn_out, rtx insn_in)
7400 +{
7401 + /* Only valid bypass if the output result is used as an src in the store
7402 + instruction, NOT if used as a pointer or base. */
7403 + if (rtx_equal_p
7404 + (SET_DEST (PATTERN (insn_out)), SET_SRC (PATTERN (insn_in))))
7405 + {
7406 + return TRUE;
7407 + }
7408 +
7409 + return FALSE;
7410 +}
7411 +
7412 +
7413 +int
7414 +avr32_mul_waw_bypass (rtx insn_out, rtx insn_in)
7415 +{
7416 + /* Check if the register holding the result from the mul instruction is
7417 + used as a result register in the input instruction. */
7418 + if (rtx_equal_p
7419 + (SET_DEST (PATTERN (insn_out)), SET_DEST (PATTERN (insn_in))))
7420 + {
7421 + return TRUE;
7422 + }
7423 +
7424 + return FALSE;
7425 +}
7426 +
7427 +
7428 +int
7429 +avr32_valid_load_double_bypass (rtx insn_out, rtx insn_in)
7430 +{
7431 + /* Check if the first loaded word in insn_out is used in insn_in. */
7432 + rtx dst_reg;
7433 + rtx second_loaded_reg;
7434 +
7435 + /* If this is a double alu operation then the bypass is not valid */
7436 + if ((get_attr_type (insn_in) == TYPE_ALU
7437 + || get_attr_type (insn_in) == TYPE_ALU2)
7438 + && (GET_MODE_SIZE (GET_MODE (SET_DEST (PATTERN (insn_out)))) > 4))
7439 + return FALSE;
7440 +
7441 + /* Get the destination register in the load */
7442 + if (!REG_P (SET_DEST (PATTERN (insn_out))))
7443 + return FALSE;
7444 +
7445 + dst_reg = SET_DEST (PATTERN (insn_out));
7446 + second_loaded_reg = gen_rtx_REG (SImode, REGNO (dst_reg) + 1);
7447 +
7448 + if (!reg_mentioned_p (second_loaded_reg, PATTERN (insn_in)))
7449 + return TRUE;
7450 +
7451 + return FALSE;
7452 +}
7453 +
7454 +
7455 +int
7456 +avr32_valid_load_quad_bypass (rtx insn_out, rtx insn_in)
7457 +{
7458 + /*
7459 + Check if the two first loaded word in insn_out are used in insn_in. */
7460 + rtx dst_reg;
7461 + rtx third_loaded_reg, fourth_loaded_reg;
7462 +
7463 + /* Get the destination register in the load */
7464 + if (!REG_P (SET_DEST (PATTERN (insn_out))))
7465 + return FALSE;
7466 +
7467 + dst_reg = SET_DEST (PATTERN (insn_out));
7468 + third_loaded_reg = gen_rtx_REG (SImode, REGNO (dst_reg) + 2);
7469 + fourth_loaded_reg = gen_rtx_REG (SImode, REGNO (dst_reg) + 3);
7470 +
7471 + if (!reg_mentioned_p (third_loaded_reg, PATTERN (insn_in))
7472 + && !reg_mentioned_p (fourth_loaded_reg, PATTERN (insn_in)))
7473 + {
7474 + return TRUE;
7475 + }
7476 +
7477 + return FALSE;
7478 +}
7479 +
7480 +
7481 +rtx
7482 +avr32_ifcvt_modify_test (ce_if_block_t *ce_info, rtx test )
7483 +{
7484 + rtx branch_insn;
7485 + rtx cmp_test;
7486 + rtx compare_op0;
7487 + rtx compare_op1;
7488 +
7489 +
7490 + if ( !ce_info
7491 + || test == NULL_RTX
7492 + || !reg_mentioned_p (cc0_rtx, test))
7493 + return test;
7494 +
7495 + branch_insn = BB_END (ce_info->test_bb);
7496 + cmp_test = PATTERN(prev_nonnote_insn (branch_insn));
7497 +
7498 + if (GET_CODE(cmp_test) != SET
7499 + || !CC0_P(XEXP(cmp_test, 0)) )
7500 + return cmp_test;
7501 +
7502 + if ( GET_CODE(SET_SRC(cmp_test)) == COMPARE ){
7503 + compare_op0 = XEXP(SET_SRC(cmp_test), 0);
7504 + compare_op1 = XEXP(SET_SRC(cmp_test), 1);
7505 + } else {
7506 + compare_op0 = SET_SRC(cmp_test);
7507 + compare_op1 = const0_rtx;
7508 + }
7509 +
7510 + return gen_rtx_fmt_ee (GET_CODE(test), GET_MODE (compare_op0),
7511 + compare_op0, compare_op1);
7512 +}
7513 +
7514 +
7515 +rtx
7516 +avr32_ifcvt_modify_insn (ce_if_block_t *ce_info, rtx pattern, rtx insn,
7517 + int *num_true_changes)
7518 +{
7519 + rtx test = COND_EXEC_TEST(pattern);
7520 + rtx op = COND_EXEC_CODE(pattern);
7521 + rtx cmp_insn;
7522 + rtx cond_exec_insn;
7523 + int inputs_set_outside_ifblock = 1;
7524 + basic_block current_bb = BLOCK_FOR_INSN (insn);
7525 + rtx bb_insn ;
7526 + enum machine_mode mode = GET_MODE (XEXP (op, 0));
7527 +
7528 + if (CC0_P(XEXP(test, 0)))
7529 + test = avr32_ifcvt_modify_test (ce_info,
7530 + test );
7531 +
7532 + /* We do not support multiple tests. */
7533 + if ( ce_info
7534 + && ce_info->num_multiple_test_blocks > 0 )
7535 + return NULL_RTX;
7536 +
7537 + pattern = gen_rtx_COND_EXEC (VOIDmode, test, op);
7538 +
7539 + if ( !reload_completed )
7540 + {
7541 + rtx start;
7542 + int num_insns;
7543 + int max_insns = MAX_CONDITIONAL_EXECUTE;
7544 +
7545 + if ( !ce_info )
7546 + return op;
7547 +
7548 + /* Check if the insn is not suitable for conditional
7549 + execution. */
7550 + start_sequence ();
7551 + cond_exec_insn = emit_insn (pattern);
7552 + if ( recog_memoized (cond_exec_insn) < 0
7553 + && can_create_pseudo_p () )
7554 + {
7555 + /* Insn is not suitable for conditional execution, try
7556 + to fix it up by using an extra scratch register or
7557 + by pulling the operation outside the if-then-else
7558 + and then emiting a conditional move inside the if-then-else. */
7559 + end_sequence ();
7560 + if ( GET_CODE (op) != SET
7561 + || !REG_P (SET_DEST (op))
7562 + || GET_CODE (SET_SRC (op)) == IF_THEN_ELSE
7563 + || GET_MODE_SIZE (mode) > UNITS_PER_WORD )
7564 + return NULL_RTX;
7565 +
7566 + /* Check if any of the input operands to the insn is set inside the
7567 + current block. */
7568 + if ( current_bb->index == ce_info->then_bb->index )
7569 + start = PREV_INSN (BB_HEAD (ce_info->then_bb));
7570 + else
7571 + start = PREV_INSN (BB_HEAD (ce_info->else_bb));
7572 +
7573 +
7574 + for ( bb_insn = next_nonnote_insn (start); bb_insn != insn; bb_insn = next_nonnote_insn (bb_insn) )
7575 + {
7576 + rtx set = single_set (bb_insn);
7577 +
7578 + if ( set && reg_mentioned_p (SET_DEST (set), SET_SRC (op)))
7579 + {
7580 + inputs_set_outside_ifblock = 0;
7581 + break;
7582 + }
7583 + }
7584 +
7585 + cmp_insn = prev_nonnote_insn (BB_END (ce_info->test_bb));
7586 +
7587 +
7588 + /* Check if we can insert more insns. */
7589 + num_insns = ( ce_info->num_then_insns +
7590 + ce_info->num_else_insns +
7591 + ce_info->num_cond_clobber_insns +
7592 + ce_info->num_extra_move_insns );
7593 +
7594 + if ( ce_info->num_else_insns != 0 )
7595 + max_insns *=2;
7596 +
7597 + if ( num_insns >= max_insns )
7598 + return NULL_RTX;
7599 +
7600 + /* Check if we have an instruction which might be converted to
7601 + conditional form if we give it a scratch register to clobber. */
7602 + {
7603 + rtx clobber_insn;
7604 + rtx scratch_reg = gen_reg_rtx (mode);
7605 + rtx new_pattern = copy_rtx (pattern);
7606 + rtx set_src = SET_SRC (COND_EXEC_CODE (new_pattern));
7607 +
7608 + rtx clobber = gen_rtx_CLOBBER (mode, scratch_reg);
7609 + rtx vec[2] = { COND_EXEC_CODE (new_pattern), clobber };
7610 + COND_EXEC_CODE (new_pattern) = gen_rtx_PARALLEL (mode, gen_rtvec_v (2, vec));
7611 +
7612 + start_sequence ();
7613 + clobber_insn = emit_insn (new_pattern);
7614 +
7615 + if ( recog_memoized (clobber_insn) >= 0
7616 + && ( ( GET_RTX_LENGTH (GET_CODE (set_src)) == 2
7617 + && CONST_INT_P (XEXP (set_src, 1))
7618 + && avr32_const_ok_for_constraint_p (INTVAL (XEXP (set_src, 1)), 'K', "Ks08") )
7619 + || !ce_info->else_bb
7620 + || current_bb->index == ce_info->else_bb->index ))
7621 + {
7622 + end_sequence ();
7623 + /* Force the insn to be recognized again. */
7624 + INSN_CODE (insn) = -1;
7625 +
7626 + /* If this is the first change in this IF-block then
7627 + signal that we have made a change. */
7628 + if ( ce_info->num_cond_clobber_insns == 0
7629 + && ce_info->num_extra_move_insns == 0 )
7630 + *num_true_changes += 1;
7631 +
7632 + ce_info->num_cond_clobber_insns++;
7633 +
7634 + if (dump_file)
7635 + fprintf (dump_file,
7636 + "\nReplacing INSN %d with an insn using a scratch register for later ifcvt passes...\n",
7637 + INSN_UID (insn));
7638 +
7639 + return COND_EXEC_CODE (new_pattern);
7640 + }
7641 + end_sequence ();
7642 + }
7643 +
7644 + if ( inputs_set_outside_ifblock )
7645 + {
7646 + /* Check if the insn before the cmp is an and which used
7647 + together with the cmp can be optimized into a bld. If
7648 + so then we should try to put the insn before the and
7649 + so that we can catch the bld peephole. */
7650 + rtx set;
7651 + rtx insn_before_cmp_insn = prev_nonnote_insn (cmp_insn);
7652 + if (insn_before_cmp_insn
7653 + && (set = single_set (insn_before_cmp_insn))
7654 + && GET_CODE (SET_SRC (set)) == AND
7655 + && one_bit_set_operand (XEXP (SET_SRC (set), 1), SImode)
7656 + /* Also make sure that the insn does not set any
7657 + of the input operands to the insn we are pulling out. */
7658 + && !reg_mentioned_p (SET_DEST (set), SET_SRC (op)) )
7659 + cmp_insn = prev_nonnote_insn (cmp_insn);
7660 +
7661 + /* We can try to put the operation outside the if-then-else
7662 + blocks and insert a move. */
7663 + if ( !insn_invalid_p (insn)
7664 + /* Do not allow conditional insns to be moved outside the
7665 + if-then-else. */
7666 + && !reg_mentioned_p (cc0_rtx, insn)
7667 + /* We cannot move memory loads outside of the if-then-else
7668 + since the memory access should not be perfomed if the
7669 + condition is not met. */
7670 + && !mem_mentioned_p (SET_SRC (op)) )
7671 + {
7672 + rtx scratch_reg = gen_reg_rtx (mode);
7673 + rtx op_pattern = copy_rtx (op);
7674 + rtx new_insn, seq;
7675 + rtx link, prev_link;
7676 + op = copy_rtx (op);
7677 + /* Emit the operation to a temp reg before the compare,
7678 + and emit a move inside the if-then-else, hoping that the
7679 + whole if-then-else can be converted to conditional
7680 + execution. */
7681 + SET_DEST (op_pattern) = scratch_reg;
7682 + start_sequence ();
7683 + new_insn = emit_insn (op_pattern);
7684 + seq = get_insns();
7685 + end_sequence ();
7686 +
7687 + /* Check again that the insn is valid. For some insns the insn might
7688 + become invalid if the destination register is changed. Ie. for mulacc
7689 + operations. */
7690 + if ( insn_invalid_p (new_insn) )
7691 + return NULL_RTX;
7692 +
7693 + emit_insn_before_setloc (seq, cmp_insn, INSN_LOCATOR (insn));
7694 +
7695 + if (dump_file)
7696 + fprintf (dump_file,
7697 + "\nMoving INSN %d out of IF-block by adding INSN %d...\n",
7698 + INSN_UID (insn), INSN_UID (new_insn));
7699 +
7700 + ce_info->extra_move_insns[ce_info->num_extra_move_insns] = insn;
7701 + ce_info->moved_insns[ce_info->num_extra_move_insns] = new_insn;
7702 + XEXP (op, 1) = scratch_reg;
7703 + /* Force the insn to be recognized again. */
7704 + INSN_CODE (insn) = -1;
7705 +
7706 + /* Move REG_DEAD notes to the moved insn. */
7707 + prev_link = NULL_RTX;
7708 + for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
7709 + {
7710 + if (REG_NOTE_KIND (link) == REG_DEAD)
7711 + {
7712 + /* Add the REG_DEAD note to the new insn. */
7713 + rtx dead_reg = XEXP (link, 0);
7714 + REG_NOTES (new_insn) = gen_rtx_EXPR_LIST (REG_DEAD, dead_reg, REG_NOTES (new_insn));
7715 + /* Remove the REG_DEAD note from the insn we convert to a move. */
7716 + if ( prev_link )
7717 + XEXP (prev_link, 1) = XEXP (link, 1);
7718 + else
7719 + REG_NOTES (insn) = XEXP (link, 1);
7720 + }
7721 + else
7722 + {
7723 + prev_link = link;
7724 + }
7725 + }
7726 + /* Add a REG_DEAD note to signal that the scratch register is dead. */
7727 + REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_DEAD, scratch_reg, REG_NOTES (insn));
7728 +
7729 + /* If this is the first change in this IF-block then
7730 + signal that we have made a change. */
7731 + if ( ce_info->num_cond_clobber_insns == 0
7732 + && ce_info->num_extra_move_insns == 0 )
7733 + *num_true_changes += 1;
7734 +
7735 + ce_info->num_extra_move_insns++;
7736 + return op;
7737 + }
7738 + }
7739 +
7740 + /* We failed to fixup the insns, so this if-then-else can not be made
7741 + conditional. Just return NULL_RTX so that the if-then-else conversion
7742 + for this if-then-else will be cancelled. */
7743 + return NULL_RTX;
7744 + }
7745 + end_sequence ();
7746 + return op;
7747 + }
7748 +
7749 + /* Signal that we have started if conversion after reload, which means
7750 + that it should be safe to split all the predicable clobber insns which
7751 + did not become cond_exec back into a simpler form if possible. */
7752 + cfun->machine->ifcvt_after_reload = 1;
7753 +
7754 + return pattern;
7755 +}
7756 +
7757 +
7758 +void
7759 +avr32_ifcvt_modify_cancel ( ce_if_block_t *ce_info, int *num_true_changes)
7760 +{
7761 + int n;
7762 +
7763 + if ( ce_info->num_extra_move_insns > 0
7764 + && ce_info->num_cond_clobber_insns == 0)
7765 + /* Signal that we did not do any changes after all. */
7766 + *num_true_changes -= 1;
7767 +
7768 + /* Remove any inserted move insns. */
7769 + for ( n = 0; n < ce_info->num_extra_move_insns; n++ )
7770 + {
7771 + rtx link, prev_link;
7772 +
7773 + /* Remove REG_DEAD note since we are not needing the scratch register anyway. */
7774 + prev_link = NULL_RTX;
7775 + for (link = REG_NOTES (ce_info->extra_move_insns[n]); link; link = XEXP (link, 1))
7776 + {
7777 + if (REG_NOTE_KIND (link) == REG_DEAD)
7778 + {
7779 + if ( prev_link )
7780 + XEXP (prev_link, 1) = XEXP (link, 1);
7781 + else
7782 + REG_NOTES (ce_info->extra_move_insns[n]) = XEXP (link, 1);
7783 + }
7784 + else
7785 + {
7786 + prev_link = link;
7787 + }
7788 + }
7789 +
7790 + /* Revert all reg_notes for the moved insn. */
7791 + for (link = REG_NOTES (ce_info->moved_insns[n]); link; link = XEXP (link, 1))
7792 + {
7793 + REG_NOTES (ce_info->extra_move_insns[n]) = gen_rtx_EXPR_LIST (REG_NOTE_KIND (link),
7794 + XEXP (link, 0),
7795 + REG_NOTES (ce_info->extra_move_insns[n]));
7796 + }
7797 +
7798 + /* Remove the moved insn. */
7799 + remove_insn ( ce_info->moved_insns[n] );
7800 + }
7801 +}
7802 +
7803 +
7804 +/* Function returning TRUE if INSN with OPERANDS is a splittable
7805 + conditional immediate clobber insn. We assume that the insn is
7806 + already a conditional immediate clobber insns and do not check
7807 + for that. */
7808 +int
7809 +avr32_cond_imm_clobber_splittable (rtx insn, rtx operands[])
7810 +{
7811 + if ( REGNO (operands[0]) == REGNO (operands[1]) )
7812 + {
7813 + if ( (GET_CODE (SET_SRC (XVECEXP (PATTERN (insn),0,0))) == PLUS
7814 + && !avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'I', "Is21"))
7815 + || (GET_CODE (SET_SRC (XVECEXP (PATTERN (insn),0,0))) == MINUS
7816 + && !avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks21")))
7817 + return FALSE;
7818 + }
7819 + else if ( (logical_binary_operator (SET_SRC (XVECEXP (PATTERN (insn),0,0)), VOIDmode)
7820 + || (GET_CODE (SET_SRC (XVECEXP (PATTERN (insn),0,0))) == PLUS
7821 + && !avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'I', "Is16"))
7822 + || (GET_CODE (SET_SRC (XVECEXP (PATTERN (insn),0,0))) == MINUS
7823 + && !avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks16"))) )
7824 + return FALSE;
7825 +
7826 + return TRUE;
7827 +}
7828 +
7829 +
7830 +/* Function for getting an integer value from a const_int or const_double
7831 + expression regardless of the HOST_WIDE_INT size. Each target cpu word
7832 + will be put into the val array where the LSW will be stored at the lowest
7833 + address and so forth. Assumes that const_expr is either a const_int or
7834 + const_double. Only valid for modes which have sizes that are a multiple
7835 + of the word size.
7836 +*/
7837 +void
7838 +avr32_get_intval (enum machine_mode mode, rtx const_expr, HOST_WIDE_INT *val)
7839 +{
7840 + int words_in_mode = GET_MODE_SIZE (mode)/UNITS_PER_WORD;
7841 + const int words_in_const_int = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
7842 +
7843 + if ( GET_CODE(const_expr) == CONST_DOUBLE ){
7844 + HOST_WIDE_INT hi = CONST_DOUBLE_HIGH(const_expr);
7845 + HOST_WIDE_INT lo = CONST_DOUBLE_LOW(const_expr);
7846 + /* Evaluate hi and lo values of const_double. */
7847 + avr32_get_intval (mode_for_size (HOST_BITS_PER_WIDE_INT, MODE_INT, 0),
7848 + GEN_INT (lo),
7849 + &val[0]);
7850 + avr32_get_intval (mode_for_size (HOST_BITS_PER_WIDE_INT, MODE_INT, 0),
7851 + GEN_INT (hi),
7852 + &val[words_in_const_int]);
7853 + } else if ( GET_CODE(const_expr) == CONST_INT ){
7854 + HOST_WIDE_INT value = INTVAL(const_expr);
7855 + int word;
7856 + for ( word = 0; (word < words_in_mode) && (word < words_in_const_int); word++ ){
7857 + /* Shift word up to the MSW and shift down again to extract the
7858 + word and sign-extend. */
7859 + int lshift = (words_in_const_int - word - 1) * BITS_PER_WORD;
7860 + int rshift = (words_in_const_int-1) * BITS_PER_WORD;
7861 + val[word] = (value << lshift) >> rshift;
7862 + }
7863 +
7864 + for ( ; word < words_in_mode; word++ ){
7865 + /* Just put the sign bits in the remaining words. */
7866 + val[word] = value < 0 ? -1 : 0;
7867 + }
7868 + }
7869 +}
7870 +
7871 +
7872 +void
7873 +avr32_split_const_expr (enum machine_mode mode, enum machine_mode new_mode,
7874 + rtx expr, rtx *split_expr)
7875 +{
7876 + int i, word;
7877 + int words_in_intval = GET_MODE_SIZE (mode)/UNITS_PER_WORD;
7878 + int words_in_split_values = GET_MODE_SIZE (new_mode)/UNITS_PER_WORD;
7879 + const int words_in_const_int = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
7880 + HOST_WIDE_INT *val = alloca (words_in_intval * UNITS_PER_WORD);
7881 +
7882 + avr32_get_intval (mode, expr, val);
7883 +
7884 + for ( i=0; i < (words_in_intval/words_in_split_values); i++ )
7885 + {
7886 + HOST_WIDE_INT value_lo = 0, value_hi = 0;
7887 + for ( word = 0; word < words_in_split_values; word++ )
7888 + {
7889 + if ( word >= words_in_const_int )
7890 + value_hi |= ((val[i * words_in_split_values + word] &
7891 + (((HOST_WIDE_INT)1 << BITS_PER_WORD)-1))
7892 + << (BITS_PER_WORD * (word - words_in_const_int)));
7893 + else
7894 + value_lo |= ((val[i * words_in_split_values + word] &
7895 + (((HOST_WIDE_INT)1 << BITS_PER_WORD)-1))
7896 + << (BITS_PER_WORD * word));
7897 + }
7898 + split_expr[i] = immed_double_const(value_lo, value_hi, new_mode);
7899 + }
7900 +}
7901 +
7902 +
7903 +/* Set up library functions to comply to AVR32 ABI */
7904 +static void
7905 +avr32_init_libfuncs (void)
7906 +{
7907 + /* Convert gcc run-time function names to AVR32 ABI names */
7908 +
7909 + /* Double-precision floating-point arithmetic. */
7910 + set_optab_libfunc (neg_optab, DFmode, NULL);
7911 +
7912 + /* Double-precision comparisons. */
7913 + set_optab_libfunc (eq_optab, DFmode, "__avr32_f64_cmp_eq");
7914 + set_optab_libfunc (ne_optab, DFmode, NULL);
7915 + set_optab_libfunc (lt_optab, DFmode, "__avr32_f64_cmp_lt");
7916 + set_optab_libfunc (le_optab, DFmode, NULL);
7917 + set_optab_libfunc (ge_optab, DFmode, "__avr32_f64_cmp_ge");
7918 + set_optab_libfunc (gt_optab, DFmode, NULL);
7919 +
7920 + /* Single-precision floating-point arithmetic. */
7921 + set_optab_libfunc (smul_optab, SFmode, "__avr32_f32_mul");
7922 + set_optab_libfunc (neg_optab, SFmode, NULL);
7923 +
7924 + /* Single-precision comparisons. */
7925 + set_optab_libfunc (eq_optab, SFmode, "__avr32_f32_cmp_eq");
7926 + set_optab_libfunc (ne_optab, SFmode, NULL);
7927 + set_optab_libfunc (lt_optab, SFmode, "__avr32_f32_cmp_lt");
7928 + set_optab_libfunc (le_optab, SFmode, NULL);
7929 + set_optab_libfunc (ge_optab, SFmode, "__avr32_f32_cmp_ge");
7930 + set_optab_libfunc (gt_optab, SFmode, NULL);
7931 +
7932 + /* Floating-point to integer conversions. */
7933 + set_conv_libfunc (sfix_optab, SImode, DFmode, "__avr32_f64_to_s32");
7934 + set_conv_libfunc (ufix_optab, SImode, DFmode, "__avr32_f64_to_u32");
7935 + set_conv_libfunc (sfix_optab, DImode, DFmode, "__avr32_f64_to_s64");
7936 + set_conv_libfunc (ufix_optab, DImode, DFmode, "__avr32_f64_to_u64");
7937 + set_conv_libfunc (sfix_optab, SImode, SFmode, "__avr32_f32_to_s32");
7938 + set_conv_libfunc (ufix_optab, SImode, SFmode, "__avr32_f32_to_u32");
7939 + set_conv_libfunc (sfix_optab, DImode, SFmode, "__avr32_f32_to_s64");
7940 + set_conv_libfunc (ufix_optab, DImode, SFmode, "__avr32_f32_to_u64");
7941 +
7942 + /* Conversions between floating types. */
7943 + set_conv_libfunc (trunc_optab, SFmode, DFmode, "__avr32_f64_to_f32");
7944 + set_conv_libfunc (sext_optab, DFmode, SFmode, "__avr32_f32_to_f64");
7945 +
7946 + /* Integer to floating-point conversions. Table 8. */
7947 + set_conv_libfunc (sfloat_optab, DFmode, SImode, "__avr32_s32_to_f64");
7948 + set_conv_libfunc (sfloat_optab, DFmode, DImode, "__avr32_s64_to_f64");
7949 + set_conv_libfunc (sfloat_optab, SFmode, SImode, "__avr32_s32_to_f32");
7950 + set_conv_libfunc (sfloat_optab, SFmode, DImode, "__avr32_s64_to_f32");
7951 + set_conv_libfunc (ufloat_optab, DFmode, SImode, "__avr32_u32_to_f64");
7952 + set_conv_libfunc (ufloat_optab, SFmode, SImode, "__avr32_u32_to_f32");
7953 + /* TODO: Add these to gcc library functions */
7954 + //set_conv_libfunc (ufloat_optab, DFmode, DImode, NULL);
7955 + //set_conv_libfunc (ufloat_optab, SFmode, DImode, NULL);
7956 +
7957 + /* Long long. Table 9. */
7958 + set_optab_libfunc (smul_optab, DImode, "__avr32_mul64");
7959 + set_optab_libfunc (sdiv_optab, DImode, "__avr32_sdiv64");
7960 + set_optab_libfunc (udiv_optab, DImode, "__avr32_udiv64");
7961 + set_optab_libfunc (smod_optab, DImode, "__avr32_smod64");
7962 + set_optab_libfunc (umod_optab, DImode, "__avr32_umod64");
7963 + set_optab_libfunc (ashl_optab, DImode, "__avr32_lsl64");
7964 + set_optab_libfunc (lshr_optab, DImode, "__avr32_lsr64");
7965 + set_optab_libfunc (ashr_optab, DImode, "__avr32_asr64");
7966 +
7967 + /* Floating point library functions which have fast versions. */
7968 + if ( TARGET_FAST_FLOAT )
7969 + {
7970 + set_optab_libfunc (sdiv_optab, DFmode, "__avr32_f64_div_fast");
7971 + set_optab_libfunc (smul_optab, DFmode, "__avr32_f64_mul_fast");
7972 + set_optab_libfunc (add_optab, DFmode, "__avr32_f64_add_fast");
7973 + set_optab_libfunc (sub_optab, DFmode, "__avr32_f64_sub_fast");
7974 + set_optab_libfunc (add_optab, SFmode, "__avr32_f32_add_fast");
7975 + set_optab_libfunc (sub_optab, SFmode, "__avr32_f32_sub_fast");
7976 + set_optab_libfunc (sdiv_optab, SFmode, "__avr32_f32_div_fast");
7977 + }
7978 + else
7979 + {
7980 + set_optab_libfunc (sdiv_optab, DFmode, "__avr32_f64_div");
7981 + set_optab_libfunc (smul_optab, DFmode, "__avr32_f64_mul");
7982 + set_optab_libfunc (add_optab, DFmode, "__avr32_f64_add");
7983 + set_optab_libfunc (sub_optab, DFmode, "__avr32_f64_sub");
7984 + set_optab_libfunc (add_optab, SFmode, "__avr32_f32_add");
7985 + set_optab_libfunc (sub_optab, SFmode, "__avr32_f32_sub");
7986 + set_optab_libfunc (sdiv_optab, SFmode, "__avr32_f32_div");
7987 + }
7988 +}
7989 +
7990 +
7991 +/* Record a flashvault declaration. */
7992 +static void
7993 +flashvault_decl_list_add (unsigned int vector_num, const char *name)
7994 +{
7995 + struct flashvault_decl_list *p;
7996 +
7997 + p = (struct flashvault_decl_list *)
7998 + xmalloc (sizeof (struct flashvault_decl_list));
7999 + p->next = flashvault_decl_list_head;
8000 + p->name = name;
8001 + p->vector_num = vector_num;
8002 + flashvault_decl_list_head = p;
8003 +}
8004 +
8005 +
8006 +static void
8007 +avr32_file_end (void)
8008 +{
8009 + struct flashvault_decl_list *p;
8010 + unsigned int num_entries = 0;
8011 +
8012 + /* Check if a list of flashvault declarations exists. */
8013 + if (flashvault_decl_list_head != NULL)
8014 + {
8015 + /* Calculate the number of entries in the table. */
8016 + for (p = flashvault_decl_list_head; p != NULL; p = p->next)
8017 + {
8018 + num_entries++;
8019 + }
8020 +
8021 + /* Generate the beginning of the flashvault data table. */
8022 + fputs ("\t.global __fv_table\n"
8023 + "\t.data\n"
8024 + "\t.align 2\n"
8025 + "\t.set .LFVTABLE, . + 0\n"
8026 + "\t.type __fv_table, @object\n", asm_out_file);
8027 + /* Each table entry is 8 bytes. */
8028 + fprintf (asm_out_file, "\t.size __fv_table, %u\n", (num_entries * 8));
8029 +
8030 + fputs("__fv_table:\n", asm_out_file);
8031 +
8032 + for (p = flashvault_decl_list_head; p != NULL; p = p->next)
8033 + {
8034 + /* Output table entry. */
8035 + fprintf (asm_out_file,
8036 + "\t.align 2\n"
8037 + "\t.int %u\n", p->vector_num);
8038 + fprintf (asm_out_file,
8039 + "\t.align 2\n"
8040 + "\t.int %s\n", p->name);
8041 + }
8042 + }
8043 +}
8044 --- /dev/null
8045 +++ b/gcc/config/avr32/avr32-elf.h
8046 @@ -0,0 +1,91 @@
8047 +/*
8048 + Elf specific definitions.
8049 + Copyright 2003,2004,2005,2006,2007,2008,2009 Atmel Corporation.
8050 +
8051 + This file is part of GCC.
8052 +
8053 + This program is free software; you can redistribute it and/or modify
8054 + it under the terms of the GNU General Public License as published by
8055 + the Free Software Foundation; either version 2 of the License, or
8056 + (at your option) any later version.
8057 +
8058 + This program is distributed in the hope that it will be useful,
8059 + but WITHOUT ANY WARRANTY; without even the implied warranty of
8060 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8061 + GNU General Public License for more details.
8062 +
8063 + You should have received a copy of the GNU General Public License
8064 + along with this program; if not, write to the Free Software
8065 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
8066 +
8067 +
8068 +/*****************************************************************************
8069 + * Controlling the Compiler Driver, 'gcc'
8070 + *****************************************************************************/
8071 +
8072 +/* Run-time Target Specification. */
8073 +#undef TARGET_VERSION
8074 +#define TARGET_VERSION fputs (" (AVR32 GNU with ELF)", stderr);
8075 +
8076 +/*
8077 +Another C string constant used much like LINK_SPEC. The
8078 +difference between the two is that STARTFILE_SPEC is used at
8079 +the very beginning of the command given to the linker.
8080 +
8081 +If this macro is not defined, a default is provided that loads the
8082 +standard C startup file from the usual place. See gcc.c.
8083 +*/
8084 +#if 0
8085 +#undef STARTFILE_SPEC
8086 +#define STARTFILE_SPEC "crt0%O%s crti%O%s crtbegin%O%s"
8087 +#endif
8088 +#undef STARTFILE_SPEC
8089 +#define STARTFILE_SPEC "%{mflashvault: crtfv.o%s} %{!mflashvault: crt0.o%s} \
8090 + crti.o%s crtbegin.o%s"
8091 +
8092 +#undef LINK_SPEC
8093 +#define LINK_SPEC "%{muse-oscall:--defsym __do_not_use_oscall_coproc__=0} %{mrelax|O*:%{mno-relax|O0|O1: ;:--relax}} %{mpart=uc3a3revd:-mavr32elf_uc3a3256s;:%{mpart=*:-mavr32elf_%*}} %{mcpu=*:-mavr32elf_%*}"
8094 +
8095 +
8096 +/*
8097 +Another C string constant used much like LINK_SPEC. The
8098 +difference between the two is that ENDFILE_SPEC is used at
8099 +the very end of the command given to the linker.
8100 +
8101 +Do not define this macro if it does not need to do anything.
8102 +*/
8103 +#undef ENDFILE_SPEC
8104 +#define ENDFILE_SPEC "crtend%O%s crtn%O%s"
8105 +
8106 +
8107 +/* Target CPU builtins. */
8108 +#define TARGET_CPU_CPP_BUILTINS() \
8109 + do \
8110 + { \
8111 + builtin_define ("__avr32__"); \
8112 + builtin_define ("__AVR32__"); \
8113 + builtin_define ("__AVR32_ELF__"); \
8114 + builtin_define (avr32_part->macro); \
8115 + builtin_define (avr32_arch->macro); \
8116 + if (avr32_arch->uarch_type == UARCH_TYPE_AVR32A) \
8117 + builtin_define ("__AVR32_AVR32A__"); \
8118 + else \
8119 + builtin_define ("__AVR32_AVR32B__"); \
8120 + if (TARGET_UNALIGNED_WORD) \
8121 + builtin_define ("__AVR32_HAS_UNALIGNED_WORD__"); \
8122 + if (TARGET_SIMD) \
8123 + builtin_define ("__AVR32_HAS_SIMD__"); \
8124 + if (TARGET_DSP) \
8125 + builtin_define ("__AVR32_HAS_DSP__"); \
8126 + if (TARGET_RMW) \
8127 + builtin_define ("__AVR32_HAS_RMW__"); \
8128 + if (TARGET_BRANCH_PRED) \
8129 + builtin_define ("__AVR32_HAS_BRANCH_PRED__"); \
8130 + if (TARGET_FAST_FLOAT) \
8131 + builtin_define ("__AVR32_FAST_FLOAT__"); \
8132 + if (TARGET_FLASHVAULT) \
8133 + builtin_define ("__AVR32_FLASHVAULT__"); \
8134 + if (TARGET_NO_MUL_INSNS) \
8135 + builtin_define ("__AVR32_NO_MUL__"); \
8136 + } \
8137 + while (0)
8138 --- /dev/null
8139 +++ b/gcc/config/avr32/avr32.h
8140 @@ -0,0 +1,3274 @@
8141 +/*
8142 + Definitions of target machine for AVR32.
8143 + Copyright 2003,2004,2005,2006,2007,2008,2009,2010 Atmel Corporation.
8144 +
8145 + This file is part of GCC.
8146 +
8147 + This program is free software; you can redistribute it and/or modify
8148 + it under the terms of the GNU General Public License as published by
8149 + the Free Software Foundation; either version 2 of the License, or
8150 + (at your option) any later version.
8151 +
8152 + This program is distributed in the hope that it will be useful,
8153 + but WITHOUT ANY WARRANTY; without even the implied warranty of
8154 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8155 + GNU General Public License for more details.
8156 +
8157 + You should have received a copy of the GNU General Public License
8158 + along with this program; if not, write to the Free Software
8159 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
8160 +
8161 +#ifndef GCC_AVR32_H
8162 +#define GCC_AVR32_H
8163 +
8164 +
8165 +#ifndef OBJECT_FORMAT_ELF
8166 +#error avr32.h included before elfos.h
8167 +#endif
8168 +
8169 +#ifndef LOCAL_LABEL_PREFIX
8170 +#define LOCAL_LABEL_PREFIX "."
8171 +#endif
8172 +
8173 +#ifndef SUBTARGET_CPP_SPEC
8174 +#define SUBTARGET_CPP_SPEC "-D__ELF__"
8175 +#endif
8176 +
8177 +
8178 +extern struct rtx_def *avr32_compare_op0;
8179 +extern struct rtx_def *avr32_compare_op1;
8180 +
8181 +
8182 +extern struct rtx_def *avr32_acc_cache;
8183 +
8184 +/* cache instruction op5 codes */
8185 +#define AVR32_CACHE_INVALIDATE_ICACHE 1
8186 +
8187 +/*
8188 +These bits describe the different types of function supported by the AVR32
8189 +backend. They are exclusive, e.g. a function cannot be both a normal function
8190 +and an interworked function. Knowing the type of a function is important for
8191 +determining its prologue and epilogue sequences. Note value 7 is currently
8192 +unassigned. Also note that the interrupt function types all have bit 2 set,
8193 +so that they can be tested for easily. Note that 0 is deliberately chosen for
8194 +AVR32_FT_UNKNOWN so that when the machine_function structure is initialized
8195 +(to zero) func_type will default to unknown. This will force the first use of
8196 +avr32_current_func_type to call avr32_compute_func_type.
8197 +*/
8198 +#define AVR32_FT_UNKNOWN 0 /* Type has not yet been determined. */
8199 +#define AVR32_FT_NORMAL 1 /* Normal function. */
8200 +#define AVR32_FT_ACALL 2 /* An acall function. */
8201 +#define AVR32_FT_EXCEPTION_HANDLER 3 /* A C++ exception handler. */
8202 +#define AVR32_FT_ISR_FULL 4 /* A fully shadowed interrupt mode. */
8203 +#define AVR32_FT_ISR_HALF 5 /* A half shadowed interrupt mode. */
8204 +#define AVR32_FT_ISR_NONE 6 /* No shadow registers. */
8205 +
8206 +#define AVR32_FT_TYPE_MASK ((1 << 3) - 1)
8207 +
8208 +/* In addition functions can have several type modifiers, outlined by these bit masks: */
8209 +#define AVR32_FT_INTERRUPT (1 << 2) /* Note overlap with FT_ISR and above. */
8210 +#define AVR32_FT_NAKED (1 << 3) /* No prologue or epilogue. */
8211 +#define AVR32_FT_VOLATILE (1 << 4) /* Does not return. */
8212 +#define AVR32_FT_NESTED (1 << 5) /* Embedded inside another func. */
8213 +#define AVR32_FT_FLASHVAULT (1 << 6) /* Flashvault function call. */
8214 +#define AVR32_FT_FLASHVAULT_IMPL (1 << 7) /* Function definition in FlashVault. */
8215 +
8216 +
8217 +/* Some macros to test these flags. */
8218 +#define AVR32_FUNC_TYPE(t) (t & AVR32_FT_TYPE_MASK)
8219 +#define IS_INTERRUPT(t) (t & AVR32_FT_INTERRUPT)
8220 +#define IS_NAKED(t) (t & AVR32_FT_NAKED)
8221 +#define IS_VOLATILE(t) (t & AVR32_FT_VOLATILE)
8222 +#define IS_NESTED(t) (t & AVR32_FT_NESTED)
8223 +#define IS_FLASHVAULT(t) (t & AVR32_FT_FLASHVAULT)
8224 +#define IS_FLASHVAULT_IMPL(t) (t & AVR32_FT_FLASHVAULT_IMPL)
8225 +
8226 +#define SYMBOL_FLAG_RMW_ADDR_SHIFT SYMBOL_FLAG_MACH_DEP_SHIFT
8227 +#define SYMBOL_REF_RMW_ADDR(RTX) \
8228 + ((SYMBOL_REF_FLAGS (RTX) & (1 << SYMBOL_FLAG_RMW_ADDR_SHIFT)) != 0)
8229 +
8230 +
8231 +typedef struct minipool_labels
8232 +GTY ((chain_next ("%h.next"), chain_prev ("%h.prev")))
8233 +{
8234 + rtx label;
8235 + struct minipool_labels *prev;
8236 + struct minipool_labels *next;
8237 +} minipool_labels;
8238 +
8239 +/* A C structure for machine-specific, per-function data.
8240 + This is added to the cfun structure. */
8241 +
8242 +typedef struct machine_function
8243 +GTY (())
8244 +{
8245 + /* Records the type of the current function. */
8246 + unsigned long func_type;
8247 + /* List of minipool labels, use for checking if code label is valid in a
8248 + memory expression */
8249 + minipool_labels *minipool_label_head;
8250 + minipool_labels *minipool_label_tail;
8251 + int ifcvt_after_reload;
8252 +} machine_function;
8253 +
8254 +/* Initialize data used by insn expanders. This is called from insn_emit,
8255 + once for every function before code is generated. */
8256 +#define INIT_EXPANDERS avr32_init_expanders ()
8257 +
8258 +/******************************************************************************
8259 + * SPECS
8260 + *****************************************************************************/
8261 +
8262 +#ifndef ASM_SPEC
8263 +#define ASM_SPEC "%{fpic:--pic} %{mrelax|O*:%{mno-relax|O0|O1: ;:--linkrelax}} %{march=ucr2nomul:-march=ucr2;:%{march=*:-march=%*}} %{mpart=uc3a3revd:-mpart=uc3a3256s;:%{mpart=*:-mpart=%*}}"
8264 +#endif
8265 +
8266 +#ifndef MULTILIB_DEFAULTS
8267 +#define MULTILIB_DEFAULTS { "march=ap", "" }
8268 +#endif
8269 +
8270 +/******************************************************************************
8271 + * Run-time Target Specification
8272 + *****************************************************************************/
8273 +#ifndef TARGET_VERSION
8274 +#define TARGET_VERSION fprintf(stderr, " (AVR32, GNU assembler syntax)");
8275 +#endif
8276 +
8277 +
8278 +/* Part types. Keep this in sync with the order of avr32_part_types in avr32.c*/
8279 +enum part_type
8280 +{
8281 + PART_TYPE_AVR32_NONE,
8282 + PART_TYPE_AVR32_AP7000,
8283 + PART_TYPE_AVR32_AP7001,
8284 + PART_TYPE_AVR32_AP7002,
8285 + PART_TYPE_AVR32_AP7200,
8286 + PART_TYPE_AVR32_UC3A0128,
8287 + PART_TYPE_AVR32_UC3A0256,
8288 + PART_TYPE_AVR32_UC3A0512,
8289 + PART_TYPE_AVR32_UC3A0512ES,
8290 + PART_TYPE_AVR32_UC3A1128,
8291 + PART_TYPE_AVR32_UC3A1256,
8292 + PART_TYPE_AVR32_UC3A1512,
8293 + PART_TYPE_AVR32_UC3A1512ES,
8294 + PART_TYPE_AVR32_UC3A3REVD,
8295 + PART_TYPE_AVR32_UC3A364,
8296 + PART_TYPE_AVR32_UC3A364S,
8297 + PART_TYPE_AVR32_UC3A3128,
8298 + PART_TYPE_AVR32_UC3A3128S,
8299 + PART_TYPE_AVR32_UC3A3256,
8300 + PART_TYPE_AVR32_UC3A3256S,
8301 + PART_TYPE_AVR32_UC3B064,
8302 + PART_TYPE_AVR32_UC3B0128,
8303 + PART_TYPE_AVR32_UC3B0256,
8304 + PART_TYPE_AVR32_UC3B0256ES,
8305 + PART_TYPE_AVR32_UC3B0512,
8306 + PART_TYPE_AVR32_UC3B0512REVC,
8307 + PART_TYPE_AVR32_UC3B164,
8308 + PART_TYPE_AVR32_UC3B1128,
8309 + PART_TYPE_AVR32_UC3B1256,
8310 + PART_TYPE_AVR32_UC3B1256ES,
8311 + PART_TYPE_AVR32_UC3B1512,
8312 + PART_TYPE_AVR32_UC3B1512REVC,
8313 + PART_TYPE_AVR32_UC3C0512CREVC,
8314 + PART_TYPE_AVR32_UC3C1512CREVC,
8315 + PART_TYPE_AVR32_UC3C2512CREVC,
8316 + PART_TYPE_AVR32_UC3L0256,
8317 + PART_TYPE_AVR32_UC3L0128,
8318 + PART_TYPE_AVR32_UC3L064,
8319 + PART_TYPE_AVR32_UC3L032,
8320 + PART_TYPE_AVR32_UC3L016,
8321 + PART_TYPE_AVR32_UC3C064C,
8322 + PART_TYPE_AVR32_UC3C0128C,
8323 + PART_TYPE_AVR32_UC3C0256C,
8324 + PART_TYPE_AVR32_UC3C0512C,
8325 + PART_TYPE_AVR32_UC3C164C,
8326 + PART_TYPE_AVR32_UC3C1128C,
8327 + PART_TYPE_AVR32_UC3C1256C,
8328 + PART_TYPE_AVR32_UC3C1512C,
8329 + PART_TYPE_AVR32_UC3C264C,
8330 + PART_TYPE_AVR32_UC3C2128C,
8331 + PART_TYPE_AVR32_UC3C2256C,
8332 + PART_TYPE_AVR32_UC3C2512C,
8333 + PART_TYPE_AVR32_MXT768E
8334 +};
8335 +
8336 +/* Microarchitectures. */
8337 +enum microarchitecture_type
8338 +{
8339 + UARCH_TYPE_AVR32A,
8340 + UARCH_TYPE_AVR32B,
8341 + UARCH_TYPE_NONE
8342 +};
8343 +
8344 +/* Architectures types which specifies the pipeline.
8345 + Keep this in sync with avr32_arch_types in avr32.c
8346 + and the pipeline attribute in avr32.md */
8347 +enum architecture_type
8348 +{
8349 + ARCH_TYPE_AVR32_AP,
8350 + ARCH_TYPE_AVR32_UCR1,
8351 + ARCH_TYPE_AVR32_UCR2,
8352 + ARCH_TYPE_AVR32_UCR2NOMUL,
8353 + ARCH_TYPE_AVR32_UCR3,
8354 + ARCH_TYPE_AVR32_UCR3FP,
8355 + ARCH_TYPE_AVR32_NONE
8356 +};
8357 +
8358 +/* Flag specifying if the cpu has support for DSP instructions.*/
8359 +#define FLAG_AVR32_HAS_DSP (1 << 0)
8360 +/* Flag specifying if the cpu has support for Read-Modify-Write
8361 + instructions.*/
8362 +#define FLAG_AVR32_HAS_RMW (1 << 1)
8363 +/* Flag specifying if the cpu has support for SIMD instructions. */
8364 +#define FLAG_AVR32_HAS_SIMD (1 << 2)
8365 +/* Flag specifying if the cpu has support for unaligned memory word access. */
8366 +#define FLAG_AVR32_HAS_UNALIGNED_WORD (1 << 3)
8367 +/* Flag specifying if the cpu has support for branch prediction. */
8368 +#define FLAG_AVR32_HAS_BRANCH_PRED (1 << 4)
8369 +/* Flag specifying if the cpu has support for a return stack. */
8370 +#define FLAG_AVR32_HAS_RETURN_STACK (1 << 5)
8371 +/* Flag specifying if the cpu has caches. */
8372 +#define FLAG_AVR32_HAS_CACHES (1 << 6)
8373 +/* Flag specifying if the cpu has support for v2 insns. */
8374 +#define FLAG_AVR32_HAS_V2_INSNS (1 << 7)
8375 +/* Flag specifying that the cpu has buggy mul insns. */
8376 +#define FLAG_AVR32_HAS_NO_MUL_INSNS (1 << 8)
8377 +/* Flag specifying that the device has FPU instructions according
8378 + to AVR32002 specifications*/
8379 +#define FLAG_AVR32_HAS_FPU (1 << 9)
8380 +
8381 +/* Structure for holding information about different avr32 CPUs/parts */
8382 +struct part_type_s
8383 +{
8384 + const char *const name;
8385 + enum part_type part_type;
8386 + enum architecture_type arch_type;
8387 + /* Must lie outside user's namespace. NULL == no macro. */
8388 + const char *const macro;
8389 +};
8390 +
8391 +/* Structure for holding information about different avr32 pipeline
8392 + architectures. */
8393 +struct arch_type_s
8394 +{
8395 + const char *const name;
8396 + enum architecture_type arch_type;
8397 + enum microarchitecture_type uarch_type;
8398 + const unsigned long feature_flags;
8399 + /* Must lie outside user's namespace. NULL == no macro. */
8400 + const char *const macro;
8401 +};
8402 +
8403 +extern const struct part_type_s *avr32_part;
8404 +extern const struct arch_type_s *avr32_arch;
8405 +
8406 +#define TARGET_SIMD (avr32_arch->feature_flags & FLAG_AVR32_HAS_SIMD)
8407 +#define TARGET_DSP (avr32_arch->feature_flags & FLAG_AVR32_HAS_DSP)
8408 +#define TARGET_RMW (avr32_arch->feature_flags & FLAG_AVR32_HAS_RMW)
8409 +#define TARGET_UNALIGNED_WORD (avr32_arch->feature_flags & FLAG_AVR32_HAS_UNALIGNED_WORD)
8410 +#define TARGET_BRANCH_PRED (avr32_arch->feature_flags & FLAG_AVR32_HAS_BRANCH_PRED)
8411 +#define TARGET_RETURN_STACK (avr32_arch->feature_flags & FLAG_AVR32_HAS_RETURN_STACK)
8412 +#define TARGET_V2_INSNS (avr32_arch->feature_flags & FLAG_AVR32_HAS_V2_INSNS)
8413 +#define TARGET_CACHES (avr32_arch->feature_flags & FLAG_AVR32_HAS_CACHES)
8414 +#define TARGET_NO_MUL_INSNS (avr32_arch->feature_flags & FLAG_AVR32_HAS_NO_MUL_INSNS)
8415 +#define TARGET_ARCH_AP (avr32_arch->arch_type == ARCH_TYPE_AVR32_AP)
8416 +#define TARGET_ARCH_UCR1 (avr32_arch->arch_type == ARCH_TYPE_AVR32_UCR1)
8417 +#define TARGET_ARCH_UCR2 (avr32_arch->arch_type == ARCH_TYPE_AVR32_UCR2)
8418 +#define TARGET_ARCH_UC (TARGET_ARCH_UCR1 || TARGET_ARCH_UCR2)
8419 +#define TARGET_UARCH_AVR32A (avr32_arch->uarch_type == UARCH_TYPE_AVR32A)
8420 +#define TARGET_UARCH_AVR32B (avr32_arch->uarch_type == UARCH_TYPE_AVR32B)
8421 +#define TARGET_ARCH_FPU (avr32_arch->feature_flags & FLAG_AVR32_HAS_FPU)
8422 +
8423 +#define CAN_DEBUG_WITHOUT_FP
8424 +
8425 +
8426 +
8427 +
8428 +/******************************************************************************
8429 + * Storage Layout
8430 + *****************************************************************************/
8431 +
8432 +/*
8433 +Define this macro to have the value 1 if the most significant bit in a
8434 +byte has the lowest number; otherwise define it to have the value zero.
8435 +This means that bit-field instructions count from the most significant
8436 +bit. If the machine has no bit-field instructions, then this must still
8437 +be defined, but it doesn't matter which value it is defined to. This
8438 +macro need not be a constant.
8439 +
8440 +This macro does not affect the way structure fields are packed into
8441 +bytes or words; that is controlled by BYTES_BIG_ENDIAN.
8442 +*/
8443 +#define BITS_BIG_ENDIAN 0
8444 +
8445 +/*
8446 +Define this macro to have the value 1 if the most significant byte in a
8447 +word has the lowest number. This macro need not be a constant.
8448 +*/
8449 +/*
8450 + Data is stored in an big-endian way.
8451 +*/
8452 +#define BYTES_BIG_ENDIAN 1
8453 +
8454 +/*
8455 +Define this macro to have the value 1 if, in a multiword object, the
8456 +most significant word has the lowest number. This applies to both
8457 +memory locations and registers; GCC fundamentally assumes that the
8458 +order of words in memory is the same as the order in registers. This
8459 +macro need not be a constant.
8460 +*/
8461 +/*
8462 + Data is stored in an bin-endian way.
8463 +*/
8464 +#define WORDS_BIG_ENDIAN 1
8465 +
8466 +/*
8467 +Define this macro if WORDS_BIG_ENDIAN is not constant. This must be a
8468 +constant value with the same meaning as WORDS_BIG_ENDIAN, which will be
8469 +used only when compiling libgcc2.c. Typically the value will be set
8470 +based on preprocessor defines.
8471 +*/
8472 +#define LIBGCC2_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
8473 +
8474 +/*
8475 +Define this macro to have the value 1 if DFmode, XFmode or
8476 +TFmode floating point numbers are stored in memory with the word
8477 +containing the sign bit at the lowest address; otherwise define it to
8478 +have the value 0. This macro need not be a constant.
8479 +
8480 +You need not define this macro if the ordering is the same as for
8481 +multi-word integers.
8482 +*/
8483 +/* #define FLOAT_WORDS_BIG_ENDIAN 1 */
8484 +
8485 +/*
8486 +Define this macro to be the number of bits in an addressable storage
8487 +unit (byte); normally 8.
8488 +*/
8489 +#define BITS_PER_UNIT 8
8490 +
8491 +/*
8492 +Number of bits in a word; normally 32.
8493 +*/
8494 +#define BITS_PER_WORD 32
8495 +
8496 +/*
8497 +Maximum number of bits in a word. If this is undefined, the default is
8498 +BITS_PER_WORD. Otherwise, it is the constant value that is the
8499 +largest value that BITS_PER_WORD can have at run-time.
8500 +*/
8501 +/* MAX_BITS_PER_WORD not defined*/
8502 +
8503 +/*
8504 +Number of storage units in a word; normally 4.
8505 +*/
8506 +#define UNITS_PER_WORD 4
8507 +
8508 +/*
8509 +Minimum number of units in a word. If this is undefined, the default is
8510 +UNITS_PER_WORD. Otherwise, it is the constant value that is the
8511 +smallest value that UNITS_PER_WORD can have at run-time.
8512 +*/
8513 +/* MIN_UNITS_PER_WORD not defined */
8514 +
8515 +/*
8516 +Width of a pointer, in bits. You must specify a value no wider than the
8517 +width of Pmode. If it is not equal to the width of Pmode,
8518 +you must define POINTERS_EXTEND_UNSIGNED.
8519 +*/
8520 +#define POINTER_SIZE 32
8521 +
8522 +/*
8523 +A C expression whose value is greater than zero if pointers that need to be
8524 +extended from being POINTER_SIZE bits wide to Pmode are to
8525 +be zero-extended and zero if they are to be sign-extended. If the value
8526 +is less then zero then there must be an "ptr_extend" instruction that
8527 +extends a pointer from POINTER_SIZE to Pmode.
8528 +
8529 +You need not define this macro if the POINTER_SIZE is equal
8530 +to the width of Pmode.
8531 +*/
8532 +/* #define POINTERS_EXTEND_UNSIGNED */
8533 +
8534 +/*
8535 +A Macro to update M and UNSIGNEDP when an object whose type
8536 +is TYPE and which has the specified mode and signedness is to be
8537 +stored in a register. This macro is only called when TYPE is a
8538 +scalar type.
8539 +
8540 +On most RISC machines, which only have operations that operate on a full
8541 +register, define this macro to set M to word_mode if
8542 +M is an integer mode narrower than BITS_PER_WORD. In most
8543 +cases, only integer modes should be widened because wider-precision
8544 +floating-point operations are usually more expensive than their narrower
8545 +counterparts.
8546 +
8547 +For most machines, the macro definition does not change UNSIGNEDP.
8548 +However, some machines, have instructions that preferentially handle
8549 +either signed or unsigned quantities of certain modes. For example, on
8550 +the DEC Alpha, 32-bit loads from memory and 32-bit add instructions
8551 +sign-extend the result to 64 bits. On such machines, set
8552 +UNSIGNEDP according to which kind of extension is more efficient.
8553 +
8554 +Do not define this macro if it would never modify M.
8555 +*/
8556 +#define PROMOTE_MODE(M, UNSIGNEDP, TYPE) \
8557 + { \
8558 + if (!AGGREGATE_TYPE_P (TYPE) \
8559 + && GET_MODE_CLASS (mode) == MODE_INT \
8560 + && GET_MODE_SIZE (mode) < 4) \
8561 + { \
8562 + if (M == QImode) \
8563 + (UNSIGNEDP) = 1; \
8564 + else if (M == HImode) \
8565 + (UNSIGNEDP) = 0; \
8566 + (M) = SImode; \
8567 + } \
8568 + }
8569 +
8570 +#define PROMOTE_FUNCTION_MODE(M, UNSIGNEDP, TYPE) \
8571 + PROMOTE_MODE(M, UNSIGNEDP, TYPE)
8572 +
8573 +/* Define if operations between registers always perform the operation
8574 + on the full register even if a narrower mode is specified. */
8575 +#define WORD_REGISTER_OPERATIONS
8576 +
8577 +/* Define if loading in MODE, an integral mode narrower than BITS_PER_WORD
8578 + will either zero-extend or sign-extend. The value of this macro should
8579 + be the code that says which one of the two operations is implicitly
8580 + done, UNKNOWN if not known. */
8581 +#define LOAD_EXTEND_OP(MODE) \
8582 + (((MODE) == QImode) ? ZERO_EXTEND \
8583 + : ((MODE) == HImode) ? SIGN_EXTEND : UNKNOWN)
8584 +
8585 +
8586 +/*
8587 +Normal alignment required for function parameters on the stack, in
8588 +bits. All stack parameters receive at least this much alignment
8589 +regardless of data type. On most machines, this is the same as the
8590 +size of an integer.
8591 +*/
8592 +#define PARM_BOUNDARY 32
8593 +
8594 +/*
8595 +Define this macro to the minimum alignment enforced by hardware for the
8596 +stack pointer on this machine. The definition is a C expression for the
8597 +desired alignment (measured in bits). This value is used as a default
8598 +if PREFERRED_STACK_BOUNDARY is not defined. On most machines,
8599 +this should be the same as PARM_BOUNDARY.
8600 +*/
8601 +#define STACK_BOUNDARY 32
8602 +
8603 +/*
8604 +Define this macro if you wish to preserve a certain alignment for the
8605 +stack pointer, greater than what the hardware enforces. The definition
8606 +is a C expression for the desired alignment (measured in bits). This
8607 +macro must evaluate to a value equal to or larger than
8608 +STACK_BOUNDARY.
8609 +*/
8610 +#define PREFERRED_STACK_BOUNDARY (TARGET_FORCE_DOUBLE_ALIGN ? 64 : 32 )
8611 +
8612 +/*
8613 +Alignment required for a function entry point, in bits.
8614 +*/
8615 +#define FUNCTION_BOUNDARY 16
8616 +
8617 +/*
8618 +Biggest alignment that any data type can require on this machine, in bits.
8619 +*/
8620 +#define BIGGEST_ALIGNMENT (TARGET_FORCE_DOUBLE_ALIGN ? 64 : 32 )
8621 +
8622 +/*
8623 +If defined, the smallest alignment, in bits, that can be given to an
8624 +object that can be referenced in one operation, without disturbing any
8625 +nearby object. Normally, this is BITS_PER_UNIT, but may be larger
8626 +on machines that don't have byte or half-word store operations.
8627 +*/
8628 +#define MINIMUM_ATOMIC_ALIGNMENT BITS_PER_UNIT
8629 +
8630 +
8631 +/*
8632 +An integer expression for the size in bits of the largest integer machine mode that
8633 +should actually be used. All integer machine modes of this size or smaller can be
8634 +used for structures and unions with the appropriate sizes. If this macro is undefined,
8635 +GET_MODE_BITSIZE (DImode) is assumed.*/
8636 +#define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode)
8637 +
8638 +
8639 +/*
8640 +If defined, a C expression to compute the alignment given to a constant
8641 +that is being placed in memory. CONSTANT is the constant and
8642 +BASIC_ALIGN is the alignment that the object would ordinarily
8643 +have. The value of this macro is used instead of that alignment to
8644 +align the object.
8645 +
8646 +If this macro is not defined, then BASIC_ALIGN is used.
8647 +
8648 +The typical use of this macro is to increase alignment for string
8649 +constants to be word aligned so that strcpy calls that copy
8650 +constants can be done inline.
8651 +*/
8652 +#define CONSTANT_ALIGNMENT(CONSTANT, BASIC_ALIGN) \
8653 + ((TREE_CODE(CONSTANT) == STRING_CST) ? BITS_PER_WORD : BASIC_ALIGN)
8654 +
8655 +/* Try to align string to a word. */
8656 +#define DATA_ALIGNMENT(TYPE, ALIGN) \
8657 + ({(TREE_CODE (TYPE) == ARRAY_TYPE \
8658 + && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \
8659 + && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN));})
8660 +
8661 +/* Try to align local store strings to a word. */
8662 +#define LOCAL_ALIGNMENT(TYPE, ALIGN) \
8663 + ({(TREE_CODE (TYPE) == ARRAY_TYPE \
8664 + && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \
8665 + && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN));})
8666 +
8667 +/*
8668 +Define this macro to be the value 1 if instructions will fail to work
8669 +if given data not on the nominal alignment. If instructions will merely
8670 +go slower in that case, define this macro as 0.
8671 +*/
8672 +#define STRICT_ALIGNMENT 1
8673 +
8674 +/*
8675 +Define this if you wish to imitate the way many other C compilers handle
8676 +alignment of bit-fields and the structures that contain them.
8677 +
8678 +The behavior is that the type written for a bit-field (int,
8679 +short, or other integer type) imposes an alignment for the
8680 +entire structure, as if the structure really did contain an ordinary
8681 +field of that type. In addition, the bit-field is placed within the
8682 +structure so that it would fit within such a field, not crossing a
8683 +boundary for it.
8684 +
8685 +Thus, on most machines, a bit-field whose type is written as int
8686 +would not cross a four-byte boundary, and would force four-byte
8687 +alignment for the whole structure. (The alignment used may not be four
8688 +bytes; it is controlled by the other alignment parameters.)
8689 +
8690 +If the macro is defined, its definition should be a C expression;
8691 +a nonzero value for the expression enables this behavior.
8692 +
8693 +Note that if this macro is not defined, or its value is zero, some
8694 +bit-fields may cross more than one alignment boundary. The compiler can
8695 +support such references if there are insv, extv, and
8696 +extzv insns that can directly reference memory.
8697 +
8698 +The other known way of making bit-fields work is to define
8699 +STRUCTURE_SIZE_BOUNDARY as large as BIGGEST_ALIGNMENT.
8700 +Then every structure can be accessed with fullwords.
8701 +
8702 +Unless the machine has bit-field instructions or you define
8703 +STRUCTURE_SIZE_BOUNDARY that way, you must define
8704 +PCC_BITFIELD_TYPE_MATTERS to have a nonzero value.
8705 +
8706 +If your aim is to make GCC use the same conventions for laying out
8707 +bit-fields as are used by another compiler, here is how to investigate
8708 +what the other compiler does. Compile and run this program:
8709 +
8710 +struct foo1
8711 +{
8712 + char x;
8713 + char :0;
8714 + char y;
8715 +};
8716 +
8717 +struct foo2
8718 +{
8719 + char x;
8720 + int :0;
8721 + char y;
8722 +};
8723 +
8724 +main ()
8725 +{
8726 + printf ("Size of foo1 is %d\n",
8727 + sizeof (struct foo1));
8728 + printf ("Size of foo2 is %d\n",
8729 + sizeof (struct foo2));
8730 + exit (0);
8731 +}
8732 +
8733 +If this prints 2 and 5, then the compiler's behavior is what you would
8734 +get from PCC_BITFIELD_TYPE_MATTERS.
8735 +*/
8736 +#define PCC_BITFIELD_TYPE_MATTERS 1
8737 +
8738 +
8739 +/******************************************************************************
8740 + * Layout of Source Language Data Types
8741 + *****************************************************************************/
8742 +
8743 +/*
8744 +A C expression for the size in bits of the type int on the
8745 +target machine. If you don't define this, the default is one word.
8746 +*/
8747 +#define INT_TYPE_SIZE 32
8748 +
8749 +/*
8750 +A C expression for the size in bits of the type short on the
8751 +target machine. If you don't define this, the default is half a word. (If
8752 +this would be less than one storage unit, it is rounded up to one unit.)
8753 +*/
8754 +#define SHORT_TYPE_SIZE 16
8755 +
8756 +/*
8757 +A C expression for the size in bits of the type long on the
8758 +target machine. If you don't define this, the default is one word.
8759 +*/
8760 +#define LONG_TYPE_SIZE 32
8761 +
8762 +
8763 +/*
8764 +A C expression for the size in bits of the type long long on the
8765 +target machine. If you don't define this, the default is two
8766 +words. If you want to support GNU Ada on your machine, the value of this
8767 +macro must be at least 64.
8768 +*/
8769 +#define LONG_LONG_TYPE_SIZE 64
8770 +
8771 +/*
8772 +A C expression for the size in bits of the type char on the
8773 +target machine. If you don't define this, the default is
8774 +BITS_PER_UNIT.
8775 +*/
8776 +#define CHAR_TYPE_SIZE 8
8777 +
8778 +
8779 +/*
8780 +A C expression for the size in bits of the C++ type bool and
8781 +C99 type _Bool on the target machine. If you don't define
8782 +this, and you probably shouldn't, the default is CHAR_TYPE_SIZE.
8783 +*/
8784 +#define BOOL_TYPE_SIZE 8
8785 +
8786 +
8787 +/*
8788 +An expression whose value is 1 or 0, according to whether the type
8789 +char should be signed or unsigned by default. The user can
8790 +always override this default with the options -fsigned-char
8791 +and -funsigned-char.
8792 +*/
8793 +/* We are using unsigned char */
8794 +#define DEFAULT_SIGNED_CHAR 0
8795 +
8796 +
8797 +/*
8798 +A C expression for a string describing the name of the data type to use
8799 +for size values. The typedef name size_t is defined using the
8800 +contents of the string.
8801 +
8802 +The string can contain more than one keyword. If so, separate them with
8803 +spaces, and write first any length keyword, then unsigned if
8804 +appropriate, and finally int. The string must exactly match one
8805 +of the data type names defined in the function
8806 +init_decl_processing in the file c-decl.c. You may not
8807 +omit int or change the order - that would cause the compiler to
8808 +crash on startup.
8809 +
8810 +If you don't define this macro, the default is "long unsigned int".
8811 +*/
8812 +#define SIZE_TYPE "long unsigned int"
8813 +
8814 +/*
8815 +A C expression for a string describing the name of the data type to use
8816 +for the result of subtracting two pointers. The typedef name
8817 +ptrdiff_t is defined using the contents of the string. See
8818 +SIZE_TYPE above for more information.
8819 +
8820 +If you don't define this macro, the default is "long int".
8821 +*/
8822 +#define PTRDIFF_TYPE "long int"
8823 +
8824 +
8825 +/*
8826 +A C expression for the size in bits of the data type for wide
8827 +characters. This is used in cpp, which cannot make use of
8828 +WCHAR_TYPE.
8829 +*/
8830 +#define WCHAR_TYPE_SIZE 32
8831 +
8832 +
8833 +/*
8834 +A C expression for a string describing the name of the data type to
8835 +use for wide characters passed to printf and returned from
8836 +getwc. The typedef name wint_t is defined using the
8837 +contents of the string. See SIZE_TYPE above for more
8838 +information.
8839 +
8840 +If you don't define this macro, the default is "unsigned int".
8841 +*/
8842 +#define WINT_TYPE "unsigned int"
8843 +
8844 +/*
8845 +A C expression for a string describing the name of the data type that
8846 +can represent any value of any standard or extended signed integer type.
8847 +The typedef name intmax_t is defined using the contents of the
8848 +string. See SIZE_TYPE above for more information.
8849 +
8850 +If you don't define this macro, the default is the first of
8851 +"int", "long int", or "long long int" that has as
8852 +much precision as long long int.
8853 +*/
8854 +#define INTMAX_TYPE "long long int"
8855 +
8856 +/*
8857 +A C expression for a string describing the name of the data type that
8858 +can represent any value of any standard or extended unsigned integer
8859 +type. The typedef name uintmax_t is defined using the contents
8860 +of the string. See SIZE_TYPE above for more information.
8861 +
8862 +If you don't define this macro, the default is the first of
8863 +"unsigned int", "long unsigned int", or "long long unsigned int"
8864 +that has as much precision as long long unsigned int.
8865 +*/
8866 +#define UINTMAX_TYPE "long long unsigned int"
8867 +
8868 +
8869 +/******************************************************************************
8870 + * Register Usage
8871 + *****************************************************************************/
8872 +
8873 +/* Convert from gcc internal register number to register number
8874 + used in assembly code */
8875 +#define ASM_REGNUM(reg) (LAST_REGNUM - (reg))
8876 +
8877 +/* Convert between register number used in assembly to gcc
8878 + internal register number */
8879 +#define INTERNAL_REGNUM(reg) (LAST_REGNUM - (reg))
8880 +
8881 +/** Basic Characteristics of Registers **/
8882 +
8883 +/*
8884 +Number of hardware registers known to the compiler. They receive
8885 +numbers 0 through FIRST_PSEUDO_REGISTER-1; thus, the first
8886 +pseudo register's number really is assigned the number
8887 +FIRST_PSEUDO_REGISTER.
8888 +*/
8889 +#define FIRST_PSEUDO_REGISTER (LAST_REGNUM + 1)
8890 +
8891 +#define FIRST_REGNUM 0
8892 +#define LAST_REGNUM 15
8893 +
8894 +/*
8895 +An initializer that says which registers are used for fixed purposes
8896 +all throughout the compiled code and are therefore not available for
8897 +general allocation. These would include the stack pointer, the frame
8898 +pointer (except on machines where that can be used as a general
8899 +register when no frame pointer is needed), the program counter on
8900 +machines where that is considered one of the addressable registers,
8901 +and any other numbered register with a standard use.
8902 +
8903 +This information is expressed as a sequence of numbers, separated by
8904 +commas and surrounded by braces. The nth number is 1 if
8905 +register n is fixed, 0 otherwise.
8906 +
8907 +The table initialized from this macro, and the table initialized by
8908 +the following one, may be overridden at run time either automatically,
8909 +by the actions of the macro CONDITIONAL_REGISTER_USAGE, or by
8910 +the user with the command options -ffixed-[reg],
8911 +-fcall-used-[reg] and -fcall-saved-[reg].
8912 +*/
8913 +
8914 +/* The internal gcc register numbers are reversed
8915 + compared to the real register numbers since
8916 + gcc expects data types stored over multiple
8917 + registers in the register file to be big endian
8918 + if the memory layout is big endian. But this
8919 + is not the case for avr32 so we fake a big
8920 + endian register file. */
8921 +
8922 +#define FIXED_REGISTERS { \
8923 + 1, /* Program Counter */ \
8924 + 0, /* Link Register */ \
8925 + 1, /* Stack Pointer */ \
8926 + 0, /* r12 */ \
8927 + 0, /* r11 */ \
8928 + 0, /* r10 */ \
8929 + 0, /* r9 */ \
8930 + 0, /* r8 */ \
8931 + 0, /* r7 */ \
8932 + 0, /* r6 */ \
8933 + 0, /* r5 */ \
8934 + 0, /* r4 */ \
8935 + 0, /* r3 */ \
8936 + 0, /* r2 */ \
8937 + 0, /* r1 */ \
8938 + 0, /* r0 */ \
8939 +}
8940 +
8941 +/*
8942 +Like FIXED_REGISTERS but has 1 for each register that is
8943 +clobbered (in general) by function calls as well as for fixed
8944 +registers. This macro therefore identifies the registers that are not
8945 +available for general allocation of values that must live across
8946 +function calls.
8947 +
8948 +If a register has 0 in CALL_USED_REGISTERS, the compiler
8949 +automatically saves it on function entry and restores it on function
8950 +exit, if the register is used within the function.
8951 +*/
8952 +#define CALL_USED_REGISTERS { \
8953 + 1, /* Program Counter */ \
8954 + 0, /* Link Register */ \
8955 + 1, /* Stack Pointer */ \
8956 + 1, /* r12 */ \
8957 + 1, /* r11 */ \
8958 + 1, /* r10 */ \
8959 + 1, /* r9 */ \
8960 + 1, /* r8 */ \
8961 + 0, /* r7 */ \
8962 + 0, /* r6 */ \
8963 + 0, /* r5 */ \
8964 + 0, /* r4 */ \
8965 + 0, /* r3 */ \
8966 + 0, /* r2 */ \
8967 + 0, /* r1 */ \
8968 + 0, /* r0 */ \
8969 +}
8970 +
8971 +/* Interrupt functions can only use registers that have already been
8972 + saved by the prologue, even if they would normally be
8973 + call-clobbered. */
8974 +#define HARD_REGNO_RENAME_OK(SRC, DST) \
8975 + (! IS_INTERRUPT (cfun->machine->func_type) || \
8976 + df_regs_ever_live_p (DST))
8977 +
8978 +
8979 +/*
8980 +Zero or more C statements that may conditionally modify five variables
8981 +fixed_regs, call_used_regs, global_regs,
8982 +reg_names, and reg_class_contents, to take into account
8983 +any dependence of these register sets on target flags. The first three
8984 +of these are of type char [] (interpreted as Boolean vectors).
8985 +global_regs is a const char *[], and
8986 +reg_class_contents is a HARD_REG_SET. Before the macro is
8987 +called, fixed_regs, call_used_regs,
8988 +reg_class_contents, and reg_names have been initialized
8989 +from FIXED_REGISTERS, CALL_USED_REGISTERS,
8990 +REG_CLASS_CONTENTS, and REGISTER_NAMES, respectively.
8991 +global_regs has been cleared, and any -ffixed-[reg],
8992 +-fcall-used-[reg] and -fcall-saved-[reg]
8993 +command options have been applied.
8994 +
8995 +You need not define this macro if it has no work to do.
8996 +
8997 +If the usage of an entire class of registers depends on the target
8998 +flags, you may indicate this to GCC by using this macro to modify
8999 +fixed_regs and call_used_regs to 1 for each of the
9000 +registers in the classes which should not be used by GCC. Also define
9001 +the macro REG_CLASS_FROM_LETTER to return NO_REGS if it
9002 +is called with a letter for a class that shouldn't be used.
9003 +
9004 + (However, if this class is not included in GENERAL_REGS and all
9005 +of the insn patterns whose constraints permit this class are
9006 +controlled by target switches, then GCC will automatically avoid using
9007 +these registers when the target switches are opposed to them.)
9008 +*/
9009 +#define CONDITIONAL_REGISTER_USAGE \
9010 + do \
9011 + { \
9012 + if (flag_pic) \
9013 + { \
9014 + fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1; \
9015 + call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1; \
9016 + } \
9017 + } \
9018 + while (0)
9019 +
9020 +
9021 +/*
9022 +If the program counter has a register number, define this as that
9023 +register number. Otherwise, do not define it.
9024 +*/
9025 +
9026 +#define LAST_AVR32_REGNUM 16
9027 +
9028 +
9029 +/** Order of Allocation of Registers **/
9030 +
9031 +/*
9032 +If defined, an initializer for a vector of integers, containing the
9033 +numbers of hard registers in the order in which GCC should prefer
9034 +to use them (from most preferred to least).
9035 +
9036 +If this macro is not defined, registers are used lowest numbered first
9037 +(all else being equal).
9038 +
9039 +One use of this macro is on machines where the highest numbered
9040 +registers must always be saved and the save-multiple-registers
9041 +instruction supports only sequences of consecutive registers. On such
9042 +machines, define REG_ALLOC_ORDER to be an initializer that lists
9043 +the highest numbered allocable register first.
9044 +*/
9045 +#define REG_ALLOC_ORDER \
9046 +{ \
9047 + INTERNAL_REGNUM(8), \
9048 + INTERNAL_REGNUM(9), \
9049 + INTERNAL_REGNUM(10), \
9050 + INTERNAL_REGNUM(11), \
9051 + INTERNAL_REGNUM(12), \
9052 + LR_REGNUM, \
9053 + INTERNAL_REGNUM(7), \
9054 + INTERNAL_REGNUM(6), \
9055 + INTERNAL_REGNUM(5), \
9056 + INTERNAL_REGNUM(4), \
9057 + INTERNAL_REGNUM(3), \
9058 + INTERNAL_REGNUM(2), \
9059 + INTERNAL_REGNUM(1), \
9060 + INTERNAL_REGNUM(0), \
9061 + SP_REGNUM, \
9062 + PC_REGNUM \
9063 +}
9064 +
9065 +
9066 +/** How Values Fit in Registers **/
9067 +
9068 +/*
9069 +A C expression for the number of consecutive hard registers, starting
9070 +at register number REGNO, required to hold a value of mode
9071 +MODE.
9072 +
9073 +On a machine where all registers are exactly one word, a suitable
9074 +definition of this macro is
9075 +
9076 +#define HARD_REGNO_NREGS(REGNO, MODE) \
9077 + ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
9078 + / UNITS_PER_WORD)
9079 +*/
9080 +#define HARD_REGNO_NREGS(REGNO, MODE) \
9081 + ((unsigned int)((GET_MODE_SIZE(MODE) + UNITS_PER_WORD -1 ) / UNITS_PER_WORD))
9082 +
9083 +/*
9084 +A C expression that is nonzero if it is permissible to store a value
9085 +of mode MODE in hard register number REGNO (or in several
9086 +registers starting with that one). For a machine where all registers
9087 +are equivalent, a suitable definition is
9088 +
9089 + #define HARD_REGNO_MODE_OK(REGNO, MODE) 1
9090 +
9091 +You need not include code to check for the numbers of fixed registers,
9092 +because the allocation mechanism considers them to be always occupied.
9093 +
9094 +On some machines, double-precision values must be kept in even/odd
9095 +register pairs. You can implement that by defining this macro to reject
9096 +odd register numbers for such modes.
9097 +
9098 +The minimum requirement for a mode to be OK in a register is that the
9099 +mov[mode] instruction pattern support moves between the
9100 +register and other hard register in the same class and that moving a
9101 +value into the register and back out not alter it.
9102 +
9103 +Since the same instruction used to move word_mode will work for
9104 +all narrower integer modes, it is not necessary on any machine for
9105 +HARD_REGNO_MODE_OK to distinguish between these modes, provided
9106 +you define patterns movhi, etc., to take advantage of this. This
9107 +is useful because of the interaction between HARD_REGNO_MODE_OK
9108 +and MODES_TIEABLE_P; it is very desirable for all integer modes
9109 +to be tieable.
9110 +
9111 +Many machines have special registers for floating point arithmetic.
9112 +Often people assume that floating point machine modes are allowed only
9113 +in floating point registers. This is not true. Any registers that
9114 +can hold integers can safely hold a floating point machine
9115 +mode, whether or not floating arithmetic can be done on it in those
9116 +registers. Integer move instructions can be used to move the values.
9117 +
9118 +On some machines, though, the converse is true: fixed-point machine
9119 +modes may not go in floating registers. This is true if the floating
9120 +registers normalize any value stored in them, because storing a
9121 +non-floating value there would garble it. In this case,
9122 +HARD_REGNO_MODE_OK should reject fixed-point machine modes in
9123 +floating registers. But if the floating registers do not automatically
9124 +normalize, if you can store any bit pattern in one and retrieve it
9125 +unchanged without a trap, then any machine mode may go in a floating
9126 +register, so you can define this macro to say so.
9127 +
9128 +The primary significance of special floating registers is rather that
9129 +they are the registers acceptable in floating point arithmetic
9130 +instructions. However, this is of no concern to
9131 +HARD_REGNO_MODE_OK. You handle it by writing the proper
9132 +constraints for those instructions.
9133 +
9134 +On some machines, the floating registers are especially slow to access,
9135 +so that it is better to store a value in a stack frame than in such a
9136 +register if floating point arithmetic is not being done. As long as the
9137 +floating registers are not in class GENERAL_REGS, they will not
9138 +be used unless some pattern's constraint asks for one.
9139 +*/
9140 +#define HARD_REGNO_MODE_OK(REGNO, MODE) avr32_hard_regno_mode_ok(REGNO, MODE)
9141 +
9142 +/*
9143 +A C expression that is nonzero if a value of mode
9144 +MODE1 is accessible in mode MODE2 without copying.
9145 +
9146 +If HARD_REGNO_MODE_OK(R, MODE1) and
9147 +HARD_REGNO_MODE_OK(R, MODE2) are always the same for
9148 +any R, then MODES_TIEABLE_P(MODE1, MODE2)
9149 +should be nonzero. If they differ for any R, you should define
9150 +this macro to return zero unless some other mechanism ensures the
9151 +accessibility of the value in a narrower mode.
9152 +
9153 +You should define this macro to return nonzero in as many cases as
9154 +possible since doing so will allow GCC to perform better register
9155 +allocation.
9156 +*/
9157 +#define MODES_TIEABLE_P(MODE1, MODE2) \
9158 + (GET_MODE_CLASS (MODE1) == GET_MODE_CLASS (MODE2))
9159 +
9160 +
9161 +
9162 +/******************************************************************************
9163 + * Register Classes
9164 + *****************************************************************************/
9165 +
9166 +/*
9167 +An enumeral type that must be defined with all the register class names
9168 +as enumeral values. NO_REGS must be first. ALL_REGS
9169 +must be the last register class, followed by one more enumeral value,
9170 +LIM_REG_CLASSES, which is not a register class but rather
9171 +tells how many classes there are.
9172 +
9173 +Each register class has a number, which is the value of casting
9174 +the class name to type int. The number serves as an index
9175 +in many of the tables described below.
9176 +*/
9177 +enum reg_class
9178 +{
9179 + NO_REGS,
9180 + GENERAL_REGS,
9181 + ALL_REGS,
9182 + LIM_REG_CLASSES
9183 +};
9184 +
9185 +/*
9186 +The number of distinct register classes, defined as follows:
9187 + #define N_REG_CLASSES (int) LIM_REG_CLASSES
9188 +*/
9189 +#define N_REG_CLASSES (int)LIM_REG_CLASSES
9190 +
9191 +/*
9192 +An initializer containing the names of the register classes as C string
9193 +constants. These names are used in writing some of the debugging dumps.
9194 +*/
9195 +#define REG_CLASS_NAMES \
9196 +{ \
9197 + "NO_REGS", \
9198 + "GENERAL_REGS", \
9199 + "ALL_REGS" \
9200 +}
9201 +
9202 +/*
9203 +An initializer containing the contents of the register classes, as integers
9204 +which are bit masks. The nth integer specifies the contents of class
9205 +n. The way the integer mask is interpreted is that
9206 +register r is in the class if mask & (1 << r) is 1.
9207 +
9208 +When the machine has more than 32 registers, an integer does not suffice.
9209 +Then the integers are replaced by sub-initializers, braced groupings containing
9210 +several integers. Each sub-initializer must be suitable as an initializer
9211 +for the type HARD_REG_SET which is defined in hard-reg-set.h.
9212 +In this situation, the first integer in each sub-initializer corresponds to
9213 +registers 0 through 31, the second integer to registers 32 through 63, and
9214 +so on.
9215 +*/
9216 +#define REG_CLASS_CONTENTS { \
9217 + {0x00000000}, /* NO_REGS */ \
9218 + {0x0000FFFF}, /* GENERAL_REGS */ \
9219 + {0x7FFFFFFF}, /* ALL_REGS */ \
9220 +}
9221 +
9222 +
9223 +/*
9224 +A C expression whose value is a register class containing hard register
9225 +REGNO. In general there is more than one such class; choose a class
9226 +which is minimal, meaning that no smaller class also contains the
9227 +register.
9228 +*/
9229 +#define REGNO_REG_CLASS(REGNO) (GENERAL_REGS)
9230 +
9231 +/*
9232 +A macro whose definition is the name of the class to which a valid
9233 +base register must belong. A base register is one used in an address
9234 +which is the register value plus a displacement.
9235 +*/
9236 +#define BASE_REG_CLASS GENERAL_REGS
9237 +
9238 +/*
9239 +This is a variation of the BASE_REG_CLASS macro which allows
9240 +the selection of a base register in a mode depenedent manner. If
9241 +mode is VOIDmode then it should return the same value as
9242 +BASE_REG_CLASS.
9243 +*/
9244 +#define MODE_BASE_REG_CLASS(MODE) BASE_REG_CLASS
9245 +
9246 +/*
9247 +A macro whose definition is the name of the class to which a valid
9248 +index register must belong. An index register is one used in an
9249 +address where its value is either multiplied by a scale factor or
9250 +added to another register (as well as added to a displacement).
9251 +*/
9252 +#define INDEX_REG_CLASS BASE_REG_CLASS
9253 +
9254 +/*
9255 +A C expression which defines the machine-dependent operand constraint
9256 +letters for register classes. If CHAR is such a letter, the
9257 +value should be the register class corresponding to it. Otherwise,
9258 +the value should be NO_REGS. The register letter r,
9259 +corresponding to class GENERAL_REGS, will not be passed
9260 +to this macro; you do not need to handle it.
9261 +*/
9262 +#define REG_CLASS_FROM_LETTER(CHAR) NO_REGS
9263 +
9264 +/* These assume that REGNO is a hard or pseudo reg number.
9265 + They give nonzero only if REGNO is a hard reg of the suitable class
9266 + or a pseudo reg currently allocated to a suitable hard reg.
9267 + Since they use reg_renumber, they are safe only once reg_renumber
9268 + has been allocated, which happens in local-alloc.c. */
9269 +#define TEST_REGNO(R, TEST, VALUE) \
9270 + ((R TEST VALUE) || ((unsigned) reg_renumber[R] TEST VALUE))
9271 +
9272 +/*
9273 +A C expression which is nonzero if register number num is suitable for use as a base
9274 +register in operand addresses. It may be either a suitable hard register or a pseudo
9275 +register that has been allocated such a hard register.
9276 +*/
9277 +#define REGNO_OK_FOR_BASE_P(NUM) TEST_REGNO(NUM, <=, LAST_REGNUM)
9278 +
9279 +/*
9280 +A C expression which is nonzero if register number NUM is
9281 +suitable for use as an index register in operand addresses. It may be
9282 +either a suitable hard register or a pseudo register that has been
9283 +allocated such a hard register.
9284 +
9285 +The difference between an index register and a base register is that
9286 +the index register may be scaled. If an address involves the sum of
9287 +two registers, neither one of them scaled, then either one may be
9288 +labeled the ``base'' and the other the ``index''; but whichever
9289 +labeling is used must fit the machine's constraints of which registers
9290 +may serve in each capacity. The compiler will try both labelings,
9291 +looking for one that is valid, and will reload one or both registers
9292 +only if neither labeling works.
9293 +*/
9294 +#define REGNO_OK_FOR_INDEX_P(NUM) TEST_REGNO(NUM, <=, LAST_REGNUM)
9295 +
9296 +/*
9297 +A C expression that places additional restrictions on the register class
9298 +to use when it is necessary to copy value X into a register in class
9299 +CLASS. The value is a register class; perhaps CLASS, or perhaps
9300 +another, smaller class. On many machines, the following definition is
9301 +safe: #define PREFERRED_RELOAD_CLASS(X,CLASS) CLASS
9302 +
9303 +Sometimes returning a more restrictive class makes better code. For
9304 +example, on the 68000, when X is an integer constant that is in range
9305 +for a 'moveq' instruction, the value of this macro is always
9306 +DATA_REGS as long as CLASS includes the data registers.
9307 +Requiring a data register guarantees that a 'moveq' will be used.
9308 +
9309 +If X is a const_double, by returning NO_REGS
9310 +you can force X into a memory constant. This is useful on
9311 +certain machines where immediate floating values cannot be loaded into
9312 +certain kinds of registers.
9313 +*/
9314 +#define PREFERRED_RELOAD_CLASS(X, CLASS) CLASS
9315 +
9316 +
9317 +
9318 +/*
9319 +A C expression for the maximum number of consecutive registers
9320 +of class CLASS needed to hold a value of mode MODE.
9321 +
9322 +This is closely related to the macro HARD_REGNO_NREGS. In fact,
9323 +the value of the macro CLASS_MAX_NREGS(CLASS, MODE)
9324 +should be the maximum value of HARD_REGNO_NREGS(REGNO, MODE)
9325 +for all REGNO values in the class CLASS.
9326 +
9327 +This macro helps control the handling of multiple-word values
9328 +in the reload pass.
9329 +*/
9330 +#define CLASS_MAX_NREGS(CLASS, MODE) /* ToDo:fixme */ \
9331 + (unsigned int)((GET_MODE_SIZE(MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
9332 +
9333 +
9334 +/*
9335 + Using CONST_OK_FOR_CONSTRAINT_P instead of CONS_OK_FOR_LETTER_P
9336 + in order to support constraints with more than one letter.
9337 + Only two letters are then used for constant constraints,
9338 + the letter 'K' and the letter 'I'. The constraint starting with
9339 + these letters must consist of four characters. The character following
9340 + 'K' or 'I' must be either 'u' (unsigned) or 's' (signed) to specify
9341 + if the constant is zero or sign extended. The last two characters specify
9342 + the length in bits of the constant. The base constraint letter 'I' means
9343 + that this is an negated constant, meaning that actually -VAL should be
9344 + checked to lie withing the valid range instead of VAL which is used when
9345 + 'K' is the base constraint letter.
9346 +
9347 +*/
9348 +
9349 +#define CONSTRAINT_LEN(C, STR) \
9350 + ( ((C) == 'K' || (C) == 'I') ? 4 : \
9351 + ((C) == 'R') ? 5 : \
9352 + ((C) == 'P') ? -1 : \
9353 + DEFAULT_CONSTRAINT_LEN((C), (STR)) )
9354 +
9355 +#define CONST_OK_FOR_CONSTRAINT_P(VALUE, C, STR) \
9356 + avr32_const_ok_for_constraint_p(VALUE, C, STR)
9357 +
9358 +/*
9359 +A C expression that defines the machine-dependent operand constraint
9360 +letters that specify particular ranges of const_double values ('G' or 'H').
9361 +
9362 +If C is one of those letters, the expression should check that
9363 +VALUE, an RTX of code const_double, is in the appropriate
9364 +range and return 1 if so, 0 otherwise. If C is not one of those
9365 +letters, the value should be 0 regardless of VALUE.
9366 +
9367 +const_double is used for all floating-point constants and for
9368 +DImode fixed-point constants. A given letter can accept either
9369 +or both kinds of values. It can use GET_MODE to distinguish
9370 +between these kinds.
9371 +*/
9372 +#define CONST_DOUBLE_OK_FOR_LETTER_P(OP, C) \
9373 + ((C) == 'G' ? avr32_const_double_immediate(OP) : 0)
9374 +
9375 +/*
9376 +A C expression that defines the optional machine-dependent constraint
9377 +letters that can be used to segregate specific types of operands, usually
9378 +memory references, for the target machine. Any letter that is not
9379 +elsewhere defined and not matched by REG_CLASS_FROM_LETTER
9380 +may be used. Normally this macro will not be defined.
9381 +
9382 +If it is required for a particular target machine, it should return 1
9383 +if VALUE corresponds to the operand type represented by the
9384 +constraint letter C. If C is not defined as an extra
9385 +constraint, the value returned should be 0 regardless of VALUE.
9386 +
9387 +For example, on the ROMP, load instructions cannot have their output
9388 +in r0 if the memory reference contains a symbolic address. Constraint
9389 +letter 'Q' is defined as representing a memory address that does
9390 +not contain a symbolic address. An alternative is specified with
9391 +a 'Q' constraint on the input and 'r' on the output. The next
9392 +alternative specifies 'm' on the input and a register class that
9393 +does not include r0 on the output.
9394 +*/
9395 +#define EXTRA_CONSTRAINT_STR(OP, C, STR) \
9396 + ((C) == 'W' ? avr32_address_operand(OP, GET_MODE(OP)) : \
9397 + (C) == 'R' ? (avr32_indirect_register_operand(OP, GET_MODE(OP)) || \
9398 + (avr32_imm_disp_memory_operand(OP, GET_MODE(OP)) \
9399 + && avr32_const_ok_for_constraint_p( \
9400 + INTVAL(XEXP(XEXP(OP, 0), 1)), \
9401 + (STR)[1], &(STR)[1]))) : \
9402 + (C) == 'S' ? avr32_indexed_memory_operand(OP, GET_MODE(OP)) : \
9403 + (C) == 'T' ? avr32_const_pool_ref_operand(OP, GET_MODE(OP)) : \
9404 + (C) == 'U' ? SYMBOL_REF_RCALL_FUNCTION_P(OP) : \
9405 + (C) == 'Z' ? avr32_cop_memory_operand(OP, GET_MODE(OP)) : \
9406 + (C) == 'Q' ? avr32_non_rmw_memory_operand(OP, GET_MODE(OP)) : \
9407 + (C) == 'Y' ? avr32_rmw_memory_operand(OP, GET_MODE(OP)) : \
9408 + 0)
9409 +
9410 +
9411 +#define EXTRA_MEMORY_CONSTRAINT(C, STR) ( ((C) == 'R') || \
9412 + ((C) == 'Q') || \
9413 + ((C) == 'S') || \
9414 + ((C) == 'Y') || \
9415 + ((C) == 'Z') )
9416 +
9417 +
9418 +/* Returns nonzero if op is a function SYMBOL_REF which
9419 + can be called using an rcall instruction */
9420 +#define SYMBOL_REF_RCALL_FUNCTION_P(op) \
9421 + ( GET_CODE(op) == SYMBOL_REF \
9422 + && SYMBOL_REF_FUNCTION_P(op) \
9423 + && SYMBOL_REF_LOCAL_P(op) \
9424 + && !SYMBOL_REF_EXTERNAL_P(op) \
9425 + && !TARGET_HAS_ASM_ADDR_PSEUDOS )
9426 +
9427 +/******************************************************************************
9428 + * Stack Layout and Calling Conventions
9429 + *****************************************************************************/
9430 +
9431 +/** Basic Stack Layout **/
9432 +
9433 +/*
9434 +Define this macro if pushing a word onto the stack moves the stack
9435 +pointer to a smaller address.
9436 +
9437 +When we say, ``define this macro if ...,'' it means that the
9438 +compiler checks this macro only with #ifdef so the precise
9439 +definition used does not matter.
9440 +*/
9441 +/* pushm decrece SP: *(--SP) <-- Rx */
9442 +#define STACK_GROWS_DOWNWARD
9443 +
9444 +/*
9445 +This macro defines the operation used when something is pushed
9446 +on the stack. In RTL, a push operation will be
9447 +(set (mem (STACK_PUSH_CODE (reg sp))) ...)
9448 +
9449 +The choices are PRE_DEC, POST_DEC, PRE_INC,
9450 +and POST_INC. Which of these is correct depends on
9451 +the stack direction and on whether the stack pointer points
9452 +to the last item on the stack or whether it points to the
9453 +space for the next item on the stack.
9454 +
9455 +The default is PRE_DEC when STACK_GROWS_DOWNWARD is
9456 +defined, which is almost always right, and PRE_INC otherwise,
9457 +which is often wrong.
9458 +*/
9459 +/* pushm: *(--SP) <-- Rx */
9460 +#define STACK_PUSH_CODE PRE_DEC
9461 +
9462 +/* Define this to nonzero if the nominal address of the stack frame
9463 + is at the high-address end of the local variables;
9464 + that is, each additional local variable allocated
9465 + goes at a more negative offset in the frame. */
9466 +#define FRAME_GROWS_DOWNWARD 1
9467 +
9468 +
9469 +/*
9470 +Offset from the frame pointer to the first local variable slot to be allocated.
9471 +
9472 +If FRAME_GROWS_DOWNWARD, find the next slot's offset by
9473 +subtracting the first slot's length from STARTING_FRAME_OFFSET.
9474 +Otherwise, it is found by adding the length of the first slot to the
9475 +value STARTING_FRAME_OFFSET.
9476 + (i'm not sure if the above is still correct.. had to change it to get
9477 + rid of an overfull. --mew 2feb93 )
9478 +*/
9479 +#define STARTING_FRAME_OFFSET 0
9480 +
9481 +/*
9482 +Offset from the stack pointer register to the first location at which
9483 +outgoing arguments are placed. If not specified, the default value of
9484 +zero is used. This is the proper value for most machines.
9485 +
9486 +If ARGS_GROW_DOWNWARD, this is the offset to the location above
9487 +the first location at which outgoing arguments are placed.
9488 +*/
9489 +#define STACK_POINTER_OFFSET 0
9490 +
9491 +/*
9492 +Offset from the argument pointer register to the first argument's
9493 +address. On some machines it may depend on the data type of the
9494 +function.
9495 +
9496 +If ARGS_GROW_DOWNWARD, this is the offset to the location above
9497 +the first argument's address.
9498 +*/
9499 +#define FIRST_PARM_OFFSET(FUNDECL) 0
9500 +
9501 +
9502 +/*
9503 +A C expression whose value is RTL representing the address in a stack
9504 +frame where the pointer to the caller's frame is stored. Assume that
9505 +FRAMEADDR is an RTL expression for the address of the stack frame
9506 +itself.
9507 +
9508 +If you don't define this macro, the default is to return the value
9509 +of FRAMEADDR - that is, the stack frame address is also the
9510 +address of the stack word that points to the previous frame.
9511 +*/
9512 +#define DYNAMIC_CHAIN_ADDRESS(FRAMEADDR) plus_constant ((FRAMEADDR), 4)
9513 +
9514 +
9515 +/*
9516 +A C expression whose value is RTL representing the value of the return
9517 +address for the frame COUNT steps up from the current frame, after
9518 +the prologue. FRAMEADDR is the frame pointer of the COUNT
9519 +frame, or the frame pointer of the COUNT - 1 frame if
9520 +RETURN_ADDR_IN_PREVIOUS_FRAME is defined.
9521 +
9522 +The value of the expression must always be the correct address when
9523 +COUNT is zero, but may be NULL_RTX if there is not way to
9524 +determine the return address of other frames.
9525 +*/
9526 +#define RETURN_ADDR_RTX(COUNT, FRAMEADDR) avr32_return_addr(COUNT, FRAMEADDR)
9527 +
9528 +
9529 +/*
9530 +A C expression whose value is RTL representing the location of the
9531 +incoming return address at the beginning of any function, before the
9532 +prologue. This RTL is either a REG, indicating that the return
9533 +value is saved in 'REG', or a MEM representing a location in
9534 +the stack.
9535 +
9536 +You only need to define this macro if you want to support call frame
9537 +debugging information like that provided by DWARF 2.
9538 +
9539 +If this RTL is a REG, you should also define
9540 +DWARF_FRAME_RETURN_COLUMN to DWARF_FRAME_REGNUM (REGNO).
9541 +*/
9542 +#define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (Pmode, LR_REGNUM)
9543 +
9544 +/*
9545 +A C expression whose value is an integer giving the offset, in bytes,
9546 +from the value of the stack pointer register to the top of the stack
9547 +frame at the beginning of any function, before the prologue. The top of
9548 +the frame is defined to be the value of the stack pointer in the
9549 +previous frame, just before the call instruction.
9550 +
9551 +You only need to define this macro if you want to support call frame
9552 +debugging information like that provided by DWARF 2.
9553 +*/
9554 +#define INCOMING_FRAME_SP_OFFSET 0
9555 +
9556 +
9557 +/** Exception Handling Support **/
9558 +
9559 +/* Use setjump/longjump for exception handling. */
9560 +#define DWARF2_UNWIND_INFO 0
9561 +#define MUST_USE_SJLJ_EXCEPTIONS 1
9562 +
9563 +/*
9564 +A C expression whose value is the Nth register number used for
9565 +data by exception handlers, or INVALID_REGNUM if fewer than
9566 +N registers are usable.
9567 +
9568 +The exception handling library routines communicate with the exception
9569 +handlers via a set of agreed upon registers. Ideally these registers
9570 +should be call-clobbered; it is possible to use call-saved registers,
9571 +but may negatively impact code size. The target must support at least
9572 +2 data registers, but should define 4 if there are enough free registers.
9573 +
9574 +You must define this macro if you want to support call frame exception
9575 +handling like that provided by DWARF 2.
9576 +*/
9577 +/*
9578 + Use r9-r11
9579 +*/
9580 +#define EH_RETURN_DATA_REGNO(N) \
9581 + ((N<3) ? INTERNAL_REGNUM(N+9) : INVALID_REGNUM)
9582 +
9583 +/*
9584 +A C expression whose value is RTL representing a location in which
9585 +to store a stack adjustment to be applied before function return.
9586 +This is used to unwind the stack to an exception handler's call frame.
9587 +It will be assigned zero on code paths that return normally.
9588 +
9589 +Typically this is a call-clobbered hard register that is otherwise
9590 +untouched by the epilogue, but could also be a stack slot.
9591 +
9592 +You must define this macro if you want to support call frame exception
9593 +handling like that provided by DWARF 2.
9594 +*/
9595 +/*
9596 + Use r8
9597 +*/
9598 +#define EH_RETURN_STACKADJ_REGNO INTERNAL_REGNUM(8)
9599 +#define EH_RETURN_STACKADJ_RTX gen_rtx_REG(SImode, EH_RETURN_STACKADJ_REGNO)
9600 +
9601 +/*
9602 +A C expression whose value is RTL representing a location in which
9603 +to store the address of an exception handler to which we should
9604 +return. It will not be assigned on code paths that return normally.
9605 +
9606 +Typically this is the location in the call frame at which the normal
9607 +return address is stored. For targets that return by popping an
9608 +address off the stack, this might be a memory address just below
9609 +the target call frame rather than inside the current call
9610 +frame. EH_RETURN_STACKADJ_RTX will have already been assigned,
9611 +so it may be used to calculate the location of the target call frame.
9612 +
9613 +Some targets have more complex requirements than storing to an
9614 +address calculable during initial code generation. In that case
9615 +the eh_return instruction pattern should be used instead.
9616 +
9617 +If you want to support call frame exception handling, you must
9618 +define either this macro or the eh_return instruction pattern.
9619 +*/
9620 +/*
9621 + We define the eh_return instruction pattern, so this isn't needed.
9622 +*/
9623 +/* #define EH_RETURN_HANDLER_RTX gen_rtx_REG(Pmode, RET_REGISTER) */
9624 +
9625 +/*
9626 + This macro chooses the encoding of pointers embedded in the
9627 + exception handling sections. If at all possible, this should be
9628 + defined such that the exception handling section will not require
9629 + dynamic relocations, and so may be read-only.
9630 +
9631 + code is 0 for data, 1 for code labels, 2 for function
9632 + pointers. global is true if the symbol may be affected by dynamic
9633 + relocations. The macro should return a combination of the DW_EH_PE_*
9634 + defines as found in dwarf2.h.
9635 +
9636 + If this macro is not defined, pointers will not be encoded but
9637 + represented directly.
9638 +*/
9639 +#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
9640 + ((flag_pic && (GLOBAL) ? DW_EH_PE_indirect : 0) \
9641 + | (flag_pic ? DW_EH_PE_pcrel : DW_EH_PE_absptr) \
9642 + | DW_EH_PE_sdata4)
9643 +
9644 +/* ToDo: The rest of this subsection */
9645 +
9646 +/** Specifying How Stack Checking is Done **/
9647 +/* ToDo: All in this subsection */
9648 +
9649 +/** Registers That Address the Stack Frame **/
9650 +
9651 +/*
9652 +The register number of the stack pointer register, which must also be a
9653 +fixed register according to FIXED_REGISTERS. On most machines,
9654 +the hardware determines which register this is.
9655 +*/
9656 +/* Using r13 as stack pointer. */
9657 +#define STACK_POINTER_REGNUM INTERNAL_REGNUM(13)
9658 +
9659 +/*
9660 +The register number of the frame pointer register, which is used to
9661 +access automatic variables in the stack frame. On some machines, the
9662 +hardware determines which register this is. On other machines, you can
9663 +choose any register you wish for this purpose.
9664 +*/
9665 +/* Use r7 */
9666 +#define FRAME_POINTER_REGNUM INTERNAL_REGNUM(7)
9667 +
9668 +/*
9669 +The register number of the arg pointer register, which is used to access
9670 +the function's argument list. On some machines, this is the same as the
9671 +frame pointer register. On some machines, the hardware determines which
9672 +register this is. On other machines, you can choose any register you
9673 +wish for this purpose. If this is not the same register as the frame
9674 +pointer register, then you must mark it as a fixed register according to
9675 +FIXED_REGISTERS, or arrange to be able to eliminate it (see Section
9676 +10.10.5 [Elimination], page 224).
9677 +*/
9678 +/* Using r5 */
9679 +#define ARG_POINTER_REGNUM INTERNAL_REGNUM(4)
9680 +
9681 +
9682 +/*
9683 +Register numbers used for passing a function's static chain pointer. If
9684 +register windows are used, the register number as seen by the called
9685 +function is STATIC_CHAIN_INCOMING_REGNUM, while the register
9686 +number as seen by the calling function is STATIC_CHAIN_REGNUM. If
9687 +these registers are the same, STATIC_CHAIN_INCOMING_REGNUM need
9688 +not be defined.
9689 +
9690 +The static chain register need not be a fixed register.
9691 +
9692 +If the static chain is passed in memory, these macros should not be
9693 +defined; instead, the next two macros should be defined.
9694 +*/
9695 +/* Using r0 */
9696 +#define STATIC_CHAIN_REGNUM INTERNAL_REGNUM(0)
9697 +
9698 +/** Eliminating Frame Pointer and Arg Pointer **/
9699 +
9700 +/*
9701 +A C expression which is nonzero if a function must have and use a frame
9702 +pointer. This expression is evaluated in the reload pass. If its value is
9703 +nonzero the function will have a frame pointer.
9704 +
9705 +The expression can in principle examine the current function and decide
9706 +according to the facts, but on most machines the constant 0 or the
9707 +constant 1 suffices. Use 0 when the machine allows code to be generated
9708 +with no frame pointer, and doing so saves some time or space. Use 1
9709 +when there is no possible advantage to avoiding a frame pointer.
9710 +
9711 +In certain cases, the compiler does not know how to produce valid code
9712 +without a frame pointer. The compiler recognizes those cases and
9713 +automatically gives the function a frame pointer regardless of what
9714 +FRAME_POINTER_REQUIRED says. You don't need to worry about
9715 +them.
9716 +
9717 +In a function that does not require a frame pointer, the frame pointer
9718 +register can be allocated for ordinary usage, unless you mark it as a
9719 +fixed register. See FIXED_REGISTERS for more information.
9720 +*/
9721 +/* We need the frame pointer when compiling for profiling */
9722 +#define FRAME_POINTER_REQUIRED (current_function_profile)
9723 +
9724 +/*
9725 +A C statement to store in the variable DEPTH_VAR the difference
9726 +between the frame pointer and the stack pointer values immediately after
9727 +the function prologue. The value would be computed from information
9728 +such as the result of get_frame_size () and the tables of
9729 +registers regs_ever_live and call_used_regs.
9730 +
9731 +If ELIMINABLE_REGS is defined, this macro will be not be used and
9732 +need not be defined. Otherwise, it must be defined even if
9733 +FRAME_POINTER_REQUIRED is defined to always be true; in that
9734 +case, you may set DEPTH_VAR to anything.
9735 +*/
9736 +#define INITIAL_FRAME_POINTER_OFFSET(DEPTH_VAR) ((DEPTH_VAR) = get_frame_size())
9737 +
9738 +/*
9739 +If defined, this macro specifies a table of register pairs used to
9740 +eliminate unneeded registers that point into the stack frame. If it is not
9741 +defined, the only elimination attempted by the compiler is to replace
9742 +references to the frame pointer with references to the stack pointer.
9743 +
9744 +The definition of this macro is a list of structure initializations, each
9745 +of which specifies an original and replacement register.
9746 +
9747 +On some machines, the position of the argument pointer is not known until
9748 +the compilation is completed. In such a case, a separate hard register
9749 +must be used for the argument pointer. This register can be eliminated by
9750 +replacing it with either the frame pointer or the argument pointer,
9751 +depending on whether or not the frame pointer has been eliminated.
9752 +
9753 +In this case, you might specify:
9754 + #define ELIMINABLE_REGS \
9755 + {{ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
9756 + {ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM}, \
9757 + {FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}}
9758 +
9759 +Note that the elimination of the argument pointer with the stack pointer is
9760 +specified first since that is the preferred elimination.
9761 +*/
9762 +#define ELIMINABLE_REGS \
9763 +{ \
9764 + { FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
9765 + { ARG_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
9766 + { ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM } \
9767 +}
9768 +
9769 +/*
9770 +A C expression that returns nonzero if the compiler is allowed to try
9771 +to replace register number FROM with register number
9772 +TO. This macro need only be defined if ELIMINABLE_REGS
9773 +is defined, and will usually be the constant 1, since most of the cases
9774 +preventing register elimination are things that the compiler already
9775 +knows about.
9776 +*/
9777 +#define CAN_ELIMINATE(FROM, TO) 1
9778 +
9779 +/*
9780 +This macro is similar to INITIAL_FRAME_POINTER_OFFSET. It
9781 +specifies the initial difference between the specified pair of
9782 +registers. This macro must be defined if ELIMINABLE_REGS is
9783 +defined.
9784 +*/
9785 +#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
9786 + ((OFFSET) = avr32_initial_elimination_offset(FROM, TO))
9787 +
9788 +/** Passing Function Arguments on the Stack **/
9789 +
9790 +
9791 +/*
9792 +A C expression. If nonzero, push insns will be used to pass
9793 +outgoing arguments.
9794 +If the target machine does not have a push instruction, set it to zero.
9795 +That directs GCC to use an alternate strategy: to
9796 +allocate the entire argument block and then store the arguments into
9797 +it. When PUSH_ARGS is nonzero, PUSH_ROUNDING must be defined too.
9798 +*/
9799 +#define PUSH_ARGS 1
9800 +
9801 +/*
9802 +A C expression that is the number of bytes actually pushed onto the
9803 +stack when an instruction attempts to push NPUSHED bytes.
9804 +
9805 +On some machines, the definition
9806 +
9807 + #define PUSH_ROUNDING(BYTES) (BYTES)
9808 +
9809 +will suffice. But on other machines, instructions that appear
9810 +to push one byte actually push two bytes in an attempt to maintain
9811 +alignment. Then the definition should be
9812 +
9813 + #define PUSH_ROUNDING(BYTES) (((BYTES) + 1) & ~1)
9814 +*/
9815 +/* Push 4 bytes at the time. */
9816 +#define PUSH_ROUNDING(NPUSHED) (((NPUSHED) + 3) & ~3)
9817 +
9818 +/*
9819 +A C expression. If nonzero, the maximum amount of space required for
9820 +outgoing arguments will be computed and placed into the variable
9821 +current_function_outgoing_args_size. No space will be pushed
9822 +onto the stack for each call; instead, the function prologue should
9823 +increase the stack frame size by this amount.
9824 +
9825 +Setting both PUSH_ARGS and ACCUMULATE_OUTGOING_ARGS is not proper.
9826 +*/
9827 +#define ACCUMULATE_OUTGOING_ARGS 0
9828 +
9829 +/*
9830 +A C expression that should indicate the number of bytes of its own
9831 +arguments that a function pops on returning, or 0 if the
9832 +function pops no arguments and the caller must therefore pop them all
9833 +after the function returns.
9834 +
9835 +FUNDECL is a C variable whose value is a tree node that describes
9836 +the function in question. Normally it is a node of type
9837 +FUNCTION_DECL that describes the declaration of the function.
9838 +From this you can obtain the DECL_ATTRIBUTES of the function.
9839 +
9840 +FUNTYPE is a C variable whose value is a tree node that
9841 +describes the function in question. Normally it is a node of type
9842 +FUNCTION_TYPE that describes the data type of the function.
9843 +From this it is possible to obtain the data types of the value and
9844 +arguments (if known).
9845 +
9846 +When a call to a library function is being considered, FUNDECL
9847 +will contain an identifier node for the library function. Thus, if
9848 +you need to distinguish among various library functions, you can do so
9849 +by their names. Note that ``library function'' in this context means
9850 +a function used to perform arithmetic, whose name is known specially
9851 +in the compiler and was not mentioned in the C code being compiled.
9852 +
9853 +STACK_SIZE is the number of bytes of arguments passed on the
9854 +stack. If a variable number of bytes is passed, it is zero, and
9855 +argument popping will always be the responsibility of the calling function.
9856 +
9857 +On the VAX, all functions always pop their arguments, so the definition
9858 +of this macro is STACK_SIZE. On the 68000, using the standard
9859 +calling convention, no functions pop their arguments, so the value of
9860 +the macro is always 0 in this case. But an alternative calling
9861 +convention is available in which functions that take a fixed number of
9862 +arguments pop them but other functions (such as printf) pop
9863 +nothing (the caller pops all). When this convention is in use,
9864 +FUNTYPE is examined to determine whether a function takes a fixed
9865 +number of arguments.
9866 +*/
9867 +#define RETURN_POPS_ARGS(FUNDECL, FUNTYPE, STACK_SIZE) 0
9868 +
9869 +
9870 +/*Return true if this function can we use a single return instruction*/
9871 +#define USE_RETURN_INSN(ISCOND) avr32_use_return_insn(ISCOND)
9872 +
9873 +/*
9874 +A C expression that should indicate the number of bytes a call sequence
9875 +pops off the stack. It is added to the value of RETURN_POPS_ARGS
9876 +when compiling a function call.
9877 +
9878 +CUM is the variable in which all arguments to the called function
9879 +have been accumulated.
9880 +
9881 +On certain architectures, such as the SH5, a call trampoline is used
9882 +that pops certain registers off the stack, depending on the arguments
9883 +that have been passed to the function. Since this is a property of the
9884 +call site, not of the called function, RETURN_POPS_ARGS is not
9885 +appropriate.
9886 +*/
9887 +#define CALL_POPS_ARGS(CUM) 0
9888 +
9889 +/* Passing Arguments in Registers */
9890 +
9891 +/*
9892 +A C expression that controls whether a function argument is passed
9893 +in a register, and which register.
9894 +
9895 +The arguments are CUM, which summarizes all the previous
9896 +arguments; MODE, the machine mode of the argument; TYPE,
9897 +the data type of the argument as a tree node or 0 if that is not known
9898 +(which happens for C support library functions); and NAMED,
9899 +which is 1 for an ordinary argument and 0 for nameless arguments that
9900 +correspond to '...' in the called function's prototype.
9901 +TYPE can be an incomplete type if a syntax error has previously
9902 +occurred.
9903 +
9904 +The value of the expression is usually either a reg RTX for the
9905 +hard register in which to pass the argument, or zero to pass the
9906 +argument on the stack.
9907 +
9908 +For machines like the VAX and 68000, where normally all arguments are
9909 +pushed, zero suffices as a definition.
9910 +
9911 +The value of the expression can also be a parallel RTX. This is
9912 +used when an argument is passed in multiple locations. The mode of the
9913 +of the parallel should be the mode of the entire argument. The
9914 +parallel holds any number of expr_list pairs; each one
9915 +describes where part of the argument is passed. In each
9916 +expr_list the first operand must be a reg RTX for the hard
9917 +register in which to pass this part of the argument, and the mode of the
9918 +register RTX indicates how large this part of the argument is. The
9919 +second operand of the expr_list is a const_int which gives
9920 +the offset in bytes into the entire argument of where this part starts.
9921 +As a special exception the first expr_list in the parallel
9922 +RTX may have a first operand of zero. This indicates that the entire
9923 +argument is also stored on the stack.
9924 +
9925 +The last time this macro is called, it is called with MODE == VOIDmode,
9926 +and its result is passed to the call or call_value
9927 +pattern as operands 2 and 3 respectively.
9928 +
9929 +The usual way to make the ISO library 'stdarg.h' work on a machine
9930 +where some arguments are usually passed in registers, is to cause
9931 +nameless arguments to be passed on the stack instead. This is done
9932 +by making FUNCTION_ARG return 0 whenever NAMED is 0.
9933 +
9934 +You may use the macro MUST_PASS_IN_STACK (MODE, TYPE)
9935 +in the definition of this macro to determine if this argument is of a
9936 +type that must be passed in the stack. If REG_PARM_STACK_SPACE
9937 +is not defined and FUNCTION_ARG returns nonzero for such an
9938 +argument, the compiler will abort. If REG_PARM_STACK_SPACE is
9939 +defined, the argument will be computed in the stack and then loaded into
9940 +a register. */
9941 +
9942 +#define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
9943 + avr32_function_arg(&(CUM), MODE, TYPE, NAMED)
9944 +
9945 +/*
9946 +A C type for declaring a variable that is used as the first argument of
9947 +FUNCTION_ARG and other related values. For some target machines,
9948 +the type int suffices and can hold the number of bytes of
9949 +argument so far.
9950 +
9951 +There is no need to record in CUMULATIVE_ARGS anything about the
9952 +arguments that have been passed on the stack. The compiler has other
9953 +variables to keep track of that. For target machines on which all
9954 +arguments are passed on the stack, there is no need to store anything in
9955 +CUMULATIVE_ARGS; however, the data structure must exist and
9956 +should not be empty, so use int.
9957 +*/
9958 +typedef struct avr32_args
9959 +{
9960 + /* Index representing the argument register the current function argument
9961 + will occupy */
9962 + int index;
9963 + /* A mask with bits representing the argument registers: if a bit is set
9964 + then this register is used for an argument */
9965 + int used_index;
9966 + /* TRUE if this function has anonymous arguments */
9967 + int uses_anonymous_args;
9968 + /* The size in bytes of the named arguments pushed on the stack */
9969 + int stack_pushed_args_size;
9970 + /* Set to true if this function needs a Return Value Pointer */
9971 + int use_rvp;
9972 + /* Set to true if function is a flashvault function. */
9973 + int flashvault_func;
9974 +
9975 +} CUMULATIVE_ARGS;
9976 +
9977 +
9978 +#define FIRST_CUM_REG_INDEX 0
9979 +#define LAST_CUM_REG_INDEX 4
9980 +#define GET_REG_INDEX(CUM) ((CUM)->index)
9981 +#define SET_REG_INDEX(CUM, INDEX) ((CUM)->index = (INDEX));
9982 +#define GET_USED_INDEX(CUM, INDEX) ((CUM)->used_index & (1 << (INDEX)))
9983 +#define SET_USED_INDEX(CUM, INDEX) \
9984 + do \
9985 + { \
9986 + if (INDEX >= 0) \
9987 + (CUM)->used_index |= (1 << (INDEX)); \
9988 + } \
9989 + while (0)
9990 +#define SET_INDEXES_UNUSED(CUM) ((CUM)->used_index = 0)
9991 +
9992 +/*
9993 + A C statement (sans semicolon) for initializing the variable cum for the
9994 + state at the beginning of the argument list. The variable has type
9995 + CUMULATIVE_ARGS. The value of FNTYPE is the tree node for the data type of
9996 + the function which will receive the args, or 0 if the args are to a compiler
9997 + support library function. For direct calls that are not libcalls, FNDECL
9998 + contain the declaration node of the function. FNDECL is also set when
9999 + INIT_CUMULATIVE_ARGS is used to find arguments for the function being
10000 + compiled. N_NAMED_ARGS is set to the number of named arguments, including a
10001 + structure return address if it is passed as a parameter, when making a call.
10002 + When processing incoming arguments, N_NAMED_ARGS is set to -1.
10003 +
10004 + When processing a call to a compiler support library function, LIBNAME
10005 + identifies which one. It is a symbol_ref rtx which contains the name of the
10006 + function, as a string. LIBNAME is 0 when an ordinary C function call is
10007 + being processed. Thus, each time this macro is called, either LIBNAME or
10008 + FNTYPE is nonzero, but never both of them at once.
10009 +*/
10010 +#define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \
10011 + avr32_init_cumulative_args(&(CUM), FNTYPE, LIBNAME, FNDECL)
10012 +
10013 +/*
10014 +A C statement (sans semicolon) to update the summarizer variable
10015 +CUM to advance past an argument in the argument list. The
10016 +values MODE, TYPE and NAMED describe that argument.
10017 +Once this is done, the variable CUM is suitable for analyzing
10018 +the following argument with FUNCTION_ARG, etc.
10019 +
10020 +This macro need not do anything if the argument in question was passed
10021 +on the stack. The compiler knows how to track the amount of stack space
10022 +used for arguments without any special help.
10023 +*/
10024 +#define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED) \
10025 + avr32_function_arg_advance(&(CUM), MODE, TYPE, NAMED)
10026 +
10027 +/*
10028 +If defined, a C expression which determines whether, and in which direction,
10029 +to pad out an argument with extra space. The value should be of type
10030 +enum direction: either 'upward' to pad above the argument,
10031 +'downward' to pad below, or 'none' to inhibit padding.
10032 +
10033 +The amount of padding is always just enough to reach the next
10034 +multiple of FUNCTION_ARG_BOUNDARY; this macro does not control
10035 +it.
10036 +
10037 +This macro has a default definition which is right for most systems.
10038 +For little-endian machines, the default is to pad upward. For
10039 +big-endian machines, the default is to pad downward for an argument of
10040 +constant size shorter than an int, and upward otherwise.
10041 +*/
10042 +#define FUNCTION_ARG_PADDING(MODE, TYPE) \
10043 + avr32_function_arg_padding(MODE, TYPE)
10044 +
10045 +/*
10046 + Specify padding for the last element of a block move between registers
10047 + and memory. First is nonzero if this is the only element. Defining
10048 + this macro allows better control of register function parameters on
10049 + big-endian machines, without using PARALLEL rtl. In particular,
10050 + MUST_PASS_IN_STACK need not test padding and mode of types in registers,
10051 + as there is no longer a "wrong" part of a register; For example, a three
10052 + byte aggregate may be passed in the high part of a register if so required.
10053 +*/
10054 +#define BLOCK_REG_PADDING(MODE, TYPE, FIRST) \
10055 + avr32_function_arg_padding(MODE, TYPE)
10056 +
10057 +/*
10058 +If defined, a C expression which determines whether the default
10059 +implementation of va_arg will attempt to pad down before reading the
10060 +next argument, if that argument is smaller than its aligned space as
10061 +controlled by PARM_BOUNDARY. If this macro is not defined, all such
10062 +arguments are padded down if BYTES_BIG_ENDIAN is true.
10063 +*/
10064 +#define PAD_VARARGS_DOWN \
10065 + (FUNCTION_ARG_PADDING (TYPE_MODE (type), type) == downward)
10066 +
10067 +/*
10068 +A C expression that is nonzero if REGNO is the number of a hard
10069 +register in which function arguments are sometimes passed. This does
10070 +not include implicit arguments such as the static chain and
10071 +the structure-value address. On many machines, no registers can be
10072 +used for this purpose since all function arguments are pushed on the
10073 +stack.
10074 +*/
10075 +/*
10076 + Use r8 - r12 for function arguments.
10077 +*/
10078 +#define FUNCTION_ARG_REGNO_P(REGNO) \
10079 + (REGNO >= 3 && REGNO <= 7)
10080 +
10081 +/* Number of registers used for passing function arguments */
10082 +#define NUM_ARG_REGS 5
10083 +
10084 +/*
10085 +If defined, the order in which arguments are loaded into their
10086 +respective argument registers is reversed so that the last
10087 +argument is loaded first. This macro only affects arguments
10088 +passed in registers.
10089 +*/
10090 +/* #define LOAD_ARGS_REVERSED */
10091 +
10092 +/** How Scalar Function Values Are Returned **/
10093 +
10094 +/* AVR32 is using r12 as return register. */
10095 +#define RET_REGISTER (15 - 12)
10096 +
10097 +/*
10098 +A C expression to create an RTX representing the place where a library
10099 +function returns a value of mode MODE. If the precise function
10100 +being called is known, FUNC is a tree node
10101 +(FUNCTION_DECL) for it; otherwise, func is a null
10102 +pointer. This makes it possible to use a different value-returning
10103 +convention for specific functions when all their calls are
10104 +known.
10105 +
10106 +Note that "library function" in this context means a compiler
10107 +support routine, used to perform arithmetic, whose name is known
10108 +specially by the compiler and was not mentioned in the C code being
10109 +compiled.
10110 +
10111 +The definition of LIBRARY_VALUE need not be concerned aggregate
10112 +data types, because none of the library functions returns such types.
10113 +*/
10114 +#define LIBCALL_VALUE(MODE) avr32_libcall_value(MODE)
10115 +
10116 +/*
10117 +A C expression that is nonzero if REGNO is the number of a hard
10118 +register in which the values of called function may come back.
10119 +
10120 +A register whose use for returning values is limited to serving as the
10121 +second of a pair (for a value of type double, say) need not be
10122 +recognized by this macro. So for most machines, this definition
10123 +suffices:
10124 + #define FUNCTION_VALUE_REGNO_P(N) ((N) == 0)
10125 +
10126 +If the machine has register windows, so that the caller and the called
10127 +function use different registers for the return value, this macro
10128 +should recognize only the caller's register numbers.
10129 +*/
10130 +/*
10131 + When returning a value of mode DImode, r11:r10 is used, else r12 is used.
10132 +*/
10133 +#define FUNCTION_VALUE_REGNO_P(REGNO) ((REGNO) == RET_REGISTER \
10134 + || (REGNO) == INTERNAL_REGNUM(11))
10135 +
10136 +
10137 +/** How Large Values Are Returned **/
10138 +
10139 +
10140 +/*
10141 +Define this macro to be 1 if all structure and union return values must be
10142 +in memory. Since this results in slower code, this should be defined
10143 +only if needed for compatibility with other compilers or with an ABI.
10144 +If you define this macro to be 0, then the conventions used for structure
10145 +and union return values are decided by the RETURN_IN_MEMORY macro.
10146 +
10147 +If not defined, this defaults to the value 1.
10148 +*/
10149 +#define DEFAULT_PCC_STRUCT_RETURN 0
10150 +
10151 +
10152 +
10153 +
10154 +/** Generating Code for Profiling **/
10155 +
10156 +/*
10157 +A C statement or compound statement to output to FILE some
10158 +assembler code to call the profiling subroutine mcount.
10159 +
10160 +The details of how mcount expects to be called are determined by
10161 +your operating system environment, not by GCC. To figure them out,
10162 +compile a small program for profiling using the system's installed C
10163 +compiler and look at the assembler code that results.
10164 +
10165 +Older implementations of mcount expect the address of a counter
10166 +variable to be loaded into some register. The name of this variable is
10167 +'LP' followed by the number LABELNO, so you would generate
10168 +the name using 'LP%d' in a fprintf.
10169 +*/
10170 +/* ToDo: fixme */
10171 +#ifndef FUNCTION_PROFILER
10172 +#define FUNCTION_PROFILER(FILE, LABELNO) \
10173 + fprintf((FILE), "/* profiler %d */", (LABELNO))
10174 +#endif
10175 +
10176 +
10177 +/*****************************************************************************
10178 + * Trampolines for Nested Functions *
10179 + *****************************************************************************/
10180 +
10181 +/*
10182 +A C statement to output, on the stream FILE, assembler code for a
10183 +block of data that contains the constant parts of a trampoline. This
10184 +code should not include a label - the label is taken care of
10185 +automatically.
10186 +
10187 +If you do not define this macro, it means no template is needed
10188 +for the target. Do not define this macro on systems where the block move
10189 +code to copy the trampoline into place would be larger than the code
10190 +to generate it on the spot.
10191 +*/
10192 +/* ToDo: correct? */
10193 +#define TRAMPOLINE_TEMPLATE(FILE) avr32_trampoline_template(FILE);
10194 +
10195 +
10196 +/*
10197 +A C expression for the size in bytes of the trampoline, as an integer.
10198 +*/
10199 +/* ToDo: fixme */
10200 +#define TRAMPOLINE_SIZE 0x0C
10201 +
10202 +/*
10203 +Alignment required for trampolines, in bits.
10204 +
10205 +If you don't define this macro, the value of BIGGEST_ALIGNMENT
10206 +is used for aligning trampolines.
10207 +*/
10208 +#define TRAMPOLINE_ALIGNMENT 16
10209 +
10210 +/*
10211 +A C statement to initialize the variable parts of a trampoline.
10212 +ADDR is an RTX for the address of the trampoline; FNADDR is
10213 +an RTX for the address of the nested function; STATIC_CHAIN is an
10214 +RTX for the static chain value that should be passed to the function
10215 +when it is called.
10216 +*/
10217 +#define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, STATIC_CHAIN) \
10218 + avr32_initialize_trampoline(ADDR, FNADDR, STATIC_CHAIN)
10219 +
10220 +
10221 +/******************************************************************************
10222 + * Implicit Calls to Library Routines
10223 + *****************************************************************************/
10224 +
10225 +/* Tail calling. */
10226 +
10227 +/* A C expression that evaluates to true if it is ok to perform a sibling
10228 + call to DECL. */
10229 +#define FUNCTION_OK_FOR_SIBCALL(DECL) 0
10230 +
10231 +#define OVERRIDE_OPTIONS avr32_override_options ()
10232 +
10233 +#define OPTIMIZATION_OPTIONS(LEVEL, SIZE) avr32_optimization_options (LEVEL, SIZE)
10234 +
10235 +/******************************************************************************
10236 + * Addressing Modes
10237 + *****************************************************************************/
10238 +
10239 +/*
10240 +A C expression that is nonzero if the machine supports pre-increment,
10241 +pre-decrement, post-increment, or post-decrement addressing respectively.
10242 +*/
10243 +/*
10244 + AVR32 supports Rp++ and --Rp
10245 +*/
10246 +#define HAVE_PRE_INCREMENT 0
10247 +#define HAVE_PRE_DECREMENT 1
10248 +#define HAVE_POST_INCREMENT 1
10249 +#define HAVE_POST_DECREMENT 0
10250 +
10251 +/*
10252 +A C expression that is nonzero if the machine supports pre- or
10253 +post-address side-effect generation involving constants other than
10254 +the size of the memory operand.
10255 +*/
10256 +#define HAVE_PRE_MODIFY_DISP 0
10257 +#define HAVE_POST_MODIFY_DISP 0
10258 +
10259 +/*
10260 +A C expression that is nonzero if the machine supports pre- or
10261 +post-address side-effect generation involving a register displacement.
10262 +*/
10263 +#define HAVE_PRE_MODIFY_REG 0
10264 +#define HAVE_POST_MODIFY_REG 0
10265 +
10266 +/*
10267 +A C expression that is 1 if the RTX X is a constant which
10268 +is a valid address. On most machines, this can be defined as
10269 +CONSTANT_P (X), but a few machines are more restrictive
10270 +in which constant addresses are supported.
10271 +
10272 +CONSTANT_P accepts integer-values expressions whose values are
10273 +not explicitly known, such as symbol_ref, label_ref, and
10274 +high expressions and const arithmetic expressions, in
10275 +addition to const_int and const_double expressions.
10276 +*/
10277 +#define CONSTANT_ADDRESS_P(X) CONSTANT_P(X)
10278 +
10279 +/*
10280 +A number, the maximum number of registers that can appear in a valid
10281 +memory address. Note that it is up to you to specify a value equal to
10282 +the maximum number that GO_IF_LEGITIMATE_ADDRESS would ever
10283 +accept.
10284 +*/
10285 +#define MAX_REGS_PER_ADDRESS 2
10286 +
10287 +/*
10288 +A C compound statement with a conditional goto LABEL;
10289 +executed if X (an RTX) is a legitimate memory address on the
10290 +target machine for a memory operand of mode MODE.
10291 +
10292 +It usually pays to define several simpler macros to serve as
10293 +subroutines for this one. Otherwise it may be too complicated to
10294 +understand.
10295 +
10296 +This macro must exist in two variants: a strict variant and a
10297 +non-strict one. The strict variant is used in the reload pass. It
10298 +must be defined so that any pseudo-register that has not been
10299 +allocated a hard register is considered a memory reference. In
10300 +contexts where some kind of register is required, a pseudo-register
10301 +with no hard register must be rejected.
10302 +
10303 +The non-strict variant is used in other passes. It must be defined to
10304 +accept all pseudo-registers in every context where some kind of
10305 +register is required.
10306 +
10307 +Compiler source files that want to use the strict variant of this
10308 +macro define the macro REG_OK_STRICT. You should use an
10309 +#ifdef REG_OK_STRICT conditional to define the strict variant
10310 +in that case and the non-strict variant otherwise.
10311 +
10312 +Subroutines to check for acceptable registers for various purposes (one
10313 +for base registers, one for index registers, and so on) are typically
10314 +among the subroutines used to define GO_IF_LEGITIMATE_ADDRESS.
10315 +Then only these subroutine macros need have two variants; the higher
10316 +levels of macros may be the same whether strict or not.
10317 +
10318 +Normally, constant addresses which are the sum of a symbol_ref
10319 +and an integer are stored inside a const RTX to mark them as
10320 +constant. Therefore, there is no need to recognize such sums
10321 +specifically as legitimate addresses. Normally you would simply
10322 +recognize any const as legitimate.
10323 +
10324 +Usually PRINT_OPERAND_ADDRESS is not prepared to handle constant
10325 +sums that are not marked with const. It assumes that a naked
10326 +plus indicates indexing. If so, then you must reject such
10327 +naked constant sums as illegitimate addresses, so that none of them will
10328 +be given to PRINT_OPERAND_ADDRESS.
10329 +
10330 +On some machines, whether a symbolic address is legitimate depends on
10331 +the section that the address refers to. On these machines, define the
10332 +macro ENCODE_SECTION_INFO to store the information into the
10333 +symbol_ref, and then check for it here. When you see a
10334 +const, you will have to look inside it to find the
10335 +symbol_ref in order to determine the section.
10336 +
10337 +The best way to modify the name string is by adding text to the
10338 +beginning, with suitable punctuation to prevent any ambiguity. Allocate
10339 +the new name in saveable_obstack. You will have to modify
10340 +ASM_OUTPUT_LABELREF to remove and decode the added text and
10341 +output the name accordingly, and define STRIP_NAME_ENCODING to
10342 +access the original name string.
10343 +
10344 +You can check the information stored here into the symbol_ref in
10345 +the definitions of the macros GO_IF_LEGITIMATE_ADDRESS and
10346 +PRINT_OPERAND_ADDRESS.
10347 +*/
10348 +#ifdef REG_OK_STRICT
10349 +# define GO_IF_LEGITIMATE_ADDRESS(MODE, X, LABEL) \
10350 + do \
10351 + { \
10352 + if (avr32_legitimate_address(MODE, X, 1)) \
10353 + goto LABEL; \
10354 + } \
10355 + while (0)
10356 +#else
10357 +# define GO_IF_LEGITIMATE_ADDRESS(MODE, X, LABEL) \
10358 + do \
10359 + { \
10360 + if (avr32_legitimate_address(MODE, X, 0)) \
10361 + goto LABEL; \
10362 + } \
10363 + while (0)
10364 +#endif
10365 +
10366 +
10367 +
10368 +/*
10369 +A C compound statement that attempts to replace X with a valid
10370 +memory address for an operand of mode MODE. win will be a
10371 +C statement label elsewhere in the code; the macro definition may use
10372 +
10373 + GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN);
10374 +
10375 +to avoid further processing if the address has become legitimate.
10376 +
10377 +X will always be the result of a call to break_out_memory_refs,
10378 +and OLDX will be the operand that was given to that function to produce
10379 +X.
10380 +
10381 +The code generated by this macro should not alter the substructure of
10382 +X. If it transforms X into a more legitimate form, it
10383 +should assign X (which will always be a C variable) a new value.
10384 +
10385 +It is not necessary for this macro to come up with a legitimate
10386 +address. The compiler has standard ways of doing so in all cases. In
10387 +fact, it is safe for this macro to do nothing. But often a
10388 +machine-dependent strategy can generate better code.
10389 +*/
10390 +#define LEGITIMIZE_ADDRESS(X, OLDX, MODE, WIN) \
10391 + do \
10392 + { \
10393 + if (GET_CODE(X) == PLUS \
10394 + && GET_CODE(XEXP(X, 0)) == REG \
10395 + && GET_CODE(XEXP(X, 1)) == CONST_INT \
10396 + && !CONST_OK_FOR_CONSTRAINT_P(INTVAL(XEXP(X, 1)), \
10397 + 'K', "Ks16")) \
10398 + { \
10399 + rtx index = force_reg(SImode, XEXP(X, 1)); \
10400 + X = gen_rtx_PLUS( SImode, XEXP(X, 0), index); \
10401 + } \
10402 + GO_IF_LEGITIMATE_ADDRESS(MODE, X, WIN); \
10403 + } \
10404 + while(0)
10405 +
10406 +
10407 +/*
10408 +A C statement or compound statement with a conditional
10409 +goto LABEL; executed if memory address X (an RTX) can have
10410 +different meanings depending on the machine mode of the memory
10411 +reference it is used for or if the address is valid for some modes
10412 +but not others.
10413 +
10414 +Autoincrement and autodecrement addresses typically have mode-dependent
10415 +effects because the amount of the increment or decrement is the size
10416 +of the operand being addressed. Some machines have other mode-dependent
10417 +addresses. Many RISC machines have no mode-dependent addresses.
10418 +
10419 +You may assume that ADDR is a valid address for the machine.
10420 +*/
10421 +#define GO_IF_MODE_DEPENDENT_ADDRESS(ADDR, LABEL) \
10422 + do \
10423 + { \
10424 + if (GET_CODE (ADDR) == POST_INC \
10425 + || GET_CODE (ADDR) == PRE_DEC) \
10426 + goto LABEL; \
10427 + } \
10428 + while (0)
10429 +
10430 +/*
10431 +A C expression that is nonzero if X is a legitimate constant for
10432 +an immediate operand on the target machine. You can assume that
10433 +X satisfies CONSTANT_P, so you need not check this. In fact,
10434 +'1' is a suitable definition for this macro on machines where
10435 +anything CONSTANT_P is valid.
10436 +*/
10437 +#define LEGITIMATE_CONSTANT_P(X) avr32_legitimate_constant_p(X)
10438 +
10439 +
10440 +/******************************************************************************
10441 + * Condition Code Status
10442 + *****************************************************************************/
10443 +
10444 +/*
10445 +C code for a data type which is used for declaring the mdep
10446 +component of cc_status. It defaults to int.
10447 +
10448 +This macro is not used on machines that do not use cc0.
10449 +*/
10450 +
10451 +typedef struct
10452 +{
10453 + int flags;
10454 + rtx value;
10455 + int cond_exec_cmp_clobbered;
10456 +} avr32_status_reg;
10457 +
10458 +
10459 +#define CC_STATUS_MDEP avr32_status_reg
10460 +
10461 +/*
10462 +A C expression to initialize the mdep field to "empty".
10463 +The default definition does nothing, since most machines don't use
10464 +the field anyway. If you want to use the field, you should probably
10465 +define this macro to initialize it.
10466 +
10467 +This macro is not used on machines that do not use cc0.
10468 +*/
10469 +
10470 +#define CC_STATUS_MDEP_INIT \
10471 + (cc_status.mdep.flags = CC_NONE , cc_status.mdep.cond_exec_cmp_clobbered = 0, cc_status.mdep.value = 0)
10472 +
10473 +/*
10474 +A C compound statement to set the components of cc_status
10475 +appropriately for an insn INSN whose body is EXP. It is
10476 +this macro's responsibility to recognize insns that set the condition
10477 +code as a byproduct of other activity as well as those that explicitly
10478 +set (cc0).
10479 +
10480 +This macro is not used on machines that do not use cc0.
10481 +
10482 +If there are insns that do not set the condition code but do alter
10483 +other machine registers, this macro must check to see whether they
10484 +invalidate the expressions that the condition code is recorded as
10485 +reflecting. For example, on the 68000, insns that store in address
10486 +registers do not set the condition code, which means that usually
10487 +NOTICE_UPDATE_CC can leave cc_status unaltered for such
10488 +insns. But suppose that the previous insn set the condition code
10489 +based on location 'a4@@(102)' and the current insn stores a new
10490 +value in 'a4'. Although the condition code is not changed by
10491 +this, it will no longer be true that it reflects the contents of
10492 +'a4@@(102)'. Therefore, NOTICE_UPDATE_CC must alter
10493 +cc_status in this case to say that nothing is known about the
10494 +condition code value.
10495 +
10496 +The definition of NOTICE_UPDATE_CC must be prepared to deal
10497 +with the results of peephole optimization: insns whose patterns are
10498 +parallel RTXs containing various reg, mem or
10499 +constants which are just the operands. The RTL structure of these
10500 +insns is not sufficient to indicate what the insns actually do. What
10501 +NOTICE_UPDATE_CC should do when it sees one is just to run
10502 +CC_STATUS_INIT.
10503 +
10504 +A possible definition of NOTICE_UPDATE_CC is to call a function
10505 +that looks at an attribute (see Insn Attributes) named, for example,
10506 +'cc'. This avoids having detailed information about patterns in
10507 +two places, the 'md' file and in NOTICE_UPDATE_CC.
10508 +*/
10509 +
10510 +#define NOTICE_UPDATE_CC(EXP, INSN) avr32_notice_update_cc(EXP, INSN)
10511 +
10512 +
10513 +
10514 +
10515 +/******************************************************************************
10516 + * Describing Relative Costs of Operations
10517 + *****************************************************************************/
10518 +
10519 +
10520 +
10521 +/*
10522 +A C expression for the cost of moving data of mode MODE from a
10523 +register in class FROM to one in class TO. The classes are
10524 +expressed using the enumeration values such as GENERAL_REGS. A
10525 +value of 2 is the default; other values are interpreted relative to
10526 +that.
10527 +
10528 +It is not required that the cost always equal 2 when FROM is the
10529 +same as TO; on some machines it is expensive to move between
10530 +registers if they are not general registers.
10531 +
10532 +If reload sees an insn consisting of a single set between two
10533 +hard registers, and if REGISTER_MOVE_COST applied to their
10534 +classes returns a value of 2, reload does not check to ensure that the
10535 +constraints of the insn are met. Setting a cost of other than 2 will
10536 +allow reload to verify that the constraints are met. You should do this
10537 +if the movm pattern's constraints do not allow such copying.
10538 +*/
10539 +#define REGISTER_MOVE_COST(MODE, FROM, TO) \
10540 + ((GET_MODE_SIZE(MODE) <= 4) ? 2: \
10541 + (GET_MODE_SIZE(MODE) <= 8) ? 3: \
10542 + 4)
10543 +
10544 +/*
10545 +A C expression for the cost of moving data of mode MODE between a
10546 +register of class CLASS and memory; IN is zero if the value
10547 +is to be written to memory, nonzero if it is to be read in. This cost
10548 +is relative to those in REGISTER_MOVE_COST. If moving between
10549 +registers and memory is more expensive than between two registers, you
10550 +should define this macro to express the relative cost.
10551 +
10552 +If you do not define this macro, GCC uses a default cost of 4 plus
10553 +the cost of copying via a secondary reload register, if one is
10554 +needed. If your machine requires a secondary reload register to copy
10555 +between memory and a register of CLASS but the reload mechanism is
10556 +more complex than copying via an intermediate, define this macro to
10557 +reflect the actual cost of the move.
10558 +
10559 +GCC defines the function memory_move_secondary_cost if
10560 +secondary reloads are needed. It computes the costs due to copying via
10561 +a secondary register. If your machine copies from memory using a
10562 +secondary register in the conventional way but the default base value of
10563 +4 is not correct for your machine, define this macro to add some other
10564 +value to the result of that function. The arguments to that function
10565 +are the same as to this macro.
10566 +*/
10567 +/*
10568 + Memory moves are costly
10569 +*/
10570 +#define MEMORY_MOVE_COST(MODE, CLASS, IN) \
10571 + (((IN) ? ((GET_MODE_SIZE(MODE) < 4) ? 4 : \
10572 + (GET_MODE_SIZE(MODE) > 8) ? 6 : \
10573 + 3) \
10574 + : ((GET_MODE_SIZE(MODE) > 8) ? 6 : 3)))
10575 +
10576 +/*
10577 +A C expression for the cost of a branch instruction. A value of 1 is
10578 +the default; other values are interpreted relative to that.
10579 +*/
10580 + /* Try to use conditionals as much as possible */
10581 +#define BRANCH_COST (TARGET_BRANCH_PRED ? 3 : 4)
10582 +
10583 +/*A C expression for the maximum number of instructions to execute via conditional
10584 + execution instructions instead of a branch. A value of BRANCH_COST+1 is the default
10585 + if the machine does not use cc0, and 1 if it does use cc0.*/
10586 +#define MAX_CONDITIONAL_EXECUTE 4
10587 +
10588 +/*
10589 +Define this macro as a C expression which is nonzero if accessing less
10590 +than a word of memory (i.e.: a char or a short) is no
10591 +faster than accessing a word of memory, i.e., if such access
10592 +require more than one instruction or if there is no difference in cost
10593 +between byte and (aligned) word loads.
10594 +
10595 +When this macro is not defined, the compiler will access a field by
10596 +finding the smallest containing object; when it is defined, a fullword
10597 +load will be used if alignment permits. Unless bytes accesses are
10598 +faster than word accesses, using word accesses is preferable since it
10599 +may eliminate subsequent memory access if subsequent accesses occur to
10600 +other fields in the same word of the structure, but to different bytes.
10601 +*/
10602 +#define SLOW_BYTE_ACCESS 1
10603 +
10604 +
10605 +/*
10606 +Define this macro if it is as good or better to call a constant
10607 +function address than to call an address kept in a register.
10608 +*/
10609 +#define NO_FUNCTION_CSE
10610 +
10611 +
10612 +/******************************************************************************
10613 + * Adjusting the Instruction Scheduler
10614 + *****************************************************************************/
10615 +
10616 +/*****************************************************************************
10617 + * Dividing the Output into Sections (Texts, Data, ...) *
10618 + *****************************************************************************/
10619 +
10620 +/*
10621 +A C expression whose value is a string, including spacing, containing the
10622 +assembler operation that should precede instructions and read-only data.
10623 +Normally "\t.text" is right.
10624 +*/
10625 +#define TEXT_SECTION_ASM_OP "\t.text"
10626 +/*
10627 +A C statement that switches to the default section containing instructions.
10628 +Normally this is not needed, as simply defining TEXT_SECTION_ASM_OP
10629 +is enough. The MIPS port uses this to sort all functions after all data
10630 +declarations.
10631 +*/
10632 +/* #define TEXT_SECTION */
10633 +
10634 +/*
10635 +A C expression whose value is a string, including spacing, containing the
10636 +assembler operation to identify the following data as writable initialized
10637 +data. Normally "\t.data" is right.
10638 +*/
10639 +#define DATA_SECTION_ASM_OP "\t.data"
10640 +
10641 +/*
10642 +If defined, a C expression whose value is a string, including spacing,
10643 +containing the assembler operation to identify the following data as
10644 +shared data. If not defined, DATA_SECTION_ASM_OP will be used.
10645 +*/
10646 +
10647 +/*
10648 +A C expression whose value is a string, including spacing, containing
10649 +the assembler operation to identify the following data as read-only
10650 +initialized data.
10651 +*/
10652 +#undef READONLY_DATA_SECTION_ASM_OP
10653 +#define READONLY_DATA_SECTION_ASM_OP \
10654 + ((TARGET_USE_RODATA_SECTION) ? \
10655 + "\t.section\t.rodata" : \
10656 + TEXT_SECTION_ASM_OP )
10657 +
10658 +
10659 +/*
10660 +If defined, a C expression whose value is a string, including spacing,
10661 +containing the assembler operation to identify the following data as
10662 +uninitialized global data. If not defined, and neither
10663 +ASM_OUTPUT_BSS nor ASM_OUTPUT_ALIGNED_BSS are defined,
10664 +uninitialized global data will be output in the data section if
10665 +-fno-common is passed, otherwise ASM_OUTPUT_COMMON will be
10666 +used.
10667 +*/
10668 +#define BSS_SECTION_ASM_OP "\t.section\t.bss"
10669 +
10670 +/*
10671 +If defined, a C expression whose value is a string, including spacing,
10672 +containing the assembler operation to identify the following data as
10673 +uninitialized global shared data. If not defined, and
10674 +BSS_SECTION_ASM_OP is, the latter will be used.
10675 +*/
10676 +/*#define SHARED_BSS_SECTION_ASM_OP "\trseg\tshared_bbs_section:data:noroot(0)\n"*/
10677 +/*
10678 +If defined, a C expression whose value is a string, including spacing,
10679 +containing the assembler operation to identify the following data as
10680 +initialization code. If not defined, GCC will assume such a section does
10681 +not exist.
10682 +*/
10683 +#undef INIT_SECTION_ASM_OP
10684 +#define INIT_SECTION_ASM_OP "\t.section\t.init"
10685 +
10686 +/*
10687 +If defined, a C expression whose value is a string, including spacing,
10688 +containing the assembler operation to identify the following data as
10689 +finalization code. If not defined, GCC will assume such a section does
10690 +not exist.
10691 +*/
10692 +#undef FINI_SECTION_ASM_OP
10693 +#define FINI_SECTION_ASM_OP "\t.section\t.fini"
10694 +
10695 +/*
10696 +If defined, an ASM statement that switches to a different section
10697 +via SECTION_OP, calls FUNCTION, and switches back to
10698 +the text section. This is used in crtstuff.c if
10699 +INIT_SECTION_ASM_OP or FINI_SECTION_ASM_OP to calls
10700 +to initialization and finalization functions from the init and fini
10701 +sections. By default, this macro uses a simple function call. Some
10702 +ports need hand-crafted assembly code to avoid dependencies on
10703 +registers initialized in the function prologue or to ensure that
10704 +constant pools don't end up too far way in the text section.
10705 +*/
10706 +#define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
10707 + asm ( SECTION_OP "\n" \
10708 + "mcall r6[" USER_LABEL_PREFIX #FUNC "@got]\n" \
10709 + TEXT_SECTION_ASM_OP);
10710 +
10711 +
10712 +/*
10713 +Define this macro to be an expression with a nonzero value if jump
10714 +tables (for tablejump insns) should be output in the text
10715 +section, along with the assembler instructions. Otherwise, the
10716 +readonly data section is used.
10717 +
10718 +This macro is irrelevant if there is no separate readonly data section.
10719 +*/
10720 +/* Put jump tables in text section if we have caches. Otherwise assume that
10721 + loading data from code memory is slow. */
10722 +#define JUMP_TABLES_IN_TEXT_SECTION \
10723 + (TARGET_CACHES ? 1 : 0)
10724 +
10725 +
10726 +/******************************************************************************
10727 + * Position Independent Code (PIC)
10728 + *****************************************************************************/
10729 +
10730 +#ifndef AVR32_ALWAYS_PIC
10731 +#define AVR32_ALWAYS_PIC 0
10732 +#endif
10733 +
10734 +/* GOT is set to r6 */
10735 +#define PIC_OFFSET_TABLE_REGNUM INTERNAL_REGNUM(6)
10736 +
10737 +/*
10738 +A C expression that is nonzero if X is a legitimate immediate
10739 +operand on the target machine when generating position independent code.
10740 +You can assume that X satisfies CONSTANT_P, so you need not
10741 +check this. You can also assume flag_pic is true, so you need not
10742 +check it either. You need not define this macro if all constants
10743 +(including SYMBOL_REF) can be immediate operands when generating
10744 +position independent code.
10745 +*/
10746 +/* We can't directly access anything that contains a symbol,
10747 + nor can we indirect via the constant pool. */
10748 +#define LEGITIMATE_PIC_OPERAND_P(X) avr32_legitimate_pic_operand_p(X)
10749 +
10750 +
10751 +/* We need to know when we are making a constant pool; this determines
10752 + whether data needs to be in the GOT or can be referenced via a GOT
10753 + offset. */
10754 +extern int making_const_table;
10755 +
10756 +/******************************************************************************
10757 + * Defining the Output Assembler Language
10758 + *****************************************************************************/
10759 +
10760 +
10761 +/*
10762 +A C string constant describing how to begin a comment in the target
10763 +assembler language. The compiler assumes that the comment will end at
10764 +the end of the line.
10765 +*/
10766 +#define ASM_COMMENT_START "# "
10767 +
10768 +/*
10769 +A C string constant for text to be output before each asm
10770 +statement or group of consecutive ones. Normally this is
10771 +"#APP", which is a comment that has no effect on most
10772 +assemblers but tells the GNU assembler that it must check the lines
10773 +that follow for all valid assembler constructs.
10774 +*/
10775 +#undef ASM_APP_ON
10776 +#define ASM_APP_ON "#APP\n"
10777 +
10778 +/*
10779 +A C string constant for text to be output after each asm
10780 +statement or group of consecutive ones. Normally this is
10781 +"#NO_APP", which tells the GNU assembler to resume making the
10782 +time-saving assumptions that are valid for ordinary compiler output.
10783 +*/
10784 +#undef ASM_APP_OFF
10785 +#define ASM_APP_OFF "#NO_APP\n"
10786 +
10787 +
10788 +
10789 +#define FILE_ASM_OP "\t.file\n"
10790 +#define IDENT_ASM_OP "\t.ident\t"
10791 +#define SET_ASM_OP "\t.set\t"
10792 +
10793 +
10794 +/*
10795 + * Output assembly directives to switch to section name. The section
10796 + * should have attributes as specified by flags, which is a bit mask
10797 + * of the SECTION_* flags defined in 'output.h'. If align is nonzero,
10798 + * it contains an alignment in bytes to be used for the section,
10799 + * otherwise some target default should be used. Only targets that
10800 + * must specify an alignment within the section directive need pay
10801 + * attention to align -- we will still use ASM_OUTPUT_ALIGN.
10802 + *
10803 + * NOTE: This one must not be moved to avr32.c
10804 + */
10805 +#undef TARGET_ASM_NAMED_SECTION
10806 +#define TARGET_ASM_NAMED_SECTION default_elf_asm_named_section
10807 +
10808 +
10809 +/*
10810 +You may define this macro as a C expression. You should define the
10811 +expression to have a nonzero value if GCC should output the constant
10812 +pool for a function before the code for the function, or a zero value if
10813 +GCC should output the constant pool after the function. If you do
10814 +not define this macro, the usual case, GCC will output the constant
10815 +pool before the function.
10816 +*/
10817 +#define CONSTANT_POOL_BEFORE_FUNCTION 0
10818 +
10819 +
10820 +/*
10821 +Define this macro as a C expression which is nonzero if the constant
10822 +EXP, of type tree, should be output after the code for a
10823 +function. The compiler will normally output all constants before the
10824 +function; you need not define this macro if this is OK.
10825 +*/
10826 +#define CONSTANT_AFTER_FUNCTION_P(EXP) 1
10827 +
10828 +
10829 +/*
10830 +Define this macro as a C expression which is nonzero if C is
10831 +as a logical line separator by the assembler. STR points to the
10832 +position in the string where C was found; this can be used if a
10833 +line separator uses multiple characters.
10834 +
10835 +If you do not define this macro, the default is that only
10836 +the character ';' is treated as a logical line separator.
10837 +*/
10838 +#define IS_ASM_LOGICAL_LINE_SEPARATOR(C,STR) (((C) == '\n') || ((C) == ';'))
10839 +
10840 +
10841 +/** Output of Uninitialized Variables **/
10842 +
10843 +/*
10844 +A C statement (sans semicolon) to output to the stdio stream
10845 +STREAM the assembler definition of a common-label named
10846 +NAME whose size is SIZE bytes. The variable ROUNDED
10847 +is the size rounded up to whatever alignment the caller wants.
10848 +
10849 +Use the expression assemble_name(STREAM, NAME) to
10850 +output the name itself; before and after that, output the additional
10851 +assembler syntax for defining the name, and a newline.
10852 +
10853 +This macro controls how the assembler definitions of uninitialized
10854 +common global variables are output.
10855 +*/
10856 +/*
10857 +#define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED) \
10858 + avr32_asm_output_common(STREAM, NAME, SIZE, ROUNDED)
10859 +*/
10860 +
10861 +#define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \
10862 + do \
10863 + { \
10864 + fputs ("\t.comm ", (FILE)); \
10865 + assemble_name ((FILE), (NAME)); \
10866 + fprintf ((FILE), ",%d\n", (SIZE)); \
10867 + } \
10868 + while (0)
10869 +
10870 +/*
10871 + * Like ASM_OUTPUT_BSS except takes the required alignment as a
10872 + * separate, explicit argument. If you define this macro, it is used
10873 + * in place of ASM_OUTPUT_BSS, and gives you more flexibility in
10874 + * handling the required alignment of the variable. The alignment is
10875 + * specified as the number of bits.
10876 + *
10877 + * Try to use function asm_output_aligned_bss defined in file varasm.c
10878 + * when defining this macro.
10879 + */
10880 +#define ASM_OUTPUT_ALIGNED_BSS(STREAM, DECL, NAME, SIZE, ALIGNMENT) \
10881 + asm_output_aligned_bss (STREAM, DECL, NAME, SIZE, ALIGNMENT)
10882 +
10883 +/*
10884 +A C statement (sans semicolon) to output to the stdio stream
10885 +STREAM the assembler definition of a local-common-label named
10886 +NAME whose size is SIZE bytes. The variable ROUNDED
10887 +is the size rounded up to whatever alignment the caller wants.
10888 +
10889 +Use the expression assemble_name(STREAM, NAME) to
10890 +output the name itself; before and after that, output the additional
10891 +assembler syntax for defining the name, and a newline.
10892 +
10893 +This macro controls how the assembler definitions of uninitialized
10894 +static variables are output.
10895 +*/
10896 +#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \
10897 + do \
10898 + { \
10899 + fputs ("\t.lcomm ", (FILE)); \
10900 + assemble_name ((FILE), (NAME)); \
10901 + fprintf ((FILE), ",%d, %d\n", (SIZE), 2); \
10902 + } \
10903 + while (0)
10904 +
10905 +
10906 +/*
10907 +A C statement (sans semicolon) to output to the stdio stream
10908 +STREAM the assembler definition of a label named NAME.
10909 +Use the expression assemble_name(STREAM, NAME) to
10910 +output the name itself; before and after that, output the additional
10911 +assembler syntax for defining the name, and a newline.
10912 +*/
10913 +#define ASM_OUTPUT_LABEL(STREAM, NAME) avr32_asm_output_label(STREAM, NAME)
10914 +
10915 +/* A C string containing the appropriate assembler directive to
10916 + * specify the size of a symbol, without any arguments. On systems
10917 + * that use ELF, the default (in 'config/elfos.h') is '"\t.size\t"';
10918 + * on other systems, the default is not to define this macro.
10919 + *
10920 + * Define this macro only if it is correct to use the default
10921 + * definitions of ASM_ OUTPUT_SIZE_DIRECTIVE and
10922 + * ASM_OUTPUT_MEASURED_SIZE for your system. If you need your own
10923 + * custom definitions of those macros, or if you do not need explicit
10924 + * symbol sizes at all, do not define this macro.
10925 + */
10926 +#define SIZE_ASM_OP "\t.size\t"
10927 +
10928 +
10929 +/*
10930 +A C statement (sans semicolon) to output to the stdio stream
10931 +STREAM some commands that will make the label NAME global;
10932 +that is, available for reference from other files. Use the expression
10933 +assemble_name(STREAM, NAME) to output the name
10934 +itself; before and after that, output the additional assembler syntax
10935 +for making that name global, and a newline.
10936 +*/
10937 +#define GLOBAL_ASM_OP "\t.global\t"
10938 +
10939 +
10940 +
10941 +/*
10942 +A C expression which evaluates to true if the target supports weak symbols.
10943 +
10944 +If you don't define this macro, defaults.h provides a default
10945 +definition. If either ASM_WEAKEN_LABEL or ASM_WEAKEN_DECL
10946 +is defined, the default definition is '1'; otherwise, it is
10947 +'0'. Define this macro if you want to control weak symbol support
10948 +with a compiler flag such as -melf.
10949 +*/
10950 +#define SUPPORTS_WEAK 1
10951 +
10952 +/*
10953 +A C statement (sans semicolon) to output to the stdio stream
10954 +STREAM a reference in assembler syntax to a label named
10955 +NAME. This should add '_' to the front of the name, if that
10956 +is customary on your operating system, as it is in most Berkeley Unix
10957 +systems. This macro is used in assemble_name.
10958 +*/
10959 +#define ASM_OUTPUT_LABELREF(STREAM, NAME) \
10960 + avr32_asm_output_labelref(STREAM, NAME)
10961 +
10962 +
10963 +
10964 +/*
10965 +A C expression to assign to OUTVAR (which is a variable of type
10966 +char *) a newly allocated string made from the string
10967 +NAME and the number NUMBER, with some suitable punctuation
10968 +added. Use alloca to get space for the string.
10969 +
10970 +The string will be used as an argument to ASM_OUTPUT_LABELREF to
10971 +produce an assembler label for an internal static variable whose name is
10972 +NAME. Therefore, the string must be such as to result in valid
10973 +assembler code. The argument NUMBER is different each time this
10974 +macro is executed; it prevents conflicts between similarly-named
10975 +internal static variables in different scopes.
10976 +
10977 +Ideally this string should not be a valid C identifier, to prevent any
10978 +conflict with the user's own symbols. Most assemblers allow periods
10979 +or percent signs in assembler symbols; putting at least one of these
10980 +between the name and the number will suffice.
10981 +*/
10982 +#define ASM_FORMAT_PRIVATE_NAME(OUTVAR, NAME, NUMBER) \
10983 + do \
10984 + { \
10985 + (OUTVAR) = (char *) alloca (strlen ((NAME)) + 10); \
10986 + sprintf ((OUTVAR), "%s.%d", (NAME), (NUMBER)); \
10987 + } \
10988 + while (0)
10989 +
10990 +
10991 +/** Macros Controlling Initialization Routines **/
10992 +
10993 +
10994 +/*
10995 +If defined, main will not call __main as described above.
10996 +This macro should be defined for systems that control start-up code
10997 +on a symbol-by-symbol basis, such as OSF/1, and should not
10998 +be defined explicitly for systems that support INIT_SECTION_ASM_OP.
10999 +*/
11000 +/*
11001 + __main is not defined when debugging.
11002 +*/
11003 +#define HAS_INIT_SECTION
11004 +
11005 +
11006 +/** Output of Assembler Instructions **/
11007 +
11008 +/*
11009 +A C initializer containing the assembler's names for the machine
11010 +registers, each one as a C string constant. This is what translates
11011 +register numbers in the compiler into assembler language.
11012 +*/
11013 +
11014 +#define REGISTER_NAMES \
11015 +{ \
11016 + "pc", "lr", \
11017 + "sp", "r12", \
11018 + "r11", "r10", \
11019 + "r9", "r8", \
11020 + "r7", "r6", \
11021 + "r5", "r4", \
11022 + "r3", "r2", \
11023 + "r1", "r0", \
11024 +}
11025 +
11026 +/*
11027 +A C compound statement to output to stdio stream STREAM the
11028 +assembler syntax for an instruction operand X. X is an
11029 +RTL expression.
11030 +
11031 +CODE is a value that can be used to specify one of several ways
11032 +of printing the operand. It is used when identical operands must be
11033 +printed differently depending on the context. CODE comes from
11034 +the '%' specification that was used to request printing of the
11035 +operand. If the specification was just '%digit' then
11036 +CODE is 0; if the specification was '%ltr digit'
11037 +then CODE is the ASCII code for ltr.
11038 +
11039 +If X is a register, this macro should print the register's name.
11040 +The names can be found in an array reg_names whose type is
11041 +char *[]. reg_names is initialized from REGISTER_NAMES.
11042 +
11043 +When the machine description has a specification '%punct'
11044 +(a '%' followed by a punctuation character), this macro is called
11045 +with a null pointer for X and the punctuation character for
11046 +CODE.
11047 +*/
11048 +#define PRINT_OPERAND(STREAM, X, CODE) avr32_print_operand(STREAM, X, CODE)
11049 +
11050 +/* A C statement to be executed just prior to the output of
11051 + assembler code for INSN, to modify the extracted operands so
11052 + they will be output differently.
11053 +
11054 + Here the argument OPVEC is the vector containing the operands
11055 + extracted from INSN, and NOPERANDS is the number of elements of
11056 + the vector which contain meaningful data for this insn.
11057 + The contents of this vector are what will be used to convert the insn
11058 + template into assembler code, so you can change the assembler output
11059 + by changing the contents of the vector. */
11060 +#define FINAL_PRESCAN_INSN(INSN, OPVEC, NOPERANDS) \
11061 + avr32_final_prescan_insn ((INSN), (OPVEC), (NOPERANDS))
11062 +
11063 +/*
11064 +A C expression which evaluates to true if CODE is a valid
11065 +punctuation character for use in the PRINT_OPERAND macro. If
11066 +PRINT_OPERAND_PUNCT_VALID_P is not defined, it means that no
11067 +punctuation characters (except for the standard one, '%') are used
11068 +in this way.
11069 +*/
11070 +#define PRINT_OPERAND_PUNCT_VALID_P(CODE) \
11071 + (((CODE) == '?') \
11072 + || ((CODE) == '!'))
11073 +
11074 +/*
11075 +A C compound statement to output to stdio stream STREAM the
11076 +assembler syntax for an instruction operand that is a memory reference
11077 +whose address is X. X is an RTL expression.
11078 +
11079 +On some machines, the syntax for a symbolic address depends on the
11080 +section that the address refers to. On these machines, define the macro
11081 +ENCODE_SECTION_INFO to store the information into the
11082 +symbol_ref, and then check for it here. (see Assembler Format.)
11083 +*/
11084 +#define PRINT_OPERAND_ADDRESS(STREAM, X) avr32_print_operand_address(STREAM, X)
11085 +
11086 +
11087 +/** Output of Dispatch Tables **/
11088 +
11089 +/*
11090 + * A C statement to output to the stdio stream stream an assembler
11091 + * pseudo-instruction to generate a difference between two
11092 + * labels. value and rel are the numbers of two internal labels. The
11093 + * definitions of these labels are output using
11094 + * (*targetm.asm_out.internal_label), and they must be printed in the
11095 + * same way here. For example,
11096 + *
11097 + * fprintf (stream, "\t.word L%d-L%d\n",
11098 + * value, rel)
11099 + *
11100 + * You must provide this macro on machines where the addresses in a
11101 + * dispatch table are relative to the table's own address. If defined,
11102 + * GCC will also use this macro on all machines when producing
11103 + * PIC. body is the body of the ADDR_DIFF_VEC; it is provided so that
11104 + * the mode and flags can be read.
11105 + */
11106 +#define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM, BODY, VALUE, REL) \
11107 + fprintf(STREAM, "\tbral\t%sL%d\n", LOCAL_LABEL_PREFIX, VALUE)
11108 +
11109 +/*
11110 +This macro should be provided on machines where the addresses
11111 +in a dispatch table are absolute.
11112 +
11113 +The definition should be a C statement to output to the stdio stream
11114 +STREAM an assembler pseudo-instruction to generate a reference to
11115 +a label. VALUE is the number of an internal label whose
11116 +definition is output using ASM_OUTPUT_INTERNAL_LABEL.
11117 +For example,
11118 +
11119 +fprintf(STREAM, "\t.word L%d\n", VALUE)
11120 +*/
11121 +
11122 +#define ASM_OUTPUT_ADDR_VEC_ELT(STREAM, VALUE) \
11123 + fprintf(STREAM, "\t.long %sL%d\n", LOCAL_LABEL_PREFIX, VALUE)
11124 +
11125 +/** Assembler Commands for Exception Regions */
11126 +
11127 +/* ToDo: All of this subsection */
11128 +
11129 +/** Assembler Commands for Alignment */
11130 +
11131 +
11132 +/*
11133 +A C statement to output to the stdio stream STREAM an assembler
11134 +command to advance the location counter to a multiple of 2 to the
11135 +POWER bytes. POWER will be a C expression of type int.
11136 +*/
11137 +#define ASM_OUTPUT_ALIGN(STREAM, POWER) \
11138 + do \
11139 + { \
11140 + if ((POWER) != 0) \
11141 + fprintf(STREAM, "\t.align\t%d\n", POWER); \
11142 + } \
11143 + while (0)
11144 +
11145 +/*
11146 +Like ASM_OUTPUT_ALIGN, except that the \nop" instruction is used for padding, if
11147 +necessary.
11148 +*/
11149 +#define ASM_OUTPUT_ALIGN_WITH_NOP(STREAM, POWER) \
11150 + fprintf(STREAM, "\t.balignw\t%d, 0xd703\n", (1 << POWER))
11151 +
11152 +
11153 +
11154 +/******************************************************************************
11155 + * Controlling Debugging Information Format
11156 + *****************************************************************************/
11157 +
11158 +/* How to renumber registers for dbx and gdb. */
11159 +#define DBX_REGISTER_NUMBER(REGNO) ASM_REGNUM (REGNO)
11160 +
11161 +/* The DWARF 2 CFA column which tracks the return address. */
11162 +#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM(LR_REGNUM)
11163 +
11164 +/*
11165 +Define this macro if GCC should produce dwarf version 2 format
11166 +debugging output in response to the -g option.
11167 +
11168 +To support optional call frame debugging information, you must also
11169 +define INCOMING_RETURN_ADDR_RTX and either set
11170 +RTX_FRAME_RELATED_P on the prologue insns if you use RTL for the
11171 +prologue, or call dwarf2out_def_cfa and dwarf2out_reg_save
11172 +as appropriate from TARGET_ASM_FUNCTION_PROLOGUE if you don't.
11173 +*/
11174 +#define DWARF2_DEBUGGING_INFO 1
11175 +
11176 +
11177 +#define DWARF2_ASM_LINE_DEBUG_INFO 1
11178 +#define DWARF2_FRAME_INFO 1
11179 +
11180 +
11181 +/******************************************************************************
11182 + * Miscellaneous Parameters
11183 + *****************************************************************************/
11184 +
11185 +/* ToDo: a lot */
11186 +
11187 +/*
11188 +An alias for a machine mode name. This is the machine mode that
11189 +elements of a jump-table should have.
11190 +*/
11191 +#define CASE_VECTOR_MODE SImode
11192 +
11193 +/*
11194 +Define this macro to be a C expression to indicate when jump-tables
11195 +should contain relative addresses. If jump-tables never contain
11196 +relative addresses, then you need not define this macro.
11197 +*/
11198 +#define CASE_VECTOR_PC_RELATIVE 0
11199 +
11200 +/* Increase the threshold for using table jumps on the UC arch. */
11201 +#define CASE_VALUES_THRESHOLD (TARGET_BRANCH_PRED ? 4 : 7)
11202 +
11203 +/*
11204 +The maximum number of bytes that a single instruction can move quickly
11205 +between memory and registers or between two memory locations.
11206 +*/
11207 +#define MOVE_MAX (2*UNITS_PER_WORD)
11208 +
11209 +
11210 +/* A C expression that is nonzero if on this machine the number of bits actually used
11211 + for the count of a shift operation is equal to the number of bits needed to represent
11212 + the size of the object being shifted. When this macro is nonzero, the compiler will
11213 + assume that it is safe to omit a sign-extend, zero-extend, and certain bitwise 'and'
11214 + instructions that truncates the count of a shift operation. On machines that have
11215 + instructions that act on bit-fields at variable positions, which may include 'bit test'
11216 + 378 GNU Compiler Collection (GCC) Internals
11217 + instructions, a nonzero SHIFT_COUNT_TRUNCATED also enables deletion of truncations
11218 + of the values that serve as arguments to bit-field instructions.
11219 + If both types of instructions truncate the count (for shifts) and position (for bit-field
11220 + operations), or if no variable-position bit-field instructions exist, you should define
11221 + this macro.
11222 + However, on some machines, such as the 80386 and the 680x0, truncation only applies
11223 + to shift operations and not the (real or pretended) bit-field operations. Define SHIFT_
11224 + COUNT_TRUNCATED to be zero on such machines. Instead, add patterns to the 'md' file
11225 + that include the implied truncation of the shift instructions.
11226 + You need not de\fne this macro if it would always have the value of zero. */
11227 +#define SHIFT_COUNT_TRUNCATED 1
11228 +
11229 +/*
11230 +A C expression which is nonzero if on this machine it is safe to
11231 +convert an integer of INPREC bits to one of OUTPREC
11232 +bits (where OUTPREC is smaller than INPREC) by merely
11233 +operating on it as if it had only OUTPREC bits.
11234 +
11235 +On many machines, this expression can be 1.
11236 +
11237 +When TRULY_NOOP_TRUNCATION returns 1 for a pair of sizes for
11238 +modes for which MODES_TIEABLE_P is 0, suboptimal code can result.
11239 +If this is the case, making TRULY_NOOP_TRUNCATION return 0 in
11240 +such cases may improve things.
11241 +*/
11242 +#define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
11243 +
11244 +/*
11245 +An alias for the machine mode for pointers. On most machines, define
11246 +this to be the integer mode corresponding to the width of a hardware
11247 +pointer; SImode on 32-bit machine or DImode on 64-bit machines.
11248 +On some machines you must define this to be one of the partial integer
11249 +modes, such as PSImode.
11250 +
11251 +The width of Pmode must be at least as large as the value of
11252 +POINTER_SIZE. If it is not equal, you must define the macro
11253 +POINTERS_EXTEND_UNSIGNED to specify how pointers are extended
11254 +to Pmode.
11255 +*/
11256 +#define Pmode SImode
11257 +
11258 +/*
11259 +An alias for the machine mode used for memory references to functions
11260 +being called, in call RTL expressions. On most machines this
11261 +should be QImode.
11262 +*/
11263 +#define FUNCTION_MODE SImode
11264 +
11265 +
11266 +#define REG_S_P(x) \
11267 + (REG_P (x) || (GET_CODE (x) == SUBREG && REG_P (XEXP (x, 0))))
11268 +
11269 +
11270 +/* If defined, modifies the length assigned to instruction INSN as a
11271 + function of the context in which it is used. LENGTH is an lvalue
11272 + that contains the initially computed length of the insn and should
11273 + be updated with the correct length of the insn. */
11274 +#define ADJUST_INSN_LENGTH(INSN, LENGTH) \
11275 + ((LENGTH) = avr32_adjust_insn_length ((INSN), (LENGTH)))
11276 +
11277 +
11278 +#define CLZ_DEFINED_VALUE_AT_ZERO(mode, value) \
11279 + (value = 32, (mode == SImode))
11280 +
11281 +#define CTZ_DEFINED_VALUE_AT_ZERO(mode, value) \
11282 + (value = 32, (mode == SImode))
11283 +
11284 +#define UNITS_PER_SIMD_WORD UNITS_PER_WORD
11285 +
11286 +#define STORE_FLAG_VALUE 1
11287 +
11288 +
11289 +/* IF-conversion macros. */
11290 +#define IFCVT_MODIFY_INSN( CE_INFO, PATTERN, INSN ) \
11291 + { \
11292 + (PATTERN) = avr32_ifcvt_modify_insn (CE_INFO, PATTERN, INSN, &num_true_changes); \
11293 + }
11294 +
11295 +#define IFCVT_EXTRA_FIELDS \
11296 + int num_cond_clobber_insns; \
11297 + int num_extra_move_insns; \
11298 + rtx extra_move_insns[MAX_CONDITIONAL_EXECUTE]; \
11299 + rtx moved_insns[MAX_CONDITIONAL_EXECUTE];
11300 +
11301 +#define IFCVT_INIT_EXTRA_FIELDS( CE_INFO ) \
11302 + { \
11303 + (CE_INFO)->num_cond_clobber_insns = 0; \
11304 + (CE_INFO)->num_extra_move_insns = 0; \
11305 + }
11306 +
11307 +
11308 +#define IFCVT_MODIFY_CANCEL( CE_INFO ) avr32_ifcvt_modify_cancel (CE_INFO, &num_true_changes)
11309 +
11310 +#define IFCVT_ALLOW_MODIFY_TEST_IN_INSN 1
11311 +#define IFCVT_COND_EXEC_BEFORE_RELOAD (TARGET_COND_EXEC_BEFORE_RELOAD)
11312 +
11313 +enum avr32_builtins
11314 +{
11315 + AVR32_BUILTIN_MTSR,
11316 + AVR32_BUILTIN_MFSR,
11317 + AVR32_BUILTIN_MTDR,
11318 + AVR32_BUILTIN_MFDR,
11319 + AVR32_BUILTIN_CACHE,
11320 + AVR32_BUILTIN_SYNC,
11321 + AVR32_BUILTIN_SSRF,
11322 + AVR32_BUILTIN_CSRF,
11323 + AVR32_BUILTIN_TLBR,
11324 + AVR32_BUILTIN_TLBS,
11325 + AVR32_BUILTIN_TLBW,
11326 + AVR32_BUILTIN_BREAKPOINT,
11327 + AVR32_BUILTIN_XCHG,
11328 + AVR32_BUILTIN_LDXI,
11329 + AVR32_BUILTIN_BSWAP16,
11330 + AVR32_BUILTIN_BSWAP32,
11331 + AVR32_BUILTIN_COP,
11332 + AVR32_BUILTIN_MVCR_W,
11333 + AVR32_BUILTIN_MVRC_W,
11334 + AVR32_BUILTIN_MVCR_D,
11335 + AVR32_BUILTIN_MVRC_D,
11336 + AVR32_BUILTIN_MULSATHH_H,
11337 + AVR32_BUILTIN_MULSATHH_W,
11338 + AVR32_BUILTIN_MULSATRNDHH_H,
11339 + AVR32_BUILTIN_MULSATRNDWH_W,
11340 + AVR32_BUILTIN_MULSATWH_W,
11341 + AVR32_BUILTIN_MACSATHH_W,
11342 + AVR32_BUILTIN_SATADD_H,
11343 + AVR32_BUILTIN_SATSUB_H,
11344 + AVR32_BUILTIN_SATADD_W,
11345 + AVR32_BUILTIN_SATSUB_W,
11346 + AVR32_BUILTIN_MULWH_D,
11347 + AVR32_BUILTIN_MULNWH_D,
11348 + AVR32_BUILTIN_MACWH_D,
11349 + AVR32_BUILTIN_MACHH_D,
11350 + AVR32_BUILTIN_MUSFR,
11351 + AVR32_BUILTIN_MUSTR,
11352 + AVR32_BUILTIN_SATS,
11353 + AVR32_BUILTIN_SATU,
11354 + AVR32_BUILTIN_SATRNDS,
11355 + AVR32_BUILTIN_SATRNDU,
11356 + AVR32_BUILTIN_MEMS,
11357 + AVR32_BUILTIN_MEMC,
11358 + AVR32_BUILTIN_MEMT,
11359 + AVR32_BUILTIN_SLEEP,
11360 + AVR32_BUILTIN_DELAY_CYCLES
11361 +};
11362 +
11363 +
11364 +#define FLOAT_LIB_COMPARE_RETURNS_BOOL(MODE, COMPARISON) \
11365 + ((MODE == SFmode) || (MODE == DFmode))
11366 +
11367 +#define RENAME_LIBRARY_SET ".set"
11368 +
11369 +/* Make ABI_NAME an alias for __GCC_NAME. */
11370 +#define RENAME_LIBRARY(GCC_NAME, ABI_NAME) \
11371 + __asm__ (".globl\t__avr32_" #ABI_NAME "\n" \
11372 + ".set\t__avr32_" #ABI_NAME \
11373 + ", __" #GCC_NAME "\n");
11374 +
11375 +/* Give libgcc functions avr32 ABI name. */
11376 +#ifdef L_muldi3
11377 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (muldi3, mul64)
11378 +#endif
11379 +#ifdef L_divdi3
11380 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (divdi3, sdiv64)
11381 +#endif
11382 +#ifdef L_udivdi3
11383 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (udivdi3, udiv64)
11384 +#endif
11385 +#ifdef L_moddi3
11386 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (moddi3, smod64)
11387 +#endif
11388 +#ifdef L_umoddi3
11389 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (umoddi3, umod64)
11390 +#endif
11391 +#ifdef L_ashldi3
11392 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (ashldi3, lsl64)
11393 +#endif
11394 +#ifdef L_lshrdi3
11395 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (lshrdi3, lsr64)
11396 +#endif
11397 +#ifdef L_ashrdi3
11398 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (ashrdi3, asr64)
11399 +#endif
11400 +
11401 +#ifdef L_fixsfdi
11402 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (fixsfdi, f32_to_s64)
11403 +#endif
11404 +#ifdef L_fixunssfdi
11405 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (fixunssfdi, f32_to_u64)
11406 +#endif
11407 +#ifdef L_floatdidf
11408 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (floatdidf, s64_to_f64)
11409 +#endif
11410 +#ifdef L_floatdisf
11411 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (floatdisf, s64_to_f32)
11412 +#endif
11413 +
11414 +#endif
11415 --- /dev/null
11416 +++ b/gcc/config/avr32/avr32.md
11417 @@ -0,0 +1,5025 @@
11418 +;; AVR32 machine description file.
11419 +;; Copyright 2003,2004,2005,2006,2007,2008,2009 Atmel Corporation.
11420 +;;
11421 +;; This file is part of GCC.
11422 +;;
11423 +;; This program is free software; you can redistribute it and/or modify
11424 +;; it under the terms of the GNU General Public License as published by
11425 +;; the Free Software Foundation; either version 2 of the License, or
11426 +;; (at your option) any later version.
11427 +;;
11428 +;; This program is distributed in the hope that it will be useful,
11429 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11430 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11431 +;; GNU General Public License for more details.
11432 +;;
11433 +;; You should have received a copy of the GNU General Public License
11434 +;; along with this program; if not, write to the Free Software
11435 +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11436 +
11437 +;; -*- Mode: Scheme -*-
11438 +
11439 +(define_attr "type" "alu,alu2,alu_sat,mulhh,mulwh,mulww_w,mulww_d,div,machh_w,macww_w,macww_d,branch,call,load,load_rm,store,load2,load4,store2,store4,fmul,fcmps,fcmpd,fcast,fmv,fmvcpu,fldd,fstd,flds,fsts,fstm"
11440 + (const_string "alu"))
11441 +
11442 +
11443 +(define_attr "cc" "none,set_vncz,set_ncz,set_cz,set_z,set_z_if_not_v2,bld,compare,cmp_cond_insn,clobber,call_set,fpcompare,from_fpcc"
11444 + (const_string "none"))
11445 +
11446 +
11447 +; NB! Keep this in sync with enum architecture_type in avr32.h
11448 +(define_attr "pipeline" "ap,ucr1,ucr2,ucr2nomul,ucr3,ucr3fp"
11449 + (const (symbol_ref "avr32_arch->arch_type")))
11450 +
11451 +; Insn length in bytes
11452 +(define_attr "length" ""
11453 + (const_int 4))
11454 +
11455 +; Signal if an insn is predicable and hence can be conditionally executed.
11456 +(define_attr "predicable" "no,yes" (const_string "no"))
11457 +
11458 +;; Uses of UNSPEC in this file:
11459 +(define_constants
11460 + [(UNSPEC_PUSHM 0)
11461 + (UNSPEC_POPM 1)
11462 + (UNSPEC_UDIVMODSI4_INTERNAL 2)
11463 + (UNSPEC_DIVMODSI4_INTERNAL 3)
11464 + (UNSPEC_STM 4)
11465 + (UNSPEC_LDM 5)
11466 + (UNSPEC_MOVSICC 6)
11467 + (UNSPEC_ADDSICC 7)
11468 + (UNSPEC_COND_MI 8)
11469 + (UNSPEC_COND_PL 9)
11470 + (UNSPEC_PIC_SYM 10)
11471 + (UNSPEC_PIC_BASE 11)
11472 + (UNSPEC_STORE_MULTIPLE 12)
11473 + (UNSPEC_STMFP 13)
11474 + (UNSPEC_FRCPA 14)
11475 + (UNSPEC_REG_TO_CC 15)
11476 + (UNSPEC_FORCE_MINIPOOL 16)
11477 + (UNSPEC_SATS 17)
11478 + (UNSPEC_SATU 18)
11479 + (UNSPEC_SATRNDS 19)
11480 + (UNSPEC_SATRNDU 20)
11481 + ])
11482 +
11483 +(define_constants
11484 + [(VUNSPEC_EPILOGUE 0)
11485 + (VUNSPEC_CACHE 1)
11486 + (VUNSPEC_MTSR 2)
11487 + (VUNSPEC_MFSR 3)
11488 + (VUNSPEC_BLOCKAGE 4)
11489 + (VUNSPEC_SYNC 5)
11490 + (VUNSPEC_TLBR 6)
11491 + (VUNSPEC_TLBW 7)
11492 + (VUNSPEC_TLBS 8)
11493 + (VUNSPEC_BREAKPOINT 9)
11494 + (VUNSPEC_MTDR 10)
11495 + (VUNSPEC_MFDR 11)
11496 + (VUNSPEC_MVCR 12)
11497 + (VUNSPEC_MVRC 13)
11498 + (VUNSPEC_COP 14)
11499 + (VUNSPEC_ALIGN 15)
11500 + (VUNSPEC_POOL_START 16)
11501 + (VUNSPEC_POOL_END 17)
11502 + (VUNSPEC_POOL_4 18)
11503 + (VUNSPEC_POOL_8 19)
11504 + (VUNSPEC_POOL_16 20)
11505 + (VUNSPEC_MUSFR 21)
11506 + (VUNSPEC_MUSTR 22)
11507 + (VUNSPEC_SYNC_CMPXCHG 23)
11508 + (VUNSPEC_SYNC_SET_LOCK_AND_LOAD 24)
11509 + (VUNSPEC_SYNC_STORE_IF_LOCK 25)
11510 + (VUNSPEC_EH_RETURN 26)
11511 + (VUNSPEC_FRS 27)
11512 + (VUNSPEC_CSRF 28)
11513 + (VUNSPEC_SSRF 29)
11514 + (VUNSPEC_SLEEP 30)
11515 + (VUNSPEC_DELAY_CYCLES 31)
11516 + (VUNSPEC_DELAY_CYCLES_1 32)
11517 + (VUNSPEC_DELAY_CYCLES_2 33)
11518 + (VUNSPEC_NOP 34)
11519 + (VUNSPEC_NOP3 35)
11520 + ])
11521 +
11522 +(define_constants
11523 + [
11524 + ;; R7 = 15-7 = 8
11525 + (FP_REGNUM 8)
11526 + ;; Return Register = R12 = 15 - 12 = 3
11527 + (RETVAL_REGNUM 3)
11528 + ;; SP = R13 = 15 - 13 = 2
11529 + (SP_REGNUM 2)
11530 + ;; LR = R14 = 15 - 14 = 1
11531 + (LR_REGNUM 1)
11532 + ;; PC = R15 = 15 - 15 = 0
11533 + (PC_REGNUM 0)
11534 + ;; FPSR = GENERAL_REGS + 1 = 17
11535 + (FPCC_REGNUM 17)
11536 + ])
11537 +
11538 +
11539 +
11540 +
11541 +;;******************************************************************************
11542 +;; Macros
11543 +;;******************************************************************************
11544 +
11545 +;; Integer Modes for basic alu insns
11546 +(define_mode_iterator INTM [SI HI QI])
11547 +(define_mode_attr alu_cc_attr [(SI "set_vncz") (HI "clobber") (QI "clobber")])
11548 +
11549 +;; Move word modes
11550 +(define_mode_iterator MOVM [SI V2HI V4QI])
11551 +
11552 +;; For mov/addcc insns
11553 +(define_mode_iterator ADDCC [SI HI QI])
11554 +(define_mode_iterator MOVCC [SF SI HI QI])
11555 +(define_mode_iterator CMP [DI SI HI QI])
11556 +(define_mode_attr store_postfix [(SF ".w") (SI ".w") (HI ".h") (QI ".b")])
11557 +(define_mode_attr load_postfix [(SF ".w") (SI ".w") (HI ".sh") (QI ".ub")])
11558 +(define_mode_attr load_postfix_s [(SI ".w") (HI ".sh") (QI ".sb")])
11559 +(define_mode_attr load_postfix_u [(SI ".w") (HI ".uh") (QI ".ub")])
11560 +(define_mode_attr pred_mem_constraint [(SF "RKu11") (SI "RKu11") (HI "RKu10") (QI "RKu09")])
11561 +(define_mode_attr cmp_constraint [(DI "rKu20") (SI "rKs21") (HI "r") (QI "r")])
11562 +(define_mode_attr cmp_predicate [(DI "register_immediate_operand")
11563 + (SI "register_const_int_operand")
11564 + (HI "register_operand")
11565 + (QI "register_operand")])
11566 +(define_mode_attr cmp_length [(DI "6")
11567 + (SI "4")
11568 + (HI "4")
11569 + (QI "4")])
11570 +
11571 +;; For all conditional insns
11572 +(define_code_iterator any_cond [eq ne gt ge lt le gtu geu ltu leu])
11573 +(define_code_attr cond [(eq "eq") (ne "ne") (gt "gt") (ge "ge") (lt "lt") (le "le")
11574 + (gtu "hi") (geu "hs") (ltu "lo") (leu "ls")])
11575 +(define_code_attr invcond [(eq "ne") (ne "eq") (gt "le") (ge "lt") (lt "ge") (le "gt")
11576 + (gtu "ls") (geu "lo") (ltu "hs") (leu "hi")])
11577 +
11578 +;; For logical operations
11579 +(define_code_iterator logical [and ior xor])
11580 +(define_code_attr logical_insn [(and "and") (ior "or") (xor "eor")])
11581 +
11582 +;; Predicable operations with three register operands
11583 +(define_code_iterator predicable_op3 [and ior xor plus minus])
11584 +(define_code_attr predicable_insn3 [(and "and") (ior "or") (xor "eor") (plus "add") (minus "sub")])
11585 +(define_code_attr predicable_commutative3 [(and "%") (ior "%") (xor "%") (plus "%") (minus "")])
11586 +
11587 +;; Load the predicates
11588 +(include "predicates.md")
11589 +
11590 +
11591 +;;******************************************************************************
11592 +;; Automaton pipeline description for avr32
11593 +;;******************************************************************************
11594 +
11595 +(define_automaton "avr32_ap")
11596 +
11597 +
11598 +(define_cpu_unit "is" "avr32_ap")
11599 +(define_cpu_unit "a1,m1,da" "avr32_ap")
11600 +(define_cpu_unit "a2,m2,d" "avr32_ap")
11601 +
11602 +;;Alu instructions
11603 +(define_insn_reservation "alu_op" 1
11604 + (and (eq_attr "pipeline" "ap")
11605 + (eq_attr "type" "alu"))
11606 + "is,a1,a2")
11607 +
11608 +(define_insn_reservation "alu2_op" 2
11609 + (and (eq_attr "pipeline" "ap")
11610 + (eq_attr "type" "alu2"))
11611 + "is,is+a1,a1+a2,a2")
11612 +
11613 +(define_insn_reservation "alu_sat_op" 2
11614 + (and (eq_attr "pipeline" "ap")
11615 + (eq_attr "type" "alu_sat"))
11616 + "is,a1,a2")
11617 +
11618 +
11619 +;;Mul instructions
11620 +(define_insn_reservation "mulhh_op" 2
11621 + (and (eq_attr "pipeline" "ap")
11622 + (eq_attr "type" "mulhh,mulwh"))
11623 + "is,m1,m2")
11624 +
11625 +(define_insn_reservation "mulww_w_op" 3
11626 + (and (eq_attr "pipeline" "ap")
11627 + (eq_attr "type" "mulww_w"))
11628 + "is,m1,m1+m2,m2")
11629 +
11630 +(define_insn_reservation "mulww_d_op" 5
11631 + (and (eq_attr "pipeline" "ap")
11632 + (eq_attr "type" "mulww_d"))
11633 + "is,m1,m1+m2,m1+m2,m2,m2")
11634 +
11635 +(define_insn_reservation "div_op" 33
11636 + (and (eq_attr "pipeline" "ap")
11637 + (eq_attr "type" "div"))
11638 + "is,m1,m1*31 + m2*31,m2")
11639 +
11640 +(define_insn_reservation "machh_w_op" 3
11641 + (and (eq_attr "pipeline" "ap")
11642 + (eq_attr "type" "machh_w"))
11643 + "is*2,m1,m2")
11644 +
11645 +
11646 +(define_insn_reservation "macww_w_op" 4
11647 + (and (eq_attr "pipeline" "ap")
11648 + (eq_attr "type" "macww_w"))
11649 + "is*2,m1,m1,m2")
11650 +
11651 +
11652 +(define_insn_reservation "macww_d_op" 6
11653 + (and (eq_attr "pipeline" "ap")
11654 + (eq_attr "type" "macww_d"))
11655 + "is*2,m1,m1+m2,m1+m2,m2")
11656 +
11657 +;;Bypasses for Mac instructions, because of accumulator cache.
11658 +;;Set latency as low as possible in order to let the compiler let
11659 +;;mul -> mac and mac -> mac combinations which use the same
11660 +;;accumulator cache be placed close together to avoid any
11661 +;;instructions which can ruin the accumulator cache come inbetween.
11662 +(define_bypass 4 "machh_w_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11663 +(define_bypass 5 "macww_w_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11664 +(define_bypass 7 "macww_d_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11665 +
11666 +(define_bypass 3 "mulhh_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11667 +(define_bypass 4 "mulww_w_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11668 +(define_bypass 6 "mulww_d_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11669 +
11670 +
11671 +;;Bypasses for all mul/mac instructions followed by an instruction
11672 +;;which reads the output AND writes the result to the same register.
11673 +;;This will generate an Write After Write hazard which gives an
11674 +;;extra cycle before the result is ready.
11675 +(define_bypass 0 "machh_w_op" "machh_w_op" "avr32_valid_macmac_bypass")
11676 +(define_bypass 0 "macww_w_op" "macww_w_op" "avr32_valid_macmac_bypass")
11677 +(define_bypass 0 "macww_d_op" "macww_d_op" "avr32_valid_macmac_bypass")
11678 +
11679 +(define_bypass 0 "mulhh_op" "machh_w_op" "avr32_valid_mulmac_bypass")
11680 +(define_bypass 0 "mulww_w_op" "macww_w_op" "avr32_valid_mulmac_bypass")
11681 +(define_bypass 0 "mulww_d_op" "macww_d_op" "avr32_valid_mulmac_bypass")
11682 +
11683 +;;Branch and call instructions
11684 +;;We assume that all branches and rcalls are predicted correctly :-)
11685 +;;while calls use a lot of cycles.
11686 +(define_insn_reservation "branch_op" 0
11687 + (and (eq_attr "pipeline" "ap")
11688 + (eq_attr "type" "branch"))
11689 + "nothing")
11690 +
11691 +(define_insn_reservation "call_op" 10
11692 + (and (eq_attr "pipeline" "ap")
11693 + (eq_attr "type" "call"))
11694 + "nothing")
11695 +
11696 +
11697 +;;Load store instructions
11698 +(define_insn_reservation "load_op" 2
11699 + (and (eq_attr "pipeline" "ap")
11700 + (eq_attr "type" "load"))
11701 + "is,da,d")
11702 +
11703 +(define_insn_reservation "load_rm_op" 3
11704 + (and (eq_attr "pipeline" "ap")
11705 + (eq_attr "type" "load_rm"))
11706 + "is,da,d")
11707 +
11708 +
11709 +(define_insn_reservation "store_op" 0
11710 + (and (eq_attr "pipeline" "ap")
11711 + (eq_attr "type" "store"))
11712 + "is,da,d")
11713 +
11714 +
11715 +(define_insn_reservation "load_double_op" 3
11716 + (and (eq_attr "pipeline" "ap")
11717 + (eq_attr "type" "load2"))
11718 + "is,da,da+d,d")
11719 +
11720 +(define_insn_reservation "load_quad_op" 4
11721 + (and (eq_attr "pipeline" "ap")
11722 + (eq_attr "type" "load4"))
11723 + "is,da,da+d,da+d,d")
11724 +
11725 +(define_insn_reservation "store_double_op" 0
11726 + (and (eq_attr "pipeline" "ap")
11727 + (eq_attr "type" "store2"))
11728 + "is,da,da+d,d")
11729 +
11730 +
11731 +(define_insn_reservation "store_quad_op" 0
11732 + (and (eq_attr "pipeline" "ap")
11733 + (eq_attr "type" "store4"))
11734 + "is,da,da+d,da+d,d")
11735 +
11736 +;;For store the operand to write to memory is read in d and
11737 +;;the real latency between any instruction and a store is therefore
11738 +;;one less than for the instructions which reads the operands in the first
11739 +;;excecution stage
11740 +(define_bypass 2 "load_double_op" "store_double_op" "avr32_store_bypass")
11741 +(define_bypass 3 "load_quad_op" "store_quad_op" "avr32_store_bypass")
11742 +(define_bypass 1 "load_op" "store_op" "avr32_store_bypass")
11743 +(define_bypass 2 "load_rm_op" "store_op" "avr32_store_bypass")
11744 +(define_bypass 1 "alu_sat_op" "store_op" "avr32_store_bypass")
11745 +(define_bypass 1 "alu2_op" "store_op" "avr32_store_bypass")
11746 +(define_bypass 1 "mulhh_op" "store_op" "avr32_store_bypass")
11747 +(define_bypass 2 "mulww_w_op" "store_op" "avr32_store_bypass")
11748 +(define_bypass 4 "mulww_d_op" "store_op" "avr32_store_bypass" )
11749 +(define_bypass 2 "machh_w_op" "store_op" "avr32_store_bypass")
11750 +(define_bypass 3 "macww_w_op" "store_op" "avr32_store_bypass")
11751 +(define_bypass 5 "macww_d_op" "store_op" "avr32_store_bypass")
11752 +
11753 +
11754 +; Bypass for load double operation. If only the first loaded word is needed
11755 +; then the latency is 2
11756 +(define_bypass 2 "load_double_op"
11757 + "load_op,load_rm_op,alu_sat_op, alu2_op, alu_op, mulhh_op, mulww_w_op,
11758 + mulww_d_op, machh_w_op, macww_w_op, macww_d_op"
11759 + "avr32_valid_load_double_bypass")
11760 +
11761 +; Bypass for load quad operation. If only the first or second loaded word is needed
11762 +; we set the latency to 2
11763 +(define_bypass 2 "load_quad_op"
11764 + "load_op,load_rm_op,alu_sat_op, alu2_op, alu_op, mulhh_op, mulww_w_op,
11765 + mulww_d_op, machh_w_op, macww_w_op, macww_d_op"
11766 + "avr32_valid_load_quad_bypass")
11767 +
11768 +
11769 +;;******************************************************************************
11770 +;; End of Automaton pipeline description for avr32
11771 +;;******************************************************************************
11772 +
11773 +(define_cond_exec
11774 + [(match_operator 0 "avr32_comparison_operator"
11775 + [(match_operand:CMP 1 "register_operand" "r")
11776 + (match_operand:CMP 2 "<CMP:cmp_predicate>" "<CMP:cmp_constraint>")])]
11777 + "TARGET_V2_INSNS"
11778 + "%!"
11779 +)
11780 +
11781 +(define_cond_exec
11782 + [(match_operator 0 "avr32_comparison_operator"
11783 + [(and:SI (match_operand:SI 1 "register_operand" "r")
11784 + (match_operand:SI 2 "one_bit_set_operand" "i"))
11785 + (const_int 0)])]
11786 + "TARGET_V2_INSNS"
11787 + "%!"
11788 + )
11789 +
11790 +;;=============================================================================
11791 +;; move
11792 +;;-----------------------------------------------------------------------------
11793 +
11794 +
11795 +;;== char - 8 bits ============================================================
11796 +(define_expand "movqi"
11797 + [(set (match_operand:QI 0 "nonimmediate_operand" "")
11798 + (match_operand:QI 1 "general_operand" ""))]
11799 + ""
11800 + {
11801 + if ( can_create_pseudo_p () ){
11802 + if (GET_CODE (operands[1]) == MEM && optimize){
11803 + rtx reg = gen_reg_rtx (SImode);
11804 +
11805 + emit_insn (gen_zero_extendqisi2 (reg, operands[1]));
11806 + operands[1] = gen_lowpart (QImode, reg);
11807 + }
11808 +
11809 + /* One of the ops has to be in a register. */
11810 + if (GET_CODE (operands[0]) == MEM)
11811 + operands[1] = force_reg (QImode, operands[1]);
11812 + }
11813 +
11814 + })
11815 +
11816 +(define_insn "*movqi_internal"
11817 + [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r")
11818 + (match_operand:QI 1 "general_operand" "rKs08,m,r,i"))]
11819 + "register_operand (operands[0], QImode)
11820 + || register_operand (operands[1], QImode)"
11821 + "@
11822 + mov\t%0, %1
11823 + ld.ub\t%0, %1
11824 + st.b\t%0, %1
11825 + mov\t%0, %1"
11826 + [(set_attr "length" "2,4,4,4")
11827 + (set_attr "type" "alu,load_rm,store,alu")])
11828 +
11829 +
11830 +
11831 +;;== short - 16 bits ==========================================================
11832 +(define_expand "movhi"
11833 + [(set (match_operand:HI 0 "nonimmediate_operand" "")
11834 + (match_operand:HI 1 "general_operand" ""))]
11835 + ""
11836 + {
11837 + if ( can_create_pseudo_p () ){
11838 + if (GET_CODE (operands[1]) == MEM && optimize){
11839 + rtx reg = gen_reg_rtx (SImode);
11840 +
11841 + emit_insn (gen_extendhisi2 (reg, operands[1]));
11842 + operands[1] = gen_lowpart (HImode, reg);
11843 + }
11844 +
11845 + /* One of the ops has to be in a register. */
11846 + if (GET_CODE (operands[0]) == MEM)
11847 + operands[1] = force_reg (HImode, operands[1]);
11848 + }
11849 +
11850 + })
11851 +
11852 +
11853 +(define_insn "*movhi_internal"
11854 + [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r")
11855 + (match_operand:HI 1 "general_operand" "rKs08,m,r,i"))]
11856 + "register_operand (operands[0], HImode)
11857 + || register_operand (operands[1], HImode)"
11858 + "@
11859 + mov\t%0, %1
11860 + ld.sh\t%0, %1
11861 + st.h\t%0, %1
11862 + mov\t%0, %1"
11863 + [(set_attr "length" "2,4,4,4")
11864 + (set_attr "type" "alu,load_rm,store,alu")])
11865 +
11866 +
11867 +;;== int - 32 bits ============================================================
11868 +
11869 +(define_expand "movmisalignsi"
11870 + [(set (match_operand:SI 0 "nonimmediate_operand" "")
11871 + (match_operand:SI 1 "nonimmediate_operand" ""))]
11872 + "TARGET_UNALIGNED_WORD"
11873 + {
11874 + }
11875 +)
11876 +
11877 +(define_expand "mov<mode>"
11878 + [(set (match_operand:MOVM 0 "avr32_non_rmw_nonimmediate_operand" "")
11879 + (match_operand:MOVM 1 "avr32_non_rmw_general_operand" ""))]
11880 + ""
11881 + {
11882 +
11883 + /* One of the ops has to be in a register. */
11884 + if (GET_CODE (operands[0]) == MEM)
11885 + operands[1] = force_reg (<MODE>mode, operands[1]);
11886 +
11887 + /* Check for out of range immediate constants as these may
11888 + occur during reloading, since it seems like reload does
11889 + not check if the immediate is legitimate. Don't know if
11890 + this is a bug? */
11891 + if ( reload_in_progress
11892 + && avr32_imm_in_const_pool
11893 + && GET_CODE(operands[1]) == CONST_INT
11894 + && !avr32_const_ok_for_constraint_p(INTVAL(operands[1]), 'K', "Ks21") ){
11895 + operands[1] = force_const_mem(SImode, operands[1]);
11896 + }
11897 + /* Check for RMW memory operands. They are not allowed for mov operations
11898 + only the atomic memc/s/t operations */
11899 + if ( !reload_in_progress
11900 + && avr32_rmw_memory_operand (operands[0], <MODE>mode) ){
11901 + operands[0] = copy_rtx (operands[0]);
11902 + XEXP(operands[0], 0) = force_reg (<MODE>mode, XEXP(operands[0], 0));
11903 + }
11904 +
11905 + if ( !reload_in_progress
11906 + && avr32_rmw_memory_operand (operands[1], <MODE>mode) ){
11907 + operands[1] = copy_rtx (operands[1]);
11908 + XEXP(operands[1], 0) = force_reg (<MODE>mode, XEXP(operands[1], 0));
11909 + }
11910 + if ( (flag_pic || TARGET_HAS_ASM_ADDR_PSEUDOS)
11911 + && !avr32_legitimate_pic_operand_p(operands[1]) )
11912 + operands[1] = legitimize_pic_address (operands[1], <MODE>mode,
11913 + (can_create_pseudo_p () ? 0: operands[0]));
11914 + else if ( flag_pic && avr32_address_operand(operands[1], GET_MODE(operands[1])) )
11915 + /* If we have an address operand then this function uses the pic register. */
11916 + current_function_uses_pic_offset_table = 1;
11917 + })
11918 +
11919 +
11920 +(define_insn "mov<mode>_internal"
11921 + [(set (match_operand:MOVM 0 "avr32_non_rmw_nonimmediate_operand" "=r, r, r,r,r,Q,r")
11922 + (match_operand:MOVM 1 "avr32_non_rmw_general_operand" "rKs08,Ks21,J,n,Q,r,W"))]
11923 + "(register_operand (operands[0], <MODE>mode)
11924 + || register_operand (operands[1], <MODE>mode))
11925 + && !avr32_rmw_memory_operand (operands[0], <MODE>mode)
11926 + && !avr32_rmw_memory_operand (operands[1], <MODE>mode)"
11927 + {
11928 + switch (which_alternative) {
11929 + case 0:
11930 + case 1: return "mov\t%0, %1";
11931 + case 2:
11932 + if ( TARGET_V2_INSNS )
11933 + return "movh\t%0, hi(%1)";
11934 + /* Fallthrough */
11935 + case 3: return "mov\t%0, lo(%1)\;orh\t%0,hi(%1)";
11936 + case 4:
11937 + if ( (REG_P(XEXP(operands[1], 0))
11938 + && REGNO(XEXP(operands[1], 0)) == SP_REGNUM)
11939 + || (GET_CODE(XEXP(operands[1], 0)) == PLUS
11940 + && REGNO(XEXP(XEXP(operands[1], 0), 0)) == SP_REGNUM
11941 + && GET_CODE(XEXP(XEXP(operands[1], 0), 1)) == CONST_INT
11942 + && INTVAL(XEXP(XEXP(operands[1], 0), 1)) % 4 == 0
11943 + && INTVAL(XEXP(XEXP(operands[1], 0), 1)) <= 0x1FC) )
11944 + return "lddsp\t%0, %1";
11945 + else if ( avr32_const_pool_ref_operand(operands[1], GET_MODE(operands[1])) )
11946 + return "lddpc\t%0, %1";
11947 + else
11948 + return "ld.w\t%0, %1";
11949 + case 5:
11950 + if ( (REG_P(XEXP(operands[0], 0))
11951 + && REGNO(XEXP(operands[0], 0)) == SP_REGNUM)
11952 + || (GET_CODE(XEXP(operands[0], 0)) == PLUS
11953 + && REGNO(XEXP(XEXP(operands[0], 0), 0)) == SP_REGNUM
11954 + && GET_CODE(XEXP(XEXP(operands[0], 0), 1)) == CONST_INT
11955 + && INTVAL(XEXP(XEXP(operands[0], 0), 1)) % 4 == 0
11956 + && INTVAL(XEXP(XEXP(operands[0], 0), 1)) <= 0x1FC) )
11957 + return "stdsp\t%0, %1";
11958 + else
11959 + return "st.w\t%0, %1";
11960 + case 6:
11961 + if ( TARGET_HAS_ASM_ADDR_PSEUDOS )
11962 + return "lda.w\t%0, %1";
11963 + else
11964 + return "ld.w\t%0, r6[%1@got]";
11965 + default:
11966 + abort();
11967 + }
11968 + }
11969 +
11970 + [(set_attr "length" "2,4,4,8,4,4,8")
11971 + (set_attr "type" "alu,alu,alu,alu2,load,store,load")
11972 + (set_attr "cc" "none,none,set_z_if_not_v2,set_z,none,none,clobber")])
11973 +
11974 +
11975 +(define_expand "reload_out_rmw_memory_operand"
11976 + [(set (match_operand:SI 2 "register_operand" "=r")
11977 + (match_operand:SI 0 "address_operand" ""))
11978 + (set (mem:SI (match_dup 2))
11979 + (match_operand:SI 1 "register_operand" ""))]
11980 + ""
11981 + {
11982 + operands[0] = XEXP(operands[0], 0);
11983 + }
11984 +)
11985 +
11986 +(define_expand "reload_in_rmw_memory_operand"
11987 + [(set (match_operand:SI 2 "register_operand" "=r")
11988 + (match_operand:SI 1 "address_operand" ""))
11989 + (set (match_operand:SI 0 "register_operand" "")
11990 + (mem:SI (match_dup 2)))]
11991 + ""
11992 + {
11993 + operands[1] = XEXP(operands[1], 0);
11994 + }
11995 +)
11996 +
11997 +
11998 +;; These instructions are for loading constants which cannot be loaded
11999 +;; directly from the constant pool because the offset is too large
12000 +;; high and lo_sum are used even tough for our case it should be
12001 +;; low and high sum :-)
12002 +(define_insn "mov_symbol_lo"
12003 + [(set (match_operand:SI 0 "register_operand" "=r")
12004 + (high:SI (match_operand:SI 1 "immediate_operand" "i" )))]
12005 + ""
12006 + "mov\t%0, lo(%1)"
12007 + [(set_attr "type" "alu")
12008 + (set_attr "length" "4")]
12009 +)
12010 +
12011 +(define_insn "add_symbol_hi"
12012 + [(set (match_operand:SI 0 "register_operand" "=r")
12013 + (lo_sum:SI (match_dup 0)
12014 + (match_operand:SI 1 "immediate_operand" "i" )))]
12015 + ""
12016 + "orh\t%0, hi(%1)"
12017 + [(set_attr "type" "alu")
12018 + (set_attr "length" "4")]
12019 +)
12020 +
12021 +
12022 +
12023 +;; When generating pic, we need to load the symbol offset into a register.
12024 +;; So that the optimizer does not confuse this with a normal symbol load
12025 +;; we use an unspec. The offset will be loaded from a constant pool entry,
12026 +;; since that is the only type of relocation we can use.
12027 +(define_insn "pic_load_addr"
12028 + [(set (match_operand:SI 0 "register_operand" "=r")
12029 + (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PIC_SYM))]
12030 + "flag_pic && CONSTANT_POOL_ADDRESS_P(XEXP(operands[1], 0))"
12031 + "lddpc\t%0, %1"
12032 + [(set_attr "type" "load")
12033 + (set_attr "length" "4")]
12034 +)
12035 +
12036 +(define_insn "pic_compute_got_from_pc"
12037 + [(set (match_operand:SI 0 "register_operand" "+r")
12038 + (unspec:SI [(minus:SI (pc)
12039 + (match_dup 0))] UNSPEC_PIC_BASE))
12040 + (use (label_ref (match_operand 1 "" "")))]
12041 + "flag_pic"
12042 + {
12043 + (*targetm.asm_out.internal_label) (asm_out_file, "L",
12044 + CODE_LABEL_NUMBER (operands[1]));
12045 + return \"rsub\t%0, pc\";
12046 + }
12047 + [(set_attr "cc" "clobber")
12048 + (set_attr "length" "2")]
12049 +)
12050 +
12051 +;;== long long int - 64 bits ==================================================
12052 +
12053 +(define_expand "movdi"
12054 + [(set (match_operand:DI 0 "nonimmediate_operand" "")
12055 + (match_operand:DI 1 "general_operand" ""))]
12056 + ""
12057 + {
12058 +
12059 + /* One of the ops has to be in a register. */
12060 + if (GET_CODE (operands[0]) != REG)
12061 + operands[1] = force_reg (DImode, operands[1]);
12062 +
12063 + })
12064 +
12065 +
12066 +(define_insn_and_split "*movdi_internal"
12067 + [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r, r, r,r,r,m")
12068 + (match_operand:DI 1 "general_operand" "r, Ks08,Ks21,G,n,m,r"))]
12069 + "register_operand (operands[0], DImode)
12070 + || register_operand (operands[1], DImode)"
12071 + {
12072 + switch (which_alternative ){
12073 + case 0:
12074 + case 1:
12075 + case 2:
12076 + case 3:
12077 + case 4:
12078 + return "#";
12079 + case 5:
12080 + if ( avr32_const_pool_ref_operand(operands[1], GET_MODE(operands[1])))
12081 + return "ld.d\t%0, pc[%1 - .]";
12082 + else
12083 + return "ld.d\t%0, %1";
12084 + case 6:
12085 + return "st.d\t%0, %1";
12086 + default:
12087 + abort();
12088 + }
12089 + }
12090 +;; Lets split all reg->reg or imm->reg transfers into two SImode transfers
12091 + "reload_completed &&
12092 + (REG_P (operands[0]) &&
12093 + (REG_P (operands[1])
12094 + || GET_CODE (operands[1]) == CONST_INT
12095 + || GET_CODE (operands[1]) == CONST_DOUBLE))"
12096 + [(set (match_dup 0) (match_dup 1))
12097 + (set (match_dup 2) (match_dup 3))]
12098 + {
12099 + operands[2] = gen_highpart (SImode, operands[0]);
12100 + operands[0] = gen_lowpart (SImode, operands[0]);
12101 + if ( REG_P(operands[1]) ){
12102 + operands[3] = gen_highpart(SImode, operands[1]);
12103 + operands[1] = gen_lowpart(SImode, operands[1]);
12104 + } else if ( GET_CODE(operands[1]) == CONST_DOUBLE
12105 + || GET_CODE(operands[1]) == CONST_INT ){
12106 + rtx split_const[2];
12107 + avr32_split_const_expr (DImode, SImode, operands[1], split_const);
12108 + operands[3] = split_const[1];
12109 + operands[1] = split_const[0];
12110 + } else {
12111 + internal_error("Illegal operand[1] for movdi split!");
12112 + }
12113 + }
12114 +
12115 + [(set_attr "length" "*,*,*,*,*,4,4")
12116 + (set_attr "type" "*,*,*,*,*,load2,store2")
12117 + (set_attr "cc" "*,*,*,*,*,none,none")])
12118 +
12119 +
12120 +;;== 128 bits ==================================================
12121 +(define_expand "movti"
12122 + [(set (match_operand:TI 0 "nonimmediate_operand" "")
12123 + (match_operand:TI 1 "nonimmediate_operand" ""))]
12124 + "TARGET_ARCH_AP"
12125 + {
12126 +
12127 + /* One of the ops has to be in a register. */
12128 + if (GET_CODE (operands[0]) != REG)
12129 + operands[1] = force_reg (TImode, operands[1]);
12130 +
12131 + /* We must fix any pre_dec for loads and post_inc stores */
12132 + if ( GET_CODE (operands[0]) == MEM
12133 + && GET_CODE (XEXP(operands[0],0)) == POST_INC ){
12134 + emit_move_insn(gen_rtx_MEM(TImode, XEXP(XEXP(operands[0],0),0)), operands[1]);
12135 + emit_insn(gen_addsi3(XEXP(XEXP(operands[0],0),0), XEXP(XEXP(operands[0],0),0), GEN_INT(GET_MODE_SIZE(TImode))));
12136 + DONE;
12137 + }
12138 +
12139 + if ( GET_CODE (operands[1]) == MEM
12140 + && GET_CODE (XEXP(operands[1],0)) == PRE_DEC ){
12141 + emit_insn(gen_addsi3(XEXP(XEXP(operands[1],0),0), XEXP(XEXP(operands[1],0),0), GEN_INT(-GET_MODE_SIZE(TImode))));
12142 + emit_move_insn(operands[0], gen_rtx_MEM(TImode, XEXP(XEXP(operands[1],0),0)));
12143 + DONE;
12144 + }
12145 + })
12146 +
12147 +
12148 +(define_insn_and_split "*movti_internal"
12149 + [(set (match_operand:TI 0 "avr32_movti_dst_operand" "=r,&r, r, <RKu00,r,r")
12150 + (match_operand:TI 1 "avr32_movti_src_operand" " r,RKu00>,RKu00,r, n,T"))]
12151 + "(register_operand (operands[0], TImode)
12152 + || register_operand (operands[1], TImode))"
12153 + {
12154 + switch (which_alternative ){
12155 + case 0:
12156 + case 2:
12157 + case 4:
12158 + return "#";
12159 + case 1:
12160 + return "ldm\t%p1, %0";
12161 + case 3:
12162 + return "stm\t%p0, %1";
12163 + case 5:
12164 + return "ld.d\t%U0, pc[%1 - .]\;ld.d\t%B0, pc[%1 - . + 8]";
12165 + }
12166 + }
12167 +
12168 + "reload_completed &&
12169 + (REG_P (operands[0]) &&
12170 + (REG_P (operands[1])
12171 + /* If this is a load from the constant pool we split it into
12172 + two double loads. */
12173 + || (GET_CODE (operands[1]) == MEM
12174 + && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
12175 + && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
12176 + /* If this is a load where the pointer register is a part
12177 + of the register list, we must split it into two double
12178 + loads in order for it to be exception safe. */
12179 + || (GET_CODE (operands[1]) == MEM
12180 + && register_operand (XEXP (operands[1], 0), SImode)
12181 + && reg_overlap_mentioned_p (operands[0], XEXP (operands[1], 0)))
12182 + || GET_CODE (operands[1]) == CONST_INT
12183 + || GET_CODE (operands[1]) == CONST_DOUBLE))"
12184 + [(set (match_dup 0) (match_dup 1))
12185 + (set (match_dup 2) (match_dup 3))]
12186 + {
12187 + operands[2] = simplify_gen_subreg ( DImode, operands[0],
12188 + TImode, 0 );
12189 + operands[0] = simplify_gen_subreg ( DImode, operands[0],
12190 + TImode, 8 );
12191 + if ( REG_P(operands[1]) ){
12192 + operands[3] = simplify_gen_subreg ( DImode, operands[1],
12193 + TImode, 0 );
12194 + operands[1] = simplify_gen_subreg ( DImode, operands[1],
12195 + TImode, 8 );
12196 + } else if ( GET_CODE(operands[1]) == CONST_DOUBLE
12197 + || GET_CODE(operands[1]) == CONST_INT ){
12198 + rtx split_const[2];
12199 + avr32_split_const_expr (TImode, DImode, operands[1], split_const);
12200 + operands[3] = split_const[1];
12201 + operands[1] = split_const[0];
12202 + } else if (avr32_const_pool_ref_operand (operands[1], GET_MODE(operands[1]))){
12203 + rtx split_const[2];
12204 + rtx cop = avoid_constant_pool_reference (operands[1]);
12205 + if (operands[1] == cop)
12206 + cop = get_pool_constant (XEXP (operands[1], 0));
12207 + avr32_split_const_expr (TImode, DImode, cop, split_const);
12208 + operands[3] = force_const_mem (DImode, split_const[1]);
12209 + operands[1] = force_const_mem (DImode, split_const[0]);
12210 + } else {
12211 + rtx ptr_reg = XEXP (operands[1], 0);
12212 + operands[1] = gen_rtx_MEM (DImode,
12213 + gen_rtx_PLUS ( SImode,
12214 + ptr_reg,
12215 + GEN_INT (8) ));
12216 + operands[3] = gen_rtx_MEM (DImode,
12217 + ptr_reg);
12218 +
12219 + /* Check if the first load will clobber the pointer.
12220 + If so, we must switch the order of the operations. */
12221 + if ( reg_overlap_mentioned_p (operands[0], ptr_reg) )
12222 + {
12223 + /* We need to switch the order of the operations
12224 + so that the pointer register does not get clobbered
12225 + after the first double word load. */
12226 + rtx tmp;
12227 + tmp = operands[0];
12228 + operands[0] = operands[2];
12229 + operands[2] = tmp;
12230 + tmp = operands[1];
12231 + operands[1] = operands[3];
12232 + operands[3] = tmp;
12233 + }
12234 +
12235 +
12236 + }
12237 + }
12238 + [(set_attr "length" "*,*,4,4,*,8")
12239 + (set_attr "type" "*,*,load4,store4,*,load4")])
12240 +
12241 +
12242 +;;== float - 32 bits ==========================================================
12243 +(define_expand "movsf"
12244 + [(set (match_operand:SF 0 "nonimmediate_operand" "")
12245 + (match_operand:SF 1 "general_operand" ""))]
12246 + ""
12247 + {
12248 +
12249 +
12250 + /* One of the ops has to be in a register. */
12251 + if (GET_CODE (operands[0]) != REG)
12252 + operands[1] = force_reg (SFmode, operands[1]);
12253 +
12254 + })
12255 +
12256 +(define_insn "*movsf_internal"
12257 + [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,r,r,m")
12258 + (match_operand:SF 1 "general_operand" "r, G,F,m,r"))]
12259 + "(register_operand (operands[0], SFmode)
12260 + || register_operand (operands[1], SFmode))"
12261 + {
12262 + switch (which_alternative) {
12263 + case 0:
12264 + case 1: return "mov\t%0, %1";
12265 + case 2:
12266 + {
12267 + HOST_WIDE_INT target_float[2];
12268 + real_to_target (target_float, CONST_DOUBLE_REAL_VALUE (operands[1]), SFmode);
12269 + if ( TARGET_V2_INSNS
12270 + && avr32_hi16_immediate_operand (GEN_INT (target_float[0]), VOIDmode) )
12271 + return "movh\t%0, hi(%1)";
12272 + else
12273 + return "mov\t%0, lo(%1)\;orh\t%0, hi(%1)";
12274 + }
12275 + case 3:
12276 + if ( (REG_P(XEXP(operands[1], 0))
12277 + && REGNO(XEXP(operands[1], 0)) == SP_REGNUM)
12278 + || (GET_CODE(XEXP(operands[1], 0)) == PLUS
12279 + && REGNO(XEXP(XEXP(operands[1], 0), 0)) == SP_REGNUM
12280 + && GET_CODE(XEXP(XEXP(operands[1], 0), 1)) == CONST_INT
12281 + && INTVAL(XEXP(XEXP(operands[1], 0), 1)) % 4 == 0
12282 + && INTVAL(XEXP(XEXP(operands[1], 0), 1)) <= 0x1FC) )
12283 + return "lddsp\t%0, %1";
12284 + else if ( avr32_const_pool_ref_operand(operands[1], GET_MODE(operands[1])) )
12285 + return "lddpc\t%0, %1";
12286 + else
12287 + return "ld.w\t%0, %1";
12288 + case 4:
12289 + if ( (REG_P(XEXP(operands[0], 0))
12290 + && REGNO(XEXP(operands[0], 0)) == SP_REGNUM)
12291 + || (GET_CODE(XEXP(operands[0], 0)) == PLUS
12292 + && REGNO(XEXP(XEXP(operands[0], 0), 0)) == SP_REGNUM
12293 + && GET_CODE(XEXP(XEXP(operands[0], 0), 1)) == CONST_INT
12294 + && INTVAL(XEXP(XEXP(operands[0], 0), 1)) % 4 == 0
12295 + && INTVAL(XEXP(XEXP(operands[0], 0), 1)) <= 0x1FC) )
12296 + return "stdsp\t%0, %1";
12297 + else
12298 + return "st.w\t%0, %1";
12299 + default:
12300 + abort();
12301 + }
12302 + }
12303 +
12304 + [(set_attr "length" "2,4,8,4,4")
12305 + (set_attr "type" "alu,alu,alu2,load,store")
12306 + (set_attr "cc" "none,none,clobber,none,none")])
12307 +
12308 +
12309 +
12310 +;;== double - 64 bits =========================================================
12311 +(define_expand "movdf"
12312 + [(set (match_operand:DF 0 "nonimmediate_operand" "")
12313 + (match_operand:DF 1 "general_operand" ""))]
12314 + ""
12315 + {
12316 + /* One of the ops has to be in a register. */
12317 + if (GET_CODE (operands[0]) != REG){
12318 + operands[1] = force_reg (DFmode, operands[1]);
12319 + }
12320 + })
12321 +
12322 +
12323 +(define_insn_and_split "*movdf_internal"
12324 + [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,r,r,m")
12325 + (match_operand:DF 1 "general_operand" " r,G,F,m,r"))]
12326 + "(register_operand (operands[0], DFmode)
12327 + || register_operand (operands[1], DFmode))"
12328 + {
12329 + switch (which_alternative ){
12330 + case 0:
12331 + case 1:
12332 + case 2:
12333 + return "#";
12334 + case 3:
12335 + if ( avr32_const_pool_ref_operand(operands[1], GET_MODE(operands[1])))
12336 + return "ld.d\t%0, pc[%1 - .]";
12337 + else
12338 + return "ld.d\t%0, %1";
12339 + case 4:
12340 + return "st.d\t%0, %1";
12341 + default:
12342 + abort();
12343 + }
12344 + }
12345 + "reload_completed
12346 + && (REG_P (operands[0])
12347 + && (REG_P (operands[1])
12348 + || GET_CODE (operands[1]) == CONST_DOUBLE))"
12349 + [(set (match_dup 0) (match_dup 1))
12350 + (set (match_dup 2) (match_dup 3))]
12351 + "
12352 + {
12353 + operands[2] = gen_highpart (SImode, operands[0]);
12354 + operands[0] = gen_lowpart (SImode, operands[0]);
12355 + operands[3] = gen_highpart(SImode, operands[1]);
12356 + operands[1] = gen_lowpart(SImode, operands[1]);
12357 + }
12358 + "
12359 +
12360 + [(set_attr "length" "*,*,*,4,4")
12361 + (set_attr "type" "*,*,*,load2,store2")
12362 + (set_attr "cc" "*,*,*,none,none")])
12363 +
12364 +
12365 +;;=============================================================================
12366 +;; Conditional Moves
12367 +;;=============================================================================
12368 +(define_insn "ld<mode>_predicable"
12369 + [(set (match_operand:MOVCC 0 "register_operand" "=r")
12370 + (match_operand:MOVCC 1 "avr32_non_rmw_memory_operand" "<MOVCC:pred_mem_constraint>"))]
12371 + "TARGET_V2_INSNS"
12372 + "ld<MOVCC:load_postfix>%?\t%0, %1"
12373 + [(set_attr "length" "4")
12374 + (set_attr "cc" "cmp_cond_insn")
12375 + (set_attr "type" "load")
12376 + (set_attr "predicable" "yes")]
12377 +)
12378 +
12379 +
12380 +(define_insn "st<mode>_predicable"
12381 + [(set (match_operand:MOVCC 0 "avr32_non_rmw_memory_operand" "=<MOVCC:pred_mem_constraint>")
12382 + (match_operand:MOVCC 1 "register_operand" "r"))]
12383 + "TARGET_V2_INSNS"
12384 + "st<MOVCC:store_postfix>%?\t%0, %1"
12385 + [(set_attr "length" "4")
12386 + (set_attr "cc" "cmp_cond_insn")
12387 + (set_attr "type" "store")
12388 + (set_attr "predicable" "yes")]
12389 +)
12390 +
12391 +(define_insn "mov<mode>_predicable"
12392 + [(set (match_operand:MOVCC 0 "register_operand" "=r")
12393 + (match_operand:MOVCC 1 "avr32_cond_register_immediate_operand" "rKs08"))]
12394 + ""
12395 + "mov%?\t%0, %1"
12396 + [(set_attr "length" "4")
12397 + (set_attr "cc" "cmp_cond_insn")
12398 + (set_attr "type" "alu")
12399 + (set_attr "predicable" "yes")]
12400 +)
12401 +
12402 +
12403 +;;=============================================================================
12404 +;; Move chunks of memory
12405 +;;=============================================================================
12406 +
12407 +(define_expand "movmemsi"
12408 + [(match_operand:BLK 0 "general_operand" "")
12409 + (match_operand:BLK 1 "general_operand" "")
12410 + (match_operand:SI 2 "const_int_operand" "")
12411 + (match_operand:SI 3 "const_int_operand" "")]
12412 + ""
12413 + "
12414 + if (avr32_gen_movmemsi (operands))
12415 + DONE;
12416 + FAIL;
12417 + "
12418 + )
12419 +
12420 +
12421 +
12422 +
12423 +;;=============================================================================
12424 +;; Bit field instructions
12425 +;;-----------------------------------------------------------------------------
12426 +;; Instructions to insert or extract bit-fields
12427 +;;=============================================================================
12428 +
12429 +(define_insn "insv"
12430 + [ (set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
12431 + (match_operand:SI 1 "immediate_operand" "Ku05")
12432 + (match_operand:SI 2 "immediate_operand" "Ku05"))
12433 + (match_operand 3 "register_operand" "r"))]
12434 + ""
12435 + "bfins\t%0, %3, %2, %1"
12436 + [(set_attr "type" "alu")
12437 + (set_attr "length" "4")
12438 + (set_attr "cc" "set_ncz")])
12439 +
12440 +
12441 +
12442 +(define_expand "extv"
12443 + [ (set (match_operand:SI 0 "register_operand" "")
12444 + (sign_extract:SI (match_operand:SI 1 "register_operand" "")
12445 + (match_operand:SI 2 "immediate_operand" "")
12446 + (match_operand:SI 3 "immediate_operand" "")))]
12447 + ""
12448 + {
12449 + if ( INTVAL(operands[2]) >= 32 )
12450 + FAIL;
12451 + }
12452 +)
12453 +
12454 +(define_expand "extzv"
12455 + [ (set (match_operand:SI 0 "register_operand" "")
12456 + (zero_extract:SI (match_operand:SI 1 "register_operand" "")
12457 + (match_operand:SI 2 "immediate_operand" "")
12458 + (match_operand:SI 3 "immediate_operand" "")))]
12459 + ""
12460 + {
12461 + if ( INTVAL(operands[2]) >= 32 )
12462 + FAIL;
12463 + }
12464 +)
12465 +
12466 +(define_insn "extv_internal"
12467 + [ (set (match_operand:SI 0 "register_operand" "=r")
12468 + (sign_extract:SI (match_operand:SI 1 "register_operand" "r")
12469 + (match_operand:SI 2 "immediate_operand" "Ku05")
12470 + (match_operand:SI 3 "immediate_operand" "Ku05")))]
12471 + "INTVAL(operands[2]) < 32"
12472 + "bfexts\t%0, %1, %3, %2"
12473 + [(set_attr "type" "alu")
12474 + (set_attr "length" "4")
12475 + (set_attr "cc" "set_ncz")])
12476 +
12477 +
12478 +(define_insn "extzv_internal"
12479 + [ (set (match_operand:SI 0 "register_operand" "=r")
12480 + (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
12481 + (match_operand:SI 2 "immediate_operand" "Ku05")
12482 + (match_operand:SI 3 "immediate_operand" "Ku05")))]
12483 + "INTVAL(operands[2]) < 32"
12484 + "bfextu\t%0, %1, %3, %2"
12485 + [(set_attr "type" "alu")
12486 + (set_attr "length" "4")
12487 + (set_attr "cc" "set_ncz")])
12488 +
12489 +
12490 +
12491 +;;=============================================================================
12492 +;; Some peepholes for avoiding unnecessary cast instructions
12493 +;; followed by bfins.
12494 +;;-----------------------------------------------------------------------------
12495 +
12496 +(define_peephole2
12497 + [(set (match_operand:SI 0 "register_operand" "")
12498 + (zero_extend:SI (match_operand:QI 1 "register_operand" "")))
12499 + (set (zero_extract:SI (match_operand 2 "register_operand" "")
12500 + (match_operand:SI 3 "immediate_operand" "")
12501 + (match_operand:SI 4 "immediate_operand" ""))
12502 + (match_dup 0))]
12503 + "((peep2_reg_dead_p(2, operands[0]) &&
12504 + (INTVAL(operands[3]) <= 8)))"
12505 + [(set (zero_extract:SI (match_dup 2)
12506 + (match_dup 3)
12507 + (match_dup 4))
12508 + (match_dup 1))]
12509 + )
12510 +
12511 +(define_peephole2
12512 + [(set (match_operand:SI 0 "register_operand" "")
12513 + (zero_extend:SI (match_operand:HI 1 "register_operand" "")))
12514 + (set (zero_extract:SI (match_operand 2 "register_operand" "")
12515 + (match_operand:SI 3 "immediate_operand" "")
12516 + (match_operand:SI 4 "immediate_operand" ""))
12517 + (match_dup 0))]
12518 + "((peep2_reg_dead_p(2, operands[0]) &&
12519 + (INTVAL(operands[3]) <= 16)))"
12520 + [(set (zero_extract:SI (match_dup 2)
12521 + (match_dup 3)
12522 + (match_dup 4))
12523 + (match_dup 1))]
12524 + )
12525 +
12526 +;;=============================================================================
12527 +;; push bytes
12528 +;;-----------------------------------------------------------------------------
12529 +;; Implements the push instruction
12530 +;;=============================================================================
12531 +(define_insn "pushm"
12532 + [(set (mem:BLK (pre_dec:BLK (reg:SI SP_REGNUM)))
12533 + (unspec:BLK [(match_operand 0 "const_int_operand" "")]
12534 + UNSPEC_PUSHM))]
12535 + ""
12536 + {
12537 + if (INTVAL(operands[0])) {
12538 + return "pushm\t%r0";
12539 + } else {
12540 + return "";
12541 + }
12542 + }
12543 + [(set_attr "type" "store")
12544 + (set_attr "length" "2")
12545 + (set_attr "cc" "none")])
12546 +
12547 +(define_insn "stm"
12548 + [(unspec [(match_operand 0 "register_operand" "r")
12549 + (match_operand 1 "const_int_operand" "")
12550 + (match_operand 2 "const_int_operand" "")]
12551 + UNSPEC_STM)]
12552 + ""
12553 + {
12554 + if (INTVAL(operands[1])) {
12555 + if (INTVAL(operands[2]) != 0)
12556 + return "stm\t--%0, %s1";
12557 + else
12558 + return "stm\t%0, %s1";
12559 + } else {
12560 + return "";
12561 + }
12562 + }
12563 + [(set_attr "type" "store")
12564 + (set_attr "length" "4")
12565 + (set_attr "cc" "none")])
12566 +
12567 +
12568 +
12569 +(define_insn "popm"
12570 + [(unspec [(match_operand 0 "const_int_operand" "")]
12571 + UNSPEC_POPM)]
12572 + ""
12573 + {
12574 + if (INTVAL(operands[0])) {
12575 + return "popm %r0";
12576 + } else {
12577 + return "";
12578 + }
12579 + }
12580 + [(set_attr "type" "load")
12581 + (set_attr "length" "2")])
12582 +
12583 +
12584 +
12585 +;;=============================================================================
12586 +;; add
12587 +;;-----------------------------------------------------------------------------
12588 +;; Adds reg1 with reg2 and puts the result in reg0.
12589 +;;=============================================================================
12590 +(define_insn "add<mode>3"
12591 + [(set (match_operand:INTM 0 "register_operand" "=r,r,r,r,r")
12592 + (plus:INTM (match_operand:INTM 1 "register_operand" "%0,r,0,r,0")
12593 + (match_operand:INTM 2 "avr32_add_operand" "r,r,Is08,Is16,Is21")))]
12594 + ""
12595 + "@
12596 + add %0, %2
12597 + add %0, %1, %2
12598 + sub %0, %n2
12599 + sub %0, %1, %n2
12600 + sub %0, %n2"
12601 +
12602 + [(set_attr "length" "2,4,2,4,4")
12603 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12604 +
12605 +(define_insn "add<mode>3_lsl"
12606 + [(set (match_operand:INTM 0 "register_operand" "=r")
12607 + (plus:INTM (ashift:INTM (match_operand:INTM 1 "register_operand" "r")
12608 + (match_operand:INTM 3 "avr32_add_shift_immediate_operand" "Ku02"))
12609 + (match_operand:INTM 2 "register_operand" "r")))]
12610 + ""
12611 + "add %0, %2, %1 << %3"
12612 + [(set_attr "length" "4")
12613 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12614 +
12615 +(define_insn "add<mode>3_lsl2"
12616 + [(set (match_operand:INTM 0 "register_operand" "=r")
12617 + (plus:INTM (match_operand:INTM 1 "register_operand" "r")
12618 + (ashift:INTM (match_operand:INTM 2 "register_operand" "r")
12619 + (match_operand:INTM 3 "avr32_add_shift_immediate_operand" "Ku02"))))]
12620 + ""
12621 + "add %0, %1, %2 << %3"
12622 + [(set_attr "length" "4")
12623 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12624 +
12625 +
12626 +(define_insn "add<mode>3_mul"
12627 + [(set (match_operand:INTM 0 "register_operand" "=r")
12628 + (plus:INTM (mult:INTM (match_operand:INTM 1 "register_operand" "r")
12629 + (match_operand:INTM 3 "immediate_operand" "Ku04" ))
12630 + (match_operand:INTM 2 "register_operand" "r")))]
12631 + "(INTVAL(operands[3]) == 0) || (INTVAL(operands[3]) == 2) ||
12632 + (INTVAL(operands[3]) == 4) || (INTVAL(operands[3]) == 8)"
12633 + "add %0, %2, %1 << %p3"
12634 + [(set_attr "length" "4")
12635 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12636 +
12637 +(define_insn "add<mode>3_mul2"
12638 + [(set (match_operand:INTM 0 "register_operand" "=r")
12639 + (plus:INTM (match_operand:INTM 1 "register_operand" "r")
12640 + (mult:INTM (match_operand:INTM 2 "register_operand" "r")
12641 + (match_operand:INTM 3 "immediate_operand" "Ku04" ))))]
12642 + "(INTVAL(operands[3]) == 0) || (INTVAL(operands[3]) == 2) ||
12643 + (INTVAL(operands[3]) == 4) || (INTVAL(operands[3]) == 8)"
12644 + "add %0, %1, %2 << %p3"
12645 + [(set_attr "length" "4")
12646 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12647 +
12648 +
12649 +(define_peephole2
12650 + [(set (match_operand:SI 0 "register_operand" "")
12651 + (ashift:SI (match_operand:SI 1 "register_operand" "")
12652 + (match_operand:SI 2 "immediate_operand" "")))
12653 + (set (match_operand:SI 3 "register_operand" "")
12654 + (plus:SI (match_dup 0)
12655 + (match_operand:SI 4 "register_operand" "")))]
12656 + "(peep2_reg_dead_p(2, operands[0]) &&
12657 + (INTVAL(operands[2]) < 4 && INTVAL(operands[2]) > 0))"
12658 + [(set (match_dup 3)
12659 + (plus:SI (ashift:SI (match_dup 1)
12660 + (match_dup 2))
12661 + (match_dup 4)))]
12662 + )
12663 +
12664 +(define_peephole2
12665 + [(set (match_operand:SI 0 "register_operand" "")
12666 + (ashift:SI (match_operand:SI 1 "register_operand" "")
12667 + (match_operand:SI 2 "immediate_operand" "")))
12668 + (set (match_operand:SI 3 "register_operand" "")
12669 + (plus:SI (match_operand:SI 4 "register_operand" "")
12670 + (match_dup 0)))]
12671 + "(peep2_reg_dead_p(2, operands[0]) &&
12672 + (INTVAL(operands[2]) < 4 && INTVAL(operands[2]) > 0))"
12673 + [(set (match_dup 3)
12674 + (plus:SI (ashift:SI (match_dup 1)
12675 + (match_dup 2))
12676 + (match_dup 4)))]
12677 + )
12678 +
12679 +(define_insn "adddi3"
12680 + [(set (match_operand:DI 0 "register_operand" "=r,r")
12681 + (plus:DI (match_operand:DI 1 "register_operand" "%0,r")
12682 + (match_operand:DI 2 "register_operand" "r,r")))]
12683 + ""
12684 + "@
12685 + add %0, %2\;adc %m0, %m0, %m2
12686 + add %0, %1, %2\;adc %m0, %m1, %m2"
12687 + [(set_attr "length" "6,8")
12688 + (set_attr "type" "alu2")
12689 + (set_attr "cc" "set_vncz")])
12690 +
12691 +
12692 +(define_insn "add<mode>_imm_predicable"
12693 + [(set (match_operand:INTM 0 "register_operand" "+r")
12694 + (plus:INTM (match_dup 0)
12695 + (match_operand:INTM 1 "avr32_cond_immediate_operand" "%Is08")))]
12696 + ""
12697 + "sub%?\t%0, -%1"
12698 + [(set_attr "length" "4")
12699 + (set_attr "cc" "cmp_cond_insn")
12700 + (set_attr "predicable" "yes")]
12701 +)
12702 +
12703 +;;=============================================================================
12704 +;; subtract
12705 +;;-----------------------------------------------------------------------------
12706 +;; Subtract reg2 or immediate value from reg0 and puts the result in reg0.
12707 +;;=============================================================================
12708 +
12709 +(define_insn "sub<mode>3"
12710 + [(set (match_operand:INTM 0 "general_operand" "=r,r,r,r,r,r,r")
12711 + (minus:INTM (match_operand:INTM 1 "register_const_int_operand" "0,r,0,r,0,r,Ks08")
12712 + (match_operand:INTM 2 "register_const_int_operand" "r,r,Ks08,Ks16,Ks21,0,r")))]
12713 + ""
12714 + "@
12715 + sub %0, %2
12716 + sub %0, %1, %2
12717 + sub %0, %2
12718 + sub %0, %1, %2
12719 + sub %0, %2
12720 + rsub %0, %1
12721 + rsub %0, %2, %1"
12722 + [(set_attr "length" "2,4,2,4,4,2,4")
12723 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12724 +
12725 +(define_insn "*sub<mode>3_mul"
12726 + [(set (match_operand:INTM 0 "register_operand" "=r")
12727 + (minus:INTM (match_operand:INTM 1 "register_operand" "r")
12728 + (mult:INTM (match_operand:INTM 2 "register_operand" "r")
12729 + (match_operand:SI 3 "immediate_operand" "Ku04" ))))]
12730 + "(INTVAL(operands[3]) == 0) || (INTVAL(operands[3]) == 2) ||
12731 + (INTVAL(operands[3]) == 4) || (INTVAL(operands[3]) == 8)"
12732 + "sub %0, %1, %2 << %p3"
12733 + [(set_attr "length" "4")
12734 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12735 +
12736 +(define_insn "*sub<mode>3_lsl"
12737 + [(set (match_operand:INTM 0 "register_operand" "=r")
12738 + (minus:INTM (match_operand:INTM 1 "register_operand" "r")
12739 + (ashift:INTM (match_operand:INTM 2 "register_operand" "r")
12740 + (match_operand:SI 3 "avr32_add_shift_immediate_operand" "Ku02"))))]
12741 + ""
12742 + "sub %0, %1, %2 << %3"
12743 + [(set_attr "length" "4")
12744 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12745 +
12746 +
12747 +(define_insn "subdi3"
12748 + [(set (match_operand:DI 0 "register_operand" "=r,r")
12749 + (minus:DI (match_operand:DI 1 "register_operand" "%0,r")
12750 + (match_operand:DI 2 "register_operand" "r,r")))]
12751 + ""
12752 + "@
12753 + sub %0, %2\;sbc %m0, %m0, %m2
12754 + sub %0, %1, %2\;sbc %m0, %m1, %m2"
12755 + [(set_attr "length" "6,8")
12756 + (set_attr "type" "alu2")
12757 + (set_attr "cc" "set_vncz")])
12758 +
12759 +
12760 +(define_insn "sub<mode>_imm_predicable"
12761 + [(set (match_operand:INTM 0 "register_operand" "+r")
12762 + (minus:INTM (match_dup 0)
12763 + (match_operand:INTM 1 "avr32_cond_immediate_operand" "Ks08")))]
12764 + ""
12765 + "sub%?\t%0, %1"
12766 + [(set_attr "length" "4")
12767 + (set_attr "cc" "cmp_cond_insn")
12768 + (set_attr "predicable" "yes")])
12769 +
12770 +(define_insn "rsub<mode>_imm_predicable"
12771 + [(set (match_operand:INTM 0 "register_operand" "+r")
12772 + (minus:INTM (match_operand:INTM 1 "avr32_cond_immediate_operand" "Ks08")
12773 + (match_dup 0)))]
12774 + ""
12775 + "rsub%?\t%0, %1"
12776 + [(set_attr "length" "4")
12777 + (set_attr "cc" "cmp_cond_insn")
12778 + (set_attr "predicable" "yes")])
12779 +
12780 +;;=============================================================================
12781 +;; multiply
12782 +;;-----------------------------------------------------------------------------
12783 +;; Multiply op1 and op2 and put the value in op0.
12784 +;;=============================================================================
12785 +
12786 +
12787 +(define_insn "mulqi3"
12788 + [(set (match_operand:QI 0 "register_operand" "=r,r,r")
12789 + (mult:QI (match_operand:QI 1 "register_operand" "%0,r,r")
12790 + (match_operand:QI 2 "avr32_mul_operand" "r,r,Ks08")))]
12791 + "!TARGET_NO_MUL_INSNS"
12792 + {
12793 + switch (which_alternative){
12794 + case 0:
12795 + return "mul %0, %2";
12796 + case 1:
12797 + return "mul %0, %1, %2";
12798 + case 2:
12799 + return "mul %0, %1, %2";
12800 + default:
12801 + gcc_unreachable();
12802 + }
12803 + }
12804 + [(set_attr "type" "mulww_w,mulww_w,mulwh")
12805 + (set_attr "length" "2,4,4")
12806 + (set_attr "cc" "none")])
12807 +
12808 +(define_insn "mulsi3"
12809 + [(set (match_operand:SI 0 "register_operand" "=r,r,r")
12810 + (mult:SI (match_operand:SI 1 "register_operand" "%0,r,r")
12811 + (match_operand:SI 2 "avr32_mul_operand" "r,r,Ks08")))]
12812 + "!TARGET_NO_MUL_INSNS"
12813 + {
12814 + switch (which_alternative){
12815 + case 0:
12816 + return "mul %0, %2";
12817 + case 1:
12818 + return "mul %0, %1, %2";
12819 + case 2:
12820 + return "mul %0, %1, %2";
12821 + default:
12822 + gcc_unreachable();
12823 + }
12824 + }
12825 + [(set_attr "type" "mulww_w,mulww_w,mulwh")
12826 + (set_attr "length" "2,4,4")
12827 + (set_attr "cc" "none")])
12828 +
12829 +
12830 +(define_insn "mulhisi3"
12831 + [(set (match_operand:SI 0 "register_operand" "=r")
12832 + (mult:SI
12833 + (sign_extend:SI (match_operand:HI 1 "register_operand" "%r"))
12834 + (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
12835 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12836 + "mulhh.w %0, %1:b, %2:b"
12837 + [(set_attr "type" "mulhh")
12838 + (set_attr "length" "4")
12839 + (set_attr "cc" "none")])
12840 +
12841 +(define_peephole2
12842 + [(match_scratch:DI 6 "r")
12843 + (set (match_operand:SI 0 "register_operand" "")
12844 + (mult:SI
12845 + (sign_extend:SI (match_operand:HI 1 "register_operand" ""))
12846 + (sign_extend:SI (match_operand:HI 2 "register_operand" ""))))
12847 + (set (match_operand:SI 3 "register_operand" "")
12848 + (ashiftrt:SI (match_dup 0)
12849 + (const_int 16)))]
12850 + "!TARGET_NO_MUL_INSNS && TARGET_DSP
12851 + && (peep2_reg_dead_p(1, operands[0]) || (REGNO(operands[0]) == REGNO(operands[3])))"
12852 + [(set (match_dup 4) (sign_extend:SI (match_dup 1)))
12853 + (set (match_dup 6)
12854 + (ashift:DI (mult:DI (sign_extend:DI (match_dup 4))
12855 + (sign_extend:DI (match_dup 2)))
12856 + (const_int 16)))
12857 + (set (match_dup 3) (match_dup 5))]
12858 +
12859 + "{
12860 + operands[4] = gen_rtx_REG(SImode, REGNO(operands[1]));
12861 + operands[5] = gen_highpart (SImode, operands[4]);
12862 + }"
12863 + )
12864 +
12865 +(define_insn "mulnhisi3"
12866 + [(set (match_operand:SI 0 "register_operand" "=r")
12867 + (mult:SI
12868 + (sign_extend:SI (neg:HI (match_operand:HI 1 "register_operand" "r")))
12869 + (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
12870 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12871 + "mulnhh.w %0, %1:b, %2:b"
12872 + [(set_attr "type" "mulhh")
12873 + (set_attr "length" "4")
12874 + (set_attr "cc" "none")])
12875 +
12876 +(define_insn "machisi3"
12877 + [(set (match_operand:SI 0 "register_operand" "+r")
12878 + (plus:SI (mult:SI
12879 + (sign_extend:SI (match_operand:HI 1 "register_operand" "%r"))
12880 + (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))
12881 + (match_dup 0)))]
12882 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12883 + "machh.w %0, %1:b, %2:b"
12884 + [(set_attr "type" "machh_w")
12885 + (set_attr "length" "4")
12886 + (set_attr "cc" "none")])
12887 +
12888 +
12889 +
12890 +(define_insn "mulsidi3"
12891 + [(set (match_operand:DI 0 "register_operand" "=r")
12892 + (mult:DI
12893 + (sign_extend:DI (match_operand:SI 1 "register_operand" "%r"))
12894 + (sign_extend:DI (match_operand:SI 2 "register_operand" "r"))))]
12895 + "!TARGET_NO_MUL_INSNS"
12896 + "muls.d %0, %1, %2"
12897 + [(set_attr "type" "mulww_d")
12898 + (set_attr "length" "4")
12899 + (set_attr "cc" "none")])
12900 +
12901 +(define_insn "umulsidi3"
12902 + [(set (match_operand:DI 0 "register_operand" "=r")
12903 + (mult:DI
12904 + (zero_extend:DI (match_operand:SI 1 "register_operand" "%r"))
12905 + (zero_extend:DI (match_operand:SI 2 "register_operand" "r"))))]
12906 + "!TARGET_NO_MUL_INSNS"
12907 + "mulu.d %0, %1, %2"
12908 + [(set_attr "type" "mulww_d")
12909 + (set_attr "length" "4")
12910 + (set_attr "cc" "none")])
12911 +
12912 +(define_insn "*mulaccsi3"
12913 + [(set (match_operand:SI 0 "register_operand" "+r")
12914 + (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "%r")
12915 + (match_operand:SI 2 "register_operand" "r"))
12916 + (match_dup 0)))]
12917 + "!TARGET_NO_MUL_INSNS"
12918 + "mac %0, %1, %2"
12919 + [(set_attr "type" "macww_w")
12920 + (set_attr "length" "4")
12921 + (set_attr "cc" "none")])
12922 +
12923 +(define_insn "*mulaccsidi3"
12924 + [(set (match_operand:DI 0 "register_operand" "+r")
12925 + (plus:DI (mult:DI
12926 + (sign_extend:DI (match_operand:SI 1 "register_operand" "%r"))
12927 + (sign_extend:DI (match_operand:SI 2 "register_operand" "r")))
12928 + (match_dup 0)))]
12929 + "!TARGET_NO_MUL_INSNS"
12930 + "macs.d %0, %1, %2"
12931 + [(set_attr "type" "macww_d")
12932 + (set_attr "length" "4")
12933 + (set_attr "cc" "none")])
12934 +
12935 +(define_insn "*umulaccsidi3"
12936 + [(set (match_operand:DI 0 "register_operand" "+r")
12937 + (plus:DI (mult:DI
12938 + (zero_extend:DI (match_operand:SI 1 "register_operand" "%r"))
12939 + (zero_extend:DI (match_operand:SI 2 "register_operand" "r")))
12940 + (match_dup 0)))]
12941 + "!TARGET_NO_MUL_INSNS"
12942 + "macu.d %0, %1, %2"
12943 + [(set_attr "type" "macww_d")
12944 + (set_attr "length" "4")
12945 + (set_attr "cc" "none")])
12946 +
12947 +
12948 +
12949 +;; Try to avoid Write-After-Write hazards for mul operations
12950 +;; if it can be done
12951 +(define_peephole2
12952 + [(set (match_operand:SI 0 "register_operand" "")
12953 + (mult:SI
12954 + (sign_extend:SI (match_operand 1 "general_operand" ""))
12955 + (sign_extend:SI (match_operand 2 "general_operand" ""))))
12956 + (set (match_dup 0)
12957 + (match_operator:SI 3 "alu_operator" [(match_dup 0)
12958 + (match_operand 4 "general_operand" "")]))]
12959 + "peep2_reg_dead_p(1, operands[2])"
12960 + [(set (match_dup 5)
12961 + (mult:SI
12962 + (sign_extend:SI (match_dup 1))
12963 + (sign_extend:SI (match_dup 2))))
12964 + (set (match_dup 0)
12965 + (match_op_dup 3 [(match_dup 5)
12966 + (match_dup 4)]))]
12967 + "{operands[5] = gen_rtx_REG(SImode, REGNO(operands[2]));}"
12968 + )
12969 +
12970 +
12971 +
12972 +;;=============================================================================
12973 +;; DSP instructions
12974 +;;=============================================================================
12975 +(define_insn "mulsathh_h"
12976 + [(set (match_operand:HI 0 "register_operand" "=r")
12977 + (ss_truncate:HI (ashiftrt:SI (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%r"))
12978 + (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))
12979 + (const_int 15))))]
12980 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12981 + "mulsathh.h\t%0, %1:b, %2:b"
12982 + [(set_attr "length" "4")
12983 + (set_attr "cc" "none")
12984 + (set_attr "type" "mulhh")])
12985 +
12986 +(define_insn "mulsatrndhh_h"
12987 + [(set (match_operand:HI 0 "register_operand" "=r")
12988 + (ss_truncate:HI (ashiftrt:SI
12989 + (plus:SI (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%r"))
12990 + (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))
12991 + (const_int 1073741824))
12992 + (const_int 15))))]
12993 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12994 + "mulsatrndhh.h\t%0, %1:b, %2:b"
12995 + [(set_attr "length" "4")
12996 + (set_attr "cc" "none")
12997 + (set_attr "type" "mulhh")])
12998 +
12999 +(define_insn "mulsathh_w"
13000 + [(set (match_operand:SI 0 "register_operand" "=r")
13001 + (ss_truncate:SI (ashift:DI (mult:DI (sign_extend:DI (match_operand:HI 1 "register_operand" "%r"))
13002 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
13003 + (const_int 1))))]
13004 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
13005 + "mulsathh.w\t%0, %1:b, %2:b"
13006 + [(set_attr "length" "4")
13007 + (set_attr "cc" "none")
13008 + (set_attr "type" "mulhh")])
13009 +
13010 +(define_insn "mulsatwh_w"
13011 + [(set (match_operand:SI 0 "register_operand" "=r")
13012 + (ss_truncate:SI (ashiftrt:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r"))
13013 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
13014 + (const_int 15))))]
13015 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
13016 + "mulsatwh.w\t%0, %1, %2:b"
13017 + [(set_attr "length" "4")
13018 + (set_attr "cc" "none")
13019 + (set_attr "type" "mulwh")])
13020 +
13021 +(define_insn "mulsatrndwh_w"
13022 + [(set (match_operand:SI 0 "register_operand" "=r")
13023 + (ss_truncate:SI (ashiftrt:DI (plus:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r"))
13024 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
13025 + (const_int 1073741824))
13026 + (const_int 15))))]
13027 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
13028 + "mulsatrndwh.w\t%0, %1, %2:b"
13029 + [(set_attr "length" "4")
13030 + (set_attr "cc" "none")
13031 + (set_attr "type" "mulwh")])
13032 +
13033 +(define_insn "macsathh_w"
13034 + [(set (match_operand:SI 0 "register_operand" "+r")
13035 + (plus:SI (match_dup 0)
13036 + (ss_truncate:SI (ashift:DI (mult:DI (sign_extend:DI (match_operand:HI 1 "register_operand" "%r"))
13037 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
13038 + (const_int 1)))))]
13039 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
13040 + "macsathh.w\t%0, %1:b, %2:b"
13041 + [(set_attr "length" "4")
13042 + (set_attr "cc" "none")
13043 + (set_attr "type" "mulhh")])
13044 +
13045 +
13046 +(define_insn "mulwh_d"
13047 + [(set (match_operand:DI 0 "register_operand" "=r")
13048 + (ashift:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r"))
13049 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
13050 + (const_int 16)))]
13051 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
13052 + "mulwh.d\t%0, %1, %2:b"
13053 + [(set_attr "length" "4")
13054 + (set_attr "cc" "none")
13055 + (set_attr "type" "mulwh")])
13056 +
13057 +
13058 +(define_insn "mulnwh_d"
13059 + [(set (match_operand:DI 0 "register_operand" "=r")
13060 + (ashift:DI (mult:DI (not:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r")))
13061 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
13062 + (const_int 16)))]
13063 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
13064 + "mulnwh.d\t%0, %1, %2:b"
13065 + [(set_attr "length" "4")
13066 + (set_attr "cc" "none")
13067 + (set_attr "type" "mulwh")])
13068 +
13069 +(define_insn "macwh_d"
13070 + [(set (match_operand:DI 0 "register_operand" "+r")
13071 + (plus:DI (match_dup 0)
13072 + (ashift:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "%r"))
13073 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
13074 + (const_int 16))))]
13075 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
13076 + "macwh.d\t%0, %1, %2:b"
13077 + [(set_attr "length" "4")
13078 + (set_attr "cc" "none")
13079 + (set_attr "type" "mulwh")])
13080 +
13081 +(define_insn "machh_d"
13082 + [(set (match_operand:DI 0 "register_operand" "+r")
13083 + (plus:DI (match_dup 0)
13084 + (mult:DI (sign_extend:DI (match_operand:HI 1 "register_operand" "%r"))
13085 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))))]
13086 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
13087 + "machh.d\t%0, %1:b, %2:b"
13088 + [(set_attr "length" "4")
13089 + (set_attr "cc" "none")
13090 + (set_attr "type" "mulwh")])
13091 +
13092 +(define_insn "satadd_w"
13093 + [(set (match_operand:SI 0 "register_operand" "=r")
13094 + (ss_plus:SI (match_operand:SI 1 "register_operand" "r")
13095 + (match_operand:SI 2 "register_operand" "r")))]
13096 + "TARGET_DSP"
13097 + "satadd.w\t%0, %1, %2"
13098 + [(set_attr "length" "4")
13099 + (set_attr "cc" "none")
13100 + (set_attr "type" "alu_sat")])
13101 +
13102 +(define_insn "satsub_w"
13103 + [(set (match_operand:SI 0 "register_operand" "=r")
13104 + (ss_minus:SI (match_operand:SI 1 "register_operand" "r")
13105 + (match_operand:SI 2 "register_operand" "r")))]
13106 + "TARGET_DSP"
13107 + "satsub.w\t%0, %1, %2"
13108 + [(set_attr "length" "4")
13109 + (set_attr "cc" "none")
13110 + (set_attr "type" "alu_sat")])
13111 +
13112 +(define_insn "satadd_h"
13113 + [(set (match_operand:HI 0 "register_operand" "=r")
13114 + (ss_plus:HI (match_operand:HI 1 "register_operand" "r")
13115 + (match_operand:HI 2 "register_operand" "r")))]
13116 + "TARGET_DSP"
13117 + "satadd.h\t%0, %1, %2"
13118 + [(set_attr "length" "4")
13119 + (set_attr "cc" "none")
13120 + (set_attr "type" "alu_sat")])
13121 +
13122 +(define_insn "satsub_h"
13123 + [(set (match_operand:HI 0 "register_operand" "=r")
13124 + (ss_minus:HI (match_operand:HI 1 "register_operand" "r")
13125 + (match_operand:HI 2 "register_operand" "r")))]
13126 + "TARGET_DSP"
13127 + "satsub.h\t%0, %1, %2"
13128 + [(set_attr "length" "4")
13129 + (set_attr "cc" "none")
13130 + (set_attr "type" "alu_sat")])
13131 +
13132 +
13133 +;;=============================================================================
13134 +;; smin
13135 +;;-----------------------------------------------------------------------------
13136 +;; Set reg0 to the smallest value of reg1 and reg2. It is used for signed
13137 +;; values in the registers.
13138 +;;=============================================================================
13139 +(define_insn "sminsi3"
13140 + [(set (match_operand:SI 0 "register_operand" "=r")
13141 + (smin:SI (match_operand:SI 1 "register_operand" "r")
13142 + (match_operand:SI 2 "register_operand" "r")))]
13143 + ""
13144 + "min %0, %1, %2"
13145 + [(set_attr "length" "4")
13146 + (set_attr "cc" "none")])
13147 +
13148 +;;=============================================================================
13149 +;; smax
13150 +;;-----------------------------------------------------------------------------
13151 +;; Set reg0 to the largest value of reg1 and reg2. It is used for signed
13152 +;; values in the registers.
13153 +;;=============================================================================
13154 +(define_insn "smaxsi3"
13155 + [(set (match_operand:SI 0 "register_operand" "=r")
13156 + (smax:SI (match_operand:SI 1 "register_operand" "r")
13157 + (match_operand:SI 2 "register_operand" "r")))]
13158 + ""
13159 + "max %0, %1, %2"
13160 + [(set_attr "length" "4")
13161 + (set_attr "cc" "none")])
13162 +
13163 +
13164 +
13165 +;;=============================================================================
13166 +;; Logical operations
13167 +;;-----------------------------------------------------------------------------
13168 +
13169 +
13170 +;; Split up simple DImode logical operations. Simply perform the logical
13171 +;; operation on the upper and lower halves of the registers.
13172 +(define_split
13173 + [(set (match_operand:DI 0 "register_operand" "")
13174 + (match_operator:DI 6 "logical_binary_operator"
13175 + [(match_operand:DI 1 "register_operand" "")
13176 + (match_operand:DI 2 "register_operand" "")]))]
13177 + "reload_completed"
13178 + [(set (match_dup 0) (match_op_dup:SI 6 [(match_dup 1) (match_dup 2)]))
13179 + (set (match_dup 3) (match_op_dup:SI 6 [(match_dup 4) (match_dup 5)]))]
13180 + "
13181 + {
13182 + operands[3] = gen_highpart (SImode, operands[0]);
13183 + operands[0] = gen_lowpart (SImode, operands[0]);
13184 + operands[4] = gen_highpart (SImode, operands[1]);
13185 + operands[1] = gen_lowpart (SImode, operands[1]);
13186 + operands[5] = gen_highpart (SImode, operands[2]);
13187 + operands[2] = gen_lowpart (SImode, operands[2]);
13188 + }"
13189 +)
13190 +
13191 +;;=============================================================================
13192 +;; Logical operations with shifted operand
13193 +;;=============================================================================
13194 +(define_insn "<code>si_lshift"
13195 + [(set (match_operand:SI 0 "register_operand" "=r")
13196 + (logical:SI (match_operator:SI 4 "logical_shift_operator"
13197 + [(match_operand:SI 2 "register_operand" "r")
13198 + (match_operand:SI 3 "immediate_operand" "Ku05")])
13199 + (match_operand:SI 1 "register_operand" "r")))]
13200 + ""
13201 + {
13202 + if ( GET_CODE(operands[4]) == ASHIFT )
13203 + return "<logical_insn>\t%0, %1, %2 << %3";
13204 + else
13205 + return "<logical_insn>\t%0, %1, %2 >> %3";
13206 + }
13207 +
13208 + [(set_attr "cc" "set_z")]
13209 +)
13210 +
13211 +
13212 +;;************************************************
13213 +;; Peepholes for detecting logical operantions
13214 +;; with shifted operands
13215 +;;************************************************
13216 +
13217 +(define_peephole
13218 + [(set (match_operand:SI 3 "register_operand" "")
13219 + (match_operator:SI 5 "logical_shift_operator"
13220 + [(match_operand:SI 1 "register_operand" "")
13221 + (match_operand:SI 2 "immediate_operand" "")]))
13222 + (set (match_operand:SI 0 "register_operand" "")
13223 + (logical:SI (match_operand:SI 4 "register_operand" "")
13224 + (match_dup 3)))]
13225 + "(dead_or_set_p(insn, operands[3])) || (REGNO(operands[3]) == REGNO(operands[0]))"
13226 + {
13227 + if ( GET_CODE(operands[5]) == ASHIFT )
13228 + return "<logical_insn>\t%0, %4, %1 << %2";
13229 + else
13230 + return "<logical_insn>\t%0, %4, %1 >> %2";
13231 + }
13232 + [(set_attr "cc" "set_z")]
13233 + )
13234 +
13235 +(define_peephole
13236 + [(set (match_operand:SI 3 "register_operand" "")
13237 + (match_operator:SI 5 "logical_shift_operator"
13238 + [(match_operand:SI 1 "register_operand" "")
13239 + (match_operand:SI 2 "immediate_operand" "")]))
13240 + (set (match_operand:SI 0 "register_operand" "")
13241 + (logical:SI (match_dup 3)
13242 + (match_operand:SI 4 "register_operand" "")))]
13243 + "(dead_or_set_p(insn, operands[3])) || (REGNO(operands[3]) == REGNO(operands[0]))"
13244 + {
13245 + if ( GET_CODE(operands[5]) == ASHIFT )
13246 + return "<logical_insn>\t%0, %4, %1 << %2";
13247 + else
13248 + return "<logical_insn>\t%0, %4, %1 >> %2";
13249 + }
13250 + [(set_attr "cc" "set_z")]
13251 + )
13252 +
13253 +
13254 +(define_peephole2
13255 + [(set (match_operand:SI 0 "register_operand" "")
13256 + (match_operator:SI 5 "logical_shift_operator"
13257 + [(match_operand:SI 1 "register_operand" "")
13258 + (match_operand:SI 2 "immediate_operand" "")]))
13259 + (set (match_operand:SI 3 "register_operand" "")
13260 + (logical:SI (match_operand:SI 4 "register_operand" "")
13261 + (match_dup 0)))]
13262 + "(peep2_reg_dead_p(2, operands[0])) || (REGNO(operands[3]) == REGNO(operands[0]))"
13263 +
13264 + [(set (match_dup 3)
13265 + (logical:SI (match_op_dup:SI 5 [(match_dup 1) (match_dup 2)])
13266 + (match_dup 4)))]
13267 +
13268 + ""
13269 +)
13270 +
13271 +(define_peephole2
13272 + [(set (match_operand:SI 0 "register_operand" "")
13273 + (match_operator:SI 5 "logical_shift_operator"
13274 + [(match_operand:SI 1 "register_operand" "")
13275 + (match_operand:SI 2 "immediate_operand" "")]))
13276 + (set (match_operand:SI 3 "register_operand" "")
13277 + (logical:SI (match_dup 0)
13278 + (match_operand:SI 4 "register_operand" "")))]
13279 + "(peep2_reg_dead_p(2, operands[0])) || (REGNO(operands[3]) == REGNO(operands[0]))"
13280 +
13281 + [(set (match_dup 3)
13282 + (logical:SI (match_op_dup:SI 5 [(match_dup 1) (match_dup 2)])
13283 + (match_dup 4)))]
13284 +
13285 + ""
13286 +)
13287 +
13288 +
13289 +;;=============================================================================
13290 +;; and
13291 +;;-----------------------------------------------------------------------------
13292 +;; Store the result after a bitwise logical-and between reg0 and reg2 in reg0.
13293 +;;=============================================================================
13294 +
13295 +(define_insn "andnsi"
13296 + [(set (match_operand:SI 0 "register_operand" "+r")
13297 + (and:SI (match_dup 0)
13298 + (not:SI (match_operand:SI 1 "register_operand" "r"))))]
13299 + ""
13300 + "andn %0, %1"
13301 + [(set_attr "cc" "set_z")
13302 + (set_attr "length" "2")]
13303 +)
13304 +
13305 +
13306 +(define_insn "andsi3"
13307 + [(set (match_operand:SI 0 "avr32_rmw_memory_or_register_operand" "=Y,r,r,r, r, r,r,r,r,r")
13308 + (and:SI (match_operand:SI 1 "avr32_rmw_memory_or_register_operand" "%0,r,0,0, 0, 0,0,0,0,r" )
13309 + (match_operand:SI 2 "nonmemory_operand" " N,M,N,Ku16,Ks17,J,L,r,i,r")))]
13310 + ""
13311 + "@
13312 + memc\t%0, %z2
13313 + bfextu\t%0, %1, 0, %z2
13314 + cbr\t%0, %z2
13315 + andl\t%0, %2, COH
13316 + andl\t%0, lo(%2)
13317 + andh\t%0, hi(%2), COH
13318 + andh\t%0, hi(%2)
13319 + and\t%0, %2
13320 + andh\t%0, hi(%2)\;andl\t%0, lo(%2)
13321 + and\t%0, %1, %2"
13322 +
13323 + [(set_attr "length" "4,4,2,4,4,4,4,2,8,4")
13324 + (set_attr "cc" "none,set_z,set_z,set_z,set_z,set_z,set_z,set_z,set_z,set_z")])
13325 +
13326 +
13327 +
13328 +(define_insn "anddi3"
13329 + [(set (match_operand:DI 0 "register_operand" "=&r,&r")
13330 + (and:DI (match_operand:DI 1 "register_operand" "%0,r")
13331 + (match_operand:DI 2 "register_operand" "r,r")))]
13332 + ""
13333 + "#"
13334 + [(set_attr "length" "8")
13335 + (set_attr "cc" "clobber")]
13336 +)
13337 +
13338 +;;=============================================================================
13339 +;; or
13340 +;;-----------------------------------------------------------------------------
13341 +;; Store the result after a bitwise inclusive-or between reg0 and reg2 in reg0.
13342 +;;=============================================================================
13343 +
13344 +(define_insn "iorsi3"
13345 + [(set (match_operand:SI 0 "avr32_rmw_memory_or_register_operand" "=Y,r,r, r,r,r,r")
13346 + (ior:SI (match_operand:SI 1 "avr32_rmw_memory_or_register_operand" "%0,0,0, 0,0,0,r" )
13347 + (match_operand:SI 2 "nonmemory_operand" " O,O,Ku16,J,r,i,r")))]
13348 + ""
13349 + "@
13350 + mems\t%0, %p2
13351 + sbr\t%0, %p2
13352 + orl\t%0, %2
13353 + orh\t%0, hi(%2)
13354 + or\t%0, %2
13355 + orh\t%0, hi(%2)\;orl\t%0, lo(%2)
13356 + or\t%0, %1, %2"
13357 +
13358 + [(set_attr "length" "4,2,4,4,2,8,4")
13359 + (set_attr "cc" "none,set_z,set_z,set_z,set_z,set_z,set_z")])
13360 +
13361 +
13362 +(define_insn "iordi3"
13363 + [(set (match_operand:DI 0 "register_operand" "=&r,&r")
13364 + (ior:DI (match_operand:DI 1 "register_operand" "%0,r")
13365 + (match_operand:DI 2 "register_operand" "r,r")))]
13366 + ""
13367 + "#"
13368 + [(set_attr "length" "8")
13369 + (set_attr "cc" "clobber")]
13370 +)
13371 +
13372 +;;=============================================================================
13373 +;; xor bytes
13374 +;;-----------------------------------------------------------------------------
13375 +;; Store the result after a bitwise exclusive-or between reg0 and reg2 in reg0.
13376 +;;=============================================================================
13377 +
13378 +(define_insn "xorsi3"
13379 + [(set (match_operand:SI 0 "avr32_rmw_memory_or_register_operand" "=Y,r, r,r,r,r")
13380 + (xor:SI (match_operand:SI 1 "avr32_rmw_memory_or_register_operand" "%0,0, 0,0,0,r" )
13381 + (match_operand:SI 2 "nonmemory_operand" " O,Ku16,J,r,i,r")))]
13382 + ""
13383 + "@
13384 + memt\t%0, %p2
13385 + eorl\t%0, %2
13386 + eorh\t%0, hi(%2)
13387 + eor\t%0, %2
13388 + eorh\t%0, hi(%2)\;eorl\t%0, lo(%2)
13389 + eor\t%0, %1, %2"
13390 +
13391 + [(set_attr "length" "4,4,4,2,8,4")
13392 + (set_attr "cc" "none,set_z,set_z,set_z,set_z,set_z")])
13393 +
13394 +(define_insn "xordi3"
13395 + [(set (match_operand:DI 0 "register_operand" "=&r,&r")
13396 + (xor:DI (match_operand:DI 1 "register_operand" "%0,r")
13397 + (match_operand:DI 2 "register_operand" "r,r")))]
13398 + ""
13399 + "#"
13400 + [(set_attr "length" "8")
13401 + (set_attr "cc" "clobber")]
13402 +)
13403 +
13404 +;;=============================================================================
13405 +;; Three operand predicable insns
13406 +;;=============================================================================
13407 +
13408 +(define_insn "<predicable_insn3><mode>_predicable"
13409 + [(set (match_operand:INTM 0 "register_operand" "=r")
13410 + (predicable_op3:INTM (match_operand:INTM 1 "register_operand" "<predicable_commutative3>r")
13411 + (match_operand:INTM 2 "register_operand" "r")))]
13412 + "TARGET_V2_INSNS"
13413 + "<predicable_insn3>%?\t%0, %1, %2"
13414 + [(set_attr "length" "4")
13415 + (set_attr "cc" "cmp_cond_insn")
13416 + (set_attr "predicable" "yes")]
13417 +)
13418 +
13419 +(define_insn_and_split "<predicable_insn3><mode>_imm_clobber_predicable"
13420 + [(parallel
13421 + [(set (match_operand:INTM 0 "register_operand" "=r")
13422 + (predicable_op3:INTM (match_operand:INTM 1 "register_operand" "<predicable_commutative3>r")
13423 + (match_operand:INTM 2 "avr32_mov_immediate_operand" "JKs21")))
13424 + (clobber (match_operand:INTM 3 "register_operand" "=&r"))])]
13425 + "TARGET_V2_INSNS"
13426 + {
13427 + if ( current_insn_predicate != NULL_RTX )
13428 + {
13429 + if ( avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks08") )
13430 + return "%! mov%?\t%3, %2\;<predicable_insn3>%?\t%0, %1, %3";
13431 + else if ( avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks21") )
13432 + return "%! mov\t%3, %2\;<predicable_insn3>%?\t%0, %1, %3";
13433 + else
13434 + return "%! movh\t%3, hi(%2)\;<predicable_insn3>%?\t%0, %1, %3";
13435 + }
13436 + else
13437 + {
13438 + if ( !avr32_cond_imm_clobber_splittable (insn, operands) )
13439 + {
13440 + if ( avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks08") )
13441 + return "mov%?\t%3, %2\;<predicable_insn3>%?\t%0, %1, %3";
13442 + else if ( avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks21") )
13443 + return "mov\t%3, %2\;<predicable_insn3>%?\t%0, %1, %3";
13444 + else
13445 + return "movh\t%3, hi(%2)\;<predicable_insn3>%?\t%0, %1, %3";
13446 + }
13447 + return "#";
13448 + }
13449 +
13450 + }
13451 + ;; If we find out that we could not actually do if-conversion on the block
13452 + ;; containing this insn we convert it back to normal immediate format
13453 + ;; to avoid outputing a redundant move insn
13454 + ;; Do not split until after we have checked if we can make the insn
13455 + ;; conditional.
13456 + "(GET_CODE (PATTERN (insn)) != COND_EXEC
13457 + && cfun->machine->ifcvt_after_reload
13458 + && avr32_cond_imm_clobber_splittable (insn, operands))"
13459 + [(set (match_dup 0)
13460 + (predicable_op3:INTM (match_dup 1)
13461 + (match_dup 2)))]
13462 + ""
13463 + [(set_attr "length" "8")
13464 + (set_attr "cc" "cmp_cond_insn")
13465 + (set_attr "predicable" "yes")]
13466 + )
13467 +
13468 +
13469 +;;=============================================================================
13470 +;; Zero extend predicable insns
13471 +;;=============================================================================
13472 +(define_insn_and_split "zero_extendhisi_clobber_predicable"
13473 + [(parallel
13474 + [(set (match_operand:SI 0 "register_operand" "=r")
13475 + (zero_extend:SI (match_operand:HI 1 "register_operand" "r")))
13476 + (clobber (match_operand:SI 2 "register_operand" "=&r"))])]
13477 + "TARGET_V2_INSNS"
13478 + {
13479 + if ( current_insn_predicate != NULL_RTX )
13480 + {
13481 + return "%! mov\t%2, 0xffff\;and%?\t%0, %1, %2";
13482 + }
13483 + else
13484 + {
13485 + return "#";
13486 + }
13487 +
13488 + }
13489 + ;; If we find out that we could not actually do if-conversion on the block
13490 + ;; containing this insn we convert it back to normal immediate format
13491 + ;; to avoid outputing a redundant move insn
13492 + ;; Do not split until after we have checked if we can make the insn
13493 + ;; conditional.
13494 + "(GET_CODE (PATTERN (insn)) != COND_EXEC
13495 + && cfun->machine->ifcvt_after_reload)"
13496 + [(set (match_dup 0)
13497 + (zero_extend:SI (match_dup 1)))]
13498 + ""
13499 + [(set_attr "length" "8")
13500 + (set_attr "cc" "cmp_cond_insn")
13501 + (set_attr "predicable" "yes")]
13502 + )
13503 +
13504 +(define_insn_and_split "zero_extendqisi_clobber_predicable"
13505 + [(parallel
13506 + [(set (match_operand:SI 0 "register_operand" "=r")
13507 + (zero_extend:SI (match_operand:QI 1 "register_operand" "r")))
13508 + (clobber (match_operand:SI 2 "register_operand" "=&r"))])]
13509 + "TARGET_V2_INSNS"
13510 + {
13511 + if ( current_insn_predicate != NULL_RTX )
13512 + {
13513 + return "%! mov\t%2, 0xff\;and%?\t%0, %1, %2";
13514 + }
13515 + else
13516 + {
13517 + return "#";
13518 + }
13519 +
13520 + }
13521 + ;; If we find out that we could not actually do if-conversion on the block
13522 + ;; containing this insn we convert it back to normal immediate format
13523 + ;; to avoid outputing a redundant move insn
13524 + ;; Do not split until after we have checked if we can make the insn
13525 + ;; conditional.
13526 + "(GET_CODE (PATTERN (insn)) != COND_EXEC
13527 + && cfun->machine->ifcvt_after_reload)"
13528 + [(set (match_dup 0)
13529 + (zero_extend:SI (match_dup 1)))]
13530 + ""
13531 + [(set_attr "length" "8")
13532 + (set_attr "cc" "cmp_cond_insn")
13533 + (set_attr "predicable" "yes")]
13534 + )
13535 +
13536 +(define_insn_and_split "zero_extendqihi_clobber_predicable"
13537 + [(parallel
13538 + [(set (match_operand:HI 0 "register_operand" "=r")
13539 + (zero_extend:HI (match_operand:QI 1 "register_operand" "r")))
13540 + (clobber (match_operand:SI 2 "register_operand" "=&r"))])]
13541 + "TARGET_V2_INSNS"
13542 + {
13543 + if ( current_insn_predicate != NULL_RTX )
13544 + {
13545 + return "%! mov\t%2, 0xff\;and%?\t%0, %1, %2";
13546 + }
13547 + else
13548 + {
13549 + return "#";
13550 + }
13551 +
13552 + }
13553 + ;; If we find out that we could not actually do if-conversion on the block
13554 + ;; containing this insn we convert it back to normal immediate format
13555 + ;; to avoid outputing a redundant move insn
13556 + ;; Do not split until after we have checked if we can make the insn
13557 + ;; conditional.
13558 + "(GET_CODE (PATTERN (insn)) != COND_EXEC
13559 + && cfun->machine->ifcvt_after_reload)"
13560 + [(set (match_dup 0)
13561 + (zero_extend:HI (match_dup 1)))]
13562 + ""
13563 + [(set_attr "length" "8")
13564 + (set_attr "cc" "cmp_cond_insn")
13565 + (set_attr "predicable" "yes")]
13566 + )
13567 +;;=============================================================================
13568 +;; divmod
13569 +;;-----------------------------------------------------------------------------
13570 +;; Signed division that produces both a quotient and a remainder.
13571 +;;=============================================================================
13572 +
13573 +(define_expand "divmodsi4"
13574 + [(parallel [
13575 + (parallel [
13576 + (set (match_operand:SI 0 "register_operand" "=r")
13577 + (div:SI (match_operand:SI 1 "register_operand" "r")
13578 + (match_operand:SI 2 "register_operand" "r")))
13579 + (set (match_operand:SI 3 "register_operand" "=r")
13580 + (mod:SI (match_dup 1)
13581 + (match_dup 2)))])
13582 + (use (match_dup 4))])]
13583 + ""
13584 + {
13585 + if (can_create_pseudo_p ()) {
13586 + operands[4] = gen_reg_rtx (DImode);
13587 + emit_insn(gen_divmodsi4_internal(operands[4],operands[1],operands[2]));
13588 + emit_move_insn(operands[0], gen_rtx_SUBREG( SImode, operands[4], 4));
13589 + emit_move_insn(operands[3], gen_rtx_SUBREG( SImode, operands[4], 0));
13590 + DONE;
13591 + } else {
13592 + FAIL;
13593 + }
13594 + })
13595 +
13596 +
13597 +(define_insn "divmodsi4_internal"
13598 + [(set (match_operand:DI 0 "register_operand" "=r")
13599 + (unspec:DI [(match_operand:SI 1 "register_operand" "r")
13600 + (match_operand:SI 2 "register_operand" "r")]
13601 + UNSPEC_DIVMODSI4_INTERNAL))]
13602 + ""
13603 + "divs %0, %1, %2"
13604 + [(set_attr "type" "div")
13605 + (set_attr "cc" "none")])
13606 +
13607 +
13608 +;;=============================================================================
13609 +;; udivmod
13610 +;;-----------------------------------------------------------------------------
13611 +;; Unsigned division that produces both a quotient and a remainder.
13612 +;;=============================================================================
13613 +(define_expand "udivmodsi4"
13614 + [(parallel [
13615 + (parallel [
13616 + (set (match_operand:SI 0 "register_operand" "=r")
13617 + (udiv:SI (match_operand:SI 1 "register_operand" "r")
13618 + (match_operand:SI 2 "register_operand" "r")))
13619 + (set (match_operand:SI 3 "register_operand" "=r")
13620 + (umod:SI (match_dup 1)
13621 + (match_dup 2)))])
13622 + (use (match_dup 4))])]
13623 + ""
13624 + {
13625 + if (can_create_pseudo_p ()) {
13626 + operands[4] = gen_reg_rtx (DImode);
13627 +
13628 + emit_insn(gen_udivmodsi4_internal(operands[4],operands[1],operands[2]));
13629 + emit_move_insn(operands[0], gen_rtx_SUBREG( SImode, operands[4], 4));
13630 + emit_move_insn(operands[3], gen_rtx_SUBREG( SImode, operands[4], 0));
13631 +
13632 + DONE;
13633 + } else {
13634 + FAIL;
13635 + }
13636 + })
13637 +
13638 +(define_insn "udivmodsi4_internal"
13639 + [(set (match_operand:DI 0 "register_operand" "=r")
13640 + (unspec:DI [(match_operand:SI 1 "register_operand" "r")
13641 + (match_operand:SI 2 "register_operand" "r")]
13642 + UNSPEC_UDIVMODSI4_INTERNAL))]
13643 + ""
13644 + "divu %0, %1, %2"
13645 + [(set_attr "type" "div")
13646 + (set_attr "cc" "none")])
13647 +
13648 +
13649 +;;=============================================================================
13650 +;; Arithmetic-shift left
13651 +;;-----------------------------------------------------------------------------
13652 +;; Arithmetic-shift reg0 left by reg2 or immediate value.
13653 +;;=============================================================================
13654 +
13655 +(define_insn "ashlsi3"
13656 + [(set (match_operand:SI 0 "register_operand" "=r,r,r")
13657 + (ashift:SI (match_operand:SI 1 "register_operand" "r,0,r")
13658 + (match_operand:SI 2 "register_const_int_operand" "r,Ku05,Ku05")))]
13659 + ""
13660 + "@
13661 + lsl %0, %1, %2
13662 + lsl %0, %2
13663 + lsl %0, %1, %2"
13664 + [(set_attr "length" "4,2,4")
13665 + (set_attr "cc" "set_ncz")])
13666 +
13667 +;;=============================================================================
13668 +;; Arithmetic-shift right
13669 +;;-----------------------------------------------------------------------------
13670 +;; Arithmetic-shift reg0 right by an immediate value.
13671 +;;=============================================================================
13672 +
13673 +(define_insn "ashrsi3"
13674 + [(set (match_operand:SI 0 "register_operand" "=r,r,r")
13675 + (ashiftrt:SI (match_operand:SI 1 "register_operand" "r,0,r")
13676 + (match_operand:SI 2 "register_const_int_operand" "r,Ku05,Ku05")))]
13677 + ""
13678 + "@
13679 + asr %0, %1, %2
13680 + asr %0, %2
13681 + asr %0, %1, %2"
13682 + [(set_attr "length" "4,2,4")
13683 + (set_attr "cc" "set_ncz")])
13684 +
13685 +;;=============================================================================
13686 +;; Logical shift right
13687 +;;-----------------------------------------------------------------------------
13688 +;; Logical shift reg0 right by an immediate value.
13689 +;;=============================================================================
13690 +
13691 +(define_insn "lshrsi3"
13692 + [(set (match_operand:SI 0 "register_operand" "=r,r,r")
13693 + (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,0,r")
13694 + (match_operand:SI 2 "register_const_int_operand" "r,Ku05,Ku05")))]
13695 + ""
13696 + "@
13697 + lsr %0, %1, %2
13698 + lsr %0, %2
13699 + lsr %0, %1, %2"
13700 + [(set_attr "length" "4,2,4")
13701 + (set_attr "cc" "set_ncz")])
13702 +
13703 +
13704 +;;=============================================================================
13705 +;; neg
13706 +;;-----------------------------------------------------------------------------
13707 +;; Negate operand 1 and store the result in operand 0.
13708 +;;=============================================================================
13709 +(define_insn "negsi2"
13710 + [(set (match_operand:SI 0 "register_operand" "=r,r")
13711 + (neg:SI (match_operand:SI 1 "register_operand" "0,r")))]
13712 + ""
13713 + "@
13714 + neg\t%0
13715 + rsub\t%0, %1, 0"
13716 + [(set_attr "length" "2,4")
13717 + (set_attr "cc" "set_vncz")])
13718 +
13719 +(define_insn "negsi2_predicable"
13720 + [(set (match_operand:SI 0 "register_operand" "+r")
13721 + (neg:SI (match_dup 0)))]
13722 + "TARGET_V2_INSNS"
13723 + "rsub%?\t%0, 0"
13724 + [(set_attr "length" "4")
13725 + (set_attr "cc" "cmp_cond_insn")
13726 + (set_attr "predicable" "yes")])
13727 +
13728 +;;=============================================================================
13729 +;; abs
13730 +;;-----------------------------------------------------------------------------
13731 +;; Store the absolute value of operand 1 into operand 0.
13732 +;;=============================================================================
13733 +(define_insn "abssi2"
13734 + [(set (match_operand:SI 0 "register_operand" "=r")
13735 + (abs:SI (match_operand:SI 1 "register_operand" "0")))]
13736 + ""
13737 + "abs\t%0"
13738 + [(set_attr "length" "2")
13739 + (set_attr "cc" "set_z")])
13740 +
13741 +
13742 +;;=============================================================================
13743 +;; one_cmpl
13744 +;;-----------------------------------------------------------------------------
13745 +;; Store the bitwise-complement of operand 1 into operand 0.
13746 +;;=============================================================================
13747 +
13748 +(define_insn "one_cmplsi2"
13749 + [(set (match_operand:SI 0 "register_operand" "=r,r")
13750 + (not:SI (match_operand:SI 1 "register_operand" "0,r")))]
13751 + ""
13752 + "@
13753 + com\t%0
13754 + rsub\t%0, %1, -1"
13755 + [(set_attr "length" "2,4")
13756 + (set_attr "cc" "set_z")])
13757 +
13758 +
13759 +(define_insn "one_cmplsi2_predicable"
13760 + [(set (match_operand:SI 0 "register_operand" "+r")
13761 + (not:SI (match_dup 0)))]
13762 + "TARGET_V2_INSNS"
13763 + "rsub%?\t%0, -1"
13764 + [(set_attr "length" "4")
13765 + (set_attr "cc" "cmp_cond_insn")
13766 + (set_attr "predicable" "yes")])
13767 +
13768 +
13769 +;;=============================================================================
13770 +;; Bit load
13771 +;;-----------------------------------------------------------------------------
13772 +;; Load a bit into Z and C flags
13773 +;;=============================================================================
13774 +(define_insn "bldsi"
13775 + [(set (cc0)
13776 + (and:SI (match_operand:SI 0 "register_operand" "r")
13777 + (match_operand:SI 1 "one_bit_set_operand" "i")))]
13778 + ""
13779 + "bld\t%0, %p1"
13780 + [(set_attr "length" "4")
13781 + (set_attr "cc" "bld")]
13782 + )
13783 +
13784 +
13785 +;;=============================================================================
13786 +;; Compare
13787 +;;-----------------------------------------------------------------------------
13788 +;; Compare reg0 with reg1 or an immediate value.
13789 +;;=============================================================================
13790 +
13791 +(define_expand "cmp<mode>"
13792 + [(set (cc0)
13793 + (compare:CMP
13794 + (match_operand:CMP 0 "register_operand" "")
13795 + (match_operand:CMP 1 "<CMP:cmp_predicate>" "")))]
13796 + ""
13797 + "{
13798 + avr32_compare_op0 = operands[0];
13799 + avr32_compare_op1 = operands[1];
13800 + }"
13801 +)
13802 +
13803 +(define_insn "cmp<mode>_internal"
13804 + [(set (cc0)
13805 + (compare:CMP
13806 + (match_operand:CMP 0 "register_operand" "r")
13807 + (match_operand:CMP 1 "<CMP:cmp_predicate>" "<CMP:cmp_constraint>")))]
13808 + ""
13809 + {
13810 + /* Check if the next insn already will output a compare. */
13811 + if (!next_insn_emits_cmp (insn))
13812 + set_next_insn_cond(insn,
13813 + avr32_output_cmp(get_next_insn_cond(insn), GET_MODE (operands[0]), operands[0], operands[1]));
13814 + return "";
13815 + }
13816 + [(set_attr "length" "4")
13817 + (set_attr "cc" "compare")])
13818 +
13819 +(define_expand "cmpsf"
13820 + [(set (cc0)
13821 + (compare:SF
13822 + (match_operand:SF 0 "general_operand" "")
13823 + (match_operand:SF 1 "general_operand" "")))]
13824 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
13825 + "{
13826 + rtx tmpreg;
13827 + if ( !REG_P(operands[0]) )
13828 + operands[0] = force_reg(SFmode, operands[0]);
13829 +
13830 + if ( !REG_P(operands[1]) )
13831 + operands[1] = force_reg(SFmode, operands[1]);
13832 +
13833 + avr32_compare_op0 = operands[0];
13834 + avr32_compare_op1 = operands[1];
13835 + emit_insn(gen_cmpsf_internal_uc3fp(operands[0], operands[1]));
13836 + DONE;
13837 + }"
13838 +)
13839 +
13840 +;;;=============================================================================
13841 +;; Test if zero
13842 +;;-----------------------------------------------------------------------------
13843 +;; Compare reg against zero and set the condition codes.
13844 +;;=============================================================================
13845 +
13846 +
13847 +(define_expand "tstsi"
13848 + [(set (cc0)
13849 + (match_operand:SI 0 "register_operand" ""))]
13850 + ""
13851 + {
13852 + avr32_compare_op0 = operands[0];
13853 + avr32_compare_op1 = const0_rtx;
13854 + }
13855 +)
13856 +
13857 +(define_insn "tstsi_internal"
13858 + [(set (cc0)
13859 + (match_operand:SI 0 "register_operand" "r"))]
13860 + ""
13861 + {
13862 + /* Check if the next insn already will output a compare. */
13863 + if (!next_insn_emits_cmp (insn))
13864 + set_next_insn_cond(insn,
13865 + avr32_output_cmp(get_next_insn_cond(insn), SImode, operands[0], const0_rtx));
13866 +
13867 + return "";
13868 + }
13869 + [(set_attr "length" "2")
13870 + (set_attr "cc" "compare")])
13871 +
13872 +
13873 +(define_expand "tstdi"
13874 + [(set (cc0)
13875 + (match_operand:DI 0 "register_operand" ""))]
13876 + ""
13877 + {
13878 + avr32_compare_op0 = operands[0];
13879 + avr32_compare_op1 = const0_rtx;
13880 + }
13881 +)
13882 +
13883 +(define_insn "tstdi_internal"
13884 + [(set (cc0)
13885 + (match_operand:DI 0 "register_operand" "r"))]
13886 + ""
13887 + {
13888 + /* Check if the next insn already will output a compare. */
13889 + if (!next_insn_emits_cmp (insn))
13890 + set_next_insn_cond(insn,
13891 + avr32_output_cmp(get_next_insn_cond(insn), DImode, operands[0], const0_rtx));
13892 + return "";
13893 + }
13894 + [(set_attr "length" "4")
13895 + (set_attr "type" "alu2")
13896 + (set_attr "cc" "compare")])
13897 +
13898 +
13899 +
13900 +;;=============================================================================
13901 +;; Convert operands
13902 +;;-----------------------------------------------------------------------------
13903 +;;
13904 +;;=============================================================================
13905 +(define_insn "truncdisi2"
13906 + [(set (match_operand:SI 0 "general_operand" "")
13907 + (truncate:SI (match_operand:DI 1 "general_operand" "")))]
13908 + ""
13909 + "truncdisi2")
13910 +
13911 +;;=============================================================================
13912 +;; Extend
13913 +;;-----------------------------------------------------------------------------
13914 +;;
13915 +;;=============================================================================
13916 +
13917 +
13918 +(define_insn "extendhisi2"
13919 + [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
13920 + (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "0,r,<RKu00>,m")))]
13921 + ""
13922 + {
13923 + switch ( which_alternative ){
13924 + case 0:
13925 + return "casts.h\t%0";
13926 + case 1:
13927 + return "bfexts\t%0, %1, 0, 16";
13928 + case 2:
13929 + case 3:
13930 + return "ld.sh\t%0, %1";
13931 + default:
13932 + abort();
13933 + }
13934 + }
13935 + [(set_attr "length" "2,4,2,4")
13936 + (set_attr "cc" "set_ncz,set_ncz,none,none")
13937 + (set_attr "type" "alu,alu,load_rm,load_rm")])
13938 +
13939 +(define_insn "extendqisi2"
13940 + [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
13941 + (sign_extend:SI (match_operand:QI 1 "extendqi_operand" "0,r,RKu00,m")))]
13942 + ""
13943 + {
13944 + switch ( which_alternative ){
13945 + case 0:
13946 + return "casts.b\t%0";
13947 + case 1:
13948 + return "bfexts\t%0, %1, 0, 8";
13949 + case 2:
13950 + case 3:
13951 + return "ld.sb\t%0, %1";
13952 + default:
13953 + abort();
13954 + }
13955 + }
13956 + [(set_attr "length" "2,4,2,4")
13957 + (set_attr "cc" "set_ncz,set_ncz,none,none")
13958 + (set_attr "type" "alu,alu,load_rm,load_rm")])
13959 +
13960 +(define_insn "extendqihi2"
13961 + [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
13962 + (sign_extend:HI (match_operand:QI 1 "extendqi_operand" "0,r,RKu00,m")))]
13963 + ""
13964 + {
13965 + switch ( which_alternative ){
13966 + case 0:
13967 + return "casts.b\t%0";
13968 + case 1:
13969 + return "bfexts\t%0, %1, 0, 8";
13970 + case 2:
13971 + case 3:
13972 + return "ld.sb\t%0, %1";
13973 + default:
13974 + abort();
13975 + }
13976 + }
13977 + [(set_attr "length" "2,4,2,4")
13978 + (set_attr "cc" "set_ncz,set_ncz,none,none")
13979 + (set_attr "type" "alu,alu,load_rm,load_rm")])
13980 +
13981 +
13982 +;;=============================================================================
13983 +;; Zero-extend
13984 +;;-----------------------------------------------------------------------------
13985 +;;
13986 +;;=============================================================================
13987 +
13988 +(define_insn "zero_extendhisi2"
13989 + [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
13990 + (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "0,r,<RKu00>,m")))]
13991 + ""
13992 + {
13993 + switch ( which_alternative ){
13994 + case 0:
13995 + return "castu.h\t%0";
13996 + case 1:
13997 + return "bfextu\t%0, %1, 0, 16";
13998 + case 2:
13999 + case 3:
14000 + return "ld.uh\t%0, %1";
14001 + default:
14002 + abort();
14003 + }
14004 + }
14005 +
14006 + [(set_attr "length" "2,4,2,4")
14007 + (set_attr "cc" "set_ncz,set_ncz,none,none")
14008 + (set_attr "type" "alu,alu,load_rm,load_rm")])
14009 +
14010 +(define_insn "zero_extendqisi2"
14011 + [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
14012 + (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "0,r,<RKu00>,m")))]
14013 + ""
14014 + {
14015 + switch ( which_alternative ){
14016 + case 0:
14017 + return "castu.b\t%0";
14018 + case 1:
14019 + return "bfextu\t%0, %1, 0, 8";
14020 + case 2:
14021 + case 3:
14022 + return "ld.ub\t%0, %1";
14023 + default:
14024 + abort();
14025 + }
14026 + }
14027 + [(set_attr "length" "2,4,2,4")
14028 + (set_attr "cc" "set_ncz, set_ncz, none, none")
14029 + (set_attr "type" "alu, alu, load_rm, load_rm")])
14030 +
14031 +(define_insn "zero_extendqihi2"
14032 + [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
14033 + (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,r,<RKu00>,m")))]
14034 + ""
14035 + {
14036 + switch ( which_alternative ){
14037 + case 0:
14038 + return "castu.b\t%0";
14039 + case 1:
14040 + return "bfextu\t%0, %1, 0, 8";
14041 + case 2:
14042 + case 3:
14043 + return "ld.ub\t%0, %1";
14044 + default:
14045 + abort();
14046 + }
14047 + }
14048 + [(set_attr "length" "2,4,2,4")
14049 + (set_attr "cc" "set_ncz, set_ncz, none, none")
14050 + (set_attr "type" "alu, alu, load_rm, load_rm")])
14051 +
14052 +
14053 +;;=============================================================================
14054 +;; Conditional load and extend insns
14055 +;;=============================================================================
14056 +(define_insn "ldsi<mode>_predicable_se"
14057 + [(set (match_operand:SI 0 "register_operand" "=r")
14058 + (sign_extend:SI
14059 + (match_operand:INTM 1 "memory_operand" "<INTM:pred_mem_constraint>")))]
14060 + "TARGET_V2_INSNS"
14061 + "ld<INTM:load_postfix_s>%?\t%0, %1"
14062 + [(set_attr "length" "4")
14063 + (set_attr "cc" "cmp_cond_insn")
14064 + (set_attr "type" "load")
14065 + (set_attr "predicable" "yes")]
14066 +)
14067 +
14068 +(define_insn "ldsi<mode>_predicable_ze"
14069 + [(set (match_operand:SI 0 "register_operand" "=r")
14070 + (zero_extend:SI
14071 + (match_operand:INTM 1 "memory_operand" "<INTM:pred_mem_constraint>")))]
14072 + "TARGET_V2_INSNS"
14073 + "ld<INTM:load_postfix_u>%?\t%0, %1"
14074 + [(set_attr "length" "4")
14075 + (set_attr "cc" "cmp_cond_insn")
14076 + (set_attr "type" "load")
14077 + (set_attr "predicable" "yes")]
14078 +)
14079 +
14080 +(define_insn "ldhi_predicable_ze"
14081 + [(set (match_operand:HI 0 "register_operand" "=r")
14082 + (zero_extend:HI
14083 + (match_operand:QI 1 "memory_operand" "RKs10")))]
14084 + "TARGET_V2_INSNS"
14085 + "ld.ub%?\t%0, %1"
14086 + [(set_attr "length" "4")
14087 + (set_attr "cc" "cmp_cond_insn")
14088 + (set_attr "type" "load")
14089 + (set_attr "predicable" "yes")]
14090 +)
14091 +
14092 +(define_insn "ldhi_predicable_se"
14093 + [(set (match_operand:HI 0 "register_operand" "=r")
14094 + (sign_extend:HI
14095 + (match_operand:QI 1 "memory_operand" "RKs10")))]
14096 + "TARGET_V2_INSNS"
14097 + "ld.sb%?\t%0, %1"
14098 + [(set_attr "length" "4")
14099 + (set_attr "cc" "cmp_cond_insn")
14100 + (set_attr "type" "load")
14101 + (set_attr "predicable" "yes")]
14102 +)
14103 +
14104 +;;=============================================================================
14105 +;; Conditional set register
14106 +;; sr{cond4} rd
14107 +;;-----------------------------------------------------------------------------
14108 +
14109 +;;Because of the same issue as with conditional moves and adds we must
14110 +;;not separate the compare instrcution from the scc instruction as
14111 +;;they might be sheduled "badly".
14112 +
14113 +(define_insn "s<code>"
14114 + [(set (match_operand:SI 0 "register_operand" "=r")
14115 + (any_cond:SI (cc0)
14116 + (const_int 0)))]
14117 + ""
14118 + "sr<cond>\t%0"
14119 + [(set_attr "length" "2")
14120 + (set_attr "cc" "none")])
14121 +
14122 +(define_insn "smi"
14123 + [(set (match_operand:SI 0 "register_operand" "=r")
14124 + (unspec:SI [(cc0)
14125 + (const_int 0)] UNSPEC_COND_MI))]
14126 + ""
14127 + "srmi\t%0"
14128 + [(set_attr "length" "2")
14129 + (set_attr "cc" "none")])
14130 +
14131 +(define_insn "spl"
14132 + [(set (match_operand:SI 0 "register_operand" "=r")
14133 + (unspec:SI [(cc0)
14134 + (const_int 0)] UNSPEC_COND_PL))]
14135 + ""
14136 + "srpl\t%0"
14137 + [(set_attr "length" "2")
14138 + (set_attr "cc" "none")])
14139 +
14140 +
14141 +;;=============================================================================
14142 +;; Conditional branch
14143 +;;-----------------------------------------------------------------------------
14144 +;; Branch to label if the specified condition codes are set.
14145 +;;=============================================================================
14146 +; branch if negative
14147 +(define_insn "bmi"
14148 + [(set (pc)
14149 + (if_then_else (unspec:CC [(cc0) (const_int 0)] UNSPEC_COND_MI)
14150 + (label_ref (match_operand 0 "" ""))
14151 + (pc)))]
14152 + ""
14153 + "brmi %0"
14154 + [(set_attr "type" "branch")
14155 + (set (attr "length")
14156 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14157 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14158 + (const_int 2)] ; use compact branch
14159 + (const_int 4))) ; use extended branch
14160 + (set_attr "cc" "none")])
14161 +
14162 +(define_insn "*bmi-reverse"
14163 + [(set (pc)
14164 + (if_then_else (unspec:CC [(cc0) (const_int 0)] UNSPEC_COND_MI)
14165 + (pc)
14166 + (label_ref (match_operand 0 "" ""))))]
14167 + ""
14168 + "brpl %0"
14169 + [(set_attr "type" "branch")
14170 + (set (attr "length")
14171 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14172 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14173 + (const_int 2)] ; use compact branch
14174 + (const_int 4))) ; use extended branch
14175 + (set_attr "cc" "none")])
14176 +
14177 +; branch if positive
14178 +(define_insn "bpl"
14179 + [(set (pc)
14180 + (if_then_else (unspec:CC [(cc0) (const_int 0)] UNSPEC_COND_PL)
14181 + (label_ref (match_operand 0 "" ""))
14182 + (pc)))]
14183 + ""
14184 + "brpl %0"
14185 + [(set_attr "type" "branch")
14186 + (set (attr "length")
14187 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14188 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14189 + (const_int 2)] ; use compact branch
14190 + (const_int 4))) ; use extended branch
14191 + (set_attr "cc" "none")])
14192 +
14193 +(define_insn "*bpl-reverse"
14194 + [(set (pc)
14195 + (if_then_else (unspec:CC [(cc0) (const_int 0)] UNSPEC_COND_PL)
14196 + (pc)
14197 + (label_ref (match_operand 0 "" ""))))]
14198 + ""
14199 + "brmi %0"
14200 + [(set_attr "type" "branch")
14201 + (set (attr "length")
14202 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14203 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14204 + (const_int 2)] ; use compact branch
14205 + (const_int 4))) ; use extended branch
14206 + (set_attr "cc" "none")])
14207 +
14208 +; branch if equal
14209 +(define_insn "b<code>"
14210 + [(set (pc)
14211 + (if_then_else (any_cond:CC (cc0)
14212 + (const_int 0))
14213 + (label_ref (match_operand 0 "" ""))
14214 + (pc)))]
14215 + ""
14216 + "br<cond> %0 "
14217 + [(set_attr "type" "branch")
14218 + (set (attr "length")
14219 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14220 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14221 + (const_int 2)] ; use compact branch
14222 + (const_int 4))) ; use extended branch
14223 + (set_attr "cc" "none")])
14224 +
14225 +
14226 +(define_insn "*b<code>-reverse"
14227 + [(set (pc)
14228 + (if_then_else (any_cond:CC (cc0)
14229 + (const_int 0))
14230 + (pc)
14231 + (label_ref (match_operand 0 "" ""))))]
14232 + ""
14233 + "br<invcond> %0 "
14234 + [(set_attr "type" "branch")
14235 + (set (attr "length")
14236 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14237 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14238 + (const_int 2)] ; use compact branch
14239 + (const_int 4))) ; use extended branch
14240 + (set_attr "cc" "none")])
14241 +
14242 +
14243 +
14244 +;=============================================================================
14245 +; Conditional Add/Subtract
14246 +;-----------------------------------------------------------------------------
14247 +; sub{cond4} Rd, imm
14248 +;=============================================================================
14249 +
14250 +
14251 +(define_expand "add<mode>cc"
14252 + [(set (match_operand:ADDCC 0 "register_operand" "")
14253 + (if_then_else:ADDCC (match_operator 1 "avr32_comparison_operator"
14254 + [(match_dup 4)
14255 + (match_dup 5)])
14256 + (match_operand:ADDCC 2 "register_operand" "")
14257 + (plus:ADDCC
14258 + (match_dup 2)
14259 + (match_operand:ADDCC 3 "" ""))))]
14260 + ""
14261 + {
14262 + if ( !(GET_CODE (operands[3]) == CONST_INT
14263 + || (TARGET_V2_INSNS && REG_P(operands[3]))) ){
14264 + FAIL;
14265 + }
14266 +
14267 + /* Delete compare instruction as it is merged into this instruction */
14268 + remove_insn (get_last_insn_anywhere ());
14269 +
14270 + operands[4] = avr32_compare_op0;
14271 + operands[5] = avr32_compare_op1;
14272 +
14273 + if ( TARGET_V2_INSNS
14274 + && REG_P(operands[3])
14275 + && REGNO(operands[0]) != REGNO(operands[2]) ){
14276 + emit_move_insn (operands[0], operands[2]);
14277 + operands[2] = operands[0];
14278 + }
14279 + }
14280 + )
14281 +
14282 +(define_insn "add<ADDCC:mode>cc_cmp<CMP:mode>_reg"
14283 + [(set (match_operand:ADDCC 0 "register_operand" "=r")
14284 + (if_then_else:ADDCC (match_operator 1 "avr32_comparison_operator"
14285 + [(match_operand:CMP 4 "register_operand" "r")
14286 + (match_operand:CMP 5 "<CMP:cmp_predicate>" "<CMP:cmp_constraint>")])
14287 + (match_dup 0)
14288 + (plus:ADDCC
14289 + (match_operand:ADDCC 2 "register_operand" "r")
14290 + (match_operand:ADDCC 3 "register_operand" "r"))))]
14291 + "TARGET_V2_INSNS"
14292 + {
14293 + operands[1] = avr32_output_cmp(operands[1], GET_MODE(operands[4]), operands[4], operands[5]);
14294 + return "add%i1\t%0, %2, %3";
14295 + }
14296 + [(set_attr "length" "8")
14297 + (set_attr "cc" "cmp_cond_insn")])
14298 +
14299 +(define_insn "add<ADDCC:mode>cc_cmp<CMP:mode>"
14300 + [(set (match_operand:ADDCC 0 "register_operand" "=r")
14301 + (if_then_else:ADDCC (match_operator 1 "avr32_comparison_operator"
14302 + [(match_operand:CMP 4 "register_operand" "r")
14303 + (match_operand:CMP 5 "<CMP:cmp_predicate>" "<CMP:cmp_constraint>")])
14304 + (match_operand:ADDCC 2 "register_operand" "0")
14305 + (plus:ADDCC
14306 + (match_dup 2)
14307 + (match_operand:ADDCC 3 "avr32_cond_immediate_operand" "Is08"))))]
14308 + ""
14309 + {
14310 + operands[1] = avr32_output_cmp(operands[1], GET_MODE(operands[4]), operands[4], operands[5]);
14311 + return "sub%i1\t%0, -%3";
14312 + }
14313 + [(set_attr "length" "8")
14314 + (set_attr "cc" "cmp_cond_insn")])
14315 +
14316 +;=============================================================================
14317 +; Conditional Move
14318 +;-----------------------------------------------------------------------------
14319 +; mov{cond4} Rd, (Rs/imm)
14320 +;=============================================================================
14321 +(define_expand "mov<mode>cc"
14322 + [(set (match_operand:MOVCC 0 "register_operand" "")
14323 + (if_then_else:MOVCC (match_operator 1 "avr32_comparison_operator"
14324 + [(match_dup 4)
14325 + (match_dup 5)])
14326 + (match_operand:MOVCC 2 "avr32_cond_register_immediate_operand" "")
14327 + (match_operand:MOVCC 3 "avr32_cond_register_immediate_operand" "")))]
14328 + ""
14329 + {
14330 + /* Delete compare instruction as it is merged into this instruction */
14331 + remove_insn (get_last_insn_anywhere ());
14332 +
14333 + operands[4] = avr32_compare_op0;
14334 + operands[5] = avr32_compare_op1;
14335 + }
14336 + )
14337 +
14338 +
14339 +(define_insn "mov<MOVCC:mode>cc_cmp<CMP:mode>"
14340 + [(set (match_operand:MOVCC 0 "register_operand" "=r,r,r")
14341 + (if_then_else:MOVCC (match_operator 1 "avr32_comparison_operator"
14342 + [(match_operand:CMP 4 "register_operand" "r,r,r")
14343 + (match_operand:CMP 5 "<CMP:cmp_predicate>" "<CMP:cmp_constraint>,<CMP:cmp_constraint>,<CMP:cmp_constraint>")])
14344 + (match_operand:MOVCC 2 "avr32_cond_register_immediate_operand" "0, rKs08,rKs08")
14345 + (match_operand:MOVCC 3 "avr32_cond_register_immediate_operand" "rKs08,0,rKs08")))]
14346 + ""
14347 + {
14348 + operands[1] = avr32_output_cmp(operands[1], GET_MODE(operands[4]), operands[4], operands[5]);
14349 +
14350 + switch( which_alternative ){
14351 + case 0:
14352 + return "mov%i1 %0, %3";
14353 + case 1:
14354 + return "mov%1 %0, %2";
14355 + case 2:
14356 + return "mov%1 %0, %2\;mov%i1 %0, %3";
14357 + default:
14358 + abort();
14359 + }
14360 +
14361 + }
14362 + [(set_attr "length" "8,8,12")
14363 + (set_attr "cc" "cmp_cond_insn")])
14364 +
14365 +
14366 +
14367 +
14368 +;;=============================================================================
14369 +;; jump
14370 +;;-----------------------------------------------------------------------------
14371 +;; Jump inside a function; an unconditional branch to a label.
14372 +;;=============================================================================
14373 +(define_insn "jump"
14374 + [(set (pc)
14375 + (label_ref (match_operand 0 "" "")))]
14376 + ""
14377 + {
14378 + if (get_attr_length(insn) > 4)
14379 + return "Can't jump this far";
14380 + return (get_attr_length(insn) == 2 ?
14381 + "rjmp %0" : "bral %0");
14382 + }
14383 + [(set_attr "type" "branch")
14384 + (set (attr "length")
14385 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 1022))
14386 + (le (minus (pc) (match_dup 0)) (const_int 1024)))
14387 + (const_int 2) ; use rjmp
14388 + (le (match_dup 0) (const_int 1048575))
14389 + (const_int 4)] ; use bral
14390 + (const_int 8))) ; do something else
14391 + (set_attr "cc" "none")])
14392 +
14393 +;;=============================================================================
14394 +;; call
14395 +;;-----------------------------------------------------------------------------
14396 +;; Subroutine call instruction returning no value.
14397 +;;=============================================================================
14398 +(define_insn "call_internal"
14399 + [(parallel [(call (mem:SI (match_operand:SI 0 "avr32_call_operand" "r,U,T,W"))
14400 + (match_operand 1 "" ""))
14401 + (clobber (reg:SI LR_REGNUM))])]
14402 + ""
14403 + {
14404 +
14405 + /* Check for a flashvault call. */
14406 + if (avr32_flashvault_call (SYMBOL_REF_DECL (operands[0])))
14407 + {
14408 + /* Assembly is already emitted. */
14409 + return "";
14410 + }
14411 +
14412 + switch (which_alternative) {
14413 + case 0:
14414 + return "icall\t%0";
14415 + case 1:
14416 + return "rcall\t%0";
14417 + case 2:
14418 + return "mcall\t%0";
14419 + case 3:
14420 + if (TARGET_HAS_ASM_ADDR_PSEUDOS)
14421 + return "call\t%0";
14422 + else
14423 + return "mcall\tr6[%0@got]";
14424 + default:
14425 + abort();
14426 + }
14427 + }
14428 + [(set_attr "type" "call")
14429 + (set_attr "length" "2,4,4,10")
14430 + (set_attr "cc" "clobber")])
14431 +
14432 +
14433 +(define_expand "call"
14434 + [(parallel [(call (match_operand:SI 0 "" "")
14435 + (match_operand 1 "" ""))
14436 + (clobber (reg:SI LR_REGNUM))])]
14437 + ""
14438 + {
14439 + rtx call_address;
14440 + if ( GET_CODE(operands[0]) != MEM )
14441 + FAIL;
14442 +
14443 + call_address = XEXP(operands[0], 0);
14444 +
14445 + /* If assembler supports call pseudo insn and the call address is a symbol then nothing special needs to be done. */
14446 + if (TARGET_HAS_ASM_ADDR_PSEUDOS && (GET_CODE(call_address) == SYMBOL_REF) )
14447 + {
14448 + /* We must however mark the function as using the GOT if flag_pic is set, since the call insn might turn into a mcall using the GOT ptr register. */
14449 + if (flag_pic)
14450 + {
14451 + current_function_uses_pic_offset_table = 1;
14452 + emit_call_insn(gen_call_internal(call_address, operands[1]));
14453 + DONE;
14454 + }
14455 + }
14456 + else
14457 + {
14458 + if (flag_pic && GET_CODE(call_address) == SYMBOL_REF )
14459 + {
14460 + current_function_uses_pic_offset_table = 1;
14461 + emit_call_insn(gen_call_internal(call_address, operands[1]));
14462 + DONE;
14463 + }
14464 +
14465 + if (!SYMBOL_REF_RCALL_FUNCTION_P(operands[0]) )
14466 + {
14467 + if (optimize_size && GET_CODE(call_address) == SYMBOL_REF )
14468 + {
14469 + call_address = force_const_mem(SImode, call_address);
14470 + }
14471 + else
14472 + {
14473 + call_address = force_reg(SImode, call_address);
14474 + }
14475 + }
14476 + }
14477 + emit_call_insn(gen_call_internal(call_address, operands[1]));
14478 + DONE;
14479 +
14480 + }
14481 +)
14482 +
14483 +;;=============================================================================
14484 +;; call_value
14485 +;;-----------------------------------------------------------------------------
14486 +;; Subroutine call instruction returning a value.
14487 +;;=============================================================================
14488 +(define_expand "call_value"
14489 + [(parallel [(set (match_operand:SI 0 "" "")
14490 + (call (match_operand:SI 1 "" "")
14491 + (match_operand 2 "" "")))
14492 + (clobber (reg:SI LR_REGNUM))])]
14493 + ""
14494 + {
14495 + rtx call_address;
14496 + if ( GET_CODE(operands[1]) != MEM )
14497 + FAIL;
14498 +
14499 + call_address = XEXP(operands[1], 0);
14500 +
14501 + /* Check for a flashvault call.
14502 + if (GET_CODE (call_address) == SYMBOL_REF
14503 + && avr32_flashvault_call (SYMBOL_REF_DECL (call_address)))
14504 + DONE;
14505 +
14506 + */
14507 +
14508 + /* If assembler supports call pseudo insn and the call
14509 + address is a symbol then nothing special needs to be done. */
14510 + if ( TARGET_HAS_ASM_ADDR_PSEUDOS
14511 + && (GET_CODE(call_address) == SYMBOL_REF) ){
14512 + /* We must however mark the function as using the GOT if
14513 + flag_pic is set, since the call insn might turn into
14514 + a mcall using the GOT ptr register. */
14515 + if ( flag_pic ) {
14516 + current_function_uses_pic_offset_table = 1;
14517 + emit_call_insn(gen_call_value_internal(operands[0], call_address, operands[2]));
14518 + DONE;
14519 + }
14520 + } else {
14521 + if ( flag_pic &&
14522 + GET_CODE(call_address) == SYMBOL_REF ){
14523 + current_function_uses_pic_offset_table = 1;
14524 + emit_call_insn(gen_call_value_internal(operands[0], call_address, operands[2]));
14525 + DONE;
14526 + }
14527 +
14528 + if ( !SYMBOL_REF_RCALL_FUNCTION_P(operands[1]) ){
14529 + if ( optimize_size &&
14530 + GET_CODE(call_address) == SYMBOL_REF){
14531 + call_address = force_const_mem(SImode, call_address);
14532 + } else {
14533 + call_address = force_reg(SImode, call_address);
14534 + }
14535 + }
14536 + }
14537 + emit_call_insn(gen_call_value_internal(operands[0], call_address,
14538 + operands[2]));
14539 + DONE;
14540 +
14541 + })
14542 +
14543 +(define_insn "call_value_internal"
14544 + [(parallel [(set (match_operand 0 "register_operand" "=r,r,r,r")
14545 + (call (mem:SI (match_operand:SI 1 "avr32_call_operand" "r,U,T,W"))
14546 + (match_operand 2 "" "")))
14547 + (clobber (reg:SI LR_REGNUM))])]
14548 + ;; Operand 2 not used on the AVR32.
14549 + ""
14550 + {
14551 + /* Check for a flashvault call. */
14552 + if (avr32_flashvault_call (SYMBOL_REF_DECL (operands[1])))
14553 + {
14554 + /* Assembly is already emitted. */
14555 + return "";
14556 + }
14557 +
14558 +
14559 + switch (which_alternative) {
14560 + case 0:
14561 + return "icall\t%1";
14562 + case 1:
14563 + return "rcall\t%1";
14564 + case 2:
14565 + return "mcall\t%1";
14566 + case 3:
14567 + if ( TARGET_HAS_ASM_ADDR_PSEUDOS )
14568 + return "call\t%1";
14569 + else
14570 + return "mcall\tr6[%1@got]";
14571 + default:
14572 + abort();
14573 + }
14574 + }
14575 + [(set_attr "type" "call")
14576 + (set_attr "length" "2,4,4,10")
14577 + (set_attr "cc" "call_set")])
14578 +
14579 +
14580 +;;=============================================================================
14581 +;; untyped_call
14582 +;;-----------------------------------------------------------------------------
14583 +;; Subrutine call instruction returning a value of any type.
14584 +;; The code is copied from m68k.md (except gen_blockage is removed)
14585 +;; Fixme!
14586 +;;=============================================================================
14587 +(define_expand "untyped_call"
14588 + [(parallel [(call (match_operand 0 "avr32_call_operand" "")
14589 + (const_int 0))
14590 + (match_operand 1 "" "")
14591 + (match_operand 2 "" "")])]
14592 + ""
14593 + {
14594 + int i;
14595 +
14596 + emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
14597 +
14598 + for (i = 0; i < XVECLEN (operands[2], 0); i++) {
14599 + rtx set = XVECEXP (operands[2], 0, i);
14600 + emit_move_insn (SET_DEST (set), SET_SRC (set));
14601 + }
14602 +
14603 + /* The optimizer does not know that the call sets the function value
14604 + registers we stored in the result block. We avoid problems by
14605 + claiming that all hard registers are used and clobbered at this
14606 + point. */
14607 + emit_insn (gen_blockage ());
14608 +
14609 + DONE;
14610 + })
14611 +
14612 +
14613 +;;=============================================================================
14614 +;; return
14615 +;;=============================================================================
14616 +
14617 +(define_insn "return"
14618 + [(return)]
14619 + "USE_RETURN_INSN (FALSE)"
14620 + {
14621 + avr32_output_return_instruction(TRUE, FALSE, NULL, NULL);
14622 + return "";
14623 + }
14624 + [(set_attr "length" "4")
14625 + (set_attr "type" "call")]
14626 + )
14627 +
14628 +
14629 +(define_insn "return_cond"
14630 + [(set (pc)
14631 + (if_then_else (match_operand 0 "avr32_comparison_operand" "")
14632 + (return)
14633 + (pc)))]
14634 + "USE_RETURN_INSN (TRUE)"
14635 + "ret%0\tr12";
14636 + [(set_attr "type" "call")])
14637 +
14638 +(define_insn "return_cond_predicable"
14639 + [(return)]
14640 + "USE_RETURN_INSN (TRUE)"
14641 + "ret%?\tr12";
14642 + [(set_attr "type" "call")
14643 + (set_attr "predicable" "yes")])
14644 +
14645 +
14646 +(define_insn "return_imm"
14647 + [(parallel [(set (reg RETVAL_REGNUM) (match_operand 0 "immediate_operand" "i"))
14648 + (use (reg RETVAL_REGNUM))
14649 + (return)])]
14650 + "USE_RETURN_INSN (FALSE) &&
14651 + ((INTVAL(operands[0]) == -1) || (INTVAL(operands[0]) == 0) || (INTVAL(operands[0]) == 1))"
14652 + {
14653 + avr32_output_return_instruction(TRUE, FALSE, NULL, operands[0]);
14654 + return "";
14655 + }
14656 + [(set_attr "length" "4")
14657 + (set_attr "type" "call")]
14658 + )
14659 +
14660 +(define_insn "return_imm_cond"
14661 + [(parallel [(set (reg RETVAL_REGNUM) (match_operand 0 "immediate_operand" "i"))
14662 + (use (reg RETVAL_REGNUM))
14663 + (set (pc)
14664 + (if_then_else (match_operand 1 "avr32_comparison_operand" "")
14665 + (return)
14666 + (pc)))])]
14667 + "USE_RETURN_INSN (TRUE) &&
14668 + ((INTVAL(operands[0]) == -1) || (INTVAL(operands[0]) == 0) || (INTVAL(operands[0]) == 1))"
14669 + "ret%1\t%0";
14670 + [(set_attr "type" "call")]
14671 + )
14672 +
14673 +(define_insn "return_imm_predicable"
14674 + [(parallel [(set (reg RETVAL_REGNUM) (match_operand 0 "immediate_operand" "i"))
14675 + (use (reg RETVAL_REGNUM))
14676 + (return)])]
14677 + "USE_RETURN_INSN (TRUE) &&
14678 + ((INTVAL(operands[0]) == -1) || (INTVAL(operands[0]) == 0) || (INTVAL(operands[0]) == 1))"
14679 + "ret%?\t%0";
14680 + [(set_attr "type" "call")
14681 + (set_attr "predicable" "yes")])
14682 +
14683 +(define_insn "return_<mode>reg"
14684 + [(set (reg RETVAL_REGNUM) (match_operand:MOVM 0 "register_operand" "r"))
14685 + (use (reg RETVAL_REGNUM))
14686 + (return)]
14687 + "USE_RETURN_INSN (TRUE)"
14688 + "ret%?\t%0";
14689 + [(set_attr "type" "call")
14690 + (set_attr "predicable" "yes")])
14691 +
14692 +(define_insn "return_<mode>reg_cond"
14693 + [(set (reg RETVAL_REGNUM) (match_operand:MOVM 0 "register_operand" "r"))
14694 + (use (reg RETVAL_REGNUM))
14695 + (set (pc)
14696 + (if_then_else (match_operator 1 "avr32_comparison_operator"
14697 + [(cc0) (const_int 0)])
14698 + (return)
14699 + (pc)))]
14700 + "USE_RETURN_INSN (TRUE)"
14701 + "ret%1\t%0";
14702 + [(set_attr "type" "call")])
14703 +
14704 +;;=============================================================================
14705 +;; nonlocal_goto_receiver
14706 +;;-----------------------------------------------------------------------------
14707 +;; For targets with a return stack we must make sure to flush the return stack
14708 +;; since it will be corrupt after a nonlocal goto.
14709 +;;=============================================================================
14710 +(define_expand "nonlocal_goto_receiver"
14711 + [(const_int 0)]
14712 + "TARGET_RETURN_STACK"
14713 + "
14714 + {
14715 + emit_insn ( gen_frs() );
14716 + DONE;
14717 + }
14718 + "
14719 + )
14720 +
14721 +
14722 +;;=============================================================================
14723 +;; builtin_setjmp_receiver
14724 +;;-----------------------------------------------------------------------------
14725 +;; For pic code we need to reload the pic register.
14726 +;; For targets with a return stack we must make sure to flush the return stack
14727 +;; since it will probably be corrupted.
14728 +;;=============================================================================
14729 +(define_expand "builtin_setjmp_receiver"
14730 + [(label_ref (match_operand 0 "" ""))]
14731 + "flag_pic"
14732 + "
14733 + {
14734 + if ( TARGET_RETURN_STACK )
14735 + emit_insn ( gen_frs() );
14736 +
14737 + avr32_load_pic_register ();
14738 + DONE;
14739 + }
14740 + "
14741 +)
14742 +
14743 +
14744 +;;=============================================================================
14745 +;; indirect_jump
14746 +;;-----------------------------------------------------------------------------
14747 +;; Jump to an address in reg or memory.
14748 +;;=============================================================================
14749 +(define_expand "indirect_jump"
14750 + [(set (pc)
14751 + (match_operand:SI 0 "general_operand" ""))]
14752 + ""
14753 + {
14754 + /* One of the ops has to be in a register. */
14755 + if ( (flag_pic || TARGET_HAS_ASM_ADDR_PSEUDOS )
14756 + && !avr32_legitimate_pic_operand_p(operands[0]) )
14757 + operands[0] = legitimize_pic_address (operands[0], SImode, 0);
14758 + else if ( flag_pic && avr32_address_operand(operands[0], GET_MODE(operands[0])) )
14759 + /* If we have an address operand then this function uses the pic register. */
14760 + current_function_uses_pic_offset_table = 1;
14761 + })
14762 +
14763 +
14764 +(define_insn "indirect_jump_internal"
14765 + [(set (pc)
14766 + (match_operand:SI 0 "avr32_non_rmw_general_operand" "r,m,W"))]
14767 + ""
14768 + {
14769 + switch( which_alternative ){
14770 + case 0:
14771 + return "mov\tpc, %0";
14772 + case 1:
14773 + if ( avr32_const_pool_ref_operand(operands[0], GET_MODE(operands[0])) )
14774 + return "lddpc\tpc, %0";
14775 + else
14776 + return "ld.w\tpc, %0";
14777 + case 2:
14778 + if ( flag_pic )
14779 + return "ld.w\tpc, r6[%0@got]";
14780 + else
14781 + return "lda.w\tpc, %0";
14782 + default:
14783 + abort();
14784 + }
14785 + }
14786 + [(set_attr "length" "2,4,8")
14787 + (set_attr "type" "call,call,call")
14788 + (set_attr "cc" "none,none,clobber")])
14789 +
14790 +
14791 +
14792 +;;=============================================================================
14793 +;; casesi and tablejump
14794 +;;=============================================================================
14795 +(define_insn "tablejump_add"
14796 + [(set (pc)
14797 + (plus:SI (match_operand:SI 0 "register_operand" "r")
14798 + (mult:SI (match_operand:SI 1 "register_operand" "r")
14799 + (match_operand:SI 2 "immediate_operand" "Ku04" ))))
14800 + (use (label_ref (match_operand 3 "" "")))]
14801 + "flag_pic &&
14802 + ((INTVAL(operands[2]) == 0) || (INTVAL(operands[2]) == 2) ||
14803 + (INTVAL(operands[2]) == 4) || (INTVAL(operands[2]) == 8))"
14804 + "add\tpc, %0, %1 << %p2"
14805 + [(set_attr "length" "4")
14806 + (set_attr "cc" "clobber")])
14807 +
14808 +(define_insn "tablejump_insn"
14809 + [(set (pc) (match_operand:SI 0 "memory_operand" "m"))
14810 + (use (label_ref (match_operand 1 "" "")))]
14811 + "!flag_pic"
14812 + "ld.w\tpc, %0"
14813 + [(set_attr "length" "4")
14814 + (set_attr "type" "call")
14815 + (set_attr "cc" "none")])
14816 +
14817 +(define_expand "casesi"
14818 + [(match_operand:SI 0 "register_operand" "") ; index to jump on
14819 + (match_operand:SI 1 "const_int_operand" "") ; lower bound
14820 + (match_operand:SI 2 "const_int_operand" "") ; total range
14821 + (match_operand:SI 3 "" "") ; table label
14822 + (match_operand:SI 4 "" "")] ; Out of range label
14823 + ""
14824 + "
14825 + {
14826 + rtx reg;
14827 + rtx index = operands[0];
14828 + rtx low_bound = operands[1];
14829 + rtx range = operands[2];
14830 + rtx table_label = operands[3];
14831 + rtx oor_label = operands[4];
14832 +
14833 + index = force_reg ( SImode, index );
14834 + if (low_bound != const0_rtx)
14835 + {
14836 + if (!avr32_const_ok_for_constraint_p(INTVAL (low_bound), 'I', \"Is21\")){
14837 + reg = force_reg(SImode, GEN_INT (INTVAL (low_bound)));
14838 + emit_insn (gen_subsi3 (reg, index,
14839 + reg));
14840 + } else {
14841 + reg = gen_reg_rtx (SImode);
14842 + emit_insn (gen_addsi3 (reg, index,
14843 + GEN_INT (-INTVAL (low_bound))));
14844 + }
14845 + index = reg;
14846 + }
14847 +
14848 + if (!avr32_const_ok_for_constraint_p (INTVAL (range), 'K', \"Ks21\"))
14849 + range = force_reg (SImode, range);
14850 +
14851 + emit_cmp_and_jump_insns ( index, range, GTU, NULL_RTX, SImode, 1, oor_label );
14852 + reg = gen_reg_rtx (SImode);
14853 + emit_move_insn ( reg, gen_rtx_LABEL_REF (VOIDmode, table_label));
14854 +
14855 + if ( flag_pic )
14856 + emit_jump_insn ( gen_tablejump_add ( reg, index, GEN_INT(4), table_label));
14857 + else
14858 + emit_jump_insn (
14859 + gen_tablejump_insn ( gen_rtx_MEM ( SImode,
14860 + gen_rtx_PLUS ( SImode,
14861 + reg,
14862 + gen_rtx_MULT ( SImode,
14863 + index,
14864 + GEN_INT(4)))),
14865 + table_label));
14866 + DONE;
14867 + }"
14868 +)
14869 +
14870 +
14871 +
14872 +(define_insn "prefetch"
14873 + [(prefetch (match_operand:SI 0 "avr32_ks16_address_operand" "p")
14874 + (match_operand 1 "const_int_operand" "")
14875 + (match_operand 2 "const_int_operand" ""))]
14876 + ""
14877 + {
14878 + return "pref\t%0";
14879 + }
14880 +
14881 + [(set_attr "length" "4")
14882 + (set_attr "type" "load")
14883 + (set_attr "cc" "none")])
14884 +
14885 +
14886 +
14887 +;;=============================================================================
14888 +;; prologue
14889 +;;-----------------------------------------------------------------------------
14890 +;; This pattern, if defined, emits RTL for entry to a function. The function
14891 +;; entry i responsible for setting up the stack frame, initializing the frame
14892 +;; pointer register, saving callee saved registers, etc.
14893 +;;=============================================================================
14894 +(define_expand "prologue"
14895 + [(clobber (const_int 0))]
14896 + ""
14897 + "
14898 + avr32_expand_prologue();
14899 + DONE;
14900 + "
14901 + )
14902 +
14903 +;;=============================================================================
14904 +;; eh_return
14905 +;;-----------------------------------------------------------------------------
14906 +;; This pattern, if defined, affects the way __builtin_eh_return, and
14907 +;; thence the call frame exception handling library routines, are
14908 +;; built. It is intended to handle non-trivial actions needed along
14909 +;; the abnormal return path.
14910 +;;
14911 +;; The address of the exception handler to which the function should
14912 +;; return is passed as operand to this pattern. It will normally need
14913 +;; to copied by the pattern to some special register or memory
14914 +;; location. If the pattern needs to determine the location of the
14915 +;; target call frame in order to do so, it may use
14916 +;; EH_RETURN_STACKADJ_RTX, if defined; it will have already been
14917 +;; assigned.
14918 +;;
14919 +;; If this pattern is not defined, the default action will be to
14920 +;; simply copy the return address to EH_RETURN_HANDLER_RTX. Either
14921 +;; that macro or this pattern needs to be defined if call frame
14922 +;; exception handling is to be used.
14923 +
14924 +;; We can't expand this before we know where the link register is stored.
14925 +(define_insn_and_split "eh_return"
14926 + [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
14927 + VUNSPEC_EH_RETURN)
14928 + (clobber (match_scratch:SI 1 "=&r"))]
14929 + ""
14930 + "#"
14931 + "reload_completed"
14932 + [(const_int 0)]
14933 + "
14934 + {
14935 + avr32_set_return_address (operands[0], operands[1]);
14936 + DONE;
14937 + }"
14938 + )
14939 +
14940 +
14941 +;;=============================================================================
14942 +;; ffssi2
14943 +;;-----------------------------------------------------------------------------
14944 +(define_insn "ffssi2"
14945 + [ (set (match_operand:SI 0 "register_operand" "=r")
14946 + (ffs:SI (match_operand:SI 1 "register_operand" "r"))) ]
14947 + ""
14948 + "mov %0, %1
14949 + brev %0
14950 + clz %0, %0
14951 + sub %0, -1
14952 + cp %0, 33
14953 + moveq %0, 0"
14954 + [(set_attr "length" "18")
14955 + (set_attr "cc" "clobber")]
14956 + )
14957 +
14958 +
14959 +
14960 +;;=============================================================================
14961 +;; swap_h
14962 +;;-----------------------------------------------------------------------------
14963 +(define_insn "*swap_h"
14964 + [ (set (match_operand:SI 0 "register_operand" "=r")
14965 + (ior:SI (ashift:SI (match_dup 0) (const_int 16))
14966 + (lshiftrt:SI (match_dup 0) (const_int 16))))]
14967 + ""
14968 + "swap.h %0"
14969 + [(set_attr "length" "2")]
14970 + )
14971 +
14972 +(define_insn_and_split "bswap_16"
14973 + [ (set (match_operand:HI 0 "avr32_bswap_operand" "=r,RKs13,r")
14974 + (ior:HI (and:HI (lshiftrt:HI (match_operand:HI 1 "avr32_bswap_operand" "r,r,RKs13")
14975 + (const_int 8))
14976 + (const_int 255))
14977 + (ashift:HI (and:HI (match_dup 1)
14978 + (const_int 255))
14979 + (const_int 8))))]
14980 + ""
14981 + {
14982 + switch ( which_alternative ){
14983 + case 0:
14984 + if ( REGNO(operands[0]) == REGNO(operands[1]))
14985 + return "swap.bh\t%0";
14986 + else
14987 + return "mov\t%0, %1\;swap.bh\t%0";
14988 + case 1:
14989 + return "stswp.h\t%0, %1";
14990 + case 2:
14991 + return "ldswp.sh\t%0, %1";
14992 + default:
14993 + abort();
14994 + }
14995 + }
14996 +
14997 + "(reload_completed &&
14998 + REG_P(operands[0]) && REG_P(operands[1])
14999 + && (REGNO(operands[0]) != REGNO(operands[1])))"
15000 + [(set (match_dup 0) (match_dup 1))
15001 + (set (match_dup 0)
15002 + (ior:HI (and:HI (lshiftrt:HI (match_dup 0)
15003 + (const_int 8))
15004 + (const_int 255))
15005 + (ashift:HI (and:HI (match_dup 0)
15006 + (const_int 255))
15007 + (const_int 8))))]
15008 + ""
15009 +
15010 + [(set_attr "length" "4,4,4")
15011 + (set_attr "type" "alu,store,load_rm")]
15012 + )
15013 +
15014 +(define_insn_and_split "bswap_32"
15015 + [ (set (match_operand:SI 0 "avr32_bswap_operand" "=r,RKs14,r")
15016 + (ior:SI (ior:SI (lshiftrt:SI (and:SI (match_operand:SI 1 "avr32_bswap_operand" "r,r,RKs14")
15017 + (const_int -16777216))
15018 + (const_int 24))
15019 + (lshiftrt:SI (and:SI (match_dup 1)
15020 + (const_int 16711680))
15021 + (const_int 8)))
15022 + (ior:SI (ashift:SI (and:SI (match_dup 1)
15023 + (const_int 65280))
15024 + (const_int 8))
15025 + (ashift:SI (and:SI (match_dup 1)
15026 + (const_int 255))
15027 + (const_int 24)))))]
15028 + ""
15029 + {
15030 + switch ( which_alternative ){
15031 + case 0:
15032 + if ( REGNO(operands[0]) == REGNO(operands[1]))
15033 + return "swap.b\t%0";
15034 + else
15035 + return "#";
15036 + case 1:
15037 + return "stswp.w\t%0, %1";
15038 + case 2:
15039 + return "ldswp.w\t%0, %1";
15040 + default:
15041 + abort();
15042 + }
15043 + }
15044 + "(reload_completed &&
15045 + REG_P(operands[0]) && REG_P(operands[1])
15046 + && (REGNO(operands[0]) != REGNO(operands[1])))"
15047 + [(set (match_dup 0) (match_dup 1))
15048 + (set (match_dup 0)
15049 + (ior:SI (ior:SI (lshiftrt:SI (and:SI (match_dup 0)
15050 + (const_int -16777216))
15051 + (const_int 24))
15052 + (lshiftrt:SI (and:SI (match_dup 0)
15053 + (const_int 16711680))
15054 + (const_int 8)))
15055 + (ior:SI (ashift:SI (and:SI (match_dup 0)
15056 + (const_int 65280))
15057 + (const_int 8))
15058 + (ashift:SI (and:SI (match_dup 0)
15059 + (const_int 255))
15060 + (const_int 24)))))]
15061 + ""
15062 +
15063 + [(set_attr "length" "4,4,4")
15064 + (set_attr "type" "alu,store,load_rm")]
15065 + )
15066 +
15067 +
15068 +;;=============================================================================
15069 +;; blockage
15070 +;;-----------------------------------------------------------------------------
15071 +;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
15072 +;; all of memory. This blocks insns from being moved across this point.
15073 +
15074 +(define_insn "blockage"
15075 + [(unspec_volatile [(const_int 0)] VUNSPEC_BLOCKAGE)]
15076 + ""
15077 + ""
15078 + [(set_attr "length" "0")]
15079 +)
15080 +
15081 +;;=============================================================================
15082 +;; clzsi2
15083 +;;-----------------------------------------------------------------------------
15084 +(define_insn "clzsi2"
15085 + [ (set (match_operand:SI 0 "register_operand" "=r")
15086 + (clz:SI (match_operand:SI 1 "register_operand" "r"))) ]
15087 + ""
15088 + "clz %0, %1"
15089 + [(set_attr "length" "4")
15090 + (set_attr "cc" "set_z")]
15091 + )
15092 +
15093 +;;=============================================================================
15094 +;; ctzsi2
15095 +;;-----------------------------------------------------------------------------
15096 +(define_insn "ctzsi2"
15097 + [ (set (match_operand:SI 0 "register_operand" "=r,r")
15098 + (ctz:SI (match_operand:SI 1 "register_operand" "0,r"))) ]
15099 + ""
15100 + "@
15101 + brev\t%0\;clz\t%0, %0
15102 + mov\t%0, %1\;brev\t%0\;clz\t%0, %0"
15103 + [(set_attr "length" "8")
15104 + (set_attr "cc" "set_z")]
15105 + )
15106 +
15107 +;;=============================================================================
15108 +;; cache instructions
15109 +;;-----------------------------------------------------------------------------
15110 +(define_insn "cache"
15111 + [ (unspec_volatile [(match_operand:SI 0 "avr32_ks11_address_operand" "p")
15112 + (match_operand:SI 1 "immediate_operand" "Ku05")] VUNSPEC_CACHE)]
15113 + ""
15114 + "cache %0, %1"
15115 + [(set_attr "length" "4")]
15116 + )
15117 +
15118 +(define_insn "sync"
15119 + [ (unspec_volatile [(match_operand:SI 0 "immediate_operand" "Ku08")] VUNSPEC_SYNC)]
15120 + ""
15121 + "sync %0"
15122 + [(set_attr "length" "4")]
15123 + )
15124 +
15125 +;;=============================================================================
15126 +;; TLB instructions
15127 +;;-----------------------------------------------------------------------------
15128 +(define_insn "tlbr"
15129 + [ (unspec_volatile [(const_int 0)] VUNSPEC_TLBR)]
15130 + ""
15131 + "tlbr"
15132 + [(set_attr "length" "2")]
15133 + )
15134 +
15135 +(define_insn "tlbw"
15136 + [ (unspec_volatile [(const_int 0)] VUNSPEC_TLBW)]
15137 + ""
15138 + "tlbw"
15139 + [(set_attr "length" "2")]
15140 + )
15141 +
15142 +(define_insn "tlbs"
15143 + [ (unspec_volatile [(const_int 0)] VUNSPEC_TLBS)]
15144 + ""
15145 + "tlbs"
15146 + [(set_attr "length" "2")]
15147 + )
15148 +
15149 +;;=============================================================================
15150 +;; Breakpoint instruction
15151 +;;-----------------------------------------------------------------------------
15152 +(define_insn "breakpoint"
15153 + [ (unspec_volatile [(const_int 0)] VUNSPEC_BREAKPOINT)]
15154 + ""
15155 + "breakpoint"
15156 + [(set_attr "length" "2")]
15157 + )
15158 +
15159 +
15160 +;;=============================================================================
15161 +;; mtsr/mfsr instruction
15162 +;;-----------------------------------------------------------------------------
15163 +(define_insn "mtsr"
15164 + [ (unspec_volatile [(match_operand 0 "immediate_operand" "i")
15165 + (match_operand:SI 1 "register_operand" "r")] VUNSPEC_MTSR)]
15166 + ""
15167 + "mtsr\t%0, %1"
15168 + [(set_attr "length" "4")]
15169 + )
15170 +
15171 +(define_insn "mfsr"
15172 + [ (set (match_operand:SI 0 "register_operand" "=r")
15173 + (unspec_volatile:SI [(match_operand 1 "immediate_operand" "i")] VUNSPEC_MFSR)) ]
15174 + ""
15175 + "mfsr\t%0, %1"
15176 + [(set_attr "length" "4")]
15177 + )
15178 +
15179 +;;=============================================================================
15180 +;; mtdr/mfdr instruction
15181 +;;-----------------------------------------------------------------------------
15182 +(define_insn "mtdr"
15183 + [ (unspec_volatile [(match_operand 0 "immediate_operand" "i")
15184 + (match_operand:SI 1 "register_operand" "r")] VUNSPEC_MTDR)]
15185 + ""
15186 + "mtdr\t%0, %1"
15187 + [(set_attr "length" "4")]
15188 + )
15189 +
15190 +(define_insn "mfdr"
15191 + [ (set (match_operand:SI 0 "register_operand" "=r")
15192 + (unspec_volatile:SI [(match_operand 1 "immediate_operand" "i")] VUNSPEC_MFDR)) ]
15193 + ""
15194 + "mfdr\t%0, %1"
15195 + [(set_attr "length" "4")]
15196 + )
15197 +
15198 +;;=============================================================================
15199 +;; musfr
15200 +;;-----------------------------------------------------------------------------
15201 +(define_insn "musfr"
15202 + [ (unspec_volatile [(match_operand:SI 0 "register_operand" "r")] VUNSPEC_MUSFR)]
15203 + ""
15204 + "musfr\t%0"
15205 + [(set_attr "length" "2")
15206 + (set_attr "cc" "clobber")]
15207 + )
15208 +
15209 +(define_insn "mustr"
15210 + [ (set (match_operand:SI 0 "register_operand" "=r")
15211 + (unspec_volatile:SI [(const_int 0)] VUNSPEC_MUSTR)) ]
15212 + ""
15213 + "mustr\t%0"
15214 + [(set_attr "length" "2")]
15215 + )
15216 +
15217 +(define_insn "ssrf"
15218 + [ (unspec_volatile [(match_operand:SI 0 "immediate_operand" "Ku05")] VUNSPEC_SSRF)]
15219 + ""
15220 + "ssrf %0"
15221 + [(set_attr "length" "2")
15222 + (set_attr "cc" "clobber")]
15223 + )
15224 +
15225 +(define_insn "csrf"
15226 + [ (unspec_volatile [(match_operand:SI 0 "immediate_operand" "Ku05")] VUNSPEC_CSRF)]
15227 + ""
15228 + "csrf %0"
15229 + [(set_attr "length" "2")
15230 + (set_attr "cc" "clobber")]
15231 + )
15232 +
15233 +;;=============================================================================
15234 +;; Flush Return Stack instruction
15235 +;;-----------------------------------------------------------------------------
15236 +(define_insn "frs"
15237 + [ (unspec_volatile [(const_int 0)] VUNSPEC_FRS)]
15238 + ""
15239 + "frs"
15240 + [(set_attr "length" "2")
15241 + (set_attr "cc" "none")]
15242 + )
15243 +
15244 +
15245 +;;=============================================================================
15246 +;; Saturation Round Scale instruction
15247 +;;-----------------------------------------------------------------------------
15248 +(define_insn "sats"
15249 + [ (set (match_operand:SI 0 "register_operand" "+r")
15250 + (unspec:SI [(match_dup 0)
15251 + (match_operand 1 "immediate_operand" "Ku05")
15252 + (match_operand 2 "immediate_operand" "Ku05")]
15253 + UNSPEC_SATS)) ]
15254 + "TARGET_DSP"
15255 + "sats\t%0 >> %1, %2"
15256 + [(set_attr "type" "alu_sat")
15257 + (set_attr "length" "4")]
15258 + )
15259 +
15260 +(define_insn "satu"
15261 + [ (set (match_operand:SI 0 "register_operand" "+r")
15262 + (unspec:SI [(match_dup 0)
15263 + (match_operand 1 "immediate_operand" "Ku05")
15264 + (match_operand 2 "immediate_operand" "Ku05")]
15265 + UNSPEC_SATU)) ]
15266 + "TARGET_DSP"
15267 + "satu\t%0 >> %1, %2"
15268 + [(set_attr "type" "alu_sat")
15269 + (set_attr "length" "4")]
15270 + )
15271 +
15272 +(define_insn "satrnds"
15273 + [ (set (match_operand:SI 0 "register_operand" "+r")
15274 + (unspec:SI [(match_dup 0)
15275 + (match_operand 1 "immediate_operand" "Ku05")
15276 + (match_operand 2 "immediate_operand" "Ku05")]
15277 + UNSPEC_SATRNDS)) ]
15278 + "TARGET_DSP"
15279 + "satrnds\t%0 >> %1, %2"
15280 + [(set_attr "type" "alu_sat")
15281 + (set_attr "length" "4")]
15282 + )
15283 +
15284 +(define_insn "satrndu"
15285 + [ (set (match_operand:SI 0 "register_operand" "+r")
15286 + (unspec:SI [(match_dup 0)
15287 + (match_operand 1 "immediate_operand" "Ku05")
15288 + (match_operand 2 "immediate_operand" "Ku05")]
15289 + UNSPEC_SATRNDU)) ]
15290 + "TARGET_DSP"
15291 + "sats\t%0 >> %1, %2"
15292 + [(set_attr "type" "alu_sat")
15293 + (set_attr "length" "4")]
15294 + )
15295 +
15296 +(define_insn "sleep"
15297 + [(unspec_volatile [(const_int 0)] VUNSPEC_SLEEP)
15298 + (match_operand:SI 0 "const_int_operand" "")]
15299 + ""
15300 + "sleep %0"
15301 + [(set_attr "length" "1")
15302 + (set_attr "cc" "none")
15303 + ])
15304 +
15305 +(define_expand "delay_cycles"
15306 + [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "i")]
15307 + VUNSPEC_DELAY_CYCLES)]
15308 + ""
15309 + "
15310 + unsigned int cycles = UINTVAL (operands[0]);
15311 + if (IN_RANGE(cycles,0x10000 ,0xFFFFFFFF))
15312 + {
15313 + unsigned int msb = (cycles & 0xFFFF0000);
15314 + unsigned int shift = 16;
15315 + msb = (msb >> shift);
15316 + unsigned int cycles_used = (msb*0x10000);
15317 + emit_insn (gen_delay_cycles_2 (gen_int_mode (msb, SImode)));
15318 + cycles -= cycles_used;
15319 + }
15320 + if (IN_RANGE(cycles, 4, 0xFFFF))
15321 + {
15322 + unsigned int loop_count = (cycles/ 4);
15323 + unsigned int cycles_used = (loop_count*4);
15324 + emit_insn (gen_delay_cycles_1 (gen_int_mode (loop_count, SImode)));
15325 + cycles -= cycles_used;
15326 + }
15327 + while (cycles >= 3)
15328 + {
15329 + emit_insn (gen_nop3 ());
15330 + cycles -= 3;
15331 + }
15332 + if (cycles == 1 || cycles == 2)
15333 + {
15334 + while (cycles--)
15335 + emit_insn (gen_nop ());
15336 + }
15337 + DONE;
15338 + ")
15339 +
15340 +(define_insn "delay_cycles_1"
15341 +[(unspec_volatile [(const_int 0)] VUNSPEC_DELAY_CYCLES_1)
15342 + (match_operand:SI 0 "immediate_operand" "")
15343 + (clobber (match_scratch:SI 1 "=&r"))]
15344 + ""
15345 + "mov\t%1, %0
15346 + 1: sub\t%1, 1
15347 + brne\t1b
15348 + nop"
15349 +)
15350 +
15351 +(define_insn "delay_cycles_2"
15352 +[(unspec_volatile [(const_int 0)] VUNSPEC_DELAY_CYCLES_2)
15353 + (match_operand:SI 0 "immediate_operand" "")
15354 + (clobber (match_scratch:SI 1 "=&r"))
15355 + (clobber (match_scratch:SI 2 "=&r"))]
15356 + ""
15357 + "mov\t%1, %0
15358 + 1: mov\t%2, 16383
15359 + 2: sub\t%2, 1
15360 + brne\t2b
15361 + nop
15362 + sub\t%1, 1
15363 + brne\t1b
15364 + nop"
15365 +)
15366 +
15367 +;; CPU instructions
15368 +
15369 +;;=============================================================================
15370 +;; nop
15371 +;;-----------------------------------------------------------------------------
15372 +;; No-op instruction.
15373 +;;=============================================================================
15374 +(define_insn "nop"
15375 + [(unspec_volatile [(const_int 0)] VUNSPEC_NOP)]
15376 + ""
15377 + "nop"
15378 + [(set_attr "length" "1")
15379 + (set_attr "type" "alu")
15380 + (set_attr "cc" "none")])
15381 +
15382 +;; NOP3
15383 +(define_insn "nop3"
15384 + [(unspec_volatile [(const_int 0)] VUNSPEC_NOP3)]
15385 + ""
15386 + "rjmp\t2"
15387 + [(set_attr "length" "3")
15388 + (set_attr "type" "alu")
15389 + (set_attr "cc" "none")])
15390 +
15391 +;; Special patterns for dealing with the constant pool
15392 +
15393 +(define_insn "align_4"
15394 + [(unspec_volatile [(const_int 0)] VUNSPEC_ALIGN)]
15395 + ""
15396 + {
15397 + assemble_align (32);
15398 + return "";
15399 + }
15400 + [(set_attr "length" "2")]
15401 +)
15402 +
15403 +
15404 +(define_insn "consttable_start"
15405 + [(unspec_volatile [(const_int 0)] VUNSPEC_POOL_START)]
15406 + ""
15407 + {
15408 + return ".cpool";
15409 + }
15410 + [(set_attr "length" "0")]
15411 + )
15412 +
15413 +(define_insn "consttable_end"
15414 + [(unspec_volatile [(const_int 0)] VUNSPEC_POOL_END)]
15415 + ""
15416 + {
15417 + making_const_table = FALSE;
15418 + return "";
15419 + }
15420 + [(set_attr "length" "0")]
15421 +)
15422 +
15423 +
15424 +(define_insn "consttable_4"
15425 + [(unspec_volatile [(match_operand 0 "" "")] VUNSPEC_POOL_4)]
15426 + ""
15427 + {
15428 + making_const_table = TRUE;
15429 + switch (GET_MODE_CLASS (GET_MODE (operands[0])))
15430 + {
15431 + case MODE_FLOAT:
15432 + {
15433 + REAL_VALUE_TYPE r;
15434 + char real_string[1024];
15435 + REAL_VALUE_FROM_CONST_DOUBLE (r, operands[0]);
15436 + real_to_decimal(real_string, &r, 1024, 0, 1);
15437 + asm_fprintf (asm_out_file, "\t.float\t%s\n", real_string);
15438 + break;
15439 + }
15440 + default:
15441 + assemble_integer (operands[0], 4, 0, 1);
15442 + break;
15443 + }
15444 + return "";
15445 + }
15446 + [(set_attr "length" "4")]
15447 +)
15448 +
15449 +(define_insn "consttable_8"
15450 + [(unspec_volatile [(match_operand 0 "" "")] VUNSPEC_POOL_8)]
15451 + ""
15452 + {
15453 + making_const_table = TRUE;
15454 + switch (GET_MODE_CLASS (GET_MODE (operands[0])))
15455 + {
15456 + case MODE_FLOAT:
15457 + {
15458 + REAL_VALUE_TYPE r;
15459 + char real_string[1024];
15460 + REAL_VALUE_FROM_CONST_DOUBLE (r, operands[0]);
15461 + real_to_decimal(real_string, &r, 1024, 0, 1);
15462 + asm_fprintf (asm_out_file, "\t.double\t%s\n", real_string);
15463 + break;
15464 + }
15465 + default:
15466 + assemble_integer(operands[0], 8, 0, 1);
15467 + break;
15468 + }
15469 + return "";
15470 + }
15471 + [(set_attr "length" "8")]
15472 +)
15473 +
15474 +(define_insn "consttable_16"
15475 + [(unspec_volatile [(match_operand 0 "" "")] VUNSPEC_POOL_16)]
15476 + ""
15477 + {
15478 + making_const_table = TRUE;
15479 + assemble_integer(operands[0], 16, 0, 1);
15480 + return "";
15481 + }
15482 + [(set_attr "length" "16")]
15483 +)
15484 +
15485 +;;=============================================================================
15486 +;; coprocessor instructions
15487 +;;-----------------------------------------------------------------------------
15488 +(define_insn "cop"
15489 + [ (unspec_volatile [(match_operand 0 "immediate_operand" "Ku03")
15490 + (match_operand 1 "immediate_operand" "Ku04")
15491 + (match_operand 2 "immediate_operand" "Ku04")
15492 + (match_operand 3 "immediate_operand" "Ku04")
15493 + (match_operand 4 "immediate_operand" "Ku07")] VUNSPEC_COP)]
15494 + ""
15495 + "cop\tcp%0, cr%1, cr%2, cr%3, %4"
15496 + [(set_attr "length" "4")]
15497 + )
15498 +
15499 +(define_insn "mvcrsi"
15500 + [ (set (match_operand:SI 0 "avr32_cop_move_operand" "=r,<,Z")
15501 + (unspec_volatile:SI [(match_operand 1 "immediate_operand" "Ku03,Ku03,Ku03")
15502 + (match_operand 2 "immediate_operand" "Ku04,Ku04,Ku04")]
15503 + VUNSPEC_MVCR)) ]
15504 + ""
15505 + "@
15506 + mvcr.w\tcp%1, %0, cr%2
15507 + stcm.w\tcp%1, %0, cr%2
15508 + stc.w\tcp%1, %0, cr%2"
15509 + [(set_attr "length" "4")]
15510 + )
15511 +
15512 +(define_insn "mvcrdi"
15513 + [ (set (match_operand:DI 0 "avr32_cop_move_operand" "=r,<,Z")
15514 + (unspec_volatile:DI [(match_operand 1 "immediate_operand" "Ku03,Ku03,Ku03")
15515 + (match_operand 2 "immediate_operand" "Ku04,Ku04,Ku04")]
15516 + VUNSPEC_MVCR)) ]
15517 + ""
15518 + "@
15519 + mvcr.d\tcp%1, %0, cr%2
15520 + stcm.d\tcp%1, %0, cr%2-cr%i2
15521 + stc.d\tcp%1, %0, cr%2"
15522 + [(set_attr "length" "4")]
15523 + )
15524 +
15525 +(define_insn "mvrcsi"
15526 + [ (unspec_volatile:SI [(match_operand 0 "immediate_operand" "Ku03,Ku03,Ku03")
15527 + (match_operand 1 "immediate_operand" "Ku04,Ku04,Ku04")
15528 + (match_operand:SI 2 "avr32_cop_move_operand" "r,>,Z")]
15529 + VUNSPEC_MVRC)]
15530 + ""
15531 + {
15532 + switch (which_alternative){
15533 + case 0:
15534 + return "mvrc.w\tcp%0, cr%1, %2";
15535 + case 1:
15536 + return "ldcm.w\tcp%0, %2, cr%1";
15537 + case 2:
15538 + return "ldc.w\tcp%0, cr%1, %2";
15539 + default:
15540 + abort();
15541 + }
15542 + }
15543 + [(set_attr "length" "4")]
15544 + )
15545 +
15546 +(define_insn "mvrcdi"
15547 + [ (unspec_volatile:DI [(match_operand 0 "immediate_operand" "Ku03,Ku03,Ku03")
15548 + (match_operand 1 "immediate_operand" "Ku04,Ku04,Ku04")
15549 + (match_operand:DI 2 "avr32_cop_move_operand" "r,>,Z")]
15550 + VUNSPEC_MVRC)]
15551 + ""
15552 + {
15553 + switch (which_alternative){
15554 + case 0:
15555 + return "mvrc.d\tcp%0, cr%1, %2";
15556 + case 1:
15557 + return "ldcm.d\tcp%0, %2, cr%1-cr%i1";
15558 + case 2:
15559 + return "ldc.d\tcp%0, cr%1, %2";
15560 + default:
15561 + abort();
15562 + }
15563 + }
15564 + [(set_attr "length" "4")]
15565 + )
15566 +
15567 +;;=============================================================================
15568 +;; epilogue
15569 +;;-----------------------------------------------------------------------------
15570 +;; This pattern emits RTL for exit from a function. The function exit is
15571 +;; responsible for deallocating the stack frame, restoring callee saved
15572 +;; registers and emitting the return instruction.
15573 +;; ToDo: using TARGET_ASM_FUNCTION_PROLOGUE instead.
15574 +;;=============================================================================
15575 +(define_expand "epilogue"
15576 + [(unspec_volatile [(return)] VUNSPEC_EPILOGUE)]
15577 + ""
15578 + "
15579 + if (USE_RETURN_INSN (FALSE)){
15580 + emit_jump_insn (gen_return ());
15581 + DONE;
15582 + }
15583 + emit_jump_insn (gen_rtx_UNSPEC_VOLATILE (VOIDmode,
15584 + gen_rtvec (1,
15585 + gen_rtx_RETURN (VOIDmode)),
15586 + VUNSPEC_EPILOGUE));
15587 + DONE;
15588 + "
15589 + )
15590 +
15591 +(define_insn "*epilogue_insns"
15592 + [(unspec_volatile [(return)] VUNSPEC_EPILOGUE)]
15593 + ""
15594 + {
15595 + avr32_output_return_instruction (FALSE, FALSE, NULL, NULL);
15596 + return "";
15597 + }
15598 + ; Length is absolute worst case
15599 + [(set_attr "type" "branch")
15600 + (set_attr "length" "12")]
15601 + )
15602 +
15603 +(define_insn "*epilogue_insns_ret_imm"
15604 + [(parallel [(set (reg RETVAL_REGNUM) (match_operand 0 "immediate_operand" "i"))
15605 + (use (reg RETVAL_REGNUM))
15606 + (unspec_volatile [(return)] VUNSPEC_EPILOGUE)])]
15607 + "((INTVAL(operands[0]) == -1) || (INTVAL(operands[0]) == 0) || (INTVAL(operands[0]) == 1))"
15608 + {
15609 + avr32_output_return_instruction (FALSE, FALSE, NULL, operands[0]);
15610 + return "";
15611 + }
15612 + ; Length is absolute worst case
15613 + [(set_attr "type" "branch")
15614 + (set_attr "length" "12")]
15615 + )
15616 +
15617 +(define_insn "sibcall_epilogue"
15618 + [(unspec_volatile [(const_int 0)] VUNSPEC_EPILOGUE)]
15619 + ""
15620 + {
15621 + avr32_output_return_instruction (FALSE, FALSE, NULL, NULL);
15622 + return "";
15623 + }
15624 +;; Length is absolute worst case
15625 + [(set_attr "type" "branch")
15626 + (set_attr "length" "12")]
15627 + )
15628 +
15629 +(define_insn "*sibcall_epilogue_insns_ret_imm"
15630 + [(parallel [(set (reg RETVAL_REGNUM) (match_operand 0 "immediate_operand" "i"))
15631 + (use (reg RETVAL_REGNUM))
15632 + (unspec_volatile [(const_int 0)] VUNSPEC_EPILOGUE)])]
15633 + "((INTVAL(operands[0]) == -1) || (INTVAL(operands[0]) == 0) || (INTVAL(operands[0]) == 1))"
15634 + {
15635 + avr32_output_return_instruction (FALSE, FALSE, NULL, operands[0]);
15636 + return "";
15637 + }
15638 + ; Length is absolute worst case
15639 + [(set_attr "type" "branch")
15640 + (set_attr "length" "12")]
15641 + )
15642 +
15643 +(define_insn "ldxi"
15644 + [(set (match_operand:SI 0 "register_operand" "=r")
15645 + (mem:SI (plus:SI
15646 + (match_operand:SI 1 "register_operand" "r")
15647 + (mult:SI (zero_extract:SI (match_operand:SI 2 "register_operand" "r")
15648 + (const_int 8)
15649 + (match_operand:SI 3 "immediate_operand" "Ku05"))
15650 + (const_int 4)))))]
15651 + "(INTVAL(operands[3]) == 24 || INTVAL(operands[3]) == 16 || INTVAL(operands[3]) == 8
15652 + || INTVAL(operands[3]) == 0)"
15653 + {
15654 + switch ( INTVAL(operands[3]) ){
15655 + case 0:
15656 + return "ld.w %0, %1[%2:b << 2]";
15657 + case 8:
15658 + return "ld.w %0, %1[%2:l << 2]";
15659 + case 16:
15660 + return "ld.w %0, %1[%2:u << 2]";
15661 + case 24:
15662 + return "ld.w %0, %1[%2:t << 2]";
15663 + default:
15664 + internal_error("illegal operand for ldxi");
15665 + }
15666 + }
15667 + [(set_attr "type" "load")
15668 + (set_attr "length" "4")
15669 + (set_attr "cc" "none")])
15670 +
15671 +
15672 +
15673 +
15674 +
15675 +
15676 +;;=============================================================================
15677 +;; Peephole optimizing
15678 +;;-----------------------------------------------------------------------------
15679 +;; Changing
15680 +;; sub r8, r7, 8
15681 +;; st.w r8[0x0], r12
15682 +;; to
15683 +;; sub r8, r7, 8
15684 +;; st.w r7[-0x8], r12
15685 +;;=============================================================================
15686 +; (set (reg:SI 9 r8)
15687 +; (plus:SI (reg/f:SI 6 r7)
15688 +; (const_int ...)))
15689 +; (set (mem:SI (reg:SI 9 r8))
15690 +; (reg:SI 12 r12))
15691 +(define_peephole2
15692 + [(set (match_operand:SI 0 "register_operand" "")
15693 + (plus:SI (match_operand:SI 1 "register_operand" "")
15694 + (match_operand:SI 2 "immediate_operand" "")))
15695 + (set (mem:SI (match_dup 0))
15696 + (match_operand:SI 3 "register_operand" ""))]
15697 + "REGNO(operands[0]) != REGNO(operands[1]) && avr32_const_ok_for_constraint_p(INTVAL(operands[2]), 'K', \"Ks16\")"
15698 + [(set (match_dup 0)
15699 + (plus:SI (match_dup 1)
15700 + (match_dup 2)))
15701 + (set (mem:SI (plus:SI (match_dup 1)
15702 + (match_dup 2)))
15703 + (match_dup 3))]
15704 + "")
15705 +
15706 +;;=============================================================================
15707 +;; Peephole optimizing
15708 +;;-----------------------------------------------------------------------------
15709 +;; Changing
15710 +;; sub r6, r7, 4
15711 +;; ld.w r6, r6[0x0]
15712 +;; to
15713 +;; sub r6, r7, 4
15714 +;; ld.w r6, r7[-0x4]
15715 +;;=============================================================================
15716 +; (set (reg:SI 7 r6)
15717 +; (plus:SI (reg/f:SI 6 r7)
15718 +; (const_int -4 [0xfffffffc])))
15719 +; (set (reg:SI 7 r6)
15720 +; (mem:SI (reg:SI 7 r6)))
15721 +(define_peephole2
15722 + [(set (match_operand:SI 0 "register_operand" "")
15723 + (plus:SI (match_operand:SI 1 "register_operand" "")
15724 + (match_operand:SI 2 "immediate_operand" "")))
15725 + (set (match_operand:SI 3 "register_operand" "")
15726 + (mem:SI (match_dup 0)))]
15727 + "REGNO(operands[0]) != REGNO(operands[1]) && avr32_const_ok_for_constraint_p(INTVAL(operands[2]), 'K', \"Ks16\")"
15728 + [(set (match_dup 0)
15729 + (plus:SI (match_dup 1)
15730 + (match_dup 2)))
15731 + (set (match_dup 3)
15732 + (mem:SI (plus:SI (match_dup 1)
15733 + (match_dup 2))))]
15734 + "")
15735 +
15736 +;;=============================================================================
15737 +;; Peephole optimizing
15738 +;;-----------------------------------------------------------------------------
15739 +;; Changing
15740 +;; ld.sb r0, r7[-0x6]
15741 +;; cashs.b r0
15742 +;; to
15743 +;; ld.sb r0, r7[-0x6]
15744 +;;=============================================================================
15745 +(define_peephole2
15746 + [(set (match_operand:QI 0 "register_operand" "")
15747 + (match_operand:QI 1 "load_sb_memory_operand" ""))
15748 + (set (match_operand:SI 2 "register_operand" "")
15749 + (sign_extend:SI (match_dup 0)))]
15750 + "(REGNO(operands[0]) == REGNO(operands[2]) || peep2_reg_dead_p(2, operands[0]))"
15751 + [(set (match_dup 2)
15752 + (sign_extend:SI (match_dup 1)))]
15753 + "")
15754 +
15755 +;;=============================================================================
15756 +;; Peephole optimizing
15757 +;;-----------------------------------------------------------------------------
15758 +;; Changing
15759 +;; ld.ub r0, r7[-0x6]
15760 +;; cashu.b r0
15761 +;; to
15762 +;; ld.ub r0, r7[-0x6]
15763 +;;=============================================================================
15764 +(define_peephole2
15765 + [(set (match_operand:QI 0 "register_operand" "")
15766 + (match_operand:QI 1 "memory_operand" ""))
15767 + (set (match_operand:SI 2 "register_operand" "")
15768 + (zero_extend:SI (match_dup 0)))]
15769 + "(REGNO(operands[0]) == REGNO(operands[2])) || peep2_reg_dead_p(2, operands[0])"
15770 + [(set (match_dup 2)
15771 + (zero_extend:SI (match_dup 1)))]
15772 + "")
15773 +
15774 +;;=============================================================================
15775 +;; Peephole optimizing
15776 +;;-----------------------------------------------------------------------------
15777 +;; Changing
15778 +;; ld.sh r0, r7[-0x6]
15779 +;; casts.h r0
15780 +;; to
15781 +;; ld.sh r0, r7[-0x6]
15782 +;;=============================================================================
15783 +(define_peephole2
15784 + [(set (match_operand:HI 0 "register_operand" "")
15785 + (match_operand:HI 1 "memory_operand" ""))
15786 + (set (match_operand:SI 2 "register_operand" "")
15787 + (sign_extend:SI (match_dup 0)))]
15788 + "(REGNO(operands[0]) == REGNO(operands[2])) || peep2_reg_dead_p(2, operands[0])"
15789 + [(set (match_dup 2)
15790 + (sign_extend:SI (match_dup 1)))]
15791 + "")
15792 +
15793 +;;=============================================================================
15794 +;; Peephole optimizing
15795 +;;-----------------------------------------------------------------------------
15796 +;; Changing
15797 +;; ld.uh r0, r7[-0x6]
15798 +;; castu.h r0
15799 +;; to
15800 +;; ld.uh r0, r7[-0x6]
15801 +;;=============================================================================
15802 +(define_peephole2
15803 + [(set (match_operand:HI 0 "register_operand" "")
15804 + (match_operand:HI 1 "memory_operand" ""))
15805 + (set (match_operand:SI 2 "register_operand" "")
15806 + (zero_extend:SI (match_dup 0)))]
15807 + "(REGNO(operands[0]) == REGNO(operands[2])) || peep2_reg_dead_p(2, operands[0])"
15808 + [(set (match_dup 2)
15809 + (zero_extend:SI (match_dup 1)))]
15810 + "")
15811 +
15812 +;;=============================================================================
15813 +;; Peephole optimizing
15814 +;;-----------------------------------------------------------------------------
15815 +;; Changing
15816 +;; mul rd, rx, ry
15817 +;; add rd2, rd
15818 +;; or
15819 +;; add rd2, rd, rd2
15820 +;; to
15821 +;; mac rd2, rx, ry
15822 +;;=============================================================================
15823 +(define_peephole2
15824 + [(set (match_operand:SI 0 "register_operand" "")
15825 + (mult:SI (match_operand:SI 1 "register_operand" "")
15826 + (match_operand:SI 2 "register_operand" "")))
15827 + (set (match_operand:SI 3 "register_operand" "")
15828 + (plus:SI (match_dup 3)
15829 + (match_dup 0)))]
15830 + "peep2_reg_dead_p(2, operands[0])"
15831 + [(set (match_dup 3)
15832 + (plus:SI (mult:SI (match_dup 1)
15833 + (match_dup 2))
15834 + (match_dup 3)))]
15835 + "")
15836 +
15837 +(define_peephole2
15838 + [(set (match_operand:SI 0 "register_operand" "")
15839 + (mult:SI (match_operand:SI 1 "register_operand" "")
15840 + (match_operand:SI 2 "register_operand" "")))
15841 + (set (match_operand:SI 3 "register_operand" "")
15842 + (plus:SI (match_dup 0)
15843 + (match_dup 3)))]
15844 + "peep2_reg_dead_p(2, operands[0])"
15845 + [(set (match_dup 3)
15846 + (plus:SI (mult:SI (match_dup 1)
15847 + (match_dup 2))
15848 + (match_dup 3)))]
15849 + "")
15850 +
15851 +
15852 +;;=============================================================================
15853 +;; Peephole optimizing
15854 +;;-----------------------------------------------------------------------------
15855 +;; Changing
15856 +;; bfextu rd, rs, k5, 1 or and(h/l) rd, one_bit_set_mask
15857 +;; to
15858 +;; bld rs, k5
15859 +;;
15860 +;; If rd is dead after the operation.
15861 +;;=============================================================================
15862 +(define_peephole2
15863 + [ (set (match_operand:SI 0 "register_operand" "")
15864 + (zero_extract:SI (match_operand:SI 1 "register_operand" "")
15865 + (const_int 1)
15866 + (match_operand:SI 2 "immediate_operand" "")))
15867 + (set (cc0)
15868 + (match_dup 0))]
15869 + "peep2_reg_dead_p(2, operands[0])"
15870 + [(set (cc0)
15871 + (and:SI (match_dup 1)
15872 + (match_dup 2)))]
15873 + "operands[2] = GEN_INT(1 << INTVAL(operands[2]));")
15874 +
15875 +(define_peephole2
15876 + [ (set (match_operand:SI 0 "register_operand" "")
15877 + (and:SI (match_operand:SI 1 "register_operand" "")
15878 + (match_operand:SI 2 "one_bit_set_operand" "")))
15879 + (set (cc0)
15880 + (match_dup 0))]
15881 + "peep2_reg_dead_p(2, operands[0])"
15882 + [(set (cc0)
15883 + (and:SI (match_dup 1)
15884 + (match_dup 2)))]
15885 + "")
15886 +
15887 +;;=============================================================================
15888 +;; Peephole optimizing
15889 +;;-----------------------------------------------------------------------------
15890 +;; Load with extracted index: ld.w Rd, Rb[Ri:{t/u/b/l} << 2]
15891 +;;
15892 +;;=============================================================================
15893 +
15894 +
15895 +(define_peephole
15896 + [(set (match_operand:SI 0 "register_operand" "")
15897 + (zero_extract:SI (match_operand:SI 1 "register_operand" "")
15898 + (const_int 8)
15899 + (match_operand:SI 2 "avr32_extract_shift_operand" "")))
15900 + (set (match_operand:SI 3 "register_operand" "")
15901 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15902 + (match_operand:SI 4 "register_operand" ""))))]
15903 +
15904 + "(dead_or_set_p(insn, operands[0]))"
15905 + {
15906 + switch ( INTVAL(operands[2]) ){
15907 + case 0:
15908 + return "ld.w %3, %4[%1:b << 2]";
15909 + case 8:
15910 + return "ld.w %3, %4[%1:l << 2]";
15911 + case 16:
15912 + return "ld.w %3, %4[%1:u << 2]";
15913 + case 24:
15914 + return "ld.w %3, %4[%1:t << 2]";
15915 + default:
15916 + internal_error("illegal operand for ldxi");
15917 + }
15918 + }
15919 + [(set_attr "type" "load")
15920 + (set_attr "length" "4")
15921 + (set_attr "cc" "clobber")]
15922 + )
15923 +
15924 +
15925 +
15926 +(define_peephole
15927 + [(set (match_operand:SI 0 "register_operand" "")
15928 + (and:SI (match_operand:SI 1 "register_operand" "") (const_int 255)))
15929 + (set (match_operand:SI 2 "register_operand" "")
15930 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15931 + (match_operand:SI 3 "register_operand" ""))))]
15932 +
15933 + "(dead_or_set_p(insn, operands[0]))"
15934 +
15935 + "ld.w %2, %3[%1:b << 2]"
15936 + [(set_attr "type" "load")
15937 + (set_attr "length" "4")
15938 + (set_attr "cc" "clobber")]
15939 + )
15940 +
15941 +
15942 +(define_peephole2
15943 + [(set (match_operand:SI 0 "register_operand" "")
15944 + (zero_extract:SI (match_operand:SI 1 "register_operand" "")
15945 + (const_int 8)
15946 + (match_operand:SI 2 "avr32_extract_shift_operand" "")))
15947 + (set (match_operand:SI 3 "register_operand" "")
15948 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15949 + (match_operand:SI 4 "register_operand" ""))))]
15950 +
15951 + "(peep2_reg_dead_p(2, operands[0]))
15952 + || (REGNO(operands[0]) == REGNO(operands[3]))"
15953 + [(set (match_dup 3)
15954 + (mem:SI (plus:SI
15955 + (match_dup 4)
15956 + (mult:SI (zero_extract:SI (match_dup 1)
15957 + (const_int 8)
15958 + (match_dup 2))
15959 + (const_int 4)))))]
15960 + )
15961 +
15962 +(define_peephole2
15963 + [(set (match_operand:SI 0 "register_operand" "")
15964 + (zero_extend:SI (match_operand:QI 1 "register_operand" "")))
15965 + (set (match_operand:SI 2 "register_operand" "")
15966 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15967 + (match_operand:SI 3 "register_operand" ""))))]
15968 +
15969 + "(peep2_reg_dead_p(2, operands[0]))
15970 + || (REGNO(operands[0]) == REGNO(operands[2]))"
15971 + [(set (match_dup 2)
15972 + (mem:SI (plus:SI
15973 + (match_dup 3)
15974 + (mult:SI (zero_extract:SI (match_dup 1)
15975 + (const_int 8)
15976 + (const_int 0))
15977 + (const_int 4)))))]
15978 + "operands[1] = gen_rtx_REG(SImode, REGNO(operands[1]));"
15979 + )
15980 +
15981 +
15982 +(define_peephole2
15983 + [(set (match_operand:SI 0 "register_operand" "")
15984 + (and:SI (match_operand:SI 1 "register_operand" "")
15985 + (const_int 255)))
15986 + (set (match_operand:SI 2 "register_operand" "")
15987 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15988 + (match_operand:SI 3 "register_operand" ""))))]
15989 +
15990 + "(peep2_reg_dead_p(2, operands[0]))
15991 + || (REGNO(operands[0]) == REGNO(operands[2]))"
15992 + [(set (match_dup 2)
15993 + (mem:SI (plus:SI
15994 + (match_dup 3)
15995 + (mult:SI (zero_extract:SI (match_dup 1)
15996 + (const_int 8)
15997 + (const_int 0))
15998 + (const_int 4)))))]
15999 + ""
16000 + )
16001 +
16002 +
16003 +
16004 +(define_peephole2
16005 + [(set (match_operand:SI 0 "register_operand" "")
16006 + (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
16007 + (const_int 24)))
16008 + (set (match_operand:SI 2 "register_operand" "")
16009 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
16010 + (match_operand:SI 3 "register_operand" ""))))]
16011 +
16012 + "(peep2_reg_dead_p(2, operands[0]))
16013 + || (REGNO(operands[0]) == REGNO(operands[2]))"
16014 + [(set (match_dup 2)
16015 + (mem:SI (plus:SI
16016 + (match_dup 3)
16017 + (mult:SI (zero_extract:SI (match_dup 1)
16018 + (const_int 8)
16019 + (const_int 24))
16020 + (const_int 4)))))]
16021 + ""
16022 + )
16023 +
16024 +
16025 +;;************************************************
16026 +;; ANDN
16027 +;;
16028 +;;************************************************
16029 +
16030 +
16031 +(define_peephole2
16032 + [(set (match_operand:SI 0 "register_operand" "")
16033 + (not:SI (match_operand:SI 1 "register_operand" "")))
16034 + (set (match_operand:SI 2 "register_operand" "")
16035 + (and:SI (match_dup 2)
16036 + (match_dup 0)))]
16037 + "peep2_reg_dead_p(2, operands[0])"
16038 +
16039 + [(set (match_dup 2)
16040 + (and:SI (match_dup 2)
16041 + (not:SI (match_dup 1))
16042 + ))]
16043 + ""
16044 +)
16045 +
16046 +(define_peephole2
16047 + [(set (match_operand:SI 0 "register_operand" "")
16048 + (not:SI (match_operand:SI 1 "register_operand" "")))
16049 + (set (match_operand:SI 2 "register_operand" "")
16050 + (and:SI (match_dup 0)
16051 + (match_dup 2)
16052 + ))]
16053 + "peep2_reg_dead_p(2, operands[0])"
16054 +
16055 + [(set (match_dup 2)
16056 + (and:SI (match_dup 2)
16057 + (not:SI (match_dup 1))
16058 + ))]
16059 +
16060 + ""
16061 +)
16062 +
16063 +
16064 +;;=================================================================
16065 +;; Addabs peephole
16066 +;;=================================================================
16067 +
16068 +(define_peephole
16069 + [(set (match_operand:SI 2 "register_operand" "=r")
16070 + (abs:SI (match_operand:SI 1 "register_operand" "r")))
16071 + (set (match_operand:SI 0 "register_operand" "=r")
16072 + (plus:SI (match_operand:SI 3 "register_operand" "r")
16073 + (match_dup 2)))]
16074 + "dead_or_set_p(insn, operands[2])"
16075 + "addabs %0, %3, %1"
16076 + [(set_attr "length" "4")
16077 + (set_attr "cc" "set_z")])
16078 +
16079 +(define_peephole
16080 + [(set (match_operand:SI 2 "register_operand" "=r")
16081 + (abs:SI (match_operand:SI 1 "register_operand" "r")))
16082 + (set (match_operand:SI 0 "register_operand" "=r")
16083 + (plus:SI (match_dup 2)
16084 + (match_operand:SI 3 "register_operand" "r")))]
16085 + "dead_or_set_p(insn, operands[2])"
16086 + "addabs %0, %3, %1"
16087 + [(set_attr "length" "4")
16088 + (set_attr "cc" "set_z")])
16089 +
16090 +
16091 +;;=================================================================
16092 +;; Detect roundings
16093 +;;=================================================================
16094 +
16095 +(define_insn "*round"
16096 + [(set (match_operand:SI 0 "register_operand" "+r")
16097 + (ashiftrt:SI (plus:SI (match_dup 0)
16098 + (match_operand:SI 1 "immediate_operand" "i"))
16099 + (match_operand:SI 2 "immediate_operand" "i")))]
16100 + "avr32_rnd_operands(operands[1], operands[2])"
16101 +
16102 + "satrnds %0 >> %2, 31"
16103 +
16104 + [(set_attr "type" "alu_sat")
16105 + (set_attr "length" "4")]
16106 +
16107 + )
16108 +
16109 +
16110 +(define_peephole2
16111 + [(set (match_operand:SI 0 "register_operand" "")
16112 + (plus:SI (match_dup 0)
16113 + (match_operand:SI 1 "immediate_operand" "")))
16114 + (set (match_dup 0)
16115 + (ashiftrt:SI (match_dup 0)
16116 + (match_operand:SI 2 "immediate_operand" "")))]
16117 + "avr32_rnd_operands(operands[1], operands[2])"
16118 +
16119 + [(set (match_dup 0)
16120 + (ashiftrt:SI (plus:SI (match_dup 0)
16121 + (match_dup 1))
16122 + (match_dup 2)))]
16123 + )
16124 +
16125 +(define_peephole
16126 + [(set (match_operand:SI 0 "register_operand" "r")
16127 + (plus:SI (match_dup 0)
16128 + (match_operand:SI 1 "immediate_operand" "i")))
16129 + (set (match_dup 0)
16130 + (ashiftrt:SI (match_dup 0)
16131 + (match_operand:SI 2 "immediate_operand" "i")))]
16132 + "avr32_rnd_operands(operands[1], operands[2])"
16133 +
16134 + "satrnds %0 >> %2, 31"
16135 +
16136 + [(set_attr "type" "alu_sat")
16137 + (set_attr "length" "4")
16138 + (set_attr "cc" "clobber")]
16139 +
16140 + )
16141 +
16142 +
16143 +;;=================================================================
16144 +;; mcall
16145 +;;=================================================================
16146 +(define_peephole
16147 + [(set (match_operand:SI 0 "register_operand" "")
16148 + (match_operand 1 "avr32_const_pool_ref_operand" ""))
16149 + (parallel [(call (mem:SI (match_dup 0))
16150 + (match_operand 2 "" ""))
16151 + (clobber (reg:SI LR_REGNUM))])]
16152 + "dead_or_set_p(insn, operands[0])"
16153 + "mcall %1"
16154 + [(set_attr "type" "call")
16155 + (set_attr "length" "4")
16156 + (set_attr "cc" "clobber")]
16157 +)
16158 +
16159 +(define_peephole
16160 + [(set (match_operand:SI 2 "register_operand" "")
16161 + (match_operand 1 "avr32_const_pool_ref_operand" ""))
16162 + (parallel [(set (match_operand 0 "register_operand" "")
16163 + (call (mem:SI (match_dup 2))
16164 + (match_operand 3 "" "")))
16165 + (clobber (reg:SI LR_REGNUM))])]
16166 + "dead_or_set_p(insn, operands[2])"
16167 + "mcall %1"
16168 + [(set_attr "type" "call")
16169 + (set_attr "length" "4")
16170 + (set_attr "cc" "call_set")]
16171 +)
16172 +
16173 +
16174 +(define_peephole2
16175 + [(set (match_operand:SI 0 "register_operand" "")
16176 + (match_operand 1 "avr32_const_pool_ref_operand" ""))
16177 + (parallel [(call (mem:SI (match_dup 0))
16178 + (match_operand 2 "" ""))
16179 + (clobber (reg:SI LR_REGNUM))])]
16180 + "peep2_reg_dead_p(2, operands[0])"
16181 + [(parallel [(call (mem:SI (match_dup 1))
16182 + (match_dup 2))
16183 + (clobber (reg:SI LR_REGNUM))])]
16184 + ""
16185 +)
16186 +
16187 +(define_peephole2
16188 + [(set (match_operand:SI 0 "register_operand" "")
16189 + (match_operand 1 "avr32_const_pool_ref_operand" ""))
16190 + (parallel [(set (match_operand 2 "register_operand" "")
16191 + (call (mem:SI (match_dup 0))
16192 + (match_operand 3 "" "")))
16193 + (clobber (reg:SI LR_REGNUM))])]
16194 + "(peep2_reg_dead_p(2, operands[0]) || (REGNO(operands[2]) == REGNO(operands[0])))"
16195 + [(parallel [(set (match_dup 2)
16196 + (call (mem:SI (match_dup 1))
16197 + (match_dup 3)))
16198 + (clobber (reg:SI LR_REGNUM))])]
16199 + ""
16200 +)
16201 +
16202 +;;=================================================================
16203 +;; Returning a value
16204 +;;=================================================================
16205 +
16206 +
16207 +(define_peephole
16208 + [(set (match_operand 0 "register_operand" "")
16209 + (match_operand 1 "register_operand" ""))
16210 + (return)]
16211 + "USE_RETURN_INSN (TRUE) && (REGNO(operands[0]) == RETVAL_REGNUM)
16212 + && (REGNO(operands[1]) != LR_REGNUM)
16213 + && (REGNO_REG_CLASS(REGNO(operands[1])) == GENERAL_REGS)"
16214 + "retal %1"
16215 + [(set_attr "type" "call")
16216 + (set_attr "length" "2")]
16217 + )
16218 +
16219 +
16220 +(define_peephole
16221 + [(set (match_operand 0 "register_operand" "r")
16222 + (match_operand 1 "immediate_operand" "i"))
16223 + (return)]
16224 + "(USE_RETURN_INSN (FALSE) && (REGNO(operands[0]) == RETVAL_REGNUM) &&
16225 + ((INTVAL(operands[1]) == -1) || (INTVAL(operands[1]) == 0) || (INTVAL(operands[1]) == 1)))"
16226 + {
16227 + avr32_output_return_instruction (TRUE, FALSE, NULL, operands[1]);
16228 + return "";
16229 + }
16230 + [(set_attr "type" "call")
16231 + (set_attr "length" "4")]
16232 + )
16233 +
16234 +(define_peephole
16235 + [(set (match_operand 0 "register_operand" "r")
16236 + (match_operand 1 "immediate_operand" "i"))
16237 + (unspec_volatile [(return)] VUNSPEC_EPILOGUE)]
16238 + "(REGNO(operands[0]) == RETVAL_REGNUM) &&
16239 + ((INTVAL(operands[1]) == -1) || (INTVAL(operands[1]) == 0) || (INTVAL(operands[1]) == 1))"
16240 + {
16241 + avr32_output_return_instruction (FALSE, FALSE, NULL, operands[1]);
16242 + return "";
16243 + }
16244 + ; Length is absolute worst case
16245 + [(set_attr "type" "branch")
16246 + (set_attr "length" "12")]
16247 + )
16248 +
16249 +(define_peephole
16250 + [(set (match_operand 0 "register_operand" "=r")
16251 + (if_then_else (match_operator 1 "avr32_comparison_operator"
16252 + [(match_operand 4 "register_operand" "r")
16253 + (match_operand 5 "register_immediate_operand" "rKs21")])
16254 + (match_operand 2 "avr32_cond_register_immediate_operand" "rKs08")
16255 + (match_operand 3 "avr32_cond_register_immediate_operand" "rKs08")))
16256 + (return)]
16257 + "USE_RETURN_INSN (TRUE) && (REGNO(operands[0]) == RETVAL_REGNUM)"
16258 + {
16259 + operands[1] = avr32_output_cmp(operands[1], GET_MODE(operands[4]), operands[4], operands[5]);
16260 +
16261 + if ( GET_CODE(operands[2]) == REG
16262 + && GET_CODE(operands[3]) == REG
16263 + && REGNO(operands[2]) != LR_REGNUM
16264 + && REGNO(operands[3]) != LR_REGNUM ){
16265 + return "ret%1 %2\;ret%i1 %3";
16266 + } else if ( GET_CODE(operands[2]) == REG
16267 + && GET_CODE(operands[3]) == CONST_INT ){
16268 + if ( INTVAL(operands[3]) == -1
16269 + || INTVAL(operands[3]) == 0
16270 + || INTVAL(operands[3]) == 1 ){
16271 + return "ret%1 %2\;ret%i1 %d3";
16272 + } else {
16273 + return "mov%1 r12, %2\;mov%i1 r12, %3\;retal r12";
16274 + }
16275 + } else if ( GET_CODE(operands[2]) == CONST_INT
16276 + && GET_CODE(operands[3]) == REG ){
16277 + if ( INTVAL(operands[2]) == -1
16278 + || INTVAL(operands[2]) == 0
16279 + || INTVAL(operands[2]) == 1 ){
16280 + return "ret%1 %d2\;ret%i1 %3";
16281 + } else {
16282 + return "mov%1 r12, %2\;mov%i1 r12, %3\;retal r12";
16283 + }
16284 + } else {
16285 + if ( (INTVAL(operands[2]) == -1
16286 + || INTVAL(operands[2]) == 0
16287 + || INTVAL(operands[2]) == 1 )
16288 + && (INTVAL(operands[3]) == -1
16289 + || INTVAL(operands[3]) == 0
16290 + || INTVAL(operands[3]) == 1 )){
16291 + return "ret%1 %d2\;ret%i1 %d3";
16292 + } else {
16293 + return "mov%1 r12, %2\;mov%i1 r12, %3\;retal r12";
16294 + }
16295 + }
16296 + }
16297 +
16298 + [(set_attr "length" "10")
16299 + (set_attr "cc" "none")
16300 + (set_attr "type" "call")])
16301 +
16302 +
16303 +
16304 +;;=================================================================
16305 +;; mulnhh.w
16306 +;;=================================================================
16307 +
16308 +(define_peephole2
16309 + [(set (match_operand:HI 0 "register_operand" "")
16310 + (neg:HI (match_operand:HI 1 "register_operand" "")))
16311 + (set (match_operand:SI 2 "register_operand" "")
16312 + (mult:SI
16313 + (sign_extend:SI (match_dup 0))
16314 + (sign_extend:SI (match_operand:HI 3 "register_operand" ""))))]
16315 + "(peep2_reg_dead_p(2, operands[0])) || (REGNO(operands[2]) == REGNO(operands[0]))"
16316 + [ (set (match_dup 2)
16317 + (mult:SI
16318 + (sign_extend:SI (neg:HI (match_dup 1)))
16319 + (sign_extend:SI (match_dup 3))))]
16320 + ""
16321 + )
16322 +
16323 +(define_peephole2
16324 + [(set (match_operand:HI 0 "register_operand" "")
16325 + (neg:HI (match_operand:HI 1 "register_operand" "")))
16326 + (set (match_operand:SI 2 "register_operand" "")
16327 + (mult:SI
16328 + (sign_extend:SI (match_operand:HI 3 "register_operand" ""))
16329 + (sign_extend:SI (match_dup 0))))]
16330 + "(peep2_reg_dead_p(2, operands[0])) || (REGNO(operands[2]) == REGNO(operands[0]))"
16331 + [ (set (match_dup 2)
16332 + (mult:SI
16333 + (sign_extend:SI (neg:HI (match_dup 1)))
16334 + (sign_extend:SI (match_dup 3))))]
16335 + ""
16336 + )
16337 +
16338 +
16339 +
16340 +;;=================================================================
16341 +;; Vector set and extract operations
16342 +;;=================================================================
16343 +(define_insn "vec_setv2hi_hi"
16344 + [(set (match_operand:V2HI 0 "register_operand" "=r")
16345 + (vec_merge:V2HI
16346 + (match_dup 0)
16347 + (vec_duplicate:V2HI
16348 + (match_operand:HI 1 "register_operand" "r"))
16349 + (const_int 1)))]
16350 + ""
16351 + "bfins\t%0, %1, 16, 16"
16352 + [(set_attr "type" "alu")
16353 + (set_attr "length" "4")
16354 + (set_attr "cc" "clobber")])
16355 +
16356 +(define_insn "vec_setv2hi_lo"
16357 + [(set (match_operand:V2HI 0 "register_operand" "+r")
16358 + (vec_merge:V2HI
16359 + (match_dup 0)
16360 + (vec_duplicate:V2HI
16361 + (match_operand:HI 1 "register_operand" "r"))
16362 + (const_int 2)))]
16363 + ""
16364 + "bfins\t%0, %1, 0, 16"
16365 + [(set_attr "type" "alu")
16366 + (set_attr "length" "4")
16367 + (set_attr "cc" "clobber")])
16368 +
16369 +(define_expand "vec_setv2hi"
16370 + [(set (match_operand:V2HI 0 "register_operand" "")
16371 + (vec_merge:V2HI
16372 + (match_dup 0)
16373 + (vec_duplicate:V2HI
16374 + (match_operand:HI 1 "register_operand" ""))
16375 + (match_operand 2 "immediate_operand" "")))]
16376 + ""
16377 + { operands[2] = GEN_INT(INTVAL(operands[2]) + 1); }
16378 + )
16379 +
16380 +(define_insn "vec_extractv2hi"
16381 + [(set (match_operand:HI 0 "register_operand" "=r")
16382 + (vec_select:HI
16383 + (match_operand:V2HI 1 "register_operand" "r")
16384 + (parallel [(match_operand:SI 2 "immediate_operand" "i")])))]
16385 + ""
16386 + {
16387 + if ( INTVAL(operands[2]) == 0 )
16388 + return "bfextu\t%0, %1, 16, 16";
16389 + else
16390 + return "bfextu\t%0, %1, 0, 16";
16391 + }
16392 + [(set_attr "type" "alu")
16393 + (set_attr "length" "4")
16394 + (set_attr "cc" "clobber")])
16395 +
16396 +(define_insn "vec_extractv4qi"
16397 + [(set (match_operand:QI 0 "register_operand" "=r")
16398 + (vec_select:QI
16399 + (match_operand:V4QI 1 "register_operand" "r")
16400 + (parallel [(match_operand:SI 2 "immediate_operand" "i")])))]
16401 + ""
16402 + {
16403 + switch ( INTVAL(operands[2]) ){
16404 + case 0:
16405 + return "bfextu\t%0, %1, 24, 8";
16406 + case 1:
16407 + return "bfextu\t%0, %1, 16, 8";
16408 + case 2:
16409 + return "bfextu\t%0, %1, 8, 8";
16410 + case 3:
16411 + return "bfextu\t%0, %1, 0, 8";
16412 + default:
16413 + abort();
16414 + }
16415 + }
16416 + [(set_attr "type" "alu")
16417 + (set_attr "length" "4")
16418 + (set_attr "cc" "clobber")])
16419 +
16420 +
16421 +(define_insn "concatv2hi"
16422 + [(set (match_operand:V2HI 0 "register_operand" "=r, r, r")
16423 + (vec_concat:V2HI
16424 + (match_operand:HI 1 "register_operand" "r, r, 0")
16425 + (match_operand:HI 2 "register_operand" "r, 0, r")))]
16426 + ""
16427 + "@
16428 + mov\t%0, %1\;bfins\t%0, %2, 0, 16
16429 + bfins\t%0, %2, 0, 16
16430 + bfins\t%0, %1, 16, 16"
16431 + [(set_attr "length" "6, 4, 4")
16432 + (set_attr "type" "alu")])
16433 +
16434 +
16435 +;; Load the atomic operation description
16436 +(include "sync.md")
16437 +
16438 +;; Load the SIMD description
16439 +(include "simd.md")
16440 +
16441 +;; Include the FPU for uc3
16442 +(include "uc3fpu.md")
16443 --- /dev/null
16444 +++ b/gcc/config/avr32/avr32-modes.def
16445 @@ -0,0 +1 @@
16446 +VECTOR_MODES (INT, 4); /* V4QI V2HI */
16447 --- /dev/null
16448 +++ b/gcc/config/avr32/avr32.opt
16449 @@ -0,0 +1,89 @@
16450 +; Options for the ATMEL AVR32 port of the compiler.
16451 +
16452 +; Copyright 2007 Atmel Corporation.
16453 +;
16454 +; This file is part of GCC.
16455 +;
16456 +; GCC is free software; you can redistribute it and/or modify it under
16457 +; the terms of the GNU General Public License as published by the Free
16458 +; Software Foundation; either version 2, or (at your option) any later
16459 +; version.
16460 +;
16461 +; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16462 +; WARRANTY; without even the implied warranty of MERCHANTABILITY or
16463 +; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16464 +; for more details.
16465 +;
16466 +; You should have received a copy of the GNU General Public License
16467 +; along with GCC; see the file COPYING. If not, write to the Free
16468 +; Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
16469 +; 02110-1301, USA.
16470 +
16471 +muse-rodata-section
16472 +Target Report Mask(USE_RODATA_SECTION)
16473 +Use section .rodata for read-only data instead of .text.
16474 +
16475 +mhard-float
16476 +Target Report Mask(HARD_FLOAT)
16477 +Use FPU instructions instead of floating point emulation.
16478 +
16479 +msoft-float
16480 +Target Report InverseMask(HARD_FLOAT, SOFT_FLOAT)
16481 +Use floating point emulation for floating point operations.
16482 +
16483 +mforce-double-align
16484 +Target Report RejectNegative Mask(FORCE_DOUBLE_ALIGN)
16485 +Force double-word alignment for double-word memory accesses.
16486 +
16487 +mno-init-got
16488 +Target Report RejectNegative Mask(NO_INIT_GOT)
16489 +Do not initialize GOT register before using it when compiling PIC code.
16490 +
16491 +mrelax
16492 +Target Report Mask(RELAX)
16493 +Let invoked assembler and linker do relaxing (Enabled by default when optimization level is >1).
16494 +
16495 +mmd-reorg-opt
16496 +Target Report Undocumented Mask(MD_REORG_OPTIMIZATION)
16497 +Perform machine dependent optimizations in reorg stage.
16498 +
16499 +masm-addr-pseudos
16500 +Target Report Mask(HAS_ASM_ADDR_PSEUDOS)
16501 +Use assembler pseudo-instructions lda.w and call for handling direct addresses. (Enabled by default)
16502 +
16503 +mpart=
16504 +Target Report RejectNegative Joined Var(avr32_part_name)
16505 +Specify the AVR32 part name
16506 +
16507 +mcpu=
16508 +Target Report RejectNegative Joined Undocumented Var(avr32_part_name)
16509 +Specify the AVR32 part name (deprecated)
16510 +
16511 +march=
16512 +Target Report RejectNegative Joined Var(avr32_arch_name)
16513 +Specify the AVR32 architecture name
16514 +
16515 +mfast-float
16516 +Target Report Mask(FAST_FLOAT)
16517 +Enable fast floating-point library. Enabled by default if the -funsafe-math-optimizations switch is specified.
16518 +
16519 +mimm-in-const-pool
16520 +Target Report Var(avr32_imm_in_const_pool) Init(-1)
16521 +Put large immediates in constant pool. This is enabled by default for archs with insn-cache.
16522 +
16523 +mno-pic
16524 +Target Report RejectNegative Mask(NO_PIC)
16525 +Do not generate position-independent code. (deprecated, use -fno-pic instead)
16526 +
16527 +mcond-exec-before-reload
16528 +Target Report Undocumented Mask(COND_EXEC_BEFORE_RELOAD)
16529 +Enable experimental conditional execution preparation before the reload stage.
16530 +
16531 +mrmw-addressable-data
16532 +Target Report Mask(RMW_ADDRESSABLE_DATA)
16533 +Signal that all data is in range for the Atomic Read-Modify-Write memory instructions, and that
16534 +gcc can safely generate these whenever possible.
16535 +
16536 +mflashvault
16537 +Target Var(TARGET_FLASHVAULT)
16538 +Generate code for flashvault
16539 --- /dev/null
16540 +++ b/gcc/config/avr32/avr32-protos.h
16541 @@ -0,0 +1,196 @@
16542 +/*
16543 + Prototypes for exported functions defined in avr32.c
16544 + Copyright 2003,2004,2005,2006,2007,2008,2009 Atmel Corporation.
16545 +
16546 + This file is part of GCC.
16547 +
16548 + This program is free software; you can redistribute it and/or modify
16549 + it under the terms of the GNU General Public License as published by
16550 + the Free Software Foundation; either version 2 of the License, or
16551 + (at your option) any later version.
16552 +
16553 + This program is distributed in the hope that it will be useful,
16554 + but WITHOUT ANY WARRANTY; without even the implied warranty of
16555 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16556 + GNU General Public License for more details.
16557 +
16558 + You should have received a copy of the GNU General Public License
16559 + along with this program; if not, write to the Free Software
16560 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16561 +
16562 +
16563 +#ifndef AVR32_PROTOS_H
16564 +#define AVR32_PROTOS_H
16565 +
16566 +extern const int swap_reg[];
16567 +
16568 +extern int avr32_valid_macmac_bypass (rtx, rtx);
16569 +extern int avr32_valid_mulmac_bypass (rtx, rtx);
16570 +
16571 +extern int avr32_decode_lcomm_symbol_offset (rtx, int *);
16572 +extern void avr32_encode_lcomm_symbol_offset (tree, char *, int);
16573 +
16574 +extern const char *avr32_strip_name_encoding (const char *);
16575 +
16576 +extern rtx avr32_get_note_reg_equiv (rtx insn);
16577 +
16578 +extern int avr32_use_return_insn (int iscond);
16579 +
16580 +extern void avr32_make_reglist16 (int reglist16_vect, char *reglist16_string);
16581 +
16582 +extern void avr32_make_reglist8 (int reglist8_vect, char *reglist8_string);
16583 +extern void avr32_make_fp_reglist_w (int reglist_mask, char *reglist_string);
16584 +extern void avr32_make_fp_reglist_d (int reglist_mask, char *reglist_string);
16585 +
16586 +extern void avr32_output_return_instruction (int single_ret_inst,
16587 + int iscond, rtx cond,
16588 + rtx r12_imm);
16589 +extern void avr32_expand_prologue (void);
16590 +extern void avr32_set_return_address (rtx source, rtx scratch);
16591 +
16592 +extern int avr32_hard_regno_mode_ok (int regno, enum machine_mode mode);
16593 +extern int avr32_extra_constraint_s (rtx value, const int strict);
16594 +extern int avr32_eh_return_data_regno (const int n);
16595 +extern int avr32_initial_elimination_offset (const int from, const int to);
16596 +extern rtx avr32_function_arg (CUMULATIVE_ARGS * cum, enum machine_mode mode,
16597 + tree type, int named);
16598 +extern void avr32_init_cumulative_args (CUMULATIVE_ARGS * cum, tree fntype,
16599 + rtx libname, tree fndecl);
16600 +extern void avr32_function_arg_advance (CUMULATIVE_ARGS * cum,
16601 + enum machine_mode mode,
16602 + tree type, int named);
16603 +#ifdef ARGS_SIZE_RTX
16604 +/* expr.h defines ARGS_SIZE_RTX and `enum direction'. */
16605 +extern enum direction avr32_function_arg_padding (enum machine_mode mode,
16606 + tree type);
16607 +#endif /* ARGS_SIZE_RTX */
16608 +extern rtx avr32_function_value (tree valtype, tree func, bool outgoing);
16609 +extern rtx avr32_libcall_value (enum machine_mode mode);
16610 +extern int avr32_sched_use_dfa_pipeline_interface (void);
16611 +extern bool avr32_return_in_memory (tree type, tree fntype);
16612 +extern void avr32_regs_to_save (char *operand);
16613 +extern void avr32_target_asm_function_prologue (FILE * file,
16614 + HOST_WIDE_INT size);
16615 +extern void avr32_target_asm_function_epilogue (FILE * file,
16616 + HOST_WIDE_INT size);
16617 +extern void avr32_trampoline_template (FILE * file);
16618 +extern void avr32_initialize_trampoline (rtx addr, rtx fnaddr,
16619 + rtx static_chain);
16620 +extern int avr32_legitimate_address (enum machine_mode mode, rtx x,
16621 + int strict);
16622 +extern int avr32_legitimate_constant_p (rtx x);
16623 +
16624 +extern int avr32_legitimate_pic_operand_p (rtx x);
16625 +
16626 +extern rtx avr32_find_symbol (rtx x);
16627 +extern void avr32_select_section (rtx exp, int reloc, int align);
16628 +extern void avr32_encode_section_info (tree decl, rtx rtl, int first);
16629 +extern void avr32_asm_file_end (FILE * stream);
16630 +extern void avr32_asm_output_ascii (FILE * stream, char *ptr, int len);
16631 +extern void avr32_asm_output_common (FILE * stream, const char *name,
16632 + int size, int rounded);
16633 +extern void avr32_asm_output_label (FILE * stream, const char *name);
16634 +extern void avr32_asm_declare_object_name (FILE * stream, char *name,
16635 + tree decl);
16636 +extern void avr32_asm_globalize_label (FILE * stream, const char *name);
16637 +extern void avr32_asm_weaken_label (FILE * stream, const char *name);
16638 +extern void avr32_asm_output_external (FILE * stream, tree decl,
16639 + const char *name);
16640 +extern void avr32_asm_output_external_libcall (FILE * stream, rtx symref);
16641 +extern void avr32_asm_output_labelref (FILE * stream, const char *name);
16642 +extern void avr32_notice_update_cc (rtx exp, rtx insn);
16643 +extern void avr32_print_operand (FILE * stream, rtx x, int code);
16644 +extern void avr32_print_operand_address (FILE * stream, rtx x);
16645 +
16646 +extern int avr32_symbol (rtx x);
16647 +
16648 +extern void avr32_select_rtx_section (enum machine_mode mode, rtx x,
16649 + unsigned HOST_WIDE_INT align);
16650 +
16651 +extern int avr32_load_multiple_operation (rtx op, enum machine_mode mode);
16652 +extern int avr32_store_multiple_operation (rtx op, enum machine_mode mode);
16653 +
16654 +extern int avr32_const_ok_for_constraint_p (HOST_WIDE_INT value, char c,
16655 + const char *str);
16656 +
16657 +extern bool avr32_cannot_force_const_mem (rtx x);
16658 +
16659 +extern void avr32_init_builtins (void);
16660 +
16661 +extern rtx avr32_expand_builtin (tree exp, rtx target, rtx subtarget,
16662 + enum machine_mode mode, int ignore);
16663 +
16664 +extern bool avr32_must_pass_in_stack (enum machine_mode mode, tree type);
16665 +
16666 +extern bool avr32_strict_argument_naming (CUMULATIVE_ARGS * ca);
16667 +
16668 +extern bool avr32_pass_by_reference (CUMULATIVE_ARGS * cum,
16669 + enum machine_mode mode,
16670 + tree type, bool named);
16671 +
16672 +extern rtx avr32_gen_load_multiple (rtx * regs, int count, rtx from,
16673 + int write_back, int in_struct_p,
16674 + int scalar_p);
16675 +extern rtx avr32_gen_store_multiple (rtx * regs, int count, rtx to,
16676 + int in_struct_p, int scalar_p);
16677 +extern int avr32_gen_movmemsi (rtx * operands);
16678 +
16679 +extern int avr32_rnd_operands (rtx add, rtx shift);
16680 +extern int avr32_adjust_insn_length (rtx insn, int length);
16681 +
16682 +extern int symbol_mentioned_p (rtx x);
16683 +extern int label_mentioned_p (rtx x);
16684 +extern rtx legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg);
16685 +extern int avr32_address_register_rtx_p (rtx x, int strict_p);
16686 +extern int avr32_legitimate_index_p (enum machine_mode mode, rtx index,
16687 + int strict_p);
16688 +
16689 +extern int avr32_const_double_immediate (rtx value);
16690 +extern void avr32_init_expanders (void);
16691 +extern rtx avr32_return_addr (int count, rtx frame);
16692 +extern bool avr32_got_mentioned_p (rtx addr);
16693 +
16694 +extern void avr32_final_prescan_insn (rtx insn, rtx * opvec, int noperands);
16695 +
16696 +extern int avr32_expand_movcc (enum machine_mode mode, rtx operands[]);
16697 +extern int avr32_expand_addcc (enum machine_mode mode, rtx operands[]);
16698 +#ifdef RTX_CODE
16699 +extern int avr32_expand_scc (RTX_CODE cond, rtx * operands);
16700 +#endif
16701 +
16702 +extern int avr32_store_bypass (rtx insn_out, rtx insn_in);
16703 +extern int avr32_mul_waw_bypass (rtx insn_out, rtx insn_in);
16704 +extern int avr32_valid_load_double_bypass (rtx insn_out, rtx insn_in);
16705 +extern int avr32_valid_load_quad_bypass (rtx insn_out, rtx insn_in);
16706 +extern rtx avr32_output_cmp (rtx cond, enum machine_mode mode,
16707 + rtx op0, rtx op1);
16708 +
16709 +rtx get_next_insn_cond (rtx cur_insn);
16710 +int set_next_insn_cond (rtx cur_insn, rtx cond);
16711 +rtx next_insn_emits_cmp (rtx cur_insn);
16712 +void avr32_override_options (void);
16713 +void avr32_load_pic_register (void);
16714 +#ifdef GCC_BASIC_BLOCK_H
16715 +rtx avr32_ifcvt_modify_insn (ce_if_block_t *ce_info, rtx pattern, rtx insn,
16716 + int *num_true_changes);
16717 +rtx avr32_ifcvt_modify_test (ce_if_block_t *ce_info, rtx test );
16718 +void avr32_ifcvt_modify_cancel ( ce_if_block_t *ce_info, int *num_true_changes);
16719 +#endif
16720 +void avr32_optimization_options (int level, int size);
16721 +int avr32_const_ok_for_move (HOST_WIDE_INT c);
16722 +
16723 +void avr32_split_const_expr (enum machine_mode mode,
16724 + enum machine_mode new_mode,
16725 + rtx expr,
16726 + rtx *split_expr);
16727 +void avr32_get_intval (enum machine_mode mode,
16728 + rtx const_expr,
16729 + HOST_WIDE_INT *val);
16730 +
16731 +int avr32_cond_imm_clobber_splittable (rtx insn,
16732 + rtx operands[]);
16733 +
16734 +bool avr32_flashvault_call(tree decl);
16735 +extern void avr32_emit_swdivsf (rtx, rtx, rtx);
16736 +
16737 +#endif /* AVR32_PROTOS_H */
16738 --- /dev/null
16739 +++ b/gcc/config/avr32/crti.asm
16740 @@ -0,0 +1,64 @@
16741 +/*
16742 + Init/fini stuff for AVR32.
16743 + Copyright 2003-2006 Atmel Corporation.
16744 +
16745 + Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
16746 +
16747 + This file is part of GCC.
16748 +
16749 + This program is free software; you can redistribute it and/or modify
16750 + it under the terms of the GNU General Public License as published by
16751 + the Free Software Foundation; either version 2 of the License, or
16752 + (at your option) any later version.
16753 +
16754 + This program is distributed in the hope that it will be useful,
16755 + but WITHOUT ANY WARRANTY; without even the implied warranty of
16756 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16757 + GNU General Public License for more details.
16758 +
16759 + You should have received a copy of the GNU General Public License
16760 + along with this program; if not, write to the Free Software
16761 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16762 +
16763 +
16764 +/* The code in sections .init and .fini is supposed to be a single
16765 + regular function. The function in .init is called directly from
16766 + start in crt1.asm. The function in .fini is atexit()ed in crt1.asm
16767 + too.
16768 +
16769 + crti.asm contributes the prologue of a function to these sections,
16770 + and crtn.asm comes up the epilogue. STARTFILE_SPEC should list
16771 + crti.o before any other object files that might add code to .init
16772 + or .fini sections, and ENDFILE_SPEC should list crtn.o after any
16773 + such object files. */
16774 +
16775 + .file "crti.asm"
16776 +
16777 + .section ".init"
16778 +/* Just load the GOT */
16779 + .align 2
16780 + .global _init
16781 +_init:
16782 + stm --sp, r6, lr
16783 + lddpc r6, 1f
16784 +0:
16785 + rsub r6, pc
16786 + rjmp 2f
16787 + .align 2
16788 +1: .long 0b - _GLOBAL_OFFSET_TABLE_
16789 +2:
16790 +
16791 + .section ".fini"
16792 +/* Just load the GOT */
16793 + .align 2
16794 + .global _fini
16795 +_fini:
16796 + stm --sp, r6, lr
16797 + lddpc r6, 1f
16798 +0:
16799 + rsub r6, pc
16800 + rjmp 2f
16801 + .align 2
16802 +1: .long 0b - _GLOBAL_OFFSET_TABLE_
16803 +2:
16804 +
16805 --- /dev/null
16806 +++ b/gcc/config/avr32/crtn.asm
16807 @@ -0,0 +1,44 @@
16808 +/* Copyright (C) 2001 Free Software Foundation, Inc.
16809 + Written By Nick Clifton
16810 +
16811 + This file is free software; you can redistribute it and/or modify it
16812 + under the terms of the GNU General Public License as published by the
16813 + Free Software Foundation; either version 2, or (at your option) any
16814 + later version.
16815 +
16816 + In addition to the permissions in the GNU General Public License, the
16817 + Free Software Foundation gives you unlimited permission to link the
16818 + compiled version of this file with other programs, and to distribute
16819 + those programs without any restriction coming from the use of this
16820 + file. (The General Public License restrictions do apply in other
16821 + respects; for example, they cover modification of the file, and
16822 + distribution when not linked into another program.)
16823 +
16824 + This file is distributed in the hope that it will be useful, but
16825 + WITHOUT ANY WARRANTY; without even the implied warranty of
16826 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16827 + General Public License for more details.
16828 +
16829 + You should have received a copy of the GNU General Public License
16830 + along with this program; see the file COPYING. If not, write to
16831 + the Free Software Foundation, 59 Temple Place - Suite 330,
16832 + Boston, MA 02111-1307, USA.
16833 +
16834 + As a special exception, if you link this library with files
16835 + compiled with GCC to produce an executable, this does not cause
16836 + the resulting executable to be covered by the GNU General Public License.
16837 + This exception does not however invalidate any other reasons why
16838 + the executable file might be covered by the GNU General Public License.
16839 +*/
16840 +
16841 +
16842 +
16843 +
16844 + .file "crtn.asm"
16845 +
16846 + .section ".init"
16847 + ldm sp++, r6, pc
16848 +
16849 + .section ".fini"
16850 + ldm sp++, r6, pc
16851 +
16852 --- /dev/null
16853 +++ b/gcc/config/avr32/lib1funcs.S
16854 @@ -0,0 +1,2903 @@
16855 +/* Macro for moving immediate value to register. */
16856 +.macro mov_imm reg, imm
16857 +.if (((\imm & 0xfffff) == \imm) || ((\imm | 0xfff00000) == \imm))
16858 + mov \reg, \imm
16859 +#if __AVR32_UC__ >= 2
16860 +.elseif ((\imm & 0xffff) == 0)
16861 + movh \reg, hi(\imm)
16862 +
16863 +#endif
16864 +.else
16865 + mov \reg, lo(\imm)
16866 + orh \reg, hi(\imm)
16867 +.endif
16868 +.endm
16869 +
16870 +
16871 +
16872 +/* Adjust the unpacked double number if it is a subnormal number.
16873 + The exponent and mantissa pair are stored
16874 + in [mant_hi,mant_lo] and [exp]. A register with the correct sign bit in
16875 + the MSB is passed in [sign]. Needs two scratch
16876 + registers [scratch1] and [scratch2]. An adjusted and packed double float
16877 + is present in [mant_hi,mant_lo] after macro has executed */
16878 +.macro adjust_subnormal_df exp, mant_lo, mant_hi, sign, scratch1, scratch2
16879 + /* We have an exponent which is <=0 indicating a subnormal number
16880 + As it should be stored as if the exponent was 1 (although the
16881 + exponent field is all zeros to indicate a subnormal number)
16882 + we have to shift down the mantissa to its correct position. */
16883 + neg \exp
16884 + sub \exp,-1 /* amount to shift down */
16885 + cp.w \exp,54
16886 + brlo 50f /* if more than 53 shift steps, the
16887 + entire mantissa will disappear
16888 + without any rounding to occur */
16889 + mov \mant_hi, 0
16890 + mov \mant_lo, 0
16891 + rjmp 52f
16892 +50:
16893 + sub \exp,-10 /* do the shift to position the
16894 + mantissa at the same time
16895 + note! this does not include the
16896 + final 1 step shift to add the sign */
16897 +
16898 + /* when shifting, save all shifted out bits in [scratch2]. we may need to
16899 + look at them to make correct rounding. */
16900 +
16901 + rsub \scratch1,\exp,32 /* get inverted shift count */
16902 + cp.w \exp,32 /* handle shifts >= 32 separately */
16903 + brhs 51f
16904 +
16905 + /* small (<32) shift amount, both words are part of the shift */
16906 + lsl \scratch2,\mant_lo,\scratch1 /* save bits to shift out from lsw*/
16907 + lsl \scratch1,\mant_hi,\scratch1 /* get bits from msw destined for lsw*/
16908 + lsr \mant_lo,\mant_lo,\exp /* shift down lsw */
16909 + lsr \mant_hi,\mant_hi,\exp /* shift down msw */
16910 + or \mant_hi,\scratch1 /* add bits from msw with prepared lsw */
16911 + rjmp 50f
16912 +
16913 + /* large (>=32) shift amount, only lsw will have bits left after shift.
16914 + note that shift operations will use ((shift count) mod 32) so
16915 + we do not need to subtract 32 from shift count. */
16916 +51:
16917 + lsl \scratch2,\mant_hi,\scratch1 /* save bits to shift out from msw */
16918 + or \scratch2,\mant_lo /* also save all bits from lsw */
16919 + mov \mant_lo,\mant_hi /* msw -> lsw (i.e. "shift 32 first") */
16920 + mov \mant_hi,0 /* clear msw */
16921 + lsr \mant_lo,\mant_lo,\exp /* make rest of shift inside lsw */
16922 +
16923 +50:
16924 + /* result is almost ready to return, except that least significant bit
16925 + and the part we already shifted out may cause the result to be
16926 + rounded */
16927 + bld \mant_lo,0 /* get bit to be shifted out */
16928 + brcc 51f /* if bit was 0, no rounding */
16929 +
16930 + /* msb of part to remove is 1, so rounding depends on rest of bits */
16931 + tst \scratch2,\scratch2 /* get shifted out tail */
16932 + brne 50f /* if rest > 0, do round */
16933 + bld \mant_lo,1 /* we have to look at lsb in result */
16934 + brcc 51f /* if lsb is 0, don't round */
16935 +
16936 +50:
16937 + /* subnormal result requires rounding
16938 + rounding may cause subnormal to become smallest normal number
16939 + luckily, smallest normal number has exactly the representation
16940 + we got by rippling a one bit up from mantissa into exponent field. */
16941 + sub \mant_lo,-1
16942 + subcc \mant_hi,-1
16943 +
16944 +51:
16945 + /* shift and return packed double with correct sign */
16946 + rol \sign
16947 + ror \mant_hi
16948 + ror \mant_lo
16949 +52:
16950 +.endm
16951 +
16952 +
16953 +/* Adjust subnormal single float number with exponent [exp]
16954 + and mantissa [mant] and round. */
16955 +.macro adjust_subnormal_sf sf, exp, mant, sign, scratch
16956 + /* subnormal number */
16957 + rsub \exp,\exp, 1 /* shift amount */
16958 + cp.w \exp, 25
16959 + movhs \mant, 0
16960 + brhs 90f /* Return zero */
16961 + rsub \scratch, \exp, 32
16962 + lsl \scratch, \mant,\scratch/* Check if there are any bits set
16963 + in the bits discarded in the mantissa */
16964 + srne \scratch /* If so set the lsb of the shifted mantissa */
16965 + lsr \mant,\mant,\exp /* Shift the mantissa */
16966 + or \mant, \scratch /* Round lsb if any bits were shifted out */
16967 + /* Rounding : For explaination, see round_sf. */
16968 + mov \scratch, 0x7f /* Set rounding constant */
16969 + bld \mant, 8
16970 + subeq \scratch, -1 /* For odd numbers use rounding constant 0x80 */
16971 + add \mant, \scratch /* Add rounding constant to mantissa */
16972 + /* We can't overflow because mantissa is at least shifted one position
16973 + to the right so the implicit bit is zero. We can however get the implicit
16974 + bit set after rounding which means that we have the lowest normal number
16975 + but this is ok since this bit has the same position as the LSB of the
16976 + exponent */
16977 + lsr \sf, \mant, 7
16978 + /* Rotate in sign */
16979 + lsl \sign, 1
16980 + ror \sf
16981 +90:
16982 +.endm
16983 +
16984 +
16985 +/* Round the unpacked df number with exponent [exp] and
16986 + mantissa [mant_hi, mant_lo]. Uses scratch register
16987 + [scratch] */
16988 +.macro round_df exp, mant_lo, mant_hi, scratch
16989 + mov \scratch, 0x3ff /* Rounding constant */
16990 + bld \mant_lo,11 /* Check if lsb in the final result is
16991 + set */
16992 + subeq \scratch, -1 /* Adjust rounding constant to 0x400
16993 + if rounding 0.5 upwards */
16994 + add \mant_lo, \scratch /* Round */
16995 + acr \mant_hi /* If overflowing we know that
16996 + we have all zeros in the bits not
16997 + scaled out so we can leave them
16998 + but we must increase the exponent with
16999 + two since we had an implicit bit
17000 + which is lost + the extra overflow bit */
17001 + subcs \exp, -2 /* Update exponent */
17002 +.endm
17003 +
17004 +/* Round single float number stored in [mant] and [exp] */
17005 +.macro round_sf exp, mant, scratch
17006 + /* Round:
17007 + For 0.5 we round to nearest even integer
17008 + for all other cases we round to nearest integer.
17009 + This means that if the digit left of the "point" (.)
17010 + is 1 we can add 0x80 to the mantissa since the
17011 + corner case 0x180 will round up to 0x200. If the
17012 + digit left of the "point" is 0 we will have to
17013 + add 0x7f since this will give 0xff and hence a
17014 + truncation/rounding downwards for the corner
17015 + case when the 9 lowest bits are 0x080 */
17016 + mov \scratch, 0x7f /* Set rounding constant */
17017 + /* Check if the mantissa is even or odd */
17018 + bld \mant, 8
17019 + subeq \scratch, -1 /* Rounding constant should be 0x80 */
17020 + add \mant, \scratch
17021 + subcs \exp, -2 /* Adjust exponent if we overflowed */
17022 +.endm
17023 +
17024 +
17025 +
17026 +/* Pack a single float number stored in [mant] and [exp]
17027 + into a single float number in [sf] */
17028 +.macro pack_sf sf, exp, mant
17029 + bld \mant,31 /* implicit bit to z */
17030 + subne \exp,1 /* if subnormal (implicit bit 0)
17031 + adjust exponent to storage format */
17032 +
17033 + lsr \sf, \mant, 7
17034 + bfins \sf, \exp, 24, 8
17035 +.endm
17036 +
17037 +/* Pack exponent [exp] and mantissa [mant_hi, mant_lo]
17038 + into [df_hi, df_lo]. [df_hi] is shifted
17039 + one bit up so the sign bit can be shifted into it */
17040 +
17041 +.macro pack_df exp, mant_lo, mant_hi, df_lo, df_hi
17042 + bld \mant_hi,31 /* implicit bit to z */
17043 + subne \exp,1 /* if subnormal (implicit bit 0)
17044 + adjust exponent to storage format */
17045 +
17046 + lsr \mant_lo,11 /* shift back lsw */
17047 + or \df_lo,\mant_lo,\mant_hi<<21 /* combine with low bits from msw */
17048 + lsl \mant_hi,1 /* get rid of implicit bit */
17049 + lsr \mant_hi,11 /* shift back msw except for one step*/
17050 + or \df_hi,\mant_hi,\exp<<21 /* combine msw with exponent */
17051 +.endm
17052 +
17053 +/* Normalize single float number stored in [mant] and [exp]
17054 + using scratch register [scratch] */
17055 +.macro normalize_sf exp, mant, scratch
17056 + /* Adjust exponent and mantissa */
17057 + clz \scratch, \mant
17058 + sub \exp, \scratch
17059 + lsl \mant, \mant, \scratch
17060 +.endm
17061 +
17062 +/* Normalize the exponent and mantissa pair stored
17063 + in [mant_hi,mant_lo] and [exp]. Needs two scratch
17064 + registers [scratch1] and [scratch2]. */
17065 +.macro normalize_df exp, mant_lo, mant_hi, scratch1, scratch2
17066 + clz \scratch1,\mant_hi /* Check if we have zeros in high bits */
17067 + breq 80f /* No need for scaling if no zeros in high bits */
17068 + brcs 81f /* Check for all zeros */
17069 +
17070 + /* shift amount is smaller than 32, and involves both msw and lsw*/
17071 + rsub \scratch2,\scratch1,32 /* shift mantissa */
17072 + lsl \mant_hi,\mant_hi,\scratch1
17073 + lsr \scratch2,\mant_lo,\scratch2
17074 + or \mant_hi,\scratch2
17075 + lsl \mant_lo,\mant_lo,\scratch1
17076 + sub \exp,\scratch1 /* adjust exponent */
17077 + rjmp 80f /* Finished */
17078 +81:
17079 + /* shift amount is greater than 32 */
17080 + clz \scratch1,\mant_lo /* shift mantissa */
17081 + movcs \scratch1, 0
17082 + subcc \scratch1,-32
17083 + lsl \mant_hi,\mant_lo,\scratch1
17084 + mov \mant_lo,0
17085 + sub \exp,\scratch1 /* adjust exponent */
17086 +80:
17087 +.endm
17088 +
17089 +
17090 +/* Fast but approximate multiply of two 64-bit numbers to give a 64 bit result.
17091 + The multiplication of [al]x[bl] is discarded.
17092 + Operands in [ah], [al], [bh], [bl].
17093 + Scratch registers in [sh], [sl].
17094 + Returns results in registers [rh], [rl].*/
17095 +.macro mul_approx_df ah, al, bh, bl, rh, rl, sh, sl
17096 + mulu.d \sl, \ah, \bl
17097 + macu.d \sl, \al, \bh
17098 + mulu.d \rl, \ah, \bh
17099 + add \rl, \sh
17100 + acr \rh
17101 +.endm
17102 +
17103 +
17104 +
17105 +#if defined(L_avr32_f64_mul) || defined(L_avr32_f64_mul_fast)
17106 + .align 2
17107 +#if defined(L_avr32_f64_mul)
17108 + .global __avr32_f64_mul
17109 + .type __avr32_f64_mul,@function
17110 +__avr32_f64_mul:
17111 +#else
17112 + .global __avr32_f64_mul_fast
17113 + .type __avr32_f64_mul_fast,@function
17114 +__avr32_f64_mul_fast:
17115 +#endif
17116 + or r12, r10, r11 << 1
17117 + breq __avr32_f64_mul_op1_zero
17118 +
17119 +#if defined(L_avr32_f64_mul)
17120 + pushm r4-r7, lr
17121 +#else
17122 + stm --sp, r5,r6,r7,lr
17123 +#endif
17124 +
17125 +#define AVR32_F64_MUL_OP1_INT_BITS 1
17126 +#define AVR32_F64_MUL_OP2_INT_BITS 10
17127 +#define AVR32_F64_MUL_RES_INT_BITS 11
17128 +
17129 + /* op1 in {r11,r10}*/
17130 + /* op2 in {r9,r8}*/
17131 + eor lr, r11, r9 /* MSB(lr) = Sign(op1) ^ Sign(op2) */
17132 +
17133 + /* Unpack op1 to 1.63 format*/
17134 + /* exp: r7 */
17135 + /* sf: r11, r10 */
17136 + bfextu r7, r11, 20, 11 /* Extract exponent */
17137 +
17138 + mov r5, 1
17139 +
17140 + /* Check if normalization is needed */
17141 + breq __avr32_f64_mul_op1_subnormal /*If number is subnormal, normalize it */
17142 +
17143 + lsl r11, (12-AVR32_F64_MUL_OP1_INT_BITS-1) /* Extract mantissa, leave room for implicit bit */
17144 + or r11, r11, r10>>(32-(12-AVR32_F64_MUL_OP1_INT_BITS-1))
17145 + lsl r10, (12-AVR32_F64_MUL_OP1_INT_BITS-1)
17146 + bfins r11, r5, 32 - (1 + AVR32_F64_MUL_OP1_INT_BITS), 1 + AVR32_F64_MUL_OP1_INT_BITS /* Insert implicit bit */
17147 +
17148 +
17149 +22:
17150 + /* Unpack op2 to 10.54 format */
17151 + /* exp: r6 */
17152 + /* sf: r9, r8 */
17153 + bfextu r6, r9, 20, 11 /* Extract exponent */
17154 +
17155 + /* Check if normalization is needed */
17156 + breq __avr32_f64_mul_op2_subnormal /*If number is subnormal, normalize it */
17157 +
17158 + lsl r8, 1 /* Extract mantissa, leave room for implicit bit */
17159 + rol r9
17160 + bfins r9, r5, 32 - (1 + AVR32_F64_MUL_OP2_INT_BITS), 1 + AVR32_F64_MUL_OP2_INT_BITS /* Insert implicit bit */
17161 +
17162 +23:
17163 +
17164 + /* Check if any operands are NaN or INF */
17165 + cp r7, 0x7ff
17166 + breq __avr32_f64_mul_op_nan_or_inf /* Check op1 for NaN or Inf */
17167 + cp r6, 0x7ff
17168 + breq __avr32_f64_mul_op_nan_or_inf /* Check op2 for NaN or Inf */
17169 +
17170 +
17171 + /* Calculate new exponent in r12*/
17172 + add r12, r7, r6
17173 + sub r12, (1023-1)
17174 +
17175 +#if defined(L_avr32_f64_mul)
17176 + /* Do the multiplication.
17177 + Place result in [r11, r10, r7, r6]. The result is in 11.117 format. */
17178 + mulu.d r4, r11, r8
17179 + macu.d r4, r10, r9
17180 + mulu.d r6, r10, r8
17181 + mulu.d r10, r11, r9
17182 + add r7, r4
17183 + adc r10, r10, r5
17184 + acr r11
17185 +#else
17186 + /* Do the multiplication using approximate calculation. discard the al x bl
17187 + calculation.
17188 + Place result in [r11, r10, r7]. The result is in 11.85 format. */
17189 +
17190 + /* Do the multiplication using approximate calculation.
17191 + Place result in r11, r10. Use r7, r6 as scratch registers */
17192 + mulu.d r6, r11, r8
17193 + macu.d r6, r10, r9
17194 + mulu.d r10, r11, r9
17195 + add r10, r7
17196 + acr r11
17197 +#endif
17198 + /* Adjust exponent and mantissa */
17199 + /* [r12]:exp, [r11, r10]:mant [r7, r6]:sticky bits */
17200 + /* Mantissa may be of the format 00000000000.0xxx or 00000000000.1xxx. */
17201 + /* In the first case, shift one pos to left.*/
17202 + bld r11, 32-AVR32_F64_MUL_RES_INT_BITS-1
17203 + breq 0f
17204 + lsl r7, 1
17205 + rol r10
17206 + rol r11
17207 + sub r12, 1
17208 +0:
17209 + cp r12, 0
17210 + brle __avr32_f64_mul_res_subnormal /*Result was subnormal.*/
17211 +
17212 + /* Check for Inf. */
17213 + cp.w r12, 0x7ff
17214 + brge __avr32_f64_mul_res_inf
17215 +
17216 + /* Insert exponent. */
17217 + bfins r11, r12, 20, 11
17218 +
17219 + /* Result was not subnormal. Perform rounding. */
17220 + /* For the fast version we discard the sticky bits and always round
17221 + the halfwaycase up. */
17222 +24:
17223 +#if defined(L_avr32_f64_mul)
17224 + or r6, r6, r10 << 31 /* Or in parity bit into stickybits */
17225 + or r7, r7, r6 >> 1 /* Or together sticky and still make the msb
17226 + of r7 represent the halfway bit. */
17227 + eorh r7, 0x8000 /* Toggle halfway bit. */
17228 + /* We should now round up by adding one for the following cases:
17229 +
17230 + halfway sticky|parity round-up
17231 + 0 x no
17232 + 1 0 no
17233 + 1 1 yes
17234 +
17235 + Since we have inverted the halfway bit we can use the satu instruction
17236 + by saturating to 1 bit to implement this.
17237 + */
17238 + satu r7 >> 0, 1
17239 +#else
17240 + lsr r7, 31
17241 +#endif
17242 + add r10, r7
17243 + acr r11
17244 +
17245 + /* Insert sign bit*/
17246 + bld lr, 31
17247 + bst r11, 31
17248 +
17249 + /* Return result in [r11,r10] */
17250 +#if defined(L_avr32_f64_mul)
17251 + popm r4-r7, pc
17252 +#else
17253 + ldm sp++, r5, r6, r7,pc
17254 +#endif
17255 +
17256 +
17257 +__avr32_f64_mul_op1_subnormal:
17258 + andh r11, 0x000f /* Remove sign bit and exponent */
17259 + clz r12, r10 /* Count leading zeros in lsw */
17260 + clz r6, r11 /* Count leading zeros in msw */
17261 + subcs r12, -32 + AVR32_F64_MUL_OP1_INT_BITS
17262 + movcs r6, r12
17263 + subcc r6, AVR32_F64_MUL_OP1_INT_BITS
17264 + cp.w r6, 32
17265 + brge 0f
17266 +
17267 + /* shifting involves both msw and lsw*/
17268 + rsub r12, r6, 32 /* shift mantissa */
17269 + lsl r11, r11, r6
17270 + lsr r12, r10, r12
17271 + or r11, r12
17272 + lsl r10, r10, r6
17273 + sub r6, 12-AVR32_F64_MUL_OP1_INT_BITS
17274 + sub r7, r6 /* adjust exponent */
17275 + rjmp 22b /* Finished */
17276 +0:
17277 + /* msw is zero so only need to consider lsw */
17278 + lsl r11, r10, r6
17279 + breq __avr32_f64_mul_res_zero
17280 + mov r10, 0
17281 + sub r6, 12-AVR32_F64_MUL_OP1_INT_BITS
17282 + sub r7, r6 /* adjust exponent */
17283 + rjmp 22b
17284 +
17285 +
17286 +__avr32_f64_mul_op2_subnormal:
17287 + andh r9, 0x000f /* Remove sign bit and exponent */
17288 + clz r12, r8 /* Count leading zeros in lsw */
17289 + clz r5, r9 /* Count leading zeros in msw */
17290 + subcs r12, -32 + AVR32_F64_MUL_OP2_INT_BITS
17291 + movcs r5, r12
17292 + subcc r5, AVR32_F64_MUL_OP2_INT_BITS
17293 + cp.w r5, 32
17294 + brge 0f
17295 +
17296 + /* shifting involves both msw and lsw*/
17297 + rsub r12, r5, 32 /* shift mantissa */
17298 + lsl r9, r9, r5
17299 + lsr r12, r8, r12
17300 + or r9, r12
17301 + lsl r8, r8, r5
17302 + sub r5, 12 - AVR32_F64_MUL_OP2_INT_BITS
17303 + sub r6, r5 /* adjust exponent */
17304 + rjmp 23b /* Finished */
17305 +0:
17306 + /* msw is zero so only need to consider lsw */
17307 + lsl r9, r8, r5
17308 + breq __avr32_f64_mul_res_zero
17309 + mov r8, 0
17310 + sub r5, 12 - AVR32_F64_MUL_OP2_INT_BITS
17311 + sub r6, r5 /* adjust exponent */
17312 + rjmp 23b
17313 +
17314 +
17315 +__avr32_f64_mul_op_nan_or_inf:
17316 + /* Same code for OP1 and OP2*/
17317 + /* Since we are here, at least one of the OPs were NaN or INF*/
17318 + andh r9, 0x000f /* Remove sign bit and exponent */
17319 + andh r11, 0x000f /* Remove sign bit and exponent */
17320 + /* Merge the regs in each operand to check for zero*/
17321 + or r11, r10 /* op1 */
17322 + or r9, r8 /* op2 */
17323 + /* Check if op1 is NaN or INF */
17324 + cp r7, 0x7ff
17325 + brne __avr32_f64_mul_op1_not_naninf
17326 + /* op1 was NaN or INF.*/
17327 + cp r11, 0
17328 + brne __avr32_f64_mul_res_nan /* op1 was NaN. Result will be NaN*/
17329 + /*op1 was INF. check if op2 is NaN or INF*/
17330 + cp r6, 0x7ff
17331 + brne __avr32_f64_mul_res_inf /*op1 was INF, op2 was neither NaN nor INF*/
17332 + /* op1 is INF, op2 is either NaN or INF*/
17333 + cp r9, 0
17334 + breq __avr32_f64_mul_res_inf /*op2 was also INF*/
17335 + rjmp __avr32_f64_mul_res_nan /*op2 was NaN*/
17336 +
17337 +__avr32_f64_mul_op1_not_naninf:
17338 + /* op1 was not NaN nor INF. Then op2 must be NaN or INF*/
17339 + cp r9, 0
17340 + breq __avr32_f64_mul_res_inf /*op2 was INF, return INF*/
17341 + rjmp __avr32_f64_mul_res_nan /*else return NaN*/
17342 +
17343 +__avr32_f64_mul_res_subnormal:/* Multiply result was subnormal. */
17344 +#if defined(L_avr32_f64_mul)
17345 + /* Check how much we must scale down the mantissa. */
17346 + neg r12
17347 + sub r12, -1 /* We do no longer have an implicit bit. */
17348 + satu r12 >> 0, 6 /* Saturate shift amount to max 63. */
17349 + cp.w r12, 32
17350 + brge 0f
17351 + /* Shift amount <32 */
17352 + rsub r8, r12, 32
17353 + or r6, r7
17354 + lsr r7, r7, r12
17355 + lsl r9, r10, r8
17356 + or r7, r9
17357 + lsr r10, r10, r12
17358 + lsl r9, r11, r8
17359 + or r10, r9
17360 + lsr r11, r11, r12
17361 + rjmp 24b
17362 +0:
17363 + /* Shift amount >=32 */
17364 + rsub r8, r12, 32
17365 + moveq r9, 0
17366 + breq 0f
17367 + lsl r9, r11, r8
17368 +0:
17369 + or r6, r7
17370 + or r6, r6, r10 << 1
17371 + lsr r10, r10, r12
17372 + or r7, r9, r10
17373 + lsr r10, r11, r12
17374 + mov r11, 0
17375 + rjmp 24b
17376 +#else
17377 + /* Flush to zero for the fast version. */
17378 + mov r11, lr /*Get correct sign*/
17379 + andh r11, 0x8000, COH
17380 + mov r10, 0
17381 + ldm sp++, r5, r6, r7,pc
17382 +#endif
17383 +
17384 +__avr32_f64_mul_res_zero:/* Multiply result is zero. */
17385 + mov r11, lr /*Get correct sign*/
17386 + andh r11, 0x8000, COH
17387 + mov r10, 0
17388 +#if defined(L_avr32_f64_mul)
17389 + popm r4-r7, pc
17390 +#else
17391 + ldm sp++, r5, r6, r7,pc
17392 +#endif
17393 +
17394 +__avr32_f64_mul_res_nan: /* Return NaN. */
17395 + mov r11, -1
17396 + mov r10, -1
17397 +#if defined(L_avr32_f64_mul)
17398 + popm r4-r7, pc
17399 +#else
17400 + ldm sp++, r5, r6, r7,pc
17401 +#endif
17402 +
17403 +__avr32_f64_mul_res_inf: /* Return INF. */
17404 + mov r11, 0xfff00000
17405 + bld lr, 31
17406 + bst r11, 31
17407 + mov r10, 0
17408 +#if defined(L_avr32_f64_mul)
17409 + popm r4-r7, pc
17410 +#else
17411 + ldm sp++, r5, r6, r7,pc
17412 +#endif
17413 +
17414 +__avr32_f64_mul_op1_zero:
17415 + /* Get sign */
17416 + eor r11, r11, r9
17417 + andh r11, 0x8000, COH
17418 + /* Check if op2 is Inf or NaN. */
17419 + bfextu r12, r9, 20, 11
17420 + cp.w r12, 0x7ff
17421 + retne r12 /* Return 0.0 */
17422 + /* Return NaN */
17423 + mov r10, -1
17424 + mov r11, -1
17425 + ret r12
17426 +
17427 +
17428 +
17429 +#endif
17430 +
17431 +
17432 +#if defined(L_avr32_f64_addsub) || defined(L_avr32_f64_addsub_fast)
17433 + .align 2
17434 +
17435 +__avr32_f64_sub_from_add:
17436 + /* Switch sign on op2 */
17437 + eorh r9, 0x8000
17438 +
17439 +#if defined(L_avr32_f64_addsub_fast)
17440 + .global __avr32_f64_sub_fast
17441 + .type __avr32_f64_sub_fast,@function
17442 +__avr32_f64_sub_fast:
17443 +#else
17444 + .global __avr32_f64_sub
17445 + .type __avr32_f64_sub,@function
17446 +__avr32_f64_sub:
17447 +#endif
17448 +
17449 + /* op1 in {r11,r10}*/
17450 + /* op2 in {r9,r8}*/
17451 +
17452 +#if defined(L_avr32_f64_addsub_fast)
17453 + /* If op2 is zero just return op1 */
17454 + or r12, r8, r9 << 1
17455 + reteq r12
17456 +#endif
17457 +
17458 + /* Check signs */
17459 + eor r12, r11, r9
17460 + /* Different signs, use addition. */
17461 + brmi __avr32_f64_add_from_sub
17462 +
17463 + stm --sp, r5, r6, r7, lr
17464 +
17465 + /* Get sign of op1 into r12 */
17466 + mov r12, r11
17467 + andh r12, 0x8000, COH
17468 +
17469 + /* Remove sign from operands */
17470 + cbr r11, 31
17471 + cbr r9, 31
17472 +
17473 + /* Put the largest number in [r11, r10]
17474 + and the smallest number in [r9, r8] */
17475 + cp r10, r8
17476 + cpc r11, r9
17477 + brhs 1f /* Skip swap if operands already correctly ordered*/
17478 + /* Operands were not correctly ordered, swap them*/
17479 + mov r7, r11
17480 + mov r11, r9
17481 + mov r9, r7
17482 + mov r7, r10
17483 + mov r10, r8
17484 + mov r8, r7
17485 + eorh r12, 0x8000 /* Invert sign in r12*/
17486 +1:
17487 + /* Unpack largest operand - opH */
17488 + /* exp: r7 */
17489 + /* sf: r11, r10 */
17490 + lsr r7, r11, 20 /* Extract exponent */
17491 + lsl r11, 11 /* Extract mantissa, leave room for implicit bit */
17492 + or r11, r11, r10>>21
17493 + lsl r10, 11
17494 + sbr r11, 31 /* Insert implicit bit */
17495 +
17496 +
17497 + /* Unpack smallest operand - opL */
17498 + /* exp: r6 */
17499 + /* sf: r9, r8 */
17500 + lsr r6, r9, 20 /* Extract exponent */
17501 + breq __avr32_f64_sub_opL_subnormal /* If either zero or subnormal */
17502 + lsl r9, 11 /* Extract mantissa, leave room for implicit bit */
17503 + or r9, r9, r8>>21
17504 + lsl r8, 11
17505 + sbr r9, 31 /* Insert implicit bit */
17506 +
17507 +
17508 +__avr32_f64_sub_opL_subnormal_done:
17509 + /* opH is NaN or Inf. */
17510 + cp.w r7, 0x7ff
17511 + breq __avr32_f64_sub_opH_nan_or_inf
17512 +
17513 + /* Get shift amount to scale mantissa of op2. */
17514 + rsub r6, r7
17515 + breq __avr32_f64_sub_shift_done /* No need to shift, exponents are equal*/
17516 +
17517 + /* Scale mantissa [r9, r8] with amount [r6].
17518 + Uses scratch registers [r5] and [lr].
17519 + In IEEE mode:Must not forget the sticky bits we intend to shift out. */
17520 +
17521 + rsub r5,r6,32 /* get (32 - shift count)
17522 + (if shift count > 32 we get a
17523 + negative value, but that will
17524 + work as well in the code below.) */
17525 +
17526 + cp.w r6,32 /* handle shifts >= 32 separately */
17527 + brhs __avr32_f64_sub_longshift
17528 +
17529 + /* small (<32) shift amount, both words are part of the shift
17530 + first remember whether part that is lost contains any 1 bits ... */
17531 + lsl lr,r8,r5 /* shift away bits that are part of
17532 + final mantissa. only part that goes
17533 + to lr are bits that will be lost */
17534 +
17535 + /* ... and now to the actual shift */
17536 + lsl r5,r9,r5 /* get bits from msw destined for lsw*/
17537 + lsr r8,r8,r6 /* shift down lsw of mantissa */
17538 + lsr r9,r9,r6 /* shift down msw of mantissa */
17539 + or r8,r5 /* combine these bits with prepared lsw*/
17540 +#if defined(L_avr32_f64_addsub)
17541 + cp.w lr,0 /* if any '1' bit in part we lost ...*/
17542 + srne lr
17543 + or r8, lr /* ... we need to set sticky bit*/
17544 +#endif
17545 +
17546 +__avr32_f64_sub_shift_done:
17547 + /* Now subtract the mantissas. */
17548 + sub r10, r8
17549 + sbc r11, r11, r9
17550 +
17551 + /* Normalize the exponent and mantissa pair stored in
17552 + [r11,r10] and exponent in [r7]. Needs two scratch registers [r6] and [lr]. */
17553 + clz r6,r11 /* Check if we have zeros in high bits */
17554 + breq __avr32_f64_sub_longnormalize_done /* No need for scaling if no zeros in high bits */
17555 + brcs __avr32_f64_sub_longnormalize
17556 +
17557 +
17558 + /* shift amount is smaller than 32, and involves both msw and lsw*/
17559 + rsub lr,r6,32 /* shift mantissa */
17560 + lsl r11,r11,r6
17561 + lsr lr,r10,lr
17562 + or r11,lr
17563 + lsl r10,r10,r6
17564 +
17565 + sub r7,r6 /* adjust exponent */
17566 + brle __avr32_f64_sub_subnormal_result
17567 +__avr32_f64_sub_longnormalize_done:
17568 +
17569 +#if defined(L_avr32_f64_addsub)
17570 + /* Insert the bits we will remove from the mantissa r9[31:21] */
17571 + lsl r9, r10, (32 - 11)
17572 +#else
17573 + /* Keep the last bit shifted out. */
17574 + bfextu r9, r10, 10, 1
17575 +#endif
17576 +
17577 + /* Pack final result*/
17578 + /* Input: [r7]:exp, [r11, r10]:mant, [r12]:sign in MSB */
17579 + /* Result in [r11,r10] */
17580 + /* Insert mantissa */
17581 + lsr r10, 11
17582 + or r10, r10, r11<<21
17583 + lsr r11, 11
17584 + /* Insert exponent and sign bit*/
17585 + bfins r11, r7, 20, 11
17586 + or r11, r12
17587 +
17588 + /* Round */
17589 +__avr32_f64_sub_round:
17590 +#if defined(L_avr32_f64_addsub)
17591 + mov_imm r7, 0x80000000
17592 + bld r10, 0
17593 + subne r7, -1
17594 +
17595 + cp.w r9, r7
17596 + srhs r9
17597 +#endif
17598 + add r10, r9
17599 + acr r11
17600 +
17601 + /* Return result in [r11,r10] */
17602 + ldm sp++, r5, r6, r7,pc
17603 +
17604 +
17605 +
17606 +__avr32_f64_sub_opL_subnormal:
17607 + /* Extract the of mantissa */
17608 + lsl r9, 11 /* Extract mantissa, leave room for implicit bit */
17609 + or r9, r9, r8>>21
17610 + lsl r8, 11
17611 +
17612 + /* Set exponent to 1 if we do not have a zero. */
17613 + or lr, r9, r8
17614 + movne r6,1
17615 +
17616 + /* Check if opH is also subnormal. If so, clear implicit bit in r11*/
17617 + rsub lr, r7, 0
17618 + moveq r7,1
17619 + bst r11, 31
17620 +
17621 + /* Check if op1 is zero, if so set exponent to 0. */
17622 + or lr, r11, r10
17623 + moveq r7,0
17624 +
17625 + rjmp __avr32_f64_sub_opL_subnormal_done
17626 +
17627 +__avr32_f64_sub_opH_nan_or_inf:
17628 + /* Check if opH is NaN, if so return NaN */
17629 + cbr r11, 31
17630 + or lr, r11, r10
17631 + brne __avr32_f64_sub_return_nan
17632 +
17633 + /* opH is Inf. */
17634 + /* Check if opL is Inf. or NaN */
17635 + cp.w r6, 0x7ff
17636 + breq __avr32_f64_sub_return_nan
17637 + /* Return infinity with correct sign. */
17638 + or r11, r12, r7 << 20
17639 + ldm sp++, r5, r6, r7, pc/* opL not Inf or NaN, return opH */
17640 +__avr32_f64_sub_return_nan:
17641 + mov r10, -1 /* Generate NaN in r11, r10 */
17642 + mov r11, -1
17643 + ldm sp++, r5, r6, r7, pc/* opL Inf or NaN, return NaN */
17644 +
17645 +
17646 +__avr32_f64_sub_subnormal_result:
17647 +#if defined(L_avr32_f64_addsub)
17648 + /* Check how much we must scale down the mantissa. */
17649 + neg r7
17650 + sub r7, -1 /* We do no longer have an implicit bit. */
17651 + satu r7 >> 0, 6 /* Saturate shift amount to max 63. */
17652 + cp.w r7, 32
17653 + brge 0f
17654 + /* Shift amount <32 */
17655 + rsub r8, r7, 32
17656 + lsl r9, r10, r8
17657 + srne r6
17658 + lsr r10, r10, r7
17659 + or r10, r6 /* Sticky bit from the
17660 + part that was shifted out. */
17661 + lsl r9, r11, r8
17662 + or r10, r10, r9
17663 + lsr r11, r10, r7
17664 + /* Set exponent */
17665 + mov r7, 0
17666 + rjmp __avr32_f64_sub_longnormalize_done
17667 +0:
17668 + /* Shift amount >=32 */
17669 + rsub r8, r7, 64
17670 + lsl r9, r11, r8
17671 + or r9, r10
17672 + srne r6
17673 + lsr r10, r11, r7
17674 + or r10, r6 /* Sticky bit from the
17675 + part that was shifted out. */
17676 + mov r11, 0
17677 + /* Set exponent */
17678 + mov r7, 0
17679 + rjmp __avr32_f64_sub_longnormalize_done
17680 +#else
17681 + /* Just flush subnormals to zero. */
17682 + mov r10, 0
17683 + mov r11, 0
17684 +#endif
17685 + ldm sp++, r5, r6, r7, pc
17686 +
17687 +__avr32_f64_sub_longshift:
17688 + /* large (>=32) shift amount, only lsw will have bits left after shift.
17689 + note that shift operations will use ((shift count=r6) mod 32) so
17690 + we do not need to subtract 32 from shift count. */
17691 + /* Saturate the shift amount to 63. If the amount
17692 + is any larger op2 is insignificant. */
17693 + satu r6 >> 0, 6
17694 +
17695 +#if defined(L_avr32_f64_addsub)
17696 + /* first remember whether part that is lost contains any 1 bits ... */
17697 + moveq lr, r8 /* If shift amount is 32, no bits from msw are lost. */
17698 + breq 0f
17699 + lsl lr,r9,r5 /* save all lost bits from msw */
17700 + or lr,r8 /* also save lost bits (all) from lsw
17701 + now lr != 0 if we lose any bits */
17702 +#endif
17703 +0:
17704 + /* ... and now to the actual shift */
17705 + lsr r8,r9,r6 /* Move msw to lsw and shift. */
17706 + mov r9,0 /* clear msw */
17707 +#if defined(L_avr32_f64_addsub)
17708 + cp.w lr,0 /* if any '1' bit in part we lost ...*/
17709 + srne lr
17710 + or r8, lr /* ... we need to set sticky bit*/
17711 +#endif
17712 + rjmp __avr32_f64_sub_shift_done
17713 +
17714 +__avr32_f64_sub_longnormalize:
17715 + /* shift amount is greater than 32 */
17716 + clz r6,r10 /* shift mantissa */
17717 + /* If the resulting mantissa is zero the result is
17718 + zero so force exponent to zero. */
17719 + movcs r7, 0
17720 + movcs r6, 0
17721 + movcs r12, 0 /* Also clear sign bit. A zero result from subtraction
17722 + always is +0.0 */
17723 + subcc r6,-32
17724 + lsl r11,r10,r6
17725 + mov r10,0
17726 + sub r7,r6 /* adjust exponent */
17727 + brle __avr32_f64_sub_subnormal_result
17728 + rjmp __avr32_f64_sub_longnormalize_done
17729 +
17730 +
17731 +
17732 + .align 2
17733 +__avr32_f64_add_from_sub:
17734 + /* Switch sign on op2 */
17735 + eorh r9, 0x8000
17736 +
17737 +#if defined(L_avr32_f64_addsub_fast)
17738 + .global __avr32_f64_add_fast
17739 + .type __avr32_f64_add_fast,@function
17740 +__avr32_f64_add_fast:
17741 +#else
17742 + .global __avr32_f64_add
17743 + .type __avr32_f64_add,@function
17744 +__avr32_f64_add:
17745 +#endif
17746 +
17747 + /* op1 in {r11,r10}*/
17748 + /* op2 in {r9,r8}*/
17749 +
17750 +#if defined(L_avr32_f64_addsub_fast)
17751 + /* If op2 is zero just return op1 */
17752 + or r12, r8, r9 << 1
17753 + reteq r12
17754 +#endif
17755 +
17756 + /* Check signs */
17757 + eor r12, r11, r9
17758 + /* Different signs, use subtraction. */
17759 + brmi __avr32_f64_sub_from_add
17760 +
17761 + stm --sp, r5, r6, r7, lr
17762 +
17763 + /* Get sign of op1 into r12 */
17764 + mov r12, r11
17765 + andh r12, 0x8000, COH
17766 +
17767 + /* Remove sign from operands */
17768 + cbr r11, 31
17769 + cbr r9, 31
17770 +
17771 + /* Put the number with the largest exponent in [r11, r10]
17772 + and the number with the smallest exponent in [r9, r8] */
17773 + cp r11, r9
17774 + brhs 1f /* Skip swap if operands already correctly ordered */
17775 + /* Operands were not correctly ordered, swap them */
17776 + mov r7, r11
17777 + mov r11, r9
17778 + mov r9, r7
17779 + mov r7, r10
17780 + mov r10, r8
17781 + mov r8, r7
17782 +1:
17783 + mov lr, 0 /* Set sticky bits to zero */
17784 + /* Unpack largest operand - opH */
17785 + /* exp: r7 */
17786 + /* sf: r11, r10 */
17787 + bfextu R7, R11, 20, 11 /* Extract exponent */
17788 + bfextu r11, r11, 0, 20 /* Extract mantissa */
17789 + sbr r11, 20 /* Insert implicit bit */
17790 +
17791 + /* Unpack smallest operand - opL */
17792 + /* exp: r6 */
17793 + /* sf: r9, r8 */
17794 + bfextu R6, R9, 20, 11 /* Extract exponent */
17795 + breq __avr32_f64_add_op2_subnormal
17796 + bfextu r9, r9, 0, 20 /* Extract mantissa */
17797 + sbr r9, 20 /* Insert implicit bit */
17798 +
17799 +2:
17800 + /* opH is NaN or Inf. */
17801 + cp.w r7, 0x7ff
17802 + breq __avr32_f64_add_opH_nan_or_inf
17803 +
17804 + /* Get shift amount to scale mantissa of op2. */
17805 + rsub r6, r7
17806 + breq __avr32_f64_add_shift_done /* No need to shift, exponents are equal*/
17807 +
17808 + /* Scale mantissa [r9, r8] with amount [r6].
17809 + Uses scratch registers [r5] and [lr].
17810 + In IEEE mode:Must not forget the sticky bits we intend to shift out. */
17811 + rsub r5,r6,32 /* get (32 - shift count)
17812 + (if shift count > 32 we get a
17813 + negative value, but that will
17814 + work as well in the code below.) */
17815 +
17816 + cp.w r6,32 /* handle shifts >= 32 separately */
17817 + brhs __avr32_f64_add_longshift
17818 +
17819 + /* small (<32) shift amount, both words are part of the shift
17820 + first remember whether part that is lost contains any 1 bits ... */
17821 + lsl lr,r8,r5 /* shift away bits that are part of
17822 + final mantissa. only part that goes
17823 + to lr are bits that will be lost */
17824 +
17825 + /* ... and now to the actual shift */
17826 + lsl r5,r9,r5 /* get bits from msw destined for lsw*/
17827 + lsr r8,r8,r6 /* shift down lsw of mantissa */
17828 + lsr r9,r9,r6 /* shift down msw of mantissa */
17829 + or r8,r5 /* combine these bits with prepared lsw*/
17830 +
17831 +__avr32_f64_add_shift_done:
17832 + /* Now add the mantissas. */
17833 + add r10, r8
17834 + adc r11, r11, r9
17835 +
17836 + /* Check if we overflowed. */
17837 + bld r11, 21
17838 + breq __avr32_f64_add_res_of:
17839 +
17840 +__avr32_f64_add_res_of_done:
17841 +
17842 + /* Pack final result*/
17843 + /* Input: [r7]:exp, [r11, r10]:mant, [r12]:sign in MSB */
17844 + /* Result in [r11,r10] */
17845 + /* Insert exponent and sign bit*/
17846 + bfins r11, r7, 20, 11
17847 + or r11, r12
17848 +
17849 + /* Round */
17850 +__avr32_f64_add_round:
17851 +#if defined(L_avr32_f64_addsub)
17852 + bfextu r12, r10, 0, 1 /* Extract parity bit.*/
17853 + or lr, r12 /* or it together with the sticky bits. */
17854 + eorh lr, 0x8000 /* Toggle round bit. */
17855 + /* We should now round up by adding one for the following cases:
17856 +
17857 + halfway sticky|parity round-up
17858 + 0 x no
17859 + 1 0 no
17860 + 1 1 yes
17861 +
17862 + Since we have inverted the halfway bit we can use the satu instruction
17863 + by saturating to 1 bit to implement this.
17864 + */
17865 + satu lr >> 0, 1
17866 +#else
17867 + lsr lr, 31
17868 +#endif
17869 + add r10, lr
17870 + acr r11
17871 +
17872 + /* Return result in [r11,r10] */
17873 + ldm sp++, r5, r6, r7,pc
17874 +
17875 +
17876 +__avr32_f64_add_opH_nan_or_inf:
17877 + /* Check if opH is NaN, if so return NaN */
17878 + cbr r11, 20
17879 + or lr, r11, r10
17880 + brne __avr32_f64_add_return_nan
17881 +
17882 + /* opH is Inf. */
17883 + /* Check if opL is Inf. or NaN */
17884 + cp.w r6, 0x7ff
17885 + breq __avr32_f64_add_opL_nan_or_inf
17886 + ldm sp++, r5, r6, r7, pc/* opL not Inf or NaN, return opH */
17887 +__avr32_f64_add_opL_nan_or_inf:
17888 + cbr r9, 20
17889 + or lr, r9, r8
17890 + brne __avr32_f64_add_return_nan
17891 + mov r10, 0 /* Generate Inf in r11, r10 */
17892 + mov_imm r11, 0x7ff00000
17893 + or r11, r12 /* Put sign bit back */
17894 + ldm sp++, r5, r6, r7, pc/* opL Inf, return Inf */
17895 +__avr32_f64_add_return_nan:
17896 + mov r10, -1 /* Generate NaN in r11, r10 */
17897 + mov r11, -1
17898 + ldm sp++, r5, r6, r7, pc/* opL Inf or NaN, return NaN */
17899 +
17900 +
17901 +__avr32_f64_add_longshift:
17902 + /* large (>=32) shift amount, only lsw will have bits left after shift.
17903 + note that shift operations will use ((shift count=r6) mod 32) so
17904 + we do not need to subtract 32 from shift count. */
17905 + /* Saturate the shift amount to 63. If the amount
17906 + is any larger op2 is insignificant. */
17907 + satu r6 >> 0, 6
17908 + /* If shift amount is 32 there are no bits from the msw that are lost. */
17909 + moveq lr, r8
17910 + breq 0f
17911 + /* first remember whether part that is lost contains any 1 bits ... */
17912 + lsl lr,r9,r5 /* save all lost bits from msw */
17913 +#if defined(L_avr32_f64_addsub)
17914 + cp.w r8, 0
17915 + srne r8
17916 + or lr,r8 /* also save lost bits (all) from lsw
17917 + now lr != 0 if we lose any bits */
17918 +#endif
17919 +0:
17920 + /* ... and now to the actual shift */
17921 + lsr r8,r9,r6 /* msw -> lsw and make rest of shift inside lsw*/
17922 + mov r9,0 /* clear msw */
17923 + rjmp __avr32_f64_add_shift_done
17924 +
17925 +__avr32_f64_add_res_of:
17926 + /* We overflowed. Scale down mantissa by shifting right one position. */
17927 + or lr, lr, lr << 1 /* Remember stickybits*/
17928 + lsr r11, 1
17929 + ror r10
17930 + ror lr
17931 + sub r7, -1 /* Increment exponent */
17932 +
17933 + /* Clear mantissa to set result to Inf if the exponent is 255. */
17934 + cp.w r7, 0x7ff
17935 + moveq r10, 0
17936 + moveq r11, 0
17937 + moveq lr, 0
17938 + rjmp __avr32_f64_add_res_of_done
17939 +
17940 +__avr32_f64_add_op2_subnormal:
17941 + /* Set epxponent to 1 */
17942 + mov r6, 1
17943 +
17944 + /* Check if op2 is also subnormal. */
17945 + cp.w r7, 0
17946 + brne 2b
17947 +
17948 + cbr r11, 20
17949 + /* Both operands are subnormal. Just addd the mantissas
17950 + and the exponent will automatically be set to 1 if
17951 + we overflow into a normal number. */
17952 + add r10, r8
17953 + adc r11, r11, r9
17954 +
17955 + /* Add sign bit */
17956 + or r11, r12
17957 +
17958 + /* Return result in [r11,r10] */
17959 + ldm sp++, r5, r6, r7,pc
17960 +
17961 +
17962 +
17963 +#endif
17964 +
17965 +#ifdef L_avr32_f64_to_u32
17966 + /* This goes into L_fixdfsi */
17967 +#endif
17968 +
17969 +
17970 +#ifdef L_avr32_f64_to_s32
17971 + .global __avr32_f64_to_u32
17972 + .type __avr32_f64_to_u32,@function
17973 +__avr32_f64_to_u32:
17974 + cp.w r11, 0
17975 + retmi 0 /* Negative returns 0 */
17976 +
17977 + /* Fallthrough to df to signed si conversion */
17978 + .global __avr32_f64_to_s32
17979 + .type __avr32_f64_to_s32,@function
17980 +__avr32_f64_to_s32:
17981 + lsl r12,r11,1
17982 + lsr r12,21 /* extract exponent*/
17983 + sub r12,1023 /* convert to unbiased exponent.*/
17984 + retlo 0 /* too small exponent implies zero. */
17985 +
17986 +1:
17987 + rsub r12,r12,31 /* shift count = 31 - exponent */
17988 + mov r9,r11 /* save sign for later...*/
17989 + lsl r11,11 /* remove exponent and sign*/
17990 + sbr r11,31 /* add implicit bit*/
17991 + or r11,r11,r10>>21 /* get rest of bits from lsw of double */
17992 + lsr r11,r11,r12 /* shift down mantissa to final place */
17993 + lsl r9,1 /* sign -> carry */
17994 + retcc r11 /* if positive, we are done */
17995 + neg r11 /* if negative float, negate result */
17996 + ret r11
17997 +
17998 +#endif /* L_fixdfsi*/
17999 +
18000 +#ifdef L_avr32_f64_to_u64
18001 + /* Actual function is in L_fixdfdi */
18002 +#endif
18003 +
18004 +#ifdef L_avr32_f64_to_s64
18005 + .global __avr32_f64_to_u64
18006 + .type __avr32_f64_to_u64,@function
18007 +__avr32_f64_to_u64:
18008 + cp.w r11,0
18009 + /* Negative numbers return zero */
18010 + movmi r10, 0
18011 + movmi r11, 0
18012 + retmi r11
18013 +
18014 +
18015 +
18016 + /* Fallthrough */
18017 + .global __avr32_f64_to_s64
18018 + .type __avr32_f64_to_s64,@function
18019 +__avr32_f64_to_s64:
18020 + lsl r9,r11,1
18021 + lsr r9,21 /* get exponent*/
18022 + sub r9,1023 /* convert to correct range*/
18023 + /* Return zero if exponent to small */
18024 + movlo r10, 0
18025 + movlo r11, 0
18026 + retlo r11
18027 +
18028 + mov r8,r11 /* save sign for later...*/
18029 +1:
18030 + lsl r11,11 /* remove exponent */
18031 + sbr r11,31 /* add implicit bit*/
18032 + or r11,r11,r10>>21 /* get rest of bits from lsw of double*/
18033 + lsl r10,11 /* align lsw correctly as well */
18034 + rsub r9,r9,63 /* shift count = 63 - exponent */
18035 + breq 1f
18036 +
18037 + cp.w r9,32 /* is shift count more than one reg? */
18038 + brhs 0f
18039 +
18040 + mov r12,r11 /* save msw */
18041 + lsr r10,r10,r9 /* small shift count, shift down lsw */
18042 + lsr r11,r11,r9 /* small shift count, shift down msw */
18043 + rsub r9,r9,32 /* get 32-size of shifted out tail */
18044 + lsl r12,r12,r9 /* align part to move from msw to lsw */
18045 + or r10,r12 /* combine to get new lsw */
18046 + rjmp 1f
18047 +
18048 +0:
18049 + lsr r10,r11,r9 /* large shift count,only lsw get bits
18050 + note that shift count is modulo 32*/
18051 + mov r11,0 /* msw will be 0 */
18052 +
18053 +1:
18054 + lsl r8,1 /* sign -> carry */
18055 + retcc r11 /* if positive, we are done */
18056 +
18057 + neg r11 /* if negative float, negate result */
18058 + neg r10
18059 + scr r11
18060 + ret r11
18061 +
18062 +#endif
18063 +
18064 +#ifdef L_avr32_u32_to_f64
18065 + /* Code located in L_floatsidf */
18066 +#endif
18067 +
18068 +#ifdef L_avr32_s32_to_f64
18069 + .global __avr32_u32_to_f64
18070 + .type __avr32_u32_to_f64,@function
18071 +__avr32_u32_to_f64:
18072 + sub r11, r12, 0 /* Move to r11 and force Z flag to be updated */
18073 + mov r12, 0 /* always positive */
18074 + rjmp 0f /* Jump to common code for floatsidf */
18075 +
18076 + .global __avr32_s32_to_f64
18077 + .type __avr32_s32_to_f64,@function
18078 +__avr32_s32_to_f64:
18079 + mov r11, r12 /* Keep original value in r12 for sign */
18080 + abs r11 /* Absolute value if r12 */
18081 +0:
18082 + mov r10,0 /* let remaining bits be zero */
18083 + reteq r11 /* zero long will return zero float */
18084 +
18085 + pushm lr
18086 + mov r9,31+1023 /* set exponent */
18087 +
18088 + normalize_df r9 /*exp*/, r10, r11 /* mantissa */, r8, lr /* scratch */
18089 +
18090 + /* Check if a subnormal result was created */
18091 + cp.w r9, 0
18092 + brgt 0f
18093 +
18094 + adjust_subnormal_df r9 /* exp */, r10, r11 /* Mantissa */, r12 /*sign*/, r8, lr /* scratch */
18095 + popm pc
18096 +0:
18097 +
18098 + /* Round result */
18099 + round_df r9 /*exp*/, r10, r11 /* Mantissa */, r8 /*scratch*/
18100 + cp.w r9,0x7ff
18101 + brlt 0f
18102 + /*Return infinity */
18103 + mov r10, 0
18104 + mov_imm r11, 0xffe00000
18105 + rjmp __floatsidf_return_op1
18106 +
18107 +0:
18108 +
18109 + /* Pack */
18110 + pack_df r9 /*exp*/, r10, r11 /* mantissa */, r10, r11 /* Output df number*/
18111 +__floatsidf_return_op1:
18112 + lsl r12,1 /* shift in sign bit */
18113 + ror r11
18114 +
18115 + popm pc
18116 +#endif
18117 +
18118 +
18119 +#ifdef L_avr32_f32_cmp_eq
18120 + .global __avr32_f32_cmp_eq
18121 + .type __avr32_f32_cmp_eq,@function
18122 +__avr32_f32_cmp_eq:
18123 + cp.w r12, r11
18124 + breq 0f
18125 + /* If not equal check for +/-0 */
18126 + /* Or together the two values and shift out the sign bit.
18127 + If the result is zero, then the two values are both zero. */
18128 + or r12, r11
18129 + lsl r12, 1
18130 + reteq 1
18131 + ret 0
18132 +0:
18133 + /* Numbers were equal. Check for NaN or Inf */
18134 + mov_imm r11, 0xff000000
18135 + lsl r12, 1
18136 + cp.w r12, r11
18137 + retls 1 /* 0 if NaN, 1 otherwise */
18138 + ret 0
18139 +#endif
18140 +
18141 +#if defined(L_avr32_f32_cmp_ge) || defined(L_avr32_f32_cmp_lt)
18142 +#ifdef L_avr32_f32_cmp_ge
18143 + .global __avr32_f32_cmp_ge
18144 + .type __avr32_f32_cmp_ge,@function
18145 +__avr32_f32_cmp_ge:
18146 +#endif
18147 +#ifdef L_avr32_f32_cmp_lt
18148 + .global __avr32_f32_cmp_lt
18149 + .type __avr32_f32_cmp_lt,@function
18150 +__avr32_f32_cmp_lt:
18151 +#endif
18152 + lsl r10, r12, 1 /* Remove sign bits */
18153 + lsl r9, r11, 1
18154 + subfeq r10, 0
18155 +#ifdef L_avr32_f32_cmp_ge
18156 + reteq 1 /* Both number are zero. Return true. */
18157 +#endif
18158 +#ifdef L_avr32_f32_cmp_lt
18159 + reteq 0 /* Both number are zero. Return false. */
18160 +#endif
18161 + mov_imm r8, 0xff000000
18162 + cp.w r10, r8
18163 + rethi 0 /* Op0 is NaN */
18164 + cp.w r9, r8
18165 + rethi 0 /* Op1 is Nan */
18166 +
18167 + eor r8, r11, r12
18168 + bld r12, 31
18169 +#ifdef L_avr32_f32_cmp_ge
18170 + srcc r8 /* Set result to true if op0 is positive*/
18171 +#endif
18172 +#ifdef L_avr32_f32_cmp_lt
18173 + srcs r8 /* Set result to true if op0 is negative*/
18174 +#endif
18175 + retmi r8 /* Return if signs are different */
18176 + brcs 0f /* Both signs negative? */
18177 +
18178 + /* Both signs positive */
18179 + cp.w r12, r11
18180 +#ifdef L_avr32_f32_cmp_ge
18181 + reths 1
18182 + retlo 0
18183 +#endif
18184 +#ifdef L_avr32_f32_cmp_lt
18185 + reths 0
18186 + retlo 1
18187 +#endif
18188 +0:
18189 + /* Both signs negative */
18190 + cp.w r11, r12
18191 +#ifdef L_avr32_f32_cmp_ge
18192 + reths 1
18193 + retlo 0
18194 +#endif
18195 +#ifdef L_avr32_f32_cmp_lt
18196 + reths 0
18197 + retlo 1
18198 +#endif
18199 +#endif
18200 +
18201 +
18202 +#ifdef L_avr32_f64_cmp_eq
18203 + .global __avr32_f64_cmp_eq
18204 + .type __avr32_f64_cmp_eq,@function
18205 +__avr32_f64_cmp_eq:
18206 + cp.w r10,r8
18207 + cpc r11,r9
18208 + breq 0f
18209 +
18210 + /* Args were not equal*/
18211 + /* Both args could be zero with different sign bits */
18212 + lsl r11,1 /* get rid of sign bits */
18213 + lsl r9,1
18214 + or r11,r10 /* Check if all bits are zero */
18215 + or r11,r9
18216 + or r11,r8
18217 + reteq 1 /* If all zeros the arguments are equal
18218 + so return 1 else return 0 */
18219 + ret 0
18220 +0:
18221 + /* check for NaN */
18222 + lsl r11,1
18223 + mov_imm r12, 0xffe00000
18224 + cp.w r10,0
18225 + cpc r11,r12 /* check if nan or inf */
18226 + retls 1 /* If Arg is NaN return 0 else 1*/
18227 + ret 0 /* Return */
18228 +
18229 +#endif
18230 +
18231 +
18232 +#if defined(L_avr32_f64_cmp_ge) || defined(L_avr32_f64_cmp_lt)
18233 +
18234 +#ifdef L_avr32_f64_cmp_ge
18235 + .global __avr32_f64_cmp_ge
18236 + .type __avr32_f64_cmp_ge,@function
18237 +__avr32_f64_cmp_ge:
18238 +#endif
18239 +#ifdef L_avr32_f64_cmp_lt
18240 + .global __avr32_f64_cmp_lt
18241 + .type __avr32_f64_cmp_lt,@function
18242 +__avr32_f64_cmp_lt:
18243 +#endif
18244 +
18245 + /* compare magnitude of op1 and op2 */
18246 + st.w --sp, lr
18247 + st.w --sp, r7
18248 + lsl r11,1 /* Remove sign bit of op1 */
18249 + srcs r12 /* Sign op1 to lsb of r12*/
18250 + lsl r9,1 /* Remove sign bit of op2 */
18251 + srcs r7
18252 + rol r12 /* Sign op2 to lsb of lr, sign bit op1 bit 1 of r12*/
18253 +
18254 +
18255 + /* Check for Nan */
18256 + mov_imm lr, 0xffe00000
18257 + cp.w r10,0
18258 + cpc r11,lr
18259 + brhi 0f /* We have NaN */
18260 + cp.w r8,0
18261 + cpc r9,lr
18262 + brhi 0f /* We have NaN */
18263 +
18264 + cp.w r11, 0
18265 + subfeq r10, 0
18266 + breq 3f /* op1 zero */
18267 + ld.w r7, sp++
18268 + ld.w lr, sp++
18269 +
18270 + cp.w r12,3 /* both operands negative ?*/
18271 + breq 1f
18272 +
18273 + cp.w r12,1 /* both operands positive? */
18274 + brlo 2f
18275 +
18276 + /* Different signs. If sign of op1 is negative the difference
18277 + between op1 and op2 will always be negative, and if op1 is
18278 + positive the difference will always be positive */
18279 +#ifdef L_avr32_f64_cmp_ge
18280 + reteq 1
18281 + retne 0
18282 +#endif
18283 +#ifdef L_avr32_f64_cmp_lt
18284 + reteq 0
18285 + retne 1
18286 +#endif
18287 +
18288 +2:
18289 + /* Both operands positive. Just compute the difference */
18290 + cp.w r10,r8
18291 + cpc r11,r9
18292 +#ifdef L_avr32_f64_cmp_ge
18293 + reths 1
18294 + retlo 0
18295 +#endif
18296 +#ifdef L_avr32_f64_cmp_lt
18297 + reths 0
18298 + retlo 1
18299 +#endif
18300 +
18301 +1:
18302 + /* Both operands negative. Compute the difference with operands switched */
18303 + cp r8,r10
18304 + cpc r9,r11
18305 +#ifdef L_avr32_f64_cmp_ge
18306 + reths 1
18307 + retlo 0
18308 +#endif
18309 +#ifdef L_avr32_f64_cmp_lt
18310 + reths 0
18311 + retlo 1
18312 +#endif
18313 +
18314 +0:
18315 + ld.w r7, sp++
18316 + popm pc, r12=0
18317 +#endif
18318 +
18319 +3:
18320 + cp.w r7, 1 /* Check sign bit from r9 */
18321 +#ifdef L_avr32_f64_cmp_ge
18322 + sreq r12 /* If op2 is negative then op1 >= op2. */
18323 +#endif
18324 +#ifdef L_avr32_f64_cmp_lt
18325 + srne r12 /* If op2 is positve then op1 <= op2. */
18326 +#endif
18327 + cp.w r9, 0
18328 + subfeq r8, 0
18329 + ld.w r7, sp++
18330 + ld.w lr, sp++
18331 +#ifdef L_avr32_f64_cmp_ge
18332 + reteq 1 /* Both operands are zero. Return true. */
18333 +#endif
18334 +#ifdef L_avr32_f64_cmp_lt
18335 + reteq 0 /* Both operands are zero. Return false. */
18336 +#endif
18337 + ret r12
18338 +
18339 +
18340 +#if defined(L_avr32_f64_div) || defined(L_avr32_f64_div_fast)
18341 + .align 2
18342 +
18343 +#if defined(L_avr32_f64_div_fast)
18344 + .global __avr32_f64_div_fast
18345 + .type __avr32_f64_div_fast,@function
18346 +__avr32_f64_div_fast:
18347 +#else
18348 + .global __avr32_f64_div
18349 + .type __avr32_f64_div,@function
18350 +__avr32_f64_div:
18351 +#endif
18352 + stm --sp, r0, r1, r2, r3, r4, r5, r6, r7,lr
18353 + /* op1 in {r11,r10}*/
18354 + /* op2 in {r9,r8}*/
18355 + eor lr, r11, r9 /* MSB(lr) = Sign(op1) ^ Sign(op2) */
18356 +
18357 +
18358 + /* Unpack op1 to 2.62 format*/
18359 + /* exp: r7 */
18360 + /* sf: r11, r10 */
18361 + lsr r7, r11, 20 /* Extract exponent */
18362 +
18363 + lsl r11, 9 /* Extract mantissa, leave room for implicit bit */
18364 + or r11, r11, r10>>23
18365 + lsl r10, 9
18366 + sbr r11, 29 /* Insert implicit bit */
18367 + andh r11, 0x3fff /*Mask last part of exponent since we use 2.62 format*/
18368 +
18369 + cbr r7, 11 /* Clear sign bit */
18370 + /* Check if normalization is needed */
18371 + breq 11f /*If number is subnormal, normalize it */
18372 +22:
18373 + cp r7, 0x7ff
18374 + brge 2f /* Check op1 for NaN or Inf */
18375 +
18376 + /* Unpack op2 to 2.62 format*/
18377 + /* exp: r6 */
18378 + /* sf: r9, r8 */
18379 + lsr r6, r9, 20 /* Extract exponent */
18380 +
18381 + lsl r9, 9 /* Extract mantissa, leave room for implicit bit */
18382 + or r9, r9, r8>>23
18383 + lsl r8, 9
18384 + sbr r9, 29 /* Insert implicit bit */
18385 + andh r9, 0x3fff /*Mask last part of exponent since we use 2.62 format*/
18386 +
18387 + cbr r6, 11 /* Clear sign bit */
18388 + /* Check if normalization is needed */
18389 + breq 13f /*If number is subnormal, normalize it */
18390 +23:
18391 + cp r6, 0x7ff
18392 + brge 3f /* Check op2 for NaN or Inf */
18393 +
18394 + /* Calculate new exponent */
18395 + sub r7, r6
18396 + sub r7,-1023
18397 +
18398 + /* Divide */
18399 + /* Approximating 1/d with the following recurrence: */
18400 + /* R[j+1] = R[j]*(2-R[j]*d) */
18401 + /* Using 2.62 format */
18402 + /* TWO: r12 */
18403 + /* d = op2 = divisor (2.62 format): r9,r8 */
18404 + /* Multiply result : r5, r4 */
18405 + /* Initial guess : r3, r2 */
18406 + /* New approximations : r3, r2 */
18407 + /* op1 = Dividend (2.62 format) : r11, r10 */
18408 +
18409 + mov_imm r12, 0x80000000
18410 +
18411 + /* Load initial guess, using look-up table */
18412 + /* Initial guess is of format 01.XY, where XY is constructed as follows: */
18413 + /* Let d be of following format: 00.1xy....., then XY=~xy */
18414 + /* For d=00.100 = 0,5 -> initial guess=01.11 = 1,75 */
18415 + /* For d=00.101 = 0,625 -> initial guess=01.11 = 1,5 */
18416 + /* For d=00.110 = 0,75 -> initial guess=01.11 = 1,25 */
18417 + /* For d=00.111 = 0,875 -> initial guess=01.11 = 1,0 */
18418 + /* r2 is also part of the reg pair forming initial guess, but it*/
18419 + /* is kept uninitialized to save one cycle since it has so low significance*/
18420 +
18421 + lsr r3, r12, 1
18422 + bfextu r4, r9, 27, 2
18423 + com r4
18424 + bfins r3, r4, 28, 2
18425 +
18426 + /* First approximation */
18427 + /* Approximating to 32 bits */
18428 + /* r5 = R[j]*d */
18429 + mulu.d r4, r3, r9
18430 + /* r5 = 2-R[j]*d */
18431 + sub r5, r12, r5<<2
18432 + /* r3 = R[j]*(2-R[j]*d) */
18433 + mulu.d r4, r3, r5
18434 + lsl r3, r5, 2
18435 +
18436 + /* Second approximation */
18437 + /* Approximating to 32 bits */
18438 + /* r5 = R[j]*d */
18439 + mulu.d r4, r3, r9
18440 + /* r5 = 2-R[j]*d */
18441 + sub r5, r12, r5<<2
18442 + /* r3 = R[j]*(2-R[j]*d) */
18443 + mulu.d r4, r3, r5
18444 + lsl r3, r5, 2
18445 +
18446 + /* Third approximation */
18447 + /* Approximating to 32 bits */
18448 + /* r5 = R[j]*d */
18449 + mulu.d r4, r3, r9
18450 + /* r5 = 2-R[j]*d */
18451 + sub r5, r12, r5<<2
18452 + /* r3 = R[j]*(2-R[j]*d) */
18453 + mulu.d r4, r3, r5
18454 + lsl r3, r5, 2
18455 +
18456 + /* Fourth approximation */
18457 + /* Approximating to 64 bits */
18458 + /* r5,r4 = R[j]*d */
18459 + mul_approx_df r3 /*ah*/, r2 /*al*/, r9 /*bh*/, r8 /*bl*/, r5 /*rh*/, r4 /*rl*/, r1 /*sh*/, r0 /*sl*/
18460 + lsl r5, 2
18461 + or r5, r5, r4>>30
18462 + lsl r4, 2
18463 + /* r5,r4 = 2-R[j]*d */
18464 + neg r4
18465 + sbc r5, r12, r5
18466 + /* r3,r2 = R[j]*(2-R[j]*d) */
18467 + mul_approx_df r3 /*ah*/, r2 /*al*/, r5 /*bh*/, r4 /*bl*/, r5 /*rh*/, r4 /*rl*/, r1 /*sh*/, r0 /*sl*/
18468 + lsl r3, r5, 2
18469 + or r3, r3, r4>>30
18470 + lsl r2, r4, 2
18471 +
18472 +
18473 + /* Fifth approximation */
18474 + /* Approximating to 64 bits */
18475 + /* r5,r4 = R[j]*d */
18476 + mul_approx_df r3 /*ah*/, r2 /*al*/, r9 /*bh*/, r8 /*bl*/, r5 /*rh*/, r4 /*rl*/, r1 /*sh*/, r0 /*sl*/
18477 + lsl r5, 2
18478 + or r5, r5, r4>>30
18479 + lsl r4, 2
18480 + /* r5,r4 = 2-R[j]*d */
18481 + neg r4
18482 + sbc r5, r12, r5
18483 + /* r3,r2 = R[j]*(2-R[j]*d) */
18484 + mul_approx_df r3 /*ah*/, r2 /*al*/, r5 /*bh*/, r4 /*bl*/, r5 /*rh*/, r4 /*rl*/, r1 /*sh*/, r0 /*sl*/
18485 + lsl r3, r5, 2
18486 + or r3, r3, r4>>30
18487 + lsl r2, r4, 2
18488 +
18489 +
18490 + /* Multiply with dividend to get quotient */
18491 + mul_approx_df r3 /*ah*/, r2 /*al*/, r11 /*bh*/, r10 /*bl*/, r3 /*rh*/, r2 /*rl*/, r1 /*sh*/, r0 /*sl*/
18492 +
18493 +
18494 + /* To increase speed, this result is not corrected before final rounding.*/
18495 + /* This may give a difference to IEEE compliant code of 1 ULP.*/
18496 +
18497 +
18498 + /* Adjust exponent and mantissa */
18499 + /* r7:exp, [r3, r2]:mant, [r5, r4]:scratch*/
18500 + /* Mantissa may be of the format 0.xxxx or 1.xxxx. */
18501 + /* In the first case, shift one pos to left.*/
18502 + bld r3, 31-3
18503 + breq 0f
18504 + lsl r2, 1
18505 + rol r3
18506 + sub r7, 1
18507 +#if defined(L_avr32_f64_div)
18508 + /* We must scale down the dividend to 5.59 format. */
18509 + lsr r10, 3
18510 + or r10, r10, r11 << 29
18511 + lsr r11, 3
18512 + rjmp 1f
18513 +#endif
18514 +0:
18515 +#if defined(L_avr32_f64_div)
18516 + /* We must scale down the dividend to 6.58 format. */
18517 + lsr r10, 4
18518 + or r10, r10, r11 << 28
18519 + lsr r11, 4
18520 +1:
18521 +#endif
18522 + cp r7, 0
18523 + brle __avr32_f64_div_res_subnormal /* Result was subnormal. */
18524 +
18525 +
18526 +#if defined(L_avr32_f64_div)
18527 + /* In order to round correctly we calculate the remainder:
18528 + Remainder = dividend[11:r10] - divisor[r9:r8]*quotient[r3:r2]
18529 + for the case when the quotient is halfway between the round-up
18530 + value and the round down value. If the remainder then is negative
18531 + it means that the quotient was to big and that it should not be
18532 + rounded up, if the remainder is positive the quotient was to small
18533 + and we need to round up. If the remainder is zero it means that the
18534 + quotient is exact but since we need to remove the guard bit we should
18535 + round to even. */
18536 +
18537 + /* Truncate and add guard bit. */
18538 + andl r2, 0xff00
18539 + orl r2, 0x0080
18540 +
18541 +
18542 + /* Now do the multiplication. The quotient has the format 4.60
18543 + while the divisor has the format 2.62 which gives a result
18544 + of 6.58 */
18545 + mulu.d r0, r3, r8
18546 + macu.d r0, r2, r9
18547 + mulu.d r4, r2, r8
18548 + mulu.d r8, r3, r9
18549 + add r5, r0
18550 + adc r8, r8, r1
18551 + acr r9
18552 +
18553 +
18554 + /* Check if remainder is positive, negative or equal. */
18555 + bfextu r12, r2, 8, 1 /* Get parity bit into bit 0 of r0 */
18556 + cp r4, 0
18557 + cpc r5
18558 +__avr32_f64_div_round_subnormal:
18559 + cpc r8, r10
18560 + cpc r9, r11
18561 + srlo r6 /* Remainder positive: we need to round up.*/
18562 + moveq r6, r12 /* Remainder zero: round up if mantissa odd. */
18563 +#else
18564 + bfextu r6, r2, 7, 1 /* Get guard bit */
18565 +#endif
18566 + /* Final packing, scale down mantissa. */
18567 + lsr r10, r2, 8
18568 + or r10, r10, r3<<24
18569 + lsr r11, r3, 8
18570 + /* Insert exponent and sign bit*/
18571 + bfins r11, r7, 20, 11
18572 + bld lr, 31
18573 + bst r11, 31
18574 +
18575 + /* Final rounding */
18576 + add r10, r6
18577 + acr r11
18578 +
18579 + /* Return result in [r11,r10] */
18580 + ldm sp++, r0, r1, r2, r3, r4, r5, r6, r7,pc
18581 +
18582 +
18583 +2:
18584 + /* Op1 is NaN or inf */
18585 + andh r11, 0x000f /* Extract mantissa */
18586 + or r11, r10
18587 + brne 16f /* Return NaN if op1 is NaN */
18588 + /* Op1 is inf check op2 */
18589 + lsr r6, r9, 20 /* Extract exponent */
18590 + cbr r6, 11 /* Clear sign bit */
18591 + cp r6, 0x7ff
18592 + brne 17f /* Inf/number gives inf, return inf */
18593 + rjmp 16f /* The rest gives NaN*/
18594 +
18595 +3:
18596 + /* Op1 is a valid number. Op 2 is NaN or inf */
18597 + andh r9, 0x000f /* Extract mantissa */
18598 + or r9, r8
18599 + brne 16f /* Return NaN if op2 is NaN */
18600 + rjmp 15f /* Op2 was inf, return zero*/
18601 +
18602 +11: /* Op1 was denormal. Fix it. */
18603 + lsl r11, 3
18604 + or r11, r11, r10 >> 29
18605 + lsl r10, 3
18606 + /* Check if op1 is zero. */
18607 + or r4, r10, r11
18608 + breq __avr32_f64_div_op1_zero
18609 + normalize_df r7 /*exp*/, r10, r11 /*Mantissa*/, r4, r5 /*scratch*/
18610 + lsr r10, 2
18611 + or r10, r10, r11 << 30
18612 + lsr r11, 2
18613 + rjmp 22b
18614 +
18615 +
18616 +13: /* Op2 was denormal. Fix it */
18617 + lsl r9, 3
18618 + or r9, r9, r8 >> 29
18619 + lsl r8, 3
18620 + /* Check if op2 is zero. */
18621 + or r4, r9, r8
18622 + breq 17f /* Divisor is zero -> return Inf */
18623 + normalize_df r6 /*exp*/, r8, r9 /*Mantissa*/, r4, r5 /*scratch*/
18624 + lsr r8, 2
18625 + or r8, r8, r9 << 30
18626 + lsr r9, 2
18627 + rjmp 23b
18628 +
18629 +
18630 +__avr32_f64_div_res_subnormal:/* Divide result was subnormal. */
18631 +#if defined(L_avr32_f64_div)
18632 + /* Check how much we must scale down the mantissa. */
18633 + neg r7
18634 + sub r7, -1 /* We do no longer have an implicit bit. */
18635 + satu r7 >> 0, 6 /* Saturate shift amount to max 63. */
18636 + cp.w r7, 32
18637 + brge 0f
18638 + /* Shift amount <32 */
18639 + /* Scale down quotient */
18640 + rsub r6, r7, 32
18641 + lsr r2, r2, r7
18642 + lsl r12, r3, r6
18643 + or r2, r12
18644 + lsr r3, r3, r7
18645 + /* Scale down the dividend to match the scaling of the quotient. */
18646 + lsl r1, r10, r6
18647 + lsr r10, r10, r7
18648 + lsl r12, r11, r6
18649 + or r10, r12
18650 + lsr r11, r11, r7
18651 + mov r0, 0
18652 + rjmp 1f
18653 +0:
18654 + /* Shift amount >=32 */
18655 + rsub r6, r7, 32
18656 + moveq r0, 0
18657 + moveq r12, 0
18658 + breq 0f
18659 + lsl r0, r10, r6
18660 + lsl r12, r11, r6
18661 +0:
18662 + lsr r2, r3, r7
18663 + mov r3, 0
18664 + /* Scale down the dividend to match the scaling of the quotient. */
18665 + lsr r1, r10, r7
18666 + or r1, r12
18667 + lsr r10, r11, r7
18668 + mov r11, 0
18669 +1:
18670 + /* Start performing the same rounding as done for normal numbers
18671 + but this time we have scaled the quotient and dividend and hence
18672 + need a little different comparison. */
18673 + /* Truncate and add guard bit. */
18674 + andl r2, 0xff00
18675 + orl r2, 0x0080
18676 +
18677 + /* Now do the multiplication. */
18678 + mulu.d r6, r3, r8
18679 + macu.d r6, r2, r9
18680 + mulu.d r4, r2, r8
18681 + mulu.d r8, r3, r9
18682 + add r5, r6
18683 + adc r8, r8, r7
18684 + acr r9
18685 +
18686 + /* Set exponent to 0 */
18687 + mov r7, 0
18688 +
18689 + /* Check if remainder is positive, negative or equal. */
18690 + bfextu r12, r2, 8, 1 /* Get parity bit into bit 0 of r0 */
18691 + cp r4, r0
18692 + cpc r5, r1
18693 + /* Now the rest of the rounding is the same as for normals. */
18694 + rjmp __avr32_f64_div_round_subnormal
18695 +
18696 +#endif
18697 +15:
18698 + /* Flush to zero for the fast version. */
18699 + mov r11, lr /*Get correct sign*/
18700 + andh r11, 0x8000, COH
18701 + mov r10, 0
18702 + ldm sp++, r0, r1, r2, r3, r4, r5, r6, r7,pc
18703 +
18704 +16: /* Return NaN. */
18705 + mov r11, -1
18706 + mov r10, 0
18707 + ldm sp++, r0, r1, r2, r3, r4, r5, r6, r7,pc
18708 +
18709 +17:
18710 + /* Check if op1 is zero. */
18711 + or r4, r10, r11
18712 + breq __avr32_f64_div_op1_zero
18713 + /* Return INF. */
18714 + mov r11, lr /*Get correct sign*/
18715 + andh r11, 0x8000, COH
18716 + orh r11, 0x7ff0
18717 + mov r10, 0
18718 + ldm sp++, r0, r1, r2, r3, r4, r5, r6, r7,pc
18719 +
18720 +__avr32_f64_div_op1_zero:
18721 + or r5, r8, r9 << 1
18722 + breq 16b /* 0.0/0.0 -> NaN */
18723 + bfextu r4, r9, 20, 11
18724 + cp r4, 0x7ff
18725 + brne 15b /* Return zero */
18726 + /* Check if divisor is Inf or NaN */
18727 + or r5, r8, r9 << 12
18728 + breq 15b /* Divisor is inf -> return zero */
18729 + rjmp 16b /* Return NaN */
18730 +
18731 +
18732 +
18733 +
18734 +#endif
18735 +
18736 +#if defined(L_avr32_f32_addsub) || defined(L_avr32_f32_addsub_fast)
18737 +
18738 + .align 2
18739 +__avr32_f32_sub_from_add:
18740 + /* Switch sign on op2 */
18741 + eorh r11, 0x8000
18742 +
18743 +#if defined(L_avr32_f32_addsub_fast)
18744 + .global __avr32_f32_sub_fast
18745 + .type __avr32_f32_sub_fast,@function
18746 +__avr32_f32_sub_fast:
18747 +#else
18748 + .global __avr32_f32_sub
18749 + .type __avr32_f32_sub,@function
18750 +__avr32_f32_sub:
18751 +#endif
18752 +
18753 + /* Check signs */
18754 + eor r8, r11, r12
18755 + /* Different signs, use subtraction. */
18756 + brmi __avr32_f32_add_from_sub
18757 +
18758 + /* Get sign of op1 */
18759 + mov r8, r12
18760 + andh r12, 0x8000, COH
18761 +
18762 + /* Remove sign from operands */
18763 + cbr r11, 31
18764 +#if defined(L_avr32_f32_addsub_fast)
18765 + reteq r8 /* If op2 is zero return op1 */
18766 +#endif
18767 + cbr r8, 31
18768 +
18769 + /* Put the number with the largest exponent in r10
18770 + and the number with the smallest exponent in r9 */
18771 + max r10, r8, r11
18772 + min r9, r8, r11
18773 + cp r10, r8 /*If largest operand (in R10) is not equal to op1*/
18774 + subne r12, 1 /* Subtract 1 from sign, which will invert MSB of r12*/
18775 + andh r12, 0x8000, COH /*Mask all but MSB*/
18776 +
18777 + /* Unpack exponent and mantissa of op1 */
18778 + lsl r8, r10, 8
18779 + sbr r8, 31 /* Set implicit bit. */
18780 + lsr r10, 23
18781 +
18782 + /* op1 is NaN or Inf. */
18783 + cp.w r10, 0xff
18784 + breq __avr32_f32_sub_op1_nan_or_inf
18785 +
18786 + /* Unpack exponent and mantissa of op2 */
18787 + lsl r11, r9, 8
18788 + sbr r11, 31 /* Set implicit bit. */
18789 + lsr r9, 23
18790 +
18791 +#if defined(L_avr32_f32_addsub)
18792 + /* Keep sticky bit for correct IEEE rounding */
18793 + st.w --sp, r12
18794 +
18795 + /* op2 is either zero or subnormal. */
18796 + breq __avr32_f32_sub_op2_subnormal
18797 +0:
18798 + /* Get shift amount to scale mantissa of op2. */
18799 + sub r12, r10, r9
18800 +
18801 + breq __avr32_f32_sub_shift_done
18802 +
18803 + /* Saturate the shift amount to 31. If the amount
18804 + is any larger op2 is insignificant. */
18805 + satu r12 >> 0, 5
18806 +
18807 + /* Put the remaining bits into r9.*/
18808 + rsub r9, r12, 32
18809 + lsl r9, r11, r9
18810 +
18811 + /* If the remaining bits are non-zero then we must subtract one
18812 + more from opL. */
18813 + subne r8, 1
18814 + srne r9 /* LSB of r9 represents sticky bits. */
18815 +
18816 + /* Shift mantissa of op2 to same decimal point as the mantissa
18817 + of op1. */
18818 + lsr r11, r11, r12
18819 +
18820 +
18821 +__avr32_f32_sub_shift_done:
18822 + /* Now subtract the mantissas. */
18823 + sub r8, r11
18824 +
18825 + ld.w r12, sp++
18826 +
18827 + /* Normalize resulting mantissa. */
18828 + clz r11, r8
18829 +
18830 + retcs 0
18831 + lsl r8, r8, r11
18832 + sub r10, r11
18833 + brle __avr32_f32_sub_subnormal_result
18834 +
18835 + /* Insert the bits we will remove from the mantissa into r9[31:24] */
18836 + or r9, r9, r8 << 24
18837 +#else
18838 + /* Ignore sticky bit to simplify and speed up rounding */
18839 + /* op2 is either zero or subnormal. */
18840 + breq __avr32_f32_sub_op2_subnormal
18841 +0:
18842 + /* Get shift amount to scale mantissa of op2. */
18843 + rsub r9, r10
18844 +
18845 + /* Saturate the shift amount to 31. If the amount
18846 + is any larger op2 is insignificant. */
18847 + satu r9 >> 0, 5
18848 +
18849 + /* Shift mantissa of op2 to same decimal point as the mantissa
18850 + of op1. */
18851 + lsr r11, r11, r9
18852 +
18853 + /* Now subtract the mantissas. */
18854 + sub r8, r11
18855 +
18856 + /* Normalize resulting mantissa. */
18857 + clz r9, r8
18858 + retcs 0
18859 + lsl r8, r8, r9
18860 + sub r10, r9
18861 + brle __avr32_f32_sub_subnormal_result
18862 +#endif
18863 +
18864 + /* Pack result. */
18865 + or r12, r12, r8 >> 8
18866 + bfins r12, r10, 23, 8
18867 +
18868 + /* Round */
18869 +__avr32_f32_sub_round:
18870 +#if defined(L_avr32_f32_addsub)
18871 + mov_imm r10, 0x80000000
18872 + bld r12, 0
18873 + subne r10, -1
18874 + cp.w r9, r10
18875 + subhs r12, -1
18876 +#else
18877 + bld r8, 7
18878 + acr r12
18879 +#endif
18880 +
18881 + ret r12
18882 +
18883 +
18884 +__avr32_f32_sub_op2_subnormal:
18885 + /* Fix implicit bit and adjust exponent of subnormals. */
18886 + cbr r11, 31
18887 + /* Set exponent to 1 if we do not have a zero. */
18888 + movne r9,1
18889 +
18890 + /* Check if op1 is also subnormal. */
18891 + cp.w r10, 0
18892 + brne 0b
18893 +
18894 + cbr r8, 31
18895 + /* If op1 is not zero set exponent to 1. */
18896 + movne r10,1
18897 +
18898 + rjmp 0b
18899 +
18900 +__avr32_f32_sub_op1_nan_or_inf:
18901 + /* Check if op1 is NaN, if so return NaN */
18902 + lsl r11, r8, 1
18903 + retne -1
18904 +
18905 + /* op1 is Inf. */
18906 + bfins r12, r10, 23, 8 /* Generate Inf in r12 */
18907 +
18908 + /* Check if op2 is Inf. or NaN */
18909 + lsr r11, r9, 23
18910 + cp.w r11, 0xff
18911 + retne r12 /* op2 not Inf or NaN, return op1 */
18912 +
18913 + ret -1 /* op2 Inf or NaN, return NaN */
18914 +
18915 +__avr32_f32_sub_subnormal_result:
18916 + /* Check if the number is so small that
18917 + it will be represented with zero. */
18918 + rsub r10, r10, 9
18919 + rsub r11, r10, 32
18920 + retcs 0
18921 +
18922 + /* Shift the mantissa into the correct position.*/
18923 + lsr r10, r8, r10
18924 + /* Add sign bit. */
18925 + or r12, r10
18926 +
18927 + /* Put the shifted out bits in the most significant part
18928 + of r8. */
18929 + lsl r8, r8, r11
18930 +
18931 +#if defined(L_avr32_f32_addsub)
18932 + /* Add all the remainder bits used for rounding into r9 */
18933 + or r9, r8
18934 +#else
18935 + lsr r8, 24
18936 +#endif
18937 + rjmp __avr32_f32_sub_round
18938 +
18939 +
18940 + .align 2
18941 +
18942 +__avr32_f32_add_from_sub:
18943 + /* Switch sign on op2 */
18944 + eorh r11, 0x8000
18945 +
18946 +#if defined(L_avr32_f32_addsub_fast)
18947 + .global __avr32_f32_add_fast
18948 + .type __avr32_f32_add_fast,@function
18949 +__avr32_f32_add_fast:
18950 +#else
18951 + .global __avr32_f32_add
18952 + .type __avr32_f32_add,@function
18953 +__avr32_f32_add:
18954 +#endif
18955 +
18956 + /* Check signs */
18957 + eor r8, r11, r12
18958 + /* Different signs, use subtraction. */
18959 + brmi __avr32_f32_sub_from_add
18960 +
18961 + /* Get sign of op1 */
18962 + mov r8, r12
18963 + andh r12, 0x8000, COH
18964 +
18965 + /* Remove sign from operands */
18966 + cbr r11, 31
18967 +#if defined(L_avr32_f32_addsub_fast)
18968 + reteq r8 /* If op2 is zero return op1 */
18969 +#endif
18970 + cbr r8, 31
18971 +
18972 + /* Put the number with the largest exponent in r10
18973 + and the number with the smallest exponent in r9 */
18974 + max r10, r8, r11
18975 + min r9, r8, r11
18976 +
18977 + /* Unpack exponent and mantissa of op1 */
18978 + lsl r8, r10, 8
18979 + sbr r8, 31 /* Set implicit bit. */
18980 + lsr r10, 23
18981 +
18982 + /* op1 is NaN or Inf. */
18983 + cp.w r10, 0xff
18984 + breq __avr32_f32_add_op1_nan_or_inf
18985 +
18986 + /* Unpack exponent and mantissa of op2 */
18987 + lsl r11, r9, 8
18988 + sbr r11, 31 /* Set implicit bit. */
18989 + lsr r9, 23
18990 +
18991 +#if defined(L_avr32_f32_addsub)
18992 + /* op2 is either zero or subnormal. */
18993 + breq __avr32_f32_add_op2_subnormal
18994 +0:
18995 + /* Keep sticky bit for correct IEEE rounding */
18996 + st.w --sp, r12
18997 +
18998 + /* Get shift amount to scale mantissa of op2. */
18999 + rsub r9, r10
19000 +
19001 + /* Saturate the shift amount to 31. If the amount
19002 + is any larger op2 is insignificant. */
19003 + satu r9 >> 0, 5
19004 +
19005 + /* Shift mantissa of op2 to same decimal point as the mantissa
19006 + of op1. */
19007 + lsr r12, r11, r9
19008 +
19009 + /* Put the remainding bits into r11[23:..].*/
19010 + rsub r9, r9, (32-8)
19011 + lsl r11, r11, r9
19012 + /* Insert the bits we will remove from the mantissa into r11[31:24] */
19013 + bfins r11, r12, 24, 8
19014 +
19015 + /* Now add the mantissas. */
19016 + add r8, r12
19017 +
19018 + ld.w r12, sp++
19019 +#else
19020 + /* Ignore sticky bit to simplify and speed up rounding */
19021 + /* op2 is either zero or subnormal. */
19022 + breq __avr32_f32_add_op2_subnormal
19023 +0:
19024 + /* Get shift amount to scale mantissa of op2. */
19025 + rsub r9, r10
19026 +
19027 + /* Saturate the shift amount to 31. If the amount
19028 + is any larger op2 is insignificant. */
19029 + satu r9 >> 0, 5
19030 +
19031 + /* Shift mantissa of op2 to same decimal point as the mantissa
19032 + of op1. */
19033 + lsr r11, r11, r9
19034 +
19035 + /* Now add the mantissas. */
19036 + add r8, r11
19037 +
19038 +#endif
19039 + /* Check if we overflowed. */
19040 + brcs __avr32_f32_add_res_of
19041 +1:
19042 + /* Pack result. */
19043 + or r12, r12, r8 >> 8
19044 + bfins r12, r10, 23, 8
19045 +
19046 + /* Round */
19047 +#if defined(L_avr32_f32_addsub)
19048 + mov_imm r10, 0x80000000
19049 + bld r12, 0
19050 + subne r10, -1
19051 + cp.w r11, r10
19052 + subhs r12, -1
19053 +#else
19054 + bld r8, 7
19055 + acr r12
19056 +#endif
19057 +
19058 + ret r12
19059 +
19060 +__avr32_f32_add_op2_subnormal:
19061 + /* Fix implicit bit and adjust exponent of subnormals. */
19062 + cbr r11, 31
19063 + /* Set exponent to 1 if we do not have a zero. */
19064 + movne r9,1
19065 +
19066 + /* Check if op1 is also subnormal. */
19067 + cp.w r10, 0
19068 + brne 0b
19069 + /* Both operands subnormal, just add the mantissas and
19070 + pack. If the addition of the subnormal numbers results
19071 + in a normal number then the exponent will automatically
19072 + be set to 1 by the addition. */
19073 + cbr r8, 31
19074 + add r11, r8
19075 + or r12, r12, r11 >> 8
19076 + ret r12
19077 +
19078 +__avr32_f32_add_op1_nan_or_inf:
19079 + /* Check if op1 is NaN, if so return NaN */
19080 + lsl r11, r8, 1
19081 + retne -1
19082 +
19083 + /* op1 is Inf. */
19084 + bfins r12, r10, 23, 8 /* Generate Inf in r12 */
19085 +
19086 + /* Check if op2 is Inf. or NaN */
19087 + lsr r11, r9, 23
19088 + cp.w r11, 0xff
19089 + retne r12 /* op2 not Inf or NaN, return op1 */
19090 +
19091 + lsl r9, 9
19092 + reteq r12 /* op2 Inf return op1 */
19093 + ret -1 /* op2 is NaN, return NaN */
19094 +
19095 +__avr32_f32_add_res_of:
19096 + /* We overflowed. Increase exponent and shift mantissa.*/
19097 + lsr r8, 1
19098 + sub r10, -1
19099 +
19100 + /* Clear mantissa to set result to Inf if the exponent is 255. */
19101 + cp.w r10, 255
19102 + moveq r8, 0
19103 + moveq r11, 0
19104 + rjmp 1b
19105 +
19106 +
19107 +#endif
19108 +
19109 +
19110 +#if defined(L_avr32_f32_div) || defined(L_avr32_f32_div_fast)
19111 + .align 2
19112 +
19113 +#if defined(L_avr32_f32_div_fast)
19114 + .global __avr32_f32_div_fast
19115 + .type __avr32_f32_div_fast,@function
19116 +__avr32_f32_div_fast:
19117 +#else
19118 + .global __avr32_f32_div
19119 + .type __avr32_f32_div,@function
19120 +__avr32_f32_div:
19121 +#endif
19122 +
19123 + eor r8, r11, r12 /* MSB(r8) = Sign(op1) ^ Sign(op2) */
19124 +
19125 + /* Unpack */
19126 + lsl r12,1
19127 + lsl r11,1
19128 + breq 4f /* Check op2 for zero */
19129 +
19130 + tst r12, r12
19131 + moveq r9, 0
19132 + breq 12f
19133 +
19134 + /* Unpack op1*/
19135 + /* exp: r9 */
19136 + /* sf: r12 */
19137 + lsr r9, r12, 24
19138 + breq 11f /*If number is subnormal*/
19139 + cp r9, 0xff
19140 + brhs 2f /* Check op1 for NaN or Inf */
19141 + lsl r12, 7
19142 + sbr r12, 31 /*Implicit bit*/
19143 +12:
19144 +
19145 + /* Unpack op2*/
19146 + /* exp: r10 */
19147 + /* sf: r11 */
19148 + lsr r10, r11, 24
19149 + breq 13f /*If number is subnormal*/
19150 + cp r10, 0xff
19151 + brhs 3f /* Check op2 for NaN or Inf */
19152 + lsl r11,7
19153 + sbr r11, 31 /*Implicit bit*/
19154 +
19155 + cp.w r9, 0
19156 + subfeq r12, 0
19157 + reteq 0 /* op1 is zero and op2 is not zero */
19158 + /* or NaN so return zero */
19159 +
19160 +14:
19161 +
19162 + /* For UC3, store with predecrement is faster than stm */
19163 + st.w --sp, r5
19164 + st.d --sp, r6
19165 +
19166 + /* Calculate new exponent */
19167 + sub r9, r10
19168 + sub r9,-127
19169 +
19170 + /* Divide */
19171 + /* Approximating 1/d with the following recurrence: */
19172 + /* R[j+1] = R[j]*(2-R[j]*d) */
19173 + /* Using 2.30 format */
19174 + /* TWO: r10 */
19175 + /* d: r5 */
19176 + /* Multiply result : r6, r7 */
19177 + /* Initial guess : r11 */
19178 + /* New approximations : r11 */
19179 + /* Dividend : r12 */
19180 +
19181 + /* Load TWO */
19182 + mov_imm r10, 0x80000000
19183 +
19184 + lsr r12, 2 /* Get significand of Op1 in 2.30 format */
19185 + lsr r5, r11, 2 /* Get significand of Op2 (=d) in 2.30 format */
19186 +
19187 + /* Load initial guess, using look-up table */
19188 + /* Initial guess is of format 01.XY, where XY is constructed as follows: */
19189 + /* Let d be of following format: 00.1xy....., then XY=~xy */
19190 + /* For d=00.100 = 0,5 -> initial guess=01.11 = 1,75 */
19191 + /* For d=00.101 = 0,625 -> initial guess=01.11 = 1,5 */
19192 + /* For d=00.110 = 0,75 -> initial guess=01.11 = 1,25 */
19193 + /* For d=00.111 = 0,875 -> initial guess=01.11 = 1,0 */
19194 +
19195 + lsr r11, r10, 1
19196 + bfextu r6, r5, 27, 2
19197 + com r6
19198 + bfins r11, r6, 28, 2
19199 +
19200 + /* First approximation */
19201 + /* r7 = R[j]*d */
19202 + mulu.d r6, r11, r5
19203 + /* r7 = 2-R[j]*d */
19204 + sub r7, r10, r7<<2
19205 + /* r11 = R[j]*(2-R[j]*d) */
19206 + mulu.d r6, r11, r7
19207 + lsl r11, r7, 2
19208 +
19209 + /* Second approximation */
19210 + /* r7 = R[j]*d */
19211 + mulu.d r6, r11, r5
19212 + /* r7 = 2-R[j]*d */
19213 + sub r7, r10, r7<<2
19214 + /* r11 = R[j]*(2-R[j]*d) */
19215 + mulu.d r6, r11, r7
19216 + lsl r11, r7, 2
19217 +
19218 + /* Third approximation */
19219 + /* r7 = R[j]*d */
19220 + mulu.d r6, r11, r5
19221 + /* r7 = 2-R[j]*d */
19222 + sub r7, r10, r7<<2
19223 + /* r11 = R[j]*(2-R[j]*d) */
19224 + mulu.d r6, r11, r7
19225 + lsl r11, r7, 2
19226 +
19227 + /* Fourth approximation */
19228 + /* r7 = R[j]*d */
19229 + mulu.d r6, r11, r5
19230 + /* r7 = 2-R[j]*d */
19231 + sub r7, r10, r7<<2
19232 + /* r11 = R[j]*(2-R[j]*d) */
19233 + mulu.d r6, r11, r7
19234 + lsl r11, r7, 2
19235 +
19236 +
19237 + /* Multiply with dividend to get quotient, r7 = sf(op1)/sf(op2) */
19238 + mulu.d r6, r11, r12
19239 +
19240 + /* Shift by 3 to get result in 1.31 format, as required by the exponent. */
19241 + /* Note that 1.31 format is already used by the exponent in r9, since */
19242 + /* a bias of 127 was added to the result exponent, even though the implicit */
19243 + /* bit was inserted. This gives the exponent an additional bias of 1, which */
19244 + /* supports 1.31 format. */
19245 + //lsl r10, r7, 3
19246 +
19247 + /* Adjust exponent and mantissa in case the result is of format
19248 + 0000.1xxx to 0001.xxx*/
19249 +#if defined(L_avr32_f32_div)
19250 + lsr r12, 4 /* Scale dividend to 6.26 format to match the
19251 + result of the multiplication of the divisor and
19252 + quotient to get the remainder. */
19253 +#endif
19254 + bld r7, 31-3
19255 + breq 0f
19256 + lsl r7, 1
19257 + sub r9, 1
19258 +#if defined(L_avr32_f32_div)
19259 + lsl r12, 1 /* Scale dividend to 5.27 format to match the
19260 + result of the multiplication of the divisor and
19261 + quotient to get the remainder. */
19262 +#endif
19263 +0:
19264 + cp r9, 0
19265 + brle __avr32_f32_div_res_subnormal /* Result was subnormal. */
19266 +
19267 +
19268 +#if defined(L_avr32_f32_div)
19269 + /* In order to round correctly we calculate the remainder:
19270 + Remainder = dividend[r12] - divisor[r5]*quotient[r7]
19271 + for the case when the quotient is halfway between the round-up
19272 + value and the round down value. If the remainder then is negative
19273 + it means that the quotient was to big and that it should not be
19274 + rounded up, if the remainder is positive the quotient was to small
19275 + and we need to round up. If the remainder is zero it means that the
19276 + quotient is exact but since we need to remove the guard bit we should
19277 + round to even. */
19278 + andl r7, 0xffe0
19279 + orl r7, 0x0010
19280 +
19281 + /* Now do the multiplication. The quotient has the format 4.28
19282 + while the divisor has the format 2.30 which gives a result
19283 + of 6.26 */
19284 + mulu.d r10, r5, r7
19285 +
19286 + /* Check if remainder is positive, negative or equal. */
19287 + bfextu r5, r7, 5, 1 /* Get parity bit into bit 0 of r5 */
19288 + cp r10, 0
19289 +__avr32_f32_div_round_subnormal:
19290 + cpc r11, r12
19291 + srlo r11 /* Remainder positive: we need to round up.*/
19292 + moveq r11, r5 /* Remainder zero: round up if mantissa odd. */
19293 +#else
19294 + bfextu r11, r7, 4, 1 /* Get guard bit */
19295 +#endif
19296 +
19297 + /* Pack final result*/
19298 + lsr r12, r7, 5
19299 + bfins r12, r9, 23, 8
19300 + /* For UC3, load with postincrement is faster than ldm */
19301 + ld.d r6, sp++
19302 + ld.w r5, sp++
19303 + bld r8, 31
19304 + bst r12, 31
19305 + /* Rounding add. */
19306 + add r12, r11
19307 + ret r12
19308 +
19309 +__divsf_return_op1:
19310 + lsl r8, 1
19311 + ror r12
19312 + ret r12
19313 +
19314 +
19315 +2:
19316 + /* Op1 is NaN or inf */
19317 + retne -1 /* Return NaN if op1 is NaN */
19318 + /* Op1 is inf check op2 */
19319 + mov_imm r9, 0xff000000
19320 + cp r11, r9
19321 + brlo __divsf_return_op1 /* inf/number gives inf */
19322 + ret -1 /* The rest gives NaN*/
19323 +3:
19324 + /* Op2 is NaN or inf */
19325 + reteq 0 /* Return zero if number/inf*/
19326 + ret -1 /* Return NaN*/
19327 +4:
19328 + /* Op1 is zero ? */
19329 + tst r12,r12
19330 + reteq -1 /* 0.0/0.0 is NaN */
19331 + /* Op1 is Nan? */
19332 + lsr r9, r12, 24
19333 + breq 11f /*If number is subnormal*/
19334 + cp r9, 0xff
19335 + brhs 2b /* Check op1 for NaN or Inf */
19336 + /* Nonzero/0.0 is Inf. Sign bit will be shifted in before returning*/
19337 + mov_imm r12, 0xff000000
19338 + rjmp __divsf_return_op1
19339 +
19340 +11: /* Op1 was denormal. Fix it. */
19341 + lsl r12,7
19342 + clz r9,r12
19343 + lsl r12,r12,r9
19344 + rsub r9,r9,1
19345 + rjmp 12b
19346 +
19347 +13: /* Op2 was denormal. Fix it. */
19348 + lsl r11,7
19349 + clz r10,r11
19350 + lsl r11,r11,r10
19351 + rsub r10,r10,1
19352 + rjmp 14b
19353 +
19354 +
19355 +__avr32_f32_div_res_subnormal: /* Divide result was subnormal */
19356 +#if defined(L_avr32_f32_div)
19357 + /* Check how much we must scale down the mantissa. */
19358 + neg r9
19359 + sub r9, -1 /* We do no longer have an implicit bit. */
19360 + satu r9 >> 0, 5 /* Saturate shift amount to max 32. */
19361 + /* Scale down quotient */
19362 + rsub r10, r9, 32
19363 + lsr r7, r7, r9
19364 + /* Scale down the dividend to match the scaling of the quotient. */
19365 + lsl r6, r12, r10 /* Make the divident 64-bit and put the lsw in r6 */
19366 + lsr r12, r12, r9
19367 +
19368 + /* Start performing the same rounding as done for normal numbers
19369 + but this time we have scaled the quotient and dividend and hence
19370 + need a little different comparison. */
19371 + andl r7, 0xffe0
19372 + orl r7, 0x0010
19373 +
19374 + /* Now do the multiplication. The quotient has the format 4.28
19375 + while the divisor has the format 2.30 which gives a result
19376 + of 6.26 */
19377 + mulu.d r10, r5, r7
19378 +
19379 + /* Set exponent to 0 */
19380 + mov r9, 0
19381 +
19382 + /* Check if remainder is positive, negative or equal. */
19383 + bfextu r5, r7, 5, 1 /* Get parity bit into bit 0 of r5 */
19384 + cp r10, r6
19385 + rjmp __avr32_f32_div_round_subnormal
19386 +
19387 +#else
19388 + ld.d r6, sp++
19389 + ld.w r5, sp++
19390 + /*Flush to zero*/
19391 + ret 0
19392 +#endif
19393 +#endif
19394 +
19395 +#ifdef L_avr32_f32_mul
19396 + .global __avr32_f32_mul
19397 + .type __avr32_f32_mul,@function
19398 +
19399 +
19400 +__avr32_f32_mul:
19401 + mov r8, r12
19402 + eor r12, r11 /* MSB(r8) = Sign(op1) ^ Sign(op2) */
19403 + andh r12, 0x8000, COH
19404 +
19405 + /* arrange operands so that that op1 >= op2 */
19406 + cbr r8, 31
19407 + breq __avr32_f32_mul_op1_zero
19408 + cbr r11, 31
19409 +
19410 + /* Put the number with the largest exponent in r10
19411 + and the number with the smallest exponent in r9 */
19412 + max r10, r8, r11
19413 + min r9, r8, r11
19414 +
19415 + /* Unpack exponent and mantissa of op1 */
19416 + lsl r8, r10, 8
19417 + sbr r8, 31 /* Set implicit bit. */
19418 + lsr r10, 23
19419 +
19420 + /* op1 is NaN or Inf. */
19421 + cp.w r10, 0xff
19422 + breq __avr32_f32_mul_op1_nan_or_inf
19423 +
19424 + /* Unpack exponent and mantissa of op2 */
19425 + lsl r11, r9, 8
19426 + sbr r11, 31 /* Set implicit bit. */
19427 + lsr r9, 23
19428 +
19429 + /* op2 is either zero or subnormal. */
19430 + breq __avr32_f32_mul_op2_subnormal
19431 +0:
19432 + /* Calculate new exponent */
19433 + add r9,r10
19434 +
19435 + /* Do the multiplication */
19436 + mulu.d r10,r8,r11
19437 +
19438 + /* We might need to scale up by two if the MSB of the result is
19439 + zero. */
19440 + lsl r8, r11, 1
19441 + movcc r11, r8
19442 + subcc r9, 1
19443 +
19444 + /* Put the shifted out bits of the mantissa into r10 */
19445 + lsr r10, 8
19446 + bfins r10, r11, 24, 8
19447 +
19448 + sub r9,(127-1) /* remove extra exponent bias */
19449 + brle __avr32_f32_mul_res_subnormal
19450 +
19451 + /* Check for Inf. */
19452 + cp.w r9, 0xff
19453 + brge 1f
19454 +
19455 + /* Pack result. */
19456 + or r12, r12, r11 >> 8
19457 + bfins r12, r9, 23, 8
19458 +
19459 + /* Round */
19460 +__avr32_f32_mul_round:
19461 + mov_imm r8, 0x80000000
19462 + bld r12, 0
19463 + subne r8, -1
19464 +
19465 + cp.w r10, r8
19466 + subhs r12, -1
19467 +
19468 + ret r12
19469 +
19470 +1:
19471 + /* Return Inf */
19472 + orh r12, 0x7f80
19473 + ret r12
19474 +
19475 +__avr32_f32_mul_op2_subnormal:
19476 + cbr r11, 31
19477 + clz r9, r11
19478 + retcs 0 /* op2 is zero. Return 0 */
19479 + sub r9, 8
19480 + lsl r11, r11, r9
19481 + rsub r9, r9, 1
19482 +
19483 + /* Check if op2 is subnormal. */
19484 + tst r10, r10
19485 + brne 0b
19486 +
19487 + /* op2 is subnormal */
19488 + cbr r8, 31
19489 + clz r10, r11
19490 + retcs 0 /* op1 is zero. Return 0 */
19491 + lsl r8, r8, r10
19492 + rsub r10, r10, 1
19493 +
19494 + rjmp 0b
19495 +
19496 +
19497 +__avr32_f32_mul_op1_nan_or_inf:
19498 + /* Check if op1 is NaN, if so return NaN */
19499 + lsl r11, r8, 1
19500 + retne -1
19501 +
19502 + /* op1 is Inf. */
19503 + tst r9, r9
19504 + reteq -1 /* Inf * 0 -> NaN */
19505 +
19506 + bfins r12, r10, 23, 8 /* Generate Inf in r12 */
19507 +
19508 + /* Check if op2 is Inf. or NaN */
19509 + lsr r11, r9, 23
19510 + cp.w r11, 0xff
19511 + retne r12 /* op2 not Inf or NaN, return Info */
19512 +
19513 + lsl r9, 9
19514 + reteq r12 /* op2 Inf return Inf */
19515 + ret -1 /* op2 is NaN, return NaN */
19516 +
19517 +__avr32_f32_mul_res_subnormal:
19518 + /* Check if the number is so small that
19519 + it will be represented with zero. */
19520 + rsub r9, r9, 9
19521 + rsub r8, r9, 32
19522 + retcs 0
19523 +
19524 + /* Shift the mantissa into the correct position.*/
19525 + lsr r9, r11, r9
19526 + /* Add sign bit. */
19527 + or r12, r9
19528 + /* Put the shifted out bits in the most significant part
19529 + of r8. */
19530 + lsl r11, r11, r8
19531 +
19532 + /* Add all the remainder bits used for rounding into r11 */
19533 + andh r10, 0x00FF
19534 + or r10, r11
19535 + rjmp __avr32_f32_mul_round
19536 +
19537 +__avr32_f32_mul_op1_zero:
19538 + bfextu r10, r11, 23, 8
19539 + cp.w r10, 0xff
19540 + retne r12
19541 + reteq -1
19542 +
19543 +#endif
19544 +
19545 +
19546 +#ifdef L_avr32_s32_to_f32
19547 + .global __avr32_s32_to_f32
19548 + .type __avr32_s32_to_f32,@function
19549 +__avr32_s32_to_f32:
19550 + cp r12, 0
19551 + reteq r12 /* If zero then return zero float */
19552 + mov r11, r12 /* Keep the sign */
19553 + abs r12 /* Compute the absolute value */
19554 + mov r10, 31 + 127 /* Set the correct exponent */
19555 +
19556 + /* Normalize */
19557 + normalize_sf r10 /*exp*/, r12 /*mant*/, r9 /*scratch*/
19558 +
19559 + /* Check for subnormal result */
19560 + cp.w r10, 0
19561 + brle __avr32_s32_to_f32_subnormal
19562 +
19563 + round_sf r10 /*exp*/, r12 /*mant*/, r9 /*scratch*/
19564 + pack_sf r12 /*sf*/, r10 /*exp*/, r12 /*mant*/
19565 + lsl r11, 1
19566 + ror r12
19567 + ret r12
19568 +
19569 +__avr32_s32_to_f32_subnormal:
19570 + /* Adjust a subnormal result */
19571 + adjust_subnormal_sf r12/*sf*/, r10 /*exp*/, r12 /*mant*/, r11/*sign*/, r9 /*scratch*/
19572 + ret r12
19573 +
19574 +#endif
19575 +
19576 +#ifdef L_avr32_u32_to_f32
19577 + .global __avr32_u32_to_f32
19578 + .type __avr32_u32_to_f32,@function
19579 +__avr32_u32_to_f32:
19580 + cp r12, 0
19581 + reteq r12 /* If zero then return zero float */
19582 + mov r10, 31 + 127 /* Set the correct exponent */
19583 +
19584 + /* Normalize */
19585 + normalize_sf r10 /*exp*/, r12 /*mant*/, r9 /*scratch*/
19586 +
19587 + /* Check for subnormal result */
19588 + cp.w r10, 0
19589 + brle __avr32_u32_to_f32_subnormal
19590 +
19591 + round_sf r10 /*exp*/, r12 /*mant*/, r9 /*scratch*/
19592 + pack_sf r12 /*sf*/, r10 /*exp*/, r12 /*mant*/
19593 + lsr r12,1 /* Sign bit is 0 for unsigned int */
19594 + ret r12
19595 +
19596 +__avr32_u32_to_f32_subnormal:
19597 + /* Adjust a subnormal result */
19598 + mov r8, 0
19599 + adjust_subnormal_sf r12/*sf*/,r10 /*exp*/, r12 /*mant*/,r8/*sign*/, r9 /*scratch*/
19600 + ret r12
19601 +
19602 +
19603 +#endif
19604 +
19605 +
19606 +#ifdef L_avr32_f32_to_s32
19607 + .global __avr32_f32_to_s32
19608 + .type __avr32_f32_to_s32,@function
19609 +__avr32_f32_to_s32:
19610 + bfextu r11, r12, 23, 8
19611 + sub r11,127 /* Fix bias */
19612 + retlo 0 /* Negative exponent yields zero integer */
19613 +
19614 + /* Shift mantissa into correct position */
19615 + rsub r11,r11,31 /* Shift amount */
19616 + lsl r10,r12,8 /* Get mantissa */
19617 + sbr r10,31 /* Add implicit bit */
19618 + lsr r10,r10,r11 /* Perform shift */
19619 + lsl r12,1 /* Check sign */
19620 + retcc r10 /* if positive, we are done */
19621 + neg r10 /* if negative float, negate result */
19622 + ret r10
19623 +
19624 +#endif
19625 +
19626 +#ifdef L_avr32_f32_to_u32
19627 + .global __avr32_f32_to_u32
19628 + .type __avr32_f32_to_u32,@function
19629 +__avr32_f32_to_u32:
19630 + cp r12,0
19631 + retmi 0 /* Negative numbers gives 0 */
19632 + bfextu r11, r12, 23, 8 /* Extract exponent */
19633 + sub r11,127 /* Fix bias */
19634 + retlo 0 /* Negative exponent yields zero integer */
19635 +
19636 + /* Shift mantissa into correct position */
19637 + rsub r11,r11,31 /* Shift amount */
19638 + lsl r12,8 /* Get mantissa */
19639 + sbr r12,31 /* Add implicit bit */
19640 + lsr r12,r12,r11 /* Perform shift */
19641 + ret r12
19642 +
19643 +#endif
19644 +
19645 +#ifdef L_avr32_f32_to_f64
19646 + .global __avr32_f32_to_f64
19647 + .type __avr32_f32_to_f64,@function
19648 +
19649 +__avr32_f32_to_f64:
19650 + lsl r11,r12,1 /* Remove sign bit, keep original value in r12*/
19651 + moveq r10, 0
19652 + reteq r11 /* Return zero if input is zero */
19653 +
19654 + bfextu r9,r11,24,8 /* Get exponent */
19655 + cp.w r9,0xff /* check for NaN or inf */
19656 + breq 0f
19657 +
19658 + lsl r11,7 /* Convert sf mantissa to df format */
19659 + mov r10,0
19660 +
19661 + /* Check if implicit bit should be set */
19662 + cp.w r9, 0
19663 + subeq r9,-1 /* Adjust exponent if it was 0 */
19664 + srne r8
19665 + or r11, r11, r8 << 31 /* Set implicit bit if needed */
19666 + sub r9,(127-0x3ff) /* Convert exponent to df format exponent */
19667 +
19668 + /*We know that low register of mantissa is 0, and will be unaffected by normalization.*/
19669 + /*We can therefore use the faster normalize_sf function instead of normalize_df.*/
19670 + normalize_sf r9 /*exp*/, r11 /*mantissa*/, r8 /*scratch*/
19671 + pack_df r9 /*exp*/, r10, r11 /*mantissa*/, r10, r11 /*df*/
19672 +
19673 +__extendsfdf_return_op1:
19674 + /* Rotate in sign bit */
19675 + lsl r12, 1
19676 + ror r11
19677 + ret r11
19678 +
19679 +0:
19680 + /* Inf or NaN*/
19681 + mov_imm r10, 0xffe00000
19682 + lsl r11,8 /* check mantissa */
19683 + movne r11, -1 /* Return NaN */
19684 + moveq r11, r10 /* Return inf */
19685 + mov r10, 0
19686 + rjmp __extendsfdf_return_op1
19687 +#endif
19688 +
19689 +
19690 +#ifdef L_avr32_f64_to_f32
19691 + .global __avr32_f64_to_f32
19692 + .type __avr32_f64_to_f32,@function
19693 +
19694 +__avr32_f64_to_f32:
19695 + /* Unpack */
19696 + lsl r9,r11,1 /* Unpack exponent */
19697 + lsr r9,21
19698 +
19699 + reteq 0 /* If exponent is 0 the number is so small
19700 + that the conversion to single float gives
19701 + zero */
19702 +
19703 + lsl r8,r11,10 /* Adjust mantissa */
19704 + or r12,r8,r10>>22
19705 +
19706 + lsl r10,10 /* Check if there are any remaining bits
19707 + in the low part of the mantissa.*/
19708 + neg r10
19709 + rol r12 /* If there were remaining bits then set lsb
19710 + of mantissa to 1 */
19711 +
19712 + cp r9,0x7ff
19713 + breq 2f /* Check for NaN or inf */
19714 +
19715 + sub r9,(0x3ff-127) /* Adjust bias of exponent */
19716 + sbr r12,31 /* set the implicit bit.*/
19717 +
19718 + cp.w r9, 0 /* Check for subnormal number */
19719 + brle 3f
19720 +
19721 + round_sf r9 /*exp*/, r12 /*mant*/, r10 /*scratch*/
19722 + pack_sf r12 /*sf*/, r9 /*exp*/, r12 /*mant*/
19723 +__truncdfsf_return_op1:
19724 + /* Rotate in sign bit */
19725 + lsl r11, 1
19726 + ror r12
19727 + ret r12
19728 +
19729 +2:
19730 + /* NaN or inf */
19731 + cbr r12,31 /* clear implicit bit */
19732 + retne -1 /* Return NaN if mantissa not zero */
19733 + mov_imm r12, 0x7f800000
19734 + ret r12 /* Return inf */
19735 +
19736 +3: /* Result is subnormal. Adjust it.*/
19737 + adjust_subnormal_sf r12/*sf*/,r9 /*exp*/, r12 /*mant*/, r11/*sign*/, r10 /*scratch*/
19738 + ret r12
19739 +
19740 +
19741 +#endif
19742 +
19743 +#if defined(L_mulsi3) && defined(__AVR32_NO_MUL__)
19744 + .global __mulsi3
19745 + .type __mulsi3,@function
19746 +
19747 +__mulsi3:
19748 + mov r9, 0
19749 +0:
19750 + lsr r11, 1
19751 + addcs r9, r9, r12
19752 + breq 1f
19753 + lsl r12, 1
19754 + rjmp 0b
19755 +1:
19756 + ret r9
19757 +#endif
19758 --- /dev/null
19759 +++ b/gcc/config/avr32/lib2funcs.S
19760 @@ -0,0 +1,21 @@
19761 + .align 4
19762 + .global __nonlocal_goto
19763 + .type __nonlocal_goto,@function
19764 +
19765 +/* __nonlocal_goto: This function handles nonlocal_goto's in gcc.
19766 +
19767 + parameter 0 (r12) = New Frame Pointer
19768 + parameter 1 (r11) = Address to goto
19769 + parameter 2 (r10) = New Stack Pointer
19770 +
19771 + This function invalidates the return stack, since it returns from a
19772 + function without using a return instruction.
19773 +*/
19774 +__nonlocal_goto:
19775 + mov r7, r12
19776 + mov sp, r10
19777 + frs # Flush return stack
19778 + mov pc, r11
19779 +
19780 +
19781 +
19782 --- /dev/null
19783 +++ b/gcc/config/avr32/linux-elf.h
19784 @@ -0,0 +1,151 @@
19785 +/*
19786 + Linux/Elf specific definitions.
19787 + Copyright 2003-2006 Atmel Corporation.
19788 +
19789 + Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
19790 + and H�vard Skinnemoen, Atmel Norway, <hskinnemoen@atmel.com>
19791 +
19792 + This file is part of GCC.
19793 +
19794 + This program is free software; you can redistribute it and/or modify
19795 + it under the terms of the GNU General Public License as published by
19796 + the Free Software Foundation; either version 2 of the License, or
19797 + (at your option) any later version.
19798 +
19799 + This program is distributed in the hope that it will be useful,
19800 + but WITHOUT ANY WARRANTY; without even the implied warranty of
19801 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19802 + GNU General Public License for more details.
19803 +
19804 + You should have received a copy of the GNU General Public License
19805 + along with this program; if not, write to the Free Software
19806 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19807 +
19808 +
19809 +
19810 +/* elfos.h should have already been included. Now just override
19811 + any conflicting definitions and add any extras. */
19812 +
19813 +/* Run-time Target Specification. */
19814 +#undef TARGET_VERSION
19815 +#define TARGET_VERSION fputs (" (AVR32 GNU/Linux with ELF)", stderr);
19816 +
19817 +/* Do not assume anything about header files. */
19818 +#define NO_IMPLICIT_EXTERN_C
19819 +
19820 +/* The GNU C++ standard library requires that these macros be defined. */
19821 +#undef CPLUSPLUS_CPP_SPEC
19822 +#define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)"
19823 +
19824 +/* Now we define the strings used to build the spec file. */
19825 +#undef LIB_SPEC
19826 +#define LIB_SPEC \
19827 + "%{pthread:-lpthread} \
19828 + %{shared:-lc} \
19829 + %{!shared:%{profile:-lc_p}%{!profile:-lc}}"
19830 +
19831 +/* Provide a STARTFILE_SPEC appropriate for GNU/Linux. Here we add
19832 + the GNU/Linux magical crtbegin.o file (see crtstuff.c) which
19833 + provides part of the support for getting C++ file-scope static
19834 + object constructed before entering `main'. */
19835 +
19836 +#undef STARTFILE_SPEC
19837 +#define STARTFILE_SPEC \
19838 + "%{!shared: \
19839 + %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \
19840 + %{!p:%{profile:gcrt1.o%s} \
19841 + %{!profile:crt1.o%s}}}} \
19842 + crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}"
19843 +
19844 +/* Provide a ENDFILE_SPEC appropriate for GNU/Linux. Here we tack on
19845 + the GNU/Linux magical crtend.o file (see crtstuff.c) which
19846 + provides part of the support for getting C++ file-scope static
19847 + object constructed before entering `main', followed by a normal
19848 + GNU/Linux "finalizer" file, `crtn.o'. */
19849 +
19850 +#undef ENDFILE_SPEC
19851 +#define ENDFILE_SPEC \
19852 + "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s"
19853 +
19854 +#undef ASM_SPEC
19855 +#define ASM_SPEC "%{!mno-pic:%{!fno-pic:--pic}} %{mrelax|O*:%{mno-relax|O0|O1: ;:--linkrelax}} %{mcpu=*:-mcpu=%*}"
19856 +
19857 +#undef LINK_SPEC
19858 +#define LINK_SPEC "%{version:-v} \
19859 + %{static:-Bstatic} \
19860 + %{shared:-shared} \
19861 + %{symbolic:-Bsymbolic} \
19862 + %{rdynamic:-export-dynamic} \
19863 + %{!dynamic-linker:-dynamic-linker /lib/ld-uClibc.so.0} \
19864 + %{mrelax|O*:%{mno-relax|O0|O1: ;:--relax}}"
19865 +
19866 +#define TARGET_OS_CPP_BUILTINS() LINUX_TARGET_OS_CPP_BUILTINS()
19867 +
19868 +/* This is how we tell the assembler that two symbols have the same value. */
19869 +#define ASM_OUTPUT_DEF(FILE, NAME1, NAME2) \
19870 + do \
19871 + { \
19872 + assemble_name (FILE, NAME1); \
19873 + fputs (" = ", FILE); \
19874 + assemble_name (FILE, NAME2); \
19875 + fputc ('\n', FILE); \
19876 + } \
19877 + while (0)
19878 +
19879 +
19880 +
19881 +#undef CC1_SPEC
19882 +#define CC1_SPEC "%{profile:-p}"
19883 +
19884 +/* Target CPU builtins. */
19885 +#define TARGET_CPU_CPP_BUILTINS() \
19886 + do \
19887 + { \
19888 + builtin_define ("__avr32__"); \
19889 + builtin_define ("__AVR32__"); \
19890 + builtin_define ("__AVR32_LINUX__"); \
19891 + builtin_define (avr32_part->macro); \
19892 + builtin_define (avr32_arch->macro); \
19893 + if (avr32_arch->uarch_type == UARCH_TYPE_AVR32A) \
19894 + builtin_define ("__AVR32_AVR32A__"); \
19895 + else \
19896 + builtin_define ("__AVR32_AVR32B__"); \
19897 + if (TARGET_UNALIGNED_WORD) \
19898 + builtin_define ("__AVR32_HAS_UNALIGNED_WORD__"); \
19899 + if (TARGET_SIMD) \
19900 + builtin_define ("__AVR32_HAS_SIMD__"); \
19901 + if (TARGET_DSP) \
19902 + builtin_define ("__AVR32_HAS_DSP__"); \
19903 + if (TARGET_RMW) \
19904 + builtin_define ("__AVR32_HAS_RMW__"); \
19905 + if (TARGET_BRANCH_PRED) \
19906 + builtin_define ("__AVR32_HAS_BRANCH_PRED__"); \
19907 + if (TARGET_FAST_FLOAT) \
19908 + builtin_define ("__AVR32_FAST_FLOAT__"); \
19909 + } \
19910 + while (0)
19911 +
19912 +
19913 +
19914 +/* Call the function profiler with a given profile label. */
19915 +#undef FUNCTION_PROFILER
19916 +#define FUNCTION_PROFILER(STREAM, LABELNO) \
19917 + do \
19918 + { \
19919 + fprintf (STREAM, "\tmov\tlr, lo(mcount)\n\torh\tlr, hi(mcount)\n"); \
19920 + fprintf (STREAM, "\ticall lr\n"); \
19921 + } \
19922 + while (0)
19923 +
19924 +#define NO_PROFILE_COUNTERS 1
19925 +
19926 +/* For dynamic libraries to work */
19927 +/* #define PLT_REG_CALL_CLOBBERED 1 */
19928 +#define AVR32_ALWAYS_PIC 1
19929 +
19930 +/* uclibc does not implement sinf, cosf etc. */
19931 +#undef TARGET_C99_FUNCTIONS
19932 +#define TARGET_C99_FUNCTIONS 0
19933 +
19934 +#define LINK_GCC_C_SEQUENCE_SPEC \
19935 + "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
19936 --- /dev/null
19937 +++ b/gcc/config/avr32/predicates.md
19938 @@ -0,0 +1,422 @@
19939 +;; AVR32 predicates file.
19940 +;; Copyright 2003-2006 Atmel Corporation.
19941 +;;
19942 +;; Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
19943 +;;
19944 +;; This file is part of GCC.
19945 +;;
19946 +;; This program is free software; you can redistribute it and/or modify
19947 +;; it under the terms of the GNU General Public License as published by
19948 +;; the Free Software Foundation; either version 2 of the License, or
19949 +;; (at your option) any later version.
19950 +;;
19951 +;; This program is distributed in the hope that it will be useful,
19952 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19953 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19954 +;; GNU General Public License for more details.
19955 +;;
19956 +;; You should have received a copy of the GNU General Public License
19957 +;; along with this program; if not, write to the Free Software
19958 +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19959 +
19960 +
19961 +;; True if the operand is a memory reference which contains an
19962 +;; Address consisting of a single pointer register
19963 +(define_predicate "avr32_indirect_register_operand"
19964 + (and (match_code "mem")
19965 + (match_test "register_operand(XEXP(op, 0), SImode)")))
19966 +
19967 +
19968 +
19969 +;; Address expression with a base pointer offset with
19970 +;; a register displacement
19971 +(define_predicate "avr32_indexed_memory_operand"
19972 + (and (match_code "mem")
19973 + (match_test "GET_CODE(XEXP(op, 0)) == PLUS"))
19974 + {
19975 +
19976 + rtx op0 = XEXP(XEXP(op, 0), 0);
19977 + rtx op1 = XEXP(XEXP(op, 0), 1);
19978 +
19979 + return ((avr32_address_register_rtx_p (op0, 0)
19980 + && avr32_legitimate_index_p (GET_MODE(op), op1, 0))
19981 + || (avr32_address_register_rtx_p (op1, 0)
19982 + && avr32_legitimate_index_p (GET_MODE(op), op0, 0)));
19983 +
19984 + })
19985 +
19986 +;; Operand suitable for the ld.sb instruction
19987 +(define_predicate "load_sb_memory_operand"
19988 + (ior (match_operand 0 "avr32_indirect_register_operand")
19989 + (match_operand 0 "avr32_indexed_memory_operand")))
19990 +
19991 +
19992 +;; Operand suitable as operand to insns sign extending QI values
19993 +(define_predicate "extendqi_operand"
19994 + (ior (match_operand 0 "load_sb_memory_operand")
19995 + (match_operand 0 "register_operand")))
19996 +
19997 +(define_predicate "post_inc_memory_operand"
19998 + (and (match_code "mem")
19999 + (match_test "(GET_CODE(XEXP(op, 0)) == POST_INC)
20000 + && REG_P(XEXP(XEXP(op, 0), 0))")))
20001 +
20002 +(define_predicate "pre_dec_memory_operand"
20003 + (and (match_code "mem")
20004 + (match_test "(GET_CODE(XEXP(op, 0)) == PRE_DEC)
20005 + && REG_P(XEXP(XEXP(op, 0), 0))")))
20006 +
20007 +;; Operand suitable for add instructions
20008 +(define_predicate "avr32_add_operand"
20009 + (ior (match_operand 0 "register_operand")
20010 + (and (match_operand 0 "immediate_operand")
20011 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'I', \"Is21\")"))))
20012 +
20013 +;; Operand is a power of two immediate
20014 +(define_predicate "power_of_two_operand"
20015 + (match_code "const_int")
20016 +{
20017 + HOST_WIDE_INT value = INTVAL (op);
20018 +
20019 + return value != 0 && (value & (value - 1)) == 0;
20020 +})
20021 +
20022 +;; Operand is a multiple of 8 immediate
20023 +(define_predicate "multiple_of_8_operand"
20024 + (match_code "const_int")
20025 +{
20026 + HOST_WIDE_INT value = INTVAL (op);
20027 +
20028 + return (value & 0x7) == 0 ;
20029 +})
20030 +
20031 +;; Operand is a multiple of 16 immediate
20032 +(define_predicate "multiple_of_16_operand"
20033 + (match_code "const_int")
20034 +{
20035 + HOST_WIDE_INT value = INTVAL (op);
20036 +
20037 + return (value & 0xf) == 0 ;
20038 +})
20039 +
20040 +;; Operand is a mask used for masking away upper bits of a reg
20041 +(define_predicate "avr32_mask_upper_bits_operand"
20042 + (match_code "const_int")
20043 +{
20044 + HOST_WIDE_INT value = INTVAL (op) + 1;
20045 +
20046 + return value != 1 && value != 0 && (value & (value - 1)) == 0;
20047 +})
20048 +
20049 +
20050 +;; Operand suitable for mul instructions
20051 +(define_predicate "avr32_mul_operand"
20052 + (ior (match_operand 0 "register_operand")
20053 + (and (match_operand 0 "immediate_operand")
20054 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'K', \"Ks08\")"))))
20055 +
20056 +;; True for logical binary operators.
20057 +(define_predicate "logical_binary_operator"
20058 + (match_code "ior,xor,and"))
20059 +
20060 +;; True for logical shift operators
20061 +(define_predicate "logical_shift_operator"
20062 + (match_code "ashift,lshiftrt"))
20063 +
20064 +;; True for shift operand for logical and, or and eor insns
20065 +(define_predicate "avr32_logical_shift_operand"
20066 + (and (match_code "ashift,lshiftrt")
20067 + (ior (and (match_test "GET_CODE(XEXP(op, 1)) == CONST_INT")
20068 + (match_test "register_operand(XEXP(op, 0), GET_MODE(XEXP(op, 0)))"))
20069 + (and (match_test "GET_CODE(XEXP(op, 0)) == CONST_INT")
20070 + (match_test "register_operand(XEXP(op, 1), GET_MODE(XEXP(op, 1)))"))))
20071 + )
20072 +
20073 +
20074 +;; Predicate for second operand to and, ior and xor insn patterns
20075 +(define_predicate "avr32_logical_insn_operand"
20076 + (ior (match_operand 0 "register_operand")
20077 + (match_operand 0 "avr32_logical_shift_operand"))
20078 +)
20079 +
20080 +
20081 +;; True for avr32 comparison operators
20082 +(define_predicate "avr32_comparison_operator"
20083 + (ior (match_code "eq, ne, gt, ge, lt, le, gtu, geu, ltu, leu")
20084 + (and (match_code "unspec")
20085 + (match_test "(XINT(op, 1) == UNSPEC_COND_MI)
20086 + || (XINT(op, 1) == UNSPEC_COND_PL)"))))
20087 +
20088 +(define_predicate "avr32_cond3_comparison_operator"
20089 + (ior (match_code "eq, ne, ge, lt, geu, ltu")
20090 + (and (match_code "unspec")
20091 + (match_test "(XINT(op, 1) == UNSPEC_COND_MI)
20092 + || (XINT(op, 1) == UNSPEC_COND_PL)"))))
20093 +
20094 +;; True for avr32 comparison operand
20095 +(define_predicate "avr32_comparison_operand"
20096 + (ior (and (match_code "eq, ne, gt, ge, lt, le, gtu, geu, ltu, leu")
20097 + (match_test "(CC0_P (XEXP(op,0)) && rtx_equal_p (XEXP(op,1), const0_rtx))"))
20098 + (and (match_code "unspec")
20099 + (match_test "(XINT(op, 1) == UNSPEC_COND_MI)
20100 + || (XINT(op, 1) == UNSPEC_COND_PL)"))))
20101 +
20102 +;; True if this is a const_int with one bit set
20103 +(define_predicate "one_bit_set_operand"
20104 + (match_code "const_int")
20105 + {
20106 + int i;
20107 + int value;
20108 + int ones = 0;
20109 +
20110 + value = INTVAL(op);
20111 + for ( i = 0 ; i < 32; i++ ){
20112 + if ( value & ( 1 << i ) ){
20113 + ones++;
20114 + }
20115 + }
20116 +
20117 + return ( ones == 1 );
20118 + })
20119 +
20120 +
20121 +;; True if this is a const_int with one bit cleared
20122 +(define_predicate "one_bit_cleared_operand"
20123 + (match_code "const_int")
20124 + {
20125 + int i;
20126 + int value;
20127 + int zeroes = 0;
20128 +
20129 + value = INTVAL(op);
20130 + for ( i = 0 ; i < 32; i++ ){
20131 + if ( !(value & ( 1 << i )) ){
20132 + zeroes++;
20133 + }
20134 + }
20135 +
20136 + return ( zeroes == 1 );
20137 + })
20138 +
20139 +
20140 +;; Immediate all the low 16-bits cleared
20141 +(define_predicate "avr32_hi16_immediate_operand"
20142 + (match_code "const_int")
20143 + {
20144 + /* If the low 16-bits are zero then this
20145 + is a hi16 immediate. */
20146 + return ((INTVAL(op) & 0xffff) == 0);
20147 + }
20148 +)
20149 +
20150 +;; True if this is a register or immediate operand
20151 +(define_predicate "register_immediate_operand"
20152 + (ior (match_operand 0 "register_operand")
20153 + (match_operand 0 "immediate_operand")))
20154 +
20155 +;; True if this is a register or const_int operand
20156 +(define_predicate "register_const_int_operand"
20157 + (ior (match_operand 0 "register_operand")
20158 + (and (match_operand 0 "const_int_operand")
20159 + (match_operand 0 "immediate_operand"))))
20160 +
20161 +;; True if this is a register or const_double operand
20162 +(define_predicate "register_const_double_operand"
20163 + (ior (match_operand 0 "register_operand")
20164 + (match_operand 0 "const_double_operand")))
20165 +
20166 +;; True if this is an operand containing a label_ref.
20167 +(define_predicate "avr32_label_ref_operand"
20168 + (and (match_code "mem")
20169 + (match_test "avr32_find_symbol(op)
20170 + && (GET_CODE(avr32_find_symbol(op)) == LABEL_REF)")))
20171 +
20172 +;; True if this is a valid symbol pointing to the constant pool.
20173 +(define_predicate "avr32_const_pool_operand"
20174 + (and (match_code "symbol_ref")
20175 + (match_test "CONSTANT_POOL_ADDRESS_P(op)"))
20176 + {
20177 + return (flag_pic ? (!(symbol_mentioned_p (get_pool_constant (op))
20178 + || label_mentioned_p (get_pool_constant (op)))
20179 + || avr32_got_mentioned_p(get_pool_constant (op)))
20180 + : true);
20181 + }
20182 +)
20183 +
20184 +;; True if this is a memory reference to the constant or mini pool.
20185 +(define_predicate "avr32_const_pool_ref_operand"
20186 + (ior (match_operand 0 "avr32_label_ref_operand")
20187 + (and (match_code "mem")
20188 + (match_test "avr32_const_pool_operand(XEXP(op,0), GET_MODE(XEXP(op,0)))"))))
20189 +
20190 +
20191 +;; Legal source operand for movti insns
20192 +(define_predicate "avr32_movti_src_operand"
20193 + (ior (match_operand 0 "avr32_const_pool_ref_operand")
20194 + (ior (ior (match_operand 0 "register_immediate_operand")
20195 + (match_operand 0 "avr32_indirect_register_operand"))
20196 + (match_operand 0 "post_inc_memory_operand"))))
20197 +
20198 +;; Legal destination operand for movti insns
20199 +(define_predicate "avr32_movti_dst_operand"
20200 + (ior (ior (match_operand 0 "register_operand")
20201 + (match_operand 0 "avr32_indirect_register_operand"))
20202 + (match_operand 0 "pre_dec_memory_operand")))
20203 +
20204 +
20205 +;; True if this is a k12 offseted memory operand.
20206 +(define_predicate "avr32_k12_memory_operand"
20207 + (and (match_code "mem")
20208 + (ior (match_test "REG_P(XEXP(op, 0))")
20209 + (match_test "GET_CODE(XEXP(op, 0)) == PLUS
20210 + && REG_P(XEXP(XEXP(op, 0), 0))
20211 + && (GET_CODE(XEXP(XEXP(op, 0), 1)) == CONST_INT)
20212 + && (CONST_OK_FOR_CONSTRAINT_P(INTVAL(XEXP(XEXP(op, 0), 0)),
20213 + 'K', (mode == SImode) ? \"Ks14\" : ((mode == HImode) ? \"Ks13\" : \"Ks12\")))"))))
20214 +
20215 +;; True if this is a memory operand with an immediate displacement.
20216 +(define_predicate "avr32_imm_disp_memory_operand"
20217 + (and (match_code "mem")
20218 + (match_test "GET_CODE(XEXP(op, 0)) == PLUS
20219 + && REG_P(XEXP(XEXP(op, 0), 0))
20220 + && (GET_CODE(XEXP(XEXP(op, 0), 1)) == CONST_INT)")))
20221 +
20222 +;; True if this is a bswap operand.
20223 +(define_predicate "avr32_bswap_operand"
20224 + (ior (match_operand 0 "avr32_k12_memory_operand")
20225 + (match_operand 0 "register_operand")))
20226 +
20227 +;; True if this is a valid coprocessor insn memory operand.
20228 +(define_predicate "avr32_cop_memory_operand"
20229 + (and (match_operand 0 "memory_operand")
20230 + (not (match_test "GET_CODE(XEXP(op, 0)) == PLUS
20231 + && REG_P(XEXP(XEXP(op, 0), 0))
20232 + && (GET_CODE(XEXP(XEXP(op, 0), 1)) == CONST_INT)
20233 + && !(CONST_OK_FOR_CONSTRAINT_P(INTVAL(XEXP(XEXP(op, 0), 0)), 'K', \"Ku10\"))"))))
20234 +
20235 +;; True if this is a valid source/destination operand.
20236 +;; for moving values to/from a coprocessor
20237 +(define_predicate "avr32_cop_move_operand"
20238 + (ior (match_operand 0 "register_operand")
20239 + (match_operand 0 "avr32_cop_memory_operand")))
20240 +
20241 +
20242 +;; True if this is a valid extract byte offset for use in
20243 +;; load extracted index insns.
20244 +(define_predicate "avr32_extract_shift_operand"
20245 + (and (match_operand 0 "const_int_operand")
20246 + (match_test "(INTVAL(op) == 0) || (INTVAL(op) == 8)
20247 + || (INTVAL(op) == 16) || (INTVAL(op) == 24)")))
20248 +
20249 +;; True if this is a valid avr32 symbol operand.
20250 +(define_predicate "avr32_symbol_operand"
20251 + (and (match_code "label_ref, symbol_ref, const")
20252 + (match_test "avr32_find_symbol(op)")))
20253 +
20254 +;; True if this is a valid operand for the lda.w and call pseudo insns.
20255 +(define_predicate "avr32_address_operand"
20256 + (and (and (match_code "label_ref, symbol_ref")
20257 + (match_test "avr32_find_symbol(op)"))
20258 + (ior (match_test "TARGET_HAS_ASM_ADDR_PSEUDOS")
20259 + (match_test "flag_pic")) ))
20260 +
20261 +;; An immediate k16 address operand
20262 +(define_predicate "avr32_ks16_address_operand"
20263 + (and (match_operand 0 "address_operand")
20264 + (ior (match_test "REG_P(op)")
20265 + (match_test "GET_CODE(op) == PLUS
20266 + && ((GET_CODE(XEXP(op,0)) == CONST_INT)
20267 + || (GET_CODE(XEXP(op,1)) == CONST_INT))")) ))
20268 +
20269 +;; An offset k16 memory operand
20270 +(define_predicate "avr32_ks16_memory_operand"
20271 + (and (match_code "mem")
20272 + (match_test "avr32_ks16_address_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)))")))
20273 +
20274 +;; An immediate k11 address operand
20275 +(define_predicate "avr32_ks11_address_operand"
20276 + (and (match_operand 0 "address_operand")
20277 + (ior (match_test "REG_P(op)")
20278 + (match_test "GET_CODE(op) == PLUS
20279 + && (((GET_CODE(XEXP(op,0)) == CONST_INT)
20280 + && avr32_const_ok_for_constraint_p(INTVAL(XEXP(op,0)), 'K', \"Ks11\"))
20281 + || ((GET_CODE(XEXP(op,1)) == CONST_INT)
20282 + && avr32_const_ok_for_constraint_p(INTVAL(XEXP(op,1)), 'K', \"Ks11\")))")) ))
20283 +
20284 +;; True if this is a avr32 call operand
20285 +(define_predicate "avr32_call_operand"
20286 + (ior (ior (match_operand 0 "register_operand")
20287 + (ior (match_operand 0 "avr32_const_pool_ref_operand")
20288 + (match_operand 0 "avr32_address_operand")))
20289 + (match_test "SYMBOL_REF_RCALL_FUNCTION_P(op)")))
20290 +
20291 +;; Return true for operators performing ALU operations
20292 +
20293 +(define_predicate "alu_operator"
20294 + (match_code "ior, xor, and, plus, minus, ashift, lshiftrt, ashiftrt"))
20295 +
20296 +(define_predicate "avr32_add_shift_immediate_operand"
20297 + (and (match_operand 0 "immediate_operand")
20298 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'K', \"Ku02\")")))
20299 +
20300 +(define_predicate "avr32_cond_register_immediate_operand"
20301 + (ior (match_operand 0 "register_operand")
20302 + (and (match_operand 0 "immediate_operand")
20303 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'K', \"Ks08\")"))))
20304 +
20305 +(define_predicate "avr32_cond_immediate_operand"
20306 + (and (match_operand 0 "immediate_operand")
20307 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'I', \"Is08\")")))
20308 +
20309 +
20310 +(define_predicate "avr32_cond_move_operand"
20311 + (ior (ior (match_operand 0 "register_operand")
20312 + (and (match_operand 0 "immediate_operand")
20313 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'K', \"Ks08\")")))
20314 + (and (match_test "TARGET_V2_INSNS")
20315 + (match_operand 0 "memory_operand"))))
20316 +
20317 +(define_predicate "avr32_mov_immediate_operand"
20318 + (and (match_operand 0 "immediate_operand")
20319 + (match_test "avr32_const_ok_for_move(INTVAL(op))")))
20320 +
20321 +
20322 +(define_predicate "avr32_rmw_address_operand"
20323 + (ior (and (match_code "symbol_ref")
20324 + (match_test "({rtx symbol = avr32_find_symbol(op); \
20325 + symbol && (GET_CODE (symbol) == SYMBOL_REF) && SYMBOL_REF_RMW_ADDR(symbol);})"))
20326 + (and (match_operand 0 "immediate_operand")
20327 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'K', \"Ks17\")")))
20328 + {
20329 + return TARGET_RMW && !flag_pic;
20330 + }
20331 +)
20332 +
20333 +(define_predicate "avr32_rmw_memory_operand"
20334 + (and (match_code "mem")
20335 + (match_test "!volatile_refs_p(op) && (GET_MODE(op) == SImode) &&
20336 + avr32_rmw_address_operand(XEXP(op, 0), GET_MODE(XEXP(op, 0)))")))
20337 +
20338 +(define_predicate "avr32_rmw_memory_or_register_operand"
20339 + (ior (match_operand 0 "avr32_rmw_memory_operand")
20340 + (match_operand 0 "register_operand")))
20341 +
20342 +(define_predicate "avr32_non_rmw_memory_operand"
20343 + (and (not (match_operand 0 "avr32_rmw_memory_operand"))
20344 + (match_operand 0 "memory_operand")))
20345 +
20346 +(define_predicate "avr32_non_rmw_general_operand"
20347 + (and (not (match_operand 0 "avr32_rmw_memory_operand"))
20348 + (match_operand 0 "general_operand")))
20349 +
20350 +(define_predicate "avr32_non_rmw_nonimmediate_operand"
20351 + (and (not (match_operand 0 "avr32_rmw_memory_operand"))
20352 + (match_operand 0 "nonimmediate_operand")))
20353 +
20354 +;; Return true if the operand is the 1.0f constant.
20355 +
20356 +(define_predicate "const_1f_operand"
20357 + (match_code "const_int,const_double")
20358 +{
20359 + return (op == CONST1_RTX (SFmode));
20360 +})
20361 --- /dev/null
20362 +++ b/gcc/config/avr32/simd.md
20363 @@ -0,0 +1,145 @@
20364 +;; AVR32 machine description file for SIMD instructions.
20365 +;; Copyright 2003-2006 Atmel Corporation.
20366 +;;
20367 +;; Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
20368 +;;
20369 +;; This file is part of GCC.
20370 +;;
20371 +;; This program is free software; you can redistribute it and/or modify
20372 +;; it under the terms of the GNU General Public License as published by
20373 +;; the Free Software Foundation; either version 2 of the License, or
20374 +;; (at your option) any later version.
20375 +;;
20376 +;; This program is distributed in the hope that it will be useful,
20377 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20378 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20379 +;; GNU General Public License for more details.
20380 +;;
20381 +;; You should have received a copy of the GNU General Public License
20382 +;; along with this program; if not, write to the Free Software
20383 +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20384 +
20385 +;; -*- Mode: Scheme -*-
20386 +
20387 +
20388 +;; Vector modes
20389 +(define_mode_iterator VECM [V2HI V4QI])
20390 +(define_mode_attr size [(V2HI "h") (V4QI "b")])
20391 +
20392 +(define_insn "add<mode>3"
20393 + [(set (match_operand:VECM 0 "register_operand" "=r")
20394 + (plus:VECM (match_operand:VECM 1 "register_operand" "r")
20395 + (match_operand:VECM 2 "register_operand" "r")))]
20396 + "TARGET_SIMD"
20397 + "padd.<size>\t%0, %1, %2"
20398 + [(set_attr "length" "4")
20399 + (set_attr "type" "alu")])
20400 +
20401 +
20402 +(define_insn "sub<mode>3"
20403 + [(set (match_operand:VECM 0 "register_operand" "=r")
20404 + (minus:VECM (match_operand:VECM 1 "register_operand" "r")
20405 + (match_operand:VECM 2 "register_operand" "r")))]
20406 + "TARGET_SIMD"
20407 + "psub.<size>\t%0, %1, %2"
20408 + [(set_attr "length" "4")
20409 + (set_attr "type" "alu")])
20410 +
20411 +
20412 +(define_insn "abs<mode>2"
20413 + [(set (match_operand:VECM 0 "register_operand" "=r")
20414 + (abs:VECM (match_operand:VECM 1 "register_operand" "r")))]
20415 + "TARGET_SIMD"
20416 + "pabs.s<size>\t%0, %1"
20417 + [(set_attr "length" "4")
20418 + (set_attr "type" "alu")])
20419 +
20420 +(define_insn "ashl<mode>3"
20421 + [(set (match_operand:VECM 0 "register_operand" "=r")
20422 + (ashift:VECM (match_operand:VECM 1 "register_operand" "r")
20423 + (match_operand:SI 2 "immediate_operand" "Ku04")))]
20424 + "TARGET_SIMD"
20425 + "plsl.<size>\t%0, %1, %2"
20426 + [(set_attr "length" "4")
20427 + (set_attr "type" "alu")])
20428 +
20429 +(define_insn "ashr<mode>3"
20430 + [(set (match_operand:VECM 0 "register_operand" "=r")
20431 + (ashiftrt:VECM (match_operand:VECM 1 "register_operand" "r")
20432 + (match_operand:SI 2 "immediate_operand" "Ku04")))]
20433 + "TARGET_SIMD"
20434 + "pasr.<size>\t%0, %1, %2"
20435 + [(set_attr "length" "4")
20436 + (set_attr "type" "alu")])
20437 +
20438 +(define_insn "lshr<mode>3"
20439 + [(set (match_operand:VECM 0 "register_operand" "=r")
20440 + (lshiftrt:VECM (match_operand:VECM 1 "register_operand" "r")
20441 + (match_operand:SI 2 "immediate_operand" "Ku04")))]
20442 + "TARGET_SIMD"
20443 + "plsr.<size>\t%0, %1, %2"
20444 + [(set_attr "length" "4")
20445 + (set_attr "type" "alu")])
20446 +
20447 +(define_insn "smaxv2hi3"
20448 + [(set (match_operand:V2HI 0 "register_operand" "=r")
20449 + (smax:V2HI (match_operand:V2HI 1 "register_operand" "r")
20450 + (match_operand:V2HI 2 "register_operand" "r")))]
20451 +
20452 + "TARGET_SIMD"
20453 + "pmax.sh\t%0, %1, %2"
20454 + [(set_attr "length" "4")
20455 + (set_attr "type" "alu")])
20456 +
20457 +(define_insn "sminv2hi3"
20458 + [(set (match_operand:V2HI 0 "register_operand" "=r")
20459 + (smin:V2HI (match_operand:V2HI 1 "register_operand" "r")
20460 + (match_operand:V2HI 2 "register_operand" "r")))]
20461 +
20462 + "TARGET_SIMD"
20463 + "pmin.sh\t%0, %1, %2"
20464 + [(set_attr "length" "4")
20465 + (set_attr "type" "alu")])
20466 +
20467 +(define_insn "umaxv4qi3"
20468 + [(set (match_operand:V4QI 0 "register_operand" "=r")
20469 + (umax:V4QI (match_operand:V4QI 1 "register_operand" "r")
20470 + (match_operand:V4QI 2 "register_operand" "r")))]
20471 +
20472 + "TARGET_SIMD"
20473 + "pmax.ub\t%0, %1, %2"
20474 + [(set_attr "length" "4")
20475 + (set_attr "type" "alu")])
20476 +
20477 +(define_insn "uminv4qi3"
20478 + [(set (match_operand:V4QI 0 "register_operand" "=r")
20479 + (umin:V4QI (match_operand:V4QI 1 "register_operand" "r")
20480 + (match_operand:V4QI 2 "register_operand" "r")))]
20481 +
20482 + "TARGET_SIMD"
20483 + "pmin.ub\t%0, %1, %2"
20484 + [(set_attr "length" "4")
20485 + (set_attr "type" "alu")])
20486 +
20487 +
20488 +(define_insn "addsubv2hi"
20489 + [(set (match_operand:V2HI 0 "register_operand" "=r")
20490 + (vec_concat:V2HI
20491 + (plus:HI (match_operand:HI 1 "register_operand" "r")
20492 + (match_operand:HI 2 "register_operand" "r"))
20493 + (minus:HI (match_dup 1) (match_dup 2))))]
20494 + "TARGET_SIMD"
20495 + "paddsub.h\t%0, %1:b, %2:b"
20496 + [(set_attr "length" "4")
20497 + (set_attr "type" "alu")])
20498 +
20499 +(define_insn "subaddv2hi"
20500 + [(set (match_operand:V2HI 0 "register_operand" "=r")
20501 + (vec_concat:V2HI
20502 + (minus:HI (match_operand:HI 1 "register_operand" "r")
20503 + (match_operand:HI 2 "register_operand" "r"))
20504 + (plus:HI (match_dup 1) (match_dup 2))))]
20505 + "TARGET_SIMD"
20506 + "psubadd.h\t%0, %1:b, %2:b"
20507 + [(set_attr "length" "4")
20508 + (set_attr "type" "alu")])
20509 --- /dev/null
20510 +++ b/gcc/config/avr32/sync.md
20511 @@ -0,0 +1,244 @@
20512 +;;=================================================================
20513 +;; Atomic operations
20514 +;;=================================================================
20515 +
20516 +
20517 +(define_insn "sync_compare_and_swapsi"
20518 + [(set (match_operand:SI 0 "register_operand" "=&r,&r")
20519 + (match_operand:SI 1 "memory_operand" "+RKs16,+RKs16"))
20520 + (set (match_dup 1)
20521 + (unspec_volatile:SI
20522 + [(match_dup 1)
20523 + (match_operand:SI 2 "register_immediate_operand" "r,Ks21")
20524 + (match_operand:SI 3 "register_operand" "r,r")]
20525 + VUNSPEC_SYNC_CMPXCHG)) ]
20526 + ""
20527 + "0:
20528 + ssrf\t5
20529 + ld.w\t%0,%1
20530 + cp.w\t%0,%2
20531 + brne\t0f
20532 + stcond\t%1, %3
20533 + brne\t0b
20534 + 0:
20535 + "
20536 + [(set_attr "length" "16,18")
20537 + (set_attr "cc" "clobber")]
20538 + )
20539 +
20540 +
20541 +(define_code_iterator atomic_op [plus minus and ior xor])
20542 +(define_code_attr atomic_asm_insn [(plus "add") (minus "sub") (and "and") (ior "or") (xor "eor")])
20543 +(define_code_attr atomic_insn [(plus "add") (minus "sub") (and "and") (ior "ior") (xor "xor")])
20544 +
20545 +(define_insn "sync_loadsi"
20546 + ; NB! Put an early clobber on the destination operand to
20547 + ; avoid gcc using the same register in the source and
20548 + ; destination. This is done in order to avoid gcc to
20549 + ; clobber the source operand since these instructions
20550 + ; are actually inside a "loop".
20551 + [(set (match_operand:SI 0 "register_operand" "=&r")
20552 + (unspec_volatile:SI
20553 + [(match_operand:SI 1 "avr32_ks16_memory_operand" "RKs16")
20554 + (label_ref (match_operand 2 "" ""))]
20555 + VUNSPEC_SYNC_SET_LOCK_AND_LOAD) )]
20556 + ""
20557 + "%2:
20558 + ssrf\t5
20559 + ld.w\t%0,%1"
20560 + [(set_attr "length" "6")
20561 + (set_attr "cc" "clobber")]
20562 + )
20563 +
20564 +(define_insn "sync_store_if_lock"
20565 + [(set (match_operand:SI 0 "avr32_ks16_memory_operand" "=RKs16")
20566 + (unspec_volatile:SI
20567 + [(match_operand:SI 1 "register_operand" "r")
20568 + (label_ref (match_operand 2 "" ""))]
20569 + VUNSPEC_SYNC_STORE_IF_LOCK) )]
20570 + ""
20571 + "stcond\t%0, %1
20572 + brne\t%2"
20573 + [(set_attr "length" "6")
20574 + (set_attr "cc" "clobber")]
20575 + )
20576 +
20577 +
20578 +(define_expand "sync_<atomic_insn>si"
20579 + [(set (match_dup 2)
20580 + (unspec_volatile:SI
20581 + [(match_operand:SI 0 "avr32_ks16_memory_operand" "")
20582 + (match_dup 3)]
20583 + VUNSPEC_SYNC_SET_LOCK_AND_LOAD))
20584 + (set (match_dup 2)
20585 + (atomic_op:SI (match_dup 2)
20586 + (match_operand:SI 1 "register_immediate_operand" "")))
20587 + (set (match_dup 0)
20588 + (unspec_volatile:SI
20589 + [(match_dup 2)
20590 + (match_dup 3)]
20591 + VUNSPEC_SYNC_STORE_IF_LOCK) )
20592 + (use (match_dup 1))
20593 + (use (match_dup 4))]
20594 + ""
20595 + {
20596 + rtx *mem_expr = &operands[0];
20597 + rtx ptr_reg;
20598 + if ( !avr32_ks16_memory_operand (*mem_expr, GET_MODE (*mem_expr)) )
20599 + {
20600 + ptr_reg = force_reg (Pmode, XEXP (*mem_expr, 0));
20601 + XEXP (*mem_expr, 0) = ptr_reg;
20602 + }
20603 + else
20604 + {
20605 + rtx address = XEXP (*mem_expr, 0);
20606 + if ( REG_P (address) )
20607 + ptr_reg = address;
20608 + else if ( REG_P (XEXP (address, 0)) )
20609 + ptr_reg = XEXP (address, 0);
20610 + else
20611 + ptr_reg = XEXP (address, 1);
20612 + }
20613 +
20614 + operands[2] = gen_reg_rtx (SImode);
20615 + operands[3] = gen_rtx_LABEL_REF(Pmode, gen_label_rtx ());
20616 + operands[4] = ptr_reg;
20617 +
20618 + }
20619 + )
20620 +
20621 +
20622 +
20623 +(define_expand "sync_old_<atomic_insn>si"
20624 + [(set (match_operand:SI 0 "register_operand" "")
20625 + (unspec_volatile:SI
20626 + [(match_operand:SI 1 "avr32_ks16_memory_operand" "")
20627 + (match_dup 4)]
20628 + VUNSPEC_SYNC_SET_LOCK_AND_LOAD))
20629 + (set (match_dup 3)
20630 + (atomic_op:SI (match_dup 0)
20631 + (match_operand:SI 2 "register_immediate_operand" "")))
20632 + (set (match_dup 1)
20633 + (unspec_volatile:SI
20634 + [(match_dup 3)
20635 + (match_dup 4)]
20636 + VUNSPEC_SYNC_STORE_IF_LOCK) )
20637 + (use (match_dup 2))
20638 + (use (match_dup 5))]
20639 + ""
20640 + {
20641 + rtx *mem_expr = &operands[1];
20642 + rtx ptr_reg;
20643 + if ( !avr32_ks16_memory_operand (*mem_expr, GET_MODE (*mem_expr)) )
20644 + {
20645 + ptr_reg = force_reg (Pmode, XEXP (*mem_expr, 0));
20646 + XEXP (*mem_expr, 0) = ptr_reg;
20647 + }
20648 + else
20649 + {
20650 + rtx address = XEXP (*mem_expr, 0);
20651 + if ( REG_P (address) )
20652 + ptr_reg = address;
20653 + else if ( REG_P (XEXP (address, 0)) )
20654 + ptr_reg = XEXP (address, 0);
20655 + else
20656 + ptr_reg = XEXP (address, 1);
20657 + }
20658 +
20659 + operands[3] = gen_reg_rtx (SImode);
20660 + operands[4] = gen_rtx_LABEL_REF(Pmode, gen_label_rtx ());
20661 + operands[5] = ptr_reg;
20662 + }
20663 + )
20664 +
20665 +(define_expand "sync_new_<atomic_insn>si"
20666 + [(set (match_operand:SI 0 "register_operand" "")
20667 + (unspec_volatile:SI
20668 + [(match_operand:SI 1 "avr32_ks16_memory_operand" "")
20669 + (match_dup 3)]
20670 + VUNSPEC_SYNC_SET_LOCK_AND_LOAD))
20671 + (set (match_dup 0)
20672 + (atomic_op:SI (match_dup 0)
20673 + (match_operand:SI 2 "register_immediate_operand" "")))
20674 + (set (match_dup 1)
20675 + (unspec_volatile:SI
20676 + [(match_dup 0)
20677 + (match_dup 3)]
20678 + VUNSPEC_SYNC_STORE_IF_LOCK) )
20679 + (use (match_dup 2))
20680 + (use (match_dup 4))]
20681 + ""
20682 + {
20683 + rtx *mem_expr = &operands[1];
20684 + rtx ptr_reg;
20685 + if ( !avr32_ks16_memory_operand (*mem_expr, GET_MODE (*mem_expr)) )
20686 + {
20687 + ptr_reg = force_reg (Pmode, XEXP (*mem_expr, 0));
20688 + XEXP (*mem_expr, 0) = ptr_reg;
20689 + }
20690 + else
20691 + {
20692 + rtx address = XEXP (*mem_expr, 0);
20693 + if ( REG_P (address) )
20694 + ptr_reg = address;
20695 + else if ( REG_P (XEXP (address, 0)) )
20696 + ptr_reg = XEXP (address, 0);
20697 + else
20698 + ptr_reg = XEXP (address, 1);
20699 + }
20700 +
20701 + operands[3] = gen_rtx_LABEL_REF(Pmode, gen_label_rtx ());
20702 + operands[4] = ptr_reg;
20703 + }
20704 + )
20705 +
20706 +
20707 +;(define_insn "sync_<atomic_insn>si"
20708 +; [(set (match_operand:SI 0 "memory_operand" "+RKs16")
20709 +; (unspec_volatile:SI
20710 +; [(atomic_op:SI (match_dup 0)
20711 +; (match_operand:SI 1 "register_operand" "r"))]
20712 +; VUNSPEC_SYNC_CMPXCHG))
20713 +; (clobber (match_scratch:SI 2 "=&r"))]
20714 +; ""
20715 +; "0:
20716 +; ssrf\t5
20717 +; ld.w\t%2,%0
20718 +; <atomic_asm_insn>\t%2,%1
20719 +; stcond\t%0, %2
20720 +; brne\t0b
20721 +; "
20722 +; [(set_attr "length" "14")
20723 +; (set_attr "cc" "clobber")]
20724 +; )
20725 +;
20726 +;(define_insn "sync_new_<atomic_insn>si"
20727 +; [(set (match_operand:SI 1 "memory_operand" "+RKs16")
20728 +; (unspec_volatile:SI
20729 +; [(atomic_op:SI (match_dup 1)
20730 +; (match_operand:SI 2 "register_operand" "r"))]
20731 +; VUNSPEC_SYNC_CMPXCHG))
20732 +; (set (match_operand:SI 0 "register_operand" "=&r")
20733 +; (atomic_op:SI (match_dup 1)
20734 +; (match_dup 2)))]
20735 +; ""
20736 +; "0:
20737 +; ssrf\t5
20738 +; ld.w\t%0,%1
20739 +; <atomic_asm_insn>\t%0,%2
20740 +; stcond\t%1, %0
20741 +; brne\t0b
20742 +; "
20743 +; [(set_attr "length" "14")
20744 +; (set_attr "cc" "clobber")]
20745 +; )
20746 +
20747 +(define_insn "sync_lock_test_and_setsi"
20748 + [ (set (match_operand:SI 0 "register_operand" "=&r")
20749 + (match_operand:SI 1 "memory_operand" "+RKu00"))
20750 + (set (match_dup 1)
20751 + (match_operand:SI 2 "register_operand" "r")) ]
20752 + ""
20753 + "xchg\t%0, %p1, %2"
20754 + [(set_attr "length" "4")]
20755 + )
20756 --- /dev/null
20757 +++ b/gcc/config/avr32/t-avr32
20758 @@ -0,0 +1,102 @@
20759 +
20760 +MD_INCLUDES= $(srcdir)/config/avr32/avr32.md \
20761 + $(srcdir)/config/avr32/sync.md \
20762 + $(srcdir)/config/avr32/simd.md \
20763 + $(srcdir)/config/avr32/predicates.md
20764 +
20765 +s-config s-conditions s-flags s-codes s-constants s-emit s-recog s-preds \
20766 + s-opinit s-extract s-peep s-attr s-attrtab s-output: $(MD_INCLUDES)
20767 +
20768 +# We want fine grained libraries, so use the new code
20769 +# to build the floating point emulation libraries.
20770 +FPBIT = fp-bit.c
20771 +DPBIT = dp-bit.c
20772 +
20773 +LIB1ASMSRC = avr32/lib1funcs.S
20774 +LIB1ASMFUNCS = _avr32_f64_mul _avr32_f64_mul_fast _avr32_f64_addsub _avr32_f64_addsub_fast _avr32_f64_to_u32 \
20775 + _avr32_f64_to_s32 _avr32_f64_to_u64 _avr32_f64_to_s64 _avr32_u32_to_f64 \
20776 + _avr32_s32_to_f64 _avr32_f64_cmp_eq _avr32_f64_cmp_ge _avr32_f64_cmp_lt \
20777 + _avr32_f32_cmp_eq _avr32_f32_cmp_ge _avr32_f32_cmp_lt _avr32_f64_div _avr32_f64_div_fast \
20778 + _avr32_f32_div _avr32_f32_div_fast _avr32_f32_addsub _avr32_f32_addsub_fast \
20779 + _avr32_f32_mul _avr32_s32_to_f32 _avr32_u32_to_f32 _avr32_f32_to_s32 \
20780 + _avr32_f32_to_u32 _avr32_f32_to_f64 _avr32_f64_to_f32 _mulsi3
20781 +
20782 +#LIB2FUNCS_EXTRA += $(srcdir)/config/avr32/lib2funcs.S
20783 +
20784 +MULTILIB_OPTIONS = march=ap/march=ucr1/march=ucr2/march=ucr2nomul/march=ucr3/march=ucr3fp
20785 +MULTILIB_DIRNAMES = ap ucr1 ucr2 ucr2nomul ucr3 ucr3fp
20786 +MULTILIB_EXCEPTIONS =
20787 +MULTILIB_MATCHES += march?ap=mpart?ap7000
20788 +MULTILIB_MATCHES += march?ap=mpart?ap7001
20789 +MULTILIB_MATCHES += march?ap=mpart?ap7002
20790 +MULTILIB_MATCHES += march?ap=mpart?ap7200
20791 +MULTILIB_MATCHES += march?ucr1=march?uc
20792 +MULTILIB_MATCHES += march?ucr1=mpart?uc3a0512es
20793 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0128
20794 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0256
20795 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0512
20796 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1128
20797 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1256
20798 +MULTILIB_MATCHES += march?ucr1=mpart?uc3a1512es
20799 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1512
20800 +MULTILIB_MATCHES += march?ucr2nomul=mpart?uc3a3revd
20801 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a364
20802 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a364s
20803 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3128
20804 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3128s
20805 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3256
20806 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3256s
20807 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b064
20808 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0128
20809 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0256es
20810 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0256
20811 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b0512
20812 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b0512revc
20813 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b164
20814 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1128
20815 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1256es
20816 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1256
20817 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b1512
20818 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b1512revc
20819 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c0512crevc
20820 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c1512crevc
20821 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c2512crevc
20822 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l0256
20823 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l0128
20824 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l064
20825 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l032
20826 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l016
20827 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l064revb
20828 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c064c
20829 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c0128c
20830 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c0256c
20831 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c0512c
20832 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c164c
20833 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c1128c
20834 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c1256c
20835 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c1512c
20836 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c264c
20837 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c2128c
20838 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c2256c
20839 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c2512c
20840 +MULTILIB_MATCHES += march?ucr3=mpart?mxt768e
20841 +
20842 +
20843 +EXTRA_MULTILIB_PARTS = crtbegin.o crtbeginS.o crtend.o crtendS.o crti.o crtn.o
20844 +
20845 +CRTSTUFF_T_CFLAGS = -mrelax
20846 +CRTSTUFF_T_CFLAGS_S = -mrelax -fPIC
20847 +TARGET_LIBGCC2_CFLAGS += -mrelax
20848 +
20849 +LIBGCC = stmp-multilib
20850 +INSTALL_LIBGCC = install-multilib
20851 +
20852 +fp-bit.c: $(srcdir)/config/fp-bit.c
20853 + echo '#define FLOAT' > fp-bit.c
20854 + cat $(srcdir)/config/fp-bit.c >> fp-bit.c
20855 +
20856 +dp-bit.c: $(srcdir)/config/fp-bit.c
20857 + cat $(srcdir)/config/fp-bit.c > dp-bit.c
20858 +
20859 +
20860 +
20861 --- /dev/null
20862 +++ b/gcc/config/avr32/t-avr32-linux
20863 @@ -0,0 +1,102 @@
20864 +
20865 +MD_INCLUDES= $(srcdir)/config/avr32/avr32.md \
20866 + $(srcdir)/config/avr32/sync.md \
20867 + $(srcdir)/config/avr32/simd.md \
20868 + $(srcdir)/config/avr32/predicates.md
20869 +
20870 +s-config s-conditions s-flags s-codes s-constants s-emit s-recog s-preds \
20871 + s-opinit s-extract s-peep s-attr s-attrtab s-output: $(MD_INCLUDES)
20872 +
20873 +# We want fine grained libraries, so use the new code
20874 +# to build the floating point emulation libraries.
20875 +FPBIT = fp-bit.c
20876 +DPBIT = dp-bit.c
20877 +
20878 +LIB1ASMSRC = avr32/lib1funcs.S
20879 +LIB1ASMFUNCS = _avr32_f64_mul _avr32_f64_mul_fast _avr32_f64_addsub _avr32_f64_addsub_fast _avr32_f64_to_u32 \
20880 + _avr32_f64_to_s32 _avr32_f64_to_u64 _avr32_f64_to_s64 _avr32_u32_to_f64 \
20881 + _avr32_s32_to_f64 _avr32_f64_cmp_eq _avr32_f64_cmp_ge _avr32_f64_cmp_lt \
20882 + _avr32_f32_cmp_eq _avr32_f32_cmp_ge _avr32_f32_cmp_lt _avr32_f64_div _avr32_f64_div_fast \
20883 + _avr32_f32_div _avr32_f32_div_fast _avr32_f32_addsub _avr32_f32_addsub_fast \
20884 + _avr32_f32_mul _avr32_s32_to_f32 _avr32_u32_to_f32 _avr32_f32_to_s32 \
20885 + _avr32_f32_to_u32 _avr32_f32_to_f64 _avr32_f64_to_f32 _mulsi3
20886 +
20887 +#LIB2FUNCS_EXTRA += $(srcdir)/config/avr32/lib2funcs.S
20888 +
20889 +MULTILIB_OPTIONS = march=ap/march=ucr1/march=ucr2/march=ucr2nomul/march=ucr3/march=ucr3fp
20890 +MULTILIB_DIRNAMES = ap ucr1 ucr2 ucr2nomul ucr3 ucr3fp
20891 +MULTILIB_EXCEPTIONS =
20892 +MULTILIB_MATCHES += march?ap=mpart?ap7000
20893 +MULTILIB_MATCHES += march?ap=mpart?ap7001
20894 +MULTILIB_MATCHES += march?ap=mpart?ap7002
20895 +MULTILIB_MATCHES += march?ap=mpart?ap7200
20896 +MULTILIB_MATCHES += march?ucr1=march?uc
20897 +MULTILIB_MATCHES += march?ucr1=mpart?uc3a0512es
20898 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0128
20899 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0256
20900 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0512
20901 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1128
20902 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1256
20903 +MULTILIB_MATCHES += march?ucr1=mpart?uc3a1512es
20904 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1512
20905 +MULTILIB_MATCHES += march?ucr2nomul=mpart?uc3a3revd
20906 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a364
20907 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a364s
20908 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3128
20909 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3128s
20910 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3256
20911 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3256s
20912 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b064
20913 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0128
20914 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0256es
20915 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0256
20916 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b0512
20917 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b0512revc
20918 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b164
20919 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1128
20920 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1256es
20921 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1256
20922 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b1512
20923 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b1512revc
20924 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c0512crevc
20925 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c1512crevc
20926 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c2512crevc
20927 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l0256
20928 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l0128
20929 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l064
20930 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l032
20931 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l016
20932 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l064revb
20933 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c064c
20934 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c0128c
20935 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c0256c
20936 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c0512c
20937 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c164c
20938 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c1128c
20939 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c1256c
20940 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c1512c
20941 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c264c
20942 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c2128c
20943 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c2256c
20944 +MULTILIB_MATCHES += march?ucr3fp=mpart?uc3c2512c
20945 +MULTILIB_MATCHES += march?ucr3=mpart?mxt768e
20946 +
20947 +
20948 +EXTRA_MULTILIB_PARTS = crtbegin.o crtbeginS.o crtend.o crtendS.o
20949 +
20950 +CRTSTUFF_T_CFLAGS = -mrelax
20951 +CRTSTUFF_T_CFLAGS_S = -mrelax -fPIC
20952 +TARGET_LIBGCC2_CFLAGS += -mrelax
20953 +
20954 +LIBGCC = stmp-multilib
20955 +INSTALL_LIBGCC = install-multilib
20956 +
20957 +fp-bit.c: $(srcdir)/config/fp-bit.c
20958 + echo '#define FLOAT' > fp-bit.c
20959 + cat $(srcdir)/config/fp-bit.c >> fp-bit.c
20960 +
20961 +dp-bit.c: $(srcdir)/config/fp-bit.c
20962 + cat $(srcdir)/config/fp-bit.c > dp-bit.c
20963 +
20964 +
20965 +
20966 --- /dev/null
20967 +++ b/gcc/config/avr32/t-elf
20968 @@ -0,0 +1,16 @@
20969 +
20970 +# Assemble startup files.
20971 +$(T)crti.o: $(srcdir)/config/avr32/crti.asm $(GCC_PASSES)
20972 + $(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) $(INCLUDES) \
20973 + -c -o $(T)crti.o -x assembler-with-cpp $(srcdir)/config/avr32/crti.asm
20974 +
20975 +$(T)crtn.o: $(srcdir)/config/avr32/crtn.asm $(GCC_PASSES)
20976 + $(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) $(INCLUDES) \
20977 + -c -o $(T)crtn.o -x assembler-with-cpp $(srcdir)/config/avr32/crtn.asm
20978 +
20979 +
20980 +# Build the libraries for both hard and soft floating point
20981 +EXTRA_MULTILIB_PARTS = crtbegin.o crtbeginS.o crtend.o crtendS.o crti.o crtn.o
20982 +
20983 +LIBGCC = stmp-multilib
20984 +INSTALL_LIBGCC = install-multilib
20985 --- /dev/null
20986 +++ b/gcc/config/avr32/uc3fpu.md
20987 @@ -0,0 +1,198 @@
20988 +;; AVR32 machine description file for Floating-Point instructions.
20989 +;; Copyright 2003-2006 Atmel Corporation.
20990 +;;
20991 +;;
20992 +;; This file is part of GCC.
20993 +;;
20994 +;; This program is free software; you can redistribute it and/or modify
20995 +;; it under the terms of the GNU General Public License as published by
20996 +;; the Free Software Foundation; either version 2 of the License, or
20997 +;; (at your option) any later version.
20998 +;;
20999 +;; This program is distributed in the hope that it will be useful,
21000 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21001 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21002 +;; GNU General Public License for more details.
21003 +;;
21004 +;; You should have received a copy of the GNU General Public License
21005 +;; along with this program; if not, write to the Free Software
21006 +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21007 +
21008 +(define_insn "*movsf_uc3fp"
21009 + [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,r,m")
21010 + (match_operand:SF 1 "general_operand" "r,G,m,r"))]
21011 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21012 + "@
21013 + mov\t%0, %1
21014 + mov\t%0, %1
21015 + ld.w\t%0, %1
21016 + st.w\t%0, %1"
21017 + [(set_attr "length" "2,4,4,4")
21018 + (set_attr "type" "alu,alu,load,store")])
21019 +
21020 +(define_insn "mulsf3"
21021 + [(set (match_operand:SF 0 "register_operand" "=r")
21022 + (mult:SF (match_operand:SF 1 "register_operand" "r")
21023 + (match_operand:SF 2 "register_operand" "r")))]
21024 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21025 + "fmul.s\t%0, %1, %2"
21026 + [(set_attr "length" "4")
21027 + (set_attr "type" "fmul")])
21028 +
21029 +(define_insn "nmulsf3"
21030 + [(set (match_operand:SF 0 "register_operand" "=r")
21031 + (neg:SF (mult:SF (match_operand:SF 1 "register_operand" "%r")
21032 + (match_operand:SF 2 "register_operand" "r"))))]
21033 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21034 + "fnmul.s\t%0, %1, %2"
21035 + [(set_attr "length" "4")
21036 + (set_attr "type" "fmul")])
21037 +
21038 +(define_insn "macsf3"
21039 + [(set (match_operand:SF 0 "register_operand" "=r")
21040 + (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "r")
21041 + (match_operand:SF 2 "register_operand" "r"))
21042 + (match_operand:SF 3 "register_operand" "r")))]
21043 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21044 + "fmac.s\t%0, %3, %1, %2"
21045 + [(set_attr "length" "4")
21046 + (set_attr "type" "fmul")])
21047 +
21048 +;(define_insn "nmacsf3"
21049 +; [(set (match_operand:SF 0 "register_operand" "=r")
21050 +; (plus:SF (neg:SF (match_operand:SF 1 "register_operand" "r"))
21051 +; (mult:SF(match_operand:SF 2 "register_operand" "r")
21052 +; (match_operand:SF 3 "register_operand" "r"))))]
21053 +; "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21054 +; "fnmac.s\t%0, %1, %2, %3"
21055 +; [(set_attr "length" "4")
21056 +; (set_attr "type" "fmul")])
21057 +
21058 +(define_insn "nmacsf3"
21059 + [(set (match_operand:SF 0 "register_operand" "=r")
21060 + (minus:SF (mult:SF (match_operand:SF 2 "register_operand" "r")
21061 + (match_operand:SF 3 "register_operand" "r"))
21062 + (match_operand:SF 1 "register_operand" "r")))]
21063 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21064 + "fnmac.s\t%0, %1, %2, %3"
21065 + [(set_attr "length" "4")
21066 + (set_attr "type" "fmul")])
21067 +
21068 +(define_insn "msubacsf3"
21069 + [(set (match_operand:SF 0 "register_operand" "=r")
21070 + (minus:SF (match_operand:SF 3 "register_operand" "r")
21071 + (mult:SF (match_operand:SF 1 "register_operand" "r")
21072 + (match_operand:SF 2 "register_operand" "r"))))]
21073 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21074 + "fmsc.s\t%0, %3, %1, %2"
21075 + [(set_attr "length" "4")
21076 + (set_attr "type" "fmul")])
21077 +
21078 +(define_insn "nmsubacsf3"
21079 + [(set (match_operand:SF 0 "register_operand" "=r")
21080 + (minus:SF (neg:SF (mult:SF (match_operand:SF 1 "register_operand" "r")
21081 + (match_operand:SF 2 "register_operand" "r")))
21082 + (match_operand:SF 3 "register_operand" "r")))]
21083 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21084 + "fnmsc.s\t%0, %3, %1, %2"
21085 + [(set_attr "length" "4")
21086 + (set_attr "type" "fmul")])
21087 +
21088 +(define_insn "addsf3"
21089 + [(set (match_operand:SF 0 "register_operand" "=r")
21090 + (plus:SF (match_operand:SF 1 "register_operand" "%r")
21091 + (match_operand:SF 2 "register_operand" "r")))]
21092 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21093 + "fadd.s\t%0, %1, %2"
21094 + [(set_attr "length" "4")
21095 + (set_attr "type" "fmul")])
21096 +
21097 +(define_insn "subsf3"
21098 + [(set (match_operand:SF 0 "register_operand" "=r")
21099 + (minus:SF (match_operand:SF 1 "register_operand" "r")
21100 + (match_operand:SF 2 "register_operand" "r")))]
21101 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21102 + "fsub.s\t%0, %1, %2"
21103 + [(set_attr "length" "4")
21104 + (set_attr "type" "fmul")])
21105 +
21106 +(define_insn "fixuns_truncsfsi2"
21107 + [(set (match_operand:SI 0 "register_operand" "=r")
21108 + (unsigned_fix:SI (match_operand:SF 1 "register_operand" "r")))]
21109 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21110 + "fcastrs.uw\t%0, %1"
21111 + [(set_attr "length" "4")])
21112 +
21113 +(define_insn "fix_truncsfsi2"
21114 + [(set (match_operand:SI 0 "register_operand" "=r")
21115 + (fix:SI (match_operand:SF 1 "register_operand" "r")))]
21116 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21117 + "fcastrs.sw\t%0, %1"
21118 + [(set_attr "length" "4")])
21119 +
21120 +(define_insn "floatunssisf2"
21121 + [(set (match_operand:SF 0 "register_operand" "=r")
21122 + (unsigned_float:SF (match_operand:SI 1 "register_operand" "r")))]
21123 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21124 + "fcastuw.s\t%0, %1"
21125 + [(set_attr "length" "4")])
21126 +
21127 +(define_insn "floatsisf2"
21128 + [(set (match_operand:SF 0 "register_operand" "=r")
21129 + (float:SF (match_operand:SI 1 "register_operand" "r")))]
21130 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21131 + "fcastsw.s\t%0, %1"
21132 + [(set_attr "length" "4")])
21133 +
21134 +(define_insn "cmpsf_internal_uc3fp"
21135 + [(set (cc0)
21136 + (compare:CC
21137 + (match_operand:SF 0 "register_operand" "r")
21138 + (match_operand:SF 1 "register_operand" "r")))]
21139 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21140 + {
21141 + if (!rtx_equal_p(cc_prev_status.mdep.value, SET_SRC(PATTERN (insn))) )
21142 + return "fcmp.s\t%0, %1";
21143 + return "";
21144 + }
21145 + [(set_attr "length" "4")
21146 + (set_attr "cc" "compare")])
21147 +
21148 +(define_expand "divsf3"
21149 + [(set (match_operand:SF 0 "register_operand" "=r")
21150 + (div:SF (match_operand:SF 1 "register_operand" "r")
21151 + (match_operand:SF 2 "register_operand" "r")))]
21152 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT && flag_unsafe_math_optimizations"
21153 + "{
21154 + emit_insn(gen_frcpa_internal(operands[0],operands[2]));
21155 + emit_insn(gen_mulsf3(operands[0],operands[0],operands[1]));
21156 + DONE;
21157 + }"
21158 +)
21159 +
21160 +(define_insn "frcpa_internal"
21161 + [(set (match_operand:SF 0 "register_operand" "=r")
21162 + (unspec:SF [(match_operand:SF 1 "register_operand" "r")] UNSPEC_FRCPA))]
21163 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21164 + "frcpa.s %0,%1"
21165 + [(set_attr "length" "4")])
21166 +
21167 +(define_expand "sqrtsf2"
21168 + [(set (match_operand:SF 0 "register_operand" "")
21169 + (sqrt:SF (match_operand:SF 1 "register_operand" "")))]
21170 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT && flag_unsafe_math_optimizations"
21171 + "
21172 +{
21173 + rtx scratch = gen_reg_rtx (SFmode);
21174 + emit_insn (gen_rsqrtsf2 (scratch, operands[1], CONST1_RTX (SFmode)));
21175 + emit_insn (gen_divsf3(operands[0], force_reg (SFmode, CONST1_RTX (SFmode)),
21176 + scratch));
21177 + DONE;
21178 +}")
21179 +
21180 +(define_insn "rsqrtsf2"
21181 + [(set (match_operand:SF 0 "register_operand" "=r")
21182 + (div:SF (match_operand:SF 2 "const_1f_operand" "F")
21183 + (sqrt:SF (match_operand:SF 1 "register_operand" "?r"))))]
21184 + "TARGET_ARCH_FPU && TARGET_HARD_FLOAT"
21185 + "frsqrta.s %1, %0")
21186 --- /dev/null
21187 +++ b/gcc/config/avr32/uclinux-elf.h
21188 @@ -0,0 +1,20 @@
21189 +
21190 +/* Run-time Target Specification. */
21191 +#undef TARGET_VERSION
21192 +#define TARGET_VERSION fputs (" (AVR32 uClinux with ELF)", stderr)
21193 +
21194 +/* We don't want a .jcr section on uClinux. As if this makes a difference... */
21195 +#define TARGET_USE_JCR_SECTION 0
21196 +
21197 +/* Here we go. Drop the crtbegin/crtend stuff completely. */
21198 +#undef STARTFILE_SPEC
21199 +#define STARTFILE_SPEC \
21200 + "%{!shared: %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s}" \
21201 + " %{!p:%{profile:gcrt1.o%s}" \
21202 + " %{!profile:crt1.o%s}}}} crti.o%s"
21203 +
21204 +#undef ENDFILE_SPEC
21205 +#define ENDFILE_SPEC "crtn.o%s"
21206 +
21207 +#undef TARGET_DEFAULT
21208 +#define TARGET_DEFAULT (AVR32_FLAG_NO_INIT_GOT)
21209 --- a/gcc/config/host-linux.c
21210 +++ b/gcc/config/host-linux.c
21211 @@ -25,6 +25,9 @@
21212 #include "hosthooks.h"
21213 #include "hosthooks-def.h"
21214
21215 +#ifndef SSIZE_MAX
21216 +#define SSIZE_MAX LONG_MAX
21217 +#endif
21218
21219 /* Linux has a feature called exec-shield-randomize that perturbs the
21220 address of non-fixed mapped segments by a (relatively) small amount.
21221 --- a/gcc/config.gcc
21222 +++ b/gcc/config.gcc
21223 @@ -834,6 +834,24 @@ avr-*-*)
21224 tm_file="avr/avr.h dbxelf.h"
21225 use_fixproto=yes
21226 ;;
21227 +avr32*-*-linux*)
21228 + tm_file="dbxelf.h elfos.h linux.h avr32/linux-elf.h avr32/avr32.h "
21229 + tmake_file="t-linux avr32/t-avr32-linux"
21230 + extra_parts="crtbegin.o crtbeginS.o crtend.o crtendS.o"
21231 + extra_modes=avr32/avr32-modes.def
21232 + gnu_ld=yes
21233 + ;;
21234 +avr32*-*-uclinux*)
21235 + tm_file="dbxelf.h elfos.h linux.h avr32/linux-elf.h avr32/uclinux-elf.h avr32/avr32.h"
21236 + tmake_file="t-linux avr32/t-avr32-linux"
21237 + extra_modes=avr32/avr32-modes.def
21238 + gnu_ld=yes
21239 + ;;
21240 +avr32-*-*)
21241 + tm_file="dbxelf.h elfos.h avr32/avr32.h avr32/avr32-elf.h"
21242 + tmake_file="avr32/t-avr32 avr32/t-elf"
21243 + extra_modes=avr32/avr32-modes.def
21244 + ;;
21245 bfin*-elf*)
21246 tm_file="${tm_file} dbxelf.h elfos.h bfin/elf.h"
21247 tmake_file=bfin/t-bfin-elf
21248 @@ -2950,6 +2968,32 @@ case "${target}" in
21249 fi
21250 ;;
21251
21252 + avr32*-*-*)
21253 + supported_defaults="part arch"
21254 +
21255 + case "$with_part" in
21256 + "" \
21257 + | "ap7000" | "ap7010" | "ap7020" | "uc3a0256" | "uc3a0512" | "uc3a1128" | "uc3a1256" | "uc3a1512" )
21258 + # OK
21259 + ;;
21260 + *)
21261 + echo "Unknown part used in --with-part=$with_part" 1>&2
21262 + exit 1
21263 + ;;
21264 + esac
21265 +
21266 + case "$with_arch" in
21267 + "" \
21268 + | "ap" | "uc")
21269 + # OK
21270 + ;;
21271 + *)
21272 + echo "Unknown arch used in --with-arch=$with_arch" 1>&2
21273 + exit 1
21274 + ;;
21275 + esac
21276 + ;;
21277 +
21278 fr*-*-*linux*)
21279 supported_defaults=cpu
21280 case "$with_cpu" in
21281 --- a/gcc/configure.ac
21282 +++ b/gcc/configure.ac
21283 @@ -2174,10 +2174,9 @@ L2:],
21284 as_ver=`$gcc_cv_as --version 2>/dev/null | sed 1q`
21285 if echo "$as_ver" | grep GNU > /dev/null; then
21286 changequote(,)dnl
21287 - as_vers=`echo $as_ver | sed -n \
21288 - -e 's,^.*[ ]\([0-9][0-9]*\.[0-9][0-9]*.*\)$,\1,p'`
21289 - as_major=`expr "$as_vers" : '\([0-9]*\)'`
21290 - as_minor=`expr "$as_vers" : '[0-9]*\.\([0-9]*\)'`
21291 + as_ver=`echo $as_ver | sed -e 's/GNU assembler\( (GNU Binutils)\)\? \([0-9.][0-9.]*\).*/\2/'`
21292 + as_major=`echo $as_ver | sed 's/\..*//'`
21293 + as_minor=`echo $as_ver | sed 's/[^.]*\.\([0-9]*\).*/\1/'`
21294 changequote([,])dnl
21295 if test $as_major -eq 2 && test $as_minor -lt 11
21296 then :
21297 @@ -3077,7 +3076,7 @@ esac
21298 case "$target" in
21299 i?86*-*-* | mips*-*-* | alpha*-*-* | powerpc*-*-* | sparc*-*-* | m68*-*-* \
21300 | x86_64*-*-* | hppa*-*-* | arm*-*-* | strongarm*-*-* | xscale*-*-* \
21301 - | xstormy16*-*-* | cris-*-* | xtensa-*-* | bfin-*-* | score*-*-* | spu-*-*)
21302 + | xstormy16*-*-* | cris-*-* | xtensa-*-* | bfin-*-* | score*-*-* | spu-*-* | avr32-*-*)
21303 insn="nop"
21304 ;;
21305 ia64*-*-* | s390*-*-*)
21306 --- a/gcc/doc/extend.texi
21307 +++ b/gcc/doc/extend.texi
21308 @@ -2336,7 +2336,7 @@ This attribute is ignored for R8C target
21309
21310 @item interrupt
21311 @cindex interrupt handler functions
21312 -Use this attribute on the ARM, AVR, CRX, M32C, M32R/D, m68k, MS1,
21313 +Use this attribute on the ARM, AVR, AVR32, CRX, M32C, M32R/D, m68k, MS1,
21314 and Xstormy16 ports to indicate that the specified function is an
21315 interrupt handler. The compiler will generate function entry and exit
21316 sequences suitable for use in an interrupt handler when this attribute
21317 @@ -2356,6 +2356,15 @@ void f () __attribute__ ((interrupt ("IR
21318
21319 Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF@.
21320
21321 +Note, for the AVR32, you can specify which banking scheme is used for
21322 +the interrupt mode this interrupt handler is used in like this:
21323 +
21324 +@smallexample
21325 +void f () __attribute__ ((interrupt ("FULL")));
21326 +@end smallexample
21327 +
21328 +Permissible values for this parameter are: FULL, HALF, NONE and UNDEF.
21329 +
21330 On ARMv7-M the interrupt type is ignored, and the attribute means the function
21331 may be called with a word aligned stack pointer.
21332
21333 @@ -3925,6 +3934,23 @@ placed in either the @code{.bss_below100
21334
21335 @end table
21336
21337 +@subsection AVR32 Variable Attributes
21338 +
21339 +One attribute is currently defined for AVR32 configurations:
21340 +@code{rmw_addressable}
21341 +
21342 +@table @code
21343 +@item rmw_addressable
21344 +@cindex @code{rmw_addressable} attribute
21345 +
21346 +This attribute can be used to signal that a variable can be accessed
21347 +with the addressing mode of the AVR32 Atomic Read-Modify-Write memory
21348 +instructions and hence make it possible for gcc to generate these
21349 +instructions without using built-in functions or inline assembly statements.
21350 +Variables used within the AVR32 Atomic Read-Modify-Write built-in
21351 +functions will automatically get the @code{rmw_addressable} attribute.
21352 +@end table
21353 +
21354 @subsection AVR Variable Attributes
21355
21356 @table @code
21357 @@ -6708,6 +6734,7 @@ instructions, but allow the compiler to
21358 * Alpha Built-in Functions::
21359 * ARM iWMMXt Built-in Functions::
21360 * ARM NEON Intrinsics::
21361 +* AVR32 Built-in Functions::
21362 * Blackfin Built-in Functions::
21363 * FR-V Built-in Functions::
21364 * X86 Built-in Functions::
21365 @@ -6947,6 +6974,7 @@ long long __builtin_arm_wxor (long long,
21366 long long __builtin_arm_wzero ()
21367 @end smallexample
21368
21369 +
21370 @node ARM NEON Intrinsics
21371 @subsection ARM NEON Intrinsics
21372
21373 @@ -6955,6 +6983,74 @@ when the @option{-mfpu=neon} switch is u
21374
21375 @include arm-neon-intrinsics.texi
21376
21377 +@node AVR32 Built-in Functions
21378 +@subsection AVR32 Built-in Functions
21379 +
21380 +Built-in functions for atomic memory (RMW) instructions. Note that these
21381 +built-ins will fail for targets where the RMW instructions are not
21382 +implemented. Also note that these instructions only that a Ks15 << 2
21383 +memory address and will therefor not work with any runtime computed
21384 +memory addresses. The user is responsible for making sure that any
21385 +pointers used within these functions points to a valid memory address.
21386 +
21387 +@smallexample
21388 +void __builtin_mems(int */*ptr*/, int /*bit*/)
21389 +void __builtin_memc(int */*ptr*/, int /*bit*/)
21390 +void __builtin_memt(int */*ptr*/, int /*bit*/)
21391 +@end smallexample
21392 +
21393 +Built-in functions for DSP instructions. Note that these built-ins will
21394 +fail for targets where the DSP instructions are not implemented.
21395 +
21396 +@smallexample
21397 +int __builtin_sats (int /*Rd*/,int /*sa*/, int /*bn*/)
21398 +int __builtin_satu (int /*Rd*/,int /*sa*/, int /*bn*/)
21399 +int __builtin_satrnds (int /*Rd*/,int /*sa*/, int /*bn*/)
21400 +int __builtin_satrndu (int /*Rd*/,int /*sa*/, int /*bn*/)
21401 +short __builtin_mulsathh_h (short, short)
21402 +int __builtin_mulsathh_w (short, short)
21403 +short __builtin_mulsatrndhh_h (short, short)
21404 +int __builtin_mulsatrndwh_w (int, short)
21405 +int __builtin_mulsatwh_w (int, short)
21406 +int __builtin_macsathh_w (int, short, short)
21407 +short __builtin_satadd_h (short, short)
21408 +short __builtin_satsub_h (short, short)
21409 +int __builtin_satadd_w (int, int)
21410 +int __builtin_satsub_w (int, int)
21411 +long long __builtin_mulwh_d(int, short)
21412 +long long __builtin_mulnwh_d(int, short)
21413 +long long __builtin_macwh_d(long long, int, short)
21414 +long long __builtin_machh_d(long long, short, short)
21415 +@end smallexample
21416 +
21417 +Other built-in functions for instructions that cannot easily be
21418 +generated by the compiler.
21419 +
21420 +@smallexample
21421 +void __builtin_ssrf(int);
21422 +void __builtin_csrf(int);
21423 +void __builtin_musfr(int);
21424 +int __builtin_mustr(void);
21425 +int __builtin_mfsr(int /*Status Register Address*/)
21426 +void __builtin_mtsr(int /*Status Register Address*/, int /*Value*/)
21427 +int __builtin_mfdr(int /*Debug Register Address*/)
21428 +void __builtin_mtdr(int /*Debug Register Address*/, int /*Value*/)
21429 +void __builtin_cache(void * /*Address*/, int /*Cache Operation*/)
21430 +void __builtin_sync(int /*Sync Operation*/)
21431 +void __builtin_tlbr(void)
21432 +void __builtin_tlbs(void)
21433 +void __builtin_tlbw(void)
21434 +void __builtin_breakpoint(void)
21435 +int __builtin_xchg(void * /*Address*/, int /*Value*/ )
21436 +short __builtin_bswap_16(short)
21437 +int __builtin_bswap_32(int)
21438 +void __builtin_cop(int/*cpnr*/, int/*crd*/, int/*crx*/, int/*cry*/, int/*op*/)
21439 +int __builtin_mvcr_w(int/*cpnr*/, int/*crs*/)
21440 +void __builtin_mvrc_w(int/*cpnr*/, int/*crd*/, int/*value*/)
21441 +long long __builtin_mvcr_d(int/*cpnr*/, int/*crs*/)
21442 +void __builtin_mvrc_d(int/*cpnr*/, int/*crd*/, long long/*value*/)
21443 +@end smallexample
21444 +
21445 @node Blackfin Built-in Functions
21446 @subsection Blackfin Built-in Functions
21447
21448 --- a/gcc/doc/invoke.texi
21449 +++ b/gcc/doc/invoke.texi
21450 @@ -195,7 +195,7 @@ in the following sections.
21451 -fvisibility-ms-compat @gol
21452 -Wabi -Wctor-dtor-privacy @gol
21453 -Wnon-virtual-dtor -Wreorder @gol
21454 --Weffc++ -Wno-deprecated -Wstrict-null-sentinel @gol
21455 +-Weffc++ -Wno-deprecated @gol
21456 -Wno-non-template-friend -Wold-style-cast @gol
21457 -Woverloaded-virtual -Wno-pmf-conversions @gol
21458 -Wsign-promo}
21459 @@ -609,6 +609,12 @@ Objective-C and Objective-C++ Dialects}.
21460 -mauto-incdec -minmax -mlong-calls -mshort @gol
21461 -msoft-reg-count=@var{count}}
21462
21463 +@emph{AVR32 Options}
21464 +@gccoptlist{-muse-rodata-section -mhard-float -msoft-float -mrelax @gol
21465 +-mforce-double-align -mno-init-got -mrelax -mmd-reorg-opt -masm-addr-pseudos @gol
21466 +-mpart=@var{part} -mcpu=@var{cpu} -march=@var{arch} @gol
21467 +-mfast-float -mimm-in-const-pool}
21468 +
21469 @emph{MCore Options}
21470 @gccoptlist{-mhardlit -mno-hardlit -mdiv -mno-div -mrelax-immediates @gol
21471 -mno-relax-immediates -mwide-bitfields -mno-wide-bitfields @gol
21472 @@ -3163,13 +3169,11 @@ requiring @option{-O}.
21473 If you want to warn about code which uses the uninitialized value of the
21474 variable in its own initializer, use the @option{-Winit-self} option.
21475
21476 -These warnings occur for individual uninitialized or clobbered
21477 -elements of structure, union or array variables as well as for
21478 -variables which are uninitialized or clobbered as a whole. They do
21479 -not occur for variables or elements declared @code{volatile}. Because
21480 -these warnings depend on optimization, the exact variables or elements
21481 -for which there are warnings will depend on the precise optimization
21482 -options and version of GCC used.
21483 +These warnings occur only for variables that are candidates for
21484 +register allocation. Therefore, they do not occur for a variable that
21485 +is declared @code{volatile}, or whose address is taken, or whose size
21486 +is other than 1, 2, 4 or 8 bytes. Also, they do not occur for
21487 +structures, unions or arrays, even when they are in registers.
21488
21489 Note that there may be no warning about a variable that is used only
21490 to compute a value that itself is never used, because such
21491 @@ -7034,10 +7038,6 @@ If number of candidates in the set is sm
21492 we always try to remove unnecessary ivs from the set during its
21493 optimization when a new iv is added to the set.
21494
21495 -@item scev-max-expr-size
21496 -Bound on size of expressions used in the scalar evolutions analyzer.
21497 -Large expressions slow the analyzer.
21498 -
21499 @item omega-max-vars
21500 The maximum number of variables in an Omega constraint system.
21501 The default value is 128.
21502 @@ -8363,6 +8363,7 @@ platform.
21503 * ARC Options::
21504 * ARM Options::
21505 * AVR Options::
21506 +* AVR32 Options::
21507 * Blackfin Options::
21508 * CRIS Options::
21509 * CRX Options::
21510 @@ -8834,6 +8835,129 @@ comply to the C standards, but it will p
21511 size.
21512 @end table
21513
21514 +@node AVR32 Options
21515 +@subsection AVR32 Options
21516 +@cindex AVR32 Options
21517 +
21518 +These options are defined for AVR32 implementations:
21519 +
21520 +@table @gcctabopt
21521 +@item -muse-rodata-section
21522 +@opindex muse-rodata-section
21523 +Use section @samp{.rodata} for read-only data instead of @samp{.text}.
21524 +
21525 +@item -mhard-float
21526 +@opindex mhard-float
21527 +Use floating point coprocessor instructions.
21528 +
21529 +@item -msoft-float
21530 +@opindex msoft-float
21531 +Use software floating-point library for floating-point operations.
21532 +
21533 +@item -mforce-double-align
21534 +@opindex mforce-double-align
21535 +Force double-word alignment for double-word memory accesses.
21536 +
21537 +@item -masm-addr-pseudos
21538 +@opindex masm-addr-pseudos
21539 +Use assembler pseudo-instructions lda.w and call for handling direct
21540 +addresses. (Enabled by default)
21541 +
21542 +@item -mno-init-got
21543 +@opindex mno-init-got
21544 +Do not initialize the GOT register before using it when compiling PIC
21545 +code.
21546 +
21547 +@item -mrelax
21548 +@opindex mrelax
21549 +Let invoked assembler and linker do relaxing
21550 +(Enabled by default when optimization level is >1).
21551 +This means that when the address of symbols are known at link time,
21552 +the linker can optimize @samp{icall} and @samp{mcall}
21553 +instructions into a @samp{rcall} instruction if possible.
21554 +Loading the address of a symbol can also be optimized.
21555 +
21556 +@item -mmd-reorg-opt
21557 +@opindex mmd-reorg-opt
21558 +Perform machine dependent optimizations in reorg stage.
21559 +
21560 +@item -mpart=@var{part}
21561 +@opindex mpart
21562 +Generate code for the specified part. Permissible parts are:
21563 +@samp{ap7000},
21564 +@samp{ap7001},
21565 +@samp{ap7002},
21566 +@samp{ap7200},
21567 +@samp{uc3a0128},
21568 +@samp{uc3a0256},
21569 +@samp{uc3a0512},
21570 +@samp{uc3a0512es},
21571 +@samp{uc3a1128},
21572 +@samp{uc3a1256},
21573 +@samp{uc3a1512},
21574 +@samp{uc3a1512es},
21575 +@samp{uc3a3revd},
21576 +@samp{uc3a364},
21577 +@samp{uc3a364s},
21578 +@samp{uc3a3128},
21579 +@samp{uc3a3128s},
21580 +@samp{uc3a3256},
21581 +@samp{uc3a3256s},
21582 +@samp{uc3b064},
21583 +@samp{uc3b0128},
21584 +@samp{uc3b0256},
21585 +@samp{uc3b0256es},
21586 +@samp{uc3b0512},
21587 +@samp{uc3b0512revc},
21588 +@samp{uc3b164},
21589 +@samp{uc3b1128},
21590 +@samp{uc3b1256},
21591 +@samp{uc3b1256es},
21592 +@samp{uc3b1512}
21593 +@samp{uc3b1512revc}
21594 +@samp{uc3c0512crevc},
21595 +@samp{uc3c1512crevc},
21596 +@samp{uc3c2512crevc},
21597 +@samp{uc3l0256},
21598 +@samp{uc3l0128},
21599 +@samp{uc3l064},
21600 +@samp{uc3l032},
21601 +@samp{uc3l016},
21602 +@samp{uc3l064revb},
21603 +@samp{uc3c064c},
21604 +@samp{uc3c0128c},
21605 +@samp{uc3c0256c},
21606 +@samp{uc3c0512c},
21607 +@samp{uc3c164c},
21608 +@samp{uc3c1128c},
21609 +@samp{uc3c1256c},
21610 +@samp{uc3c1512c},
21611 +@samp{uc3c264c},
21612 +@samp{uc3c2128c},
21613 +@samp{uc3c2256c},
21614 +@samp{uc3c2512c},
21615 +@samp{mxt768e}.
21616 +
21617 +@item -mcpu=@var{cpu-type}
21618 +@opindex mcpu
21619 +Same as -mpart. Obsolete.
21620 +
21621 +@item -march=@var{arch}
21622 +@opindex march
21623 +Generate code for the specified architecture. Permissible architectures are:
21624 +@samp{ap}, @samp{uc} and @samp{ucr2}.
21625 +
21626 +@item -mfast-float
21627 +@opindex mfast-float
21628 +Enable fast floating-point library that does not conform to IEEE-754 but is still good enough
21629 +for most applications. The fast floating-point library does not round to the nearest even
21630 +but away from zero. Enabled by default if the -funsafe-math-optimizations switch is specified.
21631 +
21632 +@item -mimm-in-const-pool
21633 +@opindex mimm-in-const-pool
21634 +Put large immediates in constant pool. This is enabled by default for archs with insn-cache.
21635 +@end table
21636 +
21637 @node Blackfin Options
21638 @subsection Blackfin Options
21639 @cindex Blackfin Options
21640 @@ -8889,29 +9013,12 @@ When enabled, the compiler will ensure t
21641 contain speculative loads after jump instructions. If this option is used,
21642 @code{__WORKAROUND_SPECULATIVE_LOADS} is defined.
21643
21644 -@item -mno-specld-anomaly
21645 -@opindex mno-specld-anomaly
21646 -Don't generate extra code to prevent speculative loads from occurring.
21647 -
21648 @item -mcsync-anomaly
21649 @opindex mcsync-anomaly
21650 When enabled, the compiler will ensure that the generated code does not
21651 contain CSYNC or SSYNC instructions too soon after conditional branches.
21652 If this option is used, @code{__WORKAROUND_SPECULATIVE_SYNCS} is defined.
21653
21654 -@item -mno-csync-anomaly
21655 -@opindex mno-csync-anomaly
21656 -Don't generate extra code to prevent CSYNC or SSYNC instructions from
21657 -occurring too soon after a conditional branch.
21658 -
21659 -@item -mlow-64k
21660 -@opindex mlow-64k
21661 -When enabled, the compiler is free to take advantage of the knowledge that
21662 -the entire program fits into the low 64k of memory.
21663 -
21664 -@item -mno-low-64k
21665 -@opindex mno-low-64k
21666 -Assume that the program is arbitrarily large. This is the default.
21667
21668 @item -mstack-check-l1
21669 @opindex mstack-check-l1
21670 @@ -8925,11 +9032,6 @@ This allows for execute in place and sha
21671 without virtual memory management. This option implies @option{-fPIC}.
21672 With a @samp{bfin-elf} target, this option implies @option{-msim}.
21673
21674 -@item -mno-id-shared-library
21675 -@opindex mno-id-shared-library
21676 -Generate code that doesn't assume ID based shared libraries are being used.
21677 -This is the default.
21678 -
21679 @item -mleaf-id-shared-library
21680 @opindex mleaf-id-shared-library
21681 Generate code that supports shared libraries via the library ID method,
21682 @@ -8971,11 +9073,6 @@ call on this register. This switch is n
21683 will lie outside of the 24 bit addressing range of the offset based
21684 version of subroutine call instruction.
21685
21686 -This feature is not enabled by default. Specifying
21687 -@option{-mno-long-calls} will restore the default behavior. Note these
21688 -switches have no effect on how the compiler generates code to handle
21689 -function calls via function pointers.
21690 -
21691 @item -mfast-fp
21692 @opindex mfast-fp
21693 Link with the fast floating-point library. This library relaxes some of
21694 --- a/gcc/doc/md.texi
21695 +++ b/gcc/doc/md.texi
21696 @@ -3,6 +3,7 @@
21697 @c This is part of the GCC manual.
21698 @c For copying conditions, see the file gcc.texi.
21699
21700 +
21701 @ifset INTERNALS
21702 @node Machine Desc
21703 @chapter Machine Descriptions
21704 @@ -1681,6 +1682,58 @@ A memory reference suitable for iWMMXt l
21705 A memory reference suitable for the ARMv4 ldrsb instruction.
21706 @end table
21707
21708 +@item AVR32 family---@file{avr32.h}
21709 +@table @code
21710 +@item f
21711 +Floating-point registers (f0 to f15)
21712 +
21713 +@item Ku@var{bits}
21714 +Unsigned constant representable with @var{bits} number of bits (Must be
21715 +two digits). I.e: An unsigned 8-bit constant is written as @samp{Ku08}
21716 +
21717 +@item Ks@var{bits}
21718 +Signed constant representable with @var{bits} number of bits (Must be
21719 +two digits). I.e: A signed 12-bit constant is written as @samp{Ks12}
21720 +
21721 +@item Is@var{bits}
21722 +The negated range of a signed constant representable with @var{bits}
21723 +number of bits. The same as @samp{Ks@var{bits}} with a negated range.
21724 +This means that the constant must be in the range @math{-2^{bits-1}-1} to @math{2^{bits-1}}
21725 +
21726 +@item G
21727 +A single/double precision floating-point immediate or 64-bit integer
21728 +immediate where the least and most significant words both can be
21729 +loaded with a move instruction. That is the the integer form of the
21730 +values in the least and most significant words both are in the range
21731 +@math{-2^{20}} to @math{2^{20}-1}.
21732 +
21733 +@item RKs@var{bits}
21734 +A memory reference where the address consists of a base register
21735 +plus a signed immediate displacement with range given by @samp{Ks@var{bits}}
21736 +which has the same format as for the signed immediate integer constraint
21737 +given above.
21738 +
21739 +@item RKu@var{bits}
21740 +A memory reference where the address consists of a base register
21741 +plus an unsigned immediate displacement with range given by @samp{Ku@var{bits}}
21742 +which has the same format as for the unsigned immediate integer constraint
21743 +given above.
21744 +
21745 +@item S
21746 +A memory reference with an immediate or register offset
21747 +
21748 +@item T
21749 +A memory reference to a constant pool entry
21750 +
21751 +@item W
21752 +A valid operand for use in the @samp{lda.w} instruction macro when
21753 +relaxing is enabled
21754 +
21755 +@item Z
21756 +A memory reference valid for coprocessor memory instructions
21757 +
21758 +@end table
21759 +
21760 @item AVR family---@file{config/avr/constraints.md}
21761 @table @code
21762 @item l
21763 --- a/gcc/expmed.c
21764 +++ b/gcc/expmed.c
21765 @@ -463,9 +463,9 @@ store_bit_field_1 (rtx str_rtx, unsigned
21766 ? ((GET_MODE_SIZE (fieldmode) >= UNITS_PER_WORD
21767 || GET_MODE_SIZE (GET_MODE (op0)) == GET_MODE_SIZE (fieldmode))
21768 && byte_offset % GET_MODE_SIZE (fieldmode) == 0)
21769 - : (! SLOW_UNALIGNED_ACCESS (fieldmode, MEM_ALIGN (op0))
21770 + : ( (! SLOW_UNALIGNED_ACCESS (fieldmode, MEM_ALIGN (op0))
21771 || (offset * BITS_PER_UNIT % bitsize == 0
21772 - && MEM_ALIGN (op0) % GET_MODE_BITSIZE (fieldmode) == 0))))
21773 + && MEM_ALIGN (op0) % GET_MODE_BITSIZE (fieldmode) == 0)))))
21774 {
21775 if (MEM_P (op0))
21776 op0 = adjust_address (op0, fieldmode, offset);
21777 --- a/gcc/expr.c
21778 +++ b/gcc/expr.c
21779 @@ -52,6 +52,7 @@ along with GCC; see the file COPYING3.
21780 #include "tree-flow.h"
21781 #include "target.h"
21782 #include "timevar.h"
21783 +#include "c-common.h"
21784 #include "df.h"
21785 #include "diagnostic.h"
21786
21787 @@ -3620,16 +3621,17 @@ emit_single_push_insn (enum machine_mode
21788 }
21789 else
21790 {
21791 + emit_move_insn (stack_pointer_rtx,
21792 + expand_binop (Pmode,
21793 #ifdef STACK_GROWS_DOWNWARD
21794 - /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
21795 - dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
21796 - GEN_INT (-(HOST_WIDE_INT) rounded_size));
21797 + sub_optab,
21798 #else
21799 - /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
21800 - dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
21801 - GEN_INT (rounded_size));
21802 + add_optab,
21803 #endif
21804 - dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
21805 + stack_pointer_rtx,
21806 + GEN_INT (rounded_size),
21807 + NULL_RTX, 0, OPTAB_LIB_WIDEN));
21808 + dest_addr = stack_pointer_rtx;
21809 }
21810
21811 dest = gen_rtx_MEM (mode, dest_addr);
21812 @@ -5739,7 +5741,8 @@ store_field (rtx target, HOST_WIDE_INT b
21813 is a bit field, we cannot use addressing to access it.
21814 Use bit-field techniques or SUBREG to store in it. */
21815
21816 - if (mode == VOIDmode
21817 + if (
21818 + mode == VOIDmode
21819 || (mode != BLKmode && ! direct_store[(int) mode]
21820 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
21821 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
21822 @@ -5896,7 +5899,18 @@ get_inner_reference (tree exp, HOST_WIDE
21823 {
21824 tree field = TREE_OPERAND (exp, 1);
21825 size_tree = DECL_SIZE (field);
21826 - if (!DECL_BIT_FIELD (field))
21827 + if (!DECL_BIT_FIELD (field)
21828 + /* Added for AVR32:
21829 + Bitfields with a size equal to a target storage
21830 + type might not cause DECL_BIT_FIELD to return
21831 + true since it can be optimized into a normal array
21832 + access operation. But for volatile bitfields we do
21833 + not allow this when targetm.narrow_volatile_bitfield ()
21834 + is false. We can use DECL_C_BIT_FIELD to check if this
21835 + really is a c-bitfield. */
21836 + && !(TREE_THIS_VOLATILE (exp)
21837 + && !targetm.narrow_volatile_bitfield ()
21838 + && DECL_C_BIT_FIELD (field)) )
21839 mode = DECL_MODE (field);
21840 else if (DECL_MODE (field) == BLKmode)
21841 blkmode_bitfield = true;
21842 @@ -7889,7 +7903,8 @@ expand_expr_real_1 (tree exp, rtx target
21843 by doing the extract into an object as wide as the field
21844 (which we know to be the width of a basic mode), then
21845 storing into memory, and changing the mode to BLKmode. */
21846 - if (mode1 == VOIDmode
21847 + if (
21848 + mode1 == VOIDmode
21849 || REG_P (op0) || GET_CODE (op0) == SUBREG
21850 || (mode1 != BLKmode && ! direct_load[(int) mode1]
21851 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
21852 --- a/gcc/function.c
21853 +++ b/gcc/function.c
21854 @@ -2715,7 +2715,11 @@ assign_parm_setup_reg (struct assign_par
21855 SET_DECL_RTL (parm, parmreg);
21856
21857 /* Copy the value into the register. */
21858 - if (data->nominal_mode != data->passed_mode
21859 + if ( (data->nominal_mode != data->passed_mode
21860 + /* Added for AVR32: If passed_mode is equal
21861 + to promoted nominal mode why should be convert?
21862 + The conversion should make no difference. */
21863 + && data->passed_mode != promoted_nominal_mode)
21864 || promoted_nominal_mode != data->promoted_mode)
21865 {
21866 int save_tree_used;
21867 --- a/gcc/genemit.c
21868 +++ b/gcc/genemit.c
21869 @@ -121,6 +121,24 @@ max_operand_vec (rtx insn, int arg)
21870 }
21871 \f
21872 static void
21873 +gen_vararg_prologue(int operands)
21874 +{
21875 + int i;
21876 +
21877 + if (operands > 1)
21878 + {
21879 + for (i = 1; i < operands; i++)
21880 + printf(" rtx operand%d ATTRIBUTE_UNUSED;\n", i);
21881 +
21882 + printf(" va_list args;\n\n");
21883 + printf(" va_start(args, operand0);\n");
21884 + for (i = 1; i < operands; i++)
21885 + printf(" operand%d = va_arg(args, rtx);\n", i);
21886 + printf(" va_end(args);\n\n");
21887 + }
21888 +}
21889 +
21890 +static void
21891 print_code (RTX_CODE code)
21892 {
21893 const char *p1;
21894 @@ -406,18 +424,16 @@ gen_insn (rtx insn, int lineno)
21895 fatal ("match_dup operand number has no match_operand");
21896
21897 /* Output the function name and argument declarations. */
21898 - printf ("rtx\ngen_%s (", XSTR (insn, 0));
21899 + printf ("rtx\ngen_%s ", XSTR (insn, 0));
21900 +
21901 if (operands)
21902 - for (i = 0; i < operands; i++)
21903 - if (i)
21904 - printf (",\n\trtx operand%d ATTRIBUTE_UNUSED", i);
21905 + printf("(rtx operand0 ATTRIBUTE_UNUSED, ...)\n");
21906 else
21907 - printf ("rtx operand%d ATTRIBUTE_UNUSED", i);
21908 - else
21909 - printf ("void");
21910 - printf (")\n");
21911 + printf("(void)\n");
21912 printf ("{\n");
21913
21914 + gen_vararg_prologue(operands);
21915 +
21916 /* Output code to construct and return the rtl for the instruction body. */
21917
21918 if (XVECLEN (insn, 1) == 1)
21919 @@ -461,16 +477,12 @@ gen_expand (rtx expand)
21920 operands = max_operand_vec (expand, 1);
21921
21922 /* Output the function name and argument declarations. */
21923 - printf ("rtx\ngen_%s (", XSTR (expand, 0));
21924 + printf ("rtx\ngen_%s ", XSTR (expand, 0));
21925 if (operands)
21926 - for (i = 0; i < operands; i++)
21927 - if (i)
21928 - printf (",\n\trtx operand%d", i);
21929 - else
21930 - printf ("rtx operand%d", i);
21931 + printf("(rtx operand0 ATTRIBUTE_UNUSED, ...)\n");
21932 else
21933 - printf ("void");
21934 - printf (")\n");
21935 + printf("(void)\n");
21936 +
21937 printf ("{\n");
21938
21939 /* If we don't have any C code to write, only one insn is being written,
21940 @@ -480,6 +492,8 @@ gen_expand (rtx expand)
21941 && operands > max_dup_opno
21942 && XVECLEN (expand, 1) == 1)
21943 {
21944 + gen_vararg_prologue(operands);
21945 +
21946 printf (" return ");
21947 gen_exp (XVECEXP (expand, 1, 0), DEFINE_EXPAND, NULL);
21948 printf (";\n}\n\n");
21949 @@ -493,6 +507,7 @@ gen_expand (rtx expand)
21950 for (; i <= max_scratch_opno; i++)
21951 printf (" rtx operand%d ATTRIBUTE_UNUSED;\n", i);
21952 printf (" rtx _val = 0;\n");
21953 + gen_vararg_prologue(operands);
21954 printf (" start_sequence ();\n");
21955
21956 /* The fourth operand of DEFINE_EXPAND is some code to be executed
21957 --- a/gcc/genflags.c
21958 +++ b/gcc/genflags.c
21959 @@ -127,7 +127,6 @@ static void
21960 gen_proto (rtx insn)
21961 {
21962 int num = num_operands (insn);
21963 - int i;
21964 const char *name = XSTR (insn, 0);
21965 int truth = maybe_eval_c_test (XSTR (insn, 2));
21966
21967 @@ -158,12 +157,7 @@ gen_proto (rtx insn)
21968 if (num == 0)
21969 fputs ("void", stdout);
21970 else
21971 - {
21972 - for (i = 1; i < num; i++)
21973 - fputs ("rtx, ", stdout);
21974 -
21975 - fputs ("rtx", stdout);
21976 - }
21977 + fputs("rtx, ...", stdout);
21978
21979 puts (");");
21980
21981 @@ -173,12 +167,7 @@ gen_proto (rtx insn)
21982 {
21983 printf ("static inline rtx\ngen_%s", name);
21984 if (num > 0)
21985 - {
21986 - putchar ('(');
21987 - for (i = 0; i < num-1; i++)
21988 - printf ("rtx ARG_UNUSED (%c), ", 'a' + i);
21989 - printf ("rtx ARG_UNUSED (%c))\n", 'a' + i);
21990 - }
21991 + puts("(rtx ARG_UNUSED(a), ...)");
21992 else
21993 puts ("(void)");
21994 puts ("{\n return 0;\n}");
21995 --- a/gcc/genoutput.c
21996 +++ b/gcc/genoutput.c
21997 @@ -386,7 +386,7 @@ output_insn_data (void)
21998 }
21999
22000 if (d->name && d->name[0] != '*')
22001 - printf (" (insn_gen_fn) gen_%s,\n", d->name);
22002 + printf (" gen_%s,\n", d->name);
22003 else
22004 printf (" 0,\n");
22005
22006 --- a/gcc/ifcvt.c
22007 +++ b/gcc/ifcvt.c
22008 @@ -81,7 +81,7 @@ static int num_possible_if_blocks;
22009 static int num_updated_if_blocks;
22010
22011 /* # of changes made. */
22012 -static int num_true_changes;
22013 +int num_true_changes;
22014
22015 /* Whether conditional execution changes were made. */
22016 static int cond_exec_changed_p;
22017 @@ -286,6 +286,9 @@ cond_exec_process_insns (ce_if_block_t *
22018 if (must_be_last)
22019 return FALSE;
22020
22021 +#ifdef IFCVT_ALLOW_MODIFY_TEST_IN_INSN
22022 + if ( !IFCVT_ALLOW_MODIFY_TEST_IN_INSN )
22023 +#endif
22024 if (modified_in_p (test, insn))
22025 {
22026 if (!mod_ok)
22027 @@ -566,15 +569,18 @@ cond_exec_process_if_block (ce_if_block_
22028 IFCVT_MODIFY_FINAL (ce_info);
22029 #endif
22030
22031 + /* Merge the blocks! */
22032 + if ( reload_completed ){
22033 /* Conversion succeeded. */
22034 if (dump_file)
22035 fprintf (dump_file, "%d insn%s converted to conditional execution.\n",
22036 n_insns, (n_insns == 1) ? " was" : "s were");
22037
22038 - /* Merge the blocks! */
22039 merge_if_block (ce_info);
22040 cond_exec_changed_p = TRUE;
22041 return TRUE;
22042 + }
22043 + return FALSE;
22044
22045 fail:
22046 #ifdef IFCVT_MODIFY_CANCEL
22047 @@ -1080,7 +1086,11 @@ noce_try_addcc (struct noce_if_info *if_
22048 != UNKNOWN))
22049 {
22050 rtx cond = if_info->cond;
22051 - enum rtx_code code = reversed_comparison_code (cond, if_info->jump);
22052 + /* This generates wrong code for AVR32. The cond code need not be reversed
22053 + since the addmodecc patterns add if the condition is NOT met. */
22054 + /* enum rtx_code code = reversed_comparison_code (cond, if_info->jump);*/
22055 + enum rtx_code code = GET_CODE(cond);
22056 +
22057
22058 /* First try to use addcc pattern. */
22059 if (general_operand (XEXP (cond, 0), VOIDmode)
22060 @@ -3017,7 +3027,12 @@ find_if_header (basic_block test_bb, int
22061 && noce_find_if_block (test_bb, then_edge, else_edge, pass))
22062 goto success;
22063
22064 - if (HAVE_conditional_execution && reload_completed
22065 + if (HAVE_conditional_execution &&
22066 +#ifdef IFCVT_COND_EXEC_BEFORE_RELOAD
22067 + (reload_completed || IFCVT_COND_EXEC_BEFORE_RELOAD)
22068 +#else
22069 + reload_completed
22070 +#endif
22071 && cond_exec_find_if_block (&ce_info))
22072 goto success;
22073
22074 @@ -3132,7 +3147,11 @@ cond_exec_find_if_block (struct ce_if_bl
22075
22076 /* We only ever should get here after reload,
22077 and only if we have conditional execution. */
22078 +#ifdef IFCVT_COND_EXEC_BEFORE_RELOAD
22079 + gcc_assert (HAVE_conditional_execution && (reload_completed||IFCVT_COND_EXEC_BEFORE_RELOAD));
22080 +#else
22081 gcc_assert (HAVE_conditional_execution && reload_completed);
22082 +#endif
22083
22084 /* Discover if any fall through predecessors of the current test basic block
22085 were && tests (which jump to the else block) or || tests (which jump to
22086 @@ -4226,6 +4245,14 @@ gate_handle_if_after_reload (void)
22087 static unsigned int
22088 rest_of_handle_if_after_reload (void)
22089 {
22090 + /* Hack for the AVR32 experimental ifcvt processing before reload.
22091 + The AVR32 specific ifcvt code needs to know when ifcvt after reload
22092 + has begun. */
22093 +#ifdef IFCVT_COND_EXEC_BEFORE_RELOAD
22094 + if ( IFCVT_COND_EXEC_BEFORE_RELOAD )
22095 + cfun->machine->ifcvt_after_reload = 1;
22096 +#endif
22097 +
22098 if_convert ();
22099 return 0;
22100 }
22101 --- a/gcc/longlong.h
22102 +++ b/gcc/longlong.h
22103 @@ -239,6 +239,41 @@ UDItype __umulsidi3 (USItype, USItype);
22104 #define UDIV_TIME 100
22105 #endif /* __arm__ */
22106
22107 +#if defined (__avr32__) && W_TYPE_SIZE == 32
22108 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
22109 + __asm__ ("add\t%1, %4, %5\n\tadc\t%0, %2, %3" \
22110 + : "=r" ((USItype) (sh)), \
22111 + "=&r" ((USItype) (sl)) \
22112 + : "r" ((USItype) (ah)), \
22113 + "r" ((USItype) (bh)), \
22114 + "r" ((USItype) (al)), \
22115 + "r" ((USItype) (bl)) __CLOBBER_CC)
22116 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
22117 + __asm__ ("sub\t%1, %4, %5\n\tsbc\t%0, %2, %3" \
22118 + : "=r" ((USItype) (sh)), \
22119 + "=&r" ((USItype) (sl)) \
22120 + : "r" ((USItype) (ah)), \
22121 + "r" ((USItype) (bh)), \
22122 + "r" ((USItype) (al)), \
22123 + "r" ((USItype) (bl)) __CLOBBER_CC)
22124 +
22125 +#if !defined (__AVR32_NO_MUL__)
22126 +#define __umulsidi3(a,b) ((UDItype)(a) * (UDItype)(b))
22127 +
22128 +#define umul_ppmm(w1, w0, u, v) \
22129 +{ \
22130 + DWunion __w; \
22131 + __w.ll = __umulsidi3 (u, v); \
22132 + w1 = __w.s.high; \
22133 + w0 = __w.s.low; \
22134 +}
22135 +#endif
22136 +
22137 +#define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clz (X))
22138 +#define count_trailing_zeros(COUNT,X) ((COUNT) = __builtin_ctz (X))
22139 +#define COUNT_LEADING_ZEROS_0 32
22140 +#endif
22141 +
22142 #if defined (__CRIS__) && __CRIS_arch_version >= 3
22143 #define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clz (X))
22144 #if __CRIS_arch_version >= 8
22145 --- a/gcc/optabs.h
22146 +++ b/gcc/optabs.h
22147 @@ -586,7 +586,7 @@ extern enum insn_code reload_out_optab[N
22148 extern optab code_to_optab[NUM_RTX_CODE + 1];
22149
22150 \f
22151 -typedef rtx (*rtxfun) (rtx);
22152 +typedef rtx (*rtxfun) (rtx, ...);
22153
22154 /* Indexed by the rtx-code for a conditional (e.g. EQ, LT,...)
22155 gives the gen_function to make a branch to test that condition. */
22156 --- a/gcc/regrename.c
22157 +++ b/gcc/regrename.c
22158 @@ -1580,6 +1580,9 @@ copyprop_hardreg_forward_1 (basic_block
22159 bool changed = false;
22160 rtx insn;
22161
22162 + rtx prev_pred_test;
22163 + int prev_pred_insn_skipped = 0;
22164 +
22165 for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
22166 {
22167 int n_ops, i, alt, predicated;
22168 @@ -1619,6 +1622,58 @@ copyprop_hardreg_forward_1 (basic_block
22169 recog_data.operand_type[i] = OP_INOUT;
22170 }
22171
22172 +
22173 + /* Added for targets (AVR32) which supports test operands to be modified
22174 + in cond_exec instruction. For these targets we cannot make a change to
22175 + the test operands if one of the test operands is an output operand This beacuse
22176 + changing the test operands might cause the need for inserting a new test
22177 + insns in the middle of a sequence of cond_exec insns and if the test operands
22178 + are modified these tests will fail.
22179 + */
22180 + if ( IFCVT_ALLOW_MODIFY_TEST_IN_INSN
22181 + && predicated )
22182 + {
22183 + int insn_skipped = 0;
22184 + rtx test = COND_EXEC_TEST (PATTERN (insn));
22185 +
22186 + /* Check if the previous insn was a skipped predicated insn with the same
22187 + test as this predicated insns. If so we cannot do any modification to
22188 + this insn either since we cannot emit the test insn because the operands
22189 + are clobbered. */
22190 + if ( prev_pred_insn_skipped
22191 + && (rtx_equal_p (test, prev_pred_test)
22192 + || rtx_equal_p (test, reversed_condition (prev_pred_test))) )
22193 + {
22194 + insn_skipped = 1;
22195 + }
22196 + else
22197 + {
22198 + /* Check if the output operand is used in the test expression. */
22199 + for (i = 0; i < n_ops; ++i)
22200 + if ( recog_data.operand_type[i] == OP_INOUT
22201 + && reg_mentioned_p (recog_data.operand[i], test) )
22202 + {
22203 + insn_skipped = 1;
22204 + break;
22205 + }
22206 +
22207 + }
22208 +
22209 + prev_pred_test = test;
22210 + prev_pred_insn_skipped = insn_skipped;
22211 + if ( insn_skipped )
22212 + {
22213 + if (insn == BB_END (bb))
22214 + break;
22215 + else
22216 + continue;
22217 + }
22218 + }
22219 + else
22220 + {
22221 + prev_pred_insn_skipped = 0;
22222 + }
22223 +
22224 /* For each earlyclobber operand, zap the value data. */
22225 for (i = 0; i < n_ops; i++)
22226 if (recog_op_alt[i][alt].earlyclobber)
22227 --- a/gcc/sched-deps.c
22228 +++ b/gcc/sched-deps.c
22229 @@ -1406,7 +1406,14 @@ fixup_sched_groups (rtx insn)
22230
22231 prev_nonnote = prev_nonnote_insn (insn);
22232 if (BLOCK_FOR_INSN (insn) == BLOCK_FOR_INSN (prev_nonnote)
22233 - && ! sched_insns_conditions_mutex_p (insn, prev_nonnote))
22234 + /* Modification for AVR32 by RP: Why is this here, this will
22235 + cause instruction to be without any dependencies which might
22236 + cause it to be moved anywhere. For the AVR32 we try to keep
22237 + a group of conditionals together even if they are mutual exclusive.
22238 + */
22239 + && (! sched_insns_conditions_mutex_p (insn, prev_nonnote)
22240 + || GET_CODE (PATTERN (insn)) == COND_EXEC )
22241 + )
22242 add_dependence (insn, prev_nonnote, REG_DEP_ANTI);
22243 }
22244 \f
22245 @@ -1905,8 +1912,29 @@ sched_analyze_insn (struct deps *deps, r
22246
22247 if (code == COND_EXEC)
22248 {
22249 +#ifdef IFCVT_ALLOW_MODIFY_TEST_IN_INSN
22250 + if (IFCVT_ALLOW_MODIFY_TEST_IN_INSN)
22251 + {
22252 + /* Check if we have a group og conditional instructions with the same test.
22253 + If so we must make sure that they are not scheduled apart in order to
22254 + avoid unnecesarry tests and if one of the registers in the test is modified
22255 + in the instruction this is needed to ensure correct code. */
22256 + if ( prev_nonnote_insn (insn)
22257 + && INSN_P (prev_nonnote_insn (insn))
22258 + && GET_CODE (PATTERN (prev_nonnote_insn (insn))) == COND_EXEC
22259 + && rtx_equal_p (XEXP(COND_EXEC_TEST (PATTERN (prev_nonnote_insn (insn))), 0), XEXP (COND_EXEC_TEST (x), 0))
22260 + && rtx_equal_p (XEXP(COND_EXEC_TEST (PATTERN (prev_nonnote_insn (insn))), 1), XEXP (COND_EXEC_TEST (x), 1))
22261 + && ( GET_CODE (COND_EXEC_TEST (PATTERN (prev_nonnote_insn (insn)))) == GET_CODE (COND_EXEC_TEST (x))
22262 + || GET_CODE (COND_EXEC_TEST (PATTERN (prev_nonnote_insn (insn)))) == reversed_comparison_code (COND_EXEC_TEST (x), insn)))
22263 + {
22264 + SCHED_GROUP_P (insn) = 1;
22265 + //CANT_MOVE (prev_nonnote_insn (insn)) = 1;
22266 + }
22267 + }
22268 +#endif
22269 sched_analyze_2 (deps, COND_EXEC_TEST (x), insn);
22270
22271 +
22272 /* ??? Should be recording conditions so we reduce the number of
22273 false dependencies. */
22274 x = COND_EXEC_CODE (x);
22275 --- a/gcc/testsuite/gcc.dg/sibcall-3.c
22276 +++ b/gcc/testsuite/gcc.dg/sibcall-3.c
22277 @@ -5,7 +5,7 @@
22278 Copyright (C) 2002 Free Software Foundation Inc.
22279 Contributed by Hans-Peter Nilsson <hp@bitrange.com> */
22280
22281 -/* { dg-do run { xfail arc-*-* avr-*-* cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* m68hc1?-*-* mcore-*-* mn10300-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
22282 +/* { dg-do run { xfail arc-*-* avr-*-* avr32-*-* cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* m68hc1?-*-* mcore-*-* mn10300-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
22283 /* -mlongcall disables sibcall patterns. */
22284 /* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */
22285 /* { dg-options "-O2 -foptimize-sibling-calls" } */
22286 --- a/gcc/testsuite/gcc.dg/sibcall-4.c
22287 +++ b/gcc/testsuite/gcc.dg/sibcall-4.c
22288 @@ -5,7 +5,7 @@
22289 Copyright (C) 2002 Free Software Foundation Inc.
22290 Contributed by Hans-Peter Nilsson <hp@bitrange.com> */
22291
22292 -/* { dg-do run { xfail arc-*-* avr-*-* cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* m68hc1?-*-* mcore-*-* mn10300-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
22293 +/* { dg-do run { xfail arc-*-* avr-*-* avr32-*-* cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* m68hc1?-*-* mcore-*-* mn10300-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
22294 /* -mlongcall disables sibcall patterns. */
22295 /* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */
22296 /* { dg-options "-O2 -foptimize-sibling-calls" } */
22297 --- a/gcc/testsuite/gcc.dg/trampoline-1.c
22298 +++ b/gcc/testsuite/gcc.dg/trampoline-1.c
22299 @@ -46,6 +46,8 @@ void foo (void)
22300
22301 int main (void)
22302 {
22303 +#ifndef NO_TRAMPOLINES
22304 foo ();
22305 +#endif
22306 return 0;
22307 }
22308 --- a/gcc/testsuite/g++.old-deja/g++.pt/static11.C
22309 +++ b/gcc/testsuite/g++.old-deja/g++.pt/static11.C
22310 @@ -2,7 +2,7 @@
22311 // in their dejagnu baseboard description) require that the status is
22312 // final when exit is entered (or main returns), and not "overruled" by a
22313 // destructor calling _exit. It's not really worth it to handle that.
22314 -// { dg-do run { xfail mmix-knuth-mmixware arm*-*-elf arm*-*-eabi m68k-*-elf } }
22315 +// { dg-do run { xfail mmix-knuth-mmixware avr32-*-elf arm*-*-elf arm*-*-eabi m68k-*-elf } }
22316
22317 // Bug: g++ was failing to destroy C<int>::a because it was using two
22318 // different sentry variables for construction and destruction.
22319 --- a/libgcc/config.host
22320 +++ b/libgcc/config.host
22321 @@ -240,6 +240,13 @@ arm-*-pe*)
22322 ;;
22323 arm*-*-kaos*)
22324 ;;
22325 +avr32-*-linux*)
22326 + # No need to build crtbeginT.o on uClibc systems. Should probably be
22327 + # moved to the OS specific section above.
22328 + extra_parts="crtbegin.o crtbeginS.o crtend.o crtendS.o"
22329 + ;;
22330 +avr32-*-*)
22331 + ;;
22332 avr-*-rtems*)
22333 ;;
22334 avr-*-*)
22335 --- a/libstdc++-v3/config/os/gnu-linux/ctype_base.h
22336 +++ b/libstdc++-v3/config/os/gnu-linux/ctype_base.h
22337 @@ -31,6 +31,8 @@
22338 //
22339 // ISO C++ 14882: 22.1 Locales
22340 //
22341 +#include <features.h>
22342 +#include <ctype.h>
22343
22344 /** @file ctype_base.h
22345 * This is an internal header file, included by other library headers.
22346 @@ -45,7 +47,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
22347 struct ctype_base
22348 {
22349 // Non-standard typedefs.
22350 +#ifdef __UCLIBC__
22351 + typedef const __ctype_touplow_t* __to_type;
22352 +#else
22353 typedef const int* __to_type;
22354 +#endif
22355
22356 // NB: Offsets into ctype<char>::_M_table force a particular size
22357 // on the mask type. Because of this, we don't use an enum.
22358 --- a/libstdc++-v3/include/Makefile.in
22359 +++ b/libstdc++-v3/include/Makefile.in
22360 @@ -36,6 +36,7 @@ POST_UNINSTALL = :
22361 build_triplet = @build@
22362 host_triplet = @host@
22363 target_triplet = @target@
22364 +LIBOBJDIR =
22365 DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/Makefile.in \
22366 $(srcdir)/Makefile.am
22367 subdir = include
22368 --- a/libstdc++-v3/libmath/Makefile.in
22369 +++ b/libstdc++-v3/libmath/Makefile.in
22370 @@ -37,6 +37,7 @@ POST_UNINSTALL = :
22371 build_triplet = @build@
22372 host_triplet = @host@
22373 target_triplet = @target@
22374 +LIBOBJDIR =
22375 subdir = libmath
22376 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
22377 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
22378 --- a/libstdc++-v3/libsupc++/Makefile.in
22379 +++ b/libstdc++-v3/libsupc++/Makefile.in
22380 @@ -38,6 +38,7 @@ POST_UNINSTALL = :
22381 build_triplet = @build@
22382 host_triplet = @host@
22383 target_triplet = @target@
22384 +LIBOBJDIR =
22385 DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/Makefile.in \
22386 $(srcdir)/Makefile.am $(glibcxxinstall_HEADERS)
22387 subdir = libsupc++
22388 --- a/libstdc++-v3/Makefile.in
22389 +++ b/libstdc++-v3/Makefile.in
22390 @@ -36,6 +36,7 @@ POST_UNINSTALL = :
22391 build_triplet = @build@
22392 host_triplet = @host@
22393 target_triplet = @target@
22394 +LIBOBJDIR =
22395 DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/../config.guess \
22396 $(srcdir)/../config.sub README ChangeLog $(srcdir)/Makefile.in \
22397 $(srcdir)/Makefile.am $(top_srcdir)/configure \
22398 --- a/libstdc++-v3/po/Makefile.in
22399 +++ b/libstdc++-v3/po/Makefile.in
22400 @@ -36,6 +36,7 @@ POST_UNINSTALL = :
22401 build_triplet = @build@
22402 host_triplet = @host@
22403 target_triplet = @target@
22404 +LIBOBJDIR =
22405 DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/Makefile.in \
22406 $(srcdir)/Makefile.am
22407 subdir = po
22408 --- a/libstdc++-v3/src/Makefile.in
22409 +++ b/libstdc++-v3/src/Makefile.in
22410 @@ -37,6 +37,7 @@ POST_UNINSTALL = :
22411 build_triplet = @build@
22412 host_triplet = @host@
22413 target_triplet = @target@
22414 +LIBOBJDIR =
22415 DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/Makefile.in \
22416 $(srcdir)/Makefile.am
22417 subdir = src
This page took 1.321458 seconds and 3 git commands to generate.