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]
Other format: [Raw text]

Re: [RFC] Contributing tree-ssa to mainline


On Sat, 2004-01-17 at 00:52, Per Bothner wrote:
> Diego Novillo wrote:
> 
> > On Fri, 2004-01-16 at 22:24, Richard Kenner wrote:
> > 
> > 
> >>Remember that the last time we had the discussion of the timing of tree-ssa,
> >>people claimed it was "essential" for 3.5 since there was a tremendous
> >>improvement on some C++ cases.  So let's see those cases.
> >>
> > 
> > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12747
> 
> Can you give numbers?  I.e. how much faster does that (or a similar)
> testcase run?
>
Sure.  I added some of the missing bits in 12747's test program to make
it executable (attached).  The binary produced by mainline executes in
28.62 seconds.  The one produced by tree-ssa executes in 10.57 seconds
(average over 3 runs).

As with any benchmark, the fact that we do good here cannot be
extrapolated to any other random piece of code.

[ apologies to our C++ experts for butchering the test case. ]


Diego.
#include <string.h>
#include <stdlib.h>

class BitRef;

class BitVector
{
public:

    BitVector (unsigned nbits) : m_size(nbits)
      {
	m_data = (unsigned long *)malloc (m_size*sizeof(unsigned long));
      }

    BitVector (const BitVector &orig) : m_size (orig.size())
      {
	m_data = (unsigned long *)malloc (m_size*sizeof(unsigned long));
	memcpy(m_data,orig.m_data,m_size);
      }

    BitVector & operator= (const BitVector &orig)
      {
	m_size = orig.size();
	m_data = (unsigned long *)malloc (m_size*sizeof(unsigned long));
	memcpy(m_data,orig.m_data,m_size);
      }

   ~BitVector ()
     {
       free (m_data);
     }
  unsigned size () const
  {
    return m_size;
  }
  bool getBit (unsigned idx)
    {
      return m_data[idx] != 0;
    }

  void setBit (unsigned idx, bool value)
    {
      m_data[idx] = (unsigned long)value;
    }

  inline BitRef operator[] (unsigned idx);
//private:
  unsigned long *m_data;
  unsigned m_size;
};

class BitRef
{
public:
  BitRef (BitVector & bv, unsigned idx):m_bv (bv), m_idx (idx)
  {
  }
  bool value () const
  {
    return m_bv.getBit (m_idx);
  }
  operator  bool () const
  {
    return value ();
  }
  BitRef & operator= (bool newVal)
  {
    m_bv.setBit (m_idx, newVal);
    return *this;
  }
  BitRef & operator= (const BitRef & newVal)
  {
    m_bv.setBit (m_idx, newVal.value ());
    return *this;
  }
private:
  BitVector & m_bv;
  unsigned m_idx;
};

inline BitRef
BitVector::operator[] (unsigned idx)
{
  return BitRef (*this, idx);
}

// abstract copy: compiler should be able to make this as fast as copy_2
void
copy (BitVector & dest, BitVector & src)
{
  unsigned
    sz = dest.size ();
  for (unsigned i = 0; i < sz; i++)
    dest[i] = src[i];
}

// direct copy, without proxy objects.
void
copy_2 (BitVector & dest, BitVector & src)
{
  unsigned
    sz = dest.size ();
  for (unsigned i = 0; i < sz; i++)
    dest.setBit (i, src.getBit (i));
}

main()
{
  BitVector bv1(30000), bv2(30000);
  int i;

  for (i = 0; i < 50000; i++)
    copy (bv1, bv2);
}

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