grunwald@flute.cs.uiuc.edu (Dirk Grunwald) (07/26/89)
g++-1.35.1+, sun3/os4, -m68881 G++ doesn't notice that the variable `stride' is an induction variable in the following code; stride is a private member variable. It is not modified anywhere but at the beginning of the loop. It should qualify as an induction variable, but I don't think it's being considered for this. //--------------- C++ header to handle arrays like fortran. class Matrix { // by dave nichols private: int *index; double *data; int stride; public: Matrix( int n1, int n2, int *indx, double *dat); double& operator()( int i, int j ); }; static inline double& Matrix::operator()( int i, int j ) { return ( data[i + j * stride ] ); } static inline Matrix::Matrix( int n1, int n2, int *indx, double *dat) { index = indx; data = dat; // for( int i =0; i<n2; i++ ) { // index[i] = i*n1; // } stride = n1; } #include <stdio.h> #include <math.h> #include <generic.h> #define MATRIX(name,n1,n2)\ int name2(name,index)[n1];\ double name2(name,data)[n1*n2]; \ Matrix name(n1, n2, name2(name,index), name2(name,data)); main () { int i, j, k; static const int n=200; MATRIX(x,n,n); double total=0.; for( i=0; i<n; i++ ) for( j=0; j<n; j++ ) x(i,j) = sqrt(1.+(i+1)+(j+1)); for( i=0; i<n; i++ ) for( j=0; j<n; j++ ) for( k=0; k<n; k++ ) total = total + x(i,k) * x(k,j); printf("total=%f\n 1576677724. if double precision\n", (double) total ); } // 7.0sec 1575556480. DEC 3100 (f77 -O3) // 13.1sec 1575559552 DEC 3100 (C++ -O2) // -- Dirk Grunwald -- Univ. of Illinois (grunwald@flute.cs.uiuc.edu)