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 /* The canonical saved comparison operands for non-cc0 machines, set in
66 the compare expander. */
70 /* We ignore some options with arguments. They are passed to the linker,
71 but also ends up here because they start with "-m". We tell the driver
72 to store them in a variable we don't inspect. */
73 const char *mmix_cc1_ignored_option;
75 /* Declarations of locals. */
77 /* This is used in the prologue for what number to pass in a PUSHJ or
79 static int mmix_highest_saved_stack_register;
81 /* Intermediate for insn output. */
82 static int mmix_output_destination_register;
84 static void mmix_output_shiftvalue_op_from_str
85 PARAMS ((FILE *, const char *, HOST_WIDEST_INT));
86 static void mmix_output_shifted_value PARAMS ((FILE *, HOST_WIDEST_INT));
87 static void mmix_output_condition PARAMS ((FILE *, rtx, int));
88 static HOST_WIDEST_INT mmix_intval PARAMS ((rtx));
89 static void mmix_output_octa PARAMS ((FILE *, HOST_WIDEST_INT, int));
90 static bool mmix_assemble_integer PARAMS ((rtx, unsigned int, int));
91 static void mmix_init_machine_status PARAMS ((struct function *));
93 extern void mmix_target_asm_function_prologue
94 PARAMS ((FILE *, HOST_WIDE_INT));
95 extern void mmix_target_asm_function_epilogue
96 PARAMS ((FILE *, HOST_WIDE_INT));
99 /* Target structure macros. Listed by node. See `Using and Porting GCC'
100 for a general description. */
102 /* Node: Function Entry */
104 #undef TARGET_ASM_BYTE_OP
105 #define TARGET_ASM_BYTE_OP NULL
106 #undef TARGET_ASM_ALIGNED_HI_OP
107 #define TARGET_ASM_ALIGNED_HI_OP NULL
108 #undef TARGET_ASM_ALIGNED_SI_OP
109 #define TARGET_ASM_ALIGNED_SI_OP NULL
110 #undef TARGET_ASM_ALIGNED_DI_OP
111 #define TARGET_ASM_ALIGNED_DI_OP NULL
112 #undef TARGET_ASM_INTEGER
113 #define TARGET_ASM_INTEGER mmix_assemble_integer
115 #undef TARGET_ASM_FUNCTION_PROLOGUE
116 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
118 #undef TARGET_ASM_FUNCTION_EPILOGUE
119 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
121 struct gcc_target targetm = TARGET_INITIALIZER;
123 /* Functions that are expansions for target macros.
124 See Target Macros in `Using and Porting GCC'. */
126 /* OVERRIDE_OPTIONS. */
129 mmix_override_options ()
131 /* Should we err or should we warn? Hmm. At least we must neutralize
132 it. For example the wrong kind of case-tables will be generated with
133 PIC; we use absolute address items for mmixal compatibility. FIXME:
134 They could be relative if we just elide them to after all pertinent
138 warning ("-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
142 /* All other targets add GC roots from their override_options function,
144 ggc_add_rtx_root (&mmix_compare_op0, 1);
145 ggc_add_rtx_root (&mmix_compare_op1, 1);
148 /* INIT_EXPANDERS. */
151 mmix_init_expanders ()
153 init_machine_status = mmix_init_machine_status;
156 /* Set the per-function data. */
159 mmix_init_machine_status (f)
162 f->machine = xcalloc (1, sizeof (struct machine_function));
166 We have trouble getting the address of stuff that is located at other
167 than 32-bit alignments (GETA requirements), so try to give everything
168 at least 32-bit alignment. */
171 mmix_data_alignment (type, basic_align)
172 tree type ATTRIBUTE_UNUSED;
175 if (basic_align < 32)
181 /* CONSTANT_ALIGNMENT. */
184 mmix_constant_alignment (constant, basic_align)
185 tree constant ATTRIBUTE_UNUSED;
188 if (basic_align < 32)
194 /* LOCAL_ALIGNMENT. */
197 mmix_local_alignment (type, basic_align)
198 tree type ATTRIBUTE_UNUSED;
201 if (basic_align < 32)
207 /* CONDITIONAL_REGISTER_USAGE. */
210 mmix_conditional_register_usage ()
216 static const int gnu_abi_reg_alloc_order[]
217 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
219 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
220 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
222 /* Change the default from the mmixware ABI. For the GNU ABI,
223 $15..$30 are call-saved just as $0..$14. There must be one
224 call-clobbered local register for the "hole" describing number of
225 saved local registers saved by PUSHJ/PUSHGO during the function
226 call, receiving the return value at return. So best is to use
227 the highest, $31. It's already marked call-clobbered for the
229 for (i = 15; i <= 30; i++)
230 call_used_regs[i] = 0;
233 /* Step over the ":" in special register names. */
234 if (! TARGET_TOPLEVEL_SYMBOLS)
235 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
236 if (reg_names[i][0] == ':')
240 /* PREFERRED_RELOAD_CLASS.
241 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
244 mmix_preferred_reload_class (x, class)
245 rtx x ATTRIBUTE_UNUSED;
246 enum reg_class class;
248 /* FIXME: Revisit. */
249 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
250 ? REMAINDER_REG : class;
253 /* PREFERRED_OUTPUT_RELOAD_CLASS.
254 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
257 mmix_preferred_output_reload_class (x, class)
258 rtx x ATTRIBUTE_UNUSED;
259 enum reg_class class;
261 /* FIXME: Revisit. */
262 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
263 ? REMAINDER_REG : class;
266 /* SECONDARY_RELOAD_CLASS.
267 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
270 mmix_secondary_reload_class (class, mode, x, in_p)
271 enum reg_class class;
272 enum machine_mode mode ATTRIBUTE_UNUSED;
273 rtx x ATTRIBUTE_UNUSED;
274 int in_p ATTRIBUTE_UNUSED;
276 if (class == REMAINDER_REG
277 || class == HIMULT_REG
278 || class == SYSTEM_REGS)
284 /* CONST_OK_FOR_LETTER_P. */
287 mmix_const_ok_for_letter_p (value, c)
292 (c == 'I' ? value >= 0 && value <= 255
293 : c == 'J' ? value >= 0 && value <= 65535
294 : c == 'K' ? value <= 0 && value >= -255
295 : c == 'L' ? mmix_shiftable_wyde_value (value)
296 : c == 'M' ? value == 0
297 : c == 'N' ? mmix_shiftable_wyde_value (~value)
298 : c == 'O' ? (value == 3 || value == 5 || value == 9
303 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
306 mmix_const_double_ok_for_letter_p (value, c)
311 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
316 We need this since our constants are not always expressible as
317 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
320 mmix_extra_constraint (x, c, strict)
325 HOST_WIDEST_INT value;
327 /* When checking for an address, we need to handle strict vs. non-strict
328 register checks. Don't use address_operand, but instead its
329 equivalent (its callee, which it is just a wrapper for),
330 memory_operand_p and the strict-equivalent strict_memory_address_p. */
334 ? strict_memory_address_p (Pmode, x)
335 : memory_address_p (Pmode, x);
337 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
340 value = mmix_intval (x);
342 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
343 more ('U' taken for address_operand). Some letters map outside of
344 CONST_INT, though; we still use 'S' and 'T'. */
346 return mmix_shiftable_wyde_value (value);
348 return mmix_shiftable_wyde_value (~value);
352 /* DYNAMIC_CHAIN_ADDRESS. */
355 mmix_dynamic_chain_address (frame)
358 /* FIXME: the frame-pointer is stored at offset -8 from the current
359 frame-pointer. Unfortunately, the caller assumes that a
360 frame-pointer is present for *all* previous frames. There should be
361 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
362 return plus_constant (frame, -8);
365 /* STARTING_FRAME_OFFSET. */
368 mmix_starting_frame_offset ()
370 /* The old frame pointer is in the slot below the new one, so
371 FIRST_PARM_OFFSET does not need to depend on whether the
372 frame-pointer is needed or not. We have to adjust for the register
373 stack pointer being located below the saved frame pointer.
374 Similarly, we store the return address on the stack too, for
375 exception handling, and always if we save the register stack pointer. */
378 + (MMIX_CFUN_HAS_LANDING_PAD
379 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
382 /* RETURN_ADDR_RTX. */
385 mmix_return_addr_rtx (count, frame)
387 rtx frame ATTRIBUTE_UNUSED;
390 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
391 /* FIXME: Set frame_alias_set on the following. */
392 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
393 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
397 /* SETUP_FRAME_ADDRESSES. */
400 mmix_setup_frame_addresses ()
402 /* Nothing needed at the moment. */
405 /* The difference between the (imaginary) frame pointer and the stack
406 pointer. Used to eliminate the frame pointer. */
409 mmix_initial_elimination_offset (fromreg, toreg)
415 = (get_frame_size () + current_function_outgoing_args_size + 7) & ~7;
417 /* There is no actual difference between these two. */
418 if (fromreg == MMIX_ARG_POINTER_REGNUM
419 && toreg == MMIX_FRAME_POINTER_REGNUM)
422 /* The difference is the size of local variables plus the size of
423 outgoing function arguments that would normally be passed as
424 registers but must be passed on stack because we're out of
425 function-argument registers. Only global saved registers are
426 counted; the others go on the register stack.
428 The frame-pointer is counted too if it is what is eliminated, as we
429 need to balance the offset for it from STARTING_FRAME_OFFSET.
431 Also add in the slot for the register stack pointer we save if we
434 Unfortunately, we can't access $0..$14, from unwinder code easily, so
435 store the return address in a frame slot too. FIXME: Only for
436 non-leaf functions. FIXME: Always with a landing pad, because it's
437 hard to know whether we need the other at the time we know we need
438 the offset for one (and have to state it). It's a kludge until we
439 can express the register stack in the EH frame info.
441 We have to do alignment here; get_frame_size will not return a
442 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
444 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
447 if ((regs_ever_live[regno] && ! call_used_regs[regno])
448 || IS_MMIX_EH_RETURN_DATA_REG (regno))
452 + (MMIX_CFUN_HAS_LANDING_PAD
453 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
454 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
457 /* Return an rtx for a function argument to go in a register, and 0 for
458 one that must go on stack. */
461 mmix_function_arg (argsp, mode, type, named, incoming)
462 const CUMULATIVE_ARGS * argsp;
463 enum machine_mode mode;
465 int named ATTRIBUTE_UNUSED;
468 /* Handling of the positional dummy parameter for varargs gets nasty.
469 Check execute/991216-3 and function.c:assign_params. We have to say
470 that the dummy parameter goes on stack in order to get the correct
471 offset when va_start and va_arg is applied. FIXME: Should do TRT by
472 itself in the gcc core. */
473 if ((! named && incoming && current_function_varargs) || argsp->now_varargs)
476 /* Last-argument marker. */
477 if (type == void_type_node)
478 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
481 ? MMIX_FIRST_INCOMING_ARG_REGNUM
482 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
485 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
486 && !MUST_PASS_IN_STACK (mode, type)
487 && (GET_MODE_BITSIZE (mode) <= 64
492 ? MMIX_FIRST_INCOMING_ARG_REGNUM
493 : MMIX_FIRST_ARG_REGNUM)
498 /* Returns nonzero for everything that goes by reference, 0 for
499 everything that goes by value. */
502 mmix_function_arg_pass_by_reference (argsp, mode, type, named)
503 const CUMULATIVE_ARGS * argsp;
504 enum machine_mode mode;
506 int named ATTRIBUTE_UNUSED;
508 /* FIXME: Check: I'm not sure the MUST_PASS_IN_STACK check is
511 MUST_PASS_IN_STACK (mode, type)
512 || (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
517 /* Return nonzero if regno is a register number where a parameter is
518 passed, and 0 otherwise. */
521 mmix_function_arg_regno_p (regno, incoming)
526 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
528 return regno >= first_arg_regnum
529 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
532 /* FUNCTION_OUTGOING_VALUE. */
535 mmix_function_outgoing_value (valtype, func)
537 tree func ATTRIBUTE_UNUSED;
539 enum machine_mode mode = TYPE_MODE (valtype);
540 enum machine_mode cmode;
541 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
542 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
546 /* Return values that fit in a register need no special handling.
547 There's no register hole when parameters are passed in global
550 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
552 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
554 /* A complex type, made up of components. */
555 cmode = TYPE_MODE (TREE_TYPE (valtype));
556 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
558 /* We need to take care of the effect of the register hole on return
559 values of large sizes; the last register will appear as the first
560 register, with the rest shifted. (For complex modes, this is just
561 swapped registers.) */
563 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
564 internal_error ("too large function value type, needs %d registers,\
565 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
567 /* FIXME: Maybe we should handle structure values like this too
568 (adjusted for BLKmode), perhaps for both ABI:s. */
569 for (i = 0; i < nregs - 1; i++)
571 = gen_rtx_EXPR_LIST (VOIDmode,
572 gen_rtx_REG (cmode, first_val_regnum + i),
573 GEN_INT ((i + 1) * BITS_PER_UNIT));
576 = gen_rtx_EXPR_LIST (VOIDmode,
577 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
580 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
583 /* EH_RETURN_DATA_REGNO. */
586 mmix_eh_return_data_regno (n)
587 int n ATTRIBUTE_UNUSED;
590 return MMIX_EH_RETURN_DATA_REGNO_START + n;
592 return INVALID_REGNUM;
595 /* EH_RETURN_STACKADJ_RTX. */
598 mmix_eh_return_stackadj_rtx ()
600 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
603 /* EH_RETURN_HANDLER_RTX. */
606 mmix_eh_return_handler_rtx ()
609 gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
612 /* ASM_PREFERRED_EH_DATA_FORMAT. */
615 mmix_asm_preferred_eh_data_format (code, global)
616 int code ATTRIBUTE_UNUSED;
617 int global ATTRIBUTE_UNUSED;
619 /* This is the default (was at 2001-07-20). Revisit when needed. */
620 return DW_EH_PE_absptr;
623 /* Emit the function prologue. For simplicity while the port is still
624 in a flux, we do it as text rather than the now preferred RTL way,
625 as (define_insn "function_prologue").
627 FIXME: Translate to RTL and/or optimize some of the DWARF 2 stuff. */
630 mmix_target_asm_function_prologue (stream, locals_size)
632 HOST_WIDE_INT locals_size;
635 int stack_space_to_allocate
636 = (current_function_outgoing_args_size
637 + current_function_pretend_args_size
638 + (int) locals_size + 8 + 7) & ~7;
640 int empty_stack_frame
641 = (current_function_outgoing_args_size == 0
643 && current_function_pretend_args_size == 0
644 && current_function_varargs == 0
645 && current_function_stdarg == 0);
646 int doing_dwarf = dwarf2out_do_frame ();
649 /* Guard our assumptions. Very low priority FIXME. */
650 if (locals_size != (int) locals_size)
651 error ("stack frame too big");
653 /* Add room needed to save global non-register-stack registers. */
655 regno >= MMIX_FIRST_GLOBAL_REGNUM;
657 /* Note that we assume that the frame-pointer-register is one of these
658 registers, in which case we don't count it here. */
659 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
660 && regs_ever_live[regno] && !call_used_regs[regno]))
661 || IS_MMIX_EH_RETURN_DATA_REG (regno))
662 stack_space_to_allocate += 8;
664 /* If we do have a frame-pointer, add room for it. */
665 if (frame_pointer_needed)
666 stack_space_to_allocate += 8;
668 /* If we have a non-local label, we need to be able to unwind to it, so
669 store the current register stack pointer. Also store the return
670 address if we do that. */
671 if (MMIX_CFUN_HAS_LANDING_PAD)
672 stack_space_to_allocate += 16;
673 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
674 /* If we do have a saved return-address slot, add room for it. */
675 stack_space_to_allocate += 8;
677 /* Make sure we don't get an unaligned stack. */
678 if ((stack_space_to_allocate % 8) != 0)
679 internal_error ("stack frame not a multiple of 8 bytes: %d",
680 stack_space_to_allocate);
682 if (current_function_pretend_args_size)
684 int mmix_first_vararg_reg
685 = (MMIX_FIRST_INCOMING_ARG_REGNUM
686 + (MMIX_MAX_ARGS_IN_REGS
687 - current_function_pretend_args_size / 8));
690 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
691 regno >= mmix_first_vararg_reg;
697 = stack_space_to_allocate > (256 - 8)
698 ? (256 - 8) : stack_space_to_allocate;
700 fprintf (stream, "\tSUBU %s,%s,%d\n",
701 reg_names[MMIX_STACK_POINTER_REGNUM],
702 reg_names[MMIX_STACK_POINTER_REGNUM],
707 /* Each call to dwarf2out_def_cfa overrides the previous
708 setting; they don't accumulate. We must keep track
709 of the offset ourselves. */
710 cfa_offset += stack_chunk;
711 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
714 offset += stack_chunk;
715 stack_space_to_allocate -= stack_chunk;
718 fprintf (stream, "\tSTOU %s,%s,%d\n", reg_names[regno],
719 reg_names[MMIX_STACK_POINTER_REGNUM],
722 /* These registers aren't actually saved (as in "will be
723 restored"), so don't tell DWARF2 they're saved. */
729 /* In any case, skip over the return-address slot. FIXME: Not needed
733 /* Store the frame-pointer. */
735 if (frame_pointer_needed)
737 empty_stack_frame = 0;
741 /* Get 8 less than otherwise, since we need to reach offset + 8. */
743 = stack_space_to_allocate > (256 - 8 - 8)
744 ? (256 - 8 - 8) : stack_space_to_allocate;
746 fprintf (stream, "\tSUBU %s,%s,%d\n",
747 reg_names[MMIX_STACK_POINTER_REGNUM],
748 reg_names[MMIX_STACK_POINTER_REGNUM],
752 cfa_offset += stack_chunk;
753 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
756 offset += stack_chunk;
757 stack_space_to_allocate -= stack_chunk;
760 fprintf (stream, "\tSTOU %s,%s,%d\n\tADDU %s,%s,%d\n",
761 reg_names[MMIX_FRAME_POINTER_REGNUM],
762 reg_names[MMIX_STACK_POINTER_REGNUM],
764 reg_names[MMIX_FRAME_POINTER_REGNUM],
765 reg_names[MMIX_STACK_POINTER_REGNUM],
768 dwarf2out_reg_save ("", MMIX_FRAME_POINTER_REGNUM,
769 -cfa_offset + offset);
774 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
776 /* Store the return-address, if one is needed on the stack. */
777 empty_stack_frame = 0;
781 /* Get 8 less than otherwise, since we need to reach offset + 8. */
783 = stack_space_to_allocate > (256 - 8 - 8)
784 ? (256 - 8 - 8) : stack_space_to_allocate;
786 fprintf (stream, "\tSUBU %s,%s,%d\n",
787 reg_names[MMIX_STACK_POINTER_REGNUM],
788 reg_names[MMIX_STACK_POINTER_REGNUM],
792 cfa_offset += stack_chunk;
793 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
796 offset += stack_chunk;
797 stack_space_to_allocate -= stack_chunk;
800 fprintf (stream, "\tGET $255,rJ\n\tSTOU $255,%s,%d\n",
801 reg_names[MMIX_STACK_POINTER_REGNUM],
804 dwarf2out_return_save ("", -cfa_offset + offset);
807 else if (MMIX_CFUN_HAS_LANDING_PAD)
810 if (MMIX_CFUN_HAS_LANDING_PAD)
812 /* Store the register defining the numbering of local registers, so
813 we know how long to unwind the register stack. */
815 empty_stack_frame = 0;
819 /* Get 8 less than otherwise, since we need to reach offset + 8. */
821 = stack_space_to_allocate > (256 - 8 - 8)
822 ? (256 - 8 - 8) : stack_space_to_allocate;
824 fprintf (stream, "\tSUBU %s,%s,%d\n",
825 reg_names[MMIX_STACK_POINTER_REGNUM],
826 reg_names[MMIX_STACK_POINTER_REGNUM],
828 offset += stack_chunk;
829 stack_space_to_allocate -= stack_chunk;
833 cfa_offset += stack_chunk;
834 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
839 /* We don't tell dwarf2 about this one; we just have it to unwind
840 the register stack at landing pads. FIXME: It's a kludge because
841 we can't describe the effect of the PUSHJ and PUSHGO insns on the
842 register stack at the moment. Best thing would be to handle it
843 like stack-pointer offsets. Better: some hook into dwarf2out.c
844 to produce DW_CFA_expression:s that specify the increment of rO,
845 and unwind it at eh_return (preferred) or at the landing pad.
846 Then saves to $0..$G-1 could be specified through that register. */
848 fprintf (stream, "\tGET $255,rO\n\tSTOU $255,%s,%d\n",
849 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
854 /* After the return-address and the frame-pointer, we have the local
855 variables. They're the ones that may have an "unaligned" size. */
856 offset -= (locals_size + 7) & ~7;
858 /* Now store all registers that are global, i.e. not saved by the
859 register file machinery.
861 It is assumed that the frame-pointer is one of these registers, so it
862 is explicitly excluded in the count. */
865 regno >= MMIX_FIRST_GLOBAL_REGNUM;
867 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
868 && regs_ever_live[regno] && ! call_used_regs[regno])
869 || IS_MMIX_EH_RETURN_DATA_REG (regno))
871 empty_stack_frame = 0;
877 /* Since the local variables go above, we may get a large
881 /* We're not going to access the locals area in the
882 prologue, so we'll just silently subtract the slab we
885 stack_space_to_allocate > (256 - offset - 8)
886 ? (256 - offset - 8) : stack_space_to_allocate;
888 mmix_output_register_setting (stream, 255, stack_chunk, 1);
889 fprintf (stream, "\tSUBU %s,%s,$255\n",
890 reg_names[MMIX_STACK_POINTER_REGNUM],
891 reg_names[MMIX_STACK_POINTER_REGNUM]);
895 cfa_offset += stack_chunk;
896 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
902 stack_chunk = stack_space_to_allocate > (256 - 8)
903 ? (256 - 8) : stack_space_to_allocate;
905 fprintf (stream, "\tSUBU %s,%s,%d\n",
906 reg_names[MMIX_STACK_POINTER_REGNUM],
907 reg_names[MMIX_STACK_POINTER_REGNUM], stack_chunk);
910 cfa_offset += stack_chunk;
911 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
916 offset += stack_chunk;
917 stack_space_to_allocate -= stack_chunk;
920 fprintf (stream, "\tSTOU %s,%s,%d\n", reg_names[regno],
921 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
923 dwarf2out_reg_save ("", regno, -cfa_offset + offset);
927 /* Finally, allocate room for local vars (if they weren't allocated for
928 above) and outgoing args. This might be any number of bytes (well,
929 we assume it fits in a host-int).
930 Don't allocate (the return-address slot) if the stack frame is empty. */
931 if (stack_space_to_allocate && ! empty_stack_frame)
933 if (stack_space_to_allocate < 256)
935 fprintf (stream, "\tSUBU %s,%s,%d\n",
936 reg_names[MMIX_STACK_POINTER_REGNUM],
937 reg_names[MMIX_STACK_POINTER_REGNUM],
938 stack_space_to_allocate);
942 mmix_output_register_setting (stream, 255,
943 stack_space_to_allocate, 1);
944 fprintf (stream, "\tSUBU %s,%s,$255\n",
945 reg_names[MMIX_STACK_POINTER_REGNUM],
946 reg_names[MMIX_STACK_POINTER_REGNUM]);
951 cfa_offset += stack_space_to_allocate;
952 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
957 /* We put the number of the highest saved register-file register in a
958 location convenient for the call-patterns to output. Note that we
959 don't tell dwarf2 about these registers, since it can't restore them
961 for (regno = MMIX_LAST_REGISTER_FILE_REGNUM;
964 if ((regs_ever_live[regno] && !call_used_regs[regno])
965 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
968 mmix_highest_saved_stack_register = regno;
970 /* FIXME: Remove this when a corrected mmix version is released.
972 This kludge is a work-around for a presumed bug in the mmix simulator
973 (reported to knuth-bug), all versions up and including "Version of 14
974 October 2001". When the circular register stack fills up, the parts
975 that would be overwritten need to be written to memory. If the
976 "filling" instruction is a PUSHJ or PUSHGO, rL == 0 afterwards. That
977 precise condition (rS == rO && rL == 0) is the same as for an empty
978 register stack, which means no more data is written to memory for
979 that round. A hack is to remove the "&& L!=0" from "@<Increase
980 rL@>=" in mmix-sim.w: the register stack isn't empty under normal
981 circumstances, unless SAVE or UNSAVE is used, interrupts are enabled
982 or cases where rS == rO and rL is explicitly written to 0 as in
985 A workaround is to make sure PUSHJ or PUSHGO isn't filling up the
986 register stac. This is accomplished if $16 or higher is written
987 before the function call. This doesn't happen from a leaf functions
988 of course. For the MMIXware ABI, this can't happen if all called
989 functions have parameters, because parameters start at $16.
990 Otherwise, and for the GNU ABI, if any register $16 and up is used,
991 we can see if it's mentioned before any function-call without
992 parameters. This isn't too important; the bug will probably be fixed
993 soon and there's an option to not emit the work-around code. The
994 call-with-parameters kludge wouldn't be there if it hadn't been for
995 it being left-over from a previous mmix version.
997 The actual code makes sure any register stack fill happens as early
998 as in the function prologue with a "SET $16,$16" (essentially a nop
999 except for the effects on the register stack). */
1000 if (TARGET_REG_STACK_FILL_BUG
1001 && ((TARGET_ABI_GNU && !leaf_function_p ())
1003 && cfun->machine->has_call_without_parameters)))
1005 /* We don't have a specific macro or derivable expression for the
1006 first non-call-saved register. If we need it in other places
1007 than here (which is temporary code anyway), such a macro should
1010 = TARGET_ABI_GNU ? mmix_highest_saved_stack_register + 2 : 16;
1012 fprintf (stream, "\tSET %s,%s\n",
1013 reg_names[flush_regno], reg_names[flush_regno]);
1017 /* TARGET_ASM_FUNCTION_EPILOGUE. */
1020 mmix_target_asm_function_epilogue (stream, locals_size)
1022 HOST_WIDE_INT locals_size;
1026 int stack_space_to_deallocate
1027 = (current_function_outgoing_args_size
1028 + current_function_pretend_args_size
1029 + (int) locals_size + 8 + 7) & ~7;
1031 /* The assumption that locals_size fits in an int is asserted in
1032 mmix_target_asm_function_prologue. */
1034 /* The first address to access is beyond the outgoing_args area. */
1035 int offset = current_function_outgoing_args_size;
1036 int empty_stack_frame
1037 = (current_function_outgoing_args_size == 0
1039 && current_function_pretend_args_size == 0
1040 && ! MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
1041 && ! MMIX_CFUN_HAS_LANDING_PAD);
1043 /* Add the space for global non-register-stack registers.
1044 It is assumed that the frame-pointer register can be one of these
1045 registers, in which case it is excluded from the count when needed. */
1047 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1049 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1050 && regs_ever_live[regno] && !call_used_regs[regno])
1051 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1052 stack_space_to_deallocate += 8;
1054 /* Add in the space for register stack-pointer. If so, always add room
1055 for the saved PC. */
1056 if (MMIX_CFUN_HAS_LANDING_PAD)
1057 stack_space_to_deallocate += 16;
1058 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1059 /* If we have a saved return-address slot, add it in. */
1060 stack_space_to_deallocate += 8;
1062 /* Add in the frame-pointer. */
1063 if (frame_pointer_needed)
1064 stack_space_to_deallocate += 8;
1066 /* Make sure we don't get an unaligned stack. */
1067 if ((stack_space_to_deallocate % 8) != 0)
1068 internal_error ("stack frame not a multiple of octabyte: %d",
1069 stack_space_to_deallocate);
1071 /* We will add back small offsets to the stack pointer as we go.
1072 First, we restore all registers that are global, i.e. not saved by
1073 the register file machinery. */
1075 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
1078 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1079 && regs_ever_live[regno] && !call_used_regs[regno])
1080 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1082 empty_stack_frame = 0;
1088 /* There's better support for incrementing than
1089 decrementing, so we might be able to optimize this as
1091 mmix_output_register_setting (stream, 255, offset, 1);
1092 fprintf (stream, "\tADDU %s,%s,$255\n",
1093 reg_names[MMIX_STACK_POINTER_REGNUM],
1094 reg_names[MMIX_STACK_POINTER_REGNUM]);
1097 fprintf (stream, "\tINCL %s,%d\n",
1098 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
1100 stack_space_to_deallocate -= offset;
1104 fprintf (stream, "\tLDOU %s,%s,%d\n",
1106 reg_names[MMIX_STACK_POINTER_REGNUM],
1111 /* Here is where the local variables were. As in the prologue, they
1112 might be of an unaligned size. */
1113 offset += (locals_size + 7) & ~7;
1116 /* The saved register stack pointer is just below the frame-pointer
1117 register. We don't need to restore it "manually"; the POP
1118 instruction does that. */
1119 if (MMIX_CFUN_HAS_LANDING_PAD)
1121 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1122 /* The return-address slot is just below the frame-pointer register.
1123 We don't need to restore it because we don't really use it. */
1126 /* Get back the old frame-pointer-value. */
1127 if (frame_pointer_needed)
1129 empty_stack_frame = 0;
1135 /* There's better support for incrementing than
1136 decrementing, so we might be able to optimize this as
1138 mmix_output_register_setting (stream, 255, offset, 1);
1139 fprintf (stream, "\tADDU %s,%s,$255\n",
1140 reg_names[MMIX_STACK_POINTER_REGNUM],
1141 reg_names[MMIX_STACK_POINTER_REGNUM]);
1144 fprintf (stream, "\tINCL %s,%d\n",
1145 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
1147 stack_space_to_deallocate -= offset;
1151 fprintf (stream, "\tLDOU %s,%s,%d\n",
1152 reg_names[MMIX_FRAME_POINTER_REGNUM],
1153 reg_names[MMIX_STACK_POINTER_REGNUM],
1158 /* Do not deallocate the return-address slot if the stack frame is
1159 empty, because then it was never allocated. */
1160 if (! empty_stack_frame)
1162 /* We do not need to restore pretended incoming args, just add
1163 back offset to sp. */
1164 if (stack_space_to_deallocate > 65535)
1166 /* There's better support for incrementing than decrementing, so
1167 we might be able to optimize this as we see a need. */
1168 mmix_output_register_setting (stream, 255,
1169 stack_space_to_deallocate, 1);
1170 fprintf (stream, "\tADDU %s,%s,$255\n",
1171 reg_names[MMIX_STACK_POINTER_REGNUM],
1172 reg_names[MMIX_STACK_POINTER_REGNUM]);
1175 fprintf (stream, "\tINCL %s,%d\n",
1176 reg_names[MMIX_STACK_POINTER_REGNUM],
1177 stack_space_to_deallocate);
1180 if (current_function_calls_eh_return)
1181 /* Adjustment the (normal) stack-pointer to that of the receiver.
1182 FIXME: It would be nice if we could also adjust the register stack
1183 here, but we need to express it through DWARF 2 too. */
1184 fprintf (stream, "\tADDU %s,%s,%s\n",
1185 reg_names [MMIX_STACK_POINTER_REGNUM],
1186 reg_names [MMIX_STACK_POINTER_REGNUM],
1187 reg_names [MMIX_EH_RETURN_STACKADJ_REGNUM]);
1189 /* The extra \n is so we have a blank line between the assembly code of
1190 separate functions. */
1191 fprintf (stream, "\tPOP %d,0\n\n",
1193 && current_function_return_rtx != NULL
1194 && ! current_function_returns_struct)
1195 ? (GET_CODE (current_function_return_rtx) == PARALLEL
1196 ? GET_NUM_ELEM (XVEC (current_function_return_rtx, 0)) : 1)
1200 /* ASM_OUTPUT_MI_THUNK. */
1203 mmix_asm_output_mi_thunk (stream, fndecl, delta, func)
1205 tree fndecl ATTRIBUTE_UNUSED;
1209 /* If you define STRUCT_VALUE to 0, rather than use STRUCT_VALUE_REGNUM,
1210 (i.e. pass location of structure to return as invisible first
1211 argument) you need to tweak this code too. */
1212 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
1214 if (delta >= 0 && delta < 65536)
1215 asm_fprintf (stream, "\tINCL %s,%d\n", delta, regname);
1216 else if (delta < 0 && delta >= -255)
1217 asm_fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, -delta);
1220 mmix_output_register_setting (stream, 255, delta, 1);
1221 asm_fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
1224 fprintf (stream, "\tJMP ");
1225 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
1226 fprintf (stream, "\n");
1229 /* FUNCTION_PROFILER. */
1232 mmix_function_profiler (stream, labelno)
1233 FILE *stream ATTRIBUTE_UNUSED;
1234 int labelno ATTRIBUTE_UNUSED;
1236 sorry ("function_profiler support for MMIX");
1239 /* SETUP_INCOMING_VARARGS. */
1242 mmix_setup_incoming_varargs (args_so_farp, mode, vartype, pretend_sizep,
1244 CUMULATIVE_ARGS * args_so_farp;
1245 enum machine_mode mode;
1247 int * pretend_sizep;
1248 int second_time ATTRIBUTE_UNUSED;
1250 /* For stdarg, the last named variable has been handled, but
1251 args_so_farp has not been advanced for it. For varargs, the current
1252 argument is to be counted to the anonymous ones. */
1253 if (current_function_stdarg)
1255 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
1257 = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
1259 else if (current_function_varargs)
1261 if (args_so_farp->regs < MMIX_MAX_ARGS_IN_REGS)
1263 = (MMIX_MAX_ARGS_IN_REGS - args_so_farp->regs) * 8;
1265 /* For varargs, we get here when we see the last named parameter,
1266 which will actually be passed on stack. So make the next call
1267 (there will be one) to FUNCTION_ARG return 0, to count it on
1268 stack, so va_arg for it will get right. FIXME: The GCC core
1269 should provide TRT. */
1270 args_so_farp->now_varargs = 1;
1273 internal_error ("neither varargs or stdarg in mmix_setup_incoming_varargs");
1276 /* We assume that one argument takes up one register here. That should
1277 be true until we start messing with multi-reg parameters. */
1278 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
1279 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
1282 /* EXPAND_BUILTIN_VA_ARG. */
1284 /* This is modified from the "standard" implementation of va_arg: read the
1285 value from the current (padded) address and increment by the (padded)
1286 size. The difference for MMIX is that if the type is
1287 pass-by-reference, then perform an indirection. */
1290 mmix_expand_builtin_va_arg (valist, type)
1295 HOST_WIDE_INT align;
1296 HOST_WIDE_INT rounded_size;
1299 /* Compute the rounded size of the type. */
1300 align = PARM_BOUNDARY / BITS_PER_UNIT;
1301 rounded_size = (((int_size_in_bytes (type) + align - 1) / align) * align);
1306 if (AGGREGATE_TYPE_P (type)
1307 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) < 8
1308 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) != 0)
1310 /* Adjust for big-endian the location of aggregates passed in a
1311 register, but where the aggregate is accessed in a shorter mode
1312 than the natural register mode (i.e. it is accessed as SFmode(?),
1313 SImode, HImode or QImode rather than DImode or DFmode(?)). FIXME:
1314 Or should we adjust the mode in which the aggregate is read, to be
1315 a register size mode? (Hum, nah, a small offset is generally
1316 cheaper than a wider memory access on MMIX.) */
1318 = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
1319 build_int_2 ((BITS_PER_WORD / BITS_PER_UNIT)
1320 - GET_MODE_UNIT_SIZE (TYPE_MODE (type)), 0));
1325 adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT;
1326 if (rounded_size > align)
1329 addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
1330 build_int_2 (rounded_size - adj, 0));
1332 /* If this type is larger than what fits in a register, then it is
1333 passed by reference. */
1334 if (rounded_size > BITS_PER_WORD / BITS_PER_UNIT)
1336 tree type_ptr = build_pointer_type (type);
1337 addr_tree = build1 (INDIRECT_REF, type_ptr, addr_tree);
1341 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
1342 addr = copy_to_reg (addr);
1344 /* Compute new value for AP. For MMIX, it is always advanced by the
1345 size of a register. */
1346 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
1347 build (PLUS_EXPR, TREE_TYPE (valist), valist,
1348 build_int_2 (BITS_PER_WORD / BITS_PER_UNIT, 0)));
1349 TREE_SIDE_EFFECTS (t) = 1;
1350 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1355 /* TRAMPOLINE_SIZE. */
1356 /* Four 4-byte insns plus two 8-byte values. */
1357 int mmix_trampoline_size = 32;
1360 /* TRAMPOLINE_TEMPLATE. */
1363 mmix_trampoline_template (stream)
1366 /* Read a value from to static-chain, jump somewhere. The static chain
1367 is stored at offset 16, and the function address is stored at offset
1369 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
1370 register size (octa). */
1371 fprintf (stream, "\tGETA $255,1F\n\t");
1372 fprintf (stream, "LDOU %s,$255,0\n\t",
1373 reg_names[MMIX_STATIC_CHAIN_REGNUM]);
1374 fprintf (stream, "LDOU $255,$255,8\n\t");
1375 fprintf (stream, "GO $255,$255,0\n");
1376 fprintf (stream, "1H\tOCTA 0\n\t");
1377 fprintf (stream, "OCTA 0\n");
1380 /* INITIALIZE_TRAMPOLINE. */
1381 /* Set the static chain and function pointer field in the trampoline.
1382 We also SYNCID here to be sure (doesn't matter in the simulator, but
1383 some day it will). */
1386 mmix_initialize_trampoline (trampaddr, fnaddr, static_chain)
1391 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)),
1393 emit_move_insn (gen_rtx_MEM (DImode,
1394 plus_constant (trampaddr, 24)),
1396 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode,
1398 GEN_INT (mmix_trampoline_size - 1)));
1401 /* We must exclude constant addresses that have an increment that is not a
1402 multiple of four bytes because of restrictions of the GETA
1403 instruction. FIXME: No, I don't think so. Just add a constraint. */
1406 mmix_constant_address_p (x)
1409 RTX_CODE code = GET_CODE (x);
1412 if (code == LABEL_REF || code == SYMBOL_REF)
1415 if (code == CONSTANT_P_RTX || code == HIGH)
1416 /* FIXME: Don't know how to dissect these. Avoid them for now. */
1426 /* Can we get a naked PLUS? */
1427 case CONSTANT_P_RTX:
1429 /* FIXME: Don't know how to dissect these. Avoid them for now. */
1433 addend = INTVAL (x);
1437 if (GET_MODE (x) != VOIDmode)
1438 /* Strange that we got here. FIXME: Check if we do. */
1440 addend = CONST_DOUBLE_LOW (x);
1444 /* Note that expressions with arithmetic on forward references don't
1445 work in mmixal. People using gcc assembly code with mmixal might
1446 need to move arrays and such to before the point of use. */
1447 if (GET_CODE (XEXP (x, 0)) == PLUS)
1449 rtx x0 = XEXP (XEXP (x, 0), 0);
1450 rtx x1 = XEXP (XEXP (x, 0), 1);
1452 if ((GET_CODE (x0) == SYMBOL_REF
1453 || GET_CODE (x0) == LABEL_REF)
1454 && (GET_CODE (x1) == CONST_INT
1455 || (GET_CODE (x1) == CONST_DOUBLE
1456 && GET_MODE (x1) == VOIDmode)))
1457 addend = mmix_intval (x1);
1469 return (addend & 3) == 0;
1472 /* Return 1 if the address is OK, otherwise 0.
1473 Used by GO_IF_LEGITIMATE_ADDRESS. */
1476 mmix_legitimate_address (mode, x, strict_checking)
1477 enum machine_mode mode ATTRIBUTE_UNUSED;
1479 int strict_checking;
1481 #define MMIX_REG_OK(X) \
1483 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1484 || (reg_renumber[REGNO (X)] > 0 \
1485 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1486 || (!strict_checking \
1487 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1488 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1489 || REGNO (X) == ARG_POINTER_REGNUM)))
1493 (mem (plus reg reg))
1494 (mem (plus reg 0..255)). */
1498 if (REG_P (x) && MMIX_REG_OK (x))
1501 if (GET_CODE(x) == PLUS)
1503 rtx x1 = XEXP (x, 0);
1504 rtx x2 = XEXP (x, 1);
1506 /* Try swapping the order. FIXME: Do we need this? */
1514 /* (mem (plus (reg) (?))) */
1515 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1518 /* (mem (plus (reg) (reg))) */
1519 if (REG_P (x2) && MMIX_REG_OK (x2))
1522 /* (mem (plus (reg) (0..255))) */
1523 if (GET_CODE (x2) == CONST_INT
1524 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1531 /* LEGITIMATE_CONSTANT_P. */
1534 mmix_legitimate_constant_p (x)
1537 RTX_CODE code = GET_CODE (x);
1539 /* We must allow any number due to the way the cse passes works; if we
1540 do not allow any number here, general_operand will fail, and insns
1541 will fatally fail recognition instead of "softly". */
1542 if (code == CONST_INT || code == CONST_DOUBLE)
1545 return CONSTANT_ADDRESS_P (x);
1548 /* SELECT_CC_MODE. */
1551 mmix_select_cc_mode (op, x, y)
1554 rtx y ATTRIBUTE_UNUSED;
1556 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1557 output different compare insns. Note that we do not check the
1558 validity of the comparison here. */
1560 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1562 if (op == ORDERED || op == UNORDERED || op == UNGE
1563 || op == UNGT || op == UNLE || op == UNLT)
1566 if (op == EQ || op == NE)
1572 if (op == GTU || op == LTU || op == GEU || op == LEU)
1578 /* CANONICALIZE_COMPARISON.
1579 FIXME: Check if the number adjustments trig. */
1582 mmix_canonicalize_comparison (codep, op0p, op1p)
1584 rtx * op0p ATTRIBUTE_UNUSED;
1587 /* Change -1 to zero, if possible. */
1588 if ((*codep == LE || *codep == GT)
1589 && GET_CODE (*op1p) == CONST_INT
1590 && *op1p == constm1_rtx)
1592 *codep = *codep == LE ? LT : GE;
1596 /* Fix up 256 to 255, if possible. */
1597 if ((*codep == LT || *codep == LTU || *codep == GE || *codep == GEU)
1598 && GET_CODE (*op1p) == CONST_INT
1599 && INTVAL (*op1p) == 256)
1601 /* FIXME: Remove when I know this trigs. */
1602 fatal_insn ("oops, not debugged; fixing up value:", *op1p);
1603 *codep = *codep == LT ? LE : *codep == LTU ? LEU : *codep
1605 *op1p = GEN_INT (255);
1609 /* REVERSIBLE_CC_MODE. */
1612 mmix_reversible_cc_mode (mode)
1613 enum machine_mode mode;
1615 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1617 return mode != CC_FPmode;
1620 /* DEFAULT_RTX_COSTS. */
1623 mmix_rtx_cost_recalculated (x, code, outer_code, costp)
1624 rtx x ATTRIBUTE_UNUSED;
1625 RTX_CODE code ATTRIBUTE_UNUSED;
1626 RTX_CODE outer_code ATTRIBUTE_UNUSED;
1627 int *costp ATTRIBUTE_UNUSED;
1629 /* For the time being, this is just a stub and we'll accept the
1630 generic calculations, until we can do measurements, at least.
1631 Say we did not modify any calculated costs. */
1638 mmix_address_cost (addr)
1639 rtx addr ATTRIBUTE_UNUSED;
1641 /* There's no difference in the address costs and we have lots of
1642 registers. Some targets use constant 0, many others use 1 to say
1643 this. Let's start with 1. */
1647 /* REGISTER_MOVE_COST. */
1650 mmix_register_move_cost (mode, from, to)
1651 enum machine_mode mode ATTRIBUTE_UNUSED;
1652 enum reg_class from;
1655 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1658 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1659 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1662 /* DATA_SECTION_ASM_OP. */
1665 mmix_data_section_asm_op ()
1667 return "\t.data ! mmixal:= 8H LOC 9B";
1671 The meat is from elfos.h, which we will eventually consider using. */
1674 mmix_select_section (decl, reloc, align)
1677 int align ATTRIBUTE_UNUSED;
1679 if (TREE_CODE (decl) == STRING_CST)
1681 if (! flag_writable_strings)
1686 else if (TREE_CODE (decl) == VAR_DECL)
1688 if ((flag_pic && reloc)
1689 || !TREE_READONLY (decl) || TREE_SIDE_EFFECTS (decl)
1690 || !DECL_INITIAL (decl)
1691 || (DECL_INITIAL (decl) != error_mark_node
1692 && !TREE_CONSTANT (DECL_INITIAL (decl))))
1697 else if (TREE_CODE (decl) == CONSTRUCTOR)
1699 if ((flag_pic && reloc)
1700 || !TREE_READONLY (decl) || TREE_SIDE_EFFECTS (decl)
1701 || ! TREE_CONSTANT (decl))
1710 /* ENCODE_SECTION_INFO. */
1713 mmix_encode_section_info (decl)
1716 /* Test for an external declaration, and do nothing if it is one. */
1717 if ((TREE_CODE (decl) == VAR_DECL
1718 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1719 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1721 else if (DECL_P (decl))
1723 /* For non-visible declarations, add a "@" prefix, which we skip
1724 when the label is output. If the label does not have this
1725 prefix, a ":" is output.
1727 Note that this does not work for data that is declared extern and
1728 later defined as static. If there's code in between, that code
1729 will refer to the extern declaration. And vice versa. Until we
1730 can get rid of mmixal, we have to assume that code is
1733 const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1734 int len = strlen (str);
1737 /* Doing as rs6000 seems safe; always use ggc. Except don't copy
1738 the suspected off-by-one bug.
1739 FIXME: Is it still there? yes 2001-08-23
1740 Why is the return type of ggc_alloc_string const? */
1741 newstr = (char *) ggc_alloc_string ("", len + 2);
1743 strcpy (newstr + 1, str);
1745 XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
1748 /* FIXME: Later on, add SYMBOL_REF_FLAG for things that we can reach
1749 from here via GETA, to check in LEGITIMATE_CONSTANT_P. Needs to have
1750 different options for the cases where we want *all* to be assumed
1751 reachable via GETA, or all constant symbols, or just text symbols in
1752 this file, or perhaps just the constant pool. */
1755 /* STRIP_NAME_ENCODING. */
1758 mmix_strip_name_encoding (name)
1761 for (; (*name == '@' || *name == '*'); name++)
1768 The meat is from elfos.h, which we should consider using. */
1771 mmix_unique_section (decl, reloc)
1780 static const char *const prefixes[4][2] =
1782 { ".text.", ".gnu.linkonce.t." },
1783 { ".rodata.", ".gnu.linkonce.r." },
1784 { ".data.", ".gnu.linkonce.d." },
1785 { ".bss.", ".gnu.linkonce.b." }
1788 if (TREE_CODE (decl) == FUNCTION_DECL)
1790 else if (DECL_INITIAL (decl) == 0
1791 || DECL_INITIAL (decl) == error_mark_node)
1793 else if (DECL_READONLY_SECTION (decl, reloc))
1798 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1799 /* Strip off any encoding in name. */
1800 STRIP_NAME_ENCODING (name, name);
1801 prefix = prefixes[sec][DECL_ONE_ONLY (decl)];
1802 len = strlen (name) + strlen (prefix);
1803 string = alloca (len + 1);
1805 sprintf (string, "%s%s", prefix, name);
1807 DECL_SECTION_NAME (decl) = build_string (len, string);
1810 /* ASM_FILE_START. */
1813 mmix_asm_file_start (stream)
1816 /* We just emit a little comment for the time being. FIXME: Perhaps add
1817 -mstandalone and some segment and prefix setup here. */
1818 ASM_OUTPUT_SOURCE_FILENAME (stream, main_input_filename);
1820 fprintf (stream, "! mmixal:= 8H LOC Data_Section\n");
1822 /* Make sure each file starts with the text section. */
1829 mmix_asm_file_end (stream)
1830 FILE * stream ATTRIBUTE_UNUSED;
1832 /* Make sure each file ends with the data section. */
1836 /* ASM_IDENTIFY_GCC. */
1839 mmix_asm_identify_gcc (stream)
1842 /* No real need for the time being. May be useful to GDB later on. */
1843 fprintf (stream, "# Compiled by GCC version %s\n",
1847 /* ASM_OUTPUT_SOURCE_FILENAME. */
1850 mmix_asm_output_source_filename (stream, name)
1854 fprintf (stream, "# 1 ");
1855 OUTPUT_QUOTED_STRING (stream, name);
1856 fprintf (stream, "\n");
1859 /* OUTPUT_QUOTED_STRING. */
1862 mmix_output_quoted_string (stream, string, length)
1864 const char * string;
1867 const char * string_end = string + length;
1868 static const char *const unwanted_chars = "\"[]\\";
1870 /* Output "any character except newline and double quote character". We
1871 play it safe and avoid all control characters too. We also do not
1872 want [] as characters, should input be passed through m4 with [] as
1873 quotes. Further, we avoid "\", because the GAS port handles it as a
1874 quoting character. */
1875 while (string < string_end)
1878 && (unsigned char) *string < 128
1879 && !ISCNTRL (*string)
1880 && strchr (unwanted_chars, *string) == NULL)
1882 fputc ('"', stream);
1884 && (unsigned char) *string < 128
1885 && !ISCNTRL (*string)
1886 && strchr (unwanted_chars, *string) == NULL
1887 && string < string_end)
1889 fputc (*string, stream);
1892 fputc ('"', stream);
1893 if (string < string_end)
1894 fprintf (stream, ",");
1896 if (string < string_end)
1898 fprintf (stream, "#%x", *string & 255);
1900 if (string < string_end)
1901 fprintf (stream, ",");
1906 /* ASM_OUTPUT_SOURCE_LINE. */
1909 mmix_asm_output_source_line (stream, lineno)
1913 fprintf (stream, "# %d ", lineno);
1914 OUTPUT_QUOTED_STRING (stream, main_input_filename);
1915 fprintf (stream, "\n");
1918 /* Target hook for assembling integer objects. Use mmix_print_operand
1919 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1923 mmix_assemble_integer (x, size, aligned_p)
1932 fputs ("\tBYTE\t", asm_out_file);
1933 mmix_print_operand (asm_out_file, x, 'B');
1934 fputc ('\n', asm_out_file);
1938 fputs ("\tWYDE\t", asm_out_file);
1939 mmix_print_operand (asm_out_file, x, 'W');
1940 fputc ('\n', asm_out_file);
1944 fputs ("\tTETRA\t", asm_out_file);
1945 mmix_print_operand (asm_out_file, x, 'L');
1946 fputc ('\n', asm_out_file);
1950 if (GET_CODE (x) == CONST_DOUBLE)
1951 mmix_output_octa (asm_out_file, mmix_intval (x), 0);
1953 assemble_integer_with_op ("\tOCTA\t", x);
1956 return default_assemble_integer (x, size, aligned_p);
1959 /* ASM_OUTPUT_ASCII. */
1962 mmix_asm_output_ascii (stream, string, length)
1969 int chunk_size = length > 60 ? 60 : length;
1970 fprintf (stream, "\tBYTE ");
1971 mmix_output_quoted_string (stream, string, chunk_size);
1972 string += chunk_size;
1973 length -= chunk_size;
1974 fprintf (stream, "\n");
1978 /* ASM_OUTPUT_ALIGNED_COMMON. */
1981 mmix_asm_output_aligned_common (stream, name, size, align)
1987 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1988 express this in a mmixal-compatible way. */
1989 fprintf (stream, "\t.comm\t");
1990 assemble_name (stream, name);
1991 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1992 size, align / BITS_PER_UNIT);
1995 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1998 mmix_asm_output_aligned_local (stream, name, size, align)
2006 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
2007 assemble_name (stream, name);
2008 fprintf (stream, "\tLOC @+%d\n", size);
2011 /* ASM_OUTPUT_LABEL. */
2014 mmix_asm_output_label (stream, name)
2018 assemble_name (stream, name);
2019 fprintf (stream, "\tIS @\n");
2022 /* ASM_DECLARE_REGISTER_GLOBAL. */
2025 mmix_asm_declare_register_global (stream, decl, regno, name)
2026 FILE *stream ATTRIBUTE_UNUSED;
2027 tree decl ATTRIBUTE_UNUSED;
2028 int regno ATTRIBUTE_UNUSED;
2029 const char *name ATTRIBUTE_UNUSED;
2031 /* Nothing to do here, but there *will* be, therefore the framework is
2035 /* ASM_GLOBALIZE_LABEL. */
2038 mmix_asm_globalize_label (stream, name)
2039 FILE * stream ATTRIBUTE_UNUSED;
2040 const char * name ATTRIBUTE_UNUSED;
2042 asm_fprintf (stream, "\t.global ");
2043 assemble_name (stream, name);
2044 putc ('\n', stream);
2047 /* ASM_WEAKEN_LABEL. */
2050 mmix_asm_weaken_label (stream, name)
2051 FILE * stream ATTRIBUTE_UNUSED;
2052 const char * name ATTRIBUTE_UNUSED;
2054 asm_fprintf (stream, "\t.weak ");
2055 assemble_name (stream, name);
2056 asm_fprintf (stream, " ! mmixal-incompatible\n");
2059 /* MAKE_DECL_ONE_ONLY. */
2062 mmix_make_decl_one_only (decl)
2065 DECL_WEAK (decl) = 1;
2068 /* ASM_OUTPUT_LABELREF.
2069 Strip GCC's '*' and our own '@'. No order is assumed. */
2072 mmix_asm_output_labelref (stream, name)
2078 for (; (*name == '@' || *name == '*'); name++)
2082 asm_fprintf (stream, "%s%U%s",
2083 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
2087 /* ASM_OUTPUT_INTERNAL_LABEL. */
2090 mmix_asm_output_internal_label (stream, name, num)
2095 fprintf (stream, "%s:%d\tIS @\n", name, num);
2098 /* ASM_OUTPUT_DEF. */
2101 mmix_asm_output_def (stream, name, value)
2106 assemble_name (stream, name);
2107 fprintf (stream, "\tIS ");
2108 assemble_name (stream, value);
2109 fputc ('\n', stream);
2112 /* ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL. */
2115 mmix_asm_output_define_label_difference_symbol (stream, symbol, hi, lo)
2121 assemble_name (stream, symbol);
2122 fprintf (stream, "\tIS\t");
2123 assemble_name (stream, hi);
2124 fputc ('-', stream);
2125 assemble_name (stream, lo);
2126 fprintf (stream, "\n");
2129 /* PRINT_OPERAND. */
2132 mmix_print_operand (stream, x, code)
2137 /* When we add support for different codes later, we can, when needed,
2138 drop through to the main handler with a modified operand. */
2143 /* Unrelated codes are in alphabetic order. */
2146 /* For conditional branches, output "P" for a probable branch. */
2147 if (TARGET_BRANCH_PREDICT)
2149 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
2150 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
2156 if (GET_CODE (x) != CONST_INT)
2157 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
2158 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
2162 /* Highpart. Must be general register, and not the last one, as
2163 that one cannot be part of a consecutive register pair. */
2164 if (REGNO (x) > MMIX_LAST_GENERAL_REGISTER - 1)
2165 internal_error ("MMIX Internal: Bad register: %d", REGNO (x));
2167 /* This is big-endian, so the high-part is the first one. */
2168 fprintf (stream, "%s", reg_names[REGNO (x)]);
2172 /* Lowpart. Must be CONST_INT or general register, and not the last
2173 one, as that one cannot be part of a consecutive register pair. */
2174 if (GET_CODE (x) == CONST_INT)
2176 fprintf (stream, "#%lx",
2177 (unsigned long) (INTVAL (x)
2178 & ((unsigned int) 0x7fffffff * 2 + 1)));
2182 if (GET_CODE (x) == SYMBOL_REF)
2184 output_addr_const (stream, x);
2188 if (REGNO (x) > MMIX_LAST_GENERAL_REGISTER - 1)
2189 internal_error ("MMIX Internal: Bad register: %d", REGNO (x));
2191 /* This is big-endian, so the low-part is + 1. */
2192 fprintf (stream, "%s", reg_names[REGNO (x) + 1]);
2195 /* Can't use 'a' because that's a generic modifier for address
2198 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
2199 ~(unsigned HOST_WIDEST_INT)
2204 mmix_output_shiftvalue_op_from_str (stream, "INC",
2205 (unsigned HOST_WIDEST_INT)
2210 mmix_output_shiftvalue_op_from_str (stream, "OR",
2211 (unsigned HOST_WIDEST_INT)
2216 mmix_output_shiftvalue_op_from_str (stream, "SET",
2217 (unsigned HOST_WIDEST_INT)
2223 mmix_output_condition (stream, x, (code == 'D'));
2227 /* Output an extra "e" to make fcmpe, fune. */
2228 if (TARGET_FCMP_EPSILON)
2229 fprintf (stream, "e");
2233 /* Output the number minus 1. */
2234 if (GET_CODE (x) != CONST_INT)
2236 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
2239 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
2240 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
2244 /* Store the number of registers we want to save. This was setup
2245 by the prologue. The actual operand contains the number of
2246 registers to pass, but we don't use it currently. Anyway, we
2247 need to output the number of saved registers here. */
2249 fprintf (stream, "%d", mmix_highest_saved_stack_register + 1);
2251 /* FIXME: Get the effect of renaming $16, $17.. to the first
2252 unused call-saved reg. */
2253 fprintf (stream, "15");
2257 /* Store the register to output a constant to. */
2259 fatal_insn ("MMIX Internal: Expected a register, not this", x);
2260 mmix_output_destination_register = REGNO (x);
2264 /* Output the constant. Note that we use this for floats as well. */
2265 if (GET_CODE (x) != CONST_INT
2266 && (GET_CODE (x) != CONST_DOUBLE
2267 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
2268 && GET_MODE (x) != SFmode)))
2269 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
2270 mmix_output_register_setting (stream,
2271 mmix_output_destination_register,
2272 mmix_intval (x), 0);
2276 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
2277 if (TARGET_ZERO_EXTEND)
2282 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
2286 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
2290 if (GET_CODE (x) != CONST_INT)
2291 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
2292 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
2296 /* Nothing to do. */
2300 /* Presumably there's a missing case above if we get here. */
2301 internal_error ("MMIX Internal: Missing `%c' case in mmix_print_operand", code);
2304 switch (GET_CODE (modified_x))
2307 if (REGNO (modified_x) >= FIRST_PSEUDO_REGISTER)
2308 internal_error ("MMIX Internal: Bad register: %d", REGNO (modified_x));
2309 fprintf (stream, "%s", reg_names[REGNO (modified_x)]);
2313 output_address (XEXP (modified_x, 0));
2317 /* For -2147483648, mmixal complains that the constant does not fit
2318 in 4 bytes, so let's output it as hex. Take care to handle hosts
2319 where HOST_WIDE_INT is longer than an int.
2321 Print small constants +-255 using decimal. */
2323 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
2324 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
2326 fprintf (stream, "#%x",
2327 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
2331 /* Do somewhat as CONST_INT. */
2332 mmix_output_octa (stream, mmix_intval (modified_x), 0);
2336 output_addr_const (stream, modified_x);
2340 /* No need to test for all strange things. Let output_addr_const do
2342 if (CONSTANT_P (modified_x)
2343 /* Strangely enough, this is not included in CONSTANT_P.
2344 FIXME: Ask/check about sanity here. */
2345 || GET_CODE (modified_x) == CODE_LABEL)
2347 output_addr_const (stream, modified_x);
2351 /* We need the original here. */
2352 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
2356 /* PRINT_OPERAND_PUNCT_VALID_P. */
2359 mmix_print_operand_punct_valid_p (code)
2360 int code ATTRIBUTE_UNUSED;
2362 /* A '+' is used for branch prediction, similar to other ports. */
2366 /* PRINT_OPERAND_ADDRESS. */
2369 mmix_print_operand_address (stream, x)
2375 /* I find the generated assembly code harder to read without
2377 fprintf (stream, "%s,0",reg_names[REGNO (x)]);
2380 else if (GET_CODE (x) == PLUS)
2382 rtx x1 = XEXP (x, 0);
2383 rtx x2 = XEXP (x, 1);
2385 /* Try swap the order. FIXME: Do we need this? */
2395 fprintf (stream, "%s,", reg_names[REGNO (x1)]);
2399 fprintf (stream, "%s", reg_names[REGNO (x2)]);
2402 else if (GET_CODE (x2) == CONST_INT
2403 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
2405 output_addr_const (stream, x2);
2411 fatal_insn ("MMIX Internal: This is not a recognized address", x);
2414 /* ASM_OUTPUT_REG_PUSH. */
2417 mmix_asm_output_reg_push (stream, regno)
2421 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
2422 reg_names[MMIX_STACK_POINTER_REGNUM],
2423 reg_names[MMIX_STACK_POINTER_REGNUM],
2425 reg_names[MMIX_STACK_POINTER_REGNUM]);
2428 /* ASM_OUTPUT_REG_POP. */
2431 mmix_asm_output_reg_pop (stream, regno)
2435 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
2437 reg_names[MMIX_STACK_POINTER_REGNUM],
2438 reg_names[MMIX_STACK_POINTER_REGNUM]);
2441 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
2444 mmix_asm_output_addr_diff_elt (stream, body, value, rel)
2446 rtx body ATTRIBUTE_UNUSED;
2450 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
2453 /* ASM_OUTPUT_ADDR_VEC_ELT. */
2456 mmix_asm_output_addr_vec_elt (stream, value)
2460 fprintf (stream, "\tOCTA L:%d\n", value);
2463 /* ASM_OUTPUT_SKIP. */
2466 mmix_asm_output_skip (stream, nbytes)
2470 fprintf (stream, "\tLOC @+%d\n", nbytes);
2473 /* ASM_OUTPUT_ALIGN. */
2476 mmix_asm_output_align (stream, power)
2480 /* We need to record the needed alignment of this section in the object,
2481 so we have to output an alignment directive. Use a .p2align (not
2482 .align) so people will never have to wonder about whether the
2483 argument is in number of bytes or the log2 thereof. We do it in
2484 addition to the LOC directive, so nothing needs tweaking when
2485 copy-pasting assembly into mmixal. */
2486 fprintf (stream, "\t.p2align %d\n", power);
2487 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
2490 /* DBX_REGISTER_NUMBER. */
2493 mmix_dbx_register_number (regno)
2496 /* FIXME: Implement final register renumbering if necessary. (Use
2497 target state in cfun). */
2499 /* We need to renumber registers to get the number of the return address
2500 register in the range 0..255. It is also space-saving if registers
2501 mentioned in the call-frame information (which uses this function by
2502 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
2503 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
2504 return regno >= 224 ? (regno - 224) : (regno + 48);
2507 /* End of target macro support functions.
2509 Now MMIX's own functions. First the exported ones. */
2511 /* Output an optimal sequence for setting a register to a specific
2512 constant. Used in an alternative for const_ints in movdi, and when
2513 using large stack-frame offsets.
2515 Use do_begin_end to say if a line-starting TAB and newline before the
2516 first insn and after the last insn is wanted. */
2519 mmix_output_register_setting (stream, regno, value, do_begin_end)
2522 HOST_WIDEST_INT value;
2526 fprintf (stream, "\t");
2528 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2530 /* First, the one-insn cases. */
2531 mmix_output_shiftvalue_op_from_str (stream, "SET",
2532 (unsigned HOST_WIDEST_INT)
2534 fprintf (stream, " %s,", reg_names[regno]);
2535 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2537 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2539 /* We do this to get a bit more legible assembly code. The next
2540 alternative is mostly redundant with this. */
2542 mmix_output_shiftvalue_op_from_str (stream, "SET",
2543 -(unsigned HOST_WIDEST_INT)
2545 fprintf (stream, " %s,", reg_names[regno]);
2546 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2547 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2550 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2552 /* Slightly more expensive, the two-insn cases. */
2554 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2555 is shiftable, or any other one-insn transformation of the value.
2556 FIXME: Check first if the value is "shiftable" by two loading
2557 with two insns, since it makes more readable assembly code (if
2558 anyone else cares). */
2560 mmix_output_shiftvalue_op_from_str (stream, "SET",
2561 ~(unsigned HOST_WIDEST_INT)
2563 fprintf (stream, " %s,", reg_names[regno]);
2564 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2565 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2570 /* The generic case. 2..4 insns. */
2571 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2572 const char *op = "SET";
2573 const char *line_begin = "";
2576 /* Output pertinent parts of the 4-wyde sequence.
2577 Still more to do if we want this to be optimal, but hey...
2578 Note that the zero case has been handled above. */
2579 for (i = 0; i < 4 && value != 0; i++)
2583 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2584 higher_parts[i], reg_names[regno],
2585 (int) (value & 65535));
2586 /* The first one sets the rest of the bits to 0, the next
2587 ones add set bits. */
2589 line_begin = "\n\t";
2597 fprintf (stream, "\n");
2600 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2604 mmix_shiftable_wyde_value (value)
2605 unsigned HOST_WIDEST_INT value;
2607 /* Shift by 16 bits per group, stop when we've found two groups with
2610 int has_candidate = 0;
2612 for (i = 0; i < 4; i++)
2628 /* True if this is an address_operand or a symbolic operand. */
2631 mmix_symbolic_or_address_operand (op, mode)
2633 enum machine_mode mode;
2635 switch (GET_CODE (op))
2642 if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2643 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
2644 && (GET_CODE (XEXP (op, 1)) == CONST_INT
2645 || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE
2646 && GET_MODE (XEXP (op, 1)) == VOIDmode)))
2650 return address_operand (op, mode);
2654 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2655 We could narrow the value down with a couple of predicated, but that
2656 doesn't seem to be worth it at the moment. */
2659 mmix_reg_or_constant_operand (op, mode)
2661 enum machine_mode mode;
2663 return register_operand (op, mode)
2664 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
2665 || GET_CODE (op) == CONST_INT;
2668 /* True if this is a register with a condition-code mode. */
2671 mmix_reg_cc_operand (op, mode)
2673 enum machine_mode mode;
2675 if (mode == VOIDmode)
2676 mode = GET_MODE (op);
2678 return register_operand (op, mode)
2679 && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode
2680 || mode == CC_FPEQmode || mode == CC_FUNmode);
2683 /* True if this is a foldable comparison operator
2684 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2685 replaced by (reg). */
2688 mmix_foldable_comparison_operator (op, mode)
2690 enum machine_mode mode;
2692 RTX_CODE code = GET_CODE (op);
2694 if (mode == VOIDmode)
2695 mode = GET_MODE (op);
2697 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2698 mode = GET_MODE (XEXP (op, 0));
2700 return ((mode == CCmode || mode == DImode)
2701 && (code == NE || code == EQ || code == GE || code == GT
2703 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2704 reverse the condition? Can it do that by itself? Maybe it can
2705 even reverse the condition to fit a foldable one in the first
2707 || (mode == CC_UNSmode && (code == GTU || code == LEU));
2710 /* Like comparison_operator, but only true if this comparison operator is
2711 applied to a valid mode. Needed to avoid jump.c generating invalid
2712 code with -ffast-math (gcc.dg/20001228-1.c). */
2715 mmix_comparison_operator (op, mode)
2717 enum machine_mode mode;
2719 RTX_CODE code = GET_CODE (op);
2721 /* Comparison operators usually don't have a mode, but let's try and get
2722 one anyway for the day that changes. */
2723 if (mode == VOIDmode)
2724 mode = GET_MODE (op);
2726 /* Get the mode from the first operand if we don't have one. */
2727 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2728 mode = GET_MODE (XEXP (op, 0));
2730 /* FIXME: This needs to be kept in sync with the tables in
2731 mmix_output_condition. */
2733 (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2734 || (mode == CC_FUNmode
2735 && (code == ORDERED || code == UNORDERED))
2736 || (mode == CC_FPmode
2737 && (code == GT || code == LT))
2738 || (mode == CC_FPEQmode
2739 && (code == NE || code == EQ))
2740 || (mode == CC_UNSmode
2741 && (code == GEU || code == GTU || code == LEU || code == LTU))
2743 && (code == NE || code == EQ || code == GE || code == GT
2744 || code == LE || code == LT))
2746 && (code == NE || code == EQ || code == GE || code == GT
2747 || code == LE || code == LT || code == LEU || code == GTU));
2750 /* True if this is a register or 0 (int or float). */
2753 mmix_reg_or_0_operand (op, mode)
2755 enum machine_mode mode;
2757 /* FIXME: Is mode calculation necessary and correct? */
2759 op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode)
2760 || register_operand (op, mode);
2763 /* True if this is a register or an int 0..255. */
2766 mmix_reg_or_8bit_operand (op, mode)
2768 enum machine_mode mode;
2770 return register_operand (op, mode)
2771 || (GET_CODE (op) == CONST_INT
2772 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
2775 /* True if this is a register or an int 0..256. We include 256,
2776 because it can be canonicalized into 255 for comparisons, which is
2777 currently the only use of this predicate.
2778 FIXME: Check that this happens and does TRT. */
2781 mmix_reg_or_8bit_or_256_operand (op, mode)
2783 enum machine_mode mode;
2785 return mmix_reg_or_8bit_operand (op, mode)
2786 || (GET_CODE (op) == CONST_INT && INTVAL (op) == 256);
2789 /* Returns zero if code and mode is not a valid condition from a
2790 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2791 is the comparison of mode is CC-somethingmode. */
2794 mmix_valid_comparison (code, mode, op)
2796 enum machine_mode mode;
2799 if (mode == VOIDmode && op != NULL_RTX)
2800 mode = GET_MODE (op);
2802 /* We don't care to look at these, they should always be valid. */
2803 if (mode == CCmode || mode == CC_UNSmode || mode == DImode)
2806 if ((mode == CC_FPmode || mode == DFmode)
2807 && (code == GT || code == LT))
2810 if ((mode == CC_FPEQmode || mode == DFmode)
2811 && (code == EQ || code == NE))
2814 if ((mode == CC_FUNmode || mode == DFmode)
2815 && (code == ORDERED || code == UNORDERED))
2821 /* X and Y are two things to compare using CODE. Emit a compare insn if
2822 possible and return the rtx for the cc-reg in the proper mode, or
2823 NULL_RTX if this is not a valid comparison. */
2826 mmix_gen_compare_reg (code, x, y)
2830 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2833 /* FIXME: Do we get constants here? Of double mode? */
2834 enum machine_mode mode
2835 = GET_MODE (x) == VOIDmode
2837 : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode;
2839 if (! mmix_valid_comparison (code, mode, x))
2842 cc_reg = gen_reg_rtx (ccmode);
2844 /* FIXME: Can we avoid emitting a compare insn here? */
2845 if (! REG_P (x) && ! REG_P (y))
2846 x = force_reg (mode, x);
2848 CANONICALIZE_COMPARISON (code, x, y);
2850 /* If it's not quite right yet, put y in a register. */
2852 && (GET_CODE (y) != CONST_INT
2853 || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I')))
2854 y = force_reg (mode, y);
2856 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2857 gen_rtx_COMPARE (ccmode, x, y)));
2862 /* Local (static) helper functions. */
2864 /* Print operator suitable for doing something with a shiftable
2865 wyde. The type of operator is passed as an asm output modifier. */
2868 mmix_output_shiftvalue_op_from_str (stream, mainop, value)
2871 HOST_WIDEST_INT value;
2873 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2876 if (! mmix_shiftable_wyde_value (value))
2878 char s[sizeof ("0xffffffffffffffff")];
2879 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2880 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2883 for (i = 0; i < 4; i++)
2885 /* We know we're through when we find one-bits in the low
2889 fprintf (stream, "%s%s", mainop, op_part[i]);
2895 /* No bits set? Then it must have been zero. */
2896 fprintf (stream, "%sL", mainop);
2899 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2902 mmix_output_octa (stream, value, do_begin_end)
2904 HOST_WIDEST_INT value;
2907 /* Snipped from final.c:output_addr_const. We need to avoid the
2908 presumed universal "0x" prefix. We can do it by replacing "0x" with
2909 "#0" here; we must avoid a space in the operands and no, the zero
2910 won't cause the number to be assumed in octal format. */
2911 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2914 fprintf (stream, "\tOCTA ");
2916 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2917 hex_format[0] = '#';
2918 hex_format[1] = '0';
2920 /* Provide a few alternative output formats depending on the number, to
2921 improve legibility of assembler output. */
2922 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2923 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2924 fprintf (stream, "%d", (int) value);
2925 else if (value > (HOST_WIDEST_INT) 0
2926 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2927 fprintf (stream, "#%x", (unsigned int) value);
2929 fprintf (stream, hex_format, value);
2932 fprintf (stream, "\n");
2935 /* Print the presumed shiftable wyde argument shifted into place (to
2936 be output with an operand). */
2939 mmix_output_shifted_value (stream, value)
2941 HOST_WIDEST_INT value;
2945 if (! mmix_shiftable_wyde_value (value))
2948 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2949 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2952 for (i = 0; i < 4; i++)
2954 /* We know we're through when we find one-bits in the low 16 bits. */
2957 fprintf (stream, "#%x", (int) (value & 0xffff));
2964 /* No bits set? Then it must have been zero. */
2965 fprintf (stream, "0");
2968 /* Output an MMIX condition name corresponding to an operator
2970 (comparison_operator [(comparison_operator ...) (const_int 0)])
2971 which means we have to look at *two* operators.
2973 The argument "reversed" refers to reversal of the condition (not the
2974 same as swapping the arguments). */
2977 mmix_output_condition (stream, x, reversed)
2986 /* The normal output cc-code. */
2987 const char *const normal;
2989 /* The reversed cc-code, or NULL if invalid. */
2990 const char *const reversed;
2995 enum machine_mode cc_mode;
2997 /* Terminated with {NIL, NULL, NULL} */
2998 const struct cc_conv *const convs;
3002 #define CCEND {NIL, NULL, NULL}
3004 static const struct cc_conv cc_fun_convs[]
3005 = {{ORDERED, "Z", "P"},
3006 {UNORDERED, "P", "Z"},
3008 static const struct cc_conv cc_fp_convs[]
3012 static const struct cc_conv cc_fpeq_convs[]
3016 static const struct cc_conv cc_uns_convs[]
3017 = {{GEU, "NN", "N"},
3022 static const struct cc_conv cc_signed_convs[]
3030 static const struct cc_conv cc_di_convs[]
3042 static const struct cc_type_conv cc_convs[]
3043 = {{CC_FUNmode, cc_fun_convs},
3044 {CC_FPmode, cc_fp_convs},
3045 {CC_FPEQmode, cc_fpeq_convs},
3046 {CC_UNSmode, cc_uns_convs},
3047 {CCmode, cc_signed_convs},
3048 {DImode, cc_di_convs}};
3053 enum machine_mode mode = GET_MODE (XEXP (x, 0));
3054 RTX_CODE cc = GET_CODE (x);
3056 for (i = 0; i < sizeof (cc_convs)/sizeof(*cc_convs); i++)
3058 if (mode == cc_convs[i].cc_mode)
3060 for (j = 0; cc_convs[i].convs[j].cc != NIL; j++)
3061 if (cc == cc_convs[i].convs[j].cc)
3064 = (reversed ? cc_convs[i].convs[j].reversed
3065 : cc_convs[i].convs[j].normal);
3067 if (mmix_cc == NULL)
3068 fatal_insn ("MMIX Internal: Trying to output invalidly\
3069 reversed condition:", x);
3071 fprintf (stream, "%s", mmix_cc);
3075 fatal_insn ("MMIX Internal: What's the CC of this?", x);
3079 fatal_insn ("MMIX Internal: What is the CC of this?", x);
3082 /* Return the bit-value for a const_int or const_double. */
3084 static HOST_WIDEST_INT
3088 unsigned HOST_WIDEST_INT retval;
3090 if (GET_CODE (x) == CONST_INT)
3093 /* We make a little song and dance because converting to long long in
3094 gcc-2.7.2 is broken. I still want people to be able to use it for
3095 cross-compilation to MMIX. */
3096 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
3098 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
3100 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
3102 retval |= CONST_DOUBLE_LOW (x) & 1;
3105 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
3106 << (HOST_BITS_PER_LONG);
3109 retval = CONST_DOUBLE_HIGH (x);
3114 if (GET_CODE (x) == CONST_DOUBLE)
3116 REAL_VALUE_TYPE value;
3118 /* FIXME: This macro is not in the manual but should be. */
3119 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
3121 if (GET_MODE (x) == DFmode)
3125 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
3127 if (sizeof (long) < sizeof (HOST_WIDEST_INT))
3129 retval = (unsigned long) bits[1] / 2;
3131 retval |= (unsigned long) bits[1] & 1;
3133 |= (unsigned HOST_WIDEST_INT) bits[0]
3134 << (sizeof (bits[0]) * 8);
3137 retval = (unsigned long) bits[1];
3141 else if (GET_MODE (x) == SFmode)
3144 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
3146 return (unsigned long) bits;
3150 fatal_insn ("MMIX Internal: This is not a constant:", x);
3155 * eval: (c-set-style "gnu")
3156 * indent-tabs-mode: t