D pointers

Thomas Braxton brax108 at cox.net
Sat Oct 1 18:57:53 BST 2005


On Saturday 01 October 2005 12:16 pm, George Staikos wrote:
> On Saturday 01 October 2005 12:56, Lubos Lunak wrote:
> > Dne so 1. října 2005 17:35 George Staikos napsal(a):
> > > On Saturday 01 October 2005 11:16, Stephan Kulow wrote:
> > > > Am Samstag, 1. Oktober 2005 17:00 schrieb Thiago Macieira:
> > > > > The optimising compiler will very likely elect this->d to be cached
> > > > > in a register, just like this itself is.
> > > >
> > > > Yeah, right. Glad we have soo many registers on i386.
> > >
> > >   I'm glad someone else pointed this out.  I was trying to get out of
> > > this conversation altogether (and I will just revert changes to my own
> > > classes that I don't like), but this is a very valid point.
> >
> >  No, it's not a very valid point. Unless somebody can find a problem with
> > my KURL benchmark (which I ran on i386), the point is as valid as about
> > 2% performance loss. And BTW exactly which of your classes are
> > performance critical?
>
>    It's not a valid point that register pressure is an issue on our most
> significant platform?
This is a small test i made up to see the difference of d-pointers on register 
pressure. The test has two classes with exactly the same members, one using a 
d-pointer the other not.
Compile with g++ -O3 -g3 -fPIC -c test.cpp
the other file is the output of objdump -CSd test.o
If you look at status() in both classes you see that this{0x8(%ebp)} is 
assigned to %eax.
In withDPointer::status() this->d{(%eax)} is then assigned to %eax.
Then both assign _status{0x8(%eax)} to %eax.
register pressure doesn't look to be an issue on i386, at least w/ gcc 4.0.1.
-------------- next part --------------

test.o:     file format elf32-i386

Disassembly of section .text:

00000000 <withDPointer::withDPointer()>:
	int _jumbo;
	int _status;
};

withDPointer::withDPointer() : d(new Private)
   0:	55                   	push   %ebp
   1:	89 e5                	mov    %esp,%ebp
   3:	53                   	push   %ebx
   4:	83 ec 10             	sub    $0x10,%esp
   7:	e8 00 00 00 00       	call   c <withDPointer::withDPointer()+0xc>
   c:	5b                   	pop    %ebx
   d:	81 c3 03 00 00 00    	add    $0x3,%ebx
  13:	6a 0c                	push   $0xc
  15:	e8 fc ff ff ff       	call   16 <withDPointer::withDPointer()+0x16>
  1a:	8b 55 08             	mov    0x8(%ebp),%edx
  1d:	89 02                	mov    %eax,(%edx)
  1f:	83 c4 10             	add    $0x10,%esp
{
}
  22:	8b 5d fc             	mov    0xfffffffc(%ebp),%ebx
  25:	c9                   	leave
  26:	c3                   	ret
  27:	90                   	nop

00000028 <withDPointer::withDPointer()>:
  28:	55                   	push   %ebp
  29:	89 e5                	mov    %esp,%ebp
  2b:	53                   	push   %ebx
  2c:	83 ec 10             	sub    $0x10,%esp
  2f:	e8 00 00 00 00       	call   34 <withDPointer::withDPointer()+0xc>
  34:	5b                   	pop    %ebx
  35:	81 c3 03 00 00 00    	add    $0x3,%ebx
  3b:	6a 0c                	push   $0xc
  3d:	e8 fc ff ff ff       	call   3e <withDPointer::withDPointer()+0x16>
  42:	8b 55 08             	mov    0x8(%ebp),%edx
  45:	89 02                	mov    %eax,(%edx)
  47:	83 c4 10             	add    $0x10,%esp
  4a:	8b 5d fc             	mov    0xfffffffc(%ebp),%ebx
  4d:	c9                   	leave
  4e:	c3                   	ret
  4f:	90                   	nop

00000050 <withDPointer::~withDPointer()>:

withDPointer::~withDPointer()
  50:	55                   	push   %ebp
  51:	89 e5                	mov    %esp,%ebp
  53:	53                   	push   %ebx
  54:	83 ec 10             	sub    $0x10,%esp
  57:	e8 00 00 00 00       	call   5c <withDPointer::~withDPointer()+0xc>
  5c:	5b                   	pop    %ebx
  5d:	81 c3 03 00 00 00    	add    $0x3,%ebx
{
	delete d;
  63:	8b 45 08             	mov    0x8(%ebp),%eax
  66:	ff 30                	pushl  (%eax)
  68:	e8 fc ff ff ff       	call   69 <withDPointer::~withDPointer()+0x19>
  6d:	83 c4 10             	add    $0x10,%esp
}
  70:	8b 5d fc             	mov    0xfffffffc(%ebp),%ebx
  73:	c9                   	leave
  74:	c3                   	ret
  75:	90                   	nop
  76:	89 f6                	mov    %esi,%esi

00000078 <withDPointer::~withDPointer()>:
  78:	55                   	push   %ebp
  79:	89 e5                	mov    %esp,%ebp
  7b:	53                   	push   %ebx
  7c:	83 ec 10             	sub    $0x10,%esp
  7f:	e8 00 00 00 00       	call   84 <withDPointer::~withDPointer()+0xc>
  84:	5b                   	pop    %ebx
  85:	81 c3 03 00 00 00    	add    $0x3,%ebx
  8b:	8b 45 08             	mov    0x8(%ebp),%eax
  8e:	ff 30                	pushl  (%eax)
  90:	e8 fc ff ff ff       	call   91 <withDPointer::~withDPointer()+0x19>
  95:	83 c4 10             	add    $0x10,%esp
  98:	8b 5d fc             	mov    0xfffffffc(%ebp),%ebx
  9b:	c9                   	leave
  9c:	c3                   	ret
  9d:	90                   	nop
  9e:	89 f6                	mov    %esi,%esi

000000a0 <withDPointer::status() const>:

int
withDPointer::status() const
  a0:	55                   	push   %ebp
  a1:	89 e5                	mov    %esp,%ebp
  a3:	8b 45 08             	mov    0x8(%ebp),%eax
  a6:	8b 00                	mov    (%eax),%eax
  a8:	8b 40 08             	mov    0x8(%eax),%eax
{
	return d->_status;
}
  ab:	c9                   	leave
  ac:	c3                   	ret
  ad:	90                   	nop
  ae:	89 f6                	mov    %esi,%esi

000000b0 <withoutDPointer::withoutDPointer()>:

class withoutDPointer
{
	int _mumbo;
	int _jumbo;
	int _status;
public:
	withoutDPointer();
	~withoutDPointer();
	int status() const;
};

withoutDPointer::withoutDPointer()
  b0:	55                   	push   %ebp
  b1:	89 e5                	mov    %esp,%ebp
{
}
  b3:	c9                   	leave
  b4:	c3                   	ret
  b5:	90                   	nop
  b6:	89 f6                	mov    %esi,%esi

000000b8 <withoutDPointer::withoutDPointer()>:
  b8:	55                   	push   %ebp
  b9:	89 e5                	mov    %esp,%ebp
  bb:	c9                   	leave
  bc:	c3                   	ret
  bd:	90                   	nop
  be:	89 f6                	mov    %esi,%esi

000000c0 <withoutDPointer::~withoutDPointer()>:

withoutDPointer::~withoutDPointer()
  c0:	55                   	push   %ebp
  c1:	89 e5                	mov    %esp,%ebp
{
}
  c3:	c9                   	leave
  c4:	c3                   	ret
  c5:	90                   	nop
  c6:	89 f6                	mov    %esi,%esi

000000c8 <withoutDPointer::~withoutDPointer()>:
  c8:	55                   	push   %ebp
  c9:	89 e5                	mov    %esp,%ebp
  cb:	c9                   	leave
  cc:	c3                   	ret
  cd:	90                   	nop
  ce:	89 f6                	mov    %esi,%esi

000000d0 <withoutDPointer::status() const>:

int
withoutDPointer::status() const
  d0:	55                   	push   %ebp
  d1:	89 e5                	mov    %esp,%ebp
  d3:	8b 45 08             	mov    0x8(%ebp),%eax
  d6:	8b 40 08             	mov    0x8(%eax),%eax
{
	return _status;
}
  d9:	c9                   	leave
  da:	c3                   	ret

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cpp
Type: text/x-c++src
Size: 631 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20051001/63c56dfc/attachment.cpp>


More information about the kde-core-devel mailing list