On Sat, Jan 30, 2016 at 02:04:45PM +0000, Richard Sandiford wrote: > Not sure what to call it. Maybe canonize_uhwi? Like canonize, except > that it takes a uhwi instead of a length. > > > Can that be done as a follow-up? Certainly it would need > > to take the uhwi to store, pointer to the array of hwis, and precision. > > Yeah, guess it can wait.
So like this? Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-02-01 Jakub Jelinek <ja...@redhat.com> * wide-int.cc (canonize_uhwi): New function. (wi::divmod_internal): Use it. --- gcc/wide-int.cc.jj 2016-01-30 19:03:35.000000000 +0100 +++ gcc/wide-int.cc 2016-02-01 12:28:23.501519292 +0100 @@ -118,6 +118,20 @@ canonize (HOST_WIDE_INT *val, unsigned i return 1; } +/* VAL[0] is unsigned result of operation. Canonize it by adding + another 0 block if needed, and return number of blocks needed. */ + +static inline unsigned int +canonize_uhwi (HOST_WIDE_INT *val, unsigned int precision) +{ + if (val[0] < 0 && precision > HOST_BITS_PER_WIDE_INT) + { + val[1] = 0; + return 2; + } + return 1; +} + /* * Conversion routines in and out of wide_int. */ @@ -1793,25 +1807,12 @@ wi::divmod_internal (HOST_WIDE_INT *quot if (quotient) { quotient[0] = o0 / o1; - if (o1 == 1 - && (HOST_WIDE_INT) o0 < 0 - && dividend_prec > HOST_BITS_PER_WIDE_INT) - { - quotient[1] = 0; - quotient_len = 2; - } + quotient_len = canonize_uhwi (quotient, dividend_prec); } if (remainder) { remainder[0] = o0 % o1; - if ((HOST_WIDE_INT) remainder[0] < 0 - && dividend_prec > HOST_BITS_PER_WIDE_INT) - { - remainder[1] = 0; - *remainder_len = 2; - } - else - *remainder_len = 1; + *remainder_len = canonize_uhwi (remainder, dividend_prec); } return quotient_len; } Jakub