1 /* Expand the basic unary and binary arithmetic operations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
29 /* Include insn-config.h before expr.h so that HAVE_conditional_move
30 is properly defined. */
31 #include "insn-config.h"
45 #include "basic-block.h"
48 /* Each optab contains info on how this target machine
49 can perform a particular operation
50 for all sizes and kinds of operands.
52 The operation to be performed is often specified
53 by passing one of these optabs as an argument.
55 See expr.h for documentation of these optabs. */
57 optab optab_table[OTI_MAX];
59 rtx libfunc_table[LTI_MAX];
61 /* Tables of patterns for converting one mode to another. */
62 convert_optab convert_optab_table[CTI_MAX];
64 /* Contains the optab used for each rtx code. */
65 optab code_to_optab[NUM_RTX_CODE + 1];
67 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
68 gives the gen_function to make a branch to test that condition. */
70 rtxfun bcc_gen_fctn[NUM_RTX_CODE];
72 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
73 gives the insn code to make a store-condition insn
74 to test that condition. */
76 enum insn_code setcc_gen_code[NUM_RTX_CODE];
78 #ifdef HAVE_conditional_move
79 /* Indexed by the machine mode, gives the insn code to make a conditional
80 move insn. This is not indexed by the rtx-code like bcc_gen_fctn and
81 setcc_gen_code to cut down on the number of named patterns. Consider a day
82 when a lot more rtx codes are conditional (eg: for the ARM). */
84 enum insn_code movcc_gen_code[NUM_MACHINE_MODES];
87 /* The insn generating function can not take an rtx_code argument.
88 TRAP_RTX is used as an rtx argument. Its code is replaced with
89 the code to be used in the trap insn and all other fields are ignored. */
90 static GTY(()) rtx trap_rtx;
92 static int add_equal_note (rtx, rtx, enum rtx_code, rtx, rtx);
93 static rtx widen_operand (rtx, enum machine_mode, enum machine_mode, int,
95 static int expand_cmplxdiv_straight (rtx, rtx, rtx, rtx, rtx, rtx,
96 enum machine_mode, int,
97 enum optab_methods, enum mode_class,
99 static int expand_cmplxdiv_wide (rtx, rtx, rtx, rtx, rtx, rtx,
100 enum machine_mode, int, enum optab_methods,
101 enum mode_class, optab);
102 static void prepare_cmp_insn (rtx *, rtx *, enum rtx_code *, rtx,
103 enum machine_mode *, int *,
104 enum can_compare_purpose);
105 static enum insn_code can_fix_p (enum machine_mode, enum machine_mode, int,
107 static enum insn_code can_float_p (enum machine_mode, enum machine_mode, int);
108 static optab new_optab (void);
109 static convert_optab new_convert_optab (void);
110 static inline optab init_optab (enum rtx_code);
111 static inline optab init_optabv (enum rtx_code);
112 static inline convert_optab init_convert_optab (enum rtx_code);
113 static void init_libfuncs (optab, int, int, const char *, int);
114 static void init_integral_libfuncs (optab, const char *, int);
115 static void init_floating_libfuncs (optab, const char *, int);
116 static void init_interclass_conv_libfuncs (convert_optab, const char *,
117 enum mode_class, enum mode_class);
118 static void init_intraclass_conv_libfuncs (convert_optab, const char *,
119 enum mode_class, bool);
120 static void emit_cmp_and_jump_insn_1 (rtx, rtx, enum machine_mode,
121 enum rtx_code, int, rtx);
122 static void prepare_float_lib_cmp (rtx *, rtx *, enum rtx_code *,
123 enum machine_mode *, int *);
124 static rtx expand_vector_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
126 static rtx expand_vector_unop (enum machine_mode, optab, rtx, rtx, int);
127 static rtx widen_clz (enum machine_mode, rtx, rtx);
128 static rtx expand_parity (enum machine_mode, rtx, rtx);
130 #ifndef HAVE_conditional_trap
131 #define HAVE_conditional_trap 0
132 #define gen_conditional_trap(a,b) (abort (), NULL_RTX)
135 /* Add a REG_EQUAL note to the last insn in INSNS. TARGET is being set to
136 the result of operation CODE applied to OP0 (and OP1 if it is a binary
139 If the last insn does not set TARGET, don't do anything, but return 1.
141 If a previous insn sets TARGET and TARGET is one of OP0 or OP1,
142 don't add the REG_EQUAL note but return 0. Our caller can then try
143 again, ensuring that TARGET is not one of the operands. */
146 add_equal_note (rtx insns, rtx target, enum rtx_code code, rtx op0, rtx op1)
148 rtx last_insn, insn, set;
153 || NEXT_INSN (insns) == NULL_RTX)
156 if (GET_RTX_CLASS (code) != RTX_COMM_ARITH
157 && GET_RTX_CLASS (code) != RTX_BIN_ARITH
158 && GET_RTX_CLASS (code) != RTX_COMM_COMPARE
159 && GET_RTX_CLASS (code) != RTX_COMPARE
160 && GET_RTX_CLASS (code) != RTX_UNARY)
163 if (GET_CODE (target) == ZERO_EXTRACT)
166 for (last_insn = insns;
167 NEXT_INSN (last_insn) != NULL_RTX;
168 last_insn = NEXT_INSN (last_insn))
171 set = single_set (last_insn);
175 if (! rtx_equal_p (SET_DEST (set), target)
176 /* For a STRICT_LOW_PART, the REG_NOTE applies to what is inside it. */
177 && (GET_CODE (SET_DEST (set)) != STRICT_LOW_PART
178 || ! rtx_equal_p (XEXP (SET_DEST (set), 0), target)))
181 /* If TARGET is in OP0 or OP1, check if anything in SEQ sets TARGET
182 besides the last insn. */
183 if (reg_overlap_mentioned_p (target, op0)
184 || (op1 && reg_overlap_mentioned_p (target, op1)))
186 insn = PREV_INSN (last_insn);
187 while (insn != NULL_RTX)
189 if (reg_set_p (target, insn))
192 insn = PREV_INSN (insn);
196 if (GET_RTX_CLASS (code) == RTX_UNARY)
197 note = gen_rtx_fmt_e (code, GET_MODE (target), copy_rtx (op0));
199 note = gen_rtx_fmt_ee (code, GET_MODE (target), copy_rtx (op0), copy_rtx (op1));
201 set_unique_reg_note (last_insn, REG_EQUAL, note);
206 /* Widen OP to MODE and return the rtx for the widened operand. UNSIGNEDP
207 says whether OP is signed or unsigned. NO_EXTEND is nonzero if we need
208 not actually do a sign-extend or zero-extend, but can leave the
209 higher-order bits of the result rtx undefined, for example, in the case
210 of logical operations, but not right shifts. */
213 widen_operand (rtx op, enum machine_mode mode, enum machine_mode oldmode,
214 int unsignedp, int no_extend)
218 /* If we don't have to extend and this is a constant, return it. */
219 if (no_extend && GET_MODE (op) == VOIDmode)
222 /* If we must extend do so. If OP is a SUBREG for a promoted object, also
223 extend since it will be more efficient to do so unless the signedness of
224 a promoted object differs from our extension. */
226 || (GET_CODE (op) == SUBREG && SUBREG_PROMOTED_VAR_P (op)
227 && SUBREG_PROMOTED_UNSIGNED_P (op) == unsignedp))
228 return convert_modes (mode, oldmode, op, unsignedp);
230 /* If MODE is no wider than a single word, we return a paradoxical
232 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
233 return gen_rtx_SUBREG (mode, force_reg (GET_MODE (op), op), 0);
235 /* Otherwise, get an object of MODE, clobber it, and set the low-order
238 result = gen_reg_rtx (mode);
239 emit_insn (gen_rtx_CLOBBER (VOIDmode, result));
240 emit_move_insn (gen_lowpart (GET_MODE (op), result), op);
244 /* Generate code to perform a straightforward complex divide. */
247 expand_cmplxdiv_straight (rtx real0, rtx real1, rtx imag0, rtx imag1,
248 rtx realr, rtx imagr, enum machine_mode submode,
249 int unsignedp, enum optab_methods methods,
250 enum mode_class class, optab binoptab)
256 optab this_add_optab = add_optab;
257 optab this_sub_optab = sub_optab;
258 optab this_neg_optab = neg_optab;
259 optab this_mul_optab = smul_optab;
261 if (binoptab == sdivv_optab)
263 this_add_optab = addv_optab;
264 this_sub_optab = subv_optab;
265 this_neg_optab = negv_optab;
266 this_mul_optab = smulv_optab;
269 /* Don't fetch these from memory more than once. */
270 real0 = force_reg (submode, real0);
271 real1 = force_reg (submode, real1);
274 imag0 = force_reg (submode, imag0);
276 imag1 = force_reg (submode, imag1);
278 /* Divisor: c*c + d*d. */
279 temp1 = expand_binop (submode, this_mul_optab, real1, real1,
280 NULL_RTX, unsignedp, methods);
282 temp2 = expand_binop (submode, this_mul_optab, imag1, imag1,
283 NULL_RTX, unsignedp, methods);
285 if (temp1 == 0 || temp2 == 0)
288 divisor = expand_binop (submode, this_add_optab, temp1, temp2,
289 NULL_RTX, unsignedp, methods);
295 /* Mathematically, ((a)(c-id))/divisor. */
296 /* Computationally, (a+i0) / (c+id) = (ac/(cc+dd)) + i(-ad/(cc+dd)). */
298 /* Calculate the dividend. */
299 real_t = expand_binop (submode, this_mul_optab, real0, real1,
300 NULL_RTX, unsignedp, methods);
302 imag_t = expand_binop (submode, this_mul_optab, real0, imag1,
303 NULL_RTX, unsignedp, methods);
305 if (real_t == 0 || imag_t == 0)
308 imag_t = expand_unop (submode, this_neg_optab, imag_t,
309 NULL_RTX, unsignedp);
313 /* Mathematically, ((a+ib)(c-id))/divider. */
314 /* Calculate the dividend. */
315 temp1 = expand_binop (submode, this_mul_optab, real0, real1,
316 NULL_RTX, unsignedp, methods);
318 temp2 = expand_binop (submode, this_mul_optab, imag0, imag1,
319 NULL_RTX, unsignedp, methods);
321 if (temp1 == 0 || temp2 == 0)
324 real_t = expand_binop (submode, this_add_optab, temp1, temp2,
325 NULL_RTX, unsignedp, methods);
327 temp1 = expand_binop (submode, this_mul_optab, imag0, real1,
328 NULL_RTX, unsignedp, methods);
330 temp2 = expand_binop (submode, this_mul_optab, real0, imag1,
331 NULL_RTX, unsignedp, methods);
333 if (temp1 == 0 || temp2 == 0)
336 imag_t = expand_binop (submode, this_sub_optab, temp1, temp2,
337 NULL_RTX, unsignedp, methods);
339 if (real_t == 0 || imag_t == 0)
343 if (class == MODE_COMPLEX_FLOAT)
344 res = expand_binop (submode, binoptab, real_t, divisor,
345 realr, unsignedp, methods);
347 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
348 real_t, divisor, realr, unsignedp);
354 emit_move_insn (realr, res);
356 if (class == MODE_COMPLEX_FLOAT)
357 res = expand_binop (submode, binoptab, imag_t, divisor,
358 imagr, unsignedp, methods);
360 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
361 imag_t, divisor, imagr, unsignedp);
367 emit_move_insn (imagr, res);
372 /* Generate code to perform a wide-input-range-acceptable complex divide. */
375 expand_cmplxdiv_wide (rtx real0, rtx real1, rtx imag0, rtx imag1, rtx realr,
376 rtx imagr, enum machine_mode submode, int unsignedp,
377 enum optab_methods methods, enum mode_class class,
382 rtx temp1, temp2, lab1, lab2;
383 enum machine_mode mode;
385 optab this_add_optab = add_optab;
386 optab this_sub_optab = sub_optab;
387 optab this_neg_optab = neg_optab;
388 optab this_mul_optab = smul_optab;
390 if (binoptab == sdivv_optab)
392 this_add_optab = addv_optab;
393 this_sub_optab = subv_optab;
394 this_neg_optab = negv_optab;
395 this_mul_optab = smulv_optab;
398 /* Don't fetch these from memory more than once. */
399 real0 = force_reg (submode, real0);
400 real1 = force_reg (submode, real1);
403 imag0 = force_reg (submode, imag0);
405 imag1 = force_reg (submode, imag1);
407 /* XXX What's an "unsigned" complex number? */
415 temp1 = expand_abs (submode, real1, NULL_RTX, unsignedp, 1);
416 temp2 = expand_abs (submode, imag1, NULL_RTX, unsignedp, 1);
419 if (temp1 == 0 || temp2 == 0)
422 mode = GET_MODE (temp1);
423 lab1 = gen_label_rtx ();
424 emit_cmp_and_jump_insns (temp1, temp2, LT, NULL_RTX,
425 mode, unsignedp, lab1);
427 /* |c| >= |d|; use ratio d/c to scale dividend and divisor. */
429 if (class == MODE_COMPLEX_FLOAT)
430 ratio = expand_binop (submode, binoptab, imag1, real1,
431 NULL_RTX, unsignedp, methods);
433 ratio = expand_divmod (0, TRUNC_DIV_EXPR, submode,
434 imag1, real1, NULL_RTX, unsignedp);
439 /* Calculate divisor. */
441 temp1 = expand_binop (submode, this_mul_optab, imag1, ratio,
442 NULL_RTX, unsignedp, methods);
447 divisor = expand_binop (submode, this_add_optab, temp1, real1,
448 NULL_RTX, unsignedp, methods);
453 /* Calculate dividend. */
459 /* Compute a / (c+id) as a / (c+d(d/c)) + i (-a(d/c)) / (c+d(d/c)). */
461 imag_t = expand_binop (submode, this_mul_optab, real0, ratio,
462 NULL_RTX, unsignedp, methods);
467 imag_t = expand_unop (submode, this_neg_optab, imag_t,
468 NULL_RTX, unsignedp);
470 if (real_t == 0 || imag_t == 0)
475 /* Compute (a+ib)/(c+id) as
476 (a+b(d/c))/(c+d(d/c) + i(b-a(d/c))/(c+d(d/c)). */
478 temp1 = expand_binop (submode, this_mul_optab, imag0, ratio,
479 NULL_RTX, unsignedp, methods);
484 real_t = expand_binop (submode, this_add_optab, temp1, real0,
485 NULL_RTX, unsignedp, methods);
487 temp1 = expand_binop (submode, this_mul_optab, real0, ratio,
488 NULL_RTX, unsignedp, methods);
493 imag_t = expand_binop (submode, this_sub_optab, imag0, temp1,
494 NULL_RTX, unsignedp, methods);
496 if (real_t == 0 || imag_t == 0)
500 if (class == MODE_COMPLEX_FLOAT)
501 res = expand_binop (submode, binoptab, real_t, divisor,
502 realr, unsignedp, methods);
504 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
505 real_t, divisor, realr, unsignedp);
511 emit_move_insn (realr, res);
513 if (class == MODE_COMPLEX_FLOAT)
514 res = expand_binop (submode, binoptab, imag_t, divisor,
515 imagr, unsignedp, methods);
517 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
518 imag_t, divisor, imagr, unsignedp);
524 emit_move_insn (imagr, res);
526 lab2 = gen_label_rtx ();
527 emit_jump_insn (gen_jump (lab2));
532 /* |d| > |c|; use ratio c/d to scale dividend and divisor. */
534 if (class == MODE_COMPLEX_FLOAT)
535 ratio = expand_binop (submode, binoptab, real1, imag1,
536 NULL_RTX, unsignedp, methods);
538 ratio = expand_divmod (0, TRUNC_DIV_EXPR, submode,
539 real1, imag1, NULL_RTX, unsignedp);
544 /* Calculate divisor. */
546 temp1 = expand_binop (submode, this_mul_optab, real1, ratio,
547 NULL_RTX, unsignedp, methods);
552 divisor = expand_binop (submode, this_add_optab, temp1, imag1,
553 NULL_RTX, unsignedp, methods);
558 /* Calculate dividend. */
562 /* Compute a / (c+id) as a(c/d) / (c(c/d)+d) + i (-a) / (c(c/d)+d). */
564 real_t = expand_binop (submode, this_mul_optab, real0, ratio,
565 NULL_RTX, unsignedp, methods);
567 imag_t = expand_unop (submode, this_neg_optab, real0,
568 NULL_RTX, unsignedp);
570 if (real_t == 0 || imag_t == 0)
575 /* Compute (a+ib)/(c+id) as
576 (a(c/d)+b)/(c(c/d)+d) + i (b(c/d)-a)/(c(c/d)+d). */
578 temp1 = expand_binop (submode, this_mul_optab, real0, ratio,
579 NULL_RTX, unsignedp, methods);
584 real_t = expand_binop (submode, this_add_optab, temp1, imag0,
585 NULL_RTX, unsignedp, methods);
587 temp1 = expand_binop (submode, this_mul_optab, imag0, ratio,
588 NULL_RTX, unsignedp, methods);
593 imag_t = expand_binop (submode, this_sub_optab, temp1, real0,
594 NULL_RTX, unsignedp, methods);
596 if (real_t == 0 || imag_t == 0)
600 if (class == MODE_COMPLEX_FLOAT)
601 res = expand_binop (submode, binoptab, real_t, divisor,
602 realr, unsignedp, methods);
604 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
605 real_t, divisor, realr, unsignedp);
611 emit_move_insn (realr, res);
613 if (class == MODE_COMPLEX_FLOAT)
614 res = expand_binop (submode, binoptab, imag_t, divisor,
615 imagr, unsignedp, methods);
617 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
618 imag_t, divisor, imagr, unsignedp);
624 emit_move_insn (imagr, res);
631 /* Wrapper around expand_binop which takes an rtx code to specify
632 the operation to perform, not an optab pointer. All other
633 arguments are the same. */
635 expand_simple_binop (enum machine_mode mode, enum rtx_code code, rtx op0,
636 rtx op1, rtx target, int unsignedp,
637 enum optab_methods methods)
639 optab binop = code_to_optab[(int) code];
643 return expand_binop (mode, binop, op0, op1, target, unsignedp, methods);
646 /* Generate code to perform an operation specified by BINOPTAB
647 on operands OP0 and OP1, with result having machine-mode MODE.
649 UNSIGNEDP is for the case where we have to widen the operands
650 to perform the operation. It says to use zero-extension.
652 If TARGET is nonzero, the value
653 is generated there, if it is convenient to do so.
654 In all cases an rtx is returned for the locus of the value;
655 this may or may not be TARGET. */
658 expand_binop (enum machine_mode mode, optab binoptab, rtx op0, rtx op1,
659 rtx target, int unsignedp, enum optab_methods methods)
661 enum optab_methods next_methods
662 = (methods == OPTAB_LIB || methods == OPTAB_LIB_WIDEN
663 ? OPTAB_WIDEN : methods);
664 enum mode_class class;
665 enum machine_mode wider_mode;
667 int commutative_op = 0;
668 int shift_op = (binoptab->code == ASHIFT
669 || binoptab->code == ASHIFTRT
670 || binoptab->code == LSHIFTRT
671 || binoptab->code == ROTATE
672 || binoptab->code == ROTATERT);
673 rtx entry_last = get_last_insn ();
676 class = GET_MODE_CLASS (mode);
678 op0 = protect_from_queue (op0, 0);
679 op1 = protect_from_queue (op1, 0);
681 target = protect_from_queue (target, 1);
685 /* Load duplicate non-volatile operands once. */
686 if (rtx_equal_p (op0, op1) && ! volatile_refs_p (op0))
688 op0 = force_not_mem (op0);
693 op0 = force_not_mem (op0);
694 op1 = force_not_mem (op1);
698 /* If subtracting an integer constant, convert this into an addition of
699 the negated constant. */
701 if (binoptab == sub_optab && GET_CODE (op1) == CONST_INT)
703 op1 = negate_rtx (mode, op1);
704 binoptab = add_optab;
707 /* If we are inside an appropriately-short loop and one operand is an
708 expensive constant, force it into a register. */
709 if (CONSTANT_P (op0) && preserve_subexpressions_p ()
710 && rtx_cost (op0, binoptab->code) > COSTS_N_INSNS (1))
711 op0 = force_reg (mode, op0);
713 if (CONSTANT_P (op1) && preserve_subexpressions_p ()
714 && ! shift_op && rtx_cost (op1, binoptab->code) > COSTS_N_INSNS (1))
715 op1 = force_reg (mode, op1);
717 /* Record where to delete back to if we backtrack. */
718 last = get_last_insn ();
720 /* If operation is commutative,
721 try to make the first operand a register.
722 Even better, try to make it the same as the target.
723 Also try to make the last operand a constant. */
724 if (GET_RTX_CLASS (binoptab->code) == RTX_COMM_ARITH
725 || binoptab == smul_widen_optab
726 || binoptab == umul_widen_optab
727 || binoptab == smul_highpart_optab
728 || binoptab == umul_highpart_optab)
732 if (((target == 0 || GET_CODE (target) == REG)
733 ? ((GET_CODE (op1) == REG
734 && GET_CODE (op0) != REG)
736 : rtx_equal_p (op1, target))
737 || GET_CODE (op0) == CONST_INT)
745 /* If we can do it with a three-operand insn, do so. */
747 if (methods != OPTAB_MUST_WIDEN
748 && binoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
750 int icode = (int) binoptab->handlers[(int) mode].insn_code;
751 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
752 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
754 rtx xop0 = op0, xop1 = op1;
759 temp = gen_reg_rtx (mode);
761 /* If it is a commutative operator and the modes would match
762 if we would swap the operands, we can save the conversions. */
765 if (GET_MODE (op0) != mode0 && GET_MODE (op1) != mode1
766 && GET_MODE (op0) == mode1 && GET_MODE (op1) == mode0)
770 tmp = op0; op0 = op1; op1 = tmp;
771 tmp = xop0; xop0 = xop1; xop1 = tmp;
775 /* In case the insn wants input operands in modes different from
776 those of the actual operands, convert the operands. It would
777 seem that we don't need to convert CONST_INTs, but we do, so
778 that they're properly zero-extended, sign-extended or truncated
781 if (GET_MODE (op0) != mode0 && mode0 != VOIDmode)
782 xop0 = convert_modes (mode0,
783 GET_MODE (op0) != VOIDmode
788 if (GET_MODE (op1) != mode1 && mode1 != VOIDmode)
789 xop1 = convert_modes (mode1,
790 GET_MODE (op1) != VOIDmode
795 /* Now, if insn's predicates don't allow our operands, put them into
798 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0)
799 && mode0 != VOIDmode)
800 xop0 = copy_to_mode_reg (mode0, xop0);
802 if (! (*insn_data[icode].operand[2].predicate) (xop1, mode1)
803 && mode1 != VOIDmode)
804 xop1 = copy_to_mode_reg (mode1, xop1);
806 if (! (*insn_data[icode].operand[0].predicate) (temp, mode))
807 temp = gen_reg_rtx (mode);
809 pat = GEN_FCN (icode) (temp, xop0, xop1);
812 /* If PAT is composed of more than one insn, try to add an appropriate
813 REG_EQUAL note to it. If we can't because TEMP conflicts with an
814 operand, call ourselves again, this time without a target. */
815 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX
816 && ! add_equal_note (pat, temp, binoptab->code, xop0, xop1))
818 delete_insns_since (last);
819 return expand_binop (mode, binoptab, op0, op1, NULL_RTX,
827 delete_insns_since (last);
830 /* If this is a multiply, see if we can do a widening operation that
831 takes operands of this mode and makes a wider mode. */
833 if (binoptab == smul_optab && GET_MODE_WIDER_MODE (mode) != VOIDmode
834 && (((unsignedp ? umul_widen_optab : smul_widen_optab)
835 ->handlers[(int) GET_MODE_WIDER_MODE (mode)].insn_code)
836 != CODE_FOR_nothing))
838 temp = expand_binop (GET_MODE_WIDER_MODE (mode),
839 unsignedp ? umul_widen_optab : smul_widen_optab,
840 op0, op1, NULL_RTX, unsignedp, OPTAB_DIRECT);
844 if (GET_MODE_CLASS (mode) == MODE_INT)
845 return gen_lowpart (mode, temp);
847 return convert_to_mode (mode, temp, unsignedp);
851 /* Look for a wider mode of the same class for which we think we
852 can open-code the operation. Check for a widening multiply at the
853 wider mode as well. */
855 if ((class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
856 && methods != OPTAB_DIRECT && methods != OPTAB_LIB)
857 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
858 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
860 if (binoptab->handlers[(int) wider_mode].insn_code != CODE_FOR_nothing
861 || (binoptab == smul_optab
862 && GET_MODE_WIDER_MODE (wider_mode) != VOIDmode
863 && (((unsignedp ? umul_widen_optab : smul_widen_optab)
864 ->handlers[(int) GET_MODE_WIDER_MODE (wider_mode)].insn_code)
865 != CODE_FOR_nothing)))
867 rtx xop0 = op0, xop1 = op1;
870 /* For certain integer operations, we need not actually extend
871 the narrow operands, as long as we will truncate
872 the results to the same narrowness. */
874 if ((binoptab == ior_optab || binoptab == and_optab
875 || binoptab == xor_optab
876 || binoptab == add_optab || binoptab == sub_optab
877 || binoptab == smul_optab || binoptab == ashl_optab)
878 && class == MODE_INT)
881 xop0 = widen_operand (xop0, wider_mode, mode, unsignedp, no_extend);
883 /* The second operand of a shift must always be extended. */
884 xop1 = widen_operand (xop1, wider_mode, mode, unsignedp,
885 no_extend && binoptab != ashl_optab);
887 temp = expand_binop (wider_mode, binoptab, xop0, xop1, NULL_RTX,
888 unsignedp, OPTAB_DIRECT);
891 if (class != MODE_INT)
894 target = gen_reg_rtx (mode);
895 convert_move (target, temp, 0);
899 return gen_lowpart (mode, temp);
902 delete_insns_since (last);
906 /* These can be done a word at a time. */
907 if ((binoptab == and_optab || binoptab == ior_optab || binoptab == xor_optab)
909 && GET_MODE_SIZE (mode) > UNITS_PER_WORD
910 && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
916 /* If TARGET is the same as one of the operands, the REG_EQUAL note
917 won't be accurate, so use a new target. */
918 if (target == 0 || target == op0 || target == op1)
919 target = gen_reg_rtx (mode);
923 /* Do the actual arithmetic. */
924 for (i = 0; i < GET_MODE_BITSIZE (mode) / BITS_PER_WORD; i++)
926 rtx target_piece = operand_subword (target, i, 1, mode);
927 rtx x = expand_binop (word_mode, binoptab,
928 operand_subword_force (op0, i, mode),
929 operand_subword_force (op1, i, mode),
930 target_piece, unsignedp, next_methods);
935 if (target_piece != x)
936 emit_move_insn (target_piece, x);
939 insns = get_insns ();
942 if (i == GET_MODE_BITSIZE (mode) / BITS_PER_WORD)
944 if (binoptab->code != UNKNOWN)
946 = gen_rtx_fmt_ee (binoptab->code, mode,
947 copy_rtx (op0), copy_rtx (op1));
951 emit_no_conflict_block (insns, target, op0, op1, equiv_value);
956 /* Synthesize double word shifts from single word shifts. */
957 if ((binoptab == lshr_optab || binoptab == ashl_optab
958 || binoptab == ashr_optab)
960 && GET_CODE (op1) == CONST_INT
961 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
962 && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
963 && ashl_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
964 && lshr_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
966 rtx insns, inter, equiv_value;
967 rtx into_target, outof_target;
968 rtx into_input, outof_input;
969 int shift_count, left_shift, outof_word;
971 /* If TARGET is the same as one of the operands, the REG_EQUAL note
972 won't be accurate, so use a new target. */
973 if (target == 0 || target == op0 || target == op1)
974 target = gen_reg_rtx (mode);
978 shift_count = INTVAL (op1);
980 /* OUTOF_* is the word we are shifting bits away from, and
981 INTO_* is the word that we are shifting bits towards, thus
982 they differ depending on the direction of the shift and
985 left_shift = binoptab == ashl_optab;
986 outof_word = left_shift ^ ! WORDS_BIG_ENDIAN;
988 outof_target = operand_subword (target, outof_word, 1, mode);
989 into_target = operand_subword (target, 1 - outof_word, 1, mode);
991 outof_input = operand_subword_force (op0, outof_word, mode);
992 into_input = operand_subword_force (op0, 1 - outof_word, mode);
994 if (shift_count >= BITS_PER_WORD)
996 inter = expand_binop (word_mode, binoptab,
998 GEN_INT (shift_count - BITS_PER_WORD),
999 into_target, unsignedp, next_methods);
1001 if (inter != 0 && inter != into_target)
1002 emit_move_insn (into_target, inter);
1004 /* For a signed right shift, we must fill the word we are shifting
1005 out of with copies of the sign bit. Otherwise it is zeroed. */
1006 if (inter != 0 && binoptab != ashr_optab)
1007 inter = CONST0_RTX (word_mode);
1008 else if (inter != 0)
1009 inter = expand_binop (word_mode, binoptab,
1011 GEN_INT (BITS_PER_WORD - 1),
1012 outof_target, unsignedp, next_methods);
1014 if (inter != 0 && inter != outof_target)
1015 emit_move_insn (outof_target, inter);
1020 optab reverse_unsigned_shift, unsigned_shift;
1022 /* For a shift of less then BITS_PER_WORD, to compute the carry,
1023 we must do a logical shift in the opposite direction of the
1026 reverse_unsigned_shift = (left_shift ? lshr_optab : ashl_optab);
1028 /* For a shift of less than BITS_PER_WORD, to compute the word
1029 shifted towards, we need to unsigned shift the orig value of
1032 unsigned_shift = (left_shift ? ashl_optab : lshr_optab);
1034 carries = expand_binop (word_mode, reverse_unsigned_shift,
1036 GEN_INT (BITS_PER_WORD - shift_count),
1037 0, unsignedp, next_methods);
1042 inter = expand_binop (word_mode, unsigned_shift, into_input,
1043 op1, 0, unsignedp, next_methods);
1046 inter = expand_binop (word_mode, ior_optab, carries, inter,
1047 into_target, unsignedp, next_methods);
1049 if (inter != 0 && inter != into_target)
1050 emit_move_insn (into_target, inter);
1053 inter = expand_binop (word_mode, binoptab, outof_input,
1054 op1, outof_target, unsignedp, next_methods);
1056 if (inter != 0 && inter != outof_target)
1057 emit_move_insn (outof_target, inter);
1060 insns = get_insns ();
1065 if (binoptab->code != UNKNOWN)
1066 equiv_value = gen_rtx_fmt_ee (binoptab->code, mode, op0, op1);
1070 emit_no_conflict_block (insns, target, op0, op1, equiv_value);
1075 /* Synthesize double word rotates from single word shifts. */
1076 if ((binoptab == rotl_optab || binoptab == rotr_optab)
1077 && class == MODE_INT
1078 && GET_CODE (op1) == CONST_INT
1079 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1080 && ashl_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
1081 && lshr_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
1083 rtx insns, equiv_value;
1084 rtx into_target, outof_target;
1085 rtx into_input, outof_input;
1087 int shift_count, left_shift, outof_word;
1089 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1090 won't be accurate, so use a new target. */
1091 if (target == 0 || target == op0 || target == op1)
1092 target = gen_reg_rtx (mode);
1096 shift_count = INTVAL (op1);
1098 /* OUTOF_* is the word we are shifting bits away from, and
1099 INTO_* is the word that we are shifting bits towards, thus
1100 they differ depending on the direction of the shift and
1101 WORDS_BIG_ENDIAN. */
1103 left_shift = (binoptab == rotl_optab);
1104 outof_word = left_shift ^ ! WORDS_BIG_ENDIAN;
1106 outof_target = operand_subword (target, outof_word, 1, mode);
1107 into_target = operand_subword (target, 1 - outof_word, 1, mode);
1109 outof_input = operand_subword_force (op0, outof_word, mode);
1110 into_input = operand_subword_force (op0, 1 - outof_word, mode);
1112 if (shift_count == BITS_PER_WORD)
1114 /* This is just a word swap. */
1115 emit_move_insn (outof_target, into_input);
1116 emit_move_insn (into_target, outof_input);
1121 rtx into_temp1, into_temp2, outof_temp1, outof_temp2;
1122 rtx first_shift_count, second_shift_count;
1123 optab reverse_unsigned_shift, unsigned_shift;
1125 reverse_unsigned_shift = (left_shift ^ (shift_count < BITS_PER_WORD)
1126 ? lshr_optab : ashl_optab);
1128 unsigned_shift = (left_shift ^ (shift_count < BITS_PER_WORD)
1129 ? ashl_optab : lshr_optab);
1131 if (shift_count > BITS_PER_WORD)
1133 first_shift_count = GEN_INT (shift_count - BITS_PER_WORD);
1134 second_shift_count = GEN_INT (2 * BITS_PER_WORD - shift_count);
1138 first_shift_count = GEN_INT (BITS_PER_WORD - shift_count);
1139 second_shift_count = GEN_INT (shift_count);
1142 into_temp1 = expand_binop (word_mode, unsigned_shift,
1143 outof_input, first_shift_count,
1144 NULL_RTX, unsignedp, next_methods);
1145 into_temp2 = expand_binop (word_mode, reverse_unsigned_shift,
1146 into_input, second_shift_count,
1147 NULL_RTX, unsignedp, next_methods);
1149 if (into_temp1 != 0 && into_temp2 != 0)
1150 inter = expand_binop (word_mode, ior_optab, into_temp1, into_temp2,
1151 into_target, unsignedp, next_methods);
1155 if (inter != 0 && inter != into_target)
1156 emit_move_insn (into_target, inter);
1158 outof_temp1 = expand_binop (word_mode, unsigned_shift,
1159 into_input, first_shift_count,
1160 NULL_RTX, unsignedp, next_methods);
1161 outof_temp2 = expand_binop (word_mode, reverse_unsigned_shift,
1162 outof_input, second_shift_count,
1163 NULL_RTX, unsignedp, next_methods);
1165 if (inter != 0 && outof_temp1 != 0 && outof_temp2 != 0)
1166 inter = expand_binop (word_mode, ior_optab,
1167 outof_temp1, outof_temp2,
1168 outof_target, unsignedp, next_methods);
1170 if (inter != 0 && inter != outof_target)
1171 emit_move_insn (outof_target, inter);
1174 insns = get_insns ();
1179 if (binoptab->code != UNKNOWN)
1180 equiv_value = gen_rtx_fmt_ee (binoptab->code, mode, op0, op1);
1184 /* We can't make this a no conflict block if this is a word swap,
1185 because the word swap case fails if the input and output values
1186 are in the same register. */
1187 if (shift_count != BITS_PER_WORD)
1188 emit_no_conflict_block (insns, target, op0, op1, equiv_value);
1197 /* These can be done a word at a time by propagating carries. */
1198 if ((binoptab == add_optab || binoptab == sub_optab)
1199 && class == MODE_INT
1200 && GET_MODE_SIZE (mode) >= 2 * UNITS_PER_WORD
1201 && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
1204 optab otheroptab = binoptab == add_optab ? sub_optab : add_optab;
1205 const unsigned int nwords = GET_MODE_BITSIZE (mode) / BITS_PER_WORD;
1206 rtx carry_in = NULL_RTX, carry_out = NULL_RTX;
1207 rtx xop0, xop1, xtarget;
1209 /* We can handle either a 1 or -1 value for the carry. If STORE_FLAG
1210 value is one of those, use it. Otherwise, use 1 since it is the
1211 one easiest to get. */
1212 #if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1
1213 int normalizep = STORE_FLAG_VALUE;
1218 /* Prepare the operands. */
1219 xop0 = force_reg (mode, op0);
1220 xop1 = force_reg (mode, op1);
1222 xtarget = gen_reg_rtx (mode);
1224 if (target == 0 || GET_CODE (target) != REG)
1227 /* Indicate for flow that the entire target reg is being set. */
1228 if (GET_CODE (target) == REG)
1229 emit_insn (gen_rtx_CLOBBER (VOIDmode, xtarget));
1231 /* Do the actual arithmetic. */
1232 for (i = 0; i < nwords; i++)
1234 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
1235 rtx target_piece = operand_subword (xtarget, index, 1, mode);
1236 rtx op0_piece = operand_subword_force (xop0, index, mode);
1237 rtx op1_piece = operand_subword_force (xop1, index, mode);
1240 /* Main add/subtract of the input operands. */
1241 x = expand_binop (word_mode, binoptab,
1242 op0_piece, op1_piece,
1243 target_piece, unsignedp, next_methods);
1249 /* Store carry from main add/subtract. */
1250 carry_out = gen_reg_rtx (word_mode);
1251 carry_out = emit_store_flag_force (carry_out,
1252 (binoptab == add_optab
1255 word_mode, 1, normalizep);
1262 /* Add/subtract previous carry to main result. */
1263 newx = expand_binop (word_mode,
1264 normalizep == 1 ? binoptab : otheroptab,
1266 NULL_RTX, 1, next_methods);
1270 /* Get out carry from adding/subtracting carry in. */
1271 rtx carry_tmp = gen_reg_rtx (word_mode);
1272 carry_tmp = emit_store_flag_force (carry_tmp,
1273 (binoptab == add_optab
1276 word_mode, 1, normalizep);
1278 /* Logical-ior the two poss. carry together. */
1279 carry_out = expand_binop (word_mode, ior_optab,
1280 carry_out, carry_tmp,
1281 carry_out, 0, next_methods);
1285 emit_move_insn (target_piece, newx);
1288 carry_in = carry_out;
1291 if (i == GET_MODE_BITSIZE (mode) / (unsigned) BITS_PER_WORD)
1293 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
1294 || ! rtx_equal_p (target, xtarget))
1296 rtx temp = emit_move_insn (target, xtarget);
1298 set_unique_reg_note (temp,
1300 gen_rtx_fmt_ee (binoptab->code, mode,
1311 delete_insns_since (last);
1314 /* If we want to multiply two two-word values and have normal and widening
1315 multiplies of single-word values, we can do this with three smaller
1316 multiplications. Note that we do not make a REG_NO_CONFLICT block here
1317 because we are not operating on one word at a time.
1319 The multiplication proceeds as follows:
1320 _______________________
1321 [__op0_high_|__op0_low__]
1322 _______________________
1323 * [__op1_high_|__op1_low__]
1324 _______________________________________________
1325 _______________________
1326 (1) [__op0_low__*__op1_low__]
1327 _______________________
1328 (2a) [__op0_low__*__op1_high_]
1329 _______________________
1330 (2b) [__op0_high_*__op1_low__]
1331 _______________________
1332 (3) [__op0_high_*__op1_high_]
1335 This gives a 4-word result. Since we are only interested in the
1336 lower 2 words, partial result (3) and the upper words of (2a) and
1337 (2b) don't need to be calculated. Hence (2a) and (2b) can be
1338 calculated using non-widening multiplication.
1340 (1), however, needs to be calculated with an unsigned widening
1341 multiplication. If this operation is not directly supported we
1342 try using a signed widening multiplication and adjust the result.
1343 This adjustment works as follows:
1345 If both operands are positive then no adjustment is needed.
1347 If the operands have different signs, for example op0_low < 0 and
1348 op1_low >= 0, the instruction treats the most significant bit of
1349 op0_low as a sign bit instead of a bit with significance
1350 2**(BITS_PER_WORD-1), i.e. the instruction multiplies op1_low
1351 with 2**BITS_PER_WORD - op0_low, and two's complements the
1352 result. Conclusion: We need to add op1_low * 2**BITS_PER_WORD to
1355 Similarly, if both operands are negative, we need to add
1356 (op0_low + op1_low) * 2**BITS_PER_WORD.
1358 We use a trick to adjust quickly. We logically shift op0_low right
1359 (op1_low) BITS_PER_WORD-1 steps to get 0 or 1, and add this to
1360 op0_high (op1_high) before it is used to calculate 2b (2a). If no
1361 logical shift exists, we do an arithmetic right shift and subtract
1364 if (binoptab == smul_optab
1365 && class == MODE_INT
1366 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1367 && smul_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
1368 && add_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
1369 && ((umul_widen_optab->handlers[(int) mode].insn_code
1370 != CODE_FOR_nothing)
1371 || (smul_widen_optab->handlers[(int) mode].insn_code
1372 != CODE_FOR_nothing)))
1374 int low = (WORDS_BIG_ENDIAN ? 1 : 0);
1375 int high = (WORDS_BIG_ENDIAN ? 0 : 1);
1376 rtx op0_high = operand_subword_force (op0, high, mode);
1377 rtx op0_low = operand_subword_force (op0, low, mode);
1378 rtx op1_high = operand_subword_force (op1, high, mode);
1379 rtx op1_low = operand_subword_force (op1, low, mode);
1381 rtx op0_xhigh = NULL_RTX;
1382 rtx op1_xhigh = NULL_RTX;
1384 /* If the target is the same as one of the inputs, don't use it. This
1385 prevents problems with the REG_EQUAL note. */
1386 if (target == op0 || target == op1
1387 || (target != 0 && GET_CODE (target) != REG))
1390 /* Multiply the two lower words to get a double-word product.
1391 If unsigned widening multiplication is available, use that;
1392 otherwise use the signed form and compensate. */
1394 if (umul_widen_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
1396 product = expand_binop (mode, umul_widen_optab, op0_low, op1_low,
1397 target, 1, OPTAB_DIRECT);
1399 /* If we didn't succeed, delete everything we did so far. */
1401 delete_insns_since (last);
1403 op0_xhigh = op0_high, op1_xhigh = op1_high;
1407 && smul_widen_optab->handlers[(int) mode].insn_code
1408 != CODE_FOR_nothing)
1410 rtx wordm1 = GEN_INT (BITS_PER_WORD - 1);
1411 product = expand_binop (mode, smul_widen_optab, op0_low, op1_low,
1412 target, 1, OPTAB_DIRECT);
1413 op0_xhigh = expand_binop (word_mode, lshr_optab, op0_low, wordm1,
1414 NULL_RTX, 1, next_methods);
1416 op0_xhigh = expand_binop (word_mode, add_optab, op0_high,
1417 op0_xhigh, op0_xhigh, 0, next_methods);
1420 op0_xhigh = expand_binop (word_mode, ashr_optab, op0_low, wordm1,
1421 NULL_RTX, 0, next_methods);
1423 op0_xhigh = expand_binop (word_mode, sub_optab, op0_high,
1424 op0_xhigh, op0_xhigh, 0,
1428 op1_xhigh = expand_binop (word_mode, lshr_optab, op1_low, wordm1,
1429 NULL_RTX, 1, next_methods);
1431 op1_xhigh = expand_binop (word_mode, add_optab, op1_high,
1432 op1_xhigh, op1_xhigh, 0, next_methods);
1435 op1_xhigh = expand_binop (word_mode, ashr_optab, op1_low, wordm1,
1436 NULL_RTX, 0, next_methods);
1438 op1_xhigh = expand_binop (word_mode, sub_optab, op1_high,
1439 op1_xhigh, op1_xhigh, 0,
1444 /* If we have been able to directly compute the product of the
1445 low-order words of the operands and perform any required adjustments
1446 of the operands, we proceed by trying two more multiplications
1447 and then computing the appropriate sum.
1449 We have checked above that the required addition is provided.
1450 Full-word addition will normally always succeed, especially if
1451 it is provided at all, so we don't worry about its failure. The
1452 multiplication may well fail, however, so we do handle that. */
1454 if (product && op0_xhigh && op1_xhigh)
1456 rtx product_high = operand_subword (product, high, 1, mode);
1457 rtx temp = expand_binop (word_mode, binoptab, op0_low, op1_xhigh,
1458 NULL_RTX, 0, OPTAB_DIRECT);
1460 if (!REG_P (product_high))
1461 product_high = force_reg (word_mode, product_high);
1464 temp = expand_binop (word_mode, add_optab, temp, product_high,
1465 product_high, 0, next_methods);
1467 if (temp != 0 && temp != product_high)
1468 emit_move_insn (product_high, temp);
1471 temp = expand_binop (word_mode, binoptab, op1_low, op0_xhigh,
1472 NULL_RTX, 0, OPTAB_DIRECT);
1475 temp = expand_binop (word_mode, add_optab, temp,
1476 product_high, product_high,
1479 if (temp != 0 && temp != product_high)
1480 emit_move_insn (product_high, temp);
1482 emit_move_insn (operand_subword (product, high, 1, mode), product_high);
1486 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
1488 temp = emit_move_insn (product, product);
1489 set_unique_reg_note (temp,
1491 gen_rtx_fmt_ee (MULT, mode,
1500 /* If we get here, we couldn't do it for some reason even though we
1501 originally thought we could. Delete anything we've emitted in
1504 delete_insns_since (last);
1507 /* Open-code the vector operations if we have no hardware support
1509 if (class == MODE_VECTOR_INT || class == MODE_VECTOR_FLOAT)
1510 return expand_vector_binop (mode, binoptab, op0, op1, target,
1511 unsignedp, methods);
1513 /* We need to open-code the complex type operations: '+, -, * and /' */
1515 /* At this point we allow operations between two similar complex
1516 numbers, and also if one of the operands is not a complex number
1517 but rather of MODE_FLOAT or MODE_INT. However, the caller
1518 must make sure that the MODE of the non-complex operand matches
1519 the SUBMODE of the complex operand. */
1521 if (class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT)
1523 rtx real0 = 0, imag0 = 0;
1524 rtx real1 = 0, imag1 = 0;
1525 rtx realr, imagr, res;
1529 /* Find the correct mode for the real and imaginary parts. */
1530 enum machine_mode submode = GET_MODE_INNER (mode);
1532 if (submode == BLKmode)
1537 if (GET_MODE (op0) == mode)
1539 real0 = gen_realpart (submode, op0);
1540 imag0 = gen_imagpart (submode, op0);
1545 if (GET_MODE (op1) == mode)
1547 real1 = gen_realpart (submode, op1);
1548 imag1 = gen_imagpart (submode, op1);
1553 if (real0 == 0 || real1 == 0 || ! (imag0 != 0 || imag1 != 0))
1556 result = gen_reg_rtx (mode);
1557 realr = gen_realpart (submode, result);
1558 imagr = gen_imagpart (submode, result);
1560 switch (binoptab->code)
1563 /* (a+ib) + (c+id) = (a+c) + i(b+d) */
1565 /* (a+ib) - (c+id) = (a-c) + i(b-d) */
1566 res = expand_binop (submode, binoptab, real0, real1,
1567 realr, unsignedp, methods);
1571 else if (res != realr)
1572 emit_move_insn (realr, res);
1574 if (imag0 != 0 && imag1 != 0)
1575 res = expand_binop (submode, binoptab, imag0, imag1,
1576 imagr, unsignedp, methods);
1577 else if (imag0 != 0)
1579 else if (binoptab->code == MINUS)
1580 res = expand_unop (submode,
1581 binoptab == subv_optab ? negv_optab : neg_optab,
1582 imag1, imagr, unsignedp);
1588 else if (res != imagr)
1589 emit_move_insn (imagr, res);
1595 /* (a+ib) * (c+id) = (ac-bd) + i(ad+cb) */
1597 if (imag0 != 0 && imag1 != 0)
1601 /* Don't fetch these from memory more than once. */
1602 real0 = force_reg (submode, real0);
1603 real1 = force_reg (submode, real1);
1604 imag0 = force_reg (submode, imag0);
1605 imag1 = force_reg (submode, imag1);
1607 temp1 = expand_binop (submode, binoptab, real0, real1, NULL_RTX,
1608 unsignedp, methods);
1610 temp2 = expand_binop (submode, binoptab, imag0, imag1, NULL_RTX,
1611 unsignedp, methods);
1613 if (temp1 == 0 || temp2 == 0)
1618 binoptab == smulv_optab ? subv_optab : sub_optab,
1619 temp1, temp2, realr, unsignedp, methods));
1623 else if (res != realr)
1624 emit_move_insn (realr, res);
1626 temp1 = expand_binop (submode, binoptab, real0, imag1,
1627 NULL_RTX, unsignedp, methods);
1629 /* Avoid expanding redundant multiplication for the common
1630 case of squaring a complex number. */
1631 if (rtx_equal_p (real0, real1) && rtx_equal_p (imag0, imag1))
1634 temp2 = expand_binop (submode, binoptab, real1, imag0,
1635 NULL_RTX, unsignedp, methods);
1637 if (temp1 == 0 || temp2 == 0)
1642 binoptab == smulv_optab ? addv_optab : add_optab,
1643 temp1, temp2, imagr, unsignedp, methods));
1647 else if (res != imagr)
1648 emit_move_insn (imagr, res);
1654 /* Don't fetch these from memory more than once. */
1655 real0 = force_reg (submode, real0);
1656 real1 = force_reg (submode, real1);
1658 res = expand_binop (submode, binoptab, real0, real1,
1659 realr, unsignedp, methods);
1662 else if (res != realr)
1663 emit_move_insn (realr, res);
1666 res = expand_binop (submode, binoptab,
1667 real1, imag0, imagr, unsignedp, methods);
1669 res = expand_binop (submode, binoptab,
1670 real0, imag1, imagr, unsignedp, methods);
1674 else if (res != imagr)
1675 emit_move_insn (imagr, res);
1682 /* (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) */
1686 /* (a+ib) / (c+i0) = (a/c) + i(b/c) */
1688 /* Don't fetch these from memory more than once. */
1689 real1 = force_reg (submode, real1);
1691 /* Simply divide the real and imaginary parts by `c' */
1692 if (class == MODE_COMPLEX_FLOAT)
1693 res = expand_binop (submode, binoptab, real0, real1,
1694 realr, unsignedp, methods);
1696 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
1697 real0, real1, realr, unsignedp);
1701 else if (res != realr)
1702 emit_move_insn (realr, res);
1704 if (class == MODE_COMPLEX_FLOAT)
1705 res = expand_binop (submode, binoptab, imag0, real1,
1706 imagr, unsignedp, methods);
1708 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
1709 imag0, real1, imagr, unsignedp);
1713 else if (res != imagr)
1714 emit_move_insn (imagr, res);
1720 switch (flag_complex_divide_method)
1723 ok = expand_cmplxdiv_straight (real0, real1, imag0, imag1,
1724 realr, imagr, submode,
1730 ok = expand_cmplxdiv_wide (real0, real1, imag0, imag1,
1731 realr, imagr, submode,
1751 rtx equiv = gen_rtx_fmt_ee (binoptab->code, mode,
1752 copy_rtx (op0), copy_rtx (op1));
1753 emit_no_conflict_block (seq, result, op0, op1, equiv);
1758 /* It can't be open-coded in this mode.
1759 Use a library call if one is available and caller says that's ok. */
1761 if (binoptab->handlers[(int) mode].libfunc
1762 && (methods == OPTAB_LIB || methods == OPTAB_LIB_WIDEN))
1766 enum machine_mode op1_mode = mode;
1773 op1_mode = word_mode;
1774 /* Specify unsigned here,
1775 since negative shift counts are meaningless. */
1776 op1x = convert_to_mode (word_mode, op1, 1);
1779 if (GET_MODE (op0) != VOIDmode
1780 && GET_MODE (op0) != mode)
1781 op0 = convert_to_mode (mode, op0, unsignedp);
1783 /* Pass 1 for NO_QUEUE so we don't lose any increments
1784 if the libcall is cse'd or moved. */
1785 value = emit_library_call_value (binoptab->handlers[(int) mode].libfunc,
1786 NULL_RTX, LCT_CONST, mode, 2,
1787 op0, mode, op1x, op1_mode);
1789 insns = get_insns ();
1792 target = gen_reg_rtx (mode);
1793 emit_libcall_block (insns, target, value,
1794 gen_rtx_fmt_ee (binoptab->code, mode, op0, op1));
1799 delete_insns_since (last);
1801 /* It can't be done in this mode. Can we do it in a wider mode? */
1803 if (! (methods == OPTAB_WIDEN || methods == OPTAB_LIB_WIDEN
1804 || methods == OPTAB_MUST_WIDEN))
1806 /* Caller says, don't even try. */
1807 delete_insns_since (entry_last);
1811 /* Compute the value of METHODS to pass to recursive calls.
1812 Don't allow widening to be tried recursively. */
1814 methods = (methods == OPTAB_LIB_WIDEN ? OPTAB_LIB : OPTAB_DIRECT);
1816 /* Look for a wider mode of the same class for which it appears we can do
1819 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
1821 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
1822 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
1824 if ((binoptab->handlers[(int) wider_mode].insn_code
1825 != CODE_FOR_nothing)
1826 || (methods == OPTAB_LIB
1827 && binoptab->handlers[(int) wider_mode].libfunc))
1829 rtx xop0 = op0, xop1 = op1;
1832 /* For certain integer operations, we need not actually extend
1833 the narrow operands, as long as we will truncate
1834 the results to the same narrowness. */
1836 if ((binoptab == ior_optab || binoptab == and_optab
1837 || binoptab == xor_optab
1838 || binoptab == add_optab || binoptab == sub_optab
1839 || binoptab == smul_optab || binoptab == ashl_optab)
1840 && class == MODE_INT)
1843 xop0 = widen_operand (xop0, wider_mode, mode,
1844 unsignedp, no_extend);
1846 /* The second operand of a shift must always be extended. */
1847 xop1 = widen_operand (xop1, wider_mode, mode, unsignedp,
1848 no_extend && binoptab != ashl_optab);
1850 temp = expand_binop (wider_mode, binoptab, xop0, xop1, NULL_RTX,
1851 unsignedp, methods);
1854 if (class != MODE_INT)
1857 target = gen_reg_rtx (mode);
1858 convert_move (target, temp, 0);
1862 return gen_lowpart (mode, temp);
1865 delete_insns_since (last);
1870 delete_insns_since (entry_last);
1874 /* Like expand_binop, but for open-coding vectors binops. */
1877 expand_vector_binop (enum machine_mode mode, optab binoptab, rtx op0,
1878 rtx op1, rtx target, int unsignedp,
1879 enum optab_methods methods)
1881 enum machine_mode submode, tmode;
1882 int size, elts, subsize, subbitsize, i;
1883 rtx t, a, b, res, seq;
1884 enum mode_class class;
1886 class = GET_MODE_CLASS (mode);
1888 size = GET_MODE_SIZE (mode);
1889 submode = GET_MODE_INNER (mode);
1891 /* Search for the widest vector mode with the same inner mode that is
1892 still narrower than MODE and that allows to open-code this operator.
1893 Note, if we find such a mode and the handler later decides it can't
1894 do the expansion, we'll be called recursively with the narrower mode. */
1895 for (tmode = GET_CLASS_NARROWEST_MODE (class);
1896 GET_MODE_SIZE (tmode) < GET_MODE_SIZE (mode);
1897 tmode = GET_MODE_WIDER_MODE (tmode))
1899 if (GET_MODE_INNER (tmode) == GET_MODE_INNER (mode)
1900 && binoptab->handlers[(int) tmode].insn_code != CODE_FOR_nothing)
1904 switch (binoptab->code)
1909 tmode = int_mode_for_mode (mode);
1910 if (tmode != BLKmode)
1916 subsize = GET_MODE_SIZE (submode);
1917 subbitsize = GET_MODE_BITSIZE (submode);
1918 elts = size / subsize;
1920 /* If METHODS is OPTAB_DIRECT, we don't insist on the exact mode,
1921 but that we operate on more than one element at a time. */
1922 if (subsize == GET_MODE_UNIT_SIZE (mode) && methods == OPTAB_DIRECT)
1927 /* Errors can leave us with a const0_rtx as operand. */
1928 if (GET_MODE (op0) != mode)
1929 op0 = copy_to_mode_reg (mode, op0);
1930 if (GET_MODE (op1) != mode)
1931 op1 = copy_to_mode_reg (mode, op1);
1934 target = gen_reg_rtx (mode);
1936 for (i = 0; i < elts; ++i)
1938 /* If this is part of a register, and not the first item in the
1939 word, we can't store using a SUBREG - that would clobber
1941 And storing with a SUBREG is only possible for the least
1942 significant part, hence we can't do it for big endian
1943 (unless we want to permute the evaluation order. */
1944 if (GET_CODE (target) == REG
1945 && (BYTES_BIG_ENDIAN
1946 ? subsize < UNITS_PER_WORD
1947 : ((i * subsize) % UNITS_PER_WORD) != 0))
1950 t = simplify_gen_subreg (submode, target, mode, i * subsize);
1951 if (CONSTANT_P (op0))
1952 a = simplify_gen_subreg (submode, op0, mode, i * subsize);
1954 a = extract_bit_field (op0, subbitsize, i * subbitsize, unsignedp,
1955 NULL_RTX, submode, submode, size);
1956 if (CONSTANT_P (op1))
1957 b = simplify_gen_subreg (submode, op1, mode, i * subsize);
1959 b = extract_bit_field (op1, subbitsize, i * subbitsize, unsignedp,
1960 NULL_RTX, submode, submode, size);
1962 if (binoptab->code == DIV)
1964 if (class == MODE_VECTOR_FLOAT)
1965 res = expand_binop (submode, binoptab, a, b, t,
1966 unsignedp, methods);
1968 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
1969 a, b, t, unsignedp);
1972 res = expand_binop (submode, binoptab, a, b, t,
1973 unsignedp, methods);
1979 emit_move_insn (t, res);
1981 store_bit_field (target, subbitsize, i * subbitsize, submode, res,
1997 /* Like expand_unop but for open-coding vector unops. */
2000 expand_vector_unop (enum machine_mode mode, optab unoptab, rtx op0,
2001 rtx target, int unsignedp)
2003 enum machine_mode submode, tmode;
2004 int size, elts, subsize, subbitsize, i;
2007 size = GET_MODE_SIZE (mode);
2008 submode = GET_MODE_INNER (mode);
2010 /* Search for the widest vector mode with the same inner mode that is
2011 still narrower than MODE and that allows to open-code this operator.
2012 Note, if we find such a mode and the handler later decides it can't
2013 do the expansion, we'll be called recursively with the narrower mode. */
2014 for (tmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (mode));
2015 GET_MODE_SIZE (tmode) < GET_MODE_SIZE (mode);
2016 tmode = GET_MODE_WIDER_MODE (tmode))
2018 if (GET_MODE_INNER (tmode) == GET_MODE_INNER (mode)
2019 && unoptab->handlers[(int) tmode].insn_code != CODE_FOR_nothing)
2022 /* If there is no negate operation, try doing a subtract from zero. */
2023 if (unoptab == neg_optab && GET_MODE_CLASS (submode) == MODE_INT
2024 /* Avoid infinite recursion when an
2025 error has left us with the wrong mode. */
2026 && GET_MODE (op0) == mode)
2029 temp = expand_binop (mode, sub_optab, CONST0_RTX (mode), op0,
2030 target, unsignedp, OPTAB_DIRECT);
2035 if (unoptab == one_cmpl_optab)
2037 tmode = int_mode_for_mode (mode);
2038 if (tmode != BLKmode)
2042 subsize = GET_MODE_SIZE (submode);
2043 subbitsize = GET_MODE_BITSIZE (submode);
2044 elts = size / subsize;
2046 /* Errors can leave us with a const0_rtx as operand. */
2047 if (GET_MODE (op0) != mode)
2048 op0 = copy_to_mode_reg (mode, op0);
2051 target = gen_reg_rtx (mode);
2055 for (i = 0; i < elts; ++i)
2057 /* If this is part of a register, and not the first item in the
2058 word, we can't store using a SUBREG - that would clobber
2060 And storing with a SUBREG is only possible for the least
2061 significant part, hence we can't do it for big endian
2062 (unless we want to permute the evaluation order. */
2063 if (GET_CODE (target) == REG
2064 && (BYTES_BIG_ENDIAN
2065 ? subsize < UNITS_PER_WORD
2066 : ((i * subsize) % UNITS_PER_WORD) != 0))
2069 t = simplify_gen_subreg (submode, target, mode, i * subsize);
2070 if (CONSTANT_P (op0))
2071 a = simplify_gen_subreg (submode, op0, mode, i * subsize);
2073 a = extract_bit_field (op0, subbitsize, i * subbitsize, unsignedp,
2074 t, submode, submode, size);
2076 res = expand_unop (submode, unoptab, a, t, unsignedp);
2079 emit_move_insn (t, res);
2081 store_bit_field (target, subbitsize, i * subbitsize, submode, res,
2092 /* Expand a binary operator which has both signed and unsigned forms.
2093 UOPTAB is the optab for unsigned operations, and SOPTAB is for
2096 If we widen unsigned operands, we may use a signed wider operation instead
2097 of an unsigned wider operation, since the result would be the same. */
2100 sign_expand_binop (enum machine_mode mode, optab uoptab, optab soptab,
2101 rtx op0, rtx op1, rtx target, int unsignedp,
2102 enum optab_methods methods)
2105 optab direct_optab = unsignedp ? uoptab : soptab;
2106 struct optab wide_soptab;
2108 /* Do it without widening, if possible. */
2109 temp = expand_binop (mode, direct_optab, op0, op1, target,
2110 unsignedp, OPTAB_DIRECT);
2111 if (temp || methods == OPTAB_DIRECT)
2114 /* Try widening to a signed int. Make a fake signed optab that
2115 hides any signed insn for direct use. */
2116 wide_soptab = *soptab;
2117 wide_soptab.handlers[(int) mode].insn_code = CODE_FOR_nothing;
2118 wide_soptab.handlers[(int) mode].libfunc = 0;
2120 temp = expand_binop (mode, &wide_soptab, op0, op1, target,
2121 unsignedp, OPTAB_WIDEN);
2123 /* For unsigned operands, try widening to an unsigned int. */
2124 if (temp == 0 && unsignedp)
2125 temp = expand_binop (mode, uoptab, op0, op1, target,
2126 unsignedp, OPTAB_WIDEN);
2127 if (temp || methods == OPTAB_WIDEN)
2130 /* Use the right width lib call if that exists. */
2131 temp = expand_binop (mode, direct_optab, op0, op1, target, unsignedp, OPTAB_LIB);
2132 if (temp || methods == OPTAB_LIB)
2135 /* Must widen and use a lib call, use either signed or unsigned. */
2136 temp = expand_binop (mode, &wide_soptab, op0, op1, target,
2137 unsignedp, methods);
2141 return expand_binop (mode, uoptab, op0, op1, target,
2142 unsignedp, methods);
2146 /* Generate code to perform an operation specified by BINOPTAB
2147 on operands OP0 and OP1, with two results to TARG1 and TARG2.
2148 We assume that the order of the operands for the instruction
2149 is TARG0, OP0, OP1, TARG1, which would fit a pattern like
2150 [(set TARG0 (operate OP0 OP1)) (set TARG1 (operate ...))].
2152 Either TARG0 or TARG1 may be zero, but what that means is that
2153 the result is not actually wanted. We will generate it into
2154 a dummy pseudo-reg and discard it. They may not both be zero.
2156 Returns 1 if this operation can be performed; 0 if not. */
2159 expand_twoval_binop (optab binoptab, rtx op0, rtx op1, rtx targ0, rtx targ1,
2162 enum machine_mode mode = GET_MODE (targ0 ? targ0 : targ1);
2163 enum mode_class class;
2164 enum machine_mode wider_mode;
2165 rtx entry_last = get_last_insn ();
2168 class = GET_MODE_CLASS (mode);
2170 op0 = protect_from_queue (op0, 0);
2171 op1 = protect_from_queue (op1, 0);
2175 op0 = force_not_mem (op0);
2176 op1 = force_not_mem (op1);
2179 /* If we are inside an appropriately-short loop and one operand is an
2180 expensive constant, force it into a register. */
2181 if (CONSTANT_P (op0) && preserve_subexpressions_p ()
2182 && rtx_cost (op0, binoptab->code) > COSTS_N_INSNS (1))
2183 op0 = force_reg (mode, op0);
2185 if (CONSTANT_P (op1) && preserve_subexpressions_p ()
2186 && rtx_cost (op1, binoptab->code) > COSTS_N_INSNS (1))
2187 op1 = force_reg (mode, op1);
2190 targ0 = protect_from_queue (targ0, 1);
2192 targ0 = gen_reg_rtx (mode);
2194 targ1 = protect_from_queue (targ1, 1);
2196 targ1 = gen_reg_rtx (mode);
2198 /* Record where to go back to if we fail. */
2199 last = get_last_insn ();
2201 if (binoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2203 int icode = (int) binoptab->handlers[(int) mode].insn_code;
2204 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2205 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
2207 rtx xop0 = op0, xop1 = op1;
2209 /* In case the insn wants input operands in modes different from
2210 those of the actual operands, convert the operands. It would
2211 seem that we don't need to convert CONST_INTs, but we do, so
2212 that they're properly zero-extended, sign-extended or truncated
2215 if (GET_MODE (op0) != mode0 && mode0 != VOIDmode)
2216 xop0 = convert_modes (mode0,
2217 GET_MODE (op0) != VOIDmode
2222 if (GET_MODE (op1) != mode1 && mode1 != VOIDmode)
2223 xop1 = convert_modes (mode1,
2224 GET_MODE (op1) != VOIDmode
2229 /* Now, if insn doesn't accept these operands, put them into pseudos. */
2230 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0))
2231 xop0 = copy_to_mode_reg (mode0, xop0);
2233 if (! (*insn_data[icode].operand[2].predicate) (xop1, mode1))
2234 xop1 = copy_to_mode_reg (mode1, xop1);
2236 /* We could handle this, but we should always be called with a pseudo
2237 for our targets and all insns should take them as outputs. */
2238 if (! (*insn_data[icode].operand[0].predicate) (targ0, mode)
2239 || ! (*insn_data[icode].operand[3].predicate) (targ1, mode))
2242 pat = GEN_FCN (icode) (targ0, xop0, xop1, targ1);
2249 delete_insns_since (last);
2252 /* It can't be done in this mode. Can we do it in a wider mode? */
2254 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2256 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2257 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2259 if (binoptab->handlers[(int) wider_mode].insn_code
2260 != CODE_FOR_nothing)
2262 rtx t0 = gen_reg_rtx (wider_mode);
2263 rtx t1 = gen_reg_rtx (wider_mode);
2264 rtx cop0 = convert_modes (wider_mode, mode, op0, unsignedp);
2265 rtx cop1 = convert_modes (wider_mode, mode, op1, unsignedp);
2267 if (expand_twoval_binop (binoptab, cop0, cop1,
2270 convert_move (targ0, t0, unsignedp);
2271 convert_move (targ1, t1, unsignedp);
2275 delete_insns_since (last);
2280 delete_insns_since (entry_last);
2284 /* Wrapper around expand_unop which takes an rtx code to specify
2285 the operation to perform, not an optab pointer. All other
2286 arguments are the same. */
2288 expand_simple_unop (enum machine_mode mode, enum rtx_code code, rtx op0,
2289 rtx target, int unsignedp)
2291 optab unop = code_to_optab[(int) code];
2295 return expand_unop (mode, unop, op0, target, unsignedp);
2301 (clz:wide (zero_extend:wide x)) - ((width wide) - (width narrow)). */
2303 widen_clz (enum machine_mode mode, rtx op0, rtx target)
2305 enum mode_class class = GET_MODE_CLASS (mode);
2306 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2308 enum machine_mode wider_mode;
2309 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2310 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2312 if (clz_optab->handlers[(int) wider_mode].insn_code
2313 != CODE_FOR_nothing)
2315 rtx xop0, temp, last;
2317 last = get_last_insn ();
2320 target = gen_reg_rtx (mode);
2321 xop0 = widen_operand (op0, wider_mode, mode, true, false);
2322 temp = expand_unop (wider_mode, clz_optab, xop0, NULL_RTX, true);
2324 temp = expand_binop (wider_mode, sub_optab, temp,
2325 GEN_INT (GET_MODE_BITSIZE (wider_mode)
2326 - GET_MODE_BITSIZE (mode)),
2327 target, true, OPTAB_DIRECT);
2329 delete_insns_since (last);
2338 /* Try calculating (parity x) as (and (popcount x) 1), where
2339 popcount can also be done in a wider mode. */
2341 expand_parity (enum machine_mode mode, rtx op0, rtx target)
2343 enum mode_class class = GET_MODE_CLASS (mode);
2344 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2346 enum machine_mode wider_mode;
2347 for (wider_mode = mode; wider_mode != VOIDmode;
2348 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2350 if (popcount_optab->handlers[(int) wider_mode].insn_code
2351 != CODE_FOR_nothing)
2353 rtx xop0, temp, last;
2355 last = get_last_insn ();
2358 target = gen_reg_rtx (mode);
2359 xop0 = widen_operand (op0, wider_mode, mode, true, false);
2360 temp = expand_unop (wider_mode, popcount_optab, xop0, NULL_RTX,
2363 temp = expand_binop (wider_mode, and_optab, temp, const1_rtx,
2364 target, true, OPTAB_DIRECT);
2366 delete_insns_since (last);
2375 /* Generate code to perform an operation specified by UNOPTAB
2376 on operand OP0, with result having machine-mode MODE.
2378 UNSIGNEDP is for the case where we have to widen the operands
2379 to perform the operation. It says to use zero-extension.
2381 If TARGET is nonzero, the value
2382 is generated there, if it is convenient to do so.
2383 In all cases an rtx is returned for the locus of the value;
2384 this may or may not be TARGET. */
2387 expand_unop (enum machine_mode mode, optab unoptab, rtx op0, rtx target,
2390 enum mode_class class;
2391 enum machine_mode wider_mode;
2393 rtx last = get_last_insn ();
2396 class = GET_MODE_CLASS (mode);
2398 op0 = protect_from_queue (op0, 0);
2402 op0 = force_not_mem (op0);
2406 target = protect_from_queue (target, 1);
2408 if (unoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2410 int icode = (int) unoptab->handlers[(int) mode].insn_code;
2411 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2417 temp = gen_reg_rtx (mode);
2419 if (GET_MODE (xop0) != VOIDmode
2420 && GET_MODE (xop0) != mode0)
2421 xop0 = convert_to_mode (mode0, xop0, unsignedp);
2423 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
2425 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0))
2426 xop0 = copy_to_mode_reg (mode0, xop0);
2428 if (! (*insn_data[icode].operand[0].predicate) (temp, mode))
2429 temp = gen_reg_rtx (mode);
2431 pat = GEN_FCN (icode) (temp, xop0);
2434 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX
2435 && ! add_equal_note (pat, temp, unoptab->code, xop0, NULL_RTX))
2437 delete_insns_since (last);
2438 return expand_unop (mode, unoptab, op0, NULL_RTX, unsignedp);
2446 delete_insns_since (last);
2449 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2451 /* Widening clz needs special treatment. */
2452 if (unoptab == clz_optab)
2454 temp = widen_clz (mode, op0, target);
2461 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2462 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2463 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2465 if (unoptab->handlers[(int) wider_mode].insn_code != CODE_FOR_nothing)
2469 /* For certain operations, we need not actually extend
2470 the narrow operand, as long as we will truncate the
2471 results to the same narrowness. */
2473 xop0 = widen_operand (xop0, wider_mode, mode, unsignedp,
2474 (unoptab == neg_optab
2475 || unoptab == one_cmpl_optab)
2476 && class == MODE_INT);
2478 temp = expand_unop (wider_mode, unoptab, xop0, NULL_RTX,
2483 if (class != MODE_INT)
2486 target = gen_reg_rtx (mode);
2487 convert_move (target, temp, 0);
2491 return gen_lowpart (mode, temp);
2494 delete_insns_since (last);
2498 /* These can be done a word at a time. */
2499 if (unoptab == one_cmpl_optab
2500 && class == MODE_INT
2501 && GET_MODE_SIZE (mode) > UNITS_PER_WORD
2502 && unoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
2507 if (target == 0 || target == op0)
2508 target = gen_reg_rtx (mode);
2512 /* Do the actual arithmetic. */
2513 for (i = 0; i < GET_MODE_BITSIZE (mode) / BITS_PER_WORD; i++)
2515 rtx target_piece = operand_subword (target, i, 1, mode);
2516 rtx x = expand_unop (word_mode, unoptab,
2517 operand_subword_force (op0, i, mode),
2518 target_piece, unsignedp);
2520 if (target_piece != x)
2521 emit_move_insn (target_piece, x);
2524 insns = get_insns ();
2527 emit_no_conflict_block (insns, target, op0, NULL_RTX,
2528 gen_rtx_fmt_e (unoptab->code, mode,
2533 /* Open-code the complex negation operation. */
2534 else if (unoptab->code == NEG
2535 && (class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT))
2541 /* Find the correct mode for the real and imaginary parts. */
2542 enum machine_mode submode = GET_MODE_INNER (mode);
2544 if (submode == BLKmode)
2548 target = gen_reg_rtx (mode);
2552 target_piece = gen_imagpart (submode, target);
2553 x = expand_unop (submode, unoptab,
2554 gen_imagpart (submode, op0),
2555 target_piece, unsignedp);
2556 if (target_piece != x)
2557 emit_move_insn (target_piece, x);
2559 target_piece = gen_realpart (submode, target);
2560 x = expand_unop (submode, unoptab,
2561 gen_realpart (submode, op0),
2562 target_piece, unsignedp);
2563 if (target_piece != x)
2564 emit_move_insn (target_piece, x);
2569 emit_no_conflict_block (seq, target, op0, 0,
2570 gen_rtx_fmt_e (unoptab->code, mode,
2575 /* Try negating floating point values by flipping the sign bit. */
2576 if (unoptab->code == NEG && class == MODE_FLOAT
2577 && GET_MODE_BITSIZE (mode) <= 2 * HOST_BITS_PER_WIDE_INT)
2579 const struct real_format *fmt = REAL_MODE_FORMAT (mode);
2580 enum machine_mode imode = int_mode_for_mode (mode);
2581 int bitpos = (fmt != 0) ? fmt->signbit : -1;
2583 if (imode != BLKmode && bitpos >= 0 && fmt->has_signed_zero)
2585 HOST_WIDE_INT hi, lo;
2586 rtx last = get_last_insn ();
2588 /* Handle targets with different FP word orders. */
2589 if (FLOAT_WORDS_BIG_ENDIAN != WORDS_BIG_ENDIAN)
2591 int nwords = GET_MODE_BITSIZE (mode) / BITS_PER_WORD;
2592 int word = nwords - (bitpos / BITS_PER_WORD) - 1;
2593 bitpos = word * BITS_PER_WORD + bitpos % BITS_PER_WORD;
2596 if (bitpos < HOST_BITS_PER_WIDE_INT)
2599 lo = (HOST_WIDE_INT) 1 << bitpos;
2603 hi = (HOST_WIDE_INT) 1 << (bitpos - HOST_BITS_PER_WIDE_INT);
2606 temp = expand_binop (imode, xor_optab,
2607 gen_lowpart (imode, op0),
2608 immed_double_const (lo, hi, imode),
2609 NULL_RTX, 1, OPTAB_LIB_WIDEN);
2614 target = gen_reg_rtx (mode);
2615 insn = emit_move_insn (target, gen_lowpart (mode, temp));
2616 set_unique_reg_note (insn, REG_EQUAL,
2617 gen_rtx_fmt_e (NEG, mode,
2621 delete_insns_since (last);
2625 /* Try calculating parity (x) as popcount (x) % 2. */
2626 if (unoptab == parity_optab)
2628 temp = expand_parity (mode, op0, target);
2634 /* Now try a library call in this mode. */
2635 if (unoptab->handlers[(int) mode].libfunc)
2639 enum machine_mode outmode = mode;
2641 /* All of these functions return small values. Thus we choose to
2642 have them return something that isn't a double-word. */
2643 if (unoptab == ffs_optab || unoptab == clz_optab || unoptab == ctz_optab
2644 || unoptab == popcount_optab || unoptab == parity_optab)
2646 = GET_MODE (hard_libcall_value (TYPE_MODE (integer_type_node)));
2650 /* Pass 1 for NO_QUEUE so we don't lose any increments
2651 if the libcall is cse'd or moved. */
2652 value = emit_library_call_value (unoptab->handlers[(int) mode].libfunc,
2653 NULL_RTX, LCT_CONST, outmode,
2655 insns = get_insns ();
2658 target = gen_reg_rtx (outmode);
2659 emit_libcall_block (insns, target, value,
2660 gen_rtx_fmt_e (unoptab->code, mode, op0));
2665 if (class == MODE_VECTOR_FLOAT || class == MODE_VECTOR_INT)
2666 return expand_vector_unop (mode, unoptab, op0, target, unsignedp);
2668 /* It can't be done in this mode. Can we do it in a wider mode? */
2670 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2672 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2673 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2675 if ((unoptab->handlers[(int) wider_mode].insn_code
2676 != CODE_FOR_nothing)
2677 || unoptab->handlers[(int) wider_mode].libfunc)
2681 /* For certain operations, we need not actually extend
2682 the narrow operand, as long as we will truncate the
2683 results to the same narrowness. */
2685 xop0 = widen_operand (xop0, wider_mode, mode, unsignedp,
2686 (unoptab == neg_optab
2687 || unoptab == one_cmpl_optab)
2688 && class == MODE_INT);
2690 temp = expand_unop (wider_mode, unoptab, xop0, NULL_RTX,
2693 /* If we are generating clz using wider mode, adjust the
2695 if (unoptab == clz_optab && temp != 0)
2696 temp = expand_binop (wider_mode, sub_optab, temp,
2697 GEN_INT (GET_MODE_BITSIZE (wider_mode)
2698 - GET_MODE_BITSIZE (mode)),
2699 target, true, OPTAB_DIRECT);
2703 if (class != MODE_INT)
2706 target = gen_reg_rtx (mode);
2707 convert_move (target, temp, 0);
2711 return gen_lowpart (mode, temp);
2714 delete_insns_since (last);
2719 /* If there is no negate operation, try doing a subtract from zero.
2720 The US Software GOFAST library needs this. */
2721 if (unoptab->code == NEG)
2724 temp = expand_binop (mode,
2725 unoptab == negv_optab ? subv_optab : sub_optab,
2726 CONST0_RTX (mode), op0,
2727 target, unsignedp, OPTAB_LIB_WIDEN);
2735 /* Emit code to compute the absolute value of OP0, with result to
2736 TARGET if convenient. (TARGET may be 0.) The return value says
2737 where the result actually is to be found.
2739 MODE is the mode of the operand; the mode of the result is
2740 different but can be deduced from MODE.
2745 expand_abs_nojump (enum machine_mode mode, rtx op0, rtx target,
2746 int result_unsignedp)
2751 result_unsignedp = 1;
2753 /* First try to do it with a special abs instruction. */
2754 temp = expand_unop (mode, result_unsignedp ? abs_optab : absv_optab,
2759 /* For floating point modes, try clearing the sign bit. */
2760 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2761 && GET_MODE_BITSIZE (mode) <= 2 * HOST_BITS_PER_WIDE_INT)
2763 const struct real_format *fmt = REAL_MODE_FORMAT (mode);
2764 enum machine_mode imode = int_mode_for_mode (mode);
2765 int bitpos = (fmt != 0) ? fmt->signbit : -1;
2767 if (imode != BLKmode && bitpos >= 0)
2769 HOST_WIDE_INT hi, lo;
2770 rtx last = get_last_insn ();
2772 /* Handle targets with different FP word orders. */
2773 if (FLOAT_WORDS_BIG_ENDIAN != WORDS_BIG_ENDIAN)
2775 int nwords = GET_MODE_BITSIZE (mode) / BITS_PER_WORD;
2776 int word = nwords - (bitpos / BITS_PER_WORD) - 1;
2777 bitpos = word * BITS_PER_WORD + bitpos % BITS_PER_WORD;
2780 if (bitpos < HOST_BITS_PER_WIDE_INT)
2783 lo = (HOST_WIDE_INT) 1 << bitpos;
2787 hi = (HOST_WIDE_INT) 1 << (bitpos - HOST_BITS_PER_WIDE_INT);
2790 temp = expand_binop (imode, and_optab,
2791 gen_lowpart (imode, op0),
2792 immed_double_const (~lo, ~hi, imode),
2793 NULL_RTX, 1, OPTAB_LIB_WIDEN);
2798 target = gen_reg_rtx (mode);
2799 insn = emit_move_insn (target, gen_lowpart (mode, temp));
2800 set_unique_reg_note (insn, REG_EQUAL,
2801 gen_rtx_fmt_e (ABS, mode,
2805 delete_insns_since (last);
2809 /* If we have a MAX insn, we can do this as MAX (x, -x). */
2810 if (smax_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2812 rtx last = get_last_insn ();
2814 temp = expand_unop (mode, neg_optab, op0, NULL_RTX, 0);
2816 temp = expand_binop (mode, smax_optab, op0, temp, target, 0,
2822 delete_insns_since (last);
2825 /* If this machine has expensive jumps, we can do integer absolute
2826 value of X as (((signed) x >> (W-1)) ^ x) - ((signed) x >> (W-1)),
2827 where W is the width of MODE. */
2829 if (GET_MODE_CLASS (mode) == MODE_INT && BRANCH_COST >= 2)
2831 rtx extended = expand_shift (RSHIFT_EXPR, mode, op0,
2832 size_int (GET_MODE_BITSIZE (mode) - 1),
2835 temp = expand_binop (mode, xor_optab, extended, op0, target, 0,
2838 temp = expand_binop (mode, result_unsignedp ? sub_optab : subv_optab,
2839 temp, extended, target, 0, OPTAB_LIB_WIDEN);
2849 expand_abs (enum machine_mode mode, rtx op0, rtx target,
2850 int result_unsignedp, int safe)
2855 result_unsignedp = 1;
2857 temp = expand_abs_nojump (mode, op0, target, result_unsignedp);
2861 /* If that does not win, use conditional jump and negate. */
2863 /* It is safe to use the target if it is the same
2864 as the source if this is also a pseudo register */
2865 if (op0 == target && GET_CODE (op0) == REG
2866 && REGNO (op0) >= FIRST_PSEUDO_REGISTER)
2869 op1 = gen_label_rtx ();
2870 if (target == 0 || ! safe
2871 || GET_MODE (target) != mode
2872 || (GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
2873 || (GET_CODE (target) == REG
2874 && REGNO (target) < FIRST_PSEUDO_REGISTER))
2875 target = gen_reg_rtx (mode);
2877 emit_move_insn (target, op0);
2880 /* If this mode is an integer too wide to compare properly,
2881 compare word by word. Rely on CSE to optimize constant cases. */
2882 if (GET_MODE_CLASS (mode) == MODE_INT
2883 && ! can_compare_p (GE, mode, ccp_jump))
2884 do_jump_by_parts_greater_rtx (mode, 0, target, const0_rtx,
2887 do_compare_rtx_and_jump (target, CONST0_RTX (mode), GE, 0, mode,
2888 NULL_RTX, NULL_RTX, op1);
2890 op0 = expand_unop (mode, result_unsignedp ? neg_optab : negv_optab,
2893 emit_move_insn (target, op0);
2899 /* Emit code to compute the absolute value of OP0, with result to
2900 TARGET if convenient. (TARGET may be 0.) The return value says
2901 where the result actually is to be found.
2903 MODE is the mode of the operand; the mode of the result is
2904 different but can be deduced from MODE.
2906 UNSIGNEDP is relevant for complex integer modes. */
2909 expand_complex_abs (enum machine_mode mode, rtx op0, rtx target,
2912 enum mode_class class = GET_MODE_CLASS (mode);
2913 enum machine_mode wider_mode;
2915 rtx entry_last = get_last_insn ();
2918 optab this_abs_optab;
2920 /* Find the correct mode for the real and imaginary parts. */
2921 enum machine_mode submode = GET_MODE_INNER (mode);
2923 if (submode == BLKmode)
2926 op0 = protect_from_queue (op0, 0);
2930 op0 = force_not_mem (op0);
2933 last = get_last_insn ();
2936 target = protect_from_queue (target, 1);
2938 this_abs_optab = ! unsignedp && flag_trapv
2939 && (GET_MODE_CLASS(mode) == MODE_INT)
2940 ? absv_optab : abs_optab;
2942 if (this_abs_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2944 int icode = (int) this_abs_optab->handlers[(int) mode].insn_code;
2945 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2951 temp = gen_reg_rtx (submode);
2953 if (GET_MODE (xop0) != VOIDmode
2954 && GET_MODE (xop0) != mode0)
2955 xop0 = convert_to_mode (mode0, xop0, unsignedp);
2957 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
2959 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0))
2960 xop0 = copy_to_mode_reg (mode0, xop0);
2962 if (! (*insn_data[icode].operand[0].predicate) (temp, submode))
2963 temp = gen_reg_rtx (submode);
2965 pat = GEN_FCN (icode) (temp, xop0);
2968 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX
2969 && ! add_equal_note (pat, temp, this_abs_optab->code, xop0,
2972 delete_insns_since (last);
2973 return expand_unop (mode, this_abs_optab, op0, NULL_RTX,
2982 delete_insns_since (last);
2985 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2987 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2988 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2990 if (this_abs_optab->handlers[(int) wider_mode].insn_code
2991 != CODE_FOR_nothing)
2995 xop0 = convert_modes (wider_mode, mode, xop0, unsignedp);
2996 temp = expand_complex_abs (wider_mode, xop0, NULL_RTX, unsignedp);
3000 if (class != MODE_COMPLEX_INT)
3003 target = gen_reg_rtx (submode);
3004 convert_move (target, temp, 0);
3008 return gen_lowpart (submode, temp);
3011 delete_insns_since (last);
3015 /* Open-code the complex absolute-value operation
3016 if we can open-code sqrt. Otherwise it's not worth while. */
3017 if (sqrt_optab->handlers[(int) submode].insn_code != CODE_FOR_nothing
3020 rtx real, imag, total;
3022 real = gen_realpart (submode, op0);
3023 imag = gen_imagpart (submode, op0);
3025 /* Square both parts. */
3026 real = expand_mult (submode, real, real, NULL_RTX, 0);
3027 imag = expand_mult (submode, imag, imag, NULL_RTX, 0);
3029 /* Sum the parts. */
3030 total = expand_binop (submode, add_optab, real, imag, NULL_RTX,
3031 0, OPTAB_LIB_WIDEN);
3033 /* Get sqrt in TARGET. Set TARGET to where the result is. */
3034 target = expand_unop (submode, sqrt_optab, total, target, 0);
3036 delete_insns_since (last);
3041 /* Now try a library call in this mode. */
3042 if (this_abs_optab->handlers[(int) mode].libfunc)
3049 /* Pass 1 for NO_QUEUE so we don't lose any increments
3050 if the libcall is cse'd or moved. */
3051 value = emit_library_call_value (abs_optab->handlers[(int) mode].libfunc,
3052 NULL_RTX, LCT_CONST, submode, 1, op0, mode);
3053 insns = get_insns ();
3056 target = gen_reg_rtx (submode);
3057 emit_libcall_block (insns, target, value,
3058 gen_rtx_fmt_e (this_abs_optab->code, mode, op0));
3063 /* It can't be done in this mode. Can we do it in a wider mode? */
3065 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
3066 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
3068 if ((this_abs_optab->handlers[(int) wider_mode].insn_code
3069 != CODE_FOR_nothing)
3070 || this_abs_optab->handlers[(int) wider_mode].libfunc)
3074 xop0 = convert_modes (wider_mode, mode, xop0, unsignedp);
3076 temp = expand_complex_abs (wider_mode, xop0, NULL_RTX, unsignedp);
3080 if (class != MODE_COMPLEX_INT)
3083 target = gen_reg_rtx (submode);
3084 convert_move (target, temp, 0);
3088 return gen_lowpart (submode, temp);
3091 delete_insns_since (last);
3095 delete_insns_since (entry_last);
3099 /* Generate an instruction whose insn-code is INSN_CODE,
3100 with two operands: an output TARGET and an input OP0.
3101 TARGET *must* be nonzero, and the output is always stored there.
3102 CODE is an rtx code such that (CODE OP0) is an rtx that describes
3103 the value that is stored into TARGET. */
3106 emit_unop_insn (int icode, rtx target, rtx op0, enum rtx_code code)
3109 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
3112 temp = target = protect_from_queue (target, 1);
3114 op0 = protect_from_queue (op0, 0);
3116 /* Sign and zero extension from memory is often done specially on
3117 RISC machines, so forcing into a register here can pessimize
3119 if (flag_force_mem && code != SIGN_EXTEND && code != ZERO_EXTEND)
3120 op0 = force_not_mem (op0);
3122 /* Now, if insn does not accept our operands, put them into pseudos. */
3124 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
3125 op0 = copy_to_mode_reg (mode0, op0);
3127 if (! (*insn_data[icode].operand[0].predicate) (temp, GET_MODE (temp))
3128 || (flag_force_mem && GET_CODE (temp) == MEM))
3129 temp = gen_reg_rtx (GET_MODE (temp));
3131 pat = GEN_FCN (icode) (temp, op0);
3133 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX && code != UNKNOWN)
3134 add_equal_note (pat, temp, code, op0, NULL_RTX);
3139 emit_move_insn (target, temp);
3142 /* Emit code to perform a series of operations on a multi-word quantity, one
3145 Such a block is preceded by a CLOBBER of the output, consists of multiple
3146 insns, each setting one word of the output, and followed by a SET copying
3147 the output to itself.
3149 Each of the insns setting words of the output receives a REG_NO_CONFLICT
3150 note indicating that it doesn't conflict with the (also multi-word)
3151 inputs. The entire block is surrounded by REG_LIBCALL and REG_RETVAL
3154 INSNS is a block of code generated to perform the operation, not including
3155 the CLOBBER and final copy. All insns that compute intermediate values
3156 are first emitted, followed by the block as described above.
3158 TARGET, OP0, and OP1 are the output and inputs of the operations,
3159 respectively. OP1 may be zero for a unary operation.
3161 EQUIV, if nonzero, is an expression to be placed into a REG_EQUAL note
3164 If TARGET is not a register, INSNS is simply emitted with no special
3165 processing. Likewise if anything in INSNS is not an INSN or if
3166 there is a libcall block inside INSNS.
3168 The final insn emitted is returned. */
3171 emit_no_conflict_block (rtx insns, rtx target, rtx op0, rtx op1, rtx equiv)
3173 rtx prev, next, first, last, insn;
3175 if (GET_CODE (target) != REG || reload_in_progress)
3176 return emit_insn (insns);
3178 for (insn = insns; insn; insn = NEXT_INSN (insn))
3179 if (GET_CODE (insn) != INSN
3180 || find_reg_note (insn, REG_LIBCALL, NULL_RTX))
3181 return emit_insn (insns);
3183 /* First emit all insns that do not store into words of the output and remove
3184 these from the list. */
3185 for (insn = insns; insn; insn = next)
3190 next = NEXT_INSN (insn);
3192 /* Some ports (cris) create a libcall regions at their own. We must
3193 avoid any potential nesting of LIBCALLs. */
3194 if ((note = find_reg_note (insn, REG_LIBCALL, NULL)) != NULL)
3195 remove_note (insn, note);
3196 if ((note = find_reg_note (insn, REG_RETVAL, NULL)) != NULL)
3197 remove_note (insn, note);
3199 if (GET_CODE (PATTERN (insn)) == SET || GET_CODE (PATTERN (insn)) == USE
3200 || GET_CODE (PATTERN (insn)) == CLOBBER)
3201 set = PATTERN (insn);
3202 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
3204 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
3205 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
3207 set = XVECEXP (PATTERN (insn), 0, i);
3215 if (! reg_overlap_mentioned_p (target, SET_DEST (set)))
3217 if (PREV_INSN (insn))
3218 NEXT_INSN (PREV_INSN (insn)) = next;
3223 PREV_INSN (next) = PREV_INSN (insn);
3229 prev = get_last_insn ();
3231 /* Now write the CLOBBER of the output, followed by the setting of each
3232 of the words, followed by the final copy. */
3233 if (target != op0 && target != op1)
3234 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
3236 for (insn = insns; insn; insn = next)
3238 next = NEXT_INSN (insn);
3241 if (op1 && GET_CODE (op1) == REG)
3242 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT, op1,
3245 if (op0 && GET_CODE (op0) == REG)
3246 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT, op0,
3250 if (mov_optab->handlers[(int) GET_MODE (target)].insn_code
3251 != CODE_FOR_nothing)
3253 last = emit_move_insn (target, target);
3255 set_unique_reg_note (last, REG_EQUAL, equiv);
3259 last = get_last_insn ();
3261 /* Remove any existing REG_EQUAL note from "last", or else it will
3262 be mistaken for a note referring to the full contents of the
3263 alleged libcall value when found together with the REG_RETVAL
3264 note added below. An existing note can come from an insn
3265 expansion at "last". */
3266 remove_note (last, find_reg_note (last, REG_EQUAL, NULL_RTX));
3270 first = get_insns ();
3272 first = NEXT_INSN (prev);
3274 /* Encapsulate the block so it gets manipulated as a unit. */
3275 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3277 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, REG_NOTES (last));
3282 /* Emit code to make a call to a constant function or a library call.
3284 INSNS is a list containing all insns emitted in the call.
3285 These insns leave the result in RESULT. Our block is to copy RESULT
3286 to TARGET, which is logically equivalent to EQUIV.
3288 We first emit any insns that set a pseudo on the assumption that these are
3289 loading constants into registers; doing so allows them to be safely cse'ed
3290 between blocks. Then we emit all the other insns in the block, followed by
3291 an insn to move RESULT to TARGET. This last insn will have a REQ_EQUAL
3292 note with an operand of EQUIV.
3294 Moving assignments to pseudos outside of the block is done to improve
3295 the generated code, but is not required to generate correct code,
3296 hence being unable to move an assignment is not grounds for not making
3297 a libcall block. There are two reasons why it is safe to leave these
3298 insns inside the block: First, we know that these pseudos cannot be
3299 used in generated RTL outside the block since they are created for
3300 temporary purposes within the block. Second, CSE will not record the
3301 values of anything set inside a libcall block, so we know they must
3302 be dead at the end of the block.
3304 Except for the first group of insns (the ones setting pseudos), the
3305 block is delimited by REG_RETVAL and REG_LIBCALL notes. */
3308 emit_libcall_block (rtx insns, rtx target, rtx result, rtx equiv)
3310 rtx final_dest = target;
3311 rtx prev, next, first, last, insn;
3313 /* If this is a reg with REG_USERVAR_P set, then it could possibly turn
3314 into a MEM later. Protect the libcall block from this change. */
3315 if (! REG_P (target) || REG_USERVAR_P (target))
3316 target = gen_reg_rtx (GET_MODE (target));
3318 /* If we're using non-call exceptions, a libcall corresponding to an
3319 operation that may trap may also trap. */
3320 if (flag_non_call_exceptions && may_trap_p (equiv))
3322 for (insn = insns; insn; insn = NEXT_INSN (insn))
3323 if (GET_CODE (insn) == CALL_INSN)
3325 rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
3327 if (note != 0 && INTVAL (XEXP (note, 0)) <= 0)
3328 remove_note (insn, note);
3332 /* look for any CALL_INSNs in this sequence, and attach a REG_EH_REGION
3333 reg note to indicate that this call cannot throw or execute a nonlocal
3334 goto (unless there is already a REG_EH_REGION note, in which case
3336 for (insn = insns; insn; insn = NEXT_INSN (insn))
3337 if (GET_CODE (insn) == CALL_INSN)
3339 rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
3342 XEXP (note, 0) = constm1_rtx;
3344 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, constm1_rtx,
3348 /* First emit all insns that set pseudos. Remove them from the list as
3349 we go. Avoid insns that set pseudos which were referenced in previous
3350 insns. These can be generated by move_by_pieces, for example,
3351 to update an address. Similarly, avoid insns that reference things
3352 set in previous insns. */
3354 for (insn = insns; insn; insn = next)
3356 rtx set = single_set (insn);
3359 /* Some ports (cris) create a libcall regions at their own. We must
3360 avoid any potential nesting of LIBCALLs. */
3361 if ((note = find_reg_note (insn, REG_LIBCALL, NULL)) != NULL)
3362 remove_note (insn, note);
3363 if ((note = find_reg_note (insn, REG_RETVAL, NULL)) != NULL)
3364 remove_note (insn, note);
3366 next = NEXT_INSN (insn);
3368 if (set != 0 && GET_CODE (SET_DEST (set)) == REG
3369 && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
3371 || ((! INSN_P(insns)
3372 || ! reg_mentioned_p (SET_DEST (set), PATTERN (insns)))
3373 && ! reg_used_between_p (SET_DEST (set), insns, insn)
3374 && ! modified_in_p (SET_SRC (set), insns)
3375 && ! modified_between_p (SET_SRC (set), insns, insn))))
3377 if (PREV_INSN (insn))
3378 NEXT_INSN (PREV_INSN (insn)) = next;
3383 PREV_INSN (next) = PREV_INSN (insn);
3388 /* Some ports use a loop to copy large arguments onto the stack.
3389 Don't move anything outside such a loop. */
3390 if (GET_CODE (insn) == CODE_LABEL)
3394 prev = get_last_insn ();
3396 /* Write the remaining insns followed by the final copy. */
3398 for (insn = insns; insn; insn = next)
3400 next = NEXT_INSN (insn);
3405 last = emit_move_insn (target, result);
3406 if (mov_optab->handlers[(int) GET_MODE (target)].insn_code
3407 != CODE_FOR_nothing)
3408 set_unique_reg_note (last, REG_EQUAL, copy_rtx (equiv));
3411 /* Remove any existing REG_EQUAL note from "last", or else it will
3412 be mistaken for a note referring to the full contents of the
3413 libcall value when found together with the REG_RETVAL note added
3414 below. An existing note can come from an insn expansion at
3416 remove_note (last, find_reg_note (last, REG_EQUAL, NULL_RTX));
3419 if (final_dest != target)
3420 emit_move_insn (final_dest, target);
3423 first = get_insns ();
3425 first = NEXT_INSN (prev);
3427 /* Encapsulate the block so it gets manipulated as a unit. */
3428 if (!flag_non_call_exceptions || !may_trap_p (equiv))
3430 /* We can't attach the REG_LIBCALL and REG_RETVAL notes
3431 when the encapsulated region would not be in one basic block,
3432 i.e. when there is a control_flow_insn_p insn between FIRST and LAST.
3434 bool attach_libcall_retval_notes = true;
3435 next = NEXT_INSN (last);
3436 for (insn = first; insn != next; insn = NEXT_INSN (insn))
3437 if (control_flow_insn_p (insn))
3439 attach_libcall_retval_notes = false;
3443 if (attach_libcall_retval_notes)
3445 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3447 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
3453 /* Generate code to store zero in X. */
3456 emit_clr_insn (rtx x)
3458 emit_move_insn (x, const0_rtx);
3461 /* Generate code to store 1 in X
3462 assuming it contains zero beforehand. */
3465 emit_0_to_1_insn (rtx x)
3467 emit_move_insn (x, const1_rtx);
3470 /* Nonzero if we can perform a comparison of mode MODE straightforwardly.
3471 PURPOSE describes how this comparison will be used. CODE is the rtx
3472 comparison code we will be using.
3474 ??? Actually, CODE is slightly weaker than that. A target is still
3475 required to implement all of the normal bcc operations, but not
3476 required to implement all (or any) of the unordered bcc operations. */
3479 can_compare_p (enum rtx_code code, enum machine_mode mode,
3480 enum can_compare_purpose purpose)
3484 if (cmp_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3486 if (purpose == ccp_jump)
3487 return bcc_gen_fctn[(int) code] != NULL;
3488 else if (purpose == ccp_store_flag)
3489 return setcc_gen_code[(int) code] != CODE_FOR_nothing;
3491 /* There's only one cmov entry point, and it's allowed to fail. */
3494 if (purpose == ccp_jump
3495 && cbranch_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3497 if (purpose == ccp_cmov
3498 && cmov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3500 if (purpose == ccp_store_flag
3501 && cstore_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3504 mode = GET_MODE_WIDER_MODE (mode);
3506 while (mode != VOIDmode);
3511 /* This function is called when we are going to emit a compare instruction that
3512 compares the values found in *PX and *PY, using the rtl operator COMPARISON.
3514 *PMODE is the mode of the inputs (in case they are const_int).
3515 *PUNSIGNEDP nonzero says that the operands are unsigned;
3516 this matters if they need to be widened.
3518 If they have mode BLKmode, then SIZE specifies the size of both operands.
3520 This function performs all the setup necessary so that the caller only has
3521 to emit a single comparison insn. This setup can involve doing a BLKmode
3522 comparison or emitting a library call to perform the comparison if no insn
3523 is available to handle it.
3524 The values which are passed in through pointers can be modified; the caller
3525 should perform the comparison on the modified values. */
3528 prepare_cmp_insn (rtx *px, rtx *py, enum rtx_code *pcomparison, rtx size,
3529 enum machine_mode *pmode, int *punsignedp,
3530 enum can_compare_purpose purpose)
3532 enum machine_mode mode = *pmode;
3533 rtx x = *px, y = *py;
3534 int unsignedp = *punsignedp;
3535 enum mode_class class;
3537 class = GET_MODE_CLASS (mode);
3539 /* They could both be VOIDmode if both args are immediate constants,
3540 but we should fold that at an earlier stage.
3541 With no special code here, this will call abort,
3542 reminding the programmer to implement such folding. */
3544 if (mode != BLKmode && flag_force_mem)
3546 /* Load duplicate non-volatile operands once. */
3547 if (rtx_equal_p (x, y) && ! volatile_refs_p (x))
3549 x = force_not_mem (x);
3554 x = force_not_mem (x);
3555 y = force_not_mem (y);
3559 /* If we are inside an appropriately-short loop and one operand is an
3560 expensive constant, force it into a register. */
3561 if (CONSTANT_P (x) && preserve_subexpressions_p ()
3562 && rtx_cost (x, COMPARE) > COSTS_N_INSNS (1))
3563 x = force_reg (mode, x);
3565 if (CONSTANT_P (y) && preserve_subexpressions_p ()
3566 && rtx_cost (y, COMPARE) > COSTS_N_INSNS (1))
3567 y = force_reg (mode, y);
3570 /* Abort if we have a non-canonical comparison. The RTL documentation
3571 states that canonical comparisons are required only for targets which
3573 if (CONSTANT_P (x) && ! CONSTANT_P (y))
3577 /* Don't let both operands fail to indicate the mode. */
3578 if (GET_MODE (x) == VOIDmode && GET_MODE (y) == VOIDmode)
3579 x = force_reg (mode, x);
3581 /* Handle all BLKmode compares. */
3583 if (mode == BLKmode)
3585 enum machine_mode cmp_mode, result_mode;
3586 enum insn_code cmp_code;
3591 = GEN_INT (MIN (MEM_ALIGN (x), MEM_ALIGN (y)) / BITS_PER_UNIT);
3597 x = protect_from_queue (x, 0);
3598 y = protect_from_queue (y, 0);
3599 size = protect_from_queue (size, 0);
3601 /* Try to use a memory block compare insn - either cmpstr
3602 or cmpmem will do. */
3603 for (cmp_mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3604 cmp_mode != VOIDmode;
3605 cmp_mode = GET_MODE_WIDER_MODE (cmp_mode))
3607 cmp_code = cmpmem_optab[cmp_mode];
3608 if (cmp_code == CODE_FOR_nothing)
3609 cmp_code = cmpstr_optab[cmp_mode];
3610 if (cmp_code == CODE_FOR_nothing)
3613 /* Must make sure the size fits the insn's mode. */
3614 if ((GET_CODE (size) == CONST_INT
3615 && INTVAL (size) >= (1 << GET_MODE_BITSIZE (cmp_mode)))
3616 || (GET_MODE_BITSIZE (GET_MODE (size))
3617 > GET_MODE_BITSIZE (cmp_mode)))
3620 result_mode = insn_data[cmp_code].operand[0].mode;
3621 result = gen_reg_rtx (result_mode);
3622 size = convert_to_mode (cmp_mode, size, 1);
3623 emit_insn (GEN_FCN (cmp_code) (result, x, y, size, opalign));
3627 *pmode = result_mode;
3631 /* Otherwise call a library function, memcmp if we've got it,
3633 #ifdef TARGET_MEM_FUNCTIONS
3634 libfunc = memcmp_libfunc;
3635 length_type = sizetype;
3637 libfunc = bcmp_libfunc;
3638 length_type = integer_type_node;
3640 result_mode = TYPE_MODE (integer_type_node);
3641 cmp_mode = TYPE_MODE (length_type);
3642 size = convert_to_mode (TYPE_MODE (length_type), size,
3643 TREE_UNSIGNED (length_type));
3645 result = emit_library_call_value (libfunc, 0, LCT_PURE_MAKE_BLOCK,
3652 *pmode = result_mode;
3656 /* Don't allow operands to the compare to trap, as that can put the
3657 compare and branch in different basic blocks. */
3658 if (flag_non_call_exceptions)
3661 x = force_reg (mode, x);
3663 y = force_reg (mode, y);
3668 if (can_compare_p (*pcomparison, mode, purpose))
3671 /* Handle a lib call just for the mode we are using. */
3673 if (cmp_optab->handlers[(int) mode].libfunc && class != MODE_FLOAT)
3675 rtx libfunc = cmp_optab->handlers[(int) mode].libfunc;
3678 /* If we want unsigned, and this mode has a distinct unsigned
3679 comparison routine, use that. */
3680 if (unsignedp && ucmp_optab->handlers[(int) mode].libfunc)
3681 libfunc = ucmp_optab->handlers[(int) mode].libfunc;
3683 result = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST_MAKE_BLOCK,
3684 word_mode, 2, x, mode, y, mode);
3686 /* Integer comparison returns a result that must be compared against 1,
3687 so that even if we do an unsigned compare afterward,
3688 there is still a value that can represent the result "less than". */
3695 if (class == MODE_FLOAT)
3696 prepare_float_lib_cmp (px, py, pcomparison, pmode, punsignedp);
3702 /* Before emitting an insn with code ICODE, make sure that X, which is going
3703 to be used for operand OPNUM of the insn, is converted from mode MODE to
3704 WIDER_MODE (UNSIGNEDP determines whether it is an unsigned conversion), and
3705 that it is accepted by the operand predicate. Return the new value. */
3708 prepare_operand (int icode, rtx x, int opnum, enum machine_mode mode,
3709 enum machine_mode wider_mode, int unsignedp)
3711 x = protect_from_queue (x, 0);
3713 if (mode != wider_mode)
3714 x = convert_modes (wider_mode, mode, x, unsignedp);
3716 if (! (*insn_data[icode].operand[opnum].predicate)
3717 (x, insn_data[icode].operand[opnum].mode))
3721 x = copy_to_mode_reg (insn_data[icode].operand[opnum].mode, x);
3727 /* Subroutine of emit_cmp_and_jump_insns; this function is called when we know
3728 we can do the comparison.
3729 The arguments are the same as for emit_cmp_and_jump_insns; but LABEL may
3730 be NULL_RTX which indicates that only a comparison is to be generated. */
3733 emit_cmp_and_jump_insn_1 (rtx x, rtx y, enum machine_mode mode,
3734 enum rtx_code comparison, int unsignedp, rtx label)
3736 rtx test = gen_rtx_fmt_ee (comparison, mode, x, y);
3737 enum mode_class class = GET_MODE_CLASS (mode);
3738 enum machine_mode wider_mode = mode;
3740 /* Try combined insns first. */
3743 enum insn_code icode;
3744 PUT_MODE (test, wider_mode);
3748 icode = cbranch_optab->handlers[(int) wider_mode].insn_code;
3750 if (icode != CODE_FOR_nothing
3751 && (*insn_data[icode].operand[0].predicate) (test, wider_mode))
3753 x = prepare_operand (icode, x, 1, mode, wider_mode, unsignedp);
3754 y = prepare_operand (icode, y, 2, mode, wider_mode, unsignedp);
3755 emit_jump_insn (GEN_FCN (icode) (test, x, y, label));
3760 /* Handle some compares against zero. */
3761 icode = (int) tst_optab->handlers[(int) wider_mode].insn_code;
3762 if (y == CONST0_RTX (mode) && icode != CODE_FOR_nothing)
3764 x = prepare_operand (icode, x, 0, mode, wider_mode, unsignedp);
3765 emit_insn (GEN_FCN (icode) (x));
3767 emit_jump_insn ((*bcc_gen_fctn[(int) comparison]) (label));
3771 /* Handle compares for which there is a directly suitable insn. */
3773 icode = (int) cmp_optab->handlers[(int) wider_mode].insn_code;
3774 if (icode != CODE_FOR_nothing)
3776 x = prepare_operand (icode, x, 0, mode, wider_mode, unsignedp);
3777 y = prepare_operand (icode, y, 1, mode, wider_mode, unsignedp);
3778 emit_insn (GEN_FCN (icode) (x, y));
3780 emit_jump_insn ((*bcc_gen_fctn[(int) comparison]) (label));
3784 if (class != MODE_INT && class != MODE_FLOAT
3785 && class != MODE_COMPLEX_FLOAT)
3788 wider_mode = GET_MODE_WIDER_MODE (wider_mode);
3790 while (wider_mode != VOIDmode);
3795 /* Generate code to compare X with Y so that the condition codes are
3796 set and to jump to LABEL if the condition is true. If X is a
3797 constant and Y is not a constant, then the comparison is swapped to
3798 ensure that the comparison RTL has the canonical form.
3800 UNSIGNEDP nonzero says that X and Y are unsigned; this matters if they
3801 need to be widened by emit_cmp_insn. UNSIGNEDP is also used to select
3802 the proper branch condition code.
3804 If X and Y have mode BLKmode, then SIZE specifies the size of both X and Y.
3806 MODE is the mode of the inputs (in case they are const_int).
3808 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). It will
3809 be passed unchanged to emit_cmp_insn, then potentially converted into an
3810 unsigned variant based on UNSIGNEDP to select a proper jump instruction. */
3813 emit_cmp_and_jump_insns (rtx x, rtx y, enum rtx_code comparison, rtx size,
3814 enum machine_mode mode, int unsignedp, rtx label)
3816 rtx op0 = x, op1 = y;
3818 /* Swap operands and condition to ensure canonical RTL. */
3819 if (swap_commutative_operands_p (x, y))
3821 /* If we're not emitting a branch, this means some caller
3827 comparison = swap_condition (comparison);
3831 /* If OP0 is still a constant, then both X and Y must be constants. Force
3832 X into a register to avoid aborting in emit_cmp_insn due to non-canonical
3834 if (CONSTANT_P (op0))
3835 op0 = force_reg (mode, op0);
3840 comparison = unsigned_condition (comparison);
3842 prepare_cmp_insn (&op0, &op1, &comparison, size, &mode, &unsignedp,
3844 emit_cmp_and_jump_insn_1 (op0, op1, mode, comparison, unsignedp, label);
3847 /* Like emit_cmp_and_jump_insns, but generate only the comparison. */
3850 emit_cmp_insn (rtx x, rtx y, enum rtx_code comparison, rtx size,
3851 enum machine_mode mode, int unsignedp)
3853 emit_cmp_and_jump_insns (x, y, comparison, size, mode, unsignedp, 0);
3856 /* Emit a library call comparison between floating point X and Y.
3857 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). */
3860 prepare_float_lib_cmp (rtx *px, rtx *py, enum rtx_code *pcomparison,
3861 enum machine_mode *pmode, int *punsignedp)
3863 enum rtx_code comparison = *pcomparison;
3864 enum rtx_code swapped = swap_condition (comparison);
3865 rtx x = protect_from_queue (*px, 0);
3866 rtx y = protect_from_queue (*py, 0);
3867 enum machine_mode orig_mode = GET_MODE (x);
3868 enum machine_mode mode;
3869 rtx value, target, insns, equiv;
3872 for (mode = orig_mode; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
3874 if ((libfunc = code_to_optab[comparison]->handlers[mode].libfunc))
3877 if ((libfunc = code_to_optab[swapped]->handlers[mode].libfunc))
3880 tmp = x; x = y; y = tmp;
3881 comparison = swapped;
3886 if (mode == VOIDmode)
3889 if (mode != orig_mode)
3891 x = convert_to_mode (mode, x, 0);
3892 y = convert_to_mode (mode, y, 0);
3895 /* Attach a REG_EQUAL note describing the semantics of the libcall to
3896 the RTL. The allows the RTL optimizers to delete the libcall if the
3897 condition can be determined at compile-time. */
3898 if (comparison == UNORDERED)
3900 rtx temp = simplify_gen_relational (NE, word_mode, mode, x, x);
3901 equiv = simplify_gen_relational (NE, word_mode, mode, y, y);
3902 equiv = simplify_gen_ternary (IF_THEN_ELSE, word_mode, word_mode,
3903 temp, const_true_rtx, equiv);
3907 equiv = simplify_gen_relational (comparison, word_mode, mode, x, y);
3908 if (! FLOAT_LIB_COMPARE_RETURNS_BOOL (mode, comparison))
3910 rtx true_rtx, false_rtx;
3915 true_rtx = const0_rtx;
3916 false_rtx = const_true_rtx;
3920 true_rtx = const_true_rtx;
3921 false_rtx = const0_rtx;
3925 true_rtx = const1_rtx;
3926 false_rtx = const0_rtx;
3930 true_rtx = const0_rtx;
3931 false_rtx = constm1_rtx;
3935 true_rtx = constm1_rtx;
3936 false_rtx = const0_rtx;
3940 true_rtx = const0_rtx;
3941 false_rtx = const1_rtx;
3947 equiv = simplify_gen_ternary (IF_THEN_ELSE, word_mode, word_mode,
3948 equiv, true_rtx, false_rtx);
3953 value = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST,
3954 word_mode, 2, x, mode, y, mode);
3955 insns = get_insns ();
3958 target = gen_reg_rtx (word_mode);
3959 emit_libcall_block (insns, target, value, equiv);
3962 if (comparison == UNORDERED
3963 || FLOAT_LIB_COMPARE_RETURNS_BOOL (mode, comparison))
3969 *pcomparison = comparison;
3973 /* Generate code to indirectly jump to a location given in the rtx LOC. */
3976 emit_indirect_jump (rtx loc)
3978 if (! ((*insn_data[(int) CODE_FOR_indirect_jump].operand[0].predicate)
3980 loc = copy_to_mode_reg (Pmode, loc);
3982 emit_jump_insn (gen_indirect_jump (loc));
3986 #ifdef HAVE_conditional_move
3988 /* Emit a conditional move instruction if the machine supports one for that
3989 condition and machine mode.
3991 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
3992 the mode to use should they be constants. If it is VOIDmode, they cannot
3995 OP2 should be stored in TARGET if the comparison is true, otherwise OP3
3996 should be stored there. MODE is the mode to use should they be constants.
3997 If it is VOIDmode, they cannot both be constants.
3999 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
4000 is not supported. */
4003 emit_conditional_move (rtx target, enum rtx_code code, rtx op0, rtx op1,
4004 enum machine_mode cmode, rtx op2, rtx op3,
4005 enum machine_mode mode, int unsignedp)
4007 rtx tem, subtarget, comparison, insn;
4008 enum insn_code icode;
4009 enum rtx_code reversed;
4011 /* If one operand is constant, make it the second one. Only do this
4012 if the other operand is not constant as well. */
4014 if (swap_commutative_operands_p (op0, op1))