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, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-attr.h"
40 #include "integrate.h"
42 #include "diagnostic-core.h"
48 #include "common/common-target.h"
49 #include "target-def.h"
50 #include "langhooks.h"
54 /* Return nonzero if there is a bypass for the output of
55 OUT_INSN and the fp store IN_INSN. */
57 pa_fpstore_bypass_p (rtx out_insn, rtx in_insn)
59 enum machine_mode store_mode;
60 enum machine_mode other_mode;
63 if (recog_memoized (in_insn) < 0
64 || (get_attr_type (in_insn) != TYPE_FPSTORE
65 && get_attr_type (in_insn) != TYPE_FPSTORE_LOAD)
66 || recog_memoized (out_insn) < 0)
69 store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
71 set = single_set (out_insn);
75 other_mode = GET_MODE (SET_SRC (set));
77 return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
81 #ifndef DO_FRAME_NOTES
82 #ifdef INCOMING_RETURN_ADDR_RTX
83 #define DO_FRAME_NOTES 1
85 #define DO_FRAME_NOTES 0
89 static void pa_option_override (void);
90 static void copy_reg_pointer (rtx, rtx);
91 static void fix_range (const char *);
92 static int hppa_register_move_cost (enum machine_mode mode, reg_class_t,
94 static int hppa_address_cost (rtx, bool);
95 static bool hppa_rtx_costs (rtx, int, int, int, int *, bool);
96 static inline rtx force_mode (enum machine_mode, rtx);
97 static void pa_reorg (void);
98 static void pa_combine_instructions (void);
99 static int pa_can_combine_p (rtx, rtx, rtx, int, rtx, rtx, rtx);
100 static bool forward_branch_p (rtx);
101 static void compute_zdepwi_operands (unsigned HOST_WIDE_INT, unsigned *);
102 static void compute_zdepdi_operands (unsigned HOST_WIDE_INT, unsigned *);
103 static int compute_movmem_length (rtx);
104 static int compute_clrmem_length (rtx);
105 static bool pa_assemble_integer (rtx, unsigned int, int);
106 static void remove_useless_addtr_insns (int);
107 static void store_reg (int, HOST_WIDE_INT, int);
108 static void store_reg_modify (int, int, HOST_WIDE_INT);
109 static void load_reg (int, HOST_WIDE_INT, int);
110 static void set_reg_plus_d (int, int, HOST_WIDE_INT, int);
111 static rtx pa_function_value (const_tree, const_tree, bool);
112 static rtx pa_libcall_value (enum machine_mode, const_rtx);
113 static bool pa_function_value_regno_p (const unsigned int);
114 static void pa_output_function_prologue (FILE *, HOST_WIDE_INT);
115 static void update_total_code_bytes (unsigned int);
116 static void pa_output_function_epilogue (FILE *, HOST_WIDE_INT);
117 static int pa_adjust_cost (rtx, rtx, rtx, int);
118 static int pa_adjust_priority (rtx, int);
119 static int pa_issue_rate (void);
120 static void pa_som_asm_init_sections (void) ATTRIBUTE_UNUSED;
121 static section *pa_som_tm_clone_table_section (void) ATTRIBUTE_UNUSED;
122 static section *pa_select_section (tree, int, unsigned HOST_WIDE_INT)
124 static void pa_encode_section_info (tree, rtx, int);
125 static const char *pa_strip_name_encoding (const char *);
126 static bool pa_function_ok_for_sibcall (tree, tree);
127 static void pa_globalize_label (FILE *, const char *)
129 static void pa_asm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
130 HOST_WIDE_INT, tree);
131 #if !defined(USE_COLLECT2)
132 static void pa_asm_out_constructor (rtx, int);
133 static void pa_asm_out_destructor (rtx, int);
135 static void pa_init_builtins (void);
136 static rtx pa_expand_builtin (tree, rtx, rtx, enum machine_mode mode, int);
137 static rtx hppa_builtin_saveregs (void);
138 static void hppa_va_start (tree, rtx);
139 static tree hppa_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
140 static bool pa_scalar_mode_supported_p (enum machine_mode);
141 static bool pa_commutative_p (const_rtx x, int outer_code);
142 static void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
143 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
144 static rtx hppa_legitimize_address (rtx, rtx, enum machine_mode);
145 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
146 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
147 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
148 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
149 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
150 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
151 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
152 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
153 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
154 static void output_deferred_plabels (void);
155 static void output_deferred_profile_counters (void) ATTRIBUTE_UNUSED;
156 #ifdef ASM_OUTPUT_EXTERNAL_REAL
157 static void pa_hpux_file_end (void);
159 static void pa_init_libfuncs (void);
160 static rtx pa_struct_value_rtx (tree, int);
161 static bool pa_pass_by_reference (cumulative_args_t, enum machine_mode,
163 static int pa_arg_partial_bytes (cumulative_args_t, enum machine_mode,
165 static void pa_function_arg_advance (cumulative_args_t, enum machine_mode,
167 static rtx pa_function_arg (cumulative_args_t, enum machine_mode,
169 static unsigned int pa_function_arg_boundary (enum machine_mode, const_tree);
170 static struct machine_function * pa_init_machine_status (void);
171 static reg_class_t pa_secondary_reload (bool, rtx, reg_class_t,
173 secondary_reload_info *);
174 static void pa_extra_live_on_entry (bitmap);
175 static enum machine_mode pa_promote_function_mode (const_tree,
176 enum machine_mode, int *,
179 static void pa_asm_trampoline_template (FILE *);
180 static void pa_trampoline_init (rtx, tree, rtx);
181 static rtx pa_trampoline_adjust_address (rtx);
182 static rtx pa_delegitimize_address (rtx);
183 static bool pa_print_operand_punct_valid_p (unsigned char);
184 static rtx pa_internal_arg_pointer (void);
185 static bool pa_can_eliminate (const int, const int);
186 static void pa_conditional_register_usage (void);
187 static enum machine_mode pa_c_mode_for_suffix (char);
188 static section *pa_function_section (tree, enum node_frequency, bool, bool);
189 static bool pa_cannot_force_const_mem (enum machine_mode, rtx);
190 static bool pa_legitimate_constant_p (enum machine_mode, rtx);
191 static unsigned int pa_section_type_flags (tree, const char *, int);
193 /* The following extra sections are only used for SOM. */
194 static GTY(()) section *som_readonly_data_section;
195 static GTY(()) section *som_one_only_readonly_data_section;
196 static GTY(()) section *som_one_only_data_section;
197 static GTY(()) section *som_tm_clone_table_section;
199 /* Counts for the number of callee-saved general and floating point
200 registers which were saved by the current function's prologue. */
201 static int gr_saved, fr_saved;
203 /* Boolean indicating whether the return pointer was saved by the
204 current function's prologue. */
205 static bool rp_saved;
207 static rtx find_addr_reg (rtx);
209 /* Keep track of the number of bytes we have output in the CODE subspace
210 during this compilation so we'll know when to emit inline long-calls. */
211 unsigned long total_code_bytes;
213 /* The last address of the previous function plus the number of bytes in
214 associated thunks that have been output. This is used to determine if
215 a thunk can use an IA-relative branch to reach its target function. */
216 static unsigned int last_address;
218 /* Variables to handle plabels that we discover are necessary at assembly
219 output time. They are output after the current function. */
220 struct GTY(()) deferred_plabel
225 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
227 static size_t n_deferred_plabels = 0;
229 /* Initialize the GCC target structure. */
231 #undef TARGET_OPTION_OVERRIDE
232 #define TARGET_OPTION_OVERRIDE pa_option_override
234 #undef TARGET_ASM_ALIGNED_HI_OP
235 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
236 #undef TARGET_ASM_ALIGNED_SI_OP
237 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
238 #undef TARGET_ASM_ALIGNED_DI_OP
239 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
240 #undef TARGET_ASM_UNALIGNED_HI_OP
241 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
242 #undef TARGET_ASM_UNALIGNED_SI_OP
243 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
244 #undef TARGET_ASM_UNALIGNED_DI_OP
245 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
246 #undef TARGET_ASM_INTEGER
247 #define TARGET_ASM_INTEGER pa_assemble_integer
249 #undef TARGET_ASM_FUNCTION_PROLOGUE
250 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
251 #undef TARGET_ASM_FUNCTION_EPILOGUE
252 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
254 #undef TARGET_FUNCTION_VALUE
255 #define TARGET_FUNCTION_VALUE pa_function_value
256 #undef TARGET_LIBCALL_VALUE
257 #define TARGET_LIBCALL_VALUE pa_libcall_value
258 #undef TARGET_FUNCTION_VALUE_REGNO_P
259 #define TARGET_FUNCTION_VALUE_REGNO_P pa_function_value_regno_p
261 #undef TARGET_LEGITIMIZE_ADDRESS
262 #define TARGET_LEGITIMIZE_ADDRESS hppa_legitimize_address
264 #undef TARGET_SCHED_ADJUST_COST
265 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
266 #undef TARGET_SCHED_ADJUST_PRIORITY
267 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
268 #undef TARGET_SCHED_ISSUE_RATE
269 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
271 #undef TARGET_ENCODE_SECTION_INFO
272 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
273 #undef TARGET_STRIP_NAME_ENCODING
274 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
276 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
277 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
279 #undef TARGET_COMMUTATIVE_P
280 #define TARGET_COMMUTATIVE_P pa_commutative_p
282 #undef TARGET_ASM_OUTPUT_MI_THUNK
283 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
284 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
285 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
287 #undef TARGET_ASM_FILE_END
288 #ifdef ASM_OUTPUT_EXTERNAL_REAL
289 #define TARGET_ASM_FILE_END pa_hpux_file_end
291 #define TARGET_ASM_FILE_END output_deferred_plabels
294 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
295 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P pa_print_operand_punct_valid_p
297 #if !defined(USE_COLLECT2)
298 #undef TARGET_ASM_CONSTRUCTOR
299 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
300 #undef TARGET_ASM_DESTRUCTOR
301 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
304 #undef TARGET_INIT_BUILTINS
305 #define TARGET_INIT_BUILTINS pa_init_builtins
307 #undef TARGET_EXPAND_BUILTIN
308 #define TARGET_EXPAND_BUILTIN pa_expand_builtin
310 #undef TARGET_REGISTER_MOVE_COST
311 #define TARGET_REGISTER_MOVE_COST hppa_register_move_cost
312 #undef TARGET_RTX_COSTS
313 #define TARGET_RTX_COSTS hppa_rtx_costs
314 #undef TARGET_ADDRESS_COST
315 #define TARGET_ADDRESS_COST hppa_address_cost
317 #undef TARGET_MACHINE_DEPENDENT_REORG
318 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
320 #undef TARGET_INIT_LIBFUNCS
321 #define TARGET_INIT_LIBFUNCS pa_init_libfuncs
323 #undef TARGET_PROMOTE_FUNCTION_MODE
324 #define TARGET_PROMOTE_FUNCTION_MODE pa_promote_function_mode
325 #undef TARGET_PROMOTE_PROTOTYPES
326 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
328 #undef TARGET_STRUCT_VALUE_RTX
329 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
330 #undef TARGET_RETURN_IN_MEMORY
331 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
332 #undef TARGET_MUST_PASS_IN_STACK
333 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
334 #undef TARGET_PASS_BY_REFERENCE
335 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
336 #undef TARGET_CALLEE_COPIES
337 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
338 #undef TARGET_ARG_PARTIAL_BYTES
339 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
340 #undef TARGET_FUNCTION_ARG
341 #define TARGET_FUNCTION_ARG pa_function_arg
342 #undef TARGET_FUNCTION_ARG_ADVANCE
343 #define TARGET_FUNCTION_ARG_ADVANCE pa_function_arg_advance
344 #undef TARGET_FUNCTION_ARG_BOUNDARY
345 #define TARGET_FUNCTION_ARG_BOUNDARY pa_function_arg_boundary
347 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
348 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
349 #undef TARGET_EXPAND_BUILTIN_VA_START
350 #define TARGET_EXPAND_BUILTIN_VA_START hppa_va_start
351 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
352 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
354 #undef TARGET_SCALAR_MODE_SUPPORTED_P
355 #define TARGET_SCALAR_MODE_SUPPORTED_P pa_scalar_mode_supported_p
357 #undef TARGET_CANNOT_FORCE_CONST_MEM
358 #define TARGET_CANNOT_FORCE_CONST_MEM pa_cannot_force_const_mem
360 #undef TARGET_SECONDARY_RELOAD
361 #define TARGET_SECONDARY_RELOAD pa_secondary_reload
363 #undef TARGET_EXTRA_LIVE_ON_ENTRY
364 #define TARGET_EXTRA_LIVE_ON_ENTRY pa_extra_live_on_entry
366 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
367 #define TARGET_ASM_TRAMPOLINE_TEMPLATE pa_asm_trampoline_template
368 #undef TARGET_TRAMPOLINE_INIT
369 #define TARGET_TRAMPOLINE_INIT pa_trampoline_init
370 #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
371 #define TARGET_TRAMPOLINE_ADJUST_ADDRESS pa_trampoline_adjust_address
372 #undef TARGET_DELEGITIMIZE_ADDRESS
373 #define TARGET_DELEGITIMIZE_ADDRESS pa_delegitimize_address
374 #undef TARGET_INTERNAL_ARG_POINTER
375 #define TARGET_INTERNAL_ARG_POINTER pa_internal_arg_pointer
376 #undef TARGET_CAN_ELIMINATE
377 #define TARGET_CAN_ELIMINATE pa_can_eliminate
378 #undef TARGET_CONDITIONAL_REGISTER_USAGE
379 #define TARGET_CONDITIONAL_REGISTER_USAGE pa_conditional_register_usage
380 #undef TARGET_C_MODE_FOR_SUFFIX
381 #define TARGET_C_MODE_FOR_SUFFIX pa_c_mode_for_suffix
382 #undef TARGET_ASM_FUNCTION_SECTION
383 #define TARGET_ASM_FUNCTION_SECTION pa_function_section
385 #undef TARGET_LEGITIMATE_CONSTANT_P
386 #define TARGET_LEGITIMATE_CONSTANT_P pa_legitimate_constant_p
387 #undef TARGET_SECTION_TYPE_FLAGS
388 #define TARGET_SECTION_TYPE_FLAGS pa_section_type_flags
390 struct gcc_target targetm = TARGET_INITIALIZER;
392 /* Parse the -mfixed-range= option string. */
395 fix_range (const char *const_str)
398 char *str, *dash, *comma;
400 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
401 REG2 are either register names or register numbers. The effect
402 of this option is to mark the registers in the range from REG1 to
403 REG2 as ``fixed'' so they won't be used by the compiler. This is
404 used, e.g., to ensure that kernel mode code doesn't use fr4-fr31. */
406 i = strlen (const_str);
407 str = (char *) alloca (i + 1);
408 memcpy (str, const_str, i + 1);
412 dash = strchr (str, '-');
415 warning (0, "value of -mfixed-range must have form REG1-REG2");
420 comma = strchr (dash + 1, ',');
424 first = decode_reg_name (str);
427 warning (0, "unknown register name: %s", str);
431 last = decode_reg_name (dash + 1);
434 warning (0, "unknown register name: %s", dash + 1);
442 warning (0, "%s-%s is an empty range", str, dash + 1);
446 for (i = first; i <= last; ++i)
447 fixed_regs[i] = call_used_regs[i] = 1;
456 /* Check if all floating point registers have been fixed. */
457 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
462 target_flags |= MASK_DISABLE_FPREGS;
465 /* Implement the TARGET_OPTION_OVERRIDE hook. */
468 pa_option_override (void)
471 cl_deferred_option *opt;
472 VEC(cl_deferred_option,heap) *vec
473 = (VEC(cl_deferred_option,heap) *) pa_deferred_options;
475 FOR_EACH_VEC_ELT (cl_deferred_option, vec, i, opt)
477 switch (opt->opt_index)
479 case OPT_mfixed_range_:
480 fix_range (opt->arg);
488 /* Unconditional branches in the delay slot are not compatible with dwarf2
489 call frame information. There is no benefit in using this optimization
490 on PA8000 and later processors. */
491 if (pa_cpu >= PROCESSOR_8000
492 || (targetm_common.except_unwind_info (&global_options) == UI_DWARF2
494 || flag_unwind_tables)
495 target_flags &= ~MASK_JUMP_IN_DELAY;
497 if (flag_pic && TARGET_PORTABLE_RUNTIME)
499 warning (0, "PIC code generation is not supported in the portable runtime model");
502 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
504 warning (0, "PIC code generation is not compatible with fast indirect calls");
507 if (! TARGET_GAS && write_symbols != NO_DEBUG)
509 warning (0, "-g is only supported when using GAS on this processor,");
510 warning (0, "-g option disabled");
511 write_symbols = NO_DEBUG;
514 /* We only support the "big PIC" model now. And we always generate PIC
515 code when in 64bit mode. */
516 if (flag_pic == 1 || TARGET_64BIT)
519 /* Disable -freorder-blocks-and-partition as we don't support hot and
520 cold partitioning. */
521 if (flag_reorder_blocks_and_partition)
523 inform (input_location,
524 "-freorder-blocks-and-partition does not work "
525 "on this architecture");
526 flag_reorder_blocks_and_partition = 0;
527 flag_reorder_blocks = 1;
530 /* We can't guarantee that .dword is available for 32-bit targets. */
531 if (UNITS_PER_WORD == 4)
532 targetm.asm_out.aligned_op.di = NULL;
534 /* The unaligned ops are only available when using GAS. */
537 targetm.asm_out.unaligned_op.hi = NULL;
538 targetm.asm_out.unaligned_op.si = NULL;
539 targetm.asm_out.unaligned_op.di = NULL;
542 init_machine_status = pa_init_machine_status;
547 PA_BUILTIN_COPYSIGNQ,
550 PA_BUILTIN_HUGE_VALQ,
554 static GTY(()) tree pa_builtins[(int) PA_BUILTIN_max];
557 pa_init_builtins (void)
559 #ifdef DONT_HAVE_FPUTC_UNLOCKED
561 tree decl = builtin_decl_explicit (BUILT_IN_PUTC_UNLOCKED);
562 set_builtin_decl (BUILT_IN_FPUTC_UNLOCKED, decl,
563 builtin_decl_implicit_p (BUILT_IN_PUTC_UNLOCKED));
570 if ((decl = builtin_decl_explicit (BUILT_IN_FINITE)) != NULL_TREE)
571 set_user_assembler_name (decl, "_Isfinite");
572 if ((decl = builtin_decl_explicit (BUILT_IN_FINITEF)) != NULL_TREE)
573 set_user_assembler_name (decl, "_Isfinitef");
577 if (HPUX_LONG_DOUBLE_LIBRARY)
581 /* Under HPUX, the __float128 type is a synonym for "long double". */
582 (*lang_hooks.types.register_builtin_type) (long_double_type_node,
585 /* TFmode support builtins. */
586 ftype = build_function_type_list (long_double_type_node,
587 long_double_type_node,
589 decl = add_builtin_function ("__builtin_fabsq", ftype,
590 PA_BUILTIN_FABSQ, BUILT_IN_MD,
591 "_U_Qfabs", NULL_TREE);
592 TREE_READONLY (decl) = 1;
593 pa_builtins[PA_BUILTIN_FABSQ] = decl;
595 ftype = build_function_type_list (long_double_type_node,
596 long_double_type_node,
597 long_double_type_node,
599 decl = add_builtin_function ("__builtin_copysignq", ftype,
600 PA_BUILTIN_COPYSIGNQ, BUILT_IN_MD,
601 "_U_Qfcopysign", NULL_TREE);
602 TREE_READONLY (decl) = 1;
603 pa_builtins[PA_BUILTIN_COPYSIGNQ] = decl;
605 ftype = build_function_type_list (long_double_type_node, NULL_TREE);
606 decl = add_builtin_function ("__builtin_infq", ftype,
607 PA_BUILTIN_INFQ, BUILT_IN_MD,
609 pa_builtins[PA_BUILTIN_INFQ] = decl;
611 decl = add_builtin_function ("__builtin_huge_valq", ftype,
612 PA_BUILTIN_HUGE_VALQ, BUILT_IN_MD,
614 pa_builtins[PA_BUILTIN_HUGE_VALQ] = decl;
619 pa_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
620 enum machine_mode mode ATTRIBUTE_UNUSED,
621 int ignore ATTRIBUTE_UNUSED)
623 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
624 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
628 case PA_BUILTIN_FABSQ:
629 case PA_BUILTIN_COPYSIGNQ:
630 return expand_call (exp, target, ignore);
632 case PA_BUILTIN_INFQ:
633 case PA_BUILTIN_HUGE_VALQ:
635 enum machine_mode target_mode = TYPE_MODE (TREE_TYPE (exp));
640 tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, target_mode);
642 tmp = validize_mem (force_const_mem (target_mode, tmp));
645 target = gen_reg_rtx (target_mode);
647 emit_move_insn (target, tmp);
658 /* Function to init struct machine_function.
659 This will be called, via a pointer variable,
660 from push_function_context. */
662 static struct machine_function *
663 pa_init_machine_status (void)
665 return ggc_alloc_cleared_machine_function ();
668 /* If FROM is a probable pointer register, mark TO as a probable
669 pointer register with the same pointer alignment as FROM. */
672 copy_reg_pointer (rtx to, rtx from)
674 if (REG_POINTER (from))
675 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
678 /* Return 1 if X contains a symbolic expression. We know these
679 expressions will have one of a few well defined forms, so
680 we need only check those forms. */
682 pa_symbolic_expression_p (rtx x)
685 /* Strip off any HIGH. */
686 if (GET_CODE (x) == HIGH)
689 return (symbolic_operand (x, VOIDmode));
692 /* Accept any constant that can be moved in one instruction into a
695 pa_cint_ok_for_move (HOST_WIDE_INT ival)
697 /* OK if ldo, ldil, or zdepi, can be used. */
698 return (VAL_14_BITS_P (ival)
699 || pa_ldil_cint_p (ival)
700 || pa_zdepi_cint_p (ival));
703 /* True iff ldil can be used to load this CONST_INT. The least
704 significant 11 bits of the value must be zero and the value must
705 not change sign when extended from 32 to 64 bits. */
707 pa_ldil_cint_p (HOST_WIDE_INT ival)
709 HOST_WIDE_INT x = ival & (((HOST_WIDE_INT) -1 << 31) | 0x7ff);
711 return x == 0 || x == ((HOST_WIDE_INT) -1 << 31);
714 /* True iff zdepi can be used to generate this CONST_INT.
715 zdepi first sign extends a 5-bit signed number to a given field
716 length, then places this field anywhere in a zero. */
718 pa_zdepi_cint_p (unsigned HOST_WIDE_INT x)
720 unsigned HOST_WIDE_INT lsb_mask, t;
722 /* This might not be obvious, but it's at least fast.
723 This function is critical; we don't have the time loops would take. */
725 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
726 /* Return true iff t is a power of two. */
727 return ((t & (t - 1)) == 0);
730 /* True iff depi or extru can be used to compute (reg & mask).
731 Accept bit pattern like these:
736 pa_and_mask_p (unsigned HOST_WIDE_INT mask)
739 mask += mask & -mask;
740 return (mask & (mask - 1)) == 0;
743 /* True iff depi can be used to compute (reg | MASK). */
745 pa_ior_mask_p (unsigned HOST_WIDE_INT mask)
747 mask += mask & -mask;
748 return (mask & (mask - 1)) == 0;
751 /* Legitimize PIC addresses. If the address is already
752 position-independent, we return ORIG. Newly generated
753 position-independent addresses go to REG. If we need more
754 than one register, we lose. */
757 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
761 gcc_assert (!PA_SYMBOL_REF_TLS_P (orig));
763 /* Labels need special handling. */
764 if (pic_label_operand (orig, mode))
768 /* We do not want to go through the movXX expanders here since that
769 would create recursion.
771 Nor do we really want to call a generator for a named pattern
772 since that requires multiple patterns if we want to support
775 So instead we just emit the raw set, which avoids the movXX
776 expanders completely. */
777 mark_reg_pointer (reg, BITS_PER_UNIT);
778 insn = emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
780 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
781 add_reg_note (insn, REG_EQUAL, orig);
783 /* During and after reload, we need to generate a REG_LABEL_OPERAND note
784 and update LABEL_NUSES because this is not done automatically. */
785 if (reload_in_progress || reload_completed)
787 /* Extract LABEL_REF. */
788 if (GET_CODE (orig) == CONST)
789 orig = XEXP (XEXP (orig, 0), 0);
790 /* Extract CODE_LABEL. */
791 orig = XEXP (orig, 0);
792 add_reg_note (insn, REG_LABEL_OPERAND, orig);
793 LABEL_NUSES (orig)++;
795 crtl->uses_pic_offset_table = 1;
798 if (GET_CODE (orig) == SYMBOL_REF)
804 /* Before reload, allocate a temporary register for the intermediate
805 result. This allows the sequence to be deleted when the final
806 result is unused and the insns are trivially dead. */
807 tmp_reg = ((reload_in_progress || reload_completed)
808 ? reg : gen_reg_rtx (Pmode));
810 if (function_label_operand (orig, VOIDmode))
812 /* Force function label into memory in word mode. */
813 orig = XEXP (force_const_mem (word_mode, orig), 0);
814 /* Load plabel address from DLT. */
815 emit_move_insn (tmp_reg,
816 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
817 gen_rtx_HIGH (word_mode, orig)));
819 = gen_const_mem (Pmode,
820 gen_rtx_LO_SUM (Pmode, tmp_reg,
821 gen_rtx_UNSPEC (Pmode,
824 emit_move_insn (reg, pic_ref);
825 /* Now load address of function descriptor. */
826 pic_ref = gen_rtx_MEM (Pmode, reg);
830 /* Load symbol reference from DLT. */
831 emit_move_insn (tmp_reg,
832 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
833 gen_rtx_HIGH (word_mode, orig)));
835 = gen_const_mem (Pmode,
836 gen_rtx_LO_SUM (Pmode, tmp_reg,
837 gen_rtx_UNSPEC (Pmode,
842 crtl->uses_pic_offset_table = 1;
843 mark_reg_pointer (reg, BITS_PER_UNIT);
844 insn = emit_move_insn (reg, pic_ref);
846 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
847 set_unique_reg_note (insn, REG_EQUAL, orig);
851 else if (GET_CODE (orig) == CONST)
855 if (GET_CODE (XEXP (orig, 0)) == PLUS
856 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
860 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
862 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
863 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
864 base == reg ? 0 : reg);
866 if (GET_CODE (orig) == CONST_INT)
868 if (INT_14_BITS (orig))
869 return plus_constant (base, INTVAL (orig));
870 orig = force_reg (Pmode, orig);
872 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
873 /* Likewise, should we set special REG_NOTEs here? */
879 static GTY(()) rtx gen_tls_tga;
882 gen_tls_get_addr (void)
885 gen_tls_tga = init_one_libfunc ("__tls_get_addr");
890 hppa_tls_call (rtx arg)
894 ret = gen_reg_rtx (Pmode);
895 emit_library_call_value (gen_tls_get_addr (), ret,
896 LCT_CONST, Pmode, 1, arg, Pmode);
902 legitimize_tls_address (rtx addr)
904 rtx ret, insn, tmp, t1, t2, tp;
905 enum tls_model model = SYMBOL_REF_TLS_MODEL (addr);
909 case TLS_MODEL_GLOBAL_DYNAMIC:
910 tmp = gen_reg_rtx (Pmode);
912 emit_insn (gen_tgd_load_pic (tmp, addr));
914 emit_insn (gen_tgd_load (tmp, addr));
915 ret = hppa_tls_call (tmp);
918 case TLS_MODEL_LOCAL_DYNAMIC:
919 ret = gen_reg_rtx (Pmode);
920 tmp = gen_reg_rtx (Pmode);
923 emit_insn (gen_tld_load_pic (tmp, addr));
925 emit_insn (gen_tld_load (tmp, addr));
926 t1 = hppa_tls_call (tmp);
929 t2 = gen_reg_rtx (Pmode);
930 emit_libcall_block (insn, t2, t1,
931 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
933 emit_insn (gen_tld_offset_load (ret, addr, t2));
936 case TLS_MODEL_INITIAL_EXEC:
937 tp = gen_reg_rtx (Pmode);
938 tmp = gen_reg_rtx (Pmode);
939 ret = gen_reg_rtx (Pmode);
940 emit_insn (gen_tp_load (tp));
942 emit_insn (gen_tie_load_pic (tmp, addr));
944 emit_insn (gen_tie_load (tmp, addr));
945 emit_move_insn (ret, gen_rtx_PLUS (Pmode, tp, tmp));
948 case TLS_MODEL_LOCAL_EXEC:
949 tp = gen_reg_rtx (Pmode);
950 ret = gen_reg_rtx (Pmode);
951 emit_insn (gen_tp_load (tp));
952 emit_insn (gen_tle_load (ret, addr, tp));
962 /* Try machine-dependent ways of modifying an illegitimate address
963 to be legitimate. If we find one, return the new, valid address.
964 This macro is used in only one place: `memory_address' in explow.c.
966 OLDX is the address as it was before break_out_memory_refs was called.
967 In some cases it is useful to look at this to decide what needs to be done.
969 It is always safe for this macro to do nothing. It exists to recognize
970 opportunities to optimize the output.
972 For the PA, transform:
974 memory(X + <large int>)
978 if (<large int> & mask) >= 16
979 Y = (<large int> & ~mask) + mask + 1 Round up.
981 Y = (<large int> & ~mask) Round down.
983 memory (Z + (<large int> - Y));
985 This is for CSE to find several similar references, and only use one Z.
987 X can either be a SYMBOL_REF or REG, but because combine cannot
988 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
989 D will not fit in 14 bits.
991 MODE_FLOAT references allow displacements which fit in 5 bits, so use
994 MODE_INT references allow displacements which fit in 14 bits, so use
997 This relies on the fact that most mode MODE_FLOAT references will use FP
998 registers and most mode MODE_INT references will use integer registers.
999 (In the rare case of an FP register used in an integer MODE, we depend
1000 on secondary reloads to clean things up.)
1003 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
1004 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
1005 addressing modes to be used).
1007 Put X and Z into registers. Then put the entire expression into
1011 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
1012 enum machine_mode mode)
1016 /* We need to canonicalize the order of operands in unscaled indexed
1017 addresses since the code that checks if an address is valid doesn't
1018 always try both orders. */
1019 if (!TARGET_NO_SPACE_REGS
1020 && GET_CODE (x) == PLUS
1021 && GET_MODE (x) == Pmode
1022 && REG_P (XEXP (x, 0))
1023 && REG_P (XEXP (x, 1))
1024 && REG_POINTER (XEXP (x, 0))
1025 && !REG_POINTER (XEXP (x, 1)))
1026 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
1028 if (PA_SYMBOL_REF_TLS_P (x))
1029 return legitimize_tls_address (x);
1031 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
1033 /* Strip off CONST. */
1034 if (GET_CODE (x) == CONST)
1037 /* Special case. Get the SYMBOL_REF into a register and use indexing.
1038 That should always be safe. */
1039 if (GET_CODE (x) == PLUS
1040 && GET_CODE (XEXP (x, 0)) == REG
1041 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
1043 rtx reg = force_reg (Pmode, XEXP (x, 1));
1044 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
1047 /* Note we must reject symbols which represent function addresses
1048 since the assembler/linker can't handle arithmetic on plabels. */
1049 if (GET_CODE (x) == PLUS
1050 && GET_CODE (XEXP (x, 1)) == CONST_INT
1051 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1052 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
1053 || GET_CODE (XEXP (x, 0)) == REG))
1055 rtx int_part, ptr_reg;
1057 int offset = INTVAL (XEXP (x, 1));
1060 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
1061 ? (INT14_OK_STRICT ? 0x3fff : 0x1f) : 0x3fff);
1063 /* Choose which way to round the offset. Round up if we
1064 are >= halfway to the next boundary. */
1065 if ((offset & mask) >= ((mask + 1) / 2))
1066 newoffset = (offset & ~ mask) + mask + 1;
1068 newoffset = (offset & ~ mask);
1070 /* If the newoffset will not fit in 14 bits (ldo), then
1071 handling this would take 4 or 5 instructions (2 to load
1072 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
1073 add the new offset and the SYMBOL_REF.) Combine can
1074 not handle 4->2 or 5->2 combinations, so do not create
1076 if (! VAL_14_BITS_P (newoffset)
1077 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
1079 rtx const_part = plus_constant (XEXP (x, 0), newoffset);
1082 gen_rtx_HIGH (Pmode, const_part));
1085 gen_rtx_LO_SUM (Pmode,
1086 tmp_reg, const_part));
1090 if (! VAL_14_BITS_P (newoffset))
1091 int_part = force_reg (Pmode, GEN_INT (newoffset));
1093 int_part = GEN_INT (newoffset);
1095 ptr_reg = force_reg (Pmode,
1096 gen_rtx_PLUS (Pmode,
1097 force_reg (Pmode, XEXP (x, 0)),
1100 return plus_constant (ptr_reg, offset - newoffset);
1103 /* Handle (plus (mult (a) (shadd_constant)) (b)). */
1105 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
1106 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1107 && pa_shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
1108 && (OBJECT_P (XEXP (x, 1))
1109 || GET_CODE (XEXP (x, 1)) == SUBREG)
1110 && GET_CODE (XEXP (x, 1)) != CONST)
1112 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1116 if (GET_CODE (reg1) != REG)
1117 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1119 reg2 = XEXP (XEXP (x, 0), 0);
1120 if (GET_CODE (reg2) != REG)
1121 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1123 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1124 gen_rtx_MULT (Pmode,
1130 /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
1132 Only do so for floating point modes since this is more speculative
1133 and we lose if it's an integer store. */
1134 if (GET_CODE (x) == PLUS
1135 && GET_CODE (XEXP (x, 0)) == PLUS
1136 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1137 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
1138 && pa_shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
1139 && (mode == SFmode || mode == DFmode))
1142 /* First, try and figure out what to use as a base register. */
1143 rtx reg1, reg2, base, idx;
1145 reg1 = XEXP (XEXP (x, 0), 1);
1150 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
1151 then pa_emit_move_sequence will turn on REG_POINTER so we'll know
1152 it's a base register below. */
1153 if (GET_CODE (reg1) != REG)
1154 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1156 if (GET_CODE (reg2) != REG)
1157 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1159 /* Figure out what the base and index are. */
1161 if (GET_CODE (reg1) == REG
1162 && REG_POINTER (reg1))
1165 idx = gen_rtx_PLUS (Pmode,
1166 gen_rtx_MULT (Pmode,
1167 XEXP (XEXP (XEXP (x, 0), 0), 0),
1168 XEXP (XEXP (XEXP (x, 0), 0), 1)),
1171 else if (GET_CODE (reg2) == REG
1172 && REG_POINTER (reg2))
1181 /* If the index adds a large constant, try to scale the
1182 constant so that it can be loaded with only one insn. */
1183 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1184 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1185 / INTVAL (XEXP (XEXP (idx, 0), 1)))
1186 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1188 /* Divide the CONST_INT by the scale factor, then add it to A. */
1189 int val = INTVAL (XEXP (idx, 1));
1191 val /= INTVAL (XEXP (XEXP (idx, 0), 1));
1192 reg1 = XEXP (XEXP (idx, 0), 0);
1193 if (GET_CODE (reg1) != REG)
1194 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1196 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1198 /* We can now generate a simple scaled indexed address. */
1201 (Pmode, gen_rtx_PLUS (Pmode,
1202 gen_rtx_MULT (Pmode, reg1,
1203 XEXP (XEXP (idx, 0), 1)),
1207 /* If B + C is still a valid base register, then add them. */
1208 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1209 && INTVAL (XEXP (idx, 1)) <= 4096
1210 && INTVAL (XEXP (idx, 1)) >= -4096)
1212 int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1215 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1217 reg2 = XEXP (XEXP (idx, 0), 0);
1218 if (GET_CODE (reg2) != CONST_INT)
1219 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1221 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1222 gen_rtx_MULT (Pmode,
1228 /* Get the index into a register, then add the base + index and
1229 return a register holding the result. */
1231 /* First get A into a register. */
1232 reg1 = XEXP (XEXP (idx, 0), 0);
1233 if (GET_CODE (reg1) != REG)
1234 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1236 /* And get B into a register. */
1237 reg2 = XEXP (idx, 1);
1238 if (GET_CODE (reg2) != REG)
1239 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1241 reg1 = force_reg (Pmode,
1242 gen_rtx_PLUS (Pmode,
1243 gen_rtx_MULT (Pmode, reg1,
1244 XEXP (XEXP (idx, 0), 1)),
1247 /* Add the result to our base register and return. */
1248 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1252 /* Uh-oh. We might have an address for x[n-100000]. This needs
1253 special handling to avoid creating an indexed memory address
1254 with x-100000 as the base.
1256 If the constant part is small enough, then it's still safe because
1257 there is a guard page at the beginning and end of the data segment.
1259 Scaled references are common enough that we want to try and rearrange the
1260 terms so that we can use indexing for these addresses too. Only
1261 do the optimization for floatint point modes. */
1263 if (GET_CODE (x) == PLUS
1264 && pa_symbolic_expression_p (XEXP (x, 1)))
1266 /* Ugly. We modify things here so that the address offset specified
1267 by the index expression is computed first, then added to x to form
1268 the entire address. */
1270 rtx regx1, regx2, regy1, regy2, y;
1272 /* Strip off any CONST. */
1274 if (GET_CODE (y) == CONST)
1277 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1279 /* See if this looks like
1280 (plus (mult (reg) (shadd_const))
1281 (const (plus (symbol_ref) (const_int))))
1283 Where const_int is small. In that case the const
1284 expression is a valid pointer for indexing.
1286 If const_int is big, but can be divided evenly by shadd_const
1287 and added to (reg). This allows more scaled indexed addresses. */
1288 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1289 && GET_CODE (XEXP (x, 0)) == MULT
1290 && GET_CODE (XEXP (y, 1)) == CONST_INT
1291 && INTVAL (XEXP (y, 1)) >= -4096
1292 && INTVAL (XEXP (y, 1)) <= 4095
1293 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1294 && pa_shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1296 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1300 if (GET_CODE (reg1) != REG)
1301 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1303 reg2 = XEXP (XEXP (x, 0), 0);
1304 if (GET_CODE (reg2) != REG)
1305 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1307 return force_reg (Pmode,
1308 gen_rtx_PLUS (Pmode,
1309 gen_rtx_MULT (Pmode,
1314 else if ((mode == DFmode || mode == SFmode)
1315 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1316 && GET_CODE (XEXP (x, 0)) == MULT
1317 && GET_CODE (XEXP (y, 1)) == CONST_INT
1318 && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1319 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1320 && pa_shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1323 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1324 / INTVAL (XEXP (XEXP (x, 0), 1))));
1325 regx2 = XEXP (XEXP (x, 0), 0);
1326 if (GET_CODE (regx2) != REG)
1327 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1328 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1332 gen_rtx_PLUS (Pmode,
1333 gen_rtx_MULT (Pmode, regx2,
1334 XEXP (XEXP (x, 0), 1)),
1335 force_reg (Pmode, XEXP (y, 0))));
1337 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1338 && INTVAL (XEXP (y, 1)) >= -4096
1339 && INTVAL (XEXP (y, 1)) <= 4095)
1341 /* This is safe because of the guard page at the
1342 beginning and end of the data space. Just
1343 return the original address. */
1348 /* Doesn't look like one we can optimize. */
1349 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1350 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1351 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1352 regx1 = force_reg (Pmode,
1353 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1355 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1363 /* Implement the TARGET_REGISTER_MOVE_COST hook.
1365 Compute extra cost of moving data between one register class
1368 Make moves from SAR so expensive they should never happen. We used to
1369 have 0xffff here, but that generates overflow in rare cases.
1371 Copies involving a FP register and a non-FP register are relatively
1372 expensive because they must go through memory.
1374 Other copies are reasonably cheap. */
1377 hppa_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1378 reg_class_t from, reg_class_t to)
1380 if (from == SHIFT_REGS)
1382 else if (to == SHIFT_REGS && FP_REG_CLASS_P (from))
1384 else if ((FP_REG_CLASS_P (from) && ! FP_REG_CLASS_P (to))
1385 || (FP_REG_CLASS_P (to) && ! FP_REG_CLASS_P (from)))
1391 /* For the HPPA, REG and REG+CONST is cost 0
1392 and addresses involving symbolic constants are cost 2.
1394 PIC addresses are very expensive.
1396 It is no coincidence that this has the same structure
1397 as GO_IF_LEGITIMATE_ADDRESS. */
1400 hppa_address_cost (rtx X,
1401 bool speed ATTRIBUTE_UNUSED)
1403 switch (GET_CODE (X))
1416 /* Compute a (partial) cost for rtx X. Return true if the complete
1417 cost has been computed, and false if subexpressions should be
1418 scanned. In either case, *TOTAL contains the cost result. */
1421 hppa_rtx_costs (rtx x, int code, int outer_code, int opno ATTRIBUTE_UNUSED,
1422 int *total, bool speed ATTRIBUTE_UNUSED)
1427 if (INTVAL (x) == 0)
1429 else if (INT_14_BITS (x))
1446 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1447 && outer_code != SET)
1454 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1455 *total = COSTS_N_INSNS (3);
1456 else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1457 *total = COSTS_N_INSNS (8);
1459 *total = COSTS_N_INSNS (20);
1463 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1465 *total = COSTS_N_INSNS (14);
1473 *total = COSTS_N_INSNS (60);
1476 case PLUS: /* this includes shNadd insns */
1478 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1479 *total = COSTS_N_INSNS (3);
1481 *total = COSTS_N_INSNS (1);
1487 *total = COSTS_N_INSNS (1);
1495 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1496 new rtx with the correct mode. */
1498 force_mode (enum machine_mode mode, rtx orig)
1500 if (mode == GET_MODE (orig))
1503 gcc_assert (REGNO (orig) < FIRST_PSEUDO_REGISTER);
1505 return gen_rtx_REG (mode, REGNO (orig));
1508 /* Return 1 if *X is a thread-local symbol. */
1511 pa_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1513 return PA_SYMBOL_REF_TLS_P (*x);
1516 /* Return 1 if X contains a thread-local symbol. */
1519 pa_tls_referenced_p (rtx x)
1521 if (!TARGET_HAVE_TLS)
1524 return for_each_rtx (&x, &pa_tls_symbol_ref_1, 0);
1527 /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */
1530 pa_cannot_force_const_mem (enum machine_mode mode ATTRIBUTE_UNUSED, rtx x)
1532 return pa_tls_referenced_p (x);
1535 /* Emit insns to move operands[1] into operands[0].
1537 Return 1 if we have written out everything that needs to be done to
1538 do the move. Otherwise, return 0 and the caller will emit the move
1541 Note SCRATCH_REG may not be in the proper mode depending on how it
1542 will be used. This routine is responsible for creating a new copy
1543 of SCRATCH_REG in the proper mode. */
1546 pa_emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1548 register rtx operand0 = operands[0];
1549 register rtx operand1 = operands[1];
1552 /* We can only handle indexed addresses in the destination operand
1553 of floating point stores. Thus, we need to break out indexed
1554 addresses from the destination operand. */
1555 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1557 gcc_assert (can_create_pseudo_p ());
1559 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1560 operand0 = replace_equiv_address (operand0, tem);
1563 /* On targets with non-equivalent space registers, break out unscaled
1564 indexed addresses from the source operand before the final CSE.
1565 We have to do this because the REG_POINTER flag is not correctly
1566 carried through various optimization passes and CSE may substitute
1567 a pseudo without the pointer set for one with the pointer set. As
1568 a result, we loose various opportunities to create insns with
1569 unscaled indexed addresses. */
1570 if (!TARGET_NO_SPACE_REGS
1571 && !cse_not_expected
1572 && GET_CODE (operand1) == MEM
1573 && GET_CODE (XEXP (operand1, 0)) == PLUS
1574 && REG_P (XEXP (XEXP (operand1, 0), 0))
1575 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1577 = replace_equiv_address (operand1,
1578 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1581 && reload_in_progress && GET_CODE (operand0) == REG
1582 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1583 operand0 = reg_equiv_mem (REGNO (operand0));
1584 else if (scratch_reg
1585 && reload_in_progress && GET_CODE (operand0) == SUBREG
1586 && GET_CODE (SUBREG_REG (operand0)) == REG
1587 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1589 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1590 the code which tracks sets/uses for delete_output_reload. */
1591 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1592 reg_equiv_mem (REGNO (SUBREG_REG (operand0))),
1593 SUBREG_BYTE (operand0));
1594 operand0 = alter_subreg (&temp);
1598 && reload_in_progress && GET_CODE (operand1) == REG
1599 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1600 operand1 = reg_equiv_mem (REGNO (operand1));
1601 else if (scratch_reg
1602 && reload_in_progress && GET_CODE (operand1) == SUBREG
1603 && GET_CODE (SUBREG_REG (operand1)) == REG
1604 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1606 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1607 the code which tracks sets/uses for delete_output_reload. */
1608 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1609 reg_equiv_mem (REGNO (SUBREG_REG (operand1))),
1610 SUBREG_BYTE (operand1));
1611 operand1 = alter_subreg (&temp);
1614 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1615 && ((tem = find_replacement (&XEXP (operand0, 0)))
1616 != XEXP (operand0, 0)))
1617 operand0 = replace_equiv_address (operand0, tem);
1619 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1620 && ((tem = find_replacement (&XEXP (operand1, 0)))
1621 != XEXP (operand1, 0)))
1622 operand1 = replace_equiv_address (operand1, tem);
1624 /* Handle secondary reloads for loads/stores of FP registers from
1625 REG+D addresses where D does not fit in 5 or 14 bits, including
1626 (subreg (mem (addr))) cases. */
1628 && fp_reg_operand (operand0, mode)
1629 && ((GET_CODE (operand1) == MEM
1630 && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1631 XEXP (operand1, 0)))
1632 || ((GET_CODE (operand1) == SUBREG
1633 && GET_CODE (XEXP (operand1, 0)) == MEM
1634 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1636 XEXP (XEXP (operand1, 0), 0))))))
1638 if (GET_CODE (operand1) == SUBREG)
1639 operand1 = XEXP (operand1, 0);
1641 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1642 it in WORD_MODE regardless of what mode it was originally given
1644 scratch_reg = force_mode (word_mode, scratch_reg);
1646 /* D might not fit in 14 bits either; for such cases load D into
1648 if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1650 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1651 emit_move_insn (scratch_reg,
1652 gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1654 XEXP (XEXP (operand1, 0), 0),
1658 emit_move_insn (scratch_reg, XEXP (operand1, 0));
1659 emit_insn (gen_rtx_SET (VOIDmode, operand0,
1660 replace_equiv_address (operand1, scratch_reg)));
1663 else if (scratch_reg
1664 && fp_reg_operand (operand1, mode)
1665 && ((GET_CODE (operand0) == MEM
1666 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1668 XEXP (operand0, 0)))
1669 || ((GET_CODE (operand0) == SUBREG)
1670 && GET_CODE (XEXP (operand0, 0)) == MEM
1671 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1673 XEXP (XEXP (operand0, 0), 0)))))
1675 if (GET_CODE (operand0) == SUBREG)
1676 operand0 = XEXP (operand0, 0);
1678 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1679 it in WORD_MODE regardless of what mode it was originally given
1681 scratch_reg = force_mode (word_mode, scratch_reg);
1683 /* D might not fit in 14 bits either; for such cases load D into
1685 if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1687 emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1688 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1691 XEXP (XEXP (operand0, 0),
1696 emit_move_insn (scratch_reg, XEXP (operand0, 0));
1697 emit_insn (gen_rtx_SET (VOIDmode,
1698 replace_equiv_address (operand0, scratch_reg),
1702 /* Handle secondary reloads for loads of FP registers from constant
1703 expressions by forcing the constant into memory.
1705 Use scratch_reg to hold the address of the memory location.
1707 The proper fix is to change TARGET_PREFERRED_RELOAD_CLASS to return
1708 NO_REGS when presented with a const_int and a register class
1709 containing only FP registers. Doing so unfortunately creates
1710 more problems than it solves. Fix this for 2.5. */
1711 else if (scratch_reg
1712 && CONSTANT_P (operand1)
1713 && fp_reg_operand (operand0, mode))
1715 rtx const_mem, xoperands[2];
1717 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1718 it in WORD_MODE regardless of what mode it was originally given
1720 scratch_reg = force_mode (word_mode, scratch_reg);
1722 /* Force the constant into memory and put the address of the
1723 memory location into scratch_reg. */
1724 const_mem = force_const_mem (mode, operand1);
1725 xoperands[0] = scratch_reg;
1726 xoperands[1] = XEXP (const_mem, 0);
1727 pa_emit_move_sequence (xoperands, Pmode, 0);
1729 /* Now load the destination register. */
1730 emit_insn (gen_rtx_SET (mode, operand0,
1731 replace_equiv_address (const_mem, scratch_reg)));
1734 /* Handle secondary reloads for SAR. These occur when trying to load
1735 the SAR from memory or a constant. */
1736 else if (scratch_reg
1737 && GET_CODE (operand0) == REG
1738 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1739 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1740 && (GET_CODE (operand1) == MEM || GET_CODE (operand1) == CONST_INT))
1742 /* D might not fit in 14 bits either; for such cases load D into
1744 if (GET_CODE (operand1) == MEM
1745 && !memory_address_p (GET_MODE (operand0), XEXP (operand1, 0)))
1747 /* We are reloading the address into the scratch register, so we
1748 want to make sure the scratch register is a full register. */
1749 scratch_reg = force_mode (word_mode, scratch_reg);
1751 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1752 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1755 XEXP (XEXP (operand1, 0),
1759 /* Now we are going to load the scratch register from memory,
1760 we want to load it in the same width as the original MEM,
1761 which must be the same as the width of the ultimate destination,
1763 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1765 emit_move_insn (scratch_reg,
1766 replace_equiv_address (operand1, scratch_reg));
1770 /* We want to load the scratch register using the same mode as
1771 the ultimate destination. */
1772 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1774 emit_move_insn (scratch_reg, operand1);
1777 /* And emit the insn to set the ultimate destination. We know that
1778 the scratch register has the same mode as the destination at this
1780 emit_move_insn (operand0, scratch_reg);
1783 /* Handle the most common case: storing into a register. */
1784 else if (register_operand (operand0, mode))
1786 /* Legitimize TLS symbol references. This happens for references
1787 that aren't a legitimate constant. */
1788 if (PA_SYMBOL_REF_TLS_P (operand1))
1789 operand1 = legitimize_tls_address (operand1);
1791 if (register_operand (operand1, mode)
1792 || (GET_CODE (operand1) == CONST_INT
1793 && pa_cint_ok_for_move (INTVAL (operand1)))
1794 || (operand1 == CONST0_RTX (mode))
1795 || (GET_CODE (operand1) == HIGH
1796 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1797 /* Only `general_operands' can come here, so MEM is ok. */
1798 || GET_CODE (operand1) == MEM)
1800 /* Various sets are created during RTL generation which don't
1801 have the REG_POINTER flag correctly set. After the CSE pass,
1802 instruction recognition can fail if we don't consistently
1803 set this flag when performing register copies. This should
1804 also improve the opportunities for creating insns that use
1805 unscaled indexing. */
1806 if (REG_P (operand0) && REG_P (operand1))
1808 if (REG_POINTER (operand1)
1809 && !REG_POINTER (operand0)
1810 && !HARD_REGISTER_P (operand0))
1811 copy_reg_pointer (operand0, operand1);
1814 /* When MEMs are broken out, the REG_POINTER flag doesn't
1815 get set. In some cases, we can set the REG_POINTER flag
1816 from the declaration for the MEM. */
1817 if (REG_P (operand0)
1818 && GET_CODE (operand1) == MEM
1819 && !REG_POINTER (operand0))
1821 tree decl = MEM_EXPR (operand1);
1823 /* Set the register pointer flag and register alignment
1824 if the declaration for this memory reference is a
1830 /* If this is a COMPONENT_REF, use the FIELD_DECL from
1832 if (TREE_CODE (decl) == COMPONENT_REF)
1833 decl = TREE_OPERAND (decl, 1);
1835 type = TREE_TYPE (decl);
1836 type = strip_array_types (type);
1838 if (POINTER_TYPE_P (type))
1842 type = TREE_TYPE (type);
1843 /* Using TYPE_ALIGN_OK is rather conservative as
1844 only the ada frontend actually sets it. */
1845 align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1847 mark_reg_pointer (operand0, align);
1852 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1856 else if (GET_CODE (operand0) == MEM)
1858 if (mode == DFmode && operand1 == CONST0_RTX (mode)
1859 && !(reload_in_progress || reload_completed))
1861 rtx temp = gen_reg_rtx (DFmode);
1863 emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
1864 emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
1867 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
1869 /* Run this case quickly. */
1870 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1873 if (! (reload_in_progress || reload_completed))
1875 operands[0] = validize_mem (operand0);
1876 operands[1] = operand1 = force_reg (mode, operand1);
1880 /* Simplify the source if we need to.
1881 Note we do have to handle function labels here, even though we do
1882 not consider them legitimate constants. Loop optimizations can
1883 call the emit_move_xxx with one as a source. */
1884 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
1885 || function_label_operand (operand1, VOIDmode)
1886 || (GET_CODE (operand1) == HIGH
1887 && symbolic_operand (XEXP (operand1, 0), mode)))
1891 if (GET_CODE (operand1) == HIGH)
1894 operand1 = XEXP (operand1, 0);
1896 if (symbolic_operand (operand1, mode))
1898 /* Argh. The assembler and linker can't handle arithmetic
1901 So we force the plabel into memory, load operand0 from
1902 the memory location, then add in the constant part. */
1903 if ((GET_CODE (operand1) == CONST
1904 && GET_CODE (XEXP (operand1, 0)) == PLUS
1905 && function_label_operand (XEXP (XEXP (operand1, 0), 0),
1907 || function_label_operand (operand1, VOIDmode))
1909 rtx temp, const_part;
1911 /* Figure out what (if any) scratch register to use. */
1912 if (reload_in_progress || reload_completed)
1914 scratch_reg = scratch_reg ? scratch_reg : operand0;
1915 /* SCRATCH_REG will hold an address and maybe the actual
1916 data. We want it in WORD_MODE regardless of what mode it
1917 was originally given to us. */
1918 scratch_reg = force_mode (word_mode, scratch_reg);
1921 scratch_reg = gen_reg_rtx (Pmode);
1923 if (GET_CODE (operand1) == CONST)
1925 /* Save away the constant part of the expression. */
1926 const_part = XEXP (XEXP (operand1, 0), 1);
1927 gcc_assert (GET_CODE (const_part) == CONST_INT);
1929 /* Force the function label into memory. */
1930 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
1934 /* No constant part. */
1935 const_part = NULL_RTX;
1937 /* Force the function label into memory. */
1938 temp = force_const_mem (mode, operand1);
1942 /* Get the address of the memory location. PIC-ify it if
1944 temp = XEXP (temp, 0);
1946 temp = legitimize_pic_address (temp, mode, scratch_reg);
1948 /* Put the address of the memory location into our destination
1951 pa_emit_move_sequence (operands, mode, scratch_reg);
1953 /* Now load from the memory location into our destination
1955 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
1956 pa_emit_move_sequence (operands, mode, scratch_reg);
1958 /* And add back in the constant part. */
1959 if (const_part != NULL_RTX)
1960 expand_inc (operand0, const_part);
1969 if (reload_in_progress || reload_completed)
1971 temp = scratch_reg ? scratch_reg : operand0;
1972 /* TEMP will hold an address and maybe the actual
1973 data. We want it in WORD_MODE regardless of what mode it
1974 was originally given to us. */
1975 temp = force_mode (word_mode, temp);
1978 temp = gen_reg_rtx (Pmode);
1980 /* (const (plus (symbol) (const_int))) must be forced to
1981 memory during/after reload if the const_int will not fit
1983 if (GET_CODE (operand1) == CONST
1984 && GET_CODE (XEXP (operand1, 0)) == PLUS
1985 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
1986 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
1987 && (reload_completed || reload_in_progress)
1990 rtx const_mem = force_const_mem (mode, operand1);
1991 operands[1] = legitimize_pic_address (XEXP (const_mem, 0),
1993 operands[1] = replace_equiv_address (const_mem, operands[1]);
1994 pa_emit_move_sequence (operands, mode, temp);
1998 operands[1] = legitimize_pic_address (operand1, mode, temp);
1999 if (REG_P (operand0) && REG_P (operands[1]))
2000 copy_reg_pointer (operand0, operands[1]);
2001 emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
2004 /* On the HPPA, references to data space are supposed to use dp,
2005 register 27, but showing it in the RTL inhibits various cse
2006 and loop optimizations. */
2011 if (reload_in_progress || reload_completed)
2013 temp = scratch_reg ? scratch_reg : operand0;
2014 /* TEMP will hold an address and maybe the actual
2015 data. We want it in WORD_MODE regardless of what mode it
2016 was originally given to us. */
2017 temp = force_mode (word_mode, temp);
2020 temp = gen_reg_rtx (mode);
2022 /* Loading a SYMBOL_REF into a register makes that register
2023 safe to be used as the base in an indexed address.
2025 Don't mark hard registers though. That loses. */
2026 if (GET_CODE (operand0) == REG
2027 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
2028 mark_reg_pointer (operand0, BITS_PER_UNIT);
2029 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
2030 mark_reg_pointer (temp, BITS_PER_UNIT);
2033 set = gen_rtx_SET (mode, operand0, temp);
2035 set = gen_rtx_SET (VOIDmode,
2037 gen_rtx_LO_SUM (mode, temp, operand1));
2039 emit_insn (gen_rtx_SET (VOIDmode,
2041 gen_rtx_HIGH (mode, operand1)));
2047 else if (pa_tls_referenced_p (operand1))
2052 if (GET_CODE (tmp) == CONST && GET_CODE (XEXP (tmp, 0)) == PLUS)
2054 addend = XEXP (XEXP (tmp, 0), 1);
2055 tmp = XEXP (XEXP (tmp, 0), 0);
2058 gcc_assert (GET_CODE (tmp) == SYMBOL_REF);
2059 tmp = legitimize_tls_address (tmp);
2062 tmp = gen_rtx_PLUS (mode, tmp, addend);
2063 tmp = force_operand (tmp, operands[0]);
2067 else if (GET_CODE (operand1) != CONST_INT
2068 || !pa_cint_ok_for_move (INTVAL (operand1)))
2072 HOST_WIDE_INT value = 0;
2073 HOST_WIDE_INT insv = 0;
2076 if (GET_CODE (operand1) == CONST_INT)
2077 value = INTVAL (operand1);
2080 && GET_CODE (operand1) == CONST_INT
2081 && HOST_BITS_PER_WIDE_INT > 32
2082 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
2086 /* Extract the low order 32 bits of the value and sign extend.
2087 If the new value is the same as the original value, we can
2088 can use the original value as-is. If the new value is
2089 different, we use it and insert the most-significant 32-bits
2090 of the original value into the final result. */
2091 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
2092 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
2095 #if HOST_BITS_PER_WIDE_INT > 32
2096 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
2100 operand1 = GEN_INT (nval);
2104 if (reload_in_progress || reload_completed)
2105 temp = scratch_reg ? scratch_reg : operand0;
2107 temp = gen_reg_rtx (mode);
2109 /* We don't directly split DImode constants on 32-bit targets
2110 because PLUS uses an 11-bit immediate and the insn sequence
2111 generated is not as efficient as the one using HIGH/LO_SUM. */
2112 if (GET_CODE (operand1) == CONST_INT
2113 && GET_MODE_BITSIZE (mode) <= BITS_PER_WORD
2114 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2117 /* Directly break constant into high and low parts. This
2118 provides better optimization opportunities because various
2119 passes recognize constants split with PLUS but not LO_SUM.
2120 We use a 14-bit signed low part except when the addition
2121 of 0x4000 to the high part might change the sign of the
2123 HOST_WIDE_INT low = value & 0x3fff;
2124 HOST_WIDE_INT high = value & ~ 0x3fff;
2128 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
2136 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
2137 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2141 emit_insn (gen_rtx_SET (VOIDmode, temp,
2142 gen_rtx_HIGH (mode, operand1)));
2143 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
2146 insn = emit_move_insn (operands[0], operands[1]);
2148 /* Now insert the most significant 32 bits of the value
2149 into the register. When we don't have a second register
2150 available, it could take up to nine instructions to load
2151 a 64-bit integer constant. Prior to reload, we force
2152 constants that would take more than three instructions
2153 to load to the constant pool. During and after reload,
2154 we have to handle all possible values. */
2157 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
2158 register and the value to be inserted is outside the
2159 range that can be loaded with three depdi instructions. */
2160 if (temp != operand0 && (insv >= 16384 || insv < -16384))
2162 operand1 = GEN_INT (insv);
2164 emit_insn (gen_rtx_SET (VOIDmode, temp,
2165 gen_rtx_HIGH (mode, operand1)));
2166 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
2167 emit_insn (gen_insv (operand0, GEN_INT (32),
2172 int len = 5, pos = 27;
2174 /* Insert the bits using the depdi instruction. */
2177 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
2178 HOST_WIDE_INT sign = v5 < 0;
2180 /* Left extend the insertion. */
2181 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
2182 while (pos > 0 && (insv & 1) == sign)
2184 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
2189 emit_insn (gen_insv (operand0, GEN_INT (len),
2190 GEN_INT (pos), GEN_INT (v5)));
2192 len = pos > 0 && pos < 5 ? pos : 5;
2198 set_unique_reg_note (insn, REG_EQUAL, op1);
2203 /* Now have insn-emit do whatever it normally does. */
2207 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
2208 it will need a link/runtime reloc). */
2211 pa_reloc_needed (tree exp)
2215 switch (TREE_CODE (exp))
2220 case POINTER_PLUS_EXPR:
2223 reloc = pa_reloc_needed (TREE_OPERAND (exp, 0));
2224 reloc |= pa_reloc_needed (TREE_OPERAND (exp, 1));
2228 case NON_LVALUE_EXPR:
2229 reloc = pa_reloc_needed (TREE_OPERAND (exp, 0));
2235 unsigned HOST_WIDE_INT ix;
2237 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), ix, value)
2239 reloc |= pa_reloc_needed (value);
2253 /* Return the best assembler insn template
2254 for moving operands[1] into operands[0] as a fullword. */
2256 pa_singlemove_string (rtx *operands)
2258 HOST_WIDE_INT intval;
2260 if (GET_CODE (operands[0]) == MEM)
2261 return "stw %r1,%0";
2262 if (GET_CODE (operands[1]) == MEM)
2264 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2269 gcc_assert (GET_MODE (operands[1]) == SFmode);
2271 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2273 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2274 REAL_VALUE_TO_TARGET_SINGLE (d, i);
2276 operands[1] = GEN_INT (i);
2277 /* Fall through to CONST_INT case. */
2279 if (GET_CODE (operands[1]) == CONST_INT)
2281 intval = INTVAL (operands[1]);
2283 if (VAL_14_BITS_P (intval))
2285 else if ((intval & 0x7ff) == 0)
2286 return "ldil L'%1,%0";
2287 else if (pa_zdepi_cint_p (intval))
2288 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2290 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2292 return "copy %1,%0";
2296 /* Compute position (in OP[1]) and width (in OP[2])
2297 useful for copying IMM to a register using the zdepi
2298 instructions. Store the immediate value to insert in OP[0]. */
2300 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2304 /* Find the least significant set bit in IMM. */
2305 for (lsb = 0; lsb < 32; lsb++)
2312 /* Choose variants based on *sign* of the 5-bit field. */
2313 if ((imm & 0x10) == 0)
2314 len = (lsb <= 28) ? 4 : 32 - lsb;
2317 /* Find the width of the bitstring in IMM. */
2318 for (len = 5; len < 32 - lsb; len++)
2320 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2324 /* Sign extend IMM as a 5-bit value. */
2325 imm = (imm & 0xf) - 0x10;
2333 /* Compute position (in OP[1]) and width (in OP[2])
2334 useful for copying IMM to a register using the depdi,z
2335 instructions. Store the immediate value to insert in OP[0]. */
2338 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2340 int lsb, len, maxlen;
2342 maxlen = MIN (HOST_BITS_PER_WIDE_INT, 64);
2344 /* Find the least significant set bit in IMM. */
2345 for (lsb = 0; lsb < maxlen; lsb++)
2352 /* Choose variants based on *sign* of the 5-bit field. */
2353 if ((imm & 0x10) == 0)
2354 len = (lsb <= maxlen - 4) ? 4 : maxlen - lsb;
2357 /* Find the width of the bitstring in IMM. */
2358 for (len = 5; len < maxlen - lsb; len++)
2360 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2364 /* Extend length if host is narrow and IMM is negative. */
2365 if (HOST_BITS_PER_WIDE_INT == 32 && len == maxlen - lsb)
2368 /* Sign extend IMM as a 5-bit value. */
2369 imm = (imm & 0xf) - 0x10;
2377 /* Output assembler code to perform a doubleword move insn
2378 with operands OPERANDS. */
2381 pa_output_move_double (rtx *operands)
2383 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2385 rtx addreg0 = 0, addreg1 = 0;
2387 /* First classify both operands. */
2389 if (REG_P (operands[0]))
2391 else if (offsettable_memref_p (operands[0]))
2393 else if (GET_CODE (operands[0]) == MEM)
2398 if (REG_P (operands[1]))
2400 else if (CONSTANT_P (operands[1]))
2402 else if (offsettable_memref_p (operands[1]))
2404 else if (GET_CODE (operands[1]) == MEM)
2409 /* Check for the cases that the operand constraints are not
2410 supposed to allow to happen. */
2411 gcc_assert (optype0 == REGOP || optype1 == REGOP);
2413 /* Handle copies between general and floating registers. */
2415 if (optype0 == REGOP && optype1 == REGOP
2416 && FP_REG_P (operands[0]) ^ FP_REG_P (operands[1]))
2418 if (FP_REG_P (operands[0]))
2420 output_asm_insn ("{stws|stw} %1,-16(%%sp)", operands);
2421 output_asm_insn ("{stws|stw} %R1,-12(%%sp)", operands);
2422 return "{fldds|fldd} -16(%%sp),%0";
2426 output_asm_insn ("{fstds|fstd} %1,-16(%%sp)", operands);
2427 output_asm_insn ("{ldws|ldw} -16(%%sp),%0", operands);
2428 return "{ldws|ldw} -12(%%sp),%R0";
2432 /* Handle auto decrementing and incrementing loads and stores
2433 specifically, since the structure of the function doesn't work
2434 for them without major modification. Do it better when we learn
2435 this port about the general inc/dec addressing of PA.
2436 (This was written by tege. Chide him if it doesn't work.) */
2438 if (optype0 == MEMOP)
2440 /* We have to output the address syntax ourselves, since print_operand
2441 doesn't deal with the addresses we want to use. Fix this later. */
2443 rtx addr = XEXP (operands[0], 0);
2444 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2446 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2448 operands[0] = XEXP (addr, 0);
2449 gcc_assert (GET_CODE (operands[1]) == REG
2450 && GET_CODE (operands[0]) == REG);
2452 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2454 /* No overlap between high target register and address
2455 register. (We do this in a non-obvious way to
2456 save a register file writeback) */
2457 if (GET_CODE (addr) == POST_INC)
2458 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2459 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2461 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2463 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2465 operands[0] = XEXP (addr, 0);
2466 gcc_assert (GET_CODE (operands[1]) == REG
2467 && GET_CODE (operands[0]) == REG);
2469 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2470 /* No overlap between high target register and address
2471 register. (We do this in a non-obvious way to save a
2472 register file writeback) */
2473 if (GET_CODE (addr) == PRE_INC)
2474 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2475 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2478 if (optype1 == MEMOP)
2480 /* We have to output the address syntax ourselves, since print_operand
2481 doesn't deal with the addresses we want to use. Fix this later. */
2483 rtx addr = XEXP (operands[1], 0);
2484 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2486 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2488 operands[1] = XEXP (addr, 0);
2489 gcc_assert (GET_CODE (operands[0]) == REG
2490 && GET_CODE (operands[1]) == REG);
2492 if (!reg_overlap_mentioned_p (high_reg, addr))
2494 /* No overlap between high target register and address
2495 register. (We do this in a non-obvious way to
2496 save a register file writeback) */
2497 if (GET_CODE (addr) == POST_INC)
2498 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2499 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2503 /* This is an undefined situation. We should load into the
2504 address register *and* update that register. Probably
2505 we don't need to handle this at all. */
2506 if (GET_CODE (addr) == POST_INC)
2507 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2508 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2511 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2513 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2515 operands[1] = XEXP (addr, 0);
2516 gcc_assert (GET_CODE (operands[0]) == REG
2517 && GET_CODE (operands[1]) == REG);
2519 if (!reg_overlap_mentioned_p (high_reg, addr))
2521 /* No overlap between high target register and address
2522 register. (We do this in a non-obvious way to
2523 save a register file writeback) */
2524 if (GET_CODE (addr) == PRE_INC)
2525 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2526 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2530 /* This is an undefined situation. We should load into the
2531 address register *and* update that register. Probably
2532 we don't need to handle this at all. */
2533 if (GET_CODE (addr) == PRE_INC)
2534 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2535 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2538 else if (GET_CODE (addr) == PLUS
2539 && GET_CODE (XEXP (addr, 0)) == MULT)
2542 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2544 if (!reg_overlap_mentioned_p (high_reg, addr))
2546 xoperands[0] = high_reg;
2547 xoperands[1] = XEXP (addr, 1);
2548 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2549 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2550 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2552 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2556 xoperands[0] = high_reg;
2557 xoperands[1] = XEXP (addr, 1);
2558 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2559 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2560 output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2562 return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2567 /* If an operand is an unoffsettable memory ref, find a register
2568 we can increment temporarily to make it refer to the second word. */
2570 if (optype0 == MEMOP)
2571 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2573 if (optype1 == MEMOP)
2574 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2576 /* Ok, we can do one word at a time.
2577 Normally we do the low-numbered word first.
2579 In either case, set up in LATEHALF the operands to use
2580 for the high-numbered word and in some cases alter the
2581 operands in OPERANDS to be suitable for the low-numbered word. */
2583 if (optype0 == REGOP)
2584 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2585 else if (optype0 == OFFSOP)
2586 latehalf[0] = adjust_address (operands[0], SImode, 4);
2588 latehalf[0] = operands[0];
2590 if (optype1 == REGOP)
2591 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2592 else if (optype1 == OFFSOP)
2593 latehalf[1] = adjust_address (operands[1], SImode, 4);
2594 else if (optype1 == CNSTOP)
2595 split_double (operands[1], &operands[1], &latehalf[1]);
2597 latehalf[1] = operands[1];
2599 /* If the first move would clobber the source of the second one,
2600 do them in the other order.
2602 This can happen in two cases:
2604 mem -> register where the first half of the destination register
2605 is the same register used in the memory's address. Reload
2606 can create such insns.
2608 mem in this case will be either register indirect or register
2609 indirect plus a valid offset.
2611 register -> register move where REGNO(dst) == REGNO(src + 1)
2612 someone (Tim/Tege?) claimed this can happen for parameter loads.
2614 Handle mem -> register case first. */
2615 if (optype0 == REGOP
2616 && (optype1 == MEMOP || optype1 == OFFSOP)
2617 && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2620 /* Do the late half first. */
2622 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2623 output_asm_insn (pa_singlemove_string (latehalf), latehalf);
2627 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2628 return pa_singlemove_string (operands);
2631 /* Now handle register -> register case. */
2632 if (optype0 == REGOP && optype1 == REGOP
2633 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2635 output_asm_insn (pa_singlemove_string (latehalf), latehalf);
2636 return pa_singlemove_string (operands);
2639 /* Normal case: do the two words, low-numbered first. */
2641 output_asm_insn (pa_singlemove_string (operands), operands);
2643 /* Make any unoffsettable addresses point at high-numbered word. */
2645 output_asm_insn ("ldo 4(%0),%0", &addreg0);
2647 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2650 output_asm_insn (pa_singlemove_string (latehalf), latehalf);
2652 /* Undo the adds we just did. */
2654 output_asm_insn ("ldo -4(%0),%0", &addreg0);
2656 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2662 pa_output_fp_move_double (rtx *operands)
2664 if (FP_REG_P (operands[0]))
2666 if (FP_REG_P (operands[1])
2667 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2668 output_asm_insn ("fcpy,dbl %f1,%0", operands);
2670 output_asm_insn ("fldd%F1 %1,%0", operands);
2672 else if (FP_REG_P (operands[1]))
2674 output_asm_insn ("fstd%F0 %1,%0", operands);
2680 gcc_assert (operands[1] == CONST0_RTX (GET_MODE (operands[0])));
2682 /* This is a pain. You have to be prepared to deal with an
2683 arbitrary address here including pre/post increment/decrement.
2685 so avoid this in the MD. */
2686 gcc_assert (GET_CODE (operands[0]) == REG);
2688 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2689 xoperands[0] = operands[0];
2690 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2695 /* Return a REG that occurs in ADDR with coefficient 1.
2696 ADDR can be effectively incremented by incrementing REG. */
2699 find_addr_reg (rtx addr)
2701 while (GET_CODE (addr) == PLUS)
2703 if (GET_CODE (XEXP (addr, 0)) == REG)
2704 addr = XEXP (addr, 0);
2705 else if (GET_CODE (XEXP (addr, 1)) == REG)
2706 addr = XEXP (addr, 1);
2707 else if (CONSTANT_P (XEXP (addr, 0)))
2708 addr = XEXP (addr, 1);
2709 else if (CONSTANT_P (XEXP (addr, 1)))
2710 addr = XEXP (addr, 0);
2714 gcc_assert (GET_CODE (addr) == REG);
2718 /* Emit code to perform a block move.
2720 OPERANDS[0] is the destination pointer as a REG, clobbered.
2721 OPERANDS[1] is the source pointer as a REG, clobbered.
2722 OPERANDS[2] is a register for temporary storage.
2723 OPERANDS[3] is a register for temporary storage.
2724 OPERANDS[4] is the size as a CONST_INT
2725 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2726 OPERANDS[6] is another temporary register. */
2729 pa_output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2731 int align = INTVAL (operands[5]);
2732 unsigned long n_bytes = INTVAL (operands[4]);
2734 /* We can't move more than a word at a time because the PA
2735 has no longer integer move insns. (Could use fp mem ops?) */
2736 if (align > (TARGET_64BIT ? 8 : 4))
2737 align = (TARGET_64BIT ? 8 : 4);
2739 /* Note that we know each loop below will execute at least twice
2740 (else we would have open-coded the copy). */
2744 /* Pre-adjust the loop counter. */
2745 operands[4] = GEN_INT (n_bytes - 16);
2746 output_asm_insn ("ldi %4,%2", operands);
2749 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2750 output_asm_insn ("ldd,ma 8(%1),%6", operands);
2751 output_asm_insn ("std,ma %3,8(%0)", operands);
2752 output_asm_insn ("addib,>= -16,%2,.-12", operands);
2753 output_asm_insn ("std,ma %6,8(%0)", operands);
2755 /* Handle the residual. There could be up to 7 bytes of
2756 residual to copy! */
2757 if (n_bytes % 16 != 0)
2759 operands[4] = GEN_INT (n_bytes % 8);
2760 if (n_bytes % 16 >= 8)
2761 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2762 if (n_bytes % 8 != 0)
2763 output_asm_insn ("ldd 0(%1),%6", operands);
2764 if (n_bytes % 16 >= 8)
2765 output_asm_insn ("std,ma %3,8(%0)", operands);
2766 if (n_bytes % 8 != 0)
2767 output_asm_insn ("stdby,e %6,%4(%0)", operands);
2772 /* Pre-adjust the loop counter. */
2773 operands[4] = GEN_INT (n_bytes - 8);
2774 output_asm_insn ("ldi %4,%2", operands);
2777 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2778 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2779 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2780 output_asm_insn ("addib,>= -8,%2,.-12", operands);
2781 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2783 /* Handle the residual. There could be up to 7 bytes of
2784 residual to copy! */
2785 if (n_bytes % 8 != 0)
2787 operands[4] = GEN_INT (n_bytes % 4);
2788 if (n_bytes % 8 >= 4)
2789 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2790 if (n_bytes % 4 != 0)
2791 output_asm_insn ("ldw 0(%1),%6", operands);
2792 if (n_bytes % 8 >= 4)
2793 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2794 if (n_bytes % 4 != 0)
2795 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2800 /* Pre-adjust the loop counter. */
2801 operands[4] = GEN_INT (n_bytes - 4);
2802 output_asm_insn ("ldi %4,%2", operands);
2805 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2806 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2807 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2808 output_asm_insn ("addib,>= -4,%2,.-12", operands);
2809 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2811 /* Handle the residual. */
2812 if (n_bytes % 4 != 0)
2814 if (n_bytes % 4 >= 2)
2815 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2816 if (n_bytes % 2 != 0)
2817 output_asm_insn ("ldb 0(%1),%6", operands);
2818 if (n_bytes % 4 >= 2)
2819 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2820 if (n_bytes % 2 != 0)
2821 output_asm_insn ("stb %6,0(%0)", operands);
2826 /* Pre-adjust the loop counter. */
2827 operands[4] = GEN_INT (n_bytes - 2);
2828 output_asm_insn ("ldi %4,%2", operands);
2831 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2832 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2833 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2834 output_asm_insn ("addib,>= -2,%2,.-12", operands);
2835 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2837 /* Handle the residual. */
2838 if (n_bytes % 2 != 0)
2840 output_asm_insn ("ldb 0(%1),%3", operands);
2841 output_asm_insn ("stb %3,0(%0)", operands);
2850 /* Count the number of insns necessary to handle this block move.
2852 Basic structure is the same as emit_block_move, except that we
2853 count insns rather than emit them. */
2856 compute_movmem_length (rtx insn)
2858 rtx pat = PATTERN (insn);
2859 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2860 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2861 unsigned int n_insns = 0;
2863 /* We can't move more than four bytes at a time because the PA
2864 has no longer integer move insns. (Could use fp mem ops?) */
2865 if (align > (TARGET_64BIT ? 8 : 4))
2866 align = (TARGET_64BIT ? 8 : 4);
2868 /* The basic copying loop. */
2872 if (n_bytes % (2 * align) != 0)
2874 if ((n_bytes % (2 * align)) >= align)
2877 if ((n_bytes % align) != 0)
2881 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2885 /* Emit code to perform a block clear.
2887 OPERANDS[0] is the destination pointer as a REG, clobbered.
2888 OPERANDS[1] is a register for temporary storage.
2889 OPERANDS[2] is the size as a CONST_INT
2890 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
2893 pa_output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2895 int align = INTVAL (operands[3]);
2896 unsigned long n_bytes = INTVAL (operands[2]);
2898 /* We can't clear more than a word at a time because the PA
2899 has no longer integer move insns. */
2900 if (align > (TARGET_64BIT ? 8 : 4))
2901 align = (TARGET_64BIT ? 8 : 4);
2903 /* Note that we know each loop below will execute at least twice
2904 (else we would have open-coded the copy). */
2908 /* Pre-adjust the loop counter. */
2909 operands[2] = GEN_INT (n_bytes - 16);
2910 output_asm_insn ("ldi %2,%1", operands);
2913 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2914 output_asm_insn ("addib,>= -16,%1,.-4", operands);
2915 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2917 /* Handle the residual. There could be up to 7 bytes of
2918 residual to copy! */
2919 if (n_bytes % 16 != 0)
2921 operands[2] = GEN_INT (n_bytes % 8);
2922 if (n_bytes % 16 >= 8)
2923 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2924 if (n_bytes % 8 != 0)
2925 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
2930 /* Pre-adjust the loop counter. */
2931 operands[2] = GEN_INT (n_bytes - 8);
2932 output_asm_insn ("ldi %2,%1", operands);
2935 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2936 output_asm_insn ("addib,>= -8,%1,.-4", operands);
2937 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2939 /* Handle the residual. There could be up to 7 bytes of
2940 residual to copy! */
2941 if (n_bytes % 8 != 0)
2943 operands[2] = GEN_INT (n_bytes % 4);
2944 if (n_bytes % 8 >= 4)
2945 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2946 if (n_bytes % 4 != 0)
2947 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
2952 /* Pre-adjust the loop counter. */
2953 operands[2] = GEN_INT (n_bytes - 4);
2954 output_asm_insn ("ldi %2,%1", operands);
2957 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2958 output_asm_insn ("addib,>= -4,%1,.-4", operands);
2959 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2961 /* Handle the residual. */
2962 if (n_bytes % 4 != 0)
2964 if (n_bytes % 4 >= 2)
2965 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2966 if (n_bytes % 2 != 0)
2967 output_asm_insn ("stb %%r0,0(%0)", operands);
2972 /* Pre-adjust the loop counter. */
2973 operands[2] = GEN_INT (n_bytes - 2);
2974 output_asm_insn ("ldi %2,%1", operands);
2977 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2978 output_asm_insn ("addib,>= -2,%1,.-4", operands);
2979 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2981 /* Handle the residual. */
2982 if (n_bytes % 2 != 0)
2983 output_asm_insn ("stb %%r0,0(%0)", operands);
2992 /* Count the number of insns necessary to handle this block move.
2994 Basic structure is the same as emit_block_move, except that we
2995 count insns rather than emit them. */
2998 compute_clrmem_length (rtx insn)
3000 rtx pat = PATTERN (insn);
3001 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
3002 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
3003 unsigned int n_insns = 0;
3005 /* We can't clear more than a word at a time because the PA
3006 has no longer integer move insns. */
3007 if (align > (TARGET_64BIT ? 8 : 4))
3008 align = (TARGET_64BIT ? 8 : 4);
3010 /* The basic loop. */
3014 if (n_bytes % (2 * align) != 0)
3016 if ((n_bytes % (2 * align)) >= align)
3019 if ((n_bytes % align) != 0)
3023 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3029 pa_output_and (rtx *operands)
3031 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3033 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3034 int ls0, ls1, ms0, p, len;
3036 for (ls0 = 0; ls0 < 32; ls0++)
3037 if ((mask & (1 << ls0)) == 0)
3040 for (ls1 = ls0; ls1 < 32; ls1++)
3041 if ((mask & (1 << ls1)) != 0)
3044 for (ms0 = ls1; ms0 < 32; ms0++)
3045 if ((mask & (1 << ms0)) == 0)
3048 gcc_assert (ms0 == 32);
3056 operands[2] = GEN_INT (len);
3057 return "{extru|extrw,u} %1,31,%2,%0";
3061 /* We could use this `depi' for the case above as well, but `depi'
3062 requires one more register file access than an `extru'. */
3067 operands[2] = GEN_INT (p);
3068 operands[3] = GEN_INT (len);
3069 return "{depi|depwi} 0,%2,%3,%0";
3073 return "and %1,%2,%0";
3076 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3077 storing the result in operands[0]. */
3079 pa_output_64bit_and (rtx *operands)
3081 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3083 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3084 int ls0, ls1, ms0, p, len;
3086 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
3087 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
3090 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
3091 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
3094 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
3095 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
3098 gcc_assert (ms0 == HOST_BITS_PER_WIDE_INT);
3100 if (ls1 == HOST_BITS_PER_WIDE_INT)
3106 operands[2] = GEN_INT (len);
3107 return "extrd,u %1,63,%2,%0";
3111 /* We could use this `depi' for the case above as well, but `depi'
3112 requires one more register file access than an `extru'. */
3117 operands[2] = GEN_INT (p);
3118 operands[3] = GEN_INT (len);
3119 return "depdi 0,%2,%3,%0";
3123 return "and %1,%2,%0";
3127 pa_output_ior (rtx *operands)
3129 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3130 int bs0, bs1, p, len;
3132 if (INTVAL (operands[2]) == 0)
3133 return "copy %1,%0";
3135 for (bs0 = 0; bs0 < 32; bs0++)
3136 if ((mask & (1 << bs0)) != 0)
3139 for (bs1 = bs0; bs1 < 32; bs1++)
3140 if ((mask & (1 << bs1)) == 0)
3143 gcc_assert (bs1 == 32 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
3148 operands[2] = GEN_INT (p);
3149 operands[3] = GEN_INT (len);
3150 return "{depi|depwi} -1,%2,%3,%0";
3153 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3154 storing the result in operands[0]. */
3156 pa_output_64bit_ior (rtx *operands)
3158 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3159 int bs0, bs1, p, len;
3161 if (INTVAL (operands[2]) == 0)
3162 return "copy %1,%0";
3164 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
3165 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
3168 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
3169 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
3172 gcc_assert (bs1 == HOST_BITS_PER_WIDE_INT
3173 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
3178 operands[2] = GEN_INT (p);
3179 operands[3] = GEN_INT (len);
3180 return "depdi -1,%2,%3,%0";
3183 /* Target hook for assembling integer objects. This code handles
3184 aligned SI and DI integers specially since function references
3185 must be preceded by P%. */
3188 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
3190 if (size == UNITS_PER_WORD
3192 && function_label_operand (x, VOIDmode))
3194 fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
3195 output_addr_const (asm_out_file, x);
3196 fputc ('\n', asm_out_file);
3199 return default_assemble_integer (x, size, aligned_p);
3202 /* Output an ascii string. */
3204 pa_output_ascii (FILE *file, const char *p, int size)
3208 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
3210 /* The HP assembler can only take strings of 256 characters at one
3211 time. This is a limitation on input line length, *not* the
3212 length of the string. Sigh. Even worse, it seems that the
3213 restriction is in number of input characters (see \xnn &
3214 \whatever). So we have to do this very carefully. */
3216 fputs ("\t.STRING \"", file);
3219 for (i = 0; i < size; i += 4)
3223 for (io = 0, co = 0; io < MIN (4, size - i); io++)
3225 register unsigned int c = (unsigned char) p[i + io];
3227 if (c == '\"' || c == '\\')
3228 partial_output[co++] = '\\';
3229 if (c >= ' ' && c < 0177)
3230 partial_output[co++] = c;
3234 partial_output[co++] = '\\';
3235 partial_output[co++] = 'x';
3236 hexd = c / 16 - 0 + '0';
3238 hexd -= '9' - 'a' + 1;
3239 partial_output[co++] = hexd;
3240 hexd = c % 16 - 0 + '0';
3242 hexd -= '9' - 'a' + 1;
3243 partial_output[co++] = hexd;
3246 if (chars_output + co > 243)
3248 fputs ("\"\n\t.STRING \"", file);
3251 fwrite (partial_output, 1, (size_t) co, file);
3255 fputs ("\"\n", file);
3258 /* Try to rewrite floating point comparisons & branches to avoid
3259 useless add,tr insns.
3261 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3262 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3263 first attempt to remove useless add,tr insns. It is zero
3264 for the second pass as reorg sometimes leaves bogus REG_DEAD
3267 When CHECK_NOTES is zero we can only eliminate add,tr insns
3268 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3271 remove_useless_addtr_insns (int check_notes)
3274 static int pass = 0;
3276 /* This is fairly cheap, so always run it when optimizing. */
3280 int fbranch_count = 0;
3282 /* Walk all the insns in this function looking for fcmp & fbranch
3283 instructions. Keep track of how many of each we find. */
3284 for (insn = get_insns (); insn; insn = next_insn (insn))
3288 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3289 if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3292 tmp = PATTERN (insn);
3294 /* It must be a set. */
3295 if (GET_CODE (tmp) != SET)
3298 /* If the destination is CCFP, then we've found an fcmp insn. */
3299 tmp = SET_DEST (tmp);
3300 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3306 tmp = PATTERN (insn);
3307 /* If this is an fbranch instruction, bump the fbranch counter. */
3308 if (GET_CODE (tmp) == SET
3309 && SET_DEST (tmp) == pc_rtx
3310 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3311 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3312 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3313 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3321 /* Find all floating point compare + branch insns. If possible,
3322 reverse the comparison & the branch to avoid add,tr insns. */
3323 for (insn = get_insns (); insn; insn = next_insn (insn))
3327 /* Ignore anything that isn't an INSN. */
3328 if (GET_CODE (insn) != INSN)
3331 tmp = PATTERN (insn);
3333 /* It must be a set. */
3334 if (GET_CODE (tmp) != SET)
3337 /* The destination must be CCFP, which is register zero. */
3338 tmp = SET_DEST (tmp);
3339 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3342 /* INSN should be a set of CCFP.
3344 See if the result of this insn is used in a reversed FP
3345 conditional branch. If so, reverse our condition and
3346 the branch. Doing so avoids useless add,tr insns. */
3347 next = next_insn (insn);
3350 /* Jumps, calls and labels stop our search. */
3351 if (GET_CODE (next) == JUMP_INSN
3352 || GET_CODE (next) == CALL_INSN
3353 || GET_CODE (next) == CODE_LABEL)
3356 /* As does another fcmp insn. */
3357 if (GET_CODE (next) == INSN
3358 && GET_CODE (PATTERN (next)) == SET
3359 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3360 && REGNO (SET_DEST (PATTERN (next))) == 0)
3363 next = next_insn (next);
3366 /* Is NEXT_INSN a branch? */
3368 && GET_CODE (next) == JUMP_INSN)
3370 rtx pattern = PATTERN (next);
3372 /* If it a reversed fp conditional branch (e.g. uses add,tr)
3373 and CCFP dies, then reverse our conditional and the branch
3374 to avoid the add,tr. */
3375 if (GET_CODE (pattern) == SET
3376 && SET_DEST (pattern) == pc_rtx
3377 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3378 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3379 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3380 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3381 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3382 && (fcmp_count == fbranch_count