1 /* Expand the basic unary and binary arithmetic operations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
29 /* Include insn-config.h before expr.h so that HAVE_conditional_move
30 is properly defined. */
31 #include "insn-config.h"
45 #include "basic-block.h"
48 /* Each optab contains info on how this target machine
49 can perform a particular operation
50 for all sizes and kinds of operands.
52 The operation to be performed is often specified
53 by passing one of these optabs as an argument.
55 See expr.h for documentation of these optabs. */
57 optab optab_table
[OTI_MAX
];
59 rtx libfunc_table
[LTI_MAX
];
61 /* Tables of patterns for converting one mode to another. */
62 convert_optab convert_optab_table
[CTI_MAX
];
64 /* Contains the optab used for each rtx code. */
65 optab code_to_optab
[NUM_RTX_CODE
+ 1];
67 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
68 gives the gen_function to make a branch to test that condition. */
70 rtxfun bcc_gen_fctn
[NUM_RTX_CODE
];
72 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
73 gives the insn code to make a store-condition insn
74 to test that condition. */
76 enum insn_code setcc_gen_code
[NUM_RTX_CODE
];
78 #ifdef HAVE_conditional_move
79 /* Indexed by the machine mode, gives the insn code to make a conditional
80 move insn. This is not indexed by the rtx-code like bcc_gen_fctn and
81 setcc_gen_code to cut down on the number of named patterns. Consider a day
82 when a lot more rtx codes are conditional (eg: for the ARM). */
84 enum insn_code movcc_gen_code
[NUM_MACHINE_MODES
];
87 /* The insn generating function can not take an rtx_code argument.
88 TRAP_RTX is used as an rtx argument. Its code is replaced with
89 the code to be used in the trap insn and all other fields are ignored. */
90 static GTY(()) rtx trap_rtx
;
92 static int add_equal_note (rtx
, rtx
, enum rtx_code
, rtx
, rtx
);
93 static rtx
widen_operand (rtx
, enum machine_mode
, enum machine_mode
, int,
95 static void prepare_cmp_insn (rtx
*, rtx
*, enum rtx_code
*, rtx
,
96 enum machine_mode
*, int *,
97 enum can_compare_purpose
);
98 static enum insn_code
can_fix_p (enum machine_mode
, enum machine_mode
, int,
100 static enum insn_code
can_float_p (enum machine_mode
, enum machine_mode
, int);
101 static optab
new_optab (void);
102 static convert_optab
new_convert_optab (void);
103 static inline optab
init_optab (enum rtx_code
);
104 static inline optab
init_optabv (enum rtx_code
);
105 static inline convert_optab
init_convert_optab (enum rtx_code
);
106 static void init_libfuncs (optab
, int, int, const char *, int);
107 static void init_integral_libfuncs (optab
, const char *, int);
108 static void init_floating_libfuncs (optab
, const char *, int);
109 static void init_interclass_conv_libfuncs (convert_optab
, const char *,
110 enum mode_class
, enum mode_class
);
111 static void init_intraclass_conv_libfuncs (convert_optab
, const char *,
112 enum mode_class
, bool);
113 static void emit_cmp_and_jump_insn_1 (rtx
, rtx
, enum machine_mode
,
114 enum rtx_code
, int, rtx
);
115 static void prepare_float_lib_cmp (rtx
*, rtx
*, enum rtx_code
*,
116 enum machine_mode
*, int *);
117 static rtx
widen_clz (enum machine_mode
, rtx
, rtx
);
118 static rtx
expand_parity (enum machine_mode
, rtx
, rtx
);
120 #ifndef HAVE_conditional_trap
121 #define HAVE_conditional_trap 0
122 #define gen_conditional_trap(a,b) (abort (), NULL_RTX)
125 /* Add a REG_EQUAL note to the last insn in INSNS. TARGET is being set to
126 the result of operation CODE applied to OP0 (and OP1 if it is a binary
129 If the last insn does not set TARGET, don't do anything, but return 1.
131 If a previous insn sets TARGET and TARGET is one of OP0 or OP1,
132 don't add the REG_EQUAL note but return 0. Our caller can then try
133 again, ensuring that TARGET is not one of the operands. */
136 add_equal_note (rtx insns
, rtx target
, enum rtx_code code
, rtx op0
, rtx op1
)
138 rtx last_insn
, insn
, set
;
143 || NEXT_INSN (insns
) == NULL_RTX
)
146 if (GET_RTX_CLASS (code
) != RTX_COMM_ARITH
147 && GET_RTX_CLASS (code
) != RTX_BIN_ARITH
148 && GET_RTX_CLASS (code
) != RTX_COMM_COMPARE
149 && GET_RTX_CLASS (code
) != RTX_COMPARE
150 && GET_RTX_CLASS (code
) != RTX_UNARY
)
153 if (GET_CODE (target
) == ZERO_EXTRACT
)
156 for (last_insn
= insns
;
157 NEXT_INSN (last_insn
) != NULL_RTX
;
158 last_insn
= NEXT_INSN (last_insn
))
161 set
= single_set (last_insn
);
165 if (! rtx_equal_p (SET_DEST (set
), target
)
166 /* For a STRICT_LOW_PART, the REG_NOTE applies to what is inside it. */
167 && (GET_CODE (SET_DEST (set
)) != STRICT_LOW_PART
168 || ! rtx_equal_p (XEXP (SET_DEST (set
), 0), target
)))
171 /* If TARGET is in OP0 or OP1, check if anything in SEQ sets TARGET
172 besides the last insn. */
173 if (reg_overlap_mentioned_p (target
, op0
)
174 || (op1
&& reg_overlap_mentioned_p (target
, op1
)))
176 insn
= PREV_INSN (last_insn
);
177 while (insn
!= NULL_RTX
)
179 if (reg_set_p (target
, insn
))
182 insn
= PREV_INSN (insn
);
186 if (GET_RTX_CLASS (code
) == RTX_UNARY
)
187 note
= gen_rtx_fmt_e (code
, GET_MODE (target
), copy_rtx (op0
));
189 note
= gen_rtx_fmt_ee (code
, GET_MODE (target
), copy_rtx (op0
), copy_rtx (op1
));
191 set_unique_reg_note (last_insn
, REG_EQUAL
, note
);
196 /* Widen OP to MODE and return the rtx for the widened operand. UNSIGNEDP
197 says whether OP is signed or unsigned. NO_EXTEND is nonzero if we need
198 not actually do a sign-extend or zero-extend, but can leave the
199 higher-order bits of the result rtx undefined, for example, in the case
200 of logical operations, but not right shifts. */
203 widen_operand (rtx op
, enum machine_mode mode
, enum machine_mode oldmode
,
204 int unsignedp
, int no_extend
)
208 /* If we don't have to extend and this is a constant, return it. */
209 if (no_extend
&& GET_MODE (op
) == VOIDmode
)
212 /* If we must extend do so. If OP is a SUBREG for a promoted object, also
213 extend since it will be more efficient to do so unless the signedness of
214 a promoted object differs from our extension. */
216 || (GET_CODE (op
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (op
)
217 && SUBREG_PROMOTED_UNSIGNED_P (op
) == unsignedp
))
218 return convert_modes (mode
, oldmode
, op
, unsignedp
);
220 /* If MODE is no wider than a single word, we return a paradoxical
222 if (GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
)
223 return gen_rtx_SUBREG (mode
, force_reg (GET_MODE (op
), op
), 0);
225 /* Otherwise, get an object of MODE, clobber it, and set the low-order
228 result
= gen_reg_rtx (mode
);
229 emit_insn (gen_rtx_CLOBBER (VOIDmode
, result
));
230 emit_move_insn (gen_lowpart (GET_MODE (op
), result
), op
);
234 /* Return the optab used for computing the operation given by
235 the tree code, CODE. This function is not always usable (for
236 example, it cannot give complete results for multiplication
237 or division) but probably ought to be relied on more widely
238 throughout the expander. */
240 optab_for_tree_code (enum tree_code code
, tree type
)
252 return one_cmpl_optab
;
261 return TYPE_UNSIGNED (type
) ? umod_optab
: smod_optab
;
269 return TYPE_UNSIGNED (type
) ? udiv_optab
: sdiv_optab
;
275 return TYPE_UNSIGNED (type
) ? lshr_optab
: ashr_optab
;
284 return TYPE_UNSIGNED (type
) ? umax_optab
: smax_optab
;
287 return TYPE_UNSIGNED (type
) ? umin_optab
: smin_optab
;
289 case REALIGN_STORE_EXPR
:
290 return vec_realign_store_optab
;
292 case REALIGN_LOAD_EXPR
:
293 return vec_realign_load_optab
;
299 trapv
= flag_trapv
&& INTEGRAL_TYPE_P (type
) && !TYPE_UNSIGNED (type
);
303 return trapv
? addv_optab
: add_optab
;
306 return trapv
? subv_optab
: sub_optab
;
309 return trapv
? smulv_optab
: smul_optab
;
312 return trapv
? negv_optab
: neg_optab
;
315 return trapv
? absv_optab
: abs_optab
;
323 /* Generate code to perform an operation specified by TERNARY_OPTAB
324 on operands OP0, OP1 and OP2, with result having machine-mode MODE.
326 UNSIGNEDP is for the case where we have to widen the operands
327 to perform the operation. It says to use zero-extension.
329 If TARGET is nonzero, the value
330 is generated there, if it is convenient to do so.
331 In all cases an rtx is returned for the locus of the value;
332 this may or may not be TARGET. */
335 expand_ternary_op (enum machine_mode mode
, optab ternary_optab
, rtx op0
,
336 rtx op1
, rtx op2
, rtx target
, int unsignedp
)
338 int icode
= (int) ternary_optab
->handlers
[(int) mode
].insn_code
;
339 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
340 enum machine_mode mode1
= insn_data
[icode
].operand
[2].mode
;
341 enum machine_mode mode2
= insn_data
[icode
].operand
[3].mode
;
344 rtx xop0
= op0
, xop1
= op1
, xop2
= op2
;
346 if (ternary_optab
->handlers
[(int) mode
].insn_code
== CODE_FOR_nothing
)
350 || ! (*insn_data
[icode
].operand
[0].predicate
) (target
, mode
))
351 temp
= gen_reg_rtx (mode
);
355 /* In case the insn wants input operands in modes different from
356 those of the actual operands, convert the operands. It would
357 seem that we don't need to convert CONST_INTs, but we do, so
358 that they're properly zero-extended, sign-extended or truncated
361 if (GET_MODE (op0
) != mode0
&& mode0
!= VOIDmode
)
362 xop0
= convert_modes (mode0
,
363 GET_MODE (op0
) != VOIDmode
368 if (GET_MODE (op1
) != mode1
&& mode1
!= VOIDmode
)
369 xop1
= convert_modes (mode1
,
370 GET_MODE (op1
) != VOIDmode
375 if (GET_MODE (op2
) != mode2
&& mode2
!= VOIDmode
)
376 xop2
= convert_modes (mode2
,
377 GET_MODE (op2
) != VOIDmode
382 /* Now, if insn's predicates don't allow our operands, put them into
385 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
)
386 && mode0
!= VOIDmode
)
387 xop0
= copy_to_mode_reg (mode0
, xop0
);
389 if (! (*insn_data
[icode
].operand
[2].predicate
) (xop1
, mode1
)
390 && mode1
!= VOIDmode
)
391 xop1
= copy_to_mode_reg (mode1
, xop1
);
393 if (! (*insn_data
[icode
].operand
[3].predicate
) (xop2
, mode2
)
394 && mode2
!= VOIDmode
)
395 xop2
= copy_to_mode_reg (mode2
, xop2
);
397 pat
= GEN_FCN (icode
) (temp
, xop0
, xop1
, xop2
);
404 /* Like expand_binop, but return a constant rtx if the result can be
405 calculated at compile time. The arguments and return value are
406 otherwise the same as for expand_binop. */
409 simplify_expand_binop (enum machine_mode mode
, optab binoptab
,
410 rtx op0
, rtx op1
, rtx target
, int unsignedp
,
411 enum optab_methods methods
)
413 if (CONSTANT_P (op0
) && CONSTANT_P (op1
))
414 return simplify_gen_binary (binoptab
->code
, mode
, op0
, op1
);
416 return expand_binop (mode
, binoptab
, op0
, op1
, target
, unsignedp
, methods
);
419 /* Like simplify_expand_binop, but always put the result in TARGET.
420 Return true if the expansion succeeded. */
423 force_expand_binop (enum machine_mode mode
, optab binoptab
,
424 rtx op0
, rtx op1
, rtx target
, int unsignedp
,
425 enum optab_methods methods
)
427 rtx x
= simplify_expand_binop (mode
, binoptab
, op0
, op1
,
428 target
, unsignedp
, methods
);
432 emit_move_insn (target
, x
);
436 /* This subroutine of expand_doubleword_shift handles the cases in which
437 the effective shift value is >= BITS_PER_WORD. The arguments and return
438 value are the same as for the parent routine, except that SUPERWORD_OP1
439 is the shift count to use when shifting OUTOF_INPUT into INTO_TARGET.
440 INTO_TARGET may be null if the caller has decided to calculate it. */
443 expand_superword_shift (optab binoptab
, rtx outof_input
, rtx superword_op1
,
444 rtx outof_target
, rtx into_target
,
445 int unsignedp
, enum optab_methods methods
)
447 if (into_target
!= 0)
448 if (!force_expand_binop (word_mode
, binoptab
, outof_input
, superword_op1
,
449 into_target
, unsignedp
, methods
))
452 if (outof_target
!= 0)
454 /* For a signed right shift, we must fill OUTOF_TARGET with copies
455 of the sign bit, otherwise we must fill it with zeros. */
456 if (binoptab
!= ashr_optab
)
457 emit_move_insn (outof_target
, CONST0_RTX (word_mode
));
459 if (!force_expand_binop (word_mode
, binoptab
,
460 outof_input
, GEN_INT (BITS_PER_WORD
- 1),
461 outof_target
, unsignedp
, methods
))
467 /* This subroutine of expand_doubleword_shift handles the cases in which
468 the effective shift value is < BITS_PER_WORD. The arguments and return
469 value are the same as for the parent routine. */
472 expand_subword_shift (enum machine_mode op1_mode
, optab binoptab
,
473 rtx outof_input
, rtx into_input
, rtx op1
,
474 rtx outof_target
, rtx into_target
,
475 int unsignedp
, enum optab_methods methods
,
476 unsigned HOST_WIDE_INT shift_mask
)
478 optab reverse_unsigned_shift
, unsigned_shift
;
481 reverse_unsigned_shift
= (binoptab
== ashl_optab
? lshr_optab
: ashl_optab
);
482 unsigned_shift
= (binoptab
== ashl_optab
? ashl_optab
: lshr_optab
);
484 /* The low OP1 bits of INTO_TARGET come from the high bits of OUTOF_INPUT.
485 We therefore need to shift OUTOF_INPUT by (BITS_PER_WORD - OP1) bits in
486 the opposite direction to BINOPTAB. */
487 if (CONSTANT_P (op1
) || shift_mask
>= BITS_PER_WORD
)
489 carries
= outof_input
;
490 tmp
= immed_double_const (BITS_PER_WORD
, 0, op1_mode
);
491 tmp
= simplify_expand_binop (op1_mode
, sub_optab
, tmp
, op1
,
496 /* We must avoid shifting by BITS_PER_WORD bits since that is either
497 the same as a zero shift (if shift_mask == BITS_PER_WORD - 1) or
498 has unknown behavior. Do a single shift first, then shift by the
499 remainder. It's OK to use ~OP1 as the remainder if shift counts
500 are truncated to the mode size. */
501 carries
= expand_binop (word_mode
, reverse_unsigned_shift
,
502 outof_input
, const1_rtx
, 0, unsignedp
, methods
);
503 if (shift_mask
== BITS_PER_WORD
- 1)
505 tmp
= immed_double_const (-1, -1, op1_mode
);
506 tmp
= simplify_expand_binop (op1_mode
, xor_optab
, op1
, tmp
,
511 tmp
= immed_double_const (BITS_PER_WORD
- 1, 0, op1_mode
);
512 tmp
= simplify_expand_binop (op1_mode
, sub_optab
, tmp
, op1
,
516 if (tmp
== 0 || carries
== 0)
518 carries
= expand_binop (word_mode
, reverse_unsigned_shift
,
519 carries
, tmp
, 0, unsignedp
, methods
);
523 /* Shift INTO_INPUT logically by OP1. This is the last use of INTO_INPUT
524 so the result can go directly into INTO_TARGET if convenient. */
525 tmp
= expand_binop (word_mode
, unsigned_shift
, into_input
, op1
,
526 into_target
, unsignedp
, methods
);
530 /* Now OR in the bits carried over from OUTOF_INPUT. */
531 if (!force_expand_binop (word_mode
, ior_optab
, tmp
, carries
,
532 into_target
, unsignedp
, methods
))
535 /* Use a standard word_mode shift for the out-of half. */
536 if (outof_target
!= 0)
537 if (!force_expand_binop (word_mode
, binoptab
, outof_input
, op1
,
538 outof_target
, unsignedp
, methods
))
545 #ifdef HAVE_conditional_move
546 /* Try implementing expand_doubleword_shift using conditional moves.
547 The shift is by < BITS_PER_WORD if (CMP_CODE CMP1 CMP2) is true,
548 otherwise it is by >= BITS_PER_WORD. SUBWORD_OP1 and SUPERWORD_OP1
549 are the shift counts to use in the former and latter case. All other
550 arguments are the same as the parent routine. */
553 expand_doubleword_shift_condmove (enum machine_mode op1_mode
, optab binoptab
,
554 enum rtx_code cmp_code
, rtx cmp1
, rtx cmp2
,
555 rtx outof_input
, rtx into_input
,
556 rtx subword_op1
, rtx superword_op1
,
557 rtx outof_target
, rtx into_target
,
558 int unsignedp
, enum optab_methods methods
,
559 unsigned HOST_WIDE_INT shift_mask
)
561 rtx outof_superword
, into_superword
;
563 /* Put the superword version of the output into OUTOF_SUPERWORD and
565 outof_superword
= outof_target
!= 0 ? gen_reg_rtx (word_mode
) : 0;
566 if (outof_target
!= 0 && subword_op1
== superword_op1
)
568 /* The value INTO_TARGET >> SUBWORD_OP1, which we later store in
569 OUTOF_TARGET, is the same as the value of INTO_SUPERWORD. */
570 into_superword
= outof_target
;
571 if (!expand_superword_shift (binoptab
, outof_input
, superword_op1
,
572 outof_superword
, 0, unsignedp
, methods
))
577 into_superword
= gen_reg_rtx (word_mode
);
578 if (!expand_superword_shift (binoptab
, outof_input
, superword_op1
,
579 outof_superword
, into_superword
,
584 /* Put the subword version directly in OUTOF_TARGET and INTO_TARGET. */
585 if (!expand_subword_shift (op1_mode
, binoptab
,
586 outof_input
, into_input
, subword_op1
,
587 outof_target
, into_target
,
588 unsignedp
, methods
, shift_mask
))
591 /* Select between them. Do the INTO half first because INTO_SUPERWORD
592 might be the current value of OUTOF_TARGET. */
593 if (!emit_conditional_move (into_target
, cmp_code
, cmp1
, cmp2
, op1_mode
,
594 into_target
, into_superword
, word_mode
, false))
597 if (outof_target
!= 0)
598 if (!emit_conditional_move (outof_target
, cmp_code
, cmp1
, cmp2
, op1_mode
,
599 outof_target
, outof_superword
,
607 /* Expand a doubleword shift (ashl, ashr or lshr) using word-mode shifts.
608 OUTOF_INPUT and INTO_INPUT are the two word-sized halves of the first
609 input operand; the shift moves bits in the direction OUTOF_INPUT->
610 INTO_TARGET. OUTOF_TARGET and INTO_TARGET are the equivalent words
611 of the target. OP1 is the shift count and OP1_MODE is its mode.
612 If OP1 is constant, it will have been truncated as appropriate
613 and is known to be nonzero.
615 If SHIFT_MASK is zero, the result of word shifts is undefined when the
616 shift count is outside the range [0, BITS_PER_WORD). This routine must
617 avoid generating such shifts for OP1s in the range [0, BITS_PER_WORD * 2).
619 If SHIFT_MASK is nonzero, all word-mode shift counts are effectively
620 masked by it and shifts in the range [BITS_PER_WORD, SHIFT_MASK) will
621 fill with zeros or sign bits as appropriate.
623 If SHIFT_MASK is BITS_PER_WORD - 1, this routine will synthesize
624 a doubleword shift whose equivalent mask is BITS_PER_WORD * 2 - 1.
625 Doing this preserves semantics required by SHIFT_COUNT_TRUNCATED.
626 In all other cases, shifts by values outside [0, BITS_PER_UNIT * 2)
629 BINOPTAB, UNSIGNEDP and METHODS are as for expand_binop. This function
630 may not use INTO_INPUT after modifying INTO_TARGET, and similarly for
631 OUTOF_INPUT and OUTOF_TARGET. OUTOF_TARGET can be null if the parent
632 function wants to calculate it itself.
634 Return true if the shift could be successfully synthesized. */
637 expand_doubleword_shift (enum machine_mode op1_mode
, optab binoptab
,
638 rtx outof_input
, rtx into_input
, rtx op1
,
639 rtx outof_target
, rtx into_target
,
640 int unsignedp
, enum optab_methods methods
,
641 unsigned HOST_WIDE_INT shift_mask
)
643 rtx superword_op1
, tmp
, cmp1
, cmp2
;
644 rtx subword_label
, done_label
;
645 enum rtx_code cmp_code
;
647 /* See if word-mode shifts by BITS_PER_WORD...BITS_PER_WORD * 2 - 1 will
648 fill the result with sign or zero bits as appropriate. If so, the value
649 of OUTOF_TARGET will always be (SHIFT OUTOF_INPUT OP1). Recursively call
650 this routine to calculate INTO_TARGET (which depends on both OUTOF_INPUT
651 and INTO_INPUT), then emit code to set up OUTOF_TARGET.
653 This isn't worthwhile for constant shifts since the optimizers will
654 cope better with in-range shift counts. */
655 if (shift_mask
>= BITS_PER_WORD
657 && !CONSTANT_P (op1
))
659 if (!expand_doubleword_shift (op1_mode
, binoptab
,
660 outof_input
, into_input
, op1
,
662 unsignedp
, methods
, shift_mask
))
664 if (!force_expand_binop (word_mode
, binoptab
, outof_input
, op1
,
665 outof_target
, unsignedp
, methods
))
670 /* Set CMP_CODE, CMP1 and CMP2 so that the rtx (CMP_CODE CMP1 CMP2)
671 is true when the effective shift value is less than BITS_PER_WORD.
672 Set SUPERWORD_OP1 to the shift count that should be used to shift
673 OUTOF_INPUT into INTO_TARGET when the condition is false. */
674 tmp
= immed_double_const (BITS_PER_WORD
, 0, op1_mode
);
675 if (!CONSTANT_P (op1
) && shift_mask
== BITS_PER_WORD
- 1)
677 /* Set CMP1 to OP1 & BITS_PER_WORD. The result is zero iff OP1
678 is a subword shift count. */
679 cmp1
= simplify_expand_binop (op1_mode
, and_optab
, op1
, tmp
,
681 cmp2
= CONST0_RTX (op1_mode
);
687 /* Set CMP1 to OP1 - BITS_PER_WORD. */
688 cmp1
= simplify_expand_binop (op1_mode
, sub_optab
, op1
, tmp
,
690 cmp2
= CONST0_RTX (op1_mode
);
692 superword_op1
= cmp1
;
697 /* If we can compute the condition at compile time, pick the
698 appropriate subroutine. */
699 tmp
= simplify_relational_operation (cmp_code
, SImode
, op1_mode
, cmp1
, cmp2
);
700 if (tmp
!= 0 && GET_CODE (tmp
) == CONST_INT
)
702 if (tmp
== const0_rtx
)
703 return expand_superword_shift (binoptab
, outof_input
, superword_op1
,
704 outof_target
, into_target
,
707 return expand_subword_shift (op1_mode
, binoptab
,
708 outof_input
, into_input
, op1
,
709 outof_target
, into_target
,
710 unsignedp
, methods
, shift_mask
);
713 #ifdef HAVE_conditional_move
714 /* Try using conditional moves to generate straight-line code. */
716 rtx start
= get_last_insn ();
717 if (expand_doubleword_shift_condmove (op1_mode
, binoptab
,
718 cmp_code
, cmp1
, cmp2
,
719 outof_input
, into_input
,
721 outof_target
, into_target
,
722 unsignedp
, methods
, shift_mask
))
724 delete_insns_since (start
);
728 /* As a last resort, use branches to select the correct alternative. */
729 subword_label
= gen_label_rtx ();
730 done_label
= gen_label_rtx ();
732 do_compare_rtx_and_jump (cmp1
, cmp2
, cmp_code
, false, op1_mode
,
733 0, 0, subword_label
);
735 if (!expand_superword_shift (binoptab
, outof_input
, superword_op1
,
736 outof_target
, into_target
,
740 emit_jump_insn (gen_jump (done_label
));
742 emit_label (subword_label
);
744 if (!expand_subword_shift (op1_mode
, binoptab
,
745 outof_input
, into_input
, op1
,
746 outof_target
, into_target
,
747 unsignedp
, methods
, shift_mask
))
750 emit_label (done_label
);
754 /* Wrapper around expand_binop which takes an rtx code to specify
755 the operation to perform, not an optab pointer. All other
756 arguments are the same. */
758 expand_simple_binop (enum machine_mode mode
, enum rtx_code code
, rtx op0
,
759 rtx op1
, rtx target
, int unsignedp
,
760 enum optab_methods methods
)
762 optab binop
= code_to_optab
[(int) code
];
766 return expand_binop (mode
, binop
, op0
, op1
, target
, unsignedp
, methods
);
769 /* Generate code to perform an operation specified by BINOPTAB
770 on operands OP0 and OP1, with result having machine-mode MODE.
772 UNSIGNEDP is for the case where we have to widen the operands
773 to perform the operation. It says to use zero-extension.
775 If TARGET is nonzero, the value
776 is generated there, if it is convenient to do so.
777 In all cases an rtx is returned for the locus of the value;
778 this may or may not be TARGET. */
781 expand_binop (enum machine_mode mode
, optab binoptab
, rtx op0
, rtx op1
,
782 rtx target
, int unsignedp
, enum optab_methods methods
)
784 enum optab_methods next_methods
785 = (methods
== OPTAB_LIB
|| methods
== OPTAB_LIB_WIDEN
786 ? OPTAB_WIDEN
: methods
);
787 enum mode_class
class;
788 enum machine_mode wider_mode
;
790 int commutative_op
= 0;
791 int shift_op
= (binoptab
->code
== ASHIFT
792 || binoptab
->code
== ASHIFTRT
793 || binoptab
->code
== LSHIFTRT
794 || binoptab
->code
== ROTATE
795 || binoptab
->code
== ROTATERT
);
796 rtx entry_last
= get_last_insn ();
799 class = GET_MODE_CLASS (mode
);
803 /* Load duplicate non-volatile operands once. */
804 if (rtx_equal_p (op0
, op1
) && ! volatile_refs_p (op0
))
806 op0
= force_not_mem (op0
);
811 op0
= force_not_mem (op0
);
812 op1
= force_not_mem (op1
);
816 /* If subtracting an integer constant, convert this into an addition of
817 the negated constant. */
819 if (binoptab
== sub_optab
&& GET_CODE (op1
) == CONST_INT
)
821 op1
= negate_rtx (mode
, op1
);
822 binoptab
= add_optab
;
825 /* If we are inside an appropriately-short loop and we are optimizing,
826 force expensive constants into a register. */
827 if (CONSTANT_P (op0
) && optimize
828 && rtx_cost (op0
, binoptab
->code
) > COSTS_N_INSNS (1))
829 op0
= force_reg (mode
, op0
);
831 if (CONSTANT_P (op1
) && optimize
832 && ! shift_op
&& rtx_cost (op1
, binoptab
->code
) > COSTS_N_INSNS (1))
833 op1
= force_reg (mode
, op1
);
835 /* Record where to delete back to if we backtrack. */
836 last
= get_last_insn ();
838 /* If operation is commutative,
839 try to make the first operand a register.
840 Even better, try to make it the same as the target.
841 Also try to make the last operand a constant. */
842 if (GET_RTX_CLASS (binoptab
->code
) == RTX_COMM_ARITH
843 || binoptab
== smul_widen_optab
844 || binoptab
== umul_widen_optab
845 || binoptab
== smul_highpart_optab
846 || binoptab
== umul_highpart_optab
)
850 if (((target
== 0 || REG_P (target
))
854 : rtx_equal_p (op1
, target
))
855 || GET_CODE (op0
) == CONST_INT
)
863 /* If we can do it with a three-operand insn, do so. */
865 if (methods
!= OPTAB_MUST_WIDEN
866 && binoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
868 int icode
= (int) binoptab
->handlers
[(int) mode
].insn_code
;
869 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
870 enum machine_mode mode1
= insn_data
[icode
].operand
[2].mode
;
872 rtx xop0
= op0
, xop1
= op1
;
877 temp
= gen_reg_rtx (mode
);
879 /* If it is a commutative operator and the modes would match
880 if we would swap the operands, we can save the conversions. */
883 if (GET_MODE (op0
) != mode0
&& GET_MODE (op1
) != mode1
884 && GET_MODE (op0
) == mode1
&& GET_MODE (op1
) == mode0
)
888 tmp
= op0
; op0
= op1
; op1
= tmp
;
889 tmp
= xop0
; xop0
= xop1
; xop1
= tmp
;
893 /* In case the insn wants input operands in modes different from
894 those of the actual operands, convert the operands. It would
895 seem that we don't need to convert CONST_INTs, but we do, so
896 that they're properly zero-extended, sign-extended or truncated
899 if (GET_MODE (op0
) != mode0
&& mode0
!= VOIDmode
)
900 xop0
= convert_modes (mode0
,
901 GET_MODE (op0
) != VOIDmode
906 if (GET_MODE (op1
) != mode1
&& mode1
!= VOIDmode
)
907 xop1
= convert_modes (mode1
,
908 GET_MODE (op1
) != VOIDmode
913 /* Now, if insn's predicates don't allow our operands, put them into
916 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
)
917 && mode0
!= VOIDmode
)
918 xop0
= copy_to_mode_reg (mode0
, xop0
);
920 if (! (*insn_data
[icode
].operand
[2].predicate
) (xop1
, mode1
)
921 && mode1
!= VOIDmode
)
922 xop1
= copy_to_mode_reg (mode1
, xop1
);
924 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, mode
))
925 temp
= gen_reg_rtx (mode
);
927 pat
= GEN_FCN (icode
) (temp
, xop0
, xop1
);
930 /* If PAT is composed of more than one insn, try to add an appropriate
931 REG_EQUAL note to it. If we can't because TEMP conflicts with an
932 operand, call ourselves again, this time without a target. */
933 if (INSN_P (pat
) && NEXT_INSN (pat
) != NULL_RTX
934 && ! add_equal_note (pat
, temp
, binoptab
->code
, xop0
, xop1
))
936 delete_insns_since (last
);
937 return expand_binop (mode
, binoptab
, op0
, op1
, NULL_RTX
,
945 delete_insns_since (last
);
948 /* If this is a multiply, see if we can do a widening operation that
949 takes operands of this mode and makes a wider mode. */
951 if (binoptab
== smul_optab
&& GET_MODE_WIDER_MODE (mode
) != VOIDmode
952 && (((unsignedp
? umul_widen_optab
: smul_widen_optab
)
953 ->handlers
[(int) GET_MODE_WIDER_MODE (mode
)].insn_code
)
954 != CODE_FOR_nothing
))
956 temp
= expand_binop (GET_MODE_WIDER_MODE (mode
),
957 unsignedp
? umul_widen_optab
: smul_widen_optab
,
958 op0
, op1
, NULL_RTX
, unsignedp
, OPTAB_DIRECT
);
962 if (GET_MODE_CLASS (mode
) == MODE_INT
)
963 return gen_lowpart (mode
, temp
);
965 return convert_to_mode (mode
, temp
, unsignedp
);
969 /* Look for a wider mode of the same class for which we think we
970 can open-code the operation. Check for a widening multiply at the
971 wider mode as well. */
973 if ((class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
974 && methods
!= OPTAB_DIRECT
&& methods
!= OPTAB_LIB
)
975 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
976 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
978 if (binoptab
->handlers
[(int) wider_mode
].insn_code
!= CODE_FOR_nothing
979 || (binoptab
== smul_optab
980 && GET_MODE_WIDER_MODE (wider_mode
) != VOIDmode
981 && (((unsignedp
? umul_widen_optab
: smul_widen_optab
)
982 ->handlers
[(int) GET_MODE_WIDER_MODE (wider_mode
)].insn_code
)
983 != CODE_FOR_nothing
)))
985 rtx xop0
= op0
, xop1
= op1
;
988 /* For certain integer operations, we need not actually extend
989 the narrow operands, as long as we will truncate
990 the results to the same narrowness. */
992 if ((binoptab
== ior_optab
|| binoptab
== and_optab
993 || binoptab
== xor_optab
994 || binoptab
== add_optab
|| binoptab
== sub_optab
995 || binoptab
== smul_optab
|| binoptab
== ashl_optab
)
996 && class == MODE_INT
)
999 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
, no_extend
);
1001 /* The second operand of a shift must always be extended. */
1002 xop1
= widen_operand (xop1
, wider_mode
, mode
, unsignedp
,
1003 no_extend
&& binoptab
!= ashl_optab
);
1005 temp
= expand_binop (wider_mode
, binoptab
, xop0
, xop1
, NULL_RTX
,
1006 unsignedp
, OPTAB_DIRECT
);
1009 if (class != MODE_INT
)
1012 target
= gen_reg_rtx (mode
);
1013 convert_move (target
, temp
, 0);
1017 return gen_lowpart (mode
, temp
);
1020 delete_insns_since (last
);
1024 /* These can be done a word at a time. */
1025 if ((binoptab
== and_optab
|| binoptab
== ior_optab
|| binoptab
== xor_optab
)
1026 && class == MODE_INT
1027 && GET_MODE_SIZE (mode
) > UNITS_PER_WORD
1028 && binoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
1034 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1035 won't be accurate, so use a new target. */
1036 if (target
== 0 || target
== op0
|| target
== op1
)
1037 target
= gen_reg_rtx (mode
);
1041 /* Do the actual arithmetic. */
1042 for (i
= 0; i
< GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
; i
++)
1044 rtx target_piece
= operand_subword (target
, i
, 1, mode
);
1045 rtx x
= expand_binop (word_mode
, binoptab
,
1046 operand_subword_force (op0
, i
, mode
),
1047 operand_subword_force (op1
, i
, mode
),
1048 target_piece
, unsignedp
, next_methods
);
1053 if (target_piece
!= x
)
1054 emit_move_insn (target_piece
, x
);
1057 insns
= get_insns ();
1060 if (i
== GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
)
1062 if (binoptab
->code
!= UNKNOWN
)
1064 = gen_rtx_fmt_ee (binoptab
->code
, mode
,
1065 copy_rtx (op0
), copy_rtx (op1
));
1069 emit_no_conflict_block (insns
, target
, op0
, op1
, equiv_value
);
1074 /* Synthesize double word shifts from single word shifts. */
1075 if ((binoptab
== lshr_optab
|| binoptab
== ashl_optab
1076 || binoptab
== ashr_optab
)
1077 && class == MODE_INT
1078 && (GET_CODE (op1
) == CONST_INT
|| !optimize_size
)
1079 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
1080 && binoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1081 && ashl_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1082 && lshr_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
1084 unsigned HOST_WIDE_INT shift_mask
, double_shift_mask
;
1085 enum machine_mode op1_mode
;
1087 double_shift_mask
= targetm
.shift_truncation_mask (mode
);
1088 shift_mask
= targetm
.shift_truncation_mask (word_mode
);
1089 op1_mode
= GET_MODE (op1
) != VOIDmode
? GET_MODE (op1
) : word_mode
;
1091 /* Apply the truncation to constant shifts. */
1092 if (double_shift_mask
> 0 && GET_CODE (op1
) == CONST_INT
)
1093 op1
= GEN_INT (INTVAL (op1
) & double_shift_mask
);
1095 if (op1
== CONST0_RTX (op1_mode
))
1098 /* Make sure that this is a combination that expand_doubleword_shift
1099 can handle. See the comments there for details. */
1100 if (double_shift_mask
== 0
1101 || (shift_mask
== BITS_PER_WORD
- 1
1102 && double_shift_mask
== BITS_PER_WORD
* 2 - 1))
1104 rtx insns
, equiv_value
;
1105 rtx into_target
, outof_target
;
1106 rtx into_input
, outof_input
;
1107 int left_shift
, outof_word
;
1109 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1110 won't be accurate, so use a new target. */
1111 if (target
== 0 || target
== op0
|| target
== op1
)
1112 target
= gen_reg_rtx (mode
);
1116 /* OUTOF_* is the word we are shifting bits away from, and
1117 INTO_* is the word that we are shifting bits towards, thus
1118 they differ depending on the direction of the shift and
1119 WORDS_BIG_ENDIAN. */
1121 left_shift
= binoptab
== ashl_optab
;
1122 outof_word
= left_shift
^ ! WORDS_BIG_ENDIAN
;
1124 outof_target
= operand_subword (target
, outof_word
, 1, mode
);
1125 into_target
= operand_subword (target
, 1 - outof_word
, 1, mode
);
1127 outof_input
= operand_subword_force (op0
, outof_word
, mode
);
1128 into_input
= operand_subword_force (op0
, 1 - outof_word
, mode
);
1130 if (expand_doubleword_shift (op1_mode
, binoptab
,
1131 outof_input
, into_input
, op1
,
1132 outof_target
, into_target
,
1133 unsignedp
, methods
, shift_mask
))
1135 insns
= get_insns ();
1138 equiv_value
= gen_rtx_fmt_ee (binoptab
->code
, mode
, op0
, op1
);
1139 emit_no_conflict_block (insns
, target
, op0
, op1
, equiv_value
);
1146 /* Synthesize double word rotates from single word shifts. */
1147 if ((binoptab
== rotl_optab
|| binoptab
== rotr_optab
)
1148 && class == MODE_INT
1149 && GET_CODE (op1
) == CONST_INT
1150 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
1151 && ashl_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1152 && lshr_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
1154 rtx insns
, equiv_value
;
1155 rtx into_target
, outof_target
;
1156 rtx into_input
, outof_input
;
1158 int shift_count
, left_shift
, outof_word
;
1160 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1161 won't be accurate, so use a new target. Do this also if target is not
1162 a REG, first because having a register instead may open optimization
1163 opportunities, and second because if target and op0 happen to be MEMs
1164 designating the same location, we would risk clobbering it too early
1165 in the code sequence we generate below. */
1166 if (target
== 0 || target
== op0
|| target
== op1
|| ! REG_P (target
))
1167 target
= gen_reg_rtx (mode
);
1171 shift_count
= INTVAL (op1
);
1173 /* OUTOF_* is the word we are shifting bits away from, and
1174 INTO_* is the word that we are shifting bits towards, thus
1175 they differ depending on the direction of the shift and
1176 WORDS_BIG_ENDIAN. */
1178 left_shift
= (binoptab
== rotl_optab
);
1179 outof_word
= left_shift
^ ! WORDS_BIG_ENDIAN
;
1181 outof_target
= operand_subword (target
, outof_word
, 1, mode
);
1182 into_target
= operand_subword (target
, 1 - outof_word
, 1, mode
);
1184 outof_input
= operand_subword_force (op0
, outof_word
, mode
);
1185 into_input
= operand_subword_force (op0
, 1 - outof_word
, mode
);
1187 if (shift_count
== BITS_PER_WORD
)
1189 /* This is just a word swap. */
1190 emit_move_insn (outof_target
, into_input
);
1191 emit_move_insn (into_target
, outof_input
);
1196 rtx into_temp1
, into_temp2
, outof_temp1
, outof_temp2
;
1197 rtx first_shift_count
, second_shift_count
;
1198 optab reverse_unsigned_shift
, unsigned_shift
;
1200 reverse_unsigned_shift
= (left_shift
^ (shift_count
< BITS_PER_WORD
)
1201 ? lshr_optab
: ashl_optab
);
1203 unsigned_shift
= (left_shift
^ (shift_count
< BITS_PER_WORD
)
1204 ? ashl_optab
: lshr_optab
);
1206 if (shift_count
> BITS_PER_WORD
)
1208 first_shift_count
= GEN_INT (shift_count
- BITS_PER_WORD
);
1209 second_shift_count
= GEN_INT (2 * BITS_PER_WORD
- shift_count
);
1213 first_shift_count
= GEN_INT (BITS_PER_WORD
- shift_count
);
1214 second_shift_count
= GEN_INT (shift_count
);
1217 into_temp1
= expand_binop (word_mode
, unsigned_shift
,
1218 outof_input
, first_shift_count
,
1219 NULL_RTX
, unsignedp
, next_methods
);
1220 into_temp2
= expand_binop (word_mode
, reverse_unsigned_shift
,
1221 into_input
, second_shift_count
,
1222 NULL_RTX
, unsignedp
, next_methods
);
1224 if (into_temp1
!= 0 && into_temp2
!= 0)
1225 inter
= expand_binop (word_mode
, ior_optab
, into_temp1
, into_temp2
,
1226 into_target
, unsignedp
, next_methods
);
1230 if (inter
!= 0 && inter
!= into_target
)
1231 emit_move_insn (into_target
, inter
);
1233 outof_temp1
= expand_binop (word_mode
, unsigned_shift
,
1234 into_input
, first_shift_count
,
1235 NULL_RTX
, unsignedp
, next_methods
);
1236 outof_temp2
= expand_binop (word_mode
, reverse_unsigned_shift
,
1237 outof_input
, second_shift_count
,
1238 NULL_RTX
, unsignedp
, next_methods
);
1240 if (inter
!= 0 && outof_temp1
!= 0 && outof_temp2
!= 0)
1241 inter
= expand_binop (word_mode
, ior_optab
,
1242 outof_temp1
, outof_temp2
,
1243 outof_target
, unsignedp
, next_methods
);
1245 if (inter
!= 0 && inter
!= outof_target
)
1246 emit_move_insn (outof_target
, inter
);
1249 insns
= get_insns ();
1254 if (binoptab
->code
!= UNKNOWN
)
1255 equiv_value
= gen_rtx_fmt_ee (binoptab
->code
, mode
, op0
, op1
);
1259 /* We can't make this a no conflict block if this is a word swap,
1260 because the word swap case fails if the input and output values
1261 are in the same register. */
1262 if (shift_count
!= BITS_PER_WORD
)
1263 emit_no_conflict_block (insns
, target
, op0
, op1
, equiv_value
);
1272 /* These can be done a word at a time by propagating carries. */
1273 if ((binoptab
== add_optab
|| binoptab
== sub_optab
)
1274 && class == MODE_INT
1275 && GET_MODE_SIZE (mode
) >= 2 * UNITS_PER_WORD
1276 && binoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
1279 optab otheroptab
= binoptab
== add_optab
? sub_optab
: add_optab
;
1280 const unsigned int nwords
= GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
;
1281 rtx carry_in
= NULL_RTX
, carry_out
= NULL_RTX
;
1282 rtx xop0
, xop1
, xtarget
;
1284 /* We can handle either a 1 or -1 value for the carry. If STORE_FLAG
1285 value is one of those, use it. Otherwise, use 1 since it is the
1286 one easiest to get. */
1287 #if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1
1288 int normalizep
= STORE_FLAG_VALUE
;
1293 /* Prepare the operands. */
1294 xop0
= force_reg (mode
, op0
);
1295 xop1
= force_reg (mode
, op1
);
1297 xtarget
= gen_reg_rtx (mode
);
1299 if (target
== 0 || !REG_P (target
))
1302 /* Indicate for flow that the entire target reg is being set. */
1304 emit_insn (gen_rtx_CLOBBER (VOIDmode
, xtarget
));
1306 /* Do the actual arithmetic. */
1307 for (i
= 0; i
< nwords
; i
++)
1309 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
1310 rtx target_piece
= operand_subword (xtarget
, index
, 1, mode
);
1311 rtx op0_piece
= operand_subword_force (xop0
, index
, mode
);
1312 rtx op1_piece
= operand_subword_force (xop1
, index
, mode
);
1315 /* Main add/subtract of the input operands. */
1316 x
= expand_binop (word_mode
, binoptab
,
1317 op0_piece
, op1_piece
,
1318 target_piece
, unsignedp
, next_methods
);
1324 /* Store carry from main add/subtract. */
1325 carry_out
= gen_reg_rtx (word_mode
);
1326 carry_out
= emit_store_flag_force (carry_out
,
1327 (binoptab
== add_optab
1330 word_mode
, 1, normalizep
);
1337 /* Add/subtract previous carry to main result. */
1338 newx
= expand_binop (word_mode
,
1339 normalizep
== 1 ? binoptab
: otheroptab
,
1341 NULL_RTX
, 1, next_methods
);
1345 /* Get out carry from adding/subtracting carry in. */
1346 rtx carry_tmp
= gen_reg_rtx (word_mode
);
1347 carry_tmp
= emit_store_flag_force (carry_tmp
,
1348 (binoptab
== add_optab
1351 word_mode
, 1, normalizep
);
1353 /* Logical-ior the two poss. carry together. */
1354 carry_out
= expand_binop (word_mode
, ior_optab
,
1355 carry_out
, carry_tmp
,
1356 carry_out
, 0, next_methods
);
1360 emit_move_insn (target_piece
, newx
);
1363 carry_in
= carry_out
;
1366 if (i
== GET_MODE_BITSIZE (mode
) / (unsigned) BITS_PER_WORD
)
1368 if (mov_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
1369 || ! rtx_equal_p (target
, xtarget
))
1371 rtx temp
= emit_move_insn (target
, xtarget
);
1373 set_unique_reg_note (temp
,
1375 gen_rtx_fmt_ee (binoptab
->code
, mode
,
1386 delete_insns_since (last
);
1389 /* If we want to multiply two two-word values and have normal and widening
1390 multiplies of single-word values, we can do this with three smaller
1391 multiplications. Note that we do not make a REG_NO_CONFLICT block here
1392 because we are not operating on one word at a time.
1394 The multiplication proceeds as follows:
1395 _______________________
1396 [__op0_high_|__op0_low__]
1397 _______________________
1398 * [__op1_high_|__op1_low__]
1399 _______________________________________________
1400 _______________________
1401 (1) [__op0_low__*__op1_low__]
1402 _______________________
1403 (2a) [__op0_low__*__op1_high_]
1404 _______________________
1405 (2b) [__op0_high_*__op1_low__]
1406 _______________________
1407 (3) [__op0_high_*__op1_high_]
1410 This gives a 4-word result. Since we are only interested in the
1411 lower 2 words, partial result (3) and the upper words of (2a) and
1412 (2b) don't need to be calculated. Hence (2a) and (2b) can be
1413 calculated using non-widening multiplication.
1415 (1), however, needs to be calculated with an unsigned widening
1416 multiplication. If this operation is not directly supported we
1417 try using a signed widening multiplication and adjust the result.
1418 This adjustment works as follows:
1420 If both operands are positive then no adjustment is needed.
1422 If the operands have different signs, for example op0_low < 0 and
1423 op1_low >= 0, the instruction treats the most significant bit of
1424 op0_low as a sign bit instead of a bit with significance
1425 2**(BITS_PER_WORD-1), i.e. the instruction multiplies op1_low
1426 with 2**BITS_PER_WORD - op0_low, and two's complements the
1427 result. Conclusion: We need to add op1_low * 2**BITS_PER_WORD to
1430 Similarly, if both operands are negative, we need to add
1431 (op0_low + op1_low) * 2**BITS_PER_WORD.
1433 We use a trick to adjust quickly. We logically shift op0_low right
1434 (op1_low) BITS_PER_WORD-1 steps to get 0 or 1, and add this to
1435 op0_high (op1_high) before it is used to calculate 2b (2a). If no
1436 logical shift exists, we do an arithmetic right shift and subtract
1439 if (binoptab
== smul_optab
1440 && class == MODE_INT
1441 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
1442 && smul_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1443 && add_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1444 && ((umul_widen_optab
->handlers
[(int) mode
].insn_code
1445 != CODE_FOR_nothing
)
1446 || (smul_widen_optab
->handlers
[(int) mode
].insn_code
1447 != CODE_FOR_nothing
)))
1449 int low
= (WORDS_BIG_ENDIAN
? 1 : 0);
1450 int high
= (WORDS_BIG_ENDIAN
? 0 : 1);
1451 rtx op0_high
= operand_subword_force (op0
, high
, mode
);
1452 rtx op0_low
= operand_subword_force (op0
, low
, mode
);
1453 rtx op1_high
= operand_subword_force (op1
, high
, mode
);
1454 rtx op1_low
= operand_subword_force (op1
, low
, mode
);
1456 rtx op0_xhigh
= NULL_RTX
;
1457 rtx op1_xhigh
= NULL_RTX
;
1459 /* If the target is the same as one of the inputs, don't use it. This
1460 prevents problems with the REG_EQUAL note. */
1461 if (target
== op0
|| target
== op1
1462 || (target
!= 0 && !REG_P (target
)))
1465 /* Multiply the two lower words to get a double-word product.
1466 If unsigned widening multiplication is available, use that;
1467 otherwise use the signed form and compensate. */
1469 if (umul_widen_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
1471 product
= expand_binop (mode
, umul_widen_optab
, op0_low
, op1_low
,
1472 target
, 1, OPTAB_DIRECT
);
1474 /* If we didn't succeed, delete everything we did so far. */
1476 delete_insns_since (last
);
1478 op0_xhigh
= op0_high
, op1_xhigh
= op1_high
;
1482 && smul_widen_optab
->handlers
[(int) mode
].insn_code
1483 != CODE_FOR_nothing
)
1485 rtx wordm1
= GEN_INT (BITS_PER_WORD
- 1);
1486 product
= expand_binop (mode
, smul_widen_optab
, op0_low
, op1_low
,
1487 target
, 1, OPTAB_DIRECT
);
1488 op0_xhigh
= expand_binop (word_mode
, lshr_optab
, op0_low
, wordm1
,
1489 NULL_RTX
, 1, next_methods
);
1491 op0_xhigh
= expand_binop (word_mode
, add_optab
, op0_high
,
1492 op0_xhigh
, op0_xhigh
, 0, next_methods
);
1495 op0_xhigh
= expand_binop (word_mode
, ashr_optab
, op0_low
, wordm1
,
1496 NULL_RTX
, 0, next_methods
);
1498 op0_xhigh
= expand_binop (word_mode
, sub_optab
, op0_high
,
1499 op0_xhigh
, op0_xhigh
, 0,
1503 op1_xhigh
= expand_binop (word_mode
, lshr_optab
, op1_low
, wordm1
,
1504 NULL_RTX
, 1, next_methods
);
1506 op1_xhigh
= expand_binop (word_mode
, add_optab
, op1_high
,
1507 op1_xhigh
, op1_xhigh
, 0, next_methods
);
1510 op1_xhigh
= expand_binop (word_mode
, ashr_optab
, op1_low
, wordm1
,
1511 NULL_RTX
, 0, next_methods
);
1513 op1_xhigh
= expand_binop (word_mode
, sub_optab
, op1_high
,
1514 op1_xhigh
, op1_xhigh
, 0,
1519 /* If we have been able to directly compute the product of the
1520 low-order words of the operands and perform any required adjustments
1521 of the operands, we proceed by trying two more multiplications
1522 and then computing the appropriate sum.
1524 We have checked above that the required addition is provided.
1525 Full-word addition will normally always succeed, especially if
1526 it is provided at all, so we don't worry about its failure. The
1527 multiplication may well fail, however, so we do handle that. */
1529 if (product
&& op0_xhigh
&& op1_xhigh
)
1531 rtx product_high
= operand_subword (product
, high
, 1, mode
);
1532 rtx temp
= expand_binop (word_mode
, binoptab
, op0_low
, op1_xhigh
,
1533 NULL_RTX
, 0, OPTAB_DIRECT
);
1535 if (!REG_P (product_high
))
1536 product_high
= force_reg (word_mode
, product_high
);
1539 temp
= expand_binop (word_mode
, add_optab
, temp
, product_high
,
1540 product_high
, 0, next_methods
);
1542 if (temp
!= 0 && temp
!= product_high
)
1543 emit_move_insn (product_high
, temp
);
1546 temp
= expand_binop (word_mode
, binoptab
, op1_low
, op0_xhigh
,
1547 NULL_RTX
, 0, OPTAB_DIRECT
);
1550 temp
= expand_binop (word_mode
, add_optab
, temp
,
1551 product_high
, product_high
,
1554 if (temp
!= 0 && temp
!= product_high
)
1555 emit_move_insn (product_high
, temp
);
1557 emit_move_insn (operand_subword (product
, high
, 1, mode
), product_high
);
1561 if (mov_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
1563 temp
= emit_move_insn (product
, product
);
1564 set_unique_reg_note (temp
,
1566 gen_rtx_fmt_ee (MULT
, mode
,
1575 /* If we get here, we couldn't do it for some reason even though we
1576 originally thought we could. Delete anything we've emitted in
1579 delete_insns_since (last
);
1582 /* It can't be open-coded in this mode.
1583 Use a library call if one is available and caller says that's ok. */
1585 if (binoptab
->handlers
[(int) mode
].libfunc
1586 && (methods
== OPTAB_LIB
|| methods
== OPTAB_LIB_WIDEN
))
1590 enum machine_mode op1_mode
= mode
;
1597 op1_mode
= word_mode
;
1598 /* Specify unsigned here,
1599 since negative shift counts are meaningless. */
1600 op1x
= convert_to_mode (word_mode
, op1
, 1);
1603 if (GET_MODE (op0
) != VOIDmode
1604 && GET_MODE (op0
) != mode
)
1605 op0
= convert_to_mode (mode
, op0
, unsignedp
);
1607 /* Pass 1 for NO_QUEUE so we don't lose any increments
1608 if the libcall is cse'd or moved. */
1609 value
= emit_library_call_value (binoptab
->handlers
[(int) mode
].libfunc
,
1610 NULL_RTX
, LCT_CONST
, mode
, 2,
1611 op0
, mode
, op1x
, op1_mode
);
1613 insns
= get_insns ();
1616 target
= gen_reg_rtx (mode
);
1617 emit_libcall_block (insns
, target
, value
,
1618 gen_rtx_fmt_ee (binoptab
->code
, mode
, op0
, op1
));
1623 delete_insns_since (last
);
1625 /* It can't be done in this mode. Can we do it in a wider mode? */
1627 if (! (methods
== OPTAB_WIDEN
|| methods
== OPTAB_LIB_WIDEN
1628 || methods
== OPTAB_MUST_WIDEN
))
1630 /* Caller says, don't even try. */
1631 delete_insns_since (entry_last
);
1635 /* Compute the value of METHODS to pass to recursive calls.
1636 Don't allow widening to be tried recursively. */
1638 methods
= (methods
== OPTAB_LIB_WIDEN
? OPTAB_LIB
: OPTAB_DIRECT
);
1640 /* Look for a wider mode of the same class for which it appears we can do
1643 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
1645 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
1646 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
1648 if ((binoptab
->handlers
[(int) wider_mode
].insn_code
1649 != CODE_FOR_nothing
)
1650 || (methods
== OPTAB_LIB
1651 && binoptab
->handlers
[(int) wider_mode
].libfunc
))
1653 rtx xop0
= op0
, xop1
= op1
;
1656 /* For certain integer operations, we need not actually extend
1657 the narrow operands, as long as we will truncate
1658 the results to the same narrowness. */
1660 if ((binoptab
== ior_optab
|| binoptab
== and_optab
1661 || binoptab
== xor_optab
1662 || binoptab
== add_optab
|| binoptab
== sub_optab
1663 || binoptab
== smul_optab
|| binoptab
== ashl_optab
)
1664 && class == MODE_INT
)
1667 xop0
= widen_operand (xop0
, wider_mode
, mode
,
1668 unsignedp
, no_extend
);
1670 /* The second operand of a shift must always be extended. */
1671 xop1
= widen_operand (xop1
, wider_mode
, mode
, unsignedp
,
1672 no_extend
&& binoptab
!= ashl_optab
);
1674 temp
= expand_binop (wider_mode
, binoptab
, xop0
, xop1
, NULL_RTX
,
1675 unsignedp
, methods
);
1678 if (class != MODE_INT
)
1681 target
= gen_reg_rtx (mode
);
1682 convert_move (target
, temp
, 0);
1686 return gen_lowpart (mode
, temp
);
1689 delete_insns_since (last
);
1694 delete_insns_since (entry_last
);
1698 /* Expand a binary operator which has both signed and unsigned forms.
1699 UOPTAB is the optab for unsigned operations, and SOPTAB is for
1702 If we widen unsigned operands, we may use a signed wider operation instead
1703 of an unsigned wider operation, since the result would be the same. */
1706 sign_expand_binop (enum machine_mode mode
, optab uoptab
, optab soptab
,
1707 rtx op0
, rtx op1
, rtx target
, int unsignedp
,
1708 enum optab_methods methods
)
1711 optab direct_optab
= unsignedp
? uoptab
: soptab
;
1712 struct optab wide_soptab
;
1714 /* Do it without widening, if possible. */
1715 temp
= expand_binop (mode
, direct_optab
, op0
, op1
, target
,
1716 unsignedp
, OPTAB_DIRECT
);
1717 if (temp
|| methods
== OPTAB_DIRECT
)
1720 /* Try widening to a signed int. Make a fake signed optab that
1721 hides any signed insn for direct use. */
1722 wide_soptab
= *soptab
;
1723 wide_soptab
.handlers
[(int) mode
].insn_code
= CODE_FOR_nothing
;
1724 wide_soptab
.handlers
[(int) mode
].libfunc
= 0;
1726 temp
= expand_binop (mode
, &wide_soptab
, op0
, op1
, target
,
1727 unsignedp
, OPTAB_WIDEN
);
1729 /* For unsigned operands, try widening to an unsigned int. */
1730 if (temp
== 0 && unsignedp
)
1731 temp
= expand_binop (mode
, uoptab
, op0
, op1
, target
,
1732 unsignedp
, OPTAB_WIDEN
);
1733 if (temp
|| methods
== OPTAB_WIDEN
)
1736 /* Use the right width lib call if that exists. */
1737 temp
= expand_binop (mode
, direct_optab
, op0
, op1
, target
, unsignedp
, OPTAB_LIB
);
1738 if (temp
|| methods
== OPTAB_LIB
)
1741 /* Must widen and use a lib call, use either signed or unsigned. */
1742 temp
= expand_binop (mode
, &wide_soptab
, op0
, op1
, target
,
1743 unsignedp
, methods
);
1747 return expand_binop (mode
, uoptab
, op0
, op1
, target
,
1748 unsignedp
, methods
);
1752 /* Generate code to perform an operation specified by UNOPPTAB
1753 on operand OP0, with two results to TARG0 and TARG1.
1754 We assume that the order of the operands for the instruction
1755 is TARG0, TARG1, OP0.
1757 Either TARG0 or TARG1 may be zero, but what that means is that
1758 the result is not actually wanted. We will generate it into
1759 a dummy pseudo-reg and discard it. They may not both be zero.
1761 Returns 1 if this operation can be performed; 0 if not. */
1764 expand_twoval_unop (optab unoptab
, rtx op0
, rtx targ0
, rtx targ1
,
1767 enum machine_mode mode
= GET_MODE (targ0
? targ0
: targ1
);
1768 enum mode_class
class;
1769 enum machine_mode wider_mode
;
1770 rtx entry_last
= get_last_insn ();
1773 class = GET_MODE_CLASS (mode
);
1776 op0
= force_not_mem (op0
);
1779 targ0
= gen_reg_rtx (mode
);
1781 targ1
= gen_reg_rtx (mode
);
1783 /* Record where to go back to if we fail. */
1784 last
= get_last_insn ();
1786 if (unoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
1788 int icode
= (int) unoptab
->handlers
[(int) mode
].insn_code
;
1789 enum machine_mode mode0
= insn_data
[icode
].operand
[2].mode
;
1793 if (GET_MODE (xop0
) != VOIDmode
1794 && GET_MODE (xop0
) != mode0
)
1795 xop0
= convert_to_mode (mode0
, xop0
, unsignedp
);
1797 /* Now, if insn doesn't accept these operands, put them into pseudos. */
1798 if (! (*insn_data
[icode
].operand
[2].predicate
) (xop0
, mode0
))
1799 xop0
= copy_to_mode_reg (mode0
, xop0
);
1801 /* We could handle this, but we should always be called with a pseudo
1802 for our targets and all insns should take them as outputs. */
1803 if (! (*insn_data
[icode
].operand
[0].predicate
) (targ0
, mode
)
1804 || ! (*insn_data
[icode
].operand
[1].predicate
) (targ1
, mode
))
1807 pat
= GEN_FCN (icode
) (targ0
, targ1
, xop0
);
1814 delete_insns_since (last
);
1817 /* It can't be done in this mode. Can we do it in a wider mode? */
1819 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
1821 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
1822 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
1824 if (unoptab
->handlers
[(int) wider_mode
].insn_code
1825 != CODE_FOR_nothing
)
1827 rtx t0
= gen_reg_rtx (wider_mode
);
1828 rtx t1
= gen_reg_rtx (wider_mode
);
1829 rtx cop0
= convert_modes (wider_mode
, mode
, op0
, unsignedp
);
1831 if (expand_twoval_unop (unoptab
, cop0
, t0
, t1
, unsignedp
))
1833 convert_move (targ0
, t0
, unsignedp
);
1834 convert_move (targ1
, t1
, unsignedp
);
1838 delete_insns_since (last
);
1843 delete_insns_since (entry_last
);
1847 /* Generate code to perform an operation specified by BINOPTAB
1848 on operands OP0 and OP1, with two results to TARG1 and TARG2.
1849 We assume that the order of the operands for the instruction
1850 is TARG0, OP0, OP1, TARG1, which would fit a pattern like
1851 [(set TARG0 (operate OP0 OP1)) (set TARG1 (operate ...))].
1853 Either TARG0 or TARG1 may be zero, but what that means is that
1854 the result is not actually wanted. We will generate it into
1855 a dummy pseudo-reg and discard it. They may not both be zero.
1857 Returns 1 if this operation can be performed; 0 if not. */
1860 expand_twoval_binop (optab binoptab
, rtx op0
, rtx op1
, rtx targ0
, rtx targ1
,
1863 enum machine_mode mode
= GET_MODE (targ0
? targ0
: targ1
);
1864 enum mode_class
class;
1865 enum machine_mode wider_mode
;
1866 rtx entry_last
= get_last_insn ();
1869 class = GET_MODE_CLASS (mode
);
1873 op0
= force_not_mem (op0
);
1874 op1
= force_not_mem (op1
);
1877 /* If we are inside an appropriately-short loop and we are optimizing,
1878 force expensive constants into a register. */
1879 if (CONSTANT_P (op0
) && optimize
1880 && rtx_cost (op0
, binoptab
->code
) > COSTS_N_INSNS (1))
1881 op0
= force_reg (mode
, op0
);
1883 if (CONSTANT_P (op1
) && optimize
1884 && rtx_cost (op1
, binoptab
->code
) > COSTS_N_INSNS (1))
1885 op1
= force_reg (mode
, op1
);
1888 targ0
= gen_reg_rtx (mode
);
1890 targ1
= gen_reg_rtx (mode
);
1892 /* Record where to go back to if we fail. */
1893 last
= get_last_insn ();
1895 if (binoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
1897 int icode
= (int) binoptab
->handlers
[(int) mode
].insn_code
;
1898 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
1899 enum machine_mode mode1
= insn_data
[icode
].operand
[2].mode
;
1901 rtx xop0
= op0
, xop1
= op1
;
1903 /* In case the insn wants input operands in modes different from
1904 those of the actual operands, convert the operands. It would
1905 seem that we don't need to convert CONST_INTs, but we do, so
1906 that they're properly zero-extended, sign-extended or truncated
1909 if (GET_MODE (op0
) != mode0
&& mode0
!= VOIDmode
)
1910 xop0
= convert_modes (mode0
,
1911 GET_MODE (op0
) != VOIDmode
1916 if (GET_MODE (op1
) != mode1
&& mode1
!= VOIDmode
)
1917 xop1
= convert_modes (mode1
,
1918 GET_MODE (op1
) != VOIDmode
1923 /* Now, if insn doesn't accept these operands, put them into pseudos. */
1924 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
))
1925 xop0
= copy_to_mode_reg (mode0
, xop0
);
1927 if (! (*insn_data
[icode
].operand
[2].predicate
) (xop1
, mode1
))
1928 xop1
= copy_to_mode_reg (mode1
, xop1
);
1930 /* We could handle this, but we should always be called with a pseudo
1931 for our targets and all insns should take them as outputs. */
1932 if (! (*insn_data
[icode
].operand
[0].predicate
) (targ0
, mode
)
1933 || ! (*insn_data
[icode
].operand
[3].predicate
) (targ1
, mode
))
1936 pat
= GEN_FCN (icode
) (targ0
, xop0
, xop1
, targ1
);
1943 delete_insns_since (last
);
1946 /* It can't be done in this mode. Can we do it in a wider mode? */
1948 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
1950 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
1951 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
1953 if (binoptab
->handlers
[(int) wider_mode
].insn_code
1954 != CODE_FOR_nothing
)
1956 rtx t0
= gen_reg_rtx (wider_mode
);
1957 rtx t1
= gen_reg_rtx (wider_mode
);
1958 rtx cop0
= convert_modes (wider_mode
, mode
, op0
, unsignedp
);
1959 rtx cop1
= convert_modes (wider_mode
, mode
, op1
, unsignedp
);
1961 if (expand_twoval_binop (binoptab
, cop0
, cop1
,
1964 convert_move (targ0
, t0
, unsignedp
);
1965 convert_move (targ1
, t1
, unsignedp
);
1969 delete_insns_since (last
);
1974 delete_insns_since (entry_last
);
1978 /* Expand the two-valued library call indicated by BINOPTAB, but
1979 preserve only one of the values. If TARG0 is non-NULL, the first
1980 value is placed into TARG0; otherwise the second value is placed
1981 into TARG1. Exactly one of TARG0 and TARG1 must be non-NULL. The
1982 value stored into TARG0 or TARG1 is equivalent to (CODE OP0 OP1).
1983 This routine assumes that the value returned by the library call is
1984 as if the return value was of an integral mode twice as wide as the
1985 mode of OP0. Returns 1 if the call was successful. */
1988 expand_twoval_binop_libfunc (optab binoptab
, rtx op0
, rtx op1
,
1989 rtx targ0
, rtx targ1
, enum rtx_code code
)
1991 enum machine_mode mode
;
1992 enum machine_mode libval_mode
;
1996 /* Exactly one of TARG0 or TARG1 should be non-NULL. */
1997 if (!((targ0
!= NULL_RTX
) ^ (targ1
!= NULL_RTX
)))
2000 mode
= GET_MODE (op0
);
2001 if (!binoptab
->handlers
[(int) mode
].libfunc
)
2004 /* The value returned by the library function will have twice as
2005 many bits as the nominal MODE. */
2006 libval_mode
= smallest_mode_for_size (2 * GET_MODE_BITSIZE (mode
),
2009 libval
= emit_library_call_value (binoptab
->handlers
[(int) mode
].libfunc
,
2010 NULL_RTX
, LCT_CONST
,
2014 /* Get the part of VAL containing the value that we want. */
2015 libval
= simplify_gen_subreg (mode
, libval
, libval_mode
,
2016 targ0
? 0 : GET_MODE_SIZE (mode
));
2017 insns
= get_insns ();
2019 /* Move the into the desired location. */
2020 emit_libcall_block (insns
, targ0
? targ0
: targ1
, libval
,
2021 gen_rtx_fmt_ee (code
, mode
, op0
, op1
));
2027 /* Wrapper around expand_unop which takes an rtx code to specify
2028 the operation to perform, not an optab pointer. All other
2029 arguments are the same. */
2031 expand_simple_unop (enum machine_mode mode
, enum rtx_code code
, rtx op0
,
2032 rtx target
, int unsignedp
)
2034 optab unop
= code_to_optab
[(int) code
];
2038 return expand_unop (mode
, unop
, op0
, target
, unsignedp
);
2044 (clz:wide (zero_extend:wide x)) - ((width wide) - (width narrow)). */
2046 widen_clz (enum machine_mode mode
, rtx op0
, rtx target
)
2048 enum mode_class
class = GET_MODE_CLASS (mode
);
2049 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2051 enum machine_mode wider_mode
;
2052 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2053 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2055 if (clz_optab
->handlers
[(int) wider_mode
].insn_code
2056 != CODE_FOR_nothing
)
2058 rtx xop0
, temp
, last
;
2060 last
= get_last_insn ();
2063 target
= gen_reg_rtx (mode
);
2064 xop0
= widen_operand (op0
, wider_mode
, mode
, true, false);
2065 temp
= expand_unop (wider_mode
, clz_optab
, xop0
, NULL_RTX
, true);
2067 temp
= expand_binop (wider_mode
, sub_optab
, temp
,
2068 GEN_INT (GET_MODE_BITSIZE (wider_mode
)
2069 - GET_MODE_BITSIZE (mode
)),
2070 target
, true, OPTAB_DIRECT
);
2072 delete_insns_since (last
);
2081 /* Try calculating (parity x) as (and (popcount x) 1), where
2082 popcount can also be done in a wider mode. */
2084 expand_parity (enum machine_mode mode
, rtx op0
, rtx target
)
2086 enum mode_class
class = GET_MODE_CLASS (mode
);
2087 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2089 enum machine_mode wider_mode
;
2090 for (wider_mode
= mode
; wider_mode
!= VOIDmode
;
2091 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2093 if (popcount_optab
->handlers
[(int) wider_mode
].insn_code
2094 != CODE_FOR_nothing
)
2096 rtx xop0
, temp
, last
;
2098 last
= get_last_insn ();
2101 target
= gen_reg_rtx (mode
);
2102 xop0
= widen_operand (op0
, wider_mode
, mode
, true, false);
2103 temp
= expand_unop (wider_mode
, popcount_optab
, xop0
, NULL_RTX
,
2106 temp
= expand_binop (wider_mode
, and_optab
, temp
, const1_rtx
,
2107 target
, true, OPTAB_DIRECT
);
2109 delete_insns_since (last
);
2118 /* Generate code to perform an operation specified by UNOPTAB
2119 on operand OP0, with result having machine-mode MODE.
2121 UNSIGNEDP is for the case where we have to widen the operands
2122 to perform the operation. It says to use zero-extension.
2124 If TARGET is nonzero, the value
2125 is generated there, if it is convenient to do so.
2126 In all cases an rtx is returned for the locus of the value;
2127 this may or may not be TARGET. */
2130 expand_unop (enum machine_mode mode
, optab unoptab
, rtx op0
, rtx target
,
2133 enum mode_class
class;
2134 enum machine_mode wider_mode
;
2136 rtx last
= get_last_insn ();
2139 class = GET_MODE_CLASS (mode
);
2142 op0
= force_not_mem (op0
);
2144 if (unoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2146 int icode
= (int) unoptab
->handlers
[(int) mode
].insn_code
;
2147 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
2153 temp
= gen_reg_rtx (mode
);
2155 if (GET_MODE (xop0
) != VOIDmode
2156 && GET_MODE (xop0
) != mode0
)
2157 xop0
= convert_to_mode (mode0
, xop0
, unsignedp
);
2159 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
2161 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
))
2162 xop0
= copy_to_mode_reg (mode0
, xop0
);
2164 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, mode
))
2165 temp
= gen_reg_rtx (mode
);
2167 pat
= GEN_FCN (icode
) (temp
, xop0
);
2170 if (INSN_P (pat
) && NEXT_INSN (pat
) != NULL_RTX
2171 && ! add_equal_note (pat
, temp
, unoptab
->code
, xop0
, NULL_RTX
))
2173 delete_insns_since (last
);
2174 return expand_unop (mode
, unoptab
, op0
, NULL_RTX
, unsignedp
);
2182 delete_insns_since (last
);
2185 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2187 /* Widening clz needs special treatment. */
2188 if (unoptab
== clz_optab
)
2190 temp
= widen_clz (mode
, op0
, target
);
2197 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2198 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2199 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2201 if (unoptab
->handlers
[(int) wider_mode
].insn_code
!= CODE_FOR_nothing
)
2205 /* For certain operations, we need not actually extend
2206 the narrow operand, as long as we will truncate the
2207 results to the same narrowness. */
2209 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
,
2210 (unoptab
== neg_optab
2211 || unoptab
== one_cmpl_optab
)
2212 && class == MODE_INT
);
2214 temp
= expand_unop (wider_mode
, unoptab
, xop0
, NULL_RTX
,
2219 if (class != MODE_INT
)
2222 target
= gen_reg_rtx (mode
);
2223 convert_move (target
, temp
, 0);
2227 return gen_lowpart (mode
, temp
);
2230 delete_insns_since (last
);
2234 /* These can be done a word at a time. */
2235 if (unoptab
== one_cmpl_optab
2236 && class == MODE_INT
2237 && GET_MODE_SIZE (mode
) > UNITS_PER_WORD
2238 && unoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
2243 if (target
== 0 || target
== op0
)
2244 target
= gen_reg_rtx (mode
);
2248 /* Do the actual arithmetic. */
2249 for (i
= 0; i
< GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
; i
++)
2251 rtx target_piece
= operand_subword (target
, i
, 1, mode
);
2252 rtx x
= expand_unop (word_mode
, unoptab
,
2253 operand_subword_force (op0
, i
, mode
),
2254 target_piece
, unsignedp
);
2256 if (target_piece
!= x
)
2257 emit_move_insn (target_piece
, x
);
2260 insns
= get_insns ();
2263 emit_no_conflict_block (insns
, target
, op0
, NULL_RTX
,
2264 gen_rtx_fmt_e (unoptab
->code
, mode
,
2269 /* Try negating floating point values by flipping the sign bit. */
2270 if (unoptab
->code
== NEG
&& class == MODE_FLOAT
2271 && GET_MODE_BITSIZE (mode
) <= 2 * HOST_BITS_PER_WIDE_INT
)
2273 const struct real_format
*fmt
= REAL_MODE_FORMAT (mode
);
2274 enum machine_mode imode
= int_mode_for_mode (mode
);
2275 int bitpos
= (fmt
!= 0) ? fmt
->signbit
: -1;
2277 if (imode
!= BLKmode
&& bitpos
>= 0 && fmt
->has_signed_zero
)
2279 HOST_WIDE_INT hi
, lo
;
2280 rtx last
= get_last_insn ();
2282 /* Handle targets with different FP word orders. */
2283 if (FLOAT_WORDS_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
2285 int nwords
= GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
;
2286 int word
= nwords
- (bitpos
/ BITS_PER_WORD
) - 1;
2287 bitpos
= word
* BITS_PER_WORD
+ bitpos
% BITS_PER_WORD
;
2290 if (bitpos
< HOST_BITS_PER_WIDE_INT
)
2293 lo
= (HOST_WIDE_INT
) 1 << bitpos
;
2297 hi
= (HOST_WIDE_INT
) 1 << (bitpos
- HOST_BITS_PER_WIDE_INT
);
2300 temp
= expand_binop (imode
, xor_optab
,
2301 gen_lowpart (imode
, op0
),
2302 immed_double_const (lo
, hi
, imode
),
2303 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2308 target
= gen_reg_rtx (mode
);
2309 insn
= emit_move_insn (target
, gen_lowpart (mode
, temp
));
2310 set_unique_reg_note (insn
, REG_EQUAL
,
2311 gen_rtx_fmt_e (NEG
, mode
,
2315 delete_insns_since (last
);
2319 /* Try calculating parity (x) as popcount (x) % 2. */
2320 if (unoptab
== parity_optab
)
2322 temp
= expand_parity (mode
, op0
, target
);
2327 /* If there is no negation pattern, try subtracting from zero. */
2328 if (unoptab
== neg_optab
&& class == MODE_INT
)
2330 temp
= expand_binop (mode
, sub_optab
, CONST0_RTX (mode
), op0
,
2331 target
, unsignedp
, OPTAB_DIRECT
);
2337 /* Now try a library call in this mode. */
2338 if (unoptab
->handlers
[(int) mode
].libfunc
)
2342 enum machine_mode outmode
= mode
;
2344 /* All of these functions return small values. Thus we choose to
2345 have them return something that isn't a double-word. */
2346 if (unoptab
== ffs_optab
|| unoptab
== clz_optab
|| unoptab
== ctz_optab
2347 || unoptab
== popcount_optab
|| unoptab
== parity_optab
)
2349 = GET_MODE (hard_libcall_value (TYPE_MODE (integer_type_node
)));
2353 /* Pass 1 for NO_QUEUE so we don't lose any increments
2354 if the libcall is cse'd or moved. */
2355 value
= emit_library_call_value (unoptab
->handlers
[(int) mode
].libfunc
,
2356 NULL_RTX
, LCT_CONST
, outmode
,
2358 insns
= get_insns ();
2361 target
= gen_reg_rtx (outmode
);
2362 emit_libcall_block (insns
, target
, value
,
2363 gen_rtx_fmt_e (unoptab
->code
, mode
, op0
));
2368 /* It can't be done in this mode. Can we do it in a wider mode? */
2370 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2372 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2373 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2375 if ((unoptab
->handlers
[(int) wider_mode
].insn_code
2376 != CODE_FOR_nothing
)
2377 || unoptab
->handlers
[(int) wider_mode
].libfunc
)
2381 /* For certain operations, we need not actually extend
2382 the narrow operand, as long as we will truncate the
2383 results to the same narrowness. */
2385 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
,
2386 (unoptab
== neg_optab
2387 || unoptab
== one_cmpl_optab
)
2388 && class == MODE_INT
);
2390 temp
= expand_unop (wider_mode
, unoptab
, xop0
, NULL_RTX
,
2393 /* If we are generating clz using wider mode, adjust the
2395 if (unoptab
== clz_optab
&& temp
!= 0)
2396 temp
= expand_binop (wider_mode
, sub_optab
, temp
,
2397 GEN_INT (GET_MODE_BITSIZE (wider_mode
)
2398 - GET_MODE_BITSIZE (mode
)),
2399 target
, true, OPTAB_DIRECT
);
2403 if (class != MODE_INT
)
2406 target
= gen_reg_rtx (mode
);
2407 convert_move (target
, temp
, 0);
2411 return gen_lowpart (mode
, temp
);
2414 delete_insns_since (last
);
2419 /* If there is no negate operation, try doing a subtract from zero.
2420 The US Software GOFAST library needs this. FIXME: This is *wrong*
2421 for floating-point operations due to negative zeros! */
2422 if (unoptab
->code
== NEG
)
2425 temp
= expand_binop (mode
,
2426 unoptab
== negv_optab
? subv_optab
: sub_optab
,
2427 CONST0_RTX (mode
), op0
,
2428 target
, unsignedp
, OPTAB_LIB_WIDEN
);
2436 /* Emit code to compute the absolute value of OP0, with result to
2437 TARGET if convenient. (TARGET may be 0.) The return value says
2438 where the result actually is to be found.
2440 MODE is the mode of the operand; the mode of the result is
2441 different but can be deduced from MODE.
2446 expand_abs_nojump (enum machine_mode mode
, rtx op0
, rtx target
,
2447 int result_unsignedp
)
2452 result_unsignedp
= 1;
2454 /* First try to do it with a special abs instruction. */
2455 temp
= expand_unop (mode
, result_unsignedp
? abs_optab
: absv_optab
,
2460 /* For floating point modes, try clearing the sign bit. */
2461 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
2462 && GET_MODE_BITSIZE (mode
) <= 2 * HOST_BITS_PER_WIDE_INT
)
2464 const struct real_format
*fmt
= REAL_MODE_FORMAT (mode
);
2465 enum machine_mode imode
= int_mode_for_mode (mode
);
2466 int bitpos
= (fmt
!= 0) ? fmt
->signbit
: -1;
2468 if (imode
!= BLKmode
&& bitpos
>= 0)
2470 HOST_WIDE_INT hi
, lo
;
2471 rtx last
= get_last_insn ();
2473 /* Handle targets with different FP word orders. */
2474 if (FLOAT_WORDS_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
2476 int nwords
= GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
;
2477 int word
= nwords
- (bitpos
/ BITS_PER_WORD
) - 1;
2478 bitpos
= word
* BITS_PER_WORD
+ bitpos
% BITS_PER_WORD
;
2481 if (bitpos
< HOST_BITS_PER_WIDE_INT
)
2484 lo
= (HOST_WIDE_INT
) 1 << bitpos
;
2488 hi
= (HOST_WIDE_INT
) 1 << (bitpos
- HOST_BITS_PER_WIDE_INT
);
2491 temp
= expand_binop (imode
, and_optab
,
2492 gen_lowpart (imode
, op0
),
2493 immed_double_const (~lo
, ~hi
, imode
),
2494 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2499 target
= gen_reg_rtx (mode
);
2500 insn
= emit_move_insn (target
, gen_lowpart (mode
, temp
));
2501 set_unique_reg_note (insn
, REG_EQUAL
,
2502 gen_rtx_fmt_e (ABS
, mode
,
2506 delete_insns_since (last
);
2510 /* If we have a MAX insn, we can do this as MAX (x, -x). */
2511 if (smax_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2513 rtx last
= get_last_insn ();
2515 temp
= expand_unop (mode
, neg_optab
, op0
, NULL_RTX
, 0);
2517 temp
= expand_binop (mode
, smax_optab
, op0
, temp
, target
, 0,
2523 delete_insns_since (last
);
2526 /* If this machine has expensive jumps, we can do integer absolute
2527 value of X as (((signed) x >> (W-1)) ^ x) - ((signed) x >> (W-1)),
2528 where W is the width of MODE. */
2530 if (GET_MODE_CLASS (mode
) == MODE_INT
&& BRANCH_COST
>= 2)
2532 rtx extended
= expand_shift (RSHIFT_EXPR
, mode
, op0
,
2533 size_int (GET_MODE_BITSIZE (mode
) - 1),
2536 temp
= expand_binop (mode
, xor_optab
, extended
, op0
, target
, 0,
2539 temp
= expand_binop (mode
, result_unsignedp
? sub_optab
: subv_optab
,
2540 temp
, extended
, target
, 0, OPTAB_LIB_WIDEN
);
2550 expand_abs (enum machine_mode mode
, rtx op0
, rtx target
,
2551 int result_unsignedp
, int safe
)
2556 result_unsignedp
= 1;
2558 temp
= expand_abs_nojump (mode
, op0
, target
, result_unsignedp
);
2562 /* If that does not win, use conditional jump and negate. */
2564 /* It is safe to use the target if it is the same
2565 as the source if this is also a pseudo register */
2566 if (op0
== target
&& REG_P (op0
)
2567 && REGNO (op0
) >= FIRST_PSEUDO_REGISTER
)
2570 op1
= gen_label_rtx ();
2571 if (target
== 0 || ! safe
2572 || GET_MODE (target
) != mode
2573 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
2575 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
2576 target
= gen_reg_rtx (mode
);
2578 emit_move_insn (target
, op0
);
2581 /* If this mode is an integer too wide to compare properly,
2582 compare word by word. Rely on CSE to optimize constant cases. */
2583 if (GET_MODE_CLASS (mode
) == MODE_INT
2584 && ! can_compare_p (GE
, mode
, ccp_jump
))
2585 do_jump_by_parts_greater_rtx (mode
, 0, target
, const0_rtx
,
2588 do_compare_rtx_and_jump (target
, CONST0_RTX (mode
), GE
, 0, mode
,
2589 NULL_RTX
, NULL_RTX
, op1
);
2591 op0
= expand_unop (mode
, result_unsignedp
? neg_optab
: negv_optab
,
2594 emit_move_insn (target
, op0
);
2600 /* Generate an instruction whose insn-code is INSN_CODE,
2601 with two operands: an output TARGET and an input OP0.
2602 TARGET *must* be nonzero, and the output is always stored there.
2603 CODE is an rtx code such that (CODE OP0) is an rtx that describes
2604 the value that is stored into TARGET. */
2607 emit_unop_insn (int icode
, rtx target
, rtx op0
, enum rtx_code code
)
2610 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
2615 /* Sign and zero extension from memory is often done specially on
2616 RISC machines, so forcing into a register here can pessimize
2618 if (flag_force_mem
&& code
!= SIGN_EXTEND
&& code
!= ZERO_EXTEND
)
2619 op0
= force_not_mem (op0
);
2621 /* Now, if insn does not accept our operands, put them into pseudos. */
2623 if (! (*insn_data
[icode
].operand
[1].predicate
) (op0
, mode0
))
2624 op0
= copy_to_mode_reg (mode0
, op0
);
2626 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, GET_MODE (temp
))
2627 || (flag_force_mem
&& MEM_P (temp
)))
2628 temp
= gen_reg_rtx (GET_MODE (temp
));
2630 pat
= GEN_FCN (icode
) (temp
, op0
);
2632 if (INSN_P (pat
) && NEXT_INSN (pat
) != NULL_RTX
&& code
!= UNKNOWN
)
2633 add_equal_note (pat
, temp
, code
, op0
, NULL_RTX
);
2638 emit_move_insn (target
, temp
);
2641 /* Emit code to perform a series of operations on a multi-word quantity, one
2644 Such a block is preceded by a CLOBBER of the output, consists of multiple
2645 insns, each setting one word of the output, and followed by a SET copying
2646 the output to itself.
2648 Each of the insns setting words of the output receives a REG_NO_CONFLICT
2649 note indicating that it doesn't conflict with the (also multi-word)
2650 inputs. The entire block is surrounded by REG_LIBCALL and REG_RETVAL
2653 INSNS is a block of code generated to perform the operation, not including
2654 the CLOBBER and final copy. All insns that compute intermediate values
2655 are first emitted, followed by the block as described above.
2657 TARGET, OP0, and OP1 are the output and inputs of the operations,
2658 respectively. OP1 may be zero for a unary operation.
2660 EQUIV, if nonzero, is an expression to be placed into a REG_EQUAL note
2663 If TARGET is not a register, INSNS is simply emitted with no special
2664 processing. Likewise if anything in INSNS is not an INSN or if
2665 there is a libcall block inside INSNS.
2667 The final insn emitted is returned. */
2670 emit_no_conflict_block (rtx insns
, rtx target
, rtx op0
, rtx op1
, rtx equiv
)
2672 rtx prev
, next
, first
, last
, insn
;
2674 if (!REG_P (target
) || reload_in_progress
)
2675 return emit_insn (insns
);
2677 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
2678 if (!NONJUMP_INSN_P (insn
)
2679 || find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
))
2680 return emit_insn (insns
);
2682 /* First emit all insns that do not store into words of the output and remove
2683 these from the list. */
2684 for (insn
= insns
; insn
; insn
= next
)
2689 next
= NEXT_INSN (insn
);
2691 /* Some ports (cris) create a libcall regions at their own. We must
2692 avoid any potential nesting of LIBCALLs. */
2693 if ((note
= find_reg_note (insn
, REG_LIBCALL
, NULL
)) != NULL
)
2694 remove_note (insn
, note
);
2695 if ((note
= find_reg_note (insn
, REG_RETVAL
, NULL
)) != NULL
)
2696 remove_note (insn
, note
);
2698 if (GET_CODE (PATTERN (insn
)) == SET
|| GET_CODE (PATTERN (insn
)) == USE
2699 || GET_CODE (PATTERN (insn
)) == CLOBBER
)
2700 set
= PATTERN (insn
);
2701 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
2703 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
2704 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
2706 set
= XVECEXP (PATTERN (insn
), 0, i
);
2714 if (! reg_overlap_mentioned_p (target
, SET_DEST (set
)))
2716 if (PREV_INSN (insn
))
2717 NEXT_INSN (PREV_INSN (insn
)) = next
;
2722 PREV_INSN (next
) = PREV_INSN (insn
);
2728 prev
= get_last_insn ();
2730 /* Now write the CLOBBER of the output, followed by the setting of each
2731 of the words, followed by the final copy. */
2732 if (target
!= op0
&& target
!= op1
)
2733 emit_insn (gen_rtx_CLOBBER (VOIDmode
, target
));
2735 for (insn
= insns
; insn
; insn
= next
)
2737 next
= NEXT_INSN (insn
);
2740 if (op1
&& REG_P (op1
))
2741 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT
, op1
,
2744 if (op0
&& REG_P (op0
))
2745 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT
, op0
,
2749 if (mov_optab
->handlers
[(int) GET_MODE (target
)].insn_code
2750 != CODE_FOR_nothing
)
2752 last
= emit_move_insn (target
, target
);
2754 set_unique_reg_note (last
, REG_EQUAL
, equiv
);
2758 last
= get_last_insn ();
2760 /* Remove any existing REG_EQUAL note from "last", or else it will
2761 be mistaken for a note referring to the full contents of the
2762 alleged libcall value when found together with the REG_RETVAL
2763 note added below. An existing note can come from an insn
2764 expansion at "last". */
2765 remove_note (last
, find_reg_note (last
, REG_EQUAL
, NULL_RTX
));
2769 first
= get_insns ();
2771 first
= NEXT_INSN (prev
);
2773 /* Encapsulate the block so it gets manipulated as a unit. */
2774 REG_NOTES (first
) = gen_rtx_INSN_LIST (REG_LIBCALL
, last
,
2776 REG_NOTES (last
) = gen_rtx_INSN_LIST (REG_RETVAL
, first
, REG_NOTES (last
));
2781 /* Emit code to make a call to a constant function or a library call.
2783 INSNS is a list containing all insns emitted in the call.
2784 These insns leave the result in RESULT. Our block is to copy RESULT
2785 to TARGET, which is logically equivalent to EQUIV.
2787 We first emit any insns that set a pseudo on the assumption that these are
2788 loading constants into registers; doing so allows them to be safely cse'ed
2789 between blocks. Then we emit all the other insns in the block, followed by
2790 an insn to move RESULT to TARGET. This last insn will have a REQ_EQUAL
2791 note with an operand of EQUIV.
2793 Moving assignments to pseudos outside of the block is done to improve
2794 the generated code, but is not required to generate correct code,
2795 hence being unable to move an assignment is not grounds for not making
2796 a libcall block. There are two reasons why it is safe to leave these
2797 insns inside the block: First, we know that these pseudos cannot be
2798 used in generated RTL outside the block since they are created for
2799 temporary purposes within the block. Second, CSE will not record the
2800 values of anything set inside a libcall block, so we know they must
2801 be dead at the end of the block.
2803 Except for the first group of insns (the ones setting pseudos), the
2804 block is delimited by REG_RETVAL and REG_LIBCALL notes. */
2807 emit_libcall_block (rtx insns
, rtx target
, rtx result
, rtx equiv
)
2809 rtx final_dest
= target
;
2810 rtx prev
, next
, first
, last
, insn
;
2812 /* If this is a reg with REG_USERVAR_P set, then it could possibly turn
2813 into a MEM later. Protect the libcall block from this change. */
2814 if (! REG_P (target
) || REG_USERVAR_P (target
))
2815 target
= gen_reg_rtx (GET_MODE (target
));
2817 /* If we're using non-call exceptions, a libcall corresponding to an
2818 operation that may trap may also trap. */
2819 if (flag_non_call_exceptions
&& may_trap_p (equiv
))
2821 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
2824 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
2826 if (note
!= 0 && INTVAL (XEXP (note
, 0)) <= 0)
2827 remove_note (insn
, note
);
2831 /* look for any CALL_INSNs in this sequence, and attach a REG_EH_REGION
2832 reg note to indicate that this call cannot throw or execute a nonlocal
2833 goto (unless there is already a REG_EH_REGION note, in which case
2835 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
2838 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
2841 XEXP (note
, 0) = constm1_rtx
;
2843 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_EH_REGION
, constm1_rtx
,
2847 /* First emit all insns that set pseudos. Remove them from the list as
2848 we go. Avoid insns that set pseudos which were referenced in previous
2849 insns. These can be generated by move_by_pieces, for example,
2850 to update an address. Similarly, avoid insns that reference things
2851 set in previous insns. */
2853 for (insn
= insns
; insn
; insn
= next
)
2855 rtx set
= single_set (insn
);
2858 /* Some ports (cris) create a libcall regions at their own. We must
2859 avoid any potential nesting of LIBCALLs. */
2860 if ((note
= find_reg_note (insn
, REG_LIBCALL
, NULL
)) != NULL
)
2861 remove_note (insn
, note
);
2862 if ((note
= find_reg_note (insn
, REG_RETVAL
, NULL
)) != NULL
)
2863 remove_note (insn
, note
);
2865 next
= NEXT_INSN (insn
);
2867 if (set
!= 0 && REG_P (SET_DEST (set
))
2868 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
2870 || ((! INSN_P(insns
)
2871 || ! reg_mentioned_p (SET_DEST (set
), PATTERN (insns
)))
2872 && ! reg_used_between_p (SET_DEST (set
), insns
, insn
)
2873 && ! modified_in_p (SET_SRC (set
), insns
)
2874 && ! modified_between_p (SET_SRC (set
), insns
, insn
))))
2876 if (PREV_INSN (insn
))
2877 NEXT_INSN (PREV_INSN (insn
)) = next
;
2882 PREV_INSN (next
) = PREV_INSN (insn
);
2887 /* Some ports use a loop to copy large arguments onto the stack.
2888 Don't move anything outside such a loop. */
2893 prev
= get_last_insn ();
2895 /* Write the remaining insns followed by the final copy. */
2897 for (insn
= insns
; insn
; insn
= next
)
2899 next
= NEXT_INSN (insn
);
2904 last
= emit_move_insn (target
, result
);
2905 if (mov_optab
->handlers
[(int) GET_MODE (target
)].insn_code
2906 != CODE_FOR_nothing
)
2907 set_unique_reg_note (last
, REG_EQUAL
, copy_rtx (equiv
));
2910 /* Remove any existing REG_EQUAL note from "last", or else it will
2911 be mistaken for a note referring to the full contents of the
2912 libcall value when found together with the REG_RETVAL note added
2913 below. An existing note can come from an insn expansion at
2915 remove_note (last
, find_reg_note (last
, REG_EQUAL
, NULL_RTX
));
2918 if (final_dest
!= target
)
2919 emit_move_insn (final_dest
, target
);
2922 first
= get_insns ();
2924 first
= NEXT_INSN (prev
);
2926 /* Encapsulate the block so it gets manipulated as a unit. */
2927 if (!flag_non_call_exceptions
|| !may_trap_p (equiv
))
2929 /* We can't attach the REG_LIBCALL and REG_RETVAL notes
2930 when the encapsulated region would not be in one basic block,
2931 i.e. when there is a control_flow_insn_p insn between FIRST and LAST.
2933 bool attach_libcall_retval_notes
= true;
2934 next
= NEXT_INSN (last
);
2935 for (insn
= first
; insn
!= next
; insn
= NEXT_INSN (insn
))
2936 if (control_flow_insn_p (insn
))
2938 attach_libcall_retval_notes
= false;
2942 if (attach_libcall_retval_notes
)
2944 REG_NOTES (first
) = gen_rtx_INSN_LIST (REG_LIBCALL
, last
,
2946 REG_NOTES (last
) = gen_rtx_INSN_LIST (REG_RETVAL
, first
,
2952 /* Nonzero if we can perform a comparison of mode MODE straightforwardly.
2953 PURPOSE describes how this comparison will be used. CODE is the rtx
2954 comparison code we will be using.
2956 ??? Actually, CODE is slightly weaker than that. A target is still
2957 required to implement all of the normal bcc operations, but not
2958 required to implement all (or any) of the unordered bcc operations. */
2961 can_compare_p (enum rtx_code code
, enum machine_mode mode
,
2962 enum can_compare_purpose purpose
)
2966 if (cmp_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2968 if (purpose
== ccp_jump
)
2969 return bcc_gen_fctn
[(int) code
] != NULL
;
2970 else if (purpose
== ccp_store_flag
)
2971 return setcc_gen_code
[(int) code
] != CODE_FOR_nothing
;
2973 /* There's only one cmov entry point, and it's allowed to fail. */
2976 if (purpose
== ccp_jump
2977 && cbranch_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2979 if (purpose
== ccp_cmov
2980 && cmov_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2982 if (purpose
== ccp_store_flag
2983 && cstore_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2986 mode
= GET_MODE_WIDER_MODE (mode
);
2988 while (mode
!= VOIDmode
);
2993 /* This function is called when we are going to emit a compare instruction that
2994 compares the values found in *PX and *PY, using the rtl operator COMPARISON.
2996 *PMODE is the mode of the inputs (in case they are const_int).
2997 *PUNSIGNEDP nonzero says that the operands are unsigned;
2998 this matters if they need to be widened.
3000 If they have mode BLKmode, then SIZE specifies the size of both operands.
3002 This function performs all the setup necessary so that the caller only has
3003 to emit a single comparison insn. This setup can involve doing a BLKmode
3004 comparison or emitting a library call to perform the comparison if no insn
3005 is available to handle it.
3006 The values which are passed in through pointers can be modified; the caller
3007 should perform the comparison on the modified values. */
3010 prepare_cmp_insn (rtx
*px
, rtx
*py
, enum rtx_code
*pcomparison
, rtx size
,
3011 enum machine_mode
*pmode
, int *punsignedp
,
3012 enum can_compare_purpose purpose
)
3014 enum machine_mode mode
= *pmode
;
3015 rtx x
= *px
, y
= *py
;
3016 int unsignedp
= *punsignedp
;
3017 enum mode_class
class;
3019 class = GET_MODE_CLASS (mode
);
3021 /* They could both be VOIDmode if both args are immediate constants,
3022 but we should fold that at an earlier stage.
3023 With no special code here, this will call abort,
3024 reminding the programmer to implement such folding. */
3026 if (mode
!= BLKmode
&& flag_force_mem
)
3028 /* Load duplicate non-volatile operands once. */
3029 if (rtx_equal_p (x
, y
) && ! volatile_refs_p (x
))
3031 x
= force_not_mem (x
);
3036 x
= force_not_mem (x
);
3037 y
= force_not_mem (y
);
3041 /* If we are inside an appropriately-short loop and we are optimizing,
3042 force expensive constants into a register. */
3043 if (CONSTANT_P (x
) && optimize
3044 && rtx_cost (x
, COMPARE
) > COSTS_N_INSNS (1))
3045 x
= force_reg (mode
, x
);
3047 if (CONSTANT_P (y
) && optimize
3048 && rtx_cost (y
, COMPARE
) > COSTS_N_INSNS (1))
3049 y
= force_reg (mode
, y
);
3052 /* Abort if we have a non-canonical comparison. The RTL documentation
3053 states that canonical comparisons are required only for targets which
3055 if (CONSTANT_P (x
) && ! CONSTANT_P (y
))
3059 /* Don't let both operands fail to indicate the mode. */
3060 if (GET_MODE (x
) == VOIDmode
&& GET_MODE (y
) == VOIDmode
)
3061 x
= force_reg (mode
, x
);
3063 /* Handle all BLKmode compares. */
3065 if (mode
== BLKmode
)
3067 enum machine_mode cmp_mode
, result_mode
;
3068 enum insn_code cmp_code
;
3073 = GEN_INT (MIN (MEM_ALIGN (x
), MEM_ALIGN (y
)) / BITS_PER_UNIT
);
3078 /* Try to use a memory block compare insn - either cmpstr
3079 or cmpmem will do. */
3080 for (cmp_mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
3081 cmp_mode
!= VOIDmode
;
3082 cmp_mode
= GET_MODE_WIDER_MODE (cmp_mode
))
3084 cmp_code
= cmpmem_optab
[cmp_mode
];
3085 if (cmp_code
== CODE_FOR_nothing
)
3086 cmp_code
= cmpstr_optab
[cmp_mode
];
3087 if (cmp_code
== CODE_FOR_nothing
)
3090 /* Must make sure the size fits the insn's mode. */
3091 if ((GET_CODE (size
) == CONST_INT
3092 && INTVAL (size
) >= (1 << GET_MODE_BITSIZE (cmp_mode
)))
3093 || (GET_MODE_BITSIZE (GET_MODE (size
))
3094 > GET_MODE_BITSIZE (cmp_mode
)))
3097 result_mode
= insn_data
[cmp_code
].operand
[0].mode
;
3098 result
= gen_reg_rtx (result_mode
);
3099 size
= convert_to_mode (cmp_mode
, size
, 1);
3100 emit_insn (GEN_FCN (cmp_code
) (result
, x
, y
, size
, opalign
));
3104 *pmode
= result_mode
;
3108 /* Otherwise call a library function, memcmp. */
3109 libfunc
= memcmp_libfunc
;
3110 length_type
= sizetype
;
3111 result_mode
= TYPE_MODE (integer_type_node
);
3112 cmp_mode
= TYPE_MODE (length_type
);
3113 size
= convert_to_mode (TYPE_MODE (length_type
), size
,
3114 TYPE_UNSIGNED (length_type
));
3116 result
= emit_library_call_value (libfunc
, 0, LCT_PURE_MAKE_BLOCK
,
3123 *pmode
= result_mode
;
3127 /* Don't allow operands to the compare to trap, as that can put the
3128 compare and branch in different basic blocks. */
3129 if (flag_non_call_exceptions
)
3132 x
= force_reg (mode
, x
);
3134 y
= force_reg (mode
, y
);
3139 if (can_compare_p (*pcomparison
, mode
, purpose
))
3142 /* Handle a lib call just for the mode we are using. */
3144 if (cmp_optab
->handlers
[(int) mode
].libfunc
&& class != MODE_FLOAT
)
3146 rtx libfunc
= cmp_optab
->handlers
[(int) mode
].libfunc
;
3149 /* If we want unsigned, and this mode has a distinct unsigned
3150 comparison routine, use that. */
3151 if (unsignedp
&& ucmp_optab
->handlers
[(int) mode
].libfunc
)
3152 libfunc
= ucmp_optab
->handlers
[(int) mode
].libfunc
;
3154 result
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST_MAKE_BLOCK
,
3155 word_mode
, 2, x
, mode
, y
, mode
);
3159 if (TARGET_LIB_INT_CMP_BIASED
)
3160 /* Integer comparison returns a result that must be compared
3161 against 1, so that even if we do an unsigned compare
3162 afterward, there is still a value that can represent the
3163 result "less than". */
3173 if (class == MODE_FLOAT
)
3174 prepare_float_lib_cmp (px
, py
, pcomparison
, pmode
, punsignedp
);
3180 /* Before emitting an insn with code ICODE, make sure that X, which is going
3181 to be used for operand OPNUM of the insn, is converted from mode MODE to
3182 WIDER_MODE (UNSIGNEDP determines whether it is an unsigned conversion), and
3183 that it is accepted by the operand predicate. Return the new value. */
3186 prepare_operand (int icode
, rtx x
, int opnum
, enum machine_mode mode
,
3187 enum machine_mode wider_mode
, int unsignedp
)
3189 if (mode
!= wider_mode
)
3190 x
= convert_modes (wider_mode
, mode
, x
, unsignedp
);
3192 if (! (*insn_data
[icode
].operand
[opnum
].predicate
)
3193 (x
, insn_data
[icode
].operand
[opnum
].mode
))
3197 x
= copy_to_mode_reg (insn_data
[icode
].operand
[opnum
].mode
, x
);
3203 /* Subroutine of emit_cmp_and_jump_insns; this function is called when we know
3204 we can do the comparison.
3205 The arguments are the same as for emit_cmp_and_jump_insns; but LABEL may
3206 be NULL_RTX which indicates that only a comparison is to be generated. */
3209 emit_cmp_and_jump_insn_1 (rtx x
, rtx y
, enum machine_mode mode
,
3210 enum rtx_code comparison
, int unsignedp
, rtx label
)
3212 rtx test
= gen_rtx_fmt_ee (comparison
, mode
, x
, y
);
3213 enum mode_class
class = GET_MODE_CLASS (mode
);
3214 enum machine_mode wider_mode
= mode
;
3216 /* Try combined insns first. */
3219 enum insn_code icode
;
3220 PUT_MODE (test
, wider_mode
);
3224 icode
= cbranch_optab
->handlers
[(int) wider_mode
].insn_code
;
3226 if (icode
!= CODE_FOR_nothing
3227 && (*insn_data
[icode
].operand
[0].predicate
) (test
, wider_mode
))
3229 x
= prepare_operand (icode
, x
, 1, mode
, wider_mode
, unsignedp
);
3230 y
= prepare_operand (icode
, y
, 2, mode
, wider_mode
, unsignedp
);
3231 emit_jump_insn (GEN_FCN (icode
) (test
, x
, y
, label
));
3236 /* Handle some compares against zero. */
3237 icode
= (int) tst_optab
->handlers
[(int) wider_mode
].insn_code
;
3238 if (y
== CONST0_RTX (mode
) && icode
!= CODE_FOR_nothing
)
3240 x
= prepare_operand (icode
, x
, 0, mode
, wider_mode
, unsignedp
);
3241 emit_insn (GEN_FCN (icode
) (x
));
3243 emit_jump_insn ((*bcc_gen_fctn
[(int) comparison
]) (label
));
3247 /* Handle compares for which there is a directly suitable insn. */
3249 icode
= (int) cmp_optab
->handlers
[(int) wider_mode
].insn_code
;
3250 if (icode
!= CODE_FOR_nothing
)
3252 x
= prepare_operand (icode
, x
, 0, mode
, wider_mode
, unsignedp
);
3253 y
= prepare_operand (icode
, y
, 1, mode
, wider_mode
, unsignedp
);
3254 emit_insn (GEN_FCN (icode
) (x
, y
));
3256 emit_jump_insn ((*bcc_gen_fctn
[(int) comparison
]) (label
));
3260 if (class != MODE_INT
&& class != MODE_FLOAT
3261 && class != MODE_COMPLEX_FLOAT
)
3264 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
);
3266 while (wider_mode
!= VOIDmode
);
3271 /* Generate code to compare X with Y so that the condition codes are
3272 set and to jump to LABEL if the condition is true. If X is a
3273 constant and Y is not a constant, then the comparison is swapped to
3274 ensure that the comparison RTL has the canonical form.
3276 UNSIGNEDP nonzero says that X and Y are unsigned; this matters if they
3277 need to be widened by emit_cmp_insn. UNSIGNEDP is also used to select
3278 the proper branch condition code.
3280 If X and Y have mode BLKmode, then SIZE specifies the size of both X and Y.
3282 MODE is the mode of the inputs (in case they are const_int).
3284 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). It will
3285 be passed unchanged to emit_cmp_insn, then potentially converted into an
3286 unsigned variant based on UNSIGNEDP to select a proper jump instruction. */
3289 emit_cmp_and_jump_insns (rtx x
, rtx y
, enum rtx_code comparison
, rtx size
,
3290 enum machine_mode mode
, int unsignedp
, rtx label
)
3292 rtx op0
= x
, op1
= y
;
3294 /* Swap operands and condition to ensure canonical RTL. */
3295 if (swap_commutative_operands_p (x
, y
))
3297 /* If we're not emitting a branch, this means some caller
3303 comparison
= swap_condition (comparison
);
3307 /* If OP0 is still a constant, then both X and Y must be constants. Force
3308 X into a register to avoid aborting in emit_cmp_insn due to non-canonical
3310 if (CONSTANT_P (op0
))
3311 op0
= force_reg (mode
, op0
);
3315 comparison
= unsigned_condition (comparison
);
3317 prepare_cmp_insn (&op0
, &op1
, &comparison
, size
, &mode
, &unsignedp
,
3319 emit_cmp_and_jump_insn_1 (op0
, op1
, mode
, comparison
, unsignedp
, label
);
3322 /* Like emit_cmp_and_jump_insns, but generate only the comparison. */
3325 emit_cmp_insn (rtx x
, rtx y
, enum rtx_code comparison
, rtx size
,
3326 enum machine_mode mode
, int unsignedp
)
3328 emit_cmp_and_jump_insns (x
, y
, comparison
, size
, mode
, unsignedp
, 0);
3331 /* Emit a library call comparison between floating point X and Y.
3332 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). */
3335 prepare_float_lib_cmp (rtx
*px
, rtx
*py
, enum rtx_code
*pcomparison
,
3336 enum machine_mode
*pmode
, int *punsignedp
)
3338 enum rtx_code comparison
= *pcomparison
;
3339 enum rtx_code swapped
= swap_condition (comparison
);
3340 enum rtx_code reversed
= reverse_condition_maybe_unordered (comparison
);
3343 enum machine_mode orig_mode
= GET_MODE (x
);
3344 enum machine_mode mode
;
3345 rtx value
, target
, insns
, equiv
;
3347 bool reversed_p
= false;
3349 for (mode
= orig_mode
; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3351 if ((libfunc
= code_to_optab
[comparison
]->handlers
[mode
].libfunc
))
3354 if ((libfunc
= code_to_optab
[swapped
]->handlers
[mode
].libfunc
))
3357 tmp
= x
; x
= y
; y
= tmp
;
3358 comparison
= swapped
;
3362 if ((libfunc
= code_to_optab
[reversed
]->handlers
[mode
].libfunc
)
3363 && FLOAT_LIB_COMPARE_RETURNS_BOOL (mode
, reversed
))
3365 comparison
= reversed
;
3371 if (mode
== VOIDmode
)
3374 if (mode
!= orig_mode
)
3376 x
= convert_to_mode (mode
, x
, 0);
3377 y
= convert_to_mode (mode
, y
, 0);
3380 /* Attach a REG_EQUAL note describing the semantics of the libcall to
3381 the RTL. The allows the RTL optimizers to delete the libcall if the
3382 condition can be determined at compile-time. */
3383 if (comparison
== UNORDERED
)
3385 rtx temp
= simplify_gen_relational (NE
, word_mode
, mode
, x
, x
);
3386 equiv
= simplify_gen_relational (NE
, word_mode
, mode
, y
, y
);
3387 equiv
= simplify_gen_ternary (IF_THEN_ELSE
, word_mode
, word_mode
,
3388 temp
, const_true_rtx
, equiv
);
3392 equiv
= simplify_gen_relational (comparison
, word_mode
, mode
, x
, y
);
3393 if (! FLOAT_LIB_COMPARE_RETURNS_BOOL (mode
, comparison
))
3395 rtx true_rtx
, false_rtx
;
3400 true_rtx
= const0_rtx
;
3401 false_rtx
= const_true_rtx
;
3405 true_rtx
= const_true_rtx
;
3406 false_rtx
= const0_rtx
;
3410 true_rtx
= const1_rtx
;
3411 false_rtx
= const0_rtx
;
3415 true_rtx
= const0_rtx
;
3416 false_rtx
= constm1_rtx
;
3420 true_rtx
= constm1_rtx
;
3421 false_rtx
= const0_rtx
;
3425 true_rtx
= const0_rtx
;
3426 false_rtx
= const1_rtx
;
3432 equiv
= simplify_gen_ternary (IF_THEN_ELSE
, word_mode
, word_mode
,
3433 equiv
, true_rtx
, false_rtx
);
3438 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
3439 word_mode
, 2, x
, mode
, y
, mode
);
3440 insns
= get_insns ();
3443 target
= gen_reg_rtx (word_mode
);
3444 emit_libcall_block (insns
, target
, value
, equiv
);
3446 if (comparison
== UNORDERED
3447 || FLOAT_LIB_COMPARE_RETURNS_BOOL (mode
, comparison
))
3448 comparison
= reversed_p
? EQ
: NE
;
3453 *pcomparison
= comparison
;
3457 /* Generate code to indirectly jump to a location given in the rtx LOC. */
3460 emit_indirect_jump (rtx loc
)
3462 if (! ((*insn_data
[(int) CODE_FOR_indirect_jump
].operand
[0].predicate
)
3464 loc
= copy_to_mode_reg (Pmode
, loc
);
3466 emit_jump_insn (gen_indirect_jump (loc
));
3470 #ifdef HAVE_conditional_move
3472 /* Emit a conditional move instruction if the machine supports one for that
3473 condition and machine mode.
3475 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
3476 the mode to use should they be constants. If it is VOIDmode, they cannot
3479 OP2 should be stored in TARGET if the comparison is true, otherwise OP3
3480 should be stored there. MODE is the mode to use should they be constants.
3481 If it is VOIDmode, they cannot both be constants.
3483 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
3484 is not supported. */
3487 emit_conditional_move (rtx target
, enum rtx_code code
, rtx op0
, rtx op1
,
3488 enum machine_mode cmode
, rtx op2
, rtx op3
,
3489 enum machine_mode mode
, int unsignedp
)
3491 rtx tem
, subtarget
, comparison
, insn
;
3492 enum insn_code icode
;
3493 enum rtx_code reversed
;
3495 /* If one operand is constant, make it the second one. Only do this
3496 if the other operand is not constant as well. */
3498 if (swap_commutative_operands_p (op0
, op1
))
3503 code
= swap_condition (code
);
3506 /* get_condition will prefer to generate LT and GT even if the old
3507 comparison was against zero, so undo that canonicalization here since
3508 comparisons against zero are cheaper. */
3509 if (code
== LT
&& op1
== const1_rtx
)
3510 code
= LE
, op1
= const0_rtx
;
3511 else if (code
== GT
&& op1
== constm1_rtx
)
3512 code
= GE
, op1
= const0_rtx
;
3514 if (cmode
== VOIDmode
)
3515 cmode
= GET_MODE (op0
);
3517 if (swap_commutative_operands_p (op2
, op3
)
3518 && ((reversed
= reversed_comparison_code_parts (code
, op0
, op1
, NULL
))
3527 if (mode
== VOIDmode
)
3528 mode
= GET_MODE (op2
);
3530 icode
= movcc_gen_code
[mode
];
3532 if (icode
== CODE_FOR_nothing
)
3537 op2
= force_not_mem (op2
);
3538 op3
= force_not_mem (op3
);
3542 target
= gen_reg_rtx (mode
);
3546 /* If the insn doesn't accept these operands, put them in pseudos. */
3548 if (! (*insn_data
[icode
].operand
[0].predicate
)
3549 (subtarget
, insn_data
[icode
].operand
[0].mode
))
3550 subtarget
= gen_reg_rtx (insn_data
[icode
].operand
[0].mode
);
3552 if (! (*insn_data
[icode
].operand
[2].predicate
)
3553 (op2
, insn_data
[icode
].operand
[2].mode
))
3554 op2
= copy_to_mode_reg (insn_data
[icode
].operand
[2].mode
, op2
);
3556 if (! (*insn_data
[icode
].operand
[3].predicate
)
3557 (op3
, insn_data
[icode
].operand
[3].mode
))
3558 op3
= copy_to_mode_reg (insn_data
[icode
].operand
[3].mode
, op3
);
3560 /* Everything should now be in the suitable form, so emit the compare insn
3561 and then the conditional move. */
3564 = compare_from_rtx (op0
, op1
, code
, unsignedp
, cmode
, NULL_RTX
);
3566 /* ??? Watch for const0_rtx (nop) and const_true_rtx (unconditional)? */
3567 /* We can get const0_rtx or const_true_rtx in some circumstances. Just
3568 return NULL and let the caller figure out how best to deal with this
3570 if (GET_CODE (comparison
) != code
)
3573 insn
= GEN_FCN (icode
) (subtarget
, comparison
, op2
, op3
);
3575 /* If that failed, then give up. */
3581 if (subtarget
!= target
)
3582 convert_move (target
, subtarget
, 0);
3587 /* Return nonzero if a conditional move of mode MODE is supported.
3589 This function is for combine so it can tell whether an insn that looks
3590 like a conditional move is actually supported by the hardware. If we
3591 guess wrong we lose a bit on optimization, but that's it. */
3592 /* ??? sparc64 supports conditionally moving integers values based on fp
3593 comparisons, and vice versa. How do we handle them? */
3596 can_conditionally_move_p (enum machine_mode mode
)
3598 if (movcc_gen_code
[mode
] != CODE_FOR_nothing
)
3604 #endif /* HAVE_conditional_move */
3606 /* Emit a conditional addition instruction if the machine supports one for that
3607 condition and machine mode.
3609 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
3610 the mode to use should they be constants. If it is VOIDmode, they cannot
3613 OP2 should be stored in TARGET if the comparison is true, otherwise OP2+OP3
3614 should be stored there. MODE is the mode to use should they be constants.
3615 If it is VOIDmode, they cannot both be constants.
3617 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
3618 is not supported. */
3621 emit_conditional_add (rtx target
, enum rtx_code code
, rtx op0
, rtx op1
,
3622 enum machine_mode cmode
, rtx op2
, rtx op3
,
3623 enum machine_mode mode
, int unsignedp
)
3625 rtx tem
, subtarget
, comparison
, insn
;
3626 enum insn_code icode
;
3627 enum rtx_code reversed
;
3629 /* If one operand is constant, make it the second one. Only do this
3630 if the other operand is not constant as well. */
3632 if (swap_commutative_operands_p (op0
, op1
))
3637 code
= swap_condition (code
);
3640 /* get_condition will prefer to generate LT and GT even if the old
3641 comparison was against zero, so undo that canonicalization here since
3642 comparisons against zero are cheaper. */
3643 if (code
== LT
&& op1
== const1_rtx
)
3644 code
= LE
, op1
= const0_rtx
;
3645 else if (code
== GT
&& op1
== constm1_rtx
)
3646 code
= GE
, op1
= const0_rtx
;
3648 if (cmode
== VOIDmode
)
3649 cmode
= GET_MODE (op0
);
3651 if (swap_commutative_operands_p (op2
, op3
)
3652 && ((reversed
= reversed_comparison_code_parts (code
, op0
, op1
, NULL
))
3661 if (mode
== VOIDmode
)
3662 mode
= GET_MODE (op2
);
3664 icode
= addcc_optab
->handlers
[(int) mode
].insn_code
;
3666 if (icode
== CODE_FOR_nothing
)
3671 op2
= force_not_mem (op2
);
3672 op3
= force_not_mem (op3
);
3676 target
= gen_reg_rtx (mode
);
3678 /* If the insn doesn't accept these operands, put them in pseudos. */
3680 if (! (*insn_data
[icode
].operand
[0].predicate
)
3681 (target
, insn_data
[icode
].operand
[0].mode
))
3682 subtarget
= gen_reg_rtx (insn_data
[icode
].operand
[0].mode
);
3686 if (! (*insn_data
[icode
].operand
[2].predicate
)
3687 (op2
, insn_data
[icode
].operand
[2].mode
))
3688 op2
= copy_to_mode_reg (insn_data
[icode
].operand
[2].mode
, op2
);
3690 if (! (*insn_data
[icode
].operand
[3].predicate
)
3691 (op3
, insn_data
[icode
].operand
[3].mode
))
3692 op3
= copy_to_mode_reg (insn_data
[icode
].operand
[3].mode
, op3
);
3694 /* Everything should now be in the suitable form, so emit the compare insn
3695 and then the conditional move. */
3698 = compare_from_rtx (op0
, op1
, code
, unsignedp
, cmode
, NULL_RTX
);
3700 /* ??? Watch for const0_rtx (nop) and const_true_rtx (unconditional)? */
3701 /* We can get const0_rtx or const_true_rtx in some circumstances. Just
3702 return NULL and let the caller figure out how best to deal with this
3704 if (GET_CODE (comparison
) != code
)
3707 insn
= GEN_FCN (icode
) (subtarget
, comparison
, op2
, op3
);
3709 /* If that failed, then give up. */
3715 if (subtarget
!= target
)
3716 convert_move (target
, subtarget
, 0);
3721 /* These functions attempt to generate an insn body, rather than
3722 emitting the insn, but if the gen function already emits them, we
3723 make no attempt to turn them back into naked patterns. */
3725 /* Generate and return an insn body to add Y to X. */
3728 gen_add2_insn (rtx x
, rtx y
)
3730 int icode
= (int) add_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
3732 if (! ((*insn_data
[icode
].operand
[0].predicate
)
3733 (x
, insn_data
[icode
].operand
[0].mode
))
3734 || ! ((*insn_data
[icode
].operand
[1].predicate
)
3735 (x
, insn_data
[icode
].operand
[1].mode
))
3736 || ! ((*insn_data
[icode
].operand
[2].predicate
)
3737 (y
, insn_data
[icode
].operand
[2].mode
)))
3740 return (GEN_FCN (icode
) (x
, x
, y
));
3743 /* Generate and return an insn body to add r1 and c,
3744 storing the result in r0. */
3746 gen_add3_insn (rtx r0
, rtx r1
, rtx c
)
3748 int icode
= (int) add_optab
->handlers
[(int) GET_MODE (r0
)].insn_code
;
3750 if (icode
== CODE_FOR_nothing
3751 || ! ((*insn_data
[icode
].operand
[0].predicate
)
3752 (r0
, insn_data
[icode
].operand
[0].mode
))
3753 || ! ((*insn_data
[icode
].operand
[1].predicate
)
3754 (r1
, insn_data
[icode
].operand
[1].mode
))
3755 || ! ((*insn_data
[icode
].operand
[2].predicate
)
3756 (c
, insn_data
[icode
].operand
[2].mode
)))
3759 return (GEN_FCN (icode
) (r0
, r1
, c
));
3763 have_add2_insn (rtx x
, rtx y
)
3767 if (GET_MODE (x
) == VOIDmode
)
3770 icode
= (int) add_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
3772 if (icode
== CODE_FOR_nothing
)
3775 if (! ((*insn_data
[icode
].operand
[0].predicate
)
3776 (x
, insn_data
[icode
].operand
[0].mode
))
3777 || ! ((*insn_data
[icode
].operand
[1].predicate
)
3778 (x
, insn_data
[icode
].operand
[1].mode
))
3779 || ! ((*insn_data
[icode
].operand
[2].predicate
)
3780 (y
, insn_data
[icode
].operand
[2].mode
)))
3786 /* Generate and return an insn body to subtract Y from X. */
3789 gen_sub2_insn (rtx x
, rtx y
)
3791 int icode
= (int) sub_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
3793 if (! ((*insn_data
[icode
].operand
[0].predicate
)
3794 (x
, insn_data
[icode
].operand
[0].mode
))
3795 || ! ((*insn_data
[icode
].operand
[1].predicate
)
3796 (x
, insn_data
[icode
].operand
[1].mode
))
3797 || ! ((*insn_data
[icode
].operand
[2].predicate
)
3798 (y
, insn_data
[icode
].operand
[2].mode
)))
3801 return (GEN_FCN (icode
) (x
, x
, y
));
3804 /* Generate and return an insn body to subtract r1 and c,
3805 storing the result in r0. */
3807 gen_sub3_insn (rtx r0
, rtx r1
, rtx c
)
3809 int icode
= (int) sub_optab
->handlers
[(int) GET_MODE (r0
)].insn_code
;
3811 if (icode
== CODE_FOR_nothing
3812 || ! ((*insn_data
[icode
].operand
[0].predicate
)
3813 (r0
, insn_data
[icode
].operand
[0].mode
))
3814 || ! ((*insn_data
[icode
].operand
[1].predicate
)
3815 (r1
, insn_data
[icode
].operand
[1].mode
))
3816 || ! ((*insn_data
[icode
].operand
[2].predicate
)
3817 (c
, insn_data
[icode
].operand
[2].mode
)))
3820 return (GEN_FCN (icode
) (r0
, r1
, c
));
3824 have_sub2_insn (rtx x
, rtx y
)
3828 if (GET_MODE (x
) == VOIDmode
)
3831 icode
= (int) sub_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
3833 if (icode
== CODE_FOR_nothing
)
3836 if (! ((*insn_data
[icode
].operand
[0].predicate
)
3837 (x
, insn_data
[icode
].operand
[0].mode
))
3838 || ! ((*insn_data
[icode
].operand
[1].predicate
)
3839 (x
, insn_data
[icode
].operand
[1].mode
))
3840 || ! ((*insn_data
[icode
].operand
[2].predicate
)
3841 (y
, insn_data
[icode
].operand
[2].mode
)))
3847 /* Generate the body of an instruction to copy Y into X.
3848 It may be a list of insns, if one insn isn't enough. */
3851 gen_move_insn (rtx x
, rtx y
)
3856 emit_move_insn_1 (x
, y
);
3862 /* Return the insn code used to extend FROM_MODE to TO_MODE.
3863 UNSIGNEDP specifies zero-extension instead of sign-extension. If
3864 no such operation exists, CODE_FOR_nothing will be returned. */
3867 can_extend_p (enum machine_mode to_mode
, enum machine_mode from_mode
,
3871 #ifdef HAVE_ptr_extend
3873 return CODE_FOR_ptr_extend
;
3876 tab
= unsignedp
? zext_optab
: sext_optab
;
3877 return tab
->handlers
[to_mode
][from_mode
].insn_code
;
3880 /* Generate the body of an insn to extend Y (with mode MFROM)
3881 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
3884 gen_extend_insn (rtx x
, rtx y
, enum machine_mode mto
,
3885 enum machine_mode mfrom
, int unsignedp
)
3887 enum insn_code icode
= can_extend_p (mto
, mfrom
, unsignedp
);
3888 return GEN_FCN (icode
) (x
, y
);
3891 /* can_fix_p and can_float_p say whether the target machine
3892 can directly convert a given fixed point type to
3893 a given floating point type, or vice versa.
3894 The returned value is the CODE_FOR_... value to use,
3895 or CODE_FOR_nothing if these modes cannot be directly converted.
3897 *TRUNCP_PTR is set to 1 if it is necessary to output
3898 an explicit FTRUNC insn before the fix insn; otherwise 0. */
3900 static enum insn_code
3901 can_fix_p (enum machine_mode fixmode
, enum machine_mode fltmode
,
3902 int unsignedp
, int *truncp_ptr
)
3905 enum insn_code icode
;
3907 tab
= unsignedp
? ufixtrunc_optab
: sfixtrunc_optab
;
3908 icode
= tab
->handlers
[fixmode
][fltmode
].insn_code
;
3909 if (icode
!= CODE_FOR_nothing
)
3915 /* FIXME: This requires a port to define both FIX and FTRUNC pattern
3916 for this to work. We need to rework the fix* and ftrunc* patterns
3917 and documentation. */
3918 tab
= unsignedp
? ufix_optab
: sfix_optab
;
3919 icode
= tab
->handlers
[fixmode
][fltmode
].insn_code
;
3920 if (icode
!= CODE_FOR_nothing
3921 && ftrunc_optab
->handlers
[fltmode
].insn_code
!= CODE_FOR_nothing
)
3928 return CODE_FOR_nothing
;
3931 static enum insn_code
3932 can_float_p (enum machine_mode fltmode
, enum machine_mode fixmode
,
3937 tab
= unsignedp
? ufloat_optab
: sfloat_optab
;
3938 return tab
->handlers
[fltmode
][fixmode
].insn_code
;
3941 /* Generate code to convert FROM to floating point
3942 and store in TO. FROM must be fixed point and not VOIDmode.
3943 UNSIGNEDP nonzero means regard FROM as unsigned.
3944 Normally this is done by correcting the final value
3945 if it is negative. */
3948 expand_float (rtx to
, rtx from
, int unsignedp
)
3950 enum insn_code icode
;
3952 enum machine_mode fmode
, imode
;
3954 /* Crash now, because we won't be able to decide which mode to use. */
3955 if (GET_MODE (from
) == VOIDmode
)
3958 /* Look for an insn to do the conversion. Do it in the specified
3959 modes if possible; otherwise convert either input, output or both to
3960 wider mode. If the integer mode is wider than the mode of FROM,
3961 we can do the conversion signed even if the input is unsigned. */
3963 for (fmode
= GET_MODE (to
); fmode
!= VOIDmode
;
3964 fmode
= GET_MODE_WIDER_MODE (fmode
))
3965 for (imode
= GET_MODE (from
); imode
!= VOIDmode
;
3966 imode
= GET_MODE_WIDER_MODE (imode
))
3968 int doing_unsigned
= unsignedp
;
3970 if (fmode
!= GET_MODE (to
)
3971 && significand_size (fmode
) < GET_MODE_BITSIZE (GET_MODE (from
)))
3974 icode
= can_float_p (fmode
, imode
, unsignedp
);
3975 if (icode
== CODE_FOR_nothing
&& imode
!= GET_MODE (from
) && unsignedp
)
3976 icode
= can_float_p (fmode
, imode
, 0), doing_unsigned
= 0;
3978 if (icode
!= CODE_FOR_nothing
)
3980 if (imode
!= GET_MODE (from
))
3981 from
= convert_to_mode (imode
, from
, unsignedp
);
3983 if (fmode
!= GET_MODE (to
))
3984 target
= gen_reg_rtx (fmode
);
3986 emit_unop_insn (icode
, target
, from
,
3987 doing_unsigned
? UNSIGNED_FLOAT
: FLOAT
);
3990 convert_move (to
, target
, 0);
3995 /* Unsigned integer, and no way to convert directly.
3996 Convert as signed, then conditionally adjust the result. */
3999 rtx label
= gen_label_rtx ();
4001 REAL_VALUE_TYPE offset
;
4004 from
= force_not_mem (from
);
4006 /* Look for a usable floating mode FMODE wider than the source and at
4007 least as wide as the target. Using FMODE will avoid rounding woes
4008 with unsigned values greater than the signed maximum value. */
4010 for (fmode
= GET_MODE (to
); fmode
!= VOIDmode
;
4011 fmode
= GET_MODE_WIDER_MODE (fmode
))
4012 if (GET_MODE_BITSIZE (GET_MODE (from
)) < GET_MODE_BITSIZE (fmode
)
4013 && can_float_p (fmode
, GET_MODE (from
), 0) != CODE_FOR_nothing
)
4016 if (fmode
== VOIDmode
)
4018 /* There is no such mode. Pretend the target is wide enough. */
4019 fmode
= GET_MODE (to
);
4021 /* Avoid double-rounding when TO is narrower than FROM. */
4022 if ((significand_size (fmode
) + 1)
4023 < GET_MODE_BITSIZE (GET_MODE (from
)))
4026 rtx neglabel
= gen_label_rtx ();
4028 /* Don't use TARGET if it isn't a register, is a hard register,
4029 or is the wrong mode. */
4031 || REGNO (target
) < FIRST_PSEUDO_REGISTER
4032 || GET_MODE (target
) != fmode
)
4033 target
= gen_reg_rtx (fmode
);
4035 imode
= GET_MODE (from
);
4036 do_pending_stack_adjust ();
4038 /* Test whether the sign bit is set. */
4039 emit_cmp_and_jump_insns (from
, const0_rtx
, LT
, NULL_RTX
, imode
,
4042 /* The sign bit is not set. Convert as signed. */
4043 expand_float (target
, from
, 0);
4044 emit_jump_insn (gen_jump (label
));
4047 /* The sign bit is set.
4048 Convert to a usable (positive signed) value by shifting right
4049 one bit, while remembering if a nonzero bit was shifted
4050 out; i.e., compute (from & 1) | (from >> 1). */
4052 emit_label (neglabel
);
4053 temp
= expand_binop (imode
, and_optab
, from
, const1_rtx
,
4054 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
4055 temp1
= expand_shift (RSHIFT_EXPR
, imode
, from
, integer_one_node
,
4057 temp
= expand_binop (imode
, ior_optab
, temp
, temp1
, temp
, 1,
4059 expand_float (target
, temp
, 0);
4061 /* Multiply by 2 to undo the shift above. */
4062 temp
= expand_binop (fmode
, add_optab
, target
, target
,
4063 target
, 0, OPTAB_LIB_WIDEN
);
4065 emit_move_insn (target
, temp
);
4067 do_pending_stack_adjust ();
4073 /* If we are about to do some arithmetic to correct for an
4074 unsigned operand, do it in a pseudo-register. */
4076 if (GET_MODE (to
) != fmode
4077 || !REG_P (to
) || REGNO (to
) < FIRST_PSEUDO_REGISTER
)
4078 target
= gen_reg_rtx (fmode
);
4080 /* Convert as signed integer to floating. */
4081 expand_float (target
, from
, 0);
4083 /* If FROM is negative (and therefore TO is negative),
4084 correct its value by 2**bitwidth. */
4086 do_pending_stack_adjust ();
4087 emit_cmp_and_jump_insns (from
, const0_rtx
, GE
, NULL_RTX
, GET_MODE (from
),
4091 real_2expN (&offset
, GET_MODE_BITSIZE (GET_MODE (from
)));
4092 temp
= expand_binop (fmode
, add_optab
, target
,
4093 CONST_DOUBLE_FROM_REAL_VALUE (offset
, fmode
),
4094 target
, 0, OPTAB_LIB_WIDEN
);
4096 emit_move_insn (target
, temp
);
4098 do_pending_stack_adjust ();
4103 /* No hardware instruction available; call a library routine. */
4108 convert_optab tab
= unsignedp
? ufloat_optab
: sfloat_optab
;
4110 if (GET_MODE_SIZE (GET_MODE (from
)) < GET_MODE_SIZE (SImode
))
4111 from
= convert_to_mode (SImode
, from
, unsignedp
);
4114 from
= force_not_mem (from
);
4116 libfunc
= tab
->handlers
[GET_MODE (to
)][GET_MODE (from
)].libfunc
;
4122 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
4123 GET_MODE (to
), 1, from
,
4125 insns
= get_insns ();
4128 emit_libcall_block (insns
, target
, value
,
4129 gen_rtx_FLOAT (GET_MODE (to
), from
));
4134 /* Copy result to requested destination
4135 if we have been computing in a temp location. */
4139 if (GET_MODE (target
) == GET_MODE (to
))
4140 emit_move_insn (to
, target
);
4142 convert_move (to
, target
, 0);
4146 /* Generate code to convert FROM to fixed point and store in TO. FROM
4147 must be floating point. */
4150 expand_fix (rtx to
, rtx from
, int unsignedp
)
4152 enum insn_code icode
;
4154 enum machine_mode fmode
, imode
;
4157 /* We first try to find a pair of modes, one real and one integer, at
4158 least as wide as FROM and TO, respectively, in which we can open-code
4159 this conversion. If the integer mode is wider than the mode of TO,
4160 we can do the conversion either signed or unsigned. */
4162 for (fmode
= GET_MODE (from
); fmode
!= VOIDmode
;
4163 fmode
= GET_MODE_WIDER_MODE (fmode
))
4164 for (imode
= GET_MODE (to
); imode
!= VOIDmode
;
4165 imode
= GET_MODE_WIDER_MODE (imode
))
4167 int doing_unsigned
= unsignedp
;
4169 icode
= can_fix_p (imode
, fmode
, unsignedp
, &must_trunc
);
4170 if (icode
== CODE_FOR_nothing
&& imode
!= GET_MODE (to
) && unsignedp
)
4171 icode
= can_fix_p (imode
, fmode
, 0, &must_trunc
), doing_unsigned
= 0;
4173 if (icode
!= CODE_FOR_nothing
)
4175 if (fmode
!= GET_MODE (from
))
4176 from
= convert_to_mode (fmode
, from
, 0);
4180 rtx temp
= gen_reg_rtx (GET_MODE (from
));
4181 from
= expand_unop (GET_MODE (from
), ftrunc_optab
, from
,
4185 if (imode
!= GET_MODE (to
))
4186 target
= gen_reg_rtx (imode
);
4188 emit_unop_insn (icode
, target
, from
,
4189 doing_unsigned
? UNSIGNED_FIX
: FIX
);
4191 convert_move (to
, target
, unsignedp
);
4196 /* For an unsigned conversion, there is one more way to do it.
4197 If we have a signed conversion, we generate code that compares
4198 the real value to the largest representable positive number. If if
4199 is smaller, the conversion is done normally. Otherwise, subtract
4200 one plus the highest signed number, convert, and add it back.
4202 We only need to check all real modes, since we know we didn't find
4203 anything with a wider integer mode.
4205 This code used to extend FP value into mode wider than the destination.
4206 This is not needed. Consider, for instance conversion from SFmode
4209 The hot path trought the code is dealing with inputs smaller than 2^63
4210 and doing just the conversion, so there is no bits to lose.
4212 In the other path we know the value is positive in the range 2^63..2^64-1
4213 inclusive. (as for other imput overflow happens and result is undefined)
4214 So we know that the most important bit set in mantissa corresponds to
4215 2^63. The subtraction of 2^63 should not generate any rounding as it
4216 simply clears out that bit. The rest is trivial. */
4218 if (unsignedp
&& GET_MODE_BITSIZE (GET_MODE (to
)) <= HOST_BITS_PER_WIDE_INT
)
4219 for (fmode
= GET_MODE (from
); fmode
!= VOIDmode
;
4220 fmode
= GET_MODE_WIDER_MODE (fmode
))
4221 if (CODE_FOR_nothing
!= can_fix_p (GET_MODE (to
), fmode
, 0,
4225 REAL_VALUE_TYPE offset
;
4226 rtx limit
, lab1
, lab2
, insn
;
4228 bitsize
= GET_MODE_BITSIZE (GET_MODE (to
));
4229 real_2expN (&offset
, bitsize
- 1);
4230 limit
= CONST_DOUBLE_FROM_REAL_VALUE (offset
, fmode
);
4231 lab1
= gen_label_rtx ();
4232 lab2
= gen_label_rtx ();
4235 from
= force_not_mem (from
);
4237 if (fmode
!= GET_MODE (from
))
4238 from
= convert_to_mode (fmode
, from
, 0);
4240 /* See if we need to do the subtraction. */
4241 do_pending_stack_adjust ();
4242 emit_cmp_and_jump_insns (from
, limit
, GE
, NULL_RTX
, GET_MODE (from
),
4245 /* If not, do the signed "fix" and branch around fixup code. */
4246 expand_fix (to
, from
, 0);
4247 emit_jump_insn (gen_jump (lab2
));
4250 /* Otherwise, subtract 2**(N-1), convert to signed number,
4251 then add 2**(N-1). Do the addition using XOR since this
4252 will often generate better code. */
4254 target
= expand_binop (GET_MODE (from
), sub_optab
, from
, limit
,
4255 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4256 expand_fix (to
, target
, 0);
4257 target
= expand_binop (GET_MODE (to
), xor_optab
, to
,
4259 ((HOST_WIDE_INT
) 1 << (bitsize
- 1),
4261 to
, 1, OPTAB_LIB_WIDEN
);
4264 emit_move_insn (to
, target
);
4268 if (mov_optab
->handlers
[(int) GET_MODE (to
)].insn_code
4269 != CODE_FOR_nothing
)
4271 /* Make a place for a REG_NOTE and add it. */
4272 insn
= emit_move_insn (to
, to
);
4273 set_unique_reg_note (insn
,
4275 gen_rtx_fmt_e (UNSIGNED_FIX
,
4283 /* We can't do it with an insn, so use a library call. But first ensure
4284 that the mode of TO is at least as wide as SImode, since those are the
4285 only library calls we know about. */
4287 if (GET_MODE_SIZE (GET_MODE (to
)) < GET_MODE_SIZE (SImode
))
4289 target
= gen_reg_rtx (SImode
);
4291 expand_fix (target
, from
, unsignedp
);
4299 convert_optab tab
= unsignedp
? ufix_optab
: sfix_optab
;
4300 libfunc
= tab
->handlers
[GET_MODE (to
)][GET_MODE (from
)].libfunc
;
4305 from
= force_not_mem (from
);
4309 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
4310 GET_MODE (to
), 1, from
,
4312 insns
= get_insns ();
4315 emit_libcall_block (insns
, target
, value
,
4316 gen_rtx_fmt_e (unsignedp
? UNSIGNED_FIX
: FIX
,
4317 GET_MODE (to
), from
));
4322 if (GET_MODE (to
) == GET_MODE (target
))
4323 emit_move_insn (to
, target
);
4325 convert_move (to
, target
, 0);
4329 /* Report whether we have an instruction to perform the operation
4330 specified by CODE on operands of mode MODE. */
4332 have_insn_for (enum rtx_code code
, enum machine_mode mode
)
4334 return (code_to_optab
[(int) code
] != 0
4335 && (code_to_optab
[(int) code
]->handlers
[(int) mode
].insn_code
4336 != CODE_FOR_nothing
));
4339 /* Create a blank optab. */
4344 optab op
= ggc_alloc (sizeof (struct optab
));
4345 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
4347 op
->handlers
[i
].insn_code
= CODE_FOR_nothing
;
4348 op
->handlers
[i
].libfunc
= 0;
4354 static convert_optab
4355 new_convert_optab (void)
4358 convert_optab op
= ggc_alloc (sizeof (struct convert_optab
));
4359 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
4360 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
4362 op
->handlers
[i
][j
].insn_code
= CODE_FOR_nothing
;
4363 op
->handlers
[i
][j
].libfunc
= 0;
4368 /* Same, but fill in its code as CODE, and write it into the
4369 code_to_optab table. */
4371 init_optab (enum rtx_code code
)
4373 optab op
= new_optab ();
4375 code_to_optab
[(int) code
] = op
;
4379 /* Same, but fill in its code as CODE, and do _not_ write it into
4380 the code_to_optab table. */
4382 init_optabv (enum rtx_code code
)
4384 optab op
= new_optab ();
4389 /* Conversion optabs never go in the code_to_optab table. */
4390 static inline convert_optab
4391 init_convert_optab (enum rtx_code code
)
4393 convert_optab op
= new_convert_optab ();
4398 /* Initialize the libfunc fields of an entire group of entries in some
4399 optab. Each entry is set equal to a string consisting of a leading
4400 pair of underscores followed by a generic operation name followed by
4401 a mode name (downshifted to lowercase) followed by a single character
4402 representing the number of operands for the given operation (which is
4403 usually one of the characters '2', '3', or '4').
4405 OPTABLE is the table in which libfunc fields are to be initialized.
4406 FIRST_MODE is the first machine mode index in the given optab to
4408 LAST_MODE is the last machine mode index in the given optab to
4410 OPNAME is the generic (string) name of the operation.
4411 SUFFIX is the character which specifies the number of operands for
4412 the given generic operation.
4416 init_libfuncs (optab optable
, int first_mode
, int last_mode
,
4417 const char *opname
, int suffix
)
4420 unsigned opname_len
= strlen (opname
);
4422 for (mode
= first_mode
; (int) mode
<= (int) last_mode
;
4423 mode
= (enum machine_mode
) ((int) mode
+ 1))
4425 const char *mname
= GET_MODE_NAME (mode
);
4426 unsigned mname_len
= strlen (mname
);
4427 char *libfunc_name
= alloca (2 + opname_len
+ mname_len
+ 1 + 1);
4434 for (q
= opname
; *q
; )
4436 for (q
= mname
; *q
; q
++)
4437 *p
++ = TOLOWER (*q
);
4441 optable
->handlers
[(int) mode
].libfunc
4442 = init_one_libfunc (ggc_alloc_string (libfunc_name
, p
- libfunc_name
));
4446 /* Initialize the libfunc fields of an entire group of entries in some
4447 optab which correspond to all integer mode operations. The parameters
4448 have the same meaning as similarly named ones for the `init_libfuncs'
4449 routine. (See above). */
4452 init_integral_libfuncs (optab optable
, const char *opname
, int suffix
)
4454 int maxsize
= 2*BITS_PER_WORD
;
4455 if (maxsize
< LONG_LONG_TYPE_SIZE
)
4456 maxsize
= LONG_LONG_TYPE_SIZE
;
4457 init_libfuncs (optable
, word_mode
,
4458 mode_for_size (maxsize
, MODE_INT
, 0),
4462 /* Initialize the libfunc fields of an entire group of entries in some
4463 optab which correspond to all real mode operations. The parameters
4464 have the same meaning as similarly named ones for the `init_libfuncs'
4465 routine. (See above). */
4468 init_floating_libfuncs (optab optable
, const char *opname
, int suffix
)
4470 init_libfuncs (optable
, MIN_MODE_FLOAT
, MAX_MODE_FLOAT
, opname
, suffix
);
4473 /* Initialize the libfunc fields of an entire group of entries of an
4474 inter-mode-class conversion optab. The string formation rules are
4475 similar to the ones for init_libfuncs, above, but instead of having
4476 a mode name and an operand count these functions have two mode names
4477 and no operand count. */
4479 init_interclass_conv_libfuncs (convert_optab tab
, const char *opname
,
4480 enum mode_class from_class
,
4481 enum mode_class to_class
)
4483 enum machine_mode first_from_mode
= GET_CLASS_NARROWEST_MODE (from_class
);
4484 enum machine_mode first_to_mode
= GET_CLASS_NARROWEST_MODE (to_class
);
4485 size_t opname_len
= strlen (opname
);
4486 size_t max_mname_len
= 0;
4488 enum machine_mode fmode
, tmode
;
4489 const char *fname
, *tname
;
4491 char *libfunc_name
, *suffix
;
4494 for (fmode
= first_from_mode
;
4496 fmode
= GET_MODE_WIDER_MODE (fmode
))
4497 max_mname_len
= MAX (max_mname_len
, strlen (GET_MODE_NAME (fmode
)));
4499 for (tmode
= first_to_mode
;
4501 tmode
= GET_MODE_WIDER_MODE (tmode
))
4502 max_mname_len
= MAX (max_mname_len
, strlen (GET_MODE_NAME (tmode
)));
4504 libfunc_name
= alloca (2 + opname_len
+ 2*max_mname_len
+ 1 + 1);
4505 libfunc_name
[0] = '_';
4506 libfunc_name
[1] = '_';
4507 memcpy (&libfunc_name
[2], opname
, opname_len
);
4508 suffix
= libfunc_name
+ opname_len
+ 2;
4510 for (fmode
= first_from_mode
; fmode
!= VOIDmode
;
4511 fmode
= GET_MODE_WIDER_MODE (fmode
))
4512 for (tmode
= first_to_mode
; tmode
!= VOIDmode
;
4513 tmode
= GET_MODE_WIDER_MODE (tmode
))
4515 fname
= GET_MODE_NAME (fmode
);
4516 tname
= GET_MODE_NAME (tmode
);
4519 for (q
= fname
; *q
; p
++, q
++)
4521 for (q
= tname
; *q
; p
++, q
++)
4526 tab
->handlers
[tmode
][fmode
].libfunc
4527 = init_one_libfunc (ggc_alloc_string (libfunc_name
,
4532 /* Initialize the libfunc fields of an entire group of entries of an
4533 intra-mode-class conversion optab. The string formation rules are
4534 similar to the ones for init_libfunc, above. WIDENING says whether
4535 the optab goes from narrow to wide modes or vice versa. These functions
4536 have two mode names _and_ an operand count. */
4538 init_intraclass_conv_libfuncs (convert_optab tab
, const char *opname
,
4539 enum mode_class
class, bool widening
)
4541 enum machine_mode first_mode
= GET_CLASS_NARROWEST_MODE (class);
4542 size_t opname_len
= strlen (opname
);
4543 size_t max_mname_len
= 0;
4545 enum machine_mode nmode
, wmode
;
4546 const char *nname
, *wname
;
4548 char *libfunc_name
, *suffix
;
4551 for (nmode
= first_mode
; nmode
!= VOIDmode
;
4552 nmode
= GET_MODE_WIDER_MODE (nmode
))
4553 max_mname_len
= MAX (max_mname_len
, strlen (GET_MODE_NAME (nmode
)));
4555 libfunc_name
= alloca (2 + opname_len
+ 2*max_mname_len
+ 1 + 1);
4556 libfunc_name
[0] = '_';
4557 libfunc_name
[1] = '_';
4558 memcpy (&libfunc_name
[2], opname
, opname_len
);
4559 suffix
= libfunc_name
+ opname_len
+ 2;
4561 for (nmode
= first_mode
; nmode
!= VOIDmode
;
4562 nmode
= GET_MODE_WIDER_MODE (nmode
))
4563 for (wmode
= GET_MODE_WIDER_MODE (nmode
); wmode
!= VOIDmode
;
4564 wmode
= GET_MODE_WIDER_MODE (wmode
))
4566 nname
= GET_MODE_NAME (nmode
);
4567 wname
= GET_MODE_NAME (wmode
);
4570 for (q
= widening
? nname
: wname
; *q
; p
++, q
++)
4572 for (q
= widening
? wname
: nname
; *q
; p
++, q
++)
4578 tab
->handlers
[widening
? wmode
: nmode
]
4579 [widening
? nmode
: wmode
].libfunc
4580 = init_one_libfunc (ggc_alloc_string (libfunc_name
,
4587 init_one_libfunc (const char *name
)
4591 /* Create a FUNCTION_DECL that can be passed to
4592 targetm.encode_section_info. */
4593 /* ??? We don't have any type information except for this is
4594 a function. Pretend this is "int foo()". */
4595 tree decl
= build_decl (FUNCTION_DECL
, get_identifier (name
),
4596 build_function_type (integer_type_node
, NULL_TREE
));
4597 DECL_ARTIFICIAL (decl
) = 1;
4598 DECL_EXTERNAL (decl
) = 1;
4599 TREE_PUBLIC (decl
) = 1;
4601 symbol
= XEXP (DECL_RTL (decl
), 0);
4603 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
4604 are the flags assigned by targetm.encode_section_info. */
4605 SYMBOL_REF_DECL (symbol
) = 0;
4610 /* Call this to reset the function entry for one optab (OPTABLE) in mode
4611 MODE to NAME, which should be either 0 or a string constant. */
4613 set_optab_libfunc (optab optable
, enum machine_mode mode
, const char *name
)
4616 optable
->handlers
[mode
].libfunc
= init_one_libfunc (name
);
4618 optable
->handlers
[mode
].libfunc
= 0;
4621 /* Call this to reset the function entry for one conversion optab
4622 (OPTABLE) from mode FMODE to mode TMODE to NAME, which should be
4623 either 0 or a string constant. */
4625 set_conv_libfunc (convert_optab optable
, enum machine_mode tmode
,
4626 enum machine_mode fmode
, const char *name
)
4629 optable
->handlers
[tmode
][fmode
].libfunc
= init_one_libfunc (name
);
4631 optable
->handlers
[tmode
][fmode
].libfunc
= 0;
4634 /* Call this once to initialize the contents of the optabs
4635 appropriately for the current target machine. */
4642 /* Start by initializing all tables to contain CODE_FOR_nothing. */
4644 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
4645 setcc_gen_code
[i
] = CODE_FOR_nothing
;
4647 #ifdef HAVE_conditional_move
4648 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
4649 movcc_gen_code
[i
] = CODE_FOR_nothing
;
4652 add_optab
= init_optab (PLUS
);
4653 addv_optab
= init_optabv (PLUS
);
4654 sub_optab
= init_optab (MINUS
);
4655 subv_optab
= init_optabv (MINUS
);
4656 smul_optab
= init_optab (MULT
);
4657 smulv_optab
= init_optabv (MULT
);
4658 smul_highpart_optab
= init_optab (UNKNOWN
);
4659 umul_highpart_optab
= init_optab (UNKNOWN
);
4660 smul_widen_optab
= init_optab (UNKNOWN
);
4661 umul_widen_optab
= init_optab (UNKNOWN
);
4662 sdiv_optab
= init_optab (DIV
);
4663 sdivv_optab
= init_optabv (DIV
);
4664 sdivmod_optab
= init_optab (UNKNOWN
);
4665 udiv_optab
= init_optab (UDIV
);
4666 udivmod_optab
= init_optab (UNKNOWN
);
4667 smod_optab
= init_optab (MOD
);
4668 umod_optab
= init_optab (UMOD
);
4669 fmod_optab
= init_optab (UNKNOWN
);
4670 drem_optab
= init_optab (UNKNOWN
);
4671 ftrunc_optab
= init_optab (UNKNOWN
);
4672 and_optab
= init_optab (AND
);
4673 ior_optab
= init_optab (IOR
);
4674 xor_optab
= init_optab (XOR
);
4675 ashl_optab
= init_optab (ASHIFT
);
4676 ashr_optab
= init_optab (ASHIFTRT
);
4677 lshr_optab
= init_optab (LSHIFTRT
);
4678 rotl_optab
= init_optab (ROTATE
);
4679 rotr_optab
= init_optab (ROTATERT
);
4680 smin_optab
= init_optab (SMIN
);
4681 smax_optab
= init_optab (SMAX
);
4682 umin_optab
= init_optab (UMIN
);
4683 umax_optab
= init_optab (UMAX
);
4684 pow_optab
= init_optab (UNKNOWN
);
4685 atan2_optab
= init_optab (UNKNOWN
);
4687 /* These three have codes assigned exclusively for the sake of
4689 mov_optab
= init_optab (SET
);
4690 movstrict_optab
= init_optab (STRICT_LOW_PART
);
4691 cmp_optab
= init_optab (COMPARE
);
4693 ucmp_optab
= init_optab (UNKNOWN
);
4694 tst_optab
= init_optab (UNKNOWN
);
4696 eq_optab
= init_optab (EQ
);
4697 ne_optab
= init_optab (NE
);
4698 gt_optab
= init_optab (GT
);
4699 ge_optab
= init_optab (GE
);
4700 lt_optab
= init_optab (LT
);
4701 le_optab
= init_optab (LE
);
4702 unord_optab
= init_optab (UNORDERED
);
4704 neg_optab
= init_optab (NEG
);
4705 negv_optab
= init_optabv (NEG
);
4706 abs_optab
= init_optab (ABS
);
4707 absv_optab
= init_optabv (ABS
);
4708 addcc_optab
= init_optab (UNKNOWN
);
4709 one_cmpl_optab
= init_optab (NOT
);
4710 ffs_optab
= init_optab (FFS
);
4711 clz_optab
= init_optab (CLZ
);
4712 ctz_optab
= init_optab (CTZ
);
4713 popcount_optab
= init_optab (POPCOUNT
);
4714 parity_optab
= init_optab (PARITY
);
4715 sqrt_optab
= init_optab (SQRT
);
4716 floor_optab
= init_optab (UNKNOWN
);
4717 ceil_optab
= init_optab (UNKNOWN
);
4718 round_optab
= init_optab (UNKNOWN
);
4719 btrunc_optab
= init_optab (UNKNOWN
);
4720 nearbyint_optab
= init_optab (UNKNOWN
);
4721 rint_optab
= init_optab (UNKNOWN
);
4722 sincos_optab
= init_optab (UNKNOWN
);
4723 sin_optab
= init_optab (UNKNOWN
);
4724 asin_optab
= init_optab (UNKNOWN
);
4725 cos_optab
= init_optab (UNKNOWN
);
4726 acos_optab
= init_optab (UNKNOWN
);
4727 exp_optab
= init_optab (UNKNOWN
);
4728 exp10_optab
= init_optab (UNKNOWN
);
4729 exp2_optab
= init_optab (UNKNOWN
);
4730 expm1_optab
= init_optab (UNKNOWN
);
4731 logb_optab
= init_optab (UNKNOWN
);
4732 ilogb_optab
= init_optab (UNKNOWN
);
4733 log_optab
= init_optab (UNKNOWN
);
4734 log10_optab
= init_optab (UNKNOWN
);
4735 log2_optab
= init_optab (UNKNOWN
);
4736 log1p_optab
= init_optab (UNKNOWN
);
4737 tan_optab
= init_optab (UNKNOWN
);
4738 atan_optab
= init_optab (UNKNOWN
);
4739 strlen_optab
= init_optab (UNKNOWN
);
4740 cbranch_optab
= init_optab (UNKNOWN
);
4741 cmov_optab
= init_optab (UNKNOWN
);
4742 cstore_optab
= init_optab (UNKNOWN
);
4743 push_optab
= init_optab (UNKNOWN
);
4745 vec_extract_optab
= init_optab (UNKNOWN
);
4746 vec_set_optab
= init_optab (UNKNOWN
);
4747 vec_init_optab
= init_optab (UNKNOWN
);
4748 vec_realign_load_optab
= init_optab (UNKNOWN
);
4751 sext_optab
= init_convert_optab (SIGN_EXTEND
);
4752 zext_optab
= init_convert_optab (ZERO_EXTEND
);
4753 trunc_optab
= init_convert_optab (TRUNCATE
);
4754 sfix_optab
= init_convert_optab (FIX
);
4755 ufix_optab
= init_convert_optab (UNSIGNED_FIX
);
4756 sfixtrunc_optab
= init_convert_optab (UNKNOWN
);
4757 ufixtrunc_optab
= init_convert_optab (UNKNOWN
);
4758 sfloat_optab
= init_convert_optab (FLOAT
);
4759 ufloat_optab
= init_convert_optab (UNSIGNED_FLOAT
);
4761 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
4763 movmem_optab
[i
] = CODE_FOR_nothing
;
4764 clrmem_optab
[i
] = CODE_FOR_nothing
;
4765 cmpstr_optab
[i
] = CODE_FOR_nothing
;
4766 cmpmem_optab
[i
] = CODE_FOR_nothing
;
4768 #ifdef HAVE_SECONDARY_RELOADS
4769 reload_in_optab
[i
] = reload_out_optab
[i
] = CODE_FOR_nothing
;
4773 /* Fill in the optabs with the insns we support. */
4776 /* Initialize the optabs with the names of the library functions. */
4777 init_integral_libfuncs (add_optab
, "add", '3');
4778 init_floating_libfuncs (add_optab
, "add", '3');
4779 init_integral_libfuncs (addv_optab
, "addv", '3');
4780 init_floating_libfuncs (addv_optab
, "add", '3');
4781 init_integral_libfuncs (sub_optab
, "sub", '3');
4782 init_floating_libfuncs (sub_optab
, "sub", '3');
4783 init_integral_libfuncs (subv_optab
, "subv", '3');
4784 init_floating_libfuncs (subv_optab
, "sub", '3');
4785 init_integral_libfuncs (smul_optab
, "mul", '3');
4786 init_floating_libfuncs (smul_optab
, "mul", '3');
4787 init_integral_libfuncs (smulv_optab
, "mulv", '3');
4788 init_floating_libfuncs (smulv_optab
, "mul", '3');
4789 init_integral_libfuncs (sdiv_optab
, "div", '3');
4790 init_floating_libfuncs (sdiv_optab
, "div", '3');
4791 init_integral_libfuncs (sdivv_optab
, "divv", '3');
4792 init_integral_libfuncs (udiv_optab
, "udiv", '3');
4793 init_integral_libfuncs (sdivmod_optab
, "divmod", '4');
4794 init_integral_libfuncs (udivmod_optab
, "udivmod", '4');
4795 init_integral_libfuncs (smod_optab
, "mod", '3');
4796 init_integral_libfuncs (umod_optab
, "umod", '3');
4797 init_floating_libfuncs (ftrunc_optab
, "ftrunc", '2');
4798 init_integral_libfuncs (and_optab
, "and", '3');
4799 init_integral_libfuncs (ior_optab
, "ior", '3');
4800 init_integral_libfuncs (xor_optab
, "xor", '3');
4801 init_integral_libfuncs (ashl_optab
, "ashl", '3');
4802 init_integral_libfuncs (ashr_optab
, "ashr", '3');
4803 init_integral_libfuncs (lshr_optab
, "lshr", '3');
4804 init_integral_libfuncs (smin_optab
, "min", '3');
4805 init_floating_libfuncs (smin_optab
, "min", '3');
4806 init_integral_libfuncs (smax_optab
, "max", '3');
4807 init_floating_libfuncs (smax_optab
, "max", '3');
4808 init_integral_libfuncs (umin_optab
, "umin", '3');
4809 init_integral_libfuncs (umax_optab
, "umax", '3');
4810 init_integral_libfuncs (neg_optab
, "neg", '2');
4811 init_floating_libfuncs (neg_optab
, "neg", '2');
4812 init_integral_libfuncs (negv_optab
, "negv", '2');
4813 init_floating_libfuncs (negv_optab
, "neg", '2');
4814 init_integral_libfuncs (one_cmpl_optab
, "one_cmpl", '2');
4815 init_integral_libfuncs (ffs_optab
, "ffs", '2');
4816 init_integral_libfuncs (clz_optab
, "clz", '2');
4817 init_integral_libfuncs (ctz_optab
, "ctz", '2');
4818 init_integral_libfuncs (popcount_optab
, "popcount", '2');
4819 init_integral_libfuncs (parity_optab
, "parity", '2');
4821 /* Comparison libcalls for integers MUST come in pairs,
4823 init_integral_libfuncs (cmp_optab
, "cmp", '2');
4824 init_integral_libfuncs (ucmp_optab
, "ucmp", '2');
4825 init_floating_libfuncs (cmp_optab
, "cmp", '2');
4827 /* EQ etc are floating point only. */
4828 init_floating_libfuncs (eq_optab
, "eq", '2');
4829 init_floating_libfuncs (ne_optab
, "ne", '2');
4830 init_floating_libfuncs (gt_optab
, "gt", '2');
4831 init_floating_libfuncs (ge_optab
, "ge", '2');
4832 init_floating_libfuncs (lt_optab
, "lt", '2');
4833 init_floating_libfuncs (le_optab
, "le", '2');
4834 init_floating_libfuncs (unord_optab
, "unord", '2');
4837 init_interclass_conv_libfuncs (sfloat_optab
, "float",
4838 MODE_INT
, MODE_FLOAT
);
4839 init_interclass_conv_libfuncs (sfix_optab
, "fix",
4840 MODE_FLOAT
, MODE_INT
);
4841 init_interclass_conv_libfuncs (ufix_optab
, "fixuns",
4842 MODE_FLOAT
, MODE_INT
);
4844 /* sext_optab is also used for FLOAT_EXTEND. */
4845 init_intraclass_conv_libfuncs (sext_optab
, "extend", MODE_FLOAT
, true);
4846 init_intraclass_conv_libfuncs (trunc_optab
, "trunc", MODE_FLOAT
, false);
4848 /* Use cabs for double complex abs, since systems generally have cabs.
4849 Don't define any libcall for float complex, so that cabs will be used. */
4850 if (complex_double_type_node
)
4851 abs_optab
->handlers
[TYPE_MODE (complex_double_type_node
)].libfunc
4852 = init_one_libfunc ("cabs");
4854 /* The ffs function operates on `int'. */
4855 ffs_optab
->handlers
[(int) mode_for_size (INT_TYPE_SIZE
, MODE_INT
, 0)].libfunc
4856 = init_one_libfunc ("ffs");
4858 abort_libfunc
= init_one_libfunc ("abort");
4859 memcpy_libfunc
= init_one_libfunc ("memcpy");
4860 memmove_libfunc
= init_one_libfunc ("memmove");
4861 memcmp_libfunc
= init_one_libfunc ("memcmp");
4862 memset_libfunc
= init_one_libfunc ("memset");
4863 setbits_libfunc
= init_one_libfunc ("__setbits");
4865 unwind_resume_libfunc
= init_one_libfunc (USING_SJLJ_EXCEPTIONS
4866 ? "_Unwind_SjLj_Resume"
4867 : "_Unwind_Resume");
4868 #ifndef DONT_USE_BUILTIN_SETJMP
4869 setjmp_libfunc
= init_one_libfunc ("__builtin_setjmp");
4870 longjmp_libfunc
= init_one_libfunc ("__builtin_longjmp");
4872 setjmp_libfunc
= init_one_libfunc ("setjmp");
4873 longjmp_libfunc
= init_one_libfunc ("longjmp");
4875 unwind_sjlj_register_libfunc
= init_one_libfunc ("_Unwind_SjLj_Register");
4876 unwind_sjlj_unregister_libfunc
4877 = init_one_libfunc ("_Unwind_SjLj_Unregister");
4879 /* For function entry/exit instrumentation. */
4880 profile_function_entry_libfunc
4881 = init_one_libfunc ("__cyg_profile_func_enter");
4882 profile_function_exit_libfunc
4883 = init_one_libfunc ("__cyg_profile_func_exit");
4885 gcov_flush_libfunc
= init_one_libfunc ("__gcov_flush");
4887 if (HAVE_conditional_trap
)
4888 trap_rtx
= gen_rtx_fmt_ee (EQ
, VOIDmode
, NULL_RTX
, NULL_RTX
);
4890 /* Allow the target to add more libcalls or rename some, etc. */
4891 targetm
.init_libfuncs ();
4896 /* Print information about the current contents of the optabs on
4900 debug_optab_libfuncs (void)
4906 /* Dump the arithmetic optabs. */
4907 for (i
= 0; i
!= (int) OTI_MAX
; i
++)
4908 for (j
= 0; j
< NUM_MACHINE_MODES
; ++j
)
4911 struct optab_handlers
*h
;
4914 h
= &o
->handlers
[j
];
4917 if (GET_CODE (h
->libfunc
) != SYMBOL_REF
)
4919 fprintf (stderr
, "%s\t%s:\t%s\n",
4920 GET_RTX_NAME (o
->code
),
4922 XSTR (h
->libfunc
, 0));
4926 /* Dump the conversion optabs. */
4927 for (i
= 0; i
< (int) CTI_MAX
; ++i
)
4928 for (j
= 0; j
< NUM_MACHINE_MODES
; ++j
)
4929 for (k
= 0; k
< NUM_MACHINE_MODES
; ++k
)
4932 struct optab_handlers
*h
;
4934 o
= &convert_optab_table
[i
];
4935 h
= &o
->handlers
[j
][k
];
4938 if (GET_CODE (h
->libfunc
) != SYMBOL_REF
)
4940 fprintf (stderr
, "%s\t%s\t%s:\t%s\n",
4941 GET_RTX_NAME (o
->code
),
4944 XSTR (h
->libfunc
, 0));
4952 /* Generate insns to trap with code TCODE if OP1 and OP2 satisfy condition
4953 CODE. Return 0 on failure. */
4956 gen_cond_trap (enum rtx_code code ATTRIBUTE_UNUSED
, rtx op1
,
4957 rtx op2 ATTRIBUTE_UNUSED
, rtx tcode ATTRIBUTE_UNUSED
)
4959 enum machine_mode mode
= GET_MODE (op1
);
4960 enum insn_code icode
;
4963 if (!HAVE_conditional_trap
)
4966 if (mode
== VOIDmode
)
4969 icode
= cmp_optab
->handlers
[(int) mode
].insn_code
;
4970 if (icode
== CODE_FOR_nothing
)
4974 op1
= prepare_operand (icode
, op1
, 0, mode
, mode
, 0);
4975 op2
= prepare_operand (icode
, op2
, 1, mode
, mode
, 0);
4981 emit_insn (GEN_FCN (icode
) (op1
, op2
));
4983 PUT_CODE (trap_rtx
, code
);
4984 insn
= gen_conditional_trap (trap_rtx
, tcode
);
4988 insn
= get_insns ();
4995 #include "gt-optabs.h"