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 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
27 /* Include insn-config.h before expr.h so that HAVE_conditional_move
28 is properly defined. */
29 #include "insn-config.h"
42 /* Each optab contains info on how this target machine
43 can perform a particular operation
44 for all sizes and kinds of operands.
46 The operation to be performed is often specified
47 by passing one of these optabs as an argument.
49 See expr.h for documentation of these optabs. */
51 optab optab_table
[OTI_MAX
];
53 rtx libfunc_table
[LTI_MAX
];
55 /* Tables of patterns for extending one integer mode to another. */
56 enum insn_code extendtab
[MAX_MACHINE_MODE
][MAX_MACHINE_MODE
][2];
58 /* Tables of patterns for converting between fixed and floating point. */
59 enum insn_code fixtab
[NUM_MACHINE_MODES
][NUM_MACHINE_MODES
][2];
60 enum insn_code fixtrunctab
[NUM_MACHINE_MODES
][NUM_MACHINE_MODES
][2];
61 enum insn_code floattab
[NUM_MACHINE_MODES
][NUM_MACHINE_MODES
][2];
63 /* Contains the optab used for each rtx code. */
64 optab code_to_optab
[NUM_RTX_CODE
+ 1];
66 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
67 gives the gen_function to make a branch to test that condition. */
69 rtxfun bcc_gen_fctn
[NUM_RTX_CODE
];
71 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
72 gives the insn code to make a store-condition insn
73 to test that condition. */
75 enum insn_code setcc_gen_code
[NUM_RTX_CODE
];
77 #ifdef HAVE_conditional_move
78 /* Indexed by the machine mode, gives the insn code to make a conditional
79 move insn. This is not indexed by the rtx-code like bcc_gen_fctn and
80 setcc_gen_code to cut down on the number of named patterns. Consider a day
81 when a lot more rtx codes are conditional (eg: for the ARM). */
83 enum insn_code movcc_gen_code
[NUM_MACHINE_MODES
];
86 static int add_equal_note
PARAMS ((rtx
, rtx
, enum rtx_code
, rtx
, rtx
));
87 static rtx widen_operand
PARAMS ((rtx
, enum machine_mode
,
88 enum machine_mode
, int, int));
89 static int expand_cmplxdiv_straight
PARAMS ((rtx
, rtx
, rtx
, rtx
,
90 rtx
, rtx
, enum machine_mode
,
91 int, enum optab_methods
,
92 enum mode_class
, optab
));
93 static int expand_cmplxdiv_wide
PARAMS ((rtx
, rtx
, rtx
, rtx
,
94 rtx
, rtx
, enum machine_mode
,
95 int, enum optab_methods
,
96 enum mode_class
, optab
));
97 static enum insn_code can_fix_p
PARAMS ((enum machine_mode
, enum machine_mode
,
99 static enum insn_code can_float_p
PARAMS ((enum machine_mode
, enum machine_mode
,
101 static rtx ftruncify
PARAMS ((rtx
));
102 static optab init_optab
PARAMS ((enum rtx_code
));
103 static void init_libfuncs
PARAMS ((optab
, int, int, const char *, int));
104 static void init_integral_libfuncs
PARAMS ((optab
, const char *, int));
105 static void init_floating_libfuncs
PARAMS ((optab
, const char *, int));
106 #ifdef HAVE_conditional_trap
107 static void init_traps
PARAMS ((void));
109 static void emit_cmp_and_jump_insn_1
PARAMS ((rtx
, rtx
, enum machine_mode
,
110 enum rtx_code
, int, rtx
));
111 static void prepare_float_lib_cmp
PARAMS ((rtx
*, rtx
*, enum rtx_code
*,
112 enum machine_mode
*, int *));
114 /* Add a REG_EQUAL note to the last insn in SEQ. TARGET is being set to
115 the result of operation CODE applied to OP0 (and OP1 if it is a binary
118 If the last insn does not set TARGET, don't do anything, but return 1.
120 If a previous insn sets TARGET and TARGET is one of OP0 or OP1,
121 don't add the REG_EQUAL note but return 0. Our caller can then try
122 again, ensuring that TARGET is not one of the operands. */
125 add_equal_note (seq
, target
, code
, op0
, op1
)
135 if ((GET_RTX_CLASS (code
) != '1' && GET_RTX_CLASS (code
) != '2'
136 && GET_RTX_CLASS (code
) != 'c' && GET_RTX_CLASS (code
) != '<')
137 || GET_CODE (seq
) != SEQUENCE
138 || (set
= single_set (XVECEXP (seq
, 0, XVECLEN (seq
, 0) - 1))) == 0
139 || GET_CODE (target
) == ZERO_EXTRACT
140 || (! rtx_equal_p (SET_DEST (set
), target
)
141 /* For a STRICT_LOW_PART, the REG_NOTE applies to what is inside the
143 && (GET_CODE (SET_DEST (set
)) != STRICT_LOW_PART
144 || ! rtx_equal_p (SUBREG_REG (XEXP (SET_DEST (set
), 0)),
148 /* If TARGET is in OP0 or OP1, check if anything in SEQ sets TARGET
149 besides the last insn. */
150 if (reg_overlap_mentioned_p (target
, op0
)
151 || (op1
&& reg_overlap_mentioned_p (target
, op1
)))
152 for (i
= XVECLEN (seq
, 0) - 2; i
>= 0; i
--)
153 if (reg_set_p (target
, XVECEXP (seq
, 0, i
)))
156 if (GET_RTX_CLASS (code
) == '1')
157 note
= gen_rtx_fmt_e (code
, GET_MODE (target
), copy_rtx (op0
));
159 note
= gen_rtx_fmt_ee (code
, GET_MODE (target
), copy_rtx (op0
), copy_rtx (op1
));
161 set_unique_reg_note (XVECEXP (seq
, 0, XVECLEN (seq
, 0) - 1), REG_EQUAL
, note
);
166 /* Widen OP to MODE and return the rtx for the widened operand. UNSIGNEDP
167 says whether OP is signed or unsigned. NO_EXTEND is nonzero if we need
168 not actually do a sign-extend or zero-extend, but can leave the
169 higher-order bits of the result rtx undefined, for example, in the case
170 of logical operations, but not right shifts. */
173 widen_operand (op
, mode
, oldmode
, unsignedp
, no_extend
)
175 enum machine_mode mode
, oldmode
;
181 /* If we must extend do so. If OP is either a constant or a SUBREG
182 for a promoted object, also extend since it will be more efficient to
185 || GET_MODE (op
) == VOIDmode
186 || (GET_CODE (op
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (op
)))
187 return convert_modes (mode
, oldmode
, op
, unsignedp
);
189 /* If MODE is no wider than a single word, we return a paradoxical
191 if (GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
)
192 return gen_rtx_SUBREG (mode
, force_reg (GET_MODE (op
), op
), 0);
194 /* Otherwise, get an object of MODE, clobber it, and set the low-order
197 result
= gen_reg_rtx (mode
);
198 emit_insn (gen_rtx_CLOBBER (VOIDmode
, result
));
199 emit_move_insn (gen_lowpart (GET_MODE (op
), result
), op
);
203 /* Generate code to perform a straightforward complex divide. */
206 expand_cmplxdiv_straight (real0
, real1
, imag0
, imag1
, realr
, imagr
, submode
,
207 unsignedp
, methods
, class, binoptab
)
208 rtx real0
, real1
, imag0
, imag1
, realr
, imagr
;
209 enum machine_mode submode
;
211 enum optab_methods methods
;
212 enum mode_class
class;
219 optab this_add_optab
= add_optab
;
220 optab this_sub_optab
= sub_optab
;
221 optab this_neg_optab
= neg_optab
;
222 optab this_mul_optab
= smul_optab
;
224 if (binoptab
== sdivv_optab
)
226 this_add_optab
= addv_optab
;
227 this_sub_optab
= subv_optab
;
228 this_neg_optab
= negv_optab
;
229 this_mul_optab
= smulv_optab
;
232 /* Don't fetch these from memory more than once. */
233 real0
= force_reg (submode
, real0
);
234 real1
= force_reg (submode
, real1
);
237 imag0
= force_reg (submode
, imag0
);
239 imag1
= force_reg (submode
, imag1
);
241 /* Divisor: c*c + d*d. */
242 temp1
= expand_binop (submode
, this_mul_optab
, real1
, real1
,
243 NULL_RTX
, unsignedp
, methods
);
245 temp2
= expand_binop (submode
, this_mul_optab
, imag1
, imag1
,
246 NULL_RTX
, unsignedp
, methods
);
248 if (temp1
== 0 || temp2
== 0)
251 divisor
= expand_binop (submode
, this_add_optab
, temp1
, temp2
,
252 NULL_RTX
, unsignedp
, methods
);
258 /* Mathematically, ((a)(c-id))/divisor. */
259 /* Computationally, (a+i0) / (c+id) = (ac/(cc+dd)) + i(-ad/(cc+dd)). */
261 /* Calculate the dividend. */
262 real_t
= expand_binop (submode
, this_mul_optab
, real0
, real1
,
263 NULL_RTX
, unsignedp
, methods
);
265 imag_t
= expand_binop (submode
, this_mul_optab
, real0
, imag1
,
266 NULL_RTX
, unsignedp
, methods
);
268 if (real_t
== 0 || imag_t
== 0)
271 imag_t
= expand_unop (submode
, this_neg_optab
, imag_t
,
272 NULL_RTX
, unsignedp
);
276 /* Mathematically, ((a+ib)(c-id))/divider. */
277 /* Calculate the dividend. */
278 temp1
= expand_binop (submode
, this_mul_optab
, real0
, real1
,
279 NULL_RTX
, unsignedp
, methods
);
281 temp2
= expand_binop (submode
, this_mul_optab
, imag0
, imag1
,
282 NULL_RTX
, unsignedp
, methods
);
284 if (temp1
== 0 || temp2
== 0)
287 real_t
= expand_binop (submode
, this_add_optab
, temp1
, temp2
,
288 NULL_RTX
, unsignedp
, methods
);
290 temp1
= expand_binop (submode
, this_mul_optab
, imag0
, real1
,
291 NULL_RTX
, unsignedp
, methods
);
293 temp2
= expand_binop (submode
, this_mul_optab
, real0
, imag1
,
294 NULL_RTX
, unsignedp
, methods
);
296 if (temp1
== 0 || temp2
== 0)
299 imag_t
= expand_binop (submode
, this_sub_optab
, temp1
, temp2
,
300 NULL_RTX
, unsignedp
, methods
);
302 if (real_t
== 0 || imag_t
== 0)
306 if (class == MODE_COMPLEX_FLOAT
)
307 res
= expand_binop (submode
, binoptab
, real_t
, divisor
,
308 realr
, unsignedp
, methods
);
310 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
311 real_t
, divisor
, realr
, unsignedp
);
317 emit_move_insn (realr
, res
);
319 if (class == MODE_COMPLEX_FLOAT
)
320 res
= expand_binop (submode
, binoptab
, imag_t
, divisor
,
321 imagr
, unsignedp
, methods
);
323 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
324 imag_t
, divisor
, imagr
, unsignedp
);
330 emit_move_insn (imagr
, res
);
335 /* Generate code to perform a wide-input-range-acceptable complex divide. */
338 expand_cmplxdiv_wide (real0
, real1
, imag0
, imag1
, realr
, imagr
, submode
,
339 unsignedp
, methods
, class, binoptab
)
340 rtx real0
, real1
, imag0
, imag1
, realr
, imagr
;
341 enum machine_mode submode
;
343 enum optab_methods methods
;
344 enum mode_class
class;
349 rtx temp1
, temp2
, lab1
, lab2
;
350 enum machine_mode mode
;
353 optab this_add_optab
= add_optab
;
354 optab this_sub_optab
= sub_optab
;
355 optab this_neg_optab
= neg_optab
;
356 optab this_mul_optab
= smul_optab
;
358 if (binoptab
== sdivv_optab
)
360 this_add_optab
= addv_optab
;
361 this_sub_optab
= subv_optab
;
362 this_neg_optab
= negv_optab
;
363 this_mul_optab
= smulv_optab
;
366 /* Don't fetch these from memory more than once. */
367 real0
= force_reg (submode
, real0
);
368 real1
= force_reg (submode
, real1
);
371 imag0
= force_reg (submode
, imag0
);
373 imag1
= force_reg (submode
, imag1
);
375 /* XXX What's an "unsigned" complex number? */
383 temp1
= expand_abs (submode
, real1
, NULL_RTX
, unsignedp
, 1);
384 temp2
= expand_abs (submode
, imag1
, NULL_RTX
, unsignedp
, 1);
387 if (temp1
== 0 || temp2
== 0)
390 mode
= GET_MODE (temp1
);
391 align
= GET_MODE_ALIGNMENT (mode
);
392 lab1
= gen_label_rtx ();
393 emit_cmp_and_jump_insns (temp1
, temp2
, LT
, NULL_RTX
,
394 mode
, unsignedp
, align
, lab1
);
396 /* |c| >= |d|; use ratio d/c to scale dividend and divisor. */
398 if (class == MODE_COMPLEX_FLOAT
)
399 ratio
= expand_binop (submode
, binoptab
, imag1
, real1
,
400 NULL_RTX
, unsignedp
, methods
);
402 ratio
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
403 imag1
, real1
, NULL_RTX
, unsignedp
);
408 /* Calculate divisor. */
410 temp1
= expand_binop (submode
, this_mul_optab
, imag1
, ratio
,
411 NULL_RTX
, unsignedp
, methods
);
416 divisor
= expand_binop (submode
, this_add_optab
, temp1
, real1
,
417 NULL_RTX
, unsignedp
, methods
);
422 /* Calculate dividend. */
428 /* Compute a / (c+id) as a / (c+d(d/c)) + i (-a(d/c)) / (c+d(d/c)). */
430 imag_t
= expand_binop (submode
, this_mul_optab
, real0
, ratio
,
431 NULL_RTX
, unsignedp
, methods
);
436 imag_t
= expand_unop (submode
, this_neg_optab
, imag_t
,
437 NULL_RTX
, unsignedp
);
439 if (real_t
== 0 || imag_t
== 0)
444 /* Compute (a+ib)/(c+id) as
445 (a+b(d/c))/(c+d(d/c) + i(b-a(d/c))/(c+d(d/c)). */
447 temp1
= expand_binop (submode
, this_mul_optab
, imag0
, ratio
,
448 NULL_RTX
, unsignedp
, methods
);
453 real_t
= expand_binop (submode
, this_add_optab
, temp1
, real0
,
454 NULL_RTX
, unsignedp
, methods
);
456 temp1
= expand_binop (submode
, this_mul_optab
, real0
, ratio
,
457 NULL_RTX
, unsignedp
, methods
);
462 imag_t
= expand_binop (submode
, this_sub_optab
, imag0
, temp1
,
463 NULL_RTX
, unsignedp
, methods
);
465 if (real_t
== 0 || imag_t
== 0)
469 if (class == MODE_COMPLEX_FLOAT
)
470 res
= expand_binop (submode
, binoptab
, real_t
, divisor
,
471 realr
, unsignedp
, methods
);
473 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
474 real_t
, divisor
, realr
, unsignedp
);
480 emit_move_insn (realr
, res
);
482 if (class == MODE_COMPLEX_FLOAT
)
483 res
= expand_binop (submode
, binoptab
, imag_t
, divisor
,
484 imagr
, unsignedp
, methods
);
486 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
487 imag_t
, divisor
, imagr
, unsignedp
);
493 emit_move_insn (imagr
, res
);
495 lab2
= gen_label_rtx ();
496 emit_jump_insn (gen_jump (lab2
));
501 /* |d| > |c|; use ratio c/d to scale dividend and divisor. */
503 if (class == MODE_COMPLEX_FLOAT
)
504 ratio
= expand_binop (submode
, binoptab
, real1
, imag1
,
505 NULL_RTX
, unsignedp
, methods
);
507 ratio
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
508 real1
, imag1
, NULL_RTX
, unsignedp
);
513 /* Calculate divisor. */
515 temp1
= expand_binop (submode
, this_mul_optab
, real1
, ratio
,
516 NULL_RTX
, unsignedp
, methods
);
521 divisor
= expand_binop (submode
, this_add_optab
, temp1
, imag1
,
522 NULL_RTX
, unsignedp
, methods
);
527 /* Calculate dividend. */
531 /* Compute a / (c+id) as a(c/d) / (c(c/d)+d) + i (-a) / (c(c/d)+d). */
533 real_t
= expand_binop (submode
, this_mul_optab
, real0
, ratio
,
534 NULL_RTX
, unsignedp
, methods
);
536 imag_t
= expand_unop (submode
, this_neg_optab
, real0
,
537 NULL_RTX
, unsignedp
);
539 if (real_t
== 0 || imag_t
== 0)
544 /* Compute (a+ib)/(c+id) as
545 (a(c/d)+b)/(c(c/d)+d) + i (b(c/d)-a)/(c(c/d)+d). */
547 temp1
= expand_binop (submode
, this_mul_optab
, real0
, ratio
,
548 NULL_RTX
, unsignedp
, methods
);
553 real_t
= expand_binop (submode
, this_add_optab
, temp1
, imag0
,
554 NULL_RTX
, unsignedp
, methods
);
556 temp1
= expand_binop (submode
, this_mul_optab
, imag0
, ratio
,
557 NULL_RTX
, unsignedp
, methods
);
562 imag_t
= expand_binop (submode
, this_sub_optab
, temp1
, real0
,
563 NULL_RTX
, unsignedp
, methods
);
565 if (real_t
== 0 || imag_t
== 0)
569 if (class == MODE_COMPLEX_FLOAT
)
570 res
= expand_binop (submode
, binoptab
, real_t
, divisor
,
571 realr
, unsignedp
, methods
);
573 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
574 real_t
, divisor
, realr
, unsignedp
);
580 emit_move_insn (realr
, res
);
582 if (class == MODE_COMPLEX_FLOAT
)
583 res
= expand_binop (submode
, binoptab
, imag_t
, divisor
,
584 imagr
, unsignedp
, methods
);
586 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
587 imag_t
, divisor
, imagr
, unsignedp
);
593 emit_move_insn (imagr
, res
);
600 /* Generate code to perform an operation specified by BINOPTAB
601 on operands OP0 and OP1, with result having machine-mode MODE.
603 UNSIGNEDP is for the case where we have to widen the operands
604 to perform the operation. It says to use zero-extension.
606 If TARGET is nonzero, the value
607 is generated there, if it is convenient to do so.
608 In all cases an rtx is returned for the locus of the value;
609 this may or may not be TARGET. */
612 expand_binop (mode
, binoptab
, op0
, op1
, target
, unsignedp
, methods
)
613 enum machine_mode mode
;
618 enum optab_methods methods
;
620 enum optab_methods next_methods
621 = (methods
== OPTAB_LIB
|| methods
== OPTAB_LIB_WIDEN
622 ? OPTAB_WIDEN
: methods
);
623 enum mode_class
class;
624 enum machine_mode wider_mode
;
626 int commutative_op
= 0;
627 int shift_op
= (binoptab
->code
== ASHIFT
628 || binoptab
->code
== ASHIFTRT
629 || binoptab
->code
== LSHIFTRT
630 || binoptab
->code
== ROTATE
631 || binoptab
->code
== ROTATERT
);
632 rtx entry_last
= get_last_insn ();
635 class = GET_MODE_CLASS (mode
);
637 op0
= protect_from_queue (op0
, 0);
638 op1
= protect_from_queue (op1
, 0);
640 target
= protect_from_queue (target
, 1);
644 op0
= force_not_mem (op0
);
645 op1
= force_not_mem (op1
);
648 /* If subtracting an integer constant, convert this into an addition of
649 the negated constant. */
651 if (binoptab
== sub_optab
&& GET_CODE (op1
) == CONST_INT
)
653 op1
= negate_rtx (mode
, op1
);
654 binoptab
= add_optab
;
657 /* If we are inside an appropriately-short loop and one operand is an
658 expensive constant, force it into a register. */
659 if (CONSTANT_P (op0
) && preserve_subexpressions_p ()
660 && rtx_cost (op0
, binoptab
->code
) > COSTS_N_INSNS (1))
661 op0
= force_reg (mode
, op0
);
663 if (CONSTANT_P (op1
) && preserve_subexpressions_p ()
664 && ! shift_op
&& rtx_cost (op1
, binoptab
->code
) > COSTS_N_INSNS (1))
665 op1
= force_reg (mode
, op1
);
667 /* Record where to delete back to if we backtrack. */
668 last
= get_last_insn ();
670 /* If operation is commutative,
671 try to make the first operand a register.
672 Even better, try to make it the same as the target.
673 Also try to make the last operand a constant. */
674 if (GET_RTX_CLASS (binoptab
->code
) == 'c'
675 || binoptab
== smul_widen_optab
676 || binoptab
== umul_widen_optab
677 || binoptab
== smul_highpart_optab
678 || binoptab
== umul_highpart_optab
)
682 if (((target
== 0 || GET_CODE (target
) == REG
)
683 ? ((GET_CODE (op1
) == REG
684 && GET_CODE (op0
) != REG
)
686 : rtx_equal_p (op1
, target
))
687 || GET_CODE (op0
) == CONST_INT
)
695 /* If we can do it with a three-operand insn, do so. */
697 if (methods
!= OPTAB_MUST_WIDEN
698 && binoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
700 int icode
= (int) binoptab
->handlers
[(int) mode
].insn_code
;
701 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
702 enum machine_mode mode1
= insn_data
[icode
].operand
[2].mode
;
704 rtx xop0
= op0
, xop1
= op1
;
709 temp
= gen_reg_rtx (mode
);
711 /* If it is a commutative operator and the modes would match
712 if we would swap the operands, we can save the conversions. */
715 if (GET_MODE (op0
) != mode0
&& GET_MODE (op1
) != mode1
716 && GET_MODE (op0
) == mode1
&& GET_MODE (op1
) == mode0
)
720 tmp
= op0
; op0
= op1
; op1
= tmp
;
721 tmp
= xop0
; xop0
= xop1
; xop1
= tmp
;
725 /* In case the insn wants input operands in modes different from
726 the result, convert the operands. It would seem that we
727 don't need to convert CONST_INTs, but we do, so that they're
728 a properly sign-extended for their modes; we choose the
729 widest mode between mode and mode[01], so that, in a widening
730 operation, we call convert_modes with different FROM and TO
731 modes, which ensures the value is sign-extended. Shift
732 operations are an exception, because the second operand needs
733 not be extended to the mode of the result. */
735 if (GET_MODE (op0
) != mode0
736 && mode0
!= VOIDmode
)
737 xop0
= convert_modes (mode0
,
738 GET_MODE (op0
) != VOIDmode
740 : GET_MODE_SIZE (mode
) > GET_MODE_SIZE (mode0
)
745 if (GET_MODE (xop1
) != mode1
746 && mode1
!= VOIDmode
)
747 xop1
= convert_modes (mode1
,
748 GET_MODE (op1
) != VOIDmode
750 : (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (mode1
)
756 /* Now, if insn's predicates don't allow our operands, put them into
759 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
)
760 && mode0
!= VOIDmode
)
761 xop0
= copy_to_mode_reg (mode0
, xop0
);
763 if (! (*insn_data
[icode
].operand
[2].predicate
) (xop1
, mode1
)
764 && mode1
!= VOIDmode
)
765 xop1
= copy_to_mode_reg (mode1
, xop1
);
767 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, mode
))
768 temp
= gen_reg_rtx (mode
);
770 pat
= GEN_FCN (icode
) (temp
, xop0
, xop1
);
773 /* If PAT is a multi-insn sequence, try to add an appropriate
774 REG_EQUAL note to it. If we can't because TEMP conflicts with an
775 operand, call ourselves again, this time without a target. */
776 if (GET_CODE (pat
) == SEQUENCE
777 && ! add_equal_note (pat
, temp
, binoptab
->code
, xop0
, xop1
))
779 delete_insns_since (last
);
780 return expand_binop (mode
, binoptab
, op0
, op1
, NULL_RTX
,
788 delete_insns_since (last
);
791 /* If this is a multiply, see if we can do a widening operation that
792 takes operands of this mode and makes a wider mode. */
794 if (binoptab
== smul_optab
&& GET_MODE_WIDER_MODE (mode
) != VOIDmode
795 && (((unsignedp
? umul_widen_optab
: smul_widen_optab
)
796 ->handlers
[(int) GET_MODE_WIDER_MODE (mode
)].insn_code
)
797 != CODE_FOR_nothing
))
799 temp
= expand_binop (GET_MODE_WIDER_MODE (mode
),
800 unsignedp
? umul_widen_optab
: smul_widen_optab
,
801 op0
, op1
, NULL_RTX
, unsignedp
, OPTAB_DIRECT
);
805 if (GET_MODE_CLASS (mode
) == MODE_INT
)
806 return gen_lowpart (mode
, temp
);
808 return convert_to_mode (mode
, temp
, unsignedp
);
812 /* Look for a wider mode of the same class for which we think we
813 can open-code the operation. Check for a widening multiply at the
814 wider mode as well. */
816 if ((class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
817 && methods
!= OPTAB_DIRECT
&& methods
!= OPTAB_LIB
)
818 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
819 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
821 if (binoptab
->handlers
[(int) wider_mode
].insn_code
!= CODE_FOR_nothing
822 || (binoptab
== smul_optab
823 && GET_MODE_WIDER_MODE (wider_mode
) != VOIDmode
824 && (((unsignedp
? umul_widen_optab
: smul_widen_optab
)
825 ->handlers
[(int) GET_MODE_WIDER_MODE (wider_mode
)].insn_code
)
826 != CODE_FOR_nothing
)))
828 rtx xop0
= op0
, xop1
= op1
;
831 /* For certain integer operations, we need not actually extend
832 the narrow operands, as long as we will truncate
833 the results to the same narrowness. */
835 if ((binoptab
== ior_optab
|| binoptab
== and_optab
836 || binoptab
== xor_optab
837 || binoptab
== add_optab
|| binoptab
== sub_optab
838 || binoptab
== smul_optab
|| binoptab
== ashl_optab
)
839 && class == MODE_INT
)
842 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
, no_extend
);
844 /* The second operand of a shift must always be extended. */
845 xop1
= widen_operand (xop1
, wider_mode
, mode
, unsignedp
,
846 no_extend
&& binoptab
!= ashl_optab
);
848 temp
= expand_binop (wider_mode
, binoptab
, xop0
, xop1
, NULL_RTX
,
849 unsignedp
, OPTAB_DIRECT
);
852 if (class != MODE_INT
)
855 target
= gen_reg_rtx (mode
);
856 convert_move (target
, temp
, 0);
860 return gen_lowpart (mode
, temp
);
863 delete_insns_since (last
);
867 /* These can be done a word at a time. */
868 if ((binoptab
== and_optab
|| binoptab
== ior_optab
|| binoptab
== xor_optab
)
870 && GET_MODE_SIZE (mode
) > UNITS_PER_WORD
871 && binoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
877 /* If TARGET is the same as one of the operands, the REG_EQUAL note
878 won't be accurate, so use a new target. */
879 if (target
== 0 || target
== op0
|| target
== op1
)
880 target
= gen_reg_rtx (mode
);
884 /* Do the actual arithmetic. */
885 for (i
= 0; i
< GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
; i
++)
887 rtx target_piece
= operand_subword (target
, i
, 1, mode
);
888 rtx x
= expand_binop (word_mode
, binoptab
,
889 operand_subword_force (op0
, i
, mode
),
890 operand_subword_force (op1
, i
, mode
),
891 target_piece
, unsignedp
, next_methods
);
896 if (target_piece
!= x
)
897 emit_move_insn (target_piece
, x
);
900 insns
= get_insns ();
903 if (i
== GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
)
905 if (binoptab
->code
!= UNKNOWN
)
907 = gen_rtx_fmt_ee (binoptab
->code
, mode
,
908 copy_rtx (op0
), copy_rtx (op1
));
912 emit_no_conflict_block (insns
, target
, op0
, op1
, equiv_value
);
917 /* Synthesize double word shifts from single word shifts. */
918 if ((binoptab
== lshr_optab
|| binoptab
== ashl_optab
919 || binoptab
== ashr_optab
)
921 && GET_CODE (op1
) == CONST_INT
922 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
923 && binoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
924 && ashl_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
925 && lshr_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
927 rtx insns
, inter
, equiv_value
;
928 rtx into_target
, outof_target
;
929 rtx into_input
, outof_input
;
930 int shift_count
, left_shift
, outof_word
;
932 /* If TARGET is the same as one of the operands, the REG_EQUAL note
933 won't be accurate, so use a new target. */
934 if (target
== 0 || target
== op0
|| target
== op1
)
935 target
= gen_reg_rtx (mode
);
939 shift_count
= INTVAL (op1
);
941 /* OUTOF_* is the word we are shifting bits away from, and
942 INTO_* is the word that we are shifting bits towards, thus
943 they differ depending on the direction of the shift and
946 left_shift
= binoptab
== ashl_optab
;
947 outof_word
= left_shift
^ ! WORDS_BIG_ENDIAN
;
949 outof_target
= operand_subword (target
, outof_word
, 1, mode
);
950 into_target
= operand_subword (target
, 1 - outof_word
, 1, mode
);
952 outof_input
= operand_subword_force (op0
, outof_word
, mode
);
953 into_input
= operand_subword_force (op0
, 1 - outof_word
, mode
);
955 if (shift_count
>= BITS_PER_WORD
)
957 inter
= expand_binop (word_mode
, binoptab
,
959 GEN_INT (shift_count
- BITS_PER_WORD
),
960 into_target
, unsignedp
, next_methods
);
962 if (inter
!= 0 && inter
!= into_target
)
963 emit_move_insn (into_target
, inter
);
965 /* For a signed right shift, we must fill the word we are shifting
966 out of with copies of the sign bit. Otherwise it is zeroed. */
967 if (inter
!= 0 && binoptab
!= ashr_optab
)
968 inter
= CONST0_RTX (word_mode
);
970 inter
= expand_binop (word_mode
, binoptab
,
972 GEN_INT (BITS_PER_WORD
- 1),
973 outof_target
, unsignedp
, next_methods
);
975 if (inter
!= 0 && inter
!= outof_target
)
976 emit_move_insn (outof_target
, inter
);
981 optab reverse_unsigned_shift
, unsigned_shift
;
983 /* For a shift of less then BITS_PER_WORD, to compute the carry,
984 we must do a logical shift in the opposite direction of the
987 reverse_unsigned_shift
= (left_shift
? lshr_optab
: ashl_optab
);
989 /* For a shift of less than BITS_PER_WORD, to compute the word
990 shifted towards, we need to unsigned shift the orig value of
993 unsigned_shift
= (left_shift
? ashl_optab
: lshr_optab
);
995 carries
= expand_binop (word_mode
, reverse_unsigned_shift
,
997 GEN_INT (BITS_PER_WORD
- shift_count
),
998 0, unsignedp
, next_methods
);
1003 inter
= expand_binop (word_mode
, unsigned_shift
, into_input
,
1004 op1
, 0, unsignedp
, next_methods
);
1007 inter
= expand_binop (word_mode
, ior_optab
, carries
, inter
,
1008 into_target
, unsignedp
, next_methods
);
1010 if (inter
!= 0 && inter
!= into_target
)
1011 emit_move_insn (into_target
, inter
);
1014 inter
= expand_binop (word_mode
, binoptab
, outof_input
,
1015 op1
, outof_target
, unsignedp
, next_methods
);
1017 if (inter
!= 0 && inter
!= outof_target
)
1018 emit_move_insn (outof_target
, inter
);
1021 insns
= get_insns ();
1026 if (binoptab
->code
!= UNKNOWN
)
1027 equiv_value
= gen_rtx_fmt_ee (binoptab
->code
, mode
, op0
, op1
);
1031 emit_no_conflict_block (insns
, target
, op0
, op1
, equiv_value
);
1036 /* Synthesize double word rotates from single word shifts. */
1037 if ((binoptab
== rotl_optab
|| binoptab
== rotr_optab
)
1038 && class == MODE_INT
1039 && GET_CODE (op1
) == CONST_INT
1040 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
1041 && ashl_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1042 && lshr_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
1044 rtx insns
, equiv_value
;
1045 rtx into_target
, outof_target
;
1046 rtx into_input
, outof_input
;
1048 int shift_count
, left_shift
, outof_word
;
1050 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1051 won't be accurate, so use a new target. */
1052 if (target
== 0 || target
== op0
|| target
== op1
)
1053 target
= gen_reg_rtx (mode
);
1057 shift_count
= INTVAL (op1
);
1059 /* OUTOF_* is the word we are shifting bits away from, and
1060 INTO_* is the word that we are shifting bits towards, thus
1061 they differ depending on the direction of the shift and
1062 WORDS_BIG_ENDIAN. */
1064 left_shift
= (binoptab
== rotl_optab
);
1065 outof_word
= left_shift
^ ! WORDS_BIG_ENDIAN
;
1067 outof_target
= operand_subword (target
, outof_word
, 1, mode
);
1068 into_target
= operand_subword (target
, 1 - outof_word
, 1, mode
);
1070 outof_input
= operand_subword_force (op0
, outof_word
, mode
);
1071 into_input
= operand_subword_force (op0
, 1 - outof_word
, mode
);
1073 if (shift_count
== BITS_PER_WORD
)
1075 /* This is just a word swap. */
1076 emit_move_insn (outof_target
, into_input
);
1077 emit_move_insn (into_target
, outof_input
);
1082 rtx into_temp1
, into_temp2
, outof_temp1
, outof_temp2
;
1083 rtx first_shift_count
, second_shift_count
;
1084 optab reverse_unsigned_shift
, unsigned_shift
;
1086 reverse_unsigned_shift
= (left_shift
^ (shift_count
< BITS_PER_WORD
)
1087 ? lshr_optab
: ashl_optab
);
1089 unsigned_shift
= (left_shift
^ (shift_count
< BITS_PER_WORD
)
1090 ? ashl_optab
: lshr_optab
);
1092 if (shift_count
> BITS_PER_WORD
)
1094 first_shift_count
= GEN_INT (shift_count
- BITS_PER_WORD
);
1095 second_shift_count
= GEN_INT (2*BITS_PER_WORD
- shift_count
);
1099 first_shift_count
= GEN_INT (BITS_PER_WORD
- shift_count
);
1100 second_shift_count
= GEN_INT (shift_count
);
1103 into_temp1
= expand_binop (word_mode
, unsigned_shift
,
1104 outof_input
, first_shift_count
,
1105 NULL_RTX
, unsignedp
, next_methods
);
1106 into_temp2
= expand_binop (word_mode
, reverse_unsigned_shift
,
1107 into_input
, second_shift_count
,
1108 into_target
, unsignedp
, next_methods
);
1110 if (into_temp1
!= 0 && into_temp2
!= 0)
1111 inter
= expand_binop (word_mode
, ior_optab
, into_temp1
, into_temp2
,
1112 into_target
, unsignedp
, next_methods
);
1116 if (inter
!= 0 && inter
!= into_target
)
1117 emit_move_insn (into_target
, inter
);
1119 outof_temp1
= expand_binop (word_mode
, unsigned_shift
,
1120 into_input
, first_shift_count
,
1121 NULL_RTX
, unsignedp
, next_methods
);
1122 outof_temp2
= expand_binop (word_mode
, reverse_unsigned_shift
,
1123 outof_input
, second_shift_count
,
1124 outof_target
, unsignedp
, next_methods
);
1126 if (inter
!= 0 && outof_temp1
!= 0 && outof_temp2
!= 0)
1127 inter
= expand_binop (word_mode
, ior_optab
,
1128 outof_temp1
, outof_temp2
,
1129 outof_target
, unsignedp
, next_methods
);
1131 if (inter
!= 0 && inter
!= outof_target
)
1132 emit_move_insn (outof_target
, inter
);
1135 insns
= get_insns ();
1140 if (binoptab
->code
!= UNKNOWN
)
1141 equiv_value
= gen_rtx_fmt_ee (binoptab
->code
, mode
, op0
, op1
);
1145 /* We can't make this a no conflict block if this is a word swap,
1146 because the word swap case fails if the input and output values
1147 are in the same register. */
1148 if (shift_count
!= BITS_PER_WORD
)
1149 emit_no_conflict_block (insns
, target
, op0
, op1
, equiv_value
);
1158 /* These can be done a word at a time by propagating carries. */
1159 if ((binoptab
== add_optab
|| binoptab
== sub_optab
)
1160 && class == MODE_INT
1161 && GET_MODE_SIZE (mode
) >= 2 * UNITS_PER_WORD
1162 && binoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
1165 rtx carry_tmp
= gen_reg_rtx (word_mode
);
1166 optab otheroptab
= binoptab
== add_optab
? sub_optab
: add_optab
;
1167 unsigned int nwords
= GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
;
1168 rtx carry_in
= NULL_RTX
, carry_out
= NULL_RTX
;
1171 /* We can handle either a 1 or -1 value for the carry. If STORE_FLAG
1172 value is one of those, use it. Otherwise, use 1 since it is the
1173 one easiest to get. */
1174 #if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1
1175 int normalizep
= STORE_FLAG_VALUE
;
1180 /* Prepare the operands. */
1181 xop0
= force_reg (mode
, op0
);
1182 xop1
= force_reg (mode
, op1
);
1184 if (target
== 0 || GET_CODE (target
) != REG
1185 || target
== xop0
|| target
== xop1
)
1186 target
= gen_reg_rtx (mode
);
1188 /* Indicate for flow that the entire target reg is being set. */
1189 if (GET_CODE (target
) == REG
)
1190 emit_insn (gen_rtx_CLOBBER (VOIDmode
, target
));
1192 /* Do the actual arithmetic. */
1193 for (i
= 0; i
< nwords
; i
++)
1195 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
1196 rtx target_piece
= operand_subword (target
, index
, 1, mode
);
1197 rtx op0_piece
= operand_subword_force (xop0
, index
, mode
);
1198 rtx op1_piece
= operand_subword_force (xop1
, index
, mode
);
1201 /* Main add/subtract of the input operands. */
1202 x
= expand_binop (word_mode
, binoptab
,
1203 op0_piece
, op1_piece
,
1204 target_piece
, unsignedp
, next_methods
);
1210 /* Store carry from main add/subtract. */
1211 carry_out
= gen_reg_rtx (word_mode
);
1212 carry_out
= emit_store_flag_force (carry_out
,
1213 (binoptab
== add_optab
1216 word_mode
, 1, normalizep
);
1221 /* Add/subtract previous carry to main result. */
1222 x
= expand_binop (word_mode
,
1223 normalizep
== 1 ? binoptab
: otheroptab
,
1225 target_piece
, 1, next_methods
);
1228 else if (target_piece
!= x
)
1229 emit_move_insn (target_piece
, x
);
1233 /* THIS CODE HAS NOT BEEN TESTED. */
1234 /* Get out carry from adding/subtracting carry in. */
1235 carry_tmp
= emit_store_flag_force (carry_tmp
,
1236 binoptab
== add_optab
1239 word_mode
, 1, normalizep
);
1241 /* Logical-ior the two poss. carry together. */
1242 carry_out
= expand_binop (word_mode
, ior_optab
,
1243 carry_out
, carry_tmp
,
1244 carry_out
, 0, next_methods
);
1250 carry_in
= carry_out
;
1253 if (i
== GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
)
1255 if (mov_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
1257 rtx temp
= emit_move_insn (target
, target
);
1259 set_unique_reg_note (temp
,
1261 gen_rtx_fmt_ee (binoptab
->code
, mode
,
1270 delete_insns_since (last
);
1273 /* If we want to multiply two two-word values and have normal and widening
1274 multiplies of single-word values, we can do this with three smaller
1275 multiplications. Note that we do not make a REG_NO_CONFLICT block here
1276 because we are not operating on one word at a time.
1278 The multiplication proceeds as follows:
1279 _______________________
1280 [__op0_high_|__op0_low__]
1281 _______________________
1282 * [__op1_high_|__op1_low__]
1283 _______________________________________________
1284 _______________________
1285 (1) [__op0_low__*__op1_low__]
1286 _______________________
1287 (2a) [__op0_low__*__op1_high_]
1288 _______________________
1289 (2b) [__op0_high_*__op1_low__]
1290 _______________________
1291 (3) [__op0_high_*__op1_high_]
1294 This gives a 4-word result. Since we are only interested in the
1295 lower 2 words, partial result (3) and the upper words of (2a) and
1296 (2b) don't need to be calculated. Hence (2a) and (2b) can be
1297 calculated using non-widening multiplication.
1299 (1), however, needs to be calculated with an unsigned widening
1300 multiplication. If this operation is not directly supported we
1301 try using a signed widening multiplication and adjust the result.
1302 This adjustment works as follows:
1304 If both operands are positive then no adjustment is needed.
1306 If the operands have different signs, for example op0_low < 0 and
1307 op1_low >= 0, the instruction treats the most significant bit of
1308 op0_low as a sign bit instead of a bit with significance
1309 2**(BITS_PER_WORD-1), i.e. the instruction multiplies op1_low
1310 with 2**BITS_PER_WORD - op0_low, and two's complements the
1311 result. Conclusion: We need to add op1_low * 2**BITS_PER_WORD to
1314 Similarly, if both operands are negative, we need to add
1315 (op0_low + op1_low) * 2**BITS_PER_WORD.
1317 We use a trick to adjust quickly. We logically shift op0_low right
1318 (op1_low) BITS_PER_WORD-1 steps to get 0 or 1, and add this to
1319 op0_high (op1_high) before it is used to calculate 2b (2a). If no
1320 logical shift exists, we do an arithmetic right shift and subtract
1323 if (binoptab
== smul_optab
1324 && class == MODE_INT
1325 && GET_MODE_SIZE (mode
) == 2 * UNITS_PER_WORD
1326 && smul_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1327 && add_optab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
1328 && ((umul_widen_optab
->handlers
[(int) mode
].insn_code
1329 != CODE_FOR_nothing
)
1330 || (smul_widen_optab
->handlers
[(int) mode
].insn_code
1331 != CODE_FOR_nothing
)))
1333 int low
= (WORDS_BIG_ENDIAN
? 1 : 0);
1334 int high
= (WORDS_BIG_ENDIAN
? 0 : 1);
1335 rtx op0_high
= operand_subword_force (op0
, high
, mode
);
1336 rtx op0_low
= operand_subword_force (op0
, low
, mode
);
1337 rtx op1_high
= operand_subword_force (op1
, high
, mode
);
1338 rtx op1_low
= operand_subword_force (op1
, low
, mode
);
1340 rtx op0_xhigh
= NULL_RTX
;
1341 rtx op1_xhigh
= NULL_RTX
;
1343 /* If the target is the same as one of the inputs, don't use it. This
1344 prevents problems with the REG_EQUAL note. */
1345 if (target
== op0
|| target
== op1
1346 || (target
!= 0 && GET_CODE (target
) != REG
))
1349 /* Multiply the two lower words to get a double-word product.
1350 If unsigned widening multiplication is available, use that;
1351 otherwise use the signed form and compensate. */
1353 if (umul_widen_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
1355 product
= expand_binop (mode
, umul_widen_optab
, op0_low
, op1_low
,
1356 target
, 1, OPTAB_DIRECT
);
1358 /* If we didn't succeed, delete everything we did so far. */
1360 delete_insns_since (last
);
1362 op0_xhigh
= op0_high
, op1_xhigh
= op1_high
;
1366 && smul_widen_optab
->handlers
[(int) mode
].insn_code
1367 != CODE_FOR_nothing
)
1369 rtx wordm1
= GEN_INT (BITS_PER_WORD
- 1);
1370 product
= expand_binop (mode
, smul_widen_optab
, op0_low
, op1_low
,
1371 target
, 1, OPTAB_DIRECT
);
1372 op0_xhigh
= expand_binop (word_mode
, lshr_optab
, op0_low
, wordm1
,
1373 NULL_RTX
, 1, next_methods
);
1375 op0_xhigh
= expand_binop (word_mode
, add_optab
, op0_high
,
1376 op0_xhigh
, op0_xhigh
, 0, next_methods
);
1379 op0_xhigh
= expand_binop (word_mode
, ashr_optab
, op0_low
, wordm1
,
1380 NULL_RTX
, 0, next_methods
);
1382 op0_xhigh
= expand_binop (word_mode
, sub_optab
, op0_high
,
1383 op0_xhigh
, op0_xhigh
, 0,
1387 op1_xhigh
= expand_binop (word_mode
, lshr_optab
, op1_low
, wordm1
,
1388 NULL_RTX
, 1, next_methods
);
1390 op1_xhigh
= expand_binop (word_mode
, add_optab
, op1_high
,
1391 op1_xhigh
, op1_xhigh
, 0, next_methods
);
1394 op1_xhigh
= expand_binop (word_mode
, ashr_optab
, op1_low
, wordm1
,
1395 NULL_RTX
, 0, next_methods
);
1397 op1_xhigh
= expand_binop (word_mode
, sub_optab
, op1_high
,
1398 op1_xhigh
, op1_xhigh
, 0,
1403 /* If we have been able to directly compute the product of the
1404 low-order words of the operands and perform any required adjustments
1405 of the operands, we proceed by trying two more multiplications
1406 and then computing the appropriate sum.
1408 We have checked above that the required addition is provided.
1409 Full-word addition will normally always succeed, especially if
1410 it is provided at all, so we don't worry about its failure. The
1411 multiplication may well fail, however, so we do handle that. */
1413 if (product
&& op0_xhigh
&& op1_xhigh
)
1415 rtx product_high
= operand_subword (product
, high
, 1, mode
);
1416 rtx temp
= expand_binop (word_mode
, binoptab
, op0_low
, op1_xhigh
,
1417 NULL_RTX
, 0, OPTAB_DIRECT
);
1420 temp
= expand_binop (word_mode
, add_optab
, temp
, product_high
,
1421 product_high
, 0, next_methods
);
1423 if (temp
!= 0 && temp
!= product_high
)
1424 emit_move_insn (product_high
, temp
);
1427 temp
= expand_binop (word_mode
, binoptab
, op1_low
, op0_xhigh
,
1428 NULL_RTX
, 0, OPTAB_DIRECT
);
1431 temp
= expand_binop (word_mode
, add_optab
, temp
,
1432 product_high
, product_high
,
1435 if (temp
!= 0 && temp
!= product_high
)
1436 emit_move_insn (product_high
, temp
);
1440 if (mov_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
1442 temp
= emit_move_insn (product
, product
);
1443 set_unique_reg_note (temp
,
1445 gen_rtx_fmt_ee (MULT
, mode
,
1454 /* If we get here, we couldn't do it for some reason even though we
1455 originally thought we could. Delete anything we've emitted in
1458 delete_insns_since (last
);
1461 /* We need to open-code the complex type operations: '+, -, * and /' */
1463 /* At this point we allow operations between two similar complex
1464 numbers, and also if one of the operands is not a complex number
1465 but rather of MODE_FLOAT or MODE_INT. However, the caller
1466 must make sure that the MODE of the non-complex operand matches
1467 the SUBMODE of the complex operand. */
1469 if (class == MODE_COMPLEX_FLOAT
|| class == MODE_COMPLEX_INT
)
1471 rtx real0
= 0, imag0
= 0;
1472 rtx real1
= 0, imag1
= 0;
1473 rtx realr
, imagr
, res
;
1478 /* Find the correct mode for the real and imaginary parts */
1479 enum machine_mode submode
1480 = mode_for_size (GET_MODE_UNIT_SIZE (mode
) * BITS_PER_UNIT
,
1481 class == MODE_COMPLEX_INT
? MODE_INT
: MODE_FLOAT
,
1484 if (submode
== BLKmode
)
1488 target
= gen_reg_rtx (mode
);
1492 realr
= gen_realpart (submode
, target
);
1493 imagr
= gen_imagpart (submode
, target
);
1495 if (GET_MODE (op0
) == mode
)
1497 real0
= gen_realpart (submode
, op0
);
1498 imag0
= gen_imagpart (submode
, op0
);
1503 if (GET_MODE (op1
) == mode
)
1505 real1
= gen_realpart (submode
, op1
);
1506 imag1
= gen_imagpart (submode
, op1
);
1511 if (real0
== 0 || real1
== 0 || ! (imag0
!= 0|| imag1
!= 0))
1514 switch (binoptab
->code
)
1517 /* (a+ib) + (c+id) = (a+c) + i(b+d) */
1519 /* (a+ib) - (c+id) = (a-c) + i(b-d) */
1520 res
= expand_binop (submode
, binoptab
, real0
, real1
,
1521 realr
, unsignedp
, methods
);
1525 else if (res
!= realr
)
1526 emit_move_insn (realr
, res
);
1529 res
= expand_binop (submode
, binoptab
, imag0
, imag1
,
1530 imagr
, unsignedp
, methods
);
1533 else if (binoptab
->code
== MINUS
)
1534 res
= expand_unop (submode
,
1535 binoptab
== subv_optab
? negv_optab
: neg_optab
,
1536 imag1
, imagr
, unsignedp
);
1542 else if (res
!= imagr
)
1543 emit_move_insn (imagr
, res
);
1549 /* (a+ib) * (c+id) = (ac-bd) + i(ad+cb) */
1555 /* Don't fetch these from memory more than once. */
1556 real0
= force_reg (submode
, real0
);
1557 real1
= force_reg (submode
, real1
);
1558 imag0
= force_reg (submode
, imag0
);
1559 imag1
= force_reg (submode
, imag1
);
1561 temp1
= expand_binop (submode
, binoptab
, real0
, real1
, NULL_RTX
,
1562 unsignedp
, methods
);
1564 temp2
= expand_binop (submode
, binoptab
, imag0
, imag1
, NULL_RTX
,
1565 unsignedp
, methods
);
1567 if (temp1
== 0 || temp2
== 0)
1572 binoptab
== smulv_optab
? subv_optab
: sub_optab
,
1573 temp1
, temp2
, realr
, unsignedp
, methods
));
1577 else if (res
!= realr
)
1578 emit_move_insn (realr
, res
);
1580 temp1
= expand_binop (submode
, binoptab
, real0
, imag1
,
1581 NULL_RTX
, unsignedp
, methods
);
1583 temp2
= expand_binop (submode
, binoptab
, real1
, imag0
,
1584 NULL_RTX
, unsignedp
, methods
);
1586 if (temp1
== 0 || temp2
== 0)
1591 binoptab
== smulv_optab
? addv_optab
: add_optab
,
1592 temp1
, temp2
, imagr
, unsignedp
, methods
));
1596 else if (res
!= imagr
)
1597 emit_move_insn (imagr
, res
);
1603 /* Don't fetch these from memory more than once. */
1604 real0
= force_reg (submode
, real0
);
1605 real1
= force_reg (submode
, real1
);
1607 res
= expand_binop (submode
, binoptab
, real0
, real1
,
1608 realr
, unsignedp
, methods
);
1611 else if (res
!= realr
)
1612 emit_move_insn (realr
, res
);
1615 res
= expand_binop (submode
, binoptab
,
1616 real1
, imag0
, imagr
, unsignedp
, methods
);
1618 res
= expand_binop (submode
, binoptab
,
1619 real0
, imag1
, imagr
, unsignedp
, methods
);
1623 else if (res
!= imagr
)
1624 emit_move_insn (imagr
, res
);
1631 /* (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) */
1635 /* (a+ib) / (c+i0) = (a/c) + i(b/c) */
1637 /* Don't fetch these from memory more than once. */
1638 real1
= force_reg (submode
, real1
);
1640 /* Simply divide the real and imaginary parts by `c' */
1641 if (class == MODE_COMPLEX_FLOAT
)
1642 res
= expand_binop (submode
, binoptab
, real0
, real1
,
1643 realr
, unsignedp
, methods
);
1645 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
1646 real0
, real1
, realr
, unsignedp
);
1650 else if (res
!= realr
)
1651 emit_move_insn (realr
, res
);
1653 if (class == MODE_COMPLEX_FLOAT
)
1654 res
= expand_binop (submode
, binoptab
, imag0
, real1
,
1655 imagr
, unsignedp
, methods
);
1657 res
= expand_divmod (0, TRUNC_DIV_EXPR
, submode
,
1658 imag0
, real1
, imagr
, unsignedp
);
1662 else if (res
!= imagr
)
1663 emit_move_insn (imagr
, res
);
1669 switch (flag_complex_divide_method
)
1672 ok
= expand_cmplxdiv_straight (real0
, real1
, imag0
, imag1
,
1673 realr
, imagr
, submode
,
1679 ok
= expand_cmplxdiv_wide (real0
, real1
, imag0
, imag1
,
1680 realr
, imagr
, submode
,
1700 if (binoptab
->code
!= UNKNOWN
)
1702 = gen_rtx_fmt_ee (binoptab
->code
, mode
,
1703 copy_rtx (op0
), copy_rtx (op1
));
1707 emit_no_conflict_block (seq
, target
, op0
, op1
, equiv_value
);
1713 /* It can't be open-coded in this mode.
1714 Use a library call if one is available and caller says that's ok. */
1716 if (binoptab
->handlers
[(int) mode
].libfunc
1717 && (methods
== OPTAB_LIB
|| methods
== OPTAB_LIB_WIDEN
))
1721 enum machine_mode op1_mode
= mode
;
1728 op1_mode
= word_mode
;
1729 /* Specify unsigned here,
1730 since negative shift counts are meaningless. */
1731 op1x
= convert_to_mode (word_mode
, op1
, 1);
1734 if (GET_MODE (op0
) != VOIDmode
1735 && GET_MODE (op0
) != mode
)
1736 op0
= convert_to_mode (mode
, op0
, unsignedp
);
1738 /* Pass 1 for NO_QUEUE so we don't lose any increments
1739 if the libcall is cse'd or moved. */
1740 value
= emit_library_call_value (binoptab
->handlers
[(int) mode
].libfunc
,
1741 NULL_RTX
, LCT_CONST
, mode
, 2,
1742 op0
, mode
, op1x
, op1_mode
);
1744 insns
= get_insns ();
1747 target
= gen_reg_rtx (mode
);
1748 emit_libcall_block (insns
, target
, value
,
1749 gen_rtx_fmt_ee (binoptab
->code
, mode
, op0
, op1
));
1754 delete_insns_since (last
);
1756 /* It can't be done in this mode. Can we do it in a wider mode? */
1758 if (! (methods
== OPTAB_WIDEN
|| methods
== OPTAB_LIB_WIDEN
1759 || methods
== OPTAB_MUST_WIDEN
))
1761 /* Caller says, don't even try. */
1762 delete_insns_since (entry_last
);
1766 /* Compute the value of METHODS to pass to recursive calls.
1767 Don't allow widening to be tried recursively. */
1769 methods
= (methods
== OPTAB_LIB_WIDEN
? OPTAB_LIB
: OPTAB_DIRECT
);
1771 /* Look for a wider mode of the same class for which it appears we can do
1774 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
1776 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
1777 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
1779 if ((binoptab
->handlers
[(int) wider_mode
].insn_code
1780 != CODE_FOR_nothing
)
1781 || (methods
== OPTAB_LIB
1782 && binoptab
->handlers
[(int) wider_mode
].libfunc
))
1784 rtx xop0
= op0
, xop1
= op1
;
1787 /* For certain integer operations, we need not actually extend
1788 the narrow operands, as long as we will truncate
1789 the results to the same narrowness. */
1791 if ((binoptab
== ior_optab
|| binoptab
== and_optab
1792 || binoptab
== xor_optab
1793 || binoptab
== add_optab
|| binoptab
== sub_optab
1794 || binoptab
== smul_optab
|| binoptab
== ashl_optab
)
1795 && class == MODE_INT
)
1798 xop0
= widen_operand (xop0
, wider_mode
, mode
,
1799 unsignedp
, no_extend
);
1801 /* The second operand of a shift must always be extended. */
1802 xop1
= widen_operand (xop1
, wider_mode
, mode
, unsignedp
,
1803 no_extend
&& binoptab
!= ashl_optab
);
1805 temp
= expand_binop (wider_mode
, binoptab
, xop0
, xop1
, NULL_RTX
,
1806 unsignedp
, methods
);
1809 if (class != MODE_INT
)
1812 target
= gen_reg_rtx (mode
);
1813 convert_move (target
, temp
, 0);
1817 return gen_lowpart (mode
, temp
);
1820 delete_insns_since (last
);
1825 delete_insns_since (entry_last
);
1829 /* Expand a binary operator which has both signed and unsigned forms.
1830 UOPTAB is the optab for unsigned operations, and SOPTAB is for
1833 If we widen unsigned operands, we may use a signed wider operation instead
1834 of an unsigned wider operation, since the result would be the same. */
1837 sign_expand_binop (mode
, uoptab
, soptab
, op0
, op1
, target
, unsignedp
, methods
)
1838 enum machine_mode mode
;
1839 optab uoptab
, soptab
;
1840 rtx op0
, op1
, target
;
1842 enum optab_methods methods
;
1845 optab direct_optab
= unsignedp
? uoptab
: soptab
;
1846 struct optab wide_soptab
;
1848 /* Do it without widening, if possible. */
1849 temp
= expand_binop (mode
, direct_optab
, op0
, op1
, target
,
1850 unsignedp
, OPTAB_DIRECT
);
1851 if (temp
|| methods
== OPTAB_DIRECT
)
1854 /* Try widening to a signed int. Make a fake signed optab that
1855 hides any signed insn for direct use. */
1856 wide_soptab
= *soptab
;
1857 wide_soptab
.handlers
[(int) mode
].insn_code
= CODE_FOR_nothing
;
1858 wide_soptab
.handlers
[(int) mode
].libfunc
= 0;
1860 temp
= expand_binop (mode
, &wide_soptab
, op0
, op1
, target
,
1861 unsignedp
, OPTAB_WIDEN
);
1863 /* For unsigned operands, try widening to an unsigned int. */
1864 if (temp
== 0 && unsignedp
)
1865 temp
= expand_binop (mode
, uoptab
, op0
, op1
, target
,
1866 unsignedp
, OPTAB_WIDEN
);
1867 if (temp
|| methods
== OPTAB_WIDEN
)
1870 /* Use the right width lib call if that exists. */
1871 temp
= expand_binop (mode
, direct_optab
, op0
, op1
, target
, unsignedp
, OPTAB_LIB
);
1872 if (temp
|| methods
== OPTAB_LIB
)
1875 /* Must widen and use a lib call, use either signed or unsigned. */
1876 temp
= expand_binop (mode
, &wide_soptab
, op0
, op1
, target
,
1877 unsignedp
, methods
);
1881 return expand_binop (mode
, uoptab
, op0
, op1
, target
,
1882 unsignedp
, methods
);
1886 /* Generate code to perform an operation specified by BINOPTAB
1887 on operands OP0 and OP1, with two results to TARG1 and TARG2.
1888 We assume that the order of the operands for the instruction
1889 is TARG0, OP0, OP1, TARG1, which would fit a pattern like
1890 [(set TARG0 (operate OP0 OP1)) (set TARG1 (operate ...))].
1892 Either TARG0 or TARG1 may be zero, but what that means is that
1893 the result is not actually wanted. We will generate it into
1894 a dummy pseudo-reg and discard it. They may not both be zero.
1896 Returns 1 if this operation can be performed; 0 if not. */
1899 expand_twoval_binop (binoptab
, op0
, op1
, targ0
, targ1
, unsignedp
)
1905 enum machine_mode mode
= GET_MODE (targ0
? targ0
: targ1
);
1906 enum mode_class
class;
1907 enum machine_mode wider_mode
;
1908 rtx entry_last
= get_last_insn ();
1911 class = GET_MODE_CLASS (mode
);
1913 op0
= protect_from_queue (op0
, 0);
1914 op1
= protect_from_queue (op1
, 0);
1918 op0
= force_not_mem (op0
);
1919 op1
= force_not_mem (op1
);
1922 /* If we are inside an appropriately-short loop and one operand is an
1923 expensive constant, force it into a register. */
1924 if (CONSTANT_P (op0
) && preserve_subexpressions_p ()
1925 && rtx_cost (op0
, binoptab
->code
) > COSTS_N_INSNS (1))
1926 op0
= force_reg (mode
, op0
);
1928 if (CONSTANT_P (op1
) && preserve_subexpressions_p ()
1929 && rtx_cost (op1
, binoptab
->code
) > COSTS_N_INSNS (1))
1930 op1
= force_reg (mode
, op1
);
1933 targ0
= protect_from_queue (targ0
, 1);
1935 targ0
= gen_reg_rtx (mode
);
1937 targ1
= protect_from_queue (targ1
, 1);
1939 targ1
= gen_reg_rtx (mode
);
1941 /* Record where to go back to if we fail. */
1942 last
= get_last_insn ();
1944 if (binoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
1946 int icode
= (int) binoptab
->handlers
[(int) mode
].insn_code
;
1947 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
1948 enum machine_mode mode1
= insn_data
[icode
].operand
[2].mode
;
1950 rtx xop0
= op0
, xop1
= op1
;
1952 /* In case this insn wants input operands in modes different from the
1953 result, convert the operands. */
1954 if (GET_MODE (op0
) != VOIDmode
&& GET_MODE (op0
) != mode0
)
1955 xop0
= convert_to_mode (mode0
, xop0
, unsignedp
);
1957 if (GET_MODE (op1
) != VOIDmode
&& GET_MODE (op1
) != mode1
)
1958 xop1
= convert_to_mode (mode1
, xop1
, unsignedp
);
1960 /* Now, if insn doesn't accept these operands, put them into pseudos. */
1961 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
))
1962 xop0
= copy_to_mode_reg (mode0
, xop0
);
1964 if (! (*insn_data
[icode
].operand
[2].predicate
) (xop1
, mode1
))
1965 xop1
= copy_to_mode_reg (mode1
, xop1
);
1967 /* We could handle this, but we should always be called with a pseudo
1968 for our targets and all insns should take them as outputs. */
1969 if (! (*insn_data
[icode
].operand
[0].predicate
) (targ0
, mode
)
1970 || ! (*insn_data
[icode
].operand
[3].predicate
) (targ1
, mode
))
1973 pat
= GEN_FCN (icode
) (targ0
, xop0
, xop1
, targ1
);
1980 delete_insns_since (last
);
1983 /* It can't be done in this mode. Can we do it in a wider mode? */
1985 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
1987 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
1988 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
1990 if (binoptab
->handlers
[(int) wider_mode
].insn_code
1991 != CODE_FOR_nothing
)
1993 register rtx t0
= gen_reg_rtx (wider_mode
);
1994 register rtx t1
= gen_reg_rtx (wider_mode
);
1995 rtx cop0
= convert_modes (wider_mode
, mode
, op0
, unsignedp
);
1996 rtx cop1
= convert_modes (wider_mode
, mode
, op1
, unsignedp
);
1998 if (expand_twoval_binop (binoptab
, cop0
, cop1
,
2001 convert_move (targ0
, t0
, unsignedp
);
2002 convert_move (targ1
, t1
, unsignedp
);
2006 delete_insns_since (last
);
2011 delete_insns_since (entry_last
);
2015 /* Generate code to perform an operation specified by UNOPTAB
2016 on operand OP0, with result having machine-mode MODE.
2018 UNSIGNEDP is for the case where we have to widen the operands
2019 to perform the operation. It says to use zero-extension.
2021 If TARGET is nonzero, the value
2022 is generated there, if it is convenient to do so.
2023 In all cases an rtx is returned for the locus of the value;
2024 this may or may not be TARGET. */
2027 expand_unop (mode
, unoptab
, op0
, target
, unsignedp
)
2028 enum machine_mode mode
;
2034 enum mode_class
class;
2035 enum machine_mode wider_mode
;
2037 rtx last
= get_last_insn ();
2040 class = GET_MODE_CLASS (mode
);
2042 op0
= protect_from_queue (op0
, 0);
2046 op0
= force_not_mem (op0
);
2050 target
= protect_from_queue (target
, 1);
2052 if (unoptab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2054 int icode
= (int) unoptab
->handlers
[(int) mode
].insn_code
;
2055 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
2061 temp
= gen_reg_rtx (mode
);
2063 if (GET_MODE (xop0
) != VOIDmode
2064 && GET_MODE (xop0
) != mode0
)
2065 xop0
= convert_to_mode (mode0
, xop0
, unsignedp
);
2067 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
2069 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
))
2070 xop0
= copy_to_mode_reg (mode0
, xop0
);
2072 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, mode
))
2073 temp
= gen_reg_rtx (mode
);
2075 pat
= GEN_FCN (icode
) (temp
, xop0
);
2078 if (GET_CODE (pat
) == SEQUENCE
2079 && ! add_equal_note (pat
, temp
, unoptab
->code
, xop0
, NULL_RTX
))
2081 delete_insns_since (last
);
2082 return expand_unop (mode
, unoptab
, op0
, NULL_RTX
, unsignedp
);
2090 delete_insns_since (last
);
2093 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2095 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2096 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2097 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2099 if (unoptab
->handlers
[(int) wider_mode
].insn_code
!= CODE_FOR_nothing
)
2103 /* For certain operations, we need not actually extend
2104 the narrow operand, as long as we will truncate the
2105 results to the same narrowness. */
2107 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
,
2108 (unoptab
== neg_optab
2109 || unoptab
== one_cmpl_optab
)
2110 && class == MODE_INT
);
2112 temp
= expand_unop (wider_mode
, unoptab
, xop0
, NULL_RTX
,
2117 if (class != MODE_INT
)
2120 target
= gen_reg_rtx (mode
);
2121 convert_move (target
, temp
, 0);
2125 return gen_lowpart (mode
, temp
);
2128 delete_insns_since (last
);
2132 /* These can be done a word at a time. */
2133 if (unoptab
== one_cmpl_optab
2134 && class == MODE_INT
2135 && GET_MODE_SIZE (mode
) > UNITS_PER_WORD
2136 && unoptab
->handlers
[(int) word_mode
].insn_code
!= CODE_FOR_nothing
)
2141 if (target
== 0 || target
== op0
)
2142 target
= gen_reg_rtx (mode
);
2146 /* Do the actual arithmetic. */
2147 for (i
= 0; i
< GET_MODE_BITSIZE (mode
) / BITS_PER_WORD
; i
++)
2149 rtx target_piece
= operand_subword (target
, i
, 1, mode
);
2150 rtx x
= expand_unop (word_mode
, unoptab
,
2151 operand_subword_force (op0
, i
, mode
),
2152 target_piece
, unsignedp
);
2153 if (target_piece
!= x
)
2154 emit_move_insn (target_piece
, x
);
2157 insns
= get_insns ();
2160 emit_no_conflict_block (insns
, target
, op0
, NULL_RTX
,
2161 gen_rtx_fmt_e (unoptab
->code
, mode
,
2166 /* Open-code the complex negation operation. */
2167 else if (unoptab
->code
== NEG
2168 && (class == MODE_COMPLEX_FLOAT
|| class == MODE_COMPLEX_INT
))
2174 /* Find the correct mode for the real and imaginary parts */
2175 enum machine_mode submode
2176 = mode_for_size (GET_MODE_UNIT_SIZE (mode
) * BITS_PER_UNIT
,
2177 class == MODE_COMPLEX_INT
? MODE_INT
: MODE_FLOAT
,
2180 if (submode
== BLKmode
)
2184 target
= gen_reg_rtx (mode
);
2188 target_piece
= gen_imagpart (submode
, target
);
2189 x
= expand_unop (submode
, unoptab
,
2190 gen_imagpart (submode
, op0
),
2191 target_piece
, unsignedp
);
2192 if (target_piece
!= x
)
2193 emit_move_insn (target_piece
, x
);
2195 target_piece
= gen_realpart (submode
, target
);
2196 x
= expand_unop (submode
, unoptab
,
2197 gen_realpart (submode
, op0
),
2198 target_piece
, unsignedp
);
2199 if (target_piece
!= x
)
2200 emit_move_insn (target_piece
, x
);
2205 emit_no_conflict_block (seq
, target
, op0
, 0,
2206 gen_rtx_fmt_e (unoptab
->code
, mode
,
2211 /* Now try a library call in this mode. */
2212 if (unoptab
->handlers
[(int) mode
].libfunc
)
2219 /* Pass 1 for NO_QUEUE so we don't lose any increments
2220 if the libcall is cse'd or moved. */
2221 value
= emit_library_call_value (unoptab
->handlers
[(int) mode
].libfunc
,
2222 NULL_RTX
, LCT_CONST
, mode
, 1, op0
, mode
);
2223 insns
= get_insns ();
2226 target
= gen_reg_rtx (mode
);
2227 emit_libcall_block (insns
, target
, value
,
2228 gen_rtx_fmt_e (unoptab
->code
, mode
, op0
));
2233 /* It can't be done in this mode. Can we do it in a wider mode? */
2235 if (class == MODE_INT
|| class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
2237 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2238 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2240 if ((unoptab
->handlers
[(int) wider_mode
].insn_code
2241 != CODE_FOR_nothing
)
2242 || unoptab
->handlers
[(int) wider_mode
].libfunc
)
2246 /* For certain operations, we need not actually extend
2247 the narrow operand, as long as we will truncate the
2248 results to the same narrowness. */
2250 xop0
= widen_operand (xop0
, wider_mode
, mode
, unsignedp
,
2251 (unoptab
== neg_optab
2252 || unoptab
== one_cmpl_optab
)
2253 && class == MODE_INT
);
2255 temp
= expand_unop (wider_mode
, unoptab
, xop0
, NULL_RTX
,
2260 if (class != MODE_INT
)
2263 target
= gen_reg_rtx (mode
);
2264 convert_move (target
, temp
, 0);
2268 return gen_lowpart (mode
, temp
);
2271 delete_insns_since (last
);
2276 /* If there is no negate operation, try doing a subtract from zero.
2277 The US Software GOFAST library needs this. */
2278 if (unoptab
->code
== NEG
)
2281 temp
= expand_binop (mode
,
2282 unoptab
== negv_optab
? subv_optab
: sub_optab
,
2283 CONST0_RTX (mode
), op0
,
2284 target
, unsignedp
, OPTAB_LIB_WIDEN
);
2292 /* Emit code to compute the absolute value of OP0, with result to
2293 TARGET if convenient. (TARGET may be 0.) The return value says
2294 where the result actually is to be found.
2296 MODE is the mode of the operand; the mode of the result is
2297 different but can be deduced from MODE.
2302 expand_abs (mode
, op0
, target
, result_unsignedp
, safe
)
2303 enum machine_mode mode
;
2306 int result_unsignedp
;
2312 result_unsignedp
= 1;
2314 /* First try to do it with a special abs instruction. */
2315 temp
= expand_unop (mode
, result_unsignedp
? abs_optab
: absv_optab
,
2320 /* If we have a MAX insn, we can do this as MAX (x, -x). */
2321 if (smax_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2323 rtx last
= get_last_insn ();
2325 temp
= expand_unop (mode
, neg_optab
, op0
, NULL_RTX
, 0);
2327 temp
= expand_binop (mode
, smax_optab
, op0
, temp
, target
, 0,
2333 delete_insns_since (last
);
2336 /* If this machine has expensive jumps, we can do integer absolute
2337 value of X as (((signed) x >> (W-1)) ^ x) - ((signed) x >> (W-1)),
2338 where W is the width of MODE. */
2340 if (GET_MODE_CLASS (mode
) == MODE_INT
&& BRANCH_COST
>= 2)
2342 rtx extended
= expand_shift (RSHIFT_EXPR
, mode
, op0
,
2343 size_int (GET_MODE_BITSIZE (mode
) - 1),
2346 temp
= expand_binop (mode
, xor_optab
, extended
, op0
, target
, 0,
2349 temp
= expand_binop (mode
, result_unsignedp
? sub_optab
: subv_optab
,
2350 temp
, extended
, target
, 0, OPTAB_LIB_WIDEN
);
2356 /* If that does not win, use conditional jump and negate. */
2358 /* It is safe to use the target if it is the same
2359 as the source if this is also a pseudo register */
2360 if (op0
== target
&& GET_CODE (op0
) == REG
2361 && REGNO (op0
) >= FIRST_PSEUDO_REGISTER
)
2364 op1
= gen_label_rtx ();
2365 if (target
== 0 || ! safe
2366 || GET_MODE (target
) != mode
2367 || (GET_CODE (target
) == MEM
&& MEM_VOLATILE_P (target
))
2368 || (GET_CODE (target
) == REG
2369 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
2370 target
= gen_reg_rtx (mode
);
2372 emit_move_insn (target
, op0
);
2375 /* If this mode is an integer too wide to compare properly,
2376 compare word by word. Rely on CSE to optimize constant cases. */
2377 if (GET_MODE_CLASS (mode
) == MODE_INT
2378 && ! can_compare_p (GE
, mode
, ccp_jump
))
2379 do_jump_by_parts_greater_rtx (mode
, 0, target
, const0_rtx
,
2382 do_compare_rtx_and_jump (target
, CONST0_RTX (mode
), GE
, 0, mode
,
2383 NULL_RTX
, 0, NULL_RTX
, op1
);
2385 op0
= expand_unop (mode
, result_unsignedp
? neg_optab
: negv_optab
,
2388 emit_move_insn (target
, op0
);
2394 /* Emit code to compute the absolute value of OP0, with result to
2395 TARGET if convenient. (TARGET may be 0.) The return value says
2396 where the result actually is to be found.
2398 MODE is the mode of the operand; the mode of the result is
2399 different but can be deduced from MODE.
2401 UNSIGNEDP is relevant for complex integer modes. */
2404 expand_complex_abs (mode
, op0
, target
, unsignedp
)
2405 enum machine_mode mode
;
2410 enum mode_class
class = GET_MODE_CLASS (mode
);
2411 enum machine_mode wider_mode
;
2413 rtx entry_last
= get_last_insn ();
2416 optab this_abs_optab
;
2418 /* Find the correct mode for the real and imaginary parts. */
2419 enum machine_mode submode
2420 = mode_for_size (GET_MODE_UNIT_SIZE (mode
) * BITS_PER_UNIT
,
2421 class == MODE_COMPLEX_INT
? MODE_INT
: MODE_FLOAT
,
2424 if (submode
== BLKmode
)
2427 op0
= protect_from_queue (op0
, 0);
2431 op0
= force_not_mem (op0
);
2434 last
= get_last_insn ();
2437 target
= protect_from_queue (target
, 1);
2439 this_abs_optab
= ! unsignedp
&& flag_trapv
2440 && (GET_MODE_CLASS(mode
) == MODE_INT
)
2441 ? absv_optab
: abs_optab
;
2443 if (this_abs_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
2445 int icode
= (int) this_abs_optab
->handlers
[(int) mode
].insn_code
;
2446 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
2452 temp
= gen_reg_rtx (submode
);
2454 if (GET_MODE (xop0
) != VOIDmode
2455 && GET_MODE (xop0
) != mode0
)
2456 xop0
= convert_to_mode (mode0
, xop0
, unsignedp
);
2458 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
2460 if (! (*insn_data
[icode
].operand
[1].predicate
) (xop0
, mode0
))
2461 xop0
= copy_to_mode_reg (mode0
, xop0
);
2463 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, submode
))
2464 temp
= gen_reg_rtx (submode
);
2466 pat
= GEN_FCN (icode
) (temp
, xop0
);
2469 if (GET_CODE (pat
) == SEQUENCE
2470 && ! add_equal_note (pat
, temp
, this_abs_optab
->code
, xop0
,
2473 delete_insns_since (last
);
2474 return expand_unop (mode
, this_abs_optab
, op0
, NULL_RTX
,
2483 delete_insns_since (last
);
2486 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2488 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2489 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2491 if (this_abs_optab
->handlers
[(int) wider_mode
].insn_code
2492 != CODE_FOR_nothing
)
2496 xop0
= convert_modes (wider_mode
, mode
, xop0
, unsignedp
);
2497 temp
= expand_complex_abs (wider_mode
, xop0
, NULL_RTX
, unsignedp
);
2501 if (class != MODE_COMPLEX_INT
)
2504 target
= gen_reg_rtx (submode
);
2505 convert_move (target
, temp
, 0);
2509 return gen_lowpart (submode
, temp
);
2512 delete_insns_since (last
);
2516 /* Open-code the complex absolute-value operation
2517 if we can open-code sqrt. Otherwise it's not worth while. */
2518 if (sqrt_optab
->handlers
[(int) submode
].insn_code
!= CODE_FOR_nothing
2521 rtx real
, imag
, total
;
2523 real
= gen_realpart (submode
, op0
);
2524 imag
= gen_imagpart (submode
, op0
);
2526 /* Square both parts. */
2527 real
= expand_mult (submode
, real
, real
, NULL_RTX
, 0);
2528 imag
= expand_mult (submode
, imag
, imag
, NULL_RTX
, 0);
2530 /* Sum the parts. */
2531 total
= expand_binop (submode
, add_optab
, real
, imag
, NULL_RTX
,
2532 0, OPTAB_LIB_WIDEN
);
2534 /* Get sqrt in TARGET. Set TARGET to where the result is. */
2535 target
= expand_unop (submode
, sqrt_optab
, total
, target
, 0);
2537 delete_insns_since (last
);
2542 /* Now try a library call in this mode. */
2543 if (this_abs_optab
->handlers
[(int) mode
].libfunc
)
2550 /* Pass 1 for NO_QUEUE so we don't lose any increments
2551 if the libcall is cse'd or moved. */
2552 value
= emit_library_call_value (abs_optab
->handlers
[(int) mode
].libfunc
,
2553 NULL_RTX
, LCT_CONST
, submode
, 1, op0
, mode
);
2554 insns
= get_insns ();
2557 target
= gen_reg_rtx (submode
);
2558 emit_libcall_block (insns
, target
, value
,
2559 gen_rtx_fmt_e (this_abs_optab
->code
, mode
, op0
));
2564 /* It can't be done in this mode. Can we do it in a wider mode? */
2566 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
2567 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
2569 if ((this_abs_optab
->handlers
[(int) wider_mode
].insn_code
2570 != CODE_FOR_nothing
)
2571 || this_abs_optab
->handlers
[(int) wider_mode
].libfunc
)
2575 xop0
= convert_modes (wider_mode
, mode
, xop0
, unsignedp
);
2577 temp
= expand_complex_abs (wider_mode
, xop0
, NULL_RTX
, unsignedp
);
2581 if (class != MODE_COMPLEX_INT
)
2584 target
= gen_reg_rtx (submode
);
2585 convert_move (target
, temp
, 0);
2589 return gen_lowpart (submode
, temp
);
2592 delete_insns_since (last
);
2596 delete_insns_since (entry_last
);
2600 /* Generate an instruction whose insn-code is INSN_CODE,
2601 with two operands: an output TARGET and an input OP0.
2602 TARGET *must* be nonzero, and the output is always stored there.
2603 CODE is an rtx code such that (CODE OP0) is an rtx that describes
2604 the value that is stored into TARGET. */
2607 emit_unop_insn (icode
, target
, op0
, code
)
2614 enum machine_mode mode0
= insn_data
[icode
].operand
[1].mode
;
2617 temp
= target
= protect_from_queue (target
, 1);
2619 op0
= protect_from_queue (op0
, 0);
2621 /* Sign and zero extension from memory is often done specially on
2622 RISC machines, so forcing into a register here can pessimize
2624 if (flag_force_mem
&& code
!= SIGN_EXTEND
&& code
!= ZERO_EXTEND
)
2625 op0
= force_not_mem (op0
);
2627 /* Now, if insn does not accept our operands, put them into pseudos. */
2629 if (! (*insn_data
[icode
].operand
[1].predicate
) (op0
, mode0
))
2630 op0
= copy_to_mode_reg (mode0
, op0
);
2632 if (! (*insn_data
[icode
].operand
[0].predicate
) (temp
, GET_MODE (temp
))
2633 || (flag_force_mem
&& GET_CODE (temp
) == MEM
))
2634 temp
= gen_reg_rtx (GET_MODE (temp
));
2636 pat
= GEN_FCN (icode
) (temp
, op0
);
2638 if (GET_CODE (pat
) == SEQUENCE
&& code
!= UNKNOWN
)
2639 add_equal_note (pat
, temp
, code
, op0
, NULL_RTX
);
2644 emit_move_insn (target
, temp
);
2647 /* Emit code to perform a series of operations on a multi-word quantity, one
2650 Such a block is preceded by a CLOBBER of the output, consists of multiple
2651 insns, each setting one word of the output, and followed by a SET copying
2652 the output to itself.
2654 Each of the insns setting words of the output receives a REG_NO_CONFLICT
2655 note indicating that it doesn't conflict with the (also multi-word)
2656 inputs. The entire block is surrounded by REG_LIBCALL and REG_RETVAL
2659 INSNS is a block of code generated to perform the operation, not including
2660 the CLOBBER and final copy. All insns that compute intermediate values
2661 are first emitted, followed by the block as described above.
2663 TARGET, OP0, and OP1 are the output and inputs of the operations,
2664 respectively. OP1 may be zero for a unary operation.
2666 EQUIV, if non-zero, is an expression to be placed into a REG_EQUAL note
2669 If TARGET is not a register, INSNS is simply emitted with no special
2670 processing. Likewise if anything in INSNS is not an INSN or if
2671 there is a libcall block inside INSNS.
2673 The final insn emitted is returned. */
2676 emit_no_conflict_block (insns
, target
, op0
, op1
, equiv
)
2682 rtx prev
, next
, first
, last
, insn
;
2684 if (GET_CODE (target
) != REG
|| reload_in_progress
)
2685 return emit_insns (insns
);
2687 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
2688 if (GET_CODE (insn
) != INSN
2689 || find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
))
2690 return emit_insns (insns
);
2692 /* First emit all insns that do not store into words of the output and remove
2693 these from the list. */
2694 for (insn
= insns
; insn
; insn
= next
)
2699 next
= NEXT_INSN (insn
);
2701 if (GET_CODE (PATTERN (insn
)) == SET
|| GET_CODE (PATTERN (insn
)) == USE
2702 || GET_CODE (PATTERN (insn
)) == CLOBBER
)
2703 set
= PATTERN (insn
);
2704 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
2706 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
2707 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
2709 set
= XVECEXP (PATTERN (insn
), 0, i
);
2717 if (! reg_overlap_mentioned_p (target
, SET_DEST (set
)))
2719 if (PREV_INSN (insn
))
2720 NEXT_INSN (PREV_INSN (insn
)) = next
;
2725 PREV_INSN (next
) = PREV_INSN (insn
);
2731 prev
= get_last_insn ();
2733 /* Now write the CLOBBER of the output, followed by the setting of each
2734 of the words, followed by the final copy. */
2735 if (target
!= op0
&& target
!= op1
)
2736 emit_insn (gen_rtx_CLOBBER (VOIDmode
, target
));
2738 for (insn
= insns
; insn
; insn
= next
)
2740 next
= NEXT_INSN (insn
);
2743 if (op1
&& GET_CODE (op1
) == REG
)
2744 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT
, op1
,
2747 if (op0
&& GET_CODE (op0
) == REG
)
2748 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT
, op0
,
2752 if (mov_optab
->handlers
[(int) GET_MODE (target
)].insn_code
2753 != CODE_FOR_nothing
)
2755 last
= emit_move_insn (target
, target
);
2757 set_unique_reg_note (last
, REG_EQUAL
, equiv
);
2761 last
= get_last_insn ();
2763 /* Remove any existing REG_EQUAL note from "last", or else it will
2764 be mistaken for a note referring to the full contents of the
2765 alleged libcall value when found together with the REG_RETVAL
2766 note added below. An existing note can come from an insn
2767 expansion at "last". */
2768 remove_note (last
, find_reg_note (last
, REG_EQUAL
, NULL_RTX
));
2772 first
= get_insns ();
2774 first
= NEXT_INSN (prev
);
2776 /* Encapsulate the block so it gets manipulated as a unit. */
2777 REG_NOTES (first
) = gen_rtx_INSN_LIST (REG_LIBCALL
, last
,
2779 REG_NOTES (last
) = gen_rtx_INSN_LIST (REG_RETVAL
, first
, REG_NOTES (last
));
2784 /* Emit code to make a call to a constant function or a library call.
2786 INSNS is a list containing all insns emitted in the call.
2787 These insns leave the result in RESULT. Our block is to copy RESULT
2788 to TARGET, which is logically equivalent to EQUIV.
2790 We first emit any insns that set a pseudo on the assumption that these are
2791 loading constants into registers; doing so allows them to be safely cse'ed
2792 between blocks. Then we emit all the other insns in the block, followed by
2793 an insn to move RESULT to TARGET. This last insn will have a REQ_EQUAL
2794 note with an operand of EQUIV.
2796 Moving assignments to pseudos outside of the block is done to improve
2797 the generated code, but is not required to generate correct code,
2798 hence being unable to move an assignment is not grounds for not making
2799 a libcall block. There are two reasons why it is safe to leave these
2800 insns inside the block: First, we know that these pseudos cannot be
2801 used in generated RTL outside the block since they are created for
2802 temporary purposes within the block. Second, CSE will not record the
2803 values of anything set inside a libcall block, so we know they must
2804 be dead at the end of the block.
2806 Except for the first group of insns (the ones setting pseudos), the
2807 block is delimited by REG_RETVAL and REG_LIBCALL notes. */
2810 emit_libcall_block (insns
, target
, result
, equiv
)
2816 rtx final_dest
= target
;
2817 rtx prev
, next
, first
, last
, insn
;
2819 /* If this is a reg with REG_USERVAR_P set, then it could possibly turn
2820 into a MEM later. Protect the libcall block from this change. */
2821 if (! REG_P (target
) || REG_USERVAR_P (target
))
2822 target
= gen_reg_rtx (GET_MODE (target
));
2824 /* If we're using non-call exceptions, a libcall corresponding to an
2825 operation that may trap may also trap. */
2826 if (flag_non_call_exceptions
&& may_trap_p (equiv
))
2828 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
2829 if (GET_CODE (insn
) == CALL_INSN
)
2831 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
2833 if (note
!= 0 && INTVAL (XEXP (note
, 0)) <= 0)
2834 remove_note (insn
, note
);
2838 /* look for any CALL_INSNs in this sequence, and attach a REG_EH_REGION
2839 reg note to indicate that this call cannot throw or execute a nonlocal
2840 goto (unless there is already a REG_EH_REGION note, in which case
2842 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
2843 if (GET_CODE (insn
) == CALL_INSN
)
2845 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
2848 XEXP (note
, 0) = GEN_INT (-1);
2850 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_EH_REGION
, GEN_INT (-1),
2854 /* First emit all insns that set pseudos. Remove them from the list as
2855 we go. Avoid insns that set pseudos which were referenced in previous
2856 insns. These can be generated by move_by_pieces, for example,
2857 to update an address. Similarly, avoid insns that reference things
2858 set in previous insns. */
2860 for (insn
= insns
; insn
; insn
= next
)
2862 rtx set
= single_set (insn
);
2864 next
= NEXT_INSN (insn
);
2866 if (set
!= 0 && GET_CODE (SET_DEST (set
)) == REG
2867 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
2869 || ((! INSN_P(insns
)
2870 || ! reg_mentioned_p (SET_DEST (set
), PATTERN (insns
)))
2871 && ! reg_used_between_p (SET_DEST (set
), insns
, insn
)
2872 && ! modified_in_p (SET_SRC (set
), insns
)
2873 && ! modified_between_p (SET_SRC (set
), insns
, insn
))))
2875 if (PREV_INSN (insn
))
2876 NEXT_INSN (PREV_INSN (insn
)) = next
;
2881 PREV_INSN (next
) = PREV_INSN (insn
);
2887 prev
= get_last_insn ();
2889 /* Write the remaining insns followed by the final copy. */
2891 for (insn
= insns
; insn
; insn
= next
)
2893 next
= NEXT_INSN (insn
);
2898 last
= emit_move_insn (target
, result
);
2899 if (mov_optab
->handlers
[(int) GET_MODE (target
)].insn_code
2900 != CODE_FOR_nothing
)
2901 set_unique_reg_note (last
, REG_EQUAL
, copy_rtx (equiv
));
2904 /* Remove any existing REG_EQUAL note from "last", or else it will
2905 be mistaken for a note referring to the full contents of the
2906 libcall value when found together with the REG_RETVAL note added
2907 below. An existing note can come from an insn expansion at
2909 remove_note (last
, find_reg_note (last
, REG_EQUAL
, NULL_RTX
));
2912 if (final_dest
!= target
)
2913 emit_move_insn (final_dest
, target
);
2916 first
= get_insns ();
2918 first
= NEXT_INSN (prev
);
2920 /* Encapsulate the block so it gets manipulated as a unit. */
2921 REG_NOTES (first
) = gen_rtx_INSN_LIST (REG_LIBCALL
, last
,
2923 REG_NOTES (last
) = gen_rtx_INSN_LIST (REG_RETVAL
, first
, REG_NOTES (last
));
2926 /* Generate code to store zero in X. */
2932 emit_move_insn (x
, const0_rtx
);
2935 /* Generate code to store 1 in X
2936 assuming it contains zero beforehand. */
2939 emit_0_to_1_insn (x
)
2942 emit_move_insn (x
, const1_rtx
);
2945 /* Nonzero if we can perform a comparison of mode MODE straightforwardly.
2946 PURPOSE describes how this comparison will be used. CODE is the rtx
2947 comparison code we will be using.
2949 ??? Actually, CODE is slightly weaker than that. A target is still
2950 required to implement all of the normal bcc operations, but not
2951 required to implement all (or any) of the unordered bcc operations. */
2954 can_compare_p (code
, mode
, purpose
)
2956 enum machine_mode mode
;
2957 enum can_compare_purpose purpose
;
2961 if (cmp_optab
->handlers
[(int)mode
].insn_code
!= CODE_FOR_nothing
)
2963 if (purpose
== ccp_jump
)
2964 return bcc_gen_fctn
[(int)code
] != NULL
;
2965 else if (purpose
== ccp_store_flag
)
2966 return setcc_gen_code
[(int)code
] != CODE_FOR_nothing
;
2968 /* There's only one cmov entry point, and it's allowed to fail. */
2971 if (purpose
== ccp_jump
2972 && cbranch_optab
->handlers
[(int)mode
].insn_code
!= CODE_FOR_nothing
)
2974 if (purpose
== ccp_cmov
2975 && cmov_optab
->handlers
[(int)mode
].insn_code
!= CODE_FOR_nothing
)
2977 if (purpose
== ccp_store_flag
2978 && cstore_optab
->handlers
[(int)mode
].insn_code
!= CODE_FOR_nothing
)
2981 mode
= GET_MODE_WIDER_MODE (mode
);
2983 while (mode
!= VOIDmode
);
2988 /* This function is called when we are going to emit a compare instruction that
2989 compares the values found in *PX and *PY, using the rtl operator COMPARISON.
2991 *PMODE is the mode of the inputs (in case they are const_int).
2992 *PUNSIGNEDP nonzero says that the operands are unsigned;
2993 this matters if they need to be widened.
2995 If they have mode BLKmode, then SIZE specifies the size of both operands,
2996 and ALIGN specifies the known shared alignment of the operands.
2998 This function performs all the setup necessary so that the caller only has
2999 to emit a single comparison insn. This setup can involve doing a BLKmode
3000 comparison or emitting a library call to perform the comparison if no insn
3001 is available to handle it.
3002 The values which are passed in through pointers can be modified; the caller
3003 should perform the comparison on the modified values. */
3006 prepare_cmp_insn (px
, py
, pcomparison
, size
, pmode
, punsignedp
, align
,
3009 enum rtx_code
*pcomparison
;
3011 enum machine_mode
*pmode
;
3013 int align ATTRIBUTE_UNUSED
;
3014 enum can_compare_purpose purpose
;
3016 enum machine_mode mode
= *pmode
;
3017 rtx x
= *px
, y
= *py
;
3018 int unsignedp
= *punsignedp
;
3019 enum mode_class
class;
3020 rtx opalign ATTRIBUTE_UNUSED
= GEN_INT (align
/ BITS_PER_UNIT
);;
3022 class = GET_MODE_CLASS (mode
);
3024 /* They could both be VOIDmode if both args are immediate constants,
3025 but we should fold that at an earlier stage.
3026 With no special code here, this will call abort,
3027 reminding the programmer to implement such folding. */
3029 if (mode
!= BLKmode
&& flag_force_mem
)
3031 x
= force_not_mem (x
);
3032 y
= force_not_mem (y
);
3035 /* If we are inside an appropriately-short loop and one operand is an
3036 expensive constant, force it into a register. */
3037 if (CONSTANT_P (x
) && preserve_subexpressions_p ()
3038 && rtx_cost (x
, COMPARE
) > COSTS_N_INSNS (1))
3039 x
= force_reg (mode
, x
);
3041 if (CONSTANT_P (y
) && preserve_subexpressions_p ()
3042 && rtx_cost (y
, COMPARE
) > COSTS_N_INSNS (1))
3043 y
= force_reg (mode
, y
);
3046 /* Abort if we have a non-canonical comparison. The RTL documentation
3047 states that canonical comparisons are required only for targets which
3049 if (CONSTANT_P (x
) && ! CONSTANT_P (y
))
3053 /* Don't let both operands fail to indicate the mode. */
3054 if (GET_MODE (x
) == VOIDmode
&& GET_MODE (y
) == VOIDmode
)
3055 x
= force_reg (mode
, x
);
3057 /* Handle all BLKmode compares. */
3059 if (mode
== BLKmode
)
3062 enum machine_mode result_mode
;
3065 x
= protect_from_queue (x
, 0);
3066 y
= protect_from_queue (y
, 0);
3070 #ifdef HAVE_cmpstrqi
3072 && GET_CODE (size
) == CONST_INT
3073 && INTVAL (size
) < (1 << GET_MODE_BITSIZE (QImode
)))
3075 result_mode
= insn_data
[(int) CODE_FOR_cmpstrqi
].operand
[0].mode
;
3076 result
= gen_reg_rtx (result_mode
);
3077 emit_insn (gen_cmpstrqi (result
, x
, y
, size
, opalign
));
3081 #ifdef HAVE_cmpstrhi
3083 && GET_CODE (size
) == CONST_INT
3084 && INTVAL (size
) < (1 << GET_MODE_BITSIZE (HImode
)))
3086 result_mode
= insn_data
[(int) CODE_FOR_cmpstrhi
].operand
[0].mode
;
3087 result
= gen_reg_rtx (result_mode
);
3088 emit_insn (gen_cmpstrhi (result
, x
, y
, size
, opalign
));
3092 #ifdef HAVE_cmpstrsi
3095 result_mode
= insn_data
[(int) CODE_FOR_cmpstrsi
].operand
[0].mode
;
3096 result
= gen_reg_rtx (result_mode
);
3097 size
= protect_from_queue (size
, 0);
3098 emit_insn (gen_cmpstrsi (result
, x
, y
,
3099 convert_to_mode (SImode
, size
, 1),
3105 #ifdef TARGET_MEM_FUNCTIONS
3106 emit_library_call (memcmp_libfunc
, LCT_PURE_MAKE_BLOCK
,
3107 TYPE_MODE (integer_type_node
), 3,
3108 XEXP (x
, 0), Pmode
, XEXP (y
, 0), Pmode
,
3109 convert_to_mode (TYPE_MODE (sizetype
), size
,
3110 TREE_UNSIGNED (sizetype
)),
3111 TYPE_MODE (sizetype
));
3113 emit_library_call (bcmp_libfunc
, LCT_PURE_MAKE_BLOCK
,
3114 TYPE_MODE (integer_type_node
), 3,
3115 XEXP (x
, 0), Pmode
, XEXP (y
, 0), Pmode
,
3116 convert_to_mode (TYPE_MODE (integer_type_node
),
3118 TREE_UNSIGNED (integer_type_node
)),
3119 TYPE_MODE (integer_type_node
));
3122 /* Immediately move the result of the libcall into a pseudo
3123 register so reload doesn't clobber the value if it needs
3124 the return register for a spill reg. */
3125 result
= gen_reg_rtx (TYPE_MODE (integer_type_node
));
3126 result_mode
= TYPE_MODE (integer_type_node
);
3127 emit_move_insn (result
,
3128 hard_libcall_value (result_mode
));
3132 *pmode
= result_mode
;
3138 if (can_compare_p (*pcomparison
, mode
, purpose
))
3141 /* Handle a lib call just for the mode we are using. */
3143 if (cmp_optab
->handlers
[(int) mode
].libfunc
&& class != MODE_FLOAT
)
3145 rtx libfunc
= cmp_optab
->handlers
[(int) mode
].libfunc
;
3148 /* If we want unsigned, and this mode has a distinct unsigned
3149 comparison routine, use that. */
3150 if (unsignedp
&& ucmp_optab
->handlers
[(int) mode
].libfunc
)
3151 libfunc
= ucmp_optab
->handlers
[(int) mode
].libfunc
;
3153 emit_library_call (libfunc
, 1,
3154 word_mode
, 2, x
, mode
, y
, mode
);
3156 /* Immediately move the result of the libcall into a pseudo
3157 register so reload doesn't clobber the value if it needs
3158 the return register for a spill reg. */
3159 result
= gen_reg_rtx (word_mode
);
3160 emit_move_insn (result
, hard_libcall_value (word_mode
));
3162 /* Integer comparison returns a result that must be compared against 1,
3163 so that even if we do an unsigned compare afterward,
3164 there is still a value that can represent the result "less than". */
3171 if (class == MODE_FLOAT
)
3172 prepare_float_lib_cmp (px
, py
, pcomparison
, pmode
, punsignedp
);
3178 /* Before emitting an insn with code ICODE, make sure that X, which is going
3179 to be used for operand OPNUM of the insn, is converted from mode MODE to
3180 WIDER_MODE (UNSIGNEDP determines whether it is a unsigned conversion), and
3181 that it is accepted by the operand predicate. Return the new value. */
3184 prepare_operand (icode
, x
, opnum
, mode
, wider_mode
, unsignedp
)
3188 enum machine_mode mode
, wider_mode
;
3191 x
= protect_from_queue (x
, 0);
3193 if (mode
!= wider_mode
)
3194 x
= convert_modes (wider_mode
, mode
, x
, unsignedp
);
3196 if (! (*insn_data
[icode
].operand
[opnum
].predicate
)
3197 (x
, insn_data
[icode
].operand
[opnum
].mode
))
3198 x
= copy_to_mode_reg (insn_data
[icode
].operand
[opnum
].mode
, x
);
3202 /* Subroutine of emit_cmp_and_jump_insns; this function is called when we know
3203 we can do the comparison.
3204 The arguments are the same as for emit_cmp_and_jump_insns; but LABEL may
3205 be NULL_RTX which indicates that only a comparison is to be generated. */
3208 emit_cmp_and_jump_insn_1 (x
, y
, mode
, comparison
, unsignedp
, label
)
3210 enum machine_mode mode
;
3211 enum rtx_code comparison
;
3215 rtx test
= gen_rtx_fmt_ee (comparison
, mode
, x
, y
);
3216 enum mode_class
class = GET_MODE_CLASS (mode
);
3217 enum machine_mode wider_mode
= mode
;
3219 /* Try combined insns first. */
3222 enum insn_code icode
;
3223 PUT_MODE (test
, wider_mode
);
3227 icode
= cbranch_optab
->handlers
[(int)wider_mode
].insn_code
;
3229 if (icode
!= CODE_FOR_nothing
3230 && (*insn_data
[icode
].operand
[0].predicate
) (test
, wider_mode
))
3232 x
= prepare_operand (icode
, x
, 1, mode
, wider_mode
, unsignedp
);
3233 y
= prepare_operand (icode
, y
, 2, mode
, wider_mode
, unsignedp
);
3234 emit_jump_insn (GEN_FCN (icode
) (test
, x
, y
, label
));
3239 /* Handle some compares against zero. */
3240 icode
= (int) tst_optab
->handlers
[(int) wider_mode
].insn_code
;
3241 if (y
== CONST0_RTX (mode
) && icode
!= CODE_FOR_nothing
)
3243 x
= prepare_operand (icode
, x
, 0, mode
, wider_mode
, unsignedp
);
3244 emit_insn (GEN_FCN (icode
) (x
));
3246 emit_jump_insn ((*bcc_gen_fctn
[(int) comparison
]) (label
));
3250 /* Handle compares for which there is a directly suitable insn. */
3252 icode
= (int) cmp_optab
->handlers
[(int) wider_mode
].insn_code
;
3253 if (icode
!= CODE_FOR_nothing
)
3255 x
= prepare_operand (icode
, x
, 0, mode
, wider_mode
, unsignedp
);
3256 y
= prepare_operand (icode
, y
, 1, mode
, wider_mode
, unsignedp
);
3257 emit_insn (GEN_FCN (icode
) (x
, y
));
3259 emit_jump_insn ((*bcc_gen_fctn
[(int) comparison
]) (label
));
3263 if (class != MODE_INT
&& class != MODE_FLOAT
3264 && class != MODE_COMPLEX_FLOAT
)
3267 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
);
3268 } while (wider_mode
!= VOIDmode
);
3273 /* Generate code to compare X with Y so that the condition codes are
3274 set and to jump to LABEL if the condition is true. If X is a
3275 constant and Y is not a constant, then the comparison is swapped to
3276 ensure that the comparison RTL has the canonical form.
3278 UNSIGNEDP nonzero says that X and Y are unsigned; this matters if they
3279 need to be widened by emit_cmp_insn. UNSIGNEDP is also used to select
3280 the proper branch condition code.
3282 If X and Y have mode BLKmode, then SIZE specifies the size of both X and Y,
3283 and ALIGN specifies the known shared alignment of X and Y.
3285 MODE is the mode of the inputs (in case they are const_int).
3287 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). It will
3288 be passed unchanged to emit_cmp_insn, then potentially converted into an
3289 unsigned variant based on UNSIGNEDP to select a proper jump instruction. */
3292 emit_cmp_and_jump_insns (x
, y
, comparison
, size
, mode
, unsignedp
, align
, label
)
3294 enum rtx_code comparison
;
3296 enum machine_mode mode
;
3301 rtx op0
= x
, op1
= y
;
3303 /* Swap operands and condition to ensure canonical RTL. */
3304 if (swap_commutative_operands_p (x
, y
))
3306 /* If we're not emitting a branch, this means some caller
3312 comparison
= swap_condition (comparison
);
3316 /* If OP0 is still a constant, then both X and Y must be constants. Force
3317 X into a register to avoid aborting in emit_cmp_insn due to non-canonical
3319 if (CONSTANT_P (op0
))
3320 op0
= force_reg (mode
, op0
);
3325 comparison
= unsigned_condition (comparison
);
3326 prepare_cmp_insn (&op0
, &op1
, &comparison
, size
, &mode
, &unsignedp
, align
,
3328 emit_cmp_and_jump_insn_1 (op0
, op1
, mode
, comparison
, unsignedp
, label
);
3331 /* Like emit_cmp_and_jump_insns, but generate only the comparison. */
3334 emit_cmp_insn (x
, y
, comparison
, size
, mode
, unsignedp
, align
)
3336 enum rtx_code comparison
;
3338 enum machine_mode mode
;
3342 emit_cmp_and_jump_insns (x
, y
, comparison
, size
, mode
, unsignedp
, align
, 0);
3345 /* Emit a library call comparison between floating point X and Y.
3346 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). */
3349 prepare_float_lib_cmp (px
, py
, pcomparison
, pmode
, punsignedp
)
3351 enum rtx_code
*pcomparison
;
3352 enum machine_mode
*pmode
;
3355 enum rtx_code comparison
= *pcomparison
;
3356 rtx x
= *px
= protect_from_queue (*px
, 0);
3357 rtx y
= *py
= protect_from_queue (*py
, 0);
3358 enum machine_mode mode
= GET_MODE (x
);
3366 libfunc
= eqhf2_libfunc
;
3370 libfunc
= nehf2_libfunc
;
3374 libfunc
= gthf2_libfunc
;
3378 libfunc
= gehf2_libfunc
;
3382 libfunc
= lthf2_libfunc
;
3386 libfunc
= lehf2_libfunc
;
3390 libfunc
= unordhf2_libfunc
;
3396 else if (mode
== SFmode
)
3400 libfunc
= eqsf2_libfunc
;
3404 libfunc
= nesf2_libfunc
;
3408 libfunc
= gtsf2_libfunc
;
3412 libfunc
= gesf2_libfunc
;
3416 libfunc
= ltsf2_libfunc
;
3420 libfunc
= lesf2_libfunc
;
3424 libfunc
= unordsf2_libfunc
;
3430 else if (mode
== DFmode
)
3434 libfunc
= eqdf2_libfunc
;
3438 libfunc
= nedf2_libfunc
;
3442 libfunc
= gtdf2_libfunc
;
3446 libfunc
= gedf2_libfunc
;
3450 libfunc
= ltdf2_libfunc
;
3454 libfunc
= ledf2_libfunc
;
3458 libfunc
= unorddf2_libfunc
;
3464 else if (mode
== XFmode
)
3468 libfunc
= eqxf2_libfunc
;
3472 libfunc
= nexf2_libfunc
;
3476 libfunc
= gtxf2_libfunc
;
3480 libfunc
= gexf2_libfunc
;
3484 libfunc
= ltxf2_libfunc
;
3488 libfunc
= lexf2_libfunc
;
3492 libfunc
= unordxf2_libfunc
;
3498 else if (mode
== TFmode
)
3502 libfunc
= eqtf2_libfunc
;
3506 libfunc
= netf2_libfunc
;
3510 libfunc
= gttf2_libfunc
;
3514 libfunc
= getf2_libfunc
;
3518 libfunc
= lttf2_libfunc
;
3522 libfunc
= letf2_libfunc
;
3526 libfunc
= unordtf2_libfunc
;
3534 enum machine_mode wider_mode
;
3536 for (wider_mode
= GET_MODE_WIDER_MODE (mode
); wider_mode
!= VOIDmode
;
3537 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
3539 if ((cmp_optab
->handlers
[(int) wider_mode
].insn_code
3540 != CODE_FOR_nothing
)
3541 || (cmp_optab
->handlers
[(int) wider_mode
].libfunc
!= 0))
3543 x
= protect_from_queue (x
, 0);
3544 y
= protect_from_queue (y
, 0);
3545 *px
= convert_to_mode (wider_mode
, x
, 0);
3546 *py
= convert_to_mode (wider_mode
, y
, 0);
3547 prepare_float_lib_cmp (px
, py
, pcomparison
, pmode
, punsignedp
);
3557 emit_library_call (libfunc
, LCT_CONST_MAKE_BLOCK
, word_mode
, 2, x
, mode
, y
,
3560 /* Immediately move the result of the libcall into a pseudo
3561 register so reload doesn't clobber the value if it needs
3562 the return register for a spill reg. */
3563 result
= gen_reg_rtx (word_mode
);
3564 emit_move_insn (result
, hard_libcall_value (word_mode
));
3568 if (comparison
== UNORDERED
)
3570 #ifdef FLOAT_LIB_COMPARE_RETURNS_BOOL
3571 else if (FLOAT_LIB_COMPARE_RETURNS_BOOL (mode
, comparison
))
3577 /* Generate code to indirectly jump to a location given in the rtx LOC. */
3580 emit_indirect_jump (loc
)
3583 if (! ((*insn_data
[(int)CODE_FOR_indirect_jump
].operand
[0].predicate
)
3585 loc
= copy_to_mode_reg (Pmode
, loc
);
3587 emit_jump_insn (gen_indirect_jump (loc
));
3591 #ifdef HAVE_conditional_move
3593 /* Emit a conditional move instruction if the machine supports one for that
3594 condition and machine mode.
3596 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
3597 the mode to use should they be constants. If it is VOIDmode, they cannot
3600 OP2 should be stored in TARGET if the comparison is true, otherwise OP3
3601 should be stored there. MODE is the mode to use should they be constants.
3602 If it is VOIDmode, they cannot both be constants.
3604 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
3605 is not supported. */
3608 emit_conditional_move (target
, code
, op0
, op1
, cmode
, op2
, op3
, mode
,
3613 enum machine_mode cmode
;
3615 enum machine_mode mode
;
3618 rtx tem
, subtarget
, comparison
, insn
;
3619 enum insn_code icode
;
3620 enum rtx_code reversed
;
3622 /* If one operand is constant, make it the second one. Only do this
3623 if the other operand is not constant as well. */
3625 if (swap_commutative_operands_p (op0
, op1
))
3630 code
= swap_condition (code
);
3633 /* get_condition will prefer to generate LT and GT even if the old
3634 comparison was against zero, so undo that canonicalization here since
3635 comparisons against zero are cheaper. */
3636 if (code
== LT
&& GET_CODE (op1
) == CONST_INT
&& INTVAL (op1
) == 1)
3637 code
= LE
, op1
= const0_rtx
;
3638 else if (code
== GT
&& GET_CODE (op1
) == CONST_INT
&& INTVAL (op1
) == -1)
3639 code
= GE
, op1
= const0_rtx
;
3641 if (cmode
== VOIDmode
)
3642 cmode
= GET_MODE (op0
);
3644 if (swap_commutative_operands_p (op2
, op3
)
3645 && ((reversed
= reversed_comparison_code_parts (code
, op0
, op1
, NULL
))
3654 if (mode
== VOIDmode
)
3655 mode
= GET_MODE (op2
);
3657 icode
= movcc_gen_code
[mode
];
3659 if (icode
== CODE_FOR_nothing
)
3664 op2
= force_not_mem (op2
);
3665 op3
= force_not_mem (op3
);
3669 target
= protect_from_queue (target
, 1);
3671 target
= gen_reg_rtx (mode
);
3677 op2
= protect_from_queue (op2
, 0);
3678 op3
= protect_from_queue (op3
, 0);
3680 /* If the insn doesn't accept these operands, put them in pseudos. */
3682 if (! (*insn_data
[icode
].operand
[0].predicate
)
3683 (subtarget
, insn_data
[icode
].operand
[0].mode
))
3684 subtarget
= gen_reg_rtx (insn_data
[icode
].operand
[0].mode
);
3686 if (! (*insn_data
[icode
].operand
[2].predicate
)
3687 (op2
, insn_data
[icode
].operand
[2].mode
))
3688 op2
= copy_to_mode_reg (insn_data
[icode
].operand
[2].mode
, op2
);
3690 if (! (*insn_data
[icode
].operand
[3].predicate
)
3691 (op3
, insn_data
[icode
].operand
[3].mode
))
3692 op3
= copy_to_mode_reg (insn_data
[icode
].operand
[3].mode
, op3
);
3694 /* Everything should now be in the suitable form, so emit the compare insn
3695 and then the conditional move. */
3698 = compare_from_rtx (op0
, op1
, code
, unsignedp
, cmode
, NULL_RTX
, 0);
3700 /* ??? Watch for const0_rtx (nop) and const_true_rtx (unconditional)? */
3701 /* We can get const0_rtx or const_true_rtx in some circumstances. Just
3702 return NULL and let the caller figure out how best to deal with this
3704 if (GET_CODE (comparison
) != code
)
3707 insn
= GEN_FCN (icode
) (subtarget
, comparison
, op2
, op3
);
3709 /* If that failed, then give up. */
3715 if (subtarget
!= target
)
3716 convert_move (target
, subtarget
, 0);
3721 /* Return non-zero if a conditional move of mode MODE is supported.
3723 This function is for combine so it can tell whether an insn that looks
3724 like a conditional move is actually supported by the hardware. If we
3725 guess wrong we lose a bit on optimization, but that's it. */
3726 /* ??? sparc64 supports conditionally moving integers values based on fp
3727 comparisons, and vice versa. How do we handle them? */
3730 can_conditionally_move_p (mode
)
3731 enum machine_mode mode
;
3733 if (movcc_gen_code
[mode
] != CODE_FOR_nothing
)
3739 #endif /* HAVE_conditional_move */
3741 /* These three functions generate an insn body and return it
3742 rather than emitting the insn.
3744 They do not protect from queued increments,
3745 because they may be used 1) in protect_from_queue itself
3746 and 2) in other passes where there is no queue. */
3748 /* Generate and return an insn body to add Y to X. */
3751 gen_add2_insn (x
, y
)
3754 int icode
= (int) add_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
3756 if (! ((*insn_data
[icode
].operand
[0].predicate
)
3757 (x
, insn_data
[icode
].operand
[0].mode
))
3758 || ! ((*insn_data
[icode
].operand
[1].predicate
)
3759 (x
, insn_data
[icode
].operand
[1].mode
))
3760 || ! ((*insn_data
[icode
].operand
[2].predicate
)
3761 (y
, insn_data
[icode
].operand
[2].mode
)))
3764 return (GEN_FCN (icode
) (x
, x
, y
));
3768 have_add2_insn (x
, y
)
3773 if (GET_MODE (x
) == VOIDmode
)
3776 icode
= (int) add_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
3778 if (icode
== CODE_FOR_nothing
)
3781 if (! ((*insn_data
[icode
].operand
[0].predicate
)
3782 (x
, insn_data
[icode
].operand
[0].mode
))
3783 || ! ((*insn_data
[icode
].operand
[1].predicate
)
3784 (x
, insn_data
[icode
].operand
[1].mode
))
3785 || ! ((*insn_data
[icode
].operand
[2].predicate
)
3786 (y
, insn_data
[icode
].operand
[2].mode
)))
3792 /* Generate and return an insn body to subtract Y from X. */
3795 gen_sub2_insn (x
, y
)
3798 int icode
= (int) sub_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
3800 if (! ((*insn_data
[icode
].operand
[0].predicate
)
3801 (x
, insn_data
[icode
].operand
[0].mode
))
3802 || ! ((*insn_data
[icode
].operand
[1].predicate
)
3803 (x
, insn_data
[icode
].operand
[1].mode
))
3804 || ! ((*insn_data
[icode
].operand
[2].predicate
)
3805 (y
, insn_data
[icode
].operand
[2].mode
)))
3808 return (GEN_FCN (icode
) (x
, x
, y
));
3812 have_sub2_insn (x
, y
)
3817 if (GET_MODE (x
) == VOIDmode
)
3820 icode
= (int) sub_optab
->handlers
[(int) GET_MODE (x
)].insn_code
;
3822 if (icode
== CODE_FOR_nothing
)
3825 if (! ((*insn_data
[icode
].operand
[0].predicate
)
3826 (x
, insn_data
[icode
].operand
[0].mode
))
3827 || ! ((*insn_data
[icode
].operand
[1].predicate
)
3828 (x
, insn_data
[icode
].operand
[1].mode
))
3829 || ! ((*insn_data
[icode
].operand
[2].predicate
)
3830 (y
, insn_data
[icode
].operand
[2].mode
)))
3836 /* Generate the body of an instruction to copy Y into X.
3837 It may be a SEQUENCE, if one insn isn't enough. */
3840 gen_move_insn (x
, y
)
3843 register enum machine_mode mode
= GET_MODE (x
);
3844 enum insn_code insn_code
;
3847 if (mode
== VOIDmode
)
3848 mode
= GET_MODE (y
);
3850 insn_code
= mov_optab
->handlers
[(int) mode
].insn_code
;
3852 /* Handle MODE_CC modes: If we don't have a special move insn for this mode,
3853 find a mode to do it in. If we have a movcc, use it. Otherwise,
3854 find the MODE_INT mode of the same width. */
3856 if (GET_MODE_CLASS (mode
) == MODE_CC
&& insn_code
== CODE_FOR_nothing
)
3858 enum machine_mode tmode
= VOIDmode
;
3862 && mov_optab
->handlers
[(int) CCmode
].insn_code
!= CODE_FOR_nothing
)
3865 for (tmode
= QImode
; tmode
!= VOIDmode
;
3866 tmode
= GET_MODE_WIDER_MODE (tmode
))
3867 if (GET_MODE_SIZE (tmode
) == GET_MODE_SIZE (mode
))
3870 if (tmode
== VOIDmode
)
3873 /* Get X and Y in TMODE. We can't use gen_lowpart here because it
3874 may call change_address which is not appropriate if we were
3875 called when a reload was in progress. We don't have to worry
3876 about changing the address since the size in bytes is supposed to
3877 be the same. Copy the MEM to change the mode and move any
3878 substitutions from the old MEM to the new one. */
3880 if (reload_in_progress
)
3882 x
= gen_lowpart_common (tmode
, x1
);
3883 if (x
== 0 && GET_CODE (x1
) == MEM
)
3885 x
= adjust_address_nv (x1
, tmode
, 0);
3886 copy_replacements (x1
, x
);
3889 y
= gen_lowpart_common (tmode
, y1
);
3890 if (y
== 0 && GET_CODE (y1
) == MEM
)
3892 y
= adjust_address_nv (y1
, tmode
, 0);
3893 copy_replacements (y1
, y
);
3898 x
= gen_lowpart (tmode
, x
);
3899 y
= gen_lowpart (tmode
, y
);
3902 insn_code
= mov_optab
->handlers
[(int) tmode
].insn_code
;
3903 return (GEN_FCN (insn_code
) (x
, y
));
3907 emit_move_insn_1 (x
, y
);
3908 seq
= gen_sequence ();
3913 /* Return the insn code used to extend FROM_MODE to TO_MODE.
3914 UNSIGNEDP specifies zero-extension instead of sign-extension. If
3915 no such operation exists, CODE_FOR_nothing will be returned. */
3918 can_extend_p (to_mode
, from_mode
, unsignedp
)
3919 enum machine_mode to_mode
, from_mode
;
3922 #ifdef HAVE_ptr_extend
3924 return CODE_FOR_ptr_extend
;
3927 return extendtab
[(int) to_mode
][(int) from_mode
][unsignedp
!= 0];
3930 /* Generate the body of an insn to extend Y (with mode MFROM)
3931 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
3934 gen_extend_insn (x
, y
, mto
, mfrom
, unsignedp
)
3936 enum machine_mode mto
, mfrom
;
3939 return (GEN_FCN (extendtab
[(int) mto
][(int) mfrom
][unsignedp
!= 0]) (x
, y
));
3942 /* can_fix_p and can_float_p say whether the target machine
3943 can directly convert a given fixed point type to
3944 a given floating point type, or vice versa.
3945 The returned value is the CODE_FOR_... value to use,
3946 or CODE_FOR_nothing if these modes cannot be directly converted.
3948 *TRUNCP_PTR is set to 1 if it is necessary to output
3949 an explicit FTRUNC insn before the fix insn; otherwise 0. */
3951 static enum insn_code
3952 can_fix_p (fixmode
, fltmode
, unsignedp
, truncp_ptr
)
3953 enum machine_mode fltmode
, fixmode
;
3958 if (fixtrunctab
[(int) fltmode
][(int) fixmode
][unsignedp
!= 0]
3959 != CODE_FOR_nothing
)
3960 return fixtrunctab
[(int) fltmode
][(int) fixmode
][unsignedp
!= 0];
3962 if (ftrunc_optab
->handlers
[(int) fltmode
].insn_code
!= CODE_FOR_nothing
)
3965 return fixtab
[(int) fltmode
][(int) fixmode
][unsignedp
!= 0];
3967 return CODE_FOR_nothing
;
3970 static enum insn_code
3971 can_float_p (fltmode
, fixmode
, unsignedp
)
3972 enum machine_mode fixmode
, fltmode
;
3975 return floattab
[(int) fltmode
][(int) fixmode
][unsignedp
!= 0];
3978 /* Generate code to convert FROM to floating point
3979 and store in TO. FROM must be fixed point and not VOIDmode.
3980 UNSIGNEDP nonzero means regard FROM as unsigned.
3981 Normally this is done by correcting the final value
3982 if it is negative. */
3985 expand_float (to
, from
, unsignedp
)
3989 enum insn_code icode
;
3990 register rtx target
= to
;
3991 enum machine_mode fmode
, imode
;
3993 /* Crash now, because we won't be able to decide which mode to use. */
3994 if (GET_MODE (from
) == VOIDmode
)
3997 /* Look for an insn to do the conversion. Do it in the specified
3998 modes if possible; otherwise convert either input, output or both to
3999 wider mode. If the integer mode is wider than the mode of FROM,
4000 we can do the conversion signed even if the input is unsigned. */
4002 for (imode
= GET_MODE (from
); imode
!= VOIDmode
;
4003 imode
= GET_MODE_WIDER_MODE (imode
))
4004 for (fmode
= GET_MODE (to
); fmode
!= VOIDmode
;
4005 fmode
= GET_MODE_WIDER_MODE (fmode
))
4007 int doing_unsigned
= unsignedp
;
4009 if (fmode
!= GET_MODE (to
)
4010 && significand_size (fmode
) < GET_MODE_BITSIZE (GET_MODE (from
)))
4013 icode
= can_float_p (fmode
, imode
, unsignedp
);
4014 if (icode
== CODE_FOR_nothing
&& imode
!= GET_MODE (from
) && unsignedp
)
4015 icode
= can_float_p (fmode
, imode
, 0), doing_unsigned
= 0;
4017 if (icode
!= CODE_FOR_nothing
)
4019 to
= protect_from_queue (to
, 1);
4020 from
= protect_from_queue (from
, 0);
4022 if (imode
!= GET_MODE (from
))
4023 from
= convert_to_mode (imode
, from
, unsignedp
);
4025 if (fmode
!= GET_MODE (to
))
4026 target
= gen_reg_rtx (fmode
);
4028 emit_unop_insn (icode
, target
, from
,
4029 doing_unsigned
? UNSIGNED_FLOAT
: FLOAT
);
4032 convert_move (to
, target
, 0);
4037 #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
4039 /* Unsigned integer, and no way to convert directly.
4040 Convert as signed, then conditionally adjust the result. */
4043 rtx label
= gen_label_rtx ();
4045 REAL_VALUE_TYPE offset
;
4049 to
= protect_from_queue (to
, 1);
4050 from
= protect_from_queue (from
, 0);
4053 from
= force_not_mem (from
);
4055 /* Look for a usable floating mode FMODE wider than the source and at
4056 least as wide as the target. Using FMODE will avoid rounding woes
4057 with unsigned values greater than the signed maximum value. */
4059 for (fmode
= GET_MODE (to
); fmode
!= VOIDmode
;
4060 fmode
= GET_MODE_WIDER_MODE (fmode
))
4061 if (GET_MODE_BITSIZE (GET_MODE (from
)) < GET_MODE_BITSIZE (fmode
)
4062 && can_float_p (fmode
, GET_MODE (from
), 0) != CODE_FOR_nothing
)
4065 if (fmode
== VOIDmode
)
4067 /* There is no such mode. Pretend the target is wide enough. */
4068 fmode
= GET_MODE (to
);
4070 /* Avoid double-rounding when TO is narrower than FROM. */
4071 if ((significand_size (fmode
) + 1)
4072 < GET_MODE_BITSIZE (GET_MODE (from
)))
4075 rtx neglabel
= gen_label_rtx ();
4077 /* Don't use TARGET if it isn't a register, is a hard register,
4078 or is the wrong mode. */
4079 if (GET_CODE (target
) != REG
4080 || REGNO (target
) < FIRST_PSEUDO_REGISTER
4081 || GET_MODE (target
) != fmode
)
4082 target
= gen_reg_rtx (fmode
);
4084 imode
= GET_MODE (from
);
4085 do_pending_stack_adjust ();
4087 /* Test whether the sign bit is set. */
4088 emit_cmp_and_jump_insns (from
, const0_rtx
, LT
, NULL_RTX
, imode
,
4091 /* The sign bit is not set. Convert as signed. */
4092 expand_float (target
, from
, 0);
4093 emit_jump_insn (gen_jump (label
));
4096 /* The sign bit is set.
4097 Convert to a usable (positive signed) value by shifting right
4098 one bit, while remembering if a nonzero bit was shifted
4099 out; i.e., compute (from & 1) | (from >> 1). */
4101 emit_label (neglabel
);
4102 temp
= expand_binop (imode
, and_optab
, from
, const1_rtx
,
4103 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
4104 temp1
= expand_shift (RSHIFT_EXPR
, imode
, from
, integer_one_node
,
4106 temp
= expand_binop (imode
, ior_optab
, temp
, temp1
, temp
, 1,
4108 expand_float (target
, temp
, 0);
4110 /* Multiply by 2 to undo the shift above. */
4111 temp
= expand_binop (fmode
, add_optab
, target
, target
,
4112 target
, 0, OPTAB_LIB_WIDEN
);
4114 emit_move_insn (target
, temp
);
4116 do_pending_stack_adjust ();
4122 /* If we are about to do some arithmetic to correct for an
4123 unsigned operand, do it in a pseudo-register. */
4125 if (GET_MODE (to
) != fmode
4126 || GET_CODE (to
) != REG
|| REGNO (to
) < FIRST_PSEUDO_REGISTER
)
4127 target
= gen_reg_rtx (fmode
);
4129 /* Convert as signed integer to floating. */
4130 expand_float (target
, from
, 0);
4132 /* If FROM is negative (and therefore TO is negative),
4133 correct its value by 2**bitwidth. */
4135 do_pending_stack_adjust ();
4136 emit_cmp_and_jump_insns (from
, const0_rtx
, GE
, NULL_RTX
, GET_MODE (from
),
4139 /* On SCO 3.2.1, ldexp rejects values outside [0.5, 1).
4140 Rather than setting up a dconst_dot_5, let's hope SCO
4142 offset
= REAL_VALUE_LDEXP (dconst1
, GET_MODE_BITSIZE (GET_MODE (from
)));
4143 temp
= expand_binop (fmode
, add_optab
, target
,
4144 CONST_DOUBLE_FROM_REAL_VALUE (offset
, fmode
),
4145 target
, 0, OPTAB_LIB_WIDEN
);
4147 emit_move_insn (target
, temp
);
4149 do_pending_stack_adjust ();
4155 /* No hardware instruction available; call a library routine to convert from
4156 SImode, DImode, or TImode into SFmode, DFmode, XFmode, or TFmode. */
4162 to
= protect_from_queue (to
, 1);
4163 from
= protect_from_queue (from
, 0);
4165 if (GET_MODE_SIZE (GET_MODE (from
)) < GET_MODE_SIZE (SImode
))
4166 from
= convert_to_mode (SImode
, from
, unsignedp
);
4169 from
= force_not_mem (from
);
4171 if (GET_MODE (to
) == SFmode
)
4173 if (GET_MODE (from
) == SImode
)
4174 libfcn
= floatsisf_libfunc
;
4175 else if (GET_MODE (from
) == DImode
)
4176 libfcn
= floatdisf_libfunc
;
4177 else if (GET_MODE (from
) == TImode
)
4178 libfcn
= floattisf_libfunc
;
4182 else if (GET_MODE (to
) == DFmode
)
4184 if (GET_MODE (from
) == SImode
)
4185 libfcn
= floatsidf_libfunc
;
4186 else if (GET_MODE (from
) == DImode
)
4187 libfcn
= floatdidf_libfunc
;
4188 else if (GET_MODE (from
) == TImode
)
4189 libfcn
= floattidf_libfunc
;
4193 else if (GET_MODE (to
) == XFmode
)
4195 if (GET_MODE (from
) == SImode
)
4196 libfcn
= floatsixf_libfunc
;
4197 else if (GET_MODE (from
) == DImode
)
4198 libfcn
= floatdixf_libfunc
;
4199 else if (GET_MODE (from
) == TImode
)
4200 libfcn
= floattixf_libfunc
;
4204 else if (GET_MODE (to
) == TFmode
)
4206 if (GET_MODE (from
) == SImode
)
4207 libfcn
= floatsitf_libfunc
;
4208 else if (GET_MODE (from
) == DImode
)
4209 libfcn
= floatditf_libfunc
;
4210 else if (GET_MODE (from
) == TImode
)
4211 libfcn
= floattitf_libfunc
;
4220 value
= emit_library_call_value (libfcn
, NULL_RTX
, LCT_CONST
,
4221 GET_MODE (to
), 1, from
,
4223 insns
= get_insns ();
4226 emit_libcall_block (insns
, target
, value
,
4227 gen_rtx_FLOAT (GET_MODE (to
), from
));
4232 /* Copy result to requested destination
4233 if we have been computing in a temp location. */
4237 if (GET_MODE (target
) == GET_MODE (to
))
4238 emit_move_insn (to
, target
);
4240 convert_move (to
, target
, 0);
4244 /* expand_fix: generate code to convert FROM to fixed point
4245 and store in TO. FROM must be floating point. */
4251 rtx temp
= gen_reg_rtx (GET_MODE (x
));
4252 return expand_unop (GET_MODE (x
), ftrunc_optab
, x
, temp
, 0);
4256 expand_fix (to
, from
, unsignedp
)
4257 register rtx to
, from
;
4260 enum insn_code icode
;
4261 register rtx target
= to
;
4262 enum machine_mode fmode
, imode
;
4266 /* We first try to find a pair of modes, one real and one integer, at
4267 least as wide as FROM and TO, respectively, in which we can open-code
4268 this conversion. If the integer mode is wider than the mode of TO,
4269 we can do the conversion either signed or unsigned. */
4271 for (imode
= GET_MODE (to
); imode
!= VOIDmode
;
4272 imode
= GET_MODE_WIDER_MODE (imode
))
4273 for (fmode
= GET_MODE (from
); fmode
!= VOIDmode
;
4274 fmode
= GET_MODE_WIDER_MODE (fmode
))
4276 int doing_unsigned
= unsignedp
;
4278 icode
= can_fix_p (imode
, fmode
, unsignedp
, &must_trunc
);
4279 if (icode
== CODE_FOR_nothing
&& imode
!= GET_MODE (to
) && unsignedp
)
4280 icode
= can_fix_p (imode
, fmode
, 0, &must_trunc
), doing_unsigned
= 0;
4282 if (icode
!= CODE_FOR_nothing
)
4284 to
= protect_from_queue (to
, 1);
4285 from
= protect_from_queue (from
, 0);
4287 if (fmode
!= GET_MODE (from
))
4288 from
= convert_to_mode (fmode
, from
, 0);
4291 from
= ftruncify (from
);
4293 if (imode
!= GET_MODE (to
))
4294 target
= gen_reg_rtx (imode
);
4296 emit_unop_insn (icode
, target
, from
,
4297 doing_unsigned
? UNSIGNED_FIX
: FIX
);
4299 convert_move (to
, target
, unsignedp
);
4304 #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
4305 /* For an unsigned conversion, there is one more way to do it.
4306 If we have a signed conversion, we generate code that compares
4307 the real value to the largest representable positive number. If if
4308 is smaller, the conversion is done normally. Otherwise, subtract
4309 one plus the highest signed number, convert, and add it back.
4311 We only need to check all real modes, since we know we didn't find
4312 anything with a wider integer mode. */
4314 if (unsignedp
&& GET_MODE_BITSIZE (GET_MODE (to
)) <= HOST_BITS_PER_WIDE_INT
)
4315 for (fmode
= GET_MODE (from
); fmode
!= VOIDmode
;
4316 fmode
= GET_MODE_WIDER_MODE (fmode
))
4317 /* Make sure we won't lose significant bits doing this. */
4318 if (GET_MODE_BITSIZE (fmode
) > GET_MODE_BITSIZE (GET_MODE (to
))
4319 && CODE_FOR_nothing
!= can_fix_p (GET_MODE (to
), fmode
, 0,
4323 REAL_VALUE_TYPE offset
;
4324 rtx limit
, lab1
, lab2
, insn
;
4326 bitsize
= GET_MODE_BITSIZE (GET_MODE (to
));
4327 offset
= REAL_VALUE_LDEXP (dconst1
, bitsize
- 1);
4328 limit
= CONST_DOUBLE_FROM_REAL_VALUE (offset
, fmode
);
4329 lab1
= gen_label_rtx ();
4330 lab2
= gen_label_rtx ();
4333 to
= protect_from_queue (to
, 1);
4334 from
= protect_from_queue (from
, 0);
4337 from
= force_not_mem (from
);
4339 if (fmode
!= GET_MODE (from
))
4340 from
= convert_to_mode (fmode
, from
, 0);
4342 /* See if we need to do the subtraction. */
4343 do_pending_stack_adjust ();
4344 emit_cmp_and_jump_insns (from
, limit
, GE
, NULL_RTX
, GET_MODE (from
),
4347 /* If not, do the signed "fix" and branch around fixup code. */
4348 expand_fix (to
, from
, 0);
4349 emit_jump_insn (gen_jump (lab2
));
4352 /* Otherwise, subtract 2**(N-1), convert to signed number,
4353 then add 2**(N-1). Do the addition using XOR since this
4354 will often generate better code. */
4356 target
= expand_binop (GET_MODE (from
), sub_optab
, from
, limit
,
4357 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4358 expand_fix (to
, target
, 0);
4359 target
= expand_binop (GET_MODE (to
), xor_optab
, to
,
4360 GEN_INT (trunc_int_for_mode
4361 ((HOST_WIDE_INT
) 1 << (bitsize
- 1),
4363 to
, 1, OPTAB_LIB_WIDEN
);
4366 emit_move_insn (to
, target
);
4370 if (mov_optab
->handlers
[(int) GET_MODE (to
)].insn_code
4371 != CODE_FOR_nothing
)
4373 /* Make a place for a REG_NOTE and add it. */
4374 insn
= emit_move_insn (to
, to
);
4375 set_unique_reg_note (insn
,
4377 gen_rtx_fmt_e (UNSIGNED_FIX
,
4386 /* We can't do it with an insn, so use a library call. But first ensure
4387 that the mode of TO is at least as wide as SImode, since those are the
4388 only library calls we know about. */
4390 if (GET_MODE_SIZE (GET_MODE (to
)) < GET_MODE_SIZE (SImode
))
4392 target
= gen_reg_rtx (SImode
);
4394 expand_fix (target
, from
, unsignedp
);
4396 else if (GET_MODE (from
) == SFmode
)
4398 if (GET_MODE (to
) == SImode
)
4399 libfcn
= unsignedp
? fixunssfsi_libfunc
: fixsfsi_libfunc
;
4400 else if (GET_MODE (to
) == DImode
)
4401 libfcn
= unsignedp
? fixunssfdi_libfunc
: fixsfdi_libfunc
;
4402 else if (GET_MODE (to
) == TImode
)
4403 libfcn
= unsignedp
? fixunssfti_libfunc
: fixsfti_libfunc
;
4407 else if (GET_MODE (from
) == DFmode
)
4409 if (GET_MODE (to
) == SImode
)
4410 libfcn
= unsignedp
? fixunsdfsi_libfunc
: fixdfsi_libfunc
;
4411 else if (GET_MODE (to
) == DImode
)
4412 libfcn
= unsignedp
? fixunsdfdi_libfunc
: fixdfdi_libfunc
;
4413 else if (GET_MODE (to
) == TImode
)
4414 libfcn
= unsignedp
? fixunsdfti_libfunc
: fixdfti_libfunc
;
4418 else if (GET_MODE (from
) == XFmode
)
4420 if (GET_MODE (to
) == SImode
)
4421 libfcn
= unsignedp
? fixunsxfsi_libfunc
: fixxfsi_libfunc
;
4422 else if (GET_MODE (to
) == DImode
)
4423 libfcn
= unsignedp
? fixunsxfdi_libfunc
: fixxfdi_libfunc
;
4424 else if (GET_MODE (to
) == TImode
)
4425 libfcn
= unsignedp
? fixunsxfti_libfunc
: fixxfti_libfunc
;
4429 else if (GET_MODE (from
) == TFmode
)
4431 if (GET_MODE (to
) == SImode
)
4432 libfcn
= unsignedp
? fixunstfsi_libfunc
: fixtfsi_libfunc
;
4433 else if (GET_MODE (to
) == DImode
)
4434 libfcn
= unsignedp
? fixunstfdi_libfunc
: fixtfdi_libfunc
;
4435 else if (GET_MODE (to
) == TImode
)
4436 libfcn
= unsignedp
? fixunstfti_libfunc
: fixtfti_libfunc
;
4448 to
= protect_from_queue (to
, 1);
4449 from
= protect_from_queue (from
, 0);
4452 from
= force_not_mem (from
);
4456 value
= emit_library_call_value (libfcn
, NULL_RTX
, LCT_CONST
,
4457 GET_MODE (to
), 1, from
,
4459 insns
= get_insns ();
4462 emit_libcall_block (insns
, target
, value
,
4463 gen_rtx_fmt_e (unsignedp
? UNSIGNED_FIX
: FIX
,
4464 GET_MODE (to
), from
));
4469 if (GET_MODE (to
) == GET_MODE (target
))
4470 emit_move_insn (to
, target
);
4472 convert_move (to
, target
, 0);
4481 optab op
= (optab
) xmalloc (sizeof (struct optab
));
4483 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
4485 op
->handlers
[i
].insn_code
= CODE_FOR_nothing
;
4486 op
->handlers
[i
].libfunc
= 0;
4489 if (code
!= UNKNOWN
)
4490 code_to_optab
[(int) code
] = op
;
4495 /* Initialize the libfunc fields of an entire group of entries in some
4496 optab. Each entry is set equal to a string consisting of a leading
4497 pair of underscores followed by a generic operation name followed by
4498 a mode name (downshifted to lower case) followed by a single character
4499 representing the number of operands for the given operation (which is
4500 usually one of the characters '2', '3', or '4').
4502 OPTABLE is the table in which libfunc fields are to be initialized.
4503 FIRST_MODE is the first machine mode index in the given optab to
4505 LAST_MODE is the last machine mode index in the given optab to
4507 OPNAME is the generic (string) name of the operation.
4508 SUFFIX is the character which specifies the number of operands for
4509 the given generic operation.
4513 init_libfuncs (optable
, first_mode
, last_mode
, opname
, suffix
)
4514 register optab optable
;
4515 register int first_mode
;
4516 register int last_mode
;
4517 register const char *opname
;
4518 register int suffix
;
4521 register unsigned opname_len
= strlen (opname
);
4523 for (mode
= first_mode
; (int) mode
<= (int) last_mode
;
4524 mode
= (enum machine_mode
) ((int) mode
+ 1))
4526 register const char *mname
= GET_MODE_NAME(mode
);
4527 register unsigned mname_len
= strlen (mname
);
4528 register char *libfunc_name
= alloca (2 + opname_len
+ mname_len
+ 1 + 1);
4530 register const char *q
;
4535 for (q
= opname
; *q
; )
4537 for (q
= mname
; *q
; q
++)
4538 *p
++ = TOLOWER (*q
);
4542 optable
->handlers
[(int) mode
].libfunc
4543 = gen_rtx_SYMBOL_REF (Pmode
, ggc_alloc_string (libfunc_name
,
4548 /* Initialize the libfunc fields of an entire group of entries in some
4549 optab which correspond to all integer mode operations. The parameters
4550 have the same meaning as similarly named ones for the `init_libfuncs'
4551 routine. (See above). */
4554 init_integral_libfuncs (optable
, opname
, suffix
)
4555 register optab optable
;
4556 register const char *opname
;
4557 register int suffix
;
4559 init_libfuncs (optable
, SImode
, TImode
, opname
, suffix
);
4562 /* Initialize the libfunc fields of an entire group of entries in some
4563 optab which correspond to all real mode operations. The parameters
4564 have the same meaning as similarly named ones for the `init_libfuncs'
4565 routine. (See above). */
4568 init_floating_libfuncs (optable
, opname
, suffix
)
4569 register optab optable
;
4570 register const char *opname
;
4571 register int suffix
;
4573 init_libfuncs (optable
, SFmode
, TFmode
, opname
, suffix
);
4577 init_one_libfunc (name
)
4578 register const char *name
;
4580 name
= ggc_strdup (name
);
4582 return gen_rtx_SYMBOL_REF (Pmode
, name
);
4585 /* Mark ARG (which is really an OPTAB *) for GC. */
4591 optab o
= *(optab
*) arg
;
4594 for (i
= 0; i
< NUM_MACHINE_MODES
; ++i
)
4595 ggc_mark_rtx (o
->handlers
[i
].libfunc
);
4598 /* Call this once to initialize the contents of the optabs
4599 appropriately for the current target machine. */
4604 unsigned int i
, j
, k
;
4606 /* Start by initializing all tables to contain CODE_FOR_nothing. */
4608 for (i
= 0; i
< ARRAY_SIZE (fixtab
); i
++)
4609 for (j
= 0; j
< ARRAY_SIZE (fixtab
[0]); j
++)
4610 for (k
= 0; k
< ARRAY_SIZE (fixtab
[0][0]); k
++)
4611 fixtab
[i
][j
][k
] = CODE_FOR_nothing
;
4613 for (i
= 0; i
< ARRAY_SIZE (fixtrunctab
); i
++)
4614 for (j
= 0; j
< ARRAY_SIZE (fixtrunctab
[0]); j
++)
4615 for (k
= 0; k
< ARRAY_SIZE (fixtrunctab
[0][0]); k
++)
4616 fixtrunctab
[i
][j
][k
] = CODE_FOR_nothing
;
4618 for (i
= 0; i
< ARRAY_SIZE (floattab
); i
++)
4619 for (j
= 0; j
< ARRAY_SIZE (floattab
[0]); j
++)
4620 for (k
= 0; k
< ARRAY_SIZE (floattab
[0][0]); k
++)
4621 floattab
[i
][j
][k
] = CODE_FOR_nothing
;
4623 for (i
= 0; i
< ARRAY_SIZE (extendtab
); i
++)
4624 for (j
= 0; j
< ARRAY_SIZE (extendtab
[0]); j
++)
4625 for (k
= 0; k
< ARRAY_SIZE (extendtab
[0][0]); k
++)
4626 extendtab
[i
][j
][k
] = CODE_FOR_nothing
;
4628 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
4629 setcc_gen_code
[i
] = CODE_FOR_nothing
;
4631 #ifdef HAVE_conditional_move
4632 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
4633 movcc_gen_code
[i
] = CODE_FOR_nothing
;
4636 add_optab
= init_optab (PLUS
);
4637 addv_optab
= init_optab (PLUS
);
4638 sub_optab
= init_optab (MINUS
);
4639 subv_optab
= init_optab (MINUS
);
4640 smul_optab
= init_optab (MULT
);
4641 smulv_optab
= init_optab (MULT
);
4642 smul_highpart_optab
= init_optab (UNKNOWN
);
4643 umul_highpart_optab
= init_optab (UNKNOWN
);
4644 smul_widen_optab
= init_optab (UNKNOWN
);
4645 umul_widen_optab
= init_optab (UNKNOWN
);
4646 sdiv_optab
= init_optab (DIV
);
4647 sdivv_optab
= init_optab (DIV
);
4648 sdivmod_optab
= init_optab (UNKNOWN
);
4649 udiv_optab
= init_optab (UDIV
);
4650 udivmod_optab
= init_optab (UNKNOWN
);
4651 smod_optab
= init_optab (MOD
);
4652 umod_optab
= init_optab (UMOD
);
4653 flodiv_optab
= init_optab (DIV
);
4654 ftrunc_optab
= init_optab (UNKNOWN
);
4655 and_optab
= init_optab (AND
);
4656 ior_optab
= init_optab (IOR
);
4657 xor_optab
= init_optab (XOR
);
4658 ashl_optab
= init_optab (ASHIFT
);
4659 ashr_optab
= init_optab (ASHIFTRT
);
4660 lshr_optab
= init_optab (LSHIFTRT
);
4661 rotl_optab
= init_optab (ROTATE
);
4662 rotr_optab
= init_optab (ROTATERT
);
4663 smin_optab
= init_optab (SMIN
);
4664 smax_optab
= init_optab (SMAX
);
4665 umin_optab
= init_optab (UMIN
);
4666 umax_optab
= init_optab (UMAX
);
4667 mov_optab
= init_optab (UNKNOWN
);
4668 movstrict_optab
= init_optab (UNKNOWN
);
4669 cmp_optab
= init_optab (UNKNOWN
);
4670 ucmp_optab
= init_optab (UNKNOWN
);
4671 tst_optab
= init_optab (UNKNOWN
);
4672 neg_optab
= init_optab (NEG
);
4673 negv_optab
= init_optab (NEG
);
4674 abs_optab
= init_optab (ABS
);
4675 absv_optab
= init_optab (ABS
);
4676 one_cmpl_optab
= init_optab (NOT
);
4677 ffs_optab
= init_optab (FFS
);
4678 sqrt_optab
= init_optab (SQRT
);
4679 sin_optab
= init_optab (UNKNOWN
);
4680 cos_optab
= init_optab (UNKNOWN
);
4681 strlen_optab
= init_optab (UNKNOWN
);
4682 cbranch_optab
= init_optab (UNKNOWN
);
4683 cmov_optab
= init_optab (UNKNOWN
);
4684 cstore_optab
= init_optab (UNKNOWN
);
4685 push_optab
= init_optab (UNKNOWN
);
4687 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
4689 movstr_optab
[i
] = CODE_FOR_nothing
;
4690 clrstr_optab
[i
] = CODE_FOR_nothing
;
4692 #ifdef HAVE_SECONDARY_RELOADS
4693 reload_in_optab
[i
] = reload_out_optab
[i
] = CODE_FOR_nothing
;
4697 /* Fill in the optabs with the insns we support. */
4700 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4701 /* This flag says the same insns that convert to a signed fixnum
4702 also convert validly to an unsigned one. */
4703 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
4704 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
4705 fixtrunctab
[i
][j
][1] = fixtrunctab
[i
][j
][0];
4708 /* Initialize the optabs with the names of the library functions. */
4709 init_integral_libfuncs (add_optab
, "add", '3');
4710 init_floating_libfuncs (add_optab
, "add", '3');
4711 init_integral_libfuncs (addv_optab
, "addv", '3');
4712 init_floating_libfuncs (addv_optab
, "add", '3');
4713 init_integral_libfuncs (sub_optab
, "sub", '3');
4714 init_floating_libfuncs (sub_optab
, "sub", '3');
4715 init_integral_libfuncs (subv_optab
, "subv", '3');
4716 init_floating_libfuncs (subv_optab
, "sub", '3');
4717 init_integral_libfuncs (smul_optab
, "mul", '3');
4718 init_floating_libfuncs (smul_optab
, "mul", '3');
4719 init_integral_libfuncs (smulv_optab
, "mulv", '3');
4720 init_floating_libfuncs (smulv_optab
, "mul", '3');
4721 init_integral_libfuncs (sdiv_optab
, "div", '3');
4722 init_integral_libfuncs (sdivv_optab
, "divv", '3');
4723 init_integral_libfuncs (udiv_optab
, "udiv", '3');
4724 init_integral_libfuncs (sdivmod_optab
, "divmod", '4');
4725 init_integral_libfuncs (udivmod_optab
, "udivmod", '4');
4726 init_integral_libfuncs (smod_optab
, "mod", '3');
4727 init_integral_libfuncs (umod_optab
, "umod", '3');
4728 init_floating_libfuncs (flodiv_optab
, "div", '3');
4729 init_floating_libfuncs (ftrunc_optab
, "ftrunc", '2');
4730 init_integral_libfuncs (and_optab
, "and", '3');
4731 init_integral_libfuncs (ior_optab
, "ior", '3');
4732 init_integral_libfuncs (xor_optab
, "xor", '3');
4733 init_integral_libfuncs (ashl_optab
, "ashl", '3');
4734 init_integral_libfuncs (ashr_optab
, "ashr", '3');
4735 init_integral_libfuncs (lshr_optab
, "lshr", '3');
4736 init_integral_libfuncs (smin_optab
, "min", '3');
4737 init_floating_libfuncs (smin_optab
, "min", '3');
4738 init_integral_libfuncs (smax_optab
, "max", '3');
4739 init_floating_libfuncs (smax_optab
, "max", '3');
4740 init_integral_libfuncs (umin_optab
, "umin", '3');
4741 init_integral_libfuncs (umax_optab
, "umax", '3');
4742 init_integral_libfuncs (neg_optab
, "neg", '2');
4743 init_floating_libfuncs (neg_optab
, "neg", '2');
4744 init_integral_libfuncs (negv_optab
, "negv", '2');
4745 init_floating_libfuncs (negv_optab
, "neg", '2');
4746 init_integral_libfuncs (one_cmpl_optab
, "one_cmpl", '2');
4747 init_integral_libfuncs (ffs_optab
, "ffs", '2');
4749 /* Comparison libcalls for integers MUST come in pairs, signed/unsigned. */
4750 init_integral_libfuncs (cmp_optab
, "cmp", '2');
4751 init_integral_libfuncs (ucmp_optab
, "ucmp", '2');
4752 init_floating_libfuncs (cmp_optab
, "cmp", '2');
4754 #ifdef MULSI3_LIBCALL
4755 smul_optab
->handlers
[(int) SImode
].libfunc
4756 = init_one_libfunc (MULSI3_LIBCALL
);
4758 #ifdef MULDI3_LIBCALL
4759 smul_optab
->handlers
[(int) DImode
].libfunc
4760 = init_one_libfunc (MULDI3_LIBCALL
);
4763 #ifdef DIVSI3_LIBCALL
4764 sdiv_optab
->handlers
[(int) SImode
].libfunc
4765 = init_one_libfunc (DIVSI3_LIBCALL
);
4767 #ifdef DIVDI3_LIBCALL
4768 sdiv_optab
->handlers
[(int) DImode
].libfunc
4769 = init_one_libfunc (DIVDI3_LIBCALL
);
4772 #ifdef UDIVSI3_LIBCALL
4773 udiv_optab
->handlers
[(int) SImode
].libfunc
4774 = init_one_libfunc (UDIVSI3_LIBCALL
);
4776 #ifdef UDIVDI3_LIBCALL
4777 udiv_optab
->handlers
[(int) DImode
].libfunc
4778 = init_one_libfunc (UDIVDI3_LIBCALL
);
4781 #ifdef MODSI3_LIBCALL
4782 smod_optab
->handlers
[(int) SImode
].libfunc
4783 = init_one_libfunc (MODSI3_LIBCALL
);
4785 #ifdef MODDI3_LIBCALL
4786 smod_optab
->handlers
[(int) DImode
].libfunc
4787 = init_one_libfunc (MODDI3_LIBCALL
);
4790 #ifdef UMODSI3_LIBCALL
4791 umod_optab
->handlers
[(int) SImode
].libfunc
4792 = init_one_libfunc (UMODSI3_LIBCALL
);
4794 #ifdef UMODDI3_LIBCALL
4795 umod_optab
->handlers
[(int) DImode
].libfunc
4796 = init_one_libfunc (UMODDI3_LIBCALL
);
4799 /* Use cabs for DC complex abs, since systems generally have cabs.
4800 Don't define any libcall for SCmode, so that cabs will be used. */
4801 abs_optab
->handlers
[(int) DCmode
].libfunc
4802 = init_one_libfunc ("cabs");
4804 /* The ffs function operates on `int'. */
4805 ffs_optab
->handlers
[(int) mode_for_size (INT_TYPE_SIZE
, MODE_INT
, 0)].libfunc
4806 = init_one_libfunc ("ffs");
4808 extendsfdf2_libfunc
= init_one_libfunc ("__extendsfdf2");
4809 extendsfxf2_libfunc
= init_one_libfunc ("__extendsfxf2");
4810 extendsftf2_libfunc
= init_one_libfunc ("__extendsftf2");
4811 extenddfxf2_libfunc
= init_one_libfunc ("__extenddfxf2");
4812 extenddftf2_libfunc
= init_one_libfunc ("__extenddftf2");
4814 truncdfsf2_libfunc
= init_one_libfunc ("__truncdfsf2");
4815 truncxfsf2_libfunc
= init_one_libfunc ("__truncxfsf2");
4816 trunctfsf2_libfunc
= init_one_libfunc ("__trunctfsf2");
4817 truncxfdf2_libfunc
= init_one_libfunc ("__truncxfdf2");
4818 trunctfdf2_libfunc
= init_one_libfunc ("__trunctfdf2");
4820 memcpy_libfunc
= init_one_libfunc ("memcpy");
4821 memmove_libfunc
= init_one_libfunc ("memmove");
4822 bcopy_libfunc
= init_one_libfunc ("bcopy");
4823 memcmp_libfunc
= init_one_libfunc ("memcmp");
4824 bcmp_libfunc
= init_one_libfunc ("__gcc_bcmp");
4825 memset_libfunc
= init_one_libfunc ("memset");
4826 bzero_libfunc
= init_one_libfunc ("bzero");
4828 unwind_resume_libfunc
= init_one_libfunc (USING_SJLJ_EXCEPTIONS
4829 ? "_Unwind_SjLj_Resume"
4830 : "_Unwind_Resume");
4831 #ifndef DONT_USE_BUILTIN_SETJMP
4832 setjmp_libfunc
= init_one_libfunc ("__builtin_setjmp");
4833 longjmp_libfunc
= init_one_libfunc ("__builtin_longjmp");
4835 setjmp_libfunc
= init_one_libfunc ("setjmp");
4836 longjmp_libfunc
= init_one_libfunc ("longjmp");
4838 unwind_sjlj_register_libfunc
= init_one_libfunc ("_Unwind_SjLj_Register");
4839 unwind_sjlj_unregister_libfunc
4840 = init_one_libfunc ("_Unwind_SjLj_Unregister");
4842 eqhf2_libfunc
= init_one_libfunc ("__eqhf2");
4843 nehf2_libfunc
= init_one_libfunc ("__nehf2");
4844 gthf2_libfunc
= init_one_libfunc ("__gthf2");
4845 gehf2_libfunc
= init_one_libfunc ("__gehf2");
4846 lthf2_libfunc
= init_one_libfunc ("__lthf2");
4847 lehf2_libfunc
= init_one_libfunc ("__lehf2");
4848 unordhf2_libfunc
= init_one_libfunc ("__unordhf2");
4850 eqsf2_libfunc
= init_one_libfunc ("__eqsf2");
4851 nesf2_libfunc
= init_one_libfunc ("__nesf2");
4852 gtsf2_libfunc
= init_one_libfunc ("__gtsf2");
4853 gesf2_libfunc
= init_one_libfunc ("__gesf2");
4854 ltsf2_libfunc
= init_one_libfunc ("__ltsf2");
4855 lesf2_libfunc
= init_one_libfunc ("__lesf2");
4856 unordsf2_libfunc
= init_one_libfunc ("__unordsf2");
4858 eqdf2_libfunc
= init_one_libfunc ("__eqdf2");
4859 nedf2_libfunc
= init_one_libfunc ("__nedf2");
4860 gtdf2_libfunc
= init_one_libfunc ("__gtdf2");
4861 gedf2_libfunc
= init_one_libfunc ("__gedf2");
4862 ltdf2_libfunc
= init_one_libfunc ("__ltdf2");
4863 ledf2_libfunc
= init_one_libfunc ("__ledf2");
4864 unorddf2_libfunc
= init_one_libfunc ("__unorddf2");
4866 eqxf2_libfunc
= init_one_libfunc ("__eqxf2");
4867 nexf2_libfunc
= init_one_libfunc ("__nexf2");
4868 gtxf2_libfunc
= init_one_libfunc ("__gtxf2");
4869 gexf2_libfunc
= init_one_libfunc ("__gexf2");
4870 ltxf2_libfunc
= init_one_libfunc ("__ltxf2");
4871 lexf2_libfunc
= init_one_libfunc ("__lexf2");
4872 unordxf2_libfunc
= init_one_libfunc ("__unordxf2");
4874 eqtf2_libfunc
= init_one_libfunc ("__eqtf2");
4875 netf2_libfunc
= init_one_libfunc ("__netf2");
4876 gttf2_libfunc
= init_one_libfunc ("__gttf2");
4877 getf2_libfunc
= init_one_libfunc ("__getf2");
4878 lttf2_libfunc
= init_one_libfunc ("__lttf2");
4879 letf2_libfunc
= init_one_libfunc ("__letf2");
4880 unordtf2_libfunc
= init_one_libfunc ("__unordtf2");
4882 floatsisf_libfunc
= init_one_libfunc ("__floatsisf");
4883 floatdisf_libfunc
= init_one_libfunc ("__floatdisf");
4884 floattisf_libfunc
= init_one_libfunc ("__floattisf");
4886 floatsidf_libfunc
= init_one_libfunc ("__floatsidf");
4887 floatdidf_libfunc
= init_one_libfunc ("__floatdidf");
4888 floattidf_libfunc
= init_one_libfunc ("__floattidf");
4890 floatsixf_libfunc
= init_one_libfunc ("__floatsixf");
4891 floatdixf_libfunc
= init_one_libfunc ("__floatdixf");
4892 floattixf_libfunc
= init_one_libfunc ("__floattixf");
4894 floatsitf_libfunc
= init_one_libfunc ("__floatsitf");
4895 floatditf_libfunc
= init_one_libfunc ("__floatditf");
4896 floattitf_libfunc
= init_one_libfunc ("__floattitf");
4898 fixsfsi_libfunc
= init_one_libfunc ("__fixsfsi");
4899 fixsfdi_libfunc
= init_one_libfunc ("__fixsfdi");
4900 fixsfti_libfunc
= init_one_libfunc ("__fixsfti");
4902 fixdfsi_libfunc
= init_one_libfunc ("__fixdfsi");
4903 fixdfdi_libfunc
= init_one_libfunc ("__fixdfdi");
4904 fixdfti_libfunc
= init_one_libfunc ("__fixdfti");
4906 fixxfsi_libfunc
= init_one_libfunc ("__fixxfsi");
4907 fixxfdi_libfunc
= init_one_libfunc ("__fixxfdi");
4908 fixxfti_libfunc
= init_one_libfunc ("__fixxfti");
4910 fixtfsi_libfunc
= init_one_libfunc ("__fixtfsi");
4911 fixtfdi_libfunc
= init_one_libfunc ("__fixtfdi");
4912 fixtfti_libfunc
= init_one_libfunc ("__fixtfti");
4914 fixunssfsi_libfunc
= init_one_libfunc ("__fixunssfsi");
4915 fixunssfdi_libfunc
= init_one_libfunc ("__fixunssfdi");
4916 fixunssfti_libfunc
= init_one_libfunc ("__fixunssfti");
4918 fixunsdfsi_libfunc
= init_one_libfunc ("__fixunsdfsi");
4919 fixunsdfdi_libfunc
= init_one_libfunc ("__fixunsdfdi");
4920 fixunsdfti_libfunc
= init_one_libfunc ("__fixunsdfti");
4922 fixunsxfsi_libfunc
= init_one_libfunc ("__fixunsxfsi");
4923 fixunsxfdi_libfunc
= init_one_libfunc ("__fixunsxfdi");
4924 fixunsxfti_libfunc
= init_one_libfunc ("__fixunsxfti");
4926 fixunstfsi_libfunc
= init_one_libfunc ("__fixunstfsi");
4927 fixunstfdi_libfunc
= init_one_libfunc ("__fixunstfdi");
4928 fixunstfti_libfunc
= init_one_libfunc ("__fixunstfti");
4930 /* For check-memory-usage. */
4931 chkr_check_addr_libfunc
= init_one_libfunc ("chkr_check_addr");
4932 chkr_set_right_libfunc
= init_one_libfunc ("chkr_set_right");
4933 chkr_copy_bitmap_libfunc
= init_one_libfunc ("chkr_copy_bitmap");
4934 chkr_check_exec_libfunc
= init_one_libfunc ("chkr_check_exec");
4935 chkr_check_str_libfunc
= init_one_libfunc ("chkr_check_str");
4937 /* For function entry/exit instrumentation. */
4938 profile_function_entry_libfunc
4939 = init_one_libfunc ("__cyg_profile_func_enter");
4940 profile_function_exit_libfunc
4941 = init_one_libfunc ("__cyg_profile_func_exit");
4943 #ifdef HAVE_conditional_trap
4947 #ifdef INIT_TARGET_OPTABS
4948 /* Allow the target to add more libcalls or rename some, etc. */
4952 /* Add these GC roots. */
4953 ggc_add_root (optab_table
, OTI_MAX
, sizeof(optab
), mark_optab
);
4954 ggc_add_rtx_root (libfunc_table
, LTI_MAX
);
4957 #ifdef HAVE_conditional_trap
4958 /* The insn generating function can not take an rtx_code argument.
4959 TRAP_RTX is used as an rtx argument. Its code is replaced with
4960 the code to be used in the trap insn and all other fields are
4962 static rtx trap_rtx
;
4967 if (HAVE_conditional_trap
)
4969 trap_rtx
= gen_rtx_fmt_ee (EQ
, VOIDmode
, NULL_RTX
, NULL_RTX
);
4970 ggc_add_rtx_root (&trap_rtx
, 1);
4975 /* Generate insns to trap with code TCODE if OP1 and OP2 satisfy condition
4976 CODE. Return 0 on failure. */
4979 gen_cond_trap (code
, op1
, op2
, tcode
)
4980 enum rtx_code code ATTRIBUTE_UNUSED
;
4981 rtx op1
, op2 ATTRIBUTE_UNUSED
, tcode ATTRIBUTE_UNUSED
;
4983 enum machine_mode mode
= GET_MODE (op1
);
4985 if (mode
== VOIDmode
)
4988 #ifdef HAVE_conditional_trap
4989 if (HAVE_conditional_trap
4990 && cmp_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
4994 emit_insn (GEN_FCN (cmp_optab
->handlers
[(int) mode
].insn_code
) (op1
, op2
));
4995 PUT_CODE (trap_rtx
, code
);
4996 insn
= gen_conditional_trap (trap_rtx
, tcode
);
5000 insn
= gen_sequence ();