FSF GCC merge 02/23/03
[official-gcc.git] / gcc / config / sparc / sparc.c
blobbb84f45cb092b430c70153d0c3a2bc7211566ee7
1 /* Subroutines for insn-output.c for Sun SPARC.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 64 bit SPARC V9 support by Michael Tiemann, Jim Wilson, and Doug Evans,
6 at Cygnus Support.
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "tree.h"
30 #include "rtl.h"
31 #include "regs.h"
32 #include "hard-reg-set.h"
33 #include "real.h"
34 #include "insn-config.h"
35 #include "conditions.h"
36 #include "output.h"
37 #include "insn-attr.h"
38 #include "flags.h"
39 #include "function.h"
40 #include "expr.h"
41 #include "optabs.h"
42 #include "libfuncs.h"
43 #include "recog.h"
44 #include "toplev.h"
45 #include "ggc.h"
46 #include "tm_p.h"
47 #include "debug.h"
48 #include "target.h"
49 #include "target-def.h"
51 /* 1 if the caller has placed an "unimp" insn immediately after the call.
52 This is used in v8 code when calling a function that returns a structure.
53 v9 doesn't have this. Be careful to have this test be the same as that
54 used on the call. */
56 #define SKIP_CALLERS_UNIMP_P \
57 (!TARGET_ARCH64 && current_function_returns_struct \
58 && ! integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))) \
59 && (TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl))) \
60 == INTEGER_CST))
62 /* Global variables for machine-dependent things. */
64 /* Size of frame. Need to know this to emit return insns from leaf procedures.
65 ACTUAL_FSIZE is set by compute_frame_size() which is called during the
66 reload pass. This is important as the value is later used in insn
67 scheduling (to see what can go in a delay slot).
68 APPARENT_FSIZE is the size of the stack less the register save area and less
69 the outgoing argument area. It is used when saving call preserved regs. */
70 static int apparent_fsize;
71 static int actual_fsize;
73 /* Number of live general or floating point registers needed to be
74 saved (as 4-byte quantities). */
75 static int num_gfregs;
77 /* Save the operands last given to a compare for use when we
78 generate a scc or bcc insn. */
79 rtx sparc_compare_op0, sparc_compare_op1;
81 /* Coordinate with the md file wrt special insns created by
82 sparc_nonflat_function_epilogue. */
83 bool sparc_emitting_epilogue;
85 /* Vector to say how input registers are mapped to output registers.
86 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
87 eliminate it. You must use -fomit-frame-pointer to get that. */
88 char leaf_reg_remap[] =
89 { 0, 1, 2, 3, 4, 5, 6, 7,
90 -1, -1, -1, -1, -1, -1, 14, -1,
91 -1, -1, -1, -1, -1, -1, -1, -1,
92 8, 9, 10, 11, 12, 13, -1, 15,
94 32, 33, 34, 35, 36, 37, 38, 39,
95 40, 41, 42, 43, 44, 45, 46, 47,
96 48, 49, 50, 51, 52, 53, 54, 55,
97 56, 57, 58, 59, 60, 61, 62, 63,
98 64, 65, 66, 67, 68, 69, 70, 71,
99 72, 73, 74, 75, 76, 77, 78, 79,
100 80, 81, 82, 83, 84, 85, 86, 87,
101 88, 89, 90, 91, 92, 93, 94, 95,
102 96, 97, 98, 99, 100};
104 /* Vector, indexed by hard register number, which contains 1
105 for a register that is allowable in a candidate for leaf
106 function treatment. */
107 char sparc_leaf_regs[] =
108 { 1, 1, 1, 1, 1, 1, 1, 1,
109 0, 0, 0, 0, 0, 0, 1, 0,
110 0, 0, 0, 0, 0, 0, 0, 0,
111 1, 1, 1, 1, 1, 1, 0, 1,
112 1, 1, 1, 1, 1, 1, 1, 1,
113 1, 1, 1, 1, 1, 1, 1, 1,
114 1, 1, 1, 1, 1, 1, 1, 1,
115 1, 1, 1, 1, 1, 1, 1, 1,
116 1, 1, 1, 1, 1, 1, 1, 1,
117 1, 1, 1, 1, 1, 1, 1, 1,
118 1, 1, 1, 1, 1, 1, 1, 1,
119 1, 1, 1, 1, 1, 1, 1, 1,
120 1, 1, 1, 1, 1};
122 /* Name of where we pretend to think the frame pointer points.
123 Normally, this is "%fp", but if we are in a leaf procedure,
124 this is "%sp+something". We record "something" separately as it may be
125 too big for reg+constant addressing. */
127 static const char *frame_base_name;
128 static int frame_base_offset;
130 static void sparc_init_modes PARAMS ((void));
131 static int save_regs PARAMS ((FILE *, int, int, const char *,
132 int, int, int));
133 static int restore_regs PARAMS ((FILE *, int, int, const char *, int, int));
134 static void build_big_number PARAMS ((FILE *, int, const char *));
135 static int function_arg_slotno PARAMS ((const CUMULATIVE_ARGS *,
136 enum machine_mode, tree, int, int,
137 int *, int *));
139 static int supersparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
140 static int hypersparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
142 static void sparc_output_addr_vec PARAMS ((rtx));
143 static void sparc_output_addr_diff_vec PARAMS ((rtx));
144 static void sparc_output_deferred_case_vectors PARAMS ((void));
145 static int check_return_regs PARAMS ((rtx));
146 static int epilogue_renumber PARAMS ((rtx *, int));
147 static bool sparc_assemble_integer PARAMS ((rtx, unsigned int, int));
148 static int set_extends PARAMS ((rtx));
149 static void output_restore_regs PARAMS ((FILE *, int));
150 static void sparc_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
151 static void sparc_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
152 static void sparc_flat_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
153 static void sparc_flat_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
154 static void sparc_nonflat_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT,
155 int));
156 static void sparc_nonflat_function_prologue PARAMS ((FILE *, HOST_WIDE_INT,
157 int));
158 #ifdef OBJECT_FORMAT_ELF
159 static void sparc_elf_asm_named_section PARAMS ((const char *, unsigned int));
160 #endif
161 static void sparc_aout_select_section PARAMS ((tree, int,
162 unsigned HOST_WIDE_INT))
163 ATTRIBUTE_UNUSED;
164 static void sparc_aout_select_rtx_section PARAMS ((enum machine_mode, rtx,
165 unsigned HOST_WIDE_INT))
166 ATTRIBUTE_UNUSED;
168 static int sparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
169 static int sparc_issue_rate PARAMS ((void));
170 static void sparc_sched_init PARAMS ((FILE *, int, int));
171 static int sparc_use_dfa_pipeline_interface PARAMS ((void));
172 static int sparc_use_sched_lookahead PARAMS ((void));
174 static void emit_soft_tfmode_libcall PARAMS ((const char *, int, rtx *));
175 static void emit_soft_tfmode_binop PARAMS ((enum rtx_code, rtx *));
176 static void emit_soft_tfmode_unop PARAMS ((enum rtx_code, rtx *));
177 static void emit_soft_tfmode_cvt PARAMS ((enum rtx_code, rtx *));
178 static void emit_hard_tfmode_operation PARAMS ((enum rtx_code, rtx *));
180 static void sparc_encode_section_info PARAMS ((tree, int));
181 static bool sparc_function_ok_for_sibcall PARAMS ((tree, tree));
182 static void sparc_output_mi_thunk PARAMS ((FILE *, tree, HOST_WIDE_INT,
183 HOST_WIDE_INT, tree));
184 static bool sparc_rtx_costs PARAMS ((rtx, int, int, int *));
186 /* Option handling. */
188 /* Code model option as passed by user. */
189 const char *sparc_cmodel_string;
190 /* Parsed value. */
191 enum cmodel sparc_cmodel;
193 char sparc_hard_reg_printed[8];
195 struct sparc_cpu_select sparc_select[] =
197 /* switch name, tune arch */
198 { (char *)0, "default", 1, 1 },
199 { (char *)0, "-mcpu=", 1, 1 },
200 { (char *)0, "-mtune=", 1, 0 },
201 { 0, 0, 0, 0 }
204 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
205 enum processor_type sparc_cpu;
207 /* Initialize the GCC target structure. */
209 /* The sparc default is to use .half rather than .short for aligned
210 HI objects. Use .word instead of .long on non-ELF systems. */
211 #undef TARGET_ASM_ALIGNED_HI_OP
212 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
213 #ifndef OBJECT_FORMAT_ELF
214 #undef TARGET_ASM_ALIGNED_SI_OP
215 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
216 #endif
218 #undef TARGET_ASM_UNALIGNED_HI_OP
219 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
220 #undef TARGET_ASM_UNALIGNED_SI_OP
221 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
222 #undef TARGET_ASM_UNALIGNED_DI_OP
223 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
225 /* The target hook has to handle DI-mode values. */
226 #undef TARGET_ASM_INTEGER
227 #define TARGET_ASM_INTEGER sparc_assemble_integer
229 #undef TARGET_ASM_FUNCTION_PROLOGUE
230 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_output_function_prologue
231 #undef TARGET_ASM_FUNCTION_EPILOGUE
232 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_output_function_epilogue
234 #undef TARGET_SCHED_ADJUST_COST
235 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
236 #undef TARGET_SCHED_ISSUE_RATE
237 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
238 #undef TARGET_SCHED_INIT
239 #define TARGET_SCHED_INIT sparc_sched_init
240 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
241 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE sparc_use_dfa_pipeline_interface
242 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
243 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
245 #undef TARGET_ENCODE_SECTION_INFO
246 #define TARGET_ENCODE_SECTION_INFO sparc_encode_section_info
248 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
249 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
251 #undef TARGET_ASM_OUTPUT_MI_THUNK
252 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
253 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
254 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
256 #undef TARGET_RTX_COSTS
257 #define TARGET_RTX_COSTS sparc_rtx_costs
258 #undef TARGET_ADDRESS_COST
259 #define TARGET_ADDRESS_COST hook_int_rtx_0
261 struct gcc_target targetm = TARGET_INITIALIZER;
263 /* Validate and override various options, and do some machine dependent
264 initialization. */
266 void
267 sparc_override_options ()
269 static struct code_model {
270 const char *const name;
271 const int value;
272 } const cmodels[] = {
273 { "32", CM_32 },
274 { "medlow", CM_MEDLOW },
275 { "medmid", CM_MEDMID },
276 { "medany", CM_MEDANY },
277 { "embmedany", CM_EMBMEDANY },
278 { 0, 0 }
280 const struct code_model *cmodel;
281 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
282 static struct cpu_default {
283 const int cpu;
284 const char *const name;
285 } const cpu_default[] = {
286 /* There must be one entry here for each TARGET_CPU value. */
287 { TARGET_CPU_sparc, "cypress" },
288 { TARGET_CPU_sparclet, "tsc701" },
289 { TARGET_CPU_sparclite, "f930" },
290 { TARGET_CPU_v8, "v8" },
291 { TARGET_CPU_hypersparc, "hypersparc" },
292 { TARGET_CPU_sparclite86x, "sparclite86x" },
293 { TARGET_CPU_supersparc, "supersparc" },
294 { TARGET_CPU_v9, "v9" },
295 { TARGET_CPU_ultrasparc, "ultrasparc" },
296 { TARGET_CPU_ultrasparc3, "ultrasparc3" },
297 { 0, 0 }
299 const struct cpu_default *def;
300 /* Table of values for -m{cpu,tune}=. */
301 static struct cpu_table {
302 const char *const name;
303 const enum processor_type processor;
304 const int disable;
305 const int enable;
306 } const cpu_table[] = {
307 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
308 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
309 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
310 /* TI TMS390Z55 supersparc */
311 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
312 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
313 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
314 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
315 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
316 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
317 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
318 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
319 MASK_SPARCLITE },
320 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
321 /* TEMIC sparclet */
322 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
323 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
324 /* TI ultrasparc I, II, IIi */
325 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
326 /* Although insns using %y are deprecated, it is a clear win on current
327 ultrasparcs. */
328 |MASK_DEPRECATED_V8_INSNS},
329 /* TI ultrasparc III */
330 /* ??? Check if %y issue still holds true in ultra3. */
331 { "ultrasparc3", PROCESSOR_ULTRASPARC3, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
332 { 0, 0, 0, 0 }
334 const struct cpu_table *cpu;
335 const struct sparc_cpu_select *sel;
336 int fpu;
338 #ifndef SPARC_BI_ARCH
339 /* Check for unsupported architecture size. */
340 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
341 error ("%s is not supported by this configuration",
342 DEFAULT_ARCH32_P ? "-m64" : "-m32");
343 #endif
345 /* We force all 64bit archs to use 128 bit long double */
346 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
348 error ("-mlong-double-64 not allowed with -m64");
349 target_flags |= MASK_LONG_DOUBLE_128;
352 /* Code model selection. */
353 sparc_cmodel = SPARC_DEFAULT_CMODEL;
355 #ifdef SPARC_BI_ARCH
356 if (TARGET_ARCH32)
357 sparc_cmodel = CM_32;
358 #endif
360 if (sparc_cmodel_string != NULL)
362 if (TARGET_ARCH64)
364 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
365 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
366 break;
367 if (cmodel->name == NULL)
368 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
369 else
370 sparc_cmodel = cmodel->value;
372 else
373 error ("-mcmodel= is not supported on 32 bit systems");
376 fpu = TARGET_FPU; /* save current -mfpu status */
378 /* Set the default CPU. */
379 for (def = &cpu_default[0]; def->name; ++def)
380 if (def->cpu == TARGET_CPU_DEFAULT)
381 break;
382 if (! def->name)
383 abort ();
384 sparc_select[0].string = def->name;
386 for (sel = &sparc_select[0]; sel->name; ++sel)
388 if (sel->string)
390 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
391 if (! strcmp (sel->string, cpu->name))
393 if (sel->set_tune_p)
394 sparc_cpu = cpu->processor;
396 if (sel->set_arch_p)
398 target_flags &= ~cpu->disable;
399 target_flags |= cpu->enable;
401 break;
404 if (! cpu->name)
405 error ("bad value (%s) for %s switch", sel->string, sel->name);
409 /* If -mfpu or -mno-fpu was explicitly used, don't override with
410 the processor default. Clear MASK_FPU_SET to avoid confusing
411 the reverse mapping from switch values to names. */
412 if (TARGET_FPU_SET)
414 target_flags = (target_flags & ~MASK_FPU) | fpu;
415 target_flags &= ~MASK_FPU_SET;
418 /* Don't allow -mvis if FPU is disabled. */
419 if (! TARGET_FPU)
420 target_flags &= ~MASK_VIS;
422 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
423 are available.
424 -m64 also implies v9. */
425 if (TARGET_VIS || TARGET_ARCH64)
427 target_flags |= MASK_V9;
428 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
431 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
432 if (TARGET_V9 && TARGET_ARCH32)
433 target_flags |= MASK_DEPRECATED_V8_INSNS;
435 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
436 if (! TARGET_V9 || TARGET_ARCH64)
437 target_flags &= ~MASK_V8PLUS;
439 /* Don't use stack biasing in 32 bit mode. */
440 if (TARGET_ARCH32)
441 target_flags &= ~MASK_STACK_BIAS;
443 /* Supply a default value for align_functions. */
444 if (align_functions == 0
445 && (sparc_cpu == PROCESSOR_ULTRASPARC
446 || sparc_cpu == PROCESSOR_ULTRASPARC3))
447 align_functions = 32;
449 /* Validate PCC_STRUCT_RETURN. */
450 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
451 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
453 /* Only use .uaxword when compiling for a 64-bit target. */
454 if (!TARGET_ARCH64)
455 targetm.asm_out.unaligned_op.di = NULL;
457 /* Do various machine dependent initializations. */
458 sparc_init_modes ();
461 /* Miscellaneous utilities. */
463 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
464 or branch on register contents instructions. */
467 v9_regcmp_p (code)
468 enum rtx_code code;
470 return (code == EQ || code == NE || code == GE || code == LT
471 || code == LE || code == GT);
475 /* Operand constraints. */
477 /* Return nonzero only if OP is a register of mode MODE,
478 or const0_rtx. */
481 reg_or_0_operand (op, mode)
482 rtx op;
483 enum machine_mode mode;
485 if (register_operand (op, mode))
486 return 1;
487 if (op == const0_rtx)
488 return 1;
489 if (GET_MODE (op) == VOIDmode && GET_CODE (op) == CONST_DOUBLE
490 && CONST_DOUBLE_HIGH (op) == 0
491 && CONST_DOUBLE_LOW (op) == 0)
492 return 1;
493 if (fp_zero_operand (op, mode))
494 return 1;
495 return 0;
498 /* Return nonzero only if OP is const1_rtx. */
501 const1_operand (op, mode)
502 rtx op;
503 enum machine_mode mode ATTRIBUTE_UNUSED;
505 return op == const1_rtx;
508 /* Nonzero if OP is a floating point value with value 0.0. */
511 fp_zero_operand (op, mode)
512 rtx op;
513 enum machine_mode mode;
515 if (GET_MODE_CLASS (GET_MODE (op)) != MODE_FLOAT)
516 return 0;
517 return op == CONST0_RTX (mode);
520 /* Nonzero if OP is a register operand in floating point register. */
523 fp_register_operand (op, mode)
524 rtx op;
525 enum machine_mode mode;
527 if (! register_operand (op, mode))
528 return 0;
529 if (GET_CODE (op) == SUBREG)
530 op = SUBREG_REG (op);
531 return GET_CODE (op) == REG && SPARC_FP_REG_P (REGNO (op));
534 /* Nonzero if OP is a floating point constant which can
535 be loaded into an integer register using a single
536 sethi instruction. */
539 fp_sethi_p (op)
540 rtx op;
542 if (GET_CODE (op) == CONST_DOUBLE)
544 REAL_VALUE_TYPE r;
545 long i;
547 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
548 if (REAL_VALUES_EQUAL (r, dconst0) &&
549 ! REAL_VALUE_MINUS_ZERO (r))
550 return 0;
551 REAL_VALUE_TO_TARGET_SINGLE (r, i);
552 if (SPARC_SETHI_P (i))
553 return 1;
556 return 0;
559 /* Nonzero if OP is a floating point constant which can
560 be loaded into an integer register using a single
561 mov instruction. */
564 fp_mov_p (op)
565 rtx op;
567 if (GET_CODE (op) == CONST_DOUBLE)
569 REAL_VALUE_TYPE r;
570 long i;
572 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
573 if (REAL_VALUES_EQUAL (r, dconst0) &&
574 ! REAL_VALUE_MINUS_ZERO (r))
575 return 0;
576 REAL_VALUE_TO_TARGET_SINGLE (r, i);
577 if (SPARC_SIMM13_P (i))
578 return 1;
581 return 0;
584 /* Nonzero if OP is a floating point constant which can
585 be loaded into an integer register using a high/losum
586 instruction sequence. */
589 fp_high_losum_p (op)
590 rtx op;
592 /* The constraints calling this should only be in
593 SFmode move insns, so any constant which cannot
594 be moved using a single insn will do. */
595 if (GET_CODE (op) == CONST_DOUBLE)
597 REAL_VALUE_TYPE r;
598 long i;
600 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
601 if (REAL_VALUES_EQUAL (r, dconst0) &&
602 ! REAL_VALUE_MINUS_ZERO (r))
603 return 0;
604 REAL_VALUE_TO_TARGET_SINGLE (r, i);
605 if (! SPARC_SETHI_P (i)
606 && ! SPARC_SIMM13_P (i))
607 return 1;
610 return 0;
613 /* Nonzero if OP is an integer register. */
616 intreg_operand (op, mode)
617 rtx op;
618 enum machine_mode mode ATTRIBUTE_UNUSED;
620 return (register_operand (op, SImode)
621 || (TARGET_ARCH64 && register_operand (op, DImode)));
624 /* Nonzero if OP is a floating point condition code register. */
627 fcc_reg_operand (op, mode)
628 rtx op;
629 enum machine_mode mode;
631 /* This can happen when recog is called from combine. Op may be a MEM.
632 Fail instead of calling abort in this case. */
633 if (GET_CODE (op) != REG)
634 return 0;
636 if (mode != VOIDmode && mode != GET_MODE (op))
637 return 0;
638 if (mode == VOIDmode
639 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
640 return 0;
642 #if 0 /* ??? ==> 1 when %fcc0-3 are pseudos first. See gen_compare_reg(). */
643 if (reg_renumber == 0)
644 return REGNO (op) >= FIRST_PSEUDO_REGISTER;
645 return REGNO_OK_FOR_CCFP_P (REGNO (op));
646 #else
647 return (unsigned) REGNO (op) - SPARC_FIRST_V9_FCC_REG < 4;
648 #endif
651 /* Nonzero if OP is a floating point condition code fcc0 register. */
654 fcc0_reg_operand (op, mode)
655 rtx op;
656 enum machine_mode mode;
658 /* This can happen when recog is called from combine. Op may be a MEM.
659 Fail instead of calling abort in this case. */
660 if (GET_CODE (op) != REG)
661 return 0;
663 if (mode != VOIDmode && mode != GET_MODE (op))
664 return 0;
665 if (mode == VOIDmode
666 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
667 return 0;
669 return REGNO (op) == SPARC_FCC_REG;
672 /* Nonzero if OP is an integer or floating point condition code register. */
675 icc_or_fcc_reg_operand (op, mode)
676 rtx op;
677 enum machine_mode mode;
679 if (GET_CODE (op) == REG && REGNO (op) == SPARC_ICC_REG)
681 if (mode != VOIDmode && mode != GET_MODE (op))
682 return 0;
683 if (mode == VOIDmode
684 && GET_MODE (op) != CCmode && GET_MODE (op) != CCXmode)
685 return 0;
686 return 1;
689 return fcc_reg_operand (op, mode);
692 /* Nonzero if OP can appear as the dest of a RESTORE insn. */
694 restore_operand (op, mode)
695 rtx op;
696 enum machine_mode mode;
698 return (GET_CODE (op) == REG && GET_MODE (op) == mode
699 && (REGNO (op) < 8 || (REGNO (op) >= 24 && REGNO (op) < 32)));
702 /* Call insn on SPARC can take a PC-relative constant address, or any regular
703 memory address. */
706 call_operand (op, mode)
707 rtx op;
708 enum machine_mode mode;
710 if (GET_CODE (op) != MEM)
711 abort ();
712 op = XEXP (op, 0);
713 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
717 call_operand_address (op, mode)
718 rtx op;
719 enum machine_mode mode;
721 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
724 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
725 reference and a constant. */
728 symbolic_operand (op, mode)
729 register rtx op;
730 enum machine_mode mode;
732 enum machine_mode omode = GET_MODE (op);
734 if (omode != mode && omode != VOIDmode && mode != VOIDmode)
735 return 0;
737 switch (GET_CODE (op))
739 case SYMBOL_REF:
740 case LABEL_REF:
741 return 1;
743 case CONST:
744 op = XEXP (op, 0);
745 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
746 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
747 && GET_CODE (XEXP (op, 1)) == CONST_INT);
749 default:
750 return 0;
754 /* Return truth value of statement that OP is a symbolic memory
755 operand of mode MODE. */
758 symbolic_memory_operand (op, mode)
759 rtx op;
760 enum machine_mode mode ATTRIBUTE_UNUSED;
762 if (GET_CODE (op) == SUBREG)
763 op = SUBREG_REG (op);
764 if (GET_CODE (op) != MEM)
765 return 0;
766 op = XEXP (op, 0);
767 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
768 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
771 /* Return truth value of statement that OP is a LABEL_REF of mode MODE. */
774 label_ref_operand (op, mode)
775 rtx op;
776 enum machine_mode mode;
778 if (GET_CODE (op) != LABEL_REF)
779 return 0;
780 if (GET_MODE (op) != mode)
781 return 0;
782 return 1;
785 /* Return 1 if the operand is an argument used in generating pic references
786 in either the medium/low or medium/anywhere code models of sparc64. */
789 sp64_medium_pic_operand (op, mode)
790 rtx op;
791 enum machine_mode mode ATTRIBUTE_UNUSED;
793 /* Check for (const (minus (symbol_ref:GOT)
794 (const (minus (label) (pc))))). */
795 if (GET_CODE (op) != CONST)
796 return 0;
797 op = XEXP (op, 0);
798 if (GET_CODE (op) != MINUS)
799 return 0;
800 if (GET_CODE (XEXP (op, 0)) != SYMBOL_REF)
801 return 0;
802 /* ??? Ensure symbol is GOT. */
803 if (GET_CODE (XEXP (op, 1)) != CONST)
804 return 0;
805 if (GET_CODE (XEXP (XEXP (op, 1), 0)) != MINUS)
806 return 0;
807 return 1;
810 /* Return 1 if the operand is a data segment reference. This includes
811 the readonly data segment, or in other words anything but the text segment.
812 This is needed in the medium/anywhere code model on v9. These values
813 are accessed with EMBMEDANY_BASE_REG. */
816 data_segment_operand (op, mode)
817 rtx op;
818 enum machine_mode mode ATTRIBUTE_UNUSED;
820 switch (GET_CODE (op))
822 case SYMBOL_REF :
823 return ! SYMBOL_REF_FLAG (op);
824 case PLUS :
825 /* Assume canonical format of symbol + constant.
826 Fall through. */
827 case CONST :
828 return data_segment_operand (XEXP (op, 0), VOIDmode);
829 default :
830 return 0;
834 /* Return 1 if the operand is a text segment reference.
835 This is needed in the medium/anywhere code model on v9. */
838 text_segment_operand (op, mode)
839 rtx op;
840 enum machine_mode mode ATTRIBUTE_UNUSED;
842 switch (GET_CODE (op))
844 case LABEL_REF :
845 return 1;
846 case SYMBOL_REF :
847 return SYMBOL_REF_FLAG (op);
848 case PLUS :
849 /* Assume canonical format of symbol + constant.
850 Fall through. */
851 case CONST :
852 return text_segment_operand (XEXP (op, 0), VOIDmode);
853 default :
854 return 0;
858 /* Return 1 if the operand is either a register or a memory operand that is
859 not symbolic. */
862 reg_or_nonsymb_mem_operand (op, mode)
863 register rtx op;
864 enum machine_mode mode;
866 if (register_operand (op, mode))
867 return 1;
869 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
870 return 1;
872 return 0;
876 splittable_symbolic_memory_operand (op, mode)
877 rtx op;
878 enum machine_mode mode ATTRIBUTE_UNUSED;
880 if (GET_CODE (op) != MEM)
881 return 0;
882 if (! symbolic_operand (XEXP (op, 0), Pmode))
883 return 0;
884 return 1;
888 splittable_immediate_memory_operand (op, mode)
889 rtx op;
890 enum machine_mode mode ATTRIBUTE_UNUSED;
892 if (GET_CODE (op) != MEM)
893 return 0;
894 if (! immediate_operand (XEXP (op, 0), Pmode))
895 return 0;
896 return 1;
899 /* Return truth value of whether OP is EQ or NE. */
902 eq_or_neq (op, mode)
903 rtx op;
904 enum machine_mode mode ATTRIBUTE_UNUSED;
906 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
909 /* Return 1 if this is a comparison operator, but not an EQ, NE, GEU,
910 or LTU for non-floating-point. We handle those specially. */
913 normal_comp_operator (op, mode)
914 rtx op;
915 enum machine_mode mode ATTRIBUTE_UNUSED;
917 enum rtx_code code = GET_CODE (op);
919 if (GET_RTX_CLASS (code) != '<')
920 return 0;
922 if (GET_MODE (XEXP (op, 0)) == CCFPmode
923 || GET_MODE (XEXP (op, 0)) == CCFPEmode)
924 return 1;
926 return (code != NE && code != EQ && code != GEU && code != LTU);
929 /* Return 1 if this is a comparison operator. This allows the use of
930 MATCH_OPERATOR to recognize all the branch insns. */
933 noov_compare_op (op, mode)
934 register rtx op;
935 enum machine_mode mode ATTRIBUTE_UNUSED;
937 enum rtx_code code = GET_CODE (op);
939 if (GET_RTX_CLASS (code) != '<')
940 return 0;
942 if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode
943 || GET_MODE (XEXP (op, 0)) == CCX_NOOVmode)
944 /* These are the only branches which work with CC_NOOVmode. */
945 return (code == EQ || code == NE || code == GE || code == LT);
946 return 1;
949 /* Return 1 if this is a 64-bit comparison operator. This allows the use of
950 MATCH_OPERATOR to recognize all the branch insns. */
953 noov_compare64_op (op, mode)
954 register rtx op;
955 enum machine_mode mode ATTRIBUTE_UNUSED;
957 enum rtx_code code = GET_CODE (op);
959 if (! TARGET_V9)
960 return 0;
962 if (GET_RTX_CLASS (code) != '<')
963 return 0;
965 if (GET_MODE (XEXP (op, 0)) == CCX_NOOVmode)
966 /* These are the only branches which work with CCX_NOOVmode. */
967 return (code == EQ || code == NE || code == GE || code == LT);
968 return (GET_MODE (XEXP (op, 0)) == CCXmode);
971 /* Nonzero if OP is a comparison operator suitable for use in v9
972 conditional move or branch on register contents instructions. */
975 v9_regcmp_op (op, mode)
976 register rtx op;
977 enum machine_mode mode ATTRIBUTE_UNUSED;
979 enum rtx_code code = GET_CODE (op);
981 if (GET_RTX_CLASS (code) != '<')
982 return 0;
984 return v9_regcmp_p (code);
987 /* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */
990 extend_op (op, mode)
991 rtx op;
992 enum machine_mode mode ATTRIBUTE_UNUSED;
994 return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND;
997 /* Return nonzero if OP is an operator of mode MODE which can set
998 the condition codes explicitly. We do not include PLUS and MINUS
999 because these require CC_NOOVmode, which we handle explicitly. */
1002 cc_arithop (op, mode)
1003 rtx op;
1004 enum machine_mode mode ATTRIBUTE_UNUSED;
1006 if (GET_CODE (op) == AND
1007 || GET_CODE (op) == IOR
1008 || GET_CODE (op) == XOR)
1009 return 1;
1011 return 0;
1014 /* Return nonzero if OP is an operator of mode MODE which can bitwise
1015 complement its second operand and set the condition codes explicitly. */
1018 cc_arithopn (op, mode)
1019 rtx op;
1020 enum machine_mode mode ATTRIBUTE_UNUSED;
1022 /* XOR is not here because combine canonicalizes (xor (not ...) ...)
1023 and (xor ... (not ...)) to (not (xor ...)). */
1024 return (GET_CODE (op) == AND
1025 || GET_CODE (op) == IOR);
1028 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1029 signed 13 bit immediate field. This is an acceptable SImode operand for
1030 most 3 address instructions. */
1033 arith_operand (op, mode)
1034 rtx op;
1035 enum machine_mode mode;
1037 if (register_operand (op, mode))
1038 return 1;
1039 if (GET_CODE (op) != CONST_INT)
1040 return 0;
1041 return SMALL_INT32 (op);
1044 /* Return true if OP is a constant 4096 */
1047 arith_4096_operand (op, mode)
1048 rtx op;
1049 enum machine_mode mode ATTRIBUTE_UNUSED;
1051 if (GET_CODE (op) != CONST_INT)
1052 return 0;
1053 else
1054 return INTVAL (op) == 4096;
1057 /* Return true if OP is suitable as second operand for add/sub */
1060 arith_add_operand (op, mode)
1061 rtx op;
1062 enum machine_mode mode;
1064 return arith_operand (op, mode) || arith_4096_operand (op, mode);
1067 /* Return true if OP is a CONST_INT or a CONST_DOUBLE which can fit in the
1068 immediate field of OR and XOR instructions. Used for 64-bit
1069 constant formation patterns. */
1071 const64_operand (op, mode)
1072 rtx op;
1073 enum machine_mode mode ATTRIBUTE_UNUSED;
1075 return ((GET_CODE (op) == CONST_INT
1076 && SPARC_SIMM13_P (INTVAL (op)))
1077 #if HOST_BITS_PER_WIDE_INT != 64
1078 || (GET_CODE (op) == CONST_DOUBLE
1079 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1080 && (CONST_DOUBLE_HIGH (op) ==
1081 ((CONST_DOUBLE_LOW (op) & 0x80000000) != 0 ?
1082 (HOST_WIDE_INT)-1 : 0)))
1083 #endif
1087 /* The same, but only for sethi instructions. */
1089 const64_high_operand (op, mode)
1090 rtx op;
1091 enum machine_mode mode;
1093 return ((GET_CODE (op) == CONST_INT
1094 && (INTVAL (op) & ~(HOST_WIDE_INT)0x3ff) != 0
1095 && SPARC_SETHI_P (INTVAL (op) & GET_MODE_MASK (mode))
1097 || (GET_CODE (op) == CONST_DOUBLE
1098 && CONST_DOUBLE_HIGH (op) == 0
1099 && (CONST_DOUBLE_LOW (op) & ~(HOST_WIDE_INT)0x3ff) != 0
1100 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op))));
1103 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1104 signed 11 bit immediate field. This is an acceptable SImode operand for
1105 the movcc instructions. */
1108 arith11_operand (op, mode)
1109 rtx op;
1110 enum machine_mode mode;
1112 return (register_operand (op, mode)
1113 || (GET_CODE (op) == CONST_INT && SPARC_SIMM11_P (INTVAL (op))));
1116 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1117 signed 10 bit immediate field. This is an acceptable SImode operand for
1118 the movrcc instructions. */
1121 arith10_operand (op, mode)
1122 rtx op;
1123 enum machine_mode mode;
1125 return (register_operand (op, mode)
1126 || (GET_CODE (op) == CONST_INT && SPARC_SIMM10_P (INTVAL (op))));
1129 /* Return true if OP is a register, is a CONST_INT that fits in a 13 bit
1130 immediate field, or is a CONST_DOUBLE whose both parts fit in a 13 bit
1131 immediate field.
1132 v9: Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1133 can fit in a 13 bit immediate field. This is an acceptable DImode operand
1134 for most 3 address instructions. */
1137 arith_double_operand (op, mode)
1138 rtx op;
1139 enum machine_mode mode;
1141 return (register_operand (op, mode)
1142 || (GET_CODE (op) == CONST_INT && SMALL_INT (op))
1143 || (! TARGET_ARCH64
1144 && GET_CODE (op) == CONST_DOUBLE
1145 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1146 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_HIGH (op) + 0x1000) < 0x2000)
1147 || (TARGET_ARCH64
1148 && GET_CODE (op) == CONST_DOUBLE
1149 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1150 && ((CONST_DOUBLE_HIGH (op) == -1
1151 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000)
1152 || (CONST_DOUBLE_HIGH (op) == 0
1153 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
1156 /* Return true if OP is a constant 4096 for DImode on ARCH64 */
1159 arith_double_4096_operand (op, mode)
1160 rtx op;
1161 enum machine_mode mode ATTRIBUTE_UNUSED;
1163 return (TARGET_ARCH64 &&
1164 ((GET_CODE (op) == CONST_INT && INTVAL (op) == 4096) ||
1165 (GET_CODE (op) == CONST_DOUBLE &&
1166 CONST_DOUBLE_LOW (op) == 4096 &&
1167 CONST_DOUBLE_HIGH (op) == 0)));
1170 /* Return true if OP is suitable as second operand for add/sub in DImode */
1173 arith_double_add_operand (op, mode)
1174 rtx op;
1175 enum machine_mode mode;
1177 return arith_double_operand (op, mode) || arith_double_4096_operand (op, mode);
1180 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1181 can fit in an 11 bit immediate field. This is an acceptable DImode
1182 operand for the movcc instructions. */
1183 /* ??? Replace with arith11_operand? */
1186 arith11_double_operand (op, mode)
1187 rtx op;
1188 enum machine_mode mode;
1190 return (register_operand (op, mode)
1191 || (GET_CODE (op) == CONST_DOUBLE
1192 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1193 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x400) < 0x800
1194 && ((CONST_DOUBLE_HIGH (op) == -1
1195 && (CONST_DOUBLE_LOW (op) & 0x400) == 0x400)
1196 || (CONST_DOUBLE_HIGH (op) == 0
1197 && (CONST_DOUBLE_LOW (op) & 0x400) == 0)))
1198 || (GET_CODE (op) == CONST_INT
1199 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1200 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x400) < 0x800));
1203 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1204 can fit in an 10 bit immediate field. This is an acceptable DImode
1205 operand for the movrcc instructions. */
1206 /* ??? Replace with arith10_operand? */
1209 arith10_double_operand (op, mode)
1210 rtx op;
1211 enum machine_mode mode;
1213 return (register_operand (op, mode)
1214 || (GET_CODE (op) == CONST_DOUBLE
1215 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1216 && (unsigned) (CONST_DOUBLE_LOW (op) + 0x200) < 0x400
1217 && ((CONST_DOUBLE_HIGH (op) == -1
1218 && (CONST_DOUBLE_LOW (op) & 0x200) == 0x200)
1219 || (CONST_DOUBLE_HIGH (op) == 0
1220 && (CONST_DOUBLE_LOW (op) & 0x200) == 0)))
1221 || (GET_CODE (op) == CONST_INT
1222 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1223 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x200) < 0x400));
1226 /* Return truth value of whether OP is an integer which fits the
1227 range constraining immediate operands in most three-address insns,
1228 which have a 13 bit immediate field. */
1231 small_int (op, mode)
1232 rtx op;
1233 enum machine_mode mode ATTRIBUTE_UNUSED;
1235 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
1239 small_int_or_double (op, mode)
1240 rtx op;
1241 enum machine_mode mode ATTRIBUTE_UNUSED;
1243 return ((GET_CODE (op) == CONST_INT && SMALL_INT (op))
1244 || (GET_CODE (op) == CONST_DOUBLE
1245 && CONST_DOUBLE_HIGH (op) == 0
1246 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))));
1249 /* Recognize operand values for the umul instruction. That instruction sign
1250 extends immediate values just like all other sparc instructions, but
1251 interprets the extended result as an unsigned number. */
1254 uns_small_int (op, mode)
1255 rtx op;
1256 enum machine_mode mode ATTRIBUTE_UNUSED;
1258 #if HOST_BITS_PER_WIDE_INT > 32
1259 /* All allowed constants will fit a CONST_INT. */
1260 return (GET_CODE (op) == CONST_INT
1261 && ((INTVAL (op) >= 0 && INTVAL (op) < 0x1000)
1262 || (INTVAL (op) >= 0xFFFFF000
1263 && INTVAL (op) <= 0xFFFFFFFF)));
1264 #else
1265 return ((GET_CODE (op) == CONST_INT && (unsigned) INTVAL (op) < 0x1000)
1266 || (GET_CODE (op) == CONST_DOUBLE
1267 && CONST_DOUBLE_HIGH (op) == 0
1268 && (unsigned) CONST_DOUBLE_LOW (op) - 0xFFFFF000 < 0x1000));
1269 #endif
1273 uns_arith_operand (op, mode)
1274 rtx op;
1275 enum machine_mode mode;
1277 return register_operand (op, mode) || uns_small_int (op, mode);
1280 /* Return truth value of statement that OP is a call-clobbered register. */
1282 clobbered_register (op, mode)
1283 rtx op;
1284 enum machine_mode mode ATTRIBUTE_UNUSED;
1286 return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]);
1289 /* Return 1 if OP is a valid operand for the source of a move insn. */
1292 input_operand (op, mode)
1293 rtx op;
1294 enum machine_mode mode;
1296 /* If both modes are non-void they must be the same. */
1297 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1298 return 0;
1300 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
1301 if (GET_CODE (op) == CONST && GET_CODE (XEXP (op, 0)) == CONSTANT_P_RTX)
1302 return 1;
1304 /* Allow any one instruction integer constant, and all CONST_INT
1305 variants when we are working in DImode and !arch64. */
1306 if (GET_MODE_CLASS (mode) == MODE_INT
1307 && ((GET_CODE (op) == CONST_INT
1308 && (SPARC_SETHI_P (INTVAL (op) & GET_MODE_MASK (mode))
1309 || SPARC_SIMM13_P (INTVAL (op))
1310 || (mode == DImode
1311 && ! TARGET_ARCH64)))
1312 || (TARGET_ARCH64
1313 && GET_CODE (op) == CONST_DOUBLE
1314 && ((CONST_DOUBLE_HIGH (op) == 0
1315 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op)))
1317 #if HOST_BITS_PER_WIDE_INT == 64
1318 (CONST_DOUBLE_HIGH (op) == 0
1319 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op)))
1320 #else
1321 (SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1322 && (((CONST_DOUBLE_LOW (op) & 0x80000000) == 0
1323 && CONST_DOUBLE_HIGH (op) == 0)
1324 || (CONST_DOUBLE_HIGH (op) == -1
1325 && CONST_DOUBLE_LOW (op) & 0x80000000) != 0))
1326 #endif
1327 ))))
1328 return 1;
1330 /* If !arch64 and this is a DImode const, allow it so that
1331 the splits can be generated. */
1332 if (! TARGET_ARCH64
1333 && mode == DImode
1334 && GET_CODE (op) == CONST_DOUBLE)
1335 return 1;
1337 if (register_operand (op, mode))
1338 return 1;
1340 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1341 && GET_CODE (op) == CONST_DOUBLE)
1342 return 1;
1344 /* If this is a SUBREG, look inside so that we handle
1345 paradoxical ones. */
1346 if (GET_CODE (op) == SUBREG)
1347 op = SUBREG_REG (op);
1349 /* Check for valid MEM forms. */
1350 if (GET_CODE (op) == MEM)
1352 rtx inside = XEXP (op, 0);
1354 if (GET_CODE (inside) == LO_SUM)
1356 /* We can't allow these because all of the splits
1357 (eventually as they trickle down into DFmode
1358 splits) require offsettable memory references. */
1359 if (! TARGET_V9
1360 && GET_MODE (op) == TFmode)
1361 return 0;
1363 return (register_operand (XEXP (inside, 0), Pmode)
1364 && CONSTANT_P (XEXP (inside, 1)));
1366 return memory_address_p (mode, inside);
1369 return 0;
1373 /* We know it can't be done in one insn when we get here,
1374 the movsi expander guarentees this. */
1375 void
1376 sparc_emit_set_const32 (op0, op1)
1377 rtx op0;
1378 rtx op1;
1380 enum machine_mode mode = GET_MODE (op0);
1381 rtx temp;
1383 if (GET_CODE (op1) == CONST_INT)
1385 HOST_WIDE_INT value = INTVAL (op1);
1387 if (SPARC_SETHI_P (value & GET_MODE_MASK (mode))
1388 || SPARC_SIMM13_P (value))
1389 abort ();
1392 /* Full 2-insn decomposition is needed. */
1393 if (reload_in_progress || reload_completed)
1394 temp = op0;
1395 else
1396 temp = gen_reg_rtx (mode);
1398 if (GET_CODE (op1) == CONST_INT)
1400 /* Emit them as real moves instead of a HIGH/LO_SUM,
1401 this way CSE can see everything and reuse intermediate
1402 values if it wants. */
1403 if (TARGET_ARCH64
1404 && HOST_BITS_PER_WIDE_INT != 64
1405 && (INTVAL (op1) & 0x80000000) != 0)
1406 emit_insn (gen_rtx_SET
1407 (VOIDmode, temp,
1408 immed_double_const (INTVAL (op1) & ~(HOST_WIDE_INT)0x3ff,
1409 0, DImode)));
1410 else
1411 emit_insn (gen_rtx_SET (VOIDmode, temp,
1412 GEN_INT (INTVAL (op1)
1413 & ~(HOST_WIDE_INT)0x3ff)));
1415 emit_insn (gen_rtx_SET (VOIDmode,
1416 op0,
1417 gen_rtx_IOR (mode, temp,
1418 GEN_INT (INTVAL (op1) & 0x3ff))));
1420 else
1422 /* A symbol, emit in the traditional way. */
1423 emit_insn (gen_rtx_SET (VOIDmode, temp,
1424 gen_rtx_HIGH (mode, op1)));
1425 emit_insn (gen_rtx_SET (VOIDmode,
1426 op0, gen_rtx_LO_SUM (mode, temp, op1)));
1432 /* SPARC-v9 code-model support. */
1433 void
1434 sparc_emit_set_symbolic_const64 (op0, op1, temp1)
1435 rtx op0;
1436 rtx op1;
1437 rtx temp1;
1439 rtx ti_temp1 = 0;
1441 if (temp1 && GET_MODE (temp1) == TImode)
1443 ti_temp1 = temp1;
1444 temp1 = gen_rtx_REG (DImode, REGNO (temp1));
1447 switch (sparc_cmodel)
1449 case CM_MEDLOW:
1450 /* The range spanned by all instructions in the object is less
1451 than 2^31 bytes (2GB) and the distance from any instruction
1452 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1453 than 2^31 bytes (2GB).
1455 The executable must be in the low 4TB of the virtual address
1456 space.
1458 sethi %hi(symbol), %temp
1459 or %temp, %lo(symbol), %reg */
1460 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
1461 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1462 break;
1464 case CM_MEDMID:
1465 /* The range spanned by all instructions in the object is less
1466 than 2^31 bytes (2GB) and the distance from any instruction
1467 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1468 than 2^31 bytes (2GB).
1470 The executable must be in the low 16TB of the virtual address
1471 space.
1473 sethi %h44(symbol), %temp1
1474 or %temp1, %m44(symbol), %temp2
1475 sllx %temp2, 12, %temp3
1476 or %temp3, %l44(symbol), %reg */
1477 emit_insn (gen_seth44 (op0, op1));
1478 emit_insn (gen_setm44 (op0, op0, op1));
1479 emit_insn (gen_rtx_SET (VOIDmode, temp1,
1480 gen_rtx_ASHIFT (DImode, op0, GEN_INT (12))));
1481 emit_insn (gen_setl44 (op0, temp1, op1));
1482 break;
1484 case CM_MEDANY:
1485 /* The range spanned by all instructions in the object is less
1486 than 2^31 bytes (2GB) and the distance from any instruction
1487 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1488 than 2^31 bytes (2GB).
1490 The executable can be placed anywhere in the virtual address
1491 space.
1493 sethi %hh(symbol), %temp1
1494 sethi %lm(symbol), %temp2
1495 or %temp1, %hm(symbol), %temp3
1496 or %temp2, %lo(symbol), %temp4
1497 sllx %temp3, 32, %temp5
1498 or %temp4, %temp5, %reg */
1500 /* It is possible that one of the registers we got for operands[2]
1501 might coincide with that of operands[0] (which is why we made
1502 it TImode). Pick the other one to use as our scratch. */
1503 if (rtx_equal_p (temp1, op0))
1505 if (ti_temp1)
1506 temp1 = gen_rtx_REG (DImode, REGNO (temp1) + 1);
1507 else
1508 abort();
1511 emit_insn (gen_sethh (op0, op1));
1512 emit_insn (gen_setlm (temp1, op1));
1513 emit_insn (gen_sethm (op0, op0, op1));
1514 emit_insn (gen_rtx_SET (VOIDmode, op0,
1515 gen_rtx_ASHIFT (DImode, op0, GEN_INT (32))));
1516 emit_insn (gen_rtx_SET (VOIDmode, op0,
1517 gen_rtx_PLUS (DImode, op0, temp1)));
1518 emit_insn (gen_setlo (op0, op0, op1));
1519 break;
1521 case CM_EMBMEDANY:
1522 /* Old old old backwards compatibility kruft here.
1523 Essentially it is MEDLOW with a fixed 64-bit
1524 virtual base added to all data segment addresses.
1525 Text-segment stuff is computed like MEDANY, we can't
1526 reuse the code above because the relocation knobs
1527 look different.
1529 Data segment: sethi %hi(symbol), %temp1
1530 or %temp1, %lo(symbol), %temp2
1531 add %temp2, EMBMEDANY_BASE_REG, %reg
1533 Text segment: sethi %uhi(symbol), %temp1
1534 sethi %hi(symbol), %temp2
1535 or %temp1, %ulo(symbol), %temp3
1536 or %temp2, %lo(symbol), %temp4
1537 sllx %temp3, 32, %temp5
1538 or %temp4, %temp5, %reg */
1539 if (data_segment_operand (op1, GET_MODE (op1)))
1541 emit_insn (gen_embmedany_sethi (temp1, op1));
1542 emit_insn (gen_embmedany_brsum (op0, temp1));
1543 emit_insn (gen_embmedany_losum (op0, op0, op1));
1545 else
1547 /* It is possible that one of the registers we got for operands[2]
1548 might coincide with that of operands[0] (which is why we made
1549 it TImode). Pick the other one to use as our scratch. */
1550 if (rtx_equal_p (temp1, op0))
1552 if (ti_temp1)
1553 temp1 = gen_rtx_REG (DImode, REGNO (temp1) + 1);
1554 else
1555 abort();
1558 emit_insn (gen_embmedany_textuhi (op0, op1));
1559 emit_insn (gen_embmedany_texthi (temp1, op1));
1560 emit_insn (gen_embmedany_textulo (op0, op0, op1));
1561 emit_insn (gen_rtx_SET (VOIDmode, op0,
1562 gen_rtx_ASHIFT (DImode, op0, GEN_INT (32))));
1563 emit_insn (gen_rtx_SET (VOIDmode, op0,
1564 gen_rtx_PLUS (DImode, op0, temp1)));
1565 emit_insn (gen_embmedany_textlo (op0, op0, op1));
1567 break;
1569 default:
1570 abort();
1574 /* These avoid problems when cross compiling. If we do not
1575 go through all this hair then the optimizer will see
1576 invalid REG_EQUAL notes or in some cases none at all. */
1577 static void sparc_emit_set_safe_HIGH64 PARAMS ((rtx, HOST_WIDE_INT));
1578 static rtx gen_safe_SET64 PARAMS ((rtx, HOST_WIDE_INT));
1579 static rtx gen_safe_OR64 PARAMS ((rtx, HOST_WIDE_INT));
1580 static rtx gen_safe_XOR64 PARAMS ((rtx, HOST_WIDE_INT));
1582 #if HOST_BITS_PER_WIDE_INT == 64
1583 #define GEN_HIGHINT64(__x) GEN_INT ((__x) & ~(HOST_WIDE_INT)0x3ff)
1584 #define GEN_INT64(__x) GEN_INT (__x)
1585 #else
1586 #define GEN_HIGHINT64(__x) \
1587 immed_double_const ((__x) & ~(HOST_WIDE_INT)0x3ff, 0, DImode)
1588 #define GEN_INT64(__x) \
1589 immed_double_const ((__x) & 0xffffffff, \
1590 ((__x) & 0x80000000 ? -1 : 0), DImode)
1591 #endif
1593 /* The optimizer is not to assume anything about exactly
1594 which bits are set for a HIGH, they are unspecified.
1595 Unfortunately this leads to many missed optimizations
1596 during CSE. We mask out the non-HIGH bits, and matches
1597 a plain movdi, to alleviate this problem. */
1598 static void
1599 sparc_emit_set_safe_HIGH64 (dest, val)
1600 rtx dest;
1601 HOST_WIDE_INT val;
1603 emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_HIGHINT64 (val)));
1606 static rtx
1607 gen_safe_SET64 (dest, val)
1608 rtx dest;
1609 HOST_WIDE_INT val;
1611 return gen_rtx_SET (VOIDmode, dest, GEN_INT64 (val));
1614 static rtx
1615 gen_safe_OR64 (src, val)
1616 rtx src;
1617 HOST_WIDE_INT val;
1619 return gen_rtx_IOR (DImode, src, GEN_INT64 (val));
1622 static rtx
1623 gen_safe_XOR64 (src, val)
1624 rtx src;
1625 HOST_WIDE_INT val;
1627 return gen_rtx_XOR (DImode, src, GEN_INT64 (val));
1630 /* Worker routines for 64-bit constant formation on arch64.
1631 One of the key things to be doing in these emissions is
1632 to create as many temp REGs as possible. This makes it
1633 possible for half-built constants to be used later when
1634 such values are similar to something required later on.
1635 Without doing this, the optimizer cannot see such
1636 opportunities. */
1638 static void sparc_emit_set_const64_quick1
1639 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT, int));
1641 static void
1642 sparc_emit_set_const64_quick1 (op0, temp, low_bits, is_neg)
1643 rtx op0;
1644 rtx temp;
1645 unsigned HOST_WIDE_INT low_bits;
1646 int is_neg;
1648 unsigned HOST_WIDE_INT high_bits;
1650 if (is_neg)
1651 high_bits = (~low_bits) & 0xffffffff;
1652 else
1653 high_bits = low_bits;
1655 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1656 if (!is_neg)
1658 emit_insn (gen_rtx_SET (VOIDmode, op0,
1659 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1661 else
1663 /* If we are XOR'ing with -1, then we should emit a one's complement
1664 instead. This way the combiner will notice logical operations
1665 such as ANDN later on and substitute. */
1666 if ((low_bits & 0x3ff) == 0x3ff)
1668 emit_insn (gen_rtx_SET (VOIDmode, op0,
1669 gen_rtx_NOT (DImode, temp)));
1671 else
1673 emit_insn (gen_rtx_SET (VOIDmode, op0,
1674 gen_safe_XOR64 (temp,
1675 (-(HOST_WIDE_INT)0x400
1676 | (low_bits & 0x3ff)))));
1681 static void sparc_emit_set_const64_quick2
1682 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT,
1683 unsigned HOST_WIDE_INT, int));
1685 static void
1686 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_immediate, shift_count)
1687 rtx op0;
1688 rtx temp;
1689 unsigned HOST_WIDE_INT high_bits;
1690 unsigned HOST_WIDE_INT low_immediate;
1691 int shift_count;
1693 rtx temp2 = op0;
1695 if ((high_bits & 0xfffffc00) != 0)
1697 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1698 if ((high_bits & ~0xfffffc00) != 0)
1699 emit_insn (gen_rtx_SET (VOIDmode, op0,
1700 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1701 else
1702 temp2 = temp;
1704 else
1706 emit_insn (gen_safe_SET64 (temp, high_bits));
1707 temp2 = temp;
1710 /* Now shift it up into place. */
1711 emit_insn (gen_rtx_SET (VOIDmode, op0,
1712 gen_rtx_ASHIFT (DImode, temp2,
1713 GEN_INT (shift_count))));
1715 /* If there is a low immediate part piece, finish up by
1716 putting that in as well. */
1717 if (low_immediate != 0)
1718 emit_insn (gen_rtx_SET (VOIDmode, op0,
1719 gen_safe_OR64 (op0, low_immediate)));
1722 static void sparc_emit_set_const64_longway
1723 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT));
1725 /* Full 64-bit constant decomposition. Even though this is the
1726 'worst' case, we still optimize a few things away. */
1727 static void
1728 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits)
1729 rtx op0;
1730 rtx temp;
1731 unsigned HOST_WIDE_INT high_bits;
1732 unsigned HOST_WIDE_INT low_bits;
1734 rtx sub_temp;
1736 if (reload_in_progress || reload_completed)
1737 sub_temp = op0;
1738 else
1739 sub_temp = gen_reg_rtx (DImode);
1741 if ((high_bits & 0xfffffc00) != 0)
1743 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1744 if ((high_bits & ~0xfffffc00) != 0)
1745 emit_insn (gen_rtx_SET (VOIDmode,
1746 sub_temp,
1747 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1748 else
1749 sub_temp = temp;
1751 else
1753 emit_insn (gen_safe_SET64 (temp, high_bits));
1754 sub_temp = temp;
1757 if (!reload_in_progress && !reload_completed)
1759 rtx temp2 = gen_reg_rtx (DImode);
1760 rtx temp3 = gen_reg_rtx (DImode);
1761 rtx temp4 = gen_reg_rtx (DImode);
1763 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1764 gen_rtx_ASHIFT (DImode, sub_temp,
1765 GEN_INT (32))));
1767 sparc_emit_set_safe_HIGH64 (temp2, low_bits);
1768 if ((low_bits & ~0xfffffc00) != 0)
1770 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1771 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
1772 emit_insn (gen_rtx_SET (VOIDmode, op0,
1773 gen_rtx_PLUS (DImode, temp4, temp3)));
1775 else
1777 emit_insn (gen_rtx_SET (VOIDmode, op0,
1778 gen_rtx_PLUS (DImode, temp4, temp2)));
1781 else
1783 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
1784 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
1785 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
1786 int to_shift = 12;
1788 /* We are in the middle of reload, so this is really
1789 painful. However we do still make an attempt to
1790 avoid emitting truly stupid code. */
1791 if (low1 != const0_rtx)
1793 emit_insn (gen_rtx_SET (VOIDmode, op0,
1794 gen_rtx_ASHIFT (DImode, sub_temp,
1795 GEN_INT (to_shift))));
1796 emit_insn (gen_rtx_SET (VOIDmode, op0,
1797 gen_rtx_IOR (DImode, op0, low1)));
1798 sub_temp = op0;
1799 to_shift = 12;
1801 else
1803 to_shift += 12;
1805 if (low2 != const0_rtx)
1807 emit_insn (gen_rtx_SET (VOIDmode, op0,
1808 gen_rtx_ASHIFT (DImode, sub_temp,
1809 GEN_INT (to_shift))));
1810 emit_insn (gen_rtx_SET (VOIDmode, op0,
1811 gen_rtx_IOR (DImode, op0, low2)));
1812 sub_temp = op0;
1813 to_shift = 8;
1815 else
1817 to_shift += 8;
1819 emit_insn (gen_rtx_SET (VOIDmode, op0,
1820 gen_rtx_ASHIFT (DImode, sub_temp,
1821 GEN_INT (to_shift))));
1822 if (low3 != const0_rtx)
1823 emit_insn (gen_rtx_SET (VOIDmode, op0,
1824 gen_rtx_IOR (DImode, op0, low3)));
1825 /* phew... */
1829 /* Analyze a 64-bit constant for certain properties. */
1830 static void analyze_64bit_constant
1831 PARAMS ((unsigned HOST_WIDE_INT,
1832 unsigned HOST_WIDE_INT,
1833 int *, int *, int *));
1835 static void
1836 analyze_64bit_constant (high_bits, low_bits, hbsp, lbsp, abbasp)
1837 unsigned HOST_WIDE_INT high_bits, low_bits;
1838 int *hbsp, *lbsp, *abbasp;
1840 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
1841 int i;
1843 lowest_bit_set = highest_bit_set = -1;
1844 i = 0;
1847 if ((lowest_bit_set == -1)
1848 && ((low_bits >> i) & 1))
1849 lowest_bit_set = i;
1850 if ((highest_bit_set == -1)
1851 && ((high_bits >> (32 - i - 1)) & 1))
1852 highest_bit_set = (64 - i - 1);
1854 while (++i < 32
1855 && ((highest_bit_set == -1)
1856 || (lowest_bit_set == -1)));
1857 if (i == 32)
1859 i = 0;
1862 if ((lowest_bit_set == -1)
1863 && ((high_bits >> i) & 1))
1864 lowest_bit_set = i + 32;
1865 if ((highest_bit_set == -1)
1866 && ((low_bits >> (32 - i - 1)) & 1))
1867 highest_bit_set = 32 - i - 1;
1869 while (++i < 32
1870 && ((highest_bit_set == -1)
1871 || (lowest_bit_set == -1)));
1873 /* If there are no bits set this should have gone out
1874 as one instruction! */
1875 if (lowest_bit_set == -1
1876 || highest_bit_set == -1)
1877 abort ();
1878 all_bits_between_are_set = 1;
1879 for (i = lowest_bit_set; i <= highest_bit_set; i++)
1881 if (i < 32)
1883 if ((low_bits & (1 << i)) != 0)
1884 continue;
1886 else
1888 if ((high_bits & (1 << (i - 32))) != 0)
1889 continue;
1891 all_bits_between_are_set = 0;
1892 break;
1894 *hbsp = highest_bit_set;
1895 *lbsp = lowest_bit_set;
1896 *abbasp = all_bits_between_are_set;
1899 static int const64_is_2insns
1900 PARAMS ((unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT));
1902 static int
1903 const64_is_2insns (high_bits, low_bits)
1904 unsigned HOST_WIDE_INT high_bits, low_bits;
1906 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
1908 if (high_bits == 0
1909 || high_bits == 0xffffffff)
1910 return 1;
1912 analyze_64bit_constant (high_bits, low_bits,
1913 &highest_bit_set, &lowest_bit_set,
1914 &all_bits_between_are_set);
1916 if ((highest_bit_set == 63
1917 || lowest_bit_set == 0)
1918 && all_bits_between_are_set != 0)
1919 return 1;
1921 if ((highest_bit_set - lowest_bit_set) < 21)
1922 return 1;
1924 return 0;
1927 static unsigned HOST_WIDE_INT create_simple_focus_bits
1928 PARAMS ((unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
1929 int, int));
1931 static unsigned HOST_WIDE_INT
1932 create_simple_focus_bits (high_bits, low_bits, lowest_bit_set, shift)
1933 unsigned HOST_WIDE_INT high_bits, low_bits;
1934 int lowest_bit_set, shift;
1936 HOST_WIDE_INT hi, lo;
1938 if (lowest_bit_set < 32)
1940 lo = (low_bits >> lowest_bit_set) << shift;
1941 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
1943 else
1945 lo = 0;
1946 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
1948 if (hi & lo)
1949 abort ();
1950 return (hi | lo);
1953 /* Here we are sure to be arch64 and this is an integer constant
1954 being loaded into a register. Emit the most efficient
1955 insn sequence possible. Detection of all the 1-insn cases
1956 has been done already. */
1957 void
1958 sparc_emit_set_const64 (op0, op1)
1959 rtx op0;
1960 rtx op1;
1962 unsigned HOST_WIDE_INT high_bits, low_bits;
1963 int lowest_bit_set, highest_bit_set;
1964 int all_bits_between_are_set;
1965 rtx temp;
1967 /* Sanity check that we know what we are working with. */
1968 if (! TARGET_ARCH64)
1969 abort ();
1971 if (GET_CODE (op0) != SUBREG)
1973 if (GET_CODE (op0) != REG
1974 || (REGNO (op0) >= SPARC_FIRST_FP_REG
1975 && REGNO (op0) <= SPARC_LAST_V9_FP_REG))
1976 abort ();
1979 if (reload_in_progress || reload_completed)
1980 temp = op0;
1981 else
1982 temp = gen_reg_rtx (DImode);
1984 if (GET_CODE (op1) != CONST_DOUBLE
1985 && GET_CODE (op1) != CONST_INT)
1987 sparc_emit_set_symbolic_const64 (op0, op1, temp);
1988 return;
1991 if (GET_CODE (op1) == CONST_DOUBLE)
1993 #if HOST_BITS_PER_WIDE_INT == 64
1994 high_bits = (CONST_DOUBLE_LOW (op1) >> 32) & 0xffffffff;
1995 low_bits = CONST_DOUBLE_LOW (op1) & 0xffffffff;
1996 #else
1997 high_bits = CONST_DOUBLE_HIGH (op1);
1998 low_bits = CONST_DOUBLE_LOW (op1);
1999 #endif
2001 else
2003 #if HOST_BITS_PER_WIDE_INT == 64
2004 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
2005 low_bits = (INTVAL (op1) & 0xffffffff);
2006 #else
2007 high_bits = ((INTVAL (op1) < 0) ?
2008 0xffffffff :
2009 0x00000000);
2010 low_bits = INTVAL (op1);
2011 #endif
2014 /* low_bits bits 0 --> 31
2015 high_bits bits 32 --> 63 */
2017 analyze_64bit_constant (high_bits, low_bits,
2018 &highest_bit_set, &lowest_bit_set,
2019 &all_bits_between_are_set);
2021 /* First try for a 2-insn sequence. */
2023 /* These situations are preferred because the optimizer can
2024 * do more things with them:
2025 * 1) mov -1, %reg
2026 * sllx %reg, shift, %reg
2027 * 2) mov -1, %reg
2028 * srlx %reg, shift, %reg
2029 * 3) mov some_small_const, %reg
2030 * sllx %reg, shift, %reg
2032 if (((highest_bit_set == 63
2033 || lowest_bit_set == 0)
2034 && all_bits_between_are_set != 0)
2035 || ((highest_bit_set - lowest_bit_set) < 12))
2037 HOST_WIDE_INT the_const = -1;
2038 int shift = lowest_bit_set;
2040 if ((highest_bit_set != 63
2041 && lowest_bit_set != 0)
2042 || all_bits_between_are_set == 0)
2044 the_const =
2045 create_simple_focus_bits (high_bits, low_bits,
2046 lowest_bit_set, 0);
2048 else if (lowest_bit_set == 0)
2049 shift = -(63 - highest_bit_set);
2051 if (! SPARC_SIMM13_P (the_const))
2052 abort ();
2054 emit_insn (gen_safe_SET64 (temp, the_const));
2055 if (shift > 0)
2056 emit_insn (gen_rtx_SET (VOIDmode,
2057 op0,
2058 gen_rtx_ASHIFT (DImode,
2059 temp,
2060 GEN_INT (shift))));
2061 else if (shift < 0)
2062 emit_insn (gen_rtx_SET (VOIDmode,
2063 op0,
2064 gen_rtx_LSHIFTRT (DImode,
2065 temp,
2066 GEN_INT (-shift))));
2067 else
2068 abort ();
2069 return;
2072 /* Now a range of 22 or less bits set somewhere.
2073 * 1) sethi %hi(focus_bits), %reg
2074 * sllx %reg, shift, %reg
2075 * 2) sethi %hi(focus_bits), %reg
2076 * srlx %reg, shift, %reg
2078 if ((highest_bit_set - lowest_bit_set) < 21)
2080 unsigned HOST_WIDE_INT focus_bits =
2081 create_simple_focus_bits (high_bits, low_bits,
2082 lowest_bit_set, 10);
2084 if (! SPARC_SETHI_P (focus_bits))
2085 abort ();
2087 sparc_emit_set_safe_HIGH64 (temp, focus_bits);
2089 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
2090 if (lowest_bit_set < 10)
2091 emit_insn (gen_rtx_SET (VOIDmode,
2092 op0,
2093 gen_rtx_LSHIFTRT (DImode, temp,
2094 GEN_INT (10 - lowest_bit_set))));
2095 else if (lowest_bit_set > 10)
2096 emit_insn (gen_rtx_SET (VOIDmode,
2097 op0,
2098 gen_rtx_ASHIFT (DImode, temp,
2099 GEN_INT (lowest_bit_set - 10))));
2100 else
2101 abort ();
2102 return;
2105 /* 1) sethi %hi(low_bits), %reg
2106 * or %reg, %lo(low_bits), %reg
2107 * 2) sethi %hi(~low_bits), %reg
2108 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
2110 if (high_bits == 0
2111 || high_bits == 0xffffffff)
2113 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
2114 (high_bits == 0xffffffff));
2115 return;
2118 /* Now, try 3-insn sequences. */
2120 /* 1) sethi %hi(high_bits), %reg
2121 * or %reg, %lo(high_bits), %reg
2122 * sllx %reg, 32, %reg
2124 if (low_bits == 0)
2126 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
2127 return;
2130 /* We may be able to do something quick
2131 when the constant is negated, so try that. */
2132 if (const64_is_2insns ((~high_bits) & 0xffffffff,
2133 (~low_bits) & 0xfffffc00))
2135 /* NOTE: The trailing bits get XOR'd so we need the
2136 non-negated bits, not the negated ones. */
2137 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
2139 if ((((~high_bits) & 0xffffffff) == 0
2140 && ((~low_bits) & 0x80000000) == 0)
2141 || (((~high_bits) & 0xffffffff) == 0xffffffff
2142 && ((~low_bits) & 0x80000000) != 0))
2144 int fast_int = (~low_bits & 0xffffffff);
2146 if ((SPARC_SETHI_P (fast_int)
2147 && (~high_bits & 0xffffffff) == 0)
2148 || SPARC_SIMM13_P (fast_int))
2149 emit_insn (gen_safe_SET64 (temp, fast_int));
2150 else
2151 sparc_emit_set_const64 (temp, GEN_INT64 (fast_int));
2153 else
2155 rtx negated_const;
2156 #if HOST_BITS_PER_WIDE_INT == 64
2157 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
2158 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
2159 #else
2160 negated_const = immed_double_const ((~low_bits) & 0xfffffc00,
2161 (~high_bits) & 0xffffffff,
2162 DImode);
2163 #endif
2164 sparc_emit_set_const64 (temp, negated_const);
2167 /* If we are XOR'ing with -1, then we should emit a one's complement
2168 instead. This way the combiner will notice logical operations
2169 such as ANDN later on and substitute. */
2170 if (trailing_bits == 0x3ff)
2172 emit_insn (gen_rtx_SET (VOIDmode, op0,
2173 gen_rtx_NOT (DImode, temp)));
2175 else
2177 emit_insn (gen_rtx_SET (VOIDmode,
2178 op0,
2179 gen_safe_XOR64 (temp,
2180 (-0x400 | trailing_bits))));
2182 return;
2185 /* 1) sethi %hi(xxx), %reg
2186 * or %reg, %lo(xxx), %reg
2187 * sllx %reg, yyy, %reg
2189 * ??? This is just a generalized version of the low_bits==0
2190 * thing above, FIXME...
2192 if ((highest_bit_set - lowest_bit_set) < 32)
2194 unsigned HOST_WIDE_INT focus_bits =
2195 create_simple_focus_bits (high_bits, low_bits,
2196 lowest_bit_set, 0);
2198 /* We can't get here in this state. */
2199 if (highest_bit_set < 32
2200 || lowest_bit_set >= 32)
2201 abort ();
2203 /* So what we know is that the set bits straddle the
2204 middle of the 64-bit word. */
2205 sparc_emit_set_const64_quick2 (op0, temp,
2206 focus_bits, 0,
2207 lowest_bit_set);
2208 return;
2211 /* 1) sethi %hi(high_bits), %reg
2212 * or %reg, %lo(high_bits), %reg
2213 * sllx %reg, 32, %reg
2214 * or %reg, low_bits, %reg
2216 if (SPARC_SIMM13_P(low_bits)
2217 && ((int)low_bits > 0))
2219 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2220 return;
2223 /* The easiest way when all else fails, is full decomposition. */
2224 #if 0
2225 printf ("sparc_emit_set_const64: Hard constant [%08lx%08lx] neg[%08lx%08lx]\n",
2226 high_bits, low_bits, ~high_bits, ~low_bits);
2227 #endif
2228 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2231 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2232 return the mode to be used for the comparison. For floating-point,
2233 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
2234 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2235 processing is needed. */
2237 enum machine_mode
2238 select_cc_mode (op, x, y)
2239 enum rtx_code op;
2240 rtx x;
2241 rtx y ATTRIBUTE_UNUSED;
2243 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2245 switch (op)
2247 case EQ:
2248 case NE:
2249 case UNORDERED:
2250 case ORDERED:
2251 case UNLT:
2252 case UNLE:
2253 case UNGT:
2254 case UNGE:
2255 case UNEQ:
2256 case LTGT:
2257 return CCFPmode;
2259 case LT:
2260 case LE:
2261 case GT:
2262 case GE:
2263 return CCFPEmode;
2265 default:
2266 abort ();
2269 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2270 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2272 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2273 return CCX_NOOVmode;
2274 else
2275 return CC_NOOVmode;
2277 else
2279 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2280 return CCXmode;
2281 else
2282 return CCmode;
2286 /* X and Y are two things to compare using CODE. Emit the compare insn and
2287 return the rtx for the cc reg in the proper mode. */
2290 gen_compare_reg (code, x, y)
2291 enum rtx_code code;
2292 rtx x, y;
2294 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
2295 rtx cc_reg;
2297 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2298 fcc regs (cse can't tell they're really call clobbered regs and will
2299 remove a duplicate comparison even if there is an intervening function
2300 call - it will then try to reload the cc reg via an int reg which is why
2301 we need the movcc patterns). It is possible to provide the movcc
2302 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2303 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2304 to tell cse that CCFPE mode registers (even pseudos) are call
2305 clobbered. */
2307 /* ??? This is an experiment. Rather than making changes to cse which may
2308 or may not be easy/clean, we do our own cse. This is possible because
2309 we will generate hard registers. Cse knows they're call clobbered (it
2310 doesn't know the same thing about pseudos). If we guess wrong, no big
2311 deal, but if we win, great! */
2313 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2314 #if 1 /* experiment */
2316 int reg;
2317 /* We cycle through the registers to ensure they're all exercised. */
2318 static int next_fcc_reg = 0;
2319 /* Previous x,y for each fcc reg. */
2320 static rtx prev_args[4][2];
2322 /* Scan prev_args for x,y. */
2323 for (reg = 0; reg < 4; reg++)
2324 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2325 break;
2326 if (reg == 4)
2328 reg = next_fcc_reg;
2329 prev_args[reg][0] = x;
2330 prev_args[reg][1] = y;
2331 next_fcc_reg = (next_fcc_reg + 1) & 3;
2333 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2335 #else
2336 cc_reg = gen_reg_rtx (mode);
2337 #endif /* ! experiment */
2338 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2339 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2340 else
2341 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2343 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2344 gen_rtx_COMPARE (mode, x, y)));
2346 return cc_reg;
2349 /* This function is used for v9 only.
2350 CODE is the code for an Scc's comparison.
2351 OPERANDS[0] is the target of the Scc insn.
2352 OPERANDS[1] is the value we compare against const0_rtx (which hasn't
2353 been generated yet).
2355 This function is needed to turn
2357 (set (reg:SI 110)
2358 (gt (reg:CCX 100 %icc)
2359 (const_int 0)))
2360 into
2361 (set (reg:SI 110)
2362 (gt:DI (reg:CCX 100 %icc)
2363 (const_int 0)))
2365 IE: The instruction recognizer needs to see the mode of the comparison to
2366 find the right instruction. We could use "gt:DI" right in the
2367 define_expand, but leaving it out allows us to handle DI, SI, etc.
2369 We refer to the global sparc compare operands sparc_compare_op0 and
2370 sparc_compare_op1. */
2373 gen_v9_scc (compare_code, operands)
2374 enum rtx_code compare_code;
2375 register rtx *operands;
2377 rtx temp, op0, op1;
2379 if (! TARGET_ARCH64
2380 && (GET_MODE (sparc_compare_op0) == DImode
2381 || GET_MODE (operands[0]) == DImode))
2382 return 0;
2384 op0 = sparc_compare_op0;
2385 op1 = sparc_compare_op1;
2387 /* Try to use the movrCC insns. */
2388 if (TARGET_ARCH64
2389 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
2390 && op1 == const0_rtx
2391 && v9_regcmp_p (compare_code))
2393 /* Special case for op0 != 0. This can be done with one instruction if
2394 operands[0] == sparc_compare_op0. */
2396 if (compare_code == NE
2397 && GET_MODE (operands[0]) == DImode
2398 && rtx_equal_p (op0, operands[0]))
2400 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2401 gen_rtx_IF_THEN_ELSE (DImode,
2402 gen_rtx_fmt_ee (compare_code, DImode,
2403 op0, const0_rtx),
2404 const1_rtx,
2405 operands[0])));
2406 return 1;
2409 if (reg_overlap_mentioned_p (operands[0], op0))
2411 /* Handle the case where operands[0] == sparc_compare_op0.
2412 We "early clobber" the result. */
2413 op0 = gen_reg_rtx (GET_MODE (sparc_compare_op0));
2414 emit_move_insn (op0, sparc_compare_op0);
2417 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2418 if (GET_MODE (op0) != DImode)
2420 temp = gen_reg_rtx (DImode);
2421 convert_move (temp, op0, 0);
2423 else
2424 temp = op0;
2425 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2426 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2427 gen_rtx_fmt_ee (compare_code, DImode,
2428 temp, const0_rtx),
2429 const1_rtx,
2430 operands[0])));
2431 return 1;
2433 else
2435 operands[1] = gen_compare_reg (compare_code, op0, op1);
2437 switch (GET_MODE (operands[1]))
2439 case CCmode :
2440 case CCXmode :
2441 case CCFPEmode :
2442 case CCFPmode :
2443 break;
2444 default :
2445 abort ();
2447 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2448 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2449 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2450 gen_rtx_fmt_ee (compare_code,
2451 GET_MODE (operands[1]),
2452 operands[1], const0_rtx),
2453 const1_rtx, operands[0])));
2454 return 1;
2458 /* Emit a conditional jump insn for the v9 architecture using comparison code
2459 CODE and jump target LABEL.
2460 This function exists to take advantage of the v9 brxx insns. */
2462 void
2463 emit_v9_brxx_insn (code, op0, label)
2464 enum rtx_code code;
2465 rtx op0, label;
2467 emit_jump_insn (gen_rtx_SET (VOIDmode,
2468 pc_rtx,
2469 gen_rtx_IF_THEN_ELSE (VOIDmode,
2470 gen_rtx_fmt_ee (code, GET_MODE (op0),
2471 op0, const0_rtx),
2472 gen_rtx_LABEL_REF (VOIDmode, label),
2473 pc_rtx)));
2476 /* Generate a DFmode part of a hard TFmode register.
2477 REG is the TFmode hard register, LOW is 1 for the
2478 low 64bit of the register and 0 otherwise.
2481 gen_df_reg (reg, low)
2482 rtx reg;
2483 int low;
2485 int regno = REGNO (reg);
2487 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
2488 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
2489 return gen_rtx_REG (DFmode, regno);
2492 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
2493 Unlike normal calls, TFmode operands are passed by reference. It is
2494 assumed that no more than 3 operands are required. */
2496 static void
2497 emit_soft_tfmode_libcall (func_name, nargs, operands)
2498 const char *func_name;
2499 int nargs;
2500 rtx *operands;
2502 rtx ret_slot = NULL, arg[3], func_sym;
2503 int i;
2505 /* We only expect to be called for conversions, unary, and binary ops. */
2506 if (nargs < 2 || nargs > 3)
2507 abort ();
2509 for (i = 0; i < nargs; ++i)
2511 rtx this_arg = operands[i];
2512 rtx this_slot;
2514 /* TFmode arguments and return values are passed by reference. */
2515 if (GET_MODE (this_arg) == TFmode)
2517 int force_stack_temp;
2519 force_stack_temp = 0;
2520 if (TARGET_BUGGY_QP_LIB && i == 0)
2521 force_stack_temp = 1;
2523 if (GET_CODE (this_arg) == MEM
2524 && ! force_stack_temp)
2525 this_arg = XEXP (this_arg, 0);
2526 else if (CONSTANT_P (this_arg)
2527 && ! force_stack_temp)
2529 this_slot = force_const_mem (TFmode, this_arg);
2530 this_arg = XEXP (this_slot, 0);
2532 else
2534 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode), 0);
2536 /* Operand 0 is the return value. We'll copy it out later. */
2537 if (i > 0)
2538 emit_move_insn (this_slot, this_arg);
2539 else
2540 ret_slot = this_slot;
2542 this_arg = XEXP (this_slot, 0);
2546 arg[i] = this_arg;
2549 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
2551 if (GET_MODE (operands[0]) == TFmode)
2553 if (nargs == 2)
2554 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
2555 arg[0], GET_MODE (arg[0]),
2556 arg[1], GET_MODE (arg[1]));
2557 else
2558 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
2559 arg[0], GET_MODE (arg[0]),
2560 arg[1], GET_MODE (arg[1]),
2561 arg[2], GET_MODE (arg[2]));
2563 if (ret_slot)
2564 emit_move_insn (operands[0], ret_slot);
2566 else
2568 rtx ret;
2570 if (nargs != 2)
2571 abort ();
2573 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
2574 GET_MODE (operands[0]), 1,
2575 arg[1], GET_MODE (arg[1]));
2577 if (ret != operands[0])
2578 emit_move_insn (operands[0], ret);
2582 /* Expand soft-float TFmode calls to sparc abi routines. */
2584 static void
2585 emit_soft_tfmode_binop (code, operands)
2586 enum rtx_code code;
2587 rtx *operands;
2589 const char *func;
2591 switch (code)
2593 case PLUS:
2594 func = "_Qp_add";
2595 break;
2596 case MINUS:
2597 func = "_Qp_sub";
2598 break;
2599 case MULT:
2600 func = "_Qp_mul";
2601 break;
2602 case DIV:
2603 func = "_Qp_div";
2604 break;
2605 default:
2606 abort ();
2609 emit_soft_tfmode_libcall (func, 3, operands);
2612 static void
2613 emit_soft_tfmode_unop (code, operands)
2614 enum rtx_code code;
2615 rtx *operands;
2617 const char *func;
2619 switch (code)
2621 case SQRT:
2622 func = "_Qp_sqrt";
2623 break;
2624 default:
2625 abort ();
2628 emit_soft_tfmode_libcall (func, 2, operands);
2631 static void
2632 emit_soft_tfmode_cvt (code, operands)
2633 enum rtx_code code;
2634 rtx *operands;
2636 const char *func;
2638 switch (code)
2640 case FLOAT_EXTEND:
2641 switch (GET_MODE (operands[1]))
2643 case SFmode:
2644 func = "_Qp_stoq";
2645 break;
2646 case DFmode:
2647 func = "_Qp_dtoq";
2648 break;
2649 default:
2650 abort ();
2652 break;
2654 case FLOAT_TRUNCATE:
2655 switch (GET_MODE (operands[0]))
2657 case SFmode:
2658 func = "_Qp_qtos";
2659 break;
2660 case DFmode:
2661 func = "_Qp_qtod";
2662 break;
2663 default:
2664 abort ();
2666 break;
2668 case FLOAT:
2669 switch (GET_MODE (operands[1]))
2671 case SImode:
2672 func = "_Qp_itoq";
2673 break;
2674 case DImode:
2675 func = "_Qp_xtoq";
2676 break;
2677 default:
2678 abort ();
2680 break;
2682 case UNSIGNED_FLOAT:
2683 switch (GET_MODE (operands[1]))
2685 case SImode:
2686 func = "_Qp_uitoq";
2687 break;
2688 case DImode:
2689 func = "_Qp_uxtoq";
2690 break;
2691 default:
2692 abort ();
2694 break;
2696 case FIX:
2697 switch (GET_MODE (operands[0]))
2699 case SImode:
2700 func = "_Qp_qtoi";
2701 break;
2702 case DImode:
2703 func = "_Qp_qtox";
2704 break;
2705 default:
2706 abort ();
2708 break;
2710 case UNSIGNED_FIX:
2711 switch (GET_MODE (operands[0]))
2713 case SImode:
2714 func = "_Qp_qtoui";
2715 break;
2716 case DImode:
2717 func = "_Qp_qtoux";
2718 break;
2719 default:
2720 abort ();
2722 break;
2724 default:
2725 abort ();
2728 emit_soft_tfmode_libcall (func, 2, operands);
2731 /* Expand a hard-float tfmode operation. All arguments must be in
2732 registers. */
2734 static void
2735 emit_hard_tfmode_operation (code, operands)
2736 enum rtx_code code;
2737 rtx *operands;
2739 rtx op, dest;
2741 if (GET_RTX_CLASS (code) == '1')
2743 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2744 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
2746 else
2748 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2749 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
2750 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
2751 operands[1], operands[2]);
2754 if (register_operand (operands[0], VOIDmode))
2755 dest = operands[0];
2756 else
2757 dest = gen_reg_rtx (GET_MODE (operands[0]));
2759 emit_insn (gen_rtx_SET (VOIDmode, dest, op));
2761 if (dest != operands[0])
2762 emit_move_insn (operands[0], dest);
2765 void
2766 emit_tfmode_binop (code, operands)
2767 enum rtx_code code;
2768 rtx *operands;
2770 if (TARGET_HARD_QUAD)
2771 emit_hard_tfmode_operation (code, operands);
2772 else
2773 emit_soft_tfmode_binop (code, operands);
2776 void
2777 emit_tfmode_unop (code, operands)
2778 enum rtx_code code;
2779 rtx *operands;
2781 if (TARGET_HARD_QUAD)
2782 emit_hard_tfmode_operation (code, operands);
2783 else
2784 emit_soft_tfmode_unop (code, operands);
2787 void
2788 emit_tfmode_cvt (code, operands)
2789 enum rtx_code code;
2790 rtx *operands;
2792 if (TARGET_HARD_QUAD)
2793 emit_hard_tfmode_operation (code, operands);
2794 else
2795 emit_soft_tfmode_cvt (code, operands);
2798 /* Return nonzero if a return peephole merging return with
2799 setting of output register is ok. */
2801 leaf_return_peephole_ok ()
2803 return (actual_fsize == 0);
2806 /* Return nonzero if a branch/jump/call instruction will be emitting
2807 nop into its delay slot. */
2810 empty_delay_slot (insn)
2811 rtx insn;
2813 rtx seq;
2815 /* If no previous instruction (should not happen), return true. */
2816 if (PREV_INSN (insn) == NULL)
2817 return 1;
2819 seq = NEXT_INSN (PREV_INSN (insn));
2820 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
2821 return 0;
2823 return 1;
2826 /* Return nonzero if TRIAL can go into the function epilogue's
2827 delay slot. SLOT is the slot we are trying to fill. */
2830 eligible_for_epilogue_delay (trial, slot)
2831 rtx trial;
2832 int slot;
2834 rtx pat, src;
2836 if (slot >= 1)
2837 return 0;
2839 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2840 return 0;
2842 if (get_attr_length (trial) != 1)
2843 return 0;
2845 /* If there are any call-saved registers, we should scan TRIAL if it
2846 does not reference them. For now just make it easy. */
2847 if (num_gfregs)
2848 return 0;
2850 /* If the function uses __builtin_eh_return, the eh_return machinery
2851 occupies the delay slot. */
2852 if (current_function_calls_eh_return)
2853 return 0;
2855 /* In the case of a true leaf function, anything can go into the delay slot.
2856 A delay slot only exists however if the frame size is zero, otherwise
2857 we will put an insn to adjust the stack after the return. */
2858 if (current_function_uses_only_leaf_regs)
2860 if (leaf_return_peephole_ok ())
2861 return ((get_attr_in_uncond_branch_delay (trial)
2862 == IN_BRANCH_DELAY_TRUE));
2863 return 0;
2866 pat = PATTERN (trial);
2868 /* Otherwise, only operations which can be done in tandem with
2869 a `restore' or `return' insn can go into the delay slot. */
2870 if (GET_CODE (SET_DEST (pat)) != REG
2871 || REGNO (SET_DEST (pat)) < 24)
2872 return 0;
2874 /* If this instruction sets up floating point register and we have a return
2875 instruction, it can probably go in. But restore will not work
2876 with FP_REGS. */
2877 if (REGNO (SET_DEST (pat)) >= 32)
2879 if (TARGET_V9 && ! epilogue_renumber (&pat, 1)
2880 && (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE))
2881 return 1;
2882 return 0;
2885 /* The set of insns matched here must agree precisely with the set of
2886 patterns paired with a RETURN in sparc.md. */
2888 src = SET_SRC (pat);
2890 /* This matches "*return_[qhs]i" or even "*return_di" on TARGET_ARCH64. */
2891 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2892 && arith_operand (src, GET_MODE (src)))
2894 if (TARGET_ARCH64)
2895 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2896 else
2897 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2900 /* This matches "*return_di". */
2901 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2902 && arith_double_operand (src, GET_MODE (src)))
2903 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2905 /* This matches "*return_sf_no_fpu". */
2906 else if (! TARGET_FPU && restore_operand (SET_DEST (pat), SFmode)
2907 && register_operand (src, SFmode))
2908 return 1;
2910 /* If we have return instruction, anything that does not use
2911 local or output registers and can go into a delay slot wins. */
2912 else if (TARGET_V9 && ! epilogue_renumber (&pat, 1)
2913 && (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE))
2914 return 1;
2916 /* This matches "*return_addsi". */
2917 else if (GET_CODE (src) == PLUS
2918 && arith_operand (XEXP (src, 0), SImode)
2919 && arith_operand (XEXP (src, 1), SImode)
2920 && (register_operand (XEXP (src, 0), SImode)
2921 || register_operand (XEXP (src, 1), SImode)))
2922 return 1;
2924 /* This matches "*return_adddi". */
2925 else if (GET_CODE (src) == PLUS
2926 && arith_double_operand (XEXP (src, 0), DImode)
2927 && arith_double_operand (XEXP (src, 1), DImode)
2928 && (register_operand (XEXP (src, 0), DImode)
2929 || register_operand (XEXP (src, 1), DImode)))
2930 return 1;
2932 /* This can match "*return_losum_[sd]i".
2933 Catch only some cases, so that return_losum* don't have
2934 to be too big. */
2935 else if (GET_CODE (src) == LO_SUM
2936 && ! TARGET_CM_MEDMID
2937 && ((register_operand (XEXP (src, 0), SImode)
2938 && immediate_operand (XEXP (src, 1), SImode))
2939 || (TARGET_ARCH64
2940 && register_operand (XEXP (src, 0), DImode)
2941 && immediate_operand (XEXP (src, 1), DImode))))
2942 return 1;
2944 /* sll{,x} reg,1,reg2 is add reg,reg,reg2 as well. */
2945 else if (GET_CODE (src) == ASHIFT
2946 && (register_operand (XEXP (src, 0), SImode)
2947 || register_operand (XEXP (src, 0), DImode))
2948 && XEXP (src, 1) == const1_rtx)
2949 return 1;
2951 return 0;
2954 /* Return nonzero if TRIAL can go into the sibling call
2955 delay slot. */
2958 eligible_for_sibcall_delay (trial)
2959 rtx trial;
2961 rtx pat, src;
2963 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2964 return 0;
2966 if (get_attr_length (trial) != 1)
2967 return 0;
2969 pat = PATTERN (trial);
2971 if (current_function_uses_only_leaf_regs)
2973 /* If the tail call is done using the call instruction,
2974 we have to restore %o7 in the delay slot. */
2975 if ((TARGET_ARCH64 && ! TARGET_CM_MEDLOW) || flag_pic)
2976 return 0;
2978 /* %g1 is used to build the function address */
2979 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
2980 return 0;
2982 return 1;
2985 /* Otherwise, only operations which can be done in tandem with
2986 a `restore' insn can go into the delay slot. */
2987 if (GET_CODE (SET_DEST (pat)) != REG
2988 || REGNO (SET_DEST (pat)) < 24
2989 || REGNO (SET_DEST (pat)) >= 32)
2990 return 0;
2992 /* If it mentions %o7, it can't go in, because sibcall will clobber it
2993 in most cases. */
2994 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
2995 return 0;
2997 src = SET_SRC (pat);
2999 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3000 && arith_operand (src, GET_MODE (src)))
3002 if (TARGET_ARCH64)
3003 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3004 else
3005 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
3008 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3009 && arith_double_operand (src, GET_MODE (src)))
3010 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3012 else if (! TARGET_FPU && restore_operand (SET_DEST (pat), SFmode)
3013 && register_operand (src, SFmode))
3014 return 1;
3016 else if (GET_CODE (src) == PLUS
3017 && arith_operand (XEXP (src, 0), SImode)
3018 && arith_operand (XEXP (src, 1), SImode)
3019 && (register_operand (XEXP (src, 0), SImode)
3020 || register_operand (XEXP (src, 1), SImode)))
3021 return 1;
3023 else if (GET_CODE (src) == PLUS
3024 && arith_double_operand (XEXP (src, 0), DImode)
3025 && arith_double_operand (XEXP (src, 1), DImode)
3026 && (register_operand (XEXP (src, 0), DImode)
3027 || register_operand (XEXP (src, 1), DImode)))
3028 return 1;
3030 else if (GET_CODE (src) == LO_SUM
3031 && ! TARGET_CM_MEDMID
3032 && ((register_operand (XEXP (src, 0), SImode)
3033 && immediate_operand (XEXP (src, 1), SImode))
3034 || (TARGET_ARCH64
3035 && register_operand (XEXP (src, 0), DImode)
3036 && immediate_operand (XEXP (src, 1), DImode))))
3037 return 1;
3039 else if (GET_CODE (src) == ASHIFT
3040 && (register_operand (XEXP (src, 0), SImode)
3041 || register_operand (XEXP (src, 0), DImode))
3042 && XEXP (src, 1) == const1_rtx)
3043 return 1;
3045 return 0;
3048 static int
3049 check_return_regs (x)
3050 rtx x;
3052 switch (GET_CODE (x))
3054 case REG:
3055 return IN_OR_GLOBAL_P (x);
3057 case CONST_INT:
3058 case CONST_DOUBLE:
3059 case CONST:
3060 case SYMBOL_REF:
3061 case LABEL_REF:
3062 return 1;
3064 case SET:
3065 case IOR:
3066 case AND:
3067 case XOR:
3068 case PLUS:
3069 case MINUS:
3070 if (check_return_regs (XEXP (x, 1)) == 0)
3071 return 0;
3072 case NOT:
3073 case NEG:
3074 case MEM:
3075 return check_return_regs (XEXP (x, 0));
3077 default:
3078 return 0;
3084 short_branch (uid1, uid2)
3085 int uid1, uid2;
3087 int delta = INSN_ADDRESSES (uid1) - INSN_ADDRESSES (uid2);
3089 /* Leave a few words of "slop". */
3090 if (delta >= -1023 && delta <= 1022)
3091 return 1;
3093 return 0;
3096 /* Return nonzero if REG is not used after INSN.
3097 We assume REG is a reload reg, and therefore does
3098 not live past labels or calls or jumps. */
3100 reg_unused_after (reg, insn)
3101 rtx reg;
3102 rtx insn;
3104 enum rtx_code code, prev_code = UNKNOWN;
3106 while ((insn = NEXT_INSN (insn)))
3108 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
3109 return 1;
3111 code = GET_CODE (insn);
3112 if (GET_CODE (insn) == CODE_LABEL)
3113 return 1;
3115 if (GET_RTX_CLASS (code) == 'i')
3117 rtx set = single_set (insn);
3118 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
3119 if (set && in_src)
3120 return 0;
3121 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
3122 return 1;
3123 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
3124 return 0;
3126 prev_code = code;
3128 return 1;
3131 /* The table we use to reference PIC data. */
3132 static GTY(()) rtx global_offset_table;
3134 /* The function we use to get at it. */
3135 static GTY(()) rtx get_pc_symbol;
3136 static char get_pc_symbol_name[256];
3138 /* Ensure that we are not using patterns that are not OK with PIC. */
3141 check_pic (i)
3142 int i;
3144 switch (flag_pic)
3146 case 1:
3147 if (GET_CODE (recog_data.operand[i]) == SYMBOL_REF
3148 || (GET_CODE (recog_data.operand[i]) == CONST
3149 && ! (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
3150 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
3151 == global_offset_table)
3152 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
3153 == CONST))))
3154 abort ();
3155 case 2:
3156 default:
3157 return 1;
3161 /* Return true if X is an address which needs a temporary register when
3162 reloaded while generating PIC code. */
3165 pic_address_needs_scratch (x)
3166 rtx x;
3168 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
3169 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3170 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
3171 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3172 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
3173 return 1;
3175 return 0;
3178 /* Legitimize PIC addresses. If the address is already position-independent,
3179 we return ORIG. Newly generated position-independent addresses go into a
3180 reg. This is REG if nonzero, otherwise we allocate register(s) as
3181 necessary. */
3184 legitimize_pic_address (orig, mode, reg)
3185 rtx orig;
3186 enum machine_mode mode ATTRIBUTE_UNUSED;
3187 rtx reg;
3189 if (GET_CODE (orig) == SYMBOL_REF)
3191 rtx pic_ref, address;
3192 rtx insn;
3194 if (reg == 0)
3196 if (reload_in_progress || reload_completed)
3197 abort ();
3198 else
3199 reg = gen_reg_rtx (Pmode);
3202 if (flag_pic == 2)
3204 /* If not during reload, allocate another temp reg here for loading
3205 in the address, so that these instructions can be optimized
3206 properly. */
3207 rtx temp_reg = ((reload_in_progress || reload_completed)
3208 ? reg : gen_reg_rtx (Pmode));
3210 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
3211 won't get confused into thinking that these two instructions
3212 are loading in the true address of the symbol. If in the
3213 future a PIC rtx exists, that should be used instead. */
3214 if (Pmode == SImode)
3216 emit_insn (gen_movsi_high_pic (temp_reg, orig));
3217 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
3219 else
3221 emit_insn (gen_movdi_high_pic (temp_reg, orig));
3222 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
3224 address = temp_reg;
3226 else
3227 address = orig;
3229 pic_ref = gen_rtx_MEM (Pmode,
3230 gen_rtx_PLUS (Pmode,
3231 pic_offset_table_rtx, address));
3232 current_function_uses_pic_offset_table = 1;
3233 RTX_UNCHANGING_P (pic_ref) = 1;
3234 insn = emit_move_insn (reg, pic_ref);
3235 /* Put a REG_EQUAL note on this insn, so that it can be optimized
3236 by loop. */
3237 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
3238 REG_NOTES (insn));
3239 return reg;
3241 else if (GET_CODE (orig) == CONST)
3243 rtx base, offset;
3245 if (GET_CODE (XEXP (orig, 0)) == PLUS
3246 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3247 return orig;
3249 if (reg == 0)
3251 if (reload_in_progress || reload_completed)
3252 abort ();
3253 else
3254 reg = gen_reg_rtx (Pmode);
3257 if (GET_CODE (XEXP (orig, 0)) == PLUS)
3259 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
3260 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
3261 base == reg ? 0 : reg);
3263 else
3264 abort ();
3266 if (GET_CODE (offset) == CONST_INT)
3268 if (SMALL_INT (offset))
3269 return plus_constant (base, INTVAL (offset));
3270 else if (! reload_in_progress && ! reload_completed)
3271 offset = force_reg (Pmode, offset);
3272 else
3273 /* If we reach here, then something is seriously wrong. */
3274 abort ();
3276 return gen_rtx_PLUS (Pmode, base, offset);
3278 else if (GET_CODE (orig) == LABEL_REF)
3279 /* ??? Why do we do this? */
3280 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
3281 the register is live instead, in case it is eliminated. */
3282 current_function_uses_pic_offset_table = 1;
3284 return orig;
3287 /* Emit special PIC prologues. */
3289 void
3290 load_pic_register ()
3292 /* Labels to get the PC in the prologue of this function. */
3293 int orig_flag_pic = flag_pic;
3295 if (! flag_pic)
3296 abort ();
3298 /* If we haven't emitted the special get_pc helper function, do so now. */
3299 if (get_pc_symbol_name[0] == 0)
3301 int align;
3303 ASM_GENERATE_INTERNAL_LABEL (get_pc_symbol_name, "LGETPC", 0);
3304 text_section ();
3306 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
3307 if (align > 0)
3308 ASM_OUTPUT_ALIGN (asm_out_file, align);
3309 (*targetm.asm_out.internal_label) (asm_out_file, "LGETPC", 0);
3310 fputs ("\tretl\n\tadd\t%o7, %l7, %l7\n", asm_out_file);
3313 /* Initialize every time through, since we can't easily
3314 know this to be permanent. */
3315 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3316 get_pc_symbol = gen_rtx_SYMBOL_REF (Pmode, get_pc_symbol_name);
3317 flag_pic = 0;
3319 emit_insn (gen_get_pc (pic_offset_table_rtx, global_offset_table,
3320 get_pc_symbol));
3322 flag_pic = orig_flag_pic;
3324 /* Need to emit this whether or not we obey regdecls,
3325 since setjmp/longjmp can cause life info to screw up.
3326 ??? In the case where we don't obey regdecls, this is not sufficient
3327 since we may not fall out the bottom. */
3328 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3331 /* Return 1 if RTX is a MEM which is known to be aligned to at
3332 least a DESIRED byte boundary. */
3335 mem_min_alignment (mem, desired)
3336 rtx mem;
3337 int desired;
3339 rtx addr, base, offset;
3341 /* If it's not a MEM we can't accept it. */
3342 if (GET_CODE (mem) != MEM)
3343 return 0;
3345 addr = XEXP (mem, 0);
3346 base = offset = NULL_RTX;
3347 if (GET_CODE (addr) == PLUS)
3349 if (GET_CODE (XEXP (addr, 0)) == REG)
3351 base = XEXP (addr, 0);
3353 /* What we are saying here is that if the base
3354 REG is aligned properly, the compiler will make
3355 sure any REG based index upon it will be so
3356 as well. */
3357 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3358 offset = XEXP (addr, 1);
3359 else
3360 offset = const0_rtx;
3363 else if (GET_CODE (addr) == REG)
3365 base = addr;
3366 offset = const0_rtx;
3369 if (base != NULL_RTX)
3371 int regno = REGNO (base);
3373 if (regno != HARD_FRAME_POINTER_REGNUM && regno != STACK_POINTER_REGNUM)
3375 /* Check if the compiler has recorded some information
3376 about the alignment of the base REG. If reload has
3377 completed, we already matched with proper alignments.
3378 If not running global_alloc, reload might give us
3379 unaligned pointer to local stack though. */
3380 if (((cfun != 0
3381 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
3382 || (optimize && reload_completed))
3383 && (INTVAL (offset) & (desired - 1)) == 0)
3384 return 1;
3386 else
3388 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
3389 return 1;
3392 else if (! TARGET_UNALIGNED_DOUBLES
3393 || CONSTANT_P (addr)
3394 || GET_CODE (addr) == LO_SUM)
3396 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
3397 is true, in which case we can only assume that an access is aligned if
3398 it is to a constant address, or the address involves a LO_SUM. */
3399 return 1;
3402 /* An obviously unaligned address. */
3403 return 0;
3407 /* Vectors to keep interesting information about registers where it can easily
3408 be got. We use to use the actual mode value as the bit number, but there
3409 are more than 32 modes now. Instead we use two tables: one indexed by
3410 hard register number, and one indexed by mode. */
3412 /* The purpose of sparc_mode_class is to shrink the range of modes so that
3413 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
3414 mapped into one sparc_mode_class mode. */
3416 enum sparc_mode_class {
3417 S_MODE, D_MODE, T_MODE, O_MODE,
3418 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
3419 CC_MODE, CCFP_MODE
3422 /* Modes for single-word and smaller quantities. */
3423 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
3425 /* Modes for double-word and smaller quantities. */
3426 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
3428 /* Modes for quad-word and smaller quantities. */
3429 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
3431 /* Modes for 8-word and smaller quantities. */
3432 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
3434 /* Modes for single-float quantities. We must allow any single word or
3435 smaller quantity. This is because the fix/float conversion instructions
3436 take integer inputs/outputs from the float registers. */
3437 #define SF_MODES (S_MODES)
3439 /* Modes for double-float and smaller quantities. */
3440 #define DF_MODES (S_MODES | D_MODES)
3442 /* Modes for double-float only quantities. */
3443 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
3445 /* Modes for quad-float only quantities. */
3446 #define TF_ONLY_MODES (1 << (int) TF_MODE)
3448 /* Modes for quad-float and smaller quantities. */
3449 #define TF_MODES (DF_MODES | TF_ONLY_MODES)
3451 /* Modes for quad-float and double-float quantities. */
3452 #define TF_MODES_NO_S (DF_MODES_NO_S | TF_ONLY_MODES)
3454 /* Modes for quad-float pair only quantities. */
3455 #define OF_ONLY_MODES (1 << (int) OF_MODE)
3457 /* Modes for quad-float pairs and smaller quantities. */
3458 #define OF_MODES (TF_MODES | OF_ONLY_MODES)
3460 #define OF_MODES_NO_S (TF_MODES_NO_S | OF_ONLY_MODES)
3462 /* Modes for condition codes. */
3463 #define CC_MODES (1 << (int) CC_MODE)
3464 #define CCFP_MODES (1 << (int) CCFP_MODE)
3466 /* Value is 1 if register/mode pair is acceptable on sparc.
3467 The funny mixture of D and T modes is because integer operations
3468 do not specially operate on tetra quantities, so non-quad-aligned
3469 registers can hold quadword quantities (except %o4 and %i4 because
3470 they cross fixed registers). */
3472 /* This points to either the 32 bit or the 64 bit version. */
3473 const int *hard_regno_mode_classes;
3475 static const int hard_32bit_mode_classes[] = {
3476 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3477 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3478 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3479 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3481 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3482 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3483 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3484 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3486 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3487 and none can hold SFmode/SImode values. */
3488 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3489 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3490 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3491 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3493 /* %fcc[0123] */
3494 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3496 /* %icc */
3497 CC_MODES
3500 static const int hard_64bit_mode_classes[] = {
3501 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3502 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3503 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3504 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3506 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3507 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3508 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3509 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3511 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3512 and none can hold SFmode/SImode values. */
3513 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3514 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3515 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3516 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3518 /* %fcc[0123] */
3519 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3521 /* %icc */
3522 CC_MODES
3525 int sparc_mode_class [NUM_MACHINE_MODES];
3527 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
3529 static void
3530 sparc_init_modes ()
3532 int i;
3534 for (i = 0; i < NUM_MACHINE_MODES; i++)
3536 switch (GET_MODE_CLASS (i))
3538 case MODE_INT:
3539 case MODE_PARTIAL_INT:
3540 case MODE_COMPLEX_INT:
3541 if (GET_MODE_SIZE (i) <= 4)
3542 sparc_mode_class[i] = 1 << (int) S_MODE;
3543 else if (GET_MODE_SIZE (i) == 8)
3544 sparc_mode_class[i] = 1 << (int) D_MODE;
3545 else if (GET_MODE_SIZE (i) == 16)
3546 sparc_mode_class[i] = 1 << (int) T_MODE;
3547 else if (GET_MODE_SIZE (i) == 32)
3548 sparc_mode_class[i] = 1 << (int) O_MODE;
3549 else
3550 sparc_mode_class[i] = 0;
3551 break;
3552 case MODE_FLOAT:
3553 case MODE_COMPLEX_FLOAT:
3554 if (GET_MODE_SIZE (i) <= 4)
3555 sparc_mode_class[i] = 1 << (int) SF_MODE;
3556 else if (GET_MODE_SIZE (i) == 8)
3557 sparc_mode_class[i] = 1 << (int) DF_MODE;
3558 else if (GET_MODE_SIZE (i) == 16)
3559 sparc_mode_class[i] = 1 << (int) TF_MODE;
3560 else if (GET_MODE_SIZE (i) == 32)
3561 sparc_mode_class[i] = 1 << (int) OF_MODE;
3562 else
3563 sparc_mode_class[i] = 0;
3564 break;
3565 case MODE_CC:
3566 default:
3567 /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so
3568 we must explicitly check for them here. */
3569 if (i == (int) CCFPmode || i == (int) CCFPEmode)
3570 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
3571 else if (i == (int) CCmode || i == (int) CC_NOOVmode
3572 || i == (int) CCXmode || i == (int) CCX_NOOVmode)
3573 sparc_mode_class[i] = 1 << (int) CC_MODE;
3574 else
3575 sparc_mode_class[i] = 0;
3576 break;
3580 if (TARGET_ARCH64)
3581 hard_regno_mode_classes = hard_64bit_mode_classes;
3582 else
3583 hard_regno_mode_classes = hard_32bit_mode_classes;
3585 /* Initialize the array used by REGNO_REG_CLASS. */
3586 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3588 if (i < 16 && TARGET_V8PLUS)
3589 sparc_regno_reg_class[i] = I64_REGS;
3590 else if (i < 32 || i == FRAME_POINTER_REGNUM)
3591 sparc_regno_reg_class[i] = GENERAL_REGS;
3592 else if (i < 64)
3593 sparc_regno_reg_class[i] = FP_REGS;
3594 else if (i < 96)
3595 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
3596 else if (i < 100)
3597 sparc_regno_reg_class[i] = FPCC_REGS;
3598 else
3599 sparc_regno_reg_class[i] = NO_REGS;
3603 /* Save non call used registers from LOW to HIGH at BASE+OFFSET.
3604 N_REGS is the number of 4-byte regs saved thus far. This applies even to
3605 v9 int regs as it simplifies the code. */
3607 static int
3608 save_regs (file, low, high, base, offset, n_regs, real_offset)
3609 FILE *file;
3610 int low, high;
3611 const char *base;
3612 int offset;
3613 int n_regs;
3614 int real_offset;
3616 int i;
3618 if (TARGET_ARCH64 && high <= 32)
3620 for (i = low; i < high; i++)
3622 if (regs_ever_live[i] && ! call_used_regs[i])
3624 fprintf (file, "\tstx\t%s, [%s+%d]\n",
3625 reg_names[i], base, offset + 4 * n_regs);
3626 if (dwarf2out_do_frame ())
3627 dwarf2out_reg_save ("", i, real_offset + 4 * n_regs);
3628 n_regs += 2;
3632 else
3634 for (i = low; i < high; i += 2)
3636 if (regs_ever_live[i] && ! call_used_regs[i])
3638 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3640 fprintf (file, "\tstd\t%s, [%s+%d]\n",
3641 reg_names[i], base, offset + 4 * n_regs);
3642 if (dwarf2out_do_frame ())
3644 char *l = dwarf2out_cfi_label ();
3645 dwarf2out_reg_save (l, i, real_offset + 4 * n_regs);
3646 dwarf2out_reg_save (l, i+1, real_offset + 4 * n_regs + 4);
3648 n_regs += 2;
3650 else
3652 fprintf (file, "\tst\t%s, [%s+%d]\n",
3653 reg_names[i], base, offset + 4 * n_regs);
3654 if (dwarf2out_do_frame ())
3655 dwarf2out_reg_save ("", i, real_offset + 4 * n_regs);
3656 n_regs += 2;
3659 else
3661 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3663 fprintf (file, "\tst\t%s, [%s+%d]\n",
3664 reg_names[i+1], base, offset + 4 * n_regs + 4);
3665 if (dwarf2out_do_frame ())
3666 dwarf2out_reg_save ("", i + 1, real_offset + 4 * n_regs + 4);
3667 n_regs += 2;
3672 return n_regs;
3675 /* Restore non call used registers from LOW to HIGH at BASE+OFFSET.
3677 N_REGS is the number of 4-byte regs saved thus far. This applies even to
3678 v9 int regs as it simplifies the code. */
3680 static int
3681 restore_regs (file, low, high, base, offset, n_regs)
3682 FILE *file;
3683 int low, high;
3684 const char *base;
3685 int offset;
3686 int n_regs;
3688 int i;
3690 if (TARGET_ARCH64 && high <= 32)
3692 for (i = low; i < high; i++)
3694 if (regs_ever_live[i] && ! call_used_regs[i])
3695 fprintf (file, "\tldx\t[%s+%d], %s\n",
3696 base, offset + 4 * n_regs, reg_names[i]),
3697 n_regs += 2;
3700 else
3702 for (i = low; i < high; i += 2)
3704 if (regs_ever_live[i] && ! call_used_regs[i])
3705 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3706 fprintf (file, "\tldd\t[%s+%d], %s\n",
3707 base, offset + 4 * n_regs, reg_names[i]),
3708 n_regs += 2;
3709 else
3710 fprintf (file, "\tld\t[%s+%d], %s\n",
3711 base, offset + 4 * n_regs, reg_names[i]),
3712 n_regs += 2;
3713 else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3714 fprintf (file, "\tld\t[%s+%d], %s\n",
3715 base, offset + 4 * n_regs + 4, reg_names[i+1]),
3716 n_regs += 2;
3719 return n_regs;
3722 /* Compute the frame size required by the function. This function is called
3723 during the reload pass and also by output_function_prologue(). */
3726 compute_frame_size (size, leaf_function)
3727 int size;
3728 int leaf_function;
3730 int n_regs = 0, i;
3731 int outgoing_args_size = (current_function_outgoing_args_size
3732 + REG_PARM_STACK_SPACE (current_function_decl));
3734 /* N_REGS is the number of 4-byte regs saved thus far. This applies
3735 even to v9 int regs to be consistent with save_regs/restore_regs. */
3737 if (TARGET_ARCH64)
3739 for (i = 0; i < 8; i++)
3740 if (regs_ever_live[i] && ! call_used_regs[i])
3741 n_regs += 2;
3743 else
3745 for (i = 0; i < 8; i += 2)
3746 if ((regs_ever_live[i] && ! call_used_regs[i])
3747 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3748 n_regs += 2;
3751 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
3752 if ((regs_ever_live[i] && ! call_used_regs[i])
3753 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3754 n_regs += 2;
3756 /* Set up values for use in `function_epilogue'. */
3757 num_gfregs = n_regs;
3759 if (leaf_function && n_regs == 0
3760 && size == 0 && current_function_outgoing_args_size == 0)
3762 actual_fsize = apparent_fsize = 0;
3764 else
3766 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
3767 apparent_fsize = (size - STARTING_FRAME_OFFSET + 7) & -8;
3768 apparent_fsize += n_regs * 4;
3769 actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
3772 /* Make sure nothing can clobber our register windows.
3773 If a SAVE must be done, or there is a stack-local variable,
3774 the register window area must be allocated.
3775 ??? For v8 we apparently need an additional 8 bytes of reserved space. */
3776 if (leaf_function == 0 || size > 0)
3777 actual_fsize += (16 * UNITS_PER_WORD) + (TARGET_ARCH64 ? 0 : 8);
3779 return SPARC_STACK_ALIGN (actual_fsize);
3782 /* Build a (32 bit) big number in a register. */
3783 /* ??? We may be able to use the set macro here too. */
3785 static void
3786 build_big_number (file, num, reg)
3787 FILE *file;
3788 int num;
3789 const char *reg;
3791 if (num >= 0 || ! TARGET_ARCH64)
3793 fprintf (file, "\tsethi\t%%hi(%d), %s\n", num, reg);
3794 if ((num & 0x3ff) != 0)
3795 fprintf (file, "\tor\t%s, %%lo(%d), %s\n", reg, num, reg);
3797 else /* num < 0 && TARGET_ARCH64 */
3799 /* Sethi does not sign extend, so we must use a little trickery
3800 to use it for negative numbers. Invert the constant before
3801 loading it in, then use xor immediate to invert the loaded bits
3802 (along with the upper 32 bits) to the desired constant. This
3803 works because the sethi and immediate fields overlap. */
3804 int asize = num;
3805 int inv = ~asize;
3806 int low = -0x400 + (asize & 0x3FF);
3808 fprintf (file, "\tsethi\t%%hi(%d), %s\n\txor\t%s, %d, %s\n",
3809 inv, reg, reg, low, reg);
3813 /* Output any necessary .register pseudo-ops. */
3814 void
3815 sparc_output_scratch_registers (file)
3816 FILE *file ATTRIBUTE_UNUSED;
3818 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
3819 int i;
3821 if (TARGET_ARCH32)
3822 return;
3824 /* Check if %g[2367] were used without
3825 .register being printed for them already. */
3826 for (i = 2; i < 8; i++)
3828 if (regs_ever_live [i]
3829 && ! sparc_hard_reg_printed [i])
3831 sparc_hard_reg_printed [i] = 1;
3832 fprintf (file, "\t.register\t%%g%d, #scratch\n", i);
3834 if (i == 3) i = 5;
3836 #endif
3839 /* This function generates the assembly code for function entry.
3840 FILE is a stdio stream to output the code to.
3841 SIZE is an int: how many units of temporary storage to allocate.
3842 Refer to the array `regs_ever_live' to determine which registers
3843 to save; `regs_ever_live[I]' is nonzero if register number I
3844 is ever used in the function. This macro is responsible for
3845 knowing which registers should not be saved even if used. */
3847 /* On SPARC, move-double insns between fpu and cpu need an 8-byte block
3848 of memory. If any fpu reg is used in the function, we allocate
3849 such a block here, at the bottom of the frame, just in case it's needed.
3851 If this function is a leaf procedure, then we may choose not
3852 to do a "save" insn. The decision about whether or not
3853 to do this is made in regclass.c. */
3855 static void
3856 sparc_output_function_prologue (file, size)
3857 FILE *file;
3858 HOST_WIDE_INT size;
3860 if (TARGET_FLAT)
3861 sparc_flat_function_prologue (file, size);
3862 else
3863 sparc_nonflat_function_prologue (file, size,
3864 current_function_uses_only_leaf_regs);
3867 /* Output code for the function prologue. */
3869 static void
3870 sparc_nonflat_function_prologue (file, size, leaf_function)
3871 FILE *file;
3872 HOST_WIDE_INT size;
3873 int leaf_function;
3875 sparc_output_scratch_registers (file);
3877 /* Need to use actual_fsize, since we are also allocating
3878 space for our callee (and our own register save area). */
3879 actual_fsize = compute_frame_size (size, leaf_function);
3881 if (leaf_function)
3883 frame_base_name = "%sp";
3884 frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
3886 else
3888 frame_base_name = "%fp";
3889 frame_base_offset = SPARC_STACK_BIAS;
3892 /* This is only for the human reader. */
3893 fprintf (file, "\t%s#PROLOGUE# 0\n", ASM_COMMENT_START);
3895 if (actual_fsize == 0)
3896 /* do nothing. */ ;
3897 else if (! leaf_function)
3899 if (actual_fsize <= 4096)
3900 fprintf (file, "\tsave\t%%sp, -%d, %%sp\n", actual_fsize);
3901 else if (actual_fsize <= 8192)
3903 fprintf (file, "\tsave\t%%sp, -4096, %%sp\n");
3904 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize - 4096);
3906 else
3908 build_big_number (file, -actual_fsize, "%g1");
3909 fprintf (file, "\tsave\t%%sp, %%g1, %%sp\n");
3912 else /* leaf function */
3914 if (actual_fsize <= 4096)
3915 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize);
3916 else if (actual_fsize <= 8192)
3918 fprintf (file, "\tadd\t%%sp, -4096, %%sp\n");
3919 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize - 4096);
3921 else
3923 build_big_number (file, -actual_fsize, "%g1");
3924 fprintf (file, "\tadd\t%%sp, %%g1, %%sp\n");
3928 if (dwarf2out_do_frame () && actual_fsize)
3930 char *label = dwarf2out_cfi_label ();
3932 /* The canonical frame address refers to the top of the frame. */
3933 dwarf2out_def_cfa (label, (leaf_function ? STACK_POINTER_REGNUM
3934 : HARD_FRAME_POINTER_REGNUM),
3935 frame_base_offset);
3937 if (! leaf_function)
3939 /* Note the register window save. This tells the unwinder that
3940 it needs to restore the window registers from the previous
3941 frame's window save area at 0(cfa). */
3942 dwarf2out_window_save (label);
3944 /* The return address (-8) is now in %i7. */
3945 dwarf2out_return_reg (label, 31);
3949 /* If doing anything with PIC, do it now. */
3950 if (! flag_pic)
3951 fprintf (file, "\t%s#PROLOGUE# 1\n", ASM_COMMENT_START);
3953 /* Call saved registers are saved just above the outgoing argument area. */
3954 if (num_gfregs)
3956 int offset, real_offset, n_regs;
3957 const char *base;
3959 real_offset = -apparent_fsize;
3960 offset = -apparent_fsize + frame_base_offset;
3961 if (offset < -4096 || offset + num_gfregs * 4 > 4096)
3963 /* ??? This might be optimized a little as %g1 might already have a
3964 value close enough that a single add insn will do. */
3965 /* ??? Although, all of this is probably only a temporary fix
3966 because if %g1 can hold a function result, then
3967 output_function_epilogue will lose (the result will get
3968 clobbered). */
3969 build_big_number (file, offset, "%g1");
3970 fprintf (file, "\tadd\t%s, %%g1, %%g1\n", frame_base_name);
3971 base = "%g1";
3972 offset = 0;
3974 else
3976 base = frame_base_name;
3979 n_regs = save_regs (file, 0, 8, base, offset, 0, real_offset);
3980 save_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs,
3981 real_offset);
3985 /* Output code to restore any call saved registers. */
3987 static void
3988 output_restore_regs (file, leaf_function)
3989 FILE *file;
3990 int leaf_function ATTRIBUTE_UNUSED;
3992 int offset, n_regs;
3993 const char *base;
3995 offset = -apparent_fsize + frame_base_offset;
3996 if (offset < -4096 || offset + num_gfregs * 4 > 4096 - 8 /*double*/)
3998 build_big_number (file, offset, "%g1");
3999 fprintf (file, "\tadd\t%s, %%g1, %%g1\n", frame_base_name);
4000 base = "%g1";
4001 offset = 0;
4003 else
4005 base = frame_base_name;
4008 n_regs = restore_regs (file, 0, 8, base, offset, 0);
4009 restore_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs);
4012 /* This function generates the assembly code for function exit,
4013 on machines that need it.
4015 The function epilogue should not depend on the current stack pointer!
4016 It should use the frame pointer only. This is mandatory because
4017 of alloca; we also take advantage of it to omit stack adjustments
4018 before returning. */
4020 static void
4021 sparc_output_function_epilogue (file, size)
4022 FILE *file;
4023 HOST_WIDE_INT size;
4025 if (TARGET_FLAT)
4026 sparc_flat_function_epilogue (file, size);
4027 else
4028 sparc_nonflat_function_epilogue (file, size,
4029 current_function_uses_only_leaf_regs);
4032 /* Output code for the function epilogue. */
4034 static void
4035 sparc_nonflat_function_epilogue (file, size, leaf_function)
4036 FILE *file;
4037 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
4038 int leaf_function;
4040 const char *ret;
4042 if (current_function_epilogue_delay_list == 0)
4044 /* If code does not drop into the epilogue, we need
4045 do nothing except output pending case vectors.
4047 We have to still output a dummy nop for the sake of
4048 sane backtraces. Otherwise, if the last two instructions
4049 of a function were call foo; dslot; this can make the return
4050 PC of foo (ie. address of call instruction plus 8) point to
4051 the first instruction in the next function. */
4052 rtx insn;
4054 fputs("\tnop\n", file);
4056 insn = get_last_insn ();
4057 if (GET_CODE (insn) == NOTE)
4058 insn = prev_nonnote_insn (insn);
4059 if (insn && GET_CODE (insn) == BARRIER)
4060 goto output_vectors;
4063 if (num_gfregs)
4064 output_restore_regs (file, leaf_function);
4066 /* Work out how to skip the caller's unimp instruction if required. */
4067 if (leaf_function)
4068 ret = (SKIP_CALLERS_UNIMP_P ? "jmp\t%o7+12" : "retl");
4069 else
4070 ret = (SKIP_CALLERS_UNIMP_P ? "jmp\t%i7+12" : "ret");
4072 if (! leaf_function)
4074 if (current_function_calls_eh_return)
4076 if (current_function_epilogue_delay_list)
4077 abort ();
4078 if (SKIP_CALLERS_UNIMP_P)
4079 abort ();
4081 fputs ("\trestore\n\tretl\n\tadd\t%sp, %g1, %sp\n", file);
4083 /* If we wound up with things in our delay slot, flush them here. */
4084 else if (current_function_epilogue_delay_list)
4086 rtx delay = PATTERN (XEXP (current_function_epilogue_delay_list, 0));
4088 if (TARGET_V9 && ! epilogue_renumber (&delay, 1))
4090 epilogue_renumber (&delay, 0);
4091 fputs (SKIP_CALLERS_UNIMP_P
4092 ? "\treturn\t%i7+12\n"
4093 : "\treturn\t%i7+8\n", file);
4094 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
4095 file, 1, 0, 0);
4097 else
4099 rtx insn, src;
4101 if (GET_CODE (delay) != SET)
4102 abort();
4104 src = SET_SRC (delay);
4105 if (GET_CODE (src) == ASHIFT)
4107 if (XEXP (src, 1) != const1_rtx)
4108 abort();
4109 SET_SRC (delay)
4110 = gen_rtx_PLUS (GET_MODE (src), XEXP (src, 0),
4111 XEXP (src, 0));
4114 insn = gen_rtx_PARALLEL (VOIDmode,
4115 gen_rtvec (2, delay,
4116 gen_rtx_RETURN (VOIDmode)));
4117 insn = emit_jump_insn (insn);
4119 sparc_emitting_epilogue = true;
4120 final_scan_insn (insn, file, 1, 0, 1);
4121 sparc_emitting_epilogue = false;
4124 else if (TARGET_V9 && ! SKIP_CALLERS_UNIMP_P)
4125 fputs ("\treturn\t%i7+8\n\tnop\n", file);
4126 else
4127 fprintf (file, "\t%s\n\trestore\n", ret);
4129 /* All of the following cases are for leaf functions. */
4130 else if (current_function_calls_eh_return)
4131 abort ();
4132 else if (current_function_epilogue_delay_list)
4134 /* eligible_for_epilogue_delay_slot ensures that if this is a
4135 leaf function, then we will only have insn in the delay slot
4136 if the frame size is zero, thus no adjust for the stack is
4137 needed here. */
4138 if (actual_fsize != 0)
4139 abort ();
4140 fprintf (file, "\t%s\n", ret);
4141 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
4142 file, 1, 0, 1);
4144 /* Output 'nop' instead of 'sub %sp,-0,%sp' when no frame, so as to
4145 avoid generating confusing assembly language output. */
4146 else if (actual_fsize == 0)
4147 fprintf (file, "\t%s\n\tnop\n", ret);
4148 else if (actual_fsize <= 4096)
4149 fprintf (file, "\t%s\n\tsub\t%%sp, -%d, %%sp\n", ret, actual_fsize);
4150 else if (actual_fsize <= 8192)
4151 fprintf (file, "\tsub\t%%sp, -4096, %%sp\n\t%s\n\tsub\t%%sp, -%d, %%sp\n",
4152 ret, actual_fsize - 4096);
4153 else if ((actual_fsize & 0x3ff) == 0)
4154 fprintf (file, "\tsethi\t%%hi(%d), %%g1\n\t%s\n\tadd\t%%sp, %%g1, %%sp\n",
4155 actual_fsize, ret);
4156 else
4157 fprintf (file, "\tsethi\t%%hi(%d), %%g1\n\tor\t%%g1, %%lo(%d), %%g1\n\t%s\n\tadd\t%%sp, %%g1, %%sp\n",
4158 actual_fsize, actual_fsize, ret);
4160 output_vectors:
4161 sparc_output_deferred_case_vectors ();
4164 /* Output a sibling call. */
4166 const char *
4167 output_sibcall (insn, call_operand)
4168 rtx insn, call_operand;
4170 int leaf_regs = current_function_uses_only_leaf_regs;
4171 rtx operands[3];
4172 int delay_slot = dbr_sequence_length () > 0;
4174 if (num_gfregs)
4176 /* Call to restore global regs might clobber
4177 the delay slot. Instead of checking for this
4178 output the delay slot now. */
4179 if (delay_slot)
4181 rtx delay = NEXT_INSN (insn);
4183 if (! delay)
4184 abort ();
4186 final_scan_insn (delay, asm_out_file, 1, 0, 1);
4187 PATTERN (delay) = gen_blockage ();
4188 INSN_CODE (delay) = -1;
4189 delay_slot = 0;
4191 output_restore_regs (asm_out_file, leaf_regs);
4194 operands[0] = call_operand;
4196 if (leaf_regs)
4198 #ifdef HAVE_AS_RELAX_OPTION
4199 /* If as and ld are relaxing tail call insns into branch always,
4200 use or %o7,%g0,X; call Y; or X,%g0,%o7 always, so that it can
4201 be optimized. With sethi/jmpl as nor ld has no easy way how to
4202 find out if somebody does not branch between the sethi and jmpl. */
4203 int spare_slot = 0;
4204 #else
4205 int spare_slot = ((TARGET_ARCH32 || TARGET_CM_MEDLOW) && ! flag_pic);
4206 #endif
4207 int size = 0;
4209 if ((actual_fsize || ! spare_slot) && delay_slot)
4211 rtx delay = NEXT_INSN (insn);
4213 if (! delay)
4214 abort ();
4216 final_scan_insn (delay, asm_out_file, 1, 0, 1);
4217 PATTERN (delay) = gen_blockage ();
4218 INSN_CODE (delay) = -1;
4219 delay_slot = 0;
4221 if (actual_fsize)
4223 if (actual_fsize <= 4096)
4224 size = actual_fsize;
4225 else if (actual_fsize <= 8192)
4227 fputs ("\tsub\t%sp, -4096, %sp\n", asm_out_file);
4228 size = actual_fsize - 4096;
4230 else if ((actual_fsize & 0x3ff) == 0)
4231 fprintf (asm_out_file,
4232 "\tsethi\t%%hi(%d), %%g1\n\tadd\t%%sp, %%g1, %%sp\n",
4233 actual_fsize);
4234 else
4236 fprintf (asm_out_file,
4237 "\tsethi\t%%hi(%d), %%g1\n\tor\t%%g1, %%lo(%d), %%g1\n",
4238 actual_fsize, actual_fsize);
4239 fputs ("\tadd\t%%sp, %%g1, %%sp\n", asm_out_file);
4242 if (spare_slot)
4244 output_asm_insn ("sethi\t%%hi(%a0), %%g1", operands);
4245 output_asm_insn ("jmpl\t%%g1 + %%lo(%a0), %%g0", operands);
4246 if (size)
4247 fprintf (asm_out_file, "\t sub\t%%sp, -%d, %%sp\n", size);
4248 else if (! delay_slot)
4249 fputs ("\t nop\n", asm_out_file);
4251 else
4253 if (size)
4254 fprintf (asm_out_file, "\tsub\t%%sp, -%d, %%sp\n", size);
4255 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
4256 it into branch if possible. */
4257 output_asm_insn ("or\t%%o7, %%g0, %%g1", operands);
4258 output_asm_insn ("call\t%a0, 0", operands);
4259 output_asm_insn (" or\t%%g1, %%g0, %%o7", operands);
4261 return "";
4264 output_asm_insn ("call\t%a0, 0", operands);
4265 if (delay_slot)
4267 rtx delay = NEXT_INSN (insn), pat;
4269 if (! delay)
4270 abort ();
4272 pat = PATTERN (delay);
4273 if (GET_CODE (pat) != SET)
4274 abort ();
4276 operands[0] = SET_DEST (pat);
4277 pat = SET_SRC (pat);
4278 switch (GET_CODE (pat))
4280 case PLUS:
4281 operands[1] = XEXP (pat, 0);
4282 operands[2] = XEXP (pat, 1);
4283 output_asm_insn (" restore %r1, %2, %Y0", operands);
4284 break;
4285 case LO_SUM:
4286 operands[1] = XEXP (pat, 0);
4287 operands[2] = XEXP (pat, 1);
4288 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
4289 break;
4290 case ASHIFT:
4291 operands[1] = XEXP (pat, 0);
4292 output_asm_insn (" restore %r1, %r1, %Y0", operands);
4293 break;
4294 default:
4295 operands[1] = pat;
4296 output_asm_insn (" restore %%g0, %1, %Y0", operands);
4297 break;
4299 PATTERN (delay) = gen_blockage ();
4300 INSN_CODE (delay) = -1;
4302 else
4303 fputs ("\t restore\n", asm_out_file);
4304 return "";
4307 /* Functions for handling argument passing.
4309 For v8 the first six args are normally in registers and the rest are
4310 pushed. Any arg that starts within the first 6 words is at least
4311 partially passed in a register unless its data type forbids.
4313 For v9, the argument registers are laid out as an array of 16 elements
4314 and arguments are added sequentially. The first 6 int args and up to the
4315 first 16 fp args (depending on size) are passed in regs.
4317 Slot Stack Integral Float Float in structure Double Long Double
4318 ---- ----- -------- ----- ------------------ ------ -----------
4319 15 [SP+248] %f31 %f30,%f31 %d30
4320 14 [SP+240] %f29 %f28,%f29 %d28 %q28
4321 13 [SP+232] %f27 %f26,%f27 %d26
4322 12 [SP+224] %f25 %f24,%f25 %d24 %q24
4323 11 [SP+216] %f23 %f22,%f23 %d22
4324 10 [SP+208] %f21 %f20,%f21 %d20 %q20
4325 9 [SP+200] %f19 %f18,%f19 %d18
4326 8 [SP+192] %f17 %f16,%f17 %d16 %q16
4327 7 [SP+184] %f15 %f14,%f15 %d14
4328 6 [SP+176] %f13 %f12,%f13 %d12 %q12
4329 5 [SP+168] %o5 %f11 %f10,%f11 %d10
4330 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
4331 3 [SP+152] %o3 %f7 %f6,%f7 %d6
4332 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
4333 1 [SP+136] %o1 %f3 %f2,%f3 %d2
4334 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
4336 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
4338 Integral arguments are always passed as 64 bit quantities appropriately
4339 extended.
4341 Passing of floating point values is handled as follows.
4342 If a prototype is in scope:
4343 If the value is in a named argument (i.e. not a stdarg function or a
4344 value not part of the `...') then the value is passed in the appropriate
4345 fp reg.
4346 If the value is part of the `...' and is passed in one of the first 6
4347 slots then the value is passed in the appropriate int reg.
4348 If the value is part of the `...' and is not passed in one of the first 6
4349 slots then the value is passed in memory.
4350 If a prototype is not in scope:
4351 If the value is one of the first 6 arguments the value is passed in the
4352 appropriate integer reg and the appropriate fp reg.
4353 If the value is not one of the first 6 arguments the value is passed in
4354 the appropriate fp reg and in memory.
4357 /* Maximum number of int regs for args. */
4358 #define SPARC_INT_ARG_MAX 6
4359 /* Maximum number of fp regs for args. */
4360 #define SPARC_FP_ARG_MAX 16
4362 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
4364 /* Handle the INIT_CUMULATIVE_ARGS macro.
4365 Initialize a variable CUM of type CUMULATIVE_ARGS
4366 for a call to a function whose data type is FNTYPE.
4367 For a library call, FNTYPE is 0. */
4369 void
4370 init_cumulative_args (cum, fntype, libname, fndecl)
4371 CUMULATIVE_ARGS *cum;
4372 tree fntype;
4373 rtx libname ATTRIBUTE_UNUSED;
4374 tree fndecl ATTRIBUTE_UNUSED;
4376 cum->words = 0;
4377 cum->prototype_p = fntype && TYPE_ARG_TYPES (fntype);
4378 cum->libcall_p = fntype == 0;
4381 /* Compute the slot number to pass an argument in.
4382 Returns the slot number or -1 if passing on the stack.
4384 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4385 the preceding args and about the function being called.
4386 MODE is the argument's machine mode.
4387 TYPE is the data type of the argument (as a tree).
4388 This is null for libcalls where that information may
4389 not be available.
4390 NAMED is nonzero if this argument is a named parameter
4391 (otherwise it is an extra parameter matching an ellipsis).
4392 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
4393 *PREGNO records the register number to use if scalar type.
4394 *PPADDING records the amount of padding needed in words. */
4396 static int
4397 function_arg_slotno (cum, mode, type, named, incoming_p, pregno, ppadding)
4398 const CUMULATIVE_ARGS *cum;
4399 enum machine_mode mode;
4400 tree type;
4401 int named;
4402 int incoming_p;
4403 int *pregno;
4404 int *ppadding;
4406 int regbase = (incoming_p
4407 ? SPARC_INCOMING_INT_ARG_FIRST
4408 : SPARC_OUTGOING_INT_ARG_FIRST);
4409 int slotno = cum->words;
4410 int regno;
4412 *ppadding = 0;
4414 if (type != 0 && TREE_ADDRESSABLE (type))
4415 return -1;
4416 if (TARGET_ARCH32
4417 && type != 0 && mode == BLKmode
4418 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
4419 return -1;
4421 switch (mode)
4423 case VOIDmode :
4424 /* MODE is VOIDmode when generating the actual call.
4425 See emit_call_1. */
4426 return -1;
4428 case QImode : case CQImode :
4429 case HImode : case CHImode :
4430 case SImode : case CSImode :
4431 case DImode : case CDImode :
4432 case TImode : case CTImode :
4433 if (slotno >= SPARC_INT_ARG_MAX)
4434 return -1;
4435 regno = regbase + slotno;
4436 break;
4438 case SFmode : case SCmode :
4439 case DFmode : case DCmode :
4440 case TFmode : case TCmode :
4441 if (TARGET_ARCH32)
4443 if (slotno >= SPARC_INT_ARG_MAX)
4444 return -1;
4445 regno = regbase + slotno;
4447 else
4449 if ((mode == TFmode || mode == TCmode)
4450 && (slotno & 1) != 0)
4451 slotno++, *ppadding = 1;
4452 if (TARGET_FPU && named)
4454 if (slotno >= SPARC_FP_ARG_MAX)
4455 return -1;
4456 regno = SPARC_FP_ARG_FIRST + slotno * 2;
4457 if (mode == SFmode)
4458 regno++;
4460 else
4462 if (slotno >= SPARC_INT_ARG_MAX)
4463 return -1;
4464 regno = regbase + slotno;
4467 break;
4469 case BLKmode :
4470 /* For sparc64, objects requiring 16 byte alignment get it. */
4471 if (TARGET_ARCH64)
4473 if (type && TYPE_ALIGN (type) == 128 && (slotno & 1) != 0)
4474 slotno++, *ppadding = 1;
4477 if (TARGET_ARCH32
4478 || (type && TREE_CODE (type) == UNION_TYPE))
4480 if (slotno >= SPARC_INT_ARG_MAX)
4481 return -1;
4482 regno = regbase + slotno;
4484 else
4486 tree field;
4487 int intregs_p = 0, fpregs_p = 0;
4488 /* The ABI obviously doesn't specify how packed
4489 structures are passed. These are defined to be passed
4490 in int regs if possible, otherwise memory. */
4491 int packed_p = 0;
4493 /* First see what kinds of registers we need. */
4494 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4496 if (TREE_CODE (field) == FIELD_DECL)
4498 if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4499 && TARGET_FPU)
4500 fpregs_p = 1;
4501 else
4502 intregs_p = 1;
4503 if (DECL_PACKED (field))
4504 packed_p = 1;
4507 if (packed_p || !named)
4508 fpregs_p = 0, intregs_p = 1;
4510 /* If all arg slots are filled, then must pass on stack. */
4511 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
4512 return -1;
4513 /* If there are only int args and all int arg slots are filled,
4514 then must pass on stack. */
4515 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
4516 return -1;
4517 /* Note that even if all int arg slots are filled, fp members may
4518 still be passed in regs if such regs are available.
4519 *PREGNO isn't set because there may be more than one, it's up
4520 to the caller to compute them. */
4521 return slotno;
4523 break;
4525 default :
4526 abort ();
4529 *pregno = regno;
4530 return slotno;
4533 /* Handle recursive register counting for structure field layout. */
4535 struct function_arg_record_value_parms
4537 rtx ret;
4538 int slotno, named, regbase;
4539 unsigned int nregs;
4540 int intoffset;
4543 static void function_arg_record_value_3
4544 PARAMS ((HOST_WIDE_INT, struct function_arg_record_value_parms *));
4545 static void function_arg_record_value_2
4546 PARAMS ((tree, HOST_WIDE_INT,
4547 struct function_arg_record_value_parms *));
4548 static void function_arg_record_value_1
4549 PARAMS ((tree, HOST_WIDE_INT,
4550 struct function_arg_record_value_parms *));
4551 static rtx function_arg_record_value
4552 PARAMS ((tree, enum machine_mode, int, int, int));
4554 /* A subroutine of function_arg_record_value. Traverse the structure
4555 recusively and determine how many registers will be required. */
4557 static void
4558 function_arg_record_value_1 (type, startbitpos, parms)
4559 tree type;
4560 HOST_WIDE_INT startbitpos;
4561 struct function_arg_record_value_parms *parms;
4563 tree field;
4565 /* The ABI obviously doesn't specify how packed structures are
4566 passed. These are defined to be passed in int regs if possible,
4567 otherwise memory. */
4568 int packed_p = 0;
4570 /* We need to compute how many registers are needed so we can
4571 allocate the PARALLEL but before we can do that we need to know
4572 whether there are any packed fields. If there are, int regs are
4573 used regardless of whether there are fp values present. */
4574 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4576 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4578 packed_p = 1;
4579 break;
4583 /* Compute how many registers we need. */
4584 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4586 if (TREE_CODE (field) == FIELD_DECL)
4588 HOST_WIDE_INT bitpos = startbitpos;
4590 if (DECL_SIZE (field) != 0
4591 && host_integerp (bit_position (field), 1))
4592 bitpos += int_bit_position (field);
4594 /* ??? FIXME: else assume zero offset. */
4596 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4597 function_arg_record_value_1 (TREE_TYPE (field), bitpos, parms);
4598 else if ((TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4599 || (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE
4600 && (TREE_CODE (TREE_TYPE (TREE_TYPE (field)))
4601 == REAL_TYPE)))
4602 && TARGET_FPU
4603 && ! packed_p
4604 && parms->named)
4606 if (parms->intoffset != -1)
4608 int intslots, this_slotno;
4610 intslots = (bitpos - parms->intoffset + BITS_PER_WORD - 1)
4611 / BITS_PER_WORD;
4612 this_slotno = parms->slotno + parms->intoffset
4613 / BITS_PER_WORD;
4615 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4616 intslots = MAX (intslots, 0);
4617 parms->nregs += intslots;
4618 parms->intoffset = -1;
4621 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
4622 If it wasn't true we wouldn't be here. */
4623 parms->nregs += 1;
4624 if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
4625 parms->nregs += 1;
4627 else
4629 if (parms->intoffset == -1)
4630 parms->intoffset = bitpos;
4636 /* A subroutine of function_arg_record_value. Assign the bits of the
4637 structure between parms->intoffset and bitpos to integer registers. */
4639 static void
4640 function_arg_record_value_3 (bitpos, parms)
4641 HOST_WIDE_INT bitpos;
4642 struct function_arg_record_value_parms *parms;
4644 enum machine_mode mode;
4645 unsigned int regno;
4646 unsigned int startbit, endbit;
4647 int this_slotno, intslots, intoffset;
4648 rtx reg;
4650 if (parms->intoffset == -1)
4651 return;
4653 intoffset = parms->intoffset;
4654 parms->intoffset = -1;
4656 startbit = intoffset & -BITS_PER_WORD;
4657 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4658 intslots = (endbit - startbit) / BITS_PER_WORD;
4659 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
4661 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4662 if (intslots <= 0)
4663 return;
4665 /* If this is the trailing part of a word, only load that much into
4666 the register. Otherwise load the whole register. Note that in
4667 the latter case we may pick up unwanted bits. It's not a problem
4668 at the moment but may wish to revisit. */
4670 if (intoffset % BITS_PER_WORD != 0)
4671 mode = mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
4672 MODE_INT, 0);
4673 else
4674 mode = word_mode;
4676 intoffset /= BITS_PER_UNIT;
4679 regno = parms->regbase + this_slotno;
4680 reg = gen_rtx_REG (mode, regno);
4681 XVECEXP (parms->ret, 0, parms->nregs)
4682 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
4684 this_slotno += 1;
4685 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
4686 parms->nregs += 1;
4687 intslots -= 1;
4689 while (intslots > 0);
4692 /* A subroutine of function_arg_record_value. Traverse the structure
4693 recursively and assign bits to floating point registers. Track which
4694 bits in between need integer registers; invoke function_arg_record_value_3
4695 to make that happen. */
4697 static void
4698 function_arg_record_value_2 (type, startbitpos, parms)
4699 tree type;
4700 HOST_WIDE_INT startbitpos;
4701 struct function_arg_record_value_parms *parms;
4703 tree field;
4704 int packed_p = 0;
4706 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4708 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4710 packed_p = 1;
4711 break;
4715 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4717 if (TREE_CODE (field) == FIELD_DECL)
4719 HOST_WIDE_INT bitpos = startbitpos;
4721 if (DECL_SIZE (field) != 0
4722 && host_integerp (bit_position (field), 1))
4723 bitpos += int_bit_position (field);
4725 /* ??? FIXME: else assume zero offset. */
4727 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4728 function_arg_record_value_2 (TREE_TYPE (field), bitpos, parms);
4729 else if ((TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4730 || (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE
4731 && (TREE_CODE (TREE_TYPE (TREE_TYPE (field)))
4732 == REAL_TYPE)))
4733 && TARGET_FPU
4734 && ! packed_p
4735 && parms->named)
4737 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
4738 int regno;
4739 enum machine_mode mode = DECL_MODE (field);
4740 rtx reg;
4742 function_arg_record_value_3 (bitpos, parms);
4743 regno = SPARC_FP_ARG_FIRST + this_slotno * 2
4744 + ((mode == SFmode || mode == SCmode)
4745 && (bitpos & 32) != 0);
4746 switch (mode)
4748 case SCmode: mode = SFmode; break;
4749 case DCmode: mode = DFmode; break;
4750 case TCmode: mode = TFmode; break;
4751 default: break;
4753 reg = gen_rtx_REG (mode, regno);
4754 XVECEXP (parms->ret, 0, parms->nregs)
4755 = gen_rtx_EXPR_LIST (VOIDmode, reg,
4756 GEN_INT (bitpos / BITS_PER_UNIT));
4757 parms->nregs += 1;
4758 if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
4760 regno += GET_MODE_SIZE (mode) / 4;
4761 reg = gen_rtx_REG (mode, regno);
4762 XVECEXP (parms->ret, 0, parms->nregs)
4763 = gen_rtx_EXPR_LIST (VOIDmode, reg,
4764 GEN_INT ((bitpos + GET_MODE_BITSIZE (mode))
4765 / BITS_PER_UNIT));
4766 parms->nregs += 1;
4769 else
4771 if (parms->intoffset == -1)
4772 parms->intoffset = bitpos;
4778 /* Used by function_arg and function_value to implement the complex
4779 SPARC64 structure calling conventions. */
4781 static rtx
4782 function_arg_record_value (type, mode, slotno, named, regbase)
4783 tree type;
4784 enum machine_mode mode;
4785 int slotno, named, regbase;
4787 HOST_WIDE_INT typesize = int_size_in_bytes (type);
4788 struct function_arg_record_value_parms parms;
4789 unsigned int nregs;
4791 parms.ret = NULL_RTX;
4792 parms.slotno = slotno;
4793 parms.named = named;
4794 parms.regbase = regbase;
4796 /* Compute how many registers we need. */
4797 parms.nregs = 0;
4798 parms.intoffset = 0;
4799 function_arg_record_value_1 (type, 0, &parms);
4801 if (parms.intoffset != -1)
4803 unsigned int startbit, endbit;
4804 int intslots, this_slotno;
4806 startbit = parms.intoffset & -BITS_PER_WORD;
4807 endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4808 intslots = (endbit - startbit) / BITS_PER_WORD;
4809 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
4811 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4812 intslots = MAX (intslots, 0);
4814 parms.nregs += intslots;
4816 nregs = parms.nregs;
4818 /* Allocate the vector and handle some annoying special cases. */
4819 if (nregs == 0)
4821 /* ??? Empty structure has no value? Duh? */
4822 if (typesize <= 0)
4824 /* Though there's nothing really to store, return a word register
4825 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
4826 leads to breakage due to the fact that there are zero bytes to
4827 load. */
4828 return gen_rtx_REG (mode, regbase);
4830 else
4832 /* ??? C++ has structures with no fields, and yet a size. Give up
4833 for now and pass everything back in integer registers. */
4834 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4836 if (nregs + slotno > SPARC_INT_ARG_MAX)
4837 nregs = SPARC_INT_ARG_MAX - slotno;
4839 if (nregs == 0)
4840 abort ();
4842 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (nregs));
4844 /* Fill in the entries. */
4845 parms.nregs = 0;
4846 parms.intoffset = 0;
4847 function_arg_record_value_2 (type, 0, &parms);
4848 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
4850 if (parms.nregs != nregs)
4851 abort ();
4853 return parms.ret;
4856 /* Handle the FUNCTION_ARG macro.
4857 Determine where to put an argument to a function.
4858 Value is zero to push the argument on the stack,
4859 or a hard register in which to store the argument.
4861 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4862 the preceding args and about the function being called.
4863 MODE is the argument's machine mode.
4864 TYPE is the data type of the argument (as a tree).
4865 This is null for libcalls where that information may
4866 not be available.
4867 NAMED is nonzero if this argument is a named parameter
4868 (otherwise it is an extra parameter matching an ellipsis).
4869 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
4872 function_arg (cum, mode, type, named, incoming_p)
4873 const CUMULATIVE_ARGS *cum;
4874 enum machine_mode mode;
4875 tree type;
4876 int named;
4877 int incoming_p;
4879 int regbase = (incoming_p
4880 ? SPARC_INCOMING_INT_ARG_FIRST
4881 : SPARC_OUTGOING_INT_ARG_FIRST);
4882 int slotno, regno, padding;
4883 rtx reg;
4885 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
4886 &regno, &padding);
4888 if (slotno == -1)
4889 return 0;
4891 if (TARGET_ARCH32)
4893 reg = gen_rtx_REG (mode, regno);
4894 return reg;
4897 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
4898 but also have the slot allocated for them.
4899 If no prototype is in scope fp values in register slots get passed
4900 in two places, either fp regs and int regs or fp regs and memory. */
4901 if ((GET_MODE_CLASS (mode) == MODE_FLOAT
4902 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4903 && SPARC_FP_REG_P (regno))
4905 reg = gen_rtx_REG (mode, regno);
4906 if (cum->prototype_p || cum->libcall_p)
4908 /* "* 2" because fp reg numbers are recorded in 4 byte
4909 quantities. */
4910 #if 0
4911 /* ??? This will cause the value to be passed in the fp reg and
4912 in the stack. When a prototype exists we want to pass the
4913 value in the reg but reserve space on the stack. That's an
4914 optimization, and is deferred [for a bit]. */
4915 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
4916 return gen_rtx_PARALLEL (mode,
4917 gen_rtvec (2,
4918 gen_rtx_EXPR_LIST (VOIDmode,
4919 NULL_RTX, const0_rtx),
4920 gen_rtx_EXPR_LIST (VOIDmode,
4921 reg, const0_rtx)));
4922 else
4923 #else
4924 /* ??? It seems that passing back a register even when past
4925 the area declared by REG_PARM_STACK_SPACE will allocate
4926 space appropriately, and will not copy the data onto the
4927 stack, exactly as we desire.
4929 This is due to locate_and_pad_parm being called in
4930 expand_call whenever reg_parm_stack_space > 0, which
4931 while benefical to our example here, would seem to be
4932 in error from what had been intended. Ho hum... -- r~ */
4933 #endif
4934 return reg;
4936 else
4938 rtx v0, v1;
4940 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
4942 int intreg;
4944 /* On incoming, we don't need to know that the value
4945 is passed in %f0 and %i0, and it confuses other parts
4946 causing needless spillage even on the simplest cases. */
4947 if (incoming_p)
4948 return reg;
4950 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
4951 + (regno - SPARC_FP_ARG_FIRST) / 2);
4953 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4954 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
4955 const0_rtx);
4956 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
4958 else
4960 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4961 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4962 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
4966 else if (type && TREE_CODE (type) == RECORD_TYPE)
4968 /* Structures up to 16 bytes in size are passed in arg slots on the
4969 stack and are promoted to registers where possible. */
4971 if (int_size_in_bytes (type) > 16)
4972 abort (); /* shouldn't get here */
4974 return function_arg_record_value (type, mode, slotno, named, regbase);
4976 else if (type && TREE_CODE (type) == UNION_TYPE)
4978 enum machine_mode mode;
4979 int bytes = int_size_in_bytes (type);
4981 if (bytes > 16)
4982 abort ();
4984 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
4985 reg = gen_rtx_REG (mode, regno);
4987 else
4989 /* Scalar or complex int. */
4990 reg = gen_rtx_REG (mode, regno);
4993 return reg;
4996 /* Handle the FUNCTION_ARG_PARTIAL_NREGS macro.
4997 For an arg passed partly in registers and partly in memory,
4998 this is the number of registers used.
4999 For args passed entirely in registers or entirely in memory, zero.
5001 Any arg that starts in the first 6 regs but won't entirely fit in them
5002 needs partial registers on v8. On v9, structures with integer
5003 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
5004 values that begin in the last fp reg [where "last fp reg" varies with the
5005 mode] will be split between that reg and memory. */
5008 function_arg_partial_nregs (cum, mode, type, named)
5009 const CUMULATIVE_ARGS *cum;
5010 enum machine_mode mode;
5011 tree type;
5012 int named;
5014 int slotno, regno, padding;
5016 /* We pass 0 for incoming_p here, it doesn't matter. */
5017 slotno = function_arg_slotno (cum, mode, type, named, 0, &regno, &padding);
5019 if (slotno == -1)
5020 return 0;
5022 if (TARGET_ARCH32)
5024 if ((slotno + (mode == BLKmode
5025 ? ROUND_ADVANCE (int_size_in_bytes (type))
5026 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
5027 > NPARM_REGS (SImode))
5028 return NPARM_REGS (SImode) - slotno;
5029 return 0;
5031 else
5033 if (type && AGGREGATE_TYPE_P (type))
5035 int size = int_size_in_bytes (type);
5036 int align = TYPE_ALIGN (type);
5038 if (align == 16)
5039 slotno += slotno & 1;
5040 if (size > 8 && size <= 16
5041 && slotno == SPARC_INT_ARG_MAX - 1)
5042 return 1;
5044 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
5045 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5046 && ! TARGET_FPU))
5048 if (GET_MODE_ALIGNMENT (mode) == 128)
5050 slotno += slotno & 1;
5051 if (slotno == SPARC_INT_ARG_MAX - 2)
5052 return 1;
5054 else
5056 if (slotno == SPARC_INT_ARG_MAX - 1)
5057 return 1;
5060 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
5062 if (GET_MODE_ALIGNMENT (mode) == 128)
5063 slotno += slotno & 1;
5064 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
5065 > SPARC_FP_ARG_MAX)
5066 return 1;
5068 return 0;
5072 /* Handle the FUNCTION_ARG_PASS_BY_REFERENCE macro.
5073 !v9: The SPARC ABI stipulates passing struct arguments (of any size) and
5074 quad-precision floats by invisible reference.
5075 v9: Aggregates greater than 16 bytes are passed by reference.
5076 For Pascal, also pass arrays by reference. */
5079 function_arg_pass_by_reference (cum, mode, type, named)
5080 const CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
5081 enum machine_mode mode;
5082 tree type;
5083 int named ATTRIBUTE_UNUSED;
5085 if (TARGET_ARCH32)
5087 return ((type && AGGREGATE_TYPE_P (type))
5088 || mode == TFmode || mode == TCmode);
5090 else
5092 return ((type && TREE_CODE (type) == ARRAY_TYPE)
5093 /* Consider complex values as aggregates, so care for TCmode. */
5094 || GET_MODE_SIZE (mode) > 16
5095 || (type
5096 && AGGREGATE_TYPE_P (type)
5097 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 16));
5101 /* Handle the FUNCTION_ARG_ADVANCE macro.
5102 Update the data in CUM to advance over an argument
5103 of mode MODE and data type TYPE.
5104 TYPE is null for libcalls where that information may not be available. */
5106 void
5107 function_arg_advance (cum, mode, type, named)
5108 CUMULATIVE_ARGS *cum;
5109 enum machine_mode mode;
5110 tree type;
5111 int named;
5113 int slotno, regno, padding;
5115 /* We pass 0 for incoming_p here, it doesn't matter. */
5116 slotno = function_arg_slotno (cum, mode, type, named, 0, &regno, &padding);
5118 /* If register required leading padding, add it. */
5119 if (slotno != -1)
5120 cum->words += padding;
5122 if (TARGET_ARCH32)
5124 cum->words += (mode != BLKmode
5125 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5126 : ROUND_ADVANCE (int_size_in_bytes (type)));
5128 else
5130 if (type && AGGREGATE_TYPE_P (type))
5132 int size = int_size_in_bytes (type);
5134 if (size <= 8)
5135 ++cum->words;
5136 else if (size <= 16)
5137 cum->words += 2;
5138 else /* passed by reference */
5139 ++cum->words;
5141 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
5143 cum->words += 2;
5145 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
5147 cum->words += GET_MODE_SIZE (mode) / UNITS_PER_WORD;
5149 else
5151 cum->words += (mode != BLKmode
5152 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5153 : ROUND_ADVANCE (int_size_in_bytes (type)));
5158 /* Handle the FUNCTION_ARG_PADDING macro.
5159 For the 64 bit ABI structs are always stored left shifted in their
5160 argument slot. */
5162 enum direction
5163 function_arg_padding (mode, type)
5164 enum machine_mode mode;
5165 tree type;
5167 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
5168 return upward;
5170 /* This is the default definition. */
5171 return (! BYTES_BIG_ENDIAN
5172 ? upward
5173 : ((mode == BLKmode
5174 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
5175 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
5176 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
5177 ? downward : upward));
5180 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.
5181 For v9, function return values are subject to the same rules as arguments,
5182 except that up to 32-bytes may be returned in registers. */
5185 function_value (type, mode, incoming_p)
5186 tree type;
5187 enum machine_mode mode;
5188 int incoming_p;
5190 int regno;
5191 int regbase = (incoming_p
5192 ? SPARC_OUTGOING_INT_ARG_FIRST
5193 : SPARC_INCOMING_INT_ARG_FIRST);
5195 if (TARGET_ARCH64 && type)
5197 if (TREE_CODE (type) == RECORD_TYPE)
5199 /* Structures up to 32 bytes in size are passed in registers,
5200 promoted to fp registers where possible. */
5202 if (int_size_in_bytes (type) > 32)
5203 abort (); /* shouldn't get here */
5205 return function_arg_record_value (type, mode, 0, 1, regbase);
5207 else if (AGGREGATE_TYPE_P (type))
5209 /* All other aggregate types are passed in an integer register
5210 in a mode corresponding to the size of the type. */
5211 HOST_WIDE_INT bytes = int_size_in_bytes (type);
5213 if (bytes > 32)
5214 abort ();
5216 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
5220 if (TARGET_ARCH64
5221 && GET_MODE_CLASS (mode) == MODE_INT
5222 && GET_MODE_SIZE (mode) < UNITS_PER_WORD
5223 && type && ! AGGREGATE_TYPE_P (type))
5224 mode = DImode;
5226 if (incoming_p)
5227 regno = BASE_RETURN_VALUE_REG (mode);
5228 else
5229 regno = BASE_OUTGOING_VALUE_REG (mode);
5231 return gen_rtx_REG (mode, regno);
5234 /* Do what is necessary for `va_start'. We look at the current function
5235 to determine if stdarg or varargs is used and return the address of
5236 the first unnamed parameter. */
5239 sparc_builtin_saveregs ()
5241 int first_reg = current_function_args_info.words;
5242 rtx address;
5243 int regno;
5245 for (regno = first_reg; regno < NPARM_REGS (word_mode); regno++)
5246 emit_move_insn (gen_rtx_MEM (word_mode,
5247 gen_rtx_PLUS (Pmode,
5248 frame_pointer_rtx,
5249 GEN_INT (FIRST_PARM_OFFSET (0)
5250 + (UNITS_PER_WORD
5251 * regno)))),
5252 gen_rtx_REG (word_mode,
5253 BASE_INCOMING_ARG_REG (word_mode) + regno));
5255 address = gen_rtx_PLUS (Pmode,
5256 frame_pointer_rtx,
5257 GEN_INT (FIRST_PARM_OFFSET (0)
5258 + UNITS_PER_WORD * first_reg));
5260 return address;
5263 /* Implement `va_start' for varargs and stdarg. */
5265 void
5266 sparc_va_start (valist, nextarg)
5267 tree valist;
5268 rtx nextarg;
5270 nextarg = expand_builtin_saveregs ();
5271 std_expand_builtin_va_start (valist, nextarg);
5274 /* Implement `va_arg'. */
5277 sparc_va_arg (valist, type)
5278 tree valist, type;
5280 HOST_WIDE_INT size, rsize, align;
5281 tree addr, incr;
5282 rtx addr_rtx;
5283 int indirect = 0;
5285 /* Round up sizeof(type) to a word. */
5286 size = int_size_in_bytes (type);
5287 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
5288 align = 0;
5290 if (TARGET_ARCH64)
5292 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
5293 align = 2 * UNITS_PER_WORD;
5295 if (AGGREGATE_TYPE_P (type))
5297 if ((unsigned HOST_WIDE_INT) size > 16)
5299 indirect = 1;
5300 size = rsize = UNITS_PER_WORD;
5302 /* SPARC v9 ABI states that structures up to 8 bytes in size are
5303 given one 8 byte slot. */
5304 else if (size == 0)
5305 size = rsize = UNITS_PER_WORD;
5306 else
5307 size = rsize;
5310 else
5312 if (AGGREGATE_TYPE_P (type)
5313 || TYPE_MODE (type) == TFmode
5314 || TYPE_MODE (type) == TCmode)
5316 indirect = 1;
5317 size = rsize = UNITS_PER_WORD;
5321 incr = valist;
5322 if (align)
5324 incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
5325 build_int_2 (align - 1, 0)));
5326 incr = fold (build (BIT_AND_EXPR, ptr_type_node, incr,
5327 build_int_2 (-align, -1)));
5330 addr = incr = save_expr (incr);
5331 if (BYTES_BIG_ENDIAN && size < rsize)
5333 addr = fold (build (PLUS_EXPR, ptr_type_node, incr,
5334 build_int_2 (rsize - size, 0)));
5336 incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
5337 build_int_2 (rsize, 0)));
5339 incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
5340 TREE_SIDE_EFFECTS (incr) = 1;
5341 expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
5343 addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
5345 /* If the address isn't aligned properly for the type,
5346 we may need to copy to a temporary.
5347 FIXME: This is inefficient. Usually we can do this
5348 in registers. */
5349 if (align == 0
5350 && TYPE_ALIGN (type) > BITS_PER_WORD
5351 && !indirect)
5353 /* FIXME: We really need to specify that the temporary is live
5354 for the whole function because expand_builtin_va_arg wants
5355 the alias set to be get_varargs_alias_set (), but in this
5356 case the alias set is that for TYPE and if the memory gets
5357 reused it will be reused with alias set TYPE. */
5358 rtx tmp = assign_temp (type, 0, 1, 0);
5359 rtx dest_addr;
5361 addr_rtx = force_reg (Pmode, addr_rtx);
5362 addr_rtx = gen_rtx_MEM (BLKmode, addr_rtx);
5363 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
5364 set_mem_align (addr_rtx, BITS_PER_WORD);
5365 tmp = shallow_copy_rtx (tmp);
5366 PUT_MODE (tmp, BLKmode);
5367 set_mem_alias_set (tmp, 0);
5369 dest_addr = emit_block_move (tmp, addr_rtx, GEN_INT (rsize),
5370 BLOCK_OP_NORMAL);
5371 if (dest_addr != NULL_RTX)
5372 addr_rtx = dest_addr;
5373 else
5374 addr_rtx = XCEXP (tmp, 0, MEM);
5377 if (indirect)
5379 addr_rtx = force_reg (Pmode, addr_rtx);
5380 addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
5381 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
5384 return addr_rtx;
5387 /* Return the string to output a conditional branch to LABEL, which is
5388 the operand number of the label. OP is the conditional expression.
5389 XEXP (OP, 0) is assumed to be a condition code register (integer or
5390 floating point) and its mode specifies what kind of comparison we made.
5392 REVERSED is nonzero if we should reverse the sense of the comparison.
5394 ANNUL is nonzero if we should generate an annulling branch.
5396 NOOP is nonzero if we have to follow this branch by a noop.
5398 INSN, if set, is the insn. */
5400 char *
5401 output_cbranch (op, dest, label, reversed, annul, noop, insn)
5402 rtx op, dest;
5403 int label;
5404 int reversed, annul, noop;
5405 rtx insn;
5407 static char string[50];
5408 enum rtx_code code = GET_CODE (op);
5409 rtx cc_reg = XEXP (op, 0);
5410 enum machine_mode mode = GET_MODE (cc_reg);
5411 const char *labelno, *branch;
5412 int spaces = 8, far;
5413 char *p;
5415 /* v9 branches are limited to +-1MB. If it is too far away,
5416 change
5418 bne,pt %xcc, .LC30
5422 be,pn %xcc, .+12
5424 ba .LC30
5428 fbne,a,pn %fcc2, .LC29
5432 fbe,pt %fcc2, .+16
5434 ba .LC29 */
5436 far = get_attr_length (insn) >= 3;
5437 if (reversed ^ far)
5439 /* Reversal of FP compares takes care -- an ordered compare
5440 becomes an unordered compare and vice versa. */
5441 if (mode == CCFPmode || mode == CCFPEmode)
5442 code = reverse_condition_maybe_unordered (code);
5443 else
5444 code = reverse_condition (code);
5447 /* Start by writing the branch condition. */
5448 if (mode == CCFPmode || mode == CCFPEmode)
5450 switch (code)
5452 case NE:
5453 branch = "fbne";
5454 break;
5455 case EQ:
5456 branch = "fbe";
5457 break;
5458 case GE:
5459 branch = "fbge";
5460 break;
5461 case GT:
5462 branch = "fbg";
5463 break;
5464 case LE:
5465 branch = "fble";
5466 break;
5467 case LT:
5468 branch = "fbl";
5469 break;
5470 case UNORDERED:
5471 branch = "fbu";
5472 break;
5473 case ORDERED:
5474 branch = "fbo";
5475 break;
5476 case UNGT:
5477 branch = "fbug";
5478 break;
5479 case UNLT:
5480 branch = "fbul";
5481 break;
5482 case UNEQ:
5483 branch = "fbue";
5484 break;
5485 case UNGE:
5486 branch = "fbuge";
5487 break;
5488 case UNLE:
5489 branch = "fbule";
5490 break;
5491 case LTGT:
5492 branch = "fblg";
5493 break;
5495 default:
5496 abort ();
5499 /* ??? !v9: FP branches cannot be preceded by another floating point
5500 insn. Because there is currently no concept of pre-delay slots,
5501 we can fix this only by always emitting a nop before a floating
5502 point branch. */
5504 string[0] = '\0';
5505 if (! TARGET_V9)
5506 strcpy (string, "nop\n\t");
5507 strcat (string, branch);
5509 else
5511 switch (code)
5513 case NE:
5514 branch = "bne";
5515 break;
5516 case EQ:
5517 branch = "be";
5518 break;
5519 case GE:
5520 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
5521 branch = "bpos";
5522 else
5523 branch = "bge";
5524 break;
5525 case GT:
5526 branch = "bg";
5527 break;
5528 case LE:
5529 branch = "ble";
5530 break;
5531 case LT:
5532 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
5533 branch = "bneg";
5534 else
5535 branch = "bl";
5536 break;
5537 case GEU:
5538 branch = "bgeu";
5539 break;
5540 case GTU:
5541 branch = "bgu";
5542 break;
5543 case LEU:
5544 branch = "bleu";
5545 break;
5546 case LTU:
5547 branch = "blu";
5548 break;
5550 default:
5551 abort ();
5553 strcpy (string, branch);
5555 spaces -= strlen (branch);
5556 p = strchr (string, '\0');
5558 /* Now add the annulling, the label, and a possible noop. */
5559 if (annul && ! far)
5561 strcpy (p, ",a");
5562 p += 2;
5563 spaces -= 2;
5566 if (! TARGET_V9)
5567 labelno = "";
5568 else
5570 rtx note;
5571 int v8 = 0;
5573 if (! far && insn && INSN_ADDRESSES_SET_P ())
5575 int delta = (INSN_ADDRESSES (INSN_UID (dest))
5576 - INSN_ADDRESSES (INSN_UID (insn)));
5577 /* Leave some instructions for "slop". */
5578 if (delta < -260000 || delta >= 260000)
5579 v8 = 1;
5582 if (mode == CCFPmode || mode == CCFPEmode)
5584 static char v9_fcc_labelno[] = "%%fccX, ";
5585 /* Set the char indicating the number of the fcc reg to use. */
5586 v9_fcc_labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
5587 labelno = v9_fcc_labelno;
5588 if (v8)
5590 if (REGNO (cc_reg) == SPARC_FCC_REG)
5591 labelno = "";
5592 else
5593 abort ();
5596 else if (mode == CCXmode || mode == CCX_NOOVmode)
5598 labelno = "%%xcc, ";
5599 if (v8)
5600 abort ();
5602 else
5604 labelno = "%%icc, ";
5605 if (v8)
5606 labelno = "";
5609 if (*labelno && insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
5611 strcpy (p,
5612 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
5613 ? ",pt" : ",pn");
5614 p += 3;
5615 spaces -= 3;
5618 if (spaces > 0)
5619 *p++ = '\t';
5620 else
5621 *p++ = ' ';
5622 strcpy (p, labelno);
5623 p = strchr (p, '\0');
5624 if (far)
5626 strcpy (p, ".+12\n\tnop\n\tb\t");
5627 if (annul || noop)
5628 p[3] = '6';
5629 p += 13;
5631 *p++ = '%';
5632 *p++ = 'l';
5633 /* Set the char indicating the number of the operand containing the
5634 label_ref. */
5635 *p++ = label + '0';
5636 *p = '\0';
5637 if (noop)
5638 strcpy (p, "\n\tnop");
5640 return string;
5643 /* Emit a library call comparison between floating point X and Y.
5644 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
5645 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
5646 values as arguments instead of the TFmode registers themselves,
5647 that's why we cannot call emit_float_lib_cmp. */
5648 void
5649 sparc_emit_float_lib_cmp (x, y, comparison)
5650 rtx x, y;
5651 enum rtx_code comparison;
5653 const char *qpfunc;
5654 rtx slot0, slot1, result, tem, tem2;
5655 enum machine_mode mode;
5657 switch (comparison)
5659 case EQ:
5660 qpfunc = (TARGET_ARCH64) ? "_Qp_feq" : "_Q_feq";
5661 break;
5663 case NE:
5664 qpfunc = (TARGET_ARCH64) ? "_Qp_fne" : "_Q_fne";
5665 break;
5667 case GT:
5668 qpfunc = (TARGET_ARCH64) ? "_Qp_fgt" : "_Q_fgt";
5669 break;
5671 case GE:
5672 qpfunc = (TARGET_ARCH64) ? "_Qp_fge" : "_Q_fge";
5673 break;
5675 case LT:
5676 qpfunc = (TARGET_ARCH64) ? "_Qp_flt" : "_Q_flt";
5677 break;
5679 case LE:
5680 qpfunc = (TARGET_ARCH64) ? "_Qp_fle" : "_Q_fle";
5681 break;
5683 case ORDERED:
5684 case UNORDERED:
5685 case UNGT:
5686 case UNLT:
5687 case UNEQ:
5688 case UNGE:
5689 case UNLE:
5690 case LTGT:
5691 qpfunc = (TARGET_ARCH64) ? "_Qp_cmp" : "_Q_cmp";
5692 break;
5694 default:
5695 abort();
5696 break;
5699 if (TARGET_ARCH64)
5701 if (GET_CODE (x) != MEM)
5703 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5704 emit_insn (gen_rtx_SET (VOIDmode, slot0, x));
5706 else
5707 slot0 = x;
5709 if (GET_CODE (y) != MEM)
5711 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5712 emit_insn (gen_rtx_SET (VOIDmode, slot1, y));
5714 else
5715 slot1 = y;
5717 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
5718 DImode, 2,
5719 XEXP (slot0, 0), Pmode,
5720 XEXP (slot1, 0), Pmode);
5722 mode = DImode;
5724 else
5726 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
5727 SImode, 2,
5728 x, TFmode, y, TFmode);
5730 mode = SImode;
5734 /* Immediately move the result of the libcall into a pseudo
5735 register so reload doesn't clobber the value if it needs
5736 the return register for a spill reg. */
5737 result = gen_reg_rtx (mode);
5738 emit_move_insn (result, hard_libcall_value (mode));
5740 switch (comparison)
5742 default:
5743 emit_cmp_insn (result, const0_rtx, NE, NULL_RTX, mode, 0);
5744 break;
5745 case ORDERED:
5746 case UNORDERED:
5747 emit_cmp_insn (result, GEN_INT(3), comparison == UNORDERED ? EQ : NE,
5748 NULL_RTX, mode, 0);
5749 break;
5750 case UNGT:
5751 case UNGE:
5752 emit_cmp_insn (result, const1_rtx,
5753 comparison == UNGT ? GT : NE, NULL_RTX, mode, 0);
5754 break;
5755 case UNLE:
5756 emit_cmp_insn (result, const2_rtx, NE, NULL_RTX, mode, 0);
5757 break;
5758 case UNLT:
5759 tem = gen_reg_rtx (mode);
5760 if (TARGET_ARCH32)
5761 emit_insn (gen_andsi3 (tem, result, const1_rtx));
5762 else
5763 emit_insn (gen_anddi3 (tem, result, const1_rtx));
5764 emit_cmp_insn (tem, const0_rtx, NE, NULL_RTX, mode, 0);
5765 break;
5766 case UNEQ:
5767 case LTGT:
5768 tem = gen_reg_rtx (mode);
5769 if (TARGET_ARCH32)
5770 emit_insn (gen_addsi3 (tem, result, const1_rtx));
5771 else
5772 emit_insn (gen_adddi3 (tem, result, const1_rtx));
5773 tem2 = gen_reg_rtx (mode);
5774 if (TARGET_ARCH32)
5775 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
5776 else
5777 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
5778 emit_cmp_insn (tem2, const0_rtx, comparison == UNEQ ? EQ : NE,
5779 NULL_RTX, mode, 0);
5780 break;
5784 /* Generate an unsigned DImode to FP conversion. This is the same code
5785 optabs would emit if we didn't have TFmode patterns. */
5787 void
5788 sparc_emit_floatunsdi (operands)
5789 rtx operands[2];
5791 rtx neglab, donelab, i0, i1, f0, in, out;
5792 enum machine_mode mode;
5794 out = operands[0];
5795 in = force_reg (DImode, operands[1]);
5796 mode = GET_MODE (out);
5797 neglab = gen_label_rtx ();
5798 donelab = gen_label_rtx ();
5799 i0 = gen_reg_rtx (DImode);
5800 i1 = gen_reg_rtx (DImode);
5801 f0 = gen_reg_rtx (mode);
5803 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
5805 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
5806 emit_jump_insn (gen_jump (donelab));
5807 emit_barrier ();
5809 emit_label (neglab);
5811 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
5812 emit_insn (gen_anddi3 (i1, in, const1_rtx));
5813 emit_insn (gen_iordi3 (i0, i0, i1));
5814 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
5815 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
5817 emit_label (donelab);
5820 /* Return the string to output a conditional branch to LABEL, testing
5821 register REG. LABEL is the operand number of the label; REG is the
5822 operand number of the reg. OP is the conditional expression. The mode
5823 of REG says what kind of comparison we made.
5825 REVERSED is nonzero if we should reverse the sense of the comparison.
5827 ANNUL is nonzero if we should generate an annulling branch.
5829 NOOP is nonzero if we have to follow this branch by a noop. */
5831 char *
5832 output_v9branch (op, dest, reg, label, reversed, annul, noop, insn)
5833 rtx op, dest;
5834 int reg, label;
5835 int reversed, annul, noop;
5836 rtx insn;
5838 static char string[50];
5839 enum rtx_code code = GET_CODE (op);
5840 enum machine_mode mode = GET_MODE (XEXP (op, 0));
5841 rtx note;
5842 int far;
5843 char *p;
5845 /* branch on register are limited to +-128KB. If it is too far away,
5846 change
5848 brnz,pt %g1, .LC30
5852 brz,pn %g1, .+12
5854 ba,pt %xcc, .LC30
5858 brgez,a,pn %o1, .LC29
5862 brlz,pt %o1, .+16
5864 ba,pt %xcc, .LC29 */
5866 far = get_attr_length (insn) >= 3;
5868 /* If not floating-point or if EQ or NE, we can just reverse the code. */
5869 if (reversed ^ far)
5870 code = reverse_condition (code);
5872 /* Only 64 bit versions of these instructions exist. */
5873 if (mode != DImode)
5874 abort ();
5876 /* Start by writing the branch condition. */
5878 switch (code)
5880 case NE:
5881 strcpy (string, "brnz");
5882 break;
5884 case EQ:
5885 strcpy (string, "brz");
5886 break;
5888 case GE:
5889 strcpy (string, "brgez");
5890 break;
5892 case LT:
5893 strcpy (string, "brlz");
5894 break;
5896 case LE:
5897 strcpy (string, "brlez");
5898 break;
5900 case GT:
5901 strcpy (string, "brgz");
5902 break;
5904 default:
5905 abort ();
5908 p = strchr (string, '\0');
5910 /* Now add the annulling, reg, label, and nop. */
5911 if (annul && ! far)
5913 strcpy (p, ",a");
5914 p += 2;
5917 if (insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
5919 strcpy (p,
5920 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
5921 ? ",pt" : ",pn");
5922 p += 3;
5925 *p = p < string + 8 ? '\t' : ' ';
5926 p++;
5927 *p++ = '%';
5928 *p++ = '0' + reg;
5929 *p++ = ',';
5930 *p++ = ' ';
5931 if (far)
5933 int veryfar = 1, delta;
5935 if (INSN_ADDRESSES_SET_P ())
5937 delta = (INSN_ADDRESSES (INSN_UID (dest))
5938 - INSN_ADDRESSES (INSN_UID (insn)));
5939 /* Leave some instructions for "slop". */
5940 if (delta >= -260000 && delta < 260000)
5941 veryfar = 0;
5944 strcpy (p, ".+12\n\tnop\n\t");
5945 if (annul || noop)
5946 p[3] = '6';
5947 p += 11;
5948 if (veryfar)
5950 strcpy (p, "b\t");
5951 p += 2;
5953 else
5955 strcpy (p, "ba,pt\t%%xcc, ");
5956 p += 13;
5959 *p++ = '%';
5960 *p++ = 'l';
5961 *p++ = '0' + label;
5962 *p = '\0';
5964 if (noop)
5965 strcpy (p, "\n\tnop");
5967 return string;
5970 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
5971 Such instructions cannot be used in the delay slot of return insn on v9.
5972 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
5975 static int
5976 epilogue_renumber (where, test)
5977 register rtx *where;
5978 int test;
5980 register const char *fmt;
5981 register int i;
5982 register enum rtx_code code;
5984 if (*where == 0)
5985 return 0;
5987 code = GET_CODE (*where);
5989 switch (code)
5991 case REG:
5992 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
5993 return 1;
5994 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
5995 *where = gen_rtx (REG, GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
5996 case SCRATCH:
5997 case CC0:
5998 case PC:
5999 case CONST_INT:
6000 case CONST_DOUBLE:
6001 return 0;
6003 /* Do not replace the frame pointer with the stack pointer because
6004 it can cause the delayed instruction to load below the stack.
6005 This occurs when instructions like:
6007 (set (reg/i:SI 24 %i0)
6008 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
6009 (const_int -20 [0xffffffec])) 0))
6011 are in the return delayed slot. */
6012 case PLUS:
6013 if (GET_CODE (XEXP (*where, 0)) == REG
6014 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM
6015 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
6016 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
6017 return 1;
6018 break;
6020 case MEM:
6021 if (SPARC_STACK_BIAS
6022 && GET_CODE (XEXP (*where, 0)) == REG
6023 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM)
6024 return 1;
6025 break;
6027 default:
6028 break;
6031 fmt = GET_RTX_FORMAT (code);
6033 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6035 if (fmt[i] == 'E')
6037 register int j;
6038 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
6039 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
6040 return 1;
6042 else if (fmt[i] == 'e'
6043 && epilogue_renumber (&(XEXP (*where, i)), test))
6044 return 1;
6046 return 0;
6049 /* Leaf functions and non-leaf functions have different needs. */
6051 static const int
6052 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
6054 static const int
6055 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
6057 static const int *const reg_alloc_orders[] = {
6058 reg_leaf_alloc_order,
6059 reg_nonleaf_alloc_order};
6061 void
6062 order_regs_for_local_alloc ()
6064 static int last_order_nonleaf = 1;
6066 if (regs_ever_live[15] != last_order_nonleaf)
6068 last_order_nonleaf = !last_order_nonleaf;
6069 memcpy ((char *) reg_alloc_order,
6070 (const char *) reg_alloc_orders[last_order_nonleaf],
6071 FIRST_PSEUDO_REGISTER * sizeof (int));
6075 /* Return 1 if REG and MEM are legitimate enough to allow the various
6076 mem<-->reg splits to be run. */
6079 sparc_splitdi_legitimate (reg, mem)
6080 rtx reg;
6081 rtx mem;
6083 /* Punt if we are here by mistake. */
6084 if (! reload_completed)
6085 abort ();
6087 /* We must have an offsettable memory reference. */
6088 if (! offsettable_memref_p (mem))
6089 return 0;
6091 /* If we have legitimate args for ldd/std, we do not want
6092 the split to happen. */
6093 if ((REGNO (reg) % 2) == 0
6094 && mem_min_alignment (mem, 8))
6095 return 0;
6097 /* Success. */
6098 return 1;
6101 /* Return 1 if x and y are some kind of REG and they refer to
6102 different hard registers. This test is guarenteed to be
6103 run after reload. */
6106 sparc_absnegfloat_split_legitimate (x, y)
6107 rtx x, y;
6109 if (GET_CODE (x) != REG)
6110 return 0;
6111 if (GET_CODE (y) != REG)
6112 return 0;
6113 if (REGNO (x) == REGNO (y))
6114 return 0;
6115 return 1;
6118 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
6119 This makes them candidates for using ldd and std insns.
6121 Note reg1 and reg2 *must* be hard registers. */
6124 registers_ok_for_ldd_peep (reg1, reg2)
6125 rtx reg1, reg2;
6127 /* We might have been passed a SUBREG. */
6128 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
6129 return 0;
6131 if (REGNO (reg1) % 2 != 0)
6132 return 0;
6134 /* Integer ldd is deprecated in SPARC V9 */
6135 if (TARGET_V9 && REGNO (reg1) < 32)
6136 return 0;
6138 return (REGNO (reg1) == REGNO (reg2) - 1);
6141 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
6142 an ldd or std insn.
6144 This can only happen when addr1 and addr2, the addresses in mem1
6145 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
6146 addr1 must also be aligned on a 64-bit boundary.
6148 Also iff dependent_reg_rtx is not null it should not be used to
6149 compute the address for mem1, i.e. we cannot optimize a sequence
6150 like:
6151 ld [%o0], %o0
6152 ld [%o0 + 4], %o1
6154 ldd [%o0], %o0
6155 nor:
6156 ld [%g3 + 4], %g3
6157 ld [%g3], %g2
6159 ldd [%g3], %g2
6161 But, note that the transformation from:
6162 ld [%g2 + 4], %g3
6163 ld [%g2], %g2
6165 ldd [%g2], %g2
6166 is perfectly fine. Thus, the peephole2 patterns always pass us
6167 the destination register of the first load, never the second one.
6169 For stores we don't have a similar problem, so dependent_reg_rtx is
6170 NULL_RTX. */
6173 mems_ok_for_ldd_peep (mem1, mem2, dependent_reg_rtx)
6174 rtx mem1, mem2, dependent_reg_rtx;
6176 rtx addr1, addr2;
6177 unsigned int reg1;
6178 int offset1;
6180 /* The mems cannot be volatile. */
6181 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
6182 return 0;
6184 /* MEM1 should be aligned on a 64-bit boundary. */
6185 if (MEM_ALIGN (mem1) < 64)
6186 return 0;
6188 addr1 = XEXP (mem1, 0);
6189 addr2 = XEXP (mem2, 0);
6191 /* Extract a register number and offset (if used) from the first addr. */
6192 if (GET_CODE (addr1) == PLUS)
6194 /* If not a REG, return zero. */
6195 if (GET_CODE (XEXP (addr1, 0)) != REG)
6196 return 0;
6197 else
6199 reg1 = REGNO (XEXP (addr1, 0));
6200 /* The offset must be constant! */
6201 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
6202 return 0;
6203 offset1 = INTVAL (XEXP (addr1, 1));
6206 else if (GET_CODE (addr1) != REG)
6207 return 0;
6208 else
6210 reg1 = REGNO (addr1);
6211 /* This was a simple (mem (reg)) expression. Offset is 0. */
6212 offset1 = 0;
6215 /* Make sure the second address is a (mem (plus (reg) (const_int). */
6216 if (GET_CODE (addr2) != PLUS)
6217 return 0;
6219 if (GET_CODE (XEXP (addr2, 0)) != REG
6220 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
6221 return 0;
6223 if (reg1 != REGNO (XEXP (addr2, 0)))
6224 return 0;
6226 if (dependent_reg_rtx != NULL_RTX && reg1 == REGNO (dependent_reg_rtx))
6227 return 0;
6229 /* The first offset must be evenly divisible by 8 to ensure the
6230 address is 64 bit aligned. */
6231 if (offset1 % 8 != 0)
6232 return 0;
6234 /* The offset for the second addr must be 4 more than the first addr. */
6235 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
6236 return 0;
6238 /* All the tests passed. addr1 and addr2 are valid for ldd and std
6239 instructions. */
6240 return 1;
6243 /* Return 1 if reg is a pseudo, or is the first register in
6244 a hard register pair. This makes it a candidate for use in
6245 ldd and std insns. */
6248 register_ok_for_ldd (reg)
6249 rtx reg;
6251 /* We might have been passed a SUBREG. */
6252 if (GET_CODE (reg) != REG)
6253 return 0;
6255 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
6256 return (REGNO (reg) % 2 == 0);
6257 else
6258 return 1;
6261 /* Print operand X (an rtx) in assembler syntax to file FILE.
6262 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
6263 For `%' followed by punctuation, CODE is the punctuation and X is null. */
6265 void
6266 print_operand (file, x, code)
6267 FILE *file;
6268 rtx x;
6269 int code;
6271 switch (code)
6273 case '#':
6274 /* Output a 'nop' if there's nothing for the delay slot. */
6275 if (dbr_sequence_length () == 0)
6276 fputs ("\n\t nop", file);
6277 return;
6278 case '*':
6279 /* Output an annul flag if there's nothing for the delay slot and we
6280 are optimizing. This is always used with '(' below. */
6281 /* Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
6282 this is a dbx bug. So, we only do this when optimizing. */
6283 /* On UltraSPARC, a branch in a delay slot causes a pipeline flush.
6284 Always emit a nop in case the next instruction is a branch. */
6285 if (dbr_sequence_length () == 0
6286 && (optimize && (int)sparc_cpu < PROCESSOR_V9))
6287 fputs (",a", file);
6288 return;
6289 case '(':
6290 /* Output a 'nop' if there's nothing for the delay slot and we are
6291 not optimizing. This is always used with '*' above. */
6292 if (dbr_sequence_length () == 0
6293 && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
6294 fputs ("\n\t nop", file);
6295 return;
6296 case '_':
6297 /* Output the Embedded Medium/Anywhere code model base register. */
6298 fputs (EMBMEDANY_BASE_REG, file);
6299 return;
6300 case '@':
6301 /* Print out what we are using as the frame pointer. This might
6302 be %fp, or might be %sp+offset. */
6303 /* ??? What if offset is too big? Perhaps the caller knows it isn't? */
6304 fprintf (file, "%s+%d", frame_base_name, frame_base_offset);
6305 return;
6306 case 'Y':
6307 /* Adjust the operand to take into account a RESTORE operation. */
6308 if (GET_CODE (x) == CONST_INT)
6309 break;
6310 else if (GET_CODE (x) != REG)
6311 output_operand_lossage ("invalid %%Y operand");
6312 else if (REGNO (x) < 8)
6313 fputs (reg_names[REGNO (x)], file);
6314 else if (REGNO (x) >= 24 && REGNO (x) < 32)
6315 fputs (reg_names[REGNO (x)-16], file);
6316 else
6317 output_operand_lossage ("invalid %%Y operand");
6318 return;
6319 case 'L':
6320 /* Print out the low order register name of a register pair. */
6321 if (WORDS_BIG_ENDIAN)
6322 fputs (reg_names[REGNO (x)+1], file);
6323 else
6324 fputs (reg_names[REGNO (x)], file);
6325 return;
6326 case 'H':
6327 /* Print out the high order register name of a register pair. */
6328 if (WORDS_BIG_ENDIAN)
6329 fputs (reg_names[REGNO (x)], file);
6330 else
6331 fputs (reg_names[REGNO (x)+1], file);
6332 return;
6333 case 'R':
6334 /* Print out the second register name of a register pair or quad.
6335 I.e., R (%o0) => %o1. */
6336 fputs (reg_names[REGNO (x)+1], file);
6337 return;
6338 case 'S':
6339 /* Print out the third register name of a register quad.
6340 I.e., S (%o0) => %o2. */
6341 fputs (reg_names[REGNO (x)+2], file);
6342 return;
6343 case 'T':
6344 /* Print out the fourth register name of a register quad.
6345 I.e., T (%o0) => %o3. */
6346 fputs (reg_names[REGNO (x)+3], file);
6347 return;
6348 case 'x':
6349 /* Print a condition code register. */
6350 if (REGNO (x) == SPARC_ICC_REG)
6352 /* We don't handle CC[X]_NOOVmode because they're not supposed
6353 to occur here. */
6354 if (GET_MODE (x) == CCmode)
6355 fputs ("%icc", file);
6356 else if (GET_MODE (x) == CCXmode)
6357 fputs ("%xcc", file);
6358 else
6359 abort ();
6361 else
6362 /* %fccN register */
6363 fputs (reg_names[REGNO (x)], file);
6364 return;
6365 case 'm':
6366 /* Print the operand's address only. */
6367 output_address (XEXP (x, 0));
6368 return;
6369 case 'r':
6370 /* In this case we need a register. Use %g0 if the
6371 operand is const0_rtx. */
6372 if (x == const0_rtx
6373 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
6375 fputs ("%g0", file);
6376 return;
6378 else
6379 break;
6381 case 'A':
6382 switch (GET_CODE (x))
6384 case IOR: fputs ("or", file); break;
6385 case AND: fputs ("and", file); break;
6386 case XOR: fputs ("xor", file); break;
6387 default: output_operand_lossage ("invalid %%A operand");
6389 return;
6391 case 'B':
6392 switch (GET_CODE (x))
6394 case IOR: fputs ("orn", file); break;
6395 case AND: fputs ("andn", file); break;
6396 case XOR: fputs ("xnor", file); break;
6397 default: output_operand_lossage ("invalid %%B operand");
6399 return;
6401 /* These are used by the conditional move instructions. */
6402 case 'c' :
6403 case 'C':
6405 enum rtx_code rc = GET_CODE (x);
6407 if (code == 'c')
6409 enum machine_mode mode = GET_MODE (XEXP (x, 0));
6410 if (mode == CCFPmode || mode == CCFPEmode)
6411 rc = reverse_condition_maybe_unordered (GET_CODE (x));
6412 else
6413 rc = reverse_condition (GET_CODE (x));
6415 switch (rc)
6417 case NE: fputs ("ne", file); break;
6418 case EQ: fputs ("e", file); break;
6419 case GE: fputs ("ge", file); break;
6420 case GT: fputs ("g", file); break;
6421 case LE: fputs ("le", file); break;
6422 case LT: fputs ("l", file); break;
6423 case GEU: fputs ("geu", file); break;
6424 case GTU: fputs ("gu", file); break;
6425 case LEU: fputs ("leu", file); break;
6426 case LTU: fputs ("lu", file); break;
6427 case LTGT: fputs ("lg", file); break;
6428 case UNORDERED: fputs ("u", file); break;
6429 case ORDERED: fputs ("o", file); break;
6430 case UNLT: fputs ("ul", file); break;
6431 case UNLE: fputs ("ule", file); break;
6432 case UNGT: fputs ("ug", file); break;
6433 case UNGE: fputs ("uge", file); break;
6434 case UNEQ: fputs ("ue", file); break;
6435 default: output_operand_lossage (code == 'c'
6436 ? "invalid %%c operand"
6437 : "invalid %%C operand");
6439 return;
6442 /* These are used by the movr instruction pattern. */
6443 case 'd':
6444 case 'D':
6446 enum rtx_code rc = (code == 'd'
6447 ? reverse_condition (GET_CODE (x))
6448 : GET_CODE (x));
6449 switch (rc)
6451 case NE: fputs ("ne", file); break;
6452 case EQ: fputs ("e", file); break;
6453 case GE: fputs ("gez", file); break;
6454 case LT: fputs ("lz", file); break;
6455 case LE: fputs ("lez", file); break;
6456 case GT: fputs ("gz", file); break;
6457 default: output_operand_lossage (code == 'd'
6458 ? "invalid %%d operand"
6459 : "invalid %%D operand");
6461 return;
6464 case 'b':
6466 /* Print a sign-extended character. */
6467 int i = trunc_int_for_mode (INTVAL (x), QImode);
6468 fprintf (file, "%d", i);
6469 return;
6472 case 'f':
6473 /* Operand must be a MEM; write its address. */
6474 if (GET_CODE (x) != MEM)
6475 output_operand_lossage ("invalid %%f operand");
6476 output_address (XEXP (x, 0));
6477 return;
6479 case 0:
6480 /* Do nothing special. */
6481 break;
6483 default:
6484 /* Undocumented flag. */
6485 output_operand_lossage ("invalid operand output code");
6488 if (GET_CODE (x) == REG)
6489 fputs (reg_names[REGNO (x)], file);
6490 else if (GET_CODE (x) == MEM)
6492 fputc ('[', file);
6493 /* Poor Sun assembler doesn't understand absolute addressing. */
6494 if (CONSTANT_P (XEXP (x, 0)))
6495 fputs ("%g0+", file);
6496 output_address (XEXP (x, 0));
6497 fputc (']', file);
6499 else if (GET_CODE (x) == HIGH)
6501 fputs ("%hi(", file);
6502 output_addr_const (file, XEXP (x, 0));
6503 fputc (')', file);
6505 else if (GET_CODE (x) == LO_SUM)
6507 print_operand (file, XEXP (x, 0), 0);
6508 if (TARGET_CM_MEDMID)
6509 fputs ("+%l44(", file);
6510 else
6511 fputs ("+%lo(", file);
6512 output_addr_const (file, XEXP (x, 1));
6513 fputc (')', file);
6515 else if (GET_CODE (x) == CONST_DOUBLE
6516 && (GET_MODE (x) == VOIDmode
6517 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
6519 if (CONST_DOUBLE_HIGH (x) == 0)
6520 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
6521 else if (CONST_DOUBLE_HIGH (x) == -1
6522 && CONST_DOUBLE_LOW (x) < 0)
6523 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
6524 else
6525 output_operand_lossage ("long long constant not a valid immediate operand");
6527 else if (GET_CODE (x) == CONST_DOUBLE)
6528 output_operand_lossage ("floating point constant not a valid immediate operand");
6529 else { output_addr_const (file, x); }
6532 /* Target hook for assembling integer objects. The sparc version has
6533 special handling for aligned DI-mode objects. */
6535 static bool
6536 sparc_assemble_integer (x, size, aligned_p)
6537 rtx x;
6538 unsigned int size;
6539 int aligned_p;
6541 /* ??? We only output .xword's for symbols and only then in environments
6542 where the assembler can handle them. */
6543 if (aligned_p && size == 8
6544 && (GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE))
6546 if (TARGET_V9)
6548 assemble_integer_with_op ("\t.xword\t", x);
6549 return true;
6551 else
6553 assemble_aligned_integer (4, const0_rtx);
6554 assemble_aligned_integer (4, x);
6555 return true;
6558 return default_assemble_integer (x, size, aligned_p);
6561 /* Return the value of a code used in the .proc pseudo-op that says
6562 what kind of result this function returns. For non-C types, we pick
6563 the closest C type. */
6565 #ifndef SHORT_TYPE_SIZE
6566 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
6567 #endif
6569 #ifndef INT_TYPE_SIZE
6570 #define INT_TYPE_SIZE BITS_PER_WORD
6571 #endif
6573 #ifndef LONG_TYPE_SIZE
6574 #define LONG_TYPE_SIZE BITS_PER_WORD
6575 #endif
6577 #ifndef LONG_LONG_TYPE_SIZE
6578 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
6579 #endif
6581 #ifndef FLOAT_TYPE_SIZE
6582 #define FLOAT_TYPE_SIZE BITS_PER_WORD
6583 #endif
6585 #ifndef DOUBLE_TYPE_SIZE
6586 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6587 #endif
6589 #ifndef LONG_DOUBLE_TYPE_SIZE
6590 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6591 #endif
6593 unsigned long
6594 sparc_type_code (type)
6595 register tree type;
6597 register unsigned long qualifiers = 0;
6598 register unsigned shift;
6600 /* Only the first 30 bits of the qualifier are valid. We must refrain from
6601 setting more, since some assemblers will give an error for this. Also,
6602 we must be careful to avoid shifts of 32 bits or more to avoid getting
6603 unpredictable results. */
6605 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
6607 switch (TREE_CODE (type))
6609 case ERROR_MARK:
6610 return qualifiers;
6612 case ARRAY_TYPE:
6613 qualifiers |= (3 << shift);
6614 break;
6616 case FUNCTION_TYPE:
6617 case METHOD_TYPE:
6618 qualifiers |= (2 << shift);
6619 break;
6621 case POINTER_TYPE:
6622 case REFERENCE_TYPE:
6623 case OFFSET_TYPE:
6624 qualifiers |= (1 << shift);
6625 break;
6627 case RECORD_TYPE:
6628 return (qualifiers | 8);
6630 case UNION_TYPE:
6631 case QUAL_UNION_TYPE:
6632 return (qualifiers | 9);
6634 case ENUMERAL_TYPE:
6635 return (qualifiers | 10);
6637 case VOID_TYPE:
6638 return (qualifiers | 16);
6640 case INTEGER_TYPE:
6641 /* If this is a range type, consider it to be the underlying
6642 type. */
6643 if (TREE_TYPE (type) != 0)
6644 break;
6646 /* Carefully distinguish all the standard types of C,
6647 without messing up if the language is not C. We do this by
6648 testing TYPE_PRECISION and TREE_UNSIGNED. The old code used to
6649 look at both the names and the above fields, but that's redundant.
6650 Any type whose size is between two C types will be considered
6651 to be the wider of the two types. Also, we do not have a
6652 special code to use for "long long", so anything wider than
6653 long is treated the same. Note that we can't distinguish
6654 between "int" and "long" in this code if they are the same
6655 size, but that's fine, since neither can the assembler. */
6657 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
6658 return (qualifiers | (TREE_UNSIGNED (type) ? 12 : 2));
6660 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
6661 return (qualifiers | (TREE_UNSIGNED (type) ? 13 : 3));
6663 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
6664 return (qualifiers | (TREE_UNSIGNED (type) ? 14 : 4));
6666 else
6667 return (qualifiers | (TREE_UNSIGNED (type) ? 15 : 5));
6669 case REAL_TYPE:
6670 /* If this is a range type, consider it to be the underlying
6671 type. */
6672 if (TREE_TYPE (type) != 0)
6673 break;
6675 /* Carefully distinguish all the standard types of C,
6676 without messing up if the language is not C. */
6678 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
6679 return (qualifiers | 6);
6681 else
6682 return (qualifiers | 7);
6684 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
6685 /* ??? We need to distinguish between double and float complex types,
6686 but I don't know how yet because I can't reach this code from
6687 existing front-ends. */
6688 return (qualifiers | 7); /* Who knows? */
6690 case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */
6691 case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */
6692 case FILE_TYPE: /* GNU Pascal FILE type. */
6693 case SET_TYPE: /* GNU Pascal SET type. */
6694 case LANG_TYPE: /* ? */
6695 return qualifiers;
6697 default:
6698 abort (); /* Not a type! */
6702 return qualifiers;
6705 /* Nested function support. */
6707 /* Emit RTL insns to initialize the variable parts of a trampoline.
6708 FNADDR is an RTX for the address of the function's pure code.
6709 CXT is an RTX for the static chain value for the function.
6711 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
6712 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
6713 (to store insns). This is a bit excessive. Perhaps a different
6714 mechanism would be better here.
6716 Emit enough FLUSH insns to synchronize the data and instruction caches. */
6718 void
6719 sparc_initialize_trampoline (tramp, fnaddr, cxt)
6720 rtx tramp, fnaddr, cxt;
6722 /* SPARC 32 bit trampoline:
6724 sethi %hi(fn), %g1
6725 sethi %hi(static), %g2
6726 jmp %g1+%lo(fn)
6727 or %g2, %lo(static), %g2
6729 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
6730 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
6732 #ifdef TRANSFER_FROM_TRAMPOLINE
6733 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
6734 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
6735 #endif
6737 emit_move_insn
6738 (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
6739 expand_binop (SImode, ior_optab,
6740 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
6741 size_int (10), 0, 1),
6742 GEN_INT (trunc_int_for_mode (0x03000000, SImode)),
6743 NULL_RTX, 1, OPTAB_DIRECT));
6745 emit_move_insn
6746 (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6747 expand_binop (SImode, ior_optab,
6748 expand_shift (RSHIFT_EXPR, SImode, cxt,
6749 size_int (10), 0, 1),
6750 GEN_INT (trunc_int_for_mode (0x05000000, SImode)),
6751 NULL_RTX, 1, OPTAB_DIRECT));
6753 emit_move_insn
6754 (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6755 expand_binop (SImode, ior_optab,
6756 expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
6757 GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
6758 NULL_RTX, 1, OPTAB_DIRECT));
6760 emit_move_insn
6761 (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6762 expand_binop (SImode, ior_optab,
6763 expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
6764 GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
6765 NULL_RTX, 1, OPTAB_DIRECT));
6767 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
6768 aligned on a 16 byte boundary so one flush clears it all. */
6769 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode, tramp))));
6770 if (sparc_cpu != PROCESSOR_ULTRASPARC
6771 && sparc_cpu != PROCESSOR_ULTRASPARC3)
6772 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode,
6773 plus_constant (tramp, 8)))));
6776 /* The 64 bit version is simpler because it makes more sense to load the
6777 values as "immediate" data out of the trampoline. It's also easier since
6778 we can read the PC without clobbering a register. */
6780 void
6781 sparc64_initialize_trampoline (tramp, fnaddr, cxt)
6782 rtx tramp, fnaddr, cxt;
6784 #ifdef TRANSFER_FROM_TRAMPOLINE
6785 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
6786 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
6787 #endif
6790 rd %pc, %g1
6791 ldx [%g1+24], %g5
6792 jmp %g5
6793 ldx [%g1+16], %g5
6794 +16 bytes data
6797 emit_move_insn (gen_rtx_MEM (SImode, tramp),
6798 GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
6799 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6800 GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
6801 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6802 GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
6803 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6804 GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
6805 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
6806 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
6807 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
6809 if (sparc_cpu != PROCESSOR_ULTRASPARC
6810 && sparc_cpu != PROCESSOR_ULTRASPARC3)
6811 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));
6814 /* Subroutines to support a flat (single) register window calling
6815 convention. */
6817 /* Single-register window sparc stack frames look like:
6819 Before call After call
6820 +-----------------------+ +-----------------------+
6821 high | | | |
6822 mem | caller's temps. | | caller's temps. |
6823 | | | |
6824 +-----------------------+ +-----------------------+
6825 | | | |
6826 | arguments on stack. | | arguments on stack. |
6827 | | | |
6828 +-----------------------+FP+92->+-----------------------+
6829 | 6 words to save | | 6 words to save |
6830 | arguments passed | | arguments passed |
6831 | in registers, even | | in registers, even |
6832 | if not passed. | | if not passed. |
6833 SP+68->+-----------------------+FP+68->+-----------------------+
6834 | 1 word struct addr | | 1 word struct addr |
6835 +-----------------------+FP+64->+-----------------------+
6836 | | | |
6837 | 16 word reg save area | | 16 word reg save area |
6838 | | | |
6839 SP->+-----------------------+ FP->+-----------------------+
6840 | 4 word area for |
6841 | fp/alu reg moves |
6842 FP-16->+-----------------------+
6844 | local variables |
6846 +-----------------------+
6848 | fp register save |
6850 +-----------------------+
6852 | gp register save |
6854 +-----------------------+
6856 | alloca allocations |
6858 +-----------------------+
6860 | arguments on stack |
6862 SP+92->+-----------------------+
6863 | 6 words to save |
6864 | arguments passed |
6865 | in registers, even |
6866 low | if not passed. |
6867 memory SP+68->+-----------------------+
6868 | 1 word struct addr |
6869 SP+64->+-----------------------+
6871 I 16 word reg save area |
6873 SP->+-----------------------+ */
6875 /* Structure to be filled in by sparc_flat_compute_frame_size with register
6876 save masks, and offsets for the current function. */
6878 struct sparc_frame_info
6880 unsigned long total_size; /* # bytes that the entire frame takes up. */
6881 unsigned long var_size; /* # bytes that variables take up. */
6882 unsigned long args_size; /* # bytes that outgoing arguments take up. */
6883 unsigned long extra_size; /* # bytes of extra gunk. */
6884 unsigned int gp_reg_size; /* # bytes needed to store gp regs. */
6885 unsigned int fp_reg_size; /* # bytes needed to store fp regs. */
6886 unsigned long gmask; /* Mask of saved gp registers. */
6887 unsigned long fmask; /* Mask of saved fp registers. */
6888 unsigned long reg_offset; /* Offset from new sp to store regs. */
6889 int initialized; /* Nonzero if frame size already calculated. */
6892 /* Current frame information calculated by sparc_flat_compute_frame_size. */
6893 struct sparc_frame_info current_frame_info;
6895 /* Zero structure to initialize current_frame_info. */
6896 struct sparc_frame_info zero_frame_info;
6898 /* Tell prologue and epilogue if register REGNO should be saved / restored. */
6900 #define RETURN_ADDR_REGNUM 15
6901 #define HARD_FRAME_POINTER_MASK (1 << (HARD_FRAME_POINTER_REGNUM))
6902 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
6904 #define MUST_SAVE_REGISTER(regno) \
6905 ((regs_ever_live[regno] && !call_used_regs[regno]) \
6906 || (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed) \
6907 || (regno == RETURN_ADDR_REGNUM && regs_ever_live[RETURN_ADDR_REGNUM]))
6909 /* Return the bytes needed to compute the frame pointer from the current
6910 stack pointer. */
6912 unsigned long
6913 sparc_flat_compute_frame_size (size)
6914 int size; /* # of var. bytes allocated. */
6916 int regno;
6917 unsigned long total_size; /* # bytes that the entire frame takes up. */
6918 unsigned long var_size; /* # bytes that variables take up. */
6919 unsigned long args_size; /* # bytes that outgoing arguments take up. */
6920 unsigned long extra_size; /* # extra bytes. */
6921 unsigned int gp_reg_size; /* # bytes needed to store gp regs. */
6922 unsigned int fp_reg_size; /* # bytes needed to store fp regs. */
6923 unsigned long gmask; /* Mask of saved gp registers. */
6924 unsigned long fmask; /* Mask of saved fp registers. */
6925 unsigned long reg_offset; /* Offset to register save area. */
6926 int need_aligned_p; /* 1 if need the save area 8 byte aligned. */
6928 /* This is the size of the 16 word reg save area, 1 word struct addr
6929 area, and 4 word fp/alu register copy area. */
6930 extra_size = -STARTING_FRAME_OFFSET + FIRST_PARM_OFFSET(0);
6931 var_size = size;
6932 gp_reg_size = 0;
6933 fp_reg_size = 0;
6934 gmask = 0;
6935 fmask = 0;
6936 reg_offset = 0;
6937 need_aligned_p = 0;
6939 args_size = 0;
6940 if (!leaf_function_p ())
6942 /* Also include the size needed for the 6 parameter registers. */
6943 args_size = current_function_outgoing_args_size + 24;
6945 total_size = var_size + args_size;
6947 /* Calculate space needed for gp registers. */
6948 for (regno = 1; regno <= 31; regno++)
6950 if (MUST_SAVE_REGISTER (regno))
6952 /* If we need to save two regs in a row, ensure there's room to bump
6953 up the address to align it to a doubleword boundary. */
6954 if ((regno & 0x1) == 0 && MUST_SAVE_REGISTER (regno+1))
6956 if (gp_reg_size % 8 != 0)
6957 gp_reg_size += 4;
6958 gp_reg_size += 2 * UNITS_PER_WORD;
6959 gmask |= 3 << regno;
6960 regno++;
6961 need_aligned_p = 1;
6963 else
6965 gp_reg_size += UNITS_PER_WORD;
6966 gmask |= 1 << regno;
6971 /* Calculate space needed for fp registers. */
6972 for (regno = 32; regno <= 63; regno++)
6974 if (regs_ever_live[regno] && !call_used_regs[regno])
6976 fp_reg_size += UNITS_PER_WORD;
6977 fmask |= 1 << (regno - 32);
6981 if (gmask || fmask)
6983 int n;
6984 reg_offset = FIRST_PARM_OFFSET(0) + args_size;
6985 /* Ensure save area is 8 byte aligned if we need it. */
6986 n = reg_offset % 8;
6987 if (need_aligned_p && n != 0)
6989 total_size += 8 - n;
6990 reg_offset += 8 - n;
6992 total_size += gp_reg_size + fp_reg_size;
6995 /* If we must allocate a stack frame at all, we must also allocate
6996 room for register window spillage, so as to be binary compatible
6997 with libraries and operating systems that do not use -mflat. */
6998 if (total_size > 0)
6999 total_size += extra_size;
7000 else
7001 extra_size = 0;
7003 total_size = SPARC_STACK_ALIGN (total_size);
7005 /* Save other computed information. */
7006 current_frame_info.total_size = total_size;
7007 current_frame_info.var_size = var_size;
7008 current_frame_info.args_size = args_size;
7009 current_frame_info.extra_size = extra_size;
7010 current_frame_info.gp_reg_size = gp_reg_size;
7011 current_frame_info.fp_reg_size = fp_reg_size;
7012 current_frame_info.gmask = gmask;
7013 current_frame_info.fmask = fmask;
7014 current_frame_info.reg_offset = reg_offset;
7015 current_frame_info.initialized = reload_completed;
7017 /* Ok, we're done. */
7018 return total_size;
7021 /* Save/restore registers in GMASK and FMASK at register BASE_REG plus offset
7022 OFFSET.
7024 BASE_REG must be 8 byte aligned. This allows us to test OFFSET for
7025 appropriate alignment and use DOUBLEWORD_OP when we can. We assume
7026 [BASE_REG+OFFSET] will always be a valid address.
7028 WORD_OP is either "st" for save, "ld" for restore.
7029 DOUBLEWORD_OP is either "std" for save, "ldd" for restore. */
7031 void
7032 sparc_flat_save_restore (file, base_reg, offset, gmask, fmask, word_op,
7033 doubleword_op, base_offset)
7034 FILE *file;
7035 const char *base_reg;
7036 unsigned int offset;
7037 unsigned long gmask;
7038 unsigned long fmask;
7039 const char *word_op;
7040 const char *doubleword_op;
7041 unsigned long base_offset;
7043 int regno;
7045 if (gmask == 0 && fmask == 0)
7046 return;
7048 /* Save registers starting from high to low. We've already saved the
7049 previous frame pointer and previous return address for the debugger's
7050 sake. The debugger allows us to not need a nop in the epilog if at least
7051 one register is reloaded in addition to return address. */
7053 if (gmask)
7055 for (regno = 1; regno <= 31; regno++)
7057 if ((gmask & (1L << regno)) != 0)
7059 if ((regno & 0x1) == 0 && ((gmask & (1L << (regno+1))) != 0))
7061 /* We can save two registers in a row. If we're not at a
7062 double word boundary, move to one.
7063 sparc_flat_compute_frame_size ensures there's room to do
7064 this. */
7065 if (offset % 8 != 0)
7066 offset += UNITS_PER_WORD;
7068 if (word_op[0] == 's')
7070 fprintf (file, "\t%s\t%s, [%s+%d]\n",
7071 doubleword_op, reg_names[regno],
7072 base_reg, offset);
7073 if (dwarf2out_do_frame ())
7075 char *l = dwarf2out_cfi_label ();
7076 dwarf2out_reg_save (l, regno, offset + base_offset);
7077 dwarf2out_reg_save
7078 (l, regno+1, offset+base_offset + UNITS_PER_WORD);
7081 else
7082 fprintf (file, "\t%s\t[%s+%d], %s\n",
7083 doubleword_op, base_reg, offset,
7084 reg_names[regno]);
7086 offset += 2 * UNITS_PER_WORD;
7087 regno++;
7089 else
7091 if (word_op[0] == 's')
7093 fprintf (file, "\t%s\t%s, [%s+%d]\n",
7094 word_op, reg_names[regno],
7095 base_reg, offset);
7096 if (dwarf2out_do_frame ())
7097 dwarf2out_reg_save ("", regno, offset + base_offset);
7099 else
7100 fprintf (file, "\t%s\t[%s+%d], %s\n",
7101 word_op, base_reg, offset, reg_names[regno]);
7103 offset += UNITS_PER_WORD;
7109 if (fmask)
7111 for (regno = 32; regno <= 63; regno++)
7113 if ((fmask & (1L << (regno - 32))) != 0)
7115 if (word_op[0] == 's')
7117 fprintf (file, "\t%s\t%s, [%s+%d]\n",
7118 word_op, reg_names[regno],
7119 base_reg, offset);
7120 if (dwarf2out_do_frame ())
7121 dwarf2out_reg_save ("", regno, offset + base_offset);
7123 else
7124 fprintf (file, "\t%s\t[%s+%d], %s\n",
7125 word_op, base_reg, offset, reg_names[regno]);
7127 offset += UNITS_PER_WORD;
7133 /* Set up the stack and frame (if desired) for the function. */
7135 static void
7136 sparc_flat_function_prologue (file, size)
7137 FILE *file;
7138 HOST_WIDE_INT size;
7140 const char *sp_str = reg_names[STACK_POINTER_REGNUM];
7141 unsigned long gmask = current_frame_info.gmask;
7143 sparc_output_scratch_registers (file);
7145 /* This is only for the human reader. */
7146 fprintf (file, "\t%s#PROLOGUE# 0\n", ASM_COMMENT_START);
7147 fprintf (file, "\t%s# vars= %ld, regs= %d/%d, args= %d, extra= %ld\n",
7148 ASM_COMMENT_START,
7149 current_frame_info.var_size,
7150 current_frame_info.gp_reg_size / 4,
7151 current_frame_info.fp_reg_size / 4,
7152 current_function_outgoing_args_size,
7153 current_frame_info.extra_size);
7155 size = SPARC_STACK_ALIGN (size);
7156 size = (! current_frame_info.initialized
7157 ? sparc_flat_compute_frame_size (size)
7158 : current_frame_info.total_size);
7160 /* These cases shouldn't happen. Catch them now. */
7161 if (size == 0 && (gmask || current_frame_info.fmask))
7162 abort ();
7164 /* Allocate our stack frame by decrementing %sp.
7165 At present, the only algorithm gdb can use to determine if this is a
7166 flat frame is if we always set %i7 if we set %sp. This can be optimized
7167 in the future by putting in some sort of debugging information that says
7168 this is a `flat' function. However, there is still the case of debugging
7169 code without such debugging information (including cases where most fns
7170 have such info, but there is one that doesn't). So, always do this now
7171 so we don't get a lot of code out there that gdb can't handle.
7172 If the frame pointer isn't needn't then that's ok - gdb won't be able to
7173 distinguish us from a non-flat function but there won't (and shouldn't)
7174 be any differences anyway. The return pc is saved (if necessary) right
7175 after %i7 so gdb won't have to look too far to find it. */
7176 if (size > 0)
7178 unsigned int reg_offset = current_frame_info.reg_offset;
7179 const char *const fp_str = reg_names[HARD_FRAME_POINTER_REGNUM];
7180 static const char *const t1_str = "%g1";
7182 /* Things get a little tricky if local variables take up more than ~4096
7183 bytes and outgoing arguments take up more than ~4096 bytes. When that
7184 happens, the register save area can't be accessed from either end of
7185 the frame. Handle this by decrementing %sp to the start of the gp
7186 register save area, save the regs, update %i7, and then set %sp to its
7187 final value. Given that we only have one scratch register to play
7188 with it is the cheapest solution, and it helps gdb out as it won't
7189 slow down recognition of flat functions.
7190 Don't change the order of insns emitted here without checking with
7191 the gdb folk first. */
7193 /* Is the entire register save area offsettable from %sp? */
7194 if (reg_offset < 4096 - 64 * (unsigned) UNITS_PER_WORD)
7196 if (size <= 4096)
7198 fprintf (file, "\tadd\t%s, %d, %s\n",
7199 sp_str, (int) -size, sp_str);
7200 if (gmask & HARD_FRAME_POINTER_MASK)
7202 fprintf (file, "\tst\t%s, [%s+%d]\n",
7203 fp_str, sp_str, reg_offset);
7204 fprintf (file, "\tsub\t%s, %d, %s\t%s# set up frame pointer\n",
7205 sp_str, (int) -size, fp_str, ASM_COMMENT_START);
7206 reg_offset += 4;
7209 else
7211 fprintf (file, "\tset\t");
7212 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
7213 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
7214 t1_str, sp_str, t1_str, sp_str);
7215 if (gmask & HARD_FRAME_POINTER_MASK)
7217 fprintf (file, "\tst\t%s, [%s+%d]\n",
7218 fp_str, sp_str, reg_offset);
7219 fprintf (file, "\tadd\t%s, %s, %s\t%s# set up frame pointer\n",
7220 sp_str, t1_str, fp_str, ASM_COMMENT_START);
7221 reg_offset += 4;
7224 if (dwarf2out_do_frame ())
7226 char *l = dwarf2out_cfi_label ();
7227 if (gmask & HARD_FRAME_POINTER_MASK)
7229 dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM,
7230 reg_offset - 4 - size);
7231 dwarf2out_def_cfa (l, HARD_FRAME_POINTER_REGNUM, 0);
7233 else
7234 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size);
7236 if (gmask & RETURN_ADDR_MASK)
7238 fprintf (file, "\tst\t%s, [%s+%d]\n",
7239 reg_names[RETURN_ADDR_REGNUM], sp_str, reg_offset);
7240 if (dwarf2out_do_frame ())
7241 dwarf2out_return_save ("", reg_offset - size);
7242 reg_offset += 4;
7244 sparc_flat_save_restore (file, sp_str, reg_offset,
7245 gmask & ~(HARD_FRAME_POINTER_MASK | RETURN_ADDR_MASK),
7246 current_frame_info.fmask,
7247 "st", "std", -size);
7249 else
7251 /* Subtract %sp in two steps, but make sure there is always a
7252 64 byte register save area, and %sp is properly aligned. */
7253 /* Amount to decrement %sp by, the first time. */
7254 unsigned HOST_WIDE_INT size1 = ((size - reg_offset + 64) + 15) & -16;
7255 /* Offset to register save area from %sp. */
7256 unsigned HOST_WIDE_INT offset = size1 - (size - reg_offset);
7258 if (size1 <= 4096)
7260 fprintf (file, "\tadd\t%s, %d, %s\n",
7261 sp_str, (int) -size1, sp_str);
7262 if (gmask & HARD_FRAME_POINTER_MASK)
7264 fprintf (file, "\tst\t%s, [%s+%d]\n\tsub\t%s, %d, %s\t%s# set up frame pointer\n",
7265 fp_str, sp_str, (int) offset, sp_str, (int) -size1,
7266 fp_str, ASM_COMMENT_START);
7267 offset += 4;
7270 else
7272 fprintf (file, "\tset\t");
7273 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size1);
7274 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
7275 t1_str, sp_str, t1_str, sp_str);
7276 if (gmask & HARD_FRAME_POINTER_MASK)
7278 fprintf (file, "\tst\t%s, [%s+%d]\n\tadd\t%s, %s, %s\t%s# set up frame pointer\n",
7279 fp_str, sp_str, (int) offset, sp_str, t1_str,
7280 fp_str, ASM_COMMENT_START);
7281 offset += 4;
7284 if (dwarf2out_do_frame ())
7286 char *l = dwarf2out_cfi_label ();
7287 if (gmask & HARD_FRAME_POINTER_MASK)
7289 dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM,
7290 offset - 4 - size1);
7291 dwarf2out_def_cfa (l, HARD_FRAME_POINTER_REGNUM, 0);
7293 else
7294 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size1);
7296 if (gmask & RETURN_ADDR_MASK)
7298 fprintf (file, "\tst\t%s, [%s+%d]\n",
7299 reg_names[RETURN_ADDR_REGNUM], sp_str, (int) offset);
7300 if (dwarf2out_do_frame ())
7301 /* offset - size1 == reg_offset - size
7302 if reg_offset were updated above like offset. */
7303 dwarf2out_return_save ("", offset - size1);
7304 offset += 4;
7306 sparc_flat_save_restore (file, sp_str, offset,
7307 gmask & ~(HARD_FRAME_POINTER_MASK | RETURN_ADDR_MASK),
7308 current_frame_info.fmask,
7309 "st", "std", -size1);
7310 fprintf (file, "\tset\t");
7311 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size - size1);
7312 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
7313 t1_str, sp_str, t1_str, sp_str);
7314 if (dwarf2out_do_frame ())
7315 if (! (gmask & HARD_FRAME_POINTER_MASK))
7316 dwarf2out_def_cfa ("", STACK_POINTER_REGNUM, size);
7320 fprintf (file, "\t%s#PROLOGUE# 1\n", ASM_COMMENT_START);
7323 /* Do any necessary cleanup after a function to restore stack, frame,
7324 and regs. */
7326 static void
7327 sparc_flat_function_epilogue (file, size)
7328 FILE *file;
7329 HOST_WIDE_INT size;
7331 rtx epilogue_delay = current_function_epilogue_delay_list;
7332 int noepilogue = FALSE;
7334 /* This is only for the human reader. */
7335 fprintf (file, "\t%s#EPILOGUE#\n", ASM_COMMENT_START);
7337 /* The epilogue does not depend on any registers, but the stack
7338 registers, so we assume that if we have 1 pending nop, it can be
7339 ignored, and 2 it must be filled (2 nops occur for integer
7340 multiply and divide). */
7342 size = SPARC_STACK_ALIGN (size);
7343 size = (!current_frame_info.initialized
7344 ? sparc_flat_compute_frame_size (size)
7345 : current_frame_info.total_size);
7347 if (size == 0 && epilogue_delay == 0)
7349 rtx insn = get_last_insn ();
7351 /* If the last insn was a BARRIER, we don't have to write any code
7352 because a jump (aka return) was put there. */
7353 if (GET_CODE (insn) == NOTE)
7354 insn = prev_nonnote_insn (insn);
7355 if (insn && GET_CODE (insn) == BARRIER)
7356 noepilogue = TRUE;
7359 if (!noepilogue)
7361 unsigned HOST_WIDE_INT reg_offset = current_frame_info.reg_offset;
7362 unsigned HOST_WIDE_INT size1;
7363 const char *const sp_str = reg_names[STACK_POINTER_REGNUM];
7364 const char *const fp_str = reg_names[HARD_FRAME_POINTER_REGNUM];
7365 static const char *const t1_str = "%g1";
7367 /* In the reload sequence, we don't need to fill the load delay
7368 slots for most of the loads, also see if we can fill the final
7369 delay slot if not otherwise filled by the reload sequence. */
7371 if (size > 4095)
7373 fprintf (file, "\tset\t");
7374 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
7375 fprintf (file, ", %s\n", t1_str);
7378 if (frame_pointer_needed)
7380 if (size > 4095)
7381 fprintf (file,"\tsub\t%s, %s, %s\t\t%s# sp not trusted here\n",
7382 fp_str, t1_str, sp_str, ASM_COMMENT_START);
7383 else
7384 fprintf (file,"\tsub\t%s, %d, %s\t\t%s# sp not trusted here\n",
7385 fp_str, (int) size, sp_str, ASM_COMMENT_START);
7388 /* Is the entire register save area offsettable from %sp? */
7389 if (reg_offset < 4096 - 64 * (unsigned) UNITS_PER_WORD)
7391 size1 = 0;
7393 else
7395 /* Restore %sp in two steps, but make sure there is always a
7396 64 byte register save area, and %sp is properly aligned. */
7397 /* Amount to increment %sp by, the first time. */
7398 size1 = ((reg_offset - 64 - 16) + 15) & -16;
7399 /* Offset to register save area from %sp. */
7400 reg_offset = size1 - reg_offset;
7402 fprintf (file, "\tset\t");
7403 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size1);
7404 fprintf (file, ", %s\n\tadd\t%s, %s, %s\n",
7405 t1_str, sp_str, t1_str, sp_str);
7408 /* We must restore the frame pointer and return address reg first
7409 because they are treated specially by the prologue output code. */
7410 if (current_frame_info.gmask & HARD_FRAME_POINTER_MASK)
7412 fprintf (file, "\tld\t[%s+%d], %s\n",
7413 sp_str, (int) reg_offset, fp_str);
7414 reg_offset += 4;
7416 if (current_frame_info.gmask & RETURN_ADDR_MASK)
7418 fprintf (file, "\tld\t[%s+%d], %s\n",
7419 sp_str, (int) reg_offset, reg_names[RETURN_ADDR_REGNUM]);
7420 reg_offset += 4;
7423 /* Restore any remaining saved registers. */
7424 sparc_flat_save_restore (file, sp_str, reg_offset,
7425 current_frame_info.gmask & ~(HARD_FRAME_POINTER_MASK | RETURN_ADDR_MASK),
7426 current_frame_info.fmask,
7427 "ld", "ldd", 0);
7429 /* If we had to increment %sp in two steps, record it so the second
7430 restoration in the epilogue finishes up. */
7431 if (size1 > 0)
7433 size -= size1;
7434 if (size > 4095)
7436 fprintf (file, "\tset\t");
7437 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
7438 fprintf (file, ", %s\n", t1_str);
7442 if (current_function_returns_struct)
7443 fprintf (file, "\tjmp\t%%o7+12\n");
7444 else
7445 fprintf (file, "\tretl\n");
7447 /* If the only register saved is the return address, we need a
7448 nop, unless we have an instruction to put into it. Otherwise
7449 we don't since reloading multiple registers doesn't reference
7450 the register being loaded. */
7452 if (epilogue_delay)
7454 if (size)
7455 abort ();
7456 final_scan_insn (XEXP (epilogue_delay, 0), file, 1, -2, 1);
7459 else if (size > 4095)
7460 fprintf (file, "\tadd\t%s, %s, %s\n", sp_str, t1_str, sp_str);
7462 else if (size > 0)
7463 fprintf (file, "\tadd\t%s, %d, %s\n", sp_str, (int) size, sp_str);
7465 else
7466 fprintf (file, "\tnop\n");
7469 /* Reset state info for each function. */
7470 current_frame_info = zero_frame_info;
7472 sparc_output_deferred_case_vectors ();
7475 /* Define the number of delay slots needed for the function epilogue.
7477 On the sparc, we need a slot if either no stack has been allocated,
7478 or the only register saved is the return register. */
7481 sparc_flat_epilogue_delay_slots ()
7483 if (!current_frame_info.initialized)
7484 (void) sparc_flat_compute_frame_size (get_frame_size ());
7486 if (current_frame_info.total_size == 0)
7487 return 1;
7489 return 0;
7492 /* Return true if TRIAL is a valid insn for the epilogue delay slot.
7493 Any single length instruction which doesn't reference the stack or frame
7494 pointer is OK. */
7497 sparc_flat_eligible_for_epilogue_delay (trial, slot)
7498 rtx trial;
7499 int slot ATTRIBUTE_UNUSED;
7501 rtx pat = PATTERN (trial);
7503 if (get_attr_length (trial) != 1)
7504 return 0;
7506 if (! reg_mentioned_p (stack_pointer_rtx, pat)
7507 && ! reg_mentioned_p (frame_pointer_rtx, pat))
7508 return 1;
7510 return 0;
7513 /* Adjust the cost of a scheduling dependency. Return the new cost of
7514 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7516 static int
7517 supersparc_adjust_cost (insn, link, dep_insn, cost)
7518 rtx insn;
7519 rtx link;
7520 rtx dep_insn;
7521 int cost;
7523 enum attr_type insn_type;
7525 if (! recog_memoized (insn))
7526 return 0;
7528 insn_type = get_attr_type (insn);
7530 if (REG_NOTE_KIND (link) == 0)
7532 /* Data dependency; DEP_INSN writes a register that INSN reads some
7533 cycles later. */
7535 /* if a load, then the dependence must be on the memory address;
7536 add an extra "cycle". Note that the cost could be two cycles
7537 if the reg was written late in an instruction group; we ca not tell
7538 here. */
7539 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
7540 return cost + 3;
7542 /* Get the delay only if the address of the store is the dependence. */
7543 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
7545 rtx pat = PATTERN(insn);
7546 rtx dep_pat = PATTERN (dep_insn);
7548 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7549 return cost; /* This should not happen! */
7551 /* The dependency between the two instructions was on the data that
7552 is being stored. Assume that this implies that the address of the
7553 store is not dependent. */
7554 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7555 return cost;
7557 return cost + 3; /* An approximation. */
7560 /* A shift instruction cannot receive its data from an instruction
7561 in the same cycle; add a one cycle penalty. */
7562 if (insn_type == TYPE_SHIFT)
7563 return cost + 3; /* Split before cascade into shift. */
7565 else
7567 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
7568 INSN writes some cycles later. */
7570 /* These are only significant for the fpu unit; writing a fp reg before
7571 the fpu has finished with it stalls the processor. */
7573 /* Reusing an integer register causes no problems. */
7574 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7575 return 0;
7578 return cost;
7581 static int
7582 hypersparc_adjust_cost (insn, link, dep_insn, cost)
7583 rtx insn;
7584 rtx link;
7585 rtx dep_insn;
7586 int cost;
7588 enum attr_type insn_type, dep_type;
7589 rtx pat = PATTERN(insn);
7590 rtx dep_pat = PATTERN (dep_insn);
7592 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7593 return cost;
7595 insn_type = get_attr_type (insn);
7596 dep_type = get_attr_type (dep_insn);
7598 switch (REG_NOTE_KIND (link))
7600 case 0:
7601 /* Data dependency; DEP_INSN writes a register that INSN reads some
7602 cycles later. */
7604 switch (insn_type)
7606 case TYPE_STORE:
7607 case TYPE_FPSTORE:
7608 /* Get the delay iff the address of the store is the dependence. */
7609 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7610 return cost;
7612 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7613 return cost;
7614 return cost + 3;
7616 case TYPE_LOAD:
7617 case TYPE_SLOAD:
7618 case TYPE_FPLOAD:
7619 /* If a load, then the dependence must be on the memory address. If
7620 the addresses aren't equal, then it might be a false dependency */
7621 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7623 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7624 || GET_CODE (SET_DEST (dep_pat)) != MEM
7625 || GET_CODE (SET_SRC (pat)) != MEM
7626 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
7627 XEXP (SET_SRC (pat), 0)))
7628 return cost + 2;
7630 return cost + 8;
7632 break;
7634 case TYPE_BRANCH:
7635 /* Compare to branch latency is 0. There is no benefit from
7636 separating compare and branch. */
7637 if (dep_type == TYPE_COMPARE)
7638 return 0;
7639 /* Floating point compare to branch latency is less than
7640 compare to conditional move. */
7641 if (dep_type == TYPE_FPCMP)
7642 return cost - 1;
7643 break;
7644 default:
7645 break;
7647 break;
7649 case REG_DEP_ANTI:
7650 /* Anti-dependencies only penalize the fpu unit. */
7651 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7652 return 0;
7653 break;
7655 default:
7656 break;
7659 return cost;
7662 static int
7663 sparc_adjust_cost(insn, link, dep, cost)
7664 rtx insn;
7665 rtx link;
7666 rtx dep;
7667 int cost;
7669 switch (sparc_cpu)
7671 case PROCESSOR_SUPERSPARC:
7672 cost = supersparc_adjust_cost (insn, link, dep, cost);
7673 break;
7674 case PROCESSOR_HYPERSPARC:
7675 case PROCESSOR_SPARCLITE86X:
7676 cost = hypersparc_adjust_cost (insn, link, dep, cost);
7677 break;
7678 default:
7679 break;
7681 return cost;
7684 static void
7685 sparc_sched_init (dump, sched_verbose, max_ready)
7686 FILE *dump ATTRIBUTE_UNUSED;
7687 int sched_verbose ATTRIBUTE_UNUSED;
7688 int max_ready ATTRIBUTE_UNUSED;
7692 static int
7693 sparc_use_dfa_pipeline_interface ()
7695 if ((1 << sparc_cpu) &
7696 ((1 << PROCESSOR_ULTRASPARC) | (1 << PROCESSOR_CYPRESS) |
7697 (1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
7698 (1 << PROCESSOR_SPARCLITE86X) | (1 << PROCESSOR_TSC701) |
7699 (1 << PROCESSOR_ULTRASPARC3)))
7700 return 1;
7701 return 0;
7704 static int
7705 sparc_use_sched_lookahead ()
7707 if (sparc_cpu == PROCESSOR_ULTRASPARC
7708 || sparc_cpu == PROCESSOR_ULTRASPARC3)
7709 return 4;
7710 if ((1 << sparc_cpu) &
7711 ((1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
7712 (1 << PROCESSOR_SPARCLITE86X)))
7713 return 3;
7714 return 0;
7717 static int
7718 sparc_issue_rate ()
7720 switch (sparc_cpu)
7722 default:
7723 return 1;
7724 case PROCESSOR_V9:
7725 /* Assume V9 processors are capable of at least dual-issue. */
7726 return 2;
7727 case PROCESSOR_SUPERSPARC:
7728 return 3;
7729 case PROCESSOR_HYPERSPARC:
7730 case PROCESSOR_SPARCLITE86X:
7731 return 2;
7732 case PROCESSOR_ULTRASPARC:
7733 case PROCESSOR_ULTRASPARC3:
7734 return 4;
7738 static int
7739 set_extends (insn)
7740 rtx insn;
7742 register rtx pat = PATTERN (insn);
7744 switch (GET_CODE (SET_SRC (pat)))
7746 /* Load and some shift instructions zero extend. */
7747 case MEM:
7748 case ZERO_EXTEND:
7749 /* sethi clears the high bits */
7750 case HIGH:
7751 /* LO_SUM is used with sethi. sethi cleared the high
7752 bits and the values used with lo_sum are positive */
7753 case LO_SUM:
7754 /* Store flag stores 0 or 1 */
7755 case LT: case LTU:
7756 case GT: case GTU:
7757 case LE: case LEU:
7758 case GE: case GEU:
7759 case EQ:
7760 case NE:
7761 return 1;
7762 case AND:
7764 rtx op0 = XEXP (SET_SRC (pat), 0);
7765 rtx op1 = XEXP (SET_SRC (pat), 1);
7766 if (GET_CODE (op1) == CONST_INT)
7767 return INTVAL (op1) >= 0;
7768 if (GET_CODE (op0) != REG)
7769 return 0;
7770 if (sparc_check_64 (op0, insn) == 1)
7771 return 1;
7772 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
7774 case IOR:
7775 case XOR:
7777 rtx op0 = XEXP (SET_SRC (pat), 0);
7778 rtx op1 = XEXP (SET_SRC (pat), 1);
7779 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
7780 return 0;
7781 if (GET_CODE (op1) == CONST_INT)
7782 return INTVAL (op1) >= 0;
7783 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
7785 case LSHIFTRT:
7786 return GET_MODE (SET_SRC (pat)) == SImode;
7787 /* Positive integers leave the high bits zero. */
7788 case CONST_DOUBLE:
7789 return ! (CONST_DOUBLE_LOW (SET_SRC (pat)) & 0x80000000);
7790 case CONST_INT:
7791 return ! (INTVAL (SET_SRC (pat)) & 0x80000000);
7792 case ASHIFTRT:
7793 case SIGN_EXTEND:
7794 return - (GET_MODE (SET_SRC (pat)) == SImode);
7795 case REG:
7796 return sparc_check_64 (SET_SRC (pat), insn);
7797 default:
7798 return 0;
7802 /* We _ought_ to have only one kind per function, but... */
7803 static GTY(()) rtx sparc_addr_diff_list;
7804 static GTY(()) rtx sparc_addr_list;
7806 void
7807 sparc_defer_case_vector (lab, vec, diff)
7808 rtx lab, vec;
7809 int diff;
7811 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
7812 if (diff)
7813 sparc_addr_diff_list
7814 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
7815 else
7816 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
7819 static void
7820 sparc_output_addr_vec (vec)
7821 rtx vec;
7823 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
7824 int idx, vlen = XVECLEN (body, 0);
7826 #ifdef ASM_OUTPUT_ADDR_VEC_START
7827 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
7828 #endif
7830 #ifdef ASM_OUTPUT_CASE_LABEL
7831 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
7832 NEXT_INSN (lab));
7833 #else
7834 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
7835 #endif
7837 for (idx = 0; idx < vlen; idx++)
7839 ASM_OUTPUT_ADDR_VEC_ELT
7840 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
7843 #ifdef ASM_OUTPUT_ADDR_VEC_END
7844 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
7845 #endif
7848 static void
7849 sparc_output_addr_diff_vec (vec)
7850 rtx vec;
7852 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
7853 rtx base = XEXP (XEXP (body, 0), 0);
7854 int idx, vlen = XVECLEN (body, 1);
7856 #ifdef ASM_OUTPUT_ADDR_VEC_START
7857 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
7858 #endif
7860 #ifdef ASM_OUTPUT_CASE_LABEL
7861 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
7862 NEXT_INSN (lab));
7863 #else
7864 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
7865 #endif
7867 for (idx = 0; idx < vlen; idx++)
7869 ASM_OUTPUT_ADDR_DIFF_ELT
7870 (asm_out_file,
7871 body,
7872 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
7873 CODE_LABEL_NUMBER (base));
7876 #ifdef ASM_OUTPUT_ADDR_VEC_END
7877 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
7878 #endif
7881 static void
7882 sparc_output_deferred_case_vectors ()
7884 rtx t;
7885 int align;
7887 if (sparc_addr_list == NULL_RTX
7888 && sparc_addr_diff_list == NULL_RTX)
7889 return;
7891 /* Align to cache line in the function's code section. */
7892 function_section (current_function_decl);
7894 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
7895 if (align > 0)
7896 ASM_OUTPUT_ALIGN (asm_out_file, align);
7898 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
7899 sparc_output_addr_vec (XEXP (t, 0));
7900 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
7901 sparc_output_addr_diff_vec (XEXP (t, 0));
7903 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
7906 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
7907 unknown. Return 1 if the high bits are zero, -1 if the register is
7908 sign extended. */
7910 sparc_check_64 (x, insn)
7911 rtx x, insn;
7913 /* If a register is set only once it is safe to ignore insns this
7914 code does not know how to handle. The loop will either recognize
7915 the single set and return the correct value or fail to recognize
7916 it and return 0. */
7917 int set_once = 0;
7918 rtx y = x;
7920 if (GET_CODE (x) != REG)
7921 abort ();
7923 if (GET_MODE (x) == DImode)
7924 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
7926 if (flag_expensive_optimizations
7927 && REG_N_SETS (REGNO (y)) == 1)
7928 set_once = 1;
7930 if (insn == 0)
7932 if (set_once)
7933 insn = get_last_insn_anywhere ();
7934 else
7935 return 0;
7938 while ((insn = PREV_INSN (insn)))
7940 switch (GET_CODE (insn))
7942 case JUMP_INSN:
7943 case NOTE:
7944 break;
7945 case CODE_LABEL:
7946 case CALL_INSN:
7947 default:
7948 if (! set_once)
7949 return 0;
7950 break;
7951 case INSN:
7953 rtx pat = PATTERN (insn);
7954 if (GET_CODE (pat) != SET)
7955 return 0;
7956 if (rtx_equal_p (x, SET_DEST (pat)))
7957 return set_extends (insn);
7958 if (y && rtx_equal_p (y, SET_DEST (pat)))
7959 return set_extends (insn);
7960 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
7961 return 0;
7965 return 0;
7968 char *
7969 sparc_v8plus_shift (operands, insn, opcode)
7970 rtx *operands;
7971 rtx insn;
7972 const char *opcode;
7974 static char asm_code[60];
7976 if (GET_CODE (operands[3]) == SCRATCH)
7977 operands[3] = operands[0];
7978 if (GET_CODE (operands[1]) == CONST_INT)
7980 output_asm_insn ("mov\t%1, %3", operands);
7982 else
7984 output_asm_insn ("sllx\t%H1, 32, %3", operands);
7985 if (sparc_check_64 (operands[1], insn) <= 0)
7986 output_asm_insn ("srl\t%L1, 0, %L1", operands);
7987 output_asm_insn ("or\t%L1, %3, %3", operands);
7990 strcpy(asm_code, opcode);
7991 if (which_alternative != 2)
7992 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
7993 else
7994 return strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
7997 /* Output rtl to increment the profiler label LABELNO
7998 for profiling a function entry. */
8000 void
8001 sparc_profile_hook (labelno)
8002 int labelno;
8004 char buf[32];
8005 rtx lab, fun;
8007 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
8008 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
8009 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_FUNCTION);
8011 emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lab, Pmode);
8014 #ifdef OBJECT_FORMAT_ELF
8015 static void
8016 sparc_elf_asm_named_section (name, flags)
8017 const char *name;
8018 unsigned int flags;
8020 if (flags & SECTION_MERGE)
8022 /* entsize cannot be expressed in this section attributes
8023 encoding style. */
8024 default_elf_asm_named_section (name, flags);
8025 return;
8028 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
8030 if (!(flags & SECTION_DEBUG))
8031 fputs (",#alloc", asm_out_file);
8032 if (flags & SECTION_WRITE)
8033 fputs (",#write", asm_out_file);
8034 if (flags & SECTION_CODE)
8035 fputs (",#execinstr", asm_out_file);
8037 /* ??? Handle SECTION_BSS. */
8039 fputc ('\n', asm_out_file);
8041 #endif /* OBJECT_FORMAT_ELF */
8043 /* We do not allow sibling calls if -mflat, nor
8044 we do not allow indirect calls to be optimized into sibling calls.
8046 Also, on sparc 32-bit we cannot emit a sibling call when the
8047 current function returns a structure. This is because the "unimp
8048 after call" convention would cause the callee to return to the
8049 wrong place. The generic code already disallows cases where the
8050 function being called returns a structure.
8052 It may seem strange how this last case could occur. Usually there
8053 is code after the call which jumps to epilogue code which dumps the
8054 return value into the struct return area. That ought to invalidate
8055 the sibling call right? Well, in the c++ case we can end up passing
8056 the pointer to the struct return area to a constructor (which returns
8057 void) and then nothing else happens. Such a sibling call would look
8058 valid without the added check here. */
8059 static bool
8060 sparc_function_ok_for_sibcall (decl, exp)
8061 tree decl;
8062 tree exp ATTRIBUTE_UNUSED;
8064 return (decl
8065 && ! TARGET_FLAT
8066 && (TARGET_ARCH64 || ! current_function_returns_struct));
8069 /* ??? Similar to the standard section selection, but force reloc-y-ness
8070 if SUNOS4_SHARED_LIBRARIES. Unclear why this helps (as opposed to
8071 pretending PIC always on), but that's what the old code did. */
8073 static void
8074 sparc_aout_select_section (t, reloc, align)
8075 tree t;
8076 int reloc;
8077 unsigned HOST_WIDE_INT align;
8079 default_select_section (t, reloc | SUNOS4_SHARED_LIBRARIES, align);
8082 /* Use text section for a constant unless we need more alignment than
8083 that offers. */
8085 static void
8086 sparc_aout_select_rtx_section (mode, x, align)
8087 enum machine_mode mode;
8088 rtx x;
8089 unsigned HOST_WIDE_INT align;
8091 if (align <= MAX_TEXT_ALIGN
8092 && ! (flag_pic && (symbolic_operand (x, mode)
8093 || SUNOS4_SHARED_LIBRARIES)))
8094 readonly_data_section ();
8095 else
8096 data_section ();
8100 sparc_extra_constraint_check (op, c, strict)
8101 rtx op;
8102 int c;
8103 int strict;
8105 int reload_ok_mem;
8107 if (TARGET_ARCH64
8108 && (c == 'T' || c == 'U'))
8109 return 0;
8111 switch (c)
8113 case 'Q':
8114 return fp_sethi_p (op);
8116 case 'R':
8117 return fp_mov_p (op);
8119 case 'S':
8120 return fp_high_losum_p (op);
8122 case 'U':
8123 if (! strict
8124 || (GET_CODE (op) == REG
8125 && (REGNO (op) < FIRST_PSEUDO_REGISTER
8126 || reg_renumber[REGNO (op)] >= 0)))
8127 return register_ok_for_ldd (op);
8129 return 0;
8131 case 'W':
8132 case 'T':
8133 break;
8135 default:
8136 return 0;
8139 /* Our memory extra constraints have to emulate the
8140 behavior of 'm' and 'o' in order for reload to work
8141 correctly. */
8142 if (GET_CODE (op) == MEM)
8144 reload_ok_mem = 0;
8145 if ((TARGET_ARCH64 || mem_min_alignment (op, 8))
8146 && (! strict
8147 || strict_memory_address_p (Pmode, XEXP (op, 0))))
8148 reload_ok_mem = 1;
8150 else
8152 reload_ok_mem = (reload_in_progress
8153 && GET_CODE (op) == REG
8154 && REGNO (op) >= FIRST_PSEUDO_REGISTER
8155 && reg_renumber [REGNO (op)] < 0);
8158 return reload_ok_mem;
8161 /* ??? This duplicates information provided to the compiler by the
8162 ??? scheduler description. Some day, teach genautomata to output
8163 ??? the latencies and then CSE will just use that. */
8165 static bool
8166 sparc_rtx_costs (x, code, outer_code, total)
8167 rtx x;
8168 int code, outer_code, *total;
8170 switch (code)
8172 case PLUS: case MINUS: case ABS: case NEG:
8173 case FLOAT: case UNSIGNED_FLOAT:
8174 case FIX: case UNSIGNED_FIX:
8175 case FLOAT_EXTEND: case FLOAT_TRUNCATE:
8176 if (FLOAT_MODE_P (GET_MODE (x)))
8178 switch (sparc_cpu)
8180 case PROCESSOR_ULTRASPARC:
8181 case PROCESSOR_ULTRASPARC3:
8182 *total = COSTS_N_INSNS (4);
8183 return true;
8185 case PROCESSOR_SUPERSPARC:
8186 *total = COSTS_N_INSNS (3);
8187 return true;
8189 case PROCESSOR_CYPRESS:
8190 *total = COSTS_N_INSNS (5);
8191 return true;
8193 case PROCESSOR_HYPERSPARC:
8194 case PROCESSOR_SPARCLITE86X:
8195 default:
8196 *total = COSTS_N_INSNS (1);
8197 return true;
8201 *total = COSTS_N_INSNS (1);
8202 return true;
8204 case SQRT:
8205 switch (sparc_cpu)
8207 case PROCESSOR_ULTRASPARC:
8208 if (GET_MODE (x) == SFmode)
8209 *total = COSTS_N_INSNS (13);
8210 else
8211 *total = COSTS_N_INSNS (23);
8212 return true;
8214 case PROCESSOR_ULTRASPARC3:
8215 if (GET_MODE (x) == SFmode)
8216 *total = COSTS_N_INSNS (20);
8217 else
8218 *total = COSTS_N_INSNS (29);
8219 return true;
8221 case PROCESSOR_SUPERSPARC:
8222 *total = COSTS_N_INSNS (12);
8223 return true;
8225 case PROCESSOR_CYPRESS:
8226 *total = COSTS_N_INSNS (63);
8227 return true;
8229 case PROCESSOR_HYPERSPARC:
8230 case PROCESSOR_SPARCLITE86X:
8231 *total = COSTS_N_INSNS (17);
8232 return true;
8234 default:
8235 *total = COSTS_N_INSNS (30);
8236 return true;
8239 case COMPARE:
8240 if (FLOAT_MODE_P (GET_MODE (x)))
8242 switch (sparc_cpu)
8244 case PROCESSOR_ULTRASPARC:
8245 case PROCESSOR_ULTRASPARC3:
8246 *total = COSTS_N_INSNS (1);
8247 return true;
8249 case PROCESSOR_SUPERSPARC:
8250 *total = COSTS_N_INSNS (3);
8251 return true;
8253 case PROCESSOR_CYPRESS:
8254 *total = COSTS_N_INSNS (5);
8255 return true;
8257 case PROCESSOR_HYPERSPARC:
8258 case PROCESSOR_SPARCLITE86X:
8259 default:
8260 *total = COSTS_N_INSNS (1);
8261 return true;
8265 /* ??? Maybe mark integer compares as zero cost on
8266 ??? all UltraSPARC processors because the result
8267 ??? can be bypassed to a branch in the same group. */
8269 *total = COSTS_N_INSNS (1);
8270 return true;
8272 case MULT:
8273 if (FLOAT_MODE_P (GET_MODE (x)))
8275 switch (sparc_cpu)
8277 case PROCESSOR_ULTRASPARC:
8278 case PROCESSOR_ULTRASPARC3:
8279 *total = COSTS_N_INSNS (4);
8280 return true;
8282 case PROCESSOR_SUPERSPARC:
8283 *total = COSTS_N_INSNS (3);
8284 return true;
8286 case PROCESSOR_CYPRESS:
8287 *total = COSTS_N_INSNS (7);
8288 return true;
8290 case PROCESSOR_HYPERSPARC:
8291 case PROCESSOR_SPARCLITE86X:
8292 *total = COSTS_N_INSNS (1);
8293 return true;
8295 default:
8296 *total = COSTS_N_INSNS (5);
8297 return true;
8301 /* The latency is actually variable for Ultra-I/II
8302 And if one of the inputs have a known constant
8303 value, we could calculate this precisely.
8305 However, for that to be useful we would need to
8306 add some machine description changes which would
8307 make sure small constants ended up in rs1 of the
8308 multiply instruction. This is because the multiply
8309 latency is determined by the number of clear (or
8310 set if the value is negative) bits starting from
8311 the most significant bit of the first input.
8313 The algorithm for computing num_cycles of a multiply
8314 on Ultra-I/II is:
8316 if (rs1 < 0)
8317 highest_bit = highest_clear_bit(rs1);
8318 else
8319 highest_bit = highest_set_bit(rs1);
8320 if (num_bits < 3)
8321 highest_bit = 3;
8322 num_cycles = 4 + ((highest_bit - 3) / 2);
8324 If we did that we would have to also consider register
8325 allocation issues that would result from forcing such
8326 a value into a register.
8328 There are other similar tricks we could play if we
8329 knew, for example, that one input was an array index.
8331 Since we do not play any such tricks currently the
8332 safest thing to do is report the worst case latency. */
8333 if (sparc_cpu == PROCESSOR_ULTRASPARC)
8335 *total = (GET_MODE (x) == DImode
8336 ? COSTS_N_INSNS (34) : COSTS_N_INSNS (19));
8337 return true;
8340 /* Multiply latency on Ultra-III, fortunately, is constant. */
8341 if (sparc_cpu == PROCESSOR_ULTRASPARC3)
8343 *total = COSTS_N_INSNS (6);
8344 return true;
8347 if (sparc_cpu == PROCESSOR_HYPERSPARC
8348 || sparc_cpu == PROCESSOR_SPARCLITE86X)
8350 *total = COSTS_N_INSNS (17);
8351 return true;
8354 *total = (TARGET_HARD_MUL ? COSTS_N_INSNS (5) : COSTS_N_INSNS (25));
8355 return true;
8357 case DIV:
8358 case UDIV:
8359 case MOD:
8360 case UMOD:
8361 if (FLOAT_MODE_P (GET_MODE (x)))
8363 switch (sparc_cpu)
8365 case PROCESSOR_ULTRASPARC:
8366 if (GET_MODE (x) == SFmode)
8367 *total = COSTS_N_INSNS (13);
8368 else
8369 *total = COSTS_N_INSNS (23);
8370 return true;
8372 case PROCESSOR_ULTRASPARC3:
8373 if (GET_MODE (x) == SFmode)
8374 *total = COSTS_N_INSNS (17);
8375 else
8376 *total = COSTS_N_INSNS (20);
8377 return true;
8379 case PROCESSOR_SUPERSPARC:
8380 if (GET_MODE (x) == SFmode)
8381 *total = COSTS_N_INSNS (6);
8382 else
8383 *total = COSTS_N_INSNS (9);
8384 return true;
8386 case PROCESSOR_HYPERSPARC:
8387 case PROCESSOR_SPARCLITE86X:
8388 if (GET_MODE (x) == SFmode)
8389 *total = COSTS_N_INSNS (8);
8390 else
8391 *total = COSTS_N_INSNS (12);
8392 return true;
8394 default:
8395 *total = COSTS_N_INSNS (7);
8396 return true;
8400 if (sparc_cpu == PROCESSOR_ULTRASPARC)
8401 *total = (GET_MODE (x) == DImode
8402 ? COSTS_N_INSNS (68) : COSTS_N_INSNS (37));
8403 else if (sparc_cpu == PROCESSOR_ULTRASPARC3)
8404 *total = (GET_MODE (x) == DImode
8405 ? COSTS_N_INSNS (71) : COSTS_N_INSNS (40));
8406 else
8407 *total = COSTS_N_INSNS (25);
8408 return true;
8410 case IF_THEN_ELSE:
8411 /* Conditional moves. */
8412 switch (sparc_cpu)
8414 case PROCESSOR_ULTRASPARC:
8415 *total = COSTS_N_INSNS (2);
8416 return true;
8418 case PROCESSOR_ULTRASPARC3:
8419 if (FLOAT_MODE_P (GET_MODE (x)))
8420 *total = COSTS_N_INSNS (3);
8421 else
8422 *total = COSTS_N_INSNS (2);
8423 return true;
8425 default:
8426 *total = COSTS_N_INSNS (1);
8427 return true;
8430 case MEM:
8431 /* If outer-code is SIGN/ZERO extension we have to subtract
8432 out COSTS_N_INSNS (1) from whatever we return in determining
8433 the cost. */
8434 switch (sparc_cpu)
8436 case PROCESSOR_ULTRASPARC:
8437 if (outer_code == ZERO_EXTEND)
8438 *total = COSTS_N_INSNS (1);
8439 else
8440 *total = COSTS_N_INSNS (2);
8441 return true;
8443 case PROCESSOR_ULTRASPARC3:
8444 if (outer_code == ZERO_EXTEND)
8446 if (GET_MODE (x) == QImode
8447 || GET_MODE (x) == HImode
8448 || outer_code == SIGN_EXTEND)
8449 *total = COSTS_N_INSNS (2);
8450 else
8451 *total = COSTS_N_INSNS (1);
8453 else
8455 /* This handles sign extension (3 cycles)
8456 and everything else (2 cycles). */
8457 *total = COSTS_N_INSNS (2);
8459 return true;
8461 case PROCESSOR_SUPERSPARC:
8462 if (FLOAT_MODE_P (GET_MODE (x))
8463 || outer_code == ZERO_EXTEND
8464 || outer_code == SIGN_EXTEND)
8465 *total = COSTS_N_INSNS (0);
8466 else
8467 *total = COSTS_N_INSNS (1);
8468 return true;
8470 case PROCESSOR_TSC701:
8471 if (outer_code == ZERO_EXTEND
8472 || outer_code == SIGN_EXTEND)
8473 *total = COSTS_N_INSNS (2);
8474 else
8475 *total = COSTS_N_INSNS (3);
8476 return true;
8478 case PROCESSOR_CYPRESS:
8479 if (outer_code == ZERO_EXTEND
8480 || outer_code == SIGN_EXTEND)
8481 *total = COSTS_N_INSNS (1);
8482 else
8483 *total = COSTS_N_INSNS (2);
8484 return true;
8486 case PROCESSOR_HYPERSPARC:
8487 case PROCESSOR_SPARCLITE86X:
8488 default:
8489 if (outer_code == ZERO_EXTEND
8490 || outer_code == SIGN_EXTEND)
8491 *total = COSTS_N_INSNS (0);
8492 else
8493 *total = COSTS_N_INSNS (1);
8494 return true;
8497 case CONST_INT:
8498 if (INTVAL (x) < 0x1000 && INTVAL (x) >= -0x1000)
8500 *total = 0;
8501 return true;
8503 /* FALLTHRU */
8505 case HIGH:
8506 *total = 2;
8507 return true;
8509 case CONST:
8510 case LABEL_REF:
8511 case SYMBOL_REF:
8512 *total = 4;
8513 return true;
8515 case CONST_DOUBLE:
8516 if (GET_MODE (x) == DImode
8517 && ((XINT (x, 3) == 0
8518 && (unsigned HOST_WIDE_INT) XINT (x, 2) < 0x1000)
8519 || (XINT (x, 3) == -1
8520 && XINT (x, 2) < 0
8521 && XINT (x, 2) >= -0x1000)))
8522 *total = 0;
8523 else
8524 *total = 8;
8525 return true;
8527 default:
8528 return false;
8532 /* If we are referencing a function make the SYMBOL_REF special. In
8533 the Embedded Medium/Anywhere code model, %g4 points to the data
8534 segment so we must not add it to function addresses. */
8536 static void
8537 sparc_encode_section_info (decl, first)
8538 tree decl;
8539 int first ATTRIBUTE_UNUSED;
8541 if (TARGET_CM_EMBMEDANY && TREE_CODE (decl) == FUNCTION_DECL)
8542 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1;
8545 /* Output code to add DELTA to the first argument, and then jump to FUNCTION.
8546 Used for C++ multiple inheritance. */
8548 static void
8549 sparc_output_mi_thunk (file, thunk_fndecl, delta, vcall_offset, function)
8550 FILE *file;
8551 tree thunk_fndecl ATTRIBUTE_UNUSED;
8552 HOST_WIDE_INT delta;
8553 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED;
8554 tree function;
8556 rtx this, insn, funexp, delta_rtx, tmp;
8558 reload_completed = 1;
8559 no_new_pseudos = 1;
8560 current_function_uses_only_leaf_regs = 1;
8562 emit_note (NULL, NOTE_INSN_PROLOGUE_END);
8564 /* Find the "this" pointer. Normally in %o0, but in ARCH64 if the function
8565 returns a structure, the structure return pointer is there instead. */
8566 if (TARGET_ARCH64 && aggregate_value_p (TREE_TYPE (TREE_TYPE (function))))
8567 this = gen_rtx_REG (Pmode, SPARC_INCOMING_INT_ARG_FIRST + 1);
8568 else
8569 this = gen_rtx_REG (Pmode, SPARC_INCOMING_INT_ARG_FIRST);
8571 /* Add DELTA. When possible use a plain add, otherwise load it into
8572 a register first. */
8573 delta_rtx = GEN_INT (delta);
8574 if (!SPARC_SIMM13_P (delta))
8576 rtx scratch = gen_rtx_REG (Pmode, 1);
8577 if (TARGET_ARCH64)
8578 sparc_emit_set_const64 (scratch, delta_rtx);
8579 else
8580 sparc_emit_set_const32 (scratch, delta_rtx);
8581 delta_rtx = scratch;
8584 tmp = gen_rtx_PLUS (Pmode, this, delta_rtx);
8585 emit_insn (gen_rtx_SET (VOIDmode, this, tmp));
8587 /* Generate a tail call to the target function. */
8588 if (! TREE_USED (function))
8590 assemble_external (function);
8591 TREE_USED (function) = 1;
8593 funexp = XEXP (DECL_RTL (function), 0);
8594 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
8595 insn = emit_call_insn (gen_sibcall (funexp));
8596 SIBLING_CALL_P (insn) = 1;
8597 emit_barrier ();
8599 /* Run just enough of rest_of_compilation to get the insns emitted.
8600 There's not really enough bulk here to make other passes such as
8601 instruction scheduling worth while. Note that use_thunk calls
8602 assemble_start_function and assemble_end_function. */
8603 insn = get_insns ();
8604 shorten_branches (insn);
8605 final_start_function (insn, file, 1);
8606 final (insn, file, 1, 0);
8607 final_end_function ();
8609 reload_completed = 0;
8610 no_new_pseudos = 0;
8613 #include "gt-sparc.h"