1 /* Medium-level subroutines: convert bit-field store and extract
2 and shifts, multiplies and divides to rtl instructions.
3 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "coretypes.h"
33 #include "insn-config.h"
38 #include "langhooks.h"
40 static void store_fixed_bit_field (rtx, unsigned HOST_WIDE_INT,
41 unsigned HOST_WIDE_INT,
42 unsigned HOST_WIDE_INT, rtx);
43 static void store_split_bit_field (rtx, unsigned HOST_WIDE_INT,
44 unsigned HOST_WIDE_INT, rtx);
45 static rtx extract_fixed_bit_field (enum machine_mode, rtx,
46 unsigned HOST_WIDE_INT,
47 unsigned HOST_WIDE_INT,
48 unsigned HOST_WIDE_INT, rtx, int);
49 static rtx mask_rtx (enum machine_mode, int, int, int);
50 static rtx lshift_value (enum machine_mode, rtx, int, int);
51 static rtx extract_split_bit_field (rtx, unsigned HOST_WIDE_INT,
52 unsigned HOST_WIDE_INT, int);
53 static void do_cmp_and_jump (rtx, rtx, enum rtx_code, enum machine_mode, rtx);
55 /* Nonzero means divides or modulus operations are relatively cheap for
56 powers of two, so don't use branches; emit the operation instead.
57 Usually, this will mean that the MD file will emit non-branch
60 static int sdiv_pow2_cheap[NUM_MACHINE_MODES];
61 static int smod_pow2_cheap[NUM_MACHINE_MODES];
63 #ifndef SLOW_UNALIGNED_ACCESS
64 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
67 /* For compilers that support multiple targets with different word sizes,
68 MAX_BITS_PER_WORD contains the biggest value of BITS_PER_WORD. An example
69 is the H8/300(H) compiler. */
71 #ifndef MAX_BITS_PER_WORD
72 #define MAX_BITS_PER_WORD BITS_PER_WORD
75 /* Reduce conditional compilation elsewhere. */
78 #define CODE_FOR_insv CODE_FOR_nothing
79 #define gen_insv(a,b,c,d) NULL_RTX
83 #define CODE_FOR_extv CODE_FOR_nothing
84 #define gen_extv(a,b,c,d) NULL_RTX
88 #define CODE_FOR_extzv CODE_FOR_nothing
89 #define gen_extzv(a,b,c,d) NULL_RTX
92 /* Cost of various pieces of RTL. Note that some of these are indexed by
93 shift count and some by mode. */
95 static int add_cost[NUM_MACHINE_MODES];
96 static int neg_cost[NUM_MACHINE_MODES];
97 static int shift_cost[NUM_MACHINE_MODES][MAX_BITS_PER_WORD];
98 static int shiftadd_cost[NUM_MACHINE_MODES][MAX_BITS_PER_WORD];
99 static int shiftsub_cost[NUM_MACHINE_MODES][MAX_BITS_PER_WORD];
100 static int mul_cost[NUM_MACHINE_MODES];
101 static int div_cost[NUM_MACHINE_MODES];
102 static int mul_widen_cost[NUM_MACHINE_MODES];
103 static int mul_highpart_cost[NUM_MACHINE_MODES];
108 rtx reg, shift_insn, shiftadd_insn, shiftsub_insn;
109 rtx shift_pat, shiftadd_pat, shiftsub_pat;
110 rtx pow2[MAX_BITS_PER_WORD];
111 rtx cint[MAX_BITS_PER_WORD];
114 enum machine_mode mode, wider_mode;
118 zero_cost = rtx_cost (const0_rtx, 0);
122 for (m = 1; m < MAX_BITS_PER_WORD; m++)
124 pow2[m] = GEN_INT ((HOST_WIDE_INT) 1 << m);
125 cint[m] = GEN_INT (m);
128 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
130 mode = GET_MODE_WIDER_MODE (mode))
132 reg = gen_rtx_REG (mode, 10000);
133 add_cost[mode] = rtx_cost (gen_rtx_PLUS (mode, reg, reg), SET);
134 neg_cost[mode] = rtx_cost (gen_rtx_NEG (mode, reg), SET);
135 div_cost[mode] = rtx_cost (gen_rtx_UDIV (mode, reg, reg), SET);
136 mul_cost[mode] = rtx_cost (gen_rtx_MULT (mode, reg, reg), SET);
138 sdiv_pow2_cheap[mode]
139 = (rtx_cost (gen_rtx_DIV (mode, reg, GEN_INT (32)), SET)
140 <= 2 * add_cost[mode]);
141 smod_pow2_cheap[mode]
142 = (rtx_cost (gen_rtx_MOD (mode, reg, GEN_INT (32)), SET)
143 <= 2 * add_cost[mode]);
145 wider_mode = GET_MODE_WIDER_MODE (mode);
146 if (wider_mode != VOIDmode)
148 mul_widen_cost[wider_mode]
149 = rtx_cost (gen_rtx_MULT (wider_mode,
150 gen_rtx_ZERO_EXTEND (wider_mode, reg),
151 gen_rtx_ZERO_EXTEND (wider_mode, reg)),
153 mul_highpart_cost[mode]
154 = rtx_cost (gen_rtx_TRUNCATE
156 gen_rtx_LSHIFTRT (wider_mode,
157 gen_rtx_MULT (wider_mode,
162 GEN_INT (GET_MODE_BITSIZE (mode)))),
166 shift_insn = emit_insn (gen_rtx_SET (VOIDmode, reg,
167 gen_rtx_ASHIFT (mode, reg,
171 = emit_insn (gen_rtx_SET (VOIDmode, reg,
179 = emit_insn (gen_rtx_SET (VOIDmode, reg,
186 shift_pat = PATTERN (shift_insn);
187 shiftadd_pat = PATTERN (shiftadd_insn);
188 shiftsub_pat = PATTERN (shiftsub_insn);
190 shift_cost[mode][0] = 0;
191 shiftadd_cost[mode][0] = shiftsub_cost[mode][0] = add_cost[mode];
193 n = MIN (MAX_BITS_PER_WORD, GET_MODE_BITSIZE (mode));
194 for (m = 1; m < n; m++)
196 shift_cost[mode][m] = 32000;
197 XEXP (SET_SRC (shift_pat), 1) = cint[m];
198 if (recog (shift_pat, shift_insn, &dummy) >= 0)
199 shift_cost[mode][m] = rtx_cost (SET_SRC (shift_pat), SET);
201 shiftadd_cost[mode][m] = 32000;
202 XEXP (XEXP (SET_SRC (shiftadd_pat), 0), 1) = pow2[m];
203 if (recog (shiftadd_pat, shiftadd_insn, &dummy) >= 0)
204 shiftadd_cost[mode][m] = rtx_cost (SET_SRC (shiftadd_pat), SET);
206 shiftsub_cost[mode][m] = 32000;
207 XEXP (XEXP (SET_SRC (shiftsub_pat), 0), 1) = pow2[m];
208 if (recog (shiftsub_pat, shiftsub_insn, &dummy) >= 0)
209 shiftsub_cost[mode][m] = rtx_cost (SET_SRC (shiftsub_pat), SET);
216 /* Return an rtx representing minus the value of X.
217 MODE is the intended mode of the result,
218 useful if X is a CONST_INT. */
221 negate_rtx (enum machine_mode mode, rtx x)
223 rtx result = simplify_unary_operation (NEG, mode, x, mode);
226 result = expand_unop (mode, neg_optab, x, NULL_RTX, 0);
231 /* Report on the availability of insv/extv/extzv and the desired mode
232 of each of their operands. Returns MAX_MACHINE_MODE if HAVE_foo
233 is false; else the mode of the specified operand. If OPNO is -1,
234 all the caller cares about is whether the insn is available. */
236 mode_for_extraction (enum extraction_pattern pattern, int opno)
238 const struct insn_data *data;
245 data = &insn_data[CODE_FOR_insv];
248 return MAX_MACHINE_MODE;
253 data = &insn_data[CODE_FOR_extv];
256 return MAX_MACHINE_MODE;
261 data = &insn_data[CODE_FOR_extzv];
264 return MAX_MACHINE_MODE;
273 /* Everyone who uses this function used to follow it with
274 if (result == VOIDmode) result = word_mode; */
275 if (data->operand[opno].mode == VOIDmode)
277 return data->operand[opno].mode;
281 /* Generate code to store value from rtx VALUE
282 into a bit-field within structure STR_RTX
283 containing BITSIZE bits starting at bit BITNUM.
284 FIELDMODE is the machine-mode of the FIELD_DECL node for this field.
285 ALIGN is the alignment that STR_RTX is known to have.
286 TOTAL_SIZE is the size of the structure in bytes, or -1 if varying. */
288 /* ??? Note that there are two different ideas here for how
289 to determine the size to count bits within, for a register.
290 One is BITS_PER_WORD, and the other is the size of operand 3
293 If operand 3 of the insv pattern is VOIDmode, then we will use BITS_PER_WORD
294 else, we use the mode of operand 3. */
297 store_bit_field (rtx str_rtx, unsigned HOST_WIDE_INT bitsize,
298 unsigned HOST_WIDE_INT bitnum, enum machine_mode fieldmode,
299 rtx value, HOST_WIDE_INT total_size)
302 = (GET_CODE (str_rtx) == MEM) ? BITS_PER_UNIT : BITS_PER_WORD;
303 unsigned HOST_WIDE_INT offset = bitnum / unit;
304 unsigned HOST_WIDE_INT bitpos = bitnum % unit;
308 enum machine_mode op_mode = mode_for_extraction (EP_insv, 3);
310 /* Discount the part of the structure before the desired byte.
311 We need to know how many bytes are safe to reference after it. */
313 total_size -= (bitpos / BIGGEST_ALIGNMENT
314 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
316 while (GET_CODE (op0) == SUBREG)
318 /* The following line once was done only if WORDS_BIG_ENDIAN,
319 but I think that is a mistake. WORDS_BIG_ENDIAN is
320 meaningful at a much higher level; when structures are copied
321 between memory and regs, the higher-numbered regs
322 always get higher addresses. */
323 offset += (SUBREG_BYTE (op0) / UNITS_PER_WORD);
324 /* We used to adjust BITPOS here, but now we do the whole adjustment
325 right after the loop. */
326 op0 = SUBREG_REG (op0);
329 value = protect_from_queue (value, 0);
331 /* Use vec_extract patterns for extracting parts of vectors whenever
333 if (VECTOR_MODE_P (GET_MODE (op0))
334 && GET_CODE (op0) != MEM
335 && (vec_set_optab->handlers[GET_MODE (op0)].insn_code
337 && fieldmode == GET_MODE_INNER (GET_MODE (op0))
338 && bitsize == GET_MODE_BITSIZE (GET_MODE_INNER (GET_MODE (op0)))
339 && !(bitnum % GET_MODE_BITSIZE (GET_MODE_INNER (GET_MODE (op0)))))
341 enum machine_mode outermode = GET_MODE (op0);
342 enum machine_mode innermode = GET_MODE_INNER (outermode);
343 int icode = (int) vec_set_optab->handlers[outermode].insn_code;
344 int pos = bitnum / GET_MODE_BITSIZE (innermode);
345 rtx rtxpos = GEN_INT (pos);
349 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
350 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
351 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
355 if (! (*insn_data[icode].operand[1].predicate) (src, mode1))
356 src = copy_to_mode_reg (mode1, src);
358 if (! (*insn_data[icode].operand[2].predicate) (rtxpos, mode2))
359 rtxpos = copy_to_mode_reg (mode1, rtxpos);
361 /* We could handle this, but we should always be called with a pseudo
362 for our targets and all insns should take them as outputs. */
363 if (! (*insn_data[icode].operand[0].predicate) (dest, mode0)
364 || ! (*insn_data[icode].operand[1].predicate) (src, mode1)
365 || ! (*insn_data[icode].operand[2].predicate) (rtxpos, mode2))
367 pat = GEN_FCN (icode) (dest, src, rtxpos);
380 int old_generating_concat_p = generating_concat_p;
381 generating_concat_p = 0;
382 value = force_not_mem (value);
383 generating_concat_p = old_generating_concat_p;
386 /* If the target is a register, overwriting the entire object, or storing
387 a full-word or multi-word field can be done with just a SUBREG.
389 If the target is memory, storing any naturally aligned field can be
390 done with a simple store. For targets that support fast unaligned
391 memory, any naturally sized, unit aligned field can be done directly. */
393 byte_offset = (bitnum % BITS_PER_WORD) / BITS_PER_UNIT
394 + (offset * UNITS_PER_WORD);
397 && bitsize == GET_MODE_BITSIZE (fieldmode)
398 && (GET_CODE (op0) != MEM
399 ? ((GET_MODE_SIZE (fieldmode) >= UNITS_PER_WORD
400 || GET_MODE_SIZE (GET_MODE (op0)) == GET_MODE_SIZE (fieldmode))
401 && byte_offset % GET_MODE_SIZE (fieldmode) == 0)
402 : (! SLOW_UNALIGNED_ACCESS (fieldmode, MEM_ALIGN (op0))
403 || (offset * BITS_PER_UNIT % bitsize == 0
404 && MEM_ALIGN (op0) % GET_MODE_BITSIZE (fieldmode) == 0))))
406 if (GET_MODE (op0) != fieldmode)
408 if (GET_CODE (op0) == SUBREG)
410 if (GET_MODE (SUBREG_REG (op0)) == fieldmode
411 || GET_MODE_CLASS (fieldmode) == MODE_INT
412 || GET_MODE_CLASS (fieldmode) == MODE_PARTIAL_INT)
413 op0 = SUBREG_REG (op0);
415 /* Else we've got some float mode source being extracted into
416 a different float mode destination -- this combination of
417 subregs results in Severe Tire Damage. */
420 if (GET_CODE (op0) == REG)
421 op0 = gen_rtx_SUBREG (fieldmode, op0, byte_offset);
423 op0 = adjust_address (op0, fieldmode, offset);
425 emit_move_insn (op0, value);
429 /* Make sure we are playing with integral modes. Pun with subregs
430 if we aren't. This must come after the entire register case above,
431 since that case is valid for any mode. The following cases are only
432 valid for integral modes. */
434 enum machine_mode imode = int_mode_for_mode (GET_MODE (op0));
435 if (imode != GET_MODE (op0))
437 if (GET_CODE (op0) == MEM)
438 op0 = adjust_address (op0, imode, 0);
439 else if (imode != BLKmode)
440 op0 = gen_lowpart (imode, op0);
446 /* We may be accessing data outside the field, which means
447 we can alias adjacent data. */
448 if (GET_CODE (op0) == MEM)
450 op0 = shallow_copy_rtx (op0);
451 set_mem_alias_set (op0, 0);
452 set_mem_expr (op0, 0);
455 /* If OP0 is a register, BITPOS must count within a word.
456 But as we have it, it counts within whatever size OP0 now has.
457 On a bigendian machine, these are not the same, so convert. */
459 && GET_CODE (op0) != MEM
460 && unit > GET_MODE_BITSIZE (GET_MODE (op0)))
461 bitpos += unit - GET_MODE_BITSIZE (GET_MODE (op0));
463 /* Storing an lsb-aligned field in a register
464 can be done with a movestrict instruction. */
466 if (GET_CODE (op0) != MEM
467 && (BYTES_BIG_ENDIAN ? bitpos + bitsize == unit : bitpos == 0)
468 && bitsize == GET_MODE_BITSIZE (fieldmode)
469 && (movstrict_optab->handlers[fieldmode].insn_code
470 != CODE_FOR_nothing))
472 int icode = movstrict_optab->handlers[fieldmode].insn_code;
474 /* Get appropriate low part of the value being stored. */
475 if (GET_CODE (value) == CONST_INT || GET_CODE (value) == REG)
476 value = gen_lowpart (fieldmode, value);
477 else if (!(GET_CODE (value) == SYMBOL_REF
478 || GET_CODE (value) == LABEL_REF
479 || GET_CODE (value) == CONST))
480 value = convert_to_mode (fieldmode, value, 0);
482 if (! (*insn_data[icode].operand[1].predicate) (value, fieldmode))
483 value = copy_to_mode_reg (fieldmode, value);
485 if (GET_CODE (op0) == SUBREG)
487 if (GET_MODE (SUBREG_REG (op0)) == fieldmode
488 || GET_MODE_CLASS (fieldmode) == MODE_INT
489 || GET_MODE_CLASS (fieldmode) == MODE_PARTIAL_INT)
490 op0 = SUBREG_REG (op0);
492 /* Else we've got some float mode source being extracted into
493 a different float mode destination -- this combination of
494 subregs results in Severe Tire Damage. */
498 emit_insn (GEN_FCN (icode)
499 (gen_rtx_SUBREG (fieldmode, op0,
500 (bitnum % BITS_PER_WORD) / BITS_PER_UNIT
501 + (offset * UNITS_PER_WORD)),
507 /* Handle fields bigger than a word. */
509 if (bitsize > BITS_PER_WORD)
511 /* Here we transfer the words of the field
512 in the order least significant first.
513 This is because the most significant word is the one which may
515 However, only do that if the value is not BLKmode. */
517 unsigned int backwards = WORDS_BIG_ENDIAN && fieldmode != BLKmode;
518 unsigned int nwords = (bitsize + (BITS_PER_WORD - 1)) / BITS_PER_WORD;
521 /* This is the mode we must force value to, so that there will be enough
522 subwords to extract. Note that fieldmode will often (always?) be
523 VOIDmode, because that is what store_field uses to indicate that this
524 is a bit field, but passing VOIDmode to operand_subword_force will
525 result in an abort. */
526 fieldmode = GET_MODE (value);
527 if (fieldmode == VOIDmode)
528 fieldmode = smallest_mode_for_size (nwords * BITS_PER_WORD, MODE_INT);
530 for (i = 0; i < nwords; i++)
532 /* If I is 0, use the low-order word in both field and target;
533 if I is 1, use the next to lowest word; and so on. */
534 unsigned int wordnum = (backwards ? nwords - i - 1 : i);
535 unsigned int bit_offset = (backwards
536 ? MAX ((int) bitsize - ((int) i + 1)
539 : (int) i * BITS_PER_WORD);
541 store_bit_field (op0, MIN (BITS_PER_WORD,
542 bitsize - i * BITS_PER_WORD),
543 bitnum + bit_offset, word_mode,
544 operand_subword_force (value, wordnum, fieldmode),
550 /* From here on we can assume that the field to be stored in is
551 a full-word (whatever type that is), since it is shorter than a word. */
553 /* OFFSET is the number of words or bytes (UNIT says which)
554 from STR_RTX to the first word or byte containing part of the field. */
556 if (GET_CODE (op0) != MEM)
559 || GET_MODE_SIZE (GET_MODE (op0)) > UNITS_PER_WORD)
561 if (GET_CODE (op0) != REG)
563 /* Since this is a destination (lvalue), we can't copy it to a
564 pseudo. We can trivially remove a SUBREG that does not
565 change the size of the operand. Such a SUBREG may have been
566 added above. Otherwise, abort. */
567 if (GET_CODE (op0) == SUBREG
568 && (GET_MODE_SIZE (GET_MODE (op0))
569 == GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0)))))
570 op0 = SUBREG_REG (op0);
574 op0 = gen_rtx_SUBREG (mode_for_size (BITS_PER_WORD, MODE_INT, 0),
575 op0, (offset * UNITS_PER_WORD));
580 op0 = protect_from_queue (op0, 1);
582 /* If VALUE is a floating-point mode, access it as an integer of the
583 corresponding size. This can occur on a machine with 64 bit registers
584 that uses SFmode for float. This can also occur for unaligned float
586 if (GET_MODE_CLASS (GET_MODE (value)) != MODE_INT
587 && GET_MODE_CLASS (GET_MODE (value)) != MODE_PARTIAL_INT)
588 value = gen_lowpart ((GET_MODE (value) == VOIDmode
589 ? word_mode : int_mode_for_mode (GET_MODE (value))),
592 /* Now OFFSET is nonzero only if OP0 is memory
593 and is therefore always measured in bytes. */
596 && GET_MODE (value) != BLKmode
597 && !(bitsize == 1 && GET_CODE (value) == CONST_INT)
598 /* Ensure insv's size is wide enough for this field. */
599 && (GET_MODE_BITSIZE (op_mode) >= bitsize)
600 && ! ((GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG)
601 && (bitsize + bitpos > GET_MODE_BITSIZE (op_mode))))
603 int xbitpos = bitpos;
606 rtx last = get_last_insn ();
608 enum machine_mode maxmode = mode_for_extraction (EP_insv, 3);
609 int save_volatile_ok = volatile_ok;
613 /* If this machine's insv can only insert into a register, copy OP0
614 into a register and save it back later. */
615 /* This used to check flag_force_mem, but that was a serious
616 de-optimization now that flag_force_mem is enabled by -O2. */
617 if (GET_CODE (op0) == MEM
618 && ! ((*insn_data[(int) CODE_FOR_insv].operand[0].predicate)
622 enum machine_mode bestmode;
624 /* Get the mode to use for inserting into this field. If OP0 is
625 BLKmode, get the smallest mode consistent with the alignment. If
626 OP0 is a non-BLKmode object that is no wider than MAXMODE, use its
627 mode. Otherwise, use the smallest mode containing the field. */
629 if (GET_MODE (op0) == BLKmode
630 || GET_MODE_SIZE (GET_MODE (op0)) > GET_MODE_SIZE (maxmode))
632 = get_best_mode (bitsize, bitnum, MEM_ALIGN (op0), maxmode,
633 MEM_VOLATILE_P (op0));
635 bestmode = GET_MODE (op0);
637 if (bestmode == VOIDmode
638 || (SLOW_UNALIGNED_ACCESS (bestmode, MEM_ALIGN (op0))
639 && GET_MODE_BITSIZE (bestmode) > MEM_ALIGN (op0)))
642 /* Adjust address to point to the containing unit of that mode.
643 Compute offset as multiple of this unit, counting in bytes. */
644 unit = GET_MODE_BITSIZE (bestmode);
645 offset = (bitnum / unit) * GET_MODE_SIZE (bestmode);
646 bitpos = bitnum % unit;
647 op0 = adjust_address (op0, bestmode, offset);
649 /* Fetch that unit, store the bitfield in it, then store
651 tempreg = copy_to_reg (op0);
652 store_bit_field (tempreg, bitsize, bitpos, fieldmode, value,
654 emit_move_insn (op0, tempreg);
657 volatile_ok = save_volatile_ok;
659 /* Add OFFSET into OP0's address. */
660 if (GET_CODE (xop0) == MEM)
661 xop0 = adjust_address (xop0, byte_mode, offset);
663 /* If xop0 is a register, we need it in MAXMODE
664 to make it acceptable to the format of insv. */
665 if (GET_CODE (xop0) == SUBREG)
666 /* We can't just change the mode, because this might clobber op0,
667 and we will need the original value of op0 if insv fails. */
668 xop0 = gen_rtx_SUBREG (maxmode, SUBREG_REG (xop0), SUBREG_BYTE (xop0));
669 if (GET_CODE (xop0) == REG && GET_MODE (xop0) != maxmode)
670 xop0 = gen_rtx_SUBREG (maxmode, xop0, 0);
672 /* On big-endian machines, we count bits from the most significant.
673 If the bit field insn does not, we must invert. */
675 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
676 xbitpos = unit - bitsize - xbitpos;
678 /* We have been counting XBITPOS within UNIT.
679 Count instead within the size of the register. */
680 if (BITS_BIG_ENDIAN && GET_CODE (xop0) != MEM)
681 xbitpos += GET_MODE_BITSIZE (maxmode) - unit;
683 unit = GET_MODE_BITSIZE (maxmode);
685 /* Convert VALUE to maxmode (which insv insn wants) in VALUE1. */
687 if (GET_MODE (value) != maxmode)
689 if (GET_MODE_BITSIZE (GET_MODE (value)) >= bitsize)
691 /* Optimization: Don't bother really extending VALUE
692 if it has all the bits we will actually use. However,
693 if we must narrow it, be sure we do it correctly. */
695 if (GET_MODE_SIZE (GET_MODE (value)) < GET_MODE_SIZE (maxmode))
699 tmp = simplify_subreg (maxmode, value1, GET_MODE (value), 0);
701 tmp = simplify_gen_subreg (maxmode,
702 force_reg (GET_MODE (value),
704 GET_MODE (value), 0);
708 value1 = gen_lowpart (maxmode, value1);
710 else if (GET_CODE (value) == CONST_INT)
711 value1 = gen_int_mode (INTVAL (value), maxmode);
712 else if (!CONSTANT_P (value))
713 /* Parse phase is supposed to make VALUE's data type
714 match that of the component reference, which is a type
715 at least as wide as the field; so VALUE should have
716 a mode that corresponds to that type. */
720 /* If this machine's insv insists on a register,
721 get VALUE1 into a register. */
722 if (! ((*insn_data[(int) CODE_FOR_insv].operand[3].predicate)
724 value1 = force_reg (maxmode, value1);
726 pat = gen_insv (xop0, GEN_INT (bitsize), GEN_INT (xbitpos), value1);
731 delete_insns_since (last);
732 store_fixed_bit_field (op0, offset, bitsize, bitpos, value);
737 /* Insv is not available; store using shifts and boolean ops. */
738 store_fixed_bit_field (op0, offset, bitsize, bitpos, value);
742 /* Use shifts and boolean operations to store VALUE
743 into a bit field of width BITSIZE
744 in a memory location specified by OP0 except offset by OFFSET bytes.
745 (OFFSET must be 0 if OP0 is a register.)
746 The field starts at position BITPOS within the byte.
747 (If OP0 is a register, it may be a full word or a narrower mode,
748 but BITPOS still counts within a full word,
749 which is significant on bigendian machines.)
751 Note that protect_from_queue has already been done on OP0 and VALUE. */
754 store_fixed_bit_field (rtx op0, unsigned HOST_WIDE_INT offset,
755 unsigned HOST_WIDE_INT bitsize,
756 unsigned HOST_WIDE_INT bitpos, rtx value)
758 enum machine_mode mode;
759 unsigned int total_bits = BITS_PER_WORD;
764 /* There is a case not handled here:
765 a structure with a known alignment of just a halfword
766 and a field split across two aligned halfwords within the structure.
767 Or likewise a structure with a known alignment of just a byte
768 and a field split across two bytes.
769 Such cases are not supposed to be able to occur. */
771 if (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG)
775 /* Special treatment for a bit field split across two registers. */
776 if (bitsize + bitpos > BITS_PER_WORD)
778 store_split_bit_field (op0, bitsize, bitpos, value);
784 /* Get the proper mode to use for this field. We want a mode that
785 includes the entire field. If such a mode would be larger than
786 a word, we won't be doing the extraction the normal way.
787 We don't want a mode bigger than the destination. */
789 mode = GET_MODE (op0);
790 if (GET_MODE_BITSIZE (mode) == 0
791 || GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (word_mode))
793 mode = get_best_mode (bitsize, bitpos + offset * BITS_PER_UNIT,
794 MEM_ALIGN (op0), mode, MEM_VOLATILE_P (op0));
796 if (mode == VOIDmode)
798 /* The only way this should occur is if the field spans word
800 store_split_bit_field (op0, bitsize, bitpos + offset * BITS_PER_UNIT,
805 total_bits = GET_MODE_BITSIZE (mode);
807 /* Make sure bitpos is valid for the chosen mode. Adjust BITPOS to
808 be in the range 0 to total_bits-1, and put any excess bytes in
810 if (bitpos >= total_bits)
812 offset += (bitpos / total_bits) * (total_bits / BITS_PER_UNIT);
813 bitpos -= ((bitpos / total_bits) * (total_bits / BITS_PER_UNIT)
817 /* Get ref to an aligned byte, halfword, or word containing the field.
818 Adjust BITPOS to be position within a word,
819 and OFFSET to be the offset of that word.
820 Then alter OP0 to refer to that word. */
821 bitpos += (offset % (total_bits / BITS_PER_UNIT)) * BITS_PER_UNIT;
822 offset -= (offset % (total_bits / BITS_PER_UNIT));
823 op0 = adjust_address (op0, mode, offset);
826 mode = GET_MODE (op0);
828 /* Now MODE is either some integral mode for a MEM as OP0,
829 or is a full-word for a REG as OP0. TOTAL_BITS corresponds.
830 The bit field is contained entirely within OP0.
831 BITPOS is the starting bit number within OP0.
832 (OP0's mode may actually be narrower than MODE.) */
834 if (BYTES_BIG_ENDIAN)
835 /* BITPOS is the distance between our msb
836 and that of the containing datum.
837 Convert it to the distance from the lsb. */
838 bitpos = total_bits - bitsize - bitpos;
840 /* Now BITPOS is always the distance between our lsb
843 /* Shift VALUE left by BITPOS bits. If VALUE is not constant,
844 we must first convert its mode to MODE. */
846 if (GET_CODE (value) == CONST_INT)
848 HOST_WIDE_INT v = INTVAL (value);
850 if (bitsize < HOST_BITS_PER_WIDE_INT)
851 v &= ((HOST_WIDE_INT) 1 << bitsize) - 1;
855 else if ((bitsize < HOST_BITS_PER_WIDE_INT
856 && v == ((HOST_WIDE_INT) 1 << bitsize) - 1)
857 || (bitsize == HOST_BITS_PER_WIDE_INT && v == -1))
860 value = lshift_value (mode, value, bitpos, bitsize);
864 int must_and = (GET_MODE_BITSIZE (GET_MODE (value)) != bitsize
865 && bitpos + bitsize != GET_MODE_BITSIZE (mode));
867 if (GET_MODE (value) != mode)
869 if ((GET_CODE (value) == REG || GET_CODE (value) == SUBREG)
870 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (value)))
871 value = gen_lowpart (mode, value);
873 value = convert_to_mode (mode, value, 1);
877 value = expand_binop (mode, and_optab, value,
878 mask_rtx (mode, 0, bitsize, 0),
879 NULL_RTX, 1, OPTAB_LIB_WIDEN);
881 value = expand_shift (LSHIFT_EXPR, mode, value,
882 build_int_2 (bitpos, 0), NULL_RTX, 1);
885 /* Now clear the chosen bits in OP0,
886 except that if VALUE is -1 we need not bother. */
888 subtarget = (GET_CODE (op0) == REG || ! flag_force_mem) ? op0 : 0;
892 temp = expand_binop (mode, and_optab, op0,
893 mask_rtx (mode, bitpos, bitsize, 1),
894 subtarget, 1, OPTAB_LIB_WIDEN);
900 /* Now logical-or VALUE into OP0, unless it is zero. */
903 temp = expand_binop (mode, ior_optab, temp, value,
904 subtarget, 1, OPTAB_LIB_WIDEN);
906 emit_move_insn (op0, temp);
909 /* Store a bit field that is split across multiple accessible memory objects.
911 OP0 is the REG, SUBREG or MEM rtx for the first of the objects.
912 BITSIZE is the field width; BITPOS the position of its first bit
914 VALUE is the value to store.
916 This does not yet handle fields wider than BITS_PER_WORD. */
919 store_split_bit_field (rtx op0, unsigned HOST_WIDE_INT bitsize,
920 unsigned HOST_WIDE_INT bitpos, rtx value)
923 unsigned int bitsdone = 0;
925 /* Make sure UNIT isn't larger than BITS_PER_WORD, we can only handle that
927 if (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG)
928 unit = BITS_PER_WORD;
930 unit = MIN (MEM_ALIGN (op0), BITS_PER_WORD);
932 /* If VALUE is a constant other than a CONST_INT, get it into a register in
933 WORD_MODE. If we can do this using gen_lowpart_common, do so. Note
934 that VALUE might be a floating-point constant. */
935 if (CONSTANT_P (value) && GET_CODE (value) != CONST_INT)
937 rtx word = gen_lowpart_common (word_mode, value);
939 if (word && (value != word))
942 value = gen_lowpart_common (word_mode,
943 force_reg (GET_MODE (value) != VOIDmode
945 : word_mode, value));
947 else if (GET_CODE (value) == ADDRESSOF)
948 value = copy_to_reg (value);
950 while (bitsdone < bitsize)
952 unsigned HOST_WIDE_INT thissize;
954 unsigned HOST_WIDE_INT thispos;
955 unsigned HOST_WIDE_INT offset;
957 offset = (bitpos + bitsdone) / unit;
958 thispos = (bitpos + bitsdone) % unit;
960 /* THISSIZE must not overrun a word boundary. Otherwise,
961 store_fixed_bit_field will call us again, and we will mutually
963 thissize = MIN (bitsize - bitsdone, BITS_PER_WORD);
964 thissize = MIN (thissize, unit - thispos);
966 if (BYTES_BIG_ENDIAN)
970 /* We must do an endian conversion exactly the same way as it is
971 done in extract_bit_field, so that the two calls to
972 extract_fixed_bit_field will have comparable arguments. */
973 if (GET_CODE (value) != MEM || GET_MODE (value) == BLKmode)
974 total_bits = BITS_PER_WORD;
976 total_bits = GET_MODE_BITSIZE (GET_MODE (value));
978 /* Fetch successively less significant portions. */
979 if (GET_CODE (value) == CONST_INT)
980 part = GEN_INT (((unsigned HOST_WIDE_INT) (INTVAL (value))
981 >> (bitsize - bitsdone - thissize))
982 & (((HOST_WIDE_INT) 1 << thissize) - 1));
984 /* The args are chosen so that the last part includes the
985 lsb. Give extract_bit_field the value it needs (with
986 endianness compensation) to fetch the piece we want. */
987 part = extract_fixed_bit_field (word_mode, value, 0, thissize,
988 total_bits - bitsize + bitsdone,
993 /* Fetch successively more significant portions. */
994 if (GET_CODE (value) == CONST_INT)
995 part = GEN_INT (((unsigned HOST_WIDE_INT) (INTVAL (value))
997 & (((HOST_WIDE_INT) 1 << thissize) - 1));
999 part = extract_fixed_bit_field (word_mode, value, 0, thissize,
1000 bitsdone, NULL_RTX, 1);
1003 /* If OP0 is a register, then handle OFFSET here.
1005 When handling multiword bitfields, extract_bit_field may pass
1006 down a word_mode SUBREG of a larger REG for a bitfield that actually
1007 crosses a word boundary. Thus, for a SUBREG, we must find
1008 the current word starting from the base register. */
1009 if (GET_CODE (op0) == SUBREG)
1011 int word_offset = (SUBREG_BYTE (op0) / UNITS_PER_WORD) + offset;
1012 word = operand_subword_force (SUBREG_REG (op0), word_offset,
1013 GET_MODE (SUBREG_REG (op0)));
1016 else if (GET_CODE (op0) == REG)
1018 word = operand_subword_force (op0, offset, GET_MODE (op0));
1024 /* OFFSET is in UNITs, and UNIT is in bits.
1025 store_fixed_bit_field wants offset in bytes. */
1026 store_fixed_bit_field (word, offset * unit / BITS_PER_UNIT, thissize,
1028 bitsdone += thissize;
1032 /* Generate code to extract a byte-field from STR_RTX
1033 containing BITSIZE bits, starting at BITNUM,
1034 and put it in TARGET if possible (if TARGET is nonzero).
1035 Regardless of TARGET, we return the rtx for where the value is placed.
1038 STR_RTX is the structure containing the byte (a REG or MEM).
1039 UNSIGNEDP is nonzero if this is an unsigned bit field.
1040 MODE is the natural mode of the field value once extracted.
1041 TMODE is the mode the caller would like the value to have;
1042 but the value may be returned with type MODE instead.
1044 TOTAL_SIZE is the size in bytes of the containing structure,
1047 If a TARGET is specified and we can store in it at no extra cost,
1048 we do so, and return TARGET.
1049 Otherwise, we return a REG of mode TMODE or MODE, with TMODE preferred
1050 if they are equally easy. */
1053 extract_bit_field (rtx str_rtx, unsigned HOST_WIDE_INT bitsize,
1054 unsigned HOST_WIDE_INT bitnum, int unsignedp, rtx target,
1055 enum machine_mode mode, enum machine_mode tmode,
1056 HOST_WIDE_INT total_size)
1059 = (GET_CODE (str_rtx) == MEM) ? BITS_PER_UNIT : BITS_PER_WORD;
1060 unsigned HOST_WIDE_INT offset = bitnum / unit;
1061 unsigned HOST_WIDE_INT bitpos = bitnum % unit;
1063 rtx spec_target = target;
1064 rtx spec_target_subreg = 0;
1065 enum machine_mode int_mode;
1066 enum machine_mode extv_mode = mode_for_extraction (EP_extv, 0);
1067 enum machine_mode extzv_mode = mode_for_extraction (EP_extzv, 0);
1068 enum machine_mode mode1;
1071 /* Discount the part of the structure before the desired byte.
1072 We need to know how many bytes are safe to reference after it. */
1073 if (total_size >= 0)
1074 total_size -= (bitpos / BIGGEST_ALIGNMENT
1075 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1077 if (tmode == VOIDmode)
1080 while (GET_CODE (op0) == SUBREG)
1082 bitpos += SUBREG_BYTE (op0) * BITS_PER_UNIT;
1085 offset += (bitpos / unit);
1088 op0 = SUBREG_REG (op0);
1091 if (GET_CODE (op0) == REG
1092 && mode == GET_MODE (op0)
1094 && bitsize == GET_MODE_BITSIZE (GET_MODE (op0)))
1096 /* We're trying to extract a full register from itself. */
1100 /* Use vec_extract patterns for extracting parts of vectors whenever
1102 if (VECTOR_MODE_P (GET_MODE (op0))
1103 && GET_CODE (op0) != MEM
1104 && (vec_extract_optab->handlers[GET_MODE (op0)].insn_code
1105 != CODE_FOR_nothing)
1106 && ((bitsize + bitnum) / GET_MODE_BITSIZE (GET_MODE_INNER (GET_MODE (op0)))
1107 == bitsize / GET_MODE_BITSIZE (GET_MODE_INNER (GET_MODE (op0)))))
1109 enum machine_mode outermode = GET_MODE (op0);
1110 enum machine_mode innermode = GET_MODE_INNER (outermode);
1111 int icode = (int) vec_extract_optab->handlers[outermode].insn_code;
1112 int pos = bitnum / GET_MODE_BITSIZE (innermode);
1113 rtx rtxpos = GEN_INT (pos);
1115 rtx dest = NULL, pat, seq;
1116 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
1117 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
1118 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
1120 if (innermode == tmode || innermode == mode)
1124 dest = gen_reg_rtx (innermode);
1128 if (! (*insn_data[icode].operand[0].predicate) (dest, mode0))
1129 dest = copy_to_mode_reg (mode0, dest);
1131 if (! (*insn_data[icode].operand[1].predicate) (src, mode1))
1132 src = copy_to_mode_reg (mode1, src);
1134 if (! (*insn_data[icode].operand[2].predicate) (rtxpos, mode2))
1135 rtxpos = copy_to_mode_reg (mode1, rtxpos);
1137 /* We could handle this, but we should always be called with a pseudo
1138 for our targets and all insns should take them as outputs. */
1139 if (! (*insn_data[icode].operand[0].predicate) (dest, mode0)
1140 || ! (*insn_data[icode].operand[1].predicate) (src, mode1)
1141 || ! (*insn_data[icode].operand[2].predicate) (rtxpos, mode2))
1144 pat = GEN_FCN (icode) (dest, src, rtxpos);
1155 /* Make sure we are playing with integral modes. Pun with subregs
1158 enum machine_mode imode = int_mode_for_mode (GET_MODE (op0));
1159 if (imode != GET_MODE (op0))
1161 if (GET_CODE (op0) == MEM)
1162 op0 = adjust_address (op0, imode, 0);
1163 else if (imode != BLKmode)
1164 op0 = gen_lowpart (imode, op0);
1170 /* We may be accessing data outside the field, which means
1171 we can alias adjacent data. */
1172 if (GET_CODE (op0) == MEM)
1174 op0 = shallow_copy_rtx (op0);
1175 set_mem_alias_set (op0, 0);
1176 set_mem_expr (op0, 0);
1179 /* Extraction of a full-word or multi-word value from a structure
1180 in a register or aligned memory can be done with just a SUBREG.
1181 A subword value in the least significant part of a register
1182 can also be extracted with a SUBREG. For this, we need the
1183 byte offset of the value in op0. */
1185 byte_offset = bitpos / BITS_PER_UNIT + offset * UNITS_PER_WORD;
1187 /* If OP0 is a register, BITPOS must count within a word.
1188 But as we have it, it counts within whatever size OP0 now has.
1189 On a bigendian machine, these are not the same, so convert. */
1190 if (BYTES_BIG_ENDIAN
1191 && GET_CODE (op0) != MEM
1192 && unit > GET_MODE_BITSIZE (GET_MODE (op0)))
1193 bitpos += unit - GET_MODE_BITSIZE (GET_MODE (op0));
1195 /* ??? We currently assume TARGET is at least as big as BITSIZE.
1196 If that's wrong, the solution is to test for it and set TARGET to 0
1199 /* Only scalar integer modes can be converted via subregs. There is an
1200 additional problem for FP modes here in that they can have a precision
1201 which is different from the size. mode_for_size uses precision, but
1202 we want a mode based on the size, so we must avoid calling it for FP
1204 mode1 = (SCALAR_INT_MODE_P (tmode)
1205 ? mode_for_size (bitsize, GET_MODE_CLASS (tmode), 0)
1208 if (((bitsize >= BITS_PER_WORD && bitsize == GET_MODE_BITSIZE (mode)
1209 && bitpos % BITS_PER_WORD == 0)
1210 || (mode1 != BLKmode
1211 /* ??? The big endian test here is wrong. This is correct
1212 if the value is in a register, and if mode_for_size is not
1213 the same mode as op0. This causes us to get unnecessarily
1214 inefficient code from the Thumb port when -mbig-endian. */
1215 && (BYTES_BIG_ENDIAN
1216 ? bitpos + bitsize == BITS_PER_WORD
1218 && ((GET_CODE (op0) != MEM
1219 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
1220 GET_MODE_BITSIZE (GET_MODE (op0)))
1221 && GET_MODE_SIZE (mode1) != 0
1222 && byte_offset % GET_MODE_SIZE (mode1) == 0)
1223 || (GET_CODE (op0) == MEM
1224 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (op0))
1225 || (offset * BITS_PER_UNIT % bitsize == 0
1226 && MEM_ALIGN (op0) % bitsize == 0)))))
1228 if (mode1 != GET_MODE (op0))
1230 if (GET_CODE (op0) == SUBREG)
1232 if (GET_MODE (SUBREG_REG (op0)) == mode1
1233 || GET_MODE_CLASS (mode1) == MODE_INT
1234 || GET_MODE_CLASS (mode1) == MODE_PARTIAL_INT)
1235 op0 = SUBREG_REG (op0);
1237 /* Else we've got some float mode source being extracted into
1238 a different float mode destination -- this combination of
1239 subregs results in Severe Tire Damage. */
1240 goto no_subreg_mode_swap;
1242 if (GET_CODE (op0) == REG)
1243 op0 = gen_rtx_SUBREG (mode1, op0, byte_offset);
1245 op0 = adjust_address (op0, mode1, offset);
1248 return convert_to_mode (tmode, op0, unsignedp);
1251 no_subreg_mode_swap:
1253 /* Handle fields bigger than a word. */
1255 if (bitsize > BITS_PER_WORD)
1257 /* Here we transfer the words of the field
1258 in the order least significant first.
1259 This is because the most significant word is the one which may
1260 be less than full. */
1262 unsigned int nwords = (bitsize + (BITS_PER_WORD - 1)) / BITS_PER_WORD;
1265 if (target == 0 || GET_CODE (target) != REG)
1266 target = gen_reg_rtx (mode);
1268 /* Indicate for flow that the entire target reg is being set. */
1269 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
1271 for (i = 0; i < nwords; i++)
1273 /* If I is 0, use the low-order word in both field and target;
1274 if I is 1, use the next to lowest word; and so on. */
1275 /* Word number in TARGET to use. */
1276 unsigned int wordnum
1278 ? GET_MODE_SIZE (GET_MODE (target)) / UNITS_PER_WORD - i - 1
1280 /* Offset from start of field in OP0. */
1281 unsigned int bit_offset = (WORDS_BIG_ENDIAN
1282 ? MAX (0, ((int) bitsize - ((int) i + 1)
1283 * (int) BITS_PER_WORD))
1284 : (int) i * BITS_PER_WORD);
1285 rtx target_part = operand_subword (target, wordnum, 1, VOIDmode);
1287 = extract_bit_field (op0, MIN (BITS_PER_WORD,
1288 bitsize - i * BITS_PER_WORD),
1289 bitnum + bit_offset, 1, target_part, mode,
1290 word_mode, total_size);
1292 if (target_part == 0)
1295 if (result_part != target_part)
1296 emit_move_insn (target_part, result_part);
1301 /* Unless we've filled TARGET, the upper regs in a multi-reg value
1302 need to be zero'd out. */
1303 if (GET_MODE_SIZE (GET_MODE (target)) > nwords * UNITS_PER_WORD)
1305 unsigned int i, total_words;
1307 total_words = GET_MODE_SIZE (GET_MODE (target)) / UNITS_PER_WORD;
1308 for (i = nwords; i < total_words; i++)
1310 (operand_subword (target,
1311 WORDS_BIG_ENDIAN ? total_words - i - 1 : i,
1318 /* Signed bit field: sign-extend with two arithmetic shifts. */
1319 target = expand_shift (LSHIFT_EXPR, mode, target,
1320 build_int_2 (GET_MODE_BITSIZE (mode) - bitsize, 0),
1322 return expand_shift (RSHIFT_EXPR, mode, target,
1323 build_int_2 (GET_MODE_BITSIZE (mode) - bitsize, 0),
1327 /* From here on we know the desired field is smaller than a word. */
1329 /* Check if there is a correspondingly-sized integer field, so we can
1330 safely extract it as one size of integer, if necessary; then
1331 truncate or extend to the size that is wanted; then use SUBREGs or
1332 convert_to_mode to get one of the modes we really wanted. */
1334 int_mode = int_mode_for_mode (tmode);
1335 if (int_mode == BLKmode)
1336 int_mode = int_mode_for_mode (mode);
1337 if (int_mode == BLKmode)
1338 abort (); /* Should probably push op0 out to memory and then
1341 /* OFFSET is the number of words or bytes (UNIT says which)
1342 from STR_RTX to the first word or byte containing part of the field. */
1344 if (GET_CODE (op0) != MEM)
1347 || GET_MODE_SIZE (GET_MODE (op0)) > UNITS_PER_WORD)
1349 if (GET_CODE (op0) != REG)
1350 op0 = copy_to_reg (op0);
1351 op0 = gen_rtx_SUBREG (mode_for_size (BITS_PER_WORD, MODE_INT, 0),
1352 op0, (offset * UNITS_PER_WORD));
1357 op0 = protect_from_queue (str_rtx, 1);
1359 /* Now OFFSET is nonzero only for memory operands. */
1364 && (GET_MODE_BITSIZE (extzv_mode) >= bitsize)
1365 && ! ((GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG)
1366 && (bitsize + bitpos > GET_MODE_BITSIZE (extzv_mode))))
1368 unsigned HOST_WIDE_INT xbitpos = bitpos, xoffset = offset;
1369 rtx bitsize_rtx, bitpos_rtx;
1370 rtx last = get_last_insn ();
1372 rtx xtarget = target;
1373 rtx xspec_target = spec_target;
1374 rtx xspec_target_subreg = spec_target_subreg;
1376 enum machine_mode maxmode = mode_for_extraction (EP_extzv, 0);
1378 if (GET_CODE (xop0) == MEM)
1380 int save_volatile_ok = volatile_ok;
1383 /* Is the memory operand acceptable? */
1384 if (! ((*insn_data[(int) CODE_FOR_extzv].operand[1].predicate)
1385 (xop0, GET_MODE (xop0))))
1387 /* No, load into a reg and extract from there. */
1388 enum machine_mode bestmode;
1390 /* Get the mode to use for inserting into this field. If
1391 OP0 is BLKmode, get the smallest mode consistent with the
1392 alignment. If OP0 is a non-BLKmode object that is no
1393 wider than MAXMODE, use its mode. Otherwise, use the
1394 smallest mode containing the field. */
1396 if (GET_MODE (xop0) == BLKmode
1397 || (GET_MODE_SIZE (GET_MODE (op0))
1398 > GET_MODE_SIZE (maxmode)))
1399 bestmode = get_best_mode (bitsize, bitnum,
1400 MEM_ALIGN (xop0), maxmode,
1401 MEM_VOLATILE_P (xop0));
1403 bestmode = GET_MODE (xop0);
1405 if (bestmode == VOIDmode
1406 || (SLOW_UNALIGNED_ACCESS (bestmode, MEM_ALIGN (xop0))
1407 && GET_MODE_BITSIZE (bestmode) > MEM_ALIGN (xop0)))
1410 /* Compute offset as multiple of this unit,
1411 counting in bytes. */
1412 unit = GET_MODE_BITSIZE (bestmode);
1413 xoffset = (bitnum / unit) * GET_MODE_SIZE (bestmode);
1414 xbitpos = bitnum % unit;
1415 xop0 = adjust_address (xop0, bestmode, xoffset);
1417 /* Fetch it to a register in that size. */
1418 xop0 = force_reg (bestmode, xop0);
1420 /* XBITPOS counts within UNIT, which is what is expected. */
1423 /* Get ref to first byte containing part of the field. */
1424 xop0 = adjust_address (xop0, byte_mode, xoffset);
1426 volatile_ok = save_volatile_ok;
1429 /* If op0 is a register, we need it in MAXMODE (which is usually
1430 SImode). to make it acceptable to the format of extzv. */
1431 if (GET_CODE (xop0) == SUBREG && GET_MODE (xop0) != maxmode)
1433 if (GET_CODE (xop0) == REG && GET_MODE (xop0) != maxmode)
1434 xop0 = gen_rtx_SUBREG (maxmode, xop0, 0);
1436 /* On big-endian machines, we count bits from the most significant.
1437 If the bit field insn does not, we must invert. */
1438 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
1439 xbitpos = unit - bitsize - xbitpos;
1441 /* Now convert from counting within UNIT to counting in MAXMODE. */
1442 if (BITS_BIG_ENDIAN && GET_CODE (xop0) != MEM)
1443 xbitpos += GET_MODE_BITSIZE (maxmode) - unit;
1445 unit = GET_MODE_BITSIZE (maxmode);
1448 || (flag_force_mem && GET_CODE (xtarget) == MEM))
1449 xtarget = xspec_target = gen_reg_rtx (tmode);
1451 if (GET_MODE (xtarget) != maxmode)
1453 if (GET_CODE (xtarget) == REG)
1455 int wider = (GET_MODE_SIZE (maxmode)
1456 > GET_MODE_SIZE (GET_MODE (xtarget)));
1457 xtarget = gen_lowpart (maxmode, xtarget);
1459 xspec_target_subreg = xtarget;
1462 xtarget = gen_reg_rtx (maxmode);
1465 /* If this machine's extzv insists on a register target,
1466 make sure we have one. */
1467 if (! ((*insn_data[(int) CODE_FOR_extzv].operand[0].predicate)
1468 (xtarget, maxmode)))
1469 xtarget = gen_reg_rtx (maxmode);
1471 bitsize_rtx = GEN_INT (bitsize);
1472 bitpos_rtx = GEN_INT (xbitpos);
1474 pat = gen_extzv (protect_from_queue (xtarget, 1),
1475 xop0, bitsize_rtx, bitpos_rtx);
1480 spec_target = xspec_target;
1481 spec_target_subreg = xspec_target_subreg;
1485 delete_insns_since (last);
1486 target = extract_fixed_bit_field (int_mode, op0, offset, bitsize,
1492 target = extract_fixed_bit_field (int_mode, op0, offset, bitsize,
1498 && (GET_MODE_BITSIZE (extv_mode) >= bitsize)
1499 && ! ((GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG)
1500 && (bitsize + bitpos > GET_MODE_BITSIZE (extv_mode))))
1502 int xbitpos = bitpos, xoffset = offset;
1503 rtx bitsize_rtx, bitpos_rtx;
1504 rtx last = get_last_insn ();
1505 rtx xop0 = op0, xtarget = target;
1506 rtx xspec_target = spec_target;
1507 rtx xspec_target_subreg = spec_target_subreg;
1509 enum machine_mode maxmode = mode_for_extraction (EP_extv, 0);
1511 if (GET_CODE (xop0) == MEM)
1513 /* Is the memory operand acceptable? */
1514 if (! ((*insn_data[(int) CODE_FOR_extv].operand[1].predicate)
1515 (xop0, GET_MODE (xop0))))
1517 /* No, load into a reg and extract from there. */
1518 enum machine_mode bestmode;
1520 /* Get the mode to use for inserting into this field. If
1521 OP0 is BLKmode, get the smallest mode consistent with the
1522 alignment. If OP0 is a non-BLKmode object that is no
1523 wider than MAXMODE, use its mode. Otherwise, use the
1524 smallest mode containing the field. */
1526 if (GET_MODE (xop0) == BLKmode
1527 || (GET_MODE_SIZE (GET_MODE (op0))
1528 > GET_MODE_SIZE (maxmode)))
1529 bestmode = get_best_mode (bitsize, bitnum,
1530 MEM_ALIGN (xop0), maxmode,
1531 MEM_VOLATILE_P (xop0));
1533 bestmode = GET_MODE (xop0);
1535 if (bestmode == VOIDmode
1536 || (SLOW_UNALIGNED_ACCESS (bestmode, MEM_ALIGN (xop0))
1537 && GET_MODE_BITSIZE (bestmode) > MEM_ALIGN (xop0)))
1540 /* Compute offset as multiple of this unit,
1541 counting in bytes. */
1542 unit = GET_MODE_BITSIZE (bestmode);
1543 xoffset = (bitnum / unit) * GET_MODE_SIZE (bestmode);
1544 xbitpos = bitnum % unit;
1545 xop0 = adjust_address (xop0, bestmode, xoffset);
1547 /* Fetch it to a register in that size. */
1548 xop0 = force_reg (bestmode, xop0);
1550 /* XBITPOS counts within UNIT, which is what is expected. */
1553 /* Get ref to first byte containing part of the field. */
1554 xop0 = adjust_address (xop0, byte_mode, xoffset);
1557 /* If op0 is a register, we need it in MAXMODE (which is usually
1558 SImode) to make it acceptable to the format of extv. */
1559 if (GET_CODE (xop0) == SUBREG && GET_MODE (xop0) != maxmode)
1561 if (GET_CODE (xop0) == REG && GET_MODE (xop0) != maxmode)
1562 xop0 = gen_rtx_SUBREG (maxmode, xop0, 0);
1564 /* On big-endian machines, we count bits from the most significant.
1565 If the bit field insn does not, we must invert. */
1566 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
1567 xbitpos = unit - bitsize - xbitpos;
1569 /* XBITPOS counts within a size of UNIT.
1570 Adjust to count within a size of MAXMODE. */
1571 if (BITS_BIG_ENDIAN && GET_CODE (xop0) != MEM)
1572 xbitpos += (GET_MODE_BITSIZE (maxmode) - unit);
1574 unit = GET_MODE_BITSIZE (maxmode);
1577 || (flag_force_mem && GET_CODE (xtarget) == MEM))
1578 xtarget = xspec_target = gen_reg_rtx (tmode);
1580 if (GET_MODE (xtarget) != maxmode)
1582 if (GET_CODE (xtarget) == REG)
1584 int wider = (GET_MODE_SIZE (maxmode)
1585 > GET_MODE_SIZE (GET_MODE (xtarget)));
1586 xtarget = gen_lowpart (maxmode, xtarget);
1588 xspec_target_subreg = xtarget;
1591 xtarget = gen_reg_rtx (maxmode);
1594 /* If this machine's extv insists on a register target,
1595 make sure we have one. */
1596 if (! ((*insn_data[(int) CODE_FOR_extv].operand[0].predicate)
1597 (xtarget, maxmode)))
1598 xtarget = gen_reg_rtx (maxmode);
1600 bitsize_rtx = GEN_INT (bitsize);
1601 bitpos_rtx = GEN_INT (xbitpos);
1603 pat = gen_extv (protect_from_queue (xtarget, 1),
1604 xop0, bitsize_rtx, bitpos_rtx);
1609 spec_target = xspec_target;
1610 spec_target_subreg = xspec_target_subreg;
1614 delete_insns_since (last);
1615 target = extract_fixed_bit_field (int_mode, op0, offset, bitsize,
1621 target = extract_fixed_bit_field (int_mode, op0, offset, bitsize,
1624 if (target == spec_target)
1626 if (target == spec_target_subreg)
1628 if (GET_MODE (target) != tmode && GET_MODE (target) != mode)
1630 /* If the target mode is floating-point, first convert to the
1631 integer mode of that size and then access it as a floating-point
1632 value via a SUBREG. */
1633 if (GET_MODE_CLASS (tmode) != MODE_INT
1634 && GET_MODE_CLASS (tmode) != MODE_PARTIAL_INT)
1636 target = convert_to_mode (mode_for_size (GET_MODE_BITSIZE (tmode),
1639 return gen_lowpart (tmode, target);
1642 return convert_to_mode (tmode, target, unsignedp);
1647 /* Extract a bit field using shifts and boolean operations
1648 Returns an rtx to represent the value.
1649 OP0 addresses a register (word) or memory (byte).
1650 BITPOS says which bit within the word or byte the bit field starts in.
1651 OFFSET says how many bytes farther the bit field starts;
1652 it is 0 if OP0 is a register.
1653 BITSIZE says how many bits long the bit field is.
1654 (If OP0 is a register, it may be narrower than a full word,
1655 but BITPOS still counts within a full word,
1656 which is significant on bigendian machines.)
1658 UNSIGNEDP is nonzero for an unsigned bit field (don't sign-extend value).
1659 If TARGET is nonzero, attempts to store the value there
1660 and return TARGET, but this is not guaranteed.
1661 If TARGET is not used, create a pseudo-reg of mode TMODE for the value. */
1664 extract_fixed_bit_field (enum machine_mode tmode, rtx op0,
1665 unsigned HOST_WIDE_INT offset,
1666 unsigned HOST_WIDE_INT bitsize,
1667 unsigned HOST_WIDE_INT bitpos, rtx target,
1670 unsigned int total_bits = BITS_PER_WORD;
1671 enum machine_mode mode;
1673 if (GET_CODE (op0) == SUBREG || GET_CODE (op0) == REG)
1675 /* Special treatment for a bit field split across two registers. */
1676 if (bitsize + bitpos > BITS_PER_WORD)
1677 return extract_split_bit_field (op0, bitsize, bitpos, unsignedp);
1681 /* Get the proper mode to use for this field. We want a mode that
1682 includes the entire field. If such a mode would be larger than
1683 a word, we won't be doing the extraction the normal way. */
1685 mode = get_best_mode (bitsize, bitpos + offset * BITS_PER_UNIT,
1686 MEM_ALIGN (op0), word_mode, MEM_VOLATILE_P (op0));
1688 if (mode == VOIDmode)
1689 /* The only way this should occur is if the field spans word
1691 return extract_split_bit_field (op0, bitsize,
1692 bitpos + offset * BITS_PER_UNIT,
1695 total_bits = GET_MODE_BITSIZE (mode);
1697 /* Make sure bitpos is valid for the chosen mode. Adjust BITPOS to
1698 be in the range 0 to total_bits-1, and put any excess bytes in
1700 if (bitpos >= total_bits)
1702 offset += (bitpos / total_bits) * (total_bits / BITS_PER_UNIT);
1703 bitpos -= ((bitpos / total_bits) * (total_bits / BITS_PER_UNIT)
1707 /* Get ref to an aligned byte, halfword, or word containing the field.
1708 Adjust BITPOS to be position within a word,
1709 and OFFSET to be the offset of that word.
1710 Then alter OP0 to refer to that word. */
1711 bitpos += (offset % (total_bits / BITS_PER_UNIT)) * BITS_PER_UNIT;
1712 offset -= (offset % (total_bits / BITS_PER_UNIT));
1713 op0 = adjust_address (op0, mode, offset);
1716 mode = GET_MODE (op0);
1718 if (BYTES_BIG_ENDIAN)
1719 /* BITPOS is the distance between our msb and that of OP0.
1720 Convert it to the distance from the lsb. */
1721 bitpos = total_bits - bitsize - bitpos;
1723 /* Now BITPOS is always the distance between the field's lsb and that of OP0.
1724 We have reduced the big-endian case to the little-endian case. */
1730 /* If the field does not already start at the lsb,
1731 shift it so it does. */
1732 tree amount = build_int_2 (bitpos, 0);
1733 /* Maybe propagate the target for the shift. */
1734 /* But not if we will return it--could confuse integrate.c. */
1735 rtx subtarget = (target != 0 && GET_CODE (target) == REG ? target : 0);
1736 if (tmode != mode) subtarget = 0;
1737 op0 = expand_shift (RSHIFT_EXPR, mode, op0, amount, subtarget, 1);
1739 /* Convert the value to the desired mode. */
1741 op0 = convert_to_mode (tmode, op0, 1);
1743 /* Unless the msb of the field used to be the msb when we shifted,
1744 mask out the upper bits. */
1746 if (GET_MODE_BITSIZE (mode) != bitpos + bitsize)
1747 return expand_binop (GET_MODE (op0), and_optab, op0,
1748 mask_rtx (GET_MODE (op0), 0, bitsize, 0),
1749 target, 1, OPTAB_LIB_WIDEN);
1753 /* To extract a signed bit-field, first shift its msb to the msb of the word,
1754 then arithmetic-shift its lsb to the lsb of the word. */
1755 op0 = force_reg (mode, op0);
1759 /* Find the narrowest integer mode that contains the field. */
1761 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1762 mode = GET_MODE_WIDER_MODE (mode))
1763 if (GET_MODE_BITSIZE (mode) >= bitsize + bitpos)
1765 op0 = convert_to_mode (mode, op0, 0);
1769 if (GET_MODE_BITSIZE (mode) != (bitsize + bitpos))
1772 = build_int_2 (GET_MODE_BITSIZE (mode) - (bitsize + bitpos), 0);
1773 /* Maybe propagate the target for the shift. */
1774 rtx subtarget = (target != 0 && GET_CODE (target) == REG ? target : 0);
1775 op0 = expand_shift (LSHIFT_EXPR, mode, op0, amount, subtarget, 1);
1778 return expand_shift (RSHIFT_EXPR, mode, op0,
1779 build_int_2 (GET_MODE_BITSIZE (mode) - bitsize, 0),
1783 /* Return a constant integer (CONST_INT or CONST_DOUBLE) mask value
1784 of mode MODE with BITSIZE ones followed by BITPOS zeros, or the
1785 complement of that if COMPLEMENT. The mask is truncated if
1786 necessary to the width of mode MODE. The mask is zero-extended if
1787 BITSIZE+BITPOS is too small for MODE. */
1790 mask_rtx (enum machine_mode mode, int bitpos, int bitsize, int complement)
1792 HOST_WIDE_INT masklow, maskhigh;
1796 else if (bitpos < HOST_BITS_PER_WIDE_INT)
1797 masklow = (HOST_WIDE_INT) -1 << bitpos;
1801 if (bitpos + bitsize < HOST_BITS_PER_WIDE_INT)
1802 masklow &= ((unsigned HOST_WIDE_INT) -1
1803 >> (HOST_BITS_PER_WIDE_INT - bitpos - bitsize));
1805 if (bitpos <= HOST_BITS_PER_WIDE_INT)
1808 maskhigh = (HOST_WIDE_INT) -1 << (bitpos - HOST_BITS_PER_WIDE_INT);
1812 else if (bitpos + bitsize > HOST_BITS_PER_WIDE_INT)
1813 maskhigh &= ((unsigned HOST_WIDE_INT) -1
1814 >> (2 * HOST_BITS_PER_WIDE_INT - bitpos - bitsize));
1820 maskhigh = ~maskhigh;
1824 return immed_double_const (masklow, maskhigh, mode);
1827 /* Return a constant integer (CONST_INT or CONST_DOUBLE) rtx with the value
1828 VALUE truncated to BITSIZE bits and then shifted left BITPOS bits. */
1831 lshift_value (enum machine_mode mode, rtx value, int bitpos, int bitsize)
1833 unsigned HOST_WIDE_INT v = INTVAL (value);
1834 HOST_WIDE_INT low, high;
1836 if (bitsize < HOST_BITS_PER_WIDE_INT)
1837 v &= ~((HOST_WIDE_INT) -1 << bitsize);
1839 if (bitpos < HOST_BITS_PER_WIDE_INT)
1842 high = (bitpos > 0 ? (v >> (HOST_BITS_PER_WIDE_INT - bitpos)) : 0);
1847 high = v << (bitpos - HOST_BITS_PER_WIDE_INT);
1850 return immed_double_const (low, high, mode);
1853 /* Extract a bit field that is split across two words
1854 and return an RTX for the result.
1856 OP0 is the REG, SUBREG or MEM rtx for the first of the two words.
1857 BITSIZE is the field width; BITPOS, position of its first bit, in the word.
1858 UNSIGNEDP is 1 if should zero-extend the contents; else sign-extend. */
1861 extract_split_bit_field (rtx op0, unsigned HOST_WIDE_INT bitsize,
1862 unsigned HOST_WIDE_INT bitpos, int unsignedp)
1865 unsigned int bitsdone = 0;
1866 rtx result = NULL_RTX;
1869 /* Make sure UNIT isn't larger than BITS_PER_WORD, we can only handle that
1871 if (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG)
1872 unit = BITS_PER_WORD;
1874 unit = MIN (MEM_ALIGN (op0), BITS_PER_WORD);
1876 while (bitsdone < bitsize)
1878 unsigned HOST_WIDE_INT thissize;
1880 unsigned HOST_WIDE_INT thispos;
1881 unsigned HOST_WIDE_INT offset;
1883 offset = (bitpos + bitsdone) / unit;
1884 thispos = (bitpos + bitsdone) % unit;
1886 /* THISSIZE must not overrun a word boundary. Otherwise,
1887 extract_fixed_bit_field will call us again, and we will mutually
1889 thissize = MIN (bitsize - bitsdone, BITS_PER_WORD);
1890 thissize = MIN (thissize, unit - thispos);
1892 /* If OP0 is a register, then handle OFFSET here.
1894 When handling multiword bitfields, extract_bit_field may pass
1895 down a word_mode SUBREG of a larger REG for a bitfield that actually
1896 crosses a word boundary. Thus, for a SUBREG, we must find
1897 the current word starting from the base register. */
1898 if (GET_CODE (op0) == SUBREG)
1900 int word_offset = (SUBREG_BYTE (op0) / UNITS_PER_WORD) + offset;
1901 word = operand_subword_force (SUBREG_REG (op0), word_offset,
1902 GET_MODE (SUBREG_REG (op0)));
1905 else if (GET_CODE (op0) == REG)
1907 word = operand_subword_force (op0, offset, GET_MODE (op0));
1913 /* Extract the parts in bit-counting order,
1914 whose meaning is determined by BYTES_PER_UNIT.
1915 OFFSET is in UNITs, and UNIT is in bits.
1916 extract_fixed_bit_field wants offset in bytes. */
1917 part = extract_fixed_bit_field (word_mode, word,
1918 offset * unit / BITS_PER_UNIT,
1919 thissize, thispos, 0, 1);
1920 bitsdone += thissize;
1922 /* Shift this part into place for the result. */
1923 if (BYTES_BIG_ENDIAN)
1925 if (bitsize != bitsdone)
1926 part = expand_shift (LSHIFT_EXPR, word_mode, part,
1927 build_int_2 (bitsize - bitsdone, 0), 0, 1);
1931 if (bitsdone != thissize)
1932 part = expand_shift (LSHIFT_EXPR, word_mode, part,
1933 build_int_2 (bitsdone - thissize, 0), 0, 1);
1939 /* Combine the parts with bitwise or. This works
1940 because we extracted each part as an unsigned bit field. */
1941 result = expand_binop (word_mode, ior_optab, part, result, NULL_RTX, 1,
1947 /* Unsigned bit field: we are done. */
1950 /* Signed bit field: sign-extend with two arithmetic shifts. */
1951 result = expand_shift (LSHIFT_EXPR, word_mode, result,
1952 build_int_2 (BITS_PER_WORD - bitsize, 0),
1954 return expand_shift (RSHIFT_EXPR, word_mode, result,
1955 build_int_2 (BITS_PER_WORD - bitsize, 0), NULL_RTX, 0);
1958 /* Add INC into TARGET. */
1961 expand_inc (rtx target, rtx inc)
1963 rtx value = expand_binop (GET_MODE (target), add_optab,
1965 target, 0, OPTAB_LIB_WIDEN);
1966 if (value != target)
1967 emit_move_insn (target, value);
1970 /* Subtract DEC from TARGET. */
1973 expand_dec (rtx target, rtx dec)
1975 rtx value = expand_binop (GET_MODE (target), sub_optab,
1977 target, 0, OPTAB_LIB_WIDEN);
1978 if (value != target)
1979 emit_move_insn (target, value);
1982 /* Output a shift instruction for expression code CODE,
1983 with SHIFTED being the rtx for the value to shift,
1984 and AMOUNT the tree for the amount to shift by.
1985 Store the result in the rtx TARGET, if that is convenient.
1986 If UNSIGNEDP is nonzero, do a logical shift; otherwise, arithmetic.
1987 Return the rtx for where the value is. */
1990 expand_shift (enum tree_code code, enum machine_mode mode, rtx shifted,
1991 tree amount, rtx target, int unsignedp)
1994 int left = (code == LSHIFT_EXPR || code == LROTATE_EXPR);
1995 int rotate = (code == LROTATE_EXPR || code == RROTATE_EXPR);
1998 /* Previously detected shift-counts computed by NEGATE_EXPR
1999 and shifted in the other direction; but that does not work
2002 op1 = expand_expr (amount, NULL_RTX, VOIDmode, 0);
2004 if (SHIFT_COUNT_TRUNCATED)
2006 if (GET_CODE (op1) == CONST_INT
2007 && ((unsigned HOST_WIDE_INT) INTVAL (op1) >=
2008 (unsigned HOST_WIDE_INT) GET_MODE_BITSIZE (mode)))
2009 op1 = GEN_INT ((unsigned HOST_WIDE_INT) INTVAL (op1)
2010 % GET_MODE_BITSIZE (mode));
2011 else if (GET_CODE (op1) == SUBREG
2012 && subreg_lowpart_p (op1))
2013 op1 = SUBREG_REG (op1);
2016 if (op1 == const0_rtx)
2019 for (try = 0; temp == 0 && try < 3; try++)
2021 enum optab_methods methods;
2024 methods = OPTAB_DIRECT;
2026 methods = OPTAB_WIDEN;
2028 methods = OPTAB_LIB_WIDEN;
2032 /* Widening does not work for rotation. */
2033 if (methods == OPTAB_WIDEN)
2035 else if (methods == OPTAB_LIB_WIDEN)
2037 /* If we have been unable to open-code this by a rotation,
2038 do it as the IOR of two shifts. I.e., to rotate A
2039 by N bits, compute (A << N) | ((unsigned) A >> (C - N))
2040 where C is the bitsize of A.
2042 It is theoretically possible that the target machine might
2043 not be able to perform either shift and hence we would
2044 be making two libcalls rather than just the one for the
2045 shift (similarly if IOR could not be done). We will allow
2046 this extremely unlikely lossage to avoid complicating the
2049 rtx subtarget = target == shifted ? 0 : target;
2051 tree type = TREE_TYPE (amount);
2052 tree new_amount = make_tree (type, op1);
2054 = fold (build (MINUS_EXPR, type,
2056 build_int_2 (GET_MODE_BITSIZE (mode),
2060 shifted = force_reg (mode, shifted);
2062 temp = expand_shift (left ? LSHIFT_EXPR : RSHIFT_EXPR,
2063 mode, shifted, new_amount, subtarget, 1);
2064 temp1 = expand_shift (left ? RSHIFT_EXPR : LSHIFT_EXPR,
2065 mode, shifted, other_amount, 0, 1);
2066 return expand_binop (mode, ior_optab, temp, temp1, target,
2067 unsignedp, methods);
2070 temp = expand_binop (mode,
2071 left ? rotl_optab : rotr_optab,
2072 shifted, op1, target, unsignedp, methods);
2074 /* If we don't have the rotate, but we are rotating by a constant
2075 that is in range, try a rotate in the opposite direction. */
2077 if (temp == 0 && GET_CODE (op1) == CONST_INT
2079 && (unsigned int) INTVAL (op1) < GET_MODE_BITSIZE (mode))
2080 temp = expand_binop (mode,
2081 left ? rotr_optab : rotl_optab,
2083 GEN_INT (GET_MODE_BITSIZE (mode)
2085 target, unsignedp, methods);
2088 temp = expand_binop (mode,
2089 left ? ashl_optab : lshr_optab,
2090 shifted, op1, target, unsignedp, methods);
2092 /* Do arithmetic shifts.
2093 Also, if we are going to widen the operand, we can just as well
2094 use an arithmetic right-shift instead of a logical one. */
2095 if (temp == 0 && ! rotate
2096 && (! unsignedp || (! left && methods == OPTAB_WIDEN)))
2098 enum optab_methods methods1 = methods;
2100 /* If trying to widen a log shift to an arithmetic shift,
2101 don't accept an arithmetic shift of the same size. */
2103 methods1 = OPTAB_MUST_WIDEN;
2105 /* Arithmetic shift */
2107 temp = expand_binop (mode,
2108 left ? ashl_optab : ashr_optab,
2109 shifted, op1, target, unsignedp, methods1);
2112 /* We used to try extzv here for logical right shifts, but that was
2113 only useful for one machine, the VAX, and caused poor code
2114 generation there for lshrdi3, so the code was deleted and a
2115 define_expand for lshrsi3 was added to vax.md. */
2123 enum alg_code { alg_zero, alg_m, alg_shift,
2124 alg_add_t_m2, alg_sub_t_m2,
2125 alg_add_factor, alg_sub_factor,
2126 alg_add_t2_m, alg_sub_t2_m,
2127 alg_add, alg_subtract, alg_factor, alg_shiftop };
2129 /* This structure records a sequence of operations.
2130 `ops' is the number of operations recorded.
2131 `cost' is their total cost.
2132 The operations are stored in `op' and the corresponding
2133 logarithms of the integer coefficients in `log'.
2135 These are the operations:
2136 alg_zero total := 0;
2137 alg_m total := multiplicand;
2138 alg_shift total := total * coeff
2139 alg_add_t_m2 total := total + multiplicand * coeff;
2140 alg_sub_t_m2 total := total - multiplicand * coeff;
2141 alg_add_factor total := total * coeff + total;
2142 alg_sub_factor total := total * coeff - total;
2143 alg_add_t2_m total := total * coeff + multiplicand;
2144 alg_sub_t2_m total := total * coeff - multiplicand;
2146 The first operand must be either alg_zero or alg_m. */
2152 /* The size of the OP and LOG fields are not directly related to the
2153 word size, but the worst-case algorithms will be if we have few
2154 consecutive ones or zeros, i.e., a multiplicand like 10101010101...
2155 In that case we will generate shift-by-2, add, shift-by-2, add,...,
2156 in total wordsize operations. */
2157 enum alg_code op[MAX_BITS_PER_WORD];
2158 char log[MAX_BITS_PER_WORD];
2161 /* Indicates the type of fixup needed after a constant multiplication.
2162 BASIC_VARIANT means no fixup is needed, NEGATE_VARIANT means that
2163 the result should be negated, and ADD_VARIANT means that the
2164 multiplicand should be added to the result. */
2165 enum mult_variant {basic_variant, negate_variant, add_variant};
2167 static void synth_mult (struct algorithm *, unsigned HOST_WIDE_INT,
2168 int, enum machine_mode mode);
2169 static bool choose_mult_variant (enum machine_mode, HOST_WIDE_INT,
2170 struct algorithm *, enum mult_variant *, int);
2171 static rtx expand_mult_const (enum machine_mode, rtx, HOST_WIDE_INT, rtx,
2172 const struct algorithm *, enum mult_variant);
2173 static unsigned HOST_WIDE_INT choose_multiplier (unsigned HOST_WIDE_INT, int,
2174 int, unsigned HOST_WIDE_INT *,
2176 static unsigned HOST_WIDE_INT invert_mod2n (unsigned HOST_WIDE_INT, int);
2177 static rtx extract_high_half (enum machine_mode, rtx);
2178 static rtx expand_mult_highpart_optab (enum machine_mode, rtx, rtx, rtx,
2180 /* Compute and return the best algorithm for multiplying by T.
2181 The algorithm must cost less than cost_limit
2182 If retval.cost >= COST_LIMIT, no algorithm was found and all
2183 other field of the returned struct are undefined.
2184 MODE is the machine mode of the multiplication. */
2187 synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t,
2188 int cost_limit, enum machine_mode mode)
2191 struct algorithm *alg_in, *best_alg;
2193 unsigned HOST_WIDE_INT q;
2194 int maxm = MIN (BITS_PER_WORD, GET_MODE_BITSIZE (mode));
2196 /* Indicate that no algorithm is yet found. If no algorithm
2197 is found, this value will be returned and indicate failure. */
2198 alg_out->cost = cost_limit;
2200 if (cost_limit <= 0)
2203 /* Restrict the bits of "t" to the multiplication's mode. */
2204 t &= GET_MODE_MASK (mode);
2206 /* t == 1 can be done in zero cost. */
2211 alg_out->op[0] = alg_m;
2215 /* t == 0 sometimes has a cost. If it does and it exceeds our limit,
2219 if (zero_cost >= cost_limit)
2224 alg_out->cost = zero_cost;
2225 alg_out->op[0] = alg_zero;
2230 /* We'll be needing a couple extra algorithm structures now. */
2232 alg_in = alloca (sizeof (struct algorithm));
2233 best_alg = alloca (sizeof (struct algorithm));
2235 /* If we have a group of zero bits at the low-order part of T, try
2236 multiplying by the remaining bits and then doing a shift. */
2240 m = floor_log2 (t & -t); /* m = number of low zero bits */
2244 cost = shift_cost[mode][m];
2245 synth_mult (alg_in, q, cost_limit - cost, mode);
2247 cost += alg_in->cost;
2248 if (cost < cost_limit)
2250 struct algorithm *x;
2251 x = alg_in, alg_in = best_alg, best_alg = x;
2252 best_alg->log[best_alg->ops] = m;
2253 best_alg->op[best_alg->ops] = alg_shift;
2259 /* If we have an odd number, add or subtract one. */
2262 unsigned HOST_WIDE_INT w;
2264 for (w = 1; (w & t) != 0; w <<= 1)
2266 /* If T was -1, then W will be zero after the loop. This is another
2267 case where T ends with ...111. Handling this with (T + 1) and
2268 subtract 1 produces slightly better code and results in algorithm
2269 selection much faster than treating it like the ...0111 case
2273 /* Reject the case where t is 3.
2274 Thus we prefer addition in that case. */
2277 /* T ends with ...111. Multiply by (T + 1) and subtract 1. */
2279 cost = add_cost[mode];
2280 synth_mult (alg_in, t + 1, cost_limit - cost, mode);
2282 cost += alg_in->cost;
2283 if (cost < cost_limit)
2285 struct algorithm *x;
2286 x = alg_in, alg_in = best_alg, best_alg = x;
2287 best_alg->log[best_alg->ops] = 0;
2288 best_alg->op[best_alg->ops] = alg_sub_t_m2;
2294 /* T ends with ...01 or ...011. Multiply by (T - 1) and add 1. */
2296 cost = add_cost[mode];
2297 synth_mult (alg_in, t - 1, cost_limit - cost, mode);
2299 cost += alg_in->cost;
2300 if (cost < cost_limit)
2302 struct algorithm *x;
2303 x = alg_in, alg_in = best_alg, best_alg = x;
2304 best_alg->log[best_alg->ops] = 0;
2305 best_alg->op[best_alg->ops] = alg_add_t_m2;
2311 /* Look for factors of t of the form
2312 t = q(2**m +- 1), 2 <= m <= floor(log2(t - 1)).
2313 If we find such a factor, we can multiply by t using an algorithm that
2314 multiplies by q, shift the result by m and add/subtract it to itself.
2316 We search for large factors first and loop down, even if large factors
2317 are less probable than small; if we find a large factor we will find a
2318 good sequence quickly, and therefore be able to prune (by decreasing
2319 COST_LIMIT) the search. */
2321 for (m = floor_log2 (t - 1); m >= 2; m--)
2323 unsigned HOST_WIDE_INT d;
2325 d = ((unsigned HOST_WIDE_INT) 1 << m) + 1;
2326 if (t % d == 0 && t > d && m < maxm)
2328 cost = add_cost[mode] + shift_cost[mode][m];
2329 if (shiftadd_cost[mode][m] < cost)
2330 cost = shiftadd_cost[mode][m];
2331 synth_mult (alg_in, t / d, cost_limit - cost, mode);
2333 cost += alg_in->cost;
2334 if (cost < cost_limit)
2336 struct algorithm *x;
2337 x = alg_in, alg_in = best_alg, best_alg = x;
2338 best_alg->log[best_alg->ops] = m;
2339 best_alg->op[best_alg->ops] = alg_add_factor;
2342 /* Other factors will have been taken care of in the recursion. */
2346 d = ((unsigned HOST_WIDE_INT) 1 << m) - 1;
2347 if (t % d == 0 && t > d && m < maxm)
2349 cost = add_cost[mode] + shift_cost[mode][m];
2350 if (shiftsub_cost[mode][m] < cost)
2351 cost = shiftsub_cost[mode][m];
2352 synth_mult (alg_in, t / d, cost_limit - cost, mode);
2354 cost += alg_in->cost;
2355 if (cost < cost_limit)
2357 struct algorithm *x;
2358 x = alg_in, alg_in = best_alg, best_alg = x;
2359 best_alg->log[best_alg->ops] = m;
2360 best_alg->op[best_alg->ops] = alg_sub_factor;
2367 /* Try shift-and-add (load effective address) instructions,
2368 i.e. do a*3, a*5, a*9. */
2374 if (m >= 0 && m < maxm)
2376 cost = shiftadd_cost[mode][m];
2377 synth_mult (alg_in, (t - 1) >> m, cost_limit - cost, mode);
2379 cost += alg_in->cost;
2380 if (cost < cost_limit)
2382 struct algorithm *x;
2383 x = alg_in, alg_in = best_alg, best_alg = x;
2384 best_alg->log[best_alg->ops] = m;
2385 best_alg->op[best_alg->ops] = alg_add_t2_m;
2393 if (m >= 0 && m < maxm)
2395 cost = shiftsub_cost[mode][m];
2396 synth_mult (alg_in, (t + 1) >> m, cost_limit - cost, mode);
2398 cost += alg_in->cost;
2399 if (cost < cost_limit)
2401 struct algorithm *x;
2402 x = alg_in, alg_in = best_alg, best_alg = x;
2403 best_alg->log[best_alg->ops] = m;
2404 best_alg->op[best_alg->ops] = alg_sub_t2_m;
2410 /* If cost_limit has not decreased since we stored it in alg_out->cost,
2411 we have not found any algorithm. */
2412 if (cost_limit == alg_out->cost)
2415 /* If we are getting a too long sequence for `struct algorithm'
2416 to record, make this search fail. */
2417 if (best_alg->ops == MAX_BITS_PER_WORD)
2420 /* Copy the algorithm from temporary space to the space at alg_out.
2421 We avoid using structure assignment because the majority of
2422 best_alg is normally undefined, and this is a critical function. */
2423 alg_out->ops = best_alg->ops + 1;
2424 alg_out->cost = cost_limit;
2425 memcpy (alg_out->op, best_alg->op,
2426 alg_out->ops * sizeof *alg_out->op);
2427 memcpy (alg_out->log, best_alg->log,
2428 alg_out->ops * sizeof *alg_out->log);
2431 /* Find the cheapest way of multiplying a value of mode MODE by VAL.
2432 Try three variations:
2434 - a shift/add sequence based on VAL itself
2435 - a shift/add sequence based on -VAL, followed by a negation
2436 - a shift/add sequence based on VAL - 1, followed by an addition.
2438 Return true if the cheapest of these cost less than MULT_COST,
2439 describing the algorithm in *ALG and final fixup in *VARIANT. */
2442 choose_mult_variant (enum machine_mode mode, HOST_WIDE_INT val,
2443 struct algorithm *alg, enum mult_variant *variant,
2446 struct algorithm alg2;
2448 *variant = basic_variant;
2449 synth_mult (alg, val, mult_cost, mode);
2451 /* This works only if the inverted value actually fits in an
2453 if (HOST_BITS_PER_INT >= GET_MODE_BITSIZE (mode))
2455 synth_mult (&alg2, -val, MIN (alg->cost, mult_cost) - neg_cost[mode],
2457 alg2.cost += neg_cost[mode];
2458 if (alg2.cost < alg->cost)
2459 *alg = alg2, *variant = negate_variant;
2462 /* This proves very useful for division-by-constant. */
2463 synth_mult (&alg2, val - 1, MIN (alg->cost, mult_cost) - add_cost[mode],
2465 alg2.cost += add_cost[mode];
2466 if (alg2.cost < alg->cost)
2467 *alg = alg2, *variant = add_variant;
2469 return alg->cost < mult_cost;
2472 /* A subroutine of expand_mult, used for constant multiplications.
2473 Multiply OP0 by VAL in mode MODE, storing the result in TARGET if
2474 convenient. Use the shift/add sequence described by ALG and apply
2475 the final fixup specified by VARIANT. */
2478 expand_mult_const (enum machine_mode mode, rtx op0, HOST_WIDE_INT val,
2479 rtx target, const struct algorithm *alg,
2480 enum mult_variant variant)
2482 HOST_WIDE_INT val_so_far;
2483 rtx insn, accum, tem;
2485 enum machine_mode nmode;
2487 /* op0 must be register to make mult_cost match the precomputed
2488 shiftadd_cost array. */
2489 op0 = protect_from_queue (op0, 0);
2491 /* Avoid referencing memory over and over.
2492 For speed, but also for correctness when mem is volatile. */
2493 if (GET_CODE (op0) == MEM)
2494 op0 = force_reg (mode, op0);
2496 /* ACCUM starts out either as OP0 or as a zero, depending on
2497 the first operation. */
2499 if (alg->op[0] == alg_zero)
2501 accum = copy_to_mode_reg (mode, const0_rtx);
2504 else if (alg->op[0] == alg_m)
2506 accum = copy_to_mode_reg (mode, op0);
2512 for (opno = 1; opno < alg->ops; opno++)
2514 int log = alg->log[opno];
2515 int preserve = preserve_subexpressions_p ();
2516 rtx shift_subtarget = preserve ? 0 : accum;
2518 = (opno == alg->ops - 1 && target != 0 && variant != add_variant
2521 rtx accum_target = preserve ? 0 : accum;
2523 switch (alg->op[opno])
2526 accum = expand_shift (LSHIFT_EXPR, mode, accum,
2527 build_int_2 (log, 0), NULL_RTX, 0);
2532 tem = expand_shift (LSHIFT_EXPR, mode, op0,
2533 build_int_2 (log, 0), NULL_RTX, 0);
2534 accum = force_operand (gen_rtx_PLUS (mode, accum, tem),
2535 add_target ? add_target : accum_target);
2536 val_so_far += (HOST_WIDE_INT) 1 << log;
2540 tem = expand_shift (LSHIFT_EXPR, mode, op0,
2541 build_int_2 (log, 0), NULL_RTX, 0);
2542 accum = force_operand (gen_rtx_MINUS (mode, accum, tem),
2543 add_target ? add_target : accum_target);
2544 val_so_far -= (HOST_WIDE_INT) 1 << log;
2548 accum = expand_shift (LSHIFT_EXPR, mode, accum,
2549 build_int_2 (log, 0), shift_subtarget,
2551 accum = force_operand (gen_rtx_PLUS (mode, accum, op0),
2552 add_target ? add_target : accum_target);
2553 val_so_far = (val_so_far << log) + 1;
2557 accum = expand_shift (LSHIFT_EXPR, mode, accum,
2558 build_int_2 (log, 0), shift_subtarget, 0);
2559 accum = force_operand (gen_rtx_MINUS (mode, accum, op0),
2560 add_target ? add_target : accum_target);
2561 val_so_far = (val_so_far << log) - 1;
2564 case alg_add_factor:
2565 tem = expand_shift (LSHIFT_EXPR, mode, accum,
2566 build_int_2 (log, 0), NULL_RTX, 0);
2567 accum = force_operand (gen_rtx_PLUS (mode, accum, tem),
2568 add_target ? add_target : accum_target);
2569 val_so_far += val_so_far << log;
2572 case alg_sub_factor:
2573 tem = expand_shift (LSHIFT_EXPR, mode, accum,
2574 build_int_2 (log, 0), NULL_RTX, 0);
2575 accum = force_operand (gen_rtx_MINUS (mode, tem, accum),
2576 (add_target ? add_target
2577 : preserve ? 0 : tem));
2578 val_so_far = (val_so_far << log) - val_so_far;
2585 /* Write a REG_EQUAL note on the last insn so that we can cse
2586 multiplication sequences. Note that if ACCUM is a SUBREG,
2587 we've set the inner register and must properly indicate
2590 tem = op0, nmode = mode;
2591 if (GET_CODE (accum) == SUBREG)
2593 nmode = GET_MODE (SUBREG_REG (accum));
2594 tem = gen_lowpart (nmode, op0);
2597 insn = get_last_insn ();
2598 set_unique_reg_note (insn, REG_EQUAL,
2599 gen_rtx_MULT (nmode, tem, GEN_INT (val_so_far)));
2602 if (variant == negate_variant)
2604 val_so_far = -val_so_far;
2605 accum = expand_unop (mode, neg_optab, accum, target, 0);
2607 else if (variant == add_variant)
2609 val_so_far = val_so_far + 1;
2610 accum = force_operand (gen_rtx_PLUS (mode, accum, op0), target);
2613 if (val != val_so_far)
2619 /* Perform a multiplication and return an rtx for the result.
2620 MODE is mode of value; OP0 and OP1 are what to multiply (rtx's);
2621 TARGET is a suggestion for where to store the result (an rtx).
2623 We check specially for a constant integer as OP1.
2624 If you want this check for OP0 as well, then before calling
2625 you should swap the two operands if OP0 would be constant. */
2628 expand_mult (enum machine_mode mode, rtx op0, rtx op1, rtx target,
2631 rtx const_op1 = op1;
2632 enum mult_variant variant;
2633 struct algorithm algorithm;
2635 /* synth_mult does an `unsigned int' multiply. As long as the mode is
2636 less than or equal in size to `unsigned int' this doesn't matter.
2637 If the mode is larger than `unsigned int', then synth_mult works only
2638 if the constant value exactly fits in an `unsigned int' without any
2639 truncation. This means that multiplying by negative values does
2640 not work; results are off by 2^32 on a 32 bit machine. */
2642 /* If we are multiplying in DImode, it may still be a win
2643 to try to work with shifts and adds. */
2644 if (GET_CODE (op1) == CONST_DOUBLE
2645 && GET_MODE_CLASS (GET_MODE (op1)) == MODE_INT
2646 && HOST_BITS_PER_INT >= BITS_PER_WORD
2647 && CONST_DOUBLE_HIGH (op1) == 0)
2648 const_op1 = GEN_INT (CONST_DOUBLE_LOW (op1));
2649 else if (HOST_BITS_PER_INT < GET_MODE_BITSIZE (mode)
2650 && GET_CODE (op1) == CONST_INT
2651 && INTVAL (op1) < 0)
2654 /* We used to test optimize here, on the grounds that it's better to
2655 produce a smaller program when -O is not used.
2656 But this causes such a terrible slowdown sometimes
2657 that it seems better to use synth_mult always. */
2659 if (const_op1 && GET_CODE (const_op1) == CONST_INT
2660 && (unsignedp || !flag_trapv))
2662 int mult_cost = rtx_cost (gen_rtx_MULT (mode, op0, op1), SET);
2663 mult_cost = MIN (12 * add_cost[mode], mult_cost);
2665 if (choose_mult_variant (mode, INTVAL (const_op1), &algorithm, &variant,
2667 return expand_mult_const (mode, op0, INTVAL (const_op1), target,
2668 &algorithm, variant);
2671 if (GET_CODE (op0) == CONST_DOUBLE)
2678 /* Expand x*2.0 as x+x. */
2679 if (GET_CODE (op1) == CONST_DOUBLE
2680 && GET_MODE_CLASS (mode) == MODE_FLOAT)
2683 REAL_VALUE_FROM_CONST_DOUBLE (d, op1);
2685 if (REAL_VALUES_EQUAL (d, dconst2))
2687 op0 = force_reg (GET_MODE (op0), op0);
2688 return expand_binop (mode, add_optab, op0, op0,
2689 target, unsignedp, OPTAB_LIB_WIDEN);
2693 /* This used to use umul_optab if unsigned, but for non-widening multiply
2694 there is no difference between signed and unsigned. */
2695 op0 = expand_binop (mode,
2697 && flag_trapv && (GET_MODE_CLASS(mode) == MODE_INT)
2698 ? smulv_optab : smul_optab,
2699 op0, op1, target, unsignedp, OPTAB_LIB_WIDEN);
2705 /* Return the smallest n such that 2**n >= X. */
2708 ceil_log2 (unsigned HOST_WIDE_INT x)
2710 return floor_log2 (x - 1) + 1;
2713 /* Choose a minimal N + 1 bit approximation to 1/D that can be used to
2714 replace division by D, and put the least significant N bits of the result
2715 in *MULTIPLIER_PTR and return the most significant bit.
2717 The width of operations is N (should be <= HOST_BITS_PER_WIDE_INT), the
2718 needed precision is in PRECISION (should be <= N).
2720 PRECISION should be as small as possible so this function can choose
2721 multiplier more freely.
2723 The rounded-up logarithm of D is placed in *lgup_ptr. A shift count that
2724 is to be used for a final right shift is placed in *POST_SHIFT_PTR.
2726 Using this function, x/D will be equal to (x * m) >> (*POST_SHIFT_PTR),
2727 where m is the full HOST_BITS_PER_WIDE_INT + 1 bit multiplier. */
2730 unsigned HOST_WIDE_INT
2731 choose_multiplier (unsigned HOST_WIDE_INT d, int n, int precision,
2732 unsigned HOST_WIDE_INT *multiplier_ptr,
2733 int *post_shift_ptr, int *lgup_ptr)
2735 HOST_WIDE_INT mhigh_hi, mlow_hi;
2736 unsigned HOST_WIDE_INT mhigh_lo, mlow_lo;
2737 int lgup, post_shift;
2739 unsigned HOST_WIDE_INT nl, dummy1;
2740 HOST_WIDE_INT nh, dummy2;
2742 /* lgup = ceil(log2(divisor)); */
2743 lgup = ceil_log2 (d);
2749 pow2 = n + lgup - precision;
2751 if (pow == 2 * HOST_BITS_PER_WIDE_INT)
2753 /* We could handle this with some effort, but this case is much better
2754 handled directly with a scc insn, so rely on caller using that. */
2758 /* mlow = 2^(N + lgup)/d */
2759 if (pow >= HOST_BITS_PER_WIDE_INT)
2761 nh = (HOST_WIDE_INT) 1 << (pow - HOST_BITS_PER_WIDE_INT);
2767 nl = (unsigned HOST_WIDE_INT) 1 << pow;
2769 div_and_round_double (TRUNC_DIV_EXPR, 1, nl, nh, d, (HOST_WIDE_INT) 0,
2770 &mlow_lo, &mlow_hi, &dummy1, &dummy2);
2772 /* mhigh = (2^(N + lgup) + 2^N + lgup - precision)/d */
2773 if (pow2 >= HOST_BITS_PER_WIDE_INT)
2774 nh |= (HOST_WIDE_INT) 1 << (pow2 - HOST_BITS_PER_WIDE_INT);
2776 nl |= (unsigned HOST_WIDE_INT) 1 << pow2;
2777 div_and_round_double (TRUNC_DIV_EXPR, 1, nl, nh, d, (HOST_WIDE_INT) 0,
2778 &mhigh_lo, &mhigh_hi, &dummy1, &dummy2);
2780 if (mhigh_hi && nh - d >= d)
2782 if (mhigh_hi > 1 || mlow_hi > 1)
2784 /* Assert that mlow < mhigh. */
2785 if (! (mlow_hi < mhigh_hi || (mlow_hi == mhigh_hi && mlow_lo < mhigh_lo)))
2788 /* If precision == N, then mlow, mhigh exceed 2^N
2789 (but they do not exceed 2^(N+1)). */
2791 /* Reduce to lowest terms. */
2792 for (post_shift = lgup; post_shift > 0; post_shift--)
2794 unsigned HOST_WIDE_INT ml_lo = (mlow_hi << (HOST_BITS_PER_WIDE_INT - 1)) | (mlow_lo >> 1);
2795 unsigned HOST_WIDE_INT mh_lo = (mhigh_hi << (HOST_BITS_PER_WIDE_INT - 1)) | (mhigh_lo >> 1);
2805 *post_shift_ptr = post_shift;
2807 if (n < HOST_BITS_PER_WIDE_INT)
2809 unsigned HOST_WIDE_INT mask = ((unsigned HOST_WIDE_INT) 1 << n) - 1;
2810 *multiplier_ptr = mhigh_lo & mask;
2811 return mhigh_lo >= mask;
2815 *multiplier_ptr = mhigh_lo;
2820 /* Compute the inverse of X mod 2**n, i.e., find Y such that X * Y is
2821 congruent to 1 (mod 2**N). */
2823 static unsigned HOST_WIDE_INT
2824 invert_mod2n (unsigned HOST_WIDE_INT x, int n)
2826 /* Solve x*y == 1 (mod 2^n), where x is odd. Return y. */
2828 /* The algorithm notes that the choice y = x satisfies
2829 x*y == 1 mod 2^3, since x is assumed odd.
2830 Each iteration doubles the number of bits of significance in y. */
2832 unsigned HOST_WIDE_INT mask;
2833 unsigned HOST_WIDE_INT y = x;
2836 mask = (n == HOST_BITS_PER_WIDE_INT
2837 ? ~(unsigned HOST_WIDE_INT) 0
2838 : ((unsigned HOST_WIDE_INT) 1 << n) - 1);
2842 y = y * (2 - x*y) & mask; /* Modulo 2^N */
2848 /* Emit code to adjust ADJ_OPERAND after multiplication of wrong signedness
2849 flavor of OP0 and OP1. ADJ_OPERAND is already the high half of the
2850 product OP0 x OP1. If UNSIGNEDP is nonzero, adjust the signed product
2851 to become unsigned, if UNSIGNEDP is zero, adjust the unsigned product to
2854 The result is put in TARGET if that is convenient.
2856 MODE is the mode of operation. */
2859 expand_mult_highpart_adjust (enum machine_mode mode, rtx adj_operand, rtx op0,
2860 rtx op1, rtx target, int unsignedp)
2863 enum rtx_code adj_code = unsignedp ? PLUS : MINUS;
2865 tem = expand_shift (RSHIFT_EXPR, mode, op0,
2866 build_int_2 (GET_MODE_BITSIZE (mode) - 1, 0),
2868 tem = expand_and (mode, tem, op1, NULL_RTX);
2870 = force_operand (gen_rtx_fmt_ee (adj_code, mode, adj_operand, tem),
2873 tem = expand_shift (RSHIFT_EXPR, mode, op1,
2874 build_int_2 (GET_MODE_BITSIZE (mode) - 1, 0),
2876 tem = expand_and (mode, tem, op0, NULL_RTX);
2877 target = force_operand (gen_rtx_fmt_ee (adj_code, mode, adj_operand, tem),
2883 /* Subroutine of expand_mult_highpart. Return the MODE high part of OP. */
2886 extract_high_half (enum machine_mode mode, rtx op)
2888 enum machine_mode wider_mode;
2890 if (mode == word_mode)
2891 return gen_highpart (mode, op);
2893 wider_mode = GET_MODE_WIDER_MODE (mode);
2894 op = expand_shift (RSHIFT_EXPR, wider_mode, op,
2895 build_int_2 (GET_MODE_BITSIZE (mode), 0), 0, 1);
2896 return convert_modes (mode, wider_mode, op, 0);
2899 /* Like expand_mult_highpart, but only consider using a multiplication
2900 optab. OP1 is an rtx for the constant operand. */
2903 expand_mult_highpart_optab (enum machine_mode mode, rtx op0, rtx op1,
2904 rtx target, int unsignedp, int max_cost)
2906 rtx narrow_op1 = gen_int_mode (INTVAL (op1), mode);
2907 enum machine_mode wider_mode;
2912 wider_mode = GET_MODE_WIDER_MODE (mode);
2913 size = GET_MODE_BITSIZE (mode);
2915 /* Firstly, try using a multiplication insn that only generates the needed
2916 high part of the product, and in the sign flavor of unsignedp. */
2917 if (mul_highpart_cost[mode] < max_cost)
2919 moptab = unsignedp ? umul_highpart_optab : smul_highpart_optab;
2920 tem = expand_binop (mode, moptab, op0, narrow_op1, target,
2921 unsignedp, OPTAB_DIRECT);
2926 /* Secondly, same as above, but use sign flavor opposite of unsignedp.
2927 Need to adjust the result after the multiplication. */
2928 if (size - 1 < BITS_PER_WORD
2929 && (mul_highpart_cost[mode] + 2 * shift_cost[mode][size-1]
2930 + 4 * add_cost[mode] < max_cost))
2932 moptab = unsignedp ? smul_highpart_optab : umul_highpart_optab;
2933 tem = expand_binop (mode, moptab, op0, narrow_op1, target,
2934 unsignedp, OPTAB_DIRECT);
2936 /* We used the wrong signedness. Adjust the result. */
2937 return expand_mult_highpart_adjust (mode, tem, op0, narrow_op1,
2941 /* Try widening multiplication. */
2942 moptab = unsignedp ? umul_widen_optab : smul_widen_optab;
2943 if (moptab->handlers[wider_mode].insn_code != CODE_FOR_nothing
2944 && mul_widen_cost[wider_mode] < max_cost)
2946 tem = expand_binop (wider_mode, moptab, op0, narrow_op1, 0,
2947 unsignedp, OPTAB_WIDEN);
2949 return extract_high_half (mode, tem);
2952 /* Try widening the mode and perform a non-widening multiplication. */
2953 moptab = smul_optab;
2954 if (smul_optab->handlers[wider_mode].insn_code != CODE_FOR_nothing
2955 && size - 1 < BITS_PER_WORD
2956 && mul_cost[wider_mode] + shift_cost[mode][size-1] < max_cost)
2958 tem = expand_binop (wider_mode, moptab, op0, op1, 0,
2959 unsignedp, OPTAB_WIDEN);
2961 return extract_high_half (mode, tem);
2964 /* Try widening multiplication of opposite signedness, and adjust. */
2965 moptab = unsignedp ? smul_widen_optab : umul_widen_optab;
2966 if (moptab->handlers[wider_mode].insn_code != CODE_FOR_nothing
2967 && size - 1 < BITS_PER_WORD
2968 && (mul_widen_cost[wider_mode] + 2 * shift_cost[mode][size-1]
2969 + 4 * add_cost[mode] < max_cost))
2971 tem = expand_binop (wider_mode, moptab, op0, narrow_op1,
2972 NULL_RTX, ! unsignedp, OPTAB_WIDEN);
2975 tem = extract_high_half (mode, tem);
2976 /* We used the wrong signedness. Adjust the result. */
2977 return expand_mult_highpart_adjust (mode, tem, op0, narrow_op1,
2985 /* Emit code to multiply OP0 and CNST1, putting the high half of the result
2986 in TARGET if that is convenient, and return where the result is. If the
2987 operation can not be performed, 0 is returned.
2989 MODE is the mode of operation and result.
2991 UNSIGNEDP nonzero means unsigned multiply.
2993 MAX_COST is the total allowed cost for the expanded RTL. */
2996 expand_mult_highpart (enum machine_mode mode, rtx op0,
2997 unsigned HOST_WIDE_INT cnst1, rtx target,
2998 int unsignedp, int max_cost)
3000 enum machine_mode wider_mode = GET_MODE_WIDER_MODE (mode);
3002 bool sign_adjust = false;
3003 enum mult_variant variant;
3004 struct algorithm alg;
3007 /* We can't support modes wider than HOST_BITS_PER_INT. */
3008 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
3011 op1 = gen_int_mode (cnst1, wider_mode);
3012 cnst1 &= GET_MODE_MASK (mode);
3014 /* We can't optimize modes wider than BITS_PER_WORD.
3015 ??? We might be able to perform double-word arithmetic if
3016 mode == word_mode, however all the cost calculations in
3017 synth_mult etc. assume single-word operations. */
3018 if (GET_MODE_BITSIZE (wider_mode) > BITS_PER_WORD)
3019 return expand_mult_highpart_optab (mode, op0, op1, target,
3020 unsignedp, max_cost);
3022 extra_cost = shift_cost[mode][GET_MODE_BITSIZE (mode) - 1];
3024 /* Check whether we try to multiply by a negative constant. */
3025 if (!unsignedp && ((cnst1 >> (GET_MODE_BITSIZE (mode) - 1)) & 1))
3028 extra_cost += add_cost[mode];
3031 /* See whether shift/add multiplication is cheap enough. */
3032 if (choose_mult_variant (wider_mode, cnst1, &alg, &variant,
3033 max_cost - extra_cost))
3035 /* See whether the specialized multiplication optabs are
3036 cheaper than the shift/add version. */
3037 tem = expand_mult_highpart_optab (mode, op0, op1, target,
3038 unsignedp, alg.cost + extra_cost);
3042 tem = convert_to_mode (wider_mode, op0, unsignedp);
3043 tem = expand_mult_const (wider_mode, tem, cnst1, 0, &alg, variant);
3044 tem = extract_high_half (mode, tem);
3046 /* Adjust result for signedness. */
3048 tem = force_operand (gen_rtx_MINUS (mode, tem, op0), tem);
3052 return expand_mult_highpart_optab (mode, op0, op1, target,
3053 unsignedp, max_cost);
3056 /* Emit the code to divide OP0 by OP1, putting the result in TARGET
3057 if that is convenient, and returning where the result is.
3058 You may request either the quotient or the remainder as the result;
3059 specify REM_FLAG nonzero to get the remainder.
3061 CODE is the expression code for which kind of division this is;
3062 it controls how rounding is done. MODE is the machine mode to use.
3063 UNSIGNEDP nonzero means do unsigned division. */
3065 /* ??? For CEIL_MOD_EXPR, can compute incorrect remainder with ANDI
3066 and then correct it by or'ing in missing high bits
3067 if result of ANDI is nonzero.
3068 For ROUND_MOD_EXPR, can use ANDI and then sign-extend the result.
3069 This could optimize to a bfexts instruction.
3070 But C doesn't use these operations, so their optimizations are
3072 /* ??? For modulo, we don't actually need the highpart of the first product,
3073 the low part will do nicely. And for small divisors, the second multiply
3074 can also be a low-part only multiply or even be completely left out.
3075 E.g. to calculate the remainder of a division by 3 with a 32 bit
3076 multiply, multiply with 0x55555556 and extract the upper two bits;
3077 the result is exact for inputs up to 0x1fffffff.
3078 The input range can be reduced by using cross-sum rules.
3079 For odd divisors >= 3, the following table gives right shift counts
3080 so that if a number is shifted by an integer multiple of the given
3081 amount, the remainder stays the same:
3082 2, 4, 3, 6, 10, 12, 4, 8, 18, 6, 11, 20, 18, 0, 5, 10, 12, 0, 12, 20,
3083 14, 12, 23, 21, 8, 0, 20, 18, 0, 0, 6, 12, 0, 22, 0, 18, 20, 30, 0, 0,
3084 0, 8, 0, 11, 12, 10, 36, 0, 30, 0, 0, 12, 0, 0, 0, 0, 44, 12, 24, 0,
3085 20, 0, 7, 14, 0, 18, 36, 0, 0, 46, 60, 0, 42, 0, 15, 24, 20, 0, 0, 33,
3086 0, 20, 0, 0, 18, 0, 60, 0, 0, 0, 0, 0, 40, 18, 0, 0, 12
3088 Cross-sum rules for even numbers can be derived by leaving as many bits
3089 to the right alone as the divisor has zeros to the right.
3090 E.g. if x is an unsigned 32 bit number:
3091 (x mod 12) == (((x & 1023) + ((x >> 8) & ~3)) * 0x15555558 >> 2 * 3) >> 28
3094 #define EXACT_POWER_OF_2_OR_ZERO_P(x) (((x) & ((x) - 1)) == 0)
3097 expand_divmod (int rem_flag, enum tree_code code, enum machine_mode mode,
3098 rtx op0, rtx op1, rtx target, int unsignedp)
3100 enum machine_mode compute_mode;
3102 rtx quotient = 0, remainder = 0;
3106 optab optab1, optab2;
3107 int op1_is_constant, op1_is_pow2 = 0;
3108 int max_cost, extra_cost;
3109 static HOST_WIDE_INT last_div_const = 0;
3110 static HOST_WIDE_INT ext_op1;
3112 op1_is_constant = GET_CODE (op1) == CONST_INT;
3113 if (op1_is_constant)
3115 ext_op1 = INTVAL (op1);
3117 ext_op1 &= GET_MODE_MASK (mode);
3118 op1_is_pow2 = ((EXACT_POWER_OF_2_OR_ZERO_P (ext_op1)
3119 || (! unsignedp && EXACT_POWER_OF_2_OR_ZERO_P (-ext_op1))));
3123 This is the structure of expand_divmod:
3125 First comes code to fix up the operands so we can perform the operations
3126 correctly and efficiently.
3128 Second comes a switch statement with code specific for each rounding mode.
3129 For some special operands this code emits all RTL for the desired
3130 operation, for other cases, it generates only a quotient and stores it in
3131 QUOTIENT. The case for trunc division/remainder might leave quotient = 0,
3132 to indicate that it has not done anything.
3134 Last comes code that finishes the operation. If QUOTIENT is set and
3135 REM_FLAG is set, the remainder is computed as OP0 - QUOTIENT * OP1. If
3136 QUOTIENT is not set, it is computed using trunc rounding.
3138 We try to generate special code for division and remainder when OP1 is a
3139 constant. If |OP1| = 2**n we can use shifts and some other fast
3140 operations. For other values of OP1, we compute a carefully selected
3141 fixed-point approximation m = 1/OP1, and generate code that multiplies OP0
3144 In all cases but EXACT_DIV_EXPR, this multiplication requires the upper
3145 half of the product. Different strategies for generating the product are
3146 implemented in expand_mult_highpart.
3148 If what we actually want is the remainder, we generate that by another
3149 by-constant multiplication and a subtraction. */
3151 /* We shouldn't be called with OP1 == const1_rtx, but some of the
3152 code below will malfunction if we are, so check here and handle
3153 the special case if so. */
3154 if (op1 == const1_rtx)
3155 return rem_flag ? const0_rtx : op0;
3157 /* When dividing by -1, we could get an overflow.
3158 negv_optab can handle overflows. */
3159 if (! unsignedp && op1 == constm1_rtx)
3163 return expand_unop (mode, flag_trapv && GET_MODE_CLASS(mode) == MODE_INT
3164 ? negv_optab : neg_optab, op0, target, 0);
3168 /* Don't use the function value register as a target
3169 since we have to read it as well as write it,
3170 and function-inlining gets confused by this. */
3171 && ((REG_P (target) && REG_FUNCTION_VALUE_P (target))
3172 /* Don't clobber an operand while doing a multi-step calculation. */
3173 || ((rem_flag || op1_is_constant)
3174 && (reg_mentioned_p (target, op0)
3175 || (GET_CODE (op0) == MEM && GET_CODE (target) == MEM)))
3176 || reg_mentioned_p (target, op1)
3177 || (GET_CODE (op1) == MEM && GET_CODE (target) == MEM)))
3180 /* Get the mode in which to perform this computation. Normally it will
3181 be MODE, but sometimes we can't do the desired operation in MODE.
3182 If so, pick a wider mode in which we can do the operation. Convert
3183 to that mode at the start to avoid repeated conversions.
3185 First see what operations we need. These depend on the expression
3186 we are evaluating. (We assume that divxx3 insns exist under the
3187 same conditions that modxx3 insns and that these insns don't normally
3188 fail. If these assumptions are not correct, we may generate less
3189 efficient code in some cases.)
3191 Then see if we find a mode in which we can open-code that operation
3192 (either a division, modulus, or shift). Finally, check for the smallest
3193 mode for which we can do the operation with a library call. */
3195 /* We might want to refine this now that we have division-by-constant
3196 optimization. Since expand_mult_highpart tries so many variants, it is
3197 not straightforward to generalize this. Maybe we should make an array
3198 of possible modes in init_expmed? Save this for GCC 2.7. */
3200 optab1 = ((op1_is_pow2 && op1 != const0_rtx)
3201 ? (unsignedp ? lshr_optab : ashr_optab)
3202 : (unsignedp ? udiv_optab : sdiv_optab));
3203 optab2 = ((op1_is_pow2 && op1 != const0_rtx)
3205 : (unsignedp ? udivmod_optab : sdivmod_optab));
3207 for (compute_mode = mode; compute_mode != VOIDmode;
3208 compute_mode = GET_MODE_WIDER_MODE (compute_mode))
3209 if (optab1->handlers[compute_mode].insn_code != CODE_FOR_nothing
3210 || optab2->handlers[compute_mode].insn_code != CODE_FOR_nothing)
3213 if (compute_mode == VOIDmode)
3214 for (compute_mode = mode; compute_mode != VOIDmode;
3215 compute_mode = GET_MODE_WIDER_MODE (compute_mode))
3216 if (optab1->handlers[compute_mode].libfunc
3217 || optab2->handlers[compute_mode].libfunc)
3220 /* If we still couldn't find a mode, use MODE, but we'll probably abort
3222 if (compute_mode == VOIDmode)
3223 compute_mode = mode;
3225 if (target && GET_MODE (target) == compute_mode)
3228 tquotient = gen_reg_rtx (compute_mode);
3230 size = GET_MODE_BITSIZE (compute_mode);
3232 /* It should be possible to restrict the precision to GET_MODE_BITSIZE
3233 (mode), and thereby get better code when OP1 is a constant. Do that
3234 later. It will require going over all usages of SIZE below. */
3235 size = GET_MODE_BITSIZE (mode);
3238 /* Only deduct something for a REM if the last divide done was
3239 for a different constant. Then set the constant of the last
3241 max_cost = div_cost[compute_mode]
3242 - (rem_flag && ! (last_div_const != 0 && op1_is_constant
3243 && INTVAL (op1) == last_div_const)
3244 ? mul_cost[compute_mode] + add_cost[compute_mode]
3247 last_div_const = ! rem_flag && op1_is_constant ? INTVAL (op1) : 0;
3249 /* Now convert to the best mode to use. */
3250 if (compute_mode != mode)
3252 op0 = convert_modes (compute_mode, mode, op0, unsignedp);
3253 op1 = convert_modes (compute_mode, mode, op1, unsignedp);
3255 /* convert_modes may have placed op1 into a register, so we
3256 must recompute the following. */
3257 op1_is_constant = GET_CODE (op1) == CONST_INT;
3258 op1_is_pow2 = (op1_is_constant
3259 && ((EXACT_POWER_OF_2_OR_ZERO_P (INTVAL (op1))
3261 && EXACT_POWER_OF_2_OR_ZERO_P (-INTVAL (op1)))))) ;
3264 /* If one of the operands is a volatile MEM, copy it into a register. */
3266 if (GET_CODE (op0) == MEM && MEM_VOLATILE_P (op0))
3267 op0 = force_reg (compute_mode, op0);
3268 if (GET_CODE (op1) == MEM && MEM_VOLATILE_P (op1))
3269 op1 = force_reg (compute_mode, op1);
3271 /* If we need the remainder or if OP1 is constant, we need to
3272 put OP0 in a register in case it has any queued subexpressions. */
3273 if (rem_flag || op1_is_constant)
3274 op0 = force_reg (compute_mode, op0);
3276 last = get_last_insn ();
3278 /* Promote floor rounding to trunc rounding for unsigned operations. */
3281 if (code == FLOOR_DIV_EXPR)
3282 code = TRUNC_DIV_EXPR;
3283 if (code == FLOOR_MOD_EXPR)
3284 code = TRUNC_MOD_EXPR;
3285 if (code == EXACT_DIV_EXPR && op1_is_pow2)
3286 code = TRUNC_DIV_EXPR;
3289 if (op1 != const0_rtx)
3292 case TRUNC_MOD_EXPR:
3293 case TRUNC_DIV_EXPR:
3294 if (op1_is_constant)
3298 unsigned HOST_WIDE_INT mh, ml;
3299 int pre_shift, post_shift;
3301 unsigned HOST_WIDE_INT d = (INTVAL (op1)
3302 & GET_MODE_MASK (compute_mode));
3304 if (EXACT_POWER_OF_2_OR_ZERO_P (d))
3306 pre_shift = floor_log2 (d);
3310 = expand_binop (compute_mode, and_optab, op0,
3311 GEN_INT (((HOST_WIDE_INT) 1 << pre_shift) - 1),
3315 return gen_lowpart (mode, remainder);
3317 quotient = expand_shift (RSHIFT_EXPR, compute_mode, op0,
3318 build_int_2 (pre_shift, 0),
3321 else if (size <= HOST_BITS_PER_WIDE_INT)
3323 if (d >= ((unsigned HOST_WIDE_INT) 1 << (size - 1)))
3325 /* Most significant bit of divisor is set; emit an scc
3327 quotient = emit_store_flag (tquotient, GEU, op0, op1,
3328 compute_mode, 1, 1);
3334 /* Find a suitable multiplier and right shift count
3335 instead of multiplying with D. */
3337 mh = choose_multiplier (d, size, size,
3338 &ml, &post_shift, &dummy);
3340 /* If the suggested multiplier is more than SIZE bits,
3341 we can do better for even divisors, using an
3342 initial right shift. */
3343 if (mh != 0 && (d & 1) == 0)
3345 pre_shift = floor_log2 (d & -d);
3346 mh = choose_multiplier (d >> pre_shift, size,
3348 &ml, &post_shift, &dummy);
3359 if (post_shift - 1 >= BITS_PER_WORD)
3363 = (shift_cost[compute_mode][post_shift - 1]
3364 + shift_cost[compute_mode][1]
3365 + 2 * add_cost[compute_mode]);
3366 t1 = expand_mult_highpart (compute_mode, op0, ml,
3368 max_cost - extra_cost);
3371 t2 = force_operand (gen_rtx_MINUS (compute_mode,
3374 t3 = expand_shift (RSHIFT_EXPR, compute_mode, t2,
3375 build_int_2 (1, 0), NULL_RTX,1);
3376 t4 = force_operand (gen_rtx_PLUS (compute_mode,
3380 = expand_shift (RSHIFT_EXPR, compute_mode, t4,
3381 build_int_2 (post_shift - 1, 0),
3388 if (pre_shift >= BITS_PER_WORD
3389 || post_shift >= BITS_PER_WORD)
3392 t1 = expand_shift (RSHIFT_EXPR, compute_mode, op0,
3393 build_int_2 (pre_shift, 0),
3396 = (shift_cost[compute_mode][pre_shift]
3397 + shift_cost[compute_mode][post_shift]);
3398 t2 = expand_mult_highpart (compute_mode, t1, ml,
3400 max_cost - extra_cost);
3404 = expand_shift (RSHIFT_EXPR, compute_mode, t2,
3405 build_int_2 (post_shift, 0),
3410 else /* Too wide mode to use tricky code */
3413 insn = get_last_insn ();
3415 && (set = single_set (insn)) != 0
3416 && SET_DEST (set) == quotient)
3417 set_unique_reg_note (insn,
3419 gen_rtx_UDIV (compute_mode, op0, op1));
3421 else /* TRUNC_DIV, signed */
3423 unsigned HOST_WIDE_INT ml;
3424 int lgup, post_shift;
3425 HOST_WIDE_INT d = INTVAL (op1);
3426 unsigned HOST_WIDE_INT abs_d = d >= 0 ? d : -d;
3428 /* n rem d = n rem -d */
3429 if (rem_flag && d < 0)
3432 op1 = gen_int_mode (abs_d, compute_mode);
3438 quotient = expand_unop (compute_mode, neg_optab, op0,
3440 else if (abs_d == (unsigned HOST_WIDE_INT) 1 << (size - 1))
3442 /* This case is not handled correctly below. */
3443 quotient = emit_store_flag (tquotient, EQ, op0, op1,
3444 compute_mode, 1, 1);
3448 else if (EXACT_POWER_OF_2_OR_ZERO_P (d)
3449 && (rem_flag ? smod_pow2_cheap[compute_mode]
3450 : sdiv_pow2_cheap[compute_mode])
3451 /* ??? The cheap metric is computed only for
3452 word_mode. If this operation is wider, this may
3453 not be so. Assume true if the optab has an
3454 expander for this mode. */
3455 && (((rem_flag ? smod_optab : sdiv_optab)
3456 ->handlers[compute_mode].insn_code
3457 != CODE_FOR_nothing)
3458 || (sdivmod_optab->handlers[compute_mode]
3459 .insn_code != CODE_FOR_nothing)))
3461 else if (EXACT_POWER_OF_2_OR_ZERO_P (abs_d))
3463 lgup = floor_log2 (abs_d);
3464 if (BRANCH_COST < 1 || (abs_d != 2 && BRANCH_COST < 3))
3466 rtx label = gen_label_rtx ();
3469 t1 = copy_to_mode_reg (compute_mode, op0);
3470 do_cmp_and_jump (t1, const0_rtx, GE,
3471 compute_mode, label);
3472 expand_inc (t1, gen_int_mode (abs_d - 1,
3475 quotient = expand_shift (RSHIFT_EXPR, compute_mode, t1,
3476 build_int_2 (lgup, 0),
3482 t1 = expand_shift (RSHIFT_EXPR, compute_mode, op0,
3483 build_int_2 (size - 1, 0),
3485 t2 = expand_shift (RSHIFT_EXPR, compute_mode, t1,
3486 build_int_2 (size - lgup, 0),
3488 t3 = force_operand (gen_rtx_PLUS (compute_mode,
3491 quotient = expand_shift (RSHIFT_EXPR, compute_mode, t3,
3492 build_int_2 (lgup, 0),
3496 /* We have computed OP0 / abs(OP1). If OP1 is negative, negate
3500 insn = get_last_insn ();
3502 && (set = single_set (insn)) != 0
3503 && SET_DEST (set) == quotient
3504 && abs_d < ((unsigned HOST_WIDE_INT) 1
3505 << (HOST_BITS_PER_WIDE_INT - 1)))
3506 set_unique_reg_note (insn,
3508 gen_rtx_DIV (compute_mode,
3515 quotient = expand_unop (compute_mode, neg_optab,
3516 quotient, quotient, 0);
3519 else if (size <= HOST_BITS_PER_WIDE_INT)
3521 choose_multiplier (abs_d, size, size - 1,
3522 &ml, &post_shift, &lgup);
3523 if (ml < (unsigned HOST_WIDE_INT) 1 << (size - 1))
3527 if (post_shift >= BITS_PER_WORD
3528 || size - 1 >= BITS_PER_WORD)
3531 extra_cost = (shift_cost[compute_mode][post_shift]
3532 + shift_cost[compute_mode][size - 1]
3533 + add_cost[compute_mode]);
3534 t1 = expand_mult_highpart (compute_mode, op0, ml,
3536 max_cost - extra_cost);
3539 t2 = expand_shift (RSHIFT_EXPR, compute_mode, t1,
3540 build_int_2 (post_shift, 0), NULL_RTX, 0);
3541 t3 = expand_shift (RSHIFT_EXPR, compute_mode, op0,
3542 build_int_2 (size - 1, 0), NULL_RTX, 0);
3545 = force_operand (gen_rtx_MINUS (compute_mode,
3550 = force_operand (gen_rtx_MINUS (compute_mode,
3558 if (post_shift >= BITS_PER_WORD
3559 || size - 1 >= BITS_PER_WORD)
3562 ml |= (~(unsigned HOST_WIDE_INT) 0) << (size - 1);
3563 extra_cost = (shift_cost[compute_mode][post_shift]
3564 + shift_cost[compute_mode][size - 1]
3565 + 2 * add_cost[compute_mode]);
3566 t1 = expand_mult_highpart (compute_mode, op0, ml,
3568 max_cost - extra_cost);
3571 t2 = force_operand (gen_rtx_PLUS (compute_mode,
3574 t3 = expand_shift (RSHIFT_EXPR, compute_mode, t2,
3575 build_int_2 (post_shift, 0),
3577 t4 = expand_shift (RSHIFT_EXPR, compute_mode, op0,
3578 build_int_2 (size - 1, 0),
3582 = force_operand (gen_rtx_MINUS (compute_mode,
3587 = force_operand (gen_rtx_MINUS (compute_mode,
3592 else /* Too wide mode to use tricky code */
3595 insn = get_last_insn ();
3597 && (set = single_set (insn)) != 0
3598 && SET_DEST (set) == quotient)
3599 set_unique_reg_note (insn,
3601 gen_rtx_DIV (compute_mode, op0, op1));
3606 delete_insns_since (last);
3609 case FLOOR_DIV_EXPR:
3610 case FLOOR_MOD_EXPR:
3611 /* We will come here only for signed operations. */
3612 if (op1_is_constant && HOST_BITS_PER_WIDE_INT >= size)
3614 unsigned HOST_WIDE_INT mh, ml;
3615 int pre_shift, lgup, post_shift;
3616 HOST_WIDE_INT d = INTVAL (op1);
3620 /* We could just as easily deal with negative constants here,
3621 but it does not seem worth the trouble for GCC 2.6. */
3622 if (EXACT_POWER_OF_2_OR_ZERO_P (d))
3624 pre_shift = floor_log2 (d);
3627 remainder = expand_binop (compute_mode, and_optab, op0,
3628 GEN_INT (((HOST_WIDE_INT) 1 << pre_shift) - 1),
3629 remainder, 0, OPTAB_LIB_WIDEN);
3631 return gen_lowpart (mode, remainder);
3633 quotient = expand_shift (RSHIFT_EXPR, compute_mode, op0,
3634 build_int_2 (pre_shift, 0),
3641 mh = choose_multiplier (d, size, size - 1,
3642 &ml, &post_shift, &lgup);
3646 if (post_shift < BITS_PER_WORD
3647 && size - 1 < BITS_PER_WORD)
3649 t1 = expand_shift (RSHIFT_EXPR, compute_mode, op0,
3650 build_int_2 (size - 1, 0),
3652 t2 = expand_binop (compute_mode, xor_optab, op0, t1,
3653 NULL_RTX, 0, OPTAB_WIDEN);
3654 extra_cost = (shift_cost[compute_mode][post_shift]
3655 + shift_cost[compute_mode][size - 1]
3656 + 2 * add_cost[compute_mode]);
3657 t3 = expand_mult_highpart (compute_mode, t2, ml,
3659 max_cost - extra_cost);
3662 t4 = expand_shift (RSHIFT_EXPR, compute_mode, t3,
3663 build_int_2 (post_shift, 0),
3665 quotient = expand_binop (compute_mode, xor_optab,
3666 t4, t1, tquotient, 0,
3674 rtx nsign, t1, t2, t3, t4;
3675 t1 = force_operand (gen_rtx_PLUS (compute_mode,
3676 op0, constm1_rtx), NULL_RTX);
3677 t2 = expand_binop (compute_mode, ior_optab, op0, t1, NULL_RTX,
3679 nsign = expand_shift (RSHIFT_EXPR, compute_mode, t2,
3680 build_int_2 (size - 1, 0), NULL_RTX, 0);
3681 t3 = force_operand (gen_rtx_MINUS (compute_mode, t1, nsign),
3683 t4 = expand_divmod (0, TRUNC_DIV_EXPR, compute_mode, t3, op1,
3688 t5 = expand_unop (compute_mode, one_cmpl_optab, nsign,
3690 quotient = force_operand (gen_rtx_PLUS (compute_mode,
3699 delete_insns_since (last);
3701 /* Try using an instruction that produces both the quotient and
3702 remainder, using truncation. We can easily compensate the quotient
3703 or remainder to get floor rounding, once we have the remainder.
3704 Notice that we compute also the final remainder value here,
3705 and return the result right away. */
3706 if (target == 0 || GET_MODE (target) != compute_mode)
3707 target = gen_reg_rtx (compute_mode);
3712 = GET_CODE (target) == REG ? target : gen_reg_rtx (compute_mode);
3713 quotient = gen_reg_rtx (compute_mode);
3718 = GET_CODE (target) == REG ? target : gen_reg_rtx (compute_mode);
3719 remainder = gen_reg_rtx (compute_mode);
3722 if (expand_twoval_binop (sdivmod_optab, op0, op1,
3723 quotient, remainder, 0))
3725 /* This could be computed with a branch-less sequence.
3726 Save that for later. */
3728 rtx label = gen_label_rtx ();
3729 do_cmp_and_jump (remainder, const0_rtx, EQ, compute_mode, label);
3730 tem = expand_binop (compute_mode, xor_optab, op0, op1,
3731 NULL_RTX, 0, OPTAB_WIDEN);
3732 do_cmp_and_jump (tem, const0_rtx, GE, compute_mode, label);
3733 expand_dec (quotient, const1_rtx);
3734 expand_inc (remainder, op1);
3736 return gen_lowpart (mode, rem_flag ? remainder : quotient);
3739 /* No luck with division elimination or divmod. Have to do it
3740 by conditionally adjusting op0 *and* the result. */
3742 rtx label1, label2, label3, label4, label5;
3746 quotient = gen_reg_rtx (compute_mode);
3747 adjusted_op0 = copy_to_mode_reg (compute_mode, op0);
3748 label1 = gen_label_rtx ();
3749 label2 = gen_label_rtx ();
3750 label3 = gen_label_rtx ();
3751 label4 = gen_label_rtx ();
3752 label5 = gen_label_rtx ();
3753 do_cmp_and_jump (op1, const0_rtx, LT, compute_mode, label2);
3754 do_cmp_and_jump (adjusted_op0, const0_rtx, LT, compute_mode, label1);
3755 tem = expand_binop (compute_mode, sdiv_optab, adjusted_op0, op1,
3756 quotient, 0, OPTAB_LIB_WIDEN);
3757 if (tem != quotient)
3758 emit_move_insn (quotient, tem);
3759 emit_jump_insn (gen_jump (label5));
3761 emit_label (label1);
3762 expand_inc (adjusted_op0, const1_rtx);
3763 emit_jump_insn (gen_jump (label4));
3765 emit_label (label2);
3766 do_cmp_and_jump (adjusted_op0, const0_rtx, GT, compute_mode, label3);
3767 tem = expand_binop (compute_mode, sdiv_optab, adjusted_op0, op1,
3768 quotient, 0, OPTAB_LIB_WIDEN);
3769 if (tem != quotient)
3770 emit_move_insn (quotient, tem);
3771 emit_jump_insn (gen_jump (label5));
3773 emit_label (label3);
3774 expand_dec (adjusted_op0, const1_rtx);
3775 emit_label (label4);
3776 tem = expand_binop (compute_mode, sdiv_optab, adjusted_op0, op1,
3777 quotient, 0, OPTAB_LIB_WIDEN);
3778 if (tem != quotient)
3779 emit_move_insn (quotient, tem);
3780 expand_dec (quotient, const1_rtx);
3781 emit_label (label5);
3789 if (op1_is_constant && EXACT_POWER_OF_2_OR_ZERO_P (INTVAL (op1)))
3792 unsigned HOST_WIDE_INT d = INTVAL (op1);
3793 t1 = expand_shift (RSHIFT_EXPR, compute_mode, op0,
3794 build_int_2 (floor_log2 (d), 0),
3796 t2 = expand_binop (compute_mode, and_optab, op0,
3798 NULL_RTX, 1, OPTAB_LIB_WIDEN);
3799 t3 = gen_reg_rtx (compute_mode);
3800 t3 = emit_store_flag (t3, NE, t2, const0_rtx,
3801 compute_mode, 1, 1);
3805 lab = gen_label_rtx ();
3806 do_cmp_and_jump (t2, const0_rtx, EQ, compute_mode, lab);
3807 expand_inc (t1, const1_rtx);
3812 quotient = force_operand (gen_rtx_PLUS (compute_mode,
3818 /* Try using an instruction that produces both the quotient and
3819 remainder, using truncation. We can easily compensate the
3820 quotient or remainder to get ceiling rounding, once we have the
3821 remainder. Notice that we compute also the final remainder
3822 value here, and return the result right away. */
3823 if (target == 0 || GET_MODE (target) != compute_mode)
3824 target = gen_reg_rtx (compute_mode);
3828 remainder = (GET_CODE (target) == REG
3829 ? target : gen_reg_rtx (compute_mode));
3830 quotient = gen_reg_rtx (compute_mode);
3834 quotient = (GET_CODE (target) == REG
3835 ? target : gen_reg_rtx (compute_mode));
3836 remainder = gen_reg_rtx (compute_mode);
3839 if (expand_twoval_binop (udivmod_optab, op0, op1, quotient,
3842 /* This could be computed with a branch-less sequence.
3843 Save that for later. */
3844 rtx label = gen_label_rtx ();
3845 do_cmp_and_jump (remainder, const0_rtx, EQ,
3846 compute_mode, label);
3847 expand_inc (quotient, const1_rtx);
3848 expand_dec (remainder, op1);
3850 return gen_lowpart (mode, rem_flag ? remainder : quotient);
3853 /* No luck with division elimination or divmod. Have to do it
3854 by conditionally adjusting op0 *and* the result. */
3857 rtx adjusted_op0, tem;
3859 quotient = gen_reg_rtx (compute_mode);
3860 adjusted_op0 = copy_to_mode_reg (compute_mode, op0);
3861 label1 = gen_label_rtx ();
3862 label2 = gen_label_rtx ();
3863 do_cmp_and_jump (adjusted_op0, const0_rtx, NE,
3864 compute_mode, label1);
3865 emit_move_insn (quotient, const0_rtx);
3866 emit_jump_insn (gen_jump (label2));
3868 emit_label (label1);
3869 expand_dec (adjusted_op0, const1_rtx);
3870 tem = expand_binop (compute_mode, udiv_optab, adjusted_op0, op1,
3871 quotient, 1, OPTAB_LIB_WIDEN);
3872 if (tem != quotient)
3873 emit_move_insn (quotient, tem);
3874 expand_inc (quotient, const1_rtx);
3875 emit_label (label2);
3880 if (op1_is_constant && EXACT_POWER_OF_2_OR_ZERO_P (INTVAL (op1))
3881 && INTVAL (op1) >= 0)
3883 /* This is extremely similar to the code for the unsigned case
3884 above. For 2.7 we should merge these variants, but for
3885 2.6.1 I don't want to touch the code for unsigned since that
3886 get used in C. The signed case will only be used by other
3890 unsigned HOST_WIDE_INT d = INTVAL (op1);
3891 t1 = expand_shift (RSHIFT_EXPR, compute_mode, op0,
3892 build_int_2 (floor_log2 (d), 0),
3894 t2 = expand_binop (compute_mode, and_optab, op0,
3896 NULL_RTX, 1, OPTAB_LIB_WIDEN);
3897 t3 = gen_reg_rtx (compute_mode);
3898 t3 = emit_store_flag (t3, NE, t2, const0_rtx,
3899 compute_mode, 1, 1);
3903 lab = gen_label_rtx ();
3904 do_cmp_and_jump (t2, const0_rtx, EQ, compute_mode, lab);
3905 expand_inc (t1, const1_rtx);
3910 quotient = force_operand (gen_rtx_PLUS (compute_mode,
3916 /* Try using an instruction that produces both the quotient and
3917 remainder, using truncation. We can easily compensate the
3918 quotient or remainder to get ceiling rounding, once we have the
3919 remainder. Notice that we compute also the final remainder
3920 value here, and return the result right away. */
3921 if (target == 0 || GET_MODE (target) != compute_mode)
3922 target = gen_reg_rtx (compute_mode);
3925 remainder= (GET_CODE (target) == REG
3926 ? target : gen_reg_rtx (compute_mode));
3927 quotient = gen_reg_rtx (compute_mode);
3931 quotient = (GET_CODE (target) == REG
3932 ? target : gen_reg_rtx (compute_mode));
3933 remainder = gen_reg_rtx (compute_mode);
3936 if (expand_twoval_binop (sdivmod_optab, op0, op1, quotient,
3939 /* This could be computed with a branch-less sequence.
3940 Save that for later. */
3942 rtx label = gen_label_rtx ();
3943 do_cmp_and_jump (remainder, const0_rtx, EQ,
3944 compute_mode, label);
3945 tem = expand_binop (compute_mode, xor_optab, op0, op1,
3946 NULL_RTX, 0, OPTAB_WIDEN);
3947 do_cmp_and_jump (tem, const0_rtx, LT, compute_mode, label);
3948 expand_inc (quotient, const1_rtx);
3949 expand_dec (remainder, op1);
3951 return gen_lowpart (mode, rem_flag ? remainder : quotient);
3954 /* No luck with division elimination or divmod. Have to do it
3955 by conditionally adjusting op0 *and* the result. */
3957 rtx label1, label2, label3, label4, label5;
3961 quotient = gen_reg_rtx (compute_mode);
3962 adjusted_op0 = copy_to_mode_reg (compute_mode, op0);
3963 label1 = gen_label_rtx ();
3964 label2 = gen_label_rtx ();
3965 label3 = gen_label_rtx ();
3966 label4 = gen_label_rtx ();
3967 label5 = gen_label_rtx ();
3968 do_cmp_and_jump (op1, const0_rtx, LT, compute_mode, label2);
3969 do_cmp_and_jump (adjusted_op0, const0_rtx, GT,
3970 compute_mode, label1);
3971 tem = expand_binop (compute_mode, sdiv_optab, adjusted_op0, op1,
3972 quotient, 0, OPTAB_LIB_WIDEN);
3973 if (tem != quotient)
3974 emit_move_insn (quotient, tem);
3975 emit_jump_insn (gen_jump (label5));
3977 emit_label (label1);
3978 expand_dec (adjusted_op0, const1_rtx);
3979 emit_jump_insn (gen_jump (label4));
3981 emit_label (label2);
3982 do_cmp_and_jump (adjusted_op0, const0_rtx, LT,
3983 compute_mode, label3);
3984 tem = expand_binop (compute_mode, sdiv_optab, adjusted_op0, op1,
3985 quotient, 0, OPTAB_LIB_WIDEN);
3986 if (tem != quotient)
3987 emit_move_insn (quotient, tem);
3988 emit_jump_insn (gen_jump (label5));
3990 emit_label (label3);
3991 expand_inc (adjusted_op0, const1_rtx);
3992 emit_label (label4);
3993 tem = expand_binop (compute_mode, sdiv_optab, adjusted_op0, op1,
3994 quotient, 0, OPTAB_LIB_WIDEN);
3995 if (tem != quotient)
3996 emit_move_insn (quotient, tem);
3997 expand_inc (quotient, const1_rtx);
3998 emit_label (label5);
4003 case EXACT_DIV_EXPR:
4004 if (op1_is_constant && HOST_BITS_PER_WIDE_INT >= size)
4006 HOST_WIDE_INT d = INTVAL (op1);
4007 unsigned HOST_WIDE_INT ml;
4011 pre_shift = floor_log2 (d & -d);
4012 ml = invert_mod2n (d >> pre_shift, size);
4013 t1 = expand_shift (RSHIFT_EXPR, compute_mode, op0,
4014 build_int_2 (pre_shift, 0), NULL_RTX, unsignedp);
4015 quotient = expand_mult (compute_mode, t1,
4016 gen_int_mode (ml, compute_mode),
4019 insn = get_last_insn ();
4020 set_unique_reg_note (insn,
4022 gen_rtx_fmt_ee (unsignedp ? UDIV : DIV,
4028 case ROUND_DIV_EXPR:
4029 case ROUND_MOD_EXPR:
4034 label = gen_label_rtx ();
4035 quotient = gen_reg_rtx (compute_mode);
4036 remainder = gen_reg_rtx (compute_mode);
4037 if (expand_twoval_binop (udivmod_optab, op0, op1, quotient, remainder, 1) == 0)
4040 quotient = expand_binop (compute_mode, udiv_optab, op0, op1,
4041 quotient, 1, OPTAB_LIB_WIDEN);
4042 tem = expand_mult (compute_mode, quotient, op1, NULL_RTX, 1);
4043 remainder = expand_binop (compute_mode, sub_optab, op0, tem,
4044 remainder, 1, OPTAB_LIB_WIDEN);
4046 tem = plus_constant (op1, -1);
4047 tem = expand_shift (RSHIFT_EXPR, compute_mode, tem,
4048 build_int_2 (1, 0), NULL_RTX, 1);
4049 do_cmp_and_jump (remainder, tem, LEU, compute_mode, label);
4050 expand_inc (quotient, const1_rtx);
4051 expand_dec (remainder, op1);
4056 rtx abs_rem, abs_op1, tem, mask;
4058 label = gen_label_rtx ();
4059 quotient = gen_reg_rtx (compute_mode);
4060 remainder = gen_reg_rtx (compute_mode);
4061 if (expand_twoval_binop (sdivmod_optab, op0, op1, quotient, remainder, 0) == 0)
4064 quotient = expand_binop (compute_mode, sdiv_optab, op0, op1,
4065 quotient, 0, OPTAB_LIB_WIDEN);
4066 tem = expand_mult (compute_mode, quotient, op1, NULL_RTX, 0);
4067 remainder = expand_binop (compute_mode, sub_optab, op0, tem,
4068 remainder, 0, OPTAB_LIB_WIDEN);
4070 abs_rem = expand_abs (compute_mode, remainder, NULL_RTX, 1, 0);
4071 abs_op1 = expand_abs (compute_mode, op1, NULL_RTX, 1, 0);
4072 tem = expand_shift (LSHIFT_EXPR, compute_mode, abs_rem,
4073 build_int_2 (1, 0), NULL_RTX, 1);
4074 do_cmp_and_jump (tem, abs_op1, LTU, compute_mode, label);
4075 tem = expand_binop (compute_mode, xor_optab, op0, op1,
4076 NULL_RTX, 0, OPTAB_WIDEN);
4077 mask = expand_shift (RSHIFT_EXPR, compute_mode, tem,
4078 build_int_2 (size - 1, 0), NULL_RTX, 0);
4079 tem = expand_binop (compute_mode, xor_optab, mask, const1_rtx,
4080 NULL_RTX, 0, OPTAB_WIDEN);
4081 tem = expand_binop (compute_mode, sub_optab, tem, mask,
4082 NULL_RTX, 0, OPTAB_WIDEN);
4083 expand_inc (quotient, tem);
4084 tem = expand_binop (compute_mode, xor_optab, mask, op1,
4085 NULL_RTX, 0, OPTAB_WIDEN);
4086 tem = expand_binop (compute_mode, sub_optab, tem, mask,
4087 NULL_RTX, 0, OPTAB_WIDEN);
4088 expand_dec (remainder, tem);
4091 return gen_lowpart (mode, rem_flag ? remainder : quotient);
4099 if (target && GET_MODE (target) != compute_mode)
4104 /* Try to produce the remainder without producing the quotient.
4105 If we seem to have a divmod pattern that does not require widening,
4106 don't try widening here. We should really have a WIDEN argument
4107 to expand_twoval_binop, since what we'd really like to do here is
4108 1) try a mod insn in compute_mode
4109 2) try a divmod insn in compute_mode
4110 3) try a div insn in compute_mode and multiply-subtract to get
4112 4) try the same things with widening allowed. */
4114 = sign_expand_binop (compute_mode, umod_optab, smod_optab,
4117 ((optab2->handlers[compute_mode].insn_code
4118 != CODE_FOR_nothing)
4119 ? OPTAB_DIRECT : OPTAB_WIDEN));
4122 /* No luck there. Can we do remainder and divide at once
4123 without a library call? */
4124 remainder = gen_reg_rtx (compute_mode);
4125 if (! expand_twoval_binop ((unsignedp
4129 NULL_RTX, remainder, unsignedp))
4134 return gen_lowpart (mode, remainder);
4137 /* Produce the quotient. Try a quotient insn, but not a library call.
4138 If we have a divmod in this mode, use it in preference to widening
4139 the div (for this test we assume it will not fail). Note that optab2
4140 is set to the one of the two optabs that the call below will use. */
4142 = sign_expand_binop (compute_mode, udiv_optab, sdiv_optab,
4143 op0, op1, rem_flag ? NULL_RTX : target,
4145 ((optab2->handlers[compute_mode].insn_code
4146 != CODE_FOR_nothing)
4147 ? OPTAB_DIRECT : OPTAB_WIDEN));
4151 /* No luck there. Try a quotient-and-remainder insn,
4152 keeping the quotient alone. */
4153 quotient = gen_reg_rtx (compute_mode);
4154 if (! expand_twoval_binop (unsignedp ? udivmod_optab : sdivmod_optab,
4156 quotient, NULL_RTX, unsignedp))
4160 /* Still no luck. If we are not computing the remainder,
4161 use a library call for the quotient. */
4162 quotient = sign_expand_binop (compute_mode,
4163 udiv_optab, sdiv_optab,
4165 unsignedp, OPTAB_LIB_WIDEN);
4172 if (target && GET_MODE (target) != compute_mode)
4176 /* No divide instruction either. Use library for remainder. */
4177 remainder = sign_expand_binop (compute_mode, umod_optab, smod_optab,
4179 unsignedp, OPTAB_LIB_WIDEN);
4182 /* We divided. Now finish doing X - Y * (X / Y). */
4183 remainder = expand_mult (compute_mode, quotient, op1,
4184 NULL_RTX, unsignedp);
4185 remainder = expand_binop (compute_mode, sub_optab, op0,
4186 remainder, target, unsignedp,
4191 return gen_lowpart (mode, rem_flag ? remainder : quotient);
4194 /* Return a tree node with data type TYPE, describing the value of X.
4195 Usually this is an RTL_EXPR, if there is no obvious better choice.
4196 X may be an expression, however we only support those expressions
4197 generated by loop.c. */
4200 make_tree (tree type, rtx x)
4204 switch (GET_CODE (x))
4207 t = build_int_2 (INTVAL (x),
4208 (TYPE_UNSIGNED (type)
4209 && (GET_MODE_BITSIZE (TYPE_MODE (type))
4210 < HOST_BITS_PER_WIDE_INT))
4211 || INTVAL (x) >= 0 ? 0 : -1);
4212 TREE_TYPE (t) = type;
4216 if (GET_MODE (x) == VOIDmode)
4218 t = build_int_2 (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x));
4219 TREE_TYPE (t) = type;
4225 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
4226 t = build_real (type, d);
4237 units = CONST_VECTOR_NUNITS (x);
4239 /* Build a tree with vector elements. */
4240 for (i = units - 1; i >= 0; --i)
4242 elt = CONST_VECTOR_ELT (x, i);
4243 t = tree_cons (NULL_TREE, make_tree (type, elt), t);
4246 return build_vector (type, t);
4250 return fold (build (PLUS_EXPR, type, make_tree (type, XEXP (x, 0)),
4251 make_tree (type, XEXP (x, 1))));
4254 return fold (build (MINUS_EXPR, type, make_tree (type, XEXP (x, 0)),
4255 make_tree (type, XEXP (x, 1))));
4258 return fold (build1 (NEGATE_EXPR, type, make_tree (type, XEXP (x, 0))));
4261 return fold (build (MULT_EXPR, type, make_tree (type, XEXP (x, 0)),
4262 make_tree (type, XEXP (x, 1))));
4265 return fold (build (LSHIFT_EXPR, type, make_tree (type, XEXP (x, 0)),
4266 make_tree (type, XEXP (x, 1))));
4269 t = lang_hooks.types.unsigned_type (type);
4270 return fold (convert (type,
4271 build (RSHIFT_EXPR, t,
4272 make_tree (t, XEXP (x, 0)),
4273 make_tree (type, XEXP (x, 1)))));
4276 t = lang_hooks.types.signed_type (type);
4277 return fold (convert (type,
4278 build (RSHIFT_EXPR, t,
4279 make_tree (t, XEXP (x, 0)),
4280 make_tree (type, XEXP (x, 1)))));
4283 if (TREE_CODE (type) != REAL_TYPE)
4284 t = lang_hooks.types.signed_type (type);
4288 return fold (convert (type,
4289 build (TRUNC_DIV_EXPR, t,
4290 make_tree (t, XEXP (x, 0)),
4291 make_tree (t, XEXP (x, 1)))));
4293 t = lang_hooks.types.unsigned_type (type);
4294 return fold (convert (type,
4295 build (TRUNC_DIV_EXPR, t,
4296 make_tree (t, XEXP (x, 0)),
4297 make_tree (t, XEXP (x, 1)))));
4301 t = lang_hooks.types.type_for_mode (GET_MODE (XEXP (x, 0)),
4302 GET_CODE (x) == ZERO_EXTEND);
4303 return fold (convert (type, make_tree (t, XEXP (x, 0))));
4306 t = make_node (RTL_EXPR);
4307 TREE_TYPE (t) = type;
4309 /* If TYPE is a POINTER_TYPE, X might be Pmode with TYPE_MODE being
4310 ptr_mode. So convert. */
4311 if (POINTER_TYPE_P (type))
4312 x = convert_memory_address (TYPE_MODE (type), x);
4314 RTL_EXPR_RTL (t) = x;
4315 /* There are no insns to be output
4316 when this rtl_expr is used. */
4317 RTL_EXPR_SEQUENCE (t) = 0;
4322 /* Check whether the multiplication X * MULT + ADD overflows.
4323 X, MULT and ADD must be CONST_*.
4324 MODE is the machine mode for the computation.
4325 X and MULT must have mode MODE. ADD may have a different mode.
4326 So can X (defaults to same as MODE).
4327 UNSIGNEDP is nonzero to do unsigned multiplication. */
4330 const_mult_add_overflow_p (rtx x, rtx mult, rtx add, enum machine_mode mode, int unsignedp)
4332 tree type, mult_type, add_type, result;
4334 type = lang_hooks.types.type_for_mode (mode, unsignedp);
4336 /* In order to get a proper overflow indication from an unsigned
4337 type, we have to pretend that it's a sizetype. */
4341 mult_type = copy_node (type);
4342 TYPE_IS_SIZETYPE (mult_type) = 1;
4345 add_type = (GET_MODE (add) == VOIDmode ? mult_type
4346 : lang_hooks.types.type_for_mode (GET_MODE (add), unsignedp));
4348 result = fold (build (PLUS_EXPR, mult_type,
4349 fold (build (MULT_EXPR, mult_type,
4350 make_tree (mult_type, x),
4351 make_tree (mult_type, mult))),
4352 make_tree (add_type, add)));
4354 return TREE_CONSTANT_OVERFLOW (result);
4357 /* Return an rtx representing the value of X * MULT + ADD.
4358 TARGET is a suggestion for where to store the result (an rtx).
4359 MODE is the machine mode for the computation.
4360 X and MULT must have mode MODE. ADD may have a different mode.
4361 So can X (defaults to same as MODE).
4362 UNSIGNEDP is nonzero to do unsigned multiplication.
4363 This may emit insns. */
4366 expand_mult_add (rtx x, rtx target, rtx mult, rtx add, enum machine_mode mode,
4369 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
4370 tree add_type = (GET_MODE (add) == VOIDmode
4371 ? type: lang_hooks.types.type_for_mode (GET_MODE (add),
4373 tree result = fold (build (PLUS_EXPR, type,
4374 fold (build (MULT_EXPR, type,
4375 make_tree (type, x),
4376 make_tree (type, mult))),
4377 make_tree (add_type, add)));
4379 return expand_expr (result, target, VOIDmode, 0);
4382 /* Compute the logical-and of OP0 and OP1, storing it in TARGET
4383 and returning TARGET.
4385 If TARGET is 0, a pseudo-register or constant is returned. */
4388 expand_and (enum machine_mode mode, rtx op0, rtx op1, rtx target)
4392 if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
4393 tem = simplify_binary_operation (AND, mode, op0, op1);
4395 tem = expand_binop (mode, and_optab, op0, op1, target, 0, OPTAB_LIB_WIDEN);
4399 else if (tem != target)
4400 emit_move_insn (target, tem);
4404 /* Emit a store-flags instruction for comparison CODE on OP0 and OP1
4405 and storing in TARGET. Normally return TARGET.
4406 Return 0 if that cannot be done.
4408 MODE is the mode to use for OP0 and OP1 should they be CONST_INTs. If
4409 it is VOIDmode, they cannot both be CONST_INT.
4411 UNSIGNEDP is for the case where we have to widen the operands
4412 to perform the operation. It says to use zero-extension.
4414 NORMALIZEP is 1 if we should convert the result to be either zero
4415 or one. Normalize is -1 if we should convert the result to be
4416 either zero or -1. If NORMALIZEP is zero, the result will be left
4417 "raw" out of the scc insn. */
4420 emit_store_flag (rtx target, enum rtx_code code, rtx op0, rtx op1,
4421 enum machine_mode mode, int unsignedp, int normalizep)
4424 enum insn_code icode;
4425 enum machine_mode compare_mode;
4426 enum machine_mode target_mode = GET_MODE (target);
4428 rtx last = get_last_insn ();
4429 rtx pattern, comparison;
4431 /* ??? Ok to do this and then fail? */
4432 op0 = protect_from_queue (op0, 0);
4433 op1 = protect_from_queue (op1, 0);
4436 code = unsigned_condition (code);
4438 /* If one operand is constant, make it the second one. Only do this
4439 if the other operand is not constant as well. */
4441 if (swap_commutative_operands_p (op0, op1))
4446 code = swap_condition (code);
4449 if (mode == VOIDmode)
4450 mode = GET_MODE (op0);
4452 /* For some comparisons with 1 and -1, we can convert this to
4453 comparisons with zero. This will often produce more opportunities for
4454 store-flag insns. */
4459 if (op1 == const1_rtx)
4460 op1 = const0_rtx, code = LE;
4463 if (op1 == constm1_rtx)
4464 op1 = const0_rtx, code = LT;
4467 if (op1 == const1_rtx)
4468 op1 = const0_rtx, code = GT;
4471 if (op1 == constm1_rtx)
4472 op1 = const0_rtx, code = GE;
4475 if (op1 == const1_rtx)
4476 op1 = const0_rtx, code = NE;
4479 if (op1 == const1_rtx)
4480 op1 = const0_rtx, code = EQ;
4486 /* If we are comparing a double-word integer with zero, we can convert
4487 the comparison into one involving a single word. */
4488 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD * 2
4489 && GET_MODE_CLASS (mode) == MODE_INT
4490 && op1 == const0_rtx
4491 && (GET_CODE (op0) != MEM || ! MEM_VOLATILE_P (op0)))
4493 if (code == EQ || code == NE)
4495 rtx op00, op01, op0both;
4497 /* Do a logical OR of the two words and compare the result. */
4498 op00 = simplify_gen_subreg (word_mode, op0, mode, 0);
4499 op01 = simplify_gen_subreg (word_mode, op0, mode, UNITS_PER_WORD);
4500 op0both = expand_binop (word_mode, ior_optab, op00, op01,
4501 NULL_RTX, unsignedp, OPTAB_DIRECT);
4503 return emit_store_flag (target, code, op0both, op1, word_mode,
4504 unsignedp, normalizep);
4506 else if (code == LT || code == GE)
4510 /* If testing the sign bit, can just test on high word. */
4511 op0h = simplify_gen_subreg (word_mode, op0, mode,
4512 subreg_highpart_offset (word_mode, mode));
4513 return emit_store_flag (target, code, op0h, op1, word_mode,
4514 unsignedp, normalizep);
4518 /* From now on, we won't change CODE, so set ICODE now. */
4519 icode = setcc_gen_code[(int) code];
4521 /* If this is A < 0 or A >= 0, we can do this by taking the ones
4522 complement of A (for GE) and shifting the sign bit to the low bit. */
4523 if (op1 == const0_rtx && (code == LT || code == GE)
4524 && GET_MODE_CLASS (mode) == MODE_INT
4525 && (normalizep || STORE_FLAG_VALUE == 1
4526 || (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
4527 && ((STORE_FLAG_VALUE & GET_MODE_MASK (mode))
4528 == (unsigned HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1)))))
4532 /* If the result is to be wider than OP0, it is best to convert it
4533 first. If it is to be narrower, it is *incorrect* to convert it
4535 if (GET_MODE_SIZE (target_mode) > GET_MODE_SIZE (mode))
4537 op0 = protect_from_queue (op0, 0);
4538 op0 = convert_modes (target_mode, mode, op0, 0);
4542 if (target_mode != mode)
4546 op0 = expand_unop (mode, one_cmpl_optab, op0,
4547 ((STORE_FLAG_VALUE == 1 || normalizep)
4548 ? 0 : subtarget), 0);
4550 if (STORE_FLAG_VALUE == 1 || normalizep)
4551 /* If we are supposed to produce a 0/1 value, we want to do
4552 a logical shift from the sign bit to the low-order bit; for
4553 a -1/0 value, we do an arithmetic shift. */
4554 op0 = expand_shift (RSHIFT_EXPR, mode, op0,
4555 size_int (GET_MODE_BITSIZE (mode) - 1),
4556 subtarget, normalizep != -1);
4558 if (mode != target_mode)
4559 op0 = convert_modes (target_mode, mode, op0, 0);
4564 if (icode != CODE_FOR_nothing)
4566 insn_operand_predicate_fn pred;
4568 /* We think we may be able to do this with a scc insn. Emit the
4569 comparison and then the scc insn.
4571 compare_from_rtx may call emit_queue, which would be deleted below
4572 if the scc insn fails. So call it ourselves before setting LAST.
4573 Likewise for do_pending_stack_adjust. */
4576 do_pending_stack_adjust ();
4577 last = get_last_insn ();
4580 = compare_from_rtx (op0, op1, code, unsignedp, mode, NULL_RTX);
4581 if (CONSTANT_P (comparison))
4583 if (GET_CODE (comparison) == CONST_INT)
4585 if (comparison == const0_rtx)
4588 #ifdef FLOAT_STORE_FLAG_VALUE
4589 else if (GET_CODE (comparison) == CONST_DOUBLE)
4591 if (comparison == CONST0_RTX (GET_MODE (comparison)))
4597 if (normalizep == 1)
4599 if (normalizep == -1)
4601 return const_true_rtx;
4604 /* The code of COMPARISON may not match CODE if compare_from_rtx
4605 decided to swap its operands and reverse the original code.
4607 We know that compare_from_rtx returns either a CONST_INT or
4608 a new comparison code, so it is safe to just extract the
4609 code from COMPARISON. */
4610 code = GET_CODE (comparison);
4612 /* Get a reference to the target in the proper mode for this insn. */
4613 compare_mode = insn_data[(int) icode].operand[0].mode;
4615 pred = insn_data[(int) icode].operand[0].predicate;
4616 if (preserve_subexpressions_p ()
4617 || ! (*pred) (subtarget, compare_mode))
4618 subtarget = gen_reg_rtx (compare_mode);
4620 pattern = GEN_FCN (icode) (subtarget);
4623 emit_insn (pattern);
4625 /* If we are converting to a wider mode, first convert to
4626 TARGET_MODE, then normalize. This produces better combining
4627 opportunities on machines that have a SIGN_EXTRACT when we are
4628 testing a single bit. This mostly benefits the 68k.
4630 If STORE_FLAG_VALUE does not have the sign bit set when
4631 interpreted in COMPARE_MODE, we can do this conversion as
4632 unsigned, which is usually more efficient. */
4633 if (GET_MODE_SIZE (target_mode) > GET_MODE_SIZE (compare_mode))
4635 convert_move (target, subtarget,
4636 (GET_MODE_BITSIZE (compare_mode)
4637 <= HOST_BITS_PER_WIDE_INT)
4638 && 0 == (STORE_FLAG_VALUE
4639 & ((HOST_WIDE_INT) 1
4640 << (GET_MODE_BITSIZE (compare_mode) -1))));
4642 compare_mode = target_mode;
4647 /* If we want to keep subexpressions around, don't reuse our
4650 if (preserve_subexpressions_p ())
4653 /* Now normalize to the proper value in COMPARE_MODE. Sometimes
4654 we don't have to do anything. */
4655 if (normalizep == 0 || normalizep == STORE_FLAG_VALUE)
4657 /* STORE_FLAG_VALUE might be the most negative number, so write
4658 the comparison this way to avoid a compiler-time warning. */
4659 else if (- normalizep == STORE_FLAG_VALUE)
4660 op0 = expand_unop (compare_mode, neg_optab, op0, subtarget, 0);
4662 /* We don't want to use STORE_FLAG_VALUE < 0 below since this
4663 makes it hard to use a value of just the sign bit due to
4664 ANSI integer constant typing rules. */
4665 else if (GET_MODE_BITSIZE (compare_mode) <= HOST_BITS_PER_WIDE_INT
4666 && (STORE_FLAG_VALUE
4667 & ((HOST_WIDE_INT) 1
4668 << (GET_MODE_BITSIZE (compare_mode) - 1))))
4669 op0 = expand_shift (RSHIFT_EXPR, compare_mode, op0,
4670 size_int (GET_MODE_BITSIZE (compare_mode) - 1),
4671 subtarget, normalizep == 1);
4672 else if (STORE_FLAG_VALUE & 1)
4674 op0 = expand_and (compare_mode, op0, const1_rtx, subtarget);
4675 if (normalizep == -1)
4676 op0 = expand_unop (compare_mode, neg_optab, op0, op0, 0);
4681 /* If we were converting to a smaller mode, do the
4683 if (target_mode != compare_mode)
4685 convert_move (target, op0, 0);
4693 delete_insns_since (last);
4695 /* If expensive optimizations, use different pseudo registers for each
4696 insn, instead of reusing the same pseudo. This leads to better CSE,
4697 but slows down the compiler, since there are more pseudos */
4698 subtarget = (!flag_expensive_optimizations
4699 && (target_mode == mode)) ? target : NULL_RTX;
4701 /* If we reached here, we can't do this with a scc insn. However, there
4702 are some comparisons that can be done directly. For example, if
4703 this is an equality comparison of integers, we can try to exclusive-or
4704 (or subtract) the two operands and use a recursive call to try the
4705 comparison with zero. Don't do any of these cases if branches are
4709 && GET_MODE_CLASS (mode) == MODE_INT && (code == EQ || code == NE)
4710 && op1 != const0_rtx)
4712 tem = expand_binop (mode, xor_optab, op0, op1, subtarget, 1,
4716 tem = expand_binop (mode, sub_optab, op0, op1, subtarget, 1,
4719 tem = emit_store_flag (target, code, tem, const0_rtx,
4720 mode, unsignedp, normalizep);
4722 delete_insns_since (last);
4726 /* Some other cases we can do are EQ, NE, LE, and GT comparisons with
4727 the constant zero. Reject all other comparisons at this point. Only
4728 do LE and GT if branches are expensive since they are expensive on
4729 2-operand machines. */
4731 if (BRANCH_COST == 0
4732 || GET_MODE_CLASS (mode) != MODE_INT || op1 != const0_rtx
4733 || (code != EQ && code != NE
4734 && (BRANCH_COST <= 1 || (code != LE && code != GT))))
4737 /* See what we need to return. We can only return a 1, -1, or the
4740 if (normalizep == 0)
4742 if (STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
4743 normalizep = STORE_FLAG_VALUE;
4745 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
4746 && ((STORE_FLAG_VALUE & GET_MODE_MASK (mode))
4747 == (unsigned HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1)))
4753 /* Try to put the result of the comparison in the sign bit. Assume we can't
4754 do the necessary operation below. */
4758 /* To see if A <= 0, compute (A | (A - 1)). A <= 0 iff that result has
4759 the sign bit set. */
4763 /* This is destructive, so SUBTARGET can't be OP0. */
4764 if (rtx_equal_p (subtarget, op0))
4767 tem = expand_binop (mode, sub_optab, op0, const1_rtx, subtarget, 0,
4770 tem = expand_binop (mode, ior_optab, op0, tem, subtarget, 0,
4774 /* To see if A > 0, compute (((signed) A) << BITS) - A, where BITS is the
4775 number of bits in the mode of OP0, minus one. */
4779 if (rtx_equal_p (subtarget, op0))
4782 tem = expand_shift (RSHIFT_EXPR, mode, op0,
4783 size_int (GET_MODE_BITSIZE (mode) - 1),
4785 tem = expand_binop (mode, sub_optab, tem, op0, subtarget, 0,
4789 if (code == EQ || code == NE)
4791 /* For EQ or NE, one way to do the comparison is to apply an operation
4792 that converts the operand into a positive number if it is nonzero
4793 or zero if it was originally zero. Then, for EQ, we subtract 1 and
4794 for NE we negate. This puts the result in the sign bit. Then we
4795 normalize with a shift, if needed.
4797 Two operations that can do the above actions are ABS and FFS, so try
4798 them. If that doesn't work, and MODE is smaller than a full word,
4799 we can use zero-extension to the wider mode (an unsigned conversion)
4800 as the operation. */
4802 /* Note that ABS doesn't yield a positive number for INT_MIN, but
4803 that is compensated by the subsequent overflow when subtracting
4806 if (abs_optab->handlers[mode].insn_code != CODE_FOR_nothing)
4807 tem = expand_unop (mode, abs_optab, op0, subtarget, 1);
4808 else if (ffs_optab->handlers[mode].insn_code != CODE_FOR_nothing)
4809 tem = expand_unop (mode, ffs_optab, op0, subtarget, 1);
4810 else if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
4812 op0 = protect_from_queue (op0, 0);
4813 tem = convert_modes (word_mode, mode, op0, 1);
4820 tem = expand_binop (mode, sub_optab, tem, const1_rtx, subtarget,
4823 tem = expand_unop (mode, neg_optab, tem, subtarget, 0);
4826 /* If we couldn't do it that way, for NE we can "or" the two's complement
4827 of the value with itself. For EQ, we take the one's complement of
4828 that "or", which is an extra insn, so we only handle EQ if branches
4831 if (tem == 0 && (code == NE || BRANCH_COST > 1))
4833 if (rtx_equal_p (subtarget, op0))
4836 tem = expand_unop (mode, neg_optab, op0, subtarget, 0);
4837 tem = expand_binop (mode, ior_optab, tem, op0, subtarget, 0,
4840 if (tem && code == EQ)
4841 tem = expand_unop (mode, one_cmpl_optab, tem, subtarget, 0);
4845 if (tem && normalizep)
4846 tem = expand_shift (RSHIFT_EXPR, mode, tem,
4847 size_int (GET_MODE_BITSIZE (mode) - 1),
4848 subtarget, normalizep == 1);
4852 if (GET_MODE (tem) != target_mode)
4854 convert_move (target, tem, 0);
4857 else if (!subtarget)
4859 emit_move_insn (target, tem);
4864 delete_insns_since (last);
4869 /* Like emit_store_flag, but always succeeds. */
4872 emit_store_flag_force (rtx target, enum rtx_code code, rtx op0, rtx op1,
4873 enum machine_mode mode, int unsignedp, int normalizep)
4877 /* First see if emit_store_flag can do the job. */
4878 tem = emit_store_flag (target, code, op0, op1, mode, unsignedp, normalizep);
4882 if (normalizep == 0)
4885 /* If this failed, we have to do this with set/compare/jump/set code. */
4887 if (GET_CODE (target) != REG
4888 || reg_mentioned_p (target, op0) || reg_mentioned_p (target, op1))
4889 target = gen_reg_rtx (GET_MODE (target));
4891 emit_move_insn (target, const1_rtx);
4892 label = gen_label_rtx ();
4893 do_compare_rtx_and_jump (op0, op1, code, unsignedp, mode, NULL_RTX,
4896 emit_move_insn (target, const0_rtx);
4902 /* Perform possibly multi-word comparison and conditional jump to LABEL
4903 if ARG1 OP ARG2 true where ARG1 and ARG2 are of mode MODE
4905 The algorithm is based on the code in expr.c:do_jump.
4907 Note that this does not perform a general comparison. Only variants
4908 generated within expmed.c are correctly handled, others abort (but could
4909 be handled if needed). */
4912 do_cmp_and_jump (rtx arg1, rtx arg2, enum rtx_code op, enum machine_mode mode,
4915 /* If this mode is an integer too wide to compare properly,
4916 compare word by word. Rely on cse to optimize constant cases. */
4918 if (GET_MODE_CLASS (mode) == MODE_INT
4919 && ! can_compare_p (op, mode, ccp_jump))
4921 rtx label2 = gen_label_rtx ();
4926 do_jump_by_parts_greater_rtx (mode, 1, arg2, arg1, label2, label);
4930 do_jump_by_parts_greater_rtx (mode, 1, arg1, arg2, label, label2);
4934 do_jump_by_parts_greater_rtx (mode, 0, arg2, arg1, label2, label);
4938 do_jump_by_parts_greater_rtx (mode, 0, arg1, arg2, label2, label);
4942 do_jump_by_parts_greater_rtx (mode, 0, arg2, arg1, label, label2);
4945 /* do_jump_by_parts_equality_rtx compares with zero. Luckily
4946 that's the only equality operations we do */
4948 if (arg2 != const0_rtx || mode != GET_MODE(arg1))
4950 do_jump_by_parts_equality_rtx (arg1, label2, label);
4954 if (arg2 != const0_rtx || mode != GET_MODE(arg1))
4956 do_jump_by_parts_equality_rtx (arg1, label, label2);
4963 emit_label (label2);
4966 emit_cmp_and_jump_insns (arg1, arg2, op, NULL_RTX, mode, 0, label);