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 GNU CC.
7 GNU CC 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 GNU CC 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 GNU CC; 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"
44 /* First some local helper definitions. */
45 #define MMIX_FIRST_GLOBAL_REGNUM 32
47 /* We'd need a current_function_has_landing_pad. It's marked as such when
48 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
50 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
52 /* We have no means to tell DWARF 2 about the register stack, so we need
53 to store the return address on the stack if an exception can get into
54 this function. FIXME: Narrow condition. */
55 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
56 (flag_exceptions && ! leaf_function_p ())
58 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
59 (current_function_calls_eh_return \
60 && (EH_RETURN_DATA_REGNO (0) == REGNO \
61 || EH_RETURN_DATA_REGNO (1) == REGNO \
62 || EH_RETURN_DATA_REGNO (2) == REGNO \
63 || EH_RETURN_DATA_REGNO (3) == REGNO))
65 /* For the default ABI, we rename registers at output-time to fill the gap
66 between the (statically partitioned) saved registers and call-clobbered
67 registers. In effect this makes unused call-saved registers to be used
68 as call-clobbered registers. The benefit comes from keeping the number
69 of local registers (value of rL) low, since there's a cost of
70 increasing rL and clearing unused (unset) registers with lower numbers. */
71 #define MMIX_OUTPUT_REGNO(N) \
73 || (N) < MMIX_RETURN_VALUE_REGNUM \
74 || (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
75 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
76 + cfun->machine->highest_saved_stack_register + 1))
78 /* The canonical saved comparison operands for non-cc0 machines, set in
79 the compare expander. */
83 /* We ignore some options with arguments. They are passed to the linker,
84 but also ends up here because they start with "-m". We tell the driver
85 to store them in a variable we don't inspect. */
86 const char *mmix_cc1_ignored_option;
88 /* Declarations of locals. */
90 /* Intermediate for insn output. */
91 static int mmix_output_destination_register;
93 static void mmix_output_shiftvalue_op_from_str
94 PARAMS ((FILE *, const char *, HOST_WIDEST_INT));
95 static void mmix_output_shifted_value PARAMS ((FILE *, HOST_WIDEST_INT));
96 static void mmix_output_condition PARAMS ((FILE *, rtx, int));
97 static HOST_WIDEST_INT mmix_intval PARAMS ((rtx));
98 static void mmix_output_octa PARAMS ((FILE *, HOST_WIDEST_INT, int));
99 static bool mmix_assemble_integer PARAMS ((rtx, unsigned int, int));
100 static void mmix_init_machine_status PARAMS ((struct function *));
102 extern void mmix_target_asm_function_prologue
103 PARAMS ((FILE *, HOST_WIDE_INT));
104 extern void mmix_target_asm_function_epilogue
105 PARAMS ((FILE *, HOST_WIDE_INT));
108 /* Target structure macros. Listed by node. See `Using and Porting GCC'
109 for a general description. */
111 /* Node: Function Entry */
113 #undef TARGET_ASM_BYTE_OP
114 #define TARGET_ASM_BYTE_OP NULL
115 #undef TARGET_ASM_ALIGNED_HI_OP
116 #define TARGET_ASM_ALIGNED_HI_OP NULL
117 #undef TARGET_ASM_ALIGNED_SI_OP
118 #define TARGET_ASM_ALIGNED_SI_OP NULL
119 #undef TARGET_ASM_ALIGNED_DI_OP
120 #define TARGET_ASM_ALIGNED_DI_OP NULL
121 #undef TARGET_ASM_INTEGER
122 #define TARGET_ASM_INTEGER mmix_assemble_integer
124 #undef TARGET_ASM_FUNCTION_PROLOGUE
125 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
127 #undef TARGET_ASM_FUNCTION_EPILOGUE
128 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
130 struct gcc_target targetm = TARGET_INITIALIZER;
132 /* Functions that are expansions for target macros.
133 See Target Macros in `Using and Porting GCC'. */
135 /* OVERRIDE_OPTIONS. */
138 mmix_override_options ()
140 /* Should we err or should we warn? Hmm. At least we must neutralize
141 it. For example the wrong kind of case-tables will be generated with
142 PIC; we use absolute address items for mmixal compatibility. FIXME:
143 They could be relative if we just elide them to after all pertinent
147 warning ("-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
151 /* All other targets add GC roots from their override_options function,
153 ggc_add_rtx_root (&mmix_compare_op0, 1);
154 ggc_add_rtx_root (&mmix_compare_op1, 1);
157 /* INIT_EXPANDERS. */
160 mmix_init_expanders ()
162 init_machine_status = mmix_init_machine_status;
165 /* Set the per-function data. */
168 mmix_init_machine_status (f)
171 f->machine = xcalloc (1, sizeof (struct machine_function));
175 We have trouble getting the address of stuff that is located at other
176 than 32-bit alignments (GETA requirements), so try to give everything
177 at least 32-bit alignment. */
180 mmix_data_alignment (type, basic_align)
181 tree type ATTRIBUTE_UNUSED;
184 if (basic_align < 32)
190 /* CONSTANT_ALIGNMENT. */
193 mmix_constant_alignment (constant, basic_align)
194 tree constant ATTRIBUTE_UNUSED;
197 if (basic_align < 32)
203 /* LOCAL_ALIGNMENT. */
206 mmix_local_alignment (type, basic_align)
207 tree type ATTRIBUTE_UNUSED;
210 if (basic_align < 32)
216 /* CONDITIONAL_REGISTER_USAGE. */
219 mmix_conditional_register_usage ()
225 static const int gnu_abi_reg_alloc_order[]
226 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
228 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
229 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
231 /* Change the default from the mmixware ABI. For the GNU ABI,
232 $15..$30 are call-saved just as $0..$14. There must be one
233 call-clobbered local register for the "hole" describing number of
234 saved local registers saved by PUSHJ/PUSHGO during the function
235 call, receiving the return value at return. So best is to use
236 the highest, $31. It's already marked call-clobbered for the
238 for (i = 15; i <= 30; i++)
239 call_used_regs[i] = 0;
241 /* "Unfix" the parameter registers. */
242 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
243 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
248 /* Step over the ":" in special register names. */
249 if (! TARGET_TOPLEVEL_SYMBOLS)
250 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
251 if (reg_names[i][0] == ':')
255 /* PREFERRED_RELOAD_CLASS.
256 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
259 mmix_preferred_reload_class (x, class)
260 rtx x ATTRIBUTE_UNUSED;
261 enum reg_class class;
263 /* FIXME: Revisit. */
264 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
265 ? REMAINDER_REG : class;
268 /* PREFERRED_OUTPUT_RELOAD_CLASS.
269 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
272 mmix_preferred_output_reload_class (x, class)
273 rtx x ATTRIBUTE_UNUSED;
274 enum reg_class class;
276 /* FIXME: Revisit. */
277 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
278 ? REMAINDER_REG : class;
281 /* SECONDARY_RELOAD_CLASS.
282 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
285 mmix_secondary_reload_class (class, mode, x, in_p)
286 enum reg_class class;
287 enum machine_mode mode ATTRIBUTE_UNUSED;
288 rtx x ATTRIBUTE_UNUSED;
289 int in_p ATTRIBUTE_UNUSED;
291 if (class == REMAINDER_REG
292 || class == HIMULT_REG
293 || class == SYSTEM_REGS)
299 /* CONST_OK_FOR_LETTER_P. */
302 mmix_const_ok_for_letter_p (value, c)
307 (c == 'I' ? value >= 0 && value <= 255
308 : c == 'J' ? value >= 0 && value <= 65535
309 : c == 'K' ? value <= 0 && value >= -255
310 : c == 'L' ? mmix_shiftable_wyde_value (value)
311 : c == 'M' ? value == 0
312 : c == 'N' ? mmix_shiftable_wyde_value (~value)
313 : c == 'O' ? (value == 3 || value == 5 || value == 9
318 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
321 mmix_const_double_ok_for_letter_p (value, c)
326 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
331 We need this since our constants are not always expressible as
332 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
335 mmix_extra_constraint (x, c, strict)
340 HOST_WIDEST_INT value;
342 /* When checking for an address, we need to handle strict vs. non-strict
343 register checks. Don't use address_operand, but instead its
344 equivalent (its callee, which it is just a wrapper for),
345 memory_operand_p and the strict-equivalent strict_memory_address_p. */
349 ? strict_memory_address_p (Pmode, x)
350 : memory_address_p (Pmode, x);
352 /* R asks whether x is to be loaded with GETA or something else. Right
353 now, only a SYMBOL_REF and LABEL_REF can fit for
354 TARGET_BASE_ADDRESSES.
356 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
357 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
358 set right now; only function addresses and code labels. If we change
359 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
360 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
361 effect, a "raw" constant check together with mmix_constant_address_p
362 is all that's needed; we want all constant addresses to be loaded
366 GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE
367 && mmix_constant_address_p (x)
368 && (! TARGET_BASE_ADDRESSES
369 || (GET_CODE (x) == LABEL_REF
370 || (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))));
372 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
375 value = mmix_intval (x);
377 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
378 more ('U' taken for address_operand, 'R' similarly). Some letters map
379 outside of CONST_INT, though; we still use 'S' and 'T'. */
381 return mmix_shiftable_wyde_value (value);
383 return mmix_shiftable_wyde_value (~value);
387 /* DYNAMIC_CHAIN_ADDRESS. */
390 mmix_dynamic_chain_address (frame)
393 /* FIXME: the frame-pointer is stored at offset -8 from the current
394 frame-pointer. Unfortunately, the caller assumes that a
395 frame-pointer is present for *all* previous frames. There should be
396 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
397 return plus_constant (frame, -8);
400 /* STARTING_FRAME_OFFSET. */
403 mmix_starting_frame_offset ()
405 /* The old frame pointer is in the slot below the new one, so
406 FIRST_PARM_OFFSET does not need to depend on whether the
407 frame-pointer is needed or not. We have to adjust for the register
408 stack pointer being located below the saved frame pointer.
409 Similarly, we store the return address on the stack too, for
410 exception handling, and always if we save the register stack pointer. */
413 + (MMIX_CFUN_HAS_LANDING_PAD
414 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
417 /* RETURN_ADDR_RTX. */
420 mmix_return_addr_rtx (count, frame)
422 rtx frame ATTRIBUTE_UNUSED;
425 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
426 /* FIXME: Set frame_alias_set on the following. (Why?)
427 See mmix_initial_elimination_offset for the reason we can't use
428 get_hard_reg_initial_val for both. Always using a stack slot
429 and not a register would be suboptimal. */
430 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
431 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
435 /* SETUP_FRAME_ADDRESSES. */
438 mmix_setup_frame_addresses ()
440 /* Nothing needed at the moment. */
443 /* The difference between the (imaginary) frame pointer and the stack
444 pointer. Used to eliminate the frame pointer. */
447 mmix_initial_elimination_offset (fromreg, toreg)
453 = (get_frame_size () + current_function_outgoing_args_size + 7) & ~7;
455 /* There is no actual offset between these two virtual values, but for
456 the frame-pointer, we have the old one in the stack position below
457 it, so the offset for the frame-pointer to the stack-pointer is one
459 if (fromreg == MMIX_ARG_POINTER_REGNUM
460 && toreg == MMIX_FRAME_POINTER_REGNUM)
463 /* The difference is the size of local variables plus the size of
464 outgoing function arguments that would normally be passed as
465 registers but must be passed on stack because we're out of
466 function-argument registers. Only global saved registers are
467 counted; the others go on the register stack.
469 The frame-pointer is counted too if it is what is eliminated, as we
470 need to balance the offset for it from STARTING_FRAME_OFFSET.
472 Also add in the slot for the register stack pointer we save if we
475 Unfortunately, we can't access $0..$14, from unwinder code easily, so
476 store the return address in a frame slot too. FIXME: Only for
477 non-leaf functions. FIXME: Always with a landing pad, because it's
478 hard to know whether we need the other at the time we know we need
479 the offset for one (and have to state it). It's a kludge until we
480 can express the register stack in the EH frame info.
482 We have to do alignment here; get_frame_size will not return a
483 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
485 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
488 if ((regs_ever_live[regno] && ! call_used_regs[regno])
489 || IS_MMIX_EH_RETURN_DATA_REG (regno))
493 + (MMIX_CFUN_HAS_LANDING_PAD
494 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
495 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
498 /* Return an rtx for a function argument to go in a register, and 0 for
499 one that must go on stack. */
502 mmix_function_arg (argsp, mode, type, named, incoming)
503 const CUMULATIVE_ARGS * argsp;
504 enum machine_mode mode;
506 int named ATTRIBUTE_UNUSED;
509 /* Handling of the positional dummy parameter for varargs gets nasty.
510 Check execute/991216-3 and function.c:assign_params. We have to say
511 that the dummy parameter goes on stack in order to get the correct
512 offset when va_start and va_arg is applied. FIXME: Should do TRT by
513 itself in the gcc core. */
514 if ((! named && incoming && current_function_varargs) || argsp->now_varargs)
517 /* Last-argument marker. */
518 if (type == void_type_node)
519 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
522 ? MMIX_FIRST_INCOMING_ARG_REGNUM
523 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
526 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
527 && !MUST_PASS_IN_STACK (mode, type)
528 && (GET_MODE_BITSIZE (mode) <= 64
533 ? MMIX_FIRST_INCOMING_ARG_REGNUM
534 : MMIX_FIRST_ARG_REGNUM)
539 /* Returns nonzero for everything that goes by reference, 0 for
540 everything that goes by value. */
543 mmix_function_arg_pass_by_reference (argsp, mode, type, named)
544 const CUMULATIVE_ARGS * argsp;
545 enum machine_mode mode;
547 int named ATTRIBUTE_UNUSED;
549 /* FIXME: Check: I'm not sure the MUST_PASS_IN_STACK check is
552 MUST_PASS_IN_STACK (mode, type)
553 || (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
558 /* Return nonzero if regno is a register number where a parameter is
559 passed, and 0 otherwise. */
562 mmix_function_arg_regno_p (regno, incoming)
567 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
569 return regno >= first_arg_regnum
570 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
573 /* FUNCTION_OUTGOING_VALUE. */
576 mmix_function_outgoing_value (valtype, func)
578 tree func ATTRIBUTE_UNUSED;
580 enum machine_mode mode = TYPE_MODE (valtype);
581 enum machine_mode cmode;
582 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
583 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
587 /* Return values that fit in a register need no special handling.
588 There's no register hole when parameters are passed in global
591 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
593 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
595 /* A complex type, made up of components. */
596 cmode = TYPE_MODE (TREE_TYPE (valtype));
597 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
599 /* We need to take care of the effect of the register hole on return
600 values of large sizes; the last register will appear as the first
601 register, with the rest shifted. (For complex modes, this is just
602 swapped registers.) */
604 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
605 internal_error ("too large function value type, needs %d registers,\
606 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
608 /* FIXME: Maybe we should handle structure values like this too
609 (adjusted for BLKmode), perhaps for both ABI:s. */
610 for (i = 0; i < nregs - 1; i++)
612 = gen_rtx_EXPR_LIST (VOIDmode,
613 gen_rtx_REG (cmode, first_val_regnum + i),
614 GEN_INT ((i + 1) * BITS_PER_UNIT));
617 = gen_rtx_EXPR_LIST (VOIDmode,
618 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
621 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
624 /* EH_RETURN_DATA_REGNO. */
627 mmix_eh_return_data_regno (n)
628 int n ATTRIBUTE_UNUSED;
631 return MMIX_EH_RETURN_DATA_REGNO_START + n;
633 return INVALID_REGNUM;
636 /* EH_RETURN_STACKADJ_RTX. */
639 mmix_eh_return_stackadj_rtx ()
641 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
644 /* EH_RETURN_HANDLER_RTX. */
647 mmix_eh_return_handler_rtx ()
650 gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
653 /* ASM_PREFERRED_EH_DATA_FORMAT. */
656 mmix_asm_preferred_eh_data_format (code, global)
657 int code ATTRIBUTE_UNUSED;
658 int global ATTRIBUTE_UNUSED;
660 /* This is the default (was at 2001-07-20). Revisit when needed. */
661 return DW_EH_PE_absptr;
664 /* Emit the function prologue. For simplicity while the port is still
665 in a flux, we do it as text rather than the now preferred RTL way,
666 as (define_insn "function_prologue").
668 FIXME: Translate to RTL and/or optimize some of the DWARF 2 stuff. */
671 mmix_target_asm_function_prologue (stream, locals_size)
673 HOST_WIDE_INT locals_size;
676 int stack_space_to_allocate
677 = (current_function_outgoing_args_size
678 + current_function_pretend_args_size
679 + (int) locals_size + 7) & ~7;
681 int doing_dwarf = dwarf2out_do_frame ();
684 /* Guard our assumptions. Very low priority FIXME. */
685 if (locals_size != (int) locals_size)
686 error ("stack frame too big");
688 /* Add room needed to save global non-register-stack registers. */
690 regno >= MMIX_FIRST_GLOBAL_REGNUM;
692 /* Note that we assume that the frame-pointer-register is one of these
693 registers, in which case we don't count it here. */
694 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
695 && regs_ever_live[regno] && !call_used_regs[regno]))
696 || IS_MMIX_EH_RETURN_DATA_REG (regno))
697 stack_space_to_allocate += 8;
699 /* If we do have a frame-pointer, add room for it. */
700 if (frame_pointer_needed)
701 stack_space_to_allocate += 8;
703 /* If we have a non-local label, we need to be able to unwind to it, so
704 store the current register stack pointer. Also store the return
705 address if we do that. */
706 if (MMIX_CFUN_HAS_LANDING_PAD)
707 stack_space_to_allocate += 16;
708 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
709 /* If we do have a saved return-address slot, add room for it. */
710 stack_space_to_allocate += 8;
712 /* Make sure we don't get an unaligned stack. */
713 if ((stack_space_to_allocate % 8) != 0)
714 internal_error ("stack frame not a multiple of 8 bytes: %d",
715 stack_space_to_allocate);
717 if (current_function_pretend_args_size)
719 int mmix_first_vararg_reg
720 = (MMIX_FIRST_INCOMING_ARG_REGNUM
721 + (MMIX_MAX_ARGS_IN_REGS
722 - current_function_pretend_args_size / 8));
725 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
726 regno >= mmix_first_vararg_reg;
732 = stack_space_to_allocate > (256 - 8)
733 ? (256 - 8) : stack_space_to_allocate;
735 fprintf (stream, "\tSUBU %s,%s,%d\n",
736 reg_names[MMIX_STACK_POINTER_REGNUM],
737 reg_names[MMIX_STACK_POINTER_REGNUM],
742 /* Each call to dwarf2out_def_cfa overrides the previous
743 setting; they don't accumulate. We must keep track
744 of the offset ourselves. */
745 cfa_offset += stack_chunk;
746 if (!frame_pointer_needed)
747 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
750 offset += stack_chunk;
751 stack_space_to_allocate -= stack_chunk;
754 fprintf (stream, "\tSTOU %s,%s,%d\n", reg_names[regno],
755 reg_names[MMIX_STACK_POINTER_REGNUM],
758 /* These registers aren't actually saved (as in "will be
759 restored"), so don't tell DWARF2 they're saved. */
765 /* Store the frame-pointer. */
767 if (frame_pointer_needed)
771 /* Get 8 less than otherwise, since we need to reach offset + 8. */
773 = stack_space_to_allocate > (256 - 8 - 8)
774 ? (256 - 8 - 8) : stack_space_to_allocate;
776 fprintf (stream, "\tSUBU %s,%s,%d\n",
777 reg_names[MMIX_STACK_POINTER_REGNUM],
778 reg_names[MMIX_STACK_POINTER_REGNUM],
781 cfa_offset += stack_chunk;
782 offset += stack_chunk;
783 stack_space_to_allocate -= stack_chunk;
786 fprintf (stream, "\tSTOU %s,%s,%d\n\tADDU %s,%s,%d\n",
787 reg_names[MMIX_FRAME_POINTER_REGNUM],
788 reg_names[MMIX_STACK_POINTER_REGNUM],
790 reg_names[MMIX_FRAME_POINTER_REGNUM],
791 reg_names[MMIX_STACK_POINTER_REGNUM],
795 /* If we're using the frame-pointer, then we just need this CFA
796 definition basing on that value (often equal to the CFA).
797 Further changes to the stack-pointer do not affect the
798 frame-pointer, so we conditionalize them below on
799 !frame_pointer_needed. */
800 dwarf2out_def_cfa ("", MMIX_FRAME_POINTER_REGNUM,
801 -cfa_offset + offset + 8);
803 dwarf2out_reg_save ("", MMIX_FRAME_POINTER_REGNUM,
804 -cfa_offset + offset);
810 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
812 /* Store the return-address, if one is needed on the stack. We
813 usually store it in a register when needed, but that doesn't work
814 with -fexceptions. */
818 /* Get 8 less than otherwise, since we need to reach offset + 8. */
820 = stack_space_to_allocate > (256 - 8 - 8)
821 ? (256 - 8 - 8) : stack_space_to_allocate;
823 fprintf (stream, "\tSUBU %s,%s,%d\n",
824 reg_names[MMIX_STACK_POINTER_REGNUM],
825 reg_names[MMIX_STACK_POINTER_REGNUM],
829 cfa_offset += stack_chunk;
830 if (!frame_pointer_needed)
831 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
834 offset += stack_chunk;
835 stack_space_to_allocate -= stack_chunk;
838 fprintf (stream, "\tGET $255,rJ\n\tSTOU $255,%s,%d\n",
839 reg_names[MMIX_STACK_POINTER_REGNUM],
842 dwarf2out_return_save ("", -cfa_offset + offset);
845 else if (MMIX_CFUN_HAS_LANDING_PAD)
848 if (MMIX_CFUN_HAS_LANDING_PAD)
850 /* Store the register defining the numbering of local registers, so
851 we know how long to unwind the register stack. */
855 /* Get 8 less than otherwise, since we need to reach offset + 8. */
857 = stack_space_to_allocate > (256 - 8 - 8)
858 ? (256 - 8 - 8) : stack_space_to_allocate;
860 fprintf (stream, "\tSUBU %s,%s,%d\n",
861 reg_names[MMIX_STACK_POINTER_REGNUM],
862 reg_names[MMIX_STACK_POINTER_REGNUM],
864 offset += stack_chunk;
865 stack_space_to_allocate -= stack_chunk;
869 cfa_offset += stack_chunk;
870 if (!frame_pointer_needed)
871 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
876 /* We don't tell dwarf2 about this one; we just have it to unwind
877 the register stack at landing pads. FIXME: It's a kludge because
878 we can't describe the effect of the PUSHJ and PUSHGO insns on the
879 register stack at the moment. Best thing would be to handle it
880 like stack-pointer offsets. Better: some hook into dwarf2out.c
881 to produce DW_CFA_expression:s that specify the increment of rO,
882 and unwind it at eh_return (preferred) or at the landing pad.
883 Then saves to $0..$G-1 could be specified through that register. */
885 fprintf (stream, "\tGET $255,rO\n\tSTOU $255,%s,%d\n",
886 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
891 /* After the return-address and the frame-pointer, we have the local
892 variables. They're the ones that may have an "unaligned" size. */
893 offset -= (locals_size + 7) & ~7;
895 /* Now store all registers that are global, i.e. not saved by the
896 register file machinery.
898 It is assumed that the frame-pointer is one of these registers, so it
899 is explicitly excluded in the count. */
902 regno >= MMIX_FIRST_GLOBAL_REGNUM;
904 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
905 && regs_ever_live[regno] && ! call_used_regs[regno])
906 || IS_MMIX_EH_RETURN_DATA_REG (regno))
912 /* Since the local variables go above, we may get a large
916 /* We're not going to access the locals area in the
917 prologue, so we'll just silently subtract the slab we
920 stack_space_to_allocate > (256 - offset - 8)
921 ? (256 - offset - 8) : stack_space_to_allocate;
923 mmix_output_register_setting (stream, 255, stack_chunk, 1);
924 fprintf (stream, "\tSUBU %s,%s,$255\n",
925 reg_names[MMIX_STACK_POINTER_REGNUM],
926 reg_names[MMIX_STACK_POINTER_REGNUM]);
930 cfa_offset += stack_chunk;
931 if (!frame_pointer_needed)
932 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
938 stack_chunk = stack_space_to_allocate > (256 - 8)
939 ? (256 - 8) : stack_space_to_allocate;
941 fprintf (stream, "\tSUBU %s,%s,%d\n",
942 reg_names[MMIX_STACK_POINTER_REGNUM],
943 reg_names[MMIX_STACK_POINTER_REGNUM], stack_chunk);
946 cfa_offset += stack_chunk;
947 if (!frame_pointer_needed)
948 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
953 offset += stack_chunk;
954 stack_space_to_allocate -= stack_chunk;
957 fprintf (stream, "\tSTOU %s,%s,%d\n", reg_names[regno],
958 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
960 dwarf2out_reg_save ("", regno, -cfa_offset + offset);
964 /* Finally, allocate room for outgoing args and local vars if room
965 wasn't allocated above. This might be any number of bytes (well, we
966 assume it fits in a host-int). */
967 if (stack_space_to_allocate)
969 if (stack_space_to_allocate < 256)
971 fprintf (stream, "\tSUBU %s,%s,%d\n",
972 reg_names[MMIX_STACK_POINTER_REGNUM],
973 reg_names[MMIX_STACK_POINTER_REGNUM],
974 stack_space_to_allocate);
978 mmix_output_register_setting (stream, 255,
979 stack_space_to_allocate, 1);
980 fprintf (stream, "\tSUBU %s,%s,$255\n",
981 reg_names[MMIX_STACK_POINTER_REGNUM],
982 reg_names[MMIX_STACK_POINTER_REGNUM]);
987 cfa_offset += stack_space_to_allocate;
988 if (!frame_pointer_needed)
989 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
995 /* MACHINE_DEPENDENT_REORG.
996 No actual rearrangements done here; just virtually by calculating the
997 highest saved stack register number used to modify the register numbers
1001 mmix_machine_dependent_reorg (first)
1002 rtx first ATTRIBUTE_UNUSED;
1006 /* We put the number of the highest saved register-file register in a
1007 location convenient for the call-patterns to output. Note that we
1008 don't tell dwarf2 about these registers, since it can't restore them
1010 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
1013 if ((regs_ever_live[regno] && !call_used_regs[regno])
1014 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
1017 /* Regardless of whether they're saved (they might be just read), we
1018 mustn't include registers that carry parameters. We could scan the
1019 insns to see whether they're actually used (and indeed do other less
1020 trivial register usage analysis and transformations), but it seems
1021 wasteful to optimize for unused parameter registers. As of
1022 2002-04-30, regs_ever_live[n] seems to be set for only-reads too, but
1023 that might change. */
1024 if (!TARGET_ABI_GNU && regno < current_function_args_info.regs - 1)
1026 regno = current_function_args_info.regs - 1;
1028 /* We don't want to let this cause us to go over the limit and make
1029 incoming parameter registers be misnumbered and treating the last
1030 parameter register and incoming return value register call-saved.
1031 Stop things at the unmodified scheme. */
1032 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
1033 regno = MMIX_RETURN_VALUE_REGNUM - 1;
1036 cfun->machine->highest_saved_stack_register = regno;
1039 /* TARGET_ASM_FUNCTION_EPILOGUE. */
1042 mmix_target_asm_function_epilogue (stream, locals_size)
1044 HOST_WIDE_INT locals_size;
1048 int stack_space_to_deallocate
1049 = (current_function_outgoing_args_size
1050 + current_function_pretend_args_size
1051 + (int) locals_size + 7) & ~7;
1053 /* The assumption that locals_size fits in an int is asserted in
1054 mmix_target_asm_function_prologue. */
1056 /* The first address to access is beyond the outgoing_args area. */
1057 int offset = current_function_outgoing_args_size;
1059 /* Add the space for global non-register-stack registers.
1060 It is assumed that the frame-pointer register can be one of these
1061 registers, in which case it is excluded from the count when needed. */
1063 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1065 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1066 && regs_ever_live[regno] && !call_used_regs[regno])
1067 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1068 stack_space_to_deallocate += 8;
1070 /* Add in the space for register stack-pointer. If so, always add room
1071 for the saved PC. */
1072 if (MMIX_CFUN_HAS_LANDING_PAD)
1073 stack_space_to_deallocate += 16;
1074 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1075 /* If we have a saved return-address slot, add it in. */
1076 stack_space_to_deallocate += 8;
1078 /* Add in the frame-pointer. */
1079 if (frame_pointer_needed)
1080 stack_space_to_deallocate += 8;
1082 /* Make sure we don't get an unaligned stack. */
1083 if ((stack_space_to_deallocate % 8) != 0)
1084 internal_error ("stack frame not a multiple of octabyte: %d",
1085 stack_space_to_deallocate);
1087 /* We will add back small offsets to the stack pointer as we go.
1088 First, we restore all registers that are global, i.e. not saved by
1089 the register file machinery. */
1091 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
1094 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1095 && regs_ever_live[regno] && !call_used_regs[regno])
1096 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1102 /* There's better support for incrementing than
1103 decrementing, so we might be able to optimize this as
1105 mmix_output_register_setting (stream, 255, offset, 1);
1106 fprintf (stream, "\tADDU %s,%s,$255\n",
1107 reg_names[MMIX_STACK_POINTER_REGNUM],
1108 reg_names[MMIX_STACK_POINTER_REGNUM]);
1111 fprintf (stream, "\tINCL %s,%d\n",
1112 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
1114 stack_space_to_deallocate -= offset;
1118 fprintf (stream, "\tLDOU %s,%s,%d\n",
1120 reg_names[MMIX_STACK_POINTER_REGNUM],
1125 /* Here is where the local variables were. As in the prologue, they
1126 might be of an unaligned size. */
1127 offset += (locals_size + 7) & ~7;
1130 /* The saved register stack pointer is just below the frame-pointer
1131 register. We don't need to restore it "manually"; the POP
1132 instruction does that. */
1133 if (MMIX_CFUN_HAS_LANDING_PAD)
1135 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1136 /* The return-address slot is just below the frame-pointer register.
1137 We don't need to restore it because we don't really use it. */
1140 /* Get back the old frame-pointer-value. */
1141 if (frame_pointer_needed)
1147 /* There's better support for incrementing than
1148 decrementing, so we might be able to optimize this as
1150 mmix_output_register_setting (stream, 255, offset, 1);
1151 fprintf (stream, "\tADDU %s,%s,$255\n",
1152 reg_names[MMIX_STACK_POINTER_REGNUM],
1153 reg_names[MMIX_STACK_POINTER_REGNUM]);
1156 fprintf (stream, "\tINCL %s,%d\n",
1157 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
1159 stack_space_to_deallocate -= offset;
1163 fprintf (stream, "\tLDOU %s,%s,%d\n",
1164 reg_names[MMIX_FRAME_POINTER_REGNUM],
1165 reg_names[MMIX_STACK_POINTER_REGNUM],
1170 /* We do not need to restore pretended incoming args, just add back
1172 if (stack_space_to_deallocate > 65535)
1174 /* There's better support for incrementing than decrementing, so
1175 we might be able to optimize this as we see a need. */
1176 mmix_output_register_setting (stream, 255,
1177 stack_space_to_deallocate, 1);
1178 fprintf (stream, "\tADDU %s,%s,$255\n",
1179 reg_names[MMIX_STACK_POINTER_REGNUM],
1180 reg_names[MMIX_STACK_POINTER_REGNUM]);
1182 else if (stack_space_to_deallocate != 0)
1183 fprintf (stream, "\tINCL %s,%d\n",
1184 reg_names[MMIX_STACK_POINTER_REGNUM],
1185 stack_space_to_deallocate);
1187 if (current_function_calls_eh_return)
1188 /* Adjustment the (normal) stack-pointer to that of the receiver.
1189 FIXME: It would be nice if we could also adjust the register stack
1190 here, but we need to express it through DWARF 2 too. */
1191 fprintf (stream, "\tADDU %s,%s,%s\n",
1192 reg_names [MMIX_STACK_POINTER_REGNUM],
1193 reg_names [MMIX_STACK_POINTER_REGNUM],
1194 reg_names [MMIX_EH_RETURN_STACKADJ_REGNUM]);
1196 /* The extra \n is so we have a blank line between the assembly code of
1197 separate functions. */
1198 fprintf (stream, "\tPOP %d,0\n\n",
1200 && current_function_return_rtx != NULL
1201 && ! current_function_returns_struct)
1202 ? (GET_CODE (current_function_return_rtx) == PARALLEL
1203 ? GET_NUM_ELEM (XVEC (current_function_return_rtx, 0)) : 1)
1207 /* ASM_OUTPUT_MI_THUNK. */
1210 mmix_asm_output_mi_thunk (stream, fndecl, delta, func)
1212 tree fndecl ATTRIBUTE_UNUSED;
1216 /* If you define STRUCT_VALUE to 0, rather than use STRUCT_VALUE_REGNUM,
1217 (i.e. pass location of structure to return as invisible first
1218 argument) you need to tweak this code too. */
1219 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
1221 if (delta >= 0 && delta < 65536)
1222 asm_fprintf (stream, "\tINCL %s,%d\n", delta, regname);
1223 else if (delta < 0 && delta >= -255)
1224 asm_fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, -delta);
1227 mmix_output_register_setting (stream, 255, delta, 1);
1228 asm_fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
1231 fprintf (stream, "\tJMP ");
1232 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
1233 fprintf (stream, "\n");
1236 /* FUNCTION_PROFILER. */
1239 mmix_function_profiler (stream, labelno)
1240 FILE *stream ATTRIBUTE_UNUSED;
1241 int labelno ATTRIBUTE_UNUSED;
1243 sorry ("function_profiler support for MMIX");
1246 /* SETUP_INCOMING_VARARGS. */
1249 mmix_setup_incoming_varargs (args_so_farp, mode, vartype, pretend_sizep,
1251 CUMULATIVE_ARGS * args_so_farp;
1252 enum machine_mode mode;
1254 int * pretend_sizep;
1255 int second_time ATTRIBUTE_UNUSED;
1257 /* For stdarg, the last named variable has been handled, but
1258 args_so_farp has not been advanced for it. For varargs, the current
1259 argument is to be counted to the anonymous ones. */
1260 if (current_function_stdarg)
1262 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
1264 = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
1266 else if (current_function_varargs)
1268 if (args_so_farp->regs < MMIX_MAX_ARGS_IN_REGS)
1270 = (MMIX_MAX_ARGS_IN_REGS - args_so_farp->regs) * 8;
1272 /* For varargs, we get here when we see the last named parameter,
1273 which will actually be passed on stack. So make the next call
1274 (there will be one) to FUNCTION_ARG return 0, to count it on
1275 stack, so va_arg for it will get right. FIXME: The GCC core
1276 should provide TRT. */
1277 args_so_farp->now_varargs = 1;
1280 internal_error ("neither varargs or stdarg in mmix_setup_incoming_varargs");
1283 /* We assume that one argument takes up one register here. That should
1284 be true until we start messing with multi-reg parameters. */
1285 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
1286 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
1289 /* EXPAND_BUILTIN_VA_ARG. */
1291 /* This is modified from the "standard" implementation of va_arg: read the
1292 value from the current (padded) address and increment by the (padded)
1293 size. The difference for MMIX is that if the type is
1294 pass-by-reference, then perform an indirection. */
1297 mmix_expand_builtin_va_arg (valist, type)
1301 tree ptr_size = size_int (BITS_PER_WORD / BITS_PER_UNIT);
1302 tree addr_tree, type_size = NULL;
1303 tree align, alignm1;
1307 /* Compute the rounded size of the type. */
1311 align = size_int (PARM_BOUNDARY / BITS_PER_UNIT);
1312 alignm1 = size_int (PARM_BOUNDARY / BITS_PER_UNIT - 1);
1313 if (type == error_mark_node
1314 || (type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type))) == NULL
1315 || TREE_OVERFLOW (type_size))
1316 /* Presumably an error; the size isn't computable. A message has
1317 supposedly been emitted elsewhere. */
1318 rounded_size = size_zero_node;
1320 rounded_size = fold (build (MULT_EXPR, sizetype,
1321 fold (build (TRUNC_DIV_EXPR, sizetype,
1322 fold (build (PLUS_EXPR, sizetype,
1323 type_size, alignm1)),
1327 if (AGGREGATE_TYPE_P (type)
1328 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) < 8
1329 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) != 0)
1331 /* Adjust for big-endian the location of aggregates passed in a
1332 register, but where the aggregate is accessed in a shorter mode
1333 than the natural register mode (i.e. it is accessed as SFmode(?),
1334 SImode, HImode or QImode rather than DImode or DFmode(?)). FIXME:
1335 Or should we adjust the mode in which the aggregate is read, to be
1336 a register size mode? (Hum, nah, a small offset is generally
1337 cheaper than a wider memory access on MMIX.) */
1339 = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
1340 size_int ((BITS_PER_WORD / BITS_PER_UNIT)
1341 - GET_MODE_UNIT_SIZE (TYPE_MODE (type))));
1343 else if (!integer_zerop (rounded_size))
1345 if (!really_constant_p (type_size))
1346 /* Varying-size types come in by reference. */
1348 = build1 (INDIRECT_REF, build_pointer_type (type), addr_tree);
1351 /* If the size is less than a register, then we need to pad the
1352 address by adding the difference. */
1354 = fold (build (COND_EXPR, sizetype,
1355 fold (build (GT_EXPR, sizetype,
1359 fold (build (MINUS_EXPR, sizetype,
1363 = fold (build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
1366 /* If this type is larger than what fits in a register, then it
1367 is passed by reference. */
1369 = fold (build (COND_EXPR, TREE_TYPE (addr_tree1),
1370 fold (build (GT_EXPR, sizetype,
1373 build1 (INDIRECT_REF, build_pointer_type (type),
1379 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
1380 addr = copy_to_reg (addr);
1382 if (!integer_zerop (rounded_size))
1384 /* Compute new value for AP. For MMIX, it is always advanced by the
1385 size of a register. */
1386 tree t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
1387 build (PLUS_EXPR, TREE_TYPE (valist), valist,
1389 TREE_SIDE_EFFECTS (t) = 1;
1390 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1396 /* TRAMPOLINE_SIZE. */
1397 /* Four 4-byte insns plus two 8-byte values. */
1398 int mmix_trampoline_size = 32;
1401 /* TRAMPOLINE_TEMPLATE. */
1404 mmix_trampoline_template (stream)
1407 /* Read a value into the static-chain register and jump somewhere. The
1408 static chain is stored at offset 16, and the function address is
1409 stored at offset 24. */
1410 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
1411 register size (octa). */
1412 fprintf (stream, "\tGETA $255,1F\n\t");
1413 fprintf (stream, "LDOU %s,$255,0\n\t",
1414 reg_names[MMIX_STATIC_CHAIN_REGNUM]);
1415 fprintf (stream, "LDOU $255,$255,8\n\t");
1416 fprintf (stream, "GO $255,$255,0\n");
1417 fprintf (stream, "1H\tOCTA 0\n\t");
1418 fprintf (stream, "OCTA 0\n");
1421 /* INITIALIZE_TRAMPOLINE. */
1422 /* Set the static chain and function pointer field in the trampoline.
1423 We also SYNCID here to be sure (doesn't matter in the simulator, but
1424 some day it will). */
1427 mmix_initialize_trampoline (trampaddr, fnaddr, static_chain)
1432 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)),
1434 emit_move_insn (gen_rtx_MEM (DImode,
1435 plus_constant (trampaddr, 24)),
1437 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode,
1439 GEN_INT (mmix_trampoline_size - 1)));
1442 /* We must exclude constant addresses that have an increment that is not a
1443 multiple of four bytes because of restrictions of the GETA
1444 instruction, unless TARGET_BASE_ADDRESSES. */
1447 mmix_constant_address_p (x)
1450 RTX_CODE code = GET_CODE (x);
1452 /* When using "base addresses", anything constant goes. */
1453 int constant_ok = TARGET_BASE_ADDRESSES != 0;
1455 if (code == LABEL_REF || code == SYMBOL_REF)
1458 if (code == CONSTANT_P_RTX || code == HIGH)
1459 /* FIXME: Don't know how to dissect these. Avoid them for now. */
1468 case CONSTANT_P_RTX:
1470 /* FIXME: Don't know how to dissect these. Avoid them for now,
1471 except we know they're constants. */
1475 addend = INTVAL (x);
1479 if (GET_MODE (x) != VOIDmode)
1480 /* Strange that we got here. FIXME: Check if we do. */
1482 addend = CONST_DOUBLE_LOW (x);
1486 /* Note that expressions with arithmetic on forward references don't
1487 work in mmixal. People using gcc assembly code with mmixal might
1488 need to move arrays and such to before the point of use. */
1489 if (GET_CODE (XEXP (x, 0)) == PLUS)
1491 rtx x0 = XEXP (XEXP (x, 0), 0);
1492 rtx x1 = XEXP (XEXP (x, 0), 1);
1494 if ((GET_CODE (x0) == SYMBOL_REF
1495 || GET_CODE (x0) == LABEL_REF)
1496 && (GET_CODE (x1) == CONST_INT
1497 || (GET_CODE (x1) == CONST_DOUBLE
1498 && GET_MODE (x1) == VOIDmode)))
1499 addend = mmix_intval (x1);
1511 return constant_ok || (addend & 3) == 0;
1514 /* Return 1 if the address is OK, otherwise 0.
1515 Used by GO_IF_LEGITIMATE_ADDRESS. */
1518 mmix_legitimate_address (mode, x, strict_checking)
1519 enum machine_mode mode ATTRIBUTE_UNUSED;
1521 int strict_checking;
1523 #define MMIX_REG_OK(X) \
1525 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1526 || (reg_renumber[REGNO (X)] > 0 \
1527 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1528 || (!strict_checking \
1529 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1530 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1531 || REGNO (X) == ARG_POINTER_REGNUM)))
1535 (mem (plus reg reg))
1536 (mem (plus reg 0..255)).
1537 unless TARGET_BASE_ADDRESSES, in which case we accept all
1538 (mem constant_address) too. */
1542 if (REG_P (x) && MMIX_REG_OK (x))
1545 if (GET_CODE(x) == PLUS)
1547 rtx x1 = XEXP (x, 0);
1548 rtx x2 = XEXP (x, 1);
1550 /* Try swapping the order. FIXME: Do we need this? */
1558 /* (mem (plus (reg?) (?))) */
1559 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1560 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1562 /* (mem (plus (reg) (reg?))) */
1563 if (REG_P (x2) && MMIX_REG_OK (x2))
1566 /* (mem (plus (reg) (0..255?))) */
1567 if (GET_CODE (x2) == CONST_INT
1568 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1574 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1577 /* LEGITIMATE_CONSTANT_P. */
1580 mmix_legitimate_constant_p (x)
1583 RTX_CODE code = GET_CODE (x);
1585 /* We must allow any number due to the way the cse passes works; if we
1586 do not allow any number here, general_operand will fail, and insns
1587 will fatally fail recognition instead of "softly". */
1588 if (code == CONST_INT || code == CONST_DOUBLE)
1591 return CONSTANT_ADDRESS_P (x);
1594 /* SELECT_CC_MODE. */
1597 mmix_select_cc_mode (op, x, y)
1600 rtx y ATTRIBUTE_UNUSED;
1602 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1603 output different compare insns. Note that we do not check the
1604 validity of the comparison here. */
1606 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1608 if (op == ORDERED || op == UNORDERED || op == UNGE
1609 || op == UNGT || op == UNLE || op == UNLT)
1612 if (op == EQ || op == NE)
1618 if (op == GTU || op == LTU || op == GEU || op == LEU)
1624 /* CANONICALIZE_COMPARISON.
1625 FIXME: Check if the number adjustments trig. */
1628 mmix_canonicalize_comparison (codep, op0p, op1p)
1630 rtx * op0p ATTRIBUTE_UNUSED;
1633 /* Change -1 to zero, if possible. */
1634 if ((*codep == LE || *codep == GT)
1635 && GET_CODE (*op1p) == CONST_INT
1636 && *op1p == constm1_rtx)
1638 *codep = *codep == LE ? LT : GE;
1642 /* Fix up 256 to 255, if possible. */
1643 if ((*codep == LT || *codep == LTU || *codep == GE || *codep == GEU)
1644 && GET_CODE (*op1p) == CONST_INT
1645 && INTVAL (*op1p) == 256)
1647 /* FIXME: Remove when I know this trigs. */
1648 fatal_insn ("oops, not debugged; fixing up value:", *op1p);
1649 *codep = *codep == LT ? LE : *codep == LTU ? LEU : *codep
1651 *op1p = GEN_INT (255);
1655 /* REVERSIBLE_CC_MODE. */
1658 mmix_reversible_cc_mode (mode)
1659 enum machine_mode mode;
1661 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1663 return mode != CC_FPmode;
1666 /* DEFAULT_RTX_COSTS. */
1669 mmix_rtx_cost_recalculated (x, code, outer_code, costp)
1670 rtx x ATTRIBUTE_UNUSED;
1671 RTX_CODE code ATTRIBUTE_UNUSED;
1672 RTX_CODE outer_code ATTRIBUTE_UNUSED;
1673 int *costp ATTRIBUTE_UNUSED;
1675 /* For the time being, this is just a stub and we'll accept the
1676 generic calculations, until we can do measurements, at least.
1677 Say we did not modify any calculated costs. */
1684 mmix_address_cost (addr)
1685 rtx addr ATTRIBUTE_UNUSED;
1687 /* There's no difference in the address costs and we have lots of
1688 registers. Some targets use constant 0, many others use 1 to say
1689 this. Let's start with 1. */
1693 /* REGISTER_MOVE_COST. */
1696 mmix_register_move_cost (mode, from, to)
1697 enum machine_mode mode ATTRIBUTE_UNUSED;
1698 enum reg_class from;
1701 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1704 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1705 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1708 /* DATA_SECTION_ASM_OP. */
1711 mmix_data_section_asm_op ()
1713 return "\t.data ! mmixal:= 8H LOC 9B";
1716 /* ENCODE_SECTION_INFO. */
1719 mmix_encode_section_info (decl, first)
1723 /* Test for an external declaration, and do nothing if it is one. */
1724 if ((TREE_CODE (decl) == VAR_DECL
1725 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1726 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1728 else if (first && DECL_P (decl))
1730 /* For non-visible declarations, add a "@" prefix, which we skip
1731 when the label is output. If the label does not have this
1732 prefix, a ":" is output if -mtoplevel-symbols.
1734 Note that this does not work for data that is declared extern and
1735 later defined as static. If there's code in between, that code
1736 will refer to the extern declaration, and vice versa. This just
1737 means that when -mtoplevel-symbols is in use, we can just handle
1738 well-behaved ISO-compliant code. */
1740 const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1741 int len = strlen (str);
1744 /* Why is the return type of ggc_alloc_string const? */
1745 newstr = (char *) ggc_alloc_string ("", len + 1);
1747 strcpy (newstr + 1, str);
1749 XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
1752 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1753 may need different options to reach for different things with GETA.
1754 For now, functions and things we know or have been told are constant. */
1755 if (TREE_CODE (decl) == FUNCTION_DECL
1756 || TREE_CONSTANT (decl)
1757 || (TREE_CODE (decl) == VAR_DECL
1758 && TREE_READONLY (decl)
1759 && !TREE_SIDE_EFFECTS (decl)
1760 && (!DECL_INITIAL (decl)
1761 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1763 rtx rtl = (TREE_CODE_CLASS (TREE_CODE (decl)) != 'd'
1764 ? TREE_CST_RTL (decl) : DECL_RTL (decl));
1765 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1769 /* STRIP_NAME_ENCODING. */
1772 mmix_strip_name_encoding (name)
1775 for (; (*name == '@' || *name == '*'); name++)
1781 /* ASM_FILE_START. */
1784 mmix_asm_file_start (stream)
1787 /* We just emit a little comment for the time being. FIXME: Perhaps add
1788 -mstandalone and some segment and prefix setup here. */
1789 ASM_OUTPUT_SOURCE_FILENAME (stream, main_input_filename);
1791 fprintf (stream, "! mmixal:= 8H LOC Data_Section\n");
1793 /* Make sure each file starts with the text section. */
1800 mmix_asm_file_end (stream)
1801 FILE * stream ATTRIBUTE_UNUSED;
1803 /* Make sure each file ends with the data section. */
1807 /* ASM_OUTPUT_SOURCE_FILENAME. */
1810 mmix_asm_output_source_filename (stream, name)
1814 fprintf (stream, "# 1 ");
1815 OUTPUT_QUOTED_STRING (stream, name);
1816 fprintf (stream, "\n");
1819 /* OUTPUT_QUOTED_STRING. */
1822 mmix_output_quoted_string (stream, string, length)
1824 const char * string;
1827 const char * string_end = string + length;
1828 static const char *const unwanted_chars = "\"[]\\";
1830 /* Output "any character except newline and double quote character". We
1831 play it safe and avoid all control characters too. We also do not
1832 want [] as characters, should input be passed through m4 with [] as
1833 quotes. Further, we avoid "\", because the GAS port handles it as a
1834 quoting character. */
1835 while (string < string_end)
1838 && (unsigned char) *string < 128
1839 && !ISCNTRL (*string)
1840 && strchr (unwanted_chars, *string) == NULL)
1842 fputc ('"', stream);
1844 && (unsigned char) *string < 128
1845 && !ISCNTRL (*string)
1846 && strchr (unwanted_chars, *string) == NULL
1847 && string < string_end)
1849 fputc (*string, stream);
1852 fputc ('"', stream);
1853 if (string < string_end)
1854 fprintf (stream, ",");
1856 if (string < string_end)
1858 fprintf (stream, "#%x", *string & 255);
1860 if (string < string_end)
1861 fprintf (stream, ",");
1866 /* ASM_OUTPUT_SOURCE_LINE. */
1869 mmix_asm_output_source_line (stream, lineno)
1873 fprintf (stream, "# %d ", lineno);
1874 OUTPUT_QUOTED_STRING (stream, main_input_filename);
1875 fprintf (stream, "\n");
1878 /* Target hook for assembling integer objects. Use mmix_print_operand
1879 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1883 mmix_assemble_integer (x, size, aligned_p)
1891 /* We handle a limited number of types of operands in here. But
1892 that's ok, because we can punt to generic functions. We then
1893 pretend that aligned data isn't needed, so the usual .<pseudo>
1894 syntax is used (which works for aligned data too). We actually
1895 *must* do that, since we say we don't have simple aligned
1896 pseudos, causing this function to be called. We just try and
1897 keep as much compatibility as possible with mmixal syntax for
1898 normal cases (i.e. without GNU extensions and C only). */
1900 if (GET_CODE (x) != CONST_INT)
1905 fputs ("\tBYTE\t", asm_out_file);
1906 mmix_print_operand (asm_out_file, x, 'B');
1907 fputc ('\n', asm_out_file);
1911 if (GET_CODE (x) != CONST_INT)
1916 fputs ("\tWYDE\t", asm_out_file);
1917 mmix_print_operand (asm_out_file, x, 'W');
1918 fputc ('\n', asm_out_file);
1922 if (GET_CODE (x) != CONST_INT)
1927 fputs ("\tTETRA\t", asm_out_file);
1928 mmix_print_operand (asm_out_file, x, 'L');
1929 fputc ('\n', asm_out_file);
1933 if (GET_CODE (x) == CONST_DOUBLE)
1934 /* We don't get here anymore for CONST_DOUBLE, because DImode
1935 isn't expressed as CONST_DOUBLE, and DFmode is handled
1938 assemble_integer_with_op ("\tOCTA\t", x);
1941 return default_assemble_integer (x, size, aligned_p);
1944 /* ASM_OUTPUT_ASCII. */
1947 mmix_asm_output_ascii (stream, string, length)
1954 int chunk_size = length > 60 ? 60 : length;
1955 fprintf (stream, "\tBYTE ");
1956 mmix_output_quoted_string (stream, string, chunk_size);
1957 string += chunk_size;
1958 length -= chunk_size;
1959 fprintf (stream, "\n");
1963 /* ASM_OUTPUT_ALIGNED_COMMON. */
1966 mmix_asm_output_aligned_common (stream, name, size, align)
1972 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1973 express this in a mmixal-compatible way. */
1974 fprintf (stream, "\t.comm\t");
1975 assemble_name (stream, name);
1976 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1977 size, align / BITS_PER_UNIT);
1980 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1983 mmix_asm_output_aligned_local (stream, name, size, align)
1991 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1992 assemble_name (stream, name);
1993 fprintf (stream, "\tLOC @+%d\n", size);
1996 /* ASM_OUTPUT_LABEL. */
1999 mmix_asm_output_label (stream, name)
2003 assemble_name (stream, name);
2004 fprintf (stream, "\tIS @\n");
2007 /* ASM_DECLARE_REGISTER_GLOBAL. */
2010 mmix_asm_declare_register_global (stream, decl, regno, name)
2011 FILE *stream ATTRIBUTE_UNUSED;
2012 tree decl ATTRIBUTE_UNUSED;
2013 int regno ATTRIBUTE_UNUSED;
2014 const char *name ATTRIBUTE_UNUSED;
2016 /* Nothing to do here, but there *will* be, therefore the framework is
2020 /* ASM_GLOBALIZE_LABEL. */
2023 mmix_asm_globalize_label (stream, name)
2024 FILE * stream ATTRIBUTE_UNUSED;
2025 const char * name ATTRIBUTE_UNUSED;
2027 asm_fprintf (stream, "\t.global ");
2028 assemble_name (stream, name);
2029 putc ('\n', stream);
2032 /* ASM_WEAKEN_LABEL. */
2035 mmix_asm_weaken_label (stream, name)
2036 FILE * stream ATTRIBUTE_UNUSED;
2037 const char * name ATTRIBUTE_UNUSED;
2039 asm_fprintf (stream, "\t.weak ");
2040 assemble_name (stream, name);
2041 asm_fprintf (stream, " ! mmixal-incompatible\n");
2044 /* MAKE_DECL_ONE_ONLY. */
2047 mmix_make_decl_one_only (decl)
2050 DECL_WEAK (decl) = 1;
2053 /* ASM_OUTPUT_LABELREF.
2054 Strip GCC's '*' and our own '@'. No order is assumed. */
2057 mmix_asm_output_labelref (stream, name)
2063 for (; (*name == '@' || *name == '*'); name++)
2067 asm_fprintf (stream, "%s%U%s",
2068 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
2072 /* ASM_OUTPUT_INTERNAL_LABEL. */
2075 mmix_asm_output_internal_label (stream, name, num)
2080 fprintf (stream, "%s:%d\tIS @\n", name, num);
2083 /* ASM_OUTPUT_DEF. */
2086 mmix_asm_output_def (stream, name, value)
2091 assemble_name (stream, name);
2092 fprintf (stream, "\tIS ");
2093 assemble_name (stream, value);
2094 fputc ('\n', stream);
2097 /* ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL. */
2100 mmix_asm_output_define_label_difference_symbol (stream, symbol, hi, lo)
2106 assemble_name (stream, symbol);
2107 fprintf (stream, "\tIS\t");
2108 assemble_name (stream, hi);
2109 fputc ('-', stream);
2110 assemble_name (stream, lo);
2111 fprintf (stream, "\n");
2114 /* PRINT_OPERAND. */
2117 mmix_print_operand (stream, x, code)
2122 /* When we add support for different codes later, we can, when needed,
2123 drop through to the main handler with a modified operand. */
2125 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
2129 /* Unrelated codes are in alphabetic order. */
2132 /* For conditional branches, output "P" for a probable branch. */
2133 if (TARGET_BRANCH_PREDICT)
2135 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
2136 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
2142 if (GET_CODE (x) != CONST_INT)
2143 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
2144 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
2148 /* Highpart. Must be general register, and not the last one, as
2149 that one cannot be part of a consecutive register pair. */
2150 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
2151 internal_error ("MMIX Internal: Bad register: %d", regno);
2153 /* This is big-endian, so the high-part is the first one. */
2154 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
2158 /* Lowpart. Must be CONST_INT or general register, and not the last
2159 one, as that one cannot be part of a consecutive register pair. */
2160 if (GET_CODE (x) == CONST_INT)
2162 fprintf (stream, "#%lx",
2163 (unsigned long) (INTVAL (x)
2164 & ((unsigned int) 0x7fffffff * 2 + 1)));
2168 if (GET_CODE (x) == SYMBOL_REF)
2170 output_addr_const (stream, x);
2174 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
2175 internal_error ("MMIX Internal: Bad register: %d", regno);
2177 /* This is big-endian, so the low-part is + 1. */
2178 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
2181 /* Can't use 'a' because that's a generic modifier for address
2184 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
2185 ~(unsigned HOST_WIDEST_INT)
2190 mmix_output_shiftvalue_op_from_str (stream, "INC",
2191 (unsigned HOST_WIDEST_INT)
2196 mmix_output_shiftvalue_op_from_str (stream, "OR",
2197 (unsigned HOST_WIDEST_INT)
2202 mmix_output_shiftvalue_op_from_str (stream, "SET",
2203 (unsigned HOST_WIDEST_INT)
2209 mmix_output_condition (stream, x, (code == 'D'));
2213 /* Output an extra "e" to make fcmpe, fune. */
2214 if (TARGET_FCMP_EPSILON)
2215 fprintf (stream, "e");
2219 /* Output the number minus 1. */
2220 if (GET_CODE (x) != CONST_INT)
2222 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
2225 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
2226 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
2230 /* Store the number of registers we want to save. This was setup
2231 by the prologue. The actual operand contains the number of
2232 registers to pass, but we don't use it currently. Anyway, we
2233 need to output the number of saved registers here. */
2234 fprintf (stream, "%d",
2235 cfun->machine->highest_saved_stack_register + 1);
2239 /* Store the register to output a constant to. */
2241 fatal_insn ("MMIX Internal: Expected a register, not this", x);
2242 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
2246 /* Output the constant. Note that we use this for floats as well. */
2247 if (GET_CODE (x) != CONST_INT
2248 && (GET_CODE (x) != CONST_DOUBLE
2249 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
2250 && GET_MODE (x) != SFmode)))
2251 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
2252 mmix_output_register_setting (stream,
2253 mmix_output_destination_register,
2254 mmix_intval (x), 0);
2258 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
2259 if (TARGET_ZERO_EXTEND)
2264 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
2268 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
2272 if (GET_CODE (x) != CONST_INT)
2273 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
2274 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
2278 /* Nothing to do. */
2282 /* Presumably there's a missing case above if we get here. */
2283 internal_error ("MMIX Internal: Missing `%c' case in mmix_print_operand", code);
2286 switch (GET_CODE (modified_x))
2289 regno = REGNO (modified_x);
2290 if (regno >= FIRST_PSEUDO_REGISTER)
2291 internal_error ("MMIX Internal: Bad register: %d", regno);
2292 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
2296 output_address (XEXP (modified_x, 0));
2300 /* For -2147483648, mmixal complains that the constant does not fit
2301 in 4 bytes, so let's output it as hex. Take care to handle hosts
2302 where HOST_WIDE_INT is longer than an int.
2304 Print small constants +-255 using decimal. */
2306 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
2307 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
2309 fprintf (stream, "#%x",
2310 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
2314 /* Do somewhat as CONST_INT. */
2315 mmix_output_octa (stream, mmix_intval (modified_x), 0);
2319 output_addr_const (stream, modified_x);
2323 /* No need to test for all strange things. Let output_addr_const do
2325 if (CONSTANT_P (modified_x)
2326 /* Strangely enough, this is not included in CONSTANT_P.
2327 FIXME: Ask/check about sanity here. */
2328 || GET_CODE (modified_x) == CODE_LABEL)
2330 output_addr_const (stream, modified_x);
2334 /* We need the original here. */
2335 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
2339 /* PRINT_OPERAND_PUNCT_VALID_P. */
2342 mmix_print_operand_punct_valid_p (code)
2343 int code ATTRIBUTE_UNUSED;
2345 /* A '+' is used for branch prediction, similar to other ports. */
2349 /* PRINT_OPERAND_ADDRESS. */
2352 mmix_print_operand_address (stream, x)
2358 /* I find the generated assembly code harder to read without
2360 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
2363 else if (GET_CODE (x) == PLUS)
2365 rtx x1 = XEXP (x, 0);
2366 rtx x2 = XEXP (x, 1);
2368 /* Try swap the order. FIXME: Do we need this? */
2378 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
2382 fprintf (stream, "%s",
2383 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
2386 else if (GET_CODE (x2) == CONST_INT
2387 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
2389 output_addr_const (stream, x2);
2395 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (x))
2397 output_addr_const (stream, x);
2401 fatal_insn ("MMIX Internal: This is not a recognized address", x);
2404 /* ASM_OUTPUT_REG_PUSH. */
2407 mmix_asm_output_reg_push (stream, regno)
2411 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
2412 reg_names[MMIX_STACK_POINTER_REGNUM],
2413 reg_names[MMIX_STACK_POINTER_REGNUM],
2414 reg_names[MMIX_OUTPUT_REGNO (regno)],
2415 reg_names[MMIX_STACK_POINTER_REGNUM]);
2418 /* ASM_OUTPUT_REG_POP. */
2421 mmix_asm_output_reg_pop (stream, regno)
2425 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
2426 reg_names[MMIX_OUTPUT_REGNO (regno)],
2427 reg_names[MMIX_STACK_POINTER_REGNUM],
2428 reg_names[MMIX_STACK_POINTER_REGNUM]);
2431 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
2434 mmix_asm_output_addr_diff_elt (stream, body, value, rel)
2436 rtx body ATTRIBUTE_UNUSED;
2440 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
2443 /* ASM_OUTPUT_ADDR_VEC_ELT. */
2446 mmix_asm_output_addr_vec_elt (stream, value)
2450 fprintf (stream, "\tOCTA L:%d\n", value);
2453 /* ASM_OUTPUT_SKIP. */
2456 mmix_asm_output_skip (stream, nbytes)
2460 fprintf (stream, "\tLOC @+%d\n", nbytes);
2463 /* ASM_OUTPUT_ALIGN. */
2466 mmix_asm_output_align (stream, power)
2470 /* We need to record the needed alignment of this section in the object,
2471 so we have to output an alignment directive. Use a .p2align (not
2472 .align) so people will never have to wonder about whether the
2473 argument is in number of bytes or the log2 thereof. We do it in
2474 addition to the LOC directive, so nothing needs tweaking when
2475 copy-pasting assembly into mmixal. */
2476 fprintf (stream, "\t.p2align %d\n", power);
2477 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
2480 /* DBX_REGISTER_NUMBER. */
2483 mmix_dbx_register_number (regno)
2486 /* Adjust the register number to the one it will be output as, dammit.
2487 It'd be nice if we could check the assumption that we're filling a
2488 gap, but every register between the last saved register and parameter
2489 registers might be a valid parameter register. */
2490 regno = MMIX_OUTPUT_REGNO (regno);
2492 /* We need to renumber registers to get the number of the return address
2493 register in the range 0..255. It is also space-saving if registers
2494 mentioned in the call-frame information (which uses this function by
2495 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
2496 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
2497 return regno >= 224 ? (regno - 224) : (regno + 48);
2500 /* End of target macro support functions.
2502 Now MMIX's own functions. First the exported ones. */
2504 /* Output an optimal sequence for setting a register to a specific
2505 constant. Used in an alternative for const_ints in movdi, and when
2506 using large stack-frame offsets.
2508 Use do_begin_end to say if a line-starting TAB and newline before the
2509 first insn and after the last insn is wanted. */
2512 mmix_output_register_setting (stream, regno, value, do_begin_end)
2515 HOST_WIDEST_INT value;
2519 fprintf (stream, "\t");
2521 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2523 /* First, the one-insn cases. */
2524 mmix_output_shiftvalue_op_from_str (stream, "SET",
2525 (unsigned HOST_WIDEST_INT)
2527 fprintf (stream, " %s,", reg_names[regno]);
2528 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2530 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2532 /* We do this to get a bit more legible assembly code. The next
2533 alternative is mostly redundant with this. */
2535 mmix_output_shiftvalue_op_from_str (stream, "SET",
2536 -(unsigned HOST_WIDEST_INT)
2538 fprintf (stream, " %s,", reg_names[regno]);
2539 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2540 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2543 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2545 /* Slightly more expensive, the two-insn cases. */
2547 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2548 is shiftable, or any other one-insn transformation of the value.
2549 FIXME: Check first if the value is "shiftable" by two loading
2550 with two insns, since it makes more readable assembly code (if
2551 anyone else cares). */
2553 mmix_output_shiftvalue_op_from_str (stream, "SET",
2554 ~(unsigned HOST_WIDEST_INT)
2556 fprintf (stream, " %s,", reg_names[regno]);
2557 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2558 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2563 /* The generic case. 2..4 insns. */
2564 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2565 const char *op = "SET";
2566 const char *line_begin = "";
2569 HOST_WIDEST_INT tmpvalue = value;
2571 /* Compute the number of insns needed to output this constant. */
2572 for (i = 0; i < 4 && tmpvalue != 0; i++)
2574 if (tmpvalue & 65535)
2578 if (TARGET_BASE_ADDRESSES && insns == 3)
2580 /* The number three is based on a static observation on
2581 ghostscript-6.52. Two and four are excluded because there
2582 are too many such constants, and each unique constant (maybe
2583 offset by 1..255) were used few times compared to other uses,
2586 We use base-plus-offset addressing to force it into a global
2587 register; we just use a "LDA reg,VALUE", which will cause the
2588 assembler and linker to DTRT (for constants as well as
2590 fprintf (stream, "LDA %s,", reg_names[regno]);
2591 mmix_output_octa (stream, value, 0);
2595 /* Output pertinent parts of the 4-wyde sequence.
2596 Still more to do if we want this to be optimal, but hey...
2597 Note that the zero case has been handled above. */
2598 for (i = 0; i < 4 && value != 0; i++)
2602 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2603 higher_parts[i], reg_names[regno],
2604 (int) (value & 65535));
2605 /* The first one sets the rest of the bits to 0, the next
2606 ones add set bits. */
2608 line_begin = "\n\t";
2617 fprintf (stream, "\n");
2620 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2624 mmix_shiftable_wyde_value (value)
2625 unsigned HOST_WIDEST_INT value;
2627 /* Shift by 16 bits per group, stop when we've found two groups with
2630 int has_candidate = 0;
2632 for (i = 0; i < 4; i++)
2648 /* True if this is an address_operand or a symbolic operand. */
2651 mmix_symbolic_or_address_operand (op, mode)
2653 enum machine_mode mode;
2655 switch (GET_CODE (op))
2662 if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2663 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
2664 && (GET_CODE (XEXP (op, 1)) == CONST_INT
2665 || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE
2666 && GET_MODE (XEXP (op, 1)) == VOIDmode)))
2670 return address_operand (op, mode);
2674 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2675 We could narrow the value down with a couple of predicated, but that
2676 doesn't seem to be worth it at the moment. */
2679 mmix_reg_or_constant_operand (op, mode)
2681 enum machine_mode mode;
2683 return register_operand (op, mode)
2684 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
2685 || GET_CODE (op) == CONST_INT;
2688 /* True if this is a register with a condition-code mode. */
2691 mmix_reg_cc_operand (op, mode)
2693 enum machine_mode mode;
2695 if (mode == VOIDmode)
2696 mode = GET_MODE (op);
2698 return register_operand (op, mode)
2699 && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode
2700 || mode == CC_FPEQmode || mode == CC_FUNmode);
2703 /* True if this is a foldable comparison operator
2704 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2705 replaced by (reg). */
2708 mmix_foldable_comparison_operator (op, mode)
2710 enum machine_mode mode;
2712 RTX_CODE code = GET_CODE (op);
2714 if (mode == VOIDmode)
2715 mode = GET_MODE (op);
2717 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2718 mode = GET_MODE (XEXP (op, 0));
2720 return ((mode == CCmode || mode == DImode)
2721 && (code == NE || code == EQ || code == GE || code == GT
2723 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2724 reverse the condition? Can it do that by itself? Maybe it can
2725 even reverse the condition to fit a foldable one in the first
2727 || (mode == CC_UNSmode && (code == GTU || code == LEU));
2730 /* Like comparison_operator, but only true if this comparison operator is
2731 applied to a valid mode. Needed to avoid jump.c generating invalid
2732 code with -ffast-math (gcc.dg/20001228-1.c). */
2735 mmix_comparison_operator (op, mode)
2737 enum machine_mode mode;
2739 RTX_CODE code = GET_CODE (op);
2741 /* Comparison operators usually don't have a mode, but let's try and get
2742 one anyway for the day that changes. */
2743 if (mode == VOIDmode)
2744 mode = GET_MODE (op);
2746 /* Get the mode from the first operand if we don't have one. */
2747 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2748 mode = GET_MODE (XEXP (op, 0));
2750 /* FIXME: This needs to be kept in sync with the tables in
2751 mmix_output_condition. */
2753 (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2754 || (mode == CC_FUNmode
2755 && (code == ORDERED || code == UNORDERED))
2756 || (mode == CC_FPmode
2757 && (code == GT || code == LT))
2758 || (mode == CC_FPEQmode
2759 && (code == NE || code == EQ))
2760 || (mode == CC_UNSmode
2761 && (code == GEU || code == GTU || code == LEU || code == LTU))
2763 && (code == NE || code == EQ || code == GE || code == GT
2764 || code == LE || code == LT))
2766 && (code == NE || code == EQ || code == GE || code == GT
2767 || code == LE || code == LT || code == LEU || code == GTU));
2770 /* True if this is a register or 0 (int or float). */
2773 mmix_reg_or_0_operand (op, mode)
2775 enum machine_mode mode;
2777 /* FIXME: Is mode calculation necessary and correct? */
2779 op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode)
2780 || register_operand (op, mode);
2783 /* True if this is a register or an int 0..255. */
2786 mmix_reg_or_8bit_operand (op, mode)
2788 enum machine_mode mode;
2790 return register_operand (op, mode)
2791 || (GET_CODE (op) == CONST_INT
2792 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
2795 /* True if this is a register or an int 0..256. We include 256,
2796 because it can be canonicalized into 255 for comparisons, which is
2797 currently the only use of this predicate.
2798 FIXME: Check that this happens and does TRT. */
2801 mmix_reg_or_8bit_or_256_operand (op, mode)
2803 enum machine_mode mode;
2805 return mmix_reg_or_8bit_operand (op, mode)
2806 || (GET_CODE (op) == CONST_INT && INTVAL (op) == 256);
2809 /* Returns zero if code and mode is not a valid condition from a
2810 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2811 is the comparison of mode is CC-somethingmode. */
2814 mmix_valid_comparison (code, mode, op)
2816 enum machine_mode mode;
2819 if (mode == VOIDmode && op != NULL_RTX)
2820 mode = GET_MODE (op);
2822 /* We don't care to look at these, they should always be valid. */
2823 if (mode == CCmode || mode == CC_UNSmode || mode == DImode)
2826 if ((mode == CC_FPmode || mode == DFmode)
2827 && (code == GT || code == LT))
2830 if ((mode == CC_FPEQmode || mode == DFmode)
2831 && (code == EQ || code == NE))
2834 if ((mode == CC_FUNmode || mode == DFmode)
2835 && (code == ORDERED || code == UNORDERED))
2841 /* X and Y are two things to compare using CODE. Emit a compare insn if
2842 possible and return the rtx for the cc-reg in the proper mode, or
2843 NULL_RTX if this is not a valid comparison. */
2846 mmix_gen_compare_reg (code, x, y)
2850 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2853 /* FIXME: Do we get constants here? Of double mode? */
2854 enum machine_mode mode
2855 = GET_MODE (x) == VOIDmode
2857 : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode;
2859 if (! mmix_valid_comparison (code, mode, x))
2862 cc_reg = gen_reg_rtx (ccmode);
2864 /* FIXME: Can we avoid emitting a compare insn here? */
2865 if (! REG_P (x) && ! REG_P (y))
2866 x = force_reg (mode, x);
2868 CANONICALIZE_COMPARISON (code, x, y);
2870 /* If it's not quite right yet, put y in a register. */
2872 && (GET_CODE (y) != CONST_INT
2873 || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I')))
2874 y = force_reg (mode, y);
2876 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2877 gen_rtx_COMPARE (ccmode, x, y)));
2882 /* Local (static) helper functions. */
2884 /* Print operator suitable for doing something with a shiftable
2885 wyde. The type of operator is passed as an asm output modifier. */
2888 mmix_output_shiftvalue_op_from_str (stream, mainop, value)
2891 HOST_WIDEST_INT value;
2893 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2896 if (! mmix_shiftable_wyde_value (value))
2898 char s[sizeof ("0xffffffffffffffff")];
2899 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2900 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2903 for (i = 0; i < 4; i++)
2905 /* We know we're through when we find one-bits in the low
2909 fprintf (stream, "%s%s", mainop, op_part[i]);
2915 /* No bits set? Then it must have been zero. */
2916 fprintf (stream, "%sL", mainop);
2919 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2922 mmix_output_octa (stream, value, do_begin_end)
2924 HOST_WIDEST_INT value;
2927 /* Snipped from final.c:output_addr_const. We need to avoid the
2928 presumed universal "0x" prefix. We can do it by replacing "0x" with
2929 "#0" here; we must avoid a space in the operands and no, the zero
2930 won't cause the number to be assumed in octal format. */
2931 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2934 fprintf (stream, "\tOCTA ");
2936 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2937 hex_format[0] = '#';
2938 hex_format[1] = '0';
2940 /* Provide a few alternative output formats depending on the number, to
2941 improve legibility of assembler output. */
2942 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2943 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2944 fprintf (stream, "%d", (int) value);
2945 else if (value > (HOST_WIDEST_INT) 0
2946 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2947 fprintf (stream, "#%x", (unsigned int) value);
2949 fprintf (stream, hex_format, value);
2952 fprintf (stream, "\n");
2955 /* Print the presumed shiftable wyde argument shifted into place (to
2956 be output with an operand). */
2959 mmix_output_shifted_value (stream, value)
2961 HOST_WIDEST_INT value;
2965 if (! mmix_shiftable_wyde_value (value))
2968 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2969 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2972 for (i = 0; i < 4; i++)
2974 /* We know we're through when we find one-bits in the low 16 bits. */
2977 fprintf (stream, "#%x", (int) (value & 0xffff));
2984 /* No bits set? Then it must have been zero. */
2985 fprintf (stream, "0");
2988 /* Output an MMIX condition name corresponding to an operator
2990 (comparison_operator [(comparison_operator ...) (const_int 0)])
2991 which means we have to look at *two* operators.
2993 The argument "reversed" refers to reversal of the condition (not the
2994 same as swapping the arguments). */
2997 mmix_output_condition (stream, x, reversed)
3006 /* The normal output cc-code. */
3007 const char *const normal;
3009 /* The reversed cc-code, or NULL if invalid. */
3010 const char *const reversed;
3015 enum machine_mode cc_mode;
3017 /* Terminated with {NIL, NULL, NULL} */
3018 const struct cc_conv *const convs;
3022 #define CCEND {NIL, NULL, NULL}
3024 static const struct cc_conv cc_fun_convs[]
3025 = {{ORDERED, "Z", "P"},
3026 {UNORDERED, "P", "Z"},
3028 static const struct cc_conv cc_fp_convs[]
3032 static const struct cc_conv cc_fpeq_convs[]
3036 static const struct cc_conv cc_uns_convs[]
3037 = {{GEU, "NN", "N"},
3042 static const struct cc_conv cc_signed_convs[]
3050 static const struct cc_conv cc_di_convs[]
3062 static const struct cc_type_conv cc_convs[]
3063 = {{CC_FUNmode, cc_fun_convs},
3064 {CC_FPmode, cc_fp_convs},
3065 {CC_FPEQmode, cc_fpeq_convs},
3066 {CC_UNSmode, cc_uns_convs},
3067 {CCmode, cc_signed_convs},
3068 {DImode, cc_di_convs}};
3073 enum machine_mode mode = GET_MODE (XEXP (x, 0));
3074 RTX_CODE cc = GET_CODE (x);
3076 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
3078 if (mode == cc_convs[i].cc_mode)
3080 for (j = 0; cc_convs[i].convs[j].cc != NIL; j++)
3081 if (cc == cc_convs[i].convs[j].cc)
3084 = (reversed ? cc_convs[i].convs[j].reversed
3085 : cc_convs[i].convs[j].normal);
3087 if (mmix_cc == NULL)
3088 fatal_insn ("MMIX Internal: Trying to output invalidly\
3089 reversed condition:", x);
3091 fprintf (stream, "%s", mmix_cc);
3095 fatal_insn ("MMIX Internal: What's the CC of this?", x);
3099 fatal_insn ("MMIX Internal: What is the CC of this?", x);
3102 /* Return the bit-value for a const_int or const_double. */
3104 static HOST_WIDEST_INT
3108 unsigned HOST_WIDEST_INT retval;
3110 if (GET_CODE (x) == CONST_INT)
3113 /* We make a little song and dance because converting to long long in
3114 gcc-2.7.2 is broken. I still want people to be able to use it for
3115 cross-compilation to MMIX. */
3116 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
3118 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
3120 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
3122 retval |= CONST_DOUBLE_LOW (x) & 1;
3125 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
3126 << (HOST_BITS_PER_LONG);
3129 retval = CONST_DOUBLE_HIGH (x);
3134 if (GET_CODE (x) == CONST_DOUBLE)
3136 REAL_VALUE_TYPE value;
3138 /* FIXME: This macro is not in the manual but should be. */
3139 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
3141 if (GET_MODE (x) == DFmode)
3145 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
3147 if (sizeof (long) < sizeof (HOST_WIDEST_INT))
3149 retval = (unsigned long) bits[1] / 2;
3151 retval |= (unsigned long) bits[1] & 1;
3153 |= (unsigned HOST_WIDEST_INT) bits[0]
3154 << (sizeof (bits[0]) * 8);
3157 retval = (unsigned long) bits[1];
3161 else if (GET_MODE (x) == SFmode)
3164 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
3166 return (unsigned long) bits;
3170 fatal_insn ("MMIX Internal: This is not a constant:", x);
3175 * eval: (c-set-style "gnu")
3176 * indent-tabs-mode: t