* config/mmix/mmix.c: Remove extra broken prototype for
[official-gcc.git] / gcc / config / mmix / mmix.c
blob6e66c9f8d06b5566f5cd4c1206fc1dce46529eb2
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)
10 any later version.
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. */
22 #include "config.h"
23 #include "system.h"
24 #include "rtl.h"
25 #include "regs.h"
26 #include "hard-reg-set.h"
27 #include "hashtab.h"
28 #include "insn-config.h"
29 #include "output.h"
30 #include "flags.h"
31 #include "tree.h"
32 #include "function.h"
33 #include "expr.h"
34 #include "toplev.h"
35 #include "recog.h"
36 #include "ggc.h"
37 #include "dwarf2.h"
38 #include "debug.h"
39 #include "tm_p.h"
40 #include "integrate.h"
41 #include "target.h"
42 #include "target-def.h"
43 #include "real.h"
45 /* First some local helper definitions. */
46 #define MMIX_FIRST_GLOBAL_REGNUM 32
48 /* We'd need a current_function_has_landing_pad. It's marked as such when
49 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
50 mostly. */
51 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
53 /* We have no means to tell DWARF 2 about the register stack, so we need
54 to store the return address on the stack if an exception can get into
55 this function. FIXME: Narrow condition. */
56 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
57 (flag_exceptions && ! leaf_function_p ())
59 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
60 (current_function_calls_eh_return \
61 && (EH_RETURN_DATA_REGNO (0) == REGNO \
62 || EH_RETURN_DATA_REGNO (1) == REGNO \
63 || EH_RETURN_DATA_REGNO (2) == REGNO \
64 || EH_RETURN_DATA_REGNO (3) == REGNO))
66 /* For the default ABI, we rename registers at output-time to fill the gap
67 between the (statically partitioned) saved registers and call-clobbered
68 registers. In effect this makes unused call-saved registers to be used
69 as call-clobbered registers. The benefit comes from keeping the number
70 of local registers (value of rL) low, since there's a cost of
71 increasing rL and clearing unused (unset) registers with lower numbers. */
72 #define MMIX_OUTPUT_REGNO(N) \
73 (TARGET_ABI_GNU \
74 || (N) < MMIX_RETURN_VALUE_REGNUM \
75 || (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
76 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
77 + cfun->machine->highest_saved_stack_register + 1))
79 /* The canonical saved comparison operands for non-cc0 machines, set in
80 the compare expander. */
81 rtx mmix_compare_op0;
82 rtx mmix_compare_op1;
84 /* We ignore some options with arguments. They are passed to the linker,
85 but also ends up here because they start with "-m". We tell the driver
86 to store them in a variable we don't inspect. */
87 const char *mmix_cc1_ignored_option;
89 /* Declarations of locals. */
91 /* Intermediate for insn output. */
92 static int mmix_output_destination_register;
94 static void mmix_output_shiftvalue_op_from_str
95 PARAMS ((FILE *, const char *, HOST_WIDEST_INT));
96 static void mmix_output_shifted_value PARAMS ((FILE *, HOST_WIDEST_INT));
97 static void mmix_output_condition PARAMS ((FILE *, rtx, int));
98 static HOST_WIDEST_INT mmix_intval PARAMS ((rtx));
99 static void mmix_output_octa PARAMS ((FILE *, HOST_WIDEST_INT, int));
100 static bool mmix_assemble_integer PARAMS ((rtx, unsigned int, int));
101 static struct machine_function * mmix_init_machine_status PARAMS ((void));
102 static void mmix_encode_section_info PARAMS ((tree, int));
103 static const char *mmix_strip_name_encoding PARAMS ((const char *));
105 extern void mmix_target_asm_function_prologue
106 PARAMS ((FILE *, HOST_WIDE_INT));
107 extern void mmix_target_asm_function_epilogue
108 PARAMS ((FILE *, HOST_WIDE_INT));
111 /* Target structure macros. Listed by node. See `Using and Porting GCC'
112 for a general description. */
114 /* Node: Function Entry */
116 #undef TARGET_ASM_BYTE_OP
117 #define TARGET_ASM_BYTE_OP NULL
118 #undef TARGET_ASM_ALIGNED_HI_OP
119 #define TARGET_ASM_ALIGNED_HI_OP NULL
120 #undef TARGET_ASM_ALIGNED_SI_OP
121 #define TARGET_ASM_ALIGNED_SI_OP NULL
122 #undef TARGET_ASM_ALIGNED_DI_OP
123 #define TARGET_ASM_ALIGNED_DI_OP NULL
124 #undef TARGET_ASM_INTEGER
125 #define TARGET_ASM_INTEGER mmix_assemble_integer
127 #undef TARGET_ASM_FUNCTION_PROLOGUE
128 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
130 #undef TARGET_ASM_FUNCTION_EPILOGUE
131 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
133 #undef TARGET_ENCODE_SECTION_INFO
134 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
135 #undef TARGET_STRIP_NAME_ENCODING
136 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
138 struct gcc_target targetm = TARGET_INITIALIZER;
140 /* Functions that are expansions for target macros.
141 See Target Macros in `Using and Porting GCC'. */
143 /* OVERRIDE_OPTIONS. */
145 void
146 mmix_override_options ()
148 /* Should we err or should we warn? Hmm. At least we must neutralize
149 it. For example the wrong kind of case-tables will be generated with
150 PIC; we use absolute address items for mmixal compatibility. FIXME:
151 They could be relative if we just elide them to after all pertinent
152 labels. */
153 if (flag_pic)
155 warning ("-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
156 flag_pic = 0;
160 /* INIT_EXPANDERS. */
162 void
163 mmix_init_expanders ()
165 init_machine_status = mmix_init_machine_status;
168 /* Set the per-function data. */
170 static struct machine_function *
171 mmix_init_machine_status ()
173 return ggc_alloc_cleared (sizeof (struct machine_function));
176 /* DATA_ALIGNMENT.
177 We have trouble getting the address of stuff that is located at other
178 than 32-bit alignments (GETA requirements), so try to give everything
179 at least 32-bit alignment. */
182 mmix_data_alignment (type, basic_align)
183 tree type ATTRIBUTE_UNUSED;
184 int basic_align;
186 if (basic_align < 32)
187 return 32;
189 return basic_align;
192 /* CONSTANT_ALIGNMENT. */
195 mmix_constant_alignment (constant, basic_align)
196 tree constant ATTRIBUTE_UNUSED;
197 int basic_align;
199 if (basic_align < 32)
200 return 32;
202 return basic_align;
205 /* LOCAL_ALIGNMENT. */
208 mmix_local_alignment (type, basic_align)
209 tree type ATTRIBUTE_UNUSED;
210 int basic_align;
212 if (basic_align < 32)
213 return 32;
215 return basic_align;
218 /* CONDITIONAL_REGISTER_USAGE. */
220 void
221 mmix_conditional_register_usage ()
223 int i;
225 if (TARGET_ABI_GNU)
227 static const int gnu_abi_reg_alloc_order[]
228 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
230 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
231 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
233 /* Change the default from the mmixware ABI. For the GNU ABI,
234 $15..$30 are call-saved just as $0..$14. There must be one
235 call-clobbered local register for the "hole" describing number of
236 saved local registers saved by PUSHJ/PUSHGO during the function
237 call, receiving the return value at return. So best is to use
238 the highest, $31. It's already marked call-clobbered for the
239 mmixware ABI. */
240 for (i = 15; i <= 30; i++)
241 call_used_regs[i] = 0;
243 /* "Unfix" the parameter registers. */
244 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
245 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
246 i++)
247 fixed_regs[i] = 0;
250 /* Step over the ":" in special register names. */
251 if (! TARGET_TOPLEVEL_SYMBOLS)
252 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
253 if (reg_names[i][0] == ':')
254 reg_names[i]++;
257 /* PREFERRED_RELOAD_CLASS.
258 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
260 enum reg_class
261 mmix_preferred_reload_class (x, class)
262 rtx x ATTRIBUTE_UNUSED;
263 enum reg_class class;
265 /* FIXME: Revisit. */
266 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
267 ? REMAINDER_REG : class;
270 /* PREFERRED_OUTPUT_RELOAD_CLASS.
271 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
273 enum reg_class
274 mmix_preferred_output_reload_class (x, class)
275 rtx x ATTRIBUTE_UNUSED;
276 enum reg_class class;
278 /* FIXME: Revisit. */
279 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
280 ? REMAINDER_REG : class;
283 /* SECONDARY_RELOAD_CLASS.
284 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
286 enum reg_class
287 mmix_secondary_reload_class (class, mode, x, in_p)
288 enum reg_class class;
289 enum machine_mode mode ATTRIBUTE_UNUSED;
290 rtx x ATTRIBUTE_UNUSED;
291 int in_p ATTRIBUTE_UNUSED;
293 if (class == REMAINDER_REG
294 || class == HIMULT_REG
295 || class == SYSTEM_REGS)
296 return GENERAL_REGS;
298 return NO_REGS;
301 /* CONST_OK_FOR_LETTER_P. */
304 mmix_const_ok_for_letter_p (value, c)
305 HOST_WIDE_INT value;
306 int c;
308 return
309 (c == 'I' ? value >= 0 && value <= 255
310 : c == 'J' ? value >= 0 && value <= 65535
311 : c == 'K' ? value <= 0 && value >= -255
312 : c == 'L' ? mmix_shiftable_wyde_value (value)
313 : c == 'M' ? value == 0
314 : c == 'N' ? mmix_shiftable_wyde_value (~value)
315 : c == 'O' ? (value == 3 || value == 5 || value == 9
316 || value == 17)
317 : 0);
320 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
323 mmix_const_double_ok_for_letter_p (value, c)
324 rtx value;
325 int c;
327 return
328 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
329 : 0);
332 /* EXTRA_CONSTRAINT.
333 We need this since our constants are not always expressible as
334 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
337 mmix_extra_constraint (x, c, strict)
338 rtx x;
339 int c;
340 int strict;
342 HOST_WIDEST_INT value;
344 /* When checking for an address, we need to handle strict vs. non-strict
345 register checks. Don't use address_operand, but instead its
346 equivalent (its callee, which it is just a wrapper for),
347 memory_operand_p and the strict-equivalent strict_memory_address_p. */
348 if (c == 'U')
349 return
350 strict
351 ? strict_memory_address_p (Pmode, x)
352 : memory_address_p (Pmode, x);
354 /* R asks whether x is to be loaded with GETA or something else. Right
355 now, only a SYMBOL_REF and LABEL_REF can fit for
356 TARGET_BASE_ADDRESSES.
358 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
359 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
360 set right now; only function addresses and code labels. If we change
361 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
362 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
363 effect, a "raw" constant check together with mmix_constant_address_p
364 is all that's needed; we want all constant addresses to be loaded
365 with GETA then. */
366 if (c == 'R')
367 return
368 GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE
369 && mmix_constant_address_p (x)
370 && (! TARGET_BASE_ADDRESSES
371 || (GET_CODE (x) == LABEL_REF
372 || (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))));
374 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
375 return 0;
377 value = mmix_intval (x);
379 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
380 more ('U' taken for address_operand, 'R' similarly). Some letters map
381 outside of CONST_INT, though; we still use 'S' and 'T'. */
382 if (c == 'S')
383 return mmix_shiftable_wyde_value (value);
384 else if (c == 'T')
385 return mmix_shiftable_wyde_value (~value);
386 return 0;
389 /* DYNAMIC_CHAIN_ADDRESS. */
392 mmix_dynamic_chain_address (frame)
393 rtx frame;
395 /* FIXME: the frame-pointer is stored at offset -8 from the current
396 frame-pointer. Unfortunately, the caller assumes that a
397 frame-pointer is present for *all* previous frames. There should be
398 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
399 return plus_constant (frame, -8);
402 /* STARTING_FRAME_OFFSET. */
405 mmix_starting_frame_offset ()
407 /* The old frame pointer is in the slot below the new one, so
408 FIRST_PARM_OFFSET does not need to depend on whether the
409 frame-pointer is needed or not. We have to adjust for the register
410 stack pointer being located below the saved frame pointer.
411 Similarly, we store the return address on the stack too, for
412 exception handling, and always if we save the register stack pointer. */
413 return
415 + (MMIX_CFUN_HAS_LANDING_PAD
416 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
419 /* RETURN_ADDR_RTX. */
422 mmix_return_addr_rtx (count, frame)
423 int count;
424 rtx frame ATTRIBUTE_UNUSED;
426 return count == 0
427 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
428 /* FIXME: Set frame_alias_set on the following. (Why?)
429 See mmix_initial_elimination_offset for the reason we can't use
430 get_hard_reg_initial_val for both. Always using a stack slot
431 and not a register would be suboptimal. */
432 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
433 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
434 : NULL_RTX;
437 /* SETUP_FRAME_ADDRESSES. */
439 void
440 mmix_setup_frame_addresses ()
442 /* Nothing needed at the moment. */
445 /* The difference between the (imaginary) frame pointer and the stack
446 pointer. Used to eliminate the frame pointer. */
449 mmix_initial_elimination_offset (fromreg, toreg)
450 int fromreg;
451 int toreg;
453 int regno;
454 int fp_sp_offset
455 = (get_frame_size () + current_function_outgoing_args_size + 7) & ~7;
457 /* There is no actual offset between these two virtual values, but for
458 the frame-pointer, we have the old one in the stack position below
459 it, so the offset for the frame-pointer to the stack-pointer is one
460 octabyte larger. */
461 if (fromreg == MMIX_ARG_POINTER_REGNUM
462 && toreg == MMIX_FRAME_POINTER_REGNUM)
463 return 0;
465 /* The difference is the size of local variables plus the size of
466 outgoing function arguments that would normally be passed as
467 registers but must be passed on stack because we're out of
468 function-argument registers. Only global saved registers are
469 counted; the others go on the register stack.
471 The frame-pointer is counted too if it is what is eliminated, as we
472 need to balance the offset for it from STARTING_FRAME_OFFSET.
474 Also add in the slot for the register stack pointer we save if we
475 have a landing pad.
477 Unfortunately, we can't access $0..$14, from unwinder code easily, so
478 store the return address in a frame slot too. FIXME: Only for
479 non-leaf functions. FIXME: Always with a landing pad, because it's
480 hard to know whether we need the other at the time we know we need
481 the offset for one (and have to state it). It's a kludge until we
482 can express the register stack in the EH frame info.
484 We have to do alignment here; get_frame_size will not return a
485 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
487 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
488 regno <= 255;
489 regno++)
490 if ((regs_ever_live[regno] && ! call_used_regs[regno])
491 || IS_MMIX_EH_RETURN_DATA_REG (regno))
492 fp_sp_offset += 8;
494 return fp_sp_offset
495 + (MMIX_CFUN_HAS_LANDING_PAD
496 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
497 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
500 /* Return an rtx for a function argument to go in a register, and 0 for
501 one that must go on stack. */
504 mmix_function_arg (argsp, mode, type, named, incoming)
505 const CUMULATIVE_ARGS * argsp;
506 enum machine_mode mode;
507 tree type;
508 int named ATTRIBUTE_UNUSED;
509 int incoming;
511 /* Handling of the positional dummy parameter for varargs gets nasty.
512 Check execute/991216-3 and function.c:assign_params. We have to say
513 that the dummy parameter goes on stack in order to get the correct
514 offset when va_start and va_arg is applied. FIXME: Should do TRT by
515 itself in the gcc core. */
516 if ((! named && incoming && current_function_varargs) || argsp->now_varargs)
517 return NULL_RTX;
519 /* Last-argument marker. */
520 if (type == void_type_node)
521 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
522 ? gen_rtx_REG (mode,
523 (incoming
524 ? MMIX_FIRST_INCOMING_ARG_REGNUM
525 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
526 : NULL_RTX;
528 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
529 && !MUST_PASS_IN_STACK (mode, type)
530 && (GET_MODE_BITSIZE (mode) <= 64
531 || argsp->lib
532 || TARGET_LIBFUNC))
533 ? gen_rtx_REG (mode,
534 (incoming
535 ? MMIX_FIRST_INCOMING_ARG_REGNUM
536 : MMIX_FIRST_ARG_REGNUM)
537 + argsp->regs)
538 : NULL_RTX;
541 /* Returns nonzero for everything that goes by reference, 0 for
542 everything that goes by value. */
545 mmix_function_arg_pass_by_reference (argsp, mode, type, named)
546 const CUMULATIVE_ARGS * argsp;
547 enum machine_mode mode;
548 tree type;
549 int named ATTRIBUTE_UNUSED;
551 /* FIXME: Check: I'm not sure the MUST_PASS_IN_STACK check is
552 necessary. */
553 return
554 MUST_PASS_IN_STACK (mode, type)
555 || (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
556 && !TARGET_LIBFUNC
557 && !argsp->lib);
560 /* Return nonzero if regno is a register number where a parameter is
561 passed, and 0 otherwise. */
564 mmix_function_arg_regno_p (regno, incoming)
565 int regno;
566 int incoming;
568 int first_arg_regnum
569 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
571 return regno >= first_arg_regnum
572 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
575 /* FUNCTION_OUTGOING_VALUE. */
578 mmix_function_outgoing_value (valtype, func)
579 tree valtype;
580 tree func ATTRIBUTE_UNUSED;
582 enum machine_mode mode = TYPE_MODE (valtype);
583 enum machine_mode cmode;
584 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
585 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
586 int i;
587 int nregs;
589 /* Return values that fit in a register need no special handling.
590 There's no register hole when parameters are passed in global
591 registers. */
592 if (TARGET_ABI_GNU
593 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
594 return
595 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
597 /* A complex type, made up of components. */
598 cmode = TYPE_MODE (TREE_TYPE (valtype));
599 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
601 /* We need to take care of the effect of the register hole on return
602 values of large sizes; the last register will appear as the first
603 register, with the rest shifted. (For complex modes, this is just
604 swapped registers.) */
606 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
607 internal_error ("too large function value type, needs %d registers,\
608 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
610 /* FIXME: Maybe we should handle structure values like this too
611 (adjusted for BLKmode), perhaps for both ABI:s. */
612 for (i = 0; i < nregs - 1; i++)
613 vec[i]
614 = gen_rtx_EXPR_LIST (VOIDmode,
615 gen_rtx_REG (cmode, first_val_regnum + i),
616 GEN_INT ((i + 1) * BITS_PER_UNIT));
618 vec[nregs - 1]
619 = gen_rtx_EXPR_LIST (VOIDmode,
620 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
621 GEN_INT (0));
623 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
626 /* EH_RETURN_DATA_REGNO. */
629 mmix_eh_return_data_regno (n)
630 int n ATTRIBUTE_UNUSED;
632 if (n >= 0 && n < 4)
633 return MMIX_EH_RETURN_DATA_REGNO_START + n;
635 return INVALID_REGNUM;
638 /* EH_RETURN_STACKADJ_RTX. */
641 mmix_eh_return_stackadj_rtx ()
643 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
646 /* EH_RETURN_HANDLER_RTX. */
649 mmix_eh_return_handler_rtx ()
651 return
652 gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
655 /* ASM_PREFERRED_EH_DATA_FORMAT. */
658 mmix_asm_preferred_eh_data_format (code, global)
659 int code ATTRIBUTE_UNUSED;
660 int global ATTRIBUTE_UNUSED;
662 /* This is the default (was at 2001-07-20). Revisit when needed. */
663 return DW_EH_PE_absptr;
666 /* Emit the function prologue. For simplicity while the port is still
667 in a flux, we do it as text rather than the now preferred RTL way,
668 as (define_insn "function_prologue").
670 FIXME: Translate to RTL and/or optimize some of the DWARF 2 stuff. */
672 void
673 mmix_target_asm_function_prologue (stream, locals_size)
674 FILE *stream;
675 HOST_WIDE_INT locals_size;
677 int regno;
678 int stack_space_to_allocate
679 = (current_function_outgoing_args_size
680 + current_function_pretend_args_size
681 + (int) locals_size + 7) & ~7;
682 int offset = -8;
683 int doing_dwarf = dwarf2out_do_frame ();
684 long cfa_offset = 0;
686 /* Guard our assumptions. Very low priority FIXME. */
687 if (locals_size != (int) locals_size)
688 error ("stack frame too big");
690 /* Add room needed to save global non-register-stack registers. */
691 for (regno = 255;
692 regno >= MMIX_FIRST_GLOBAL_REGNUM;
693 regno--)
694 /* Note that we assume that the frame-pointer-register is one of these
695 registers, in which case we don't count it here. */
696 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
697 && regs_ever_live[regno] && !call_used_regs[regno]))
698 || IS_MMIX_EH_RETURN_DATA_REG (regno))
699 stack_space_to_allocate += 8;
701 /* If we do have a frame-pointer, add room for it. */
702 if (frame_pointer_needed)
703 stack_space_to_allocate += 8;
705 /* If we have a non-local label, we need to be able to unwind to it, so
706 store the current register stack pointer. Also store the return
707 address if we do that. */
708 if (MMIX_CFUN_HAS_LANDING_PAD)
709 stack_space_to_allocate += 16;
710 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
711 /* If we do have a saved return-address slot, add room for it. */
712 stack_space_to_allocate += 8;
714 /* Make sure we don't get an unaligned stack. */
715 if ((stack_space_to_allocate % 8) != 0)
716 internal_error ("stack frame not a multiple of 8 bytes: %d",
717 stack_space_to_allocate);
719 if (current_function_pretend_args_size)
721 int mmix_first_vararg_reg
722 = (MMIX_FIRST_INCOMING_ARG_REGNUM
723 + (MMIX_MAX_ARGS_IN_REGS
724 - current_function_pretend_args_size / 8));
726 for (regno
727 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
728 regno >= mmix_first_vararg_reg;
729 regno--)
731 if (offset < 0)
733 int stack_chunk
734 = stack_space_to_allocate > (256 - 8)
735 ? (256 - 8) : stack_space_to_allocate;
737 fprintf (stream, "\tSUBU %s,%s,%d\n",
738 reg_names[MMIX_STACK_POINTER_REGNUM],
739 reg_names[MMIX_STACK_POINTER_REGNUM],
740 stack_chunk);
742 if (doing_dwarf)
744 /* Each call to dwarf2out_def_cfa overrides the previous
745 setting; they don't accumulate. We must keep track
746 of the offset ourselves. */
747 cfa_offset += stack_chunk;
748 if (!frame_pointer_needed)
749 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
750 cfa_offset);
752 offset += stack_chunk;
753 stack_space_to_allocate -= stack_chunk;
756 fprintf (stream, "\tSTOU %s,%s,%d\n", reg_names[regno],
757 reg_names[MMIX_STACK_POINTER_REGNUM],
758 offset);
760 /* These registers aren't actually saved (as in "will be
761 restored"), so don't tell DWARF2 they're saved. */
763 offset -= 8;
767 /* Store the frame-pointer. */
769 if (frame_pointer_needed)
771 if (offset < 0)
773 /* Get 8 less than otherwise, since we need to reach offset + 8. */
774 int stack_chunk
775 = stack_space_to_allocate > (256 - 8 - 8)
776 ? (256 - 8 - 8) : stack_space_to_allocate;
778 fprintf (stream, "\tSUBU %s,%s,%d\n",
779 reg_names[MMIX_STACK_POINTER_REGNUM],
780 reg_names[MMIX_STACK_POINTER_REGNUM],
781 stack_chunk);
782 if (doing_dwarf)
783 cfa_offset += stack_chunk;
784 offset += stack_chunk;
785 stack_space_to_allocate -= stack_chunk;
788 fprintf (stream, "\tSTOU %s,%s,%d\n\tADDU %s,%s,%d\n",
789 reg_names[MMIX_FRAME_POINTER_REGNUM],
790 reg_names[MMIX_STACK_POINTER_REGNUM],
791 offset,
792 reg_names[MMIX_FRAME_POINTER_REGNUM],
793 reg_names[MMIX_STACK_POINTER_REGNUM],
794 offset + 8);
795 if (doing_dwarf)
797 /* If we're using the frame-pointer, then we just need this CFA
798 definition basing on that value (often equal to the CFA).
799 Further changes to the stack-pointer do not affect the
800 frame-pointer, so we conditionalize them below on
801 !frame_pointer_needed. */
802 dwarf2out_def_cfa ("", MMIX_FRAME_POINTER_REGNUM,
803 -cfa_offset + offset + 8);
805 dwarf2out_reg_save ("", MMIX_FRAME_POINTER_REGNUM,
806 -cfa_offset + offset);
809 offset -= 8;
812 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
814 /* Store the return-address, if one is needed on the stack. We
815 usually store it in a register when needed, but that doesn't work
816 with -fexceptions. */
818 if (offset < 0)
820 /* Get 8 less than otherwise, since we need to reach offset + 8. */
821 int stack_chunk
822 = stack_space_to_allocate > (256 - 8 - 8)
823 ? (256 - 8 - 8) : stack_space_to_allocate;
825 fprintf (stream, "\tSUBU %s,%s,%d\n",
826 reg_names[MMIX_STACK_POINTER_REGNUM],
827 reg_names[MMIX_STACK_POINTER_REGNUM],
828 stack_chunk);
829 if (doing_dwarf)
831 cfa_offset += stack_chunk;
832 if (!frame_pointer_needed)
833 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
834 cfa_offset);
836 offset += stack_chunk;
837 stack_space_to_allocate -= stack_chunk;
840 fprintf (stream, "\tGET $255,rJ\n\tSTOU $255,%s,%d\n",
841 reg_names[MMIX_STACK_POINTER_REGNUM],
842 offset);
843 if (doing_dwarf)
844 dwarf2out_return_save ("", -cfa_offset + offset);
845 offset -= 8;
847 else if (MMIX_CFUN_HAS_LANDING_PAD)
848 offset -= 8;
850 if (MMIX_CFUN_HAS_LANDING_PAD)
852 /* Store the register defining the numbering of local registers, so
853 we know how long to unwind the register stack. */
855 if (offset < 0)
857 /* Get 8 less than otherwise, since we need to reach offset + 8. */
858 int stack_chunk
859 = stack_space_to_allocate > (256 - 8 - 8)
860 ? (256 - 8 - 8) : stack_space_to_allocate;
862 fprintf (stream, "\tSUBU %s,%s,%d\n",
863 reg_names[MMIX_STACK_POINTER_REGNUM],
864 reg_names[MMIX_STACK_POINTER_REGNUM],
865 stack_chunk);
866 offset += stack_chunk;
867 stack_space_to_allocate -= stack_chunk;
869 if (doing_dwarf)
871 cfa_offset += stack_chunk;
872 if (!frame_pointer_needed)
873 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
874 cfa_offset);
878 /* We don't tell dwarf2 about this one; we just have it to unwind
879 the register stack at landing pads. FIXME: It's a kludge because
880 we can't describe the effect of the PUSHJ and PUSHGO insns on the
881 register stack at the moment. Best thing would be to handle it
882 like stack-pointer offsets. Better: some hook into dwarf2out.c
883 to produce DW_CFA_expression:s that specify the increment of rO,
884 and unwind it at eh_return (preferred) or at the landing pad.
885 Then saves to $0..$G-1 could be specified through that register. */
887 fprintf (stream, "\tGET $255,rO\n\tSTOU $255,%s,%d\n",
888 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
890 offset -= 8;
893 /* After the return-address and the frame-pointer, we have the local
894 variables. They're the ones that may have an "unaligned" size. */
895 offset -= (locals_size + 7) & ~7;
897 /* Now store all registers that are global, i.e. not saved by the
898 register file machinery.
900 It is assumed that the frame-pointer is one of these registers, so it
901 is explicitly excluded in the count. */
903 for (regno = 255;
904 regno >= MMIX_FIRST_GLOBAL_REGNUM;
905 regno--)
906 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
907 && regs_ever_live[regno] && ! call_used_regs[regno])
908 || IS_MMIX_EH_RETURN_DATA_REG (regno))
910 if (offset < 0)
912 int stack_chunk;
914 /* Since the local variables go above, we may get a large
915 offset here. */
916 if (offset < -248)
918 /* We're not going to access the locals area in the
919 prologue, so we'll just silently subtract the slab we
920 will not access. */
921 stack_chunk =
922 stack_space_to_allocate > (256 - offset - 8)
923 ? (256 - offset - 8) : stack_space_to_allocate;
925 mmix_output_register_setting (stream, 255, stack_chunk, 1);
926 fprintf (stream, "\tSUBU %s,%s,$255\n",
927 reg_names[MMIX_STACK_POINTER_REGNUM],
928 reg_names[MMIX_STACK_POINTER_REGNUM]);
930 if (doing_dwarf)
932 cfa_offset += stack_chunk;
933 if (!frame_pointer_needed)
934 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
935 cfa_offset);
938 else
940 stack_chunk = stack_space_to_allocate > (256 - 8)
941 ? (256 - 8) : stack_space_to_allocate;
943 fprintf (stream, "\tSUBU %s,%s,%d\n",
944 reg_names[MMIX_STACK_POINTER_REGNUM],
945 reg_names[MMIX_STACK_POINTER_REGNUM], stack_chunk);
946 if (doing_dwarf)
948 cfa_offset += stack_chunk;
949 if (!frame_pointer_needed)
950 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
951 cfa_offset);
955 offset += stack_chunk;
956 stack_space_to_allocate -= stack_chunk;
959 fprintf (stream, "\tSTOU %s,%s,%d\n", reg_names[regno],
960 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
961 if (doing_dwarf)
962 dwarf2out_reg_save ("", regno, -cfa_offset + offset);
963 offset -= 8;
966 /* Finally, allocate room for outgoing args and local vars if room
967 wasn't allocated above. This might be any number of bytes (well, we
968 assume it fits in a host-int). */
969 if (stack_space_to_allocate)
971 if (stack_space_to_allocate < 256)
973 fprintf (stream, "\tSUBU %s,%s,%d\n",
974 reg_names[MMIX_STACK_POINTER_REGNUM],
975 reg_names[MMIX_STACK_POINTER_REGNUM],
976 stack_space_to_allocate);
978 else
980 mmix_output_register_setting (stream, 255,
981 stack_space_to_allocate, 1);
982 fprintf (stream, "\tSUBU %s,%s,$255\n",
983 reg_names[MMIX_STACK_POINTER_REGNUM],
984 reg_names[MMIX_STACK_POINTER_REGNUM]);
987 if (doing_dwarf)
989 cfa_offset += stack_space_to_allocate;
990 if (!frame_pointer_needed)
991 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
992 cfa_offset);
997 /* MACHINE_DEPENDENT_REORG.
998 No actual rearrangements done here; just virtually by calculating the
999 highest saved stack register number used to modify the register numbers
1000 at output time. */
1002 void
1003 mmix_machine_dependent_reorg (first)
1004 rtx first ATTRIBUTE_UNUSED;
1006 int regno;
1008 /* We put the number of the highest saved register-file register in a
1009 location convenient for the call-patterns to output. Note that we
1010 don't tell dwarf2 about these registers, since it can't restore them
1011 anyway. */
1012 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
1013 regno >= 0;
1014 regno--)
1015 if ((regs_ever_live[regno] && !call_used_regs[regno])
1016 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
1017 break;
1019 /* Regardless of whether they're saved (they might be just read), we
1020 mustn't include registers that carry parameters. We could scan the
1021 insns to see whether they're actually used (and indeed do other less
1022 trivial register usage analysis and transformations), but it seems
1023 wasteful to optimize for unused parameter registers. As of
1024 2002-04-30, regs_ever_live[n] seems to be set for only-reads too, but
1025 that might change. */
1026 if (!TARGET_ABI_GNU && regno < current_function_args_info.regs - 1)
1028 regno = current_function_args_info.regs - 1;
1030 /* We don't want to let this cause us to go over the limit and make
1031 incoming parameter registers be misnumbered and treating the last
1032 parameter register and incoming return value register call-saved.
1033 Stop things at the unmodified scheme. */
1034 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
1035 regno = MMIX_RETURN_VALUE_REGNUM - 1;
1038 cfun->machine->highest_saved_stack_register = regno;
1041 /* TARGET_ASM_FUNCTION_EPILOGUE. */
1043 void
1044 mmix_target_asm_function_epilogue (stream, locals_size)
1045 FILE *stream;
1046 HOST_WIDE_INT locals_size;
1049 int regno;
1050 int stack_space_to_deallocate
1051 = (current_function_outgoing_args_size
1052 + current_function_pretend_args_size
1053 + (int) locals_size + 7) & ~7;
1055 /* The assumption that locals_size fits in an int is asserted in
1056 mmix_target_asm_function_prologue. */
1058 /* The first address to access is beyond the outgoing_args area. */
1059 int offset = current_function_outgoing_args_size;
1061 /* Add the space for global non-register-stack registers.
1062 It is assumed that the frame-pointer register can be one of these
1063 registers, in which case it is excluded from the count when needed. */
1064 for (regno = 255;
1065 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1066 regno--)
1067 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1068 && regs_ever_live[regno] && !call_used_regs[regno])
1069 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1070 stack_space_to_deallocate += 8;
1072 /* Add in the space for register stack-pointer. If so, always add room
1073 for the saved PC. */
1074 if (MMIX_CFUN_HAS_LANDING_PAD)
1075 stack_space_to_deallocate += 16;
1076 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1077 /* If we have a saved return-address slot, add it in. */
1078 stack_space_to_deallocate += 8;
1080 /* Add in the frame-pointer. */
1081 if (frame_pointer_needed)
1082 stack_space_to_deallocate += 8;
1084 /* Make sure we don't get an unaligned stack. */
1085 if ((stack_space_to_deallocate % 8) != 0)
1086 internal_error ("stack frame not a multiple of octabyte: %d",
1087 stack_space_to_deallocate);
1089 /* We will add back small offsets to the stack pointer as we go.
1090 First, we restore all registers that are global, i.e. not saved by
1091 the register file machinery. */
1093 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
1094 regno <= 255;
1095 regno++)
1096 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1097 && regs_ever_live[regno] && !call_used_regs[regno])
1098 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1100 if (offset > 255)
1102 if (offset > 65535)
1104 /* There's better support for incrementing than
1105 decrementing, so we might be able to optimize this as
1106 we see a need. */
1107 mmix_output_register_setting (stream, 255, offset, 1);
1108 fprintf (stream, "\tADDU %s,%s,$255\n",
1109 reg_names[MMIX_STACK_POINTER_REGNUM],
1110 reg_names[MMIX_STACK_POINTER_REGNUM]);
1112 else
1113 fprintf (stream, "\tINCL %s,%d\n",
1114 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
1116 stack_space_to_deallocate -= offset;
1117 offset = 0;
1120 fprintf (stream, "\tLDOU %s,%s,%d\n",
1121 reg_names[regno],
1122 reg_names[MMIX_STACK_POINTER_REGNUM],
1123 offset);
1124 offset += 8;
1127 /* Here is where the local variables were. As in the prologue, they
1128 might be of an unaligned size. */
1129 offset += (locals_size + 7) & ~7;
1132 /* The saved register stack pointer is just below the frame-pointer
1133 register. We don't need to restore it "manually"; the POP
1134 instruction does that. */
1135 if (MMIX_CFUN_HAS_LANDING_PAD)
1136 offset += 16;
1137 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1138 /* The return-address slot is just below the frame-pointer register.
1139 We don't need to restore it because we don't really use it. */
1140 offset += 8;
1142 /* Get back the old frame-pointer-value. */
1143 if (frame_pointer_needed)
1145 if (offset > 255)
1147 if (offset > 65535)
1149 /* There's better support for incrementing than
1150 decrementing, so we might be able to optimize this as
1151 we see a need. */
1152 mmix_output_register_setting (stream, 255, offset, 1);
1153 fprintf (stream, "\tADDU %s,%s,$255\n",
1154 reg_names[MMIX_STACK_POINTER_REGNUM],
1155 reg_names[MMIX_STACK_POINTER_REGNUM]);
1157 else
1158 fprintf (stream, "\tINCL %s,%d\n",
1159 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
1161 stack_space_to_deallocate -= offset;
1162 offset = 0;
1165 fprintf (stream, "\tLDOU %s,%s,%d\n",
1166 reg_names[MMIX_FRAME_POINTER_REGNUM],
1167 reg_names[MMIX_STACK_POINTER_REGNUM],
1168 offset);
1169 offset += 8;
1172 /* We do not need to restore pretended incoming args, just add back
1173 offset to sp. */
1174 if (stack_space_to_deallocate > 65535)
1176 /* There's better support for incrementing than decrementing, so
1177 we might be able to optimize this as we see a need. */
1178 mmix_output_register_setting (stream, 255,
1179 stack_space_to_deallocate, 1);
1180 fprintf (stream, "\tADDU %s,%s,$255\n",
1181 reg_names[MMIX_STACK_POINTER_REGNUM],
1182 reg_names[MMIX_STACK_POINTER_REGNUM]);
1184 else if (stack_space_to_deallocate != 0)
1185 fprintf (stream, "\tINCL %s,%d\n",
1186 reg_names[MMIX_STACK_POINTER_REGNUM],
1187 stack_space_to_deallocate);
1189 if (current_function_calls_eh_return)
1190 /* Adjustment the (normal) stack-pointer to that of the receiver.
1191 FIXME: It would be nice if we could also adjust the register stack
1192 here, but we need to express it through DWARF 2 too. */
1193 fprintf (stream, "\tADDU %s,%s,%s\n",
1194 reg_names [MMIX_STACK_POINTER_REGNUM],
1195 reg_names [MMIX_STACK_POINTER_REGNUM],
1196 reg_names [MMIX_EH_RETURN_STACKADJ_REGNUM]);
1198 /* The extra \n is so we have a blank line between the assembly code of
1199 separate functions. */
1200 fprintf (stream, "\tPOP %d,0\n\n",
1201 (! TARGET_ABI_GNU
1202 && current_function_return_rtx != NULL
1203 && ! current_function_returns_struct)
1204 ? (GET_CODE (current_function_return_rtx) == PARALLEL
1205 ? GET_NUM_ELEM (XVEC (current_function_return_rtx, 0)) : 1)
1206 : 0);
1209 /* ASM_OUTPUT_MI_THUNK. */
1211 void
1212 mmix_asm_output_mi_thunk (stream, fndecl, delta, func)
1213 FILE * stream;
1214 tree fndecl ATTRIBUTE_UNUSED;
1215 int delta;
1216 tree func;
1218 /* If you define STRUCT_VALUE to 0, rather than use STRUCT_VALUE_REGNUM,
1219 (i.e. pass location of structure to return as invisible first
1220 argument) you need to tweak this code too. */
1221 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
1223 if (delta >= 0 && delta < 65536)
1224 asm_fprintf (stream, "\tINCL %s,%d\n", delta, regname);
1225 else if (delta < 0 && delta >= -255)
1226 asm_fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, -delta);
1227 else
1229 mmix_output_register_setting (stream, 255, delta, 1);
1230 asm_fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
1233 fprintf (stream, "\tJMP ");
1234 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
1235 fprintf (stream, "\n");
1238 /* FUNCTION_PROFILER. */
1240 void
1241 mmix_function_profiler (stream, labelno)
1242 FILE *stream ATTRIBUTE_UNUSED;
1243 int labelno ATTRIBUTE_UNUSED;
1245 sorry ("function_profiler support for MMIX");
1248 /* SETUP_INCOMING_VARARGS. */
1250 void
1251 mmix_setup_incoming_varargs (args_so_farp, mode, vartype, pretend_sizep,
1252 second_time)
1253 CUMULATIVE_ARGS * args_so_farp;
1254 enum machine_mode mode;
1255 tree vartype;
1256 int * pretend_sizep;
1257 int second_time ATTRIBUTE_UNUSED;
1259 /* For stdarg, the last named variable has been handled, but
1260 args_so_farp has not been advanced for it. For varargs, the current
1261 argument is to be counted to the anonymous ones. */
1262 if (current_function_stdarg)
1264 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
1265 *pretend_sizep
1266 = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
1268 else if (current_function_varargs)
1270 if (args_so_farp->regs < MMIX_MAX_ARGS_IN_REGS)
1271 *pretend_sizep
1272 = (MMIX_MAX_ARGS_IN_REGS - args_so_farp->regs) * 8;
1274 /* For varargs, we get here when we see the last named parameter,
1275 which will actually be passed on stack. So make the next call
1276 (there will be one) to FUNCTION_ARG return 0, to count it on
1277 stack, so va_arg for it will get right. FIXME: The GCC core
1278 should provide TRT. */
1279 args_so_farp->now_varargs = 1;
1281 else
1282 internal_error ("neither varargs or stdarg in mmix_setup_incoming_varargs");
1285 /* We assume that one argument takes up one register here. That should
1286 be true until we start messing with multi-reg parameters. */
1287 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
1288 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
1291 /* EXPAND_BUILTIN_VA_ARG. */
1293 /* This is modified from the "standard" implementation of va_arg: read the
1294 value from the current (padded) address and increment by the (padded)
1295 size. The difference for MMIX is that if the type is
1296 pass-by-reference, then perform an indirection. */
1299 mmix_expand_builtin_va_arg (valist, type)
1300 tree valist;
1301 tree type;
1303 tree ptr_size = size_int (BITS_PER_WORD / BITS_PER_UNIT);
1304 tree addr_tree, type_size = NULL;
1305 tree align, alignm1;
1306 tree rounded_size;
1307 rtx addr;
1309 /* Compute the rounded size of the type. */
1311 /* Get AP. */
1312 addr_tree = valist;
1313 align = size_int (PARM_BOUNDARY / BITS_PER_UNIT);
1314 alignm1 = size_int (PARM_BOUNDARY / BITS_PER_UNIT - 1);
1315 if (type == error_mark_node
1316 || (type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type))) == NULL
1317 || TREE_OVERFLOW (type_size))
1318 /* Presumably an error; the size isn't computable. A message has
1319 supposedly been emitted elsewhere. */
1320 rounded_size = size_zero_node;
1321 else
1322 rounded_size = fold (build (MULT_EXPR, sizetype,
1323 fold (build (TRUNC_DIV_EXPR, sizetype,
1324 fold (build (PLUS_EXPR, sizetype,
1325 type_size, alignm1)),
1326 align)),
1327 align));
1329 if (AGGREGATE_TYPE_P (type)
1330 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) < 8
1331 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) != 0)
1333 /* Adjust for big-endian the location of aggregates passed in a
1334 register, but where the aggregate is accessed in a shorter mode
1335 than the natural register mode (i.e. it is accessed as SFmode(?),
1336 SImode, HImode or QImode rather than DImode or DFmode(?)). FIXME:
1337 Or should we adjust the mode in which the aggregate is read, to be
1338 a register size mode? (Hum, nah, a small offset is generally
1339 cheaper than a wider memory access on MMIX.) */
1340 addr_tree
1341 = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
1342 size_int ((BITS_PER_WORD / BITS_PER_UNIT)
1343 - GET_MODE_UNIT_SIZE (TYPE_MODE (type))));
1345 else if (!integer_zerop (rounded_size))
1347 if (!really_constant_p (type_size))
1348 /* Varying-size types come in by reference. */
1349 addr_tree
1350 = build1 (INDIRECT_REF, build_pointer_type (type), addr_tree);
1351 else
1353 /* If the size is less than a register, then we need to pad the
1354 address by adding the difference. */
1355 tree addend
1356 = fold (build (COND_EXPR, sizetype,
1357 fold (build (GT_EXPR, sizetype,
1358 rounded_size,
1359 align)),
1360 size_zero_node,
1361 fold (build (MINUS_EXPR, sizetype,
1362 rounded_size,
1363 type_size))));
1364 tree addr_tree1
1365 = fold (build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
1366 addend));
1368 /* If this type is larger than what fits in a register, then it
1369 is passed by reference. */
1370 addr_tree
1371 = fold (build (COND_EXPR, TREE_TYPE (addr_tree1),
1372 fold (build (GT_EXPR, sizetype,
1373 rounded_size,
1374 ptr_size)),
1375 build1 (INDIRECT_REF, build_pointer_type (type),
1376 addr_tree1),
1377 addr_tree1));
1381 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
1382 addr = copy_to_reg (addr);
1384 if (!integer_zerop (rounded_size))
1386 /* Compute new value for AP. For MMIX, it is always advanced by the
1387 size of a register. */
1388 tree t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
1389 build (PLUS_EXPR, TREE_TYPE (valist), valist,
1390 ptr_size));
1391 TREE_SIDE_EFFECTS (t) = 1;
1392 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1395 return addr;
1398 /* TRAMPOLINE_SIZE. */
1399 /* Four 4-byte insns plus two 8-byte values. */
1400 int mmix_trampoline_size = 32;
1403 /* TRAMPOLINE_TEMPLATE. */
1405 void
1406 mmix_trampoline_template (stream)
1407 FILE * stream;
1409 /* Read a value into the static-chain register and jump somewhere. The
1410 static chain is stored at offset 16, and the function address is
1411 stored at offset 24. */
1412 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
1413 register size (octa). */
1414 fprintf (stream, "\tGETA $255,1F\n\t");
1415 fprintf (stream, "LDOU %s,$255,0\n\t",
1416 reg_names[MMIX_STATIC_CHAIN_REGNUM]);
1417 fprintf (stream, "LDOU $255,$255,8\n\t");
1418 fprintf (stream, "GO $255,$255,0\n");
1419 fprintf (stream, "1H\tOCTA 0\n\t");
1420 fprintf (stream, "OCTA 0\n");
1423 /* INITIALIZE_TRAMPOLINE. */
1424 /* Set the static chain and function pointer field in the trampoline.
1425 We also SYNCID here to be sure (doesn't matter in the simulator, but
1426 some day it will). */
1428 void
1429 mmix_initialize_trampoline (trampaddr, fnaddr, static_chain)
1430 rtx trampaddr;
1431 rtx fnaddr;
1432 rtx static_chain;
1434 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)),
1435 static_chain);
1436 emit_move_insn (gen_rtx_MEM (DImode,
1437 plus_constant (trampaddr, 24)),
1438 fnaddr);
1439 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode,
1440 trampaddr)),
1441 GEN_INT (mmix_trampoline_size - 1)));
1444 /* We must exclude constant addresses that have an increment that is not a
1445 multiple of four bytes because of restrictions of the GETA
1446 instruction, unless TARGET_BASE_ADDRESSES. */
1449 mmix_constant_address_p (x)
1450 rtx x;
1452 RTX_CODE code = GET_CODE (x);
1453 int addend = 0;
1454 /* When using "base addresses", anything constant goes. */
1455 int constant_ok = TARGET_BASE_ADDRESSES != 0;
1457 if (code == CONSTANT_P_RTX || code == HIGH)
1458 /* FIXME: Don't know how to dissect these. Avoid them for now. */
1459 return constant_ok;
1461 switch (code)
1463 case LABEL_REF:
1464 case SYMBOL_REF:
1465 return 1;
1467 case CONSTANT_P_RTX:
1468 case HIGH:
1469 /* FIXME: Don't know how to dissect these. Avoid them for now,
1470 except we know they're constants. */
1471 return constant_ok;
1473 case CONST_INT:
1474 addend = INTVAL (x);
1475 break;
1477 case CONST_DOUBLE:
1478 if (GET_MODE (x) != VOIDmode)
1479 /* Strange that we got here. FIXME: Check if we do. */
1480 return constant_ok;
1481 addend = CONST_DOUBLE_LOW (x);
1482 break;
1484 case CONST:
1485 /* Note that expressions with arithmetic on forward references don't
1486 work in mmixal. People using gcc assembly code with mmixal might
1487 need to move arrays and such to before the point of use. */
1488 if (GET_CODE (XEXP (x, 0)) == PLUS)
1490 rtx x0 = XEXP (XEXP (x, 0), 0);
1491 rtx x1 = XEXP (XEXP (x, 0), 1);
1493 if ((GET_CODE (x0) == SYMBOL_REF
1494 || GET_CODE (x0) == LABEL_REF)
1495 && (GET_CODE (x1) == CONST_INT
1496 || (GET_CODE (x1) == CONST_DOUBLE
1497 && GET_MODE (x1) == VOIDmode)))
1498 addend = mmix_intval (x1);
1499 else
1500 return constant_ok;
1502 else
1503 return constant_ok;
1504 break;
1506 default:
1507 return 0;
1510 return constant_ok || (addend & 3) == 0;
1513 /* Return 1 if the address is OK, otherwise 0.
1514 Used by GO_IF_LEGITIMATE_ADDRESS. */
1517 mmix_legitimate_address (mode, x, strict_checking)
1518 enum machine_mode mode ATTRIBUTE_UNUSED;
1519 rtx x;
1520 int strict_checking;
1522 #define MMIX_REG_OK(X) \
1523 ((strict_checking \
1524 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1525 || (reg_renumber[REGNO (X)] > 0 \
1526 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1527 || (!strict_checking \
1528 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1529 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1530 || REGNO (X) == ARG_POINTER_REGNUM)))
1532 /* We only accept:
1533 (mem reg)
1534 (mem (plus reg reg))
1535 (mem (plus reg 0..255)).
1536 unless TARGET_BASE_ADDRESSES, in which case we accept all
1537 (mem constant_address) too. */
1540 /* (mem reg) */
1541 if (REG_P (x) && MMIX_REG_OK (x))
1542 return 1;
1544 if (GET_CODE(x) == PLUS)
1546 rtx x1 = XEXP (x, 0);
1547 rtx x2 = XEXP (x, 1);
1549 /* Try swapping the order. FIXME: Do we need this? */
1550 if (! REG_P (x1))
1552 rtx tem = x1;
1553 x1 = x2;
1554 x2 = tem;
1557 /* (mem (plus (reg?) (?))) */
1558 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1559 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1561 /* (mem (plus (reg) (reg?))) */
1562 if (REG_P (x2) && MMIX_REG_OK (x2))
1563 return 1;
1565 /* (mem (plus (reg) (0..255?))) */
1566 if (GET_CODE (x2) == CONST_INT
1567 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1568 return 1;
1570 return 0;
1573 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1576 /* LEGITIMATE_CONSTANT_P. */
1579 mmix_legitimate_constant_p (x)
1580 rtx x;
1582 RTX_CODE code = GET_CODE (x);
1584 /* We must allow any number due to the way the cse passes works; if we
1585 do not allow any number here, general_operand will fail, and insns
1586 will fatally fail recognition instead of "softly". */
1587 if (code == CONST_INT || code == CONST_DOUBLE)
1588 return 1;
1590 return CONSTANT_ADDRESS_P (x);
1593 /* SELECT_CC_MODE. */
1595 enum machine_mode
1596 mmix_select_cc_mode (op, x, y)
1597 RTX_CODE op;
1598 rtx x;
1599 rtx y ATTRIBUTE_UNUSED;
1601 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1602 output different compare insns. Note that we do not check the
1603 validity of the comparison here. */
1605 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1607 if (op == ORDERED || op == UNORDERED || op == UNGE
1608 || op == UNGT || op == UNLE || op == UNLT)
1609 return CC_FUNmode;
1611 if (op == EQ || op == NE)
1612 return CC_FPEQmode;
1614 return CC_FPmode;
1617 if (op == GTU || op == LTU || op == GEU || op == LEU)
1618 return CC_UNSmode;
1620 return CCmode;
1623 /* CANONICALIZE_COMPARISON.
1624 FIXME: Check if the number adjustments trig. */
1626 void
1627 mmix_canonicalize_comparison (codep, op0p, op1p)
1628 RTX_CODE * codep;
1629 rtx * op0p ATTRIBUTE_UNUSED;
1630 rtx * op1p;
1632 /* Change -1 to zero, if possible. */
1633 if ((*codep == LE || *codep == GT)
1634 && GET_CODE (*op1p) == CONST_INT
1635 && *op1p == constm1_rtx)
1637 *codep = *codep == LE ? LT : GE;
1638 *op1p = const0_rtx;
1641 /* Fix up 256 to 255, if possible. */
1642 if ((*codep == LT || *codep == LTU || *codep == GE || *codep == GEU)
1643 && GET_CODE (*op1p) == CONST_INT
1644 && INTVAL (*op1p) == 256)
1646 /* FIXME: Remove when I know this trigs. */
1647 fatal_insn ("oops, not debugged; fixing up value:", *op1p);
1648 *codep = *codep == LT ? LE : *codep == LTU ? LEU : *codep
1649 == GE ? GT : GTU;
1650 *op1p = GEN_INT (255);
1654 /* REVERSIBLE_CC_MODE. */
1657 mmix_reversible_cc_mode (mode)
1658 enum machine_mode mode;
1660 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1661 cmpares. */
1662 return mode != CC_FPmode;
1665 /* DEFAULT_RTX_COSTS. */
1668 mmix_rtx_cost_recalculated (x, code, outer_code, costp)
1669 rtx x ATTRIBUTE_UNUSED;
1670 RTX_CODE code ATTRIBUTE_UNUSED;
1671 RTX_CODE outer_code ATTRIBUTE_UNUSED;
1672 int *costp ATTRIBUTE_UNUSED;
1674 /* For the time being, this is just a stub and we'll accept the
1675 generic calculations, until we can do measurements, at least.
1676 Say we did not modify any calculated costs. */
1677 return 0;
1680 /* ADDRESS_COST. */
1683 mmix_address_cost (addr)
1684 rtx addr ATTRIBUTE_UNUSED;
1686 /* There's no difference in the address costs and we have lots of
1687 registers. Some targets use constant 0, many others use 1 to say
1688 this. Let's start with 1. */
1689 return 1;
1692 /* REGISTER_MOVE_COST. */
1695 mmix_register_move_cost (mode, from, to)
1696 enum machine_mode mode ATTRIBUTE_UNUSED;
1697 enum reg_class from;
1698 enum reg_class to;
1700 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1703 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1704 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1705 the target. */
1707 /* DATA_SECTION_ASM_OP. */
1709 const char *
1710 mmix_data_section_asm_op ()
1712 return "\t.data ! mmixal:= 8H LOC 9B";
1715 static void
1716 mmix_encode_section_info (decl, first)
1717 tree decl;
1718 int first;
1720 /* Test for an external declaration, and do nothing if it is one. */
1721 if ((TREE_CODE (decl) == VAR_DECL
1722 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1723 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1725 else if (first && DECL_P (decl))
1727 /* For non-visible declarations, add a "@" prefix, which we skip
1728 when the label is output. If the label does not have this
1729 prefix, a ":" is output if -mtoplevel-symbols.
1731 Note that this does not work for data that is declared extern and
1732 later defined as static. If there's code in between, that code
1733 will refer to the extern declaration, and vice versa. This just
1734 means that when -mtoplevel-symbols is in use, we can just handle
1735 well-behaved ISO-compliant code. */
1737 const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1738 int len = strlen (str);
1739 char *newstr;
1741 /* Why is the return type of ggc_alloc_string const? */
1742 newstr = (char *) ggc_alloc_string ("", len + 1);
1744 strcpy (newstr + 1, str);
1745 *newstr = '@';
1746 XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
1749 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1750 may need different options to reach for different things with GETA.
1751 For now, functions and things we know or have been told are constant. */
1752 if (TREE_CODE (decl) == FUNCTION_DECL
1753 || TREE_CONSTANT (decl)
1754 || (TREE_CODE (decl) == VAR_DECL
1755 && TREE_READONLY (decl)
1756 && !TREE_SIDE_EFFECTS (decl)
1757 && (!DECL_INITIAL (decl)
1758 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1760 rtx rtl = (TREE_CODE_CLASS (TREE_CODE (decl)) != 'd'
1761 ? TREE_CST_RTL (decl) : DECL_RTL (decl));
1762 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1766 static const char *
1767 mmix_strip_name_encoding (name)
1768 const char *name;
1770 for (; (*name == '@' || *name == '*'); name++)
1773 return name;
1776 /* ASM_FILE_START. */
1778 void
1779 mmix_asm_file_start (stream)
1780 FILE * stream;
1782 /* We just emit a little comment for the time being. FIXME: Perhaps add
1783 -mstandalone and some segment and prefix setup here. */
1784 ASM_OUTPUT_SOURCE_FILENAME (stream, main_input_filename);
1786 fprintf (stream, "! mmixal:= 8H LOC Data_Section\n");
1788 /* Make sure each file starts with the text section. */
1789 text_section ();
1792 /* ASM_FILE_END. */
1794 void
1795 mmix_asm_file_end (stream)
1796 FILE * stream ATTRIBUTE_UNUSED;
1798 /* Make sure each file ends with the data section. */
1799 data_section ();
1802 /* ASM_OUTPUT_SOURCE_FILENAME. */
1804 void
1805 mmix_asm_output_source_filename (stream, name)
1806 FILE * stream;
1807 const char * name;
1809 fprintf (stream, "# 1 ");
1810 OUTPUT_QUOTED_STRING (stream, name);
1811 fprintf (stream, "\n");
1814 /* OUTPUT_QUOTED_STRING. */
1816 void
1817 mmix_output_quoted_string (stream, string, length)
1818 FILE * stream;
1819 const char * string;
1820 int length;
1822 const char * string_end = string + length;
1823 static const char *const unwanted_chars = "\"[]\\";
1825 /* Output "any character except newline and double quote character". We
1826 play it safe and avoid all control characters too. We also do not
1827 want [] as characters, should input be passed through m4 with [] as
1828 quotes. Further, we avoid "\", because the GAS port handles it as a
1829 quoting character. */
1830 while (string < string_end)
1832 if (*string
1833 && (unsigned char) *string < 128
1834 && !ISCNTRL (*string)
1835 && strchr (unwanted_chars, *string) == NULL)
1837 fputc ('"', stream);
1838 while (*string
1839 && (unsigned char) *string < 128
1840 && !ISCNTRL (*string)
1841 && strchr (unwanted_chars, *string) == NULL
1842 && string < string_end)
1844 fputc (*string, stream);
1845 string++;
1847 fputc ('"', stream);
1848 if (string < string_end)
1849 fprintf (stream, ",");
1851 if (string < string_end)
1853 fprintf (stream, "#%x", *string & 255);
1854 string++;
1855 if (string < string_end)
1856 fprintf (stream, ",");
1861 /* ASM_OUTPUT_SOURCE_LINE. */
1863 void
1864 mmix_asm_output_source_line (stream, lineno)
1865 FILE * stream;
1866 int lineno;
1868 fprintf (stream, "# %d ", lineno);
1869 OUTPUT_QUOTED_STRING (stream, main_input_filename);
1870 fprintf (stream, "\n");
1873 /* Target hook for assembling integer objects. Use mmix_print_operand
1874 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1875 CONST_DOUBLEs. */
1877 static bool
1878 mmix_assemble_integer (x, size, aligned_p)
1879 rtx x;
1880 unsigned int size;
1881 int aligned_p;
1883 if (aligned_p)
1884 switch (size)
1886 /* We handle a limited number of types of operands in here. But
1887 that's ok, because we can punt to generic functions. We then
1888 pretend that aligned data isn't needed, so the usual .<pseudo>
1889 syntax is used (which works for aligned data too). We actually
1890 *must* do that, since we say we don't have simple aligned
1891 pseudos, causing this function to be called. We just try and
1892 keep as much compatibility as possible with mmixal syntax for
1893 normal cases (i.e. without GNU extensions and C only). */
1894 case 1:
1895 if (GET_CODE (x) != CONST_INT)
1897 aligned_p = 0;
1898 break;
1900 fputs ("\tBYTE\t", asm_out_file);
1901 mmix_print_operand (asm_out_file, x, 'B');
1902 fputc ('\n', asm_out_file);
1903 return true;
1905 case 2:
1906 if (GET_CODE (x) != CONST_INT)
1908 aligned_p = 0;
1909 break;
1911 fputs ("\tWYDE\t", asm_out_file);
1912 mmix_print_operand (asm_out_file, x, 'W');
1913 fputc ('\n', asm_out_file);
1914 return true;
1916 case 4:
1917 if (GET_CODE (x) != CONST_INT)
1919 aligned_p = 0;
1920 break;
1922 fputs ("\tTETRA\t", asm_out_file);
1923 mmix_print_operand (asm_out_file, x, 'L');
1924 fputc ('\n', asm_out_file);
1925 return true;
1927 case 8:
1928 if (GET_CODE (x) == CONST_DOUBLE)
1929 /* We don't get here anymore for CONST_DOUBLE, because DImode
1930 isn't expressed as CONST_DOUBLE, and DFmode is handled
1931 elsewhere. */
1932 abort ();
1933 assemble_integer_with_op ("\tOCTA\t", x);
1934 return true;
1936 return default_assemble_integer (x, size, aligned_p);
1939 /* ASM_OUTPUT_ASCII. */
1941 void
1942 mmix_asm_output_ascii (stream, string, length)
1943 FILE *stream;
1944 const char *string;
1945 int length;
1947 while (length > 0)
1949 int chunk_size = length > 60 ? 60 : length;
1950 fprintf (stream, "\tBYTE ");
1951 mmix_output_quoted_string (stream, string, chunk_size);
1952 string += chunk_size;
1953 length -= chunk_size;
1954 fprintf (stream, "\n");
1958 /* ASM_OUTPUT_ALIGNED_COMMON. */
1960 void
1961 mmix_asm_output_aligned_common (stream, name, size, align)
1962 FILE *stream;
1963 const char *name;
1964 int size;
1965 int align;
1967 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1968 express this in a mmixal-compatible way. */
1969 fprintf (stream, "\t.comm\t");
1970 assemble_name (stream, name);
1971 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1972 size, align / BITS_PER_UNIT);
1975 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1977 void
1978 mmix_asm_output_aligned_local (stream, name, size, align)
1979 FILE * stream;
1980 const char * name;
1981 int size;
1982 int align;
1984 data_section ();
1986 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1987 assemble_name (stream, name);
1988 fprintf (stream, "\tLOC @+%d\n", size);
1991 /* ASM_OUTPUT_LABEL. */
1993 void
1994 mmix_asm_output_label (stream, name)
1995 FILE *stream;
1996 const char * name;
1998 assemble_name (stream, name);
1999 fprintf (stream, "\tIS @\n");
2002 /* ASM_DECLARE_REGISTER_GLOBAL. */
2004 void
2005 mmix_asm_declare_register_global (stream, decl, regno, name)
2006 FILE *stream ATTRIBUTE_UNUSED;
2007 tree decl ATTRIBUTE_UNUSED;
2008 int regno ATTRIBUTE_UNUSED;
2009 const char *name ATTRIBUTE_UNUSED;
2011 /* Nothing to do here, but there *will* be, therefore the framework is
2012 here. */
2015 /* ASM_GLOBALIZE_LABEL. */
2017 void
2018 mmix_asm_globalize_label (stream, name)
2019 FILE * stream ATTRIBUTE_UNUSED;
2020 const char * name ATTRIBUTE_UNUSED;
2022 asm_fprintf (stream, "\t.global ");
2023 assemble_name (stream, name);
2024 putc ('\n', stream);
2027 /* ASM_WEAKEN_LABEL. */
2029 void
2030 mmix_asm_weaken_label (stream, name)
2031 FILE * stream ATTRIBUTE_UNUSED;
2032 const char * name ATTRIBUTE_UNUSED;
2034 asm_fprintf (stream, "\t.weak ");
2035 assemble_name (stream, name);
2036 asm_fprintf (stream, " ! mmixal-incompatible\n");
2039 /* MAKE_DECL_ONE_ONLY. */
2041 void
2042 mmix_make_decl_one_only (decl)
2043 tree decl;
2045 DECL_WEAK (decl) = 1;
2048 /* ASM_OUTPUT_LABELREF.
2049 Strip GCC's '*' and our own '@'. No order is assumed. */
2051 void
2052 mmix_asm_output_labelref (stream, name)
2053 FILE *stream;
2054 const char *name;
2056 int is_extern = 1;
2058 for (; (*name == '@' || *name == '*'); name++)
2059 if (*name == '@')
2060 is_extern = 0;
2062 asm_fprintf (stream, "%s%U%s",
2063 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
2064 name);
2067 /* ASM_OUTPUT_INTERNAL_LABEL. */
2069 void
2070 mmix_asm_output_internal_label (stream, name, num)
2071 FILE * stream;
2072 const char * name;
2073 int num;
2075 fprintf (stream, "%s:%d\tIS @\n", name, num);
2078 /* ASM_OUTPUT_DEF. */
2080 void
2081 mmix_asm_output_def (stream, name, value)
2082 FILE * stream;
2083 const char * name;
2084 const char * value;
2086 assemble_name (stream, name);
2087 fprintf (stream, "\tIS ");
2088 assemble_name (stream, value);
2089 fputc ('\n', stream);
2092 /* ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL. */
2094 void
2095 mmix_asm_output_define_label_difference_symbol (stream, symbol, hi, lo)
2096 FILE *stream;
2097 const char *symbol;
2098 const char *hi;
2099 const char *lo;
2101 assemble_name (stream, symbol);
2102 fprintf (stream, "\tIS\t");
2103 assemble_name (stream, hi);
2104 fputc ('-', stream);
2105 assemble_name (stream, lo);
2106 fprintf (stream, "\n");
2109 /* PRINT_OPERAND. */
2111 void
2112 mmix_print_operand (stream, x, code)
2113 FILE * stream;
2114 rtx x;
2115 int code;
2117 /* When we add support for different codes later, we can, when needed,
2118 drop through to the main handler with a modified operand. */
2119 rtx modified_x = x;
2120 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
2122 switch (code)
2124 /* Unrelated codes are in alphabetic order. */
2126 case '+':
2127 /* For conditional branches, output "P" for a probable branch. */
2128 if (TARGET_BRANCH_PREDICT)
2130 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
2131 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
2132 putc ('P', stream);
2134 return;
2136 case 'B':
2137 if (GET_CODE (x) != CONST_INT)
2138 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
2139 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
2140 return;
2142 case 'H':
2143 /* Highpart. Must be general register, and not the last one, as
2144 that one cannot be part of a consecutive register pair. */
2145 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
2146 internal_error ("MMIX Internal: Bad register: %d", regno);
2148 /* This is big-endian, so the high-part is the first one. */
2149 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
2150 return;
2152 case 'L':
2153 /* Lowpart. Must be CONST_INT or general register, and not the last
2154 one, as that one cannot be part of a consecutive register pair. */
2155 if (GET_CODE (x) == CONST_INT)
2157 fprintf (stream, "#%lx",
2158 (unsigned long) (INTVAL (x)
2159 & ((unsigned int) 0x7fffffff * 2 + 1)));
2160 return;
2163 if (GET_CODE (x) == SYMBOL_REF)
2165 output_addr_const (stream, x);
2166 return;
2169 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
2170 internal_error ("MMIX Internal: Bad register: %d", regno);
2172 /* This is big-endian, so the low-part is + 1. */
2173 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
2174 return;
2176 /* Can't use 'a' because that's a generic modifier for address
2177 output. */
2178 case 'A':
2179 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
2180 ~(unsigned HOST_WIDEST_INT)
2181 mmix_intval (x));
2182 return;
2184 case 'i':
2185 mmix_output_shiftvalue_op_from_str (stream, "INC",
2186 (unsigned HOST_WIDEST_INT)
2187 mmix_intval (x));
2188 return;
2190 case 'o':
2191 mmix_output_shiftvalue_op_from_str (stream, "OR",
2192 (unsigned HOST_WIDEST_INT)
2193 mmix_intval (x));
2194 return;
2196 case 's':
2197 mmix_output_shiftvalue_op_from_str (stream, "SET",
2198 (unsigned HOST_WIDEST_INT)
2199 mmix_intval (x));
2200 return;
2202 case 'd':
2203 case 'D':
2204 mmix_output_condition (stream, x, (code == 'D'));
2205 return;
2207 case 'e':
2208 /* Output an extra "e" to make fcmpe, fune. */
2209 if (TARGET_FCMP_EPSILON)
2210 fprintf (stream, "e");
2211 return;
2213 case 'm':
2214 /* Output the number minus 1. */
2215 if (GET_CODE (x) != CONST_INT)
2217 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
2220 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
2221 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
2222 return;
2224 case 'p':
2225 /* Store the number of registers we want to save. This was setup
2226 by the prologue. The actual operand contains the number of
2227 registers to pass, but we don't use it currently. Anyway, we
2228 need to output the number of saved registers here. */
2229 fprintf (stream, "%d",
2230 cfun->machine->highest_saved_stack_register + 1);
2231 return;
2233 case 'r':
2234 /* Store the register to output a constant to. */
2235 if (! REG_P (x))
2236 fatal_insn ("MMIX Internal: Expected a register, not this", x);
2237 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
2238 return;
2240 case 'I':
2241 /* Output the constant. Note that we use this for floats as well. */
2242 if (GET_CODE (x) != CONST_INT
2243 && (GET_CODE (x) != CONST_DOUBLE
2244 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
2245 && GET_MODE (x) != SFmode)))
2246 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
2247 mmix_output_register_setting (stream,
2248 mmix_output_destination_register,
2249 mmix_intval (x), 0);
2250 return;
2252 case 'U':
2253 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
2254 if (TARGET_ZERO_EXTEND)
2255 putc ('U', stream);
2256 return;
2258 case 'v':
2259 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
2260 return;
2262 case 'V':
2263 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
2264 return;
2266 case 'W':
2267 if (GET_CODE (x) != CONST_INT)
2268 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
2269 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
2270 return;
2272 case 0:
2273 /* Nothing to do. */
2274 break;
2276 default:
2277 /* Presumably there's a missing case above if we get here. */
2278 internal_error ("MMIX Internal: Missing `%c' case in mmix_print_operand", code);
2281 switch (GET_CODE (modified_x))
2283 case REG:
2284 regno = REGNO (modified_x);
2285 if (regno >= FIRST_PSEUDO_REGISTER)
2286 internal_error ("MMIX Internal: Bad register: %d", regno);
2287 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
2288 return;
2290 case MEM:
2291 output_address (XEXP (modified_x, 0));
2292 return;
2294 case CONST_INT:
2295 /* For -2147483648, mmixal complains that the constant does not fit
2296 in 4 bytes, so let's output it as hex. Take care to handle hosts
2297 where HOST_WIDE_INT is longer than an int.
2299 Print small constants +-255 using decimal. */
2301 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
2302 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
2303 else
2304 fprintf (stream, "#%x",
2305 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
2306 return;
2308 case CONST_DOUBLE:
2309 /* Do somewhat as CONST_INT. */
2310 mmix_output_octa (stream, mmix_intval (modified_x), 0);
2311 return;
2313 case CONST:
2314 output_addr_const (stream, modified_x);
2315 return;
2317 default:
2318 /* No need to test for all strange things. Let output_addr_const do
2319 it for us. */
2320 if (CONSTANT_P (modified_x)
2321 /* Strangely enough, this is not included in CONSTANT_P.
2322 FIXME: Ask/check about sanity here. */
2323 || GET_CODE (modified_x) == CODE_LABEL)
2325 output_addr_const (stream, modified_x);
2326 return;
2329 /* We need the original here. */
2330 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
2334 /* PRINT_OPERAND_PUNCT_VALID_P. */
2337 mmix_print_operand_punct_valid_p (code)
2338 int code ATTRIBUTE_UNUSED;
2340 /* A '+' is used for branch prediction, similar to other ports. */
2341 return code == '+';
2344 /* PRINT_OPERAND_ADDRESS. */
2346 void
2347 mmix_print_operand_address (stream, x)
2348 FILE *stream;
2349 rtx x;
2351 if (REG_P (x))
2353 /* I find the generated assembly code harder to read without
2354 the ",0". */
2355 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
2356 return;
2358 else if (GET_CODE (x) == PLUS)
2360 rtx x1 = XEXP (x, 0);
2361 rtx x2 = XEXP (x, 1);
2363 /* Try swap the order. FIXME: Do we need this? */
2364 if (! REG_P (x1))
2366 rtx tem = x1;
2367 x1 = x2;
2368 x2 = tem;
2371 if (REG_P (x1))
2373 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
2375 if (REG_P (x2))
2377 fprintf (stream, "%s",
2378 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
2379 return;
2381 else if (GET_CODE (x2) == CONST_INT
2382 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
2384 output_addr_const (stream, x2);
2385 return;
2390 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (x))
2392 output_addr_const (stream, x);
2393 return;
2396 fatal_insn ("MMIX Internal: This is not a recognized address", x);
2399 /* ASM_OUTPUT_REG_PUSH. */
2401 void
2402 mmix_asm_output_reg_push (stream, regno)
2403 FILE * stream;
2404 int regno;
2406 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
2407 reg_names[MMIX_STACK_POINTER_REGNUM],
2408 reg_names[MMIX_STACK_POINTER_REGNUM],
2409 reg_names[MMIX_OUTPUT_REGNO (regno)],
2410 reg_names[MMIX_STACK_POINTER_REGNUM]);
2413 /* ASM_OUTPUT_REG_POP. */
2415 void
2416 mmix_asm_output_reg_pop (stream, regno)
2417 FILE * stream;
2418 int regno;
2420 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
2421 reg_names[MMIX_OUTPUT_REGNO (regno)],
2422 reg_names[MMIX_STACK_POINTER_REGNUM],
2423 reg_names[MMIX_STACK_POINTER_REGNUM]);
2426 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
2428 void
2429 mmix_asm_output_addr_diff_elt (stream, body, value, rel)
2430 FILE *stream;
2431 rtx body ATTRIBUTE_UNUSED;
2432 int value;
2433 int rel;
2435 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
2438 /* ASM_OUTPUT_ADDR_VEC_ELT. */
2440 void
2441 mmix_asm_output_addr_vec_elt (stream, value)
2442 FILE *stream;
2443 int value;
2445 fprintf (stream, "\tOCTA L:%d\n", value);
2448 /* ASM_OUTPUT_SKIP. */
2450 void
2451 mmix_asm_output_skip (stream, nbytes)
2452 FILE *stream;
2453 int nbytes;
2455 fprintf (stream, "\tLOC @+%d\n", nbytes);
2458 /* ASM_OUTPUT_ALIGN. */
2460 void
2461 mmix_asm_output_align (stream, power)
2462 FILE *stream;
2463 int power;
2465 /* We need to record the needed alignment of this section in the object,
2466 so we have to output an alignment directive. Use a .p2align (not
2467 .align) so people will never have to wonder about whether the
2468 argument is in number of bytes or the log2 thereof. We do it in
2469 addition to the LOC directive, so nothing needs tweaking when
2470 copy-pasting assembly into mmixal. */
2471 fprintf (stream, "\t.p2align %d\n", power);
2472 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
2475 /* DBX_REGISTER_NUMBER. */
2478 mmix_dbx_register_number (regno)
2479 int regno;
2481 /* Adjust the register number to the one it will be output as, dammit.
2482 It'd be nice if we could check the assumption that we're filling a
2483 gap, but every register between the last saved register and parameter
2484 registers might be a valid parameter register. */
2485 regno = MMIX_OUTPUT_REGNO (regno);
2487 /* We need to renumber registers to get the number of the return address
2488 register in the range 0..255. It is also space-saving if registers
2489 mentioned in the call-frame information (which uses this function by
2490 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
2491 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
2492 return regno >= 224 ? (regno - 224) : (regno + 48);
2495 /* End of target macro support functions.
2497 Now MMIX's own functions. First the exported ones. */
2499 /* Output an optimal sequence for setting a register to a specific
2500 constant. Used in an alternative for const_ints in movdi, and when
2501 using large stack-frame offsets.
2503 Use do_begin_end to say if a line-starting TAB and newline before the
2504 first insn and after the last insn is wanted. */
2506 void
2507 mmix_output_register_setting (stream, regno, value, do_begin_end)
2508 FILE *stream;
2509 int regno;
2510 HOST_WIDEST_INT value;
2511 int do_begin_end;
2513 if (do_begin_end)
2514 fprintf (stream, "\t");
2516 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2518 /* First, the one-insn cases. */
2519 mmix_output_shiftvalue_op_from_str (stream, "SET",
2520 (unsigned HOST_WIDEST_INT)
2521 value);
2522 fprintf (stream, " %s,", reg_names[regno]);
2523 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2525 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2527 /* We do this to get a bit more legible assembly code. The next
2528 alternative is mostly redundant with this. */
2530 mmix_output_shiftvalue_op_from_str (stream, "SET",
2531 -(unsigned HOST_WIDEST_INT)
2532 value);
2533 fprintf (stream, " %s,", reg_names[regno]);
2534 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2535 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2536 reg_names[regno]);
2538 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2540 /* Slightly more expensive, the two-insn cases. */
2542 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2543 is shiftable, or any other one-insn transformation of the value.
2544 FIXME: Check first if the value is "shiftable" by two loading
2545 with two insns, since it makes more readable assembly code (if
2546 anyone else cares). */
2548 mmix_output_shiftvalue_op_from_str (stream, "SET",
2549 ~(unsigned HOST_WIDEST_INT)
2550 value);
2551 fprintf (stream, " %s,", reg_names[regno]);
2552 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2553 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2554 reg_names[regno]);
2556 else
2558 /* The generic case. 2..4 insns. */
2559 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2560 const char *op = "SET";
2561 const char *line_begin = "";
2562 int insns = 0;
2563 int i;
2564 HOST_WIDEST_INT tmpvalue = value;
2566 /* Compute the number of insns needed to output this constant. */
2567 for (i = 0; i < 4 && tmpvalue != 0; i++)
2569 if (tmpvalue & 65535)
2570 insns++;
2571 tmpvalue >>= 16;
2573 if (TARGET_BASE_ADDRESSES && insns == 3)
2575 /* The number three is based on a static observation on
2576 ghostscript-6.52. Two and four are excluded because there
2577 are too many such constants, and each unique constant (maybe
2578 offset by 1..255) were used few times compared to other uses,
2579 e.g. addresses.
2581 We use base-plus-offset addressing to force it into a global
2582 register; we just use a "LDA reg,VALUE", which will cause the
2583 assembler and linker to DTRT (for constants as well as
2584 addresses). */
2585 fprintf (stream, "LDA %s,", reg_names[regno]);
2586 mmix_output_octa (stream, value, 0);
2588 else
2590 /* Output pertinent parts of the 4-wyde sequence.
2591 Still more to do if we want this to be optimal, but hey...
2592 Note that the zero case has been handled above. */
2593 for (i = 0; i < 4 && value != 0; i++)
2595 if (value & 65535)
2597 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2598 higher_parts[i], reg_names[regno],
2599 (int) (value & 65535));
2600 /* The first one sets the rest of the bits to 0, the next
2601 ones add set bits. */
2602 op = "INC";
2603 line_begin = "\n\t";
2606 value >>= 16;
2611 if (do_begin_end)
2612 fprintf (stream, "\n");
2615 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2616 else return 0. */
2619 mmix_shiftable_wyde_value (value)
2620 unsigned HOST_WIDEST_INT value;
2622 /* Shift by 16 bits per group, stop when we've found two groups with
2623 nonzero bits. */
2624 int i;
2625 int has_candidate = 0;
2627 for (i = 0; i < 4; i++)
2629 if (value & 65535)
2631 if (has_candidate)
2632 return 0;
2633 else
2634 has_candidate = 1;
2637 value >>= 16;
2640 return 1;
2643 /* True if this is an address_operand or a symbolic operand. */
2646 mmix_symbolic_or_address_operand (op, mode)
2647 rtx op;
2648 enum machine_mode mode;
2650 switch (GET_CODE (op))
2652 case SYMBOL_REF:
2653 case LABEL_REF:
2654 return 1;
2655 case CONST:
2656 op = XEXP (op, 0);
2657 if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2658 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
2659 && (GET_CODE (XEXP (op, 1)) == CONST_INT
2660 || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE
2661 && GET_MODE (XEXP (op, 1)) == VOIDmode)))
2662 return 1;
2663 /* FALLTHROUGH */
2664 default:
2665 return address_operand (op, mode);
2669 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2670 We could narrow the value down with a couple of predicated, but that
2671 doesn't seem to be worth it at the moment. */
2674 mmix_reg_or_constant_operand (op, mode)
2675 rtx op;
2676 enum machine_mode mode;
2678 return register_operand (op, mode)
2679 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
2680 || GET_CODE (op) == CONST_INT;
2683 /* True if this is a register with a condition-code mode. */
2686 mmix_reg_cc_operand (op, mode)
2687 rtx op;
2688 enum machine_mode mode;
2690 if (mode == VOIDmode)
2691 mode = GET_MODE (op);
2693 return register_operand (op, mode)
2694 && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode
2695 || mode == CC_FPEQmode || mode == CC_FUNmode);
2698 /* True if this is a foldable comparison operator
2699 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2700 replaced by (reg). */
2703 mmix_foldable_comparison_operator (op, mode)
2704 rtx op;
2705 enum machine_mode mode;
2707 RTX_CODE code = GET_CODE (op);
2709 if (mode == VOIDmode)
2710 mode = GET_MODE (op);
2712 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2713 mode = GET_MODE (XEXP (op, 0));
2715 return ((mode == CCmode || mode == DImode)
2716 && (code == NE || code == EQ || code == GE || code == GT
2717 || code == LE))
2718 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2719 reverse the condition? Can it do that by itself? Maybe it can
2720 even reverse the condition to fit a foldable one in the first
2721 place? */
2722 || (mode == CC_UNSmode && (code == GTU || code == LEU));
2725 /* Like comparison_operator, but only true if this comparison operator is
2726 applied to a valid mode. Needed to avoid jump.c generating invalid
2727 code with -ffast-math (gcc.dg/20001228-1.c). */
2730 mmix_comparison_operator (op, mode)
2731 rtx op;
2732 enum machine_mode mode;
2734 RTX_CODE code = GET_CODE (op);
2736 /* Comparison operators usually don't have a mode, but let's try and get
2737 one anyway for the day that changes. */
2738 if (mode == VOIDmode)
2739 mode = GET_MODE (op);
2741 /* Get the mode from the first operand if we don't have one. */
2742 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2743 mode = GET_MODE (XEXP (op, 0));
2745 /* FIXME: This needs to be kept in sync with the tables in
2746 mmix_output_condition. */
2747 return
2748 (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2749 || (mode == CC_FUNmode
2750 && (code == ORDERED || code == UNORDERED))
2751 || (mode == CC_FPmode
2752 && (code == GT || code == LT))
2753 || (mode == CC_FPEQmode
2754 && (code == NE || code == EQ))
2755 || (mode == CC_UNSmode
2756 && (code == GEU || code == GTU || code == LEU || code == LTU))
2757 || (mode == CCmode
2758 && (code == NE || code == EQ || code == GE || code == GT
2759 || code == LE || code == LT))
2760 || (mode == DImode
2761 && (code == NE || code == EQ || code == GE || code == GT
2762 || code == LE || code == LT || code == LEU || code == GTU));
2765 /* True if this is a register or 0 (int or float). */
2768 mmix_reg_or_0_operand (op, mode)
2769 rtx op;
2770 enum machine_mode mode;
2772 /* FIXME: Is mode calculation necessary and correct? */
2773 return
2774 op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode)
2775 || register_operand (op, mode);
2778 /* True if this is a register or an int 0..255. */
2781 mmix_reg_or_8bit_operand (op, mode)
2782 rtx op;
2783 enum machine_mode mode;
2785 return register_operand (op, mode)
2786 || (GET_CODE (op) == CONST_INT
2787 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
2790 /* True if this is a register or an int 0..256. We include 256,
2791 because it can be canonicalized into 255 for comparisons, which is
2792 currently the only use of this predicate.
2793 FIXME: Check that this happens and does TRT. */
2796 mmix_reg_or_8bit_or_256_operand (op, mode)
2797 rtx op;
2798 enum machine_mode mode;
2800 return mmix_reg_or_8bit_operand (op, mode)
2801 || (GET_CODE (op) == CONST_INT && INTVAL (op) == 256);
2804 /* Returns zero if code and mode is not a valid condition from a
2805 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2806 is the comparison of mode is CC-somethingmode. */
2809 mmix_valid_comparison (code, mode, op)
2810 RTX_CODE code;
2811 enum machine_mode mode;
2812 rtx op;
2814 if (mode == VOIDmode && op != NULL_RTX)
2815 mode = GET_MODE (op);
2817 /* We don't care to look at these, they should always be valid. */
2818 if (mode == CCmode || mode == CC_UNSmode || mode == DImode)
2819 return 1;
2821 if ((mode == CC_FPmode || mode == DFmode)
2822 && (code == GT || code == LT))
2823 return 1;
2825 if ((mode == CC_FPEQmode || mode == DFmode)
2826 && (code == EQ || code == NE))
2827 return 1;
2829 if ((mode == CC_FUNmode || mode == DFmode)
2830 && (code == ORDERED || code == UNORDERED))
2831 return 1;
2833 return 0;
2836 /* X and Y are two things to compare using CODE. Emit a compare insn if
2837 possible and return the rtx for the cc-reg in the proper mode, or
2838 NULL_RTX if this is not a valid comparison. */
2841 mmix_gen_compare_reg (code, x, y)
2842 RTX_CODE code;
2843 rtx x, y;
2845 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2846 rtx cc_reg;
2848 /* FIXME: Do we get constants here? Of double mode? */
2849 enum machine_mode mode
2850 = GET_MODE (x) == VOIDmode
2851 ? GET_MODE (y)
2852 : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode;
2854 if (! mmix_valid_comparison (code, mode, x))
2855 return NULL_RTX;
2857 cc_reg = gen_reg_rtx (ccmode);
2859 /* FIXME: Can we avoid emitting a compare insn here? */
2860 if (! REG_P (x) && ! REG_P (y))
2861 x = force_reg (mode, x);
2863 CANONICALIZE_COMPARISON (code, x, y);
2865 /* If it's not quite right yet, put y in a register. */
2866 if (! REG_P (y)
2867 && (GET_CODE (y) != CONST_INT
2868 || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I')))
2869 y = force_reg (mode, y);
2871 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2872 gen_rtx_COMPARE (ccmode, x, y)));
2874 return cc_reg;
2877 /* Local (static) helper functions. */
2879 /* Print operator suitable for doing something with a shiftable
2880 wyde. The type of operator is passed as an asm output modifier. */
2882 static void
2883 mmix_output_shiftvalue_op_from_str (stream, mainop, value)
2884 FILE *stream;
2885 const char *mainop;
2886 HOST_WIDEST_INT value;
2888 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2889 int i;
2891 if (! mmix_shiftable_wyde_value (value))
2893 char s[sizeof ("0xffffffffffffffff")];
2894 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2895 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2898 for (i = 0; i < 4; i++)
2900 /* We know we're through when we find one-bits in the low
2901 16 bits. */
2902 if (value & 0xffff)
2904 fprintf (stream, "%s%s", mainop, op_part[i]);
2905 return;
2907 value >>= 16;
2910 /* No bits set? Then it must have been zero. */
2911 fprintf (stream, "%sL", mainop);
2914 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2916 static void
2917 mmix_output_octa (stream, value, do_begin_end)
2918 FILE *stream;
2919 HOST_WIDEST_INT value;
2920 int do_begin_end;
2922 /* Snipped from final.c:output_addr_const. We need to avoid the
2923 presumed universal "0x" prefix. We can do it by replacing "0x" with
2924 "#0" here; we must avoid a space in the operands and no, the zero
2925 won't cause the number to be assumed in octal format. */
2926 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2928 if (do_begin_end)
2929 fprintf (stream, "\tOCTA ");
2931 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2932 hex_format[0] = '#';
2933 hex_format[1] = '0';
2935 /* Provide a few alternative output formats depending on the number, to
2936 improve legibility of assembler output. */
2937 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2938 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2939 fprintf (stream, "%d", (int) value);
2940 else if (value > (HOST_WIDEST_INT) 0
2941 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2942 fprintf (stream, "#%x", (unsigned int) value);
2943 else
2944 fprintf (stream, hex_format, value);
2946 if (do_begin_end)
2947 fprintf (stream, "\n");
2950 /* Print the presumed shiftable wyde argument shifted into place (to
2951 be output with an operand). */
2953 static void
2954 mmix_output_shifted_value (stream, value)
2955 FILE * stream;
2956 HOST_WIDEST_INT value;
2958 int i;
2960 if (! mmix_shiftable_wyde_value (value))
2962 char s[16+2+1];
2963 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2964 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2967 for (i = 0; i < 4; i++)
2969 /* We know we're through when we find one-bits in the low 16 bits. */
2970 if (value & 0xffff)
2972 fprintf (stream, "#%x", (int) (value & 0xffff));
2973 return;
2976 value >>= 16;
2979 /* No bits set? Then it must have been zero. */
2980 fprintf (stream, "0");
2983 /* Output an MMIX condition name corresponding to an operator
2984 and operands:
2985 (comparison_operator [(comparison_operator ...) (const_int 0)])
2986 which means we have to look at *two* operators.
2988 The argument "reversed" refers to reversal of the condition (not the
2989 same as swapping the arguments). */
2991 static void
2992 mmix_output_condition (stream, x, reversed)
2993 FILE *stream;
2994 rtx x;
2995 int reversed;
2997 struct cc_conv
2999 RTX_CODE cc;
3001 /* The normal output cc-code. */
3002 const char *const normal;
3004 /* The reversed cc-code, or NULL if invalid. */
3005 const char *const reversed;
3008 struct cc_type_conv
3010 enum machine_mode cc_mode;
3012 /* Terminated with {NIL, NULL, NULL} */
3013 const struct cc_conv *const convs;
3016 #undef CCEND
3017 #define CCEND {NIL, NULL, NULL}
3019 static const struct cc_conv cc_fun_convs[]
3020 = {{ORDERED, "Z", "P"},
3021 {UNORDERED, "P", "Z"},
3022 CCEND};
3023 static const struct cc_conv cc_fp_convs[]
3024 = {{GT, "P", NULL},
3025 {LT, "N", NULL},
3026 CCEND};
3027 static const struct cc_conv cc_fpeq_convs[]
3028 = {{NE, "Z", "P"},
3029 {EQ, "P", "Z"},
3030 CCEND};
3031 static const struct cc_conv cc_uns_convs[]
3032 = {{GEU, "NN", "N"},
3033 {GTU, "P", "NP"},
3034 {LEU, "NP", "P"},
3035 {LTU, "N", "NN"},
3036 CCEND};
3037 static const struct cc_conv cc_signed_convs[]
3038 = {{NE, "NZ", "Z"},
3039 {EQ, "Z", "NZ"},
3040 {GE, "NN", "N"},
3041 {GT, "P", "NP"},
3042 {LE, "NP", "P"},
3043 {LT, "N", "NN"},
3044 CCEND};
3045 static const struct cc_conv cc_di_convs[]
3046 = {{NE, "NZ", "Z"},
3047 {EQ, "Z", "NZ"},
3048 {GE, "NN", "N"},
3049 {GT, "P", "NP"},
3050 {LE, "NP", "P"},
3051 {LT, "N", "NN"},
3052 {GTU, "NZ", "Z"},
3053 {LEU, "Z", "NZ"},
3054 CCEND};
3055 #undef CCEND
3057 static const struct cc_type_conv cc_convs[]
3058 = {{CC_FUNmode, cc_fun_convs},
3059 {CC_FPmode, cc_fp_convs},
3060 {CC_FPEQmode, cc_fpeq_convs},
3061 {CC_UNSmode, cc_uns_convs},
3062 {CCmode, cc_signed_convs},
3063 {DImode, cc_di_convs}};
3065 size_t i;
3066 int j;
3068 enum machine_mode mode = GET_MODE (XEXP (x, 0));
3069 RTX_CODE cc = GET_CODE (x);
3071 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
3073 if (mode == cc_convs[i].cc_mode)
3075 for (j = 0; cc_convs[i].convs[j].cc != NIL; j++)
3076 if (cc == cc_convs[i].convs[j].cc)
3078 const char *mmix_cc
3079 = (reversed ? cc_convs[i].convs[j].reversed
3080 : cc_convs[i].convs[j].normal);
3082 if (mmix_cc == NULL)
3083 fatal_insn ("MMIX Internal: Trying to output invalidly\
3084 reversed condition:", x);
3086 fprintf (stream, "%s", mmix_cc);
3087 return;
3090 fatal_insn ("MMIX Internal: What's the CC of this?", x);
3094 fatal_insn ("MMIX Internal: What is the CC of this?", x);
3097 /* Return the bit-value for a const_int or const_double. */
3099 static HOST_WIDEST_INT
3100 mmix_intval (x)
3101 rtx x;
3103 unsigned HOST_WIDEST_INT retval;
3105 if (GET_CODE (x) == CONST_INT)
3106 return INTVAL (x);
3108 /* We make a little song and dance because converting to long long in
3109 gcc-2.7.2 is broken. I still want people to be able to use it for
3110 cross-compilation to MMIX. */
3111 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
3113 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
3115 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
3116 retval *= 2;
3117 retval |= CONST_DOUBLE_LOW (x) & 1;
3119 retval |=
3120 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
3121 << (HOST_BITS_PER_LONG);
3123 else
3124 retval = CONST_DOUBLE_HIGH (x);
3126 return retval;
3129 if (GET_CODE (x) == CONST_DOUBLE)
3131 REAL_VALUE_TYPE value;
3133 /* FIXME: This macro is not in the manual but should be. */
3134 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
3136 if (GET_MODE (x) == DFmode)
3138 long bits[2];
3140 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
3142 if (sizeof (long) < sizeof (HOST_WIDEST_INT))
3144 retval = (unsigned long) bits[1] / 2;
3145 retval *= 2;
3146 retval |= (unsigned long) bits[1] & 1;
3147 retval
3148 |= (unsigned HOST_WIDEST_INT) bits[0]
3149 << (sizeof (bits[0]) * 8);
3151 else
3152 retval = (unsigned long) bits[1];
3154 return retval;
3156 else if (GET_MODE (x) == SFmode)
3158 long bits;
3159 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
3161 return (unsigned long) bits;
3165 fatal_insn ("MMIX Internal: This is not a constant:", x);
3169 * Local variables:
3170 * eval: (c-set-style "gnu")
3171 * indent-tabs-mode: t
3172 * End: