]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/optabs.c
Merge basic-improvements-branch to trunk
[thirdparty/gcc.git] / gcc / optabs.c
1 /* Expand the basic unary and binary arithmetic operations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
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.
11
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.
16
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. */
21
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "toplev.h"
28
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
46 /* Each optab contains info on how this target machine
47 can perform a particular operation
48 for all sizes and kinds of operands.
49
50 The operation to be performed is often specified
51 by passing one of these optabs as an argument.
52
53 See expr.h for documentation of these optabs. */
54
55 optab optab_table[OTI_MAX];
56
57 rtx libfunc_table[LTI_MAX];
58
59 /* Tables of patterns for extending one integer mode to another. */
60 enum insn_code extendtab[MAX_MACHINE_MODE][MAX_MACHINE_MODE][2];
61
62 /* Tables of patterns for converting between fixed and floating point. */
63 enum insn_code fixtab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
64 enum insn_code fixtrunctab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
65 enum insn_code floattab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
66
67 /* Contains the optab used for each rtx code. */
68 optab code_to_optab[NUM_RTX_CODE + 1];
69
70 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
71 gives the gen_function to make a branch to test that condition. */
72
73 rtxfun bcc_gen_fctn[NUM_RTX_CODE];
74
75 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
76 gives the insn code to make a store-condition insn
77 to test that condition. */
78
79 enum insn_code setcc_gen_code[NUM_RTX_CODE];
80
81 #ifdef HAVE_conditional_move
82 /* Indexed by the machine mode, gives the insn code to make a conditional
83 move insn. This is not indexed by the rtx-code like bcc_gen_fctn and
84 setcc_gen_code to cut down on the number of named patterns. Consider a day
85 when a lot more rtx codes are conditional (eg: for the ARM). */
86
87 enum insn_code movcc_gen_code[NUM_MACHINE_MODES];
88 #endif
89
90 static int add_equal_note PARAMS ((rtx, rtx, enum rtx_code, rtx, rtx));
91 static rtx widen_operand PARAMS ((rtx, enum machine_mode,
92 enum machine_mode, int, int));
93 static int expand_cmplxdiv_straight PARAMS ((rtx, rtx, rtx, rtx,
94 rtx, rtx, enum machine_mode,
95 int, enum optab_methods,
96 enum mode_class, optab));
97 static int expand_cmplxdiv_wide PARAMS ((rtx, rtx, rtx, rtx,
98 rtx, rtx, enum machine_mode,
99 int, enum optab_methods,
100 enum mode_class, optab));
101 static void prepare_cmp_insn PARAMS ((rtx *, rtx *, enum rtx_code *, rtx,
102 enum machine_mode *, int *,
103 enum can_compare_purpose));
104 static enum insn_code can_fix_p PARAMS ((enum machine_mode, enum machine_mode,
105 int, int *));
106 static enum insn_code can_float_p PARAMS ((enum machine_mode,
107 enum machine_mode,
108 int));
109 static rtx ftruncify PARAMS ((rtx));
110 static optab new_optab PARAMS ((void));
111 static inline optab init_optab PARAMS ((enum rtx_code));
112 static inline optab init_optabv PARAMS ((enum rtx_code));
113 static void init_libfuncs PARAMS ((optab, int, int, const char *, int));
114 static void init_integral_libfuncs PARAMS ((optab, const char *, int));
115 static void init_floating_libfuncs PARAMS ((optab, const char *, int));
116 #ifdef HAVE_conditional_trap
117 static void init_traps PARAMS ((void));
118 #endif
119 static void emit_cmp_and_jump_insn_1 PARAMS ((rtx, rtx, enum machine_mode,
120 enum rtx_code, int, rtx));
121 static void prepare_float_lib_cmp PARAMS ((rtx *, rtx *, enum rtx_code *,
122 enum machine_mode *, int *));
123 static rtx expand_vector_binop PARAMS ((enum machine_mode, optab,
124 rtx, rtx, rtx, int,
125 enum optab_methods));
126 static rtx expand_vector_unop PARAMS ((enum machine_mode, optab, rtx, rtx,
127 int));
128 \f
129 /* Add a REG_EQUAL note to the last insn in INSNS. TARGET is being set to
130 the result of operation CODE applied to OP0 (and OP1 if it is a binary
131 operation).
132
133 If the last insn does not set TARGET, don't do anything, but return 1.
134
135 If a previous insn sets TARGET and TARGET is one of OP0 or OP1,
136 don't add the REG_EQUAL note but return 0. Our caller can then try
137 again, ensuring that TARGET is not one of the operands. */
138
139 static int
140 add_equal_note (insns, target, code, op0, op1)
141 rtx insns;
142 rtx target;
143 enum rtx_code code;
144 rtx op0, op1;
145 {
146 rtx last_insn, insn, set;
147 rtx note;
148
149 if (! insns
150 || ! INSN_P (insns)
151 || NEXT_INSN (insns) == NULL_RTX)
152 abort ();
153
154 if (GET_RTX_CLASS (code) != '1' && GET_RTX_CLASS (code) != '2'
155 && GET_RTX_CLASS (code) != 'c' && GET_RTX_CLASS (code) != '<')
156 return 1;
157
158 if (GET_CODE (target) == ZERO_EXTRACT)
159 return 1;
160
161 for (last_insn = insns;
162 NEXT_INSN (last_insn) != NULL_RTX;
163 last_insn = NEXT_INSN (last_insn))
164 ;
165
166 set = single_set (last_insn);
167 if (set == NULL_RTX)
168 return 1;
169
170 if (! rtx_equal_p (SET_DEST (set), target)
171 /* For a STRICT_LOW_PART, the REG_NOTE applies to what is inside the
172 SUBREG. */
173 && (GET_CODE (SET_DEST (set)) != STRICT_LOW_PART
174 || ! rtx_equal_p (SUBREG_REG (XEXP (SET_DEST (set), 0)),
175 target)))
176 return 1;
177
178 /* If TARGET is in OP0 or OP1, check if anything in SEQ sets TARGET
179 besides the last insn. */
180 if (reg_overlap_mentioned_p (target, op0)
181 || (op1 && reg_overlap_mentioned_p (target, op1)))
182 {
183 insn = PREV_INSN (last_insn);
184 while (insn != NULL_RTX)
185 {
186 if (reg_set_p (target, insn))
187 return 0;
188
189 insn = PREV_INSN (insn);
190 }
191 }
192
193 if (GET_RTX_CLASS (code) == '1')
194 note = gen_rtx_fmt_e (code, GET_MODE (target), copy_rtx (op0));
195 else
196 note = gen_rtx_fmt_ee (code, GET_MODE (target), copy_rtx (op0), copy_rtx (op1));
197
198 set_unique_reg_note (last_insn, REG_EQUAL, note);
199
200 return 1;
201 }
202 \f
203 /* Widen OP to MODE and return the rtx for the widened operand. UNSIGNEDP
204 says whether OP is signed or unsigned. NO_EXTEND is nonzero if we need
205 not actually do a sign-extend or zero-extend, but can leave the
206 higher-order bits of the result rtx undefined, for example, in the case
207 of logical operations, but not right shifts. */
208
209 static rtx
210 widen_operand (op, mode, oldmode, unsignedp, no_extend)
211 rtx op;
212 enum machine_mode mode, oldmode;
213 int unsignedp;
214 int no_extend;
215 {
216 rtx result;
217
218 /* If we don't have to extend and this is a constant, return it. */
219 if (no_extend && GET_MODE (op) == VOIDmode)
220 return op;
221
222 /* If we must extend do so. If OP is a SUBREG for a promoted object, also
223 extend since it will be more efficient to do so unless the signedness of
224 a promoted object differs from our extension. */
225 if (! no_extend
226 || (GET_CODE (op) == SUBREG && SUBREG_PROMOTED_VAR_P (op)
227 && SUBREG_PROMOTED_UNSIGNED_P (op) == unsignedp))
228 return convert_modes (mode, oldmode, op, unsignedp);
229
230 /* If MODE is no wider than a single word, we return a paradoxical
231 SUBREG. */
232 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
233 return gen_rtx_SUBREG (mode, force_reg (GET_MODE (op), op), 0);
234
235 /* Otherwise, get an object of MODE, clobber it, and set the low-order
236 part to OP. */
237
238 result = gen_reg_rtx (mode);
239 emit_insn (gen_rtx_CLOBBER (VOIDmode, result));
240 emit_move_insn (gen_lowpart (GET_MODE (op), result), op);
241 return result;
242 }
243 \f
244 /* Generate code to perform a straightforward complex divide. */
245
246 static int
247 expand_cmplxdiv_straight (real0, real1, imag0, imag1, realr, imagr, submode,
248 unsignedp, methods, class, binoptab)
249 rtx real0, real1, imag0, imag1, realr, imagr;
250 enum machine_mode submode;
251 int unsignedp;
252 enum optab_methods methods;
253 enum mode_class class;
254 optab binoptab;
255 {
256 rtx divisor;
257 rtx real_t, imag_t;
258 rtx temp1, temp2;
259 rtx res;
260 optab this_add_optab = add_optab;
261 optab this_sub_optab = sub_optab;
262 optab this_neg_optab = neg_optab;
263 optab this_mul_optab = smul_optab;
264
265 if (binoptab == sdivv_optab)
266 {
267 this_add_optab = addv_optab;
268 this_sub_optab = subv_optab;
269 this_neg_optab = negv_optab;
270 this_mul_optab = smulv_optab;
271 }
272
273 /* Don't fetch these from memory more than once. */
274 real0 = force_reg (submode, real0);
275 real1 = force_reg (submode, real1);
276
277 if (imag0 != 0)
278 imag0 = force_reg (submode, imag0);
279
280 imag1 = force_reg (submode, imag1);
281
282 /* Divisor: c*c + d*d. */
283 temp1 = expand_binop (submode, this_mul_optab, real1, real1,
284 NULL_RTX, unsignedp, methods);
285
286 temp2 = expand_binop (submode, this_mul_optab, imag1, imag1,
287 NULL_RTX, unsignedp, methods);
288
289 if (temp1 == 0 || temp2 == 0)
290 return 0;
291
292 divisor = expand_binop (submode, this_add_optab, temp1, temp2,
293 NULL_RTX, unsignedp, methods);
294 if (divisor == 0)
295 return 0;
296
297 if (imag0 == 0)
298 {
299 /* Mathematically, ((a)(c-id))/divisor. */
300 /* Computationally, (a+i0) / (c+id) = (ac/(cc+dd)) + i(-ad/(cc+dd)). */
301
302 /* Calculate the dividend. */
303 real_t = expand_binop (submode, this_mul_optab, real0, real1,
304 NULL_RTX, unsignedp, methods);
305
306 imag_t = expand_binop (submode, this_mul_optab, real0, imag1,
307 NULL_RTX, unsignedp, methods);
308
309 if (real_t == 0 || imag_t == 0)
310 return 0;
311
312 imag_t = expand_unop (submode, this_neg_optab, imag_t,
313 NULL_RTX, unsignedp);
314 }
315 else
316 {
317 /* Mathematically, ((a+ib)(c-id))/divider. */
318 /* Calculate the dividend. */
319 temp1 = expand_binop (submode, this_mul_optab, real0, real1,
320 NULL_RTX, unsignedp, methods);
321
322 temp2 = expand_binop (submode, this_mul_optab, imag0, imag1,
323 NULL_RTX, unsignedp, methods);
324
325 if (temp1 == 0 || temp2 == 0)
326 return 0;
327
328 real_t = expand_binop (submode, this_add_optab, temp1, temp2,
329 NULL_RTX, unsignedp, methods);
330
331 temp1 = expand_binop (submode, this_mul_optab, imag0, real1,
332 NULL_RTX, unsignedp, methods);
333
334 temp2 = expand_binop (submode, this_mul_optab, real0, imag1,
335 NULL_RTX, unsignedp, methods);
336
337 if (temp1 == 0 || temp2 == 0)
338 return 0;
339
340 imag_t = expand_binop (submode, this_sub_optab, temp1, temp2,
341 NULL_RTX, unsignedp, methods);
342
343 if (real_t == 0 || imag_t == 0)
344 return 0;
345 }
346
347 if (class == MODE_COMPLEX_FLOAT)
348 res = expand_binop (submode, binoptab, real_t, divisor,
349 realr, unsignedp, methods);
350 else
351 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
352 real_t, divisor, realr, unsignedp);
353
354 if (res == 0)
355 return 0;
356
357 if (res != realr)
358 emit_move_insn (realr, res);
359
360 if (class == MODE_COMPLEX_FLOAT)
361 res = expand_binop (submode, binoptab, imag_t, divisor,
362 imagr, unsignedp, methods);
363 else
364 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
365 imag_t, divisor, imagr, unsignedp);
366
367 if (res == 0)
368 return 0;
369
370 if (res != imagr)
371 emit_move_insn (imagr, res);
372
373 return 1;
374 }
375 \f
376 /* Generate code to perform a wide-input-range-acceptable complex divide. */
377
378 static int
379 expand_cmplxdiv_wide (real0, real1, imag0, imag1, realr, imagr, submode,
380 unsignedp, methods, class, binoptab)
381 rtx real0, real1, imag0, imag1, realr, imagr;
382 enum machine_mode submode;
383 int unsignedp;
384 enum optab_methods methods;
385 enum mode_class class;
386 optab binoptab;
387 {
388 rtx ratio, divisor;
389 rtx real_t, imag_t;
390 rtx temp1, temp2, lab1, lab2;
391 enum machine_mode mode;
392 rtx res;
393 optab this_add_optab = add_optab;
394 optab this_sub_optab = sub_optab;
395 optab this_neg_optab = neg_optab;
396 optab this_mul_optab = smul_optab;
397
398 if (binoptab == sdivv_optab)
399 {
400 this_add_optab = addv_optab;
401 this_sub_optab = subv_optab;
402 this_neg_optab = negv_optab;
403 this_mul_optab = smulv_optab;
404 }
405
406 /* Don't fetch these from memory more than once. */
407 real0 = force_reg (submode, real0);
408 real1 = force_reg (submode, real1);
409
410 if (imag0 != 0)
411 imag0 = force_reg (submode, imag0);
412
413 imag1 = force_reg (submode, imag1);
414
415 /* XXX What's an "unsigned" complex number? */
416 if (unsignedp)
417 {
418 temp1 = real1;
419 temp2 = imag1;
420 }
421 else
422 {
423 temp1 = expand_abs (submode, real1, NULL_RTX, unsignedp, 1);
424 temp2 = expand_abs (submode, imag1, NULL_RTX, unsignedp, 1);
425 }
426
427 if (temp1 == 0 || temp2 == 0)
428 return 0;
429
430 mode = GET_MODE (temp1);
431 lab1 = gen_label_rtx ();
432 emit_cmp_and_jump_insns (temp1, temp2, LT, NULL_RTX,
433 mode, unsignedp, lab1);
434
435 /* |c| >= |d|; use ratio d/c to scale dividend and divisor. */
436
437 if (class == MODE_COMPLEX_FLOAT)
438 ratio = expand_binop (submode, binoptab, imag1, real1,
439 NULL_RTX, unsignedp, methods);
440 else
441 ratio = expand_divmod (0, TRUNC_DIV_EXPR, submode,
442 imag1, real1, NULL_RTX, unsignedp);
443
444 if (ratio == 0)
445 return 0;
446
447 /* Calculate divisor. */
448
449 temp1 = expand_binop (submode, this_mul_optab, imag1, ratio,
450 NULL_RTX, unsignedp, methods);
451
452 if (temp1 == 0)
453 return 0;
454
455 divisor = expand_binop (submode, this_add_optab, temp1, real1,
456 NULL_RTX, unsignedp, methods);
457
458 if (divisor == 0)
459 return 0;
460
461 /* Calculate dividend. */
462
463 if (imag0 == 0)
464 {
465 real_t = real0;
466
467 /* Compute a / (c+id) as a / (c+d(d/c)) + i (-a(d/c)) / (c+d(d/c)). */
468
469 imag_t = expand_binop (submode, this_mul_optab, real0, ratio,
470 NULL_RTX, unsignedp, methods);
471
472 if (imag_t == 0)
473 return 0;
474
475 imag_t = expand_unop (submode, this_neg_optab, imag_t,
476 NULL_RTX, unsignedp);
477
478 if (real_t == 0 || imag_t == 0)
479 return 0;
480 }
481 else
482 {
483 /* Compute (a+ib)/(c+id) as
484 (a+b(d/c))/(c+d(d/c) + i(b-a(d/c))/(c+d(d/c)). */
485
486 temp1 = expand_binop (submode, this_mul_optab, imag0, ratio,
487 NULL_RTX, unsignedp, methods);
488
489 if (temp1 == 0)
490 return 0;
491
492 real_t = expand_binop (submode, this_add_optab, temp1, real0,
493 NULL_RTX, unsignedp, methods);
494
495 temp1 = expand_binop (submode, this_mul_optab, real0, ratio,
496 NULL_RTX, unsignedp, methods);
497
498 if (temp1 == 0)
499 return 0;
500
501 imag_t = expand_binop (submode, this_sub_optab, imag0, temp1,
502 NULL_RTX, unsignedp, methods);
503
504 if (real_t == 0 || imag_t == 0)
505 return 0;
506 }
507
508 if (class == MODE_COMPLEX_FLOAT)
509 res = expand_binop (submode, binoptab, real_t, divisor,
510 realr, unsignedp, methods);
511 else
512 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
513 real_t, divisor, realr, unsignedp);
514
515 if (res == 0)
516 return 0;
517
518 if (res != realr)
519 emit_move_insn (realr, res);
520
521 if (class == MODE_COMPLEX_FLOAT)
522 res = expand_binop (submode, binoptab, imag_t, divisor,
523 imagr, unsignedp, methods);
524 else
525 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
526 imag_t, divisor, imagr, unsignedp);
527
528 if (res == 0)
529 return 0;
530
531 if (res != imagr)
532 emit_move_insn (imagr, res);
533
534 lab2 = gen_label_rtx ();
535 emit_jump_insn (gen_jump (lab2));
536 emit_barrier ();
537
538 emit_label (lab1);
539
540 /* |d| > |c|; use ratio c/d to scale dividend and divisor. */
541
542 if (class == MODE_COMPLEX_FLOAT)
543 ratio = expand_binop (submode, binoptab, real1, imag1,
544 NULL_RTX, unsignedp, methods);
545 else
546 ratio = expand_divmod (0, TRUNC_DIV_EXPR, submode,
547 real1, imag1, NULL_RTX, unsignedp);
548
549 if (ratio == 0)
550 return 0;
551
552 /* Calculate divisor. */
553
554 temp1 = expand_binop (submode, this_mul_optab, real1, ratio,
555 NULL_RTX, unsignedp, methods);
556
557 if (temp1 == 0)
558 return 0;
559
560 divisor = expand_binop (submode, this_add_optab, temp1, imag1,
561 NULL_RTX, unsignedp, methods);
562
563 if (divisor == 0)
564 return 0;
565
566 /* Calculate dividend. */
567
568 if (imag0 == 0)
569 {
570 /* Compute a / (c+id) as a(c/d) / (c(c/d)+d) + i (-a) / (c(c/d)+d). */
571
572 real_t = expand_binop (submode, this_mul_optab, real0, ratio,
573 NULL_RTX, unsignedp, methods);
574
575 imag_t = expand_unop (submode, this_neg_optab, real0,
576 NULL_RTX, unsignedp);
577
578 if (real_t == 0 || imag_t == 0)
579 return 0;
580 }
581 else
582 {
583 /* Compute (a+ib)/(c+id) as
584 (a(c/d)+b)/(c(c/d)+d) + i (b(c/d)-a)/(c(c/d)+d). */
585
586 temp1 = expand_binop (submode, this_mul_optab, real0, ratio,
587 NULL_RTX, unsignedp, methods);
588
589 if (temp1 == 0)
590 return 0;
591
592 real_t = expand_binop (submode, this_add_optab, temp1, imag0,
593 NULL_RTX, unsignedp, methods);
594
595 temp1 = expand_binop (submode, this_mul_optab, imag0, ratio,
596 NULL_RTX, unsignedp, methods);
597
598 if (temp1 == 0)
599 return 0;
600
601 imag_t = expand_binop (submode, this_sub_optab, temp1, real0,
602 NULL_RTX, unsignedp, methods);
603
604 if (real_t == 0 || imag_t == 0)
605 return 0;
606 }
607
608 if (class == MODE_COMPLEX_FLOAT)
609 res = expand_binop (submode, binoptab, real_t, divisor,
610 realr, unsignedp, methods);
611 else
612 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
613 real_t, divisor, realr, unsignedp);
614
615 if (res == 0)
616 return 0;
617
618 if (res != realr)
619 emit_move_insn (realr, res);
620
621 if (class == MODE_COMPLEX_FLOAT)
622 res = expand_binop (submode, binoptab, imag_t, divisor,
623 imagr, unsignedp, methods);
624 else
625 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
626 imag_t, divisor, imagr, unsignedp);
627
628 if (res == 0)
629 return 0;
630
631 if (res != imagr)
632 emit_move_insn (imagr, res);
633
634 emit_label (lab2);
635
636 return 1;
637 }
638 \f
639 /* Wrapper around expand_binop which takes an rtx code to specify
640 the operation to perform, not an optab pointer. All other
641 arguments are the same. */
642 rtx
643 expand_simple_binop (mode, code, op0, op1, target, unsignedp, methods)
644 enum machine_mode mode;
645 enum rtx_code code;
646 rtx op0, op1;
647 rtx target;
648 int unsignedp;
649 enum optab_methods methods;
650 {
651 optab binop = code_to_optab[(int) code];
652 if (binop == 0)
653 abort ();
654
655 return expand_binop (mode, binop, op0, op1, target, unsignedp, methods);
656 }
657
658 /* Generate code to perform an operation specified by BINOPTAB
659 on operands OP0 and OP1, with result having machine-mode MODE.
660
661 UNSIGNEDP is for the case where we have to widen the operands
662 to perform the operation. It says to use zero-extension.
663
664 If TARGET is nonzero, the value
665 is generated there, if it is convenient to do so.
666 In all cases an rtx is returned for the locus of the value;
667 this may or may not be TARGET. */
668
669 rtx
670 expand_binop (mode, binoptab, op0, op1, target, unsignedp, methods)
671 enum machine_mode mode;
672 optab binoptab;
673 rtx op0, op1;
674 rtx target;
675 int unsignedp;
676 enum optab_methods methods;
677 {
678 enum optab_methods next_methods
679 = (methods == OPTAB_LIB || methods == OPTAB_LIB_WIDEN
680 ? OPTAB_WIDEN : methods);
681 enum mode_class class;
682 enum machine_mode wider_mode;
683 rtx temp;
684 int commutative_op = 0;
685 int shift_op = (binoptab->code == ASHIFT
686 || binoptab->code == ASHIFTRT
687 || binoptab->code == LSHIFTRT
688 || binoptab->code == ROTATE
689 || binoptab->code == ROTATERT);
690 rtx entry_last = get_last_insn ();
691 rtx last;
692
693 class = GET_MODE_CLASS (mode);
694
695 op0 = protect_from_queue (op0, 0);
696 op1 = protect_from_queue (op1, 0);
697 if (target)
698 target = protect_from_queue (target, 1);
699
700 if (flag_force_mem)
701 {
702 op0 = force_not_mem (op0);
703 op1 = force_not_mem (op1);
704 }
705
706 /* If subtracting an integer constant, convert this into an addition of
707 the negated constant. */
708
709 if (binoptab == sub_optab && GET_CODE (op1) == CONST_INT)
710 {
711 op1 = negate_rtx (mode, op1);
712 binoptab = add_optab;
713 }
714
715 /* If we are inside an appropriately-short loop and one operand is an
716 expensive constant, force it into a register. */
717 if (CONSTANT_P (op0) && preserve_subexpressions_p ()
718 && rtx_cost (op0, binoptab->code) > COSTS_N_INSNS (1))
719 op0 = force_reg (mode, op0);
720
721 if (CONSTANT_P (op1) && preserve_subexpressions_p ()
722 && ! shift_op && rtx_cost (op1, binoptab->code) > COSTS_N_INSNS (1))
723 op1 = force_reg (mode, op1);
724
725 /* Record where to delete back to if we backtrack. */
726 last = get_last_insn ();
727
728 /* If operation is commutative,
729 try to make the first operand a register.
730 Even better, try to make it the same as the target.
731 Also try to make the last operand a constant. */
732 if (GET_RTX_CLASS (binoptab->code) == 'c'
733 || binoptab == smul_widen_optab
734 || binoptab == umul_widen_optab
735 || binoptab == smul_highpart_optab
736 || binoptab == umul_highpart_optab)
737 {
738 commutative_op = 1;
739
740 if (((target == 0 || GET_CODE (target) == REG)
741 ? ((GET_CODE (op1) == REG
742 && GET_CODE (op0) != REG)
743 || target == op1)
744 : rtx_equal_p (op1, target))
745 || GET_CODE (op0) == CONST_INT)
746 {
747 temp = op1;
748 op1 = op0;
749 op0 = temp;
750 }
751 }
752
753 /* If we can do it with a three-operand insn, do so. */
754
755 if (methods != OPTAB_MUST_WIDEN
756 && binoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
757 {
758 int icode = (int) binoptab->handlers[(int) mode].insn_code;
759 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
760 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
761 rtx pat;
762 rtx xop0 = op0, xop1 = op1;
763
764 if (target)
765 temp = target;
766 else
767 temp = gen_reg_rtx (mode);
768
769 /* If it is a commutative operator and the modes would match
770 if we would swap the operands, we can save the conversions. */
771 if (commutative_op)
772 {
773 if (GET_MODE (op0) != mode0 && GET_MODE (op1) != mode1
774 && GET_MODE (op0) == mode1 && GET_MODE (op1) == mode0)
775 {
776 rtx tmp;
777
778 tmp = op0; op0 = op1; op1 = tmp;
779 tmp = xop0; xop0 = xop1; xop1 = tmp;
780 }
781 }
782
783 /* In case the insn wants input operands in modes different from
784 those of the actual operands, convert the operands. It would
785 seem that we don't need to convert CONST_INTs, but we do, so
786 that they're properly zero-extended, sign-extended or truncated
787 for their mode. */
788
789 if (GET_MODE (op0) != mode0 && mode0 != VOIDmode)
790 xop0 = convert_modes (mode0,
791 GET_MODE (op0) != VOIDmode
792 ? GET_MODE (op0)
793 : mode,
794 xop0, unsignedp);
795
796 if (GET_MODE (op1) != mode1 && mode1 != VOIDmode)
797 xop1 = convert_modes (mode1,
798 GET_MODE (op1) != VOIDmode
799 ? GET_MODE (op1)
800 : mode,
801 xop1, unsignedp);
802
803 /* Now, if insn's predicates don't allow our operands, put them into
804 pseudo regs. */
805
806 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0)
807 && mode0 != VOIDmode)
808 xop0 = copy_to_mode_reg (mode0, xop0);
809
810 if (! (*insn_data[icode].operand[2].predicate) (xop1, mode1)
811 && mode1 != VOIDmode)
812 xop1 = copy_to_mode_reg (mode1, xop1);
813
814 if (! (*insn_data[icode].operand[0].predicate) (temp, mode))
815 temp = gen_reg_rtx (mode);
816
817 pat = GEN_FCN (icode) (temp, xop0, xop1);
818 if (pat)
819 {
820 /* If PAT is composed of more than one insn, try to add an appropriate
821 REG_EQUAL note to it. If we can't because TEMP conflicts with an
822 operand, call ourselves again, this time without a target. */
823 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX
824 && ! add_equal_note (pat, temp, binoptab->code, xop0, xop1))
825 {
826 delete_insns_since (last);
827 return expand_binop (mode, binoptab, op0, op1, NULL_RTX,
828 unsignedp, methods);
829 }
830
831 emit_insn (pat);
832 return temp;
833 }
834 else
835 delete_insns_since (last);
836 }
837
838 /* If this is a multiply, see if we can do a widening operation that
839 takes operands of this mode and makes a wider mode. */
840
841 if (binoptab == smul_optab && GET_MODE_WIDER_MODE (mode) != VOIDmode
842 && (((unsignedp ? umul_widen_optab : smul_widen_optab)
843 ->handlers[(int) GET_MODE_WIDER_MODE (mode)].insn_code)
844 != CODE_FOR_nothing))
845 {
846 temp = expand_binop (GET_MODE_WIDER_MODE (mode),
847 unsignedp ? umul_widen_optab : smul_widen_optab,
848 op0, op1, NULL_RTX, unsignedp, OPTAB_DIRECT);
849
850 if (temp != 0)
851 {
852 if (GET_MODE_CLASS (mode) == MODE_INT)
853 return gen_lowpart (mode, temp);
854 else
855 return convert_to_mode (mode, temp, unsignedp);
856 }
857 }
858
859 /* Look for a wider mode of the same class for which we think we
860 can open-code the operation. Check for a widening multiply at the
861 wider mode as well. */
862
863 if ((class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
864 && methods != OPTAB_DIRECT && methods != OPTAB_LIB)
865 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
866 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
867 {
868 if (binoptab->handlers[(int) wider_mode].insn_code != CODE_FOR_nothing
869 || (binoptab == smul_optab
870 && GET_MODE_WIDER_MODE (wider_mode) != VOIDmode
871 && (((unsignedp ? umul_widen_optab : smul_widen_optab)
872 ->handlers[(int) GET_MODE_WIDER_MODE (wider_mode)].insn_code)
873 != CODE_FOR_nothing)))
874 {
875 rtx xop0 = op0, xop1 = op1;
876 int no_extend = 0;
877
878 /* For certain integer operations, we need not actually extend
879 the narrow operands, as long as we will truncate
880 the results to the same narrowness. */
881
882 if ((binoptab == ior_optab || binoptab == and_optab
883 || binoptab == xor_optab
884 || binoptab == add_optab || binoptab == sub_optab
885 || binoptab == smul_optab || binoptab == ashl_optab)
886 && class == MODE_INT)
887 no_extend = 1;
888
889 xop0 = widen_operand (xop0, wider_mode, mode, unsignedp, no_extend);
890
891 /* The second operand of a shift must always be extended. */
892 xop1 = widen_operand (xop1, wider_mode, mode, unsignedp,
893 no_extend && binoptab != ashl_optab);
894
895 temp = expand_binop (wider_mode, binoptab, xop0, xop1, NULL_RTX,
896 unsignedp, OPTAB_DIRECT);
897 if (temp)
898 {
899 if (class != MODE_INT)
900 {
901 if (target == 0)
902 target = gen_reg_rtx (mode);
903 convert_move (target, temp, 0);
904 return target;
905 }
906 else
907 return gen_lowpart (mode, temp);
908 }
909 else
910 delete_insns_since (last);
911 }
912 }
913
914 /* These can be done a word at a time. */
915 if ((binoptab == and_optab || binoptab == ior_optab || binoptab == xor_optab)
916 && class == MODE_INT
917 && GET_MODE_SIZE (mode) > UNITS_PER_WORD
918 && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
919 {
920 int i;
921 rtx insns;
922 rtx equiv_value;
923
924 /* If TARGET is the same as one of the operands, the REG_EQUAL note
925 won't be accurate, so use a new target. */
926 if (target == 0 || target == op0 || target == op1)
927 target = gen_reg_rtx (mode);
928
929 start_sequence ();
930
931 /* Do the actual arithmetic. */
932 for (i = 0; i < GET_MODE_BITSIZE (mode) / BITS_PER_WORD; i++)
933 {
934 rtx target_piece = operand_subword (target, i, 1, mode);
935 rtx x = expand_binop (word_mode, binoptab,
936 operand_subword_force (op0, i, mode),
937 operand_subword_force (op1, i, mode),
938 target_piece, unsignedp, next_methods);
939
940 if (x == 0)
941 break;
942
943 if (target_piece != x)
944 emit_move_insn (target_piece, x);
945 }
946
947 insns = get_insns ();
948 end_sequence ();
949
950 if (i == GET_MODE_BITSIZE (mode) / BITS_PER_WORD)
951 {
952 if (binoptab->code != UNKNOWN)
953 equiv_value
954 = gen_rtx_fmt_ee (binoptab->code, mode,
955 copy_rtx (op0), copy_rtx (op1));
956 else
957 equiv_value = 0;
958
959 emit_no_conflict_block (insns, target, op0, op1, equiv_value);
960 return target;
961 }
962 }
963
964 /* Synthesize double word shifts from single word shifts. */
965 if ((binoptab == lshr_optab || binoptab == ashl_optab
966 || binoptab == ashr_optab)
967 && class == MODE_INT
968 && GET_CODE (op1) == CONST_INT
969 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
970 && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
971 && ashl_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
972 && lshr_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
973 {
974 rtx insns, inter, equiv_value;
975 rtx into_target, outof_target;
976 rtx into_input, outof_input;
977 int shift_count, left_shift, outof_word;
978
979 /* If TARGET is the same as one of the operands, the REG_EQUAL note
980 won't be accurate, so use a new target. */
981 if (target == 0 || target == op0 || target == op1)
982 target = gen_reg_rtx (mode);
983
984 start_sequence ();
985
986 shift_count = INTVAL (op1);
987
988 /* OUTOF_* is the word we are shifting bits away from, and
989 INTO_* is the word that we are shifting bits towards, thus
990 they differ depending on the direction of the shift and
991 WORDS_BIG_ENDIAN. */
992
993 left_shift = binoptab == ashl_optab;
994 outof_word = left_shift ^ ! WORDS_BIG_ENDIAN;
995
996 outof_target = operand_subword (target, outof_word, 1, mode);
997 into_target = operand_subword (target, 1 - outof_word, 1, mode);
998
999 outof_input = operand_subword_force (op0, outof_word, mode);
1000 into_input = operand_subword_force (op0, 1 - outof_word, mode);
1001
1002 if (shift_count >= BITS_PER_WORD)
1003 {
1004 inter = expand_binop (word_mode, binoptab,
1005 outof_input,
1006 GEN_INT (shift_count - BITS_PER_WORD),
1007 into_target, unsignedp, next_methods);
1008
1009 if (inter != 0 && inter != into_target)
1010 emit_move_insn (into_target, inter);
1011
1012 /* For a signed right shift, we must fill the word we are shifting
1013 out of with copies of the sign bit. Otherwise it is zeroed. */
1014 if (inter != 0 && binoptab != ashr_optab)
1015 inter = CONST0_RTX (word_mode);
1016 else if (inter != 0)
1017 inter = expand_binop (word_mode, binoptab,
1018 outof_input,
1019 GEN_INT (BITS_PER_WORD - 1),
1020 outof_target, unsignedp, next_methods);
1021
1022 if (inter != 0 && inter != outof_target)
1023 emit_move_insn (outof_target, inter);
1024 }
1025 else
1026 {
1027 rtx carries;
1028 optab reverse_unsigned_shift, unsigned_shift;
1029
1030 /* For a shift of less then BITS_PER_WORD, to compute the carry,
1031 we must do a logical shift in the opposite direction of the
1032 desired shift. */
1033
1034 reverse_unsigned_shift = (left_shift ? lshr_optab : ashl_optab);
1035
1036 /* For a shift of less than BITS_PER_WORD, to compute the word
1037 shifted towards, we need to unsigned shift the orig value of
1038 that word. */
1039
1040 unsigned_shift = (left_shift ? ashl_optab : lshr_optab);
1041
1042 carries = expand_binop (word_mode, reverse_unsigned_shift,
1043 outof_input,
1044 GEN_INT (BITS_PER_WORD - shift_count),
1045 0, unsignedp, next_methods);
1046
1047 if (carries == 0)
1048 inter = 0;
1049 else
1050 inter = expand_binop (word_mode, unsigned_shift, into_input,
1051 op1, 0, unsignedp, next_methods);
1052
1053 if (inter != 0)
1054 inter = expand_binop (word_mode, ior_optab, carries, inter,
1055 into_target, unsignedp, next_methods);
1056
1057 if (inter != 0 && inter != into_target)
1058 emit_move_insn (into_target, inter);
1059
1060 if (inter != 0)
1061 inter = expand_binop (word_mode, binoptab, outof_input,
1062 op1, outof_target, unsignedp, next_methods);
1063
1064 if (inter != 0 && inter != outof_target)
1065 emit_move_insn (outof_target, inter);
1066 }
1067
1068 insns = get_insns ();
1069 end_sequence ();
1070
1071 if (inter != 0)
1072 {
1073 if (binoptab->code != UNKNOWN)
1074 equiv_value = gen_rtx_fmt_ee (binoptab->code, mode, op0, op1);
1075 else
1076 equiv_value = 0;
1077
1078 emit_no_conflict_block (insns, target, op0, op1, equiv_value);
1079 return target;
1080 }
1081 }
1082
1083 /* Synthesize double word rotates from single word shifts. */
1084 if ((binoptab == rotl_optab || binoptab == rotr_optab)
1085 && class == MODE_INT
1086 && GET_CODE (op1) == CONST_INT
1087 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1088 && ashl_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
1089 && lshr_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
1090 {
1091 rtx insns, equiv_value;
1092 rtx into_target, outof_target;
1093 rtx into_input, outof_input;
1094 rtx inter;
1095 int shift_count, left_shift, outof_word;
1096
1097 /* If TARGET is the same as one of the operands, the REG_EQUAL note
1098 won't be accurate, so use a new target. */
1099 if (target == 0 || target == op0 || target == op1)
1100 target = gen_reg_rtx (mode);
1101
1102 start_sequence ();
1103
1104 shift_count = INTVAL (op1);
1105
1106 /* OUTOF_* is the word we are shifting bits away from, and
1107 INTO_* is the word that we are shifting bits towards, thus
1108 they differ depending on the direction of the shift and
1109 WORDS_BIG_ENDIAN. */
1110
1111 left_shift = (binoptab == rotl_optab);
1112 outof_word = left_shift ^ ! WORDS_BIG_ENDIAN;
1113
1114 outof_target = operand_subword (target, outof_word, 1, mode);
1115 into_target = operand_subword (target, 1 - outof_word, 1, mode);
1116
1117 outof_input = operand_subword_force (op0, outof_word, mode);
1118 into_input = operand_subword_force (op0, 1 - outof_word, mode);
1119
1120 if (shift_count == BITS_PER_WORD)
1121 {
1122 /* This is just a word swap. */
1123 emit_move_insn (outof_target, into_input);
1124 emit_move_insn (into_target, outof_input);
1125 inter = const0_rtx;
1126 }
1127 else
1128 {
1129 rtx into_temp1, into_temp2, outof_temp1, outof_temp2;
1130 rtx first_shift_count, second_shift_count;
1131 optab reverse_unsigned_shift, unsigned_shift;
1132
1133 reverse_unsigned_shift = (left_shift ^ (shift_count < BITS_PER_WORD)
1134 ? lshr_optab : ashl_optab);
1135
1136 unsigned_shift = (left_shift ^ (shift_count < BITS_PER_WORD)
1137 ? ashl_optab : lshr_optab);
1138
1139 if (shift_count > BITS_PER_WORD)
1140 {
1141 first_shift_count = GEN_INT (shift_count - BITS_PER_WORD);
1142 second_shift_count = GEN_INT (2 * BITS_PER_WORD - shift_count);
1143 }
1144 else
1145 {
1146 first_shift_count = GEN_INT (BITS_PER_WORD - shift_count);
1147 second_shift_count = GEN_INT (shift_count);
1148 }
1149
1150 into_temp1 = expand_binop (word_mode, unsigned_shift,
1151 outof_input, first_shift_count,
1152 NULL_RTX, unsignedp, next_methods);
1153 into_temp2 = expand_binop (word_mode, reverse_unsigned_shift,
1154 into_input, second_shift_count,
1155 NULL_RTX, unsignedp, next_methods);
1156
1157 if (into_temp1 != 0 && into_temp2 != 0)
1158 inter = expand_binop (word_mode, ior_optab, into_temp1, into_temp2,
1159 into_target, unsignedp, next_methods);
1160 else
1161 inter = 0;
1162
1163 if (inter != 0 && inter != into_target)
1164 emit_move_insn (into_target, inter);
1165
1166 outof_temp1 = expand_binop (word_mode, unsigned_shift,
1167 into_input, first_shift_count,
1168 NULL_RTX, unsignedp, next_methods);
1169 outof_temp2 = expand_binop (word_mode, reverse_unsigned_shift,
1170 outof_input, second_shift_count,
1171 NULL_RTX, unsignedp, next_methods);
1172
1173 if (inter != 0 && outof_temp1 != 0 && outof_temp2 != 0)
1174 inter = expand_binop (word_mode, ior_optab,
1175 outof_temp1, outof_temp2,
1176 outof_target, unsignedp, next_methods);
1177
1178 if (inter != 0 && inter != outof_target)
1179 emit_move_insn (outof_target, inter);
1180 }
1181
1182 insns = get_insns ();
1183 end_sequence ();
1184
1185 if (inter != 0)
1186 {
1187 if (binoptab->code != UNKNOWN)
1188 equiv_value = gen_rtx_fmt_ee (binoptab->code, mode, op0, op1);
1189 else
1190 equiv_value = 0;
1191
1192 /* We can't make this a no conflict block if this is a word swap,
1193 because the word swap case fails if the input and output values
1194 are in the same register. */
1195 if (shift_count != BITS_PER_WORD)
1196 emit_no_conflict_block (insns, target, op0, op1, equiv_value);
1197 else
1198 emit_insn (insns);
1199
1200
1201 return target;
1202 }
1203 }
1204
1205 /* These can be done a word at a time by propagating carries. */
1206 if ((binoptab == add_optab || binoptab == sub_optab)
1207 && class == MODE_INT
1208 && GET_MODE_SIZE (mode) >= 2 * UNITS_PER_WORD
1209 && binoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
1210 {
1211 unsigned int i;
1212 optab otheroptab = binoptab == add_optab ? sub_optab : add_optab;
1213 const unsigned int nwords = GET_MODE_BITSIZE (mode) / BITS_PER_WORD;
1214 rtx carry_in = NULL_RTX, carry_out = NULL_RTX;
1215 rtx xop0, xop1, xtarget;
1216
1217 /* We can handle either a 1 or -1 value for the carry. If STORE_FLAG
1218 value is one of those, use it. Otherwise, use 1 since it is the
1219 one easiest to get. */
1220 #if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1
1221 int normalizep = STORE_FLAG_VALUE;
1222 #else
1223 int normalizep = 1;
1224 #endif
1225
1226 /* Prepare the operands. */
1227 xop0 = force_reg (mode, op0);
1228 xop1 = force_reg (mode, op1);
1229
1230 xtarget = gen_reg_rtx (mode);
1231
1232 if (target == 0 || GET_CODE (target) != REG)
1233 target = xtarget;
1234
1235 /* Indicate for flow that the entire target reg is being set. */
1236 if (GET_CODE (target) == REG)
1237 emit_insn (gen_rtx_CLOBBER (VOIDmode, xtarget));
1238
1239 /* Do the actual arithmetic. */
1240 for (i = 0; i < nwords; i++)
1241 {
1242 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
1243 rtx target_piece = operand_subword (xtarget, index, 1, mode);
1244 rtx op0_piece = operand_subword_force (xop0, index, mode);
1245 rtx op1_piece = operand_subword_force (xop1, index, mode);
1246 rtx x;
1247
1248 /* Main add/subtract of the input operands. */
1249 x = expand_binop (word_mode, binoptab,
1250 op0_piece, op1_piece,
1251 target_piece, unsignedp, next_methods);
1252 if (x == 0)
1253 break;
1254
1255 if (i + 1 < nwords)
1256 {
1257 /* Store carry from main add/subtract. */
1258 carry_out = gen_reg_rtx (word_mode);
1259 carry_out = emit_store_flag_force (carry_out,
1260 (binoptab == add_optab
1261 ? LT : GT),
1262 x, op0_piece,
1263 word_mode, 1, normalizep);
1264 }
1265
1266 if (i > 0)
1267 {
1268 rtx newx;
1269
1270 /* Add/subtract previous carry to main result. */
1271 newx = expand_binop (word_mode,
1272 normalizep == 1 ? binoptab : otheroptab,
1273 x, carry_in,
1274 NULL_RTX, 1, next_methods);
1275
1276 if (i + 1 < nwords)
1277 {
1278 /* Get out carry from adding/subtracting carry in. */
1279 rtx carry_tmp = gen_reg_rtx (word_mode);
1280 carry_tmp = emit_store_flag_force (carry_tmp,
1281 (binoptab == add_optab
1282 ? LT : GT),
1283 newx, x,
1284 word_mode, 1, normalizep);
1285
1286 /* Logical-ior the two poss. carry together. */
1287 carry_out = expand_binop (word_mode, ior_optab,
1288 carry_out, carry_tmp,
1289 carry_out, 0, next_methods);
1290 if (carry_out == 0)
1291 break;
1292 }
1293 emit_move_insn (target_piece, newx);
1294 }
1295
1296 carry_in = carry_out;
1297 }
1298
1299 if (i == GET_MODE_BITSIZE (mode) / (unsigned) BITS_PER_WORD)
1300 {
1301 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
1302 {
1303 rtx temp = emit_move_insn (target, xtarget);
1304
1305 set_unique_reg_note (temp,
1306 REG_EQUAL,
1307 gen_rtx_fmt_ee (binoptab->code, mode,
1308 copy_rtx (xop0),
1309 copy_rtx (xop1)));
1310 }
1311
1312 return target;
1313 }
1314
1315 else
1316 delete_insns_since (last);
1317 }
1318
1319 /* If we want to multiply two two-word values and have normal and widening
1320 multiplies of single-word values, we can do this with three smaller
1321 multiplications. Note that we do not make a REG_NO_CONFLICT block here
1322 because we are not operating on one word at a time.
1323
1324 The multiplication proceeds as follows:
1325 _______________________
1326 [__op0_high_|__op0_low__]
1327 _______________________
1328 * [__op1_high_|__op1_low__]
1329 _______________________________________________
1330 _______________________
1331 (1) [__op0_low__*__op1_low__]
1332 _______________________
1333 (2a) [__op0_low__*__op1_high_]
1334 _______________________
1335 (2b) [__op0_high_*__op1_low__]
1336 _______________________
1337 (3) [__op0_high_*__op1_high_]
1338
1339
1340 This gives a 4-word result. Since we are only interested in the
1341 lower 2 words, partial result (3) and the upper words of (2a) and
1342 (2b) don't need to be calculated. Hence (2a) and (2b) can be
1343 calculated using non-widening multiplication.
1344
1345 (1), however, needs to be calculated with an unsigned widening
1346 multiplication. If this operation is not directly supported we
1347 try using a signed widening multiplication and adjust the result.
1348 This adjustment works as follows:
1349
1350 If both operands are positive then no adjustment is needed.
1351
1352 If the operands have different signs, for example op0_low < 0 and
1353 op1_low >= 0, the instruction treats the most significant bit of
1354 op0_low as a sign bit instead of a bit with significance
1355 2**(BITS_PER_WORD-1), i.e. the instruction multiplies op1_low
1356 with 2**BITS_PER_WORD - op0_low, and two's complements the
1357 result. Conclusion: We need to add op1_low * 2**BITS_PER_WORD to
1358 the result.
1359
1360 Similarly, if both operands are negative, we need to add
1361 (op0_low + op1_low) * 2**BITS_PER_WORD.
1362
1363 We use a trick to adjust quickly. We logically shift op0_low right
1364 (op1_low) BITS_PER_WORD-1 steps to get 0 or 1, and add this to
1365 op0_high (op1_high) before it is used to calculate 2b (2a). If no
1366 logical shift exists, we do an arithmetic right shift and subtract
1367 the 0 or -1. */
1368
1369 if (binoptab == smul_optab
1370 && class == MODE_INT
1371 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1372 && smul_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
1373 && add_optab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing
1374 && ((umul_widen_optab->handlers[(int) mode].insn_code
1375 != CODE_FOR_nothing)
1376 || (smul_widen_optab->handlers[(int) mode].insn_code
1377 != CODE_FOR_nothing)))
1378 {
1379 int low = (WORDS_BIG_ENDIAN ? 1 : 0);
1380 int high = (WORDS_BIG_ENDIAN ? 0 : 1);
1381 rtx op0_high = operand_subword_force (op0, high, mode);
1382 rtx op0_low = operand_subword_force (op0, low, mode);
1383 rtx op1_high = operand_subword_force (op1, high, mode);
1384 rtx op1_low = operand_subword_force (op1, low, mode);
1385 rtx product = 0;
1386 rtx op0_xhigh = NULL_RTX;
1387 rtx op1_xhigh = NULL_RTX;
1388
1389 /* If the target is the same as one of the inputs, don't use it. This
1390 prevents problems with the REG_EQUAL note. */
1391 if (target == op0 || target == op1
1392 || (target != 0 && GET_CODE (target) != REG))
1393 target = 0;
1394
1395 /* Multiply the two lower words to get a double-word product.
1396 If unsigned widening multiplication is available, use that;
1397 otherwise use the signed form and compensate. */
1398
1399 if (umul_widen_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
1400 {
1401 product = expand_binop (mode, umul_widen_optab, op0_low, op1_low,
1402 target, 1, OPTAB_DIRECT);
1403
1404 /* If we didn't succeed, delete everything we did so far. */
1405 if (product == 0)
1406 delete_insns_since (last);
1407 else
1408 op0_xhigh = op0_high, op1_xhigh = op1_high;
1409 }
1410
1411 if (product == 0
1412 && smul_widen_optab->handlers[(int) mode].insn_code
1413 != CODE_FOR_nothing)
1414 {
1415 rtx wordm1 = GEN_INT (BITS_PER_WORD - 1);
1416 product = expand_binop (mode, smul_widen_optab, op0_low, op1_low,
1417 target, 1, OPTAB_DIRECT);
1418 op0_xhigh = expand_binop (word_mode, lshr_optab, op0_low, wordm1,
1419 NULL_RTX, 1, next_methods);
1420 if (op0_xhigh)
1421 op0_xhigh = expand_binop (word_mode, add_optab, op0_high,
1422 op0_xhigh, op0_xhigh, 0, next_methods);
1423 else
1424 {
1425 op0_xhigh = expand_binop (word_mode, ashr_optab, op0_low, wordm1,
1426 NULL_RTX, 0, next_methods);
1427 if (op0_xhigh)
1428 op0_xhigh = expand_binop (word_mode, sub_optab, op0_high,
1429 op0_xhigh, op0_xhigh, 0,
1430 next_methods);
1431 }
1432
1433 op1_xhigh = expand_binop (word_mode, lshr_optab, op1_low, wordm1,
1434 NULL_RTX, 1, next_methods);
1435 if (op1_xhigh)
1436 op1_xhigh = expand_binop (word_mode, add_optab, op1_high,
1437 op1_xhigh, op1_xhigh, 0, next_methods);
1438 else
1439 {
1440 op1_xhigh = expand_binop (word_mode, ashr_optab, op1_low, wordm1,
1441 NULL_RTX, 0, next_methods);
1442 if (op1_xhigh)
1443 op1_xhigh = expand_binop (word_mode, sub_optab, op1_high,
1444 op1_xhigh, op1_xhigh, 0,
1445 next_methods);
1446 }
1447 }
1448
1449 /* If we have been able to directly compute the product of the
1450 low-order words of the operands and perform any required adjustments
1451 of the operands, we proceed by trying two more multiplications
1452 and then computing the appropriate sum.
1453
1454 We have checked above that the required addition is provided.
1455 Full-word addition will normally always succeed, especially if
1456 it is provided at all, so we don't worry about its failure. The
1457 multiplication may well fail, however, so we do handle that. */
1458
1459 if (product && op0_xhigh && op1_xhigh)
1460 {
1461 rtx product_high = operand_subword (product, high, 1, mode);
1462 rtx temp = expand_binop (word_mode, binoptab, op0_low, op1_xhigh,
1463 NULL_RTX, 0, OPTAB_DIRECT);
1464
1465 if (!REG_P (product_high))
1466 product_high = force_reg (word_mode, product_high);
1467
1468 if (temp != 0)
1469 temp = expand_binop (word_mode, add_optab, temp, product_high,
1470 product_high, 0, next_methods);
1471
1472 if (temp != 0 && temp != product_high)
1473 emit_move_insn (product_high, temp);
1474
1475 if (temp != 0)
1476 temp = expand_binop (word_mode, binoptab, op1_low, op0_xhigh,
1477 NULL_RTX, 0, OPTAB_DIRECT);
1478
1479 if (temp != 0)
1480 temp = expand_binop (word_mode, add_optab, temp,
1481 product_high, product_high,
1482 0, next_methods);
1483
1484 if (temp != 0 && temp != product_high)
1485 emit_move_insn (product_high, temp);
1486
1487 emit_move_insn (operand_subword (product, high, 1, mode), product_high);
1488
1489 if (temp != 0)
1490 {
1491 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
1492 {
1493 temp = emit_move_insn (product, product);
1494 set_unique_reg_note (temp,
1495 REG_EQUAL,
1496 gen_rtx_fmt_ee (MULT, mode,
1497 copy_rtx (op0),
1498 copy_rtx (op1)));
1499 }
1500
1501 return product;
1502 }
1503 }
1504
1505 /* If we get here, we couldn't do it for some reason even though we
1506 originally thought we could. Delete anything we've emitted in
1507 trying to do it. */
1508
1509 delete_insns_since (last);
1510 }
1511
1512 /* Open-code the vector operations if we have no hardware support
1513 for them. */
1514 if (class == MODE_VECTOR_INT || class == MODE_VECTOR_FLOAT)
1515 return expand_vector_binop (mode, binoptab, op0, op1, target,
1516 unsignedp, methods);
1517
1518 /* We need to open-code the complex type operations: '+, -, * and /' */
1519
1520 /* At this point we allow operations between two similar complex
1521 numbers, and also if one of the operands is not a complex number
1522 but rather of MODE_FLOAT or MODE_INT. However, the caller
1523 must make sure that the MODE of the non-complex operand matches
1524 the SUBMODE of the complex operand. */
1525
1526 if (class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT)
1527 {
1528 rtx real0 = 0, imag0 = 0;
1529 rtx real1 = 0, imag1 = 0;
1530 rtx realr, imagr, res;
1531 rtx seq;
1532 rtx equiv_value;
1533 int ok = 0;
1534
1535 /* Find the correct mode for the real and imaginary parts */
1536 enum machine_mode submode = GET_MODE_INNER(mode);
1537
1538 if (submode == BLKmode)
1539 abort ();
1540
1541 if (! target)
1542 target = gen_reg_rtx (mode);
1543
1544 start_sequence ();
1545
1546 realr = gen_realpart (submode, target);
1547 imagr = gen_imagpart (submode, target);
1548
1549 if (GET_MODE (op0) == mode)
1550 {
1551 real0 = gen_realpart (submode, op0);
1552 imag0 = gen_imagpart (submode, op0);
1553 }
1554 else
1555 real0 = op0;
1556
1557 if (GET_MODE (op1) == mode)
1558 {
1559 real1 = gen_realpart (submode, op1);
1560 imag1 = gen_imagpart (submode, op1);
1561 }
1562 else
1563 real1 = op1;
1564
1565 if (real0 == 0 || real1 == 0 || ! (imag0 != 0 || imag1 != 0))
1566 abort ();
1567
1568 switch (binoptab->code)
1569 {
1570 case PLUS:
1571 /* (a+ib) + (c+id) = (a+c) + i(b+d) */
1572 case MINUS:
1573 /* (a+ib) - (c+id) = (a-c) + i(b-d) */
1574 res = expand_binop (submode, binoptab, real0, real1,
1575 realr, unsignedp, methods);
1576
1577 if (res == 0)
1578 break;
1579 else if (res != realr)
1580 emit_move_insn (realr, res);
1581
1582 if (imag0 != 0 && imag1 != 0)
1583 res = expand_binop (submode, binoptab, imag0, imag1,
1584 imagr, unsignedp, methods);
1585 else if (imag0 != 0)
1586 res = imag0;
1587 else if (binoptab->code == MINUS)
1588 res = expand_unop (submode,
1589 binoptab == subv_optab ? negv_optab : neg_optab,
1590 imag1, imagr, unsignedp);
1591 else
1592 res = imag1;
1593
1594 if (res == 0)
1595 break;
1596 else if (res != imagr)
1597 emit_move_insn (imagr, res);
1598
1599 ok = 1;
1600 break;
1601
1602 case MULT:
1603 /* (a+ib) * (c+id) = (ac-bd) + i(ad+cb) */
1604
1605 if (imag0 != 0 && imag1 != 0)
1606 {
1607 rtx temp1, temp2;
1608
1609 /* Don't fetch these from memory more than once. */
1610 real0 = force_reg (submode, real0);
1611 real1 = force_reg (submode, real1);
1612 imag0 = force_reg (submode, imag0);
1613 imag1 = force_reg (submode, imag1);
1614
1615 temp1 = expand_binop (submode, binoptab, real0, real1, NULL_RTX,
1616 unsignedp, methods);
1617
1618 temp2 = expand_binop (submode, binoptab, imag0, imag1, NULL_RTX,
1619 unsignedp, methods);
1620
1621 if (temp1 == 0 || temp2 == 0)
1622 break;
1623
1624 res = (expand_binop
1625 (submode,
1626 binoptab == smulv_optab ? subv_optab : sub_optab,
1627 temp1, temp2, realr, unsignedp, methods));
1628
1629 if (res == 0)
1630 break;
1631 else if (res != realr)
1632 emit_move_insn (realr, res);
1633
1634 temp1 = expand_binop (submode, binoptab, real0, imag1,
1635 NULL_RTX, unsignedp, methods);
1636
1637 temp2 = expand_binop (submode, binoptab, real1, imag0,
1638 NULL_RTX, unsignedp, methods);
1639
1640 if (temp1 == 0 || temp2 == 0)
1641 break;
1642
1643 res = (expand_binop
1644 (submode,
1645 binoptab == smulv_optab ? addv_optab : add_optab,
1646 temp1, temp2, imagr, unsignedp, methods));
1647
1648 if (res == 0)
1649 break;
1650 else if (res != imagr)
1651 emit_move_insn (imagr, res);
1652
1653 ok = 1;
1654 }
1655 else
1656 {
1657 /* Don't fetch these from memory more than once. */
1658 real0 = force_reg (submode, real0);
1659 real1 = force_reg (submode, real1);
1660
1661 res = expand_binop (submode, binoptab, real0, real1,
1662 realr, unsignedp, methods);
1663 if (res == 0)
1664 break;
1665 else if (res != realr)
1666 emit_move_insn (realr, res);
1667
1668 if (imag0 != 0)
1669 res = expand_binop (submode, binoptab,
1670 real1, imag0, imagr, unsignedp, methods);
1671 else
1672 res = expand_binop (submode, binoptab,
1673 real0, imag1, imagr, unsignedp, methods);
1674
1675 if (res == 0)
1676 break;
1677 else if (res != imagr)
1678 emit_move_insn (imagr, res);
1679
1680 ok = 1;
1681 }
1682 break;
1683
1684 case DIV:
1685 /* (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) */
1686
1687 if (imag1 == 0)
1688 {
1689 /* (a+ib) / (c+i0) = (a/c) + i(b/c) */
1690
1691 /* Don't fetch these from memory more than once. */
1692 real1 = force_reg (submode, real1);
1693
1694 /* Simply divide the real and imaginary parts by `c' */
1695 if (class == MODE_COMPLEX_FLOAT)
1696 res = expand_binop (submode, binoptab, real0, real1,
1697 realr, unsignedp, methods);
1698 else
1699 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
1700 real0, real1, realr, unsignedp);
1701
1702 if (res == 0)
1703 break;
1704 else if (res != realr)
1705 emit_move_insn (realr, res);
1706
1707 if (class == MODE_COMPLEX_FLOAT)
1708 res = expand_binop (submode, binoptab, imag0, real1,
1709 imagr, unsignedp, methods);
1710 else
1711 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
1712 imag0, real1, imagr, unsignedp);
1713
1714 if (res == 0)
1715 break;
1716 else if (res != imagr)
1717 emit_move_insn (imagr, res);
1718
1719 ok = 1;
1720 }
1721 else
1722 {
1723 switch (flag_complex_divide_method)
1724 {
1725 case 0:
1726 ok = expand_cmplxdiv_straight (real0, real1, imag0, imag1,
1727 realr, imagr, submode,
1728 unsignedp, methods,
1729 class, binoptab);
1730 break;
1731
1732 case 1:
1733 ok = expand_cmplxdiv_wide (real0, real1, imag0, imag1,
1734 realr, imagr, submode,
1735 unsignedp, methods,
1736 class, binoptab);
1737 break;
1738
1739 default:
1740 abort ();
1741 }
1742 }
1743 break;
1744
1745 default:
1746 abort ();
1747 }
1748
1749 seq = get_insns ();
1750 end_sequence ();
1751
1752 if (ok)
1753 {
1754 if (binoptab->code != UNKNOWN)
1755 equiv_value
1756 = gen_rtx_fmt_ee (binoptab->code, mode,
1757 copy_rtx (op0), copy_rtx (op1));
1758 else
1759 equiv_value = 0;
1760
1761 emit_no_conflict_block (seq, target, op0, op1, equiv_value);
1762
1763 return target;
1764 }
1765 }
1766
1767 /* It can't be open-coded in this mode.
1768 Use a library call if one is available and caller says that's ok. */
1769
1770 if (binoptab->handlers[(int) mode].libfunc
1771 && (methods == OPTAB_LIB || methods == OPTAB_LIB_WIDEN))
1772 {
1773 rtx insns;
1774 rtx op1x = op1;
1775 enum machine_mode op1_mode = mode;
1776 rtx value;
1777
1778 start_sequence ();
1779
1780 if (shift_op)
1781 {
1782 op1_mode = word_mode;
1783 /* Specify unsigned here,
1784 since negative shift counts are meaningless. */
1785 op1x = convert_to_mode (word_mode, op1, 1);
1786 }
1787
1788 if (GET_MODE (op0) != VOIDmode
1789 && GET_MODE (op0) != mode)
1790 op0 = convert_to_mode (mode, op0, unsignedp);
1791
1792 /* Pass 1 for NO_QUEUE so we don't lose any increments
1793 if the libcall is cse'd or moved. */
1794 value = emit_library_call_value (binoptab->handlers[(int) mode].libfunc,
1795 NULL_RTX, LCT_CONST, mode, 2,
1796 op0, mode, op1x, op1_mode);
1797
1798 insns = get_insns ();
1799 end_sequence ();
1800
1801 target = gen_reg_rtx (mode);
1802 emit_libcall_block (insns, target, value,
1803 gen_rtx_fmt_ee (binoptab->code, mode, op0, op1));
1804
1805 return target;
1806 }
1807
1808 delete_insns_since (last);
1809
1810 /* It can't be done in this mode. Can we do it in a wider mode? */
1811
1812 if (! (methods == OPTAB_WIDEN || methods == OPTAB_LIB_WIDEN
1813 || methods == OPTAB_MUST_WIDEN))
1814 {
1815 /* Caller says, don't even try. */
1816 delete_insns_since (entry_last);
1817 return 0;
1818 }
1819
1820 /* Compute the value of METHODS to pass to recursive calls.
1821 Don't allow widening to be tried recursively. */
1822
1823 methods = (methods == OPTAB_LIB_WIDEN ? OPTAB_LIB : OPTAB_DIRECT);
1824
1825 /* Look for a wider mode of the same class for which it appears we can do
1826 the operation. */
1827
1828 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
1829 {
1830 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
1831 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
1832 {
1833 if ((binoptab->handlers[(int) wider_mode].insn_code
1834 != CODE_FOR_nothing)
1835 || (methods == OPTAB_LIB
1836 && binoptab->handlers[(int) wider_mode].libfunc))
1837 {
1838 rtx xop0 = op0, xop1 = op1;
1839 int no_extend = 0;
1840
1841 /* For certain integer operations, we need not actually extend
1842 the narrow operands, as long as we will truncate
1843 the results to the same narrowness. */
1844
1845 if ((binoptab == ior_optab || binoptab == and_optab
1846 || binoptab == xor_optab
1847 || binoptab == add_optab || binoptab == sub_optab
1848 || binoptab == smul_optab || binoptab == ashl_optab)
1849 && class == MODE_INT)
1850 no_extend = 1;
1851
1852 xop0 = widen_operand (xop0, wider_mode, mode,
1853 unsignedp, no_extend);
1854
1855 /* The second operand of a shift must always be extended. */
1856 xop1 = widen_operand (xop1, wider_mode, mode, unsignedp,
1857 no_extend && binoptab != ashl_optab);
1858
1859 temp = expand_binop (wider_mode, binoptab, xop0, xop1, NULL_RTX,
1860 unsignedp, methods);
1861 if (temp)
1862 {
1863 if (class != MODE_INT)
1864 {
1865 if (target == 0)
1866 target = gen_reg_rtx (mode);
1867 convert_move (target, temp, 0);
1868 return target;
1869 }
1870 else
1871 return gen_lowpart (mode, temp);
1872 }
1873 else
1874 delete_insns_since (last);
1875 }
1876 }
1877 }
1878
1879 delete_insns_since (entry_last);
1880 return 0;
1881 }
1882
1883 /* Like expand_binop, but for open-coding vectors binops. */
1884
1885 static rtx
1886 expand_vector_binop (mode, binoptab, op0, op1, target, unsignedp, methods)
1887 enum machine_mode mode;
1888 optab binoptab;
1889 rtx op0, op1;
1890 rtx target;
1891 int unsignedp;
1892 enum optab_methods methods;
1893 {
1894 enum machine_mode submode, tmode;
1895 int size, elts, subsize, subbitsize, i;
1896 rtx t, a, b, res, seq;
1897 enum mode_class class;
1898
1899 class = GET_MODE_CLASS (mode);
1900
1901 size = GET_MODE_SIZE (mode);
1902 submode = GET_MODE_INNER (mode);
1903
1904 /* Search for the widest vector mode with the same inner mode that is
1905 still narrower than MODE and that allows to open-code this operator.
1906 Note, if we find such a mode and the handler later decides it can't
1907 do the expansion, we'll be called recursively with the narrower mode. */
1908 for (tmode = GET_CLASS_NARROWEST_MODE (class);
1909 GET_MODE_SIZE (tmode) < GET_MODE_SIZE (mode);
1910 tmode = GET_MODE_WIDER_MODE (tmode))
1911 {
1912 if (GET_MODE_INNER (tmode) == GET_MODE_INNER (mode)
1913 && binoptab->handlers[(int) tmode].insn_code != CODE_FOR_nothing)
1914 submode = tmode;
1915 }
1916
1917 switch (binoptab->code)
1918 {
1919 case AND:
1920 case IOR:
1921 case XOR:
1922 tmode = int_mode_for_mode (mode);
1923 if (tmode != BLKmode)
1924 submode = tmode;
1925 case PLUS:
1926 case MINUS:
1927 case MULT:
1928 case DIV:
1929 subsize = GET_MODE_SIZE (submode);
1930 subbitsize = GET_MODE_BITSIZE (submode);
1931 elts = size / subsize;
1932
1933 /* If METHODS is OPTAB_DIRECT, we don't insist on the exact mode,
1934 but that we operate on more than one element at a time. */
1935 if (subsize == GET_MODE_UNIT_SIZE (mode) && methods == OPTAB_DIRECT)
1936 return 0;
1937
1938 start_sequence ();
1939
1940 /* Errors can leave us with a const0_rtx as operand. */
1941 if (GET_MODE (op0) != mode)
1942 op0 = copy_to_mode_reg (mode, op0);
1943 if (GET_MODE (op1) != mode)
1944 op1 = copy_to_mode_reg (mode, op1);
1945
1946 if (!target)
1947 target = gen_reg_rtx (mode);
1948
1949 for (i = 0; i < elts; ++i)
1950 {
1951 /* If this is part of a register, and not the first item in the
1952 word, we can't store using a SUBREG - that would clobber
1953 previous results.
1954 And storing with a SUBREG is only possible for the least
1955 significant part, hence we can't do it for big endian
1956 (unless we want to permute the evaluation order. */
1957 if (GET_CODE (target) == REG
1958 && (BYTES_BIG_ENDIAN
1959 ? subsize < UNITS_PER_WORD
1960 : ((i * subsize) % UNITS_PER_WORD) != 0))
1961 t = NULL_RTX;
1962 else
1963 t = simplify_gen_subreg (submode, target, mode, i * subsize);
1964 if (CONSTANT_P (op0))
1965 a = simplify_gen_subreg (submode, op0, mode, i * subsize);
1966 else
1967 a = extract_bit_field (op0, subbitsize, i * subbitsize, unsignedp,
1968 NULL_RTX, submode, submode, size);
1969 if (CONSTANT_P (op1))
1970 b = simplify_gen_subreg (submode, op1, mode, i * subsize);
1971 else
1972 b = extract_bit_field (op1, subbitsize, i * subbitsize, unsignedp,
1973 NULL_RTX, submode, submode, size);
1974
1975 if (binoptab->code == DIV)
1976 {
1977 if (class == MODE_VECTOR_FLOAT)
1978 res = expand_binop (submode, binoptab, a, b, t,
1979 unsignedp, methods);
1980 else
1981 res = expand_divmod (0, TRUNC_DIV_EXPR, submode,
1982 a, b, t, unsignedp);
1983 }
1984 else
1985 res = expand_binop (submode, binoptab, a, b, t,
1986 unsignedp, methods);
1987
1988 if (res == 0)
1989 break;
1990
1991 if (t)
1992 emit_move_insn (t, res);
1993 else
1994 store_bit_field (target, subbitsize, i * subbitsize, submode, res,
1995 size);
1996 }
1997 break;
1998
1999 default:
2000 abort ();
2001 }
2002
2003 seq = get_insns ();
2004 end_sequence ();
2005 emit_insn (seq);
2006
2007 return target;
2008 }
2009
2010 /* Like expand_unop but for open-coding vector unops. */
2011
2012 static rtx
2013 expand_vector_unop (mode, unoptab, op0, target, unsignedp)
2014 enum machine_mode mode;
2015 optab unoptab;
2016 rtx op0;
2017 rtx target;
2018 int unsignedp;
2019 {
2020 enum machine_mode submode, tmode;
2021 int size, elts, subsize, subbitsize, i;
2022 rtx t, a, res, seq;
2023
2024 size = GET_MODE_SIZE (mode);
2025 submode = GET_MODE_INNER (mode);
2026
2027 /* Search for the widest vector mode with the same inner mode that is
2028 still narrower than MODE and that allows to open-code this operator.
2029 Note, if we find such a mode and the handler later decides it can't
2030 do the expansion, we'll be called recursively with the narrower mode. */
2031 for (tmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (mode));
2032 GET_MODE_SIZE (tmode) < GET_MODE_SIZE (mode);
2033 tmode = GET_MODE_WIDER_MODE (tmode))
2034 {
2035 if (GET_MODE_INNER (tmode) == GET_MODE_INNER (mode)
2036 && unoptab->handlers[(int) tmode].insn_code != CODE_FOR_nothing)
2037 submode = tmode;
2038 }
2039 /* If there is no negate operation, try doing a subtract from zero. */
2040 if (unoptab == neg_optab && GET_MODE_CLASS (submode) == MODE_INT
2041 /* Avoid infinite recursion when an
2042 error has left us with the wrong mode. */
2043 && GET_MODE (op0) == mode)
2044 {
2045 rtx temp;
2046 temp = expand_binop (mode, sub_optab, CONST0_RTX (mode), op0,
2047 target, unsignedp, OPTAB_DIRECT);
2048 if (temp)
2049 return temp;
2050 }
2051
2052 if (unoptab == one_cmpl_optab)
2053 {
2054 tmode = int_mode_for_mode (mode);
2055 if (tmode != BLKmode)
2056 submode = tmode;
2057 }
2058
2059 subsize = GET_MODE_SIZE (submode);
2060 subbitsize = GET_MODE_BITSIZE (submode);
2061 elts = size / subsize;
2062
2063 /* Errors can leave us with a const0_rtx as operand. */
2064 if (GET_MODE (op0) != mode)
2065 op0 = copy_to_mode_reg (mode, op0);
2066
2067 if (!target)
2068 target = gen_reg_rtx (mode);
2069
2070 start_sequence ();
2071
2072 for (i = 0; i < elts; ++i)
2073 {
2074 /* If this is part of a register, and not the first item in the
2075 word, we can't store using a SUBREG - that would clobber
2076 previous results.
2077 And storing with a SUBREG is only possible for the least
2078 significant part, hence we can't do it for big endian
2079 (unless we want to permute the evaluation order. */
2080 if (GET_CODE (target) == REG
2081 && (BYTES_BIG_ENDIAN
2082 ? subsize < UNITS_PER_WORD
2083 : ((i * subsize) % UNITS_PER_WORD) != 0))
2084 t = NULL_RTX;
2085 else
2086 t = simplify_gen_subreg (submode, target, mode, i * subsize);
2087 if (CONSTANT_P (op0))
2088 a = simplify_gen_subreg (submode, op0, mode, i * subsize);
2089 else
2090 a = extract_bit_field (op0, subbitsize, i * subbitsize, unsignedp,
2091 t, submode, submode, size);
2092
2093 res = expand_unop (submode, unoptab, a, t, unsignedp);
2094
2095 if (t)
2096 emit_move_insn (t, res);
2097 else
2098 store_bit_field (target, subbitsize, i * subbitsize, submode, res,
2099 size);
2100 }
2101
2102 seq = get_insns ();
2103 end_sequence ();
2104 emit_insn (seq);
2105
2106 return target;
2107 }
2108 \f
2109 /* Expand a binary operator which has both signed and unsigned forms.
2110 UOPTAB is the optab for unsigned operations, and SOPTAB is for
2111 signed operations.
2112
2113 If we widen unsigned operands, we may use a signed wider operation instead
2114 of an unsigned wider operation, since the result would be the same. */
2115
2116 rtx
2117 sign_expand_binop (mode, uoptab, soptab, op0, op1, target, unsignedp, methods)
2118 enum machine_mode mode;
2119 optab uoptab, soptab;
2120 rtx op0, op1, target;
2121 int unsignedp;
2122 enum optab_methods methods;
2123 {
2124 rtx temp;
2125 optab direct_optab = unsignedp ? uoptab : soptab;
2126 struct optab wide_soptab;
2127
2128 /* Do it without widening, if possible. */
2129 temp = expand_binop (mode, direct_optab, op0, op1, target,
2130 unsignedp, OPTAB_DIRECT);
2131 if (temp || methods == OPTAB_DIRECT)
2132 return temp;
2133
2134 /* Try widening to a signed int. Make a fake signed optab that
2135 hides any signed insn for direct use. */
2136 wide_soptab = *soptab;
2137 wide_soptab.handlers[(int) mode].insn_code = CODE_FOR_nothing;
2138 wide_soptab.handlers[(int) mode].libfunc = 0;
2139
2140 temp = expand_binop (mode, &wide_soptab, op0, op1, target,
2141 unsignedp, OPTAB_WIDEN);
2142
2143 /* For unsigned operands, try widening to an unsigned int. */
2144 if (temp == 0 && unsignedp)
2145 temp = expand_binop (mode, uoptab, op0, op1, target,
2146 unsignedp, OPTAB_WIDEN);
2147 if (temp || methods == OPTAB_WIDEN)
2148 return temp;
2149
2150 /* Use the right width lib call if that exists. */
2151 temp = expand_binop (mode, direct_optab, op0, op1, target, unsignedp, OPTAB_LIB);
2152 if (temp || methods == OPTAB_LIB)
2153 return temp;
2154
2155 /* Must widen and use a lib call, use either signed or unsigned. */
2156 temp = expand_binop (mode, &wide_soptab, op0, op1, target,
2157 unsignedp, methods);
2158 if (temp != 0)
2159 return temp;
2160 if (unsignedp)
2161 return expand_binop (mode, uoptab, op0, op1, target,
2162 unsignedp, methods);
2163 return 0;
2164 }
2165 \f
2166 /* Generate code to perform an operation specified by BINOPTAB
2167 on operands OP0 and OP1, with two results to TARG1 and TARG2.
2168 We assume that the order of the operands for the instruction
2169 is TARG0, OP0, OP1, TARG1, which would fit a pattern like
2170 [(set TARG0 (operate OP0 OP1)) (set TARG1 (operate ...))].
2171
2172 Either TARG0 or TARG1 may be zero, but what that means is that
2173 the result is not actually wanted. We will generate it into
2174 a dummy pseudo-reg and discard it. They may not both be zero.
2175
2176 Returns 1 if this operation can be performed; 0 if not. */
2177
2178 int
2179 expand_twoval_binop (binoptab, op0, op1, targ0, targ1, unsignedp)
2180 optab binoptab;
2181 rtx op0, op1;
2182 rtx targ0, targ1;
2183 int unsignedp;
2184 {
2185 enum machine_mode mode = GET_MODE (targ0 ? targ0 : targ1);
2186 enum mode_class class;
2187 enum machine_mode wider_mode;
2188 rtx entry_last = get_last_insn ();
2189 rtx last;
2190
2191 class = GET_MODE_CLASS (mode);
2192
2193 op0 = protect_from_queue (op0, 0);
2194 op1 = protect_from_queue (op1, 0);
2195
2196 if (flag_force_mem)
2197 {
2198 op0 = force_not_mem (op0);
2199 op1 = force_not_mem (op1);
2200 }
2201
2202 /* If we are inside an appropriately-short loop and one operand is an
2203 expensive constant, force it into a register. */
2204 if (CONSTANT_P (op0) && preserve_subexpressions_p ()
2205 && rtx_cost (op0, binoptab->code) > COSTS_N_INSNS (1))
2206 op0 = force_reg (mode, op0);
2207
2208 if (CONSTANT_P (op1) && preserve_subexpressions_p ()
2209 && rtx_cost (op1, binoptab->code) > COSTS_N_INSNS (1))
2210 op1 = force_reg (mode, op1);
2211
2212 if (targ0)
2213 targ0 = protect_from_queue (targ0, 1);
2214 else
2215 targ0 = gen_reg_rtx (mode);
2216 if (targ1)
2217 targ1 = protect_from_queue (targ1, 1);
2218 else
2219 targ1 = gen_reg_rtx (mode);
2220
2221 /* Record where to go back to if we fail. */
2222 last = get_last_insn ();
2223
2224 if (binoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2225 {
2226 int icode = (int) binoptab->handlers[(int) mode].insn_code;
2227 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2228 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
2229 rtx pat;
2230 rtx xop0 = op0, xop1 = op1;
2231
2232 /* In case the insn wants input operands in modes different from
2233 those of the actual operands, convert the operands. It would
2234 seem that we don't need to convert CONST_INTs, but we do, so
2235 that they're properly zero-extended, sign-extended or truncated
2236 for their mode. */
2237
2238 if (GET_MODE (op0) != mode0 && mode0 != VOIDmode)
2239 xop0 = convert_modes (mode0,
2240 GET_MODE (op0) != VOIDmode
2241 ? GET_MODE (op0)
2242 : mode,
2243 xop0, unsignedp);
2244
2245 if (GET_MODE (op1) != mode1 && mode1 != VOIDmode)
2246 xop1 = convert_modes (mode1,
2247 GET_MODE (op1) != VOIDmode
2248 ? GET_MODE (op1)
2249 : mode,
2250 xop1, unsignedp);
2251
2252 /* Now, if insn doesn't accept these operands, put them into pseudos. */
2253 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0))
2254 xop0 = copy_to_mode_reg (mode0, xop0);
2255
2256 if (! (*insn_data[icode].operand[2].predicate) (xop1, mode1))
2257 xop1 = copy_to_mode_reg (mode1, xop1);
2258
2259 /* We could handle this, but we should always be called with a pseudo
2260 for our targets and all insns should take them as outputs. */
2261 if (! (*insn_data[icode].operand[0].predicate) (targ0, mode)
2262 || ! (*insn_data[icode].operand[3].predicate) (targ1, mode))
2263 abort ();
2264
2265 pat = GEN_FCN (icode) (targ0, xop0, xop1, targ1);
2266 if (pat)
2267 {
2268 emit_insn (pat);
2269 return 1;
2270 }
2271 else
2272 delete_insns_since (last);
2273 }
2274
2275 /* It can't be done in this mode. Can we do it in a wider mode? */
2276
2277 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2278 {
2279 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2280 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2281 {
2282 if (binoptab->handlers[(int) wider_mode].insn_code
2283 != CODE_FOR_nothing)
2284 {
2285 rtx t0 = gen_reg_rtx (wider_mode);
2286 rtx t1 = gen_reg_rtx (wider_mode);
2287 rtx cop0 = convert_modes (wider_mode, mode, op0, unsignedp);
2288 rtx cop1 = convert_modes (wider_mode, mode, op1, unsignedp);
2289
2290 if (expand_twoval_binop (binoptab, cop0, cop1,
2291 t0, t1, unsignedp))
2292 {
2293 convert_move (targ0, t0, unsignedp);
2294 convert_move (targ1, t1, unsignedp);
2295 return 1;
2296 }
2297 else
2298 delete_insns_since (last);
2299 }
2300 }
2301 }
2302
2303 delete_insns_since (entry_last);
2304 return 0;
2305 }
2306 \f
2307 /* Wrapper around expand_unop which takes an rtx code to specify
2308 the operation to perform, not an optab pointer. All other
2309 arguments are the same. */
2310 rtx
2311 expand_simple_unop (mode, code, op0, target, unsignedp)
2312 enum machine_mode mode;
2313 enum rtx_code code;
2314 rtx op0;
2315 rtx target;
2316 int unsignedp;
2317 {
2318 optab unop = code_to_optab[(int) code];
2319 if (unop == 0)
2320 abort ();
2321
2322 return expand_unop (mode, unop, op0, target, unsignedp);
2323 }
2324
2325 /* Generate code to perform an operation specified by UNOPTAB
2326 on operand OP0, with result having machine-mode MODE.
2327
2328 UNSIGNEDP is for the case where we have to widen the operands
2329 to perform the operation. It says to use zero-extension.
2330
2331 If TARGET is nonzero, the value
2332 is generated there, if it is convenient to do so.
2333 In all cases an rtx is returned for the locus of the value;
2334 this may or may not be TARGET. */
2335
2336 rtx
2337 expand_unop (mode, unoptab, op0, target, unsignedp)
2338 enum machine_mode mode;
2339 optab unoptab;
2340 rtx op0;
2341 rtx target;
2342 int unsignedp;
2343 {
2344 enum mode_class class;
2345 enum machine_mode wider_mode;
2346 rtx temp;
2347 rtx last = get_last_insn ();
2348 rtx pat;
2349
2350 class = GET_MODE_CLASS (mode);
2351
2352 op0 = protect_from_queue (op0, 0);
2353
2354 if (flag_force_mem)
2355 {
2356 op0 = force_not_mem (op0);
2357 }
2358
2359 if (target)
2360 target = protect_from_queue (target, 1);
2361
2362 if (unoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2363 {
2364 int icode = (int) unoptab->handlers[(int) mode].insn_code;
2365 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2366 rtx xop0 = op0;
2367
2368 if (target)
2369 temp = target;
2370 else
2371 temp = gen_reg_rtx (mode);
2372
2373 if (GET_MODE (xop0) != VOIDmode
2374 && GET_MODE (xop0) != mode0)
2375 xop0 = convert_to_mode (mode0, xop0, unsignedp);
2376
2377 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
2378
2379 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0))
2380 xop0 = copy_to_mode_reg (mode0, xop0);
2381
2382 if (! (*insn_data[icode].operand[0].predicate) (temp, mode))
2383 temp = gen_reg_rtx (mode);
2384
2385 pat = GEN_FCN (icode) (temp, xop0);
2386 if (pat)
2387 {
2388 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX
2389 && ! add_equal_note (pat, temp, unoptab->code, xop0, NULL_RTX))
2390 {
2391 delete_insns_since (last);
2392 return expand_unop (mode, unoptab, op0, NULL_RTX, unsignedp);
2393 }
2394
2395 emit_insn (pat);
2396
2397 return temp;
2398 }
2399 else
2400 delete_insns_since (last);
2401 }
2402
2403 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2404
2405 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2406 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2407 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2408 {
2409 if (unoptab->handlers[(int) wider_mode].insn_code != CODE_FOR_nothing)
2410 {
2411 rtx xop0 = op0;
2412
2413 /* For certain operations, we need not actually extend
2414 the narrow operand, as long as we will truncate the
2415 results to the same narrowness. */
2416
2417 xop0 = widen_operand (xop0, wider_mode, mode, unsignedp,
2418 (unoptab == neg_optab
2419 || unoptab == one_cmpl_optab)
2420 && class == MODE_INT);
2421
2422 temp = expand_unop (wider_mode, unoptab, xop0, NULL_RTX,
2423 unsignedp);
2424
2425 if (temp)
2426 {
2427 if (class != MODE_INT)
2428 {
2429 if (target == 0)
2430 target = gen_reg_rtx (mode);
2431 convert_move (target, temp, 0);
2432 return target;
2433 }
2434 else
2435 return gen_lowpart (mode, temp);
2436 }
2437 else
2438 delete_insns_since (last);
2439 }
2440 }
2441
2442 /* These can be done a word at a time. */
2443 if (unoptab == one_cmpl_optab
2444 && class == MODE_INT
2445 && GET_MODE_SIZE (mode) > UNITS_PER_WORD
2446 && unoptab->handlers[(int) word_mode].insn_code != CODE_FOR_nothing)
2447 {
2448 int i;
2449 rtx insns;
2450
2451 if (target == 0 || target == op0)
2452 target = gen_reg_rtx (mode);
2453
2454 start_sequence ();
2455
2456 /* Do the actual arithmetic. */
2457 for (i = 0; i < GET_MODE_BITSIZE (mode) / BITS_PER_WORD; i++)
2458 {
2459 rtx target_piece = operand_subword (target, i, 1, mode);
2460 rtx x = expand_unop (word_mode, unoptab,
2461 operand_subword_force (op0, i, mode),
2462 target_piece, unsignedp);
2463
2464 if (target_piece != x)
2465 emit_move_insn (target_piece, x);
2466 }
2467
2468 insns = get_insns ();
2469 end_sequence ();
2470
2471 emit_no_conflict_block (insns, target, op0, NULL_RTX,
2472 gen_rtx_fmt_e (unoptab->code, mode,
2473 copy_rtx (op0)));
2474 return target;
2475 }
2476
2477 /* Open-code the complex negation operation. */
2478 else if (unoptab->code == NEG
2479 && (class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT))
2480 {
2481 rtx target_piece;
2482 rtx x;
2483 rtx seq;
2484
2485 /* Find the correct mode for the real and imaginary parts */
2486 enum machine_mode submode = GET_MODE_INNER (mode);
2487
2488 if (submode == BLKmode)
2489 abort ();
2490
2491 if (target == 0)
2492 target = gen_reg_rtx (mode);
2493
2494 start_sequence ();
2495
2496 target_piece = gen_imagpart (submode, target);
2497 x = expand_unop (submode, unoptab,
2498 gen_imagpart (submode, op0),
2499 target_piece, unsignedp);
2500 if (target_piece != x)
2501 emit_move_insn (target_piece, x);
2502
2503 target_piece = gen_realpart (submode, target);
2504 x = expand_unop (submode, unoptab,
2505 gen_realpart (submode, op0),
2506 target_piece, unsignedp);
2507 if (target_piece != x)
2508 emit_move_insn (target_piece, x);
2509
2510 seq = get_insns ();
2511 end_sequence ();
2512
2513 emit_no_conflict_block (seq, target, op0, 0,
2514 gen_rtx_fmt_e (unoptab->code, mode,
2515 copy_rtx (op0)));
2516 return target;
2517 }
2518
2519 /* Try negating floating point values by flipping the sign bit. */
2520 if (unoptab->code == NEG && class == MODE_FLOAT
2521 && GET_MODE_BITSIZE (mode) <= 2 * HOST_BITS_PER_WIDE_INT)
2522 {
2523 const struct real_format *fmt = real_format_for_mode[mode - QFmode];
2524 enum machine_mode imode = int_mode_for_mode (mode);
2525 int bitpos = (fmt != 0) ? fmt->signbit : -1;
2526
2527 if (imode != BLKmode && bitpos >= 0 && fmt->has_signed_zero)
2528 {
2529 HOST_WIDE_INT hi, lo;
2530 rtx last = get_last_insn ();
2531
2532 if (bitpos < HOST_BITS_PER_WIDE_INT)
2533 {
2534 hi = 0;
2535 lo = (HOST_WIDE_INT) 1 << bitpos;
2536 }
2537 else
2538 {
2539 hi = (HOST_WIDE_INT) 1 << (bitpos - HOST_BITS_PER_WIDE_INT);
2540 lo = 0;
2541 }
2542 temp = expand_binop (imode, xor_optab,
2543 gen_lowpart (imode, op0),
2544 immed_double_const (lo, hi, imode),
2545 NULL_RTX, 1, OPTAB_LIB_WIDEN);
2546 if (temp != 0)
2547 return gen_lowpart (mode, temp);
2548 delete_insns_since (last);
2549 }
2550 }
2551
2552 /* Now try a library call in this mode. */
2553 if (unoptab->handlers[(int) mode].libfunc)
2554 {
2555 rtx insns;
2556 rtx value;
2557
2558 start_sequence ();
2559
2560 /* Pass 1 for NO_QUEUE so we don't lose any increments
2561 if the libcall is cse'd or moved. */
2562 value = emit_library_call_value (unoptab->handlers[(int) mode].libfunc,
2563 NULL_RTX, LCT_CONST, mode, 1, op0, mode);
2564 insns = get_insns ();
2565 end_sequence ();
2566
2567 target = gen_reg_rtx (mode);
2568 emit_libcall_block (insns, target, value,
2569 gen_rtx_fmt_e (unoptab->code, mode, op0));
2570
2571 return target;
2572 }
2573
2574 if (class == MODE_VECTOR_FLOAT || class == MODE_VECTOR_INT)
2575 return expand_vector_unop (mode, unoptab, op0, target, unsignedp);
2576
2577 /* It can't be done in this mode. Can we do it in a wider mode? */
2578
2579 if (class == MODE_INT || class == MODE_FLOAT || class == MODE_COMPLEX_FLOAT)
2580 {
2581 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2582 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2583 {
2584 if ((unoptab->handlers[(int) wider_mode].insn_code
2585 != CODE_FOR_nothing)
2586 || unoptab->handlers[(int) wider_mode].libfunc)
2587 {
2588 rtx xop0 = op0;
2589
2590 /* For certain operations, we need not actually extend
2591 the narrow operand, as long as we will truncate the
2592 results to the same narrowness. */
2593
2594 xop0 = widen_operand (xop0, wider_mode, mode, unsignedp,
2595 (unoptab == neg_optab
2596 || unoptab == one_cmpl_optab)
2597 && class == MODE_INT);
2598
2599 temp = expand_unop (wider_mode, unoptab, xop0, NULL_RTX,
2600 unsignedp);
2601
2602 if (temp)
2603 {
2604 if (class != MODE_INT)
2605 {
2606 if (target == 0)
2607 target = gen_reg_rtx (mode);
2608 convert_move (target, temp, 0);
2609 return target;
2610 }
2611 else
2612 return gen_lowpart (mode, temp);
2613 }
2614 else
2615 delete_insns_since (last);
2616 }
2617 }
2618 }
2619
2620 /* If there is no negate operation, try doing a subtract from zero.
2621 The US Software GOFAST library needs this. */
2622 if (unoptab->code == NEG)
2623 {
2624 rtx temp;
2625 temp = expand_binop (mode,
2626 unoptab == negv_optab ? subv_optab : sub_optab,
2627 CONST0_RTX (mode), op0,
2628 target, unsignedp, OPTAB_LIB_WIDEN);
2629 if (temp)
2630 return temp;
2631 }
2632
2633 return 0;
2634 }
2635 \f
2636 /* Emit code to compute the absolute value of OP0, with result to
2637 TARGET if convenient. (TARGET may be 0.) The return value says
2638 where the result actually is to be found.
2639
2640 MODE is the mode of the operand; the mode of the result is
2641 different but can be deduced from MODE.
2642
2643 */
2644
2645 rtx
2646 expand_abs (mode, op0, target, result_unsignedp, safe)
2647 enum machine_mode mode;
2648 rtx op0;
2649 rtx target;
2650 int result_unsignedp;
2651 int safe;
2652 {
2653 rtx temp, op1;
2654
2655 if (! flag_trapv)
2656 result_unsignedp = 1;
2657
2658 /* First try to do it with a special abs instruction. */
2659 temp = expand_unop (mode, result_unsignedp ? abs_optab : absv_optab,
2660 op0, target, 0);
2661 if (temp != 0)
2662 return temp;
2663
2664 /* For floating point modes, try clearing the sign bit. */
2665 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2666 && GET_MODE_BITSIZE (mode) <= 2 * HOST_BITS_PER_WIDE_INT)
2667 {
2668 const struct real_format *fmt = real_format_for_mode[mode - QFmode];
2669 enum machine_mode imode = int_mode_for_mode (mode);
2670 int bitpos = (fmt != 0) ? fmt->signbit : -1;
2671
2672 if (imode != BLKmode && bitpos >= 0)
2673 {
2674 HOST_WIDE_INT hi, lo;
2675 rtx last = get_last_insn ();
2676
2677 if (bitpos < HOST_BITS_PER_WIDE_INT)
2678 {
2679 hi = 0;
2680 lo = (HOST_WIDE_INT) 1 << bitpos;
2681 }
2682 else
2683 {
2684 hi = (HOST_WIDE_INT) 1 << (bitpos - HOST_BITS_PER_WIDE_INT);
2685 lo = 0;
2686 }
2687 temp = expand_binop (imode, and_optab,
2688 gen_lowpart (imode, op0),
2689 immed_double_const (~lo, ~hi, imode),
2690 NULL_RTX, 1, OPTAB_LIB_WIDEN);
2691 if (temp != 0)
2692 return gen_lowpart (mode, temp);
2693 delete_insns_since (last);
2694 }
2695 }
2696
2697 /* If we have a MAX insn, we can do this as MAX (x, -x). */
2698 if (smax_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2699 {
2700 rtx last = get_last_insn ();
2701
2702 temp = expand_unop (mode, neg_optab, op0, NULL_RTX, 0);
2703 if (temp != 0)
2704 temp = expand_binop (mode, smax_optab, op0, temp, target, 0,
2705 OPTAB_WIDEN);
2706
2707 if (temp != 0)
2708 return temp;
2709
2710 delete_insns_since (last);
2711 }
2712
2713 /* If this machine has expensive jumps, we can do integer absolute
2714 value of X as (((signed) x >> (W-1)) ^ x) - ((signed) x >> (W-1)),
2715 where W is the width of MODE. */
2716
2717 if (GET_MODE_CLASS (mode) == MODE_INT && BRANCH_COST >= 2)
2718 {
2719 rtx extended = expand_shift (RSHIFT_EXPR, mode, op0,
2720 size_int (GET_MODE_BITSIZE (mode) - 1),
2721 NULL_RTX, 0);
2722
2723 temp = expand_binop (mode, xor_optab, extended, op0, target, 0,
2724 OPTAB_LIB_WIDEN);
2725 if (temp != 0)
2726 temp = expand_binop (mode, result_unsignedp ? sub_optab : subv_optab,
2727 temp, extended, target, 0, OPTAB_LIB_WIDEN);
2728
2729 if (temp != 0)
2730 return temp;
2731 }
2732
2733 /* If that does not win, use conditional jump and negate. */
2734
2735 /* It is safe to use the target if it is the same
2736 as the source if this is also a pseudo register */
2737 if (op0 == target && GET_CODE (op0) == REG
2738 && REGNO (op0) >= FIRST_PSEUDO_REGISTER)
2739 safe = 1;
2740
2741 op1 = gen_label_rtx ();
2742 if (target == 0 || ! safe
2743 || GET_MODE (target) != mode
2744 || (GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
2745 || (GET_CODE (target) == REG
2746 && REGNO (target) < FIRST_PSEUDO_REGISTER))
2747 target = gen_reg_rtx (mode);
2748
2749 emit_move_insn (target, op0);
2750 NO_DEFER_POP;
2751
2752 /* If this mode is an integer too wide to compare properly,
2753 compare word by word. Rely on CSE to optimize constant cases. */
2754 if (GET_MODE_CLASS (mode) == MODE_INT
2755 && ! can_compare_p (GE, mode, ccp_jump))
2756 do_jump_by_parts_greater_rtx (mode, 0, target, const0_rtx,
2757 NULL_RTX, op1);
2758 else
2759 do_compare_rtx_and_jump (target, CONST0_RTX (mode), GE, 0, mode,
2760 NULL_RTX, NULL_RTX, op1);
2761
2762 op0 = expand_unop (mode, result_unsignedp ? neg_optab : negv_optab,
2763 target, target, 0);
2764 if (op0 != target)
2765 emit_move_insn (target, op0);
2766 emit_label (op1);
2767 OK_DEFER_POP;
2768 return target;
2769 }
2770 \f
2771 /* Emit code to compute the absolute value of OP0, with result to
2772 TARGET if convenient. (TARGET may be 0.) The return value says
2773 where the result actually is to be found.
2774
2775 MODE is the mode of the operand; the mode of the result is
2776 different but can be deduced from MODE.
2777
2778 UNSIGNEDP is relevant for complex integer modes. */
2779
2780 rtx
2781 expand_complex_abs (mode, op0, target, unsignedp)
2782 enum machine_mode mode;
2783 rtx op0;
2784 rtx target;
2785 int unsignedp;
2786 {
2787 enum mode_class class = GET_MODE_CLASS (mode);
2788 enum machine_mode wider_mode;
2789 rtx temp;
2790 rtx entry_last = get_last_insn ();
2791 rtx last;
2792 rtx pat;
2793 optab this_abs_optab;
2794
2795 /* Find the correct mode for the real and imaginary parts. */
2796 enum machine_mode submode = GET_MODE_INNER (mode);
2797
2798 if (submode == BLKmode)
2799 abort ();
2800
2801 op0 = protect_from_queue (op0, 0);
2802
2803 if (flag_force_mem)
2804 {
2805 op0 = force_not_mem (op0);
2806 }
2807
2808 last = get_last_insn ();
2809
2810 if (target)
2811 target = protect_from_queue (target, 1);
2812
2813 this_abs_optab = ! unsignedp && flag_trapv
2814 && (GET_MODE_CLASS(mode) == MODE_INT)
2815 ? absv_optab : abs_optab;
2816
2817 if (this_abs_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2818 {
2819 int icode = (int) this_abs_optab->handlers[(int) mode].insn_code;
2820 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2821 rtx xop0 = op0;
2822
2823 if (target)
2824 temp = target;
2825 else
2826 temp = gen_reg_rtx (submode);
2827
2828 if (GET_MODE (xop0) != VOIDmode
2829 && GET_MODE (xop0) != mode0)
2830 xop0 = convert_to_mode (mode0, xop0, unsignedp);
2831
2832 /* Now, if insn doesn't accept our operand, put it into a pseudo. */
2833
2834 if (! (*insn_data[icode].operand[1].predicate) (xop0, mode0))
2835 xop0 = copy_to_mode_reg (mode0, xop0);
2836
2837 if (! (*insn_data[icode].operand[0].predicate) (temp, submode))
2838 temp = gen_reg_rtx (submode);
2839
2840 pat = GEN_FCN (icode) (temp, xop0);
2841 if (pat)
2842 {
2843 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX
2844 && ! add_equal_note (pat, temp, this_abs_optab->code, xop0,
2845 NULL_RTX))
2846 {
2847 delete_insns_since (last);
2848 return expand_unop (mode, this_abs_optab, op0, NULL_RTX,
2849 unsignedp);
2850 }
2851
2852 emit_insn (pat);
2853
2854 return temp;
2855 }
2856 else
2857 delete_insns_since (last);
2858 }
2859
2860 /* It can't be done in this mode. Can we open-code it in a wider mode? */
2861
2862 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2863 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2864 {
2865 if (this_abs_optab->handlers[(int) wider_mode].insn_code
2866 != CODE_FOR_nothing)
2867 {
2868 rtx xop0 = op0;
2869
2870 xop0 = convert_modes (wider_mode, mode, xop0, unsignedp);
2871 temp = expand_complex_abs (wider_mode, xop0, NULL_RTX, unsignedp);
2872
2873 if (temp)
2874 {
2875 if (class != MODE_COMPLEX_INT)
2876 {
2877 if (target == 0)
2878 target = gen_reg_rtx (submode);
2879 convert_move (target, temp, 0);
2880 return target;
2881 }
2882 else
2883 return gen_lowpart (submode, temp);
2884 }
2885 else
2886 delete_insns_since (last);
2887 }
2888 }
2889
2890 /* Open-code the complex absolute-value operation
2891 if we can open-code sqrt. Otherwise it's not worth while. */
2892 if (sqrt_optab->handlers[(int) submode].insn_code != CODE_FOR_nothing
2893 && ! flag_trapv)
2894 {
2895 rtx real, imag, total;
2896
2897 real = gen_realpart (submode, op0);
2898 imag = gen_imagpart (submode, op0);
2899
2900 /* Square both parts. */
2901 real = expand_mult (submode, real, real, NULL_RTX, 0);
2902 imag = expand_mult (submode, imag, imag, NULL_RTX, 0);
2903
2904 /* Sum the parts. */
2905 total = expand_binop (submode, add_optab, real, imag, NULL_RTX,
2906 0, OPTAB_LIB_WIDEN);
2907
2908 /* Get sqrt in TARGET. Set TARGET to where the result is. */
2909 target = expand_unop (submode, sqrt_optab, total, target, 0);
2910 if (target == 0)
2911 delete_insns_since (last);
2912 else
2913 return target;
2914 }
2915
2916 /* Now try a library call in this mode. */
2917 if (this_abs_optab->handlers[(int) mode].libfunc)
2918 {
2919 rtx insns;
2920 rtx value;
2921
2922 start_sequence ();
2923
2924 /* Pass 1 for NO_QUEUE so we don't lose any increments
2925 if the libcall is cse'd or moved. */
2926 value = emit_library_call_value (abs_optab->handlers[(int) mode].libfunc,
2927 NULL_RTX, LCT_CONST, submode, 1, op0, mode);
2928 insns = get_insns ();
2929 end_sequence ();
2930
2931 target = gen_reg_rtx (submode);
2932 emit_libcall_block (insns, target, value,
2933 gen_rtx_fmt_e (this_abs_optab->code, mode, op0));
2934
2935 return target;
2936 }
2937
2938 /* It can't be done in this mode. Can we do it in a wider mode? */
2939
2940 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
2941 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
2942 {
2943 if ((this_abs_optab->handlers[(int) wider_mode].insn_code
2944 != CODE_FOR_nothing)
2945 || this_abs_optab->handlers[(int) wider_mode].libfunc)
2946 {
2947 rtx xop0 = op0;
2948
2949 xop0 = convert_modes (wider_mode, mode, xop0, unsignedp);
2950
2951 temp = expand_complex_abs (wider_mode, xop0, NULL_RTX, unsignedp);
2952
2953 if (temp)
2954 {
2955 if (class != MODE_COMPLEX_INT)
2956 {
2957 if (target == 0)
2958 target = gen_reg_rtx (submode);
2959 convert_move (target, temp, 0);
2960 return target;
2961 }
2962 else
2963 return gen_lowpart (submode, temp);
2964 }
2965 else
2966 delete_insns_since (last);
2967 }
2968 }
2969
2970 delete_insns_since (entry_last);
2971 return 0;
2972 }
2973 \f
2974 /* Generate an instruction whose insn-code is INSN_CODE,
2975 with two operands: an output TARGET and an input OP0.
2976 TARGET *must* be nonzero, and the output is always stored there.
2977 CODE is an rtx code such that (CODE OP0) is an rtx that describes
2978 the value that is stored into TARGET. */
2979
2980 void
2981 emit_unop_insn (icode, target, op0, code)
2982 int icode;
2983 rtx target;
2984 rtx op0;
2985 enum rtx_code code;
2986 {
2987 rtx temp;
2988 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
2989 rtx pat;
2990
2991 temp = target = protect_from_queue (target, 1);
2992
2993 op0 = protect_from_queue (op0, 0);
2994
2995 /* Sign and zero extension from memory is often done specially on
2996 RISC machines, so forcing into a register here can pessimize
2997 code. */
2998 if (flag_force_mem && code != SIGN_EXTEND && code != ZERO_EXTEND)
2999 op0 = force_not_mem (op0);
3000
3001 /* Now, if insn does not accept our operands, put them into pseudos. */
3002
3003 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
3004 op0 = copy_to_mode_reg (mode0, op0);
3005
3006 if (! (*insn_data[icode].operand[0].predicate) (temp, GET_MODE (temp))
3007 || (flag_force_mem && GET_CODE (temp) == MEM))
3008 temp = gen_reg_rtx (GET_MODE (temp));
3009
3010 pat = GEN_FCN (icode) (temp, op0);
3011
3012 if (INSN_P (pat) && NEXT_INSN (pat) != NULL_RTX && code != UNKNOWN)
3013 add_equal_note (pat, temp, code, op0, NULL_RTX);
3014
3015 emit_insn (pat);
3016
3017 if (temp != target)
3018 emit_move_insn (target, temp);
3019 }
3020 \f
3021 /* Emit code to perform a series of operations on a multi-word quantity, one
3022 word at a time.
3023
3024 Such a block is preceded by a CLOBBER of the output, consists of multiple
3025 insns, each setting one word of the output, and followed by a SET copying
3026 the output to itself.
3027
3028 Each of the insns setting words of the output receives a REG_NO_CONFLICT
3029 note indicating that it doesn't conflict with the (also multi-word)
3030 inputs. The entire block is surrounded by REG_LIBCALL and REG_RETVAL
3031 notes.
3032
3033 INSNS is a block of code generated to perform the operation, not including
3034 the CLOBBER and final copy. All insns that compute intermediate values
3035 are first emitted, followed by the block as described above.
3036
3037 TARGET, OP0, and OP1 are the output and inputs of the operations,
3038 respectively. OP1 may be zero for a unary operation.
3039
3040 EQUIV, if nonzero, is an expression to be placed into a REG_EQUAL note
3041 on the last insn.
3042
3043 If TARGET is not a register, INSNS is simply emitted with no special
3044 processing. Likewise if anything in INSNS is not an INSN or if
3045 there is a libcall block inside INSNS.
3046
3047 The final insn emitted is returned. */
3048
3049 rtx
3050 emit_no_conflict_block (insns, target, op0, op1, equiv)
3051 rtx insns;
3052 rtx target;
3053 rtx op0, op1;
3054 rtx equiv;
3055 {
3056 rtx prev, next, first, last, insn;
3057
3058 if (GET_CODE (target) != REG || reload_in_progress)
3059 return emit_insn (insns);
3060 else
3061 for (insn = insns; insn; insn = NEXT_INSN (insn))
3062 if (GET_CODE (insn) != INSN
3063 || find_reg_note (insn, REG_LIBCALL, NULL_RTX))
3064 return emit_insn (insns);
3065
3066 /* First emit all insns that do not store into words of the output and remove
3067 these from the list. */
3068 for (insn = insns; insn; insn = next)
3069 {
3070 rtx set = 0, note;
3071 int i;
3072
3073 next = NEXT_INSN (insn);
3074
3075 /* Some ports (cris) create an libcall regions at their own. We must
3076 avoid any potential nesting of LIBCALLs. */
3077 if ((note = find_reg_note (insn, REG_LIBCALL, NULL)) != NULL)
3078 remove_note (insn, note);
3079 if ((note = find_reg_note (insn, REG_RETVAL, NULL)) != NULL)
3080 remove_note (insn, note);
3081
3082 if (GET_CODE (PATTERN (insn)) == SET || GET_CODE (PATTERN (insn)) == USE
3083 || GET_CODE (PATTERN (insn)) == CLOBBER)
3084 set = PATTERN (insn);
3085 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
3086 {
3087 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
3088 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
3089 {
3090 set = XVECEXP (PATTERN (insn), 0, i);
3091 break;
3092 }
3093 }
3094
3095 if (set == 0)
3096 abort ();
3097
3098 if (! reg_overlap_mentioned_p (target, SET_DEST (set)))
3099 {
3100 if (PREV_INSN (insn))
3101 NEXT_INSN (PREV_INSN (insn)) = next;
3102 else
3103 insns = next;
3104
3105 if (next)
3106 PREV_INSN (next) = PREV_INSN (insn);
3107
3108 add_insn (insn);
3109 }
3110 }
3111
3112 prev = get_last_insn ();
3113
3114 /* Now write the CLOBBER of the output, followed by the setting of each
3115 of the words, followed by the final copy. */
3116 if (target != op0 && target != op1)
3117 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
3118
3119 for (insn = insns; insn; insn = next)
3120 {
3121 next = NEXT_INSN (insn);
3122 add_insn (insn);
3123
3124 if (op1 && GET_CODE (op1) == REG)
3125 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT, op1,
3126 REG_NOTES (insn));
3127
3128 if (op0 && GET_CODE (op0) == REG)
3129 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_NO_CONFLICT, op0,
3130 REG_NOTES (insn));
3131 }
3132
3133 if (mov_optab->handlers[(int) GET_MODE (target)].insn_code
3134 != CODE_FOR_nothing)
3135 {
3136 last = emit_move_insn (target, target);
3137 if (equiv)
3138 set_unique_reg_note (last, REG_EQUAL, equiv);
3139 }
3140 else
3141 {
3142 last = get_last_insn ();
3143
3144 /* Remove any existing REG_EQUAL note from "last", or else it will
3145 be mistaken for a note referring to the full contents of the
3146 alleged libcall value when found together with the REG_RETVAL
3147 note added below. An existing note can come from an insn
3148 expansion at "last". */
3149 remove_note (last, find_reg_note (last, REG_EQUAL, NULL_RTX));
3150 }
3151
3152 if (prev == 0)
3153 first = get_insns ();
3154 else
3155 first = NEXT_INSN (prev);
3156
3157 /* Encapsulate the block so it gets manipulated as a unit. */
3158 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3159 REG_NOTES (first));
3160 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, REG_NOTES (last));
3161
3162 return last;
3163 }
3164 \f
3165 /* Emit code to make a call to a constant function or a library call.
3166
3167 INSNS is a list containing all insns emitted in the call.
3168 These insns leave the result in RESULT. Our block is to copy RESULT
3169 to TARGET, which is logically equivalent to EQUIV.
3170
3171 We first emit any insns that set a pseudo on the assumption that these are
3172 loading constants into registers; doing so allows them to be safely cse'ed
3173 between blocks. Then we emit all the other insns in the block, followed by
3174 an insn to move RESULT to TARGET. This last insn will have a REQ_EQUAL
3175 note with an operand of EQUIV.
3176
3177 Moving assignments to pseudos outside of the block is done to improve
3178 the generated code, but is not required to generate correct code,
3179 hence being unable to move an assignment is not grounds for not making
3180 a libcall block. There are two reasons why it is safe to leave these
3181 insns inside the block: First, we know that these pseudos cannot be
3182 used in generated RTL outside the block since they are created for
3183 temporary purposes within the block. Second, CSE will not record the
3184 values of anything set inside a libcall block, so we know they must
3185 be dead at the end of the block.
3186
3187 Except for the first group of insns (the ones setting pseudos), the
3188 block is delimited by REG_RETVAL and REG_LIBCALL notes. */
3189
3190 void
3191 emit_libcall_block (insns, target, result, equiv)
3192 rtx insns;
3193 rtx target;
3194 rtx result;
3195 rtx equiv;
3196 {
3197 rtx final_dest = target;
3198 rtx prev, next, first, last, insn;
3199
3200 /* If this is a reg with REG_USERVAR_P set, then it could possibly turn
3201 into a MEM later. Protect the libcall block from this change. */
3202 if (! REG_P (target) || REG_USERVAR_P (target))
3203 target = gen_reg_rtx (GET_MODE (target));
3204
3205 /* If we're using non-call exceptions, a libcall corresponding to an
3206 operation that may trap may also trap. */
3207 if (flag_non_call_exceptions && may_trap_p (equiv))
3208 {
3209 for (insn = insns; insn; insn = NEXT_INSN (insn))
3210 if (GET_CODE (insn) == CALL_INSN)
3211 {
3212 rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
3213
3214 if (note != 0 && INTVAL (XEXP (note, 0)) <= 0)
3215 remove_note (insn, note);
3216 }
3217 }
3218 else
3219 /* look for any CALL_INSNs in this sequence, and attach a REG_EH_REGION
3220 reg note to indicate that this call cannot throw or execute a nonlocal
3221 goto (unless there is already a REG_EH_REGION note, in which case
3222 we update it). */
3223 for (insn = insns; insn; insn = NEXT_INSN (insn))
3224 if (GET_CODE (insn) == CALL_INSN)
3225 {
3226 rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
3227
3228 if (note != 0)
3229 XEXP (note, 0) = GEN_INT (-1);
3230 else
3231 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, GEN_INT (-1),
3232 REG_NOTES (insn));
3233 }
3234
3235 /* First emit all insns that set pseudos. Remove them from the list as
3236 we go. Avoid insns that set pseudos which were referenced in previous
3237 insns. These can be generated by move_by_pieces, for example,
3238 to update an address. Similarly, avoid insns that reference things
3239 set in previous insns. */
3240
3241 for (insn = insns; insn; insn = next)
3242 {
3243 rtx set = single_set (insn);
3244 rtx note;
3245
3246 /* Some ports (cris) create an libcall regions at their own. We must
3247 avoid any potential nesting of LIBCALLs. */
3248 if ((note = find_reg_note (insn, REG_LIBCALL, NULL)) != NULL)
3249 remove_note (insn, note);
3250 if ((note = find_reg_note (insn, REG_RETVAL, NULL)) != NULL)
3251 remove_note (insn, note);
3252
3253 next = NEXT_INSN (insn);
3254
3255 if (set != 0 && GET_CODE (SET_DEST (set)) == REG
3256 && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
3257 && (insn == insns
3258 || ((! INSN_P(insns)
3259 || ! reg_mentioned_p (SET_DEST (set), PATTERN (insns)))
3260 && ! reg_used_between_p (SET_DEST (set), insns, insn)
3261 && ! modified_in_p (SET_SRC (set), insns)
3262 && ! modified_between_p (SET_SRC (set), insns, insn))))
3263 {
3264 if (PREV_INSN (insn))
3265 NEXT_INSN (PREV_INSN (insn)) = next;
3266 else
3267 insns = next;
3268
3269 if (next)
3270 PREV_INSN (next) = PREV_INSN (insn);
3271
3272 add_insn (insn);
3273 }
3274 }
3275
3276 prev = get_last_insn ();
3277
3278 /* Write the remaining insns followed by the final copy. */
3279
3280 for (insn = insns; insn; insn = next)
3281 {
3282 next = NEXT_INSN (insn);
3283
3284 add_insn (insn);
3285 }
3286
3287 last = emit_move_insn (target, result);
3288 if (mov_optab->handlers[(int) GET_MODE (target)].insn_code
3289 != CODE_FOR_nothing)
3290 set_unique_reg_note (last, REG_EQUAL, copy_rtx (equiv));
3291 else
3292 {
3293 /* Remove any existing REG_EQUAL note from "last", or else it will
3294 be mistaken for a note referring to the full contents of the
3295 libcall value when found together with the REG_RETVAL note added
3296 below. An existing note can come from an insn expansion at
3297 "last". */
3298 remove_note (last, find_reg_note (last, REG_EQUAL, NULL_RTX));
3299 }
3300
3301 if (final_dest != target)
3302 emit_move_insn (final_dest, target);
3303
3304 if (prev == 0)
3305 first = get_insns ();
3306 else
3307 first = NEXT_INSN (prev);
3308
3309 /* Encapsulate the block so it gets manipulated as a unit. */
3310 if (!flag_non_call_exceptions || !may_trap_p (equiv))
3311 {
3312 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3313 REG_NOTES (first));
3314 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
3315 REG_NOTES (last));
3316 }
3317 }
3318 \f
3319 /* Generate code to store zero in X. */
3320
3321 void
3322 emit_clr_insn (x)
3323 rtx x;
3324 {
3325 emit_move_insn (x, const0_rtx);
3326 }
3327
3328 /* Generate code to store 1 in X
3329 assuming it contains zero beforehand. */
3330
3331 void
3332 emit_0_to_1_insn (x)
3333 rtx x;
3334 {
3335 emit_move_insn (x, const1_rtx);
3336 }
3337
3338 /* Nonzero if we can perform a comparison of mode MODE straightforwardly.
3339 PURPOSE describes how this comparison will be used. CODE is the rtx
3340 comparison code we will be using.
3341
3342 ??? Actually, CODE is slightly weaker than that. A target is still
3343 required to implement all of the normal bcc operations, but not
3344 required to implement all (or any) of the unordered bcc operations. */
3345
3346 int
3347 can_compare_p (code, mode, purpose)
3348 enum rtx_code code;
3349 enum machine_mode mode;
3350 enum can_compare_purpose purpose;
3351 {
3352 do
3353 {
3354 if (cmp_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3355 {
3356 if (purpose == ccp_jump)
3357 return bcc_gen_fctn[(int) code] != NULL;
3358 else if (purpose == ccp_store_flag)
3359 return setcc_gen_code[(int) code] != CODE_FOR_nothing;
3360 else
3361 /* There's only one cmov entry point, and it's allowed to fail. */
3362 return 1;
3363 }
3364 if (purpose == ccp_jump
3365 && cbranch_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3366 return 1;
3367 if (purpose == ccp_cmov
3368 && cmov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3369 return 1;
3370 if (purpose == ccp_store_flag
3371 && cstore_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3372 return 1;
3373
3374 mode = GET_MODE_WIDER_MODE (mode);
3375 }
3376 while (mode != VOIDmode);
3377
3378 return 0;
3379 }
3380
3381 /* This function is called when we are going to emit a compare instruction that
3382 compares the values found in *PX and *PY, using the rtl operator COMPARISON.
3383
3384 *PMODE is the mode of the inputs (in case they are const_int).
3385 *PUNSIGNEDP nonzero says that the operands are unsigned;
3386 this matters if they need to be widened.
3387
3388 If they have mode BLKmode, then SIZE specifies the size of both operands.
3389
3390 This function performs all the setup necessary so that the caller only has
3391 to emit a single comparison insn. This setup can involve doing a BLKmode
3392 comparison or emitting a library call to perform the comparison if no insn
3393 is available to handle it.
3394 The values which are passed in through pointers can be modified; the caller
3395 should perform the comparison on the modified values. */
3396
3397 static void
3398 prepare_cmp_insn (px, py, pcomparison, size, pmode, punsignedp, purpose)
3399 rtx *px, *py;
3400 enum rtx_code *pcomparison;
3401 rtx size;
3402 enum machine_mode *pmode;
3403 int *punsignedp;
3404 enum can_compare_purpose purpose;
3405 {
3406 enum machine_mode mode = *pmode;
3407 rtx x = *px, y = *py;
3408 int unsignedp = *punsignedp;
3409 enum mode_class class;
3410
3411 class = GET_MODE_CLASS (mode);
3412
3413 /* They could both be VOIDmode if both args are immediate constants,
3414 but we should fold that at an earlier stage.
3415 With no special code here, this will call abort,
3416 reminding the programmer to implement such folding. */
3417
3418 if (mode != BLKmode && flag_force_mem)
3419 {
3420 x = force_not_mem (x);
3421 y = force_not_mem (y);
3422 }
3423
3424 /* If we are inside an appropriately-short loop and one operand is an
3425 expensive constant, force it into a register. */
3426 if (CONSTANT_P (x) && preserve_subexpressions_p ()
3427 && rtx_cost (x, COMPARE) > COSTS_N_INSNS (1))
3428 x = force_reg (mode, x);
3429
3430 if (CONSTANT_P (y) && preserve_subexpressions_p ()
3431 && rtx_cost (y, COMPARE) > COSTS_N_INSNS (1))
3432 y = force_reg (mode, y);
3433
3434 #ifdef HAVE_cc0
3435 /* Abort if we have a non-canonical comparison. The RTL documentation
3436 states that canonical comparisons are required only for targets which
3437 have cc0. */
3438 if (CONSTANT_P (x) && ! CONSTANT_P (y))
3439 abort ();
3440 #endif
3441
3442 /* Don't let both operands fail to indicate the mode. */
3443 if (GET_MODE (x) == VOIDmode && GET_MODE (y) == VOIDmode)
3444 x = force_reg (mode, x);
3445
3446 /* Handle all BLKmode compares. */
3447
3448 if (mode == BLKmode)
3449 {
3450 rtx result;
3451 enum machine_mode result_mode;
3452 rtx opalign ATTRIBUTE_UNUSED
3453 = GEN_INT (MIN (MEM_ALIGN (x), MEM_ALIGN (y)) / BITS_PER_UNIT);
3454
3455 emit_queue ();
3456 x = protect_from_queue (x, 0);
3457 y = protect_from_queue (y, 0);
3458
3459 if (size == 0)
3460 abort ();
3461 #ifdef HAVE_cmpstrqi
3462 if (HAVE_cmpstrqi
3463 && GET_CODE (size) == CONST_INT
3464 && INTVAL (size) < (1 << GET_MODE_BITSIZE (QImode)))
3465 {
3466 result_mode = insn_data[(int) CODE_FOR_cmpstrqi].operand[0].mode;
3467 result = gen_reg_rtx (result_mode);
3468 emit_insn (gen_cmpstrqi (result, x, y, size, opalign));
3469 }
3470 else
3471 #endif
3472 #ifdef HAVE_cmpstrhi
3473 if (HAVE_cmpstrhi
3474 && GET_CODE (size) == CONST_INT
3475 && INTVAL (size) < (1 << GET_MODE_BITSIZE (HImode)))
3476 {
3477 result_mode = insn_data[(int) CODE_FOR_cmpstrhi].operand[0].mode;
3478 result = gen_reg_rtx (result_mode);
3479 emit_insn (gen_cmpstrhi (result, x, y, size, opalign));
3480 }
3481 else
3482 #endif
3483 #ifdef HAVE_cmpstrsi
3484 if (HAVE_cmpstrsi)
3485 {
3486 result_mode = insn_data[(int) CODE_FOR_cmpstrsi].operand[0].mode;
3487 result = gen_reg_rtx (result_mode);
3488 size = protect_from_queue (size, 0);
3489 emit_insn (gen_cmpstrsi (result, x, y,
3490 convert_to_mode (SImode, size, 1),
3491 opalign));
3492 }
3493 else
3494 #endif
3495 {
3496 #ifdef TARGET_MEM_FUNCTIONS
3497 result = emit_library_call_value (memcmp_libfunc, NULL_RTX, LCT_PURE_MAKE_BLOCK,
3498 TYPE_MODE (integer_type_node), 3,
3499 XEXP (x, 0), Pmode, XEXP (y, 0), Pmode,
3500 convert_to_mode (TYPE_MODE (sizetype), size,
3501 TREE_UNSIGNED (sizetype)),
3502 TYPE_MODE (sizetype));
3503 #else
3504 result = emit_library_call_value (bcmp_libfunc, NULL_RTX, LCT_PURE_MAKE_BLOCK,
3505 TYPE_MODE (integer_type_node), 3,
3506 XEXP (x, 0), Pmode, XEXP (y, 0), Pmode,
3507 convert_to_mode (TYPE_MODE (integer_type_node),
3508 size,
3509 TREE_UNSIGNED (integer_type_node)),
3510 TYPE_MODE (integer_type_node));
3511 #endif
3512
3513 result_mode = TYPE_MODE (integer_type_node);
3514 }
3515 *px = result;
3516 *py = const0_rtx;
3517 *pmode = result_mode;
3518 return;
3519 }
3520
3521 *px = x;
3522 *py = y;
3523 if (can_compare_p (*pcomparison, mode, purpose))
3524 return;
3525
3526 /* Handle a lib call just for the mode we are using. */
3527
3528 if (cmp_optab->handlers[(int) mode].libfunc && class != MODE_FLOAT)
3529 {
3530 rtx libfunc = cmp_optab->handlers[(int) mode].libfunc;
3531 rtx result;
3532
3533 /* If we want unsigned, and this mode has a distinct unsigned
3534 comparison routine, use that. */
3535 if (unsignedp && ucmp_optab->handlers[(int) mode].libfunc)
3536 libfunc = ucmp_optab->handlers[(int) mode].libfunc;
3537
3538 result = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST_MAKE_BLOCK,
3539 word_mode, 2, x, mode, y, mode);
3540
3541 /* Integer comparison returns a result that must be compared against 1,
3542 so that even if we do an unsigned compare afterward,
3543 there is still a value that can represent the result "less than". */
3544 *px = result;
3545 *py = const1_rtx;
3546 *pmode = word_mode;
3547 return;
3548 }
3549
3550 if (class == MODE_FLOAT)
3551 prepare_float_lib_cmp (px, py, pcomparison, pmode, punsignedp);
3552
3553 else
3554 abort ();
3555 }
3556
3557 /* Before emitting an insn with code ICODE, make sure that X, which is going
3558 to be used for operand OPNUM of the insn, is converted from mode MODE to
3559 WIDER_MODE (UNSIGNEDP determines whether it is an unsigned conversion), and
3560 that it is accepted by the operand predicate. Return the new value. */
3561
3562 rtx
3563 prepare_operand (icode, x, opnum, mode, wider_mode, unsignedp)
3564 int icode;
3565 rtx x;
3566 int opnum;
3567 enum machine_mode mode, wider_mode;
3568 int unsignedp;
3569 {
3570 x = protect_from_queue (x, 0);
3571
3572 if (mode != wider_mode)
3573 x = convert_modes (wider_mode, mode, x, unsignedp);
3574
3575 if (! (*insn_data[icode].operand[opnum].predicate)
3576 (x, insn_data[icode].operand[opnum].mode))
3577 x = copy_to_mode_reg (insn_data[icode].operand[opnum].mode, x);
3578 return x;
3579 }
3580
3581 /* Subroutine of emit_cmp_and_jump_insns; this function is called when we know
3582 we can do the comparison.
3583 The arguments are the same as for emit_cmp_and_jump_insns; but LABEL may
3584 be NULL_RTX which indicates that only a comparison is to be generated. */
3585
3586 static void
3587 emit_cmp_and_jump_insn_1 (x, y, mode, comparison, unsignedp, label)
3588 rtx x, y;
3589 enum machine_mode mode;
3590 enum rtx_code comparison;
3591 int unsignedp;
3592 rtx label;
3593 {
3594 rtx test = gen_rtx_fmt_ee (comparison, mode, x, y);
3595 enum mode_class class = GET_MODE_CLASS (mode);
3596 enum machine_mode wider_mode = mode;
3597
3598 /* Try combined insns first. */
3599 do
3600 {
3601 enum insn_code icode;
3602 PUT_MODE (test, wider_mode);
3603
3604 if (label)
3605 {
3606 icode = cbranch_optab->handlers[(int) wider_mode].insn_code;
3607
3608 if (icode != CODE_FOR_nothing
3609 && (*insn_data[icode].operand[0].predicate) (test, wider_mode))
3610 {
3611 x = prepare_operand (icode, x, 1, mode, wider_mode, unsignedp);
3612 y = prepare_operand (icode, y, 2, mode, wider_mode, unsignedp);
3613 emit_jump_insn (GEN_FCN (icode) (test, x, y, label));
3614 return;
3615 }
3616 }
3617
3618 /* Handle some compares against zero. */
3619 icode = (int) tst_optab->handlers[(int) wider_mode].insn_code;
3620 if (y == CONST0_RTX (mode) && icode != CODE_FOR_nothing)
3621 {
3622 x = prepare_operand (icode, x, 0, mode, wider_mode, unsignedp);
3623 emit_insn (GEN_FCN (icode) (x));
3624 if (label)
3625 emit_jump_insn ((*bcc_gen_fctn[(int) comparison]) (label));
3626 return;
3627 }
3628
3629 /* Handle compares for which there is a directly suitable insn. */
3630
3631 icode = (int) cmp_optab->handlers[(int) wider_mode].insn_code;
3632 if (icode != CODE_FOR_nothing)
3633 {
3634 x = prepare_operand (icode, x, 0, mode, wider_mode, unsignedp);
3635 y = prepare_operand (icode, y, 1, mode, wider_mode, unsignedp);
3636 emit_insn (GEN_FCN (icode) (x, y));
3637 if (label)
3638 emit_jump_insn ((*bcc_gen_fctn[(int) comparison]) (label));
3639 return;
3640 }
3641
3642 if (class != MODE_INT && class != MODE_FLOAT
3643 && class != MODE_COMPLEX_FLOAT)
3644 break;
3645
3646 wider_mode = GET_MODE_WIDER_MODE (wider_mode);
3647 }
3648 while (wider_mode != VOIDmode);
3649
3650 abort ();
3651 }
3652
3653 /* Generate code to compare X with Y so that the condition codes are
3654 set and to jump to LABEL if the condition is true. If X is a
3655 constant and Y is not a constant, then the comparison is swapped to
3656 ensure that the comparison RTL has the canonical form.
3657
3658 UNSIGNEDP nonzero says that X and Y are unsigned; this matters if they
3659 need to be widened by emit_cmp_insn. UNSIGNEDP is also used to select
3660 the proper branch condition code.
3661
3662 If X and Y have mode BLKmode, then SIZE specifies the size of both X and Y.
3663
3664 MODE is the mode of the inputs (in case they are const_int).
3665
3666 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). It will
3667 be passed unchanged to emit_cmp_insn, then potentially converted into an
3668 unsigned variant based on UNSIGNEDP to select a proper jump instruction. */
3669
3670 void
3671 emit_cmp_and_jump_insns (x, y, comparison, size, mode, unsignedp, label)
3672 rtx x, y;
3673 enum rtx_code comparison;
3674 rtx size;
3675 enum machine_mode mode;
3676 int unsignedp;
3677 rtx label;
3678 {
3679 rtx op0 = x, op1 = y;
3680
3681 /* Swap operands and condition to ensure canonical RTL. */
3682 if (swap_commutative_operands_p (x, y))
3683 {
3684 /* If we're not emitting a branch, this means some caller
3685 is out of sync. */
3686 if (! label)
3687 abort ();
3688
3689 op0 = y, op1 = x;
3690 comparison = swap_condition (comparison);
3691 }
3692
3693 #ifdef HAVE_cc0
3694 /* If OP0 is still a constant, then both X and Y must be constants. Force
3695 X into a register to avoid aborting in emit_cmp_insn due to non-canonical
3696 RTL. */
3697 if (CONSTANT_P (op0))
3698 op0 = force_reg (mode, op0);
3699 #endif
3700
3701 emit_queue ();
3702 if (unsignedp)
3703 comparison = unsigned_condition (comparison);
3704
3705 prepare_cmp_insn (&op0, &op1, &comparison, size, &mode, &unsignedp,
3706 ccp_jump);
3707 emit_cmp_and_jump_insn_1 (op0, op1, mode, comparison, unsignedp, label);
3708 }
3709
3710 /* Like emit_cmp_and_jump_insns, but generate only the comparison. */
3711
3712 void
3713 emit_cmp_insn (x, y, comparison, size, mode, unsignedp)
3714 rtx x, y;
3715 enum rtx_code comparison;
3716 rtx size;
3717 enum machine_mode mode;
3718 int unsignedp;
3719 {
3720 emit_cmp_and_jump_insns (x, y, comparison, size, mode, unsignedp, 0);
3721 }
3722 \f
3723 /* Emit a library call comparison between floating point X and Y.
3724 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.). */
3725
3726 static void
3727 prepare_float_lib_cmp (px, py, pcomparison, pmode, punsignedp)
3728 rtx *px, *py;
3729 enum rtx_code *pcomparison;
3730 enum machine_mode *pmode;
3731 int *punsignedp;
3732 {
3733 enum rtx_code comparison = *pcomparison;
3734 rtx tmp;
3735 rtx x = *px = protect_from_queue (*px, 0);
3736 rtx y = *py = protect_from_queue (*py, 0);
3737 enum machine_mode mode = GET_MODE (x);
3738 rtx libfunc = 0;
3739 rtx result;
3740
3741 if (mode == HFmode)
3742 switch (comparison)
3743 {
3744 case EQ:
3745 libfunc = eqhf2_libfunc;
3746 break;
3747
3748 case NE:
3749 libfunc = nehf2_libfunc;
3750 break;
3751
3752 case GT:
3753 libfunc = gthf2_libfunc;
3754 if (libfunc == NULL_RTX)
3755 {
3756 tmp = x; x = y; y = tmp;
3757 *pcomparison = LT;
3758 libfunc = lthf2_libfunc;
3759 }
3760 break;
3761
3762 case GE:
3763 libfunc = gehf2_libfunc;
3764 if (libfunc == NULL_RTX)
3765 {
3766 tmp = x; x = y; y = tmp;
3767 *pcomparison = LE;
3768 libfunc = lehf2_libfunc;
3769 }
3770 break;
3771
3772 case LT:
3773 libfunc = lthf2_libfunc;
3774 if (libfunc == NULL_RTX)
3775 {
3776 tmp = x; x = y; y = tmp;
3777 *pcomparison = GT;
3778 libfunc = gthf2_libfunc;
3779 }
3780 break;
3781
3782 case LE:
3783 libfunc = lehf2_libfunc;
3784 if (libfunc == NULL_RTX)
3785 {
3786 tmp = x; x = y; y = tmp;
3787 *pcomparison = GE;
3788 libfunc = gehf2_libfunc;
3789 }
3790 break;
3791
3792 case UNORDERED:
3793 libfunc = unordhf2_libfunc;
3794 break;
3795
3796 default:
3797 break;
3798 }
3799 else if (mode == SFmode)
3800 switch (comparison)
3801 {
3802 case EQ:
3803 libfunc = eqsf2_libfunc;
3804 break;
3805
3806 case NE:
3807 libfunc = nesf2_libfunc;
3808 break;
3809
3810 case GT:
3811 libfunc = gtsf2_libfunc;
3812 if (libfunc == NULL_RTX)
3813 {
3814 tmp = x; x = y; y = tmp;
3815 *pcomparison = LT;
3816 libfunc = ltsf2_libfunc;
3817 }
3818 break;
3819
3820 case GE:
3821 libfunc = gesf2_libfunc;
3822 if (libfunc == NULL_RTX)
3823 {
3824 tmp = x; x = y; y = tmp;
3825 *pcomparison = LE;
3826 libfunc = lesf2_libfunc;
3827 }
3828 break;
3829
3830 case LT:
3831 libfunc = ltsf2_libfunc;
3832 if (libfunc == NULL_RTX)
3833 {
3834 tmp = x; x = y; y = tmp;
3835 *pcomparison = GT;
3836 libfunc = gtsf2_libfunc;
3837 }
3838 break;
3839
3840 case LE:
3841 libfunc = lesf2_libfunc;
3842 if (libfunc == NULL_RTX)
3843 {
3844 tmp = x; x = y; y = tmp;
3845 *pcomparison = GE;
3846 libfunc = gesf2_libfunc;
3847 }
3848 break;
3849
3850 case UNORDERED:
3851 libfunc = unordsf2_libfunc;
3852 break;
3853
3854 default:
3855 break;
3856 }
3857 else if (mode == DFmode)
3858 switch (comparison)
3859 {
3860 case EQ:
3861 libfunc = eqdf2_libfunc;
3862 break;
3863
3864 case NE:
3865 libfunc = nedf2_libfunc;
3866 break;
3867
3868 case GT:
3869 libfunc = gtdf2_libfunc;
3870 if (libfunc == NULL_RTX)
3871 {
3872 tmp = x; x = y; y = tmp;
3873 *pcomparison = LT;
3874 libfunc = ltdf2_libfunc;
3875 }
3876 break;
3877
3878 case GE:
3879 libfunc = gedf2_libfunc;
3880 if (libfunc == NULL_RTX)
3881 {
3882 tmp = x; x = y; y = tmp;
3883 *pcomparison = LE;
3884 libfunc = ledf2_libfunc;
3885 }
3886 break;
3887
3888 case LT:
3889 libfunc = ltdf2_libfunc;
3890 if (libfunc == NULL_RTX)
3891 {
3892 tmp = x; x = y; y = tmp;
3893 *pcomparison = GT;
3894 libfunc = gtdf2_libfunc;
3895 }
3896 break;
3897
3898 case LE:
3899 libfunc = ledf2_libfunc;
3900 if (libfunc == NULL_RTX)
3901 {
3902 tmp = x; x = y; y = tmp;
3903 *pcomparison = GE;
3904 libfunc = gedf2_libfunc;
3905 }
3906 break;
3907
3908 case UNORDERED:
3909 libfunc = unorddf2_libfunc;
3910 break;
3911
3912 default:
3913 break;
3914 }
3915 else if (mode == XFmode)
3916 switch (comparison)
3917 {
3918 case EQ:
3919 libfunc = eqxf2_libfunc;
3920 break;
3921
3922 case NE:
3923 libfunc = nexf2_libfunc;
3924 break;
3925
3926 case GT:
3927 libfunc = gtxf2_libfunc;
3928 if (libfunc == NULL_RTX)
3929 {
3930 tmp = x; x = y; y = tmp;
3931 *pcomparison = LT;
3932 libfunc = ltxf2_libfunc;
3933 }
3934 break;
3935
3936 case GE:
3937 libfunc = gexf2_libfunc;
3938 if (libfunc == NULL_RTX)
3939 {
3940 tmp = x; x = y; y = tmp;
3941 *pcomparison = LE;
3942 libfunc = lexf2_libfunc;
3943 }
3944 break;
3945
3946 case LT:
3947 libfunc = ltxf2_libfunc;
3948 if (libfunc == NULL_RTX)
3949 {
3950 tmp = x; x = y; y = tmp;
3951 *pcomparison = GT;
3952 libfunc = gtxf2_libfunc;
3953 }
3954 break;
3955
3956 case LE:
3957 libfunc = lexf2_libfunc;
3958 if (libfunc == NULL_RTX)
3959 {
3960 tmp = x; x = y; y = tmp;
3961 *pcomparison = GE;
3962 libfunc = gexf2_libfunc;
3963 }
3964 break;
3965
3966 case UNORDERED:
3967 libfunc = unordxf2_libfunc;
3968 break;
3969
3970 default:
3971 break;
3972 }
3973 else if (mode == TFmode)
3974 switch (comparison)
3975 {
3976 case EQ:
3977 libfunc = eqtf2_libfunc;
3978 break;
3979
3980 case NE:
3981 libfunc = netf2_libfunc;
3982 break;
3983
3984 case GT:
3985 libfunc = gttf2_libfunc;
3986 if (libfunc == NULL_RTX)
3987 {
3988 tmp = x; x = y; y = tmp;
3989 *pcomparison = LT;
3990 libfunc = lttf2_libfunc;
3991 }
3992 break;
3993
3994 case GE:
3995 libfunc = getf2_libfunc;
3996 if (libfunc == NULL_RTX)
3997 {
3998 tmp = x; x = y; y = tmp;
3999 *pcomparison = LE;
4000 libfunc = letf2_libfunc;
4001 }
4002 break;
4003
4004 case LT:
4005 libfunc = lttf2_libfunc;
4006 if (libfunc == NULL_RTX)
4007 {
4008 tmp = x; x = y; y = tmp;
4009 *pcomparison = GT;
4010 libfunc = gttf2_libfunc;
4011 }
4012 break;
4013
4014 case LE:
4015 libfunc = letf2_libfunc;
4016 if (libfunc == NULL_RTX)
4017 {
4018 tmp = x; x = y; y = tmp;
4019 *pcomparison = GE;
4020 libfunc = getf2_libfunc;
4021 }
4022 break;
4023
4024 case UNORDERED:
4025 libfunc = unordtf2_libfunc;
4026 break;
4027
4028 default:
4029 break;
4030 }
4031 else
4032 {
4033 enum machine_mode wider_mode;
4034
4035 for (wider_mode = GET_MODE_WIDER_MODE (mode); wider_mode != VOIDmode;
4036 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
4037 {
4038 if ((cmp_optab->handlers[(int) wider_mode].insn_code
4039 != CODE_FOR_nothing)
4040 || (cmp_optab->handlers[(int) wider_mode].libfunc != 0))
4041 {
4042 x = protect_from_queue (x, 0);
4043 y = protect_from_queue (y, 0);
4044 *px = convert_to_mode (wider_mode, x, 0);
4045 *py = convert_to_mode (wider_mode, y, 0);
4046 prepare_float_lib_cmp (px, py, pcomparison, pmode, punsignedp);
4047 return;
4048 }
4049 }
4050 abort ();
4051 }
4052
4053 if (libfunc == 0)
4054 abort ();
4055
4056 result = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST_MAKE_BLOCK,
4057 word_mode, 2, x, mode, y, mode);
4058 *px = result;
4059 *py = const0_rtx;
4060 *pmode = word_mode;
4061 if (comparison == UNORDERED)
4062 *pcomparison = NE;
4063 #ifdef FLOAT_LIB_COMPARE_RETURNS_BOOL
4064 else if (FLOAT_LIB_COMPARE_RETURNS_BOOL (mode, comparison))
4065 *pcomparison = NE;
4066 #endif
4067 *punsignedp = 0;
4068 }
4069 \f
4070 /* Generate code to indirectly jump to a location given in the rtx LOC. */
4071
4072 void
4073 emit_indirect_jump (loc)
4074 rtx loc;
4075 {
4076 if (! ((*insn_data[(int) CODE_FOR_indirect_jump].operand[0].predicate)
4077 (loc, Pmode)))
4078 loc = copy_to_mode_reg (Pmode, loc);
4079
4080 emit_jump_insn (gen_indirect_jump (loc));
4081 emit_barrier ();
4082 }
4083 \f
4084 #ifdef HAVE_conditional_move
4085
4086 /* Emit a conditional move instruction if the machine supports one for that
4087 condition and machine mode.
4088
4089 OP0 and OP1 are the operands that should be compared using CODE. CMODE is
4090 the mode to use should they be constants. If it is VOIDmode, they cannot
4091 both be constants.
4092
4093 OP2 should be stored in TARGET if the comparison is true, otherwise OP3
4094 should be stored there. MODE is the mode to use should they be constants.
4095 If it is VOIDmode, they cannot both be constants.
4096
4097 The result is either TARGET (perhaps modified) or NULL_RTX if the operation
4098 is not supported. */
4099
4100 rtx
4101 emit_conditional_move (target, code, op0, op1, cmode, op2, op3, mode,
4102 unsignedp)
4103 rtx target;
4104 enum rtx_code code;
4105 rtx op0, op1;
4106 enum machine_mode cmode;
4107 rtx op2, op3;
4108 enum machine_mode mode;
4109 int unsignedp;
4110 {
4111 rtx tem, subtarget, comparison, insn;
4112 enum insn_code icode;
4113 enum rtx_code reversed;
4114
4115 /* If one operand is constant, make it the second one. Only do this
4116 if the other operand is not constant as well. */
4117
4118 if (swap_commutative_operands_p (op0, op1))
4119 {
4120 tem = op0;
4121 op0 = op1;
4122 op1 = tem;
4123 code = swap_condition (code);
4124 }
4125
4126 /* get_condition will prefer to generate LT and GT even if the old
4127 comparison was against zero, so undo that canonicalization here since
4128 comparisons against zero are cheaper. */
4129 if (code == LT && GET_CODE (op1) == CONST_INT && INTVAL (op1) == 1)
4130 code = LE, op1 = const0_rtx;
4131 else if (code == GT && GET_CODE (op1) == CONST_INT && INTVAL (op1) == -1)
4132 code = GE, op1 = const0_rtx;
4133
4134 if (cmode == VOIDmode)
4135 cmode = GET_MODE (op0);
4136
4137 if (swap_commutative_operands_p (op2, op3)
4138 && ((reversed = reversed_comparison_code_parts (code, op0, op1, NULL))
4139 != UNKNOWN))
4140 {
4141 tem = op2;
4142 op2 = op3;
4143 op3 = tem;
4144 code = reversed;
4145 }
4146
4147 if (mode == VOIDmode)
4148 mode = GET_MODE (op2);
4149
4150 icode = movcc_gen_code[mode];
4151
4152 if (icode == CODE_FOR_nothing)
4153 return 0;
4154
4155 if (flag_force_mem)
4156 {
4157 op2 = force_not_mem (op2);
4158 op3 = force_not_mem (op3);
4159 }
4160
4161 if (target)
4162 target = protect_from_queue (target, 1);
4163 else
4164 target = gen_reg_rtx (mode);
4165
4166 subtarget = target;
4167
4168 emit_queue ();
4169
4170 op2 = protect_from_queue (op2, 0);
4171 op3 = protect_from_queue (op3, 0);
4172
4173 /* If the insn doesn't accept these operands, put them in pseudos. */
4174
4175 if (! (*insn_data[icode].operand[0].predicate)
4176 (subtarget, insn_data[icode].operand[0].mode))
4177 subtarget = gen_reg_rtx (insn_data[icode].operand[0].mode);
4178
4179 if (! (*insn_data[icode].operand[2].predicate)
4180 (op2, insn_data[icode].operand[2].mode))
4181 op2 = copy_to_mode_reg (insn_data[icode].operand[2].mode, op2);
4182
4183 if (! (*insn_data[icode].operand[3].predicate)
4184 (op3, insn_data[icode].operand[3].mode))
4185 op3 = copy_to_mode_reg (insn_data[icode].operand[3].mode, op3);
4186
4187 /* Everything should now be in the suitable form, so emit the compare insn
4188 and then the conditional move. */
4189
4190 comparison
4191 = compare_from_rtx (op0, op1, code, unsignedp, cmode, NULL_RTX);
4192
4193 /* ??? Watch for const0_rtx (nop) and const_true_rtx (unconditional)? */
4194 /* We can get const0_rtx or const_true_rtx in some circumstances. Just
4195 return NULL and let the caller figure out how best to deal with this
4196 situation. */
4197 if (GET_CODE (comparison) != code)
4198 return NULL_RTX;
4199
4200 insn = GEN_FCN (icode) (subtarget, comparison, op2, op3);
4201
4202 /* If that failed, then give up. */
4203 if (insn == 0)
4204 return 0;
4205
4206 emit_insn (insn);
4207
4208 if (subtarget != target)
4209 convert_move (target, subtarget, 0);
4210
4211 return target;
4212 }
4213
4214 /* Return nonzero if a conditional move of mode MODE is supported.
4215
4216 This function is for combine so it can tell whether an insn that looks
4217 like a conditional move is actually supported by the hardware. If we
4218 guess wrong we lose a bit on optimization, but that's it. */
4219 /* ??? sparc64 supports conditionally moving integers values based on fp
4220 comparisons, and vice versa. How do we handle them? */
4221
4222 int
4223 can_conditionally_move_p (mode)
4224 enum machine_mode mode;
4225 {
4226 if (movcc_gen_code[mode] != CODE_FOR_nothing)
4227 return 1;
4228
4229 return 0;
4230 }
4231
4232 #endif /* HAVE_conditional_move */
4233 \f
4234 /* These functions generate an insn body and return it
4235 rather than emitting the insn.
4236
4237 They do not protect from queued increments,
4238 because they may be used 1) in protect_from_queue itself
4239 and 2) in other passes where there is no queue. */
4240
4241 /* Generate and return an insn body to add Y to X. */
4242
4243 rtx
4244 gen_add2_insn (x, y)
4245 rtx x, y;
4246 {
4247 int icode = (int) add_optab->handlers[(int) GET_MODE (x)].insn_code;
4248
4249 if (! ((*insn_data[icode].operand[0].predicate)
4250 (x, insn_data[icode].operand[0].mode))
4251 || ! ((*insn_data[icode].operand[1].predicate)
4252 (x, insn_data[icode].operand[1].mode))
4253 || ! ((*insn_data[icode].operand[2].predicate)
4254 (y, insn_data[icode].operand[2].mode)))
4255 abort ();
4256
4257 return (GEN_FCN (icode) (x, x, y));
4258 }
4259
4260 /* Generate and return an insn body to add r1 and c,
4261 storing the result in r0. */
4262 rtx
4263 gen_add3_insn (r0, r1, c)
4264 rtx r0, r1, c;
4265 {
4266 int icode = (int) add_optab->handlers[(int) GET_MODE (r0)].insn_code;
4267
4268 if (icode == CODE_FOR_nothing
4269 || ! ((*insn_data[icode].operand[0].predicate)
4270 (r0, insn_data[icode].operand[0].mode))
4271 || ! ((*insn_data[icode].operand[1].predicate)
4272 (r1, insn_data[icode].operand[1].mode))
4273 || ! ((*insn_data[icode].operand[2].predicate)
4274 (c, insn_data[icode].operand[2].mode)))
4275 return NULL_RTX;
4276
4277 return (GEN_FCN (icode) (r0, r1, c));
4278 }
4279
4280 int
4281 have_add2_insn (x, y)
4282 rtx x, y;
4283 {
4284 int icode;
4285
4286 if (GET_MODE (x) == VOIDmode)
4287 abort ();
4288
4289 icode = (int) add_optab->handlers[(int) GET_MODE (x)].insn_code;
4290
4291 if (icode == CODE_FOR_nothing)
4292 return 0;
4293
4294 if (! ((*insn_data[icode].operand[0].predicate)
4295 (x, insn_data[icode].operand[0].mode))
4296 || ! ((*insn_data[icode].operand[1].predicate)
4297 (x, insn_data[icode].operand[1].mode))
4298 || ! ((*insn_data[icode].operand[2].predicate)
4299 (y, insn_data[icode].operand[2].mode)))
4300 return 0;
4301
4302 return 1;
4303 }
4304
4305 /* Generate and return an insn body to subtract Y from X. */
4306
4307 rtx
4308 gen_sub2_insn (x, y)
4309 rtx x, y;
4310 {
4311 int icode = (int) sub_optab->handlers[(int) GET_MODE (x)].insn_code;
4312
4313 if (! ((*insn_data[icode].operand[0].predicate)
4314 (x, insn_data[icode].operand[0].mode))
4315 || ! ((*insn_data[icode].operand[1].predicate)
4316 (x, insn_data[icode].operand[1].mode))
4317 || ! ((*insn_data[icode].operand[2].predicate)
4318 (y, insn_data[icode].operand[2].mode)))
4319 abort ();
4320
4321 return (GEN_FCN (icode) (x, x, y));
4322 }
4323
4324 /* Generate and return an insn body to subtract r1 and c,
4325 storing the result in r0. */
4326 rtx
4327 gen_sub3_insn (r0, r1, c)
4328 rtx r0, r1, c;
4329 {
4330 int icode = (int) sub_optab->handlers[(int) GET_MODE (r0)].insn_code;
4331
4332 if (icode == CODE_FOR_nothing
4333 || ! ((*insn_data[icode].operand[0].predicate)
4334 (r0, insn_data[icode].operand[0].mode))
4335 || ! ((*insn_data[icode].operand[1].predicate)
4336 (r1, insn_data[icode].operand[1].mode))
4337 || ! ((*insn_data[icode].operand[2].predicate)
4338 (c, insn_data[icode].operand[2].mode)))
4339 return NULL_RTX;
4340
4341 return (GEN_FCN (icode) (r0, r1, c));
4342 }
4343
4344 int
4345 have_sub2_insn (x, y)
4346 rtx x, y;
4347 {
4348 int icode;
4349
4350 if (GET_MODE (x) == VOIDmode)
4351 abort ();
4352
4353 icode = (int) sub_optab->handlers[(int) GET_MODE (x)].insn_code;
4354
4355 if (icode == CODE_FOR_nothing)
4356 return 0;
4357
4358 if (! ((*insn_data[icode].operand[0].predicate)
4359 (x, insn_data[icode].operand[0].mode))
4360 || ! ((*insn_data[icode].operand[1].predicate)
4361 (x, insn_data[icode].operand[1].mode))
4362 || ! ((*insn_data[icode].operand[2].predicate)
4363 (y, insn_data[icode].operand[2].mode)))
4364 return 0;
4365
4366 return 1;
4367 }
4368
4369 /* Generate the body of an instruction to copy Y into X.
4370 It may be a list of insns, if one insn isn't enough. */
4371
4372 rtx
4373 gen_move_insn (x, y)
4374 rtx x, y;
4375 {
4376 enum machine_mode mode = GET_MODE (x);
4377 enum insn_code insn_code;
4378 rtx seq;
4379
4380 if (mode == VOIDmode)
4381 mode = GET_MODE (y);
4382
4383 insn_code = mov_optab->handlers[(int) mode].insn_code;
4384
4385 /* Handle MODE_CC modes: If we don't have a special move insn for this mode,
4386 find a mode to do it in. If we have a movcc, use it. Otherwise,
4387 find the MODE_INT mode of the same width. */
4388
4389 if (GET_MODE_CLASS (mode) == MODE_CC && insn_code == CODE_FOR_nothing)
4390 {
4391 enum machine_mode tmode = VOIDmode;
4392 rtx x1 = x, y1 = y;
4393
4394 if (mode != CCmode
4395 && mov_optab->handlers[(int) CCmode].insn_code != CODE_FOR_nothing)
4396 tmode = CCmode;
4397 else
4398 for (tmode = QImode; tmode != VOIDmode;
4399 tmode = GET_MODE_WIDER_MODE (tmode))
4400 if (GET_MODE_SIZE (tmode) == GET_MODE_SIZE (mode))
4401 break;
4402
4403 if (tmode == VOIDmode)
4404 abort ();
4405
4406 /* Get X and Y in TMODE. We can't use gen_lowpart here because it
4407 may call change_address which is not appropriate if we were
4408 called when a reload was in progress. We don't have to worry
4409 about changing the address since the size in bytes is supposed to
4410 be the same. Copy the MEM to change the mode and move any
4411 substitutions from the old MEM to the new one. */
4412
4413 if (reload_in_progress)
4414 {
4415 x = gen_lowpart_common (tmode, x1);
4416 if (x == 0 && GET_CODE (x1) == MEM)
4417 {
4418 x = adjust_address_nv (x1, tmode, 0);
4419 copy_replacements (x1, x);
4420 }
4421
4422 y = gen_lowpart_common (tmode, y1);
4423 if (y == 0 && GET_CODE (y1) == MEM)
4424 {
4425 y = adjust_address_nv (y1, tmode, 0);
4426 copy_replacements (y1, y);
4427 }
4428 }
4429 else
4430 {
4431 x = gen_lowpart (tmode, x);
4432 y = gen_lowpart (tmode, y);
4433 }
4434
4435 insn_code = mov_optab->handlers[(int) tmode].insn_code;
4436 return (GEN_FCN (insn_code) (x, y));
4437 }
4438
4439 start_sequence ();
4440 emit_move_insn_1 (x, y);
4441 seq = get_insns ();
4442 end_sequence ();
4443 return seq;
4444 }
4445 \f
4446 /* Return the insn code used to extend FROM_MODE to TO_MODE.
4447 UNSIGNEDP specifies zero-extension instead of sign-extension. If
4448 no such operation exists, CODE_FOR_nothing will be returned. */
4449
4450 enum insn_code
4451 can_extend_p (to_mode, from_mode, unsignedp)
4452 enum machine_mode to_mode, from_mode;
4453 int unsignedp;
4454 {
4455 #ifdef HAVE_ptr_extend
4456 if (unsignedp < 0)
4457 return CODE_FOR_ptr_extend;
4458 else
4459 #endif
4460 return extendtab[(int) to_mode][(int) from_mode][unsignedp != 0];
4461 }
4462
4463 /* Generate the body of an insn to extend Y (with mode MFROM)
4464 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
4465
4466 rtx
4467 gen_extend_insn (x, y, mto, mfrom, unsignedp)
4468 rtx x, y;
4469 enum machine_mode mto, mfrom;
4470 int unsignedp;
4471 {
4472 return (GEN_FCN (extendtab[(int) mto][(int) mfrom][unsignedp != 0]) (x, y));
4473 }
4474 \f
4475 /* can_fix_p and can_float_p say whether the target machine
4476 can directly convert a given fixed point type to
4477 a given floating point type, or vice versa.
4478 The returned value is the CODE_FOR_... value to use,
4479 or CODE_FOR_nothing if these modes cannot be directly converted.
4480
4481 *TRUNCP_PTR is set to 1 if it is necessary to output
4482 an explicit FTRUNC insn before the fix insn; otherwise 0. */
4483
4484 static enum insn_code
4485 can_fix_p (fixmode, fltmode, unsignedp, truncp_ptr)
4486 enum machine_mode fltmode, fixmode;
4487 int unsignedp;
4488 int *truncp_ptr;
4489 {
4490 *truncp_ptr = 0;
4491 if (fixtrunctab[(int) fltmode][(int) fixmode][unsignedp != 0]
4492 != CODE_FOR_nothing)
4493 return fixtrunctab[(int) fltmode][(int) fixmode][unsignedp != 0];
4494
4495 if (ftrunc_optab->handlers[(int) fltmode].insn_code != CODE_FOR_nothing)
4496 {
4497 *truncp_ptr = 1;
4498 return fixtab[(int) fltmode][(int) fixmode][unsignedp != 0];
4499 }
4500 return CODE_FOR_nothing;
4501 }
4502
4503 static enum insn_code
4504 can_float_p (fltmode, fixmode, unsignedp)
4505 enum machine_mode fixmode, fltmode;
4506 int unsignedp;
4507 {
4508 return floattab[(int) fltmode][(int) fixmode][unsignedp != 0];
4509 }
4510 \f
4511 /* Generate code to convert FROM to floating point
4512 and store in TO. FROM must be fixed point and not VOIDmode.
4513 UNSIGNEDP nonzero means regard FROM as unsigned.
4514 Normally this is done by correcting the final value
4515 if it is negative. */
4516
4517 void
4518 expand_float (to, from, unsignedp)
4519 rtx to, from;
4520 int unsignedp;
4521 {
4522 enum insn_code icode;
4523 rtx target = to;
4524 enum machine_mode fmode, imode;
4525
4526 /* Crash now, because we won't be able to decide which mode to use. */
4527 if (GET_MODE (from) == VOIDmode)
4528 abort ();
4529
4530 /* Look for an insn to do the conversion. Do it in the specified
4531 modes if possible; otherwise convert either input, output or both to
4532 wider mode. If the integer mode is wider than the mode of FROM,
4533 we can do the conversion signed even if the input is unsigned. */
4534
4535 for (imode = GET_MODE (from); imode != VOIDmode;
4536 imode = GET_MODE_WIDER_MODE (imode))
4537 for (fmode = GET_MODE (to); fmode != VOIDmode;
4538 fmode = GET_MODE_WIDER_MODE (fmode))
4539 {
4540 int doing_unsigned = unsignedp;
4541
4542 if (fmode != GET_MODE (to)
4543 && significand_size (fmode) < GET_MODE_BITSIZE (GET_MODE (from)))
4544 continue;
4545
4546 icode = can_float_p (fmode, imode, unsignedp);
4547 if (icode == CODE_FOR_nothing && imode != GET_MODE (from) && unsignedp)
4548 icode = can_float_p (fmode, imode, 0), doing_unsigned = 0;
4549
4550 if (icode != CODE_FOR_nothing)
4551 {
4552 to = protect_from_queue (to, 1);
4553 from = protect_from_queue (from, 0);
4554
4555 if (imode != GET_MODE (from))
4556 from = convert_to_mode (imode, from, unsignedp);
4557
4558 if (fmode != GET_MODE (to))
4559 target = gen_reg_rtx (fmode);
4560
4561 emit_unop_insn (icode, target, from,
4562 doing_unsigned ? UNSIGNED_FLOAT : FLOAT);
4563
4564 if (target != to)
4565 convert_move (to, target, 0);
4566 return;
4567 }
4568 }
4569
4570 /* Unsigned integer, and no way to convert directly.
4571 Convert as signed, then conditionally adjust the result. */
4572 if (unsignedp)
4573 {
4574 rtx label = gen_label_rtx ();
4575 rtx temp;
4576 REAL_VALUE_TYPE offset;
4577
4578 emit_queue ();
4579
4580 to = protect_from_queue (to, 1);
4581 from = protect_from_queue (from, 0);
4582
4583 if (flag_force_mem)
4584 from = force_not_mem (from);
4585
4586 /* Look for a usable floating mode FMODE wider than the source and at
4587 least as wide as the target. Using FMODE will avoid rounding woes
4588 with unsigned values greater than the signed maximum value. */
4589
4590 for (fmode = GET_MODE (to); fmode != VOIDmode;
4591 fmode = GET_MODE_WIDER_MODE (fmode))
4592 if (GET_MODE_BITSIZE (GET_MODE (from)) < GET_MODE_BITSIZE (fmode)
4593 && can_float_p (fmode, GET_MODE (from), 0) != CODE_FOR_nothing)
4594 break;
4595
4596 if (fmode == VOIDmode)
4597 {
4598 /* There is no such mode. Pretend the target is wide enough. */
4599 fmode = GET_MODE (to);
4600
4601 /* Avoid double-rounding when TO is narrower than FROM. */
4602 if ((significand_size (fmode) + 1)
4603 < GET_MODE_BITSIZE (GET_MODE (from)))
4604 {
4605 rtx temp1;
4606 rtx neglabel = gen_label_rtx ();
4607
4608 /* Don't use TARGET if it isn't a register, is a hard register,
4609 or is the wrong mode. */
4610 if (GET_CODE (target) != REG
4611 || REGNO (target) < FIRST_PSEUDO_REGISTER
4612 || GET_MODE (target) != fmode)
4613 target = gen_reg_rtx (fmode);
4614
4615 imode = GET_MODE (from);
4616 do_pending_stack_adjust ();
4617
4618 /* Test whether the sign bit is set. */
4619 emit_cmp_and_jump_insns (from, const0_rtx, LT, NULL_RTX, imode,
4620 0, neglabel);
4621
4622 /* The sign bit is not set. Convert as signed. */
4623 expand_float (target, from, 0);
4624 emit_jump_insn (gen_jump (label));
4625 emit_barrier ();
4626
4627 /* The sign bit is set.
4628 Convert to a usable (positive signed) value by shifting right
4629 one bit, while remembering if a nonzero bit was shifted
4630 out; i.e., compute (from & 1) | (from >> 1). */
4631
4632 emit_label (neglabel);
4633 temp = expand_binop (imode, and_optab, from, const1_rtx,
4634 NULL_RTX, 1, OPTAB_LIB_WIDEN);
4635 temp1 = expand_shift (RSHIFT_EXPR, imode, from, integer_one_node,
4636 NULL_RTX, 1);
4637 temp = expand_binop (imode, ior_optab, temp, temp1, temp, 1,
4638 OPTAB_LIB_WIDEN);
4639 expand_float (target, temp, 0);
4640
4641 /* Multiply by 2 to undo the shift above. */
4642 temp = expand_binop (fmode, add_optab, target, target,
4643 target, 0, OPTAB_LIB_WIDEN);
4644 if (temp != target)
4645 emit_move_insn (target, temp);
4646
4647 do_pending_stack_adjust ();
4648 emit_label (label);
4649 goto done;
4650 }
4651 }
4652
4653 /* If we are about to do some arithmetic to correct for an
4654 unsigned operand, do it in a pseudo-register. */
4655
4656 if (GET_MODE (to) != fmode
4657 || GET_CODE (to) != REG || REGNO (to) < FIRST_PSEUDO_REGISTER)
4658 target = gen_reg_rtx (fmode);
4659
4660 /* Convert as signed integer to floating. */
4661 expand_float (target, from, 0);
4662
4663 /* If FROM is negative (and therefore TO is negative),
4664 correct its value by 2**bitwidth. */
4665
4666 do_pending_stack_adjust ();
4667 emit_cmp_and_jump_insns (from, const0_rtx, GE, NULL_RTX, GET_MODE (from),
4668 0, label);
4669
4670
4671 real_2expN (&offset, GET_MODE_BITSIZE (GET_MODE (from)));
4672 temp = expand_binop (fmode, add_optab, target,
4673 CONST_DOUBLE_FROM_REAL_VALUE (offset, fmode),
4674 target, 0, OPTAB_LIB_WIDEN);
4675 if (temp != target)
4676 emit_move_insn (target, temp);
4677
4678 do_pending_stack_adjust ();
4679 emit_label (label);
4680 goto done;
4681 }
4682
4683 /* No hardware instruction available; call a library routine to convert from
4684 SImode, DImode, or TImode into SFmode, DFmode, XFmode, or TFmode. */
4685 {
4686 rtx libfcn;
4687 rtx insns;
4688 rtx value;
4689
4690 to = protect_from_queue (to, 1);
4691 from = protect_from_queue (from, 0);
4692
4693 if (GET_MODE_SIZE (GET_MODE (from)) < GET_MODE_SIZE (SImode))
4694 from = convert_to_mode (SImode, from, unsignedp);
4695
4696 if (flag_force_mem)
4697 from = force_not_mem (from);
4698
4699 if (GET_MODE (to) == SFmode)
4700 {
4701 if (GET_MODE (from) == SImode)
4702 libfcn = floatsisf_libfunc;
4703 else if (GET_MODE (from) == DImode)
4704 libfcn = floatdisf_libfunc;
4705 else if (GET_MODE (from) == TImode)
4706 libfcn = floattisf_libfunc;
4707 else
4708 abort ();
4709 }
4710 else if (GET_MODE (to) == DFmode)
4711 {
4712 if (GET_MODE (from) == SImode)
4713 libfcn = floatsidf_libfunc;
4714 else if (GET_MODE (from) == DImode)
4715 libfcn = floatdidf_libfunc;
4716 else if (GET_MODE (from) == TImode)
4717 libfcn = floattidf_libfunc;
4718 else
4719 abort ();
4720 }
4721 else if (GET_MODE (to) == XFmode)
4722 {
4723 if (GET_MODE (from) == SImode)
4724 libfcn = floatsixf_libfunc;
4725 else if (GET_MODE (from) == DImode)
4726 libfcn = floatdixf_libfunc;
4727 else if (GET_MODE (from) == TImode)
4728 libfcn = floattixf_libfunc;
4729 else
4730 abort ();
4731 }
4732 else if (GET_MODE (to) == TFmode)
4733 {
4734 if (GET_MODE (from) == SImode)
4735 libfcn = floatsitf_libfunc;
4736 else if (GET_MODE (from) == DImode)
4737 libfcn = floatditf_libfunc;
4738 else if (GET_MODE (from) == TImode)
4739 libfcn = floattitf_libfunc;
4740 else
4741 abort ();
4742 }
4743 else
4744 abort ();
4745
4746 start_sequence ();
4747
4748 value = emit_library_call_value (libfcn, NULL_RTX, LCT_CONST,
4749 GET_MODE (to), 1, from,
4750 GET_MODE (from));
4751 insns = get_insns ();
4752 end_sequence ();
4753
4754 emit_libcall_block (insns, target, value,
4755 gen_rtx_FLOAT (GET_MODE (to), from));
4756 }
4757
4758 done:
4759
4760 /* Copy result to requested destination
4761 if we have been computing in a temp location. */
4762
4763 if (target != to)
4764 {
4765 if (GET_MODE (target) == GET_MODE (to))
4766 emit_move_insn (to, target);
4767 else
4768 convert_move (to, target, 0);
4769 }
4770 }
4771 \f
4772 /* expand_fix: generate code to convert FROM to fixed point
4773 and store in TO. FROM must be floating point. */
4774
4775 static rtx
4776 ftruncify (x)
4777 rtx x;
4778 {
4779 rtx temp = gen_reg_rtx (GET_MODE (x));
4780 return expand_unop (GET_MODE (x), ftrunc_optab, x, temp, 0);
4781 }
4782
4783 void
4784 expand_fix (to, from, unsignedp)
4785 rtx to, from;
4786 int unsignedp;
4787 {
4788 enum insn_code icode;
4789 rtx target = to;
4790 enum machine_mode fmode, imode;
4791 int must_trunc = 0;
4792 rtx libfcn = 0;
4793
4794 /* We first try to find a pair of modes, one real and one integer, at
4795 least as wide as FROM and TO, respectively, in which we can open-code
4796 this conversion. If the integer mode is wider than the mode of TO,
4797 we can do the conversion either signed or unsigned. */
4798
4799 for (fmode = GET_MODE (from); fmode != VOIDmode;
4800 fmode = GET_MODE_WIDER_MODE (fmode))
4801 for (imode = GET_MODE (to); imode != VOIDmode;
4802 imode = GET_MODE_WIDER_MODE (imode))
4803 {
4804 int doing_unsigned = unsignedp;
4805
4806 icode = can_fix_p (imode, fmode, unsignedp, &must_trunc);
4807 if (icode == CODE_FOR_nothing && imode != GET_MODE (to) && unsignedp)
4808 icode = can_fix_p (imode, fmode, 0, &must_trunc), doing_unsigned = 0;
4809
4810 if (icode != CODE_FOR_nothing)
4811 {
4812 to = protect_from_queue (to, 1);
4813 from = protect_from_queue (from, 0);
4814
4815 if (fmode != GET_MODE (from))
4816 from = convert_to_mode (fmode, from, 0);
4817
4818 if (must_trunc)
4819 from = ftruncify (from);
4820
4821 if (imode != GET_MODE (to))
4822 target = gen_reg_rtx (imode);
4823
4824 emit_unop_insn (icode, target, from,
4825 doing_unsigned ? UNSIGNED_FIX : FIX);
4826 if (target != to)
4827 convert_move (to, target, unsignedp);
4828 return;
4829 }
4830 }
4831
4832 /* For an unsigned conversion, there is one more way to do it.
4833 If we have a signed conversion, we generate code that compares
4834 the real value to the largest representable positive number. If if
4835 is smaller, the conversion is done normally. Otherwise, subtract
4836 one plus the highest signed number, convert, and add it back.
4837
4838 We only need to check all real modes, since we know we didn't find
4839 anything with a wider integer mode. */
4840
4841 if (unsignedp && GET_MODE_BITSIZE (GET_MODE (to)) <= HOST_BITS_PER_WIDE_INT)
4842 for (fmode = GET_MODE (from); fmode != VOIDmode;
4843 fmode = GET_MODE_WIDER_MODE (fmode))
4844 /* Make sure we won't lose significant bits doing this. */
4845 if (GET_MODE_BITSIZE (fmode) > GET_MODE_BITSIZE (GET_MODE (to))
4846 && CODE_FOR_nothing != can_fix_p (GET_MODE (to), fmode, 0,
4847 &must_trunc))
4848 {
4849 int bitsize;
4850 REAL_VALUE_TYPE offset;
4851 rtx limit, lab1, lab2, insn;
4852
4853 bitsize = GET_MODE_BITSIZE (GET_MODE (to));
4854 real_2expN (&offset, bitsize - 1);
4855 limit = CONST_DOUBLE_FROM_REAL_VALUE (offset, fmode);
4856 lab1 = gen_label_rtx ();
4857 lab2 = gen_label_rtx ();
4858
4859 emit_queue ();
4860 to = protect_from_queue (to, 1);
4861 from = protect_from_queue (from, 0);
4862
4863 if (flag_force_mem)
4864 from = force_not_mem (from);
4865
4866 if (fmode != GET_MODE (from))
4867 from = convert_to_mode (fmode, from, 0);
4868
4869 /* See if we need to do the subtraction. */
4870 do_pending_stack_adjust ();
4871 emit_cmp_and_jump_insns (from, limit, GE, NULL_RTX, GET_MODE (from),
4872 0, lab1);
4873
4874 /* If not, do the signed "fix" and branch around fixup code. */
4875 expand_fix (to, from, 0);
4876 emit_jump_insn (gen_jump (lab2));
4877 emit_barrier ();
4878
4879 /* Otherwise, subtract 2**(N-1), convert to signed number,
4880 then add 2**(N-1). Do the addition using XOR since this
4881 will often generate better code. */
4882 emit_label (lab1);
4883 target = expand_binop (GET_MODE (from), sub_optab, from, limit,
4884 NULL_RTX, 0, OPTAB_LIB_WIDEN);
4885 expand_fix (to, target, 0);
4886 target = expand_binop (GET_MODE (to), xor_optab, to,
4887 gen_int_mode
4888 ((HOST_WIDE_INT) 1 << (bitsize - 1),
4889 GET_MODE (to)),
4890 to, 1, OPTAB_LIB_WIDEN);
4891
4892 if (target != to)
4893 emit_move_insn (to, target);
4894
4895 emit_label (lab2);
4896
4897 if (mov_optab->handlers[(int) GET_MODE (to)].insn_code
4898 != CODE_FOR_nothing)
4899 {
4900 /* Make a place for a REG_NOTE and add it. */
4901 insn = emit_move_insn (to, to);
4902 set_unique_reg_note (insn,
4903 REG_EQUAL,
4904 gen_rtx_fmt_e (UNSIGNED_FIX,
4905 GET_MODE (to),
4906 copy_rtx (from)));
4907 }
4908
4909 return;
4910 }
4911
4912 /* We can't do it with an insn, so use a library call. But first ensure
4913 that the mode of TO is at least as wide as SImode, since those are the
4914 only library calls we know about. */
4915
4916 if (GET_MODE_SIZE (GET_MODE (to)) < GET_MODE_SIZE (SImode))
4917 {
4918 target = gen_reg_rtx (SImode);
4919
4920 expand_fix (target, from, unsignedp);
4921 }
4922 else if (GET_MODE (from) == SFmode)
4923 {
4924 if (GET_MODE (to) == SImode)
4925 libfcn = unsignedp ? fixunssfsi_libfunc : fixsfsi_libfunc;
4926 else if (GET_MODE (to) == DImode)
4927 libfcn = unsignedp ? fixunssfdi_libfunc : fixsfdi_libfunc;
4928 else if (GET_MODE (to) == TImode)
4929 libfcn = unsignedp ? fixunssfti_libfunc : fixsfti_libfunc;
4930 else
4931 abort ();
4932 }
4933 else if (GET_MODE (from) == DFmode)
4934 {
4935 if (GET_MODE (to) == SImode)
4936 libfcn = unsignedp ? fixunsdfsi_libfunc : fixdfsi_libfunc;
4937 else if (GET_MODE (to) == DImode)
4938 libfcn = unsignedp ? fixunsdfdi_libfunc : fixdfdi_libfunc;
4939 else if (GET_MODE (to) == TImode)
4940 libfcn = unsignedp ? fixunsdfti_libfunc : fixdfti_libfunc;
4941 else
4942 abort ();
4943 }
4944 else if (GET_MODE (from) == XFmode)
4945 {
4946 if (GET_MODE (to) == SImode)
4947 libfcn = unsignedp ? fixunsxfsi_libfunc : fixxfsi_libfunc;
4948 else if (GET_MODE (to) == DImode)
4949 libfcn = unsignedp ? fixunsxfdi_libfunc : fixxfdi_libfunc;
4950 else if (GET_MODE (to) == TImode)
4951 libfcn = unsignedp ? fixunsxfti_libfunc : fixxfti_libfunc;
4952 else
4953 abort ();
4954 }
4955 else if (GET_MODE (from) == TFmode)
4956 {
4957 if (GET_MODE (to) == SImode)
4958 libfcn = unsignedp ? fixunstfsi_libfunc : fixtfsi_libfunc;
4959 else if (GET_MODE (to) == DImode)
4960 libfcn = unsignedp ? fixunstfdi_libfunc : fixtfdi_libfunc;
4961 else if (GET_MODE (to) == TImode)
4962 libfcn = unsignedp ? fixunstfti_libfunc : fixtfti_libfunc;
4963 else
4964 abort ();
4965 }
4966 else
4967 abort ();
4968
4969 if (libfcn)
4970 {
4971 rtx insns;
4972 rtx value;
4973
4974 to = protect_from_queue (to, 1);
4975 from = protect_from_queue (from, 0);
4976
4977 if (flag_force_mem)
4978 from = force_not_mem (from);
4979
4980 start_sequence ();
4981
4982 value = emit_library_call_value (libfcn, NULL_RTX, LCT_CONST,
4983 GET_MODE (to), 1, from,
4984 GET_MODE (from));
4985 insns = get_insns ();
4986 end_sequence ();
4987
4988 emit_libcall_block (insns, target, value,
4989 gen_rtx_fmt_e (unsignedp ? UNSIGNED_FIX : FIX,
4990 GET_MODE (to), from));
4991 }
4992
4993 if (target != to)
4994 {
4995 if (GET_MODE (to) == GET_MODE (target))
4996 emit_move_insn (to, target);
4997 else
4998 convert_move (to, target, 0);
4999 }
5000 }
5001 \f
5002 /* Report whether we have an instruction to perform the operation
5003 specified by CODE on operands of mode MODE. */
5004 int
5005 have_insn_for (code, mode)
5006 enum rtx_code code;
5007 enum machine_mode mode;
5008 {
5009 return (code_to_optab[(int) code] != 0
5010 && (code_to_optab[(int) code]->handlers[(int) mode].insn_code
5011 != CODE_FOR_nothing));
5012 }
5013
5014 /* Create a blank optab. */
5015 static optab
5016 new_optab ()
5017 {
5018 int i;
5019 optab op = (optab) ggc_alloc (sizeof (struct optab));
5020 for (i = 0; i < NUM_MACHINE_MODES; i++)
5021 {
5022 op->handlers[i].insn_code = CODE_FOR_nothing;
5023 op->handlers[i].libfunc = 0;
5024 }
5025
5026 return op;
5027 }
5028
5029 /* Same, but fill in its code as CODE, and write it into the
5030 code_to_optab table. */
5031 static inline optab
5032 init_optab (code)
5033 enum rtx_code code;
5034 {
5035 optab op = new_optab ();
5036 op->code = code;
5037 code_to_optab[(int) code] = op;
5038 return op;
5039 }
5040
5041 /* Same, but fill in its code as CODE, and do _not_ write it into
5042 the code_to_optab table. */
5043 static inline optab
5044 init_optabv (code)
5045 enum rtx_code code;
5046 {
5047 optab op = new_optab ();
5048 op->code = code;
5049 return op;
5050 }
5051
5052 /* Initialize the libfunc fields of an entire group of entries in some
5053 optab. Each entry is set equal to a string consisting of a leading
5054 pair of underscores followed by a generic operation name followed by
5055 a mode name (downshifted to lower case) followed by a single character
5056 representing the number of operands for the given operation (which is
5057 usually one of the characters '2', '3', or '4').
5058
5059 OPTABLE is the table in which libfunc fields are to be initialized.
5060 FIRST_MODE is the first machine mode index in the given optab to
5061 initialize.
5062 LAST_MODE is the last machine mode index in the given optab to
5063 initialize.
5064 OPNAME is the generic (string) name of the operation.
5065 SUFFIX is the character which specifies the number of operands for
5066 the given generic operation.
5067 */
5068
5069 static void
5070 init_libfuncs (optable, first_mode, last_mode, opname, suffix)
5071 optab optable;
5072 int first_mode;
5073 int last_mode;
5074 const char *opname;
5075 int suffix;
5076 {
5077 int mode;
5078 unsigned opname_len = strlen (opname);
5079
5080 for (mode = first_mode; (int) mode <= (int) last_mode;
5081 mode = (enum machine_mode) ((int) mode + 1))
5082 {
5083 const char *mname = GET_MODE_NAME (mode);
5084 unsigned mname_len = strlen (mname);
5085 char *libfunc_name = alloca (2 + opname_len + mname_len + 1 + 1);
5086 char *p;
5087 const char *q;
5088
5089 p = libfunc_name;
5090 *p++ = '_';
5091 *p++ = '_';
5092 for (q = opname; *q; )
5093 *p++ = *q++;
5094 for (q = mname; *q; q++)
5095 *p++ = TOLOWER (*q);
5096 *p++ = suffix;
5097 *p = '\0';
5098
5099 optable->handlers[(int) mode].libfunc
5100 = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (libfunc_name,
5101 p - libfunc_name));
5102 }
5103 }
5104
5105 /* Initialize the libfunc fields of an entire group of entries in some
5106 optab which correspond to all integer mode operations. The parameters
5107 have the same meaning as similarly named ones for the `init_libfuncs'
5108 routine. (See above). */
5109
5110 static void
5111 init_integral_libfuncs (optable, opname, suffix)
5112 optab optable;
5113 const char *opname;
5114 int suffix;
5115 {
5116 init_libfuncs (optable, SImode, TImode, opname, suffix);
5117 }
5118
5119 /* Initialize the libfunc fields of an entire group of entries in some
5120 optab which correspond to all real mode operations. The parameters
5121 have the same meaning as similarly named ones for the `init_libfuncs'
5122 routine. (See above). */
5123
5124 static void
5125 init_floating_libfuncs (optable, opname, suffix)
5126 optab optable;
5127 const char *opname;
5128 int suffix;
5129 {
5130 init_libfuncs (optable, SFmode, TFmode, opname, suffix);
5131 }
5132
5133 rtx
5134 init_one_libfunc (name)
5135 const char *name;
5136 {
5137 /* Create a FUNCTION_DECL that can be passed to
5138 targetm.encode_section_info. */
5139 /* ??? We don't have any type information except for this is
5140 a function. Pretend this is "int foo()". */
5141 tree decl = build_decl (FUNCTION_DECL, get_identifier (name),
5142 build_function_type (integer_type_node, NULL_TREE));
5143 DECL_ARTIFICIAL (decl) = 1;
5144 DECL_EXTERNAL (decl) = 1;
5145 TREE_PUBLIC (decl) = 1;
5146
5147 /* Return the symbol_ref from the mem rtx. */
5148 return XEXP (DECL_RTL (decl), 0);
5149 }
5150
5151 /* Call this once to initialize the contents of the optabs
5152 appropriately for the current target machine. */
5153
5154 void
5155 init_optabs ()
5156 {
5157 unsigned int i, j, k;
5158
5159 /* Start by initializing all tables to contain CODE_FOR_nothing. */
5160
5161 for (i = 0; i < ARRAY_SIZE (fixtab); i++)
5162 for (j = 0; j < ARRAY_SIZE (fixtab[0]); j++)
5163 for (k = 0; k < ARRAY_SIZE (fixtab[0][0]); k++)
5164 fixtab[i][j][k] = CODE_FOR_nothing;
5165
5166 for (i = 0; i < ARRAY_SIZE (fixtrunctab); i++)
5167 for (j = 0; j < ARRAY_SIZE (fixtrunctab[0]); j++)
5168 for (k = 0; k < ARRAY_SIZE (fixtrunctab[0][0]); k++)
5169 fixtrunctab[i][j][k] = CODE_FOR_nothing;
5170
5171 for (i = 0; i < ARRAY_SIZE (floattab); i++)
5172 for (j = 0; j < ARRAY_SIZE (floattab[0]); j++)
5173 for (k = 0; k < ARRAY_SIZE (floattab[0][0]); k++)
5174 floattab[i][j][k] = CODE_FOR_nothing;
5175
5176 for (i = 0; i < ARRAY_SIZE (extendtab); i++)
5177 for (j = 0; j < ARRAY_SIZE (extendtab[0]); j++)
5178 for (k = 0; k < ARRAY_SIZE (extendtab[0][0]); k++)
5179 extendtab[i][j][k] = CODE_FOR_nothing;
5180
5181 for (i = 0; i < NUM_RTX_CODE; i++)
5182 setcc_gen_code[i] = CODE_FOR_nothing;
5183
5184 #ifdef HAVE_conditional_move
5185 for (i = 0; i < NUM_MACHINE_MODES; i++)
5186 movcc_gen_code[i] = CODE_FOR_nothing;
5187 #endif
5188
5189 add_optab = init_optab (PLUS);
5190 addv_optab = init_optabv (PLUS);
5191 sub_optab = init_optab (MINUS);
5192 subv_optab = init_optabv (MINUS);
5193 smul_optab = init_optab (MULT);
5194 smulv_optab = init_optabv (MULT);
5195 smul_highpart_optab = init_optab (UNKNOWN);
5196 umul_highpart_optab = init_optab (UNKNOWN);
5197 smul_widen_optab = init_optab (UNKNOWN);
5198 umul_widen_optab = init_optab (UNKNOWN);
5199 sdiv_optab = init_optab (DIV);
5200 sdivv_optab = init_optabv (DIV);
5201 sdivmod_optab = init_optab (UNKNOWN);
5202 udiv_optab = init_optab (UDIV);
5203 udivmod_optab = init_optab (UNKNOWN);
5204 smod_optab = init_optab (MOD);
5205 umod_optab = init_optab (UMOD);
5206 ftrunc_optab = init_optab (UNKNOWN);
5207 and_optab = init_optab (AND);
5208 ior_optab = init_optab (IOR);
5209 xor_optab = init_optab (XOR);
5210 ashl_optab = init_optab (ASHIFT);
5211 ashr_optab = init_optab (ASHIFTRT);
5212 lshr_optab = init_optab (LSHIFTRT);
5213 rotl_optab = init_optab (ROTATE);
5214 rotr_optab = init_optab (ROTATERT);
5215 smin_optab = init_optab (SMIN);
5216 smax_optab = init_optab (SMAX);
5217 umin_optab = init_optab (UMIN);
5218 umax_optab = init_optab (UMAX);
5219
5220 /* These three have codes assigned exclusively for the sake of
5221 have_insn_for. */
5222 mov_optab = init_optab (SET);
5223 movstrict_optab = init_optab (STRICT_LOW_PART);
5224 cmp_optab = init_optab (COMPARE);
5225
5226 ucmp_optab = init_optab (UNKNOWN);
5227 tst_optab = init_optab (UNKNOWN);
5228 neg_optab = init_optab (NEG);
5229 negv_optab = init_optabv (NEG);
5230 abs_optab = init_optab (ABS);
5231 absv_optab = init_optabv (ABS);
5232 one_cmpl_optab = init_optab (NOT);
5233 ffs_optab = init_optab (FFS);
5234 sqrt_optab = init_optab (SQRT);
5235 floor_optab = init_optab (UNKNOWN);
5236 ceil_optab = init_optab (UNKNOWN);
5237 round_optab = init_optab (UNKNOWN);
5238 trunc_optab = init_optab (UNKNOWN);
5239 nearbyint_optab = init_optab (UNKNOWN);
5240 sin_optab = init_optab (UNKNOWN);
5241 cos_optab = init_optab (UNKNOWN);
5242 exp_optab = init_optab (UNKNOWN);
5243 log_optab = init_optab (UNKNOWN);
5244 strlen_optab = init_optab (UNKNOWN);
5245 cbranch_optab = init_optab (UNKNOWN);
5246 cmov_optab = init_optab (UNKNOWN);
5247 cstore_optab = init_optab (UNKNOWN);
5248 push_optab = init_optab (UNKNOWN);
5249
5250 for (i = 0; i < NUM_MACHINE_MODES; i++)
5251 {
5252 movstr_optab[i] = CODE_FOR_nothing;
5253 clrstr_optab[i] = CODE_FOR_nothing;
5254
5255 #ifdef HAVE_SECONDARY_RELOADS
5256 reload_in_optab[i] = reload_out_optab[i] = CODE_FOR_nothing;
5257 #endif
5258 }
5259
5260 /* Fill in the optabs with the insns we support. */
5261 init_all_optabs ();
5262
5263 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
5264 /* This flag says the same insns that convert to a signed fixnum
5265 also convert validly to an unsigned one. */
5266 for (i = 0; i < NUM_MACHINE_MODES; i++)
5267 for (j = 0; j < NUM_MACHINE_MODES; j++)
5268 fixtrunctab[i][j][1] = fixtrunctab[i][j][0];
5269 #endif
5270
5271 /* Initialize the optabs with the names of the library functions. */
5272 init_integral_libfuncs (add_optab, "add", '3');
5273 init_floating_libfuncs (add_optab, "add", '3');
5274 init_integral_libfuncs (addv_optab, "addv", '3');
5275 init_floating_libfuncs (addv_optab, "add", '3');
5276 init_integral_libfuncs (sub_optab, "sub", '3');
5277 init_floating_libfuncs (sub_optab, "sub", '3');
5278 init_integral_libfuncs (subv_optab, "subv", '3');
5279 init_floating_libfuncs (subv_optab, "sub", '3');
5280 init_integral_libfuncs (smul_optab, "mul", '3');
5281 init_floating_libfuncs (smul_optab, "mul", '3');
5282 init_integral_libfuncs (smulv_optab, "mulv", '3');
5283 init_floating_libfuncs (smulv_optab, "mul", '3');
5284 init_integral_libfuncs (sdiv_optab, "div", '3');
5285 init_floating_libfuncs (sdiv_optab, "div", '3');
5286 init_integral_libfuncs (sdivv_optab, "divv", '3');
5287 init_integral_libfuncs (udiv_optab, "udiv", '3');
5288 init_integral_libfuncs (sdivmod_optab, "divmod", '4');
5289 init_integral_libfuncs (udivmod_optab, "udivmod", '4');
5290 init_integral_libfuncs (smod_optab, "mod", '3');
5291 init_integral_libfuncs (umod_optab, "umod", '3');
5292 init_floating_libfuncs (ftrunc_optab, "ftrunc", '2');
5293 init_integral_libfuncs (and_optab, "and", '3');
5294 init_integral_libfuncs (ior_optab, "ior", '3');
5295 init_integral_libfuncs (xor_optab, "xor", '3');
5296 init_integral_libfuncs (ashl_optab, "ashl", '3');
5297 init_integral_libfuncs (ashr_optab, "ashr", '3');
5298 init_integral_libfuncs (lshr_optab, "lshr", '3');
5299 init_integral_libfuncs (smin_optab, "min", '3');
5300 init_floating_libfuncs (smin_optab, "min", '3');
5301 init_integral_libfuncs (smax_optab, "max", '3');
5302 init_floating_libfuncs (smax_optab, "max", '3');
5303 init_integral_libfuncs (umin_optab, "umin", '3');
5304 init_integral_libfuncs (umax_optab, "umax", '3');
5305 init_integral_libfuncs (neg_optab, "neg", '2');
5306 init_floating_libfuncs (neg_optab, "neg", '2');
5307 init_integral_libfuncs (negv_optab, "negv", '2');
5308 init_floating_libfuncs (negv_optab, "neg", '2');
5309 init_integral_libfuncs (one_cmpl_optab, "one_cmpl", '2');
5310 init_integral_libfuncs (ffs_optab, "ffs", '2');
5311
5312 /* Comparison libcalls for integers MUST come in pairs, signed/unsigned. */
5313 init_integral_libfuncs (cmp_optab, "cmp", '2');
5314 init_integral_libfuncs (ucmp_optab, "ucmp", '2');
5315 init_floating_libfuncs (cmp_optab, "cmp", '2');
5316
5317 #ifdef MULSI3_LIBCALL
5318 smul_optab->handlers[(int) SImode].libfunc
5319 = init_one_libfunc (MULSI3_LIBCALL);
5320 #endif
5321 #ifdef MULDI3_LIBCALL
5322 smul_optab->handlers[(int) DImode].libfunc
5323 = init_one_libfunc (MULDI3_LIBCALL);
5324 #endif
5325
5326 #ifdef DIVSI3_LIBCALL
5327 sdiv_optab->handlers[(int) SImode].libfunc
5328 = init_one_libfunc (DIVSI3_LIBCALL);
5329 #endif
5330 #ifdef DIVDI3_LIBCALL
5331 sdiv_optab->handlers[(int) DImode].libfunc
5332 = init_one_libfunc (DIVDI3_LIBCALL);
5333 #endif
5334
5335 #ifdef UDIVSI3_LIBCALL
5336 udiv_optab->handlers[(int) SImode].libfunc
5337 = init_one_libfunc (UDIVSI3_LIBCALL);
5338 #endif
5339 #ifdef UDIVDI3_LIBCALL
5340 udiv_optab->handlers[(int) DImode].libfunc
5341 = init_one_libfunc (UDIVDI3_LIBCALL);
5342 #endif
5343
5344 #ifdef MODSI3_LIBCALL
5345 smod_optab->handlers[(int) SImode].libfunc
5346 = init_one_libfunc (MODSI3_LIBCALL);
5347 #endif
5348 #ifdef MODDI3_LIBCALL
5349 smod_optab->handlers[(int) DImode].libfunc
5350 = init_one_libfunc (MODDI3_LIBCALL);
5351 #endif
5352
5353 #ifdef UMODSI3_LIBCALL
5354 umod_optab->handlers[(int) SImode].libfunc
5355 = init_one_libfunc (UMODSI3_LIBCALL);
5356 #endif
5357 #ifdef UMODDI3_LIBCALL
5358 umod_optab->handlers[(int) DImode].libfunc
5359 = init_one_libfunc (UMODDI3_LIBCALL);
5360 #endif
5361
5362 /* Use cabs for DC complex abs, since systems generally have cabs.
5363 Don't define any libcall for SCmode, so that cabs will be used. */
5364 abs_optab->handlers[(int) DCmode].libfunc
5365 = init_one_libfunc ("cabs");
5366
5367 /* The ffs function operates on `int'. */
5368 ffs_optab->handlers[(int) mode_for_size (INT_TYPE_SIZE, MODE_INT, 0)].libfunc
5369 = init_one_libfunc ("ffs");
5370
5371 extendsfdf2_libfunc = init_one_libfunc ("__extendsfdf2");
5372 extendsfxf2_libfunc = init_one_libfunc ("__extendsfxf2");
5373 extendsftf2_libfunc = init_one_libfunc ("__extendsftf2");
5374 extenddfxf2_libfunc = init_one_libfunc ("__extenddfxf2");
5375 extenddftf2_libfunc = init_one_libfunc ("__extenddftf2");
5376
5377 truncdfsf2_libfunc = init_one_libfunc ("__truncdfsf2");
5378 truncxfsf2_libfunc = init_one_libfunc ("__truncxfsf2");
5379 trunctfsf2_libfunc = init_one_libfunc ("__trunctfsf2");
5380 truncxfdf2_libfunc = init_one_libfunc ("__truncxfdf2");
5381 trunctfdf2_libfunc = init_one_libfunc ("__trunctfdf2");
5382
5383 abort_libfunc = init_one_libfunc ("abort");
5384 memcpy_libfunc = init_one_libfunc ("memcpy");
5385 memmove_libfunc = init_one_libfunc ("memmove");
5386 bcopy_libfunc = init_one_libfunc ("bcopy");
5387 memcmp_libfunc = init_one_libfunc ("memcmp");
5388 bcmp_libfunc = init_one_libfunc ("__gcc_bcmp");
5389 memset_libfunc = init_one_libfunc ("memset");
5390 bzero_libfunc = init_one_libfunc ("bzero");
5391
5392 unwind_resume_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
5393 ? "_Unwind_SjLj_Resume"
5394 : "_Unwind_Resume");
5395 #ifndef DONT_USE_BUILTIN_SETJMP
5396 setjmp_libfunc = init_one_libfunc ("__builtin_setjmp");
5397 longjmp_libfunc = init_one_libfunc ("__builtin_longjmp");
5398 #else
5399 setjmp_libfunc = init_one_libfunc ("setjmp");
5400 longjmp_libfunc = init_one_libfunc ("longjmp");
5401 #endif
5402 unwind_sjlj_register_libfunc = init_one_libfunc ("_Unwind_SjLj_Register");
5403 unwind_sjlj_unregister_libfunc
5404 = init_one_libfunc ("_Unwind_SjLj_Unregister");
5405
5406 eqhf2_libfunc = init_one_libfunc ("__eqhf2");
5407 nehf2_libfunc = init_one_libfunc ("__nehf2");
5408 gthf2_libfunc = init_one_libfunc ("__gthf2");
5409 gehf2_libfunc = init_one_libfunc ("__gehf2");
5410 lthf2_libfunc = init_one_libfunc ("__lthf2");
5411 lehf2_libfunc = init_one_libfunc ("__lehf2");
5412 unordhf2_libfunc = init_one_libfunc ("__unordhf2");
5413
5414 eqsf2_libfunc = init_one_libfunc ("__eqsf2");
5415 nesf2_libfunc = init_one_libfunc ("__nesf2");
5416 gtsf2_libfunc = init_one_libfunc ("__gtsf2");
5417 gesf2_libfunc = init_one_libfunc ("__gesf2");
5418 ltsf2_libfunc = init_one_libfunc ("__ltsf2");
5419 lesf2_libfunc = init_one_libfunc ("__lesf2");
5420 unordsf2_libfunc = init_one_libfunc ("__unordsf2");
5421
5422 eqdf2_libfunc = init_one_libfunc ("__eqdf2");
5423 nedf2_libfunc = init_one_libfunc ("__nedf2");
5424 gtdf2_libfunc = init_one_libfunc ("__gtdf2");
5425 gedf2_libfunc = init_one_libfunc ("__gedf2");
5426 ltdf2_libfunc = init_one_libfunc ("__ltdf2");
5427 ledf2_libfunc = init_one_libfunc ("__ledf2");
5428 unorddf2_libfunc = init_one_libfunc ("__unorddf2");
5429
5430 eqxf2_libfunc = init_one_libfunc ("__eqxf2");
5431 nexf2_libfunc = init_one_libfunc ("__nexf2");
5432 gtxf2_libfunc = init_one_libfunc ("__gtxf2");
5433 gexf2_libfunc = init_one_libfunc ("__gexf2");
5434 ltxf2_libfunc = init_one_libfunc ("__ltxf2");
5435 lexf2_libfunc = init_one_libfunc ("__lexf2");
5436 unordxf2_libfunc = init_one_libfunc ("__unordxf2");
5437
5438 eqtf2_libfunc = init_one_libfunc ("__eqtf2");
5439 netf2_libfunc = init_one_libfunc ("__netf2");
5440 gttf2_libfunc = init_one_libfunc ("__gttf2");
5441 getf2_libfunc = init_one_libfunc ("__getf2");
5442 lttf2_libfunc = init_one_libfunc ("__lttf2");
5443 letf2_libfunc = init_one_libfunc ("__letf2");
5444 unordtf2_libfunc = init_one_libfunc ("__unordtf2");
5445
5446 floatsisf_libfunc = init_one_libfunc ("__floatsisf");
5447 floatdisf_libfunc = init_one_libfunc ("__floatdisf");
5448 floattisf_libfunc = init_one_libfunc ("__floattisf");
5449
5450 floatsidf_libfunc = init_one_libfunc ("__floatsidf");
5451 floatdidf_libfunc = init_one_libfunc ("__floatdidf");
5452 floattidf_libfunc = init_one_libfunc ("__floattidf");
5453
5454 floatsixf_libfunc = init_one_libfunc ("__floatsixf");
5455 floatdixf_libfunc = init_one_libfunc ("__floatdixf");
5456 floattixf_libfunc = init_one_libfunc ("__floattixf");
5457
5458 floatsitf_libfunc = init_one_libfunc ("__floatsitf");
5459 floatditf_libfunc = init_one_libfunc ("__floatditf");
5460 floattitf_libfunc = init_one_libfunc ("__floattitf");
5461
5462 fixsfsi_libfunc = init_one_libfunc ("__fixsfsi");
5463 fixsfdi_libfunc = init_one_libfunc ("__fixsfdi");
5464 fixsfti_libfunc = init_one_libfunc ("__fixsfti");
5465
5466 fixdfsi_libfunc = init_one_libfunc ("__fixdfsi");
5467 fixdfdi_libfunc = init_one_libfunc ("__fixdfdi");
5468 fixdfti_libfunc = init_one_libfunc ("__fixdfti");
5469
5470 fixxfsi_libfunc = init_one_libfunc ("__fixxfsi");
5471 fixxfdi_libfunc = init_one_libfunc ("__fixxfdi");
5472 fixxfti_libfunc = init_one_libfunc ("__fixxfti");
5473
5474 fixtfsi_libfunc = init_one_libfunc ("__fixtfsi");
5475 fixtfdi_libfunc = init_one_libfunc ("__fixtfdi");
5476 fixtfti_libfunc = init_one_libfunc ("__fixtfti");
5477
5478 fixunssfsi_libfunc = init_one_libfunc ("__fixunssfsi");
5479 fixunssfdi_libfunc = init_one_libfunc ("__fixunssfdi");
5480 fixunssfti_libfunc = init_one_libfunc ("__fixunssfti");
5481
5482 fixunsdfsi_libfunc = init_one_libfunc ("__fixunsdfsi");
5483 fixunsdfdi_libfunc = init_one_libfunc ("__fixunsdfdi");
5484 fixunsdfti_libfunc = init_one_libfunc ("__fixunsdfti");
5485
5486 fixunsxfsi_libfunc = init_one_libfunc ("__fixunsxfsi");
5487 fixunsxfdi_libfunc = init_one_libfunc ("__fixunsxfdi");
5488 fixunsxfti_libfunc = init_one_libfunc ("__fixunsxfti");
5489
5490 fixunstfsi_libfunc = init_one_libfunc ("__fixunstfsi");
5491 fixunstfdi_libfunc = init_one_libfunc ("__fixunstfdi");
5492 fixunstfti_libfunc = init_one_libfunc ("__fixunstfti");
5493
5494 /* For function entry/exit instrumentation. */
5495 profile_function_entry_libfunc
5496 = init_one_libfunc ("__cyg_profile_func_enter");
5497 profile_function_exit_libfunc
5498 = init_one_libfunc ("__cyg_profile_func_exit");
5499
5500 #ifdef HAVE_conditional_trap
5501 init_traps ();
5502 #endif
5503
5504 #ifdef INIT_TARGET_OPTABS
5505 /* Allow the target to add more libcalls or rename some, etc. */
5506 INIT_TARGET_OPTABS;
5507 #endif
5508 }
5509 \f
5510 static GTY(()) rtx trap_rtx;
5511
5512 #ifdef HAVE_conditional_trap
5513 /* The insn generating function can not take an rtx_code argument.
5514 TRAP_RTX is used as an rtx argument. Its code is replaced with
5515 the code to be used in the trap insn and all other fields are
5516 ignored. */
5517
5518 static void
5519 init_traps ()
5520 {
5521 if (HAVE_conditional_trap)
5522 {
5523 trap_rtx = gen_rtx_fmt_ee (EQ, VOIDmode, NULL_RTX, NULL_RTX);
5524 }
5525 }
5526 #endif
5527
5528 /* Generate insns to trap with code TCODE if OP1 and OP2 satisfy condition
5529 CODE. Return 0 on failure. */
5530
5531 rtx
5532 gen_cond_trap (code, op1, op2, tcode)
5533 enum rtx_code code ATTRIBUTE_UNUSED;
5534 rtx op1, op2 ATTRIBUTE_UNUSED, tcode ATTRIBUTE_UNUSED;
5535 {
5536 enum machine_mode mode = GET_MODE (op1);
5537
5538 if (mode == VOIDmode)
5539 return 0;
5540
5541 #ifdef HAVE_conditional_trap
5542 if (HAVE_conditional_trap
5543 && cmp_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
5544 {
5545 rtx insn;
5546 start_sequence ();
5547 emit_insn (GEN_FCN (cmp_optab->handlers[(int) mode].insn_code) (op1, op2));
5548 PUT_CODE (trap_rtx, code);
5549 insn = gen_conditional_trap (trap_rtx, tcode);
5550 if (insn)
5551 {
5552 emit_insn (insn);
5553 insn = get_insns ();
5554 }
5555 end_sequence ();
5556 return insn;
5557 }
5558 #endif
5559
5560 return 0;
5561 }
5562
5563 #include "gt-optabs.h"