This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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: ibits


On Tue, Jan 02, 2007 at 01:53:49PM -0500, Dean McCullough wrote:
> 
> I have installed gfortran-4.3.0.  It was also pointed out that I had 
> transposed the arguments to ibits.  I believe ibits(j,0,32) should 
> extract 32 bits from j, starting with bit 0.
> 
> Unfortunately, even with the new version of gfortran, I am getting:
>    57     3FFFFFFFFFFFFFF     3FFFFFFFFFFFFFF
>    58     7FFFFFFFFFFFFFF     7FFFFFFFFFFFFFF
>    59     FFFFFFFFFFFFFFF     FFFFFFFFFFFFFFF
>    60    1FFFFFFFFFFFFFFF    1FFFFFFFFFFFFFFF

I belive you've found a bug.  If I understand ibits correctly,
then k and m in the following program should be the same.

      integer(8), parameter :: n = z'00000000FFFFFFFF'
      integer(8) i,j,k,m
      j = 1
      do i=1,70
         j = ishft(j,1) + 1
         k = ibits(j, 0, 32)
         m = iand(j,n)
         print 5,i, j, k, m
 5       format(i5,3z20)
      enddo
      end

   67    FFFFFFFFFFFFFFFF    FFFFFFFFFFFFFFFF            FFFFFFFF
   68    FFFFFFFFFFFFFFFF    FFFFFFFFFFFFFFFF            FFFFFFFF
   69    FFFFFFFFFFFFFFFF    FFFFFFFFFFFFFFFF            FFFFFFFF
   70    FFFFFFFFFFFFFFFF    FFFFFFFFFFFFFFFF            FFFFFFFF

Further, if I look at the -fdump-tree-original output, I see
the relevant lines are 

            j = (j << 1) + 1;
            k = j >> 0 & ~(-1 << 32);
            m = j & 4294967295;

The equivalent C program is

   #include <stdio.h>

   int main(void) {
     long i, k, j, m;
     j = 1l;
     for (i = 1l; i <= 70l; i++) {
       j = (j << 1l) + 1l;
       k = j >> 0l & ~(-1l << 32);
       m = j & 4294967295l;
       printf("%2d %18lX %18lX %18lX\n", i, j, k, m);
     }
   }

which gives

67   FFFFFFFFFFFFFFFF           FFFFFFFF           FFFFFFFF
68   FFFFFFFFFFFFFFFF           FFFFFFFF           FFFFFFFF
69   FFFFFFFFFFFFFFFF           FFFFFFFF           FFFFFFFF
70   FFFFFFFFFFFFFFFF           FFFFFFFF           FFFFFFFF

and the -fdump-tree-original shows

  j = (j << 1) + 1;
  k = j & 4294967295;
  m = j & 4294967295;

I'm guessing that the code in the Fortran frontend that translates
IBITS is missing a fold_convert such that ~(-1 << 32) is interpreted
as a 32-bit quantity.


BTW, as the person who fixed -fdefault-integer-8 to work, I 
would truly love to rip this option out of gfortran.

-- 
Steve


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