[toolchain/gcc/4.3.5]: refresh patches
[openwrt/svn-archive/archive.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,7858 @@
26 +/*
27 + Target hooks and helper functions for AVR32.
28 + Copyright 2003-2006 Atmel Corporation.
29 +
30 + Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
31 + Initial porting by Anders �dland.
32 +
33 + This file is part of GCC.
34 +
35 + This program is free software; you can redistribute it and/or modify
36 + it under the terms of the GNU General Public License as published by
37 + the Free Software Foundation; either version 2 of the License, or
38 + (at your option) any later version.
39 +
40 + This program is distributed in the hope that it will be useful,
41 + but WITHOUT ANY WARRANTY; without even the implied warranty of
42 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 + GNU General Public License for more details.
44 +
45 + You should have received a copy of the GNU General Public License
46 + along with this program; if not, write to the Free Software
47 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
48 +
49 +#include "config.h"
50 +#include "system.h"
51 +#include "coretypes.h"
52 +#include "tm.h"
53 +#include "rtl.h"
54 +#include "tree.h"
55 +#include "obstack.h"
56 +#include "regs.h"
57 +#include "hard-reg-set.h"
58 +#include "real.h"
59 +#include "insn-config.h"
60 +#include "conditions.h"
61 +#include "output.h"
62 +#include "insn-attr.h"
63 +#include "flags.h"
64 +#include "reload.h"
65 +#include "function.h"
66 +#include "expr.h"
67 +#include "optabs.h"
68 +#include "toplev.h"
69 +#include "recog.h"
70 +#include "ggc.h"
71 +#include "except.h"
72 +#include "c-pragma.h"
73 +#include "integrate.h"
74 +#include "tm_p.h"
75 +#include "langhooks.h"
76 +#include "hooks.h"
77 +#include "df.h"
78 +
79 +#include "target.h"
80 +#include "target-def.h"
81 +
82 +#include <ctype.h>
83 +
84 +/* Forward definitions of types. */
85 +typedef struct minipool_node Mnode;
86 +typedef struct minipool_fixup Mfix;
87 +
88 +/* Obstack for minipool constant handling. */
89 +static struct obstack minipool_obstack;
90 +static char *minipool_startobj;
91 +static rtx minipool_vector_label;
92 +
93 +/* True if we are currently building a constant table. */
94 +int making_const_table;
95 +
96 +/* Some forward function declarations */
97 +static unsigned long avr32_isr_value (tree);
98 +static unsigned long avr32_compute_func_type (void);
99 +static tree avr32_handle_isr_attribute (tree *, tree, tree, int, bool *);
100 +static tree avr32_handle_acall_attribute (tree *, tree, tree, int, bool *);
101 +static tree avr32_handle_fndecl_attribute (tree * node, tree name, tree args,
102 + int flags, bool * no_add_attrs);
103 +static void avr32_reorg (void);
104 +bool avr32_return_in_msb (tree type);
105 +bool avr32_vector_mode_supported (enum machine_mode mode);
106 +static void avr32_init_libfuncs (void);
107 +
108 +
109 +static void
110 +avr32_add_gc_roots (void)
111 +{
112 + gcc_obstack_init (&minipool_obstack);
113 + minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
114 +}
115 +
116 +
117 +/* List of all known AVR32 parts */
118 +static const struct part_type_s avr32_part_types[] = {
119 + /* name, part_type, architecture type, macro */
120 + {"none", PART_TYPE_AVR32_NONE, ARCH_TYPE_AVR32_AP, "__AVR32__"},
121 + {"ap7000", PART_TYPE_AVR32_AP7000, ARCH_TYPE_AVR32_AP, "__AVR32_AP7000__"},
122 + {"ap7001", PART_TYPE_AVR32_AP7001, ARCH_TYPE_AVR32_AP, "__AVR32_AP7001__"},
123 + {"ap7002", PART_TYPE_AVR32_AP7002, ARCH_TYPE_AVR32_AP, "__AVR32_AP7002__"},
124 + {"ap7200", PART_TYPE_AVR32_AP7200, ARCH_TYPE_AVR32_AP, "__AVR32_AP7200__"},
125 + {"uc3a0128", PART_TYPE_AVR32_UC3A0128, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A0128__"},
126 + {"uc3a0256", PART_TYPE_AVR32_UC3A0256, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A0256__"},
127 + {"uc3a0512", PART_TYPE_AVR32_UC3A0512, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A0512__"},
128 + {"uc3a0512es", PART_TYPE_AVR32_UC3A0512ES, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3A0512ES__"},
129 + {"uc3a1128", PART_TYPE_AVR32_UC3A1128, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A1128__"},
130 + {"uc3a1256", PART_TYPE_AVR32_UC3A1256, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A1256__"},
131 + {"uc3a1512", PART_TYPE_AVR32_UC3A1512, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A1512__"},
132 + {"uc3a1512es", PART_TYPE_AVR32_UC3A1512ES, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3A1512ES__"},
133 + {"uc3a3revd", PART_TYPE_AVR32_UC3A3REVD, ARCH_TYPE_AVR32_UCR2NOMUL, "__AVR32_UC3A3256S__"},
134 + {"uc3a364", PART_TYPE_AVR32_UC3A364, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A364__"},
135 + {"uc3a364s", PART_TYPE_AVR32_UC3A364S, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A364S__"},
136 + {"uc3a3128", PART_TYPE_AVR32_UC3A3128, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A3128__"},
137 + {"uc3a3128s", PART_TYPE_AVR32_UC3A3128S, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A3128S__"},
138 + {"uc3a3256", PART_TYPE_AVR32_UC3A3256, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A3256__"},
139 + {"uc3a3256s", PART_TYPE_AVR32_UC3A3256S, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3A3256S__"},
140 + {"uc3b064", PART_TYPE_AVR32_UC3B064, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B064__"},
141 + {"uc3b0128", PART_TYPE_AVR32_UC3B0128, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B0128__"},
142 + {"uc3b0256", PART_TYPE_AVR32_UC3B0256, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B0256__"},
143 + {"uc3b0256es", PART_TYPE_AVR32_UC3B0256ES, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B0256ES__"},
144 + {"uc3b0512revc", PART_TYPE_AVR32_UC3B0512REVC, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3B0512REVC__"},
145 + {"uc3b164", PART_TYPE_AVR32_UC3B164, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B164__"},
146 + {"uc3b1128", PART_TYPE_AVR32_UC3B1128, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B1128__"},
147 + {"uc3b1256", PART_TYPE_AVR32_UC3B1256, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B1256__"},
148 + {"uc3b1256es", PART_TYPE_AVR32_UC3B1256ES, ARCH_TYPE_AVR32_UCR1, "__AVR32_UC3B1256ES__"},
149 + {"uc3b1512revc", PART_TYPE_AVR32_UC3B1512REVC, ARCH_TYPE_AVR32_UCR2, "__AVR32_UC3B1512REVC__"},
150 + {"uc3c0512c", PART_TYPE_AVR32_UC3C0512C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C0512C__"},
151 + {"uc3c0256c", PART_TYPE_AVR32_UC3C0256C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C0256C__"},
152 + {"uc3c0128c", PART_TYPE_AVR32_UC3C0128C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C0128C__"},
153 + {"uc3c064c", PART_TYPE_AVR32_UC3C064C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C064C__"},
154 + {"uc3c1512c", PART_TYPE_AVR32_UC3C1512C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C1512C__"},
155 + {"uc3c1256c", PART_TYPE_AVR32_UC3C1256C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C1256C__"},
156 + {"uc3c1128c", PART_TYPE_AVR32_UC3C1128C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C1128C__"},
157 + {"uc3c164c", PART_TYPE_AVR32_UC3C164C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C164C__"},
158 + {"uc3c2512c", PART_TYPE_AVR32_UC3C2512C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C2512C__"},
159 + {"uc3c2256c", PART_TYPE_AVR32_UC3C2256C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C2256C__"},
160 + {"uc3c2128c", PART_TYPE_AVR32_UC3C2128C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C2128C__"},
161 + {"uc3c264c", PART_TYPE_AVR32_UC3C264C, ARCH_TYPE_AVR32_UCR3, "__AVR32_UC3C264C__"},
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 + {NULL, 0, 0, NULL}
166 +};
167 +
168 +/* List of all known AVR32 architectures */
169 +static const struct arch_type_s avr32_arch_types[] = {
170 + /* name, architecture type, microarchitecture type, feature flags, macro */
171 + {"ap", ARCH_TYPE_AVR32_AP, UARCH_TYPE_AVR32B,
172 + (FLAG_AVR32_HAS_DSP
173 + | FLAG_AVR32_HAS_SIMD
174 + | FLAG_AVR32_HAS_UNALIGNED_WORD
175 + | FLAG_AVR32_HAS_BRANCH_PRED | FLAG_AVR32_HAS_RETURN_STACK
176 + | FLAG_AVR32_HAS_CACHES),
177 + "__AVR32_AP__"},
178 + {"ucr1", ARCH_TYPE_AVR32_UCR1, UARCH_TYPE_AVR32A,
179 + (FLAG_AVR32_HAS_DSP | FLAG_AVR32_HAS_RMW),
180 + "__AVR32_UC__=1"},
181 + {"ucr2", ARCH_TYPE_AVR32_UCR2, UARCH_TYPE_AVR32A,
182 + (FLAG_AVR32_HAS_DSP | FLAG_AVR32_HAS_RMW
183 + | FLAG_AVR32_HAS_V2_INSNS),
184 + "__AVR32_UC__=2"},
185 + {"ucr2nomul", ARCH_TYPE_AVR32_UCR2NOMUL, UARCH_TYPE_AVR32A,
186 + (FLAG_AVR32_HAS_DSP | FLAG_AVR32_HAS_RMW
187 + | FLAG_AVR32_HAS_V2_INSNS | FLAG_AVR32_HAS_NO_MUL_INSNS),
188 + "__AVR32_UC__=2"},
189 + {"ucr3", ARCH_TYPE_AVR32_UCR3, UARCH_TYPE_AVR32A,
190 + (FLAG_AVR32_HAS_DSP | FLAG_AVR32_HAS_RMW
191 + | FLAG_AVR32_HAS_V2_INSNS),
192 + "__AVR32_UC__=3"},
193 + {NULL, 0, 0, 0, NULL}
194 +};
195 +
196 +/* Default arch name */
197 +const char *avr32_arch_name = "none";
198 +const char *avr32_part_name = "none";
199 +
200 +const struct part_type_s *avr32_part;
201 +const struct arch_type_s *avr32_arch;
202 +
203 +
204 +/* Set default target_flags. */
205 +#undef TARGET_DEFAULT_TARGET_FLAGS
206 +#define TARGET_DEFAULT_TARGET_FLAGS \
207 + (MASK_HAS_ASM_ADDR_PSEUDOS | MASK_MD_REORG_OPTIMIZATION | MASK_COND_EXEC_BEFORE_RELOAD)
208 +
209 +void
210 +avr32_optimization_options (int level,
211 + int size){
212 + if (AVR32_ALWAYS_PIC)
213 + flag_pic = 1;
214 +
215 + /* Enable section anchors if optimization is enabled. */
216 + if (level > 0 || size)
217 + flag_section_anchors = 1;
218 +}
219 +
220 +/* Override command line options */
221 +void
222 +avr32_override_options (void)
223 +{
224 + const struct part_type_s *part;
225 + const struct arch_type_s *arch;
226 +
227 + /*Add backward compability*/
228 + if (strcmp ("uc", avr32_arch_name)== 0)
229 + {
230 + fprintf (stderr, "Warning: Deprecated arch `%s' specified. "
231 + "Please use '-march=ucr1' instead. "
232 + "Converting to arch 'ucr1'\n",
233 + avr32_arch_name);
234 + avr32_arch_name="ucr1";
235 + }
236 +
237 + /* Check if arch type is set. */
238 + for (arch = avr32_arch_types; arch->name; arch++)
239 + {
240 + if (strcmp (arch->name, avr32_arch_name) == 0)
241 + break;
242 + }
243 + avr32_arch = arch;
244 +
245 + if (!arch->name && strcmp("none", avr32_arch_name) != 0)
246 + {
247 + fprintf (stderr, "Unknown arch `%s' specified\n"
248 + "Known arch names:\n"
249 + "\tuc (deprecated)\n",
250 + avr32_arch_name);
251 + for (arch = avr32_arch_types; arch->name; arch++)
252 + fprintf (stderr, "\t%s\n", arch->name);
253 + avr32_arch = &avr32_arch_types[ARCH_TYPE_AVR32_AP];
254 + }
255 +
256 + /* Check if part type is set. */
257 + for (part = avr32_part_types; part->name; part++)
258 + if (strcmp (part->name, avr32_part_name) == 0)
259 + break;
260 +
261 + avr32_part = part;
262 + if (!part->name)
263 + {
264 + fprintf (stderr, "Unknown part `%s' specified\nKnown part names:\n",
265 + avr32_part_name);
266 + for (part = avr32_part_types; part->name; part++)
267 + {
268 + if (strcmp("none", part->name) != 0)
269 + fprintf (stderr, "\t%s\n", part->name);
270 + }
271 + /* Set default to NONE*/
272 + avr32_part = &avr32_part_types[PART_TYPE_AVR32_NONE];
273 + }
274 +
275 + /* NB! option -march= overrides option -mpart
276 + * if both are used at the same time */
277 + if (!arch->name)
278 + avr32_arch = &avr32_arch_types[avr32_part->arch_type];
279 +
280 + /* If optimization level is two or greater, then align start of loops to a
281 + word boundary since this will allow folding the first insn of the loop.
282 + Do this only for targets supporting branch prediction. */
283 + if (optimize >= 2 && TARGET_BRANCH_PRED)
284 + align_loops = 2;
285 +
286 +
287 + /* Enable fast-float library if unsafe math optimizations
288 + are used. */
289 + if (flag_unsafe_math_optimizations)
290 + target_flags |= MASK_FAST_FLOAT;
291 +
292 + /* Check if we should set avr32_imm_in_const_pool
293 + based on if caches are present or not. */
294 + if ( avr32_imm_in_const_pool == -1 )
295 + {
296 + if ( TARGET_CACHES )
297 + avr32_imm_in_const_pool = 1;
298 + else
299 + avr32_imm_in_const_pool = 0;
300 + }
301 +
302 + if (TARGET_NO_PIC)
303 + flag_pic = 0;
304 +
305 + avr32_add_gc_roots ();
306 +}
307 +
308 +
309 +/*
310 +If defined, a function that outputs the assembler code for entry to a
311 +function. The prologue is responsible for setting up the stack frame,
312 +initializing the frame pointer register, saving registers that must be
313 +saved, and allocating size additional bytes of storage for the
314 +local variables. size is an integer. file is a stdio
315 +stream to which the assembler code should be output.
316 +
317 +The label for the beginning of the function need not be output by this
318 +macro. That has already been done when the macro is run.
319 +
320 +To determine which registers to save, the macro can refer to the array
321 +regs_ever_live: element r is nonzero if hard register
322 +r is used anywhere within the function. This implies the function
323 +prologue should save register r, provided it is not one of the
324 +call-used registers. (TARGET_ASM_FUNCTION_EPILOGUE must likewise use
325 +regs_ever_live.)
326 +
327 +On machines that have ``register windows'', the function entry code does
328 +not save on the stack the registers that are in the windows, even if
329 +they are supposed to be preserved by function calls; instead it takes
330 +appropriate steps to ``push'' the register stack, if any non-call-used
331 +registers are used in the function.
332 +
333 +On machines where functions may or may not have frame-pointers, the
334 +function entry code must vary accordingly; it must set up the frame
335 +pointer if one is wanted, and not otherwise. To determine whether a
336 +frame pointer is in wanted, the macro can refer to the variable
337 +frame_pointer_needed. The variable's value will be 1 at run
338 +time in a function that needs a frame pointer. (see Elimination).
339 +
340 +The function entry code is responsible for allocating any stack space
341 +required for the function. This stack space consists of the regions
342 +listed below. In most cases, these regions are allocated in the
343 +order listed, with the last listed region closest to the top of the
344 +stack (the lowest address if STACK_GROWS_DOWNWARD is defined, and
345 +the highest address if it is not defined). You can use a different order
346 +for a machine if doing so is more convenient or required for
347 +compatibility reasons. Except in cases where required by standard
348 +or by a debugger, there is no reason why the stack layout used by GCC
349 +need agree with that used by other compilers for a machine.
350 +*/
351 +
352 +#undef TARGET_ASM_FUNCTION_PROLOGUE
353 +#define TARGET_ASM_FUNCTION_PROLOGUE avr32_target_asm_function_prologue
354 +
355 +
356 +#undef TARGET_DEFAULT_SHORT_ENUMS
357 +#define TARGET_DEFAULT_SHORT_ENUMS hook_bool_void_false
358 +
359 +#undef TARGET_PROMOTE_FUNCTION_ARGS
360 +#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
361 +
362 +#undef TARGET_PROMOTE_FUNCTION_RETURN
363 +#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
364 +
365 +#undef TARGET_PROMOTE_PROTOTYPES
366 +#define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
367 +
368 +#undef TARGET_MUST_PASS_IN_STACK
369 +#define TARGET_MUST_PASS_IN_STACK avr32_must_pass_in_stack
370 +
371 +#undef TARGET_PASS_BY_REFERENCE
372 +#define TARGET_PASS_BY_REFERENCE avr32_pass_by_reference
373 +
374 +#undef TARGET_STRICT_ARGUMENT_NAMING
375 +#define TARGET_STRICT_ARGUMENT_NAMING avr32_strict_argument_naming
376 +
377 +#undef TARGET_VECTOR_MODE_SUPPORTED_P
378 +#define TARGET_VECTOR_MODE_SUPPORTED_P avr32_vector_mode_supported
379 +
380 +#undef TARGET_RETURN_IN_MEMORY
381 +#define TARGET_RETURN_IN_MEMORY avr32_return_in_memory
382 +
383 +#undef TARGET_RETURN_IN_MSB
384 +#define TARGET_RETURN_IN_MSB avr32_return_in_msb
385 +
386 +#undef TARGET_ARG_PARTIAL_BYTES
387 +#define TARGET_ARG_PARTIAL_BYTES avr32_arg_partial_bytes
388 +
389 +#undef TARGET_STRIP_NAME_ENCODING
390 +#define TARGET_STRIP_NAME_ENCODING avr32_strip_name_encoding
391 +
392 +#define streq(string1, string2) (strcmp (string1, string2) == 0)
393 +
394 +#undef TARGET_NARROW_VOLATILE_BITFIELD
395 +#define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
396 +
397 +#undef TARGET_ATTRIBUTE_TABLE
398 +#define TARGET_ATTRIBUTE_TABLE avr32_attribute_table
399 +
400 +#undef TARGET_COMP_TYPE_ATTRIBUTES
401 +#define TARGET_COMP_TYPE_ATTRIBUTES avr32_comp_type_attributes
402 +
403 +
404 +#undef TARGET_RTX_COSTS
405 +#define TARGET_RTX_COSTS avr32_rtx_costs
406 +
407 +#undef TARGET_CANNOT_FORCE_CONST_MEM
408 +#define TARGET_CANNOT_FORCE_CONST_MEM avr32_cannot_force_const_mem
409 +
410 +#undef TARGET_ASM_INTEGER
411 +#define TARGET_ASM_INTEGER avr32_assemble_integer
412 +
413 +#undef TARGET_FUNCTION_VALUE
414 +#define TARGET_FUNCTION_VALUE avr32_function_value
415 +
416 +#undef TARGET_MIN_ANCHOR_OFFSET
417 +#define TARGET_MIN_ANCHOR_OFFSET (0)
418 +
419 +#undef TARGET_MAX_ANCHOR_OFFSET
420 +#define TARGET_MAX_ANCHOR_OFFSET ((1 << 15) - 1)
421 +
422 +
423 +/*
424 + * Switches to the appropriate section for output of constant pool
425 + * entry x in mode. You can assume that x is some kind of constant in
426 + * RTL. The argument mode is redundant except in the case of a
427 + * const_int rtx. Select the section by calling readonly_data_ section
428 + * or one of the alternatives for other sections. align is the
429 + * constant alignment in bits.
430 + *
431 + * The default version of this function takes care of putting symbolic
432 + * constants in flag_ pic mode in data_section and everything else in
433 + * readonly_data_section.
434 + */
435 +//#undef TARGET_ASM_SELECT_RTX_SECTION
436 +//#define TARGET_ASM_SELECT_RTX_SECTION avr32_select_rtx_section
437 +
438 +
439 +/*
440 + * If non-null, this hook performs a target-specific pass over the
441 + * instruction stream. The compiler will run it at all optimization
442 + * levels, just before the point at which it normally does
443 + * delayed-branch scheduling.
444 + *
445 + * The exact purpose of the hook varies from target to target. Some
446 + * use it to do transformations that are necessary for correctness,
447 + * such as laying out in-function constant pools or avoiding hardware
448 + * hazards. Others use it as an opportunity to do some
449 + * machine-dependent optimizations.
450 + *
451 + * You need not implement the hook if it has nothing to do. The
452 + * default definition is null.
453 + */
454 +#undef TARGET_MACHINE_DEPENDENT_REORG
455 +#define TARGET_MACHINE_DEPENDENT_REORG avr32_reorg
456 +
457 +/* Target hook for assembling integer objects.
458 + Need to handle integer vectors */
459 +static bool
460 +avr32_assemble_integer (rtx x, unsigned int size, int aligned_p)
461 +{
462 + if (avr32_vector_mode_supported (GET_MODE (x)))
463 + {
464 + int i, units;
465 +
466 + if (GET_CODE (x) != CONST_VECTOR)
467 + abort ();
468 +
469 + units = CONST_VECTOR_NUNITS (x);
470 +
471 + switch (GET_MODE (x))
472 + {
473 + case V2HImode:
474 + size = 2;
475 + break;
476 + case V4QImode:
477 + size = 1;
478 + break;
479 + default:
480 + abort ();
481 + }
482 +
483 + for (i = 0; i < units; i++)
484 + {
485 + rtx elt;
486 +
487 + elt = CONST_VECTOR_ELT (x, i);
488 + assemble_integer (elt, size, i == 0 ? 32 : size * BITS_PER_UNIT, 1);
489 + }
490 +
491 + return true;
492 + }
493 +
494 + return default_assemble_integer (x, size, aligned_p);
495 +}
496 +
497 +/*
498 + * This target hook describes the relative costs of RTL expressions.
499 + *
500 + * The cost may depend on the precise form of the expression, which is
501 + * available for examination in x, and the rtx code of the expression
502 + * in which it is contained, found in outer_code. code is the
503 + * expression code--redundant, since it can be obtained with GET_CODE
504 + * (x).
505 + *
506 + * In implementing this hook, you can use the construct COSTS_N_INSNS
507 + * (n) to specify a cost equal to n fast instructions.
508 + *
509 + * On entry to the hook, *total contains a default estimate for the
510 + * cost of the expression. The hook should modify this value as
511 + * necessary. Traditionally, the default costs are COSTS_N_INSNS (5)
512 + * for multiplications, COSTS_N_INSNS (7) for division and modulus
513 + * operations, and COSTS_N_INSNS (1) for all other operations.
514 + *
515 + * When optimizing for code size, i.e. when optimize_size is non-zero,
516 + * this target hook should be used to estimate the relative size cost
517 + * of an expression, again relative to COSTS_N_INSNS.
518 + *
519 + * The hook returns true when all subexpressions of x have been
520 + * processed, and false when rtx_cost should recurse.
521 + */
522 +
523 +/* Worker routine for avr32_rtx_costs. */
524 +static inline int
525 +avr32_rtx_costs_1 (rtx x, enum rtx_code code ATTRIBUTE_UNUSED,
526 + enum rtx_code outer ATTRIBUTE_UNUSED)
527 +{
528 + enum machine_mode mode = GET_MODE (x);
529 +
530 + switch (GET_CODE (x))
531 + {
532 + case MEM:
533 + /* Using pre decrement / post increment memory operations on the
534 + avr32_uc architecture means that two writebacks must be performed
535 + and hence two cycles are needed. */
536 + if (!optimize_size
537 + && GET_MODE_SIZE (mode) <= 2 * UNITS_PER_WORD
538 + && TARGET_ARCH_UC
539 + && (GET_CODE (XEXP (x, 0)) == PRE_DEC
540 + || GET_CODE (XEXP (x, 0)) == POST_INC))
541 + return COSTS_N_INSNS (5);
542 +
543 + /* Memory costs quite a lot for the first word, but subsequent words
544 + load at the equivalent of a single insn each. */
545 + if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
546 + return COSTS_N_INSNS (3 + (GET_MODE_SIZE (mode) / UNITS_PER_WORD));
547 +
548 + return COSTS_N_INSNS (4);
549 + case SYMBOL_REF:
550 + case CONST:
551 + /* These are valid for the pseudo insns: lda.w and call which operates
552 + on direct addresses. We assume that the cost of a lda.w is the same
553 + as the cost of a ld.w insn. */
554 + return (outer == SET) ? COSTS_N_INSNS (4) : COSTS_N_INSNS (1);
555 + case DIV:
556 + case MOD:
557 + case UDIV:
558 + case UMOD:
559 + return optimize_size ? COSTS_N_INSNS (1) : COSTS_N_INSNS (16);
560 +
561 + case ROTATE:
562 + case ROTATERT:
563 + if (mode == TImode)
564 + return COSTS_N_INSNS (100);
565 +
566 + if (mode == DImode)
567 + return COSTS_N_INSNS (10);
568 + return COSTS_N_INSNS (4);
569 + case ASHIFT:
570 + case LSHIFTRT:
571 + case ASHIFTRT:
572 + case NOT:
573 + if (mode == TImode)
574 + return COSTS_N_INSNS (10);
575 +
576 + if (mode == DImode)
577 + return COSTS_N_INSNS (4);
578 + return COSTS_N_INSNS (1);
579 + case PLUS:
580 + case MINUS:
581 + case NEG:
582 + case COMPARE:
583 + case ABS:
584 + if (GET_MODE_CLASS (mode) == MODE_FLOAT)
585 + return COSTS_N_INSNS (100);
586 +
587 + if (mode == TImode)
588 + return COSTS_N_INSNS (50);
589 +
590 + if (mode == DImode)
591 + return COSTS_N_INSNS (2);
592 + return COSTS_N_INSNS (1);
593 +
594 + case MULT:
595 + {
596 + if (GET_MODE_CLASS (mode) == MODE_FLOAT)
597 + return COSTS_N_INSNS (300);
598 +
599 + if (mode == TImode)
600 + return COSTS_N_INSNS (16);
601 +
602 + if (mode == DImode)
603 + return COSTS_N_INSNS (4);
604 +
605 + if (mode == HImode)
606 + return COSTS_N_INSNS (2);
607 +
608 + return COSTS_N_INSNS (3);
609 + }
610 + case IF_THEN_ELSE:
611 + if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC)
612 + return COSTS_N_INSNS (4);
613 + return COSTS_N_INSNS (1);
614 + case SIGN_EXTEND:
615 + case ZERO_EXTEND:
616 + /* Sign/Zero extensions of registers cost quite much since these
617 + instrcutions only take one register operand which means that gcc
618 + often must insert some move instrcutions */
619 + if (mode == QImode || mode == HImode)
620 + return (COSTS_N_INSNS (GET_CODE (XEXP (x, 0)) == MEM ? 0 : 1));
621 + return COSTS_N_INSNS (4);
622 + case UNSPEC:
623 + /* divmod operations */
624 + if (XINT (x, 1) == UNSPEC_UDIVMODSI4_INTERNAL
625 + || XINT (x, 1) == UNSPEC_DIVMODSI4_INTERNAL)
626 + {
627 + return optimize_size ? COSTS_N_INSNS (1) : COSTS_N_INSNS (16);
628 + }
629 + /* Fallthrough */
630 + default:
631 + return COSTS_N_INSNS (1);
632 + }
633 +}
634 +
635 +static bool
636 +avr32_rtx_costs (rtx x, int code, int outer_code, int *total)
637 +{
638 + *total = avr32_rtx_costs_1 (x, code, outer_code);
639 + return true;
640 +}
641 +
642 +
643 +bool
644 +avr32_cannot_force_const_mem (rtx x ATTRIBUTE_UNUSED)
645 +{
646 + /* Do not want symbols in the constant pool when compiling pic or if using
647 + address pseudo instructions. */
648 + return ((flag_pic || TARGET_HAS_ASM_ADDR_PSEUDOS)
649 + && avr32_find_symbol (x) != NULL_RTX);
650 +}
651 +
652 +
653 +/* Table of machine attributes. */
654 +const struct attribute_spec avr32_attribute_table[] = {
655 + /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
656 + /* Interrupt Service Routines have special prologue and epilogue
657 + requirements. */
658 + {"isr", 0, 1, false, false, false, avr32_handle_isr_attribute},
659 + {"interrupt", 0, 1, false, false, false, avr32_handle_isr_attribute},
660 + {"acall", 0, 1, false, true, true, avr32_handle_acall_attribute},
661 + {"naked", 0, 0, true, false, false, avr32_handle_fndecl_attribute},
662 + {NULL, 0, 0, false, false, false, NULL}
663 +};
664 +
665 +
666 +typedef struct
667 +{
668 + const char *const arg;
669 + const unsigned long return_value;
670 +}
671 +isr_attribute_arg;
672 +
673 +static const isr_attribute_arg isr_attribute_args[] = {
674 + {"FULL", AVR32_FT_ISR_FULL},
675 + {"full", AVR32_FT_ISR_FULL},
676 + {"HALF", AVR32_FT_ISR_HALF},
677 + {"half", AVR32_FT_ISR_HALF},
678 + {"NONE", AVR32_FT_ISR_NONE},
679 + {"none", AVR32_FT_ISR_NONE},
680 + {"UNDEF", AVR32_FT_ISR_NONE},
681 + {"undef", AVR32_FT_ISR_NONE},
682 + {"SWI", AVR32_FT_ISR_NONE},
683 + {"swi", AVR32_FT_ISR_NONE},
684 + {NULL, AVR32_FT_ISR_NONE}
685 +};
686 +
687 +/* Returns the (interrupt) function type of the current
688 + function, or AVR32_FT_UNKNOWN if the type cannot be determined. */
689 +
690 +static unsigned long
691 +avr32_isr_value (tree argument)
692 +{
693 + const isr_attribute_arg *ptr;
694 + const char *arg;
695 +
696 + /* No argument - default to ISR_NONE. */
697 + if (argument == NULL_TREE)
698 + return AVR32_FT_ISR_NONE;
699 +
700 + /* Get the value of the argument. */
701 + if (TREE_VALUE (argument) == NULL_TREE
702 + || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
703 + return AVR32_FT_UNKNOWN;
704 +
705 + arg = TREE_STRING_POINTER (TREE_VALUE (argument));
706 +
707 + /* Check it against the list of known arguments. */
708 + for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
709 + if (streq (arg, ptr->arg))
710 + return ptr->return_value;
711 +
712 + /* An unrecognized interrupt type. */
713 + return AVR32_FT_UNKNOWN;
714 +}
715 +
716 +
717 +
718 +/*
719 +These hooks specify assembly directives for creating certain kinds
720 +of integer object. The TARGET_ASM_BYTE_OP directive creates a
721 +byte-sized object, the TARGET_ASM_ALIGNED_HI_OP one creates an
722 +aligned two-byte object, and so on. Any of the hooks may be
723 +NULL, indicating that no suitable directive is available.
724 +
725 +The compiler will print these strings at the start of a new line,
726 +followed immediately by the object's initial value. In most cases,
727 +the string should contain a tab, a pseudo-op, and then another tab.
728 +*/
729 +#undef TARGET_ASM_BYTE_OP
730 +#define TARGET_ASM_BYTE_OP "\t.byte\t"
731 +#undef TARGET_ASM_ALIGNED_HI_OP
732 +#define TARGET_ASM_ALIGNED_HI_OP "\t.align 1\n\t.short\t"
733 +#undef TARGET_ASM_ALIGNED_SI_OP
734 +#define TARGET_ASM_ALIGNED_SI_OP "\t.align 2\n\t.int\t"
735 +#undef TARGET_ASM_ALIGNED_DI_OP
736 +#define TARGET_ASM_ALIGNED_DI_OP NULL
737 +#undef TARGET_ASM_ALIGNED_TI_OP
738 +#define TARGET_ASM_ALIGNED_TI_OP NULL
739 +#undef TARGET_ASM_UNALIGNED_HI_OP
740 +#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
741 +#undef TARGET_ASM_UNALIGNED_SI_OP
742 +#define TARGET_ASM_UNALIGNED_SI_OP "\t.int\t"
743 +#undef TARGET_ASM_UNALIGNED_DI_OP
744 +#define TARGET_ASM_UNALIGNED_DI_OP NULL
745 +#undef TARGET_ASM_UNALIGNED_TI_OP
746 +#define TARGET_ASM_UNALIGNED_TI_OP NULL
747 +
748 +#undef TARGET_ASM_OUTPUT_MI_THUNK
749 +#define TARGET_ASM_OUTPUT_MI_THUNK avr32_output_mi_thunk
750 +
751 +#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
752 +#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
753 +
754 +static void
755 +avr32_output_mi_thunk (FILE * file,
756 + tree thunk ATTRIBUTE_UNUSED,
757 + HOST_WIDE_INT delta,
758 + HOST_WIDE_INT vcall_offset, tree function)
759 + {
760 + int mi_delta = delta;
761 + int this_regno =
762 + (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function) ?
763 + INTERNAL_REGNUM (11) : INTERNAL_REGNUM (12));
764 +
765 +
766 + if (!avr32_const_ok_for_constraint_p (mi_delta, 'I', "Is21")
767 + || vcall_offset)
768 + {
769 + fputs ("\tpushm\tlr\n", file);
770 + }
771 +
772 +
773 + if (mi_delta != 0)
774 + {
775 + if (avr32_const_ok_for_constraint_p (mi_delta, 'I', "Is21"))
776 + {
777 + fprintf (file, "\tsub\t%s, %d\n", reg_names[this_regno], -mi_delta);
778 + }
779 + else
780 + {
781 + /* Immediate is larger than k21 we must make us a temp register by
782 + pushing a register to the stack. */
783 + fprintf (file, "\tmov\tlr, lo(%d)\n", mi_delta);
784 + fprintf (file, "\torh\tlr, hi(%d)\n", mi_delta);
785 + fprintf (file, "\tadd\t%s, lr\n", reg_names[this_regno]);
786 + }
787 + }
788 +
789 +
790 + if (vcall_offset != 0)
791 + {
792 + fprintf (file, "\tld.w\tlr, %s[0]\n", reg_names[this_regno]);
793 + fprintf (file, "\tld.w\tlr, lr[%i]\n", (int) vcall_offset);
794 + fprintf (file, "\tadd\t%s, lr\n", reg_names[this_regno]);
795 + }
796 +
797 +
798 + if (!avr32_const_ok_for_constraint_p (mi_delta, 'I', "Is21")
799 + || vcall_offset)
800 + {
801 + fputs ("\tpopm\tlr\n", file);
802 + }
803 +
804 + /* Jump to the function. We assume that we can use an rjmp since the
805 + function to jump to is local and probably not too far away from
806 + the thunk. If this assumption proves to be wrong we could implement
807 + this jump by calculating the offset between the jump source and destination
808 + and put this in the constant pool and then perform an add to pc.
809 + This would also be legitimate PIC code. But for now we hope that an rjmp
810 + will be sufficient...
811 + */
812 + fputs ("\trjmp\t", file);
813 + assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0));
814 + fputc ('\n', file);
815 + }
816 +
817 +
818 +/* Implements target hook vector_mode_supported. */
819 +bool
820 +avr32_vector_mode_supported (enum machine_mode mode)
821 +{
822 + if ((mode == V2HImode) || (mode == V4QImode))
823 + return true;
824 +
825 + return false;
826 +}
827 +
828 +
829 +#undef TARGET_INIT_LIBFUNCS
830 +#define TARGET_INIT_LIBFUNCS avr32_init_libfuncs
831 +
832 +#undef TARGET_INIT_BUILTINS
833 +#define TARGET_INIT_BUILTINS avr32_init_builtins
834 +
835 +#undef TARGET_EXPAND_BUILTIN
836 +#define TARGET_EXPAND_BUILTIN avr32_expand_builtin
837 +
838 +tree int_ftype_int, int_ftype_void, short_ftype_short, void_ftype_int_int,
839 + void_ftype_ptr_int;
840 +tree void_ftype_int, void_ftype_void, int_ftype_ptr_int;
841 +tree short_ftype_short, int_ftype_int_short, int_ftype_short_short,
842 + short_ftype_short_short;
843 +tree int_ftype_int_int, longlong_ftype_int_short, longlong_ftype_short_short;
844 +tree void_ftype_int_int_int_int_int, void_ftype_int_int_int;
845 +tree longlong_ftype_int_int, void_ftype_int_int_longlong;
846 +tree int_ftype_int_int_int, longlong_ftype_longlong_int_short;
847 +tree longlong_ftype_longlong_short_short, int_ftype_int_short_short;
848 +
849 +#define def_builtin(NAME, TYPE, CODE) \
850 + add_builtin_function ((NAME), (TYPE), (CODE), \
851 + BUILT_IN_MD, NULL, NULL_TREE)
852 +
853 +#define def_mbuiltin(MASK, NAME, TYPE, CODE) \
854 + do \
855 + { \
856 + if ((MASK)) \
857 + add_builtin_function ((NAME), (TYPE), (CODE), \
858 + BUILT_IN_MD, NULL, NULL_TREE); \
859 + } \
860 + while (0)
861 +
862 +struct builtin_description
863 +{
864 + const unsigned int mask;
865 + const enum insn_code icode;
866 + const char *const name;
867 + const int code;
868 + const enum rtx_code comparison;
869 + const unsigned int flag;
870 + const tree *ftype;
871 +};
872 +
873 +static const struct builtin_description bdesc_2arg[] = {
874 +#define DSP_BUILTIN(code, builtin, ftype) \
875 + { 1, CODE_FOR_##code, "__builtin_" #code , \
876 + AVR32_BUILTIN_##builtin, 0, 0, ftype }
877 +
878 + DSP_BUILTIN (mulsathh_h, MULSATHH_H, &short_ftype_short_short),
879 + DSP_BUILTIN (mulsathh_w, MULSATHH_W, &int_ftype_short_short),
880 + DSP_BUILTIN (mulsatrndhh_h, MULSATRNDHH_H, &short_ftype_short_short),
881 + DSP_BUILTIN (mulsatrndwh_w, MULSATRNDWH_W, &int_ftype_int_short),
882 + DSP_BUILTIN (mulsatwh_w, MULSATWH_W, &int_ftype_int_short),
883 + DSP_BUILTIN (satadd_h, SATADD_H, &short_ftype_short_short),
884 + DSP_BUILTIN (satsub_h, SATSUB_H, &short_ftype_short_short),
885 + DSP_BUILTIN (satadd_w, SATADD_W, &int_ftype_int_int),
886 + DSP_BUILTIN (satsub_w, SATSUB_W, &int_ftype_int_int),
887 + DSP_BUILTIN (mulwh_d, MULWH_D, &longlong_ftype_int_short),
888 + DSP_BUILTIN (mulnwh_d, MULNWH_D, &longlong_ftype_int_short)
889 +};
890 +
891 +
892 +void
893 +avr32_init_builtins (void)
894 +{
895 + unsigned int i;
896 + const struct builtin_description *d;
897 + tree endlink = void_list_node;
898 + tree int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
899 + tree longlong_endlink =
900 + tree_cons (NULL_TREE, long_long_integer_type_node, endlink);
901 + tree short_endlink =
902 + tree_cons (NULL_TREE, short_integer_type_node, endlink);
903 + tree void_endlink = tree_cons (NULL_TREE, void_type_node, endlink);
904 +
905 + /* int func (int) */
906 + int_ftype_int = build_function_type (integer_type_node, int_endlink);
907 +
908 + /* short func (short) */
909 + short_ftype_short
910 + = build_function_type (short_integer_type_node, short_endlink);
911 +
912 + /* short func (short, short) */
913 + short_ftype_short_short
914 + = build_function_type (short_integer_type_node,
915 + tree_cons (NULL_TREE, short_integer_type_node,
916 + short_endlink));
917 +
918 + /* long long func (long long, short, short) */
919 + longlong_ftype_longlong_short_short
920 + = build_function_type (long_long_integer_type_node,
921 + tree_cons (NULL_TREE, long_long_integer_type_node,
922 + tree_cons (NULL_TREE,
923 + short_integer_type_node,
924 + short_endlink)));
925 +
926 + /* long long func (short, short) */
927 + longlong_ftype_short_short
928 + = build_function_type (long_long_integer_type_node,
929 + tree_cons (NULL_TREE, short_integer_type_node,
930 + short_endlink));
931 +
932 + /* int func (int, int) */
933 + int_ftype_int_int
934 + = build_function_type (integer_type_node,
935 + tree_cons (NULL_TREE, integer_type_node,
936 + int_endlink));
937 +
938 + /* long long func (int, int) */
939 + longlong_ftype_int_int
940 + = build_function_type (long_long_integer_type_node,
941 + tree_cons (NULL_TREE, integer_type_node,
942 + int_endlink));
943 +
944 + /* long long int func (long long, int, short) */
945 + longlong_ftype_longlong_int_short
946 + = build_function_type (long_long_integer_type_node,
947 + tree_cons (NULL_TREE, long_long_integer_type_node,
948 + tree_cons (NULL_TREE, integer_type_node,
949 + short_endlink)));
950 +
951 + /* long long int func (int, short) */
952 + longlong_ftype_int_short
953 + = build_function_type (long_long_integer_type_node,
954 + tree_cons (NULL_TREE, integer_type_node,
955 + short_endlink));
956 +
957 + /* int func (int, short, short) */
958 + int_ftype_int_short_short
959 + = build_function_type (integer_type_node,
960 + tree_cons (NULL_TREE, integer_type_node,
961 + tree_cons (NULL_TREE,
962 + short_integer_type_node,
963 + short_endlink)));
964 +
965 + /* int func (short, short) */
966 + int_ftype_short_short
967 + = build_function_type (integer_type_node,
968 + tree_cons (NULL_TREE, short_integer_type_node,
969 + short_endlink));
970 +
971 + /* int func (int, short) */
972 + int_ftype_int_short
973 + = build_function_type (integer_type_node,
974 + tree_cons (NULL_TREE, integer_type_node,
975 + short_endlink));
976 +
977 + /* void func (int, int) */
978 + void_ftype_int_int
979 + = build_function_type (void_type_node,
980 + tree_cons (NULL_TREE, integer_type_node,
981 + int_endlink));
982 +
983 + /* void func (int, int, int) */
984 + void_ftype_int_int_int
985 + = build_function_type (void_type_node,
986 + tree_cons (NULL_TREE, integer_type_node,
987 + tree_cons (NULL_TREE, integer_type_node,
988 + int_endlink)));
989 +
990 + /* void func (int, int, long long) */
991 + void_ftype_int_int_longlong
992 + = build_function_type (void_type_node,
993 + tree_cons (NULL_TREE, integer_type_node,
994 + tree_cons (NULL_TREE, integer_type_node,
995 + longlong_endlink)));
996 +
997 + /* void func (int, int, int, int, int) */
998 + void_ftype_int_int_int_int_int
999 + = build_function_type (void_type_node,
1000 + tree_cons (NULL_TREE, integer_type_node,
1001 + tree_cons (NULL_TREE, integer_type_node,
1002 + tree_cons (NULL_TREE,
1003 + integer_type_node,
1004 + tree_cons
1005 + (NULL_TREE,
1006 + integer_type_node,
1007 + int_endlink)))));
1008 +
1009 + /* void func (void *, int) */
1010 + void_ftype_ptr_int
1011 + = build_function_type (void_type_node,
1012 + tree_cons (NULL_TREE, ptr_type_node, int_endlink));
1013 +
1014 + /* void func (int) */
1015 + void_ftype_int = build_function_type (void_type_node, int_endlink);
1016 +
1017 + /* void func (void) */
1018 + void_ftype_void = build_function_type (void_type_node, void_endlink);
1019 +
1020 + /* int func (void) */
1021 + int_ftype_void = build_function_type (integer_type_node, void_endlink);
1022 +
1023 + /* int func (void *, int) */
1024 + int_ftype_ptr_int
1025 + = build_function_type (integer_type_node,
1026 + tree_cons (NULL_TREE, ptr_type_node, int_endlink));
1027 +
1028 + /* int func (int, int, int) */
1029 + int_ftype_int_int_int
1030 + = build_function_type (integer_type_node,
1031 + tree_cons (NULL_TREE, integer_type_node,
1032 + tree_cons (NULL_TREE, integer_type_node,
1033 + int_endlink)));
1034 +
1035 + /* Initialize avr32 builtins. */
1036 + def_builtin ("__builtin_mfsr", int_ftype_int, AVR32_BUILTIN_MFSR);
1037 + def_builtin ("__builtin_mtsr", void_ftype_int_int, AVR32_BUILTIN_MTSR);
1038 + def_builtin ("__builtin_mfdr", int_ftype_int, AVR32_BUILTIN_MFDR);
1039 + def_builtin ("__builtin_mtdr", void_ftype_int_int, AVR32_BUILTIN_MTDR);
1040 + def_builtin ("__builtin_cache", void_ftype_ptr_int, AVR32_BUILTIN_CACHE);
1041 + def_builtin ("__builtin_sync", void_ftype_int, AVR32_BUILTIN_SYNC);
1042 + def_builtin ("__builtin_ssrf", void_ftype_int, AVR32_BUILTIN_SSRF);
1043 + def_builtin ("__builtin_csrf", void_ftype_int, AVR32_BUILTIN_CSRF);
1044 + def_builtin ("__builtin_tlbr", void_ftype_void, AVR32_BUILTIN_TLBR);
1045 + def_builtin ("__builtin_tlbs", void_ftype_void, AVR32_BUILTIN_TLBS);
1046 + def_builtin ("__builtin_tlbw", void_ftype_void, AVR32_BUILTIN_TLBW);
1047 + def_builtin ("__builtin_breakpoint", void_ftype_void,
1048 + AVR32_BUILTIN_BREAKPOINT);
1049 + def_builtin ("__builtin_xchg", int_ftype_ptr_int, AVR32_BUILTIN_XCHG);
1050 + def_builtin ("__builtin_ldxi", int_ftype_ptr_int, AVR32_BUILTIN_LDXI);
1051 + def_builtin ("__builtin_bswap_16", short_ftype_short,
1052 + AVR32_BUILTIN_BSWAP16);
1053 + def_builtin ("__builtin_bswap_32", int_ftype_int, AVR32_BUILTIN_BSWAP32);
1054 + def_builtin ("__builtin_cop", void_ftype_int_int_int_int_int,
1055 + AVR32_BUILTIN_COP);
1056 + def_builtin ("__builtin_mvcr_w", int_ftype_int_int, AVR32_BUILTIN_MVCR_W);
1057 + def_builtin ("__builtin_mvrc_w", void_ftype_int_int_int,
1058 + AVR32_BUILTIN_MVRC_W);
1059 + def_builtin ("__builtin_mvcr_d", longlong_ftype_int_int,
1060 + AVR32_BUILTIN_MVCR_D);
1061 + def_builtin ("__builtin_mvrc_d", void_ftype_int_int_longlong,
1062 + AVR32_BUILTIN_MVRC_D);
1063 + def_builtin ("__builtin_sats", int_ftype_int_int_int, AVR32_BUILTIN_SATS);
1064 + def_builtin ("__builtin_satu", int_ftype_int_int_int, AVR32_BUILTIN_SATU);
1065 + def_builtin ("__builtin_satrnds", int_ftype_int_int_int,
1066 + AVR32_BUILTIN_SATRNDS);
1067 + def_builtin ("__builtin_satrndu", int_ftype_int_int_int,
1068 + AVR32_BUILTIN_SATRNDU);
1069 + def_builtin ("__builtin_musfr", void_ftype_int, AVR32_BUILTIN_MUSFR);
1070 + def_builtin ("__builtin_mustr", int_ftype_void, AVR32_BUILTIN_MUSTR);
1071 + def_builtin ("__builtin_macsathh_w", int_ftype_int_short_short,
1072 + AVR32_BUILTIN_MACSATHH_W);
1073 + def_builtin ("__builtin_macwh_d", longlong_ftype_longlong_int_short,
1074 + AVR32_BUILTIN_MACWH_D);
1075 + def_builtin ("__builtin_machh_d", longlong_ftype_longlong_short_short,
1076 + AVR32_BUILTIN_MACHH_D);
1077 +
1078 + /* Add all builtins that are more or less simple operations on two
1079 + operands. */
1080 + for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
1081 + {
1082 + /* Use one of the operands; the target can have a different mode for
1083 + mask-generating compares. */
1084 +
1085 + if (d->name == 0)
1086 + continue;
1087 +
1088 + def_mbuiltin (d->mask, d->name, *(d->ftype), d->code);
1089 + }
1090 +}
1091 +
1092 +
1093 +/* Subroutine of avr32_expand_builtin to take care of binop insns. */
1094 +
1095 +static rtx
1096 +avr32_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
1097 +{
1098 + rtx pat;
1099 + tree arg0 = CALL_EXPR_ARG (exp,0);
1100 + tree arg1 = CALL_EXPR_ARG (exp,1);
1101 + rtx op0 = expand_normal (arg0);
1102 + rtx op1 = expand_normal (arg1);
1103 + enum machine_mode tmode = insn_data[icode].operand[0].mode;
1104 + enum machine_mode mode0 = insn_data[icode].operand[1].mode;
1105 + enum machine_mode mode1 = insn_data[icode].operand[2].mode;
1106 +
1107 + if (!target
1108 + || GET_MODE (target) != tmode
1109 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1110 + target = gen_reg_rtx (tmode);
1111 +
1112 + /* In case the insn wants input operands in modes different from the
1113 + result, abort. */
1114 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1115 + {
1116 + /* If op0 is already a reg we must cast it to the correct mode. */
1117 + if (REG_P (op0))
1118 + op0 = convert_to_mode (mode0, op0, 1);
1119 + else
1120 + op0 = copy_to_mode_reg (mode0, op0);
1121 + }
1122 + if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
1123 + {
1124 + /* If op1 is already a reg we must cast it to the correct mode. */
1125 + if (REG_P (op1))
1126 + op1 = convert_to_mode (mode1, op1, 1);
1127 + else
1128 + op1 = copy_to_mode_reg (mode1, op1);
1129 + }
1130 + pat = GEN_FCN (icode) (target, op0, op1);
1131 + if (!pat)
1132 + return 0;
1133 + emit_insn (pat);
1134 + return target;
1135 +}
1136 +
1137 +/* Expand an expression EXP that calls a built-in function,
1138 + with result going to TARGET if that's convenient
1139 + (and in mode MODE if that's convenient).
1140 + SUBTARGET may be used as the target for computing one of EXP's operands.
1141 + IGNORE is nonzero if the value is to be ignored. */
1142 +
1143 +rtx
1144 +avr32_expand_builtin (tree exp,
1145 + rtx target,
1146 + rtx subtarget ATTRIBUTE_UNUSED,
1147 + enum machine_mode mode ATTRIBUTE_UNUSED,
1148 + int ignore ATTRIBUTE_UNUSED)
1149 +{
1150 + const struct builtin_description *d;
1151 + unsigned int i;
1152 + enum insn_code icode = 0;
1153 + tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
1154 + tree arg0, arg1, arg2;
1155 + rtx op0, op1, op2, pat;
1156 + enum machine_mode tmode, mode0, mode1;
1157 + enum machine_mode arg0_mode;
1158 + int fcode = DECL_FUNCTION_CODE (fndecl);
1159 +
1160 + switch (fcode)
1161 + {
1162 + default:
1163 + break;
1164 +
1165 + case AVR32_BUILTIN_SATS:
1166 + case AVR32_BUILTIN_SATU:
1167 + case AVR32_BUILTIN_SATRNDS:
1168 + case AVR32_BUILTIN_SATRNDU:
1169 + {
1170 + const char *fname;
1171 + switch (fcode)
1172 + {
1173 + default:
1174 + case AVR32_BUILTIN_SATS:
1175 + icode = CODE_FOR_sats;
1176 + fname = "sats";
1177 + break;
1178 + case AVR32_BUILTIN_SATU:
1179 + icode = CODE_FOR_satu;
1180 + fname = "satu";
1181 + break;
1182 + case AVR32_BUILTIN_SATRNDS:
1183 + icode = CODE_FOR_satrnds;
1184 + fname = "satrnds";
1185 + break;
1186 + case AVR32_BUILTIN_SATRNDU:
1187 + icode = CODE_FOR_satrndu;
1188 + fname = "satrndu";
1189 + break;
1190 + }
1191 +
1192 + arg0 = CALL_EXPR_ARG (exp,0);
1193 + arg1 = CALL_EXPR_ARG (exp,1);
1194 + arg2 = CALL_EXPR_ARG (exp,2);
1195 + op0 = expand_normal (arg0);
1196 + op1 = expand_normal (arg1);
1197 + op2 = expand_normal (arg2);
1198 +
1199 + tmode = insn_data[icode].operand[0].mode;
1200 +
1201 +
1202 + if (target == 0
1203 + || GET_MODE (target) != tmode
1204 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1205 + target = gen_reg_rtx (tmode);
1206 +
1207 +
1208 + if (!(*insn_data[icode].operand[0].predicate) (op0, GET_MODE (op0)))
1209 + {
1210 + op0 = copy_to_mode_reg (insn_data[icode].operand[0].mode, op0);
1211 + }
1212 +
1213 + if (!(*insn_data[icode].operand[1].predicate) (op1, SImode))
1214 + {
1215 + error ("Parameter 2 to __builtin_%s should be a constant number.",
1216 + fname);
1217 + return NULL_RTX;
1218 + }
1219 +
1220 + if (!(*insn_data[icode].operand[1].predicate) (op2, SImode))
1221 + {
1222 + error ("Parameter 3 to __builtin_%s should be a constant number.",
1223 + fname);
1224 + return NULL_RTX;
1225 + }
1226 +
1227 + emit_move_insn (target, op0);
1228 + pat = GEN_FCN (icode) (target, op1, op2);
1229 + if (!pat)
1230 + return 0;
1231 + emit_insn (pat);
1232 +
1233 + return target;
1234 + }
1235 + case AVR32_BUILTIN_MUSTR:
1236 + icode = CODE_FOR_mustr;
1237 + tmode = insn_data[icode].operand[0].mode;
1238 +
1239 + if (target == 0
1240 + || GET_MODE (target) != tmode
1241 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1242 + target = gen_reg_rtx (tmode);
1243 + pat = GEN_FCN (icode) (target);
1244 + if (!pat)
1245 + return 0;
1246 + emit_insn (pat);
1247 + return target;
1248 +
1249 + case AVR32_BUILTIN_MFSR:
1250 + icode = CODE_FOR_mfsr;
1251 + arg0 = CALL_EXPR_ARG (exp,0);
1252 + op0 = expand_normal (arg0);
1253 + tmode = insn_data[icode].operand[0].mode;
1254 + mode0 = insn_data[icode].operand[1].mode;
1255 +
1256 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1257 + {
1258 + error ("Parameter 1 to __builtin_mfsr must be a constant number");
1259 + }
1260 +
1261 + if (target == 0
1262 + || GET_MODE (target) != tmode
1263 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1264 + target = gen_reg_rtx (tmode);
1265 + pat = GEN_FCN (icode) (target, op0);
1266 + if (!pat)
1267 + return 0;
1268 + emit_insn (pat);
1269 + return target;
1270 + case AVR32_BUILTIN_MTSR:
1271 + icode = CODE_FOR_mtsr;
1272 + arg0 = CALL_EXPR_ARG (exp,0);
1273 + arg1 = CALL_EXPR_ARG (exp,1);
1274 + op0 = expand_normal (arg0);
1275 + op1 = expand_normal (arg1);
1276 + mode0 = insn_data[icode].operand[0].mode;
1277 + mode1 = insn_data[icode].operand[1].mode;
1278 +
1279 + if (!(*insn_data[icode].operand[0].predicate) (op0, mode0))
1280 + {
1281 + error ("Parameter 1 to __builtin_mtsr must be a constant number");
1282 + return gen_reg_rtx (mode0);
1283 + }
1284 + if (!(*insn_data[icode].operand[1].predicate) (op1, mode1))
1285 + op1 = copy_to_mode_reg (mode1, op1);
1286 + pat = GEN_FCN (icode) (op0, op1);
1287 + if (!pat)
1288 + return 0;
1289 + emit_insn (pat);
1290 + return NULL_RTX;
1291 + case AVR32_BUILTIN_MFDR:
1292 + icode = CODE_FOR_mfdr;
1293 + arg0 = CALL_EXPR_ARG (exp,0);
1294 + op0 = expand_normal (arg0);
1295 + tmode = insn_data[icode].operand[0].mode;
1296 + mode0 = insn_data[icode].operand[1].mode;
1297 +
1298 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1299 + {
1300 + error ("Parameter 1 to __builtin_mfdr must be a constant number");
1301 + }
1302 +
1303 + if (target == 0
1304 + || GET_MODE (target) != tmode
1305 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1306 + target = gen_reg_rtx (tmode);
1307 + pat = GEN_FCN (icode) (target, op0);
1308 + if (!pat)
1309 + return 0;
1310 + emit_insn (pat);
1311 + return target;
1312 + case AVR32_BUILTIN_MTDR:
1313 + icode = CODE_FOR_mtdr;
1314 + arg0 = CALL_EXPR_ARG (exp,0);
1315 + arg1 = CALL_EXPR_ARG (exp,1);
1316 + op0 = expand_normal (arg0);
1317 + op1 = expand_normal (arg1);
1318 + mode0 = insn_data[icode].operand[0].mode;
1319 + mode1 = insn_data[icode].operand[1].mode;
1320 +
1321 + if (!(*insn_data[icode].operand[0].predicate) (op0, mode0))
1322 + {
1323 + error ("Parameter 1 to __builtin_mtdr must be a constant number");
1324 + return gen_reg_rtx (mode0);
1325 + }
1326 + if (!(*insn_data[icode].operand[1].predicate) (op1, mode1))
1327 + op1 = copy_to_mode_reg (mode1, op1);
1328 + pat = GEN_FCN (icode) (op0, op1);
1329 + if (!pat)
1330 + return 0;
1331 + emit_insn (pat);
1332 + return NULL_RTX;
1333 + case AVR32_BUILTIN_CACHE:
1334 + icode = CODE_FOR_cache;
1335 + arg0 = CALL_EXPR_ARG (exp,0);
1336 + arg1 = CALL_EXPR_ARG (exp,1);
1337 + op0 = expand_normal (arg0);
1338 + op1 = expand_normal (arg1);
1339 + mode0 = insn_data[icode].operand[0].mode;
1340 + mode1 = insn_data[icode].operand[1].mode;
1341 +
1342 + if (!(*insn_data[icode].operand[1].predicate) (op1, mode1))
1343 + {
1344 + error ("Parameter 2 to __builtin_cache must be a constant number");
1345 + return gen_reg_rtx (mode1);
1346 + }
1347 +
1348 + if (!(*insn_data[icode].operand[0].predicate) (op0, mode0))
1349 + op0 = copy_to_mode_reg (mode0, op0);
1350 +
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_SYNC:
1357 + case AVR32_BUILTIN_MUSFR:
1358 + case AVR32_BUILTIN_SSRF:
1359 + case AVR32_BUILTIN_CSRF:
1360 + {
1361 + const char *fname;
1362 + switch (fcode)
1363 + {
1364 + default:
1365 + case AVR32_BUILTIN_SYNC:
1366 + icode = CODE_FOR_sync;
1367 + fname = "sync";
1368 + break;
1369 + case AVR32_BUILTIN_MUSFR:
1370 + icode = CODE_FOR_musfr;
1371 + fname = "musfr";
1372 + break;
1373 + case AVR32_BUILTIN_SSRF:
1374 + icode = CODE_FOR_ssrf;
1375 + fname = "ssrf";
1376 + break;
1377 + case AVR32_BUILTIN_CSRF:
1378 + icode = CODE_FOR_csrf;
1379 + fname = "csrf";
1380 + break;
1381 + }
1382 +
1383 + arg0 = CALL_EXPR_ARG (exp,0);
1384 + op0 = expand_normal (arg0);
1385 + mode0 = insn_data[icode].operand[0].mode;
1386 +
1387 + if (!(*insn_data[icode].operand[0].predicate) (op0, mode0))
1388 + {
1389 + if (icode == CODE_FOR_musfr)
1390 + op0 = copy_to_mode_reg (mode0, op0);
1391 + else
1392 + {
1393 + error ("Parameter to __builtin_%s is illegal.", fname);
1394 + return gen_reg_rtx (mode0);
1395 + }
1396 + }
1397 + pat = GEN_FCN (icode) (op0);
1398 + if (!pat)
1399 + return 0;
1400 + emit_insn (pat);
1401 + return NULL_RTX;
1402 + }
1403 + case AVR32_BUILTIN_TLBR:
1404 + icode = CODE_FOR_tlbr;
1405 + pat = GEN_FCN (icode) (NULL_RTX);
1406 + if (!pat)
1407 + return 0;
1408 + emit_insn (pat);
1409 + return NULL_RTX;
1410 + case AVR32_BUILTIN_TLBS:
1411 + icode = CODE_FOR_tlbs;
1412 + pat = GEN_FCN (icode) (NULL_RTX);
1413 + if (!pat)
1414 + return 0;
1415 + emit_insn (pat);
1416 + return NULL_RTX;
1417 + case AVR32_BUILTIN_TLBW:
1418 + icode = CODE_FOR_tlbw;
1419 + pat = GEN_FCN (icode) (NULL_RTX);
1420 + if (!pat)
1421 + return 0;
1422 + emit_insn (pat);
1423 + return NULL_RTX;
1424 + case AVR32_BUILTIN_BREAKPOINT:
1425 + icode = CODE_FOR_breakpoint;
1426 + pat = GEN_FCN (icode) (NULL_RTX);
1427 + if (!pat)
1428 + return 0;
1429 + emit_insn (pat);
1430 + return NULL_RTX;
1431 + case AVR32_BUILTIN_XCHG:
1432 + icode = CODE_FOR_sync_lock_test_and_setsi;
1433 + arg0 = CALL_EXPR_ARG (exp,0);
1434 + arg1 = CALL_EXPR_ARG (exp,1);
1435 + op0 = expand_normal (arg0);
1436 + op1 = expand_normal (arg1);
1437 + tmode = insn_data[icode].operand[0].mode;
1438 + mode0 = insn_data[icode].operand[1].mode;
1439 + mode1 = insn_data[icode].operand[2].mode;
1440 +
1441 + if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
1442 + {
1443 + op1 = copy_to_mode_reg (mode1, op1);
1444 + }
1445 +
1446 + op0 = force_reg (GET_MODE (op0), op0);
1447 + op0 = gen_rtx_MEM (GET_MODE (op0), op0);
1448 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1449 + {
1450 + error
1451 + ("Parameter 1 to __builtin_xchg must be a pointer to an integer.");
1452 + }
1453 +
1454 + if (target == 0
1455 + || GET_MODE (target) != tmode
1456 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1457 + target = gen_reg_rtx (tmode);
1458 + pat = GEN_FCN (icode) (target, op0, op1);
1459 + if (!pat)
1460 + return 0;
1461 + emit_insn (pat);
1462 + return target;
1463 + case AVR32_BUILTIN_LDXI:
1464 + icode = CODE_FOR_ldxi;
1465 + arg0 = CALL_EXPR_ARG (exp,0);
1466 + arg1 = CALL_EXPR_ARG (exp,1);
1467 + arg2 = CALL_EXPR_ARG (exp,2);
1468 + op0 = expand_normal (arg0);
1469 + op1 = expand_normal (arg1);
1470 + op2 = expand_normal (arg2);
1471 + tmode = insn_data[icode].operand[0].mode;
1472 + mode0 = insn_data[icode].operand[1].mode;
1473 + mode1 = insn_data[icode].operand[2].mode;
1474 +
1475 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1476 + {
1477 + op0 = copy_to_mode_reg (mode0, op0);
1478 + }
1479 +
1480 + if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
1481 + {
1482 + op1 = copy_to_mode_reg (mode1, op1);
1483 + }
1484 +
1485 + if (!(*insn_data[icode].operand[3].predicate) (op2, SImode))
1486 + {
1487 + error
1488 + ("Parameter 3 to __builtin_ldxi must be a valid extract shift operand: (0|8|16|24)");
1489 + return gen_reg_rtx (mode0);
1490 + }
1491 +
1492 + if (target == 0
1493 + || GET_MODE (target) != tmode
1494 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1495 + target = gen_reg_rtx (tmode);
1496 + pat = GEN_FCN (icode) (target, op0, op1, op2);
1497 + if (!pat)
1498 + return 0;
1499 + emit_insn (pat);
1500 + return target;
1501 + case AVR32_BUILTIN_BSWAP16:
1502 + {
1503 + icode = CODE_FOR_bswap_16;
1504 + arg0 = CALL_EXPR_ARG (exp,0);
1505 + arg0_mode = TYPE_MODE (TREE_TYPE (arg0));
1506 + mode0 = insn_data[icode].operand[1].mode;
1507 + if (arg0_mode != mode0)
1508 + arg0 = build1 (NOP_EXPR,
1509 + (*lang_hooks.types.type_for_mode) (mode0, 0), arg0);
1510 +
1511 + op0 = expand_expr (arg0, NULL_RTX, HImode, 0);
1512 + tmode = insn_data[icode].operand[0].mode;
1513 +
1514 +
1515 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1516 + {
1517 + if ( CONST_INT_P (op0) )
1518 + {
1519 + HOST_WIDE_INT val = ( ((INTVAL (op0)&0x00ff) << 8) |
1520 + ((INTVAL (op0)&0xff00) >> 8) );
1521 + /* Sign extend 16-bit value to host wide int */
1522 + val <<= (HOST_BITS_PER_WIDE_INT - 16);
1523 + val >>= (HOST_BITS_PER_WIDE_INT - 16);
1524 + op0 = GEN_INT(val);
1525 + if (target == 0
1526 + || GET_MODE (target) != tmode
1527 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1528 + target = gen_reg_rtx (tmode);
1529 + emit_move_insn(target, op0);
1530 + return target;
1531 + }
1532 + else
1533 + op0 = copy_to_mode_reg (mode0, op0);
1534 + }
1535 +
1536 + if (target == 0
1537 + || GET_MODE (target) != tmode
1538 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1539 + {
1540 + target = gen_reg_rtx (tmode);
1541 + }
1542 +
1543 +
1544 + pat = GEN_FCN (icode) (target, op0);
1545 + if (!pat)
1546 + return 0;
1547 + emit_insn (pat);
1548 +
1549 + return target;
1550 + }
1551 + case AVR32_BUILTIN_BSWAP32:
1552 + {
1553 + icode = CODE_FOR_bswap_32;
1554 + arg0 = CALL_EXPR_ARG (exp,0);
1555 + op0 = expand_normal (arg0);
1556 + tmode = insn_data[icode].operand[0].mode;
1557 + mode0 = insn_data[icode].operand[1].mode;
1558 +
1559 + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
1560 + {
1561 + if ( CONST_INT_P (op0) )
1562 + {
1563 + HOST_WIDE_INT val = ( ((INTVAL (op0)&0x000000ff) << 24) |
1564 + ((INTVAL (op0)&0x0000ff00) << 8) |
1565 + ((INTVAL (op0)&0x00ff0000) >> 8) |
1566 + ((INTVAL (op0)&0xff000000) >> 24) );
1567 + /* Sign extend 32-bit value to host wide int */
1568 + val <<= (HOST_BITS_PER_WIDE_INT - 32);
1569 + val >>= (HOST_BITS_PER_WIDE_INT - 32);
1570 + op0 = GEN_INT(val);
1571 + if (target == 0
1572 + || GET_MODE (target) != tmode
1573 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1574 + target = gen_reg_rtx (tmode);
1575 + emit_move_insn(target, op0);
1576 + return target;
1577 + }
1578 + else
1579 + op0 = copy_to_mode_reg (mode0, op0);
1580 + }
1581 +
1582 + if (target == 0
1583 + || GET_MODE (target) != tmode
1584 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1585 + target = gen_reg_rtx (tmode);
1586 +
1587 +
1588 + pat = GEN_FCN (icode) (target, op0);
1589 + if (!pat)
1590 + return 0;
1591 + emit_insn (pat);
1592 +
1593 + return target;
1594 + }
1595 + case AVR32_BUILTIN_MVCR_W:
1596 + case AVR32_BUILTIN_MVCR_D:
1597 + {
1598 + arg0 = CALL_EXPR_ARG (exp,0);
1599 + arg1 = CALL_EXPR_ARG (exp,1);
1600 + op0 = expand_normal (arg0);
1601 + op1 = expand_normal (arg1);
1602 +
1603 + if (fcode == AVR32_BUILTIN_MVCR_W)
1604 + icode = CODE_FOR_mvcrsi;
1605 + else
1606 + icode = CODE_FOR_mvcrdi;
1607 +
1608 + tmode = insn_data[icode].operand[0].mode;
1609 +
1610 + if (target == 0
1611 + || GET_MODE (target) != tmode
1612 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1613 + target = gen_reg_rtx (tmode);
1614 +
1615 + if (!(*insn_data[icode].operand[1].predicate) (op0, SImode))
1616 + {
1617 + error
1618 + ("Parameter 1 to __builtin_cop is not a valid coprocessor number.");
1619 + error ("Number should be between 0 and 7.");
1620 + return NULL_RTX;
1621 + }
1622 +
1623 + if (!(*insn_data[icode].operand[2].predicate) (op1, SImode))
1624 + {
1625 + error
1626 + ("Parameter 2 to __builtin_cop is not a valid coprocessor register number.");
1627 + error ("Number should be between 0 and 15.");
1628 + return NULL_RTX;
1629 + }
1630 +
1631 + pat = GEN_FCN (icode) (target, op0, op1);
1632 + if (!pat)
1633 + return 0;
1634 + emit_insn (pat);
1635 +
1636 + return target;
1637 + }
1638 + case AVR32_BUILTIN_MACSATHH_W:
1639 + case AVR32_BUILTIN_MACWH_D:
1640 + case AVR32_BUILTIN_MACHH_D:
1641 + {
1642 + arg0 = CALL_EXPR_ARG (exp,0);
1643 + arg1 = CALL_EXPR_ARG (exp,1);
1644 + arg2 = CALL_EXPR_ARG (exp,2);
1645 + op0 = expand_normal (arg0);
1646 + op1 = expand_normal (arg1);
1647 + op2 = expand_normal (arg2);
1648 +
1649 + icode = ((fcode == AVR32_BUILTIN_MACSATHH_W) ? CODE_FOR_macsathh_w :
1650 + (fcode == AVR32_BUILTIN_MACWH_D) ? CODE_FOR_macwh_d :
1651 + CODE_FOR_machh_d);
1652 +
1653 + tmode = insn_data[icode].operand[0].mode;
1654 + mode0 = insn_data[icode].operand[1].mode;
1655 + mode1 = insn_data[icode].operand[2].mode;
1656 +
1657 +
1658 + if (!target
1659 + || GET_MODE (target) != tmode
1660 + || !(*insn_data[icode].operand[0].predicate) (target, tmode))
1661 + target = gen_reg_rtx (tmode);
1662 +
1663 + if (!(*insn_data[icode].operand[0].predicate) (op0, tmode))
1664 + {
1665 + /* If op0 is already a reg we must cast it to the correct mode. */
1666 + if (REG_P (op0))
1667 + op0 = convert_to_mode (tmode, op0, 1);
1668 + else
1669 + op0 = copy_to_mode_reg (tmode, op0);
1670 + }
1671 +
1672 + if (!(*insn_data[icode].operand[1].predicate) (op1, mode0))
1673 + {
1674 + /* If op1 is already a reg we must cast it to the correct mode. */
1675 + if (REG_P (op1))
1676 + op1 = convert_to_mode (mode0, op1, 1);
1677 + else
1678 + op1 = copy_to_mode_reg (mode0, op1);
1679 + }
1680 +
1681 + if (!(*insn_data[icode].operand[2].predicate) (op2, mode1))
1682 + {
1683 + /* If op1 is already a reg we must cast it to the correct mode. */
1684 + if (REG_P (op2))
1685 + op2 = convert_to_mode (mode1, op2, 1);
1686 + else
1687 + op2 = copy_to_mode_reg (mode1, op2);
1688 + }
1689 +
1690 + emit_move_insn (target, op0);
1691 +
1692 + pat = GEN_FCN (icode) (target, op1, op2);
1693 + if (!pat)
1694 + return 0;
1695 + emit_insn (pat);
1696 + return target;
1697 + }
1698 + case AVR32_BUILTIN_MVRC_W:
1699 + case AVR32_BUILTIN_MVRC_D:
1700 + {
1701 + arg0 = CALL_EXPR_ARG (exp,0);
1702 + arg1 = CALL_EXPR_ARG (exp,1);
1703 + arg2 = CALL_EXPR_ARG (exp,2);
1704 + op0 = expand_normal (arg0);
1705 + op1 = expand_normal (arg1);
1706 + op2 = expand_normal (arg2);
1707 +
1708 + if (fcode == AVR32_BUILTIN_MVRC_W)
1709 + icode = CODE_FOR_mvrcsi;
1710 + else
1711 + icode = CODE_FOR_mvrcdi;
1712 +
1713 + if (!(*insn_data[icode].operand[0].predicate) (op0, SImode))
1714 + {
1715 + error ("Parameter 1 is not a valid coprocessor number.");
1716 + error ("Number should be between 0 and 7.");
1717 + return NULL_RTX;
1718 + }
1719 +
1720 + if (!(*insn_data[icode].operand[1].predicate) (op1, SImode))
1721 + {
1722 + error ("Parameter 2 is not a valid coprocessor register number.");
1723 + error ("Number should be between 0 and 15.");
1724 + return NULL_RTX;
1725 + }
1726 +
1727 + if (GET_CODE (op2) == CONST_INT
1728 + || GET_CODE (op2) == CONST
1729 + || GET_CODE (op2) == SYMBOL_REF || GET_CODE (op2) == LABEL_REF)
1730 + {
1731 + op2 = force_const_mem (insn_data[icode].operand[2].mode, op2);
1732 + }
1733 +
1734 + if (!(*insn_data[icode].operand[2].predicate) (op2, GET_MODE (op2)))
1735 + op2 = copy_to_mode_reg (insn_data[icode].operand[2].mode, op2);
1736 +
1737 +
1738 + pat = GEN_FCN (icode) (op0, op1, op2);
1739 + if (!pat)
1740 + return 0;
1741 + emit_insn (pat);
1742 +
1743 + return NULL_RTX;
1744 + }
1745 + case AVR32_BUILTIN_COP:
1746 + {
1747 + rtx op3, op4;
1748 + tree arg3, arg4;
1749 + icode = CODE_FOR_cop;
1750 + arg0 = CALL_EXPR_ARG (exp,0);
1751 + arg1 = CALL_EXPR_ARG (exp,1);
1752 + arg2 = CALL_EXPR_ARG (exp,2);
1753 + arg3 = CALL_EXPR_ARG (exp,3);
1754 + arg4 = CALL_EXPR_ARG (exp,4);
1755 + op0 = expand_normal (arg0);
1756 + op1 = expand_normal (arg1);
1757 + op2 = expand_normal (arg2);
1758 + op3 = expand_normal (arg3);
1759 + op4 = expand_normal (arg4);
1760 +
1761 + if (!(*insn_data[icode].operand[0].predicate) (op0, SImode))
1762 + {
1763 + error
1764 + ("Parameter 1 to __builtin_cop is not a valid coprocessor number.");
1765 + error ("Number should be between 0 and 7.");
1766 + return NULL_RTX;
1767 + }
1768 +
1769 + if (!(*insn_data[icode].operand[1].predicate) (op1, SImode))
1770 + {
1771 + error
1772 + ("Parameter 2 to __builtin_cop is not a valid coprocessor register number.");
1773 + error ("Number should be between 0 and 15.");
1774 + return NULL_RTX;
1775 + }
1776 +
1777 + if (!(*insn_data[icode].operand[2].predicate) (op2, SImode))
1778 + {
1779 + error
1780 + ("Parameter 3 to __builtin_cop is not a valid coprocessor register number.");
1781 + error ("Number should be between 0 and 15.");
1782 + return NULL_RTX;
1783 + }
1784 +
1785 + if (!(*insn_data[icode].operand[3].predicate) (op3, SImode))
1786 + {
1787 + error
1788 + ("Parameter 4 to __builtin_cop is not a valid coprocessor register number.");
1789 + error ("Number should be between 0 and 15.");
1790 + return NULL_RTX;
1791 + }
1792 +
1793 + if (!(*insn_data[icode].operand[4].predicate) (op4, SImode))
1794 + {
1795 + error
1796 + ("Parameter 5 to __builtin_cop is not a valid coprocessor operation.");
1797 + error ("Number should be between 0 and 127.");
1798 + return NULL_RTX;
1799 + }
1800 +
1801 + pat = GEN_FCN (icode) (op0, op1, op2, op3, op4);
1802 + if (!pat)
1803 + return 0;
1804 + emit_insn (pat);
1805 +
1806 + return target;
1807 + }
1808 +
1809 + }
1810 +
1811 + for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
1812 + if (d->code == fcode)
1813 + return avr32_expand_binop_builtin (d->icode, exp, target);
1814 +
1815 +
1816 + /* @@@ Should really do something sensible here. */
1817 + return NULL_RTX;
1818 +}
1819 +
1820 +
1821 +/* Handle an "interrupt" or "isr" attribute;
1822 + arguments as in struct attribute_spec.handler. */
1823 +
1824 +static tree
1825 +avr32_handle_isr_attribute (tree * node, tree name, tree args,
1826 + int flags, bool * no_add_attrs)
1827 +{
1828 + if (DECL_P (*node))
1829 + {
1830 + if (TREE_CODE (*node) != FUNCTION_DECL)
1831 + {
1832 + warning (OPT_Wattributes,"`%s' attribute only applies to functions",
1833 + IDENTIFIER_POINTER (name));
1834 + *no_add_attrs = true;
1835 + }
1836 + /* FIXME: the argument if any is checked for type attributes; should it
1837 + be checked for decl ones? */
1838 + }
1839 + else
1840 + {
1841 + if (TREE_CODE (*node) == FUNCTION_TYPE
1842 + || TREE_CODE (*node) == METHOD_TYPE)
1843 + {
1844 + if (avr32_isr_value (args) == AVR32_FT_UNKNOWN)
1845 + {
1846 + warning (OPT_Wattributes,"`%s' attribute ignored", IDENTIFIER_POINTER (name));
1847 + *no_add_attrs = true;
1848 + }
1849 + }
1850 + else if (TREE_CODE (*node) == POINTER_TYPE
1851 + && (TREE_CODE (TREE_TYPE (*node)) == FUNCTION_TYPE
1852 + || TREE_CODE (TREE_TYPE (*node)) == METHOD_TYPE)
1853 + && avr32_isr_value (args) != AVR32_FT_UNKNOWN)
1854 + {
1855 + *node = build_variant_type_copy (*node);
1856 + TREE_TYPE (*node) = build_type_attribute_variant
1857 + (TREE_TYPE (*node),
1858 + tree_cons (name, args, TYPE_ATTRIBUTES (TREE_TYPE (*node))));
1859 + *no_add_attrs = true;
1860 + }
1861 + else
1862 + {
1863 + /* Possibly pass this attribute on from the type to a decl. */
1864 + if (flags & ((int) ATTR_FLAG_DECL_NEXT
1865 + | (int) ATTR_FLAG_FUNCTION_NEXT
1866 + | (int) ATTR_FLAG_ARRAY_NEXT))
1867 + {
1868 + *no_add_attrs = true;
1869 + return tree_cons (name, args, NULL_TREE);
1870 + }
1871 + else
1872 + {
1873 + warning (OPT_Wattributes,"`%s' attribute ignored", IDENTIFIER_POINTER (name));
1874 + }
1875 + }
1876 + }
1877 +
1878 + return NULL_TREE;
1879 +}
1880 +
1881 +/* Handle an attribute requiring a FUNCTION_DECL;
1882 + arguments as in struct attribute_spec.handler. */
1883 +static tree
1884 +avr32_handle_fndecl_attribute (tree * node, tree name,
1885 + tree args ATTRIBUTE_UNUSED,
1886 + int flags ATTRIBUTE_UNUSED,
1887 + bool * no_add_attrs)
1888 +{
1889 + if (TREE_CODE (*node) != FUNCTION_DECL)
1890 + {
1891 + warning (OPT_Wattributes,"%qs attribute only applies to functions",
1892 + IDENTIFIER_POINTER (name));
1893 + *no_add_attrs = true;
1894 + }
1895 +
1896 + return NULL_TREE;
1897 +}
1898 +
1899 +
1900 +/* Handle an acall attribute;
1901 + arguments as in struct attribute_spec.handler. */
1902 +
1903 +static tree
1904 +avr32_handle_acall_attribute (tree * node, tree name,
1905 + tree args ATTRIBUTE_UNUSED,
1906 + int flags ATTRIBUTE_UNUSED, bool * no_add_attrs)
1907 +{
1908 + if (TREE_CODE (*node) == FUNCTION_TYPE || TREE_CODE (*node) == METHOD_TYPE)
1909 + {
1910 + warning (OPT_Wattributes,"`%s' attribute not yet supported...",
1911 + IDENTIFIER_POINTER (name));
1912 + *no_add_attrs = true;
1913 + return NULL_TREE;
1914 + }
1915 +
1916 + warning (OPT_Wattributes,"`%s' attribute only applies to functions",
1917 + IDENTIFIER_POINTER (name));
1918 + *no_add_attrs = true;
1919 + return NULL_TREE;
1920 +}
1921 +
1922 +
1923 +/* Return 0 if the attributes for two types are incompatible, 1 if they
1924 + are compatible, and 2 if they are nearly compatible (which causes a
1925 + warning to be generated). */
1926 +
1927 +static int
1928 +avr32_comp_type_attributes (tree type1, tree type2)
1929 +{
1930 + int acall1, acall2, isr1, isr2, naked1, naked2;
1931 +
1932 + /* Check for mismatch of non-default calling convention. */
1933 + if (TREE_CODE (type1) != FUNCTION_TYPE)
1934 + return 1;
1935 +
1936 + /* Check for mismatched call attributes. */
1937 + acall1 = lookup_attribute ("acall", TYPE_ATTRIBUTES (type1)) != NULL;
1938 + acall2 = lookup_attribute ("acall", TYPE_ATTRIBUTES (type2)) != NULL;
1939 + naked1 = lookup_attribute ("naked", TYPE_ATTRIBUTES (type1)) != NULL;
1940 + naked2 = lookup_attribute ("naked", TYPE_ATTRIBUTES (type2)) != NULL;
1941 + isr1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL;
1942 + if (!isr1)
1943 + isr1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL;
1944 +
1945 + isr2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL;
1946 + if (!isr2)
1947 + isr2 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL;
1948 +
1949 + if ((acall1 && isr2)
1950 + || (acall2 && isr1) || (naked1 && isr2) || (naked2 && isr1))
1951 + return 0;
1952 +
1953 + return 1;
1954 +}
1955 +
1956 +
1957 +/* Computes the type of the current function. */
1958 +
1959 +static unsigned long
1960 +avr32_compute_func_type (void)
1961 +{
1962 + unsigned long type = AVR32_FT_UNKNOWN;
1963 + tree a;
1964 + tree attr;
1965 +
1966 + if (TREE_CODE (current_function_decl) != FUNCTION_DECL)
1967 + abort ();
1968 +
1969 + /* Decide if the current function is volatile. Such functions never
1970 + return, and many memory cycles can be saved by not storing register
1971 + values that will never be needed again. This optimization was added to
1972 + speed up context switching in a kernel application. */
1973 + if (optimize > 0
1974 + && TREE_NOTHROW (current_function_decl)
1975 + && TREE_THIS_VOLATILE (current_function_decl))
1976 + type |= AVR32_FT_VOLATILE;
1977 +
1978 + if (cfun->static_chain_decl != NULL)
1979 + type |= AVR32_FT_NESTED;
1980 +
1981 + attr = DECL_ATTRIBUTES (current_function_decl);
1982 +
1983 + a = lookup_attribute ("isr", attr);
1984 + if (a == NULL_TREE)
1985 + a = lookup_attribute ("interrupt", attr);
1986 +
1987 + if (a == NULL_TREE)
1988 + type |= AVR32_FT_NORMAL;
1989 + else
1990 + type |= avr32_isr_value (TREE_VALUE (a));
1991 +
1992 +
1993 + a = lookup_attribute ("acall", attr);
1994 + if (a != NULL_TREE)
1995 + type |= AVR32_FT_ACALL;
1996 +
1997 + a = lookup_attribute ("naked", attr);
1998 + if (a != NULL_TREE)
1999 + type |= AVR32_FT_NAKED;
2000 +
2001 + return type;
2002 +}
2003 +
2004 +/* Returns the type of the current function. */
2005 +
2006 +static unsigned long
2007 +avr32_current_func_type (void)
2008 +{
2009 + if (AVR32_FUNC_TYPE (cfun->machine->func_type) == AVR32_FT_UNKNOWN)
2010 + cfun->machine->func_type = avr32_compute_func_type ();
2011 +
2012 + return cfun->machine->func_type;
2013 +}
2014 +
2015 +/*
2016 + This target hook should return true if we should not pass type solely
2017 + in registers. The file expr.h defines a definition that is usually appropriate,
2018 + refer to expr.h for additional documentation.
2019 +*/
2020 +bool
2021 +avr32_must_pass_in_stack (enum machine_mode mode ATTRIBUTE_UNUSED, tree type)
2022 +{
2023 + if (type && AGGREGATE_TYPE_P (type)
2024 + /* If the alignment is less than the size then pass in the struct on
2025 + the stack. */
2026 + && ((unsigned int) TYPE_ALIGN_UNIT (type) <
2027 + (unsigned int) int_size_in_bytes (type))
2028 + /* If we support unaligned word accesses then structs of size 4 and 8
2029 + can have any alignment and still be passed in registers. */
2030 + && !(TARGET_UNALIGNED_WORD
2031 + && (int_size_in_bytes (type) == 4
2032 + || int_size_in_bytes (type) == 8))
2033 + /* Double word structs need only a word alignment. */
2034 + && !(int_size_in_bytes (type) == 8 && TYPE_ALIGN_UNIT (type) >= 4))
2035 + return true;
2036 +
2037 + if (type && AGGREGATE_TYPE_P (type)
2038 + /* Structs of size 3,5,6,7 are always passed in registers. */
2039 + && (int_size_in_bytes (type) == 3
2040 + || int_size_in_bytes (type) == 5
2041 + || int_size_in_bytes (type) == 6 || int_size_in_bytes (type) == 7))
2042 + return true;
2043 +
2044 +
2045 + return (type && TREE_ADDRESSABLE (type));
2046 +}
2047 +
2048 +
2049 +bool
2050 +avr32_strict_argument_naming (CUMULATIVE_ARGS * ca ATTRIBUTE_UNUSED)
2051 +{
2052 + return true;
2053 +}
2054 +
2055 +/*
2056 + This target hook should return true if an argument at the position indicated
2057 + by cum should be passed by reference. This predicate is queried after target
2058 + independent reasons for being passed by reference, such as TREE_ADDRESSABLE (type).
2059 +
2060 + If the hook returns true, a copy of that argument is made in memory and a
2061 + pointer to the argument is passed instead of the argument itself. The pointer
2062 + is passed in whatever way is appropriate for passing a pointer to that type.
2063 +*/
2064 +bool
2065 +avr32_pass_by_reference (CUMULATIVE_ARGS * cum ATTRIBUTE_UNUSED,
2066 + enum machine_mode mode ATTRIBUTE_UNUSED,
2067 + tree type, bool named ATTRIBUTE_UNUSED)
2068 +{
2069 + return (type && (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST));
2070 +}
2071 +
2072 +static int
2073 +avr32_arg_partial_bytes (CUMULATIVE_ARGS * pcum ATTRIBUTE_UNUSED,
2074 + enum machine_mode mode ATTRIBUTE_UNUSED,
2075 + tree type ATTRIBUTE_UNUSED,
2076 + bool named ATTRIBUTE_UNUSED)
2077 +{
2078 + return 0;
2079 +}
2080 +
2081 +
2082 +struct gcc_target targetm = TARGET_INITIALIZER;
2083 +
2084 +/*
2085 + Table used to convert from register number in the assembler instructions and
2086 + the register numbers used in gcc.
2087 +*/
2088 +const int avr32_function_arg_reglist[] = {
2089 + INTERNAL_REGNUM (12),
2090 + INTERNAL_REGNUM (11),
2091 + INTERNAL_REGNUM (10),
2092 + INTERNAL_REGNUM (9),
2093 + INTERNAL_REGNUM (8)
2094 +};
2095 +
2096 +rtx avr32_compare_op0 = NULL_RTX;
2097 +rtx avr32_compare_op1 = NULL_RTX;
2098 +rtx avr32_compare_operator = NULL_RTX;
2099 +rtx avr32_acc_cache = NULL_RTX;
2100 +
2101 +/*
2102 + Returns nonzero if it is allowed to store a value of mode mode in hard
2103 + register number regno.
2104 +*/
2105 +int
2106 +avr32_hard_regno_mode_ok (int regnr, enum machine_mode mode)
2107 +{
2108 + /* We allow only float modes in the fp-registers */
2109 + if (regnr >= FIRST_FP_REGNUM
2110 + && regnr <= LAST_FP_REGNUM && GET_MODE_CLASS (mode) != MODE_FLOAT)
2111 + {
2112 + return 0;
2113 + }
2114 +
2115 + switch (mode)
2116 + {
2117 + case DImode: /* long long */
2118 + case DFmode: /* double */
2119 + case SCmode: /* __complex__ float */
2120 + case CSImode: /* __complex__ int */
2121 + if (regnr < 4)
2122 + { /* long long int not supported in r12, sp, lr
2123 + or pc. */
2124 + return 0;
2125 + }
2126 + else
2127 + {
2128 + if (regnr % 2) /* long long int has to be refered in even
2129 + registers. */
2130 + return 0;
2131 + else
2132 + return 1;
2133 + }
2134 + case CDImode: /* __complex__ long long */
2135 + case DCmode: /* __complex__ double */
2136 + case TImode: /* 16 bytes */
2137 + if (regnr < 7)
2138 + return 0;
2139 + else if (regnr % 2)
2140 + return 0;
2141 + else
2142 + return 1;
2143 + default:
2144 + return 1;
2145 + }
2146 +}
2147 +
2148 +
2149 +int
2150 +avr32_rnd_operands (rtx add, rtx shift)
2151 +{
2152 + if (GET_CODE (shift) == CONST_INT &&
2153 + GET_CODE (add) == CONST_INT && INTVAL (shift) > 0)
2154 + {
2155 + if ((1 << (INTVAL (shift) - 1)) == INTVAL (add))
2156 + return TRUE;
2157 + }
2158 +
2159 + return FALSE;
2160 +}
2161 +
2162 +
2163 +
2164 +int
2165 +avr32_const_ok_for_constraint_p (HOST_WIDE_INT value, char c, const char *str)
2166 +{
2167 + switch (c)
2168 + {
2169 + case 'K':
2170 + case 'I':
2171 + {
2172 + HOST_WIDE_INT min_value = 0, max_value = 0;
2173 + char size_str[3];
2174 + int const_size;
2175 +
2176 + size_str[0] = str[2];
2177 + size_str[1] = str[3];
2178 + size_str[2] = '\0';
2179 + const_size = atoi (size_str);
2180 +
2181 + if (toupper (str[1]) == 'U')
2182 + {
2183 + min_value = 0;
2184 + max_value = (1 << const_size) - 1;
2185 + }
2186 + else if (toupper (str[1]) == 'S')
2187 + {
2188 + min_value = -(1 << (const_size - 1));
2189 + max_value = (1 << (const_size - 1)) - 1;
2190 + }
2191 +
2192 + if (c == 'I')
2193 + {
2194 + value = -value;
2195 + }
2196 +
2197 + if (value >= min_value && value <= max_value)
2198 + {
2199 + return 1;
2200 + }
2201 + break;
2202 + }
2203 + case 'M':
2204 + return avr32_mask_upper_bits_operand (GEN_INT (value), VOIDmode);
2205 + case 'J':
2206 + return avr32_hi16_immediate_operand (GEN_INT (value), VOIDmode);
2207 + }
2208 +
2209 + return 0;
2210 +}
2211 +
2212 +
2213 +/*Compute mask of which floating-point registers needs saving upon
2214 + entry to this function*/
2215 +static unsigned long
2216 +avr32_compute_save_fp_reg_mask (void)
2217 +{
2218 + unsigned long func_type = avr32_current_func_type ();
2219 + unsigned int save_reg_mask = 0;
2220 + unsigned int reg;
2221 + unsigned int max_reg = 7;
2222 + int save_all_call_used_regs = FALSE;
2223 +
2224 + /* This only applies for hardware floating-point implementation. */
2225 + if (!TARGET_HARD_FLOAT)
2226 + return 0;
2227 +
2228 + if (IS_INTERRUPT (func_type))
2229 + {
2230 +
2231 + /* Interrupt functions must not corrupt any registers, even call
2232 + clobbered ones. If this is a leaf function we can just examine the
2233 + registers used by the RTL, but otherwise we have to assume that
2234 + whatever function is called might clobber anything, and so we have
2235 + to save all the call-clobbered registers as well. */
2236 + max_reg = 13;
2237 + save_all_call_used_regs = !current_function_is_leaf;
2238 + }
2239 +
2240 + /* All used registers used must be saved */
2241 + for (reg = 0; reg <= max_reg; reg++)
2242 + if (df_regs_ever_live_p (INTERNAL_FP_REGNUM (reg))
2243 + || (save_all_call_used_regs
2244 + && call_used_regs[INTERNAL_FP_REGNUM (reg)]))
2245 + save_reg_mask |= (1 << reg);
2246 +
2247 + return save_reg_mask;
2248 +}
2249 +
2250 +/*Compute mask of registers which needs saving upon function entry */
2251 +static unsigned long
2252 +avr32_compute_save_reg_mask (int push)
2253 +{
2254 + unsigned long func_type;
2255 + unsigned int save_reg_mask = 0;
2256 + unsigned int reg;
2257 +
2258 + func_type = avr32_current_func_type ();
2259 +
2260 + if (IS_INTERRUPT (func_type))
2261 + {
2262 + unsigned int max_reg = 12;
2263 +
2264 +
2265 + /* Get the banking scheme for the interrupt */
2266 + switch (func_type)
2267 + {
2268 + case AVR32_FT_ISR_FULL:
2269 + max_reg = 0;
2270 + break;
2271 + case AVR32_FT_ISR_HALF:
2272 + max_reg = 7;
2273 + break;
2274 + case AVR32_FT_ISR_NONE:
2275 + max_reg = 12;
2276 + break;
2277 + }
2278 +
2279 + /* Interrupt functions must not corrupt any registers, even call
2280 + clobbered ones. If this is a leaf function we can just examine the
2281 + registers used by the RTL, but otherwise we have to assume that
2282 + whatever function is called might clobber anything, and so we have
2283 + to save all the call-clobbered registers as well. */
2284 +
2285 + /* Need not push the registers r8-r12 for AVR32A architectures, as this
2286 + is automatially done in hardware. We also do not have any shadow
2287 + registers. */
2288 + if (TARGET_UARCH_AVR32A)
2289 + {
2290 + max_reg = 7;
2291 + func_type = AVR32_FT_ISR_NONE;
2292 + }
2293 +
2294 + /* All registers which are used and is not shadowed must be saved */
2295 + for (reg = 0; reg <= max_reg; reg++)
2296 + if (df_regs_ever_live_p (INTERNAL_REGNUM (reg))
2297 + || (!current_function_is_leaf
2298 + && call_used_regs[INTERNAL_REGNUM (reg)]))
2299 + save_reg_mask |= (1 << reg);
2300 +
2301 + /* Check LR */
2302 + if ((df_regs_ever_live_p (LR_REGNUM)
2303 + || !current_function_is_leaf || frame_pointer_needed)
2304 + /* Only non-shadowed register models */
2305 + && (func_type == AVR32_FT_ISR_NONE))
2306 + save_reg_mask |= (1 << ASM_REGNUM (LR_REGNUM));
2307 +
2308 + /* Make sure that the GOT register is pushed. */
2309 + if (max_reg >= ASM_REGNUM (PIC_OFFSET_TABLE_REGNUM)
2310 + && current_function_uses_pic_offset_table)
2311 + save_reg_mask |= (1 << ASM_REGNUM (PIC_OFFSET_TABLE_REGNUM));
2312 +
2313 + }
2314 + else
2315 + {
2316 + int use_pushm = optimize_size;
2317 +
2318 + /* In the normal case we only need to save those registers which are
2319 + call saved and which are used by this function. */
2320 + for (reg = 0; reg <= 7; reg++)
2321 + if (df_regs_ever_live_p (INTERNAL_REGNUM (reg))
2322 + && !call_used_regs[INTERNAL_REGNUM (reg)])
2323 + save_reg_mask |= (1 << reg);
2324 +
2325 + /* Make sure that the GOT register is pushed. */
2326 + if (current_function_uses_pic_offset_table)
2327 + save_reg_mask |= (1 << ASM_REGNUM (PIC_OFFSET_TABLE_REGNUM));
2328 +
2329 +
2330 + /* If we optimize for size and do not have anonymous arguments: use
2331 + popm/pushm always */
2332 + if (use_pushm)
2333 + {
2334 + if ((save_reg_mask & (1 << 0))
2335 + || (save_reg_mask & (1 << 1))
2336 + || (save_reg_mask & (1 << 2)) || (save_reg_mask & (1 << 3)))
2337 + save_reg_mask |= 0xf;
2338 +
2339 + if ((save_reg_mask & (1 << 4))
2340 + || (save_reg_mask & (1 << 5))
2341 + || (save_reg_mask & (1 << 6)) || (save_reg_mask & (1 << 7)))
2342 + save_reg_mask |= 0xf0;
2343 +
2344 + if ((save_reg_mask & (1 << 8)) || (save_reg_mask & (1 << 9)))
2345 + save_reg_mask |= 0x300;
2346 + }
2347 +
2348 +
2349 + /* Check LR */
2350 + if ((df_regs_ever_live_p (LR_REGNUM)
2351 + || !current_function_is_leaf
2352 + || (optimize_size
2353 + && save_reg_mask
2354 + && !current_function_calls_eh_return) || frame_pointer_needed))
2355 + {
2356 + if (push
2357 + /* Never pop LR into PC for functions which
2358 + calls __builtin_eh_return, since we need to
2359 + fix the SP after the restoring of the registers
2360 + and before returning. */
2361 + || current_function_calls_eh_return)
2362 + {
2363 + /* Push/Pop LR */
2364 + save_reg_mask |= (1 << ASM_REGNUM (LR_REGNUM));
2365 + }
2366 + else
2367 + {
2368 + /* Pop PC */
2369 + save_reg_mask |= (1 << ASM_REGNUM (PC_REGNUM));
2370 + }
2371 + }
2372 + }
2373 +
2374 +
2375 + /* Save registers so the exception handler can modify them. */
2376 + if (current_function_calls_eh_return)
2377 + {
2378 + unsigned int i;
2379 +
2380 + for (i = 0;; i++)
2381 + {
2382 + reg = EH_RETURN_DATA_REGNO (i);
2383 + if (reg == INVALID_REGNUM)
2384 + break;
2385 + save_reg_mask |= 1 << ASM_REGNUM (reg);
2386 + }
2387 + }
2388 +
2389 + return save_reg_mask;
2390 +}
2391 +
2392 +/*Compute total size in bytes of all saved registers */
2393 +static int
2394 +avr32_get_reg_mask_size (int reg_mask)
2395 +{
2396 + int reg, size;
2397 + size = 0;
2398 +
2399 + for (reg = 0; reg <= 15; reg++)
2400 + if (reg_mask & (1 << reg))
2401 + size += 4;
2402 +
2403 + return size;
2404 +}
2405 +
2406 +/*Get a register from one of the registers which are saved onto the stack
2407 + upon function entry */
2408 +
2409 +static int
2410 +avr32_get_saved_reg (int save_reg_mask)
2411 +{
2412 + unsigned int reg;
2413 +
2414 + /* Find the first register which is saved in the saved_reg_mask */
2415 + for (reg = 0; reg <= 15; reg++)
2416 + if (save_reg_mask & (1 << reg))
2417 + return reg;
2418 +
2419 + return -1;
2420 +}
2421 +
2422 +/* Return 1 if it is possible to return using a single instruction. */
2423 +int
2424 +avr32_use_return_insn (int iscond)
2425 +{
2426 + unsigned int func_type = avr32_current_func_type ();
2427 + unsigned long saved_int_regs;
2428 + unsigned long saved_fp_regs;
2429 +
2430 + /* Never use a return instruction before reload has run. */
2431 + if (!reload_completed)
2432 + return 0;
2433 +
2434 + /* Must adjust the stack for vararg functions. */
2435 + if (current_function_args_info.uses_anonymous_args)
2436 + return 0;
2437 +
2438 + /* If there a stack adjstment. */
2439 + if (get_frame_size ())
2440 + return 0;
2441 +
2442 + saved_int_regs = avr32_compute_save_reg_mask (TRUE);
2443 + saved_fp_regs = avr32_compute_save_fp_reg_mask ();
2444 +
2445 + /* Functions which have saved fp-regs on the stack can not be performed in
2446 + one instruction */
2447 + if (saved_fp_regs)
2448 + return 0;
2449 +
2450 + /* Conditional returns can not be performed in one instruction if we need
2451 + to restore registers from the stack */
2452 + if (iscond && saved_int_regs)
2453 + return 0;
2454 +
2455 + /* Conditional return can not be used for interrupt handlers. */
2456 + if (iscond && IS_INTERRUPT (func_type))
2457 + return 0;
2458 +
2459 + /* For interrupt handlers which needs to pop registers */
2460 + if (saved_int_regs && IS_INTERRUPT (func_type))
2461 + return 0;
2462 +
2463 +
2464 + /* If there are saved registers but the LR isn't saved, then we need two
2465 + instructions for the return. */
2466 + if (saved_int_regs && !(saved_int_regs & (1 << ASM_REGNUM (LR_REGNUM))))
2467 + return 0;
2468 +
2469 +
2470 + return 1;
2471 +}
2472 +
2473 +
2474 +/*Generate some function prologue info in the assembly file*/
2475 +
2476 +void
2477 +avr32_target_asm_function_prologue (FILE * f, HOST_WIDE_INT frame_size)
2478 +{
2479 + if (IS_NAKED (avr32_current_func_type ()))
2480 + fprintf (f,
2481 + "\t# Function is naked: Prologue and epilogue provided by programmer\n");
2482 +
2483 + if (IS_INTERRUPT (avr32_current_func_type ()))
2484 + {
2485 + switch (avr32_current_func_type ())
2486 + {
2487 + case AVR32_FT_ISR_FULL:
2488 + fprintf (f,
2489 + "\t# Interrupt Function: Fully shadowed register file\n");
2490 + break;
2491 + case AVR32_FT_ISR_HALF:
2492 + fprintf (f,
2493 + "\t# Interrupt Function: Half shadowed register file\n");
2494 + break;
2495 + default:
2496 + case AVR32_FT_ISR_NONE:
2497 + fprintf (f, "\t# Interrupt Function: No shadowed register file\n");
2498 + break;
2499 + }
2500 + }
2501 +
2502 +
2503 + fprintf (f, "\t# args = %i, frame = %li, pretend = %i\n",
2504 + current_function_args_size, frame_size,
2505 + current_function_pretend_args_size);
2506 +
2507 + fprintf (f, "\t# frame_needed = %i, leaf_function = %i\n",
2508 + frame_pointer_needed, current_function_is_leaf);
2509 +
2510 + fprintf (f, "\t# uses_anonymous_args = %i\n",
2511 + current_function_args_info.uses_anonymous_args);
2512 + if (current_function_calls_eh_return)
2513 + fprintf (f, "\t# Calls __builtin_eh_return.\n");
2514 +
2515 +}
2516 +
2517 +
2518 +/* Generate and emit an insn that we will recognize as a pushm or stm.
2519 + Unfortunately, since this insn does not reflect very well the actual
2520 + semantics of the operation, we need to annotate the insn for the benefit
2521 + of DWARF2 frame unwind information. */
2522 +
2523 +int avr32_convert_to_reglist16 (int reglist8_vect);
2524 +
2525 +static rtx
2526 +emit_multi_reg_push (int reglist, int usePUSHM)
2527 +{
2528 + rtx insn;
2529 + rtx dwarf;
2530 + rtx tmp;
2531 + rtx reg;
2532 + int i;
2533 + int nr_regs;
2534 + int index = 0;
2535 +
2536 + if (usePUSHM)
2537 + {
2538 + insn = emit_insn (gen_pushm (gen_rtx_CONST_INT (SImode, reglist)));
2539 + reglist = avr32_convert_to_reglist16 (reglist);
2540 + }
2541 + else
2542 + {
2543 + insn = emit_insn (gen_stm (stack_pointer_rtx,
2544 + gen_rtx_CONST_INT (SImode, reglist),
2545 + gen_rtx_CONST_INT (SImode, 1)));
2546 + }
2547 +
2548 + nr_regs = avr32_get_reg_mask_size (reglist) / 4;
2549 + dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (nr_regs + 1));
2550 +
2551 + for (i = 15; i >= 0; i--)
2552 + {
2553 + if (reglist & (1 << i))
2554 + {
2555 + reg = gen_rtx_REG (SImode, INTERNAL_REGNUM (i));
2556 + tmp = gen_rtx_SET (VOIDmode,
2557 + gen_rtx_MEM (SImode,
2558 + plus_constant (stack_pointer_rtx,
2559 + 4 * index)), reg);
2560 + RTX_FRAME_RELATED_P (tmp) = 1;
2561 + XVECEXP (dwarf, 0, 1 + index++) = tmp;
2562 + }
2563 + }
2564 +
2565 + tmp = gen_rtx_SET (SImode,
2566 + stack_pointer_rtx,
2567 + gen_rtx_PLUS (SImode,
2568 + stack_pointer_rtx,
2569 + GEN_INT (-4 * nr_regs)));
2570 + RTX_FRAME_RELATED_P (tmp) = 1;
2571 + XVECEXP (dwarf, 0, 0) = tmp;
2572 + REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, dwarf,
2573 + REG_NOTES (insn));
2574 + return insn;
2575 +}
2576 +
2577 +
2578 +static rtx
2579 +emit_multi_fp_reg_push (int reglist)
2580 +{
2581 + rtx insn;
2582 + rtx dwarf;
2583 + rtx tmp;
2584 + rtx reg;
2585 + int i;
2586 + int nr_regs;
2587 + int index = 0;
2588 +
2589 + insn = emit_insn (gen_stm_fp (stack_pointer_rtx,
2590 + gen_rtx_CONST_INT (SImode, reglist),
2591 + gen_rtx_CONST_INT (SImode, 1)));
2592 +
2593 + nr_regs = avr32_get_reg_mask_size (reglist) / 4;
2594 + dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (nr_regs + 1));
2595 +
2596 + for (i = 15; i >= 0; i--)
2597 + {
2598 + if (reglist & (1 << i))
2599 + {
2600 + reg = gen_rtx_REG (SImode, INTERNAL_FP_REGNUM (i));
2601 + tmp = gen_rtx_SET (VOIDmode,
2602 + gen_rtx_MEM (SImode,
2603 + plus_constant (stack_pointer_rtx,
2604 + 4 * index)), reg);
2605 + RTX_FRAME_RELATED_P (tmp) = 1;
2606 + XVECEXP (dwarf, 0, 1 + index++) = tmp;
2607 + }
2608 + }
2609 +
2610 + tmp = gen_rtx_SET (SImode,
2611 + stack_pointer_rtx,
2612 + gen_rtx_PLUS (SImode,
2613 + stack_pointer_rtx,
2614 + GEN_INT (-4 * nr_regs)));
2615 + RTX_FRAME_RELATED_P (tmp) = 1;
2616 + XVECEXP (dwarf, 0, 0) = tmp;
2617 + REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, dwarf,
2618 + REG_NOTES (insn));
2619 + return insn;
2620 +}
2621 +
2622 +rtx
2623 +avr32_gen_load_multiple (rtx * regs, int count, rtx from,
2624 + int write_back, int in_struct_p, int scalar_p)
2625 +{
2626 +
2627 + rtx result;
2628 + int i = 0, j;
2629 +
2630 + result =
2631 + gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + (write_back ? 1 : 0)));
2632 +
2633 + if (write_back)
2634 + {
2635 + XVECEXP (result, 0, 0)
2636 + = gen_rtx_SET (GET_MODE (from), from,
2637 + plus_constant (from, count * 4));
2638 + i = 1;
2639 + count++;
2640 + }
2641 +
2642 +
2643 + for (j = 0; i < count; i++, j++)
2644 + {
2645 + rtx unspec;
2646 + rtx mem = gen_rtx_MEM (SImode, plus_constant (from, j * 4));
2647 + MEM_IN_STRUCT_P (mem) = in_struct_p;
2648 + MEM_SCALAR_P (mem) = scalar_p;
2649 + unspec = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, mem), UNSPEC_LDM);
2650 + XVECEXP (result, 0, i) = gen_rtx_SET (VOIDmode, regs[j], unspec);
2651 + }
2652 +
2653 + return result;
2654 +}
2655 +
2656 +
2657 +rtx
2658 +avr32_gen_store_multiple (rtx * regs, int count, rtx to,
2659 + int in_struct_p, int scalar_p)
2660 +{
2661 + rtx result;
2662 + int i = 0, j;
2663 +
2664 + result = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
2665 +
2666 + for (j = 0; i < count; i++, j++)
2667 + {
2668 + rtx mem = gen_rtx_MEM (SImode, plus_constant (to, j * 4));
2669 + MEM_IN_STRUCT_P (mem) = in_struct_p;
2670 + MEM_SCALAR_P (mem) = scalar_p;
2671 + XVECEXP (result, 0, i)
2672 + = gen_rtx_SET (VOIDmode, mem,
2673 + gen_rtx_UNSPEC (VOIDmode,
2674 + gen_rtvec (1, regs[j]),
2675 + UNSPEC_STORE_MULTIPLE));
2676 + }
2677 +
2678 + return result;
2679 +}
2680 +
2681 +
2682 +/* Move a block of memory if it is word aligned or we support unaligned
2683 + word memory accesses. The size must be maximum 64 bytes. */
2684 +
2685 +int
2686 +avr32_gen_movmemsi (rtx * operands)
2687 +{
2688 + HOST_WIDE_INT bytes_to_go;
2689 + rtx src, dst;
2690 + rtx st_src, st_dst;
2691 + int src_offset = 0, dst_offset = 0;
2692 + int block_size;
2693 + int dst_in_struct_p, src_in_struct_p;
2694 + int dst_scalar_p, src_scalar_p;
2695 + int unaligned;
2696 +
2697 + if (GET_CODE (operands[2]) != CONST_INT
2698 + || GET_CODE (operands[3]) != CONST_INT
2699 + || INTVAL (operands[2]) > 64
2700 + || ((INTVAL (operands[3]) & 3) && !TARGET_UNALIGNED_WORD))
2701 + return 0;
2702 +
2703 + unaligned = (INTVAL (operands[3]) & 3) != 0;
2704 +
2705 + block_size = 4;
2706 +
2707 + st_dst = XEXP (operands[0], 0);
2708 + st_src = XEXP (operands[1], 0);
2709 +
2710 + dst_in_struct_p = MEM_IN_STRUCT_P (operands[0]);
2711 + dst_scalar_p = MEM_SCALAR_P (operands[0]);
2712 + src_in_struct_p = MEM_IN_STRUCT_P (operands[1]);
2713 + src_scalar_p = MEM_SCALAR_P (operands[1]);
2714 +
2715 + dst = copy_to_mode_reg (SImode, st_dst);
2716 + src = copy_to_mode_reg (SImode, st_src);
2717 +
2718 + bytes_to_go = INTVAL (operands[2]);
2719 +
2720 + while (bytes_to_go)
2721 + {
2722 + enum machine_mode move_mode;
2723 + /* (Seems to be a problem with reloads for the movti pattern so this is
2724 + disabled until that problem is resolved)
2725 + UPDATE: Problem seems to be solved now.... */
2726 + if (bytes_to_go >= GET_MODE_SIZE (TImode) && !unaligned
2727 + /* Do not emit ldm/stm for UC3 as ld.d/st.d is more optimal. */
2728 + && !TARGET_ARCH_UC)
2729 + move_mode = TImode;
2730 + else if ((bytes_to_go >= GET_MODE_SIZE (DImode)) && !unaligned)
2731 + move_mode = DImode;
2732 + else if (bytes_to_go >= GET_MODE_SIZE (SImode))
2733 + move_mode = SImode;
2734 + else
2735 + move_mode = QImode;
2736 +
2737 + {
2738 + rtx src_mem;
2739 + rtx dst_mem = gen_rtx_MEM (move_mode,
2740 + gen_rtx_PLUS (SImode, dst,
2741 + GEN_INT (dst_offset)));
2742 + dst_offset += GET_MODE_SIZE (move_mode);
2743 + if ( 0 /* This causes an error in GCC. Think there is
2744 + something wrong in the gcse pass which causes REQ_EQUIV notes
2745 + to be wrong so disabling it for now. */
2746 + && move_mode == TImode
2747 + && INTVAL (operands[2]) > GET_MODE_SIZE (TImode) )
2748 + {
2749 + src_mem = gen_rtx_MEM (move_mode,
2750 + gen_rtx_POST_INC (SImode, src));
2751 + }
2752 + else
2753 + {
2754 + src_mem = gen_rtx_MEM (move_mode,
2755 + gen_rtx_PLUS (SImode, src,
2756 + GEN_INT (src_offset)));
2757 + src_offset += GET_MODE_SIZE (move_mode);
2758 + }
2759 +
2760 + bytes_to_go -= GET_MODE_SIZE (move_mode);
2761 +
2762 + MEM_IN_STRUCT_P (dst_mem) = dst_in_struct_p;
2763 + MEM_SCALAR_P (dst_mem) = dst_scalar_p;
2764 +
2765 + MEM_IN_STRUCT_P (src_mem) = src_in_struct_p;
2766 + MEM_SCALAR_P (src_mem) = src_scalar_p;
2767 + emit_move_insn (dst_mem, src_mem);
2768 +
2769 + }
2770 + }
2771 +
2772 + return 1;
2773 +}
2774 +
2775 +
2776 +
2777 +/*Expand the prologue instruction*/
2778 +void
2779 +avr32_expand_prologue (void)
2780 +{
2781 + rtx insn, dwarf;
2782 + unsigned long saved_reg_mask, saved_fp_reg_mask;
2783 + int reglist8 = 0;
2784 +
2785 + /* Naked functions does not have a prologue */
2786 + if (IS_NAKED (avr32_current_func_type ()))
2787 + return;
2788 +
2789 + saved_reg_mask = avr32_compute_save_reg_mask (TRUE);
2790 +
2791 + if (saved_reg_mask)
2792 + {
2793 + /* Must push used registers */
2794 +
2795 + /* Should we use POPM or LDM? */
2796 + int usePUSHM = TRUE;
2797 + reglist8 = 0;
2798 + if (((saved_reg_mask & (1 << 0)) ||
2799 + (saved_reg_mask & (1 << 1)) ||
2800 + (saved_reg_mask & (1 << 2)) || (saved_reg_mask & (1 << 3))))
2801 + {
2802 + /* One of R0-R3 should at least be pushed */
2803 + if (((saved_reg_mask & (1 << 0)) &&
2804 + (saved_reg_mask & (1 << 1)) &&
2805 + (saved_reg_mask & (1 << 2)) && (saved_reg_mask & (1 << 3))))
2806 + {
2807 + /* All should be pushed */
2808 + reglist8 |= 0x01;
2809 + }
2810 + else
2811 + {
2812 + usePUSHM = FALSE;
2813 + }
2814 + }
2815 +
2816 + if (((saved_reg_mask & (1 << 4)) ||
2817 + (saved_reg_mask & (1 << 5)) ||
2818 + (saved_reg_mask & (1 << 6)) || (saved_reg_mask & (1 << 7))))
2819 + {
2820 + /* One of R4-R7 should at least be pushed */
2821 + if (((saved_reg_mask & (1 << 4)) &&
2822 + (saved_reg_mask & (1 << 5)) &&
2823 + (saved_reg_mask & (1 << 6)) && (saved_reg_mask & (1 << 7))))
2824 + {
2825 + if (usePUSHM)
2826 + /* All should be pushed */
2827 + reglist8 |= 0x02;
2828 + }
2829 + else
2830 + {
2831 + usePUSHM = FALSE;
2832 + }
2833 + }
2834 +
2835 + if (((saved_reg_mask & (1 << 8)) || (saved_reg_mask & (1 << 9))))
2836 + {
2837 + /* One of R8-R9 should at least be pushed */
2838 + if (((saved_reg_mask & (1 << 8)) && (saved_reg_mask & (1 << 9))))
2839 + {
2840 + if (usePUSHM)
2841 + /* All should be pushed */
2842 + reglist8 |= 0x04;
2843 + }
2844 + else
2845 + {
2846 + usePUSHM = FALSE;
2847 + }
2848 + }
2849 +
2850 + if (saved_reg_mask & (1 << 10))
2851 + reglist8 |= 0x08;
2852 +
2853 + if (saved_reg_mask & (1 << 11))
2854 + reglist8 |= 0x10;
2855 +
2856 + if (saved_reg_mask & (1 << 12))
2857 + reglist8 |= 0x20;
2858 +
2859 + if (saved_reg_mask & (1 << ASM_REGNUM (LR_REGNUM)))
2860 + {
2861 + /* Push LR */
2862 + reglist8 |= 0x40;
2863 + }
2864 +
2865 + if (usePUSHM)
2866 + {
2867 + insn = emit_multi_reg_push (reglist8, TRUE);
2868 + }
2869 + else
2870 + {
2871 + insn = emit_multi_reg_push (saved_reg_mask, FALSE);
2872 + }
2873 + RTX_FRAME_RELATED_P (insn) = 1;
2874 +
2875 + /* Prevent this instruction from being scheduled after any other
2876 + instructions. */
2877 + emit_insn (gen_blockage ());
2878 + }
2879 +
2880 + saved_fp_reg_mask = avr32_compute_save_fp_reg_mask ();
2881 + if (saved_fp_reg_mask)
2882 + {
2883 + insn = emit_multi_fp_reg_push (saved_fp_reg_mask);
2884 + RTX_FRAME_RELATED_P (insn) = 1;
2885 +
2886 + /* Prevent this instruction from being scheduled after any other
2887 + instructions. */
2888 + emit_insn (gen_blockage ());
2889 + }
2890 +
2891 + /* Set frame pointer */
2892 + if (frame_pointer_needed)
2893 + {
2894 + insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
2895 + RTX_FRAME_RELATED_P (insn) = 1;
2896 + }
2897 +
2898 + if (get_frame_size () > 0)
2899 + {
2900 + if (avr32_const_ok_for_constraint_p (get_frame_size (), 'K', "Ks21"))
2901 + {
2902 + insn = emit_insn (gen_rtx_SET (SImode,
2903 + stack_pointer_rtx,
2904 + gen_rtx_PLUS (SImode,
2905 + stack_pointer_rtx,
2906 + gen_rtx_CONST_INT
2907 + (SImode,
2908 + -get_frame_size
2909 + ()))));
2910 + RTX_FRAME_RELATED_P (insn) = 1;
2911 + }
2912 + else
2913 + {
2914 + /* Immediate is larger than k21 We must either check if we can use
2915 + one of the pushed reegisters as temporary storage or we must
2916 + make us a temp register by pushing a register to the stack. */
2917 + rtx temp_reg, const_pool_entry, insn;
2918 + if (saved_reg_mask)
2919 + {
2920 + temp_reg =
2921 + gen_rtx_REG (SImode,
2922 + INTERNAL_REGNUM (avr32_get_saved_reg
2923 + (saved_reg_mask)));
2924 + }
2925 + else
2926 + {
2927 + temp_reg = gen_rtx_REG (SImode, INTERNAL_REGNUM (7));
2928 + emit_move_insn (gen_rtx_MEM
2929 + (SImode,
2930 + gen_rtx_PRE_DEC (SImode, stack_pointer_rtx)),
2931 + temp_reg);
2932 + }
2933 +
2934 + const_pool_entry =
2935 + force_const_mem (SImode,
2936 + gen_rtx_CONST_INT (SImode, get_frame_size ()));
2937 + emit_move_insn (temp_reg, const_pool_entry);
2938 +
2939 + insn = emit_insn (gen_rtx_SET (SImode,
2940 + stack_pointer_rtx,
2941 + gen_rtx_MINUS (SImode,
2942 + stack_pointer_rtx,
2943 + temp_reg)));
2944 +
2945 + dwarf = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
2946 + gen_rtx_PLUS (SImode, stack_pointer_rtx,
2947 + GEN_INT (-get_frame_size ())));
2948 + REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
2949 + dwarf, REG_NOTES (insn));
2950 + RTX_FRAME_RELATED_P (insn) = 1;
2951 +
2952 + if (!saved_reg_mask)
2953 + {
2954 + insn =
2955 + emit_move_insn (temp_reg,
2956 + gen_rtx_MEM (SImode,
2957 + gen_rtx_POST_INC (SImode,
2958 + gen_rtx_REG
2959 + (SImode,
2960 + 13))));
2961 + }
2962 +
2963 + /* Mark the temp register as dead */
2964 + REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_DEAD, temp_reg,
2965 + REG_NOTES (insn));
2966 +
2967 +
2968 + }
2969 +
2970 + /* Prevent the the stack adjustment to be scheduled after any
2971 + instructions using the frame pointer. */
2972 + emit_insn (gen_blockage ());
2973 + }
2974 +
2975 + /* Load GOT */
2976 + if (flag_pic)
2977 + {
2978 + avr32_load_pic_register ();
2979 +
2980 + /* gcc does not know that load or call instructions might use the pic
2981 + register so it might schedule these instructions before the loading
2982 + of the pic register. To avoid this emit a barrier for now. TODO!
2983 + Find out a better way to let gcc know which instructions might use
2984 + the pic register. */
2985 + emit_insn (gen_blockage ());
2986 + }
2987 + return;
2988 +}
2989 +
2990 +void
2991 +avr32_set_return_address (rtx source, rtx scratch)
2992 +{
2993 + rtx addr;
2994 + unsigned long saved_regs;
2995 +
2996 + saved_regs = avr32_compute_save_reg_mask (TRUE);
2997 +
2998 + if (!(saved_regs & (1 << ASM_REGNUM (LR_REGNUM))))
2999 + emit_move_insn (gen_rtx_REG (Pmode, LR_REGNUM), source);
3000 + else
3001 + {
3002 + if (frame_pointer_needed)
3003 + addr = gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM);
3004 + else
3005 + if (avr32_const_ok_for_constraint_p (get_frame_size (), 'K', "Ks16"))
3006 + {
3007 + addr = plus_constant (stack_pointer_rtx, get_frame_size ());
3008 + }
3009 + else
3010 + {
3011 + emit_insn (gen_movsi (scratch, GEN_INT (get_frame_size ())));
3012 + addr = scratch;
3013 + }
3014 + emit_move_insn (gen_rtx_MEM (Pmode, addr), source);
3015 + }
3016 +}
3017 +
3018 +
3019 +
3020 +/* Return the length of INSN. LENGTH is the initial length computed by
3021 + attributes in the machine-description file. */
3022 +
3023 +int
3024 +avr32_adjust_insn_length (rtx insn ATTRIBUTE_UNUSED,
3025 + int length ATTRIBUTE_UNUSED)
3026 +{
3027 + return length;
3028 +}
3029 +
3030 +void
3031 +avr32_output_return_instruction (int single_ret_inst ATTRIBUTE_UNUSED,
3032 + int iscond ATTRIBUTE_UNUSED,
3033 + rtx cond ATTRIBUTE_UNUSED, rtx r12_imm)
3034 +{
3035 +
3036 + unsigned long saved_reg_mask, saved_fp_reg_mask;
3037 + int insert_ret = TRUE;
3038 + int reglist8 = 0;
3039 + int stack_adjustment = get_frame_size ();
3040 + unsigned int func_type = avr32_current_func_type ();
3041 + FILE *f = asm_out_file;
3042 +
3043 + /* Naked functions does not have an epilogue */
3044 + if (IS_NAKED (func_type))
3045 + return;
3046 +
3047 + saved_fp_reg_mask = avr32_compute_save_fp_reg_mask ();
3048 +
3049 + saved_reg_mask = avr32_compute_save_reg_mask (FALSE);
3050 +
3051 + /* Reset frame pointer */
3052 + if (stack_adjustment > 0)
3053 + {
3054 + if (avr32_const_ok_for_constraint_p (stack_adjustment, 'I', "Is21"))
3055 + {
3056 + fprintf (f, "\tsub\tsp, %i # Reset Frame Pointer\n",
3057 + -stack_adjustment);
3058 + }
3059 + else
3060 + {
3061 + /* TODO! Is it safe to use r8 as scratch?? */
3062 + fprintf (f, "\tmov\tr8, lo(%i) # Reset Frame Pointer\n",
3063 + -stack_adjustment);
3064 + fprintf (f, "\torh\tr8, hi(%i) # Reset Frame Pointer\n",
3065 + -stack_adjustment);
3066 + fprintf (f, "\tadd\tsp, r8 # Reset Frame Pointer\n");
3067 + }
3068 + }
3069 +
3070 + if (saved_fp_reg_mask)
3071 + {
3072 + char reglist[64]; /* 64 bytes should be enough... */
3073 + avr32_make_fp_reglist_w (saved_fp_reg_mask, (char *) reglist);
3074 + fprintf (f, "\tldcm.w\tcp0, sp++, %s\n", reglist);
3075 + if (saved_fp_reg_mask & ~0xff)
3076 + {
3077 + saved_fp_reg_mask &= ~0xff;
3078 + avr32_make_fp_reglist_d (saved_fp_reg_mask, (char *) reglist);
3079 + fprintf (f, "\tldcm.d\tcp0, sp++, %s\n", reglist);
3080 + }
3081 + }
3082 +
3083 + if (saved_reg_mask)
3084 + {
3085 + /* Must pop used registers */
3086 +
3087 + /* Should we use POPM or LDM? */
3088 + int usePOPM = TRUE;
3089 + if (((saved_reg_mask & (1 << 0)) ||
3090 + (saved_reg_mask & (1 << 1)) ||
3091 + (saved_reg_mask & (1 << 2)) || (saved_reg_mask & (1 << 3))))
3092 + {
3093 + /* One of R0-R3 should at least be popped */
3094 + if (((saved_reg_mask & (1 << 0)) &&
3095 + (saved_reg_mask & (1 << 1)) &&
3096 + (saved_reg_mask & (1 << 2)) && (saved_reg_mask & (1 << 3))))
3097 + {
3098 + /* All should be popped */
3099 + reglist8 |= 0x01;
3100 + }
3101 + else
3102 + {
3103 + usePOPM = FALSE;
3104 + }
3105 + }
3106 +
3107 + if (((saved_reg_mask & (1 << 4)) ||
3108 + (saved_reg_mask & (1 << 5)) ||
3109 + (saved_reg_mask & (1 << 6)) || (saved_reg_mask & (1 << 7))))
3110 + {
3111 + /* One of R0-R3 should at least be popped */
3112 + if (((saved_reg_mask & (1 << 4)) &&
3113 + (saved_reg_mask & (1 << 5)) &&
3114 + (saved_reg_mask & (1 << 6)) && (saved_reg_mask & (1 << 7))))
3115 + {
3116 + if (usePOPM)
3117 + /* All should be popped */
3118 + reglist8 |= 0x02;
3119 + }
3120 + else
3121 + {
3122 + usePOPM = FALSE;
3123 + }
3124 + }
3125 +
3126 + if (((saved_reg_mask & (1 << 8)) || (saved_reg_mask & (1 << 9))))
3127 + {
3128 + /* One of R8-R9 should at least be pushed */
3129 + if (((saved_reg_mask & (1 << 8)) && (saved_reg_mask & (1 << 9))))
3130 + {
3131 + if (usePOPM)
3132 + /* All should be pushed */
3133 + reglist8 |= 0x04;
3134 + }
3135 + else
3136 + {
3137 + usePOPM = FALSE;
3138 + }
3139 + }
3140 +
3141 + if (saved_reg_mask & (1 << 10))
3142 + reglist8 |= 0x08;
3143 +
3144 + if (saved_reg_mask & (1 << 11))
3145 + reglist8 |= 0x10;
3146 +
3147 + if (saved_reg_mask & (1 << 12))
3148 + reglist8 |= 0x20;
3149 +
3150 + if (saved_reg_mask & (1 << ASM_REGNUM (LR_REGNUM)))
3151 + /* Pop LR */
3152 + reglist8 |= 0x40;
3153 +
3154 + if (saved_reg_mask & (1 << ASM_REGNUM (PC_REGNUM)))
3155 + /* Pop LR into PC. */
3156 + reglist8 |= 0x80;
3157 +
3158 + if (usePOPM)
3159 + {
3160 + char reglist[64]; /* 64 bytes should be enough... */
3161 + avr32_make_reglist8 (reglist8, (char *) reglist);
3162 +
3163 + if (reglist8 & 0x80)
3164 + /* This instruction is also a return */
3165 + insert_ret = FALSE;
3166 +
3167 + if (r12_imm && !insert_ret)
3168 + fprintf (f, "\tpopm\t%s, r12=%li\n", reglist, INTVAL (r12_imm));
3169 + else
3170 + fprintf (f, "\tpopm\t%s\n", reglist);
3171 +
3172 + }
3173 + else
3174 + {
3175 + char reglist[64]; /* 64 bytes should be enough... */
3176 + avr32_make_reglist16 (saved_reg_mask, (char *) reglist);
3177 + if (saved_reg_mask & (1 << ASM_REGNUM (PC_REGNUM)))
3178 + /* This instruction is also a return */
3179 + insert_ret = FALSE;
3180 +
3181 + if (r12_imm && !insert_ret)
3182 + fprintf (f, "\tldm\tsp++, %s, r12=%li\n", reglist,
3183 + INTVAL (r12_imm));
3184 + else
3185 + fprintf (f, "\tldm\tsp++, %s\n", reglist);
3186 +
3187 + }
3188 +
3189 + }
3190 +
3191 + /* Stack adjustment for exception handler. */
3192 + if (current_function_calls_eh_return)
3193 + fprintf (f, "\tadd\tsp, r%d\n", ASM_REGNUM (EH_RETURN_STACKADJ_REGNO));
3194 +
3195 +
3196 + if (IS_INTERRUPT (func_type))
3197 + {
3198 + fprintf (f, "\trete\n");
3199 + }
3200 + else if (insert_ret)
3201 + {
3202 + if (r12_imm)
3203 + fprintf (f, "\tretal\t%li\n", INTVAL (r12_imm));
3204 + else
3205 + fprintf (f, "\tretal\tr12\n");
3206 + }
3207 +}
3208 +
3209 +/* Function for converting a fp-register mask to a
3210 + reglistCPD8 register list string. */
3211 +void
3212 +avr32_make_fp_reglist_d (int reglist_mask, char *reglist_string)
3213 +{
3214 + int i;
3215 +
3216 + /* Make sure reglist_string is empty */
3217 + reglist_string[0] = '\0';
3218 +
3219 + for (i = 0; i < NUM_FP_REGS; i += 2)
3220 + {
3221 + if (reglist_mask & (1 << i))
3222 + {
3223 + strlen (reglist_string) ?
3224 + sprintf (reglist_string, "%s, %s-%s", reglist_string,
3225 + reg_names[INTERNAL_FP_REGNUM (i)],
3226 + reg_names[INTERNAL_FP_REGNUM (i + 1)]) :
3227 + sprintf (reglist_string, "%s-%s",
3228 + reg_names[INTERNAL_FP_REGNUM (i)],
3229 + reg_names[INTERNAL_FP_REGNUM (i + 1)]);
3230 + }
3231 + }
3232 +}
3233 +
3234 +/* Function for converting a fp-register mask to a
3235 + reglistCP8 register list string. */
3236 +void
3237 +avr32_make_fp_reglist_w (int reglist_mask, char *reglist_string)
3238 +{
3239 + int i;
3240 +
3241 + /* Make sure reglist_string is empty */
3242 + reglist_string[0] = '\0';
3243 +
3244 + for (i = 0; i < NUM_FP_REGS; ++i)
3245 + {
3246 + if (reglist_mask & (1 << i))
3247 + {
3248 + strlen (reglist_string) ?
3249 + sprintf (reglist_string, "%s, %s", reglist_string,
3250 + reg_names[INTERNAL_FP_REGNUM (i)]) :
3251 + sprintf (reglist_string, "%s", reg_names[INTERNAL_FP_REGNUM (i)]);
3252 + }
3253 + }
3254 +}
3255 +
3256 +void
3257 +avr32_make_reglist16 (int reglist16_vect, char *reglist16_string)
3258 +{
3259 + int i;
3260 +
3261 + /* Make sure reglist16_string is empty */
3262 + reglist16_string[0] = '\0';
3263 +
3264 + for (i = 0; i < 16; ++i)
3265 + {
3266 + if (reglist16_vect & (1 << i))
3267 + {
3268 + strlen (reglist16_string) ?
3269 + sprintf (reglist16_string, "%s, %s", reglist16_string,
3270 + reg_names[INTERNAL_REGNUM (i)]) :
3271 + sprintf (reglist16_string, "%s", reg_names[INTERNAL_REGNUM (i)]);
3272 + }
3273 + }
3274 +}
3275 +
3276 +int
3277 +avr32_convert_to_reglist16 (int reglist8_vect)
3278 +{
3279 + int reglist16_vect = 0;
3280 + if (reglist8_vect & 0x1)
3281 + reglist16_vect |= 0xF;
3282 + if (reglist8_vect & 0x2)
3283 + reglist16_vect |= 0xF0;
3284 + if (reglist8_vect & 0x4)
3285 + reglist16_vect |= 0x300;
3286 + if (reglist8_vect & 0x8)
3287 + reglist16_vect |= 0x400;
3288 + if (reglist8_vect & 0x10)
3289 + reglist16_vect |= 0x800;
3290 + if (reglist8_vect & 0x20)
3291 + reglist16_vect |= 0x1000;
3292 + if (reglist8_vect & 0x40)
3293 + reglist16_vect |= 0x4000;
3294 + if (reglist8_vect & 0x80)
3295 + reglist16_vect |= 0x8000;
3296 +
3297 + return reglist16_vect;
3298 +}
3299 +
3300 +void
3301 +avr32_make_reglist8 (int reglist8_vect, char *reglist8_string)
3302 +{
3303 + /* Make sure reglist8_string is empty */
3304 + reglist8_string[0] = '\0';
3305 +
3306 + if (reglist8_vect & 0x1)
3307 + sprintf (reglist8_string, "r0-r3");
3308 + if (reglist8_vect & 0x2)
3309 + strlen (reglist8_string) ? sprintf (reglist8_string, "%s, r4-r7",
3310 + reglist8_string) :
3311 + sprintf (reglist8_string, "r4-r7");
3312 + if (reglist8_vect & 0x4)
3313 + strlen (reglist8_string) ? sprintf (reglist8_string, "%s, r8-r9",
3314 + reglist8_string) :
3315 + sprintf (reglist8_string, "r8-r9");
3316 + if (reglist8_vect & 0x8)
3317 + strlen (reglist8_string) ? sprintf (reglist8_string, "%s, r10",
3318 + reglist8_string) :
3319 + sprintf (reglist8_string, "r10");
3320 + if (reglist8_vect & 0x10)
3321 + strlen (reglist8_string) ? sprintf (reglist8_string, "%s, r11",
3322 + reglist8_string) :
3323 + sprintf (reglist8_string, "r11");
3324 + if (reglist8_vect & 0x20)
3325 + strlen (reglist8_string) ? sprintf (reglist8_string, "%s, r12",
3326 + reglist8_string) :
3327 + sprintf (reglist8_string, "r12");
3328 + if (reglist8_vect & 0x40)
3329 + strlen (reglist8_string) ? sprintf (reglist8_string, "%s, lr",
3330 + reglist8_string) :
3331 + sprintf (reglist8_string, "lr");
3332 + if (reglist8_vect & 0x80)
3333 + strlen (reglist8_string) ? sprintf (reglist8_string, "%s, pc",
3334 + reglist8_string) :
3335 + sprintf (reglist8_string, "pc");
3336 +}
3337 +
3338 +int
3339 +avr32_eh_return_data_regno (int n)
3340 +{
3341 + if (n >= 0 && n <= 3)
3342 + return 8 + n;
3343 + else
3344 + return INVALID_REGNUM;
3345 +}
3346 +
3347 +/* Compute the distance from register FROM to register TO.
3348 + These can be the arg pointer, the frame pointer or
3349 + the stack pointer.
3350 + Typical stack layout looks like this:
3351 +
3352 + old stack pointer -> | |
3353 + ----
3354 + | | \
3355 + | | saved arguments for
3356 + | | vararg functions
3357 + arg_pointer -> | | /
3358 + --
3359 + | | \
3360 + | | call saved
3361 + | | registers
3362 + | | /
3363 + frame ptr -> --
3364 + | | \
3365 + | | local
3366 + | | variables
3367 + stack ptr --> | | /
3368 + --
3369 + | | \
3370 + | | outgoing
3371 + | | arguments
3372 + | | /
3373 + --
3374 +
3375 + For a given funciton some or all of these stack compomnents
3376 + may not be needed, giving rise to the possibility of
3377 + eliminating some of the registers.
3378 +
3379 + The values returned by this function must reflect the behaviour
3380 + of avr32_expand_prologue() and avr32_compute_save_reg_mask().
3381 +
3382 + The sign of the number returned reflects the direction of stack
3383 + growth, so the values are positive for all eliminations except
3384 + from the soft frame pointer to the hard frame pointer. */
3385 +
3386 +
3387 +int
3388 +avr32_initial_elimination_offset (int from, int to)
3389 +{
3390 + int i;
3391 + int call_saved_regs = 0;
3392 + unsigned long saved_reg_mask, saved_fp_reg_mask;
3393 + unsigned int local_vars = get_frame_size ();
3394 +
3395 + saved_reg_mask = avr32_compute_save_reg_mask (TRUE);
3396 + saved_fp_reg_mask = avr32_compute_save_fp_reg_mask ();
3397 +
3398 + for (i = 0; i < 16; ++i)
3399 + {
3400 + if (saved_reg_mask & (1 << i))
3401 + call_saved_regs += 4;
3402 + }
3403 +
3404 + for (i = 0; i < NUM_FP_REGS; ++i)
3405 + {
3406 + if (saved_fp_reg_mask & (1 << i))
3407 + call_saved_regs += 4;
3408 + }
3409 +
3410 + switch (from)
3411 + {
3412 + case ARG_POINTER_REGNUM:
3413 + switch (to)
3414 + {
3415 + case STACK_POINTER_REGNUM:
3416 + return call_saved_regs + local_vars;
3417 + case FRAME_POINTER_REGNUM:
3418 + return call_saved_regs;
3419 + default:
3420 + abort ();
3421 + }
3422 + case FRAME_POINTER_REGNUM:
3423 + switch (to)
3424 + {
3425 + case STACK_POINTER_REGNUM:
3426 + return local_vars;
3427 + default:
3428 + abort ();
3429 + }
3430 + default:
3431 + abort ();
3432 + }
3433 +}
3434 +
3435 +
3436 +/*
3437 + Returns a rtx used when passing the next argument to a function.
3438 + avr32_init_cumulative_args() and avr32_function_arg_advance() sets witch
3439 + register to use.
3440 +*/
3441 +rtx
3442 +avr32_function_arg (CUMULATIVE_ARGS * cum, enum machine_mode mode,
3443 + tree type, int named)
3444 +{
3445 + int index = -1;
3446 +
3447 + HOST_WIDE_INT arg_size, arg_rsize;
3448 + if (type)
3449 + {
3450 + arg_size = int_size_in_bytes (type);
3451 + }
3452 + else
3453 + {
3454 + arg_size = GET_MODE_SIZE (mode);
3455 + }
3456 + arg_rsize = PUSH_ROUNDING (arg_size);
3457 +
3458 + /*
3459 + The last time this macro is called, it is called with mode == VOIDmode,
3460 + and its result is passed to the call or call_value pattern as operands 2
3461 + and 3 respectively. */
3462 + if (mode == VOIDmode)
3463 + {
3464 + return gen_rtx_CONST_INT (SImode, 22); /* ToDo: fixme. */
3465 + }
3466 +
3467 + if ((*targetm.calls.must_pass_in_stack) (mode, type) || !named)
3468 + {
3469 + return NULL_RTX;
3470 + }
3471 +
3472 + if (arg_rsize == 8)
3473 + {
3474 + /* use r11:r10 or r9:r8. */
3475 + if (!(GET_USED_INDEX (cum, 1) || GET_USED_INDEX (cum, 2)))
3476 + index = 1;
3477 + else if (!(GET_USED_INDEX (cum, 3) || GET_USED_INDEX (cum, 4)))
3478 + index = 3;
3479 + else
3480 + index = -1;
3481 + }
3482 + else if (arg_rsize == 4)
3483 + { /* Use first available register */
3484 + index = 0;
3485 + while (index <= LAST_CUM_REG_INDEX && GET_USED_INDEX (cum, index))
3486 + index++;
3487 + if (index > LAST_CUM_REG_INDEX)
3488 + index = -1;
3489 + }
3490 +
3491 + SET_REG_INDEX (cum, index);
3492 +
3493 + if (GET_REG_INDEX (cum) >= 0)
3494 + return gen_rtx_REG (mode,
3495 + avr32_function_arg_reglist[GET_REG_INDEX (cum)]);
3496 +
3497 + return NULL_RTX;
3498 +}
3499 +
3500 +/*
3501 + Set the register used for passing the first argument to a function.
3502 +*/
3503 +void
3504 +avr32_init_cumulative_args (CUMULATIVE_ARGS * cum,
3505 + tree fntype ATTRIBUTE_UNUSED,
3506 + rtx libname ATTRIBUTE_UNUSED,
3507 + tree fndecl ATTRIBUTE_UNUSED)
3508 + {
3509 + /* Set all registers as unused. */
3510 + SET_INDEXES_UNUSED (cum);
3511 +
3512 + /* Reset uses_anonymous_args */
3513 + cum->uses_anonymous_args = 0;
3514 +
3515 + /* Reset size of stack pushed arguments */
3516 + cum->stack_pushed_args_size = 0;
3517 + }
3518 +
3519 +/*
3520 + Set register used for passing the next argument to a function. Only the
3521 + Scratch Registers are used.
3522 +
3523 + number name
3524 + 15 r15 PC
3525 + 14 r14 LR
3526 + 13 r13 _SP_________
3527 + FIRST_CUM_REG 12 r12 _||_
3528 + 10 r11 ||
3529 + 11 r10 _||_ Scratch Registers
3530 + 8 r9 ||
3531 + LAST_SCRATCH_REG 9 r8 _\/_________
3532 + 6 r7 /\
3533 + 7 r6 ||
3534 + 4 r5 ||
3535 + 5 r4 ||
3536 + 2 r3 ||
3537 + 3 r2 ||
3538 + 0 r1 ||
3539 + 1 r0 _||_________
3540 +
3541 +*/
3542 +void
3543 +avr32_function_arg_advance (CUMULATIVE_ARGS * cum, enum machine_mode mode,
3544 + tree type, int named ATTRIBUTE_UNUSED)
3545 +{
3546 + HOST_WIDE_INT arg_size, arg_rsize;
3547 +
3548 + if (type)
3549 + {
3550 + arg_size = int_size_in_bytes (type);
3551 + }
3552 + else
3553 + {
3554 + arg_size = GET_MODE_SIZE (mode);
3555 + }
3556 + arg_rsize = PUSH_ROUNDING (arg_size);
3557 +
3558 + /* It the argument had to be passed in stack, no register is used. */
3559 + if ((*targetm.calls.must_pass_in_stack) (mode, type))
3560 + {
3561 + cum->stack_pushed_args_size += PUSH_ROUNDING (int_size_in_bytes (type));
3562 + return;
3563 + }
3564 +
3565 + /* Mark the used registers as "used". */
3566 + if (GET_REG_INDEX (cum) >= 0)
3567 + {
3568 + SET_USED_INDEX (cum, GET_REG_INDEX (cum));
3569 + if (arg_rsize == 8)
3570 + {
3571 + SET_USED_INDEX (cum, (GET_REG_INDEX (cum) + 1));
3572 + }
3573 + }
3574 + else
3575 + {
3576 + /* Had to use stack */
3577 + cum->stack_pushed_args_size += arg_rsize;
3578 + }
3579 +}
3580 +
3581 +/*
3582 + Defines witch direction to go to find the next register to use if the
3583 + argument is larger then one register or for arguments shorter than an
3584 + int which is not promoted, such as the last part of structures with
3585 + size not a multiple of 4. */
3586 +enum direction
3587 +avr32_function_arg_padding (enum machine_mode mode ATTRIBUTE_UNUSED,
3588 + tree type)
3589 +{
3590 + /* Pad upward for all aggregates except byte and halfword sized aggregates
3591 + which can be passed in registers. */
3592 + if (type
3593 + && AGGREGATE_TYPE_P (type)
3594 + && (int_size_in_bytes (type) != 1)
3595 + && !((int_size_in_bytes (type) == 2)
3596 + && TYPE_ALIGN_UNIT (type) >= 2)
3597 + && (int_size_in_bytes (type) & 0x3))
3598 + {
3599 + return upward;
3600 + }
3601 +
3602 + return downward;
3603 +}
3604 +
3605 +/*
3606 + Return a rtx used for the return value from a function call.
3607 +*/
3608 +rtx
3609 +avr32_function_value (tree type, tree func, bool outgoing ATTRIBUTE_UNUSED)
3610 +{
3611 + if (avr32_return_in_memory (type, func))
3612 + return NULL_RTX;
3613 +
3614 + if (int_size_in_bytes (type) <= 4)
3615 + {
3616 + enum machine_mode mode = TYPE_MODE (type);
3617 + int unsignedp = 0;
3618 + PROMOTE_FUNCTION_MODE (mode, unsignedp, type);
3619 + return gen_rtx_REG (mode, RET_REGISTER);
3620 + }
3621 + else if (int_size_in_bytes (type) <= 8)
3622 + return gen_rtx_REG (TYPE_MODE (type), INTERNAL_REGNUM (11));
3623 +
3624 + return NULL_RTX;
3625 +}
3626 +
3627 +/*
3628 + Return a rtx used for the return value from a library function call.
3629 +*/
3630 +rtx
3631 +avr32_libcall_value (enum machine_mode mode)
3632 +{
3633 +
3634 + if (GET_MODE_SIZE (mode) <= 4)
3635 + return gen_rtx_REG (mode, RET_REGISTER);
3636 + else if (GET_MODE_SIZE (mode) <= 8)
3637 + return gen_rtx_REG (mode, INTERNAL_REGNUM (11));
3638 + else
3639 + return NULL_RTX;
3640 +}
3641 +
3642 +/* Return TRUE if X references a SYMBOL_REF. */
3643 +int
3644 +symbol_mentioned_p (rtx x)
3645 +{
3646 + const char *fmt;
3647 + int i;
3648 +
3649 + if (GET_CODE (x) == SYMBOL_REF)
3650 + return 1;
3651 +
3652 + fmt = GET_RTX_FORMAT (GET_CODE (x));
3653 +
3654 + for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
3655 + {
3656 + if (fmt[i] == 'E')
3657 + {
3658 + int j;
3659 +
3660 + for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3661 + if (symbol_mentioned_p (XVECEXP (x, i, j)))
3662 + return 1;
3663 + }
3664 + else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i)))
3665 + return 1;
3666 + }
3667 +
3668 + return 0;
3669 +}
3670 +
3671 +/* Return TRUE if X references a LABEL_REF. */
3672 +int
3673 +label_mentioned_p (rtx x)
3674 +{
3675 + const char *fmt;
3676 + int i;
3677 +
3678 + if (GET_CODE (x) == LABEL_REF)
3679 + return 1;
3680 +
3681 + fmt = GET_RTX_FORMAT (GET_CODE (x));
3682 + for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
3683 + {
3684 + if (fmt[i] == 'E')
3685 + {
3686 + int j;
3687 +
3688 + for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3689 + if (label_mentioned_p (XVECEXP (x, i, j)))
3690 + return 1;
3691 + }
3692 + else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i)))
3693 + return 1;
3694 + }
3695 +
3696 + return 0;
3697 +}
3698 +
3699 +/* Return TRUE if X contains a MEM expression. */
3700 +int
3701 +mem_mentioned_p (rtx x)
3702 +{
3703 + const char *fmt;
3704 + int i;
3705 +
3706 + if (MEM_P (x))
3707 + return 1;
3708 +
3709 + fmt = GET_RTX_FORMAT (GET_CODE (x));
3710 + for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
3711 + {
3712 + if (fmt[i] == 'E')
3713 + {
3714 + int j;
3715 +
3716 + for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3717 + if (mem_mentioned_p (XVECEXP (x, i, j)))
3718 + return 1;
3719 + }
3720 + else if (fmt[i] == 'e' && mem_mentioned_p (XEXP (x, i)))
3721 + return 1;
3722 + }
3723 +
3724 + return 0;
3725 +}
3726 +
3727 +int
3728 +avr32_legitimate_pic_operand_p (rtx x)
3729 +{
3730 +
3731 + /* We can't have const, this must be broken down to a symbol. */
3732 + if (GET_CODE (x) == CONST)
3733 + return FALSE;
3734 +
3735 + /* Can't access symbols or labels via the constant pool either */
3736 + if ((GET_CODE (x) == SYMBOL_REF
3737 + && CONSTANT_POOL_ADDRESS_P (x)
3738 + && (symbol_mentioned_p (get_pool_constant (x))
3739 + || label_mentioned_p (get_pool_constant (x)))))
3740 + return FALSE;
3741 +
3742 + return TRUE;
3743 +}
3744 +
3745 +
3746 +rtx
3747 +legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED,
3748 + rtx reg)
3749 +{
3750 +
3751 + if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
3752 + {
3753 + int subregs = 0;
3754 +
3755 + if (reg == 0)
3756 + {
3757 + if (!can_create_pseudo_p ())
3758 + abort ();
3759 + else
3760 + reg = gen_reg_rtx (Pmode);
3761 +
3762 + subregs = 1;
3763 + }
3764 +
3765 + emit_move_insn (reg, orig);
3766 +
3767 + /* Only set current function as using pic offset table if flag_pic is
3768 + set. This is because this function is also used if
3769 + TARGET_HAS_ASM_ADDR_PSEUDOS is set. */
3770 + if (flag_pic)
3771 + current_function_uses_pic_offset_table = 1;
3772 +
3773 + /* Put a REG_EQUAL note on this insn, so that it can be optimized by
3774 + loop. */
3775 + return reg;
3776 + }
3777 + else if (GET_CODE (orig) == CONST)
3778 + {
3779 + rtx base, offset;
3780 +
3781 + if (flag_pic
3782 + && GET_CODE (XEXP (orig, 0)) == PLUS
3783 + && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3784 + return orig;
3785 +
3786 + if (reg == 0)
3787 + {
3788 + if (!can_create_pseudo_p ())
3789 + abort ();
3790 + else
3791 + reg = gen_reg_rtx (Pmode);
3792 + }
3793 +
3794 + if (GET_CODE (XEXP (orig, 0)) == PLUS)
3795 + {
3796 + base =
3797 + legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
3798 + offset =
3799 + legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
3800 + base == reg ? 0 : reg);
3801 + }
3802 + else
3803 + abort ();
3804 +
3805 + if (GET_CODE (offset) == CONST_INT)
3806 + {
3807 + /* The base register doesn't really matter, we only want to test
3808 + the index for the appropriate mode. */
3809 + if (!avr32_const_ok_for_constraint_p (INTVAL (offset), 'I', "Is21"))
3810 + {
3811 + if (can_create_pseudo_p ())
3812 + offset = force_reg (Pmode, offset);
3813 + else
3814 + abort ();
3815 + }
3816 +
3817 + if (GET_CODE (offset) == CONST_INT)
3818 + return plus_constant (base, INTVAL (offset));
3819 + }
3820 +
3821 + return gen_rtx_PLUS (Pmode, base, offset);
3822 + }
3823 +
3824 + return orig;
3825 +}
3826 +
3827 +/* Generate code to load the PIC register. */
3828 +void
3829 +avr32_load_pic_register (void)
3830 +{
3831 + rtx l1, pic_tmp;
3832 + rtx global_offset_table;
3833 +
3834 + if ((current_function_uses_pic_offset_table == 0) || TARGET_NO_INIT_GOT)
3835 + return;
3836 +
3837 + if (!flag_pic)
3838 + abort ();
3839 +
3840 + l1 = gen_label_rtx ();
3841 +
3842 + global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3843 + pic_tmp =
3844 + gen_rtx_CONST (Pmode,
3845 + gen_rtx_MINUS (SImode, gen_rtx_LABEL_REF (Pmode, l1),
3846 + global_offset_table));
3847 + emit_insn (gen_pic_load_addr
3848 + (pic_offset_table_rtx, force_const_mem (SImode, pic_tmp)));
3849 + emit_insn (gen_pic_compute_got_from_pc (pic_offset_table_rtx, l1));
3850 +
3851 + /* Need to emit this whether or not we obey regdecls, since setjmp/longjmp
3852 + can cause life info to screw up. */
3853 + emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3854 +}
3855 +
3856 +
3857 +
3858 +/* This hook should return true if values of type type are returned at the most
3859 + significant end of a register (in other words, if they are padded at the
3860 + least significant end). You can assume that type is returned in a register;
3861 + the caller is required to check this. Note that the register provided by
3862 + FUNCTION_VALUE must be able to hold the complete return value. For example,
3863 + if a 1-, 2- or 3-byte structure is returned at the most significant end of a
3864 + 4-byte register, FUNCTION_VALUE should provide an SImode rtx. */
3865 +bool
3866 +avr32_return_in_msb (tree type ATTRIBUTE_UNUSED)
3867 +{
3868 + /* if ( AGGREGATE_TYPE_P (type) ) if ((int_size_in_bytes(type) == 1) ||
3869 + ((int_size_in_bytes(type) == 2) && TYPE_ALIGN_UNIT(type) >= 2)) return
3870 + false; else return true; */
3871 +
3872 + return false;
3873 +}
3874 +
3875 +
3876 +/*
3877 + Returns one if a certain function value is going to be returned in memory
3878 + and zero if it is going to be returned in a register.
3879 +
3880 + BLKmode and all other modes that is larger than 64 bits are returned in
3881 + memory.
3882 +*/
3883 +bool
3884 +avr32_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
3885 +{
3886 + if (TYPE_MODE (type) == VOIDmode)
3887 + return false;
3888 +
3889 + if (int_size_in_bytes (type) > (2 * UNITS_PER_WORD)
3890 + || int_size_in_bytes (type) == -1)
3891 + {
3892 + return true;
3893 + }
3894 +
3895 + /* If we have an aggregate then use the same mechanism as when checking if
3896 + it should be passed on the stack. */
3897 + if (type
3898 + && AGGREGATE_TYPE_P (type)
3899 + && (*targetm.calls.must_pass_in_stack) (TYPE_MODE (type), type))
3900 + return true;
3901 +
3902 + return false;
3903 +}
3904 +
3905 +
3906 +/* Output the constant part of the trampoline.
3907 + lddpc r0, pc[0x8:e] ; load static chain register
3908 + lddpc pc, pc[0x8:e] ; jump to subrutine
3909 + .long 0 ; Address to static chain,
3910 + ; filled in by avr32_initialize_trampoline()
3911 + .long 0 ; Address to subrutine,
3912 + ; filled in by avr32_initialize_trampoline()
3913 +*/
3914 +void
3915 +avr32_trampoline_template (FILE * file)
3916 +{
3917 + fprintf (file, "\tlddpc r0, pc[8]\n");
3918 + fprintf (file, "\tlddpc pc, pc[8]\n");
3919 + /* make room for the address of the static chain. */
3920 + fprintf (file, "\t.long\t0\n");
3921 + /* make room for the address to the subrutine. */
3922 + fprintf (file, "\t.long\t0\n");
3923 +}
3924 +
3925 +
3926 +/*
3927 + Initialize the variable parts of a trampoline.
3928 +*/
3929 +void
3930 +avr32_initialize_trampoline (rtx addr, rtx fnaddr, rtx static_chain)
3931 +{
3932 + /* Store the address to the static chain. */
3933 + emit_move_insn (gen_rtx_MEM
3934 + (SImode, plus_constant (addr, TRAMPOLINE_SIZE - 4)),
3935 + static_chain);
3936 +
3937 + /* Store the address to the function. */
3938 + emit_move_insn (gen_rtx_MEM (SImode, plus_constant (addr, TRAMPOLINE_SIZE)),
3939 + fnaddr);
3940 +
3941 + emit_insn (gen_cache (gen_rtx_REG (SImode, 13),
3942 + gen_rtx_CONST_INT (SImode,
3943 + AVR32_CACHE_INVALIDATE_ICACHE)));
3944 +}
3945 +
3946 +/* Return nonzero if X is valid as an addressing register. */
3947 +int
3948 +avr32_address_register_rtx_p (rtx x, int strict_p)
3949 +{
3950 + int regno;
3951 +
3952 + if (!register_operand(x, GET_MODE(x)))
3953 + return 0;
3954 +
3955 + /* If strict we require the register to be a hard register. */
3956 + if (strict_p
3957 + && !REG_P(x))
3958 + return 0;
3959 +
3960 + regno = REGNO (x);
3961 +
3962 + if (strict_p)
3963 + return REGNO_OK_FOR_BASE_P (regno);
3964 +
3965 + return (regno <= LAST_REGNUM || regno >= FIRST_PSEUDO_REGISTER);
3966 +}
3967 +
3968 +/* Return nonzero if INDEX is valid for an address index operand. */
3969 +int
3970 +avr32_legitimate_index_p (enum machine_mode mode, rtx index, int strict_p)
3971 +{
3972 + enum rtx_code code = GET_CODE (index);
3973 +
3974 + if (GET_MODE_SIZE (mode) > 8)
3975 + return 0;
3976 +
3977 + /* Standard coprocessor addressing modes. */
3978 + if (code == CONST_INT)
3979 + {
3980 + if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT)
3981 + /* Coprocessor mem insns has a smaller reach than ordinary mem insns */
3982 + return CONST_OK_FOR_CONSTRAINT_P (INTVAL (index), 'K', "Ku14");
3983 + else
3984 + return CONST_OK_FOR_CONSTRAINT_P (INTVAL (index), 'K', "Ks16");
3985 + }
3986 +
3987 + if (avr32_address_register_rtx_p (index, strict_p))
3988 + return 1;
3989 +
3990 + if (code == MULT)
3991 + {
3992 + rtx xiop0 = XEXP (index, 0);
3993 + rtx xiop1 = XEXP (index, 1);
3994 + return ((avr32_address_register_rtx_p (xiop0, strict_p)
3995 + && power_of_two_operand (xiop1, SImode)
3996 + && (INTVAL (xiop1) <= 8))
3997 + || (avr32_address_register_rtx_p (xiop1, strict_p)
3998 + && power_of_two_operand (xiop0, SImode)
3999 + && (INTVAL (xiop0) <= 8)));
4000 + }
4001 + else if (code == ASHIFT)
4002 + {
4003 + rtx op = XEXP (index, 1);
4004 +
4005 + return (avr32_address_register_rtx_p (XEXP (index, 0), strict_p)
4006 + && GET_CODE (op) == CONST_INT
4007 + && INTVAL (op) > 0 && INTVAL (op) <= 3);
4008 + }
4009 +
4010 + return 0;
4011 +}
4012 +
4013 +/*
4014 + Used in the GO_IF_LEGITIMATE_ADDRESS macro. Returns a nonzero value if
4015 + the RTX x is a legitimate memory address.
4016 +
4017 + Returns NO_REGS if the address is not legatime, GENERAL_REGS or ALL_REGS
4018 + if it is.
4019 +*/
4020 +
4021 +/* Forward declaration*/
4022 +int is_minipool_label (rtx label);
4023 +
4024 +int
4025 +avr32_legitimate_address (enum machine_mode mode, rtx x, int strict)
4026 +{
4027 +
4028 + switch (GET_CODE (x))
4029 + {
4030 + case REG:
4031 + return avr32_address_register_rtx_p (x, strict);
4032 + case CONST:
4033 + {
4034 + rtx label = avr32_find_symbol (x);
4035 + if (label
4036 + &&
4037 + (/*
4038 + If we enable (const (plus (symbol_ref ...))) type constant
4039 + pool entries we must add support for it in the predicates and
4040 + in the minipool generation in avr32_reorg().
4041 + (CONSTANT_POOL_ADDRESS_P (label)
4042 + && !(flag_pic
4043 + && (symbol_mentioned_p (get_pool_constant (label))
4044 + || label_mentioned_p (get_pool_constant (label)))))
4045 + ||*/
4046 + ((GET_CODE (label) == LABEL_REF)
4047 + && GET_CODE (XEXP (label, 0)) == CODE_LABEL
4048 + && is_minipool_label (XEXP (label, 0)))))
4049 + {
4050 + return TRUE;
4051 + }
4052 + }
4053 + break;
4054 + case LABEL_REF:
4055 + if (GET_CODE (XEXP (x, 0)) == CODE_LABEL
4056 + && is_minipool_label (XEXP (x, 0)))
4057 + {
4058 + return TRUE;
4059 + }
4060 + break;
4061 + case SYMBOL_REF:
4062 + {
4063 + if (CONSTANT_POOL_ADDRESS_P (x)
4064 + && !(flag_pic
4065 + && (symbol_mentioned_p (get_pool_constant (x))
4066 + || label_mentioned_p (get_pool_constant (x)))))
4067 + return TRUE;
4068 + /*
4069 + A symbol_ref is only legal if it is a function. If all of them are
4070 + legal, a pseudo reg that is a constant will be replaced by a
4071 + symbol_ref and make illegale code. SYMBOL_REF_FLAG is set by
4072 + ENCODE_SECTION_INFO. */
4073 + else if (SYMBOL_REF_RCALL_FUNCTION_P (x))
4074 + return TRUE;
4075 + break;
4076 + }
4077 + case PRE_DEC: /* (pre_dec (...)) */
4078 + case POST_INC: /* (post_inc (...)) */
4079 + return avr32_address_register_rtx_p (XEXP (x, 0), strict);
4080 + case PLUS: /* (plus (...) (...)) */
4081 + {
4082 + rtx xop0 = XEXP (x, 0);
4083 + rtx xop1 = XEXP (x, 1);
4084 +
4085 + return ((avr32_address_register_rtx_p (xop0, strict)
4086 + && avr32_legitimate_index_p (mode, xop1, strict))
4087 + || (avr32_address_register_rtx_p (xop1, strict)
4088 + && avr32_legitimate_index_p (mode, xop0, strict)));
4089 + }
4090 + default:
4091 + break;
4092 + }
4093 +
4094 + return FALSE;
4095 +}
4096 +
4097 +
4098 +int
4099 +avr32_const_ok_for_move (HOST_WIDE_INT c)
4100 +{
4101 + if ( TARGET_V2_INSNS )
4102 + return ( avr32_const_ok_for_constraint_p (c, 'K', "Ks21")
4103 + /* movh instruction */
4104 + || avr32_hi16_immediate_operand (GEN_INT(c), VOIDmode) );
4105 + else
4106 + return avr32_const_ok_for_constraint_p (c, 'K', "Ks21");
4107 +}
4108 +
4109 +int
4110 +avr32_const_double_immediate (rtx value)
4111 +{
4112 + HOST_WIDE_INT hi, lo;
4113 +
4114 + if (GET_CODE (value) != CONST_DOUBLE)
4115 + return FALSE;
4116 +
4117 + if (SCALAR_FLOAT_MODE_P (GET_MODE (value)))
4118 + {
4119 + HOST_WIDE_INT target_float[2];
4120 + hi = lo = 0;
4121 + real_to_target (target_float, CONST_DOUBLE_REAL_VALUE (value),
4122 + GET_MODE (value));
4123 + lo = target_float[0];
4124 + hi = target_float[1];
4125 + }
4126 + else
4127 + {
4128 + hi = CONST_DOUBLE_HIGH (value);
4129 + lo = CONST_DOUBLE_LOW (value);
4130 + }
4131 +
4132 + if (avr32_const_ok_for_constraint_p (lo, 'K', "Ks21")
4133 + && (GET_MODE (value) == SFmode
4134 + || avr32_const_ok_for_constraint_p (hi, 'K', "Ks21")))
4135 + {
4136 + return TRUE;
4137 + }
4138 +
4139 + return FALSE;
4140 +}
4141 +
4142 +
4143 +int
4144 +avr32_legitimate_constant_p (rtx x)
4145 +{
4146 + switch (GET_CODE (x))
4147 + {
4148 + case CONST_INT:
4149 + /* Check if we should put large immediate into constant pool
4150 + or load them directly with mov/orh.*/
4151 + if (!avr32_imm_in_const_pool)
4152 + return 1;
4153 +
4154 + return avr32_const_ok_for_move (INTVAL (x));
4155 + case CONST_DOUBLE:
4156 + /* Check if we should put large immediate into constant pool
4157 + or load them directly with mov/orh.*/
4158 + if (!avr32_imm_in_const_pool)
4159 + return 1;
4160 +
4161 + if (GET_MODE (x) == SFmode
4162 + || GET_MODE (x) == DFmode || GET_MODE (x) == DImode)
4163 + return avr32_const_double_immediate (x);
4164 + else
4165 + return 0;
4166 + case LABEL_REF:
4167 + return flag_pic || TARGET_HAS_ASM_ADDR_PSEUDOS;
4168 + case SYMBOL_REF:
4169 + return flag_pic || TARGET_HAS_ASM_ADDR_PSEUDOS;
4170 + case CONST:
4171 + case HIGH:
4172 + case CONST_VECTOR:
4173 + return 0;
4174 + default:
4175 + printf ("%s():\n", __FUNCTION__);
4176 + debug_rtx (x);
4177 + return 1;
4178 + }
4179 +}
4180 +
4181 +
4182 +/* Strip any special encoding from labels */
4183 +const char *
4184 +avr32_strip_name_encoding (const char *name)
4185 +{
4186 + const char *stripped = name;
4187 +
4188 + while (1)
4189 + {
4190 + switch (stripped[0])
4191 + {
4192 + case '#':
4193 + stripped = strchr (name + 1, '#') + 1;
4194 + break;
4195 + case '*':
4196 + stripped = &stripped[1];
4197 + break;
4198 + default:
4199 + return stripped;
4200 + }
4201 + }
4202 +}
4203 +
4204 +
4205 +
4206 +/* Do anything needed before RTL is emitted for each function. */
4207 +static struct machine_function *
4208 +avr32_init_machine_status (void)
4209 +{
4210 + struct machine_function *machine;
4211 + machine =
4212 + (machine_function *) ggc_alloc_cleared (sizeof (machine_function));
4213 +
4214 +#if AVR32_FT_UNKNOWN != 0
4215 + machine->func_type = AVR32_FT_UNKNOWN;
4216 +#endif
4217 +
4218 + machine->minipool_label_head = 0;
4219 + machine->minipool_label_tail = 0;
4220 + machine->ifcvt_after_reload = 0;
4221 + return machine;
4222 +}
4223 +
4224 +void
4225 +avr32_init_expanders (void)
4226 +{
4227 + /* Arrange to initialize and mark the machine per-function status. */
4228 + init_machine_status = avr32_init_machine_status;
4229 +}
4230 +
4231 +
4232 +/* Return an RTX indicating where the return address to the
4233 + calling function can be found. */
4234 +
4235 +rtx
4236 +avr32_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
4237 +{
4238 + if (count != 0)
4239 + return NULL_RTX;
4240 +
4241 + return get_hard_reg_initial_val (Pmode, LR_REGNUM);
4242 +}
4243 +
4244 +
4245 +void
4246 +avr32_encode_section_info (tree decl, rtx rtl, int first)
4247 +{
4248 +
4249 + if (first && DECL_P (decl))
4250 + {
4251 + /* Set SYMBOL_REG_FLAG for local functions */
4252 + if (!TREE_PUBLIC (decl) && TREE_CODE (decl) == FUNCTION_DECL)
4253 + {
4254 + if ((*targetm.binds_local_p) (decl))
4255 + {
4256 + SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
4257 + }
4258 + }
4259 + }
4260 +}
4261 +
4262 +void
4263 +avr32_asm_output_label (FILE * stream, const char *name)
4264 +{
4265 + name = avr32_strip_name_encoding (name);
4266 +
4267 + /* Print the label. */
4268 + assemble_name (stream, name);
4269 + fprintf (stream, ":\n");
4270 +}
4271 +
4272 +
4273 +
4274 +void
4275 +avr32_asm_weaken_label (FILE * stream, const char *name)
4276 +{
4277 + fprintf (stream, "\t.weak ");
4278 + assemble_name (stream, name);
4279 + fprintf (stream, "\n");
4280 +}
4281 +
4282 +/*
4283 + Checks if a labelref is equal to a reserved word in the assembler. If it is,
4284 + insert a '_' before the label name.
4285 +*/
4286 +void
4287 +avr32_asm_output_labelref (FILE * stream, const char *name)
4288 +{
4289 + int verbatim = FALSE;
4290 + const char *stripped = name;
4291 + int strip_finished = FALSE;
4292 +
4293 + while (!strip_finished)
4294 + {
4295 + switch (stripped[0])
4296 + {
4297 + case '#':
4298 + stripped = strchr (name + 1, '#') + 1;
4299 + break;
4300 + case '*':
4301 + stripped = &stripped[1];
4302 + verbatim = TRUE;
4303 + break;
4304 + default:
4305 + strip_finished = TRUE;
4306 + break;
4307 + }
4308 + }
4309 +
4310 + if (verbatim)
4311 + fputs (stripped, stream);
4312 + else
4313 + asm_fprintf (stream, "%U%s", stripped);
4314 +}
4315 +
4316 +
4317 +
4318 +/*
4319 + Check if the comparison in compare_exp is redundant
4320 + for the condition given in next_cond given that the
4321 + needed flags are already set by an earlier instruction.
4322 + Uses cc_prev_status to check this.
4323 +
4324 + Returns NULL_RTX if the compare is not redundant
4325 + or the new condition to use in the conditional
4326 + instruction if the compare is redundant.
4327 +*/
4328 +static rtx
4329 +is_compare_redundant (rtx compare_exp, rtx next_cond)
4330 +{
4331 + int z_flag_valid = FALSE;
4332 + int n_flag_valid = FALSE;
4333 + rtx new_cond;
4334 +
4335 + if (GET_CODE (compare_exp) != COMPARE
4336 + && GET_CODE (compare_exp) != AND)
4337 + return NULL_RTX;
4338 +
4339 +
4340 + if (rtx_equal_p (cc_prev_status.mdep.value, compare_exp))
4341 + {
4342 + /* cc0 already contains the correct comparison -> delete cmp insn */
4343 + return next_cond;
4344 + }
4345 +
4346 + if (GET_MODE (compare_exp) != SImode)
4347 + return NULL_RTX;
4348 +
4349 + switch (cc_prev_status.mdep.flags)
4350 + {
4351 + case CC_SET_VNCZ:
4352 + case CC_SET_NCZ:
4353 + n_flag_valid = TRUE;
4354 + case CC_SET_CZ:
4355 + case CC_SET_Z:
4356 + z_flag_valid = TRUE;
4357 + }
4358 +
4359 + if (cc_prev_status.mdep.value
4360 + && GET_CODE (compare_exp) == COMPARE
4361 + && REG_P (XEXP (compare_exp, 0))
4362 + && REGNO (XEXP (compare_exp, 0)) == REGNO (cc_prev_status.mdep.value)
4363 + && GET_CODE (XEXP (compare_exp, 1)) == CONST_INT
4364 + && next_cond != NULL_RTX)
4365 + {
4366 + if (INTVAL (XEXP (compare_exp, 1)) == 0
4367 + && z_flag_valid
4368 + && (GET_CODE (next_cond) == EQ || GET_CODE (next_cond) == NE))
4369 + /* We can skip comparison Z flag is already reflecting ops[0] */
4370 + return next_cond;
4371 + else if (n_flag_valid
4372 + && ((INTVAL (XEXP (compare_exp, 1)) == 0
4373 + && (GET_CODE (next_cond) == GE
4374 + || GET_CODE (next_cond) == LT))
4375 + || (INTVAL (XEXP (compare_exp, 1)) == -1
4376 + && (GET_CODE (next_cond) == GT
4377 + || GET_CODE (next_cond) == LE))))
4378 + {
4379 + /* We can skip comparison N flag is already reflecting ops[0],
4380 + which means that we can use the mi/pl conditions to check if
4381 + ops[0] is GE or LT 0. */
4382 + if ((GET_CODE (next_cond) == GE) || (GET_CODE (next_cond) == GT))
4383 + new_cond =
4384 + gen_rtx_UNSPEC (GET_MODE (next_cond), gen_rtvec (2, cc0_rtx, const0_rtx),
4385 + UNSPEC_COND_PL);
4386 + else
4387 + new_cond =
4388 + gen_rtx_UNSPEC (GET_MODE (next_cond), gen_rtvec (2, cc0_rtx, const0_rtx),
4389 + UNSPEC_COND_MI);
4390 + return new_cond;
4391 + }
4392 + }
4393 + return NULL_RTX;
4394 +}
4395 +
4396 +/* Updates cc_status. */
4397 +void
4398 +avr32_notice_update_cc (rtx exp, rtx insn)
4399 +{
4400 + enum attr_cc attr_cc = get_attr_cc (insn);
4401 +
4402 + if ( attr_cc == CC_SET_Z_IF_NOT_V2 )
4403 + {
4404 + if (TARGET_V2_INSNS)
4405 + attr_cc = CC_NONE;
4406 + else
4407 + attr_cc = CC_SET_Z;
4408 + }
4409 +
4410 + switch (attr_cc)
4411 + {
4412 + case CC_CALL_SET:
4413 + CC_STATUS_INIT;
4414 + FPCC_STATUS_INIT;
4415 + /* Check if the function call returns a value in r12 */
4416 + if (REG_P (recog_data.operand[0])
4417 + && REGNO (recog_data.operand[0]) == RETVAL_REGNUM)
4418 + {
4419 + cc_status.flags = 0;
4420 + cc_status.mdep.value =
4421 + gen_rtx_COMPARE (SImode, recog_data.operand[0], const0_rtx);
4422 + cc_status.mdep.flags = CC_SET_VNCZ;
4423 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4424 +
4425 + }
4426 + break;
4427 + case CC_COMPARE:
4428 + {
4429 + /* Check that compare will not be optimized away if so nothing should
4430 + be done */
4431 + rtx compare_exp = SET_SRC (exp);
4432 + /* Check if we have a tst expression. If so convert it to a
4433 + compare with 0. */
4434 + if ( REG_P (SET_SRC (exp)) )
4435 + compare_exp = gen_rtx_COMPARE (GET_MODE (SET_SRC (exp)),
4436 + SET_SRC (exp),
4437 + const0_rtx);
4438 +
4439 + if (!next_insn_emits_cmp (insn)
4440 + && (is_compare_redundant (compare_exp, get_next_insn_cond (insn)) == NULL_RTX))
4441 + {
4442 +
4443 + /* Reset the nonstandard flag */
4444 + CC_STATUS_INIT;
4445 + cc_status.flags = 0;
4446 + cc_status.mdep.value = compare_exp;
4447 + cc_status.mdep.flags = CC_SET_VNCZ;
4448 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4449 + }
4450 + }
4451 + break;
4452 + case CC_CMP_COND_INSN:
4453 + {
4454 + /* Conditional insn that emit the compare itself. */
4455 + rtx cmp;
4456 + rtx cmp_op0, cmp_op1;
4457 + rtx cond;
4458 + rtx dest;
4459 + rtx next_insn = next_nonnote_insn (insn);
4460 +
4461 + if ( GET_CODE (exp) == COND_EXEC )
4462 + {
4463 + cmp_op0 = XEXP (COND_EXEC_TEST (exp), 0);
4464 + cmp_op1 = XEXP (COND_EXEC_TEST (exp), 1);
4465 + cond = COND_EXEC_TEST (exp);
4466 + dest = SET_DEST (COND_EXEC_CODE (exp));
4467 + }
4468 + else
4469 + {
4470 + /* If then else conditional. compare operands are in operands
4471 + 4 and 5. */
4472 + cmp_op0 = recog_data.operand[4];
4473 + cmp_op1 = recog_data.operand[5];
4474 + cond = recog_data.operand[1];
4475 + dest = SET_DEST (exp);
4476 + }
4477 +
4478 + if ( GET_CODE (cmp_op0) == AND )
4479 + cmp = cmp_op0;
4480 + else
4481 + cmp = gen_rtx_COMPARE (GET_MODE (cmp_op0),
4482 + cmp_op0,
4483 + cmp_op1);
4484 +
4485 + /* Check if the conditional insns updates a register present
4486 + in the comparison, if so then we must reset the cc_status. */
4487 + if (REG_P (dest)
4488 + && (reg_mentioned_p (dest, cmp_op0)
4489 + || reg_mentioned_p (dest, cmp_op1))
4490 + && GET_CODE (exp) != COND_EXEC )
4491 + {
4492 + CC_STATUS_INIT;
4493 + }
4494 + else if (is_compare_redundant (cmp, cond) == NULL_RTX)
4495 + {
4496 + /* Reset the nonstandard flag */
4497 + CC_STATUS_INIT;
4498 + if ( GET_CODE (cmp_op0) == AND )
4499 + {
4500 + cc_status.flags = CC_INVERTED;
4501 + cc_status.mdep.flags = CC_SET_Z;
4502 + }
4503 + else
4504 + {
4505 + cc_status.flags = 0;
4506 + cc_status.mdep.flags = CC_SET_VNCZ;
4507 + }
4508 + cc_status.mdep.value = cmp;
4509 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4510 + }
4511 +
4512 +
4513 + /* Check if we have a COND_EXEC insn which updates one
4514 + of the registers in the compare status. */
4515 + if (REG_P (dest)
4516 + && (reg_mentioned_p (dest, cmp_op0)
4517 + || reg_mentioned_p (dest, cmp_op1))
4518 + && GET_CODE (exp) == COND_EXEC )
4519 + cc_status.mdep.cond_exec_cmp_clobbered = 1;
4520 +
4521 + if ( cc_status.mdep.cond_exec_cmp_clobbered
4522 + && GET_CODE (exp) == COND_EXEC
4523 + && next_insn != NULL
4524 + && INSN_P (next_insn)
4525 + && !(GET_CODE (PATTERN (next_insn)) == COND_EXEC
4526 + && rtx_equal_p (XEXP (COND_EXEC_TEST (PATTERN (next_insn)), 0), cmp_op0)
4527 + && rtx_equal_p (XEXP (COND_EXEC_TEST (PATTERN (next_insn)), 1), cmp_op1)
4528 + && (GET_CODE (COND_EXEC_TEST (PATTERN (next_insn))) == GET_CODE (cond)
4529 + || GET_CODE (COND_EXEC_TEST (PATTERN (next_insn))) == reverse_condition (GET_CODE (cond)))) )
4530 + {
4531 + /* We have a sequence of conditional insns where the compare status has been clobbered
4532 + since the compare no longer reflects the content of the values to compare. */
4533 + CC_STATUS_INIT;
4534 + cc_status.mdep.cond_exec_cmp_clobbered = 1;
4535 + }
4536 +
4537 + }
4538 + break;
4539 + case CC_FPCOMPARE:
4540 + /* Check that floating-point compare will not be optimized away if so
4541 + nothing should be done */
4542 + if (!rtx_equal_p (cc_prev_status.mdep.fpvalue, SET_SRC (exp)))
4543 + {
4544 + /* cc0 already contains the correct comparison -> delete cmp insn */
4545 + /* Reset the nonstandard flag */
4546 + cc_status.mdep.fpvalue = SET_SRC (exp);
4547 + cc_status.mdep.fpflags = CC_SET_CZ;
4548 + }
4549 + break;
4550 + case CC_FROM_FPCC:
4551 + /* Flags are updated with flags from Floating-point coprocessor, set
4552 + CC_NOT_SIGNED flag since the flags are set so that unsigned
4553 + condidion codes can be used directly. */
4554 + CC_STATUS_INIT;
4555 + cc_status.flags = CC_NOT_SIGNED;
4556 + cc_status.mdep.value = cc_status.mdep.fpvalue;
4557 + cc_status.mdep.flags = cc_status.mdep.fpflags;
4558 + break;
4559 + case CC_BLD:
4560 + /* Bit load is kind of like an inverted testsi, because the Z flag is
4561 + inverted */
4562 + CC_STATUS_INIT;
4563 + cc_status.flags = CC_INVERTED;
4564 + cc_status.mdep.value = SET_SRC (exp);
4565 + cc_status.mdep.flags = CC_SET_Z;
4566 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4567 + break;
4568 + case CC_NONE:
4569 + /* Insn does not affect CC at all. Check if the instruction updates
4570 + some of the register currently reflected in cc0 */
4571 +
4572 + if ((GET_CODE (exp) == SET)
4573 + && (cc_status.value1 || cc_status.value2 || cc_status.mdep.value)
4574 + && (reg_mentioned_p (SET_DEST (exp), cc_status.value1)
4575 + || reg_mentioned_p (SET_DEST (exp), cc_status.value2)
4576 + || reg_mentioned_p (SET_DEST (exp), cc_status.mdep.value)))
4577 + {
4578 + CC_STATUS_INIT;
4579 + }
4580 +
4581 + /* If this is a parallel we must step through each of the parallel
4582 + expressions */
4583 + if (GET_CODE (exp) == PARALLEL)
4584 + {
4585 + int i;
4586 + for (i = 0; i < XVECLEN (exp, 0); ++i)
4587 + {
4588 + rtx vec_exp = XVECEXP (exp, 0, i);
4589 + if ((GET_CODE (vec_exp) == SET)
4590 + && (cc_status.value1 || cc_status.value2
4591 + || cc_status.mdep.value)
4592 + && (reg_mentioned_p (SET_DEST (vec_exp), cc_status.value1)
4593 + || reg_mentioned_p (SET_DEST (vec_exp),
4594 + cc_status.value2)
4595 + || reg_mentioned_p (SET_DEST (vec_exp),
4596 + cc_status.mdep.value)))
4597 + {
4598 + CC_STATUS_INIT;
4599 + }
4600 + }
4601 + }
4602 +
4603 + /* Check if we have memory opartions with post_inc or pre_dec on the
4604 + register currently reflected in cc0 */
4605 + if (GET_CODE (exp) == SET
4606 + && GET_CODE (SET_SRC (exp)) == MEM
4607 + && (GET_CODE (XEXP (SET_SRC (exp), 0)) == POST_INC
4608 + || GET_CODE (XEXP (SET_SRC (exp), 0)) == PRE_DEC)
4609 + &&
4610 + (reg_mentioned_p
4611 + (XEXP (XEXP (SET_SRC (exp), 0), 0), cc_status.value1)
4612 + || reg_mentioned_p (XEXP (XEXP (SET_SRC (exp), 0), 0),
4613 + cc_status.value2)
4614 + || reg_mentioned_p (XEXP (XEXP (SET_SRC (exp), 0), 0),
4615 + cc_status.mdep.value)))
4616 + CC_STATUS_INIT;
4617 +
4618 + if (GET_CODE (exp) == SET
4619 + && GET_CODE (SET_DEST (exp)) == MEM
4620 + && (GET_CODE (XEXP (SET_DEST (exp), 0)) == POST_INC
4621 + || GET_CODE (XEXP (SET_DEST (exp), 0)) == PRE_DEC)
4622 + &&
4623 + (reg_mentioned_p
4624 + (XEXP (XEXP (SET_DEST (exp), 0), 0), cc_status.value1)
4625 + || reg_mentioned_p (XEXP (XEXP (SET_DEST (exp), 0), 0),
4626 + cc_status.value2)
4627 + || reg_mentioned_p (XEXP (XEXP (SET_DEST (exp), 0), 0),
4628 + cc_status.mdep.value)))
4629 + CC_STATUS_INIT;
4630 + break;
4631 +
4632 + case CC_SET_VNCZ:
4633 + CC_STATUS_INIT;
4634 + cc_status.mdep.value = recog_data.operand[0];
4635 + cc_status.mdep.flags = CC_SET_VNCZ;
4636 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4637 + break;
4638 +
4639 + case CC_SET_NCZ:
4640 + CC_STATUS_INIT;
4641 + cc_status.mdep.value = recog_data.operand[0];
4642 + cc_status.mdep.flags = CC_SET_NCZ;
4643 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4644 + break;
4645 +
4646 + case CC_SET_CZ:
4647 + CC_STATUS_INIT;
4648 + cc_status.mdep.value = recog_data.operand[0];
4649 + cc_status.mdep.flags = CC_SET_CZ;
4650 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4651 + break;
4652 +
4653 + case CC_SET_Z:
4654 + CC_STATUS_INIT;
4655 + cc_status.mdep.value = recog_data.operand[0];
4656 + cc_status.mdep.flags = CC_SET_Z;
4657 + cc_status.mdep.cond_exec_cmp_clobbered = 0;
4658 + break;
4659 +
4660 + case CC_CLOBBER:
4661 + CC_STATUS_INIT;
4662 + break;
4663 +
4664 + default:
4665 + CC_STATUS_INIT;
4666 + }
4667 +}
4668 +
4669 +
4670 +/*
4671 + Outputs to stdio stream stream the assembler syntax for an instruction
4672 + operand x. x is an RTL expression.
4673 +*/
4674 +void
4675 +avr32_print_operand (FILE * stream, rtx x, int code)
4676 +{
4677 + int error = 0;
4678 +
4679 + if ( code == '?' )
4680 + {
4681 + /* Predicable instruction, print condition code */
4682 +
4683 + /* If the insn should not be conditional then do nothing. */
4684 + if ( current_insn_predicate == NULL_RTX )
4685 + return;
4686 +
4687 + /* Set x to the predicate to force printing
4688 + the condition later on. */
4689 + x = current_insn_predicate;
4690 +
4691 + /* Reverse condition if useing bld insn. */
4692 + if ( GET_CODE (XEXP(current_insn_predicate,0)) == AND )
4693 + x = reversed_condition (current_insn_predicate);
4694 + }
4695 + else if ( code == '!' )
4696 + {
4697 + /* Output compare for conditional insn if needed. */
4698 + rtx new_cond;
4699 + gcc_assert ( current_insn_predicate != NULL_RTX );
4700 + new_cond = avr32_output_cmp(current_insn_predicate,
4701 + GET_MODE(XEXP(current_insn_predicate,0)),
4702 + XEXP(current_insn_predicate,0),
4703 + XEXP(current_insn_predicate,1));
4704 +
4705 + /* Check if the new condition is a special avr32 condition
4706 + specified using UNSPECs. If so we must handle it differently. */
4707 + if ( GET_CODE (new_cond) == UNSPEC )
4708 + {
4709 + current_insn_predicate =
4710 + gen_rtx_UNSPEC (CCmode,
4711 + gen_rtvec (2,
4712 + XEXP(current_insn_predicate,0),
4713 + XEXP(current_insn_predicate,1)),
4714 + XINT (new_cond, 1));
4715 + }
4716 + else
4717 + {
4718 + PUT_CODE(current_insn_predicate, GET_CODE(new_cond));
4719 + }
4720 + return;
4721 + }
4722 +
4723 + switch (GET_CODE (x))
4724 + {
4725 + case UNSPEC:
4726 + switch (XINT (x, 1))
4727 + {
4728 + case UNSPEC_COND_PL:
4729 + if (code == 'i')
4730 + fputs ("mi", stream);
4731 + else
4732 + fputs ("pl", stream);
4733 + break;
4734 + case UNSPEC_COND_MI:
4735 + if (code == 'i')
4736 + fputs ("pl", stream);
4737 + else
4738 + fputs ("mi", stream);
4739 + break;
4740 + default:
4741 + error = 1;
4742 + }
4743 + break;
4744 + case EQ:
4745 + if (code == 'i')
4746 + fputs ("ne", stream);
4747 + else
4748 + fputs ("eq", stream);
4749 + break;
4750 + case NE:
4751 + if (code == 'i')
4752 + fputs ("eq", stream);
4753 + else
4754 + fputs ("ne", stream);
4755 + break;
4756 + case GT:
4757 + if (code == 'i')
4758 + fputs ("le", stream);
4759 + else
4760 + fputs ("gt", stream);
4761 + break;
4762 + case GTU:
4763 + if (code == 'i')
4764 + fputs ("ls", stream);
4765 + else
4766 + fputs ("hi", stream);
4767 + break;
4768 + case LT:
4769 + if (code == 'i')
4770 + fputs ("ge", stream);
4771 + else
4772 + fputs ("lt", stream);
4773 + break;
4774 + case LTU:
4775 + if (code == 'i')
4776 + fputs ("hs", stream);
4777 + else
4778 + fputs ("lo", stream);
4779 + break;
4780 + case GE:
4781 + if (code == 'i')
4782 + fputs ("lt", stream);
4783 + else
4784 + fputs ("ge", stream);
4785 + break;
4786 + case GEU:
4787 + if (code == 'i')
4788 + fputs ("lo", stream);
4789 + else
4790 + fputs ("hs", stream);
4791 + break;
4792 + case LE:
4793 + if (code == 'i')
4794 + fputs ("gt", stream);
4795 + else
4796 + fputs ("le", stream);
4797 + break;
4798 + case LEU:
4799 + if (code == 'i')
4800 + fputs ("hi", stream);
4801 + else
4802 + fputs ("ls", stream);
4803 + break;
4804 + case CONST_INT:
4805 + {
4806 + HOST_WIDE_INT value = INTVAL (x);
4807 +
4808 + switch (code)
4809 + {
4810 + case 'm':
4811 + if ( HOST_BITS_PER_WIDE_INT > BITS_PER_WORD )
4812 + {
4813 + /* A const_int can be used to represent DImode constants. */
4814 + value >>= BITS_PER_WORD;
4815 + }
4816 + /* We might get a const_int immediate for setting a DI register,
4817 + we then must then return the correct sign extended DI. The most
4818 + significant word is just a sign extension. */
4819 + else if (value < 0)
4820 + value = -1;
4821 + else
4822 + value = 0;
4823 + break;
4824 + case 'i':
4825 + value++;
4826 + break;
4827 + case 'p':
4828 + {
4829 + /* Set to bit position of first bit set in immediate */
4830 + int i, bitpos = 32;
4831 + for (i = 0; i < 32; i++)
4832 + if (value & (1 << i))
4833 + {
4834 + bitpos = i;
4835 + break;
4836 + }
4837 + value = bitpos;
4838 + }
4839 + break;
4840 + case 'r':
4841 + {
4842 + /* Reglist 8 */
4843 + char op[50];
4844 + op[0] = '\0';
4845 +
4846 + if (value & 0x01)
4847 + sprintf (op, "r0-r3");
4848 + if (value & 0x02)
4849 + strlen (op) ? sprintf (op, "%s, r4-r7", op) : sprintf (op,
4850 + "r4-r7");
4851 + if (value & 0x04)
4852 + strlen (op) ? sprintf (op, "%s, r8-r9", op) : sprintf (op,
4853 + "r8-r9");
4854 + if (value & 0x08)
4855 + strlen (op) ? sprintf (op, "%s, r10", op) : sprintf (op,
4856 + "r10");
4857 + if (value & 0x10)
4858 + strlen (op) ? sprintf (op, "%s, r11", op) : sprintf (op,
4859 + "r11");
4860 + if (value & 0x20)
4861 + strlen (op) ? sprintf (op, "%s, r12", op) : sprintf (op,
4862 + "r12");
4863 + if (value & 0x40)
4864 + strlen (op) ? sprintf (op, "%s, lr", op) : sprintf (op, "lr");
4865 + if (value & 0x80)
4866 + strlen (op) ? sprintf (op, "%s, pc", op) : sprintf (op, "pc");
4867 +
4868 + fputs (op, stream);
4869 + return;
4870 + }
4871 + case 's':
4872 + {
4873 + /* Reglist 16 */
4874 + char reglist16_string[100];
4875 + int i;
4876 + reglist16_string[0] = '\0';
4877 +
4878 + for (i = 0; i < 16; ++i)
4879 + {
4880 + if (value & (1 << i))
4881 + {
4882 + strlen (reglist16_string) ? sprintf (reglist16_string,
4883 + "%s, %s",
4884 + reglist16_string,
4885 + reg_names
4886 + [INTERNAL_REGNUM
4887 + (i)]) :
4888 + sprintf (reglist16_string, "%s",
4889 + reg_names[INTERNAL_REGNUM (i)]);
4890 + }
4891 + }
4892 + fputs (reglist16_string, stream);
4893 + return;
4894 + }
4895 + case 'C':
4896 + {
4897 + /* RegListCP8 */
4898 + char reglist_string[100];
4899 + avr32_make_fp_reglist_w (value, (char *) reglist_string);
4900 + fputs (reglist_string, stream);
4901 + return;
4902 + }
4903 + case 'D':
4904 + {
4905 + /* RegListCPD8 */
4906 + char reglist_string[100];
4907 + avr32_make_fp_reglist_d (value, (char *) reglist_string);
4908 + fputs (reglist_string, stream);
4909 + return;
4910 + }
4911 + case 'h':
4912 + /* Print halfword part of word */
4913 + fputs (value ? "b" : "t", stream);
4914 + return;
4915 + }
4916 +
4917 + /* Print Value */
4918 + fprintf (stream, "%d", value);
4919 + break;
4920 + }
4921 + case CONST_DOUBLE:
4922 + {
4923 + HOST_WIDE_INT hi, lo;
4924 + if (SCALAR_FLOAT_MODE_P (GET_MODE (x)))
4925 + {
4926 + HOST_WIDE_INT target_float[2];
4927 + hi = lo = 0;
4928 + real_to_target (target_float, CONST_DOUBLE_REAL_VALUE (x),
4929 + GET_MODE (x));
4930 + /* For doubles the most significant part starts at index 0. */
4931 + if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
4932 + {
4933 + hi = target_float[0];
4934 + lo = target_float[1];
4935 + }
4936 + else
4937 + {
4938 + lo = target_float[0];
4939 + }
4940 + }
4941 + else
4942 + {
4943 + hi = CONST_DOUBLE_HIGH (x);
4944 + lo = CONST_DOUBLE_LOW (x);
4945 + }
4946 +
4947 + if (code == 'm')
4948 + fprintf (stream, "%ld", hi);
4949 + else
4950 + fprintf (stream, "%ld", lo);
4951 +
4952 + break;
4953 + }
4954 + case CONST:
4955 + output_addr_const (stream, XEXP (XEXP (x, 0), 0));
4956 + fprintf (stream, "+%ld", INTVAL (XEXP (XEXP (x, 0), 1)));
4957 + break;
4958 + case REG:
4959 + /* Swap register name if the register is DImode or DFmode. */
4960 + if (GET_MODE (x) == DImode || GET_MODE (x) == DFmode)
4961 + {
4962 + /* Double register must have an even numbered address */
4963 + gcc_assert (!(REGNO (x) % 2));
4964 + if (code == 'm')
4965 + fputs (reg_names[true_regnum (x)], stream);
4966 + else
4967 + fputs (reg_names[true_regnum (x) + 1], stream);
4968 + }
4969 + else if (GET_MODE (x) == TImode)
4970 + {
4971 + switch (code)
4972 + {
4973 + case 'T':
4974 + fputs (reg_names[true_regnum (x)], stream);
4975 + break;
4976 + case 'U':
4977 + fputs (reg_names[true_regnum (x) + 1], stream);
4978 + break;
4979 + case 'L':
4980 + fputs (reg_names[true_regnum (x) + 2], stream);
4981 + break;
4982 + case 'B':
4983 + fputs (reg_names[true_regnum (x) + 3], stream);
4984 + break;
4985 + default:
4986 + fprintf (stream, "%s, %s, %s, %s",
4987 + reg_names[true_regnum (x) + 3],
4988 + reg_names[true_regnum (x) + 2],
4989 + reg_names[true_regnum (x) + 1],
4990 + reg_names[true_regnum (x)]);
4991 + break;
4992 + }
4993 + }
4994 + else
4995 + {
4996 + fputs (reg_names[true_regnum (x)], stream);
4997 + }
4998 + break;
4999 + case CODE_LABEL:
5000 + case LABEL_REF:
5001 + case SYMBOL_REF:
5002 + output_addr_const (stream, x);
5003 + break;
5004 + case MEM:
5005 + switch (GET_CODE (XEXP (x, 0)))
5006 + {
5007 + case LABEL_REF:
5008 + case SYMBOL_REF:
5009 + output_addr_const (stream, XEXP (x, 0));
5010 + break;
5011 + case MEM:
5012 + switch (GET_CODE (XEXP (XEXP (x, 0), 0)))
5013 + {
5014 + case SYMBOL_REF:
5015 + output_addr_const (stream, XEXP (XEXP (x, 0), 0));
5016 + break;
5017 + default:
5018 + error = 1;
5019 + break;
5020 + }
5021 + break;
5022 + case REG:
5023 + avr32_print_operand (stream, XEXP (x, 0), 0);
5024 + if (code != 'p')
5025 + fputs ("[0]", stream);
5026 + break;
5027 + case PRE_DEC:
5028 + fputs ("--", stream);
5029 + avr32_print_operand (stream, XEXP (XEXP (x, 0), 0), 0);
5030 + break;
5031 + case POST_INC:
5032 + avr32_print_operand (stream, XEXP (XEXP (x, 0), 0), 0);
5033 + fputs ("++", stream);
5034 + break;
5035 + case PLUS:
5036 + {
5037 + rtx op0 = XEXP (XEXP (x, 0), 0);
5038 + rtx op1 = XEXP (XEXP (x, 0), 1);
5039 + rtx base = NULL_RTX, offset = NULL_RTX;
5040 +
5041 + if (avr32_address_register_rtx_p (op0, 1))
5042 + {
5043 + base = op0;
5044 + offset = op1;
5045 + }
5046 + else if (avr32_address_register_rtx_p (op1, 1))
5047 + {
5048 + /* Operands are switched. */
5049 + base = op1;
5050 + offset = op0;
5051 + }
5052 +
5053 + gcc_assert (base && offset
5054 + && avr32_address_register_rtx_p (base, 1)
5055 + && avr32_legitimate_index_p (GET_MODE (x), offset,
5056 + 1));
5057 +
5058 + avr32_print_operand (stream, base, 0);
5059 + fputs ("[", stream);
5060 + avr32_print_operand (stream, offset, 0);
5061 + fputs ("]", stream);
5062 + break;
5063 + }
5064 + case CONST:
5065 + output_addr_const (stream, XEXP (XEXP (XEXP (x, 0), 0), 0));
5066 + fprintf (stream, " + %ld",
5067 + INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)));
5068 + break;
5069 + default:
5070 + error = 1;
5071 + }
5072 + break;
5073 + case MULT:
5074 + {
5075 + int value = INTVAL (XEXP (x, 1));
5076 +
5077 + /* Convert immediate in multiplication into a shift immediate */
5078 + switch (value)
5079 + {
5080 + case 2:
5081 + value = 1;
5082 + break;
5083 + case 4:
5084 + value = 2;
5085 + break;
5086 + case 8:
5087 + value = 3;
5088 + break;
5089 + default:
5090 + value = 0;
5091 + }
5092 + fprintf (stream, "%s << %i", reg_names[true_regnum (XEXP (x, 0))],
5093 + value);
5094 + break;
5095 + }
5096 + case ASHIFT:
5097 + if (GET_CODE (XEXP (x, 1)) == CONST_INT)
5098 + fprintf (stream, "%s << %i", reg_names[true_regnum (XEXP (x, 0))],
5099 + (int) INTVAL (XEXP (x, 1)));
5100 + else if (REG_P (XEXP (x, 1)))
5101 + fprintf (stream, "%s << %s", reg_names[true_regnum (XEXP (x, 0))],
5102 + reg_names[true_regnum (XEXP (x, 1))]);
5103 + else
5104 + {
5105 + error = 1;
5106 + }
5107 + break;
5108 + case LSHIFTRT:
5109 + if (GET_CODE (XEXP (x, 1)) == CONST_INT)
5110 + fprintf (stream, "%s >> %i", reg_names[true_regnum (XEXP (x, 0))],
5111 + (int) INTVAL (XEXP (x, 1)));
5112 + else if (REG_P (XEXP (x, 1)))
5113 + fprintf (stream, "%s >> %s", reg_names[true_regnum (XEXP (x, 0))],
5114 + reg_names[true_regnum (XEXP (x, 1))]);
5115 + else
5116 + {
5117 + error = 1;
5118 + }
5119 + fprintf (stream, ">>");
5120 + break;
5121 + case PARALLEL:
5122 + {
5123 + /* Load store multiple */
5124 + int i;
5125 + int count = XVECLEN (x, 0);
5126 + int reglist16 = 0;
5127 + char reglist16_string[100];
5128 +
5129 + for (i = 0; i < count; ++i)
5130 + {
5131 + rtx vec_elm = XVECEXP (x, 0, i);
5132 + if (GET_MODE (vec_elm) != SET)
5133 + {
5134 + debug_rtx (vec_elm);
5135 + internal_error ("Unknown element in parallel expression!");
5136 + }
5137 + if (GET_MODE (XEXP (vec_elm, 0)) == REG)
5138 + {
5139 + /* Load multiple */
5140 + reglist16 |= 1 << ASM_REGNUM (REGNO (XEXP (vec_elm, 0)));
5141 + }
5142 + else
5143 + {
5144 + /* Store multiple */
5145 + reglist16 |= 1 << ASM_REGNUM (REGNO (XEXP (vec_elm, 1)));
5146 + }
5147 + }
5148 +
5149 + avr32_make_reglist16 (reglist16, reglist16_string);
5150 + fputs (reglist16_string, stream);
5151 +
5152 + break;
5153 + }
5154 +
5155 + case PLUS:
5156 + {
5157 + rtx op0 = XEXP (x, 0);
5158 + rtx op1 = XEXP (x, 1);
5159 + rtx base = NULL_RTX, offset = NULL_RTX;
5160 +
5161 + if (avr32_address_register_rtx_p (op0, 1))
5162 + {
5163 + base = op0;
5164 + offset = op1;
5165 + }
5166 + else if (avr32_address_register_rtx_p (op1, 1))
5167 + {
5168 + /* Operands are switched. */
5169 + base = op1;
5170 + offset = op0;
5171 + }
5172 +
5173 + gcc_assert (base && offset
5174 + && avr32_address_register_rtx_p (base, 1)
5175 + && avr32_legitimate_index_p (GET_MODE (x), offset, 1));
5176 +
5177 + avr32_print_operand (stream, base, 0);
5178 + fputs ("[", stream);
5179 + avr32_print_operand (stream, offset, 0);
5180 + fputs ("]", stream);
5181 + break;
5182 + }
5183 +
5184 + default:
5185 + error = 1;
5186 + }
5187 +
5188 + if (error)
5189 + {
5190 + debug_rtx (x);
5191 + internal_error ("Illegal expression for avr32_print_operand");
5192 + }
5193 +}
5194 +
5195 +rtx
5196 +avr32_get_note_reg_equiv (rtx insn)
5197 +{
5198 + rtx note;
5199 +
5200 + note = find_reg_note (insn, REG_EQUIV, NULL_RTX);
5201 +
5202 + if (note != NULL_RTX)
5203 + return XEXP (note, 0);
5204 + else
5205 + return NULL_RTX;
5206 +}
5207 +
5208 +/*
5209 + Outputs to stdio stream stream the assembler syntax for an instruction
5210 + operand that is a memory reference whose address is x. x is an RTL
5211 + expression.
5212 +
5213 + ToDo: fixme.
5214 +*/
5215 +void
5216 +avr32_print_operand_address (FILE * stream, rtx x)
5217 +{
5218 + fprintf (stream, "(%d) /* address */", REGNO (x));
5219 +}
5220 +
5221 +/* Return true if _GLOBAL_OFFSET_TABLE_ symbol is mentioned. */
5222 +bool
5223 +avr32_got_mentioned_p (rtx addr)
5224 +{
5225 + if (GET_CODE (addr) == MEM)
5226 + addr = XEXP (addr, 0);
5227 + while (GET_CODE (addr) == CONST)
5228 + addr = XEXP (addr, 0);
5229 + if (GET_CODE (addr) == SYMBOL_REF)
5230 + {
5231 + return streq (XSTR (addr, 0), "_GLOBAL_OFFSET_TABLE_");
5232 + }
5233 + if (GET_CODE (addr) == PLUS || GET_CODE (addr) == MINUS)
5234 + {
5235 + bool l1, l2;
5236 +
5237 + l1 = avr32_got_mentioned_p (XEXP (addr, 0));
5238 + l2 = avr32_got_mentioned_p (XEXP (addr, 1));
5239 + return l1 || l2;
5240 + }
5241 + return false;
5242 +}
5243 +
5244 +
5245 +/* Find the symbol in an address expression. */
5246 +
5247 +rtx
5248 +avr32_find_symbol (rtx addr)
5249 +{
5250 + if (GET_CODE (addr) == MEM)
5251 + addr = XEXP (addr, 0);
5252 +
5253 + while (GET_CODE (addr) == CONST)
5254 + addr = XEXP (addr, 0);
5255 +
5256 + if (GET_CODE (addr) == SYMBOL_REF || GET_CODE (addr) == LABEL_REF)
5257 + return addr;
5258 + if (GET_CODE (addr) == PLUS)
5259 + {
5260 + rtx l1, l2;
5261 +
5262 + l1 = avr32_find_symbol (XEXP (addr, 0));
5263 + l2 = avr32_find_symbol (XEXP (addr, 1));
5264 + if (l1 != NULL_RTX && l2 == NULL_RTX)
5265 + return l1;
5266 + else if (l1 == NULL_RTX && l2 != NULL_RTX)
5267 + return l2;
5268 + }
5269 +
5270 + return NULL_RTX;
5271 +}
5272 +
5273 +
5274 +/* Routines for manipulation of the constant pool. */
5275 +
5276 +/* AVR32 instructions cannot load a large constant directly into a
5277 + register; they have to come from a pc relative load. The constant
5278 + must therefore be placed in the addressable range of the pc
5279 + relative load. Depending on the precise pc relative load
5280 + instruction the range is somewhere between 256 bytes and 4k. This
5281 + means that we often have to dump a constant inside a function, and
5282 + generate code to branch around it.
5283 +
5284 + It is important to minimize this, since the branches will slow
5285 + things down and make the code larger.
5286 +
5287 + Normally we can hide the table after an existing unconditional
5288 + branch so that there is no interruption of the flow, but in the
5289 + worst case the code looks like this:
5290 +
5291 + lddpc rn, L1
5292 + ...
5293 + rjmp L2
5294 + align
5295 + L1: .long value
5296 + L2:
5297 + ...
5298 +
5299 + lddpc rn, L3
5300 + ...
5301 + rjmp L4
5302 + align
5303 + L3: .long value
5304 + L4:
5305 + ...
5306 +
5307 + We fix this by performing a scan after scheduling, which notices
5308 + which instructions need to have their operands fetched from the
5309 + constant table and builds the table.
5310 +
5311 + The algorithm starts by building a table of all the constants that
5312 + need fixing up and all the natural barriers in the function (places
5313 + where a constant table can be dropped without breaking the flow).
5314 + For each fixup we note how far the pc-relative replacement will be
5315 + able to reach and the offset of the instruction into the function.
5316 +
5317 + Having built the table we then group the fixes together to form
5318 + tables that are as large as possible (subject to addressing
5319 + constraints) and emit each table of constants after the last
5320 + barrier that is within range of all the instructions in the group.
5321 + If a group does not contain a barrier, then we forcibly create one
5322 + by inserting a jump instruction into the flow. Once the table has
5323 + been inserted, the insns are then modified to reference the
5324 + relevant entry in the pool.
5325 +
5326 + Possible enhancements to the algorithm (not implemented) are:
5327 +
5328 + 1) For some processors and object formats, there may be benefit in
5329 + aligning the pools to the start of cache lines; this alignment
5330 + would need to be taken into account when calculating addressability
5331 + of a pool. */
5332 +
5333 +/* These typedefs are located at the start of this file, so that
5334 + they can be used in the prototypes there. This comment is to
5335 + remind readers of that fact so that the following structures
5336 + can be understood more easily.
5337 +
5338 + typedef struct minipool_node Mnode;
5339 + typedef struct minipool_fixup Mfix; */
5340 +
5341 +struct minipool_node
5342 +{
5343 + /* Doubly linked chain of entries. */
5344 + Mnode *next;
5345 + Mnode *prev;
5346 + /* The maximum offset into the code that this entry can be placed. While
5347 + pushing fixes for forward references, all entries are sorted in order of
5348 + increasing max_address. */
5349 + HOST_WIDE_INT max_address;
5350 + /* Similarly for an entry inserted for a backwards ref. */
5351 + HOST_WIDE_INT min_address;
5352 + /* The number of fixes referencing this entry. This can become zero if we
5353 + "unpush" an entry. In this case we ignore the entry when we come to
5354 + emit the code. */
5355 + int refcount;
5356 + /* The offset from the start of the minipool. */
5357 + HOST_WIDE_INT offset;
5358 + /* The value in table. */
5359 + rtx value;
5360 + /* The mode of value. */
5361 + enum machine_mode mode;
5362 + /* The size of the value. */
5363 + int fix_size;
5364 +};
5365 +
5366 +struct minipool_fixup
5367 +{
5368 + Mfix *next;
5369 + rtx insn;
5370 + HOST_WIDE_INT address;
5371 + rtx *loc;
5372 + enum machine_mode mode;
5373 + int fix_size;
5374 + rtx value;
5375 + Mnode *minipool;
5376 + HOST_WIDE_INT forwards;
5377 + HOST_WIDE_INT backwards;
5378 +};
5379 +
5380 +
5381 +/* Fixes less than a word need padding out to a word boundary. */
5382 +#define MINIPOOL_FIX_SIZE(mode, value) \
5383 + (IS_FORCE_MINIPOOL(value) ? 0 : \
5384 + (GET_MODE_SIZE ((mode)) >= 4 ? GET_MODE_SIZE ((mode)) : 4))
5385 +
5386 +#define IS_FORCE_MINIPOOL(x) \
5387 + (GET_CODE(x) == UNSPEC && \
5388 + XINT(x, 1) == UNSPEC_FORCE_MINIPOOL)
5389 +
5390 +static Mnode *minipool_vector_head;
5391 +static Mnode *minipool_vector_tail;
5392 +
5393 +/* The linked list of all minipool fixes required for this function. */
5394 +Mfix *minipool_fix_head;
5395 +Mfix *minipool_fix_tail;
5396 +/* The fix entry for the current minipool, once it has been placed. */
5397 +Mfix *minipool_barrier;
5398 +
5399 +/* Determines if INSN is the start of a jump table. Returns the end
5400 + of the TABLE or NULL_RTX. */
5401 +static rtx
5402 +is_jump_table (rtx insn)
5403 +{
5404 + rtx table;
5405 +
5406 + if (GET_CODE (insn) == JUMP_INSN
5407 + && JUMP_LABEL (insn) != NULL
5408 + && ((table = next_real_insn (JUMP_LABEL (insn)))
5409 + == next_real_insn (insn))
5410 + && table != NULL
5411 + && GET_CODE (table) == JUMP_INSN
5412 + && (GET_CODE (PATTERN (table)) == ADDR_VEC
5413 + || GET_CODE (PATTERN (table)) == ADDR_DIFF_VEC))
5414 + return table;
5415 +
5416 + return NULL_RTX;
5417 +}
5418 +
5419 +static HOST_WIDE_INT
5420 +get_jump_table_size (rtx insn)
5421 +{
5422 + /* ADDR_VECs only take room if read-only data does into the text section. */
5423 + if (JUMP_TABLES_IN_TEXT_SECTION
5424 +#if !defined(READONLY_DATA_SECTION_ASM_OP)
5425 + || 1
5426 +#endif
5427 + )
5428 + {
5429 + rtx body = PATTERN (insn);
5430 + int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0;
5431 +
5432 + return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, elt);
5433 + }
5434 +
5435 + return 0;
5436 +}
5437 +
5438 +/* Move a minipool fix MP from its current location to before MAX_MP.
5439 + If MAX_MP is NULL, then MP doesn't need moving, but the addressing
5440 + constraints may need updating. */
5441 +static Mnode *
5442 +move_minipool_fix_forward_ref (Mnode * mp, Mnode * max_mp,
5443 + HOST_WIDE_INT max_address)
5444 +{
5445 + /* This should never be true and the code below assumes these are
5446 + different. */
5447 + if (mp == max_mp)
5448 + abort ();
5449 +
5450 + if (max_mp == NULL)
5451 + {
5452 + if (max_address < mp->max_address)
5453 + mp->max_address = max_address;
5454 + }
5455 + else
5456 + {
5457 + if (max_address > max_mp->max_address - mp->fix_size)
5458 + mp->max_address = max_mp->max_address - mp->fix_size;
5459 + else
5460 + mp->max_address = max_address;
5461 +
5462 + /* Unlink MP from its current position. Since max_mp is non-null,
5463 + mp->prev must be non-null. */
5464 + mp->prev->next = mp->next;
5465 + if (mp->next != NULL)
5466 + mp->next->prev = mp->prev;
5467 + else
5468 + minipool_vector_tail = mp->prev;
5469 +
5470 + /* Re-insert it before MAX_MP. */
5471 + mp->next = max_mp;
5472 + mp->prev = max_mp->prev;
5473 + max_mp->prev = mp;
5474 +
5475 + if (mp->prev != NULL)
5476 + mp->prev->next = mp;
5477 + else
5478 + minipool_vector_head = mp;
5479 + }
5480 +
5481 + /* Save the new entry. */
5482 + max_mp = mp;
5483 +
5484 + /* Scan over the preceding entries and adjust their addresses as required.
5485 + */
5486 + while (mp->prev != NULL
5487 + && mp->prev->max_address > mp->max_address - mp->prev->fix_size)
5488 + {
5489 + mp->prev->max_address = mp->max_address - mp->prev->fix_size;
5490 + mp = mp->prev;
5491 + }
5492 +
5493 + return max_mp;
5494 +}
5495 +
5496 +/* Add a constant to the minipool for a forward reference. Returns the
5497 + node added or NULL if the constant will not fit in this pool. */
5498 +static Mnode *
5499 +add_minipool_forward_ref (Mfix * fix)
5500 +{
5501 + /* If set, max_mp is the first pool_entry that has a lower constraint than
5502 + the one we are trying to add. */
5503 + Mnode *max_mp = NULL;
5504 + HOST_WIDE_INT max_address = fix->address + fix->forwards;
5505 + Mnode *mp;
5506 +
5507 + /* If this fix's address is greater than the address of the first entry,
5508 + then we can't put the fix in this pool. We subtract the size of the
5509 + current fix to ensure that if the table is fully packed we still have
5510 + enough room to insert this value by suffling the other fixes forwards. */
5511 + if (minipool_vector_head &&
5512 + fix->address >= minipool_vector_head->max_address - fix->fix_size)
5513 + return NULL;
5514 +
5515 + /* Scan the pool to see if a constant with the same value has already been
5516 + added. While we are doing this, also note the location where we must
5517 + insert the constant if it doesn't already exist. */
5518 + for (mp = minipool_vector_head; mp != NULL; mp = mp->next)
5519 + {
5520 + if (GET_CODE (fix->value) == GET_CODE (mp->value)
5521 + && fix->mode == mp->mode
5522 + && (GET_CODE (fix->value) != CODE_LABEL
5523 + || (CODE_LABEL_NUMBER (fix->value)
5524 + == CODE_LABEL_NUMBER (mp->value)))
5525 + && rtx_equal_p (fix->value, mp->value))
5526 + {
5527 + /* More than one fix references this entry. */
5528 + mp->refcount++;
5529 + return move_minipool_fix_forward_ref (mp, max_mp, max_address);
5530 + }
5531 +
5532 + /* Note the insertion point if necessary. */
5533 + if (max_mp == NULL && mp->max_address > max_address)
5534 + max_mp = mp;
5535 +
5536 + }
5537 +
5538 + /* The value is not currently in the minipool, so we need to create a new
5539 + entry for it. If MAX_MP is NULL, the entry will be put on the end of
5540 + the list since the placement is less constrained than any existing
5541 + entry. Otherwise, we insert the new fix before MAX_MP and, if
5542 + necessary, adjust the constraints on the other entries. */
5543 + mp = xmalloc (sizeof (*mp));
5544 + mp->fix_size = fix->fix_size;
5545 + mp->mode = fix->mode;
5546 + mp->value = fix->value;
5547 + mp->refcount = 1;
5548 + /* Not yet required for a backwards ref. */
5549 + mp->min_address = -65536;
5550 +
5551 + if (max_mp == NULL)
5552 + {
5553 + mp->max_address = max_address;
5554 + mp->next = NULL;
5555 + mp->prev = minipool_vector_tail;
5556 +
5557 + if (mp->prev == NULL)
5558 + {
5559 + minipool_vector_head = mp;
5560 + minipool_vector_label = gen_label_rtx ();
5561 + }
5562 + else
5563 + mp->prev->next = mp;
5564 +
5565 + minipool_vector_tail = mp;
5566 + }
5567 + else
5568 + {
5569 + if (max_address > max_mp->max_address - mp->fix_size)
5570 + mp->max_address = max_mp->max_address - mp->fix_size;
5571 + else
5572 + mp->max_address = max_address;
5573 +
5574 + mp->next = max_mp;
5575 + mp->prev = max_mp->prev;
5576 + max_mp->prev = mp;
5577 + if (mp->prev != NULL)
5578 + mp->prev->next = mp;
5579 + else
5580 + minipool_vector_head = mp;
5581 + }
5582 +
5583 + /* Save the new entry. */
5584 + max_mp = mp;
5585 +
5586 + /* Scan over the preceding entries and adjust their addresses as required.
5587 + */
5588 + while (mp->prev != NULL
5589 + && mp->prev->max_address > mp->max_address - mp->prev->fix_size)
5590 + {
5591 + mp->prev->max_address = mp->max_address - mp->prev->fix_size;
5592 + mp = mp->prev;
5593 + }
5594 +
5595 + return max_mp;
5596 +}
5597 +
5598 +static Mnode *
5599 +move_minipool_fix_backward_ref (Mnode * mp, Mnode * min_mp,
5600 + HOST_WIDE_INT min_address)
5601 +{
5602 + HOST_WIDE_INT offset;
5603 +
5604 + /* This should never be true, and the code below assumes these are
5605 + different. */
5606 + if (mp == min_mp)
5607 + abort ();
5608 +
5609 + if (min_mp == NULL)
5610 + {
5611 + if (min_address > mp->min_address)
5612 + mp->min_address = min_address;
5613 + }
5614 + else
5615 + {
5616 + /* We will adjust this below if it is too loose. */
5617 + mp->min_address = min_address;
5618 +
5619 + /* Unlink MP from its current position. Since min_mp is non-null,
5620 + mp->next must be non-null. */
5621 + mp->next->prev = mp->prev;
5622 + if (mp->prev != NULL)
5623 + mp->prev->next = mp->next;
5624 + else
5625 + minipool_vector_head = mp->next;
5626 +
5627 + /* Reinsert it after MIN_MP. */
5628 + mp->prev = min_mp;
5629 + mp->next = min_mp->next;
5630 + min_mp->next = mp;
5631 + if (mp->next != NULL)
5632 + mp->next->prev = mp;
5633 + else
5634 + minipool_vector_tail = mp;
5635 + }
5636 +
5637 + min_mp = mp;
5638 +
5639 + offset = 0;
5640 + for (mp = minipool_vector_head; mp != NULL; mp = mp->next)
5641 + {
5642 + mp->offset = offset;
5643 + if (mp->refcount > 0)
5644 + offset += mp->fix_size;
5645 +
5646 + if (mp->next && mp->next->min_address < mp->min_address + mp->fix_size)
5647 + mp->next->min_address = mp->min_address + mp->fix_size;
5648 + }
5649 +
5650 + return min_mp;
5651 +}
5652 +
5653 +/* Add a constant to the minipool for a backward reference. Returns the
5654 + node added or NULL if the constant will not fit in this pool.
5655 +
5656 + Note that the code for insertion for a backwards reference can be
5657 + somewhat confusing because the calculated offsets for each fix do
5658 + not take into account the size of the pool (which is still under
5659 + construction. */
5660 +static Mnode *
5661 +add_minipool_backward_ref (Mfix * fix)
5662 +{
5663 + /* If set, min_mp is the last pool_entry that has a lower constraint than
5664 + the one we are trying to add. */
5665 + Mnode *min_mp = NULL;
5666 + /* This can be negative, since it is only a constraint. */
5667 + HOST_WIDE_INT min_address = fix->address - fix->backwards;
5668 + Mnode *mp;
5669 +
5670 + /* If we can't reach the current pool from this insn, or if we can't insert
5671 + this entry at the end of the pool without pushing other fixes out of
5672 + range, then we don't try. This ensures that we can't fail later on. */
5673 + if (min_address >= minipool_barrier->address
5674 + || (minipool_vector_tail->min_address + fix->fix_size
5675 + >= minipool_barrier->address))
5676 + return NULL;
5677 +
5678 + /* Scan the pool to see if a constant with the same value has already been
5679 + added. While we are doing this, also note the location where we must
5680 + insert the constant if it doesn't already exist. */
5681 + for (mp = minipool_vector_tail; mp != NULL; mp = mp->prev)
5682 + {
5683 + if (GET_CODE (fix->value) == GET_CODE (mp->value)
5684 + && fix->mode == mp->mode
5685 + && (GET_CODE (fix->value) != CODE_LABEL
5686 + || (CODE_LABEL_NUMBER (fix->value)
5687 + == CODE_LABEL_NUMBER (mp->value)))
5688 + && rtx_equal_p (fix->value, mp->value)
5689 + /* Check that there is enough slack to move this entry to the end
5690 + of the table (this is conservative). */
5691 + && (mp->max_address
5692 + > (minipool_barrier->address
5693 + + minipool_vector_tail->offset
5694 + + minipool_vector_tail->fix_size)))
5695 + {
5696 + mp->refcount++;
5697 + return move_minipool_fix_backward_ref (mp, min_mp, min_address);
5698 + }
5699 +
5700 + if (min_mp != NULL)
5701 + mp->min_address += fix->fix_size;
5702 + else
5703 + {
5704 + /* Note the insertion point if necessary. */
5705 + if (mp->min_address < min_address)
5706 + {
5707 + min_mp = mp;
5708 + }
5709 + else if (mp->max_address
5710 + < minipool_barrier->address + mp->offset + fix->fix_size)
5711 + {
5712 + /* Inserting before this entry would push the fix beyond its
5713 + maximum address (which can happen if we have re-located a
5714 + forwards fix); force the new fix to come after it. */
5715 + min_mp = mp;
5716 + min_address = mp->min_address + fix->fix_size;
5717 + }
5718 + }
5719 + }
5720 +
5721 + /* We need to create a new entry. */
5722 + mp = xmalloc (sizeof (*mp));
5723 + mp->fix_size = fix->fix_size;
5724 + mp->mode = fix->mode;
5725 + mp->value = fix->value;
5726 + mp->refcount = 1;
5727 + mp->max_address = minipool_barrier->address + 65536;
5728 +
5729 + mp->min_address = min_address;
5730 +
5731 + if (min_mp == NULL)
5732 + {
5733 + mp->prev = NULL;
5734 + mp->next = minipool_vector_head;
5735 +
5736 + if (mp->next == NULL)
5737 + {
5738 + minipool_vector_tail = mp;
5739 + minipool_vector_label = gen_label_rtx ();
5740 + }
5741 + else
5742 + mp->next->prev = mp;
5743 +
5744 + minipool_vector_head = mp;
5745 + }
5746 + else
5747 + {
5748 + mp->next = min_mp->next;
5749 + mp->prev = min_mp;
5750 + min_mp->next = mp;
5751 +
5752 + if (mp->next != NULL)
5753 + mp->next->prev = mp;
5754 + else
5755 + minipool_vector_tail = mp;
5756 + }
5757 +
5758 + /* Save the new entry. */
5759 + min_mp = mp;
5760 +
5761 + if (mp->prev)
5762 + mp = mp->prev;
5763 + else
5764 + mp->offset = 0;
5765 +
5766 + /* Scan over the following entries and adjust their offsets. */
5767 + while (mp->next != NULL)
5768 + {
5769 + if (mp->next->min_address < mp->min_address + mp->fix_size)
5770 + mp->next->min_address = mp->min_address + mp->fix_size;
5771 +
5772 + if (mp->refcount)
5773 + mp->next->offset = mp->offset + mp->fix_size;
5774 + else
5775 + mp->next->offset = mp->offset;
5776 +
5777 + mp = mp->next;
5778 + }
5779 +
5780 + return min_mp;
5781 +}
5782 +
5783 +static void
5784 +assign_minipool_offsets (Mfix * barrier)
5785 +{
5786 + HOST_WIDE_INT offset = 0;
5787 + Mnode *mp;
5788 +
5789 + minipool_barrier = barrier;
5790 +
5791 + for (mp = minipool_vector_head; mp != NULL; mp = mp->next)
5792 + {
5793 + mp->offset = offset;
5794 +
5795 + if (mp->refcount > 0)
5796 + offset += mp->fix_size;
5797 + }
5798 +}
5799 +
5800 +/* Print a symbolic form of X to the debug file, F. */
5801 +static void
5802 +avr32_print_value (FILE * f, rtx x)
5803 +{
5804 + switch (GET_CODE (x))
5805 + {
5806 + case CONST_INT:
5807 + fprintf (f, "0x%x", (int) INTVAL (x));
5808 + return;
5809 +
5810 + case CONST_DOUBLE:
5811 + fprintf (f, "<0x%lx,0x%lx>", (long) XWINT (x, 2), (long) XWINT (x, 3));
5812 + return;
5813 +
5814 + case CONST_VECTOR:
5815 + {
5816 + int i;
5817 +
5818 + fprintf (f, "<");
5819 + for (i = 0; i < CONST_VECTOR_NUNITS (x); i++)
5820 + {
5821 + fprintf (f, "0x%x", (int) INTVAL (CONST_VECTOR_ELT (x, i)));
5822 + if (i < (CONST_VECTOR_NUNITS (x) - 1))
5823 + fputc (',', f);
5824 + }
5825 + fprintf (f, ">");
5826 + }
5827 + return;
5828 +
5829 + case CONST_STRING:
5830 + fprintf (f, "\"%s\"", XSTR (x, 0));
5831 + return;
5832 +
5833 + case SYMBOL_REF:
5834 + fprintf (f, "`%s'", XSTR (x, 0));
5835 + return;
5836 +
5837 + case LABEL_REF:
5838 + fprintf (f, "L%d", INSN_UID (XEXP (x, 0)));
5839 + return;
5840 +
5841 + case CONST:
5842 + avr32_print_value (f, XEXP (x, 0));
5843 + return;
5844 +
5845 + case PLUS:
5846 + avr32_print_value (f, XEXP (x, 0));
5847 + fprintf (f, "+");
5848 + avr32_print_value (f, XEXP (x, 1));
5849 + return;
5850 +
5851 + case PC:
5852 + fprintf (f, "pc");
5853 + return;
5854 +
5855 + default:
5856 + fprintf (f, "????");
5857 + return;
5858 + }
5859 +}
5860 +
5861 +int
5862 +is_minipool_label (rtx label)
5863 +{
5864 + minipool_labels *cur_mp_label = cfun->machine->minipool_label_head;
5865 +
5866 + if (GET_CODE (label) != CODE_LABEL)
5867 + return FALSE;
5868 +
5869 + while (cur_mp_label)
5870 + {
5871 + if (CODE_LABEL_NUMBER (label)
5872 + == CODE_LABEL_NUMBER (cur_mp_label->label))
5873 + return TRUE;
5874 + cur_mp_label = cur_mp_label->next;
5875 + }
5876 + return FALSE;
5877 +}
5878 +
5879 +static void
5880 +new_minipool_label (rtx label)
5881 +{
5882 + if (!cfun->machine->minipool_label_head)
5883 + {
5884 + cfun->machine->minipool_label_head =
5885 + ggc_alloc (sizeof (minipool_labels));
5886 + cfun->machine->minipool_label_tail = cfun->machine->minipool_label_head;
5887 + cfun->machine->minipool_label_head->label = label;
5888 + cfun->machine->minipool_label_head->next = 0;
5889 + cfun->machine->minipool_label_head->prev = 0;
5890 + }
5891 + else
5892 + {
5893 + cfun->machine->minipool_label_tail->next =
5894 + ggc_alloc (sizeof (minipool_labels));
5895 + cfun->machine->minipool_label_tail->next->label = label;
5896 + cfun->machine->minipool_label_tail->next->next = 0;
5897 + cfun->machine->minipool_label_tail->next->prev =
5898 + cfun->machine->minipool_label_tail;
5899 + cfun->machine->minipool_label_tail =
5900 + cfun->machine->minipool_label_tail->next;
5901 + }
5902 +}
5903 +
5904 +/* Output the literal table */
5905 +static void
5906 +dump_minipool (rtx scan)
5907 +{
5908 + Mnode *mp;
5909 + Mnode *nmp;
5910 +
5911 + if (dump_file)
5912 + fprintf (dump_file,
5913 + ";; Emitting minipool after insn %u; address %ld; align %d (bytes)\n",
5914 + INSN_UID (scan), (unsigned long) minipool_barrier->address, 4);
5915 +
5916 + scan = emit_insn_after (gen_consttable_start (), scan);
5917 + scan = emit_insn_after (gen_align_4 (), scan);
5918 + scan = emit_label_after (minipool_vector_label, scan);
5919 + new_minipool_label (minipool_vector_label);
5920 +
5921 + for (mp = minipool_vector_head; mp != NULL; mp = nmp)
5922 + {
5923 + if (mp->refcount > 0)
5924 + {
5925 + if (dump_file)
5926 + {
5927 + fprintf (dump_file,
5928 + ";; Offset %u, min %ld, max %ld ",
5929 + (unsigned) mp->offset, (unsigned long) mp->min_address,
5930 + (unsigned long) mp->max_address);
5931 + avr32_print_value (dump_file, mp->value);
5932 + fputc ('\n', dump_file);
5933 + }
5934 +
5935 + switch (mp->fix_size)
5936 + {
5937 +#ifdef HAVE_consttable_4
5938 + case 4:
5939 + scan = emit_insn_after (gen_consttable_4 (mp->value), scan);
5940 + break;
5941 +
5942 +#endif
5943 +#ifdef HAVE_consttable_8
5944 + case 8:
5945 + scan = emit_insn_after (gen_consttable_8 (mp->value), scan);
5946 + break;
5947 +
5948 +#endif
5949 +#ifdef HAVE_consttable_16
5950 + case 16:
5951 + scan = emit_insn_after (gen_consttable_16 (mp->value), scan);
5952 + break;
5953 +
5954 +#endif
5955 + case 0:
5956 + /* This can happen for force-minipool entries which just are
5957 + there to force the minipool to be generate. */
5958 + break;
5959 + default:
5960 + abort ();
5961 + break;
5962 + }
5963 + }
5964 +
5965 + nmp = mp->next;
5966 + free (mp);
5967 + }
5968 +
5969 + minipool_vector_head = minipool_vector_tail = NULL;
5970 + scan = emit_insn_after (gen_consttable_end (), scan);
5971 + scan = emit_barrier_after (scan);
5972 +}
5973 +
5974 +/* Return the cost of forcibly inserting a barrier after INSN. */
5975 +static int
5976 +avr32_barrier_cost (rtx insn)
5977 +{
5978 + /* Basing the location of the pool on the loop depth is preferable, but at
5979 + the moment, the basic block information seems to be corrupt by this
5980 + stage of the compilation. */
5981 + int base_cost = 50;
5982 + rtx next = next_nonnote_insn (insn);
5983 +
5984 + if (next != NULL && GET_CODE (next) == CODE_LABEL)
5985 + base_cost -= 20;
5986 +
5987 + switch (GET_CODE (insn))
5988 + {
5989 + case CODE_LABEL:
5990 + /* It will always be better to place the table before the label, rather
5991 + than after it. */
5992 + return 50;
5993 +
5994 + case INSN:
5995 + case CALL_INSN:
5996 + return base_cost;
5997 +
5998 + case JUMP_INSN:
5999 + return base_cost - 10;
6000 +
6001 + default:
6002 + return base_cost + 10;
6003 + }
6004 +}
6005 +
6006 +/* Find the best place in the insn stream in the range
6007 + (FIX->address,MAX_ADDRESS) to forcibly insert a minipool barrier.
6008 + Create the barrier by inserting a jump and add a new fix entry for
6009 + it. */
6010 +static Mfix *
6011 +create_fix_barrier (Mfix * fix, HOST_WIDE_INT max_address)
6012 +{
6013 + HOST_WIDE_INT count = 0;
6014 + rtx barrier;
6015 + rtx from = fix->insn;
6016 + rtx selected = from;
6017 + int selected_cost;
6018 + HOST_WIDE_INT selected_address;
6019 + Mfix *new_fix;
6020 + HOST_WIDE_INT max_count = max_address - fix->address;
6021 + rtx label = gen_label_rtx ();
6022 +
6023 + selected_cost = avr32_barrier_cost (from);
6024 + selected_address = fix->address;
6025 +
6026 + while (from && count < max_count)
6027 + {
6028 + rtx tmp;
6029 + int new_cost;
6030 +
6031 + /* This code shouldn't have been called if there was a natural barrier
6032 + within range. */
6033 + if (GET_CODE (from) == BARRIER)
6034 + abort ();
6035 +
6036 + /* Count the length of this insn. */
6037 + count += get_attr_length (from);
6038 +
6039 + /* If there is a jump table, add its length. */
6040 + tmp = is_jump_table (from);
6041 + if (tmp != NULL)
6042 + {
6043 + count += get_jump_table_size (tmp);
6044 +
6045 + /* Jump tables aren't in a basic block, so base the cost on the
6046 + dispatch insn. If we select this location, we will still put
6047 + the pool after the table. */
6048 + new_cost = avr32_barrier_cost (from);
6049 +
6050 + if (count < max_count && new_cost <= selected_cost)
6051 + {
6052 + selected = tmp;
6053 + selected_cost = new_cost;
6054 + selected_address = fix->address + count;
6055 + }
6056 +
6057 + /* Continue after the dispatch table. */
6058 + from = NEXT_INSN (tmp);
6059 + continue;
6060 + }
6061 +
6062 + new_cost = avr32_barrier_cost (from);
6063 +
6064 + if (count < max_count && new_cost <= selected_cost)
6065 + {
6066 + selected = from;
6067 + selected_cost = new_cost;
6068 + selected_address = fix->address + count;
6069 + }
6070 +
6071 + from = NEXT_INSN (from);
6072 + }
6073 +
6074 + /* Create a new JUMP_INSN that branches around a barrier. */
6075 + from = emit_jump_insn_after (gen_jump (label), selected);
6076 + JUMP_LABEL (from) = label;
6077 + barrier = emit_barrier_after (from);
6078 + emit_label_after (label, barrier);
6079 +
6080 + /* Create a minipool barrier entry for the new barrier. */
6081 + new_fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (*new_fix));
6082 + new_fix->insn = barrier;
6083 + new_fix->address = selected_address;
6084 + new_fix->next = fix->next;
6085 + fix->next = new_fix;
6086 +
6087 + return new_fix;
6088 +}
6089 +
6090 +/* Record that there is a natural barrier in the insn stream at
6091 + ADDRESS. */
6092 +static void
6093 +push_minipool_barrier (rtx insn, HOST_WIDE_INT address)
6094 +{
6095 + Mfix *fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (*fix));
6096 +
6097 + fix->insn = insn;
6098 + fix->address = address;
6099 +
6100 + fix->next = NULL;
6101 + if (minipool_fix_head != NULL)
6102 + minipool_fix_tail->next = fix;
6103 + else
6104 + minipool_fix_head = fix;
6105 +
6106 + minipool_fix_tail = fix;
6107 +}
6108 +
6109 +/* Record INSN, which will need fixing up to load a value from the
6110 + minipool. ADDRESS is the offset of the insn since the start of the
6111 + function; LOC is a pointer to the part of the insn which requires
6112 + fixing; VALUE is the constant that must be loaded, which is of type
6113 + MODE. */
6114 +static void
6115 +push_minipool_fix (rtx insn, HOST_WIDE_INT address, rtx * loc,
6116 + enum machine_mode mode, rtx value)
6117 +{
6118 + Mfix *fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (*fix));
6119 + rtx body = PATTERN (insn);
6120 +
6121 + fix->insn = insn;
6122 + fix->address = address;
6123 + fix->loc = loc;
6124 + fix->mode = mode;
6125 + fix->fix_size = MINIPOOL_FIX_SIZE (mode, value);
6126 + fix->value = value;
6127 +
6128 + if (GET_CODE (body) == PARALLEL)
6129 + {
6130 + /* Mcall : Ks16 << 2 */
6131 + fix->forwards = ((1 << 15) - 1) << 2;
6132 + fix->backwards = (1 << 15) << 2;
6133 + }
6134 + else if (GET_CODE (body) == SET
6135 + && GET_MODE_SIZE (GET_MODE (SET_DEST (body))) == 4)
6136 + {
6137 + /* Word Load */
6138 + if (TARGET_HARD_FLOAT
6139 + && GET_MODE_CLASS (GET_MODE (SET_DEST (body))) == MODE_FLOAT)
6140 + {
6141 + /* Ldc0.w : Ku12 << 2 */
6142 + fix->forwards = ((1 << 12) - 1) << 2;
6143 + fix->backwards = 0;
6144 + }
6145 + else
6146 + {
6147 + if (optimize_size)
6148 + {
6149 + /* Lddpc : Ku7 << 2 */
6150 + fix->forwards = ((1 << 7) - 1) << 2;
6151 + fix->backwards = 0;
6152 + }
6153 + else
6154 + {
6155 + /* Ld.w : Ks16 */
6156 + fix->forwards = ((1 << 15) - 4);
6157 + fix->backwards = (1 << 15);
6158 + }
6159 + }
6160 + }
6161 + else if (GET_CODE (body) == SET
6162 + && GET_MODE_SIZE (GET_MODE (SET_DEST (body))) == 8)
6163 + {
6164 + /* Double word load */
6165 + if (TARGET_HARD_FLOAT
6166 + && GET_MODE_CLASS (GET_MODE (SET_DEST (body))) == MODE_FLOAT)
6167 + {
6168 + /* Ldc0.d : Ku12 << 2 */
6169 + fix->forwards = ((1 << 12) - 1) << 2;
6170 + fix->backwards = 0;
6171 + }
6172 + else
6173 + {
6174 + /* Ld.d : Ks16 */
6175 + fix->forwards = ((1 << 15) - 4);
6176 + fix->backwards = (1 << 15);
6177 + }
6178 + }
6179 + else if (GET_CODE (body) == UNSPEC_VOLATILE
6180 + && XINT (body, 1) == VUNSPEC_MVRC)
6181 + {
6182 + /* Coprocessor load */
6183 + /* Ldc : Ku8 << 2 */
6184 + fix->forwards = ((1 << 8) - 1) << 2;
6185 + fix->backwards = 0;
6186 + }
6187 + else
6188 + {
6189 + /* Assume worst case which is lddpc insn. */
6190 + fix->forwards = ((1 << 7) - 1) << 2;
6191 + fix->backwards = 0;
6192 + }
6193 +
6194 + fix->minipool = NULL;
6195 +
6196 + /* If an insn doesn't have a range defined for it, then it isn't expecting
6197 + to be reworked by this code. Better to abort now than to generate duff
6198 + assembly code. */
6199 + if (fix->forwards == 0 && fix->backwards == 0)
6200 + abort ();
6201 +
6202 + if (dump_file)
6203 + {
6204 + fprintf (dump_file,
6205 + ";; %smode fixup for i%d; addr %lu, range (%ld,%ld): ",
6206 + GET_MODE_NAME (mode),
6207 + INSN_UID (insn), (unsigned long) address,
6208 + -1 * (long) fix->backwards, (long) fix->forwards);
6209 + avr32_print_value (dump_file, fix->value);
6210 + fprintf (dump_file, "\n");
6211 + }
6212 +
6213 + /* Add it to the chain of fixes. */
6214 + fix->next = NULL;
6215 +
6216 + if (minipool_fix_head != NULL)
6217 + minipool_fix_tail->next = fix;
6218 + else
6219 + minipool_fix_head = fix;
6220 +
6221 + minipool_fix_tail = fix;
6222 +}
6223 +
6224 +/* Scan INSN and note any of its operands that need fixing.
6225 + If DO_PUSHES is false we do not actually push any of the fixups
6226 + needed. The function returns TRUE is any fixups were needed/pushed.
6227 + This is used by avr32_memory_load_p() which needs to know about loads
6228 + of constants that will be converted into minipool loads. */
6229 +static bool
6230 +note_invalid_constants (rtx insn, HOST_WIDE_INT address, int do_pushes)
6231 +{
6232 + bool result = false;
6233 + int opno;
6234 +
6235 + extract_insn (insn);
6236 +
6237 + if (!constrain_operands (1))
6238 + fatal_insn_not_found (insn);
6239 +
6240 + if (recog_data.n_alternatives == 0)
6241 + return false;
6242 +
6243 + /* Fill in recog_op_alt with information about the constraints of this
6244 + insn. */
6245 + preprocess_constraints ();
6246 +
6247 + for (opno = 0; opno < recog_data.n_operands; opno++)
6248 + {
6249 + rtx op;
6250 +
6251 + /* Things we need to fix can only occur in inputs. */
6252 + if (recog_data.operand_type[opno] != OP_IN)
6253 + continue;
6254 +
6255 + op = recog_data.operand[opno];
6256 +
6257 + if (avr32_const_pool_ref_operand (op, GET_MODE (op)))
6258 + {
6259 + if (do_pushes)
6260 + {
6261 + rtx cop = avoid_constant_pool_reference (op);
6262 +
6263 + /* Casting the address of something to a mode narrower than a
6264 + word can cause avoid_constant_pool_reference() to return the
6265 + pool reference itself. That's no good to us here. Lets
6266 + just hope that we can use the constant pool value directly.
6267 + */
6268 + if (op == cop)
6269 + cop = get_pool_constant (XEXP (op, 0));
6270 +
6271 + push_minipool_fix (insn, address,
6272 + recog_data.operand_loc[opno],
6273 + recog_data.operand_mode[opno], cop);
6274 + }
6275 +
6276 + result = true;
6277 + }
6278 + else if (TARGET_HAS_ASM_ADDR_PSEUDOS
6279 + && avr32_address_operand (op, GET_MODE (op)))
6280 + {
6281 + /* Handle pseudo instructions using a direct address. These pseudo
6282 + instructions might need entries in the constant pool and we must
6283 + therefor create a constant pool for them, in case the
6284 + assembler/linker needs to insert entries. */
6285 + if (do_pushes)
6286 + {
6287 + /* Push a dummy constant pool entry so that the .cpool
6288 + directive should be inserted on the appropriate place in the
6289 + code even if there are no real constant pool entries. This
6290 + is used by the assembler and linker to know where to put
6291 + generated constant pool entries. */
6292 + push_minipool_fix (insn, address,
6293 + recog_data.operand_loc[opno],
6294 + recog_data.operand_mode[opno],
6295 + gen_rtx_UNSPEC (VOIDmode,
6296 + gen_rtvec (1, const0_rtx),
6297 + UNSPEC_FORCE_MINIPOOL));
6298 + result = true;
6299 + }
6300 + }
6301 + }
6302 + return result;
6303 +}
6304 +
6305 +
6306 +static int
6307 +avr32_insn_is_cast (rtx insn)
6308 +{
6309 +
6310 + if (NONJUMP_INSN_P (insn)
6311 + && GET_CODE (PATTERN (insn)) == SET
6312 + && (GET_CODE (SET_SRC (PATTERN (insn))) == ZERO_EXTEND
6313 + || GET_CODE (SET_SRC (PATTERN (insn))) == SIGN_EXTEND)
6314 + && REG_P (XEXP (SET_SRC (PATTERN (insn)), 0))
6315 + && REG_P (SET_DEST (PATTERN (insn))))
6316 + return true;
6317 + return false;
6318 +}
6319 +
6320 +/*
6321 + Replace all occurances of reg FROM with reg TO in X */
6322 +
6323 +rtx
6324 +avr32_replace_reg (rtx x, rtx from, rtx to)
6325 +{
6326 + int i, j;
6327 + const char *fmt;
6328 +
6329 + gcc_assert ( REG_P (from) && REG_P (to) );
6330 +
6331 + /* Allow this function to make replacements in EXPR_LISTs. */
6332 + if (x == 0)
6333 + return 0;
6334 +
6335 + if (rtx_equal_p (x, from))
6336 + return to;
6337 +
6338 + if (GET_CODE (x) == SUBREG)
6339 + {
6340 + rtx new = avr32_replace_reg (SUBREG_REG (x), from, to);
6341 +
6342 + if (GET_CODE (new) == CONST_INT)
6343 + {
6344 + x = simplify_subreg (GET_MODE (x), new,
6345 + GET_MODE (SUBREG_REG (x)),
6346 + SUBREG_BYTE (x));
6347 + gcc_assert (x);
6348 + }
6349 + else
6350 + SUBREG_REG (x) = new;
6351 +
6352 + return x;
6353 + }
6354 + else if (GET_CODE (x) == ZERO_EXTEND)
6355 + {
6356 + rtx new = avr32_replace_reg (XEXP (x, 0), from, to);
6357 +
6358 + if (GET_CODE (new) == CONST_INT)
6359 + {
6360 + x = simplify_unary_operation (ZERO_EXTEND, GET_MODE (x),
6361 + new, GET_MODE (XEXP (x, 0)));
6362 + gcc_assert (x);
6363 + }
6364 + else
6365 + XEXP (x, 0) = new;
6366 +
6367 + return x;
6368 + }
6369 +
6370 + fmt = GET_RTX_FORMAT (GET_CODE (x));
6371 + for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
6372 + {
6373 + if (fmt[i] == 'e')
6374 + XEXP (x, i) = avr32_replace_reg (XEXP (x, i), from, to);
6375 + else if (fmt[i] == 'E')
6376 + for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6377 + XVECEXP (x, i, j) = avr32_replace_reg (XVECEXP (x, i, j), from, to);
6378 + }
6379 +
6380 + return x;
6381 +}
6382 +
6383 +
6384 +/* FIXME: The level of nesting in this function is way too deep. It needs to be
6385 + torn apart. */
6386 +static void
6387 +avr32_reorg_optimization (void)
6388 +{
6389 + rtx first = get_first_nonnote_insn ();
6390 + rtx insn;
6391 +
6392 + if (TARGET_MD_REORG_OPTIMIZATION && (optimize_size || (optimize > 0)))
6393 + {
6394 +
6395 + /* Scan through all insns looking for cast operations. */
6396 + if (dump_file)
6397 + {
6398 + fprintf (dump_file, ";; Deleting redundant cast operations:\n");
6399 + }
6400 + for (insn = first; insn; insn = NEXT_INSN (insn))
6401 + {
6402 + rtx reg, src_reg, scan;
6403 + enum machine_mode mode;
6404 + int unused_cast;
6405 + rtx label_ref;
6406 +
6407 + if (avr32_insn_is_cast (insn)
6408 + && (GET_MODE (XEXP (SET_SRC (PATTERN (insn)), 0)) == QImode
6409 + || GET_MODE (XEXP (SET_SRC (PATTERN (insn)), 0)) == HImode))
6410 + {
6411 + mode = GET_MODE (XEXP (SET_SRC (PATTERN (insn)), 0));
6412 + reg = SET_DEST (PATTERN (insn));
6413 + src_reg = XEXP (SET_SRC (PATTERN (insn)), 0);
6414 + }
6415 + else
6416 + {
6417 + continue;
6418 + }
6419 +
6420 + unused_cast = false;
6421 + label_ref = NULL_RTX;
6422 + for (scan = NEXT_INSN (insn); scan; scan = NEXT_INSN (scan))
6423 + {
6424 + /* Check if we have reached the destination of a simple
6425 + conditional jump which we have already scanned past. If so,
6426 + we can safely continue scanning. */
6427 + if (LABEL_P (scan) && label_ref != NULL_RTX)
6428 + {
6429 + if (CODE_LABEL_NUMBER (scan) ==
6430 + CODE_LABEL_NUMBER (XEXP (label_ref, 0)))
6431 + label_ref = NULL_RTX;
6432 + else
6433 + break;
6434 + }
6435 +
6436 + if (!INSN_P (scan))
6437 + continue;
6438 +
6439 + /* For conditional jumps we can manage to keep on scanning if
6440 + we meet the destination label later on before any new jump
6441 + insns occure. */
6442 + if (GET_CODE (scan) == JUMP_INSN)
6443 + {
6444 + if (any_condjump_p (scan) && label_ref == NULL_RTX)
6445 + label_ref = condjump_label (scan);
6446 + else
6447 + break;
6448 + }
6449 +
6450 + /* Check if we have a call and the register is used as an argument. */
6451 + if (CALL_P (scan)
6452 + && find_reg_fusage (scan, USE, reg) )
6453 + break;
6454 +
6455 + if (!reg_mentioned_p (reg, PATTERN (scan)))
6456 + continue;
6457 +
6458 + /* Check if casted register is used in this insn */
6459 + if ((regno_use_in (REGNO (reg), PATTERN (scan)) != NULL_RTX)
6460 + && (GET_MODE (regno_use_in (REGNO (reg), PATTERN (scan))) ==
6461 + GET_MODE (reg)))
6462 + {
6463 + /* If not used in the source to the set or in a memory
6464 + expression in the destiantion then the register is used
6465 + as a destination and is really dead. */
6466 + if (single_set (scan)
6467 + && GET_CODE (PATTERN (scan)) == SET
6468 + && REG_P (SET_DEST (PATTERN (scan)))
6469 + && !regno_use_in (REGNO (reg), SET_SRC (PATTERN (scan)))
6470 + && label_ref == NULL_RTX)
6471 + {
6472 + unused_cast = true;
6473 + }
6474 + break;
6475 + }
6476 +
6477 + /* Check if register is dead or set in this insn */
6478 + if (dead_or_set_p (scan, reg))
6479 + {
6480 + unused_cast = true;
6481 + break;
6482 + }
6483 + }
6484 +
6485 + /* Check if we have unresolved conditional jumps */
6486 + if (label_ref != NULL_RTX)
6487 + continue;
6488 +
6489 + if (unused_cast)
6490 + {
6491 + if (REGNO (reg) == REGNO (XEXP (SET_SRC (PATTERN (insn)), 0)))
6492 + {
6493 + /* One operand cast, safe to delete */
6494 + if (dump_file)
6495 + {
6496 + fprintf (dump_file,
6497 + ";; INSN %i removed, casted register %i value not used.\n",
6498 + INSN_UID (insn), REGNO (reg));
6499 + }
6500 + SET_INSN_DELETED (insn);
6501 + /* Force the instruction to be recognized again */
6502 + INSN_CODE (insn) = -1;
6503 + }
6504 + else
6505 + {
6506 + /* Two operand cast, which really could be substituted with
6507 + a move, if the source register is dead after the cast
6508 + insn and then the insn which sets the source register
6509 + could instead directly set the destination register for
6510 + the cast. As long as there are no insns in between which
6511 + uses the register. */
6512 + rtx link = NULL_RTX;
6513 + rtx set;
6514 + rtx src_reg = XEXP (SET_SRC (PATTERN (insn)), 0);
6515 + unused_cast = false;
6516 +
6517 + if (!find_reg_note (insn, REG_DEAD, src_reg))
6518 + continue;
6519 +
6520 + /* Search for the insn which sets the source register */
6521 + for (scan = PREV_INSN (insn);
6522 + scan && GET_CODE (scan) != CODE_LABEL;
6523 + scan = PREV_INSN (scan))
6524 + {
6525 + if (! INSN_P (scan))
6526 + continue;
6527 +
6528 + set = single_set (scan);
6529 + if (set && rtx_equal_p (src_reg, SET_DEST (set)))
6530 + {
6531 + link = scan;
6532 + break;
6533 + }
6534 +
6535 + }
6536 +
6537 +
6538 + /* Found no link or link is a call insn where we can not
6539 + change the destination register */
6540 + if (link == NULL_RTX || CALL_P (link))
6541 + continue;
6542 +
6543 + /* Scan through all insn between link and insn */
6544 + for (scan = NEXT_INSN (link); scan; scan = NEXT_INSN (scan))
6545 + {
6546 + /* Don't try to trace forward past a CODE_LABEL if we
6547 + haven't seen INSN yet. Ordinarily, we will only
6548 + find the setting insn in LOG_LINKS if it is in the
6549 + same basic block. However, cross-jumping can insert
6550 + code labels in between the load and the call, and
6551 + can result in situations where a single call insn
6552 + may have two targets depending on where we came
6553 + from. */
6554 +
6555 + if (GET_CODE (scan) == CODE_LABEL)
6556 + break;
6557 +
6558 + if (!INSN_P (scan))
6559 + continue;
6560 +
6561 + /* Don't try to trace forward past a JUMP. To optimize
6562 + safely, we would have to check that all the
6563 + instructions at the jump destination did not use REG.
6564 + */
6565 +
6566 + if (GET_CODE (scan) == JUMP_INSN)
6567 + {
6568 + break;
6569 + }
6570 +
6571 + if (!reg_mentioned_p (src_reg, PATTERN (scan)))
6572 + continue;
6573 +
6574 + /* We have reached the cast insn */
6575 + if (scan == insn)
6576 + {
6577 + /* We can remove cast and replace the destination
6578 + register of the link insn with the destination
6579 + of the cast */
6580 + if (dump_file)
6581 + {
6582 + fprintf (dump_file,
6583 + ";; INSN %i removed, casted value unused. "
6584 + "Destination of removed cast operation: register %i, folded into INSN %i.\n",
6585 + INSN_UID (insn), REGNO (reg),
6586 + INSN_UID (link));
6587 + }
6588 + /* Update link insn */
6589 + SET_DEST (PATTERN (link)) =
6590 + gen_rtx_REG (mode, REGNO (reg));
6591 + /* Force the instruction to be recognized again */
6592 + INSN_CODE (link) = -1;
6593 +
6594 + /* Delete insn */
6595 + SET_INSN_DELETED (insn);
6596 + /* Force the instruction to be recognized again */
6597 + INSN_CODE (insn) = -1;
6598 + break;
6599 + }
6600 + }
6601 + }
6602 + }
6603 + }
6604 + }
6605 +
6606 + if (TARGET_MD_REORG_OPTIMIZATION && (optimize_size || (optimize > 0)))
6607 + {
6608 +
6609 + /* Scan through all insns looking for shifted add operations */
6610 + if (dump_file)
6611 + {
6612 + fprintf (dump_file,
6613 + ";; Deleting redundant shifted add operations:\n");
6614 + }
6615 + for (insn = first; insn; insn = NEXT_INSN (insn))
6616 + {
6617 + rtx reg, mem_expr, scan, op0, op1;
6618 + int add_only_used_as_pointer;
6619 +
6620 + if (INSN_P (insn)
6621 + && GET_CODE (PATTERN (insn)) == SET
6622 + && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
6623 + && (GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 0)) == MULT
6624 + || GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 0)) == ASHIFT)
6625 + && GET_CODE (XEXP (XEXP (SET_SRC (PATTERN (insn)), 0), 1)) ==
6626 + CONST_INT && REG_P (SET_DEST (PATTERN (insn)))
6627 + && REG_P (XEXP (SET_SRC (PATTERN (insn)), 1))
6628 + && REG_P (XEXP (XEXP (SET_SRC (PATTERN (insn)), 0), 0)))
6629 + {
6630 + reg = SET_DEST (PATTERN (insn));
6631 + mem_expr = SET_SRC (PATTERN (insn));
6632 + op0 = XEXP (XEXP (mem_expr, 0), 0);
6633 + op1 = XEXP (mem_expr, 1);
6634 + }
6635 + else
6636 + {
6637 + continue;
6638 + }
6639 +
6640 + /* Scan forward the check if the result of the shifted add
6641 + operation is only used as an address in memory operations and
6642 + that the operands to the shifted add are not clobbered. */
6643 + add_only_used_as_pointer = false;
6644 + for (scan = NEXT_INSN (insn); scan; scan = NEXT_INSN (scan))
6645 + {
6646 + if (!INSN_P (scan))
6647 + continue;
6648 +
6649 + /* Don't try to trace forward past a JUMP or CALL. To optimize
6650 + safely, we would have to check that all the instructions at
6651 + the jump destination did not use REG. */
6652 +
6653 + if (GET_CODE (scan) == JUMP_INSN)
6654 + {
6655 + break;
6656 + }
6657 +
6658 + /* If used in a call insn then we cannot optimize it away */
6659 + if (CALL_P (scan) && find_regno_fusage (scan, USE, REGNO (reg)))
6660 + break;
6661 +
6662 + /* If any of the operands of the shifted add are clobbered we
6663 + cannot optimize the shifted adda away */
6664 + if ((reg_set_p (op0, scan) && (REGNO (op0) != REGNO (reg)))
6665 + || (reg_set_p (op1, scan) && (REGNO (op1) != REGNO (reg))))
6666 + break;
6667 +
6668 + if (!reg_mentioned_p (reg, PATTERN (scan)))
6669 + continue;
6670 +
6671 + /* If used any other place than as a pointer or as the
6672 + destination register we failed */
6673 + if (!(single_set (scan)
6674 + && GET_CODE (PATTERN (scan)) == SET
6675 + && ((MEM_P (SET_DEST (PATTERN (scan)))
6676 + && REG_P (XEXP (SET_DEST (PATTERN (scan)), 0))
6677 + && REGNO (XEXP (SET_DEST (PATTERN (scan)), 0)) == REGNO (reg))
6678 + || (MEM_P (SET_SRC (PATTERN (scan)))
6679 + && REG_P (XEXP (SET_SRC (PATTERN (scan)), 0))
6680 + && REGNO (XEXP
6681 + (SET_SRC (PATTERN (scan)), 0)) == REGNO (reg))))
6682 + && !(GET_CODE (PATTERN (scan)) == SET
6683 + && REG_P (SET_DEST (PATTERN (scan)))
6684 + && !regno_use_in (REGNO (reg),
6685 + SET_SRC (PATTERN (scan)))))
6686 + break;
6687 +
6688 + /* We cannot replace the pointer in TImode insns
6689 + as these has a differene addressing mode than the other
6690 + memory insns. */
6691 + if ( GET_MODE (SET_DEST (PATTERN (scan))) == TImode )
6692 + break;
6693 +
6694 + /* Check if register is dead or set in this insn */
6695 + if (dead_or_set_p (scan, reg))
6696 + {
6697 + add_only_used_as_pointer = true;
6698 + break;
6699 + }
6700 + }
6701 +
6702 + if (add_only_used_as_pointer)
6703 + {
6704 + /* Lets delete the add insn and replace all memory references
6705 + which uses the pointer with the full expression. */
6706 + if (dump_file)
6707 + {
6708 + fprintf (dump_file,
6709 + ";; Deleting INSN %i since address expression can be folded into all "
6710 + "memory references using this expression\n",
6711 + INSN_UID (insn));
6712 + }
6713 + SET_INSN_DELETED (insn);
6714 + /* Force the instruction to be recognized again */
6715 + INSN_CODE (insn) = -1;
6716 +
6717 + for (scan = NEXT_INSN (insn); scan; scan = NEXT_INSN (scan))
6718 + {
6719 + if (!INSN_P (scan))
6720 + continue;
6721 +
6722 + if (!reg_mentioned_p (reg, PATTERN (scan)))
6723 + continue;
6724 +
6725 + /* If used any other place than as a pointer or as the
6726 + destination register we failed */
6727 + if ((single_set (scan)
6728 + && GET_CODE (PATTERN (scan)) == SET
6729 + && ((MEM_P (SET_DEST (PATTERN (scan)))
6730 + && REG_P (XEXP (SET_DEST (PATTERN (scan)), 0))
6731 + && REGNO (XEXP (SET_DEST (PATTERN (scan)), 0)) ==
6732 + REGNO (reg)) || (MEM_P (SET_SRC (PATTERN (scan)))
6733 + &&
6734 + REG_P (XEXP
6735 + (SET_SRC (PATTERN (scan)),
6736 + 0))
6737 + &&
6738 + REGNO (XEXP
6739 + (SET_SRC (PATTERN (scan)),
6740 + 0)) == REGNO (reg)))))
6741 + {
6742 + if (dump_file)
6743 + {
6744 + fprintf (dump_file,
6745 + ";; Register %i replaced by indexed address in INSN %i\n",
6746 + REGNO (reg), INSN_UID (scan));
6747 + }
6748 + if (MEM_P (SET_DEST (PATTERN (scan))))
6749 + XEXP (SET_DEST (PATTERN (scan)), 0) = mem_expr;
6750 + else
6751 + XEXP (SET_SRC (PATTERN (scan)), 0) = mem_expr;
6752 + }
6753 +
6754 + /* Check if register is dead or set in this insn */
6755 + if (dead_or_set_p (scan, reg))
6756 + {
6757 + break;
6758 + }
6759 +
6760 + }
6761 + }
6762 + }
6763 + }
6764 +
6765 +
6766 + if (TARGET_MD_REORG_OPTIMIZATION && (optimize_size || (optimize > 0)))
6767 + {
6768 +
6769 + /* Scan through all insns looking for conditional register to
6770 + register move operations */
6771 + if (dump_file)
6772 + {
6773 + fprintf (dump_file,
6774 + ";; Folding redundant conditional move operations:\n");
6775 + }
6776 + for (insn = first; insn; insn = next_nonnote_insn (insn))
6777 + {
6778 + rtx src_reg, dst_reg, scan, test;
6779 +
6780 + if (INSN_P (insn)
6781 + && GET_CODE (PATTERN (insn)) == COND_EXEC
6782 + && GET_CODE (COND_EXEC_CODE (PATTERN (insn))) == SET
6783 + && REG_P (SET_SRC (COND_EXEC_CODE (PATTERN (insn))))
6784 + && REG_P (SET_DEST (COND_EXEC_CODE (PATTERN (insn))))
6785 + && find_reg_note (insn, REG_DEAD, SET_SRC (COND_EXEC_CODE (PATTERN (insn)))))
6786 + {
6787 + src_reg = SET_SRC (COND_EXEC_CODE (PATTERN (insn)));
6788 + dst_reg = SET_DEST (COND_EXEC_CODE (PATTERN (insn)));
6789 + test = COND_EXEC_TEST (PATTERN (insn));
6790 + }
6791 + else
6792 + {
6793 + continue;
6794 + }
6795 +
6796 + /* Scan backward through the rest of insns in this if-then or if-else
6797 + block and check if we can fold the move into another of the conditional
6798 + insns in the same block. */
6799 + scan = prev_nonnote_insn (insn);
6800 + while (INSN_P (scan)
6801 + && GET_CODE (PATTERN (scan)) == COND_EXEC
6802 + && rtx_equal_p (COND_EXEC_TEST (PATTERN (scan)), test))
6803 + {
6804 + rtx pattern = COND_EXEC_CODE (PATTERN (scan));
6805 + if ( GET_CODE (pattern) == PARALLEL )
6806 + pattern = XVECEXP (pattern, 0, 0);
6807 +
6808 + if ( reg_set_p (src_reg, pattern) )
6809 + {
6810 + /* Fold in the destination register for the cond. move
6811 + into this insn. */
6812 + SET_DEST (pattern) = dst_reg;
6813 + if (dump_file)
6814 + {
6815 + fprintf (dump_file,
6816 + ";; Deleting INSN %i since this operation can be folded into INSN %i\n",
6817 + INSN_UID (insn), INSN_UID (scan));
6818 + }
6819 +
6820 + /* Scan and check if any of the insns in between uses the src_reg. We
6821 + must then replace it with the dst_reg. */
6822 + while ( (scan = next_nonnote_insn (scan)) != insn ){
6823 + avr32_replace_reg (scan, src_reg, dst_reg);
6824 + }
6825 + /* Delete the insn. */
6826 + SET_INSN_DELETED (insn);
6827 +
6828 + /* Force the instruction to be recognized again */
6829 + INSN_CODE (insn) = -1;
6830 + break;
6831 + }
6832 +
6833 + /* If the destination register is used but not set in this insn
6834 + we cannot fold. */
6835 + if ( reg_mentioned_p (dst_reg, pattern) )
6836 + break;
6837 +
6838 + scan = prev_nonnote_insn (scan);
6839 + }
6840 + }
6841 + }
6842 +
6843 +}
6844 +
6845 +/* Exported to toplev.c.
6846 +
6847 + Do a final pass over the function, just before delayed branch
6848 + scheduling. */
6849 +
6850 +static void
6851 +avr32_reorg (void)
6852 +{
6853 + rtx insn;
6854 + HOST_WIDE_INT address = 0;
6855 + Mfix *fix;
6856 +
6857 + minipool_fix_head = minipool_fix_tail = NULL;
6858 +
6859 + /* The first insn must always be a note, or the code below won't scan it
6860 + properly. */
6861 + insn = get_insns ();
6862 + if (GET_CODE (insn) != NOTE)
6863 + abort ();
6864 +
6865 + /* Scan all the insns and record the operands that will need fixing. */
6866 + for (insn = next_nonnote_insn (insn); insn; insn = next_nonnote_insn (insn))
6867 + {
6868 + if (GET_CODE (insn) == BARRIER)
6869 + push_minipool_barrier (insn, address);
6870 + else if (INSN_P (insn))
6871 + {
6872 + rtx table;
6873 +
6874 + note_invalid_constants (insn, address, true);
6875 + address += get_attr_length (insn);
6876 +
6877 + /* If the insn is a vector jump, add the size of the table and skip
6878 + the table. */
6879 + if ((table = is_jump_table (insn)) != NULL)
6880 + {
6881 + address += get_jump_table_size (table);
6882 + insn = table;
6883 + }
6884 + }
6885 + }
6886 +
6887 + fix = minipool_fix_head;
6888 +
6889 + /* Now scan the fixups and perform the required changes. */
6890 + while (fix)
6891 + {
6892 + Mfix *ftmp;
6893 + Mfix *fdel;
6894 + Mfix *last_added_fix;
6895 + Mfix *last_barrier = NULL;
6896 + Mfix *this_fix;
6897 +
6898 + /* Skip any further barriers before the next fix. */
6899 + while (fix && GET_CODE (fix->insn) == BARRIER)
6900 + fix = fix->next;
6901 +
6902 + /* No more fixes. */
6903 + if (fix == NULL)
6904 + break;
6905 +
6906 + last_added_fix = NULL;
6907 +
6908 + for (ftmp = fix; ftmp; ftmp = ftmp->next)
6909 + {
6910 + if (GET_CODE (ftmp->insn) == BARRIER)
6911 + {
6912 + if (ftmp->address >= minipool_vector_head->max_address)
6913 + break;
6914 +
6915 + last_barrier = ftmp;
6916 + }
6917 + else if ((ftmp->minipool = add_minipool_forward_ref (ftmp)) == NULL)
6918 + break;
6919 +
6920 + last_added_fix = ftmp; /* Keep track of the last fix added.
6921 + */
6922 + }
6923 +
6924 + /* If we found a barrier, drop back to that; any fixes that we could
6925 + have reached but come after the barrier will now go in the next
6926 + mini-pool. */
6927 + if (last_barrier != NULL)
6928 + {
6929 + /* Reduce the refcount for those fixes that won't go into this pool
6930 + after all. */
6931 + for (fdel = last_barrier->next;
6932 + fdel && fdel != ftmp; fdel = fdel->next)
6933 + {
6934 + fdel->minipool->refcount--;
6935 + fdel->minipool = NULL;
6936 + }
6937 +
6938 + ftmp = last_barrier;
6939 + }
6940 + else
6941 + {
6942 + /* ftmp is first fix that we can't fit into this pool and there no
6943 + natural barriers that we could use. Insert a new barrier in the
6944 + code somewhere between the previous fix and this one, and
6945 + arrange to jump around it. */
6946 + HOST_WIDE_INT max_address;
6947 +
6948 + /* The last item on the list of fixes must be a barrier, so we can
6949 + never run off the end of the list of fixes without last_barrier
6950 + being set. */
6951 + if (ftmp == NULL)
6952 + abort ();
6953 +
6954 + max_address = minipool_vector_head->max_address;
6955 + /* Check that there isn't another fix that is in range that we
6956 + couldn't fit into this pool because the pool was already too
6957 + large: we need to put the pool before such an instruction. */
6958 + if (ftmp->address < max_address)
6959 + max_address = ftmp->address;
6960 +
6961 + last_barrier = create_fix_barrier (last_added_fix, max_address);
6962 + }
6963 +
6964 + assign_minipool_offsets (last_barrier);
6965 +
6966 + while (ftmp)
6967 + {
6968 + if (GET_CODE (ftmp->insn) != BARRIER
6969 + && ((ftmp->minipool = add_minipool_backward_ref (ftmp))
6970 + == NULL))
6971 + break;
6972 +
6973 + ftmp = ftmp->next;
6974 + }
6975 +
6976 + /* Scan over the fixes we have identified for this pool, fixing them up
6977 + and adding the constants to the pool itself. */
6978 + for (this_fix = fix; this_fix && ftmp != this_fix;
6979 + this_fix = this_fix->next)
6980 + if (GET_CODE (this_fix->insn) != BARRIER
6981 + /* Do nothing for entries present just to force the insertion of
6982 + a minipool. */
6983 + && !IS_FORCE_MINIPOOL (this_fix->value))
6984 + {
6985 + rtx addr = plus_constant (gen_rtx_LABEL_REF (VOIDmode,
6986 + minipool_vector_label),
6987 + this_fix->minipool->offset);
6988 + *this_fix->loc = gen_rtx_MEM (this_fix->mode, addr);
6989 + }
6990 +
6991 + dump_minipool (last_barrier->insn);
6992 + fix = ftmp;
6993 + }
6994 +
6995 + /* Free the minipool memory. */
6996 + obstack_free (&minipool_obstack, minipool_startobj);
6997 +
6998 + avr32_reorg_optimization ();
6999 +}
7000 +
7001 +
7002 +/*
7003 + Hook for doing some final scanning of instructions. Does nothing yet...*/
7004 +void
7005 +avr32_final_prescan_insn (rtx insn ATTRIBUTE_UNUSED,
7006 + rtx * opvec ATTRIBUTE_UNUSED,
7007 + int noperands ATTRIBUTE_UNUSED)
7008 +{
7009 + return;
7010 +}
7011 +
7012 +
7013 +/* Function for changing the condition on the next instruction,
7014 + should be used when emmiting compare instructions and
7015 + the condition of the next instruction needs to change.
7016 +*/
7017 +int
7018 +set_next_insn_cond (rtx cur_insn, rtx new_cond)
7019 +{
7020 + rtx next_insn = next_nonnote_insn (cur_insn);
7021 + if ((next_insn != NULL_RTX)
7022 + && (INSN_P (next_insn)))
7023 + {
7024 + if ((GET_CODE (PATTERN (next_insn)) == SET)
7025 + && (GET_CODE (SET_SRC (PATTERN (next_insn))) == IF_THEN_ELSE))
7026 + {
7027 + /* Branch instructions */
7028 + XEXP (SET_SRC (PATTERN (next_insn)), 0) = new_cond;
7029 + /* Force the instruction to be recognized again */
7030 + INSN_CODE (next_insn) = -1;
7031 + return TRUE;
7032 + }
7033 + else if ((GET_CODE (PATTERN (next_insn)) == SET)
7034 + && avr32_comparison_operator (SET_SRC (PATTERN (next_insn)),
7035 + GET_MODE (SET_SRC (PATTERN (next_insn)))))
7036 + {
7037 + /* scc with no compare */
7038 + SET_SRC (PATTERN (next_insn)) = new_cond;
7039 + /* Force the instruction to be recognized again */
7040 + INSN_CODE (next_insn) = -1;
7041 + return TRUE;
7042 + }
7043 + else if (GET_CODE (PATTERN (next_insn)) == COND_EXEC)
7044 + {
7045 + if ( GET_CODE (new_cond) == UNSPEC )
7046 + {
7047 + COND_EXEC_TEST (PATTERN (next_insn)) =
7048 + gen_rtx_UNSPEC (CCmode,
7049 + gen_rtvec (2,
7050 + XEXP (COND_EXEC_TEST (PATTERN (next_insn)), 0),
7051 + XEXP (COND_EXEC_TEST (PATTERN (next_insn)), 1)),
7052 + XINT (new_cond, 1));
7053 + }
7054 + else
7055 + {
7056 + PUT_CODE(COND_EXEC_TEST (PATTERN (next_insn)), GET_CODE(new_cond));
7057 + }
7058 + }
7059 + }
7060 +
7061 + return FALSE;
7062 +}
7063 +
7064 +/* Function for obtaining the condition for the next instruction
7065 + after cur_insn.
7066 +*/
7067 +rtx
7068 +get_next_insn_cond (rtx cur_insn)
7069 +{
7070 + rtx next_insn = next_nonnote_insn (cur_insn);
7071 + rtx cond = NULL_RTX;
7072 + if (next_insn != NULL_RTX
7073 + && INSN_P (next_insn))
7074 + {
7075 + if ((GET_CODE (PATTERN (next_insn)) == SET)
7076 + && (GET_CODE (SET_SRC (PATTERN (next_insn))) == IF_THEN_ELSE))
7077 + {
7078 + /* Branch and cond if then else instructions */
7079 + cond = XEXP (SET_SRC (PATTERN (next_insn)), 0);
7080 + }
7081 + else if ((GET_CODE (PATTERN (next_insn)) == SET)
7082 + && avr32_comparison_operator (SET_SRC (PATTERN (next_insn)),
7083 + GET_MODE (SET_SRC (PATTERN (next_insn)))))
7084 + {
7085 + /* scc with no compare */
7086 + cond = SET_SRC (PATTERN (next_insn));
7087 + }
7088 + else if (GET_CODE (PATTERN (next_insn)) == COND_EXEC)
7089 + {
7090 + cond = COND_EXEC_TEST (PATTERN (next_insn));
7091 + }
7092 + }
7093 + return cond;
7094 +}
7095 +
7096 +
7097 +/* Check if the next insn is a conditional insn that will emit a compare
7098 + for itself.
7099 +*/
7100 +rtx
7101 +next_insn_emits_cmp (rtx cur_insn)
7102 +{
7103 + rtx next_insn = next_nonnote_insn (cur_insn);
7104 + rtx cond = NULL_RTX;
7105 + if (next_insn != NULL_RTX
7106 + && INSN_P (next_insn))
7107 + {
7108 + if ( ((GET_CODE (PATTERN (next_insn)) == SET)
7109 + && (GET_CODE (SET_SRC (PATTERN (next_insn))) == IF_THEN_ELSE)
7110 + && (XEXP (XEXP (SET_SRC (PATTERN (next_insn)), 0),0) != cc0_rtx))
7111 + || GET_CODE (PATTERN (next_insn)) == COND_EXEC )
7112 + return TRUE;
7113 + }
7114 + return FALSE;
7115 +}
7116 +
7117 +
7118 +rtx
7119 +avr32_output_cmp (rtx cond, enum machine_mode mode, rtx op0, rtx op1)
7120 +{
7121 +
7122 + rtx new_cond = NULL_RTX;
7123 + rtx ops[2];
7124 + rtx compare_pattern;
7125 + ops[0] = op0;
7126 + ops[1] = op1;
7127 +
7128 + if ( GET_CODE (op0) == AND )
7129 + compare_pattern = op0;
7130 + else
7131 + compare_pattern = gen_rtx_COMPARE (mode, op0, op1);
7132 +
7133 + new_cond = is_compare_redundant (compare_pattern, cond);
7134 +
7135 + if (new_cond != NULL_RTX)
7136 + return new_cond;
7137 +
7138 + /* Check if we are inserting a bit-load instead of a compare. */
7139 + if ( GET_CODE (op0) == AND )
7140 + {
7141 + ops[0] = XEXP (op0, 0);
7142 + ops[1] = XEXP (op0, 1);
7143 + output_asm_insn ("bld\t%0, %p1", ops);
7144 + return cond;
7145 + }
7146 +
7147 + /* Insert compare */
7148 + switch (mode)
7149 + {
7150 + case QImode:
7151 + output_asm_insn ("cp.b\t%0, %1", ops);
7152 + break;
7153 + case HImode:
7154 + output_asm_insn ("cp.h\t%0, %1", ops);
7155 + break;
7156 + case SImode:
7157 + output_asm_insn ("cp.w\t%0, %1", ops);
7158 + break;
7159 + case DImode:
7160 + if (GET_CODE (op1) != REG)
7161 + output_asm_insn ("cp.w\t%0, %1\ncpc\t%m0", ops);
7162 + else
7163 + output_asm_insn ("cp.w\t%0, %1\ncpc\t%m0, %m1", ops);
7164 + break;
7165 + default:
7166 + internal_error ("Unknown comparison mode");
7167 + break;
7168 + }
7169 +
7170 + return cond;
7171 +}
7172 +
7173 +int
7174 +avr32_load_multiple_operation (rtx op,
7175 + enum machine_mode mode ATTRIBUTE_UNUSED)
7176 +{
7177 + int count = XVECLEN (op, 0);
7178 + unsigned int dest_regno;
7179 + rtx src_addr;
7180 + rtx elt;
7181 + int i = 1, base = 0;
7182 +
7183 + if (count <= 1 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
7184 + return 0;
7185 +
7186 + /* Check to see if this might be a write-back. */
7187 + if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
7188 + {
7189 + i++;
7190 + base = 1;
7191 +
7192 + /* Now check it more carefully. */
7193 + if (GET_CODE (SET_DEST (elt)) != REG
7194 + || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
7195 + || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
7196 + || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 1) * 4)
7197 + return 0;
7198 + }
7199 +
7200 + /* Perform a quick check so we don't blow up below. */
7201 + if (count <= 1
7202 + || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
7203 + || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != REG
7204 + || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != UNSPEC)
7205 + return 0;
7206 +
7207 + dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, i - 1)));
7208 + src_addr = XEXP (SET_SRC (XVECEXP (op, 0, i - 1)), 0);
7209 +
7210 + for (; i < count; i++)
7211 + {
7212 + elt = XVECEXP (op, 0, i);
7213 +
7214 + if (GET_CODE (elt) != SET
7215 + || GET_CODE (SET_DEST (elt)) != REG
7216 + || GET_MODE (SET_DEST (elt)) != SImode
7217 + || GET_CODE (SET_SRC (elt)) != UNSPEC)
7218 + return 0;
7219 + }
7220 +
7221 + return 1;
7222 +}
7223 +
7224 +int
7225 +avr32_store_multiple_operation (rtx op,
7226 + enum machine_mode mode ATTRIBUTE_UNUSED)
7227 +{
7228 + int count = XVECLEN (op, 0);
7229 + int src_regno;
7230 + rtx dest_addr;
7231 + rtx elt;
7232 + int i = 1;
7233 +
7234 + if (count <= 1 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
7235 + return 0;
7236 +
7237 + /* Perform a quick check so we don't blow up below. */
7238 + if (count <= i
7239 + || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
7240 + || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != MEM
7241 + || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != UNSPEC)
7242 + return 0;
7243 +
7244 + src_regno = REGNO (SET_SRC (XVECEXP (op, 0, i - 1)));
7245 + dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, i - 1)), 0);
7246 +
7247 + for (; i < count; i++)
7248 + {
7249 + elt = XVECEXP (op, 0, i);
7250 +
7251 + if (GET_CODE (elt) != SET
7252 + || GET_CODE (SET_DEST (elt)) != MEM
7253 + || GET_MODE (SET_DEST (elt)) != SImode
7254 + || GET_CODE (SET_SRC (elt)) != UNSPEC)
7255 + return 0;
7256 + }
7257 +
7258 + return 1;
7259 +}
7260 +
7261 +int
7262 +avr32_valid_macmac_bypass (rtx insn_out, rtx insn_in)
7263 +{
7264 + /* Check if they use the same accumulator */
7265 + if (rtx_equal_p
7266 + (SET_DEST (PATTERN (insn_out)), SET_DEST (PATTERN (insn_in))))
7267 + {
7268 + return TRUE;
7269 + }
7270 +
7271 + return FALSE;
7272 +}
7273 +
7274 +int
7275 +avr32_valid_mulmac_bypass (rtx insn_out, rtx insn_in)
7276 +{
7277 + /*
7278 + Check if the mul instruction produces the accumulator for the mac
7279 + instruction. */
7280 + if (rtx_equal_p
7281 + (SET_DEST (PATTERN (insn_out)), SET_DEST (PATTERN (insn_in))))
7282 + {
7283 + return TRUE;
7284 + }
7285 + return FALSE;
7286 +}
7287 +
7288 +int
7289 +avr32_store_bypass (rtx insn_out, rtx insn_in)
7290 +{
7291 + /* Only valid bypass if the output result is used as an src in the store
7292 + instruction, NOT if used as a pointer or base. */
7293 + if (rtx_equal_p
7294 + (SET_DEST (PATTERN (insn_out)), SET_SRC (PATTERN (insn_in))))
7295 + {
7296 + return TRUE;
7297 + }
7298 +
7299 + return FALSE;
7300 +}
7301 +
7302 +int
7303 +avr32_mul_waw_bypass (rtx insn_out, rtx insn_in)
7304 +{
7305 + /* Check if the register holding the result from the mul instruction is
7306 + used as a result register in the input instruction. */
7307 + if (rtx_equal_p
7308 + (SET_DEST (PATTERN (insn_out)), SET_DEST (PATTERN (insn_in))))
7309 + {
7310 + return TRUE;
7311 + }
7312 +
7313 + return FALSE;
7314 +}
7315 +
7316 +int
7317 +avr32_valid_load_double_bypass (rtx insn_out, rtx insn_in)
7318 +{
7319 + /* Check if the first loaded word in insn_out is used in insn_in. */
7320 + rtx dst_reg;
7321 + rtx second_loaded_reg;
7322 +
7323 + /* If this is a double alu operation then the bypass is not valid */
7324 + if ((get_attr_type (insn_in) == TYPE_ALU
7325 + || get_attr_type (insn_in) == TYPE_ALU2)
7326 + && (GET_MODE_SIZE (GET_MODE (SET_DEST (PATTERN (insn_out)))) > 4))
7327 + return FALSE;
7328 +
7329 + /* Get the destination register in the load */
7330 + if (!REG_P (SET_DEST (PATTERN (insn_out))))
7331 + return FALSE;
7332 +
7333 + dst_reg = SET_DEST (PATTERN (insn_out));
7334 + second_loaded_reg = gen_rtx_REG (SImode, REGNO (dst_reg) + 1);
7335 +
7336 + if (!reg_mentioned_p (second_loaded_reg, PATTERN (insn_in)))
7337 + return TRUE;
7338 +
7339 + return FALSE;
7340 +}
7341 +
7342 +
7343 +int
7344 +avr32_valid_load_quad_bypass (rtx insn_out, rtx insn_in)
7345 +{
7346 + /*
7347 + Check if the two first loaded word in insn_out are used in insn_in. */
7348 + rtx dst_reg;
7349 + rtx third_loaded_reg, fourth_loaded_reg;
7350 +
7351 + /* Get the destination register in the load */
7352 + if (!REG_P (SET_DEST (PATTERN (insn_out))))
7353 + return FALSE;
7354 +
7355 + dst_reg = SET_DEST (PATTERN (insn_out));
7356 + third_loaded_reg = gen_rtx_REG (SImode, REGNO (dst_reg) + 2);
7357 + fourth_loaded_reg = gen_rtx_REG (SImode, REGNO (dst_reg) + 3);
7358 +
7359 + if (!reg_mentioned_p (third_loaded_reg, PATTERN (insn_in))
7360 + && !reg_mentioned_p (fourth_loaded_reg, PATTERN (insn_in)))
7361 + {
7362 + return TRUE;
7363 + }
7364 +
7365 + return FALSE;
7366 +}
7367 +
7368 +
7369 +
7370 +rtx
7371 +avr32_ifcvt_modify_test (ce_if_block_t *ce_info,
7372 + rtx test ){
7373 + rtx branch_insn;
7374 + rtx cmp_test;
7375 + rtx compare_op0;
7376 + rtx compare_op1;
7377 +
7378 +
7379 + if ( !ce_info
7380 + || test == NULL_RTX
7381 + || !reg_mentioned_p (cc0_rtx, test))
7382 + return test;
7383 +
7384 + branch_insn = BB_END (ce_info->test_bb);
7385 + cmp_test = PATTERN(prev_nonnote_insn (branch_insn));
7386 +
7387 + if (GET_CODE(cmp_test) != SET
7388 + || !CC0_P(XEXP(cmp_test, 0)) )
7389 + return cmp_test;
7390 +
7391 + if ( GET_CODE(SET_SRC(cmp_test)) == COMPARE ){
7392 + compare_op0 = XEXP(SET_SRC(cmp_test), 0);
7393 + compare_op1 = XEXP(SET_SRC(cmp_test), 1);
7394 + } else {
7395 + compare_op0 = SET_SRC(cmp_test);
7396 + compare_op1 = const0_rtx;
7397 + }
7398 +
7399 + return gen_rtx_fmt_ee (GET_CODE(test), GET_MODE (compare_op0),
7400 + compare_op0, compare_op1);
7401 +}
7402 +
7403 +
7404 +
7405 +rtx
7406 +avr32_ifcvt_modify_insn (ce_if_block_t *ce_info,
7407 + rtx pattern,
7408 + rtx insn,
7409 + int *num_true_changes){
7410 + rtx test = COND_EXEC_TEST(pattern);
7411 + rtx op = COND_EXEC_CODE(pattern);
7412 + rtx cmp_insn;
7413 + rtx cond_exec_insn;
7414 + int inputs_set_outside_ifblock = 1;
7415 + basic_block current_bb = BLOCK_FOR_INSN (insn);
7416 + rtx bb_insn ;
7417 + enum machine_mode mode = GET_MODE (XEXP (op, 0));
7418 +
7419 + if (CC0_P(XEXP(test, 0)))
7420 + test = avr32_ifcvt_modify_test (ce_info,
7421 + test );
7422 +
7423 + /* We do not support multiple tests. */
7424 + if ( ce_info
7425 + && ce_info->num_multiple_test_blocks > 0 )
7426 + return NULL_RTX;
7427 +
7428 + pattern = gen_rtx_COND_EXEC (VOIDmode, test, op);
7429 +
7430 + if ( !reload_completed )
7431 + {
7432 + rtx start;
7433 + int num_insns;
7434 + int max_insns = MAX_CONDITIONAL_EXECUTE;
7435 +
7436 + if ( !ce_info )
7437 + return op;
7438 +
7439 + /* Check if the insn is not suitable for conditional
7440 + execution. */
7441 + start_sequence ();
7442 + cond_exec_insn = emit_insn (pattern);
7443 + if ( recog_memoized (cond_exec_insn) < 0
7444 + && can_create_pseudo_p () )
7445 + {
7446 + /* Insn is not suitable for conditional execution, try
7447 + to fix it up by using an extra scratch register or
7448 + by pulling the operation outside the if-then-else
7449 + and then emiting a conditional move inside the if-then-else. */
7450 + end_sequence ();
7451 + if ( GET_CODE (op) != SET
7452 + || !REG_P (SET_DEST (op))
7453 + || GET_CODE (SET_SRC (op)) == IF_THEN_ELSE
7454 + || GET_MODE_SIZE (mode) > UNITS_PER_WORD )
7455 + return NULL_RTX;
7456 +
7457 + /* Check if any of the input operands to the insn is set inside the
7458 + current block. */
7459 + if ( current_bb->index == ce_info->then_bb->index )
7460 + start = PREV_INSN (BB_HEAD (ce_info->then_bb));
7461 + else
7462 + start = PREV_INSN (BB_HEAD (ce_info->else_bb));
7463 +
7464 +
7465 + for ( bb_insn = next_nonnote_insn (start); bb_insn != insn; bb_insn = next_nonnote_insn (bb_insn) )
7466 + {
7467 + rtx set = single_set (bb_insn);
7468 +
7469 + if ( set && reg_mentioned_p (SET_DEST (set), SET_SRC (op)))
7470 + {
7471 + inputs_set_outside_ifblock = 0;
7472 + break;
7473 + }
7474 + }
7475 +
7476 + cmp_insn = prev_nonnote_insn (BB_END (ce_info->test_bb));
7477 +
7478 +
7479 + /* Check if we can insert more insns. */
7480 + num_insns = ( ce_info->num_then_insns +
7481 + ce_info->num_else_insns +
7482 + ce_info->num_cond_clobber_insns +
7483 + ce_info->num_extra_move_insns );
7484 +
7485 + if ( ce_info->num_else_insns != 0 )
7486 + max_insns *=2;
7487 +
7488 + if ( num_insns >= max_insns )
7489 + return NULL_RTX;
7490 +
7491 + /* Check if we have an instruction which might be converted to
7492 + conditional form if we give it a scratch register to clobber. */
7493 + {
7494 + rtx clobber_insn;
7495 + rtx scratch_reg = gen_reg_rtx (mode);
7496 + rtx new_pattern = copy_rtx (pattern);
7497 + rtx set_src = SET_SRC (COND_EXEC_CODE (new_pattern));
7498 +
7499 + rtx clobber = gen_rtx_CLOBBER (mode, scratch_reg);
7500 + rtx vec[2] = { COND_EXEC_CODE (new_pattern), clobber };
7501 + COND_EXEC_CODE (new_pattern) = gen_rtx_PARALLEL (mode, gen_rtvec_v (2, vec));
7502 +
7503 + start_sequence ();
7504 + clobber_insn = emit_insn (new_pattern);
7505 +
7506 + if ( recog_memoized (clobber_insn) >= 0
7507 + && ( ( GET_RTX_LENGTH (GET_CODE (set_src)) == 2
7508 + && CONST_INT_P (XEXP (set_src, 1))
7509 + && avr32_const_ok_for_constraint_p (INTVAL (XEXP (set_src, 1)), 'K', "Ks08") )
7510 + || !ce_info->else_bb
7511 + || current_bb->index == ce_info->else_bb->index ))
7512 + {
7513 + end_sequence ();
7514 + /* Force the insn to be recognized again. */
7515 + INSN_CODE (insn) = -1;
7516 +
7517 + /* If this is the first change in this IF-block then
7518 + signal that we have made a change. */
7519 + if ( ce_info->num_cond_clobber_insns == 0
7520 + && ce_info->num_extra_move_insns == 0 )
7521 + *num_true_changes += 1;
7522 +
7523 + ce_info->num_cond_clobber_insns++;
7524 +
7525 + if (dump_file)
7526 + fprintf (dump_file,
7527 + "\nReplacing INSN %d with an insn using a scratch register for later ifcvt passes...\n",
7528 + INSN_UID (insn));
7529 +
7530 + return COND_EXEC_CODE (new_pattern);
7531 + }
7532 + end_sequence ();
7533 + }
7534 +
7535 + if ( inputs_set_outside_ifblock )
7536 + {
7537 + /* Check if the insn before the cmp is an and which used
7538 + together with the cmp can be optimized into a bld. If
7539 + so then we should try to put the insn before the and
7540 + so that we can catch the bld peephole. */
7541 + rtx set;
7542 + rtx insn_before_cmp_insn = prev_nonnote_insn (cmp_insn);
7543 + if (insn_before_cmp_insn
7544 + && (set = single_set (insn_before_cmp_insn))
7545 + && GET_CODE (SET_SRC (set)) == AND
7546 + && one_bit_set_operand (XEXP (SET_SRC (set), 1), SImode)
7547 + /* Also make sure that the insn does not set any
7548 + of the input operands to the insn we are pulling out. */
7549 + && !reg_mentioned_p (SET_DEST (set), SET_SRC (op)) )
7550 + cmp_insn = prev_nonnote_insn (cmp_insn);
7551 +
7552 + /* We can try to put the operation outside the if-then-else
7553 + blocks and insert a move. */
7554 + if ( !insn_invalid_p (insn)
7555 + /* Do not allow conditional insns to be moved outside the
7556 + if-then-else. */
7557 + && !reg_mentioned_p (cc0_rtx, insn)
7558 + /* We cannot move memory loads outside of the if-then-else
7559 + since the memory access should not be perfomed if the
7560 + condition is not met. */
7561 + && !mem_mentioned_p (SET_SRC (op)) )
7562 + {
7563 + rtx scratch_reg = gen_reg_rtx (mode);
7564 + rtx op_pattern = copy_rtx (op);
7565 + rtx new_insn, seq;
7566 + rtx link, prev_link;
7567 + op = copy_rtx (op);
7568 + /* Emit the operation to a temp reg before the compare,
7569 + and emit a move inside the if-then-else, hoping that the
7570 + whole if-then-else can be converted to conditional
7571 + execution. */
7572 + SET_DEST (op_pattern) = scratch_reg;
7573 + start_sequence ();
7574 + new_insn = emit_insn (op_pattern);
7575 + seq = get_insns();
7576 + end_sequence ();
7577 +
7578 + /* Check again that the insn is valid. For some insns the insn might
7579 + become invalid if the destination register is changed. Ie. for mulacc
7580 + operations. */
7581 + if ( insn_invalid_p (new_insn) )
7582 + return NULL_RTX;
7583 +
7584 + emit_insn_before_setloc (seq, cmp_insn, INSN_LOCATOR (insn));
7585 +
7586 + if (dump_file)
7587 + fprintf (dump_file,
7588 + "\nMoving INSN %d out of IF-block by adding INSN %d...\n",
7589 + INSN_UID (insn), INSN_UID (new_insn));
7590 +
7591 + ce_info->extra_move_insns[ce_info->num_extra_move_insns] = insn;
7592 + ce_info->moved_insns[ce_info->num_extra_move_insns] = new_insn;
7593 + XEXP (op, 1) = scratch_reg;
7594 + /* Force the insn to be recognized again. */
7595 + INSN_CODE (insn) = -1;
7596 +
7597 + /* Move REG_DEAD notes to the moved insn. */
7598 + prev_link = NULL_RTX;
7599 + for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
7600 + {
7601 + if (REG_NOTE_KIND (link) == REG_DEAD)
7602 + {
7603 + /* Add the REG_DEAD note to the new insn. */
7604 + rtx dead_reg = XEXP (link, 0);
7605 + REG_NOTES (new_insn) = gen_rtx_EXPR_LIST (REG_DEAD, dead_reg, REG_NOTES (new_insn));
7606 + /* Remove the REG_DEAD note from the insn we convert to a move. */
7607 + if ( prev_link )
7608 + XEXP (prev_link, 1) = XEXP (link, 1);
7609 + else
7610 + REG_NOTES (insn) = XEXP (link, 1);
7611 + }
7612 + else
7613 + {
7614 + prev_link = link;
7615 + }
7616 + }
7617 + /* Add a REG_DEAD note to signal that the scratch register is dead. */
7618 + REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_DEAD, scratch_reg, REG_NOTES (insn));
7619 +
7620 + /* If this is the first change in this IF-block then
7621 + signal that we have made a change. */
7622 + if ( ce_info->num_cond_clobber_insns == 0
7623 + && ce_info->num_extra_move_insns == 0 )
7624 + *num_true_changes += 1;
7625 +
7626 + ce_info->num_extra_move_insns++;
7627 + return op;
7628 + }
7629 + }
7630 +
7631 + /* We failed to fixup the insns, so this if-then-else can not be made
7632 + conditional. Just return NULL_RTX so that the if-then-else conversion
7633 + for this if-then-else will be cancelled. */
7634 + return NULL_RTX;
7635 + }
7636 + end_sequence ();
7637 + return op;
7638 + }
7639 +
7640 + /* Signal that we have started if conversion after reload, which means
7641 + that it should be safe to split all the predicable clobber insns which
7642 + did not become cond_exec back into a simpler form if possible. */
7643 + cfun->machine->ifcvt_after_reload = 1;
7644 +
7645 + return pattern;
7646 +}
7647 +
7648 +
7649 +void
7650 +avr32_ifcvt_modify_cancel ( ce_if_block_t *ce_info,
7651 + int *num_true_changes)
7652 +{
7653 + int n;
7654 +
7655 + if ( ce_info->num_extra_move_insns > 0
7656 + && ce_info->num_cond_clobber_insns == 0)
7657 + /* Signal that we did not do any changes after all. */
7658 + *num_true_changes -= 1;
7659 +
7660 + /* Remove any inserted move insns. */
7661 + for ( n = 0; n < ce_info->num_extra_move_insns; n++ )
7662 + {
7663 + rtx link, prev_link;
7664 +
7665 + /* Remove REG_DEAD note since we are not needing the scratch register anyway. */
7666 + prev_link = NULL_RTX;
7667 + for (link = REG_NOTES (ce_info->extra_move_insns[n]); link; link = XEXP (link, 1))
7668 + {
7669 + if (REG_NOTE_KIND (link) == REG_DEAD)
7670 + {
7671 + if ( prev_link )
7672 + XEXP (prev_link, 1) = XEXP (link, 1);
7673 + else
7674 + REG_NOTES (ce_info->extra_move_insns[n]) = XEXP (link, 1);
7675 + }
7676 + else
7677 + {
7678 + prev_link = link;
7679 + }
7680 + }
7681 +
7682 + /* Revert all reg_notes for the moved insn. */
7683 + for (link = REG_NOTES (ce_info->moved_insns[n]); link; link = XEXP (link, 1))
7684 + {
7685 + REG_NOTES (ce_info->extra_move_insns[n]) = gen_rtx_EXPR_LIST (REG_NOTE_KIND (link),
7686 + XEXP (link, 0),
7687 + REG_NOTES (ce_info->extra_move_insns[n]));
7688 + }
7689 +
7690 + /* Remove the moved insn. */
7691 + remove_insn ( ce_info->moved_insns[n] );
7692 + }
7693 +}
7694 +
7695 +/* Function returning TRUE if INSN with OPERANDS is a splittable
7696 + conditional immediate clobber insn. We assume that the insn is
7697 + already a conditional immediate clobber insns and do not check
7698 + for that. */
7699 +int
7700 +avr32_cond_imm_clobber_splittable (rtx insn,
7701 + rtx operands[])
7702 +{
7703 + if ( REGNO (operands[0]) == REGNO (operands[1]) )
7704 + {
7705 + if ( (GET_CODE (SET_SRC (XVECEXP (PATTERN (insn),0,0))) == PLUS
7706 + && !avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'I', "Is21"))
7707 + || (GET_CODE (SET_SRC (XVECEXP (PATTERN (insn),0,0))) == MINUS
7708 + && !avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks21")))
7709 + return FALSE;
7710 + }
7711 + else if ( (logical_binary_operator (SET_SRC (XVECEXP (PATTERN (insn),0,0)), VOIDmode)
7712 + || (GET_CODE (SET_SRC (XVECEXP (PATTERN (insn),0,0))) == PLUS
7713 + && !avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'I', "Is16"))
7714 + || (GET_CODE (SET_SRC (XVECEXP (PATTERN (insn),0,0))) == MINUS
7715 + && !avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks16"))) )
7716 + return FALSE;
7717 +
7718 + return TRUE;
7719 +}
7720 +
7721 +/* Function for getting an integer value from a const_int or const_double
7722 + expression regardless of the HOST_WIDE_INT size. Each target cpu word
7723 + will be put into the val array where the LSW will be stored at the lowest
7724 + address and so forth. Assumes that const_expr is either a const_int or
7725 + const_double. Only valid for modes which have sizes that are a multiple
7726 + of the word size.
7727 +*/
7728 +void
7729 +avr32_get_intval (enum machine_mode mode,
7730 + rtx const_expr,
7731 + HOST_WIDE_INT *val)
7732 +{
7733 + int words_in_mode = GET_MODE_SIZE (mode)/UNITS_PER_WORD;
7734 + const int words_in_const_int = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
7735 +
7736 + if ( GET_CODE(const_expr) == CONST_DOUBLE ){
7737 + HOST_WIDE_INT hi = CONST_DOUBLE_HIGH(const_expr);
7738 + HOST_WIDE_INT lo = CONST_DOUBLE_LOW(const_expr);
7739 + /* Evaluate hi and lo values of const_double. */
7740 + avr32_get_intval (mode_for_size (HOST_BITS_PER_WIDE_INT, MODE_INT, 0),
7741 + GEN_INT (lo),
7742 + &val[0]);
7743 + avr32_get_intval (mode_for_size (HOST_BITS_PER_WIDE_INT, MODE_INT, 0),
7744 + GEN_INT (hi),
7745 + &val[words_in_const_int]);
7746 + } else if ( GET_CODE(const_expr) == CONST_INT ){
7747 + HOST_WIDE_INT value = INTVAL(const_expr);
7748 + int word;
7749 + for ( word = 0; (word < words_in_mode) && (word < words_in_const_int); word++ ){
7750 + /* Shift word up to the MSW and shift down again to extract the
7751 + word and sign-extend. */
7752 + int lshift = (words_in_const_int - word - 1) * BITS_PER_WORD;
7753 + int rshift = (words_in_const_int-1) * BITS_PER_WORD;
7754 + val[word] = (value << lshift) >> rshift;
7755 + }
7756 +
7757 + for ( ; word < words_in_mode; word++ ){
7758 + /* Just put the sign bits in the remaining words. */
7759 + val[word] = value < 0 ? -1 : 0;
7760 + }
7761 + }
7762 +}
7763 +
7764 +void
7765 +avr32_split_const_expr (enum machine_mode mode,
7766 + enum machine_mode new_mode,
7767 + rtx expr,
7768 + rtx *split_expr)
7769 +{
7770 + int i, word;
7771 + int words_in_intval = GET_MODE_SIZE (mode)/UNITS_PER_WORD;
7772 + int words_in_split_values = GET_MODE_SIZE (new_mode)/UNITS_PER_WORD;
7773 + const int words_in_const_int = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
7774 + HOST_WIDE_INT *val = alloca (words_in_intval * UNITS_PER_WORD);
7775 +
7776 + avr32_get_intval (mode, expr, val);
7777 +
7778 + for ( i=0; i < (words_in_intval/words_in_split_values); i++ )
7779 + {
7780 + HOST_WIDE_INT value_lo = 0, value_hi = 0;
7781 + for ( word = 0; word < words_in_split_values; word++ )
7782 + {
7783 + if ( word >= words_in_const_int )
7784 + value_hi |= ((val[i * words_in_split_values + word] &
7785 + (((HOST_WIDE_INT)1 << BITS_PER_WORD)-1))
7786 + << (BITS_PER_WORD * (word - words_in_const_int)));
7787 + else
7788 + value_lo |= ((val[i * words_in_split_values + word] &
7789 + (((HOST_WIDE_INT)1 << BITS_PER_WORD)-1))
7790 + << (BITS_PER_WORD * word));
7791 + }
7792 + split_expr[i] = immed_double_const(value_lo, value_hi, new_mode);
7793 + }
7794 +}
7795 +
7796 +
7797 +/* Set up library functions to comply to AVR32 ABI */
7798 +
7799 +static void
7800 +avr32_init_libfuncs (void)
7801 +{
7802 + /* Convert gcc run-time function names to AVR32 ABI names */
7803 +
7804 + /* Double-precision floating-point arithmetic. */
7805 + set_optab_libfunc (neg_optab, DFmode, NULL);
7806 +
7807 + /* Double-precision comparisons. */
7808 + set_optab_libfunc (eq_optab, DFmode, "__avr32_f64_cmp_eq");
7809 + set_optab_libfunc (ne_optab, DFmode, NULL);
7810 + set_optab_libfunc (lt_optab, DFmode, "__avr32_f64_cmp_lt");
7811 + set_optab_libfunc (le_optab, DFmode, NULL);
7812 + set_optab_libfunc (ge_optab, DFmode, "__avr32_f64_cmp_ge");
7813 + set_optab_libfunc (gt_optab, DFmode, NULL);
7814 +
7815 + /* Single-precision floating-point arithmetic. */
7816 + set_optab_libfunc (smul_optab, SFmode, "__avr32_f32_mul");
7817 + set_optab_libfunc (neg_optab, SFmode, NULL);
7818 +
7819 + /* Single-precision comparisons. */
7820 + set_optab_libfunc (eq_optab, SFmode, "__avr32_f32_cmp_eq");
7821 + set_optab_libfunc (ne_optab, SFmode, NULL);
7822 + set_optab_libfunc (lt_optab, SFmode, "__avr32_f32_cmp_lt");
7823 + set_optab_libfunc (le_optab, SFmode, NULL);
7824 + set_optab_libfunc (ge_optab, SFmode, "__avr32_f32_cmp_ge");
7825 + set_optab_libfunc (gt_optab, SFmode, NULL);
7826 +
7827 + /* Floating-point to integer conversions. */
7828 + set_conv_libfunc (sfix_optab, SImode, DFmode, "__avr32_f64_to_s32");
7829 + set_conv_libfunc (ufix_optab, SImode, DFmode, "__avr32_f64_to_u32");
7830 + set_conv_libfunc (sfix_optab, DImode, DFmode, "__avr32_f64_to_s64");
7831 + set_conv_libfunc (ufix_optab, DImode, DFmode, "__avr32_f64_to_u64");
7832 + set_conv_libfunc (sfix_optab, SImode, SFmode, "__avr32_f32_to_s32");
7833 + set_conv_libfunc (ufix_optab, SImode, SFmode, "__avr32_f32_to_u32");
7834 + set_conv_libfunc (sfix_optab, DImode, SFmode, "__avr32_f32_to_s64");
7835 + set_conv_libfunc (ufix_optab, DImode, SFmode, "__avr32_f32_to_u64");
7836 +
7837 + /* Conversions between floating types. */
7838 + set_conv_libfunc (trunc_optab, SFmode, DFmode, "__avr32_f64_to_f32");
7839 + set_conv_libfunc (sext_optab, DFmode, SFmode, "__avr32_f32_to_f64");
7840 +
7841 + /* Integer to floating-point conversions. Table 8. */
7842 + set_conv_libfunc (sfloat_optab, DFmode, SImode, "__avr32_s32_to_f64");
7843 + set_conv_libfunc (sfloat_optab, DFmode, DImode, "__avr32_s64_to_f64");
7844 + set_conv_libfunc (sfloat_optab, SFmode, SImode, "__avr32_s32_to_f32");
7845 + set_conv_libfunc (sfloat_optab, SFmode, DImode, "__avr32_s64_to_f32");
7846 + set_conv_libfunc (ufloat_optab, DFmode, SImode, "__avr32_u32_to_f64");
7847 + set_conv_libfunc (ufloat_optab, SFmode, SImode, "__avr32_u32_to_f32");
7848 + /* TODO: Add these to gcc library functions */
7849 + //set_conv_libfunc (ufloat_optab, DFmode, DImode, NULL);
7850 + //set_conv_libfunc (ufloat_optab, SFmode, DImode, NULL);
7851 +
7852 + /* Long long. Table 9. */
7853 + set_optab_libfunc (smul_optab, DImode, "__avr32_mul64");
7854 + set_optab_libfunc (sdiv_optab, DImode, "__avr32_sdiv64");
7855 + set_optab_libfunc (udiv_optab, DImode, "__avr32_udiv64");
7856 + set_optab_libfunc (smod_optab, DImode, "__avr32_smod64");
7857 + set_optab_libfunc (umod_optab, DImode, "__avr32_umod64");
7858 + set_optab_libfunc (ashl_optab, DImode, "__avr32_lsl64");
7859 + set_optab_libfunc (lshr_optab, DImode, "__avr32_lsr64");
7860 + set_optab_libfunc (ashr_optab, DImode, "__avr32_asr64");
7861 +
7862 + /* Floating point library functions which have fast versions. */
7863 + if ( TARGET_FAST_FLOAT )
7864 + {
7865 + set_optab_libfunc (sdiv_optab, DFmode, "__avr32_f64_div_fast");
7866 + set_optab_libfunc (smul_optab, DFmode, "__avr32_f64_mul_fast");
7867 + set_optab_libfunc (add_optab, DFmode, "__avr32_f64_add_fast");
7868 + set_optab_libfunc (sub_optab, DFmode, "__avr32_f64_sub_fast");
7869 + set_optab_libfunc (add_optab, SFmode, "__avr32_f32_add_fast");
7870 + set_optab_libfunc (sub_optab, SFmode, "__avr32_f32_sub_fast");
7871 + set_optab_libfunc (sdiv_optab, SFmode, "__avr32_f32_div_fast");
7872 + }
7873 + else
7874 + {
7875 + set_optab_libfunc (sdiv_optab, DFmode, "__avr32_f64_div");
7876 + set_optab_libfunc (smul_optab, DFmode, "__avr32_f64_mul");
7877 + set_optab_libfunc (add_optab, DFmode, "__avr32_f64_add");
7878 + set_optab_libfunc (sub_optab, DFmode, "__avr32_f64_sub");
7879 + set_optab_libfunc (add_optab, SFmode, "__avr32_f32_add");
7880 + set_optab_libfunc (sub_optab, SFmode, "__avr32_f32_sub");
7881 + set_optab_libfunc (sdiv_optab, SFmode, "__avr32_f32_div");
7882 + }
7883 +}
7884 --- /dev/null
7885 +++ b/gcc/config/avr32/avr32-elf.h
7886 @@ -0,0 +1,86 @@
7887 +/*
7888 + Elf specific definitions.
7889 + Copyright 2003-2006 Atmel Corporation.
7890 +
7891 + Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
7892 +
7893 + This file is part of GCC.
7894 +
7895 + This program is free software; you can redistribute it and/or modify
7896 + it under the terms of the GNU General Public License as published by
7897 + the Free Software Foundation; either version 2 of the License, or
7898 + (at your option) any later version.
7899 +
7900 + This program is distributed in the hope that it will be useful,
7901 + but WITHOUT ANY WARRANTY; without even the implied warranty of
7902 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7903 + GNU General Public License for more details.
7904 +
7905 + You should have received a copy of the GNU General Public License
7906 + along with this program; if not, write to the Free Software
7907 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
7908 +
7909 +
7910 +/*****************************************************************************
7911 + * Controlling the Compilator Driver, 'gcc'
7912 + *****************************************************************************/
7913 +
7914 +/* Run-time Target Specification. */
7915 +#undef TARGET_VERSION
7916 +#define TARGET_VERSION fputs (" (AVR32 GNU with ELF)", stderr);
7917 +
7918 +/*
7919 +Another C string constant used much like LINK_SPEC. The
7920 +difference between the two is that STARTFILE_SPEC is used at
7921 +the very beginning of the command given to the linker.
7922 +
7923 +If this macro is not defined, a default is provided that loads the
7924 +standard C startup file from the usual place. See gcc.c.
7925 +*/
7926 +#undef STARTFILE_SPEC
7927 +#define STARTFILE_SPEC "crt0%O%s crti%O%s crtbegin%O%s"
7928 +
7929 +#undef LINK_SPEC
7930 +#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_%*}"
7931 +
7932 +
7933 +/*
7934 +Another C string constant used much like LINK_SPEC. The
7935 +difference between the two is that ENDFILE_SPEC is used at
7936 +the very end of the command given to the linker.
7937 +
7938 +Do not define this macro if it does not need to do anything.
7939 +*/
7940 +#undef ENDFILE_SPEC
7941 +#define ENDFILE_SPEC "crtend%O%s crtn%O%s"
7942 +
7943 +
7944 +/* Target CPU builtins. */
7945 +#define TARGET_CPU_CPP_BUILTINS() \
7946 + do \
7947 + { \
7948 + builtin_define ("__avr32__"); \
7949 + builtin_define ("__AVR32__"); \
7950 + builtin_define ("__AVR32_ELF__"); \
7951 + builtin_define (avr32_part->macro); \
7952 + builtin_define (avr32_arch->macro); \
7953 + if (avr32_arch->uarch_type == UARCH_TYPE_AVR32A) \
7954 + builtin_define ("__AVR32_AVR32A__"); \
7955 + else \
7956 + builtin_define ("__AVR32_AVR32B__"); \
7957 + if (TARGET_UNALIGNED_WORD) \
7958 + builtin_define ("__AVR32_HAS_UNALIGNED_WORD__"); \
7959 + if (TARGET_SIMD) \
7960 + builtin_define ("__AVR32_HAS_SIMD__"); \
7961 + if (TARGET_DSP) \
7962 + builtin_define ("__AVR32_HAS_DSP__"); \
7963 + if (TARGET_RMW) \
7964 + builtin_define ("__AVR32_HAS_RMW__"); \
7965 + if (TARGET_BRANCH_PRED) \
7966 + builtin_define ("__AVR32_HAS_BRANCH_PRED__"); \
7967 + if (TARGET_FAST_FLOAT) \
7968 + builtin_define ("__AVR32_FAST_FLOAT__"); \
7969 + if (TARGET_NO_MUL_INSNS) \
7970 + builtin_define ("__AVR32_NO_MUL__"); \
7971 + } \
7972 + while (0)
7973 --- /dev/null
7974 +++ b/gcc/config/avr32/avr32.h
7975 @@ -0,0 +1,3344 @@
7976 +/*
7977 + Definitions of target machine for AVR32.
7978 + Copyright 2003-2006 Atmel Corporation.
7979 +
7980 + Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
7981 + Initial porting by Anders �dland.
7982 +
7983 + This file is part of GCC.
7984 +
7985 + This program is free software; you can redistribute it and/or modify
7986 + it under the terms of the GNU General Public License as published by
7987 + the Free Software Foundation; either version 2 of the License, or
7988 + (at your option) any later version.
7989 +
7990 + This program is distributed in the hope that it will be useful,
7991 + but WITHOUT ANY WARRANTY; without even the implied warranty of
7992 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7993 + GNU General Public License for more details.
7994 +
7995 + You should have received a copy of the GNU General Public License
7996 + along with this program; if not, write to the Free Software
7997 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
7998 +
7999 +#ifndef GCC_AVR32_H
8000 +#define GCC_AVR32_H
8001 +
8002 +
8003 +#ifndef OBJECT_FORMAT_ELF
8004 +#error avr32.h included before elfos.h
8005 +#endif
8006 +
8007 +#ifndef LOCAL_LABEL_PREFIX
8008 +#define LOCAL_LABEL_PREFIX "."
8009 +#endif
8010 +
8011 +#ifndef SUBTARGET_CPP_SPEC
8012 +#define SUBTARGET_CPP_SPEC "-D__ELF__"
8013 +#endif
8014 +
8015 +
8016 +extern struct rtx_def *avr32_compare_op0;
8017 +extern struct rtx_def *avr32_compare_op1;
8018 +
8019 +
8020 +extern struct rtx_def *avr32_acc_cache;
8021 +
8022 +/* cache instruction op5 codes */
8023 +#define AVR32_CACHE_INVALIDATE_ICACHE 1
8024 +
8025 +/* These bits describe the different types of function supported
8026 + by the AVR32 backend. They are exclusive. ie a function cannot be both a
8027 + normal function and an interworked function, for example. Knowing the
8028 + type of a function is important for determining its prologue and
8029 + epilogue sequences.
8030 + Note value 7 is currently unassigned. Also note that the interrupt
8031 + function types all have bit 2 set, so that they can be tested for easily.
8032 + Note that 0 is deliberately chosen for AVR32_FT_UNKNOWN so that when the
8033 + machine_function structure is initialized (to zero) func_type will
8034 + default to unknown. This will force the first use of avr32_current_func_type
8035 + to call avr32_compute_func_type. */
8036 +#define AVR32_FT_UNKNOWN 0 /* Type has not yet been determined.
8037 + */
8038 +#define AVR32_FT_NORMAL 1 /* Your normal, straightforward
8039 + function. */
8040 +#define AVR32_FT_ACALL 2 /* An acall function. */
8041 +#define AVR32_FT_EXCEPTION_HANDLER 3 /* A C++ exception handler. */
8042 +#define AVR32_FT_ISR_FULL 4 /* A fully shadowed interrupt mode. */
8043 +#define AVR32_FT_ISR_HALF 5 /* A half shadowed interrupt mode. */
8044 +#define AVR32_FT_ISR_NONE 6 /* No shadow registers. */
8045 +
8046 +#define AVR32_FT_TYPE_MASK ((1 << 3) - 1)
8047 +
8048 +/* In addition functions can have several type modifiers,
8049 + outlined by these bit masks: */
8050 +#define AVR32_FT_INTERRUPT (1 << 2) /* Note overlap with FT_ISR
8051 + and above. */
8052 +#define AVR32_FT_NAKED (1 << 3) /* No prologue or epilogue. */
8053 +#define AVR32_FT_VOLATILE (1 << 4) /* Does not return. */
8054 +#define AVR32_FT_NESTED (1 << 5) /* Embedded inside another
8055 + func. */
8056 +
8057 +/* Some macros to test these flags. */
8058 +#define AVR32_FUNC_TYPE(t) (t & AVR32_FT_TYPE_MASK)
8059 +#define IS_INTERRUPT(t) (t & AVR32_FT_INTERRUPT)
8060 +#define IS_VOLATILE(t) (t & AVR32_FT_VOLATILE)
8061 +#define IS_NAKED(t) (t & AVR32_FT_NAKED)
8062 +#define IS_NESTED(t) (t & AVR32_FT_NESTED)
8063 +
8064 +
8065 +typedef struct minipool_labels
8066 +GTY ((chain_next ("%h.next"), chain_prev ("%h.prev")))
8067 +{
8068 + rtx label;
8069 + struct minipool_labels *prev;
8070 + struct minipool_labels *next;
8071 +} minipool_labels;
8072 +
8073 +/* A C structure for machine-specific, per-function data.
8074 + This is added to the cfun structure. */
8075 +
8076 +typedef struct machine_function
8077 +GTY (())
8078 +{
8079 + /* Records the type of the current function. */
8080 + unsigned long func_type;
8081 + /* List of minipool labels, use for checking if code label is valid in a
8082 + memory expression */
8083 + minipool_labels *minipool_label_head;
8084 + minipool_labels *minipool_label_tail;
8085 + int ifcvt_after_reload;
8086 +} machine_function;
8087 +
8088 +/* Initialize data used by insn expanders. This is called from insn_emit,
8089 + once for every function before code is generated. */
8090 +#define INIT_EXPANDERS avr32_init_expanders ()
8091 +
8092 +/******************************************************************************
8093 + * SPECS
8094 + *****************************************************************************/
8095 +
8096 +#ifndef ASM_SPEC
8097 +#define ASM_SPEC "%{fpic:--pic} %{mrelax|O*:%{mno-relax|O0|O1: ;:--linkrelax}} %{march=ucr2nomul:-march=ucr2;:%{march=*:-march=%*}} %{mpart=uc3a3revd:-mpart=uc3a3256s;:%{mpart=*:-mpart=%*}}"
8098 +#endif
8099 +
8100 +#ifndef MULTILIB_DEFAULTS
8101 +#define MULTILIB_DEFAULTS { "march=ap", "" }
8102 +#endif
8103 +
8104 +/******************************************************************************
8105 + * Run-time Target Specification
8106 + *****************************************************************************/
8107 +#ifndef TARGET_VERSION
8108 +#define TARGET_VERSION fprintf(stderr, " (AVR32, GNU assembler syntax)");
8109 +#endif
8110 +
8111 +
8112 +/* Part types. Keep this in sync with the order of avr32_part_types in avr32.c*/
8113 +enum part_type
8114 +{
8115 + PART_TYPE_AVR32_NONE,
8116 + PART_TYPE_AVR32_AP7000,
8117 + PART_TYPE_AVR32_AP7001,
8118 + PART_TYPE_AVR32_AP7002,
8119 + PART_TYPE_AVR32_AP7200,
8120 + PART_TYPE_AVR32_UC3A0128,
8121 + PART_TYPE_AVR32_UC3A0256,
8122 + PART_TYPE_AVR32_UC3A0512,
8123 + PART_TYPE_AVR32_UC3A0512ES,
8124 + PART_TYPE_AVR32_UC3A1128,
8125 + PART_TYPE_AVR32_UC3A1256,
8126 + PART_TYPE_AVR32_UC3A1512,
8127 + PART_TYPE_AVR32_UC3A1512ES,
8128 + PART_TYPE_AVR32_UC3A3REVD,
8129 + PART_TYPE_AVR32_UC3A364,
8130 + PART_TYPE_AVR32_UC3A364S,
8131 + PART_TYPE_AVR32_UC3A3128,
8132 + PART_TYPE_AVR32_UC3A3128S,
8133 + PART_TYPE_AVR32_UC3A3256,
8134 + PART_TYPE_AVR32_UC3A3256S,
8135 + PART_TYPE_AVR32_UC3B064,
8136 + PART_TYPE_AVR32_UC3B0128,
8137 + PART_TYPE_AVR32_UC3B0256,
8138 + PART_TYPE_AVR32_UC3B0256ES,
8139 + PART_TYPE_AVR32_UC3B0512REVC,
8140 + PART_TYPE_AVR32_UC3B164,
8141 + PART_TYPE_AVR32_UC3B1128,
8142 + PART_TYPE_AVR32_UC3B1256,
8143 + PART_TYPE_AVR32_UC3B1256ES,
8144 + PART_TYPE_AVR32_UC3B1512REVC,
8145 + PART_TYPE_AVR32_UC3C0512C,
8146 + PART_TYPE_AVR32_UC3C0256C,
8147 + PART_TYPE_AVR32_UC3C0128C,
8148 + PART_TYPE_AVR32_UC3C064C,
8149 + PART_TYPE_AVR32_UC3C1512C,
8150 + PART_TYPE_AVR32_UC3C1256C,
8151 + PART_TYPE_AVR32_UC3C1128C,
8152 + PART_TYPE_AVR32_UC3C164C,
8153 + PART_TYPE_AVR32_UC3C2512C,
8154 + PART_TYPE_AVR32_UC3C2256C,
8155 + PART_TYPE_AVR32_UC3C2128C,
8156 + PART_TYPE_AVR32_UC3C264C,
8157 + PART_TYPE_AVR32_UC3L064,
8158 + PART_TYPE_AVR32_UC3L032,
8159 + PART_TYPE_AVR32_UC3L016
8160 +};
8161 +
8162 +/* Microarchitectures. */
8163 +enum microarchitecture_type
8164 +{
8165 + UARCH_TYPE_AVR32A,
8166 + UARCH_TYPE_AVR32B,
8167 + UARCH_TYPE_NONE
8168 +};
8169 +
8170 +/* Architectures types which specifies the pipeline.
8171 + Keep this in sync with avr32_arch_types in avr32.c
8172 + and the pipeline attribute in avr32.md */
8173 +enum architecture_type
8174 +{
8175 + ARCH_TYPE_AVR32_AP,
8176 + ARCH_TYPE_AVR32_UCR1,
8177 + ARCH_TYPE_AVR32_UCR2,
8178 + ARCH_TYPE_AVR32_UCR2NOMUL,
8179 + ARCH_TYPE_AVR32_UCR3,
8180 + ARCH_TYPE_AVR32_NONE
8181 +};
8182 +
8183 +/* Flag specifying if the cpu has support for DSP instructions.*/
8184 +#define FLAG_AVR32_HAS_DSP (1 << 0)
8185 +/* Flag specifying if the cpu has support for Read-Modify-Write
8186 + instructions.*/
8187 +#define FLAG_AVR32_HAS_RMW (1 << 1)
8188 +/* Flag specifying if the cpu has support for SIMD instructions. */
8189 +#define FLAG_AVR32_HAS_SIMD (1 << 2)
8190 +/* Flag specifying if the cpu has support for unaligned memory word access. */
8191 +#define FLAG_AVR32_HAS_UNALIGNED_WORD (1 << 3)
8192 +/* Flag specifying if the cpu has support for branch prediction. */
8193 +#define FLAG_AVR32_HAS_BRANCH_PRED (1 << 4)
8194 +/* Flag specifying if the cpu has support for a return stack. */
8195 +#define FLAG_AVR32_HAS_RETURN_STACK (1 << 5)
8196 +/* Flag specifying if the cpu has caches. */
8197 +#define FLAG_AVR32_HAS_CACHES (1 << 6)
8198 +/* Flag specifying if the cpu has support for v2 insns. */
8199 +#define FLAG_AVR32_HAS_V2_INSNS (1 << 7)
8200 +/* Flag specifying that the cpu has buggy mul insns. */
8201 +#define FLAG_AVR32_HAS_NO_MUL_INSNS (1 << 8)
8202 +
8203 +/* Structure for holding information about different avr32 CPUs/parts */
8204 +struct part_type_s
8205 +{
8206 + const char *const name;
8207 + enum part_type part_type;
8208 + enum architecture_type arch_type;
8209 + /* Must lie outside user's namespace. NULL == no macro. */
8210 + const char *const macro;
8211 +};
8212 +
8213 +/* Structure for holding information about different avr32 pipeline
8214 + architectures. */
8215 +struct arch_type_s
8216 +{
8217 + const char *const name;
8218 + enum architecture_type arch_type;
8219 + enum microarchitecture_type uarch_type;
8220 + const unsigned long feature_flags;
8221 + /* Must lie outside user's namespace. NULL == no macro. */
8222 + const char *const macro;
8223 +};
8224 +
8225 +extern const struct part_type_s *avr32_part;
8226 +extern const struct arch_type_s *avr32_arch;
8227 +
8228 +#define TARGET_SIMD (avr32_arch->feature_flags & FLAG_AVR32_HAS_SIMD)
8229 +#define TARGET_DSP (avr32_arch->feature_flags & FLAG_AVR32_HAS_DSP)
8230 +#define TARGET_RMW (avr32_arch->feature_flags & FLAG_AVR32_HAS_RMW)
8231 +#define TARGET_UNALIGNED_WORD (avr32_arch->feature_flags & FLAG_AVR32_HAS_UNALIGNED_WORD)
8232 +#define TARGET_BRANCH_PRED (avr32_arch->feature_flags & FLAG_AVR32_HAS_BRANCH_PRED)
8233 +#define TARGET_RETURN_STACK (avr32_arch->feature_flags & FLAG_AVR32_HAS_RETURN_STACK)
8234 +#define TARGET_V2_INSNS (avr32_arch->feature_flags & FLAG_AVR32_HAS_V2_INSNS)
8235 +#define TARGET_CACHES (avr32_arch->feature_flags & FLAG_AVR32_HAS_CACHES)
8236 +#define TARGET_NO_MUL_INSNS (avr32_arch->feature_flags & FLAG_AVR32_HAS_NO_MUL_INSNS)
8237 +#define TARGET_ARCH_AP (avr32_arch->arch_type == ARCH_TYPE_AVR32_AP)
8238 +#define TARGET_ARCH_UCR1 (avr32_arch->arch_type == ARCH_TYPE_AVR32_UCR1)
8239 +#define TARGET_ARCH_UCR2 (avr32_arch->arch_type == ARCH_TYPE_AVR32_UCR2)
8240 +#define TARGET_ARCH_UC (TARGET_ARCH_UCR1 || TARGET_ARCH_UCR2)
8241 +#define TARGET_UARCH_AVR32A (avr32_arch->uarch_type == UARCH_TYPE_AVR32A)
8242 +#define TARGET_UARCH_AVR32B (avr32_arch->uarch_type == UARCH_TYPE_AVR32B)
8243 +
8244 +#define CAN_DEBUG_WITHOUT_FP
8245 +
8246 +
8247 +
8248 +
8249 +/******************************************************************************
8250 + * Storage Layout
8251 + *****************************************************************************/
8252 +
8253 +/*
8254 +Define this macro to have the value 1 if the most significant bit in a
8255 +byte has the lowest number; otherwise define it to have the value zero.
8256 +This means that bit-field instructions count from the most significant
8257 +bit. If the machine has no bit-field instructions, then this must still
8258 +be defined, but it doesn't matter which value it is defined to. This
8259 +macro need not be a constant.
8260 +
8261 +This macro does not affect the way structure fields are packed into
8262 +bytes or words; that is controlled by BYTES_BIG_ENDIAN.
8263 +*/
8264 +#define BITS_BIG_ENDIAN 0
8265 +
8266 +/*
8267 +Define this macro to have the value 1 if the most significant byte in a
8268 +word has the lowest number. This macro need not be a constant.
8269 +*/
8270 +/*
8271 + Data is stored in an big-endian way.
8272 +*/
8273 +#define BYTES_BIG_ENDIAN 1
8274 +
8275 +/*
8276 +Define this macro to have the value 1 if, in a multiword object, the
8277 +most significant word has the lowest number. This applies to both
8278 +memory locations and registers; GCC fundamentally assumes that the
8279 +order of words in memory is the same as the order in registers. This
8280 +macro need not be a constant.
8281 +*/
8282 +/*
8283 + Data is stored in an bin-endian way.
8284 +*/
8285 +#define WORDS_BIG_ENDIAN 1
8286 +
8287 +/*
8288 +Define this macro if WORDS_BIG_ENDIAN is not constant. This must be a
8289 +constant value with the same meaning as WORDS_BIG_ENDIAN, which will be
8290 +used only when compiling libgcc2.c. Typically the value will be set
8291 +based on preprocessor defines.
8292 +*/
8293 +#define LIBGCC2_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
8294 +
8295 +/*
8296 +Define this macro to have the value 1 if DFmode, XFmode or
8297 +TFmode floating point numbers are stored in memory with the word
8298 +containing the sign bit at the lowest address; otherwise define it to
8299 +have the value 0. This macro need not be a constant.
8300 +
8301 +You need not define this macro if the ordering is the same as for
8302 +multi-word integers.
8303 +*/
8304 +/* #define FLOAT_WORDS_BIG_ENDIAN 1 */
8305 +
8306 +/*
8307 +Define this macro to be the number of bits in an addressable storage
8308 +unit (byte); normally 8.
8309 +*/
8310 +#define BITS_PER_UNIT 8
8311 +
8312 +/*
8313 +Number of bits in a word; normally 32.
8314 +*/
8315 +#define BITS_PER_WORD 32
8316 +
8317 +/*
8318 +Maximum number of bits in a word. If this is undefined, the default is
8319 +BITS_PER_WORD. Otherwise, it is the constant value that is the
8320 +largest value that BITS_PER_WORD can have at run-time.
8321 +*/
8322 +/* MAX_BITS_PER_WORD not defined*/
8323 +
8324 +/*
8325 +Number of storage units in a word; normally 4.
8326 +*/
8327 +#define UNITS_PER_WORD 4
8328 +
8329 +/*
8330 +Minimum number of units in a word. If this is undefined, the default is
8331 +UNITS_PER_WORD. Otherwise, it is the constant value that is the
8332 +smallest value that UNITS_PER_WORD can have at run-time.
8333 +*/
8334 +/* MIN_UNITS_PER_WORD not defined */
8335 +
8336 +/*
8337 +Width of a pointer, in bits. You must specify a value no wider than the
8338 +width of Pmode. If it is not equal to the width of Pmode,
8339 +you must define POINTERS_EXTEND_UNSIGNED.
8340 +*/
8341 +#define POINTER_SIZE 32
8342 +
8343 +/*
8344 +A C expression whose value is greater than zero if pointers that need to be
8345 +extended from being POINTER_SIZE bits wide to Pmode are to
8346 +be zero-extended and zero if they are to be sign-extended. If the value
8347 +is less then zero then there must be an "ptr_extend" instruction that
8348 +extends a pointer from POINTER_SIZE to Pmode.
8349 +
8350 +You need not define this macro if the POINTER_SIZE is equal
8351 +to the width of Pmode.
8352 +*/
8353 +/* #define POINTERS_EXTEND_UNSIGNED */
8354 +
8355 +/*
8356 +A Macro to update M and UNSIGNEDP when an object whose type
8357 +is TYPE and which has the specified mode and signedness is to be
8358 +stored in a register. This macro is only called when TYPE is a
8359 +scalar type.
8360 +
8361 +On most RISC machines, which only have operations that operate on a full
8362 +register, define this macro to set M to word_mode if
8363 +M is an integer mode narrower than BITS_PER_WORD. In most
8364 +cases, only integer modes should be widened because wider-precision
8365 +floating-point operations are usually more expensive than their narrower
8366 +counterparts.
8367 +
8368 +For most machines, the macro definition does not change UNSIGNEDP.
8369 +However, some machines, have instructions that preferentially handle
8370 +either signed or unsigned quantities of certain modes. For example, on
8371 +the DEC Alpha, 32-bit loads from memory and 32-bit add instructions
8372 +sign-extend the result to 64 bits. On such machines, set
8373 +UNSIGNEDP according to which kind of extension is more efficient.
8374 +
8375 +Do not define this macro if it would never modify M.
8376 +*/
8377 +#define PROMOTE_MODE(M, UNSIGNEDP, TYPE) \
8378 + { \
8379 + if (!AGGREGATE_TYPE_P (TYPE) \
8380 + && GET_MODE_CLASS (mode) == MODE_INT \
8381 + && GET_MODE_SIZE (mode) < 4) \
8382 + { \
8383 + if (M == QImode) \
8384 + (UNSIGNEDP) = 1; \
8385 + else if (M == HImode) \
8386 + (UNSIGNEDP) = 0; \
8387 + (M) = SImode; \
8388 + } \
8389 + }
8390 +
8391 +#define PROMOTE_FUNCTION_MODE(M, UNSIGNEDP, TYPE) \
8392 + PROMOTE_MODE(M, UNSIGNEDP, TYPE)
8393 +
8394 +/* Define if operations between registers always perform the operation
8395 + on the full register even if a narrower mode is specified. */
8396 +#define WORD_REGISTER_OPERATIONS
8397 +
8398 +/* Define if loading in MODE, an integral mode narrower than BITS_PER_WORD
8399 + will either zero-extend or sign-extend. The value of this macro should
8400 + be the code that says which one of the two operations is implicitly
8401 + done, UNKNOWN if not known. */
8402 +#define LOAD_EXTEND_OP(MODE) \
8403 + (((MODE) == QImode) ? ZERO_EXTEND \
8404 + : ((MODE) == HImode) ? SIGN_EXTEND : UNKNOWN)
8405 +
8406 +
8407 +/*
8408 +Normal alignment required for function parameters on the stack, in
8409 +bits. All stack parameters receive at least this much alignment
8410 +regardless of data type. On most machines, this is the same as the
8411 +size of an integer.
8412 +*/
8413 +#define PARM_BOUNDARY 32
8414 +
8415 +/*
8416 +Define this macro to the minimum alignment enforced by hardware for the
8417 +stack pointer on this machine. The definition is a C expression for the
8418 +desired alignment (measured in bits). This value is used as a default
8419 +if PREFERRED_STACK_BOUNDARY is not defined. On most machines,
8420 +this should be the same as PARM_BOUNDARY.
8421 +*/
8422 +#define STACK_BOUNDARY 32
8423 +
8424 +/*
8425 +Define this macro if you wish to preserve a certain alignment for the
8426 +stack pointer, greater than what the hardware enforces. The definition
8427 +is a C expression for the desired alignment (measured in bits). This
8428 +macro must evaluate to a value equal to or larger than
8429 +STACK_BOUNDARY.
8430 +*/
8431 +#define PREFERRED_STACK_BOUNDARY (TARGET_FORCE_DOUBLE_ALIGN ? 64 : 32 )
8432 +
8433 +/*
8434 +Alignment required for a function entry point, in bits.
8435 +*/
8436 +#define FUNCTION_BOUNDARY 16
8437 +
8438 +/*
8439 +Biggest alignment that any data type can require on this machine, in bits.
8440 +*/
8441 +#define BIGGEST_ALIGNMENT (TARGET_FORCE_DOUBLE_ALIGN ? 64 : 32 )
8442 +
8443 +/*
8444 +If defined, the smallest alignment, in bits, that can be given to an
8445 +object that can be referenced in one operation, without disturbing any
8446 +nearby object. Normally, this is BITS_PER_UNIT, but may be larger
8447 +on machines that don't have byte or half-word store operations.
8448 +*/
8449 +#define MINIMUM_ATOMIC_ALIGNMENT BITS_PER_UNIT
8450 +
8451 +
8452 +/*
8453 +An integer expression for the size in bits of the largest integer machine mode that
8454 +should actually be used. All integer machine modes of this size or smaller can be
8455 +used for structures and unions with the appropriate sizes. If this macro is undefined,
8456 +GET_MODE_BITSIZE (DImode) is assumed.*/
8457 +#define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode)
8458 +
8459 +
8460 +/*
8461 +If defined, a C expression to compute the alignment given to a constant
8462 +that is being placed in memory. CONSTANT is the constant and
8463 +BASIC_ALIGN is the alignment that the object would ordinarily
8464 +have. The value of this macro is used instead of that alignment to
8465 +align the object.
8466 +
8467 +If this macro is not defined, then BASIC_ALIGN is used.
8468 +
8469 +The typical use of this macro is to increase alignment for string
8470 +constants to be word aligned so that strcpy calls that copy
8471 +constants can be done inline.
8472 +*/
8473 +#define CONSTANT_ALIGNMENT(CONSTANT, BASIC_ALIGN) \
8474 + ((TREE_CODE(CONSTANT) == STRING_CST) ? BITS_PER_WORD : BASIC_ALIGN)
8475 +
8476 +/* Try to align string to a word. */
8477 +#define DATA_ALIGNMENT(TYPE, ALIGN) \
8478 + ({(TREE_CODE (TYPE) == ARRAY_TYPE \
8479 + && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \
8480 + && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN));})
8481 +
8482 +/* Try to align local store strings to a word. */
8483 +#define LOCAL_ALIGNMENT(TYPE, ALIGN) \
8484 + ({(TREE_CODE (TYPE) == ARRAY_TYPE \
8485 + && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \
8486 + && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN));})
8487 +
8488 +/*
8489 +Define this macro to be the value 1 if instructions will fail to work
8490 +if given data not on the nominal alignment. If instructions will merely
8491 +go slower in that case, define this macro as 0.
8492 +*/
8493 +#define STRICT_ALIGNMENT 1
8494 +
8495 +/*
8496 +Define this if you wish to imitate the way many other C compilers handle
8497 +alignment of bit-fields and the structures that contain them.
8498 +
8499 +The behavior is that the type written for a bit-field (int,
8500 +short, or other integer type) imposes an alignment for the
8501 +entire structure, as if the structure really did contain an ordinary
8502 +field of that type. In addition, the bit-field is placed within the
8503 +structure so that it would fit within such a field, not crossing a
8504 +boundary for it.
8505 +
8506 +Thus, on most machines, a bit-field whose type is written as int
8507 +would not cross a four-byte boundary, and would force four-byte
8508 +alignment for the whole structure. (The alignment used may not be four
8509 +bytes; it is controlled by the other alignment parameters.)
8510 +
8511 +If the macro is defined, its definition should be a C expression;
8512 +a nonzero value for the expression enables this behavior.
8513 +
8514 +Note that if this macro is not defined, or its value is zero, some
8515 +bit-fields may cross more than one alignment boundary. The compiler can
8516 +support such references if there are insv, extv, and
8517 +extzv insns that can directly reference memory.
8518 +
8519 +The other known way of making bit-fields work is to define
8520 +STRUCTURE_SIZE_BOUNDARY as large as BIGGEST_ALIGNMENT.
8521 +Then every structure can be accessed with fullwords.
8522 +
8523 +Unless the machine has bit-field instructions or you define
8524 +STRUCTURE_SIZE_BOUNDARY that way, you must define
8525 +PCC_BITFIELD_TYPE_MATTERS to have a nonzero value.
8526 +
8527 +If your aim is to make GCC use the same conventions for laying out
8528 +bit-fields as are used by another compiler, here is how to investigate
8529 +what the other compiler does. Compile and run this program:
8530 +
8531 +struct foo1
8532 +{
8533 + char x;
8534 + char :0;
8535 + char y;
8536 +};
8537 +
8538 +struct foo2
8539 +{
8540 + char x;
8541 + int :0;
8542 + char y;
8543 +};
8544 +
8545 +main ()
8546 +{
8547 + printf ("Size of foo1 is %d\n",
8548 + sizeof (struct foo1));
8549 + printf ("Size of foo2 is %d\n",
8550 + sizeof (struct foo2));
8551 + exit (0);
8552 +}
8553 +
8554 +If this prints 2 and 5, then the compiler's behavior is what you would
8555 +get from PCC_BITFIELD_TYPE_MATTERS.
8556 +*/
8557 +#define PCC_BITFIELD_TYPE_MATTERS 1
8558 +
8559 +
8560 +/******************************************************************************
8561 + * Layout of Source Language Data Types
8562 + *****************************************************************************/
8563 +
8564 +/*
8565 +A C expression for the size in bits of the type int on the
8566 +target machine. If you don't define this, the default is one word.
8567 +*/
8568 +#define INT_TYPE_SIZE 32
8569 +
8570 +/*
8571 +A C expression for the size in bits of the type short on the
8572 +target machine. If you don't define this, the default is half a word. (If
8573 +this would be less than one storage unit, it is rounded up to one unit.)
8574 +*/
8575 +#define SHORT_TYPE_SIZE 16
8576 +
8577 +/*
8578 +A C expression for the size in bits of the type long on the
8579 +target machine. If you don't define this, the default is one word.
8580 +*/
8581 +#define LONG_TYPE_SIZE 32
8582 +
8583 +
8584 +/*
8585 +A C expression for the size in bits of the type long long on the
8586 +target machine. If you don't define this, the default is two
8587 +words. If you want to support GNU Ada on your machine, the value of this
8588 +macro must be at least 64.
8589 +*/
8590 +#define LONG_LONG_TYPE_SIZE 64
8591 +
8592 +/*
8593 +A C expression for the size in bits of the type char on the
8594 +target machine. If you don't define this, the default is
8595 +BITS_PER_UNIT.
8596 +*/
8597 +#define CHAR_TYPE_SIZE 8
8598 +
8599 +
8600 +/*
8601 +A C expression for the size in bits of the C++ type bool and
8602 +C99 type _Bool on the target machine. If you don't define
8603 +this, and you probably shouldn't, the default is CHAR_TYPE_SIZE.
8604 +*/
8605 +#define BOOL_TYPE_SIZE 8
8606 +
8607 +
8608 +/*
8609 +An expression whose value is 1 or 0, according to whether the type
8610 +char should be signed or unsigned by default. The user can
8611 +always override this default with the options -fsigned-char
8612 +and -funsigned-char.
8613 +*/
8614 +/* We are using unsigned char */
8615 +#define DEFAULT_SIGNED_CHAR 0
8616 +
8617 +
8618 +/*
8619 +A C expression for a string describing the name of the data type to use
8620 +for size values. The typedef name size_t is defined using the
8621 +contents of the string.
8622 +
8623 +The string can contain more than one keyword. If so, separate them with
8624 +spaces, and write first any length keyword, then unsigned if
8625 +appropriate, and finally int. The string must exactly match one
8626 +of the data type names defined in the function
8627 +init_decl_processing in the file c-decl.c. You may not
8628 +omit int or change the order - that would cause the compiler to
8629 +crash on startup.
8630 +
8631 +If you don't define this macro, the default is "long unsigned int".
8632 +*/
8633 +#define SIZE_TYPE "long unsigned int"
8634 +
8635 +/*
8636 +A C expression for a string describing the name of the data type to use
8637 +for the result of subtracting two pointers. The typedef name
8638 +ptrdiff_t is defined using the contents of the string. See
8639 +SIZE_TYPE above for more information.
8640 +
8641 +If you don't define this macro, the default is "long int".
8642 +*/
8643 +#define PTRDIFF_TYPE "long int"
8644 +
8645 +
8646 +/*
8647 +A C expression for the size in bits of the data type for wide
8648 +characters. This is used in cpp, which cannot make use of
8649 +WCHAR_TYPE.
8650 +*/
8651 +#define WCHAR_TYPE_SIZE 32
8652 +
8653 +
8654 +/*
8655 +A C expression for a string describing the name of the data type to
8656 +use for wide characters passed to printf and returned from
8657 +getwc. The typedef name wint_t is defined using the
8658 +contents of the string. See SIZE_TYPE above for more
8659 +information.
8660 +
8661 +If you don't define this macro, the default is "unsigned int".
8662 +*/
8663 +#define WINT_TYPE "unsigned int"
8664 +
8665 +/*
8666 +A C expression for a string describing the name of the data type that
8667 +can represent any value of any standard or extended signed integer type.
8668 +The typedef name intmax_t is defined using the contents of the
8669 +string. See SIZE_TYPE above for more information.
8670 +
8671 +If you don't define this macro, the default is the first of
8672 +"int", "long int", or "long long int" that has as
8673 +much precision as long long int.
8674 +*/
8675 +#define INTMAX_TYPE "long long int"
8676 +
8677 +/*
8678 +A C expression for a string describing the name of the data type that
8679 +can represent any value of any standard or extended unsigned integer
8680 +type. The typedef name uintmax_t is defined using the contents
8681 +of the string. See SIZE_TYPE above for more information.
8682 +
8683 +If you don't define this macro, the default is the first of
8684 +"unsigned int", "long unsigned int", or "long long unsigned int"
8685 +that has as much precision as long long unsigned int.
8686 +*/
8687 +#define UINTMAX_TYPE "long long unsigned int"
8688 +
8689 +
8690 +/******************************************************************************
8691 + * Register Usage
8692 + *****************************************************************************/
8693 +
8694 +/* Convert from gcc internal register number to register number
8695 + used in assembly code */
8696 +#define ASM_REGNUM(reg) (LAST_REGNUM - (reg))
8697 +#define ASM_FP_REGNUM(reg) (LAST_FP_REGNUM - (reg))
8698 +
8699 +/* Convert between register number used in assembly to gcc
8700 + internal register number */
8701 +#define INTERNAL_REGNUM(reg) (LAST_REGNUM - (reg))
8702 +#define INTERNAL_FP_REGNUM(reg) (LAST_FP_REGNUM - (reg))
8703 +
8704 +/** Basic Characteristics of Registers **/
8705 +
8706 +/*
8707 +Number of hardware registers known to the compiler. They receive
8708 +numbers 0 through FIRST_PSEUDO_REGISTER-1; thus, the first
8709 +pseudo register's number really is assigned the number
8710 +FIRST_PSEUDO_REGISTER.
8711 +*/
8712 +#define FIRST_PSEUDO_REGISTER (LAST_FP_REGNUM + 1)
8713 +
8714 +#define FIRST_REGNUM 0
8715 +#define LAST_REGNUM 15
8716 +#define NUM_FP_REGS 16
8717 +#define FIRST_FP_REGNUM 16
8718 +#define LAST_FP_REGNUM (16+NUM_FP_REGS-1)
8719 +
8720 +/*
8721 +An initializer that says which registers are used for fixed purposes
8722 +all throughout the compiled code and are therefore not available for
8723 +general allocation. These would include the stack pointer, the frame
8724 +pointer (except on machines where that can be used as a general
8725 +register when no frame pointer is needed), the program counter on
8726 +machines where that is considered one of the addressable registers,
8727 +and any other numbered register with a standard use.
8728 +
8729 +This information is expressed as a sequence of numbers, separated by
8730 +commas and surrounded by braces. The nth number is 1 if
8731 +register n is fixed, 0 otherwise.
8732 +
8733 +The table initialized from this macro, and the table initialized by
8734 +the following one, may be overridden at run time either automatically,
8735 +by the actions of the macro CONDITIONAL_REGISTER_USAGE, or by
8736 +the user with the command options -ffixed-[reg],
8737 +-fcall-used-[reg] and -fcall-saved-[reg].
8738 +*/
8739 +
8740 +/* The internal gcc register numbers are reversed
8741 + compared to the real register numbers since
8742 + gcc expects data types stored over multiple
8743 + registers in the register file to be big endian
8744 + if the memory layout is big endian. But this
8745 + is not the case for avr32 so we fake a big
8746 + endian register file. */
8747 +
8748 +#define FIXED_REGISTERS { \
8749 + 1, /* Program Counter */ \
8750 + 0, /* Link Register */ \
8751 + 1, /* Stack Pointer */ \
8752 + 0, /* r12 */ \
8753 + 0, /* r11 */ \
8754 + 0, /* r10 */ \
8755 + 0, /* r9 */ \
8756 + 0, /* r8 */ \
8757 + 0, /* r7 */ \
8758 + 0, /* r6 */ \
8759 + 0, /* r5 */ \
8760 + 0, /* r4 */ \
8761 + 0, /* r3 */ \
8762 + 0, /* r2 */ \
8763 + 0, /* r1 */ \
8764 + 0, /* r0 */ \
8765 + 0, /* f15 */ \
8766 + 0, /* f14 */ \
8767 + 0, /* f13 */ \
8768 + 0, /* f12 */ \
8769 + 0, /* f11 */ \
8770 + 0, /* f10 */ \
8771 + 0, /* f9 */ \
8772 + 0, /* f8 */ \
8773 + 0, /* f7 */ \
8774 + 0, /* f6 */ \
8775 + 0, /* f5 */ \
8776 + 0, /* f4 */ \
8777 + 0, /* f3 */ \
8778 + 0, /* f2*/ \
8779 + 0, /* f1 */ \
8780 + 0 /* f0 */ \
8781 +}
8782 +
8783 +/*
8784 +Like FIXED_REGISTERS but has 1 for each register that is
8785 +clobbered (in general) by function calls as well as for fixed
8786 +registers. This macro therefore identifies the registers that are not
8787 +available for general allocation of values that must live across
8788 +function calls.
8789 +
8790 +If a register has 0 in CALL_USED_REGISTERS, the compiler
8791 +automatically saves it on function entry and restores it on function
8792 +exit, if the register is used within the function.
8793 +*/
8794 +#define CALL_USED_REGISTERS { \
8795 + 1, /* Program Counter */ \
8796 + 0, /* Link Register */ \
8797 + 1, /* Stack Pointer */ \
8798 + 1, /* r12 */ \
8799 + 1, /* r11 */ \
8800 + 1, /* r10 */ \
8801 + 1, /* r9 */ \
8802 + 1, /* r8 */ \
8803 + 0, /* r7 */ \
8804 + 0, /* r6 */ \
8805 + 0, /* r5 */ \
8806 + 0, /* r4 */ \
8807 + 0, /* r3 */ \
8808 + 0, /* r2 */ \
8809 + 0, /* r1 */ \
8810 + 0, /* r0 */ \
8811 + 1, /* f15 */ \
8812 + 1, /* f14 */ \
8813 + 1, /* f13 */ \
8814 + 1, /* f12 */ \
8815 + 1, /* f11 */ \
8816 + 1, /* f10 */ \
8817 + 1, /* f9 */ \
8818 + 1, /* f8 */ \
8819 + 0, /* f7 */ \
8820 + 0, /* f6 */ \
8821 + 0, /* f5 */ \
8822 + 0, /* f4 */ \
8823 + 0, /* f3 */ \
8824 + 0, /* f2*/ \
8825 + 0, /* f1*/ \
8826 + 0, /* f0 */ \
8827 +}
8828 +
8829 +/* Interrupt functions can only use registers that have already been
8830 + saved by the prologue, even if they would normally be
8831 + call-clobbered. */
8832 +#define HARD_REGNO_RENAME_OK(SRC, DST) \
8833 + (! IS_INTERRUPT (cfun->machine->func_type) || \
8834 + df_regs_ever_live_p (DST))
8835 +
8836 +
8837 +/*
8838 +Zero or more C statements that may conditionally modify five variables
8839 +fixed_regs, call_used_regs, global_regs,
8840 +reg_names, and reg_class_contents, to take into account
8841 +any dependence of these register sets on target flags. The first three
8842 +of these are of type char [] (interpreted as Boolean vectors).
8843 +global_regs is a const char *[], and
8844 +reg_class_contents is a HARD_REG_SET. Before the macro is
8845 +called, fixed_regs, call_used_regs,
8846 +reg_class_contents, and reg_names have been initialized
8847 +from FIXED_REGISTERS, CALL_USED_REGISTERS,
8848 +REG_CLASS_CONTENTS, and REGISTER_NAMES, respectively.
8849 +global_regs has been cleared, and any -ffixed-[reg],
8850 +-fcall-used-[reg] and -fcall-saved-[reg]
8851 +command options have been applied.
8852 +
8853 +You need not define this macro if it has no work to do.
8854 +
8855 +If the usage of an entire class of registers depends on the target
8856 +flags, you may indicate this to GCC by using this macro to modify
8857 +fixed_regs and call_used_regs to 1 for each of the
8858 +registers in the classes which should not be used by GCC. Also define
8859 +the macro REG_CLASS_FROM_LETTER to return NO_REGS if it
8860 +is called with a letter for a class that shouldn't be used.
8861 +
8862 + (However, if this class is not included in GENERAL_REGS and all
8863 +of the insn patterns whose constraints permit this class are
8864 +controlled by target switches, then GCC will automatically avoid using
8865 +these registers when the target switches are opposed to them.)
8866 +*/
8867 +#define CONDITIONAL_REGISTER_USAGE \
8868 + do \
8869 + { \
8870 + int regno; \
8871 + \
8872 + if (TARGET_SOFT_FLOAT) \
8873 + { \
8874 + for (regno = FIRST_FP_REGNUM; \
8875 + regno <= LAST_FP_REGNUM; ++regno) \
8876 + fixed_regs[regno] = call_used_regs[regno] = 1; \
8877 + } \
8878 + if (flag_pic) \
8879 + { \
8880 + fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1; \
8881 + call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1; \
8882 + } \
8883 + } \
8884 + while (0)
8885 +
8886 +
8887 +/*
8888 +If the program counter has a register number, define this as that
8889 +register number. Otherwise, do not define it.
8890 +*/
8891 +
8892 +#define LAST_AVR32_REGNUM 16
8893 +
8894 +
8895 +/** Order of Allocation of Registers **/
8896 +
8897 +/*
8898 +If defined, an initializer for a vector of integers, containing the
8899 +numbers of hard registers in the order in which GCC should prefer
8900 +to use them (from most preferred to least).
8901 +
8902 +If this macro is not defined, registers are used lowest numbered first
8903 +(all else being equal).
8904 +
8905 +One use of this macro is on machines where the highest numbered
8906 +registers must always be saved and the save-multiple-registers
8907 +instruction supports only sequences of consecutive registers. On such
8908 +machines, define REG_ALLOC_ORDER to be an initializer that lists
8909 +the highest numbered allocable register first.
8910 +*/
8911 +#define REG_ALLOC_ORDER \
8912 +{ \
8913 + INTERNAL_REGNUM(8), \
8914 + INTERNAL_REGNUM(9), \
8915 + INTERNAL_REGNUM(10), \
8916 + INTERNAL_REGNUM(11), \
8917 + INTERNAL_REGNUM(12), \
8918 + LR_REGNUM, \
8919 + INTERNAL_REGNUM(7), \
8920 + INTERNAL_REGNUM(6), \
8921 + INTERNAL_REGNUM(5), \
8922 + INTERNAL_REGNUM(4), \
8923 + INTERNAL_REGNUM(3), \
8924 + INTERNAL_REGNUM(2), \
8925 + INTERNAL_REGNUM(1), \
8926 + INTERNAL_REGNUM(0), \
8927 + INTERNAL_FP_REGNUM(15), \
8928 + INTERNAL_FP_REGNUM(14), \
8929 + INTERNAL_FP_REGNUM(13), \
8930 + INTERNAL_FP_REGNUM(12), \
8931 + INTERNAL_FP_REGNUM(11), \
8932 + INTERNAL_FP_REGNUM(10), \
8933 + INTERNAL_FP_REGNUM(9), \
8934 + INTERNAL_FP_REGNUM(8), \
8935 + INTERNAL_FP_REGNUM(7), \
8936 + INTERNAL_FP_REGNUM(6), \
8937 + INTERNAL_FP_REGNUM(5), \
8938 + INTERNAL_FP_REGNUM(4), \
8939 + INTERNAL_FP_REGNUM(3), \
8940 + INTERNAL_FP_REGNUM(2), \
8941 + INTERNAL_FP_REGNUM(1), \
8942 + INTERNAL_FP_REGNUM(0), \
8943 + SP_REGNUM, \
8944 + PC_REGNUM \
8945 +}
8946 +
8947 +
8948 +/** How Values Fit in Registers **/
8949 +
8950 +/*
8951 +A C expression for the number of consecutive hard registers, starting
8952 +at register number REGNO, required to hold a value of mode
8953 +MODE.
8954 +
8955 +On a machine where all registers are exactly one word, a suitable
8956 +definition of this macro is
8957 +
8958 +#define HARD_REGNO_NREGS(REGNO, MODE) \
8959 + ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
8960 + / UNITS_PER_WORD)
8961 +*/
8962 +#define HARD_REGNO_NREGS(REGNO, MODE) \
8963 + ((unsigned int)((GET_MODE_SIZE(MODE) + UNITS_PER_WORD -1 ) / UNITS_PER_WORD))
8964 +
8965 +/*
8966 +A C expression that is nonzero if it is permissible to store a value
8967 +of mode MODE in hard register number REGNO (or in several
8968 +registers starting with that one). For a machine where all registers
8969 +are equivalent, a suitable definition is
8970 +
8971 + #define HARD_REGNO_MODE_OK(REGNO, MODE) 1
8972 +
8973 +You need not include code to check for the numbers of fixed registers,
8974 +because the allocation mechanism considers them to be always occupied.
8975 +
8976 +On some machines, double-precision values must be kept in even/odd
8977 +register pairs. You can implement that by defining this macro to reject
8978 +odd register numbers for such modes.
8979 +
8980 +The minimum requirement for a mode to be OK in a register is that the
8981 +mov[mode] instruction pattern support moves between the
8982 +register and other hard register in the same class and that moving a
8983 +value into the register and back out not alter it.
8984 +
8985 +Since the same instruction used to move word_mode will work for
8986 +all narrower integer modes, it is not necessary on any machine for
8987 +HARD_REGNO_MODE_OK to distinguish between these modes, provided
8988 +you define patterns movhi, etc., to take advantage of this. This
8989 +is useful because of the interaction between HARD_REGNO_MODE_OK
8990 +and MODES_TIEABLE_P; it is very desirable for all integer modes
8991 +to be tieable.
8992 +
8993 +Many machines have special registers for floating point arithmetic.
8994 +Often people assume that floating point machine modes are allowed only
8995 +in floating point registers. This is not true. Any registers that
8996 +can hold integers can safely hold a floating point machine
8997 +mode, whether or not floating arithmetic can be done on it in those
8998 +registers. Integer move instructions can be used to move the values.
8999 +
9000 +On some machines, though, the converse is true: fixed-point machine
9001 +modes may not go in floating registers. This is true if the floating
9002 +registers normalize any value stored in them, because storing a
9003 +non-floating value there would garble it. In this case,
9004 +HARD_REGNO_MODE_OK should reject fixed-point machine modes in
9005 +floating registers. But if the floating registers do not automatically
9006 +normalize, if you can store any bit pattern in one and retrieve it
9007 +unchanged without a trap, then any machine mode may go in a floating
9008 +register, so you can define this macro to say so.
9009 +
9010 +The primary significance of special floating registers is rather that
9011 +they are the registers acceptable in floating point arithmetic
9012 +instructions. However, this is of no concern to
9013 +HARD_REGNO_MODE_OK. You handle it by writing the proper
9014 +constraints for those instructions.
9015 +
9016 +On some machines, the floating registers are especially slow to access,
9017 +so that it is better to store a value in a stack frame than in such a
9018 +register if floating point arithmetic is not being done. As long as the
9019 +floating registers are not in class GENERAL_REGS, they will not
9020 +be used unless some pattern's constraint asks for one.
9021 +*/
9022 +#define HARD_REGNO_MODE_OK(REGNO, MODE) avr32_hard_regno_mode_ok(REGNO, MODE)
9023 +
9024 +/*
9025 +A C expression that is nonzero if a value of mode
9026 +MODE1 is accessible in mode MODE2 without copying.
9027 +
9028 +If HARD_REGNO_MODE_OK(R, MODE1) and
9029 +HARD_REGNO_MODE_OK(R, MODE2) are always the same for
9030 +any R, then MODES_TIEABLE_P(MODE1, MODE2)
9031 +should be nonzero. If they differ for any R, you should define
9032 +this macro to return zero unless some other mechanism ensures the
9033 +accessibility of the value in a narrower mode.
9034 +
9035 +You should define this macro to return nonzero in as many cases as
9036 +possible since doing so will allow GCC to perform better register
9037 +allocation.
9038 +*/
9039 +#define MODES_TIEABLE_P(MODE1, MODE2) \
9040 + (GET_MODE_CLASS (MODE1) == GET_MODE_CLASS (MODE2))
9041 +
9042 +
9043 +
9044 +/******************************************************************************
9045 + * Register Classes
9046 + *****************************************************************************/
9047 +
9048 +/*
9049 +An enumeral type that must be defined with all the register class names
9050 +as enumeral values. NO_REGS must be first. ALL_REGS
9051 +must be the last register class, followed by one more enumeral value,
9052 +LIM_REG_CLASSES, which is not a register class but rather
9053 +tells how many classes there are.
9054 +
9055 +Each register class has a number, which is the value of casting
9056 +the class name to type int. The number serves as an index
9057 +in many of the tables described below.
9058 +*/
9059 +enum reg_class
9060 +{
9061 + NO_REGS,
9062 + GENERAL_REGS,
9063 + FP_REGS,
9064 + ALL_REGS,
9065 + LIM_REG_CLASSES
9066 +};
9067 +
9068 +/*
9069 +The number of distinct register classes, defined as follows:
9070 + #define N_REG_CLASSES (int) LIM_REG_CLASSES
9071 +*/
9072 +#define N_REG_CLASSES (int)LIM_REG_CLASSES
9073 +
9074 +/*
9075 +An initializer containing the names of the register classes as C string
9076 +constants. These names are used in writing some of the debugging dumps.
9077 +*/
9078 +#define REG_CLASS_NAMES \
9079 +{ \
9080 + "NO_REGS", \
9081 + "GENERAL_REGS", \
9082 + "FLOATING_POINT_REGS", \
9083 + "ALL_REGS" \
9084 +}
9085 +
9086 +/*
9087 +An initializer containing the contents of the register classes, as integers
9088 +which are bit masks. The nth integer specifies the contents of class
9089 +n. The way the integer mask is interpreted is that
9090 +register r is in the class if mask & (1 << r) is 1.
9091 +
9092 +When the machine has more than 32 registers, an integer does not suffice.
9093 +Then the integers are replaced by sub-initializers, braced groupings containing
9094 +several integers. Each sub-initializer must be suitable as an initializer
9095 +for the type HARD_REG_SET which is defined in hard-reg-set.h.
9096 +In this situation, the first integer in each sub-initializer corresponds to
9097 +registers 0 through 31, the second integer to registers 32 through 63, and
9098 +so on.
9099 +*/
9100 +#define REG_CLASS_CONTENTS { \
9101 + {0x00000000}, /* NO_REGS */ \
9102 + {0x0000FFFF}, /* GENERAL_REGS */ \
9103 + {0xFFFF0000}, /* FP_REGS */ \
9104 + {0x7FFFFFFF}, /* ALL_REGS */ \
9105 +}
9106 +
9107 +
9108 +/*
9109 +A C expression whose value is a register class containing hard register
9110 +REGNO. In general there is more than one such class; choose a class
9111 +which is minimal, meaning that no smaller class also contains the
9112 +register.
9113 +*/
9114 +#define REGNO_REG_CLASS(REGNO) ((REGNO < 16) ? GENERAL_REGS : FP_REGS)
9115 +
9116 +/*
9117 +A macro whose definition is the name of the class to which a valid
9118 +base register must belong. A base register is one used in an address
9119 +which is the register value plus a displacement.
9120 +*/
9121 +#define BASE_REG_CLASS GENERAL_REGS
9122 +
9123 +/*
9124 +This is a variation of the BASE_REG_CLASS macro which allows
9125 +the selection of a base register in a mode depenedent manner. If
9126 +mode is VOIDmode then it should return the same value as
9127 +BASE_REG_CLASS.
9128 +*/
9129 +#define MODE_BASE_REG_CLASS(MODE) BASE_REG_CLASS
9130 +
9131 +/*
9132 +A macro whose definition is the name of the class to which a valid
9133 +index register must belong. An index register is one used in an
9134 +address where its value is either multiplied by a scale factor or
9135 +added to another register (as well as added to a displacement).
9136 +*/
9137 +#define INDEX_REG_CLASS BASE_REG_CLASS
9138 +
9139 +/*
9140 +A C expression which defines the machine-dependent operand constraint
9141 +letters for register classes. If CHAR is such a letter, the
9142 +value should be the register class corresponding to it. Otherwise,
9143 +the value should be NO_REGS. The register letter r,
9144 +corresponding to class GENERAL_REGS, will not be passed
9145 +to this macro; you do not need to handle it.
9146 +*/
9147 +#define REG_CLASS_FROM_LETTER(CHAR) ((CHAR) == 'f' ? FP_REGS : NO_REGS)
9148 +
9149 +
9150 +/* These assume that REGNO is a hard or pseudo reg number.
9151 + They give nonzero only if REGNO is a hard reg of the suitable class
9152 + or a pseudo reg currently allocated to a suitable hard reg.
9153 + Since they use reg_renumber, they are safe only once reg_renumber
9154 + has been allocated, which happens in local-alloc.c. */
9155 +#define TEST_REGNO(R, TEST, VALUE) \
9156 + ((R TEST VALUE) || ((unsigned) reg_renumber[R] TEST VALUE))
9157 +
9158 +/*
9159 +A C expression which is nonzero if register number num is suitable for use as a base
9160 +register in operand addresses. It may be either a suitable hard register or a pseudo
9161 +register that has been allocated such a hard register.
9162 +*/
9163 +#define REGNO_OK_FOR_BASE_P(NUM) TEST_REGNO(NUM, <=, LAST_REGNUM)
9164 +
9165 +/*
9166 +A C expression which is nonzero if register number NUM is
9167 +suitable for use as an index register in operand addresses. It may be
9168 +either a suitable hard register or a pseudo register that has been
9169 +allocated such a hard register.
9170 +
9171 +The difference between an index register and a base register is that
9172 +the index register may be scaled. If an address involves the sum of
9173 +two registers, neither one of them scaled, then either one may be
9174 +labeled the ``base'' and the other the ``index''; but whichever
9175 +labeling is used must fit the machine's constraints of which registers
9176 +may serve in each capacity. The compiler will try both labelings,
9177 +looking for one that is valid, and will reload one or both registers
9178 +only if neither labeling works.
9179 +*/
9180 +#define REGNO_OK_FOR_INDEX_P(NUM) TEST_REGNO(NUM, <=, LAST_REGNUM)
9181 +
9182 +/*
9183 +A C expression that places additional restrictions on the register class
9184 +to use when it is necessary to copy value X into a register in class
9185 +CLASS. The value is a register class; perhaps CLASS, or perhaps
9186 +another, smaller class. On many machines, the following definition is
9187 +safe: #define PREFERRED_RELOAD_CLASS(X,CLASS) CLASS
9188 +
9189 +Sometimes returning a more restrictive class makes better code. For
9190 +example, on the 68000, when X is an integer constant that is in range
9191 +for a 'moveq' instruction, the value of this macro is always
9192 +DATA_REGS as long as CLASS includes the data registers.
9193 +Requiring a data register guarantees that a 'moveq' will be used.
9194 +
9195 +If X is a const_double, by returning NO_REGS
9196 +you can force X into a memory constant. This is useful on
9197 +certain machines where immediate floating values cannot be loaded into
9198 +certain kinds of registers.
9199 +*/
9200 +#define PREFERRED_RELOAD_CLASS(X, CLASS) CLASS
9201 +
9202 +
9203 +
9204 +/*
9205 +A C expression for the maximum number of consecutive registers
9206 +of class CLASS needed to hold a value of mode MODE.
9207 +
9208 +This is closely related to the macro HARD_REGNO_NREGS. In fact,
9209 +the value of the macro CLASS_MAX_NREGS(CLASS, MODE)
9210 +should be the maximum value of HARD_REGNO_NREGS(REGNO, MODE)
9211 +for all REGNO values in the class CLASS.
9212 +
9213 +This macro helps control the handling of multiple-word values
9214 +in the reload pass.
9215 +*/
9216 +#define CLASS_MAX_NREGS(CLASS, MODE) /* ToDo:fixme */ \
9217 + (unsigned int)((GET_MODE_SIZE(MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
9218 +
9219 +
9220 +/*
9221 + Using CONST_OK_FOR_CONSTRAINT_P instead of CONS_OK_FOR_LETTER_P
9222 + in order to support constraints with more than one letter.
9223 + Only two letters are then used for constant constraints,
9224 + the letter 'K' and the letter 'I'. The constraint starting with
9225 + these letters must consist of four characters. The character following
9226 + 'K' or 'I' must be either 'u' (unsigned) or 's' (signed) to specify
9227 + if the constant is zero or sign extended. The last two characters specify
9228 + the length in bits of the constant. The base constraint letter 'I' means
9229 + that this is an negated constant, meaning that actually -VAL should be
9230 + checked to lie withing the valid range instead of VAL which is used when
9231 + 'K' is the base constraint letter.
9232 +
9233 +*/
9234 +
9235 +#define CONSTRAINT_LEN(C, STR) \
9236 + ( ((C) == 'K' || (C) == 'I') ? 4 : \
9237 + ((C) == 'R') ? 5 : \
9238 + ((C) == 'N' || (C) == 'O' || \
9239 + (C) == 'P' || (C) == 'L') ? -1 : \
9240 + DEFAULT_CONSTRAINT_LEN((C), (STR)) )
9241 +
9242 +#define CONST_OK_FOR_CONSTRAINT_P(VALUE, C, STR) \
9243 + avr32_const_ok_for_constraint_p(VALUE, C, STR)
9244 +
9245 +/*
9246 +A C expression that defines the machine-dependent operand constraint
9247 +letters that specify particular ranges of const_double values ('G' or 'H').
9248 +
9249 +If C is one of those letters, the expression should check that
9250 +VALUE, an RTX of code const_double, is in the appropriate
9251 +range and return 1 if so, 0 otherwise. If C is not one of those
9252 +letters, the value should be 0 regardless of VALUE.
9253 +
9254 +const_double is used for all floating-point constants and for
9255 +DImode fixed-point constants. A given letter can accept either
9256 +or both kinds of values. It can use GET_MODE to distinguish
9257 +between these kinds.
9258 +*/
9259 +#define CONST_DOUBLE_OK_FOR_LETTER_P(OP, C) \
9260 + ((C) == 'G' ? avr32_const_double_immediate(OP) : 0)
9261 +
9262 +/*
9263 +A C expression that defines the optional machine-dependent constraint
9264 +letters that can be used to segregate specific types of operands, usually
9265 +memory references, for the target machine. Any letter that is not
9266 +elsewhere defined and not matched by REG_CLASS_FROM_LETTER
9267 +may be used. Normally this macro will not be defined.
9268 +
9269 +If it is required for a particular target machine, it should return 1
9270 +if VALUE corresponds to the operand type represented by the
9271 +constraint letter C. If C is not defined as an extra
9272 +constraint, the value returned should be 0 regardless of VALUE.
9273 +
9274 +For example, on the ROMP, load instructions cannot have their output
9275 +in r0 if the memory reference contains a symbolic address. Constraint
9276 +letter 'Q' is defined as representing a memory address that does
9277 +not contain a symbolic address. An alternative is specified with
9278 +a 'Q' constraint on the input and 'r' on the output. The next
9279 +alternative specifies 'm' on the input and a register class that
9280 +does not include r0 on the output.
9281 +*/
9282 +#define EXTRA_CONSTRAINT_STR(OP, C, STR) \
9283 + ((C) == 'W' ? avr32_address_operand(OP, GET_MODE(OP)) : \
9284 + (C) == 'R' ? (avr32_indirect_register_operand(OP, GET_MODE(OP)) || \
9285 + (avr32_imm_disp_memory_operand(OP, GET_MODE(OP)) \
9286 + && avr32_const_ok_for_constraint_p( \
9287 + INTVAL(XEXP(XEXP(OP, 0), 1)), \
9288 + (STR)[1], &(STR)[1]))) : \
9289 + (C) == 'S' ? avr32_indexed_memory_operand(OP, GET_MODE(OP)) : \
9290 + (C) == 'T' ? avr32_const_pool_ref_operand(OP, GET_MODE(OP)) : \
9291 + (C) == 'U' ? SYMBOL_REF_RCALL_FUNCTION_P(OP) : \
9292 + (C) == 'Z' ? avr32_cop_memory_operand(OP, GET_MODE(OP)) : \
9293 + 0)
9294 +
9295 +
9296 +#define EXTRA_MEMORY_CONSTRAINT(C, STR) ( ((C) == 'R') || \
9297 + ((C) == 'S') || \
9298 + ((C) == 'Z') )
9299 +
9300 +
9301 +/* Returns nonzero if op is a function SYMBOL_REF which
9302 + can be called using an rcall instruction */
9303 +#define SYMBOL_REF_RCALL_FUNCTION_P(op) \
9304 + ( GET_CODE(op) == SYMBOL_REF \
9305 + && SYMBOL_REF_FUNCTION_P(op) \
9306 + && SYMBOL_REF_LOCAL_P(op) \
9307 + && !SYMBOL_REF_EXTERNAL_P(op) \
9308 + && !TARGET_HAS_ASM_ADDR_PSEUDOS )
9309 +
9310 +/******************************************************************************
9311 + * Stack Layout and Calling Conventions
9312 + *****************************************************************************/
9313 +
9314 +/** Basic Stack Layout **/
9315 +
9316 +/*
9317 +Define this macro if pushing a word onto the stack moves the stack
9318 +pointer to a smaller address.
9319 +
9320 +When we say, ``define this macro if ...,'' it means that the
9321 +compiler checks this macro only with #ifdef so the precise
9322 +definition used does not matter.
9323 +*/
9324 +/* pushm decrece SP: *(--SP) <-- Rx */
9325 +#define STACK_GROWS_DOWNWARD
9326 +
9327 +/*
9328 +This macro defines the operation used when something is pushed
9329 +on the stack. In RTL, a push operation will be
9330 +(set (mem (STACK_PUSH_CODE (reg sp))) ...)
9331 +
9332 +The choices are PRE_DEC, POST_DEC, PRE_INC,
9333 +and POST_INC. Which of these is correct depends on
9334 +the stack direction and on whether the stack pointer points
9335 +to the last item on the stack or whether it points to the
9336 +space for the next item on the stack.
9337 +
9338 +The default is PRE_DEC when STACK_GROWS_DOWNWARD is
9339 +defined, which is almost always right, and PRE_INC otherwise,
9340 +which is often wrong.
9341 +*/
9342 +/* pushm: *(--SP) <-- Rx */
9343 +#define STACK_PUSH_CODE PRE_DEC
9344 +
9345 +/* Define this to nonzero if the nominal address of the stack frame
9346 + is at the high-address end of the local variables;
9347 + that is, each additional local variable allocated
9348 + goes at a more negative offset in the frame. */
9349 +#define FRAME_GROWS_DOWNWARD 1
9350 +
9351 +
9352 +/*
9353 +Offset from the frame pointer to the first local variable slot to be allocated.
9354 +
9355 +If FRAME_GROWS_DOWNWARD, find the next slot's offset by
9356 +subtracting the first slot's length from STARTING_FRAME_OFFSET.
9357 +Otherwise, it is found by adding the length of the first slot to the
9358 +value STARTING_FRAME_OFFSET.
9359 + (i'm not sure if the above is still correct.. had to change it to get
9360 + rid of an overfull. --mew 2feb93 )
9361 +*/
9362 +#define STARTING_FRAME_OFFSET 0
9363 +
9364 +/*
9365 +Offset from the stack pointer register to the first location at which
9366 +outgoing arguments are placed. If not specified, the default value of
9367 +zero is used. This is the proper value for most machines.
9368 +
9369 +If ARGS_GROW_DOWNWARD, this is the offset to the location above
9370 +the first location at which outgoing arguments are placed.
9371 +*/
9372 +#define STACK_POINTER_OFFSET 0
9373 +
9374 +/*
9375 +Offset from the argument pointer register to the first argument's
9376 +address. On some machines it may depend on the data type of the
9377 +function.
9378 +
9379 +If ARGS_GROW_DOWNWARD, this is the offset to the location above
9380 +the first argument's address.
9381 +*/
9382 +#define FIRST_PARM_OFFSET(FUNDECL) 0
9383 +
9384 +
9385 +/*
9386 +A C expression whose value is RTL representing the address in a stack
9387 +frame where the pointer to the caller's frame is stored. Assume that
9388 +FRAMEADDR is an RTL expression for the address of the stack frame
9389 +itself.
9390 +
9391 +If you don't define this macro, the default is to return the value
9392 +of FRAMEADDR - that is, the stack frame address is also the
9393 +address of the stack word that points to the previous frame.
9394 +*/
9395 +#define DYNAMIC_CHAIN_ADDRESS(FRAMEADDR) plus_constant ((FRAMEADDR), 4)
9396 +
9397 +
9398 +/*
9399 +A C expression whose value is RTL representing the value of the return
9400 +address for the frame COUNT steps up from the current frame, after
9401 +the prologue. FRAMEADDR is the frame pointer of the COUNT
9402 +frame, or the frame pointer of the COUNT - 1 frame if
9403 +RETURN_ADDR_IN_PREVIOUS_FRAME is defined.
9404 +
9405 +The value of the expression must always be the correct address when
9406 +COUNT is zero, but may be NULL_RTX if there is not way to
9407 +determine the return address of other frames.
9408 +*/
9409 +#define RETURN_ADDR_RTX(COUNT, FRAMEADDR) avr32_return_addr(COUNT, FRAMEADDR)
9410 +
9411 +
9412 +/*
9413 +A C expression whose value is RTL representing the location of the
9414 +incoming return address at the beginning of any function, before the
9415 +prologue. This RTL is either a REG, indicating that the return
9416 +value is saved in 'REG', or a MEM representing a location in
9417 +the stack.
9418 +
9419 +You only need to define this macro if you want to support call frame
9420 +debugging information like that provided by DWARF 2.
9421 +
9422 +If this RTL is a REG, you should also define
9423 +DWARF_FRAME_RETURN_COLUMN to DWARF_FRAME_REGNUM (REGNO).
9424 +*/
9425 +#define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (Pmode, LR_REGNUM)
9426 +
9427 +
9428 +
9429 +/*
9430 +A C expression whose value is an integer giving the offset, in bytes,
9431 +from the value of the stack pointer register to the top of the stack
9432 +frame at the beginning of any function, before the prologue. The top of
9433 +the frame is defined to be the value of the stack pointer in the
9434 +previous frame, just before the call instruction.
9435 +
9436 +You only need to define this macro if you want to support call frame
9437 +debugging information like that provided by DWARF 2.
9438 +*/
9439 +#define INCOMING_FRAME_SP_OFFSET 0
9440 +
9441 +
9442 +/** Exception Handling Support **/
9443 +
9444 +/* Use setjump/longjump for exception handling. */
9445 +#define DWARF2_UNWIND_INFO 0
9446 +#define MUST_USE_SJLJ_EXCEPTIONS 1
9447 +
9448 +/*
9449 +A C expression whose value is the Nth register number used for
9450 +data by exception handlers, or INVALID_REGNUM if fewer than
9451 +N registers are usable.
9452 +
9453 +The exception handling library routines communicate with the exception
9454 +handlers via a set of agreed upon registers. Ideally these registers
9455 +should be call-clobbered; it is possible to use call-saved registers,
9456 +but may negatively impact code size. The target must support at least
9457 +2 data registers, but should define 4 if there are enough free registers.
9458 +
9459 +You must define this macro if you want to support call frame exception
9460 +handling like that provided by DWARF 2.
9461 +*/
9462 +/*
9463 + Use r9-r11
9464 +*/
9465 +#define EH_RETURN_DATA_REGNO(N) \
9466 + ((N<3) ? INTERNAL_REGNUM(N+9) : INVALID_REGNUM)
9467 +
9468 +/*
9469 +A C expression whose value is RTL representing a location in which
9470 +to store a stack adjustment to be applied before function return.
9471 +This is used to unwind the stack to an exception handler's call frame.
9472 +It will be assigned zero on code paths that return normally.
9473 +
9474 +Typically this is a call-clobbered hard register that is otherwise
9475 +untouched by the epilogue, but could also be a stack slot.
9476 +
9477 +You must define this macro if you want to support call frame exception
9478 +handling like that provided by DWARF 2.
9479 +*/
9480 +/*
9481 + Use r8
9482 +*/
9483 +#define EH_RETURN_STACKADJ_REGNO INTERNAL_REGNUM(8)
9484 +#define EH_RETURN_STACKADJ_RTX gen_rtx_REG(SImode, EH_RETURN_STACKADJ_REGNO)
9485 +
9486 +/*
9487 +A C expression whose value is RTL representing a location in which
9488 +to store the address of an exception handler to which we should
9489 +return. It will not be assigned on code paths that return normally.
9490 +
9491 +Typically this is the location in the call frame at which the normal
9492 +return address is stored. For targets that return by popping an
9493 +address off the stack, this might be a memory address just below
9494 +the target call frame rather than inside the current call
9495 +frame. EH_RETURN_STACKADJ_RTX will have already been assigned,
9496 +so it may be used to calculate the location of the target call frame.
9497 +
9498 +Some targets have more complex requirements than storing to an
9499 +address calculable during initial code generation. In that case
9500 +the eh_return instruction pattern should be used instead.
9501 +
9502 +If you want to support call frame exception handling, you must
9503 +define either this macro or the eh_return instruction pattern.
9504 +*/
9505 +/*
9506 + We define the eh_return instruction pattern, so this isn't needed.
9507 +*/
9508 +/* #define EH_RETURN_HANDLER_RTX gen_rtx_REG(Pmode, RET_REGISTER) */
9509 +
9510 +/*
9511 + This macro chooses the encoding of pointers embedded in the
9512 + exception handling sections. If at all possible, this should be
9513 + defined such that the exception handling section will not require
9514 + dynamic relocations, and so may be read-only.
9515 +
9516 + code is 0 for data, 1 for code labels, 2 for function
9517 + pointers. global is true if the symbol may be affected by dynamic
9518 + relocations. The macro should return a combination of the DW_EH_PE_*
9519 + defines as found in dwarf2.h.
9520 +
9521 + If this macro is not defined, pointers will not be encoded but
9522 + represented directly.
9523 +*/
9524 +#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
9525 + ((flag_pic && (GLOBAL) ? DW_EH_PE_indirect : 0) \
9526 + | (flag_pic ? DW_EH_PE_pcrel : DW_EH_PE_absptr) \
9527 + | DW_EH_PE_sdata4)
9528 +
9529 +/* ToDo: The rest of this subsection */
9530 +
9531 +/** Specifying How Stack Checking is Done **/
9532 +/* ToDo: All in this subsection */
9533 +
9534 +/** Registers That Address the Stack Frame **/
9535 +
9536 +/*
9537 +The register number of the stack pointer register, which must also be a
9538 +fixed register according to FIXED_REGISTERS. On most machines,
9539 +the hardware determines which register this is.
9540 +*/
9541 +/* Using r13 as stack pointer. */
9542 +#define STACK_POINTER_REGNUM INTERNAL_REGNUM(13)
9543 +
9544 +/*
9545 +The register number of the frame pointer register, which is used to
9546 +access automatic variables in the stack frame. On some machines, the
9547 +hardware determines which register this is. On other machines, you can
9548 +choose any register you wish for this purpose.
9549 +*/
9550 +/* Use r7 */
9551 +#define FRAME_POINTER_REGNUM INTERNAL_REGNUM(7)
9552 +
9553 +
9554 +
9555 +/*
9556 +The register number of the arg pointer register, which is used to access
9557 +the function's argument list. On some machines, this is the same as the
9558 +frame pointer register. On some machines, the hardware determines which
9559 +register this is. On other machines, you can choose any register you
9560 +wish for this purpose. If this is not the same register as the frame
9561 +pointer register, then you must mark it as a fixed register according to
9562 +FIXED_REGISTERS, or arrange to be able to eliminate it (see Section
9563 +10.10.5 [Elimination], page 224).
9564 +*/
9565 +/* Using r5 */
9566 +#define ARG_POINTER_REGNUM INTERNAL_REGNUM(4)
9567 +
9568 +
9569 +/*
9570 +Register numbers used for passing a function's static chain pointer. If
9571 +register windows are used, the register number as seen by the called
9572 +function is STATIC_CHAIN_INCOMING_REGNUM, while the register
9573 +number as seen by the calling function is STATIC_CHAIN_REGNUM. If
9574 +these registers are the same, STATIC_CHAIN_INCOMING_REGNUM need
9575 +not be defined.
9576 +
9577 +The static chain register need not be a fixed register.
9578 +
9579 +If the static chain is passed in memory, these macros should not be
9580 +defined; instead, the next two macros should be defined.
9581 +*/
9582 +/* Using r0 */
9583 +#define STATIC_CHAIN_REGNUM INTERNAL_REGNUM(0)
9584 +
9585 +
9586 +/** Eliminating Frame Pointer and Arg Pointer **/
9587 +
9588 +/*
9589 +A C expression which is nonzero if a function must have and use a frame
9590 +pointer. This expression is evaluated in the reload pass. If its value is
9591 +nonzero the function will have a frame pointer.
9592 +
9593 +The expression can in principle examine the current function and decide
9594 +according to the facts, but on most machines the constant 0 or the
9595 +constant 1 suffices. Use 0 when the machine allows code to be generated
9596 +with no frame pointer, and doing so saves some time or space. Use 1
9597 +when there is no possible advantage to avoiding a frame pointer.
9598 +
9599 +In certain cases, the compiler does not know how to produce valid code
9600 +without a frame pointer. The compiler recognizes those cases and
9601 +automatically gives the function a frame pointer regardless of what
9602 +FRAME_POINTER_REQUIRED says. You don't need to worry about
9603 +them.
9604 +
9605 +In a function that does not require a frame pointer, the frame pointer
9606 +register can be allocated for ordinary usage, unless you mark it as a
9607 +fixed register. See FIXED_REGISTERS for more information.
9608 +*/
9609 +/* We need the frame pointer when compiling for profiling */
9610 +#define FRAME_POINTER_REQUIRED (current_function_profile)
9611 +
9612 +/*
9613 +A C statement to store in the variable DEPTH_VAR the difference
9614 +between the frame pointer and the stack pointer values immediately after
9615 +the function prologue. The value would be computed from information
9616 +such as the result of get_frame_size () and the tables of
9617 +registers regs_ever_live and call_used_regs.
9618 +
9619 +If ELIMINABLE_REGS is defined, this macro will be not be used and
9620 +need not be defined. Otherwise, it must be defined even if
9621 +FRAME_POINTER_REQUIRED is defined to always be true; in that
9622 +case, you may set DEPTH_VAR to anything.
9623 +*/
9624 +#define INITIAL_FRAME_POINTER_OFFSET(DEPTH_VAR) ((DEPTH_VAR) = get_frame_size())
9625 +
9626 +/*
9627 +If defined, this macro specifies a table of register pairs used to
9628 +eliminate unneeded registers that point into the stack frame. If it is not
9629 +defined, the only elimination attempted by the compiler is to replace
9630 +references to the frame pointer with references to the stack pointer.
9631 +
9632 +The definition of this macro is a list of structure initializations, each
9633 +of which specifies an original and replacement register.
9634 +
9635 +On some machines, the position of the argument pointer is not known until
9636 +the compilation is completed. In such a case, a separate hard register
9637 +must be used for the argument pointer. This register can be eliminated by
9638 +replacing it with either the frame pointer or the argument pointer,
9639 +depending on whether or not the frame pointer has been eliminated.
9640 +
9641 +In this case, you might specify:
9642 + #define ELIMINABLE_REGS \
9643 + {{ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
9644 + {ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM}, \
9645 + {FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}}
9646 +
9647 +Note that the elimination of the argument pointer with the stack pointer is
9648 +specified first since that is the preferred elimination.
9649 +*/
9650 +#define ELIMINABLE_REGS \
9651 +{ \
9652 + { FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
9653 + { ARG_POINTER_REGNUM, STACK_POINTER_REGNUM }, \
9654 + { ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM } \
9655 +}
9656 +
9657 +/*
9658 +A C expression that returns nonzero if the compiler is allowed to try
9659 +to replace register number FROM with register number
9660 +TO. This macro need only be defined if ELIMINABLE_REGS
9661 +is defined, and will usually be the constant 1, since most of the cases
9662 +preventing register elimination are things that the compiler already
9663 +knows about.
9664 +*/
9665 +#define CAN_ELIMINATE(FROM, TO) 1
9666 +
9667 +/*
9668 +This macro is similar to INITIAL_FRAME_POINTER_OFFSET. It
9669 +specifies the initial difference between the specified pair of
9670 +registers. This macro must be defined if ELIMINABLE_REGS is
9671 +defined.
9672 +*/
9673 +#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
9674 + ((OFFSET) = avr32_initial_elimination_offset(FROM, TO))
9675 +
9676 +/** Passing Function Arguments on the Stack **/
9677 +
9678 +
9679 +/*
9680 +A C expression. If nonzero, push insns will be used to pass
9681 +outgoing arguments.
9682 +If the target machine does not have a push instruction, set it to zero.
9683 +That directs GCC to use an alternate strategy: to
9684 +allocate the entire argument block and then store the arguments into
9685 +it. When PUSH_ARGS is nonzero, PUSH_ROUNDING must be defined too.
9686 +*/
9687 +#define PUSH_ARGS 1
9688 +
9689 +
9690 +/*
9691 +A C expression that is the number of bytes actually pushed onto the
9692 +stack when an instruction attempts to push NPUSHED bytes.
9693 +
9694 +On some machines, the definition
9695 +
9696 + #define PUSH_ROUNDING(BYTES) (BYTES)
9697 +
9698 +will suffice. But on other machines, instructions that appear
9699 +to push one byte actually push two bytes in an attempt to maintain
9700 +alignment. Then the definition should be
9701 +
9702 + #define PUSH_ROUNDING(BYTES) (((BYTES) + 1) & ~1)
9703 +*/
9704 +/* Push 4 bytes at the time. */
9705 +#define PUSH_ROUNDING(NPUSHED) (((NPUSHED) + 3) & ~3)
9706 +
9707 +/*
9708 +A C expression. If nonzero, the maximum amount of space required for
9709 +outgoing arguments will be computed and placed into the variable
9710 +current_function_outgoing_args_size. No space will be pushed
9711 +onto the stack for each call; instead, the function prologue should
9712 +increase the stack frame size by this amount.
9713 +
9714 +Setting both PUSH_ARGS and ACCUMULATE_OUTGOING_ARGS is not proper.
9715 +*/
9716 +#define ACCUMULATE_OUTGOING_ARGS 0
9717 +
9718 +
9719 +
9720 +
9721 +/*
9722 +A C expression that should indicate the number of bytes of its own
9723 +arguments that a function pops on returning, or 0 if the
9724 +function pops no arguments and the caller must therefore pop them all
9725 +after the function returns.
9726 +
9727 +FUNDECL is a C variable whose value is a tree node that describes
9728 +the function in question. Normally it is a node of type
9729 +FUNCTION_DECL that describes the declaration of the function.
9730 +From this you can obtain the DECL_ATTRIBUTES of the function.
9731 +
9732 +FUNTYPE is a C variable whose value is a tree node that
9733 +describes the function in question. Normally it is a node of type
9734 +FUNCTION_TYPE that describes the data type of the function.
9735 +From this it is possible to obtain the data types of the value and
9736 +arguments (if known).
9737 +
9738 +When a call to a library function is being considered, FUNDECL
9739 +will contain an identifier node for the library function. Thus, if
9740 +you need to distinguish among various library functions, you can do so
9741 +by their names. Note that ``library function'' in this context means
9742 +a function used to perform arithmetic, whose name is known specially
9743 +in the compiler and was not mentioned in the C code being compiled.
9744 +
9745 +STACK_SIZE is the number of bytes of arguments passed on the
9746 +stack. If a variable number of bytes is passed, it is zero, and
9747 +argument popping will always be the responsibility of the calling function.
9748 +
9749 +On the VAX, all functions always pop their arguments, so the definition
9750 +of this macro is STACK_SIZE. On the 68000, using the standard
9751 +calling convention, no functions pop their arguments, so the value of
9752 +the macro is always 0 in this case. But an alternative calling
9753 +convention is available in which functions that take a fixed number of
9754 +arguments pop them but other functions (such as printf) pop
9755 +nothing (the caller pops all). When this convention is in use,
9756 +FUNTYPE is examined to determine whether a function takes a fixed
9757 +number of arguments.
9758 +*/
9759 +#define RETURN_POPS_ARGS(FUNDECL, FUNTYPE, STACK_SIZE) 0
9760 +
9761 +
9762 +/*Return true if this function can we use a single return instruction*/
9763 +#define USE_RETURN_INSN(ISCOND) avr32_use_return_insn(ISCOND)
9764 +
9765 +/*
9766 +A C expression that should indicate the number of bytes a call sequence
9767 +pops off the stack. It is added to the value of RETURN_POPS_ARGS
9768 +when compiling a function call.
9769 +
9770 +CUM is the variable in which all arguments to the called function
9771 +have been accumulated.
9772 +
9773 +On certain architectures, such as the SH5, a call trampoline is used
9774 +that pops certain registers off the stack, depending on the arguments
9775 +that have been passed to the function. Since this is a property of the
9776 +call site, not of the called function, RETURN_POPS_ARGS is not
9777 +appropriate.
9778 +*/
9779 +#define CALL_POPS_ARGS(CUM) 0
9780 +
9781 +/* Passing Arguments in Registers */
9782 +
9783 +/*
9784 +A C expression that controls whether a function argument is passed
9785 +in a register, and which register.
9786 +
9787 +The arguments are CUM, which summarizes all the previous
9788 +arguments; MODE, the machine mode of the argument; TYPE,
9789 +the data type of the argument as a tree node or 0 if that is not known
9790 +(which happens for C support library functions); and NAMED,
9791 +which is 1 for an ordinary argument and 0 for nameless arguments that
9792 +correspond to '...' in the called function's prototype.
9793 +TYPE can be an incomplete type if a syntax error has previously
9794 +occurred.
9795 +
9796 +The value of the expression is usually either a reg RTX for the
9797 +hard register in which to pass the argument, or zero to pass the
9798 +argument on the stack.
9799 +
9800 +For machines like the VAX and 68000, where normally all arguments are
9801 +pushed, zero suffices as a definition.
9802 +
9803 +The value of the expression can also be a parallel RTX. This is
9804 +used when an argument is passed in multiple locations. The mode of the
9805 +of the parallel should be the mode of the entire argument. The
9806 +parallel holds any number of expr_list pairs; each one
9807 +describes where part of the argument is passed. In each
9808 +expr_list the first operand must be a reg RTX for the hard
9809 +register in which to pass this part of the argument, and the mode of the
9810 +register RTX indicates how large this part of the argument is. The
9811 +second operand of the expr_list is a const_int which gives
9812 +the offset in bytes into the entire argument of where this part starts.
9813 +As a special exception the first expr_list in the parallel
9814 +RTX may have a first operand of zero. This indicates that the entire
9815 +argument is also stored on the stack.
9816 +
9817 +The last time this macro is called, it is called with MODE == VOIDmode,
9818 +and its result is passed to the call or call_value
9819 +pattern as operands 2 and 3 respectively.
9820 +
9821 +The usual way to make the ISO library 'stdarg.h' work on a machine
9822 +where some arguments are usually passed in registers, is to cause
9823 +nameless arguments to be passed on the stack instead. This is done
9824 +by making FUNCTION_ARG return 0 whenever NAMED is 0.
9825 +
9826 +You may use the macro MUST_PASS_IN_STACK (MODE, TYPE)
9827 +in the definition of this macro to determine if this argument is of a
9828 +type that must be passed in the stack. If REG_PARM_STACK_SPACE
9829 +is not defined and FUNCTION_ARG returns nonzero for such an
9830 +argument, the compiler will abort. If REG_PARM_STACK_SPACE is
9831 +defined, the argument will be computed in the stack and then loaded into
9832 +a register. */
9833 +
9834 +#define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
9835 + avr32_function_arg(&(CUM), MODE, TYPE, NAMED)
9836 +
9837 +
9838 +
9839 +
9840 +/*
9841 +A C type for declaring a variable that is used as the first argument of
9842 +FUNCTION_ARG and other related values. For some target machines,
9843 +the type int suffices and can hold the number of bytes of
9844 +argument so far.
9845 +
9846 +There is no need to record in CUMULATIVE_ARGS anything about the
9847 +arguments that have been passed on the stack. The compiler has other
9848 +variables to keep track of that. For target machines on which all
9849 +arguments are passed on the stack, there is no need to store anything in
9850 +CUMULATIVE_ARGS; however, the data structure must exist and
9851 +should not be empty, so use int.
9852 +*/
9853 +typedef struct avr32_args
9854 +{
9855 + /* Index representing the argument register the current function argument
9856 + will occupy */
9857 + int index;
9858 + /* A mask with bits representing the argument registers: if a bit is set
9859 + then this register is used for an arguemnt */
9860 + int used_index;
9861 + /* TRUE if this function has anonymous arguments */
9862 + int uses_anonymous_args;
9863 + /* The size in bytes of the named arguments pushed on the stack */
9864 + int stack_pushed_args_size;
9865 + /* Set to true if this function needs a Return Value Pointer */
9866 + int use_rvp;
9867 +
9868 +} CUMULATIVE_ARGS;
9869 +
9870 +
9871 +#define FIRST_CUM_REG_INDEX 0
9872 +#define LAST_CUM_REG_INDEX 4
9873 +#define GET_REG_INDEX(CUM) ((CUM)->index)
9874 +#define SET_REG_INDEX(CUM, INDEX) ((CUM)->index = (INDEX));
9875 +#define GET_USED_INDEX(CUM, INDEX) ((CUM)->used_index & (1 << (INDEX)))
9876 +#define SET_USED_INDEX(CUM, INDEX) \
9877 + do \
9878 + { \
9879 + if (INDEX >= 0) \
9880 + (CUM)->used_index |= (1 << (INDEX)); \
9881 + } \
9882 + while (0)
9883 +#define SET_INDEXES_UNUSED(CUM) ((CUM)->used_index = 0)
9884 +
9885 +
9886 +/*
9887 + A C statement (sans semicolon) for initializing the variable cum for the
9888 + state at the beginning of the argument list. The variable has type
9889 + CUMULATIVE_ARGS. The value of FNTYPE is the tree node for the data type of
9890 + the function which will receive the args, or 0 if the args are to a compiler
9891 + support library function. For direct calls that are not libcalls, FNDECL
9892 + contain the declaration node of the function. FNDECL is also set when
9893 + INIT_CUMULATIVE_ARGS is used to find arguments for the function being
9894 + compiled. N_NAMED_ARGS is set to the number of named arguments, including a
9895 + structure return address if it is passed as a parameter, when making a call.
9896 + When processing incoming arguments, N_NAMED_ARGS is set to -1.
9897 +
9898 + When processing a call to a compiler support library function, LIBNAME
9899 + identifies which one. It is a symbol_ref rtx which contains the name of the
9900 + function, as a string. LIBNAME is 0 when an ordinary C function call is
9901 + being processed. Thus, each time this macro is called, either LIBNAME or
9902 + FNTYPE is nonzero, but never both of them at once.
9903 +*/
9904 +#define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \
9905 + avr32_init_cumulative_args(&(CUM), FNTYPE, LIBNAME, FNDECL)
9906 +
9907 +
9908 +/*
9909 +A C statement (sans semicolon) to update the summarizer variable
9910 +CUM to advance past an argument in the argument list. The
9911 +values MODE, TYPE and NAMED describe that argument.
9912 +Once this is done, the variable CUM is suitable for analyzing
9913 +the following argument with FUNCTION_ARG, etc.
9914 +
9915 +This macro need not do anything if the argument in question was passed
9916 +on the stack. The compiler knows how to track the amount of stack space
9917 +used for arguments without any special help.
9918 +*/
9919 +#define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED) \
9920 + avr32_function_arg_advance(&(CUM), MODE, TYPE, NAMED)
9921 +
9922 +/*
9923 +If defined, a C expression which determines whether, and in which direction,
9924 +to pad out an argument with extra space. The value should be of type
9925 +enum direction: either 'upward' to pad above the argument,
9926 +'downward' to pad below, or 'none' to inhibit padding.
9927 +
9928 +The amount of padding is always just enough to reach the next
9929 +multiple of FUNCTION_ARG_BOUNDARY; this macro does not control
9930 +it.
9931 +
9932 +This macro has a default definition which is right for most systems.
9933 +For little-endian machines, the default is to pad upward. For
9934 +big-endian machines, the default is to pad downward for an argument of
9935 +constant size shorter than an int, and upward otherwise.
9936 +*/
9937 +#define FUNCTION_ARG_PADDING(MODE, TYPE) \
9938 + avr32_function_arg_padding(MODE, TYPE)
9939 +
9940 +/*
9941 + Specify padding for the last element of a block move between registers
9942 + and memory. First is nonzero if this is the only element. Defining
9943 + this macro allows better control of register function parameters on
9944 + big-endian machines, without using PARALLEL rtl. In particular,
9945 + MUST_PASS_IN_STACK need not test padding and mode of types in registers,
9946 + as there is no longer a "wrong" part of a register; For example, a three
9947 + byte aggregate may be passed in the high part of a register if so required.
9948 +*/
9949 +#define BLOCK_REG_PADDING(MODE, TYPE, FIRST) \
9950 + avr32_function_arg_padding(MODE, TYPE)
9951 +
9952 +/*
9953 +If defined, a C expression which determines whether the default
9954 +implementation of va_arg will attempt to pad down before reading the
9955 +next argument, if that argument is smaller than its aligned space as
9956 +controlled by PARM_BOUNDARY. If this macro is not defined, all such
9957 +arguments are padded down if BYTES_BIG_ENDIAN is true.
9958 +*/
9959 +#define PAD_VARARGS_DOWN \
9960 + (FUNCTION_ARG_PADDING (TYPE_MODE (type), type) == downward)
9961 +
9962 +
9963 +/*
9964 +A C expression that is nonzero if REGNO is the number of a hard
9965 +register in which function arguments are sometimes passed. This does
9966 +not include implicit arguments such as the static chain and
9967 +the structure-value address. On many machines, no registers can be
9968 +used for this purpose since all function arguments are pushed on the
9969 +stack.
9970 +*/
9971 +/*
9972 + Use r8 - r12 for function arguments.
9973 +*/
9974 +#define FUNCTION_ARG_REGNO_P(REGNO) \
9975 + (REGNO >= 3 && REGNO <= 7)
9976 +
9977 +/* Number of registers used for passing function arguments */
9978 +#define NUM_ARG_REGS 5
9979 +
9980 +/*
9981 +If defined, the order in which arguments are loaded into their
9982 +respective argument registers is reversed so that the last
9983 +argument is loaded first. This macro only affects arguments
9984 +passed in registers.
9985 +*/
9986 +/* #define LOAD_ARGS_REVERSED */
9987 +
9988 +/** How Scalar Function Values Are Returned **/
9989 +
9990 +/* AVR32 is using r12 as return register. */
9991 +#define RET_REGISTER (15 - 12)
9992 +
9993 +
9994 +/*
9995 +A C expression to create an RTX representing the place where a library
9996 +function returns a value of mode MODE. If the precise function
9997 +being called is known, FUNC is a tree node
9998 +(FUNCTION_DECL) for it; otherwise, func is a null
9999 +pointer. This makes it possible to use a different value-returning
10000 +convention for specific functions when all their calls are
10001 +known.
10002 +
10003 +Note that "library function" in this context means a compiler
10004 +support routine, used to perform arithmetic, whose name is known
10005 +specially by the compiler and was not mentioned in the C code being
10006 +compiled.
10007 +
10008 +The definition of LIBRARY_VALUE need not be concerned aggregate
10009 +data types, because none of the library functions returns such types.
10010 +*/
10011 +#define LIBCALL_VALUE(MODE) avr32_libcall_value(MODE)
10012 +
10013 +/*
10014 +A C expression that is nonzero if REGNO is the number of a hard
10015 +register in which the values of called function may come back.
10016 +
10017 +A register whose use for returning values is limited to serving as the
10018 +second of a pair (for a value of type double, say) need not be
10019 +recognized by this macro. So for most machines, this definition
10020 +suffices:
10021 + #define FUNCTION_VALUE_REGNO_P(N) ((N) == 0)
10022 +
10023 +If the machine has register windows, so that the caller and the called
10024 +function use different registers for the return value, this macro
10025 +should recognize only the caller's register numbers.
10026 +*/
10027 +/*
10028 + When returning a value of mode DImode, r11:r10 is used, else r12 is used.
10029 +*/
10030 +#define FUNCTION_VALUE_REGNO_P(REGNO) ((REGNO) == RET_REGISTER \
10031 + || (REGNO) == INTERNAL_REGNUM(11))
10032 +
10033 +
10034 +/** How Large Values Are Returned **/
10035 +
10036 +
10037 +/*
10038 +Define this macro to be 1 if all structure and union return values must be
10039 +in memory. Since this results in slower code, this should be defined
10040 +only if needed for compatibility with other compilers or with an ABI.
10041 +If you define this macro to be 0, then the conventions used for structure
10042 +and union return values are decided by the RETURN_IN_MEMORY macro.
10043 +
10044 +If not defined, this defaults to the value 1.
10045 +*/
10046 +#define DEFAULT_PCC_STRUCT_RETURN 0
10047 +
10048 +
10049 +
10050 +
10051 +/** Generating Code for Profiling **/
10052 +
10053 +/*
10054 +A C statement or compound statement to output to FILE some
10055 +assembler code to call the profiling subroutine mcount.
10056 +
10057 +The details of how mcount expects to be called are determined by
10058 +your operating system environment, not by GCC. To figure them out,
10059 +compile a small program for profiling using the system's installed C
10060 +compiler and look at the assembler code that results.
10061 +
10062 +Older implementations of mcount expect the address of a counter
10063 +variable to be loaded into some register. The name of this variable is
10064 +'LP' followed by the number LABELNO, so you would generate
10065 +the name using 'LP%d' in a fprintf.
10066 +*/
10067 +/* ToDo: fixme */
10068 +#ifndef FUNCTION_PROFILER
10069 +#define FUNCTION_PROFILER(FILE, LABELNO) \
10070 + fprintf((FILE), "/* profiler %d */", (LABELNO))
10071 +#endif
10072 +
10073 +
10074 +/*****************************************************************************
10075 + * Trampolines for Nested Functions *
10076 + *****************************************************************************/
10077 +
10078 +/*
10079 +A C statement to output, on the stream FILE, assembler code for a
10080 +block of data that contains the constant parts of a trampoline. This
10081 +code should not include a label - the label is taken care of
10082 +automatically.
10083 +
10084 +If you do not define this macro, it means no template is needed
10085 +for the target. Do not define this macro on systems where the block move
10086 +code to copy the trampoline into place would be larger than the code
10087 +to generate it on the spot.
10088 +*/
10089 +/* ToDo: correct? */
10090 +#define TRAMPOLINE_TEMPLATE(FILE) avr32_trampoline_template(FILE);
10091 +
10092 +
10093 +/*
10094 +A C expression for the size in bytes of the trampoline, as an integer.
10095 +*/
10096 +/* ToDo: fixme */
10097 +#define TRAMPOLINE_SIZE 0x0C
10098 +
10099 +/*
10100 +Alignment required for trampolines, in bits.
10101 +
10102 +If you don't define this macro, the value of BIGGEST_ALIGNMENT
10103 +is used for aligning trampolines.
10104 +*/
10105 +#define TRAMPOLINE_ALIGNMENT 16
10106 +
10107 +/*
10108 +A C statement to initialize the variable parts of a trampoline.
10109 +ADDR is an RTX for the address of the trampoline; FNADDR is
10110 +an RTX for the address of the nested function; STATIC_CHAIN is an
10111 +RTX for the static chain value that should be passed to the function
10112 +when it is called.
10113 +*/
10114 +#define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, STATIC_CHAIN) \
10115 + avr32_initialize_trampoline(ADDR, FNADDR, STATIC_CHAIN)
10116 +
10117 +
10118 +/******************************************************************************
10119 + * Implicit Calls to Library Routines
10120 + *****************************************************************************/
10121 +
10122 +/* Tail calling. */
10123 +
10124 +/* A C expression that evaluates to true if it is ok to perform a sibling
10125 + call to DECL. */
10126 +#define FUNCTION_OK_FOR_SIBCALL(DECL) 0
10127 +
10128 +#define OVERRIDE_OPTIONS avr32_override_options ()
10129 +
10130 +#define OPTIMIZATION_OPTIONS(LEVEL, SIZE) avr32_optimization_options (LEVEL, SIZE)
10131 +
10132 +/******************************************************************************
10133 + * Addressing Modes
10134 + *****************************************************************************/
10135 +
10136 +/*
10137 +A C expression that is nonzero if the machine supports pre-increment,
10138 +pre-decrement, post-increment, or post-decrement addressing respectively.
10139 +*/
10140 +/*
10141 + AVR32 supports Rp++ and --Rp
10142 +*/
10143 +#define HAVE_PRE_INCREMENT 0
10144 +#define HAVE_PRE_DECREMENT 1
10145 +#define HAVE_POST_INCREMENT 1
10146 +#define HAVE_POST_DECREMENT 0
10147 +
10148 +/*
10149 +A C expression that is nonzero if the machine supports pre- or
10150 +post-address side-effect generation involving constants other than
10151 +the size of the memory operand.
10152 +*/
10153 +#define HAVE_PRE_MODIFY_DISP 0
10154 +#define HAVE_POST_MODIFY_DISP 0
10155 +
10156 +/*
10157 +A C expression that is nonzero if the machine supports pre- or
10158 +post-address side-effect generation involving a register displacement.
10159 +*/
10160 +#define HAVE_PRE_MODIFY_REG 0
10161 +#define HAVE_POST_MODIFY_REG 0
10162 +
10163 +/*
10164 +A C expression that is 1 if the RTX X is a constant which
10165 +is a valid address. On most machines, this can be defined as
10166 +CONSTANT_P (X), but a few machines are more restrictive
10167 +in which constant addresses are supported.
10168 +
10169 +CONSTANT_P accepts integer-values expressions whose values are
10170 +not explicitly known, such as symbol_ref, label_ref, and
10171 +high expressions and const arithmetic expressions, in
10172 +addition to const_int and const_double expressions.
10173 +*/
10174 +#define CONSTANT_ADDRESS_P(X) CONSTANT_P(X)
10175 +
10176 +/*
10177 +A number, the maximum number of registers that can appear in a valid
10178 +memory address. Note that it is up to you to specify a value equal to
10179 +the maximum number that GO_IF_LEGITIMATE_ADDRESS would ever
10180 +accept.
10181 +*/
10182 +#define MAX_REGS_PER_ADDRESS 2
10183 +
10184 +/*
10185 +A C compound statement with a conditional goto LABEL;
10186 +executed if X (an RTX) is a legitimate memory address on the
10187 +target machine for a memory operand of mode MODE.
10188 +
10189 +It usually pays to define several simpler macros to serve as
10190 +subroutines for this one. Otherwise it may be too complicated to
10191 +understand.
10192 +
10193 +This macro must exist in two variants: a strict variant and a
10194 +non-strict one. The strict variant is used in the reload pass. It
10195 +must be defined so that any pseudo-register that has not been
10196 +allocated a hard register is considered a memory reference. In
10197 +contexts where some kind of register is required, a pseudo-register
10198 +with no hard register must be rejected.
10199 +
10200 +The non-strict variant is used in other passes. It must be defined to
10201 +accept all pseudo-registers in every context where some kind of
10202 +register is required.
10203 +
10204 +Compiler source files that want to use the strict variant of this
10205 +macro define the macro REG_OK_STRICT. You should use an
10206 +#ifdef REG_OK_STRICT conditional to define the strict variant
10207 +in that case and the non-strict variant otherwise.
10208 +
10209 +Subroutines to check for acceptable registers for various purposes (one
10210 +for base registers, one for index registers, and so on) are typically
10211 +among the subroutines used to define GO_IF_LEGITIMATE_ADDRESS.
10212 +Then only these subroutine macros need have two variants; the higher
10213 +levels of macros may be the same whether strict or not.
10214 +
10215 +Normally, constant addresses which are the sum of a symbol_ref
10216 +and an integer are stored inside a const RTX to mark them as
10217 +constant. Therefore, there is no need to recognize such sums
10218 +specifically as legitimate addresses. Normally you would simply
10219 +recognize any const as legitimate.
10220 +
10221 +Usually PRINT_OPERAND_ADDRESS is not prepared to handle constant
10222 +sums that are not marked with const. It assumes that a naked
10223 +plus indicates indexing. If so, then you must reject such
10224 +naked constant sums as illegitimate addresses, so that none of them will
10225 +be given to PRINT_OPERAND_ADDRESS.
10226 +
10227 +On some machines, whether a symbolic address is legitimate depends on
10228 +the section that the address refers to. On these machines, define the
10229 +macro ENCODE_SECTION_INFO to store the information into the
10230 +symbol_ref, and then check for it here. When you see a
10231 +const, you will have to look inside it to find the
10232 +symbol_ref in order to determine the section.
10233 +
10234 +The best way to modify the name string is by adding text to the
10235 +beginning, with suitable punctuation to prevent any ambiguity. Allocate
10236 +the new name in saveable_obstack. You will have to modify
10237 +ASM_OUTPUT_LABELREF to remove and decode the added text and
10238 +output the name accordingly, and define STRIP_NAME_ENCODING to
10239 +access the original name string.
10240 +
10241 +You can check the information stored here into the symbol_ref in
10242 +the definitions of the macros GO_IF_LEGITIMATE_ADDRESS and
10243 +PRINT_OPERAND_ADDRESS.
10244 +*/
10245 +#ifdef REG_OK_STRICT
10246 +# define GO_IF_LEGITIMATE_ADDRESS(MODE, X, LABEL) \
10247 + do \
10248 + { \
10249 + if (avr32_legitimate_address(MODE, X, 1)) \
10250 + goto LABEL; \
10251 + } \
10252 + while (0)
10253 +#else
10254 +# define GO_IF_LEGITIMATE_ADDRESS(MODE, X, LABEL) \
10255 + do \
10256 + { \
10257 + if (avr32_legitimate_address(MODE, X, 0)) \
10258 + goto LABEL; \
10259 + } \
10260 + while (0)
10261 +#endif
10262 +
10263 +
10264 +
10265 +/*
10266 +A C compound statement that attempts to replace X with a valid
10267 +memory address for an operand of mode MODE. win will be a
10268 +C statement label elsewhere in the code; the macro definition may use
10269 +
10270 + GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN);
10271 +
10272 +to avoid further processing if the address has become legitimate.
10273 +
10274 +X will always be the result of a call to break_out_memory_refs,
10275 +and OLDX will be the operand that was given to that function to produce
10276 +X.
10277 +
10278 +The code generated by this macro should not alter the substructure of
10279 +X. If it transforms X into a more legitimate form, it
10280 +should assign X (which will always be a C variable) a new value.
10281 +
10282 +It is not necessary for this macro to come up with a legitimate
10283 +address. The compiler has standard ways of doing so in all cases. In
10284 +fact, it is safe for this macro to do nothing. But often a
10285 +machine-dependent strategy can generate better code.
10286 +*/
10287 +#define LEGITIMIZE_ADDRESS(X, OLDX, MODE, WIN) \
10288 + do \
10289 + { \
10290 + if (GET_CODE(X) == PLUS \
10291 + && GET_CODE(XEXP(X, 0)) == REG \
10292 + && GET_CODE(XEXP(X, 1)) == CONST_INT \
10293 + && !CONST_OK_FOR_CONSTRAINT_P(INTVAL(XEXP(X, 1)), \
10294 + 'K', "Ks16")) \
10295 + { \
10296 + rtx index = force_reg(SImode, XEXP(X, 1)); \
10297 + X = gen_rtx_PLUS( SImode, XEXP(X, 0), index); \
10298 + } \
10299 + GO_IF_LEGITIMATE_ADDRESS(MODE, X, WIN); \
10300 + } \
10301 + while(0)
10302 +
10303 +
10304 +/*
10305 +A C statement or compound statement with a conditional
10306 +goto LABEL; executed if memory address X (an RTX) can have
10307 +different meanings depending on the machine mode of the memory
10308 +reference it is used for or if the address is valid for some modes
10309 +but not others.
10310 +
10311 +Autoincrement and autodecrement addresses typically have mode-dependent
10312 +effects because the amount of the increment or decrement is the size
10313 +of the operand being addressed. Some machines have other mode-dependent
10314 +addresses. Many RISC machines have no mode-dependent addresses.
10315 +
10316 +You may assume that ADDR is a valid address for the machine.
10317 +*/
10318 +#define GO_IF_MODE_DEPENDENT_ADDRESS(ADDR, LABEL) \
10319 + do \
10320 + { \
10321 + if (GET_CODE (ADDR) == POST_INC \
10322 + || GET_CODE (ADDR) == PRE_DEC) \
10323 + goto LABEL; \
10324 + } \
10325 + while (0)
10326 +
10327 +/*
10328 +A C expression that is nonzero if X is a legitimate constant for
10329 +an immediate operand on the target machine. You can assume that
10330 +X satisfies CONSTANT_P, so you need not check this. In fact,
10331 +'1' is a suitable definition for this macro on machines where
10332 +anything CONSTANT_P is valid.
10333 +*/
10334 +#define LEGITIMATE_CONSTANT_P(X) avr32_legitimate_constant_p(X)
10335 +
10336 +
10337 +/******************************************************************************
10338 + * Condition Code Status
10339 + *****************************************************************************/
10340 +
10341 +/*
10342 +C code for a data type which is used for declaring the mdep
10343 +component of cc_status. It defaults to int.
10344 +
10345 +This macro is not used on machines that do not use cc0.
10346 +*/
10347 +
10348 +typedef struct
10349 +{
10350 + int flags;
10351 + rtx value;
10352 + int fpflags;
10353 + rtx fpvalue;
10354 + int cond_exec_cmp_clobbered;
10355 +} avr32_status_reg;
10356 +
10357 +
10358 +#define CC_STATUS_MDEP avr32_status_reg
10359 +
10360 +/*
10361 +A C expression to initialize the mdep field to "empty".
10362 +The default definition does nothing, since most machines don't use
10363 +the field anyway. If you want to use the field, you should probably
10364 +define this macro to initialize it.
10365 +
10366 +This macro is not used on machines that do not use cc0.
10367 +*/
10368 +
10369 +#define CC_STATUS_MDEP_INIT \
10370 + (cc_status.mdep.flags = CC_NONE , cc_status.mdep.cond_exec_cmp_clobbered = 0, cc_status.mdep.value = 0)
10371 +
10372 +#define FPCC_STATUS_INIT \
10373 + (cc_status.mdep.fpflags = CC_NONE , cc_status.mdep.fpvalue = 0)
10374 +
10375 +/*
10376 +A C compound statement to set the components of cc_status
10377 +appropriately for an insn INSN whose body is EXP. It is
10378 +this macro's responsibility to recognize insns that set the condition
10379 +code as a byproduct of other activity as well as those that explicitly
10380 +set (cc0).
10381 +
10382 +This macro is not used on machines that do not use cc0.
10383 +
10384 +If there are insns that do not set the condition code but do alter
10385 +other machine registers, this macro must check to see whether they
10386 +invalidate the expressions that the condition code is recorded as
10387 +reflecting. For example, on the 68000, insns that store in address
10388 +registers do not set the condition code, which means that usually
10389 +NOTICE_UPDATE_CC can leave cc_status unaltered for such
10390 +insns. But suppose that the previous insn set the condition code
10391 +based on location 'a4@@(102)' and the current insn stores a new
10392 +value in 'a4'. Although the condition code is not changed by
10393 +this, it will no longer be true that it reflects the contents of
10394 +'a4@@(102)'. Therefore, NOTICE_UPDATE_CC must alter
10395 +cc_status in this case to say that nothing is known about the
10396 +condition code value.
10397 +
10398 +The definition of NOTICE_UPDATE_CC must be prepared to deal
10399 +with the results of peephole optimization: insns whose patterns are
10400 +parallel RTXs containing various reg, mem or
10401 +constants which are just the operands. The RTL structure of these
10402 +insns is not sufficient to indicate what the insns actually do. What
10403 +NOTICE_UPDATE_CC should do when it sees one is just to run
10404 +CC_STATUS_INIT.
10405 +
10406 +A possible definition of NOTICE_UPDATE_CC is to call a function
10407 +that looks at an attribute (see Insn Attributes) named, for example,
10408 +'cc'. This avoids having detailed information about patterns in
10409 +two places, the 'md' file and in NOTICE_UPDATE_CC.
10410 +*/
10411 +
10412 +#define NOTICE_UPDATE_CC(EXP, INSN) avr32_notice_update_cc(EXP, INSN)
10413 +
10414 +
10415 +
10416 +
10417 +/******************************************************************************
10418 + * Describing Relative Costs of Operations
10419 + *****************************************************************************/
10420 +
10421 +
10422 +
10423 +/*
10424 +A C expression for the cost of moving data of mode MODE from a
10425 +register in class FROM to one in class TO. The classes are
10426 +expressed using the enumeration values such as GENERAL_REGS. A
10427 +value of 2 is the default; other values are interpreted relative to
10428 +that.
10429 +
10430 +It is not required that the cost always equal 2 when FROM is the
10431 +same as TO; on some machines it is expensive to move between
10432 +registers if they are not general registers.
10433 +
10434 +If reload sees an insn consisting of a single set between two
10435 +hard registers, and if REGISTER_MOVE_COST applied to their
10436 +classes returns a value of 2, reload does not check to ensure that the
10437 +constraints of the insn are met. Setting a cost of other than 2 will
10438 +allow reload to verify that the constraints are met. You should do this
10439 +if the movm pattern's constraints do not allow such copying.
10440 +*/
10441 +#define REGISTER_MOVE_COST(MODE, FROM, TO) \
10442 + ((GET_MODE_SIZE(MODE) <= 4) ? 2: \
10443 + (GET_MODE_SIZE(MODE) <= 8) ? 3: \
10444 + 4)
10445 +
10446 +/*
10447 +A C expression for the cost of moving data of mode MODE between a
10448 +register of class CLASS and memory; IN is zero if the value
10449 +is to be written to memory, nonzero if it is to be read in. This cost
10450 +is relative to those in REGISTER_MOVE_COST. If moving between
10451 +registers and memory is more expensive than between two registers, you
10452 +should define this macro to express the relative cost.
10453 +
10454 +If you do not define this macro, GCC uses a default cost of 4 plus
10455 +the cost of copying via a secondary reload register, if one is
10456 +needed. If your machine requires a secondary reload register to copy
10457 +between memory and a register of CLASS but the reload mechanism is
10458 +more complex than copying via an intermediate, define this macro to
10459 +reflect the actual cost of the move.
10460 +
10461 +GCC defines the function memory_move_secondary_cost if
10462 +secondary reloads are needed. It computes the costs due to copying via
10463 +a secondary register. If your machine copies from memory using a
10464 +secondary register in the conventional way but the default base value of
10465 +4 is not correct for your machine, define this macro to add some other
10466 +value to the result of that function. The arguments to that function
10467 +are the same as to this macro.
10468 +*/
10469 +/*
10470 + Memory moves are costly
10471 +*/
10472 +#define MEMORY_MOVE_COST(MODE, CLASS, IN) \
10473 + (((IN) ? ((GET_MODE_SIZE(MODE) < 4) ? 4 : \
10474 + (GET_MODE_SIZE(MODE) > 8) ? 6 : \
10475 + 3) \
10476 + : ((GET_MODE_SIZE(MODE) > 8) ? 6 : 3)))
10477 +
10478 +/*
10479 +A C expression for the cost of a branch instruction. A value of 1 is
10480 +the default; other values are interpreted relative to that.
10481 +*/
10482 + /* Try to use conditionals as much as possible */
10483 +#define BRANCH_COST (TARGET_BRANCH_PRED ? 3 : 4)
10484 +
10485 +/*A C expression for the maximum number of instructions to execute via conditional
10486 + execution instructions instead of a branch. A value of BRANCH_COST+1 is the default
10487 + if the machine does not use cc0, and 1 if it does use cc0.*/
10488 +#define MAX_CONDITIONAL_EXECUTE 4
10489 +
10490 +/*
10491 +Define this macro as a C expression which is nonzero if accessing less
10492 +than a word of memory (i.e.: a char or a short) is no
10493 +faster than accessing a word of memory, i.e., if such access
10494 +require more than one instruction or if there is no difference in cost
10495 +between byte and (aligned) word loads.
10496 +
10497 +When this macro is not defined, the compiler will access a field by
10498 +finding the smallest containing object; when it is defined, a fullword
10499 +load will be used if alignment permits. Unless bytes accesses are
10500 +faster than word accesses, using word accesses is preferable since it
10501 +may eliminate subsequent memory access if subsequent accesses occur to
10502 +other fields in the same word of the structure, but to different bytes.
10503 +*/
10504 +#define SLOW_BYTE_ACCESS 1
10505 +
10506 +
10507 +/*
10508 +Define this macro if it is as good or better to call a constant
10509 +function address than to call an address kept in a register.
10510 +*/
10511 +#define NO_FUNCTION_CSE
10512 +
10513 +
10514 +/******************************************************************************
10515 + * Adjusting the Instruction Scheduler
10516 + *****************************************************************************/
10517 +
10518 +/*****************************************************************************
10519 + * Dividing the Output into Sections (Texts, Data, ...) *
10520 + *****************************************************************************/
10521 +
10522 +/*
10523 +A C expression whose value is a string, including spacing, containing the
10524 +assembler operation that should precede instructions and read-only data.
10525 +Normally "\t.text" is right.
10526 +*/
10527 +#define TEXT_SECTION_ASM_OP "\t.text"
10528 +/*
10529 +A C statement that switches to the default section containing instructions.
10530 +Normally this is not needed, as simply defining TEXT_SECTION_ASM_OP
10531 +is enough. The MIPS port uses this to sort all functions after all data
10532 +declarations.
10533 +*/
10534 +/* #define TEXT_SECTION */
10535 +
10536 +/*
10537 +A C expression whose value is a string, including spacing, containing the
10538 +assembler operation to identify the following data as writable initialized
10539 +data. Normally "\t.data" is right.
10540 +*/
10541 +#define DATA_SECTION_ASM_OP "\t.data"
10542 +
10543 +/*
10544 +If defined, a C expression whose value is a string, including spacing,
10545 +containing the assembler operation to identify the following data as
10546 +shared data. If not defined, DATA_SECTION_ASM_OP will be used.
10547 +*/
10548 +
10549 +/*
10550 +A C expression whose value is a string, including spacing, containing
10551 +the assembler operation to identify the following data as read-only
10552 +initialized data.
10553 +*/
10554 +#undef READONLY_DATA_SECTION_ASM_OP
10555 +#define READONLY_DATA_SECTION_ASM_OP \
10556 + ((TARGET_USE_RODATA_SECTION) ? \
10557 + "\t.section\t.rodata" : \
10558 + TEXT_SECTION_ASM_OP )
10559 +
10560 +
10561 +/*
10562 +If defined, a C expression whose value is a string, including spacing,
10563 +containing the assembler operation to identify the following data as
10564 +uninitialized global data. If not defined, and neither
10565 +ASM_OUTPUT_BSS nor ASM_OUTPUT_ALIGNED_BSS are defined,
10566 +uninitialized global data will be output in the data section if
10567 +-fno-common is passed, otherwise ASM_OUTPUT_COMMON will be
10568 +used.
10569 +*/
10570 +#define BSS_SECTION_ASM_OP "\t.section\t.bss"
10571 +
10572 +/*
10573 +If defined, a C expression whose value is a string, including spacing,
10574 +containing the assembler operation to identify the following data as
10575 +uninitialized global shared data. If not defined, and
10576 +BSS_SECTION_ASM_OP is, the latter will be used.
10577 +*/
10578 +/*#define SHARED_BSS_SECTION_ASM_OP "\trseg\tshared_bbs_section:data:noroot(0)\n"*/
10579 +/*
10580 +If defined, a C expression whose value is a string, including spacing,
10581 +containing the assembler operation to identify the following data as
10582 +initialization code. If not defined, GCC will assume such a section does
10583 +not exist.
10584 +*/
10585 +#undef INIT_SECTION_ASM_OP
10586 +#define INIT_SECTION_ASM_OP "\t.section\t.init"
10587 +
10588 +/*
10589 +If defined, a C expression whose value is a string, including spacing,
10590 +containing the assembler operation to identify the following data as
10591 +finalization code. If not defined, GCC will assume such a section does
10592 +not exist.
10593 +*/
10594 +#undef FINI_SECTION_ASM_OP
10595 +#define FINI_SECTION_ASM_OP "\t.section\t.fini"
10596 +
10597 +/*
10598 +If defined, an ASM statement that switches to a different section
10599 +via SECTION_OP, calls FUNCTION, and switches back to
10600 +the text section. This is used in crtstuff.c if
10601 +INIT_SECTION_ASM_OP or FINI_SECTION_ASM_OP to calls
10602 +to initialization and finalization functions from the init and fini
10603 +sections. By default, this macro uses a simple function call. Some
10604 +ports need hand-crafted assembly code to avoid dependencies on
10605 +registers initialized in the function prologue or to ensure that
10606 +constant pools don't end up too far way in the text section.
10607 +*/
10608 +#define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
10609 + asm ( SECTION_OP "\n" \
10610 + "mcall r6[" USER_LABEL_PREFIX #FUNC "@got]\n" \
10611 + TEXT_SECTION_ASM_OP);
10612 +
10613 +
10614 +/*
10615 +Define this macro to be an expression with a nonzero value if jump
10616 +tables (for tablejump insns) should be output in the text
10617 +section, along with the assembler instructions. Otherwise, the
10618 +readonly data section is used.
10619 +
10620 +This macro is irrelevant if there is no separate readonly data section.
10621 +*/
10622 +/* Put jump tables in text section if we have caches. Otherwise assume that
10623 + loading data from code memory is slow. */
10624 +#define JUMP_TABLES_IN_TEXT_SECTION \
10625 + (TARGET_CACHES ? 1 : 0)
10626 +
10627 +
10628 +/******************************************************************************
10629 + * Position Independent Code (PIC)
10630 + *****************************************************************************/
10631 +
10632 +#ifndef AVR32_ALWAYS_PIC
10633 +#define AVR32_ALWAYS_PIC 0
10634 +#endif
10635 +
10636 +/* GOT is set to r6 */
10637 +#define PIC_OFFSET_TABLE_REGNUM INTERNAL_REGNUM(6)
10638 +
10639 +/*
10640 +A C expression that is nonzero if X is a legitimate immediate
10641 +operand on the target machine when generating position independent code.
10642 +You can assume that X satisfies CONSTANT_P, so you need not
10643 +check this. You can also assume flag_pic is true, so you need not
10644 +check it either. You need not define this macro if all constants
10645 +(including SYMBOL_REF) can be immediate operands when generating
10646 +position independent code.
10647 +*/
10648 +/* We can't directly access anything that contains a symbol,
10649 + nor can we indirect via the constant pool. */
10650 +#define LEGITIMATE_PIC_OPERAND_P(X) avr32_legitimate_pic_operand_p(X)
10651 +
10652 +
10653 +/* We need to know when we are making a constant pool; this determines
10654 + whether data needs to be in the GOT or can be referenced via a GOT
10655 + offset. */
10656 +extern int making_const_table;
10657 +
10658 +/******************************************************************************
10659 + * Defining the Output Assembler Language
10660 + *****************************************************************************/
10661 +
10662 +
10663 +/*
10664 +A C string constant describing how to begin a comment in the target
10665 +assembler language. The compiler assumes that the comment will end at
10666 +the end of the line.
10667 +*/
10668 +#define ASM_COMMENT_START "# "
10669 +
10670 +/*
10671 +A C string constant for text to be output before each asm
10672 +statement or group of consecutive ones. Normally this is
10673 +"#APP", which is a comment that has no effect on most
10674 +assemblers but tells the GNU assembler that it must check the lines
10675 +that follow for all valid assembler constructs.
10676 +*/
10677 +#undef ASM_APP_ON
10678 +#define ASM_APP_ON "#APP\n"
10679 +
10680 +/*
10681 +A C string constant for text to be output after each asm
10682 +statement or group of consecutive ones. Normally this is
10683 +"#NO_APP", which tells the GNU assembler to resume making the
10684 +time-saving assumptions that are valid for ordinary compiler output.
10685 +*/
10686 +#undef ASM_APP_OFF
10687 +#define ASM_APP_OFF "#NO_APP\n"
10688 +
10689 +
10690 +
10691 +#define FILE_ASM_OP "\t.file\n"
10692 +#define IDENT_ASM_OP "\t.ident\t"
10693 +#define SET_ASM_OP "\t.set\t"
10694 +
10695 +
10696 +/*
10697 + * Output assembly directives to switch to section name. The section
10698 + * should have attributes as specified by flags, which is a bit mask
10699 + * of the SECTION_* flags defined in 'output.h'. If align is nonzero,
10700 + * it contains an alignment in bytes to be used for the section,
10701 + * otherwise some target default should be used. Only targets that
10702 + * must specify an alignment within the section directive need pay
10703 + * attention to align -- we will still use ASM_OUTPUT_ALIGN.
10704 + *
10705 + * NOTE: This one must not be moved to avr32.c
10706 + */
10707 +#undef TARGET_ASM_NAMED_SECTION
10708 +#define TARGET_ASM_NAMED_SECTION default_elf_asm_named_section
10709 +
10710 +
10711 +/*
10712 +You may define this macro as a C expression. You should define the
10713 +expression to have a nonzero value if GCC should output the constant
10714 +pool for a function before the code for the function, or a zero value if
10715 +GCC should output the constant pool after the function. If you do
10716 +not define this macro, the usual case, GCC will output the constant
10717 +pool before the function.
10718 +*/
10719 +#define CONSTANT_POOL_BEFORE_FUNCTION 0
10720 +
10721 +
10722 +/*
10723 +Define this macro as a C expression which is nonzero if the constant
10724 +EXP, of type tree, should be output after the code for a
10725 +function. The compiler will normally output all constants before the
10726 +function; you need not define this macro if this is OK.
10727 +*/
10728 +#define CONSTANT_AFTER_FUNCTION_P(EXP) 1
10729 +
10730 +
10731 +/*
10732 +Define this macro as a C expression which is nonzero if C is
10733 +as a logical line separator by the assembler. STR points to the
10734 +position in the string where C was found; this can be used if a
10735 +line separator uses multiple characters.
10736 +
10737 +If you do not define this macro, the default is that only
10738 +the character ';' is treated as a logical line separator.
10739 +*/
10740 +#define IS_ASM_LOGICAL_LINE_SEPARATOR(C,STR) (((C) == '\n') || ((C) == ';'))
10741 +
10742 +
10743 +/** Output of Uninitialized Variables **/
10744 +
10745 +/*
10746 +A C statement (sans semicolon) to output to the stdio stream
10747 +STREAM the assembler definition of a common-label named
10748 +NAME whose size is SIZE bytes. The variable ROUNDED
10749 +is the size rounded up to whatever alignment the caller wants.
10750 +
10751 +Use the expression assemble_name(STREAM, NAME) to
10752 +output the name itself; before and after that, output the additional
10753 +assembler syntax for defining the name, and a newline.
10754 +
10755 +This macro controls how the assembler definitions of uninitialized
10756 +common global variables are output.
10757 +*/
10758 +/*
10759 +#define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED) \
10760 + avr32_asm_output_common(STREAM, NAME, SIZE, ROUNDED)
10761 +*/
10762 +
10763 +#define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \
10764 + do \
10765 + { \
10766 + fputs ("\t.comm ", (FILE)); \
10767 + assemble_name ((FILE), (NAME)); \
10768 + fprintf ((FILE), ",%d\n", (SIZE)); \
10769 + } \
10770 + while (0)
10771 +
10772 +/*
10773 + * Like ASM_OUTPUT_BSS except takes the required alignment as a
10774 + * separate, explicit argument. If you define this macro, it is used
10775 + * in place of ASM_OUTPUT_BSS, and gives you more flexibility in
10776 + * handling the required alignment of the variable. The alignment is
10777 + * specified as the number of bits.
10778 + *
10779 + * Try to use function asm_output_aligned_bss defined in file varasm.c
10780 + * when defining this macro.
10781 + */
10782 +#define ASM_OUTPUT_ALIGNED_BSS(STREAM, DECL, NAME, SIZE, ALIGNMENT) \
10783 + asm_output_aligned_bss (STREAM, DECL, NAME, SIZE, ALIGNMENT)
10784 +
10785 +/*
10786 +A C statement (sans semicolon) to output to the stdio stream
10787 +STREAM the assembler definition of a local-common-label named
10788 +NAME whose size is SIZE bytes. The variable ROUNDED
10789 +is the size rounded up to whatever alignment the caller wants.
10790 +
10791 +Use the expression assemble_name(STREAM, NAME) to
10792 +output the name itself; before and after that, output the additional
10793 +assembler syntax for defining the name, and a newline.
10794 +
10795 +This macro controls how the assembler definitions of uninitialized
10796 +static variables are output.
10797 +*/
10798 +#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \
10799 + do \
10800 + { \
10801 + fputs ("\t.lcomm ", (FILE)); \
10802 + assemble_name ((FILE), (NAME)); \
10803 + fprintf ((FILE), ",%d, %d\n", (SIZE), 2); \
10804 + } \
10805 + while (0)
10806 +
10807 +
10808 +/*
10809 +A C statement (sans semicolon) to output to the stdio stream
10810 +STREAM the assembler definition of a label named NAME.
10811 +Use the expression assemble_name(STREAM, NAME) to
10812 +output the name itself; before and after that, output the additional
10813 +assembler syntax for defining the name, and a newline.
10814 +*/
10815 +#define ASM_OUTPUT_LABEL(STREAM, NAME) avr32_asm_output_label(STREAM, NAME)
10816 +
10817 +/* A C string containing the appropriate assembler directive to
10818 + * specify the size of a symbol, without any arguments. On systems
10819 + * that use ELF, the default (in 'config/elfos.h') is '"\t.size\t"';
10820 + * on other systems, the default is not to define this macro.
10821 + *
10822 + * Define this macro only if it is correct to use the default
10823 + * definitions of ASM_ OUTPUT_SIZE_DIRECTIVE and
10824 + * ASM_OUTPUT_MEASURED_SIZE for your system. If you need your own
10825 + * custom definitions of those macros, or if you do not need explicit
10826 + * symbol sizes at all, do not define this macro.
10827 + */
10828 +#define SIZE_ASM_OP "\t.size\t"
10829 +
10830 +
10831 +/*
10832 +A C statement (sans semicolon) to output to the stdio stream
10833 +STREAM some commands that will make the label NAME global;
10834 +that is, available for reference from other files. Use the expression
10835 +assemble_name(STREAM, NAME) to output the name
10836 +itself; before and after that, output the additional assembler syntax
10837 +for making that name global, and a newline.
10838 +*/
10839 +#define GLOBAL_ASM_OP "\t.globl\t"
10840 +
10841 +
10842 +
10843 +/*
10844 +A C expression which evaluates to true if the target supports weak symbols.
10845 +
10846 +If you don't define this macro, defaults.h provides a default
10847 +definition. If either ASM_WEAKEN_LABEL or ASM_WEAKEN_DECL
10848 +is defined, the default definition is '1'; otherwise, it is
10849 +'0'. Define this macro if you want to control weak symbol support
10850 +with a compiler flag such as -melf.
10851 +*/
10852 +#define SUPPORTS_WEAK 1
10853 +
10854 +/*
10855 +A C statement (sans semicolon) to output to the stdio stream
10856 +STREAM a reference in assembler syntax to a label named
10857 +NAME. This should add '_' to the front of the name, if that
10858 +is customary on your operating system, as it is in most Berkeley Unix
10859 +systems. This macro is used in assemble_name.
10860 +*/
10861 +#define ASM_OUTPUT_LABELREF(STREAM, NAME) \
10862 + avr32_asm_output_labelref(STREAM, NAME)
10863 +
10864 +
10865 +
10866 +/*
10867 +A C expression to assign to OUTVAR (which is a variable of type
10868 +char *) a newly allocated string made from the string
10869 +NAME and the number NUMBER, with some suitable punctuation
10870 +added. Use alloca to get space for the string.
10871 +
10872 +The string will be used as an argument to ASM_OUTPUT_LABELREF to
10873 +produce an assembler label for an internal static variable whose name is
10874 +NAME. Therefore, the string must be such as to result in valid
10875 +assembler code. The argument NUMBER is different each time this
10876 +macro is executed; it prevents conflicts between similarly-named
10877 +internal static variables in different scopes.
10878 +
10879 +Ideally this string should not be a valid C identifier, to prevent any
10880 +conflict with the user's own symbols. Most assemblers allow periods
10881 +or percent signs in assembler symbols; putting at least one of these
10882 +between the name and the number will suffice.
10883 +*/
10884 +#define ASM_FORMAT_PRIVATE_NAME(OUTVAR, NAME, NUMBER) \
10885 + do \
10886 + { \
10887 + (OUTVAR) = (char *) alloca (strlen ((NAME)) + 10); \
10888 + sprintf ((OUTVAR), "%s.%d", (NAME), (NUMBER)); \
10889 + } \
10890 + while (0)
10891 +
10892 +
10893 +/** Macros Controlling Initialization Routines **/
10894 +
10895 +
10896 +/*
10897 +If defined, main will not call __main as described above.
10898 +This macro should be defined for systems that control start-up code
10899 +on a symbol-by-symbol basis, such as OSF/1, and should not
10900 +be defined explicitly for systems that support INIT_SECTION_ASM_OP.
10901 +*/
10902 +/*
10903 + __main is not defined when debugging.
10904 +*/
10905 +#define HAS_INIT_SECTION
10906 +
10907 +
10908 +/** Output of Assembler Instructions **/
10909 +
10910 +/*
10911 +A C initializer containing the assembler's names for the machine
10912 +registers, each one as a C string constant. This is what translates
10913 +register numbers in the compiler into assembler language.
10914 +*/
10915 +
10916 +#define REGISTER_NAMES \
10917 +{ \
10918 + "pc", "lr", \
10919 + "sp", "r12", \
10920 + "r11", "r10", \
10921 + "r9", "r8", \
10922 + "r7", "r6", \
10923 + "r5", "r4", \
10924 + "r3", "r2", \
10925 + "r1", "r0", \
10926 + "f15","f14", \
10927 + "f13","f12", \
10928 + "f11","f10", \
10929 + "f9", "f8", \
10930 + "f7", "f6", \
10931 + "f5", "f4", \
10932 + "f3", "f2", \
10933 + "f1", "f0" \
10934 +}
10935 +
10936 +/*
10937 +A C compound statement to output to stdio stream STREAM the
10938 +assembler syntax for an instruction operand X. X is an
10939 +RTL expression.
10940 +
10941 +CODE is a value that can be used to specify one of several ways
10942 +of printing the operand. It is used when identical operands must be
10943 +printed differently depending on the context. CODE comes from
10944 +the '%' specification that was used to request printing of the
10945 +operand. If the specification was just '%digit' then
10946 +CODE is 0; if the specification was '%ltr digit'
10947 +then CODE is the ASCII code for ltr.
10948 +
10949 +If X is a register, this macro should print the register's name.
10950 +The names can be found in an array reg_names whose type is
10951 +char *[]. reg_names is initialized from REGISTER_NAMES.
10952 +
10953 +When the machine description has a specification '%punct'
10954 +(a '%' followed by a punctuation character), this macro is called
10955 +with a null pointer for X and the punctuation character for
10956 +CODE.
10957 +*/
10958 +#define PRINT_OPERAND(STREAM, X, CODE) avr32_print_operand(STREAM, X, CODE)
10959 +
10960 +/* A C statement to be executed just prior to the output of
10961 + assembler code for INSN, to modify the extracted operands so
10962 + they will be output differently.
10963 +
10964 + Here the argument OPVEC is the vector containing the operands
10965 + extracted from INSN, and NOPERANDS is the number of elements of
10966 + the vector which contain meaningful data for this insn.
10967 + The contents of this vector are what will be used to convert the insn
10968 + template into assembler code, so you can change the assembler output
10969 + by changing the contents of the vector. */
10970 +#define FINAL_PRESCAN_INSN(INSN, OPVEC, NOPERANDS) \
10971 + avr32_final_prescan_insn ((INSN), (OPVEC), (NOPERANDS))
10972 +
10973 +/*
10974 +A C expression which evaluates to true if CODE is a valid
10975 +punctuation character for use in the PRINT_OPERAND macro. If
10976 +PRINT_OPERAND_PUNCT_VALID_P is not defined, it means that no
10977 +punctuation characters (except for the standard one, '%') are used
10978 +in this way.
10979 +*/
10980 +#define PRINT_OPERAND_PUNCT_VALID_P(CODE) \
10981 + (((CODE) == '?') \
10982 + || ((CODE) == '!'))
10983 +
10984 +/*
10985 +A C compound statement to output to stdio stream STREAM the
10986 +assembler syntax for an instruction operand that is a memory reference
10987 +whose address is X. X is an RTL expression.
10988 +
10989 +On some machines, the syntax for a symbolic address depends on the
10990 +section that the address refers to. On these machines, define the macro
10991 +ENCODE_SECTION_INFO to store the information into the
10992 +symbol_ref, and then check for it here. (see Assembler Format.)
10993 +*/
10994 +#define PRINT_OPERAND_ADDRESS(STREAM, X) avr32_print_operand_address(STREAM, X)
10995 +
10996 +
10997 +/** Output of Dispatch Tables **/
10998 +
10999 +/*
11000 + * A C statement to output to the stdio stream stream an assembler
11001 + * pseudo-instruction to generate a difference between two
11002 + * labels. value and rel are the numbers of two internal labels. The
11003 + * definitions of these labels are output using
11004 + * (*targetm.asm_out.internal_label), and they must be printed in the
11005 + * same way here. For example,
11006 + *
11007 + * fprintf (stream, "\t.word L%d-L%d\n",
11008 + * value, rel)
11009 + *
11010 + * You must provide this macro on machines where the addresses in a
11011 + * dispatch table are relative to the table's own address. If defined,
11012 + * GCC will also use this macro on all machines when producing
11013 + * PIC. body is the body of the ADDR_DIFF_VEC; it is provided so that
11014 + * the mode and flags can be read.
11015 + */
11016 +#define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM, BODY, VALUE, REL) \
11017 + fprintf(STREAM, "\tbral\t%sL%d\n", LOCAL_LABEL_PREFIX, VALUE)
11018 +
11019 +/*
11020 +This macro should be provided on machines where the addresses
11021 +in a dispatch table are absolute.
11022 +
11023 +The definition should be a C statement to output to the stdio stream
11024 +STREAM an assembler pseudo-instruction to generate a reference to
11025 +a label. VALUE is the number of an internal label whose
11026 +definition is output using ASM_OUTPUT_INTERNAL_LABEL.
11027 +For example,
11028 +
11029 +fprintf(STREAM, "\t.word L%d\n", VALUE)
11030 +*/
11031 +
11032 +#define ASM_OUTPUT_ADDR_VEC_ELT(STREAM, VALUE) \
11033 + fprintf(STREAM, "\t.long %sL%d\n", LOCAL_LABEL_PREFIX, VALUE)
11034 +
11035 +/** Assembler Commands for Exception Regions */
11036 +
11037 +/* ToDo: All of this subsection */
11038 +
11039 +/** Assembler Commands for Alignment */
11040 +
11041 +
11042 +/*
11043 +A C statement to output to the stdio stream STREAM an assembler
11044 +command to advance the location counter to a multiple of 2 to the
11045 +POWER bytes. POWER will be a C expression of type int.
11046 +*/
11047 +#define ASM_OUTPUT_ALIGN(STREAM, POWER) \
11048 + do \
11049 + { \
11050 + if ((POWER) != 0) \
11051 + fprintf(STREAM, "\t.align\t%d\n", POWER); \
11052 + } \
11053 + while (0)
11054 +
11055 +/*
11056 +Like ASM_OUTPUT_ALIGN, except that the \nop" instruction is used for padding, if
11057 +necessary.
11058 +*/
11059 +#define ASM_OUTPUT_ALIGN_WITH_NOP(STREAM, POWER) \
11060 + fprintf(STREAM, "\t.balignw\t%d, 0xd703\n", (1 << POWER))
11061 +
11062 +
11063 +
11064 +/******************************************************************************
11065 + * Controlling Debugging Information Format
11066 + *****************************************************************************/
11067 +
11068 +/* How to renumber registers for dbx and gdb. */
11069 +#define DBX_REGISTER_NUMBER(REGNO) ASM_REGNUM (REGNO)
11070 +
11071 +/* The DWARF 2 CFA column which tracks the return address. */
11072 +#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM(LR_REGNUM)
11073 +
11074 +/*
11075 +Define this macro if GCC should produce dwarf version 2 format
11076 +debugging output in response to the -g option.
11077 +
11078 +To support optional call frame debugging information, you must also
11079 +define INCOMING_RETURN_ADDR_RTX and either set
11080 +RTX_FRAME_RELATED_P on the prologue insns if you use RTL for the
11081 +prologue, or call dwarf2out_def_cfa and dwarf2out_reg_save
11082 +as appropriate from TARGET_ASM_FUNCTION_PROLOGUE if you don't.
11083 +*/
11084 +#define DWARF2_DEBUGGING_INFO 1
11085 +
11086 +
11087 +#define DWARF2_ASM_LINE_DEBUG_INFO 1
11088 +#define DWARF2_FRAME_INFO 1
11089 +
11090 +
11091 +/******************************************************************************
11092 + * Miscellaneous Parameters
11093 + *****************************************************************************/
11094 +
11095 +/* ToDo: a lot */
11096 +
11097 +/*
11098 +An alias for a machine mode name. This is the machine mode that
11099 +elements of a jump-table should have.
11100 +*/
11101 +#define CASE_VECTOR_MODE SImode
11102 +
11103 +/*
11104 +Define this macro to be a C expression to indicate when jump-tables
11105 +should contain relative addresses. If jump-tables never contain
11106 +relative addresses, then you need not define this macro.
11107 +*/
11108 +#define CASE_VECTOR_PC_RELATIVE 0
11109 +
11110 +/* Increase the threshold for using table jumps on the UC arch. */
11111 +#define CASE_VALUES_THRESHOLD (TARGET_BRANCH_PRED ? 4 : 7)
11112 +
11113 +/*
11114 +The maximum number of bytes that a single instruction can move quickly
11115 +between memory and registers or between two memory locations.
11116 +*/
11117 +#define MOVE_MAX (2*UNITS_PER_WORD)
11118 +
11119 +
11120 +/* A C expression that is nonzero if on this machine the number of bits actually used
11121 + for the count of a shift operation is equal to the number of bits needed to represent
11122 + the size of the object being shifted. When this macro is nonzero, the compiler will
11123 + assume that it is safe to omit a sign-extend, zero-extend, and certain bitwise 'and'
11124 + instructions that truncates the count of a shift operation. On machines that have
11125 + instructions that act on bit-fields at variable positions, which may include 'bit test'
11126 + 378 GNU Compiler Collection (GCC) Internals
11127 + instructions, a nonzero SHIFT_COUNT_TRUNCATED also enables deletion of truncations
11128 + of the values that serve as arguments to bit-field instructions.
11129 + If both types of instructions truncate the count (for shifts) and position (for bit-field
11130 + operations), or if no variable-position bit-field instructions exist, you should define
11131 + this macro.
11132 + However, on some machines, such as the 80386 and the 680x0, truncation only applies
11133 + to shift operations and not the (real or pretended) bit-field operations. Define SHIFT_
11134 + COUNT_TRUNCATED to be zero on such machines. Instead, add patterns to the 'md' file
11135 + that include the implied truncation of the shift instructions.
11136 + You need not de\fne this macro if it would always have the value of zero. */
11137 +#define SHIFT_COUNT_TRUNCATED 1
11138 +
11139 +/*
11140 +A C expression which is nonzero if on this machine it is safe to
11141 +convert an integer of INPREC bits to one of OUTPREC
11142 +bits (where OUTPREC is smaller than INPREC) by merely
11143 +operating on it as if it had only OUTPREC bits.
11144 +
11145 +On many machines, this expression can be 1.
11146 +
11147 +When TRULY_NOOP_TRUNCATION returns 1 for a pair of sizes for
11148 +modes for which MODES_TIEABLE_P is 0, suboptimal code can result.
11149 +If this is the case, making TRULY_NOOP_TRUNCATION return 0 in
11150 +such cases may improve things.
11151 +*/
11152 +#define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
11153 +
11154 +/*
11155 +An alias for the machine mode for pointers. On most machines, define
11156 +this to be the integer mode corresponding to the width of a hardware
11157 +pointer; SImode on 32-bit machine or DImode on 64-bit machines.
11158 +On some machines you must define this to be one of the partial integer
11159 +modes, such as PSImode.
11160 +
11161 +The width of Pmode must be at least as large as the value of
11162 +POINTER_SIZE. If it is not equal, you must define the macro
11163 +POINTERS_EXTEND_UNSIGNED to specify how pointers are extended
11164 +to Pmode.
11165 +*/
11166 +#define Pmode SImode
11167 +
11168 +/*
11169 +An alias for the machine mode used for memory references to functions
11170 +being called, in call RTL expressions. On most machines this
11171 +should be QImode.
11172 +*/
11173 +#define FUNCTION_MODE SImode
11174 +
11175 +
11176 +#define REG_S_P(x) \
11177 + (REG_P (x) || (GET_CODE (x) == SUBREG && REG_P (XEXP (x, 0))))
11178 +
11179 +
11180 +/* If defined, modifies the length assigned to instruction INSN as a
11181 + function of the context in which it is used. LENGTH is an lvalue
11182 + that contains the initially computed length of the insn and should
11183 + be updated with the correct length of the insn. */
11184 +#define ADJUST_INSN_LENGTH(INSN, LENGTH) \
11185 + ((LENGTH) = avr32_adjust_insn_length ((INSN), (LENGTH)))
11186 +
11187 +
11188 +#define CLZ_DEFINED_VALUE_AT_ZERO(mode, value) \
11189 + (value = 32, (mode == SImode))
11190 +
11191 +#define CTZ_DEFINED_VALUE_AT_ZERO(mode, value) \
11192 + (value = 32, (mode == SImode))
11193 +
11194 +#define UNITS_PER_SIMD_WORD UNITS_PER_WORD
11195 +
11196 +#define STORE_FLAG_VALUE 1
11197 +
11198 +
11199 +/* IF-conversion macros. */
11200 +#define IFCVT_MODIFY_INSN( CE_INFO, PATTERN, INSN ) \
11201 + { \
11202 + (PATTERN) = avr32_ifcvt_modify_insn (CE_INFO, PATTERN, INSN, &num_true_changes); \
11203 + }
11204 +
11205 +#define IFCVT_EXTRA_FIELDS \
11206 + int num_cond_clobber_insns; \
11207 + int num_extra_move_insns; \
11208 + rtx extra_move_insns[MAX_CONDITIONAL_EXECUTE]; \
11209 + rtx moved_insns[MAX_CONDITIONAL_EXECUTE];
11210 +
11211 +#define IFCVT_INIT_EXTRA_FIELDS( CE_INFO ) \
11212 + { \
11213 + (CE_INFO)->num_cond_clobber_insns = 0; \
11214 + (CE_INFO)->num_extra_move_insns = 0; \
11215 + }
11216 +
11217 +
11218 +#define IFCVT_MODIFY_CANCEL( CE_INFO ) avr32_ifcvt_modify_cancel (CE_INFO, &num_true_changes)
11219 +
11220 +#define IFCVT_ALLOW_MODIFY_TEST_IN_INSN 1
11221 +#define IFCVT_COND_EXEC_BEFORE_RELOAD (TARGET_COND_EXEC_BEFORE_RELOAD)
11222 +
11223 +enum avr32_builtins
11224 +{
11225 + AVR32_BUILTIN_MTSR,
11226 + AVR32_BUILTIN_MFSR,
11227 + AVR32_BUILTIN_MTDR,
11228 + AVR32_BUILTIN_MFDR,
11229 + AVR32_BUILTIN_CACHE,
11230 + AVR32_BUILTIN_SYNC,
11231 + AVR32_BUILTIN_SSRF,
11232 + AVR32_BUILTIN_CSRF,
11233 + AVR32_BUILTIN_TLBR,
11234 + AVR32_BUILTIN_TLBS,
11235 + AVR32_BUILTIN_TLBW,
11236 + AVR32_BUILTIN_BREAKPOINT,
11237 + AVR32_BUILTIN_XCHG,
11238 + AVR32_BUILTIN_LDXI,
11239 + AVR32_BUILTIN_BSWAP16,
11240 + AVR32_BUILTIN_BSWAP32,
11241 + AVR32_BUILTIN_COP,
11242 + AVR32_BUILTIN_MVCR_W,
11243 + AVR32_BUILTIN_MVRC_W,
11244 + AVR32_BUILTIN_MVCR_D,
11245 + AVR32_BUILTIN_MVRC_D,
11246 + AVR32_BUILTIN_MULSATHH_H,
11247 + AVR32_BUILTIN_MULSATHH_W,
11248 + AVR32_BUILTIN_MULSATRNDHH_H,
11249 + AVR32_BUILTIN_MULSATRNDWH_W,
11250 + AVR32_BUILTIN_MULSATWH_W,
11251 + AVR32_BUILTIN_MACSATHH_W,
11252 + AVR32_BUILTIN_SATADD_H,
11253 + AVR32_BUILTIN_SATSUB_H,
11254 + AVR32_BUILTIN_SATADD_W,
11255 + AVR32_BUILTIN_SATSUB_W,
11256 + AVR32_BUILTIN_MULWH_D,
11257 + AVR32_BUILTIN_MULNWH_D,
11258 + AVR32_BUILTIN_MACWH_D,
11259 + AVR32_BUILTIN_MACHH_D,
11260 + AVR32_BUILTIN_MUSFR,
11261 + AVR32_BUILTIN_MUSTR,
11262 + AVR32_BUILTIN_SATS,
11263 + AVR32_BUILTIN_SATU,
11264 + AVR32_BUILTIN_SATRNDS,
11265 + AVR32_BUILTIN_SATRNDU
11266 +};
11267 +
11268 +
11269 +#define FLOAT_LIB_COMPARE_RETURNS_BOOL(MODE, COMPARISON) \
11270 + ((MODE == SFmode) || (MODE == DFmode))
11271 +
11272 +#define RENAME_LIBRARY_SET ".set"
11273 +
11274 +/* Make ABI_NAME an alias for __GCC_NAME. */
11275 +#define RENAME_LIBRARY(GCC_NAME, ABI_NAME) \
11276 + __asm__ (".globl\t__avr32_" #ABI_NAME "\n" \
11277 + ".set\t__avr32_" #ABI_NAME \
11278 + ", __" #GCC_NAME "\n");
11279 +
11280 +/* Give libgcc functions avr32 ABI name. */
11281 +#ifdef L_muldi3
11282 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (muldi3, mul64)
11283 +#endif
11284 +#ifdef L_divdi3
11285 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (divdi3, sdiv64)
11286 +#endif
11287 +#ifdef L_udivdi3
11288 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (udivdi3, udiv64)
11289 +#endif
11290 +#ifdef L_moddi3
11291 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (moddi3, smod64)
11292 +#endif
11293 +#ifdef L_umoddi3
11294 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (umoddi3, umod64)
11295 +#endif
11296 +#ifdef L_ashldi3
11297 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (ashldi3, lsl64)
11298 +#endif
11299 +#ifdef L_lshrdi3
11300 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (lshrdi3, lsr64)
11301 +#endif
11302 +#ifdef L_ashrdi3
11303 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (ashrdi3, asr64)
11304 +#endif
11305 +
11306 +#ifdef L_fixsfdi
11307 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (fixsfdi, f32_to_s64)
11308 +#endif
11309 +#ifdef L_fixunssfdi
11310 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (fixunssfdi, f32_to_u64)
11311 +#endif
11312 +#ifdef L_floatdidf
11313 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (floatdidf, s64_to_f64)
11314 +#endif
11315 +#ifdef L_floatdisf
11316 +#define DECLARE_LIBRARY_RENAMES RENAME_LIBRARY (floatdisf, s64_to_f32)
11317 +#endif
11318 +
11319 +#endif
11320 --- /dev/null
11321 +++ b/gcc/config/avr32/avr32.md
11322 @@ -0,0 +1,4926 @@
11323 +;; AVR32 machine description file.
11324 +;; Copyright 2003-2006 Atmel Corporation.
11325 +;;
11326 +;; Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
11327 +;;
11328 +;; This file is part of GCC.
11329 +;;
11330 +;; This program is free software; you can redistribute it and/or modify
11331 +;; it under the terms of the GNU General Public License as published by
11332 +;; the Free Software Foundation; either version 2 of the License, or
11333 +;; (at your option) any later version.
11334 +;;
11335 +;; This program is distributed in the hope that it will be useful,
11336 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11337 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11338 +;; GNU General Public License for more details.
11339 +;;
11340 +;; You should have received a copy of the GNU General Public License
11341 +;; along with this program; if not, write to the Free Software
11342 +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11343 +
11344 +;; -*- Mode: Scheme -*-
11345 +
11346 +(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"
11347 + (const_string "alu"))
11348 +
11349 +
11350 +(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"
11351 + (const_string "none"))
11352 +
11353 +
11354 +; NB! Keep this in sync with enum architecture_type in avr32.h
11355 +(define_attr "pipeline" "ap,ucr1,ucr2,ucr2nomul,ucr3"
11356 + (const (symbol_ref "avr32_arch->arch_type")))
11357 +
11358 +; Insn length in bytes
11359 +(define_attr "length" ""
11360 + (const_int 4))
11361 +
11362 +; Signal if an insn is predicable and hence can be conditionally executed.
11363 +(define_attr "predicable" "no,yes" (const_string "no"))
11364 +
11365 +;; Uses of UNSPEC in this file:
11366 +(define_constants
11367 + [(UNSPEC_PUSHM 0)
11368 + (UNSPEC_POPM 1)
11369 + (UNSPEC_UDIVMODSI4_INTERNAL 2)
11370 + (UNSPEC_DIVMODSI4_INTERNAL 3)
11371 + (UNSPEC_STM 4)
11372 + (UNSPEC_LDM 5)
11373 + (UNSPEC_MOVSICC 6)
11374 + (UNSPEC_ADDSICC 7)
11375 + (UNSPEC_COND_MI 8)
11376 + (UNSPEC_COND_PL 9)
11377 + (UNSPEC_PIC_SYM 10)
11378 + (UNSPEC_PIC_BASE 11)
11379 + (UNSPEC_STORE_MULTIPLE 12)
11380 + (UNSPEC_STMFP 13)
11381 + (UNSPEC_FPCC_TO_REG 14)
11382 + (UNSPEC_REG_TO_CC 15)
11383 + (UNSPEC_FORCE_MINIPOOL 16)
11384 + (UNSPEC_SATS 17)
11385 + (UNSPEC_SATU 18)
11386 + (UNSPEC_SATRNDS 19)
11387 + (UNSPEC_SATRNDU 20)
11388 + ])
11389 +
11390 +(define_constants
11391 + [(VUNSPEC_EPILOGUE 0)
11392 + (VUNSPEC_CACHE 1)
11393 + (VUNSPEC_MTSR 2)
11394 + (VUNSPEC_MFSR 3)
11395 + (VUNSPEC_BLOCKAGE 4)
11396 + (VUNSPEC_SYNC 5)
11397 + (VUNSPEC_TLBR 6)
11398 + (VUNSPEC_TLBW 7)
11399 + (VUNSPEC_TLBS 8)
11400 + (VUNSPEC_BREAKPOINT 9)
11401 + (VUNSPEC_MTDR 10)
11402 + (VUNSPEC_MFDR 11)
11403 + (VUNSPEC_MVCR 12)
11404 + (VUNSPEC_MVRC 13)
11405 + (VUNSPEC_COP 14)
11406 + (VUNSPEC_ALIGN 15)
11407 + (VUNSPEC_POOL_START 16)
11408 + (VUNSPEC_POOL_END 17)
11409 + (VUNSPEC_POOL_4 18)
11410 + (VUNSPEC_POOL_8 19)
11411 + (VUNSPEC_POOL_16 20)
11412 + (VUNSPEC_MUSFR 21)
11413 + (VUNSPEC_MUSTR 22)
11414 + (VUNSPEC_SYNC_CMPXCHG 23)
11415 + (VUNSPEC_SYNC_SET_LOCK_AND_LOAD 24)
11416 + (VUNSPEC_SYNC_STORE_IF_LOCK 25)
11417 + (VUNSPEC_EH_RETURN 26)
11418 + (VUNSPEC_FRS 27)
11419 + (VUNSPEC_CSRF 28)
11420 + (VUNSPEC_SSRF 29)
11421 + ])
11422 +
11423 +(define_constants
11424 + [
11425 + ;; R7 = 15-7 = 8
11426 + (FP_REGNUM 8)
11427 + ;; Return Register = R12 = 15 - 12 = 3
11428 + (RETVAL_REGNUM 3)
11429 + ;; SP = R13 = 15 - 13 = 2
11430 + (SP_REGNUM 2)
11431 + ;; LR = R14 = 15 - 14 = 1
11432 + (LR_REGNUM 1)
11433 + ;; PC = R15 = 15 - 15 = 0
11434 + (PC_REGNUM 0)
11435 + ;; FPSR = GENERAL_REGS + 1 = 17
11436 + (FPCC_REGNUM 17)
11437 + ])
11438 +
11439 +
11440 +
11441 +
11442 +;;******************************************************************************
11443 +;; Macros
11444 +;;******************************************************************************
11445 +
11446 +;; Integer Modes for basic alu insns
11447 +(define_mode_iterator INTM [SI HI QI])
11448 +(define_mode_attr alu_cc_attr [(SI "set_vncz") (HI "clobber") (QI "clobber")])
11449 +
11450 +;; Move word modes
11451 +(define_mode_iterator MOVM [SI V2HI V4QI])
11452 +
11453 +;; For mov/addcc insns
11454 +(define_mode_iterator ADDCC [SI HI QI])
11455 +(define_mode_iterator MOVCC [SF SI HI QI])
11456 +(define_mode_iterator CMP [DI SI HI QI])
11457 +(define_mode_attr store_postfix [(SF ".w") (SI ".w") (HI ".h") (QI ".b")])
11458 +(define_mode_attr load_postfix [(SF ".w") (SI ".w") (HI ".sh") (QI ".ub")])
11459 +(define_mode_attr load_postfix_s [(SI ".w") (HI ".sh") (QI ".sb")])
11460 +(define_mode_attr load_postfix_u [(SI ".w") (HI ".uh") (QI ".ub")])
11461 +(define_mode_attr pred_mem_constraint [(SF "RKu11") (SI "RKu11") (HI "RKu10") (QI "RKu09")])
11462 +(define_mode_attr cmp_constraint [(DI "rKu20") (SI "rKs21") (HI "r") (QI "r")])
11463 +(define_mode_attr cmp_predicate [(DI "register_immediate_operand")
11464 + (SI "register_const_int_operand")
11465 + (HI "register_operand")
11466 + (QI "register_operand")])
11467 +(define_mode_attr cmp_length [(DI "6")
11468 + (SI "4")
11469 + (HI "4")
11470 + (QI "4")])
11471 +
11472 +;; For all conditional insns
11473 +(define_code_iterator any_cond [eq ne gt ge lt le gtu geu ltu leu])
11474 +(define_code_attr cond [(eq "eq") (ne "ne") (gt "gt") (ge "ge") (lt "lt") (le "le")
11475 + (gtu "hi") (geu "hs") (ltu "lo") (leu "ls")])
11476 +(define_code_attr invcond [(eq "ne") (ne "eq") (gt "le") (ge "lt") (lt "ge") (le "gt")
11477 + (gtu "ls") (geu "lo") (ltu "hs") (leu "hi")])
11478 +
11479 +;; For logical operations
11480 +(define_code_iterator logical [and ior xor])
11481 +(define_code_attr logical_insn [(and "and") (ior "or") (xor "eor")])
11482 +
11483 +;; Predicable operations with three register operands
11484 +(define_code_iterator predicable_op3 [and ior xor plus minus])
11485 +(define_code_attr predicable_insn3 [(and "and") (ior "or") (xor "eor") (plus "add") (minus "sub")])
11486 +(define_code_attr predicable_commutative3 [(and "%") (ior "%") (xor "%") (plus "%") (minus "")])
11487 +
11488 +;; Load the predicates
11489 +(include "predicates.md")
11490 +
11491 +
11492 +;;******************************************************************************
11493 +;; Automaton pipeline description for avr32
11494 +;;******************************************************************************
11495 +
11496 +(define_automaton "avr32_ap")
11497 +
11498 +
11499 +(define_cpu_unit "is" "avr32_ap")
11500 +(define_cpu_unit "a1,m1,da" "avr32_ap")
11501 +(define_cpu_unit "a2,m2,d" "avr32_ap")
11502 +
11503 +;;Alu instructions
11504 +(define_insn_reservation "alu_op" 1
11505 + (and (eq_attr "pipeline" "ap")
11506 + (eq_attr "type" "alu"))
11507 + "is,a1,a2")
11508 +
11509 +(define_insn_reservation "alu2_op" 2
11510 + (and (eq_attr "pipeline" "ap")
11511 + (eq_attr "type" "alu2"))
11512 + "is,is+a1,a1+a2,a2")
11513 +
11514 +(define_insn_reservation "alu_sat_op" 2
11515 + (and (eq_attr "pipeline" "ap")
11516 + (eq_attr "type" "alu_sat"))
11517 + "is,a1,a2")
11518 +
11519 +
11520 +;;Mul instructions
11521 +(define_insn_reservation "mulhh_op" 2
11522 + (and (eq_attr "pipeline" "ap")
11523 + (eq_attr "type" "mulhh,mulwh"))
11524 + "is,m1,m2")
11525 +
11526 +(define_insn_reservation "mulww_w_op" 3
11527 + (and (eq_attr "pipeline" "ap")
11528 + (eq_attr "type" "mulww_w"))
11529 + "is,m1,m1+m2,m2")
11530 +
11531 +(define_insn_reservation "mulww_d_op" 5
11532 + (and (eq_attr "pipeline" "ap")
11533 + (eq_attr "type" "mulww_d"))
11534 + "is,m1,m1+m2,m1+m2,m2,m2")
11535 +
11536 +(define_insn_reservation "div_op" 33
11537 + (and (eq_attr "pipeline" "ap")
11538 + (eq_attr "type" "div"))
11539 + "is,m1,m1*31 + m2*31,m2")
11540 +
11541 +(define_insn_reservation "machh_w_op" 3
11542 + (and (eq_attr "pipeline" "ap")
11543 + (eq_attr "type" "machh_w"))
11544 + "is*2,m1,m2")
11545 +
11546 +
11547 +(define_insn_reservation "macww_w_op" 4
11548 + (and (eq_attr "pipeline" "ap")
11549 + (eq_attr "type" "macww_w"))
11550 + "is*2,m1,m1,m2")
11551 +
11552 +
11553 +(define_insn_reservation "macww_d_op" 6
11554 + (and (eq_attr "pipeline" "ap")
11555 + (eq_attr "type" "macww_d"))
11556 + "is*2,m1,m1+m2,m1+m2,m2")
11557 +
11558 +;;Bypasses for Mac instructions, because of accumulator cache.
11559 +;;Set latency as low as possible in order to let the compiler let
11560 +;;mul -> mac and mac -> mac combinations which use the same
11561 +;;accumulator cache be placed close together to avoid any
11562 +;;instructions which can ruin the accumulator cache come inbetween.
11563 +(define_bypass 4 "machh_w_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11564 +(define_bypass 5 "macww_w_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11565 +(define_bypass 7 "macww_d_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11566 +
11567 +(define_bypass 3 "mulhh_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11568 +(define_bypass 4 "mulww_w_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11569 +(define_bypass 6 "mulww_d_op" "alu_op,alu2_op,alu_sat_op,load_op" "avr32_mul_waw_bypass")
11570 +
11571 +
11572 +;;Bypasses for all mul/mac instructions followed by an instruction
11573 +;;which reads the output AND writes the result to the same register.
11574 +;;This will generate an Write After Write hazard which gives an
11575 +;;extra cycle before the result is ready.
11576 +(define_bypass 0 "machh_w_op" "machh_w_op" "avr32_valid_macmac_bypass")
11577 +(define_bypass 0 "macww_w_op" "macww_w_op" "avr32_valid_macmac_bypass")
11578 +(define_bypass 0 "macww_d_op" "macww_d_op" "avr32_valid_macmac_bypass")
11579 +
11580 +(define_bypass 0 "mulhh_op" "machh_w_op" "avr32_valid_mulmac_bypass")
11581 +(define_bypass 0 "mulww_w_op" "macww_w_op" "avr32_valid_mulmac_bypass")
11582 +(define_bypass 0 "mulww_d_op" "macww_d_op" "avr32_valid_mulmac_bypass")
11583 +
11584 +;;Branch and call instructions
11585 +;;We assume that all branches and rcalls are predicted correctly :-)
11586 +;;while calls use a lot of cycles.
11587 +(define_insn_reservation "branch_op" 0
11588 + (and (eq_attr "pipeline" "ap")
11589 + (eq_attr "type" "branch"))
11590 + "nothing")
11591 +
11592 +(define_insn_reservation "call_op" 10
11593 + (and (eq_attr "pipeline" "ap")
11594 + (eq_attr "type" "call"))
11595 + "nothing")
11596 +
11597 +
11598 +;;Load store instructions
11599 +(define_insn_reservation "load_op" 2
11600 + (and (eq_attr "pipeline" "ap")
11601 + (eq_attr "type" "load"))
11602 + "is,da,d")
11603 +
11604 +(define_insn_reservation "load_rm_op" 3
11605 + (and (eq_attr "pipeline" "ap")
11606 + (eq_attr "type" "load_rm"))
11607 + "is,da,d")
11608 +
11609 +
11610 +(define_insn_reservation "store_op" 0
11611 + (and (eq_attr "pipeline" "ap")
11612 + (eq_attr "type" "store"))
11613 + "is,da,d")
11614 +
11615 +
11616 +(define_insn_reservation "load_double_op" 3
11617 + (and (eq_attr "pipeline" "ap")
11618 + (eq_attr "type" "load2"))
11619 + "is,da,da+d,d")
11620 +
11621 +(define_insn_reservation "load_quad_op" 4
11622 + (and (eq_attr "pipeline" "ap")
11623 + (eq_attr "type" "load4"))
11624 + "is,da,da+d,da+d,d")
11625 +
11626 +(define_insn_reservation "store_double_op" 0
11627 + (and (eq_attr "pipeline" "ap")
11628 + (eq_attr "type" "store2"))
11629 + "is,da,da+d,d")
11630 +
11631 +
11632 +(define_insn_reservation "store_quad_op" 0
11633 + (and (eq_attr "pipeline" "ap")
11634 + (eq_attr "type" "store4"))
11635 + "is,da,da+d,da+d,d")
11636 +
11637 +;;For store the operand to write to memory is read in d and
11638 +;;the real latency between any instruction and a store is therefore
11639 +;;one less than for the instructions which reads the operands in the first
11640 +;;excecution stage
11641 +(define_bypass 2 "load_double_op" "store_double_op" "avr32_store_bypass")
11642 +(define_bypass 3 "load_quad_op" "store_quad_op" "avr32_store_bypass")
11643 +(define_bypass 1 "load_op" "store_op" "avr32_store_bypass")
11644 +(define_bypass 2 "load_rm_op" "store_op" "avr32_store_bypass")
11645 +(define_bypass 1 "alu_sat_op" "store_op" "avr32_store_bypass")
11646 +(define_bypass 1 "alu2_op" "store_op" "avr32_store_bypass")
11647 +(define_bypass 1 "mulhh_op" "store_op" "avr32_store_bypass")
11648 +(define_bypass 2 "mulww_w_op" "store_op" "avr32_store_bypass")
11649 +(define_bypass 4 "mulww_d_op" "store_op" "avr32_store_bypass" )
11650 +(define_bypass 2 "machh_w_op" "store_op" "avr32_store_bypass")
11651 +(define_bypass 3 "macww_w_op" "store_op" "avr32_store_bypass")
11652 +(define_bypass 5 "macww_d_op" "store_op" "avr32_store_bypass")
11653 +
11654 +
11655 +; Bypass for load double operation. If only the first loaded word is needed
11656 +; then the latency is 2
11657 +(define_bypass 2 "load_double_op"
11658 + "load_op,load_rm_op,alu_sat_op, alu2_op, alu_op, mulhh_op, mulww_w_op,
11659 + mulww_d_op, machh_w_op, macww_w_op, macww_d_op"
11660 + "avr32_valid_load_double_bypass")
11661 +
11662 +; Bypass for load quad operation. If only the first or second loaded word is needed
11663 +; we set the latency to 2
11664 +(define_bypass 2 "load_quad_op"
11665 + "load_op,load_rm_op,alu_sat_op, alu2_op, alu_op, mulhh_op, mulww_w_op,
11666 + mulww_d_op, machh_w_op, macww_w_op, macww_d_op"
11667 + "avr32_valid_load_quad_bypass")
11668 +
11669 +
11670 +;;******************************************************************************
11671 +;; End of Automaton pipeline description for avr32
11672 +;;******************************************************************************
11673 +
11674 +(define_cond_exec
11675 + [(match_operator 0 "avr32_comparison_operator"
11676 + [(match_operand:CMP 1 "register_operand" "r")
11677 + (match_operand:CMP 2 "<CMP:cmp_predicate>" "<CMP:cmp_constraint>")])]
11678 + "TARGET_V2_INSNS"
11679 + "%!"
11680 +)
11681 +
11682 +(define_cond_exec
11683 + [(match_operator 0 "avr32_comparison_operator"
11684 + [(and:SI (match_operand:SI 1 "register_operand" "r")
11685 + (match_operand:SI 2 "one_bit_set_operand" "i"))
11686 + (const_int 0)])]
11687 + "TARGET_V2_INSNS"
11688 + "%!"
11689 + )
11690 +
11691 +;;=============================================================================
11692 +;; move
11693 +;;-----------------------------------------------------------------------------
11694 +
11695 +
11696 +;;== char - 8 bits ============================================================
11697 +(define_expand "movqi"
11698 + [(set (match_operand:QI 0 "nonimmediate_operand" "")
11699 + (match_operand:QI 1 "general_operand" ""))]
11700 + ""
11701 + {
11702 + if ( can_create_pseudo_p () ){
11703 + if (GET_CODE (operands[1]) == MEM && optimize){
11704 + rtx reg = gen_reg_rtx (SImode);
11705 +
11706 + emit_insn (gen_zero_extendqisi2 (reg, operands[1]));
11707 + operands[1] = gen_lowpart (QImode, reg);
11708 + }
11709 +
11710 + /* One of the ops has to be in a register. */
11711 + if (GET_CODE (operands[0]) == MEM)
11712 + operands[1] = force_reg (QImode, operands[1]);
11713 + }
11714 +
11715 + })
11716 +
11717 +(define_insn "*movqi_internal"
11718 + [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r")
11719 + (match_operand:QI 1 "general_operand" "rKs08,m,r,i"))]
11720 + "register_operand (operands[0], QImode)
11721 + || register_operand (operands[1], QImode)"
11722 + "@
11723 + mov\t%0, %1
11724 + ld.ub\t%0, %1
11725 + st.b\t%0, %1
11726 + mov\t%0, %1"
11727 + [(set_attr "length" "2,4,4,4")
11728 + (set_attr "type" "alu,load_rm,store,alu")])
11729 +
11730 +
11731 +
11732 +;;== short - 16 bits ==========================================================
11733 +(define_expand "movhi"
11734 + [(set (match_operand:HI 0 "nonimmediate_operand" "")
11735 + (match_operand:HI 1 "general_operand" ""))]
11736 + ""
11737 + {
11738 + if ( can_create_pseudo_p () ){
11739 + if (GET_CODE (operands[1]) == MEM && optimize){
11740 + rtx reg = gen_reg_rtx (SImode);
11741 +
11742 + emit_insn (gen_extendhisi2 (reg, operands[1]));
11743 + operands[1] = gen_lowpart (HImode, reg);
11744 + }
11745 +
11746 + /* One of the ops has to be in a register. */
11747 + if (GET_CODE (operands[0]) == MEM)
11748 + operands[1] = force_reg (HImode, operands[1]);
11749 + }
11750 +
11751 + })
11752 +
11753 +
11754 +(define_insn "*movhi_internal"
11755 + [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r")
11756 + (match_operand:HI 1 "general_operand" "rKs08,m,r,i"))]
11757 + "register_operand (operands[0], HImode)
11758 + || register_operand (operands[1], HImode)"
11759 + "@
11760 + mov\t%0, %1
11761 + ld.sh\t%0, %1
11762 + st.h\t%0, %1
11763 + mov\t%0, %1"
11764 + [(set_attr "length" "2,4,4,4")
11765 + (set_attr "type" "alu,load_rm,store,alu")])
11766 +
11767 +
11768 +;;== int - 32 bits ============================================================
11769 +
11770 +(define_expand "movmisalignsi"
11771 + [(set (match_operand:SI 0 "nonimmediate_operand" "")
11772 + (match_operand:SI 1 "nonimmediate_operand" ""))]
11773 + "TARGET_UNALIGNED_WORD"
11774 + {
11775 + }
11776 +)
11777 +
11778 +
11779 +(define_expand "mov<mode>"
11780 + [(set (match_operand:MOVM 0 "register_operand" "")
11781 + (match_operand:MOVM 1 "general_operand" ""))]
11782 + ""
11783 + {
11784 +
11785 + /* One of the ops has to be in a register. */
11786 + if (GET_CODE (operands[0]) == MEM)
11787 + operands[1] = force_reg (<MODE>mode, operands[1]);
11788 +
11789 +
11790 + /* Check for out of range immediate constants as these may
11791 + occur during reloading, since it seems like reload does
11792 + not check if the immediate is legitimate. Don't know if
11793 + this is a bug? */
11794 + if ( reload_in_progress
11795 + && avr32_imm_in_const_pool
11796 + && GET_CODE(operands[1]) == CONST_INT
11797 + && !avr32_const_ok_for_constraint_p(INTVAL(operands[1]), 'K', "Ks21") ){
11798 + operands[1] = force_const_mem(SImode, operands[1]);
11799 + }
11800 +
11801 + if ( (flag_pic || TARGET_HAS_ASM_ADDR_PSEUDOS)
11802 + && !avr32_legitimate_pic_operand_p(operands[1]) )
11803 + operands[1] = legitimize_pic_address (operands[1], <MODE>mode,
11804 + (can_create_pseudo_p () ? 0: operands[0]));
11805 + else if ( flag_pic && avr32_address_operand(operands[1], GET_MODE(operands[1])) )
11806 + /* If we have an address operand then this function uses the pic register. */
11807 + current_function_uses_pic_offset_table = 1;
11808 + })
11809 +
11810 +
11811 +
11812 +(define_insn "mov<mode>_internal"
11813 + [(set (match_operand:MOVM 0 "nonimmediate_operand" "=r, r, r,r,r,m,r")
11814 + (match_operand:MOVM 1 "general_operand" "rKs08,Ks21,J,n,m,r,W"))]
11815 + "register_operand (operands[0], <MODE>mode)
11816 + || register_operand (operands[1], <MODE>mode)"
11817 + {
11818 + switch (which_alternative) {
11819 + case 0:
11820 + case 1: return "mov\t%0, %1";
11821 + case 2:
11822 + if ( TARGET_V2_INSNS )
11823 + return "movh\t%0, hi(%1)";
11824 + /* Fallthrough */
11825 + case 3: return "mov\t%0, lo(%1)\;orh\t%0,hi(%1)";
11826 + case 4:
11827 + if ( (REG_P(XEXP(operands[1], 0))
11828 + && REGNO(XEXP(operands[1], 0)) == SP_REGNUM)
11829 + || (GET_CODE(XEXP(operands[1], 0)) == PLUS
11830 + && REGNO(XEXP(XEXP(operands[1], 0), 0)) == SP_REGNUM
11831 + && GET_CODE(XEXP(XEXP(operands[1], 0), 1)) == CONST_INT
11832 + && INTVAL(XEXP(XEXP(operands[1], 0), 1)) % 4 == 0
11833 + && INTVAL(XEXP(XEXP(operands[1], 0), 1)) <= 0x1FC) )
11834 + return "lddsp\t%0, %1";
11835 + else if ( avr32_const_pool_ref_operand(operands[1], GET_MODE(operands[1])) )
11836 + return "lddpc\t%0, %1";
11837 + else
11838 + return "ld.w\t%0, %1";
11839 + case 5:
11840 + if ( (REG_P(XEXP(operands[0], 0))
11841 + && REGNO(XEXP(operands[0], 0)) == SP_REGNUM)
11842 + || (GET_CODE(XEXP(operands[0], 0)) == PLUS
11843 + && REGNO(XEXP(XEXP(operands[0], 0), 0)) == SP_REGNUM
11844 + && GET_CODE(XEXP(XEXP(operands[0], 0), 1)) == CONST_INT
11845 + && INTVAL(XEXP(XEXP(operands[0], 0), 1)) % 4 == 0
11846 + && INTVAL(XEXP(XEXP(operands[0], 0), 1)) <= 0x1FC) )
11847 + return "stdsp\t%0, %1";
11848 + else
11849 + return "st.w\t%0, %1";
11850 + case 6:
11851 + if ( TARGET_HAS_ASM_ADDR_PSEUDOS )
11852 + return "lda.w\t%0, %1";
11853 + else
11854 + return "ld.w\t%0, r6[%1@got]";
11855 + default:
11856 + abort();
11857 + }
11858 + }
11859 +
11860 + [(set_attr "length" "2,4,4,8,4,4,8")
11861 + (set_attr "type" "alu,alu,alu,alu2,load,store,load")
11862 + (set_attr "cc" "none,none,set_z_if_not_v2,set_z,none,none,clobber")])
11863 +
11864 +
11865 +
11866 +
11867 +;; These instructions are for loading constants which cannot be loaded
11868 +;; directly from the constant pool because the offset is too large
11869 +;; high and lo_sum are used even tough for our case it should be
11870 +;; low and high sum :-)
11871 +(define_insn "mov_symbol_lo"
11872 + [(set (match_operand:SI 0 "register_operand" "=r")
11873 + (high:SI (match_operand:SI 1 "immediate_operand" "i" )))]
11874 + ""
11875 + "mov\t%0, lo(%1)"
11876 + [(set_attr "type" "alu")
11877 + (set_attr "length" "4")]
11878 +)
11879 +
11880 +(define_insn "add_symbol_hi"
11881 + [(set (match_operand:SI 0 "register_operand" "=r")
11882 + (lo_sum:SI (match_dup 0)
11883 + (match_operand:SI 1 "immediate_operand" "i" )))]
11884 + ""
11885 + "orh\t%0, hi(%1)"
11886 + [(set_attr "type" "alu")
11887 + (set_attr "length" "4")]
11888 +)
11889 +
11890 +
11891 +
11892 +;; When generating pic, we need to load the symbol offset into a register.
11893 +;; So that the optimizer does not confuse this with a normal symbol load
11894 +;; we use an unspec. The offset will be loaded from a constant pool entry,
11895 +;; since that is the only type of relocation we can use.
11896 +(define_insn "pic_load_addr"
11897 + [(set (match_operand:SI 0 "register_operand" "=r")
11898 + (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PIC_SYM))]
11899 + "flag_pic && CONSTANT_POOL_ADDRESS_P(XEXP(operands[1], 0))"
11900 + "lddpc\t%0, %1"
11901 + [(set_attr "type" "load")
11902 + (set_attr "length" "4")]
11903 +)
11904 +
11905 +(define_insn "pic_compute_got_from_pc"
11906 + [(set (match_operand:SI 0 "register_operand" "+r")
11907 + (unspec:SI [(minus:SI (pc)
11908 + (match_dup 0))] UNSPEC_PIC_BASE))
11909 + (use (label_ref (match_operand 1 "" "")))]
11910 + "flag_pic"
11911 + {
11912 + (*targetm.asm_out.internal_label) (asm_out_file, "L",
11913 + CODE_LABEL_NUMBER (operands[1]));
11914 + return \"rsub\t%0, pc\";
11915 + }
11916 + [(set_attr "cc" "clobber")
11917 + (set_attr "length" "2")]
11918 +)
11919 +
11920 +;;== long long int - 64 bits ==================================================
11921 +
11922 +(define_expand "movdi"
11923 + [(set (match_operand:DI 0 "nonimmediate_operand" "")
11924 + (match_operand:DI 1 "general_operand" ""))]
11925 + ""
11926 + {
11927 +
11928 + /* One of the ops has to be in a register. */
11929 + if (GET_CODE (operands[0]) != REG)
11930 + operands[1] = force_reg (DImode, operands[1]);
11931 +
11932 + })
11933 +
11934 +
11935 +(define_insn_and_split "*movdi_internal"
11936 + [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r, r, r,r,r,m")
11937 + (match_operand:DI 1 "general_operand" "r, Ks08,Ks21,G,n,m,r"))]
11938 + "register_operand (operands[0], DImode)
11939 + || register_operand (operands[1], DImode)"
11940 + {
11941 + switch (which_alternative ){
11942 + case 0:
11943 + case 1:
11944 + case 2:
11945 + case 3:
11946 + case 4:
11947 + return "#";
11948 + case 5:
11949 + if ( avr32_const_pool_ref_operand(operands[1], GET_MODE(operands[1])))
11950 + return "ld.d\t%0, pc[%1 - .]";
11951 + else
11952 + return "ld.d\t%0, %1";
11953 + case 6:
11954 + return "st.d\t%0, %1";
11955 + default:
11956 + abort();
11957 + }
11958 + }
11959 +;; Lets split all reg->reg or imm->reg transfers into two SImode transfers
11960 + "reload_completed &&
11961 + (REG_P (operands[0]) &&
11962 + (REG_P (operands[1])
11963 + || GET_CODE (operands[1]) == CONST_INT
11964 + || GET_CODE (operands[1]) == CONST_DOUBLE))"
11965 + [(set (match_dup 0) (match_dup 1))
11966 + (set (match_dup 2) (match_dup 3))]
11967 + {
11968 + operands[2] = gen_highpart (SImode, operands[0]);
11969 + operands[0] = gen_lowpart (SImode, operands[0]);
11970 + if ( REG_P(operands[1]) ){
11971 + operands[3] = gen_highpart(SImode, operands[1]);
11972 + operands[1] = gen_lowpart(SImode, operands[1]);
11973 + } else if ( GET_CODE(operands[1]) == CONST_DOUBLE
11974 + || GET_CODE(operands[1]) == CONST_INT ){
11975 + rtx split_const[2];
11976 + avr32_split_const_expr (DImode, SImode, operands[1], split_const);
11977 + operands[3] = split_const[1];
11978 + operands[1] = split_const[0];
11979 + } else {
11980 + internal_error("Illegal operand[1] for movdi split!");
11981 + }
11982 + }
11983 +
11984 + [(set_attr "length" "*,*,*,*,*,4,4")
11985 + (set_attr "type" "*,*,*,*,*,load2,store2")
11986 + (set_attr "cc" "*,*,*,*,*,none,none")])
11987 +
11988 +
11989 +;;== 128 bits ==================================================
11990 +(define_expand "movti"
11991 + [(set (match_operand:TI 0 "nonimmediate_operand" "")
11992 + (match_operand:TI 1 "nonimmediate_operand" ""))]
11993 + "TARGET_ARCH_AP"
11994 + {
11995 +
11996 + /* One of the ops has to be in a register. */
11997 + if (GET_CODE (operands[0]) != REG)
11998 + operands[1] = force_reg (TImode, operands[1]);
11999 +
12000 + /* We must fix any pre_dec for loads and post_inc stores */
12001 + if ( GET_CODE (operands[0]) == MEM
12002 + && GET_CODE (XEXP(operands[0],0)) == POST_INC ){
12003 + emit_move_insn(gen_rtx_MEM(TImode, XEXP(XEXP(operands[0],0),0)), operands[1]);
12004 + emit_insn(gen_addsi3(XEXP(XEXP(operands[0],0),0), XEXP(XEXP(operands[0],0),0), GEN_INT(GET_MODE_SIZE(TImode))));
12005 + DONE;
12006 + }
12007 +
12008 + if ( GET_CODE (operands[1]) == MEM
12009 + && GET_CODE (XEXP(operands[1],0)) == PRE_DEC ){
12010 + emit_insn(gen_addsi3(XEXP(XEXP(operands[1],0),0), XEXP(XEXP(operands[1],0),0), GEN_INT(-GET_MODE_SIZE(TImode))));
12011 + emit_move_insn(operands[0], gen_rtx_MEM(TImode, XEXP(XEXP(operands[1],0),0)));
12012 + DONE;
12013 + }
12014 + })
12015 +
12016 +
12017 +(define_insn_and_split "*movti_internal"
12018 + [(set (match_operand:TI 0 "avr32_movti_dst_operand" "=r,&r, r, <RKu00,r,r")
12019 + (match_operand:TI 1 "avr32_movti_src_operand" " r,RKu00>,RKu00,r, n,T"))]
12020 + "(register_operand (operands[0], TImode)
12021 + || register_operand (operands[1], TImode))"
12022 + {
12023 + switch (which_alternative ){
12024 + case 0:
12025 + case 2:
12026 + case 4:
12027 + return "#";
12028 + case 1:
12029 + return "ldm\t%p1, %0";
12030 + case 3:
12031 + return "stm\t%p0, %1";
12032 + case 5:
12033 + return "ld.d\t%U0, pc[%1 - .]\;ld.d\t%B0, pc[%1 - . + 8]";
12034 + }
12035 + }
12036 +
12037 + "reload_completed &&
12038 + (REG_P (operands[0]) &&
12039 + (REG_P (operands[1])
12040 + /* If this is a load from the constant pool we split it into
12041 + two double loads. */
12042 + || (GET_CODE (operands[1]) == MEM
12043 + && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
12044 + && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
12045 + /* If this is a load where the pointer register is a part
12046 + of the register list, we must split it into two double
12047 + loads in order for it to be exception safe. */
12048 + || (GET_CODE (operands[1]) == MEM
12049 + && register_operand (XEXP (operands[1], 0), SImode)
12050 + && reg_overlap_mentioned_p (operands[0], XEXP (operands[1], 0)))
12051 + || GET_CODE (operands[1]) == CONST_INT
12052 + || GET_CODE (operands[1]) == CONST_DOUBLE))"
12053 + [(set (match_dup 0) (match_dup 1))
12054 + (set (match_dup 2) (match_dup 3))]
12055 + {
12056 + operands[2] = simplify_gen_subreg ( DImode, operands[0],
12057 + TImode, 0 );
12058 + operands[0] = simplify_gen_subreg ( DImode, operands[0],
12059 + TImode, 8 );
12060 + if ( REG_P(operands[1]) ){
12061 + operands[3] = simplify_gen_subreg ( DImode, operands[1],
12062 + TImode, 0 );
12063 + operands[1] = simplify_gen_subreg ( DImode, operands[1],
12064 + TImode, 8 );
12065 + } else if ( GET_CODE(operands[1]) == CONST_DOUBLE
12066 + || GET_CODE(operands[1]) == CONST_INT ){
12067 + rtx split_const[2];
12068 + avr32_split_const_expr (TImode, DImode, operands[1], split_const);
12069 + operands[3] = split_const[1];
12070 + operands[1] = split_const[0];
12071 + } else if (avr32_const_pool_ref_operand (operands[1], GET_MODE(operands[1]))){
12072 + rtx split_const[2];
12073 + rtx cop = avoid_constant_pool_reference (operands[1]);
12074 + if (operands[1] == cop)
12075 + cop = get_pool_constant (XEXP (operands[1], 0));
12076 + avr32_split_const_expr (TImode, DImode, cop, split_const);
12077 + operands[3] = force_const_mem (DImode, split_const[1]);
12078 + operands[1] = force_const_mem (DImode, split_const[0]);
12079 + } else {
12080 + rtx ptr_reg = XEXP (operands[1], 0);
12081 + operands[1] = gen_rtx_MEM (DImode,
12082 + gen_rtx_PLUS ( SImode,
12083 + ptr_reg,
12084 + GEN_INT (8) ));
12085 + operands[3] = gen_rtx_MEM (DImode,
12086 + ptr_reg);
12087 +
12088 + /* Check if the first load will clobber the pointer.
12089 + If so, we must switch the order of the operations. */
12090 + if ( reg_overlap_mentioned_p (operands[0], ptr_reg) )
12091 + {
12092 + /* We need to switch the order of the operations
12093 + so that the pointer register does not get clobbered
12094 + after the first double word load. */
12095 + rtx tmp;
12096 + tmp = operands[0];
12097 + operands[0] = operands[2];
12098 + operands[2] = tmp;
12099 + tmp = operands[1];
12100 + operands[1] = operands[3];
12101 + operands[3] = tmp;
12102 + }
12103 +
12104 +
12105 + }
12106 + }
12107 + [(set_attr "length" "*,*,4,4,*,8")
12108 + (set_attr "type" "*,*,load4,store4,*,load4")])
12109 +
12110 +
12111 +;;== float - 32 bits ==========================================================
12112 +(define_expand "movsf"
12113 + [(set (match_operand:SF 0 "nonimmediate_operand" "")
12114 + (match_operand:SF 1 "general_operand" ""))]
12115 + ""
12116 + {
12117 +
12118 +
12119 + /* One of the ops has to be in a register. */
12120 + if (GET_CODE (operands[0]) != REG)
12121 + operands[1] = force_reg (SFmode, operands[1]);
12122 +
12123 + })
12124 +
12125 +(define_insn "*movsf_internal"
12126 + [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,r,r,m")
12127 + (match_operand:SF 1 "general_operand" "r, G,F,m,r"))]
12128 + "(register_operand (operands[0], SFmode)
12129 + || register_operand (operands[1], SFmode))"
12130 + {
12131 + switch (which_alternative) {
12132 + case 0:
12133 + case 1: return "mov\t%0, %1";
12134 + case 2:
12135 + {
12136 + HOST_WIDE_INT target_float[2];
12137 + real_to_target (target_float, CONST_DOUBLE_REAL_VALUE (operands[1]), SFmode);
12138 + if ( TARGET_V2_INSNS
12139 + && avr32_hi16_immediate_operand (GEN_INT (target_float[0]), VOIDmode) )
12140 + return "movh\t%0, hi(%1)";
12141 + else
12142 + return "mov\t%0, lo(%1)\;orh\t%0, hi(%1)";
12143 + }
12144 + case 3:
12145 + if ( (REG_P(XEXP(operands[1], 0))
12146 + && REGNO(XEXP(operands[1], 0)) == SP_REGNUM)
12147 + || (GET_CODE(XEXP(operands[1], 0)) == PLUS
12148 + && REGNO(XEXP(XEXP(operands[1], 0), 0)) == SP_REGNUM
12149 + && GET_CODE(XEXP(XEXP(operands[1], 0), 1)) == CONST_INT
12150 + && INTVAL(XEXP(XEXP(operands[1], 0), 1)) % 4 == 0
12151 + && INTVAL(XEXP(XEXP(operands[1], 0), 1)) <= 0x1FC) )
12152 + return "lddsp\t%0, %1";
12153 + else if ( avr32_const_pool_ref_operand(operands[1], GET_MODE(operands[1])) )
12154 + return "lddpc\t%0, %1";
12155 + else
12156 + return "ld.w\t%0, %1";
12157 + case 4:
12158 + if ( (REG_P(XEXP(operands[0], 0))
12159 + && REGNO(XEXP(operands[0], 0)) == SP_REGNUM)
12160 + || (GET_CODE(XEXP(operands[0], 0)) == PLUS
12161 + && REGNO(XEXP(XEXP(operands[0], 0), 0)) == SP_REGNUM
12162 + && GET_CODE(XEXP(XEXP(operands[0], 0), 1)) == CONST_INT
12163 + && INTVAL(XEXP(XEXP(operands[0], 0), 1)) % 4 == 0
12164 + && INTVAL(XEXP(XEXP(operands[0], 0), 1)) <= 0x1FC) )
12165 + return "stdsp\t%0, %1";
12166 + else
12167 + return "st.w\t%0, %1";
12168 + default:
12169 + abort();
12170 + }
12171 + }
12172 +
12173 + [(set_attr "length" "2,4,8,4,4")
12174 + (set_attr "type" "alu,alu,alu2,load,store")
12175 + (set_attr "cc" "none,none,clobber,none,none")])
12176 +
12177 +
12178 +
12179 +;;== double - 64 bits =========================================================
12180 +(define_expand "movdf"
12181 + [(set (match_operand:DF 0 "nonimmediate_operand" "")
12182 + (match_operand:DF 1 "general_operand" ""))]
12183 + ""
12184 + {
12185 + /* One of the ops has to be in a register. */
12186 + if (GET_CODE (operands[0]) != REG){
12187 + operands[1] = force_reg (DFmode, operands[1]);
12188 + }
12189 + })
12190 +
12191 +
12192 +(define_insn_and_split "*movdf_internal"
12193 + [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,r,r,m")
12194 + (match_operand:DF 1 "general_operand" " r,G,F,m,r"))]
12195 + "TARGET_SOFT_FLOAT
12196 + && (register_operand (operands[0], DFmode)
12197 + || register_operand (operands[1], DFmode))"
12198 + {
12199 + switch (which_alternative ){
12200 + case 0:
12201 + case 1:
12202 + case 2:
12203 + return "#";
12204 + case 3:
12205 + if ( avr32_const_pool_ref_operand(operands[1], GET_MODE(operands[1])))
12206 + return "ld.d\t%0, pc[%1 - .]";
12207 + else
12208 + return "ld.d\t%0, %1";
12209 + case 4:
12210 + return "st.d\t%0, %1";
12211 + default:
12212 + abort();
12213 + }
12214 + }
12215 + "TARGET_SOFT_FLOAT
12216 + && reload_completed
12217 + && (REG_P (operands[0])
12218 + && (REG_P (operands[1])
12219 + || GET_CODE (operands[1]) == CONST_DOUBLE))"
12220 + [(set (match_dup 0) (match_dup 1))
12221 + (set (match_dup 2) (match_dup 3))]
12222 + "
12223 + {
12224 + operands[2] = gen_highpart (SImode, operands[0]);
12225 + operands[0] = gen_lowpart (SImode, operands[0]);
12226 + operands[3] = gen_highpart(SImode, operands[1]);
12227 + operands[1] = gen_lowpart(SImode, operands[1]);
12228 + }
12229 + "
12230 +
12231 + [(set_attr "length" "*,*,*,4,4")
12232 + (set_attr "type" "*,*,*,load2,store2")
12233 + (set_attr "cc" "*,*,*,none,none")])
12234 +
12235 +
12236 +;;=============================================================================
12237 +;; Conditional Moves
12238 +;;=============================================================================
12239 +(define_insn "ld<mode>_predicable"
12240 + [(set (match_operand:MOVCC 0 "register_operand" "=r")
12241 + (match_operand:MOVCC 1 "memory_operand" "<MOVCC:pred_mem_constraint>"))]
12242 + "TARGET_V2_INSNS"
12243 + "ld<MOVCC:load_postfix>%?\t%0, %1"
12244 + [(set_attr "length" "4")
12245 + (set_attr "cc" "cmp_cond_insn")
12246 + (set_attr "type" "load")
12247 + (set_attr "predicable" "yes")]
12248 +)
12249 +
12250 +
12251 +(define_insn "st<mode>_predicable"
12252 + [(set (match_operand:MOVCC 0 "memory_operand" "=<MOVCC:pred_mem_constraint>")
12253 + (match_operand:MOVCC 1 "register_operand" "r"))]
12254 + "TARGET_V2_INSNS"
12255 + "st<MOVCC:store_postfix>%?\t%0, %1"
12256 + [(set_attr "length" "4")
12257 + (set_attr "cc" "cmp_cond_insn")
12258 + (set_attr "type" "store")
12259 + (set_attr "predicable" "yes")]
12260 +)
12261 +
12262 +(define_insn "mov<mode>_predicable"
12263 + [(set (match_operand:MOVCC 0 "register_operand" "=r")
12264 + (match_operand:MOVCC 1 "avr32_cond_register_immediate_operand" "rKs08"))]
12265 + ""
12266 + "mov%?\t%0, %1"
12267 + [(set_attr "length" "4")
12268 + (set_attr "cc" "cmp_cond_insn")
12269 + (set_attr "type" "alu")
12270 + (set_attr "predicable" "yes")]
12271 +)
12272 +
12273 +
12274 +;;=============================================================================
12275 +;; Move chunks of memory
12276 +;;=============================================================================
12277 +
12278 +(define_expand "movmemsi"
12279 + [(match_operand:BLK 0 "general_operand" "")
12280 + (match_operand:BLK 1 "general_operand" "")
12281 + (match_operand:SI 2 "const_int_operand" "")
12282 + (match_operand:SI 3 "const_int_operand" "")]
12283 + ""
12284 + "
12285 + if (avr32_gen_movmemsi (operands))
12286 + DONE;
12287 + FAIL;
12288 + "
12289 + )
12290 +
12291 +
12292 +
12293 +
12294 +;;=============================================================================
12295 +;; Bit field instructions
12296 +;;-----------------------------------------------------------------------------
12297 +;; Instructions to insert or extract bit-fields
12298 +;;=============================================================================
12299 +
12300 +(define_insn "insv"
12301 + [ (set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
12302 + (match_operand:SI 1 "immediate_operand" "Ku05")
12303 + (match_operand:SI 2 "immediate_operand" "Ku05"))
12304 + (match_operand 3 "register_operand" "r"))]
12305 + ""
12306 + "bfins\t%0, %3, %2, %1"
12307 + [(set_attr "type" "alu")
12308 + (set_attr "length" "4")
12309 + (set_attr "cc" "set_ncz")])
12310 +
12311 +
12312 +
12313 +(define_expand "extv"
12314 + [ (set (match_operand:SI 0 "register_operand" "")
12315 + (sign_extract:SI (match_operand:SI 1 "register_operand" "")
12316 + (match_operand:SI 2 "immediate_operand" "")
12317 + (match_operand:SI 3 "immediate_operand" "")))]
12318 + ""
12319 + {
12320 + if ( INTVAL(operands[2]) >= 32 )
12321 + FAIL;
12322 + }
12323 +)
12324 +
12325 +(define_expand "extzv"
12326 + [ (set (match_operand:SI 0 "register_operand" "")
12327 + (zero_extract:SI (match_operand:SI 1 "register_operand" "")
12328 + (match_operand:SI 2 "immediate_operand" "")
12329 + (match_operand:SI 3 "immediate_operand" "")))]
12330 + ""
12331 + {
12332 + if ( INTVAL(operands[2]) >= 32 )
12333 + FAIL;
12334 + }
12335 +)
12336 +
12337 +(define_insn "extv_internal"
12338 + [ (set (match_operand:SI 0 "register_operand" "=r")
12339 + (sign_extract:SI (match_operand:SI 1 "register_operand" "r")
12340 + (match_operand:SI 2 "immediate_operand" "Ku05")
12341 + (match_operand:SI 3 "immediate_operand" "Ku05")))]
12342 + "INTVAL(operands[2]) < 32"
12343 + "bfexts\t%0, %1, %3, %2"
12344 + [(set_attr "type" "alu")
12345 + (set_attr "length" "4")
12346 + (set_attr "cc" "set_ncz")])
12347 +
12348 +
12349 +(define_insn "extzv_internal"
12350 + [ (set (match_operand:SI 0 "register_operand" "=r")
12351 + (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
12352 + (match_operand:SI 2 "immediate_operand" "Ku05")
12353 + (match_operand:SI 3 "immediate_operand" "Ku05")))]
12354 + "INTVAL(operands[2]) < 32"
12355 + "bfextu\t%0, %1, %3, %2"
12356 + [(set_attr "type" "alu")
12357 + (set_attr "length" "4")
12358 + (set_attr "cc" "set_ncz")])
12359 +
12360 +
12361 +
12362 +;;=============================================================================
12363 +;; Some peepholes for avoiding unnecessary cast instructions
12364 +;; followed by bfins.
12365 +;;-----------------------------------------------------------------------------
12366 +
12367 +(define_peephole2
12368 + [(set (match_operand:SI 0 "register_operand" "")
12369 + (zero_extend:SI (match_operand:QI 1 "register_operand" "")))
12370 + (set (zero_extract:SI (match_operand 2 "register_operand" "")
12371 + (match_operand:SI 3 "immediate_operand" "")
12372 + (match_operand:SI 4 "immediate_operand" ""))
12373 + (match_dup 0))]
12374 + "((peep2_reg_dead_p(2, operands[0]) &&
12375 + (INTVAL(operands[3]) <= 8)))"
12376 + [(set (zero_extract:SI (match_dup 2)
12377 + (match_dup 3)
12378 + (match_dup 4))
12379 + (match_dup 1))]
12380 + )
12381 +
12382 +(define_peephole2
12383 + [(set (match_operand:SI 0 "register_operand" "")
12384 + (zero_extend:SI (match_operand:HI 1 "register_operand" "")))
12385 + (set (zero_extract:SI (match_operand 2 "register_operand" "")
12386 + (match_operand:SI 3 "immediate_operand" "")
12387 + (match_operand:SI 4 "immediate_operand" ""))
12388 + (match_dup 0))]
12389 + "((peep2_reg_dead_p(2, operands[0]) &&
12390 + (INTVAL(operands[3]) <= 16)))"
12391 + [(set (zero_extract:SI (match_dup 2)
12392 + (match_dup 3)
12393 + (match_dup 4))
12394 + (match_dup 1))]
12395 + )
12396 +
12397 +;;=============================================================================
12398 +;; push bytes
12399 +;;-----------------------------------------------------------------------------
12400 +;; Implements the push instruction
12401 +;;=============================================================================
12402 +(define_insn "pushm"
12403 + [(set (mem:BLK (pre_dec:BLK (reg:SI SP_REGNUM)))
12404 + (unspec:BLK [(match_operand 0 "const_int_operand" "")]
12405 + UNSPEC_PUSHM))]
12406 + ""
12407 + {
12408 + if (INTVAL(operands[0])) {
12409 + return "pushm\t%r0";
12410 + } else {
12411 + return "";
12412 + }
12413 + }
12414 + [(set_attr "type" "store")
12415 + (set_attr "length" "2")
12416 + (set_attr "cc" "none")])
12417 +
12418 +(define_insn "stm"
12419 + [(unspec [(match_operand 0 "register_operand" "r")
12420 + (match_operand 1 "const_int_operand" "")
12421 + (match_operand 2 "const_int_operand" "")]
12422 + UNSPEC_STM)]
12423 + ""
12424 + {
12425 + if (INTVAL(operands[1])) {
12426 + if (INTVAL(operands[2]) != 0)
12427 + return "stm\t--%0, %s1";
12428 + else
12429 + return "stm\t%0, %s1";
12430 + } else {
12431 + return "";
12432 + }
12433 + }
12434 + [(set_attr "type" "store")
12435 + (set_attr "length" "4")
12436 + (set_attr "cc" "none")])
12437 +
12438 +
12439 +
12440 +(define_insn "popm"
12441 + [(unspec [(match_operand 0 "const_int_operand" "")]
12442 + UNSPEC_POPM)]
12443 + ""
12444 + {
12445 + if (INTVAL(operands[0])) {
12446 + return "popm %r0";
12447 + } else {
12448 + return "";
12449 + }
12450 + }
12451 + [(set_attr "type" "load")
12452 + (set_attr "length" "2")])
12453 +
12454 +
12455 +
12456 +;;=============================================================================
12457 +;; add
12458 +;;-----------------------------------------------------------------------------
12459 +;; Adds reg1 with reg2 and puts the result in reg0.
12460 +;;=============================================================================
12461 +(define_insn "add<mode>3"
12462 + [(set (match_operand:INTM 0 "register_operand" "=r,r,r,r,r")
12463 + (plus:INTM (match_operand:INTM 1 "register_operand" "%0,r,0,r,0")
12464 + (match_operand:INTM 2 "avr32_add_operand" "r,r,Is08,Is16,Is21")))]
12465 + ""
12466 + "@
12467 + add %0, %2
12468 + add %0, %1, %2
12469 + sub %0, %n2
12470 + sub %0, %1, %n2
12471 + sub %0, %n2"
12472 +
12473 + [(set_attr "length" "2,4,2,4,4")
12474 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12475 +
12476 +(define_insn "add<mode>3_lsl"
12477 + [(set (match_operand:INTM 0 "register_operand" "=r")
12478 + (plus:INTM (ashift:INTM (match_operand:INTM 1 "register_operand" "r")
12479 + (match_operand:INTM 3 "avr32_add_shift_immediate_operand" "Ku02"))
12480 + (match_operand:INTM 2 "register_operand" "r")))]
12481 + ""
12482 + "add %0, %2, %1 << %3"
12483 + [(set_attr "length" "4")
12484 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12485 +
12486 +(define_insn "add<mode>3_lsl2"
12487 + [(set (match_operand:INTM 0 "register_operand" "=r")
12488 + (plus:INTM (match_operand:INTM 1 "register_operand" "r")
12489 + (ashift:INTM (match_operand:INTM 2 "register_operand" "r")
12490 + (match_operand:INTM 3 "avr32_add_shift_immediate_operand" "Ku02"))))]
12491 + ""
12492 + "add %0, %1, %2 << %3"
12493 + [(set_attr "length" "4")
12494 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12495 +
12496 +
12497 +(define_insn "add<mode>3_mul"
12498 + [(set (match_operand:INTM 0 "register_operand" "=r")
12499 + (plus:INTM (mult:INTM (match_operand:INTM 1 "register_operand" "r")
12500 + (match_operand:INTM 3 "immediate_operand" "Ku04" ))
12501 + (match_operand:INTM 2 "register_operand" "r")))]
12502 + "(INTVAL(operands[3]) == 0) || (INTVAL(operands[3]) == 2) ||
12503 + (INTVAL(operands[3]) == 4) || (INTVAL(operands[3]) == 8)"
12504 + "add %0, %2, %1 << %p3"
12505 + [(set_attr "length" "4")
12506 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12507 +
12508 +(define_insn "add<mode>3_mul2"
12509 + [(set (match_operand:INTM 0 "register_operand" "=r")
12510 + (plus:INTM (match_operand:INTM 1 "register_operand" "r")
12511 + (mult:INTM (match_operand:INTM 2 "register_operand" "r")
12512 + (match_operand:INTM 3 "immediate_operand" "Ku04" ))))]
12513 + "(INTVAL(operands[3]) == 0) || (INTVAL(operands[3]) == 2) ||
12514 + (INTVAL(operands[3]) == 4) || (INTVAL(operands[3]) == 8)"
12515 + "add %0, %1, %2 << %p3"
12516 + [(set_attr "length" "4")
12517 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12518 +
12519 +
12520 +(define_peephole2
12521 + [(set (match_operand:SI 0 "register_operand" "")
12522 + (ashift:SI (match_operand:SI 1 "register_operand" "")
12523 + (match_operand:SI 2 "immediate_operand" "")))
12524 + (set (match_operand:SI 3 "register_operand" "")
12525 + (plus:SI (match_dup 0)
12526 + (match_operand:SI 4 "register_operand" "")))]
12527 + "(peep2_reg_dead_p(2, operands[0]) &&
12528 + (INTVAL(operands[2]) < 4 && INTVAL(operands[2]) > 0))"
12529 + [(set (match_dup 3)
12530 + (plus:SI (ashift:SI (match_dup 1)
12531 + (match_dup 2))
12532 + (match_dup 4)))]
12533 + )
12534 +
12535 +(define_peephole2
12536 + [(set (match_operand:SI 0 "register_operand" "")
12537 + (ashift:SI (match_operand:SI 1 "register_operand" "")
12538 + (match_operand:SI 2 "immediate_operand" "")))
12539 + (set (match_operand:SI 3 "register_operand" "")
12540 + (plus:SI (match_operand:SI 4 "register_operand" "")
12541 + (match_dup 0)))]
12542 + "(peep2_reg_dead_p(2, operands[0]) &&
12543 + (INTVAL(operands[2]) < 4 && INTVAL(operands[2]) > 0))"
12544 + [(set (match_dup 3)
12545 + (plus:SI (ashift:SI (match_dup 1)
12546 + (match_dup 2))
12547 + (match_dup 4)))]
12548 + )
12549 +
12550 +(define_insn "adddi3"
12551 + [(set (match_operand:DI 0 "register_operand" "=r,r")
12552 + (plus:DI (match_operand:DI 1 "register_operand" "%r,0")
12553 + (match_operand:DI 2 "register_operand" "r,r")))]
12554 + ""
12555 + "@
12556 + add %0, %1, %2\;adc %m0, %m1, %m2
12557 + add %0, %2\;adc %m0, %m0, %m2"
12558 + [(set_attr "length" "8,6")
12559 + (set_attr "type" "alu2")
12560 + (set_attr "cc" "set_vncz")])
12561 +
12562 +
12563 +(define_insn "add<mode>_imm_predicable"
12564 + [(set (match_operand:INTM 0 "register_operand" "+r")
12565 + (plus:INTM (match_dup 0)
12566 + (match_operand:INTM 1 "avr32_cond_immediate_operand" "%Is08")))]
12567 + ""
12568 + "sub%?\t%0, -%1"
12569 + [(set_attr "length" "4")
12570 + (set_attr "cc" "cmp_cond_insn")
12571 + (set_attr "predicable" "yes")]
12572 +)
12573 +
12574 +;;=============================================================================
12575 +;; subtract
12576 +;;-----------------------------------------------------------------------------
12577 +;; Subtract reg2 or immediate value from reg0 and puts the result in reg0.
12578 +;;=============================================================================
12579 +
12580 +(define_insn "sub<mode>3"
12581 + [(set (match_operand:INTM 0 "general_operand" "=r,r,r,r,r,r,r")
12582 + (minus:INTM (match_operand:INTM 1 "register_const_int_operand" "0,r,0,r,0,r,Ks08")
12583 + (match_operand:INTM 2 "register_const_int_operand" "r,r,Ks08,Ks16,Ks21,0,r")))]
12584 + ""
12585 + "@
12586 + sub %0, %2
12587 + sub %0, %1, %2
12588 + sub %0, %2
12589 + sub %0, %1, %2
12590 + sub %0, %2
12591 + rsub %0, %1
12592 + rsub %0, %2, %1"
12593 + [(set_attr "length" "2,4,2,4,4,2,4")
12594 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12595 +
12596 +(define_insn "*sub<mode>3_mul"
12597 + [(set (match_operand:INTM 0 "register_operand" "=r,r,r")
12598 + (minus:INTM (match_operand:INTM 1 "register_operand" "r,0,r")
12599 + (mult:INTM (match_operand:INTM 2 "register_operand" "r,r,0")
12600 + (match_operand:SI 3 "immediate_operand" "Ku04,Ku04,Ku04" ))))]
12601 + "(INTVAL(operands[3]) == 0) || (INTVAL(operands[3]) == 2) ||
12602 + (INTVAL(operands[3]) == 4) || (INTVAL(operands[3]) == 8)"
12603 + "@
12604 + sub %0, %1, %2 << %p3
12605 + sub %0, %0, %2 << %p3
12606 + sub %0, %1, %0 << %p3"
12607 + [(set_attr "length" "4,4,4")
12608 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12609 +
12610 +(define_insn "*sub<mode>3_lsl"
12611 + [(set (match_operand:INTM 0 "register_operand" "=r")
12612 + (minus:INTM (match_operand:INTM 1 "register_operand" "r")
12613 + (ashift:INTM (match_operand:INTM 2 "register_operand" "r")
12614 + (match_operand:SI 3 "avr32_add_shift_immediate_operand" "Ku02"))))]
12615 + ""
12616 + "sub %0, %1, %2 << %3"
12617 + [(set_attr "length" "4")
12618 + (set_attr "cc" "<INTM:alu_cc_attr>")])
12619 +
12620 +
12621 +(define_insn "subdi3"
12622 + [(set (match_operand:DI 0 "register_operand" "=r,r")
12623 + (minus:DI (match_operand:DI 1 "register_operand" "%r,0")
12624 + (match_operand:DI 2 "register_operand" "r,r")))]
12625 + ""
12626 + "@
12627 + sub %0, %1, %2\;sbc %m0, %m1, %m2
12628 + sub %0, %2\;sbc %m0, %m0, %m2"
12629 + [(set_attr "length" "8,6")
12630 + (set_attr "type" "alu2")
12631 + (set_attr "cc" "set_vncz")])
12632 +
12633 +
12634 +(define_insn "sub<mode>_imm_predicable"
12635 + [(set (match_operand:INTM 0 "register_operand" "+r")
12636 + (minus:INTM (match_dup 0)
12637 + (match_operand:INTM 1 "avr32_cond_immediate_operand" "Ks08")))]
12638 + ""
12639 + "sub%?\t%0, %1"
12640 + [(set_attr "length" "4")
12641 + (set_attr "cc" "cmp_cond_insn")
12642 + (set_attr "predicable" "yes")])
12643 +
12644 +(define_insn "rsub<mode>_imm_predicable"
12645 + [(set (match_operand:INTM 0 "register_operand" "+r")
12646 + (minus:INTM (match_operand:INTM 1 "avr32_cond_immediate_operand" "Ks08")
12647 + (match_dup 0)))]
12648 + ""
12649 + "rsub%?\t%0, %1"
12650 + [(set_attr "length" "4")
12651 + (set_attr "cc" "cmp_cond_insn")
12652 + (set_attr "predicable" "yes")])
12653 +
12654 +;;=============================================================================
12655 +;; multiply
12656 +;;-----------------------------------------------------------------------------
12657 +;; Multiply op1 and op2 and put the value in op0.
12658 +;;=============================================================================
12659 +
12660 +
12661 +(define_insn "mulqi3"
12662 + [(set (match_operand:QI 0 "register_operand" "=r,r,r")
12663 + (mult:QI (match_operand:QI 1 "register_operand" "%0,r,r")
12664 + (match_operand:QI 2 "avr32_mul_operand" "r,r,Ks08")))]
12665 + "!TARGET_NO_MUL_INSNS"
12666 + {
12667 + switch (which_alternative){
12668 + case 0:
12669 + return "mul %0, %2";
12670 + case 1:
12671 + return "mul %0, %1, %2";
12672 + case 2:
12673 + return "mul %0, %1, %2";
12674 + default:
12675 + gcc_unreachable();
12676 + }
12677 + }
12678 + [(set_attr "type" "mulww_w,mulww_w,mulwh")
12679 + (set_attr "length" "2,4,4")
12680 + (set_attr "cc" "none")])
12681 +
12682 +(define_insn "mulsi3"
12683 + [(set (match_operand:SI 0 "register_operand" "=r,r,r")
12684 + (mult:SI (match_operand:SI 1 "register_operand" "%0,r,r")
12685 + (match_operand:SI 2 "avr32_mul_operand" "r,r,Ks08")))]
12686 + "!TARGET_NO_MUL_INSNS"
12687 + {
12688 + switch (which_alternative){
12689 + case 0:
12690 + return "mul %0, %2";
12691 + case 1:
12692 + return "mul %0, %1, %2";
12693 + case 2:
12694 + return "mul %0, %1, %2";
12695 + default:
12696 + gcc_unreachable();
12697 + }
12698 + }
12699 + [(set_attr "type" "mulww_w,mulww_w,mulwh")
12700 + (set_attr "length" "2,4,4")
12701 + (set_attr "cc" "none")])
12702 +
12703 +
12704 +(define_insn "mulhisi3"
12705 + [(set (match_operand:SI 0 "register_operand" "=r")
12706 + (mult:SI
12707 + (sign_extend:SI (match_operand:HI 1 "register_operand" "%r"))
12708 + (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
12709 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12710 + "mulhh.w %0, %1:b, %2:b"
12711 + [(set_attr "type" "mulhh")
12712 + (set_attr "length" "4")
12713 + (set_attr "cc" "none")])
12714 +
12715 +(define_peephole2
12716 + [(match_scratch:DI 6 "r")
12717 + (set (match_operand:SI 0 "register_operand" "")
12718 + (mult:SI
12719 + (sign_extend:SI (match_operand:HI 1 "register_operand" ""))
12720 + (sign_extend:SI (match_operand:HI 2 "register_operand" ""))))
12721 + (set (match_operand:SI 3 "register_operand" "")
12722 + (ashiftrt:SI (match_dup 0)
12723 + (const_int 16)))]
12724 + "!TARGET_NO_MUL_INSNS && TARGET_DSP
12725 + && (peep2_reg_dead_p(1, operands[0]) || (REGNO(operands[0]) == REGNO(operands[3])))"
12726 + [(set (match_dup 4) (sign_extend:SI (match_dup 1)))
12727 + (set (match_dup 6)
12728 + (ashift:DI (mult:DI (sign_extend:DI (match_dup 4))
12729 + (sign_extend:DI (match_dup 2)))
12730 + (const_int 16)))
12731 + (set (match_dup 3) (match_dup 5))]
12732 +
12733 + "{
12734 + operands[4] = gen_rtx_REG(SImode, REGNO(operands[1]));
12735 + operands[5] = gen_highpart (SImode, operands[4]);
12736 + }"
12737 + )
12738 +
12739 +(define_insn "mulnhisi3"
12740 + [(set (match_operand:SI 0 "register_operand" "=r")
12741 + (mult:SI
12742 + (sign_extend:SI (neg:HI (match_operand:HI 1 "register_operand" "r")))
12743 + (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
12744 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12745 + "mulnhh.w %0, %1:b, %2:b"
12746 + [(set_attr "type" "mulhh")
12747 + (set_attr "length" "4")
12748 + (set_attr "cc" "none")])
12749 +
12750 +(define_insn "machisi3"
12751 + [(set (match_operand:SI 0 "register_operand" "+r")
12752 + (plus:SI (mult:SI
12753 + (sign_extend:SI (match_operand:HI 1 "register_operand" "%r"))
12754 + (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))
12755 + (match_dup 0)))]
12756 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12757 + "machh.w %0, %1:b, %2:b"
12758 + [(set_attr "type" "machh_w")
12759 + (set_attr "length" "4")
12760 + (set_attr "cc" "none")])
12761 +
12762 +
12763 +
12764 +(define_insn "mulsidi3"
12765 + [(set (match_operand:DI 0 "register_operand" "=r")
12766 + (mult:DI
12767 + (sign_extend:DI (match_operand:SI 1 "register_operand" "%r"))
12768 + (sign_extend:DI (match_operand:SI 2 "register_operand" "r"))))]
12769 + "!TARGET_NO_MUL_INSNS"
12770 + "muls.d %0, %1, %2"
12771 + [(set_attr "type" "mulww_d")
12772 + (set_attr "length" "4")
12773 + (set_attr "cc" "none")])
12774 +
12775 +(define_insn "umulsidi3"
12776 + [(set (match_operand:DI 0 "register_operand" "=r")
12777 + (mult:DI
12778 + (zero_extend:DI (match_operand:SI 1 "register_operand" "%r"))
12779 + (zero_extend:DI (match_operand:SI 2 "register_operand" "r"))))]
12780 + "!TARGET_NO_MUL_INSNS"
12781 + "mulu.d %0, %1, %2"
12782 + [(set_attr "type" "mulww_d")
12783 + (set_attr "length" "4")
12784 + (set_attr "cc" "none")])
12785 +
12786 +(define_insn "*mulaccsi3"
12787 + [(set (match_operand:SI 0 "register_operand" "+r")
12788 + (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "%r")
12789 + (match_operand:SI 2 "register_operand" "r"))
12790 + (match_dup 0)))]
12791 + "!TARGET_NO_MUL_INSNS"
12792 + "mac %0, %1, %2"
12793 + [(set_attr "type" "macww_w")
12794 + (set_attr "length" "4")
12795 + (set_attr "cc" "none")])
12796 +
12797 +(define_insn "mulaccsidi3"
12798 + [(set (match_operand:DI 0 "register_operand" "+r")
12799 + (plus:DI (mult:DI
12800 + (sign_extend:DI (match_operand:SI 1 "register_operand" "%r"))
12801 + (sign_extend:DI (match_operand:SI 2 "register_operand" "r")))
12802 + (match_dup 0)))]
12803 + "!TARGET_NO_MUL_INSNS"
12804 + "macs.d %0, %1, %2"
12805 + [(set_attr "type" "macww_d")
12806 + (set_attr "length" "4")
12807 + (set_attr "cc" "none")])
12808 +
12809 +(define_insn "umulaccsidi3"
12810 + [(set (match_operand:DI 0 "register_operand" "+r")
12811 + (plus:DI (mult:DI
12812 + (zero_extend:DI (match_operand:SI 1 "register_operand" "%r"))
12813 + (zero_extend:DI (match_operand:SI 2 "register_operand" "r")))
12814 + (match_dup 0)))]
12815 + "!TARGET_NO_MUL_INSNS"
12816 + "macu.d %0, %1, %2"
12817 + [(set_attr "type" "macww_d")
12818 + (set_attr "length" "4")
12819 + (set_attr "cc" "none")])
12820 +
12821 +
12822 +
12823 +;; Try to avoid Write-After-Write hazards for mul operations
12824 +;; if it can be done
12825 +(define_peephole2
12826 + [(set (match_operand:SI 0 "register_operand" "")
12827 + (mult:SI
12828 + (sign_extend:SI (match_operand 1 "general_operand" ""))
12829 + (sign_extend:SI (match_operand 2 "general_operand" ""))))
12830 + (set (match_dup 0)
12831 + (match_operator:SI 3 "alu_operator" [(match_dup 0)
12832 + (match_operand 4 "general_operand" "")]))]
12833 + "peep2_reg_dead_p(1, operands[2])"
12834 + [(set (match_dup 5)
12835 + (mult:SI
12836 + (sign_extend:SI (match_dup 1))
12837 + (sign_extend:SI (match_dup 2))))
12838 + (set (match_dup 0)
12839 + (match_op_dup 3 [(match_dup 5)
12840 + (match_dup 4)]))]
12841 + "{operands[5] = gen_rtx_REG(SImode, REGNO(operands[2]));}"
12842 + )
12843 +
12844 +
12845 +
12846 +;;=============================================================================
12847 +;; DSP instructions
12848 +;;=============================================================================
12849 +(define_insn "mulsathh_h"
12850 + [(set (match_operand:HI 0 "register_operand" "=r")
12851 + (ss_truncate:HI (ashiftrt:SI (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%r"))
12852 + (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))
12853 + (const_int 15))))]
12854 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12855 + "mulsathh.h\t%0, %1:b, %2:b"
12856 + [(set_attr "length" "4")
12857 + (set_attr "cc" "none")
12858 + (set_attr "type" "mulhh")])
12859 +
12860 +(define_insn "mulsatrndhh_h"
12861 + [(set (match_operand:HI 0 "register_operand" "=r")
12862 + (ss_truncate:HI (ashiftrt:SI
12863 + (plus:SI (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%r"))
12864 + (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))
12865 + (const_int 1073741824))
12866 + (const_int 15))))]
12867 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12868 + "mulsatrndhh.h\t%0, %1:b, %2:b"
12869 + [(set_attr "length" "4")
12870 + (set_attr "cc" "none")
12871 + (set_attr "type" "mulhh")])
12872 +
12873 +(define_insn "mulsathh_w"
12874 + [(set (match_operand:SI 0 "register_operand" "=r")
12875 + (ss_truncate:SI (ashift:DI (mult:DI (sign_extend:DI (match_operand:HI 1 "register_operand" "%r"))
12876 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
12877 + (const_int 1))))]
12878 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12879 + "mulsathh.w\t%0, %1:b, %2:b"
12880 + [(set_attr "length" "4")
12881 + (set_attr "cc" "none")
12882 + (set_attr "type" "mulhh")])
12883 +
12884 +(define_insn "mulsatwh_w"
12885 + [(set (match_operand:SI 0 "register_operand" "=r")
12886 + (ss_truncate:SI (ashiftrt:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r"))
12887 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
12888 + (const_int 15))))]
12889 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12890 + "mulsatwh.w\t%0, %1, %2:b"
12891 + [(set_attr "length" "4")
12892 + (set_attr "cc" "none")
12893 + (set_attr "type" "mulwh")])
12894 +
12895 +(define_insn "mulsatrndwh_w"
12896 + [(set (match_operand:SI 0 "register_operand" "=r")
12897 + (ss_truncate:SI (ashiftrt:DI (plus:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r"))
12898 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
12899 + (const_int 1073741824))
12900 + (const_int 15))))]
12901 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12902 + "mulsatrndwh.w\t%0, %1, %2:b"
12903 + [(set_attr "length" "4")
12904 + (set_attr "cc" "none")
12905 + (set_attr "type" "mulwh")])
12906 +
12907 +(define_insn "macsathh_w"
12908 + [(set (match_operand:SI 0 "register_operand" "+r")
12909 + (plus:SI (match_dup 0)
12910 + (ss_truncate:SI (ashift:DI (mult:DI (sign_extend:DI (match_operand:HI 1 "register_operand" "%r"))
12911 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
12912 + (const_int 1)))))]
12913 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12914 + "macsathh.w\t%0, %1:b, %2:b"
12915 + [(set_attr "length" "4")
12916 + (set_attr "cc" "none")
12917 + (set_attr "type" "mulhh")])
12918 +
12919 +
12920 +(define_insn "mulwh_d"
12921 + [(set (match_operand:DI 0 "register_operand" "=r")
12922 + (ashift:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r"))
12923 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
12924 + (const_int 16)))]
12925 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12926 + "mulwh.d\t%0, %1, %2:b"
12927 + [(set_attr "length" "4")
12928 + (set_attr "cc" "none")
12929 + (set_attr "type" "mulwh")])
12930 +
12931 +
12932 +(define_insn "mulnwh_d"
12933 + [(set (match_operand:DI 0 "register_operand" "=r")
12934 + (ashift:DI (mult:DI (not:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r")))
12935 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
12936 + (const_int 16)))]
12937 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12938 + "mulnwh.d\t%0, %1, %2:b"
12939 + [(set_attr "length" "4")
12940 + (set_attr "cc" "none")
12941 + (set_attr "type" "mulwh")])
12942 +
12943 +(define_insn "macwh_d"
12944 + [(set (match_operand:DI 0 "register_operand" "+r")
12945 + (plus:DI (match_dup 0)
12946 + (ashift:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "%r"))
12947 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))
12948 + (const_int 16))))]
12949 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12950 + "macwh.d\t%0, %1, %2:b"
12951 + [(set_attr "length" "4")
12952 + (set_attr "cc" "none")
12953 + (set_attr "type" "mulwh")])
12954 +
12955 +(define_insn "machh_d"
12956 + [(set (match_operand:DI 0 "register_operand" "+r")
12957 + (plus:DI (match_dup 0)
12958 + (mult:DI (sign_extend:DI (match_operand:HI 1 "register_operand" "%r"))
12959 + (sign_extend:DI (match_operand:HI 2 "register_operand" "r")))))]
12960 + "!TARGET_NO_MUL_INSNS && TARGET_DSP"
12961 + "machh.d\t%0, %1:b, %2:b"
12962 + [(set_attr "length" "4")
12963 + (set_attr "cc" "none")
12964 + (set_attr "type" "mulwh")])
12965 +
12966 +(define_insn "satadd_w"
12967 + [(set (match_operand:SI 0 "register_operand" "=r")
12968 + (ss_plus:SI (match_operand:SI 1 "register_operand" "r")
12969 + (match_operand:SI 2 "register_operand" "r")))]
12970 + "TARGET_DSP"
12971 + "satadd.w\t%0, %1, %2"
12972 + [(set_attr "length" "4")
12973 + (set_attr "cc" "none")
12974 + (set_attr "type" "alu_sat")])
12975 +
12976 +(define_insn "satsub_w"
12977 + [(set (match_operand:SI 0 "register_operand" "=r")
12978 + (ss_minus:SI (match_operand:SI 1 "register_operand" "r")
12979 + (match_operand:SI 2 "register_operand" "r")))]
12980 + "TARGET_DSP"
12981 + "satsub.w\t%0, %1, %2"
12982 + [(set_attr "length" "4")
12983 + (set_attr "cc" "none")
12984 + (set_attr "type" "alu_sat")])
12985 +
12986 +(define_insn "satadd_h"
12987 + [(set (match_operand:HI 0 "register_operand" "=r")
12988 + (ss_plus:HI (match_operand:HI 1 "register_operand" "r")
12989 + (match_operand:HI 2 "register_operand" "r")))]
12990 + "TARGET_DSP"
12991 + "satadd.h\t%0, %1, %2"
12992 + [(set_attr "length" "4")
12993 + (set_attr "cc" "none")
12994 + (set_attr "type" "alu_sat")])
12995 +
12996 +(define_insn "satsub_h"
12997 + [(set (match_operand:HI 0 "register_operand" "=r")
12998 + (ss_minus:HI (match_operand:HI 1 "register_operand" "r")
12999 + (match_operand:HI 2 "register_operand" "r")))]
13000 + "TARGET_DSP"
13001 + "satsub.h\t%0, %1, %2"
13002 + [(set_attr "length" "4")
13003 + (set_attr "cc" "none")
13004 + (set_attr "type" "alu_sat")])
13005 +
13006 +
13007 +;;=============================================================================
13008 +;; smin
13009 +;;-----------------------------------------------------------------------------
13010 +;; Set reg0 to the smallest value of reg1 and reg2. It is used for signed
13011 +;; values in the registers.
13012 +;;=============================================================================
13013 +(define_insn "sminsi3"
13014 + [(set (match_operand:SI 0 "register_operand" "=r")
13015 + (smin:SI (match_operand:SI 1 "register_operand" "r")
13016 + (match_operand:SI 2 "register_operand" "r")))]
13017 + ""
13018 + "min %0, %1, %2"
13019 + [(set_attr "length" "4")
13020 + (set_attr "cc" "none")])
13021 +
13022 +;;=============================================================================
13023 +;; smax
13024 +;;-----------------------------------------------------------------------------
13025 +;; Set reg0 to the largest value of reg1 and reg2. It is used for signed
13026 +;; values in the registers.
13027 +;;=============================================================================
13028 +(define_insn "smaxsi3"
13029 + [(set (match_operand:SI 0 "register_operand" "=r")
13030 + (smax:SI (match_operand:SI 1 "register_operand" "r")
13031 + (match_operand:SI 2 "register_operand" "r")))]
13032 + ""
13033 + "max %0, %1, %2"
13034 + [(set_attr "length" "4")
13035 + (set_attr "cc" "none")])
13036 +
13037 +
13038 +
13039 +;;=============================================================================
13040 +;; Logical operations
13041 +;;-----------------------------------------------------------------------------
13042 +
13043 +
13044 +;; Split up simple DImode logical operations. Simply perform the logical
13045 +;; operation on the upper and lower halves of the registers.
13046 +(define_split
13047 + [(set (match_operand:DI 0 "register_operand" "")
13048 + (match_operator:DI 6 "logical_binary_operator"
13049 + [(match_operand:DI 1 "register_operand" "")
13050 + (match_operand:DI 2 "register_operand" "")]))]
13051 + "reload_completed"
13052 + [(set (match_dup 0) (match_op_dup:SI 6 [(match_dup 1) (match_dup 2)]))
13053 + (set (match_dup 3) (match_op_dup:SI 6 [(match_dup 4) (match_dup 5)]))]
13054 + "
13055 + {
13056 + operands[3] = gen_highpart (SImode, operands[0]);
13057 + operands[0] = gen_lowpart (SImode, operands[0]);
13058 + operands[4] = gen_highpart (SImode, operands[1]);
13059 + operands[1] = gen_lowpart (SImode, operands[1]);
13060 + operands[5] = gen_highpart (SImode, operands[2]);
13061 + operands[2] = gen_lowpart (SImode, operands[2]);
13062 + }"
13063 +)
13064 +
13065 +;;=============================================================================
13066 +;; Logical operations with shifted operand
13067 +;;=============================================================================
13068 +(define_insn "<code>si_lshift"
13069 + [(set (match_operand:SI 0 "register_operand" "=r")
13070 + (logical:SI (match_operator:SI 4 "logical_shift_operator"
13071 + [(match_operand:SI 2 "register_operand" "r")
13072 + (match_operand:SI 3 "immediate_operand" "Ku05")])
13073 + (match_operand:SI 1 "register_operand" "r")))]
13074 + ""
13075 + {
13076 + if ( GET_CODE(operands[4]) == ASHIFT )
13077 + return "<logical_insn>\t%0, %1, %2 << %3";
13078 + else
13079 + return "<logical_insn>\t%0, %1, %2 >> %3";
13080 + }
13081 +
13082 + [(set_attr "cc" "set_z")]
13083 +)
13084 +
13085 +
13086 +;;************************************************
13087 +;; Peepholes for detecting logical operantions
13088 +;; with shifted operands
13089 +;;************************************************
13090 +
13091 +(define_peephole
13092 + [(set (match_operand:SI 3 "register_operand" "")
13093 + (match_operator:SI 5 "logical_shift_operator"
13094 + [(match_operand:SI 1 "register_operand" "")
13095 + (match_operand:SI 2 "immediate_operand" "")]))
13096 + (set (match_operand:SI 0 "register_operand" "")
13097 + (logical:SI (match_operand:SI 4 "register_operand" "")
13098 + (match_dup 3)))]
13099 + "(dead_or_set_p(insn, operands[3])) || (REGNO(operands[3]) == REGNO(operands[0]))"
13100 + {
13101 + if ( GET_CODE(operands[5]) == ASHIFT )
13102 + return "<logical_insn>\t%0, %4, %1 << %2";
13103 + else
13104 + return "<logical_insn>\t%0, %4, %1 >> %2";
13105 + }
13106 + [(set_attr "cc" "set_z")]
13107 + )
13108 +
13109 +(define_peephole
13110 + [(set (match_operand:SI 3 "register_operand" "")
13111 + (match_operator:SI 5 "logical_shift_operator"
13112 + [(match_operand:SI 1 "register_operand" "")
13113 + (match_operand:SI 2 "immediate_operand" "")]))
13114 + (set (match_operand:SI 0 "register_operand" "")
13115 + (logical:SI (match_dup 3)
13116 + (match_operand:SI 4 "register_operand" "")))]
13117 + "(dead_or_set_p(insn, operands[3])) || (REGNO(operands[3]) == REGNO(operands[0]))"
13118 + {
13119 + if ( GET_CODE(operands[5]) == ASHIFT )
13120 + return "<logical_insn>\t%0, %4, %1 << %2";
13121 + else
13122 + return "<logical_insn>\t%0, %4, %1 >> %2";
13123 + }
13124 + [(set_attr "cc" "set_z")]
13125 + )
13126 +
13127 +
13128 +(define_peephole2
13129 + [(set (match_operand:SI 0 "register_operand" "")
13130 + (match_operator:SI 5 "logical_shift_operator"
13131 + [(match_operand:SI 1 "register_operand" "")
13132 + (match_operand:SI 2 "immediate_operand" "")]))
13133 + (set (match_operand:SI 3 "register_operand" "")
13134 + (logical:SI (match_operand:SI 4 "register_operand" "")
13135 + (match_dup 0)))]
13136 + "(peep2_reg_dead_p(2, operands[0])) || (REGNO(operands[3]) == REGNO(operands[0]))"
13137 +
13138 + [(set (match_dup 3)
13139 + (logical:SI (match_op_dup:SI 5 [(match_dup 1) (match_dup 2)])
13140 + (match_dup 4)))]
13141 +
13142 + ""
13143 +)
13144 +
13145 +(define_peephole2
13146 + [(set (match_operand:SI 0 "register_operand" "")
13147 + (match_operator:SI 5 "logical_shift_operator"
13148 + [(match_operand:SI 1 "register_operand" "")
13149 + (match_operand:SI 2 "immediate_operand" "")]))
13150 + (set (match_operand:SI 3 "register_operand" "")
13151 + (logical:SI (match_dup 0)
13152 + (match_operand:SI 4 "register_operand" "")))]
13153 + "(peep2_reg_dead_p(2, operands[0])) || (REGNO(operands[3]) == REGNO(operands[0]))"
13154 +
13155 + [(set (match_dup 3)
13156 + (logical:SI (match_op_dup:SI 5 [(match_dup 1) (match_dup 2)])
13157 + (match_dup 4)))]
13158 +
13159 + ""
13160 +)
13161 +
13162 +
13163 +;;=============================================================================
13164 +;; and
13165 +;;-----------------------------------------------------------------------------
13166 +;; Store the result after a bitwise logical-and between reg0 and reg2 in reg0.
13167 +;;=============================================================================
13168 +
13169 +(define_insn "andnsi"
13170 + [(set (match_operand:SI 0 "register_operand" "+r")
13171 + (and:SI (match_dup 0)
13172 + (not:SI (match_operand:SI 1 "register_operand" "r"))))]
13173 + ""
13174 + "andn %0, %1"
13175 + [(set_attr "cc" "set_z")
13176 + (set_attr "length" "2")]
13177 +)
13178 +
13179 +
13180 +(define_insn "andsi3"
13181 + [(set (match_operand:SI 0 "register_operand" "=r, r, r, r")
13182 + (and:SI (match_operand:SI 1 "register_operand" "%0, r, 0, r")
13183 + (match_operand:SI 2 "nonmemory_operand" "r, M, i, r")))]
13184 + ""
13185 + {
13186 + switch (which_alternative){
13187 + case 0:
13188 + return "and\t%0, %2";
13189 + case 1:
13190 + {
13191 + int i, first_set = -1;
13192 + /* Search for first bit set in mask */
13193 + for ( i = 31; i >= 0; --i )
13194 + if ( INTVAL(operands[2]) & (1 << i) ){
13195 + first_set = i;
13196 + break;
13197 + }
13198 + operands[2] = gen_rtx_CONST_INT(SImode, first_set + 1);
13199 + return "bfextu\t%0, %1, 0, %2";
13200 + }
13201 + case 2:
13202 + if ( one_bit_cleared_operand(operands[2], VOIDmode) ){
13203 + int bitpos;
13204 + for ( bitpos = 0; bitpos < 32; bitpos++ )
13205 + if ( !(INTVAL(operands[2]) & (1 << bitpos)) )
13206 + break;
13207 + operands[2] = gen_rtx_CONST_INT(SImode, bitpos);
13208 + return "cbr\t%0, %2";
13209 + } else if ( (INTVAL(operands[2]) >= 0) &&
13210 + (INTVAL(operands[2]) <= 65535) )
13211 + return "andl\t%0, %2, COH";
13212 + else if ( (INTVAL(operands[2]) < 0) &&
13213 + (INTVAL(operands[2]) >= -65536 ) )
13214 + return "andl\t%0, lo(%2)";
13215 + else if ( ((INTVAL(operands[2]) & 0xffff) == 0xffff) )
13216 + return "andh\t%0, hi(%2)";
13217 + else if ( ((INTVAL(operands[2]) & 0xffff) == 0x0) )
13218 + return "andh\t%0, hi(%2), COH";
13219 + else
13220 + return "andh\t%0, hi(%2)\;andl\t%0, lo(%2)";
13221 + case 3:
13222 + return "and\t%0, %1, %2";
13223 + default:
13224 + abort();
13225 + }
13226 + }
13227 +
13228 + [(set_attr "length" "2,4,8,4")
13229 + (set_attr "cc" "set_z")])
13230 +
13231 +
13232 +
13233 +
13234 +(define_insn "anddi3"
13235 + [(set (match_operand:DI 0 "register_operand" "=&r,&r")
13236 + (and:DI (match_operand:DI 1 "register_operand" "%0,r")
13237 + (match_operand:DI 2 "register_operand" "r,r")))]
13238 + ""
13239 + "#"
13240 + [(set_attr "length" "8")
13241 + (set_attr "cc" "clobber")]
13242 +)
13243 +
13244 +;;=============================================================================
13245 +;; or
13246 +;;-----------------------------------------------------------------------------
13247 +;; Store the result after a bitwise inclusive-or between reg0 and reg2 in reg0.
13248 +;;=============================================================================
13249 +
13250 +(define_insn "iorsi3"
13251 + [(set (match_operand:SI 0 "register_operand" "=r,r,r")
13252 + (ior:SI (match_operand:SI 1 "register_operand" "%0,0,r" )
13253 + (match_operand:SI 2 "nonmemory_operand" "r ,i,r")))]
13254 + ""
13255 + {
13256 + switch (which_alternative){
13257 + case 0:
13258 + return "or\t%0, %2";
13259 + case 1:
13260 + if ( one_bit_set_operand(operands[2], VOIDmode) ){
13261 + int bitpos;
13262 + for (bitpos = 0; bitpos < 32; bitpos++)
13263 + if (INTVAL(operands[2]) & (1 << bitpos))
13264 + break;
13265 + operands[2] = gen_rtx_CONST_INT( SImode, bitpos);
13266 + return "sbr\t%0, %2";
13267 + } else if ( (INTVAL(operands[2]) >= 0) &&
13268 + (INTVAL(operands[2]) <= 65535) )
13269 + return "orl\t%0, %2";
13270 + else if ( ((INTVAL(operands[2]) & 0xffff) == 0x0) )
13271 + return "orh\t%0, hi(%2)";
13272 + else
13273 + return "orh\t%0, hi(%2)\;orl\t%0, lo(%2)";
13274 + case 2:
13275 + return "or\t%0, %1, %2";
13276 + default:
13277 + abort();
13278 + }
13279 + }
13280 + [(set_attr "length" "2,8,4")
13281 + (set_attr "cc" "set_z")])
13282 +
13283 +
13284 +(define_insn "iordi3"
13285 + [(set (match_operand:DI 0 "register_operand" "=&r,&r")
13286 + (ior:DI (match_operand:DI 1 "register_operand" "%0,r")
13287 + (match_operand:DI 2 "register_operand" "r,r")))]
13288 + ""
13289 + "#"
13290 + [(set_attr "length" "8")
13291 + (set_attr "cc" "clobber")]
13292 +)
13293 +
13294 +;;=============================================================================
13295 +;; xor bytes
13296 +;;-----------------------------------------------------------------------------
13297 +;; Store the result after a bitwise exclusive-or between reg0 and reg2 in reg0.
13298 +;;=============================================================================
13299 +
13300 +(define_insn "xorsi3"
13301 + [(set (match_operand:SI 0 "register_operand" "=r,r,r")
13302 + (xor:SI (match_operand:SI 1 "register_operand" "0,0,r")
13303 + (match_operand:SI 2 "nonmemory_operand" "r,i,r")))]
13304 + ""
13305 + {
13306 + switch (which_alternative){
13307 + case 0:
13308 + return "eor %0, %2";
13309 + case 1:
13310 + if ( (INTVAL(operands[2]) >= 0) &&
13311 + (INTVAL(operands[2]) <= 65535) )
13312 + return "eorl %0, %2";
13313 + else if ( ((INTVAL(operands[2]) & 0xffff) == 0x0) )
13314 + return "eorh %0, hi(%2)";
13315 + else
13316 + return "eorh %0, hi(%2)\;eorl %0, lo(%2)";
13317 + case 2:
13318 + return "eor %0, %1, %2";
13319 + default:
13320 + abort();
13321 + }
13322 + }
13323 +
13324 + [(set_attr "length" "2,8,4")
13325 + (set_attr "cc" "set_z")])
13326 +
13327 +
13328 +(define_insn "xordi3"
13329 + [(set (match_operand:DI 0 "register_operand" "=&r,&r")
13330 + (xor: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 +;; Three operand predicable insns
13340 +;;=============================================================================
13341 +
13342 +(define_insn "<predicable_insn3><mode>_predicable"
13343 + [(set (match_operand:INTM 0 "register_operand" "=r")
13344 + (predicable_op3:INTM (match_operand:INTM 1 "register_operand" "<predicable_commutative3>r")
13345 + (match_operand:INTM 2 "register_operand" "r")))]
13346 + "TARGET_V2_INSNS"
13347 + "<predicable_insn3>%?\t%0, %1, %2"
13348 + [(set_attr "length" "4")
13349 + (set_attr "cc" "cmp_cond_insn")
13350 + (set_attr "predicable" "yes")]
13351 +)
13352 +
13353 +(define_insn_and_split "<predicable_insn3><mode>_imm_clobber_predicable"
13354 + [(parallel
13355 + [(set (match_operand:INTM 0 "register_operand" "=r")
13356 + (predicable_op3:INTM (match_operand:INTM 1 "register_operand" "<predicable_commutative3>r")
13357 + (match_operand:INTM 2 "avr32_mov_immediate_operand" "JKs21")))
13358 + (clobber (match_operand:INTM 3 "register_operand" "=&r"))])]
13359 + "TARGET_V2_INSNS"
13360 + {
13361 + if ( current_insn_predicate != NULL_RTX )
13362 + {
13363 + if ( avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks08") )
13364 + return "%! mov%?\t%3, %2\;<predicable_insn3>%?\t%0, %1, %3";
13365 + else if ( avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks21") )
13366 + return "%! mov\t%3, %2\;<predicable_insn3>%?\t%0, %1, %3";
13367 + else
13368 + return "%! movh\t%3, hi(%2)\;<predicable_insn3>%?\t%0, %1, %3";
13369 + }
13370 + else
13371 + {
13372 + if ( !avr32_cond_imm_clobber_splittable (insn, operands) )
13373 + {
13374 + if ( avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks08") )
13375 + return "mov%?\t%3, %2\;<predicable_insn3>%?\t%0, %1, %3";
13376 + else if ( avr32_const_ok_for_constraint_p (INTVAL (operands[2]), 'K', "Ks21") )
13377 + return "mov\t%3, %2\;<predicable_insn3>%?\t%0, %1, %3";
13378 + else
13379 + return "movh\t%3, hi(%2)\;<predicable_insn3>%?\t%0, %1, %3";
13380 + }
13381 + return "#";
13382 + }
13383 +
13384 + }
13385 + ;; If we find out that we could not actually do if-conversion on the block
13386 + ;; containing this insn we convert it back to normal immediate format
13387 + ;; to avoid outputing a redundant move insn
13388 + ;; Do not split until after we have checked if we can make the insn
13389 + ;; conditional.
13390 + "(GET_CODE (PATTERN (insn)) != COND_EXEC
13391 + && cfun->machine->ifcvt_after_reload
13392 + && avr32_cond_imm_clobber_splittable (insn, operands))"
13393 + [(set (match_dup 0)
13394 + (predicable_op3:INTM (match_dup 1)
13395 + (match_dup 2)))]
13396 + ""
13397 + [(set_attr "length" "8")
13398 + (set_attr "cc" "cmp_cond_insn")
13399 + (set_attr "predicable" "yes")]
13400 + )
13401 +
13402 +
13403 +;;=============================================================================
13404 +;; Zero extend predicable insns
13405 +;;=============================================================================
13406 +(define_insn_and_split "zero_extendhisi_clobber_predicable"
13407 + [(parallel
13408 + [(set (match_operand:SI 0 "register_operand" "=r")
13409 + (zero_extend:SI (match_operand:HI 1 "register_operand" "r")))
13410 + (clobber (match_operand:SI 2 "register_operand" "=&r"))])]
13411 + "TARGET_V2_INSNS"
13412 + {
13413 + if ( current_insn_predicate != NULL_RTX )
13414 + {
13415 + return "%! mov\t%2, 0xffff\;and%?\t%0, %1, %2";
13416 + }
13417 + else
13418 + {
13419 + return "#";
13420 + }
13421 +
13422 + }
13423 + ;; If we find out that we could not actually do if-conversion on the block
13424 + ;; containing this insn we convert it back to normal immediate format
13425 + ;; to avoid outputing a redundant move insn
13426 + ;; Do not split until after we have checked if we can make the insn
13427 + ;; conditional.
13428 + "(GET_CODE (PATTERN (insn)) != COND_EXEC
13429 + && cfun->machine->ifcvt_after_reload)"
13430 + [(set (match_dup 0)
13431 + (zero_extend:SI (match_dup 1)))]
13432 + ""
13433 + [(set_attr "length" "8")
13434 + (set_attr "cc" "cmp_cond_insn")
13435 + (set_attr "predicable" "yes")]
13436 + )
13437 +
13438 +(define_insn_and_split "zero_extendqisi_clobber_predicable"
13439 + [(parallel
13440 + [(set (match_operand:SI 0 "register_operand" "=r")
13441 + (zero_extend:SI (match_operand:QI 1 "register_operand" "r")))
13442 + (clobber (match_operand:SI 2 "register_operand" "=&r"))])]
13443 + "TARGET_V2_INSNS"
13444 + {
13445 + if ( current_insn_predicate != NULL_RTX )
13446 + {
13447 + return "%! mov\t%2, 0xff\;and%?\t%0, %1, %2";
13448 + }
13449 + else
13450 + {
13451 + return "#";
13452 + }
13453 +
13454 + }
13455 + ;; If we find out that we could not actually do if-conversion on the block
13456 + ;; containing this insn we convert it back to normal immediate format
13457 + ;; to avoid outputing a redundant move insn
13458 + ;; Do not split until after we have checked if we can make the insn
13459 + ;; conditional.
13460 + "(GET_CODE (PATTERN (insn)) != COND_EXEC
13461 + && cfun->machine->ifcvt_after_reload)"
13462 + [(set (match_dup 0)
13463 + (zero_extend:SI (match_dup 1)))]
13464 + ""
13465 + [(set_attr "length" "8")
13466 + (set_attr "cc" "cmp_cond_insn")
13467 + (set_attr "predicable" "yes")]
13468 + )
13469 +
13470 +(define_insn_and_split "zero_extendqihi_clobber_predicable"
13471 + [(parallel
13472 + [(set (match_operand:HI 0 "register_operand" "=r")
13473 + (zero_extend:HI (match_operand:QI 1 "register_operand" "r")))
13474 + (clobber (match_operand:SI 2 "register_operand" "=&r"))])]
13475 + "TARGET_V2_INSNS"
13476 + {
13477 + if ( current_insn_predicate != NULL_RTX )
13478 + {
13479 + return "%! mov\t%2, 0xff\;and%?\t%0, %1, %2";
13480 + }
13481 + else
13482 + {
13483 + return "#";
13484 + }
13485 +
13486 + }
13487 + ;; If we find out that we could not actually do if-conversion on the block
13488 + ;; containing this insn we convert it back to normal immediate format
13489 + ;; to avoid outputing a redundant move insn
13490 + ;; Do not split until after we have checked if we can make the insn
13491 + ;; conditional.
13492 + "(GET_CODE (PATTERN (insn)) != COND_EXEC
13493 + && cfun->machine->ifcvt_after_reload)"
13494 + [(set (match_dup 0)
13495 + (zero_extend:HI (match_dup 1)))]
13496 + ""
13497 + [(set_attr "length" "8")
13498 + (set_attr "cc" "cmp_cond_insn")
13499 + (set_attr "predicable" "yes")]
13500 + )
13501 +;;=============================================================================
13502 +;; divmod
13503 +;;-----------------------------------------------------------------------------
13504 +;; Signed division that produces both a quotient and a remainder.
13505 +;;=============================================================================
13506 +(define_expand "divmodsi4"
13507 + [(parallel [
13508 + (parallel [
13509 + (set (match_operand:SI 0 "register_operand" "=r")
13510 + (div:SI (match_operand:SI 1 "register_operand" "r")
13511 + (match_operand:SI 2 "register_operand" "r")))
13512 + (set (match_operand:SI 3 "register_operand" "=r")
13513 + (mod:SI (match_dup 1)
13514 + (match_dup 2)))])
13515 + (use (match_dup 4))])]
13516 + ""
13517 + {
13518 + if (can_create_pseudo_p ()) {
13519 + operands[4] = gen_reg_rtx (DImode);
13520 +
13521 + emit_insn(gen_divmodsi4_internal(operands[4],operands[1],operands[2]));
13522 + emit_move_insn(operands[0], gen_rtx_SUBREG( SImode, operands[4], 4));
13523 + emit_move_insn(operands[3], gen_rtx_SUBREG( SImode, operands[4], 0));
13524 +
13525 + DONE;
13526 + } else {
13527 + FAIL;
13528 + }
13529 +
13530 + })
13531 +
13532 +
13533 +(define_insn "divmodsi4_internal"
13534 + [(set (match_operand:DI 0 "register_operand" "=r")
13535 + (unspec:DI [(match_operand:SI 1 "register_operand" "r")
13536 + (match_operand:SI 2 "register_operand" "r")]
13537 + UNSPEC_DIVMODSI4_INTERNAL))]
13538 + ""
13539 + "divs %0, %1, %2"
13540 + [(set_attr "type" "div")
13541 + (set_attr "cc" "none")])
13542 +
13543 +
13544 +;;=============================================================================
13545 +;; udivmod
13546 +;;-----------------------------------------------------------------------------
13547 +;; Unsigned division that produces both a quotient and a remainder.
13548 +;;=============================================================================
13549 +(define_expand "udivmodsi4"
13550 + [(parallel [
13551 + (parallel [
13552 + (set (match_operand:SI 0 "register_operand" "=r")
13553 + (udiv:SI (match_operand:SI 1 "register_operand" "r")
13554 + (match_operand:SI 2 "register_operand" "r")))
13555 + (set (match_operand:SI 3 "register_operand" "=r")
13556 + (umod:SI (match_dup 1)
13557 + (match_dup 2)))])
13558 + (use (match_dup 4))])]
13559 + ""
13560 + {
13561 + if (can_create_pseudo_p ()) {
13562 + operands[4] = gen_reg_rtx (DImode);
13563 +
13564 + emit_insn(gen_udivmodsi4_internal(operands[4],operands[1],operands[2]));
13565 + emit_move_insn(operands[0], gen_rtx_SUBREG( SImode, operands[4], 4));
13566 + emit_move_insn(operands[3], gen_rtx_SUBREG( SImode, operands[4], 0));
13567 +
13568 + DONE;
13569 + } else {
13570 + FAIL;
13571 + }
13572 + })
13573 +
13574 +(define_insn "udivmodsi4_internal"
13575 + [(set (match_operand:DI 0 "register_operand" "=r")
13576 + (unspec:DI [(match_operand:SI 1 "register_operand" "r")
13577 + (match_operand:SI 2 "register_operand" "r")]
13578 + UNSPEC_UDIVMODSI4_INTERNAL))]
13579 + ""
13580 + "divu %0, %1, %2"
13581 + [(set_attr "type" "div")
13582 + (set_attr "cc" "none")])
13583 +
13584 +
13585 +;;=============================================================================
13586 +;; Arithmetic-shift left
13587 +;;-----------------------------------------------------------------------------
13588 +;; Arithmetic-shift reg0 left by reg2 or immediate value.
13589 +;;=============================================================================
13590 +
13591 +(define_insn "ashlsi3"
13592 + [(set (match_operand:SI 0 "register_operand" "=r,r,r")
13593 + (ashift:SI (match_operand:SI 1 "register_operand" "r,0,r")
13594 + (match_operand:SI 2 "register_const_int_operand" "r,Ku05,Ku05")))]
13595 + ""
13596 + "@
13597 + lsl %0, %1, %2
13598 + lsl %0, %2
13599 + lsl %0, %1, %2"
13600 + [(set_attr "length" "4,2,4")
13601 + (set_attr "cc" "set_ncz")])
13602 +
13603 +;;=============================================================================
13604 +;; Arithmetic-shift right
13605 +;;-----------------------------------------------------------------------------
13606 +;; Arithmetic-shift reg0 right by an immediate value.
13607 +;;=============================================================================
13608 +
13609 +(define_insn "ashrsi3"
13610 + [(set (match_operand:SI 0 "register_operand" "=r,r,r")
13611 + (ashiftrt:SI (match_operand:SI 1 "register_operand" "r,0,r")
13612 + (match_operand:SI 2 "register_const_int_operand" "r,Ku05,Ku05")))]
13613 + ""
13614 + "@
13615 + asr %0, %1, %2
13616 + asr %0, %2
13617 + asr %0, %1, %2"
13618 + [(set_attr "length" "4,2,4")
13619 + (set_attr "cc" "set_ncz")])
13620 +
13621 +;;=============================================================================
13622 +;; Logical shift right
13623 +;;-----------------------------------------------------------------------------
13624 +;; Logical shift reg0 right by an immediate value.
13625 +;;=============================================================================
13626 +
13627 +(define_insn "lshrsi3"
13628 + [(set (match_operand:SI 0 "register_operand" "=r,r,r")
13629 + (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,0,r")
13630 + (match_operand:SI 2 "register_const_int_operand" "r,Ku05,Ku05")))]
13631 + ""
13632 + "@
13633 + lsr %0, %1, %2
13634 + lsr %0, %2
13635 + lsr %0, %1, %2"
13636 + [(set_attr "length" "4,2,4")
13637 + (set_attr "cc" "set_ncz")])
13638 +
13639 +
13640 +;;=============================================================================
13641 +;; neg
13642 +;;-----------------------------------------------------------------------------
13643 +;; Negate operand 1 and store the result in operand 0.
13644 +;;=============================================================================
13645 +(define_insn "negsi2"
13646 + [(set (match_operand:SI 0 "register_operand" "=r,r")
13647 + (neg:SI (match_operand:SI 1 "register_operand" "0,r")))]
13648 + ""
13649 + "@
13650 + neg\t%0
13651 + rsub\t%0, %1, 0"
13652 + [(set_attr "length" "2,4")
13653 + (set_attr "cc" "set_vncz")])
13654 +
13655 +(define_insn "negsi2_predicable"
13656 + [(set (match_operand:SI 0 "register_operand" "+r")
13657 + (neg:SI (match_dup 0)))]
13658 + "TARGET_V2_INSNS"
13659 + "rsub%?\t%0, 0"
13660 + [(set_attr "length" "4")
13661 + (set_attr "cc" "cmp_cond_insn")
13662 + (set_attr "predicable" "yes")])
13663 +
13664 +;;=============================================================================
13665 +;; abs
13666 +;;-----------------------------------------------------------------------------
13667 +;; Store the absolute value of operand 1 into operand 0.
13668 +;;=============================================================================
13669 +(define_insn "abssi2"
13670 + [(set (match_operand:SI 0 "register_operand" "=r")
13671 + (abs:SI (match_operand:SI 1 "register_operand" "0")))]
13672 + ""
13673 + "abs\t%0"
13674 + [(set_attr "length" "2")
13675 + (set_attr "cc" "set_z")])
13676 +
13677 +
13678 +;;=============================================================================
13679 +;; one_cmpl
13680 +;;-----------------------------------------------------------------------------
13681 +;; Store the bitwise-complement of operand 1 into operand 0.
13682 +;;=============================================================================
13683 +
13684 +(define_insn "one_cmplsi2"
13685 + [(set (match_operand:SI 0 "register_operand" "=r,r")
13686 + (not:SI (match_operand:SI 1 "register_operand" "r,0")))]
13687 + ""
13688 + "@
13689 + rsub\t%0, %1, -1
13690 + com\t%0"
13691 + [(set_attr "length" "4,2")
13692 + (set_attr "cc" "set_z")])
13693 +
13694 +
13695 +(define_insn "one_cmplsi2_predicable"
13696 + [(set (match_operand:SI 0 "register_operand" "+r")
13697 + (not:SI (match_dup 0)))]
13698 + "TARGET_V2_INSNS"
13699 + "rsub%?\t%0, -1"
13700 + [(set_attr "length" "4")
13701 + (set_attr "cc" "cmp_cond_insn")
13702 + (set_attr "predicable" "yes")])
13703 +
13704 +
13705 +;;=============================================================================
13706 +;; Bit load
13707 +;;-----------------------------------------------------------------------------
13708 +;; Load a bit into Z and C flags
13709 +;;=============================================================================
13710 +(define_insn "bldsi"
13711 + [(set (cc0)
13712 + (and:SI (match_operand:SI 0 "register_operand" "r")
13713 + (match_operand:SI 1 "one_bit_set_operand" "i")))]
13714 + ""
13715 + "bld\t%0, %p1"
13716 + [(set_attr "length" "4")
13717 + (set_attr "cc" "bld")]
13718 + )
13719 +
13720 +
13721 +;;=============================================================================
13722 +;; Compare
13723 +;;-----------------------------------------------------------------------------
13724 +;; Compare reg0 with reg1 or an immediate value.
13725 +;;=============================================================================
13726 +
13727 +(define_expand "cmp<mode>"
13728 + [(set (cc0)
13729 + (compare:CMP
13730 + (match_operand:CMP 0 "register_operand" "")
13731 + (match_operand:CMP 1 "<CMP:cmp_predicate>" "")))]
13732 + ""
13733 + "{
13734 + avr32_compare_op0 = operands[0];
13735 + avr32_compare_op1 = operands[1];
13736 + }"
13737 +)
13738 +
13739 +(define_insn "cmp<mode>_internal"
13740 + [(set (cc0)
13741 + (compare:CMP
13742 + (match_operand:CMP 0 "register_operand" "r")
13743 + (match_operand:CMP 1 "<CMP:cmp_predicate>" "<CMP:cmp_constraint>")))]
13744 + ""
13745 + {
13746 + /* Check if the next insn already will output a compare. */
13747 + if (!next_insn_emits_cmp (insn))
13748 + set_next_insn_cond(insn,
13749 + avr32_output_cmp(get_next_insn_cond(insn), GET_MODE (operands[0]), operands[0], operands[1]));
13750 + return "";
13751 + }
13752 + [(set_attr "length" "4")
13753 + (set_attr "cc" "compare")])
13754 +
13755 +
13756 +;;;=============================================================================
13757 +;; Test if zero
13758 +;;-----------------------------------------------------------------------------
13759 +;; Compare reg against zero and set the condition codes.
13760 +;;=============================================================================
13761 +
13762 +
13763 +(define_expand "tstsi"
13764 + [(set (cc0)
13765 + (match_operand:SI 0 "register_operand" ""))]
13766 + ""
13767 + {
13768 + avr32_compare_op0 = operands[0];
13769 + avr32_compare_op1 = const0_rtx;
13770 + }
13771 +)
13772 +
13773 +(define_insn "tstsi_internal"
13774 + [(set (cc0)
13775 + (match_operand:SI 0 "register_operand" "r"))]
13776 + ""
13777 + {
13778 + /* Check if the next insn already will output a compare. */
13779 + if (!next_insn_emits_cmp (insn))
13780 + set_next_insn_cond(insn,
13781 + avr32_output_cmp(get_next_insn_cond(insn), SImode, operands[0], const0_rtx));
13782 +
13783 + return "";
13784 + }
13785 + [(set_attr "length" "2")
13786 + (set_attr "cc" "compare")])
13787 +
13788 +
13789 +(define_expand "tstdi"
13790 + [(set (cc0)
13791 + (match_operand:DI 0 "register_operand" ""))]
13792 + ""
13793 + {
13794 + avr32_compare_op0 = operands[0];
13795 + avr32_compare_op1 = const0_rtx;
13796 + }
13797 +)
13798 +
13799 +(define_insn "tstdi_internal"
13800 + [(set (cc0)
13801 + (match_operand:DI 0 "register_operand" "r"))]
13802 + ""
13803 + {
13804 + /* Check if the next insn already will output a compare. */
13805 + if (!next_insn_emits_cmp (insn))
13806 + set_next_insn_cond(insn,
13807 + avr32_output_cmp(get_next_insn_cond(insn), DImode, operands[0], const0_rtx));
13808 + return "";
13809 + }
13810 + [(set_attr "length" "4")
13811 + (set_attr "type" "alu2")
13812 + (set_attr "cc" "compare")])
13813 +
13814 +
13815 +
13816 +;;=============================================================================
13817 +;; Convert operands
13818 +;;-----------------------------------------------------------------------------
13819 +;;
13820 +;;=============================================================================
13821 +(define_insn "truncdisi2"
13822 + [(set (match_operand:SI 0 "general_operand" "")
13823 + (truncate:SI (match_operand:DI 1 "general_operand" "")))]
13824 + ""
13825 + "truncdisi2")
13826 +
13827 +;;=============================================================================
13828 +;; Extend
13829 +;;-----------------------------------------------------------------------------
13830 +;;
13831 +;;=============================================================================
13832 +
13833 +
13834 +(define_insn "extendhisi2"
13835 + [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
13836 + (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "0,r,<RKu00>,m")))]
13837 + ""
13838 + {
13839 + switch ( which_alternative ){
13840 + case 0:
13841 + return "casts.h\t%0";
13842 + case 1:
13843 + return "bfexts\t%0, %1, 0, 16";
13844 + case 2:
13845 + case 3:
13846 + return "ld.sh\t%0, %1";
13847 + default:
13848 + abort();
13849 + }
13850 + }
13851 + [(set_attr "length" "2,4,2,4")
13852 + (set_attr "cc" "set_ncz,set_ncz,none,none")
13853 + (set_attr "type" "alu,alu,load_rm,load_rm")])
13854 +
13855 +(define_insn "extendqisi2"
13856 + [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
13857 + (sign_extend:SI (match_operand:QI 1 "extendqi_operand" "0,r,RKu00,m")))]
13858 + ""
13859 + {
13860 + switch ( which_alternative ){
13861 + case 0:
13862 + return "casts.b\t%0";
13863 + case 1:
13864 + return "bfexts\t%0, %1, 0, 8";
13865 + case 2:
13866 + case 3:
13867 + return "ld.sb\t%0, %1";
13868 + default:
13869 + abort();
13870 + }
13871 + }
13872 + [(set_attr "length" "2,4,2,4")
13873 + (set_attr "cc" "set_ncz,set_ncz,none,none")
13874 + (set_attr "type" "alu,alu,load_rm,load_rm")])
13875 +
13876 +(define_insn "extendqihi2"
13877 + [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
13878 + (sign_extend:HI (match_operand:QI 1 "extendqi_operand" "0,r,RKu00,m")))]
13879 + ""
13880 + {
13881 + switch ( which_alternative ){
13882 + case 0:
13883 + return "casts.b\t%0";
13884 + case 1:
13885 + return "bfexts\t%0, %1, 0, 8";
13886 + case 2:
13887 + case 3:
13888 + return "ld.sb\t%0, %1";
13889 + default:
13890 + abort();
13891 + }
13892 + }
13893 + [(set_attr "length" "2,4,2,4")
13894 + (set_attr "cc" "set_ncz,set_ncz,none,none")
13895 + (set_attr "type" "alu,alu,load_rm,load_rm")])
13896 +
13897 +
13898 +;;=============================================================================
13899 +;; Zero-extend
13900 +;;-----------------------------------------------------------------------------
13901 +;;
13902 +;;=============================================================================
13903 +
13904 +(define_insn "zero_extendhisi2"
13905 + [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
13906 + (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "0,r,<RKu00>,m")))]
13907 + ""
13908 + {
13909 + switch ( which_alternative ){
13910 + case 0:
13911 + return "castu.h\t%0";
13912 + case 1:
13913 + return "bfextu\t%0, %1, 0, 16";
13914 + case 2:
13915 + case 3:
13916 + return "ld.uh\t%0, %1";
13917 + default:
13918 + abort();
13919 + }
13920 + }
13921 +
13922 + [(set_attr "length" "2,4,2,4")
13923 + (set_attr "cc" "set_ncz,set_ncz,none,none")
13924 + (set_attr "type" "alu,alu,load_rm,load_rm")])
13925 +
13926 +(define_insn "zero_extendqisi2"
13927 + [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
13928 + (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "0,r,<RKu00>,m")))]
13929 + ""
13930 + {
13931 + switch ( which_alternative ){
13932 + case 0:
13933 + return "castu.b\t%0";
13934 + case 1:
13935 + return "bfextu\t%0, %1, 0, 8";
13936 + case 2:
13937 + case 3:
13938 + return "ld.ub\t%0, %1";
13939 + default:
13940 + abort();
13941 + }
13942 + }
13943 + [(set_attr "length" "2,4,2,4")
13944 + (set_attr "cc" "set_ncz, set_ncz, none, none")
13945 + (set_attr "type" "alu, alu, load_rm, load_rm")])
13946 +
13947 +(define_insn "zero_extendqihi2"
13948 + [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
13949 + (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,r,<RKu00>,m")))]
13950 + ""
13951 + {
13952 + switch ( which_alternative ){
13953 + case 0:
13954 + return "castu.b\t%0";
13955 + case 1:
13956 + return "bfextu\t%0, %1, 0, 8";
13957 + case 2:
13958 + case 3:
13959 + return "ld.ub\t%0, %1";
13960 + default:
13961 + abort();
13962 + }
13963 + }
13964 + [(set_attr "length" "2,4,2,4")
13965 + (set_attr "cc" "set_ncz, set_ncz, none, none")
13966 + (set_attr "type" "alu, alu, load_rm, load_rm")])
13967 +
13968 +
13969 +;;=============================================================================
13970 +;; Conditional load and extend insns
13971 +;;=============================================================================
13972 +(define_insn "ldsi<mode>_predicable_se"
13973 + [(set (match_operand:SI 0 "register_operand" "=r")
13974 + (sign_extend:SI
13975 + (match_operand:INTM 1 "memory_operand" "<INTM:pred_mem_constraint>")))]
13976 + "TARGET_V2_INSNS"
13977 + "ld<INTM:load_postfix_s>%?\t%0, %1"
13978 + [(set_attr "length" "4")
13979 + (set_attr "cc" "cmp_cond_insn")
13980 + (set_attr "type" "load")
13981 + (set_attr "predicable" "yes")]
13982 +)
13983 +
13984 +(define_insn "ldsi<mode>_predicable_ze"
13985 + [(set (match_operand:SI 0 "register_operand" "=r")
13986 + (zero_extend:SI
13987 + (match_operand:INTM 1 "memory_operand" "<INTM:pred_mem_constraint>")))]
13988 + "TARGET_V2_INSNS"
13989 + "ld<INTM:load_postfix_u>%?\t%0, %1"
13990 + [(set_attr "length" "4")
13991 + (set_attr "cc" "cmp_cond_insn")
13992 + (set_attr "type" "load")
13993 + (set_attr "predicable" "yes")]
13994 +)
13995 +
13996 +(define_insn "ldhi_predicable_ze"
13997 + [(set (match_operand:HI 0 "register_operand" "=r")
13998 + (zero_extend:HI
13999 + (match_operand:QI 1 "memory_operand" "RKs10")))]
14000 + "TARGET_V2_INSNS"
14001 + "ld.ub%?\t%0, %1"
14002 + [(set_attr "length" "4")
14003 + (set_attr "cc" "cmp_cond_insn")
14004 + (set_attr "type" "load")
14005 + (set_attr "predicable" "yes")]
14006 +)
14007 +
14008 +(define_insn "ldhi_predicable_se"
14009 + [(set (match_operand:HI 0 "register_operand" "=r")
14010 + (sign_extend:HI
14011 + (match_operand:QI 1 "memory_operand" "RKs10")))]
14012 + "TARGET_V2_INSNS"
14013 + "ld.sb%?\t%0, %1"
14014 + [(set_attr "length" "4")
14015 + (set_attr "cc" "cmp_cond_insn")
14016 + (set_attr "type" "load")
14017 + (set_attr "predicable" "yes")]
14018 +)
14019 +
14020 +;;=============================================================================
14021 +;; Conditional set register
14022 +;; sr{cond4} rd
14023 +;;-----------------------------------------------------------------------------
14024 +
14025 +;;Because of the same issue as with conditional moves and adds we must
14026 +;;not separate the compare instrcution from the scc instruction as
14027 +;;they might be sheduled "badly".
14028 +
14029 +(define_insn "s<code>"
14030 + [(set (match_operand:SI 0 "register_operand" "=r")
14031 + (any_cond:SI (cc0)
14032 + (const_int 0)))]
14033 + ""
14034 + "sr<cond>\t%0"
14035 + [(set_attr "length" "2")
14036 + (set_attr "cc" "none")])
14037 +
14038 +(define_insn "smi"
14039 + [(set (match_operand:SI 0 "register_operand" "=r")
14040 + (unspec:SI [(cc0)
14041 + (const_int 0)] UNSPEC_COND_MI))]
14042 + ""
14043 + "srmi\t%0"
14044 + [(set_attr "length" "2")
14045 + (set_attr "cc" "none")])
14046 +
14047 +(define_insn "spl"
14048 + [(set (match_operand:SI 0 "register_operand" "=r")
14049 + (unspec:SI [(cc0)
14050 + (const_int 0)] UNSPEC_COND_PL))]
14051 + ""
14052 + "srpl\t%0"
14053 + [(set_attr "length" "2")
14054 + (set_attr "cc" "none")])
14055 +
14056 +
14057 +;;=============================================================================
14058 +;; Conditional branch
14059 +;;-----------------------------------------------------------------------------
14060 +;; Branch to label if the specified condition codes are set.
14061 +;;=============================================================================
14062 +; branch if negative
14063 +(define_insn "bmi"
14064 + [(set (pc)
14065 + (if_then_else (unspec:CC [(cc0) (const_int 0)] UNSPEC_COND_MI)
14066 + (label_ref (match_operand 0 "" ""))
14067 + (pc)))]
14068 + ""
14069 + "brmi %0"
14070 + [(set_attr "type" "branch")
14071 + (set (attr "length")
14072 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14073 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14074 + (const_int 2)] ; use compact branch
14075 + (const_int 4))) ; use extended branch
14076 + (set_attr "cc" "none")])
14077 +
14078 +(define_insn "*bmi-reverse"
14079 + [(set (pc)
14080 + (if_then_else (unspec:CC [(cc0) (const_int 0)] UNSPEC_COND_MI)
14081 + (pc)
14082 + (label_ref (match_operand 0 "" ""))))]
14083 + ""
14084 + "brpl %0"
14085 + [(set_attr "type" "branch")
14086 + (set (attr "length")
14087 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14088 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14089 + (const_int 2)] ; use compact branch
14090 + (const_int 4))) ; use extended branch
14091 + (set_attr "cc" "none")])
14092 +
14093 +; branch if positive
14094 +(define_insn "bpl"
14095 + [(set (pc)
14096 + (if_then_else (unspec:CC [(cc0) (const_int 0)] UNSPEC_COND_PL)
14097 + (label_ref (match_operand 0 "" ""))
14098 + (pc)))]
14099 + ""
14100 + "brpl %0"
14101 + [(set_attr "type" "branch")
14102 + (set (attr "length")
14103 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14104 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14105 + (const_int 2)] ; use compact branch
14106 + (const_int 4))) ; use extended branch
14107 + (set_attr "cc" "none")])
14108 +
14109 +(define_insn "*bpl-reverse"
14110 + [(set (pc)
14111 + (if_then_else (unspec:CC [(cc0) (const_int 0)] UNSPEC_COND_PL)
14112 + (pc)
14113 + (label_ref (match_operand 0 "" ""))))]
14114 + ""
14115 + "brmi %0"
14116 + [(set_attr "type" "branch")
14117 + (set (attr "length")
14118 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14119 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14120 + (const_int 2)] ; use compact branch
14121 + (const_int 4))) ; use extended branch
14122 + (set_attr "cc" "none")])
14123 +
14124 +; branch if equal
14125 +(define_insn "b<code>"
14126 + [(set (pc)
14127 + (if_then_else (any_cond:CC (cc0)
14128 + (const_int 0))
14129 + (label_ref (match_operand 0 "" ""))
14130 + (pc)))]
14131 + ""
14132 + "br<cond> %0 "
14133 + [(set_attr "type" "branch")
14134 + (set (attr "length")
14135 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14136 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14137 + (const_int 2)] ; use compact branch
14138 + (const_int 4))) ; use extended branch
14139 + (set_attr "cc" "none")])
14140 +
14141 +
14142 +(define_insn "*b<code>-reverse"
14143 + [(set (pc)
14144 + (if_then_else (any_cond:CC (cc0)
14145 + (const_int 0))
14146 + (pc)
14147 + (label_ref (match_operand 0 "" ""))))]
14148 + ""
14149 + "br<invcond> %0 "
14150 + [(set_attr "type" "branch")
14151 + (set (attr "length")
14152 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
14153 + (le (minus (pc) (match_dup 0)) (const_int 256)))
14154 + (const_int 2)] ; use compact branch
14155 + (const_int 4))) ; use extended branch
14156 + (set_attr "cc" "none")])
14157 +
14158 +
14159 +
14160 +;=============================================================================
14161 +; Conditional Add/Subtract
14162 +;-----------------------------------------------------------------------------
14163 +; sub{cond4} Rd, imm
14164 +;=============================================================================
14165 +
14166 +
14167 +(define_expand "add<mode>cc"
14168 + [(set (match_operand:ADDCC 0 "register_operand" "")
14169 + (if_then_else:ADDCC (match_operator 1 "avr32_comparison_operator"
14170 + [(match_dup 4)
14171 + (match_dup 5)])
14172 + (match_operand:ADDCC 2 "register_operand" "")
14173 + (plus:ADDCC
14174 + (match_dup 2)
14175 + (match_operand:ADDCC 3 "" ""))))]
14176 + ""
14177 + {
14178 + if ( !(GET_CODE (operands[3]) == CONST_INT
14179 + || (TARGET_V2_INSNS && REG_P(operands[3]))) ){
14180 + FAIL;
14181 + }
14182 +
14183 + /* Delete compare instruction as it is merged into this instruction */
14184 + remove_insn (get_last_insn_anywhere ());
14185 +
14186 + operands[4] = avr32_compare_op0;
14187 + operands[5] = avr32_compare_op1;
14188 +
14189 + if ( TARGET_V2_INSNS
14190 + && REG_P(operands[3])
14191 + && REGNO(operands[0]) != REGNO(operands[2]) ){
14192 + emit_move_insn (operands[0], operands[2]);
14193 + operands[2] = operands[0];
14194 + }
14195 + }
14196 + )
14197 +
14198 +(define_insn "add<ADDCC:mode>cc_cmp<CMP:mode>_reg"
14199 + [(set (match_operand:ADDCC 0 "register_operand" "=r")
14200 + (if_then_else:ADDCC (match_operator 1 "avr32_comparison_operator"
14201 + [(match_operand:CMP 4 "register_operand" "r")
14202 + (match_operand:CMP 5 "<CMP:cmp_predicate>" "<CMP:cmp_constraint>")])
14203 + (match_dup 0)
14204 + (plus:ADDCC
14205 + (match_operand:ADDCC 2 "register_operand" "r")
14206 + (match_operand:ADDCC 3 "register_operand" "r"))))]
14207 + "TARGET_V2_INSNS"
14208 + {
14209 + operands[1] = avr32_output_cmp(operands[1], GET_MODE(operands[4]), operands[4], operands[5]);
14210 + return "add%i1\t%0, %2, %3";
14211 + }
14212 + [(set_attr "length" "8")
14213 + (set_attr "cc" "cmp_cond_insn")])
14214 +
14215 +(define_insn "add<ADDCC:mode>cc_cmp<CMP:mode>"
14216 + [(set (match_operand:ADDCC 0 "register_operand" "=r")
14217 + (if_then_else:ADDCC (match_operator 1 "avr32_comparison_operator"
14218 + [(match_operand:CMP 4 "register_operand" "r")
14219 + (match_operand:CMP 5 "<CMP:cmp_predicate>" "<CMP:cmp_constraint>")])
14220 + (match_operand:ADDCC 2 "register_operand" "0")
14221 + (plus:ADDCC
14222 + (match_dup 2)
14223 + (match_operand:ADDCC 3 "avr32_cond_immediate_operand" "Is08"))))]
14224 + ""
14225 + {
14226 + operands[1] = avr32_output_cmp(operands[1], GET_MODE(operands[4]), operands[4], operands[5]);
14227 + return "sub%i1\t%0, -%3";
14228 + }
14229 + [(set_attr "length" "8")
14230 + (set_attr "cc" "cmp_cond_insn")])
14231 +
14232 +;=============================================================================
14233 +; Conditional Move
14234 +;-----------------------------------------------------------------------------
14235 +; mov{cond4} Rd, (Rs/imm)
14236 +;=============================================================================
14237 +(define_expand "mov<mode>cc"
14238 + [(set (match_operand:MOVCC 0 "register_operand" "")
14239 + (if_then_else:MOVCC (match_operator 1 "avr32_comparison_operator"
14240 + [(match_dup 4)
14241 + (match_dup 5)])
14242 + (match_operand:MOVCC 2 "avr32_cond_register_immediate_operand" "")
14243 + (match_operand:MOVCC 3 "avr32_cond_register_immediate_operand" "")))]
14244 + ""
14245 + {
14246 + /* Delete compare instruction as it is merged into this instruction */
14247 + remove_insn (get_last_insn_anywhere ());
14248 +
14249 + operands[4] = avr32_compare_op0;
14250 + operands[5] = avr32_compare_op1;
14251 + }
14252 + )
14253 +
14254 +
14255 +(define_insn "mov<MOVCC:mode>cc_cmp<CMP:mode>"
14256 + [(set (match_operand:MOVCC 0 "register_operand" "=r,r,r")
14257 + (if_then_else:MOVCC (match_operator 1 "avr32_comparison_operator"
14258 + [(match_operand:CMP 4 "register_operand" "r,r,r")
14259 + (match_operand:CMP 5 "<CMP:cmp_predicate>" "<CMP:cmp_constraint>,<CMP:cmp_constraint>,<CMP:cmp_constraint>")])
14260 + (match_operand:MOVCC 2 "avr32_cond_register_immediate_operand" "0, rKs08,rKs08")
14261 + (match_operand:MOVCC 3 "avr32_cond_register_immediate_operand" "rKs08,0,rKs08")))]
14262 + ""
14263 + {
14264 + operands[1] = avr32_output_cmp(operands[1], GET_MODE(operands[4]), operands[4], operands[5]);
14265 +
14266 + switch( which_alternative ){
14267 + case 0:
14268 + return "mov%i1 %0, %3";
14269 + case 1:
14270 + return "mov%1 %0, %2";
14271 + case 2:
14272 + return "mov%1 %0, %2\;mov%i1 %0, %3";
14273 + default:
14274 + abort();
14275 + }
14276 +
14277 + }
14278 + [(set_attr "length" "8,8,12")
14279 + (set_attr "cc" "cmp_cond_insn")])
14280 +
14281 +
14282 +
14283 +
14284 +;;=============================================================================
14285 +;; jump
14286 +;;-----------------------------------------------------------------------------
14287 +;; Jump inside a function; an unconditional branch to a label.
14288 +;;=============================================================================
14289 +(define_insn "jump"
14290 + [(set (pc)
14291 + (label_ref (match_operand 0 "" "")))]
14292 + ""
14293 + {
14294 + if (get_attr_length(insn) > 4)
14295 + return "Can't jump this far";
14296 + return (get_attr_length(insn) == 2 ?
14297 + "rjmp %0" : "bral %0");
14298 + }
14299 + [(set_attr "type" "branch")
14300 + (set (attr "length")
14301 + (cond [(and (le (minus (match_dup 0) (pc)) (const_int 1022))
14302 + (le (minus (pc) (match_dup 0)) (const_int 1024)))
14303 + (const_int 2) ; use rjmp
14304 + (le (match_dup 0) (const_int 1048575))
14305 + (const_int 4)] ; use bral
14306 + (const_int 8))) ; do something else
14307 + (set_attr "cc" "none")])
14308 +
14309 +;;=============================================================================
14310 +;; call
14311 +;;-----------------------------------------------------------------------------
14312 +;; Subroutine call instruction returning no value.
14313 +;;=============================================================================
14314 +(define_insn "call_internal"
14315 + [(parallel [(call (mem:SI (match_operand:SI 0 "avr32_call_operand" "r,U,T,W"))
14316 + (match_operand 1 "" ""))
14317 + (clobber (reg:SI LR_REGNUM))])]
14318 + ""
14319 + {
14320 + switch (which_alternative){
14321 + case 0:
14322 + return "icall\t%0";
14323 + case 1:
14324 + return "rcall\t%0";
14325 + case 2:
14326 + return "mcall\t%0";
14327 + case 3:
14328 + if ( TARGET_HAS_ASM_ADDR_PSEUDOS )
14329 + return "call\t%0";
14330 + else
14331 + return "mcall\tr6[%0@got]";
14332 + default:
14333 + abort();
14334 + }
14335 + }
14336 + [(set_attr "type" "call")
14337 + (set_attr "length" "2,4,4,10")
14338 + (set_attr "cc" "clobber")])
14339 +
14340 +
14341 +(define_expand "call"
14342 + [(parallel [(call (match_operand:SI 0 "" "")
14343 + (match_operand 1 "" ""))
14344 + (clobber (reg:SI LR_REGNUM))])]
14345 + ""
14346 + {
14347 + rtx call_address;
14348 + if ( GET_CODE(operands[0]) != MEM )
14349 + FAIL;
14350 +
14351 + call_address = XEXP(operands[0], 0);
14352 +
14353 + /* If assembler supports call pseudo insn and the call
14354 + address is a symbol then nothing special needs to be done. */
14355 + if ( TARGET_HAS_ASM_ADDR_PSEUDOS
14356 + && (GET_CODE(call_address) == SYMBOL_REF) ){
14357 + /* We must however mark the function as using the GOT if
14358 + flag_pic is set, since the call insn might turn into
14359 + a mcall using the GOT ptr register. */
14360 + if ( flag_pic ){
14361 + current_function_uses_pic_offset_table = 1;
14362 + emit_call_insn(gen_call_internal(call_address, operands[1]));
14363 + DONE;
14364 + }
14365 + } else {
14366 + if ( flag_pic &&
14367 + GET_CODE(call_address) == SYMBOL_REF ){
14368 + current_function_uses_pic_offset_table = 1;
14369 + emit_call_insn(gen_call_internal(call_address, operands[1]));
14370 + DONE;
14371 + }
14372 +
14373 + if ( !SYMBOL_REF_RCALL_FUNCTION_P(operands[0]) ){
14374 + if ( optimize_size &&
14375 + GET_CODE(call_address) == SYMBOL_REF ){
14376 + call_address = force_const_mem(SImode, call_address);
14377 + } else {
14378 + call_address = force_reg(SImode, call_address);
14379 + }
14380 + }
14381 + }
14382 + emit_call_insn(gen_call_internal(call_address, operands[1]));
14383 + DONE;
14384 + }
14385 +)
14386 +
14387 +;;=============================================================================
14388 +;; call_value
14389 +;;-----------------------------------------------------------------------------
14390 +;; Subrutine call instruction returning a value.
14391 +;;=============================================================================
14392 +(define_expand "call_value"
14393 + [(parallel [(set (match_operand:SI 0 "" "")
14394 + (call (match_operand:SI 1 "" "")
14395 + (match_operand 2 "" "")))
14396 + (clobber (reg:SI LR_REGNUM))])]
14397 + ""
14398 + {
14399 + rtx call_address;
14400 + if ( GET_CODE(operands[1]) != MEM )
14401 + FAIL;
14402 +
14403 + call_address = XEXP(operands[1], 0);
14404 +
14405 + /* If assembler supports call pseudo insn and the call
14406 + address is a symbol then nothing special needs to be done. */
14407 + if ( TARGET_HAS_ASM_ADDR_PSEUDOS
14408 + && (GET_CODE(call_address) == SYMBOL_REF) ){
14409 + /* We must however mark the function as using the GOT if
14410 + flag_pic is set, since the call insn might turn into
14411 + a mcall using the GOT ptr register. */
14412 + if ( flag_pic ) {
14413 + current_function_uses_pic_offset_table = 1;
14414 + emit_call_insn(gen_call_value_internal(operands[0], call_address, operands[2]));
14415 + DONE;
14416 + }
14417 + } else {
14418 + if ( flag_pic &&
14419 + GET_CODE(call_address) == SYMBOL_REF ){
14420 + current_function_uses_pic_offset_table = 1;
14421 + emit_call_insn(gen_call_value_internal(operands[0], call_address, operands[2]));
14422 + DONE;
14423 + }
14424 +
14425 + if ( !SYMBOL_REF_RCALL_FUNCTION_P(operands[1]) ){
14426 + if ( optimize_size &&
14427 + GET_CODE(call_address) == SYMBOL_REF){
14428 + call_address = force_const_mem(SImode, call_address);
14429 + } else {
14430 + call_address = force_reg(SImode, call_address);
14431 + }
14432 + }
14433 + }
14434 + emit_call_insn(gen_call_value_internal(operands[0], call_address,
14435 + operands[2]));
14436 + DONE;
14437 +
14438 + })
14439 +
14440 +(define_insn "call_value_internal"
14441 + [(parallel [(set (match_operand 0 "register_operand" "=r,r,r,r")
14442 + (call (mem:SI (match_operand:SI 1 "avr32_call_operand" "r,U,T,W"))
14443 + (match_operand 2 "" "")))
14444 + (clobber (reg:SI LR_REGNUM))])]
14445 + ;; Operand 2 not used on the AVR32.
14446 + ""
14447 + {
14448 + switch (which_alternative){
14449 + case 0:
14450 + return "icall\t%1";
14451 + case 1:
14452 + return "rcall\t%1";
14453 + case 2:
14454 + return "mcall\t%1";
14455 + case 3:
14456 + if ( TARGET_HAS_ASM_ADDR_PSEUDOS )
14457 + return "call\t%1";
14458 + else
14459 + return "mcall\tr6[%1@got]";
14460 + default:
14461 + abort();
14462 + }
14463 + }
14464 + [(set_attr "type" "call")
14465 + (set_attr "length" "2,4,4,10")
14466 + (set_attr "cc" "call_set")])
14467 +
14468 +
14469 +;;=============================================================================
14470 +;; untyped_call
14471 +;;-----------------------------------------------------------------------------
14472 +;; Subrutine call instruction returning a value of any type.
14473 +;; The code is copied from m68k.md (except gen_blockage is removed)
14474 +;; Fixme!
14475 +;;=============================================================================
14476 +(define_expand "untyped_call"
14477 + [(parallel [(call (match_operand 0 "avr32_call_operand" "")
14478 + (const_int 0))
14479 + (match_operand 1 "" "")
14480 + (match_operand 2 "" "")])]
14481 + ""
14482 + {
14483 + int i;
14484 +
14485 + emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
14486 +
14487 + for (i = 0; i < XVECLEN (operands[2], 0); i++) {
14488 + rtx set = XVECEXP (operands[2], 0, i);
14489 + emit_move_insn (SET_DEST (set), SET_SRC (set));
14490 + }
14491 +
14492 + /* The optimizer does not know that the call sets the function value
14493 + registers we stored in the result block. We avoid problems by
14494 + claiming that all hard registers are used and clobbered at this
14495 + point. */
14496 + emit_insn (gen_blockage ());
14497 +
14498 + DONE;
14499 + })
14500 +
14501 +
14502 +;;=============================================================================
14503 +;; return
14504 +;;=============================================================================
14505 +
14506 +(define_insn "return"
14507 + [(return)]
14508 + "USE_RETURN_INSN (FALSE)"
14509 + {
14510 + avr32_output_return_instruction(TRUE, FALSE, NULL, NULL);
14511 + return "";
14512 + }
14513 + [(set_attr "length" "4")
14514 + (set_attr "type" "call")]
14515 + )
14516 +
14517 +
14518 +(define_insn "return_cond"
14519 + [(set (pc)
14520 + (if_then_else (match_operand 0 "avr32_comparison_operand" "")
14521 + (return)
14522 + (pc)))]
14523 + "USE_RETURN_INSN (TRUE)"
14524 + "ret%0\tr12";
14525 + [(set_attr "type" "call")])
14526 +
14527 +(define_insn "return_cond_predicable"
14528 + [(return)]
14529 + "USE_RETURN_INSN (TRUE)"
14530 + "ret%?\tr12";
14531 + [(set_attr "type" "call")
14532 + (set_attr "predicable" "yes")])
14533 +
14534 +
14535 +(define_insn "return_imm"
14536 + [(parallel [(set (reg RETVAL_REGNUM) (match_operand 0 "immediate_operand" "i"))
14537 + (use (reg RETVAL_REGNUM))
14538 + (return)])]
14539 + "USE_RETURN_INSN (FALSE) &&
14540 + ((INTVAL(operands[0]) == -1) || (INTVAL(operands[0]) == 0) || (INTVAL(operands[0]) == 1))"
14541 + {
14542 + avr32_output_return_instruction(TRUE, FALSE, NULL, operands[0]);
14543 + return "";
14544 + }
14545 + [(set_attr "length" "4")
14546 + (set_attr "type" "call")]
14547 + )
14548 +
14549 +(define_insn "return_imm_cond"
14550 + [(parallel [(set (reg RETVAL_REGNUM) (match_operand 0 "immediate_operand" "i"))
14551 + (use (reg RETVAL_REGNUM))
14552 + (set (pc)
14553 + (if_then_else (match_operand 1 "avr32_comparison_operand" "")
14554 + (return)
14555 + (pc)))])]
14556 + "USE_RETURN_INSN (TRUE) &&
14557 + ((INTVAL(operands[0]) == -1) || (INTVAL(operands[0]) == 0) || (INTVAL(operands[0]) == 1))"
14558 + "ret%1\t%0";
14559 + [(set_attr "type" "call")]
14560 + )
14561 +
14562 +(define_insn "return_imm_predicable"
14563 + [(parallel [(set (reg RETVAL_REGNUM) (match_operand 0 "immediate_operand" "i"))
14564 + (use (reg RETVAL_REGNUM))
14565 + (return)])]
14566 + "USE_RETURN_INSN (TRUE) &&
14567 + ((INTVAL(operands[0]) == -1) || (INTVAL(operands[0]) == 0) || (INTVAL(operands[0]) == 1))"
14568 + "ret%?\t%0";
14569 + [(set_attr "type" "call")
14570 + (set_attr "predicable" "yes")])
14571 +
14572 +(define_insn "return_<mode>reg"
14573 + [(set (reg RETVAL_REGNUM) (match_operand:MOVM 0 "register_operand" "r"))
14574 + (use (reg RETVAL_REGNUM))
14575 + (return)]
14576 + "USE_RETURN_INSN (TRUE)"
14577 + "ret%?\t%0";
14578 + [(set_attr "type" "call")
14579 + (set_attr "predicable" "yes")])
14580 +
14581 +(define_insn "return_<mode>reg_cond"
14582 + [(set (reg RETVAL_REGNUM) (match_operand:MOVM 0 "register_operand" "r"))
14583 + (use (reg RETVAL_REGNUM))
14584 + (set (pc)
14585 + (if_then_else (match_operator 1 "avr32_comparison_operator"
14586 + [(cc0) (const_int 0)])
14587 + (return)
14588 + (pc)))]
14589 + "USE_RETURN_INSN (TRUE)"
14590 + "ret%1\t%0";
14591 + [(set_attr "type" "call")])
14592 +
14593 +;;=============================================================================
14594 +;; nop
14595 +;;-----------------------------------------------------------------------------
14596 +;; No-op instruction.
14597 +;;=============================================================================
14598 +(define_insn "nop"
14599 + [(const_int 0)]
14600 + ""
14601 + "nop"
14602 + [(set_attr "length" "2")
14603 + (set_attr "type" "alu")
14604 + (set_attr "cc" "none")])
14605 +
14606 +;;=============================================================================
14607 +;; nonlocal_goto_receiver
14608 +;;-----------------------------------------------------------------------------
14609 +;; For targets with a return stack we must make sure to flush the return stack
14610 +;; since it will be corrupt after a nonlocal goto.
14611 +;;=============================================================================
14612 +(define_expand "nonlocal_goto_receiver"
14613 + [(const_int 0)]
14614 + "TARGET_RETURN_STACK"
14615 + "
14616 + {
14617 + emit_insn ( gen_frs() );
14618 + DONE;
14619 + }
14620 + "
14621 + )
14622 +
14623 +
14624 +;;=============================================================================
14625 +;; builtin_setjmp_receiver
14626 +;;-----------------------------------------------------------------------------
14627 +;; For pic code we need to reload the pic register.
14628 +;; For targets with a return stack we must make sure to flush the return stack
14629 +;; since it will probably be corrupted.
14630 +;;=============================================================================
14631 +(define_expand "builtin_setjmp_receiver"
14632 + [(label_ref (match_operand 0 "" ""))]
14633 + "flag_pic"
14634 + "
14635 + {
14636 + if ( TARGET_RETURN_STACK )
14637 + emit_insn ( gen_frs() );
14638 +
14639 + avr32_load_pic_register ();
14640 + DONE;
14641 + }
14642 + "
14643 +)
14644 +
14645 +
14646 +;;=============================================================================
14647 +;; indirect_jump
14648 +;;-----------------------------------------------------------------------------
14649 +;; Jump to an address in reg or memory.
14650 +;;=============================================================================
14651 +(define_expand "indirect_jump"
14652 + [(set (pc)
14653 + (match_operand:SI 0 "general_operand" ""))]
14654 + ""
14655 + {
14656 + /* One of the ops has to be in a register. */
14657 + if ( (flag_pic || TARGET_HAS_ASM_ADDR_PSEUDOS )
14658 + && !avr32_legitimate_pic_operand_p(operands[0]) )
14659 + operands[0] = legitimize_pic_address (operands[0], SImode, 0);
14660 + else if ( flag_pic && avr32_address_operand(operands[0], GET_MODE(operands[0])) )
14661 + /* If we have an address operand then this function uses the pic register. */
14662 + current_function_uses_pic_offset_table = 1;
14663 + })
14664 +
14665 +
14666 +(define_insn "indirect_jump_internal"
14667 + [(set (pc)
14668 + (match_operand:SI 0 "general_operand" "r,m,W"))]
14669 + ""
14670 + {
14671 + switch( which_alternative ){
14672 + case 0:
14673 + return "mov\tpc, %0";
14674 + case 1:
14675 + if ( avr32_const_pool_ref_operand(operands[0], GET_MODE(operands[0])) )
14676 + return "lddpc\tpc, %0";
14677 + else
14678 + return "ld.w\tpc, %0";
14679 + case 2:
14680 + if ( flag_pic )
14681 + return "ld.w\tpc, r6[%0@got]";
14682 + else
14683 + return "lda.w\tpc, %0";
14684 + default:
14685 + abort();
14686 + }
14687 + }
14688 + [(set_attr "length" "2,4,8")
14689 + (set_attr "type" "call,call,call")
14690 + (set_attr "cc" "none,none,clobber")])
14691 +
14692 +
14693 +
14694 +;;=============================================================================
14695 +;; casesi and tablejump
14696 +;;=============================================================================
14697 +(define_insn "tablejump_add"
14698 + [(set (pc)
14699 + (plus:SI (match_operand:SI 0 "register_operand" "r")
14700 + (mult:SI (match_operand:SI 1 "register_operand" "r")
14701 + (match_operand:SI 2 "immediate_operand" "Ku04" ))))
14702 + (use (label_ref (match_operand 3 "" "")))]
14703 + "flag_pic &&
14704 + ((INTVAL(operands[2]) == 0) || (INTVAL(operands[2]) == 2) ||
14705 + (INTVAL(operands[2]) == 4) || (INTVAL(operands[2]) == 8))"
14706 + "add\tpc, %0, %1 << %p2"
14707 + [(set_attr "length" "4")
14708 + (set_attr "cc" "clobber")])
14709 +
14710 +(define_insn "tablejump_insn"
14711 + [(set (pc) (match_operand:SI 0 "memory_operand" "m"))
14712 + (use (label_ref (match_operand 1 "" "")))]
14713 + "!flag_pic"
14714 + "ld.w\tpc, %0"
14715 + [(set_attr "length" "4")
14716 + (set_attr "type" "call")
14717 + (set_attr "cc" "none")])
14718 +
14719 +(define_expand "casesi"
14720 + [(match_operand:SI 0 "register_operand" "") ; index to jump on
14721 + (match_operand:SI 1 "const_int_operand" "") ; lower bound
14722 + (match_operand:SI 2 "const_int_operand" "") ; total range
14723 + (match_operand:SI 3 "" "") ; table label
14724 + (match_operand:SI 4 "" "")] ; Out of range label
14725 + ""
14726 + "
14727 + {
14728 + rtx reg;
14729 + rtx index = operands[0];
14730 + rtx low_bound = operands[1];
14731 + rtx range = operands[2];
14732 + rtx table_label = operands[3];
14733 + rtx oor_label = operands[4];
14734 +
14735 + index = force_reg ( SImode, index );
14736 + if (low_bound != const0_rtx)
14737 + {
14738 + if (!avr32_const_ok_for_constraint_p(INTVAL (low_bound), 'I', \"Is21\")){
14739 + reg = force_reg(SImode, GEN_INT (INTVAL (low_bound)));
14740 + emit_insn (gen_subsi3 (reg, index,
14741 + reg));
14742 + } else {
14743 + reg = gen_reg_rtx (SImode);
14744 + emit_insn (gen_addsi3 (reg, index,
14745 + GEN_INT (-INTVAL (low_bound))));
14746 + }
14747 + index = reg;
14748 + }
14749 +
14750 + if (!avr32_const_ok_for_constraint_p (INTVAL (range), 'K', \"Ks21\"))
14751 + range = force_reg (SImode, range);
14752 +
14753 + emit_cmp_and_jump_insns ( index, range, GTU, NULL_RTX, SImode, 1, oor_label );
14754 + reg = gen_reg_rtx (SImode);
14755 + emit_move_insn ( reg, gen_rtx_LABEL_REF (VOIDmode, table_label));
14756 +
14757 + if ( flag_pic )
14758 + emit_jump_insn ( gen_tablejump_add ( reg, index, GEN_INT(4), table_label));
14759 + else
14760 + emit_jump_insn (
14761 + gen_tablejump_insn ( gen_rtx_MEM ( SImode,
14762 + gen_rtx_PLUS ( SImode,
14763 + reg,
14764 + gen_rtx_MULT ( SImode,
14765 + index,
14766 + GEN_INT(4)))),
14767 + table_label));
14768 + DONE;
14769 + }"
14770 +)
14771 +
14772 +
14773 +
14774 +(define_insn "prefetch"
14775 + [(prefetch (match_operand:SI 0 "avr32_ks16_address_operand" "p")
14776 + (match_operand 1 "const_int_operand" "")
14777 + (match_operand 2 "const_int_operand" ""))]
14778 + ""
14779 + {
14780 + return "pref\t%0";
14781 + }
14782 +
14783 + [(set_attr "length" "4")
14784 + (set_attr "type" "load")
14785 + (set_attr "cc" "none")])
14786 +
14787 +
14788 +
14789 +;;=============================================================================
14790 +;; prologue
14791 +;;-----------------------------------------------------------------------------
14792 +;; This pattern, if defined, emits RTL for entry to a function. The function
14793 +;; entry i responsible for setting up the stack frame, initializing the frame
14794 +;; pointer register, saving callee saved registers, etc.
14795 +;;=============================================================================
14796 +(define_expand "prologue"
14797 + [(clobber (const_int 0))]
14798 + ""
14799 + "
14800 + avr32_expand_prologue();
14801 + DONE;
14802 + "
14803 + )
14804 +
14805 +;;=============================================================================
14806 +;; eh_return
14807 +;;-----------------------------------------------------------------------------
14808 +;; This pattern, if defined, affects the way __builtin_eh_return, and
14809 +;; thence the call frame exception handling library routines, are
14810 +;; built. It is intended to handle non-trivial actions needed along
14811 +;; the abnormal return path.
14812 +;;
14813 +;; The address of the exception handler to which the function should
14814 +;; return is passed as operand to this pattern. It will normally need
14815 +;; to copied by the pattern to some special register or memory
14816 +;; location. If the pattern needs to determine the location of the
14817 +;; target call frame in order to do so, it may use
14818 +;; EH_RETURN_STACKADJ_RTX, if defined; it will have already been
14819 +;; assigned.
14820 +;;
14821 +;; If this pattern is not defined, the default action will be to
14822 +;; simply copy the return address to EH_RETURN_HANDLER_RTX. Either
14823 +;; that macro or this pattern needs to be defined if call frame
14824 +;; exception handling is to be used.
14825 +
14826 +;; We can't expand this before we know where the link register is stored.
14827 +(define_insn_and_split "eh_return"
14828 + [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
14829 + VUNSPEC_EH_RETURN)
14830 + (clobber (match_scratch:SI 1 "=&r"))]
14831 + ""
14832 + "#"
14833 + "reload_completed"
14834 + [(const_int 0)]
14835 + "
14836 + {
14837 + avr32_set_return_address (operands[0], operands[1]);
14838 + DONE;
14839 + }"
14840 + )
14841 +
14842 +
14843 +;;=============================================================================
14844 +;; ffssi2
14845 +;;-----------------------------------------------------------------------------
14846 +(define_insn "ffssi2"
14847 + [ (set (match_operand:SI 0 "register_operand" "=r")
14848 + (ffs:SI (match_operand:SI 1 "register_operand" "r"))) ]
14849 + ""
14850 + "mov %0, %1
14851 + brev %0
14852 + clz %0, %0
14853 + sub %0, -1
14854 + cp %0, 33
14855 + moveq %0, 0"
14856 + [(set_attr "length" "18")
14857 + (set_attr "cc" "clobber")]
14858 + )
14859 +
14860 +
14861 +
14862 +;;=============================================================================
14863 +;; swap_h
14864 +;;-----------------------------------------------------------------------------
14865 +(define_insn "*swap_h"
14866 + [ (set (match_operand:SI 0 "register_operand" "=r")
14867 + (ior:SI (ashift:SI (match_dup 0) (const_int 16))
14868 + (lshiftrt:SI (match_dup 0) (const_int 16))))]
14869 + ""
14870 + "swap.h %0"
14871 + [(set_attr "length" "2")]
14872 + )
14873 +
14874 +(define_insn_and_split "bswap_16"
14875 + [ (set (match_operand:HI 0 "avr32_bswap_operand" "=r,RKs13,r")
14876 + (ior:HI (and:HI (lshiftrt:HI (match_operand:HI 1 "avr32_bswap_operand" "r,r,RKs13")
14877 + (const_int 8))
14878 + (const_int 255))
14879 + (ashift:HI (and:HI (match_dup 1)
14880 + (const_int 255))
14881 + (const_int 8))))]
14882 + ""
14883 + {
14884 + switch ( which_alternative ){
14885 + case 0:
14886 + if ( REGNO(operands[0]) == REGNO(operands[1]))
14887 + return "swap.bh\t%0";
14888 + else
14889 + return "mov\t%0, %1\;swap.bh\t%0";
14890 + case 1:
14891 + return "stswp.h\t%0, %1";
14892 + case 2:
14893 + return "ldswp.sh\t%0, %1";
14894 + default:
14895 + abort();
14896 + }
14897 + }
14898 +
14899 + "(reload_completed &&
14900 + REG_P(operands[0]) && REG_P(operands[1])
14901 + && (REGNO(operands[0]) != REGNO(operands[1])))"
14902 + [(set (match_dup 0) (match_dup 1))
14903 + (set (match_dup 0)
14904 + (ior:HI (and:HI (lshiftrt:HI (match_dup 0)
14905 + (const_int 8))
14906 + (const_int 255))
14907 + (ashift:HI (and:HI (match_dup 0)
14908 + (const_int 255))
14909 + (const_int 8))))]
14910 + ""
14911 +
14912 + [(set_attr "length" "4,4,4")
14913 + (set_attr "type" "alu,store,load_rm")]
14914 + )
14915 +
14916 +(define_insn_and_split "bswap_32"
14917 + [ (set (match_operand:SI 0 "avr32_bswap_operand" "=r,RKs14,r")
14918 + (ior:SI (ior:SI (lshiftrt:SI (and:SI (match_operand:SI 1 "avr32_bswap_operand" "r,r,RKs14")
14919 + (const_int -16777216))
14920 + (const_int 24))
14921 + (lshiftrt:SI (and:SI (match_dup 1)
14922 + (const_int 16711680))
14923 + (const_int 8)))
14924 + (ior:SI (ashift:SI (and:SI (match_dup 1)
14925 + (const_int 65280))
14926 + (const_int 8))
14927 + (ashift:SI (and:SI (match_dup 1)
14928 + (const_int 255))
14929 + (const_int 24)))))]
14930 + ""
14931 + {
14932 + switch ( which_alternative ){
14933 + case 0:
14934 + if ( REGNO(operands[0]) == REGNO(operands[1]))
14935 + return "swap.b\t%0";
14936 + else
14937 + return "#";
14938 + case 1:
14939 + return "stswp.w\t%0, %1";
14940 + case 2:
14941 + return "ldswp.w\t%0, %1";
14942 + default:
14943 + abort();
14944 + }
14945 + }
14946 + "(reload_completed &&
14947 + REG_P(operands[0]) && REG_P(operands[1])
14948 + && (REGNO(operands[0]) != REGNO(operands[1])))"
14949 + [(set (match_dup 0) (match_dup 1))
14950 + (set (match_dup 0)
14951 + (ior:SI (ior:SI (lshiftrt:SI (and:SI (match_dup 0)
14952 + (const_int -16777216))
14953 + (const_int 24))
14954 + (lshiftrt:SI (and:SI (match_dup 0)
14955 + (const_int 16711680))
14956 + (const_int 8)))
14957 + (ior:SI (ashift:SI (and:SI (match_dup 0)
14958 + (const_int 65280))
14959 + (const_int 8))
14960 + (ashift:SI (and:SI (match_dup 0)
14961 + (const_int 255))
14962 + (const_int 24)))))]
14963 + ""
14964 +
14965 + [(set_attr "length" "4,4,4")
14966 + (set_attr "type" "alu,store,load_rm")]
14967 + )
14968 +
14969 +
14970 +;;=============================================================================
14971 +;; blockage
14972 +;;-----------------------------------------------------------------------------
14973 +;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
14974 +;; all of memory. This blocks insns from being moved across this point.
14975 +
14976 +(define_insn "blockage"
14977 + [(unspec_volatile [(const_int 0)] VUNSPEC_BLOCKAGE)]
14978 + ""
14979 + ""
14980 + [(set_attr "length" "0")]
14981 +)
14982 +
14983 +;;=============================================================================
14984 +;; clzsi2
14985 +;;-----------------------------------------------------------------------------
14986 +(define_insn "clzsi2"
14987 + [ (set (match_operand:SI 0 "register_operand" "=r")
14988 + (clz:SI (match_operand:SI 1 "register_operand" "r"))) ]
14989 + ""
14990 + "clz %0, %1"
14991 + [(set_attr "length" "4")
14992 + (set_attr "cc" "set_z")]
14993 + )
14994 +
14995 +;;=============================================================================
14996 +;; ctzsi2
14997 +;;-----------------------------------------------------------------------------
14998 +(define_insn "ctzsi2"
14999 + [ (set (match_operand:SI 0 "register_operand" "=r,r")
15000 + (ctz:SI (match_operand:SI 1 "register_operand" "0,r"))) ]
15001 + ""
15002 + "@
15003 + brev\t%0\;clz\t%0, %0
15004 + mov\t%0, %1\;brev\t%0\;clz\t%0, %0"
15005 + [(set_attr "length" "8")
15006 + (set_attr "cc" "set_z")]
15007 + )
15008 +
15009 +;;=============================================================================
15010 +;; cache instructions
15011 +;;-----------------------------------------------------------------------------
15012 +(define_insn "cache"
15013 + [ (unspec_volatile [(match_operand:SI 0 "avr32_ks11_address_operand" "p")
15014 + (match_operand:SI 1 "immediate_operand" "Ku05")] VUNSPEC_CACHE)]
15015 + ""
15016 + "cache %0, %1"
15017 + [(set_attr "length" "4")]
15018 + )
15019 +
15020 +(define_insn "sync"
15021 + [ (unspec_volatile [(match_operand:SI 0 "immediate_operand" "Ku08")] VUNSPEC_SYNC)]
15022 + ""
15023 + "sync %0"
15024 + [(set_attr "length" "4")]
15025 + )
15026 +
15027 +;;=============================================================================
15028 +;; TLB instructions
15029 +;;-----------------------------------------------------------------------------
15030 +(define_insn "tlbr"
15031 + [ (unspec_volatile [(const_int 0)] VUNSPEC_TLBR)]
15032 + ""
15033 + "tlbr"
15034 + [(set_attr "length" "2")]
15035 + )
15036 +
15037 +(define_insn "tlbw"
15038 + [ (unspec_volatile [(const_int 0)] VUNSPEC_TLBW)]
15039 + ""
15040 + "tlbw"
15041 + [(set_attr "length" "2")]
15042 + )
15043 +
15044 +(define_insn "tlbs"
15045 + [ (unspec_volatile [(const_int 0)] VUNSPEC_TLBS)]
15046 + ""
15047 + "tlbs"
15048 + [(set_attr "length" "2")]
15049 + )
15050 +
15051 +;;=============================================================================
15052 +;; Breakpoint instruction
15053 +;;-----------------------------------------------------------------------------
15054 +(define_insn "breakpoint"
15055 + [ (unspec_volatile [(const_int 0)] VUNSPEC_BREAKPOINT)]
15056 + ""
15057 + "breakpoint"
15058 + [(set_attr "length" "2")]
15059 + )
15060 +
15061 +
15062 +;;=============================================================================
15063 +;; mtsr/mfsr instruction
15064 +;;-----------------------------------------------------------------------------
15065 +(define_insn "mtsr"
15066 + [ (unspec_volatile [(match_operand 0 "immediate_operand" "i")
15067 + (match_operand:SI 1 "register_operand" "r")] VUNSPEC_MTSR)]
15068 + ""
15069 + "mtsr\t%0, %1"
15070 + [(set_attr "length" "4")]
15071 + )
15072 +
15073 +(define_insn "mfsr"
15074 + [ (set (match_operand:SI 0 "register_operand" "=r")
15075 + (unspec_volatile:SI [(match_operand 1 "immediate_operand" "i")] VUNSPEC_MFSR)) ]
15076 + ""
15077 + "mfsr\t%0, %1"
15078 + [(set_attr "length" "4")]
15079 + )
15080 +
15081 +;;=============================================================================
15082 +;; mtdr/mfdr instruction
15083 +;;-----------------------------------------------------------------------------
15084 +(define_insn "mtdr"
15085 + [ (unspec_volatile [(match_operand 0 "immediate_operand" "i")
15086 + (match_operand:SI 1 "register_operand" "r")] VUNSPEC_MTDR)]
15087 + ""
15088 + "mtdr\t%0, %1"
15089 + [(set_attr "length" "4")]
15090 + )
15091 +
15092 +(define_insn "mfdr"
15093 + [ (set (match_operand:SI 0 "register_operand" "=r")
15094 + (unspec_volatile:SI [(match_operand 1 "immediate_operand" "i")] VUNSPEC_MFDR)) ]
15095 + ""
15096 + "mfdr\t%0, %1"
15097 + [(set_attr "length" "4")]
15098 + )
15099 +
15100 +;;=============================================================================
15101 +;; musfr
15102 +;;-----------------------------------------------------------------------------
15103 +(define_insn "musfr"
15104 + [ (unspec_volatile [(match_operand:SI 0 "register_operand" "r")] VUNSPEC_MUSFR)]
15105 + ""
15106 + "musfr\t%0"
15107 + [(set_attr "length" "2")
15108 + (set_attr "cc" "clobber")]
15109 + )
15110 +
15111 +(define_insn "mustr"
15112 + [ (set (match_operand:SI 0 "register_operand" "=r")
15113 + (unspec_volatile:SI [(const_int 0)] VUNSPEC_MUSTR)) ]
15114 + ""
15115 + "mustr\t%0"
15116 + [(set_attr "length" "2")]
15117 + )
15118 +
15119 +(define_insn "ssrf"
15120 + [ (unspec_volatile [(match_operand:SI 0 "immediate_operand" "Ku05")] VUNSPEC_SSRF)]
15121 + ""
15122 + "ssrf %0"
15123 + [(set_attr "length" "2")
15124 + (set_attr "cc" "clobber")]
15125 + )
15126 +
15127 +(define_insn "csrf"
15128 + [ (unspec_volatile [(match_operand:SI 0 "immediate_operand" "Ku05")] VUNSPEC_CSRF)]
15129 + ""
15130 + "csrf %0"
15131 + [(set_attr "length" "2")
15132 + (set_attr "cc" "clobber")]
15133 + )
15134 +
15135 +;;=============================================================================
15136 +;; Flush Return Stack instruction
15137 +;;-----------------------------------------------------------------------------
15138 +(define_insn "frs"
15139 + [ (unspec_volatile [(const_int 0)] VUNSPEC_FRS)]
15140 + ""
15141 + "frs"
15142 + [(set_attr "length" "2")
15143 + (set_attr "cc" "none")]
15144 + )
15145 +
15146 +
15147 +;;=============================================================================
15148 +;; Saturation Round Scale instruction
15149 +;;-----------------------------------------------------------------------------
15150 +(define_insn "sats"
15151 + [ (set (match_operand:SI 0 "register_operand" "+r")
15152 + (unspec:SI [(match_dup 0)
15153 + (match_operand 1 "immediate_operand" "Ku05")
15154 + (match_operand 2 "immediate_operand" "Ku05")]
15155 + UNSPEC_SATS)) ]
15156 + "TARGET_DSP"
15157 + "sats\t%0 >> %1, %2"
15158 + [(set_attr "type" "alu_sat")
15159 + (set_attr "length" "4")]
15160 + )
15161 +
15162 +(define_insn "satu"
15163 + [ (set (match_operand:SI 0 "register_operand" "+r")
15164 + (unspec:SI [(match_dup 0)
15165 + (match_operand 1 "immediate_operand" "Ku05")
15166 + (match_operand 2 "immediate_operand" "Ku05")]
15167 + UNSPEC_SATU)) ]
15168 + "TARGET_DSP"
15169 + "satu\t%0 >> %1, %2"
15170 + [(set_attr "type" "alu_sat")
15171 + (set_attr "length" "4")]
15172 + )
15173 +
15174 +(define_insn "satrnds"
15175 + [ (set (match_operand:SI 0 "register_operand" "+r")
15176 + (unspec:SI [(match_dup 0)
15177 + (match_operand 1 "immediate_operand" "Ku05")
15178 + (match_operand 2 "immediate_operand" "Ku05")]
15179 + UNSPEC_SATRNDS)) ]
15180 + "TARGET_DSP"
15181 + "satrnds\t%0 >> %1, %2"
15182 + [(set_attr "type" "alu_sat")
15183 + (set_attr "length" "4")]
15184 + )
15185 +
15186 +(define_insn "satrndu"
15187 + [ (set (match_operand:SI 0 "register_operand" "+r")
15188 + (unspec:SI [(match_dup 0)
15189 + (match_operand 1 "immediate_operand" "Ku05")
15190 + (match_operand 2 "immediate_operand" "Ku05")]
15191 + UNSPEC_SATRNDU)) ]
15192 + "TARGET_DSP"
15193 + "sats\t%0 >> %1, %2"
15194 + [(set_attr "type" "alu_sat")
15195 + (set_attr "length" "4")]
15196 + )
15197 +
15198 +;; Special patterns for dealing with the constant pool
15199 +
15200 +(define_insn "align_4"
15201 + [(unspec_volatile [(const_int 0)] VUNSPEC_ALIGN)]
15202 + ""
15203 + {
15204 + assemble_align (32);
15205 + return "";
15206 + }
15207 + [(set_attr "length" "2")]
15208 +)
15209 +
15210 +(define_insn "consttable_start"
15211 + [(unspec_volatile [(const_int 0)] VUNSPEC_POOL_START)]
15212 + ""
15213 + {
15214 + return ".cpool";
15215 + }
15216 + [(set_attr "length" "0")]
15217 + )
15218 +
15219 +(define_insn "consttable_end"
15220 + [(unspec_volatile [(const_int 0)] VUNSPEC_POOL_END)]
15221 + ""
15222 + {
15223 + making_const_table = FALSE;
15224 + return "";
15225 + }
15226 + [(set_attr "length" "0")]
15227 +)
15228 +
15229 +
15230 +(define_insn "consttable_4"
15231 + [(unspec_volatile [(match_operand 0 "" "")] VUNSPEC_POOL_4)]
15232 + ""
15233 + {
15234 + making_const_table = TRUE;
15235 + switch (GET_MODE_CLASS (GET_MODE (operands[0])))
15236 + {
15237 + case MODE_FLOAT:
15238 + {
15239 + REAL_VALUE_TYPE r;
15240 + char real_string[1024];
15241 + REAL_VALUE_FROM_CONST_DOUBLE (r, operands[0]);
15242 + real_to_decimal(real_string, &r, 1024, 0, 1);
15243 + asm_fprintf (asm_out_file, "\t.float\t%s\n", real_string);
15244 + break;
15245 + }
15246 + default:
15247 + assemble_integer (operands[0], 4, 0, 1);
15248 + break;
15249 + }
15250 + return "";
15251 + }
15252 + [(set_attr "length" "4")]
15253 +)
15254 +
15255 +(define_insn "consttable_8"
15256 + [(unspec_volatile [(match_operand 0 "" "")] VUNSPEC_POOL_8)]
15257 + ""
15258 + {
15259 + making_const_table = TRUE;
15260 + switch (GET_MODE_CLASS (GET_MODE (operands[0])))
15261 + {
15262 + case MODE_FLOAT:
15263 + {
15264 + REAL_VALUE_TYPE r;
15265 + char real_string[1024];
15266 + REAL_VALUE_FROM_CONST_DOUBLE (r, operands[0]);
15267 + real_to_decimal(real_string, &r, 1024, 0, 1);
15268 + asm_fprintf (asm_out_file, "\t.double\t%s\n", real_string);
15269 + break;
15270 + }
15271 + default:
15272 + assemble_integer(operands[0], 8, 0, 1);
15273 + break;
15274 + }
15275 + return "";
15276 + }
15277 + [(set_attr "length" "8")]
15278 +)
15279 +
15280 +(define_insn "consttable_16"
15281 + [(unspec_volatile [(match_operand 0 "" "")] VUNSPEC_POOL_16)]
15282 + ""
15283 + {
15284 + making_const_table = TRUE;
15285 + assemble_integer(operands[0], 16, 0, 1);
15286 + return "";
15287 + }
15288 + [(set_attr "length" "16")]
15289 +)
15290 +
15291 +;;=============================================================================
15292 +;; coprocessor instructions
15293 +;;-----------------------------------------------------------------------------
15294 +(define_insn "cop"
15295 + [ (unspec_volatile [(match_operand 0 "immediate_operand" "Ku03")
15296 + (match_operand 1 "immediate_operand" "Ku04")
15297 + (match_operand 2 "immediate_operand" "Ku04")
15298 + (match_operand 3 "immediate_operand" "Ku04")
15299 + (match_operand 4 "immediate_operand" "Ku07")] VUNSPEC_COP)]
15300 + ""
15301 + "cop\tcp%0, cr%1, cr%2, cr%3, %4"
15302 + [(set_attr "length" "4")]
15303 + )
15304 +
15305 +(define_insn "mvcrsi"
15306 + [ (set (match_operand:SI 0 "avr32_cop_move_operand" "=r,<,Z")
15307 + (unspec_volatile:SI [(match_operand 1 "immediate_operand" "Ku03,Ku03,Ku03")
15308 + (match_operand 2 "immediate_operand" "Ku04,Ku04,Ku04")]
15309 + VUNSPEC_MVCR)) ]
15310 + ""
15311 + "@
15312 + mvcr.w\tcp%1, %0, cr%2
15313 + stcm.w\tcp%1, %0, cr%2
15314 + stc.w\tcp%1, %0, cr%2"
15315 + [(set_attr "length" "4")]
15316 + )
15317 +
15318 +(define_insn "mvcrdi"
15319 + [ (set (match_operand:DI 0 "avr32_cop_move_operand" "=r,<,Z")
15320 + (unspec_volatile:DI [(match_operand 1 "immediate_operand" "Ku03,Ku03,Ku03")
15321 + (match_operand 2 "immediate_operand" "Ku04,Ku04,Ku04")]
15322 + VUNSPEC_MVCR)) ]
15323 + ""
15324 + "@
15325 + mvcr.d\tcp%1, %0, cr%2
15326 + stcm.d\tcp%1, %0, cr%2-cr%i2
15327 + stc.d\tcp%1, %0, cr%2"
15328 + [(set_attr "length" "4")]
15329 + )
15330 +
15331 +(define_insn "mvrcsi"
15332 + [ (unspec_volatile:SI [(match_operand 0 "immediate_operand" "Ku03,Ku03,Ku03")
15333 + (match_operand 1 "immediate_operand" "Ku04,Ku04,Ku04")
15334 + (match_operand:SI 2 "avr32_cop_move_operand" "r,>,Z")]
15335 + VUNSPEC_MVRC)]
15336 + ""
15337 + {
15338 + switch (which_alternative){
15339 + case 0:
15340 + return "mvrc.w\tcp%0, cr%1, %2";
15341 + case 1:
15342 + return "ldcm.w\tcp%0, %2, cr%1";
15343 + case 2:
15344 + return "ldc.w\tcp%0, cr%1, %2";
15345 + default:
15346 + abort();
15347 + }
15348 + }
15349 + [(set_attr "length" "4")]
15350 + )
15351 +
15352 +(define_insn "mvrcdi"
15353 + [ (unspec_volatile:DI [(match_operand 0 "immediate_operand" "Ku03,Ku03,Ku03")
15354 + (match_operand 1 "immediate_operand" "Ku04,Ku04,Ku04")
15355 + (match_operand:DI 2 "avr32_cop_move_operand" "r,>,Z")]
15356 + VUNSPEC_MVRC)]
15357 + ""
15358 + {
15359 + switch (which_alternative){
15360 + case 0:
15361 + return "mvrc.d\tcp%0, cr%1, %2";
15362 + case 1:
15363 + return "ldcm.d\tcp%0, %2, cr%1-cr%i1";
15364 + case 2:
15365 + return "ldc.d\tcp%0, cr%1, %2";
15366 + default:
15367 + abort();
15368 + }
15369 + }
15370 + [(set_attr "length" "4")]
15371 + )
15372 +
15373 +;;=============================================================================
15374 +;; epilogue
15375 +;;-----------------------------------------------------------------------------
15376 +;; This pattern emits RTL for exit from a function. The function exit is
15377 +;; responsible for deallocating the stack frame, restoring callee saved
15378 +;; registers and emitting the return instruction.
15379 +;; ToDo: using TARGET_ASM_FUNCTION_PROLOGUE instead.
15380 +;;=============================================================================
15381 +(define_expand "epilogue"
15382 + [(unspec_volatile [(return)] VUNSPEC_EPILOGUE)]
15383 + ""
15384 + "
15385 + if (USE_RETURN_INSN (FALSE)){
15386 + emit_jump_insn (gen_return ());
15387 + DONE;
15388 + }
15389 + emit_jump_insn (gen_rtx_UNSPEC_VOLATILE (VOIDmode,
15390 + gen_rtvec (1,
15391 + gen_rtx_RETURN (VOIDmode)),
15392 + VUNSPEC_EPILOGUE));
15393 + DONE;
15394 + "
15395 + )
15396 +
15397 +(define_insn "*epilogue_insns"
15398 + [(unspec_volatile [(return)] VUNSPEC_EPILOGUE)]
15399 + ""
15400 + {
15401 + avr32_output_return_instruction (FALSE, FALSE, NULL, NULL);
15402 + return "";
15403 + }
15404 + ; Length is absolute worst case
15405 + [(set_attr "type" "branch")
15406 + (set_attr "length" "12")]
15407 + )
15408 +
15409 +(define_insn "*epilogue_insns_ret_imm"
15410 + [(parallel [(set (reg RETVAL_REGNUM) (match_operand 0 "immediate_operand" "i"))
15411 + (use (reg RETVAL_REGNUM))
15412 + (unspec_volatile [(return)] VUNSPEC_EPILOGUE)])]
15413 + "((INTVAL(operands[0]) == -1) || (INTVAL(operands[0]) == 0) || (INTVAL(operands[0]) == 1))"
15414 + {
15415 + avr32_output_return_instruction (FALSE, FALSE, NULL, operands[0]);
15416 + return "";
15417 + }
15418 + ; Length is absolute worst case
15419 + [(set_attr "type" "branch")
15420 + (set_attr "length" "12")]
15421 + )
15422 +
15423 +(define_insn "sibcall_epilogue"
15424 + [(unspec_volatile [(const_int 0)] VUNSPEC_EPILOGUE)]
15425 + ""
15426 + {
15427 + avr32_output_return_instruction (FALSE, FALSE, NULL, NULL);
15428 + return "";
15429 + }
15430 +;; Length is absolute worst case
15431 + [(set_attr "type" "branch")
15432 + (set_attr "length" "12")]
15433 + )
15434 +
15435 +(define_insn "*sibcall_epilogue_insns_ret_imm"
15436 + [(parallel [(set (reg RETVAL_REGNUM) (match_operand 0 "immediate_operand" "i"))
15437 + (use (reg RETVAL_REGNUM))
15438 + (unspec_volatile [(const_int 0)] VUNSPEC_EPILOGUE)])]
15439 + "((INTVAL(operands[0]) == -1) || (INTVAL(operands[0]) == 0) || (INTVAL(operands[0]) == 1))"
15440 + {
15441 + avr32_output_return_instruction (FALSE, FALSE, NULL, operands[0]);
15442 + return "";
15443 + }
15444 + ; Length is absolute worst case
15445 + [(set_attr "type" "branch")
15446 + (set_attr "length" "12")]
15447 + )
15448 +
15449 +(define_insn "ldxi"
15450 + [(set (match_operand:SI 0 "register_operand" "=r")
15451 + (mem:SI (plus:SI
15452 + (match_operand:SI 1 "register_operand" "r")
15453 + (mult:SI (zero_extract:SI (match_operand:SI 2 "register_operand" "r")
15454 + (const_int 8)
15455 + (match_operand:SI 3 "immediate_operand" "Ku05"))
15456 + (const_int 4)))))]
15457 + "(INTVAL(operands[3]) == 24 || INTVAL(operands[3]) == 16 || INTVAL(operands[3]) == 8
15458 + || INTVAL(operands[3]) == 0)"
15459 + {
15460 + switch ( INTVAL(operands[3]) ){
15461 + case 0:
15462 + return "ld.w %0, %1[%2:b << 2]";
15463 + case 8:
15464 + return "ld.w %0, %1[%2:l << 2]";
15465 + case 16:
15466 + return "ld.w %0, %1[%2:u << 2]";
15467 + case 24:
15468 + return "ld.w %0, %1[%2:t << 2]";
15469 + default:
15470 + internal_error("illegal operand for ldxi");
15471 + }
15472 + }
15473 + [(set_attr "type" "load")
15474 + (set_attr "length" "4")
15475 + (set_attr "cc" "none")])
15476 +
15477 +
15478 +
15479 +
15480 +
15481 +
15482 +;;=============================================================================
15483 +;; Peephole optimizing
15484 +;;-----------------------------------------------------------------------------
15485 +;; Changing
15486 +;; sub r8, r7, 8
15487 +;; st.w r8[0x0], r12
15488 +;; to
15489 +;; sub r8, r7, 8
15490 +;; st.w r7[-0x8], r12
15491 +;;=============================================================================
15492 +; (set (reg:SI 9 r8)
15493 +; (plus:SI (reg/f:SI 6 r7)
15494 +; (const_int ...)))
15495 +; (set (mem:SI (reg:SI 9 r8))
15496 +; (reg:SI 12 r12))
15497 +(define_peephole2
15498 + [(set (match_operand:SI 0 "register_operand" "")
15499 + (plus:SI (match_operand:SI 1 "register_operand" "")
15500 + (match_operand:SI 2 "immediate_operand" "")))
15501 + (set (mem:SI (match_dup 0))
15502 + (match_operand:SI 3 "register_operand" ""))]
15503 + "REGNO(operands[0]) != REGNO(operands[1]) && avr32_const_ok_for_constraint_p(INTVAL(operands[2]), 'K', \"Ks16\")"
15504 + [(set (match_dup 0)
15505 + (plus:SI (match_dup 1)
15506 + (match_dup 2)))
15507 + (set (mem:SI (plus:SI (match_dup 1)
15508 + (match_dup 2)))
15509 + (match_dup 3))]
15510 + "")
15511 +
15512 +;;=============================================================================
15513 +;; Peephole optimizing
15514 +;;-----------------------------------------------------------------------------
15515 +;; Changing
15516 +;; sub r6, r7, 4
15517 +;; ld.w r6, r6[0x0]
15518 +;; to
15519 +;; sub r6, r7, 4
15520 +;; ld.w r6, r7[-0x4]
15521 +;;=============================================================================
15522 +; (set (reg:SI 7 r6)
15523 +; (plus:SI (reg/f:SI 6 r7)
15524 +; (const_int -4 [0xfffffffc])))
15525 +; (set (reg:SI 7 r6)
15526 +; (mem:SI (reg:SI 7 r6)))
15527 +(define_peephole2
15528 + [(set (match_operand:SI 0 "register_operand" "")
15529 + (plus:SI (match_operand:SI 1 "register_operand" "")
15530 + (match_operand:SI 2 "immediate_operand" "")))
15531 + (set (match_operand:SI 3 "register_operand" "")
15532 + (mem:SI (match_dup 0)))]
15533 + "REGNO(operands[0]) != REGNO(operands[1]) && avr32_const_ok_for_constraint_p(INTVAL(operands[2]), 'K', \"Ks16\")"
15534 + [(set (match_dup 0)
15535 + (plus:SI (match_dup 1)
15536 + (match_dup 2)))
15537 + (set (match_dup 3)
15538 + (mem:SI (plus:SI (match_dup 1)
15539 + (match_dup 2))))]
15540 + "")
15541 +
15542 +;;=============================================================================
15543 +;; Peephole optimizing
15544 +;;-----------------------------------------------------------------------------
15545 +;; Changing
15546 +;; ld.sb r0, r7[-0x6]
15547 +;; cashs.b r0
15548 +;; to
15549 +;; ld.sb r0, r7[-0x6]
15550 +;;=============================================================================
15551 +(define_peephole2
15552 + [(set (match_operand:QI 0 "register_operand" "")
15553 + (match_operand:QI 1 "load_sb_memory_operand" ""))
15554 + (set (match_operand:SI 2 "register_operand" "")
15555 + (sign_extend:SI (match_dup 0)))]
15556 + "(REGNO(operands[0]) == REGNO(operands[2]) || peep2_reg_dead_p(2, operands[0]))"
15557 + [(set (match_dup 2)
15558 + (sign_extend:SI (match_dup 1)))]
15559 + "")
15560 +
15561 +;;=============================================================================
15562 +;; Peephole optimizing
15563 +;;-----------------------------------------------------------------------------
15564 +;; Changing
15565 +;; ld.ub r0, r7[-0x6]
15566 +;; cashu.b r0
15567 +;; to
15568 +;; ld.ub r0, r7[-0x6]
15569 +;;=============================================================================
15570 +(define_peephole2
15571 + [(set (match_operand:QI 0 "register_operand" "")
15572 + (match_operand:QI 1 "memory_operand" ""))
15573 + (set (match_operand:SI 2 "register_operand" "")
15574 + (zero_extend:SI (match_dup 0)))]
15575 + "(REGNO(operands[0]) == REGNO(operands[2])) || peep2_reg_dead_p(2, operands[0])"
15576 + [(set (match_dup 2)
15577 + (zero_extend:SI (match_dup 1)))]
15578 + "")
15579 +
15580 +;;=============================================================================
15581 +;; Peephole optimizing
15582 +;;-----------------------------------------------------------------------------
15583 +;; Changing
15584 +;; ld.sh r0, r7[-0x6]
15585 +;; casts.h r0
15586 +;; to
15587 +;; ld.sh r0, r7[-0x6]
15588 +;;=============================================================================
15589 +(define_peephole2
15590 + [(set (match_operand:HI 0 "register_operand" "")
15591 + (match_operand:HI 1 "memory_operand" ""))
15592 + (set (match_operand:SI 2 "register_operand" "")
15593 + (sign_extend:SI (match_dup 0)))]
15594 + "(REGNO(operands[0]) == REGNO(operands[2])) || peep2_reg_dead_p(2, operands[0])"
15595 + [(set (match_dup 2)
15596 + (sign_extend:SI (match_dup 1)))]
15597 + "")
15598 +
15599 +;;=============================================================================
15600 +;; Peephole optimizing
15601 +;;-----------------------------------------------------------------------------
15602 +;; Changing
15603 +;; ld.uh r0, r7[-0x6]
15604 +;; castu.h r0
15605 +;; to
15606 +;; ld.uh r0, r7[-0x6]
15607 +;;=============================================================================
15608 +(define_peephole2
15609 + [(set (match_operand:HI 0 "register_operand" "")
15610 + (match_operand:HI 1 "memory_operand" ""))
15611 + (set (match_operand:SI 2 "register_operand" "")
15612 + (zero_extend:SI (match_dup 0)))]
15613 + "(REGNO(operands[0]) == REGNO(operands[2])) || peep2_reg_dead_p(2, operands[0])"
15614 + [(set (match_dup 2)
15615 + (zero_extend:SI (match_dup 1)))]
15616 + "")
15617 +
15618 +;;=============================================================================
15619 +;; Peephole optimizing
15620 +;;-----------------------------------------------------------------------------
15621 +;; Changing
15622 +;; mul rd, rx, ry
15623 +;; add rd2, rd
15624 +;; or
15625 +;; add rd2, rd, rd2
15626 +;; to
15627 +;; mac rd2, rx, ry
15628 +;;=============================================================================
15629 +(define_peephole2
15630 + [(set (match_operand:SI 0 "register_operand" "")
15631 + (mult:SI (match_operand:SI 1 "register_operand" "")
15632 + (match_operand:SI 2 "register_operand" "")))
15633 + (set (match_operand:SI 3 "register_operand" "")
15634 + (plus:SI (match_dup 3)
15635 + (match_dup 0)))]
15636 + "peep2_reg_dead_p(2, operands[0])"
15637 + [(set (match_dup 3)
15638 + (plus:SI (mult:SI (match_dup 1)
15639 + (match_dup 2))
15640 + (match_dup 3)))]
15641 + "")
15642 +
15643 +(define_peephole2
15644 + [(set (match_operand:SI 0 "register_operand" "")
15645 + (mult:SI (match_operand:SI 1 "register_operand" "")
15646 + (match_operand:SI 2 "register_operand" "")))
15647 + (set (match_operand:SI 3 "register_operand" "")
15648 + (plus:SI (match_dup 0)
15649 + (match_dup 3)))]
15650 + "peep2_reg_dead_p(2, operands[0])"
15651 + [(set (match_dup 3)
15652 + (plus:SI (mult:SI (match_dup 1)
15653 + (match_dup 2))
15654 + (match_dup 3)))]
15655 + "")
15656 +
15657 +
15658 +;;=============================================================================
15659 +;; Peephole optimizing
15660 +;;-----------------------------------------------------------------------------
15661 +;; Changing
15662 +;; bfextu rd, rs, k5, 1 or and(h/l) rd, one_bit_set_mask
15663 +;; to
15664 +;; bld rs, k5
15665 +;;
15666 +;; If rd is dead after the operation.
15667 +;;=============================================================================
15668 +(define_peephole2
15669 + [ (set (match_operand:SI 0 "register_operand" "")
15670 + (zero_extract:SI (match_operand:SI 1 "register_operand" "")
15671 + (const_int 1)
15672 + (match_operand:SI 2 "immediate_operand" "")))
15673 + (set (cc0)
15674 + (match_dup 0))]
15675 + "peep2_reg_dead_p(2, operands[0])"
15676 + [(set (cc0)
15677 + (and:SI (match_dup 1)
15678 + (match_dup 2)))]
15679 + "operands[2] = GEN_INT(1 << INTVAL(operands[2]));")
15680 +
15681 +(define_peephole2
15682 + [ (set (match_operand:SI 0 "register_operand" "")
15683 + (and:SI (match_operand:SI 1 "register_operand" "")
15684 + (match_operand:SI 2 "one_bit_set_operand" "")))
15685 + (set (cc0)
15686 + (match_dup 0))]
15687 + "peep2_reg_dead_p(2, operands[0])"
15688 + [(set (cc0)
15689 + (and:SI (match_dup 1)
15690 + (match_dup 2)))]
15691 + "")
15692 +
15693 +;;=============================================================================
15694 +;; Peephole optimizing
15695 +;;-----------------------------------------------------------------------------
15696 +;; Load with extracted index: ld.w Rd, Rb[Ri:{t/u/b/l} << 2]
15697 +;;
15698 +;;=============================================================================
15699 +
15700 +
15701 +(define_peephole
15702 + [(set (match_operand:SI 0 "register_operand" "")
15703 + (zero_extract:SI (match_operand:SI 1 "register_operand" "")
15704 + (const_int 8)
15705 + (match_operand:SI 2 "avr32_extract_shift_operand" "")))
15706 + (set (match_operand:SI 3 "register_operand" "")
15707 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15708 + (match_operand:SI 4 "register_operand" ""))))]
15709 +
15710 + "(dead_or_set_p(insn, operands[0]))"
15711 + {
15712 + switch ( INTVAL(operands[2]) ){
15713 + case 0:
15714 + return "ld.w %3, %4[%1:b << 2]";
15715 + case 8:
15716 + return "ld.w %3, %4[%1:l << 2]";
15717 + case 16:
15718 + return "ld.w %3, %4[%1:u << 2]";
15719 + case 24:
15720 + return "ld.w %3, %4[%1:t << 2]";
15721 + default:
15722 + internal_error("illegal operand for ldxi");
15723 + }
15724 + }
15725 + [(set_attr "type" "load")
15726 + (set_attr "length" "4")
15727 + (set_attr "cc" "clobber")]
15728 + )
15729 +
15730 +
15731 +
15732 +(define_peephole
15733 + [(set (match_operand:SI 0 "register_operand" "")
15734 + (and:SI (match_operand:SI 1 "register_operand" "") (const_int 255)))
15735 + (set (match_operand:SI 2 "register_operand" "")
15736 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15737 + (match_operand:SI 3 "register_operand" ""))))]
15738 +
15739 + "(dead_or_set_p(insn, operands[0]))"
15740 +
15741 + "ld.w %2, %3[%1:b << 2]"
15742 + [(set_attr "type" "load")
15743 + (set_attr "length" "4")
15744 + (set_attr "cc" "clobber")]
15745 + )
15746 +
15747 +
15748 +(define_peephole2
15749 + [(set (match_operand:SI 0 "register_operand" "")
15750 + (zero_extract:SI (match_operand:SI 1 "register_operand" "")
15751 + (const_int 8)
15752 + (match_operand:SI 2 "avr32_extract_shift_operand" "")))
15753 + (set (match_operand:SI 3 "register_operand" "")
15754 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15755 + (match_operand:SI 4 "register_operand" ""))))]
15756 +
15757 + "(peep2_reg_dead_p(2, operands[0]))
15758 + || (REGNO(operands[0]) == REGNO(operands[3]))"
15759 + [(set (match_dup 3)
15760 + (mem:SI (plus:SI
15761 + (match_dup 4)
15762 + (mult:SI (zero_extract:SI (match_dup 1)
15763 + (const_int 8)
15764 + (match_dup 2))
15765 + (const_int 4)))))]
15766 + )
15767 +
15768 +(define_peephole2
15769 + [(set (match_operand:SI 0 "register_operand" "")
15770 + (zero_extend:SI (match_operand:QI 1 "register_operand" "")))
15771 + (set (match_operand:SI 2 "register_operand" "")
15772 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15773 + (match_operand:SI 3 "register_operand" ""))))]
15774 +
15775 + "(peep2_reg_dead_p(2, operands[0]))
15776 + || (REGNO(operands[0]) == REGNO(operands[2]))"
15777 + [(set (match_dup 2)
15778 + (mem:SI (plus:SI
15779 + (match_dup 3)
15780 + (mult:SI (zero_extract:SI (match_dup 1)
15781 + (const_int 8)
15782 + (const_int 0))
15783 + (const_int 4)))))]
15784 + "operands[1] = gen_rtx_REG(SImode, REGNO(operands[1]));"
15785 + )
15786 +
15787 +
15788 +(define_peephole2
15789 + [(set (match_operand:SI 0 "register_operand" "")
15790 + (and:SI (match_operand:SI 1 "register_operand" "")
15791 + (const_int 255)))
15792 + (set (match_operand:SI 2 "register_operand" "")
15793 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15794 + (match_operand:SI 3 "register_operand" ""))))]
15795 +
15796 + "(peep2_reg_dead_p(2, operands[0]))
15797 + || (REGNO(operands[0]) == REGNO(operands[2]))"
15798 + [(set (match_dup 2)
15799 + (mem:SI (plus:SI
15800 + (match_dup 3)
15801 + (mult:SI (zero_extract:SI (match_dup 1)
15802 + (const_int 8)
15803 + (const_int 0))
15804 + (const_int 4)))))]
15805 + ""
15806 + )
15807 +
15808 +
15809 +
15810 +(define_peephole2
15811 + [(set (match_operand:SI 0 "register_operand" "")
15812 + (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
15813 + (const_int 24)))
15814 + (set (match_operand:SI 2 "register_operand" "")
15815 + (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
15816 + (match_operand:SI 3 "register_operand" ""))))]
15817 +
15818 + "(peep2_reg_dead_p(2, operands[0]))
15819 + || (REGNO(operands[0]) == REGNO(operands[2]))"
15820 + [(set (match_dup 2)
15821 + (mem:SI (plus:SI
15822 + (match_dup 3)
15823 + (mult:SI (zero_extract:SI (match_dup 1)
15824 + (const_int 8)
15825 + (const_int 24))
15826 + (const_int 4)))))]
15827 + ""
15828 + )
15829 +
15830 +
15831 +;;************************************************
15832 +;; ANDN
15833 +;;
15834 +;;************************************************
15835 +
15836 +
15837 +(define_peephole2
15838 + [(set (match_operand:SI 0 "register_operand" "")
15839 + (not:SI (match_operand:SI 1 "register_operand" "")))
15840 + (set (match_operand:SI 2 "register_operand" "")
15841 + (and:SI (match_dup 2)
15842 + (match_dup 0)))]
15843 + "peep2_reg_dead_p(2, operands[0])"
15844 +
15845 + [(set (match_dup 2)
15846 + (and:SI (match_dup 2)
15847 + (not:SI (match_dup 1))
15848 + ))]
15849 + ""
15850 +)
15851 +
15852 +(define_peephole2
15853 + [(set (match_operand:SI 0 "register_operand" "")
15854 + (not:SI (match_operand:SI 1 "register_operand" "")))
15855 + (set (match_operand:SI 2 "register_operand" "")
15856 + (and:SI (match_dup 0)
15857 + (match_dup 2)
15858 + ))]
15859 + "peep2_reg_dead_p(2, operands[0])"
15860 +
15861 + [(set (match_dup 2)
15862 + (and:SI (match_dup 2)
15863 + (not:SI (match_dup 1))
15864 + ))]
15865 +
15866 + ""
15867 +)
15868 +
15869 +
15870 +;;=================================================================
15871 +;; Addabs peephole
15872 +;;=================================================================
15873 +
15874 +(define_peephole
15875 + [(set (match_operand:SI 2 "register_operand" "=r")
15876 + (abs:SI (match_operand:SI 1 "register_operand" "r")))
15877 + (set (match_operand:SI 0 "register_operand" "=r")
15878 + (plus:SI (match_operand:SI 3 "register_operand" "r")
15879 + (match_dup 2)))]
15880 + "dead_or_set_p(insn, operands[2])"
15881 + "addabs %0, %3, %1"
15882 + [(set_attr "length" "4")
15883 + (set_attr "cc" "set_z")])
15884 +
15885 +(define_peephole
15886 + [(set (match_operand:SI 2 "register_operand" "=r")
15887 + (abs:SI (match_operand:SI 1 "register_operand" "r")))
15888 + (set (match_operand:SI 0 "register_operand" "=r")
15889 + (plus:SI (match_dup 2)
15890 + (match_operand:SI 3 "register_operand" "r")))]
15891 + "dead_or_set_p(insn, operands[2])"
15892 + "addabs %0, %3, %1"
15893 + [(set_attr "length" "4")
15894 + (set_attr "cc" "set_z")])
15895 +
15896 +
15897 +;;=================================================================
15898 +;; Detect roundings
15899 +;;=================================================================
15900 +
15901 +(define_insn "*round"
15902 + [(set (match_operand:SI 0 "register_operand" "+r")
15903 + (ashiftrt:SI (plus:SI (match_dup 0)
15904 + (match_operand:SI 1 "immediate_operand" "i"))
15905 + (match_operand:SI 2 "immediate_operand" "i")))]
15906 + "avr32_rnd_operands(operands[1], operands[2])"
15907 +
15908 + "satrnds %0 >> %2, 31"
15909 +
15910 + [(set_attr "type" "alu_sat")
15911 + (set_attr "length" "4")]
15912 +
15913 + )
15914 +
15915 +
15916 +(define_peephole2
15917 + [(set (match_operand:SI 0 "register_operand" "")
15918 + (plus:SI (match_dup 0)
15919 + (match_operand:SI 1 "immediate_operand" "")))
15920 + (set (match_dup 0)
15921 + (ashiftrt:SI (match_dup 0)
15922 + (match_operand:SI 2 "immediate_operand" "")))]
15923 + "avr32_rnd_operands(operands[1], operands[2])"
15924 +
15925 + [(set (match_dup 0)
15926 + (ashiftrt:SI (plus:SI (match_dup 0)
15927 + (match_dup 1))
15928 + (match_dup 2)))]
15929 + )
15930 +
15931 +(define_peephole
15932 + [(set (match_operand:SI 0 "register_operand" "r")
15933 + (plus:SI (match_dup 0)
15934 + (match_operand:SI 1 "immediate_operand" "i")))
15935 + (set (match_dup 0)
15936 + (ashiftrt:SI (match_dup 0)
15937 + (match_operand:SI 2 "immediate_operand" "i")))]
15938 + "avr32_rnd_operands(operands[1], operands[2])"
15939 +
15940 + "satrnds %0 >> %2, 31"
15941 +
15942 + [(set_attr "type" "alu_sat")
15943 + (set_attr "length" "4")
15944 + (set_attr "cc" "clobber")]
15945 +
15946 + )
15947 +
15948 +
15949 +;;=================================================================
15950 +;; mcall
15951 +;;=================================================================
15952 +(define_peephole
15953 + [(set (match_operand:SI 0 "register_operand" "")
15954 + (match_operand 1 "avr32_const_pool_ref_operand" ""))
15955 + (parallel [(call (mem:SI (match_dup 0))
15956 + (match_operand 2 "" ""))
15957 + (clobber (reg:SI LR_REGNUM))])]
15958 + "dead_or_set_p(insn, operands[0])"
15959 + "mcall %1"
15960 + [(set_attr "type" "call")
15961 + (set_attr "length" "4")
15962 + (set_attr "cc" "clobber")]
15963 +)
15964 +
15965 +(define_peephole
15966 + [(set (match_operand:SI 2 "register_operand" "")
15967 + (match_operand 1 "avr32_const_pool_ref_operand" ""))
15968 + (parallel [(set (match_operand 0 "register_operand" "")
15969 + (call (mem:SI (match_dup 2))
15970 + (match_operand 3 "" "")))
15971 + (clobber (reg:SI LR_REGNUM))])]
15972 + "dead_or_set_p(insn, operands[2])"
15973 + "mcall %1"
15974 + [(set_attr "type" "call")
15975 + (set_attr "length" "4")
15976 + (set_attr "cc" "call_set")]
15977 +)
15978 +
15979 +
15980 +(define_peephole2
15981 + [(set (match_operand:SI 0 "register_operand" "")
15982 + (match_operand 1 "avr32_const_pool_ref_operand" ""))
15983 + (parallel [(call (mem:SI (match_dup 0))
15984 + (match_operand 2 "" ""))
15985 + (clobber (reg:SI LR_REGNUM))])]
15986 + "peep2_reg_dead_p(2, operands[0])"
15987 + [(parallel [(call (mem:SI (match_dup 1))
15988 + (match_dup 2))
15989 + (clobber (reg:SI LR_REGNUM))])]
15990 + ""
15991 +)
15992 +
15993 +(define_peephole2
15994 + [(set (match_operand:SI 0 "register_operand" "")
15995 + (match_operand 1 "avr32_const_pool_ref_operand" ""))
15996 + (parallel [(set (match_operand 2 "register_operand" "")
15997 + (call (mem:SI (match_dup 0))
15998 + (match_operand 3 "" "")))
15999 + (clobber (reg:SI LR_REGNUM))])]
16000 + "(peep2_reg_dead_p(2, operands[0]) || (REGNO(operands[2]) == REGNO(operands[0])))"
16001 + [(parallel [(set (match_dup 2)
16002 + (call (mem:SI (match_dup 1))
16003 + (match_dup 3)))
16004 + (clobber (reg:SI LR_REGNUM))])]
16005 + ""
16006 +)
16007 +
16008 +;;=================================================================
16009 +;; Returning a value
16010 +;;=================================================================
16011 +
16012 +
16013 +(define_peephole
16014 + [(set (match_operand 0 "register_operand" "")
16015 + (match_operand 1 "register_operand" ""))
16016 + (return)]
16017 + "USE_RETURN_INSN (TRUE) && (REGNO(operands[0]) == RETVAL_REGNUM)
16018 + && (REGNO(operands[1]) != LR_REGNUM)
16019 + && (REGNO_REG_CLASS(REGNO(operands[1])) == GENERAL_REGS)"
16020 + "retal %1"
16021 + [(set_attr "type" "call")
16022 + (set_attr "length" "2")]
16023 + )
16024 +
16025 +
16026 +(define_peephole
16027 + [(set (match_operand 0 "register_operand" "r")
16028 + (match_operand 1 "immediate_operand" "i"))
16029 + (return)]
16030 + "(USE_RETURN_INSN (FALSE) && (REGNO(operands[0]) == RETVAL_REGNUM) &&
16031 + ((INTVAL(operands[1]) == -1) || (INTVAL(operands[1]) == 0) || (INTVAL(operands[1]) == 1)))"
16032 + {
16033 + avr32_output_return_instruction (TRUE, FALSE, NULL, operands[1]);
16034 + return "";
16035 + }
16036 + [(set_attr "type" "call")
16037 + (set_attr "length" "4")]
16038 + )
16039 +
16040 +(define_peephole
16041 + [(set (match_operand 0 "register_operand" "r")
16042 + (match_operand 1 "immediate_operand" "i"))
16043 + (unspec_volatile [(return)] VUNSPEC_EPILOGUE)]
16044 + "(REGNO(operands[0]) == RETVAL_REGNUM) &&
16045 + ((INTVAL(operands[1]) == -1) || (INTVAL(operands[1]) == 0) || (INTVAL(operands[1]) == 1))"
16046 + {
16047 + avr32_output_return_instruction (FALSE, FALSE, NULL, operands[1]);
16048 + return "";
16049 + }
16050 + ; Length is absolute worst case
16051 + [(set_attr "type" "branch")
16052 + (set_attr "length" "12")]
16053 + )
16054 +
16055 +(define_peephole
16056 + [(set (match_operand 0 "register_operand" "=r")
16057 + (if_then_else (match_operator 1 "avr32_comparison_operator"
16058 + [(match_operand 4 "register_operand" "r")
16059 + (match_operand 5 "register_immediate_operand" "rKs21")])
16060 + (match_operand 2 "avr32_cond_register_immediate_operand" "rKs08")
16061 + (match_operand 3 "avr32_cond_register_immediate_operand" "rKs08")))
16062 + (return)]
16063 + "USE_RETURN_INSN (TRUE) && (REGNO(operands[0]) == RETVAL_REGNUM)"
16064 + {
16065 + operands[1] = avr32_output_cmp(operands[1], GET_MODE(operands[4]), operands[4], operands[5]);
16066 +
16067 + if ( GET_CODE(operands[2]) == REG
16068 + && GET_CODE(operands[3]) == REG
16069 + && REGNO(operands[2]) != LR_REGNUM
16070 + && REGNO(operands[3]) != LR_REGNUM ){
16071 + return "ret%1 %2\;ret%i1 %3";
16072 + } else if ( GET_CODE(operands[2]) == REG
16073 + && GET_CODE(operands[3]) == CONST_INT ){
16074 + if ( INTVAL(operands[3]) == -1
16075 + || INTVAL(operands[3]) == 0
16076 + || INTVAL(operands[3]) == 1 ){
16077 + return "ret%1 %2\;ret%i1 %d3";
16078 + } else {
16079 + return "mov%1 r12, %2\;mov%i1 r12, %3\;retal r12";
16080 + }
16081 + } else if ( GET_CODE(operands[2]) == CONST_INT
16082 + && GET_CODE(operands[3]) == REG ){
16083 + if ( INTVAL(operands[2]) == -1
16084 + || INTVAL(operands[2]) == 0
16085 + || INTVAL(operands[2]) == 1 ){
16086 + return "ret%1 %d2\;ret%i1 %3";
16087 + } else {
16088 + return "mov%1 r12, %2\;mov%i1 r12, %3\;retal r12";
16089 + }
16090 + } else {
16091 + if ( (INTVAL(operands[2]) == -1
16092 + || INTVAL(operands[2]) == 0
16093 + || INTVAL(operands[2]) == 1 )
16094 + && (INTVAL(operands[3]) == -1
16095 + || INTVAL(operands[3]) == 0
16096 + || INTVAL(operands[3]) == 1 )){
16097 + return "ret%1 %d2\;ret%i1 %d3";
16098 + } else {
16099 + return "mov%1 r12, %2\;mov%i1 r12, %3\;retal r12";
16100 + }
16101 + }
16102 + }
16103 +
16104 + [(set_attr "length" "10")
16105 + (set_attr "cc" "none")
16106 + (set_attr "type" "call")])
16107 +
16108 +
16109 +
16110 +;;=================================================================
16111 +;; mulnhh.w
16112 +;;=================================================================
16113 +
16114 +(define_peephole2
16115 + [(set (match_operand:HI 0 "register_operand" "")
16116 + (neg:HI (match_operand:HI 1 "register_operand" "")))
16117 + (set (match_operand:SI 2 "register_operand" "")
16118 + (mult:SI
16119 + (sign_extend:SI (match_dup 0))
16120 + (sign_extend:SI (match_operand:HI 3 "register_operand" ""))))]
16121 + "(peep2_reg_dead_p(2, operands[0])) || (REGNO(operands[2]) == REGNO(operands[0]))"
16122 + [ (set (match_dup 2)
16123 + (mult:SI
16124 + (sign_extend:SI (neg:HI (match_dup 1)))
16125 + (sign_extend:SI (match_dup 3))))]
16126 + ""
16127 + )
16128 +
16129 +(define_peephole2
16130 + [(set (match_operand:HI 0 "register_operand" "")
16131 + (neg:HI (match_operand:HI 1 "register_operand" "")))
16132 + (set (match_operand:SI 2 "register_operand" "")
16133 + (mult:SI
16134 + (sign_extend:SI (match_operand:HI 3 "register_operand" ""))
16135 + (sign_extend:SI (match_dup 0))))]
16136 + "(peep2_reg_dead_p(2, operands[0])) || (REGNO(operands[2]) == REGNO(operands[0]))"
16137 + [ (set (match_dup 2)
16138 + (mult:SI
16139 + (sign_extend:SI (neg:HI (match_dup 1)))
16140 + (sign_extend:SI (match_dup 3))))]
16141 + ""
16142 + )
16143 +
16144 +
16145 +
16146 +;;=================================================================
16147 +;; Vector set and extract operations
16148 +;;=================================================================
16149 +(define_insn "vec_setv2hi_hi"
16150 + [(set (match_operand:V2HI 0 "register_operand" "=r")
16151 + (vec_merge:V2HI
16152 + (match_dup 0)
16153 + (vec_duplicate:V2HI
16154 + (match_operand:HI 1 "register_operand" "r"))
16155 + (const_int 1)))]
16156 + ""
16157 + "bfins\t%0, %1, 16, 16"
16158 + [(set_attr "type" "alu")
16159 + (set_attr "length" "4")
16160 + (set_attr "cc" "clobber")])
16161 +
16162 +(define_insn "vec_setv2hi_lo"
16163 + [(set (match_operand:V2HI 0 "register_operand" "+r")
16164 + (vec_merge:V2HI
16165 + (match_dup 0)
16166 + (vec_duplicate:V2HI
16167 + (match_operand:HI 1 "register_operand" "r"))
16168 + (const_int 2)))]
16169 + ""
16170 + "bfins\t%0, %1, 0, 16"
16171 + [(set_attr "type" "alu")
16172 + (set_attr "length" "4")
16173 + (set_attr "cc" "clobber")])
16174 +
16175 +(define_expand "vec_setv2hi"
16176 + [(set (match_operand:V2HI 0 "register_operand" "")
16177 + (vec_merge:V2HI
16178 + (match_dup 0)
16179 + (vec_duplicate:V2HI
16180 + (match_operand:HI 1 "register_operand" ""))
16181 + (match_operand 2 "immediate_operand" "")))]
16182 + ""
16183 + { operands[2] = GEN_INT(INTVAL(operands[2]) + 1); }
16184 + )
16185 +
16186 +(define_insn "vec_extractv2hi"
16187 + [(set (match_operand:HI 0 "register_operand" "=r")
16188 + (vec_select:HI
16189 + (match_operand:V2HI 1 "register_operand" "r")
16190 + (parallel [(match_operand:SI 2 "immediate_operand" "i")])))]
16191 + ""
16192 + {
16193 + if ( INTVAL(operands[2]) == 0 )
16194 + return "bfextu\t%0, %1, 16, 16";
16195 + else
16196 + return "bfextu\t%0, %1, 0, 16";
16197 + }
16198 + [(set_attr "type" "alu")
16199 + (set_attr "length" "4")
16200 + (set_attr "cc" "clobber")])
16201 +
16202 +(define_insn "vec_extractv4qi"
16203 + [(set (match_operand:QI 0 "register_operand" "=r")
16204 + (vec_select:QI
16205 + (match_operand:V4QI 1 "register_operand" "r")
16206 + (parallel [(match_operand:SI 2 "immediate_operand" "i")])))]
16207 + ""
16208 + {
16209 + switch ( INTVAL(operands[2]) ){
16210 + case 0:
16211 + return "bfextu\t%0, %1, 24, 8";
16212 + case 1:
16213 + return "bfextu\t%0, %1, 16, 8";
16214 + case 2:
16215 + return "bfextu\t%0, %1, 8, 8";
16216 + case 3:
16217 + return "bfextu\t%0, %1, 0, 8";
16218 + default:
16219 + abort();
16220 + }
16221 + }
16222 + [(set_attr "type" "alu")
16223 + (set_attr "length" "4")
16224 + (set_attr "cc" "clobber")])
16225 +
16226 +
16227 +(define_insn "concatv2hi"
16228 + [(set (match_operand:V2HI 0 "register_operand" "=r, r, r")
16229 + (vec_concat:V2HI
16230 + (match_operand:HI 1 "register_operand" "r, r, 0")
16231 + (match_operand:HI 2 "register_operand" "r, 0, r")))]
16232 + ""
16233 + "@
16234 + mov\t%0, %1\;bfins\t%0, %2, 0, 16
16235 + bfins\t%0, %2, 0, 16
16236 + bfins\t%0, %1, 16, 16"
16237 + [(set_attr "length" "6, 4, 4")
16238 + (set_attr "type" "alu")])
16239 +
16240 +
16241 +;; Load the atomic operation description
16242 +(include "sync.md")
16243 +
16244 +;; Load the SIMD description
16245 +(include "simd.md")
16246 +
16247 +;; Load the FP coprAocessor patterns
16248 +(include "fpcp.md")
16249 --- /dev/null
16250 +++ b/gcc/config/avr32/avr32-modes.def
16251 @@ -0,0 +1 @@
16252 +VECTOR_MODES (INT, 4); /* V4QI V2HI */
16253 --- /dev/null
16254 +++ b/gcc/config/avr32/avr32.opt
16255 @@ -0,0 +1,81 @@
16256 +; Options for the ATMEL AVR32 port of the compiler.
16257 +
16258 +; Copyright 2007 Atmel Corporation.
16259 +;
16260 +; This file is part of GCC.
16261 +;
16262 +; GCC is free software; you can redistribute it and/or modify it under
16263 +; the terms of the GNU General Public License as published by the Free
16264 +; Software Foundation; either version 2, or (at your option) any later
16265 +; version.
16266 +;
16267 +; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16268 +; WARRANTY; without even the implied warranty of MERCHANTABILITY or
16269 +; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16270 +; for more details.
16271 +;
16272 +; You should have received a copy of the GNU General Public License
16273 +; along with GCC; see the file COPYING. If not, write to the Free
16274 +; Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
16275 +; 02110-1301, USA.
16276 +
16277 +muse-rodata-section
16278 +Target Report Mask(USE_RODATA_SECTION)
16279 +Use section .rodata for read-only data instead of .text.
16280 +
16281 +mhard-float
16282 +Target Report Undocumented Mask(HARD_FLOAT)
16283 +Use floating point coprocessor instructions.
16284 +
16285 +msoft-float
16286 +Target Report Undocumented InverseMask(HARD_FLOAT, SOFT_FLOAT)
16287 +Use software floating-point library for floating-point operations.
16288 +
16289 +mforce-double-align
16290 +Target Report RejectNegative Mask(FORCE_DOUBLE_ALIGN)
16291 +Force double-word alignment for double-word memory accesses.
16292 +
16293 +mno-init-got
16294 +Target Report RejectNegative Mask(NO_INIT_GOT)
16295 +Do not initialize GOT register before using it when compiling PIC code.
16296 +
16297 +mrelax
16298 +Target Report Mask(RELAX)
16299 +Let invoked assembler and linker do relaxing (Enabled by default when optimization level is >1).
16300 +
16301 +mmd-reorg-opt
16302 +Target Report Undocumented Mask(MD_REORG_OPTIMIZATION)
16303 +Perform machine dependent optimizations in reorg stage.
16304 +
16305 +masm-addr-pseudos
16306 +Target Report Mask(HAS_ASM_ADDR_PSEUDOS)
16307 +Use assembler pseudo-instructions lda.w and call for handling direct addresses. (Enabled by default)
16308 +
16309 +mpart=
16310 +Target Report RejectNegative Joined Var(avr32_part_name)
16311 +Specify the AVR32 part name
16312 +
16313 +mcpu=
16314 +Target Report RejectNegative Joined Undocumented Var(avr32_part_name)
16315 +Specify the AVR32 part name (deprecated)
16316 +
16317 +march=
16318 +Target Report RejectNegative Joined Var(avr32_arch_name)
16319 +Specify the AVR32 architecture name
16320 +
16321 +mfast-float
16322 +Target Report Mask(FAST_FLOAT)
16323 +Enable fast floating-point library. Enabled by default if the -funsafe-math-optimizations switch is specified.
16324 +
16325 +mimm-in-const-pool
16326 +Target Report Var(avr32_imm_in_const_pool) Init(-1)
16327 +Put large immediates in constant pool. This is enabled by default for archs with insn-cache.
16328 +
16329 +mno-pic
16330 +Target Report RejectNegative Mask(NO_PIC)
16331 +Do not generate position-independent code. (deprecated, use -fno-pic instead)
16332 +
16333 +mcond-exec-before-reload
16334 +Target Report Undocumented Mask(COND_EXEC_BEFORE_RELOAD)
16335 +Enable experimental conditional execution preparation before the reload stage.
16336 +
16337 --- /dev/null
16338 +++ b/gcc/config/avr32/avr32-protos.h
16339 @@ -0,0 +1,197 @@
16340 +/*
16341 + Prototypes for exported functions defined in avr32.c
16342 + Copyright 2003-2006 Atmel Corporation.
16343 +
16344 + Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
16345 + Initial porting by Anders �dland.
16346 +
16347 + This file is part of GCC.
16348 +
16349 + This program is free software; you can redistribute it and/or modify
16350 + it under the terms of the GNU General Public License as published by
16351 + the Free Software Foundation; either version 2 of the License, or
16352 + (at your option) any later version.
16353 +
16354 + This program is distributed in the hope that it will be useful,
16355 + but WITHOUT ANY WARRANTY; without even the implied warranty of
16356 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16357 + GNU General Public License for more details.
16358 +
16359 + You should have received a copy of the GNU General Public License
16360 + along with this program; if not, write to the Free Software
16361 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16362 +
16363 +
16364 +#ifndef AVR32_PROTOS_H
16365 +#define AVR32_PROTOS_H
16366 +
16367 +extern const int swap_reg[];
16368 +
16369 +extern int avr32_valid_macmac_bypass (rtx, rtx);
16370 +extern int avr32_valid_mulmac_bypass (rtx, rtx);
16371 +
16372 +extern int avr32_decode_lcomm_symbol_offset (rtx, int *);
16373 +extern void avr32_encode_lcomm_symbol_offset (tree, char *, int);
16374 +
16375 +extern const char *avr32_strip_name_encoding (const char *);
16376 +
16377 +extern rtx avr32_get_note_reg_equiv (rtx insn);
16378 +
16379 +extern int avr32_use_return_insn (int iscond);
16380 +
16381 +extern void avr32_make_reglist16 (int reglist16_vect, char *reglist16_string);
16382 +
16383 +extern void avr32_make_reglist8 (int reglist8_vect, char *reglist8_string);
16384 +extern void avr32_make_fp_reglist_w (int reglist_mask, char *reglist_string);
16385 +extern void avr32_make_fp_reglist_d (int reglist_mask, char *reglist_string);
16386 +
16387 +extern void avr32_output_return_instruction (int single_ret_inst,
16388 + int iscond, rtx cond,
16389 + rtx r12_imm);
16390 +extern void avr32_expand_prologue (void);
16391 +extern void avr32_set_return_address (rtx source, rtx scratch);
16392 +
16393 +extern int avr32_hard_regno_mode_ok (int regno, enum machine_mode mode);
16394 +extern int avr32_extra_constraint_s (rtx value, const int strict);
16395 +extern int avr32_eh_return_data_regno (const int n);
16396 +extern int avr32_initial_elimination_offset (const int from, const int to);
16397 +extern rtx avr32_function_arg (CUMULATIVE_ARGS * cum, enum machine_mode mode,
16398 + tree type, int named);
16399 +extern void avr32_init_cumulative_args (CUMULATIVE_ARGS * cum, tree fntype,
16400 + rtx libname, tree fndecl);
16401 +extern void avr32_function_arg_advance (CUMULATIVE_ARGS * cum,
16402 + enum machine_mode mode,
16403 + tree type, int named);
16404 +#ifdef ARGS_SIZE_RTX
16405 +/* expr.h defines ARGS_SIZE_RTX and `enum direction'. */
16406 +extern enum direction avr32_function_arg_padding (enum machine_mode mode,
16407 + tree type);
16408 +#endif /* ARGS_SIZE_RTX */
16409 +extern rtx avr32_function_value (tree valtype, tree func, bool outgoing);
16410 +extern rtx avr32_libcall_value (enum machine_mode mode);
16411 +extern int avr32_sched_use_dfa_pipeline_interface (void);
16412 +extern bool avr32_return_in_memory (tree type, tree fntype);
16413 +extern void avr32_regs_to_save (char *operand);
16414 +extern void avr32_target_asm_function_prologue (FILE * file,
16415 + HOST_WIDE_INT size);
16416 +extern void avr32_target_asm_function_epilogue (FILE * file,
16417 + HOST_WIDE_INT size);
16418 +extern void avr32_trampoline_template (FILE * file);
16419 +extern void avr32_initialize_trampoline (rtx addr, rtx fnaddr,
16420 + rtx static_chain);
16421 +extern int avr32_legitimate_address (enum machine_mode mode, rtx x,
16422 + int strict);
16423 +extern int avr32_legitimate_constant_p (rtx x);
16424 +
16425 +extern int avr32_legitimate_pic_operand_p (rtx x);
16426 +
16427 +extern rtx avr32_find_symbol (rtx x);
16428 +extern void avr32_select_section (rtx exp, int reloc, int align);
16429 +extern void avr32_encode_section_info (tree decl, rtx rtl, int first);
16430 +extern void avr32_asm_file_end (FILE * stream);
16431 +extern void avr32_asm_output_ascii (FILE * stream, char *ptr, int len);
16432 +extern void avr32_asm_output_common (FILE * stream, const char *name,
16433 + int size, int rounded);
16434 +extern void avr32_asm_output_label (FILE * stream, const char *name);
16435 +extern void avr32_asm_declare_object_name (FILE * stream, char *name,
16436 + tree decl);
16437 +extern void avr32_asm_globalize_label (FILE * stream, const char *name);
16438 +extern void avr32_asm_weaken_label (FILE * stream, const char *name);
16439 +extern void avr32_asm_output_external (FILE * stream, tree decl,
16440 + const char *name);
16441 +extern void avr32_asm_output_external_libcall (FILE * stream, rtx symref);
16442 +extern void avr32_asm_output_labelref (FILE * stream, const char *name);
16443 +extern void avr32_notice_update_cc (rtx exp, rtx insn);
16444 +extern void avr32_print_operand (FILE * stream, rtx x, int code);
16445 +extern void avr32_print_operand_address (FILE * stream, rtx x);
16446 +
16447 +extern int avr32_symbol (rtx x);
16448 +
16449 +extern void avr32_select_rtx_section (enum machine_mode mode, rtx x,
16450 + unsigned HOST_WIDE_INT align);
16451 +
16452 +extern int avr32_load_multiple_operation (rtx op, enum machine_mode mode);
16453 +extern int avr32_store_multiple_operation (rtx op, enum machine_mode mode);
16454 +
16455 +extern int avr32_const_ok_for_constraint_p (HOST_WIDE_INT value, char c,
16456 + const char *str);
16457 +
16458 +extern bool avr32_cannot_force_const_mem (rtx x);
16459 +
16460 +extern void avr32_init_builtins (void);
16461 +
16462 +extern rtx avr32_expand_builtin (tree exp, rtx target, rtx subtarget,
16463 + enum machine_mode mode, int ignore);
16464 +
16465 +extern bool avr32_must_pass_in_stack (enum machine_mode mode, tree type);
16466 +
16467 +extern bool avr32_strict_argument_naming (CUMULATIVE_ARGS * ca);
16468 +
16469 +extern bool avr32_pass_by_reference (CUMULATIVE_ARGS * cum,
16470 + enum machine_mode mode,
16471 + tree type, bool named);
16472 +
16473 +extern rtx avr32_gen_load_multiple (rtx * regs, int count, rtx from,
16474 + int write_back, int in_struct_p,
16475 + int scalar_p);
16476 +extern rtx avr32_gen_store_multiple (rtx * regs, int count, rtx to,
16477 + int in_struct_p, int scalar_p);
16478 +extern int avr32_gen_movmemsi (rtx * operands);
16479 +
16480 +extern int avr32_rnd_operands (rtx add, rtx shift);
16481 +extern int avr32_adjust_insn_length (rtx insn, int length);
16482 +
16483 +extern int symbol_mentioned_p (rtx x);
16484 +extern int label_mentioned_p (rtx x);
16485 +extern rtx legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg);
16486 +extern int avr32_address_register_rtx_p (rtx x, int strict_p);
16487 +extern int avr32_legitimate_index_p (enum machine_mode mode, rtx index,
16488 + int strict_p);
16489 +
16490 +extern int avr32_const_double_immediate (rtx value);
16491 +extern void avr32_init_expanders (void);
16492 +extern rtx avr32_return_addr (int count, rtx frame);
16493 +extern bool avr32_got_mentioned_p (rtx addr);
16494 +
16495 +extern void avr32_final_prescan_insn (rtx insn, rtx * opvec, int noperands);
16496 +
16497 +extern int avr32_expand_movcc (enum machine_mode mode, rtx operands[]);
16498 +extern int avr32_expand_addcc (enum machine_mode mode, rtx operands[]);
16499 +#ifdef RTX_CODE
16500 +extern int avr32_expand_scc (RTX_CODE cond, rtx * operands);
16501 +#endif
16502 +
16503 +extern int avr32_store_bypass (rtx insn_out, rtx insn_in);
16504 +extern int avr32_mul_waw_bypass (rtx insn_out, rtx insn_in);
16505 +extern int avr32_valid_load_double_bypass (rtx insn_out, rtx insn_in);
16506 +extern int avr32_valid_load_quad_bypass (rtx insn_out, rtx insn_in);
16507 +extern rtx avr32_output_cmp (rtx cond, enum machine_mode mode,
16508 + rtx op0, rtx op1);
16509 +
16510 +rtx get_next_insn_cond (rtx cur_insn);
16511 +int set_next_insn_cond (rtx cur_insn, rtx cond);
16512 +rtx next_insn_emits_cmp (rtx cur_insn);
16513 +void avr32_override_options (void);
16514 +void avr32_load_pic_register (void);
16515 +#ifdef GCC_BASIC_BLOCK_H
16516 +rtx avr32_ifcvt_modify_insn (ce_if_block_t *ce_info, rtx pattern, rtx insn,
16517 + int *num_true_changes);
16518 +rtx avr32_ifcvt_modify_test (ce_if_block_t *ce_info, rtx test );
16519 +void avr32_ifcvt_modify_cancel ( ce_if_block_t *ce_info, int *num_true_changes);
16520 +#endif
16521 +void avr32_optimization_options (int level, int size);
16522 +int avr32_const_ok_for_move (HOST_WIDE_INT c);
16523 +
16524 +void avr32_split_const_expr (enum machine_mode mode,
16525 + enum machine_mode new_mode,
16526 + rtx expr,
16527 + rtx *split_expr);
16528 +void avr32_get_intval (enum machine_mode mode,
16529 + rtx const_expr,
16530 + HOST_WIDE_INT *val);
16531 +
16532 +int avr32_cond_imm_clobber_splittable (rtx insn,
16533 + rtx operands[]);
16534 +
16535 +
16536 +#endif /* AVR32_PROTOS_H */
16537 --- /dev/null
16538 +++ b/gcc/config/avr32/crti.asm
16539 @@ -0,0 +1,64 @@
16540 +/*
16541 + Init/fini stuff for AVR32.
16542 + Copyright 2003-2006 Atmel Corporation.
16543 +
16544 + Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
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 +/* The code in sections .init and .fini is supposed to be a single
16564 + regular function. The function in .init is called directly from
16565 + start in crt1.asm. The function in .fini is atexit()ed in crt1.asm
16566 + too.
16567 +
16568 + crti.asm contributes the prologue of a function to these sections,
16569 + and crtn.asm comes up the epilogue. STARTFILE_SPEC should list
16570 + crti.o before any other object files that might add code to .init
16571 + or .fini sections, and ENDFILE_SPEC should list crtn.o after any
16572 + such object files. */
16573 +
16574 + .file "crti.asm"
16575 +
16576 + .section ".init"
16577 +/* Just load the GOT */
16578 + .align 2
16579 + .global _init
16580 +_init:
16581 + stm --sp, r6, lr
16582 + lddpc r6, 1f
16583 +0:
16584 + rsub r6, pc
16585 + rjmp 2f
16586 + .align 2
16587 +1: .long 0b - _GLOBAL_OFFSET_TABLE_
16588 +2:
16589 +
16590 + .section ".fini"
16591 +/* Just load the GOT */
16592 + .align 2
16593 + .global _fini
16594 +_fini:
16595 + stm --sp, r6, lr
16596 + lddpc r6, 1f
16597 +0:
16598 + rsub r6, pc
16599 + rjmp 2f
16600 + .align 2
16601 +1: .long 0b - _GLOBAL_OFFSET_TABLE_
16602 +2:
16603 +
16604 --- /dev/null
16605 +++ b/gcc/config/avr32/crtn.asm
16606 @@ -0,0 +1,44 @@
16607 +/* Copyright (C) 2001 Free Software Foundation, Inc.
16608 + Written By Nick Clifton
16609 +
16610 + This file is free software; you can redistribute it and/or modify it
16611 + under the terms of the GNU General Public License as published by the
16612 + Free Software Foundation; either version 2, or (at your option) any
16613 + later version.
16614 +
16615 + In addition to the permissions in the GNU General Public License, the
16616 + Free Software Foundation gives you unlimited permission to link the
16617 + compiled version of this file with other programs, and to distribute
16618 + those programs without any restriction coming from the use of this
16619 + file. (The General Public License restrictions do apply in other
16620 + respects; for example, they cover modification of the file, and
16621 + distribution when not linked into another program.)
16622 +
16623 + This file is distributed in the hope that it will be useful, but
16624 + WITHOUT ANY WARRANTY; without even the implied warranty of
16625 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16626 + General Public License for more details.
16627 +
16628 + You should have received a copy of the GNU General Public License
16629 + along with this program; see the file COPYING. If not, write to
16630 + the Free Software Foundation, 59 Temple Place - Suite 330,
16631 + Boston, MA 02111-1307, USA.
16632 +
16633 + As a special exception, if you link this library with files
16634 + compiled with GCC to produce an executable, this does not cause
16635 + the resulting executable to be covered by the GNU General Public License.
16636 + This exception does not however invalidate any other reasons why
16637 + the executable file might be covered by the GNU General Public License.
16638 +*/
16639 +
16640 +
16641 +
16642 +
16643 + .file "crtn.asm"
16644 +
16645 + .section ".init"
16646 + ldm sp++, r6, pc
16647 +
16648 + .section ".fini"
16649 + ldm sp++, r6, pc
16650 +
16651 --- /dev/null
16652 +++ b/gcc/config/avr32/fpcp.md
16653 @@ -0,0 +1,551 @@
16654 +;; AVR32 machine description file for Floating-Point instructions.
16655 +;; Copyright 2003-2006 Atmel Corporation.
16656 +;;
16657 +;; Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
16658 +;;
16659 +;; This file is part of GCC.
16660 +;;
16661 +;; This program is free software; you can redistribute it and/or modify
16662 +;; it under the terms of the GNU General Public License as published by
16663 +;; the Free Software Foundation; either version 2 of the License, or
16664 +;; (at your option) any later version.
16665 +;;
16666 +;; This program is distributed in the hope that it will be useful,
16667 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16668 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16669 +;; GNU General Public License for more details.
16670 +;;
16671 +;; You should have received a copy of the GNU General Public License
16672 +;; along with this program; if not, write to the Free Software
16673 +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16674 +
16675 +;; -*- Mode: Scheme -*-
16676 +
16677 +;;******************************************************************************
16678 +;; Automaton pipeline description for floating-point coprocessor insns
16679 +;;******************************************************************************
16680 +(define_cpu_unit "fid,fm1,fm2,fm3,fm4,fwb,fcmp,fcast" "avr32_ap")
16681 +
16682 +(define_insn_reservation "fmv_op" 1
16683 + (and (eq_attr "pipeline" "ap")
16684 + (eq_attr "type" "fmv"))
16685 + "is,da,d,fid,fwb")
16686 +
16687 +(define_insn_reservation "fmul_op" 5
16688 + (and (eq_attr "pipeline" "ap")
16689 + (eq_attr "type" "fmul"))
16690 + "is,da,d,fid,fm1,fm2,fm3,fm4,fwb")
16691 +
16692 +(define_insn_reservation "fcmps_op" 1
16693 + (and (eq_attr "pipeline" "ap")
16694 + (eq_attr "type" "fcmps"))
16695 + "is,da,d,fid,fcmp")
16696 +
16697 +(define_insn_reservation "fcmpd_op" 2
16698 + (and (eq_attr "pipeline" "ap")
16699 + (eq_attr "type" "fcmpd"))
16700 + "is,da,d,fid*2,fcmp")
16701 +
16702 +(define_insn_reservation "fcast_op" 3
16703 + (and (eq_attr "pipeline" "ap")
16704 + (eq_attr "type" "fcast"))
16705 + "is,da,d,fid,fcmp,fcast,fwb")
16706 +
16707 +(define_insn_reservation "fmvcpu_op" 2
16708 + (and (eq_attr "pipeline" "ap")
16709 + (eq_attr "type" "fmvcpu"))
16710 + "is,da,d")
16711 +
16712 +(define_insn_reservation "fldd_op" 1
16713 + (and (eq_attr "pipeline" "ap")
16714 + (eq_attr "type" "fldd"))
16715 + "is,da,d,fwb")
16716 +
16717 +(define_insn_reservation "flds_op" 1
16718 + (and (eq_attr "pipeline" "ap")
16719 + (eq_attr "type" "flds"))
16720 + "is,da,d,fwb")
16721 +
16722 +(define_insn_reservation "fsts_op" 0
16723 + (and (eq_attr "pipeline" "ap")
16724 + (eq_attr "type" "fsts"))
16725 + "is,da*2,d")
16726 +
16727 +(define_insn_reservation "fstd_op" 0
16728 + (and (eq_attr "pipeline" "ap")
16729 + (eq_attr "type" "fstd"))
16730 + "is,da*2,d")
16731 +
16732 +
16733 +(define_insn "*movsf_fpcp"
16734 + [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,r,f,m,r,r,r,m")
16735 + (match_operand:SF 1 "general_operand" " f,r,f,m,f,r,G,m,r"))]
16736 + "TARGET_HARD_FLOAT"
16737 + "@
16738 + fmov.s\t%0, %1
16739 + fmov.s\t%0, %1
16740 + fmov.s\t%0, %1
16741 + fld.s\t%0, %1
16742 + fst.s\t%0, %1
16743 + mov\t%0, %1
16744 + mov\t%0, %1
16745 + ld.w\t%0, %1
16746 + st.w\t%0, %1"
16747 + [(set_attr "length" "4,4,4,4,4,2,4,4,4")
16748 + (set_attr "type" "fmv,flds,fmvcpu,flds,fsts,alu,alu,load,store")])
16749 +
16750 +(define_insn_and_split "*movdf_fpcp"
16751 + [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,r,f,m,r,r,m")
16752 + (match_operand:DF 1 "general_operand" " f,r,f,m,f,r,m,r"))]
16753 + "TARGET_HARD_FLOAT"
16754 + "@
16755 + fmov.d\t%0, %1
16756 + fmov.d\t%0, %1
16757 + fmov.d\t%0, %1
16758 + fld.d\t%0, %1
16759 + fst.d\t%0, %1
16760 + mov\t%0, %1\;mov\t%m0, %m1
16761 + ld.d\t%0, %1
16762 + st.d\t%0, %1"
16763 +
16764 + "TARGET_HARD_FLOAT
16765 + && reload_completed
16766 + && (REG_P(operands[0]) && (REGNO_REG_CLASS(REGNO(operands[0])) == GENERAL_REGS))
16767 + && (REG_P(operands[1]) && (REGNO_REG_CLASS(REGNO(operands[1])) == GENERAL_REGS))"
16768 + [(set (match_dup 0) (match_dup 1))
16769 + (set (match_dup 2) (match_dup 3))]
16770 + "
16771 + {
16772 + operands[2] = gen_highpart (SImode, operands[0]);
16773 + operands[0] = gen_lowpart (SImode, operands[0]);
16774 + operands[3] = gen_highpart(SImode, operands[1]);
16775 + operands[1] = gen_lowpart(SImode, operands[1]);
16776 + }
16777 + "
16778 +
16779 + [(set_attr "length" "4,4,4,4,4,4,4,4")
16780 + (set_attr "type" "fmv,fldd,fmvcpu,fldd,fstd,alu2,load2,store2")])
16781 +
16782 +
16783 +(define_insn "mulsf3"
16784 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16785 + (mult:SF (match_operand:SF 1 "avr32_fp_register_operand" "f")
16786 + (match_operand:SF 2 "avr32_fp_register_operand" "f")))]
16787 + "TARGET_HARD_FLOAT"
16788 + "fmul.s\t%0, %1, %2"
16789 + [(set_attr "length" "4")
16790 + (set_attr "type" "fmul")])
16791 +
16792 +(define_insn "nmulsf3"
16793 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16794 + (neg:SF (mult:SF (match_operand:SF 1 "avr32_fp_register_operand" "f")
16795 + (match_operand:SF 2 "avr32_fp_register_operand" "f"))))]
16796 + "TARGET_HARD_FLOAT"
16797 + "fnmul.s\t%0, %1, %2"
16798 + [(set_attr "length" "4")
16799 + (set_attr "type" "fmul")])
16800 +
16801 +(define_peephole2
16802 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "")
16803 + (mult:SF (match_operand:SF 1 "avr32_fp_register_operand" "")
16804 + (match_operand:SF 2 "avr32_fp_register_operand" "")))
16805 + (set (match_operand:SF 3 "avr32_fp_register_operand" "")
16806 + (neg:SF (match_dup 0)))]
16807 + "TARGET_HARD_FLOAT &&
16808 + (peep2_reg_dead_p(2, operands[0]) || (REGNO(operands[3]) == REGNO(operands[0])))"
16809 + [(set (match_dup 3)
16810 + (neg:SF (mult:SF (match_dup 1)
16811 + (match_dup 2))))]
16812 +)
16813 +
16814 +
16815 +(define_insn "macsf3"
16816 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16817 + (plus:SF (mult:SF (match_operand:SF 1 "avr32_fp_register_operand" "f")
16818 + (match_operand:SF 2 "avr32_fp_register_operand" "f"))
16819 + (match_operand:SF 3 "avr32_fp_register_operand" "0")))]
16820 + "TARGET_HARD_FLOAT"
16821 + "fmac.s\t%0, %1, %2"
16822 + [(set_attr "length" "4")
16823 + (set_attr "type" "fmul")])
16824 +
16825 +(define_insn "nmacsf3"
16826 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16827 + (plus:SF (neg:SF (mult:SF (match_operand:SF 1 "avr32_fp_register_operand" "f")
16828 + (match_operand:SF 2 "avr32_fp_register_operand" "f")))
16829 + (match_operand:SF 3 "avr32_fp_register_operand" "0")))]
16830 + "TARGET_HARD_FLOAT"
16831 + "fnmac.s\t%0, %1, %2"
16832 + [(set_attr "length" "4")
16833 + (set_attr "type" "fmul")])
16834 +
16835 +(define_peephole2
16836 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "")
16837 + (mult:SF (match_operand:SF 1 "avr32_fp_register_operand" "")
16838 + (match_operand:SF 2 "avr32_fp_register_operand" "")))
16839 + (set (match_operand:SF 3 "avr32_fp_register_operand" "")
16840 + (minus:SF
16841 + (match_dup 3)
16842 + (match_dup 0)))]
16843 + "TARGET_HARD_FLOAT && peep2_reg_dead_p(2, operands[0])"
16844 + [(set (match_dup 3)
16845 + (plus:SF (neg:SF (mult:SF (match_dup 1)
16846 + (match_dup 2)))
16847 + (match_dup 3)))]
16848 +)
16849 +
16850 +
16851 +(define_insn "msubacsf3"
16852 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16853 + (minus:SF (mult:SF (match_operand:SF 1 "avr32_fp_register_operand" "f")
16854 + (match_operand:SF 2 "avr32_fp_register_operand" "f"))
16855 + (match_operand:SF 3 "avr32_fp_register_operand" "0")))]
16856 + "TARGET_HARD_FLOAT"
16857 + "fmsc.s\t%0, %1, %2"
16858 + [(set_attr "length" "4")
16859 + (set_attr "type" "fmul")])
16860 +
16861 +(define_peephole2
16862 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "")
16863 + (mult:SF (match_operand:SF 1 "avr32_fp_register_operand" "")
16864 + (match_operand:SF 2 "avr32_fp_register_operand" "")))
16865 + (set (match_operand:SF 3 "avr32_fp_register_operand" "")
16866 + (minus:SF
16867 + (match_dup 0)
16868 + (match_dup 3)))]
16869 + "TARGET_HARD_FLOAT && peep2_reg_dead_p(2, operands[0])"
16870 + [(set (match_dup 3)
16871 + (minus:SF (mult:SF (match_dup 1)
16872 + (match_dup 2))
16873 + (match_dup 3)))]
16874 +)
16875 +
16876 +(define_insn "nmsubacsf3"
16877 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16878 + (minus:SF (neg:SF (mult:SF (match_operand:SF 1 "avr32_fp_register_operand" "f")
16879 + (match_operand:SF 2 "avr32_fp_register_operand" "f")))
16880 + (match_operand:SF 3 "avr32_fp_register_operand" "0")))]
16881 + "TARGET_HARD_FLOAT"
16882 + "fnmsc.s\t%0, %1, %2"
16883 + [(set_attr "length" "4")
16884 + (set_attr "type" "fmul")])
16885 +
16886 +
16887 +
16888 +(define_insn "addsf3"
16889 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16890 + (plus:SF (match_operand:SF 1 "avr32_fp_register_operand" "f")
16891 + (match_operand:SF 2 "avr32_fp_register_operand" "f")))]
16892 + "TARGET_HARD_FLOAT"
16893 + "fadd.s\t%0, %1, %2"
16894 + [(set_attr "length" "4")
16895 + (set_attr "type" "fmul")])
16896 +
16897 +(define_insn "subsf3"
16898 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16899 + (minus:SF (match_operand:SF 1 "avr32_fp_register_operand" "f")
16900 + (match_operand:SF 2 "avr32_fp_register_operand" "f")))]
16901 + "TARGET_HARD_FLOAT"
16902 + "fsub.s\t%0, %1, %2"
16903 + [(set_attr "length" "4")
16904 + (set_attr "type" "fmul")])
16905 +
16906 +
16907 +(define_insn "negsf2"
16908 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16909 + (neg:SF (match_operand:SF 1 "avr32_fp_register_operand" "f")))]
16910 + "TARGET_HARD_FLOAT"
16911 + "fneg.s\t%0, %1"
16912 + [(set_attr "length" "4")
16913 + (set_attr "type" "fmv")])
16914 +
16915 +(define_insn "abssf2"
16916 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16917 + (abs:SF (match_operand:SF 1 "avr32_fp_register_operand" "f")))]
16918 + "TARGET_HARD_FLOAT"
16919 + "fabs.s\t%0, %1"
16920 + [(set_attr "length" "4")
16921 + (set_attr "type" "fmv")])
16922 +
16923 +(define_insn "truncdfsf2"
16924 + [(set (match_operand:SF 0 "avr32_fp_register_operand" "=f")
16925 + (float_truncate:SF
16926 + (match_operand:DF 1 "avr32_fp_register_operand" "f")))]
16927 + "TARGET_HARD_FLOAT"
16928 + "fcastd.s\t%0, %1"
16929 + [(set_attr "length" "4")
16930 + (set_attr "type" "fcast")])
16931 +
16932 +(define_insn "extendsfdf2"
16933 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
16934 + (float_extend:DF
16935 + (match_operand:SF 1 "avr32_fp_register_operand" "f")))]
16936 + "TARGET_HARD_FLOAT"
16937 + "fcasts.d\t%0, %1"
16938 + [(set_attr "length" "4")
16939 + (set_attr "type" "fcast")])
16940 +
16941 +(define_insn "muldf3"
16942 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
16943 + (mult:DF (match_operand:DF 1 "avr32_fp_register_operand" "f")
16944 + (match_operand:DF 2 "avr32_fp_register_operand" "f")))]
16945 + "TARGET_HARD_FLOAT"
16946 + "fmul.d\t%0, %1, %2"
16947 + [(set_attr "length" "4")
16948 + (set_attr "type" "fmul")])
16949 +
16950 +(define_insn "nmuldf3"
16951 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
16952 + (neg:DF (mult:DF (match_operand:DF 1 "avr32_fp_register_operand" "f")
16953 + (match_operand:DF 2 "avr32_fp_register_operand" "f"))))]
16954 + "TARGET_HARD_FLOAT"
16955 + "fnmul.d\t%0, %1, %2"
16956 + [(set_attr "length" "4")
16957 + (set_attr "type" "fmul")])
16958 +
16959 +(define_peephole2
16960 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "")
16961 + (mult:DF (match_operand:DF 1 "avr32_fp_register_operand" "")
16962 + (match_operand:DF 2 "avr32_fp_register_operand" "")))
16963 + (set (match_operand:DF 3 "avr32_fp_register_operand" "")
16964 + (neg:DF (match_dup 0)))]
16965 + "TARGET_HARD_FLOAT &&
16966 + (peep2_reg_dead_p(2, operands[0]) || (REGNO(operands[3]) == REGNO(operands[0])))"
16967 + [(set (match_dup 3)
16968 + (neg:DF (mult:DF (match_dup 1)
16969 + (match_dup 2))))]
16970 +)
16971 +
16972 +(define_insn "macdf3"
16973 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
16974 + (plus:DF (mult:DF (match_operand:DF 1 "avr32_fp_register_operand" "f")
16975 + (match_operand:DF 2 "avr32_fp_register_operand" "f"))
16976 + (match_operand:DF 3 "avr32_fp_register_operand" "0")))]
16977 + "TARGET_HARD_FLOAT"
16978 + "fmac.d\t%0, %1, %2"
16979 + [(set_attr "length" "4")
16980 + (set_attr "type" "fmul")])
16981 +
16982 +(define_insn "msubacdf3"
16983 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
16984 + (minus:DF (mult:DF (match_operand:DF 1 "avr32_fp_register_operand" "f")
16985 + (match_operand:DF 2 "avr32_fp_register_operand" "f"))
16986 + (match_operand:DF 3 "avr32_fp_register_operand" "0")))]
16987 + "TARGET_HARD_FLOAT"
16988 + "fmsc.d\t%0, %1, %2"
16989 + [(set_attr "length" "4")
16990 + (set_attr "type" "fmul")])
16991 +
16992 +(define_peephole2
16993 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "")
16994 + (mult:DF (match_operand:DF 1 "avr32_fp_register_operand" "")
16995 + (match_operand:DF 2 "avr32_fp_register_operand" "")))
16996 + (set (match_operand:DF 3 "avr32_fp_register_operand" "")
16997 + (minus:DF
16998 + (match_dup 0)
16999 + (match_dup 3)))]
17000 + "TARGET_HARD_FLOAT && peep2_reg_dead_p(2, operands[0])"
17001 + [(set (match_dup 3)
17002 + (minus:DF (mult:DF (match_dup 1)
17003 + (match_dup 2))
17004 + (match_dup 3)))]
17005 + )
17006 +
17007 +(define_insn "nmsubacdf3"
17008 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
17009 + (minus:DF (neg:DF (mult:DF (match_operand:DF 1 "avr32_fp_register_operand" "f")
17010 + (match_operand:DF 2 "avr32_fp_register_operand" "f")))
17011 + (match_operand:DF 3 "avr32_fp_register_operand" "0")))]
17012 + "TARGET_HARD_FLOAT"
17013 + "fnmsc.d\t%0, %1, %2"
17014 + [(set_attr "length" "4")
17015 + (set_attr "type" "fmul")])
17016 +
17017 +(define_insn "nmacdf3"
17018 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
17019 + (plus:DF (neg:DF (mult:DF (match_operand:DF 1 "avr32_fp_register_operand" "f")
17020 + (match_operand:DF 2 "avr32_fp_register_operand" "f")))
17021 + (match_operand:DF 3 "avr32_fp_register_operand" "0")))]
17022 + "TARGET_HARD_FLOAT"
17023 + "fnmac.d\t%0, %1, %2"
17024 + [(set_attr "length" "4")
17025 + (set_attr "type" "fmul")])
17026 +
17027 +(define_peephole2
17028 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "")
17029 + (mult:DF (match_operand:DF 1 "avr32_fp_register_operand" "")
17030 + (match_operand:DF 2 "avr32_fp_register_operand" "")))
17031 + (set (match_operand:DF 3 "avr32_fp_register_operand" "")
17032 + (minus:DF
17033 + (match_dup 3)
17034 + (match_dup 0)))]
17035 + "TARGET_HARD_FLOAT && peep2_reg_dead_p(2, operands[0])"
17036 + [(set (match_dup 3)
17037 + (plus:DF (neg:DF (mult:DF (match_dup 1)
17038 + (match_dup 2)))
17039 + (match_dup 3)))]
17040 +)
17041 +
17042 +(define_insn "adddf3"
17043 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
17044 + (plus:DF (match_operand:DF 1 "avr32_fp_register_operand" "f")
17045 + (match_operand:DF 2 "avr32_fp_register_operand" "f")))]
17046 + "TARGET_HARD_FLOAT"
17047 + "fadd.d\t%0, %1, %2"
17048 + [(set_attr "length" "4")
17049 + (set_attr "type" "fmul")])
17050 +
17051 +(define_insn "subdf3"
17052 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
17053 + (minus:DF (match_operand:DF 1 "avr32_fp_register_operand" "f")
17054 + (match_operand:DF 2 "avr32_fp_register_operand" "f")))]
17055 + "TARGET_HARD_FLOAT"
17056 + "fsub.d\t%0, %1, %2"
17057 + [(set_attr "length" "4")
17058 + (set_attr "type" "fmul")])
17059 +
17060 +(define_insn "negdf2"
17061 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
17062 + (neg:DF (match_operand:DF 1 "avr32_fp_register_operand" "f")))]
17063 + "TARGET_HARD_FLOAT"
17064 + "fneg.d\t%0, %1"
17065 + [(set_attr "length" "4")
17066 + (set_attr "type" "fmv")])
17067 +
17068 +(define_insn "absdf2"
17069 + [(set (match_operand:DF 0 "avr32_fp_register_operand" "=f")
17070 + (abs:DF (match_operand:DF 1 "avr32_fp_register_operand" "f")))]
17071 + "TARGET_HARD_FLOAT"
17072 + "fabs.d\t%0, %1"
17073 + [(set_attr "length" "4")
17074 + (set_attr "type" "fmv")])
17075 +
17076 +
17077 +(define_expand "cmpdf"
17078 + [(set (cc0)
17079 + (compare:DF
17080 + (match_operand:DF 0 "general_operand" "")
17081 + (match_operand:DF 1 "general_operand" "")))]
17082 + "TARGET_HARD_FLOAT"
17083 + "{
17084 + rtx tmpreg;
17085 + if ( !REG_P(operands[0]) )
17086 + operands[0] = force_reg(DFmode, operands[0]);
17087 +
17088 + if ( !REG_P(operands[1]) )
17089 + operands[1] = force_reg(DFmode, operands[1]);
17090 +
17091 + avr32_compare_op0 = operands[0];
17092 + avr32_compare_op1 = operands[1];
17093 +
17094 + emit_insn(gen_cmpdf_internal(operands[0], operands[1]));
17095 +
17096 + tmpreg = gen_reg_rtx(SImode);
17097 + emit_insn(gen_fpcc_to_reg(tmpreg));
17098 + emit_insn(gen_reg_to_cc(tmpreg));
17099 +
17100 + DONE;
17101 + }"
17102 +)
17103 +
17104 +(define_insn "cmpdf_internal"
17105 + [(set (reg:CC FPCC_REGNUM)
17106 + (compare:CC
17107 + (match_operand:DF 0 "avr32_fp_register_operand" "f")
17108 + (match_operand:DF 1 "avr32_fp_register_operand" "f")))]
17109 + "TARGET_HARD_FLOAT"
17110 + {
17111 + if (!rtx_equal_p(cc_prev_status.mdep.fpvalue, SET_SRC(PATTERN (insn))) )
17112 + return "fcmp.d\t%0, %1";
17113 + return "";
17114 + }
17115 + [(set_attr "length" "4")
17116 + (set_attr "type" "fcmpd")
17117 + (set_attr "cc" "fpcompare")])
17118 +
17119 +(define_expand "cmpsf"
17120 + [(set (cc0)
17121 + (compare:SF
17122 + (match_operand:SF 0 "general_operand" "")
17123 + (match_operand:SF 1 "general_operand" "")))]
17124 + "TARGET_HARD_FLOAT"
17125 + "{
17126 + rtx tmpreg;
17127 + if ( !REG_P(operands[0]) )
17128 + operands[0] = force_reg(SFmode, operands[0]);
17129 +
17130 + if ( !REG_P(operands[1]) )
17131 + operands[1] = force_reg(SFmode, operands[1]);
17132 +
17133 + avr32_compare_op0 = operands[0];
17134 + avr32_compare_op1 = operands[1];
17135 +
17136 + emit_insn(gen_cmpsf_internal(operands[0], operands[1]));
17137 +
17138 + tmpreg = gen_reg_rtx(SImode);
17139 + emit_insn(gen_fpcc_to_reg(tmpreg));
17140 + emit_insn(gen_reg_to_cc(tmpreg));
17141 +
17142 + DONE;
17143 + }"
17144 +)
17145 +
17146 +(define_insn "cmpsf_internal"
17147 + [(set (reg:CC FPCC_REGNUM)
17148 + (compare:CC
17149 + (match_operand:SF 0 "avr32_fp_register_operand" "f")
17150 + (match_operand:SF 1 "avr32_fp_register_operand" "f")))]
17151 + "TARGET_HARD_FLOAT"
17152 + {
17153 + if (!rtx_equal_p(cc_prev_status.mdep.fpvalue, SET_SRC(PATTERN (insn))) )
17154 + return "fcmp.s\t%0, %1";
17155 + return "";
17156 + }
17157 + [(set_attr "length" "4")
17158 + (set_attr "type" "fcmps")
17159 + (set_attr "cc" "fpcompare")])
17160 +
17161 +(define_insn "fpcc_to_reg"
17162 + [(set (match_operand:SI 0 "register_operand" "=r")
17163 + (unspec:SI [(reg:CC FPCC_REGNUM)]
17164 + UNSPEC_FPCC_TO_REG))]
17165 + "TARGET_HARD_FLOAT"
17166 + "fmov.s\t%0, fsr"
17167 + [(set_attr "length" "4")
17168 + (set_attr "type" "fmvcpu")])
17169 +
17170 +(define_insn "reg_to_cc"
17171 + [(set (cc0)
17172 + (unspec:SI [(match_operand:SI 0 "register_operand" "r")]
17173 + UNSPEC_REG_TO_CC))]
17174 + "TARGET_HARD_FLOAT"
17175 + "musfr\t%0"
17176 + [(set_attr "length" "2")
17177 + (set_attr "type" "alu")
17178 + (set_attr "cc" "from_fpcc")])
17179 +
17180 +(define_insn "stm_fp"
17181 + [(unspec [(match_operand 0 "register_operand" "r")
17182 + (match_operand 1 "const_int_operand" "")
17183 + (match_operand 2 "const_int_operand" "")]
17184 + UNSPEC_STMFP)]
17185 + "TARGET_HARD_FLOAT"
17186 + {
17187 + int cop_reglist = INTVAL(operands[1]);
17188 +
17189 + if (INTVAL(operands[2]) != 0)
17190 + return "stcm.w\tcp0, --%0, %C1";
17191 + else
17192 + return "stcm.w\tcp0, %0, %C1";
17193 +
17194 + if ( cop_reglist & ~0xff ){
17195 + operands[1] = GEN_INT(cop_reglist & ~0xff);
17196 + if (INTVAL(operands[2]) != 0)
17197 + return "stcm.d\tcp0, --%0, %D1";
17198 + else
17199 + return "stcm.d\tcp0, %0, %D1";
17200 + }
17201 + }
17202 + [(set_attr "type" "fstm")
17203 + (set_attr "length" "4")
17204 + (set_attr "cc" "none")])
17205 --- /dev/null
17206 +++ b/gcc/config/avr32/lib1funcs.S
17207 @@ -0,0 +1,2874 @@
17208 +/* Macro for moving immediate value to register. */
17209 +.macro mov_imm reg, imm
17210 +.if (((\imm & 0xfffff) == \imm) || ((\imm | 0xfff00000) == \imm))
17211 + mov \reg, \imm
17212 +#if __AVR32_UC__ >= 2
17213 +.elseif ((\imm & 0xffff) == 0)
17214 + movh \reg, hi(\imm)
17215 +
17216 +#endif
17217 +.else
17218 + mov \reg, lo(\imm)
17219 + orh \reg, hi(\imm)
17220 +.endif
17221 +.endm
17222 +
17223 +
17224 +
17225 +/* Adjust the unpacked double number if it is a subnormal number.
17226 + The exponent and mantissa pair are stored
17227 + in [mant_hi,mant_lo] and [exp]. A register with the correct sign bit in
17228 + the MSB is passed in [sign]. Needs two scratch
17229 + registers [scratch1] and [scratch2]. An adjusted and packed double float
17230 + is present in [mant_hi,mant_lo] after macro has executed */
17231 +.macro adjust_subnormal_df exp, mant_lo, mant_hi, sign, scratch1, scratch2
17232 + /* We have an exponent which is <=0 indicating a subnormal number
17233 + As it should be stored as if the exponent was 1 (although the
17234 + exponent field is all zeros to indicate a subnormal number)
17235 + we have to shift down the mantissa to its correct position. */
17236 + neg \exp
17237 + sub \exp,-1 /* amount to shift down */
17238 + cp.w \exp,54
17239 + brlo 50f /* if more than 53 shift steps, the
17240 + entire mantissa will disappear
17241 + without any rounding to occur */
17242 + mov \mant_hi, 0
17243 + mov \mant_lo, 0
17244 + rjmp 52f
17245 +50:
17246 + sub \exp,-10 /* do the shift to position the
17247 + mantissa at the same time
17248 + note! this does not include the
17249 + final 1 step shift to add the sign */
17250 +
17251 + /* when shifting, save all shifted out bits in [scratch2]. we may need to
17252 + look at them to make correct rounding. */
17253 +
17254 + rsub \scratch1,\exp,32 /* get inverted shift count */
17255 + cp.w \exp,32 /* handle shifts >= 32 separately */
17256 + brhs 51f
17257 +
17258 + /* small (<32) shift amount, both words are part of the shift */
17259 + lsl \scratch2,\mant_lo,\scratch1 /* save bits to shift out from lsw*/
17260 + lsl \scratch1,\mant_hi,\scratch1 /* get bits from msw destined for lsw*/
17261 + lsr \mant_lo,\mant_lo,\exp /* shift down lsw */
17262 + lsr \mant_hi,\mant_hi,\exp /* shift down msw */
17263 + or \mant_hi,\scratch1 /* add bits from msw with prepared lsw */
17264 + rjmp 50f
17265 +
17266 + /* large (>=32) shift amount, only lsw will have bits left after shift.
17267 + note that shift operations will use ((shift count) mod 32) so
17268 + we do not need to subtract 32 from shift count. */
17269 +51:
17270 + lsl \scratch2,\mant_hi,\scratch1 /* save bits to shift out from msw */
17271 + or \scratch2,\mant_lo /* also save all bits from lsw */
17272 + mov \mant_lo,\mant_hi /* msw -> lsw (i.e. "shift 32 first") */
17273 + mov \mant_hi,0 /* clear msw */
17274 + lsr \mant_lo,\mant_lo,\exp /* make rest of shift inside lsw */
17275 +
17276 +50:
17277 + /* result is almost ready to return, except that least significant bit
17278 + and the part we already shifted out may cause the result to be
17279 + rounded */
17280 + bld \mant_lo,0 /* get bit to be shifted out */
17281 + brcc 51f /* if bit was 0, no rounding */
17282 +
17283 + /* msb of part to remove is 1, so rounding depends on rest of bits */
17284 + tst \scratch2,\scratch2 /* get shifted out tail */
17285 + brne 50f /* if rest > 0, do round */
17286 + bld \mant_lo,1 /* we have to look at lsb in result */
17287 + brcc 51f /* if lsb is 0, don't round */
17288 +
17289 +50:
17290 + /* subnormal result requires rounding
17291 + rounding may cause subnormal to become smallest normal number
17292 + luckily, smallest normal number has exactly the representation
17293 + we got by rippling a one bit up from mantissa into exponent field. */
17294 + sub \mant_lo,-1
17295 + subcc \mant_hi,-1
17296 +
17297 +51:
17298 + /* shift and return packed double with correct sign */
17299 + rol \sign
17300 + ror \mant_hi
17301 + ror \mant_lo
17302 +52:
17303 +.endm
17304 +
17305 +
17306 +/* Adjust subnormal single float number with exponent [exp]
17307 + and mantissa [mant] and round. */
17308 +.macro adjust_subnormal_sf sf, exp, mant, sign, scratch
17309 + /* subnormal number */
17310 + rsub \exp,\exp, 1 /* shift amount */
17311 + cp.w \exp, 25
17312 + movhs \mant, 0
17313 + brhs 90f /* Return zero */
17314 + rsub \scratch, \exp, 32
17315 + lsl \scratch, \mant,\scratch/* Check if there are any bits set
17316 + in the bits discarded in the mantissa */
17317 + srne \scratch /* If so set the lsb of the shifted mantissa */
17318 + lsr \mant,\mant,\exp /* Shift the mantissa */
17319 + or \mant, \scratch /* Round lsb if any bits were shifted out */
17320 + /* Rounding : For explaination, see round_sf. */
17321 + mov \scratch, 0x7f /* Set rounding constant */
17322 + bld \mant, 8
17323 + subeq \scratch, -1 /* For odd numbers use rounding constant 0x80 */
17324 + add \mant, \scratch /* Add rounding constant to mantissa */
17325 + /* We can't overflow because mantissa is at least shifted one position
17326 + to the right so the implicit bit is zero. We can however get the implicit
17327 + bit set after rounding which means that we have the lowest normal number
17328 + but this is ok since this bit has the same position as the LSB of the
17329 + exponent */
17330 + lsr \sf, \mant, 7
17331 + /* Rotate in sign */
17332 + lsl \sign, 1
17333 + ror \sf
17334 +90:
17335 +.endm
17336 +
17337 +
17338 +/* Round the unpacked df number with exponent [exp] and
17339 + mantissa [mant_hi, mant_lo]. Uses scratch register
17340 + [scratch] */
17341 +.macro round_df exp, mant_lo, mant_hi, scratch
17342 + mov \scratch, 0x3ff /* Rounding constant */
17343 + bld \mant_lo,11 /* Check if lsb in the final result is
17344 + set */
17345 + subeq \scratch, -1 /* Adjust rounding constant to 0x400
17346 + if rounding 0.5 upwards */
17347 + add \mant_lo, \scratch /* Round */
17348 + acr \mant_hi /* If overflowing we know that
17349 + we have all zeros in the bits not
17350 + scaled out so we can leave them
17351 + but we must increase the exponent with
17352 + two since we had an implicit bit
17353 + which is lost + the extra overflow bit */
17354 + subcs \exp, -2 /* Update exponent */
17355 +.endm
17356 +
17357 +/* Round single float number stored in [mant] and [exp] */
17358 +.macro round_sf exp, mant, scratch
17359 + /* Round:
17360 + For 0.5 we round to nearest even integer
17361 + for all other cases we round to nearest integer.
17362 + This means that if the digit left of the "point" (.)
17363 + is 1 we can add 0x80 to the mantissa since the
17364 + corner case 0x180 will round up to 0x200. If the
17365 + digit left of the "point" is 0 we will have to
17366 + add 0x7f since this will give 0xff and hence a
17367 + truncation/rounding downwards for the corner
17368 + case when the 9 lowest bits are 0x080 */
17369 + mov \scratch, 0x7f /* Set rounding constant */
17370 + /* Check if the mantissa is even or odd */
17371 + bld \mant, 8
17372 + subeq \scratch, -1 /* Rounding constant should be 0x80 */
17373 + add \mant, \scratch
17374 + subcs \exp, -2 /* Adjust exponent if we overflowed */
17375 +.endm
17376 +
17377 +
17378 +
17379 +/* Pack a single float number stored in [mant] and [exp]
17380 + into a single float number in [sf] */
17381 +.macro pack_sf sf, exp, mant
17382 + bld \mant,31 /* implicit bit to z */
17383 + subne \exp,1 /* if subnormal (implicit bit 0)
17384 + adjust exponent to storage format */
17385 +
17386 + lsr \sf, \mant, 7
17387 + bfins \sf, \exp, 24, 8
17388 +.endm
17389 +
17390 +/* Pack exponent [exp] and mantissa [mant_hi, mant_lo]
17391 + into [df_hi, df_lo]. [df_hi] is shifted
17392 + one bit up so the sign bit can be shifted into it */
17393 +
17394 +.macro pack_df exp, mant_lo, mant_hi, df_lo, df_hi
17395 + bld \mant_hi,31 /* implicit bit to z */
17396 + subne \exp,1 /* if subnormal (implicit bit 0)
17397 + adjust exponent to storage format */
17398 +
17399 + lsr \mant_lo,11 /* shift back lsw */
17400 + or \df_lo,\mant_lo,\mant_hi<<21 /* combine with low bits from msw */
17401 + lsl \mant_hi,1 /* get rid of implicit bit */
17402 + lsr \mant_hi,11 /* shift back msw except for one step*/
17403 + or \df_hi,\mant_hi,\exp<<21 /* combine msw with exponent */
17404 +.endm
17405 +
17406 +/* Normalize single float number stored in [mant] and [exp]
17407 + using scratch register [scratch] */
17408 +.macro normalize_sf exp, mant, scratch
17409 + /* Adjust exponent and mantissa */
17410 + clz \scratch, \mant
17411 + sub \exp, \scratch
17412 + lsl \mant, \mant, \scratch
17413 +.endm
17414 +
17415 +/* Normalize the exponent and mantissa pair stored
17416 + in [mant_hi,mant_lo] and [exp]. Needs two scratch
17417 + registers [scratch1] and [scratch2]. */
17418 +.macro normalize_df exp, mant_lo, mant_hi, scratch1, scratch2
17419 + clz \scratch1,\mant_hi /* Check if we have zeros in high bits */
17420 + breq 80f /* No need for scaling if no zeros in high bits */
17421 + brcs 81f /* Check for all zeros */
17422 +
17423 + /* shift amount is smaller than 32, and involves both msw and lsw*/
17424 + rsub \scratch2,\scratch1,32 /* shift mantissa */
17425 + lsl \mant_hi,\mant_hi,\scratch1
17426 + lsr \scratch2,\mant_lo,\scratch2
17427 + or \mant_hi,\scratch2
17428 + lsl \mant_lo,\mant_lo,\scratch1
17429 + sub \exp,\scratch1 /* adjust exponent */
17430 + rjmp 80f /* Finished */
17431 +81:
17432 + /* shift amount is greater than 32 */
17433 + clz \scratch1,\mant_lo /* shift mantissa */
17434 + movcs \scratch1, 0
17435 + subcc \scratch1,-32
17436 + lsl \mant_hi,\mant_lo,\scratch1
17437 + mov \mant_lo,0
17438 + sub \exp,\scratch1 /* adjust exponent */
17439 +80:
17440 +.endm
17441 +
17442 +
17443 +/* Fast but approximate multiply of two 64-bit numbers to give a 64 bit result.
17444 + The multiplication of [al]x[bl] is discarded.
17445 + Operands in [ah], [al], [bh], [bl].
17446 + Scratch registers in [sh], [sl].
17447 + Returns results in registers [rh], [rl].*/
17448 +.macro mul_approx_df ah, al, bh, bl, rh, rl, sh, sl
17449 + mulu.d \sl, \ah, \bl
17450 + macu.d \sl, \al, \bh
17451 + mulu.d \rl, \ah, \bh
17452 + add \rl, \sh
17453 + acr \rh
17454 +.endm
17455 +
17456 +
17457 +
17458 +#if defined(L_avr32_f64_mul) || defined(L_avr32_f64_mul_fast)
17459 + .align 2
17460 +#if defined(L_avr32_f64_mul)
17461 + .global __avr32_f64_mul
17462 + .type __avr32_f64_mul,@function
17463 +__avr32_f64_mul:
17464 +#else
17465 + .global __avr32_f64_mul_fast
17466 + .type __avr32_f64_mul_fast,@function
17467 +__avr32_f64_mul_fast:
17468 +#endif
17469 + or r12, r10, r11 << 1
17470 + breq __avr32_f64_mul_op1_zero
17471 +
17472 +#if defined(L_avr32_f64_mul)
17473 + pushm r4-r7, lr
17474 +#else
17475 + stm --sp, r5,r6,r7,lr
17476 +#endif
17477 +
17478 +#define AVR32_F64_MUL_OP1_INT_BITS 1
17479 +#define AVR32_F64_MUL_OP2_INT_BITS 10
17480 +#define AVR32_F64_MUL_RES_INT_BITS 11
17481 +
17482 + /* op1 in {r11,r10}*/
17483 + /* op2 in {r9,r8}*/
17484 + eor lr, r11, r9 /* MSB(lr) = Sign(op1) ^ Sign(op2) */
17485 +
17486 + /* Unpack op1 to 1.63 format*/
17487 + /* exp: r7 */
17488 + /* sf: r11, r10 */
17489 + bfextu r7, r11, 20, 11 /* Extract exponent */
17490 +
17491 + mov r5, 1
17492 +
17493 + /* Check if normalization is needed */
17494 + breq __avr32_f64_mul_op1_subnormal /*If number is subnormal, normalize it */
17495 +
17496 + lsl r11, (12-AVR32_F64_MUL_OP1_INT_BITS-1) /* Extract mantissa, leave room for implicit bit */
17497 + or r11, r11, r10>>(32-(12-AVR32_F64_MUL_OP1_INT_BITS-1))
17498 + lsl r10, (12-AVR32_F64_MUL_OP1_INT_BITS-1)
17499 + bfins r11, r5, 32 - (1 + AVR32_F64_MUL_OP1_INT_BITS), 1 + AVR32_F64_MUL_OP1_INT_BITS /* Insert implicit bit */
17500 +
17501 +
17502 +22:
17503 + /* Unpack op2 to 10.54 format */
17504 + /* exp: r6 */
17505 + /* sf: r9, r8 */
17506 + bfextu r6, r9, 20, 11 /* Extract exponent */
17507 +
17508 + /* Check if normalization is needed */
17509 + breq __avr32_f64_mul_op2_subnormal /*If number is subnormal, normalize it */
17510 +
17511 + lsl r8, 1 /* Extract mantissa, leave room for implicit bit */
17512 + rol r9
17513 + bfins r9, r5, 32 - (1 + AVR32_F64_MUL_OP2_INT_BITS), 1 + AVR32_F64_MUL_OP2_INT_BITS /* Insert implicit bit */
17514 +
17515 +23:
17516 +
17517 + /* Check if any operands are NaN or INF */
17518 + cp r7, 0x7ff
17519 + breq __avr32_f64_mul_op_nan_or_inf /* Check op1 for NaN or Inf */
17520 + cp r6, 0x7ff
17521 + breq __avr32_f64_mul_op_nan_or_inf /* Check op2 for NaN or Inf */
17522 +
17523 +
17524 + /* Calculate new exponent in r12*/
17525 + add r12, r7, r6
17526 + sub r12, (1023-1)
17527 +
17528 +#if defined(L_avr32_f64_mul)
17529 + /* Do the multiplication.
17530 + Place result in [r11, r10, r7, r6]. The result is in 11.117 format. */
17531 + mulu.d r4, r11, r8
17532 + macu.d r4, r10, r9
17533 + mulu.d r6, r10, r8
17534 + mulu.d r10, r11, r9
17535 + add r7, r4
17536 + adc r10, r10, r5
17537 + acr r11
17538 +#else
17539 + /* Do the multiplication using approximate calculation. discard the al x bl
17540 + calculation.
17541 + Place result in [r11, r10, r7]. The result is in 11.85 format. */
17542 +
17543 + /* Do the multiplication using approximate calculation.
17544 + Place result in r11, r10. Use r7, r6 as scratch registers */
17545 + mulu.d r6, r11, r8
17546 + macu.d r6, r10, r9
17547 + mulu.d r10, r11, r9
17548 + add r10, r7
17549 + acr r11
17550 +#endif
17551 + /* Adjust exponent and mantissa */
17552 + /* [r12]:exp, [r11, r10]:mant [r7, r6]:sticky bits */
17553 + /* Mantissa may be of the format 00000000000.0xxx or 00000000000.1xxx. */
17554 + /* In the first case, shift one pos to left.*/
17555 + bld r11, 32-AVR32_F64_MUL_RES_INT_BITS-1
17556 + breq 0f
17557 + lsl r7, 1
17558 + rol r10
17559 + rol r11
17560 + sub r12, 1
17561 +0:
17562 + cp r12, 0
17563 + brle __avr32_f64_mul_res_subnormal /*Result was subnormal.*/
17564 +
17565 + /* Check for Inf. */
17566 + cp.w r12, 0x7ff
17567 + brge __avr32_f64_mul_res_inf
17568 +
17569 + /* Insert exponent. */
17570 + bfins r11, r12, 20, 11
17571 +
17572 + /* Result was not subnormal. Perform rounding. */
17573 + /* For the fast version we discard the sticky bits and always round
17574 + the halfwaycase up. */
17575 +24:
17576 +#if defined(L_avr32_f64_mul)
17577 + or r6, r6, r10 << 31 /* Or in parity bit into stickybits */
17578 + or r7, r7, r6 >> 1 /* Or together sticky and still make the msb
17579 + of r7 represent the halfway bit. */
17580 + eorh r7, 0x8000 /* Toggle halfway bit. */
17581 + /* We should now round up by adding one for the following cases:
17582 +
17583 + halfway sticky|parity round-up
17584 + 0 x no
17585 + 1 0 no
17586 + 1 1 yes
17587 +
17588 + Since we have inverted the halfway bit we can use the satu instruction
17589 + by saturating to 1 bit to implement this.
17590 + */
17591 + satu r7 >> 0, 1
17592 +#else
17593 + lsr r7, 31
17594 +#endif
17595 + add r10, r7
17596 + acr r11
17597 +
17598 + /* Insert sign bit*/
17599 + bld lr, 31
17600 + bst r11, 31
17601 +
17602 + /* Return result in [r11,r10] */
17603 +#if defined(L_avr32_f64_mul)
17604 + popm r4-r7, pc
17605 +#else
17606 + ldm sp++, r5, r6, r7,pc
17607 +#endif
17608 +
17609 +
17610 +__avr32_f64_mul_op1_subnormal:
17611 + andh r11, 0x000f /* Remove sign bit and exponent */
17612 + clz r12, r10 /* Count leading zeros in lsw */
17613 + clz r6, r11 /* Count leading zeros in msw */
17614 + subcs r12, -32 + AVR32_F64_MUL_OP1_INT_BITS
17615 + movcs r6, r12
17616 + subcc r6, AVR32_F64_MUL_OP1_INT_BITS
17617 + cp.w r6, 32
17618 + brge 0f
17619 +
17620 + /* shifting involves both msw and lsw*/
17621 + rsub r12, r6, 32 /* shift mantissa */
17622 + lsl r11, r11, r6
17623 + lsr r12, r10, r12
17624 + or r11, r12
17625 + lsl r10, r10, r6
17626 + sub r6, 12-AVR32_F64_MUL_OP1_INT_BITS
17627 + sub r7, r6 /* adjust exponent */
17628 + rjmp 22b /* Finished */
17629 +0:
17630 + /* msw is zero so only need to consider lsw */
17631 + lsl r11, r10, r6
17632 + breq __avr32_f64_mul_res_zero
17633 + mov r10, 0
17634 + sub r6, 12-AVR32_F64_MUL_OP1_INT_BITS
17635 + sub r7, r6 /* adjust exponent */
17636 + rjmp 22b
17637 +
17638 +
17639 +__avr32_f64_mul_op2_subnormal:
17640 + andh r9, 0x000f /* Remove sign bit and exponent */
17641 + clz r12, r8 /* Count leading zeros in lsw */
17642 + clz r5, r9 /* Count leading zeros in msw */
17643 + subcs r12, -32 + AVR32_F64_MUL_OP2_INT_BITS
17644 + movcs r5, r12
17645 + subcc r5, AVR32_F64_MUL_OP2_INT_BITS
17646 + cp.w r5, 32
17647 + brge 0f
17648 +
17649 + /* shifting involves both msw and lsw*/
17650 + rsub r12, r5, 32 /* shift mantissa */
17651 + lsl r9, r9, r5
17652 + lsr r12, r8, r12
17653 + or r9, r12
17654 + lsl r8, r8, r5
17655 + sub r5, 12 - AVR32_F64_MUL_OP2_INT_BITS
17656 + sub r6, r5 /* adjust exponent */
17657 + rjmp 23b /* Finished */
17658 +0:
17659 + /* msw is zero so only need to consider lsw */
17660 + lsl r9, r8, r5
17661 + breq __avr32_f64_mul_res_zero
17662 + mov r8, 0
17663 + sub r5, 12 - AVR32_F64_MUL_OP2_INT_BITS
17664 + sub r6, r5 /* adjust exponent */
17665 + rjmp 23b
17666 +
17667 +
17668 +__avr32_f64_mul_op_nan_or_inf:
17669 + /* Same code for OP1 and OP2*/
17670 + /* Since we are here, at least one of the OPs were NaN or INF*/
17671 + andh r9, 0x000f /* Remove sign bit and exponent */
17672 + andh r11, 0x000f /* Remove sign bit and exponent */
17673 + /* Merge the regs in each operand to check for zero*/
17674 + or r11, r10 /* op1 */
17675 + or r9, r8 /* op2 */
17676 + /* Check if op1 is NaN or INF */
17677 + cp r7, 0x7ff
17678 + brne __avr32_f64_mul_op1_not_naninf
17679 + /* op1 was NaN or INF.*/
17680 + cp r11, 0
17681 + brne __avr32_f64_mul_res_nan /* op1 was NaN. Result will be NaN*/
17682 + /*op1 was INF. check if op2 is NaN or INF*/
17683 + cp r6, 0x7ff
17684 + brne __avr32_f64_mul_res_inf /*op1 was INF, op2 was neither NaN nor INF*/
17685 + /* op1 is INF, op2 is either NaN or INF*/
17686 + cp r9, 0
17687 + breq __avr32_f64_mul_res_inf /*op2 was also INF*/
17688 + rjmp __avr32_f64_mul_res_nan /*op2 was NaN*/
17689 +
17690 +__avr32_f64_mul_op1_not_naninf:
17691 + /* op1 was not NaN nor INF. Then op2 must be NaN or INF*/
17692 + cp r9, 0
17693 + breq __avr32_f64_mul_res_inf /*op2 was INF, return INF*/
17694 + rjmp __avr32_f64_mul_res_nan /*else return NaN*/
17695 +
17696 +__avr32_f64_mul_res_subnormal:/* Multiply result was subnormal. */
17697 +#if defined(L_avr32_f64_mul)
17698 + /* Check how much we must scale down the mantissa. */
17699 + neg r12
17700 + sub r12, -1 /* We do no longer have an implicit bit. */
17701 + satu r12 >> 0, 6 /* Saturate shift amount to max 63. */
17702 + cp.w r12, 32
17703 + brge 0f
17704 + /* Shift amount <32 */
17705 + rsub r8, r12, 32
17706 + or r6, r7
17707 + lsr r7, r7, r12
17708 + lsl r9, r10, r8
17709 + or r7, r9
17710 + lsr r10, r10, r12
17711 + lsl r9, r11, r8
17712 + or r10, r9
17713 + lsr r11, r11, r12
17714 + rjmp 24b
17715 +0:
17716 + /* Shift amount >=32 */
17717 + rsub r8, r12, 32
17718 + moveq r9, 0
17719 + breq 0f
17720 + lsl r9, r11, r8
17721 +0:
17722 + or r6, r7
17723 + or r6, r6, r10 << 1
17724 + lsr r10, r10, r12
17725 + or r7, r9, r10
17726 + lsr r10, r11, r12
17727 + mov r11, 0
17728 + rjmp 24b
17729 +#else
17730 + /* Flush to zero for the fast version. */
17731 + mov r11, lr /*Get correct sign*/
17732 + andh r11, 0x8000, COH
17733 + mov r10, 0
17734 + ldm sp++, r5, r6, r7,pc
17735 +#endif
17736 +
17737 +__avr32_f64_mul_res_zero:/* Multiply result is zero. */
17738 + mov r11, lr /*Get correct sign*/
17739 + andh r11, 0x8000, COH
17740 + mov r10, 0
17741 +#if defined(L_avr32_f64_mul)
17742 + popm r4-r7, pc
17743 +#else
17744 + ldm sp++, r5, r6, r7,pc
17745 +#endif
17746 +
17747 +__avr32_f64_mul_res_nan: /* Return NaN. */
17748 + mov r11, -1
17749 + mov r10, -1
17750 +#if defined(L_avr32_f64_mul)
17751 + popm r4-r7, pc
17752 +#else
17753 + ldm sp++, r5, r6, r7,pc
17754 +#endif
17755 +
17756 +__avr32_f64_mul_res_inf: /* Return INF. */
17757 + mov r11, 0xfff00000
17758 + bld lr, 31
17759 + bst r11, 31
17760 + mov r10, 0
17761 +#if defined(L_avr32_f64_mul)
17762 + popm r4-r7, pc
17763 +#else
17764 + ldm sp++, r5, r6, r7,pc
17765 +#endif
17766 +
17767 +__avr32_f64_mul_op1_zero:
17768 + /* Get sign */
17769 + eor r11, r11, r9
17770 + andh r11, 0x8000, COH
17771 + /* Check if op2 is Inf or NaN. */
17772 + bfextu r12, r9, 20, 11
17773 + cp.w r12, 0x7ff
17774 + retne r12 /* Return 0.0 */
17775 + /* Return NaN */
17776 + mov r10, -1
17777 + mov r11, -1
17778 + ret r12
17779 +
17780 +
17781 +
17782 +#endif
17783 +
17784 +
17785 +#if defined(L_avr32_f64_addsub) || defined(L_avr32_f64_addsub_fast)
17786 + .align 2
17787 +
17788 +__avr32_f64_sub_from_add:
17789 + /* Switch sign on op2 */
17790 + eorh r9, 0x8000
17791 +
17792 +#if defined(L_avr32_f64_addsub_fast)
17793 + .global __avr32_f64_sub_fast
17794 + .type __avr32_f64_sub_fast,@function
17795 +__avr32_f64_sub_fast:
17796 +#else
17797 + .global __avr32_f64_sub
17798 + .type __avr32_f64_sub,@function
17799 +__avr32_f64_sub:
17800 +#endif
17801 +
17802 + /* op1 in {r11,r10}*/
17803 + /* op2 in {r9,r8}*/
17804 +
17805 +#if defined(L_avr32_f64_addsub_fast)
17806 + /* If op2 is zero just return op1 */
17807 + or r12, r8, r9 << 1
17808 + reteq r12
17809 +#endif
17810 +
17811 + /* Check signs */
17812 + eor r12, r11, r9
17813 + /* Different signs, use addition. */
17814 + brmi __avr32_f64_add_from_sub
17815 +
17816 + stm --sp, r5, r6, r7, lr
17817 +
17818 + /* Get sign of op1 into r12 */
17819 + mov r12, r11
17820 + andh r12, 0x8000, COH
17821 +
17822 + /* Remove sign from operands */
17823 + cbr r11, 31
17824 + cbr r9, 31
17825 +
17826 + /* Put the largest number in [r11, r10]
17827 + and the smallest number in [r9, r8] */
17828 + cp r10, r8
17829 + cpc r11, r9
17830 + brhs 1f /* Skip swap if operands already correctly ordered*/
17831 + /* Operands were not correctly ordered, swap them*/
17832 + mov r7, r11
17833 + mov r11, r9
17834 + mov r9, r7
17835 + mov r7, r10
17836 + mov r10, r8
17837 + mov r8, r7
17838 + eorh r12, 0x8000 /* Invert sign in r12*/
17839 +1:
17840 + /* Unpack largest operand - opH */
17841 + /* exp: r7 */
17842 + /* sf: r11, r10 */
17843 + lsr r7, r11, 20 /* Extract exponent */
17844 + lsl r11, 11 /* Extract mantissa, leave room for implicit bit */
17845 + or r11, r11, r10>>21
17846 + lsl r10, 11
17847 + sbr r11, 31 /* Insert implicit bit */
17848 +
17849 +
17850 + /* Unpack smallest operand - opL */
17851 + /* exp: r6 */
17852 + /* sf: r9, r8 */
17853 + lsr r6, r9, 20 /* Extract exponent */
17854 + breq __avr32_f64_sub_opL_subnormal /* If either zero or subnormal */
17855 + lsl r9, 11 /* Extract mantissa, leave room for implicit bit */
17856 + or r9, r9, r8>>21
17857 + lsl r8, 11
17858 + sbr r9, 31 /* Insert implicit bit */
17859 +
17860 +
17861 +__avr32_f64_sub_opL_subnormal_done:
17862 + /* opH is NaN or Inf. */
17863 + cp.w r7, 0x7ff
17864 + breq __avr32_f64_sub_opH_nan_or_inf
17865 +
17866 + /* Get shift amount to scale mantissa of op2. */
17867 + rsub r6, r7
17868 + breq __avr32_f64_sub_shift_done /* No need to shift, exponents are equal*/
17869 +
17870 + /* Scale mantissa [r9, r8] with amount [r6].
17871 + Uses scratch registers [r5] and [lr].
17872 + In IEEE mode:Must not forget the sticky bits we intend to shift out. */
17873 +
17874 + rsub r5,r6,32 /* get (32 - shift count)
17875 + (if shift count > 32 we get a
17876 + negative value, but that will
17877 + work as well in the code below.) */
17878 +
17879 + cp.w r6,32 /* handle shifts >= 32 separately */
17880 + brhs __avr32_f64_sub_longshift
17881 +
17882 + /* small (<32) shift amount, both words are part of the shift
17883 + first remember whether part that is lost contains any 1 bits ... */
17884 + lsl lr,r8,r5 /* shift away bits that are part of
17885 + final mantissa. only part that goes
17886 + to lr are bits that will be lost */
17887 +
17888 + /* ... and now to the actual shift */
17889 + lsl r5,r9,r5 /* get bits from msw destined for lsw*/
17890 + lsr r8,r8,r6 /* shift down lsw of mantissa */
17891 + lsr r9,r9,r6 /* shift down msw of mantissa */
17892 + or r8,r5 /* combine these bits with prepared lsw*/
17893 +#if defined(L_avr32_f64_addsub)
17894 + cp.w lr,0 /* if any '1' bit in part we lost ...*/
17895 + srne lr
17896 + or r8, lr /* ... we need to set sticky bit*/
17897 +#endif
17898 +
17899 +__avr32_f64_sub_shift_done:
17900 + /* Now subtract the mantissas. */
17901 + sub r10, r8
17902 + sbc r11, r11, r9
17903 +
17904 + /* Normalize the exponent and mantissa pair stored in
17905 + [r11,r10] and exponent in [r7]. Needs two scratch registers [r6] and [lr]. */
17906 + clz r6,r11 /* Check if we have zeros in high bits */
17907 + breq __avr32_f64_sub_longnormalize_done /* No need for scaling if no zeros in high bits */
17908 + brcs __avr32_f64_sub_longnormalize
17909 +
17910 +
17911 + /* shift amount is smaller than 32, and involves both msw and lsw*/
17912 + rsub lr,r6,32 /* shift mantissa */
17913 + lsl r11,r11,r6
17914 + lsr lr,r10,lr
17915 + or r11,lr
17916 + lsl r10,r10,r6
17917 +
17918 + sub r7,r6 /* adjust exponent */
17919 + brle __avr32_f64_sub_subnormal_result
17920 +__avr32_f64_sub_longnormalize_done:
17921 +
17922 +#if defined(L_avr32_f64_addsub)
17923 + /* Insert the bits we will remove from the mantissa r9[31:21] */
17924 + lsl r9, r10, (32 - 11)
17925 +#else
17926 + /* Keep the last bit shifted out. */
17927 + bfextu r9, r10, 10, 1
17928 +#endif
17929 +
17930 + /* Pack final result*/
17931 + /* Input: [r7]:exp, [r11, r10]:mant, [r12]:sign in MSB */
17932 + /* Result in [r11,r10] */
17933 + /* Insert mantissa */
17934 + lsr r10, 11
17935 + or r10, r10, r11<<21
17936 + lsr r11, 11
17937 + /* Insert exponent and sign bit*/
17938 + bfins r11, r7, 20, 11
17939 + or r11, r12
17940 +
17941 + /* Round */
17942 +__avr32_f64_sub_round:
17943 +#if defined(L_avr32_f64_addsub)
17944 + mov_imm r7, 0x80000000
17945 + bld r10, 0
17946 + subne r7, -1
17947 +
17948 + cp.w r9, r7
17949 + srhs r9
17950 +#endif
17951 + add r10, r9
17952 + acr r11
17953 +
17954 + /* Return result in [r11,r10] */
17955 + ldm sp++, r5, r6, r7,pc
17956 +
17957 +
17958 +
17959 +__avr32_f64_sub_opL_subnormal:
17960 + /* Extract the of mantissa */
17961 + lsl r9, 11 /* Extract mantissa, leave room for implicit bit */
17962 + or r9, r9, r8>>21
17963 + lsl r8, 11
17964 +
17965 + /* Set exponent to 1 if we do not have a zero. */
17966 + or lr, r9, r8
17967 + movne r6,1
17968 +
17969 + /* Check if opH is also subnormal. If so, clear implicit bit in r11*/
17970 + rsub lr, r7, 0
17971 + moveq r7,1
17972 + bst r11, 31
17973 +
17974 + /* Check if op1 is zero, if so set exponent to 0. */
17975 + or lr, r11, r10
17976 + moveq r7,0
17977 +
17978 + rjmp __avr32_f64_sub_opL_subnormal_done
17979 +
17980 +__avr32_f64_sub_opH_nan_or_inf:
17981 + /* Check if opH is NaN, if so return NaN */
17982 + cbr r11, 31
17983 + or lr, r11, r10
17984 + brne __avr32_f64_sub_return_nan
17985 +
17986 + /* opH is Inf. */
17987 + /* Check if opL is Inf. or NaN */
17988 + cp.w r6, 0x7ff
17989 + breq __avr32_f64_sub_return_nan
17990 + /* Return infinity with correct sign. */
17991 + or r11, r12, r7 << 20
17992 + ldm sp++, r5, r6, r7, pc/* opL not Inf or NaN, return opH */
17993 +__avr32_f64_sub_return_nan:
17994 + mov r10, -1 /* Generate NaN in r11, r10 */
17995 + mov r11, -1
17996 + ldm sp++, r5, r6, r7, pc/* opL Inf or NaN, return NaN */
17997 +
17998 +
17999 +__avr32_f64_sub_subnormal_result:
18000 +#if defined(L_avr32_f64_addsub)
18001 + /* Check how much we must scale down the mantissa. */
18002 + neg r7
18003 + sub r7, -1 /* We do no longer have an implicit bit. */
18004 + satu r7 >> 0, 6 /* Saturate shift amount to max 63. */
18005 + cp.w r7, 32
18006 + brge 0f
18007 + /* Shift amount <32 */
18008 + rsub r8, r7, 32
18009 + lsl r9, r10, r8
18010 + srne r6
18011 + lsr r10, r10, r7
18012 + or r10, r6 /* Sticky bit from the
18013 + part that was shifted out. */
18014 + lsl r9, r11, r8
18015 + or r10, r10, r9
18016 + lsr r11, r10, r7
18017 + /* Set exponent */
18018 + mov r7, 0
18019 + rjmp __avr32_f64_sub_longnormalize_done
18020 +0:
18021 + /* Shift amount >=32 */
18022 + rsub r8, r7, 64
18023 + lsl r9, r11, r8
18024 + or r9, r10
18025 + srne r6
18026 + lsr r10, r11, r7
18027 + or r10, r6 /* Sticky bit from the
18028 + part that was shifted out. */
18029 + mov r11, 0
18030 + /* Set exponent */
18031 + mov r7, 0
18032 + rjmp __avr32_f64_sub_longnormalize_done
18033 +#else
18034 + /* Just flush subnormals to zero. */
18035 + mov r10, 0
18036 + mov r11, 0
18037 +#endif
18038 + ldm sp++, r5, r6, r7, pc
18039 +
18040 +__avr32_f64_sub_longshift:
18041 + /* large (>=32) shift amount, only lsw will have bits left after shift.
18042 + note that shift operations will use ((shift count=r6) mod 32) so
18043 + we do not need to subtract 32 from shift count. */
18044 + /* Saturate the shift amount to 63. If the amount
18045 + is any larger op2 is insignificant. */
18046 + satu r6 >> 0, 6
18047 +
18048 +#if defined(L_avr32_f64_addsub)
18049 + /* first remember whether part that is lost contains any 1 bits ... */
18050 + moveq lr, r8 /* If shift amount is 32, no bits from msw are lost. */
18051 + breq 0f
18052 + lsl lr,r9,r5 /* save all lost bits from msw */
18053 + or lr,r8 /* also save lost bits (all) from lsw
18054 + now lr != 0 if we lose any bits */
18055 +#endif
18056 +0:
18057 + /* ... and now to the actual shift */
18058 + lsr r8,r9,r6 /* Move msw to lsw and shift. */
18059 + mov r9,0 /* clear msw */
18060 +#if defined(L_avr32_f64_addsub)
18061 + cp.w lr,0 /* if any '1' bit in part we lost ...*/
18062 + srne lr
18063 + or r8, lr /* ... we need to set sticky bit*/
18064 +#endif
18065 + rjmp __avr32_f64_sub_shift_done
18066 +
18067 +__avr32_f64_sub_longnormalize:
18068 + /* shift amount is greater than 32 */
18069 + clz r6,r10 /* shift mantissa */
18070 + /* If the resulting mantissa is zero the result is
18071 + zero so force exponent to zero. */
18072 + movcs r7, 0
18073 + movcs r6, 0
18074 + movcs r12, 0 /* Also clear sign bit. A zero result from subtraction
18075 + always is +0.0 */
18076 + subcc r6,-32
18077 + lsl r11,r10,r6
18078 + mov r10,0
18079 + sub r7,r6 /* adjust exponent */
18080 + brle __avr32_f64_sub_subnormal_result
18081 + rjmp __avr32_f64_sub_longnormalize_done
18082 +
18083 +
18084 +
18085 + .align 2
18086 +__avr32_f64_add_from_sub:
18087 + /* Switch sign on op2 */
18088 + eorh r9, 0x8000
18089 +
18090 +#if defined(L_avr32_f64_addsub_fast)
18091 + .global __avr32_f64_add_fast
18092 + .type __avr32_f64_add_fast,@function
18093 +__avr32_f64_add_fast:
18094 +#else
18095 + .global __avr32_f64_add
18096 + .type __avr32_f64_add,@function
18097 +__avr32_f64_add:
18098 +#endif
18099 +
18100 + /* op1 in {r11,r10}*/
18101 + /* op2 in {r9,r8}*/
18102 +
18103 +#if defined(L_avr32_f64_addsub_fast)
18104 + /* If op2 is zero just return op1 */
18105 + or r12, r8, r9 << 1
18106 + reteq r12
18107 +#endif
18108 +
18109 + /* Check signs */
18110 + eor r12, r11, r9
18111 + /* Different signs, use subtraction. */
18112 + brmi __avr32_f64_sub_from_add
18113 +
18114 + stm --sp, r5, r6, r7, lr
18115 +
18116 + /* Get sign of op1 into r12 */
18117 + mov r12, r11
18118 + andh r12, 0x8000, COH
18119 +
18120 + /* Remove sign from operands */
18121 + cbr r11, 31
18122 + cbr r9, 31
18123 +
18124 + /* Put the number with the largest exponent in [r11, r10]
18125 + and the number with the smallest exponent in [r9, r8] */
18126 + cp r11, r9
18127 + brhs 1f /* Skip swap if operands already correctly ordered */
18128 + /* Operands were not correctly ordered, swap them */
18129 + mov r7, r11
18130 + mov r11, r9
18131 + mov r9, r7
18132 + mov r7, r10
18133 + mov r10, r8
18134 + mov r8, r7
18135 +1:
18136 + mov lr, 0 /* Set sticky bits to zero */
18137 + /* Unpack largest operand - opH */
18138 + /* exp: r7 */
18139 + /* sf: r11, r10 */
18140 + bfextu R7, R11, 20, 11 /* Extract exponent */
18141 + bfextu r11, r11, 0, 20 /* Extract mantissa */
18142 + sbr r11, 20 /* Insert implicit bit */
18143 +
18144 + /* Unpack smallest operand - opL */
18145 + /* exp: r6 */
18146 + /* sf: r9, r8 */
18147 + bfextu R6, R9, 20, 11 /* Extract exponent */
18148 + breq __avr32_f64_add_op2_subnormal
18149 + bfextu r9, r9, 0, 20 /* Extract mantissa */
18150 + sbr r9, 20 /* Insert implicit bit */
18151 +
18152 +2:
18153 + /* opH is NaN or Inf. */
18154 + cp.w r7, 0x7ff
18155 + breq __avr32_f64_add_opH_nan_or_inf
18156 +
18157 + /* Get shift amount to scale mantissa of op2. */
18158 + rsub r6, r7
18159 + breq __avr32_f64_add_shift_done /* No need to shift, exponents are equal*/
18160 +
18161 + /* Scale mantissa [r9, r8] with amount [r6].
18162 + Uses scratch registers [r5] and [lr].
18163 + In IEEE mode:Must not forget the sticky bits we intend to shift out. */
18164 + rsub r5,r6,32 /* get (32 - shift count)
18165 + (if shift count > 32 we get a
18166 + negative value, but that will
18167 + work as well in the code below.) */
18168 +
18169 + cp.w r6,32 /* handle shifts >= 32 separately */
18170 + brhs __avr32_f64_add_longshift
18171 +
18172 + /* small (<32) shift amount, both words are part of the shift
18173 + first remember whether part that is lost contains any 1 bits ... */
18174 + lsl lr,r8,r5 /* shift away bits that are part of
18175 + final mantissa. only part that goes
18176 + to lr are bits that will be lost */
18177 +
18178 + /* ... and now to the actual shift */
18179 + lsl r5,r9,r5 /* get bits from msw destined for lsw*/
18180 + lsr r8,r8,r6 /* shift down lsw of mantissa */
18181 + lsr r9,r9,r6 /* shift down msw of mantissa */
18182 + or r8,r5 /* combine these bits with prepared lsw*/
18183 +
18184 +__avr32_f64_add_shift_done:
18185 + /* Now add the mantissas. */
18186 + add r10, r8
18187 + adc r11, r11, r9
18188 +
18189 + /* Check if we overflowed. */
18190 + bld r11, 21
18191 + breq __avr32_f64_add_res_of:
18192 +
18193 +__avr32_f64_add_res_of_done:
18194 +
18195 + /* Pack final result*/
18196 + /* Input: [r7]:exp, [r11, r10]:mant, [r12]:sign in MSB */
18197 + /* Result in [r11,r10] */
18198 + /* Insert exponent and sign bit*/
18199 + bfins r11, r7, 20, 11
18200 + or r11, r12
18201 +
18202 + /* Round */
18203 +__avr32_f64_add_round:
18204 +#if defined(L_avr32_f64_addsub)
18205 + bfextu r12, r10, 0, 1 /* Extract parity bit.*/
18206 + or lr, r12 /* or it together with the sticky bits. */
18207 + eorh lr, 0x8000 /* Toggle round bit. */
18208 + /* We should now round up by adding one for the following cases:
18209 +
18210 + halfway sticky|parity round-up
18211 + 0 x no
18212 + 1 0 no
18213 + 1 1 yes
18214 +
18215 + Since we have inverted the halfway bit we can use the satu instruction
18216 + by saturating to 1 bit to implement this.
18217 + */
18218 + satu lr >> 0, 1
18219 +#else
18220 + lsr lr, 31
18221 +#endif
18222 + add r10, lr
18223 + acr r11
18224 +
18225 + /* Return result in [r11,r10] */
18226 + ldm sp++, r5, r6, r7,pc
18227 +
18228 +
18229 +__avr32_f64_add_opH_nan_or_inf:
18230 + /* Check if opH is NaN, if so return NaN */
18231 + cbr r11, 20
18232 + or lr, r11, r10
18233 + brne __avr32_f64_add_return_nan
18234 +
18235 + /* opH is Inf. */
18236 + /* Check if opL is Inf. or NaN */
18237 + cp.w r6, 0x7ff
18238 + breq __avr32_f64_add_opL_nan_or_inf
18239 + ldm sp++, r5, r6, r7, pc/* opL not Inf or NaN, return opH */
18240 +__avr32_f64_add_opL_nan_or_inf:
18241 + cbr r9, 20
18242 + or lr, r9, r8
18243 + brne __avr32_f64_add_return_nan
18244 + mov r10, 0 /* Generate Inf in r11, r10 */
18245 + mov_imm r11, 0x7ff00000
18246 + ldm sp++, r5, r6, r7, pc/* opL Inf, return Inf */
18247 +__avr32_f64_add_return_nan:
18248 + mov r10, -1 /* Generate NaN in r11, r10 */
18249 + mov r11, -1
18250 + ldm sp++, r5, r6, r7, pc/* opL Inf or NaN, return NaN */
18251 +
18252 +
18253 +__avr32_f64_add_longshift:
18254 + /* large (>=32) shift amount, only lsw will have bits left after shift.
18255 + note that shift operations will use ((shift count=r6) mod 32) so
18256 + we do not need to subtract 32 from shift count. */
18257 + /* Saturate the shift amount to 63. If the amount
18258 + is any larger op2 is insignificant. */
18259 + satu r6 >> 0, 6
18260 + /* If shift amount is 32 there are no bits from the msw that are lost. */
18261 + moveq lr, r8
18262 + breq 0f
18263 + /* first remember whether part that is lost contains any 1 bits ... */
18264 + lsl lr,r9,r5 /* save all lost bits from msw */
18265 +#if defined(L_avr32_f64_addsub)
18266 + cp.w r8, 0
18267 + srne r8
18268 + or lr,r8 /* also save lost bits (all) from lsw
18269 + now lr != 0 if we lose any bits */
18270 +#endif
18271 +0:
18272 + /* ... and now to the actual shift */
18273 + lsr r8,r9,r6 /* msw -> lsw and make rest of shift inside lsw*/
18274 + mov r9,0 /* clear msw */
18275 + rjmp __avr32_f64_add_shift_done
18276 +
18277 +__avr32_f64_add_res_of:
18278 + /* We overflowed. Scale down mantissa by shifting right one position. */
18279 + or lr, lr, lr << 1 /* Remember stickybits*/
18280 + lsr r11, 1
18281 + ror r10
18282 + ror lr
18283 + sub r7, -1 /* Increment exponent */
18284 +
18285 + /* Clear mantissa to set result to Inf if the exponent is 255. */
18286 + cp.w r7, 0x7ff
18287 + moveq r10, 0
18288 + moveq r11, 0
18289 + moveq lr, 0
18290 + rjmp __avr32_f64_add_res_of_done
18291 +
18292 +__avr32_f64_add_op2_subnormal:
18293 + /* Set epxponent to 1 */
18294 + mov r6, 1
18295 +
18296 + /* Check if op2 is also subnormal. */
18297 + cp.w r7, 0
18298 + brne 2b
18299 +
18300 + cbr r11, 20
18301 + /* Both operands are subnormal. Just addd the mantissas
18302 + and the exponent will automatically be set to 1 if
18303 + we overflow into a normal number. */
18304 + add r10, r8
18305 + adc r11, r11, r9
18306 +
18307 + /* Add sign bit */
18308 + or r11, r12
18309 +
18310 + /* Return result in [r11,r10] */
18311 + ldm sp++, r5, r6, r7,pc
18312 +
18313 +
18314 +
18315 +#endif
18316 +
18317 +#ifdef L_avr32_f64_to_u32
18318 + /* This goes into L_fixdfsi */
18319 +#endif
18320 +
18321 +
18322 +#ifdef L_avr32_f64_to_s32
18323 + .global __avr32_f64_to_u32
18324 + .type __avr32_f64_to_u32,@function
18325 +__avr32_f64_to_u32:
18326 + cp.w r11, 0
18327 + retmi 0 /* Negative returns 0 */
18328 +
18329 + /* Fallthrough to df to signed si conversion */
18330 + .global __avr32_f64_to_s32
18331 + .type __avr32_f64_to_s32,@function
18332 +__avr32_f64_to_s32:
18333 + lsl r12,r11,1
18334 + lsr r12,21 /* extract exponent*/
18335 + sub r12,1023 /* convert to unbiased exponent.*/
18336 + retlo 0 /* too small exponent implies zero. */
18337 +
18338 +1:
18339 + rsub r12,r12,31 /* shift count = 31 - exponent */
18340 + mov r9,r11 /* save sign for later...*/
18341 + lsl r11,11 /* remove exponent and sign*/
18342 + sbr r11,31 /* add implicit bit*/
18343 + or r11,r11,r10>>21 /* get rest of bits from lsw of double */
18344 + lsr r11,r11,r12 /* shift down mantissa to final place */
18345 + lsl r9,1 /* sign -> carry */
18346 + retcc r11 /* if positive, we are done */
18347 + neg r11 /* if negative float, negate result */
18348 + ret r11
18349 +
18350 +#endif /* L_fixdfsi*/
18351 +
18352 +#ifdef L_avr32_f64_to_u64
18353 + /* Actual function is in L_fixdfdi */
18354 +#endif
18355 +
18356 +#ifdef L_avr32_f64_to_s64
18357 + .global __avr32_f64_to_u64
18358 + .type __avr32_f64_to_u64,@function
18359 +__avr32_f64_to_u64:
18360 + cp.w r11,0
18361 + /* Negative numbers return zero */
18362 + movmi r10, 0
18363 + movmi r11, 0
18364 + retmi r11
18365 +
18366 +
18367 +
18368 + /* Fallthrough */
18369 + .global __avr32_f64_to_s64
18370 + .type __avr32_f64_to_s64,@function
18371 +__avr32_f64_to_s64:
18372 + lsl r9,r11,1
18373 + lsr r9,21 /* get exponent*/
18374 + sub r9,1023 /* convert to correct range*/
18375 + /* Return zero if exponent to small */
18376 + movlo r10, 0
18377 + movlo r11, 0
18378 + retlo r11
18379 +
18380 + mov r8,r11 /* save sign for later...*/
18381 +1:
18382 + lsl r11,11 /* remove exponent */
18383 + sbr r11,31 /* add implicit bit*/
18384 + or r11,r11,r10>>21 /* get rest of bits from lsw of double*/
18385 + lsl r10,11 /* align lsw correctly as well */
18386 + rsub r9,r9,63 /* shift count = 63 - exponent */
18387 + breq 1f
18388 +
18389 + cp.w r9,32 /* is shift count more than one reg? */
18390 + brhs 0f
18391 +
18392 + mov r12,r11 /* save msw */
18393 + lsr r10,r10,r9 /* small shift count, shift down lsw */
18394 + lsr r11,r11,r9 /* small shift count, shift down msw */
18395 + rsub r9,r9,32 /* get 32-size of shifted out tail */
18396 + lsl r12,r12,r9 /* align part to move from msw to lsw */
18397 + or r10,r12 /* combine to get new lsw */
18398 + rjmp 1f
18399 +
18400 +0:
18401 + lsr r10,r11,r9 /* large shift count,only lsw get bits
18402 + note that shift count is modulo 32*/
18403 + mov r11,0 /* msw will be 0 */
18404 +
18405 +1:
18406 + lsl r8,1 /* sign -> carry */
18407 + retcc r11 /* if positive, we are done */
18408 +
18409 + neg r11 /* if negative float, negate result */
18410 + neg r10
18411 + scr r11
18412 + ret r11
18413 +
18414 +#endif
18415 +
18416 +#ifdef L_avr32_u32_to_f64
18417 + /* Code located in L_floatsidf */
18418 +#endif
18419 +
18420 +#ifdef L_avr32_s32_to_f64
18421 + .global __avr32_u32_to_f64
18422 + .type __avr32_u32_to_f64,@function
18423 +__avr32_u32_to_f64:
18424 + sub r11, r12, 0 /* Move to r11 and force Z flag to be updated */
18425 + mov r12, 0 /* always positive */
18426 + rjmp 0f /* Jump to common code for floatsidf */
18427 +
18428 + .global __avr32_s32_to_f64
18429 + .type __avr32_s32_to_f64,@function
18430 +__avr32_s32_to_f64:
18431 + mov r11, r12 /* Keep original value in r12 for sign */
18432 + abs r11 /* Absolute value if r12 */
18433 +0:
18434 + mov r10,0 /* let remaining bits be zero */
18435 + reteq r11 /* zero long will return zero float */
18436 +
18437 + pushm lr
18438 + mov r9,31+1023 /* set exponent */
18439 +
18440 + normalize_df r9 /*exp*/, r10, r11 /* mantissa */, r8, lr /* scratch */
18441 +
18442 + /* Check if a subnormal result was created */
18443 + cp.w r9, 0
18444 + brgt 0f
18445 +
18446 + adjust_subnormal_df r9 /* exp */, r10, r11 /* Mantissa */, r12 /*sign*/, r8, lr /* scratch */
18447 + popm pc
18448 +0:
18449 +
18450 + /* Round result */
18451 + round_df r9 /*exp*/, r10, r11 /* Mantissa */, r8 /*scratch*/
18452 + cp.w r9,0x7ff
18453 + brlt 0f
18454 + /*Return infinity */
18455 + mov r10, 0
18456 + mov_imm r11, 0xffe00000
18457 + rjmp __floatsidf_return_op1
18458 +
18459 +0:
18460 +
18461 + /* Pack */
18462 + pack_df r9 /*exp*/, r10, r11 /* mantissa */, r10, r11 /* Output df number*/
18463 +__floatsidf_return_op1:
18464 + lsl r12,1 /* shift in sign bit */
18465 + ror r11
18466 +
18467 + popm pc
18468 +#endif
18469 +
18470 +
18471 +#ifdef L_avr32_f32_cmp_eq
18472 + .global __avr32_f32_cmp_eq
18473 + .type __avr32_f32_cmp_eq,@function
18474 +__avr32_f32_cmp_eq:
18475 + cp.w r12, r11
18476 + breq 0f
18477 + /* If not equal check for +/-0 */
18478 + /* Or together the two values and shift out the sign bit.
18479 + If the result is zero, then the two values are both zero. */
18480 + or r12, r11
18481 + lsl r12, 1
18482 + reteq 1
18483 + ret 0
18484 +0:
18485 + /* Numbers were equal. Check for NaN or Inf */
18486 + mov_imm r11, 0xff000000
18487 + lsl r12, 1
18488 + cp.w r12, r11
18489 + retls 1 /* 0 if NaN, 1 otherwise */
18490 + ret 0
18491 +#endif
18492 +
18493 +#if defined(L_avr32_f32_cmp_ge) || defined(L_avr32_f32_cmp_lt)
18494 +#ifdef L_avr32_f32_cmp_ge
18495 + .global __avr32_f32_cmp_ge
18496 + .type __avr32_f32_cmp_ge,@function
18497 +__avr32_f32_cmp_ge:
18498 +#endif
18499 +#ifdef L_avr32_f32_cmp_lt
18500 + .global __avr32_f32_cmp_lt
18501 + .type __avr32_f32_cmp_lt,@function
18502 +__avr32_f32_cmp_lt:
18503 +#endif
18504 + lsl r10, r12, 1 /* Remove sign bits */
18505 + lsl r9, r11, 1
18506 + subfeq r10, 0
18507 +#ifdef L_avr32_f32_cmp_ge
18508 + reteq 1 /* Both number are zero. Return true. */
18509 +#endif
18510 +#ifdef L_avr32_f32_cmp_lt
18511 + reteq 0 /* Both number are zero. Return false. */
18512 +#endif
18513 + mov_imm r8, 0xff000000
18514 + cp.w r10, r8
18515 + rethi 0 /* Op0 is NaN */
18516 + cp.w r9, r8
18517 + rethi 0 /* Op1 is Nan */
18518 +
18519 + eor r8, r11, r12
18520 + bld r12, 31
18521 +#ifdef L_avr32_f32_cmp_ge
18522 + srcc r8 /* Set result to true if op0 is positive*/
18523 +#endif
18524 +#ifdef L_avr32_f32_cmp_lt
18525 + srcs r8 /* Set result to true if op0 is negative*/
18526 +#endif
18527 + retmi r8 /* Return if signs are different */
18528 + brcs 0f /* Both signs negative? */
18529 +
18530 + /* Both signs positive */
18531 + cp.w r12, r11
18532 +#ifdef L_avr32_f32_cmp_ge
18533 + reths 1
18534 + retlo 0
18535 +#endif
18536 +#ifdef L_avr32_f32_cmp_lt
18537 + reths 0
18538 + retlo 1
18539 +#endif
18540 +0:
18541 + /* Both signs negative */
18542 + cp.w r11, r12
18543 +#ifdef L_avr32_f32_cmp_ge
18544 + reths 1
18545 + retlo 0
18546 +#endif
18547 +#ifdef L_avr32_f32_cmp_lt
18548 + reths 0
18549 + retlo 1
18550 +#endif
18551 +#endif
18552 +
18553 +
18554 +#ifdef L_avr32_f64_cmp_eq
18555 + .global __avr32_f64_cmp_eq
18556 + .type __avr32_f64_cmp_eq,@function
18557 +__avr32_f64_cmp_eq:
18558 + cp.w r10,r8
18559 + cpc r11,r9
18560 + breq 0f
18561 +
18562 + /* Args were not equal*/
18563 + /* Both args could be zero with different sign bits */
18564 + lsl r11,1 /* get rid of sign bits */
18565 + lsl r9,1
18566 + or r11,r10 /* Check if all bits are zero */
18567 + or r11,r9
18568 + or r11,r8
18569 + reteq 1 /* If all zeros the arguments are equal
18570 + so return 1 else return 0 */
18571 + ret 0
18572 +0:
18573 + /* check for NaN */
18574 + lsl r11,1
18575 + mov_imm r12, 0xffe00000
18576 + cp.w r10,0
18577 + cpc r11,r12 /* check if nan or inf */
18578 + retls 1 /* If Arg is NaN return 0 else 1*/
18579 + ret 0 /* Return */
18580 +
18581 +#endif
18582 +
18583 +
18584 +#if defined(L_avr32_f64_cmp_ge) || defined(L_avr32_f64_cmp_lt)
18585 +
18586 +#ifdef L_avr32_f64_cmp_ge
18587 + .global __avr32_f64_cmp_ge
18588 + .type __avr32_f64_cmp_ge,@function
18589 +__avr32_f64_cmp_ge:
18590 +#endif
18591 +#ifdef L_avr32_f64_cmp_lt
18592 + .global __avr32_f64_cmp_lt
18593 + .type __avr32_f64_cmp_lt,@function
18594 +__avr32_f64_cmp_lt:
18595 +#endif
18596 +
18597 + /* compare magnitude of op1 and op2 */
18598 + lsl r11,1 /* Remove sign bit of op1 */
18599 + srcs r12 /* Sign op1 to lsb of r12*/
18600 + subfeq r10, 0
18601 + breq 3f /* op1 zero */
18602 + lsl r9,1 /* Remove sign bit of op2 */
18603 + rol r12 /* Sign op2 to lsb of lr, sign bit op1 bit 1 of r12*/
18604 +
18605 +
18606 + /* Check for Nan */
18607 + pushm lr
18608 + mov_imm lr, 0xffe00000
18609 + cp.w r10,0
18610 + cpc r11,lr
18611 + brhi 0f /* We have NaN */
18612 + cp.w r8,0
18613 + cpc r9,lr
18614 + brhi 0f /* We have NaN */
18615 + popm lr
18616 +
18617 + cp.w r12,3 /* both operands negative ?*/
18618 + breq 1f
18619 +
18620 + cp.w r12,1 /* both operands positive? */
18621 + brlo 2f
18622 +
18623 + /* Different signs. If sign of op1 is negative the difference
18624 + between op1 and op2 will always be negative, and if op1 is
18625 + positive the difference will always be positive */
18626 +#ifdef L_avr32_f64_cmp_ge
18627 + reteq 1
18628 + retne 0
18629 +#endif
18630 +#ifdef L_avr32_f64_cmp_lt
18631 + reteq 0
18632 + retne 1
18633 +#endif
18634 +
18635 +2:
18636 + /* Both operands positive. Just compute the difference */
18637 + cp.w r10,r8
18638 + cpc r11,r9
18639 +#ifdef L_avr32_f64_cmp_ge
18640 + reths 1
18641 + retlo 0
18642 +#endif
18643 +#ifdef L_avr32_f64_cmp_lt
18644 + reths 0
18645 + retlo 1
18646 +#endif
18647 +
18648 +1:
18649 + /* Both operands negative. Compute the difference with operands switched */
18650 + cp r8,r10
18651 + cpc r9,r11
18652 +#ifdef L_avr32_f64_cmp_ge
18653 + reths 1
18654 + retlo 0
18655 +#endif
18656 +#ifdef L_avr32_f64_cmp_lt
18657 + reths 0
18658 + retlo 1
18659 +#endif
18660 +
18661 +0:
18662 + popm pc, r12=0
18663 +#endif
18664 +
18665 +3:
18666 + lsl r9,1 /* Remove sign bit of op1 */
18667 +#ifdef L_avr32_f64_cmp_ge
18668 + srcs r12 /* If op2 is negative then op1 >= op2. */
18669 +#endif
18670 +#ifdef L_avr32_f64_cmp_lt
18671 + srcc r12 /* If op2 is positve then op1 <= op2. */
18672 +#endif
18673 + subfeq r8, 0
18674 +#ifdef L_avr32_f64_cmp_ge
18675 + reteq 1 /* Both operands are zero. Return true. */
18676 +#endif
18677 +#ifdef L_avr32_f64_cmp_lt
18678 + reteq 0 /* Both operands are zero. Return false. */
18679 +#endif
18680 + ret r12
18681 +
18682 +
18683 +#if defined(L_avr32_f64_div) || defined(L_avr32_f64_div_fast)
18684 + .align 2
18685 +
18686 +#if defined(L_avr32_f64_div_fast)
18687 + .global __avr32_f64_div_fast
18688 + .type __avr32_f64_div_fast,@function
18689 +__avr32_f64_div_fast:
18690 +#else
18691 + .global __avr32_f64_div
18692 + .type __avr32_f64_div,@function
18693 +__avr32_f64_div:
18694 +#endif
18695 + stm --sp, r0, r1, r2, r3, r4, r5, r6, r7,lr
18696 + /* op1 in {r11,r10}*/
18697 + /* op2 in {r9,r8}*/
18698 + eor lr, r11, r9 /* MSB(lr) = Sign(op1) ^ Sign(op2) */
18699 +
18700 +
18701 + /* Unpack op1 to 2.62 format*/
18702 + /* exp: r7 */
18703 + /* sf: r11, r10 */
18704 + lsr r7, r11, 20 /* Extract exponent */
18705 +
18706 + lsl r11, 9 /* Extract mantissa, leave room for implicit bit */
18707 + or r11, r11, r10>>23
18708 + lsl r10, 9
18709 + sbr r11, 29 /* Insert implicit bit */
18710 + andh r11, 0x3fff /*Mask last part of exponent since we use 2.62 format*/
18711 +
18712 + cbr r7, 11 /* Clear sign bit */
18713 + /* Check if normalization is needed */
18714 + breq 11f /*If number is subnormal, normalize it */
18715 +22:
18716 + cp r7, 0x7ff
18717 + brge 2f /* Check op1 for NaN or Inf */
18718 +
18719 + /* Unpack op2 to 2.62 format*/
18720 + /* exp: r6 */
18721 + /* sf: r9, r8 */
18722 + lsr r6, r9, 20 /* Extract exponent */
18723 +
18724 + lsl r9, 9 /* Extract mantissa, leave room for implicit bit */
18725 + or r9, r9, r8>>23
18726 + lsl r8, 9
18727 + sbr r9, 29 /* Insert implicit bit */
18728 + andh r9, 0x3fff /*Mask last part of exponent since we use 2.62 format*/
18729 +
18730 + cbr r6, 11 /* Clear sign bit */
18731 + /* Check if normalization is needed */
18732 + breq 13f /*If number is subnormal, normalize it */
18733 +23:
18734 + cp r6, 0x7ff
18735 + brge 3f /* Check op2 for NaN or Inf */
18736 +
18737 + /* Calculate new exponent */
18738 + sub r7, r6
18739 + sub r7,-1023
18740 +
18741 + /* Divide */
18742 + /* Approximating 1/d with the following recurrence: */
18743 + /* R[j+1] = R[j]*(2-R[j]*d) */
18744 + /* Using 2.62 format */
18745 + /* TWO: r12 */
18746 + /* d = op2 = divisor (2.62 format): r9,r8 */
18747 + /* Multiply result : r5, r4 */
18748 + /* Initial guess : r3, r2 */
18749 + /* New approximations : r3, r2 */
18750 + /* op1 = Dividend (2.62 format) : r11, r10 */
18751 +
18752 + mov_imm r12, 0x80000000
18753 +
18754 + /* Load initial guess, using look-up table */
18755 + /* Initial guess is of format 01.XY, where XY is constructed as follows: */
18756 + /* Let d be of following format: 00.1xy....., then XY=~xy */
18757 + /* For d=00.100 = 0,5 -> initial guess=01.11 = 1,75 */
18758 + /* For d=00.101 = 0,625 -> initial guess=01.11 = 1,5 */
18759 + /* For d=00.110 = 0,75 -> initial guess=01.11 = 1,25 */
18760 + /* For d=00.111 = 0,875 -> initial guess=01.11 = 1,0 */
18761 + /* r2 is also part of the reg pair forming initial guess, but it*/
18762 + /* is kept uninitialized to save one cycle since it has so low significance*/
18763 +
18764 + lsr r3, r12, 1
18765 + bfextu r4, r9, 27, 2
18766 + com r4
18767 + bfins r3, r4, 28, 2
18768 +
18769 + /* First approximation */
18770 + /* Approximating to 32 bits */
18771 + /* r5 = R[j]*d */
18772 + mulu.d r4, r3, r9
18773 + /* r5 = 2-R[j]*d */
18774 + sub r5, r12, r5<<2
18775 + /* r3 = R[j]*(2-R[j]*d) */
18776 + mulu.d r4, r3, r5
18777 + lsl r3, r5, 2
18778 +
18779 + /* Second approximation */
18780 + /* Approximating to 32 bits */
18781 + /* r5 = R[j]*d */
18782 + mulu.d r4, r3, r9
18783 + /* r5 = 2-R[j]*d */
18784 + sub r5, r12, r5<<2
18785 + /* r3 = R[j]*(2-R[j]*d) */
18786 + mulu.d r4, r3, r5
18787 + lsl r3, r5, 2
18788 +
18789 + /* Third approximation */
18790 + /* Approximating to 32 bits */
18791 + /* r5 = R[j]*d */
18792 + mulu.d r4, r3, r9
18793 + /* r5 = 2-R[j]*d */
18794 + sub r5, r12, r5<<2
18795 + /* r3 = R[j]*(2-R[j]*d) */
18796 + mulu.d r4, r3, r5
18797 + lsl r3, r5, 2
18798 +
18799 + /* Fourth approximation */
18800 + /* Approximating to 64 bits */
18801 + /* r5,r4 = R[j]*d */
18802 + mul_approx_df r3 /*ah*/, r2 /*al*/, r9 /*bh*/, r8 /*bl*/, r5 /*rh*/, r4 /*rl*/, r1 /*sh*/, r0 /*sl*/
18803 + lsl r5, 2
18804 + or r5, r5, r4>>30
18805 + lsl r4, 2
18806 + /* r5,r4 = 2-R[j]*d */
18807 + neg r4
18808 + sbc r5, r12, r5
18809 + /* r3,r2 = R[j]*(2-R[j]*d) */
18810 + mul_approx_df r3 /*ah*/, r2 /*al*/, r5 /*bh*/, r4 /*bl*/, r5 /*rh*/, r4 /*rl*/, r1 /*sh*/, r0 /*sl*/
18811 + lsl r3, r5, 2
18812 + or r3, r3, r4>>30
18813 + lsl r2, r4, 2
18814 +
18815 +
18816 + /* Fifth approximation */
18817 + /* Approximating to 64 bits */
18818 + /* r5,r4 = R[j]*d */
18819 + mul_approx_df r3 /*ah*/, r2 /*al*/, r9 /*bh*/, r8 /*bl*/, r5 /*rh*/, r4 /*rl*/, r1 /*sh*/, r0 /*sl*/
18820 + lsl r5, 2
18821 + or r5, r5, r4>>30
18822 + lsl r4, 2
18823 + /* r5,r4 = 2-R[j]*d */
18824 + neg r4
18825 + sbc r5, r12, r5
18826 + /* r3,r2 = R[j]*(2-R[j]*d) */
18827 + mul_approx_df r3 /*ah*/, r2 /*al*/, r5 /*bh*/, r4 /*bl*/, r5 /*rh*/, r4 /*rl*/, r1 /*sh*/, r0 /*sl*/
18828 + lsl r3, r5, 2
18829 + or r3, r3, r4>>30
18830 + lsl r2, r4, 2
18831 +
18832 +
18833 + /* Multiply with dividend to get quotient */
18834 + mul_approx_df r3 /*ah*/, r2 /*al*/, r11 /*bh*/, r10 /*bl*/, r3 /*rh*/, r2 /*rl*/, r1 /*sh*/, r0 /*sl*/
18835 +
18836 +
18837 + /* To increase speed, this result is not corrected before final rounding.*/
18838 + /* This may give a difference to IEEE compliant code of 1 ULP.*/
18839 +
18840 +
18841 + /* Adjust exponent and mantissa */
18842 + /* r7:exp, [r3, r2]:mant, [r5, r4]:scratch*/
18843 + /* Mantissa may be of the format 0.xxxx or 1.xxxx. */
18844 + /* In the first case, shift one pos to left.*/
18845 + bld r3, 31-3
18846 + breq 0f
18847 + lsl r2, 1
18848 + rol r3
18849 + sub r7, 1
18850 +#if defined(L_avr32_f64_div)
18851 + /* We must scale down the dividend to 5.59 format. */
18852 + lsr r10, 3
18853 + or r10, r10, r11 << 29
18854 + lsr r11, 3
18855 + rjmp 1f
18856 +#endif
18857 +0:
18858 +#if defined(L_avr32_f64_div)
18859 + /* We must scale down the dividend to 6.58 format. */
18860 + lsr r10, 4
18861 + or r10, r10, r11 << 28
18862 + lsr r11, 4
18863 +1:
18864 +#endif
18865 + cp r7, 0
18866 + brle __avr32_f64_div_res_subnormal /* Result was subnormal. */
18867 +
18868 +
18869 +#if defined(L_avr32_f64_div)
18870 + /* In order to round correctly we calculate the remainder:
18871 + Remainder = dividend[11:r10] - divisor[r9:r8]*quotient[r3:r2]
18872 + for the case when the quotient is halfway between the round-up
18873 + value and the round down value. If the remainder then is negative
18874 + it means that the quotient was to big and that it should not be
18875 + rounded up, if the remainder is positive the quotient was to small
18876 + and we need to round up. If the remainder is zero it means that the
18877 + quotient is exact but since we need to remove the guard bit we should
18878 + round to even. */
18879 +
18880 + /* Truncate and add guard bit. */
18881 + andl r2, 0xff00
18882 + orl r2, 0x0080
18883 +
18884 +
18885 + /* Now do the multiplication. The quotient has the format 4.60
18886 + while the divisor has the format 2.62 which gives a result
18887 + of 6.58 */
18888 + mulu.d r0, r3, r8
18889 + macu.d r0, r2, r9
18890 + mulu.d r4, r2, r8
18891 + mulu.d r8, r3, r9
18892 + add r5, r0
18893 + adc r8, r8, r1
18894 + acr r9
18895 +
18896 +
18897 + /* Check if remainder is positive, negative or equal. */
18898 + bfextu r12, r2, 8, 1 /* Get parity bit into bit 0 of r0 */
18899 + cp r4, 0
18900 + cpc r5
18901 +__avr32_f64_div_round_subnormal:
18902 + cpc r8, r10
18903 + cpc r9, r11
18904 + srlo r6 /* Remainder positive: we need to round up.*/
18905 + moveq r6, r12 /* Remainder zero: round up if mantissa odd. */
18906 +#else
18907 + bfextu r6, r2, 7, 1 /* Get guard bit */
18908 +#endif
18909 + /* Final packing, scale down mantissa. */
18910 + lsr r10, r2, 8
18911 + or r10, r10, r3<<24
18912 + lsr r11, r3, 8
18913 + /* Insert exponent and sign bit*/
18914 + bfins r11, r7, 20, 11
18915 + bld lr, 31
18916 + bst r11, 31
18917 +
18918 + /* Final rounding */
18919 + add r10, r6
18920 + acr r11
18921 +
18922 + /* Return result in [r11,r10] */
18923 + ldm sp++, r0, r1, r2, r3, r4, r5, r6, r7,pc
18924 +
18925 +
18926 +2:
18927 + /* Op1 is NaN or inf */
18928 + andh r11, 0x000f /* Extract mantissa */
18929 + or r11, r10
18930 + brne 16f /* Return NaN if op1 is NaN */
18931 + /* Op1 is inf check op2 */
18932 + lsr r6, r9, 20 /* Extract exponent */
18933 + cbr r6, 8 /* Clear sign bit */
18934 + cp r6, 0x7ff
18935 + brne 17f /* Inf/number gives inf, return inf */
18936 + rjmp 16f /* The rest gives NaN*/
18937 +
18938 +3:
18939 + /* Op1 is a valid number. Op 2 is NaN or inf */
18940 + andh r9, 0x000f /* Extract mantissa */
18941 + or r9, r8
18942 + brne 16f /* Return NaN if op2 is NaN */
18943 + rjmp 15f /* Op2 was inf, return zero*/
18944 +
18945 +11: /* Op1 was denormal. Fix it. */
18946 + lsl r11, 3
18947 + or r11, r11, r10 >> 29
18948 + lsl r10, 3
18949 + /* Check if op1 is zero. */
18950 + or r4, r10, r11
18951 + breq __avr32_f64_div_op1_zero
18952 + normalize_df r7 /*exp*/, r10, r11 /*Mantissa*/, r4, r5 /*scratch*/
18953 + lsr r10, 2
18954 + or r10, r10, r11 << 30
18955 + lsr r11, 2
18956 + rjmp 22b
18957 +
18958 +
18959 +13: /* Op2 was denormal. Fix it */
18960 + lsl r9, 3
18961 + or r9, r9, r8 >> 29
18962 + lsl r8, 3
18963 + /* Check if op2 is zero. */
18964 + or r4, r9, r8
18965 + breq 17f /* Divisor is zero -> return Inf */
18966 + normalize_df r6 /*exp*/, r8, r9 /*Mantissa*/, r4, r5 /*scratch*/
18967 + lsr r8, 2
18968 + or r8, r8, r9 << 30
18969 + lsr r9, 2
18970 + rjmp 23b
18971 +
18972 +
18973 +__avr32_f64_div_res_subnormal:/* Divide result was subnormal. */
18974 +#if defined(L_avr32_f64_div)
18975 + /* Check how much we must scale down the mantissa. */
18976 + neg r7
18977 + sub r7, -1 /* We do no longer have an implicit bit. */
18978 + satu r7 >> 0, 6 /* Saturate shift amount to max 63. */
18979 + cp.w r7, 32
18980 + brge 0f
18981 + /* Shift amount <32 */
18982 + /* Scale down quotient */
18983 + rsub r6, r7, 32
18984 + lsr r2, r2, r7
18985 + lsl r12, r3, r6
18986 + or r2, r12
18987 + lsr r3, r3, r7
18988 + /* Scale down the dividend to match the scaling of the quotient. */
18989 + lsl r1, r10, r6
18990 + lsr r10, r10, r7
18991 + lsl r12, r11, r6
18992 + or r10, r12
18993 + lsr r11, r11, r7
18994 + mov r0, 0
18995 + rjmp 1f
18996 +0:
18997 + /* Shift amount >=32 */
18998 + rsub r6, r7, 32
18999 + moveq r0, 0
19000 + moveq r12, 0
19001 + breq 0f
19002 + lsl r0, r10, r6
19003 + lsl r12, r11, r6
19004 +0:
19005 + lsr r2, r3, r7
19006 + mov r3, 0
19007 + /* Scale down the dividend to match the scaling of the quotient. */
19008 + lsr r1, r10, r7
19009 + or r1, r12
19010 + lsr r10, r11, r7
19011 + mov r11, 0
19012 +1:
19013 + /* Start performing the same rounding as done for normal numbers
19014 + but this time we have scaled the quotient and dividend and hence
19015 + need a little different comparison. */
19016 + /* Truncate and add guard bit. */
19017 + andl r2, 0xff00
19018 + orl r2, 0x0080
19019 +
19020 + /* Now do the multiplication. */
19021 + mulu.d r6, r3, r8
19022 + macu.d r6, r2, r9
19023 + mulu.d r4, r2, r8
19024 + mulu.d r8, r3, r9
19025 + add r5, r6
19026 + adc r8, r8, r7
19027 + acr r9
19028 +
19029 + /* Set exponent to 0 */
19030 + mov r7, 0
19031 +
19032 + /* Check if remainder is positive, negative or equal. */
19033 + bfextu r12, r2, 8, 1 /* Get parity bit into bit 0 of r0 */
19034 + cp r4, r0
19035 + cpc r5, r1
19036 + /* Now the rest of the rounding is the same as for normals. */
19037 + rjmp __avr32_f64_div_round_subnormal
19038 +
19039 +#endif
19040 +15:
19041 + /* Flush to zero for the fast version. */
19042 + mov r11, lr /*Get correct sign*/
19043 + andh r11, 0x8000, COH
19044 + mov r10, 0
19045 + ldm sp++, r0, r1, r2, r3, r4, r5, r6, r7,pc
19046 +
19047 +16: /* Return NaN. */
19048 + mov r11, -1
19049 + mov r10, -1
19050 + ldm sp++, r0, r1, r2, r3, r4, r5, r6, r7,pc
19051 +
19052 +17: /* Return INF. */
19053 + mov r11, lr /*Get correct sign*/
19054 + andh r11, 0x8000, COH
19055 + orh r11, 0x7ff0
19056 + mov r10, 0
19057 + ldm sp++, r0, r1, r2, r3, r4, r5, r6, r7,pc
19058 +
19059 +__avr32_f64_div_op1_zero:
19060 + or r5, r8, r9 << 1
19061 + breq 16b /* 0.0/0.0 -> NaN */
19062 + bfextu r4, r9, 20, 11
19063 + cp r4, 0x7ff
19064 + brne 15b /* Return zero */
19065 + /* Check if divisor is Inf or NaN */
19066 + or r5, r8, r9 << 12
19067 + breq 15b /* Divisor is inf -> return zero */
19068 + rjmp 16b /* Return NaN */
19069 +
19070 +
19071 +
19072 +
19073 +#endif
19074 +
19075 +#if defined(L_avr32_f32_addsub) || defined(L_avr32_f32_addsub_fast)
19076 +
19077 + .align 2
19078 +__avr32_f32_sub_from_add:
19079 + /* Switch sign on op2 */
19080 + eorh r11, 0x8000
19081 +
19082 +#if defined(L_avr32_f32_addsub_fast)
19083 + .global __avr32_f32_sub_fast
19084 + .type __avr32_f32_sub_fast,@function
19085 +__avr32_f32_sub_fast:
19086 +#else
19087 + .global __avr32_f32_sub
19088 + .type __avr32_f32_sub,@function
19089 +__avr32_f32_sub:
19090 +#endif
19091 +
19092 + /* Check signs */
19093 + eor r8, r11, r12
19094 + /* Different signs, use subtraction. */
19095 + brmi __avr32_f32_add_from_sub
19096 +
19097 + /* Get sign of op1 */
19098 + mov r8, r12
19099 + andh r12, 0x8000, COH
19100 +
19101 + /* Remove sign from operands */
19102 + cbr r11, 31
19103 +#if defined(L_avr32_f32_addsub_fast)
19104 + reteq r8 /* If op2 is zero return op1 */
19105 +#endif
19106 + cbr r8, 31
19107 +
19108 + /* Put the number with the largest exponent in r10
19109 + and the number with the smallest exponent in r9 */
19110 + max r10, r8, r11
19111 + min r9, r8, r11
19112 + cp r10, r8 /*If largest operand (in R10) is not equal to op1*/
19113 + subne r12, 1 /* Subtract 1 from sign, which will invert MSB of r12*/
19114 + andh r12, 0x8000, COH /*Mask all but MSB*/
19115 +
19116 + /* Unpack exponent and mantissa of op1 */
19117 + lsl r8, r10, 8
19118 + sbr r8, 31 /* Set implicit bit. */
19119 + lsr r10, 23
19120 +
19121 + /* op1 is NaN or Inf. */
19122 + cp.w r10, 0xff
19123 + breq __avr32_f32_sub_op1_nan_or_inf
19124 +
19125 + /* Unpack exponent and mantissa of op2 */
19126 + lsl r11, r9, 8
19127 + sbr r11, 31 /* Set implicit bit. */
19128 + lsr r9, 23
19129 +
19130 +#if defined(L_avr32_f32_addsub)
19131 + /* Keep sticky bit for correct IEEE rounding */
19132 + st.w --sp, r12
19133 +
19134 + /* op2 is either zero or subnormal. */
19135 + breq __avr32_f32_sub_op2_subnormal
19136 +0:
19137 + /* Get shift amount to scale mantissa of op2. */
19138 + sub r12, r10, r9
19139 +
19140 + breq __avr32_f32_sub_shift_done
19141 +
19142 + /* Saturate the shift amount to 31. If the amount
19143 + is any larger op2 is insignificant. */
19144 + satu r12 >> 0, 5
19145 +
19146 + /* Put the remaining bits into r9.*/
19147 + rsub r9, r12, 32
19148 + lsl r9, r11, r9
19149 +
19150 + /* If the remaining bits are non-zero then we must subtract one
19151 + more from opL. */
19152 + subne r8, 1
19153 + srne r9 /* LSB of r9 represents sticky bits. */
19154 +
19155 + /* Shift mantissa of op2 to same decimal point as the mantissa
19156 + of op1. */
19157 + lsr r11, r11, r12
19158 +
19159 +
19160 +__avr32_f32_sub_shift_done:
19161 + /* Now subtract the mantissas. */
19162 + sub r8, r11
19163 +
19164 + ld.w r12, sp++
19165 +
19166 + /* Normalize resulting mantissa. */
19167 + clz r11, r8
19168 +
19169 + retcs 0
19170 + lsl r8, r8, r11
19171 + sub r10, r11
19172 + brle __avr32_f32_sub_subnormal_result
19173 +
19174 + /* Insert the bits we will remove from the mantissa into r9[31:24] */
19175 + or r9, r9, r8 << 24
19176 +#else
19177 + /* Ignore sticky bit to simplify and speed up rounding */
19178 + /* op2 is either zero or subnormal. */
19179 + breq __avr32_f32_sub_op2_subnormal
19180 +0:
19181 + /* Get shift amount to scale mantissa of op2. */
19182 + rsub r9, r10
19183 +
19184 + /* Saturate the shift amount to 31. If the amount
19185 + is any larger op2 is insignificant. */
19186 + satu r9 >> 0, 5
19187 +
19188 + /* Shift mantissa of op2 to same decimal point as the mantissa
19189 + of op1. */
19190 + lsr r11, r11, r9
19191 +
19192 + /* Now subtract the mantissas. */
19193 + sub r8, r11
19194 +
19195 + /* Normalize resulting mantissa. */
19196 + clz r9, r8
19197 + retcs 0
19198 + lsl r8, r8, r9
19199 + sub r10, r9
19200 + brle __avr32_f32_sub_subnormal_result
19201 +#endif
19202 +
19203 + /* Pack result. */
19204 + or r12, r12, r8 >> 8
19205 + bfins r12, r10, 23, 8
19206 +
19207 + /* Round */
19208 +__avr32_f32_sub_round:
19209 +#if defined(L_avr32_f32_addsub)
19210 + mov_imm r10, 0x80000000
19211 + bld r12, 0
19212 + subne r10, -1
19213 + cp.w r9, r10
19214 + subhs r12, -1
19215 +#else
19216 + bld r8, 7
19217 + acr r12
19218 +#endif
19219 +
19220 + ret r12
19221 +
19222 +
19223 +__avr32_f32_sub_op2_subnormal:
19224 + /* Fix implicit bit and adjust exponent of subnormals. */
19225 + cbr r11, 31
19226 + /* Set exponent to 1 if we do not have a zero. */
19227 + movne r9,1
19228 +
19229 + /* Check if op1 is also subnormal. */
19230 + cp.w r10, 0
19231 + brne 0b
19232 +
19233 + cbr r8, 31
19234 + /* If op1 is not zero set exponent to 1. */
19235 + movne r10,1
19236 +
19237 + rjmp 0b
19238 +
19239 +__avr32_f32_sub_op1_nan_or_inf:
19240 + /* Check if op1 is NaN, if so return NaN */
19241 + lsl r11, r8, 1
19242 + retne -1
19243 +
19244 + /* op1 is Inf. */
19245 + bfins r12, r10, 23, 8 /* Generate Inf in r12 */
19246 +
19247 + /* Check if op2 is Inf. or NaN */
19248 + lsr r11, r9, 23
19249 + cp.w r11, 0xff
19250 + retne r12 /* op2 not Inf or NaN, return op1 */
19251 +
19252 + ret -1 /* op2 Inf or NaN, return NaN */
19253 +
19254 +__avr32_f32_sub_subnormal_result:
19255 + /* Check if the number is so small that
19256 + it will be represented with zero. */
19257 + rsub r10, r10, 9
19258 + rsub r11, r10, 32
19259 + retcs 0
19260 +
19261 + /* Shift the mantissa into the correct position.*/
19262 + lsr r10, r8, r10
19263 + /* Add sign bit. */
19264 + or r12, r10
19265 +
19266 + /* Put the shifted out bits in the most significant part
19267 + of r8. */
19268 + lsl r8, r8, r11
19269 +
19270 +#if defined(L_avr32_f32_addsub)
19271 + /* Add all the remainder bits used for rounding into r9 */
19272 + or r9, r8
19273 +#else
19274 + lsr r8, 24
19275 +#endif
19276 + rjmp __avr32_f32_sub_round
19277 +
19278 +
19279 + .align 2
19280 +
19281 +__avr32_f32_add_from_sub:
19282 + /* Switch sign on op2 */
19283 + eorh r11, 0x8000
19284 +
19285 +#if defined(L_avr32_f32_addsub_fast)
19286 + .global __avr32_f32_add_fast
19287 + .type __avr32_f32_add_fast,@function
19288 +__avr32_f32_add_fast:
19289 +#else
19290 + .global __avr32_f32_add
19291 + .type __avr32_f32_add,@function
19292 +__avr32_f32_add:
19293 +#endif
19294 +
19295 + /* Check signs */
19296 + eor r8, r11, r12
19297 + /* Different signs, use subtraction. */
19298 + brmi __avr32_f32_sub_from_add
19299 +
19300 + /* Get sign of op1 */
19301 + mov r8, r12
19302 + andh r12, 0x8000, COH
19303 +
19304 + /* Remove sign from operands */
19305 + cbr r11, 31
19306 +#if defined(L_avr32_f32_addsub_fast)
19307 + reteq r8 /* If op2 is zero return op1 */
19308 +#endif
19309 + cbr r8, 31
19310 +
19311 + /* Put the number with the largest exponent in r10
19312 + and the number with the smallest exponent in r9 */
19313 + max r10, r8, r11
19314 + min r9, r8, r11
19315 +
19316 + /* Unpack exponent and mantissa of op1 */
19317 + lsl r8, r10, 8
19318 + sbr r8, 31 /* Set implicit bit. */
19319 + lsr r10, 23
19320 +
19321 + /* op1 is NaN or Inf. */
19322 + cp.w r10, 0xff
19323 + breq __avr32_f32_add_op1_nan_or_inf
19324 +
19325 + /* Unpack exponent and mantissa of op2 */
19326 + lsl r11, r9, 8
19327 + sbr r11, 31 /* Set implicit bit. */
19328 + lsr r9, 23
19329 +
19330 +#if defined(L_avr32_f32_addsub)
19331 + /* op2 is either zero or subnormal. */
19332 + breq __avr32_f32_add_op2_subnormal
19333 +0:
19334 + /* Keep sticky bit for correct IEEE rounding */
19335 + st.w --sp, r12
19336 +
19337 + /* Get shift amount to scale mantissa of op2. */
19338 + rsub r9, r10
19339 +
19340 + /* Saturate the shift amount to 31. If the amount
19341 + is any larger op2 is insignificant. */
19342 + satu r9 >> 0, 5
19343 +
19344 + /* Shift mantissa of op2 to same decimal point as the mantissa
19345 + of op1. */
19346 + lsr r12, r11, r9
19347 +
19348 + /* Put the remainding bits into r11[23:..].*/
19349 + rsub r9, r9, (32-8)
19350 + lsl r11, r11, r9
19351 + /* Insert the bits we will remove from the mantissa into r11[31:24] */
19352 + bfins r11, r12, 24, 8
19353 +
19354 + /* Now add the mantissas. */
19355 + add r8, r12
19356 +
19357 + ld.w r12, sp++
19358 +#else
19359 + /* Ignore sticky bit to simplify and speed up rounding */
19360 + /* op2 is either zero or subnormal. */
19361 + breq __avr32_f32_add_op2_subnormal
19362 +0:
19363 + /* Get shift amount to scale mantissa of op2. */
19364 + rsub r9, r10
19365 +
19366 + /* Saturate the shift amount to 31. If the amount
19367 + is any larger op2 is insignificant. */
19368 + satu r9 >> 0, 5
19369 +
19370 + /* Shift mantissa of op2 to same decimal point as the mantissa
19371 + of op1. */
19372 + lsr r11, r11, r9
19373 +
19374 + /* Now add the mantissas. */
19375 + add r8, r11
19376 +
19377 +#endif
19378 + /* Check if we overflowed. */
19379 + brcs __avr32_f32_add_res_of
19380 +1:
19381 + /* Pack result. */
19382 + or r12, r12, r8 >> 8
19383 + bfins r12, r10, 23, 8
19384 +
19385 + /* Round */
19386 +#if defined(L_avr32_f32_addsub)
19387 + mov_imm r10, 0x80000000
19388 + bld r12, 0
19389 + subne r10, -1
19390 + cp.w r11, r10
19391 + subhs r12, -1
19392 +#else
19393 + bld r8, 7
19394 + acr r12
19395 +#endif
19396 +
19397 + ret r12
19398 +
19399 +__avr32_f32_add_op2_subnormal:
19400 + /* Fix implicit bit and adjust exponent of subnormals. */
19401 + cbr r11, 31
19402 + /* Set exponent to 1 if we do not have a zero. */
19403 + movne r9,1
19404 +
19405 + /* Check if op1 is also subnormal. */
19406 + cp.w r10, 0
19407 + brne 0b
19408 + /* Both operands subnormal, just add the mantissas and
19409 + pack. If the addition of the subnormal numbers results
19410 + in a normal number then the exponent will automatically
19411 + be set to 1 by the addition. */
19412 + cbr r8, 31
19413 + add r11, r8
19414 + or r12, r12, r11 >> 8
19415 + ret r12
19416 +
19417 +__avr32_f32_add_op1_nan_or_inf:
19418 + /* Check if op1 is NaN, if so return NaN */
19419 + lsl r11, r8, 1
19420 + retne -1
19421 +
19422 + /* op1 is Inf. */
19423 + bfins r12, r10, 23, 8 /* Generate Inf in r12 */
19424 +
19425 + /* Check if op2 is Inf. or NaN */
19426 + lsr r11, r9, 23
19427 + cp.w r11, 0xff
19428 + retne r12 /* op2 not Inf or NaN, return op1 */
19429 +
19430 + lsl r9, 9
19431 + reteq r12 /* op2 Inf return op1 */
19432 + ret -1 /* op2 is NaN, return NaN */
19433 +
19434 +__avr32_f32_add_res_of:
19435 + /* We overflowed. Increase exponent and shift mantissa.*/
19436 + lsr r8, 1
19437 + sub r10, -1
19438 +
19439 + /* Clear mantissa to set result to Inf if the exponent is 255. */
19440 + cp.w r10, 255
19441 + moveq r8, 0
19442 + moveq r11, 0
19443 + rjmp 1b
19444 +
19445 +
19446 +#endif
19447 +
19448 +
19449 +#if defined(L_avr32_f32_div) || defined(L_avr32_f32_div_fast)
19450 + .align 2
19451 +
19452 +#if defined(L_avr32_f32_div_fast)
19453 + .global __avr32_f32_div_fast
19454 + .type __avr32_f32_div_fast,@function
19455 +__avr32_f32_div_fast:
19456 +#else
19457 + .global __avr32_f32_div
19458 + .type __avr32_f32_div,@function
19459 +__avr32_f32_div:
19460 +#endif
19461 +
19462 + eor r8, r11, r12 /* MSB(r8) = Sign(op1) ^ Sign(op2) */
19463 +
19464 + /* Unpack */
19465 + lsl r12,1
19466 + reteq 0 /* Return zero if op1 is zero */
19467 + lsl r11,1
19468 + breq 4f /* Check op2 for zero */
19469 +
19470 + /* Unpack op1*/
19471 + /* exp: r9 */
19472 + /* sf: r12 */
19473 + lsr r9, r12, 24
19474 + breq 11f /*If number is subnormal*/
19475 + cp r9, 0xff
19476 + brhs 2f /* Check op1 for NaN or Inf */
19477 + lsl r12, 7
19478 + sbr r12, 31 /*Implicit bit*/
19479 +12:
19480 +
19481 + /* Unpack op2*/
19482 + /* exp: r10 */
19483 + /* sf: r11 */
19484 + lsr r10, r11, 24
19485 + breq 13f /*If number is subnormal*/
19486 + cp r10, 0xff
19487 + brhs 3f /* Check op2 for NaN or Inf */
19488 +
19489 + lsl r11,7
19490 + sbr r11, 31 /*Implicit bit*/
19491 +14:
19492 +
19493 + /* For UC3, store with predecrement is faster than stm */
19494 + st.w --sp, r5
19495 + st.d --sp, r6
19496 +
19497 + /* Calculate new exponent */
19498 + sub r9, r10
19499 + sub r9,-127
19500 +
19501 + /* Divide */
19502 + /* Approximating 1/d with the following recurrence: */
19503 + /* R[j+1] = R[j]*(2-R[j]*d) */
19504 + /* Using 2.30 format */
19505 + /* TWO: r10 */
19506 + /* d: r5 */
19507 + /* Multiply result : r6, r7 */
19508 + /* Initial guess : r11 */
19509 + /* New approximations : r11 */
19510 + /* Dividend : r12 */
19511 +
19512 + /* Load TWO */
19513 + mov_imm r10, 0x80000000
19514 +
19515 + lsr r12, 2 /* Get significand of Op1 in 2.30 format */
19516 + lsr r5, r11, 2 /* Get significand of Op2 (=d) in 2.30 format */
19517 +
19518 + /* Load initial guess, using look-up table */
19519 + /* Initial guess is of format 01.XY, where XY is constructed as follows: */
19520 + /* Let d be of following format: 00.1xy....., then XY=~xy */
19521 + /* For d=00.100 = 0,5 -> initial guess=01.11 = 1,75 */
19522 + /* For d=00.101 = 0,625 -> initial guess=01.11 = 1,5 */
19523 + /* For d=00.110 = 0,75 -> initial guess=01.11 = 1,25 */
19524 + /* For d=00.111 = 0,875 -> initial guess=01.11 = 1,0 */
19525 +
19526 + lsr r11, r10, 1
19527 + bfextu r6, r5, 27, 2
19528 + com r6
19529 + bfins r11, r6, 28, 2
19530 +
19531 + /* First approximation */
19532 + /* r7 = R[j]*d */
19533 + mulu.d r6, r11, r5
19534 + /* r7 = 2-R[j]*d */
19535 + sub r7, r10, r7<<2
19536 + /* r11 = R[j]*(2-R[j]*d) */
19537 + mulu.d r6, r11, r7
19538 + lsl r11, r7, 2
19539 +
19540 + /* Second approximation */
19541 + /* r7 = R[j]*d */
19542 + mulu.d r6, r11, r5
19543 + /* r7 = 2-R[j]*d */
19544 + sub r7, r10, r7<<2
19545 + /* r11 = R[j]*(2-R[j]*d) */
19546 + mulu.d r6, r11, r7
19547 + lsl r11, r7, 2
19548 +
19549 + /* Third approximation */
19550 + /* r7 = R[j]*d */
19551 + mulu.d r6, r11, r5
19552 + /* r7 = 2-R[j]*d */
19553 + sub r7, r10, r7<<2
19554 + /* r11 = R[j]*(2-R[j]*d) */
19555 + mulu.d r6, r11, r7
19556 + lsl r11, r7, 2
19557 +
19558 + /* Fourth approximation */
19559 + /* r7 = R[j]*d */
19560 + mulu.d r6, r11, r5
19561 + /* r7 = 2-R[j]*d */
19562 + sub r7, r10, r7<<2
19563 + /* r11 = R[j]*(2-R[j]*d) */
19564 + mulu.d r6, r11, r7
19565 + lsl r11, r7, 2
19566 +
19567 +
19568 + /* Multiply with dividend to get quotient, r7 = sf(op1)/sf(op2) */
19569 + mulu.d r6, r11, r12
19570 +
19571 + /* Shift by 3 to get result in 1.31 format, as required by the exponent. */
19572 + /* Note that 1.31 format is already used by the exponent in r9, since */
19573 + /* a bias of 127 was added to the result exponent, even though the implicit */
19574 + /* bit was inserted. This gives the exponent an additional bias of 1, which */
19575 + /* supports 1.31 format. */
19576 + //lsl r10, r7, 3
19577 +
19578 + /* Adjust exponent and mantissa in case the result is of format
19579 + 0000.1xxx to 0001.xxx*/
19580 +#if defined(L_avr32_f32_div)
19581 + lsr r12, 4 /* Scale dividend to 6.26 format to match the
19582 + result of the multiplication of the divisor and
19583 + quotient to get the remainder. */
19584 +#endif
19585 + bld r7, 31-3
19586 + breq 0f
19587 + lsl r7, 1
19588 + sub r9, 1
19589 +#if defined(L_avr32_f32_div)
19590 + lsl r12, 1 /* Scale dividend to 5.27 format to match the
19591 + result of the multiplication of the divisor and
19592 + quotient to get the remainder. */
19593 +#endif
19594 +0:
19595 + cp r9, 0
19596 + brle __avr32_f32_div_res_subnormal /* Result was subnormal. */
19597 +
19598 +
19599 +#if defined(L_avr32_f32_div)
19600 + /* In order to round correctly we calculate the remainder:
19601 + Remainder = dividend[r12] - divisor[r5]*quotient[r7]
19602 + for the case when the quotient is halfway between the round-up
19603 + value and the round down value. If the remainder then is negative
19604 + it means that the quotient was to big and that it should not be
19605 + rounded up, if the remainder is positive the quotient was to small
19606 + and we need to round up. If the remainder is zero it means that the
19607 + quotient is exact but since we need to remove the guard bit we should
19608 + round to even. */
19609 + andl r7, 0xffe0
19610 + orl r7, 0x0010
19611 +
19612 + /* Now do the multiplication. The quotient has the format 4.28
19613 + while the divisor has the format 2.30 which gives a result
19614 + of 6.26 */
19615 + mulu.d r10, r5, r7
19616 +
19617 + /* Check if remainder is positive, negative or equal. */
19618 + bfextu r5, r7, 5, 1 /* Get parity bit into bit 0 of r5 */
19619 + cp r10, 0
19620 +__avr32_f32_div_round_subnormal:
19621 + cpc r11, r12
19622 + srlo r11 /* Remainder positive: we need to round up.*/
19623 + moveq r11, r5 /* Remainder zero: round up if mantissa odd. */
19624 +#else
19625 + bfextu r11, r7, 4, 1 /* Get guard bit */
19626 +#endif
19627 +
19628 + /* Pack final result*/
19629 + lsr r12, r7, 5
19630 + bfins r12, r9, 23, 8
19631 + /* For UC3, load with postincrement is faster than ldm */
19632 + ld.d r6, sp++
19633 + ld.w r5, sp++
19634 + bld r8, 31
19635 + bst r12, 31
19636 + /* Rounding add. */
19637 + add r12, r11
19638 + ret r12
19639 +
19640 +__divsf_return_op1:
19641 + lsl r8, 1
19642 + ror r12
19643 + ret r12
19644 +
19645 +
19646 +2:
19647 + /* Op1 is NaN or inf */
19648 + retne -1 /* Return NaN if op1 is NaN */
19649 + /* Op1 is inf check op2 */
19650 + mov_imm r9, 0xff000000
19651 + cp r11, r9
19652 + brlo __divsf_return_op1 /* inf/number gives inf */
19653 + ret -1 /* The rest gives NaN*/
19654 +3:
19655 + /* Op2 is NaN or inf */
19656 + reteq 0 /* Return zero if number/inf*/
19657 + ret -1 /* Return NaN*/
19658 +4:
19659 + /* Op2 is zero ? */
19660 + tst r12,r12
19661 + reteq -1 /* 0.0/0.0 is NaN */
19662 + /* Nonzero/0.0 is Inf. Sign bit will be shifted in before returning*/
19663 + mov_imm r12, 0xff000000
19664 + rjmp __divsf_return_op1
19665 +
19666 +11: /* Op1 was denormal. Fix it. */
19667 + lsl r12,7
19668 + clz r9,r12
19669 + lsl r12,r12,r9
19670 + rsub r9,r9,1
19671 + rjmp 12b
19672 +
19673 +13: /* Op2 was denormal. Fix it. */
19674 + lsl r11,7
19675 + clz r10,r11
19676 + lsl r11,r11,r10
19677 + rsub r10,r10,1
19678 + rjmp 14b
19679 +
19680 +
19681 +__avr32_f32_div_res_subnormal: /* Divide result was subnormal */
19682 +#if defined(L_avr32_f32_div)
19683 + /* Check how much we must scale down the mantissa. */
19684 + neg r9
19685 + sub r9, -1 /* We do no longer have an implicit bit. */
19686 + satu r9 >> 0, 5 /* Saturate shift amount to max 32. */
19687 + /* Scale down quotient */
19688 + rsub r10, r9, 32
19689 + lsr r7, r7, r9
19690 + /* Scale down the dividend to match the scaling of the quotient. */
19691 + lsl r6, r12, r10 /* Make the divident 64-bit and put the lsw in r6 */
19692 + lsr r12, r12, r9
19693 +
19694 + /* Start performing the same rounding as done for normal numbers
19695 + but this time we have scaled the quotient and dividend and hence
19696 + need a little different comparison. */
19697 + andl r7, 0xffe0
19698 + orl r7, 0x0010
19699 +
19700 + /* Now do the multiplication. The quotient has the format 4.28
19701 + while the divisor has the format 2.30 which gives a result
19702 + of 6.26 */
19703 + mulu.d r10, r5, r7
19704 +
19705 + /* Set exponent to 0 */
19706 + mov r9, 0
19707 +
19708 + /* Check if remainder is positive, negative or equal. */
19709 + bfextu r5, r7, 5, 1 /* Get parity bit into bit 0 of r5 */
19710 + cp r10, r6
19711 + rjmp __avr32_f32_div_round_subnormal
19712 +
19713 +#else
19714 + ld.d r6, sp++
19715 + ld.w r5, sp++
19716 + /*Flush to zero*/
19717 + ret 0
19718 +#endif
19719 +#endif
19720 +
19721 +#ifdef L_avr32_f32_mul
19722 + .global __avr32_f32_mul
19723 + .type __avr32_f32_mul,@function
19724 +
19725 +
19726 +__avr32_f32_mul:
19727 + mov r8, r12
19728 + eor r12, r11 /* MSB(r8) = Sign(op1) ^ Sign(op2) */
19729 + andh r12, 0x8000, COH
19730 +
19731 + /* arrange operands so that that op1 >= op2 */
19732 + cbr r8, 31
19733 + breq __avr32_f32_mul_op1_zero
19734 + cbr r11, 31
19735 +
19736 + /* Put the number with the largest exponent in r10
19737 + and the number with the smallest exponent in r9 */
19738 + max r10, r8, r11
19739 + min r9, r8, r11
19740 +
19741 + /* Unpack exponent and mantissa of op1 */
19742 + lsl r8, r10, 8
19743 + sbr r8, 31 /* Set implicit bit. */
19744 + lsr r10, 23
19745 +
19746 + /* op1 is NaN or Inf. */
19747 + cp.w r10, 0xff
19748 + breq __avr32_f32_mul_op1_nan_or_inf
19749 +
19750 + /* Unpack exponent and mantissa of op2 */
19751 + lsl r11, r9, 8
19752 + sbr r11, 31 /* Set implicit bit. */
19753 + lsr r9, 23
19754 +
19755 + /* op2 is either zero or subnormal. */
19756 + breq __avr32_f32_mul_op2_subnormal
19757 +0:
19758 + /* Calculate new exponent */
19759 + add r9,r10
19760 +
19761 + /* Do the multiplication */
19762 + mulu.d r10,r8,r11
19763 +
19764 + /* We might need to scale up by two if the MSB of the result is
19765 + zero. */
19766 + lsl r8, r11, 1
19767 + movcc r11, r8
19768 + subcc r9, 1
19769 +
19770 + /* Put the shifted out bits of the mantissa into r10 */
19771 + lsr r10, 8
19772 + bfins r10, r11, 24, 8
19773 +
19774 + sub r9,(127-1) /* remove extra exponent bias */
19775 + brle __avr32_f32_mul_res_subnormal
19776 +
19777 + /* Check for Inf. */
19778 + cp.w r9, 0xff
19779 + brge 1f
19780 +
19781 + /* Pack result. */
19782 + or r12, r12, r11 >> 8
19783 + bfins r12, r9, 23, 8
19784 +
19785 + /* Round */
19786 +__avr32_f32_mul_round:
19787 + mov_imm r8, 0x80000000
19788 + bld r12, 0
19789 + subne r8, -1
19790 +
19791 + cp.w r10, r8
19792 + subhs r12, -1
19793 +
19794 + ret r12
19795 +
19796 +1:
19797 + /* Return Inf */
19798 + orh r12, 0x7f80
19799 + ret r12
19800 +
19801 +__avr32_f32_mul_op2_subnormal:
19802 + cbr r11, 31
19803 + clz r9, r11
19804 + retcs 0 /* op2 is zero. Return 0 */
19805 + lsl r11, r11, r9
19806 + rsub r9, r9, 1
19807 +
19808 + /* Check if op2 is subnormal. */
19809 + tst r10, r10
19810 + brne 0b
19811 +
19812 + /* op2 is subnormal */
19813 + cbr r8, 31
19814 + clz r10, r11
19815 + retcs 0 /* op1 is zero. Return 0 */
19816 + lsl r8, r8, r10
19817 + rsub r10, r10, 1
19818 +
19819 + rjmp 0b
19820 +
19821 +
19822 +__avr32_f32_mul_op1_nan_or_inf:
19823 + /* Check if op1 is NaN, if so return NaN */
19824 + lsl r11, r8, 1
19825 + retne -1
19826 +
19827 + /* op1 is Inf. */
19828 + tst r9, r9
19829 + reteq -1 /* Inf * 0 -> NaN */
19830 +
19831 + bfins r12, r10, 23, 8 /* Generate Inf in r12 */
19832 +
19833 + /* Check if op2 is Inf. or NaN */
19834 + lsr r11, r9, 23
19835 + cp.w r11, 0xff
19836 + retne r12 /* op2 not Inf or NaN, return Info */
19837 +
19838 + lsl r9, 9
19839 + reteq r12 /* op2 Inf return Inf */
19840 + ret -1 /* op2 is NaN, return NaN */
19841 +
19842 +__avr32_f32_mul_res_subnormal:
19843 + /* Check if the number is so small that
19844 + it will be represented with zero. */
19845 + rsub r9, r9, 9
19846 + rsub r8, r9, 32
19847 + retcs 0
19848 +
19849 + /* Shift the mantissa into the correct position.*/
19850 + lsr r9, r11, r9
19851 + /* Add sign bit. */
19852 + or r12, r9
19853 + /* Put the shifted out bits in the most significant part
19854 + of r8. */
19855 + lsl r11, r11, r8
19856 +
19857 + /* Add all the remainder bits used for rounding into r11 */
19858 + andh r10, 0x00FF
19859 + or r10, r11
19860 + rjmp __avr32_f32_mul_round
19861 +
19862 +__avr32_f32_mul_op1_zero:
19863 + bfextu r10, r11, 23, 8
19864 + cp.w r10, 0xff
19865 + retne r12
19866 + reteq -1
19867 +
19868 +#endif
19869 +
19870 +
19871 +#ifdef L_avr32_s32_to_f32
19872 + .global __avr32_s32_to_f32
19873 + .type __avr32_s32_to_f32,@function
19874 +__avr32_s32_to_f32:
19875 + cp r12, 0
19876 + reteq r12 /* If zero then return zero float */
19877 + mov r11, r12 /* Keep the sign */
19878 + abs r12 /* Compute the absolute value */
19879 + mov r10, 31 + 127 /* Set the correct exponent */
19880 +
19881 + /* Normalize */
19882 + normalize_sf r10 /*exp*/, r12 /*mant*/, r9 /*scratch*/
19883 +
19884 + /* Check for subnormal result */
19885 + cp.w r10, 0
19886 + brle __avr32_s32_to_f32_subnormal
19887 +
19888 + round_sf r10 /*exp*/, r12 /*mant*/, r9 /*scratch*/
19889 + pack_sf r12 /*sf*/, r10 /*exp*/, r12 /*mant*/
19890 + lsl r11, 1
19891 + ror r12
19892 + ret r12
19893 +
19894 +__avr32_s32_to_f32_subnormal:
19895 + /* Adjust a subnormal result */
19896 + adjust_subnormal_sf r12/*sf*/, r10 /*exp*/, r12 /*mant*/, r11/*sign*/, r9 /*scratch*/
19897 + ret r12
19898 +
19899 +#endif
19900 +
19901 +#ifdef L_avr32_u32_to_f32
19902 + .global __avr32_u32_to_f32
19903 + .type __avr32_u32_to_f32,@function
19904 +__avr32_u32_to_f32:
19905 + cp r12, 0
19906 + reteq r12 /* If zero then return zero float */
19907 + mov r10, 31 + 127 /* Set the correct exponent */
19908 +
19909 + /* Normalize */
19910 + normalize_sf r10 /*exp*/, r12 /*mant*/, r9 /*scratch*/
19911 +
19912 + /* Check for subnormal result */
19913 + cp.w r10, 0
19914 + brle __avr32_u32_to_f32_subnormal
19915 +
19916 + round_sf r10 /*exp*/, r12 /*mant*/, r9 /*scratch*/
19917 + pack_sf r12 /*sf*/, r10 /*exp*/, r12 /*mant*/
19918 + lsr r12,1 /* Sign bit is 0 for unsigned int */
19919 + ret r12
19920 +
19921 +__avr32_u32_to_f32_subnormal:
19922 + /* Adjust a subnormal result */
19923 + mov r8, 0
19924 + adjust_subnormal_sf r12/*sf*/,r10 /*exp*/, r12 /*mant*/,r8/*sign*/, r9 /*scratch*/
19925 + ret r12
19926 +
19927 +
19928 +#endif
19929 +
19930 +
19931 +#ifdef L_avr32_f32_to_s32
19932 + .global __avr32_f32_to_s32
19933 + .type __avr32_f32_to_s32,@function
19934 +__avr32_f32_to_s32:
19935 + bfextu r11, r12, 23, 8
19936 + sub r11,127 /* Fix bias */
19937 + retlo 0 /* Negative exponent yields zero integer */
19938 +
19939 + /* Shift mantissa into correct position */
19940 + rsub r11,r11,31 /* Shift amount */
19941 + lsl r10,r12,8 /* Get mantissa */
19942 + sbr r10,31 /* Add implicit bit */
19943 + lsr r10,r10,r11 /* Perform shift */
19944 + lsl r12,1 /* Check sign */
19945 + retcc r10 /* if positive, we are done */
19946 + neg r10 /* if negative float, negate result */
19947 + ret r10
19948 +
19949 +#endif
19950 +
19951 +#ifdef L_avr32_f32_to_u32
19952 + .global __avr32_f32_to_u32
19953 + .type __avr32_f32_to_u32,@function
19954 +__avr32_f32_to_u32:
19955 + cp r12,0
19956 + retmi 0 /* Negative numbers gives 0 */
19957 + bfextu r11, r12, 23, 8 /* Extract exponent */
19958 + sub r11,127 /* Fix bias */
19959 + retlo 0 /* Negative exponent yields zero integer */
19960 +
19961 + /* Shift mantissa into correct position */
19962 + rsub r11,r11,31 /* Shift amount */
19963 + lsl r12,8 /* Get mantissa */
19964 + sbr r12,31 /* Add implicit bit */
19965 + lsr r12,r12,r11 /* Perform shift */
19966 + ret r12
19967 +
19968 +#endif
19969 +
19970 +#ifdef L_avr32_f32_to_f64
19971 + .global __avr32_f32_to_f64
19972 + .type __avr32_f32_to_f64,@function
19973 +
19974 +__avr32_f32_to_f64:
19975 + lsl r11,r12,1 /* Remove sign bit, keep original value in r12*/
19976 + moveq r10, 0
19977 + reteq r11 /* Return zero if input is zero */
19978 +
19979 + bfextu r9,r11,24,8 /* Get exponent */
19980 + cp.w r9,0xff /* check for NaN or inf */
19981 + breq 0f
19982 +
19983 + lsl r11,7 /* Convert sf mantissa to df format */
19984 + mov r10,0
19985 +
19986 + /* Check if implicit bit should be set */
19987 + cp.w r9, 0
19988 + subeq r9,-1 /* Adjust exponent if it was 0 */
19989 + srne r8
19990 + or r11, r11, r8 << 31 /* Set implicit bit if needed */
19991 + sub r9,(127-0x3ff) /* Convert exponent to df format exponent */
19992 +
19993 + /*We know that low register of mantissa is 0, and will be unaffected by normalization.*/
19994 + /*We can therefore use the faster normalize_sf function instead of normalize_df.*/
19995 + normalize_sf r9 /*exp*/, r11 /*mantissa*/, r8 /*scratch*/
19996 + pack_df r9 /*exp*/, r10, r11 /*mantissa*/, r10, r11 /*df*/
19997 +
19998 +__extendsfdf_return_op1:
19999 + /* Rotate in sign bit */
20000 + lsl r12, 1
20001 + ror r11
20002 + ret r11
20003 +
20004 +0:
20005 + /* Inf or NaN*/
20006 + mov_imm r10, 0xffe00000
20007 + lsl r11,8 /* check mantissa */
20008 + movne r11, -1 /* Return NaN */
20009 + moveq r11, r10 /* Return inf */
20010 + rjmp __extendsfdf_return_op1
20011 +#endif
20012 +
20013 +
20014 +#ifdef L_avr32_f64_to_f32
20015 + .global __avr32_f64_to_f32
20016 + .type __avr32_f64_to_f32,@function
20017 +
20018 +__avr32_f64_to_f32:
20019 + /* Unpack */
20020 + lsl r9,r11,1 /* Unpack exponent */
20021 + lsr r9,21
20022 +
20023 + reteq 0 /* If exponent is 0 the number is so small
20024 + that the conversion to single float gives
20025 + zero */
20026 +
20027 + lsl r8,r11,10 /* Adjust mantissa */
20028 + or r12,r8,r10>>22
20029 +
20030 + lsl r10,10 /* Check if there are any remaining bits
20031 + in the low part of the mantissa.*/
20032 + neg r10
20033 + rol r12 /* If there were remaining bits then set lsb
20034 + of mantissa to 1 */
20035 +
20036 + cp r9,0x7ff
20037 + breq 2f /* Check for NaN or inf */
20038 +
20039 + sub r9,(0x3ff-127) /* Adjust bias of exponent */
20040 + sbr r12,31 /* set the implicit bit.*/
20041 +
20042 + cp.w r9, 0 /* Check for subnormal number */
20043 + brle 3f
20044 +
20045 + round_sf r9 /*exp*/, r12 /*mant*/, r10 /*scratch*/
20046 + pack_sf r12 /*sf*/, r9 /*exp*/, r12 /*mant*/
20047 +__truncdfsf_return_op1:
20048 + /* Rotate in sign bit */
20049 + lsl r11, 1
20050 + ror r12
20051 + ret r12
20052 +
20053 +2:
20054 + /* NaN or inf */
20055 + cbr r12,31 /* clear implicit bit */
20056 + retne -1 /* Return NaN if mantissa not zero */
20057 + mov_imm r12, 0xff000000
20058 + ret r12 /* Return inf */
20059 +
20060 +3: /* Result is subnormal. Adjust it.*/
20061 + adjust_subnormal_sf r12/*sf*/,r9 /*exp*/, r12 /*mant*/, r11/*sign*/, r10 /*scratch*/
20062 + ret r12
20063 +
20064 +
20065 +#endif
20066 +
20067 +#if defined(L_mulsi3) && defined(__AVR32_NO_MUL__)
20068 + .global __mulsi3
20069 + .type __mulsi3,@function
20070 +
20071 +__mulsi3:
20072 + mov r9, 0
20073 +0:
20074 + lsr r11, 1
20075 + addcs r9, r9, r12
20076 + breq 1f
20077 + lsl r12, 1
20078 + rjmp 0b
20079 +1:
20080 + ret r9
20081 +#endif
20082 --- /dev/null
20083 +++ b/gcc/config/avr32/lib2funcs.S
20084 @@ -0,0 +1,21 @@
20085 + .align 4
20086 + .global __nonlocal_goto
20087 + .type __nonlocal_goto,@function
20088 +
20089 +/* __nonlocal_goto: This function handles nonlocal_goto's in gcc.
20090 +
20091 + parameter 0 (r12) = New Frame Pointer
20092 + parameter 1 (r11) = Address to goto
20093 + parameter 2 (r10) = New Stack Pointer
20094 +
20095 + This function invalidates the return stack, since it returns from a
20096 + function without using a return instruction.
20097 +*/
20098 +__nonlocal_goto:
20099 + mov r7, r12
20100 + mov sp, r10
20101 + frs # Flush return stack
20102 + mov pc, r11
20103 +
20104 +
20105 +
20106 --- /dev/null
20107 +++ b/gcc/config/avr32/linux-elf.h
20108 @@ -0,0 +1,151 @@
20109 +/*
20110 + Linux/Elf specific definitions.
20111 + Copyright 2003-2006 Atmel Corporation.
20112 +
20113 + Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
20114 + and H�vard Skinnemoen, Atmel Norway, <hskinnemoen@atmel.com>
20115 +
20116 + This file is part of GCC.
20117 +
20118 + This program is free software; you can redistribute it and/or modify
20119 + it under the terms of the GNU General Public License as published by
20120 + the Free Software Foundation; either version 2 of the License, or
20121 + (at your option) any later version.
20122 +
20123 + This program is distributed in the hope that it will be useful,
20124 + but WITHOUT ANY WARRANTY; without even the implied warranty of
20125 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20126 + GNU General Public License for more details.
20127 +
20128 + You should have received a copy of the GNU General Public License
20129 + along with this program; if not, write to the Free Software
20130 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20131 +
20132 +
20133 +
20134 +/* elfos.h should have already been included. Now just override
20135 + any conflicting definitions and add any extras. */
20136 +
20137 +/* Run-time Target Specification. */
20138 +#undef TARGET_VERSION
20139 +#define TARGET_VERSION fputs (" (AVR32 GNU/Linux with ELF)", stderr);
20140 +
20141 +/* Do not assume anything about header files. */
20142 +#define NO_IMPLICIT_EXTERN_C
20143 +
20144 +/* The GNU C++ standard library requires that these macros be defined. */
20145 +#undef CPLUSPLUS_CPP_SPEC
20146 +#define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)"
20147 +
20148 +/* Now we define the strings used to build the spec file. */
20149 +#undef LIB_SPEC
20150 +#define LIB_SPEC \
20151 + "%{pthread:-lpthread} \
20152 + %{shared:-lc} \
20153 + %{!shared:%{profile:-lc_p}%{!profile:-lc}}"
20154 +
20155 +/* Provide a STARTFILE_SPEC appropriate for GNU/Linux. Here we add
20156 + the GNU/Linux magical crtbegin.o file (see crtstuff.c) which
20157 + provides part of the support for getting C++ file-scope static
20158 + object constructed before entering `main'. */
20159 +
20160 +#undef STARTFILE_SPEC
20161 +#define STARTFILE_SPEC \
20162 + "%{!shared: \
20163 + %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \
20164 + %{!p:%{profile:gcrt1.o%s} \
20165 + %{!profile:crt1.o%s}}}} \
20166 + crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}"
20167 +
20168 +/* Provide a ENDFILE_SPEC appropriate for GNU/Linux. Here we tack on
20169 + the GNU/Linux magical crtend.o file (see crtstuff.c) which
20170 + provides part of the support for getting C++ file-scope static
20171 + object constructed before entering `main', followed by a normal
20172 + GNU/Linux "finalizer" file, `crtn.o'. */
20173 +
20174 +#undef ENDFILE_SPEC
20175 +#define ENDFILE_SPEC \
20176 + "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s"
20177 +
20178 +#undef ASM_SPEC
20179 +#define ASM_SPEC "%{!mno-pic:%{!fno-pic:--pic}} %{mrelax|O*:%{mno-relax|O0|O1: ;:--linkrelax}} %{mcpu=*:-mcpu=%*}"
20180 +
20181 +#undef LINK_SPEC
20182 +#define LINK_SPEC "%{version:-v} \
20183 + %{static:-Bstatic} \
20184 + %{shared:-shared} \
20185 + %{symbolic:-Bsymbolic} \
20186 + %{rdynamic:-export-dynamic} \
20187 + %{!dynamic-linker:-dynamic-linker /lib/ld-uClibc.so.0} \
20188 + %{mrelax|O*:%{mno-relax|O0|O1: ;:--relax}}"
20189 +
20190 +#define TARGET_OS_CPP_BUILTINS() LINUX_TARGET_OS_CPP_BUILTINS()
20191 +
20192 +/* This is how we tell the assembler that two symbols have the same value. */
20193 +#define ASM_OUTPUT_DEF(FILE, NAME1, NAME2) \
20194 + do \
20195 + { \
20196 + assemble_name (FILE, NAME1); \
20197 + fputs (" = ", FILE); \
20198 + assemble_name (FILE, NAME2); \
20199 + fputc ('\n', FILE); \
20200 + } \
20201 + while (0)
20202 +
20203 +
20204 +
20205 +#undef CC1_SPEC
20206 +#define CC1_SPEC "%{profile:-p}"
20207 +
20208 +/* Target CPU builtins. */
20209 +#define TARGET_CPU_CPP_BUILTINS() \
20210 + do \
20211 + { \
20212 + builtin_define ("__avr32__"); \
20213 + builtin_define ("__AVR32__"); \
20214 + builtin_define ("__AVR32_LINUX__"); \
20215 + builtin_define (avr32_part->macro); \
20216 + builtin_define (avr32_arch->macro); \
20217 + if (avr32_arch->uarch_type == UARCH_TYPE_AVR32A) \
20218 + builtin_define ("__AVR32_AVR32A__"); \
20219 + else \
20220 + builtin_define ("__AVR32_AVR32B__"); \
20221 + if (TARGET_UNALIGNED_WORD) \
20222 + builtin_define ("__AVR32_HAS_UNALIGNED_WORD__"); \
20223 + if (TARGET_SIMD) \
20224 + builtin_define ("__AVR32_HAS_SIMD__"); \
20225 + if (TARGET_DSP) \
20226 + builtin_define ("__AVR32_HAS_DSP__"); \
20227 + if (TARGET_RMW) \
20228 + builtin_define ("__AVR32_HAS_RMW__"); \
20229 + if (TARGET_BRANCH_PRED) \
20230 + builtin_define ("__AVR32_HAS_BRANCH_PRED__"); \
20231 + if (TARGET_FAST_FLOAT) \
20232 + builtin_define ("__AVR32_FAST_FLOAT__"); \
20233 + } \
20234 + while (0)
20235 +
20236 +
20237 +
20238 +/* Call the function profiler with a given profile label. */
20239 +#undef FUNCTION_PROFILER
20240 +#define FUNCTION_PROFILER(STREAM, LABELNO) \
20241 + do \
20242 + { \
20243 + fprintf (STREAM, "\tmov\tlr, lo(mcount)\n\torh\tlr, hi(mcount)\n"); \
20244 + fprintf (STREAM, "\ticall lr\n"); \
20245 + } \
20246 + while (0)
20247 +
20248 +#define NO_PROFILE_COUNTERS 1
20249 +
20250 +/* For dynamic libraries to work */
20251 +/* #define PLT_REG_CALL_CLOBBERED 1 */
20252 +#define AVR32_ALWAYS_PIC 1
20253 +
20254 +/* uclibc does not implement sinf, cosf etc. */
20255 +#undef TARGET_C99_FUNCTIONS
20256 +#define TARGET_C99_FUNCTIONS 0
20257 +
20258 +#define LINK_GCC_C_SEQUENCE_SPEC \
20259 + "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
20260 --- /dev/null
20261 +++ b/gcc/config/avr32/predicates.md
20262 @@ -0,0 +1,386 @@
20263 +;; AVR32 predicates file.
20264 +;; Copyright 2003-2006 Atmel Corporation.
20265 +;;
20266 +;; Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
20267 +;;
20268 +;; This file is part of GCC.
20269 +;;
20270 +;; This program is free software; you can redistribute it and/or modify
20271 +;; it under the terms of the GNU General Public License as published by
20272 +;; the Free Software Foundation; either version 2 of the License, or
20273 +;; (at your option) any later version.
20274 +;;
20275 +;; This program is distributed in the hope that it will be useful,
20276 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20277 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20278 +;; GNU General Public License for more details.
20279 +;;
20280 +;; You should have received a copy of the GNU General Public License
20281 +;; along with this program; if not, write to the Free Software
20282 +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20283 +
20284 +
20285 +;; True if the operand is a memory reference which contains an
20286 +;; Address consisting of a single pointer register
20287 +(define_predicate "avr32_indirect_register_operand"
20288 + (and (match_code "mem")
20289 + (match_test "register_operand(XEXP(op, 0), SImode)")))
20290 +
20291 +
20292 +
20293 +;; Address expression with a base pointer offset with
20294 +;; a register displacement
20295 +(define_predicate "avr32_indexed_memory_operand"
20296 + (and (match_code "mem")
20297 + (match_test "GET_CODE(XEXP(op, 0)) == PLUS"))
20298 + {
20299 +
20300 + rtx op0 = XEXP(XEXP(op, 0), 0);
20301 + rtx op1 = XEXP(XEXP(op, 0), 1);
20302 +
20303 + return ((avr32_address_register_rtx_p (op0, 0)
20304 + && avr32_legitimate_index_p (GET_MODE(op), op1, 0))
20305 + || (avr32_address_register_rtx_p (op1, 0)
20306 + && avr32_legitimate_index_p (GET_MODE(op), op0, 0)));
20307 +
20308 + })
20309 +
20310 +;; Operand suitable for the ld.sb instruction
20311 +(define_predicate "load_sb_memory_operand"
20312 + (ior (match_operand 0 "avr32_indirect_register_operand")
20313 + (match_operand 0 "avr32_indexed_memory_operand")))
20314 +
20315 +
20316 +;; Operand suitable as operand to insns sign extending QI values
20317 +(define_predicate "extendqi_operand"
20318 + (ior (match_operand 0 "load_sb_memory_operand")
20319 + (match_operand 0 "register_operand")))
20320 +
20321 +(define_predicate "post_inc_memory_operand"
20322 + (and (match_code "mem")
20323 + (match_test "(GET_CODE(XEXP(op, 0)) == POST_INC)
20324 + && REG_P(XEXP(XEXP(op, 0), 0))")))
20325 +
20326 +(define_predicate "pre_dec_memory_operand"
20327 + (and (match_code "mem")
20328 + (match_test "(GET_CODE(XEXP(op, 0)) == PRE_DEC)
20329 + && REG_P(XEXP(XEXP(op, 0), 0))")))
20330 +
20331 +;; Operand suitable for add instructions
20332 +(define_predicate "avr32_add_operand"
20333 + (ior (match_operand 0 "register_operand")
20334 + (and (match_operand 0 "immediate_operand")
20335 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'I', \"Is21\")"))))
20336 +
20337 +;; Operand is a power of two immediate
20338 +(define_predicate "power_of_two_operand"
20339 + (match_code "const_int")
20340 +{
20341 + HOST_WIDE_INT value = INTVAL (op);
20342 +
20343 + return value != 0 && (value & (value - 1)) == 0;
20344 +})
20345 +
20346 +;; Operand is a multiple of 8 immediate
20347 +(define_predicate "multiple_of_8_operand"
20348 + (match_code "const_int")
20349 +{
20350 + HOST_WIDE_INT value = INTVAL (op);
20351 +
20352 + return (value & 0x7) == 0 ;
20353 +})
20354 +
20355 +;; Operand is a multiple of 16 immediate
20356 +(define_predicate "multiple_of_16_operand"
20357 + (match_code "const_int")
20358 +{
20359 + HOST_WIDE_INT value = INTVAL (op);
20360 +
20361 + return (value & 0xf) == 0 ;
20362 +})
20363 +
20364 +;; Operand is a mask used for masking away upper bits of a reg
20365 +(define_predicate "avr32_mask_upper_bits_operand"
20366 + (match_code "const_int")
20367 +{
20368 + HOST_WIDE_INT value = INTVAL (op) + 1;
20369 +
20370 + return value != 1 && value != 0 && (value & (value - 1)) == 0;
20371 +})
20372 +
20373 +
20374 +;; Operand suitable for mul instructions
20375 +(define_predicate "avr32_mul_operand"
20376 + (ior (match_operand 0 "register_operand")
20377 + (and (match_operand 0 "immediate_operand")
20378 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'K', \"Ks08\")"))))
20379 +
20380 +;; True for logical binary operators.
20381 +(define_predicate "logical_binary_operator"
20382 + (match_code "ior,xor,and"))
20383 +
20384 +;; True for logical shift operators
20385 +(define_predicate "logical_shift_operator"
20386 + (match_code "ashift,lshiftrt"))
20387 +
20388 +;; True for shift operand for logical and, or and eor insns
20389 +(define_predicate "avr32_logical_shift_operand"
20390 + (and (match_code "ashift,lshiftrt")
20391 + (ior (and (match_test "GET_CODE(XEXP(op, 1)) == CONST_INT")
20392 + (match_test "register_operand(XEXP(op, 0), GET_MODE(XEXP(op, 0)))"))
20393 + (and (match_test "GET_CODE(XEXP(op, 0)) == CONST_INT")
20394 + (match_test "register_operand(XEXP(op, 1), GET_MODE(XEXP(op, 1)))"))))
20395 + )
20396 +
20397 +
20398 +;; Predicate for second operand to and, ior and xor insn patterns
20399 +(define_predicate "avr32_logical_insn_operand"
20400 + (ior (match_operand 0 "register_operand")
20401 + (match_operand 0 "avr32_logical_shift_operand"))
20402 +)
20403 +
20404 +
20405 +;; True for avr32 comparison operators
20406 +(define_predicate "avr32_comparison_operator"
20407 + (ior (match_code "eq, ne, gt, ge, lt, le, gtu, geu, ltu, leu")
20408 + (and (match_code "unspec")
20409 + (match_test "(XINT(op, 1) == UNSPEC_COND_MI)
20410 + || (XINT(op, 1) == UNSPEC_COND_PL)"))))
20411 +
20412 +(define_predicate "avr32_cond3_comparison_operator"
20413 + (ior (match_code "eq, ne, ge, lt, geu, ltu")
20414 + (and (match_code "unspec")
20415 + (match_test "(XINT(op, 1) == UNSPEC_COND_MI)
20416 + || (XINT(op, 1) == UNSPEC_COND_PL)"))))
20417 +
20418 +;; True for avr32 comparison operand
20419 +(define_predicate "avr32_comparison_operand"
20420 + (ior (and (match_code "eq, ne, gt, ge, lt, le, gtu, geu, ltu, leu")
20421 + (match_test "(CC0_P (XEXP(op,0)) && rtx_equal_p (XEXP(op,1), const0_rtx))"))
20422 + (and (match_code "unspec")
20423 + (match_test "(XINT(op, 1) == UNSPEC_COND_MI)
20424 + || (XINT(op, 1) == UNSPEC_COND_PL)"))))
20425 +
20426 +;; True if this is a const_int with one bit set
20427 +(define_predicate "one_bit_set_operand"
20428 + (match_code "const_int")
20429 + {
20430 + int i;
20431 + int value;
20432 + int ones = 0;
20433 +
20434 + value = INTVAL(op);
20435 + for ( i = 0 ; i < 32; i++ ){
20436 + if ( value & ( 1 << i ) ){
20437 + ones++;
20438 + }
20439 + }
20440 +
20441 + return ( ones == 1 );
20442 + })
20443 +
20444 +
20445 +;; True if this is a const_int with one bit cleared
20446 +(define_predicate "one_bit_cleared_operand"
20447 + (match_code "const_int")
20448 + {
20449 + int i;
20450 + int value;
20451 + int zeroes = 0;
20452 +
20453 + value = INTVAL(op);
20454 + for ( i = 0 ; i < 32; i++ ){
20455 + if ( !(value & ( 1 << i )) ){
20456 + zeroes++;
20457 + }
20458 + }
20459 +
20460 + return ( zeroes == 1 );
20461 + })
20462 +
20463 +
20464 +;; Immediate all the low 16-bits cleared
20465 +(define_predicate "avr32_hi16_immediate_operand"
20466 + (match_code "const_int")
20467 + {
20468 + /* If the low 16-bits are zero then this
20469 + is a hi16 immediate. */
20470 + return ((INTVAL(op) & 0xffff) == 0);
20471 + }
20472 +)
20473 +
20474 +;; True if this is a register or immediate operand
20475 +(define_predicate "register_immediate_operand"
20476 + (ior (match_operand 0 "register_operand")
20477 + (match_operand 0 "immediate_operand")))
20478 +
20479 +;; True if this is a register or const_int operand
20480 +(define_predicate "register_const_int_operand"
20481 + (ior (match_operand 0 "register_operand")
20482 + (and (match_operand 0 "const_int_operand")
20483 + (match_operand 0 "immediate_operand"))))
20484 +
20485 +;; True if this is a register or const_double operand
20486 +(define_predicate "register_const_double_operand"
20487 + (ior (match_operand 0 "register_operand")
20488 + (match_operand 0 "const_double_operand")))
20489 +
20490 +;; True is this is an operand containing a label_ref
20491 +(define_predicate "avr32_label_ref_operand"
20492 + (and (match_code "mem")
20493 + (match_test "avr32_find_symbol(op)
20494 + && (GET_CODE(avr32_find_symbol(op)) == LABEL_REF)")))
20495 +
20496 +;; True is this is a valid symbol pointing to the constant pool
20497 +(define_predicate "avr32_const_pool_operand"
20498 + (and (match_code "symbol_ref")
20499 + (match_test "CONSTANT_POOL_ADDRESS_P(op)"))
20500 + {
20501 + return (flag_pic ? (!(symbol_mentioned_p (get_pool_constant (op))
20502 + || label_mentioned_p (get_pool_constant (op)))
20503 + || avr32_got_mentioned_p(get_pool_constant (op)))
20504 + : true);
20505 + }
20506 +)
20507 +
20508 +;; True is this is a memory reference to the constant or mini pool
20509 +(define_predicate "avr32_const_pool_ref_operand"
20510 + (ior (match_operand 0 "avr32_label_ref_operand")
20511 + (and (match_code "mem")
20512 + (match_test "avr32_const_pool_operand(XEXP(op,0), GET_MODE(XEXP(op,0)))"))))
20513 +
20514 +
20515 +;; Legal source operand for movti insns
20516 +(define_predicate "avr32_movti_src_operand"
20517 + (ior (match_operand 0 "avr32_const_pool_ref_operand")
20518 + (ior (ior (match_operand 0 "register_immediate_operand")
20519 + (match_operand 0 "avr32_indirect_register_operand"))
20520 + (match_operand 0 "post_inc_memory_operand"))))
20521 +
20522 +;; Legal destination operand for movti insns
20523 +(define_predicate "avr32_movti_dst_operand"
20524 + (ior (ior (match_operand 0 "register_operand")
20525 + (match_operand 0 "avr32_indirect_register_operand"))
20526 + (match_operand 0 "pre_dec_memory_operand")))
20527 +
20528 +
20529 +;; True is this is a k12 offseted memory operand
20530 +(define_predicate "avr32_k12_memory_operand"
20531 + (and (match_code "mem")
20532 + (ior (match_test "REG_P(XEXP(op, 0))")
20533 + (match_test "GET_CODE(XEXP(op, 0)) == PLUS
20534 + && REG_P(XEXP(XEXP(op, 0), 0))
20535 + && (GET_CODE(XEXP(XEXP(op, 0), 1)) == CONST_INT)
20536 + && (CONST_OK_FOR_CONSTRAINT_P(INTVAL(XEXP(XEXP(op, 0), 0)),
20537 + 'K', (mode == SImode) ? \"Ks14\" : ((mode == HImode) ? \"Ks13\" : \"Ks12\")))"))))
20538 +
20539 +;; True is this is a memory operand with an immediate displacement
20540 +(define_predicate "avr32_imm_disp_memory_operand"
20541 + (and (match_code "mem")
20542 + (match_test "GET_CODE(XEXP(op, 0)) == PLUS
20543 + && REG_P(XEXP(XEXP(op, 0), 0))
20544 + && (GET_CODE(XEXP(XEXP(op, 0), 1)) == CONST_INT)")))
20545 +
20546 +;; True is this is a bswap operand
20547 +(define_predicate "avr32_bswap_operand"
20548 + (ior (match_operand 0 "avr32_k12_memory_operand")
20549 + (match_operand 0 "register_operand")))
20550 +
20551 +;; True is this is a valid coprocessor insn memory operand
20552 +(define_predicate "avr32_cop_memory_operand"
20553 + (and (match_operand 0 "memory_operand")
20554 + (not (match_test "GET_CODE(XEXP(op, 0)) == PLUS
20555 + && REG_P(XEXP(XEXP(op, 0), 0))
20556 + && (GET_CODE(XEXP(XEXP(op, 0), 1)) == CONST_INT)
20557 + && !(CONST_OK_FOR_CONSTRAINT_P(INTVAL(XEXP(XEXP(op, 0), 0)), 'K', \"Ku10\"))"))))
20558 +
20559 +;; True is this is a valid source/destination operand
20560 +;; for moving values to/from a coprocessor
20561 +(define_predicate "avr32_cop_move_operand"
20562 + (ior (match_operand 0 "register_operand")
20563 + (match_operand 0 "avr32_cop_memory_operand")))
20564 +
20565 +
20566 +;; True is this is a valid extract byte offset for use in
20567 +;; load extracted index insns
20568 +(define_predicate "avr32_extract_shift_operand"
20569 + (and (match_operand 0 "const_int_operand")
20570 + (match_test "(INTVAL(op) == 0) || (INTVAL(op) == 8)
20571 + || (INTVAL(op) == 16) || (INTVAL(op) == 24)")))
20572 +
20573 +;; True is this is a floating-point register
20574 +(define_predicate "avr32_fp_register_operand"
20575 + (and (match_operand 0 "register_operand")
20576 + (match_test "REGNO_REG_CLASS(REGNO(op)) == FP_REGS")))
20577 +
20578 +;; True is this is valid avr32 symbol operand
20579 +(define_predicate "avr32_symbol_operand"
20580 + (ior (match_code "label_ref, symbol_ref")
20581 + (and (match_code "const")
20582 + (match_test "avr32_find_symbol(op)"))))
20583 +
20584 +;; True is this is valid operand for the lda.w and call pseudo insns
20585 +(define_predicate "avr32_address_operand"
20586 + (and (match_code "label_ref, symbol_ref")
20587 + (ior (match_test "TARGET_HAS_ASM_ADDR_PSEUDOS")
20588 + (match_test "flag_pic")) ))
20589 +
20590 +;; An immediate k16 address operand
20591 +(define_predicate "avr32_ks16_address_operand"
20592 + (and (match_operand 0 "address_operand")
20593 + (ior (match_test "REG_P(op)")
20594 + (match_test "GET_CODE(op) == PLUS
20595 + && ((GET_CODE(XEXP(op,0)) == CONST_INT)
20596 + || (GET_CODE(XEXP(op,1)) == CONST_INT))")) ))
20597 +
20598 +;; An offset k16 memory operand
20599 +(define_predicate "avr32_ks16_memory_operand"
20600 + (and (match_code "mem")
20601 + (match_test "avr32_ks16_address_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)))")))
20602 +
20603 +;; An immediate k11 address operand
20604 +(define_predicate "avr32_ks11_address_operand"
20605 + (and (match_operand 0 "address_operand")
20606 + (ior (match_test "REG_P(op)")
20607 + (match_test "GET_CODE(op) == PLUS
20608 + && (((GET_CODE(XEXP(op,0)) == CONST_INT)
20609 + && avr32_const_ok_for_constraint_p(INTVAL(XEXP(op,0)), 'K', \"Ks11\"))
20610 + || ((GET_CODE(XEXP(op,1)) == CONST_INT)
20611 + && avr32_const_ok_for_constraint_p(INTVAL(XEXP(op,1)), 'K', \"Ks11\")))")) ))
20612 +
20613 +;; True if this is a avr32 call operand
20614 +(define_predicate "avr32_call_operand"
20615 + (ior (ior (match_operand 0 "register_operand")
20616 + (ior (match_operand 0 "avr32_const_pool_ref_operand")
20617 + (match_operand 0 "avr32_address_operand")))
20618 + (match_test "SYMBOL_REF_RCALL_FUNCTION_P(op)")))
20619 +
20620 +;; Return true for operators performing ALU operations
20621 +
20622 +(define_predicate "alu_operator"
20623 + (match_code "ior, xor, and, plus, minus, ashift, lshiftrt, ashiftrt"))
20624 +
20625 +(define_predicate "avr32_add_shift_immediate_operand"
20626 + (and (match_operand 0 "immediate_operand")
20627 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'K', \"Ku02\")")))
20628 +
20629 +(define_predicate "avr32_cond_register_immediate_operand"
20630 + (ior (match_operand 0 "register_operand")
20631 + (and (match_operand 0 "immediate_operand")
20632 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'K', \"Ks08\")"))))
20633 +
20634 +(define_predicate "avr32_cond_immediate_operand"
20635 + (and (match_operand 0 "immediate_operand")
20636 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'I', \"Is08\")")))
20637 +
20638 +
20639 +(define_predicate "avr32_cond_move_operand"
20640 + (ior (ior (match_operand 0 "register_operand")
20641 + (and (match_operand 0 "immediate_operand")
20642 + (match_test "CONST_OK_FOR_CONSTRAINT_P(INTVAL(op), 'K', \"Ks08\")")))
20643 + (and (match_test "TARGET_V2_INSNS")
20644 + (match_operand 0 "memory_operand"))))
20645 +
20646 +(define_predicate "avr32_mov_immediate_operand"
20647 + (and (match_operand 0 "immediate_operand")
20648 + (match_test "avr32_const_ok_for_move(INTVAL(op))")))
20649 --- /dev/null
20650 +++ b/gcc/config/avr32/simd.md
20651 @@ -0,0 +1,145 @@
20652 +;; AVR32 machine description file for SIMD instructions.
20653 +;; Copyright 2003-2006 Atmel Corporation.
20654 +;;
20655 +;; Written by Ronny Pedersen, Atmel Norway, <rpedersen@atmel.com>
20656 +;;
20657 +;; This file is part of GCC.
20658 +;;
20659 +;; This program is free software; you can redistribute it and/or modify
20660 +;; it under the terms of the GNU General Public License as published by
20661 +;; the Free Software Foundation; either version 2 of the License, or
20662 +;; (at your option) any later version.
20663 +;;
20664 +;; This program is distributed in the hope that it will be useful,
20665 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20666 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20667 +;; GNU General Public License for more details.
20668 +;;
20669 +;; You should have received a copy of the GNU General Public License
20670 +;; along with this program; if not, write to the Free Software
20671 +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20672 +
20673 +;; -*- Mode: Scheme -*-
20674 +
20675 +
20676 +;; Vector modes
20677 +(define_mode_iterator VECM [V2HI V4QI])
20678 +(define_mode_attr size [(V2HI "h") (V4QI "b")])
20679 +
20680 +(define_insn "add<mode>3"
20681 + [(set (match_operand:VECM 0 "register_operand" "=r")
20682 + (plus:VECM (match_operand:VECM 1 "register_operand" "r")
20683 + (match_operand:VECM 2 "register_operand" "r")))]
20684 + "TARGET_SIMD"
20685 + "padd.<size>\t%0, %1, %2"
20686 + [(set_attr "length" "4")
20687 + (set_attr "type" "alu")])
20688 +
20689 +
20690 +(define_insn "sub<mode>3"
20691 + [(set (match_operand:VECM 0 "register_operand" "=r")
20692 + (minus:VECM (match_operand:VECM 1 "register_operand" "r")
20693 + (match_operand:VECM 2 "register_operand" "r")))]
20694 + "TARGET_SIMD"
20695 + "psub.<size>\t%0, %1, %2"
20696 + [(set_attr "length" "4")
20697 + (set_attr "type" "alu")])
20698 +
20699 +
20700 +(define_insn "abs<mode>2"
20701 + [(set (match_operand:VECM 0 "register_operand" "=r")
20702 + (abs:VECM (match_operand:VECM 1 "register_operand" "r")))]
20703 + "TARGET_SIMD"
20704 + "pabs.s<size>\t%0, %1"
20705 + [(set_attr "length" "4")
20706 + (set_attr "type" "alu")])
20707 +
20708 +(define_insn "ashl<mode>3"
20709 + [(set (match_operand:VECM 0 "register_operand" "=r")
20710 + (ashift:VECM (match_operand:VECM 1 "register_operand" "r")
20711 + (match_operand:SI 2 "immediate_operand" "Ku04")))]
20712 + "TARGET_SIMD"
20713 + "plsl.<size>\t%0, %1, %2"
20714 + [(set_attr "length" "4")
20715 + (set_attr "type" "alu")])
20716 +
20717 +(define_insn "ashr<mode>3"
20718 + [(set (match_operand:VECM 0 "register_operand" "=r")
20719 + (ashiftrt:VECM (match_operand:VECM 1 "register_operand" "r")
20720 + (match_operand:SI 2 "immediate_operand" "Ku04")))]
20721 + "TARGET_SIMD"
20722 + "pasr.<size>\t%0, %1, %2"
20723 + [(set_attr "length" "4")
20724 + (set_attr "type" "alu")])
20725 +
20726 +(define_insn "lshr<mode>3"
20727 + [(set (match_operand:VECM 0 "register_operand" "=r")
20728 + (lshiftrt:VECM (match_operand:VECM 1 "register_operand" "r")
20729 + (match_operand:SI 2 "immediate_operand" "Ku04")))]
20730 + "TARGET_SIMD"
20731 + "plsr.<size>\t%0, %1, %2"
20732 + [(set_attr "length" "4")
20733 + (set_attr "type" "alu")])
20734 +
20735 +(define_insn "smaxv2hi3"
20736 + [(set (match_operand:V2HI 0 "register_operand" "=r")
20737 + (smax:V2HI (match_operand:V2HI 1 "register_operand" "r")
20738 + (match_operand:V2HI 2 "register_operand" "r")))]
20739 +
20740 + "TARGET_SIMD"
20741 + "pmax.sh\t%0, %1, %2"
20742 + [(set_attr "length" "4")
20743 + (set_attr "type" "alu")])
20744 +
20745 +(define_insn "sminv2hi3"
20746 + [(set (match_operand:V2HI 0 "register_operand" "=r")
20747 + (smin:V2HI (match_operand:V2HI 1 "register_operand" "r")
20748 + (match_operand:V2HI 2 "register_operand" "r")))]
20749 +
20750 + "TARGET_SIMD"
20751 + "pmin.sh\t%0, %1, %2"
20752 + [(set_attr "length" "4")
20753 + (set_attr "type" "alu")])
20754 +
20755 +(define_insn "umaxv4qi3"
20756 + [(set (match_operand:V4QI 0 "register_operand" "=r")
20757 + (umax:V4QI (match_operand:V4QI 1 "register_operand" "r")
20758 + (match_operand:V4QI 2 "register_operand" "r")))]
20759 +
20760 + "TARGET_SIMD"
20761 + "pmax.ub\t%0, %1, %2"
20762 + [(set_attr "length" "4")
20763 + (set_attr "type" "alu")])
20764 +
20765 +(define_insn "uminv4qi3"
20766 + [(set (match_operand:V4QI 0 "register_operand" "=r")
20767 + (umin:V4QI (match_operand:V4QI 1 "register_operand" "r")
20768 + (match_operand:V4QI 2 "register_operand" "r")))]
20769 +
20770 + "TARGET_SIMD"
20771 + "pmin.ub\t%0, %1, %2"
20772 + [(set_attr "length" "4")
20773 + (set_attr "type" "alu")])
20774 +
20775 +
20776 +(define_insn "addsubv2hi"
20777 + [(set (match_operand:V2HI 0 "register_operand" "=r")
20778 + (vec_concat:V2HI
20779 + (plus:HI (match_operand:HI 1 "register_operand" "r")
20780 + (match_operand:HI 2 "register_operand" "r"))
20781 + (minus:HI (match_dup 1) (match_dup 2))))]
20782 + "TARGET_SIMD"
20783 + "paddsub.h\t%0, %1:b, %2:b"
20784 + [(set_attr "length" "4")
20785 + (set_attr "type" "alu")])
20786 +
20787 +(define_insn "subaddv2hi"
20788 + [(set (match_operand:V2HI 0 "register_operand" "=r")
20789 + (vec_concat:V2HI
20790 + (minus:HI (match_operand:HI 1 "register_operand" "r")
20791 + (match_operand:HI 2 "register_operand" "r"))
20792 + (plus:HI (match_dup 1) (match_dup 2))))]
20793 + "TARGET_SIMD"
20794 + "psubadd.h\t%0, %1:b, %2:b"
20795 + [(set_attr "length" "4")
20796 + (set_attr "type" "alu")])
20797 --- /dev/null
20798 +++ b/gcc/config/avr32/sync.md
20799 @@ -0,0 +1,244 @@
20800 +;;=================================================================
20801 +;; Atomic operations
20802 +;;=================================================================
20803 +
20804 +
20805 +(define_insn "sync_compare_and_swapsi"
20806 + [(set (match_operand:SI 0 "register_operand" "=&r,&r")
20807 + (match_operand:SI 1 "memory_operand" "+RKs16,+RKs16"))
20808 + (set (match_dup 1)
20809 + (unspec_volatile:SI
20810 + [(match_dup 1)
20811 + (match_operand:SI 2 "register_immediate_operand" "r,Ks21")
20812 + (match_operand:SI 3 "register_operand" "r,r")]
20813 + VUNSPEC_SYNC_CMPXCHG)) ]
20814 + ""
20815 + "0:
20816 + ssrf\t5
20817 + ld.w\t%0,%1
20818 + cp.w\t%0,%2
20819 + brne\t0f
20820 + stcond\t%1, %3
20821 + brne\t0b
20822 + 0:
20823 + "
20824 + [(set_attr "length" "16,18")
20825 + (set_attr "cc" "clobber")]
20826 + )
20827 +
20828 +
20829 +(define_code_iterator atomic_op [plus minus and ior xor])
20830 +(define_code_attr atomic_asm_insn [(plus "add") (minus "sub") (and "and") (ior "or") (xor "eor")])
20831 +(define_code_attr atomic_insn [(plus "add") (minus "sub") (and "and") (ior "ior") (xor "xor")])
20832 +
20833 +(define_insn "sync_loadsi"
20834 + ; NB! Put an early clobber on the destination operand to
20835 + ; avoid gcc using the same register in the source and
20836 + ; destination. This is done in order to avoid gcc to
20837 + ; clobber the source operand since these instructions
20838 + ; are actually inside a "loop".
20839 + [(set (match_operand:SI 0 "register_operand" "=&r")
20840 + (unspec_volatile:SI
20841 + [(match_operand:SI 1 "avr32_ks16_memory_operand" "RKs16")
20842 + (label_ref (match_operand 2 "" ""))]
20843 + VUNSPEC_SYNC_SET_LOCK_AND_LOAD) )]
20844 + ""
20845 + "%2:
20846 + ssrf\t5
20847 + ld.w\t%0,%1"
20848 + [(set_attr "length" "6")
20849 + (set_attr "cc" "clobber")]
20850 + )
20851 +
20852 +(define_insn "sync_store_if_lock"
20853 + [(set (match_operand:SI 0 "avr32_ks16_memory_operand" "=RKs16")
20854 + (unspec_volatile:SI
20855 + [(match_operand:SI 1 "register_operand" "r")
20856 + (label_ref (match_operand 2 "" ""))]
20857 + VUNSPEC_SYNC_STORE_IF_LOCK) )]
20858 + ""
20859 + "stcond\t%0, %1
20860 + brne\t%2"
20861 + [(set_attr "length" "6")
20862 + (set_attr "cc" "clobber")]
20863 + )
20864 +
20865 +
20866 +(define_expand "sync_<atomic_insn>si"
20867 + [(set (match_dup 2)
20868 + (unspec_volatile:SI
20869 + [(match_operand:SI 0 "avr32_ks16_memory_operand" "")
20870 + (match_dup 3)]
20871 + VUNSPEC_SYNC_SET_LOCK_AND_LOAD))
20872 + (set (match_dup 2)
20873 + (atomic_op:SI (match_dup 2)
20874 + (match_operand:SI 1 "register_immediate_operand" "")))
20875 + (set (match_dup 0)
20876 + (unspec_volatile:SI
20877 + [(match_dup 2)
20878 + (match_dup 3)]
20879 + VUNSPEC_SYNC_STORE_IF_LOCK) )
20880 + (use (match_dup 1))
20881 + (use (match_dup 4))]
20882 + ""
20883 + {
20884 + rtx *mem_expr = &operands[0];
20885 + rtx ptr_reg;
20886 + if ( !avr32_ks16_memory_operand (*mem_expr, GET_MODE (*mem_expr)) )
20887 + {
20888 + ptr_reg = force_reg (Pmode, XEXP (*mem_expr, 0));
20889 + XEXP (*mem_expr, 0) = ptr_reg;
20890 + }
20891 + else
20892 + {
20893 + rtx address = XEXP (*mem_expr, 0);
20894 + if ( REG_P (address) )
20895 + ptr_reg = address;
20896 + else if ( REG_P (XEXP (address, 0)) )
20897 + ptr_reg = XEXP (address, 0);
20898 + else
20899 + ptr_reg = XEXP (address, 1);
20900 + }
20901 +
20902 + operands[2] = gen_reg_rtx (SImode);
20903 + operands[3] = gen_rtx_LABEL_REF(Pmode, gen_label_rtx ());
20904 + operands[4] = ptr_reg;
20905 +
20906 + }
20907 + )
20908 +
20909 +
20910 +
20911 +(define_expand "sync_old_<atomic_insn>si"
20912 + [(set (match_operand:SI 0 "register_operand" "")
20913 + (unspec_volatile:SI
20914 + [(match_operand:SI 1 "avr32_ks16_memory_operand" "")
20915 + (match_dup 4)]
20916 + VUNSPEC_SYNC_SET_LOCK_AND_LOAD))
20917 + (set (match_dup 3)
20918 + (atomic_op:SI (match_dup 0)
20919 + (match_operand:SI 2 "register_immediate_operand" "")))
20920 + (set (match_dup 1)
20921 + (unspec_volatile:SI
20922 + [(match_dup 3)
20923 + (match_dup 4)]
20924 + VUNSPEC_SYNC_STORE_IF_LOCK) )
20925 + (use (match_dup 2))
20926 + (use (match_dup 5))]
20927 + ""
20928 + {
20929 + rtx *mem_expr = &operands[1];
20930 + rtx ptr_reg;
20931 + if ( !avr32_ks16_memory_operand (*mem_expr, GET_MODE (*mem_expr)) )
20932 + {
20933 + ptr_reg = force_reg (Pmode, XEXP (*mem_expr, 0));
20934 + XEXP (*mem_expr, 0) = ptr_reg;
20935 + }
20936 + else
20937 + {
20938 + rtx address = XEXP (*mem_expr, 0);
20939 + if ( REG_P (address) )
20940 + ptr_reg = address;
20941 + else if ( REG_P (XEXP (address, 0)) )
20942 + ptr_reg = XEXP (address, 0);
20943 + else
20944 + ptr_reg = XEXP (address, 1);
20945 + }
20946 +
20947 + operands[3] = gen_reg_rtx (SImode);
20948 + operands[4] = gen_rtx_LABEL_REF(Pmode, gen_label_rtx ());
20949 + operands[5] = ptr_reg;
20950 + }
20951 + )
20952 +
20953 +(define_expand "sync_new_<atomic_insn>si"
20954 + [(set (match_operand:SI 0 "register_operand" "")
20955 + (unspec_volatile:SI
20956 + [(match_operand:SI 1 "avr32_ks16_memory_operand" "")
20957 + (match_dup 3)]
20958 + VUNSPEC_SYNC_SET_LOCK_AND_LOAD))
20959 + (set (match_dup 0)
20960 + (atomic_op:SI (match_dup 0)
20961 + (match_operand:SI 2 "register_immediate_operand" "")))
20962 + (set (match_dup 1)
20963 + (unspec_volatile:SI
20964 + [(match_dup 0)
20965 + (match_dup 3)]
20966 + VUNSPEC_SYNC_STORE_IF_LOCK) )
20967 + (use (match_dup 2))
20968 + (use (match_dup 4))]
20969 + ""
20970 + {
20971 + rtx *mem_expr = &operands[1];
20972 + rtx ptr_reg;
20973 + if ( !avr32_ks16_memory_operand (*mem_expr, GET_MODE (*mem_expr)) )
20974 + {
20975 + ptr_reg = force_reg (Pmode, XEXP (*mem_expr, 0));
20976 + XEXP (*mem_expr, 0) = ptr_reg;
20977 + }
20978 + else
20979 + {
20980 + rtx address = XEXP (*mem_expr, 0);
20981 + if ( REG_P (address) )
20982 + ptr_reg = address;
20983 + else if ( REG_P (XEXP (address, 0)) )
20984 + ptr_reg = XEXP (address, 0);
20985 + else
20986 + ptr_reg = XEXP (address, 1);
20987 + }
20988 +
20989 + operands[3] = gen_rtx_LABEL_REF(Pmode, gen_label_rtx ());
20990 + operands[4] = ptr_reg;
20991 + }
20992 + )
20993 +
20994 +
20995 +;(define_insn "sync_<atomic_insn>si"
20996 +; [(set (match_operand:SI 0 "memory_operand" "+RKs16")
20997 +; (unspec_volatile:SI
20998 +; [(atomic_op:SI (match_dup 0)
20999 +; (match_operand:SI 1 "register_operand" "r"))]
21000 +; VUNSPEC_SYNC_CMPXCHG))
21001 +; (clobber (match_scratch:SI 2 "=&r"))]
21002 +; ""
21003 +; "0:
21004 +; ssrf\t5
21005 +; ld.w\t%2,%0
21006 +; <atomic_asm_insn>\t%2,%1
21007 +; stcond\t%0, %2
21008 +; brne\t0b
21009 +; "
21010 +; [(set_attr "length" "14")
21011 +; (set_attr "cc" "clobber")]
21012 +; )
21013 +;
21014 +;(define_insn "sync_new_<atomic_insn>si"
21015 +; [(set (match_operand:SI 1 "memory_operand" "+RKs16")
21016 +; (unspec_volatile:SI
21017 +; [(atomic_op:SI (match_dup 1)
21018 +; (match_operand:SI 2 "register_operand" "r"))]
21019 +; VUNSPEC_SYNC_CMPXCHG))
21020 +; (set (match_operand:SI 0 "register_operand" "=&r")
21021 +; (atomic_op:SI (match_dup 1)
21022 +; (match_dup 2)))]
21023 +; ""
21024 +; "0:
21025 +; ssrf\t5
21026 +; ld.w\t%0,%1
21027 +; <atomic_asm_insn>\t%0,%2
21028 +; stcond\t%1, %0
21029 +; brne\t0b
21030 +; "
21031 +; [(set_attr "length" "14")
21032 +; (set_attr "cc" "clobber")]
21033 +; )
21034 +
21035 +(define_insn "sync_lock_test_and_setsi"
21036 + [ (set (match_operand:SI 0 "register_operand" "=&r")
21037 + (match_operand:SI 1 "memory_operand" "+RKu00"))
21038 + (set (match_dup 1)
21039 + (match_operand:SI 2 "register_operand" "r")) ]
21040 + ""
21041 + "xchg\t%0, %p1, %2"
21042 + [(set_attr "length" "4")]
21043 + )
21044 --- /dev/null
21045 +++ b/gcc/config/avr32/t-avr32
21046 @@ -0,0 +1,94 @@
21047 +
21048 +MD_INCLUDES= $(srcdir)/config/avr32/avr32.md \
21049 + $(srcdir)/config/avr32/sync.md \
21050 + $(srcdir)/config/avr32/fpcp.md \
21051 + $(srcdir)/config/avr32/simd.md \
21052 + $(srcdir)/config/avr32/predicates.md
21053 +
21054 +s-config s-conditions s-flags s-codes s-constants s-emit s-recog s-preds \
21055 + s-opinit s-extract s-peep s-attr s-attrtab s-output: $(MD_INCLUDES)
21056 +
21057 +# We want fine grained libraries, so use the new code
21058 +# to build the floating point emulation libraries.
21059 +FPBIT = fp-bit.c
21060 +DPBIT = dp-bit.c
21061 +
21062 +LIB1ASMSRC = avr32/lib1funcs.S
21063 +LIB1ASMFUNCS = _avr32_f64_mul _avr32_f64_mul_fast _avr32_f64_addsub _avr32_f64_addsub_fast _avr32_f64_to_u32 \
21064 + _avr32_f64_to_s32 _avr32_f64_to_u64 _avr32_f64_to_s64 _avr32_u32_to_f64 \
21065 + _avr32_s32_to_f64 _avr32_f64_cmp_eq _avr32_f64_cmp_ge _avr32_f64_cmp_lt \
21066 + _avr32_f32_cmp_eq _avr32_f32_cmp_ge _avr32_f32_cmp_lt _avr32_f64_div _avr32_f64_div_fast \
21067 + _avr32_f32_div _avr32_f32_div_fast _avr32_f32_addsub _avr32_f32_addsub_fast \
21068 + _avr32_f32_mul _avr32_s32_to_f32 _avr32_u32_to_f32 _avr32_f32_to_s32 \
21069 + _avr32_f32_to_u32 _avr32_f32_to_f64 _avr32_f64_to_f32 _mulsi3
21070 +
21071 +#LIB2FUNCS_EXTRA += $(srcdir)/config/avr32/lib2funcs.S
21072 +
21073 +MULTILIB_OPTIONS = march=ap/march=ucr1/march=ucr2/march=ucr2nomul/march=ucr3
21074 +MULTILIB_DIRNAMES = ap ucr1 ucr2 ucr2nomul ucr3
21075 +MULTILIB_EXCEPTIONS =
21076 +MULTILIB_MATCHES += march?ap=mpart?ap7000
21077 +MULTILIB_MATCHES += march?ap=mpart?ap7001
21078 +MULTILIB_MATCHES += march?ap=mpart?ap7002
21079 +MULTILIB_MATCHES += march?ap=mpart?ap7200
21080 +MULTILIB_MATCHES += march?ucr1=march?uc
21081 +MULTILIB_MATCHES += march?ucr1=mpart?uc3a0512es
21082 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0128
21083 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0256
21084 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0512
21085 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1128
21086 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1256
21087 +MULTILIB_MATCHES += march?ucr1=mpart?uc3a1512es
21088 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1512
21089 +MULTILIB_MATCHES += march?ucr2nomul=mpart?uc3a3revd
21090 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a364
21091 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a364s
21092 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3128
21093 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3128s
21094 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3256
21095 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3256s
21096 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b064
21097 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0128
21098 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0256es
21099 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0256
21100 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b0512revc
21101 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b164
21102 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1128
21103 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1256es
21104 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1256
21105 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b1512revc
21106 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c0512c
21107 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c0256c
21108 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c0128c
21109 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c064c
21110 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c1512c
21111 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c1256c
21112 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c1128c
21113 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c164c
21114 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c2512c
21115 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c2256c
21116 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c2128c
21117 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c264c
21118 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l064
21119 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l032
21120 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l016
21121 +
21122 +
21123 +EXTRA_MULTILIB_PARTS = crtbegin.o crtbeginS.o crtend.o crtendS.o crti.o crtn.o
21124 +
21125 +CRTSTUFF_T_CFLAGS = -mrelax
21126 +CRTSTUFF_T_CFLAGS_S = -mrelax -fPIC
21127 +TARGET_LIBGCC2_CFLAGS += -mrelax
21128 +
21129 +LIBGCC = stmp-multilib
21130 +INSTALL_LIBGCC = install-multilib
21131 +
21132 +fp-bit.c: $(srcdir)/config/fp-bit.c
21133 + echo '#define FLOAT' > fp-bit.c
21134 + cat $(srcdir)/config/fp-bit.c >> fp-bit.c
21135 +
21136 +dp-bit.c: $(srcdir)/config/fp-bit.c
21137 + cat $(srcdir)/config/fp-bit.c > dp-bit.c
21138 +
21139 +
21140 +
21141 --- /dev/null
21142 +++ b/gcc/config/avr32/t-avr32-linux
21143 @@ -0,0 +1,94 @@
21144 +
21145 +MD_INCLUDES= $(srcdir)/config/avr32/avr32.md \
21146 + $(srcdir)/config/avr32/sync.md \
21147 + $(srcdir)/config/avr32/fpcp.md \
21148 + $(srcdir)/config/avr32/simd.md \
21149 + $(srcdir)/config/avr32/predicates.md
21150 +
21151 +s-config s-conditions s-flags s-codes s-constants s-emit s-recog s-preds \
21152 + s-opinit s-extract s-peep s-attr s-attrtab s-output: $(MD_INCLUDES)
21153 +
21154 +# We want fine grained libraries, so use the new code
21155 +# to build the floating point emulation libraries.
21156 +FPBIT = fp-bit.c
21157 +DPBIT = dp-bit.c
21158 +
21159 +LIB1ASMSRC = avr32/lib1funcs.S
21160 +LIB1ASMFUNCS = _avr32_f64_mul _avr32_f64_mul_fast _avr32_f64_addsub _avr32_f64_addsub_fast _avr32_f64_to_u32 \
21161 + _avr32_f64_to_s32 _avr32_f64_to_u64 _avr32_f64_to_s64 _avr32_u32_to_f64 \
21162 + _avr32_s32_to_f64 _avr32_f64_cmp_eq _avr32_f64_cmp_ge _avr32_f64_cmp_lt \
21163 + _avr32_f32_cmp_eq _avr32_f32_cmp_ge _avr32_f32_cmp_lt _avr32_f64_div _avr32_f64_div_fast \
21164 + _avr32_f32_div _avr32_f32_div_fast _avr32_f32_addsub _avr32_f32_addsub_fast \
21165 + _avr32_f32_mul _avr32_s32_to_f32 _avr32_u32_to_f32 _avr32_f32_to_s32 \
21166 + _avr32_f32_to_u32 _avr32_f32_to_f64 _avr32_f64_to_f32 _mulsi3
21167 +
21168 +#LIB2FUNCS_EXTRA += $(srcdir)/config/avr32/lib2funcs.S
21169 +
21170 +MULTILIB_OPTIONS = march=ap/march=ucr1/march=ucr2/march=ucr2nomul/march=ucr3
21171 +MULTILIB_DIRNAMES = ap ucr1 ucr2 ucr2nomul ucr3
21172 +MULTILIB_EXCEPTIONS =
21173 +MULTILIB_MATCHES += march?ap=mpart?ap7000
21174 +MULTILIB_MATCHES += march?ap=mpart?ap7001
21175 +MULTILIB_MATCHES += march?ap=mpart?ap7002
21176 +MULTILIB_MATCHES += march?ap=mpart?ap7200
21177 +MULTILIB_MATCHES += march?ucr1=march?uc
21178 +MULTILIB_MATCHES += march?ucr1=mpart?uc3a0512es
21179 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0128
21180 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0256
21181 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a0512
21182 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1128
21183 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1256
21184 +MULTILIB_MATCHES += march?ucr1=mpart?uc3a1512es
21185 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a1512
21186 +MULTILIB_MATCHES += march?ucr2nomul=mpart?uc3a3revd
21187 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a364
21188 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a364s
21189 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3128
21190 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3128s
21191 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3256
21192 +MULTILIB_MATCHES += march?ucr2=mpart?uc3a3256s
21193 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b064
21194 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0128
21195 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0256es
21196 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b0256
21197 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b0512revc
21198 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b164
21199 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1128
21200 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1256es
21201 +MULTILIB_MATCHES += march?ucr1=mpart?uc3b1256
21202 +MULTILIB_MATCHES += march?ucr2=mpart?uc3b1512revc
21203 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c0512c
21204 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c0256c
21205 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c0128c
21206 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c064c
21207 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c1512c
21208 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c1256c
21209 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c1128c
21210 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c164c
21211 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c2512c
21212 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c2256c
21213 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c2128c
21214 +MULTILIB_MATCHES += march?ucr3=mpart?uc3c264c
21215 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l064
21216 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l032
21217 +MULTILIB_MATCHES += march?ucr3=mpart?uc3l016
21218 +
21219 +
21220 +EXTRA_MULTILIB_PARTS = crtbegin.o crtbeginS.o crtend.o crtendS.o
21221 +
21222 +CRTSTUFF_T_CFLAGS = -mrelax
21223 +CRTSTUFF_T_CFLAGS_S = -mrelax -fPIC
21224 +TARGET_LIBGCC2_CFLAGS += -mrelax
21225 +
21226 +LIBGCC = stmp-multilib
21227 +INSTALL_LIBGCC = install-multilib
21228 +
21229 +fp-bit.c: $(srcdir)/config/fp-bit.c
21230 + echo '#define FLOAT' > fp-bit.c
21231 + cat $(srcdir)/config/fp-bit.c >> fp-bit.c
21232 +
21233 +dp-bit.c: $(srcdir)/config/fp-bit.c
21234 + cat $(srcdir)/config/fp-bit.c > dp-bit.c
21235 +
21236 +
21237 +
21238 --- /dev/null
21239 +++ b/gcc/config/avr32/t-elf
21240 @@ -0,0 +1,16 @@
21241 +
21242 +# Assemble startup files.
21243 +$(T)crti.o: $(srcdir)/config/avr32/crti.asm $(GCC_PASSES)
21244 + $(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) $(INCLUDES) \
21245 + -c -o $(T)crti.o -x assembler-with-cpp $(srcdir)/config/avr32/crti.asm
21246 +
21247 +$(T)crtn.o: $(srcdir)/config/avr32/crtn.asm $(GCC_PASSES)
21248 + $(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) $(INCLUDES) \
21249 + -c -o $(T)crtn.o -x assembler-with-cpp $(srcdir)/config/avr32/crtn.asm
21250 +
21251 +
21252 +# Build the libraries for both hard and soft floating point
21253 +EXTRA_MULTILIB_PARTS = crtbegin.o crtbeginS.o crtend.o crtendS.o crti.o crtn.o
21254 +
21255 +LIBGCC = stmp-multilib
21256 +INSTALL_LIBGCC = install-multilib
21257 --- /dev/null
21258 +++ b/gcc/config/avr32/uclinux-elf.h
21259 @@ -0,0 +1,20 @@
21260 +
21261 +/* Run-time Target Specification. */
21262 +#undef TARGET_VERSION
21263 +#define TARGET_VERSION fputs (" (AVR32 uClinux with ELF)", stderr)
21264 +
21265 +/* We don't want a .jcr section on uClinux. As if this makes a difference... */
21266 +#define TARGET_USE_JCR_SECTION 0
21267 +
21268 +/* Here we go. Drop the crtbegin/crtend stuff completely. */
21269 +#undef STARTFILE_SPEC
21270 +#define STARTFILE_SPEC \
21271 + "%{!shared: %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s}" \
21272 + " %{!p:%{profile:gcrt1.o%s}" \
21273 + " %{!profile:crt1.o%s}}}} crti.o%s"
21274 +
21275 +#undef ENDFILE_SPEC
21276 +#define ENDFILE_SPEC "crtn.o%s"
21277 +
21278 +#undef TARGET_DEFAULT
21279 +#define TARGET_DEFAULT (AVR32_FLAG_NO_INIT_GOT)
21280 --- a/gcc/config/host-linux.c
21281 +++ b/gcc/config/host-linux.c
21282 @@ -25,6 +25,9 @@
21283 #include "hosthooks.h"
21284 #include "hosthooks-def.h"
21285
21286 +#ifndef SSIZE_MAX
21287 +#define SSIZE_MAX LONG_MAX
21288 +#endif
21289
21290 /* Linux has a feature called exec-shield-randomize that perturbs the
21291 address of non-fixed mapped segments by a (relatively) small amount.
21292 --- a/gcc/config.gcc
21293 +++ b/gcc/config.gcc
21294 @@ -834,6 +834,24 @@ avr-*-*)
21295 tm_file="avr/avr.h dbxelf.h"
21296 use_fixproto=yes
21297 ;;
21298 +avr32*-*-linux*)
21299 + tm_file="dbxelf.h elfos.h linux.h avr32/linux-elf.h avr32/avr32.h "
21300 + tmake_file="t-linux avr32/t-avr32 avr32/t-elf"
21301 + extra_parts="crtbegin.o crtbeginS.o crtend.o crtendS.o"
21302 + extra_modes=avr32/avr32-modes.def
21303 + gnu_ld=yes
21304 + ;;
21305 +avr32*-*-uclinux*)
21306 + tm_file="dbxelf.h elfos.h linux.h avr32/linux-elf.h avr32/uclinux-elf.h avr32/avr32.h"
21307 + tmake_file="t-linux avr32/t-avr32-linux"
21308 + extra_modes=avr32/avr32-modes.def
21309 + gnu_ld=yes
21310 + ;;
21311 +avr32-*-*)
21312 + tm_file="dbxelf.h elfos.h avr32/avr32.h avr32/avr32-elf.h"
21313 + tmake_file="avr32/t-avr32 avr32/t-elf"
21314 + extra_modes=avr32/avr32-modes.def
21315 + ;;
21316 bfin*-elf*)
21317 tm_file="${tm_file} dbxelf.h elfos.h bfin/elf.h"
21318 tmake_file=bfin/t-bfin-elf
21319 @@ -2950,6 +2968,32 @@ case "${target}" in
21320 fi
21321 ;;
21322
21323 + avr32*-*-*)
21324 + supported_defaults="part arch"
21325 +
21326 + case "$with_part" in
21327 + "" \
21328 + | "ap7000" | "ap7010" | "ap7020" | "uc3a0256" | "uc3a0512" | "uc3a1128" | "uc3a1256" | "uc3a1512" )
21329 + # OK
21330 + ;;
21331 + *)
21332 + echo "Unknown part used in --with-part=$with_part" 1>&2
21333 + exit 1
21334 + ;;
21335 + esac
21336 +
21337 + case "$with_arch" in
21338 + "" \
21339 + | "ap" | "uc")
21340 + # OK
21341 + ;;
21342 + *)
21343 + echo "Unknown arch used in --with-arch=$with_arch" 1>&2
21344 + exit 1
21345 + ;;
21346 + esac
21347 + ;;
21348 +
21349 fr*-*-*linux*)
21350 supported_defaults=cpu
21351 case "$with_cpu" in
21352 --- a/gcc/configure.ac
21353 +++ b/gcc/configure.ac
21354 @@ -2174,10 +2174,9 @@ L2:],
21355 as_ver=`$gcc_cv_as --version 2>/dev/null | sed 1q`
21356 if echo "$as_ver" | grep GNU > /dev/null; then
21357 changequote(,)dnl
21358 - as_vers=`echo $as_ver | sed -n \
21359 - -e 's,^.*[ ]\([0-9][0-9]*\.[0-9][0-9]*.*\)$,\1,p'`
21360 - as_major=`expr "$as_vers" : '\([0-9]*\)'`
21361 - as_minor=`expr "$as_vers" : '[0-9]*\.\([0-9]*\)'`
21362 + as_ver=`echo $as_ver | sed -e 's/GNU assembler\( (GNU Binutils)\)\? \([0-9.][0-9.]*\).*/\2/'`
21363 + as_major=`echo $as_ver | sed 's/\..*//'`
21364 + as_minor=`echo $as_ver | sed 's/[^.]*\.\([0-9]*\).*/\1/'`
21365 changequote([,])dnl
21366 if test $as_major -eq 2 && test $as_minor -lt 11
21367 then :
21368 @@ -3077,7 +3076,7 @@ esac
21369 case "$target" in
21370 i?86*-*-* | mips*-*-* | alpha*-*-* | powerpc*-*-* | sparc*-*-* | m68*-*-* \
21371 | x86_64*-*-* | hppa*-*-* | arm*-*-* | strongarm*-*-* | xscale*-*-* \
21372 - | xstormy16*-*-* | cris-*-* | xtensa-*-* | bfin-*-* | score*-*-* | spu-*-*)
21373 + | xstormy16*-*-* | cris-*-* | xtensa-*-* | bfin-*-* | score*-*-* | spu-*-* | avr32-*-*)
21374 insn="nop"
21375 ;;
21376 ia64*-*-* | s390*-*-*)
21377 --- a/gcc/doc/extend.texi
21378 +++ b/gcc/doc/extend.texi
21379 @@ -2336,7 +2336,7 @@ This attribute is ignored for R8C target
21380
21381 @item interrupt
21382 @cindex interrupt handler functions
21383 -Use this attribute on the ARM, AVR, CRX, M32C, M32R/D, m68k, MS1,
21384 +Use this attribute on the ARM, AVR, AVR32, CRX, M32C, M32R/D, m68k, MS1,
21385 and Xstormy16 ports to indicate that the specified function is an
21386 interrupt handler. The compiler will generate function entry and exit
21387 sequences suitable for use in an interrupt handler when this attribute
21388 @@ -2356,6 +2356,15 @@ void f () __attribute__ ((interrupt ("IR
21389
21390 Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF@.
21391
21392 +Note, for the AVR32, you can specify which banking scheme is used for
21393 +the interrupt mode this interrupt handler is used in like this:
21394 +
21395 +@smallexample
21396 +void f () __attribute__ ((interrupt ("FULL")));
21397 +@end smallexample
21398 +
21399 +Permissible values for this parameter are: FULL, HALF, NONE and UNDEF.
21400 +
21401 On ARMv7-M the interrupt type is ignored, and the attribute means the function
21402 may be called with a word aligned stack pointer.
21403
21404 @@ -3925,6 +3934,23 @@ placed in either the @code{.bss_below100
21405
21406 @end table
21407
21408 +@subsection AVR32 Variable Attributes
21409 +
21410 +One attribute is currently defined for AVR32 configurations:
21411 +@code{rmw_addressable}
21412 +
21413 +@table @code
21414 +@item rmw_addressable
21415 +@cindex @code{rmw_addressable} attribute
21416 +
21417 +This attribute can be used to signal that a variable can be accessed
21418 +with the addressing mode of the AVR32 Atomic Read-Modify-Write memory
21419 +instructions and hence make it possible for gcc to generate these
21420 +instructions without using built-in functions or inline assembly statements.
21421 +Variables used within the AVR32 Atomic Read-Modify-Write built-in
21422 +functions will automatically get the @code{rmw_addressable} attribute.
21423 +@end table
21424 +
21425 @subsection AVR Variable Attributes
21426
21427 @table @code
21428 @@ -6708,6 +6734,7 @@ instructions, but allow the compiler to
21429 * Alpha Built-in Functions::
21430 * ARM iWMMXt Built-in Functions::
21431 * ARM NEON Intrinsics::
21432 +* AVR32 Built-in Functions::
21433 * Blackfin Built-in Functions::
21434 * FR-V Built-in Functions::
21435 * X86 Built-in Functions::
21436 @@ -6955,6 +6982,74 @@ when the @option{-mfpu=neon} switch is u
21437
21438 @include arm-neon-intrinsics.texi
21439
21440 +@node AVR32 Built-in Functions
21441 +@subsection AVR32 Built-in Functions
21442 +
21443 +Built-in functions for atomic memory (RMW) instructions. Note that these
21444 +built-ins will fail for targets where the RMW instructions are not
21445 +implemented. Also note that these instructions only that a Ks15 << 2
21446 +memory address and will therefor not work with any runtime computed
21447 +memory addresses. The user is responsible for making sure that any
21448 +pointers used within these functions points to a valid memory address.
21449 +
21450 +@smallexample
21451 +void __builtin_mems(int */*ptr*/, int /*bit*/)
21452 +void __builtin_memc(int */*ptr*/, int /*bit*/)
21453 +void __builtin_memt(int */*ptr*/, int /*bit*/)
21454 +@end smallexample
21455 +
21456 +Built-in functions for DSP instructions. Note that these built-ins will
21457 +fail for targets where the DSP instructions are not implemented.
21458 +
21459 +@smallexample
21460 +int __builtin_sats (int /*Rd*/,int /*sa*/, int /*bn*/)
21461 +int __builtin_satu (int /*Rd*/,int /*sa*/, int /*bn*/)
21462 +int __builtin_satrnds (int /*Rd*/,int /*sa*/, int /*bn*/)
21463 +int __builtin_satrndu (int /*Rd*/,int /*sa*/, int /*bn*/)
21464 +short __builtin_mulsathh_h (short, short)
21465 +int __builtin_mulsathh_w (short, short)
21466 +short __builtin_mulsatrndhh_h (short, short)
21467 +int __builtin_mulsatrndwh_w (int, short)
21468 +int __builtin_mulsatwh_w (int, short)
21469 +int __builtin_macsathh_w (int, short, short)
21470 +short __builtin_satadd_h (short, short)
21471 +short __builtin_satsub_h (short, short)
21472 +int __builtin_satadd_w (int, int)
21473 +int __builtin_satsub_w (int, int)
21474 +long long __builtin_mulwh_d(int, short)
21475 +long long __builtin_mulnwh_d(int, short)
21476 +long long __builtin_macwh_d(long long, int, short)
21477 +long long __builtin_machh_d(long long, short, short)
21478 +@end smallexample
21479 +
21480 +Other built-in functions for instructions that cannot easily be
21481 +generated by the compiler.
21482 +
21483 +@smallexample
21484 +void __builtin_ssrf(int);
21485 +void __builtin_csrf(int);
21486 +void __builtin_musfr(int);
21487 +int __builtin_mustr(void);
21488 +int __builtin_mfsr(int /*Status Register Address*/)
21489 +void __builtin_mtsr(int /*Status Register Address*/, int /*Value*/)
21490 +int __builtin_mfdr(int /*Debug Register Address*/)
21491 +void __builtin_mtdr(int /*Debug Register Address*/, int /*Value*/)
21492 +void __builtin_cache(void * /*Address*/, int /*Cache Operation*/)
21493 +void __builtin_sync(int /*Sync Operation*/)
21494 +void __builtin_tlbr(void)
21495 +void __builtin_tlbs(void)
21496 +void __builtin_tlbw(void)
21497 +void __builtin_breakpoint(void)
21498 +int __builtin_xchg(void * /*Address*/, int /*Value*/ )
21499 +short __builtin_bswap_16(short)
21500 +int __builtin_bswap_32(int)
21501 +void __builtin_cop(int/*cpnr*/, int/*crd*/, int/*crx*/, int/*cry*/, int/*op*/)
21502 +int __builtin_mvcr_w(int/*cpnr*/, int/*crs*/)
21503 +void __builtin_mvrc_w(int/*cpnr*/, int/*crd*/, int/*value*/)
21504 +long long __builtin_mvcr_d(int/*cpnr*/, int/*crs*/)
21505 +void __builtin_mvrc_d(int/*cpnr*/, int/*crd*/, long long/*value*/)
21506 +@end smallexample
21507 +
21508 @node Blackfin Built-in Functions
21509 @subsection Blackfin Built-in Functions
21510
21511 --- a/gcc/doc/invoke.texi
21512 +++ b/gcc/doc/invoke.texi
21513 @@ -195,7 +195,7 @@ in the following sections.
21514 -fvisibility-ms-compat @gol
21515 -Wabi -Wctor-dtor-privacy @gol
21516 -Wnon-virtual-dtor -Wreorder @gol
21517 --Weffc++ -Wno-deprecated -Wstrict-null-sentinel @gol
21518 +-Weffc++ -Wno-deprecated @gol
21519 -Wno-non-template-friend -Wold-style-cast @gol
21520 -Woverloaded-virtual -Wno-pmf-conversions @gol
21521 -Wsign-promo}
21522 @@ -609,6 +609,12 @@ Objective-C and Objective-C++ Dialects}.
21523 -mauto-incdec -minmax -mlong-calls -mshort @gol
21524 -msoft-reg-count=@var{count}}
21525
21526 +@emph{AVR32 Options}
21527 +@gccoptlist{-muse-rodata-section -mhard-float -msoft-float -mrelax @gol
21528 +-mforce-double-align -mno-init-got -mrelax -mmd-reorg-opt -masm-addr-pseudos @gol
21529 +-mpart=@var{part} -mcpu=@var{cpu} -march=@var{arch} @gol
21530 +-mfast-float -mimm-in-const-pool}
21531 +
21532 @emph{MCore Options}
21533 @gccoptlist{-mhardlit -mno-hardlit -mdiv -mno-div -mrelax-immediates @gol
21534 -mno-relax-immediates -mwide-bitfields -mno-wide-bitfields @gol
21535 @@ -3163,13 +3169,11 @@ requiring @option{-O}.
21536 If you want to warn about code which uses the uninitialized value of the
21537 variable in its own initializer, use the @option{-Winit-self} option.
21538
21539 -These warnings occur for individual uninitialized or clobbered
21540 -elements of structure, union or array variables as well as for
21541 -variables which are uninitialized or clobbered as a whole. They do
21542 -not occur for variables or elements declared @code{volatile}. Because
21543 -these warnings depend on optimization, the exact variables or elements
21544 -for which there are warnings will depend on the precise optimization
21545 -options and version of GCC used.
21546 +These warnings occur only for variables that are candidates for
21547 +register allocation. Therefore, they do not occur for a variable that
21548 +is declared @code{volatile}, or whose address is taken, or whose size
21549 +is other than 1, 2, 4 or 8 bytes. Also, they do not occur for
21550 +structures, unions or arrays, even when they are in registers.
21551
21552 Note that there may be no warning about a variable that is used only
21553 to compute a value that itself is never used, because such
21554 @@ -7034,10 +7038,6 @@ If number of candidates in the set is sm
21555 we always try to remove unnecessary ivs from the set during its
21556 optimization when a new iv is added to the set.
21557
21558 -@item scev-max-expr-size
21559 -Bound on size of expressions used in the scalar evolutions analyzer.
21560 -Large expressions slow the analyzer.
21561 -
21562 @item omega-max-vars
21563 The maximum number of variables in an Omega constraint system.
21564 The default value is 128.
21565 @@ -8363,6 +8363,7 @@ platform.
21566 * ARC Options::
21567 * ARM Options::
21568 * AVR Options::
21569 +* AVR32 Options::
21570 * Blackfin Options::
21571 * CRIS Options::
21572 * CRX Options::
21573 @@ -8834,6 +8835,120 @@ comply to the C standards, but it will p
21574 size.
21575 @end table
21576
21577 +@node AVR32 Options
21578 +@subsection AVR32 Options
21579 +@cindex AVR32 Options
21580 +
21581 +These options are defined for AVR32 implementations:
21582 +
21583 +@table @gcctabopt
21584 +@item -muse-rodata-section
21585 +@opindex muse-rodata-section
21586 +Use section @samp{.rodata} for read-only data instead of @samp{.text}.
21587 +
21588 +@item -mhard-float
21589 +@opindex mhard-float
21590 +Use floating point coprocessor instructions.
21591 +
21592 +@item -msoft-float
21593 +@opindex msoft-float
21594 +Use software floating-point library for floating-point operations.
21595 +
21596 +@item -mforce-double-align
21597 +@opindex mforce-double-align
21598 +Force double-word alignment for double-word memory accesses.
21599 +
21600 +@item -masm-addr-pseudos
21601 +@opindex masm-addr-pseudos
21602 +Use assembler pseudo-instructions lda.w and call for handling direct
21603 +addresses. (Enabled by default)
21604 +
21605 +@item -mno-init-got
21606 +@opindex mno-init-got
21607 +Do not initialize the GOT register before using it when compiling PIC
21608 +code.
21609 +
21610 +@item -mrelax
21611 +@opindex mrelax
21612 +Let invoked assembler and linker do relaxing
21613 +(Enabled by default when optimization level is >1).
21614 +This means that when the address of symbols are known at link time,
21615 +the linker can optimize @samp{icall} and @samp{mcall}
21616 +instructions into a @samp{rcall} instruction if possible.
21617 +Loading the address of a symbol can also be optimized.
21618 +
21619 +@item -mmd-reorg-opt
21620 +@opindex mmd-reorg-opt
21621 +Perform machine dependent optimizations in reorg stage.
21622 +
21623 +@item -mpart=@var{part}
21624 +@opindex mpart
21625 +Generate code for the specified part. Permissible parts are:
21626 +@samp{ap7000},
21627 +@samp{ap7001},
21628 +@samp{ap7002},
21629 +@samp{ap7200},
21630 +@samp{uc3a0128},
21631 +@samp{uc3a0256},
21632 +@samp{uc3a0512},
21633 +@samp{uc3a0512es},
21634 +@samp{uc3a1128},
21635 +@samp{uc3a1256},
21636 +@samp{uc3a1512},
21637 +@samp{uc3a1512es},
21638 +@samp{uc3a3revd},
21639 +@samp{uc3a364},
21640 +@samp{uc3a364s},
21641 +@samp{uc3a3128},
21642 +@samp{uc3a3128s},
21643 +@samp{uc3a3256},
21644 +@samp{uc3a3256s},
21645 +@samp{uc3b064},
21646 +@samp{uc3b0128},
21647 +@samp{uc3b0256},
21648 +@samp{uc3b0256es},
21649 +@samp{uc3b0512revc},
21650 +@samp{uc3b164},
21651 +@samp{uc3b1128},
21652 +@samp{uc3b1256},
21653 +@samp{uc3b1256es},
21654 +@samp{uc3b1512revc}
21655 +@samp{uc3c0512c},
21656 +@samp{uc3c0256c},
21657 +@samp{uc3c0128c},
21658 +@samp{uc3c064c},
21659 +@samp{uc3c1512c},
21660 +@samp{uc3c1256c},
21661 +@samp{uc3c1128c},
21662 +@samp{uc3c164c},
21663 +@samp{uc3c2512c},
21664 +@samp{uc3c2256c},
21665 +@samp{uc3c2128c},
21666 +@samp{uc3c264c},
21667 +@samp{uc3l064},
21668 +@samp{uc3l032},
21669 +@samp{uc3l016}.
21670 +
21671 +@item -mcpu=@var{cpu-type}
21672 +@opindex mcpu
21673 +Same as -mpart. Obsolete.
21674 +
21675 +@item -march=@var{arch}
21676 +@opindex march
21677 +Generate code for the specified architecture. Permissible architectures are:
21678 +@samp{ap}, @samp{uc} and @samp{ucr2}.
21679 +
21680 +@item -mfast-float
21681 +@opindex mfast-float
21682 +Enable fast floating-point library that does not conform to IEEE-754 but is still good enough
21683 +for most applications. The fast floating-point library does not round to the nearest even
21684 +but away from zero. Enabled by default if the -funsafe-math-optimizations switch is specified.
21685 +
21686 +@item -mimm-in-const-pool
21687 +@opindex mimm-in-const-pool
21688 +Put large immediates in constant pool. This is enabled by default for archs with insn-cache.
21689 +@end table
21690 +
21691 @node Blackfin Options
21692 @subsection Blackfin Options
21693 @cindex Blackfin Options
21694 @@ -8889,29 +9004,12 @@ When enabled, the compiler will ensure t
21695 contain speculative loads after jump instructions. If this option is used,
21696 @code{__WORKAROUND_SPECULATIVE_LOADS} is defined.
21697
21698 -@item -mno-specld-anomaly
21699 -@opindex mno-specld-anomaly
21700 -Don't generate extra code to prevent speculative loads from occurring.
21701 -
21702 @item -mcsync-anomaly
21703 @opindex mcsync-anomaly
21704 When enabled, the compiler will ensure that the generated code does not
21705 contain CSYNC or SSYNC instructions too soon after conditional branches.
21706 If this option is used, @code{__WORKAROUND_SPECULATIVE_SYNCS} is defined.
21707
21708 -@item -mno-csync-anomaly
21709 -@opindex mno-csync-anomaly
21710 -Don't generate extra code to prevent CSYNC or SSYNC instructions from
21711 -occurring too soon after a conditional branch.
21712 -
21713 -@item -mlow-64k
21714 -@opindex mlow-64k
21715 -When enabled, the compiler is free to take advantage of the knowledge that
21716 -the entire program fits into the low 64k of memory.
21717 -
21718 -@item -mno-low-64k
21719 -@opindex mno-low-64k
21720 -Assume that the program is arbitrarily large. This is the default.
21721
21722 @item -mstack-check-l1
21723 @opindex mstack-check-l1
21724 @@ -8925,11 +9023,6 @@ This allows for execute in place and sha
21725 without virtual memory management. This option implies @option{-fPIC}.
21726 With a @samp{bfin-elf} target, this option implies @option{-msim}.
21727
21728 -@item -mno-id-shared-library
21729 -@opindex mno-id-shared-library
21730 -Generate code that doesn't assume ID based shared libraries are being used.
21731 -This is the default.
21732 -
21733 @item -mleaf-id-shared-library
21734 @opindex mleaf-id-shared-library
21735 Generate code that supports shared libraries via the library ID method,
21736 @@ -8971,11 +9064,6 @@ call on this register. This switch is n
21737 will lie outside of the 24 bit addressing range of the offset based
21738 version of subroutine call instruction.
21739
21740 -This feature is not enabled by default. Specifying
21741 -@option{-mno-long-calls} will restore the default behavior. Note these
21742 -switches have no effect on how the compiler generates code to handle
21743 -function calls via function pointers.
21744 -
21745 @item -mfast-fp
21746 @opindex mfast-fp
21747 Link with the fast floating-point library. This library relaxes some of
21748 --- a/gcc/doc/md.texi
21749 +++ b/gcc/doc/md.texi
21750 @@ -1681,6 +1681,58 @@ A memory reference suitable for iWMMXt l
21751 A memory reference suitable for the ARMv4 ldrsb instruction.
21752 @end table
21753
21754 +@item AVR32 family---@file{avr32.h}
21755 +@table @code
21756 +@item f
21757 +Floating-point registers (f0 to f15)
21758 +
21759 +@item Ku@var{bits}
21760 +Unsigned constant representable with @var{bits} number of bits (Must be
21761 +two digits). I.e: An unsigned 8-bit constant is written as @samp{Ku08}
21762 +
21763 +@item Ks@var{bits}
21764 +Signed constant representable with @var{bits} number of bits (Must be
21765 +two digits). I.e: A signed 12-bit constant is written as @samp{Ks12}
21766 +
21767 +@item Is@var{bits}
21768 +The negated range of a signed constant representable with @var{bits}
21769 +number of bits. The same as @samp{Ks@var{bits}} with a negated range.
21770 +This means that the constant must be in the range @math{-2^{bits-1}-1} to @math{2^{bits-1}}
21771 +
21772 +@item G
21773 +A single/double precision floating-point immediate or 64-bit integer
21774 +immediate where the least and most significant words both can be
21775 +loaded with a move instruction. That is the the integer form of the
21776 +values in the least and most significant words both are in the range
21777 +@math{-2^{20}} to @math{2^{20}-1}.
21778 +
21779 +@item RKs@var{bits}
21780 +A memory reference where the address consists of a base register
21781 +plus a signed immediate displacement with range given by @samp{Ks@var{bits}}
21782 +which has the same format as for the signed immediate integer constraint
21783 +given above.
21784 +
21785 +@item RKu@var{bits}
21786 +A memory reference where the address consists of a base register
21787 +plus an unsigned immediate displacement with range given by @samp{Ku@var{bits}}
21788 +which has the same format as for the unsigned immediate integer constraint
21789 +given above.
21790 +
21791 +@item S
21792 +A memory reference with an immediate or register offset
21793 +
21794 +@item T
21795 +A memory reference to a constant pool entry
21796 +
21797 +@item W
21798 +A valid operand for use in the @samp{lda.w} instruction macro when
21799 +relaxing is enabled
21800 +
21801 +@item Z
21802 +A memory reference valid for coprocessor memory instructions
21803 +
21804 +@end table
21805 +
21806 @item AVR family---@file{config/avr/constraints.md}
21807 @table @code
21808 @item l
21809 --- a/gcc/expmed.c
21810 +++ b/gcc/expmed.c
21811 @@ -463,9 +463,9 @@ store_bit_field_1 (rtx str_rtx, unsigned
21812 ? ((GET_MODE_SIZE (fieldmode) >= UNITS_PER_WORD
21813 || GET_MODE_SIZE (GET_MODE (op0)) == GET_MODE_SIZE (fieldmode))
21814 && byte_offset % GET_MODE_SIZE (fieldmode) == 0)
21815 - : (! SLOW_UNALIGNED_ACCESS (fieldmode, MEM_ALIGN (op0))
21816 + : ( (! SLOW_UNALIGNED_ACCESS (fieldmode, MEM_ALIGN (op0))
21817 || (offset * BITS_PER_UNIT % bitsize == 0
21818 - && MEM_ALIGN (op0) % GET_MODE_BITSIZE (fieldmode) == 0))))
21819 + && MEM_ALIGN (op0) % GET_MODE_BITSIZE (fieldmode) == 0)))))
21820 {
21821 if (MEM_P (op0))
21822 op0 = adjust_address (op0, fieldmode, offset);
21823 --- a/gcc/expr.c
21824 +++ b/gcc/expr.c
21825 @@ -52,6 +52,7 @@ along with GCC; see the file COPYING3.
21826 #include "tree-flow.h"
21827 #include "target.h"
21828 #include "timevar.h"
21829 +#include "c-common.h"
21830 #include "df.h"
21831 #include "diagnostic.h"
21832
21833 @@ -3620,16 +3621,17 @@ emit_single_push_insn (enum machine_mode
21834 }
21835 else
21836 {
21837 + emit_move_insn (stack_pointer_rtx,
21838 + expand_binop (Pmode,
21839 #ifdef STACK_GROWS_DOWNWARD
21840 - /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
21841 - dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
21842 - GEN_INT (-(HOST_WIDE_INT) rounded_size));
21843 + sub_optab,
21844 #else
21845 - /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
21846 - dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
21847 - GEN_INT (rounded_size));
21848 + add_optab,
21849 #endif
21850 - dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
21851 + stack_pointer_rtx,
21852 + GEN_INT (rounded_size),
21853 + NULL_RTX, 0, OPTAB_LIB_WIDEN));
21854 + dest_addr = stack_pointer_rtx;
21855 }
21856
21857 dest = gen_rtx_MEM (mode, dest_addr);
21858 @@ -5739,7 +5741,8 @@ store_field (rtx target, HOST_WIDE_INT b
21859 is a bit field, we cannot use addressing to access it.
21860 Use bit-field techniques or SUBREG to store in it. */
21861
21862 - if (mode == VOIDmode
21863 + if (
21864 + mode == VOIDmode
21865 || (mode != BLKmode && ! direct_store[(int) mode]
21866 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
21867 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
21868 @@ -5896,7 +5899,19 @@ get_inner_reference (tree exp, HOST_WIDE
21869 {
21870 tree field = TREE_OPERAND (exp, 1);
21871 size_tree = DECL_SIZE (field);
21872 - if (!DECL_BIT_FIELD (field))
21873 + if (!DECL_BIT_FIELD (field)
21874 + /* Added for AVR32:
21875 + Bitfields with a size equal to a target storage
21876 + type might not cause DECL_BIT_FIELD to return
21877 + true since it can be optimized into a normal array
21878 + access operation. But for volatile bitfields we do
21879 + not allow this when targetm.narrow_volatile_bitfield ()
21880 + is false. We can use DECL_C_BIT_FIELD to check if this
21881 + really is a c-bitfield. */
21882 + && !(TREE_THIS_VOLATILE (exp)
21883 + && !targetm.narrow_volatile_bitfield ()
21884 + && DECL_C_BIT_FIELD (field)) )
21885 +
21886 mode = DECL_MODE (field);
21887 else if (DECL_MODE (field) == BLKmode)
21888 blkmode_bitfield = true;
21889 @@ -7889,7 +7904,8 @@ expand_expr_real_1 (tree exp, rtx target
21890 by doing the extract into an object as wide as the field
21891 (which we know to be the width of a basic mode), then
21892 storing into memory, and changing the mode to BLKmode. */
21893 - if (mode1 == VOIDmode
21894 + if (
21895 + mode1 == VOIDmode
21896 || REG_P (op0) || GET_CODE (op0) == SUBREG
21897 || (mode1 != BLKmode && ! direct_load[(int) mode1]
21898 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
21899 --- a/gcc/function.c
21900 +++ b/gcc/function.c
21901 @@ -2715,7 +2715,11 @@ assign_parm_setup_reg (struct assign_par
21902 SET_DECL_RTL (parm, parmreg);
21903
21904 /* Copy the value into the register. */
21905 - if (data->nominal_mode != data->passed_mode
21906 + if ( (data->nominal_mode != data->passed_mode
21907 + /* Added for AVR32: If passed_mode is equal
21908 + to promoted nominal mode why should be convert?
21909 + The conversion should make no difference. */
21910 + && data->passed_mode != promoted_nominal_mode)
21911 || promoted_nominal_mode != data->promoted_mode)
21912 {
21913 int save_tree_used;
21914 --- a/gcc/genemit.c
21915 +++ b/gcc/genemit.c
21916 @@ -121,6 +121,24 @@ max_operand_vec (rtx insn, int arg)
21917 }
21918 \f
21919 static void
21920 +gen_vararg_prologue(int operands)
21921 +{
21922 + int i;
21923 +
21924 + if (operands > 1)
21925 + {
21926 + for (i = 1; i < operands; i++)
21927 + printf(" rtx operand%d ATTRIBUTE_UNUSED;\n", i);
21928 +
21929 + printf(" va_list args;\n\n");
21930 + printf(" va_start(args, operand0);\n");
21931 + for (i = 1; i < operands; i++)
21932 + printf(" operand%d = va_arg(args, rtx);\n", i);
21933 + printf(" va_end(args);\n\n");
21934 + }
21935 +}
21936 +
21937 +static void
21938 print_code (RTX_CODE code)
21939 {
21940 const char *p1;
21941 @@ -406,18 +424,16 @@ gen_insn (rtx insn, int lineno)
21942 fatal ("match_dup operand number has no match_operand");
21943
21944 /* Output the function name and argument declarations. */
21945 - printf ("rtx\ngen_%s (", XSTR (insn, 0));
21946 + printf ("rtx\ngen_%s ", XSTR (insn, 0));
21947 +
21948 if (operands)
21949 - for (i = 0; i < operands; i++)
21950 - if (i)
21951 - printf (",\n\trtx operand%d ATTRIBUTE_UNUSED", i);
21952 + printf("(rtx operand0 ATTRIBUTE_UNUSED, ...)\n");
21953 else
21954 - printf ("rtx operand%d ATTRIBUTE_UNUSED", i);
21955 - else
21956 - printf ("void");
21957 - printf (")\n");
21958 + printf("(void)\n");
21959 printf ("{\n");
21960
21961 + gen_vararg_prologue(operands);
21962 +
21963 /* Output code to construct and return the rtl for the instruction body. */
21964
21965 if (XVECLEN (insn, 1) == 1)
21966 @@ -461,16 +477,12 @@ gen_expand (rtx expand)
21967 operands = max_operand_vec (expand, 1);
21968
21969 /* Output the function name and argument declarations. */
21970 - printf ("rtx\ngen_%s (", XSTR (expand, 0));
21971 + printf ("rtx\ngen_%s ", XSTR (expand, 0));
21972 if (operands)
21973 - for (i = 0; i < operands; i++)
21974 - if (i)
21975 - printf (",\n\trtx operand%d", i);
21976 - else
21977 - printf ("rtx operand%d", i);
21978 + printf("(rtx operand0 ATTRIBUTE_UNUSED, ...)\n");
21979 else
21980 - printf ("void");
21981 - printf (")\n");
21982 + printf("(void)\n");
21983 +
21984 printf ("{\n");
21985
21986 /* If we don't have any C code to write, only one insn is being written,
21987 @@ -480,6 +492,8 @@ gen_expand (rtx expand)
21988 && operands > max_dup_opno
21989 && XVECLEN (expand, 1) == 1)
21990 {
21991 + gen_vararg_prologue(operands);
21992 +
21993 printf (" return ");
21994 gen_exp (XVECEXP (expand, 1, 0), DEFINE_EXPAND, NULL);
21995 printf (";\n}\n\n");
21996 @@ -493,6 +507,7 @@ gen_expand (rtx expand)
21997 for (; i <= max_scratch_opno; i++)
21998 printf (" rtx operand%d ATTRIBUTE_UNUSED;\n", i);
21999 printf (" rtx _val = 0;\n");
22000 + gen_vararg_prologue(operands);
22001 printf (" start_sequence ();\n");
22002
22003 /* The fourth operand of DEFINE_EXPAND is some code to be executed
22004 --- a/gcc/genflags.c
22005 +++ b/gcc/genflags.c
22006 @@ -127,7 +127,6 @@ static void
22007 gen_proto (rtx insn)
22008 {
22009 int num = num_operands (insn);
22010 - int i;
22011 const char *name = XSTR (insn, 0);
22012 int truth = maybe_eval_c_test (XSTR (insn, 2));
22013
22014 @@ -158,12 +157,7 @@ gen_proto (rtx insn)
22015 if (num == 0)
22016 fputs ("void", stdout);
22017 else
22018 - {
22019 - for (i = 1; i < num; i++)
22020 - fputs ("rtx, ", stdout);
22021 -
22022 - fputs ("rtx", stdout);
22023 - }
22024 + fputs("rtx, ...", stdout);
22025
22026 puts (");");
22027
22028 @@ -173,12 +167,7 @@ gen_proto (rtx insn)
22029 {
22030 printf ("static inline rtx\ngen_%s", name);
22031 if (num > 0)
22032 - {
22033 - putchar ('(');
22034 - for (i = 0; i < num-1; i++)
22035 - printf ("rtx ARG_UNUSED (%c), ", 'a' + i);
22036 - printf ("rtx ARG_UNUSED (%c))\n", 'a' + i);
22037 - }
22038 + puts("(rtx ARG_UNUSED(a), ...)");
22039 else
22040 puts ("(void)");
22041 puts ("{\n return 0;\n}");
22042 --- a/gcc/genoutput.c
22043 +++ b/gcc/genoutput.c
22044 @@ -386,7 +386,7 @@ output_insn_data (void)
22045 }
22046
22047 if (d->name && d->name[0] != '*')
22048 - printf (" (insn_gen_fn) gen_%s,\n", d->name);
22049 + printf (" gen_%s,\n", d->name);
22050 else
22051 printf (" 0,\n");
22052
22053 --- a/gcc/ifcvt.c
22054 +++ b/gcc/ifcvt.c
22055 @@ -81,7 +81,7 @@ static int num_possible_if_blocks;
22056 static int num_updated_if_blocks;
22057
22058 /* # of changes made. */
22059 -static int num_true_changes;
22060 +int num_true_changes;
22061
22062 /* Whether conditional execution changes were made. */
22063 static int cond_exec_changed_p;
22064 @@ -286,6 +286,9 @@ cond_exec_process_insns (ce_if_block_t *
22065 if (must_be_last)
22066 return FALSE;
22067
22068 +#ifdef IFCVT_ALLOW_MODIFY_TEST_IN_INSN
22069 + if ( !IFCVT_ALLOW_MODIFY_TEST_IN_INSN )
22070 +#endif
22071 if (modified_in_p (test, insn))
22072 {
22073 if (!mod_ok)
22074 @@ -566,15 +569,18 @@ cond_exec_process_if_block (ce_if_block_
22075 IFCVT_MODIFY_FINAL (ce_info);
22076 #endif
22077
22078 + /* Merge the blocks! */
22079 + if ( reload_completed ){
22080 /* Conversion succeeded. */
22081 if (dump_file)
22082 fprintf (dump_file, "%d insn%s converted to conditional execution.\n",
22083 n_insns, (n_insns == 1) ? " was" : "s were");
22084
22085 - /* Merge the blocks! */
22086 merge_if_block (ce_info);
22087 cond_exec_changed_p = TRUE;
22088 return TRUE;
22089 + }
22090 + return FALSE;
22091
22092 fail:
22093 #ifdef IFCVT_MODIFY_CANCEL
22094 @@ -1080,7 +1086,11 @@ noce_try_addcc (struct noce_if_info *if_
22095 != UNKNOWN))
22096 {
22097 rtx cond = if_info->cond;
22098 - enum rtx_code code = reversed_comparison_code (cond, if_info->jump);
22099 + /* This generates wrong code for AVR32. The cond code need not be reversed
22100 + since the addmodecc patterns add if the condition is NOT met. */
22101 + /* enum rtx_code code = reversed_comparison_code (cond, if_info->jump);*/
22102 + enum rtx_code code = GET_CODE(cond);
22103 +
22104
22105 /* First try to use addcc pattern. */
22106 if (general_operand (XEXP (cond, 0), VOIDmode)
22107 @@ -3017,7 +3027,12 @@ find_if_header (basic_block test_bb, int
22108 && noce_find_if_block (test_bb, then_edge, else_edge, pass))
22109 goto success;
22110
22111 - if (HAVE_conditional_execution && reload_completed
22112 + if (HAVE_conditional_execution &&
22113 +#ifdef IFCVT_COND_EXEC_BEFORE_RELOAD
22114 + (reload_completed || IFCVT_COND_EXEC_BEFORE_RELOAD)
22115 +#else
22116 + reload_completed
22117 +#endif
22118 && cond_exec_find_if_block (&ce_info))
22119 goto success;
22120
22121 @@ -3132,7 +3147,11 @@ cond_exec_find_if_block (struct ce_if_bl
22122
22123 /* We only ever should get here after reload,
22124 and only if we have conditional execution. */
22125 +#ifdef IFCVT_COND_EXEC_BEFORE_RELOAD
22126 + gcc_assert (HAVE_conditional_execution && (reload_completed||IFCVT_COND_EXEC_BEFORE_RELOAD));
22127 +#else
22128 gcc_assert (HAVE_conditional_execution && reload_completed);
22129 +#endif
22130
22131 /* Discover if any fall through predecessors of the current test basic block
22132 were && tests (which jump to the else block) or || tests (which jump to
22133 @@ -4226,6 +4245,14 @@ gate_handle_if_after_reload (void)
22134 static unsigned int
22135 rest_of_handle_if_after_reload (void)
22136 {
22137 + /* Hack for the AVR32 experimental ifcvt processing before reload.
22138 + The AVR32 specific ifcvt code needs to know when ifcvt after reload
22139 + has begun. */
22140 +#ifdef IFCVT_COND_EXEC_BEFORE_RELOAD
22141 + if ( IFCVT_COND_EXEC_BEFORE_RELOAD )
22142 + cfun->machine->ifcvt_after_reload = 1;
22143 +#endif
22144 +
22145 if_convert ();
22146 return 0;
22147 }
22148 --- a/gcc/longlong.h
22149 +++ b/gcc/longlong.h
22150 @@ -239,6 +239,41 @@ UDItype __umulsidi3 (USItype, USItype);
22151 #define UDIV_TIME 100
22152 #endif /* __arm__ */
22153
22154 +#if defined (__avr32__) && W_TYPE_SIZE == 32
22155 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
22156 + __asm__ ("add\t%1, %4, %5\n\tadc\t%0, %2, %3" \
22157 + : "=r" ((USItype) (sh)), \
22158 + "=&r" ((USItype) (sl)) \
22159 + : "r" ((USItype) (ah)), \
22160 + "r" ((USItype) (bh)), \
22161 + "r" ((USItype) (al)), \
22162 + "r" ((USItype) (bl)) __CLOBBER_CC)
22163 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
22164 + __asm__ ("sub\t%1, %4, %5\n\tsbc\t%0, %2, %3" \
22165 + : "=r" ((USItype) (sh)), \
22166 + "=&r" ((USItype) (sl)) \
22167 + : "r" ((USItype) (ah)), \
22168 + "r" ((USItype) (bh)), \
22169 + "r" ((USItype) (al)), \
22170 + "r" ((USItype) (bl)) __CLOBBER_CC)
22171 +
22172 +#if !defined (__AVR32_NO_MUL__)
22173 +#define __umulsidi3(a,b) ((UDItype)(a) * (UDItype)(b))
22174 +
22175 +#define umul_ppmm(w1, w0, u, v) \
22176 +{ \
22177 + DWunion __w; \
22178 + __w.ll = __umulsidi3 (u, v); \
22179 + w1 = __w.s.high; \
22180 + w0 = __w.s.low; \
22181 +}
22182 +#endif
22183 +
22184 +#define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clz (X))
22185 +#define count_trailing_zeros(COUNT,X) ((COUNT) = __builtin_ctz (X))
22186 +#define COUNT_LEADING_ZEROS_0 32
22187 +#endif
22188 +
22189 #if defined (__CRIS__) && __CRIS_arch_version >= 3
22190 #define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clz (X))
22191 #if __CRIS_arch_version >= 8
22192 --- a/gcc/optabs.h
22193 +++ b/gcc/optabs.h
22194 @@ -586,7 +586,7 @@ extern enum insn_code reload_out_optab[N
22195 extern optab code_to_optab[NUM_RTX_CODE + 1];
22196
22197 \f
22198 -typedef rtx (*rtxfun) (rtx);
22199 +typedef rtx (*rtxfun) (rtx, ...);
22200
22201 /* Indexed by the rtx-code for a conditional (e.g. EQ, LT,...)
22202 gives the gen_function to make a branch to test that condition. */
22203 --- a/gcc/sched-deps.c
22204 +++ b/gcc/sched-deps.c
22205 @@ -1406,7 +1406,14 @@ fixup_sched_groups (rtx insn)
22206
22207 prev_nonnote = prev_nonnote_insn (insn);
22208 if (BLOCK_FOR_INSN (insn) == BLOCK_FOR_INSN (prev_nonnote)
22209 - && ! sched_insns_conditions_mutex_p (insn, prev_nonnote))
22210 + /* Modification for AVR32 by RP: Why is this here, this will
22211 + cause instruction to be without any dependencies which might
22212 + cause it to be moved anywhere. For the AVR32 we try to keep
22213 + a group of conditionals together even if they are mutual exclusive.
22214 + */
22215 + && (! sched_insns_conditions_mutex_p (insn, prev_nonnote)
22216 + || GET_CODE (PATTERN (insn)) == COND_EXEC )
22217 + )
22218 add_dependence (insn, prev_nonnote, REG_DEP_ANTI);
22219 }
22220 \f
22221 @@ -1905,8 +1912,29 @@ sched_analyze_insn (struct deps *deps, r
22222
22223 if (code == COND_EXEC)
22224 {
22225 +#ifdef IFCVT_ALLOW_MODIFY_TEST_IN_INSN
22226 + if (IFCVT_ALLOW_MODIFY_TEST_IN_INSN)
22227 + {
22228 + /* Check if we have a group og conditional instructions with the same test.
22229 + If so we must make sure that they are not scheduled apart in order to
22230 + avoid unnecesarry tests and if one of the registers in the test is modified
22231 + in the instruction this is needed to ensure correct code. */
22232 + if ( prev_nonnote_insn (insn)
22233 + && INSN_P (prev_nonnote_insn (insn))
22234 + && GET_CODE (PATTERN (prev_nonnote_insn (insn))) == COND_EXEC
22235 + && rtx_equal_p (XEXP(COND_EXEC_TEST (PATTERN (prev_nonnote_insn (insn))), 0), XEXP (COND_EXEC_TEST (x), 0))
22236 + && rtx_equal_p (XEXP(COND_EXEC_TEST (PATTERN (prev_nonnote_insn (insn))), 1), XEXP (COND_EXEC_TEST (x), 1))
22237 + && ( GET_CODE (COND_EXEC_TEST (PATTERN (prev_nonnote_insn (insn)))) == GET_CODE (COND_EXEC_TEST (x))
22238 + || GET_CODE (COND_EXEC_TEST (PATTERN (prev_nonnote_insn (insn)))) == reversed_comparison_code (COND_EXEC_TEST (x), insn)))
22239 + {
22240 + SCHED_GROUP_P (insn) = 1;
22241 + //CANT_MOVE (prev_nonnote_insn (insn)) = 1;
22242 + }
22243 + }
22244 +#endif
22245 sched_analyze_2 (deps, COND_EXEC_TEST (x), insn);
22246
22247 +
22248 /* ??? Should be recording conditions so we reduce the number of
22249 false dependencies. */
22250 x = COND_EXEC_CODE (x);
22251 --- a/gcc/testsuite/gcc.dg/sibcall-3.c
22252 +++ b/gcc/testsuite/gcc.dg/sibcall-3.c
22253 @@ -5,7 +5,7 @@
22254 Copyright (C) 2002 Free Software Foundation Inc.
22255 Contributed by Hans-Peter Nilsson <hp@bitrange.com> */
22256
22257 -/* { dg-do run { xfail arc-*-* avr-*-* cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* m68hc1?-*-* mcore-*-* mn10300-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
22258 +/* { dg-do run { xfail arc-*-* avr-*-* avr32-*-* cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* m68hc1?-*-* mcore-*-* mn10300-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
22259 /* -mlongcall disables sibcall patterns. */
22260 /* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */
22261 /* { dg-options "-O2 -foptimize-sibling-calls" } */
22262 --- a/gcc/testsuite/gcc.dg/sibcall-4.c
22263 +++ b/gcc/testsuite/gcc.dg/sibcall-4.c
22264 @@ -5,7 +5,7 @@
22265 Copyright (C) 2002 Free Software Foundation Inc.
22266 Contributed by Hans-Peter Nilsson <hp@bitrange.com> */
22267
22268 -/* { dg-do run { xfail arc-*-* avr-*-* cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* m68hc1?-*-* mcore-*-* mn10300-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
22269 +/* { dg-do run { xfail arc-*-* avr-*-* avr32-*-* cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* m68hc1?-*-* mcore-*-* mn10300-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
22270 /* -mlongcall disables sibcall patterns. */
22271 /* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */
22272 /* { dg-options "-O2 -foptimize-sibling-calls" } */
22273 --- a/gcc/testsuite/gcc.dg/trampoline-1.c
22274 +++ b/gcc/testsuite/gcc.dg/trampoline-1.c
22275 @@ -46,6 +46,8 @@ void foo (void)
22276
22277 int main (void)
22278 {
22279 +#ifndef NO_TRAMPOLINES
22280 foo ();
22281 +#endif
22282 return 0;
22283 }
22284 --- a/gcc/testsuite/g++.old-deja/g++.pt/static11.C
22285 +++ b/gcc/testsuite/g++.old-deja/g++.pt/static11.C
22286 @@ -2,7 +2,7 @@
22287 // in their dejagnu baseboard description) require that the status is
22288 // final when exit is entered (or main returns), and not "overruled" by a
22289 // destructor calling _exit. It's not really worth it to handle that.
22290 -// { dg-do run { xfail mmix-knuth-mmixware arm*-*-elf arm*-*-eabi m68k-*-elf } }
22291 +// { dg-do run { xfail mmix-knuth-mmixware avr32-*-elf arm*-*-elf arm*-*-eabi m68k-*-elf } }
22292
22293 // Bug: g++ was failing to destroy C<int>::a because it was using two
22294 // different sentry variables for construction and destruction.
22295 --- a/libgcc/config.host
22296 +++ b/libgcc/config.host
22297 @@ -240,6 +240,8 @@ arm-*-pe*)
22298 ;;
22299 arm*-*-kaos*)
22300 ;;
22301 +avr32-*-*)
22302 + ;;
22303 avr-*-rtems*)
22304 ;;
22305 avr-*-*)
22306 --- a/libstdc++-v3/config/os/gnu-linux/ctype_base.h
22307 +++ b/libstdc++-v3/config/os/gnu-linux/ctype_base.h
22308 @@ -31,6 +31,8 @@
22309 //
22310 // ISO C++ 14882: 22.1 Locales
22311 //
22312 +#include <features.h>
22313 +#include <ctype.h>
22314
22315 /** @file ctype_base.h
22316 * This is an internal header file, included by other library headers.
22317 @@ -45,7 +47,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
22318 struct ctype_base
22319 {
22320 // Non-standard typedefs.
22321 +#ifdef __UCLIBC__
22322 + typedef const __ctype_touplow_t* __to_type;
22323 +#else
22324 typedef const int* __to_type;
22325 +#endif
22326
22327 // NB: Offsets into ctype<char>::_M_table force a particular size
22328 // on the mask type. Because of this, we don't use an enum.
22329 --- a/libstdc++-v3/include/Makefile.in
22330 +++ b/libstdc++-v3/include/Makefile.in
22331 @@ -36,6 +36,7 @@ POST_UNINSTALL = :
22332 build_triplet = @build@
22333 host_triplet = @host@
22334 target_triplet = @target@
22335 +LIBOBJDIR =
22336 DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/Makefile.in \
22337 $(srcdir)/Makefile.am
22338 subdir = include
22339 --- a/libstdc++-v3/libmath/Makefile.in
22340 +++ b/libstdc++-v3/libmath/Makefile.in
22341 @@ -37,6 +37,7 @@ POST_UNINSTALL = :
22342 build_triplet = @build@
22343 host_triplet = @host@
22344 target_triplet = @target@
22345 +LIBOBJDIR =
22346 subdir = libmath
22347 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
22348 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
22349 --- a/libstdc++-v3/libsupc++/Makefile.in
22350 +++ b/libstdc++-v3/libsupc++/Makefile.in
22351 @@ -38,6 +38,7 @@ POST_UNINSTALL = :
22352 build_triplet = @build@
22353 host_triplet = @host@
22354 target_triplet = @target@
22355 +LIBOBJDIR =
22356 DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/Makefile.in \
22357 $(srcdir)/Makefile.am $(glibcxxinstall_HEADERS)
22358 subdir = libsupc++
22359 --- a/libstdc++-v3/Makefile.in
22360 +++ b/libstdc++-v3/Makefile.in
22361 @@ -36,6 +36,7 @@ POST_UNINSTALL = :
22362 build_triplet = @build@
22363 host_triplet = @host@
22364 target_triplet = @target@
22365 +LIBOBJDIR =
22366 DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/../config.guess \
22367 $(srcdir)/../config.sub README ChangeLog $(srcdir)/Makefile.in \
22368 $(srcdir)/Makefile.am $(top_srcdir)/configure \
22369 --- a/libstdc++-v3/po/Makefile.in
22370 +++ b/libstdc++-v3/po/Makefile.in
22371 @@ -36,6 +36,7 @@ POST_UNINSTALL = :
22372 build_triplet = @build@
22373 host_triplet = @host@
22374 target_triplet = @target@
22375 +LIBOBJDIR =
22376 DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/Makefile.in \
22377 $(srcdir)/Makefile.am
22378 subdir = po
22379 --- a/libstdc++-v3/src/Makefile.in
22380 +++ b/libstdc++-v3/src/Makefile.in
22381 @@ -37,6 +37,7 @@ POST_UNINSTALL = :
22382 build_triplet = @build@
22383 host_triplet = @host@
22384 target_triplet = @target@
22385 +LIBOBJDIR =
22386 DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/Makefile.in \
22387 $(srcdir)/Makefile.am
22388 subdir = src