1 /* Subroutines for insn-output.c for HPPA.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
4 Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-attr.h"
41 #include "integrate.h"
49 #include "target-def.h"
51 /* Return nonzero if there is a bypass for the output of
52 OUT_INSN and the fp store IN_INSN. */
54 hppa_fpstore_bypass_p (rtx out_insn, rtx in_insn)
56 enum machine_mode store_mode;
57 enum machine_mode other_mode;
60 if (recog_memoized (in_insn) < 0
61 || (get_attr_type (in_insn) != TYPE_FPSTORE
62 && get_attr_type (in_insn) != TYPE_FPSTORE_LOAD)
63 || recog_memoized (out_insn) < 0)
66 store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
68 set = single_set (out_insn);
72 other_mode = GET_MODE (SET_SRC (set));
74 return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
78 #ifndef DO_FRAME_NOTES
79 #ifdef INCOMING_RETURN_ADDR_RTX
80 #define DO_FRAME_NOTES 1
82 #define DO_FRAME_NOTES 0
86 static void copy_reg_pointer (rtx, rtx);
87 static void fix_range (const char *);
88 static bool pa_handle_option (size_t, const char *, int);
89 static int hppa_address_cost (rtx);
90 static bool hppa_rtx_costs (rtx, int, int, int *);
91 static inline rtx force_mode (enum machine_mode, rtx);
92 static void pa_reorg (void);
93 static void pa_combine_instructions (void);
94 static int pa_can_combine_p (rtx, rtx, rtx, int, rtx, rtx, rtx);
95 static int forward_branch_p (rtx);
96 static void compute_zdepwi_operands (unsigned HOST_WIDE_INT, unsigned *);
97 static int compute_movmem_length (rtx);
98 static int compute_clrmem_length (rtx);
99 static bool pa_assemble_integer (rtx, unsigned int, int);
100 static void remove_useless_addtr_insns (int);
101 static void store_reg (int, HOST_WIDE_INT, int);
102 static void store_reg_modify (int, int, HOST_WIDE_INT);
103 static void load_reg (int, HOST_WIDE_INT, int);
104 static void set_reg_plus_d (int, int, HOST_WIDE_INT, int);
105 static void pa_output_function_prologue (FILE *, HOST_WIDE_INT);
106 static void update_total_code_bytes (int);
107 static void pa_output_function_epilogue (FILE *, HOST_WIDE_INT);
108 static int pa_adjust_cost (rtx, rtx, rtx, int);
109 static int pa_adjust_priority (rtx, int);
110 static int pa_issue_rate (void);
111 static void pa_som_asm_init_sections (void) ATTRIBUTE_UNUSED;
112 static section *pa_select_section (tree, int, unsigned HOST_WIDE_INT)
114 static void pa_encode_section_info (tree, rtx, int);
115 static const char *pa_strip_name_encoding (const char *);
116 static bool pa_function_ok_for_sibcall (tree, tree);
117 static void pa_globalize_label (FILE *, const char *)
119 static void pa_asm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
120 HOST_WIDE_INT, tree);
121 #if !defined(USE_COLLECT2)
122 static void pa_asm_out_constructor (rtx, int);
123 static void pa_asm_out_destructor (rtx, int);
125 static void pa_init_builtins (void);
126 static rtx hppa_builtin_saveregs (void);
127 static tree hppa_gimplify_va_arg_expr (tree, tree, tree *, tree *);
128 static bool pa_scalar_mode_supported_p (enum machine_mode);
129 static bool pa_commutative_p (rtx x, int outer_code);
130 static void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
131 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
132 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
133 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
134 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
135 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
136 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
137 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
138 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
139 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
140 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
141 static void output_deferred_plabels (void);
142 static void output_deferred_profile_counters (void) ATTRIBUTE_UNUSED;
143 #ifdef ASM_OUTPUT_EXTERNAL_REAL
144 static void pa_hpux_file_end (void);
146 #ifdef HPUX_LONG_DOUBLE_LIBRARY
147 static void pa_hpux_init_libfuncs (void);
149 static rtx pa_struct_value_rtx (tree, int);
150 static bool pa_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
152 static int pa_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
154 static struct machine_function * pa_init_machine_status (void);
155 static enum reg_class pa_secondary_reload (bool, rtx, enum reg_class,
157 secondary_reload_info *);
160 /* The following extra sections are only used for SOM. */
161 static GTY(()) section *som_readonly_data_section;
162 static GTY(()) section *som_one_only_readonly_data_section;
163 static GTY(()) section *som_one_only_data_section;
165 /* Save the operands last given to a compare for use when we
166 generate a scc or bcc insn. */
167 rtx hppa_compare_op0, hppa_compare_op1;
168 enum cmp_type hppa_branch_type;
170 /* Which cpu we are scheduling for. */
171 enum processor_type pa_cpu = TARGET_SCHED_DEFAULT;
173 /* The UNIX standard to use for predefines and linking. */
174 int flag_pa_unix = TARGET_HPUX_11_11 ? 1998 : TARGET_HPUX_10_10 ? 1995 : 1993;
176 /* Counts for the number of callee-saved general and floating point
177 registers which were saved by the current function's prologue. */
178 static int gr_saved, fr_saved;
180 static rtx find_addr_reg (rtx);
182 /* Keep track of the number of bytes we have output in the CODE subspace
183 during this compilation so we'll know when to emit inline long-calls. */
184 unsigned long total_code_bytes;
186 /* The last address of the previous function plus the number of bytes in
187 associated thunks that have been output. This is used to determine if
188 a thunk can use an IA-relative branch to reach its target function. */
189 static int last_address;
191 /* Variables to handle plabels that we discover are necessary at assembly
192 output time. They are output after the current function. */
193 struct deferred_plabel GTY(())
198 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
200 static size_t n_deferred_plabels = 0;
203 /* Initialize the GCC target structure. */
205 #undef TARGET_ASM_ALIGNED_HI_OP
206 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
207 #undef TARGET_ASM_ALIGNED_SI_OP
208 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
209 #undef TARGET_ASM_ALIGNED_DI_OP
210 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
211 #undef TARGET_ASM_UNALIGNED_HI_OP
212 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
213 #undef TARGET_ASM_UNALIGNED_SI_OP
214 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
215 #undef TARGET_ASM_UNALIGNED_DI_OP
216 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
217 #undef TARGET_ASM_INTEGER
218 #define TARGET_ASM_INTEGER pa_assemble_integer
220 #undef TARGET_ASM_FUNCTION_PROLOGUE
221 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
222 #undef TARGET_ASM_FUNCTION_EPILOGUE
223 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
225 #undef TARGET_SCHED_ADJUST_COST
226 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
227 #undef TARGET_SCHED_ADJUST_PRIORITY
228 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
229 #undef TARGET_SCHED_ISSUE_RATE
230 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
232 #undef TARGET_ENCODE_SECTION_INFO
233 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
234 #undef TARGET_STRIP_NAME_ENCODING
235 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
237 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
238 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
240 #undef TARGET_COMMUTATIVE_P
241 #define TARGET_COMMUTATIVE_P pa_commutative_p
243 #undef TARGET_ASM_OUTPUT_MI_THUNK
244 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
245 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
246 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
248 #undef TARGET_ASM_FILE_END
249 #ifdef ASM_OUTPUT_EXTERNAL_REAL
250 #define TARGET_ASM_FILE_END pa_hpux_file_end
252 #define TARGET_ASM_FILE_END output_deferred_plabels
255 #if !defined(USE_COLLECT2)
256 #undef TARGET_ASM_CONSTRUCTOR
257 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
258 #undef TARGET_ASM_DESTRUCTOR
259 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
262 #undef TARGET_DEFAULT_TARGET_FLAGS
263 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | TARGET_CPU_DEFAULT)
264 #undef TARGET_HANDLE_OPTION
265 #define TARGET_HANDLE_OPTION pa_handle_option
267 #undef TARGET_INIT_BUILTINS
268 #define TARGET_INIT_BUILTINS pa_init_builtins
270 #undef TARGET_RTX_COSTS
271 #define TARGET_RTX_COSTS hppa_rtx_costs
272 #undef TARGET_ADDRESS_COST
273 #define TARGET_ADDRESS_COST hppa_address_cost
275 #undef TARGET_MACHINE_DEPENDENT_REORG
276 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
278 #ifdef HPUX_LONG_DOUBLE_LIBRARY
279 #undef TARGET_INIT_LIBFUNCS
280 #define TARGET_INIT_LIBFUNCS pa_hpux_init_libfuncs
283 #undef TARGET_PROMOTE_FUNCTION_RETURN
284 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
285 #undef TARGET_PROMOTE_PROTOTYPES
286 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
288 #undef TARGET_STRUCT_VALUE_RTX
289 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
290 #undef TARGET_RETURN_IN_MEMORY
291 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
292 #undef TARGET_MUST_PASS_IN_STACK
293 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
294 #undef TARGET_PASS_BY_REFERENCE
295 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
296 #undef TARGET_CALLEE_COPIES
297 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
298 #undef TARGET_ARG_PARTIAL_BYTES
299 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
301 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
302 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
303 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
304 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
306 #undef TARGET_SCALAR_MODE_SUPPORTED_P
307 #define TARGET_SCALAR_MODE_SUPPORTED_P pa_scalar_mode_supported_p
309 #undef TARGET_CANNOT_FORCE_CONST_MEM
310 #define TARGET_CANNOT_FORCE_CONST_MEM pa_tls_referenced_p
312 #undef TARGET_SECONDARY_RELOAD
313 #define TARGET_SECONDARY_RELOAD pa_secondary_reload
315 struct gcc_target targetm = TARGET_INITIALIZER;
317 /* Parse the -mfixed-range= option string. */
320 fix_range (const char *const_str)
323 char *str, *dash, *comma;
325 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
326 REG2 are either register names or register numbers. The effect
327 of this option is to mark the registers in the range from REG1 to
328 REG2 as ``fixed'' so they won't be used by the compiler. This is
329 used, e.g., to ensure that kernel mode code doesn't use fr4-fr31. */
331 i = strlen (const_str);
332 str = (char *) alloca (i + 1);
333 memcpy (str, const_str, i + 1);
337 dash = strchr (str, '-');
340 warning (0, "value of -mfixed-range must have form REG1-REG2");
345 comma = strchr (dash + 1, ',');
349 first = decode_reg_name (str);
352 warning (0, "unknown register name: %s", str);
356 last = decode_reg_name (dash + 1);
359 warning (0, "unknown register name: %s", dash + 1);
367 warning (0, "%s-%s is an empty range", str, dash + 1);
371 for (i = first; i <= last; ++i)
372 fixed_regs[i] = call_used_regs[i] = 1;
381 /* Check if all floating point registers have been fixed. */
382 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
387 target_flags |= MASK_DISABLE_FPREGS;
390 /* Implement TARGET_HANDLE_OPTION. */
393 pa_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
398 case OPT_mpa_risc_1_0:
400 target_flags &= ~(MASK_PA_11 | MASK_PA_20);
404 case OPT_mpa_risc_1_1:
406 target_flags &= ~MASK_PA_20;
407 target_flags |= MASK_PA_11;
410 case OPT_mpa_risc_2_0:
412 target_flags |= MASK_PA_11 | MASK_PA_20;
416 if (strcmp (arg, "8000") == 0)
417 pa_cpu = PROCESSOR_8000;
418 else if (strcmp (arg, "7100") == 0)
419 pa_cpu = PROCESSOR_7100;
420 else if (strcmp (arg, "700") == 0)
421 pa_cpu = PROCESSOR_700;
422 else if (strcmp (arg, "7100LC") == 0)
423 pa_cpu = PROCESSOR_7100LC;
424 else if (strcmp (arg, "7200") == 0)
425 pa_cpu = PROCESSOR_7200;
426 else if (strcmp (arg, "7300") == 0)
427 pa_cpu = PROCESSOR_7300;
432 case OPT_mfixed_range_:
442 #if TARGET_HPUX_10_10
448 #if TARGET_HPUX_11_11
460 override_options (void)
462 /* Unconditional branches in the delay slot are not compatible with dwarf2
463 call frame information. There is no benefit in using this optimization
464 on PA8000 and later processors. */
465 if (pa_cpu >= PROCESSOR_8000
466 || (! USING_SJLJ_EXCEPTIONS && flag_exceptions)
467 || flag_unwind_tables)
468 target_flags &= ~MASK_JUMP_IN_DELAY;
470 if (flag_pic && TARGET_PORTABLE_RUNTIME)
472 warning (0, "PIC code generation is not supported in the portable runtime model");
475 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
477 warning (0, "PIC code generation is not compatible with fast indirect calls");
480 if (! TARGET_GAS && write_symbols != NO_DEBUG)
482 warning (0, "-g is only supported when using GAS on this processor,");
483 warning (0, "-g option disabled");
484 write_symbols = NO_DEBUG;
487 /* We only support the "big PIC" model now. And we always generate PIC
488 code when in 64bit mode. */
489 if (flag_pic == 1 || TARGET_64BIT)
492 /* We can't guarantee that .dword is available for 32-bit targets. */
493 if (UNITS_PER_WORD == 4)
494 targetm.asm_out.aligned_op.di = NULL;
496 /* The unaligned ops are only available when using GAS. */
499 targetm.asm_out.unaligned_op.hi = NULL;
500 targetm.asm_out.unaligned_op.si = NULL;
501 targetm.asm_out.unaligned_op.di = NULL;
504 init_machine_status = pa_init_machine_status;
508 pa_init_builtins (void)
510 #ifdef DONT_HAVE_FPUTC_UNLOCKED
511 built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] =
512 built_in_decls[(int) BUILT_IN_PUTC_UNLOCKED];
513 implicit_built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED]
514 = implicit_built_in_decls[(int) BUILT_IN_PUTC_UNLOCKED];
517 if (built_in_decls [BUILT_IN_FINITE])
518 set_user_assembler_name (built_in_decls [BUILT_IN_FINITE], "_Isfinite");
519 if (built_in_decls [BUILT_IN_FINITEF])
520 set_user_assembler_name (built_in_decls [BUILT_IN_FINITEF], "_Isfinitef");
524 /* Function to init struct machine_function.
525 This will be called, via a pointer variable,
526 from push_function_context. */
528 static struct machine_function *
529 pa_init_machine_status (void)
531 return ggc_alloc_cleared (sizeof (machine_function));
534 /* If FROM is a probable pointer register, mark TO as a probable
535 pointer register with the same pointer alignment as FROM. */
538 copy_reg_pointer (rtx to, rtx from)
540 if (REG_POINTER (from))
541 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
544 /* Return 1 if X contains a symbolic expression. We know these
545 expressions will have one of a few well defined forms, so
546 we need only check those forms. */
548 symbolic_expression_p (rtx x)
551 /* Strip off any HIGH. */
552 if (GET_CODE (x) == HIGH)
555 return (symbolic_operand (x, VOIDmode));
558 /* Accept any constant that can be moved in one instruction into a
561 cint_ok_for_move (HOST_WIDE_INT intval)
563 /* OK if ldo, ldil, or zdepi, can be used. */
564 return (CONST_OK_FOR_LETTER_P (intval, 'J')
565 || CONST_OK_FOR_LETTER_P (intval, 'N')
566 || CONST_OK_FOR_LETTER_P (intval, 'K'));
569 /* Return truth value of whether OP can be used as an operand in a
572 adddi3_operand (rtx op, enum machine_mode mode)
574 return (register_operand (op, mode)
575 || (GET_CODE (op) == CONST_INT
576 && (TARGET_64BIT ? INT_14_BITS (op) : INT_11_BITS (op))));
579 /* True iff zdepi can be used to generate this CONST_INT.
580 zdepi first sign extends a 5-bit signed number to a given field
581 length, then places this field anywhere in a zero. */
583 zdepi_cint_p (unsigned HOST_WIDE_INT x)
585 unsigned HOST_WIDE_INT lsb_mask, t;
587 /* This might not be obvious, but it's at least fast.
588 This function is critical; we don't have the time loops would take. */
590 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
591 /* Return true iff t is a power of two. */
592 return ((t & (t - 1)) == 0);
595 /* True iff depi or extru can be used to compute (reg & mask).
596 Accept bit pattern like these:
601 and_mask_p (unsigned HOST_WIDE_INT mask)
604 mask += mask & -mask;
605 return (mask & (mask - 1)) == 0;
608 /* True iff depi can be used to compute (reg | MASK). */
610 ior_mask_p (unsigned HOST_WIDE_INT mask)
612 mask += mask & -mask;
613 return (mask & (mask - 1)) == 0;
616 /* Legitimize PIC addresses. If the address is already
617 position-independent, we return ORIG. Newly generated
618 position-independent addresses go to REG. If we need more
619 than one register, we lose. */
622 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
626 gcc_assert (!PA_SYMBOL_REF_TLS_P (orig));
628 /* Labels need special handling. */
629 if (pic_label_operand (orig, mode))
631 /* We do not want to go through the movXX expanders here since that
632 would create recursion.
634 Nor do we really want to call a generator for a named pattern
635 since that requires multiple patterns if we want to support
638 So instead we just emit the raw set, which avoids the movXX
639 expanders completely. */
640 mark_reg_pointer (reg, BITS_PER_UNIT);
641 emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
642 current_function_uses_pic_offset_table = 1;
645 if (GET_CODE (orig) == SYMBOL_REF)
651 /* Before reload, allocate a temporary register for the intermediate
652 result. This allows the sequence to be deleted when the final
653 result is unused and the insns are trivially dead. */
654 tmp_reg = ((reload_in_progress || reload_completed)
655 ? reg : gen_reg_rtx (Pmode));
657 emit_move_insn (tmp_reg,
658 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
659 gen_rtx_HIGH (word_mode, orig)));
661 = gen_const_mem (Pmode,
662 gen_rtx_LO_SUM (Pmode, tmp_reg,
663 gen_rtx_UNSPEC (Pmode,
667 current_function_uses_pic_offset_table = 1;
668 mark_reg_pointer (reg, BITS_PER_UNIT);
669 insn = emit_move_insn (reg, pic_ref);
671 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
672 set_unique_reg_note (insn, REG_EQUAL, orig);
676 else if (GET_CODE (orig) == CONST)
680 if (GET_CODE (XEXP (orig, 0)) == PLUS
681 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
685 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
687 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
688 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
689 base == reg ? 0 : reg);
691 if (GET_CODE (orig) == CONST_INT)
693 if (INT_14_BITS (orig))
694 return plus_constant (base, INTVAL (orig));
695 orig = force_reg (Pmode, orig);
697 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
698 /* Likewise, should we set special REG_NOTEs here? */
704 static GTY(()) rtx gen_tls_tga;
707 gen_tls_get_addr (void)
710 gen_tls_tga = init_one_libfunc ("__tls_get_addr");
715 hppa_tls_call (rtx arg)
719 ret = gen_reg_rtx (Pmode);
720 emit_library_call_value (gen_tls_get_addr (), ret,
721 LCT_CONST, Pmode, 1, arg, Pmode);
727 legitimize_tls_address (rtx addr)
729 rtx ret, insn, tmp, t1, t2, tp;
730 enum tls_model model = SYMBOL_REF_TLS_MODEL (addr);
734 case TLS_MODEL_GLOBAL_DYNAMIC:
735 tmp = gen_reg_rtx (Pmode);
736 emit_insn (gen_tgd_load (tmp, addr));
737 ret = hppa_tls_call (tmp);
740 case TLS_MODEL_LOCAL_DYNAMIC:
741 ret = gen_reg_rtx (Pmode);
742 tmp = gen_reg_rtx (Pmode);
744 emit_insn (gen_tld_load (tmp, addr));
745 t1 = hppa_tls_call (tmp);
748 t2 = gen_reg_rtx (Pmode);
749 emit_libcall_block (insn, t2, t1,
750 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
752 emit_insn (gen_tld_offset_load (ret, addr, t2));
755 case TLS_MODEL_INITIAL_EXEC:
756 tp = gen_reg_rtx (Pmode);
757 tmp = gen_reg_rtx (Pmode);
758 ret = gen_reg_rtx (Pmode);
759 emit_insn (gen_tp_load (tp));
760 emit_insn (gen_tie_load (tmp, addr));
761 emit_move_insn (ret, gen_rtx_PLUS (Pmode, tp, tmp));
764 case TLS_MODEL_LOCAL_EXEC:
765 tp = gen_reg_rtx (Pmode);
766 ret = gen_reg_rtx (Pmode);
767 emit_insn (gen_tp_load (tp));
768 emit_insn (gen_tle_load (ret, addr, tp));
778 /* Try machine-dependent ways of modifying an illegitimate address
779 to be legitimate. If we find one, return the new, valid address.
780 This macro is used in only one place: `memory_address' in explow.c.
782 OLDX is the address as it was before break_out_memory_refs was called.
783 In some cases it is useful to look at this to decide what needs to be done.
785 MODE and WIN are passed so that this macro can use
786 GO_IF_LEGITIMATE_ADDRESS.
788 It is always safe for this macro to do nothing. It exists to recognize
789 opportunities to optimize the output.
791 For the PA, transform:
793 memory(X + <large int>)
797 if (<large int> & mask) >= 16
798 Y = (<large int> & ~mask) + mask + 1 Round up.
800 Y = (<large int> & ~mask) Round down.
802 memory (Z + (<large int> - Y));
804 This is for CSE to find several similar references, and only use one Z.
806 X can either be a SYMBOL_REF or REG, but because combine cannot
807 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
808 D will not fit in 14 bits.
810 MODE_FLOAT references allow displacements which fit in 5 bits, so use
813 MODE_INT references allow displacements which fit in 14 bits, so use
816 This relies on the fact that most mode MODE_FLOAT references will use FP
817 registers and most mode MODE_INT references will use integer registers.
818 (In the rare case of an FP register used in an integer MODE, we depend
819 on secondary reloads to clean things up.)
822 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
823 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
824 addressing modes to be used).
826 Put X and Z into registers. Then put the entire expression into
830 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
831 enum machine_mode mode)
835 /* We need to canonicalize the order of operands in unscaled indexed
836 addresses since the code that checks if an address is valid doesn't
837 always try both orders. */
838 if (!TARGET_NO_SPACE_REGS
839 && GET_CODE (x) == PLUS
840 && GET_MODE (x) == Pmode
841 && REG_P (XEXP (x, 0))
842 && REG_P (XEXP (x, 1))
843 && REG_POINTER (XEXP (x, 0))
844 && !REG_POINTER (XEXP (x, 1)))
845 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
847 if (PA_SYMBOL_REF_TLS_P (x))
848 return legitimize_tls_address (x);
850 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
852 /* Strip off CONST. */
853 if (GET_CODE (x) == CONST)
856 /* Special case. Get the SYMBOL_REF into a register and use indexing.
857 That should always be safe. */
858 if (GET_CODE (x) == PLUS
859 && GET_CODE (XEXP (x, 0)) == REG
860 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
862 rtx reg = force_reg (Pmode, XEXP (x, 1));
863 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
866 /* Note we must reject symbols which represent function addresses
867 since the assembler/linker can't handle arithmetic on plabels. */
868 if (GET_CODE (x) == PLUS
869 && GET_CODE (XEXP (x, 1)) == CONST_INT
870 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
871 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
872 || GET_CODE (XEXP (x, 0)) == REG))
874 rtx int_part, ptr_reg;
876 int offset = INTVAL (XEXP (x, 1));
879 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
880 ? (TARGET_PA_20 ? 0x3fff : 0x1f) : 0x3fff);
882 /* Choose which way to round the offset. Round up if we
883 are >= halfway to the next boundary. */
884 if ((offset & mask) >= ((mask + 1) / 2))
885 newoffset = (offset & ~ mask) + mask + 1;
887 newoffset = (offset & ~ mask);
889 /* If the newoffset will not fit in 14 bits (ldo), then
890 handling this would take 4 or 5 instructions (2 to load
891 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
892 add the new offset and the SYMBOL_REF.) Combine can
893 not handle 4->2 or 5->2 combinations, so do not create
895 if (! VAL_14_BITS_P (newoffset)
896 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
898 rtx const_part = plus_constant (XEXP (x, 0), newoffset);
901 gen_rtx_HIGH (Pmode, const_part));
904 gen_rtx_LO_SUM (Pmode,
905 tmp_reg, const_part));
909 if (! VAL_14_BITS_P (newoffset))
910 int_part = force_reg (Pmode, GEN_INT (newoffset));
912 int_part = GEN_INT (newoffset);
914 ptr_reg = force_reg (Pmode,
916 force_reg (Pmode, XEXP (x, 0)),
919 return plus_constant (ptr_reg, offset - newoffset);
922 /* Handle (plus (mult (a) (shadd_constant)) (b)). */
924 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
925 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
926 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
927 && (OBJECT_P (XEXP (x, 1))
928 || GET_CODE (XEXP (x, 1)) == SUBREG)
929 && GET_CODE (XEXP (x, 1)) != CONST)
931 int val = INTVAL (XEXP (XEXP (x, 0), 1));
935 if (GET_CODE (reg1) != REG)
936 reg1 = force_reg (Pmode, force_operand (reg1, 0));
938 reg2 = XEXP (XEXP (x, 0), 0);
939 if (GET_CODE (reg2) != REG)
940 reg2 = force_reg (Pmode, force_operand (reg2, 0));
942 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
949 /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
951 Only do so for floating point modes since this is more speculative
952 and we lose if it's an integer store. */
953 if (GET_CODE (x) == PLUS
954 && GET_CODE (XEXP (x, 0)) == PLUS
955 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
956 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
957 && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
958 && (mode == SFmode || mode == DFmode))
961 /* First, try and figure out what to use as a base register. */
962 rtx reg1, reg2, base, idx, orig_base;
964 reg1 = XEXP (XEXP (x, 0), 1);
969 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
970 then emit_move_sequence will turn on REG_POINTER so we'll know
971 it's a base register below. */
972 if (GET_CODE (reg1) != REG)
973 reg1 = force_reg (Pmode, force_operand (reg1, 0));
975 if (GET_CODE (reg2) != REG)
976 reg2 = force_reg (Pmode, force_operand (reg2, 0));
978 /* Figure out what the base and index are. */
980 if (GET_CODE (reg1) == REG
981 && REG_POINTER (reg1))
984 orig_base = XEXP (XEXP (x, 0), 1);
985 idx = gen_rtx_PLUS (Pmode,
987 XEXP (XEXP (XEXP (x, 0), 0), 0),
988 XEXP (XEXP (XEXP (x, 0), 0), 1)),
991 else if (GET_CODE (reg2) == REG
992 && REG_POINTER (reg2))
995 orig_base = XEXP (x, 1);
1002 /* If the index adds a large constant, try to scale the
1003 constant so that it can be loaded with only one insn. */
1004 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1005 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1006 / INTVAL (XEXP (XEXP (idx, 0), 1)))
1007 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1009 /* Divide the CONST_INT by the scale factor, then add it to A. */
1010 int val = INTVAL (XEXP (idx, 1));
1012 val /= INTVAL (XEXP (XEXP (idx, 0), 1));
1013 reg1 = XEXP (XEXP (idx, 0), 0);
1014 if (GET_CODE (reg1) != REG)
1015 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1017 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1019 /* We can now generate a simple scaled indexed address. */
1022 (Pmode, gen_rtx_PLUS (Pmode,
1023 gen_rtx_MULT (Pmode, reg1,
1024 XEXP (XEXP (idx, 0), 1)),
1028 /* If B + C is still a valid base register, then add them. */
1029 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1030 && INTVAL (XEXP (idx, 1)) <= 4096
1031 && INTVAL (XEXP (idx, 1)) >= -4096)
1033 int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1036 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1038 reg2 = XEXP (XEXP (idx, 0), 0);
1039 if (GET_CODE (reg2) != CONST_INT)
1040 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1042 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1043 gen_rtx_MULT (Pmode,
1049 /* Get the index into a register, then add the base + index and
1050 return a register holding the result. */
1052 /* First get A into a register. */
1053 reg1 = XEXP (XEXP (idx, 0), 0);
1054 if (GET_CODE (reg1) != REG)
1055 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1057 /* And get B into a register. */
1058 reg2 = XEXP (idx, 1);
1059 if (GET_CODE (reg2) != REG)
1060 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1062 reg1 = force_reg (Pmode,
1063 gen_rtx_PLUS (Pmode,
1064 gen_rtx_MULT (Pmode, reg1,
1065 XEXP (XEXP (idx, 0), 1)),
1068 /* Add the result to our base register and return. */
1069 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1073 /* Uh-oh. We might have an address for x[n-100000]. This needs
1074 special handling to avoid creating an indexed memory address
1075 with x-100000 as the base.
1077 If the constant part is small enough, then it's still safe because
1078 there is a guard page at the beginning and end of the data segment.
1080 Scaled references are common enough that we want to try and rearrange the
1081 terms so that we can use indexing for these addresses too. Only
1082 do the optimization for floatint point modes. */
1084 if (GET_CODE (x) == PLUS
1085 && symbolic_expression_p (XEXP (x, 1)))
1087 /* Ugly. We modify things here so that the address offset specified
1088 by the index expression is computed first, then added to x to form
1089 the entire address. */
1091 rtx regx1, regx2, regy1, regy2, y;
1093 /* Strip off any CONST. */
1095 if (GET_CODE (y) == CONST)
1098 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1100 /* See if this looks like
1101 (plus (mult (reg) (shadd_const))
1102 (const (plus (symbol_ref) (const_int))))
1104 Where const_int is small. In that case the const
1105 expression is a valid pointer for indexing.
1107 If const_int is big, but can be divided evenly by shadd_const
1108 and added to (reg). This allows more scaled indexed addresses. */
1109 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1110 && GET_CODE (XEXP (x, 0)) == MULT
1111 && GET_CODE (XEXP (y, 1)) == CONST_INT
1112 && INTVAL (XEXP (y, 1)) >= -4096
1113 && INTVAL (XEXP (y, 1)) <= 4095
1114 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1115 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1117 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1121 if (GET_CODE (reg1) != REG)
1122 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1124 reg2 = XEXP (XEXP (x, 0), 0);
1125 if (GET_CODE (reg2) != REG)
1126 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1128 return force_reg (Pmode,
1129 gen_rtx_PLUS (Pmode,
1130 gen_rtx_MULT (Pmode,
1135 else if ((mode == DFmode || mode == SFmode)
1136 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1137 && GET_CODE (XEXP (x, 0)) == MULT
1138 && GET_CODE (XEXP (y, 1)) == CONST_INT
1139 && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1140 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1141 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1144 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1145 / INTVAL (XEXP (XEXP (x, 0), 1))));
1146 regx2 = XEXP (XEXP (x, 0), 0);
1147 if (GET_CODE (regx2) != REG)
1148 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1149 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1153 gen_rtx_PLUS (Pmode,
1154 gen_rtx_MULT (Pmode, regx2,
1155 XEXP (XEXP (x, 0), 1)),
1156 force_reg (Pmode, XEXP (y, 0))));
1158 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1159 && INTVAL (XEXP (y, 1)) >= -4096
1160 && INTVAL (XEXP (y, 1)) <= 4095)
1162 /* This is safe because of the guard page at the
1163 beginning and end of the data space. Just
1164 return the original address. */
1169 /* Doesn't look like one we can optimize. */
1170 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1171 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1172 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1173 regx1 = force_reg (Pmode,
1174 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1176 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1184 /* For the HPPA, REG and REG+CONST is cost 0
1185 and addresses involving symbolic constants are cost 2.
1187 PIC addresses are very expensive.
1189 It is no coincidence that this has the same structure
1190 as GO_IF_LEGITIMATE_ADDRESS. */
1193 hppa_address_cost (rtx X)
1195 switch (GET_CODE (X))
1208 /* Compute a (partial) cost for rtx X. Return true if the complete
1209 cost has been computed, and false if subexpressions should be
1210 scanned. In either case, *TOTAL contains the cost result. */
1213 hppa_rtx_costs (rtx x, int code, int outer_code, int *total)
1218 if (INTVAL (x) == 0)
1220 else if (INT_14_BITS (x))
1237 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1238 && outer_code != SET)
1245 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1246 *total = COSTS_N_INSNS (3);
1247 else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1248 *total = COSTS_N_INSNS (8);
1250 *total = COSTS_N_INSNS (20);
1254 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1256 *total = COSTS_N_INSNS (14);
1264 *total = COSTS_N_INSNS (60);
1267 case PLUS: /* this includes shNadd insns */
1269 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1270 *total = COSTS_N_INSNS (3);
1272 *total = COSTS_N_INSNS (1);
1278 *total = COSTS_N_INSNS (1);
1286 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1287 new rtx with the correct mode. */
1289 force_mode (enum machine_mode mode, rtx orig)
1291 if (mode == GET_MODE (orig))
1294 gcc_assert (REGNO (orig) < FIRST_PSEUDO_REGISTER);
1296 return gen_rtx_REG (mode, REGNO (orig));
1299 /* Return 1 if *X is a thread-local symbol. */
1302 pa_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1304 return PA_SYMBOL_REF_TLS_P (*x);
1307 /* Return 1 if X contains a thread-local symbol. */
1310 pa_tls_referenced_p (rtx x)
1312 if (!TARGET_HAVE_TLS)
1315 return for_each_rtx (&x, &pa_tls_symbol_ref_1, 0);
1318 /* Emit insns to move operands[1] into operands[0].
1320 Return 1 if we have written out everything that needs to be done to
1321 do the move. Otherwise, return 0 and the caller will emit the move
1324 Note SCRATCH_REG may not be in the proper mode depending on how it
1325 will be used. This routine is responsible for creating a new copy
1326 of SCRATCH_REG in the proper mode. */
1329 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1331 register rtx operand0 = operands[0];
1332 register rtx operand1 = operands[1];
1335 /* We can only handle indexed addresses in the destination operand
1336 of floating point stores. Thus, we need to break out indexed
1337 addresses from the destination operand. */
1338 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1340 /* This is only safe up to the beginning of life analysis. */
1341 gcc_assert (!no_new_pseudos);
1343 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1344 operand0 = replace_equiv_address (operand0, tem);
1347 /* On targets with non-equivalent space registers, break out unscaled
1348 indexed addresses from the source operand before the final CSE.
1349 We have to do this because the REG_POINTER flag is not correctly
1350 carried through various optimization passes and CSE may substitute
1351 a pseudo without the pointer set for one with the pointer set. As
1352 a result, we loose various opportunities to create insns with
1353 unscaled indexed addresses. */
1354 if (!TARGET_NO_SPACE_REGS
1355 && !cse_not_expected
1356 && GET_CODE (operand1) == MEM
1357 && GET_CODE (XEXP (operand1, 0)) == PLUS
1358 && REG_P (XEXP (XEXP (operand1, 0), 0))
1359 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1361 = replace_equiv_address (operand1,
1362 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1365 && reload_in_progress && GET_CODE (operand0) == REG
1366 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1367 operand0 = reg_equiv_mem[REGNO (operand0)];
1368 else if (scratch_reg
1369 && reload_in_progress && GET_CODE (operand0) == SUBREG
1370 && GET_CODE (SUBREG_REG (operand0)) == REG
1371 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1373 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1374 the code which tracks sets/uses for delete_output_reload. */
1375 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1376 reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1377 SUBREG_BYTE (operand0));
1378 operand0 = alter_subreg (&temp);
1382 && reload_in_progress && GET_CODE (operand1) == REG
1383 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1384 operand1 = reg_equiv_mem[REGNO (operand1)];
1385 else if (scratch_reg
1386 && reload_in_progress && GET_CODE (operand1) == SUBREG
1387 && GET_CODE (SUBREG_REG (operand1)) == REG
1388 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1390 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1391 the code which tracks sets/uses for delete_output_reload. */
1392 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1393 reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1394 SUBREG_BYTE (operand1));
1395 operand1 = alter_subreg (&temp);
1398 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1399 && ((tem = find_replacement (&XEXP (operand0, 0)))
1400 != XEXP (operand0, 0)))
1401 operand0 = replace_equiv_address (operand0, tem);
1403 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1404 && ((tem = find_replacement (&XEXP (operand1, 0)))
1405 != XEXP (operand1, 0)))
1406 operand1 = replace_equiv_address (operand1, tem);
1408 /* Handle secondary reloads for loads/stores of FP registers from
1409 REG+D addresses where D does not fit in 5 or 14 bits, including
1410 (subreg (mem (addr))) cases. */
1412 && fp_reg_operand (operand0, mode)
1413 && ((GET_CODE (operand1) == MEM
1414 && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1415 XEXP (operand1, 0)))
1416 || ((GET_CODE (operand1) == SUBREG
1417 && GET_CODE (XEXP (operand1, 0)) == MEM
1418 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1420 XEXP (XEXP (operand1, 0), 0))))))
1422 if (GET_CODE (operand1) == SUBREG)
1423 operand1 = XEXP (operand1, 0);
1425 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1426 it in WORD_MODE regardless of what mode it was originally given
1428 scratch_reg = force_mode (word_mode, scratch_reg);
1430 /* D might not fit in 14 bits either; for such cases load D into
1432 if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1434 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1435 emit_move_insn (scratch_reg,
1436 gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1438 XEXP (XEXP (operand1, 0), 0),
1442 emit_move_insn (scratch_reg, XEXP (operand1, 0));
1443 emit_insn (gen_rtx_SET (VOIDmode, operand0,
1444 replace_equiv_address (operand1, scratch_reg)));
1447 else if (scratch_reg
1448 && fp_reg_operand (operand1, mode)
1449 && ((GET_CODE (operand0) == MEM
1450 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1452 XEXP (operand0, 0)))
1453 || ((GET_CODE (operand0) == SUBREG)
1454 && GET_CODE (XEXP (operand0, 0)) == MEM
1455 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1457 XEXP (XEXP (operand0, 0), 0)))))
1459 if (GET_CODE (operand0) == SUBREG)
1460 operand0 = XEXP (operand0, 0);
1462 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1463 it in WORD_MODE regardless of what mode it was originally given
1465 scratch_reg = force_mode (word_mode, scratch_reg);
1467 /* D might not fit in 14 bits either; for such cases load D into
1469 if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1471 emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1472 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1475 XEXP (XEXP (operand0, 0),
1480 emit_move_insn (scratch_reg, XEXP (operand0, 0));
1481 emit_insn (gen_rtx_SET (VOIDmode,
1482 replace_equiv_address (operand0, scratch_reg),
1486 /* Handle secondary reloads for loads of FP registers from constant
1487 expressions by forcing the constant into memory.
1489 Use scratch_reg to hold the address of the memory location.
1491 The proper fix is to change PREFERRED_RELOAD_CLASS to return
1492 NO_REGS when presented with a const_int and a register class
1493 containing only FP registers. Doing so unfortunately creates
1494 more problems than it solves. Fix this for 2.5. */
1495 else if (scratch_reg
1496 && CONSTANT_P (operand1)
1497 && fp_reg_operand (operand0, mode))
1499 rtx const_mem, xoperands[2];
1501 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1502 it in WORD_MODE regardless of what mode it was originally given
1504 scratch_reg = force_mode (word_mode, scratch_reg);
1506 /* Force the constant into memory and put the address of the
1507 memory location into scratch_reg. */
1508 const_mem = force_const_mem (mode, operand1);
1509 xoperands[0] = scratch_reg;
1510 xoperands[1] = XEXP (const_mem, 0);
1511 emit_move_sequence (xoperands, Pmode, 0);
1513 /* Now load the destination register. */
1514 emit_insn (gen_rtx_SET (mode, operand0,
1515 replace_equiv_address (const_mem, scratch_reg)));
1518 /* Handle secondary reloads for SAR. These occur when trying to load
1519 the SAR from memory, FP register, or with a constant. */
1520 else if (scratch_reg
1521 && GET_CODE (operand0) == REG
1522 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1523 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1524 && (GET_CODE (operand1) == MEM
1525 || GET_CODE (operand1) == CONST_INT
1526 || (GET_CODE (operand1) == REG
1527 && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1))))))
1529 /* D might not fit in 14 bits either; for such cases load D into
1531 if (GET_CODE (operand1) == MEM
1532 && !memory_address_p (Pmode, XEXP (operand1, 0)))
1534 /* We are reloading the address into the scratch register, so we
1535 want to make sure the scratch register is a full register. */
1536 scratch_reg = force_mode (word_mode, scratch_reg);
1538 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1539 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1542 XEXP (XEXP (operand1, 0),
1546 /* Now we are going to load the scratch register from memory,
1547 we want to load it in the same width as the original MEM,
1548 which must be the same as the width of the ultimate destination,
1550 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1552 emit_move_insn (scratch_reg,
1553 replace_equiv_address (operand1, scratch_reg));
1557 /* We want to load the scratch register using the same mode as
1558 the ultimate destination. */
1559 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1561 emit_move_insn (scratch_reg, operand1);
1564 /* And emit the insn to set the ultimate destination. We know that
1565 the scratch register has the same mode as the destination at this
1567 emit_move_insn (operand0, scratch_reg);
1570 /* Handle the most common case: storing into a register. */
1571 else if (register_operand (operand0, mode))
1573 if (register_operand (operand1, mode)
1574 || (GET_CODE (operand1) == CONST_INT
1575 && cint_ok_for_move (INTVAL (operand1)))
1576 || (operand1 == CONST0_RTX (mode))
1577 || (GET_CODE (operand1) == HIGH
1578 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1579 /* Only `general_operands' can come here, so MEM is ok. */
1580 || GET_CODE (operand1) == MEM)
1582 /* Various sets are created during RTL generation which don't
1583 have the REG_POINTER flag correctly set. After the CSE pass,
1584 instruction recognition can fail if we don't consistently
1585 set this flag when performing register copies. This should
1586 also improve the opportunities for creating insns that use
1587 unscaled indexing. */
1588 if (REG_P (operand0) && REG_P (operand1))
1590 if (REG_POINTER (operand1)
1591 && !REG_POINTER (operand0)
1592 && !HARD_REGISTER_P (operand0))
1593 copy_reg_pointer (operand0, operand1);
1594 else if (REG_POINTER (operand0)
1595 && !REG_POINTER (operand1)
1596 && !HARD_REGISTER_P (operand1))
1597 copy_reg_pointer (operand1, operand0);
1600 /* When MEMs are broken out, the REG_POINTER flag doesn't
1601 get set. In some cases, we can set the REG_POINTER flag
1602 from the declaration for the MEM. */
1603 if (REG_P (operand0)
1604 && GET_CODE (operand1) == MEM
1605 && !REG_POINTER (operand0))
1607 tree decl = MEM_EXPR (operand1);
1609 /* Set the register pointer flag and register alignment
1610 if the declaration for this memory reference is a
1611 pointer type. Fortran indirect argument references
1614 && !(flag_argument_noalias > 1
1615 && TREE_CODE (decl) == INDIRECT_REF
1616 && TREE_CODE (TREE_OPERAND (decl, 0)) == PARM_DECL))
1620 /* If this is a COMPONENT_REF, use the FIELD_DECL from
1622 if (TREE_CODE (decl) == COMPONENT_REF)
1623 decl = TREE_OPERAND (decl, 1);
1625 type = TREE_TYPE (decl);
1626 if (TREE_CODE (type) == ARRAY_TYPE)
1627 type = get_inner_array_type (type);
1629 if (POINTER_TYPE_P (type))
1633 type = TREE_TYPE (type);
1634 /* Using TYPE_ALIGN_OK is rather conservative as
1635 only the ada frontend actually sets it. */
1636 align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1638 mark_reg_pointer (operand0, align);
1643 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1647 else if (GET_CODE (operand0) == MEM)
1649 if (mode == DFmode && operand1 == CONST0_RTX (mode)
1650 && !(reload_in_progress || reload_completed))
1652 rtx temp = gen_reg_rtx (DFmode);
1654 emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
1655 emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
1658 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
1660 /* Run this case quickly. */
1661 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1664 if (! (reload_in_progress || reload_completed))
1666 operands[0] = validize_mem (operand0);
1667 operands[1] = operand1 = force_reg (mode, operand1);
1671 /* Simplify the source if we need to.
1672 Note we do have to handle function labels here, even though we do
1673 not consider them legitimate constants. Loop optimizations can
1674 call the emit_move_xxx with one as a source. */
1675 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
1676 || function_label_operand (operand1, mode)
1677 || (GET_CODE (operand1) == HIGH
1678 && symbolic_operand (XEXP (operand1, 0), mode)))
1682 if (GET_CODE (operand1) == HIGH)
1685 operand1 = XEXP (operand1, 0);
1687 if (symbolic_operand (operand1, mode))
1689 /* Argh. The assembler and linker can't handle arithmetic
1692 So we force the plabel into memory, load operand0 from
1693 the memory location, then add in the constant part. */
1694 if ((GET_CODE (operand1) == CONST
1695 && GET_CODE (XEXP (operand1, 0)) == PLUS
1696 && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
1697 || function_label_operand (operand1, mode))
1699 rtx temp, const_part;
1701 /* Figure out what (if any) scratch register to use. */
1702 if (reload_in_progress || reload_completed)
1704 scratch_reg = scratch_reg ? scratch_reg : operand0;
1705 /* SCRATCH_REG will hold an address and maybe the actual
1706 data. We want it in WORD_MODE regardless of what mode it
1707 was originally given to us. */
1708 scratch_reg = force_mode (word_mode, scratch_reg);
1711 scratch_reg = gen_reg_rtx (Pmode);
1713 if (GET_CODE (operand1) == CONST)
1715 /* Save away the constant part of the expression. */
1716 const_part = XEXP (XEXP (operand1, 0), 1);
1717 gcc_assert (GET_CODE (const_part) == CONST_INT);
1719 /* Force the function label into memory. */
1720 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
1724 /* No constant part. */
1725 const_part = NULL_RTX;
1727 /* Force the function label into memory. */
1728 temp = force_const_mem (mode, operand1);
1732 /* Get the address of the memory location. PIC-ify it if
1734 temp = XEXP (temp, 0);
1736 temp = legitimize_pic_address (temp, mode, scratch_reg);
1738 /* Put the address of the memory location into our destination
1741 emit_move_sequence (operands, mode, scratch_reg);
1743 /* Now load from the memory location into our destination
1745 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
1746 emit_move_sequence (operands, mode, scratch_reg);
1748 /* And add back in the constant part. */
1749 if (const_part != NULL_RTX)
1750 expand_inc (operand0, const_part);
1759 if (reload_in_progress || reload_completed)
1761 temp = scratch_reg ? scratch_reg : operand0;
1762 /* TEMP will hold an address and maybe the actual
1763 data. We want it in WORD_MODE regardless of what mode it
1764 was originally given to us. */
1765 temp = force_mode (word_mode, temp);
1768 temp = gen_reg_rtx (Pmode);
1770 /* (const (plus (symbol) (const_int))) must be forced to
1771 memory during/after reload if the const_int will not fit
1773 if (GET_CODE (operand1) == CONST
1774 && GET_CODE (XEXP (operand1, 0)) == PLUS
1775 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
1776 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
1777 && (reload_completed || reload_in_progress)
1780 rtx const_mem = force_const_mem (mode, operand1);
1781 operands[1] = legitimize_pic_address (XEXP (const_mem, 0),
1783 operands[1] = replace_equiv_address (const_mem, operands[1]);
1784 emit_move_sequence (operands, mode, temp);
1788 operands[1] = legitimize_pic_address (operand1, mode, temp);
1789 if (REG_P (operand0) && REG_P (operands[1]))
1790 copy_reg_pointer (operand0, operands[1]);
1791 emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
1794 /* On the HPPA, references to data space are supposed to use dp,
1795 register 27, but showing it in the RTL inhibits various cse
1796 and loop optimizations. */
1801 if (reload_in_progress || reload_completed)
1803 temp = scratch_reg ? scratch_reg : operand0;
1804 /* TEMP will hold an address and maybe the actual
1805 data. We want it in WORD_MODE regardless of what mode it
1806 was originally given to us. */
1807 temp = force_mode (word_mode, temp);
1810 temp = gen_reg_rtx (mode);
1812 /* Loading a SYMBOL_REF into a register makes that register
1813 safe to be used as the base in an indexed address.
1815 Don't mark hard registers though. That loses. */
1816 if (GET_CODE (operand0) == REG
1817 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1818 mark_reg_pointer (operand0, BITS_PER_UNIT);
1819 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
1820 mark_reg_pointer (temp, BITS_PER_UNIT);
1823 set = gen_rtx_SET (mode, operand0, temp);
1825 set = gen_rtx_SET (VOIDmode,
1827 gen_rtx_LO_SUM (mode, temp, operand1));
1829 emit_insn (gen_rtx_SET (VOIDmode,
1831 gen_rtx_HIGH (mode, operand1)));
1837 else if (pa_tls_referenced_p (operand1))
1842 if (GET_CODE (tmp) == CONST && GET_CODE (XEXP (tmp, 0)) == PLUS)
1844 addend = XEXP (XEXP (tmp, 0), 1);
1845 tmp = XEXP (XEXP (tmp, 0), 0);
1848 gcc_assert (GET_CODE (tmp) == SYMBOL_REF);
1849 tmp = legitimize_tls_address (tmp);
1852 tmp = gen_rtx_PLUS (mode, tmp, addend);
1853 tmp = force_operand (tmp, operands[0]);
1857 else if (GET_CODE (operand1) != CONST_INT
1858 || !cint_ok_for_move (INTVAL (operand1)))
1862 HOST_WIDE_INT value = 0;
1863 HOST_WIDE_INT insv = 0;
1866 if (GET_CODE (operand1) == CONST_INT)
1867 value = INTVAL (operand1);
1870 && GET_CODE (operand1) == CONST_INT
1871 && HOST_BITS_PER_WIDE_INT > 32
1872 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
1876 /* Extract the low order 32 bits of the value and sign extend.
1877 If the new value is the same as the original value, we can
1878 can use the original value as-is. If the new value is
1879 different, we use it and insert the most-significant 32-bits
1880 of the original value into the final result. */
1881 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
1882 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
1885 #if HOST_BITS_PER_WIDE_INT > 32
1886 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
1890 operand1 = GEN_INT (nval);
1894 if (reload_in_progress || reload_completed)
1895 temp = scratch_reg ? scratch_reg : operand0;
1897 temp = gen_reg_rtx (mode);
1899 /* We don't directly split DImode constants on 32-bit targets
1900 because PLUS uses an 11-bit immediate and the insn sequence
1901 generated is not as efficient as the one using HIGH/LO_SUM. */
1902 if (GET_CODE (operand1) == CONST_INT
1903 && GET_MODE_BITSIZE (mode) <= BITS_PER_WORD
1904 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1907 /* Directly break constant into high and low parts. This
1908 provides better optimization opportunities because various
1909 passes recognize constants split with PLUS but not LO_SUM.
1910 We use a 14-bit signed low part except when the addition
1911 of 0x4000 to the high part might change the sign of the
1913 HOST_WIDE_INT low = value & 0x3fff;
1914 HOST_WIDE_INT high = value & ~ 0x3fff;
1918 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
1926 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
1927 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
1931 emit_insn (gen_rtx_SET (VOIDmode, temp,
1932 gen_rtx_HIGH (mode, operand1)));
1933 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
1936 insn = emit_move_insn (operands[0], operands[1]);
1938 /* Now insert the most significant 32 bits of the value
1939 into the register. When we don't have a second register
1940 available, it could take up to nine instructions to load
1941 a 64-bit integer constant. Prior to reload, we force
1942 constants that would take more than three instructions
1943 to load to the constant pool. During and after reload,
1944 we have to handle all possible values. */
1947 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
1948 register and the value to be inserted is outside the
1949 range that can be loaded with three depdi instructions. */
1950 if (temp != operand0 && (insv >= 16384 || insv < -16384))
1952 operand1 = GEN_INT (insv);
1954 emit_insn (gen_rtx_SET (VOIDmode, temp,
1955 gen_rtx_HIGH (mode, operand1)));
1956 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
1957 emit_insn (gen_insv (operand0, GEN_INT (32),
1962 int len = 5, pos = 27;
1964 /* Insert the bits using the depdi instruction. */
1967 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
1968 HOST_WIDE_INT sign = v5 < 0;
1970 /* Left extend the insertion. */
1971 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
1972 while (pos > 0 && (insv & 1) == sign)
1974 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
1979 emit_insn (gen_insv (operand0, GEN_INT (len),
1980 GEN_INT (pos), GEN_INT (v5)));
1982 len = pos > 0 && pos < 5 ? pos : 5;
1988 set_unique_reg_note (insn, REG_EQUAL, op1);
1993 /* Now have insn-emit do whatever it normally does. */
1997 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
1998 it will need a link/runtime reloc). */
2001 reloc_needed (tree exp)
2005 switch (TREE_CODE (exp))
2012 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2013 reloc |= reloc_needed (TREE_OPERAND (exp, 1));
2018 case NON_LVALUE_EXPR:
2019 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2025 unsigned HOST_WIDE_INT ix;
2027 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), ix, value)
2029 reloc |= reloc_needed (value);
2042 /* Does operand (which is a symbolic_operand) live in text space?
2043 If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info,
2047 read_only_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
2049 if (GET_CODE (operand) == CONST)
2050 operand = XEXP (XEXP (operand, 0), 0);
2053 if (GET_CODE (operand) == SYMBOL_REF)
2054 return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
2058 if (GET_CODE (operand) == SYMBOL_REF)
2059 return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
2065 /* Return the best assembler insn template
2066 for moving operands[1] into operands[0] as a fullword. */
2068 singlemove_string (rtx *operands)
2070 HOST_WIDE_INT intval;
2072 if (GET_CODE (operands[0]) == MEM)
2073 return "stw %r1,%0";
2074 if (GET_CODE (operands[1]) == MEM)
2076 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2081 gcc_assert (GET_MODE (operands[1]) == SFmode);
2083 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2085 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2086 REAL_VALUE_TO_TARGET_SINGLE (d, i);
2088 operands[1] = GEN_INT (i);
2089 /* Fall through to CONST_INT case. */
2091 if (GET_CODE (operands[1]) == CONST_INT)
2093 intval = INTVAL (operands[1]);
2095 if (VAL_14_BITS_P (intval))
2097 else if ((intval & 0x7ff) == 0)
2098 return "ldil L'%1,%0";
2099 else if (zdepi_cint_p (intval))
2100 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2102 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2104 return "copy %1,%0";
2108 /* Compute position (in OP[1]) and width (in OP[2])
2109 useful for copying IMM to a register using the zdepi
2110 instructions. Store the immediate value to insert in OP[0]. */
2112 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2116 /* Find the least significant set bit in IMM. */
2117 for (lsb = 0; lsb < 32; lsb++)
2124 /* Choose variants based on *sign* of the 5-bit field. */
2125 if ((imm & 0x10) == 0)
2126 len = (lsb <= 28) ? 4 : 32 - lsb;
2129 /* Find the width of the bitstring in IMM. */
2130 for (len = 5; len < 32; len++)
2132 if ((imm & (1 << len)) == 0)
2136 /* Sign extend IMM as a 5-bit value. */
2137 imm = (imm & 0xf) - 0x10;
2145 /* Compute position (in OP[1]) and width (in OP[2])
2146 useful for copying IMM to a register using the depdi,z
2147 instructions. Store the immediate value to insert in OP[0]. */
2149 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2151 HOST_WIDE_INT lsb, len;
2153 /* Find the least significant set bit in IMM. */
2154 for (lsb = 0; lsb < HOST_BITS_PER_WIDE_INT; lsb++)
2161 /* Choose variants based on *sign* of the 5-bit field. */
2162 if ((imm & 0x10) == 0)
2163 len = ((lsb <= HOST_BITS_PER_WIDE_INT - 4)
2164 ? 4 : HOST_BITS_PER_WIDE_INT - lsb);
2167 /* Find the width of the bitstring in IMM. */
2168 for (len = 5; len < HOST_BITS_PER_WIDE_INT; len++)
2170 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2174 /* Sign extend IMM as a 5-bit value. */
2175 imm = (imm & 0xf) - 0x10;
2183 /* Output assembler code to perform a doubleword move insn
2184 with operands OPERANDS. */
2187 output_move_double (rtx *operands)
2189 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2191 rtx addreg0 = 0, addreg1 = 0;
2193 /* First classify both operands. */
2195 if (REG_P (operands[0]))
2197 else if (offsettable_memref_p (operands[0]))
2199 else if (GET_CODE (operands[0]) == MEM)
2204 if (REG_P (operands[1]))
2206 else if (CONSTANT_P (operands[1]))
2208 else if (offsettable_memref_p (operands[1]))
2210 else if (GET_CODE (operands[1]) == MEM)
2215 /* Check for the cases that the operand constraints are not
2216 supposed to allow to happen. */
2217 gcc_assert (optype0 == REGOP || optype1 == REGOP);
2219 /* Handle copies between general and floating registers. */
2221 if (optype0 == REGOP && optype1 == REGOP
2222 && FP_REG_P (operands[0]) ^ FP_REG_P (operands[1]))
2224 if (FP_REG_P (operands[0]))
2226 output_asm_insn ("{stws|stw} %1,-16(%%sp)", operands);
2227 output_asm_insn ("{stws|stw} %R1,-12(%%sp)", operands);
2228 return "{fldds|fldd} -16(%%sp),%0";
2232 output_asm_insn ("{fstds|fstd} %1,-16(%%sp)", operands);
2233 output_asm_insn ("{ldws|ldw} -16(%%sp),%0", operands);
2234 return "{ldws|ldw} -12(%%sp),%R0";
2238 /* Handle auto decrementing and incrementing loads and stores
2239 specifically, since the structure of the function doesn't work
2240 for them without major modification. Do it better when we learn
2241 this port about the general inc/dec addressing of PA.
2242 (This was written by tege. Chide him if it doesn't work.) */
2244 if (optype0 == MEMOP)
2246 /* We have to output the address syntax ourselves, since print_operand
2247 doesn't deal with the addresses we want to use. Fix this later. */
2249 rtx addr = XEXP (operands[0], 0);
2250 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2252 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2254 operands[0] = XEXP (addr, 0);
2255 gcc_assert (GET_CODE (operands[1]) == REG
2256 && GET_CODE (operands[0]) == REG);
2258 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2260 /* No overlap between high target register and address
2261 register. (We do this in a non-obvious way to
2262 save a register file writeback) */
2263 if (GET_CODE (addr) == POST_INC)
2264 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2265 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2267 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2269 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2271 operands[0] = XEXP (addr, 0);
2272 gcc_assert (GET_CODE (operands[1]) == REG
2273 && GET_CODE (operands[0]) == REG);
2275 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2276 /* No overlap between high target register and address
2277 register. (We do this in a non-obvious way to save a
2278 register file writeback) */
2279 if (GET_CODE (addr) == PRE_INC)
2280 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2281 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2284 if (optype1 == MEMOP)
2286 /* We have to output the address syntax ourselves, since print_operand
2287 doesn't deal with the addresses we want to use. Fix this later. */
2289 rtx addr = XEXP (operands[1], 0);
2290 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2292 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2294 operands[1] = XEXP (addr, 0);
2295 gcc_assert (GET_CODE (operands[0]) == REG
2296 && GET_CODE (operands[1]) == REG);
2298 if (!reg_overlap_mentioned_p (high_reg, addr))
2300 /* No overlap between high target register and address
2301 register. (We do this in a non-obvious way to
2302 save a register file writeback) */
2303 if (GET_CODE (addr) == POST_INC)
2304 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2305 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2309 /* This is an undefined situation. We should load into the
2310 address register *and* update that register. Probably
2311 we don't need to handle this at all. */
2312 if (GET_CODE (addr) == POST_INC)
2313 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2314 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2317 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2319 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2321 operands[1] = XEXP (addr, 0);
2322 gcc_assert (GET_CODE (operands[0]) == REG
2323 && GET_CODE (operands[1]) == REG);
2325 if (!reg_overlap_mentioned_p (high_reg, addr))
2327 /* No overlap between high target register and address
2328 register. (We do this in a non-obvious way to
2329 save a register file writeback) */
2330 if (GET_CODE (addr) == PRE_INC)
2331 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2332 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2336 /* This is an undefined situation. We should load into the
2337 address register *and* update that register. Probably
2338 we don't need to handle this at all. */
2339 if (GET_CODE (addr) == PRE_INC)
2340 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2341 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2344 else if (GET_CODE (addr) == PLUS
2345 && GET_CODE (XEXP (addr, 0)) == MULT)
2348 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2350 if (!reg_overlap_mentioned_p (high_reg, addr))
2352 xoperands[0] = high_reg;
2353 xoperands[1] = XEXP (addr, 1);
2354 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2355 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2356 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2358 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2362 xoperands[0] = high_reg;
2363 xoperands[1] = XEXP (addr, 1);
2364 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2365 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2366 output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2368 return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2373 /* If an operand is an unoffsettable memory ref, find a register
2374 we can increment temporarily to make it refer to the second word. */
2376 if (optype0 == MEMOP)
2377 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2379 if (optype1 == MEMOP)
2380 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2382 /* Ok, we can do one word at a time.
2383 Normally we do the low-numbered word first.
2385 In either case, set up in LATEHALF the operands to use
2386 for the high-numbered word and in some cases alter the
2387 operands in OPERANDS to be suitable for the low-numbered word. */
2389 if (optype0 == REGOP)
2390 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2391 else if (optype0 == OFFSOP)
2392 latehalf[0] = adjust_address (operands[0], SImode, 4);
2394 latehalf[0] = operands[0];
2396 if (optype1 == REGOP)
2397 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2398 else if (optype1 == OFFSOP)
2399 latehalf[1] = adjust_address (operands[1], SImode, 4);
2400 else if (optype1 == CNSTOP)
2401 split_double (operands[1], &operands[1], &latehalf[1]);
2403 latehalf[1] = operands[1];
2405 /* If the first move would clobber the source of the second one,
2406 do them in the other order.
2408 This can happen in two cases:
2410 mem -> register where the first half of the destination register
2411 is the same register used in the memory's address. Reload
2412 can create such insns.
2414 mem in this case will be either register indirect or register
2415 indirect plus a valid offset.
2417 register -> register move where REGNO(dst) == REGNO(src + 1)
2418 someone (Tim/Tege?) claimed this can happen for parameter loads.
2420 Handle mem -> register case first. */
2421 if (optype0 == REGOP
2422 && (optype1 == MEMOP || optype1 == OFFSOP)
2423 && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2426 /* Do the late half first. */
2428 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2429 output_asm_insn (singlemove_string (latehalf), latehalf);
2433 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2434 return singlemove_string (operands);
2437 /* Now handle register -> register case. */
2438 if (optype0 == REGOP && optype1 == REGOP
2439 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2441 output_asm_insn (singlemove_string (latehalf), latehalf);
2442 return singlemove_string (operands);
2445 /* Normal case: do the two words, low-numbered first. */
2447 output_asm_insn (singlemove_string (operands), operands);
2449 /* Make any unoffsettable addresses point at high-numbered word. */
2451 output_asm_insn ("ldo 4(%0),%0", &addreg0);
2453 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2456 output_asm_insn (singlemove_string (latehalf), latehalf);
2458 /* Undo the adds we just did. */
2460 output_asm_insn ("ldo -4(%0),%0", &addreg0);
2462 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2468 output_fp_move_double (rtx *operands)
2470 if (FP_REG_P (operands[0]))
2472 if (FP_REG_P (operands[1])
2473 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2474 output_asm_insn ("fcpy,dbl %f1,%0", operands);
2476 output_asm_insn ("fldd%F1 %1,%0", operands);
2478 else if (FP_REG_P (operands[1]))
2480 output_asm_insn ("fstd%F0 %1,%0", operands);
2486 gcc_assert (operands[1] == CONST0_RTX (GET_MODE (operands[0])));
2488 /* This is a pain. You have to be prepared to deal with an
2489 arbitrary address here including pre/post increment/decrement.
2491 so avoid this in the MD. */
2492 gcc_assert (GET_CODE (operands[0]) == REG);
2494 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2495 xoperands[0] = operands[0];
2496 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2501 /* Return a REG that occurs in ADDR with coefficient 1.
2502 ADDR can be effectively incremented by incrementing REG. */
2505 find_addr_reg (rtx addr)
2507 while (GET_CODE (addr) == PLUS)
2509 if (GET_CODE (XEXP (addr, 0)) == REG)
2510 addr = XEXP (addr, 0);
2511 else if (GET_CODE (XEXP (addr, 1)) == REG)
2512 addr = XEXP (addr, 1);
2513 else if (CONSTANT_P (XEXP (addr, 0)))
2514 addr = XEXP (addr, 1);
2515 else if (CONSTANT_P (XEXP (addr, 1)))
2516 addr = XEXP (addr, 0);
2520 gcc_assert (GET_CODE (addr) == REG);
2524 /* Emit code to perform a block move.
2526 OPERANDS[0] is the destination pointer as a REG, clobbered.
2527 OPERANDS[1] is the source pointer as a REG, clobbered.
2528 OPERANDS[2] is a register for temporary storage.
2529 OPERANDS[3] is a register for temporary storage.
2530 OPERANDS[4] is the size as a CONST_INT
2531 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2532 OPERANDS[6] is another temporary register. */
2535 output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2537 int align = INTVAL (operands[5]);
2538 unsigned long n_bytes = INTVAL (operands[4]);
2540 /* We can't move more than a word at a time because the PA
2541 has no longer integer move insns. (Could use fp mem ops?) */
2542 if (align > (TARGET_64BIT ? 8 : 4))
2543 align = (TARGET_64BIT ? 8 : 4);
2545 /* Note that we know each loop below will execute at least twice
2546 (else we would have open-coded the copy). */
2550 /* Pre-adjust the loop counter. */
2551 operands[4] = GEN_INT (n_bytes - 16);
2552 output_asm_insn ("ldi %4,%2", operands);
2555 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2556 output_asm_insn ("ldd,ma 8(%1),%6", operands);
2557 output_asm_insn ("std,ma %3,8(%0)", operands);
2558 output_asm_insn ("addib,>= -16,%2,.-12", operands);
2559 output_asm_insn ("std,ma %6,8(%0)", operands);
2561 /* Handle the residual. There could be up to 7 bytes of
2562 residual to copy! */
2563 if (n_bytes % 16 != 0)
2565 operands[4] = GEN_INT (n_bytes % 8);
2566 if (n_bytes % 16 >= 8)
2567 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2568 if (n_bytes % 8 != 0)
2569 output_asm_insn ("ldd 0(%1),%6", operands);
2570 if (n_bytes % 16 >= 8)
2571 output_asm_insn ("std,ma %3,8(%0)", operands);
2572 if (n_bytes % 8 != 0)
2573 output_asm_insn ("stdby,e %6,%4(%0)", operands);
2578 /* Pre-adjust the loop counter. */
2579 operands[4] = GEN_INT (n_bytes - 8);
2580 output_asm_insn ("ldi %4,%2", operands);
2583 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2584 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2585 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2586 output_asm_insn ("addib,>= -8,%2,.-12", operands);
2587 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2589 /* Handle the residual. There could be up to 7 bytes of
2590 residual to copy! */
2591 if (n_bytes % 8 != 0)
2593 operands[4] = GEN_INT (n_bytes % 4);
2594 if (n_bytes % 8 >= 4)
2595 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2596 if (n_bytes % 4 != 0)
2597 output_asm_insn ("ldw 0(%1),%6", operands);
2598 if (n_bytes % 8 >= 4)
2599 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2600 if (n_bytes % 4 != 0)
2601 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2606 /* Pre-adjust the loop counter. */
2607 operands[4] = GEN_INT (n_bytes - 4);
2608 output_asm_insn ("ldi %4,%2", operands);
2611 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2612 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2613 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2614 output_asm_insn ("addib,>= -4,%2,.-12", operands);
2615 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2617 /* Handle the residual. */
2618 if (n_bytes % 4 != 0)
2620 if (n_bytes % 4 >= 2)
2621 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2622 if (n_bytes % 2 != 0)
2623 output_asm_insn ("ldb 0(%1),%6", operands);
2624 if (n_bytes % 4 >= 2)
2625 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2626 if (n_bytes % 2 != 0)
2627 output_asm_insn ("stb %6,0(%0)", operands);
2632 /* Pre-adjust the loop counter. */
2633 operands[4] = GEN_INT (n_bytes - 2);
2634 output_asm_insn ("ldi %4,%2", operands);
2637 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2638 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2639 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2640 output_asm_insn ("addib,>= -2,%2,.-12", operands);
2641 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2643 /* Handle the residual. */
2644 if (n_bytes % 2 != 0)
2646 output_asm_insn ("ldb 0(%1),%3", operands);
2647 output_asm_insn ("stb %3,0(%0)", operands);
2656 /* Count the number of insns necessary to handle this block move.
2658 Basic structure is the same as emit_block_move, except that we
2659 count insns rather than emit them. */
2662 compute_movmem_length (rtx insn)
2664 rtx pat = PATTERN (insn);
2665 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2666 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2667 unsigned int n_insns = 0;
2669 /* We can't move more than four bytes at a time because the PA
2670 has no longer integer move insns. (Could use fp mem ops?) */
2671 if (align > (TARGET_64BIT ? 8 : 4))
2672 align = (TARGET_64BIT ? 8 : 4);
2674 /* The basic copying loop. */
2678 if (n_bytes % (2 * align) != 0)
2680 if ((n_bytes % (2 * align)) >= align)
2683 if ((n_bytes % align) != 0)
2687 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2691 /* Emit code to perform a block clear.
2693 OPERANDS[0] is the destination pointer as a REG, clobbered.
2694 OPERANDS[1] is a register for temporary storage.
2695 OPERANDS[2] is the size as a CONST_INT
2696 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
2699 output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2701 int align = INTVAL (operands[3]);
2702 unsigned long n_bytes = INTVAL (operands[2]);
2704 /* We can't clear more than a word at a time because the PA
2705 has no longer integer move insns. */
2706 if (align > (TARGET_64BIT ? 8 : 4))
2707 align = (TARGET_64BIT ? 8 : 4);
2709 /* Note that we know each loop below will execute at least twice
2710 (else we would have open-coded the copy). */
2714 /* Pre-adjust the loop counter. */
2715 operands[2] = GEN_INT (n_bytes - 16);
2716 output_asm_insn ("ldi %2,%1", operands);
2719 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2720 output_asm_insn ("addib,>= -16,%1,.-4", operands);
2721 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2723 /* Handle the residual. There could be up to 7 bytes of
2724 residual to copy! */
2725 if (n_bytes % 16 != 0)
2727 operands[2] = GEN_INT (n_bytes % 8);
2728 if (n_bytes % 16 >= 8)
2729 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2730 if (n_bytes % 8 != 0)
2731 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
2736 /* Pre-adjust the loop counter. */
2737 operands[2] = GEN_INT (n_bytes - 8);
2738 output_asm_insn ("ldi %2,%1", operands);
2741 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2742 output_asm_insn ("addib,>= -8,%1,.-4", operands);
2743 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2745 /* Handle the residual. There could be up to 7 bytes of
2746 residual to copy! */
2747 if (n_bytes % 8 != 0)
2749 operands[2] = GEN_INT (n_bytes % 4);
2750 if (n_bytes % 8 >= 4)
2751 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2752 if (n_bytes % 4 != 0)
2753 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
2758 /* Pre-adjust the loop counter. */
2759 operands[2] = GEN_INT (n_bytes - 4);
2760 output_asm_insn ("ldi %2,%1", operands);
2763 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2764 output_asm_insn ("addib,>= -4,%1,.-4", operands);
2765 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2767 /* Handle the residual. */
2768 if (n_bytes % 4 != 0)
2770 if (n_bytes % 4 >= 2)
2771 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2772 if (n_bytes % 2 != 0)
2773 output_asm_insn ("stb %%r0,0(%0)", operands);
2778 /* Pre-adjust the loop counter. */
2779 operands[2] = GEN_INT (n_bytes - 2);
2780 output_asm_insn ("ldi %2,%1", operands);
2783 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2784 output_asm_insn ("addib,>= -2,%1,.-4", operands);
2785 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2787 /* Handle the residual. */
2788 if (n_bytes % 2 != 0)
2789 output_asm_insn ("stb %%r0,0(%0)", operands);
2798 /* Count the number of insns necessary to handle this block move.
2800 Basic structure is the same as emit_block_move, except that we
2801 count insns rather than emit them. */
2804 compute_clrmem_length (rtx insn)
2806 rtx pat = PATTERN (insn);
2807 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
2808 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
2809 unsigned int n_insns = 0;
2811 /* We can't clear more than a word at a time because the PA
2812 has no longer integer move insns. */
2813 if (align > (TARGET_64BIT ? 8 : 4))
2814 align = (TARGET_64BIT ? 8 : 4);
2816 /* The basic loop. */
2820 if (n_bytes % (2 * align) != 0)
2822 if ((n_bytes % (2 * align)) >= align)
2825 if ((n_bytes % align) != 0)
2829 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2835 output_and (rtx *operands)
2837 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
2839 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2840 int ls0, ls1, ms0, p, len;
2842 for (ls0 = 0; ls0 < 32; ls0++)
2843 if ((mask & (1 << ls0)) == 0)
2846 for (ls1 = ls0; ls1 < 32; ls1++)
2847 if ((mask & (1 << ls1)) != 0)
2850 for (ms0 = ls1; ms0 < 32; ms0++)
2851 if ((mask & (1 << ms0)) == 0)
2854 gcc_assert (ms0 == 32);
2862 operands[2] = GEN_INT (len);
2863 return "{extru|extrw,u} %1,31,%2,%0";
2867 /* We could use this `depi' for the case above as well, but `depi'
2868 requires one more register file access than an `extru'. */
2873 operands[2] = GEN_INT (p);
2874 operands[3] = GEN_INT (len);
2875 return "{depi|depwi} 0,%2,%3,%0";
2879 return "and %1,%2,%0";
2882 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
2883 storing the result in operands[0]. */
2885 output_64bit_and (rtx *operands)
2887 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
2889 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2890 int ls0, ls1, ms0, p, len;
2892 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
2893 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
2896 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
2897 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
2900 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
2901 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
2904 gcc_assert (ms0 == HOST_BITS_PER_WIDE_INT);
2906 if (ls1 == HOST_BITS_PER_WIDE_INT)
2912 operands[2] = GEN_INT (len);
2913 return "extrd,u %1,63,%2,%0";
2917 /* We could use this `depi' for the case above as well, but `depi'
2918 requires one more register file access than an `extru'. */
2923 operands[2] = GEN_INT (p);
2924 operands[3] = GEN_INT (len);
2925 return "depdi 0,%2,%3,%0";
2929 return "and %1,%2,%0";
2933 output_ior (rtx *operands)
2935 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2936 int bs0, bs1, p, len;
2938 if (INTVAL (operands[2]) == 0)
2939 return "copy %1,%0";
2941 for (bs0 = 0; bs0 < 32; bs0++)
2942 if ((mask & (1 << bs0)) != 0)
2945 for (bs1 = bs0; bs1 < 32; bs1++)
2946 if ((mask & (1 << bs1)) == 0)
2949 gcc_assert (bs1 == 32 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
2954 operands[2] = GEN_INT (p);
2955 operands[3] = GEN_INT (len);
2956 return "{depi|depwi} -1,%2,%3,%0";
2959 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
2960 storing the result in operands[0]. */
2962 output_64bit_ior (rtx *operands)
2964 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2965 int bs0, bs1, p, len;
2967 if (INTVAL (operands[2]) == 0)
2968 return "copy %1,%0";
2970 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
2971 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
2974 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
2975 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
2978 gcc_assert (bs1 == HOST_BITS_PER_WIDE_INT
2979 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
2984 operands[2] = GEN_INT (p);
2985 operands[3] = GEN_INT (len);
2986 return "depdi -1,%2,%3,%0";
2989 /* Target hook for assembling integer objects. This code handles
2990 aligned SI and DI integers specially since function references
2991 must be preceded by P%. */
2994 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
2996 if (size == UNITS_PER_WORD
2998 && function_label_operand (x, VOIDmode))
3000 fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
3001 output_addr_const (asm_out_file, x);
3002 fputc ('\n', asm_out_file);
3005 return default_assemble_integer (x, size, aligned_p);
3008 /* Output an ascii string. */
3010 output_ascii (FILE *file, const char *p, int size)
3014 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
3016 /* The HP assembler can only take strings of 256 characters at one
3017 time. This is a limitation on input line length, *not* the
3018 length of the string. Sigh. Even worse, it seems that the
3019 restriction is in number of input characters (see \xnn &
3020 \whatever). So we have to do this very carefully. */
3022 fputs ("\t.STRING \"", file);
3025 for (i = 0; i < size; i += 4)
3029 for (io = 0, co = 0; io < MIN (4, size - i); io++)
3031 register unsigned int c = (unsigned char) p[i + io];
3033 if (c == '\"' || c == '\\')
3034 partial_output[co++] = '\\';
3035 if (c >= ' ' && c < 0177)
3036 partial_output[co++] = c;
3040 partial_output[co++] = '\\';
3041 partial_output[co++] = 'x';
3042 hexd = c / 16 - 0 + '0';
3044 hexd -= '9' - 'a' + 1;
3045 partial_output[co++] = hexd;
3046 hexd = c % 16 - 0 + '0';
3048 hexd -= '9' - 'a' + 1;
3049 partial_output[co++] = hexd;
3052 if (chars_output + co > 243)
3054 fputs ("\"\n\t.STRING \"", file);
3057 fwrite (partial_output, 1, (size_t) co, file);
3061 fputs ("\"\n", file);
3064 /* Try to rewrite floating point comparisons & branches to avoid
3065 useless add,tr insns.
3067 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3068 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3069 first attempt to remove useless add,tr insns. It is zero
3070 for the second pass as reorg sometimes leaves bogus REG_DEAD
3073 When CHECK_NOTES is zero we can only eliminate add,tr insns
3074 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3077 remove_useless_addtr_insns (int check_notes)
3080 static int pass = 0;
3082 /* This is fairly cheap, so always run it when optimizing. */
3086 int fbranch_count = 0;
3088 /* Walk all the insns in this function looking for fcmp & fbranch
3089 instructions. Keep track of how many of each we find. */
3090 for (insn = get_insns (); insn; insn = next_insn (insn))
3094 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3095 if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3098 tmp = PATTERN (insn);
3100 /* It must be a set. */
3101 if (GET_CODE (tmp) != SET)
3104 /* If the destination is CCFP, then we've found an fcmp insn. */
3105 tmp = SET_DEST (tmp);
3106 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3112 tmp = PATTERN (insn);
3113 /* If this is an fbranch instruction, bump the fbranch counter. */
3114 if (GET_CODE (tmp) == SET
3115 && SET_DEST (tmp) == pc_rtx
3116 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3117 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3118 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3119 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3127 /* Find all floating point compare + branch insns. If possible,
3128 reverse the comparison & the branch to avoid add,tr insns. */
3129 for (insn = get_insns (); insn; insn = next_insn (insn))
3133 /* Ignore anything that isn't an INSN. */
3134 if (GET_CODE (insn) != INSN)
3137 tmp = PATTERN (insn);
3139 /* It must be a set. */
3140 if (GET_CODE (tmp) != SET)
3143 /* The destination must be CCFP, which is register zero. */
3144 tmp = SET_DEST (tmp);
3145 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3148 /* INSN should be a set of CCFP.
3150 See if the result of this insn is used in a reversed FP
3151 conditional branch. If so, reverse our condition and
3152 the branch. Doing so avoids useless add,tr insns. */
3153 next = next_insn (insn);
3156 /* Jumps, calls and labels stop our search. */
3157 if (GET_CODE (next) == JUMP_INSN
3158 || GET_CODE (next) == CALL_INSN
3159 || GET_CODE (next) == CODE_LABEL)
3162 /* As does another fcmp insn. */
3163 if (GET_CODE (next) == INSN
3164 && GET_CODE (PATTERN (next)) == SET
3165 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3166 && REGNO (SET_DEST (PATTERN (next))) == 0)
3169 next = next_insn (next);
3172 /* Is NEXT_INSN a branch? */
3174 && GET_CODE (next) == JUMP_INSN)
3176 rtx pattern = PATTERN (next);
3178 /* If it a reversed fp conditional branch (e.g. uses add,tr)
3179 and CCFP dies, then reverse our conditional and the branch
3180 to avoid the add,tr. */
3181 if (GET_CODE (pattern) == SET
3182 && SET_DEST (pattern) == pc_rtx
3183 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3184 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3185 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3186 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3187 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3188 && (fcmp_count == fbranch_count
3190 && find_regno_note (next, REG_DEAD, 0))))
3192 /* Reverse the branch. */
3193 tmp = XEXP (SET_SRC (pattern), 1);
3194 XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3195 XEXP (SET_SRC (pattern), 2) = tmp;
3196 INSN_CODE (next) = -1;
3198 /* Reverse our condition. */
3199 tmp = PATTERN (insn);
3200 PUT_CODE (XEXP (tmp, 1),
3201 (reverse_condition_maybe_unordered
3202 (GET_CODE (XEXP (tmp, 1)))));
3212 /* You may have trouble believing this, but this is the 32 bit HP-PA
3217 Variable arguments (optional; any number may be allocated)
3219 SP-(4*(N+9)) arg word N
3224 Fixed arguments (must be allocated; may remain unused)
3233 SP-32 External Data Pointer (DP)
3235 SP-24 External/stub RP (RP')
3239 SP-8 Calling Stub RP (RP'')
3244 SP-0 Stack Pointer (points to next available address)
3248 /* This function saves registers as follows. Registers marked with ' are
3249 this function's registers (as opposed to the previous function's).
3250 If a frame_pointer isn't needed, r4 is saved as a general register;
3251 the space for the frame pointer is still allocated, though, to keep
3257 SP (FP') Previous FP
3258 SP + 4 Alignment filler (sigh)
3259 SP + 8 Space for locals reserved here.
3263 SP + n All call saved register used.
3267 SP + o All call saved fp registers used.
3271 SP + p (SP') points to next available address.
3275 /* Global variables set by output_function_prologue(). */
3276 /* Size of frame. Need to know this to emit return insns from
3278 static HOST_WIDE_INT actual_fsize, local_fsize;
3279 static int save_fregs;
3281 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3282 Handle case where DISP > 8k by using the add_high_const patterns.
3284 Note in DISP > 8k case, we will leave the high part of the address
3285 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3288 store_reg (int reg, HOST_WIDE_INT disp, int base)
3290 rtx insn, dest, src, basereg;
3292 src = gen_rtx_REG (word_mode, reg);
3293 basereg = gen_rtx_REG (Pmode, base);
3294 if (VAL_14_BITS_P (disp))
3296 dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3297 insn = emit_move_insn (dest, src);
3299 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3301 rtx delta = GEN_INT (disp);
3302 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3304 emit_move_insn (tmpreg, delta);
3305 insn = emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3309 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3310 gen_rtx_SET (VOIDmode, tmpreg,
3311 gen_rtx_PLUS (Pmode, basereg, delta)),
3313 RTX_FRAME_RELATED_P (insn) = 1;
3315 dest = gen_rtx_MEM (word_mode, tmpreg);
3316 insn = emit_move_insn (dest, src);
3320 rtx delta = GEN_INT (disp);
3321 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3322 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3324 emit_move_insn (tmpreg, high);
3325 dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3326 insn = emit_move_insn (dest, src);
3330 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3331 gen_rtx_SET (VOIDmode,
3332 gen_rtx_MEM (word_mode,
3333 gen_rtx_PLUS (word_mode, basereg,
3341 RTX_FRAME_RELATED_P (insn) = 1;
3344 /* Emit RTL to store REG at the memory location specified by BASE and then
3345 add MOD to BASE. MOD must be <= 8k. */
3348 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3350 rtx insn, basereg, srcreg, delta;
3352 gcc_assert (VAL_14_BITS_P (mod));
3354 basereg = gen_rtx_REG (Pmode, base);
3355 srcreg = gen_rtx_REG (word_mode, reg);
3356 delta = GEN_INT (mod);
3358 insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3361 RTX_FRAME_RELATED_P (insn) = 1;
3363 /* RTX_FRAME_RELATED_P must be set on each frame related set
3364 in a parallel with more than one element. */
3365 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3366 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3370 /* Emit RTL to set REG to the value specified by BASE+DISP. Handle case
3371 where DISP > 8k by using the add_high_const patterns. NOTE indicates
3372 whether to add a frame note or not.
3374 In the DISP > 8k case, we leave the high part of the address in %r1.
3375 There is code in expand_hppa_{prologue,epilogue} that knows about this. */
3378 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3382 if (VAL_14_BITS_P (disp))
3384 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3385 plus_constant (gen_rtx_REG (Pmode, base), disp));
3387 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))