ifcvt.c (noce_try_addcc): Do not call emit_conditional_add with weird operands.
[official-gcc.git] / gcc / optabs.c
blobd8c058e433081367a80bef268cc8d0c858e483d8
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, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "toplev.h"
29 /* Include insn-config.h before expr.h so that HAVE_conditional_move
30 is properly defined. */
31 #include "insn-config.h"
32 #include "rtl.h"
33 #include "tree.h"
34 #include "tm_p.h"
35 #include "flags.h"
36 #include "function.h"
37 #include "except.h"
38 #include "expr.h"
39 #include "optabs.h"
40 #include "libfuncs.h"
41 #include "recog.h"
42 #include "reload.h"
43 #include "ggc.h"
44 #include "real.h"
45 #include "basic-block.h"
47 /* Each optab contains info on how this target machine
48 can perform a particular operation
49 for all sizes and kinds of operands.
51 The operation to be performed is often specified
52 by passing one of these optabs as an argument.
54 See expr.h for documentation of these optabs. */
56 optab optab_table[OTI_MAX];
58 rtx libfunc_table[LTI_MAX];
60 /* Tables of patterns for extending one integer mode to another. */
61 enum insn_code extendtab[MAX_MACHINE_MODE][MAX_MACHINE_MODE][2];
63 /* Tables of patterns for converting between fixed and floating point. */
64 enum insn_code fixtab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
65 enum insn_code fixtrunctab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
66 enum insn_code floattab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
68 /* Contains the optab used for each rtx code. */
69 optab code_to_optab[NUM_RTX_CODE + 1];
71 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
72 gives the gen_function to make a branch to test that condition. */
74 rtxfun bcc_gen_fctn[NUM_RTX_CODE];
76 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
77 gives the insn code to make a store-condition insn
78 to test that condition. */
80 enum insn_code setcc_gen_code[NUM_RTX_CODE];
82 #ifdef HAVE_conditional_move
83 /* Indexed by the machine mode, gives the insn code to make a conditional
84 move insn. This is not indexed by the rtx-code like bcc_gen_fctn and
85 setcc_gen_code to cut down on the number of named patterns. Consider a day
86 when a lot more rtx codes are conditional (eg: for the ARM). */
88 enum insn_code movcc_gen_code[NUM_MACHINE_MODES];
89 #endif
91 static int add_equal_note PARAMS ((rtx, rtx, enum rtx_code, rtx, rtx));
92 static rtx widen_operand PARAMS ((rtx, enum machine_mode,
93 enum machine_mode, int, int));
94 static int expand_cmplxdiv_straight PARAMS ((rtx, rtx, rtx, rtx,
95 rtx, rtx, enum machine_mode,
96 int, enum optab_methods,
97 enum mode_class, optab));
98 static int expand_cmplxdiv_wide PARAMS ((rtx, rtx, rtx, rtx,
99 rtx, rtx, enum machine_mode,
100 int, enum optab_methods,
101 enum mode_class, optab));
102 static void prepare_cmp_insn PARAMS ((rtx *, rtx *, enum rtx_code *, rtx,
103 enum machine_mode *, int *,
104 enum can_compare_purpose));
105 static enum insn_code can_fix_p PARAMS ((enum machine_mode, enum machine_mode,
106 int, int *));
107 static enum insn_code can_float_p PARAMS ((enum machine_mode,
108 enum machine_mode,
109 int));
110 static rtx ftruncify PARAMS ((rtx));
111 static optab new_optab PARAMS ((void));
112 static inline optab init_optab PARAMS ((enum rtx_code));
113 static inline optab init_optabv PARAMS ((enum rtx_code));
114 static void init_libfuncs PARAMS ((optab, int, int, const char *, int));
115 static void init_integral_libfuncs PARAMS ((optab, const char *, int));
116 static void init_floating_libfuncs PARAMS ((optab, const char *, int));
117 #ifdef HAVE_conditional_trap
118 static void init_traps PARAMS ((void));
119 #endif
120 static void emit_cmp_and_jump_insn_1 PARAMS ((rtx, rtx, enum machine_mode,
121 enum rtx_code, int, rtx));
122 static void prepare_float_lib_cmp PARAMS ((rtx *, rtx *, enum rtx_code *,
123 enum machine_mode *, int *));
124 static rtx expand_vector_binop PARAMS ((enum machine_mode, optab,
125 rtx, rtx, rtx, int,
126 enum optab_methods));
127 static rtx expand_vector_unop PARAMS ((enum machine_mode, optab, rtx, rtx,
128 int));
130 /* Add a REG_EQUAL note to the last insn in INSNS. TARGET is being set to
131 the result of operation CODE applied to OP0 (and OP1 if it is a binary
132 operation).
134 If the last insn does not set TARGET, don't do anything, but return 1.
136 If a previous insn sets TARGET and TARGET is one of OP0 or OP1,
137 don't add the REG_EQUAL note but return 0. Our caller can then try
138 again, ensuring that TARGET is not one of the operands. */
140 static int
141 add_equal_note (insns, target, code, op0, op1)
142 rtx insns;
143 rtx target;
144 enum rtx_code code;
145 rtx op0, op1;
147 rtx last_insn, insn, set;
148 rtx note;
150 if (! insns
151 || ! INSN_P (insns)
152 || NEXT_INSN (insns) == NULL_RTX)
153 abort ();
155 if (GET_RTX_CLASS (code) != '1' && GET_RTX_CLASS (code) != '2'
156 && GET_RTX_CLASS (code) != 'c' && GET_RTX_CLASS (code) != '<')
157 return 1;
159 if (GET_CODE (target) == ZERO_EXTRACT)
160 return 1;
162 for (last_insn = insns;
163 NEXT_INSN (last_insn) != NULL_RTX;
164 last_insn = NEXT_INSN (last_insn))
167 set = single_set (last_insn);
168 if (set == NULL_RTX)
169 return 1;
171 if (! rtx_equal_p (SET_DEST (set), target)
172 /* For a STRICT_LOW_PART, the REG_NOTE applies to what is inside the
173 SUBREG. */
174 && (GET_CODE (SET_DEST (set)) != STRICT_LOW_PART
175 || ! rtx_equal_p (SUBREG_REG (XEXP (SET_DEST (set), 0)),
176 target)))
177 return 1;
179 /* If TARGET is in OP0 or OP1, check if anything in SEQ sets TARGET
180 besides the last insn. */
181 if (reg_overlap_mentioned_p (target, op0)
182 || (op1 && reg_overlap_mentioned_p (target, op1)))
184 insn = PREV_INSN (last_insn);
185 while (insn != NULL_RTX)
187 if (reg_set_p (target, insn))
188 return 0;
190 insn = PREV_INSN (insn);
194 if (GET_RTX_CLASS (code) == '1')
195 note = gen_rtx_fmt_e (code, GET_MODE (target), copy_rtx (op0));
196 else
197 note = gen_rtx_fmt_ee (code, GET_MODE (target), copy_rtx (op0), copy_rtx (op1));
199 set_unique_reg_note (last_insn, REG_EQUAL, note);
201 return 1;
204 /* Widen OP to MODE and return the rtx for the widened operand. UNSIGNEDP
205 says whether OP is signed or unsigned. NO_EXTEND is nonzero if we need
206 not actually do a sign-extend or zero-extend, but can leave the
207 higher-order bits of the result rtx undefined, for example, in the case
208 of logical operations, but not right shifts. */
210 static rtx
211 widen_operand (op, mode, oldmode, unsignedp, no_extend)
212 rtx op;
213 enum machine_mode mode, oldmode;
214 int unsignedp;
215 int no_extend;
217 rtx result;
219 /* If we don't have to extend and this is a constant, return it. */
220 if (no_extend && GET_MODE (op) == VOIDmode)
221 return op;
223 /* If we must extend do so. If OP is a SUBREG for a promoted object, also
224 extend since it will be more efficient to do so unless the signedness of
225 a promoted object differs from our extension. */
226 if (! no_extend
227 || (GET_CODE (op) == SUBREG && SUBREG_PROMOTED_VAR_P (op)
228 && SUBREG_PROMOTED_UNSIGNED_P (op) == unsignedp))
229 return convert_modes (mode, oldmode, op, unsignedp);
231 /* If MODE is no wider than a single word, we return a paradoxical
232 SUBREG. */
233 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
234 return gen_rtx_SUBREG (mode, force_reg (GET_MODE (op), op), 0);
236 /* Otherwise, get an object of MODE, clobber it, and set the low-order
237 part to OP. */
239 result = gen_reg_rtx (mode);
240 emit_insn (gen_rtx_CLOBBER (VOIDmode, result));
241 emit_move_insn (gen_lowpart (GET_MODE (op), result), op);
242 return result;
245 /* Generate code to perform a straightforward complex divide. */
247 static int
248 expand_cmplxdiv_straight (real0, real1, imag0, imag1, realr, imagr, submode,
249 unsignedp, methods, class, binoptab)
250 rtx real0, real1, imag0, imag1, realr, imagr;
251 enum machine_mode submode;
252 int unsignedp;
253 enum optab_methods methods;
254 enum mode_class class;
255 optab binoptab;
257 rtx divisor;
258 rtx real_t, imag_t;
259 rtx temp1, temp2;
260 rtx res;
261 optab this_add_optab = add_optab;
262 optab this_sub_optab = sub_optab;
263 optab this_neg_optab = neg_optab;
264 optab this_mul_optab = smul_optab;
266 if (binoptab == sdivv_optab)
268 this_add_optab = addv_optab;
269 this_sub_optab = subv_optab;
270 this_neg_optab = negv_optab;
271 this_mul_optab = smulv_optab;
274 /* Don't fetch these from memory more than once. */
275 real0 = force_reg (submode, real0);
276 real1 = force_reg (submode, real1);
278 if (imag0 != 0)
279 imag0 = force_reg (submode, imag0);
281 imag1 = force_reg (submode, imag1);
283 /* Divisor: c*c + d*d. */
284 temp1 = expand_binop (submode, this_mul_optab, real1, real1,
285 NULL_RTX, unsignedp, methods);
287 temp2 = expand_binop (submode, this_mul_optab, imag1, imag1,
288 NULL_RTX, unsignedp, methods);
290 if (temp1 == 0 || temp2 == 0)
291 return 0;
293 divisor = expand_binop (submode, this_add_optab, temp1, temp2,
294 NULL_RTX, unsignedp, methods);
295 if (divisor == 0)
296 return 0;
298 if (imag0 == 0)
300 /* Mathematically, ((a)(c-id))/divisor. */
301 /* Computationally, (a+i0) / (c+id) = (ac/(cc+dd)) + i(-ad/(cc+dd)). */
303 /* Calculate the dividend. */
304 real_t = expand_binop (submode, this_mul_optab, real0, real1,
305 NULL_RTX, unsignedp, methods);
307 imag_t = expand_binop (submode, this_mul_optab, real0, imag1,
308 NULL_RTX, unsignedp, methods);
310 if (real_t == 0 || imag_t == 0)
311 return 0;
313 imag_t = expand_unop (submode, this_neg_optab, imag_t,
314 NULL_RTX, unsignedp);
316 else
318 /* Mathematically, ((a+ib)(c-id))/divider. */
319 /* Calculate the dividend. */
320 temp1 = expand_binop (submode, this_mul_optab, real0, real1,
321 NULL_RTX, unsignedp, methods);
323 temp2 = expand_binop (submode, this_mul_optab, imag0, imag1,
324 NULL_RTX, unsignedp, methods);
326 if (temp1 == 0 || temp2 == 0)
327 return 0;
329 real_t = expand_binop (submode, this_add_optab, temp1, temp2,
330 NULL_RTX, unsignedp, methods);
332 temp1 = expand_binop (submode, this_mul_optab, imag0, real1,
333 NULL_RTX, unsignedp, methods);
335 temp2 = expand_binop (submode, this_mul_optab, real0, imag1,
336 NULL_RTX, unsignedp, methods);
338 if (temp1 == 0 || temp2 == 0)
339 return 0;
341 imag_t = expand_binop (submode, this_sub_optab, temp1, temp2,
342 NULL_RTX, unsignedp, methods);
344 if (real_t == 0 || imag_t == 0)
345 return 0;
348 if (class == MODE_COMPLEX_FLOAT)
349 res = expand_binop (submode, binoptab, real_t, divisor,
350 realr, unsignedp, methods);
351 else
352 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
353 real_t, divisor, realr, unsignedp);
355 if (res == 0)
356 return 0;
358 if (res != realr)
359 emit_move_insn (realr, res);
361 if (class == MODE_COMPLEX_FLOAT)
362 res = expand_binop (submode, binoptab, imag_t, divisor,
363 imagr, unsignedp, methods);
364 else
365 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
366 imag_t, divisor, imagr, unsignedp);
368 if (res == 0)
369 return 0;
371 if (res != imagr)
372 emit_move_insn (imagr, res);
374 return 1;
377 /* Generate code to perform a wide-input-range-acceptable complex divide. */
379 static int
380 expand_cmplxdiv_wide (real0, real1, imag0, imag1, realr, imagr, submode,
381 unsignedp, methods, class, binoptab)
382 rtx real0, real1, imag0, imag1, realr, imagr;
383 enum machine_mode submode;
384 int unsignedp;
385 enum optab_methods methods;
386 enum mode_class class;
387 optab binoptab;
389 rtx ratio, divisor;
390 rtx real_t, imag_t;
391 rtx temp1, temp2, lab1, lab2;
392 enum machine_mode mode;
393 rtx res;
394 optab this_add_optab = add_optab;
395 optab this_sub_optab = sub_optab;
396 optab this_neg_optab = neg_optab;
397 optab this_mul_optab = smul_optab;
399 if (binoptab == sdivv_optab)
401 this_add_optab = addv_optab;
402 this_sub_optab = subv_optab;
403 this_neg_optab = negv_optab;
404 this_mul_optab = smulv_optab;
407 /* Don't fetch these from memory more than once. */
408 real0 = force_reg (submode, real0);
409 real1 = force_reg (submode, real1);
411 if (imag0 != 0)
412 imag0 = force_reg (submode, imag0);
414 imag1 = force_reg (submode, imag1);
416 /* XXX What's an "unsigned" complex number? */
417 if (unsignedp)
419 temp1 = real1;
420 temp2 = imag1;
422 else
424 temp1 = expand_abs (submode, real1, NULL_RTX, unsignedp, 1);
425 temp2 = expand_abs (submode, imag1, NULL_RTX, unsignedp, 1);
428 if (temp1 == 0 || temp2 == 0)
429 return 0;
431 mode = GET_MODE (temp1);
432 lab1 = gen_label_rtx ();
433 emit_cmp_and_jump_insns (temp1, temp2, LT, NULL_RTX,
434 mode, unsignedp, lab1);
436 /* |c| >= |d|; use ratio d/c to scale dividend and divisor. */
438 if (class == MODE_COMPLEX_FLOAT)
439 ratio = expand_binop (submode, binoptab, imag1, real1,
440 NULL_RTX, unsignedp, methods);
441 else
442 ratio = expand_divmod (0, TRUNC_DIV_EXPR, submode,
443 imag1, real1, NULL_RTX, unsignedp);
445 if (ratio == 0)
446 return 0;
448 /* Calculate divisor. */
450 temp1 = expand_binop (submode, this_mul_optab, imag1, ratio,
451 NULL_RTX, unsignedp, methods);
453 if (temp1 == 0)
454 return 0;
456 divisor = expand_binop (submode, this_add_optab, temp1, real1,
457 NULL_RTX, unsignedp, methods);
459 if (divisor == 0)
460 return 0;
462 /* Calculate dividend. */
464 if (imag0 == 0)
466 real_t = real0;
468 /* Compute a / (c+id) as a / (c+d(d/c)) + i (-a(d/c)) / (c+d(d/c)). */
470 imag_t = expand_binop (submode, this_mul_optab, real0, ratio,
471 NULL_RTX, unsignedp, methods);
473 if (imag_t == 0)
474 return 0;
476 imag_t = expand_unop (submode, this_neg_optab, imag_t,
477 NULL_RTX, unsignedp);
479 if (real_t == 0 || imag_t == 0)
480 return 0;
482 else
484 /* Compute (a+ib)/(c+id) as
485 (a+b(d/c))/(c+d(d/c) + i(b-a(d/c))/(c+d(d/c)). */
487 temp1 = expand_binop (submode, this_mul_optab, imag0, ratio,
488 NULL_RTX, unsignedp, methods);
490 if (temp1 == 0)
491 return 0;
493 real_t = expand_binop (submode, this_add_optab, temp1, real0,
494 NULL_RTX, unsignedp, methods);
496 temp1 = expand_binop (submode, this_mul_optab, real0, ratio,
497 NULL_RTX, unsignedp, methods);
499 if (temp1 == 0)
500 return 0;
502 imag_t = expand_binop (submode, this_sub_optab, imag0, temp1,
503 NULL_RTX, unsignedp, methods);
505 if (real_t == 0 || imag_t == 0)
506 return 0;
509 if (class == MODE_COMPLEX_FLOAT)
510 res = expand_binop (submode, binoptab, real_t, divisor,
511 realr, unsignedp, methods);
512 else
513 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
514 real_t, divisor, realr, unsignedp);
516 if (res == 0)
517 return 0;
519 if (res != realr)
520 emit_move_insn (realr, res);
522 if (class == MODE_COMPLEX_FLOAT)
523 res = expand_binop (submode, binoptab, imag_t, divisor,
524 imagr, unsignedp, methods);
525 else
526 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
527 imag_t, divisor, imagr, unsignedp);
529 if (res == 0)
530 return 0;
532 if (res != imagr)
533 emit_move_insn (imagr, res);
535 lab2 = gen_label_rtx ();
536 emit_jump_insn (gen_jump (lab2));
537 emit_barrier ();
539 emit_label (lab1);
541 /* |d| > |c|; use ratio c/d to scale dividend and divisor. */
543 if (class == MODE_COMPLEX_FLOAT)
544 ratio = expand_binop (submode, binoptab, real1, imag1,
545 NULL_RTX, unsignedp, methods);
546 else
547 ratio = expand_divmod (0, TRUNC_DIV_EXPR, submode,
548 real1, imag1, NULL_RTX, unsignedp);
550 if (ratio == 0)
551 return 0;
553 /* Calculate divisor. */
555 temp1 = expand_binop (submode, this_mul_optab, real1, ratio,
556 NULL_RTX, unsignedp, methods);
558 if (temp1 == 0)
559 return 0;
561 divisor = expand_binop (submode, this_add_optab, temp1, imag1,
562 NULL_RTX, unsignedp, methods);
564 if (divisor == 0)
565 return 0;
567 /* Calculate dividend. */
569 if (imag0 == 0)
571 /* Compute a / (c+id) as a(c/d) / (c(c/d)+d) + i (-a) / (c(c/d)+d). */
573 real_t = expand_binop (submode, this_mul_optab, real0, ratio,
574 NULL_RTX, unsignedp, methods);
576 imag_t = expand_unop (submode, this_neg_optab, real0,
577 NULL_RTX, unsignedp);
579 if (real_t == 0 || imag_t == 0)
580 return 0;
582 else
584 /* Compute (a+ib)/(c+id) as
585 (a(c/d)+b)/(c(c/d)+d) + i (b(c/d)-a)/(c(c/d)+d). */
587 temp1 = expand_binop (submode, this_mul_optab, real0, ratio,
588 NULL_RTX, unsignedp, methods);
590 if (temp1 == 0)
591 return 0;
593 real_t = expand_binop (submode, this_add_optab, temp1, imag0,
594 NULL_RTX, unsignedp, methods);
596 temp1 = expand_binop (submode, this_mul_optab, imag0, ratio,
597 NULL_RTX, unsignedp, methods);
599 if (temp1 == 0)
600 return 0;
602 imag_t = expand_binop (submode, this_sub_optab, temp1, real0,
603 NULL_RTX, unsignedp, methods);
605 if (real_t == 0 || imag_t == 0)
606 return 0;
609 if (class == MODE_COMPLEX_FLOAT)
610 res = expand_binop (submode, binoptab, real_t, divisor,
611 realr, unsignedp, methods);
612 else
613 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
614 real_t, divisor, realr, unsignedp);
616 if (res == 0)
617 return 0;
619 if (res != realr)
620 emit_move_insn (realr, res);
622 if (class == MODE_COMPLEX_FLOAT)
623 res = expand_binop (submode, binoptab, imag_t, divisor,
624 imagr, unsignedp, methods);
625 else
626 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
627 imag_t, divisor, imagr, unsignedp);
629 if (res == 0)
630 return 0;
632 if (res != imagr)
633 emit_move_insn (imagr, res);
635 emit_label (lab2);
637 return 1;
640 /* Wrapper around expand_binop which takes an rtx code to specify
641 the operation to perform, not an optab pointer. All other
642 arguments are the same. */
644 expand_simple_binop (mode, code, op0, op1, target, unsignedp, methods)
645 enum machine_mode mode;
646 enum rtx_code code;
647 rtx op0, op1;
648 rtx target;
649 int unsignedp;
650 enum optab_methods methods;
652 optab binop = code_to_optab[(int) code];
653 if (binop == 0)
654 abort ();
656 return expand_binop (mode, binop, op0, op1, target, unsignedp, methods);
659 /* Generate code to perform an operation specified by BINOPTAB
660 on operands OP0 and OP1, with result having machine-mode MODE.
662 UNSIGNEDP is for the case where we have to widen the operands
663 to perform the operation. It says to use zero-extension.
665 If TARGET is nonzero, the value
666 is generated there, if it is convenient to do so.
667 In all cases an rtx is returned for the locus of the value;
668 this may or may not be TARGET. */
671 expand_binop (mode, binoptab, op0, op1, target, unsignedp, methods)
672 enum machine_mode mode;
673 optab binoptab;
674 rtx op0, op1;
675 rtx target;
676 int unsignedp;
677 enum optab_methods methods;
679 enum optab_methods next_methods
680 = (methods == OPTAB_LIB || methods == OPTAB_LIB_WIDEN
681 ? OPTAB_WIDEN : methods);
682 enum mode_class class;
683 enum machine_mode wider_mode;
684 rtx temp;
685 int commutative_op = 0;
686 int shift_op = (binoptab->code == ASHIFT
687 || binoptab->code == ASHIFTRT
688 || binoptab->code == LSHIFTRT
689 || binoptab->code == ROTATE
690 || binoptab->code == ROTATERT);
691 rtx entry_last = get_last_insn ();
692 rtx last;
694 class = GET_MODE_CLASS (mode);
696 op0 = protect_from_queue (op0, 0);
697 op1 = protect_from_queue (op1, 0);
698 if (target)
699 target = protect_from_queue (target, 1);
701 if (flag_force_mem)
703 op0 = force_not_mem (op0);
704 op1 = force_not_mem (op1);
707 /* If subtracting an integer constant, convert this into an addition of
708 the negated constant. */
710 if (binoptab == sub_optab && GET_CODE (op1) == CONST_INT)
712 op1 = negate_rtx (mode, op1);
713 binoptab = add_optab;
716 /* If we are inside an appropriately-short loop and one operand is an
717 expensive constant, force it into a register. */
718 if (CONSTANT_P (op0) && preserve_subexpressions_p ()
719 && rtx_cost (op0, binoptab->code) > COSTS_N_INSNS (1))
720 op0 = force_reg (mode, op0);
722 if (CONSTANT_P (op1) && preserve_subexpressions_p ()
723 && ! shift_op && rtx_cost (op1, binoptab->code) > COSTS_N_INSNS (1))
724 op1 = force_reg (mode, op1);
726 /* Record where to delete back to if we backtrack. */
727 last = get_last_insn ();
729 /* If operation is commutative,
730 try to make the first operand a register.
731 Even better, try to make it the same as the target.
732 Also try to make the last operand a constant. */
733 if (GET_RTX_CLASS (binoptab->code) == 'c'
734 || binoptab == smul_widen_optab
735 || binoptab == umul_widen_optab
736 || binoptab == smul_highpart_optab
737 || binoptab == umul_highpart_optab)
739 commutative_op = 1;
741 if (((target == 0 || GET_CODE (target) == REG)
742 ? ((GET_CODE (op1) == REG
743 && GET_CODE (op0) != REG)
744 || target == op1)
745 : rtx_equal_p (op1, target))
746 || GET_CODE (op0) == CONST_INT)
748 temp = op1;
749 op1 = op0;
750 op0 = temp;
754 /* If we can do it with a three-operand insn, do so. */
756 if (methods != OPTAB_MUST_WIDEN
757 && binoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
759 int icode = (int) binoptab->handlers[(int) mode].insn_code;
760 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
761 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
762 rtx pat;
763 rtx xop0 = op0, xop1 = op1;
765 if (target)
766 temp = target;
767 else
768 temp = gen_reg_rtx (mode);
770 /* If it is a commutative operator and the modes would match
771 if we would swap the operands, we can save the conversions. */
772 if (commutative_op)
774 if (GET_MODE (op0) != mode0 && GET_MODE (op1) != mode1
775 && GET_MODE (op0) == mode1 && GET_MODE (op1) == mode0)
777 rtx tmp;
779 tmp = op0; op0 = op1; op1 = tmp;
780 tmp = xop0; xop0 = xop1; xop1 = tmp;
784 /* In case the insn wants input operands in modes different from
785 those of the actual operands, convert the operands. It would
786 seem that we don't need to convert CONST_INTs, but we do, so
787 that they're properly zero-extended, sign-extended or truncated
788 for their mode. */
790 if (GET_MODE (op0) != mode0 && mode0 != VOIDmode)
791 xop0 = convert_modes (mode0,
792 GET_MODE (op0) != VOIDmode
793 ? GET_MODE (op0)
794 : mode,
795 xop0, unsignedp);
797 if (GET_MODE (op1) != mode1 && mode1 != VOIDmode)
798 xop1 = convert_modes (mode1,
799 GET_MODE (op1) != VOIDmode
800 ? GET_MODE (op1)
801 : mode,
802 xop1, unsignedp);
804 /* Now, if insn's predicates don't allow our operands, put them into
805 pseudo regs. */
807 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0)
808 && mode0 != VOIDmode)
809 xop0 = copy_to_mode_reg (mode0, xop0);
811 if (! (*insn_data[icode].operand[2].predicate) (xop1, mode1)
812 && mode1 != VOIDmode)
813 xop1 = copy_to_mode_reg (mode1, xop1);
815 if (! (*insn_data[icode].operand[0].predicate) (temp, mode))
816 temp = gen_reg_rtx (mode);
818 pat = GEN_FCN (icode) (temp, xop0, xop1);
819 if (pat)
821 /* If PAT is composed of more than one insn, try to add an appropriate
822 REG_EQUAL note to it. If we can't because TEMP conflicts with an
823 operand, call ourselves again, this time without a target. */
824 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX
825 && ! add_equal_note (pat, temp, binoptab->code, xop0, xop1))
827 delete_insns_since (last);
828 return expand_binop (mode, binoptab, op0, op1, NULL_RTX,
829 unsignedp, methods);
832 emit_insn (pat);
833 return temp;
835 else
836 delete_insns_since (last);
839 /* If this is a multiply, see if we can do a widening operation that
840 takes operands of this mode and makes a wider mode. */
842 if (binoptab == smul_optab && GET_MODE_WIDER_MODE (mode) != VOIDmode
843 && (((unsignedp ? umul_widen_optab : smul_widen_optab)
844 ->handlers[(int) GET_MODE_WIDER_MODE (mode)].insn_code)
845 != CODE_FOR_nothing))
847 temp = expand_binop (GET_MODE_WIDER_MODE (mode),
848 unsignedp ? umul_widen_optab : smul_widen_optab,
849 op0, op1, NULL_RTX, unsignedp, OPTAB_DIRECT);
851 if (temp != 0)
853 if (GET_MODE_CLASS (mode) == MODE_INT)
854 return gen_lowpart (mode, temp);
855 else
856 return convert_to_mode (mode, temp, unsignedp);
860 /* Look for a wider mode of the same class for which we think we
861 can open-code the operation. Check for a widening multiply at the
862 wider mode as well. */
864 if ((class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
865 && methods != OPTAB_DIRECT && methods != OPTAB_LIB)
866 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
867 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
869 if (binoptab->handlers[(int) wider_mode].insn_code != CODE_FOR_nothing
870 || (binoptab == smul_optab
871 && GET_MODE_WIDER_MODE (wider_mode) != VOIDmode
872 && (((unsignedp ? umul_widen_optab : smul_widen_optab)
873 ->handlers[(int) GET_MODE_WIDER_MODE (wider_mode)].insn_code)
874 != CODE_FOR_nothing)))
876 rtx xop0 = op0, xop1 = op1;
877 int no_extend = 0;
879 /* For certain integer operations, we need not actually extend
880 the narrow operands, as long as we will truncate
881 the results to the same narrowness. */
883 if ((binoptab == ior_optab || binoptab == and_optab
884 || binoptab == xor_optab
885 || binoptab == add_optab || binoptab == sub_optab
886 || binoptab == smul_optab || binoptab == ashl_optab)
887 && class == MODE_INT)
888 no_extend = 1;
890 xop0 = widen_operand (xop0, wider_mode, mode, unsignedp, no_extend);
892 /* The second operand of a shift must always be extended. */
893 xop1 = widen_operand (xop1, wider_mode, mode, unsignedp,
894 no_extend && binoptab != ashl_optab);
896 temp = expand_binop (wider_mode, binoptab, xop0, xop1, NULL_RTX,
897 unsignedp, OPTAB_DIRECT);
898 if (temp)
900 if (class != MODE_INT)
902 if (target == 0)
903 target = gen_reg_rtx (mode);
904 convert_move (target, temp, 0);
905 return target;
907 else
908 return gen_lowpart (mode, temp);
910 else
911 delete_insns_since (last);
915 /* These can be done a word at a time. */
916 if ((binoptab == and_optab || binoptab == ior_optab || binoptab == xor_optab)
917 && class == MODE_INT
918 && GET_MODE_SIZE (mode) > UNITS_PER_WORD
919 && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
921 int i;
922 rtx insns;
923 rtx equiv_value;
925 /* If TARGET is the same as one of the operands, the REG_EQUAL note
926 won't be accurate, so use a new target. */
927 if (target == 0 || target == op0 || target == op1)
928 target = gen_reg_rtx (mode);
930 start_sequence ();
932 /* Do the actual arithmetic. */
933 for (i = 0; i < GET_MODE_BITSIZE (mode) / BITS_PER_WORD; i++)
935 rtx target_piece = operand_subword (target, i, 1, mode);
936 rtx x = expand_binop (word_mode, binoptab,
937 operand_subword_force (op0, i, mode),
938 operand_subword_force (op1, i, mode),
939 target_piece, unsignedp, next_methods);
941 if (x == 0)
942 break;
944 if (target_piece != x)
945 emit_move_insn (target_piece, x);
948 insns = get_insns ();
949 end_sequence ();
951 if (i == GET_MODE_BITSIZE (mode) / BITS_PER_WORD)
953 if (binoptab->code != UNKNOWN)
954 equiv_value
955 = gen_rtx_fmt_ee (binoptab->code, mode,
956 copy_rtx (op0), copy_rtx (op1));
957 else
958 equiv_value = 0;
960 emit_no_conflict_block (insns, target, op0, op1, equiv_value);
961 return target;
965 /* Synthesize double word shifts from single word shifts. */
966 if ((binoptab == lshr_optab || binoptab == ashl_optab
967 || binoptab == ashr_optab)
968 && class == MODE_INT
969 && GET_CODE (op1) == CONST_INT
970 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
971 && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
972 && ashl_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
973 && lshr_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
975 rtx insns, inter, equiv_value;
976 rtx into_target, outof_target;
977 rtx into_input, outof_input;
978 int shift_count, left_shift, outof_word;
980 /* If TARGET is the same as one of the operands, the REG_EQUAL note
981 won't be accurate, so use a new target. */
982 if (target == 0 || target == op0 || target == op1)
983 target = gen_reg_rtx (mode);
985 start_sequence ();
987 shift_count = INTVAL (op1);
989 /* OUTOF_* is the word we are shifting bits away from, and
990 INTO_* is the word that we are shifting bits towards, thus
991 they differ depending on the direction of the shift and
992 WORDS_BIG_ENDIAN. */
994 left_shift = binoptab == ashl_optab;
995 outof_word = left_shift ^ ! WORDS_BIG_ENDIAN;
997 outof_target = operand_subword (target, outof_word, 1, mode);
998 into_target = operand_subword (target, 1 - outof_word, 1, mode);
1000 outof_input = operand_subword_force (op0, outof_word, mode);
1001 into_input = operand_subword_force (op0, 1 - outof_word, mode);
1003 if (shift_count >= BITS_PER_WORD)
1005 inter = expand_binop (word_mode, binoptab,
1006 outof_input,
1007 GEN_INT (shift_count - BITS_PER_WORD),
1008 into_target, unsignedp, next_methods);
1010 if (inter != 0 && inter != into_target)
1011 emit_move_insn (into_target, inter);
1013 /* For a signed right shift, we must fill the word we are shifting
1014 out of with copies of the sign bit. Otherwise it is zeroed. */
1015 if (inter != 0 && binoptab != ashr_optab)
1016 inter = CONST0_RTX (word_mode);
1017 else if (inter != 0)
1018 inter = expand_binop (word_mode, binoptab,
1019 outof_input,
1020 GEN_INT (BITS_PER_WORD - 1),
1021 outof_target, unsignedp, next_methods);
1023 if (inter != 0 && inter != outof_target)
1024 emit_move_insn (outof_target, inter);
1026 else
1028 rtx carries;
1029 optab reverse_unsigned_shift, unsigned_shift;
1031 /* For a shift of less then BITS_PER_WORD, to compute the carry,
1032 we must do a logical shift in the opposite direction of the
1033 desired shift. */
1035 reverse_unsigned_shift = (left_shift ? lshr_optab : ashl_optab);
1037 /* For a shift of less than BITS_PER_WORD, to compute the word
1038 shifted towards, we need to unsigned shift the orig value of
1039 that word. */
1041 unsigned_shift = (left_shift ? ashl_optab : lshr_optab);
1043 carries = expand_binop (word_mode, reverse_unsigned_shift,
1044 outof_input,
1045 GEN_INT (BITS_PER_WORD - shift_count),
1046 0, unsignedp, next_methods);
1048 if (carries == 0)
1049 inter = 0;
1050 else
1051 inter = expand_binop (word_mode, unsigned_shift, into_input,
1052 op1, 0, unsignedp, next_methods);
1054 if (inter != 0)
1055 inter = expand_binop (word_mode, ior_optab, carries, inter,
1056 into_target, unsignedp, next_methods);
1058 if (inter != 0 && inter != into_target)
1059 emit_move_insn (into_target, inter);
1061 if (inter != 0)
1062 inter = expand_binop (word_mode, binoptab, outof_input,
1063 op1, outof_target, unsignedp, next_methods);
1065 if (inter != 0 && inter != outof_target)
1066 emit_move_insn (outof_target, inter);
1069 insns = get_insns ();
1070 end_sequence ();
1072 if (inter != 0)
1074 if (binoptab->code != UNKNOWN)
1075 equiv_value = gen_rtx_fmt_ee (binoptab->code, mode, op0, op1);
1076 else
1077 equiv_value = 0;
1079 emit_no_conflict_block (insns, target, op0, op1, equiv_value);
1080 return target;
1084 /* Synthesize double word rotates from single word shifts. */
1085 if ((binoptab == rotl_optab || binoptab == rotr_optab)
1086 && class == MODE_INT
1087 && GET_CODE (op1) == CONST_INT
1088 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1089 && ashl_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
1090 && lshr_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
1092 rtx insns, equiv_value;
1093 rtx into_target, outof_target;
1094 rtx into_input, outof_input;
1095 rtx inter;
1096 int shift_count, left_shift, outof_word;
1098 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1099 won't be accurate, so use a new target. */
1100 if (target == 0 || target == op0 || target == op1)
1101 target = gen_reg_rtx (mode);
1103 start_sequence ();
1105 shift_count = INTVAL (op1);
1107 /* OUTOF_* is the word we are shifting bits away from, and
1108 INTO_* is the word that we are shifting bits towards, thus
1109 they differ depending on the direction of the shift and
1110 WORDS_BIG_ENDIAN. */
1112 left_shift = (binoptab == rotl_optab);
1113 outof_word = left_shift ^ ! WORDS_BIG_ENDIAN;
1115 outof_target = operand_subword (target, outof_word, 1, mode);
1116 into_target = operand_subword (target, 1 - outof_word, 1, mode);
1118 outof_input = operand_subword_force (op0, outof_word, mode);
1119 into_input = operand_subword_force (op0, 1 - outof_word, mode);
1121 if (shift_count == BITS_PER_WORD)
1123 /* This is just a word swap. */
1124 emit_move_insn (outof_target, into_input);
1125 emit_move_insn (into_target, outof_input);
1126 inter = const0_rtx;
1128 else
1130 rtx into_temp1, into_temp2, outof_temp1, outof_temp2;
1131 rtx first_shift_count, second_shift_count;
1132 optab reverse_unsigned_shift, unsigned_shift;
1134 reverse_unsigned_shift = (left_shift ^ (shift_count < BITS_PER_WORD)
1135 ? lshr_optab : ashl_optab);
1137 unsigned_shift = (left_shift ^ (shift_count < BITS_PER_WORD)
1138 ? ashl_optab : lshr_optab);
1140 if (shift_count > BITS_PER_WORD)
1142 first_shift_count = GEN_INT (shift_count - BITS_PER_WORD);
1143 second_shift_count = GEN_INT (2 * BITS_PER_WORD - shift_count);
1145 else
1147 first_shift_count = GEN_INT (BITS_PER_WORD - shift_count);
1148 second_shift_count = GEN_INT (shift_count);
1151 into_temp1 = expand_binop (word_mode, unsigned_shift,
1152 outof_input, first_shift_count,
1153 NULL_RTX, unsignedp, next_methods);
1154 into_temp2 = expand_binop (word_mode, reverse_unsigned_shift,
1155 into_input, second_shift_count,
1156 NULL_RTX, unsignedp, next_methods);
1158 if (into_temp1 != 0 && into_temp2 != 0)
1159 inter = expand_binop (word_mode, ior_optab, into_temp1, into_temp2,
1160 into_target, unsignedp, next_methods);
1161 else
1162 inter = 0;
1164 if (inter != 0 && inter != into_target)
1165 emit_move_insn (into_target, inter);
1167 outof_temp1 = expand_binop (word_mode, unsigned_shift,
1168 into_input, first_shift_count,
1169 NULL_RTX, unsignedp, next_methods);
1170 outof_temp2 = expand_binop (word_mode, reverse_unsigned_shift,
1171 outof_input, second_shift_count,
1172 NULL_RTX, unsignedp, next_methods);
1174 if (inter != 0 && outof_temp1 != 0 && outof_temp2 != 0)
1175 inter = expand_binop (word_mode, ior_optab,
1176 outof_temp1, outof_temp2,
1177 outof_target, unsignedp, next_methods);
1179 if (inter != 0 && inter != outof_target)
1180 emit_move_insn (outof_target, inter);
1183 insns = get_insns ();
1184 end_sequence ();
1186 if (inter != 0)
1188 if (binoptab->code != UNKNOWN)
1189 equiv_value = gen_rtx_fmt_ee (binoptab->code, mode, op0, op1);
1190 else
1191 equiv_value = 0;
1193 /* We can't make this a no conflict block if this is a word swap,
1194 because the word swap case fails if the input and output values
1195 are in the same register. */
1196 if (shift_count != BITS_PER_WORD)
1197 emit_no_conflict_block (insns, target, op0, op1, equiv_value);
1198 else
1199 emit_insn (insns);
1202 return target;
1206 /* These can be done a word at a time by propagating carries. */
1207 if ((binoptab == add_optab || binoptab == sub_optab)
1208 && class == MODE_INT
1209 && GET_MODE_SIZE (mode) >= 2 * UNITS_PER_WORD
1210 && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
1212 unsigned int i;
1213 optab otheroptab = binoptab == add_optab ? sub_optab : add_optab;
1214 const unsigned int nwords = GET_MODE_BITSIZE (mode) / BITS_PER_WORD;
1215 rtx carry_in = NULL_RTX, carry_out = NULL_RTX;
1216 rtx xop0, xop1, xtarget;
1218 /* We can handle either a 1 or -1 value for the carry. If STORE_FLAG
1219 value is one of those, use it. Otherwise, use 1 since it is the
1220 one easiest to get. */
1221 #if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1
1222 int normalizep = STORE_FLAG_VALUE;
1223 #else
1224 int normalizep = 1;
1225 #endif
1227 /* Prepare the operands. */
1228 xop0 = force_reg (mode, op0);
1229 xop1 = force_reg (mode, op1);
1231 xtarget = gen_reg_rtx (mode);
1233 if (target == 0 || GET_CODE (target) != REG)
1234 target = xtarget;
1236 /* Indicate for flow that the entire target reg is being set. */
1237 if (GET_CODE (target) == REG)
1238 emit_insn (gen_rtx_CLOBBER (VOIDmode, xtarget));
1240 /* Do the actual arithmetic. */
1241 for (i = 0; i < nwords; i++)
1243 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
1244 rtx target_piece = operand_subword (xtarget, index, 1, mode);
1245 rtx op0_piece = operand_subword_force (xop0, index, mode);
1246 rtx op1_piece = operand_subword_force (xop1, index, mode);
1247 rtx x;
1249 /* Main add/subtract of the input operands. */
1250 x = expand_binop (word_mode, binoptab,
1251 op0_piece, op1_piece,
1252 target_piece, unsignedp, next_methods);
1253 if (x == 0)
1254 break;
1256 if (i + 1 < nwords)
1258 /* Store carry from main add/subtract. */
1259 carry_out = gen_reg_rtx (word_mode);
1260 carry_out = emit_store_flag_force (carry_out,
1261 (binoptab == add_optab
1262 ? LT : GT),
1263 x, op0_piece,
1264 word_mode, 1, normalizep);
1267 if (i > 0)
1269 rtx newx;
1271 /* Add/subtract previous carry to main result. */
1272 newx = expand_binop (word_mode,
1273 normalizep == 1 ? binoptab : otheroptab,
1274 x, carry_in,
1275 NULL_RTX, 1, next_methods);
1277 if (i + 1 < nwords)
1279 /* Get out carry from adding/subtracting carry in. */
1280 rtx carry_tmp = gen_reg_rtx (word_mode);
1281 carry_tmp = emit_store_flag_force (carry_tmp,
1282 (binoptab == add_optab
1283 ? LT : GT),
1284 newx, x,
1285 word_mode, 1, normalizep);
1287 /* Logical-ior the two poss. carry together. */
1288 carry_out = expand_binop (word_mode, ior_optab,
1289 carry_out, carry_tmp,
1290 carry_out, 0, next_methods);
1291 if (carry_out == 0)
1292 break;
1294 emit_move_insn (target_piece, newx);
1297 carry_in = carry_out;
1300 if (i == GET_MODE_BITSIZE (mode) / (unsigned) BITS_PER_WORD)
1302 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
1304 rtx temp = emit_move_insn (target, xtarget);
1306 set_unique_reg_note (temp,
1307 REG_EQUAL,
1308 gen_rtx_fmt_ee (binoptab->code, mode,
1309 copy_rtx (xop0),
1310 copy_rtx (xop1)));
1313 return target;
1316 else
1317 delete_insns_since (last);
1320 /* If we want to multiply two two-word values and have normal and widening
1321 multiplies of single-word values, we can do this with three smaller
1322 multiplications. Note that we do not make a REG_NO_CONFLICT block here
1323 because we are not operating on one word at a time.
1325 The multiplication proceeds as follows:
1326 _______________________
1327 [__op0_high_|__op0_low__]
1328 _______________________
1329 * [__op1_high_|__op1_low__]
1330 _______________________________________________
1331 _______________________
1332 (1) [__op0_low__*__op1_low__]
1333 _______________________
1334 (2a) [__op0_low__*__op1_high_]
1335 _______________________
1336 (2b) [__op0_high_*__op1_low__]
1337 _______________________
1338 (3) [__op0_high_*__op1_high_]
1341 This gives a 4-word result. Since we are only interested in the
1342 lower 2 words, partial result (3) and the upper words of (2a) and
1343 (2b) don't need to be calculated. Hence (2a) and (2b) can be
1344 calculated using non-widening multiplication.
1346 (1), however, needs to be calculated with an unsigned widening
1347 multiplication. If this operation is not directly supported we
1348 try using a signed widening multiplication and adjust the result.
1349 This adjustment works as follows:
1351 If both operands are positive then no adjustment is needed.
1353 If the operands have different signs, for example op0_low < 0 and
1354 op1_low >= 0, the instruction treats the most significant bit of
1355 op0_low as a sign bit instead of a bit with significance
1356 2**(BITS_PER_WORD-1), i.e. the instruction multiplies op1_low
1357 with 2**BITS_PER_WORD - op0_low, and two's complements the
1358 result. Conclusion: We need to add op1_low * 2**BITS_PER_WORD to
1359 the result.
1361 Similarly, if both operands are negative, we need to add
1362 (op0_low + op1_low) * 2**BITS_PER_WORD.
1364 We use a trick to adjust quickly. We logically shift op0_low right
1365 (op1_low) BITS_PER_WORD-1 steps to get 0 or 1, and add this to
1366 op0_high (op1_high) before it is used to calculate 2b (2a). If no
1367 logical shift exists, we do an arithmetic right shift and subtract
1368 the 0 or -1. */
1370 if (binoptab == smul_optab
1371 && class == MODE_INT
1372 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1373 && smul_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
1374 && add_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
1375 && ((umul_widen_optab->handlers[(int) mode].insn_code
1376 != CODE_FOR_nothing)
1377 || (smul_widen_optab->handlers[(int) mode].insn_code
1378 != CODE_FOR_nothing)))
1380 int low = (WORDS_BIG_ENDIAN ? 1 : 0);
1381 int high = (WORDS_BIG_ENDIAN ? 0 : 1);
1382 rtx op0_high = operand_subword_force (op0, high, mode);
1383 rtx op0_low = operand_subword_force (op0, low, mode);
1384 rtx op1_high = operand_subword_force (op1, high, mode);
1385 rtx op1_low = operand_subword_force (op1, low, mode);
1386 rtx product = 0;
1387 rtx op0_xhigh = NULL_RTX;
1388 rtx op1_xhigh = NULL_RTX;
1390 /* If the target is the same as one of the inputs, don't use it. This
1391 prevents problems with the REG_EQUAL note. */
1392 if (target == op0 || target == op1
1393 || (target != 0 && GET_CODE (target) != REG))
1394 target = 0;
1396 /* Multiply the two lower words to get a double-word product.
1397 If unsigned widening multiplication is available, use that;
1398 otherwise use the signed form and compensate. */
1400 if (umul_widen_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
1402 product = expand_binop (mode, umul_widen_optab, op0_low, op1_low,
1403 target, 1, OPTAB_DIRECT);
1405 /* If we didn't succeed, delete everything we did so far. */
1406 if (product == 0)
1407 delete_insns_since (last);
1408 else
1409 op0_xhigh = op0_high, op1_xhigh = op1_high;
1412 if (product == 0
1413 && smul_widen_optab->handlers[(int) mode].insn_code
1414 != CODE_FOR_nothing)
1416 rtx wordm1 = GEN_INT (BITS_PER_WORD - 1);
1417 product = expand_binop (mode, smul_widen_optab, op0_low, op1_low,
1418 target, 1, OPTAB_DIRECT);
1419 op0_xhigh = expand_binop (word_mode, lshr_optab, op0_low, wordm1,
1420 NULL_RTX, 1, next_methods);
1421 if (op0_xhigh)
1422 op0_xhigh = expand_binop (word_mode, add_optab, op0_high,
1423 op0_xhigh, op0_xhigh, 0, next_methods);
1424 else
1426 op0_xhigh = expand_binop (word_mode, ashr_optab, op0_low, wordm1,
1427 NULL_RTX, 0, next_methods);
1428 if (op0_xhigh)
1429 op0_xhigh = expand_binop (word_mode, sub_optab, op0_high,
1430 op0_xhigh, op0_xhigh, 0,
1431 next_methods);
1434 op1_xhigh = expand_binop (word_mode, lshr_optab, op1_low, wordm1,
1435 NULL_RTX, 1, next_methods);
1436 if (op1_xhigh)
1437 op1_xhigh = expand_binop (word_mode, add_optab, op1_high,
1438 op1_xhigh, op1_xhigh, 0, next_methods);
1439 else
1441 op1_xhigh = expand_binop (word_mode, ashr_optab, op1_low, wordm1,
1442 NULL_RTX, 0, next_methods);
1443 if (op1_xhigh)
1444 op1_xhigh = expand_binop (word_mode, sub_optab, op1_high,
1445 op1_xhigh, op1_xhigh, 0,
1446 next_methods);
1450 /* If we have been able to directly compute the product of the
1451 low-order words of the operands and perform any required adjustments
1452 of the operands, we proceed by trying two more multiplications
1453 and then computing the appropriate sum.
1455 We have checked above that the required addition is provided.
1456 Full-word addition will normally always succeed, especially if
1457 it is provided at all, so we don't worry about its failure. The
1458 multiplication may well fail, however, so we do handle that. */
1460 if (product && op0_xhigh && op1_xhigh)
1462 rtx product_high = operand_subword (product, high, 1, mode);
1463 rtx temp = expand_binop (word_mode, binoptab, op0_low, op1_xhigh,
1464 NULL_RTX, 0, OPTAB_DIRECT);
1466 if (!REG_P (product_high))
1467 product_high = force_reg (word_mode, product_high);
1469 if (temp != 0)
1470 temp = expand_binop (word_mode, add_optab, temp, product_high,
1471 product_high, 0, next_methods);
1473 if (temp != 0 && temp != product_high)
1474 emit_move_insn (product_high, temp);
1476 if (temp != 0)
1477 temp = expand_binop (word_mode, binoptab, op1_low, op0_xhigh,
1478 NULL_RTX, 0, OPTAB_DIRECT);
1480 if (temp != 0)
1481 temp = expand_binop (word_mode, add_optab, temp,
1482 product_high, product_high,
1483 0, next_methods);
1485 if (temp != 0 && temp != product_high)
1486 emit_move_insn (product_high, temp);
1488 emit_move_insn (operand_subword (product, high, 1, mode), product_high);
1490 if (temp != 0)
1492 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
1494 temp = emit_move_insn (product, product);
1495 set_unique_reg_note (temp,
1496 REG_EQUAL,
1497 gen_rtx_fmt_ee (MULT, mode,
1498 copy_rtx (op0),
1499 copy_rtx (op1)));
1502 return product;
1506 /* If we get here, we couldn't do it for some reason even though we
1507 originally thought we could. Delete anything we've emitted in
1508 trying to do it. */
1510 delete_insns_since (last);
1513 /* Open-code the vector operations if we have no hardware support
1514 for them. */
1515 if (class == MODE_VECTOR_INT || class == MODE_VECTOR_FLOAT)
1516 return expand_vector_binop (mode, binoptab, op0, op1, target,
1517 unsignedp, methods);
1519 /* We need to open-code the complex type operations: '+, -, * and /' */
1521 /* At this point we allow operations between two similar complex
1522 numbers, and also if one of the operands is not a complex number
1523 but rather of MODE_FLOAT or MODE_INT. However, the caller
1524 must make sure that the MODE of the non-complex operand matches
1525 the SUBMODE of the complex operand. */
1527 if (class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT)
1529 rtx real0 = 0, imag0 = 0;
1530 rtx real1 = 0, imag1 = 0;
1531 rtx realr, imagr, res;
1532 rtx seq;
1533 rtx equiv_value;
1534 int ok = 0;
1536 /* Find the correct mode for the real and imaginary parts */
1537 enum machine_mode submode = GET_MODE_INNER(mode);
1539 if (submode == BLKmode)
1540 abort ();
1542 if (! target)
1543 target = gen_reg_rtx (mode);
1545 start_sequence ();
1547 realr = gen_realpart (submode, target);
1548 imagr = gen_imagpart (submode, target);
1550 if (GET_MODE (op0) == mode)
1552 real0 = gen_realpart (submode, op0);
1553 imag0 = gen_imagpart (submode, op0);
1555 else
1556 real0 = op0;
1558 if (GET_MODE (op1) == mode)
1560 real1 = gen_realpart (submode, op1);
1561 imag1 = gen_imagpart (submode, op1);
1563 else
1564 real1 = op1;
1566 if (real0 == 0 || real1 == 0 || ! (imag0 != 0 || imag1 != 0))
1567 abort ();
1569 switch (binoptab->code)
1571 case PLUS:
1572 /* (a+ib) + (c+id) = (a+c) + i(b+d) */
1573 case MINUS:
1574 /* (a+ib) - (c+id) = (a-c) + i(b-d) */
1575 res = expand_binop (submode, binoptab, real0, real1,
1576 realr, unsignedp, methods);
1578 if (res == 0)
1579 break;
1580 else if (res != realr)
1581 emit_move_insn (realr, res);
1583 if (imag0 != 0 && imag1 != 0)
1584 res = expand_binop (submode, binoptab, imag0, imag1,
1585 imagr, unsignedp, methods);
1586 else if (imag0 != 0)
1587 res = imag0;
1588 else if (binoptab->code == MINUS)
1589 res = expand_unop (submode,
1590 binoptab == subv_optab ? negv_optab : neg_optab,
1591 imag1, imagr, unsignedp);
1592 else
1593 res = imag1;
1595 if (res == 0)
1596 break;
1597 else if (res != imagr)
1598 emit_move_insn (imagr, res);
1600 ok = 1;
1601 break;
1603 case MULT:
1604 /* (a+ib) * (c+id) = (ac-bd) + i(ad+cb) */
1606 if (imag0 != 0 && imag1 != 0)
1608 rtx temp1, temp2;
1610 /* Don't fetch these from memory more than once. */
1611 real0 = force_reg (submode, real0);
1612 real1 = force_reg (submode, real1);
1613 imag0 = force_reg (submode, imag0);
1614 imag1 = force_reg (submode, imag1);
1616 temp1 = expand_binop (submode, binoptab, real0, real1, NULL_RTX,
1617 unsignedp, methods);
1619 temp2 = expand_binop (submode, binoptab, imag0, imag1, NULL_RTX,
1620 unsignedp, methods);
1622 if (temp1 == 0 || temp2 == 0)
1623 break;
1625 res = (expand_binop
1626 (submode,
1627 binoptab == smulv_optab ? subv_optab : sub_optab,
1628 temp1, temp2, realr, unsignedp, methods));
1630 if (res == 0)
1631 break;
1632 else if (res != realr)
1633 emit_move_insn (realr, res);
1635 temp1 = expand_binop (submode, binoptab, real0, imag1,
1636 NULL_RTX, unsignedp, methods);
1638 temp2 = expand_binop (submode, binoptab, real1, imag0,
1639 NULL_RTX, unsignedp, methods);
1641 if (temp1 == 0 || temp2 == 0)
1642 break;
1644 res = (expand_binop
1645 (submode,
1646 binoptab == smulv_optab ? addv_optab : add_optab,
1647 temp1, temp2, imagr, unsignedp, methods));
1649 if (res == 0)
1650 break;
1651 else if (res != imagr)
1652 emit_move_insn (imagr, res);
1654 ok = 1;
1656 else
1658 /* Don't fetch these from memory more than once. */
1659 real0 = force_reg (submode, real0);
1660 real1 = force_reg (submode, real1);
1662 res = expand_binop (submode, binoptab, real0, real1,
1663 realr, unsignedp, methods);
1664 if (res == 0)
1665 break;
1666 else if (res != realr)
1667 emit_move_insn (realr, res);
1669 if (imag0 != 0)
1670 res = expand_binop (submode, binoptab,
1671 real1, imag0, imagr, unsignedp, methods);
1672 else
1673 res = expand_binop (submode, binoptab,
1674 real0, imag1, imagr, unsignedp, methods);
1676 if (res == 0)
1677 break;
1678 else if (res != imagr)
1679 emit_move_insn (imagr, res);
1681 ok = 1;
1683 break;
1685 case DIV:
1686 /* (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) */
1688 if (imag1 == 0)
1690 /* (a+ib) / (c+i0) = (a/c) + i(b/c) */
1692 /* Don't fetch these from memory more than once. */
1693 real1 = force_reg (submode, real1);
1695 /* Simply divide the real and imaginary parts by `c' */
1696 if (class == MODE_COMPLEX_FLOAT)
1697 res = expand_binop (submode, binoptab, real0, real1,
1698 realr, unsignedp, methods);
1699 else
1700 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
1701 real0, real1, realr, unsignedp);
1703 if (res == 0)
1704 break;
1705 else if (res != realr)
1706 emit_move_insn (realr, res);
1708 if (class == MODE_COMPLEX_FLOAT)
1709 res = expand_binop (submode, binoptab, imag0, real1,
1710 imagr, unsignedp, methods);
1711 else
1712 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
1713 imag0, real1, imagr, unsignedp);
1715 if (res == 0)
1716 break;
1717 else if (res != imagr)
1718 emit_move_insn (imagr, res);
1720 ok = 1;
1722 else
1724 switch (flag_complex_divide_method)
1726 case 0:
1727 ok = expand_cmplxdiv_straight (real0, real1, imag0, imag1,
1728 realr, imagr, submode,
1729 unsignedp, methods,
1730 class, binoptab);
1731 break;
1733 case 1:
1734 ok = expand_cmplxdiv_wide (real0, real1, imag0, imag1,
1735 realr, imagr, submode,
1736 unsignedp, methods,
1737 class, binoptab);
1738 break;
1740 default:
1741 abort ();
1744 break;
1746 default:
1747 abort ();
1750 seq = get_insns ();
1751 end_sequence ();
1753 if (ok)
1755 if (binoptab->code != UNKNOWN)
1756 equiv_value
1757 = gen_rtx_fmt_ee (binoptab->code, mode,
1758 copy_rtx (op0), copy_rtx (op1));
1759 else
1760 equiv_value = 0;
1762 emit_no_conflict_block (seq, target, op0, op1, equiv_value);
1764 return target;
1768 /* It can't be open-coded in this mode.
1769 Use a library call if one is available and caller says that's ok. */
1771 if (binoptab->handlers[(int) mode].libfunc
1772 && (methods == OPTAB_LIB || methods == OPTAB_LIB_WIDEN))
1774 rtx insns;
1775 rtx op1x = op1;
1776 enum machine_mode op1_mode = mode;
1777 rtx value;
1779 start_sequence ();
1781 if (shift_op)
1783 op1_mode = word_mode;
1784 /* Specify unsigned here,
1785 since negative shift counts are meaningless. */
1786 op1x = convert_to_mode (word_mode, op1, 1);
1789 if (GET_MODE (op0) != VOIDmode
1790 && GET_MODE (op0) != mode)
1791 op0 = convert_to_mode (mode, op0, unsignedp);
1793 /* Pass 1 for NO_QUEUE so we don't lose any increments
1794 if the libcall is cse'd or moved. */
1795 value = emit_library_call_value (binoptab->handlers[(int) mode].libfunc,
1796 NULL_RTX, LCT_CONST, mode, 2,
1797 op0, mode, op1x, op1_mode);
1799 insns = get_insns ();
1800 end_sequence ();
1802 target = gen_reg_rtx (mode);
1803 emit_libcall_block (insns, target, value,
1804 gen_rtx_fmt_ee (binoptab->code, mode, op0, op1));
1806 return target;
1809 delete_insns_since (last);
1811 /* It can't be done in this mode. Can we do it in a wider mode? */
1813 if (! (methods == OPTAB_WIDEN || methods == OPTAB_LIB_WIDEN
1814 || methods == OPTAB_MUST_WIDEN))
1816 /* Caller says, don't even try. */
1817 delete_insns_since (entry_last);
1818 return 0;
1821 /* Compute the value of METHODS to pass to recursive calls.
1822 Don't allow widening to be tried recursively. */
1824 methods = (methods == OPTAB_LIB_WIDEN ? OPTAB_LIB : OPTAB_DIRECT);
1826 /* Look for a wider mode of the same class for which it appears we can do
1827 the operation. */
1829 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
1831 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
1832 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
1834 if ((binoptab->handlers[(int) wider_mode].insn_code
1835 != CODE_FOR_nothing)
1836 || (methods == OPTAB_LIB
1837 && binoptab->handlers[(int) wider_mode].libfunc))
1839 rtx xop0 = op0, xop1 = op1;
1840 int no_extend = 0;
1842 /* For certain integer operations, we need not actually extend
1843 the narrow operands, as long as we will truncate
1844 the results to the same narrowness. */
1846 if ((binoptab == ior_optab || binoptab == and_optab
1847 || binoptab == xor_optab
1848 || binoptab == add_optab || binoptab == sub_optab
1849 || binoptab == smul_optab || binoptab == ashl_optab)
1850 && class == MODE_INT)
1851 no_extend = 1;
1853 xop0 = widen_operand (xop0, wider_mode, mode,
1854 unsignedp, no_extend);
1856 /* The second operand of a shift must always be extended. */
1857 xop1 = widen_operand (xop1, wider_mode, mode, unsignedp,
1858 no_extend && binoptab != ashl_optab);
1860 temp = expand_binop (wider_mode, binoptab, xop0, xop1, NULL_RTX,
1861 unsignedp, methods);
1862 if (temp)
1864 if (class != MODE_INT)
1866 if (target == 0)
1867 target = gen_reg_rtx (mode);
1868 convert_move (target, temp, 0);
1869 return target;
1871 else
1872 return gen_lowpart (mode, temp);
1874 else
1875 delete_insns_since (last);
1880 delete_insns_since (entry_last);
1881 return 0;
1884 /* Like expand_binop, but for open-coding vectors binops. */
1886 static rtx
1887 expand_vector_binop (mode, binoptab, op0, op1, target, unsignedp, methods)
1888 enum machine_mode mode;
1889 optab binoptab;
1890 rtx op0, op1;
1891 rtx target;
1892 int unsignedp;
1893 enum optab_methods methods;
1895 enum machine_mode submode, tmode;
1896 int size, elts, subsize, subbitsize, i;
1897 rtx t, a, b, res, seq;
1898 enum mode_class class;
1900 class = GET_MODE_CLASS (mode);
1902 size = GET_MODE_SIZE (mode);
1903 submode = GET_MODE_INNER (mode);
1905 /* Search for the widest vector mode with the same inner mode that is
1906 still narrower than MODE and that allows to open-code this operator.
1907 Note, if we find such a mode and the handler later decides it can't
1908 do the expansion, we'll be called recursively with the narrower mode. */
1909 for (tmode = GET_CLASS_NARROWEST_MODE (class);
1910 GET_MODE_SIZE (tmode) < GET_MODE_SIZE (mode);
1911 tmode = GET_MODE_WIDER_MODE (tmode))
1913 if (GET_MODE_INNER (tmode) == GET_MODE_INNER (mode)
1914 && binoptab->handlers[(int) tmode].insn_code != CODE_FOR_nothing)
1915 submode = tmode;
1918 switch (binoptab->code)
1920 case AND:
1921 case IOR:
1922 case XOR:
1923 tmode = int_mode_for_mode (mode);
1924 if (tmode != BLKmode)
1925 submode = tmode;
1926 case PLUS:
1927 case MINUS:
1928 case MULT:
1929 case DIV:
1930 subsize = GET_MODE_SIZE (submode);
1931 subbitsize = GET_MODE_BITSIZE (submode);
1932 elts = size / subsize;
1934 /* If METHODS is OPTAB_DIRECT, we don't insist on the exact mode,
1935 but that we operate on more than one element at a time. */
1936 if (subsize == GET_MODE_UNIT_SIZE (mode) && methods == OPTAB_DIRECT)
1937 return 0;
1939 start_sequence ();
1941 /* Errors can leave us with a const0_rtx as operand. */
1942 if (GET_MODE (op0) != mode)
1943 op0 = copy_to_mode_reg (mode, op0);
1944 if (GET_MODE (op1) != mode)
1945 op1 = copy_to_mode_reg (mode, op1);
1947 if (!target)
1948 target = gen_reg_rtx (mode);
1950 for (i = 0; i < elts; ++i)
1952 /* If this is part of a register, and not the first item in the
1953 word, we can't store using a SUBREG - that would clobber
1954 previous results.
1955 And storing with a SUBREG is only possible for the least
1956 significant part, hence we can't do it for big endian
1957 (unless we want to permute the evaluation order. */
1958 if (GET_CODE (target) == REG
1959 && (BYTES_BIG_ENDIAN
1960 ? subsize < UNITS_PER_WORD
1961 : ((i * subsize) % UNITS_PER_WORD) != 0))
1962 t = NULL_RTX;
1963 else
1964 t = simplify_gen_subreg (submode, target, mode, i * subsize);
1965 if (CONSTANT_P (op0))
1966 a = simplify_gen_subreg (submode, op0, mode, i * subsize);
1967 else
1968 a = extract_bit_field (op0, subbitsize, i * subbitsize, unsignedp,
1969 NULL_RTX, submode, submode, size);
1970 if (CONSTANT_P (op1))
1971 b = simplify_gen_subreg (submode, op1, mode, i * subsize);
1972 else
1973 b = extract_bit_field (op1, subbitsize, i * subbitsize, unsignedp,
1974 NULL_RTX, submode, submode, size);
1976 if (binoptab->code == DIV)
1978 if (class == MODE_VECTOR_FLOAT)
1979 res = expand_binop (submode, binoptab, a, b, t,
1980 unsignedp, methods);
1981 else
1982 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
1983 a, b, t, unsignedp);
1985 else
1986 res = expand_binop (submode, binoptab, a, b, t,
1987 unsignedp, methods);
1989 if (res == 0)
1990 break;
1992 if (t)
1993 emit_move_insn (t, res);
1994 else
1995 store_bit_field (target, subbitsize, i * subbitsize, submode, res,
1996 size);
1998 break;
2000 default:
2001 abort ();
2004 seq = get_insns ();
2005 end_sequence ();
2006 emit_insn (seq);
2008 return target;
2011 /* Like expand_unop but for open-coding vector unops. */
2013 static rtx
2014 expand_vector_unop (mode, unoptab, op0, target, unsignedp)
2015 enum machine_mode mode;
2016 optab unoptab;
2017 rtx op0;
2018 rtx target;
2019 int unsignedp;
2021 enum machine_mode submode, tmode;
2022 int size, elts, subsize, subbitsize, i;
2023 rtx t, a, res, seq;
2025 size = GET_MODE_SIZE (mode);
2026 submode = GET_MODE_INNER (mode);
2028 /* Search for the widest vector mode with the same inner mode that is
2029 still narrower than MODE and that allows to open-code this operator.
2030 Note, if we find such a mode and the handler later decides it can't
2031 do the expansion, we'll be called recursively with the narrower mode. */
2032 for (tmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (mode));
2033 GET_MODE_SIZE (tmode) < GET_MODE_SIZE (mode);
2034 tmode = GET_MODE_WIDER_MODE (tmode))
2036 if (GET_MODE_INNER (tmode) == GET_MODE_INNER (mode)
2037 && unoptab->handlers[(int) tmode].insn_code != CODE_FOR_nothing)
2038 submode = tmode;
2040 /* If there is no negate operation, try doing a subtract from zero. */
2041 if (unoptab == neg_optab && GET_MODE_CLASS (submode) == MODE_INT
2042 /* Avoid infinite recursion when an
2043 error has left us with the wrong mode. */
2044 && GET_MODE (op0) == mode)
2046 rtx temp;
2047 temp = expand_binop (mode, sub_optab, CONST0_RTX (mode), op0,
2048 target, unsignedp, OPTAB_DIRECT);
2049 if (temp)
2050 return temp;
2053 if (unoptab == one_cmpl_optab)
2055 tmode = int_mode_for_mode (mode);
2056 if (tmode != BLKmode)
2057 submode = tmode;
2060 subsize = GET_MODE_SIZE (submode);
2061 subbitsize = GET_MODE_BITSIZE (submode);
2062 elts = size / subsize;
2064 /* Errors can leave us with a const0_rtx as operand. */
2065 if (GET_MODE (op0) != mode)
2066 op0 = copy_to_mode_reg (mode, op0);
2068 if (!target)
2069 target = gen_reg_rtx (mode);
2071 start_sequence ();
2073 for (i = 0; i < elts; ++i)
2075 /* If this is part of a register, and not the first item in the
2076 word, we can't store using a SUBREG - that would clobber
2077 previous results.
2078 And storing with a SUBREG is only possible for the least
2079 significant part, hence we can't do it for big endian
2080 (unless we want to permute the evaluation order. */
2081 if (GET_CODE (target) == REG
2082 && (BYTES_BIG_ENDIAN
2083 ? subsize < UNITS_PER_WORD
2084 : ((i * subsize) % UNITS_PER_WORD) != 0))
2085 t = NULL_RTX;
2086 else
2087 t = simplify_gen_subreg (submode, target, mode, i * subsize);
2088 if (CONSTANT_P (op0))
2089 a = simplify_gen_subreg (submode, op0, mode, i * subsize);
2090 else
2091 a = extract_bit_field (op0, subbitsize, i * subbitsize, unsignedp,
2092 t, submode, submode, size);
2094 res = expand_unop (submode, unoptab, a, t, unsignedp);
2096 if (t)
2097 emit_move_insn (t, res);
2098 else
2099 store_bit_field (target, subbitsize, i * subbitsize, submode, res,
2100 size);
2103 seq = get_insns ();
2104 end_sequence ();
2105 emit_insn (seq);
2107 return target;
2110 /* Expand a binary operator which has both signed and unsigned forms.
2111 UOPTAB is the optab for unsigned operations, and SOPTAB is for
2112 signed operations.
2114 If we widen unsigned operands, we may use a signed wider operation instead
2115 of an unsigned wider operation, since the result would be the same. */
2118 sign_expand_binop (mode, uoptab, soptab, op0, op1, target, unsignedp, methods)
2119 enum machine_mode mode;
2120 optab uoptab, soptab;
2121 rtx op0, op1, target;
2122 int unsignedp;
2123 enum optab_methods methods;
2125 rtx temp;
2126 optab direct_optab = unsignedp ? uoptab : soptab;
2127 struct optab wide_soptab;
2129 /* Do it without widening, if possible. */
2130 temp = expand_binop (mode, direct_optab, op0, op1, target,
2131 unsignedp, OPTAB_DIRECT);
2132 if (temp || methods == OPTAB_DIRECT)
2133 return temp;
2135 /* Try widening to a signed int. Make a fake signed optab that
2136 hides any signed insn for direct use. */
2137 wide_soptab = *soptab;
2138 wide_soptab.handlers[(int) mode].insn_code = CODE_FOR_nothing;
2139 wide_soptab.handlers[(int) mode].libfunc = 0;
2141 temp = expand_binop (mode, &wide_soptab, op0, op1, target,
2142 unsignedp, OPTAB_WIDEN);
2144 /* For unsigned operands, try widening to an unsigned int. */
2145 if (temp == 0 && unsignedp)
2146 temp = expand_binop (mode, uoptab, op0, op1, target,
2147 unsignedp, OPTAB_WIDEN);
2148 if (temp || methods == OPTAB_WIDEN)
2149 return temp;
2151 /* Use the right width lib call if that exists. */
2152 temp = expand_binop (mode, direct_optab, op0, op1, target, unsignedp, OPTAB_LIB);
2153 if (temp || methods == OPTAB_LIB)
2154 return temp;
2156 /* Must widen and use a lib call, use either signed or unsigned. */
2157 temp = expand_binop (mode, &wide_soptab, op0, op1, target,
2158 unsignedp, methods);
2159 if (temp != 0)
2160 return temp;
2161 if (unsignedp)
2162 return expand_binop (mode, uoptab, op0, op1, target,
2163 unsignedp, methods);
2164 return 0;
2167 /* Generate code to perform an operation specified by BINOPTAB
2168 on operands OP0 and OP1, with two results to TARG1 and TARG2.
2169 We assume that the order of the operands for the instruction
2170 is TARG0, OP0, OP1, TARG1, which would fit a pattern like
2171 [(set TARG0 (operate OP0 OP1)) (set TARG1 (operate ...))].
2173 Either TARG0 or TARG1 may be zero, but what that means is that
2174 the result is not actually wanted. We will generate it into
2175 a dummy pseudo-reg and discard it. They may not both be zero.
2177 Returns 1 if this operation can be performed; 0 if not. */
2180 expand_twoval_binop (binoptab, op0, op1, targ0, targ1, unsignedp)
2181 optab binoptab;
2182 rtx op0, op1;
2183 rtx targ0, targ1;
2184 int unsignedp;
2186 enum machine_mode mode = GET_MODE (targ0 ? targ0 : targ1);
2187 enum mode_class class;
2188 enum machine_mode wider_mode;
2189 rtx entry_last = get_last_insn ();
2190 rtx last;
2192 class = GET_MODE_CLASS (mode);
2194 op0 = protect_from_queue (op0, 0);
2195 op1 = protect_from_queue (op1, 0);
2197 if (flag_force_mem)
2199 op0 = force_not_mem (op0);
2200 op1 = force_not_mem (op1);
2203 /* If we are inside an appropriately-short loop and one operand is an
2204 expensive constant, force it into a register. */
2205 if (CONSTANT_P (op0) && preserve_subexpressions_p ()
2206 && rtx_cost (op0, binoptab->code) > COSTS_N_INSNS (1))
2207 op0 = force_reg (mode, op0);
2209 if (CONSTANT_P (op1) && preserve_subexpressions_p ()
2210 && rtx_cost (op1, binoptab->code) > COSTS_N_INSNS (1))
2211 op1 = force_reg (mode, op1);
2213 if (targ0)
2214 targ0 = protect_from_queue (targ0, 1);
2215 else
2216 targ0 = gen_reg_rtx (mode);
2217 if (targ1)
2218 targ1 = protect_from_queue (targ1, 1);
2219 else
2220 targ1 = gen_reg_rtx (mode);
2222 /* Record where to go back to if we fail. */
2223 last = get_last_insn ();
2225 if (binoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2227 int icode = (int) binoptab->handlers[(int) mode].insn_code;
2228 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2229 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
2230 rtx pat;
2231 rtx xop0 = op0, xop1 = op1;
2233 /* In case the insn wants input operands in modes different from
2234 those of the actual operands, convert the operands. It would
2235 seem that we don't need to convert CONST_INTs, but we do, so
2236 that they're properly zero-extended, sign-extended or truncated
2237 for their mode. */
2239 if (GET_MODE (op0) != mode0 && mode0 != VOIDmode)
2240 xop0 = convert_modes (mode0,
2241 GET_MODE (op0) != VOIDmode
2242 ? GET_MODE (op0)
2243 : mode,
2244 xop0, unsignedp);
2246 if (GET_MODE (op1) != mode1 && mode1 != VOIDmode)
2247 xop1 = convert_modes (mode1,
2248 GET_MODE (op1) != VOIDmode
2249 ? GET_MODE (op1)
2250 : mode,
2251 xop1, unsignedp);
2253 /* Now, if insn doesn't accept these operands, put them into pseudos. */
2254 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0))
2255 xop0 = copy_to_mode_reg (mode0, xop0);
2257 if (! (*insn_data[icode].operand[2].predicate) (xop1, mode1))
2258 xop1 = copy_to_mode_reg (mode1, xop1);
2260 /* We could handle this, but we should always be called with a pseudo
2261 for our targets and all insns should take them as outputs. */
2262 if (! (*insn_data[icode].operand[0].predicate) (targ0, mode)
2263 || ! (*insn_data[icode].operand[3].predicate) (targ1, mode))
2264 abort ();
2266 pat = GEN_FCN (icode) (targ0, xop0, xop1, targ1);
2267 if (pat)
2269 emit_insn (pat);
2270 return 1;
2272 else
2273 delete_insns_since (last);
2276 /* It can't be done in this mode. Can we do it in a wider mode? */
2278 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2280 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2281 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2283 if (binoptab->handlers[(int) wider_mode].insn_code
2284 != CODE_FOR_nothing)
2286 rtx t0 = gen_reg_rtx (wider_mode);
2287 rtx t1 = gen_reg_rtx (wider_mode);
2288 rtx cop0 = convert_modes (wider_mode, mode, op0, unsignedp);
2289 rtx cop1 = convert_modes (wider_mode, mode, op1, unsignedp);
2291 if (expand_twoval_binop (binoptab, cop0, cop1,
2292 t0, t1, unsignedp))
2294 convert_move (targ0, t0, unsignedp);
2295 convert_move (targ1, t1, unsignedp);
2296 return 1;
2298 else
2299 delete_insns_since (last);
2304 delete_insns_since (entry_last);
2305 return 0;
2308 /* Wrapper around expand_unop which takes an rtx code to specify
2309 the operation to perform, not an optab pointer. All other
2310 arguments are the same. */
2312 expand_simple_unop (mode, code, op0, target, unsignedp)
2313 enum machine_mode mode;
2314 enum rtx_code code;
2315 rtx op0;
2316 rtx target;
2317 int unsignedp;
2319 optab unop = code_to_optab[(int) code];
2320 if (unop == 0)
2321 abort ();
2323 return expand_unop (mode, unop, op0, target, unsignedp);
2326 /* Generate code to perform an operation specified by UNOPTAB
2327 on operand OP0, with result having machine-mode MODE.
2329 UNSIGNEDP is for the case where we have to widen the operands
2330 to perform the operation. It says to use zero-extension.
2332 If TARGET is nonzero, the value
2333 is generated there, if it is convenient to do so.
2334 In all cases an rtx is returned for the locus of the value;
2335 this may or may not be TARGET. */
2338 expand_unop (mode, unoptab, op0, target, unsignedp)
2339 enum machine_mode mode;
2340 optab unoptab;
2341 rtx op0;
2342 rtx target;
2343 int unsignedp;
2345 enum mode_class class;
2346 enum machine_mode wider_mode;
2347 rtx temp;
2348 rtx last = get_last_insn ();
2349 rtx pat;
2351 class = GET_MODE_CLASS (mode);
2353 op0 = protect_from_queue (op0, 0);
2355 if (flag_force_mem)
2357 op0 = force_not_mem (op0);
2360 if (target)
2361 target = protect_from_queue (target, 1);
2363 if (unoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2365 int icode = (int) unoptab->handlers[(int) mode].insn_code;
2366 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2367 rtx xop0 = op0;
2369 if (target)
2370 temp = target;
2371 else
2372 temp = gen_reg_rtx (mode);
2374 if (GET_MODE (xop0) != VOIDmode
2375 && GET_MODE (xop0) != mode0)
2376 xop0 = convert_to_mode (mode0, xop0, unsignedp);
2378 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
2380 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0))
2381 xop0 = copy_to_mode_reg (mode0, xop0);
2383 if (! (*insn_data[icode].operand[0].predicate) (temp, mode))
2384 temp = gen_reg_rtx (mode);
2386 pat = GEN_FCN (icode) (temp, xop0);
2387 if (pat)
2389 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX
2390 && ! add_equal_note (pat, temp, unoptab->code, xop0, NULL_RTX))
2392 delete_insns_since (last);
2393 return expand_unop (mode, unoptab, op0, NULL_RTX, unsignedp);
2396 emit_insn (pat);
2398 return temp;
2400 else
2401 delete_insns_since (last);
2404 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2406 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2407 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2408 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2410 if (unoptab->handlers[(int) wider_mode].insn_code != CODE_FOR_nothing)
2412 rtx xop0 = op0;
2414 /* For certain operations, we need not actually extend
2415 the narrow operand, as long as we will truncate the
2416 results to the same narrowness. */
2418 xop0 = widen_operand (xop0, wider_mode, mode, unsignedp,
2419 (unoptab == neg_optab
2420 || unoptab == one_cmpl_optab)
2421 && class == MODE_INT);
2423 temp = expand_unop (wider_mode, unoptab, xop0, NULL_RTX,
2424 unsignedp);
2426 if (temp)
2428 if (class != MODE_INT)
2430 if (target == 0)
2431 target = gen_reg_rtx (mode);
2432 convert_move (target, temp, 0);
2433 return target;
2435 else
2436 return gen_lowpart (mode, temp);
2438 else
2439 delete_insns_since (last);
2443 /* These can be done a word at a time. */
2444 if (unoptab == one_cmpl_optab
2445 && class == MODE_INT
2446 && GET_MODE_SIZE (mode) > UNITS_PER_WORD
2447 && unoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
2449 int i;
2450 rtx insns;
2452 if (target == 0 || target == op0)
2453 target = gen_reg_rtx (mode);
2455 start_sequence ();
2457 /* Do the actual arithmetic. */
2458 for (i = 0; i < GET_MODE_BITSIZE (mode) / BITS_PER_WORD; i++)
2460 rtx target_piece = operand_subword (target, i, 1, mode);
2461 rtx x = expand_unop (word_mode, unoptab,
2462 operand_subword_force (op0, i, mode),
2463 target_piece, unsignedp);
2465 if (target_piece != x)
2466 emit_move_insn (target_piece, x);
2469 insns = get_insns ();
2470 end_sequence ();
2472 emit_no_conflict_block (insns, target, op0, NULL_RTX,
2473 gen_rtx_fmt_e (unoptab->code, mode,
2474 copy_rtx (op0)));
2475 return target;
2478 /* Open-code the complex negation operation. */
2479 else if (unoptab->code == NEG
2480 && (class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT))
2482 rtx target_piece;
2483 rtx x;
2484 rtx seq;
2486 /* Find the correct mode for the real and imaginary parts */
2487 enum machine_mode submode = GET_MODE_INNER (mode);
2489 if (submode == BLKmode)
2490 abort ();
2492 if (target == 0)
2493 target = gen_reg_rtx (mode);
2495 start_sequence ();
2497 target_piece = gen_imagpart (submode, target);
2498 x = expand_unop (submode, unoptab,
2499 gen_imagpart (submode, op0),
2500 target_piece, unsignedp);
2501 if (target_piece != x)
2502 emit_move_insn (target_piece, x);
2504 target_piece = gen_realpart (submode, target);
2505 x = expand_unop (submode, unoptab,
2506 gen_realpart (submode, op0),
2507 target_piece, unsignedp);
2508 if (target_piece != x)
2509 emit_move_insn (target_piece, x);
2511 seq = get_insns ();
2512 end_sequence ();
2514 emit_no_conflict_block (seq, target, op0, 0,
2515 gen_rtx_fmt_e (unoptab->code, mode,
2516 copy_rtx (op0)));
2517 return target;
2520 /* Try negating floating point values by flipping the sign bit. */
2521 if (unoptab->code == NEG && class == MODE_FLOAT
2522 && GET_MODE_BITSIZE (mode) <= 2 * HOST_BITS_PER_WIDE_INT)
2524 const struct real_format *fmt = real_format_for_mode[mode - QFmode];
2525 enum machine_mode imode = int_mode_for_mode (mode);
2526 int bitpos = (fmt != 0) ? fmt->signbit : -1;
2528 if (imode != BLKmode && bitpos >= 0 && fmt->has_signed_zero)
2530 HOST_WIDE_INT hi, lo;
2531 rtx last = get_last_insn ();
2533 if (bitpos < HOST_BITS_PER_WIDE_INT)
2535 hi = 0;
2536 lo = (HOST_WIDE_INT) 1 << bitpos;
2538 else
2540 hi = (HOST_WIDE_INT) 1 << (bitpos - HOST_BITS_PER_WIDE_INT);
2541 lo = 0;
2543 temp = expand_binop (imode, xor_optab,
2544 gen_lowpart (imode, op0),
2545 immed_double_const (lo, hi, imode),
2546 NULL_RTX, 1, OPTAB_LIB_WIDEN);
2547 if (temp != 0)
2548 return gen_lowpart (mode, temp);
2549 delete_insns_since (last);
2553 /* Now try a library call in this mode. */
2554 if (unoptab->handlers[(int) mode].libfunc)
2556 rtx insns;
2557 rtx value;
2559 start_sequence ();
2561 /* Pass 1 for NO_QUEUE so we don't lose any increments
2562 if the libcall is cse'd or moved. */
2563 value = emit_library_call_value (unoptab->handlers[(int) mode].libfunc,
2564 NULL_RTX, LCT_CONST, mode, 1, op0, mode);
2565 insns = get_insns ();
2566 end_sequence ();
2568 target = gen_reg_rtx (mode);
2569 emit_libcall_block (insns, target, value,
2570 gen_rtx_fmt_e (unoptab->code, mode, op0));
2572 return target;
2575 if (class == MODE_VECTOR_FLOAT || class == MODE_VECTOR_INT)
2576 return expand_vector_unop (mode, unoptab, op0, target, unsignedp);
2578 /* It can't be done in this mode. Can we do it in a wider mode? */
2580 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2582 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2583 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2585 if ((unoptab->handlers[(int) wider_mode].insn_code
2586 != CODE_FOR_nothing)
2587 || unoptab->handlers[(int) wider_mode].libfunc)
2589 rtx xop0 = op0;
2591 /* For certain operations, we need not actually extend
2592 the narrow operand, as long as we will truncate the
2593 results to the same narrowness. */
2595 xop0 = widen_operand (xop0, wider_mode, mode, unsignedp,
2596 (unoptab == neg_optab
2597 || unoptab == one_cmpl_optab)
2598 && class == MODE_INT);
2600 temp = expand_unop (wider_mode, unoptab, xop0, NULL_RTX,
2601 unsignedp);
2603 if (temp)
2605 if (class != MODE_INT)
2607 if (target == 0)
2608 target = gen_reg_rtx (mode);
2609 convert_move (target, temp, 0);
2610 return target;
2612 else
2613 return gen_lowpart (mode, temp);
2615 else
2616 delete_insns_since (last);
2621 /* If there is no negate operation, try doing a subtract from zero.
2622 The US Software GOFAST library needs this. */
2623 if (unoptab->code == NEG)
2625 rtx temp;
2626 temp = expand_binop (mode,
2627 unoptab == negv_optab ? subv_optab : sub_optab,
2628 CONST0_RTX (mode), op0,
2629 target, unsignedp, OPTAB_LIB_WIDEN);
2630 if (temp)
2631 return temp;
2634 return 0;
2637 /* Emit code to compute the absolute value of OP0, with result to
2638 TARGET if convenient. (TARGET may be 0.) The return value says
2639 where the result actually is to be found.
2641 MODE is the mode of the operand; the mode of the result is
2642 different but can be deduced from MODE.
2647 expand_abs (mode, op0, target, result_unsignedp, safe)
2648 enum machine_mode mode;
2649 rtx op0;
2650 rtx target;
2651 int result_unsignedp;
2652 int safe;
2654 rtx temp, op1;
2656 if (! flag_trapv)
2657 result_unsignedp = 1;
2659 /* First try to do it with a special abs instruction. */
2660 temp = expand_unop (mode, result_unsignedp ? abs_optab : absv_optab,
2661 op0, target, 0);
2662 if (temp != 0)
2663 return temp;
2665 /* For floating point modes, try clearing the sign bit. */
2666 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2667 && GET_MODE_BITSIZE (mode) <= 2 * HOST_BITS_PER_WIDE_INT)
2669 const struct real_format *fmt = real_format_for_mode[mode - QFmode];
2670 enum machine_mode imode = int_mode_for_mode (mode);
2671 int bitpos = (fmt != 0) ? fmt->signbit : -1;
2673 if (imode != BLKmode && bitpos >= 0)
2675 HOST_WIDE_INT hi, lo;
2676 rtx last = get_last_insn ();
2678 if (bitpos < HOST_BITS_PER_WIDE_INT)
2680 hi = 0;
2681 lo = (HOST_WIDE_INT) 1 << bitpos;
2683 else
2685 hi = (HOST_WIDE_INT) 1 << (bitpos - HOST_BITS_PER_WIDE_INT);
2686 lo = 0;
2688 temp = expand_binop (imode, and_optab,
2689 gen_lowpart (imode, op0),
2690 immed_double_const (~lo, ~hi, imode),
2691 NULL_RTX, 1, OPTAB_LIB_WIDEN);
2692 if (temp != 0)
2693 return gen_lowpart (mode, temp);
2694 delete_insns_since (last);
2698 /* If we have a MAX insn, we can do this as MAX (x, -x). */
2699 if (smax_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2701 rtx last = get_last_insn ();
2703 temp = expand_unop (mode, neg_optab, op0, NULL_RTX, 0);
2704 if (temp != 0)
2705 temp = expand_binop (mode, smax_optab, op0, temp, target, 0,
2706 OPTAB_WIDEN);
2708 if (temp != 0)
2709 return temp;
2711 delete_insns_since (last);
2714 /* If this machine has expensive jumps, we can do integer absolute
2715 value of X as (((signed) x >> (W-1)) ^ x) - ((signed) x >> (W-1)),
2716 where W is the width of MODE. */
2718 if (GET_MODE_CLASS (mode) == MODE_INT && BRANCH_COST >= 2)
2720 rtx extended = expand_shift (RSHIFT_EXPR, mode, op0,
2721 size_int (GET_MODE_BITSIZE (mode) - 1),
2722 NULL_RTX, 0);
2724 temp = expand_binop (mode, xor_optab, extended, op0, target, 0,
2725 OPTAB_LIB_WIDEN);
2726 if (temp != 0)
2727 temp = expand_binop (mode, result_unsignedp ? sub_optab : subv_optab,
2728 temp, extended, target, 0, OPTAB_LIB_WIDEN);
2730 if (temp != 0)
2731 return temp;
2734 /* If that does not win, use conditional jump and negate. */
2736 /* It is safe to use the target if it is the same
2737 as the source if this is also a pseudo register */
2738 if (op0 == target && GET_CODE (op0) == REG
2739 && REGNO (op0) >= FIRST_PSEUDO_REGISTER)
2740 safe = 1;
2742 op1 = gen_label_rtx ();
2743 if (target == 0 || ! safe
2744 || GET_MODE (target) != mode
2745 || (GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
2746 || (GET_CODE (target) == REG
2747 && REGNO (target) < FIRST_PSEUDO_REGISTER))
2748 target = gen_reg_rtx (mode);
2750 emit_move_insn (target, op0);
2751 NO_DEFER_POP;
2753 /* If this mode is an integer too wide to compare properly,
2754 compare word by word. Rely on CSE to optimize constant cases. */
2755 if (GET_MODE_CLASS (mode) == MODE_INT
2756 && ! can_compare_p (GE, mode, ccp_jump))
2757 do_jump_by_parts_greater_rtx (mode, 0, target, const0_rtx,
2758 NULL_RTX, op1);
2759 else
2760 do_compare_rtx_and_jump (target, CONST0_RTX (mode), GE, 0, mode,
2761 NULL_RTX, NULL_RTX, op1);
2763 op0 = expand_unop (mode, result_unsignedp ? neg_optab : negv_optab,
2764 target, target, 0);
2765 if (op0 != target)
2766 emit_move_insn (target, op0);
2767 emit_label (op1);
2768 OK_DEFER_POP;
2769 return target;
2772 /* Emit code to compute the absolute value of OP0, with result to
2773 TARGET if convenient. (TARGET may be 0.) The return value says
2774 where the result actually is to be found.
2776 MODE is the mode of the operand; the mode of the result is
2777 different but can be deduced from MODE.
2779 UNSIGNEDP is relevant for complex integer modes. */
2782 expand_complex_abs (mode, op0, target, unsignedp)
2783 enum machine_mode mode;
2784 rtx op0;
2785 rtx target;
2786 int unsignedp;
2788 enum mode_class class = GET_MODE_CLASS (mode);
2789 enum machine_mode wider_mode;
2790 rtx temp;
2791 rtx entry_last = get_last_insn ();
2792 rtx last;
2793 rtx pat;
2794 optab this_abs_optab;
2796 /* Find the correct mode for the real and imaginary parts. */
2797 enum machine_mode submode = GET_MODE_INNER (mode);
2799 if (submode == BLKmode)
2800 abort ();
2802 op0 = protect_from_queue (op0, 0);
2804 if (flag_force_mem)
2806 op0 = force_not_mem (op0);
2809 last = get_last_insn ();
2811 if (target)
2812 target = protect_from_queue (target, 1);
2814 this_abs_optab = ! unsignedp && flag_trapv
2815 && (GET_MODE_CLASS(mode) == MODE_INT)
2816 ? absv_optab : abs_optab;
2818 if (this_abs_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2820 int icode = (int) this_abs_optab->handlers[(int) mode].insn_code;
2821 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2822 rtx xop0 = op0;
2824 if (target)
2825 temp = target;
2826 else
2827 temp = gen_reg_rtx (submode);
2829 if (GET_MODE (xop0) != VOIDmode
2830 && GET_MODE (xop0) != mode0)
2831 xop0 = convert_to_mode (mode0, xop0, unsignedp);
2833 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
2835 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0))
2836 xop0 = copy_to_mode_reg (mode0, xop0);
2838 if (! (*insn_data[icode].operand[0].predicate) (temp, submode))
2839 temp = gen_reg_rtx (submode);
2841 pat = GEN_FCN (icode) (temp, xop0);
2842 if (pat)
2844 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX
2845 && ! add_equal_note (pat, temp, this_abs_optab->code, xop0,
2846 NULL_RTX))
2848 delete_insns_since (last);
2849 return expand_unop (mode, this_abs_optab, op0, NULL_RTX,
2850 unsignedp);
2853 emit_insn (pat);
2855 return temp;
2857 else
2858 delete_insns_since (last);
2861 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2863 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2864 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2866 if (this_abs_optab->handlers[(int) wider_mode].insn_code
2867 != CODE_FOR_nothing)
2869 rtx xop0 = op0;
2871 xop0 = convert_modes (wider_mode, mode, xop0, unsignedp);
2872 temp = expand_complex_abs (wider_mode, xop0, NULL_RTX, unsignedp);
2874 if (temp)
2876 if (class != MODE_COMPLEX_INT)
2878 if (target == 0)
2879 target = gen_reg_rtx (submode);
2880 convert_move (target, temp, 0);
2881 return target;
2883 else
2884 return gen_lowpart (submode, temp);
2886 else
2887 delete_insns_since (last);
2891 /* Open-code the complex absolute-value operation
2892 if we can open-code sqrt. Otherwise it's not worth while. */
2893 if (sqrt_optab->handlers[(int) submode].insn_code != CODE_FOR_nothing
2894 && ! flag_trapv)
2896 rtx real, imag, total;
2898 real = gen_realpart (submode, op0);
2899 imag = gen_imagpart (submode, op0);
2901 /* Square both parts. */
2902 real = expand_mult (submode, real, real, NULL_RTX, 0);
2903 imag = expand_mult (submode, imag, imag, NULL_RTX, 0);
2905 /* Sum the parts. */
2906 total = expand_binop (submode, add_optab, real, imag, NULL_RTX,
2907 0, OPTAB_LIB_WIDEN);
2909 /* Get sqrt in TARGET. Set TARGET to where the result is. */
2910 target = expand_unop (submode, sqrt_optab, total, target, 0);
2911 if (target == 0)
2912 delete_insns_since (last);
2913 else
2914 return target;
2917 /* Now try a library call in this mode. */
2918 if (this_abs_optab->handlers[(int) mode].libfunc)
2920 rtx insns;
2921 rtx value;
2923 start_sequence ();
2925 /* Pass 1 for NO_QUEUE so we don't lose any increments
2926 if the libcall is cse'd or moved. */
2927 value = emit_library_call_value (abs_optab->handlers[(int) mode].libfunc,
2928 NULL_RTX, LCT_CONST, submode, 1, op0, mode);
2929 insns = get_insns ();
2930 end_sequence ();
2932 target = gen_reg_rtx (submode);
2933 emit_libcall_block (insns, target, value,
2934 gen_rtx_fmt_e (this_abs_optab->code, mode, op0));
2936 return target;
2939 /* It can't be done in this mode. Can we do it in a wider mode? */
2941 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2942 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2944 if ((this_abs_optab->handlers[(int) wider_mode].insn_code
2945 != CODE_FOR_nothing)
2946 || this_abs_optab->handlers[(int) wider_mode].libfunc)
2948 rtx xop0 = op0;
2950 xop0 = convert_modes (wider_mode, mode, xop0, unsignedp);
2952 temp = expand_complex_abs (wider_mode, xop0, NULL_RTX, unsignedp);
2954 if (temp)
2956 if (class != MODE_COMPLEX_INT)
2958 if (target == 0)
2959 target = gen_reg_rtx (submode);
2960 convert_move (target, temp, 0);
2961 return target;
2963 else
2964 return gen_lowpart (submode, temp);
2966 else
2967 delete_insns_since (last);
2971 delete_insns_since (entry_last);
2972 return 0;
2975 /* Generate an instruction whose insn-code is INSN_CODE,
2976 with two operands: an output TARGET and an input OP0.
2977 TARGET *must* be nonzero, and the output is always stored there.
2978 CODE is an rtx code such that (CODE OP0) is an rtx that describes
2979 the value that is stored into TARGET. */
2981 void
2982 emit_unop_insn (icode, target, op0, code)
2983 int icode;
2984 rtx target;
2985 rtx op0;
2986 enum rtx_code code;
2988 rtx temp;
2989 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2990 rtx pat;
2992 temp = target = protect_from_queue (target, 1);
2994 op0 = protect_from_queue (op0, 0);
2996 /* Sign and zero extension from memory is often done specially on
2997 RISC machines, so forcing into a register here can pessimize
2998 code. */
2999 if (flag_force_mem && code != SIGN_EXTEND && code != ZERO_EXTEND)
3000 op0 = force_not_mem (op0);
3002 /* Now, if insn does not accept our operands, put them into pseudos. */
3004 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
3005 op0 = copy_to_mode_reg (mode0, op0);
3007 if (! (*insn_data[icode].operand[0].predicate) (temp, GET_MODE (temp))
3008 || (flag_force_mem && GET_CODE (temp) == MEM))
3009 temp = gen_reg_rtx (GET_MODE (temp));
3011 pat = GEN_FCN (icode) (temp, op0);
3013 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX && code != UNKNOWN)
3014 add_equal_note (pat, temp, code, op0, NULL_RTX);
3016 emit_insn (pat);
3018 if (temp != target)
3019 emit_move_insn (target, temp);
3022 /* Emit code to perform a series of operations on a multi-word quantity, one
3023 word at a time.
3025 Such a block is preceded by a CLOBBER of the output, consists of multiple
3026 insns, each setting one word of the output, and followed by a SET copying
3027 the output to itself.
3029 Each of the insns setting words of the output receives a REG_NO_CONFLICT
3030 note indicating that it doesn't conflict with the (also multi-word)
3031 inputs. The entire block is surrounded by REG_LIBCALL and REG_RETVAL
3032 notes.
3034 INSNS is a block of code generated to perform the operation, not including
3035 the CLOBBER and final copy. All insns that compute intermediate values
3036 are first emitted, followed by the block as described above.
3038 TARGET, OP0, and OP1 are the output and inputs of the operations,
3039 respectively. OP1 may be zero for a unary operation.
3041 EQUIV, if nonzero, is an expression to be placed into a REG_EQUAL note
3042 on the last insn.
3044 If TARGET is not a register, INSNS is simply emitted with no special
3045 processing. Likewise if anything in INSNS is not an INSN or if
3046 there is a libcall block inside INSNS.
3048 The final insn emitted is returned. */
3051 emit_no_conflict_block (insns, target, op0, op1, equiv)
3052 rtx insns;
3053 rtx target;
3054 rtx op0, op1;
3055 rtx equiv;
3057 rtx prev, next, first, last, insn;
3059 if (GET_CODE (target) != REG || reload_in_progress)
3060 return emit_insn (insns);
3061 else
3062 for (insn = insns; insn; insn = NEXT_INSN (insn))
3063 if (GET_CODE (insn) != INSN
3064 || find_reg_note (insn, REG_LIBCALL, NULL_RTX))
3065 return emit_insn (insns);
3067 /* First emit all insns that do not store into words of the output and remove
3068 these from the list. */
3069 for (insn = insns; insn; insn = next)
3071 rtx set = 0, note;
3072 int i;
3074 next = NEXT_INSN (insn);
3076 /* Some ports (cris) create an libcall regions at their own. We must
3077 avoid any potential nesting of LIBCALLs. */
3078 if ((note = find_reg_note (insn, REG_LIBCALL, NULL)) != NULL)
3079 remove_note (insn, note);
3080 if ((note = find_reg_note (insn, REG_RETVAL, NULL)) != NULL)
3081 remove_note (insn, note);
3083 if (GET_CODE (PATTERN (insn)) == SET || GET_CODE (PATTERN (insn)) == USE
3084 || GET_CODE (PATTERN (insn)) == CLOBBER)
3085 set = PATTERN (insn);
3086 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
3088 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
3089 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
3091 set = XVECEXP (PATTERN (insn), 0, i);
3092 break;
3096 if (set == 0)
3097 abort ();
3099 if (! reg_overlap_mentioned_p (target, SET_DEST (set)))
3101 if (PREV_INSN (insn))
3102 NEXT_INSN (PREV_INSN (insn)) = next;
3103 else
3104 insns = next;
3106 if (next)
3107 PREV_INSN (next) = PREV_INSN (insn);
3109 add_insn (insn);
3113 prev = get_last_insn ();
3115 /* Now write the CLOBBER of the output, followed by the setting of each
3116 of the words, followed by the final copy. */
3117 if (target != op0 && target != op1)
3118 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
3120 for (insn = insns; insn; insn = next)
3122 next = NEXT_INSN (insn);
3123 add_insn (insn);
3125 if (op1 && GET_CODE (op1) == REG)
3126 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT, op1,
3127 REG_NOTES (insn));
3129 if (op0 && GET_CODE (op0) == REG)
3130 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT, op0,
3131 REG_NOTES (insn));
3134 if (mov_optab->handlers[(int) GET_MODE (target)].insn_code
3135 != CODE_FOR_nothing)
3137 last = emit_move_insn (target, target);
3138 if (equiv)
3139 set_unique_reg_note (last, REG_EQUAL, equiv);
3141 else
3143 last = get_last_insn ();
3145 /* Remove any existing REG_EQUAL note from "last", or else it will
3146 be mistaken for a note referring to the full contents of the
3147 alleged libcall value when found together with the REG_RETVAL
3148 note added below. An existing note can come from an insn
3149 expansion at "last". */
3150 remove_note (last, find_reg_note (last, REG_EQUAL, NULL_RTX));
3153 if (prev == 0)
3154 first = get_insns ();
3155 else
3156 first = NEXT_INSN (prev);
3158 /* Encapsulate the block so it gets manipulated as a unit. */
3159 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3160 REG_NOTES (first));
3161 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, REG_NOTES (last));
3163 return last;
3166 /* Emit code to make a call to a constant function or a library call.
3168 INSNS is a list containing all insns emitted in the call.
3169 These insns leave the result in RESULT. Our block is to copy RESULT
3170 to TARGET, which is logically equivalent to EQUIV.
3172 We first emit any insns that set a pseudo on the assumption that these are
3173 loading constants into registers; doing so allows them to be safely cse'ed
3174 between blocks. Then we emit all the other insns in the block, followed by
3175 an insn to move RESULT to TARGET. This last insn will have a REQ_EQUAL
3176 note with an operand of EQUIV.
3178 Moving assignments to pseudos outside of the block is done to improve
3179 the generated code, but is not required to generate correct code,
3180 hence being unable to move an assignment is not grounds for not making
3181 a libcall block. There are two reasons why it is safe to leave these
3182 insns inside the block: First, we know that these pseudos cannot be
3183 used in generated RTL outside the block since they are created for
3184 temporary purposes within the block. Second, CSE will not record the
3185 values of anything set inside a libcall block, so we know they must
3186 be dead at the end of the block.
3188 Except for the first group of insns (the ones setting pseudos), the
3189 block is delimited by REG_RETVAL and REG_LIBCALL notes. */
3191 void
3192 emit_libcall_block (insns, target, result, equiv)
3193 rtx insns;
3194 rtx target;
3195 rtx result;
3196 rtx equiv;
3198 rtx final_dest = target;
3199 rtx prev, next, first, last, insn;
3201 /* If this is a reg with REG_USERVAR_P set, then it could possibly turn
3202 into a MEM later. Protect the libcall block from this change. */
3203 if (! REG_P (target) || REG_USERVAR_P (target))
3204 target = gen_reg_rtx (GET_MODE (target));
3206 /* If we're using non-call exceptions, a libcall corresponding to an
3207 operation that may trap may also trap. */
3208 if (flag_non_call_exceptions && may_trap_p (equiv))
3210 for (insn = insns; insn; insn = NEXT_INSN (insn))
3211 if (GET_CODE (insn) == CALL_INSN)
3213 rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
3215 if (note != 0 && INTVAL (XEXP (note, 0)) <= 0)
3216 remove_note (insn, note);
3219 else
3220 /* look for any CALL_INSNs in this sequence, and attach a REG_EH_REGION
3221 reg note to indicate that this call cannot throw or execute a nonlocal
3222 goto (unless there is already a REG_EH_REGION note, in which case
3223 we update it). */
3224 for (insn = insns; insn; insn = NEXT_INSN (insn))
3225 if (GET_CODE (insn) == CALL_INSN)
3227 rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
3229 if (note != 0)
3230 XEXP (note, 0) = GEN_INT (-1);
3231 else
3232 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, GEN_INT (-1),
3233 REG_NOTES (insn));
3236 /* First emit all insns that set pseudos. Remove them from the list as
3237 we go. Avoid insns that set pseudos which were referenced in previous
3238 insns. These can be generated by move_by_pieces, for example,
3239 to update an address. Similarly, avoid insns that reference things
3240 set in previous insns. */
3242 for (insn = insns; insn; insn = next)
3244 rtx set = single_set (insn);
3245 rtx note;
3247 /* Some ports (cris) create an libcall regions at their own. We must
3248 avoid any potential nesting of LIBCALLs. */
3249 if ((note = find_reg_note (insn, REG_LIBCALL, NULL)) != NULL)
3250 remove_note (insn, note);
3251 if ((note = find_reg_note (insn, REG_RETVAL, NULL)) != NULL)
3252 remove_note (insn, note);
3254 next = NEXT_INSN (insn);
3256 if (set != 0 && GET_CODE (SET_DEST (set)) == REG
3257 && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
3258 && (insn == insns
3259 || ((! INSN_P(insns)
3260 || ! reg_mentioned_p (SET_DEST (set), PATTERN (insns)))
3261 && ! reg_used_between_p (SET_DEST (set), insns, insn)
3262 && ! modified_in_p (SET_SRC (set), insns)
3263 && ! modified_between_p (SET_SRC (set), insns, insn))))
3265 if (PREV_INSN (insn))
3266 NEXT_INSN (PREV_INSN (insn)) = next;
3267 else
3268 insns = next;
3270 if (next)
3271 PREV_INSN (next) = PREV_INSN (insn);
3273 add_insn (insn);
3277 prev = get_last_insn ();
3279 /* Write the remaining insns followed by the final copy. */
3281 for (insn = insns; insn; insn = next)
3283 next = NEXT_INSN (insn);
3285 add_insn (insn);
3288 last = emit_move_insn (target, result);
3289 if (mov_optab->handlers[(int) GET_MODE (target)].insn_code
3290 != CODE_FOR_nothing)
3291 set_unique_reg_note (last, REG_EQUAL, copy_rtx (equiv));
3292 else
3294 /* Remove any existing REG_EQUAL note from "last", or else it will
3295 be mistaken for a note referring to the full contents of the
3296 libcall value when found together with the REG_RETVAL note added
3297 below. An existing note can come from an insn expansion at
3298 "last". */
3299 remove_note (last, find_reg_note (last, REG_EQUAL, NULL_RTX));
3302 if (final_dest != target)
3303 emit_move_insn (final_dest, target);
3305 if (prev == 0)
3306 first = get_insns ();
3307 else
3308 first = NEXT_INSN (prev);
3310 /* Encapsulate the block so it gets manipulated as a unit. */
3311 if (!flag_non_call_exceptions || !may_trap_p (equiv))
3313 /* We can't attach the REG_LIBCALL and REG_RETVAL notes
3314 when the encapsulated region would not be in one basic block,
3315 i.e. when there is a control_flow_insn_p insn between FIRST and LAST.
3317 bool attach_libcall_retval_notes = true;
3318 next = NEXT_INSN (last);
3319 for (insn = first; insn != next; insn = NEXT_INSN (insn))
3320 if (control_flow_insn_p (insn))
3322 attach_libcall_retval_notes = false;
3323 break;
3326 if (attach_libcall_retval_notes)
3328 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3329 REG_NOTES (first));
3330 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
3331 REG_NOTES (last));
3336 /* Generate code to store zero in X. */
3338 void
3339 emit_clr_insn (x)
3340 rtx x;
3342 emit_move_insn (x, const0_rtx);
3345 /* Generate code to store 1 in X
3346 assuming it contains zero beforehand. */
3348 void
3349 emit_0_to_1_insn (x)
3350 rtx x;
3352 emit_move_insn (x, const1_rtx);
3355 /* Nonzero if we can perform a comparison of mode MODE straightforwardly.
3356 PURPOSE describes how this comparison will be used. CODE is the rtx
3357 comparison code we will be using.
3359 ??? Actually, CODE is slightly weaker than that. A target is still
3360 required to implement all of the normal bcc operations, but not
3361 required to implement all (or any) of the unordered bcc operations. */
3364 can_compare_p (code, mode, purpose)
3365 enum rtx_code code;
3366 enum machine_mode mode;
3367 enum can_compare_purpose purpose;
3371 if (cmp_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3373 if (purpose == ccp_jump)
3374 return bcc_gen_fctn[(int) code] != NULL;
3375 else if (purpose == ccp_store_flag)
3376 return setcc_gen_code[(int) code] != CODE_FOR_nothing;
3377 else
3378 /* There's only one cmov entry point, and it's allowed to fail. */
3379 return 1;
3381 if (purpose == ccp_jump
3382 && cbranch_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3383 return 1;
3384 if (purpose == ccp_cmov
3385 && cmov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3386 return 1;
3387 if (purpose == ccp_store_flag
3388 && cstore_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3389 return 1;
3391 mode = GET_MODE_WIDER_MODE (mode);
3393 while (mode != VOIDmode);
3395 return 0;
3398 /* This function is called when we are going to emit a compare instruction that
3399 compares the values found in *PX and *PY, using the rtl operator COMPARISON.
3401 *PMODE is the mode of the inputs (in case they are const_int).
3402 *PUNSIGNEDP nonzero says that the operands are unsigned;
3403 this matters if they need to be widened.
3405 If they have mode BLKmode, then SIZE specifies the size of both operands.
3407 This function performs all the setup necessary so that the caller only has
3408 to emit a single comparison insn. This setup can involve doing a BLKmode
3409 comparison or emitting a library call to perform the comparison if no insn
3410 is available to handle it.
3411 The values which are passed in through pointers can be modified; the caller
3412 should perform the comparison on the modified values. */
3414 static void
3415 prepare_cmp_insn (px, py, pcomparison, size, pmode, punsignedp, purpose)
3416 rtx *px, *py;
3417 enum rtx_code *pcomparison;
3418 rtx size;
3419 enum machine_mode *pmode;
3420 int *punsignedp;
3421 enum can_compare_purpose purpose;
3423 enum machine_mode mode = *pmode;
3424 rtx x = *px, y = *py;
3425 int unsignedp = *punsignedp;
3426 enum mode_class class;
3428 class = GET_MODE_CLASS (mode);
3430 /* They could both be VOIDmode if both args are immediate constants,
3431 but we should fold that at an earlier stage.
3432 With no special code here, this will call abort,
3433 reminding the programmer to implement such folding. */
3435 if (mode != BLKmode && flag_force_mem)
3437 x = force_not_mem (x);
3438 y = force_not_mem (y);
3441 /* If we are inside an appropriately-short loop and one operand is an
3442 expensive constant, force it into a register. */
3443 if (CONSTANT_P (x) && preserve_subexpressions_p ()
3444 && rtx_cost (x, COMPARE) > COSTS_N_INSNS (1))
3445 x = force_reg (mode, x);
3447 if (CONSTANT_P (y) && preserve_subexpressions_p ()
3448 && rtx_cost (y, COMPARE) > COSTS_N_INSNS (1))
3449 y = force_reg (mode, y);
3451 #ifdef HAVE_cc0
3452 /* Abort if we have a non-canonical comparison. The RTL documentation
3453 states that canonical comparisons are required only for targets which
3454 have cc0. */
3455 if (CONSTANT_P (x) && ! CONSTANT_P (y))
3456 abort ();
3457 #endif
3459 /* Don't let both operands fail to indicate the mode. */
3460 if (GET_MODE (x) == VOIDmode && GET_MODE (y) == VOIDmode)
3461 x = force_reg (mode, x);
3463 /* Handle all BLKmode compares. */
3465 if (mode == BLKmode)
3467 rtx result;
3468 enum machine_mode result_mode;
3469 rtx opalign ATTRIBUTE_UNUSED
3470 = GEN_INT (MIN (MEM_ALIGN (x), MEM_ALIGN (y)) / BITS_PER_UNIT);
3472 emit_queue ();
3473 x = protect_from_queue (x, 0);
3474 y = protect_from_queue (y, 0);
3476 if (size == 0)
3477 abort ();
3478 #ifdef HAVE_cmpstrqi
3479 if (HAVE_cmpstrqi
3480 && GET_CODE (size) == CONST_INT
3481 && INTVAL (size) < (1 << GET_MODE_BITSIZE (QImode)))
3483 result_mode = insn_data[(int) CODE_FOR_cmpstrqi].operand[0].mode;
3484 result = gen_reg_rtx (result_mode);
3485 emit_insn (gen_cmpstrqi (result, x, y, size, opalign));
3487 else
3488 #endif
3489 #ifdef HAVE_cmpstrhi
3490 if (HAVE_cmpstrhi
3491 && GET_CODE (size) == CONST_INT
3492 && INTVAL (size) < (1 << GET_MODE_BITSIZE (HImode)))
3494 result_mode = insn_data[(int) CODE_FOR_cmpstrhi].operand[0].mode;
3495 result = gen_reg_rtx (result_mode);
3496 emit_insn (gen_cmpstrhi (result, x, y, size, opalign));
3498 else
3499 #endif
3500 #ifdef HAVE_cmpstrsi
3501 if (HAVE_cmpstrsi)
3503 result_mode = insn_data[(int) CODE_FOR_cmpstrsi].operand[0].mode;
3504 result = gen_reg_rtx (result_mode);
3505 size = protect_from_queue (size, 0);
3506 emit_insn (gen_cmpstrsi (result, x, y,
3507 convert_to_mode (SImode, size, 1),
3508 opalign));
3510 else
3511 #endif
3513 #ifdef TARGET_MEM_FUNCTIONS
3514 result = emit_library_call_value (memcmp_libfunc, NULL_RTX, LCT_PURE_MAKE_BLOCK,
3515 TYPE_MODE (integer_type_node), 3,
3516 XEXP (x, 0), Pmode, XEXP (y, 0), Pmode,
3517 convert_to_mode (TYPE_MODE (sizetype), size,
3518 TREE_UNSIGNED (sizetype)),
3519 TYPE_MODE (sizetype));
3520 #else
3521 result = emit_library_call_value (bcmp_libfunc, NULL_RTX, LCT_PURE_MAKE_BLOCK,
3522 TYPE_MODE (integer_type_node), 3,
3523 XEXP (x, 0), Pmode, XEXP (y, 0), Pmode,
3524 convert_to_mode (TYPE_MODE (integer_type_node),
3525 size,
3526 TREE_UNSIGNED (integer_type_node)),
3527 TYPE_MODE (integer_type_node));
3528 #endif
3530 result_mode = TYPE_MODE (integer_type_node);
3532 *px = result;
3533 *py = const0_rtx;
3534 *pmode = result_mode;
3535 return;
3538 *px = x;
3539 *py = y;
3540 if (can_compare_p (*pcomparison, mode, purpose))
3541 return;
3543 /* Handle a lib call just for the mode we are using. */
3545 if (cmp_optab->handlers[(int) mode].libfunc && class != MODE_FLOAT)
3547 rtx libfunc = cmp_optab->handlers[(int) mode].libfunc;
3548 rtx result;
3550 /* If we want unsigned, and this mode has a distinct unsigned
3551 comparison routine, use that. */
3552 if (unsignedp && ucmp_optab->handlers[(int) mode].libfunc)
3553 libfunc = ucmp_optab->handlers[(int) mode].libfunc;
3555 result = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST_MAKE_BLOCK,
3556 word_mode, 2, x, mode, y, mode);
3558 /* Integer comparison returns a result that must be compared against 1,
3559 so that even if we do an unsigned compare afterward,
3560 there is still a value that can represent the result "less than". */
3561 *px = result;
3562 *py = const1_rtx;
3563 *pmode = word_mode;
3564 return;
3567 if (class == MODE_FLOAT)
3568 prepare_float_lib_cmp (px, py, pcomparison, pmode, punsignedp);
3570 else
3571 abort ();
3574 /* Before emitting an insn with code ICODE, make sure that X, which is going
3575 to be used for operand OPNUM of the insn, is converted from mode MODE to
3576 WIDER_MODE (UNSIGNEDP determines whether it is an unsigned conversion), and
3577 that it is accepted by the operand predicate. Return the new value. */
3580 prepare_operand (icode, x, opnum, mode, wider_mode, unsignedp)
3581 int icode;
3582 rtx x;
3583 int opnum;
3584 enum machine_mode mode, wider_mode;
3585 int unsignedp;
3587 x = protect_from_queue (x, 0);
3589 if (mode != wider_mode)
3590 x = convert_modes (wider_mode, mode, x, unsignedp);
3592 if (! (*insn_data[icode].operand[opnum].predicate)
3593 (x, insn_data[icode].operand[opnum].mode))
3594 x = copy_to_mode_reg (insn_data[icode].operand[opnum].mode, x);
3595 return x;
3598 /* Subroutine of emit_cmp_and_jump_insns; this function is called when we know
3599 we can do the comparison.
3600 The arguments are the same as for emit_cmp_and_jump_insns; but LABEL may
3601 be NULL_RTX which indicates that only a comparison is to be generated. */
3603 static void
3604 emit_cmp_and_jump_insn_1 (x, y, mode, comparison, unsignedp, label)
3605 rtx x, y;
3606 enum machine_mode mode;
3607 enum rtx_code comparison;
3608 int unsignedp;
3609 rtx label;
3611 rtx test = gen_rtx_fmt_ee (comparison, mode, x, y);
3612 enum mode_class class = GET_MODE_CLASS (mode);
3613 enum machine_mode wider_mode = mode;
3615 /* Try combined insns first. */
3618 enum insn_code icode;
3619 PUT_MODE (test, wider_mode);
3621 if (label)
3623 icode = cbranch_optab->handlers[(int) wider_mode].insn_code;
3625 if (icode != CODE_FOR_nothing
3626 && (*insn_data[icode].operand[0].predicate) (test, wider_mode))
3628 x = prepare_operand (icode, x, 1, mode, wider_mode, unsignedp);
3629 y = prepare_operand (icode, y, 2, mode, wider_mode, unsignedp);
3630 emit_jump_insn (GEN_FCN (icode) (test, x, y, label));
3631 return;
3635 /* Handle some compares against zero. */
3636 icode = (int) tst_optab->handlers[(int) wider_mode].insn_code;
3637 if (y == CONST0_RTX (mode) && icode != CODE_FOR_nothing)
3639 x = prepare_operand (icode, x, 0, mode, wider_mode, unsignedp);
3640 emit_insn (GEN_FCN (icode) (x));
3641 if (label)
3642 emit_jump_insn ((*bcc_gen_fctn[(int) comparison]) (label));
3643 return;
3646 /* Handle compares for which there is a directly suitable insn. */
3648 icode = (int) cmp_optab->handlers[(int) wider_mode].insn_code;
3649 if (icode != CODE_FOR_nothing)
3651 x = prepare_operand (icode, x, 0, mode, wider_mode, unsignedp);
3652 y = prepare_operand (icode, y, 1, mode, wider_mode, unsignedp);
3653 emit_insn (GEN_FCN (icode) (x, y));
3654 if (label)
3655 emit_jump_insn ((*bcc_gen_fctn[(int) comparison]) (label));
3656 return;
3659 if (class != MODE_INT && class != MODE_FLOAT
3660 && class != MODE_COMPLEX_FLOAT)
3661 break;
3663 wider_mode = GET_MODE_WIDER_MODE (wider_mode);
3665 while (wider_mode != VOIDmode);
3667 abort ();
3670 /* Generate code to compare X with Y so that the condition codes are
3671 set and to jump to LABEL if the condition is true. If X is a
3672 constant and Y is not a constant, then the comparison is swapped to
3673 ensure that the comparison RTL has the canonical form.
3675 UNSIGNEDP nonzero says that X and Y are unsigned; this matters if they
3676 need to be widened by emit_cmp_insn. UNSIGNEDP is also used to select
3677 the proper branch condition code.
3679 If X and Y have mode BLKmode, then SIZE specifies the size of both X and Y.
3681 MODE is the mode of the inputs (in case they are const_int).
3683 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). It will
3684 be passed unchanged to emit_cmp_insn, then potentially converted into an
3685 unsigned variant based on UNSIGNEDP to select a proper jump instruction. */
3687 void
3688 emit_cmp_and_jump_insns (x, y, comparison, size, mode, unsignedp, label)
3689 rtx x, y;
3690 enum rtx_code comparison;
3691 rtx size;
3692 enum machine_mode mode;
3693 int unsignedp;
3694 rtx label;
3696 rtx op0 = x, op1 = y;
3698 /* Swap operands and condition to ensure canonical RTL. */
3699 if (swap_commutative_operands_p (x, y))
3701 /* If we're not emitting a branch, this means some caller
3702 is out of sync. */
3703 if (! label)
3704 abort ();
3706 op0 = y, op1 = x;
3707 comparison = swap_condition (comparison);
3710 #ifdef HAVE_cc0
3711 /* If OP0 is still a constant, then both X and Y must be constants. Force
3712 X into a register to avoid aborting in emit_cmp_insn due to non-canonical
3713 RTL. */
3714 if (CONSTANT_P (op0))
3715 op0 = force_reg (mode, op0);
3716 #endif
3718 emit_queue ();
3719 if (unsignedp)
3720 comparison = unsigned_condition (comparison);
3722 prepare_cmp_insn (&op0, &op1, &comparison, size, &mode, &unsignedp,
3723 ccp_jump);
3724 emit_cmp_and_jump_insn_1 (op0, op1, mode, comparison, unsignedp, label);
3727 /* Like emit_cmp_and_jump_insns, but generate only the comparison. */
3729 void
3730 emit_cmp_insn (x, y, comparison, size, mode, unsignedp)
3731 rtx x, y;
3732 enum rtx_code comparison;
3733 rtx size;
3734 enum machine_mode mode;
3735 int unsignedp;
3737 emit_cmp_and_jump_insns (x, y, comparison, size, mode, unsignedp, 0);
3740 /* Emit a library call comparison between floating point X and Y.
3741 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). */
3743 static void
3744 prepare_float_lib_cmp (px, py, pcomparison, pmode, punsignedp)
3745 rtx *px, *py;
3746 enum rtx_code *pcomparison;
3747 enum machine_mode *pmode;
3748 int *punsignedp;
3750 enum rtx_code comparison = *pcomparison;
3751 rtx tmp;
3752 rtx x = *px = protect_from_queue (*px, 0);
3753 rtx y = *py = protect_from_queue (*py, 0);
3754 enum machine_mode mode = GET_MODE (x);
3755 rtx libfunc = 0;
3756 rtx result;
3758 if (mode == HFmode)
3759 switch (comparison)
3761 case EQ:
3762 libfunc = eqhf2_libfunc;
3763 break;
3765 case NE:
3766 libfunc = nehf2_libfunc;
3767 break;
3769 case GT:
3770 libfunc = gthf2_libfunc;
3771 if (libfunc == NULL_RTX)
3773 tmp = x; x = y; y = tmp;
3774 *pcomparison = LT;
3775 libfunc = lthf2_libfunc;
3777 break;
3779 case GE:
3780 libfunc = gehf2_libfunc;
3781 if (libfunc == NULL_RTX)
3783 tmp = x; x = y; y = tmp;
3784 *pcomparison = LE;
3785 libfunc = lehf2_libfunc;
3787 break;
3789 case LT:
3790 libfunc = lthf2_libfunc;
3791 if (libfunc == NULL_RTX)
3793 tmp = x; x = y; y = tmp;
3794 *pcomparison = GT;
3795 libfunc = gthf2_libfunc;
3797 break;
3799 case LE:
3800 libfunc = lehf2_libfunc;
3801 if (libfunc == NULL_RTX)
3803 tmp = x; x = y; y = tmp;
3804 *pcomparison = GE;
3805 libfunc = gehf2_libfunc;
3807 break;
3809 case UNORDERED:
3810 libfunc = unordhf2_libfunc;
3811 break;
3813 default:
3814 break;
3816 else if (mode == SFmode)
3817 switch (comparison)
3819 case EQ:
3820 libfunc = eqsf2_libfunc;
3821 break;
3823 case NE:
3824 libfunc = nesf2_libfunc;
3825 break;
3827 case GT:
3828 libfunc = gtsf2_libfunc;
3829 if (libfunc == NULL_RTX)
3831 tmp = x; x = y; y = tmp;
3832 *pcomparison = LT;
3833 libfunc = ltsf2_libfunc;
3835 break;
3837 case GE:
3838 libfunc = gesf2_libfunc;
3839 if (libfunc == NULL_RTX)
3841 tmp = x; x = y; y = tmp;
3842 *pcomparison = LE;
3843 libfunc = lesf2_libfunc;
3845 break;
3847 case LT:
3848 libfunc = ltsf2_libfunc;
3849 if (libfunc == NULL_RTX)
3851 tmp = x; x = y; y = tmp;
3852 *pcomparison = GT;
3853 libfunc = gtsf2_libfunc;
3855 break;
3857 case LE:
3858 libfunc = lesf2_libfunc;
3859 if (libfunc == NULL_RTX)
3861 tmp = x; x = y; y = tmp;
3862 *pcomparison = GE;
3863 libfunc = gesf2_libfunc;
3865 break;
3867 case UNORDERED:
3868 libfunc = unordsf2_libfunc;
3869 break;
3871 default:
3872 break;
3874 else if (mode == DFmode)
3875 switch (comparison)
3877 case EQ:
3878 libfunc = eqdf2_libfunc;
3879 break;
3881 case NE:
3882 libfunc = nedf2_libfunc;
3883 break;
3885 case GT:
3886 libfunc = gtdf2_libfunc;
3887 if (libfunc == NULL_RTX)
3889 tmp = x; x = y; y = tmp;
3890 *pcomparison = LT;
3891 libfunc = ltdf2_libfunc;
3893 break;
3895 case GE:
3896 libfunc = gedf2_libfunc;
3897 if (libfunc == NULL_RTX)
3899 tmp = x; x = y; y = tmp;
3900 *pcomparison = LE;
3901 libfunc = ledf2_libfunc;
3903 break;
3905 case LT:
3906 libfunc = ltdf2_libfunc;
3907 if (libfunc == NULL_RTX)
3909 tmp = x; x = y; y = tmp;
3910 *pcomparison = GT;
3911 libfunc = gtdf2_libfunc;
3913 break;
3915 case LE:
3916 libfunc = ledf2_libfunc;
3917 if (libfunc == NULL_RTX)
3919 tmp = x; x = y; y = tmp;
3920 *pcomparison = GE;
3921 libfunc = gedf2_libfunc;
3923 break;
3925 case UNORDERED:
3926 libfunc = unorddf2_libfunc;
3927 break;
3929 default:
3930 break;
3932 else if (mode == XFmode)
3933 switch (comparison)
3935 case EQ:
3936 libfunc = eqxf2_libfunc;
3937 break;
3939 case NE:
3940 libfunc = nexf2_libfunc;
3941 break;
3943 case GT:
3944 libfunc = gtxf2_libfunc;
3945 if (libfunc == NULL_RTX)
3947 tmp = x; x = y; y = tmp;
3948 *pcomparison = LT;
3949 libfunc = ltxf2_libfunc;
3951 break;
3953 case GE:
3954 libfunc = gexf2_libfunc;
3955 if (libfunc == NULL_RTX)
3957 tmp = x; x = y; y = tmp;
3958 *pcomparison = LE;
3959 libfunc = lexf2_libfunc;
3961 break;
3963 case LT:
3964 libfunc = ltxf2_libfunc;
3965 if (libfunc == NULL_RTX)
3967 tmp = x; x = y; y = tmp;
3968 *pcomparison = GT;
3969 libfunc = gtxf2_libfunc;
3971 break;
3973 case LE:
3974 libfunc = lexf2_libfunc;
3975 if (libfunc == NULL_RTX)
3977 tmp = x; x = y; y = tmp;
3978 *pcomparison = GE;
3979 libfunc = gexf2_libfunc;
3981 break;
3983 case UNORDERED:
3984 libfunc = unordxf2_libfunc;
3985 break;
3987 default:
3988 break;
3990 else if (mode == TFmode)
3991 switch (comparison)
3993 case EQ:
3994 libfunc = eqtf2_libfunc;
3995 break;
3997 case NE:
3998 libfunc = netf2_libfunc;
3999 break;
4001 case GT:
4002 libfunc = gttf2_libfunc;
4003 if (libfunc == NULL_RTX)
4005 tmp = x; x = y; y = tmp;
4006 *pcomparison = LT;
4007 libfunc = lttf2_libfunc;
4009 break;
4011 case GE:
4012 libfunc = getf2_libfunc;
4013 if (libfunc == NULL_RTX)
4015 tmp = x; x = y; y = tmp;
4016 *pcomparison = LE;
4017 libfunc = letf2_libfunc;
4019 break;
4021 case LT:
4022 libfunc = lttf2_libfunc;
4023 if (libfunc == NULL_RTX)
4025 tmp = x; x = y; y = tmp;
4026 *pcomparison = GT;
4027 libfunc = gttf2_libfunc;
4029 break;
4031 case LE:
4032 libfunc = letf2_libfunc;
4033 if (libfunc == NULL_RTX)
4035 tmp = x; x = y; y = tmp;
4036 *pcomparison = GE;
4037 libfunc = getf2_libfunc;
4039 break;
4041 case UNORDERED:
4042 libfunc = unordtf2_libfunc;
4043 break;
4045 default:
4046 break;
4048 else
4050 enum machine_mode wider_mode;
4052 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
4053 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
4055 if ((cmp_optab->handlers[(int) wider_mode].insn_code
4056 != CODE_FOR_nothing)
4057 || (cmp_optab->handlers[(int) wider_mode].libfunc != 0))
4059 x = protect_from_queue (x, 0);
4060 y = protect_from_queue (y, 0);
4061 *px = convert_to_mode (wider_mode, x, 0);
4062 *py = convert_to_mode (wider_mode, y, 0);
4063 prepare_float_lib_cmp (px, py, pcomparison, pmode, punsignedp);
4064 return;
4067 abort ();
4070 if (libfunc == 0)
4071 abort ();
4073 result = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST_MAKE_BLOCK,
4074 word_mode, 2, x, mode, y, mode);
4075 *px = result;
4076 *py = const0_rtx;
4077 *pmode = word_mode;
4078 if (comparison == UNORDERED)
4079 *pcomparison = NE;
4080 #ifdef FLOAT_LIB_COMPARE_RETURNS_BOOL
4081 else if (FLOAT_LIB_COMPARE_RETURNS_BOOL (mode, comparison))
4082 *pcomparison = NE;
4083 #endif
4084 *punsignedp = 0;
4087 /* Generate code to indirectly jump to a location given in the rtx LOC. */
4089 void
4090 emit_indirect_jump (loc)
4091 rtx loc;
4093 if (! ((*insn_data[(int) CODE_FOR_indirect_jump].operand[0].predicate)
4094 (loc, Pmode)))
4095 loc = copy_to_mode_reg (Pmode, loc);
4097 emit_jump_insn (gen_indirect_jump (loc));
4098 emit_barrier ();
4101 #ifdef HAVE_conditional_move
4103 /* Emit a conditional move instruction if the machine supports one for that
4104 condition and machine mode.
4106 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
4107 the mode to use should they be constants. If it is VOIDmode, they cannot
4108 both be constants.
4110 OP2 should be stored in TARGET if the comparison is true, otherwise OP3
4111 should be stored there. MODE is the mode to use should they be constants.
4112 If it is VOIDmode, they cannot both be constants.
4114 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
4115 is not supported. */
4118 emit_conditional_move (target, code, op0, op1, cmode, op2, op3, mode,
4119 unsignedp)
4120 rtx target;
4121 enum rtx_code code;
4122 rtx op0, op1;
4123 enum machine_mode cmode;
4124 rtx op2, op3;
4125 enum machine_mode mode;
4126 int unsignedp;
4128 rtx tem, subtarget, comparison, insn;
4129 enum insn_code icode;
4130 enum rtx_code reversed;
4132 /* If one operand is constant, make it the second one. Only do this
4133 if the other operand is not constant as well. */
4135 if (swap_commutative_operands_p (op0, op1))
4137 tem = op0;
4138 op0 = op1;
4139 op1 = tem;
4140 code = swap_condition (code);
4143 /* get_condition will prefer to generate LT and GT even if the old
4144 comparison was against zero, so undo that canonicalization here since
4145 comparisons against zero are cheaper. */
4146 if (code == LT && GET_CODE (op1) == CONST_INT && INTVAL (op1) == 1)
4147 code = LE, op1 = const0_rtx;
4148 else if (code == GT && GET_CODE (op1) == CONST_INT && INTVAL (op1) == -1)
4149 code = GE, op1 = const0_rtx;
4151 if (cmode == VOIDmode)
4152 cmode = GET_MODE (op0);
4154 if (swap_commutative_operands_p (op2, op3)
4155 && ((reversed = reversed_comparison_code_parts (code, op0, op1, NULL))
4156 != UNKNOWN))
4158 tem = op2;
4159 op2 = op3;
4160 op3 = tem;
4161 code = reversed;
4164 if (mode == VOIDmode)
4165 mode = GET_MODE (op2);
4167 icode = movcc_gen_code[mode];
4169 if (icode == CODE_FOR_nothing)
4170 return 0;
4172 if (flag_force_mem)
4174 op2 = force_not_mem (op2);
4175 op3 = force_not_mem (op3);
4178 if (target)
4179 target = protect_from_queue (target, 1);
4180 else
4181 target = gen_reg_rtx (mode);
4183 subtarget = target;
4185 emit_queue ();
4187 op2 = protect_from_queue (op2, 0);
4188 op3 = protect_from_queue (op3, 0);
4190 /* If the insn doesn't accept these operands, put them in pseudos. */
4192 if (! (*insn_data[icode].operand[0].predicate)
4193 (subtarget, insn_data[icode].operand[0].mode))
4194 subtarget = gen_reg_rtx (insn_data[icode].operand[0].mode);
4196 if (! (*insn_data[icode].operand[2].predicate)
4197 (op2, insn_data[icode].operand[2].mode))
4198 op2 = copy_to_mode_reg (insn_data[icode].operand[2].mode, op2);
4200 if (! (*insn_data[icode].operand[3].predicate)
4201 (op3, insn_data[icode].operand[3].mode))
4202 op3 = copy_to_mode_reg (insn_data[icode].operand[3].mode, op3);
4204 /* Everything should now be in the suitable form, so emit the compare insn
4205 and then the conditional move. */
4207 comparison
4208 = compare_from_rtx (op0, op1, code, unsignedp, cmode, NULL_RTX);
4210 /* ??? Watch for const0_rtx (nop) and const_true_rtx (unconditional)? */
4211 /* We can get const0_rtx or const_true_rtx in some circumstances. Just
4212 return NULL and let the caller figure out how best to deal with this
4213 situation. */
4214 if (GET_CODE (comparison) != code)
4215 return NULL_RTX;
4217 insn = GEN_FCN (icode) (subtarget, comparison, op2, op3);
4219 /* If that failed, then give up. */
4220 if (insn == 0)
4221 return 0;
4223 emit_insn (insn);
4225 if (subtarget != target)
4226 convert_move (target, subtarget, 0);
4228 return target;
4231 /* Return nonzero if a conditional move of mode MODE is supported.
4233 This function is for combine so it can tell whether an insn that looks
4234 like a conditional move is actually supported by the hardware. If we
4235 guess wrong we lose a bit on optimization, but that's it. */
4236 /* ??? sparc64 supports conditionally moving integers values based on fp
4237 comparisons, and vice versa. How do we handle them? */
4240 can_conditionally_move_p (mode)
4241 enum machine_mode mode;
4243 if (movcc_gen_code[mode] != CODE_FOR_nothing)
4244 return 1;
4246 return 0;
4249 #endif /* HAVE_conditional_move */
4251 /* Emit a conditional addition instruction if the machine supports one for that
4252 condition and machine mode.
4254 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
4255 the mode to use should they be constants. If it is VOIDmode, they cannot
4256 both be constants.
4258 OP2 should be stored in TARGET if the comparison is true, otherwise OP2+OP3
4259 should be stored there. MODE is the mode to use should they be constants.
4260 If it is VOIDmode, they cannot both be constants.
4262 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
4263 is not supported. */
4266 emit_conditional_add (target, code, op0, op1, cmode, op2, op3, mode,
4267 unsignedp)
4268 rtx target;
4269 enum rtx_code code;
4270 rtx op0, op1;
4271 enum machine_mode cmode;
4272 rtx op2, op3;
4273 enum machine_mode mode;
4274 int unsignedp;
4276 rtx tem, subtarget, comparison, insn;
4277 enum insn_code icode;
4278 enum rtx_code reversed;
4280 /* If one operand is constant, make it the second one. Only do this
4281 if the other operand is not constant as well. */
4283 if (swap_commutative_operands_p (op0, op1))
4285 tem = op0;
4286 op0 = op1;
4287 op1 = tem;
4288 code = swap_condition (code);
4291 /* get_condition will prefer to generate LT and GT even if the old
4292 comparison was against zero, so undo that canonicalization here since
4293 comparisons against zero are cheaper. */
4294 if (code == LT && GET_CODE (op1) == CONST_INT && INTVAL (op1) == 1)
4295 code = LE, op1 = const0_rtx;
4296 else if (code == GT && GET_CODE (op1) == CONST_INT && INTVAL (op1) == -1)
4297 code = GE, op1 = const0_rtx;
4299 if (cmode == VOIDmode)
4300 cmode = GET_MODE (op0);
4302 if (swap_commutative_operands_p (op2, op3)
4303 && ((reversed = reversed_comparison_code_parts (code, op0, op1, NULL))
4304 != UNKNOWN))
4306 tem = op2;
4307 op2 = op3;
4308 op3 = tem;
4309 code = reversed;
4312 if (mode == VOIDmode)
4313 mode = GET_MODE (op2);
4315 icode = addcc_optab->handlers[(int) mode].insn_code;
4317 if (icode == CODE_FOR_nothing)
4318 return 0;
4320 if (flag_force_mem)
4322 op2 = force_not_mem (op2);
4323 op3 = force_not_mem (op3);
4326 if (target)
4327 target = protect_from_queue (target, 1);
4328 else
4329 target = gen_reg_rtx (mode);
4331 subtarget = target;
4333 emit_queue ();
4335 op2 = protect_from_queue (op2, 0);
4336 op3 = protect_from_queue (op3, 0);
4338 /* If the insn doesn't accept these operands, put them in pseudos. */
4340 if (! (*insn_data[icode].operand[0].predicate)
4341 (subtarget, insn_data[icode].operand[0].mode))
4342 subtarget = gen_reg_rtx (insn_data[icode].operand[0].mode);
4344 if (! (*insn_data[icode].operand[2].predicate)
4345 (op2, insn_data[icode].operand[2].mode))
4346 op2 = copy_to_mode_reg (insn_data[icode].operand[2].mode, op2);
4348 if (! (*insn_data[icode].operand[3].predicate)
4349 (op3, insn_data[icode].operand[3].mode))
4350 op3 = copy_to_mode_reg (insn_data[icode].operand[3].mode, op3);
4352 /* Everything should now be in the suitable form, so emit the compare insn
4353 and then the conditional move. */
4355 comparison
4356 = compare_from_rtx (op0, op1, code, unsignedp, cmode, NULL_RTX);
4358 /* ??? Watch for const0_rtx (nop) and const_true_rtx (unconditional)? */
4359 /* We can get const0_rtx or const_true_rtx in some circumstances. Just
4360 return NULL and let the caller figure out how best to deal with this
4361 situation. */
4362 if (GET_CODE (comparison) != code)
4363 return NULL_RTX;
4365 insn = GEN_FCN (icode) (subtarget, comparison, op2, op3);
4367 /* If that failed, then give up. */
4368 if (insn == 0)
4369 return 0;
4371 emit_insn (insn);
4373 if (subtarget != target)
4374 convert_move (target, subtarget, 0);
4376 return target;
4379 /* These functions generate an insn body and return it
4380 rather than emitting the insn.
4382 They do not protect from queued increments,
4383 because they may be used 1) in protect_from_queue itself
4384 and 2) in other passes where there is no queue. */
4386 /* Generate and return an insn body to add Y to X. */
4389 gen_add2_insn (x, y)
4390 rtx x, y;
4392 int icode = (int) add_optab->handlers[(int) GET_MODE (x)].insn_code;
4394 if (! ((*insn_data[icode].operand[0].predicate)
4395 (x, insn_data[icode].operand[0].mode))
4396 || ! ((*insn_data[icode].operand[1].predicate)
4397 (x, insn_data[icode].operand[1].mode))
4398 || ! ((*insn_data[icode].operand[2].predicate)
4399 (y, insn_data[icode].operand[2].mode)))
4400 abort ();
4402 return (GEN_FCN (icode) (x, x, y));
4405 /* Generate and return an insn body to add r1 and c,
4406 storing the result in r0. */
4408 gen_add3_insn (r0, r1, c)
4409 rtx r0, r1, c;
4411 int icode = (int) add_optab->handlers[(int) GET_MODE (r0)].insn_code;
4413 if (icode == CODE_FOR_nothing
4414 || ! ((*insn_data[icode].operand[0].predicate)
4415 (r0, insn_data[icode].operand[0].mode))
4416 || ! ((*insn_data[icode].operand[1].predicate)
4417 (r1, insn_data[icode].operand[1].mode))
4418 || ! ((*insn_data[icode].operand[2].predicate)
4419 (c, insn_data[icode].operand[2].mode)))
4420 return NULL_RTX;
4422 return (GEN_FCN (icode) (r0, r1, c));
4426 have_add2_insn (x, y)
4427 rtx x, y;
4429 int icode;
4431 if (GET_MODE (x) == VOIDmode)
4432 abort ();
4434 icode = (int) add_optab->handlers[(int) GET_MODE (x)].insn_code;
4436 if (icode == CODE_FOR_nothing)
4437 return 0;
4439 if (! ((*insn_data[icode].operand[0].predicate)
4440 (x, insn_data[icode].operand[0].mode))
4441 || ! ((*insn_data[icode].operand[1].predicate)
4442 (x, insn_data[icode].operand[1].mode))
4443 || ! ((*insn_data[icode].operand[2].predicate)
4444 (y, insn_data[icode].operand[2].mode)))
4445 return 0;
4447 return 1;
4450 /* Generate and return an insn body to subtract Y from X. */
4453 gen_sub2_insn (x, y)
4454 rtx x, y;
4456 int icode = (int) sub_optab->handlers[(int) GET_MODE (x)].insn_code;
4458 if (! ((*insn_data[icode].operand[0].predicate)
4459 (x, insn_data[icode].operand[0].mode))
4460 || ! ((*insn_data[icode].operand[1].predicate)
4461 (x, insn_data[icode].operand[1].mode))
4462 || ! ((*insn_data[icode].operand[2].predicate)
4463 (y, insn_data[icode].operand[2].mode)))
4464 abort ();
4466 return (GEN_FCN (icode) (x, x, y));
4469 /* Generate and return an insn body to subtract r1 and c,
4470 storing the result in r0. */
4472 gen_sub3_insn (r0, r1, c)
4473 rtx r0, r1, c;
4475 int icode = (int) sub_optab->handlers[(int) GET_MODE (r0)].insn_code;
4477 if (icode == CODE_FOR_nothing
4478 || ! ((*insn_data[icode].operand[0].predicate)
4479 (r0, insn_data[icode].operand[0].mode))
4480 || ! ((*insn_data[icode].operand[1].predicate)
4481 (r1, insn_data[icode].operand[1].mode))
4482 || ! ((*insn_data[icode].operand[2].predicate)
4483 (c, insn_data[icode].operand[2].mode)))
4484 return NULL_RTX;
4486 return (GEN_FCN (icode) (r0, r1, c));
4490 have_sub2_insn (x, y)
4491 rtx x, y;
4493 int icode;
4495 if (GET_MODE (x) == VOIDmode)
4496 abort ();
4498 icode = (int) sub_optab->handlers[(int) GET_MODE (x)].insn_code;
4500 if (icode == CODE_FOR_nothing)
4501 return 0;
4503 if (! ((*insn_data[icode].operand[0].predicate)
4504 (x, insn_data[icode].operand[0].mode))
4505 || ! ((*insn_data[icode].operand[1].predicate)
4506 (x, insn_data[icode].operand[1].mode))
4507 || ! ((*insn_data[icode].operand[2].predicate)
4508 (y, insn_data[icode].operand[2].mode)))
4509 return 0;
4511 return 1;
4514 /* Generate the body of an instruction to copy Y into X.
4515 It may be a list of insns, if one insn isn't enough. */
4518 gen_move_insn (x, y)
4519 rtx x, y;
4521 enum machine_mode mode = GET_MODE (x);
4522 enum insn_code insn_code;
4523 rtx seq;
4525 if (mode == VOIDmode)
4526 mode = GET_MODE (y);
4528 insn_code = mov_optab->handlers[(int) mode].insn_code;
4530 /* Handle MODE_CC modes: If we don't have a special move insn for this mode,
4531 find a mode to do it in. If we have a movcc, use it. Otherwise,
4532 find the MODE_INT mode of the same width. */
4534 if (GET_MODE_CLASS (mode) == MODE_CC && insn_code == CODE_FOR_nothing)
4536 enum machine_mode tmode = VOIDmode;
4537 rtx x1 = x, y1 = y;
4539 if (mode != CCmode
4540 && mov_optab->handlers[(int) CCmode].insn_code != CODE_FOR_nothing)
4541 tmode = CCmode;
4542 else
4543 for (tmode = QImode; tmode != VOIDmode;
4544 tmode = GET_MODE_WIDER_MODE (tmode))
4545 if (GET_MODE_SIZE (tmode) == GET_MODE_SIZE (mode))
4546 break;
4548 if (tmode == VOIDmode)
4549 abort ();
4551 /* Get X and Y in TMODE. We can't use gen_lowpart here because it
4552 may call change_address which is not appropriate if we were
4553 called when a reload was in progress. We don't have to worry
4554 about changing the address since the size in bytes is supposed to
4555 be the same. Copy the MEM to change the mode and move any
4556 substitutions from the old MEM to the new one. */
4558 if (reload_in_progress)
4560 x = gen_lowpart_common (tmode, x1);
4561 if (x == 0 && GET_CODE (x1) == MEM)
4563 x = adjust_address_nv (x1, tmode, 0);
4564 copy_replacements (x1, x);
4567 y = gen_lowpart_common (tmode, y1);
4568 if (y == 0 && GET_CODE (y1) == MEM)
4570 y = adjust_address_nv (y1, tmode, 0);
4571 copy_replacements (y1, y);
4574 else
4576 x = gen_lowpart (tmode, x);
4577 y = gen_lowpart (tmode, y);
4580 insn_code = mov_optab->handlers[(int) tmode].insn_code;
4581 return (GEN_FCN (insn_code) (x, y));
4584 start_sequence ();
4585 emit_move_insn_1 (x, y);
4586 seq = get_insns ();
4587 end_sequence ();
4588 return seq;
4591 /* Return the insn code used to extend FROM_MODE to TO_MODE.
4592 UNSIGNEDP specifies zero-extension instead of sign-extension. If
4593 no such operation exists, CODE_FOR_nothing will be returned. */
4595 enum insn_code
4596 can_extend_p (to_mode, from_mode, unsignedp)
4597 enum machine_mode to_mode, from_mode;
4598 int unsignedp;
4600 #ifdef HAVE_ptr_extend
4601 if (unsignedp < 0)
4602 return CODE_FOR_ptr_extend;
4603 else
4604 #endif
4605 return extendtab[(int) to_mode][(int) from_mode][unsignedp != 0];
4608 /* Generate the body of an insn to extend Y (with mode MFROM)
4609 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
4612 gen_extend_insn (x, y, mto, mfrom, unsignedp)
4613 rtx x, y;
4614 enum machine_mode mto, mfrom;
4615 int unsignedp;
4617 return (GEN_FCN (extendtab[(int) mto][(int) mfrom][unsignedp != 0]) (x, y));
4620 /* can_fix_p and can_float_p say whether the target machine
4621 can directly convert a given fixed point type to
4622 a given floating point type, or vice versa.
4623 The returned value is the CODE_FOR_... value to use,
4624 or CODE_FOR_nothing if these modes cannot be directly converted.
4626 *TRUNCP_PTR is set to 1 if it is necessary to output
4627 an explicit FTRUNC insn before the fix insn; otherwise 0. */
4629 static enum insn_code
4630 can_fix_p (fixmode, fltmode, unsignedp, truncp_ptr)
4631 enum machine_mode fltmode, fixmode;
4632 int unsignedp;
4633 int *truncp_ptr;
4635 *truncp_ptr = 0;
4636 if (fixtrunctab[(int) fltmode][(int) fixmode][unsignedp != 0]
4637 != CODE_FOR_nothing)
4638 return fixtrunctab[(int) fltmode][(int) fixmode][unsignedp != 0];
4640 if (ftrunc_optab->handlers[(int) fltmode].insn_code != CODE_FOR_nothing)
4642 *truncp_ptr = 1;
4643 return fixtab[(int) fltmode][(int) fixmode][unsignedp != 0];
4645 return CODE_FOR_nothing;
4648 static enum insn_code
4649 can_float_p (fltmode, fixmode, unsignedp)
4650 enum machine_mode fixmode, fltmode;
4651 int unsignedp;
4653 return floattab[(int) fltmode][(int) fixmode][unsignedp != 0];
4656 /* Generate code to convert FROM to floating point
4657 and store in TO. FROM must be fixed point and not VOIDmode.
4658 UNSIGNEDP nonzero means regard FROM as unsigned.
4659 Normally this is done by correcting the final value
4660 if it is negative. */
4662 void
4663 expand_float (to, from, unsignedp)
4664 rtx to, from;
4665 int unsignedp;
4667 enum insn_code icode;
4668 rtx target = to;
4669 enum machine_mode fmode, imode;
4671 /* Crash now, because we won't be able to decide which mode to use. */
4672 if (GET_MODE (from) == VOIDmode)
4673 abort ();
4675 /* Look for an insn to do the conversion. Do it in the specified
4676 modes if possible; otherwise convert either input, output or both to
4677 wider mode. If the integer mode is wider than the mode of FROM,
4678 we can do the conversion signed even if the input is unsigned. */
4680 for (imode = GET_MODE (from); imode != VOIDmode;
4681 imode = GET_MODE_WIDER_MODE (imode))
4682 for (fmode = GET_MODE (to); fmode != VOIDmode;
4683 fmode = GET_MODE_WIDER_MODE (fmode))
4685 int doing_unsigned = unsignedp;
4687 if (fmode != GET_MODE (to)
4688 && significand_size (fmode) < GET_MODE_BITSIZE (GET_MODE (from)))
4689 continue;
4691 icode = can_float_p (fmode, imode, unsignedp);
4692 if (icode == CODE_FOR_nothing && imode != GET_MODE (from) && unsignedp)
4693 icode = can_float_p (fmode, imode, 0), doing_unsigned = 0;
4695 if (icode != CODE_FOR_nothing)
4697 to = protect_from_queue (to, 1);
4698 from = protect_from_queue (from, 0);
4700 if (imode != GET_MODE (from))
4701 from = convert_to_mode (imode, from, unsignedp);
4703 if (fmode != GET_MODE (to))
4704 target = gen_reg_rtx (fmode);
4706 emit_unop_insn (icode, target, from,
4707 doing_unsigned ? UNSIGNED_FLOAT : FLOAT);
4709 if (target != to)
4710 convert_move (to, target, 0);
4711 return;
4715 /* Unsigned integer, and no way to convert directly.
4716 Convert as signed, then conditionally adjust the result. */
4717 if (unsignedp)
4719 rtx label = gen_label_rtx ();
4720 rtx temp;
4721 REAL_VALUE_TYPE offset;
4723 emit_queue ();
4725 to = protect_from_queue (to, 1);
4726 from = protect_from_queue (from, 0);
4728 if (flag_force_mem)
4729 from = force_not_mem (from);
4731 /* Look for a usable floating mode FMODE wider than the source and at
4732 least as wide as the target. Using FMODE will avoid rounding woes
4733 with unsigned values greater than the signed maximum value. */
4735 for (fmode = GET_MODE (to); fmode != VOIDmode;
4736 fmode = GET_MODE_WIDER_MODE (fmode))
4737 if (GET_MODE_BITSIZE (GET_MODE (from)) < GET_MODE_BITSIZE (fmode)
4738 && can_float_p (fmode, GET_MODE (from), 0) != CODE_FOR_nothing)
4739 break;
4741 if (fmode == VOIDmode)
4743 /* There is no such mode. Pretend the target is wide enough. */
4744 fmode = GET_MODE (to);
4746 /* Avoid double-rounding when TO is narrower than FROM. */
4747 if ((significand_size (fmode) + 1)
4748 < GET_MODE_BITSIZE (GET_MODE (from)))
4750 rtx temp1;
4751 rtx neglabel = gen_label_rtx ();
4753 /* Don't use TARGET if it isn't a register, is a hard register,
4754 or is the wrong mode. */
4755 if (GET_CODE (target) != REG
4756 || REGNO (target) < FIRST_PSEUDO_REGISTER
4757 || GET_MODE (target) != fmode)
4758 target = gen_reg_rtx (fmode);
4760 imode = GET_MODE (from);
4761 do_pending_stack_adjust ();
4763 /* Test whether the sign bit is set. */
4764 emit_cmp_and_jump_insns (from, const0_rtx, LT, NULL_RTX, imode,
4765 0, neglabel);
4767 /* The sign bit is not set. Convert as signed. */
4768 expand_float (target, from, 0);
4769 emit_jump_insn (gen_jump (label));
4770 emit_barrier ();
4772 /* The sign bit is set.
4773 Convert to a usable (positive signed) value by shifting right
4774 one bit, while remembering if a nonzero bit was shifted
4775 out; i.e., compute (from & 1) | (from >> 1). */
4777 emit_label (neglabel);
4778 temp = expand_binop (imode, and_optab, from, const1_rtx,
4779 NULL_RTX, 1, OPTAB_LIB_WIDEN);
4780 temp1 = expand_shift (RSHIFT_EXPR, imode, from, integer_one_node,
4781 NULL_RTX, 1);
4782 temp = expand_binop (imode, ior_optab, temp, temp1, temp, 1,
4783 OPTAB_LIB_WIDEN);
4784 expand_float (target, temp, 0);
4786 /* Multiply by 2 to undo the shift above. */
4787 temp = expand_binop (fmode, add_optab, target, target,
4788 target, 0, OPTAB_LIB_WIDEN);
4789 if (temp != target)
4790 emit_move_insn (target, temp);
4792 do_pending_stack_adjust ();
4793 emit_label (label);
4794 goto done;
4798 /* If we are about to do some arithmetic to correct for an
4799 unsigned operand, do it in a pseudo-register. */
4801 if (GET_MODE (to) != fmode
4802 || GET_CODE (to) != REG || REGNO (to) < FIRST_PSEUDO_REGISTER)
4803 target = gen_reg_rtx (fmode);
4805 /* Convert as signed integer to floating. */
4806 expand_float (target, from, 0);
4808 /* If FROM is negative (and therefore TO is negative),
4809 correct its value by 2**bitwidth. */
4811 do_pending_stack_adjust ();
4812 emit_cmp_and_jump_insns (from, const0_rtx, GE, NULL_RTX, GET_MODE (from),
4813 0, label);
4816 real_2expN (&offset, GET_MODE_BITSIZE (GET_MODE (from)));
4817 temp = expand_binop (fmode, add_optab, target,
4818 CONST_DOUBLE_FROM_REAL_VALUE (offset, fmode),
4819 target, 0, OPTAB_LIB_WIDEN);
4820 if (temp != target)
4821 emit_move_insn (target, temp);
4823 do_pending_stack_adjust ();
4824 emit_label (label);
4825 goto done;
4828 /* No hardware instruction available; call a library routine to convert from
4829 SImode, DImode, or TImode into SFmode, DFmode, XFmode, or TFmode. */
4831 rtx libfcn;
4832 rtx insns;
4833 rtx value;
4835 to = protect_from_queue (to, 1);
4836 from = protect_from_queue (from, 0);
4838 if (GET_MODE_SIZE (GET_MODE (from)) < GET_MODE_SIZE (SImode))
4839 from = convert_to_mode (SImode, from, unsignedp);
4841 if (flag_force_mem)
4842 from = force_not_mem (from);
4844 if (GET_MODE (to) == SFmode)
4846 if (GET_MODE (from) == SImode)
4847 libfcn = floatsisf_libfunc;
4848 else if (GET_MODE (from) == DImode)
4849 libfcn = floatdisf_libfunc;
4850 else if (GET_MODE (from) == TImode)
4851 libfcn = floattisf_libfunc;
4852 else
4853 abort ();
4855 else if (GET_MODE (to) == DFmode)
4857 if (GET_MODE (from) == SImode)
4858 libfcn = floatsidf_libfunc;
4859 else if (GET_MODE (from) == DImode)
4860 libfcn = floatdidf_libfunc;
4861 else if (GET_MODE (from) == TImode)
4862 libfcn = floattidf_libfunc;
4863 else
4864 abort ();
4866 else if (GET_MODE (to) == XFmode)
4868 if (GET_MODE (from) == SImode)
4869 libfcn = floatsixf_libfunc;
4870 else if (GET_MODE (from) == DImode)
4871 libfcn = floatdixf_libfunc;
4872 else if (GET_MODE (from) == TImode)
4873 libfcn = floattixf_libfunc;
4874 else
4875 abort ();
4877 else if (GET_MODE (to) == TFmode)
4879 if (GET_MODE (from) == SImode)
4880 libfcn = floatsitf_libfunc;
4881 else if (GET_MODE (from) == DImode)
4882 libfcn = floatditf_libfunc;
4883 else if (GET_MODE (from) == TImode)
4884 libfcn = floattitf_libfunc;
4885 else
4886 abort ();
4888 else
4889 abort ();
4891 start_sequence ();
4893 value = emit_library_call_value (libfcn, NULL_RTX, LCT_CONST,
4894 GET_MODE (to), 1, from,
4895 GET_MODE (from));
4896 insns = get_insns ();
4897 end_sequence ();
4899 emit_libcall_block (insns, target, value,
4900 gen_rtx_FLOAT (GET_MODE (to), from));
4903 done:
4905 /* Copy result to requested destination
4906 if we have been computing in a temp location. */
4908 if (target != to)
4910 if (GET_MODE (target) == GET_MODE (to))
4911 emit_move_insn (to, target);
4912 else
4913 convert_move (to, target, 0);
4917 /* expand_fix: generate code to convert FROM to fixed point
4918 and store in TO. FROM must be floating point. */
4920 static rtx
4921 ftruncify (x)
4922 rtx x;
4924 rtx temp = gen_reg_rtx (GET_MODE (x));
4925 return expand_unop (GET_MODE (x), ftrunc_optab, x, temp, 0);
4928 void
4929 expand_fix (to, from, unsignedp)
4930 rtx to, from;
4931 int unsignedp;
4933 enum insn_code icode;
4934 rtx target = to;
4935 enum machine_mode fmode, imode;
4936 int must_trunc = 0;
4937 rtx libfcn = 0;
4939 /* We first try to find a pair of modes, one real and one integer, at
4940 least as wide as FROM and TO, respectively, in which we can open-code
4941 this conversion. If the integer mode is wider than the mode of TO,
4942 we can do the conversion either signed or unsigned. */
4944 for (fmode = GET_MODE (from); fmode != VOIDmode;
4945 fmode = GET_MODE_WIDER_MODE (fmode))
4946 for (imode = GET_MODE (to); imode != VOIDmode;
4947 imode = GET_MODE_WIDER_MODE (imode))
4949 int doing_unsigned = unsignedp;
4951 icode = can_fix_p (imode, fmode, unsignedp, &must_trunc);
4952 if (icode == CODE_FOR_nothing && imode != GET_MODE (to) && unsignedp)
4953 icode = can_fix_p (imode, fmode, 0, &must_trunc), doing_unsigned = 0;
4955 if (icode != CODE_FOR_nothing)
4957 to = protect_from_queue (to, 1);
4958 from = protect_from_queue (from, 0);
4960 if (fmode != GET_MODE (from))
4961 from = convert_to_mode (fmode, from, 0);
4963 if (must_trunc)
4964 from = ftruncify (from);
4966 if (imode != GET_MODE (to))
4967 target = gen_reg_rtx (imode);
4969 emit_unop_insn (icode, target, from,
4970 doing_unsigned ? UNSIGNED_FIX : FIX);
4971 if (target != to)
4972 convert_move (to, target, unsignedp);
4973 return;
4977 /* For an unsigned conversion, there is one more way to do it.
4978 If we have a signed conversion, we generate code that compares
4979 the real value to the largest representable positive number. If if
4980 is smaller, the conversion is done normally. Otherwise, subtract
4981 one plus the highest signed number, convert, and add it back.
4983 We only need to check all real modes, since we know we didn't find
4984 anything with a wider integer mode. */
4986 if (unsignedp && GET_MODE_BITSIZE (GET_MODE (to)) <= HOST_BITS_PER_WIDE_INT)
4987 for (fmode = GET_MODE (from); fmode != VOIDmode;
4988 fmode = GET_MODE_WIDER_MODE (fmode))
4989 /* Make sure we won't lose significant bits doing this. */
4990 if (GET_MODE_BITSIZE (fmode) > GET_MODE_BITSIZE (GET_MODE (to))
4991 && CODE_FOR_nothing != can_fix_p (GET_MODE (to), fmode, 0,
4992 &must_trunc))
4994 int bitsize;
4995 REAL_VALUE_TYPE offset;
4996 rtx limit, lab1, lab2, insn;
4998 bitsize = GET_MODE_BITSIZE (GET_MODE (to));
4999 real_2expN (&offset, bitsize - 1);
5000 limit = CONST_DOUBLE_FROM_REAL_VALUE (offset, fmode);
5001 lab1 = gen_label_rtx ();
5002 lab2 = gen_label_rtx ();
5004 emit_queue ();
5005 to = protect_from_queue (to, 1);
5006 from = protect_from_queue (from, 0);
5008 if (flag_force_mem)
5009 from = force_not_mem (from);
5011 if (fmode != GET_MODE (from))
5012 from = convert_to_mode (fmode, from, 0);
5014 /* See if we need to do the subtraction. */
5015 do_pending_stack_adjust ();
5016 emit_cmp_and_jump_insns (from, limit, GE, NULL_RTX, GET_MODE (from),
5017 0, lab1);
5019 /* If not, do the signed "fix" and branch around fixup code. */
5020 expand_fix (to, from, 0);
5021 emit_jump_insn (gen_jump (lab2));
5022 emit_barrier ();
5024 /* Otherwise, subtract 2**(N-1), convert to signed number,
5025 then add 2**(N-1). Do the addition using XOR since this
5026 will often generate better code. */
5027 emit_label (lab1);
5028 target = expand_binop (GET_MODE (from), sub_optab, from, limit,
5029 NULL_RTX, 0, OPTAB_LIB_WIDEN);
5030 expand_fix (to, target, 0);
5031 target = expand_binop (GET_MODE (to), xor_optab, to,
5032 gen_int_mode
5033 ((HOST_WIDE_INT) 1 << (bitsize - 1),
5034 GET_MODE (to)),
5035 to, 1, OPTAB_LIB_WIDEN);
5037 if (target != to)
5038 emit_move_insn (to, target);
5040 emit_label (lab2);
5042 if (mov_optab->handlers[(int) GET_MODE (to)].insn_code
5043 != CODE_FOR_nothing)
5045 /* Make a place for a REG_NOTE and add it. */
5046 insn = emit_move_insn (to, to);
5047 set_unique_reg_note (insn,
5048 REG_EQUAL,
5049 gen_rtx_fmt_e (UNSIGNED_FIX,
5050 GET_MODE (to),
5051 copy_rtx (from)));
5054 return;
5057 /* We can't do it with an insn, so use a library call. But first ensure
5058 that the mode of TO is at least as wide as SImode, since those are the
5059 only library calls we know about. */
5061 if (GET_MODE_SIZE (GET_MODE (to)) < GET_MODE_SIZE (SImode))
5063 target = gen_reg_rtx (SImode);
5065 expand_fix (target, from, unsignedp);
5067 else if (GET_MODE (from) == SFmode)
5069 if (GET_MODE (to) == SImode)
5070 libfcn = unsignedp ? fixunssfsi_libfunc : fixsfsi_libfunc;
5071 else if (GET_MODE (to) == DImode)
5072 libfcn = unsignedp ? fixunssfdi_libfunc : fixsfdi_libfunc;
5073 else if (GET_MODE (to) == TImode)
5074 libfcn = unsignedp ? fixunssfti_libfunc : fixsfti_libfunc;
5075 else
5076 abort ();
5078 else if (GET_MODE (from) == DFmode)
5080 if (GET_MODE (to) == SImode)
5081 libfcn = unsignedp ? fixunsdfsi_libfunc : fixdfsi_libfunc;
5082 else if (GET_MODE (to) == DImode)
5083 libfcn = unsignedp ? fixunsdfdi_libfunc : fixdfdi_libfunc;
5084 else if (GET_MODE (to) == TImode)
5085 libfcn = unsignedp ? fixunsdfti_libfunc : fixdfti_libfunc;
5086 else
5087 abort ();
5089 else if (GET_MODE (from) == XFmode)
5091 if (GET_MODE (to) == SImode)
5092 libfcn = unsignedp ? fixunsxfsi_libfunc : fixxfsi_libfunc;
5093 else if (GET_MODE (to) == DImode)
5094 libfcn = unsignedp ? fixunsxfdi_libfunc : fixxfdi_libfunc;
5095 else if (GET_MODE (to) == TImode)
5096 libfcn = unsignedp ? fixunsxfti_libfunc : fixxfti_libfunc;
5097 else
5098 abort ();
5100 else if (GET_MODE (from) == TFmode)
5102 if (GET_MODE (to) == SImode)
5103 libfcn = unsignedp ? fixunstfsi_libfunc : fixtfsi_libfunc;
5104 else if (GET_MODE (to) == DImode)
5105 libfcn = unsignedp ? fixunstfdi_libfunc : fixtfdi_libfunc;
5106 else if (GET_MODE (to) == TImode)
5107 libfcn = unsignedp ? fixunstfti_libfunc : fixtfti_libfunc;
5108 else
5109 abort ();
5111 else
5112 abort ();
5114 if (libfcn)
5116 rtx insns;
5117 rtx value;
5119 to = protect_from_queue (to, 1);
5120 from = protect_from_queue (from, 0);
5122 if (flag_force_mem)
5123 from = force_not_mem (from);
5125 start_sequence ();
5127 value = emit_library_call_value (libfcn, NULL_RTX, LCT_CONST,
5128 GET_MODE (to), 1, from,
5129 GET_MODE (from));
5130 insns = get_insns ();
5131 end_sequence ();
5133 emit_libcall_block (insns, target, value,
5134 gen_rtx_fmt_e (unsignedp ? UNSIGNED_FIX : FIX,
5135 GET_MODE (to), from));
5138 if (target != to)
5140 if (GET_MODE (to) == GET_MODE (target))
5141 emit_move_insn (to, target);
5142 else
5143 convert_move (to, target, 0);
5147 /* Report whether we have an instruction to perform the operation
5148 specified by CODE on operands of mode MODE. */
5150 have_insn_for (code, mode)
5151 enum rtx_code code;
5152 enum machine_mode mode;
5154 return (code_to_optab[(int) code] != 0
5155 && (code_to_optab[(int) code]->handlers[(int) mode].insn_code
5156 != CODE_FOR_nothing));
5159 /* Create a blank optab. */
5160 static optab
5161 new_optab ()
5163 int i;
5164 optab op = (optab) ggc_alloc (sizeof (struct optab));
5165 for (i = 0; i < NUM_MACHINE_MODES; i++)
5167 op->handlers[i].insn_code = CODE_FOR_nothing;
5168 op->handlers[i].libfunc = 0;
5171 return op;
5174 /* Same, but fill in its code as CODE, and write it into the
5175 code_to_optab table. */
5176 static inline optab
5177 init_optab (code)
5178 enum rtx_code code;
5180 optab op = new_optab ();
5181 op->code = code;
5182 code_to_optab[(int) code] = op;
5183 return op;
5186 /* Same, but fill in its code as CODE, and do _not_ write it into
5187 the code_to_optab table. */
5188 static inline optab
5189 init_optabv (code)
5190 enum rtx_code code;
5192 optab op = new_optab ();
5193 op->code = code;
5194 return op;
5197 /* Initialize the libfunc fields of an entire group of entries in some
5198 optab. Each entry is set equal to a string consisting of a leading
5199 pair of underscores followed by a generic operation name followed by
5200 a mode name (downshifted to lower case) followed by a single character
5201 representing the number of operands for the given operation (which is
5202 usually one of the characters '2', '3', or '4').
5204 OPTABLE is the table in which libfunc fields are to be initialized.
5205 FIRST_MODE is the first machine mode index in the given optab to
5206 initialize.
5207 LAST_MODE is the last machine mode index in the given optab to
5208 initialize.
5209 OPNAME is the generic (string) name of the operation.
5210 SUFFIX is the character which specifies the number of operands for
5211 the given generic operation.
5214 static void
5215 init_libfuncs (optable, first_mode, last_mode, opname, suffix)
5216 optab optable;
5217 int first_mode;
5218 int last_mode;
5219 const char *opname;
5220 int suffix;
5222 int mode;
5223 unsigned opname_len = strlen (opname);
5225 for (mode = first_mode; (int) mode <= (int) last_mode;
5226 mode = (enum machine_mode) ((int) mode + 1))
5228 const char *mname = GET_MODE_NAME (mode);
5229 unsigned mname_len = strlen (mname);
5230 char *libfunc_name = alloca (2 + opname_len + mname_len + 1 + 1);
5231 char *p;
5232 const char *q;
5234 p = libfunc_name;
5235 *p++ = '_';
5236 *p++ = '_';
5237 for (q = opname; *q; )
5238 *p++ = *q++;
5239 for (q = mname; *q; q++)
5240 *p++ = TOLOWER (*q);
5241 *p++ = suffix;
5242 *p = '\0';
5244 optable->handlers[(int) mode].libfunc
5245 = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (libfunc_name,
5246 p - libfunc_name));
5250 /* Initialize the libfunc fields of an entire group of entries in some
5251 optab which correspond to all integer mode operations. The parameters
5252 have the same meaning as similarly named ones for the `init_libfuncs'
5253 routine. (See above). */
5255 static void
5256 init_integral_libfuncs (optable, opname, suffix)
5257 optab optable;
5258 const char *opname;
5259 int suffix;
5261 init_libfuncs (optable, SImode, TImode, opname, suffix);
5264 /* Initialize the libfunc fields of an entire group of entries in some
5265 optab which correspond to all real mode operations. The parameters
5266 have the same meaning as similarly named ones for the `init_libfuncs'
5267 routine. (See above). */
5269 static void
5270 init_floating_libfuncs (optable, opname, suffix)
5271 optab optable;
5272 const char *opname;
5273 int suffix;
5275 init_libfuncs (optable, SFmode, TFmode, opname, suffix);
5279 init_one_libfunc (name)
5280 const char *name;
5282 /* Create a FUNCTION_DECL that can be passed to
5283 targetm.encode_section_info. */
5284 /* ??? We don't have any type information except for this is
5285 a function. Pretend this is "int foo()". */
5286 tree decl = build_decl (FUNCTION_DECL, get_identifier (name),
5287 build_function_type (integer_type_node, NULL_TREE));
5288 DECL_ARTIFICIAL (decl) = 1;
5289 DECL_EXTERNAL (decl) = 1;
5290 TREE_PUBLIC (decl) = 1;
5292 /* Return the symbol_ref from the mem rtx. */
5293 return XEXP (DECL_RTL (decl), 0);
5296 /* Call this once to initialize the contents of the optabs
5297 appropriately for the current target machine. */
5299 void
5300 init_optabs ()
5302 unsigned int i, j, k;
5304 /* Start by initializing all tables to contain CODE_FOR_nothing. */
5306 for (i = 0; i < ARRAY_SIZE (fixtab); i++)
5307 for (j = 0; j < ARRAY_SIZE (fixtab[0]); j++)
5308 for (k = 0; k < ARRAY_SIZE (fixtab[0][0]); k++)
5309 fixtab[i][j][k] = CODE_FOR_nothing;
5311 for (i = 0; i < ARRAY_SIZE (fixtrunctab); i++)
5312 for (j = 0; j < ARRAY_SIZE (fixtrunctab[0]); j++)
5313 for (k = 0; k < ARRAY_SIZE (fixtrunctab[0][0]); k++)
5314 fixtrunctab[i][j][k] = CODE_FOR_nothing;
5316 for (i = 0; i < ARRAY_SIZE (floattab); i++)
5317 for (j = 0; j < ARRAY_SIZE (floattab[0]); j++)
5318 for (k = 0; k < ARRAY_SIZE (floattab[0][0]); k++)
5319 floattab[i][j][k] = CODE_FOR_nothing;
5321 for (i = 0; i < ARRAY_SIZE (extendtab); i++)
5322 for (j = 0; j < ARRAY_SIZE (extendtab[0]); j++)
5323 for (k = 0; k < ARRAY_SIZE (extendtab[0][0]); k++)
5324 extendtab[i][j][k] = CODE_FOR_nothing;
5326 for (i = 0; i < NUM_RTX_CODE; i++)
5327 setcc_gen_code[i] = CODE_FOR_nothing;
5329 #ifdef HAVE_conditional_move
5330 for (i = 0; i < NUM_MACHINE_MODES; i++)
5331 movcc_gen_code[i] = CODE_FOR_nothing;
5332 #endif
5334 add_optab = init_optab (PLUS);
5335 addv_optab = init_optabv (PLUS);
5336 sub_optab = init_optab (MINUS);
5337 subv_optab = init_optabv (MINUS);
5338 smul_optab = init_optab (MULT);
5339 smulv_optab = init_optabv (MULT);
5340 smul_highpart_optab = init_optab (UNKNOWN);
5341 umul_highpart_optab = init_optab (UNKNOWN);
5342 smul_widen_optab = init_optab (UNKNOWN);
5343 umul_widen_optab = init_optab (UNKNOWN);
5344 sdiv_optab = init_optab (DIV);
5345 sdivv_optab = init_optabv (DIV);
5346 sdivmod_optab = init_optab (UNKNOWN);
5347 udiv_optab = init_optab (UDIV);
5348 udivmod_optab = init_optab (UNKNOWN);
5349 smod_optab = init_optab (MOD);
5350 umod_optab = init_optab (UMOD);
5351 ftrunc_optab = init_optab (UNKNOWN);
5352 and_optab = init_optab (AND);
5353 ior_optab = init_optab (IOR);
5354 xor_optab = init_optab (XOR);
5355 ashl_optab = init_optab (ASHIFT);
5356 ashr_optab = init_optab (ASHIFTRT);
5357 lshr_optab = init_optab (LSHIFTRT);
5358 rotl_optab = init_optab (ROTATE);
5359 rotr_optab = init_optab (ROTATERT);
5360 smin_optab = init_optab (SMIN);
5361 smax_optab = init_optab (SMAX);
5362 umin_optab = init_optab (UMIN);
5363 umax_optab = init_optab (UMAX);
5365 /* These three have codes assigned exclusively for the sake of
5366 have_insn_for. */
5367 mov_optab = init_optab (SET);
5368 movstrict_optab = init_optab (STRICT_LOW_PART);
5369 cmp_optab = init_optab (COMPARE);
5371 ucmp_optab = init_optab (UNKNOWN);
5372 tst_optab = init_optab (UNKNOWN);
5373 neg_optab = init_optab (NEG);
5374 negv_optab = init_optabv (NEG);
5375 abs_optab = init_optab (ABS);
5376 absv_optab = init_optabv (ABS);
5377 addcc_optab = init_optab (UNKNOWN);
5378 one_cmpl_optab = init_optab (NOT);
5379 ffs_optab = init_optab (FFS);
5380 sqrt_optab = init_optab (SQRT);
5381 floor_optab = init_optab (UNKNOWN);
5382 ceil_optab = init_optab (UNKNOWN);
5383 round_optab = init_optab (UNKNOWN);
5384 trunc_optab = init_optab (UNKNOWN);
5385 nearbyint_optab = init_optab (UNKNOWN);
5386 sin_optab = init_optab (UNKNOWN);
5387 cos_optab = init_optab (UNKNOWN);
5388 exp_optab = init_optab (UNKNOWN);
5389 log_optab = init_optab (UNKNOWN);
5390 strlen_optab = init_optab (UNKNOWN);
5391 cbranch_optab = init_optab (UNKNOWN);
5392 cmov_optab = init_optab (UNKNOWN);
5393 cstore_optab = init_optab (UNKNOWN);
5394 push_optab = init_optab (UNKNOWN);
5396 for (i = 0; i < NUM_MACHINE_MODES; i++)
5398 movstr_optab[i] = CODE_FOR_nothing;
5399 clrstr_optab[i] = CODE_FOR_nothing;
5401 #ifdef HAVE_SECONDARY_RELOADS
5402 reload_in_optab[i] = reload_out_optab[i] = CODE_FOR_nothing;
5403 #endif
5406 /* Fill in the optabs with the insns we support. */
5407 init_all_optabs ();
5409 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
5410 /* This flag says the same insns that convert to a signed fixnum
5411 also convert validly to an unsigned one. */
5412 for (i = 0; i < NUM_MACHINE_MODES; i++)
5413 for (j = 0; j < NUM_MACHINE_MODES; j++)
5414 fixtrunctab[i][j][1] = fixtrunctab[i][j][0];
5415 #endif
5417 /* Initialize the optabs with the names of the library functions. */
5418 init_integral_libfuncs (add_optab, "add", '3');
5419 init_floating_libfuncs (add_optab, "add", '3');
5420 init_integral_libfuncs (addv_optab, "addv", '3');
5421 init_floating_libfuncs (addv_optab, "add", '3');
5422 init_integral_libfuncs (sub_optab, "sub", '3');
5423 init_floating_libfuncs (sub_optab, "sub", '3');
5424 init_integral_libfuncs (subv_optab, "subv", '3');
5425 init_floating_libfuncs (subv_optab, "sub", '3');
5426 init_integral_libfuncs (smul_optab, "mul", '3');
5427 init_floating_libfuncs (smul_optab, "mul", '3');
5428 init_integral_libfuncs (smulv_optab, "mulv", '3');
5429 init_floating_libfuncs (smulv_optab, "mul", '3');
5430 init_integral_libfuncs (sdiv_optab, "div", '3');
5431 init_floating_libfuncs (sdiv_optab, "div", '3');
5432 init_integral_libfuncs (sdivv_optab, "divv", '3');
5433 init_integral_libfuncs (udiv_optab, "udiv", '3');
5434 init_integral_libfuncs (sdivmod_optab, "divmod", '4');
5435 init_integral_libfuncs (udivmod_optab, "udivmod", '4');
5436 init_integral_libfuncs (smod_optab, "mod", '3');
5437 init_integral_libfuncs (umod_optab, "umod", '3');
5438 init_floating_libfuncs (ftrunc_optab, "ftrunc", '2');
5439 init_integral_libfuncs (and_optab, "and", '3');
5440 init_integral_libfuncs (ior_optab, "ior", '3');
5441 init_integral_libfuncs (xor_optab, "xor", '3');
5442 init_integral_libfuncs (ashl_optab, "ashl", '3');
5443 init_integral_libfuncs (ashr_optab, "ashr", '3');
5444 init_integral_libfuncs (lshr_optab, "lshr", '3');
5445 init_integral_libfuncs (smin_optab, "min", '3');
5446 init_floating_libfuncs (smin_optab, "min", '3');
5447 init_integral_libfuncs (smax_optab, "max", '3');
5448 init_floating_libfuncs (smax_optab, "max", '3');
5449 init_integral_libfuncs (umin_optab, "umin", '3');
5450 init_integral_libfuncs (umax_optab, "umax", '3');
5451 init_integral_libfuncs (neg_optab, "neg", '2');
5452 init_floating_libfuncs (neg_optab, "neg", '2');
5453 init_integral_libfuncs (negv_optab, "negv", '2');
5454 init_floating_libfuncs (negv_optab, "neg", '2');
5455 init_integral_libfuncs (one_cmpl_optab, "one_cmpl", '2');
5456 init_integral_libfuncs (ffs_optab, "ffs", '2');
5458 /* Comparison libcalls for integers MUST come in pairs, signed/unsigned. */
5459 init_integral_libfuncs (cmp_optab, "cmp", '2');
5460 init_integral_libfuncs (ucmp_optab, "ucmp", '2');
5461 init_floating_libfuncs (cmp_optab, "cmp", '2');
5463 #ifdef MULSI3_LIBCALL
5464 smul_optab->handlers[(int) SImode].libfunc
5465 = init_one_libfunc (MULSI3_LIBCALL);
5466 #endif
5467 #ifdef MULDI3_LIBCALL
5468 smul_optab->handlers[(int) DImode].libfunc
5469 = init_one_libfunc (MULDI3_LIBCALL);
5470 #endif
5472 #ifdef DIVSI3_LIBCALL
5473 sdiv_optab->handlers[(int) SImode].libfunc
5474 = init_one_libfunc (DIVSI3_LIBCALL);
5475 #endif
5476 #ifdef DIVDI3_LIBCALL
5477 sdiv_optab->handlers[(int) DImode].libfunc
5478 = init_one_libfunc (DIVDI3_LIBCALL);
5479 #endif
5481 #ifdef UDIVSI3_LIBCALL
5482 udiv_optab->handlers[(int) SImode].libfunc
5483 = init_one_libfunc (UDIVSI3_LIBCALL);
5484 #endif
5485 #ifdef UDIVDI3_LIBCALL
5486 udiv_optab->handlers[(int) DImode].libfunc
5487 = init_one_libfunc (UDIVDI3_LIBCALL);
5488 #endif
5490 #ifdef MODSI3_LIBCALL
5491 smod_optab->handlers[(int) SImode].libfunc
5492 = init_one_libfunc (MODSI3_LIBCALL);
5493 #endif
5494 #ifdef MODDI3_LIBCALL
5495 smod_optab->handlers[(int) DImode].libfunc
5496 = init_one_libfunc (MODDI3_LIBCALL);
5497 #endif
5499 #ifdef UMODSI3_LIBCALL
5500 umod_optab->handlers[(int) SImode].libfunc
5501 = init_one_libfunc (UMODSI3_LIBCALL);
5502 #endif
5503 #ifdef UMODDI3_LIBCALL
5504 umod_optab->handlers[(int) DImode].libfunc
5505 = init_one_libfunc (UMODDI3_LIBCALL);
5506 #endif
5508 /* Use cabs for DC complex abs, since systems generally have cabs.
5509 Don't define any libcall for SCmode, so that cabs will be used. */
5510 abs_optab->handlers[(int) DCmode].libfunc
5511 = init_one_libfunc ("cabs");
5513 /* The ffs function operates on `int'. */
5514 ffs_optab->handlers[(int) mode_for_size (INT_TYPE_SIZE, MODE_INT, 0)].libfunc
5515 = init_one_libfunc ("ffs");
5517 extendsfdf2_libfunc = init_one_libfunc ("__extendsfdf2");
5518 extendsfxf2_libfunc = init_one_libfunc ("__extendsfxf2");
5519 extendsftf2_libfunc = init_one_libfunc ("__extendsftf2");
5520 extenddfxf2_libfunc = init_one_libfunc ("__extenddfxf2");
5521 extenddftf2_libfunc = init_one_libfunc ("__extenddftf2");
5523 truncdfsf2_libfunc = init_one_libfunc ("__truncdfsf2");
5524 truncxfsf2_libfunc = init_one_libfunc ("__truncxfsf2");
5525 trunctfsf2_libfunc = init_one_libfunc ("__trunctfsf2");
5526 truncxfdf2_libfunc = init_one_libfunc ("__truncxfdf2");
5527 trunctfdf2_libfunc = init_one_libfunc ("__trunctfdf2");
5529 abort_libfunc = init_one_libfunc ("abort");
5530 memcpy_libfunc = init_one_libfunc ("memcpy");
5531 memmove_libfunc = init_one_libfunc ("memmove");
5532 bcopy_libfunc = init_one_libfunc ("bcopy");
5533 memcmp_libfunc = init_one_libfunc ("memcmp");
5534 bcmp_libfunc = init_one_libfunc ("__gcc_bcmp");
5535 memset_libfunc = init_one_libfunc ("memset");
5536 bzero_libfunc = init_one_libfunc ("bzero");
5538 unwind_resume_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
5539 ? "_Unwind_SjLj_Resume"
5540 : "_Unwind_Resume");
5541 #ifndef DONT_USE_BUILTIN_SETJMP
5542 setjmp_libfunc = init_one_libfunc ("__builtin_setjmp");
5543 longjmp_libfunc = init_one_libfunc ("__builtin_longjmp");
5544 #else
5545 setjmp_libfunc = init_one_libfunc ("setjmp");
5546 longjmp_libfunc = init_one_libfunc ("longjmp");
5547 #endif
5548 unwind_sjlj_register_libfunc = init_one_libfunc ("_Unwind_SjLj_Register");
5549 unwind_sjlj_unregister_libfunc
5550 = init_one_libfunc ("_Unwind_SjLj_Unregister");
5552 eqhf2_libfunc = init_one_libfunc ("__eqhf2");
5553 nehf2_libfunc = init_one_libfunc ("__nehf2");
5554 gthf2_libfunc = init_one_libfunc ("__gthf2");
5555 gehf2_libfunc = init_one_libfunc ("__gehf2");
5556 lthf2_libfunc = init_one_libfunc ("__lthf2");
5557 lehf2_libfunc = init_one_libfunc ("__lehf2");
5558 unordhf2_libfunc = init_one_libfunc ("__unordhf2");
5560 eqsf2_libfunc = init_one_libfunc ("__eqsf2");
5561 nesf2_libfunc = init_one_libfunc ("__nesf2");
5562 gtsf2_libfunc = init_one_libfunc ("__gtsf2");
5563 gesf2_libfunc = init_one_libfunc ("__gesf2");
5564 ltsf2_libfunc = init_one_libfunc ("__ltsf2");
5565 lesf2_libfunc = init_one_libfunc ("__lesf2");
5566 unordsf2_libfunc = init_one_libfunc ("__unordsf2");
5568 eqdf2_libfunc = init_one_libfunc ("__eqdf2");
5569 nedf2_libfunc = init_one_libfunc ("__nedf2");
5570 gtdf2_libfunc = init_one_libfunc ("__gtdf2");
5571 gedf2_libfunc = init_one_libfunc ("__gedf2");
5572 ltdf2_libfunc = init_one_libfunc ("__ltdf2");
5573 ledf2_libfunc = init_one_libfunc ("__ledf2");
5574 unorddf2_libfunc = init_one_libfunc ("__unorddf2");
5576 eqxf2_libfunc = init_one_libfunc ("__eqxf2");
5577 nexf2_libfunc = init_one_libfunc ("__nexf2");
5578 gtxf2_libfunc = init_one_libfunc ("__gtxf2");
5579 gexf2_libfunc = init_one_libfunc ("__gexf2");
5580 ltxf2_libfunc = init_one_libfunc ("__ltxf2");
5581 lexf2_libfunc = init_one_libfunc ("__lexf2");
5582 unordxf2_libfunc = init_one_libfunc ("__unordxf2");
5584 eqtf2_libfunc = init_one_libfunc ("__eqtf2");
5585 netf2_libfunc = init_one_libfunc ("__netf2");
5586 gttf2_libfunc = init_one_libfunc ("__gttf2");
5587 getf2_libfunc = init_one_libfunc ("__getf2");
5588 lttf2_libfunc = init_one_libfunc ("__lttf2");
5589 letf2_libfunc = init_one_libfunc ("__letf2");
5590 unordtf2_libfunc = init_one_libfunc ("__unordtf2");
5592 floatsisf_libfunc = init_one_libfunc ("__floatsisf");
5593 floatdisf_libfunc = init_one_libfunc ("__floatdisf");
5594 floattisf_libfunc = init_one_libfunc ("__floattisf");
5596 floatsidf_libfunc = init_one_libfunc ("__floatsidf");
5597 floatdidf_libfunc = init_one_libfunc ("__floatdidf");
5598 floattidf_libfunc = init_one_libfunc ("__floattidf");
5600 floatsixf_libfunc = init_one_libfunc ("__floatsixf");
5601 floatdixf_libfunc = init_one_libfunc ("__floatdixf");
5602 floattixf_libfunc = init_one_libfunc ("__floattixf");
5604 floatsitf_libfunc = init_one_libfunc ("__floatsitf");
5605 floatditf_libfunc = init_one_libfunc ("__floatditf");
5606 floattitf_libfunc = init_one_libfunc ("__floattitf");
5608 fixsfsi_libfunc = init_one_libfunc ("__fixsfsi");
5609 fixsfdi_libfunc = init_one_libfunc ("__fixsfdi");
5610 fixsfti_libfunc = init_one_libfunc ("__fixsfti");
5612 fixdfsi_libfunc = init_one_libfunc ("__fixdfsi");
5613 fixdfdi_libfunc = init_one_libfunc ("__fixdfdi");
5614 fixdfti_libfunc = init_one_libfunc ("__fixdfti");
5616 fixxfsi_libfunc = init_one_libfunc ("__fixxfsi");
5617 fixxfdi_libfunc = init_one_libfunc ("__fixxfdi");
5618 fixxfti_libfunc = init_one_libfunc ("__fixxfti");
5620 fixtfsi_libfunc = init_one_libfunc ("__fixtfsi");
5621 fixtfdi_libfunc = init_one_libfunc ("__fixtfdi");
5622 fixtfti_libfunc = init_one_libfunc ("__fixtfti");
5624 fixunssfsi_libfunc = init_one_libfunc ("__fixunssfsi");
5625 fixunssfdi_libfunc = init_one_libfunc ("__fixunssfdi");
5626 fixunssfti_libfunc = init_one_libfunc ("__fixunssfti");
5628 fixunsdfsi_libfunc = init_one_libfunc ("__fixunsdfsi");
5629 fixunsdfdi_libfunc = init_one_libfunc ("__fixunsdfdi");
5630 fixunsdfti_libfunc = init_one_libfunc ("__fixunsdfti");
5632 fixunsxfsi_libfunc = init_one_libfunc ("__fixunsxfsi");
5633 fixunsxfdi_libfunc = init_one_libfunc ("__fixunsxfdi");
5634 fixunsxfti_libfunc = init_one_libfunc ("__fixunsxfti");
5636 fixunstfsi_libfunc = init_one_libfunc ("__fixunstfsi");
5637 fixunstfdi_libfunc = init_one_libfunc ("__fixunstfdi");
5638 fixunstfti_libfunc = init_one_libfunc ("__fixunstfti");
5640 /* For function entry/exit instrumentation. */
5641 profile_function_entry_libfunc
5642 = init_one_libfunc ("__cyg_profile_func_enter");
5643 profile_function_exit_libfunc
5644 = init_one_libfunc ("__cyg_profile_func_exit");
5646 #ifdef HAVE_conditional_trap
5647 init_traps ();
5648 #endif
5650 #ifdef INIT_TARGET_OPTABS
5651 /* Allow the target to add more libcalls or rename some, etc. */
5652 INIT_TARGET_OPTABS;
5653 #endif
5656 static GTY(()) rtx trap_rtx;
5658 #ifdef HAVE_conditional_trap
5659 /* The insn generating function can not take an rtx_code argument.
5660 TRAP_RTX is used as an rtx argument. Its code is replaced with
5661 the code to be used in the trap insn and all other fields are
5662 ignored. */
5664 static void
5665 init_traps ()
5667 if (HAVE_conditional_trap)
5669 trap_rtx = gen_rtx_fmt_ee (EQ, VOIDmode, NULL_RTX, NULL_RTX);
5672 #endif
5674 /* Generate insns to trap with code TCODE if OP1 and OP2 satisfy condition
5675 CODE. Return 0 on failure. */
5678 gen_cond_trap (code, op1, op2, tcode)
5679 enum rtx_code code ATTRIBUTE_UNUSED;
5680 rtx op1, op2 ATTRIBUTE_UNUSED, tcode ATTRIBUTE_UNUSED;
5682 enum machine_mode mode = GET_MODE (op1);
5684 if (mode == VOIDmode)
5685 return 0;
5687 #ifdef HAVE_conditional_trap
5688 if (HAVE_conditional_trap
5689 && cmp_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
5691 rtx insn;
5692 start_sequence ();
5693 emit_insn (GEN_FCN (cmp_optab->handlers[(int) mode].insn_code) (op1, op2));
5694 PUT_CODE (trap_rtx, code);
5695 insn = gen_conditional_trap (trap_rtx, tcode);
5696 if (insn)
5698 emit_insn (insn);
5699 insn = get_insns ();
5701 end_sequence ();
5702 return insn;
5704 #endif
5706 return 0;
5709 #include "gt-optabs.h"