🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #5928

x86 -malign-double ignored sometimes

#5928
From: Edward Seidl
Date: Thu, 30 Jan 1997 00:00
264 lines
7191 bytes

Hi.  It appears that gcc 2.7.2.1 + g77-0.5.19 sometimes ignores the
-malign-double flag when optimization is turned on.  For example, a small
matrix multiply program I wrote produces the following output when compiled
"-g -malign-double" :

    a[0][0] = 0xbff4f978
    user time for 300 x 300 is 1.690000
    that's 31.952663 Mflops
    user time for 300 x 300 is 1.840000
    that's 29.347826 Mflops
    user time for 300 x 300 is 4.330000
    that's 12.471132 Mflops

    foo2: bffff604 bffff5f8
    a[0][0] = 0xbff4f960
    user time for 300 x 300 is 1.640000
    that's 32.926829 Mflops
    user time for 300 x 300 is 1.830000
    that's 29.508197 Mflops
    user time for 300 x 300 is 4.350000
    that's 12.413793 Mflops

    foo3: bffff604 bffff5f8
    foo3: bffff5f4 bffff5e8
    a[0][0] = 0xbff4f950
    user time for 300 x 300 is 1.640000
    that's 32.926829 Mflops
    user time for 300 x 300 is 1.800000
    that's 30.000000 Mflops
    user time for 300 x 300 is 4.360000
    that's 12.385321 Mflops

    foo2: bffff5dc bffff5d0
    a[0][0] = 0xbff4f938
    user time for 300 x 300 is 1.670000
    that's 32.335329 Mflops
    user time for 300 x 300 is 1.840000
    that's 29.347826 Mflops
    user time for 300 x 300 is 4.340000
    that's 12.442396 Mflops

but when compiled "-O -malign-double" I get the following:

    a[0][0] = 0xbff4f988
    user time for 300 x 300 is 1.160000
    that's 46.551724 Mflops
    user time for 300 x 300 is 1.090000
    that's 49.541284 Mflops
    user time for 300 x 300 is 1.360000
    that's 39.705882 Mflops

    foo2: bffff604 bffff5f8
    a[0][0] = 0xbff4f964
    user time for 300 x 300 is 3.640000
    that's 14.835165 Mflops
    user time for 300 x 300 is 3.260000
    that's 16.564417 Mflops
    user time for 300 x 300 is 3.000000
    that's 18.000000 Mflops

    foo3: bffff604 bffff5f8
    foo3: bffff5f4 bffff5e8
    a[0][0] = 0xbff4f948
    user time for 300 x 300 is 1.160000
    that's 46.551724 Mflops
    user time for 300 x 300 is 1.090000
    that's 49.541284 Mflops
    user time for 300 x 300 is 1.350000
    that's 40.000000 Mflops

    foo2: bffff5c4 bffff5b8
    a[0][0] = 0xbff4f924
    user time for 300 x 300 is 3.650000
    that's 14.794521 Mflops
    user time for 300 x 300 is 3.280000
    that's 16.463415 Mflops
    user time for 300 x 300 is 2.990000
    that's 18.060201 Mflops


As you can see, there's a factor of 2 difference when the a matrix is not
aligned on a 2-word boundary.  I've heard from the linux-smp mailing list
and a computational chemistry mailing list that others are also observing
this behavior.

This is on a dual 200MHz PPro box running Linux v 2.0.27.  I've noticed the
same thing on a 133Mhz Pentium running both Linux and also under Win 95
using cygnus' cygwin32 compiler (althogh on the Pentium the difference is
only about 25%).

As I mentioned above, this happens when using gcc-2.7.2.1 with the g77-0.5.19
patches applied, and with cygnus' cygwin32 compiler.  For the former compiler,
this is the stage3 compiler which passed "make compare".  It was compiled
with the following flags set:

  "-O2 -m486 -malign-flags=2 -malign-jumps=2 -malign-loops=2"

Here's my test code:

=====================================================================

#define DIM 300

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/times.h>
#include <time.h>
#include <unistd.h>

static double
utime(struct tms *tstart, struct tms *tend)
{
  return (double) (tend->tms_utime+tend->tms_stime-
                   tstart->tms_utime-tstart->tms_stime)/CLK_TCK;
}

static void
foo()
{
  int i,j,k;
  int dim=DIM;
  double a[DIM][DIM], b[DIM][DIM], c[DIM][DIM];
  double *att, *bt, *at1, *bt1;
  double t00,t01,t10,t11;
  double tu,mflops;
  struct tms tstart, tend;

  for (i=0; i < dim; i++) {
    for (j=0; j < dim; j++) {
      a[i][j] = (double) (i+1)*(j+1);
      b[i][j] = (double) (j+1)*(j+1);
    }
  }

  printf("a[0][0] = 0x%x\n", &a[0][0]);

  times(&tstart);

  for (j=0; j < dim-1 ; j+=2) {
    for (i=0; i < dim-1 ; i+=2) {
      att=a[i]; bt=b[j];
      at1=a[i+1]; bt1=b[j+1];
      t00=t01=t10=t11=0.0;

      for (k=dim; k ; k--,att++,bt++,at1++,bt1++) {
        t00 += *att * *bt;
        t01 += *att * *bt1;
        t10 += *at1 * *bt;
        t11 += *at1 * *bt1;
      }

      c[i][j]=t00;
      c[i][j+1]=t01;
      c[i+1][j]=t10;
      c[i+1][j+1]=t11;
    }
  }

  times(&tend);

  tu = utime(&tstart, &tend);
  printf("user time for %d x %d is %f\n",dim,dim,tu);

  mflops = 2.0 * pow((double)dim,3.0) / (1000000.0*tu);
  printf("that's %f Mflops\n",mflops);

  times(&tstart);

  for (j=0; j < dim-1 ; j+=2) {
    bt=b[j]; bt1=b[j+1];
    for (i=0; i < dim-1 ; i+=2) {
      att=a[i]; at1=a[i+1];
      t00=t01=t10=t11=0.0;

      for (k=0; k < dim; k++) {
        t00 += att[k] * bt[k];
        t01 += att[k] * bt1[k];
        t10 += at1[k] * bt[k];
        t11 += at1[k] * bt1[k];
      }

      c[i][j]=t00;
      c[i][j+1]=t01;
      c[i+1][j]=t10;
      c[i+1][j+1]=t11;
    }
  }

  times(&tend);

  tu = utime(&tstart, &tend);
  printf("user time for %d x %d is %f\n",dim,dim,tu);

  mflops = 2.0 * pow((double)dim,3.0) / (1000000.0*tu);
  printf("that's %f Mflops\n",mflops);

  times(&tstart);

  for (j=0; j < dim ; j++) {
    for (i=0; i < dim ; i++) {
      t00=0.0;

      for (k=0; k < dim; k++) {
        t00 += a[i][k] * b[j][k];
      }
      c[i][j]=t00;
    }
  }

  times(&tend);

  tu = utime(&tstart, &tend);
  printf("user time for %d x %d is %f\n",dim,dim,tu);

  mflops = 2.0 * pow((double)dim,3.0) / (1000000.0*tu);
  printf("that's %f Mflops\n",mflops);
  printf("\n");
}

static void
foo2()
{
  int i=0;
  double d=0;
  printf("foo2: %x %x\n",&i,&d);
  foo();
}

static void
foo3()
{
  int i=0;
  double d=0;
  int j=0;
  double e=0;
  printf("foo3: %x %x\n",&i,&d);
  printf("foo3: %x %x\n",&j,&e);

  foo();
  foo2();
}

int
main(int argc, char *argv[])
{
  foo();
  foo2();
  foo3();

  return 0;
}

=====================================================================



--
Edward Seidl                       Sandia National Laboratories, California     
seidl@janed.com                    Department 8117, MS 9214                   
(510) 294-3693 (voice)             Livermore, CA 94551                   
(510) 294-2234 (fax)                                                     
Technical Details
Message-ID: <199701301716.JAA06279@jutland.ca.sandia.gov>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,32ac409e6545f04c,start
X-Google-Attributes: gid113d02,public
From: etseidl@jutland.ca.sandia.gov (Edward Seidl)
Subject: x86 -malign-double ignored sometimes
Date: 1997/01/30
Message-ID: <199701301716.JAA06279@jutland.ca.sandia.gov>
X-Deja-AN: 213278974
sender: bug-gcc-request@prep.ai.mit.edu
x-gateway: relay7.UU.NET from bug-gcc to gnu.gcc.bug; Thu, 30 Jan 1997 12:17:09 EST
x-authentication-warning: jutland.ca.sandia.gov: etseidl@localhost didn't use HELO protocol
newsgroups: gnu.gcc.bug