This is the mail archive of the gcc@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]

Re: array reference optimization


On Sun, May 17, 1998 at 02:19:00PM -0700, Jim Wilson wrote:
> which requires doing the multiply in bitsizetype, we could do the divide
> first and then the multiple, something like this:
> 	oset = ... fold (build (MULT_EXPR, ssizetype, index,
> 			size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (...)
> 				    size_int (BITS_PER_UNIT))))
> which keeps everything in range of sizetype.

It keeps it in the range of sizetype, yes, but my patch had a
secondary goal: that of eliminating a divide at runtime.

When the size of a type is not constant, as for the variables `res'
`rhs' and `u' in this simplified version of a function from spec95:

      subroutine resid(res,u,rhs,n,h2i)
      implicit none
      integer n
      double precision res(n,n),rhs(n,n),u(n,n)
      integer i,j
      double precision h2i
      do j = 2, n-1
         do i = 2, n-1
            res(i,j)=-h2i*(u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1)-
     &          4.d0*u(i,j))+rhs(i,j)
         enddo
      enddo
      end

We get, in part,

	.prologue 1
	bis $20,$20,$9
	ldl $1,0($19)		; Load N
	sll $1,6,$20		; Multiply by 64
[...]
$L9:
	subq $23,1,$8
	s8addq $8,0,$8
	bis $20,$20,$6
	bis $31,$31,$7
	srl $6,3,$6		; Divide by 8

In my mind there is no excuse for this -- we should have only done
the multiply by 8 in the first place.


r~


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