1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000, 2001, 2002 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)
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. */
26 #include "hard-reg-set.h"
28 #include "insn-config.h"
40 #include "integrate.h"
42 #include "target-def.h"
45 /* First some local helper definitions. */
46 #define MMIX_FIRST_GLOBAL_REGNUM 32
48 /* We'd need a current_function_has_landing_pad. It's marked as such when
49 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
51 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
53 /* We have no means to tell DWARF 2 about the register stack, so we need
54 to store the return address on the stack if an exception can get into
55 this function. FIXME: Narrow condition. Before any whole-function
56 analysis, regs_ever_live[] isn't initialized. We know it's up-to-date
57 after reload_completed; it may contain incorrect information some time
58 before that. Within a RTL sequence (after a call to start_sequence,
59 such as in RTL expanders), leaf_function_p doesn't see all insns
60 (perhaps any insn). But regs_ever_live is up-to-date when
61 leaf_function_p () isn't, so we "or" them together to get accurate
62 information. FIXME: Some tweak to leaf_function_p might be
64 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
66 && ((reload_completed && regs_ever_live[MMIX_rJ_REGNUM]) \
67 || !leaf_function_p ()))
69 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
70 (current_function_calls_eh_return \
71 && (EH_RETURN_DATA_REGNO (0) == REGNO \
72 || EH_RETURN_DATA_REGNO (1) == REGNO \
73 || EH_RETURN_DATA_REGNO (2) == REGNO \
74 || EH_RETURN_DATA_REGNO (3) == REGNO))
76 /* For the default ABI, we rename registers at output-time to fill the gap
77 between the (statically partitioned) saved registers and call-clobbered
78 registers. In effect this makes unused call-saved registers to be used
79 as call-clobbered registers. The benefit comes from keeping the number
80 of local registers (value of rL) low, since there's a cost of
81 increasing rL and clearing unused (unset) registers with lower numbers.
82 Don't translate while outputting the prologue. */
83 #define MMIX_OUTPUT_REGNO(N) \
85 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
86 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
88 || cfun->machine == NULL \
89 || cfun->machine->in_prologue \
90 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
91 + cfun->machine->highest_saved_stack_register + 1))
93 /* The %d in "POP %d,0". */
94 #define MMIX_POP_ARGUMENT() \
96 && current_function_return_rtx != NULL \
97 && ! current_function_returns_struct) \
98 ? (GET_CODE (current_function_return_rtx) == PARALLEL \
99 ? GET_NUM_ELEM (XVEC (current_function_return_rtx, 0)) : 1) \
102 /* The canonical saved comparison operands for non-cc0 machines, set in
103 the compare expander. */
104 rtx mmix_compare_op0;
105 rtx mmix_compare_op1;
107 /* We ignore some options with arguments. They are passed to the linker,
108 but also ends up here because they start with "-m". We tell the driver
109 to store them in a variable we don't inspect. */
110 const char *mmix_cc1_ignored_option;
112 /* Declarations of locals. */
114 /* Intermediate for insn output. */
115 static int mmix_output_destination_register;
117 static void mmix_output_shiftvalue_op_from_str
118 PARAMS ((FILE *, const char *, HOST_WIDEST_INT));
119 static void mmix_output_shifted_value PARAMS ((FILE *, HOST_WIDEST_INT));
120 static void mmix_output_condition PARAMS ((FILE *, rtx, int));
121 static HOST_WIDEST_INT mmix_intval PARAMS ((rtx));
122 static void mmix_output_octa PARAMS ((FILE *, HOST_WIDEST_INT, int));
123 static bool mmix_assemble_integer PARAMS ((rtx, unsigned int, int));
124 static struct machine_function * mmix_init_machine_status PARAMS ((void));
125 static void mmix_encode_section_info PARAMS ((tree, int));
126 static const char *mmix_strip_name_encoding PARAMS ((const char *));
127 static void mmix_emit_sp_add PARAMS ((HOST_WIDE_INT offset));
128 static void mmix_target_asm_function_prologue
129 PARAMS ((FILE *, HOST_WIDE_INT));
130 static void mmix_target_asm_function_end_prologue PARAMS ((FILE *));
131 static void mmix_target_asm_function_epilogue
132 PARAMS ((FILE *, HOST_WIDE_INT));
135 /* Target structure macros. Listed by node. See `Using and Porting GCC'
136 for a general description. */
138 /* Node: Function Entry */
140 #undef TARGET_ASM_BYTE_OP
141 #define TARGET_ASM_BYTE_OP NULL
142 #undef TARGET_ASM_ALIGNED_HI_OP
143 #define TARGET_ASM_ALIGNED_HI_OP NULL
144 #undef TARGET_ASM_ALIGNED_SI_OP
145 #define TARGET_ASM_ALIGNED_SI_OP NULL
146 #undef TARGET_ASM_ALIGNED_DI_OP
147 #define TARGET_ASM_ALIGNED_DI_OP NULL
148 #undef TARGET_ASM_INTEGER
149 #define TARGET_ASM_INTEGER mmix_assemble_integer
151 #undef TARGET_ASM_FUNCTION_PROLOGUE
152 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
154 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
155 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
157 #undef TARGET_ASM_FUNCTION_EPILOGUE
158 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
160 #undef TARGET_ENCODE_SECTION_INFO
161 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
162 #undef TARGET_STRIP_NAME_ENCODING
163 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
165 struct gcc_target targetm = TARGET_INITIALIZER;
167 /* Functions that are expansions for target macros.
168 See Target Macros in `Using and Porting GCC'. */
170 /* OVERRIDE_OPTIONS. */
173 mmix_override_options ()
175 /* Should we err or should we warn? Hmm. At least we must neutralize
176 it. For example the wrong kind of case-tables will be generated with
177 PIC; we use absolute address items for mmixal compatibility. FIXME:
178 They could be relative if we just elide them to after all pertinent
182 warning ("-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
187 /* INIT_EXPANDERS. */
190 mmix_init_expanders ()
192 init_machine_status = mmix_init_machine_status;
195 /* Set the per-function data. */
197 static struct machine_function *
198 mmix_init_machine_status ()
200 return ggc_alloc_cleared (sizeof (struct machine_function));
204 We have trouble getting the address of stuff that is located at other
205 than 32-bit alignments (GETA requirements), so try to give everything
206 at least 32-bit alignment. */
209 mmix_data_alignment (type, basic_align)
210 tree type ATTRIBUTE_UNUSED;
213 if (basic_align < 32)
219 /* CONSTANT_ALIGNMENT. */
222 mmix_constant_alignment (constant, basic_align)
223 tree constant ATTRIBUTE_UNUSED;
226 if (basic_align < 32)
232 /* LOCAL_ALIGNMENT. */
235 mmix_local_alignment (type, basic_align)
236 tree type ATTRIBUTE_UNUSED;
239 if (basic_align < 32)
245 /* CONDITIONAL_REGISTER_USAGE. */
248 mmix_conditional_register_usage ()
254 static const int gnu_abi_reg_alloc_order[]
255 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
257 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
258 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
260 /* Change the default from the mmixware ABI. For the GNU ABI,
261 $15..$30 are call-saved just as $0..$14. There must be one
262 call-clobbered local register for the "hole" that holds the
263 number of saved local registers saved by PUSHJ/PUSHGO during the
264 function call, receiving the return value at return. So best is
265 to use the highest, $31. It's already marked call-clobbered for
267 for (i = 15; i <= 30; i++)
268 call_used_regs[i] = 0;
270 /* "Unfix" the parameter registers. */
271 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
272 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
277 /* Step over the ":" in special register names. */
278 if (! TARGET_TOPLEVEL_SYMBOLS)
279 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
280 if (reg_names[i][0] == ':')
285 All registers that are part of the register stack and that will be
289 mmix_local_regno (regno)
292 return regno <= MMIX_LAST_STACK_REGISTER_REGNUM && !call_used_regs[regno];
295 /* PREFERRED_RELOAD_CLASS.
296 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
299 mmix_preferred_reload_class (x, class)
300 rtx x ATTRIBUTE_UNUSED;
301 enum reg_class class;
303 /* FIXME: Revisit. */
304 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
305 ? REMAINDER_REG : class;
308 /* PREFERRED_OUTPUT_RELOAD_CLASS.
309 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
312 mmix_preferred_output_reload_class (x, class)
313 rtx x ATTRIBUTE_UNUSED;
314 enum reg_class class;
316 /* FIXME: Revisit. */
317 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
318 ? REMAINDER_REG : class;
321 /* SECONDARY_RELOAD_CLASS.
322 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
325 mmix_secondary_reload_class (class, mode, x, in_p)
326 enum reg_class class;
327 enum machine_mode mode ATTRIBUTE_UNUSED;
328 rtx x ATTRIBUTE_UNUSED;
329 int in_p ATTRIBUTE_UNUSED;
331 if (class == REMAINDER_REG
332 || class == HIMULT_REG
333 || class == SYSTEM_REGS)
339 /* CONST_OK_FOR_LETTER_P. */
342 mmix_const_ok_for_letter_p (value, c)
347 (c == 'I' ? value >= 0 && value <= 255
348 : c == 'J' ? value >= 0 && value <= 65535
349 : c == 'K' ? value <= 0 && value >= -255
350 : c == 'L' ? mmix_shiftable_wyde_value (value)
351 : c == 'M' ? value == 0
352 : c == 'N' ? mmix_shiftable_wyde_value (~value)
353 : c == 'O' ? (value == 3 || value == 5 || value == 9
358 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
361 mmix_const_double_ok_for_letter_p (value, c)
366 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
371 We need this since our constants are not always expressible as
372 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
375 mmix_extra_constraint (x, c, strict)
380 HOST_WIDEST_INT value;
382 /* When checking for an address, we need to handle strict vs. non-strict
383 register checks. Don't use address_operand, but instead its
384 equivalent (its callee, which it is just a wrapper for),
385 memory_operand_p and the strict-equivalent strict_memory_address_p. */
389 ? strict_memory_address_p (Pmode, x)
390 : memory_address_p (Pmode, x);
392 /* R asks whether x is to be loaded with GETA or something else. Right
393 now, only a SYMBOL_REF and LABEL_REF can fit for
394 TARGET_BASE_ADDRESSES.
396 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
397 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
398 set right now; only function addresses and code labels. If we change
399 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
400 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
401 effect, a "raw" constant check together with mmix_constant_address_p
402 is all that's needed; we want all constant addresses to be loaded
406 GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE
407 && mmix_constant_address_p (x)
408 && (! TARGET_BASE_ADDRESSES
409 || (GET_CODE (x) == LABEL_REF
410 || (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))));
412 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
415 value = mmix_intval (x);
417 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
418 more ('U' taken for address_operand, 'R' similarly). Some letters map
419 outside of CONST_INT, though; we still use 'S' and 'T'. */
421 return mmix_shiftable_wyde_value (value);
423 return mmix_shiftable_wyde_value (~value);
427 /* DYNAMIC_CHAIN_ADDRESS. */
430 mmix_dynamic_chain_address (frame)
433 /* FIXME: the frame-pointer is stored at offset -8 from the current
434 frame-pointer. Unfortunately, the caller assumes that a
435 frame-pointer is present for *all* previous frames. There should be
436 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
437 return plus_constant (frame, -8);
440 /* STARTING_FRAME_OFFSET. */
443 mmix_starting_frame_offset ()
445 /* The old frame pointer is in the slot below the new one, so
446 FIRST_PARM_OFFSET does not need to depend on whether the
447 frame-pointer is needed or not. We have to adjust for the register
448 stack pointer being located below the saved frame pointer.
449 Similarly, we store the return address on the stack too, for
450 exception handling, and always if we save the register stack pointer. */
453 + (MMIX_CFUN_HAS_LANDING_PAD
454 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
457 /* RETURN_ADDR_RTX. */
460 mmix_return_addr_rtx (count, frame)
462 rtx frame ATTRIBUTE_UNUSED;
465 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
466 /* FIXME: Set frame_alias_set on the following. (Why?)
467 See mmix_initial_elimination_offset for the reason we can't use
468 get_hard_reg_initial_val for both. Always using a stack slot
469 and not a register would be suboptimal. */
470 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
471 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
475 /* SETUP_FRAME_ADDRESSES. */
478 mmix_setup_frame_addresses ()
480 /* Nothing needed at the moment. */
483 /* The difference between the (imaginary) frame pointer and the stack
484 pointer. Used to eliminate the frame pointer. */
487 mmix_initial_elimination_offset (fromreg, toreg)
493 = (get_frame_size () + current_function_outgoing_args_size + 7) & ~7;
495 /* There is no actual offset between these two virtual values, but for
496 the frame-pointer, we have the old one in the stack position below
497 it, so the offset for the frame-pointer to the stack-pointer is one
499 if (fromreg == MMIX_ARG_POINTER_REGNUM
500 && toreg == MMIX_FRAME_POINTER_REGNUM)
503 /* The difference is the size of local variables plus the size of
504 outgoing function arguments that would normally be passed as
505 registers but must be passed on stack because we're out of
506 function-argument registers. Only global saved registers are
507 counted; the others go on the register stack.
509 The frame-pointer is counted too if it is what is eliminated, as we
510 need to balance the offset for it from STARTING_FRAME_OFFSET.
512 Also add in the slot for the register stack pointer we save if we
515 Unfortunately, we can't access $0..$14, from unwinder code easily, so
516 store the return address in a frame slot too. FIXME: Only for
517 non-leaf functions. FIXME: Always with a landing pad, because it's
518 hard to know whether we need the other at the time we know we need
519 the offset for one (and have to state it). It's a kludge until we
520 can express the register stack in the EH frame info.
522 We have to do alignment here; get_frame_size will not return a
523 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
525 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
528 if ((regs_ever_live[regno] && ! call_used_regs[regno])
529 || IS_MMIX_EH_RETURN_DATA_REG (regno))
533 + (MMIX_CFUN_HAS_LANDING_PAD
534 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
535 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
538 /* Return an rtx for a function argument to go in a register, and 0 for
539 one that must go on stack. */
542 mmix_function_arg (argsp, mode, type, named, incoming)
543 const CUMULATIVE_ARGS * argsp;
544 enum machine_mode mode;
546 int named ATTRIBUTE_UNUSED;
549 /* Last-argument marker. */
550 if (type == void_type_node)
551 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
554 ? MMIX_FIRST_INCOMING_ARG_REGNUM
555 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
558 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
559 && !MUST_PASS_IN_STACK (mode, type)
560 && (GET_MODE_BITSIZE (mode) <= 64
565 ? MMIX_FIRST_INCOMING_ARG_REGNUM
566 : MMIX_FIRST_ARG_REGNUM)
571 /* Returns nonzero for everything that goes by reference, 0 for
572 everything that goes by value. */
575 mmix_function_arg_pass_by_reference (argsp, mode, type, named)
576 const CUMULATIVE_ARGS * argsp;
577 enum machine_mode mode;
579 int named ATTRIBUTE_UNUSED;
581 /* FIXME: Check: I'm not sure the MUST_PASS_IN_STACK check is
584 MUST_PASS_IN_STACK (mode, type)
585 || (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
590 /* Return nonzero if regno is a register number where a parameter is
591 passed, and 0 otherwise. */
594 mmix_function_arg_regno_p (regno, incoming)
599 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
601 return regno >= first_arg_regnum
602 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
605 /* FUNCTION_OUTGOING_VALUE. */
608 mmix_function_outgoing_value (valtype, func)
610 tree func ATTRIBUTE_UNUSED;
612 enum machine_mode mode = TYPE_MODE (valtype);
613 enum machine_mode cmode;
614 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
615 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
619 /* Return values that fit in a register need no special handling.
620 There's no register hole when parameters are passed in global
623 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
625 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
627 /* A complex type, made up of components. */
628 cmode = TYPE_MODE (TREE_TYPE (valtype));
629 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
631 /* We need to take care of the effect of the register hole on return
632 values of large sizes; the last register will appear as the first
633 register, with the rest shifted. (For complex modes, this is just
634 swapped registers.) */
636 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
637 internal_error ("too large function value type, needs %d registers,\
638 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
640 /* FIXME: Maybe we should handle structure values like this too
641 (adjusted for BLKmode), perhaps for both ABI:s. */
642 for (i = 0; i < nregs - 1; i++)
644 = gen_rtx_EXPR_LIST (VOIDmode,
645 gen_rtx_REG (cmode, first_val_regnum + i),
646 GEN_INT ((i + 1) * BITS_PER_UNIT));
649 = gen_rtx_EXPR_LIST (VOIDmode,
650 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
653 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
656 /* EH_RETURN_DATA_REGNO. */
659 mmix_eh_return_data_regno (n)
660 int n ATTRIBUTE_UNUSED;
663 return MMIX_EH_RETURN_DATA_REGNO_START + n;
665 return INVALID_REGNUM;
668 /* EH_RETURN_STACKADJ_RTX. */
671 mmix_eh_return_stackadj_rtx ()
673 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
676 /* EH_RETURN_HANDLER_RTX. */
679 mmix_eh_return_handler_rtx ()
682 gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
685 /* ASM_PREFERRED_EH_DATA_FORMAT. */
688 mmix_asm_preferred_eh_data_format (code, global)
689 int code ATTRIBUTE_UNUSED;
690 int global ATTRIBUTE_UNUSED;
692 /* This is the default (was at 2001-07-20). Revisit when needed. */
693 return DW_EH_PE_absptr;
696 /* Make a note that we've seen the beginning of of the prologue. This
697 matters to whether we'll translate register numbers as calculated by
698 mmix_machine_dependent_reorg. */
701 mmix_target_asm_function_prologue (stream, framesize)
702 FILE *stream ATTRIBUTE_UNUSED;
703 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED;
705 cfun->machine->in_prologue = 1;
708 /* Make a note that we've seen the end of the prologue. */
711 mmix_target_asm_function_end_prologue (stream)
712 FILE *stream ATTRIBUTE_UNUSED;
714 cfun->machine->in_prologue = 0;
717 /* MACHINE_DEPENDENT_REORG.
718 No actual rearrangements done here; just virtually by calculating the
719 highest saved stack register number used to modify the register numbers
723 mmix_machine_dependent_reorg (first)
724 rtx first ATTRIBUTE_UNUSED;
728 /* We put the number of the highest saved register-file register in a
729 location convenient for the call-patterns to output. Note that we
730 don't tell dwarf2 about these registers, since it can't restore them
732 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
735 if ((regs_ever_live[regno] && !call_used_regs[regno])
736 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
739 /* Regardless of whether they're saved (they might be just read), we
740 mustn't include registers that carry parameters. We could scan the
741 insns to see whether they're actually used (and indeed do other less
742 trivial register usage analysis and transformations), but it seems
743 wasteful to optimize for unused parameter registers. As of
744 2002-04-30, regs_ever_live[n] seems to be set for only-reads too, but
745 that might change. */
746 if (!TARGET_ABI_GNU && regno < current_function_args_info.regs - 1)
748 regno = current_function_args_info.regs - 1;
750 /* We don't want to let this cause us to go over the limit and make
751 incoming parameter registers be misnumbered and treating the last
752 parameter register and incoming return value register call-saved.
753 Stop things at the unmodified scheme. */
754 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
755 regno = MMIX_RETURN_VALUE_REGNUM - 1;
758 cfun->machine->highest_saved_stack_register = regno;
761 /* TARGET_ASM_FUNCTION_EPILOGUE. */
764 mmix_target_asm_function_epilogue (stream, locals_size)
766 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED;
769 /* Emit an \n for readability of the generated assembly. */
770 fputc ('\n', stream);
773 /* ASM_OUTPUT_MI_THUNK. */
776 mmix_asm_output_mi_thunk (stream, fndecl, delta, func)
778 tree fndecl ATTRIBUTE_UNUSED;
782 /* If you define STRUCT_VALUE to 0, rather than use STRUCT_VALUE_REGNUM,
783 (i.e. pass location of structure to return as invisible first
784 argument) you need to tweak this code too. */
785 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
787 if (delta >= 0 && delta < 65536)
788 fprintf (stream, "\tINCL %s,%d\n", regname, delta);
789 else if (delta < 0 && delta >= -255)
790 fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, -delta);
793 mmix_output_register_setting (stream, 255, delta, 1);
794 fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
797 fprintf (stream, "\tJMP ");
798 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
799 fprintf (stream, "\n");
802 /* FUNCTION_PROFILER. */
805 mmix_function_profiler (stream, labelno)
806 FILE *stream ATTRIBUTE_UNUSED;
807 int labelno ATTRIBUTE_UNUSED;
809 sorry ("function_profiler support for MMIX");
812 /* SETUP_INCOMING_VARARGS. */
815 mmix_setup_incoming_varargs (args_so_farp, mode, vartype, pretend_sizep,
817 CUMULATIVE_ARGS * args_so_farp;
818 enum machine_mode mode;
821 int second_time ATTRIBUTE_UNUSED;
823 /* The last named variable has been handled, but
824 args_so_farp has not been advanced for it. */
825 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
826 *pretend_sizep = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
828 /* We assume that one argument takes up one register here. That should
829 be true until we start messing with multi-reg parameters. */
830 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
831 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
834 /* EXPAND_BUILTIN_VA_ARG. */
836 /* This is modified from the "standard" implementation of va_arg: read the
837 value from the current (padded) address and increment by the (padded)
838 size. The difference for MMIX is that if the type is
839 pass-by-reference, then perform an indirection. */
842 mmix_expand_builtin_va_arg (valist, type)
846 tree ptr_size = size_int (BITS_PER_WORD / BITS_PER_UNIT);
847 tree addr_tree, type_size = NULL;
852 /* Compute the rounded size of the type. */
856 align = size_int (PARM_BOUNDARY / BITS_PER_UNIT);
857 alignm1 = size_int (PARM_BOUNDARY / BITS_PER_UNIT - 1);
858 if (type == error_mark_node
859 || (type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type))) == NULL
860 || TREE_OVERFLOW (type_size))
861 /* Presumably an error; the size isn't computable. A message has
862 supposedly been emitted elsewhere. */
863 rounded_size = size_zero_node;
865 rounded_size = fold (build (MULT_EXPR, sizetype,
866 fold (build (TRUNC_DIV_EXPR, sizetype,
867 fold (build (PLUS_EXPR, sizetype,
868 type_size, alignm1)),
872 if (AGGREGATE_TYPE_P (type)
873 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) < 8
874 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) != 0)
876 /* Adjust for big-endian the location of aggregates passed in a
877 register, but where the aggregate is accessed in a shorter mode
878 than the natural register mode (i.e. it is accessed as SFmode(?),
879 SImode, HImode or QImode rather than DImode or DFmode(?)). FIXME:
880 Or should we adjust the mode in which the aggregate is read, to be
881 a register size mode? (Hum, nah, a small offset is generally
882 cheaper than a wider memory access on MMIX.) */
884 = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
885 size_int ((BITS_PER_WORD / BITS_PER_UNIT)
886 - GET_MODE_UNIT_SIZE (TYPE_MODE (type))));
888 else if (!integer_zerop (rounded_size))
890 if (!really_constant_p (type_size))
891 /* Varying-size types come in by reference. */
893 = build1 (INDIRECT_REF, build_pointer_type (type), addr_tree);
896 /* If the size is less than a register, then we need to pad the
897 address by adding the difference. */
899 = fold (build (COND_EXPR, sizetype,
900 fold (build (GT_EXPR, sizetype,
904 fold (build (MINUS_EXPR, sizetype,
908 = fold (build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
911 /* If this type is larger than what fits in a register, then it
912 is passed by reference. */
914 = fold (build (COND_EXPR, TREE_TYPE (addr_tree1),
915 fold (build (GT_EXPR, sizetype,
918 build1 (INDIRECT_REF, build_pointer_type (type),
924 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
925 addr = copy_to_reg (addr);
927 if (!integer_zerop (rounded_size))
929 /* Compute new value for AP. For MMIX, it is always advanced by the
930 size of a register. */
931 tree t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
932 build (PLUS_EXPR, TREE_TYPE (valist), valist,
934 TREE_SIDE_EFFECTS (t) = 1;
935 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
941 /* TRAMPOLINE_SIZE. */
942 /* Four 4-byte insns plus two 8-byte values. */
943 int mmix_trampoline_size = 32;
946 /* TRAMPOLINE_TEMPLATE. */
949 mmix_trampoline_template (stream)
952 /* Read a value into the static-chain register and jump somewhere. The
953 static chain is stored at offset 16, and the function address is
954 stored at offset 24. */
955 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
956 register size (octa). */
957 fprintf (stream, "\tGETA $255,1F\n\t");
958 fprintf (stream, "LDOU %s,$255,0\n\t",
959 reg_names[MMIX_STATIC_CHAIN_REGNUM]);
960 fprintf (stream, "LDOU $255,$255,8\n\t");
961 fprintf (stream, "GO $255,$255,0\n");
962 fprintf (stream, "1H\tOCTA 0\n\t");
963 fprintf (stream, "OCTA 0\n");
966 /* INITIALIZE_TRAMPOLINE. */
967 /* Set the static chain and function pointer field in the trampoline.
968 We also SYNCID here to be sure (doesn't matter in the simulator, but
969 some day it will). */
972 mmix_initialize_trampoline (trampaddr, fnaddr, static_chain)
977 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)),
979 emit_move_insn (gen_rtx_MEM (DImode,
980 plus_constant (trampaddr, 24)),
982 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode,
984 GEN_INT (mmix_trampoline_size - 1)));
987 /* We must exclude constant addresses that have an increment that is not a
988 multiple of four bytes because of restrictions of the GETA
989 instruction, unless TARGET_BASE_ADDRESSES. */
992 mmix_constant_address_p (x)
995 RTX_CODE code = GET_CODE (x);
997 /* When using "base addresses", anything constant goes. */
998 int constant_ok = TARGET_BASE_ADDRESSES != 0;
1006 case CONSTANT_P_RTX:
1008 /* FIXME: Don't know how to dissect these. Avoid them for now,
1009 except we know they're constants. */
1013 addend = INTVAL (x);
1017 if (GET_MODE (x) != VOIDmode)
1018 /* Strange that we got here. FIXME: Check if we do. */
1020 addend = CONST_DOUBLE_LOW (x);
1024 /* Note that expressions with arithmetic on forward references don't
1025 work in mmixal. People using gcc assembly code with mmixal might
1026 need to move arrays and such to before the point of use. */
1027 if (GET_CODE (XEXP (x, 0)) == PLUS)
1029 rtx x0 = XEXP (XEXP (x, 0), 0);
1030 rtx x1 = XEXP (XEXP (x, 0), 1);
1032 if ((GET_CODE (x0) == SYMBOL_REF
1033 || GET_CODE (x0) == LABEL_REF)
1034 && (GET_CODE (x1) == CONST_INT
1035 || (GET_CODE (x1) == CONST_DOUBLE
1036 && GET_MODE (x1) == VOIDmode)))
1037 addend = mmix_intval (x1);
1049 return constant_ok || (addend & 3) == 0;
1052 /* Return 1 if the address is OK, otherwise 0.
1053 Used by GO_IF_LEGITIMATE_ADDRESS. */
1056 mmix_legitimate_address (mode, x, strict_checking)
1057 enum machine_mode mode ATTRIBUTE_UNUSED;
1059 int strict_checking;
1061 #define MMIX_REG_OK(X) \
1063 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1064 || (reg_renumber[REGNO (X)] > 0 \
1065 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1066 || (!strict_checking \
1067 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1068 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1069 || REGNO (X) == ARG_POINTER_REGNUM)))
1073 (mem (plus reg reg))
1074 (mem (plus reg 0..255)).
1075 unless TARGET_BASE_ADDRESSES, in which case we accept all
1076 (mem constant_address) too. */
1080 if (REG_P (x) && MMIX_REG_OK (x))
1083 if (GET_CODE(x) == PLUS)
1085 rtx x1 = XEXP (x, 0);
1086 rtx x2 = XEXP (x, 1);
1088 /* Try swapping the order. FIXME: Do we need this? */
1096 /* (mem (plus (reg?) (?))) */
1097 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1098 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1100 /* (mem (plus (reg) (reg?))) */
1101 if (REG_P (x2) && MMIX_REG_OK (x2))
1104 /* (mem (plus (reg) (0..255?))) */
1105 if (GET_CODE (x2) == CONST_INT
1106 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1112 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1115 /* LEGITIMATE_CONSTANT_P. */
1118 mmix_legitimate_constant_p (x)
1121 RTX_CODE code = GET_CODE (x);
1123 /* We must allow any number due to the way the cse passes works; if we
1124 do not allow any number here, general_operand will fail, and insns
1125 will fatally fail recognition instead of "softly". */
1126 if (code == CONST_INT || code == CONST_DOUBLE)
1129 return CONSTANT_ADDRESS_P (x);
1132 /* SELECT_CC_MODE. */
1135 mmix_select_cc_mode (op, x, y)
1138 rtx y ATTRIBUTE_UNUSED;
1140 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1141 output different compare insns. Note that we do not check the
1142 validity of the comparison here. */
1144 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1146 if (op == ORDERED || op == UNORDERED || op == UNGE
1147 || op == UNGT || op == UNLE || op == UNLT)
1150 if (op == EQ || op == NE)
1156 if (op == GTU || op == LTU || op == GEU || op == LEU)
1162 /* REVERSIBLE_CC_MODE. */
1165 mmix_reversible_cc_mode (mode)
1166 enum machine_mode mode;
1168 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1170 return mode != CC_FPmode;
1173 /* DEFAULT_RTX_COSTS. */
1176 mmix_rtx_cost_recalculated (x, code, outer_code, costp)
1177 rtx x ATTRIBUTE_UNUSED;
1178 RTX_CODE code ATTRIBUTE_UNUSED;
1179 RTX_CODE outer_code ATTRIBUTE_UNUSED;
1180 int *costp ATTRIBUTE_UNUSED;
1182 /* For the time being, this is just a stub and we'll accept the
1183 generic calculations, until we can do measurements, at least.
1184 Say we did not modify any calculated costs. */
1191 mmix_address_cost (addr)
1192 rtx addr ATTRIBUTE_UNUSED;
1194 /* There's no difference in the address costs and we have lots of
1195 registers. Some targets use constant 0, many others use 1 to say
1196 this. Let's start with 1. */
1200 /* REGISTER_MOVE_COST. */
1203 mmix_register_move_cost (mode, from, to)
1204 enum machine_mode mode ATTRIBUTE_UNUSED;
1205 enum reg_class from;
1208 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1211 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1212 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1215 /* DATA_SECTION_ASM_OP. */
1218 mmix_data_section_asm_op ()
1220 return "\t.data ! mmixal:= 8H LOC 9B";
1224 mmix_encode_section_info (decl, first)
1228 /* Test for an external declaration, and do nothing if it is one. */
1229 if ((TREE_CODE (decl) == VAR_DECL
1230 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1231 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1233 else if (first && DECL_P (decl))
1235 /* For non-visible declarations, add a "@" prefix, which we skip
1236 when the label is output. If the label does not have this
1237 prefix, a ":" is output if -mtoplevel-symbols.
1239 Note that this does not work for data that is declared extern and
1240 later defined as static. If there's code in between, that code
1241 will refer to the extern declaration, and vice versa. This just
1242 means that when -mtoplevel-symbols is in use, we can just handle
1243 well-behaved ISO-compliant code. */
1245 const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1246 int len = strlen (str);
1249 /* Why is the return type of ggc_alloc_string const? */
1250 newstr = (char *) ggc_alloc_string ("", len + 1);
1252 strcpy (newstr + 1, str);
1254 XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
1257 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1258 may need different options to reach for different things with GETA.
1259 For now, functions and things we know or have been told are constant. */
1260 if (TREE_CODE (decl) == FUNCTION_DECL
1261 || TREE_CONSTANT (decl)
1262 || (TREE_CODE (decl) == VAR_DECL
1263 && TREE_READONLY (decl)
1264 && !TREE_SIDE_EFFECTS (decl)
1265 && (!DECL_INITIAL (decl)
1266 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1268 rtx rtl = (TREE_CODE_CLASS (TREE_CODE (decl)) != 'd'
1269 ? TREE_CST_RTL (decl) : DECL_RTL (decl));
1270 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1275 mmix_strip_name_encoding (name)
1278 for (; (*name == '@' || *name == '*'); name++)
1284 /* ASM_FILE_START. */
1287 mmix_asm_file_start (stream)
1290 /* We just emit a little comment for the time being. FIXME: Perhaps add
1291 -mstandalone and some segment and prefix setup here. */
1292 ASM_OUTPUT_SOURCE_FILENAME (stream, main_input_filename);
1294 fprintf (stream, "! mmixal:= 8H LOC Data_Section\n");
1296 /* Make sure each file starts with the text section. */
1303 mmix_asm_file_end (stream)
1304 FILE * stream ATTRIBUTE_UNUSED;
1306 /* Make sure each file ends with the data section. */
1310 /* ASM_OUTPUT_SOURCE_FILENAME. */
1313 mmix_asm_output_source_filename (stream, name)
1317 fprintf (stream, "# 1 ");
1318 OUTPUT_QUOTED_STRING (stream, name);
1319 fprintf (stream, "\n");
1322 /* OUTPUT_QUOTED_STRING. */
1325 mmix_output_quoted_string (stream, string, length)
1327 const char * string;
1330 const char * string_end = string + length;
1331 static const char *const unwanted_chars = "\"[]\\";
1333 /* Output "any character except newline and double quote character". We
1334 play it safe and avoid all control characters too. We also do not
1335 want [] as characters, should input be passed through m4 with [] as
1336 quotes. Further, we avoid "\", because the GAS port handles it as a
1337 quoting character. */
1338 while (string < string_end)
1341 && (unsigned char) *string < 128
1342 && !ISCNTRL (*string)
1343 && strchr (unwanted_chars, *string) == NULL)
1345 fputc ('"', stream);
1347 && (unsigned char) *string < 128
1348 && !ISCNTRL (*string)
1349 && strchr (unwanted_chars, *string) == NULL
1350 && string < string_end)
1352 fputc (*string, stream);
1355 fputc ('"', stream);
1356 if (string < string_end)
1357 fprintf (stream, ",");
1359 if (string < string_end)
1361 fprintf (stream, "#%x", *string & 255);
1363 if (string < string_end)
1364 fprintf (stream, ",");
1369 /* ASM_OUTPUT_SOURCE_LINE. */
1372 mmix_asm_output_source_line (stream, lineno)
1376 fprintf (stream, "# %d ", lineno);
1377 OUTPUT_QUOTED_STRING (stream, main_input_filename);
1378 fprintf (stream, "\n");
1381 /* Target hook for assembling integer objects. Use mmix_print_operand
1382 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1386 mmix_assemble_integer (x, size, aligned_p)
1394 /* We handle a limited number of types of operands in here. But
1395 that's ok, because we can punt to generic functions. We then
1396 pretend that aligned data isn't needed, so the usual .<pseudo>
1397 syntax is used (which works for aligned data too). We actually
1398 *must* do that, since we say we don't have simple aligned
1399 pseudos, causing this function to be called. We just try and
1400 keep as much compatibility as possible with mmixal syntax for
1401 normal cases (i.e. without GNU extensions and C only). */
1403 if (GET_CODE (x) != CONST_INT)
1408 fputs ("\tBYTE\t", asm_out_file);
1409 mmix_print_operand (asm_out_file, x, 'B');
1410 fputc ('\n', asm_out_file);
1414 if (GET_CODE (x) != CONST_INT)
1419 fputs ("\tWYDE\t", asm_out_file);
1420 mmix_print_operand (asm_out_file, x, 'W');
1421 fputc ('\n', asm_out_file);
1425 if (GET_CODE (x) != CONST_INT)
1430 fputs ("\tTETRA\t", asm_out_file);
1431 mmix_print_operand (asm_out_file, x, 'L');
1432 fputc ('\n', asm_out_file);
1436 if (GET_CODE (x) == CONST_DOUBLE)
1437 /* We don't get here anymore for CONST_DOUBLE, because DImode
1438 isn't expressed as CONST_DOUBLE, and DFmode is handled
1441 assemble_integer_with_op ("\tOCTA\t", x);
1444 return default_assemble_integer (x, size, aligned_p);
1447 /* ASM_OUTPUT_ASCII. */
1450 mmix_asm_output_ascii (stream, string, length)
1457 int chunk_size = length > 60 ? 60 : length;
1458 fprintf (stream, "\tBYTE ");
1459 mmix_output_quoted_string (stream, string, chunk_size);
1460 string += chunk_size;
1461 length -= chunk_size;
1462 fprintf (stream, "\n");
1466 /* ASM_OUTPUT_ALIGNED_COMMON. */
1469 mmix_asm_output_aligned_common (stream, name, size, align)
1475 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1476 express this in a mmixal-compatible way. */
1477 fprintf (stream, "\t.comm\t");
1478 assemble_name (stream, name);
1479 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1480 size, align / BITS_PER_UNIT);
1483 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1486 mmix_asm_output_aligned_local (stream, name, size, align)
1494 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1495 assemble_name (stream, name);
1496 fprintf (stream, "\tLOC @+%d\n", size);
1499 /* ASM_OUTPUT_LABEL. */
1502 mmix_asm_output_label (stream, name)
1506 assemble_name (stream, name);
1507 fprintf (stream, "\tIS @\n");
1510 /* ASM_DECLARE_REGISTER_GLOBAL. */
1513 mmix_asm_declare_register_global (stream, decl, regno, name)
1514 FILE *stream ATTRIBUTE_UNUSED;
1515 tree decl ATTRIBUTE_UNUSED;
1516 int regno ATTRIBUTE_UNUSED;
1517 const char *name ATTRIBUTE_UNUSED;
1519 /* Nothing to do here, but there *will* be, therefore the framework is
1523 /* ASM_WEAKEN_LABEL. */
1526 mmix_asm_weaken_label (stream, name)
1527 FILE * stream ATTRIBUTE_UNUSED;
1528 const char * name ATTRIBUTE_UNUSED;
1530 fprintf (stream, "\t.weak ");
1531 assemble_name (stream, name);
1532 fprintf (stream, " ! mmixal-incompatible\n");
1535 /* MAKE_DECL_ONE_ONLY. */
1538 mmix_make_decl_one_only (decl)
1541 DECL_WEAK (decl) = 1;
1544 /* ASM_OUTPUT_LABELREF.
1545 Strip GCC's '*' and our own '@'. No order is assumed. */
1548 mmix_asm_output_labelref (stream, name)
1554 for (; (*name == '@' || *name == '*'); name++)
1558 asm_fprintf (stream, "%s%U%s",
1559 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
1563 /* ASM_OUTPUT_INTERNAL_LABEL. */
1566 mmix_asm_output_internal_label (stream, name, num)
1571 fprintf (stream, "%s:%d\tIS @\n", name, num);
1574 /* ASM_OUTPUT_DEF. */
1577 mmix_asm_output_def (stream, name, value)
1582 assemble_name (stream, name);
1583 fprintf (stream, "\tIS ");
1584 assemble_name (stream, value);
1585 fputc ('\n', stream);
1588 /* PRINT_OPERAND. */
1591 mmix_print_operand (stream, x, code)
1596 /* When we add support for different codes later, we can, when needed,
1597 drop through to the main handler with a modified operand. */
1599 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
1603 /* Unrelated codes are in alphabetic order. */
1606 /* For conditional branches, output "P" for a probable branch. */
1607 if (TARGET_BRANCH_PREDICT)
1609 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
1610 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
1616 /* For the %d in POP %d,0. */
1617 fprintf (stream, "%d", MMIX_POP_ARGUMENT ());
1621 if (GET_CODE (x) != CONST_INT)
1622 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1623 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
1627 /* Highpart. Must be general register, and not the last one, as
1628 that one cannot be part of a consecutive register pair. */
1629 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1630 internal_error ("MMIX Internal: Bad register: %d", regno);
1632 /* This is big-endian, so the high-part is the first one. */
1633 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1637 /* Lowpart. Must be CONST_INT or general register, and not the last
1638 one, as that one cannot be part of a consecutive register pair. */
1639 if (GET_CODE (x) == CONST_INT)
1641 fprintf (stream, "#%lx",
1642 (unsigned long) (INTVAL (x)
1643 & ((unsigned int) 0x7fffffff * 2 + 1)));
1647 if (GET_CODE (x) == SYMBOL_REF)
1649 output_addr_const (stream, x);
1653 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1654 internal_error ("MMIX Internal: Bad register: %d", regno);
1656 /* This is big-endian, so the low-part is + 1. */
1657 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
1660 /* Can't use 'a' because that's a generic modifier for address
1663 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
1664 ~(unsigned HOST_WIDEST_INT)
1669 mmix_output_shiftvalue_op_from_str (stream, "INC",
1670 (unsigned HOST_WIDEST_INT)
1675 mmix_output_shiftvalue_op_from_str (stream, "OR",
1676 (unsigned HOST_WIDEST_INT)
1681 mmix_output_shiftvalue_op_from_str (stream, "SET",
1682 (unsigned HOST_WIDEST_INT)
1688 mmix_output_condition (stream, x, (code == 'D'));
1692 /* Output an extra "e" to make fcmpe, fune. */
1693 if (TARGET_FCMP_EPSILON)
1694 fprintf (stream, "e");
1698 /* Output the number minus 1. */
1699 if (GET_CODE (x) != CONST_INT)
1701 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1704 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
1705 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
1709 /* Store the number of registers we want to save. This was setup
1710 by the prologue. The actual operand contains the number of
1711 registers to pass, but we don't use it currently. Anyway, we
1712 need to output the number of saved registers here. */
1713 fprintf (stream, "%d",
1714 cfun->machine->highest_saved_stack_register + 1);
1718 /* Store the register to output a constant to. */
1720 fatal_insn ("MMIX Internal: Expected a register, not this", x);
1721 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
1725 /* Output the constant. Note that we use this for floats as well. */
1726 if (GET_CODE (x) != CONST_INT
1727 && (GET_CODE (x) != CONST_DOUBLE
1728 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
1729 && GET_MODE (x) != SFmode)))
1730 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
1731 mmix_output_register_setting (stream,
1732 mmix_output_destination_register,
1733 mmix_intval (x), 0);
1737 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1738 if (TARGET_ZERO_EXTEND)
1743 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
1747 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
1751 if (GET_CODE (x) != CONST_INT)
1752 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1753 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
1757 /* Nothing to do. */
1761 /* Presumably there's a missing case above if we get here. */
1762 internal_error ("MMIX Internal: Missing `%c' case in mmix_print_operand", code);
1765 switch (GET_CODE (modified_x))
1768 regno = REGNO (modified_x);
1769 if (regno >= FIRST_PSEUDO_REGISTER)
1770 internal_error ("MMIX Internal: Bad register: %d", regno);
1771 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1775 output_address (XEXP (modified_x, 0));
1779 /* For -2147483648, mmixal complains that the constant does not fit
1780 in 4 bytes, so let's output it as hex. Take care to handle hosts
1781 where HOST_WIDE_INT is longer than an int.
1783 Print small constants +-255 using decimal. */
1785 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
1786 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
1788 fprintf (stream, "#%x",
1789 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
1793 /* Do somewhat as CONST_INT. */
1794 mmix_output_octa (stream, mmix_intval (modified_x), 0);
1798 output_addr_const (stream, modified_x);
1802 /* No need to test for all strange things. Let output_addr_const do
1804 if (CONSTANT_P (modified_x)
1805 /* Strangely enough, this is not included in CONSTANT_P.
1806 FIXME: Ask/check about sanity here. */
1807 || GET_CODE (modified_x) == CODE_LABEL)
1809 output_addr_const (stream, modified_x);
1813 /* We need the original here. */
1814 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
1818 /* PRINT_OPERAND_PUNCT_VALID_P. */
1821 mmix_print_operand_punct_valid_p (code)
1822 int code ATTRIBUTE_UNUSED;
1824 /* A '+' is used for branch prediction, similar to other ports. */
1826 /* A '.' is used for the %d in the POP %d,0 return insn. */
1830 /* PRINT_OPERAND_ADDRESS. */
1833 mmix_print_operand_address (stream, x)
1839 /* I find the generated assembly code harder to read without
1841 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
1844 else if (GET_CODE (x) == PLUS)
1846 rtx x1 = XEXP (x, 0);
1847 rtx x2 = XEXP (x, 1);
1851 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
1855 fprintf (stream, "%s",
1856 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
1859 else if (GET_CODE (x2) == CONST_INT
1860 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1862 output_addr_const (stream, x2);
1868 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (x))
1870 output_addr_const (stream, x);
1874 fatal_insn ("MMIX Internal: This is not a recognized address", x);
1877 /* ASM_OUTPUT_REG_PUSH. */
1880 mmix_asm_output_reg_push (stream, regno)
1884 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1885 reg_names[MMIX_STACK_POINTER_REGNUM],
1886 reg_names[MMIX_STACK_POINTER_REGNUM],
1887 reg_names[MMIX_OUTPUT_REGNO (regno)],
1888 reg_names[MMIX_STACK_POINTER_REGNUM]);
1891 /* ASM_OUTPUT_REG_POP. */
1894 mmix_asm_output_reg_pop (stream, regno)
1898 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1899 reg_names[MMIX_OUTPUT_REGNO (regno)],
1900 reg_names[MMIX_STACK_POINTER_REGNUM],
1901 reg_names[MMIX_STACK_POINTER_REGNUM]);
1904 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1907 mmix_asm_output_addr_diff_elt (stream, body, value, rel)
1909 rtx body ATTRIBUTE_UNUSED;
1913 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
1916 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1919 mmix_asm_output_addr_vec_elt (stream, value)
1923 fprintf (stream, "\tOCTA L:%d\n", value);
1926 /* ASM_OUTPUT_SKIP. */
1929 mmix_asm_output_skip (stream, nbytes)
1933 fprintf (stream, "\tLOC @+%d\n", nbytes);
1936 /* ASM_OUTPUT_ALIGN. */
1939 mmix_asm_output_align (stream, power)
1943 /* We need to record the needed alignment of this section in the object,
1944 so we have to output an alignment directive. Use a .p2align (not
1945 .align) so people will never have to wonder about whether the
1946 argument is in number of bytes or the log2 thereof. We do it in
1947 addition to the LOC directive, so nothing needs tweaking when
1948 copy-pasting assembly into mmixal. */
1949 fprintf (stream, "\t.p2align %d\n", power);
1950 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
1953 /* DBX_REGISTER_NUMBER. */
1956 mmix_dbx_register_number (regno)
1959 /* Adjust the register number to the one it will be output as, dammit.
1960 It'd be nice if we could check the assumption that we're filling a
1961 gap, but every register between the last saved register and parameter
1962 registers might be a valid parameter register. */
1963 regno = MMIX_OUTPUT_REGNO (regno);
1965 /* We need to renumber registers to get the number of the return address
1966 register in the range 0..255. It is also space-saving if registers
1967 mentioned in the call-frame information (which uses this function by
1968 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1969 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1970 return regno >= 224 ? (regno - 224) : (regno + 48);
1973 /* End of target macro support functions.
1975 Now MMIX's own functions. First the exported ones. */
1977 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1978 from insn-emit.c. */
1981 mmix_get_hard_reg_initial_val (mode, regno)
1982 enum machine_mode mode;
1985 return get_hard_reg_initial_val (mode, regno);
1988 /* Nonzero when the function epilogue is simple enough that a single
1989 "POP %d,0" should be used even within the function. */
1992 mmix_use_simple_return ()
1996 int stack_space_to_allocate
1997 = (current_function_outgoing_args_size
1998 + current_function_pretend_args_size
1999 + get_frame_size () + 7) & ~7;
2001 if (!TARGET_USE_RETURN_INSN || !reload_completed)
2005 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2007 /* Note that we assume that the frame-pointer-register is one of these
2008 registers, in which case we don't count it here. */
2009 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2010 && regs_ever_live[regno] && !call_used_regs[regno]))
2011 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2014 if (frame_pointer_needed)
2015 stack_space_to_allocate += 8;
2017 if (MMIX_CFUN_HAS_LANDING_PAD)
2018 stack_space_to_allocate += 16;
2019 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2020 stack_space_to_allocate += 8;
2022 return stack_space_to_allocate == 0;
2026 /* Expands the function prologue into RTX. */
2029 mmix_expand_prologue ()
2031 HOST_WIDE_INT locals_size = get_frame_size ();
2033 HOST_WIDE_INT stack_space_to_allocate
2034 = (current_function_outgoing_args_size
2035 + current_function_pretend_args_size
2036 + locals_size + 7) & ~7;
2037 HOST_WIDE_INT offset = -8;
2039 /* Add room needed to save global non-register-stack registers. */
2041 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2043 /* Note that we assume that the frame-pointer-register is one of these
2044 registers, in which case we don't count it here. */
2045 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2046 && regs_ever_live[regno] && !call_used_regs[regno]))
2047 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2048 stack_space_to_allocate += 8;
2050 /* If we do have a frame-pointer, add room for it. */
2051 if (frame_pointer_needed)
2052 stack_space_to_allocate += 8;
2054 /* If we have a non-local label, we need to be able to unwind to it, so
2055 store the current register stack pointer. Also store the return
2056 address if we do that. */
2057 if (MMIX_CFUN_HAS_LANDING_PAD)
2058 stack_space_to_allocate += 16;
2059 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2060 /* If we do have a saved return-address slot, add room for it. */
2061 stack_space_to_allocate += 8;
2063 /* Make sure we don't get an unaligned stack. */
2064 if ((stack_space_to_allocate % 8) != 0)
2065 internal_error ("stack frame not a multiple of 8 bytes: %d",
2066 stack_space_to_allocate);
2068 if (current_function_pretend_args_size)
2070 int mmix_first_vararg_reg
2071 = (MMIX_FIRST_INCOMING_ARG_REGNUM
2072 + (MMIX_MAX_ARGS_IN_REGS
2073 - current_function_pretend_args_size / 8));
2076 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
2077 regno >= mmix_first_vararg_reg;
2082 HOST_WIDE_INT stack_chunk
2083 = stack_space_to_allocate > (256 - 8)
2084 ? (256 - 8) : stack_space_to_allocate;
2086 mmix_emit_sp_add (-stack_chunk);
2087 offset += stack_chunk;
2088 stack_space_to_allocate -= stack_chunk;
2091 /* These registers aren't actually saved (as in "will be
2092 restored"), so don't tell DWARF2 they're saved. */
2093 emit_move_insn (gen_rtx_MEM (DImode,
2094 plus_constant (stack_pointer_rtx,
2096 gen_rtx_REG (DImode, regno));
2101 /* Store the frame-pointer. */
2103 if (frame_pointer_needed)
2109 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2110 HOST_WIDE_INT stack_chunk
2111 = stack_space_to_allocate > (256 - 8 - 8)
2112 ? (256 - 8 - 8) : stack_space_to_allocate;
2114 mmix_emit_sp_add (-stack_chunk);
2116 offset += stack_chunk;
2117 stack_space_to_allocate -= stack_chunk;
2120 insn = emit_move_insn (gen_rtx_MEM (DImode,
2121 plus_constant (stack_pointer_rtx,
2123 hard_frame_pointer_rtx);
2124 RTX_FRAME_RELATED_P (insn) = 1;
2125 insn = emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
2127 GEN_INT (offset + 8)));
2128 RTX_FRAME_RELATED_P (insn) = 1;
2132 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2137 /* Store the return-address, if one is needed on the stack. We
2138 usually store it in a register when needed, but that doesn't work
2139 with -fexceptions. */
2143 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2144 HOST_WIDE_INT stack_chunk
2145 = stack_space_to_allocate > (256 - 8 - 8)
2146 ? (256 - 8 - 8) : stack_space_to_allocate;
2148 mmix_emit_sp_add (-stack_chunk);
2150 offset += stack_chunk;
2151 stack_space_to_allocate -= stack_chunk;
2154 tmpreg = gen_rtx_REG (DImode, 255);
2155 retreg = gen_rtx_REG (DImode, MMIX_rJ_REGNUM);
2157 /* Dwarf2 code is confused by the use of a temporary register for
2158 storing the return address, so we have to express it as a note,
2159 which we attach to the actual store insn. */
2160 emit_move_insn (tmpreg, retreg);
2162 insn = emit_move_insn (gen_rtx_MEM (DImode,
2163 plus_constant (stack_pointer_rtx,
2166 RTX_FRAME_RELATED_P (insn) = 1;
2168 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
2169 gen_rtx_SET (VOIDmode,
2170 gen_rtx_MEM (DImode,
2171 plus_constant (stack_pointer_rtx,
2178 else if (MMIX_CFUN_HAS_LANDING_PAD)
2181 if (MMIX_CFUN_HAS_LANDING_PAD)
2183 /* Store the register defining the numbering of local registers, so
2184 we know how long to unwind the register stack. */
2188 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2189 HOST_WIDE_INT stack_chunk
2190 = stack_space_to_allocate > (256 - 8 - 8)
2191 ? (256 - 8 - 8) : stack_space_to_allocate;
2193 mmix_emit_sp_add (-stack_chunk);
2195 offset += stack_chunk;
2196 stack_space_to_allocate -= stack_chunk;
2199 /* We don't tell dwarf2 about this one; we just have it to unwind
2200 the register stack at landing pads. FIXME: It's a kludge because
2201 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2202 register stack at the moment. Best thing would be to handle it
2203 like stack-pointer offsets. Better: some hook into dwarf2out.c
2204 to produce DW_CFA_expression:s that specify the increment of rO,
2205 and unwind it at eh_return (preferred) or at the landing pad.
2206 Then saves to $0..$G-1 could be specified through that register. */
2208 emit_move_insn (gen_rtx_REG (DImode, 255),
2209 gen_rtx_REG (DImode,
2211 emit_move_insn (gen_rtx_MEM (DImode,
2212 plus_constant (stack_pointer_rtx, offset)),
2213 gen_rtx_REG (DImode, 255));
2217 /* After the return-address and the frame-pointer, we have the local
2218 variables. They're the ones that may have an "unaligned" size. */
2219 offset -= (locals_size + 7) & ~7;
2221 /* Now store all registers that are global, i.e. not saved by the
2222 register file machinery.
2224 It is assumed that the frame-pointer is one of these registers, so it
2225 is explicitly excluded in the count. */
2228 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2230 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2231 && regs_ever_live[regno] && ! call_used_regs[regno])
2232 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2238 HOST_WIDE_INT stack_chunk
2239 = (stack_space_to_allocate > (256 - offset - 8)
2240 ? (256 - offset - 8) : stack_space_to_allocate);
2242 mmix_emit_sp_add (-stack_chunk);
2243 offset += stack_chunk;
2244 stack_space_to_allocate -= stack_chunk;
2247 insn = emit_move_insn (gen_rtx_MEM (DImode,
2248 plus_constant (stack_pointer_rtx,
2250 gen_rtx_REG (DImode, regno));
2251 RTX_FRAME_RELATED_P (insn) = 1;
2255 /* Finally, allocate room for outgoing args and local vars if room
2256 wasn't allocated above. */
2257 if (stack_space_to_allocate)
2258 mmix_emit_sp_add (-stack_space_to_allocate);
2261 /* Expands the function epilogue into RTX. */
2264 mmix_expand_epilogue ()
2266 HOST_WIDE_INT locals_size = get_frame_size ();
2268 HOST_WIDE_INT stack_space_to_deallocate
2269 = (current_function_outgoing_args_size
2270 + current_function_pretend_args_size
2271 + locals_size + 7) & ~7;
2273 /* The assumption that locals_size fits in an int is asserted in
2274 mmix_expand_prologue. */
2276 /* The first address to access is beyond the outgoing_args area. */
2277 int offset = current_function_outgoing_args_size;
2279 /* Add the space for global non-register-stack registers.
2280 It is assumed that the frame-pointer register can be one of these
2281 registers, in which case it is excluded from the count when needed. */
2283 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2285 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2286 && regs_ever_live[regno] && !call_used_regs[regno])
2287 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2288 stack_space_to_deallocate += 8;
2290 /* Add in the space for register stack-pointer. If so, always add room
2291 for the saved PC. */
2292 if (MMIX_CFUN_HAS_LANDING_PAD)
2293 stack_space_to_deallocate += 16;
2294 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2295 /* If we have a saved return-address slot, add it in. */
2296 stack_space_to_deallocate += 8;
2298 /* Add in the frame-pointer. */
2299 if (frame_pointer_needed)
2300 stack_space_to_deallocate += 8;
2302 /* Make sure we don't get an unaligned stack. */
2303 if ((stack_space_to_deallocate % 8) != 0)
2304 internal_error ("stack frame not a multiple of octabyte: %d",
2305 stack_space_to_deallocate);
2307 /* We will add back small offsets to the stack pointer as we go.
2308 First, we restore all registers that are global, i.e. not saved by
2309 the register file machinery. */
2311 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
2314 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2315 && regs_ever_live[regno] && !call_used_regs[regno])
2316 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2320 mmix_emit_sp_add (offset);
2321 stack_space_to_deallocate -= offset;
2325 emit_move_insn (gen_rtx_REG (DImode, regno),
2326 gen_rtx_MEM (DImode,
2327 plus_constant (stack_pointer_rtx,
2332 /* Here is where the local variables were. As in the prologue, they
2333 might be of an unaligned size. */
2334 offset += (locals_size + 7) & ~7;
2337 /* The saved register stack pointer is just below the frame-pointer
2338 register. We don't need to restore it "manually"; the POP
2339 instruction does that. */
2340 if (MMIX_CFUN_HAS_LANDING_PAD)
2342 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2343 /* The return-address slot is just below the frame-pointer register.
2344 We don't need to restore it because we don't really use it. */
2347 /* Get back the old frame-pointer-value. */
2348 if (frame_pointer_needed)
2352 mmix_emit_sp_add (offset);
2354 stack_space_to_deallocate -= offset;
2358 emit_move_insn (hard_frame_pointer_rtx,
2359 gen_rtx_MEM (DImode,
2360 plus_constant (stack_pointer_rtx,
2365 /* We do not need to restore pretended incoming args, just add back
2367 if (stack_space_to_deallocate != 0)
2368 mmix_emit_sp_add (stack_space_to_deallocate);
2370 if (current_function_calls_eh_return)
2371 /* Adjust the (normal) stack-pointer to that of the receiver.
2372 FIXME: It would be nice if we could also adjust the register stack
2373 here, but we need to express it through DWARF 2 too. */
2374 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
2375 gen_rtx_REG (DImode,
2376 MMIX_EH_RETURN_STACKADJ_REGNUM)));
2379 /* Output an optimal sequence for setting a register to a specific
2380 constant. Used in an alternative for const_ints in movdi, and when
2381 using large stack-frame offsets.
2383 Use do_begin_end to say if a line-starting TAB and newline before the
2384 first insn and after the last insn is wanted. */
2387 mmix_output_register_setting (stream, regno, value, do_begin_end)
2390 HOST_WIDEST_INT value;
2394 fprintf (stream, "\t");
2396 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2398 /* First, the one-insn cases. */
2399 mmix_output_shiftvalue_op_from_str (stream, "SET",
2400 (unsigned HOST_WIDEST_INT)
2402 fprintf (stream, " %s,", reg_names[regno]);
2403 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2405 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2407 /* We do this to get a bit more legible assembly code. The next
2408 alternative is mostly redundant with this. */
2410 mmix_output_shiftvalue_op_from_str (stream, "SET",
2411 -(unsigned HOST_WIDEST_INT)
2413 fprintf (stream, " %s,", reg_names[regno]);
2414 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2415 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2418 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2420 /* Slightly more expensive, the two-insn cases. */
2422 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2423 is shiftable, or any other one-insn transformation of the value.
2424 FIXME: Check first if the value is "shiftable" by two loading
2425 with two insns, since it makes more readable assembly code (if
2426 anyone else cares). */
2428 mmix_output_shiftvalue_op_from_str (stream, "SET",
2429 ~(unsigned HOST_WIDEST_INT)
2431 fprintf (stream, " %s,", reg_names[regno]);
2432 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2433 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2438 /* The generic case. 2..4 insns. */
2439 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2440 const char *op = "SET";
2441 const char *line_begin = "";
2444 HOST_WIDEST_INT tmpvalue = value;
2446 /* Compute the number of insns needed to output this constant. */
2447 for (i = 0; i < 4 && tmpvalue != 0; i++)
2449 if (tmpvalue & 65535)
2453 if (TARGET_BASE_ADDRESSES && insns == 3)
2455 /* The number three is based on a static observation on
2456 ghostscript-6.52. Two and four are excluded because there
2457 are too many such constants, and each unique constant (maybe
2458 offset by 1..255) were used few times compared to other uses,
2461 We use base-plus-offset addressing to force it into a global
2462 register; we just use a "LDA reg,VALUE", which will cause the
2463 assembler and linker to DTRT (for constants as well as
2465 fprintf (stream, "LDA %s,", reg_names[regno]);
2466 mmix_output_octa (stream, value, 0);
2470 /* Output pertinent parts of the 4-wyde sequence.
2471 Still more to do if we want this to be optimal, but hey...
2472 Note that the zero case has been handled above. */
2473 for (i = 0; i < 4 && value != 0; i++)
2477 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2478 higher_parts[i], reg_names[regno],
2479 (int) (value & 65535));
2480 /* The first one sets the rest of the bits to 0, the next
2481 ones add set bits. */
2483 line_begin = "\n\t";
2492 fprintf (stream, "\n");
2495 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2499 mmix_shiftable_wyde_value (value)
2500 unsigned HOST_WIDEST_INT value;
2502 /* Shift by 16 bits per group, stop when we've found two groups with
2505 int has_candidate = 0;
2507 for (i = 0; i < 4; i++)
2523 /* True if this is an address_operand or a symbolic operand. */
2526 mmix_symbolic_or_address_operand (op, mode)
2528 enum machine_mode mode;
2530 switch (GET_CODE (op))
2537 if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2538 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
2539 && (GET_CODE (XEXP (op, 1)) == CONST_INT
2540 || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE
2541 && GET_MODE (XEXP (op, 1)) == VOIDmode)))
2545 return address_operand (op, mode);
2549 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2550 We could narrow the value down with a couple of predicated, but that
2551 doesn't seem to be worth it at the moment. */
2554 mmix_reg_or_constant_operand (op, mode)
2556 enum machine_mode mode;
2558 return register_operand (op, mode)
2559 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
2560 || GET_CODE (op) == CONST_INT;
2563 /* True if this is a register with a condition-code mode. */
2566 mmix_reg_cc_operand (op, mode)
2568 enum machine_mode mode;
2570 if (mode == VOIDmode)
2571 mode = GET_MODE (op);
2573 return register_operand (op, mode)
2574 && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode
2575 || mode == CC_FPEQmode || mode == CC_FUNmode);
2578 /* True if this is a foldable comparison operator
2579 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2580 replaced by (reg). */
2583 mmix_foldable_comparison_operator (op, mode)
2585 enum machine_mode mode;
2587 RTX_CODE code = GET_CODE (op);
2589 if (mode == VOIDmode)
2590 mode = GET_MODE (op);
2592 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2593 mode = GET_MODE (XEXP (op, 0));
2595 return ((mode == CCmode || mode == DImode)
2596 && (code == NE || code == EQ || code == GE || code == GT
2598 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2599 reverse the condition? Can it do that by itself? Maybe it can
2600 even reverse the condition to fit a foldable one in the first
2602 || (mode == CC_UNSmode && (code == GTU || code == LEU));
2605 /* Like comparison_operator, but only true if this comparison operator is
2606 applied to a valid mode. Needed to avoid jump.c generating invalid
2607 code with -ffast-math (gcc.dg/20001228-1.c). */
2610 mmix_comparison_operator (op, mode)
2612 enum machine_mode mode;
2614 RTX_CODE code = GET_CODE (op);
2616 /* Comparison operators usually don't have a mode, but let's try and get
2617 one anyway for the day that changes. */
2618 if (mode == VOIDmode)
2619 mode = GET_MODE (op);
2621 /* Get the mode from the first operand if we don't have one. */
2622 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2623 mode = GET_MODE (XEXP (op, 0));
2625 /* FIXME: This needs to be kept in sync with the tables in
2626 mmix_output_condition. */
2628 (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2629 || (mode == CC_FUNmode
2630 && (code == ORDERED || code == UNORDERED))
2631 || (mode == CC_FPmode
2632 && (code == GT || code == LT))
2633 || (mode == CC_FPEQmode
2634 && (code == NE || code == EQ))
2635 || (mode == CC_UNSmode
2636 && (code == GEU || code == GTU || code == LEU || code == LTU))
2638 && (code == NE || code == EQ || code == GE || code == GT
2639 || code == LE || code == LT))
2641 && (code == NE || code == EQ || code == GE || code == GT
2642 || code == LE || code == LT || code == LEU || code == GTU));
2645 /* True if this is a register or 0 (int or float). */
2648 mmix_reg_or_0_operand (op, mode)
2650 enum machine_mode mode;
2652 /* FIXME: Is mode calculation necessary and correct? */
2654 op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode)
2655 || register_operand (op, mode);
2658 /* True if this is a register or an int 0..255. */
2661 mmix_reg_or_8bit_operand (op, mode)
2663 enum machine_mode mode;
2665 return register_operand (op, mode)
2666 || (GET_CODE (op) == CONST_INT
2667 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
2670 /* Returns zero if code and mode is not a valid condition from a
2671 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2672 is the comparison of mode is CC-somethingmode. */
2675 mmix_valid_comparison (code, mode, op)
2677 enum machine_mode mode;
2680 if (mode == VOIDmode && op != NULL_RTX)
2681 mode = GET_MODE (op);
2683 /* We don't care to look at these, they should always be valid. */
2684 if (mode == CCmode || mode == CC_UNSmode || mode == DImode)
2687 if ((mode == CC_FPmode || mode == DFmode)
2688 && (code == GT || code == LT))
2691 if ((mode == CC_FPEQmode || mode == DFmode)
2692 && (code == EQ || code == NE))
2695 if ((mode == CC_FUNmode || mode == DFmode)
2696 && (code == ORDERED || code == UNORDERED))
2702 /* X and Y are two things to compare using CODE. Emit a compare insn if
2703 possible and return the rtx for the cc-reg in the proper mode, or
2704 NULL_RTX if this is not a valid comparison. */
2707 mmix_gen_compare_reg (code, x, y)
2711 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2714 /* FIXME: Do we get constants here? Of double mode? */
2715 enum machine_mode mode
2716 = GET_MODE (x) == VOIDmode
2718 : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode;
2720 if (! mmix_valid_comparison (code, mode, x))
2723 cc_reg = gen_reg_rtx (ccmode);
2725 /* FIXME: Can we avoid emitting a compare insn here? */
2726 if (! REG_P (x) && ! REG_P (y))
2727 x = force_reg (mode, x);
2729 /* If it's not quite right yet, put y in a register. */
2731 && (GET_CODE (y) != CONST_INT
2732 || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I')))
2733 y = force_reg (mode, y);
2735 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2736 gen_rtx_COMPARE (ccmode, x, y)));
2741 /* Local (static) helper functions. */
2744 mmix_emit_sp_add (offset)
2745 HOST_WIDE_INT offset;
2751 /* Negative stack-pointer adjustments are allocations and appear in
2752 the prologue only. We mark them as frame-related so unwind and
2753 debug info is properly emitted for them. */
2755 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2760 rtx tmpr = gen_rtx_REG (DImode, 255);
2761 RTX_FRAME_RELATED_P (emit_move_insn (tmpr, GEN_INT (offset))) = 1;
2762 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2763 stack_pointer_rtx, tmpr));
2765 RTX_FRAME_RELATED_P (insn) = 1;
2769 /* Positive adjustments are in the epilogue only. Don't mark them
2770 as "frame-related" for unwind info. */
2771 if (CONST_OK_FOR_LETTER_P (offset, 'L'))
2772 emit_insn (gen_adddi3 (stack_pointer_rtx,
2777 rtx tmpr = gen_rtx_REG (DImode, 255);
2778 emit_move_insn (tmpr, GEN_INT (offset));
2779 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2780 stack_pointer_rtx, tmpr));
2785 /* Print operator suitable for doing something with a shiftable
2786 wyde. The type of operator is passed as an asm output modifier. */
2789 mmix_output_shiftvalue_op_from_str (stream, mainop, value)
2792 HOST_WIDEST_INT value;
2794 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2797 if (! mmix_shiftable_wyde_value (value))
2799 char s[sizeof ("0xffffffffffffffff")];
2800 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2801 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2804 for (i = 0; i < 4; i++)
2806 /* We know we're through when we find one-bits in the low
2810 fprintf (stream, "%s%s", mainop, op_part[i]);
2816 /* No bits set? Then it must have been zero. */
2817 fprintf (stream, "%sL", mainop);
2820 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2823 mmix_output_octa (stream, value, do_begin_end)
2825 HOST_WIDEST_INT value;
2828 /* Snipped from final.c:output_addr_const. We need to avoid the
2829 presumed universal "0x" prefix. We can do it by replacing "0x" with
2830 "#0" here; we must avoid a space in the operands and no, the zero
2831 won't cause the number to be assumed in octal format. */
2832 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2835 fprintf (stream, "\tOCTA ");
2837 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2838 hex_format[0] = '#';
2839 hex_format[1] = '0';
2841 /* Provide a few alternative output formats depending on the number, to
2842 improve legibility of assembler output. */
2843 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2844 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2845 fprintf (stream, "%d", (int) value);
2846 else if (value > (HOST_WIDEST_INT) 0
2847 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2848 fprintf (stream, "#%x", (unsigned int) value);
2850 fprintf (stream, hex_format, value);
2853 fprintf (stream, "\n");
2856 /* Print the presumed shiftable wyde argument shifted into place (to
2857 be output with an operand). */
2860 mmix_output_shifted_value (stream, value)
2862 HOST_WIDEST_INT value;
2866 if (! mmix_shiftable_wyde_value (value))
2869 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2870 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2873 for (i = 0; i < 4; i++)
2875 /* We know we're through when we find one-bits in the low 16 bits. */
2878 fprintf (stream, "#%x", (int) (value & 0xffff));
2885 /* No bits set? Then it must have been zero. */
2886 fprintf (stream, "0");
2889 /* Output an MMIX condition name corresponding to an operator
2891 (comparison_operator [(comparison_operator ...) (const_int 0)])
2892 which means we have to look at *two* operators.
2894 The argument "reversed" refers to reversal of the condition (not the
2895 same as swapping the arguments). */
2898 mmix_output_condition (stream, x, reversed)
2907 /* The normal output cc-code. */
2908 const char *const normal;
2910 /* The reversed cc-code, or NULL if invalid. */
2911 const char *const reversed;
2916 enum machine_mode cc_mode;
2918 /* Terminated with {NIL, NULL, NULL} */
2919 const struct cc_conv *const convs;
2923 #define CCEND {NIL, NULL, NULL}
2925 static const struct cc_conv cc_fun_convs[]
2926 = {{ORDERED, "Z", "P"},
2927 {UNORDERED, "P", "Z"},
2929 static const struct cc_conv cc_fp_convs[]
2933 static const struct cc_conv cc_fpeq_convs[]
2937 static const struct cc_conv cc_uns_convs[]
2938 = {{GEU, "NN", "N"},
2943 static const struct cc_conv cc_signed_convs[]
2951 static const struct cc_conv cc_di_convs[]
2963 static const struct cc_type_conv cc_convs[]
2964 = {{CC_FUNmode, cc_fun_convs},
2965 {CC_FPmode, cc_fp_convs},
2966 {CC_FPEQmode, cc_fpeq_convs},
2967 {CC_UNSmode, cc_uns_convs},
2968 {CCmode, cc_signed_convs},
2969 {DImode, cc_di_convs}};
2974 enum machine_mode mode = GET_MODE (XEXP (x, 0));
2975 RTX_CODE cc = GET_CODE (x);
2977 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
2979 if (mode == cc_convs[i].cc_mode)
2981 for (j = 0; cc_convs[i].convs[j].cc != NIL; j++)
2982 if (cc == cc_convs[i].convs[j].cc)
2985 = (reversed ? cc_convs[i].convs[j].reversed
2986 : cc_convs[i].convs[j].normal);
2988 if (mmix_cc == NULL)
2989 fatal_insn ("MMIX Internal: Trying to output invalidly\
2990 reversed condition:", x);
2992 fprintf (stream, "%s", mmix_cc);
2996 fatal_insn ("MMIX Internal: What's the CC of this?", x);
3000 fatal_insn ("MMIX Internal: What is the CC of this?", x);
3003 /* Return the bit-value for a const_int or const_double. */
3005 static HOST_WIDEST_INT
3009 unsigned HOST_WIDEST_INT retval;
3011 if (GET_CODE (x) == CONST_INT)
3014 /* We make a little song and dance because converting to long long in
3015 gcc-2.7.2 is broken. I still want people to be able to use it for
3016 cross-compilation to MMIX. */
3017 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
3019 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
3021 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
3023 retval |= CONST_DOUBLE_LOW (x) & 1;
3026 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
3027 << (HOST_BITS_PER_LONG);
3030 retval = CONST_DOUBLE_HIGH (x);
3035 if (GET_CODE (x) == CONST_DOUBLE)
3037 REAL_VALUE_TYPE value;
3039 /* FIXME: This macro is not in the manual but should be. */
3040 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
3042 if (GET_MODE (x) == DFmode)
3046 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
3048 if (sizeof (long) < sizeof (HOST_WIDEST_INT))
3050 retval = (unsigned long) bits[1] / 2;
3052 retval |= (unsigned long) bits[1] & 1;
3054 |= (unsigned HOST_WIDEST_INT) bits[0]
3055 << (sizeof (bits[0]) * 8);
3058 retval = (unsigned long) bits[1];
3062 else if (GET_MODE (x) == SFmode)
3065 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
3067 return (unsigned long) bits;
3071 fatal_insn ("MMIX Internal: This is not a constant:", x);
3076 * eval: (c-set-style "gnu")
3077 * indent-tabs-mode: t