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
);
680 /* Load duplicate non-volatile operands once. */
681 if (rtx_equal_p (op0
, op1
) && ! volatile_refs_p (op0
))
683 op0
= force_not_mem (op0
);
688 op0
= force_not_mem (op0
);
689 op1
= force_not_mem (op1
);
693 /* If subtracting an integer constant, convert this into an addition of
694 the negated constant. */
696 if (binoptab
== sub_optab
&& GET_CODE (op1
) == CONST_INT
)
698 op1
= negate_rtx (mode
, op1
);
699 binoptab
= add_optab
;
702 /* If we are inside an appropriately-short loop and one operand is an
703 expensive constant, force it into a register. */
704 if (CONSTANT_P (op0
) && preserve_subexpressions_p ()
705 && rtx_cost (op0
, binoptab
->code
) > COSTS_N_INSNS (1))
706 op0
= force_reg (mode
, op0
);
708 if (CONSTANT_P (op1
) && preserve_subexpressions_p ()
709 && ! shift_op
&& rtx_cost (op1
, binoptab
->code
) > COSTS_N_INSNS (1))
710 op1
= force_reg (mode
, op1
);
712 /* Record where to delete back to if we backtrack. */
713 last
= get_last_insn ();
715 /* If operation is commutative,
716 try to make the first operand a register.
717 Even better, try to make it the same as the target.
718 Also try to make the last operand a constant. */
719 if (GET_RTX_CLASS (binoptab
->code
) == RTX_COMM_ARITH
720 || binoptab
== smul_widen_optab
721 || binoptab
== umul_widen_optab
722 || binoptab
== smul_highpart_optab
723 || binoptab
== umul_highpart_optab
)
727 if (((target
== 0 || REG_P (target
))
731 : rtx_equal_p (op1
, target
))
732 || GET_CODE (op0
) == CONST_INT
)
740 /* If we can do it with a three-operand insn, do so. */
742 if (methods
!= OPTAB_MUST_WIDEN
743 && binoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
745 int icode
= (int) binoptab
->handlers
[(int) mode
].insn_code
;
746 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
747 enum machine_mode mode1
= insn_data
[icode
].operand
[2].mode
;
749 rtx xop0
= op0
, xop1
= op1
;
754 temp
= gen_reg_rtx (mode
);
756 /* If it is a commutative operator and the modes would match
757 if we would swap the operands, we can save the conversions. */
760 if (GET_MODE (op0
) != mode0
&& GET_MODE (op1
) != mode1
761 && GET_MODE (op0
) == mode1
&& GET_MODE (op1
) == mode0
)
765 tmp
= op0
; op0
= op1
; op1
= tmp
;
766 tmp
= xop0
; xop0
= xop1
; xop1
= tmp
;
770 /* In case the insn wants input operands in modes different from
771 those of the actual operands, convert the operands. It would
772 seem that we don't need to convert CONST_INTs, but we do, so
773 that they're properly zero-extended, sign-extended or truncated
776 if (GET_MODE (op0
) != mode0
&& mode0
!= VOIDmode
)
777 xop0
= convert_modes (mode0
,
778 GET_MODE (op0
) != VOIDmode
783 if (GET_MODE (op1
) != mode1
&& mode1
!= VOIDmode
)
784 xop1
= convert_modes (mode1
,
785 GET_MODE (op1
) != VOIDmode
790 /* Now, if insn's predicates don't allow our operands, put them into
793 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
)
794 && mode0
!= VOIDmode
)
795 xop0
= copy_to_mode_reg (mode0
, xop0
);
797 if (! (*insn_data
[icode
].operand
[2].predicate
) (xop1
, mode1
)
798 && mode1
!= VOIDmode
)
799 xop1
= copy_to_mode_reg (mode1
, xop1
);
801 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, mode
))
802 temp
= gen_reg_rtx (mode
);
804 pat
= GEN_FCN (icode
) (temp
, xop0
, xop1
);
807 /* If PAT is composed of more than one insn, try to add an appropriate
808 REG_EQUAL note to it. If we can't because TEMP conflicts with an
809 operand, call ourselves again, this time without a target. */
810 if (INSN_P (pat
) && NEXT_INSN (pat
) != NULL_RTX
811 && ! add_equal_note (pat
, temp
, binoptab
->code
, xop0
, xop1
))
813 delete_insns_since (last
);
814 return expand_binop (mode
, binoptab
, op0
, op1
, NULL_RTX
,
822 delete_insns_since (last
);
825 /* If this is a multiply, see if we can do a widening operation that
826 takes operands of this mode and makes a wider mode. */
828 if (binoptab
== smul_optab
&& GET_MODE_WIDER_MODE (mode
) != VOIDmode
829 && (((unsignedp
? umul_widen_optab
: smul_widen_optab
)
830 ->handlers
[(int) GET_MODE_WIDER_MODE (mode
)].insn_code
)
831 != CODE_FOR_nothing
))
833 temp
= expand_binop (GET_MODE_WIDER_MODE (mode
),
834 unsignedp
? umul_widen_optab
: smul_widen_optab
,
835 op0
, op1
, NULL_RTX
, unsignedp
, OPTAB_DIRECT
);
839 if (GET_MODE_CLASS (mode
) == MODE_INT
)
840 return gen_lowpart (mode
, temp
);
842 return convert_to_mode (mode
, temp
, unsignedp
);
846 /* Look for a wider mode of the same class for which we think we
847 can open-code the operation. Check for a widening multiply at the
848 wider mode as well. */
850 if ((class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
851 && methods
!= OPTAB_DIRECT
&& methods
!= OPTAB_LIB
)
852 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
853 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
855 if (binoptab
->handlers
[(int) wider_mode
].insn_code
!= CODE_FOR_nothing
856 || (binoptab
== smul_optab
857 && GET_MODE_WIDER_MODE (wider_mode
) != VOIDmode
858 && (((unsignedp
? umul_widen_optab
: smul_widen_optab
)
859 ->handlers
[(int) GET_MODE_WIDER_MODE (wider_mode
)].insn_code
)
860 != CODE_FOR_nothing
)))
862 rtx xop0
= op0
, xop1
= op1
;
865 /* For certain integer operations, we need not actually extend
866 the narrow operands, as long as we will truncate
867 the results to the same narrowness. */
869 if ((binoptab
== ior_optab
|| binoptab
== and_optab
870 || binoptab
== xor_optab
871 || binoptab
== add_optab
|| binoptab
== sub_optab
872 || binoptab
== smul_optab
|| binoptab
== ashl_optab
)
873 && class == MODE_INT
)
876 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
, no_extend
);
878 /* The second operand of a shift must always be extended. */
879 xop1
= widen_operand (xop1
, wider_mode
, mode
, unsignedp
,
880 no_extend
&& binoptab
!= ashl_optab
);
882 temp
= expand_binop (wider_mode
, binoptab
, xop0
, xop1
, NULL_RTX
,
883 unsignedp
, OPTAB_DIRECT
);
886 if (class != MODE_INT
)
889 target
= gen_reg_rtx (mode
);
890 convert_move (target
, temp
, 0);
894 return gen_lowpart (mode
, temp
);
897 delete_insns_since (last
);
901 /* These can be done a word at a time. */
902 if ((binoptab
== and_optab
|| binoptab
== ior_optab
|| binoptab
== xor_optab
)
904 && GET_MODE_SIZE (mode
) > UNITS_PER_WORD
905 && binoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
911 /* If TARGET is the same as one of the operands, the REG_EQUAL note
912 won't be accurate, so use a new target. */
913 if (target
== 0 || target
== op0
|| target
== op1
)
914 target
= gen_reg_rtx (mode
);
918 /* Do the actual arithmetic. */
919 for (i
= 0; i
< GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
; i
++)
921 rtx target_piece
= operand_subword (target
, i
, 1, mode
);
922 rtx x
= expand_binop (word_mode
, binoptab
,
923 operand_subword_force (op0
, i
, mode
),
924 operand_subword_force (op1
, i
, mode
),
925 target_piece
, unsignedp
, next_methods
);
930 if (target_piece
!= x
)
931 emit_move_insn (target_piece
, x
);
934 insns
= get_insns ();
937 if (i
== GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
)
939 if (binoptab
->code
!= UNKNOWN
)
941 = gen_rtx_fmt_ee (binoptab
->code
, mode
,
942 copy_rtx (op0
), copy_rtx (op1
));
946 emit_no_conflict_block (insns
, target
, op0
, op1
, equiv_value
);
951 /* Synthesize double word shifts from single word shifts. */
952 if ((binoptab
== lshr_optab
|| binoptab
== ashl_optab
953 || binoptab
== ashr_optab
)
955 && GET_CODE (op1
) == CONST_INT
956 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
957 && binoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
958 && ashl_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
959 && lshr_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
961 rtx insns
, inter
, equiv_value
;
962 rtx into_target
, outof_target
;
963 rtx into_input
, outof_input
;
964 int shift_count
, left_shift
, outof_word
;
966 /* If TARGET is the same as one of the operands, the REG_EQUAL note
967 won't be accurate, so use a new target. */
968 if (target
== 0 || target
== op0
|| target
== op1
)
969 target
= gen_reg_rtx (mode
);
973 shift_count
= INTVAL (op1
);
975 /* OUTOF_* is the word we are shifting bits away from, and
976 INTO_* is the word that we are shifting bits towards, thus
977 they differ depending on the direction of the shift and
980 left_shift
= binoptab
== ashl_optab
;
981 outof_word
= left_shift
^ ! WORDS_BIG_ENDIAN
;
983 outof_target
= operand_subword (target
, outof_word
, 1, mode
);
984 into_target
= operand_subword (target
, 1 - outof_word
, 1, mode
);
986 outof_input
= operand_subword_force (op0
, outof_word
, mode
);
987 into_input
= operand_subword_force (op0
, 1 - outof_word
, mode
);
989 if (shift_count
>= BITS_PER_WORD
)
991 inter
= expand_binop (word_mode
, binoptab
,
993 GEN_INT (shift_count
- BITS_PER_WORD
),
994 into_target
, unsignedp
, next_methods
);
996 if (inter
!= 0 && inter
!= into_target
)
997 emit_move_insn (into_target
, inter
);
999 /* For a signed right shift, we must fill the word we are shifting
1000 out of with copies of the sign bit. Otherwise it is zeroed. */
1001 if (inter
!= 0 && binoptab
!= ashr_optab
)
1002 inter
= CONST0_RTX (word_mode
);
1003 else if (inter
!= 0)
1004 inter
= expand_binop (word_mode
, binoptab
,
1006 GEN_INT (BITS_PER_WORD
- 1),
1007 outof_target
, unsignedp
, next_methods
);
1009 if (inter
!= 0 && inter
!= outof_target
)
1010 emit_move_insn (outof_target
, inter
);
1015 optab reverse_unsigned_shift
, unsigned_shift
;
1017 /* For a shift of less then BITS_PER_WORD, to compute the carry,
1018 we must do a logical shift in the opposite direction of the
1021 reverse_unsigned_shift
= (left_shift
? lshr_optab
: ashl_optab
);
1023 /* For a shift of less than BITS_PER_WORD, to compute the word
1024 shifted towards, we need to unsigned shift the orig value of
1027 unsigned_shift
= (left_shift
? ashl_optab
: lshr_optab
);
1029 carries
= expand_binop (word_mode
, reverse_unsigned_shift
,
1031 GEN_INT (BITS_PER_WORD
- shift_count
),
1032 0, unsignedp
, next_methods
);
1037 inter
= expand_binop (word_mode
, unsigned_shift
, into_input
,
1038 op1
, 0, unsignedp
, next_methods
);
1041 inter
= expand_binop (word_mode
, ior_optab
, carries
, inter
,
1042 into_target
, unsignedp
, next_methods
);
1044 if (inter
!= 0 && inter
!= into_target
)
1045 emit_move_insn (into_target
, inter
);
1048 inter
= expand_binop (word_mode
, binoptab
, outof_input
,
1049 op1
, outof_target
, unsignedp
, next_methods
);
1051 if (inter
!= 0 && inter
!= outof_target
)
1052 emit_move_insn (outof_target
, inter
);
1055 insns
= get_insns ();
1060 if (binoptab
->code
!= UNKNOWN
)
1061 equiv_value
= gen_rtx_fmt_ee (binoptab
->code
, mode
, op0
, op1
);
1065 emit_no_conflict_block (insns
, target
, op0
, op1
, equiv_value
);
1070 /* Synthesize double word rotates from single word shifts. */
1071 if ((binoptab
== rotl_optab
|| binoptab
== rotr_optab
)
1072 && class == MODE_INT
1073 && GET_CODE (op1
) == CONST_INT
1074 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
1075 && ashl_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1076 && lshr_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
1078 rtx insns
, equiv_value
;
1079 rtx into_target
, outof_target
;
1080 rtx into_input
, outof_input
;
1082 int shift_count
, left_shift
, outof_word
;
1084 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1085 won't be accurate, so use a new target. Do this also if target is not
1086 a REG, first because having a register instead may open optimization
1087 opportunities, and second because if target and op0 happen to be MEMs
1088 designating the same location, we would risk clobbering it too early
1089 in the code sequence we generate below. */
1090 if (target
== 0 || target
== op0
|| target
== op1
|| ! REG_P (target
))
1091 target
= gen_reg_rtx (mode
);
1095 shift_count
= INTVAL (op1
);
1097 /* OUTOF_* is the word we are shifting bits away from, and
1098 INTO_* is the word that we are shifting bits towards, thus
1099 they differ depending on the direction of the shift and
1100 WORDS_BIG_ENDIAN. */
1102 left_shift
= (binoptab
== rotl_optab
);
1103 outof_word
= left_shift
^ ! WORDS_BIG_ENDIAN
;
1105 outof_target
= operand_subword (target
, outof_word
, 1, mode
);
1106 into_target
= operand_subword (target
, 1 - outof_word
, 1, mode
);
1108 outof_input
= operand_subword_force (op0
, outof_word
, mode
);
1109 into_input
= operand_subword_force (op0
, 1 - outof_word
, mode
);
1111 if (shift_count
== BITS_PER_WORD
)
1113 /* This is just a word swap. */
1114 emit_move_insn (outof_target
, into_input
);
1115 emit_move_insn (into_target
, outof_input
);
1120 rtx into_temp1
, into_temp2
, outof_temp1
, outof_temp2
;
1121 rtx first_shift_count
, second_shift_count
;
1122 optab reverse_unsigned_shift
, unsigned_shift
;
1124 reverse_unsigned_shift
= (left_shift
^ (shift_count
< BITS_PER_WORD
)
1125 ? lshr_optab
: ashl_optab
);
1127 unsigned_shift
= (left_shift
^ (shift_count
< BITS_PER_WORD
)
1128 ? ashl_optab
: lshr_optab
);
1130 if (shift_count
> BITS_PER_WORD
)
1132 first_shift_count
= GEN_INT (shift_count
- BITS_PER_WORD
);
1133 second_shift_count
= GEN_INT (2 * BITS_PER_WORD
- shift_count
);
1137 first_shift_count
= GEN_INT (BITS_PER_WORD
- shift_count
);
1138 second_shift_count
= GEN_INT (shift_count
);
1141 into_temp1
= expand_binop (word_mode
, unsigned_shift
,
1142 outof_input
, first_shift_count
,
1143 NULL_RTX
, unsignedp
, next_methods
);
1144 into_temp2
= expand_binop (word_mode
, reverse_unsigned_shift
,
1145 into_input
, second_shift_count
,
1146 NULL_RTX
, unsignedp
, next_methods
);
1148 if (into_temp1
!= 0 && into_temp2
!= 0)
1149 inter
= expand_binop (word_mode
, ior_optab
, into_temp1
, into_temp2
,
1150 into_target
, unsignedp
, next_methods
);
1154 if (inter
!= 0 && inter
!= into_target
)
1155 emit_move_insn (into_target
, inter
);
1157 outof_temp1
= expand_binop (word_mode
, unsigned_shift
,
1158 into_input
, first_shift_count
,
1159 NULL_RTX
, unsignedp
, next_methods
);
1160 outof_temp2
= expand_binop (word_mode
, reverse_unsigned_shift
,
1161 outof_input
, second_shift_count
,
1162 NULL_RTX
, unsignedp
, next_methods
);
1164 if (inter
!= 0 && outof_temp1
!= 0 && outof_temp2
!= 0)
1165 inter
= expand_binop (word_mode
, ior_optab
,
1166 outof_temp1
, outof_temp2
,
1167 outof_target
, unsignedp
, next_methods
);
1169 if (inter
!= 0 && inter
!= outof_target
)
1170 emit_move_insn (outof_target
, inter
);
1173 insns
= get_insns ();
1178 if (binoptab
->code
!= UNKNOWN
)
1179 equiv_value
= gen_rtx_fmt_ee (binoptab
->code
, mode
, op0
, op1
);
1183 /* We can't make this a no conflict block if this is a word swap,
1184 because the word swap case fails if the input and output values
1185 are in the same register. */
1186 if (shift_count
!= BITS_PER_WORD
)
1187 emit_no_conflict_block (insns
, target
, op0
, op1
, equiv_value
);
1196 /* These can be done a word at a time by propagating carries. */
1197 if ((binoptab
== add_optab
|| binoptab
== sub_optab
)
1198 && class == MODE_INT
1199 && GET_MODE_SIZE (mode
) >= 2 * UNITS_PER_WORD
1200 && binoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
1203 optab otheroptab
= binoptab
== add_optab
? sub_optab
: add_optab
;
1204 const unsigned int nwords
= GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
;
1205 rtx carry_in
= NULL_RTX
, carry_out
= NULL_RTX
;
1206 rtx xop0
, xop1
, xtarget
;
1208 /* We can handle either a 1 or -1 value for the carry. If STORE_FLAG
1209 value is one of those, use it. Otherwise, use 1 since it is the
1210 one easiest to get. */
1211 #if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1
1212 int normalizep
= STORE_FLAG_VALUE
;
1217 /* Prepare the operands. */
1218 xop0
= force_reg (mode
, op0
);
1219 xop1
= force_reg (mode
, op1
);
1221 xtarget
= gen_reg_rtx (mode
);
1223 if (target
== 0 || !REG_P (target
))
1226 /* Indicate for flow that the entire target reg is being set. */
1228 emit_insn (gen_rtx_CLOBBER (VOIDmode
, xtarget
));
1230 /* Do the actual arithmetic. */
1231 for (i
= 0; i
< nwords
; i
++)
1233 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
1234 rtx target_piece
= operand_subword (xtarget
, index
, 1, mode
);
1235 rtx op0_piece
= operand_subword_force (xop0
, index
, mode
);
1236 rtx op1_piece
= operand_subword_force (xop1
, index
, mode
);
1239 /* Main add/subtract of the input operands. */
1240 x
= expand_binop (word_mode
, binoptab
,
1241 op0_piece
, op1_piece
,
1242 target_piece
, unsignedp
, next_methods
);
1248 /* Store carry from main add/subtract. */
1249 carry_out
= gen_reg_rtx (word_mode
);
1250 carry_out
= emit_store_flag_force (carry_out
,
1251 (binoptab
== add_optab
1254 word_mode
, 1, normalizep
);
1261 /* Add/subtract previous carry to main result. */
1262 newx
= expand_binop (word_mode
,
1263 normalizep
== 1 ? binoptab
: otheroptab
,
1265 NULL_RTX
, 1, next_methods
);
1269 /* Get out carry from adding/subtracting carry in. */
1270 rtx carry_tmp
= gen_reg_rtx (word_mode
);
1271 carry_tmp
= emit_store_flag_force (carry_tmp
,
1272 (binoptab
== add_optab
1275 word_mode
, 1, normalizep
);
1277 /* Logical-ior the two poss. carry together. */
1278 carry_out
= expand_binop (word_mode
, ior_optab
,
1279 carry_out
, carry_tmp
,
1280 carry_out
, 0, next_methods
);
1284 emit_move_insn (target_piece
, newx
);
1287 carry_in
= carry_out
;
1290 if (i
== GET_MODE_BITSIZE (mode
) / (unsigned) BITS_PER_WORD
)
1292 if (mov_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
1293 || ! rtx_equal_p (target
, xtarget
))
1295 rtx temp
= emit_move_insn (target
, xtarget
);
1297 set_unique_reg_note (temp
,
1299 gen_rtx_fmt_ee (binoptab
->code
, mode
,
1310 delete_insns_since (last
);
1313 /* If we want to multiply two two-word values and have normal and widening
1314 multiplies of single-word values, we can do this with three smaller
1315 multiplications. Note that we do not make a REG_NO_CONFLICT block here
1316 because we are not operating on one word at a time.
1318 The multiplication proceeds as follows:
1319 _______________________
1320 [__op0_high_|__op0_low__]
1321 _______________________
1322 * [__op1_high_|__op1_low__]
1323 _______________________________________________
1324 _______________________
1325 (1) [__op0_low__*__op1_low__]
1326 _______________________
1327 (2a) [__op0_low__*__op1_high_]
1328 _______________________
1329 (2b) [__op0_high_*__op1_low__]
1330 _______________________
1331 (3) [__op0_high_*__op1_high_]
1334 This gives a 4-word result. Since we are only interested in the
1335 lower 2 words, partial result (3) and the upper words of (2a) and
1336 (2b) don't need to be calculated. Hence (2a) and (2b) can be
1337 calculated using non-widening multiplication.
1339 (1), however, needs to be calculated with an unsigned widening
1340 multiplication. If this operation is not directly supported we
1341 try using a signed widening multiplication and adjust the result.
1342 This adjustment works as follows:
1344 If both operands are positive then no adjustment is needed.
1346 If the operands have different signs, for example op0_low < 0 and
1347 op1_low >= 0, the instruction treats the most significant bit of
1348 op0_low as a sign bit instead of a bit with significance
1349 2**(BITS_PER_WORD-1), i.e. the instruction multiplies op1_low
1350 with 2**BITS_PER_WORD - op0_low, and two's complements the
1351 result. Conclusion: We need to add op1_low * 2**BITS_PER_WORD to
1354 Similarly, if both operands are negative, we need to add
1355 (op0_low + op1_low) * 2**BITS_PER_WORD.
1357 We use a trick to adjust quickly. We logically shift op0_low right
1358 (op1_low) BITS_PER_WORD-1 steps to get 0 or 1, and add this to
1359 op0_high (op1_high) before it is used to calculate 2b (2a). If no
1360 logical shift exists, we do an arithmetic right shift and subtract
1363 if (binoptab
== smul_optab
1364 && class == MODE_INT
1365 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
1366 && smul_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1367 && add_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1368 && ((umul_widen_optab
->handlers
[(int) mode
].insn_code
1369 != CODE_FOR_nothing
)
1370 || (smul_widen_optab
->handlers
[(int) mode
].insn_code
1371 != CODE_FOR_nothing
)))
1373 int low
= (WORDS_BIG_ENDIAN
? 1 : 0);
1374 int high
= (WORDS_BIG_ENDIAN
? 0 : 1);
1375 rtx op0_high
= operand_subword_force (op0
, high
, mode
);
1376 rtx op0_low
= operand_subword_force (op0
, low
, mode
);
1377 rtx op1_high
= operand_subword_force (op1
, high
, mode
);
1378 rtx op1_low
= operand_subword_force (op1
, low
, mode
);
1380 rtx op0_xhigh
= NULL_RTX
;
1381 rtx op1_xhigh
= NULL_RTX
;
1383 /* If the target is the same as one of the inputs, don't use it. This
1384 prevents problems with the REG_EQUAL note. */
1385 if (target
== op0
|| target
== op1
1386 || (target
!= 0 && !REG_P (target
)))
1389 /* Multiply the two lower words to get a double-word product.
1390 If unsigned widening multiplication is available, use that;
1391 otherwise use the signed form and compensate. */
1393 if (umul_widen_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
1395 product
= expand_binop (mode
, umul_widen_optab
, op0_low
, op1_low
,
1396 target
, 1, OPTAB_DIRECT
);
1398 /* If we didn't succeed, delete everything we did so far. */
1400 delete_insns_since (last
);
1402 op0_xhigh
= op0_high
, op1_xhigh
= op1_high
;
1406 && smul_widen_optab
->handlers
[(int) mode
].insn_code
1407 != CODE_FOR_nothing
)
1409 rtx wordm1
= GEN_INT (BITS_PER_WORD
- 1);
1410 product
= expand_binop (mode
, smul_widen_optab
, op0_low
, op1_low
,
1411 target
, 1, OPTAB_DIRECT
);
1412 op0_xhigh
= expand_binop (word_mode
, lshr_optab
, op0_low
, wordm1
,
1413 NULL_RTX
, 1, next_methods
);
1415 op0_xhigh
= expand_binop (word_mode
, add_optab
, op0_high
,
1416 op0_xhigh
, op0_xhigh
, 0, next_methods
);
1419 op0_xhigh
= expand_binop (word_mode
, ashr_optab
, op0_low
, wordm1
,
1420 NULL_RTX
, 0, next_methods
);
1422 op0_xhigh
= expand_binop (word_mode
, sub_optab
, op0_high
,
1423 op0_xhigh
, op0_xhigh
, 0,
1427 op1_xhigh
= expand_binop (word_mode
, lshr_optab
, op1_low
, wordm1
,
1428 NULL_RTX
, 1, next_methods
);
1430 op1_xhigh
= expand_binop (word_mode
, add_optab
, op1_high
,
1431 op1_xhigh
, op1_xhigh
, 0, next_methods
);
1434 op1_xhigh
= expand_binop (word_mode
, ashr_optab
, op1_low
, wordm1
,
1435 NULL_RTX
, 0, next_methods
);
1437 op1_xhigh
= expand_binop (word_mode
, sub_optab
, op1_high
,
1438 op1_xhigh
, op1_xhigh
, 0,
1443 /* If we have been able to directly compute the product of the
1444 low-order words of the operands and perform any required adjustments
1445 of the operands, we proceed by trying two more multiplications
1446 and then computing the appropriate sum.
1448 We have checked above that the required addition is provided.
1449 Full-word addition will normally always succeed, especially if
1450 it is provided at all, so we don't worry about its failure. The
1451 multiplication may well fail, however, so we do handle that. */
1453 if (product
&& op0_xhigh
&& op1_xhigh
)
1455 rtx product_high
= operand_subword (product
, high
, 1, mode
);
1456 rtx temp
= expand_binop (word_mode
, binoptab
, op0_low
, op1_xhigh
,
1457 NULL_RTX
, 0, OPTAB_DIRECT
);
1459 if (!REG_P (product_high
))
1460 product_high
= force_reg (word_mode
, product_high
);
1463 temp
= expand_binop (word_mode
, add_optab
, temp
, product_high
,
1464 product_high
, 0, next_methods
);
1466 if (temp
!= 0 && temp
!= product_high
)
1467 emit_move_insn (product_high
, temp
);
1470 temp
= expand_binop (word_mode
, binoptab
, op1_low
, op0_xhigh
,
1471 NULL_RTX
, 0, OPTAB_DIRECT
);
1474 temp
= expand_binop (word_mode
, add_optab
, temp
,
1475 product_high
, product_high
,
1478 if (temp
!= 0 && temp
!= product_high
)
1479 emit_move_insn (product_high
, temp
);
1481 emit_move_insn (operand_subword (product
, high
, 1, mode
), product_high
);
1485 if (mov_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
1487 temp
= emit_move_insn (product
, product
);
1488 set_unique_reg_note (temp
,
1490 gen_rtx_fmt_ee (MULT
, mode
,
1499 /* If we get here, we couldn't do it for some reason even though we
1500 originally thought we could. Delete anything we've emitted in
1503 delete_insns_since (last
);
1506 /* Open-code the vector operations if we have no hardware support
1508 if (class == MODE_VECTOR_INT
|| class == MODE_VECTOR_FLOAT
)
1509 return expand_vector_binop (mode
, binoptab
, op0
, op1
, target
,
1510 unsignedp
, methods
);
1512 /* We need to open-code the complex type operations: '+, -, * and /' */
1514 /* At this point we allow operations between two similar complex
1515 numbers, and also if one of the operands is not a complex number
1516 but rather of MODE_FLOAT or MODE_INT. However, the caller
1517 must make sure that the MODE of the non-complex operand matches
1518 the SUBMODE of the complex operand. */
1520 if (class == MODE_COMPLEX_FLOAT
|| class == MODE_COMPLEX_INT
)
1522 rtx real0
= 0, imag0
= 0;
1523 rtx real1
= 0, imag1
= 0;
1524 rtx realr
, imagr
, res
;
1528 /* Find the correct mode for the real and imaginary parts. */
1529 enum machine_mode submode
= GET_MODE_INNER (mode
);
1531 if (submode
== BLKmode
)
1536 if (GET_MODE (op0
) == mode
)
1538 real0
= gen_realpart (submode
, op0
);
1539 imag0
= gen_imagpart (submode
, op0
);
1544 if (GET_MODE (op1
) == mode
)
1546 real1
= gen_realpart (submode
, op1
);
1547 imag1
= gen_imagpart (submode
, op1
);
1552 if (real0
== 0 || real1
== 0 || ! (imag0
!= 0 || imag1
!= 0))
1555 result
= gen_reg_rtx (mode
);
1556 realr
= gen_realpart (submode
, result
);
1557 imagr
= gen_imagpart (submode
, result
);
1559 switch (binoptab
->code
)
1562 /* (a+ib) + (c+id) = (a+c) + i(b+d) */
1564 /* (a+ib) - (c+id) = (a-c) + i(b-d) */
1565 res
= expand_binop (submode
, binoptab
, real0
, real1
,
1566 realr
, unsignedp
, methods
);
1570 else if (res
!= realr
)
1571 emit_move_insn (realr
, res
);
1573 if (imag0
!= 0 && imag1
!= 0)
1574 res
= expand_binop (submode
, binoptab
, imag0
, imag1
,
1575 imagr
, unsignedp
, methods
);
1576 else if (imag0
!= 0)
1578 else if (binoptab
->code
== MINUS
)
1579 res
= expand_unop (submode
,
1580 binoptab
== subv_optab
? negv_optab
: neg_optab
,
1581 imag1
, imagr
, unsignedp
);
1587 else if (res
!= imagr
)
1588 emit_move_insn (imagr
, res
);
1594 /* (a+ib) * (c+id) = (ac-bd) + i(ad+cb) */
1596 if (imag0
!= 0 && imag1
!= 0)
1600 /* Don't fetch these from memory more than once. */
1601 real0
= force_reg (submode
, real0
);
1602 real1
= force_reg (submode
, real1
);
1603 imag0
= force_reg (submode
, imag0
);
1604 imag1
= force_reg (submode
, imag1
);
1606 temp1
= expand_binop (submode
, binoptab
, real0
, real1
, NULL_RTX
,
1607 unsignedp
, methods
);
1609 temp2
= expand_binop (submode
, binoptab
, imag0
, imag1
, NULL_RTX
,
1610 unsignedp
, methods
);
1612 if (temp1
== 0 || temp2
== 0)
1617 binoptab
== smulv_optab
? subv_optab
: sub_optab
,
1618 temp1
, temp2
, realr
, unsignedp
, methods
));
1622 else if (res
!= realr
)
1623 emit_move_insn (realr
, res
);
1625 temp1
= expand_binop (submode
, binoptab
, real0
, imag1
,
1626 NULL_RTX
, unsignedp
, methods
);
1628 /* Avoid expanding redundant multiplication for the common
1629 case of squaring a complex number. */
1630 if (rtx_equal_p (real0
, real1
) && rtx_equal_p (imag0
, imag1
))
1633 temp2
= expand_binop (submode
, binoptab
, real1
, imag0
,
1634 NULL_RTX
, unsignedp
, methods
);
1636 if (temp1
== 0 || temp2
== 0)
1641 binoptab
== smulv_optab
? addv_optab
: add_optab
,
1642 temp1
, temp2
, imagr
, unsignedp
, methods
));
1646 else if (res
!= imagr
)
1647 emit_move_insn (imagr
, res
);
1653 /* Don't fetch these from memory more than once. */
1654 real0
= force_reg (submode
, real0
);
1655 real1
= force_reg (submode
, real1
);
1657 res
= expand_binop (submode
, binoptab
, real0
, real1
,
1658 realr
, unsignedp
, methods
);
1661 else if (res
!= realr
)
1662 emit_move_insn (realr
, res
);
1665 res
= expand_binop (submode
, binoptab
,
1666 real1
, imag0
, imagr
, unsignedp
, methods
);
1668 res
= expand_binop (submode
, binoptab
,
1669 real0
, imag1
, imagr
, unsignedp
, methods
);
1673 else if (res
!= imagr
)
1674 emit_move_insn (imagr
, res
);
1681 /* (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) */
1685 /* (a+ib) / (c+i0) = (a/c) + i(b/c) */
1687 /* Don't fetch these from memory more than once. */
1688 real1
= force_reg (submode
, real1
);
1690 /* Simply divide the real and imaginary parts by `c' */
1691 if (class == MODE_COMPLEX_FLOAT
)
1692 res
= expand_binop (submode
, binoptab
, real0
, real1
,
1693 realr
, unsignedp
, methods
);
1695 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
1696 real0
, real1
, realr
, unsignedp
);
1700 else if (res
!= realr
)
1701 emit_move_insn (realr
, res
);
1703 if (class == MODE_COMPLEX_FLOAT
)
1704 res
= expand_binop (submode
, binoptab
, imag0
, real1
,
1705 imagr
, unsignedp
, methods
);
1707 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
1708 imag0
, real1
, imagr
, unsignedp
);
1712 else if (res
!= imagr
)
1713 emit_move_insn (imagr
, res
);
1719 switch (flag_complex_divide_method
)
1722 ok
= expand_cmplxdiv_straight (real0
, real1
, imag0
, imag1
,
1723 realr
, imagr
, submode
,
1729 ok
= expand_cmplxdiv_wide (real0
, real1
, imag0
, imag1
,
1730 realr
, imagr
, submode
,
1750 rtx equiv
= gen_rtx_fmt_ee (binoptab
->code
, mode
,
1751 copy_rtx (op0
), copy_rtx (op1
));
1752 emit_no_conflict_block (seq
, result
, op0
, op1
, equiv
);
1757 /* It can't be open-coded in this mode.
1758 Use a library call if one is available and caller says that's ok. */
1760 if (binoptab
->handlers
[(int) mode
].libfunc
1761 && (methods
== OPTAB_LIB
|| methods
== OPTAB_LIB_WIDEN
))
1765 enum machine_mode op1_mode
= mode
;
1772 op1_mode
= word_mode
;
1773 /* Specify unsigned here,
1774 since negative shift counts are meaningless. */
1775 op1x
= convert_to_mode (word_mode
, op1
, 1);
1778 if (GET_MODE (op0
) != VOIDmode
1779 && GET_MODE (op0
) != mode
)
1780 op0
= convert_to_mode (mode
, op0
, unsignedp
);
1782 /* Pass 1 for NO_QUEUE so we don't lose any increments
1783 if the libcall is cse'd or moved. */
1784 value
= emit_library_call_value (binoptab
->handlers
[(int) mode
].libfunc
,
1785 NULL_RTX
, LCT_CONST
, mode
, 2,
1786 op0
, mode
, op1x
, op1_mode
);
1788 insns
= get_insns ();
1791 target
= gen_reg_rtx (mode
);
1792 emit_libcall_block (insns
, target
, value
,
1793 gen_rtx_fmt_ee (binoptab
->code
, mode
, op0
, op1
));
1798 delete_insns_since (last
);
1800 /* It can't be done in this mode. Can we do it in a wider mode? */
1802 if (! (methods
== OPTAB_WIDEN
|| methods
== OPTAB_LIB_WIDEN
1803 || methods
== OPTAB_MUST_WIDEN
))
1805 /* Caller says, don't even try. */
1806 delete_insns_since (entry_last
);
1810 /* Compute the value of METHODS to pass to recursive calls.
1811 Don't allow widening to be tried recursively. */
1813 methods
= (methods
== OPTAB_LIB_WIDEN
? OPTAB_LIB
: OPTAB_DIRECT
);
1815 /* Look for a wider mode of the same class for which it appears we can do
1818 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
1820 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
1821 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
1823 if ((binoptab
->handlers
[(int) wider_mode
].insn_code
1824 != CODE_FOR_nothing
)
1825 || (methods
== OPTAB_LIB
1826 && binoptab
->handlers
[(int) wider_mode
].libfunc
))
1828 rtx xop0
= op0
, xop1
= op1
;
1831 /* For certain integer operations, we need not actually extend
1832 the narrow operands, as long as we will truncate
1833 the results to the same narrowness. */
1835 if ((binoptab
== ior_optab
|| binoptab
== and_optab
1836 || binoptab
== xor_optab
1837 || binoptab
== add_optab
|| binoptab
== sub_optab
1838 || binoptab
== smul_optab
|| binoptab
== ashl_optab
)
1839 && class == MODE_INT
)
1842 xop0
= widen_operand (xop0
, wider_mode
, mode
,
1843 unsignedp
, no_extend
);
1845 /* The second operand of a shift must always be extended. */
1846 xop1
= widen_operand (xop1
, wider_mode
, mode
, unsignedp
,
1847 no_extend
&& binoptab
!= ashl_optab
);
1849 temp
= expand_binop (wider_mode
, binoptab
, xop0
, xop1
, NULL_RTX
,
1850 unsignedp
, methods
);
1853 if (class != MODE_INT
)
1856 target
= gen_reg_rtx (mode
);
1857 convert_move (target
, temp
, 0);
1861 return gen_lowpart (mode
, temp
);
1864 delete_insns_since (last
);
1869 delete_insns_since (entry_last
);
1873 /* Like expand_binop, but for open-coding vectors binops. */
1876 expand_vector_binop (enum machine_mode mode
, optab binoptab
, rtx op0
,
1877 rtx op1
, rtx target
, int unsignedp
,
1878 enum optab_methods methods
)
1880 enum machine_mode submode
, tmode
;
1881 int size
, elts
, subsize
, subbitsize
, i
;
1882 rtx t
, a
, b
, res
, seq
;
1883 enum mode_class
class;
1885 class = GET_MODE_CLASS (mode
);
1887 size
= GET_MODE_SIZE (mode
);
1888 submode
= GET_MODE_INNER (mode
);
1890 /* Search for the widest vector mode with the same inner mode that is
1891 still narrower than MODE and that allows to open-code this operator.
1892 Note, if we find such a mode and the handler later decides it can't
1893 do the expansion, we'll be called recursively with the narrower mode. */
1894 for (tmode
= GET_CLASS_NARROWEST_MODE (class);
1895 GET_MODE_SIZE (tmode
) < GET_MODE_SIZE (mode
);
1896 tmode
= GET_MODE_WIDER_MODE (tmode
))
1898 if (GET_MODE_INNER (tmode
) == GET_MODE_INNER (mode
)
1899 && binoptab
->handlers
[(int) tmode
].insn_code
!= CODE_FOR_nothing
)
1903 switch (binoptab
->code
)
1908 tmode
= int_mode_for_mode (mode
);
1909 if (tmode
!= BLKmode
)
1915 subsize
= GET_MODE_SIZE (submode
);
1916 subbitsize
= GET_MODE_BITSIZE (submode
);
1917 elts
= size
/ subsize
;
1919 /* If METHODS is OPTAB_DIRECT, we don't insist on the exact mode,
1920 but that we operate on more than one element at a time. */
1921 if (subsize
== GET_MODE_UNIT_SIZE (mode
) && methods
== OPTAB_DIRECT
)
1926 /* Errors can leave us with a const0_rtx as operand. */
1927 if (GET_MODE (op0
) != mode
)
1928 op0
= copy_to_mode_reg (mode
, op0
);
1929 if (GET_MODE (op1
) != mode
)
1930 op1
= copy_to_mode_reg (mode
, op1
);
1933 target
= gen_reg_rtx (mode
);
1935 for (i
= 0; i
< elts
; ++i
)
1937 /* If this is part of a register, and not the first item in the
1938 word, we can't store using a SUBREG - that would clobber
1940 And storing with a SUBREG is only possible for the least
1941 significant part, hence we can't do it for big endian
1942 (unless we want to permute the evaluation order. */
1944 && (BYTES_BIG_ENDIAN
1945 ? subsize
< UNITS_PER_WORD
1946 : ((i
* subsize
) % UNITS_PER_WORD
) != 0))
1949 t
= simplify_gen_subreg (submode
, target
, mode
, i
* subsize
);
1950 if (CONSTANT_P (op0
))
1951 a
= simplify_gen_subreg (submode
, op0
, mode
, i
* subsize
);
1953 a
= extract_bit_field (op0
, subbitsize
, i
* subbitsize
, unsignedp
,
1954 NULL_RTX
, submode
, submode
);
1955 if (CONSTANT_P (op1
))
1956 b
= simplify_gen_subreg (submode
, op1
, mode
, i
* subsize
);
1958 b
= extract_bit_field (op1
, subbitsize
, i
* subbitsize
, unsignedp
,
1959 NULL_RTX
, submode
, submode
);
1961 if (binoptab
->code
== DIV
)
1963 if (class == MODE_VECTOR_FLOAT
)
1964 res
= expand_binop (submode
, binoptab
, a
, b
, t
,
1965 unsignedp
, methods
);
1967 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
1968 a
, b
, t
, unsignedp
);
1971 res
= expand_binop (submode
, binoptab
, a
, b
, t
,
1972 unsignedp
, methods
);
1978 emit_move_insn (t
, res
);
1980 store_bit_field (target
, subbitsize
, i
* subbitsize
, submode
, res
);
1995 /* Like expand_unop but for open-coding vector unops. */
1998 expand_vector_unop (enum machine_mode mode
, optab unoptab
, rtx op0
,
1999 rtx target
, int unsignedp
)
2001 enum machine_mode submode
, tmode
;
2002 int size
, elts
, subsize
, subbitsize
, i
;
2005 size
= GET_MODE_SIZE (mode
);
2006 submode
= GET_MODE_INNER (mode
);
2008 /* Search for the widest vector mode with the same inner mode that is
2009 still narrower than MODE and that allows to open-code this operator.
2010 Note, if we find such a mode and the handler later decides it can't
2011 do the expansion, we'll be called recursively with the narrower mode. */
2012 for (tmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (mode
));
2013 GET_MODE_SIZE (tmode
) < GET_MODE_SIZE (mode
);
2014 tmode
= GET_MODE_WIDER_MODE (tmode
))
2016 if (GET_MODE_INNER (tmode
) == GET_MODE_INNER (mode
)
2017 && unoptab
->handlers
[(int) tmode
].insn_code
!= CODE_FOR_nothing
)
2020 /* If there is no negate operation, try doing a subtract from zero. */
2021 if (unoptab
== neg_optab
&& GET_MODE_CLASS (submode
) == MODE_INT
2022 /* Avoid infinite recursion when an
2023 error has left us with the wrong mode. */
2024 && GET_MODE (op0
) == mode
)
2027 temp
= expand_binop (mode
, sub_optab
, CONST0_RTX (mode
), op0
,
2028 target
, unsignedp
, OPTAB_DIRECT
);
2033 if (unoptab
== one_cmpl_optab
)
2035 tmode
= int_mode_for_mode (mode
);
2036 if (tmode
!= BLKmode
)
2040 subsize
= GET_MODE_SIZE (submode
);
2041 subbitsize
= GET_MODE_BITSIZE (submode
);
2042 elts
= size
/ subsize
;
2044 /* Errors can leave us with a const0_rtx as operand. */
2045 if (GET_MODE (op0
) != mode
)
2046 op0
= copy_to_mode_reg (mode
, op0
);
2049 target
= gen_reg_rtx (mode
);
2053 for (i
= 0; i
< elts
; ++i
)
2055 /* If this is part of a register, and not the first item in the
2056 word, we can't store using a SUBREG - that would clobber
2058 And storing with a SUBREG is only possible for the least
2059 significant part, hence we can't do it for big endian
2060 (unless we want to permute the evaluation order. */
2062 && (BYTES_BIG_ENDIAN
2063 ? subsize
< UNITS_PER_WORD
2064 : ((i
* subsize
) % UNITS_PER_WORD
) != 0))
2067 t
= simplify_gen_subreg (submode
, target
, mode
, i
* subsize
);
2068 if (CONSTANT_P (op0
))
2069 a
= simplify_gen_subreg (submode
, op0
, mode
, i
* subsize
);
2071 a
= extract_bit_field (op0
, subbitsize
, i
* subbitsize
, unsignedp
,
2072 t
, submode
, submode
);
2074 res
= expand_unop (submode
, unoptab
, a
, t
, unsignedp
);
2077 emit_move_insn (t
, res
);
2079 store_bit_field (target
, subbitsize
, i
* subbitsize
, submode
, res
);
2089 /* Expand a binary operator which has both signed and unsigned forms.
2090 UOPTAB is the optab for unsigned operations, and SOPTAB is for
2093 If we widen unsigned operands, we may use a signed wider operation instead
2094 of an unsigned wider operation, since the result would be the same. */
2097 sign_expand_binop (enum machine_mode mode
, optab uoptab
, optab soptab
,
2098 rtx op0
, rtx op1
, rtx target
, int unsignedp
,
2099 enum optab_methods methods
)
2102 optab direct_optab
= unsignedp
? uoptab
: soptab
;
2103 struct optab wide_soptab
;
2105 /* Do it without widening, if possible. */
2106 temp
= expand_binop (mode
, direct_optab
, op0
, op1
, target
,
2107 unsignedp
, OPTAB_DIRECT
);
2108 if (temp
|| methods
== OPTAB_DIRECT
)
2111 /* Try widening to a signed int. Make a fake signed optab that
2112 hides any signed insn for direct use. */
2113 wide_soptab
= *soptab
;
2114 wide_soptab
.handlers
[(int) mode
].insn_code
= CODE_FOR_nothing
;
2115 wide_soptab
.handlers
[(int) mode
].libfunc
= 0;
2117 temp
= expand_binop (mode
, &wide_soptab
, op0
, op1
, target
,
2118 unsignedp
, OPTAB_WIDEN
);
2120 /* For unsigned operands, try widening to an unsigned int. */
2121 if (temp
== 0 && unsignedp
)
2122 temp
= expand_binop (mode
, uoptab
, op0
, op1
, target
,
2123 unsignedp
, OPTAB_WIDEN
);
2124 if (temp
|| methods
== OPTAB_WIDEN
)
2127 /* Use the right width lib call if that exists. */
2128 temp
= expand_binop (mode
, direct_optab
, op0
, op1
, target
, unsignedp
, OPTAB_LIB
);
2129 if (temp
|| methods
== OPTAB_LIB
)
2132 /* Must widen and use a lib call, use either signed or unsigned. */
2133 temp
= expand_binop (mode
, &wide_soptab
, op0
, op1
, target
,
2134 unsignedp
, methods
);
2138 return expand_binop (mode
, uoptab
, op0
, op1
, target
,
2139 unsignedp
, methods
);
2143 /* Generate code to perform an operation specified by UNOPPTAB
2144 on operand OP0, with two results to TARG0 and TARG1.
2145 We assume that the order of the operands for the instruction
2146 is TARG0, TARG1, OP0.
2148 Either TARG0 or TARG1 may be zero, but what that means is that
2149 the result is not actually wanted. We will generate it into
2150 a dummy pseudo-reg and discard it. They may not both be zero.
2152 Returns 1 if this operation can be performed; 0 if not. */
2155 expand_twoval_unop (optab unoptab
, rtx op0
, rtx targ0
, rtx targ1
,
2158 enum machine_mode mode
= GET_MODE (targ0
? targ0
: targ1
);
2159 enum mode_class
class;
2160 enum machine_mode wider_mode
;
2161 rtx entry_last
= get_last_insn ();
2164 class = GET_MODE_CLASS (mode
);
2167 op0
= force_not_mem (op0
);
2170 targ0
= gen_reg_rtx (mode
);
2172 targ1
= gen_reg_rtx (mode
);
2174 /* Record where to go back to if we fail. */
2175 last
= get_last_insn ();
2177 if (unoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2179 int icode
= (int) unoptab
->handlers
[(int) mode
].insn_code
;
2180 enum machine_mode mode0
= insn_data
[icode
].operand
[2].mode
;
2184 if (GET_MODE (xop0
) != VOIDmode
2185 && GET_MODE (xop0
) != mode0
)
2186 xop0
= convert_to_mode (mode0
, xop0
, unsignedp
);
2188 /* Now, if insn doesn't accept these operands, put them into pseudos. */
2189 if (! (*insn_data
[icode
].operand
[2].predicate
) (xop0
, mode0
))
2190 xop0
= copy_to_mode_reg (mode0
, xop0
);
2192 /* We could handle this, but we should always be called with a pseudo
2193 for our targets and all insns should take them as outputs. */
2194 if (! (*insn_data
[icode
].operand
[0].predicate
) (targ0
, mode
)
2195 || ! (*insn_data
[icode
].operand
[1].predicate
) (targ1
, mode
))
2198 pat
= GEN_FCN (icode
) (targ0
, targ1
, xop0
);
2205 delete_insns_since (last
);
2208 /* It can't be done in this mode. Can we do it in a wider mode? */
2210 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2212 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2213 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2215 if (unoptab
->handlers
[(int) wider_mode
].insn_code
2216 != CODE_FOR_nothing
)
2218 rtx t0
= gen_reg_rtx (wider_mode
);
2219 rtx t1
= gen_reg_rtx (wider_mode
);
2220 rtx cop0
= convert_modes (wider_mode
, mode
, op0
, unsignedp
);
2222 if (expand_twoval_unop (unoptab
, cop0
, t0
, t1
, unsignedp
))
2224 convert_move (targ0
, t0
, unsignedp
);
2225 convert_move (targ1
, t1
, unsignedp
);
2229 delete_insns_since (last
);
2234 delete_insns_since (entry_last
);
2238 /* Generate code to perform an operation specified by BINOPTAB
2239 on operands OP0 and OP1, with two results to TARG1 and TARG2.
2240 We assume that the order of the operands for the instruction
2241 is TARG0, OP0, OP1, TARG1, which would fit a pattern like
2242 [(set TARG0 (operate OP0 OP1)) (set TARG1 (operate ...))].
2244 Either TARG0 or TARG1 may be zero, but what that means is that
2245 the result is not actually wanted. We will generate it into
2246 a dummy pseudo-reg and discard it. They may not both be zero.
2248 Returns 1 if this operation can be performed; 0 if not. */
2251 expand_twoval_binop (optab binoptab
, rtx op0
, rtx op1
, rtx targ0
, rtx targ1
,
2254 enum machine_mode mode
= GET_MODE (targ0
? targ0
: targ1
);
2255 enum mode_class
class;
2256 enum machine_mode wider_mode
;
2257 rtx entry_last
= get_last_insn ();
2260 class = GET_MODE_CLASS (mode
);
2264 op0
= force_not_mem (op0
);
2265 op1
= force_not_mem (op1
);
2268 /* If we are inside an appropriately-short loop and one operand is an
2269 expensive constant, force it into a register. */
2270 if (CONSTANT_P (op0
) && preserve_subexpressions_p ()
2271 && rtx_cost (op0
, binoptab
->code
) > COSTS_N_INSNS (1))
2272 op0
= force_reg (mode
, op0
);
2274 if (CONSTANT_P (op1
) && preserve_subexpressions_p ()
2275 && rtx_cost (op1
, binoptab
->code
) > COSTS_N_INSNS (1))
2276 op1
= force_reg (mode
, op1
);
2279 targ0
= gen_reg_rtx (mode
);
2281 targ1
= gen_reg_rtx (mode
);
2283 /* Record where to go back to if we fail. */
2284 last
= get_last_insn ();
2286 if (binoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2288 int icode
= (int) binoptab
->handlers
[(int) mode
].insn_code
;
2289 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
2290 enum machine_mode mode1
= insn_data
[icode
].operand
[2].mode
;
2292 rtx xop0
= op0
, xop1
= op1
;
2294 /* In case the insn wants input operands in modes different from
2295 those of the actual operands, convert the operands. It would
2296 seem that we don't need to convert CONST_INTs, but we do, so
2297 that they're properly zero-extended, sign-extended or truncated
2300 if (GET_MODE (op0
) != mode0
&& mode0
!= VOIDmode
)
2301 xop0
= convert_modes (mode0
,
2302 GET_MODE (op0
) != VOIDmode
2307 if (GET_MODE (op1
) != mode1
&& mode1
!= VOIDmode
)
2308 xop1
= convert_modes (mode1
,
2309 GET_MODE (op1
) != VOIDmode
2314 /* Now, if insn doesn't accept these operands, put them into pseudos. */
2315 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
))
2316 xop0
= copy_to_mode_reg (mode0
, xop0
);
2318 if (! (*insn_data
[icode
].operand
[2].predicate
) (xop1
, mode1
))
2319 xop1
= copy_to_mode_reg (mode1
, xop1
);
2321 /* We could handle this, but we should always be called with a pseudo
2322 for our targets and all insns should take them as outputs. */
2323 if (! (*insn_data
[icode
].operand
[0].predicate
) (targ0
, mode
)
2324 || ! (*insn_data
[icode
].operand
[3].predicate
) (targ1
, mode
))
2327 pat
= GEN_FCN (icode
) (targ0
, xop0
, xop1
, targ1
);
2334 delete_insns_since (last
);
2337 /* It can't be done in this mode. Can we do it in a wider mode? */
2339 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2341 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2342 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2344 if (binoptab
->handlers
[(int) wider_mode
].insn_code
2345 != CODE_FOR_nothing
)
2347 rtx t0
= gen_reg_rtx (wider_mode
);
2348 rtx t1
= gen_reg_rtx (wider_mode
);
2349 rtx cop0
= convert_modes (wider_mode
, mode
, op0
, unsignedp
);
2350 rtx cop1
= convert_modes (wider_mode
, mode
, op1
, unsignedp
);
2352 if (expand_twoval_binop (binoptab
, cop0
, cop1
,
2355 convert_move (targ0
, t0
, unsignedp
);
2356 convert_move (targ1
, t1
, unsignedp
);
2360 delete_insns_since (last
);
2365 delete_insns_since (entry_last
);
2369 /* Wrapper around expand_unop which takes an rtx code to specify
2370 the operation to perform, not an optab pointer. All other
2371 arguments are the same. */
2373 expand_simple_unop (enum machine_mode mode
, enum rtx_code code
, rtx op0
,
2374 rtx target
, int unsignedp
)
2376 optab unop
= code_to_optab
[(int) code
];
2380 return expand_unop (mode
, unop
, op0
, target
, unsignedp
);
2386 (clz:wide (zero_extend:wide x)) - ((width wide) - (width narrow)). */
2388 widen_clz (enum machine_mode mode
, rtx op0
, rtx target
)
2390 enum mode_class
class = GET_MODE_CLASS (mode
);
2391 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2393 enum machine_mode wider_mode
;
2394 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2395 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2397 if (clz_optab
->handlers
[(int) wider_mode
].insn_code
2398 != CODE_FOR_nothing
)
2400 rtx xop0
, temp
, last
;
2402 last
= get_last_insn ();
2405 target
= gen_reg_rtx (mode
);
2406 xop0
= widen_operand (op0
, wider_mode
, mode
, true, false);
2407 temp
= expand_unop (wider_mode
, clz_optab
, xop0
, NULL_RTX
, true);
2409 temp
= expand_binop (wider_mode
, sub_optab
, temp
,
2410 GEN_INT (GET_MODE_BITSIZE (wider_mode
)
2411 - GET_MODE_BITSIZE (mode
)),
2412 target
, true, OPTAB_DIRECT
);
2414 delete_insns_since (last
);
2423 /* Try calculating (parity x) as (and (popcount x) 1), where
2424 popcount can also be done in a wider mode. */
2426 expand_parity (enum machine_mode mode
, rtx op0
, rtx target
)
2428 enum mode_class
class = GET_MODE_CLASS (mode
);
2429 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2431 enum machine_mode wider_mode
;
2432 for (wider_mode
= mode
; wider_mode
!= VOIDmode
;
2433 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2435 if (popcount_optab
->handlers
[(int) wider_mode
].insn_code
2436 != CODE_FOR_nothing
)
2438 rtx xop0
, temp
, last
;
2440 last
= get_last_insn ();
2443 target
= gen_reg_rtx (mode
);
2444 xop0
= widen_operand (op0
, wider_mode
, mode
, true, false);
2445 temp
= expand_unop (wider_mode
, popcount_optab
, xop0
, NULL_RTX
,
2448 temp
= expand_binop (wider_mode
, and_optab
, temp
, const1_rtx
,
2449 target
, true, OPTAB_DIRECT
);
2451 delete_insns_since (last
);
2460 /* Generate code to perform an operation specified by UNOPTAB
2461 on operand OP0, with result having machine-mode MODE.
2463 UNSIGNEDP is for the case where we have to widen the operands
2464 to perform the operation. It says to use zero-extension.
2466 If TARGET is nonzero, the value
2467 is generated there, if it is convenient to do so.
2468 In all cases an rtx is returned for the locus of the value;
2469 this may or may not be TARGET. */
2472 expand_unop (enum machine_mode mode
, optab unoptab
, rtx op0
, rtx target
,
2475 enum mode_class
class;
2476 enum machine_mode wider_mode
;
2478 rtx last
= get_last_insn ();
2481 class = GET_MODE_CLASS (mode
);
2484 op0
= force_not_mem (op0
);
2486 if (unoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2488 int icode
= (int) unoptab
->handlers
[(int) mode
].insn_code
;
2489 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
2495 temp
= gen_reg_rtx (mode
);
2497 if (GET_MODE (xop0
) != VOIDmode
2498 && GET_MODE (xop0
) != mode0
)
2499 xop0
= convert_to_mode (mode0
, xop0
, unsignedp
);
2501 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
2503 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
))
2504 xop0
= copy_to_mode_reg (mode0
, xop0
);
2506 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, mode
))
2507 temp
= gen_reg_rtx (mode
);
2509 pat
= GEN_FCN (icode
) (temp
, xop0
);
2512 if (INSN_P (pat
) && NEXT_INSN (pat
) != NULL_RTX
2513 && ! add_equal_note (pat
, temp
, unoptab
->code
, xop0
, NULL_RTX
))
2515 delete_insns_since (last
);
2516 return expand_unop (mode
, unoptab
, op0
, NULL_RTX
, unsignedp
);
2524 delete_insns_since (last
);
2527 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2529 /* Widening clz needs special treatment. */
2530 if (unoptab
== clz_optab
)
2532 temp
= widen_clz (mode
, op0
, target
);
2539 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2540 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2541 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2543 if (unoptab
->handlers
[(int) wider_mode
].insn_code
!= CODE_FOR_nothing
)
2547 /* For certain operations, we need not actually extend
2548 the narrow operand, as long as we will truncate the
2549 results to the same narrowness. */
2551 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
,
2552 (unoptab
== neg_optab
2553 || unoptab
== one_cmpl_optab
)
2554 && class == MODE_INT
);
2556 temp
= expand_unop (wider_mode
, unoptab
, xop0
, NULL_RTX
,
2561 if (class != MODE_INT
)
2564 target
= gen_reg_rtx (mode
);
2565 convert_move (target
, temp
, 0);
2569 return gen_lowpart (mode
, temp
);
2572 delete_insns_since (last
);
2576 /* These can be done a word at a time. */
2577 if (unoptab
== one_cmpl_optab
2578 && class == MODE_INT
2579 && GET_MODE_SIZE (mode
) > UNITS_PER_WORD
2580 && unoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
2585 if (target
== 0 || target
== op0
)
2586 target
= gen_reg_rtx (mode
);
2590 /* Do the actual arithmetic. */
2591 for (i
= 0; i
< GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
; i
++)
2593 rtx target_piece
= operand_subword (target
, i
, 1, mode
);
2594 rtx x
= expand_unop (word_mode
, unoptab
,
2595 operand_subword_force (op0
, i
, mode
),
2596 target_piece
, unsignedp
);
2598 if (target_piece
!= x
)
2599 emit_move_insn (target_piece
, x
);
2602 insns
= get_insns ();
2605 emit_no_conflict_block (insns
, target
, op0
, NULL_RTX
,
2606 gen_rtx_fmt_e (unoptab
->code
, mode
,
2611 /* Open-code the complex negation operation. */
2612 else if (unoptab
->code
== NEG
2613 && (class == MODE_COMPLEX_FLOAT
|| class == MODE_COMPLEX_INT
))
2619 /* Find the correct mode for the real and imaginary parts. */
2620 enum machine_mode submode
= GET_MODE_INNER (mode
);
2622 if (submode
== BLKmode
)
2626 target
= gen_reg_rtx (mode
);
2630 target_piece
= gen_imagpart (submode
, target
);
2631 x
= expand_unop (submode
, unoptab
,
2632 gen_imagpart (submode
, op0
),
2633 target_piece
, unsignedp
);
2634 if (target_piece
!= x
)
2635 emit_move_insn (target_piece
, x
);
2637 target_piece
= gen_realpart (submode
, target
);
2638 x
= expand_unop (submode
, unoptab
,
2639 gen_realpart (submode
, op0
),
2640 target_piece
, unsignedp
);
2641 if (target_piece
!= x
)
2642 emit_move_insn (target_piece
, x
);
2647 emit_no_conflict_block (seq
, target
, op0
, 0,
2648 gen_rtx_fmt_e (unoptab
->code
, mode
,
2653 /* Try negating floating point values by flipping the sign bit. */
2654 if (unoptab
->code
== NEG
&& class == MODE_FLOAT
2655 && GET_MODE_BITSIZE (mode
) <= 2 * HOST_BITS_PER_WIDE_INT
)
2657 const struct real_format
*fmt
= REAL_MODE_FORMAT (mode
);
2658 enum machine_mode imode
= int_mode_for_mode (mode
);
2659 int bitpos
= (fmt
!= 0) ? fmt
->signbit
: -1;
2661 if (imode
!= BLKmode
&& bitpos
>= 0 && fmt
->has_signed_zero
)
2663 HOST_WIDE_INT hi
, lo
;
2664 rtx last
= get_last_insn ();
2666 /* Handle targets with different FP word orders. */
2667 if (FLOAT_WORDS_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
2669 int nwords
= GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
;
2670 int word
= nwords
- (bitpos
/ BITS_PER_WORD
) - 1;
2671 bitpos
= word
* BITS_PER_WORD
+ bitpos
% BITS_PER_WORD
;
2674 if (bitpos
< HOST_BITS_PER_WIDE_INT
)
2677 lo
= (HOST_WIDE_INT
) 1 << bitpos
;
2681 hi
= (HOST_WIDE_INT
) 1 << (bitpos
- HOST_BITS_PER_WIDE_INT
);
2684 temp
= expand_binop (imode
, xor_optab
,
2685 gen_lowpart (imode
, op0
),
2686 immed_double_const (lo
, hi
, imode
),
2687 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2692 target
= gen_reg_rtx (mode
);
2693 insn
= emit_move_insn (target
, gen_lowpart (mode
, temp
));
2694 set_unique_reg_note (insn
, REG_EQUAL
,
2695 gen_rtx_fmt_e (NEG
, mode
,
2699 delete_insns_since (last
);
2703 /* Try calculating parity (x) as popcount (x) % 2. */
2704 if (unoptab
== parity_optab
)
2706 temp
= expand_parity (mode
, op0
, target
);
2711 /* If there is no negation pattern, try subtracting from zero. */
2712 if (unoptab
== neg_optab
&& class == MODE_INT
)
2714 temp
= expand_binop (mode
, sub_optab
, CONST0_RTX (mode
), op0
,
2715 target
, unsignedp
, OPTAB_DIRECT
);
2721 /* Now try a library call in this mode. */
2722 if (unoptab
->handlers
[(int) mode
].libfunc
)
2726 enum machine_mode outmode
= mode
;
2728 /* All of these functions return small values. Thus we choose to
2729 have them return something that isn't a double-word. */
2730 if (unoptab
== ffs_optab
|| unoptab
== clz_optab
|| unoptab
== ctz_optab
2731 || unoptab
== popcount_optab
|| unoptab
== parity_optab
)
2733 = GET_MODE (hard_libcall_value (TYPE_MODE (integer_type_node
)));
2737 /* Pass 1 for NO_QUEUE so we don't lose any increments
2738 if the libcall is cse'd or moved. */
2739 value
= emit_library_call_value (unoptab
->handlers
[(int) mode
].libfunc
,
2740 NULL_RTX
, LCT_CONST
, outmode
,
2742 insns
= get_insns ();
2745 target
= gen_reg_rtx (outmode
);
2746 emit_libcall_block (insns
, target
, value
,
2747 gen_rtx_fmt_e (unoptab
->code
, mode
, op0
));
2752 if (class == MODE_VECTOR_FLOAT
|| class == MODE_VECTOR_INT
)
2753 return expand_vector_unop (mode
, unoptab
, op0
, target
, unsignedp
);
2755 /* It can't be done in this mode. Can we do it in a wider mode? */
2757 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2759 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2760 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2762 if ((unoptab
->handlers
[(int) wider_mode
].insn_code
2763 != CODE_FOR_nothing
)
2764 || unoptab
->handlers
[(int) wider_mode
].libfunc
)
2768 /* For certain operations, we need not actually extend
2769 the narrow operand, as long as we will truncate the
2770 results to the same narrowness. */
2772 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
,
2773 (unoptab
== neg_optab
2774 || unoptab
== one_cmpl_optab
)
2775 && class == MODE_INT
);
2777 temp
= expand_unop (wider_mode
, unoptab
, xop0
, NULL_RTX
,
2780 /* If we are generating clz using wider mode, adjust the
2782 if (unoptab
== clz_optab
&& temp
!= 0)
2783 temp
= expand_binop (wider_mode
, sub_optab
, temp
,
2784 GEN_INT (GET_MODE_BITSIZE (wider_mode
)
2785 - GET_MODE_BITSIZE (mode
)),
2786 target
, true, OPTAB_DIRECT
);
2790 if (class != MODE_INT
)
2793 target
= gen_reg_rtx (mode
);
2794 convert_move (target
, temp
, 0);
2798 return gen_lowpart (mode
, temp
);
2801 delete_insns_since (last
);
2806 /* If there is no negate operation, try doing a subtract from zero.
2807 The US Software GOFAST library needs this. */
2808 if (unoptab
->code
== NEG
)
2811 temp
= expand_binop (mode
,
2812 unoptab
== negv_optab
? subv_optab
: sub_optab
,
2813 CONST0_RTX (mode
), op0
,
2814 target
, unsignedp
, OPTAB_LIB_WIDEN
);
2822 /* Emit code to compute the absolute value of OP0, with result to
2823 TARGET if convenient. (TARGET may be 0.) The return value says
2824 where the result actually is to be found.
2826 MODE is the mode of the operand; the mode of the result is
2827 different but can be deduced from MODE.
2832 expand_abs_nojump (enum machine_mode mode
, rtx op0
, rtx target
,
2833 int result_unsignedp
)
2838 result_unsignedp
= 1;
2840 /* First try to do it with a special abs instruction. */
2841 temp
= expand_unop (mode
, result_unsignedp
? abs_optab
: absv_optab
,
2846 /* For floating point modes, try clearing the sign bit. */
2847 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
2848 && GET_MODE_BITSIZE (mode
) <= 2 * HOST_BITS_PER_WIDE_INT
)
2850 const struct real_format
*fmt
= REAL_MODE_FORMAT (mode
);
2851 enum machine_mode imode
= int_mode_for_mode (mode
);
2852 int bitpos
= (fmt
!= 0) ? fmt
->signbit
: -1;
2854 if (imode
!= BLKmode
&& bitpos
>= 0)
2856 HOST_WIDE_INT hi
, lo
;
2857 rtx last
= get_last_insn ();
2859 /* Handle targets with different FP word orders. */
2860 if (FLOAT_WORDS_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
2862 int nwords
= GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
;
2863 int word
= nwords
- (bitpos
/ BITS_PER_WORD
) - 1;
2864 bitpos
= word
* BITS_PER_WORD
+ bitpos
% BITS_PER_WORD
;
2867 if (bitpos
< HOST_BITS_PER_WIDE_INT
)
2870 lo
= (HOST_WIDE_INT
) 1 << bitpos
;
2874 hi
= (HOST_WIDE_INT
) 1 << (bitpos
- HOST_BITS_PER_WIDE_INT
);
2877 temp
= expand_binop (imode
, and_optab
,
2878 gen_lowpart (imode
, op0
),
2879 immed_double_const (~lo
, ~hi
, imode
),
2880 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2885 target
= gen_reg_rtx (mode
);
2886 insn
= emit_move_insn (target
, gen_lowpart (mode
, temp
));
2887 set_unique_reg_note (insn
, REG_EQUAL
,
2888 gen_rtx_fmt_e (ABS
, mode
,
2892 delete_insns_since (last
);
2896 /* If we have a MAX insn, we can do this as MAX (x, -x). */
2897 if (smax_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2899 rtx last
= get_last_insn ();
2901 temp
= expand_unop (mode
, neg_optab
, op0
, NULL_RTX
, 0);
2903 temp
= expand_binop (mode
, smax_optab
, op0
, temp
, target
, 0,
2909 delete_insns_since (last
);
2912 /* If this machine has expensive jumps, we can do integer absolute
2913 value of X as (((signed) x >> (W-1)) ^ x) - ((signed) x >> (W-1)),
2914 where W is the width of MODE. */
2916 if (GET_MODE_CLASS (mode
) == MODE_INT
&& BRANCH_COST
>= 2)
2918 rtx extended
= expand_shift (RSHIFT_EXPR
, mode
, op0
,
2919 size_int (GET_MODE_BITSIZE (mode
) - 1),
2922 temp
= expand_binop (mode
, xor_optab
, extended
, op0
, target
, 0,
2925 temp
= expand_binop (mode
, result_unsignedp
? sub_optab
: subv_optab
,
2926 temp
, extended
, target
, 0, OPTAB_LIB_WIDEN
);
2936 expand_abs (enum machine_mode mode
, rtx op0
, rtx target
,
2937 int result_unsignedp
, int safe
)
2942 result_unsignedp
= 1;
2944 temp
= expand_abs_nojump (mode
, op0
, target
, result_unsignedp
);
2948 /* If that does not win, use conditional jump and negate. */
2950 /* It is safe to use the target if it is the same
2951 as the source if this is also a pseudo register */
2952 if (op0
== target
&& REG_P (op0
)
2953 && REGNO (op0
) >= FIRST_PSEUDO_REGISTER
)
2956 op1
= gen_label_rtx ();
2957 if (target
== 0 || ! safe
2958 || GET_MODE (target
) != mode
2959 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
2961 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
2962 target
= gen_reg_rtx (mode
);
2964 emit_move_insn (target
, op0
);
2967 /* If this mode is an integer too wide to compare properly,
2968 compare word by word. Rely on CSE to optimize constant cases. */
2969 if (GET_MODE_CLASS (mode
) == MODE_INT
2970 && ! can_compare_p (GE
, mode
, ccp_jump
))
2971 do_jump_by_parts_greater_rtx (mode
, 0, target
, const0_rtx
,
2974 do_compare_rtx_and_jump (target
, CONST0_RTX (mode
), GE
, 0, mode
,
2975 NULL_RTX
, NULL_RTX
, op1
);
2977 op0
= expand_unop (mode
, result_unsignedp
? neg_optab
: negv_optab
,
2980 emit_move_insn (target
, op0
);
2986 /* Emit code to compute the absolute value of OP0, with result to
2987 TARGET if convenient. (TARGET may be 0.) The return value says
2988 where the result actually is to be found.
2990 MODE is the mode of the operand; the mode of the result is
2991 different but can be deduced from MODE.
2993 UNSIGNEDP is relevant for complex integer modes. */
2996 expand_complex_abs (enum machine_mode mode
, rtx op0
, rtx target
,
2999 enum mode_class
class = GET_MODE_CLASS (mode
);
3000 enum machine_mode wider_mode
;
3002 rtx entry_last
= get_last_insn ();
3005 optab this_abs_optab
;
3007 /* Find the correct mode for the real and imaginary parts. */
3008 enum machine_mode submode
= GET_MODE_INNER (mode
);
3010 if (submode
== BLKmode
)
3014 op0
= force_not_mem (op0
);
3016 last
= get_last_insn ();
3018 this_abs_optab
= ! unsignedp
&& flag_trapv
3019 && (GET_MODE_CLASS(mode
) == MODE_INT
)
3020 ? absv_optab
: abs_optab
;
3022 if (this_abs_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
3024 int icode
= (int) this_abs_optab
->handlers
[(int) mode
].insn_code
;
3025 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
3031 temp
= gen_reg_rtx (submode
);
3033 if (GET_MODE (xop0
) != VOIDmode
3034 && GET_MODE (xop0
) != mode0
)
3035 xop0
= convert_to_mode (mode0
, xop0
, unsignedp
);
3037 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
3039 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
))
3040 xop0
= copy_to_mode_reg (mode0
, xop0
);
3042 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, submode
))
3043 temp
= gen_reg_rtx (submode
);
3045 pat
= GEN_FCN (icode
) (temp
, xop0
);
3048 if (INSN_P (pat
) && NEXT_INSN (pat
) != NULL_RTX
3049 && ! add_equal_note (pat
, temp
, this_abs_optab
->code
, xop0
,
3052 delete_insns_since (last
);
3053 return expand_unop (mode
, this_abs_optab
, op0
, NULL_RTX
,
3062 delete_insns_since (last
);
3065 /* It can't be done in this mode. Can we open-code it in a wider mode? */
3067 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
3068 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
3070 if (this_abs_optab
->handlers
[(int) wider_mode
].insn_code
3071 != CODE_FOR_nothing
)
3075 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 /* Open-code the complex absolute-value operation
3096 if we can open-code sqrt. Otherwise it's not worth while. */
3097 if (sqrt_optab
->handlers
[(int) submode
].insn_code
!= CODE_FOR_nothing
3100 rtx real
, imag
, total
;
3102 real
= gen_realpart (submode
, op0
);
3103 imag
= gen_imagpart (submode
, op0
);
3105 /* Square both parts. */
3106 real
= expand_mult (submode
, real
, real
, NULL_RTX
, 0);
3107 imag
= expand_mult (submode
, imag
, imag
, NULL_RTX
, 0);
3109 /* Sum the parts. */
3110 total
= expand_binop (submode
, add_optab
, real
, imag
, NULL_RTX
,
3111 0, OPTAB_LIB_WIDEN
);
3113 /* Get sqrt in TARGET. Set TARGET to where the result is. */
3114 target
= expand_unop (submode
, sqrt_optab
, total
, target
, 0);
3116 delete_insns_since (last
);
3121 /* Now try a library call in this mode. */
3122 if (this_abs_optab
->handlers
[(int) mode
].libfunc
)
3129 /* Pass 1 for NO_QUEUE so we don't lose any increments
3130 if the libcall is cse'd or moved. */
3131 value
= emit_library_call_value (abs_optab
->handlers
[(int) mode
].libfunc
,
3132 NULL_RTX
, LCT_CONST
, submode
, 1, op0
, mode
);
3133 insns
= get_insns ();
3136 target
= gen_reg_rtx (submode
);
3137 emit_libcall_block (insns
, target
, value
,
3138 gen_rtx_fmt_e (this_abs_optab
->code
, mode
, op0
));
3143 /* It can't be done in this mode. Can we do it in a wider mode? */
3145 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
3146 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
3148 if ((this_abs_optab
->handlers
[(int) wider_mode
].insn_code
3149 != CODE_FOR_nothing
)
3150 || this_abs_optab
->handlers
[(int) wider_mode
].libfunc
)
3154 xop0
= convert_modes (wider_mode
, mode
, xop0
, unsignedp
);
3156 temp
= expand_complex_abs (wider_mode
, xop0
, NULL_RTX
, unsignedp
);
3160 if (class != MODE_COMPLEX_INT
)
3163 target
= gen_reg_rtx (submode
);
3164 convert_move (target
, temp
, 0);
3168 return gen_lowpart (submode
, temp
);
3171 delete_insns_since (last
);
3175 delete_insns_since (entry_last
);
3179 /* Generate an instruction whose insn-code is INSN_CODE,
3180 with two operands: an output TARGET and an input OP0.
3181 TARGET *must* be nonzero, and the output is always stored there.
3182 CODE is an rtx code such that (CODE OP0) is an rtx that describes
3183 the value that is stored into TARGET. */
3186 emit_unop_insn (int icode
, rtx target
, rtx op0
, enum rtx_code code
)
3189 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
3194 /* Sign and zero extension from memory is often done specially on
3195 RISC machines, so forcing into a register here can pessimize
3197 if (flag_force_mem
&& code
!= SIGN_EXTEND
&& code
!= ZERO_EXTEND
)
3198 op0
= force_not_mem (op0
);
3200 /* Now, if insn does not accept our operands, put them into pseudos. */
3202 if (! (*insn_data
[icode
].operand
[1].predicate
) (op0
, mode0
))
3203 op0
= copy_to_mode_reg (mode0
, op0
);
3205 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, GET_MODE (temp
))
3206 || (flag_force_mem
&& MEM_P (temp
)))
3207 temp
= gen_reg_rtx (GET_MODE (temp
));
3209 pat
= GEN_FCN (icode
) (temp
, op0
);
3211 if (INSN_P (pat
) && NEXT_INSN (pat
) != NULL_RTX
&& code
!= UNKNOWN
)
3212 add_equal_note (pat
, temp
, code
, op0
, NULL_RTX
);
3217 emit_move_insn (target
, temp
);
3220 /* Emit code to perform a series of operations on a multi-word quantity, one
3223 Such a block is preceded by a CLOBBER of the output, consists of multiple
3224 insns, each setting one word of the output, and followed by a SET copying
3225 the output to itself.
3227 Each of the insns setting words of the output receives a REG_NO_CONFLICT
3228 note indicating that it doesn't conflict with the (also multi-word)
3229 inputs. The entire block is surrounded by REG_LIBCALL and REG_RETVAL
3232 INSNS is a block of code generated to perform the operation, not including
3233 the CLOBBER and final copy. All insns that compute intermediate values
3234 are first emitted, followed by the block as described above.
3236 TARGET, OP0, and OP1 are the output and inputs of the operations,
3237 respectively. OP1 may be zero for a unary operation.
3239 EQUIV, if nonzero, is an expression to be placed into a REG_EQUAL note
3242 If TARGET is not a register, INSNS is simply emitted with no special
3243 processing. Likewise if anything in INSNS is not an INSN or if
3244 there is a libcall block inside INSNS.
3246 The final insn emitted is returned. */
3249 emit_no_conflict_block (rtx insns
, rtx target
, rtx op0
, rtx op1
, rtx equiv
)
3251 rtx prev
, next
, first
, last
, insn
;
3253 if (!REG_P (target
) || reload_in_progress
)
3254 return emit_insn (insns
);
3256 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3257 if (!NONJUMP_INSN_P (insn
)
3258 || find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
))
3259 return emit_insn (insns
);
3261 /* First emit all insns that do not store into words of the output and remove
3262 these from the list. */
3263 for (insn
= insns
; insn
; insn
= next
)
3268 next
= NEXT_INSN (insn
);
3270 /* Some ports (cris) create a libcall regions at their own. We must
3271 avoid any potential nesting of LIBCALLs. */
3272 if ((note
= find_reg_note (insn
, REG_LIBCALL
, NULL
)) != NULL
)
3273 remove_note (insn
, note
);
3274 if ((note
= find_reg_note (insn
, REG_RETVAL
, NULL
)) != NULL
)
3275 remove_note (insn
, note
);
3277 if (GET_CODE (PATTERN (insn
)) == SET
|| GET_CODE (PATTERN (insn
)) == USE
3278 || GET_CODE (PATTERN (insn
)) == CLOBBER
)
3279 set
= PATTERN (insn
);
3280 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
3282 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
3283 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
3285 set
= XVECEXP (PATTERN (insn
), 0, i
);
3293 if (! reg_overlap_mentioned_p (target
, SET_DEST (set
)))
3295 if (PREV_INSN (insn
))
3296 NEXT_INSN (PREV_INSN (insn
)) = next
;
3301 PREV_INSN (next
) = PREV_INSN (insn
);
3307 prev
= get_last_insn ();
3309 /* Now write the CLOBBER of the output, followed by the setting of each
3310 of the words, followed by the final copy. */
3311 if (target
!= op0
&& target
!= op1
)
3312 emit_insn (gen_rtx_CLOBBER (VOIDmode
, target
));
3314 for (insn
= insns
; insn
; insn
= next
)
3316 next
= NEXT_INSN (insn
);
3319 if (op1
&& REG_P (op1
))
3320 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT
, op1
,
3323 if (op0
&& REG_P (op0
))
3324 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT
, op0
,
3328 if (mov_optab
->handlers
[(int) GET_MODE (target
)].insn_code
3329 != CODE_FOR_nothing
)
3331 last
= emit_move_insn (target
, target
);
3333 set_unique_reg_note (last
, REG_EQUAL
, equiv
);
3337 last
= get_last_insn ();
3339 /* Remove any existing REG_EQUAL note from "last", or else it will
3340 be mistaken for a note referring to the full contents of the
3341 alleged libcall value when found together with the REG_RETVAL
3342 note added below. An existing note can come from an insn
3343 expansion at "last". */
3344 remove_note (last
, find_reg_note (last
, REG_EQUAL
, NULL_RTX
));
3348 first
= get_insns ();
3350 first
= NEXT_INSN (prev
);
3352 /* Encapsulate the block so it gets manipulated as a unit. */
3353 REG_NOTES (first
) = gen_rtx_INSN_LIST (REG_LIBCALL
, last
,
3355 REG_NOTES (last
) = gen_rtx_INSN_LIST (REG_RETVAL
, first
, REG_NOTES (last
));
3360 /* Emit code to make a call to a constant function or a library call.
3362 INSNS is a list containing all insns emitted in the call.
3363 These insns leave the result in RESULT. Our block is to copy RESULT
3364 to TARGET, which is logically equivalent to EQUIV.
3366 We first emit any insns that set a pseudo on the assumption that these are
3367 loading constants into registers; doing so allows them to be safely cse'ed
3368 between blocks. Then we emit all the other insns in the block, followed by
3369 an insn to move RESULT to TARGET. This last insn will have a REQ_EQUAL
3370 note with an operand of EQUIV.
3372 Moving assignments to pseudos outside of the block is done to improve
3373 the generated code, but is not required to generate correct code,
3374 hence being unable to move an assignment is not grounds for not making
3375 a libcall block. There are two reasons why it is safe to leave these
3376 insns inside the block: First, we know that these pseudos cannot be
3377 used in generated RTL outside the block since they are created for
3378 temporary purposes within the block. Second, CSE will not record the
3379 values of anything set inside a libcall block, so we know they must
3380 be dead at the end of the block.
3382 Except for the first group of insns (the ones setting pseudos), the
3383 block is delimited by REG_RETVAL and REG_LIBCALL notes. */
3386 emit_libcall_block (rtx insns
, rtx target
, rtx result
, rtx equiv
)
3388 rtx final_dest
= target
;
3389 rtx prev
, next
, first
, last
, insn
;
3391 /* If this is a reg with REG_USERVAR_P set, then it could possibly turn
3392 into a MEM later. Protect the libcall block from this change. */
3393 if (! REG_P (target
) || REG_USERVAR_P (target
))
3394 target
= gen_reg_rtx (GET_MODE (target
));
3396 /* If we're using non-call exceptions, a libcall corresponding to an
3397 operation that may trap may also trap. */
3398 if (flag_non_call_exceptions
&& may_trap_p (equiv
))
3400 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3403 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
3405 if (note
!= 0 && INTVAL (XEXP (note
, 0)) <= 0)
3406 remove_note (insn
, note
);
3410 /* look for any CALL_INSNs in this sequence, and attach a REG_EH_REGION
3411 reg note to indicate that this call cannot throw or execute a nonlocal
3412 goto (unless there is already a REG_EH_REGION note, in which case
3414 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3417 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
3420 XEXP (note
, 0) = constm1_rtx
;
3422 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_EH_REGION
, constm1_rtx
,
3426 /* First emit all insns that set pseudos. Remove them from the list as
3427 we go. Avoid insns that set pseudos which were referenced in previous
3428 insns. These can be generated by move_by_pieces, for example,
3429 to update an address. Similarly, avoid insns that reference things
3430 set in previous insns. */
3432 for (insn
= insns
; insn
; insn
= next
)
3434 rtx set
= single_set (insn
);
3437 /* Some ports (cris) create a libcall regions at their own. We must
3438 avoid any potential nesting of LIBCALLs. */
3439 if ((note
= find_reg_note (insn
, REG_LIBCALL
, NULL
)) != NULL
)
3440 remove_note (insn
, note
);
3441 if ((note
= find_reg_note (insn
, REG_RETVAL
, NULL
)) != NULL
)
3442 remove_note (insn
, note
);
3444 next
= NEXT_INSN (insn
);
3446 if (set
!= 0 && REG_P (SET_DEST (set
))
3447 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
3449 || ((! INSN_P(insns
)
3450 || ! reg_mentioned_p (SET_DEST (set
), PATTERN (insns
)))
3451 && ! reg_used_between_p (SET_DEST (set
), insns
, insn
)
3452 && ! modified_in_p (SET_SRC (set
), insns
)
3453 && ! modified_between_p (SET_SRC (set
), insns
, insn
))))
3455 if (PREV_INSN (insn
))
3456 NEXT_INSN (PREV_INSN (insn
)) = next
;
3461 PREV_INSN (next
) = PREV_INSN (insn
);
3466 /* Some ports use a loop to copy large arguments onto the stack.
3467 Don't move anything outside such a loop. */
3472 prev
= get_last_insn ();
3474 /* Write the remaining insns followed by the final copy. */
3476 for (insn
= insns
; insn
; insn
= next
)
3478 next
= NEXT_INSN (insn
);
3483 last
= emit_move_insn (target
, result
);
3484 if (mov_optab
->handlers
[(int) GET_MODE (target
)].insn_code
3485 != CODE_FOR_nothing
)
3486 set_unique_reg_note (last
, REG_EQUAL
, copy_rtx (equiv
));
3489 /* Remove any existing REG_EQUAL note from "last", or else it will
3490 be mistaken for a note referring to the full contents of the
3491 libcall value when found together with the REG_RETVAL note added
3492 below. An existing note can come from an insn expansion at
3494 remove_note (last
, find_reg_note (last
, REG_EQUAL
, NULL_RTX
));
3497 if (final_dest
!= target
)
3498 emit_move_insn (final_dest
, target
);
3501 first
= get_insns ();
3503 first
= NEXT_INSN (prev
);
3505 /* Encapsulate the block so it gets manipulated as a unit. */
3506 if (!flag_non_call_exceptions
|| !may_trap_p (equiv
))
3508 /* We can't attach the REG_LIBCALL and REG_RETVAL notes
3509 when the encapsulated region would not be in one basic block,
3510 i.e. when there is a control_flow_insn_p insn between FIRST and LAST.
3512 bool attach_libcall_retval_notes
= true;
3513 next
= NEXT_INSN (last
);
3514 for (insn
= first
; insn
!= next
; insn
= NEXT_INSN (insn
))
3515 if (control_flow_insn_p (insn
))
3517 attach_libcall_retval_notes
= false;
3521 if (attach_libcall_retval_notes
)
3523 REG_NOTES (first
) = gen_rtx_INSN_LIST (REG_LIBCALL
, last
,
3525 REG_NOTES (last
) = gen_rtx_INSN_LIST (REG_RETVAL
, first
,
3531 /* Generate code to store zero in X. */
3534 emit_clr_insn (rtx x
)
3536 emit_move_insn (x
, const0_rtx
);
3539 /* Generate code to store 1 in X
3540 assuming it contains zero beforehand. */
3543 emit_0_to_1_insn (rtx x
)
3545 emit_move_insn (x
, const1_rtx
);
3548 /* Nonzero if we can perform a comparison of mode MODE straightforwardly.
3549 PURPOSE describes how this comparison will be used. CODE is the rtx
3550 comparison code we will be using.
3552 ??? Actually, CODE is slightly weaker than that. A target is still
3553 required to implement all of the normal bcc operations, but not
3554 required to implement all (or any) of the unordered bcc operations. */
3557 can_compare_p (enum rtx_code code
, enum machine_mode mode
,
3558 enum can_compare_purpose purpose
)
3562 if (cmp_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
3564 if (purpose
== ccp_jump
)
3565 return bcc_gen_fctn
[(int) code
] != NULL
;
3566 else if (purpose
== ccp_store_flag
)
3567 return setcc_gen_code
[(int) code
] != CODE_FOR_nothing
;
3569 /* There's only one cmov entry point, and it's allowed to fail. */
3572 if (purpose
== ccp_jump
3573 && cbranch_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
3575 if (purpose
== ccp_cmov
3576 && cmov_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
3578 if (purpose
== ccp_store_flag
3579 && cstore_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
3582 mode
= GET_MODE_WIDER_MODE (mode
);
3584 while (mode
!= VOIDmode
);
3589 /* This function is called when we are going to emit a compare instruction that
3590 compares the values found in *PX and *PY, using the rtl operator COMPARISON.
3592 *PMODE is the mode of the inputs (in case they are const_int).
3593 *PUNSIGNEDP nonzero says that the operands are unsigned;
3594 this matters if they need to be widened.
3596 If they have mode BLKmode, then SIZE specifies the size of both operands.
3598 This function performs all the setup necessary so that the caller only has
3599 to emit a single comparison insn. This setup can involve doing a BLKmode
3600 comparison or emitting a library call to perform the comparison if no insn
3601 is available to handle it.
3602 The values which are passed in through pointers can be modified; the caller
3603 should perform the comparison on the modified values. */
3606 prepare_cmp_insn (rtx
*px
, rtx
*py
, enum rtx_code
*pcomparison
, rtx size
,
3607 enum machine_mode
*pmode
, int *punsignedp
,
3608 enum can_compare_purpose purpose
)
3610 enum machine_mode mode
= *pmode
;
3611 rtx x
= *px
, y
= *py
;
3612 int unsignedp
= *punsignedp
;
3613 enum mode_class
class;
3615 class = GET_MODE_CLASS (mode
);
3617 /* They could both be VOIDmode if both args are immediate constants,
3618 but we should fold that at an earlier stage.
3619 With no special code here, this will call abort,
3620 reminding the programmer to implement such folding. */
3622 if (mode
!= BLKmode
&& flag_force_mem
)
3624 /* Load duplicate non-volatile operands once. */
3625 if (rtx_equal_p (x
, y
) && ! volatile_refs_p (x
))
3627 x
= force_not_mem (x
);
3632 x
= force_not_mem (x
);
3633 y
= force_not_mem (y
);
3637 /* If we are inside an appropriately-short loop and one operand is an
3638 expensive constant, force it into a register. */
3639 if (CONSTANT_P (x
) && preserve_subexpressions_p ()
3640 && rtx_cost (x
, COMPARE
) > COSTS_N_INSNS (1))
3641 x
= force_reg (mode
, x
);
3643 if (CONSTANT_P (y
) && preserve_subexpressions_p ()
3644 && rtx_cost (y
, COMPARE
) > COSTS_N_INSNS (1))
3645 y
= force_reg (mode
, y
);
3648 /* Abort if we have a non-canonical comparison. The RTL documentation
3649 states that canonical comparisons are required only for targets which
3651 if (CONSTANT_P (x
) && ! CONSTANT_P (y
))
3655 /* Don't let both operands fail to indicate the mode. */
3656 if (GET_MODE (x
) == VOIDmode
&& GET_MODE (y
) == VOIDmode
)
3657 x
= force_reg (mode
, x
);
3659 /* Handle all BLKmode compares. */
3661 if (mode
== BLKmode
)
3663 enum machine_mode cmp_mode
, result_mode
;
3664 enum insn_code cmp_code
;
3669 = GEN_INT (MIN (MEM_ALIGN (x
), MEM_ALIGN (y
)) / BITS_PER_UNIT
);
3674 /* Try to use a memory block compare insn - either cmpstr
3675 or cmpmem will do. */
3676 for (cmp_mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
3677 cmp_mode
!= VOIDmode
;
3678 cmp_mode
= GET_MODE_WIDER_MODE (cmp_mode
))
3680 cmp_code
= cmpmem_optab
[cmp_mode
];
3681 if (cmp_code
== CODE_FOR_nothing
)
3682 cmp_code
= cmpstr_optab
[cmp_mode
];
3683 if (cmp_code
== CODE_FOR_nothing
)
3686 /* Must make sure the size fits the insn's mode. */
3687 if ((GET_CODE (size
) == CONST_INT
3688 && INTVAL (size
) >= (1 << GET_MODE_BITSIZE (cmp_mode
)))
3689 || (GET_MODE_BITSIZE (GET_MODE (size
))
3690 > GET_MODE_BITSIZE (cmp_mode
)))
3693 result_mode
= insn_data
[cmp_code
].operand
[0].mode
;
3694 result
= gen_reg_rtx (result_mode
);
3695 size
= convert_to_mode (cmp_mode
, size
, 1);
3696 emit_insn (GEN_FCN (cmp_code
) (result
, x
, y
, size
, opalign
));
3700 *pmode
= result_mode
;
3704 /* Otherwise call a library function, memcmp. */
3705 libfunc
= memcmp_libfunc
;
3706 length_type
= sizetype
;
3707 result_mode
= TYPE_MODE (integer_type_node
);
3708 cmp_mode
= TYPE_MODE (length_type
);
3709 size
= convert_to_mode (TYPE_MODE (length_type
), size
,
3710 TYPE_UNSIGNED (length_type
));
3712 result
= emit_library_call_value (libfunc
, 0, LCT_PURE_MAKE_BLOCK
,
3719 *pmode
= result_mode
;
3723 /* Don't allow operands to the compare to trap, as that can put the
3724 compare and branch in different basic blocks. */
3725 if (flag_non_call_exceptions
)
3728 x
= force_reg (mode
, x
);
3730 y
= force_reg (mode
, y
);
3735 if (can_compare_p (*pcomparison
, mode
, purpose
))
3738 /* Handle a lib call just for the mode we are using. */
3740 if (cmp_optab
->handlers
[(int) mode
].libfunc
&& class != MODE_FLOAT
)
3742 rtx libfunc
= cmp_optab
->handlers
[(int) mode
].libfunc
;
3745 /* If we want unsigned, and this mode has a distinct unsigned
3746 comparison routine, use that. */
3747 if (unsignedp
&& ucmp_optab
->handlers
[(int) mode
].libfunc
)
3748 libfunc
= ucmp_optab
->handlers
[(int) mode
].libfunc
;
3750 result
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST_MAKE_BLOCK
,
3751 word_mode
, 2, x
, mode
, y
, mode
);
3753 /* Integer comparison returns a result that must be compared against 1,
3754 so that even if we do an unsigned compare afterward,
3755 there is still a value that can represent the result "less than". */
3762 if (class == MODE_FLOAT
)
3763 prepare_float_lib_cmp (px
, py
, pcomparison
, pmode
, punsignedp
);
3769 /* Before emitting an insn with code ICODE, make sure that X, which is going
3770 to be used for operand OPNUM of the insn, is converted from mode MODE to
3771 WIDER_MODE (UNSIGNEDP determines whether it is an unsigned conversion), and
3772 that it is accepted by the operand predicate. Return the new value. */
3775 prepare_operand (int icode
, rtx x
, int opnum
, enum machine_mode mode
,
3776 enum machine_mode wider_mode
, int unsignedp
)
3778 if (mode
!= wider_mode
)
3779 x
= convert_modes (wider_mode
, mode
, x
, unsignedp
);
3781 if (! (*insn_data
[icode
].operand
[opnum
].predicate
)
3782 (x
, insn_data
[icode
].operand
[opnum
].mode
))
3786 x
= copy_to_mode_reg (insn_data
[icode
].operand
[opnum
].mode
, x
);
3792 /* Subroutine of emit_cmp_and_jump_insns; this function is called when we know
3793 we can do the comparison.
3794 The arguments are the same as for emit_cmp_and_jump_insns; but LABEL may
3795 be NULL_RTX which indicates that only a comparison is to be generated. */
3798 emit_cmp_and_jump_insn_1 (rtx x
, rtx y
, enum machine_mode mode
,
3799 enum rtx_code comparison
, int unsignedp
, rtx label
)
3801 rtx test
= gen_rtx_fmt_ee (comparison
, mode
, x
, y
);
3802 enum mode_class
class = GET_MODE_CLASS (mode
);
3803 enum machine_mode wider_mode
= mode
;
3805 /* Try combined insns first. */
3808 enum insn_code icode
;
3809 PUT_MODE (test
, wider_mode
);
3813 icode
= cbranch_optab
->handlers
[(int) wider_mode
].insn_code
;
3815 if (icode
!= CODE_FOR_nothing
3816 && (*insn_data
[icode
].operand
[0].predicate
) (test
, wider_mode
))
3818 x
= prepare_operand (icode
, x
, 1, mode
, wider_mode
, unsignedp
);
3819 y
= prepare_operand (icode
, y
, 2, mode
, wider_mode
, unsignedp
);
3820 emit_jump_insn (GEN_FCN (icode
) (test
, x
, y
, label
));
3825 /* Handle some compares against zero. */
3826 icode
= (int) tst_optab
->handlers
[(int) wider_mode
].insn_code
;
3827 if (y
== CONST0_RTX (mode
) && icode
!= CODE_FOR_nothing
)
3829 x
= prepare_operand (icode
, x
, 0, mode
, wider_mode
, unsignedp
);
3830 emit_insn (GEN_FCN (icode
) (x
));
3832 emit_jump_insn ((*bcc_gen_fctn
[(int) comparison
]) (label
));
3836 /* Handle compares for which there is a directly suitable insn. */
3838 icode
= (int) cmp_optab
->handlers
[(int) wider_mode
].insn_code
;
3839 if (icode
!= CODE_FOR_nothing
)
3841 x
= prepare_operand (icode
, x
, 0, mode
, wider_mode
, unsignedp
);
3842 y
= prepare_operand (icode
, y
, 1, mode
, wider_mode
, unsignedp
);
3843 emit_insn (GEN_FCN (icode
) (x
, y
));
3845 emit_jump_insn ((*bcc_gen_fctn
[(int) comparison
]) (label
));
3849 if (class != MODE_INT
&& class != MODE_FLOAT
3850 && class != MODE_COMPLEX_FLOAT
)
3853 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
);
3855 while (wider_mode
!= VOIDmode
);
3860 /* Generate code to compare X with Y so that the condition codes are
3861 set and to jump to LABEL if the condition is true. If X is a
3862 constant and Y is not a constant, then the comparison is swapped to
3863 ensure that the comparison RTL has the canonical form.
3865 UNSIGNEDP nonzero says that X and Y are unsigned; this matters if they
3866 need to be widened by emit_cmp_insn. UNSIGNEDP is also used to select
3867 the proper branch condition code.
3869 If X and Y have mode BLKmode, then SIZE specifies the size of both X and Y.
3871 MODE is the mode of the inputs (in case they are const_int).
3873 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). It will
3874 be passed unchanged to emit_cmp_insn, then potentially converted into an
3875 unsigned variant based on UNSIGNEDP to select a proper jump instruction. */
3878 emit_cmp_and_jump_insns (rtx x
, rtx y
, enum rtx_code comparison
, rtx size
,
3879 enum machine_mode mode
, int unsignedp
, rtx label
)
3881 rtx op0
= x
, op1
= y
;
3883 /* Swap operands and condition to ensure canonical RTL. */
3884 if (swap_commutative_operands_p (x
, y
))
3886 /* If we're not emitting a branch, this means some caller
3892 comparison
= swap_condition (comparison
);
3896 /* If OP0 is still a constant, then both X and Y must be constants. Force
3897 X into a register to avoid aborting in emit_cmp_insn due to non-canonical
3899 if (CONSTANT_P (op0
))
3900 op0
= force_reg (mode
, op0
);
3904 comparison
= unsigned_condition (comparison
);
3906 prepare_cmp_insn (&op0
, &op1
, &comparison
, size
, &mode
, &unsignedp
,
3908 emit_cmp_and_jump_insn_1 (op0
, op1
, mode
, comparison
, unsignedp
, label
);
3911 /* Like emit_cmp_and_jump_insns, but generate only the comparison. */
3914 emit_cmp_insn (rtx x
, rtx y
, enum rtx_code comparison
, rtx size
,
3915 enum machine_mode mode
, int unsignedp
)
3917 emit_cmp_and_jump_insns (x
, y
, comparison
, size
, mode
, unsignedp
, 0);
3920 /* Emit a library call comparison between floating point X and Y.
3921 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). */
3924 prepare_float_lib_cmp (rtx
*px
, rtx
*py
, enum rtx_code
*pcomparison
,
3925 enum machine_mode
*pmode
, int *punsignedp
)
3927 enum rtx_code comparison
= *pcomparison
;
3928 enum rtx_code swapped
= swap_condition (comparison
);
3931 enum machine_mode orig_mode
= GET_MODE (x
);
3932 enum machine_mode mode
;
3933 rtx value
, target
, insns
, equiv
;
3936 for (mode
= orig_mode
; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
3938 if ((libfunc
= code_to_optab
[comparison
]->handlers
[mode
].libfunc
))
3941 if ((libfunc
= code_to_optab
[swapped
]->handlers
[mode
].libfunc
))
3944 tmp
= x
; x
= y
; y
= tmp
;
3945 comparison
= swapped
;
3950 if (mode
== VOIDmode
)
3953 if (mode
!= orig_mode
)
3955 x
= convert_to_mode (mode
, x
, 0);
3956 y
= convert_to_mode (mode
, y
, 0);
3959 /* Attach a REG_EQUAL note describing the semantics of the libcall to
3960 the RTL. The allows the RTL optimizers to delete the libcall if the
3961 condition can be determined at compile-time. */
3962 if (comparison
== UNORDERED
)
3964 rtx temp
= simplify_gen_relational (NE
, word_mode
, mode
, x
, x
);
3965 equiv
= simplify_gen_relational (NE
, word_mode
, mode
, y
, y
);
3966 equiv
= simplify_gen_ternary (IF_THEN_ELSE
, word_mode
, word_mode
,
3967 temp
, const_true_rtx
, equiv
);
3971 equiv
= simplify_gen_relational (comparison
, word_mode
, mode
, x
, y
);
3972 if (! FLOAT_LIB_COMPARE_RETURNS_BOOL (mode
, comparison
))
3974 rtx true_rtx
, false_rtx
;
3979 true_rtx
= const0_rtx
;
3980 false_rtx
= const_true_rtx
;
3984 true_rtx
= const_true_rtx
;
3985 false_rtx
= const0_rtx
;
3989 true_rtx
= const1_rtx
;
3990 false_rtx
= const0_rtx
;
3994 true_rtx
= const0_rtx
;
3995 false_rtx
= constm1_rtx
;
3999 true_rtx
= constm1_rtx
;
4000 false_rtx
= const0_rtx
;
4004 true_rtx
= const0_rtx
;
4005 false_rtx
= const1_rtx
;
4011 equiv
= simplify_gen_ternary (IF_THEN_ELSE
, word_mode
, word_mode
,
4012 equiv
, true_rtx
, false_rtx
);
4017 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
4018 word_mode
, 2, x
, mode
, y
, mode
);
4019 insns
= get_insns ();
4022 target
= gen_reg_rtx (word_mode
);
4023 emit_libcall_block (insns
, target
, value
, equiv
);
4026 if (comparison
== UNORDERED
4027 || FLOAT_LIB_COMPARE_RETURNS_BOOL (mode
, comparison
))
4033 *pcomparison
= comparison
;
4037 /* Generate code to indirectly jump to a location given in the rtx LOC. */
4040 emit_indirect_jump (rtx loc
)
4042 if (! ((*insn_data
[(int) CODE_FOR_indirect_jump
].operand
[0].predicate
)
4044 loc
= copy_to_mode_reg (Pmode
, loc
);
4046 emit_jump_insn (gen_indirect_jump (loc
));
4050 #ifdef HAVE_conditional_move
4052 /* Emit a conditional move instruction if the machine supports one for that
4053 condition and machine mode.
4055 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
4056 the mode to use should they be constants. If it is VOIDmode, they cannot
4059 OP2 should be stored in TARGET if the comparison is true, otherwise OP3
4060 should be stored there. MODE is the mode to use should they be constants.
4061 If it is VOIDmode, they cannot both be constants.
4063 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
4064 is not supported. */
4067 emit_conditional_move (rtx target
, enum rtx_code code
, rtx op0
, rtx op1
,
4068 enum machine_mode cmode
, rtx op2
, rtx op3
,
4069 enum machine_mode mode
, int unsignedp
)
4071 rtx tem
, subtarget
, comparison
, insn
;
4072 enum insn_code icode
;
4073 enum rtx_code reversed
;
4075 /* If one operand is constant, make it the second one. Only do this
4076 if the other operand is not constant as well. */
4078 if (swap_commutative_operands_p (op0
, op1
))
4083 code
= swap_condition (code
);
4086 /* get_condition will prefer to generate LT and GT even if the old
4087 comparison was against zero, so undo that canonicalization here since
4088 comparisons against zero are cheaper. */
4089 if (code
== LT
&& op1
== const1_rtx
)
4090 code
= LE
, op1
= const0_rtx
;
4091 else if (code
== GT
&& op1
== constm1_rtx
)
4092 code
= GE
, op1
= const0_rtx
;
4094 if (cmode
== VOIDmode
)
4095 cmode
= GET_MODE (op0
);
4097 if (swap_commutative_operands_p (op2
, op3
)
4098 && ((reversed
= reversed_comparison_code_parts (code
, op0
, op1
, NULL
))
4107 if (mode
== VOIDmode
)
4108 mode
= GET_MODE (op2
);
4110 icode
= movcc_gen_code
[mode
];
4112 if (icode
== CODE_FOR_nothing
)
4117 op2
= force_not_mem (op2
);
4118 op3
= force_not_mem (op3
);
4122 target
= gen_reg_rtx (mode
);
4126 /* If the insn doesn't accept these operands, put them in pseudos. */
4128 if (! (*insn_data
[icode
].operand
[0].predicate
)
4129 (subtarget
, insn_data
[icode
].operand
[0].mode
))
4130 subtarget
= gen_reg_rtx (insn_data
[icode
].operand
[0].mode
);
4132 if (! (*insn_data
[icode
].operand
[2].predicate
)
4133 (op2
, insn_data
[icode
].operand
[2].mode
))
4134 op2
= copy_to_mode_reg (insn_data
[icode
].operand
[2].mode
, op2
);
4136 if (! (*insn_data
[icode
].operand
[3].predicate
)
4137 (op3
, insn_data
[icode
].operand
[3].mode
))
4138 op3
= copy_to_mode_reg (insn_data
[icode
].operand
[3].mode
, op3
);
4140 /* Everything should now be in the suitable form, so emit the compare insn
4141 and then the conditional move. */
4144 = compare_from_rtx (op0
, op1
, code
, unsignedp
, cmode
, NULL_RTX
);
4146 /* ??? Watch for const0_rtx (nop) and const_true_rtx (unconditional)? */
4147 /* We can get const0_rtx or const_true_rtx in some circumstances. Just
4148 return NULL and let the caller figure out how best to deal with this
4150 if (GET_CODE (comparison
) != code
)
4153 insn
= GEN_FCN (icode
) (subtarget
, comparison
, op2
, op3
);
4155 /* If that failed, then give up. */
4161 if (subtarget
!= target
)
4162 convert_move (target
, subtarget
, 0);
4167 /* Return nonzero if a conditional move of mode MODE is supported.
4169 This function is for combine so it can tell whether an insn that looks
4170 like a conditional move is actually supported by the hardware. If we
4171 guess wrong we lose a bit on optimization, but that's it. */
4172 /* ??? sparc64 supports conditionally moving integers values based on fp
4173 comparisons, and vice versa. How do we handle them? */
4176 can_conditionally_move_p (enum machine_mode mode
)
4178 if (movcc_gen_code
[mode
] != CODE_FOR_nothing
)
4184 #endif /* HAVE_conditional_move */
4186 /* Emit a conditional addition instruction if the machine supports one for that
4187 condition and machine mode.
4189 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
4190 the mode to use should they be constants. If it is VOIDmode, they cannot
4193 OP2 should be stored in TARGET if the comparison is true, otherwise OP2+OP3
4194 should be stored there. MODE is the mode to use should they be constants.
4195 If it is VOIDmode, they cannot both be constants.
4197 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
4198 is not supported. */
4201 emit_conditional_add (rtx target
, enum rtx_code code
, rtx op0
, rtx op1
,
4202 enum machine_mode cmode
, rtx op2
, rtx op3
,
4203 enum machine_mode mode
, int unsignedp
)
4205 rtx tem
, subtarget
, comparison
, insn
;
4206 enum insn_code icode
;
4207 enum rtx_code reversed
;
4209 /* If one operand is constant, make it the second one. Only do this
4210 if the other operand is not constant as well. */
4212 if (swap_commutative_operands_p (op0
, op1
))
4217 code
= swap_condition (code
);
4220 /* get_condition will prefer to generate LT and GT even if the old
4221 comparison was against zero, so undo that canonicalization here since
4222 comparisons against zero are cheaper. */
4223 if (code
== LT
&& op1
== const1_rtx
)
4224 code
= LE
, op1
= const0_rtx
;
4225 else if (code
== GT
&& op1
== constm1_rtx
)
4226 code
= GE
, op1
= const0_rtx
;
4228 if (cmode
== VOIDmode
)
4229 cmode
= GET_MODE (op0
);
4231 if (swap_commutative_operands_p (op2
, op3
)
4232 && ((reversed
= reversed_comparison_code_parts (code
, op0
, op1
, NULL
))
4241 if (mode
== VOIDmode
)
4242 mode
= GET_MODE (op2
);
4244 icode
= addcc_optab
->handlers
[(int) mode
].insn_code
;
4246 if (icode
== CODE_FOR_nothing
)
4251 op2
= force_not_mem (op2
);
4252 op3
= force_not_mem (op3
);
4256 target
= gen_reg_rtx (mode
);
4258 /* If the insn doesn't accept these operands, put them in pseudos. */
4260 if (! (*insn_data
[icode
].operand
[0].predicate
)
4261 (target
, insn_data
[icode
].operand
[0].mode
))
4262 subtarget
= gen_reg_rtx (insn_data
[icode
].operand
[0].mode
);
4266 if (! (*insn_data
[icode
].operand
[2].predicate
)
4267 (op2
, insn_data
[icode
].operand
[2].mode
))
4268 op2
= copy_to_mode_reg (insn_data
[icode
].operand
[2].mode
, op2
);
4270 if (! (*insn_data
[icode
].operand
[3].predicate
)
4271 (op3
, insn_data
[icode
].operand
[3].mode
))
4272 op3
= copy_to_mode_reg (insn_data
[icode
].operand
[3].mode
, op3
);
4274 /* Everything should now be in the suitable form, so emit the compare insn
4275 and then the conditional move. */
4278 = compare_from_rtx (op0
, op1
, code
, unsignedp
, cmode
, NULL_RTX
);
4280 /* ??? Watch for const0_rtx (nop) and const_true_rtx (unconditional)? */
4281 /* We can get const0_rtx or const_true_rtx in some circumstances. Just
4282 return NULL and let the caller figure out how best to deal with this
4284 if (GET_CODE (comparison
) != code
)
4287 insn
= GEN_FCN (icode
) (subtarget
, comparison
, op2
, op3
);
4289 /* If that failed, then give up. */
4295 if (subtarget
!= target
)
4296 convert_move (target
, subtarget
, 0);
4301 /* These functions attempt to generate an insn body, rather than
4302 emitting the insn, but if the gen function already emits them, we
4303 make no attempt to turn them back into naked patterns. */
4305 /* Generate and return an insn body to add Y to X. */
4308 gen_add2_insn (rtx x
, rtx y
)
4310 int icode
= (int) add_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
4312 if (! ((*insn_data
[icode
].operand
[0].predicate
)
4313 (x
, insn_data
[icode
].operand
[0].mode
))
4314 || ! ((*insn_data
[icode
].operand
[1].predicate
)
4315 (x
, insn_data
[icode
].operand
[1].mode
))
4316 || ! ((*insn_data
[icode
].operand
[2].predicate
)
4317 (y
, insn_data
[icode
].operand
[2].mode
)))
4320 return (GEN_FCN (icode
) (x
, x
, y
));
4323 /* Generate and return an insn body to add r1 and c,
4324 storing the result in r0. */
4326 gen_add3_insn (rtx r0
, rtx r1
, rtx c
)
4328 int icode
= (int) add_optab
->handlers
[(int) GET_MODE (r0
)].insn_code
;
4330 if (icode
== CODE_FOR_nothing
4331 || ! ((*insn_data
[icode
].operand
[0].predicate
)
4332 (r0
, insn_data
[icode
].operand
[0].mode
))
4333 || ! ((*insn_data
[icode
].operand
[1].predicate
)
4334 (r1
, insn_data
[icode
].operand
[1].mode
))
4335 || ! ((*insn_data
[icode
].operand
[2].predicate
)
4336 (c
, insn_data
[icode
].operand
[2].mode
)))
4339 return (GEN_FCN (icode
) (r0
, r1
, c
));
4343 have_add2_insn (rtx x
, rtx y
)
4347 if (GET_MODE (x
) == VOIDmode
)
4350 icode
= (int) add_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
4352 if (icode
== CODE_FOR_nothing
)
4355 if (! ((*insn_data
[icode
].operand
[0].predicate
)
4356 (x
, insn_data
[icode
].operand
[0].mode
))
4357 || ! ((*insn_data
[icode
].operand
[1].predicate
)
4358 (x
, insn_data
[icode
].operand
[1].mode
))
4359 || ! ((*insn_data
[icode
].operand
[2].predicate
)
4360 (y
, insn_data
[icode
].operand
[2].mode
)))
4366 /* Generate and return an insn body to subtract Y from X. */
4369 gen_sub2_insn (rtx x
, rtx y
)
4371 int icode
= (int) sub_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
4373 if (! ((*insn_data
[icode
].operand
[0].predicate
)
4374 (x
, insn_data
[icode
].operand
[0].mode
))
4375 || ! ((*insn_data
[icode
].operand
[1].predicate
)
4376 (x
, insn_data
[icode
].operand
[1].mode
))
4377 || ! ((*insn_data
[icode
].operand
[2].predicate
)
4378 (y
, insn_data
[icode
].operand
[2].mode
)))
4381 return (GEN_FCN (icode
) (x
, x
, y
));
4384 /* Generate and return an insn body to subtract r1 and c,
4385 storing the result in r0. */
4387 gen_sub3_insn (rtx r0
, rtx r1
, rtx c
)
4389 int icode
= (int) sub_optab
->handlers
[(int) GET_MODE (r0
)].insn_code
;
4391 if (icode
== CODE_FOR_nothing
4392 || ! ((*insn_data
[icode
].operand
[0].predicate
)
4393 (r0
, insn_data
[icode
].operand
[0].mode
))
4394 || ! ((*insn_data
[icode
].operand
[1].predicate
)
4395 (r1
, insn_data
[icode
].operand
[1].mode
))
4396 || ! ((*insn_data
[icode
].operand
[2].predicate
)
4397 (c
, insn_data
[icode
].operand
[2].mode
)))
4400 return (GEN_FCN (icode
) (r0
, r1
, c
));
4404 have_sub2_insn (rtx x
, rtx y
)
4408 if (GET_MODE (x
) == VOIDmode
)
4411 icode
= (int) sub_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
4413 if (icode
== CODE_FOR_nothing
)
4416 if (! ((*insn_data
[icode
].operand
[0].predicate
)
4417 (x
, insn_data
[icode
].operand
[0].mode
))
4418 || ! ((*insn_data
[icode
].operand
[1].predicate
)
4419 (x
, insn_data
[icode
].operand
[1].mode
))
4420 || ! ((*insn_data
[icode
].operand
[2].predicate
)
4421 (y
, insn_data
[icode
].operand
[2].mode
)))
4427 /* Generate the body of an instruction to copy Y into X.
4428 It may be a list of insns, if one insn isn't enough. */
4431 gen_move_insn (rtx x
, rtx y
)
4436 emit_move_insn_1 (x
, y
);
4442 /* Return the insn code used to extend FROM_MODE to TO_MODE.
4443 UNSIGNEDP specifies zero-extension instead of sign-extension. If
4444 no such operation exists, CODE_FOR_nothing will be returned. */
4447 can_extend_p (enum machine_mode to_mode
, enum machine_mode from_mode
,
4451 #ifdef HAVE_ptr_extend
4453 return CODE_FOR_ptr_extend
;
4456 tab
= unsignedp
? zext_optab
: sext_optab
;
4457 return tab
->handlers
[to_mode
][from_mode
].insn_code
;
4460 /* Generate the body of an insn to extend Y (with mode MFROM)
4461 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
4464 gen_extend_insn (rtx x
, rtx y
, enum machine_mode mto
,
4465 enum machine_mode mfrom
, int unsignedp
)
4467 enum insn_code icode
= can_extend_p (mto
, mfrom
, unsignedp
);
4468 return GEN_FCN (icode
) (x
, y
);
4471 /* can_fix_p and can_float_p say whether the target machine
4472 can directly convert a given fixed point type to
4473 a given floating point type, or vice versa.
4474 The returned value is the CODE_FOR_... value to use,
4475 or CODE_FOR_nothing if these modes cannot be directly converted.
4477 *TRUNCP_PTR is set to 1 if it is necessary to output
4478 an explicit FTRUNC insn before the fix insn; otherwise 0. */
4480 static enum insn_code
4481 can_fix_p (enum machine_mode fixmode
, enum machine_mode fltmode
,
4482 int unsignedp
, int *truncp_ptr
)
4485 enum insn_code icode
;
4487 tab
= unsignedp
? ufixtrunc_optab
: sfixtrunc_optab
;
4488 icode
= tab
->handlers
[fixmode
][fltmode
].insn_code
;
4489 if (icode
!= CODE_FOR_nothing
)
4495 /* FIXME: This requires a port to define both FIX and FTRUNC pattern
4496 for this to work. We need to rework the fix* and ftrunc* patterns
4497 and documentation. */
4498 tab
= unsignedp
? ufix_optab
: sfix_optab
;
4499 icode
= tab
->handlers
[fixmode
][fltmode
].insn_code
;
4500 if (icode
!= CODE_FOR_nothing
4501 && ftrunc_optab
->handlers
[fltmode
].insn_code
!= CODE_FOR_nothing
)
4508 return CODE_FOR_nothing
;
4511 static enum insn_code
4512 can_float_p (enum machine_mode fltmode
, enum machine_mode fixmode
,
4517 tab
= unsignedp
? ufloat_optab
: sfloat_optab
;
4518 return tab
->handlers
[fltmode
][fixmode
].insn_code
;
4521 /* Generate code to convert FROM to floating point
4522 and store in TO. FROM must be fixed point and not VOIDmode.
4523 UNSIGNEDP nonzero means regard FROM as unsigned.
4524 Normally this is done by correcting the final value
4525 if it is negative. */
4528 expand_float (rtx to
, rtx from
, int unsignedp
)
4530 enum insn_code icode
;
4532 enum machine_mode fmode
, imode
;
4534 /* Crash now, because we won't be able to decide which mode to use. */
4535 if (GET_MODE (from
) == VOIDmode
)
4538 /* Look for an insn to do the conversion. Do it in the specified
4539 modes if possible; otherwise convert either input, output or both to
4540 wider mode. If the integer mode is wider than the mode of FROM,
4541 we can do the conversion signed even if the input is unsigned. */
4543 for (fmode
= GET_MODE (to
); fmode
!= VOIDmode
;
4544 fmode
= GET_MODE_WIDER_MODE (fmode
))
4545 for (imode
= GET_MODE (from
); imode
!= VOIDmode
;
4546 imode
= GET_MODE_WIDER_MODE (imode
))
4548 int doing_unsigned
= unsignedp
;
4550 if (fmode
!= GET_MODE (to
)
4551 && significand_size (fmode
) < GET_MODE_BITSIZE (GET_MODE (from
)))
4554 icode
= can_float_p (fmode
, imode
, unsignedp
);
4555 if (icode
== CODE_FOR_nothing
&& imode
!= GET_MODE (from
) && unsignedp
)
4556 icode
= can_float_p (fmode
, imode
, 0), doing_unsigned
= 0;
4558 if (icode
!= CODE_FOR_nothing
)
4560 if (imode
!= GET_MODE (from
))
4561 from
= convert_to_mode (imode
, from
, unsignedp
);
4563 if (fmode
!= GET_MODE (to
))
4564 target
= gen_reg_rtx (fmode
);
4566 emit_unop_insn (icode
, target
, from
,
4567 doing_unsigned
? UNSIGNED_FLOAT
: FLOAT
);
4570 convert_move (to
, target
, 0);
4575 /* Unsigned integer, and no way to convert directly.
4576 Convert as signed, then conditionally adjust the result. */
4579 rtx label
= gen_label_rtx ();
4581 REAL_VALUE_TYPE offset
;
4584 from
= force_not_mem (from
);
4586 /* Look for a usable floating mode FMODE wider than the source and at
4587 least as wide as the target. Using FMODE will avoid rounding woes
4588 with unsigned values greater than the signed maximum value. */
4590 for (fmode
= GET_MODE (to
); fmode
!= VOIDmode
;
4591 fmode
= GET_MODE_WIDER_MODE (fmode
))
4592 if (GET_MODE_BITSIZE (GET_MODE (from
)) < GET_MODE_BITSIZE (fmode
)
4593 && can_float_p (fmode
, GET_MODE (from
), 0) != CODE_FOR_nothing
)
4596 if (fmode
== VOIDmode
)
4598 /* There is no such mode. Pretend the target is wide enough. */
4599 fmode
= GET_MODE (to
);
4601 /* Avoid double-rounding when TO is narrower than FROM. */
4602 if ((significand_size (fmode
) + 1)
4603 < GET_MODE_BITSIZE (GET_MODE (from
)))
4606 rtx neglabel
= gen_label_rtx ();
4608 /* Don't use TARGET if it isn't a register, is a hard register,
4609 or is the wrong mode. */
4611 || REGNO (target
) < FIRST_PSEUDO_REGISTER
4612 || GET_MODE (target
) != fmode
)
4613 target
= gen_reg_rtx (fmode
);
4615 imode
= GET_MODE (from
);
4616 do_pending_stack_adjust ();
4618 /* Test whether the sign bit is set. */
4619 emit_cmp_and_jump_insns (from
, const0_rtx
, LT
, NULL_RTX
, imode
,
4622 /* The sign bit is not set. Convert as signed. */
4623 expand_float (target
, from
, 0);
4624 emit_jump_insn (gen_jump (label
));
4627 /* The sign bit is set.
4628 Convert to a usable (positive signed) value by shifting right
4629 one bit, while remembering if a nonzero bit was shifted
4630 out; i.e., compute (from & 1) | (from >> 1). */
4632 emit_label (neglabel
);
4633 temp
= expand_binop (imode
, and_optab
, from
, const1_rtx
,
4634 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
4635 temp1
= expand_shift (RSHIFT_EXPR
, imode
, from
, integer_one_node
,
4637 temp
= expand_binop (imode
, ior_optab
, temp
, temp1
, temp
, 1,
4639 expand_float (target
, temp
, 0);
4641 /* Multiply by 2 to undo the shift above. */
4642 temp
= expand_binop (fmode
, add_optab
, target
, target
,
4643 target
, 0, OPTAB_LIB_WIDEN
);
4645 emit_move_insn (target
, temp
);
4647 do_pending_stack_adjust ();
4653 /* If we are about to do some arithmetic to correct for an
4654 unsigned operand, do it in a pseudo-register. */
4656 if (GET_MODE (to
) != fmode
4657 || !REG_P (to
) || REGNO (to
) < FIRST_PSEUDO_REGISTER
)
4658 target
= gen_reg_rtx (fmode
);
4660 /* Convert as signed integer to floating. */
4661 expand_float (target
, from
, 0);
4663 /* If FROM is negative (and therefore TO is negative),
4664 correct its value by 2**bitwidth. */
4666 do_pending_stack_adjust ();
4667 emit_cmp_and_jump_insns (from
, const0_rtx
, GE
, NULL_RTX
, GET_MODE (from
),
4671 real_2expN (&offset
, GET_MODE_BITSIZE (GET_MODE (from
)));
4672 temp
= expand_binop (fmode
, add_optab
, target
,
4673 CONST_DOUBLE_FROM_REAL_VALUE (offset
, fmode
),
4674 target
, 0, OPTAB_LIB_WIDEN
);
4676 emit_move_insn (target
, temp
);
4678 do_pending_stack_adjust ();
4683 /* No hardware instruction available; call a library routine. */
4688 convert_optab tab
= unsignedp
? ufloat_optab
: sfloat_optab
;
4690 if (GET_MODE_SIZE (GET_MODE (from
)) < GET_MODE_SIZE (SImode
))
4691 from
= convert_to_mode (SImode
, from
, unsignedp
);
4694 from
= force_not_mem (from
);
4696 libfunc
= tab
->handlers
[GET_MODE (to
)][GET_MODE (from
)].libfunc
;
4702 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
4703 GET_MODE (to
), 1, from
,
4705 insns
= get_insns ();
4708 emit_libcall_block (insns
, target
, value
,
4709 gen_rtx_FLOAT (GET_MODE (to
), from
));
4714 /* Copy result to requested destination
4715 if we have been computing in a temp location. */
4719 if (GET_MODE (target
) == GET_MODE (to
))
4720 emit_move_insn (to
, target
);
4722 convert_move (to
, target
, 0);
4726 /* Generate code to convert FROM to fixed point and store in TO. FROM
4727 must be floating point. */
4730 expand_fix (rtx to
, rtx from
, int unsignedp
)
4732 enum insn_code icode
;
4734 enum machine_mode fmode
, imode
;
4737 /* We first try to find a pair of modes, one real and one integer, at
4738 least as wide as FROM and TO, respectively, in which we can open-code
4739 this conversion. If the integer mode is wider than the mode of TO,
4740 we can do the conversion either signed or unsigned. */
4742 for (fmode
= GET_MODE (from
); fmode
!= VOIDmode
;
4743 fmode
= GET_MODE_WIDER_MODE (fmode
))
4744 for (imode
= GET_MODE (to
); imode
!= VOIDmode
;
4745 imode
= GET_MODE_WIDER_MODE (imode
))
4747 int doing_unsigned
= unsignedp
;
4749 icode
= can_fix_p (imode
, fmode
, unsignedp
, &must_trunc
);
4750 if (icode
== CODE_FOR_nothing
&& imode
!= GET_MODE (to
) && unsignedp
)
4751 icode
= can_fix_p (imode
, fmode
, 0, &must_trunc
), doing_unsigned
= 0;
4753 if (icode
!= CODE_FOR_nothing
)
4755 if (fmode
!= GET_MODE (from
))
4756 from
= convert_to_mode (fmode
, from
, 0);
4760 rtx temp
= gen_reg_rtx (GET_MODE (from
));
4761 from
= expand_unop (GET_MODE (from
), ftrunc_optab
, from
,
4765 if (imode
!= GET_MODE (to
))
4766 target
= gen_reg_rtx (imode
);
4768 emit_unop_insn (icode
, target
, from
,
4769 doing_unsigned
? UNSIGNED_FIX
: FIX
);
4771 convert_move (to
, target
, unsignedp
);
4776 /* For an unsigned conversion, there is one more way to do it.
4777 If we have a signed conversion, we generate code that compares
4778 the real value to the largest representable positive number. If if
4779 is smaller, the conversion is done normally. Otherwise, subtract
4780 one plus the highest signed number, convert, and add it back.
4782 We only need to check all real modes, since we know we didn't find
4783 anything with a wider integer mode.
4785 This code used to extend FP value into mode wider than the destination.
4786 This is not needed. Consider, for instance conversion from SFmode
4789 The hot path trought the code is dealing with inputs smaller than 2^63
4790 and doing just the conversion, so there is no bits to lose.
4792 In the other path we know the value is positive in the range 2^63..2^64-1
4793 inclusive. (as for other imput overflow happens and result is undefined)
4794 So we know that the most important bit set in mantissa corresponds to
4795 2^63. The subtraction of 2^63 should not generate any rounding as it
4796 simply clears out that bit. The rest is trivial. */
4798 if (unsignedp
&& GET_MODE_BITSIZE (GET_MODE (to
)) <= HOST_BITS_PER_WIDE_INT
)
4799 for (fmode
= GET_MODE (from
); fmode
!= VOIDmode
;
4800 fmode
= GET_MODE_WIDER_MODE (fmode
))
4801 if (CODE_FOR_nothing
!= can_fix_p (GET_MODE (to
), fmode
, 0,
4805 REAL_VALUE_TYPE offset
;
4806 rtx limit
, lab1
, lab2
, insn
;
4808 bitsize
= GET_MODE_BITSIZE (GET_MODE (to
));
4809 real_2expN (&offset
, bitsize
- 1);
4810 limit
= CONST_DOUBLE_FROM_REAL_VALUE (offset
, fmode
);
4811 lab1
= gen_label_rtx ();
4812 lab2
= gen_label_rtx ();
4815 from
= force_not_mem (from
);
4817 if (fmode
!= GET_MODE (from
))
4818 from
= convert_to_mode (fmode
, from
, 0);
4820 /* See if we need to do the subtraction. */
4821 do_pending_stack_adjust ();
4822 emit_cmp_and_jump_insns (from
, limit
, GE
, NULL_RTX
, GET_MODE (from
),
4825 /* If not, do the signed "fix" and branch around fixup code. */
4826 expand_fix (to
, from
, 0);
4827 emit_jump_insn (gen_jump (lab2
));
4830 /* Otherwise, subtract 2**(N-1), convert to signed number,
4831 then add 2**(N-1). Do the addition using XOR since this
4832 will often generate better code. */
4834 target
= expand_binop (GET_MODE (from
), sub_optab
, from
, limit
,
4835 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4836 expand_fix (to
, target
, 0);
4837 target
= expand_binop (GET_MODE (to
), xor_optab
, to
,
4839 ((HOST_WIDE_INT
) 1 << (bitsize
- 1),
4841 to
, 1, OPTAB_LIB_WIDEN
);
4844 emit_move_insn (to
, target
);
4848 if (mov_optab
->handlers
[(int) GET_MODE (to
)].insn_code
4849 != CODE_FOR_nothing
)
4851 /* Make a place for a REG_NOTE and add it. */
4852 insn
= emit_move_insn (to
, to
);
4853 set_unique_reg_note (insn
,
4855 gen_rtx_fmt_e (UNSIGNED_FIX
,
4863 /* We can't do it with an insn, so use a library call. But first ensure
4864 that the mode of TO is at least as wide as SImode, since those are the
4865 only library calls we know about. */
4867 if (GET_MODE_SIZE (GET_MODE (to
)) < GET_MODE_SIZE (SImode
))
4869 target
= gen_reg_rtx (SImode
);
4871 expand_fix (target
, from
, unsignedp
);
4879 convert_optab tab
= unsignedp
? ufix_optab
: sfix_optab
;
4880 libfunc
= tab
->handlers
[GET_MODE (to
)][GET_MODE (from
)].libfunc
;
4885 from
= force_not_mem (from
);
4889 value
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
4890 GET_MODE (to
), 1, from
,
4892 insns
= get_insns ();
4895 emit_libcall_block (insns
, target
, value
,
4896 gen_rtx_fmt_e (unsignedp
? UNSIGNED_FIX
: FIX
,
4897 GET_MODE (to
), from
));
4902 if (GET_MODE (to
) == GET_MODE (target
))
4903 emit_move_insn (to
, target
);
4905 convert_move (to
, target
, 0);
4909 /* Report whether we have an instruction to perform the operation
4910 specified by CODE on operands of mode MODE. */
4912 have_insn_for (enum rtx_code code
, enum machine_mode mode
)
4914 return (code_to_optab
[(int) code
] != 0
4915 && (code_to_optab
[(int) code
]->handlers
[(int) mode
].insn_code
4916 != CODE_FOR_nothing
));
4919 /* Create a blank optab. */
4924 optab op
= ggc_alloc (sizeof (struct optab
));
4925 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
4927 op
->handlers
[i
].insn_code
= CODE_FOR_nothing
;
4928 op
->handlers
[i
].libfunc
= 0;
4934 static convert_optab
4935 new_convert_optab (void)
4938 convert_optab op
= ggc_alloc (sizeof (struct convert_optab
));
4939 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
4940 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
4942 op
->handlers
[i
][j
].insn_code
= CODE_FOR_nothing
;
4943 op
->handlers
[i
][j
].libfunc
= 0;
4948 /* Same, but fill in its code as CODE, and write it into the
4949 code_to_optab table. */
4951 init_optab (enum rtx_code code
)
4953 optab op
= new_optab ();
4955 code_to_optab
[(int) code
] = op
;
4959 /* Same, but fill in its code as CODE, and do _not_ write it into
4960 the code_to_optab table. */
4962 init_optabv (enum rtx_code code
)
4964 optab op
= new_optab ();
4969 /* Conversion optabs never go in the code_to_optab table. */
4970 static inline convert_optab
4971 init_convert_optab (enum rtx_code code
)
4973 convert_optab op
= new_convert_optab ();
4978 /* Initialize the libfunc fields of an entire group of entries in some
4979 optab. Each entry is set equal to a string consisting of a leading
4980 pair of underscores followed by a generic operation name followed by
4981 a mode name (downshifted to lowercase) followed by a single character
4982 representing the number of operands for the given operation (which is
4983 usually one of the characters '2', '3', or '4').
4985 OPTABLE is the table in which libfunc fields are to be initialized.
4986 FIRST_MODE is the first machine mode index in the given optab to
4988 LAST_MODE is the last machine mode index in the given optab to
4990 OPNAME is the generic (string) name of the operation.
4991 SUFFIX is the character which specifies the number of operands for
4992 the given generic operation.
4996 init_libfuncs (optab optable
, int first_mode
, int last_mode
,
4997 const char *opname
, int suffix
)
5000 unsigned opname_len
= strlen (opname
);
5002 for (mode
= first_mode
; (int) mode
<= (int) last_mode
;
5003 mode
= (enum machine_mode
) ((int) mode
+ 1))
5005 const char *mname
= GET_MODE_NAME (mode
);
5006 unsigned mname_len
= strlen (mname
);
5007 char *libfunc_name
= alloca (2 + opname_len
+ mname_len
+ 1 + 1);
5014 for (q
= opname
; *q
; )
5016 for (q
= mname
; *q
; q
++)
5017 *p
++ = TOLOWER (*q
);
5021 optable
->handlers
[(int) mode
].libfunc
5022 = init_one_libfunc (ggc_alloc_string (libfunc_name
, p
- libfunc_name
));
5026 /* Initialize the libfunc fields of an entire group of entries in some
5027 optab which correspond to all integer mode operations. The parameters
5028 have the same meaning as similarly named ones for the `init_libfuncs'
5029 routine. (See above). */
5032 init_integral_libfuncs (optab optable
, const char *opname
, int suffix
)
5034 int maxsize
= 2*BITS_PER_WORD
;
5035 if (maxsize
< LONG_LONG_TYPE_SIZE
)
5036 maxsize
= LONG_LONG_TYPE_SIZE
;
5037 init_libfuncs (optable
, word_mode
,
5038 mode_for_size (maxsize
, MODE_INT
, 0),
5042 /* Initialize the libfunc fields of an entire group of entries in some
5043 optab which correspond to all real mode operations. The parameters
5044 have the same meaning as similarly named ones for the `init_libfuncs'
5045 routine. (See above). */
5048 init_floating_libfuncs (optab optable
, const char *opname
, int suffix
)
5050 init_libfuncs (optable
, MIN_MODE_FLOAT
, MAX_MODE_FLOAT
, opname
, suffix
);
5053 /* Initialize the libfunc fields of an entire group of entries of an
5054 inter-mode-class conversion optab. The string formation rules are
5055 similar to the ones for init_libfuncs, above, but instead of having
5056 a mode name and an operand count these functions have two mode names
5057 and no operand count. */
5059 init_interclass_conv_libfuncs (convert_optab tab
, const char *opname
,
5060 enum mode_class from_class
,
5061 enum mode_class to_class
)
5063 enum machine_mode first_from_mode
= GET_CLASS_NARROWEST_MODE (from_class
);
5064 enum machine_mode first_to_mode
= GET_CLASS_NARROWEST_MODE (to_class
);
5065 size_t opname_len
= strlen (opname
);
5066 size_t max_mname_len
= 0;
5068 enum machine_mode fmode
, tmode
;
5069 const char *fname
, *tname
;
5071 char *libfunc_name
, *suffix
;
5074 for (fmode
= first_from_mode
;
5076 fmode
= GET_MODE_WIDER_MODE (fmode
))
5077 max_mname_len
= MAX (max_mname_len
, strlen (GET_MODE_NAME (fmode
)));
5079 for (tmode
= first_to_mode
;
5081 tmode
= GET_MODE_WIDER_MODE (tmode
))
5082 max_mname_len
= MAX (max_mname_len
, strlen (GET_MODE_NAME (tmode
)));
5084 libfunc_name
= alloca (2 + opname_len
+ 2*max_mname_len
+ 1 + 1);
5085 libfunc_name
[0] = '_';
5086 libfunc_name
[1] = '_';
5087 memcpy (&libfunc_name
[2], opname
, opname_len
);
5088 suffix
= libfunc_name
+ opname_len
+ 2;
5090 for (fmode
= first_from_mode
; fmode
!= VOIDmode
;
5091 fmode
= GET_MODE_WIDER_MODE (fmode
))
5092 for (tmode
= first_to_mode
; tmode
!= VOIDmode
;
5093 tmode
= GET_MODE_WIDER_MODE (tmode
))
5095 fname
= GET_MODE_NAME (fmode
);
5096 tname
= GET_MODE_NAME (tmode
);
5099 for (q
= fname
; *q
; p
++, q
++)
5101 for (q
= tname
; *q
; p
++, q
++)
5106 tab
->handlers
[tmode
][fmode
].libfunc
5107 = init_one_libfunc (ggc_alloc_string (libfunc_name
,
5112 /* Initialize the libfunc fields of an entire group of entries of an
5113 intra-mode-class conversion optab. The string formation rules are
5114 similar to the ones for init_libfunc, above. WIDENING says whether
5115 the optab goes from narrow to wide modes or vice versa. These functions
5116 have two mode names _and_ an operand count. */
5118 init_intraclass_conv_libfuncs (convert_optab tab
, const char *opname
,
5119 enum mode_class
class, bool widening
)
5121 enum machine_mode first_mode
= GET_CLASS_NARROWEST_MODE (class);
5122 size_t opname_len
= strlen (opname
);
5123 size_t max_mname_len
= 0;
5125 enum machine_mode nmode
, wmode
;
5126 const char *nname
, *wname
;
5128 char *libfunc_name
, *suffix
;
5131 for (nmode
= first_mode
; nmode
!= VOIDmode
;
5132 nmode
= GET_MODE_WIDER_MODE (nmode
))
5133 max_mname_len
= MAX (max_mname_len
, strlen (GET_MODE_NAME (nmode
)));
5135 libfunc_name
= alloca (2 + opname_len
+ 2*max_mname_len
+ 1 + 1);
5136 libfunc_name
[0] = '_';
5137 libfunc_name
[1] = '_';
5138 memcpy (&libfunc_name
[2], opname
, opname_len
);
5139 suffix
= libfunc_name
+ opname_len
+ 2;
5141 for (nmode
= first_mode
; nmode
!= VOIDmode
;
5142 nmode
= GET_MODE_WIDER_MODE (nmode
))
5143 for (wmode
= GET_MODE_WIDER_MODE (nmode
); wmode
!= VOIDmode
;
5144 wmode
= GET_MODE_WIDER_MODE (wmode
))
5146 nname
= GET_MODE_NAME (nmode
);
5147 wname
= GET_MODE_NAME (wmode
);
5150 for (q
= widening
? nname
: wname
; *q
; p
++, q
++)
5152 for (q
= widening
? wname
: nname
; *q
; p
++, q
++)
5158 tab
->handlers
[widening
? wmode
: nmode
]
5159 [widening
? nmode
: wmode
].libfunc
5160 = init_one_libfunc (ggc_alloc_string (libfunc_name
,
5167 init_one_libfunc (const char *name
)
5171 /* Create a FUNCTION_DECL that can be passed to
5172 targetm.encode_section_info. */
5173 /* ??? We don't have any type information except for this is
5174 a function. Pretend this is "int foo()". */
5175 tree decl
= build_decl (FUNCTION_DECL
, get_identifier (name
),
5176 build_function_type (integer_type_node
, NULL_TREE
));
5177 DECL_ARTIFICIAL (decl
) = 1;
5178 DECL_EXTERNAL (decl
) = 1;
5179 TREE_PUBLIC (decl
) = 1;
5181 symbol
= XEXP (DECL_RTL (decl
), 0);
5183 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
5184 are the flags assigned by targetm.encode_section_info. */
5185 SYMBOL_REF_DECL (symbol
) = 0;
5190 /* Call this to reset the function entry for one optab (OPTABLE) in mode
5191 MODE to NAME, which should be either 0 or a string constant. */
5193 set_optab_libfunc (optab optable
, enum machine_mode mode
, const char *name
)
5196 optable
->handlers
[mode
].libfunc
= init_one_libfunc (name
);
5198 optable
->handlers
[mode
].libfunc
= 0;
5201 /* Call this to reset the function entry for one conversion optab
5202 (OPTABLE) from mode FMODE to mode TMODE to NAME, which should be
5203 either 0 or a string constant. */
5205 set_conv_libfunc (convert_optab optable
, enum machine_mode tmode
,
5206 enum machine_mode fmode
, const char *name
)
5209 optable
->handlers
[tmode
][fmode
].libfunc
= init_one_libfunc (name
);
5211 optable
->handlers
[tmode
][fmode
].libfunc
= 0;
5214 /* Call this once to initialize the contents of the optabs
5215 appropriately for the current target machine. */
5222 /* Start by initializing all tables to contain CODE_FOR_nothing. */
5224 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
5225 setcc_gen_code
[i
] = CODE_FOR_nothing
;
5227 #ifdef HAVE_conditional_move
5228 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
5229 movcc_gen_code
[i
] = CODE_FOR_nothing
;
5232 add_optab
= init_optab (PLUS
);
5233 addv_optab
= init_optabv (PLUS
);
5234 sub_optab
= init_optab (MINUS
);
5235 subv_optab
= init_optabv (MINUS
);
5236 smul_optab
= init_optab (MULT
);
5237 smulv_optab
= init_optabv (MULT
);
5238 smul_highpart_optab
= init_optab (UNKNOWN
);
5239 umul_highpart_optab
= init_optab (UNKNOWN
);
5240 smul_widen_optab
= init_optab (UNKNOWN
);
5241 umul_widen_optab
= init_optab (UNKNOWN
);
5242 sdiv_optab
= init_optab (DIV
);
5243 sdivv_optab
= init_optabv (DIV
);
5244 sdivmod_optab
= init_optab (UNKNOWN
);
5245 udiv_optab
= init_optab (UDIV
);
5246 udivmod_optab
= init_optab (UNKNOWN
);
5247 smod_optab
= init_optab (MOD
);
5248 umod_optab
= init_optab (UMOD
);
5249 fmod_optab
= init_optab (UNKNOWN
);
5250 drem_optab
= init_optab (UNKNOWN
);
5251 ftrunc_optab
= init_optab (UNKNOWN
);
5252 and_optab
= init_optab (AND
);
5253 ior_optab
= init_optab (IOR
);
5254 xor_optab
= init_optab (XOR
);
5255 ashl_optab
= init_optab (ASHIFT
);
5256 ashr_optab
= init_optab (ASHIFTRT
);
5257 lshr_optab
= init_optab (LSHIFTRT
);
5258 rotl_optab
= init_optab (ROTATE
);
5259 rotr_optab
= init_optab (ROTATERT
);
5260 smin_optab
= init_optab (SMIN
);
5261 smax_optab
= init_optab (SMAX
);
5262 umin_optab
= init_optab (UMIN
);
5263 umax_optab
= init_optab (UMAX
);
5264 pow_optab
= init_optab (UNKNOWN
);
5265 atan2_optab
= init_optab (UNKNOWN
);
5267 /* These three have codes assigned exclusively for the sake of
5269 mov_optab
= init_optab (SET
);
5270 movstrict_optab
= init_optab (STRICT_LOW_PART
);
5271 cmp_optab
= init_optab (COMPARE
);
5273 ucmp_optab
= init_optab (UNKNOWN
);
5274 tst_optab
= init_optab (UNKNOWN
);
5276 eq_optab
= init_optab (EQ
);
5277 ne_optab
= init_optab (NE
);
5278 gt_optab
= init_optab (GT
);
5279 ge_optab
= init_optab (GE
);
5280 lt_optab
= init_optab (LT
);
5281 le_optab
= init_optab (LE
);
5282 unord_optab
= init_optab (UNORDERED
);
5284 neg_optab
= init_optab (NEG
);
5285 negv_optab
= init_optabv (NEG
);
5286 abs_optab
= init_optab (ABS
);
5287 absv_optab
= init_optabv (ABS
);
5288 addcc_optab
= init_optab (UNKNOWN
);
5289 one_cmpl_optab
= init_optab (NOT
);
5290 ffs_optab
= init_optab (FFS
);
5291 clz_optab
= init_optab (CLZ
);
5292 ctz_optab
= init_optab (CTZ
);
5293 popcount_optab
= init_optab (POPCOUNT
);
5294 parity_optab
= init_optab (PARITY
);
5295 sqrt_optab
= init_optab (SQRT
);
5296 floor_optab
= init_optab (UNKNOWN
);
5297 ceil_optab
= init_optab (UNKNOWN
);
5298 round_optab
= init_optab (UNKNOWN
);
5299 btrunc_optab
= init_optab (UNKNOWN
);
5300 nearbyint_optab
= init_optab (UNKNOWN
);
5301 sincos_optab
= init_optab (UNKNOWN
);
5302 sin_optab
= init_optab (UNKNOWN
);
5303 asin_optab
= init_optab (UNKNOWN
);
5304 cos_optab
= init_optab (UNKNOWN
);
5305 acos_optab
= init_optab (UNKNOWN
);
5306 exp_optab
= init_optab (UNKNOWN
);
5307 exp10_optab
= init_optab (UNKNOWN
);
5308 exp2_optab
= init_optab (UNKNOWN
);
5309 expm1_optab
= init_optab (UNKNOWN
);
5310 logb_optab
= init_optab (UNKNOWN
);
5311 ilogb_optab
= init_optab (UNKNOWN
);
5312 log_optab
= init_optab (UNKNOWN
);
5313 log10_optab
= init_optab (UNKNOWN
);
5314 log2_optab
= init_optab (UNKNOWN
);
5315 log1p_optab
= init_optab (UNKNOWN
);
5316 tan_optab
= init_optab (UNKNOWN
);
5317 atan_optab
= init_optab (UNKNOWN
);
5318 strlen_optab
= init_optab (UNKNOWN
);
5319 cbranch_optab
= init_optab (UNKNOWN
);
5320 cmov_optab
= init_optab (UNKNOWN
);
5321 cstore_optab
= init_optab (UNKNOWN
);
5322 push_optab
= init_optab (UNKNOWN
);
5324 vec_extract_optab
= init_optab (UNKNOWN
);
5325 vec_set_optab
= init_optab (UNKNOWN
);
5326 vec_init_optab
= init_optab (UNKNOWN
);
5328 sext_optab
= init_convert_optab (SIGN_EXTEND
);
5329 zext_optab
= init_convert_optab (ZERO_EXTEND
);
5330 trunc_optab
= init_convert_optab (TRUNCATE
);
5331 sfix_optab
= init_convert_optab (FIX
);
5332 ufix_optab
= init_convert_optab (UNSIGNED_FIX
);
5333 sfixtrunc_optab
= init_convert_optab (UNKNOWN
);
5334 ufixtrunc_optab
= init_convert_optab (UNKNOWN
);
5335 sfloat_optab
= init_convert_optab (FLOAT
);
5336 ufloat_optab
= init_convert_optab (UNSIGNED_FLOAT
);
5338 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
5340 movmem_optab
[i
] = CODE_FOR_nothing
;
5341 clrmem_optab
[i
] = CODE_FOR_nothing
;
5342 cmpstr_optab
[i
] = CODE_FOR_nothing
;
5343 cmpmem_optab
[i
] = CODE_FOR_nothing
;
5345 #ifdef HAVE_SECONDARY_RELOADS
5346 reload_in_optab
[i
] = reload_out_optab
[i
] = CODE_FOR_nothing
;
5350 /* Fill in the optabs with the insns we support. */
5353 /* Initialize the optabs with the names of the library functions. */
5354 init_integral_libfuncs (add_optab
, "add", '3');
5355 init_floating_libfuncs (add_optab
, "add", '3');
5356 init_integral_libfuncs (addv_optab
, "addv", '3');
5357 init_floating_libfuncs (addv_optab
, "add", '3');
5358 init_integral_libfuncs (sub_optab
, "sub", '3');
5359 init_floating_libfuncs (sub_optab
, "sub", '3');
5360 init_integral_libfuncs (subv_optab
, "subv", '3');
5361 init_floating_libfuncs (subv_optab
, "sub", '3');
5362 init_integral_libfuncs (smul_optab
, "mul", '3');
5363 init_floating_libfuncs (smul_optab
, "mul", '3');
5364 init_integral_libfuncs (smulv_optab
, "mulv", '3');
5365 init_floating_libfuncs (smulv_optab
, "mul", '3');
5366 init_integral_libfuncs (sdiv_optab
, "div", '3');
5367 init_floating_libfuncs (sdiv_optab
, "div", '3');
5368 init_integral_libfuncs (sdivv_optab
, "divv", '3');
5369 init_integral_libfuncs (udiv_optab
, "udiv", '3');
5370 init_integral_libfuncs (sdivmod_optab
, "divmod", '4');
5371 init_integral_libfuncs (udivmod_optab
, "udivmod", '4');
5372 init_integral_libfuncs (smod_optab
, "mod", '3');
5373 init_integral_libfuncs (umod_optab
, "umod", '3');
5374 init_floating_libfuncs (ftrunc_optab
, "ftrunc", '2');
5375 init_integral_libfuncs (and_optab
, "and", '3');
5376 init_integral_libfuncs (ior_optab
, "ior", '3');
5377 init_integral_libfuncs (xor_optab
, "xor", '3');
5378 init_integral_libfuncs (ashl_optab
, "ashl", '3');
5379 init_integral_libfuncs (ashr_optab
, "ashr", '3');
5380 init_integral_libfuncs (lshr_optab
, "lshr", '3');
5381 init_integral_libfuncs (smin_optab
, "min", '3');
5382 init_floating_libfuncs (smin_optab
, "min", '3');
5383 init_integral_libfuncs (smax_optab
, "max", '3');
5384 init_floating_libfuncs (smax_optab
, "max", '3');
5385 init_integral_libfuncs (umin_optab
, "umin", '3');
5386 init_integral_libfuncs (umax_optab
, "umax", '3');
5387 init_integral_libfuncs (neg_optab
, "neg", '2');
5388 init_floating_libfuncs (neg_optab
, "neg", '2');
5389 init_integral_libfuncs (negv_optab
, "negv", '2');
5390 init_floating_libfuncs (negv_optab
, "neg", '2');
5391 init_integral_libfuncs (one_cmpl_optab
, "one_cmpl", '2');
5392 init_integral_libfuncs (ffs_optab
, "ffs", '2');
5393 init_integral_libfuncs (clz_optab
, "clz", '2');
5394 init_integral_libfuncs (ctz_optab
, "ctz", '2');
5395 init_integral_libfuncs (popcount_optab
, "popcount", '2');
5396 init_integral_libfuncs (parity_optab
, "parity", '2');
5398 /* Comparison libcalls for integers MUST come in pairs, signed/unsigned. */
5399 init_integral_libfuncs (cmp_optab
, "cmp", '2');
5400 init_integral_libfuncs (ucmp_optab
, "ucmp", '2');
5401 init_floating_libfuncs (cmp_optab
, "cmp", '2');
5403 /* EQ etc are floating point only. */
5404 init_floating_libfuncs (eq_optab
, "eq", '2');
5405 init_floating_libfuncs (ne_optab
, "ne", '2');
5406 init_floating_libfuncs (gt_optab
, "gt", '2');
5407 init_floating_libfuncs (ge_optab
, "ge", '2');
5408 init_floating_libfuncs (lt_optab
, "lt", '2');
5409 init_floating_libfuncs (le_optab
, "le", '2');
5410 init_floating_libfuncs (unord_optab
, "unord", '2');
5413 init_interclass_conv_libfuncs (sfloat_optab
, "float", MODE_INT
, MODE_FLOAT
);
5414 init_interclass_conv_libfuncs (sfix_optab
, "fix", MODE_FLOAT
, MODE_INT
);
5415 init_interclass_conv_libfuncs (ufix_optab
, "fixuns", MODE_FLOAT
, MODE_INT
);
5417 /* sext_optab is also used for FLOAT_EXTEND. */
5418 init_intraclass_conv_libfuncs (sext_optab
, "extend", MODE_FLOAT
, true);
5419 init_intraclass_conv_libfuncs (trunc_optab
, "trunc", MODE_FLOAT
, false);
5421 /* Use cabs for double complex abs, since systems generally have cabs.
5422 Don't define any libcall for float complex, so that cabs will be used. */
5423 if (complex_double_type_node
)
5424 abs_optab
->handlers
[TYPE_MODE (complex_double_type_node
)].libfunc
5425 = init_one_libfunc ("cabs");
5427 /* The ffs function operates on `int'. */
5428 ffs_optab
->handlers
[(int) mode_for_size (INT_TYPE_SIZE
, MODE_INT
, 0)].libfunc
5429 = init_one_libfunc ("ffs");
5431 abort_libfunc
= init_one_libfunc ("abort");
5432 memcpy_libfunc
= init_one_libfunc ("memcpy");
5433 memmove_libfunc
= init_one_libfunc ("memmove");
5434 memcmp_libfunc
= init_one_libfunc ("memcmp");
5435 memset_libfunc
= init_one_libfunc ("memset");
5436 setbits_libfunc
= init_one_libfunc ("__setbits");
5438 unwind_resume_libfunc
= init_one_libfunc (USING_SJLJ_EXCEPTIONS
5439 ? "_Unwind_SjLj_Resume"
5440 : "_Unwind_Resume");
5441 #ifndef DONT_USE_BUILTIN_SETJMP
5442 setjmp_libfunc
= init_one_libfunc ("__builtin_setjmp");
5443 longjmp_libfunc
= init_one_libfunc ("__builtin_longjmp");
5445 setjmp_libfunc
= init_one_libfunc ("setjmp");
5446 longjmp_libfunc
= init_one_libfunc ("longjmp");
5448 unwind_sjlj_register_libfunc
= init_one_libfunc ("_Unwind_SjLj_Register");
5449 unwind_sjlj_unregister_libfunc
5450 = init_one_libfunc ("_Unwind_SjLj_Unregister");
5452 /* For function entry/exit instrumentation. */
5453 profile_function_entry_libfunc
5454 = init_one_libfunc ("__cyg_profile_func_enter");
5455 profile_function_exit_libfunc
5456 = init_one_libfunc ("__cyg_profile_func_exit");
5458 gcov_flush_libfunc
= init_one_libfunc ("__gcov_flush");
5460 if (HAVE_conditional_trap
)
5461 trap_rtx
= gen_rtx_fmt_ee (EQ
, VOIDmode
, NULL_RTX
, NULL_RTX
);
5463 /* Allow the target to add more libcalls or rename some, etc. */
5464 targetm
.init_libfuncs ();
5467 /* Generate insns to trap with code TCODE if OP1 and OP2 satisfy condition
5468 CODE. Return 0 on failure. */
5471 gen_cond_trap (enum rtx_code code ATTRIBUTE_UNUSED
, rtx op1
,
5472 rtx op2 ATTRIBUTE_UNUSED
, rtx tcode ATTRIBUTE_UNUSED
)
5474 enum machine_mode mode
= GET_MODE (op1
);
5475 enum insn_code icode
;
5478 if (!HAVE_conditional_trap
)
5481 if (mode
== VOIDmode
)
5484 icode
= cmp_optab
->handlers
[(int) mode
].insn_code
;
5485 if (icode
== CODE_FOR_nothing
)
5489 op1
= prepare_operand (icode
, op1
, 0, mode
, mode
, 0);
5490 op2
= prepare_operand (icode
, op2
, 1, mode
, mode
, 0);
5496 emit_insn (GEN_FCN (icode
) (op1
, op2
));
5498 PUT_CODE (trap_rtx
, code
);
5499 insn
= gen_conditional_trap (trap_rtx
, tcode
);
5503 insn
= get_insns ();
5510 #include "gt-optabs.h"