Mark ChangeLog
[official-gcc.git] / gcc / config / mmix / mmix.c
blob0dd26ed2620e85d861bf10c6452e218cb6a9ed15
1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "regs.h"
28 #include "hard-reg-set.h"
29 #include "hashtab.h"
30 #include "insn-config.h"
31 #include "output.h"
32 #include "flags.h"
33 #include "tree.h"
34 #include "function.h"
35 #include "expr.h"
36 #include "toplev.h"
37 #include "recog.h"
38 #include "ggc.h"
39 #include "dwarf2.h"
40 #include "debug.h"
41 #include "tm_p.h"
42 #include "integrate.h"
43 #include "target.h"
44 #include "target-def.h"
45 #include "real.h"
47 /* First some local helper definitions. */
48 #define MMIX_FIRST_GLOBAL_REGNUM 32
50 /* We'd need a current_function_has_landing_pad. It's marked as such when
51 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
52 mostly. */
53 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
55 /* We have no means to tell DWARF 2 about the register stack, so we need
56 to store the return address on the stack if an exception can get into
57 this function. FIXME: Narrow condition. Before any whole-function
58 analysis, regs_ever_live[] isn't initialized. We know it's up-to-date
59 after reload_completed; it may contain incorrect information some time
60 before that. Within a RTL sequence (after a call to start_sequence,
61 such as in RTL expanders), leaf_function_p doesn't see all insns
62 (perhaps any insn). But regs_ever_live is up-to-date when
63 leaf_function_p () isn't, so we "or" them together to get accurate
64 information. FIXME: Some tweak to leaf_function_p might be
65 preferable. */
66 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
67 (flag_exceptions \
68 && ((reload_completed && regs_ever_live[MMIX_rJ_REGNUM]) \
69 || !leaf_function_p ()))
71 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
72 (current_function_calls_eh_return \
73 && (EH_RETURN_DATA_REGNO (0) == REGNO \
74 || EH_RETURN_DATA_REGNO (1) == REGNO \
75 || EH_RETURN_DATA_REGNO (2) == REGNO \
76 || EH_RETURN_DATA_REGNO (3) == REGNO))
78 /* For the default ABI, we rename registers at output-time to fill the gap
79 between the (statically partitioned) saved registers and call-clobbered
80 registers. In effect this makes unused call-saved registers to be used
81 as call-clobbered registers. The benefit comes from keeping the number
82 of local registers (value of rL) low, since there's a cost of
83 increasing rL and clearing unused (unset) registers with lower numbers.
84 Don't translate while outputting the prologue. */
85 #define MMIX_OUTPUT_REGNO(N) \
86 (TARGET_ABI_GNU \
87 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
88 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
89 || cfun == NULL \
90 || cfun->machine == NULL \
91 || cfun->machine->in_prologue \
92 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
93 + cfun->machine->highest_saved_stack_register + 1))
95 /* The %d in "POP %d,0". */
96 #define MMIX_POP_ARGUMENT() \
97 ((! TARGET_ABI_GNU \
98 && current_function_return_rtx != NULL \
99 && ! current_function_returns_struct) \
100 ? (GET_CODE (current_function_return_rtx) == PARALLEL \
101 ? GET_NUM_ELEM (XVEC (current_function_return_rtx, 0)) : 1) \
102 : 0)
104 /* The canonical saved comparison operands for non-cc0 machines, set in
105 the compare expander. */
106 rtx mmix_compare_op0;
107 rtx mmix_compare_op1;
109 /* We ignore some options with arguments. They are passed to the linker,
110 but also ends up here because they start with "-m". We tell the driver
111 to store them in a variable we don't inspect. */
112 const char *mmix_cc1_ignored_option;
114 /* Declarations of locals. */
116 /* Intermediate for insn output. */
117 static int mmix_output_destination_register;
119 static void mmix_output_shiftvalue_op_from_str
120 (FILE *, const char *, HOST_WIDEST_INT);
121 static void mmix_output_shifted_value (FILE *, HOST_WIDEST_INT);
122 static void mmix_output_condition (FILE *, rtx, int);
123 static HOST_WIDEST_INT mmix_intval (rtx);
124 static void mmix_output_octa (FILE *, HOST_WIDEST_INT, int);
125 static bool mmix_assemble_integer (rtx, unsigned int, int);
126 static struct machine_function *mmix_init_machine_status (void);
127 static void mmix_encode_section_info (tree, rtx, int);
128 static const char *mmix_strip_name_encoding (const char *);
129 static void mmix_emit_sp_add (HOST_WIDE_INT offset);
130 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT);
131 static void mmix_target_asm_function_end_prologue (FILE *);
132 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT);
133 static void mmix_reorg (void);
134 static void mmix_asm_output_mi_thunk
135 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
136 static void mmix_setup_incoming_varargs
137 (CUMULATIVE_ARGS *, enum machine_mode, tree, int *, int);
138 static void mmix_file_start (void);
139 static void mmix_file_end (void);
140 static bool mmix_rtx_costs (rtx, int, int, int *);
141 static rtx mmix_struct_value_rtx (tree, int);
142 static bool mmix_pass_by_reference (const CUMULATIVE_ARGS *,
143 enum machine_mode, tree, bool);
145 /* Target structure macros. Listed by node. See `Using and Porting GCC'
146 for a general description. */
148 /* Node: Function Entry */
150 #undef TARGET_ASM_BYTE_OP
151 #define TARGET_ASM_BYTE_OP NULL
152 #undef TARGET_ASM_ALIGNED_HI_OP
153 #define TARGET_ASM_ALIGNED_HI_OP NULL
154 #undef TARGET_ASM_ALIGNED_SI_OP
155 #define TARGET_ASM_ALIGNED_SI_OP NULL
156 #undef TARGET_ASM_ALIGNED_DI_OP
157 #define TARGET_ASM_ALIGNED_DI_OP NULL
158 #undef TARGET_ASM_INTEGER
159 #define TARGET_ASM_INTEGER mmix_assemble_integer
161 #undef TARGET_ASM_FUNCTION_PROLOGUE
162 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
164 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
165 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
167 #undef TARGET_ASM_FUNCTION_EPILOGUE
168 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
170 #undef TARGET_ENCODE_SECTION_INFO
171 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
172 #undef TARGET_STRIP_NAME_ENCODING
173 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
175 #undef TARGET_ASM_OUTPUT_MI_THUNK
176 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
177 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
178 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
179 #undef TARGET_ASM_FILE_START
180 #define TARGET_ASM_FILE_START mmix_file_start
181 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
182 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
183 #undef TARGET_ASM_FILE_END
184 #define TARGET_ASM_FILE_END mmix_file_end
186 #undef TARGET_RTX_COSTS
187 #define TARGET_RTX_COSTS mmix_rtx_costs
188 #undef TARGET_ADDRESS_COST
189 #define TARGET_ADDRESS_COST hook_int_rtx_0
191 #undef TARGET_MACHINE_DEPENDENT_REORG
192 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
194 #undef TARGET_PROMOTE_FUNCTION_ARGS
195 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
196 #if 0
197 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
198 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
199 #undef TARGET_PROMOTE_FUNCTION_RETURN
200 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
201 #endif
203 #undef TARGET_STRUCT_VALUE_RTX
204 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
205 #undef TARGET_SETUP_INCOMING_VARARGS
206 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
207 #undef TARGET_PASS_BY_REFERENCE
208 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
209 #undef TARGET_CALLEE_COPIES
210 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
212 struct gcc_target targetm = TARGET_INITIALIZER;
214 /* Functions that are expansions for target macros.
215 See Target Macros in `Using and Porting GCC'. */
217 /* OVERRIDE_OPTIONS. */
219 void
220 mmix_override_options (void)
222 /* Should we err or should we warn? Hmm. At least we must neutralize
223 it. For example the wrong kind of case-tables will be generated with
224 PIC; we use absolute address items for mmixal compatibility. FIXME:
225 They could be relative if we just elide them to after all pertinent
226 labels. */
227 if (flag_pic)
229 warning ("-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
230 flag_pic = 0;
234 /* INIT_EXPANDERS. */
236 void
237 mmix_init_expanders (void)
239 init_machine_status = mmix_init_machine_status;
242 /* Set the per-function data. */
244 static struct machine_function *
245 mmix_init_machine_status (void)
247 return ggc_alloc_cleared (sizeof (struct machine_function));
250 /* DATA_ALIGNMENT.
251 We have trouble getting the address of stuff that is located at other
252 than 32-bit alignments (GETA requirements), so try to give everything
253 at least 32-bit alignment. */
256 mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
258 if (basic_align < 32)
259 return 32;
261 return basic_align;
264 /* CONSTANT_ALIGNMENT. */
267 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED, int basic_align)
269 if (basic_align < 32)
270 return 32;
272 return basic_align;
275 /* LOCAL_ALIGNMENT. */
278 mmix_local_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
280 if (basic_align < 32)
281 return 32;
283 return basic_align;
286 /* CONDITIONAL_REGISTER_USAGE. */
288 void
289 mmix_conditional_register_usage (void)
291 int i;
293 if (TARGET_ABI_GNU)
295 static const int gnu_abi_reg_alloc_order[]
296 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
298 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
299 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
301 /* Change the default from the mmixware ABI. For the GNU ABI,
302 $15..$30 are call-saved just as $0..$14. There must be one
303 call-clobbered local register for the "hole" that holds the
304 number of saved local registers saved by PUSHJ/PUSHGO during the
305 function call, receiving the return value at return. So best is
306 to use the highest, $31. It's already marked call-clobbered for
307 the mmixware ABI. */
308 for (i = 15; i <= 30; i++)
309 call_used_regs[i] = 0;
311 /* "Unfix" the parameter registers. */
312 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
313 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
314 i++)
315 fixed_regs[i] = 0;
318 /* Step over the ":" in special register names. */
319 if (! TARGET_TOPLEVEL_SYMBOLS)
320 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
321 if (reg_names[i][0] == ':')
322 reg_names[i]++;
325 /* LOCAL_REGNO.
326 All registers that are part of the register stack and that will be
327 saved are local. */
330 mmix_local_regno (int regno)
332 return regno <= MMIX_LAST_STACK_REGISTER_REGNUM && !call_used_regs[regno];
335 /* PREFERRED_RELOAD_CLASS.
336 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
338 enum reg_class
339 mmix_preferred_reload_class (rtx x ATTRIBUTE_UNUSED, enum reg_class class)
341 /* FIXME: Revisit. */
342 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
343 ? REMAINDER_REG : class;
346 /* PREFERRED_OUTPUT_RELOAD_CLASS.
347 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
349 enum reg_class
350 mmix_preferred_output_reload_class (rtx x ATTRIBUTE_UNUSED,
351 enum reg_class class)
353 /* FIXME: Revisit. */
354 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
355 ? REMAINDER_REG : class;
358 /* SECONDARY_RELOAD_CLASS.
359 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
361 enum reg_class
362 mmix_secondary_reload_class (enum reg_class class,
363 enum machine_mode mode ATTRIBUTE_UNUSED,
364 rtx x ATTRIBUTE_UNUSED,
365 int in_p ATTRIBUTE_UNUSED)
367 if (class == REMAINDER_REG
368 || class == HIMULT_REG
369 || class == SYSTEM_REGS)
370 return GENERAL_REGS;
372 return NO_REGS;
375 /* CONST_OK_FOR_LETTER_P. */
378 mmix_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
380 return
381 (c == 'I' ? value >= 0 && value <= 255
382 : c == 'J' ? value >= 0 && value <= 65535
383 : c == 'K' ? value <= 0 && value >= -255
384 : c == 'L' ? mmix_shiftable_wyde_value (value)
385 : c == 'M' ? value == 0
386 : c == 'N' ? mmix_shiftable_wyde_value (~value)
387 : c == 'O' ? (value == 3 || value == 5 || value == 9
388 || value == 17)
389 : 0);
392 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
395 mmix_const_double_ok_for_letter_p (rtx value, int c)
397 return
398 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
399 : 0);
402 /* EXTRA_CONSTRAINT.
403 We need this since our constants are not always expressible as
404 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
407 mmix_extra_constraint (rtx x, int c, int strict)
409 HOST_WIDEST_INT value;
411 /* When checking for an address, we need to handle strict vs. non-strict
412 register checks. Don't use address_operand, but instead its
413 equivalent (its callee, which it is just a wrapper for),
414 memory_operand_p and the strict-equivalent strict_memory_address_p. */
415 if (c == 'U')
416 return
417 strict
418 ? strict_memory_address_p (Pmode, x)
419 : memory_address_p (Pmode, x);
421 /* R asks whether x is to be loaded with GETA or something else. Right
422 now, only a SYMBOL_REF and LABEL_REF can fit for
423 TARGET_BASE_ADDRESSES.
425 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
426 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
427 set right now; only function addresses and code labels. If we change
428 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
429 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
430 effect, a "raw" constant check together with mmix_constant_address_p
431 is all that's needed; we want all constant addresses to be loaded
432 with GETA then. */
433 if (c == 'R')
434 return
435 GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE
436 && mmix_constant_address_p (x)
437 && (! TARGET_BASE_ADDRESSES
438 || (GET_CODE (x) == LABEL_REF
439 || (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))));
441 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
442 return 0;
444 value = mmix_intval (x);
446 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
447 more ('U' taken for address_operand, 'R' similarly). Some letters map
448 outside of CONST_INT, though; we still use 'S' and 'T'. */
449 if (c == 'S')
450 return mmix_shiftable_wyde_value (value);
451 else if (c == 'T')
452 return mmix_shiftable_wyde_value (~value);
453 return 0;
456 /* DYNAMIC_CHAIN_ADDRESS. */
459 mmix_dynamic_chain_address (rtx frame)
461 /* FIXME: the frame-pointer is stored at offset -8 from the current
462 frame-pointer. Unfortunately, the caller assumes that a
463 frame-pointer is present for *all* previous frames. There should be
464 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
465 return plus_constant (frame, -8);
468 /* STARTING_FRAME_OFFSET. */
471 mmix_starting_frame_offset (void)
473 /* The old frame pointer is in the slot below the new one, so
474 FIRST_PARM_OFFSET does not need to depend on whether the
475 frame-pointer is needed or not. We have to adjust for the register
476 stack pointer being located below the saved frame pointer.
477 Similarly, we store the return address on the stack too, for
478 exception handling, and always if we save the register stack pointer. */
479 return
481 + (MMIX_CFUN_HAS_LANDING_PAD
482 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
485 /* RETURN_ADDR_RTX. */
488 mmix_return_addr_rtx (int count, rtx frame ATTRIBUTE_UNUSED)
490 return count == 0
491 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
492 /* FIXME: Set frame_alias_set on the following. (Why?)
493 See mmix_initial_elimination_offset for the reason we can't use
494 get_hard_reg_initial_val for both. Always using a stack slot
495 and not a register would be suboptimal. */
496 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
497 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
498 : NULL_RTX;
501 /* SETUP_FRAME_ADDRESSES. */
503 void
504 mmix_setup_frame_addresses (void)
506 /* Nothing needed at the moment. */
509 /* The difference between the (imaginary) frame pointer and the stack
510 pointer. Used to eliminate the frame pointer. */
513 mmix_initial_elimination_offset (int fromreg, int toreg)
515 int regno;
516 int fp_sp_offset
517 = (get_frame_size () + current_function_outgoing_args_size + 7) & ~7;
519 /* There is no actual offset between these two virtual values, but for
520 the frame-pointer, we have the old one in the stack position below
521 it, so the offset for the frame-pointer to the stack-pointer is one
522 octabyte larger. */
523 if (fromreg == MMIX_ARG_POINTER_REGNUM
524 && toreg == MMIX_FRAME_POINTER_REGNUM)
525 return 0;
527 /* The difference is the size of local variables plus the size of
528 outgoing function arguments that would normally be passed as
529 registers but must be passed on stack because we're out of
530 function-argument registers. Only global saved registers are
531 counted; the others go on the register stack.
533 The frame-pointer is counted too if it is what is eliminated, as we
534 need to balance the offset for it from STARTING_FRAME_OFFSET.
536 Also add in the slot for the register stack pointer we save if we
537 have a landing pad.
539 Unfortunately, we can't access $0..$14, from unwinder code easily, so
540 store the return address in a frame slot too. FIXME: Only for
541 non-leaf functions. FIXME: Always with a landing pad, because it's
542 hard to know whether we need the other at the time we know we need
543 the offset for one (and have to state it). It's a kludge until we
544 can express the register stack in the EH frame info.
546 We have to do alignment here; get_frame_size will not return a
547 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
549 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
550 regno <= 255;
551 regno++)
552 if ((regs_ever_live[regno] && ! call_used_regs[regno])
553 || IS_MMIX_EH_RETURN_DATA_REG (regno))
554 fp_sp_offset += 8;
556 return fp_sp_offset
557 + (MMIX_CFUN_HAS_LANDING_PAD
558 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
559 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
562 /* Return an rtx for a function argument to go in a register, and 0 for
563 one that must go on stack. */
566 mmix_function_arg (const CUMULATIVE_ARGS *argsp,
567 enum machine_mode mode,
568 tree type,
569 int named ATTRIBUTE_UNUSED,
570 int incoming)
572 /* Last-argument marker. */
573 if (type == void_type_node)
574 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
575 ? gen_rtx_REG (mode,
576 (incoming
577 ? MMIX_FIRST_INCOMING_ARG_REGNUM
578 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
579 : NULL_RTX;
581 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
582 && !targetm.calls.must_pass_in_stack (mode, type)
583 && (GET_MODE_BITSIZE (mode) <= 64
584 || argsp->lib
585 || TARGET_LIBFUNC))
586 ? gen_rtx_REG (mode,
587 (incoming
588 ? MMIX_FIRST_INCOMING_ARG_REGNUM
589 : MMIX_FIRST_ARG_REGNUM)
590 + argsp->regs)
591 : NULL_RTX;
594 /* Returns nonzero for everything that goes by reference, 0 for
595 everything that goes by value. */
597 static bool
598 mmix_pass_by_reference (const CUMULATIVE_ARGS *argsp, enum machine_mode mode,
599 tree type, bool named ATTRIBUTE_UNUSED)
601 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
602 necessary. */
603 if (targetm.calls.must_pass_in_stack (mode, type))
604 return true;
606 if (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
607 && !TARGET_LIBFUNC
608 && (!argsp || !argsp->lib))
609 return true;
611 return false;
614 /* Return nonzero if regno is a register number where a parameter is
615 passed, and 0 otherwise. */
618 mmix_function_arg_regno_p (int regno, int incoming)
620 int first_arg_regnum
621 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
623 return regno >= first_arg_regnum
624 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
627 /* FUNCTION_OUTGOING_VALUE. */
630 mmix_function_outgoing_value (tree valtype, tree func ATTRIBUTE_UNUSED)
632 enum machine_mode mode = TYPE_MODE (valtype);
633 enum machine_mode cmode;
634 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
635 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
636 int i;
637 int nregs;
639 /* Return values that fit in a register need no special handling.
640 There's no register hole when parameters are passed in global
641 registers. */
642 if (TARGET_ABI_GNU
643 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
644 return
645 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
647 if (COMPLEX_MODE_P (mode))
648 /* A complex type, made up of components. */
649 cmode = TYPE_MODE (TREE_TYPE (valtype));
650 else
652 /* Of the other larger-than-register modes, we only support
653 scalar mode TImode. (At least, that's the only one that's
654 been rudimentally tested.) Make sure we're alerted for
655 unexpected cases. */
656 if (mode != TImode)
657 sorry ("support for mode %qs", GET_MODE_NAME (mode));
659 /* In any case, we will fill registers to the natural size. */
660 cmode = DImode;
663 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
665 /* We need to take care of the effect of the register hole on return
666 values of large sizes; the last register will appear as the first
667 register, with the rest shifted. (For complex modes, this is just
668 swapped registers.) */
670 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
671 internal_error ("too large function value type, needs %d registers,\
672 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
674 /* FIXME: Maybe we should handle structure values like this too
675 (adjusted for BLKmode), perhaps for both ABI:s. */
676 for (i = 0; i < nregs - 1; i++)
677 vec[i]
678 = gen_rtx_EXPR_LIST (VOIDmode,
679 gen_rtx_REG (cmode, first_val_regnum + i),
680 GEN_INT ((i + 1) * BITS_PER_UNIT));
682 vec[nregs - 1]
683 = gen_rtx_EXPR_LIST (VOIDmode,
684 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
685 const0_rtx);
687 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
690 /* FUNCTION_VALUE_REGNO_P. */
693 mmix_function_value_regno_p (int regno)
695 return regno == MMIX_RETURN_VALUE_REGNUM;
698 /* EH_RETURN_DATA_REGNO. */
701 mmix_eh_return_data_regno (int n)
703 if (n >= 0 && n < 4)
704 return MMIX_EH_RETURN_DATA_REGNO_START + n;
706 return INVALID_REGNUM;
709 /* EH_RETURN_STACKADJ_RTX. */
712 mmix_eh_return_stackadj_rtx (void)
714 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
717 /* EH_RETURN_HANDLER_RTX. */
720 mmix_eh_return_handler_rtx (void)
722 return gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
725 /* ASM_PREFERRED_EH_DATA_FORMAT. */
728 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED,
729 int global ATTRIBUTE_UNUSED)
731 /* This is the default (was at 2001-07-20). Revisit when needed. */
732 return DW_EH_PE_absptr;
735 /* Make a note that we've seen the beginning of the prologue. This
736 matters to whether we'll translate register numbers as calculated by
737 mmix_reorg. */
739 static void
740 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED,
741 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED)
743 cfun->machine->in_prologue = 1;
746 /* Make a note that we've seen the end of the prologue. */
748 static void
749 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED)
751 cfun->machine->in_prologue = 0;
754 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
755 done here; just virtually by calculating the highest saved stack
756 register number used to modify the register numbers at output time. */
758 static void
759 mmix_reorg (void)
761 int regno;
763 /* We put the number of the highest saved register-file register in a
764 location convenient for the call-patterns to output. Note that we
765 don't tell dwarf2 about these registers, since it can't restore them
766 anyway. */
767 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
768 regno >= 0;
769 regno--)
770 if ((regs_ever_live[regno] && !call_used_regs[regno])
771 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
772 break;
774 /* Regardless of whether they're saved (they might be just read), we
775 mustn't include registers that carry parameters. We could scan the
776 insns to see whether they're actually used (and indeed do other less
777 trivial register usage analysis and transformations), but it seems
778 wasteful to optimize for unused parameter registers. As of
779 2002-04-30, regs_ever_live[n] seems to be set for only-reads too, but
780 that might change. */
781 if (!TARGET_ABI_GNU && regno < current_function_args_info.regs - 1)
783 regno = current_function_args_info.regs - 1;
785 /* We don't want to let this cause us to go over the limit and make
786 incoming parameter registers be misnumbered and treating the last
787 parameter register and incoming return value register call-saved.
788 Stop things at the unmodified scheme. */
789 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
790 regno = MMIX_RETURN_VALUE_REGNUM - 1;
793 cfun->machine->highest_saved_stack_register = regno;
796 /* TARGET_ASM_FUNCTION_EPILOGUE. */
798 static void
799 mmix_target_asm_function_epilogue (FILE *stream,
800 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED)
802 /* Emit an \n for readability of the generated assembly. */
803 fputc ('\n', stream);
806 /* TARGET_ASM_OUTPUT_MI_THUNK. */
808 static void
809 mmix_asm_output_mi_thunk (FILE *stream,
810 tree fndecl ATTRIBUTE_UNUSED,
811 HOST_WIDE_INT delta,
812 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
813 tree func)
815 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
816 location of structure to return as invisible first argument), you
817 need to tweak this code too. */
818 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
820 if (delta >= 0 && delta < 65536)
821 fprintf (stream, "\tINCL %s,%d\n", regname, (int)delta);
822 else if (delta < 0 && delta >= -255)
823 fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, (int)-delta);
824 else
826 mmix_output_register_setting (stream, 255, delta, 1);
827 fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
830 fprintf (stream, "\tJMP ");
831 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
832 fprintf (stream, "\n");
835 /* FUNCTION_PROFILER. */
837 void
838 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED,
839 int labelno ATTRIBUTE_UNUSED)
841 sorry ("function_profiler support for MMIX");
844 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
845 let's stick to pushing argument registers on the stack. Later, we
846 can parse all arguments in registers, to improve performance. */
848 static void
849 mmix_setup_incoming_varargs (CUMULATIVE_ARGS *args_so_farp,
850 enum machine_mode mode,
851 tree vartype,
852 int *pretend_sizep,
853 int second_time ATTRIBUTE_UNUSED)
855 /* The last named variable has been handled, but
856 args_so_farp has not been advanced for it. */
857 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
858 *pretend_sizep = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
860 /* We assume that one argument takes up one register here. That should
861 be true until we start messing with multi-reg parameters. */
862 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
863 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
866 /* TRAMPOLINE_SIZE. */
867 /* Four 4-byte insns plus two 8-byte values. */
868 int mmix_trampoline_size = 32;
871 /* TRAMPOLINE_TEMPLATE. */
873 void
874 mmix_trampoline_template (FILE *stream)
876 /* Read a value into the static-chain register and jump somewhere. The
877 static chain is stored at offset 16, and the function address is
878 stored at offset 24. */
879 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
880 register size (octa). */
881 fprintf (stream, "\tGETA $255,1F\n\t");
882 fprintf (stream, "LDOU %s,$255,0\n\t",
883 reg_names[MMIX_STATIC_CHAIN_REGNUM]);
884 fprintf (stream, "LDOU $255,$255,8\n\t");
885 fprintf (stream, "GO $255,$255,0\n");
886 fprintf (stream, "1H\tOCTA 0\n\t");
887 fprintf (stream, "OCTA 0\n");
890 /* INITIALIZE_TRAMPOLINE. */
891 /* Set the static chain and function pointer field in the trampoline.
892 We also SYNCID here to be sure (doesn't matter in the simulator, but
893 some day it will). */
895 void
896 mmix_initialize_trampoline (rtx trampaddr, rtx fnaddr, rtx static_chain)
898 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)),
899 static_chain);
900 emit_move_insn (gen_rtx_MEM (DImode,
901 plus_constant (trampaddr, 24)),
902 fnaddr);
903 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode,
904 trampaddr)),
905 GEN_INT (mmix_trampoline_size - 1)));
908 /* We must exclude constant addresses that have an increment that is not a
909 multiple of four bytes because of restrictions of the GETA
910 instruction, unless TARGET_BASE_ADDRESSES. */
913 mmix_constant_address_p (rtx x)
915 RTX_CODE code = GET_CODE (x);
916 int addend = 0;
917 /* When using "base addresses", anything constant goes. */
918 int constant_ok = TARGET_BASE_ADDRESSES != 0;
920 switch (code)
922 case LABEL_REF:
923 case SYMBOL_REF:
924 return 1;
926 case HIGH:
927 /* FIXME: Don't know how to dissect these. Avoid them for now,
928 except we know they're constants. */
929 return constant_ok;
931 case CONST_INT:
932 addend = INTVAL (x);
933 break;
935 case CONST_DOUBLE:
936 if (GET_MODE (x) != VOIDmode)
937 /* Strange that we got here. FIXME: Check if we do. */
938 return constant_ok;
939 addend = CONST_DOUBLE_LOW (x);
940 break;
942 case CONST:
943 /* Note that expressions with arithmetic on forward references don't
944 work in mmixal. People using gcc assembly code with mmixal might
945 need to move arrays and such to before the point of use. */
946 if (GET_CODE (XEXP (x, 0)) == PLUS)
948 rtx x0 = XEXP (XEXP (x, 0), 0);
949 rtx x1 = XEXP (XEXP (x, 0), 1);
951 if ((GET_CODE (x0) == SYMBOL_REF
952 || GET_CODE (x0) == LABEL_REF)
953 && (GET_CODE (x1) == CONST_INT
954 || (GET_CODE (x1) == CONST_DOUBLE
955 && GET_MODE (x1) == VOIDmode)))
956 addend = mmix_intval (x1);
957 else
958 return constant_ok;
960 else
961 return constant_ok;
962 break;
964 default:
965 return 0;
968 return constant_ok || (addend & 3) == 0;
971 /* Return 1 if the address is OK, otherwise 0.
972 Used by GO_IF_LEGITIMATE_ADDRESS. */
975 mmix_legitimate_address (enum machine_mode mode ATTRIBUTE_UNUSED,
976 rtx x,
977 int strict_checking)
979 #define MMIX_REG_OK(X) \
980 ((strict_checking \
981 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
982 || (reg_renumber[REGNO (X)] > 0 \
983 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
984 || (!strict_checking \
985 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
986 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
987 || REGNO (X) == ARG_POINTER_REGNUM)))
989 /* We only accept:
990 (mem reg)
991 (mem (plus reg reg))
992 (mem (plus reg 0..255)).
993 unless TARGET_BASE_ADDRESSES, in which case we accept all
994 (mem constant_address) too. */
997 /* (mem reg) */
998 if (REG_P (x) && MMIX_REG_OK (x))
999 return 1;
1001 if (GET_CODE(x) == PLUS)
1003 rtx x1 = XEXP (x, 0);
1004 rtx x2 = XEXP (x, 1);
1006 /* Try swapping the order. FIXME: Do we need this? */
1007 if (! REG_P (x1))
1009 rtx tem = x1;
1010 x1 = x2;
1011 x2 = tem;
1014 /* (mem (plus (reg?) (?))) */
1015 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1016 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1018 /* (mem (plus (reg) (reg?))) */
1019 if (REG_P (x2) && MMIX_REG_OK (x2))
1020 return 1;
1022 /* (mem (plus (reg) (0..255?))) */
1023 if (GET_CODE (x2) == CONST_INT
1024 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1025 return 1;
1027 return 0;
1030 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1033 /* LEGITIMATE_CONSTANT_P. */
1036 mmix_legitimate_constant_p (rtx x)
1038 RTX_CODE code = GET_CODE (x);
1040 /* We must allow any number due to the way the cse passes works; if we
1041 do not allow any number here, general_operand will fail, and insns
1042 will fatally fail recognition instead of "softly". */
1043 if (code == CONST_INT || code == CONST_DOUBLE)
1044 return 1;
1046 return CONSTANT_ADDRESS_P (x);
1049 /* SELECT_CC_MODE. */
1051 enum machine_mode
1052 mmix_select_cc_mode (RTX_CODE op, rtx x, rtx y ATTRIBUTE_UNUSED)
1054 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1055 output different compare insns. Note that we do not check the
1056 validity of the comparison here. */
1058 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1060 if (op == ORDERED || op == UNORDERED || op == UNGE
1061 || op == UNGT || op == UNLE || op == UNLT)
1062 return CC_FUNmode;
1064 if (op == EQ || op == NE)
1065 return CC_FPEQmode;
1067 return CC_FPmode;
1070 if (op == GTU || op == LTU || op == GEU || op == LEU)
1071 return CC_UNSmode;
1073 return CCmode;
1076 /* REVERSIBLE_CC_MODE. */
1079 mmix_reversible_cc_mode (enum machine_mode mode)
1081 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1082 compares. */
1083 return mode != CC_FPmode;
1086 /* TARGET_RTX_COSTS. */
1088 static bool
1089 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED,
1090 int code ATTRIBUTE_UNUSED,
1091 int outer_code ATTRIBUTE_UNUSED,
1092 int *total ATTRIBUTE_UNUSED)
1094 /* For the time being, this is just a stub and we'll accept the
1095 generic calculations, until we can do measurements, at least.
1096 Say we did not modify any calculated costs. */
1097 return false;
1100 /* REGISTER_MOVE_COST. */
1103 mmix_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1104 enum reg_class from,
1105 enum reg_class to)
1107 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1110 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1111 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1112 the target. */
1114 /* DATA_SECTION_ASM_OP. */
1116 const char *
1117 mmix_data_section_asm_op (void)
1119 return "\t.data ! mmixal:= 8H LOC 9B";
1122 static void
1123 mmix_encode_section_info (tree decl, rtx rtl, int first)
1125 /* Test for an external declaration, and do nothing if it is one. */
1126 if ((TREE_CODE (decl) == VAR_DECL
1127 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1128 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1130 else if (first && DECL_P (decl))
1132 /* For non-visible declarations, add a "@" prefix, which we skip
1133 when the label is output. If the label does not have this
1134 prefix, a ":" is output if -mtoplevel-symbols.
1136 Note that this does not work for data that is declared extern and
1137 later defined as static. If there's code in between, that code
1138 will refer to the extern declaration, and vice versa. This just
1139 means that when -mtoplevel-symbols is in use, we can just handle
1140 well-behaved ISO-compliant code. */
1142 const char *str = XSTR (XEXP (rtl, 0), 0);
1143 int len = strlen (str);
1144 char *newstr;
1146 /* Why is the return type of ggc_alloc_string const? */
1147 newstr = (char *) ggc_alloc_string ("", len + 1);
1149 strcpy (newstr + 1, str);
1150 *newstr = '@';
1151 XSTR (XEXP (rtl, 0), 0) = newstr;
1154 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1155 may need different options to reach for different things with GETA.
1156 For now, functions and things we know or have been told are constant. */
1157 if (TREE_CODE (decl) == FUNCTION_DECL
1158 || TREE_CONSTANT (decl)
1159 || (TREE_CODE (decl) == VAR_DECL
1160 && TREE_READONLY (decl)
1161 && !TREE_SIDE_EFFECTS (decl)
1162 && (!DECL_INITIAL (decl)
1163 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1164 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1167 static const char *
1168 mmix_strip_name_encoding (const char *name)
1170 for (; (*name == '@' || *name == '*'); name++)
1173 return name;
1176 /* TARGET_ASM_FILE_START.
1177 We just emit a little comment for the time being. */
1179 static void
1180 mmix_file_start (void)
1182 default_file_start ();
1184 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file);
1186 /* Make sure each file starts with the text section. */
1187 text_section ();
1190 /* TARGET_ASM_FILE_END. */
1192 static void
1193 mmix_file_end (void)
1195 /* Make sure each file ends with the data section. */
1196 data_section ();
1199 /* ASM_OUTPUT_SOURCE_FILENAME. */
1201 void
1202 mmix_asm_output_source_filename (FILE *stream, const char *name)
1204 fprintf (stream, "# 1 ");
1205 OUTPUT_QUOTED_STRING (stream, name);
1206 fprintf (stream, "\n");
1209 /* OUTPUT_QUOTED_STRING. */
1211 void
1212 mmix_output_quoted_string (FILE *stream, const char *string, int length)
1214 const char * string_end = string + length;
1215 static const char *const unwanted_chars = "\"[]\\";
1217 /* Output "any character except newline and double quote character". We
1218 play it safe and avoid all control characters too. We also do not
1219 want [] as characters, should input be passed through m4 with [] as
1220 quotes. Further, we avoid "\", because the GAS port handles it as a
1221 quoting character. */
1222 while (string < string_end)
1224 if (*string
1225 && (unsigned char) *string < 128
1226 && !ISCNTRL (*string)
1227 && strchr (unwanted_chars, *string) == NULL)
1229 fputc ('"', stream);
1230 while (*string
1231 && (unsigned char) *string < 128
1232 && !ISCNTRL (*string)
1233 && strchr (unwanted_chars, *string) == NULL
1234 && string < string_end)
1236 fputc (*string, stream);
1237 string++;
1239 fputc ('"', stream);
1240 if (string < string_end)
1241 fprintf (stream, ",");
1243 if (string < string_end)
1245 fprintf (stream, "#%x", *string & 255);
1246 string++;
1247 if (string < string_end)
1248 fprintf (stream, ",");
1253 /* Target hook for assembling integer objects. Use mmix_print_operand
1254 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1255 CONST_DOUBLEs. */
1257 static bool
1258 mmix_assemble_integer (rtx x, unsigned int size, int aligned_p)
1260 if (aligned_p)
1261 switch (size)
1263 /* We handle a limited number of types of operands in here. But
1264 that's ok, because we can punt to generic functions. We then
1265 pretend that aligned data isn't needed, so the usual .<pseudo>
1266 syntax is used (which works for aligned data too). We actually
1267 *must* do that, since we say we don't have simple aligned
1268 pseudos, causing this function to be called. We just try and
1269 keep as much compatibility as possible with mmixal syntax for
1270 normal cases (i.e. without GNU extensions and C only). */
1271 case 1:
1272 if (GET_CODE (x) != CONST_INT)
1274 aligned_p = 0;
1275 break;
1277 fputs ("\tBYTE\t", asm_out_file);
1278 mmix_print_operand (asm_out_file, x, 'B');
1279 fputc ('\n', asm_out_file);
1280 return true;
1282 case 2:
1283 if (GET_CODE (x) != CONST_INT)
1285 aligned_p = 0;
1286 break;
1288 fputs ("\tWYDE\t", asm_out_file);
1289 mmix_print_operand (asm_out_file, x, 'W');
1290 fputc ('\n', asm_out_file);
1291 return true;
1293 case 4:
1294 if (GET_CODE (x) != CONST_INT)
1296 aligned_p = 0;
1297 break;
1299 fputs ("\tTETRA\t", asm_out_file);
1300 mmix_print_operand (asm_out_file, x, 'L');
1301 fputc ('\n', asm_out_file);
1302 return true;
1304 case 8:
1305 if (GET_CODE (x) == CONST_DOUBLE)
1306 /* We don't get here anymore for CONST_DOUBLE, because DImode
1307 isn't expressed as CONST_DOUBLE, and DFmode is handled
1308 elsewhere. */
1309 abort ();
1310 assemble_integer_with_op ("\tOCTA\t", x);
1311 return true;
1313 return default_assemble_integer (x, size, aligned_p);
1316 /* ASM_OUTPUT_ASCII. */
1318 void
1319 mmix_asm_output_ascii (FILE *stream, const char *string, int length)
1321 while (length > 0)
1323 int chunk_size = length > 60 ? 60 : length;
1324 fprintf (stream, "\tBYTE ");
1325 mmix_output_quoted_string (stream, string, chunk_size);
1326 string += chunk_size;
1327 length -= chunk_size;
1328 fprintf (stream, "\n");
1332 /* ASM_OUTPUT_ALIGNED_COMMON. */
1334 void
1335 mmix_asm_output_aligned_common (FILE *stream,
1336 const char *name,
1337 int size,
1338 int align)
1340 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1341 express this in a mmixal-compatible way. */
1342 fprintf (stream, "\t.comm\t");
1343 assemble_name (stream, name);
1344 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1345 size, align / BITS_PER_UNIT);
1348 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1350 void
1351 mmix_asm_output_aligned_local (FILE *stream,
1352 const char *name,
1353 int size,
1354 int align)
1356 data_section ();
1358 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1359 assemble_name (stream, name);
1360 fprintf (stream, "\tLOC @+%d\n", size);
1363 /* ASM_OUTPUT_LABEL. */
1365 void
1366 mmix_asm_output_label (FILE *stream, const char *name)
1368 assemble_name (stream, name);
1369 fprintf (stream, "\tIS @\n");
1372 /* ASM_OUTPUT_INTERNAL_LABEL. */
1374 void
1375 mmix_asm_output_internal_label (FILE *stream, const char *name)
1377 assemble_name_raw (stream, name);
1378 fprintf (stream, "\tIS @\n");
1381 /* ASM_DECLARE_REGISTER_GLOBAL. */
1383 void
1384 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED,
1385 tree decl ATTRIBUTE_UNUSED,
1386 int regno ATTRIBUTE_UNUSED,
1387 const char *name ATTRIBUTE_UNUSED)
1389 /* Nothing to do here, but there *will* be, therefore the framework is
1390 here. */
1393 /* ASM_WEAKEN_LABEL. */
1395 void
1396 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED,
1397 const char *name ATTRIBUTE_UNUSED)
1399 fprintf (stream, "\t.weak ");
1400 assemble_name (stream, name);
1401 fprintf (stream, " ! mmixal-incompatible\n");
1404 /* MAKE_DECL_ONE_ONLY. */
1406 void
1407 mmix_make_decl_one_only (tree decl)
1409 DECL_WEAK (decl) = 1;
1412 /* ASM_OUTPUT_LABELREF.
1413 Strip GCC's '*' and our own '@'. No order is assumed. */
1415 void
1416 mmix_asm_output_labelref (FILE *stream, const char *name)
1418 int is_extern = 1;
1420 for (; (*name == '@' || *name == '*'); name++)
1421 if (*name == '@')
1422 is_extern = 0;
1424 asm_fprintf (stream, "%s%U%s",
1425 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
1426 name);
1429 /* ASM_OUTPUT_DEF. */
1431 void
1432 mmix_asm_output_def (FILE *stream, const char *name, const char *value)
1434 assemble_name (stream, name);
1435 fprintf (stream, "\tIS ");
1436 assemble_name (stream, value);
1437 fputc ('\n', stream);
1440 /* PRINT_OPERAND. */
1442 void
1443 mmix_print_operand (FILE *stream, rtx x, int code)
1445 /* When we add support for different codes later, we can, when needed,
1446 drop through to the main handler with a modified operand. */
1447 rtx modified_x = x;
1448 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
1450 switch (code)
1452 /* Unrelated codes are in alphabetic order. */
1454 case '+':
1455 /* For conditional branches, output "P" for a probable branch. */
1456 if (TARGET_BRANCH_PREDICT)
1458 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
1459 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
1460 putc ('P', stream);
1462 return;
1464 case '.':
1465 /* For the %d in POP %d,0. */
1466 fprintf (stream, "%d", MMIX_POP_ARGUMENT ());
1467 return;
1469 case 'B':
1470 if (GET_CODE (x) != CONST_INT)
1471 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1472 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
1473 return;
1475 case 'H':
1476 /* Highpart. Must be general register, and not the last one, as
1477 that one cannot be part of a consecutive register pair. */
1478 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1479 internal_error ("MMIX Internal: Bad register: %d", regno);
1481 /* This is big-endian, so the high-part is the first one. */
1482 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1483 return;
1485 case 'L':
1486 /* Lowpart. Must be CONST_INT or general register, and not the last
1487 one, as that one cannot be part of a consecutive register pair. */
1488 if (GET_CODE (x) == CONST_INT)
1490 fprintf (stream, "#%lx",
1491 (unsigned long) (INTVAL (x)
1492 & ((unsigned int) 0x7fffffff * 2 + 1)));
1493 return;
1496 if (GET_CODE (x) == SYMBOL_REF)
1498 output_addr_const (stream, x);
1499 return;
1502 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1503 internal_error ("MMIX Internal: Bad register: %d", regno);
1505 /* This is big-endian, so the low-part is + 1. */
1506 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
1507 return;
1509 /* Can't use 'a' because that's a generic modifier for address
1510 output. */
1511 case 'A':
1512 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
1513 ~(unsigned HOST_WIDEST_INT)
1514 mmix_intval (x));
1515 return;
1517 case 'i':
1518 mmix_output_shiftvalue_op_from_str (stream, "INC",
1519 (unsigned HOST_WIDEST_INT)
1520 mmix_intval (x));
1521 return;
1523 case 'o':
1524 mmix_output_shiftvalue_op_from_str (stream, "OR",
1525 (unsigned HOST_WIDEST_INT)
1526 mmix_intval (x));
1527 return;
1529 case 's':
1530 mmix_output_shiftvalue_op_from_str (stream, "SET",
1531 (unsigned HOST_WIDEST_INT)
1532 mmix_intval (x));
1533 return;
1535 case 'd':
1536 case 'D':
1537 mmix_output_condition (stream, x, (code == 'D'));
1538 return;
1540 case 'e':
1541 /* Output an extra "e" to make fcmpe, fune. */
1542 if (TARGET_FCMP_EPSILON)
1543 fprintf (stream, "e");
1544 return;
1546 case 'm':
1547 /* Output the number minus 1. */
1548 if (GET_CODE (x) != CONST_INT)
1550 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1553 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
1554 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
1555 return;
1557 case 'p':
1558 /* Store the number of registers we want to save. This was setup
1559 by the prologue. The actual operand contains the number of
1560 registers to pass, but we don't use it currently. Anyway, we
1561 need to output the number of saved registers here. */
1562 fprintf (stream, "%d",
1563 cfun->machine->highest_saved_stack_register + 1);
1564 return;
1566 case 'r':
1567 /* Store the register to output a constant to. */
1568 if (! REG_P (x))
1569 fatal_insn ("MMIX Internal: Expected a register, not this", x);
1570 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
1571 return;
1573 case 'I':
1574 /* Output the constant. Note that we use this for floats as well. */
1575 if (GET_CODE (x) != CONST_INT
1576 && (GET_CODE (x) != CONST_DOUBLE
1577 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
1578 && GET_MODE (x) != SFmode)))
1579 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
1580 mmix_output_register_setting (stream,
1581 mmix_output_destination_register,
1582 mmix_intval (x), 0);
1583 return;
1585 case 'U':
1586 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1587 if (TARGET_ZERO_EXTEND)
1588 putc ('U', stream);
1589 return;
1591 case 'v':
1592 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
1593 return;
1595 case 'V':
1596 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
1597 return;
1599 case 'W':
1600 if (GET_CODE (x) != CONST_INT)
1601 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1602 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
1603 return;
1605 case 0:
1606 /* Nothing to do. */
1607 break;
1609 default:
1610 /* Presumably there's a missing case above if we get here. */
1611 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code);
1614 switch (GET_CODE (modified_x))
1616 case REG:
1617 regno = REGNO (modified_x);
1618 if (regno >= FIRST_PSEUDO_REGISTER)
1619 internal_error ("MMIX Internal: Bad register: %d", regno);
1620 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1621 return;
1623 case MEM:
1624 output_address (XEXP (modified_x, 0));
1625 return;
1627 case CONST_INT:
1628 /* For -2147483648, mmixal complains that the constant does not fit
1629 in 4 bytes, so let's output it as hex. Take care to handle hosts
1630 where HOST_WIDE_INT is longer than an int.
1632 Print small constants +-255 using decimal. */
1634 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
1635 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
1636 else
1637 fprintf (stream, "#%x",
1638 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
1639 return;
1641 case CONST_DOUBLE:
1642 /* Do somewhat as CONST_INT. */
1643 mmix_output_octa (stream, mmix_intval (modified_x), 0);
1644 return;
1646 case CONST:
1647 output_addr_const (stream, modified_x);
1648 return;
1650 default:
1651 /* No need to test for all strange things. Let output_addr_const do
1652 it for us. */
1653 if (CONSTANT_P (modified_x)
1654 /* Strangely enough, this is not included in CONSTANT_P.
1655 FIXME: Ask/check about sanity here. */
1656 || GET_CODE (modified_x) == CODE_LABEL)
1658 output_addr_const (stream, modified_x);
1659 return;
1662 /* We need the original here. */
1663 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
1667 /* PRINT_OPERAND_PUNCT_VALID_P. */
1670 mmix_print_operand_punct_valid_p (int code ATTRIBUTE_UNUSED)
1672 /* A '+' is used for branch prediction, similar to other ports. */
1673 return code == '+'
1674 /* A '.' is used for the %d in the POP %d,0 return insn. */
1675 || code == '.';
1678 /* PRINT_OPERAND_ADDRESS. */
1680 void
1681 mmix_print_operand_address (FILE *stream, rtx x)
1683 if (REG_P (x))
1685 /* I find the generated assembly code harder to read without
1686 the ",0". */
1687 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
1688 return;
1690 else if (GET_CODE (x) == PLUS)
1692 rtx x1 = XEXP (x, 0);
1693 rtx x2 = XEXP (x, 1);
1695 if (REG_P (x1))
1697 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
1699 if (REG_P (x2))
1701 fprintf (stream, "%s",
1702 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
1703 return;
1705 else if (GET_CODE (x2) == CONST_INT
1706 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1708 output_addr_const (stream, x2);
1709 return;
1714 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (x))
1716 output_addr_const (stream, x);
1717 return;
1720 fatal_insn ("MMIX Internal: This is not a recognized address", x);
1723 /* ASM_OUTPUT_REG_PUSH. */
1725 void
1726 mmix_asm_output_reg_push (FILE *stream, int regno)
1728 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1729 reg_names[MMIX_STACK_POINTER_REGNUM],
1730 reg_names[MMIX_STACK_POINTER_REGNUM],
1731 reg_names[MMIX_OUTPUT_REGNO (regno)],
1732 reg_names[MMIX_STACK_POINTER_REGNUM]);
1735 /* ASM_OUTPUT_REG_POP. */
1737 void
1738 mmix_asm_output_reg_pop (FILE *stream, int regno)
1740 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1741 reg_names[MMIX_OUTPUT_REGNO (regno)],
1742 reg_names[MMIX_STACK_POINTER_REGNUM],
1743 reg_names[MMIX_STACK_POINTER_REGNUM]);
1746 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1748 void
1749 mmix_asm_output_addr_diff_elt (FILE *stream,
1750 rtx body ATTRIBUTE_UNUSED,
1751 int value,
1752 int rel)
1754 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
1757 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1759 void
1760 mmix_asm_output_addr_vec_elt (FILE *stream, int value)
1762 fprintf (stream, "\tOCTA L:%d\n", value);
1765 /* ASM_OUTPUT_SKIP. */
1767 void
1768 mmix_asm_output_skip (FILE *stream, int nbytes)
1770 fprintf (stream, "\tLOC @+%d\n", nbytes);
1773 /* ASM_OUTPUT_ALIGN. */
1775 void
1776 mmix_asm_output_align (FILE *stream, int power)
1778 /* We need to record the needed alignment of this section in the object,
1779 so we have to output an alignment directive. Use a .p2align (not
1780 .align) so people will never have to wonder about whether the
1781 argument is in number of bytes or the log2 thereof. We do it in
1782 addition to the LOC directive, so nothing needs tweaking when
1783 copy-pasting assembly into mmixal. */
1784 fprintf (stream, "\t.p2align %d\n", power);
1785 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
1788 /* DBX_REGISTER_NUMBER. */
1791 mmix_dbx_register_number (int regno)
1793 /* Adjust the register number to the one it will be output as, dammit.
1794 It'd be nice if we could check the assumption that we're filling a
1795 gap, but every register between the last saved register and parameter
1796 registers might be a valid parameter register. */
1797 regno = MMIX_OUTPUT_REGNO (regno);
1799 /* We need to renumber registers to get the number of the return address
1800 register in the range 0..255. It is also space-saving if registers
1801 mentioned in the call-frame information (which uses this function by
1802 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1803 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1804 return regno >= 224 ? (regno - 224) : (regno + 48);
1807 /* End of target macro support functions.
1809 Now the MMIX port's own functions. First the exported ones. */
1811 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1812 from insn-emit.c. */
1815 mmix_get_hard_reg_initial_val (enum machine_mode mode, int regno)
1817 return get_hard_reg_initial_val (mode, regno);
1820 /* Nonzero when the function epilogue is simple enough that a single
1821 "POP %d,0" should be used even within the function. */
1824 mmix_use_simple_return (void)
1826 int regno;
1828 int stack_space_to_allocate
1829 = (current_function_outgoing_args_size
1830 + current_function_pretend_args_size
1831 + get_frame_size () + 7) & ~7;
1833 if (!TARGET_USE_RETURN_INSN || !reload_completed)
1834 return 0;
1836 for (regno = 255;
1837 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1838 regno--)
1839 /* Note that we assume that the frame-pointer-register is one of these
1840 registers, in which case we don't count it here. */
1841 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1842 && regs_ever_live[regno] && !call_used_regs[regno]))
1843 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1844 return 0;
1846 if (frame_pointer_needed)
1847 stack_space_to_allocate += 8;
1849 if (MMIX_CFUN_HAS_LANDING_PAD)
1850 stack_space_to_allocate += 16;
1851 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1852 stack_space_to_allocate += 8;
1854 return stack_space_to_allocate == 0;
1858 /* Expands the function prologue into RTX. */
1860 void
1861 mmix_expand_prologue (void)
1863 HOST_WIDE_INT locals_size = get_frame_size ();
1864 int regno;
1865 HOST_WIDE_INT stack_space_to_allocate
1866 = (current_function_outgoing_args_size
1867 + current_function_pretend_args_size
1868 + locals_size + 7) & ~7;
1869 HOST_WIDE_INT offset = -8;
1871 /* Add room needed to save global non-register-stack registers. */
1872 for (regno = 255;
1873 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1874 regno--)
1875 /* Note that we assume that the frame-pointer-register is one of these
1876 registers, in which case we don't count it here. */
1877 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1878 && regs_ever_live[regno] && !call_used_regs[regno]))
1879 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1880 stack_space_to_allocate += 8;
1882 /* If we do have a frame-pointer, add room for it. */
1883 if (frame_pointer_needed)
1884 stack_space_to_allocate += 8;
1886 /* If we have a non-local label, we need to be able to unwind to it, so
1887 store the current register stack pointer. Also store the return
1888 address if we do that. */
1889 if (MMIX_CFUN_HAS_LANDING_PAD)
1890 stack_space_to_allocate += 16;
1891 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1892 /* If we do have a saved return-address slot, add room for it. */
1893 stack_space_to_allocate += 8;
1895 /* Make sure we don't get an unaligned stack. */
1896 if ((stack_space_to_allocate % 8) != 0)
1897 internal_error ("stack frame not a multiple of 8 bytes: %d",
1898 stack_space_to_allocate);
1900 if (current_function_pretend_args_size)
1902 int mmix_first_vararg_reg
1903 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1904 + (MMIX_MAX_ARGS_IN_REGS
1905 - current_function_pretend_args_size / 8));
1907 for (regno
1908 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
1909 regno >= mmix_first_vararg_reg;
1910 regno--)
1912 if (offset < 0)
1914 HOST_WIDE_INT stack_chunk
1915 = stack_space_to_allocate > (256 - 8)
1916 ? (256 - 8) : stack_space_to_allocate;
1918 mmix_emit_sp_add (-stack_chunk);
1919 offset += stack_chunk;
1920 stack_space_to_allocate -= stack_chunk;
1923 /* These registers aren't actually saved (as in "will be
1924 restored"), so don't tell DWARF2 they're saved. */
1925 emit_move_insn (gen_rtx_MEM (DImode,
1926 plus_constant (stack_pointer_rtx,
1927 offset)),
1928 gen_rtx_REG (DImode, regno));
1929 offset -= 8;
1933 /* Store the frame-pointer. */
1935 if (frame_pointer_needed)
1937 rtx insn;
1939 if (offset < 0)
1941 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1942 HOST_WIDE_INT stack_chunk
1943 = stack_space_to_allocate > (256 - 8 - 8)
1944 ? (256 - 8 - 8) : stack_space_to_allocate;
1946 mmix_emit_sp_add (-stack_chunk);
1948 offset += stack_chunk;
1949 stack_space_to_allocate -= stack_chunk;
1952 insn = emit_move_insn (gen_rtx_MEM (DImode,
1953 plus_constant (stack_pointer_rtx,
1954 offset)),
1955 hard_frame_pointer_rtx);
1956 RTX_FRAME_RELATED_P (insn) = 1;
1957 insn = emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
1958 stack_pointer_rtx,
1959 GEN_INT (offset + 8)));
1960 RTX_FRAME_RELATED_P (insn) = 1;
1961 offset -= 8;
1964 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1966 rtx tmpreg, retreg;
1967 rtx insn;
1969 /* Store the return-address, if one is needed on the stack. We
1970 usually store it in a register when needed, but that doesn't work
1971 with -fexceptions. */
1973 if (offset < 0)
1975 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1976 HOST_WIDE_INT stack_chunk
1977 = stack_space_to_allocate > (256 - 8 - 8)
1978 ? (256 - 8 - 8) : stack_space_to_allocate;
1980 mmix_emit_sp_add (-stack_chunk);
1982 offset += stack_chunk;
1983 stack_space_to_allocate -= stack_chunk;
1986 tmpreg = gen_rtx_REG (DImode, 255);
1987 retreg = gen_rtx_REG (DImode, MMIX_rJ_REGNUM);
1989 /* Dwarf2 code is confused by the use of a temporary register for
1990 storing the return address, so we have to express it as a note,
1991 which we attach to the actual store insn. */
1992 emit_move_insn (tmpreg, retreg);
1994 insn = emit_move_insn (gen_rtx_MEM (DImode,
1995 plus_constant (stack_pointer_rtx,
1996 offset)),
1997 tmpreg);
1998 RTX_FRAME_RELATED_P (insn) = 1;
1999 REG_NOTES (insn)
2000 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
2001 gen_rtx_SET (VOIDmode,
2002 gen_rtx_MEM (DImode,
2003 plus_constant (stack_pointer_rtx,
2004 offset)),
2005 retreg),
2006 REG_NOTES (insn));
2008 offset -= 8;
2010 else if (MMIX_CFUN_HAS_LANDING_PAD)
2011 offset -= 8;
2013 if (MMIX_CFUN_HAS_LANDING_PAD)
2015 /* Store the register defining the numbering of local registers, so
2016 we know how long to unwind the register stack. */
2018 if (offset < 0)
2020 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2021 HOST_WIDE_INT stack_chunk
2022 = stack_space_to_allocate > (256 - 8 - 8)
2023 ? (256 - 8 - 8) : stack_space_to_allocate;
2025 mmix_emit_sp_add (-stack_chunk);
2027 offset += stack_chunk;
2028 stack_space_to_allocate -= stack_chunk;
2031 /* We don't tell dwarf2 about this one; we just have it to unwind
2032 the register stack at landing pads. FIXME: It's a kludge because
2033 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2034 register stack at the moment. Best thing would be to handle it
2035 like stack-pointer offsets. Better: some hook into dwarf2out.c
2036 to produce DW_CFA_expression:s that specify the increment of rO,
2037 and unwind it at eh_return (preferred) or at the landing pad.
2038 Then saves to $0..$G-1 could be specified through that register. */
2040 emit_move_insn (gen_rtx_REG (DImode, 255),
2041 gen_rtx_REG (DImode,
2042 MMIX_rO_REGNUM));
2043 emit_move_insn (gen_rtx_MEM (DImode,
2044 plus_constant (stack_pointer_rtx, offset)),
2045 gen_rtx_REG (DImode, 255));
2046 offset -= 8;
2049 /* After the return-address and the frame-pointer, we have the local
2050 variables. They're the ones that may have an "unaligned" size. */
2051 offset -= (locals_size + 7) & ~7;
2053 /* Now store all registers that are global, i.e. not saved by the
2054 register file machinery.
2056 It is assumed that the frame-pointer is one of these registers, so it
2057 is explicitly excluded in the count. */
2059 for (regno = 255;
2060 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2061 regno--)
2062 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2063 && regs_ever_live[regno] && ! call_used_regs[regno])
2064 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2066 rtx insn;
2068 if (offset < 0)
2070 HOST_WIDE_INT stack_chunk
2071 = (stack_space_to_allocate > (256 - offset - 8)
2072 ? (256 - offset - 8) : stack_space_to_allocate);
2074 mmix_emit_sp_add (-stack_chunk);
2075 offset += stack_chunk;
2076 stack_space_to_allocate -= stack_chunk;
2079 insn = emit_move_insn (gen_rtx_MEM (DImode,
2080 plus_constant (stack_pointer_rtx,
2081 offset)),
2082 gen_rtx_REG (DImode, regno));
2083 RTX_FRAME_RELATED_P (insn) = 1;
2084 offset -= 8;
2087 /* Finally, allocate room for outgoing args and local vars if room
2088 wasn't allocated above. */
2089 if (stack_space_to_allocate)
2090 mmix_emit_sp_add (-stack_space_to_allocate);
2093 /* Expands the function epilogue into RTX. */
2095 void
2096 mmix_expand_epilogue (void)
2098 HOST_WIDE_INT locals_size = get_frame_size ();
2099 int regno;
2100 HOST_WIDE_INT stack_space_to_deallocate
2101 = (current_function_outgoing_args_size
2102 + current_function_pretend_args_size
2103 + locals_size + 7) & ~7;
2105 /* The first address to access is beyond the outgoing_args area. */
2106 HOST_WIDE_INT offset = current_function_outgoing_args_size;
2108 /* Add the space for global non-register-stack registers.
2109 It is assumed that the frame-pointer register can be one of these
2110 registers, in which case it is excluded from the count when needed. */
2111 for (regno = 255;
2112 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2113 regno--)
2114 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2115 && regs_ever_live[regno] && !call_used_regs[regno])
2116 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2117 stack_space_to_deallocate += 8;
2119 /* Add in the space for register stack-pointer. If so, always add room
2120 for the saved PC. */
2121 if (MMIX_CFUN_HAS_LANDING_PAD)
2122 stack_space_to_deallocate += 16;
2123 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2124 /* If we have a saved return-address slot, add it in. */
2125 stack_space_to_deallocate += 8;
2127 /* Add in the frame-pointer. */
2128 if (frame_pointer_needed)
2129 stack_space_to_deallocate += 8;
2131 /* Make sure we don't get an unaligned stack. */
2132 if ((stack_space_to_deallocate % 8) != 0)
2133 internal_error ("stack frame not a multiple of octabyte: %d",
2134 stack_space_to_deallocate);
2136 /* We will add back small offsets to the stack pointer as we go.
2137 First, we restore all registers that are global, i.e. not saved by
2138 the register file machinery. */
2140 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
2141 regno <= 255;
2142 regno++)
2143 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2144 && regs_ever_live[regno] && !call_used_regs[regno])
2145 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2147 if (offset > 255)
2149 mmix_emit_sp_add (offset);
2150 stack_space_to_deallocate -= offset;
2151 offset = 0;
2154 emit_move_insn (gen_rtx_REG (DImode, regno),
2155 gen_rtx_MEM (DImode,
2156 plus_constant (stack_pointer_rtx,
2157 offset)));
2158 offset += 8;
2161 /* Here is where the local variables were. As in the prologue, they
2162 might be of an unaligned size. */
2163 offset += (locals_size + 7) & ~7;
2165 /* The saved register stack pointer is just below the frame-pointer
2166 register. We don't need to restore it "manually"; the POP
2167 instruction does that. */
2168 if (MMIX_CFUN_HAS_LANDING_PAD)
2169 offset += 16;
2170 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2171 /* The return-address slot is just below the frame-pointer register.
2172 We don't need to restore it because we don't really use it. */
2173 offset += 8;
2175 /* Get back the old frame-pointer-value. */
2176 if (frame_pointer_needed)
2178 if (offset > 255)
2180 mmix_emit_sp_add (offset);
2182 stack_space_to_deallocate -= offset;
2183 offset = 0;
2186 emit_move_insn (hard_frame_pointer_rtx,
2187 gen_rtx_MEM (DImode,
2188 plus_constant (stack_pointer_rtx,
2189 offset)));
2190 offset += 8;
2193 /* We do not need to restore pretended incoming args, just add back
2194 offset to sp. */
2195 if (stack_space_to_deallocate != 0)
2196 mmix_emit_sp_add (stack_space_to_deallocate);
2198 if (current_function_calls_eh_return)
2199 /* Adjust the (normal) stack-pointer to that of the receiver.
2200 FIXME: It would be nice if we could also adjust the register stack
2201 here, but we need to express it through DWARF 2 too. */
2202 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
2203 gen_rtx_REG (DImode,
2204 MMIX_EH_RETURN_STACKADJ_REGNUM)));
2207 /* Output an optimal sequence for setting a register to a specific
2208 constant. Used in an alternative for const_ints in movdi, and when
2209 using large stack-frame offsets.
2211 Use do_begin_end to say if a line-starting TAB and newline before the
2212 first insn and after the last insn is wanted. */
2214 void
2215 mmix_output_register_setting (FILE *stream,
2216 int regno,
2217 HOST_WIDEST_INT value,
2218 int do_begin_end)
2220 if (do_begin_end)
2221 fprintf (stream, "\t");
2223 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2225 /* First, the one-insn cases. */
2226 mmix_output_shiftvalue_op_from_str (stream, "SET",
2227 (unsigned HOST_WIDEST_INT)
2228 value);
2229 fprintf (stream, " %s,", reg_names[regno]);
2230 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2232 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2234 /* We do this to get a bit more legible assembly code. The next
2235 alternative is mostly redundant with this. */
2237 mmix_output_shiftvalue_op_from_str (stream, "SET",
2238 -(unsigned HOST_WIDEST_INT)
2239 value);
2240 fprintf (stream, " %s,", reg_names[regno]);
2241 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2242 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2243 reg_names[regno]);
2245 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2247 /* Slightly more expensive, the two-insn cases. */
2249 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2250 is shiftable, or any other one-insn transformation of the value.
2251 FIXME: Check first if the value is "shiftable" by two loading
2252 with two insns, since it makes more readable assembly code (if
2253 anyone else cares). */
2255 mmix_output_shiftvalue_op_from_str (stream, "SET",
2256 ~(unsigned HOST_WIDEST_INT)
2257 value);
2258 fprintf (stream, " %s,", reg_names[regno]);
2259 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2260 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2261 reg_names[regno]);
2263 else
2265 /* The generic case. 2..4 insns. */
2266 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2267 const char *op = "SET";
2268 const char *line_begin = "";
2269 int insns = 0;
2270 int i;
2271 HOST_WIDEST_INT tmpvalue = value;
2273 /* Compute the number of insns needed to output this constant. */
2274 for (i = 0; i < 4 && tmpvalue != 0; i++)
2276 if (tmpvalue & 65535)
2277 insns++;
2278 tmpvalue >>= 16;
2280 if (TARGET_BASE_ADDRESSES && insns == 3)
2282 /* The number three is based on a static observation on
2283 ghostscript-6.52. Two and four are excluded because there
2284 are too many such constants, and each unique constant (maybe
2285 offset by 1..255) were used few times compared to other uses,
2286 e.g. addresses.
2288 We use base-plus-offset addressing to force it into a global
2289 register; we just use a "LDA reg,VALUE", which will cause the
2290 assembler and linker to DTRT (for constants as well as
2291 addresses). */
2292 fprintf (stream, "LDA %s,", reg_names[regno]);
2293 mmix_output_octa (stream, value, 0);
2295 else
2297 /* Output pertinent parts of the 4-wyde sequence.
2298 Still more to do if we want this to be optimal, but hey...
2299 Note that the zero case has been handled above. */
2300 for (i = 0; i < 4 && value != 0; i++)
2302 if (value & 65535)
2304 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2305 higher_parts[i], reg_names[regno],
2306 (int) (value & 65535));
2307 /* The first one sets the rest of the bits to 0, the next
2308 ones add set bits. */
2309 op = "INC";
2310 line_begin = "\n\t";
2313 value >>= 16;
2318 if (do_begin_end)
2319 fprintf (stream, "\n");
2322 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2323 else return 0. */
2326 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value)
2328 /* Shift by 16 bits per group, stop when we've found two groups with
2329 nonzero bits. */
2330 int i;
2331 int has_candidate = 0;
2333 for (i = 0; i < 4; i++)
2335 if (value & 65535)
2337 if (has_candidate)
2338 return 0;
2339 else
2340 has_candidate = 1;
2343 value >>= 16;
2346 return 1;
2349 /* True if this is an address_operand or a symbolic operand. */
2352 mmix_symbolic_or_address_operand (rtx op, enum machine_mode mode)
2354 switch (GET_CODE (op))
2356 case SYMBOL_REF:
2357 case LABEL_REF:
2358 return 1;
2359 case CONST:
2360 op = XEXP (op, 0);
2361 if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2362 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
2363 && (GET_CODE (XEXP (op, 1)) == CONST_INT
2364 || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE
2365 && GET_MODE (XEXP (op, 1)) == VOIDmode)))
2366 return 1;
2367 /* Fall through. */
2368 default:
2369 return address_operand (op, mode);
2373 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2374 We could narrow the value down with a couple of predicated, but that
2375 doesn't seem to be worth it at the moment. */
2378 mmix_reg_or_constant_operand (rtx op, enum machine_mode mode)
2380 return register_operand (op, mode)
2381 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
2382 || GET_CODE (op) == CONST_INT;
2385 /* True if this is a register with a condition-code mode. */
2388 mmix_reg_cc_operand (rtx op, enum machine_mode mode)
2390 if (mode == VOIDmode)
2391 mode = GET_MODE (op);
2393 return register_operand (op, mode)
2394 && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode
2395 || mode == CC_FPEQmode || mode == CC_FUNmode);
2398 /* True if this is a foldable comparison operator
2399 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2400 replaced by (reg). */
2403 mmix_foldable_comparison_operator (rtx op, enum machine_mode mode)
2405 RTX_CODE code = GET_CODE (op);
2407 if (mode == VOIDmode)
2408 mode = GET_MODE (op);
2410 if (mode == VOIDmode && COMPARISON_P (op))
2411 mode = GET_MODE (XEXP (op, 0));
2413 return ((mode == CCmode || mode == DImode)
2414 && (code == NE || code == EQ || code == GE || code == GT
2415 || code == LE))
2416 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2417 reverse the condition? Can it do that by itself? Maybe it can
2418 even reverse the condition to fit a foldable one in the first
2419 place? */
2420 || (mode == CC_UNSmode && (code == GTU || code == LEU));
2423 /* Like comparison_operator, but only true if this comparison operator is
2424 applied to a valid mode. Needed to avoid jump.c generating invalid
2425 code with -ffast-math (gcc.dg/20001228-1.c). */
2428 mmix_comparison_operator (rtx op, enum machine_mode mode)
2430 RTX_CODE code = GET_CODE (op);
2432 /* Comparison operators usually don't have a mode, but let's try and get
2433 one anyway for the day that changes. */
2434 if (mode == VOIDmode)
2435 mode = GET_MODE (op);
2437 /* Get the mode from the first operand if we don't have one. */
2438 if (mode == VOIDmode && COMPARISON_P (op))
2439 mode = GET_MODE (XEXP (op, 0));
2441 /* FIXME: This needs to be kept in sync with the tables in
2442 mmix_output_condition. */
2443 return
2444 (mode == VOIDmode && COMPARISON_P (op))
2445 || (mode == CC_FUNmode
2446 && (code == ORDERED || code == UNORDERED))
2447 || (mode == CC_FPmode
2448 && (code == GT || code == LT))
2449 || (mode == CC_FPEQmode
2450 && (code == NE || code == EQ))
2451 || (mode == CC_UNSmode
2452 && (code == GEU || code == GTU || code == LEU || code == LTU))
2453 || (mode == CCmode
2454 && (code == NE || code == EQ || code == GE || code == GT
2455 || code == LE || code == LT))
2456 || (mode == DImode
2457 && (code == NE || code == EQ || code == GE || code == GT
2458 || code == LE || code == LT || code == LEU || code == GTU));
2461 /* True if this is a register or 0 (int or float). */
2464 mmix_reg_or_0_operand (rtx op, enum machine_mode mode)
2466 /* FIXME: Is mode calculation necessary and correct? */
2467 return
2468 op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode)
2469 || register_operand (op, mode);
2472 /* True if this is a register or an int 0..255. */
2475 mmix_reg_or_8bit_operand (rtx op, enum machine_mode mode)
2477 return register_operand (op, mode)
2478 || (GET_CODE (op) == CONST_INT
2479 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
2482 /* Returns zero if code and mode is not a valid condition from a
2483 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2484 is the comparison of mode is CC-somethingmode. */
2487 mmix_valid_comparison (RTX_CODE code, enum machine_mode mode, rtx op)
2489 if (mode == VOIDmode && op != NULL_RTX)
2490 mode = GET_MODE (op);
2492 /* We don't care to look at these, they should always be valid. */
2493 if (mode == CCmode || mode == CC_UNSmode || mode == DImode)
2494 return 1;
2496 if ((mode == CC_FPmode || mode == DFmode)
2497 && (code == GT || code == LT))
2498 return 1;
2500 if ((mode == CC_FPEQmode || mode == DFmode)
2501 && (code == EQ || code == NE))
2502 return 1;
2504 if ((mode == CC_FUNmode || mode == DFmode)
2505 && (code == ORDERED || code == UNORDERED))
2506 return 1;
2508 return 0;
2511 /* X and Y are two things to compare using CODE. Emit a compare insn if
2512 possible and return the rtx for the cc-reg in the proper mode, or
2513 NULL_RTX if this is not a valid comparison. */
2516 mmix_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
2518 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2519 rtx cc_reg;
2521 /* FIXME: Do we get constants here? Of double mode? */
2522 enum machine_mode mode
2523 = GET_MODE (x) == VOIDmode
2524 ? GET_MODE (y)
2525 : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode;
2527 if (! mmix_valid_comparison (code, mode, x))
2528 return NULL_RTX;
2530 cc_reg = gen_reg_rtx (ccmode);
2532 /* FIXME: Can we avoid emitting a compare insn here? */
2533 if (! REG_P (x) && ! REG_P (y))
2534 x = force_reg (mode, x);
2536 /* If it's not quite right yet, put y in a register. */
2537 if (! REG_P (y)
2538 && (GET_CODE (y) != CONST_INT
2539 || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I')))
2540 y = force_reg (mode, y);
2542 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2543 gen_rtx_COMPARE (ccmode, x, y)));
2545 return cc_reg;
2548 /* Local (static) helper functions. */
2550 static void
2551 mmix_emit_sp_add (HOST_WIDE_INT offset)
2553 rtx insn;
2555 if (offset < 0)
2557 /* Negative stack-pointer adjustments are allocations and appear in
2558 the prologue only. We mark them as frame-related so unwind and
2559 debug info is properly emitted for them. */
2560 if (offset > -255)
2561 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2562 stack_pointer_rtx,
2563 GEN_INT (offset)));
2564 else
2566 rtx tmpr = gen_rtx_REG (DImode, 255);
2567 RTX_FRAME_RELATED_P (emit_move_insn (tmpr, GEN_INT (offset))) = 1;
2568 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2569 stack_pointer_rtx, tmpr));
2571 RTX_FRAME_RELATED_P (insn) = 1;
2573 else
2575 /* Positive adjustments are in the epilogue only. Don't mark them
2576 as "frame-related" for unwind info. */
2577 if (CONST_OK_FOR_LETTER_P (offset, 'L'))
2578 emit_insn (gen_adddi3 (stack_pointer_rtx,
2579 stack_pointer_rtx,
2580 GEN_INT (offset)));
2581 else
2583 rtx tmpr = gen_rtx_REG (DImode, 255);
2584 emit_move_insn (tmpr, GEN_INT (offset));
2585 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2586 stack_pointer_rtx, tmpr));
2591 /* Print operator suitable for doing something with a shiftable
2592 wyde. The type of operator is passed as an asm output modifier. */
2594 static void
2595 mmix_output_shiftvalue_op_from_str (FILE *stream,
2596 const char *mainop,
2597 HOST_WIDEST_INT value)
2599 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2600 int i;
2602 if (! mmix_shiftable_wyde_value (value))
2604 char s[sizeof ("0xffffffffffffffff")];
2605 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2606 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2609 for (i = 0; i < 4; i++)
2611 /* We know we're through when we find one-bits in the low
2612 16 bits. */
2613 if (value & 0xffff)
2615 fprintf (stream, "%s%s", mainop, op_part[i]);
2616 return;
2618 value >>= 16;
2621 /* No bits set? Then it must have been zero. */
2622 fprintf (stream, "%sL", mainop);
2625 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2627 static void
2628 mmix_output_octa (FILE *stream, HOST_WIDEST_INT value, int do_begin_end)
2630 /* Snipped from final.c:output_addr_const. We need to avoid the
2631 presumed universal "0x" prefix. We can do it by replacing "0x" with
2632 "#0" here; we must avoid a space in the operands and no, the zero
2633 won't cause the number to be assumed in octal format. */
2634 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2636 if (do_begin_end)
2637 fprintf (stream, "\tOCTA ");
2639 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2640 hex_format[0] = '#';
2641 hex_format[1] = '0';
2643 /* Provide a few alternative output formats depending on the number, to
2644 improve legibility of assembler output. */
2645 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2646 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2647 fprintf (stream, "%d", (int) value);
2648 else if (value > (HOST_WIDEST_INT) 0
2649 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2650 fprintf (stream, "#%x", (unsigned int) value);
2651 else
2652 fprintf (stream, hex_format, value);
2654 if (do_begin_end)
2655 fprintf (stream, "\n");
2658 /* Print the presumed shiftable wyde argument shifted into place (to
2659 be output with an operand). */
2661 static void
2662 mmix_output_shifted_value (FILE *stream, HOST_WIDEST_INT value)
2664 int i;
2666 if (! mmix_shiftable_wyde_value (value))
2668 char s[16+2+1];
2669 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2670 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2673 for (i = 0; i < 4; i++)
2675 /* We know we're through when we find one-bits in the low 16 bits. */
2676 if (value & 0xffff)
2678 fprintf (stream, "#%x", (int) (value & 0xffff));
2679 return;
2682 value >>= 16;
2685 /* No bits set? Then it must have been zero. */
2686 fprintf (stream, "0");
2689 /* Output an MMIX condition name corresponding to an operator
2690 and operands:
2691 (comparison_operator [(comparison_operator ...) (const_int 0)])
2692 which means we have to look at *two* operators.
2694 The argument "reversed" refers to reversal of the condition (not the
2695 same as swapping the arguments). */
2697 static void
2698 mmix_output_condition (FILE *stream, rtx x, int reversed)
2700 struct cc_conv
2702 RTX_CODE cc;
2704 /* The normal output cc-code. */
2705 const char *const normal;
2707 /* The reversed cc-code, or NULL if invalid. */
2708 const char *const reversed;
2711 struct cc_type_conv
2713 enum machine_mode cc_mode;
2715 /* Terminated with {UNKNOWN, NULL, NULL} */
2716 const struct cc_conv *const convs;
2719 #undef CCEND
2720 #define CCEND {UNKNOWN, NULL, NULL}
2722 static const struct cc_conv cc_fun_convs[]
2723 = {{ORDERED, "Z", "P"},
2724 {UNORDERED, "P", "Z"},
2725 CCEND};
2726 static const struct cc_conv cc_fp_convs[]
2727 = {{GT, "P", NULL},
2728 {LT, "N", NULL},
2729 CCEND};
2730 static const struct cc_conv cc_fpeq_convs[]
2731 = {{NE, "Z", "P"},
2732 {EQ, "P", "Z"},
2733 CCEND};
2734 static const struct cc_conv cc_uns_convs[]
2735 = {{GEU, "NN", "N"},
2736 {GTU, "P", "NP"},
2737 {LEU, "NP", "P"},
2738 {LTU, "N", "NN"},
2739 CCEND};
2740 static const struct cc_conv cc_signed_convs[]
2741 = {{NE, "NZ", "Z"},
2742 {EQ, "Z", "NZ"},
2743 {GE, "NN", "N"},
2744 {GT, "P", "NP"},
2745 {LE, "NP", "P"},
2746 {LT, "N", "NN"},
2747 CCEND};
2748 static const struct cc_conv cc_di_convs[]
2749 = {{NE, "NZ", "Z"},
2750 {EQ, "Z", "NZ"},
2751 {GE, "NN", "N"},
2752 {GT, "P", "NP"},
2753 {LE, "NP", "P"},
2754 {LT, "N", "NN"},
2755 {GTU, "NZ", "Z"},
2756 {LEU, "Z", "NZ"},
2757 CCEND};
2758 #undef CCEND
2760 static const struct cc_type_conv cc_convs[]
2761 = {{CC_FUNmode, cc_fun_convs},
2762 {CC_FPmode, cc_fp_convs},
2763 {CC_FPEQmode, cc_fpeq_convs},
2764 {CC_UNSmode, cc_uns_convs},
2765 {CCmode, cc_signed_convs},
2766 {DImode, cc_di_convs}};
2768 size_t i;
2769 int j;
2771 enum machine_mode mode = GET_MODE (XEXP (x, 0));
2772 RTX_CODE cc = GET_CODE (x);
2774 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
2776 if (mode == cc_convs[i].cc_mode)
2778 for (j = 0; cc_convs[i].convs[j].cc != UNKNOWN; j++)
2779 if (cc == cc_convs[i].convs[j].cc)
2781 const char *mmix_cc
2782 = (reversed ? cc_convs[i].convs[j].reversed
2783 : cc_convs[i].convs[j].normal);
2785 if (mmix_cc == NULL)
2786 fatal_insn ("MMIX Internal: Trying to output invalidly\
2787 reversed condition:", x);
2789 fprintf (stream, "%s", mmix_cc);
2790 return;
2793 fatal_insn ("MMIX Internal: What's the CC of this?", x);
2797 fatal_insn ("MMIX Internal: What is the CC of this?", x);
2800 /* Return the bit-value for a const_int or const_double. */
2802 static HOST_WIDEST_INT
2803 mmix_intval (rtx x)
2805 unsigned HOST_WIDEST_INT retval;
2807 if (GET_CODE (x) == CONST_INT)
2808 return INTVAL (x);
2810 /* We make a little song and dance because converting to long long in
2811 gcc-2.7.2 is broken. I still want people to be able to use it for
2812 cross-compilation to MMIX. */
2813 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
2815 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
2817 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
2818 retval *= 2;
2819 retval |= CONST_DOUBLE_LOW (x) & 1;
2821 retval |=
2822 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
2823 << (HOST_BITS_PER_LONG);
2825 else
2826 retval = CONST_DOUBLE_HIGH (x);
2828 return retval;
2831 if (GET_CODE (x) == CONST_DOUBLE)
2833 REAL_VALUE_TYPE value;
2835 /* FIXME: This macro is not in the manual but should be. */
2836 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
2838 if (GET_MODE (x) == DFmode)
2840 long bits[2];
2842 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
2844 if (sizeof (long) < sizeof (HOST_WIDEST_INT))
2846 retval = (unsigned long) bits[1] / 2;
2847 retval *= 2;
2848 retval |= (unsigned long) bits[1] & 1;
2849 retval
2850 |= (unsigned HOST_WIDEST_INT) bits[0]
2851 << (sizeof (bits[0]) * 8);
2853 else
2854 retval = (unsigned long) bits[1];
2856 return retval;
2858 else if (GET_MODE (x) == SFmode)
2860 long bits;
2861 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
2863 return (unsigned long) bits;
2867 fatal_insn ("MMIX Internal: This is not a constant:", x);
2870 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2872 static rtx
2873 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
2874 int incoming ATTRIBUTE_UNUSED)
2876 return gen_rtx_REG (Pmode, MMIX_STRUCT_VALUE_REGNUM);
2880 * Local variables:
2881 * eval: (c-set-style "gnu")
2882 * indent-tabs-mode: t
2883 * End: