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, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
27 #include "diagnostic-core.h"
29 /* Include insn-config.h before expr.h so that HAVE_conditional_move
30 is properly defined. */
31 #include "insn-config.h"
44 #include "basic-block.h"
47 struct target_optabs default_target_optabs
;
48 struct target_libfuncs default_target_libfuncs
;
50 struct target_optabs
*this_target_optabs
= &default_target_optabs
;
51 struct target_libfuncs
*this_target_libfuncs
= &default_target_libfuncs
;
54 #define libfunc_hash \
55 (this_target_libfuncs->x_libfunc_hash)
57 /* Contains the optab used for each rtx code. */
58 optab code_to_optab
[NUM_RTX_CODE
+ 1];
60 static void prepare_float_lib_cmp (rtx
, rtx
, enum rtx_code
, rtx
*,
62 static rtx
expand_unop_direct (enum machine_mode
, optab
, rtx
, rtx
, int);
64 /* Debug facility for use in GDB. */
65 void debug_optab_libfuncs (void);
67 /* Prefixes for the current version of decimal floating point (BID vs. DPD) */
68 #if ENABLE_DECIMAL_BID_FORMAT
69 #define DECIMAL_PREFIX "bid_"
71 #define DECIMAL_PREFIX "dpd_"
74 /* Used for libfunc_hash. */
77 hash_libfunc (const void *p
)
79 const struct libfunc_entry
*const e
= (const struct libfunc_entry
*) p
;
81 return (((int) e
->mode1
+ (int) e
->mode2
* NUM_MACHINE_MODES
)
85 /* Used for libfunc_hash. */
88 eq_libfunc (const void *p
, const void *q
)
90 const struct libfunc_entry
*const e1
= (const struct libfunc_entry
*) p
;
91 const struct libfunc_entry
*const e2
= (const struct libfunc_entry
*) q
;
93 return (e1
->optab
== e2
->optab
94 && e1
->mode1
== e2
->mode1
95 && e1
->mode2
== e2
->mode2
);
98 /* Return libfunc corresponding operation defined by OPTAB converting
99 from MODE2 to MODE1. Trigger lazy initialization if needed, return NULL
100 if no libfunc is available. */
102 convert_optab_libfunc (convert_optab optab
, enum machine_mode mode1
,
103 enum machine_mode mode2
)
105 struct libfunc_entry e
;
106 struct libfunc_entry
**slot
;
108 e
.optab
= (size_t) (optab
- &convert_optab_table
[0]);
111 slot
= (struct libfunc_entry
**) htab_find_slot (libfunc_hash
, &e
, NO_INSERT
);
114 if (optab
->libcall_gen
)
116 optab
->libcall_gen (optab
, optab
->libcall_basename
, mode1
, mode2
);
117 slot
= (struct libfunc_entry
**) htab_find_slot (libfunc_hash
, &e
, NO_INSERT
);
119 return (*slot
)->libfunc
;
125 return (*slot
)->libfunc
;
128 /* Return libfunc corresponding operation defined by OPTAB in MODE.
129 Trigger lazy initialization if needed, return NULL if no libfunc is
132 optab_libfunc (optab optab
, enum machine_mode mode
)
134 struct libfunc_entry e
;
135 struct libfunc_entry
**slot
;
137 e
.optab
= (size_t) (optab
- &optab_table
[0]);
140 slot
= (struct libfunc_entry
**) htab_find_slot (libfunc_hash
, &e
, NO_INSERT
);
143 if (optab
->libcall_gen
)
145 optab
->libcall_gen (optab
, optab
->libcall_basename
,
146 optab
->libcall_suffix
, mode
);
147 slot
= (struct libfunc_entry
**) htab_find_slot (libfunc_hash
,
150 return (*slot
)->libfunc
;
156 return (*slot
)->libfunc
;
160 /* Add a REG_EQUAL note to the last insn in INSNS. TARGET is being set to
161 the result of operation CODE applied to OP0 (and OP1 if it is a binary
164 If the last insn does not set TARGET, don't do anything, but return 1.
166 If a previous insn sets TARGET and TARGET is one of OP0 or OP1,
167 don't add the REG_EQUAL note but return 0. Our caller can then try
168 again, ensuring that TARGET is not one of the operands. */
171 add_equal_note (rtx insns
, rtx target
, enum rtx_code code
, rtx op0
, rtx op1
)
173 rtx last_insn
, insn
, set
;
176 gcc_assert (insns
&& INSN_P (insns
) && NEXT_INSN (insns
));
178 if (GET_RTX_CLASS (code
) != RTX_COMM_ARITH
179 && GET_RTX_CLASS (code
) != RTX_BIN_ARITH
180 && GET_RTX_CLASS (code
) != RTX_COMM_COMPARE
181 && GET_RTX_CLASS (code
) != RTX_COMPARE
182 && GET_RTX_CLASS (code
) != RTX_UNARY
)
185 if (GET_CODE (target
) == ZERO_EXTRACT
)
188 for (last_insn
= insns
;
189 NEXT_INSN (last_insn
) != NULL_RTX
;
190 last_insn
= NEXT_INSN (last_insn
))
193 set
= single_set (last_insn
);
197 if (! rtx_equal_p (SET_DEST (set
), target
)
198 /* For a STRICT_LOW_PART, the REG_NOTE applies to what is inside it. */
199 && (GET_CODE (SET_DEST (set
)) != STRICT_LOW_PART
200 || ! rtx_equal_p (XEXP (SET_DEST (set
), 0), target
)))
203 /* If TARGET is in OP0 or OP1, check if anything in SEQ sets TARGET
204 besides the last insn. */
205 if (reg_overlap_mentioned_p (target
, op0
)
206 || (op1
&& reg_overlap_mentioned_p (target
, op1
)))
208 insn
= PREV_INSN (last_insn
);
209 while (insn
!= NULL_RTX
)
211 if (reg_set_p (target
, insn
))
214 insn
= PREV_INSN (insn
);
218 if (GET_RTX_CLASS (code
) == RTX_UNARY
)
219 note
= gen_rtx_fmt_e (code
, GET_MODE (target
), copy_rtx (op0
));
221 note
= gen_rtx_fmt_ee (code
, GET_MODE (target
), copy_rtx (op0
), copy_rtx (op1
));
223 set_unique_reg_note (last_insn
, REG_EQUAL
, note
);
228 /* Widen OP to MODE and return the rtx for the widened operand. UNSIGNEDP
229 says whether OP is signed or unsigned. NO_EXTEND is nonzero if we need
230 not actually do a sign-extend or zero-extend, but can leave the
231 higher-order bits of the result rtx undefined, for example, in the case
232 of logical operations, but not right shifts. */
235 widen_operand (rtx op
, enum machine_mode mode
, enum machine_mode oldmode
,
236 int unsignedp
, int no_extend
)
240 /* If we don't have to extend and this is a constant, return it. */
241 if (no_extend
&& GET_MODE (op
) == VOIDmode
)
244 /* If we must extend do so. If OP is a SUBREG for a promoted object, also
245 extend since it will be more efficient to do so unless the signedness of
246 a promoted object differs from our extension. */
248 || (GET_CODE (op
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (op
)
249 && SUBREG_PROMOTED_UNSIGNED_P (op
) == unsignedp
))
250 return convert_modes (mode
, oldmode
, op
, unsignedp
);
252 /* If MODE is no wider than a single word, we return a paradoxical
254 if (GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
)
255 return gen_rtx_SUBREG (mode
, force_reg (GET_MODE (op
), op
), 0);
257 /* Otherwise, get an object of MODE, clobber it, and set the low-order
260 result
= gen_reg_rtx (mode
);
261 emit_clobber (result
);
262 emit_move_insn (gen_lowpart (GET_MODE (op
), result
), op
);
266 /* Return the optab used for computing the operation given by the tree code,
267 CODE and the tree EXP. This function is not always usable (for example, it
268 cannot give complete results for multiplication or division) but probably
269 ought to be relied on more widely throughout the expander. */
271 optab_for_tree_code (enum tree_code code
, const_tree type
,
272 enum optab_subtype subtype
)
284 return one_cmpl_optab
;
293 return TYPE_UNSIGNED (type
) ? umod_optab
: smod_optab
;
301 if (TYPE_SATURATING(type
))
302 return TYPE_UNSIGNED(type
) ? usdiv_optab
: ssdiv_optab
;
303 return TYPE_UNSIGNED (type
) ? udiv_optab
: sdiv_optab
;
306 if (TREE_CODE (type
) == VECTOR_TYPE
)
308 if (subtype
== optab_vector
)
309 return TYPE_SATURATING (type
) ? NULL
: vashl_optab
;
311 gcc_assert (subtype
== optab_scalar
);
313 if (TYPE_SATURATING(type
))
314 return TYPE_UNSIGNED(type
) ? usashl_optab
: ssashl_optab
;
318 if (TREE_CODE (type
) == VECTOR_TYPE
)
320 if (subtype
== optab_vector
)
321 return TYPE_UNSIGNED (type
) ? vlshr_optab
: vashr_optab
;
323 gcc_assert (subtype
== optab_scalar
);
325 return TYPE_UNSIGNED (type
) ? lshr_optab
: ashr_optab
;
328 if (TREE_CODE (type
) == VECTOR_TYPE
)
330 if (subtype
== optab_vector
)
333 gcc_assert (subtype
== optab_scalar
);
338 if (TREE_CODE (type
) == VECTOR_TYPE
)
340 if (subtype
== optab_vector
)
343 gcc_assert (subtype
== optab_scalar
);
348 return TYPE_UNSIGNED (type
) ? umax_optab
: smax_optab
;
351 return TYPE_UNSIGNED (type
) ? umin_optab
: smin_optab
;
353 case REALIGN_LOAD_EXPR
:
354 return vec_realign_load_optab
;
357 return TYPE_UNSIGNED (type
) ? usum_widen_optab
: ssum_widen_optab
;
360 return TYPE_UNSIGNED (type
) ? udot_prod_optab
: sdot_prod_optab
;
362 case WIDEN_MULT_PLUS_EXPR
:
363 return (TYPE_UNSIGNED (type
)
364 ? (TYPE_SATURATING (type
)
365 ? usmadd_widen_optab
: umadd_widen_optab
)
366 : (TYPE_SATURATING (type
)
367 ? ssmadd_widen_optab
: smadd_widen_optab
));
369 case WIDEN_MULT_MINUS_EXPR
:
370 return (TYPE_UNSIGNED (type
)
371 ? (TYPE_SATURATING (type
)
372 ? usmsub_widen_optab
: umsub_widen_optab
)
373 : (TYPE_SATURATING (type
)
374 ? ssmsub_widen_optab
: smsub_widen_optab
));
380 return TYPE_UNSIGNED (type
) ? reduc_umax_optab
: reduc_smax_optab
;
383 return TYPE_UNSIGNED (type
) ? reduc_umin_optab
: reduc_smin_optab
;
385 case REDUC_PLUS_EXPR
:
386 return TYPE_UNSIGNED (type
) ? reduc_uplus_optab
: reduc_splus_optab
;
388 case VEC_LSHIFT_EXPR
:
389 return vec_shl_optab
;
391 case VEC_RSHIFT_EXPR
:
392 return vec_shr_optab
;
394 case VEC_WIDEN_MULT_HI_EXPR
:
395 return TYPE_UNSIGNED (type
) ?
396 vec_widen_umult_hi_optab
: vec_widen_smult_hi_optab
;
398 case VEC_WIDEN_MULT_LO_EXPR
:
399 return TYPE_UNSIGNED (type
) ?
400 vec_widen_umult_lo_optab
: vec_widen_smult_lo_optab
;
402 case VEC_UNPACK_HI_EXPR
:
403 return TYPE_UNSIGNED (type
) ?
404 vec_unpacku_hi_optab
: vec_unpacks_hi_optab
;
406 case VEC_UNPACK_LO_EXPR
:
407 return TYPE_UNSIGNED (type
) ?
408 vec_unpacku_lo_optab
: vec_unpacks_lo_optab
;
410 case VEC_UNPACK_FLOAT_HI_EXPR
:
411 /* The signedness is determined from input operand. */
412 return TYPE_UNSIGNED (type
) ?
413 vec_unpacku_float_hi_optab
: vec_unpacks_float_hi_optab
;
415 case VEC_UNPACK_FLOAT_LO_EXPR
:
416 /* The signedness is determined from input operand. */
417 return TYPE_UNSIGNED (type
) ?
418 vec_unpacku_float_lo_optab
: vec_unpacks_float_lo_optab
;
420 case VEC_PACK_TRUNC_EXPR
:
421 return vec_pack_trunc_optab
;
423 case VEC_PACK_SAT_EXPR
:
424 return TYPE_UNSIGNED (type
) ? vec_pack_usat_optab
: vec_pack_ssat_optab
;
426 case VEC_PACK_FIX_TRUNC_EXPR
:
427 /* The signedness is determined from output operand. */
428 return TYPE_UNSIGNED (type
) ?
429 vec_pack_ufix_trunc_optab
: vec_pack_sfix_trunc_optab
;
435 trapv
= INTEGRAL_TYPE_P (type
) && TYPE_OVERFLOW_TRAPS (type
);
438 case POINTER_PLUS_EXPR
:
440 if (TYPE_SATURATING(type
))
441 return TYPE_UNSIGNED(type
) ? usadd_optab
: ssadd_optab
;
442 return trapv
? addv_optab
: add_optab
;
445 if (TYPE_SATURATING(type
))
446 return TYPE_UNSIGNED(type
) ? ussub_optab
: sssub_optab
;
447 return trapv
? subv_optab
: sub_optab
;
450 if (TYPE_SATURATING(type
))
451 return TYPE_UNSIGNED(type
) ? usmul_optab
: ssmul_optab
;
452 return trapv
? smulv_optab
: smul_optab
;
455 if (TYPE_SATURATING(type
))
456 return TYPE_UNSIGNED(type
) ? usneg_optab
: ssneg_optab
;
457 return trapv
? negv_optab
: neg_optab
;
460 return trapv
? absv_optab
: abs_optab
;
462 case VEC_EXTRACT_EVEN_EXPR
:
463 return vec_extract_even_optab
;
465 case VEC_EXTRACT_ODD_EXPR
:
466 return vec_extract_odd_optab
;
468 case VEC_INTERLEAVE_HIGH_EXPR
:
469 return vec_interleave_high_optab
;
471 case VEC_INTERLEAVE_LOW_EXPR
:
472 return vec_interleave_low_optab
;
480 /* Expand vector widening operations.
482 There are two different classes of operations handled here:
483 1) Operations whose result is wider than all the arguments to the operation.
484 Examples: VEC_UNPACK_HI/LO_EXPR, VEC_WIDEN_MULT_HI/LO_EXPR
485 In this case OP0 and optionally OP1 would be initialized,
486 but WIDE_OP wouldn't (not relevant for this case).
487 2) Operations whose result is of the same size as the last argument to the
488 operation, but wider than all the other arguments to the operation.
489 Examples: WIDEN_SUM_EXPR, VEC_DOT_PROD_EXPR.
490 In the case WIDE_OP, OP0 and optionally OP1 would be initialized.
492 E.g, when called to expand the following operations, this is how
493 the arguments will be initialized:
495 widening-sum 2 oprnd0 - oprnd1
496 widening-dot-product 3 oprnd0 oprnd1 oprnd2
497 widening-mult 2 oprnd0 oprnd1 -
498 type-promotion (vec-unpack) 1 oprnd0 - - */
501 expand_widen_pattern_expr (sepops ops
, rtx op0
, rtx op1
, rtx wide_op
,
502 rtx target
, int unsignedp
)
504 struct expand_operand eops
[4];
505 tree oprnd0
, oprnd1
, oprnd2
;
506 enum machine_mode wmode
= VOIDmode
, tmode0
, tmode1
= VOIDmode
;
507 optab widen_pattern_optab
;
508 enum insn_code icode
;
509 int nops
= TREE_CODE_LENGTH (ops
->code
);
513 tmode0
= TYPE_MODE (TREE_TYPE (oprnd0
));
514 widen_pattern_optab
=
515 optab_for_tree_code (ops
->code
, TREE_TYPE (oprnd0
), optab_default
);
516 if (ops
->code
== WIDEN_MULT_PLUS_EXPR
517 || ops
->code
== WIDEN_MULT_MINUS_EXPR
)
518 icode
= optab_handler (widen_pattern_optab
,
519 TYPE_MODE (TREE_TYPE (ops
->op2
)));
521 icode
= optab_handler (widen_pattern_optab
, tmode0
);
522 gcc_assert (icode
!= CODE_FOR_nothing
);
527 tmode1
= TYPE_MODE (TREE_TYPE (oprnd1
));
530 /* The last operand is of a wider mode than the rest of the operands. */
535 gcc_assert (tmode1
== tmode0
);
538 wmode
= TYPE_MODE (TREE_TYPE (oprnd2
));
542 create_output_operand (&eops
[op
++], target
, TYPE_MODE (ops
->type
));
543 create_convert_operand_from (&eops
[op
++], op0
, tmode0
, unsignedp
);
545 create_convert_operand_from (&eops
[op
++], op1
, tmode1
, unsignedp
);
547 create_convert_operand_from (&eops
[op
++], wide_op
, wmode
, unsignedp
);
548 expand_insn (icode
, op
, eops
);
549 return eops
[0].value
;
552 /* Generate code to perform an operation specified by TERNARY_OPTAB
553 on operands OP0, OP1 and OP2, with result having machine-mode MODE.
555 UNSIGNEDP is for the case where we have to widen the operands
556 to perform the operation. It says to use zero-extension.
558 If TARGET is nonzero, the value
559 is generated there, if it is convenient to do so.
560 In all cases an rtx is returned for the locus of the value;
561 this may or may not be TARGET. */
564 expand_ternary_op (enum machine_mode mode
, optab ternary_optab
, rtx op0
,
565 rtx op1
, rtx op2
, rtx target
, int unsignedp
)
567 struct expand_operand ops
[4];
568 enum insn_code icode
= optab_handler (ternary_optab
, mode
);
570 gcc_assert (optab_handler (ternary_optab
, mode
) != CODE_FOR_nothing
);
572 create_output_operand (&ops
[0], target
, mode
);
573 create_convert_operand_from (&ops
[1], op0
, mode
, unsignedp
);
574 create_convert_operand_from (&ops
[2], op1
, mode
, unsignedp
);
575 create_convert_operand_from (&ops
[3], op2
, mode
, unsignedp
);
576 expand_insn (icode
, 4, ops
);
581 /* Like expand_binop, but return a constant rtx if the result can be
582 calculated at compile time. The arguments and return value are
583 otherwise the same as for expand_binop. */
586 simplify_expand_binop (enum machine_mode mode
, optab binoptab
,
587 rtx op0
, rtx op1
, rtx target
, int unsignedp
,
588 enum optab_methods methods
)
590 if (CONSTANT_P (op0
) && CONSTANT_P (op1
))
592 rtx x
= simplify_binary_operation (binoptab
->code
, mode
, op0
, op1
);
598 return expand_binop (mode
, binoptab
, op0
, op1
, target
, unsignedp
, methods
);
601 /* Like simplify_expand_binop, but always put the result in TARGET.
602 Return true if the expansion succeeded. */
605 force_expand_binop (enum machine_mode mode
, optab binoptab
,
606 rtx op0
, rtx op1
, rtx target
, int unsignedp
,
607 enum optab_methods methods
)
609 rtx x
= simplify_expand_binop (mode
, binoptab
, op0
, op1
,
610 target
, unsignedp
, methods
);
614 emit_move_insn (target
, x
);
618 /* Generate insns for VEC_LSHIFT_EXPR, VEC_RSHIFT_EXPR. */
621 expand_vec_shift_expr (sepops ops
, rtx target
)
623 struct expand_operand eops
[3];
624 enum insn_code icode
;
625 rtx rtx_op1
, rtx_op2
;
626 enum machine_mode mode
= TYPE_MODE (ops
->type
);
627 tree vec_oprnd
= ops
->op0
;
628 tree shift_oprnd
= ops
->op1
;
633 case VEC_RSHIFT_EXPR
:
634 shift_optab
= vec_shr_optab
;
636 case VEC_LSHIFT_EXPR
:
637 shift_optab
= vec_shl_optab
;
643 icode
= optab_handler (shift_optab
, mode
);
644 gcc_assert (icode
!= CODE_FOR_nothing
);
646 rtx_op1
= expand_normal (vec_oprnd
);
647 rtx_op2
= expand_normal (shift_oprnd
);
649 create_output_operand (&eops
[0], target
, mode
);
650 create_input_operand (&eops
[1], rtx_op1
, GET_MODE (rtx_op1
));
651 create_convert_operand_from_type (&eops
[2], rtx_op2
, TREE_TYPE (shift_oprnd
));
652 expand_insn (icode
, 3, eops
);
654 return eops
[0].value
;
657 /* This subroutine of expand_doubleword_shift handles the cases in which
658 the effective shift value is >= BITS_PER_WORD. The arguments and return
659 value are the same as for the parent routine, except that SUPERWORD_OP1
660 is the shift count to use when shifting OUTOF_INPUT into INTO_TARGET.
661 INTO_TARGET may be null if the caller has decided to calculate it. */
664 expand_superword_shift (optab binoptab
, rtx outof_input
, rtx superword_op1
,
665 rtx outof_target
, rtx into_target
,
666 int unsignedp
, enum optab_methods methods
)
668 if (into_target
!= 0)
669 if (!force_expand_binop (word_mode
, binoptab
, outof_input
, superword_op1
,
670 into_target
, unsignedp
, methods
))
673 if (outof_target
!= 0)
675 /* For a signed right shift, we must fill OUTOF_TARGET with copies
676 of the sign bit, otherwise we must fill it with zeros. */
677 if (binoptab
!= ashr_optab
)
678 emit_move_insn (outof_target
, CONST0_RTX (word_mode
));
680 if (!force_expand_binop (word_mode
, binoptab
,
681 outof_input
, GEN_INT (BITS_PER_WORD
- 1),
682 outof_target
, unsignedp
, methods
))
688 /* This subroutine of expand_doubleword_shift handles the cases in which
689 the effective shift value is < BITS_PER_WORD. The arguments and return
690 value are the same as for the parent routine. */
693 expand_subword_shift (enum machine_mode op1_mode
, optab binoptab
,
694 rtx outof_input
, rtx into_input
, rtx op1
,
695 rtx outof_target
, rtx into_target
,
696 int unsignedp
, enum optab_methods methods
,
697 unsigned HOST_WIDE_INT shift_mask
)
699 optab reverse_unsigned_shift
, unsigned_shift
;
702 reverse_unsigned_shift
= (binoptab
== ashl_optab
? lshr_optab
: ashl_optab
);
703 unsigned_shift
= (binoptab
== ashl_optab
? ashl_optab
: lshr_optab
);
705 /* The low OP1 bits of INTO_TARGET come from the high bits of OUTOF_INPUT.
706 We therefore need to shift OUTOF_INPUT by (BITS_PER_WORD - OP1) bits in
707 the opposite direction to BINOPTAB. */
708 if (CONSTANT_P (op1
) || shift_mask
>= BITS_PER_WORD
)
710 carries
= outof_input
;
711 tmp
= immed_double_const (BITS_PER_WORD
, 0, op1_mode
);
712 tmp
= simplify_expand_binop (op1_mode
, sub_optab
, tmp
, op1
,
717 /* We must avoid shifting by BITS_PER_WORD bits since that is either
718 the same as a zero shift (if shift_mask == BITS_PER_WORD - 1) or
719 has unknown behavior. Do a single shift first, then shift by the
720 remainder. It's OK to use ~OP1 as the remainder if shift counts
721 are truncated to the mode size. */
722 carries
= expand_binop (word_mode
, reverse_unsigned_shift
,
723 outof_input
, const1_rtx
, 0, unsignedp
, methods
);
724 if (shift_mask
== BITS_PER_WORD
- 1)
726 tmp
= immed_double_const (-1, -1, op1_mode
);
727 tmp
= simplify_expand_binop (op1_mode
, xor_optab
, op1
, tmp
,
732 tmp
= immed_double_const (BITS_PER_WORD
- 1, 0, op1_mode
);
733 tmp
= simplify_expand_binop (op1_mode
, sub_optab
, tmp
, op1
,
737 if (tmp
== 0 || carries
== 0)
739 carries
= expand_binop (word_mode
, reverse_unsigned_shift
,
740 carries
, tmp
, 0, unsignedp
, methods
);
744 /* Shift INTO_INPUT logically by OP1. This is the last use of INTO_INPUT
745 so the result can go directly into INTO_TARGET if convenient. */
746 tmp
= expand_binop (word_mode
, unsigned_shift
, into_input
, op1
,
747 into_target
, unsignedp
, methods
);
751 /* Now OR in the bits carried over from OUTOF_INPUT. */
752 if (!force_expand_binop (word_mode
, ior_optab
, tmp
, carries
,
753 into_target
, unsignedp
, methods
))
756 /* Use a standard word_mode shift for the out-of half. */
757 if (outof_target
!= 0)
758 if (!force_expand_binop (word_mode
, binoptab
, outof_input
, op1
,
759 outof_target
, unsignedp
, methods
))
766 #ifdef HAVE_conditional_move
767 /* Try implementing expand_doubleword_shift using conditional moves.
768 The shift is by < BITS_PER_WORD if (CMP_CODE CMP1 CMP2) is true,
769 otherwise it is by >= BITS_PER_WORD. SUBWORD_OP1 and SUPERWORD_OP1
770 are the shift counts to use in the former and latter case. All other
771 arguments are the same as the parent routine. */
774 expand_doubleword_shift_condmove (enum machine_mode op1_mode
, optab binoptab
,
775 enum rtx_code cmp_code
, rtx cmp1
, rtx cmp2
,
776 rtx outof_input
, rtx into_input
,
777 rtx subword_op1
, rtx superword_op1
,
778 rtx outof_target
, rtx into_target
,
779 int unsignedp
, enum optab_methods methods
,
780 unsigned HOST_WIDE_INT shift_mask
)
782 rtx outof_superword
, into_superword
;
784 /* Put the superword version of the output into OUTOF_SUPERWORD and
786 outof_superword
= outof_target
!= 0 ? gen_reg_rtx (word_mode
) : 0;
787 if (outof_target
!= 0 && subword_op1
== superword_op1
)
789 /* The value INTO_TARGET >> SUBWORD_OP1, which we later store in
790 OUTOF_TARGET, is the same as the value of INTO_SUPERWORD. */
791 into_superword
= outof_target
;
792 if (!expand_superword_shift (binoptab
, outof_input
, superword_op1
,
793 outof_superword
, 0, unsignedp
, methods
))
798 into_superword
= gen_reg_rtx (word_mode
);
799 if (!expand_superword_shift (binoptab
, outof_input
, superword_op1
,
800 outof_superword
, into_superword
,
805 /* Put the subword version directly in OUTOF_TARGET and INTO_TARGET. */
806 if (!expand_subword_shift (op1_mode
, binoptab
,
807 outof_input
, into_input
, subword_op1
,
808 outof_target
, into_target
,
809 unsignedp
, methods
, shift_mask
))
812 /* Select between them. Do the INTO half first because INTO_SUPERWORD
813 might be the current value of OUTOF_TARGET. */
814 if (!emit_conditional_move (into_target
, cmp_code
, cmp1
, cmp2
, op1_mode
,
815 into_target
, into_superword
, word_mode
, false))
818 if (outof_target
!= 0)
819 if (!emit_conditional_move (outof_target
, cmp_code
, cmp1
, cmp2
, op1_mode
,
820 outof_target
, outof_superword
,
828 /* Expand a doubleword shift (ashl, ashr or lshr) using word-mode shifts.
829 OUTOF_INPUT and INTO_INPUT are the two word-sized halves of the first
830 input operand; the shift moves bits in the direction OUTOF_INPUT->
831 INTO_TARGET. OUTOF_TARGET and INTO_TARGET are the equivalent words
832 of the target. OP1 is the shift count and OP1_MODE is its mode.
833 If OP1 is constant, it will have been truncated as appropriate
834 and is known to be nonzero.
836 If SHIFT_MASK is zero, the result of word shifts is undefined when the
837 shift count is outside the range [0, BITS_PER_WORD). This routine must
838 avoid generating such shifts for OP1s in the range [0, BITS_PER_WORD * 2).
840 If SHIFT_MASK is nonzero, all word-mode shift counts are effectively
841 masked by it and shifts in the range [BITS_PER_WORD, SHIFT_MASK) will
842 fill with zeros or sign bits as appropriate.
844 If SHIFT_MASK is BITS_PER_WORD - 1, this routine will synthesize
845 a doubleword shift whose equivalent mask is BITS_PER_WORD * 2 - 1.
846 Doing this preserves semantics required by SHIFT_COUNT_TRUNCATED.
847 In all other cases, shifts by values outside [0, BITS_PER_UNIT * 2)
850 BINOPTAB, UNSIGNEDP and METHODS are as for expand_binop. This function
851 may not use INTO_INPUT after modifying INTO_TARGET, and similarly for
852 OUTOF_INPUT and OUTOF_TARGET. OUTOF_TARGET can be null if the parent
853 function wants to calculate it itself.
855 Return true if the shift could be successfully synthesized. */
858 expand_doubleword_shift (enum machine_mode op1_mode
, optab binoptab
,
859 rtx outof_input
, rtx into_input
, rtx op1
,
860 rtx outof_target
, rtx into_target
,
861 int unsignedp
, enum optab_methods methods
,
862 unsigned HOST_WIDE_INT shift_mask
)
864 rtx superword_op1
, tmp
, cmp1
, cmp2
;
865 rtx subword_label
, done_label
;
866 enum rtx_code cmp_code
;
868 /* See if word-mode shifts by BITS_PER_WORD...BITS_PER_WORD * 2 - 1 will
869 fill the result with sign or zero bits as appropriate. If so, the value
870 of OUTOF_TARGET will always be (SHIFT OUTOF_INPUT OP1). Recursively call
871 this routine to calculate INTO_TARGET (which depends on both OUTOF_INPUT
872 and INTO_INPUT), then emit code to set up OUTOF_TARGET.
874 This isn't worthwhile for constant shifts since the optimizers will
875 cope better with in-range shift counts. */
876 if (shift_mask
>= BITS_PER_WORD
878 && !CONSTANT_P (op1
))
880 if (!expand_doubleword_shift (op1_mode
, binoptab
,
881 outof_input
, into_input
, op1
,
883 unsignedp
, methods
, shift_mask
))
885 if (!force_expand_binop (word_mode
, binoptab
, outof_input
, op1
,
886 outof_target
, unsignedp
, methods
))
891 /* Set CMP_CODE, CMP1 and CMP2 so that the rtx (CMP_CODE CMP1 CMP2)
892 is true when the effective shift value is less than BITS_PER_WORD.
893 Set SUPERWORD_OP1 to the shift count that should be used to shift
894 OUTOF_INPUT into INTO_TARGET when the condition is false. */
895 tmp
= immed_double_const (BITS_PER_WORD
, 0, op1_mode
);
896 if (!CONSTANT_P (op1
) && shift_mask
== BITS_PER_WORD
- 1)
898 /* Set CMP1 to OP1 & BITS_PER_WORD. The result is zero iff OP1
899 is a subword shift count. */
900 cmp1
= simplify_expand_binop (op1_mode
, and_optab
, op1
, tmp
,
902 cmp2
= CONST0_RTX (op1_mode
);
908 /* Set CMP1 to OP1 - BITS_PER_WORD. */
909 cmp1
= simplify_expand_binop (op1_mode
, sub_optab
, op1
, tmp
,
911 cmp2
= CONST0_RTX (op1_mode
);
913 superword_op1
= cmp1
;
918 /* If we can compute the condition at compile time, pick the
919 appropriate subroutine. */
920 tmp
= simplify_relational_operation (cmp_code
, SImode
, op1_mode
, cmp1
, cmp2
);
921 if (tmp
!= 0 && CONST_INT_P (tmp
))
923 if (tmp
== const0_rtx
)
924 return expand_superword_shift (binoptab
, outof_input
, superword_op1
,
925 outof_target
, into_target
,
928 return expand_subword_shift (op1_mode
, binoptab
,
929 outof_input
, into_input
, op1
,
930 outof_target
, into_target
,
931 unsignedp
, methods
, shift_mask
);
934 #ifdef HAVE_conditional_move
935 /* Try using conditional moves to generate straight-line code. */
937 rtx start
= get_last_insn ();
938 if (expand_doubleword_shift_condmove (op1_mode
, binoptab
,
939 cmp_code
, cmp1
, cmp2
,
940 outof_input
, into_input
,
942 outof_target
, into_target
,
943 unsignedp
, methods
, shift_mask
))
945 delete_insns_since (start
);
949 /* As a last resort, use branches to select the correct alternative. */
950 subword_label
= gen_label_rtx ();
951 done_label
= gen_label_rtx ();
954 do_compare_rtx_and_jump (cmp1
, cmp2
, cmp_code
, false, op1_mode
,
955 0, 0, subword_label
, -1);
958 if (!expand_superword_shift (binoptab
, outof_input
, superword_op1
,
959 outof_target
, into_target
,
963 emit_jump_insn (gen_jump (done_label
));
965 emit_label (subword_label
);
967 if (!expand_subword_shift (op1_mode
, binoptab
,
968 outof_input
, into_input
, op1
,
969 outof_target
, into_target
,
970 unsignedp
, methods
, shift_mask
))
973 emit_label (done_label
);
977 /* Subroutine of expand_binop. Perform a double word multiplication of
978 operands OP0 and OP1 both of mode MODE, which is exactly twice as wide
979 as the target's word_mode. This function return NULL_RTX if anything
980 goes wrong, in which case it may have already emitted instructions
981 which need to be deleted.
983 If we want to multiply two two-word values and have normal and widening
984 multiplies of single-word values, we can do this with three smaller
987 The multiplication proceeds as follows:
988 _______________________
989 [__op0_high_|__op0_low__]
990 _______________________
991 * [__op1_high_|__op1_low__]
992 _______________________________________________
993 _______________________
994 (1) [__op0_low__*__op1_low__]
995 _______________________
996 (2a) [__op0_low__*__op1_high_]
997 _______________________
998 (2b) [__op0_high_*__op1_low__]
999 _______________________
1000 (3) [__op0_high_*__op1_high_]
1003 This gives a 4-word result. Since we are only interested in the
1004 lower 2 words, partial result (3) and the upper words of (2a) and
1005 (2b) don't need to be calculated. Hence (2a) and (2b) can be
1006 calculated using non-widening multiplication.
1008 (1), however, needs to be calculated with an unsigned widening
1009 multiplication. If this operation is not directly supported we
1010 try using a signed widening multiplication and adjust the result.
1011 This adjustment works as follows:
1013 If both operands are positive then no adjustment is needed.
1015 If the operands have different signs, for example op0_low < 0 and
1016 op1_low >= 0, the instruction treats the most significant bit of
1017 op0_low as a sign bit instead of a bit with significance
1018 2**(BITS_PER_WORD-1), i.e. the instruction multiplies op1_low
1019 with 2**BITS_PER_WORD - op0_low, and two's complements the
1020 result. Conclusion: We need to add op1_low * 2**BITS_PER_WORD to
1023 Similarly, if both operands are negative, we need to add
1024 (op0_low + op1_low) * 2**BITS_PER_WORD.
1026 We use a trick to adjust quickly. We logically shift op0_low right
1027 (op1_low) BITS_PER_WORD-1 steps to get 0 or 1, and add this to
1028 op0_high (op1_high) before it is used to calculate 2b (2a). If no
1029 logical shift exists, we do an arithmetic right shift and subtract
1033 expand_doubleword_mult (enum machine_mode mode
, rtx op0
, rtx op1
, rtx target
,
1034 bool umulp
, enum optab_methods methods
)
1036 int low
= (WORDS_BIG_ENDIAN
? 1 : 0);
1037 int high
= (WORDS_BIG_ENDIAN
? 0 : 1);
1038 rtx wordm1
= umulp
? NULL_RTX
: GEN_INT (BITS_PER_WORD
- 1);
1039 rtx product
, adjust
, product_high
, temp
;
1041 rtx op0_high
= operand_subword_force (op0
, high
, mode
);
1042 rtx op0_low
= operand_subword_force (op0
, low
, mode
);
1043 rtx op1_high
= operand_subword_force (op1
, high
, mode
);
1044 rtx op1_low
= operand_subword_force (op1
, low
, mode
);
1046 /* If we're using an unsigned multiply to directly compute the product
1047 of the low-order words of the operands and perform any required
1048 adjustments of the operands, we begin by trying two more multiplications
1049 and then computing the appropriate sum.
1051 We have checked above that the required addition is provided.
1052 Full-word addition will normally always succeed, especially if
1053 it is provided at all, so we don't worry about its failure. The
1054 multiplication may well fail, however, so we do handle that. */
1058 /* ??? This could be done with emit_store_flag where available. */
1059 temp
= expand_binop (word_mode
, lshr_optab
, op0_low
, wordm1
,
1060 NULL_RTX
, 1, methods
);
1062 op0_high
= expand_binop (word_mode
, add_optab
, op0_high
, temp
,
1063 NULL_RTX
, 0, OPTAB_DIRECT
);
1066 temp
= expand_binop (word_mode
, ashr_optab
, op0_low
, wordm1
,
1067 NULL_RTX
, 0, methods
);
1070 op0_high
= expand_binop (word_mode
, sub_optab
, op0_high
, temp
,
1071 NULL_RTX
, 0, OPTAB_DIRECT
);
1078 adjust
= expand_binop (word_mode
, smul_optab
, op0_high
, op1_low
,
1079 NULL_RTX
, 0, OPTAB_DIRECT
);
1083 /* OP0_HIGH should now be dead. */
1087 /* ??? This could be done with emit_store_flag where available. */
1088 temp
= expand_binop (word_mode
, lshr_optab
, op1_low
, wordm1
,
1089 NULL_RTX
, 1, methods
);
1091 op1_high
= expand_binop (word_mode
, add_optab
, op1_high
, temp
,
1092 NULL_RTX
, 0, OPTAB_DIRECT
);
1095 temp
= expand_binop (word_mode
, ashr_optab
, op1_low
, wordm1
,
1096 NULL_RTX
, 0, methods
);
1099 op1_high
= expand_binop (word_mode
, sub_optab
, op1_high
, temp
,
1100 NULL_RTX
, 0, OPTAB_DIRECT
);
1107 temp
= expand_binop (word_mode
, smul_optab
, op1_high
, op0_low
,
1108 NULL_RTX
, 0, OPTAB_DIRECT
);
1112 /* OP1_HIGH should now be dead. */
1114 adjust
= expand_binop (word_mode
, add_optab
, adjust
, temp
,
1115 NULL_RTX
, 0, OPTAB_DIRECT
);
1117 if (target
&& !REG_P (target
))
1121 product
= expand_binop (mode
, umul_widen_optab
, op0_low
, op1_low
,
1122 target
, 1, OPTAB_DIRECT
);
1124 product
= expand_binop (mode
, smul_widen_optab
, op0_low
, op1_low
,
1125 target
, 1, OPTAB_DIRECT
);
1130 product_high
= operand_subword (product
, high
, 1, mode
);
1131 adjust
= expand_binop (word_mode
, add_optab
, product_high
, adjust
,
1132 NULL_RTX
, 0, OPTAB_DIRECT
);
1133 emit_move_insn (product_high
, adjust
);
1137 /* Wrapper around expand_binop which takes an rtx code to specify
1138 the operation to perform, not an optab pointer. All other
1139 arguments are the same. */
1141 expand_simple_binop (enum machine_mode mode
, enum rtx_code code
, rtx op0
,
1142 rtx op1
, rtx target
, int unsignedp
,
1143 enum optab_methods methods
)
1145 optab binop
= code_to_optab
[(int) code
];
1148 return expand_binop (mode
, binop
, op0
, op1
, target
, unsignedp
, methods
);
1151 /* Return whether OP0 and OP1 should be swapped when expanding a commutative
1152 binop. Order them according to commutative_operand_precedence and, if
1153 possible, try to put TARGET or a pseudo first. */
1155 swap_commutative_operands_with_target (rtx target
, rtx op0
, rtx op1
)
1157 int op0_prec
= commutative_operand_precedence (op0
);
1158 int op1_prec
= commutative_operand_precedence (op1
);
1160 if (op0_prec
< op1_prec
)
1163 if (op0_prec
> op1_prec
)
1166 /* With equal precedence, both orders are ok, but it is better if the
1167 first operand is TARGET, or if both TARGET and OP0 are pseudos. */
1168 if (target
== 0 || REG_P (target
))
1169 return (REG_P (op1
) && !REG_P (op0
)) || target
== op1
;
1171 return rtx_equal_p (op1
, target
);
1174 /* Return true if BINOPTAB implements a shift operation. */
1177 shift_optab_p (optab binoptab
)
1179 switch (binoptab
->code
)
1195 /* Return true if BINOPTAB implements a commutative binary operation. */
1198 commutative_optab_p (optab binoptab
)
1200 return (GET_RTX_CLASS (binoptab
->code
) == RTX_COMM_ARITH
1201 || binoptab
== smul_widen_optab
1202 || binoptab
== umul_widen_optab
1203 || binoptab
== smul_highpart_optab
1204 || binoptab
== umul_highpart_optab
);
1207 /* X is to be used in mode MODE as an operand to BINOPTAB. If we're
1208 optimizing, and if the operand is a constant that costs more than
1209 1 instruction, force the constant into a register and return that
1210 register. Return X otherwise. UNSIGNEDP says whether X is unsigned. */
1213 avoid_expensive_constant (enum machine_mode mode
, optab binoptab
,
1214 rtx x
, bool unsignedp
)
1216 bool speed
= optimize_insn_for_speed_p ();
1218 if (mode
!= VOIDmode
1221 && rtx_cost (x
, binoptab
->code
, speed
) > rtx_cost (x
, SET
, speed
))
1223 if (CONST_INT_P (x
))
1225 HOST_WIDE_INT intval
= trunc_int_for_mode (INTVAL (x
), mode
);
1226 if (intval
!= INTVAL (x
))
1227 x
= GEN_INT (intval
);
1230 x
= convert_modes (mode
, VOIDmode
, x
, unsignedp
);
1231 x
= force_reg (mode
, x
);
1236 /* Helper function for expand_binop: handle the case where there
1237 is an insn that directly implements the indicated operation.
1238 Returns null if this is not possible. */
1240 expand_binop_directly (enum machine_mode mode
, optab binoptab
,
1242 rtx target
, int unsignedp
, enum optab_methods methods
,
1245 enum insn_code icode
= optab_handler (binoptab
, mode
);
1246 enum machine_mode xmode0
= insn_data
[(int) icode
].operand
[1].mode
;
1247 enum machine_mode xmode1
= insn_data
[(int) icode
].operand
[2].mode
;
1248 enum machine_mode mode0
, mode1
, tmp_mode
;
1249 struct expand_operand ops
[3];
1252 rtx xop0
= op0
, xop1
= op1
;
1255 /* If it is a commutative operator and the modes would match
1256 if we would swap the operands, we can save the conversions. */
1257 commutative_p
= commutative_optab_p (binoptab
);
1259 && GET_MODE (xop0
) != xmode0
&& GET_MODE (xop1
) != xmode1
1260 && GET_MODE (xop0
) == xmode1
&& GET_MODE (xop1
) == xmode1
)
1267 /* If we are optimizing, force expensive constants into a register. */
1268 xop0
= avoid_expensive_constant (xmode0
, binoptab
, xop0
, unsignedp
);
1269 if (!shift_optab_p (binoptab
))
1270 xop1
= avoid_expensive_constant (xmode1
, binoptab
, xop1
, unsignedp
);
1272 /* In case the insn wants input operands in modes different from
1273 those of the actual operands, convert the operands. It would
1274 seem that we don't need to convert CONST_INTs, but we do, so
1275 that they're properly zero-extended, sign-extended or truncated
1278 mode0
= GET_MODE (xop0
) != VOIDmode
? GET_MODE (xop0
) : mode
;
1279 if (xmode0
!= VOIDmode
&& xmode0
!= mode0
)
1281 xop0
= convert_modes (xmode0
, mode0
, xop0
, unsignedp
);
1285 mode1
= GET_MODE (xop1
) != VOIDmode
? GET_MODE (xop1
) : mode
;
1286 if (xmode1
!= VOIDmode
&& xmode1
!= mode1
)
1288 xop1
= convert_modes (xmode1
, mode1
, xop1
, unsignedp
);
1292 /* If operation is commutative,
1293 try to make the first operand a register.
1294 Even better, try to make it the same as the target.
1295 Also try to make the last operand a constant. */
1297 && swap_commutative_operands_with_target (target
, xop0
, xop1
))
1304 /* Now, if insn's predicates don't allow our operands, put them into
1307 if (binoptab
== vec_pack_trunc_optab
1308 || binoptab
== vec_pack_usat_optab
1309 || binoptab
== vec_pack_ssat_optab
1310 || binoptab
== vec_pack_ufix_trunc_optab
1311 || binoptab
== vec_pack_sfix_trunc_optab
)
1313 /* The mode of the result is different then the mode of the
1315 tmp_mode
= insn_data
[(int) icode
].operand
[0].mode
;
1316 if (GET_MODE_NUNITS (tmp_mode
) != 2 * GET_MODE_NUNITS (mode
))
1318 delete_insns_since (last
);
1325 create_output_operand (&ops
[0], target
, tmp_mode
);
1326 create_input_operand (&ops
[1], xop0
, mode0
);
1327 create_input_operand (&ops
[2], xop1
, mode1
);
1328 pat
= maybe_gen_insn (icode
, 3, ops
);
1331 /* If PAT is composed of more than one insn, try to add an appropriate
1332 REG_EQUAL note to it. If we can't because TEMP conflicts with an
1333 operand, call expand_binop again, this time without a target. */
1334 if (INSN_P (pat
) && NEXT_INSN (pat
) != NULL_RTX
1335 && ! add_equal_note (pat
, ops
[0].value
, binoptab
->code
,
1336 ops
[1].value
, ops
[2].value
))
1338 delete_insns_since (last
);
1339 return expand_binop (mode
, binoptab
, op0
, op1
, NULL_RTX
,
1340 unsignedp
, methods
);
1344 return ops
[0].value
;
1346 delete_insns_since (last
);
1350 /* Generate code to perform an operation specified by BINOPTAB
1351 on operands OP0 and OP1, with result having machine-mode MODE.
1353 UNSIGNEDP is for the case where we have to widen the operands
1354 to perform the operation. It says to use zero-extension.
1356 If TARGET is nonzero, the value
1357 is generated there, if it is convenient to do so.
1358 In all cases an rtx is returned for the locus of the value;
1359 this may or may not be TARGET. */
1362 expand_binop (enum machine_mode mode
, optab binoptab
, rtx op0
, rtx op1
,
1363 rtx target
, int unsignedp
, enum optab_methods methods
)
1365 enum optab_methods next_methods
1366 = (methods
== OPTAB_LIB
|| methods
== OPTAB_LIB_WIDEN
1367 ? OPTAB_WIDEN
: methods
);
1368 enum mode_class mclass
;
1369 enum machine_mode wider_mode
;
1372 rtx entry_last
= get_last_insn ();
1375 mclass
= GET_MODE_CLASS (mode
);
1377 /* If subtracting an integer constant, convert this into an addition of
1378 the negated constant. */
1380 if (binoptab
== sub_optab
&& CONST_INT_P (op1
))
1382 op1
= negate_rtx (mode
, op1
);
1383 binoptab
= add_optab
;
1386 /* Record where to delete back to if we backtrack. */
1387 last
= get_last_insn ();
1389 /* If we can do it with a three-operand insn, do so. */
1391 if (methods
!= OPTAB_MUST_WIDEN
1392 && optab_handler (binoptab
, mode
) != CODE_FOR_nothing
)
1394 temp
= expand_binop_directly (mode
, binoptab
, op0
, op1
, target
,
1395 unsignedp
, methods
, last
);
1400 /* If we were trying to rotate, and that didn't work, try rotating
1401 the other direction before falling back to shifts and bitwise-or. */
1402 if (((binoptab
== rotl_optab
1403 && optab_handler (rotr_optab
, mode
) != CODE_FOR_nothing
)
1404 || (binoptab
== rotr_optab
1405 && optab_handler (rotl_optab
, mode
) != CODE_FOR_nothing
))
1406 && mclass
== MODE_INT
)
1408 optab otheroptab
= (binoptab
== rotl_optab
? rotr_optab
: rotl_optab
);
1410 unsigned int bits
= GET_MODE_PRECISION (mode
);
1412 if (CONST_INT_P (op1
))
1413 newop1
= GEN_INT (bits
- INTVAL (op1
));
1414 else if (targetm
.shift_truncation_mask (mode
) == bits
- 1)
1415 newop1
= negate_rtx (GET_MODE (op1
), op1
);
1417 newop1
= expand_binop (GET_MODE (op1
), sub_optab
,
1418 GEN_INT (bits
), op1
,
1419 NULL_RTX
, unsignedp
, OPTAB_DIRECT
);
1421 temp
= expand_binop_directly (mode
, otheroptab
, op0
, newop1
,
1422 target
, unsignedp
, methods
, last
);
1427 /* If this is a multiply, see if we can do a widening operation that
1428 takes operands of this mode and makes a wider mode. */
1430 if (binoptab
== smul_optab
1431 && GET_MODE_2XWIDER_MODE (mode
) != VOIDmode
1432 && (optab_handler ((unsignedp
? umul_widen_optab
: smul_widen_optab
),
1433 GET_MODE_2XWIDER_MODE (mode
))
1434 != CODE_FOR_nothing
))
1436 temp
= expand_binop (GET_MODE_2XWIDER_MODE (mode
),
1437 unsignedp
? umul_widen_optab
: smul_widen_optab
,
1438 op0
, op1
, NULL_RTX
, unsignedp
, OPTAB_DIRECT
);
1442 if (GET_MODE_CLASS (mode
) == MODE_INT
1443 && TRULY_NOOP_TRUNCATION_MODES_P (mode
, GET_MODE (temp
)))
1444 return gen_lowpart (mode
, temp
);
1446 return convert_to_mode (mode
, temp
, unsignedp
);
1450 /* Look for a wider mode of the same class for which we think we
1451 can open-code the operation. Check for a widening multiply at the
1452 wider mode as well. */
1454 if (CLASS_HAS_WIDER_MODES_P (mclass
)
1455 && methods
!= OPTAB_DIRECT
&& methods
!= OPTAB_LIB
)
1456 for (wider_mode
= GET_MODE_WIDER_MODE (mode
);
1457 wider_mode
!= VOIDmode
;
1458 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
1460 if (optab_handler (binoptab
, wider_mode
) != CODE_FOR_nothing
1461 || (binoptab
== smul_optab
1462 && GET_MODE_WIDER_MODE (wider_mode
) != VOIDmode
1463 && (optab_handler ((unsignedp
? umul_widen_optab
1464 : smul_widen_optab
),
1465 GET_MODE_WIDER_MODE (wider_mode
))
1466 != CODE_FOR_nothing
)))
1468 rtx xop0
= op0
, xop1
= op1
;
1471 /* For certain integer operations, we need not actually extend
1472 the narrow operands, as long as we will truncate
1473 the results to the same narrowness. */
1475 if ((binoptab
== ior_optab
|| binoptab
== and_optab
1476 || binoptab
== xor_optab
1477 || binoptab
== add_optab
|| binoptab
== sub_optab
1478 || binoptab
== smul_optab
|| binoptab
== ashl_optab
)
1479 && mclass
== MODE_INT
)
1482 xop0
= avoid_expensive_constant (mode
, binoptab
,
1484 if (binoptab
!= ashl_optab
)
1485 xop1
= avoid_expensive_constant (mode
, binoptab
,
1489 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
, no_extend
);
1491 /* The second operand of a shift must always be extended. */
1492 xop1
= widen_operand (xop1
, wider_mode
, mode
, unsignedp
,
1493 no_extend
&& binoptab
!= ashl_optab
);
1495 temp
= expand_binop (wider_mode
, binoptab
, xop0
, xop1
, NULL_RTX
,
1496 unsignedp
, OPTAB_DIRECT
);
1499 if (mclass
!= MODE_INT
1500 || !TRULY_NOOP_TRUNCATION_MODES_P (mode
, wider_mode
))
1503 target
= gen_reg_rtx (mode
);
1504 convert_move (target
, temp
, 0);
1508 return gen_lowpart (mode
, temp
);
1511 delete_insns_since (last
);
1515 /* If operation is commutative,
1516 try to make the first operand a register.
1517 Even better, try to make it the same as the target.
1518 Also try to make the last operand a constant. */
1519 if (commutative_optab_p (binoptab
)
1520 && swap_commutative_operands_with_target (target
, op0
, op1
))
1527 /* These can be done a word at a time. */
1528 if ((binoptab
== and_optab
|| binoptab
== ior_optab
|| binoptab
== xor_optab
)
1529 && mclass
== MODE_INT
1530 && GET_MODE_SIZE (mode
) > UNITS_PER_WORD
1531 && optab_handler (binoptab
, word_mode
) != CODE_FOR_nothing
)
1536 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1537 won't be accurate, so use a new target. */
1541 || !valid_multiword_target_p (target
))
1542 target
= gen_reg_rtx (mode
);
1546 /* Do the actual arithmetic. */
1547 for (i
= 0; i
< GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
; i
++)
1549 rtx target_piece
= operand_subword (target
, i
, 1, mode
);
1550 rtx x
= expand_binop (word_mode
, binoptab
,
1551 operand_subword_force (op0
, i
, mode
),
1552 operand_subword_force (op1
, i
, mode
),
1553 target_piece
, unsignedp
, next_methods
);
1558 if (target_piece
!= x
)
1559 emit_move_insn (target_piece
, x
);
1562 insns
= get_insns ();
1565 if (i
== GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
)
1572 /* Synthesize double word shifts from single word shifts. */
1573 if ((binoptab
== lshr_optab
|| binoptab
== ashl_optab
1574 || binoptab
== ashr_optab
)
1575 && mclass
== MODE_INT
1576 && (CONST_INT_P (op1
) || optimize_insn_for_speed_p ())
1577 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
1578 && GET_MODE_PRECISION (mode
) == GET_MODE_BITSIZE (mode
)
1579 && optab_handler (binoptab
, word_mode
) != CODE_FOR_nothing
1580 && optab_handler (ashl_optab
, word_mode
) != CODE_FOR_nothing
1581 && optab_handler (lshr_optab
, word_mode
) != CODE_FOR_nothing
)
1583 unsigned HOST_WIDE_INT shift_mask
, double_shift_mask
;
1584 enum machine_mode op1_mode
;
1586 double_shift_mask
= targetm
.shift_truncation_mask (mode
);
1587 shift_mask
= targetm
.shift_truncation_mask (word_mode
);
1588 op1_mode
= GET_MODE (op1
) != VOIDmode
? GET_MODE (op1
) : word_mode
;
1590 /* Apply the truncation to constant shifts. */
1591 if (double_shift_mask
> 0 && CONST_INT_P (op1
))
1592 op1
= GEN_INT (INTVAL (op1
) & double_shift_mask
);
1594 if (op1
== CONST0_RTX (op1_mode
))
1597 /* Make sure that this is a combination that expand_doubleword_shift
1598 can handle. See the comments there for details. */
1599 if (double_shift_mask
== 0
1600 || (shift_mask
== BITS_PER_WORD
- 1
1601 && double_shift_mask
== BITS_PER_WORD
* 2 - 1))
1604 rtx into_target
, outof_target
;
1605 rtx into_input
, outof_input
;
1606 int left_shift
, outof_word
;
1608 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1609 won't be accurate, so use a new target. */
1613 || !valid_multiword_target_p (target
))
1614 target
= gen_reg_rtx (mode
);
1618 /* OUTOF_* is the word we are shifting bits away from, and
1619 INTO_* is the word that we are shifting bits towards, thus
1620 they differ depending on the direction of the shift and
1621 WORDS_BIG_ENDIAN. */
1623 left_shift
= binoptab
== ashl_optab
;
1624 outof_word
= left_shift
^ ! WORDS_BIG_ENDIAN
;
1626 outof_target
= operand_subword (target
, outof_word
, 1, mode
);
1627 into_target
= operand_subword (target
, 1 - outof_word
, 1, mode
);
1629 outof_input
= operand_subword_force (op0
, outof_word
, mode
);
1630 into_input
= operand_subword_force (op0
, 1 - outof_word
, mode
);
1632 if (expand_doubleword_shift (op1_mode
, binoptab
,
1633 outof_input
, into_input
, op1
,
1634 outof_target
, into_target
,
1635 unsignedp
, next_methods
, shift_mask
))
1637 insns
= get_insns ();
1647 /* Synthesize double word rotates from single word shifts. */
1648 if ((binoptab
== rotl_optab
|| binoptab
== rotr_optab
)
1649 && mclass
== MODE_INT
1650 && CONST_INT_P (op1
)
1651 && GET_MODE_PRECISION (mode
) == 2 * BITS_PER_WORD
1652 && optab_handler (ashl_optab
, word_mode
) != CODE_FOR_nothing
1653 && optab_handler (lshr_optab
, word_mode
) != CODE_FOR_nothing
)
1656 rtx into_target
, outof_target
;
1657 rtx into_input
, outof_input
;
1659 int shift_count
, left_shift
, outof_word
;
1661 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1662 won't be accurate, so use a new target. Do this also if target is not
1663 a REG, first because having a register instead may open optimization
1664 opportunities, and second because if target and op0 happen to be MEMs
1665 designating the same location, we would risk clobbering it too early
1666 in the code sequence we generate below. */
1671 || !valid_multiword_target_p (target
))
1672 target
= gen_reg_rtx (mode
);
1676 shift_count
= INTVAL (op1
);
1678 /* OUTOF_* is the word we are shifting bits away from, and
1679 INTO_* is the word that we are shifting bits towards, thus
1680 they differ depending on the direction of the shift and
1681 WORDS_BIG_ENDIAN. */
1683 left_shift
= (binoptab
== rotl_optab
);
1684 outof_word
= left_shift
^ ! WORDS_BIG_ENDIAN
;
1686 outof_target
= operand_subword (target
, outof_word
, 1, mode
);
1687 into_target
= operand_subword (target
, 1 - outof_word
, 1, mode
);
1689 outof_input
= operand_subword_force (op0
, outof_word
, mode
);
1690 into_input
= operand_subword_force (op0
, 1 - outof_word
, mode
);
1692 if (shift_count
== BITS_PER_WORD
)
1694 /* This is just a word swap. */
1695 emit_move_insn (outof_target
, into_input
);
1696 emit_move_insn (into_target
, outof_input
);
1701 rtx into_temp1
, into_temp2
, outof_temp1
, outof_temp2
;
1702 rtx first_shift_count
, second_shift_count
;
1703 optab reverse_unsigned_shift
, unsigned_shift
;
1705 reverse_unsigned_shift
= (left_shift
^ (shift_count
< BITS_PER_WORD
)
1706 ? lshr_optab
: ashl_optab
);
1708 unsigned_shift
= (left_shift
^ (shift_count
< BITS_PER_WORD
)
1709 ? ashl_optab
: lshr_optab
);
1711 if (shift_count
> BITS_PER_WORD
)
1713 first_shift_count
= GEN_INT (shift_count
- BITS_PER_WORD
);
1714 second_shift_count
= GEN_INT (2 * BITS_PER_WORD
- shift_count
);
1718 first_shift_count
= GEN_INT (BITS_PER_WORD
- shift_count
);
1719 second_shift_count
= GEN_INT (shift_count
);
1722 into_temp1
= expand_binop (word_mode
, unsigned_shift
,
1723 outof_input
, first_shift_count
,
1724 NULL_RTX
, unsignedp
, next_methods
);
1725 into_temp2
= expand_binop (word_mode
, reverse_unsigned_shift
,
1726 into_input
, second_shift_count
,
1727 NULL_RTX
, unsignedp
, next_methods
);
1729 if (into_temp1
!= 0 && into_temp2
!= 0)
1730 inter
= expand_binop (word_mode
, ior_optab
, into_temp1
, into_temp2
,
1731 into_target
, unsignedp
, next_methods
);
1735 if (inter
!= 0 && inter
!= into_target
)
1736 emit_move_insn (into_target
, inter
);
1738 outof_temp1
= expand_binop (word_mode
, unsigned_shift
,
1739 into_input
, first_shift_count
,
1740 NULL_RTX
, unsignedp
, next_methods
);
1741 outof_temp2
= expand_binop (word_mode
, reverse_unsigned_shift
,
1742 outof_input
, second_shift_count
,
1743 NULL_RTX
, unsignedp
, next_methods
);
1745 if (inter
!= 0 && outof_temp1
!= 0 && outof_temp2
!= 0)
1746 inter
= expand_binop (word_mode
, ior_optab
,
1747 outof_temp1
, outof_temp2
,
1748 outof_target
, unsignedp
, next_methods
);
1750 if (inter
!= 0 && inter
!= outof_target
)
1751 emit_move_insn (outof_target
, inter
);
1754 insns
= get_insns ();
1764 /* These can be done a word at a time by propagating carries. */
1765 if ((binoptab
== add_optab
|| binoptab
== sub_optab
)
1766 && mclass
== MODE_INT
1767 && GET_MODE_SIZE (mode
) >= 2 * UNITS_PER_WORD
1768 && optab_handler (binoptab
, word_mode
) != CODE_FOR_nothing
)
1771 optab otheroptab
= binoptab
== add_optab
? sub_optab
: add_optab
;
1772 const unsigned int nwords
= GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
;
1773 rtx carry_in
= NULL_RTX
, carry_out
= NULL_RTX
;
1774 rtx xop0
, xop1
, xtarget
;
1776 /* We can handle either a 1 or -1 value for the carry. If STORE_FLAG
1777 value is one of those, use it. Otherwise, use 1 since it is the
1778 one easiest to get. */
1779 #if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1
1780 int normalizep
= STORE_FLAG_VALUE
;
1785 /* Prepare the operands. */
1786 xop0
= force_reg (mode
, op0
);
1787 xop1
= force_reg (mode
, op1
);
1789 xtarget
= gen_reg_rtx (mode
);
1791 if (target
== 0 || !REG_P (target
) || !valid_multiword_target_p (target
))
1794 /* Indicate for flow that the entire target reg is being set. */
1796 emit_clobber (xtarget
);
1798 /* Do the actual arithmetic. */
1799 for (i
= 0; i
< nwords
; i
++)
1801 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
1802 rtx target_piece
= operand_subword (xtarget
, index
, 1, mode
);
1803 rtx op0_piece
= operand_subword_force (xop0
, index
, mode
);
1804 rtx op1_piece
= operand_subword_force (xop1
, index
, mode
);
1807 /* Main add/subtract of the input operands. */
1808 x
= expand_binop (word_mode
, binoptab
,
1809 op0_piece
, op1_piece
,
1810 target_piece
, unsignedp
, next_methods
);
1816 /* Store carry from main add/subtract. */
1817 carry_out
= gen_reg_rtx (word_mode
);
1818 carry_out
= emit_store_flag_force (carry_out
,
1819 (binoptab
== add_optab
1822 word_mode
, 1, normalizep
);
1829 /* Add/subtract previous carry to main result. */
1830 newx
= expand_binop (word_mode
,
1831 normalizep
== 1 ? binoptab
: otheroptab
,
1833 NULL_RTX
, 1, next_methods
);
1837 /* Get out carry from adding/subtracting carry in. */
1838 rtx carry_tmp
= gen_reg_rtx (word_mode
);
1839 carry_tmp
= emit_store_flag_force (carry_tmp
,
1840 (binoptab
== add_optab
1843 word_mode
, 1, normalizep
);
1845 /* Logical-ior the two poss. carry together. */
1846 carry_out
= expand_binop (word_mode
, ior_optab
,
1847 carry_out
, carry_tmp
,
1848 carry_out
, 0, next_methods
);
1852 emit_move_insn (target_piece
, newx
);
1856 if (x
!= target_piece
)
1857 emit_move_insn (target_piece
, x
);
1860 carry_in
= carry_out
;
1863 if (i
== GET_MODE_BITSIZE (mode
) / (unsigned) BITS_PER_WORD
)
1865 if (optab_handler (mov_optab
, mode
) != CODE_FOR_nothing
1866 || ! rtx_equal_p (target
, xtarget
))
1868 rtx temp
= emit_move_insn (target
, xtarget
);
1870 set_unique_reg_note (temp
,
1872 gen_rtx_fmt_ee (binoptab
->code
, mode
,
1883 delete_insns_since (last
);
1886 /* Attempt to synthesize double word multiplies using a sequence of word
1887 mode multiplications. We first attempt to generate a sequence using a
1888 more efficient unsigned widening multiply, and if that fails we then
1889 try using a signed widening multiply. */
1891 if (binoptab
== smul_optab
1892 && mclass
== MODE_INT
1893 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
1894 && optab_handler (smul_optab
, word_mode
) != CODE_FOR_nothing
1895 && optab_handler (add_optab
, word_mode
) != CODE_FOR_nothing
)
1897 rtx product
= NULL_RTX
;
1899 if (optab_handler (umul_widen_optab
, mode
) != CODE_FOR_nothing
)
1901 product
= expand_doubleword_mult (mode
, op0
, op1
, target
,
1904 delete_insns_since (last
);
1907 if (product
== NULL_RTX
1908 && optab_handler (smul_widen_optab
, mode
) != CODE_FOR_nothing
)
1910 product
= expand_doubleword_mult (mode
, op0
, op1
, target
,
1913 delete_insns_since (last
);
1916 if (product
!= NULL_RTX
)
1918 if (optab_handler (mov_optab
, mode
) != CODE_FOR_nothing
)
1920 temp
= emit_move_insn (target
? target
: product
, product
);
1921 set_unique_reg_note (temp
,
1923 gen_rtx_fmt_ee (MULT
, mode
,
1931 /* It can't be open-coded in this mode.
1932 Use a library call if one is available and caller says that's ok. */
1934 libfunc
= optab_libfunc (binoptab
, mode
);
1936 && (methods
== OPTAB_LIB
|| methods
== OPTAB_LIB_WIDEN
))
1940 enum machine_mode op1_mode
= mode
;
1945 if (shift_optab_p (binoptab
))
1947 op1_mode
= targetm
.libgcc_shift_count_mode ();
1948 /* Specify unsigned here,
1949 since negative shift counts are meaningless. */
1950 op1x
= convert_to_mode (op1_mode
, op1
, 1);
1953 if (GET_MODE (op0
) != VOIDmode
1954 && GET_MODE (op0
) != mode
)
1955 op0
= convert_to_mode (mode
, op0
, unsignedp
);
1957 /* Pass 1 for NO_QUEUE so we don't lose any increments
1958 if the libcall is cse'd or moved. */
1959 value
= emit_library_call_value (libfunc
,
1960 NULL_RTX
, LCT_CONST
, mode
, 2,
1961 op0
, mode
, op1x
, op1_mode
);
1963 insns
= get_insns ();
1966 target
= gen_reg_rtx (mode
);
1967 emit_libcall_block (insns
, target
, value
,
1968 gen_rtx_fmt_ee (binoptab
->code
, mode
, op0
, op1
));
1973 delete_insns_since (last
);
1975 /* It can't be done in this mode. Can we do it in a wider mode? */
1977 if (! (methods
== OPTAB_WIDEN
|| methods
== OPTAB_LIB_WIDEN
1978 || methods
== OPTAB_MUST_WIDEN
))
1980 /* Caller says, don't even try. */
1981 delete_insns_since (entry_last
);
1985 /* Compute the value of METHODS to pass to recursive calls.
1986 Don't allow widening to be tried recursively. */
1988 methods
= (methods
== OPTAB_LIB_WIDEN
? OPTAB_LIB
: OPTAB_DIRECT
);
1990 /* Look for a wider mode of the same class for which it appears we can do
1993 if (CLASS_HAS_WIDER_MODES_P (mclass
))
1995 for (wider_mode
= GET_MODE_WIDER_MODE (mode
);
1996 wider_mode
!= VOIDmode
;
1997 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
1999 if (optab_handler (binoptab
, wider_mode
) != CODE_FOR_nothing
2000 || (methods
== OPTAB_LIB
2001 && optab_libfunc (binoptab
, wider_mode
)))
2003 rtx xop0
= op0
, xop1
= op1
;
2006 /* For certain integer operations, we need not actually extend
2007 the narrow operands, as long as we will truncate
2008 the results to the same narrowness. */
2010 if ((binoptab
== ior_optab
|| binoptab
== and_optab
2011 || binoptab
== xor_optab
2012 || binoptab
== add_optab
|| binoptab
== sub_optab
2013 || binoptab
== smul_optab
|| binoptab
== ashl_optab
)
2014 && mclass
== MODE_INT
)
2017 xop0
= widen_operand (xop0
, wider_mode
, mode
,
2018 unsignedp
, no_extend
);
2020 /* The second operand of a shift must always be extended. */
2021 xop1
= widen_operand (xop1
, wider_mode
, mode
, unsignedp
,
2022 no_extend
&& binoptab
!= ashl_optab
);
2024 temp
= expand_binop (wider_mode
, binoptab
, xop0
, xop1
, NULL_RTX
,
2025 unsignedp
, methods
);
2028 if (mclass
!= MODE_INT
2029 || !TRULY_NOOP_TRUNCATION_MODES_P (mode
, wider_mode
))
2032 target
= gen_reg_rtx (mode
);
2033 convert_move (target
, temp
, 0);
2037 return gen_lowpart (mode
, temp
);
2040 delete_insns_since (last
);
2045 delete_insns_since (entry_last
);
2049 /* Expand a binary operator which has both signed and unsigned forms.
2050 UOPTAB is the optab for unsigned operations, and SOPTAB is for
2053 If we widen unsigned operands, we may use a signed wider operation instead
2054 of an unsigned wider operation, since the result would be the same. */
2057 sign_expand_binop (enum machine_mode mode
, optab uoptab
, optab soptab
,
2058 rtx op0
, rtx op1
, rtx target
, int unsignedp
,
2059 enum optab_methods methods
)
2062 optab direct_optab
= unsignedp
? uoptab
: soptab
;
2063 struct optab_d wide_soptab
;
2065 /* Do it without widening, if possible. */
2066 temp
= expand_binop (mode
, direct_optab
, op0
, op1
, target
,
2067 unsignedp
, OPTAB_DIRECT
);
2068 if (temp
|| methods
== OPTAB_DIRECT
)
2071 /* Try widening to a signed int. Make a fake signed optab that
2072 hides any signed insn for direct use. */
2073 wide_soptab
= *soptab
;
2074 set_optab_handler (&wide_soptab
, mode
, CODE_FOR_nothing
);
2075 /* We don't want to generate new hash table entries from this fake
2077 wide_soptab
.libcall_gen
= NULL
;
2079 temp
= expand_binop (mode
, &wide_soptab
, op0
, op1
, target
,
2080 unsignedp
, OPTAB_WIDEN
);
2082 /* For unsigned operands, try widening to an unsigned int. */
2083 if (temp
== 0 && unsignedp
)
2084 temp
= expand_binop (mode
, uoptab
, op0
, op1
, target
,
2085 unsignedp
, OPTAB_WIDEN
);
2086 if (temp
|| methods
== OPTAB_WIDEN
)
2089 /* Use the right width libcall if that exists. */
2090 temp
= expand_binop (mode
, direct_optab
, op0
, op1
, target
, unsignedp
, OPTAB_LIB
);
2091 if (temp
|| methods
== OPTAB_LIB
)
2094 /* Must widen and use a libcall, use either signed or unsigned. */
2095 temp
= expand_binop (mode
, &wide_soptab
, op0
, op1
, target
,
2096 unsignedp
, methods
);
2100 return expand_binop (mode
, uoptab
, op0
, op1
, target
,
2101 unsignedp
, methods
);
2105 /* Generate code to perform an operation specified by UNOPPTAB
2106 on operand OP0, with two results to TARG0 and TARG1.
2107 We assume that the order of the operands for the instruction
2108 is TARG0, TARG1, OP0.
2110 Either TARG0 or TARG1 may be zero, but what that means is that
2111 the result is not actually wanted. We will generate it into
2112 a dummy pseudo-reg and discard it. They may not both be zero.
2114 Returns 1 if this operation can be performed; 0 if not. */
2117 expand_twoval_unop (optab unoptab
, rtx op0
, rtx targ0
, rtx targ1
,
2120 enum machine_mode mode
= GET_MODE (targ0
? targ0
: targ1
);
2121 enum mode_class mclass
;
2122 enum machine_mode wider_mode
;
2123 rtx entry_last
= get_last_insn ();
2126 mclass
= GET_MODE_CLASS (mode
);
2129 targ0
= gen_reg_rtx (mode
);
2131 targ1
= gen_reg_rtx (mode
);
2133 /* Record where to go back to if we fail. */
2134 last
= get_last_insn ();
2136 if (optab_handler (unoptab
, mode
) != CODE_FOR_nothing
)
2138 struct expand_operand ops
[3];
2139 enum insn_code icode
= optab_handler (unoptab
, mode
);
2141 create_fixed_operand (&ops
[0], targ0
);
2142 create_fixed_operand (&ops
[1], targ1
);
2143 create_convert_operand_from (&ops
[2], op0
, mode
, unsignedp
);
2144 if (maybe_expand_insn (icode
, 3, ops
))
2148 /* It can't be done in this mode. Can we do it in a wider mode? */
2150 if (CLASS_HAS_WIDER_MODES_P (mclass
))
2152 for (wider_mode
= GET_MODE_WIDER_MODE (mode
);
2153 wider_mode
!= VOIDmode
;
2154 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2156 if (optab_handler (unoptab
, wider_mode
) != CODE_FOR_nothing
)
2158 rtx t0
= gen_reg_rtx (wider_mode
);
2159 rtx t1
= gen_reg_rtx (wider_mode
);
2160 rtx cop0
= convert_modes (wider_mode
, mode
, op0
, unsignedp
);
2162 if (expand_twoval_unop (unoptab
, cop0
, t0
, t1
, unsignedp
))
2164 convert_move (targ0
, t0
, unsignedp
);
2165 convert_move (targ1
, t1
, unsignedp
);
2169 delete_insns_since (last
);
2174 delete_insns_since (entry_last
);
2178 /* Generate code to perform an operation specified by BINOPTAB
2179 on operands OP0 and OP1, with two results to TARG1 and TARG2.
2180 We assume that the order of the operands for the instruction
2181 is TARG0, OP0, OP1, TARG1, which would fit a pattern like
2182 [(set TARG0 (operate OP0 OP1)) (set TARG1 (operate ...))].
2184 Either TARG0 or TARG1 may be zero, but what that means is that
2185 the result is not actually wanted. We will generate it into
2186 a dummy pseudo-reg and discard it. They may not both be zero.
2188 Returns 1 if this operation can be performed; 0 if not. */
2191 expand_twoval_binop (optab binoptab
, rtx op0
, rtx op1
, rtx targ0
, rtx targ1
,
2194 enum machine_mode mode
= GET_MODE (targ0
? targ0
: targ1
);
2195 enum mode_class mclass
;
2196 enum machine_mode wider_mode
;
2197 rtx entry_last
= get_last_insn ();
2200 mclass
= GET_MODE_CLASS (mode
);
2203 targ0
= gen_reg_rtx (mode
);
2205 targ1
= gen_reg_rtx (mode
);
2207 /* Record where to go back to if we fail. */
2208 last
= get_last_insn ();
2210 if (optab_handler (binoptab
, mode
) != CODE_FOR_nothing
)
2212 struct expand_operand ops
[4];
2213 enum insn_code icode
= optab_handler (binoptab
, mode
);
2214 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
2215 enum machine_mode mode1
= insn_data
[icode
].operand
[2].mode
;
2216 rtx xop0
= op0
, xop1
= op1
;
2218 /* If we are optimizing, force expensive constants into a register. */
2219 xop0
= avoid_expensive_constant (mode0
, binoptab
, xop0
, unsignedp
);
2220 xop1
= avoid_expensive_constant (mode1
, binoptab
, xop1
, unsignedp
);
2222 create_fixed_operand (&ops
[0], targ0
);
2223 create_convert_operand_from (&ops
[1], op0
, mode
, unsignedp
);
2224 create_convert_operand_from (&ops
[2], op1
, mode
, unsignedp
);
2225 create_fixed_operand (&ops
[3], targ1
);
2226 if (maybe_expand_insn (icode
, 4, ops
))
2228 delete_insns_since (last
);
2231 /* It can't be done in this mode. Can we do it in a wider mode? */
2233 if (CLASS_HAS_WIDER_MODES_P (mclass
))
2235 for (wider_mode
= GET_MODE_WIDER_MODE (mode
);
2236 wider_mode
!= VOIDmode
;
2237 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2239 if (optab_handler (binoptab
, wider_mode
) != CODE_FOR_nothing
)
2241 rtx t0
= gen_reg_rtx (wider_mode
);
2242 rtx t1
= gen_reg_rtx (wider_mode
);
2243 rtx cop0
= convert_modes (wider_mode
, mode
, op0
, unsignedp
);
2244 rtx cop1
= convert_modes (wider_mode
, mode
, op1
, unsignedp
);
2246 if (expand_twoval_binop (binoptab
, cop0
, cop1
,
2249 convert_move (targ0
, t0
, unsignedp
);
2250 convert_move (targ1
, t1
, unsignedp
);
2254 delete_insns_since (last
);
2259 delete_insns_since (entry_last
);
2263 /* Expand the two-valued library call indicated by BINOPTAB, but
2264 preserve only one of the values. If TARG0 is non-NULL, the first
2265 value is placed into TARG0; otherwise the second value is placed
2266 into TARG1. Exactly one of TARG0 and TARG1 must be non-NULL. The
2267 value stored into TARG0 or TARG1 is equivalent to (CODE OP0 OP1).
2268 This routine assumes that the value returned by the library call is
2269 as if the return value was of an integral mode twice as wide as the
2270 mode of OP0. Returns 1 if the call was successful. */
2273 expand_twoval_binop_libfunc (optab binoptab
, rtx op0
, rtx op1
,
2274 rtx targ0
, rtx targ1
, enum rtx_code code
)
2276 enum machine_mode mode
;
2277 enum machine_mode libval_mode
;
2282 /* Exactly one of TARG0 or TARG1 should be non-NULL. */
2283 gcc_assert (!targ0
!= !targ1
);
2285 mode
= GET_MODE (op0
);
2286 libfunc
= optab_libfunc (binoptab
, mode
);
2290 /* The value returned by the library function will have twice as
2291 many bits as the nominal MODE. */
2292 libval_mode
= smallest_mode_for_size (2 * GET_MODE_BITSIZE (mode
),
2295 libval
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
2299 /* Get the part of VAL containing the value that we want. */
2300 libval
= simplify_gen_subreg (mode
, libval
, libval_mode
,
2301 targ0
? 0 : GET_MODE_SIZE (mode
));
2302 insns
= get_insns ();
2304 /* Move the into the desired location. */
2305 emit_libcall_block (insns
, targ0
? targ0
: targ1
, libval
,
2306 gen_rtx_fmt_ee (code
, mode
, op0
, op1
));
2312 /* Wrapper around expand_unop which takes an rtx code to specify
2313 the operation to perform, not an optab pointer. All other
2314 arguments are the same. */
2316 expand_simple_unop (enum machine_mode mode
, enum rtx_code code
, rtx op0
,
2317 rtx target
, int unsignedp
)
2319 optab unop
= code_to_optab
[(int) code
];
2322 return expand_unop (mode
, unop
, op0
, target
, unsignedp
);
2328 (clz:wide (zero_extend:wide x)) - ((width wide) - (width narrow)).
2330 A similar operation can be used for clrsb. UNOPTAB says which operation
2331 we are trying to expand. */
2333 widen_leading (enum machine_mode mode
, rtx op0
, rtx target
, optab unoptab
)
2335 enum mode_class mclass
= GET_MODE_CLASS (mode
);
2336 if (CLASS_HAS_WIDER_MODES_P (mclass
))
2338 enum machine_mode wider_mode
;
2339 for (wider_mode
= GET_MODE_WIDER_MODE (mode
);
2340 wider_mode
!= VOIDmode
;
2341 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2343 if (optab_handler (unoptab
, wider_mode
) != CODE_FOR_nothing
)
2345 rtx xop0
, temp
, last
;
2347 last
= get_last_insn ();
2350 target
= gen_reg_rtx (mode
);
2351 xop0
= widen_operand (op0
, wider_mode
, mode
,
2352 unoptab
!= clrsb_optab
, false);
2353 temp
= expand_unop (wider_mode
, unoptab
, xop0
, NULL_RTX
,
2354 unoptab
!= clrsb_optab
);
2356 temp
= expand_binop (wider_mode
, sub_optab
, temp
,
2357 GEN_INT (GET_MODE_PRECISION (wider_mode
)
2358 - GET_MODE_PRECISION (mode
)),
2359 target
, true, OPTAB_DIRECT
);
2361 delete_insns_since (last
);
2370 /* Try calculating clz of a double-word quantity as two clz's of word-sized
2371 quantities, choosing which based on whether the high word is nonzero. */
2373 expand_doubleword_clz (enum machine_mode mode
, rtx op0
, rtx target
)
2375 rtx xop0
= force_reg (mode
, op0
);
2376 rtx subhi
= gen_highpart (word_mode
, xop0
);
2377 rtx sublo
= gen_lowpart (word_mode
, xop0
);
2378 rtx hi0_label
= gen_label_rtx ();
2379 rtx after_label
= gen_label_rtx ();
2380 rtx seq
, temp
, result
;
2382 /* If we were not given a target, use a word_mode register, not a
2383 'mode' register. The result will fit, and nobody is expecting
2384 anything bigger (the return type of __builtin_clz* is int). */
2386 target
= gen_reg_rtx (word_mode
);
2388 /* In any case, write to a word_mode scratch in both branches of the
2389 conditional, so we can ensure there is a single move insn setting
2390 'target' to tag a REG_EQUAL note on. */
2391 result
= gen_reg_rtx (word_mode
);
2395 /* If the high word is not equal to zero,
2396 then clz of the full value is clz of the high word. */
2397 emit_cmp_and_jump_insns (subhi
, CONST0_RTX (word_mode
), EQ
, 0,
2398 word_mode
, true, hi0_label
);
2400 temp
= expand_unop_direct (word_mode
, clz_optab
, subhi
, result
, true);
2405 convert_move (result
, temp
, true);
2407 emit_jump_insn (gen_jump (after_label
));
2410 /* Else clz of the full value is clz of the low word plus the number
2411 of bits in the high word. */
2412 emit_label (hi0_label
);
2414 temp
= expand_unop_direct (word_mode
, clz_optab
, sublo
, 0, true);
2417 temp
= expand_binop (word_mode
, add_optab
, temp
,
2418 GEN_INT (GET_MODE_BITSIZE (word_mode
)),
2419 result
, true, OPTAB_DIRECT
);
2423 convert_move (result
, temp
, true);
2425 emit_label (after_label
);
2426 convert_move (target
, result
, true);
2431 add_equal_note (seq
, target
, CLZ
, xop0
, 0);
2443 (lshiftrt:wide (bswap:wide x) ((width wide) - (width narrow))). */
2445 widen_bswap (enum machine_mode mode
, rtx op0
, rtx target
)
2447 enum mode_class mclass
= GET_MODE_CLASS (mode
);
2448 enum machine_mode wider_mode
;
2451 if (!CLASS_HAS_WIDER_MODES_P (mclass
))
2454 for (wider_mode
= GET_MODE_WIDER_MODE (mode
);
2455 wider_mode
!= VOIDmode
;
2456 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2457 if (optab_handler (bswap_optab
, wider_mode
) != CODE_FOR_nothing
)
2462 last
= get_last_insn ();
2464 x
= widen_operand (op0
, wider_mode
, mode
, true, true);
2465 x
= expand_unop (wider_mode
, bswap_optab
, x
, NULL_RTX
, true);
2467 gcc_assert (GET_MODE_PRECISION (wider_mode
) == GET_MODE_BITSIZE (wider_mode
)
2468 && GET_MODE_PRECISION (mode
) == GET_MODE_BITSIZE (mode
));
2470 x
= expand_shift (RSHIFT_EXPR
, wider_mode
, x
,
2471 GET_MODE_BITSIZE (wider_mode
)
2472 - GET_MODE_BITSIZE (mode
),
2478 target
= gen_reg_rtx (mode
);
2479 emit_move_insn (target
, gen_lowpart (mode
, x
));
2482 delete_insns_since (last
);
2487 /* Try calculating bswap as two bswaps of two word-sized operands. */
2490 expand_doubleword_bswap (enum machine_mode mode
, rtx op
, rtx target
)
2494 t1
= expand_unop (word_mode
, bswap_optab
,
2495 operand_subword_force (op
, 0, mode
), NULL_RTX
, true);
2496 t0
= expand_unop (word_mode
, bswap_optab
,
2497 operand_subword_force (op
, 1, mode
), NULL_RTX
, true);
2499 if (target
== 0 || !valid_multiword_target_p (target
))
2500 target
= gen_reg_rtx (mode
);
2502 emit_clobber (target
);
2503 emit_move_insn (operand_subword (target
, 0, 1, mode
), t0
);
2504 emit_move_insn (operand_subword (target
, 1, 1, mode
), t1
);
2509 /* Try calculating (parity x) as (and (popcount x) 1), where
2510 popcount can also be done in a wider mode. */
2512 expand_parity (enum machine_mode mode
, rtx op0
, rtx target
)
2514 enum mode_class mclass
= GET_MODE_CLASS (mode
);
2515 if (CLASS_HAS_WIDER_MODES_P (mclass
))
2517 enum machine_mode wider_mode
;
2518 for (wider_mode
= mode
; wider_mode
!= VOIDmode
;
2519 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2521 if (optab_handler (popcount_optab
, wider_mode
) != CODE_FOR_nothing
)
2523 rtx xop0
, temp
, last
;
2525 last
= get_last_insn ();
2528 target
= gen_reg_rtx (mode
);
2529 xop0
= widen_operand (op0
, wider_mode
, mode
, true, false);
2530 temp
= expand_unop (wider_mode
, popcount_optab
, xop0
, NULL_RTX
,
2533 temp
= expand_binop (wider_mode
, and_optab
, temp
, const1_rtx
,
2534 target
, true, OPTAB_DIRECT
);
2536 delete_insns_since (last
);
2545 /* Try calculating ctz(x) as K - clz(x & -x) ,
2546 where K is GET_MODE_PRECISION(mode) - 1.
2548 Both __builtin_ctz and __builtin_clz are undefined at zero, so we
2549 don't have to worry about what the hardware does in that case. (If
2550 the clz instruction produces the usual value at 0, which is K, the
2551 result of this code sequence will be -1; expand_ffs, below, relies
2552 on this. It might be nice to have it be K instead, for consistency
2553 with the (very few) processors that provide a ctz with a defined
2554 value, but that would take one more instruction, and it would be
2555 less convenient for expand_ffs anyway. */
2558 expand_ctz (enum machine_mode mode
, rtx op0
, rtx target
)
2562 if (optab_handler (clz_optab
, mode
) == CODE_FOR_nothing
)
2567 temp
= expand_unop_direct (mode
, neg_optab
, op0
, NULL_RTX
, true);
2569 temp
= expand_binop (mode
, and_optab
, op0
, temp
, NULL_RTX
,
2570 true, OPTAB_DIRECT
);
2572 temp
= expand_unop_direct (mode
, clz_optab
, temp
, NULL_RTX
, true);
2574 temp
= expand_binop (mode
, sub_optab
, GEN_INT (GET_MODE_PRECISION (mode
) - 1),
2576 true, OPTAB_DIRECT
);
2586 add_equal_note (seq
, temp
, CTZ
, op0
, 0);
2592 /* Try calculating ffs(x) using ctz(x) if we have that instruction, or
2593 else with the sequence used by expand_clz.
2595 The ffs builtin promises to return zero for a zero value and ctz/clz
2596 may have an undefined value in that case. If they do not give us a
2597 convenient value, we have to generate a test and branch. */
2599 expand_ffs (enum machine_mode mode
, rtx op0
, rtx target
)
2601 HOST_WIDE_INT val
= 0;
2602 bool defined_at_zero
= false;
2605 if (optab_handler (ctz_optab
, mode
) != CODE_FOR_nothing
)
2609 temp
= expand_unop_direct (mode
, ctz_optab
, op0
, 0, true);
2613 defined_at_zero
= (CTZ_DEFINED_VALUE_AT_ZERO (mode
, val
) == 2);
2615 else if (optab_handler (clz_optab
, mode
) != CODE_FOR_nothing
)
2618 temp
= expand_ctz (mode
, op0
, 0);
2622 if (CLZ_DEFINED_VALUE_AT_ZERO (mode
, val
) == 2)
2624 defined_at_zero
= true;
2625 val
= (GET_MODE_PRECISION (mode
) - 1) - val
;
2631 if (defined_at_zero
&& val
== -1)
2632 /* No correction needed at zero. */;
2635 /* We don't try to do anything clever with the situation found
2636 on some processors (eg Alpha) where ctz(0:mode) ==
2637 bitsize(mode). If someone can think of a way to send N to -1
2638 and leave alone all values in the range 0..N-1 (where N is a
2639 power of two), cheaper than this test-and-branch, please add it.
2641 The test-and-branch is done after the operation itself, in case
2642 the operation sets condition codes that can be recycled for this.
2643 (This is true on i386, for instance.) */
2645 rtx nonzero_label
= gen_label_rtx ();
2646 emit_cmp_and_jump_insns (op0
, CONST0_RTX (mode
), NE
, 0,
2647 mode
, true, nonzero_label
);
2649 convert_move (temp
, GEN_INT (-1), false);
2650 emit_label (nonzero_label
);
2653 /* temp now has a value in the range -1..bitsize-1. ffs is supposed
2654 to produce a value in the range 0..bitsize. */
2655 temp
= expand_binop (mode
, add_optab
, temp
, GEN_INT (1),
2656 target
, false, OPTAB_DIRECT
);
2663 add_equal_note (seq
, temp
, FFS
, op0
, 0);
2672 /* Extract the OMODE lowpart from VAL, which has IMODE. Under certain
2673 conditions, VAL may already be a SUBREG against which we cannot generate
2674 a further SUBREG. In this case, we expect forcing the value into a
2675 register will work around the situation. */
2678 lowpart_subreg_maybe_copy (enum machine_mode omode
, rtx val
,
2679 enum machine_mode imode
)
2682 ret
= lowpart_subreg (omode
, val
, imode
);
2685 val
= force_reg (imode
, val
);
2686 ret
= lowpart_subreg (omode
, val
, imode
);
2687 gcc_assert (ret
!= NULL
);
2692 /* Expand a floating point absolute value or negation operation via a
2693 logical operation on the sign bit. */
2696 expand_absneg_bit (enum rtx_code code
, enum machine_mode mode
,
2697 rtx op0
, rtx target
)
2699 const struct real_format
*fmt
;
2700 int bitpos
, word
, nwords
, i
;
2701 enum machine_mode imode
;
2705 /* The format has to have a simple sign bit. */
2706 fmt
= REAL_MODE_FORMAT (mode
);
2710 bitpos
= fmt
->signbit_rw
;
2714 /* Don't create negative zeros if the format doesn't support them. */
2715 if (code
== NEG
&& !fmt
->has_signed_zero
)
2718 if (GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
)
2720 imode
= int_mode_for_mode (mode
);
2721 if (imode
== BLKmode
)
2730 if (FLOAT_WORDS_BIG_ENDIAN
)
2731 word
= (GET_MODE_BITSIZE (mode
) - bitpos
) / BITS_PER_WORD
;
2733 word
= bitpos
/ BITS_PER_WORD
;
2734 bitpos
= bitpos
% BITS_PER_WORD
;
2735 nwords
= (GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
;
2738 mask
= double_int_setbit (double_int_zero
, bitpos
);
2740 mask
= double_int_not (mask
);
2744 || (nwords
> 1 && !valid_multiword_target_p (target
)))
2745 target
= gen_reg_rtx (mode
);
2751 for (i
= 0; i
< nwords
; ++i
)
2753 rtx targ_piece
= operand_subword (target
, i
, 1, mode
);
2754 rtx op0_piece
= operand_subword_force (op0
, i
, mode
);
2758 temp
= expand_binop (imode
, code
== ABS
? and_optab
: xor_optab
,
2760 immed_double_int_const (mask
, imode
),
2761 targ_piece
, 1, OPTAB_LIB_WIDEN
);
2762 if (temp
!= targ_piece
)
2763 emit_move_insn (targ_piece
, temp
);
2766 emit_move_insn (targ_piece
, op0_piece
);
2769 insns
= get_insns ();
2776 temp
= expand_binop (imode
, code
== ABS
? and_optab
: xor_optab
,
2777 gen_lowpart (imode
, op0
),
2778 immed_double_int_const (mask
, imode
),
2779 gen_lowpart (imode
, target
), 1, OPTAB_LIB_WIDEN
);
2780 target
= lowpart_subreg_maybe_copy (mode
, temp
, imode
);
2782 set_unique_reg_note (get_last_insn (), REG_EQUAL
,
2783 gen_rtx_fmt_e (code
, mode
, copy_rtx (op0
)));
2789 /* As expand_unop, but will fail rather than attempt the operation in a
2790 different mode or with a libcall. */
2792 expand_unop_direct (enum machine_mode mode
, optab unoptab
, rtx op0
, rtx target
,
2795 if (optab_handler (unoptab
, mode
) != CODE_FOR_nothing
)
2797 struct expand_operand ops
[2];
2798 enum insn_code icode
= optab_handler (unoptab
, mode
);
2799 rtx last
= get_last_insn ();
2802 create_output_operand (&ops
[0], target
, mode
);
2803 create_convert_operand_from (&ops
[1], op0
, mode
, unsignedp
);
2804 pat
= maybe_gen_insn (icode
, 2, ops
);
2807 if (INSN_P (pat
) && NEXT_INSN (pat
) != NULL_RTX
2808 && ! add_equal_note (pat
, ops
[0].value
, unoptab
->code
,
2809 ops
[1].value
, NULL_RTX
))
2811 delete_insns_since (last
);
2812 return expand_unop (mode
, unoptab
, op0
, NULL_RTX
, unsignedp
);
2817 return ops
[0].value
;
2823 /* Generate code to perform an operation specified by UNOPTAB
2824 on operand OP0, with result having machine-mode MODE.
2826 UNSIGNEDP is for the case where we have to widen the operands
2827 to perform the operation. It says to use zero-extension.
2829 If TARGET is nonzero, the value
2830 is generated there, if it is convenient to do so.
2831 In all cases an rtx is returned for the locus of the value;
2832 this may or may not be TARGET. */
2835 expand_unop (enum machine_mode mode
, optab unoptab
, rtx op0
, rtx target
,
2838 enum mode_class mclass
= GET_MODE_CLASS (mode
);
2839 enum machine_mode wider_mode
;
2843 temp
= expand_unop_direct (mode
, unoptab
, op0
, target
, unsignedp
);
2847 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2849 /* Widening (or narrowing) clz needs special treatment. */
2850 if (unoptab
== clz_optab
)
2852 temp
= widen_leading (mode
, op0
, target
, unoptab
);
2856 if (GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
2857 && optab_handler (unoptab
, word_mode
) != CODE_FOR_nothing
)
2859 temp
= expand_doubleword_clz (mode
, op0
, target
);
2867 if (unoptab
== clrsb_optab
)
2869 temp
= widen_leading (mode
, op0
, target
, unoptab
);
2875 /* Widening (or narrowing) bswap needs special treatment. */
2876 if (unoptab
== bswap_optab
)
2878 temp
= widen_bswap (mode
, op0
, target
);
2882 if (GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
2883 && optab_handler (unoptab
, word_mode
) != CODE_FOR_nothing
)
2885 temp
= expand_doubleword_bswap (mode
, op0
, target
);
2893 if (CLASS_HAS_WIDER_MODES_P (mclass
))
2894 for (wider_mode
= GET_MODE_WIDER_MODE (mode
);
2895 wider_mode
!= VOIDmode
;
2896 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2898 if (optab_handler (unoptab
, wider_mode
) != CODE_FOR_nothing
)
2901 rtx last
= get_last_insn ();
2903 /* For certain operations, we need not actually extend
2904 the narrow operand, as long as we will truncate the
2905 results to the same narrowness. */
2907 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
,
2908 (unoptab
== neg_optab
2909 || unoptab
== one_cmpl_optab
)
2910 && mclass
== MODE_INT
);
2912 temp
= expand_unop (wider_mode
, unoptab
, xop0
, NULL_RTX
,
2917 if (mclass
!= MODE_INT
2918 || !TRULY_NOOP_TRUNCATION_MODES_P (mode
, wider_mode
))
2921 target
= gen_reg_rtx (mode
);
2922 convert_move (target
, temp
, 0);
2926 return gen_lowpart (mode
, temp
);
2929 delete_insns_since (last
);
2933 /* These can be done a word at a time. */
2934 if (unoptab
== one_cmpl_optab
2935 && mclass
== MODE_INT
2936 && GET_MODE_SIZE (mode
) > UNITS_PER_WORD
2937 && optab_handler (unoptab
, word_mode
) != CODE_FOR_nothing
)
2942 if (target
== 0 || target
== op0
|| !valid_multiword_target_p (target
))
2943 target
= gen_reg_rtx (mode
);
2947 /* Do the actual arithmetic. */
2948 for (i
= 0; i
< GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
; i
++)
2950 rtx target_piece
= operand_subword (target
, i
, 1, mode
);
2951 rtx x
= expand_unop (word_mode
, unoptab
,
2952 operand_subword_force (op0
, i
, mode
),
2953 target_piece
, unsignedp
);
2955 if (target_piece
!= x
)
2956 emit_move_insn (target_piece
, x
);
2959 insns
= get_insns ();
2966 if (unoptab
->code
== NEG
)
2968 /* Try negating floating point values by flipping the sign bit. */
2969 if (SCALAR_FLOAT_MODE_P (mode
))
2971 temp
= expand_absneg_bit (NEG
, mode
, op0
, target
);
2976 /* If there is no negation pattern, and we have no negative zero,
2977 try subtracting from zero. */
2978 if (!HONOR_SIGNED_ZEROS (mode
))
2980 temp
= expand_binop (mode
, (unoptab
== negv_optab
2981 ? subv_optab
: sub_optab
),
2982 CONST0_RTX (mode
), op0
, target
,
2983 unsignedp
, OPTAB_DIRECT
);
2989 /* Try calculating parity (x) as popcount (x) % 2. */
2990 if (unoptab
== parity_optab
)
2992 temp
= expand_parity (mode
, op0
, target
);
2997 /* Try implementing ffs (x) in terms of clz (x). */
2998 if (unoptab
== ffs_optab
)
3000 temp
= expand_ffs (mode
, op0
, target
);
3005 /* Try implementing ctz (x) in terms of clz (x). */
3006 if (unoptab
== ctz_optab
)
3008 temp
= expand_ctz (mode
, op0
, target
);
3014 /* Now try a library call in this mode. */
3015 libfunc
= optab_libfunc (unoptab
, mode
);
3021 enum machine_mode outmode
= mode
;
3023 /* All of these functions return small values. Thus we choose to
3024 have them return something that isn't a double-word. */
3025 if (unoptab
== ffs_optab
|| unoptab
== clz_optab
|| unoptab
== ctz_optab
3026 || unoptab
== clrsb_optab
|| unoptab
== popcount_optab
3027 || unoptab
== parity_optab
)
3029 = GET_MODE (hard_libcall_value (TYPE_MODE (integer_type_node
),
3030 optab_libfunc (unoptab
, mode
)));
3034 /* Pass 1 for NO_QUEUE so we don't lose any increments
3035 if the libcall is cse'd or moved. */
3036 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
, outmode
,
3038 insns
= get_insns ();
3041 target
= gen_reg_rtx (outmode
);
3042 eq_value
= gen_rtx_fmt_e (unoptab
->code
, mode
, op0
);
3043 if (GET_MODE_SIZE (outmode
) < GET_MODE_SIZE (mode
))
3044 eq_value
= simplify_gen_unary (TRUNCATE
, outmode
, eq_value
, mode
);
3045 else if (GET_MODE_SIZE (outmode
) > GET_MODE_SIZE (mode
))
3046 eq_value
= simplify_gen_unary (ZERO_EXTEND
, outmode
, eq_value
, mode
);
3047 emit_libcall_block (insns
, target
, value
, eq_value
);
3052 /* It can't be done in this mode. Can we do it in a wider mode? */
3054 if (CLASS_HAS_WIDER_MODES_P (mclass
))
3056 for (wider_mode
= GET_MODE_WIDER_MODE (mode
);
3057 wider_mode
!= VOIDmode
;
3058 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
3060 if (optab_handler (unoptab
, wider_mode
) != CODE_FOR_nothing
3061 || optab_libfunc (unoptab
, wider_mode
))
3064 rtx last
= get_last_insn ();
3066 /* For certain operations, we need not actually extend
3067 the narrow operand, as long as we will truncate the
3068 results to the same narrowness. */
3070 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
,
3071 (unoptab
== neg_optab
3072 || unoptab
== one_cmpl_optab
)
3073 && mclass
== MODE_INT
);
3075 temp
= expand_unop (wider_mode
, unoptab
, xop0
, NULL_RTX
,
3078 /* If we are generating clz using wider mode, adjust the
3079 result. Similarly for clrsb. */
3080 if ((unoptab
== clz_optab
|| unoptab
== clrsb_optab
)
3082 temp
= expand_binop (wider_mode
, sub_optab
, temp
,
3083 GEN_INT (GET_MODE_PRECISION (wider_mode
)
3084 - GET_MODE_PRECISION (mode
)),
3085 target
, true, OPTAB_DIRECT
);
3089 if (mclass
!= MODE_INT
)
3092 target
= gen_reg_rtx (mode
);
3093 convert_move (target
, temp
, 0);
3097 return gen_lowpart (mode
, temp
);
3100 delete_insns_since (last
);
3105 /* One final attempt at implementing negation via subtraction,
3106 this time allowing widening of the operand. */
3107 if (unoptab
->code
== NEG
&& !HONOR_SIGNED_ZEROS (mode
))
3110 temp
= expand_binop (mode
,
3111 unoptab
== negv_optab
? subv_optab
: sub_optab
,
3112 CONST0_RTX (mode
), op0
,
3113 target
, unsignedp
, OPTAB_LIB_WIDEN
);
3121 /* Emit code to compute the absolute value of OP0, with result to
3122 TARGET if convenient. (TARGET may be 0.) The return value says
3123 where the result actually is to be found.
3125 MODE is the mode of the operand; the mode of the result is
3126 different but can be deduced from MODE.
3131 expand_abs_nojump (enum machine_mode mode
, rtx op0
, rtx target
,
3132 int result_unsignedp
)
3137 result_unsignedp
= 1;
3139 /* First try to do it with a special abs instruction. */
3140 temp
= expand_unop (mode
, result_unsignedp
? abs_optab
: absv_optab
,
3145 /* For floating point modes, try clearing the sign bit. */
3146 if (SCALAR_FLOAT_MODE_P (mode
))
3148 temp
= expand_absneg_bit (ABS
, mode
, op0
, target
);
3153 /* If we have a MAX insn, we can do this as MAX (x, -x). */
3154 if (optab_handler (smax_optab
, mode
) != CODE_FOR_nothing
3155 && !HONOR_SIGNED_ZEROS (mode
))
3157 rtx last
= get_last_insn ();
3159 temp
= expand_unop (mode
, neg_optab
, op0
, NULL_RTX
, 0);
3161 temp
= expand_binop (mode
, smax_optab
, op0
, temp
, target
, 0,
3167 delete_insns_since (last
);
3170 /* If this machine has expensive jumps, we can do integer absolute
3171 value of X as (((signed) x >> (W-1)) ^ x) - ((signed) x >> (W-1)),
3172 where W is the width of MODE. */
3174 if (GET_MODE_CLASS (mode
) == MODE_INT
3175 && BRANCH_COST (optimize_insn_for_speed_p (),
3178 rtx extended
= expand_shift (RSHIFT_EXPR
, mode
, op0
,
3179 GET_MODE_PRECISION (mode
) - 1,
3182 temp
= expand_binop (mode
, xor_optab
, extended
, op0
, target
, 0,
3185 temp
= expand_binop (mode
, result_unsignedp
? sub_optab
: subv_optab
,
3186 temp
, extended
, target
, 0, OPTAB_LIB_WIDEN
);
3196 expand_abs (enum machine_mode mode
, rtx op0
, rtx target
,
3197 int result_unsignedp
, int safe
)
3202 result_unsignedp
= 1;
3204 temp
= expand_abs_nojump (mode
, op0
, target
, result_unsignedp
);
3208 /* If that does not win, use conditional jump and negate. */
3210 /* It is safe to use the target if it is the same
3211 as the source if this is also a pseudo register */
3212 if (op0
== target
&& REG_P (op0
)
3213 && REGNO (op0
) >= FIRST_PSEUDO_REGISTER
)
3216 op1
= gen_label_rtx ();
3217 if (target
== 0 || ! safe
3218 || GET_MODE (target
) != mode
3219 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
3221 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
3222 target
= gen_reg_rtx (mode
);
3224 emit_move_insn (target
, op0
);
3227 do_compare_rtx_and_jump (target
, CONST0_RTX (mode
), GE
, 0, mode
,
3228 NULL_RTX
, NULL_RTX
, op1
, -1);
3230 op0
= expand_unop (mode
, result_unsignedp
? neg_optab
: negv_optab
,
3233 emit_move_insn (target
, op0
);
3239 /* Emit code to compute the one's complement absolute value of OP0
3240 (if (OP0 < 0) OP0 = ~OP0), with result to TARGET if convenient.
3241 (TARGET may be NULL_RTX.) The return value says where the result
3242 actually is to be found.
3244 MODE is the mode of the operand; the mode of the result is
3245 different but can be deduced from MODE. */
3248 expand_one_cmpl_abs_nojump (enum machine_mode mode
, rtx op0
, rtx target
)
3252 /* Not applicable for floating point modes. */
3253 if (FLOAT_MODE_P (mode
))
3256 /* If we have a MAX insn, we can do this as MAX (x, ~x). */
3257 if (optab_handler (smax_optab
, mode
) != CODE_FOR_nothing
)
3259 rtx last
= get_last_insn ();
3261 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, NULL_RTX
, 0);
3263 temp
= expand_binop (mode
, smax_optab
, op0
, temp
, target
, 0,
3269 delete_insns_since (last
);
3272 /* If this machine has expensive jumps, we can do one's complement
3273 absolute value of X as (((signed) x >> (W-1)) ^ x). */
3275 if (GET_MODE_CLASS (mode
) == MODE_INT
3276 && BRANCH_COST (optimize_insn_for_speed_p (),
3279 rtx extended
= expand_shift (RSHIFT_EXPR
, mode
, op0
,
3280 GET_MODE_PRECISION (mode
) - 1,
3283 temp
= expand_binop (mode
, xor_optab
, extended
, op0
, target
, 0,
3293 /* A subroutine of expand_copysign, perform the copysign operation using the
3294 abs and neg primitives advertised to exist on the target. The assumption
3295 is that we have a split register file, and leaving op0 in fp registers,
3296 and not playing with subregs so much, will help the register allocator. */
3299 expand_copysign_absneg (enum machine_mode mode
, rtx op0
, rtx op1
, rtx target
,
3300 int bitpos
, bool op0_is_abs
)
3302 enum machine_mode imode
;
3303 enum insn_code icode
;
3309 /* Check if the back end provides an insn that handles signbit for the
3311 icode
= optab_handler (signbit_optab
, mode
);
3312 if (icode
!= CODE_FOR_nothing
)
3314 imode
= insn_data
[(int) icode
].operand
[0].mode
;
3315 sign
= gen_reg_rtx (imode
);
3316 emit_unop_insn (icode
, sign
, op1
, UNKNOWN
);
3322 if (GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
)
3324 imode
= int_mode_for_mode (mode
);
3325 if (imode
== BLKmode
)
3327 op1
= gen_lowpart (imode
, op1
);
3334 if (FLOAT_WORDS_BIG_ENDIAN
)
3335 word
= (GET_MODE_BITSIZE (mode
) - bitpos
) / BITS_PER_WORD
;
3337 word
= bitpos
/ BITS_PER_WORD
;
3338 bitpos
= bitpos
% BITS_PER_WORD
;
3339 op1
= operand_subword_force (op1
, word
, mode
);
3342 mask
= double_int_setbit (double_int_zero
, bitpos
);
3344 sign
= expand_binop (imode
, and_optab
, op1
,
3345 immed_double_int_const (mask
, imode
),
3346 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3351 op0
= expand_unop (mode
, abs_optab
, op0
, target
, 0);
3358 if (target
== NULL_RTX
)
3359 target
= copy_to_reg (op0
);
3361 emit_move_insn (target
, op0
);
3364 label
= gen_label_rtx ();
3365 emit_cmp_and_jump_insns (sign
, const0_rtx
, EQ
, NULL_RTX
, imode
, 1, label
);
3367 if (GET_CODE (op0
) == CONST_DOUBLE
)
3368 op0
= simplify_unary_operation (NEG
, mode
, op0
, mode
);
3370 op0
= expand_unop (mode
, neg_optab
, op0
, target
, 0);
3372 emit_move_insn (target
, op0
);
3380 /* A subroutine of expand_copysign, perform the entire copysign operation
3381 with integer bitmasks. BITPOS is the position of the sign bit; OP0_IS_ABS
3382 is true if op0 is known to have its sign bit clear. */
3385 expand_copysign_bit (enum machine_mode mode
, rtx op0
, rtx op1
, rtx target
,
3386 int bitpos
, bool op0_is_abs
)
3388 enum machine_mode imode
;
3390 int word
, nwords
, i
;
3393 if (GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
)
3395 imode
= int_mode_for_mode (mode
);
3396 if (imode
== BLKmode
)
3405 if (FLOAT_WORDS_BIG_ENDIAN
)
3406 word
= (GET_MODE_BITSIZE (mode
) - bitpos
) / BITS_PER_WORD
;
3408 word
= bitpos
/ BITS_PER_WORD
;
3409 bitpos
= bitpos
% BITS_PER_WORD
;
3410 nwords
= (GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
;
3413 mask
= double_int_setbit (double_int_zero
, bitpos
);
3418 || (nwords
> 1 && !valid_multiword_target_p (target
)))
3419 target
= gen_reg_rtx (mode
);
3425 for (i
= 0; i
< nwords
; ++i
)
3427 rtx targ_piece
= operand_subword (target
, i
, 1, mode
);
3428 rtx op0_piece
= operand_subword_force (op0
, i
, mode
);
3434 = expand_binop (imode
, and_optab
, op0_piece
,
3435 immed_double_int_const (double_int_not (mask
),
3437 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3439 op1
= expand_binop (imode
, and_optab
,
3440 operand_subword_force (op1
, i
, mode
),
3441 immed_double_int_const (mask
, imode
),
3442 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3444 temp
= expand_binop (imode
, ior_optab
, op0_piece
, op1
,
3445 targ_piece
, 1, OPTAB_LIB_WIDEN
);
3446 if (temp
!= targ_piece
)
3447 emit_move_insn (targ_piece
, temp
);
3450 emit_move_insn (targ_piece
, op0_piece
);
3453 insns
= get_insns ();
3460 op1
= expand_binop (imode
, and_optab
, gen_lowpart (imode
, op1
),
3461 immed_double_int_const (mask
, imode
),
3462 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3464 op0
= gen_lowpart (imode
, op0
);
3466 op0
= expand_binop (imode
, and_optab
, op0
,
3467 immed_double_int_const (double_int_not (mask
),
3469 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3471 temp
= expand_binop (imode
, ior_optab
, op0
, op1
,
3472 gen_lowpart (imode
, target
), 1, OPTAB_LIB_WIDEN
);
3473 target
= lowpart_subreg_maybe_copy (mode
, temp
, imode
);
3479 /* Expand the C99 copysign operation. OP0 and OP1 must be the same
3480 scalar floating point mode. Return NULL if we do not know how to
3481 expand the operation inline. */
3484 expand_copysign (rtx op0
, rtx op1
, rtx target
)
3486 enum machine_mode mode
= GET_MODE (op0
);
3487 const struct real_format
*fmt
;
3491 gcc_assert (SCALAR_FLOAT_MODE_P (mode
));
3492 gcc_assert (GET_MODE (op1
) == mode
);
3494 /* First try to do it with a special instruction. */
3495 temp
= expand_binop (mode
, copysign_optab
, op0
, op1
,
3496 target
, 0, OPTAB_DIRECT
);
3500 fmt
= REAL_MODE_FORMAT (mode
);
3501 if (fmt
== NULL
|| !fmt
->has_signed_zero
)
3505 if (GET_CODE (op0
) == CONST_DOUBLE
)
3507 if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0
)))
3508 op0
= simplify_unary_operation (ABS
, mode
, op0
, mode
);
3512 if (fmt
->signbit_ro
>= 0
3513 && (GET_CODE (op0
) == CONST_DOUBLE
3514 || (optab_handler (neg_optab
, mode
) != CODE_FOR_nothing
3515 && optab_handler (abs_optab
, mode
) != CODE_FOR_nothing
)))
3517 temp
= expand_copysign_absneg (mode
, op0
, op1
, target
,
3518 fmt
->signbit_ro
, op0_is_abs
);
3523 if (fmt
->signbit_rw
< 0)
3525 return expand_copysign_bit (mode
, op0
, op1
, target
,
3526 fmt
->signbit_rw
, op0_is_abs
);
3529 /* Generate an instruction whose insn-code is INSN_CODE,
3530 with two operands: an output TARGET and an input OP0.
3531 TARGET *must* be nonzero, and the output is always stored there.
3532 CODE is an rtx code such that (CODE OP0) is an rtx that describes
3533 the value that is stored into TARGET.
3535 Return false if expansion failed. */
3538 maybe_emit_unop_insn (enum insn_code icode
, rtx target
, rtx op0
,
3541 struct expand_operand ops
[2];
3544 create_output_operand (&ops
[0], target
, GET_MODE (target
));
3545 create_input_operand (&ops
[1], op0
, GET_MODE (op0
));
3546 pat
= maybe_gen_insn (icode
, 2, ops
);
3550 if (INSN_P (pat
) && NEXT_INSN (pat
) != NULL_RTX
&& code
!= UNKNOWN
)
3551 add_equal_note (pat
, ops
[0].value
, code
, ops
[1].value
, NULL_RTX
);
3555 if (ops
[0].value
!= target
)
3556 emit_move_insn (target
, ops
[0].value
);
3559 /* Generate an instruction whose insn-code is INSN_CODE,
3560 with two operands: an output TARGET and an input OP0.
3561 TARGET *must* be nonzero, and the output is always stored there.
3562 CODE is an rtx code such that (CODE OP0) is an rtx that describes
3563 the value that is stored into TARGET. */
3566 emit_unop_insn (enum insn_code icode
, rtx target
, rtx op0
, enum rtx_code code
)
3568 bool ok
= maybe_emit_unop_insn (icode
, target
, op0
, code
);
3572 struct no_conflict_data
3574 rtx target
, first
, insn
;
3578 /* Called via note_stores by emit_libcall_block. Set P->must_stay if
3579 the currently examined clobber / store has to stay in the list of
3580 insns that constitute the actual libcall block. */
3582 no_conflict_move_test (rtx dest
, const_rtx set
, void *p0
)
3584 struct no_conflict_data
*p
= (struct no_conflict_data
*) p0
;
3586 /* If this inns directly contributes to setting the target, it must stay. */
3587 if (reg_overlap_mentioned_p (p
->target
, dest
))
3588 p
->must_stay
= true;
3589 /* If we haven't committed to keeping any other insns in the list yet,
3590 there is nothing more to check. */
3591 else if (p
->insn
== p
->first
)
3593 /* If this insn sets / clobbers a register that feeds one of the insns
3594 already in the list, this insn has to stay too. */
3595 else if (reg_overlap_mentioned_p (dest
, PATTERN (p
->first
))
3596 || (CALL_P (p
->first
) && (find_reg_fusage (p
->first
, USE
, dest
)))
3597 || reg_used_between_p (dest
, p
->first
, p
->insn
)
3598 /* Likewise if this insn depends on a register set by a previous
3599 insn in the list, or if it sets a result (presumably a hard
3600 register) that is set or clobbered by a previous insn.
3601 N.B. the modified_*_p (SET_DEST...) tests applied to a MEM
3602 SET_DEST perform the former check on the address, and the latter
3603 check on the MEM. */
3604 || (GET_CODE (set
) == SET
3605 && (modified_in_p (SET_SRC (set
), p
->first
)
3606 || modified_in_p (SET_DEST (set
), p
->first
)
3607 || modified_between_p (SET_SRC (set
), p
->first
, p
->insn
)
3608 || modified_between_p (SET_DEST (set
), p
->first
, p
->insn
))))
3609 p
->must_stay
= true;
3613 /* Emit code to make a call to a constant function or a library call.
3615 INSNS is a list containing all insns emitted in the call.
3616 These insns leave the result in RESULT. Our block is to copy RESULT
3617 to TARGET, which is logically equivalent to EQUIV.
3619 We first emit any insns that set a pseudo on the assumption that these are
3620 loading constants into registers; doing so allows them to be safely cse'ed
3621 between blocks. Then we emit all the other insns in the block, followed by
3622 an insn to move RESULT to TARGET. This last insn will have a REQ_EQUAL
3623 note with an operand of EQUIV. */
3626 emit_libcall_block (rtx insns
, rtx target
, rtx result
, rtx equiv
)
3628 rtx final_dest
= target
;
3629 rtx next
, last
, insn
;
3631 /* If this is a reg with REG_USERVAR_P set, then it could possibly turn
3632 into a MEM later. Protect the libcall block from this change. */
3633 if (! REG_P (target
) || REG_USERVAR_P (target
))
3634 target
= gen_reg_rtx (GET_MODE (target
));
3636 /* If we're using non-call exceptions, a libcall corresponding to an
3637 operation that may trap may also trap. */
3638 /* ??? See the comment in front of make_reg_eh_region_note. */
3639 if (cfun
->can_throw_non_call_exceptions
&& may_trap_p (equiv
))
3641 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3644 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
3647 int lp_nr
= INTVAL (XEXP (note
, 0));
3648 if (lp_nr
== 0 || lp_nr
== INT_MIN
)
3649 remove_note (insn
, note
);
3655 /* Look for any CALL_INSNs in this sequence, and attach a REG_EH_REGION
3656 reg note to indicate that this call cannot throw or execute a nonlocal
3657 goto (unless there is already a REG_EH_REGION note, in which case
3659 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3661 make_reg_eh_region_note_nothrow_nononlocal (insn
);
3664 /* First emit all insns that set pseudos. Remove them from the list as
3665 we go. Avoid insns that set pseudos which were referenced in previous
3666 insns. These can be generated by move_by_pieces, for example,
3667 to update an address. Similarly, avoid insns that reference things
3668 set in previous insns. */
3670 for (insn
= insns
; insn
; insn
= next
)
3672 rtx set
= single_set (insn
);
3674 next
= NEXT_INSN (insn
);
3676 if (set
!= 0 && REG_P (SET_DEST (set
))
3677 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
)
3679 struct no_conflict_data data
;
3681 data
.target
= const0_rtx
;
3685 note_stores (PATTERN (insn
), no_conflict_move_test
, &data
);
3686 if (! data
.must_stay
)
3688 if (PREV_INSN (insn
))
3689 NEXT_INSN (PREV_INSN (insn
)) = next
;
3694 PREV_INSN (next
) = PREV_INSN (insn
);
3700 /* Some ports use a loop to copy large arguments onto the stack.
3701 Don't move anything outside such a loop. */
3706 /* Write the remaining insns followed by the final copy. */
3707 for (insn
= insns
; insn
; insn
= next
)
3709 next
= NEXT_INSN (insn
);
3714 last
= emit_move_insn (target
, result
);
3715 if (optab_handler (mov_optab
, GET_MODE (target
)) != CODE_FOR_nothing
)
3716 set_unique_reg_note (last
, REG_EQUAL
, copy_rtx (equiv
));
3718 if (final_dest
!= target
)
3719 emit_move_insn (final_dest
, target
);
3722 /* Nonzero if we can perform a comparison of mode MODE straightforwardly.
3723 PURPOSE describes how this comparison will be used. CODE is the rtx
3724 comparison code we will be using.
3726 ??? Actually, CODE is slightly weaker than that. A target is still
3727 required to implement all of the normal bcc operations, but not
3728 required to implement all (or any) of the unordered bcc operations. */
3731 can_compare_p (enum rtx_code code
, enum machine_mode mode
,
3732 enum can_compare_purpose purpose
)
3735 test
= gen_rtx_fmt_ee (code
, mode
, const0_rtx
, const0_rtx
);
3738 enum insn_code icode
;
3740 if (purpose
== ccp_jump
3741 && (icode
= optab_handler (cbranch_optab
, mode
)) != CODE_FOR_nothing
3742 && insn_operand_matches (icode
, 0, test
))
3744 if (purpose
== ccp_store_flag
3745 && (icode
= optab_handler (cstore_optab
, mode
)) != CODE_FOR_nothing
3746 && insn_operand_matches (icode
, 1, test
))
3748 if (purpose
== ccp_cmov
3749 && optab_handler (cmov_optab
, mode
) != CODE_FOR_nothing
)
3752 mode
= GET_MODE_WIDER_MODE (mode
);
3753 PUT_MODE (test
, mode
);
3755 while (mode
!= VOIDmode
);
3760 /* This function is called when we are going to emit a compare instruction that
3761 compares the values found in *PX and *PY, using the rtl operator COMPARISON.
3763 *PMODE is the mode of the inputs (in case they are const_int).
3764 *PUNSIGNEDP nonzero says that the operands are unsigned;
3765 this matters if they need to be widened (as given by METHODS).
3767 If they have mode BLKmode, then SIZE specifies the size of both operands.
3769 This function performs all the setup necessary so that the caller only has
3770 to emit a single comparison insn. This setup can involve doing a BLKmode
3771 comparison or emitting a library call to perform the comparison if no insn
3772 is available to handle it.
3773 The values which are passed in through pointers can be modified; the caller
3774 should perform the comparison on the modified values. Constant
3775 comparisons must have already been folded. */
3778 prepare_cmp_insn (rtx x
, rtx y
, enum rtx_code comparison
, rtx size
,
3779 int unsignedp
, enum optab_methods methods
,
3780 rtx
*ptest
, enum machine_mode
*pmode
)
3782 enum machine_mode mode
= *pmode
;
3784 enum machine_mode cmp_mode
;
3785 enum mode_class mclass
;
3787 /* The other methods are not needed. */
3788 gcc_assert (methods
== OPTAB_DIRECT
|| methods
== OPTAB_WIDEN
3789 || methods
== OPTAB_LIB_WIDEN
);
3791 /* If we are optimizing, force expensive constants into a register. */
3792 if (CONSTANT_P (x
) && optimize
3793 && (rtx_cost (x
, COMPARE
, optimize_insn_for_speed_p ())
3794 > COSTS_N_INSNS (1)))
3795 x
= force_reg (mode
, x
);
3797 if (CONSTANT_P (y
) && optimize
3798 && (rtx_cost (y
, COMPARE
, optimize_insn_for_speed_p ())
3799 > COSTS_N_INSNS (1)))
3800 y
= force_reg (mode
, y
);
3803 /* Make sure if we have a canonical comparison. The RTL
3804 documentation states that canonical comparisons are required only
3805 for targets which have cc0. */
3806 gcc_assert (!CONSTANT_P (x
) || CONSTANT_P (y
));
3809 /* Don't let both operands fail to indicate the mode. */
3810 if (GET_MODE (x
) == VOIDmode
&& GET_MODE (y
) == VOIDmode
)
3811 x
= force_reg (mode
, x
);
3812 if (mode
== VOIDmode
)
3813 mode
= GET_MODE (x
) != VOIDmode
? GET_MODE (x
) : GET_MODE (y
);
3815 /* Handle all BLKmode compares. */
3817 if (mode
== BLKmode
)
3819 enum machine_mode result_mode
;
3820 enum insn_code cmp_code
;
3825 = GEN_INT (MIN (MEM_ALIGN (x
), MEM_ALIGN (y
)) / BITS_PER_UNIT
);
3829 /* Try to use a memory block compare insn - either cmpstr
3830 or cmpmem will do. */
3831 for (cmp_mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
3832 cmp_mode
!= VOIDmode
;
3833 cmp_mode
= GET_MODE_WIDER_MODE (cmp_mode
))
3835 cmp_code
= direct_optab_handler (cmpmem_optab
, cmp_mode
);
3836 if (cmp_code
== CODE_FOR_nothing
)
3837 cmp_code
= direct_optab_handler (cmpstr_optab
, cmp_mode
);
3838 if (cmp_code
== CODE_FOR_nothing
)
3839 cmp_code
= direct_optab_handler (cmpstrn_optab
, cmp_mode
);
3840 if (cmp_code
== CODE_FOR_nothing
)
3843 /* Must make sure the size fits the insn's mode. */
3844 if ((CONST_INT_P (size
)
3845 && INTVAL (size
) >= (1 << GET_MODE_BITSIZE (cmp_mode
)))
3846 || (GET_MODE_BITSIZE (GET_MODE (size
))
3847 > GET_MODE_BITSIZE (cmp_mode
)))
3850 result_mode
= insn_data
[cmp_code
].operand
[0].mode
;
3851 result
= gen_reg_rtx (result_mode
);
3852 size
= convert_to_mode (cmp_mode
, size
, 1);
3853 emit_insn (GEN_FCN (cmp_code
) (result
, x
, y
, size
, opalign
));
3855 *ptest
= gen_rtx_fmt_ee (comparison
, VOIDmode
, result
, const0_rtx
);
3856 *pmode
= result_mode
;
3860 if (methods
!= OPTAB_LIB
&& methods
!= OPTAB_LIB_WIDEN
)
3863 /* Otherwise call a library function, memcmp. */
3864 libfunc
= memcmp_libfunc
;
3865 length_type
= sizetype
;
3866 result_mode
= TYPE_MODE (integer_type_node
);
3867 cmp_mode
= TYPE_MODE (length_type
);
3868 size
= convert_to_mode (TYPE_MODE (length_type
), size
,
3869 TYPE_UNSIGNED (length_type
));
3871 result
= emit_library_call_value (libfunc
, 0, LCT_PURE
,
3877 *ptest
= gen_rtx_fmt_ee (comparison
, VOIDmode
, result
, const0_rtx
);
3878 *pmode
= result_mode
;
3882 /* Don't allow operands to the compare to trap, as that can put the
3883 compare and branch in different basic blocks. */
3884 if (cfun
->can_throw_non_call_exceptions
)
3887 x
= force_reg (mode
, x
);
3889 y
= force_reg (mode
, y
);
3892 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3894 gcc_assert (can_compare_p (comparison
, CCmode
, ccp_jump
));
3895 *ptest
= gen_rtx_fmt_ee (comparison
, VOIDmode
, x
, y
);
3899 mclass
= GET_MODE_CLASS (mode
);
3900 test
= gen_rtx_fmt_ee (comparison
, VOIDmode
, x
, y
);
3904 enum insn_code icode
;
3905 icode
= optab_handler (cbranch_optab
, cmp_mode
);
3906 if (icode
!= CODE_FOR_nothing
3907 && insn_operand_matches (icode
, 0, test
))
3909 rtx last
= get_last_insn ();
3910 rtx op0
= prepare_operand (icode
, x
, 1, mode
, cmp_mode
, unsignedp
);
3911 rtx op1
= prepare_operand (icode
, y
, 2, mode
, cmp_mode
, unsignedp
);
3913 && insn_operand_matches (icode
, 1, op0
)
3914 && insn_operand_matches (icode
, 2, op1
))
3916 XEXP (test
, 0) = op0
;
3917 XEXP (test
, 1) = op1
;
3922 delete_insns_since (last
);
3925 if (methods
== OPTAB_DIRECT
|| !CLASS_HAS_WIDER_MODES_P (mclass
))
3927 cmp_mode
= GET_MODE_WIDER_MODE (cmp_mode
);
3929 while (cmp_mode
!= VOIDmode
);
3931 if (methods
!= OPTAB_LIB_WIDEN
)
3934 if (!SCALAR_FLOAT_MODE_P (mode
))
3938 /* Handle a libcall just for the mode we are using. */
3939 libfunc
= optab_libfunc (cmp_optab
, mode
);
3940 gcc_assert (libfunc
);
3942 /* If we want unsigned, and this mode has a distinct unsigned
3943 comparison routine, use that. */
3946 rtx ulibfunc
= optab_libfunc (ucmp_optab
, mode
);
3951 result
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
3952 targetm
.libgcc_cmp_return_mode (),
3953 2, x
, mode
, y
, mode
);
3955 /* There are two kinds of comparison routines. Biased routines
3956 return 0/1/2, and unbiased routines return -1/0/1. Other parts
3957 of gcc expect that the comparison operation is equivalent
3958 to the modified comparison. For signed comparisons compare the
3959 result against 1 in the biased case, and zero in the unbiased
3960 case. For unsigned comparisons always compare against 1 after
3961 biasing the unbiased result by adding 1. This gives us a way to
3966 if (!TARGET_LIB_INT_CMP_BIASED
)
3969 x
= plus_constant (result
, 1);
3975 prepare_cmp_insn (x
, y
, comparison
, NULL_RTX
, unsignedp
, methods
,
3979 prepare_float_lib_cmp (x
, y
, comparison
, ptest
, pmode
);
3987 /* Before emitting an insn with code ICODE, make sure that X, which is going
3988 to be used for operand OPNUM of the insn, is converted from mode MODE to
3989 WIDER_MODE (UNSIGNEDP determines whether it is an unsigned conversion), and
3990 that it is accepted by the operand predicate. Return the new value. */
3993 prepare_operand (enum insn_code icode
, rtx x
, int opnum
, enum machine_mode mode
,
3994 enum machine_mode wider_mode
, int unsignedp
)
3996 if (mode
!= wider_mode
)
3997 x
= convert_modes (wider_mode
, mode
, x
, unsignedp
);
3999 if (!insn_operand_matches (icode
, opnum
, x
))
4001 if (reload_completed
)
4003 x
= copy_to_mode_reg (insn_data
[(int) icode
].operand
[opnum
].mode
, x
);
4009 /* Subroutine of emit_cmp_and_jump_insns; this function is called when we know
4010 we can do the branch. */
4013 emit_cmp_and_jump_insn_1 (rtx test
, enum machine_mode mode
, rtx label
)
4015 enum machine_mode optab_mode
;
4016 enum mode_class mclass
;
4017 enum insn_code icode
;
4019 mclass
= GET_MODE_CLASS (mode
);
4020 optab_mode
= (mclass
== MODE_CC
) ? CCmode
: mode
;
4021 icode
= optab_handler (cbranch_optab
, optab_mode
);
4023 gcc_assert (icode
!= CODE_FOR_nothing
);
4024 gcc_assert (insn_operand_matches (icode
, 0, test
));
4025 emit_jump_insn (GEN_FCN (icode
) (test
, XEXP (test
, 0), XEXP (test
, 1), label
));
4028 /* Generate code to compare X with Y so that the condition codes are
4029 set and to jump to LABEL if the condition is true. If X is a
4030 constant and Y is not a constant, then the comparison is swapped to
4031 ensure that the comparison RTL has the canonical form.
4033 UNSIGNEDP nonzero says that X and Y are unsigned; this matters if they
4034 need to be widened. UNSIGNEDP is also used to select the proper
4035 branch condition code.
4037 If X and Y have mode BLKmode, then SIZE specifies the size of both X and Y.
4039 MODE is the mode of the inputs (in case they are const_int).
4041 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
4042 It will be potentially converted into an unsigned variant based on
4043 UNSIGNEDP to select a proper jump instruction. */
4046 emit_cmp_and_jump_insns (rtx x
, rtx y
, enum rtx_code comparison
, rtx size
,
4047 enum machine_mode mode
, int unsignedp
, rtx label
)
4049 rtx op0
= x
, op1
= y
;
4052 /* Swap operands and condition to ensure canonical RTL. */
4053 if (swap_commutative_operands_p (x
, y
)
4054 && can_compare_p (swap_condition (comparison
), mode
, ccp_jump
))
4057 comparison
= swap_condition (comparison
);
4060 /* If OP0 is still a constant, then both X and Y must be constants
4061 or the opposite comparison is not supported. Force X into a register
4062 to create canonical RTL. */
4063 if (CONSTANT_P (op0
))
4064 op0
= force_reg (mode
, op0
);
4067 comparison
= unsigned_condition (comparison
);
4069 prepare_cmp_insn (op0
, op1
, comparison
, size
, unsignedp
, OPTAB_LIB_WIDEN
,
4071 emit_cmp_and_jump_insn_1 (test
, mode
, label
);
4075 /* Emit a library call comparison between floating point X and Y.
4076 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). */
4079 prepare_float_lib_cmp (rtx x
, rtx y
, enum rtx_code comparison
,
4080 rtx
*ptest
, enum machine_mode
*pmode
)
4082 enum rtx_code swapped
= swap_condition (comparison
);
4083 enum rtx_code reversed
= reverse_condition_maybe_unordered (comparison
);
4084 enum machine_mode orig_mode
= GET_MODE (x
);
4085 enum machine_mode mode
, cmp_mode
;
4086 rtx true_rtx
, false_rtx
;
4087 rtx value
, target
, insns
, equiv
;
4089 bool reversed_p
= false;
4090 cmp_mode
= targetm
.libgcc_cmp_return_mode ();
4092 for (mode
= orig_mode
;
4094 mode
= GET_MODE_WIDER_MODE (mode
))
4096 if (code_to_optab
[comparison
]
4097 && (libfunc
= optab_libfunc (code_to_optab
[comparison
], mode
)))
4100 if (code_to_optab
[swapped
]
4101 && (libfunc
= optab_libfunc (code_to_optab
[swapped
], mode
)))
4104 tmp
= x
; x
= y
; y
= tmp
;
4105 comparison
= swapped
;
4109 if (code_to_optab
[reversed
]
4110 && (libfunc
= optab_libfunc (code_to_optab
[reversed
], mode
)))
4112 comparison
= reversed
;
4118 gcc_assert (mode
!= VOIDmode
);
4120 if (mode
!= orig_mode
)
4122 x
= convert_to_mode (mode
, x
, 0);
4123 y
= convert_to_mode (mode
, y
, 0);
4126 /* Attach a REG_EQUAL note describing the semantics of the libcall to
4127 the RTL. The allows the RTL optimizers to delete the libcall if the
4128 condition can be determined at compile-time. */
4129 if (comparison
== UNORDERED
4130 || FLOAT_LIB_COMPARE_RETURNS_BOOL (mode
, comparison
))
4132 true_rtx
= const_true_rtx
;
4133 false_rtx
= const0_rtx
;
4140 true_rtx
= const0_rtx
;
4141 false_rtx
= const_true_rtx
;
4145 true_rtx
= const_true_rtx
;
4146 false_rtx
= const0_rtx
;
4150 true_rtx
= const1_rtx
;
4151 false_rtx
= const0_rtx
;
4155 true_rtx
= const0_rtx
;
4156 false_rtx
= constm1_rtx
;
4160 true_rtx
= constm1_rtx
;
4161 false_rtx
= const0_rtx
;
4165 true_rtx
= const0_rtx
;
4166 false_rtx
= const1_rtx
;
4174 if (comparison
== UNORDERED
)
4176 rtx temp
= simplify_gen_relational (NE
, cmp_mode
, mode
, x
, x
);
4177 equiv
= simplify_gen_relational (NE
, cmp_mode
, mode
, y
, y
);
4178 equiv
= simplify_gen_ternary (IF_THEN_ELSE
, cmp_mode
, cmp_mode
,
4179 temp
, const_true_rtx
, equiv
);
4183 equiv
= simplify_gen_relational (comparison
, cmp_mode
, mode
, x
, y
);
4184 if (! FLOAT_LIB_COMPARE_RETURNS_BOOL (mode
, comparison
))
4185 equiv
= simplify_gen_ternary (IF_THEN_ELSE
, cmp_mode
, cmp_mode
,
4186 equiv
, true_rtx
, false_rtx
);
4190 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
4191 cmp_mode
, 2, x
, mode
, y
, mode
);
4192 insns
= get_insns ();
4195 target
= gen_reg_rtx (cmp_mode
);
4196 emit_libcall_block (insns
, target
, value
, equiv
);
4198 if (comparison
== UNORDERED
4199 || FLOAT_LIB_COMPARE_RETURNS_BOOL (mode
, comparison
)
4201 *ptest
= gen_rtx_fmt_ee (reversed_p
? EQ
: NE
, VOIDmode
, target
, false_rtx
);
4203 *ptest
= gen_rtx_fmt_ee (comparison
, VOIDmode
, target
, const0_rtx
);
4208 /* Generate code to indirectly jump to a location given in the rtx LOC. */
4211 emit_indirect_jump (rtx loc
)
4213 struct expand_operand ops
[1];
4215 create_address_operand (&ops
[0], loc
);
4216 expand_jump_insn (CODE_FOR_indirect_jump
, 1, ops
);
4220 #ifdef HAVE_conditional_move
4222 /* Emit a conditional move instruction if the machine supports one for that
4223 condition and machine mode.
4225 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
4226 the mode to use should they be constants. If it is VOIDmode, they cannot
4229 OP2 should be stored in TARGET if the comparison is true, otherwise OP3
4230 should be stored there. MODE is the mode to use should they be constants.
4231 If it is VOIDmode, they cannot both be constants.
4233 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
4234 is not supported. */
4237 emit_conditional_move (rtx target
, enum rtx_code code
, rtx op0
, rtx op1
,
4238 enum machine_mode cmode
, rtx op2
, rtx op3
,
4239 enum machine_mode mode
, int unsignedp
)
4241 rtx tem
, comparison
, last
;
4242 enum insn_code icode
;
4243 enum rtx_code reversed
;
4245 /* If one operand is constant, make it the second one. Only do this
4246 if the other operand is not constant as well. */
4248 if (swap_commutative_operands_p (op0
, op1
))
4253 code
= swap_condition (code
);
4256 /* get_condition will prefer to generate LT and GT even if the old
4257 comparison was against zero, so undo that canonicalization here since
4258 comparisons against zero are cheaper. */
4259 if (code
== LT
&& op1
== const1_rtx
)
4260 code
= LE
, op1
= const0_rtx
;
4261 else if (code
== GT
&& op1
== constm1_rtx
)
4262 code
= GE
, op1
= const0_rtx
;
4264 if (cmode
== VOIDmode
)
4265 cmode
= GET_MODE (op0
);
4267 if (swap_commutative_operands_p (op2
, op3
)
4268 && ((reversed
= reversed_comparison_code_parts (code
, op0
, op1
, NULL
))
4277 if (mode
== VOIDmode
)
4278 mode
= GET_MODE (op2
);
4280 icode
= direct_optab_handler (movcc_optab
, mode
);
4282 if (icode
== CODE_FOR_nothing
)
4286 target
= gen_reg_rtx (mode
);
4288 code
= unsignedp
? unsigned_condition (code
) : code
;
4289 comparison
= simplify_gen_relational (code
, VOIDmode
, cmode
, op0
, op1
);
4291 /* We can get const0_rtx or const_true_rtx in some circumstances. Just
4292 return NULL and let the caller figure out how best to deal with this
4294 if (!COMPARISON_P (comparison
))
4297 do_pending_stack_adjust ();
4298 last
= get_last_insn ();
4299 prepare_cmp_insn (XEXP (comparison
, 0), XEXP (comparison
, 1),
4300 GET_CODE (comparison
), NULL_RTX
, unsignedp
, OPTAB_WIDEN
,
4301 &comparison
, &cmode
);
4304 struct expand_operand ops
[4];
4306 create_output_operand (&ops
[0], target
, mode
);
4307 create_fixed_operand (&ops
[1], comparison
);
4308 create_input_operand (&ops
[2], op2
, mode
);
4309 create_input_operand (&ops
[3], op3
, mode
);
4310 if (maybe_expand_insn (icode
, 4, ops
))
4312 if (ops
[0].value
!= target
)
4313 convert_move (target
, ops
[0].value
, false);
4317 delete_insns_since (last
);
4321 /* Return nonzero if a conditional move of mode MODE is supported.
4323 This function is for combine so it can tell whether an insn that looks
4324 like a conditional move is actually supported by the hardware. If we
4325 guess wrong we lose a bit on optimization, but that's it. */
4326 /* ??? sparc64 supports conditionally moving integers values based on fp
4327 comparisons, and vice versa. How do we handle them? */
4330 can_conditionally_move_p (enum machine_mode mode
)
4332 if (direct_optab_handler (movcc_optab
, mode
) != CODE_FOR_nothing
)
4338 #endif /* HAVE_conditional_move */
4340 /* Emit a conditional addition instruction if the machine supports one for that
4341 condition and machine mode.
4343 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
4344 the mode to use should they be constants. If it is VOIDmode, they cannot
4347 OP2 should be stored in TARGET if the comparison is true, otherwise OP2+OP3
4348 should be stored there. MODE is the mode to use should they be constants.
4349 If it is VOIDmode, they cannot both be constants.
4351 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
4352 is not supported. */
4355 emit_conditional_add (rtx target
, enum rtx_code code
, rtx op0
, rtx op1
,
4356 enum machine_mode cmode
, rtx op2
, rtx op3
,
4357 enum machine_mode mode
, int unsignedp
)
4359 rtx tem
, comparison
, last
;
4360 enum insn_code icode
;
4361 enum rtx_code reversed
;
4363 /* If one operand is constant, make it the second one. Only do this
4364 if the other operand is not constant as well. */
4366 if (swap_commutative_operands_p (op0
, op1
))
4371 code
= swap_condition (code
);
4374 /* get_condition will prefer to generate LT and GT even if the old
4375 comparison was against zero, so undo that canonicalization here since
4376 comparisons against zero are cheaper. */
4377 if (code
== LT
&& op1
== const1_rtx
)
4378 code
= LE
, op1
= const0_rtx
;
4379 else if (code
== GT
&& op1
== constm1_rtx
)
4380 code
= GE
, op1
= const0_rtx
;
4382 if (cmode
== VOIDmode
)
4383 cmode
= GET_MODE (op0
);
4385 if (swap_commutative_operands_p (op2
, op3
)
4386 && ((reversed
= reversed_comparison_code_parts (code
, op0
, op1
, NULL
))
4395 if (mode
== VOIDmode
)
4396 mode
= GET_MODE (op2
);
4398 icode
= optab_handler (addcc_optab
, mode
);
4400 if (icode
== CODE_FOR_nothing
)
4404 target
= gen_reg_rtx (mode
);
4406 code
= unsignedp
? unsigned_condition (code
) : code
;
4407 comparison
= simplify_gen_relational (code
, VOIDmode
, cmode
, op0
, op1
);
4409 /* We can get const0_rtx or const_true_rtx in some circumstances. Just
4410 return NULL and let the caller figure out how best to deal with this
4412 if (!COMPARISON_P (comparison
))
4415 do_pending_stack_adjust ();
4416 last
= get_last_insn ();
4417 prepare_cmp_insn (XEXP (comparison
, 0), XEXP (comparison
, 1),
4418 GET_CODE (comparison
), NULL_RTX
, unsignedp
, OPTAB_WIDEN
,
4419 &comparison
, &cmode
);
4422 struct expand_operand ops
[4];
4424 create_output_operand (&ops
[0], target
, mode
);
4425 create_fixed_operand (&ops
[1], comparison
);
4426 create_input_operand (&ops
[2], op2
, mode
);
4427 create_input_operand (&ops
[3], op3
, mode
);
4428 if (maybe_expand_insn (icode
, 4, ops
))
4430 if (ops
[0].value
!= target
)
4431 convert_move (target
, ops
[0].value
, false);
4435 delete_insns_since (last
);
4439 /* These functions attempt to generate an insn body, rather than
4440 emitting the insn, but if the gen function already emits them, we
4441 make no attempt to turn them back into naked patterns. */
4443 /* Generate and return an insn body to add Y to X. */
4446 gen_add2_insn (rtx x
, rtx y
)
4448 enum insn_code icode
= optab_handler (add_optab
, GET_MODE (x
));
4450 gcc_assert (insn_operand_matches (icode
, 0, x
));
4451 gcc_assert (insn_operand_matches (icode
, 1, x
));
4452 gcc_assert (insn_operand_matches (icode
, 2, y
));
4454 return GEN_FCN (icode
) (x
, x
, y
);
4457 /* Generate and return an insn body to add r1 and c,
4458 storing the result in r0. */
4461 gen_add3_insn (rtx r0
, rtx r1
, rtx c
)
4463 enum insn_code icode
= optab_handler (add_optab
, GET_MODE (r0
));
4465 if (icode
== CODE_FOR_nothing
4466 || !insn_operand_matches (icode
, 0, r0
)
4467 || !insn_operand_matches (icode
, 1, r1
)
4468 || !insn_operand_matches (icode
, 2, c
))
4471 return GEN_FCN (icode
) (r0
, r1
, c
);
4475 have_add2_insn (rtx x
, rtx y
)
4477 enum insn_code icode
;
4479 gcc_assert (GET_MODE (x
) != VOIDmode
);
4481 icode
= optab_handler (add_optab
, GET_MODE (x
));
4483 if (icode
== CODE_FOR_nothing
)
4486 if (!insn_operand_matches (icode
, 0, x
)
4487 || !insn_operand_matches (icode
, 1, x
)
4488 || !insn_operand_matches (icode
, 2, y
))
4494 /* Generate and return an insn body to subtract Y from X. */
4497 gen_sub2_insn (rtx x
, rtx y
)
4499 enum insn_code icode
= optab_handler (sub_optab
, GET_MODE (x
));
4501 gcc_assert (insn_operand_matches (icode
, 0, x
));
4502 gcc_assert (insn_operand_matches (icode
, 1, x
));
4503 gcc_assert (insn_operand_matches (icode
, 2, y
));
4505 return GEN_FCN (icode
) (x
, x
, y
);
4508 /* Generate and return an insn body to subtract r1 and c,
4509 storing the result in r0. */
4512 gen_sub3_insn (rtx r0
, rtx r1
, rtx c
)
4514 enum insn_code icode
= optab_handler (sub_optab
, GET_MODE (r0
));
4516 if (icode
== CODE_FOR_nothing
4517 || !insn_operand_matches (icode
, 0, r0
)
4518 || !insn_operand_matches (icode
, 1, r1
)
4519 || !insn_operand_matches (icode
, 2, c
))
4522 return GEN_FCN (icode
) (r0
, r1
, c
);
4526 have_sub2_insn (rtx x
, rtx y
)
4528 enum insn_code icode
;
4530 gcc_assert (GET_MODE (x
) != VOIDmode
);
4532 icode
= optab_handler (sub_optab
, GET_MODE (x
));
4534 if (icode
== CODE_FOR_nothing
)
4537 if (!insn_operand_matches (icode
, 0, x
)
4538 || !insn_operand_matches (icode
, 1, x
)
4539 || !insn_operand_matches (icode
, 2, y
))
4545 /* Generate the body of an instruction to copy Y into X.
4546 It may be a list of insns, if one insn isn't enough. */
4549 gen_move_insn (rtx x
, rtx y
)
4554 emit_move_insn_1 (x
, y
);
4560 /* Return the insn code used to extend FROM_MODE to TO_MODE.
4561 UNSIGNEDP specifies zero-extension instead of sign-extension. If
4562 no such operation exists, CODE_FOR_nothing will be returned. */
4565 can_extend_p (enum machine_mode to_mode
, enum machine_mode from_mode
,
4569 #ifdef HAVE_ptr_extend
4571 return CODE_FOR_ptr_extend
;
4574 tab
= unsignedp
? zext_optab
: sext_optab
;
4575 return convert_optab_handler (tab
, to_mode
, from_mode
);
4578 /* Generate the body of an insn to extend Y (with mode MFROM)
4579 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
4582 gen_extend_insn (rtx x
, rtx y
, enum machine_mode mto
,
4583 enum machine_mode mfrom
, int unsignedp
)
4585 enum insn_code icode
= can_extend_p (mto
, mfrom
, unsignedp
);
4586 return GEN_FCN (icode
) (x
, y
);
4589 /* can_fix_p and can_float_p say whether the target machine
4590 can directly convert a given fixed point type to
4591 a given floating point type, or vice versa.
4592 The returned value is the CODE_FOR_... value to use,
4593 or CODE_FOR_nothing if these modes cannot be directly converted.
4595 *TRUNCP_PTR is set to 1 if it is necessary to output
4596 an explicit FTRUNC insn before the fix insn; otherwise 0. */
4598 static enum insn_code
4599 can_fix_p (enum machine_mode fixmode
, enum machine_mode fltmode
,
4600 int unsignedp
, int *truncp_ptr
)
4603 enum insn_code icode
;
4605 tab
= unsignedp
? ufixtrunc_optab
: sfixtrunc_optab
;
4606 icode
= convert_optab_handler (tab
, fixmode
, fltmode
);
4607 if (icode
!= CODE_FOR_nothing
)
4613 /* FIXME: This requires a port to define both FIX and FTRUNC pattern
4614 for this to work. We need to rework the fix* and ftrunc* patterns
4615 and documentation. */
4616 tab
= unsignedp
? ufix_optab
: sfix_optab
;
4617 icode
= convert_optab_handler (tab
, fixmode
, fltmode
);
4618 if (icode
!= CODE_FOR_nothing
4619 && optab_handler (ftrunc_optab
, fltmode
) != CODE_FOR_nothing
)
4626 return CODE_FOR_nothing
;
4629 static enum insn_code
4630 can_float_p (enum machine_mode fltmode
, enum machine_mode fixmode
,
4635 tab
= unsignedp
? ufloat_optab
: sfloat_optab
;
4636 return convert_optab_handler (tab
, fltmode
, fixmode
);
4639 /* Generate code to convert FROM to floating point
4640 and store in TO. FROM must be fixed point and not VOIDmode.
4641 UNSIGNEDP nonzero means regard FROM as unsigned.
4642 Normally this is done by correcting the final value
4643 if it is negative. */
4646 expand_float (rtx to
, rtx from
, int unsignedp
)
4648 enum insn_code icode
;
4650 enum machine_mode fmode
, imode
;
4651 bool can_do_signed
= false;
4653 /* Crash now, because we won't be able to decide which mode to use. */
4654 gcc_assert (GET_MODE (from
) != VOIDmode
);
4656 /* Look for an insn to do the conversion. Do it in the specified
4657 modes if possible; otherwise convert either input, output or both to
4658 wider mode. If the integer mode is wider than the mode of FROM,
4659 we can do the conversion signed even if the input is unsigned. */
4661 for (fmode
= GET_MODE (to
); fmode
!= VOIDmode
;
4662 fmode
= GET_MODE_WIDER_MODE (fmode
))
4663 for (imode
= GET_MODE (from
); imode
!= VOIDmode
;
4664 imode
= GET_MODE_WIDER_MODE (imode
))
4666 int doing_unsigned
= unsignedp
;
4668 if (fmode
!= GET_MODE (to
)
4669 && significand_size (fmode
) < GET_MODE_PRECISION (GET_MODE (from
)))
4672 icode
= can_float_p (fmode
, imode
, unsignedp
);
4673 if (icode
== CODE_FOR_nothing
&& unsignedp
)
4675 enum insn_code scode
= can_float_p (fmode
, imode
, 0);
4676 if (scode
!= CODE_FOR_nothing
)
4677 can_do_signed
= true;
4678 if (imode
!= GET_MODE (from
))
4679 icode
= scode
, doing_unsigned
= 0;
4682 if (icode
!= CODE_FOR_nothing
)
4684 if (imode
!= GET_MODE (from
))
4685 from
= convert_to_mode (imode
, from
, unsignedp
);
4687 if (fmode
!= GET_MODE (to
))
4688 target
= gen_reg_rtx (fmode
);
4690 emit_unop_insn (icode
, target
, from
,
4691 doing_unsigned
? UNSIGNED_FLOAT
: FLOAT
);
4694 convert_move (to
, target
, 0);
4699 /* Unsigned integer, and no way to convert directly. Convert as signed,
4700 then unconditionally adjust the result. */
4701 if (unsignedp
&& can_do_signed
)
4703 rtx label
= gen_label_rtx ();
4705 REAL_VALUE_TYPE offset
;
4707 /* Look for a usable floating mode FMODE wider than the source and at
4708 least as wide as the target. Using FMODE will avoid rounding woes
4709 with unsigned values greater than the signed maximum value. */
4711 for (fmode
= GET_MODE (to
); fmode
!= VOIDmode
;
4712 fmode
= GET_MODE_WIDER_MODE (fmode
))
4713 if (GET_MODE_PRECISION (GET_MODE (from
)) < GET_MODE_BITSIZE (fmode
)
4714 && can_float_p (fmode
, GET_MODE (from
), 0) != CODE_FOR_nothing
)
4717 if (fmode
== VOIDmode
)
4719 /* There is no such mode. Pretend the target is wide enough. */
4720 fmode
= GET_MODE (to
);
4722 /* Avoid double-rounding when TO is narrower than FROM. */
4723 if ((significand_size (fmode
) + 1)
4724 < GET_MODE_PRECISION (GET_MODE (from
)))
4727 rtx neglabel
= gen_label_rtx ();
4729 /* Don't use TARGET if it isn't a register, is a hard register,
4730 or is the wrong mode. */
4732 || REGNO (target
) < FIRST_PSEUDO_REGISTER
4733 || GET_MODE (target
) != fmode
)
4734 target
= gen_reg_rtx (fmode
);
4736 imode
= GET_MODE (from
);
4737 do_pending_stack_adjust ();
4739 /* Test whether the sign bit is set. */
4740 emit_cmp_and_jump_insns (from
, const0_rtx
, LT
, NULL_RTX
, imode
,
4743 /* The sign bit is not set. Convert as signed. */
4744 expand_float (target
, from
, 0);
4745 emit_jump_insn (gen_jump (label
));
4748 /* The sign bit is set.
4749 Convert to a usable (positive signed) value by shifting right
4750 one bit, while remembering if a nonzero bit was shifted
4751 out; i.e., compute (from & 1) | (from >> 1). */
4753 emit_label (neglabel
);
4754 temp
= expand_binop (imode
, and_optab
, from
, const1_rtx
,
4755 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
4756 temp1
= expand_shift (RSHIFT_EXPR
, imode
, from
, 1, NULL_RTX
, 1);
4757 temp
= expand_binop (imode
, ior_optab
, temp
, temp1
, temp
, 1,
4759 expand_float (target
, temp
, 0);
4761 /* Multiply by 2 to undo the shift above. */
4762 temp
= expand_binop (fmode
, add_optab
, target
, target
,
4763 target
, 0, OPTAB_LIB_WIDEN
);
4765 emit_move_insn (target
, temp
);
4767 do_pending_stack_adjust ();
4773 /* If we are about to do some arithmetic to correct for an
4774 unsigned operand, do it in a pseudo-register. */
4776 if (GET_MODE (to
) != fmode
4777 || !REG_P (to
) || REGNO (to
) < FIRST_PSEUDO_REGISTER
)
4778 target
= gen_reg_rtx (fmode
);
4780 /* Convert as signed integer to floating. */
4781 expand_float (target
, from
, 0);
4783 /* If FROM is negative (and therefore TO is negative),
4784 correct its value by 2**bitwidth. */
4786 do_pending_stack_adjust ();
4787 emit_cmp_and_jump_insns (from
, const0_rtx
, GE
, NULL_RTX
, GET_MODE (from
),
4791 real_2expN (&offset
, GET_MODE_PRECISION (GET_MODE (from
)), fmode
);
4792 temp
= expand_binop (fmode
, add_optab
, target
,
4793 CONST_DOUBLE_FROM_REAL_VALUE (offset
, fmode
),
4794 target
, 0, OPTAB_LIB_WIDEN
);
4796 emit_move_insn (target
, temp
);
4798 do_pending_stack_adjust ();
4803 /* No hardware instruction available; call a library routine. */
4808 convert_optab tab
= unsignedp
? ufloat_optab
: sfloat_optab
;
4810 if (GET_MODE_SIZE (GET_MODE (from
)) < GET_MODE_SIZE (SImode
))
4811 from
= convert_to_mode (SImode
, from
, unsignedp
);
4813 libfunc
= convert_optab_libfunc (tab
, GET_MODE (to
), GET_MODE (from
));
4814 gcc_assert (libfunc
);
4818 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
4819 GET_MODE (to
), 1, from
,
4821 insns
= get_insns ();
4824 emit_libcall_block (insns
, target
, value
,
4825 gen_rtx_fmt_e (unsignedp
? UNSIGNED_FLOAT
: FLOAT
,
4826 GET_MODE (to
), from
));
4831 /* Copy result to requested destination
4832 if we have been computing in a temp location. */
4836 if (GET_MODE (target
) == GET_MODE (to
))
4837 emit_move_insn (to
, target
);
4839 convert_move (to
, target
, 0);
4843 /* Generate code to convert FROM to fixed point and store in TO. FROM
4844 must be floating point. */
4847 expand_fix (rtx to
, rtx from
, int unsignedp
)
4849 enum insn_code icode
;
4851 enum machine_mode fmode
, imode
;
4854 /* We first try to find a pair of modes, one real and one integer, at
4855 least as wide as FROM and TO, respectively, in which we can open-code
4856 this conversion. If the integer mode is wider than the mode of TO,
4857 we can do the conversion either signed or unsigned. */
4859 for (fmode
= GET_MODE (from
); fmode
!= VOIDmode
;
4860 fmode
= GET_MODE_WIDER_MODE (fmode
))
4861 for (imode
= GET_MODE (to
); imode
!= VOIDmode
;
4862 imode
= GET_MODE_WIDER_MODE (imode
))
4864 int doing_unsigned
= unsignedp
;
4866 icode
= can_fix_p (imode
, fmode
, unsignedp
, &must_trunc
);
4867 if (icode
== CODE_FOR_nothing
&& imode
!= GET_MODE (to
) && unsignedp
)
4868 icode
= can_fix_p (imode
, fmode
, 0, &must_trunc
), doing_unsigned
= 0;
4870 if (icode
!= CODE_FOR_nothing
)
4872 rtx last
= get_last_insn ();
4873 if (fmode
!= GET_MODE (from
))
4874 from
= convert_to_mode (fmode
, from
, 0);
4878 rtx temp
= gen_reg_rtx (GET_MODE (from
));
4879 from
= expand_unop (GET_MODE (from
), ftrunc_optab
, from
,
4883 if (imode
!= GET_MODE (to
))
4884 target
= gen_reg_rtx (imode
);
4886 if (maybe_emit_unop_insn (icode
, target
, from
,
4887 doing_unsigned
? UNSIGNED_FIX
: FIX
))
4890 convert_move (to
, target
, unsignedp
);
4893 delete_insns_since (last
);
4897 /* For an unsigned conversion, there is one more way to do it.
4898 If we have a signed conversion, we generate code that compares
4899 the real value to the largest representable positive number. If if
4900 is smaller, the conversion is done normally. Otherwise, subtract
4901 one plus the highest signed number, convert, and add it back.
4903 We only need to check all real modes, since we know we didn't find
4904 anything with a wider integer mode.
4906 This code used to extend FP value into mode wider than the destination.
4907 This is needed for decimal float modes which cannot accurately
4908 represent one plus the highest signed number of the same size, but
4909 not for binary modes. Consider, for instance conversion from SFmode
4912 The hot path through the code is dealing with inputs smaller than 2^63
4913 and doing just the conversion, so there is no bits to lose.
4915 In the other path we know the value is positive in the range 2^63..2^64-1
4916 inclusive. (as for other input overflow happens and result is undefined)
4917 So we know that the most important bit set in mantissa corresponds to
4918 2^63. The subtraction of 2^63 should not generate any rounding as it
4919 simply clears out that bit. The rest is trivial. */
4921 if (unsignedp
&& GET_MODE_PRECISION (GET_MODE (to
)) <= HOST_BITS_PER_WIDE_INT
)
4922 for (fmode
= GET_MODE (from
); fmode
!= VOIDmode
;
4923 fmode
= GET_MODE_WIDER_MODE (fmode
))
4924 if (CODE_FOR_nothing
!= can_fix_p (GET_MODE (to
), fmode
, 0, &must_trunc
)
4925 && (!DECIMAL_FLOAT_MODE_P (fmode
)
4926 || GET_MODE_BITSIZE (fmode
) > GET_MODE_PRECISION (GET_MODE (to
))))
4929 REAL_VALUE_TYPE offset
;
4930 rtx limit
, lab1
, lab2
, insn
;
4932 bitsize
= GET_MODE_PRECISION (GET_MODE (to
));
4933 real_2expN (&offset
, bitsize
- 1, fmode
);
4934 limit
= CONST_DOUBLE_FROM_REAL_VALUE (offset
, fmode
);
4935 lab1
= gen_label_rtx ();
4936 lab2
= gen_label_rtx ();
4938 if (fmode
!= GET_MODE (from
))
4939 from
= convert_to_mode (fmode
, from
, 0);
4941 /* See if we need to do the subtraction. */
4942 do_pending_stack_adjust ();
4943 emit_cmp_and_jump_insns (from
, limit
, GE
, NULL_RTX
, GET_MODE (from
),
4946 /* If not, do the signed "fix" and branch around fixup code. */
4947 expand_fix (to
, from
, 0);
4948 emit_jump_insn (gen_jump (lab2
));
4951 /* Otherwise, subtract 2**(N-1), convert to signed number,
4952 then add 2**(N-1). Do the addition using XOR since this
4953 will often generate better code. */
4955 target
= expand_binop (GET_MODE (from
), sub_optab
, from
, limit
,
4956 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4957 expand_fix (to
, target
, 0);
4958 target
= expand_binop (GET_MODE (to
), xor_optab
, to
,
4960 ((HOST_WIDE_INT
) 1 << (bitsize
- 1),
4962 to
, 1, OPTAB_LIB_WIDEN
);
4965 emit_move_insn (to
, target
);
4969 if (optab_handler (mov_optab
, GET_MODE (to
)) != CODE_FOR_nothing
)
4971 /* Make a place for a REG_NOTE and add it. */
4972 insn
= emit_move_insn (to
, to
);
4973 set_unique_reg_note (insn
,
4975 gen_rtx_fmt_e (UNSIGNED_FIX
,
4983 /* We can't do it with an insn, so use a library call. But first ensure
4984 that the mode of TO is at least as wide as SImode, since those are the
4985 only library calls we know about. */
4987 if (GET_MODE_SIZE (GET_MODE (to
)) < GET_MODE_SIZE (SImode
))
4989 target
= gen_reg_rtx (SImode
);
4991 expand_fix (target
, from
, unsignedp
);
4999 convert_optab tab
= unsignedp
? ufix_optab
: sfix_optab
;
5000 libfunc
= convert_optab_libfunc (tab
, GET_MODE (to
), GET_MODE (from
));
5001 gcc_assert (libfunc
);
5005 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
5006 GET_MODE (to
), 1, from
,
5008 insns
= get_insns ();
5011 emit_libcall_block (insns
, target
, value
,
5012 gen_rtx_fmt_e (unsignedp
? UNSIGNED_FIX
: FIX
,
5013 GET_MODE (to
), from
));
5018 if (GET_MODE (to
) == GET_MODE (target
))
5019 emit_move_insn (to
, target
);
5021 convert_move (to
, target
, 0);
5025 /* Generate code to convert FROM or TO a fixed-point.
5026 If UINTP is true, either TO or FROM is an unsigned integer.
5027 If SATP is true, we need to saturate the result. */
5030 expand_fixed_convert (rtx to
, rtx from
, int uintp
, int satp
)
5032 enum machine_mode to_mode
= GET_MODE (to
);
5033 enum machine_mode from_mode
= GET_MODE (from
);
5035 enum rtx_code this_code
;
5036 enum insn_code code
;
5040 if (to_mode
== from_mode
)
5042 emit_move_insn (to
, from
);
5048 tab
= satp
? satfractuns_optab
: fractuns_optab
;
5049 this_code
= satp
? UNSIGNED_SAT_FRACT
: UNSIGNED_FRACT_CONVERT
;
5053 tab
= satp
? satfract_optab
: fract_optab
;
5054 this_code
= satp
? SAT_FRACT
: FRACT_CONVERT
;
5056 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
5057 if (code
!= CODE_FOR_nothing
)
5059 emit_unop_insn (code
, to
, from
, this_code
);
5063 libfunc
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
5064 gcc_assert (libfunc
);
5067 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
, to_mode
,
5068 1, from
, from_mode
);
5069 insns
= get_insns ();
5072 emit_libcall_block (insns
, to
, value
,
5073 gen_rtx_fmt_e (tab
->code
, to_mode
, from
));
5076 /* Generate code to convert FROM to fixed point and store in TO. FROM
5077 must be floating point, TO must be signed. Use the conversion optab
5078 TAB to do the conversion. */
5081 expand_sfix_optab (rtx to
, rtx from
, convert_optab tab
)
5083 enum insn_code icode
;
5085 enum machine_mode fmode
, imode
;
5087 /* We first try to find a pair of modes, one real and one integer, at
5088 least as wide as FROM and TO, respectively, in which we can open-code
5089 this conversion. If the integer mode is wider than the mode of TO,
5090 we can do the conversion either signed or unsigned. */
5092 for (fmode
= GET_MODE (from
); fmode
!= VOIDmode
;
5093 fmode
= GET_MODE_WIDER_MODE (fmode
))
5094 for (imode
= GET_MODE (to
); imode
!= VOIDmode
;
5095 imode
= GET_MODE_WIDER_MODE (imode
))
5097 icode
= convert_optab_handler (tab
, imode
, fmode
);
5098 if (icode
!= CODE_FOR_nothing
)
5100 rtx last
= get_last_insn ();
5101 if (fmode
!= GET_MODE (from
))
5102 from
= convert_to_mode (fmode
, from
, 0);
5104 if (imode
!= GET_MODE (to
))
5105 target
= gen_reg_rtx (imode
);
5107 if (!maybe_emit_unop_insn (icode
, target
, from
, UNKNOWN
))
5109 delete_insns_since (last
);
5113 convert_move (to
, target
, 0);
5121 /* Report whether we have an instruction to perform the operation
5122 specified by CODE on operands of mode MODE. */
5124 have_insn_for (enum rtx_code code
, enum machine_mode mode
)
5126 return (code_to_optab
[(int) code
] != 0
5127 && (optab_handler (code_to_optab
[(int) code
], mode
)
5128 != CODE_FOR_nothing
));
5131 /* Set all insn_code fields to CODE_FOR_nothing. */
5134 init_insn_codes (void)
5136 memset (optab_table
, 0, sizeof (optab_table
));
5137 memset (convert_optab_table
, 0, sizeof (convert_optab_table
));
5138 memset (direct_optab_table
, 0, sizeof (direct_optab_table
));
5141 /* Initialize OP's code to CODE, and write it into the code_to_optab table. */
5143 init_optab (optab op
, enum rtx_code code
)
5146 code_to_optab
[(int) code
] = op
;
5149 /* Same, but fill in its code as CODE, and do _not_ write it into
5150 the code_to_optab table. */
5152 init_optabv (optab op
, enum rtx_code code
)
5157 /* Conversion optabs never go in the code_to_optab table. */
5159 init_convert_optab (convert_optab op
, enum rtx_code code
)
5164 /* Initialize the libfunc fields of an entire group of entries in some
5165 optab. Each entry is set equal to a string consisting of a leading
5166 pair of underscores followed by a generic operation name followed by
5167 a mode name (downshifted to lowercase) followed by a single character
5168 representing the number of operands for the given operation (which is
5169 usually one of the characters '2', '3', or '4').
5171 OPTABLE is the table in which libfunc fields are to be initialized.
5172 OPNAME is the generic (string) name of the operation.
5173 SUFFIX is the character which specifies the number of operands for
5174 the given generic operation.
5175 MODE is the mode to generate for.
5179 gen_libfunc (optab optable
, const char *opname
, int suffix
, enum machine_mode mode
)
5181 unsigned opname_len
= strlen (opname
);
5182 const char *mname
= GET_MODE_NAME (mode
);
5183 unsigned mname_len
= strlen (mname
);
5184 int prefix_len
= targetm
.libfunc_gnu_prefix
? 6 : 2;
5185 int len
= prefix_len
+ opname_len
+ mname_len
+ 1 + 1;
5186 char *libfunc_name
= XALLOCAVEC (char, len
);
5193 if (targetm
.libfunc_gnu_prefix
)
5200 for (q
= opname
; *q
; )
5202 for (q
= mname
; *q
; q
++)
5203 *p
++ = TOLOWER (*q
);
5207 set_optab_libfunc (optable
, mode
,
5208 ggc_alloc_string (libfunc_name
, p
- libfunc_name
));
5211 /* Like gen_libfunc, but verify that integer operation is involved. */
5214 gen_int_libfunc (optab optable
, const char *opname
, char suffix
,
5215 enum machine_mode mode
)
5217 int maxsize
= 2 * BITS_PER_WORD
;
5219 if (GET_MODE_CLASS (mode
) != MODE_INT
)
5221 if (maxsize
< LONG_LONG_TYPE_SIZE
)
5222 maxsize
= LONG_LONG_TYPE_SIZE
;
5223 if (GET_MODE_CLASS (mode
) != MODE_INT
5224 || mode
< word_mode
|| GET_MODE_BITSIZE (mode
) > maxsize
)
5226 gen_libfunc (optable
, opname
, suffix
, mode
);
5229 /* Like gen_libfunc, but verify that FP and set decimal prefix if needed. */
5232 gen_fp_libfunc (optab optable
, const char *opname
, char suffix
,
5233 enum machine_mode mode
)
5237 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
5238 gen_libfunc (optable
, opname
, suffix
, mode
);
5239 if (DECIMAL_FLOAT_MODE_P (mode
))
5241 dec_opname
= XALLOCAVEC (char, sizeof (DECIMAL_PREFIX
) + strlen (opname
));
5242 /* For BID support, change the name to have either a bid_ or dpd_ prefix
5243 depending on the low level floating format used. */
5244 memcpy (dec_opname
, DECIMAL_PREFIX
, sizeof (DECIMAL_PREFIX
) - 1);
5245 strcpy (dec_opname
+ sizeof (DECIMAL_PREFIX
) - 1, opname
);
5246 gen_libfunc (optable
, dec_opname
, suffix
, mode
);
5250 /* Like gen_libfunc, but verify that fixed-point operation is involved. */
5253 gen_fixed_libfunc (optab optable
, const char *opname
, char suffix
,
5254 enum machine_mode mode
)
5256 if (!ALL_FIXED_POINT_MODE_P (mode
))
5258 gen_libfunc (optable
, opname
, suffix
, mode
);
5261 /* Like gen_libfunc, but verify that signed fixed-point operation is
5265 gen_signed_fixed_libfunc (optab optable
, const char *opname
, char suffix
,
5266 enum machine_mode mode
)
5268 if (!SIGNED_FIXED_POINT_MODE_P (mode
))
5270 gen_libfunc (optable
, opname
, suffix
, mode
);
5273 /* Like gen_libfunc, but verify that unsigned fixed-point operation is
5277 gen_unsigned_fixed_libfunc (optab optable
, const char *opname
, char suffix
,
5278 enum machine_mode mode
)
5280 if (!UNSIGNED_FIXED_POINT_MODE_P (mode
))
5282 gen_libfunc (optable
, opname
, suffix
, mode
);
5285 /* Like gen_libfunc, but verify that FP or INT operation is involved. */
5288 gen_int_fp_libfunc (optab optable
, const char *name
, char suffix
,
5289 enum machine_mode mode
)
5291 if (DECIMAL_FLOAT_MODE_P (mode
) || GET_MODE_CLASS (mode
) == MODE_FLOAT
)
5292 gen_fp_libfunc (optable
, name
, suffix
, mode
);
5293 if (INTEGRAL_MODE_P (mode
))
5294 gen_int_libfunc (optable
, name
, suffix
, mode
);
5297 /* Like gen_libfunc, but verify that FP or INT operation is involved
5298 and add 'v' suffix for integer operation. */
5301 gen_intv_fp_libfunc (optab optable
, const char *name
, char suffix
,
5302 enum machine_mode mode
)
5304 if (DECIMAL_FLOAT_MODE_P (mode
) || GET_MODE_CLASS (mode
) == MODE_FLOAT
)
5305 gen_fp_libfunc (optable
, name
, suffix
, mode
);
5306 if (GET_MODE_CLASS (mode
) == MODE_INT
)
5308 int len
= strlen (name
);
5309 char *v_name
= XALLOCAVEC (char, len
+ 2);
5310 strcpy (v_name
, name
);
5312 v_name
[len
+ 1] = 0;
5313 gen_int_libfunc (optable
, v_name
, suffix
, mode
);
5317 /* Like gen_libfunc, but verify that FP or INT or FIXED operation is
5321 gen_int_fp_fixed_libfunc (optab optable
, const char *name
, char suffix
,
5322 enum machine_mode mode
)
5324 if (DECIMAL_FLOAT_MODE_P (mode
) || GET_MODE_CLASS (mode
) == MODE_FLOAT
)
5325 gen_fp_libfunc (optable
, name
, suffix
, mode
);
5326 if (INTEGRAL_MODE_P (mode
))
5327 gen_int_libfunc (optable
, name
, suffix
, mode
);
5328 if (ALL_FIXED_POINT_MODE_P (mode
))
5329 gen_fixed_libfunc (optable
, name
, suffix
, mode
);
5332 /* Like gen_libfunc, but verify that FP or INT or signed FIXED operation is
5336 gen_int_fp_signed_fixed_libfunc (optab optable
, const char *name
, char suffix
,
5337 enum machine_mode mode
)
5339 if (DECIMAL_FLOAT_MODE_P (mode
) || GET_MODE_CLASS (mode
) == MODE_FLOAT
)
5340 gen_fp_libfunc (optable
, name
, suffix
, mode
);
5341 if (INTEGRAL_MODE_P (mode
))
5342 gen_int_libfunc (optable
, name
, suffix
, mode
);
5343 if (SIGNED_FIXED_POINT_MODE_P (mode
))
5344 gen_signed_fixed_libfunc (optable
, name
, suffix
, mode
);
5347 /* Like gen_libfunc, but verify that INT or FIXED operation is
5351 gen_int_fixed_libfunc (optab optable
, const char *name
, char suffix
,
5352 enum machine_mode mode
)
5354 if (INTEGRAL_MODE_P (mode
))
5355 gen_int_libfunc (optable
, name
, suffix
, mode
);
5356 if (ALL_FIXED_POINT_MODE_P (mode
))
5357 gen_fixed_libfunc (optable
, name
, suffix
, mode
);
5360 /* Like gen_libfunc, but verify that INT or signed FIXED operation is
5364 gen_int_signed_fixed_libfunc (optab optable
, const char *name
, char suffix
,
5365 enum machine_mode mode
)
5367 if (INTEGRAL_MODE_P (mode
))
5368 gen_int_libfunc (optable
, name
, suffix
, mode
);
5369 if (SIGNED_FIXED_POINT_MODE_P (mode
))
5370 gen_signed_fixed_libfunc (optable
, name
, suffix
, mode
);
5373 /* Like gen_libfunc, but verify that INT or unsigned FIXED operation is
5377 gen_int_unsigned_fixed_libfunc (optab optable
, const char *name
, char suffix
,
5378 enum machine_mode mode
)
5380 if (INTEGRAL_MODE_P (mode
))
5381 gen_int_libfunc (optable
, name
, suffix
, mode
);
5382 if (UNSIGNED_FIXED_POINT_MODE_P (mode
))
5383 gen_unsigned_fixed_libfunc (optable
, name
, suffix
, mode
);
5386 /* Initialize the libfunc fields of an entire group of entries of an
5387 inter-mode-class conversion optab. The string formation rules are
5388 similar to the ones for init_libfuncs, above, but instead of having
5389 a mode name and an operand count these functions have two mode names
5390 and no operand count. */
5393 gen_interclass_conv_libfunc (convert_optab tab
,
5395 enum machine_mode tmode
,
5396 enum machine_mode fmode
)
5398 size_t opname_len
= strlen (opname
);
5399 size_t mname_len
= 0;
5401 const char *fname
, *tname
;
5403 int prefix_len
= targetm
.libfunc_gnu_prefix
? 6 : 2;
5404 char *libfunc_name
, *suffix
;
5405 char *nondec_name
, *dec_name
, *nondec_suffix
, *dec_suffix
;
5408 /* If this is a decimal conversion, add the current BID vs. DPD prefix that
5409 depends on which underlying decimal floating point format is used. */
5410 const size_t dec_len
= sizeof (DECIMAL_PREFIX
) - 1;
5412 mname_len
= strlen (GET_MODE_NAME (tmode
)) + strlen (GET_MODE_NAME (fmode
));
5414 nondec_name
= XALLOCAVEC (char, prefix_len
+ opname_len
+ mname_len
+ 1 + 1);
5415 nondec_name
[0] = '_';
5416 nondec_name
[1] = '_';
5417 if (targetm
.libfunc_gnu_prefix
)
5419 nondec_name
[2] = 'g';
5420 nondec_name
[3] = 'n';
5421 nondec_name
[4] = 'u';
5422 nondec_name
[5] = '_';
5425 memcpy (&nondec_name
[prefix_len
], opname
, opname_len
);
5426 nondec_suffix
= nondec_name
+ opname_len
+ prefix_len
;
5428 dec_name
= XALLOCAVEC (char, 2 + dec_len
+ opname_len
+ mname_len
+ 1 + 1);
5431 memcpy (&dec_name
[2], DECIMAL_PREFIX
, dec_len
);
5432 memcpy (&dec_name
[2+dec_len
], opname
, opname_len
);
5433 dec_suffix
= dec_name
+ dec_len
+ opname_len
+ 2;
5435 fname
= GET_MODE_NAME (fmode
);
5436 tname
= GET_MODE_NAME (tmode
);
5438 if (DECIMAL_FLOAT_MODE_P(fmode
) || DECIMAL_FLOAT_MODE_P(tmode
))
5440 libfunc_name
= dec_name
;
5441 suffix
= dec_suffix
;
5445 libfunc_name
= nondec_name
;
5446 suffix
= nondec_suffix
;
5450 for (q
= fname
; *q
; p
++, q
++)
5452 for (q
= tname
; *q
; p
++, q
++)
5457 set_conv_libfunc (tab
, tmode
, fmode
,
5458 ggc_alloc_string (libfunc_name
, p
- libfunc_name
));
5461 /* Same as gen_interclass_conv_libfunc but verify that we are producing
5462 int->fp conversion. */
5465 gen_int_to_fp_conv_libfunc (convert_optab tab
,
5467 enum machine_mode tmode
,
5468 enum machine_mode fmode
)
5470 if (GET_MODE_CLASS (fmode
) != MODE_INT
)
5472 if (GET_MODE_CLASS (tmode
) != MODE_FLOAT
&& !DECIMAL_FLOAT_MODE_P (tmode
))
5474 gen_interclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5477 /* ufloat_optab is special by using floatun for FP and floatuns decimal fp
5481 gen_ufloat_conv_libfunc (convert_optab tab
,
5482 const char *opname ATTRIBUTE_UNUSED
,
5483 enum machine_mode tmode
,
5484 enum machine_mode fmode
)
5486 if (DECIMAL_FLOAT_MODE_P (tmode
))
5487 gen_int_to_fp_conv_libfunc (tab
, "floatuns", tmode
, fmode
);
5489 gen_int_to_fp_conv_libfunc (tab
, "floatun", tmode
, fmode
);
5492 /* Same as gen_interclass_conv_libfunc but verify that we are producing
5493 fp->int conversion. */
5496 gen_int_to_fp_nondecimal_conv_libfunc (convert_optab tab
,
5498 enum machine_mode tmode
,
5499 enum machine_mode fmode
)
5501 if (GET_MODE_CLASS (fmode
) != MODE_INT
)
5503 if (GET_MODE_CLASS (tmode
) != MODE_FLOAT
)
5505 gen_interclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5508 /* Same as gen_interclass_conv_libfunc but verify that we are producing
5509 fp->int conversion with no decimal floating point involved. */
5512 gen_fp_to_int_conv_libfunc (convert_optab tab
,
5514 enum machine_mode tmode
,
5515 enum machine_mode fmode
)
5517 if (GET_MODE_CLASS (fmode
) != MODE_FLOAT
&& !DECIMAL_FLOAT_MODE_P (fmode
))
5519 if (GET_MODE_CLASS (tmode
) != MODE_INT
)
5521 gen_interclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5524 /* Initialize the libfunc fields of an of an intra-mode-class conversion optab.
5525 The string formation rules are
5526 similar to the ones for init_libfunc, above. */
5529 gen_intraclass_conv_libfunc (convert_optab tab
, const char *opname
,
5530 enum machine_mode tmode
, enum machine_mode fmode
)
5532 size_t opname_len
= strlen (opname
);
5533 size_t mname_len
= 0;
5535 const char *fname
, *tname
;
5537 int prefix_len
= targetm
.libfunc_gnu_prefix
? 6 : 2;
5538 char *nondec_name
, *dec_name
, *nondec_suffix
, *dec_suffix
;
5539 char *libfunc_name
, *suffix
;
5542 /* If this is a decimal conversion, add the current BID vs. DPD prefix that
5543 depends on which underlying decimal floating point format is used. */
5544 const size_t dec_len
= sizeof (DECIMAL_PREFIX
) - 1;
5546 mname_len
= strlen (GET_MODE_NAME (tmode
)) + strlen (GET_MODE_NAME (fmode
));
5548 nondec_name
= XALLOCAVEC (char, 2 + opname_len
+ mname_len
+ 1 + 1);
5549 nondec_name
[0] = '_';
5550 nondec_name
[1] = '_';
5551 if (targetm
.libfunc_gnu_prefix
)
5553 nondec_name
[2] = 'g';
5554 nondec_name
[3] = 'n';
5555 nondec_name
[4] = 'u';
5556 nondec_name
[5] = '_';
5558 memcpy (&nondec_name
[prefix_len
], opname
, opname_len
);
5559 nondec_suffix
= nondec_name
+ opname_len
+ prefix_len
;
5561 dec_name
= XALLOCAVEC (char, 2 + dec_len
+ opname_len
+ mname_len
+ 1 + 1);
5564 memcpy (&dec_name
[2], DECIMAL_PREFIX
, dec_len
);
5565 memcpy (&dec_name
[2 + dec_len
], opname
, opname_len
);
5566 dec_suffix
= dec_name
+ dec_len
+ opname_len
+ 2;
5568 fname
= GET_MODE_NAME (fmode
);
5569 tname
= GET_MODE_NAME (tmode
);
5571 if (DECIMAL_FLOAT_MODE_P(fmode
) || DECIMAL_FLOAT_MODE_P(tmode
))
5573 libfunc_name
= dec_name
;
5574 suffix
= dec_suffix
;
5578 libfunc_name
= nondec_name
;
5579 suffix
= nondec_suffix
;
5583 for (q
= fname
; *q
; p
++, q
++)
5585 for (q
= tname
; *q
; p
++, q
++)
5591 set_conv_libfunc (tab
, tmode
, fmode
,
5592 ggc_alloc_string (libfunc_name
, p
- libfunc_name
));
5595 /* Pick proper libcall for trunc_optab. We need to chose if we do
5596 truncation or extension and interclass or intraclass. */
5599 gen_trunc_conv_libfunc (convert_optab tab
,
5601 enum machine_mode tmode
,
5602 enum machine_mode fmode
)
5604 if (GET_MODE_CLASS (tmode
) != MODE_FLOAT
&& !DECIMAL_FLOAT_MODE_P (tmode
))
5606 if (GET_MODE_CLASS (fmode
) != MODE_FLOAT
&& !DECIMAL_FLOAT_MODE_P (fmode
))
5611 if ((GET_MODE_CLASS (tmode
) == MODE_FLOAT
&& DECIMAL_FLOAT_MODE_P (fmode
))
5612 || (GET_MODE_CLASS (fmode
) == MODE_FLOAT
&& DECIMAL_FLOAT_MODE_P (tmode
)))
5613 gen_interclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5615 if (GET_MODE_PRECISION (fmode
) <= GET_MODE_PRECISION (tmode
))
5618 if ((GET_MODE_CLASS (tmode
) == MODE_FLOAT
5619 && GET_MODE_CLASS (fmode
) == MODE_FLOAT
)
5620 || (DECIMAL_FLOAT_MODE_P (fmode
) && DECIMAL_FLOAT_MODE_P (tmode
)))
5621 gen_intraclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5624 /* Pick proper libcall for extend_optab. We need to chose if we do
5625 truncation or extension and interclass or intraclass. */
5628 gen_extend_conv_libfunc (convert_optab tab
,
5629 const char *opname ATTRIBUTE_UNUSED
,
5630 enum machine_mode tmode
,
5631 enum machine_mode fmode
)
5633 if (GET_MODE_CLASS (tmode
) != MODE_FLOAT
&& !DECIMAL_FLOAT_MODE_P (tmode
))
5635 if (GET_MODE_CLASS (fmode
) != MODE_FLOAT
&& !DECIMAL_FLOAT_MODE_P (fmode
))
5640 if ((GET_MODE_CLASS (tmode
) == MODE_FLOAT
&& DECIMAL_FLOAT_MODE_P (fmode
))
5641 || (GET_MODE_CLASS (fmode
) == MODE_FLOAT
&& DECIMAL_FLOAT_MODE_P (tmode
)))
5642 gen_interclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5644 if (GET_MODE_PRECISION (fmode
) > GET_MODE_PRECISION (tmode
))
5647 if ((GET_MODE_CLASS (tmode
) == MODE_FLOAT
5648 && GET_MODE_CLASS (fmode
) == MODE_FLOAT
)
5649 || (DECIMAL_FLOAT_MODE_P (fmode
) && DECIMAL_FLOAT_MODE_P (tmode
)))
5650 gen_intraclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5653 /* Pick proper libcall for fract_optab. We need to chose if we do
5654 interclass or intraclass. */
5657 gen_fract_conv_libfunc (convert_optab tab
,
5659 enum machine_mode tmode
,
5660 enum machine_mode fmode
)
5664 if (!(ALL_FIXED_POINT_MODE_P (tmode
) || ALL_FIXED_POINT_MODE_P (fmode
)))
5667 if (GET_MODE_CLASS (tmode
) == GET_MODE_CLASS (fmode
))
5668 gen_intraclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5670 gen_interclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5673 /* Pick proper libcall for fractuns_optab. */
5676 gen_fractuns_conv_libfunc (convert_optab tab
,
5678 enum machine_mode tmode
,
5679 enum machine_mode fmode
)
5683 /* One mode must be a fixed-point mode, and the other must be an integer
5685 if (!((ALL_FIXED_POINT_MODE_P (tmode
) && GET_MODE_CLASS (fmode
) == MODE_INT
)
5686 || (ALL_FIXED_POINT_MODE_P (fmode
)
5687 && GET_MODE_CLASS (tmode
) == MODE_INT
)))
5690 gen_interclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5693 /* Pick proper libcall for satfract_optab. We need to chose if we do
5694 interclass or intraclass. */
5697 gen_satfract_conv_libfunc (convert_optab tab
,
5699 enum machine_mode tmode
,
5700 enum machine_mode fmode
)
5704 /* TMODE must be a fixed-point mode. */
5705 if (!ALL_FIXED_POINT_MODE_P (tmode
))
5708 if (GET_MODE_CLASS (tmode
) == GET_MODE_CLASS (fmode
))
5709 gen_intraclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5711 gen_interclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5714 /* Pick proper libcall for satfractuns_optab. */
5717 gen_satfractuns_conv_libfunc (convert_optab tab
,
5719 enum machine_mode tmode
,
5720 enum machine_mode fmode
)
5724 /* TMODE must be a fixed-point mode, and FMODE must be an integer mode. */
5725 if (!(ALL_FIXED_POINT_MODE_P (tmode
) && GET_MODE_CLASS (fmode
) == MODE_INT
))
5728 gen_interclass_conv_libfunc (tab
, opname
, tmode
, fmode
);
5731 /* A table of previously-created libfuncs, hashed by name. */
5732 static GTY ((param_is (union tree_node
))) htab_t libfunc_decls
;
5734 /* Hashtable callbacks for libfunc_decls. */
5737 libfunc_decl_hash (const void *entry
)
5739 return IDENTIFIER_HASH_VALUE (DECL_NAME ((const_tree
) entry
));
5743 libfunc_decl_eq (const void *entry1
, const void *entry2
)
5745 return DECL_NAME ((const_tree
) entry1
) == (const_tree
) entry2
;
5748 /* Build a decl for a libfunc named NAME. */
5751 build_libfunc_function (const char *name
)
5753 tree decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
5754 get_identifier (name
),
5755 build_function_type (integer_type_node
, NULL_TREE
));
5756 /* ??? We don't have any type information except for this is
5757 a function. Pretend this is "int foo()". */
5758 DECL_ARTIFICIAL (decl
) = 1;
5759 DECL_EXTERNAL (decl
) = 1;
5760 TREE_PUBLIC (decl
) = 1;
5761 gcc_assert (DECL_ASSEMBLER_NAME (decl
));
5763 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
5764 are the flags assigned by targetm.encode_section_info. */
5765 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
5771 init_one_libfunc (const char *name
)
5777 if (libfunc_decls
== NULL
)
5778 libfunc_decls
= htab_create_ggc (37, libfunc_decl_hash
,
5779 libfunc_decl_eq
, NULL
);
5781 /* See if we have already created a libfunc decl for this function. */
5782 id
= get_identifier (name
);
5783 hash
= IDENTIFIER_HASH_VALUE (id
);
5784 slot
= htab_find_slot_with_hash (libfunc_decls
, id
, hash
, INSERT
);
5785 decl
= (tree
) *slot
;
5788 /* Create a new decl, so that it can be passed to
5789 targetm.encode_section_info. */
5790 decl
= build_libfunc_function (name
);
5793 return XEXP (DECL_RTL (decl
), 0);
5796 /* Adjust the assembler name of libfunc NAME to ASMSPEC. */
5799 set_user_assembler_libfunc (const char *name
, const char *asmspec
)
5805 id
= get_identifier (name
);
5806 hash
= IDENTIFIER_HASH_VALUE (id
);
5807 slot
= htab_find_slot_with_hash (libfunc_decls
, id
, hash
, NO_INSERT
);
5809 decl
= (tree
) *slot
;
5810 set_user_assembler_name (decl
, asmspec
);
5811 return XEXP (DECL_RTL (decl
), 0);
5814 /* Call this to reset the function entry for one optab (OPTABLE) in mode
5815 MODE to NAME, which should be either 0 or a string constant. */
5817 set_optab_libfunc (optab optable
, enum machine_mode mode
, const char *name
)
5820 struct libfunc_entry e
;
5821 struct libfunc_entry
**slot
;
5822 e
.optab
= (size_t) (optable
- &optab_table
[0]);
5827 val
= init_one_libfunc (name
);
5830 slot
= (struct libfunc_entry
**) htab_find_slot (libfunc_hash
, &e
, INSERT
);
5832 *slot
= ggc_alloc_libfunc_entry ();
5833 (*slot
)->optab
= (size_t) (optable
- &optab_table
[0]);
5834 (*slot
)->mode1
= mode
;
5835 (*slot
)->mode2
= VOIDmode
;
5836 (*slot
)->libfunc
= val
;
5839 /* Call this to reset the function entry for one conversion optab
5840 (OPTABLE) from mode FMODE to mode TMODE to NAME, which should be
5841 either 0 or a string constant. */
5843 set_conv_libfunc (convert_optab optable
, enum machine_mode tmode
,
5844 enum machine_mode fmode
, const char *name
)
5847 struct libfunc_entry e
;
5848 struct libfunc_entry
**slot
;
5849 e
.optab
= (size_t) (optable
- &convert_optab_table
[0]);
5854 val
= init_one_libfunc (name
);
5857 slot
= (struct libfunc_entry
**) htab_find_slot (libfunc_hash
, &e
, INSERT
);
5859 *slot
= ggc_alloc_libfunc_entry ();
5860 (*slot
)->optab
= (size_t) (optable
- &convert_optab_table
[0]);
5861 (*slot
)->mode1
= tmode
;
5862 (*slot
)->mode2
= fmode
;
5863 (*slot
)->libfunc
= val
;
5866 /* Call this to initialize the contents of the optabs
5867 appropriately for the current target machine. */
5874 htab_empty (libfunc_hash
);
5875 /* We statically initialize the insn_codes with the equivalent of
5876 CODE_FOR_nothing. Repeat the process if reinitialising. */
5880 libfunc_hash
= htab_create_ggc (10, hash_libfunc
, eq_libfunc
, NULL
);
5882 init_optab (add_optab
, PLUS
);
5883 init_optabv (addv_optab
, PLUS
);
5884 init_optab (sub_optab
, MINUS
);
5885 init_optabv (subv_optab
, MINUS
);
5886 init_optab (ssadd_optab
, SS_PLUS
);
5887 init_optab (usadd_optab
, US_PLUS
);
5888 init_optab (sssub_optab
, SS_MINUS
);
5889 init_optab (ussub_optab
, US_MINUS
);
5890 init_optab (smul_optab
, MULT
);
5891 init_optab (ssmul_optab
, SS_MULT
);
5892 init_optab (usmul_optab
, US_MULT
);
5893 init_optabv (smulv_optab
, MULT
);
5894 init_optab (smul_highpart_optab
, UNKNOWN
);
5895 init_optab (umul_highpart_optab
, UNKNOWN
);
5896 init_optab (smul_widen_optab
, UNKNOWN
);
5897 init_optab (umul_widen_optab
, UNKNOWN
);
5898 init_optab (usmul_widen_optab
, UNKNOWN
);
5899 init_optab (smadd_widen_optab
, UNKNOWN
);
5900 init_optab (umadd_widen_optab
, UNKNOWN
);
5901 init_optab (ssmadd_widen_optab
, UNKNOWN
);
5902 init_optab (usmadd_widen_optab
, UNKNOWN
);
5903 init_optab (smsub_widen_optab
, UNKNOWN
);
5904 init_optab (umsub_widen_optab
, UNKNOWN
);
5905 init_optab (ssmsub_widen_optab
, UNKNOWN
);
5906 init_optab (usmsub_widen_optab
, UNKNOWN
);
5907 init_optab (sdiv_optab
, DIV
);
5908 init_optab (ssdiv_optab
, SS_DIV
);
5909 init_optab (usdiv_optab
, US_DIV
);
5910 init_optabv (sdivv_optab
, DIV
);
5911 init_optab (sdivmod_optab
, UNKNOWN
);
5912 init_optab (udiv_optab
, UDIV
);
5913 init_optab (udivmod_optab
, UNKNOWN
);
5914 init_optab (smod_optab
, MOD
);
5915 init_optab (umod_optab
, UMOD
);
5916 init_optab (fmod_optab
, UNKNOWN
);
5917 init_optab (remainder_optab
, UNKNOWN
);
5918 init_optab (ftrunc_optab
, UNKNOWN
);
5919 init_optab (and_optab
, AND
);
5920 init_optab (ior_optab
, IOR
);
5921 init_optab (xor_optab
, XOR
);
5922 init_optab (ashl_optab
, ASHIFT
);
5923 init_optab (ssashl_optab
, SS_ASHIFT
);
5924 init_optab (usashl_optab
, US_ASHIFT
);
5925 init_optab (ashr_optab
, ASHIFTRT
);
5926 init_optab (lshr_optab
, LSHIFTRT
);
5927 init_optabv (vashl_optab
, ASHIFT
);
5928 init_optabv (vashr_optab
, ASHIFTRT
);
5929 init_optabv (vlshr_optab
, LSHIFTRT
);
5930 init_optab (rotl_optab
, ROTATE
);
5931 init_optab (rotr_optab
, ROTATERT
);
5932 init_optab (smin_optab
, SMIN
);
5933 init_optab (smax_optab
, SMAX
);
5934 init_optab (umin_optab
, UMIN
);
5935 init_optab (umax_optab
, UMAX
);
5936 init_optab (pow_optab
, UNKNOWN
);
5937 init_optab (atan2_optab
, UNKNOWN
);
5938 init_optab (fma_optab
, FMA
);
5939 init_optab (fms_optab
, UNKNOWN
);
5940 init_optab (fnma_optab
, UNKNOWN
);
5941 init_optab (fnms_optab
, UNKNOWN
);
5943 /* These three have codes assigned exclusively for the sake of
5945 init_optab (mov_optab
, SET
);
5946 init_optab (movstrict_optab
, STRICT_LOW_PART
);
5947 init_optab (cbranch_optab
, COMPARE
);
5949 init_optab (cmov_optab
, UNKNOWN
);
5950 init_optab (cstore_optab
, UNKNOWN
);
5951 init_optab (ctrap_optab
, UNKNOWN
);
5953 init_optab (storent_optab
, UNKNOWN
);
5955 init_optab (cmp_optab
, UNKNOWN
);
5956 init_optab (ucmp_optab
, UNKNOWN
);
5958 init_optab (eq_optab
, EQ
);
5959 init_optab (ne_optab
, NE
);
5960 init_optab (gt_optab
, GT
);
5961 init_optab (ge_optab
, GE
);
5962 init_optab (lt_optab
, LT
);
5963 init_optab (le_optab
, LE
);
5964 init_optab (unord_optab
, UNORDERED
);
5966 init_optab (neg_optab
, NEG
);
5967 init_optab (ssneg_optab
, SS_NEG
);
5968 init_optab (usneg_optab
, US_NEG
);
5969 init_optabv (negv_optab
, NEG
);
5970 init_optab (abs_optab
, ABS
);
5971 init_optabv (absv_optab
, ABS
);
5972 init_optab (addcc_optab
, UNKNOWN
);
5973 init_optab (one_cmpl_optab
, NOT
);
5974 init_optab (bswap_optab
, BSWAP
);
5975 init_optab (ffs_optab
, FFS
);
5976 init_optab (clz_optab
, CLZ
);
5977 init_optab (ctz_optab
, CTZ
);
5978 init_optab (clrsb_optab
, CLRSB
);
5979 init_optab (popcount_optab
, POPCOUNT
);
5980 init_optab (parity_optab
, PARITY
);
5981 init_optab (sqrt_optab
, SQRT
);
5982 init_optab (floor_optab
, UNKNOWN
);
5983 init_optab (ceil_optab
, UNKNOWN
);
5984 init_optab (round_optab
, UNKNOWN
);
5985 init_optab (btrunc_optab
, UNKNOWN
);
5986 init_optab (nearbyint_optab
, UNKNOWN
);
5987 init_optab (rint_optab
, UNKNOWN
);
5988 init_optab (sincos_optab
, UNKNOWN
);
5989 init_optab (sin_optab
, UNKNOWN
);
5990 init_optab (asin_optab
, UNKNOWN
);
5991 init_optab (cos_optab
, UNKNOWN
);
5992 init_optab (acos_optab
, UNKNOWN
);
5993 init_optab (exp_optab
, UNKNOWN
);
5994 init_optab (exp10_optab
, UNKNOWN
);
5995 init_optab (exp2_optab
, UNKNOWN
);
5996 init_optab (expm1_optab
, UNKNOWN
);
5997 init_optab (ldexp_optab
, UNKNOWN
);
5998 init_optab (scalb_optab
, UNKNOWN
);
5999 init_optab (significand_optab
, UNKNOWN
);
6000 init_optab (logb_optab
, UNKNOWN
);
6001 init_optab (ilogb_optab
, UNKNOWN
);
6002 init_optab (log_optab
, UNKNOWN
);
6003 init_optab (log10_optab
, UNKNOWN
);
6004 init_optab (log2_optab
, UNKNOWN
);
6005 init_optab (log1p_optab
, UNKNOWN
);
6006 init_optab (tan_optab
, UNKNOWN
);
6007 init_optab (atan_optab
, UNKNOWN
);
6008 init_optab (copysign_optab
, UNKNOWN
);
6009 init_optab (signbit_optab
, UNKNOWN
);
6011 init_optab (isinf_optab
, UNKNOWN
);
6013 init_optab (strlen_optab
, UNKNOWN
);
6014 init_optab (push_optab
, UNKNOWN
);
6016 init_optab (reduc_smax_optab
, UNKNOWN
);
6017 init_optab (reduc_umax_optab
, UNKNOWN
);
6018 init_optab (reduc_smin_optab
, UNKNOWN
);
6019 init_optab (reduc_umin_optab
, UNKNOWN
);
6020 init_optab (reduc_splus_optab
, UNKNOWN
);
6021 init_optab (reduc_uplus_optab
, UNKNOWN
);
6023 init_optab (ssum_widen_optab
, UNKNOWN
);
6024 init_optab (usum_widen_optab
, UNKNOWN
);
6025 init_optab (sdot_prod_optab
, UNKNOWN
);
6026 init_optab (udot_prod_optab
, UNKNOWN
);
6028 init_optab (vec_extract_optab
, UNKNOWN
);
6029 init_optab (vec_extract_even_optab
, UNKNOWN
);
6030 init_optab (vec_extract_odd_optab
, UNKNOWN
);
6031 init_optab (vec_interleave_high_optab
, UNKNOWN
);
6032 init_optab (vec_interleave_low_optab
, UNKNOWN
);
6033 init_optab (vec_set_optab
, UNKNOWN
);
6034 init_optab (vec_init_optab
, UNKNOWN
);
6035 init_optab (vec_shl_optab
, UNKNOWN
);
6036 init_optab (vec_shr_optab
, UNKNOWN
);
6037 init_optab (vec_realign_load_optab
, UNKNOWN
);
6038 init_optab (movmisalign_optab
, UNKNOWN
);
6039 init_optab (vec_widen_umult_hi_optab
, UNKNOWN
);
6040 init_optab (vec_widen_umult_lo_optab
, UNKNOWN
);
6041 init_optab (vec_widen_smult_hi_optab
, UNKNOWN
);
6042 init_optab (vec_widen_smult_lo_optab
, UNKNOWN
);
6043 init_optab (vec_unpacks_hi_optab
, UNKNOWN
);
6044 init_optab (vec_unpacks_lo_optab
, UNKNOWN
);
6045 init_optab (vec_unpacku_hi_optab
, UNKNOWN
);
6046 init_optab (vec_unpacku_lo_optab
, UNKNOWN
);
6047 init_optab (vec_unpacks_float_hi_optab
, UNKNOWN
);
6048 init_optab (vec_unpacks_float_lo_optab
, UNKNOWN
);
6049 init_optab (vec_unpacku_float_hi_optab
, UNKNOWN
);
6050 init_optab (vec_unpacku_float_lo_optab
, UNKNOWN
);
6051 init_optab (vec_pack_trunc_optab
, UNKNOWN
);
6052 init_optab (vec_pack_usat_optab
, UNKNOWN
);
6053 init_optab (vec_pack_ssat_optab
, UNKNOWN
);
6054 init_optab (vec_pack_ufix_trunc_optab
, UNKNOWN
);
6055 init_optab (vec_pack_sfix_trunc_optab
, UNKNOWN
);
6057 init_optab (powi_optab
, UNKNOWN
);
6060 init_convert_optab (sext_optab
, SIGN_EXTEND
);
6061 init_convert_optab (zext_optab
, ZERO_EXTEND
);
6062 init_convert_optab (trunc_optab
, TRUNCATE
);
6063 init_convert_optab (sfix_optab
, FIX
);
6064 init_convert_optab (ufix_optab
, UNSIGNED_FIX
);
6065 init_convert_optab (sfixtrunc_optab
, UNKNOWN
);
6066 init_convert_optab (ufixtrunc_optab
, UNKNOWN
);
6067 init_convert_optab (sfloat_optab
, FLOAT
);
6068 init_convert_optab (ufloat_optab
, UNSIGNED_FLOAT
);
6069 init_convert_optab (lrint_optab
, UNKNOWN
);
6070 init_convert_optab (lround_optab
, UNKNOWN
);
6071 init_convert_optab (lfloor_optab
, UNKNOWN
);
6072 init_convert_optab (lceil_optab
, UNKNOWN
);
6074 init_convert_optab (fract_optab
, FRACT_CONVERT
);
6075 init_convert_optab (fractuns_optab
, UNSIGNED_FRACT_CONVERT
);
6076 init_convert_optab (satfract_optab
, SAT_FRACT
);
6077 init_convert_optab (satfractuns_optab
, UNSIGNED_SAT_FRACT
);
6079 /* Fill in the optabs with the insns we support. */
6082 /* Initialize the optabs with the names of the library functions. */
6083 add_optab
->libcall_basename
= "add";
6084 add_optab
->libcall_suffix
= '3';
6085 add_optab
->libcall_gen
= gen_int_fp_fixed_libfunc
;
6086 addv_optab
->libcall_basename
= "add";
6087 addv_optab
->libcall_suffix
= '3';
6088 addv_optab
->libcall_gen
= gen_intv_fp_libfunc
;
6089 ssadd_optab
->libcall_basename
= "ssadd";
6090 ssadd_optab
->libcall_suffix
= '3';
6091 ssadd_optab
->libcall_gen
= gen_signed_fixed_libfunc
;
6092 usadd_optab
->libcall_basename
= "usadd";
6093 usadd_optab
->libcall_suffix
= '3';
6094 usadd_optab
->libcall_gen
= gen_unsigned_fixed_libfunc
;
6095 sub_optab
->libcall_basename
= "sub";
6096 sub_optab
->libcall_suffix
= '3';
6097 sub_optab
->libcall_gen
= gen_int_fp_fixed_libfunc
;
6098 subv_optab
->libcall_basename
= "sub";
6099 subv_optab
->libcall_suffix
= '3';
6100 subv_optab
->libcall_gen
= gen_intv_fp_libfunc
;
6101 sssub_optab
->libcall_basename
= "sssub";
6102 sssub_optab
->libcall_suffix
= '3';
6103 sssub_optab
->libcall_gen
= gen_signed_fixed_libfunc
;
6104 ussub_optab
->libcall_basename
= "ussub";
6105 ussub_optab
->libcall_suffix
= '3';
6106 ussub_optab
->libcall_gen
= gen_unsigned_fixed_libfunc
;
6107 smul_optab
->libcall_basename
= "mul";
6108 smul_optab
->libcall_suffix
= '3';
6109 smul_optab
->libcall_gen
= gen_int_fp_fixed_libfunc
;
6110 smulv_optab
->libcall_basename
= "mul";
6111 smulv_optab
->libcall_suffix
= '3';
6112 smulv_optab
->libcall_gen
= gen_intv_fp_libfunc
;
6113 ssmul_optab
->libcall_basename
= "ssmul";
6114 ssmul_optab
->libcall_suffix
= '3';
6115 ssmul_optab
->libcall_gen
= gen_signed_fixed_libfunc
;
6116 usmul_optab
->libcall_basename
= "usmul";
6117 usmul_optab
->libcall_suffix
= '3';
6118 usmul_optab
->libcall_gen
= gen_unsigned_fixed_libfunc
;
6119 sdiv_optab
->libcall_basename
= "div";
6120 sdiv_optab
->libcall_suffix
= '3';
6121 sdiv_optab
->libcall_gen
= gen_int_fp_signed_fixed_libfunc
;
6122 sdivv_optab
->libcall_basename
= "divv";
6123 sdivv_optab
->libcall_suffix
= '3';
6124 sdivv_optab
->libcall_gen
= gen_int_libfunc
;
6125 ssdiv_optab
->libcall_basename
= "ssdiv";
6126 ssdiv_optab
->libcall_suffix
= '3';
6127 ssdiv_optab
->libcall_gen
= gen_signed_fixed_libfunc
;
6128 udiv_optab
->libcall_basename
= "udiv";
6129 udiv_optab
->libcall_suffix
= '3';
6130 udiv_optab
->libcall_gen
= gen_int_unsigned_fixed_libfunc
;
6131 usdiv_optab
->libcall_basename
= "usdiv";
6132 usdiv_optab
->libcall_suffix
= '3';
6133 usdiv_optab
->libcall_gen
= gen_unsigned_fixed_libfunc
;
6134 sdivmod_optab
->libcall_basename
= "divmod";
6135 sdivmod_optab
->libcall_suffix
= '4';
6136 sdivmod_optab
->libcall_gen
= gen_int_libfunc
;
6137 udivmod_optab
->libcall_basename
= "udivmod";
6138 udivmod_optab
->libcall_suffix
= '4';
6139 udivmod_optab
->libcall_gen
= gen_int_libfunc
;
6140 smod_optab
->libcall_basename
= "mod";
6141 smod_optab
->libcall_suffix
= '3';
6142 smod_optab
->libcall_gen
= gen_int_libfunc
;
6143 umod_optab
->libcall_basename
= "umod";
6144 umod_optab
->libcall_suffix
= '3';
6145 umod_optab
->libcall_gen
= gen_int_libfunc
;
6146 ftrunc_optab
->libcall_basename
= "ftrunc";
6147 ftrunc_optab
->libcall_suffix
= '2';
6148 ftrunc_optab
->libcall_gen
= gen_fp_libfunc
;
6149 and_optab
->libcall_basename
= "and";
6150 and_optab
->libcall_suffix
= '3';
6151 and_optab
->libcall_gen
= gen_int_libfunc
;
6152 ior_optab
->libcall_basename
= "ior";
6153 ior_optab
->libcall_suffix
= '3';
6154 ior_optab
->libcall_gen
= gen_int_libfunc
;
6155 xor_optab
->libcall_basename
= "xor";
6156 xor_optab
->libcall_suffix
= '3';
6157 xor_optab
->libcall_gen
= gen_int_libfunc
;
6158 ashl_optab
->libcall_basename
= "ashl";
6159 ashl_optab
->libcall_suffix
= '3';
6160 ashl_optab
->libcall_gen
= gen_int_fixed_libfunc
;
6161 ssashl_optab
->libcall_basename
= "ssashl";
6162 ssashl_optab
->libcall_suffix
= '3';
6163 ssashl_optab
->libcall_gen
= gen_signed_fixed_libfunc
;
6164 usashl_optab
->libcall_basename
= "usashl";
6165 usashl_optab
->libcall_suffix
= '3';
6166 usashl_optab
->libcall_gen
= gen_unsigned_fixed_libfunc
;
6167 ashr_optab
->libcall_basename
= "ashr";
6168 ashr_optab
->libcall_suffix
= '3';
6169 ashr_optab
->libcall_gen
= gen_int_signed_fixed_libfunc
;
6170 lshr_optab
->libcall_basename
= "lshr";
6171 lshr_optab
->libcall_suffix
= '3';
6172 lshr_optab
->libcall_gen
= gen_int_unsigned_fixed_libfunc
;
6173 smin_optab
->libcall_basename
= "min";
6174 smin_optab
->libcall_suffix
= '3';
6175 smin_optab
->libcall_gen
= gen_int_fp_libfunc
;
6176 smax_optab
->libcall_basename
= "max";
6177 smax_optab
->libcall_suffix
= '3';
6178 smax_optab
->libcall_gen
= gen_int_fp_libfunc
;
6179 umin_optab
->libcall_basename
= "umin";
6180 umin_optab
->libcall_suffix
= '3';
6181 umin_optab
->libcall_gen
= gen_int_libfunc
;
6182 umax_optab
->libcall_basename
= "umax";
6183 umax_optab
->libcall_suffix
= '3';
6184 umax_optab
->libcall_gen
= gen_int_libfunc
;
6185 neg_optab
->libcall_basename
= "neg";
6186 neg_optab
->libcall_suffix
= '2';
6187 neg_optab
->libcall_gen
= gen_int_fp_fixed_libfunc
;
6188 ssneg_optab
->libcall_basename
= "ssneg";
6189 ssneg_optab
->libcall_suffix
= '2';
6190 ssneg_optab
->libcall_gen
= gen_signed_fixed_libfunc
;
6191 usneg_optab
->libcall_basename
= "usneg";
6192 usneg_optab
->libcall_suffix
= '2';
6193 usneg_optab
->libcall_gen
= gen_unsigned_fixed_libfunc
;
6194 negv_optab
->libcall_basename
= "neg";
6195 negv_optab
->libcall_suffix
= '2';
6196 negv_optab
->libcall_gen
= gen_intv_fp_libfunc
;
6197 one_cmpl_optab
->libcall_basename
= "one_cmpl";
6198 one_cmpl_optab
->libcall_suffix
= '2';
6199 one_cmpl_optab
->libcall_gen
= gen_int_libfunc
;
6200 ffs_optab
->libcall_basename
= "ffs";
6201 ffs_optab
->libcall_suffix
= '2';
6202 ffs_optab
->libcall_gen
= gen_int_libfunc
;
6203 clz_optab
->libcall_basename
= "clz";
6204 clz_optab
->libcall_suffix
= '2';
6205 clz_optab
->libcall_gen
= gen_int_libfunc
;
6206 ctz_optab
->libcall_basename
= "ctz";
6207 ctz_optab
->libcall_suffix
= '2';
6208 ctz_optab
->libcall_gen
= gen_int_libfunc
;
6209 clrsb_optab
->libcall_basename
= "clrsb";
6210 clrsb_optab
->libcall_suffix
= '2';
6211 clrsb_optab
->libcall_gen
= gen_int_libfunc
;
6212 popcount_optab
->libcall_basename
= "popcount";
6213 popcount_optab
->libcall_suffix
= '2';
6214 popcount_optab
->libcall_gen
= gen_int_libfunc
;
6215 parity_optab
->libcall_basename
= "parity";
6216 parity_optab
->libcall_suffix
= '2';
6217 parity_optab
->libcall_gen
= gen_int_libfunc
;
6219 /* Comparison libcalls for integers MUST come in pairs,
6221 cmp_optab
->libcall_basename
= "cmp";
6222 cmp_optab
->libcall_suffix
= '2';
6223 cmp_optab
->libcall_gen
= gen_int_fp_fixed_libfunc
;
6224 ucmp_optab
->libcall_basename
= "ucmp";
6225 ucmp_optab
->libcall_suffix
= '2';
6226 ucmp_optab
->libcall_gen
= gen_int_libfunc
;
6228 /* EQ etc are floating point only. */
6229 eq_optab
->libcall_basename
= "eq";
6230 eq_optab
->libcall_suffix
= '2';
6231 eq_optab
->libcall_gen
= gen_fp_libfunc
;
6232 ne_optab
->libcall_basename
= "ne";
6233 ne_optab
->libcall_suffix
= '2';
6234 ne_optab
->libcall_gen
= gen_fp_libfunc
;
6235 gt_optab
->libcall_basename
= "gt";
6236 gt_optab
->libcall_suffix
= '2';
6237 gt_optab
->libcall_gen
= gen_fp_libfunc
;
6238 ge_optab
->libcall_basename
= "ge";
6239 ge_optab
->libcall_suffix
= '2';
6240 ge_optab
->libcall_gen
= gen_fp_libfunc
;
6241 lt_optab
->libcall_basename
= "lt";
6242 lt_optab
->libcall_suffix
= '2';
6243 lt_optab
->libcall_gen
= gen_fp_libfunc
;
6244 le_optab
->libcall_basename
= "le";
6245 le_optab
->libcall_suffix
= '2';
6246 le_optab
->libcall_gen
= gen_fp_libfunc
;
6247 unord_optab
->libcall_basename
= "unord";
6248 unord_optab
->libcall_suffix
= '2';
6249 unord_optab
->libcall_gen
= gen_fp_libfunc
;
6251 powi_optab
->libcall_basename
= "powi";
6252 powi_optab
->libcall_suffix
= '2';
6253 powi_optab
->libcall_gen
= gen_fp_libfunc
;
6256 sfloat_optab
->libcall_basename
= "float";
6257 sfloat_optab
->libcall_gen
= gen_int_to_fp_conv_libfunc
;
6258 ufloat_optab
->libcall_gen
= gen_ufloat_conv_libfunc
;
6259 sfix_optab
->libcall_basename
= "fix";
6260 sfix_optab
->libcall_gen
= gen_fp_to_int_conv_libfunc
;
6261 ufix_optab
->libcall_basename
= "fixuns";
6262 ufix_optab
->libcall_gen
= gen_fp_to_int_conv_libfunc
;
6263 lrint_optab
->libcall_basename
= "lrint";
6264 lrint_optab
->libcall_gen
= gen_int_to_fp_nondecimal_conv_libfunc
;
6265 lround_optab
->libcall_basename
= "lround";
6266 lround_optab
->libcall_gen
= gen_int_to_fp_nondecimal_conv_libfunc
;
6267 lfloor_optab
->libcall_basename
= "lfloor";
6268 lfloor_optab
->libcall_gen
= gen_int_to_fp_nondecimal_conv_libfunc
;
6269 lceil_optab
->libcall_basename
= "lceil";
6270 lceil_optab
->libcall_gen
= gen_int_to_fp_nondecimal_conv_libfunc
;
6272 /* trunc_optab is also used for FLOAT_EXTEND. */
6273 sext_optab
->libcall_basename
= "extend";
6274 sext_optab
->libcall_gen
= gen_extend_conv_libfunc
;
6275 trunc_optab
->libcall_basename
= "trunc";
6276 trunc_optab
->libcall_gen
= gen_trunc_conv_libfunc
;
6278 /* Conversions for fixed-point modes and other modes. */
6279 fract_optab
->libcall_basename
= "fract";
6280 fract_optab
->libcall_gen
= gen_fract_conv_libfunc
;
6281 satfract_optab
->libcall_basename
= "satfract";
6282 satfract_optab
->libcall_gen
= gen_satfract_conv_libfunc
;
6283 fractuns_optab
->libcall_basename
= "fractuns";
6284 fractuns_optab
->libcall_gen
= gen_fractuns_conv_libfunc
;
6285 satfractuns_optab
->libcall_basename
= "satfractuns";
6286 satfractuns_optab
->libcall_gen
= gen_satfractuns_conv_libfunc
;
6288 /* The ffs function operates on `int'. Fall back on it if we do not
6289 have a libgcc2 function for that width. */
6290 if (INT_TYPE_SIZE
< BITS_PER_WORD
)
6291 set_optab_libfunc (ffs_optab
, mode_for_size (INT_TYPE_SIZE
, MODE_INT
, 0),
6294 /* Explicitly initialize the bswap libfuncs since we need them to be
6295 valid for things other than word_mode. */
6296 if (targetm
.libfunc_gnu_prefix
)
6298 set_optab_libfunc (bswap_optab
, SImode
, "__gnu_bswapsi2");
6299 set_optab_libfunc (bswap_optab
, DImode
, "__gnu_bswapdi2");
6303 set_optab_libfunc (bswap_optab
, SImode
, "__bswapsi2");
6304 set_optab_libfunc (bswap_optab
, DImode
, "__bswapdi2");
6307 /* Use cabs for double complex abs, since systems generally have cabs.
6308 Don't define any libcall for float complex, so that cabs will be used. */
6309 if (complex_double_type_node
)
6310 set_optab_libfunc (abs_optab
, TYPE_MODE (complex_double_type_node
), "cabs");
6312 abort_libfunc
= init_one_libfunc ("abort");
6313 memcpy_libfunc
= init_one_libfunc ("memcpy");
6314 memmove_libfunc
= init_one_libfunc ("memmove");
6315 memcmp_libfunc
= init_one_libfunc ("memcmp");
6316 memset_libfunc
= init_one_libfunc ("memset");
6317 setbits_libfunc
= init_one_libfunc ("__setbits");
6319 #ifndef DONT_USE_BUILTIN_SETJMP
6320 setjmp_libfunc
= init_one_libfunc ("__builtin_setjmp");
6321 longjmp_libfunc
= init_one_libfunc ("__builtin_longjmp");
6323 setjmp_libfunc
= init_one_libfunc ("setjmp");
6324 longjmp_libfunc
= init_one_libfunc ("longjmp");
6326 unwind_sjlj_register_libfunc
= init_one_libfunc ("_Unwind_SjLj_Register");
6327 unwind_sjlj_unregister_libfunc
6328 = init_one_libfunc ("_Unwind_SjLj_Unregister");
6330 /* For function entry/exit instrumentation. */
6331 profile_function_entry_libfunc
6332 = init_one_libfunc ("__cyg_profile_func_enter");
6333 profile_function_exit_libfunc
6334 = init_one_libfunc ("__cyg_profile_func_exit");
6336 gcov_flush_libfunc
= init_one_libfunc ("__gcov_flush");
6338 /* Allow the target to add more libcalls or rename some, etc. */
6339 targetm
.init_libfuncs ();
6342 /* Print information about the current contents of the optabs on
6346 debug_optab_libfuncs (void)
6352 /* Dump the arithmetic optabs. */
6353 for (i
= 0; i
!= (int) OTI_MAX
; i
++)
6354 for (j
= 0; j
< NUM_MACHINE_MODES
; ++j
)
6359 o
= &optab_table
[i
];
6360 l
= optab_libfunc (o
, (enum machine_mode
) j
);
6363 gcc_assert (GET_CODE (l
) == SYMBOL_REF
);
6364 fprintf (stderr
, "%s\t%s:\t%s\n",
6365 GET_RTX_NAME (o
->code
),
6371 /* Dump the conversion optabs. */
6372 for (i
= 0; i
< (int) COI_MAX
; ++i
)
6373 for (j
= 0; j
< NUM_MACHINE_MODES
; ++j
)
6374 for (k
= 0; k
< NUM_MACHINE_MODES
; ++k
)
6379 o
= &convert_optab_table
[i
];
6380 l
= convert_optab_libfunc (o
, (enum machine_mode
) j
,
6381 (enum machine_mode
) k
);
6384 gcc_assert (GET_CODE (l
) == SYMBOL_REF
);
6385 fprintf (stderr
, "%s\t%s\t%s:\t%s\n",
6386 GET_RTX_NAME (o
->code
),
6395 /* Generate insns to trap with code TCODE if OP1 and OP2 satisfy condition
6396 CODE. Return 0 on failure. */
6399 gen_cond_trap (enum rtx_code code
, rtx op1
, rtx op2
, rtx tcode
)
6401 enum machine_mode mode
= GET_MODE (op1
);
6402 enum insn_code icode
;
6406 if (mode
== VOIDmode
)
6409 icode
= optab_handler (ctrap_optab
, mode
);
6410 if (icode
== CODE_FOR_nothing
)
6413 /* Some targets only accept a zero trap code. */
6414 if (!insn_operand_matches (icode
, 3, tcode
))
6417 do_pending_stack_adjust ();
6419 prepare_cmp_insn (op1
, op2
, code
, NULL_RTX
, false, OPTAB_DIRECT
,
6424 insn
= GEN_FCN (icode
) (trap_rtx
, XEXP (trap_rtx
, 0), XEXP (trap_rtx
, 1),
6427 /* If that failed, then give up. */
6435 insn
= get_insns ();
6440 /* Return rtx code for TCODE. Use UNSIGNEDP to select signed
6441 or unsigned operation code. */
6443 static enum rtx_code
6444 get_rtx_code (enum tree_code tcode
, bool unsignedp
)
6456 code
= unsignedp
? LTU
: LT
;
6459 code
= unsignedp
? LEU
: LE
;
6462 code
= unsignedp
? GTU
: GT
;
6465 code
= unsignedp
? GEU
: GE
;
6468 case UNORDERED_EXPR
:
6499 /* Return comparison rtx for COND. Use UNSIGNEDP to select signed or
6500 unsigned operators. Do not generate compare instruction. */
6503 vector_compare_rtx (tree cond
, bool unsignedp
, enum insn_code icode
)
6505 struct expand_operand ops
[2];
6506 enum rtx_code rcode
;
6508 rtx rtx_op0
, rtx_op1
;
6510 /* This is unlikely. While generating VEC_COND_EXPR, auto vectorizer
6511 ensures that condition is a relational operation. */
6512 gcc_assert (COMPARISON_CLASS_P (cond
));
6514 rcode
= get_rtx_code (TREE_CODE (cond
), unsignedp
);
6515 t_op0
= TREE_OPERAND (cond
, 0);
6516 t_op1
= TREE_OPERAND (cond
, 1);
6518 /* Expand operands. */
6519 rtx_op0
= expand_expr (t_op0
, NULL_RTX
, TYPE_MODE (TREE_TYPE (t_op0
)),
6521 rtx_op1
= expand_expr (t_op1
, NULL_RTX
, TYPE_MODE (TREE_TYPE (t_op1
)),
6524 create_input_operand (&ops
[0], rtx_op0
, GET_MODE (rtx_op0
));
6525 create_input_operand (&ops
[1], rtx_op1
, GET_MODE (rtx_op1
));
6526 if (!maybe_legitimize_operands (icode
, 4, 2, ops
))
6528 return gen_rtx_fmt_ee (rcode
, VOIDmode
, ops
[0].value
, ops
[1].value
);
6531 /* Return insn code for TYPE, the type of a VEC_COND_EXPR. */
6533 static inline enum insn_code
6534 get_vcond_icode (tree type
, enum machine_mode mode
)
6536 enum insn_code icode
= CODE_FOR_nothing
;
6538 if (TYPE_UNSIGNED (type
))
6539 icode
= direct_optab_handler (vcondu_optab
, mode
);
6541 icode
= direct_optab_handler (vcond_optab
, mode
);
6545 /* Return TRUE iff, appropriate vector insns are available
6546 for vector cond expr with type TYPE in VMODE mode. */
6549 expand_vec_cond_expr_p (tree type
, enum machine_mode vmode
)
6551 if (get_vcond_icode (type
, vmode
) == CODE_FOR_nothing
)
6556 /* Generate insns for a VEC_COND_EXPR, given its TYPE and its
6560 expand_vec_cond_expr (tree vec_cond_type
, tree op0
, tree op1
, tree op2
,
6563 struct expand_operand ops
[6];
6564 enum insn_code icode
;
6565 rtx comparison
, rtx_op1
, rtx_op2
;
6566 enum machine_mode mode
= TYPE_MODE (vec_cond_type
);
6567 bool unsignedp
= TYPE_UNSIGNED (vec_cond_type
);
6569 icode
= get_vcond_icode (vec_cond_type
, mode
);
6570 if (icode
== CODE_FOR_nothing
)
6573 comparison
= vector_compare_rtx (op0
, unsignedp
, icode
);
6574 rtx_op1
= expand_normal (op1
);
6575 rtx_op2
= expand_normal (op2
);
6577 create_output_operand (&ops
[0], target
, mode
);
6578 create_input_operand (&ops
[1], rtx_op1
, mode
);
6579 create_input_operand (&ops
[2], rtx_op2
, mode
);
6580 create_fixed_operand (&ops
[3], comparison
);
6581 create_fixed_operand (&ops
[4], XEXP (comparison
, 0));
6582 create_fixed_operand (&ops
[5], XEXP (comparison
, 1));
6583 expand_insn (icode
, 6, ops
);
6584 return ops
[0].value
;
6588 /* This is an internal subroutine of the other compare_and_swap expanders.
6589 MEM, OLD_VAL and NEW_VAL are as you'd expect for a compare-and-swap
6590 operation. TARGET is an optional place to store the value result of
6591 the operation. ICODE is the particular instruction to expand. Return
6592 the result of the operation. */
6595 expand_val_compare_and_swap_1 (rtx mem
, rtx old_val
, rtx new_val
,
6596 rtx target
, enum insn_code icode
)
6598 struct expand_operand ops
[4];
6599 enum machine_mode mode
= GET_MODE (mem
);
6601 create_output_operand (&ops
[0], target
, mode
);
6602 create_fixed_operand (&ops
[1], mem
);
6603 /* OLD_VAL and NEW_VAL may have been promoted to a wider mode.
6604 Shrink them if so. */
6605 create_convert_operand_to (&ops
[2], old_val
, mode
, true);
6606 create_convert_operand_to (&ops
[3], new_val
, mode
, true);
6607 if (maybe_expand_insn (icode
, 4, ops
))
6608 return ops
[0].value
;
6612 /* Expand a compare-and-swap operation and return its value. */
6615 expand_val_compare_and_swap (rtx mem
, rtx old_val
, rtx new_val
, rtx target
)
6617 enum machine_mode mode
= GET_MODE (mem
);
6618 enum insn_code icode
6619 = direct_optab_handler (sync_compare_and_swap_optab
, mode
);
6621 if (icode
== CODE_FOR_nothing
)
6624 return expand_val_compare_and_swap_1 (mem
, old_val
, new_val
, target
, icode
);
6627 /* Helper function to find the MODE_CC set in a sync_compare_and_swap
6631 find_cc_set (rtx x
, const_rtx pat
, void *data
)
6633 if (REG_P (x
) && GET_MODE_CLASS (GET_MODE (x
)) == MODE_CC
6634 && GET_CODE (pat
) == SET
)
6636 rtx
*p_cc_reg
= (rtx
*) data
;
6637 gcc_assert (!*p_cc_reg
);
6642 /* Expand a compare-and-swap operation and store true into the result if
6643 the operation was successful and false otherwise. Return the result.
6644 Unlike other routines, TARGET is not optional. */
6647 expand_bool_compare_and_swap (rtx mem
, rtx old_val
, rtx new_val
, rtx target
)
6649 enum machine_mode mode
= GET_MODE (mem
);
6650 enum insn_code icode
;
6651 rtx subtarget
, seq
, cc_reg
;
6653 /* If the target supports a compare-and-swap pattern that simultaneously
6654 sets some flag for success, then use it. Otherwise use the regular
6655 compare-and-swap and follow that immediately with a compare insn. */
6656 icode
= direct_optab_handler (sync_compare_and_swap_optab
, mode
);
6657 if (icode
== CODE_FOR_nothing
)
6660 do_pending_stack_adjust ();
6664 subtarget
= expand_val_compare_and_swap_1 (mem
, old_val
, new_val
,
6667 if (subtarget
== NULL_RTX
)
6673 if (have_insn_for (COMPARE
, CCmode
))
6674 note_stores (PATTERN (get_last_insn ()), find_cc_set
, &cc_reg
);
6678 /* We might be comparing against an old value. Try again. :-( */
6679 if (!cc_reg
&& MEM_P (old_val
))
6682 old_val
= force_reg (mode
, old_val
);
6689 return emit_store_flag_force (target
, EQ
, cc_reg
, const0_rtx
, VOIDmode
, 0, 1);
6691 return emit_store_flag_force (target
, EQ
, subtarget
, old_val
, VOIDmode
, 1, 1);
6694 /* This is a helper function for the other atomic operations. This function
6695 emits a loop that contains SEQ that iterates until a compare-and-swap
6696 operation at the end succeeds. MEM is the memory to be modified. SEQ is
6697 a set of instructions that takes a value from OLD_REG as an input and
6698 produces a value in NEW_REG as an output. Before SEQ, OLD_REG will be
6699 set to the current contents of MEM. After SEQ, a compare-and-swap will
6700 attempt to update MEM with NEW_REG. The function returns true when the
6701 loop was generated successfully. */
6704 expand_compare_and_swap_loop (rtx mem
, rtx old_reg
, rtx new_reg
, rtx seq
)
6706 enum machine_mode mode
= GET_MODE (mem
);
6707 enum insn_code icode
;
6708 rtx label
, cmp_reg
, subtarget
, cc_reg
;
6710 /* The loop we want to generate looks like
6716 cmp_reg = compare-and-swap(mem, old_reg, new_reg)
6717 if (cmp_reg != old_reg)
6720 Note that we only do the plain load from memory once. Subsequent
6721 iterations use the value loaded by the compare-and-swap pattern. */
6723 label
= gen_label_rtx ();
6724 cmp_reg
= gen_reg_rtx (mode
);
6726 emit_move_insn (cmp_reg
, mem
);
6728 emit_move_insn (old_reg
, cmp_reg
);
6732 /* If the target supports a compare-and-swap pattern that simultaneously
6733 sets some flag for success, then use it. Otherwise use the regular
6734 compare-and-swap and follow that immediately with a compare insn. */
6735 icode
= direct_optab_handler (sync_compare_and_swap_optab
, mode
);
6736 if (icode
== CODE_FOR_nothing
)
6739 subtarget
= expand_val_compare_and_swap_1 (mem
, old_reg
, new_reg
,
6741 if (subtarget
== NULL_RTX
)
6745 if (have_insn_for (COMPARE
, CCmode
))
6746 note_stores (PATTERN (get_last_insn ()), find_cc_set
, &cc_reg
);
6750 old_reg
= const0_rtx
;
6754 if (subtarget
!= cmp_reg
)
6755 emit_move_insn (cmp_reg
, subtarget
);
6758 /* ??? Mark this jump predicted not taken? */
6759 emit_cmp_and_jump_insns (cmp_reg
, old_reg
, NE
, const0_rtx
, GET_MODE (cmp_reg
), 1,
6764 /* This function generates the atomic operation MEM CODE= VAL. In this
6765 case, we do not care about any resulting value. Returns NULL if we
6766 cannot generate the operation. */
6769 expand_sync_operation (rtx mem
, rtx val
, enum rtx_code code
)
6771 enum machine_mode mode
= GET_MODE (mem
);
6772 enum insn_code icode
;
6775 /* Look to see if the target supports the operation directly. */
6779 icode
= direct_optab_handler (sync_add_optab
, mode
);
6782 icode
= direct_optab_handler (sync_ior_optab
, mode
);
6785 icode
= direct_optab_handler (sync_xor_optab
, mode
);
6788 icode
= direct_optab_handler (sync_and_optab
, mode
);
6791 icode
= direct_optab_handler (sync_nand_optab
, mode
);
6795 icode
= direct_optab_handler (sync_sub_optab
, mode
);
6796 if (icode
== CODE_FOR_nothing
|| CONST_INT_P (val
))
6798 icode
= direct_optab_handler (sync_add_optab
, mode
);
6799 if (icode
!= CODE_FOR_nothing
)
6801 val
= expand_simple_unop (mode
, NEG
, val
, NULL_RTX
, 1);
6811 /* Generate the direct operation, if present. */
6812 if (icode
!= CODE_FOR_nothing
)
6814 struct expand_operand ops
[2];
6816 create_fixed_operand (&ops
[0], mem
);
6817 /* VAL may have been promoted to a wider mode. Shrink it if so. */
6818 create_convert_operand_to (&ops
[1], val
, mode
, true);
6819 if (maybe_expand_insn (icode
, 2, ops
))
6823 /* Failing that, generate a compare-and-swap loop in which we perform the
6824 operation with normal arithmetic instructions. */
6825 if (direct_optab_handler (sync_compare_and_swap_optab
, mode
)
6826 != CODE_FOR_nothing
)
6828 rtx t0
= gen_reg_rtx (mode
), t1
;
6835 t1
= expand_simple_binop (mode
, AND
, t1
, val
, NULL_RTX
,
6836 true, OPTAB_LIB_WIDEN
);
6837 t1
= expand_simple_unop (mode
, code
, t1
, NULL_RTX
, true);
6840 t1
= expand_simple_binop (mode
, code
, t1
, val
, NULL_RTX
,
6841 true, OPTAB_LIB_WIDEN
);
6842 insn
= get_insns ();
6845 if (t1
!= NULL
&& expand_compare_and_swap_loop (mem
, t0
, t1
, insn
))
6852 /* This function generates the atomic operation MEM CODE= VAL. In this
6853 case, we do care about the resulting value: if AFTER is true then
6854 return the value MEM holds after the operation, if AFTER is false
6855 then return the value MEM holds before the operation. TARGET is an
6856 optional place for the result value to be stored. */
6859 expand_sync_fetch_operation (rtx mem
, rtx val
, enum rtx_code code
,
6860 bool after
, rtx target
)
6862 enum machine_mode mode
= GET_MODE (mem
);
6863 enum insn_code old_code
, new_code
, icode
;
6867 /* Look to see if the target supports the operation directly. */
6871 old_code
= direct_optab_handler (sync_old_add_optab
, mode
);
6872 new_code
= direct_optab_handler (sync_new_add_optab
, mode
);
6875 old_code
= direct_optab_handler (sync_old_ior_optab
, mode
);
6876 new_code
= direct_optab_handler (sync_new_ior_optab
, mode
);
6879 old_code
= direct_optab_handler (sync_old_xor_optab
, mode
);
6880 new_code
= direct_optab_handler (sync_new_xor_optab
, mode
);
6883 old_code
= direct_optab_handler (sync_old_and_optab
, mode
);
6884 new_code
= direct_optab_handler (sync_new_and_optab
, mode
);
6887 old_code
= direct_optab_handler (sync_old_nand_optab
, mode
);
6888 new_code
= direct_optab_handler (sync_new_nand_optab
, mode
);
6892 old_code
= direct_optab_handler (sync_old_sub_optab
, mode
);
6893 new_code
= direct_optab_handler (sync_new_sub_optab
, mode
);
6894 if ((old_code
== CODE_FOR_nothing
&& new_code
== CODE_FOR_nothing
)
6895 || CONST_INT_P (val
))
6897 old_code
= direct_optab_handler (sync_old_add_optab
, mode
);
6898 new_code
= direct_optab_handler (sync_new_add_optab
, mode
);
6899 if (old_code
!= CODE_FOR_nothing
|| new_code
!= CODE_FOR_nothing
)
6901 val
= expand_simple_unop (mode
, NEG
, val
, NULL_RTX
, 1);
6911 /* If the target does supports the proper new/old operation, great. But
6912 if we only support the opposite old/new operation, check to see if we
6913 can compensate. In the case in which the old value is supported, then
6914 we can always perform the operation again with normal arithmetic. In
6915 the case in which the new value is supported, then we can only handle
6916 this in the case the operation is reversible. */
6921 if (icode
== CODE_FOR_nothing
)
6924 if (icode
!= CODE_FOR_nothing
)
6931 if (icode
== CODE_FOR_nothing
6932 && (code
== PLUS
|| code
== MINUS
|| code
== XOR
))
6935 if (icode
!= CODE_FOR_nothing
)
6940 /* If we found something supported, great. */
6941 if (icode
!= CODE_FOR_nothing
)
6943 struct expand_operand ops
[3];
6945 create_output_operand (&ops
[0], target
, mode
);
6946 create_fixed_operand (&ops
[1], mem
);
6947 /* VAL may have been promoted to a wider mode. Shrink it if so. */
6948 create_convert_operand_to (&ops
[2], val
, mode
, true);
6949 if (maybe_expand_insn (icode
, 3, ops
))
6951 target
= ops
[0].value
;
6953 /* If we need to compensate for using an operation with the
6954 wrong return value, do so now. */
6961 else if (code
== MINUS
)
6967 target
= expand_simple_binop (mode
, AND
, target
, val
,
6970 target
= expand_simple_unop (mode
, code
, target
,
6974 target
= expand_simple_binop (mode
, code
, target
, val
,
6983 /* Failing that, generate a compare-and-swap loop in which we perform the
6984 operation with normal arithmetic instructions. */
6985 if (direct_optab_handler (sync_compare_and_swap_optab
, mode
)
6986 != CODE_FOR_nothing
)
6988 rtx t0
= gen_reg_rtx (mode
), t1
;
6990 if (!target
|| !register_operand (target
, mode
))
6991 target
= gen_reg_rtx (mode
);
6996 emit_move_insn (target
, t0
);
7000 t1
= expand_simple_binop (mode
, AND
, t1
, val
, NULL_RTX
,
7001 true, OPTAB_LIB_WIDEN
);
7002 t1
= expand_simple_unop (mode
, code
, t1
, NULL_RTX
, true);
7005 t1
= expand_simple_binop (mode
, code
, t1
, val
, NULL_RTX
,
7006 true, OPTAB_LIB_WIDEN
);
7008 emit_move_insn (target
, t1
);
7010 insn
= get_insns ();
7013 if (t1
!= NULL
&& expand_compare_and_swap_loop (mem
, t0
, t1
, insn
))
7020 /* This function expands a test-and-set operation. Ideally we atomically
7021 store VAL in MEM and return the previous value in MEM. Some targets
7022 may not support this operation and only support VAL with the constant 1;
7023 in this case while the return value will be 0/1, but the exact value
7024 stored in MEM is target defined. TARGET is an option place to stick
7025 the return value. */
7028 expand_sync_lock_test_and_set (rtx mem
, rtx val
, rtx target
)
7030 enum machine_mode mode
= GET_MODE (mem
);
7031 enum insn_code icode
;
7033 /* If the target supports the test-and-set directly, great. */
7034 icode
= direct_optab_handler (sync_lock_test_and_set_optab
, mode
);
7035 if (icode
!= CODE_FOR_nothing
)
7037 struct expand_operand ops
[3];
7039 create_output_operand (&ops
[0], target
, mode
);
7040 create_fixed_operand (&ops
[1], mem
);
7041 /* VAL may have been promoted to a wider mode. Shrink it if so. */
7042 create_convert_operand_to (&ops
[2], val
, mode
, true);
7043 if (maybe_expand_insn (icode
, 3, ops
))
7044 return ops
[0].value
;
7047 /* Otherwise, use a compare-and-swap loop for the exchange. */
7048 if (direct_optab_handler (sync_compare_and_swap_optab
, mode
)
7049 != CODE_FOR_nothing
)
7051 if (!target
|| !register_operand (target
, mode
))
7052 target
= gen_reg_rtx (mode
);
7053 if (GET_MODE (val
) != VOIDmode
&& GET_MODE (val
) != mode
)
7054 val
= convert_modes (mode
, GET_MODE (val
), val
, 1);
7055 if (expand_compare_and_swap_loop (mem
, target
, val
, NULL_RTX
))
7062 /* Return true if OPERAND is suitable for operand number OPNO of
7063 instruction ICODE. */
7066 insn_operand_matches (enum insn_code icode
, unsigned int opno
, rtx operand
)
7068 return (!insn_data
[(int) icode
].operand
[opno
].predicate
7069 || (insn_data
[(int) icode
].operand
[opno
].predicate
7070 (operand
, insn_data
[(int) icode
].operand
[opno
].mode
)));
7073 /* TARGET is a target of a multiword operation that we are going to
7074 implement as a series of word-mode operations. Return true if
7075 TARGET is suitable for this purpose. */
7078 valid_multiword_target_p (rtx target
)
7080 enum machine_mode mode
;
7083 mode
= GET_MODE (target
);
7084 for (i
= 0; i
< GET_MODE_SIZE (mode
); i
+= UNITS_PER_WORD
)
7085 if (!validate_subreg (word_mode
, mode
, target
, i
))
7090 /* Like maybe_legitimize_operand, but do not change the code of the
7091 current rtx value. */
7094 maybe_legitimize_operand_same_code (enum insn_code icode
, unsigned int opno
,
7095 struct expand_operand
*op
)
7097 /* See if the operand matches in its current form. */
7098 if (insn_operand_matches (icode
, opno
, op
->value
))
7101 /* If the operand is a memory whose address has no side effects,
7102 try forcing the address into a register. The check for side
7103 effects is important because force_reg cannot handle things
7104 like auto-modified addresses. */
7105 if (insn_data
[(int) icode
].operand
[opno
].allows_mem
7106 && MEM_P (op
->value
)
7107 && !side_effects_p (XEXP (op
->value
, 0)))
7109 rtx addr
, mem
, last
;
7111 last
= get_last_insn ();
7112 addr
= force_reg (Pmode
, XEXP (op
->value
, 0));
7113 mem
= replace_equiv_address (op
->value
, addr
);
7114 if (insn_operand_matches (icode
, opno
, mem
))
7119 delete_insns_since (last
);
7125 /* Try to make OP match operand OPNO of instruction ICODE. Return true
7126 on success, storing the new operand value back in OP. */
7129 maybe_legitimize_operand (enum insn_code icode
, unsigned int opno
,
7130 struct expand_operand
*op
)
7132 enum machine_mode mode
, imode
;
7133 bool old_volatile_ok
, result
;
7139 old_volatile_ok
= volatile_ok
;
7141 result
= maybe_legitimize_operand_same_code (icode
, opno
, op
);
7142 volatile_ok
= old_volatile_ok
;
7146 gcc_assert (mode
!= VOIDmode
);
7148 && op
->value
!= const0_rtx
7149 && GET_MODE (op
->value
) == mode
7150 && maybe_legitimize_operand_same_code (icode
, opno
, op
))
7153 op
->value
= gen_reg_rtx (mode
);
7158 gcc_assert (mode
!= VOIDmode
);
7159 gcc_assert (GET_MODE (op
->value
) == VOIDmode
7160 || GET_MODE (op
->value
) == mode
);
7161 if (maybe_legitimize_operand_same_code (icode
, opno
, op
))
7164 op
->value
= copy_to_mode_reg (mode
, op
->value
);
7167 case EXPAND_CONVERT_TO
:
7168 gcc_assert (mode
!= VOIDmode
);
7169 op
->value
= convert_to_mode (mode
, op
->value
, op
->unsigned_p
);
7172 case EXPAND_CONVERT_FROM
:
7173 if (GET_MODE (op
->value
) != VOIDmode
)
7174 mode
= GET_MODE (op
->value
);
7176 /* The caller must tell us what mode this value has. */
7177 gcc_assert (mode
!= VOIDmode
);
7179 imode
= insn_data
[(int) icode
].operand
[opno
].mode
;
7180 if (imode
!= VOIDmode
&& imode
!= mode
)
7182 op
->value
= convert_modes (imode
, mode
, op
->value
, op
->unsigned_p
);
7187 case EXPAND_ADDRESS
:
7188 gcc_assert (mode
!= VOIDmode
);
7189 op
->value
= convert_memory_address (mode
, op
->value
);
7192 case EXPAND_INTEGER
:
7193 mode
= insn_data
[(int) icode
].operand
[opno
].mode
;
7194 if (mode
!= VOIDmode
&& const_int_operand (op
->value
, mode
))
7198 return insn_operand_matches (icode
, opno
, op
->value
);
7201 /* Make OP describe an input operand that should have the same value
7202 as VALUE, after any mode conversion that the target might request.
7203 TYPE is the type of VALUE. */
7206 create_convert_operand_from_type (struct expand_operand
*op
,
7207 rtx value
, tree type
)
7209 create_convert_operand_from (op
, value
, TYPE_MODE (type
),
7210 TYPE_UNSIGNED (type
));
7213 /* Try to make operands [OPS, OPS + NOPS) match operands [OPNO, OPNO + NOPS)
7214 of instruction ICODE. Return true on success, leaving the new operand
7215 values in the OPS themselves. Emit no code on failure. */
7218 maybe_legitimize_operands (enum insn_code icode
, unsigned int opno
,
7219 unsigned int nops
, struct expand_operand
*ops
)
7224 last
= get_last_insn ();
7225 for (i
= 0; i
< nops
; i
++)
7226 if (!maybe_legitimize_operand (icode
, opno
+ i
, &ops
[i
]))
7228 delete_insns_since (last
);
7234 /* Try to generate instruction ICODE, using operands [OPS, OPS + NOPS)
7235 as its operands. Return the instruction pattern on success,
7236 and emit any necessary set-up code. Return null and emit no
7240 maybe_gen_insn (enum insn_code icode
, unsigned int nops
,
7241 struct expand_operand
*ops
)
7243 gcc_assert (nops
== (unsigned int) insn_data
[(int) icode
].n_generator_args
);
7244 if (!maybe_legitimize_operands (icode
, 0, nops
, ops
))
7250 return GEN_FCN (icode
) (ops
[0].value
);
7252 return GEN_FCN (icode
) (ops
[0].value
, ops
[1].value
);
7254 return GEN_FCN (icode
) (ops
[0].value
, ops
[1].value
, ops
[2].value
);
7256 return GEN_FCN (icode
) (ops
[0].value
, ops
[1].value
, ops
[2].value
,
7259 return GEN_FCN (icode
) (ops
[0].value
, ops
[1].value
, ops
[2].value
,
7260 ops
[3].value
, ops
[4].value
);
7262 return GEN_FCN (icode
) (ops
[0].value
, ops
[1].value
, ops
[2].value
,
7263 ops
[3].value
, ops
[4].value
, ops
[5].value
);
7268 /* Try to emit instruction ICODE, using operands [OPS, OPS + NOPS)
7269 as its operands. Return true on success and emit no code on failure. */
7272 maybe_expand_insn (enum insn_code icode
, unsigned int nops
,
7273 struct expand_operand
*ops
)
7275 rtx pat
= maybe_gen_insn (icode
, nops
, ops
);
7284 /* Like maybe_expand_insn, but for jumps. */
7287 maybe_expand_jump_insn (enum insn_code icode
, unsigned int nops
,
7288 struct expand_operand
*ops
)
7290 rtx pat
= maybe_gen_insn (icode
, nops
, ops
);
7293 emit_jump_insn (pat
);
7299 /* Emit instruction ICODE, using operands [OPS, OPS + NOPS)
7303 expand_insn (enum insn_code icode
, unsigned int nops
,
7304 struct expand_operand
*ops
)
7306 if (!maybe_expand_insn (icode
, nops
, ops
))
7310 /* Like expand_insn, but for jumps. */
7313 expand_jump_insn (enum insn_code icode
, unsigned int nops
,
7314 struct expand_operand
*ops
)
7316 if (!maybe_expand_jump_insn (icode
, nops
, ops
))
7320 #include "gt-optabs.h"