This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [wide-int 2/5] Fix large widths in shifted_mask


approved.
On 04/25/2014 09:39 AM, Richard Sandiford wrote:
shifted_mask would mishandle cases where the start bit is in the middle
of a HWI and the end bit is in a different HWI.  The "000111000" case
needs to check that the start and end are in the same block.

In the changed lines, "shift" is the position of the lowest mask bit
in its containing HWI.  The end is in the same HWI if shift + width
< HOST_BITS_PER_WIDE_INT.

Tested on x86_64-linux-gnu.  OK to install?

Thanks,
Richard


Index: gcc/wide-int.cc
===================================================================
--- gcc/wide-int.cc	2014-04-25 09:50:37.850073188 +0100
+++ gcc/wide-int.cc	2014-04-25 09:51:05.992292099 +0100
@@ -768,8 +768,8 @@ wi::shifted_mask (HOST_WIDE_INT *val, un
    if (shift)
      {
        HOST_WIDE_INT block = ((unsigned HOST_WIDE_INT) 1 << shift) - 1;
-      shift = end & (HOST_BITS_PER_WIDE_INT - 1);
-      if (shift)
+      shift += width;
+      if (shift < HOST_BITS_PER_WIDE_INT)
  	{
  	  /* case 000111000 */
  	  block = ((unsigned HOST_WIDE_INT) 1 << shift) - block - 1;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]