9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Roman Shaposhnick <rvs@sun.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] Good enough approximation for ape/pcc
Date: Tue, 11 Apr 2006 14:25:04 -0700	[thread overview]
Message-ID: <20060411212504.GA193@submarine> (raw)
In-Reply-To: <3e1162e60604101707v6214a809h516a223bf5d14a06@mail.gmail.com>

On Mon, Apr 10, 2006 at 05:07:03PM -0700, David Leimbach wrote:
> On 4/10/06, Roman Shaposhnick <rvs@sun.com> wrote:
> > On Mon, Apr 10, 2006 at 04:18:56PM -0700, David Leimbach wrote:
> >   If the punch line here is, in fact, what I think it is, then
> >   a good optimizing compiler should be able to make these two
> >   pretty close in terms of performance.
>
> Perhaps... but only if the iterator is a real pointer.

  Or a carefully written one.

> So if I wrote my own datatype and implemented the same semantics that
> you'd expect for postfix ++ you'd likely find the following
> pseudocode:
>
> copy the iterator;
> increment *this;
> return the copy.

  Good. The punch line is exactly what I though it would be ;-) I mean,
  with C++ you never know.

> Do you really want to do that at the end of every loop iteration?  And
> what if I add some other logic between increment *this and return the
> copy, like some mutex locking/unlocking or whatever... the compiler is
> helpless to help my code here, and I throw out a copy in every loop.

  I guess I made a stronger statement that I wanted to. I was more concerned
  about somebody using prepackaged iterators (STL for example) not
  realizing the difference between ++a and a++. Somehow I feel that if a
  person took time to *explicitly* write the copy/return sequence (like
  you did in your example) than it would take a really unexperienced
  C++ programmer to not recognize the difference.

  Now, prepackaged iterators are usually part of the C++ environment, hence
  they can exploit all sorts of optimization opportunities available
  in that particular system (yes these are mostly pragmas, but hey -- they
  are invisible to an end user).

  Once again, don't get me wrong -- I'm not claiming that a properly written
  implementation will always equate ++a with a++ in terms of performance,
  but in certain cases it might.

> >   I've been doing optimizing compilers at Sun for quite some time
> >   now (C/C++ and Fortran) and one thing that I constantly talk
> >   to our customers about is that in todays world of opaque CPU
> >   design they actually don't know whether 'a = a + 1;' is slower
> >   or faster than 'a++;'. So the best advice I can give them
> >   is to:
> >
> >      1. Express semantics, not how to generate code
> >      2. Pick a compiler vendor you can trust.
> >      3. Make Performance Analysis part of your debugging.
>
> With C++ you need to understand the side effects of the language.  You
> could add profiling and logging to your copy constructor for that
> iterator above, but you might not understand why you're making so many
> copies, throwing them away and having to run both a constructor and a
> destructor at the bottom of the loop.

  I disagree somewhat. My point was -- that C++ is no longer the only
  thing you are supposed to understand inside and out if you really
  want to know what happens when your code gets executed. Modern hardware
  is very much that way too. Which means that it doesn't really matter
  what language you use -- you never really sure about performance
  implications of even the simplest of constructs (anybody who have touched
  Itanium even with a six foot pole would understand ;-)).

  My point was -- there's no way you can survive without #3 anyway, which
  means that instead of worrying about everything at a coding level -- just
  code away (and yes I agree -- understanding language semantics helps a
  great deal) the most clean code you can possibly afford and rely on
  performance analysis to catch surprises.

Thanks,
Roman.


  parent reply	other threads:[~2006-04-11 21:25 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-07 18:13 Fernan Bolando
2006-04-07 19:43 ` Russ Cox
2006-04-07 19:01   ` Fernan Bolando
2006-04-07 19:17     ` uriel
2006-04-07 19:57       ` David Leimbach
2006-04-07 21:52         ` Russ Cox
2006-04-07 21:07           ` David Leimbach
2006-04-08 22:39           ` Lluís Batlle i Rossell
2006-04-08 23:50             ` quanstro
2006-04-09  0:05               ` Russ Cox
2006-04-09  5:55                 ` Scott Schwartz
2006-04-09 16:56                   ` Russ Cox
2006-04-09 21:57                     ` Scott Schwartz
2006-04-09 23:04                       ` Russ Cox
2006-04-10  2:49                         ` Scott Schwartz
2006-04-10  4:19                           ` Russ Cox
2006-04-10  4:03                             ` lucio
2006-04-10  8:37                               ` Bruce Ellis
2006-04-10 14:42                                 ` Paul Lalonde
2006-04-10 11:11                               ` quanstro
2006-04-10 11:34                                 ` Brantley Coile
2006-04-10 14:09                                   ` Ronald G Minnich
2006-04-10 14:49                                     ` Paul Lalonde
2006-04-10 15:26                                       ` andrey mirtchovski
2006-04-10 22:07                                   ` Andrew Simmons
2006-04-10 23:04                                     ` Andy Newman
2006-04-10 23:18                                       ` David Leimbach
2006-04-10 23:51                                         ` Roman Shaposhnick
2006-04-11  0:07                                           ` David Leimbach
     [not found]                                             ` <3e1162e60604101707v6214a809h516a223bf5d14a06@mail.gmail.co m>
2006-04-11  1:26                                               ` Andrew Simmons
2006-04-11  2:37                                                 ` quanstro
2006-04-11  4:20                                                   ` Bruce Ellis
2006-04-11  5:40                                                     ` Skip Tavakkolian
2006-04-11  8:18                                                       ` Bruce Ellis
2006-04-11  8:56                                                         ` Charles Forsyth
2006-04-11  9:00                                                           ` Bruce Ellis
2006-04-11  8:17                                                 ` Lluís Batlle
2006-04-11 21:30                                                 ` Roman Shaposhnick
2006-04-11 22:37                                                   ` Russ Cox
2006-04-11 22:05                                                     ` Roman Shaposhnick
2006-04-11 21:25                                             ` Roman Shaposhnick [this message]
2006-04-10  9:57                             ` Charles Forsyth
2006-04-09 23:32                       ` geoff
2006-04-07 20:10     ` Russ Cox
     [not found]     ` <ba5b34e5051e1f0238a2df3f641d4598@cat-v.org>
2006-04-08  4:18       ` Fernan Bolando
2006-04-08  5:24         ` Russ Cox
2006-04-08  7:28           ` Bruce Ellis
2006-04-08 16:18             ` Rob Pike
2006-04-08 16:42               ` Bruce Ellis
2006-04-09 23:04 erik quanstrom
2006-04-10 23:51 erik quanstrom
2006-04-10 23:53 erik quanstrom
2006-04-11  0:37 erik quanstrom
2006-04-11  0:40 erik quanstrom
2006-04-11 10:18 Andrew Simmons
2006-04-11 10:55 ` Brantley Coile
2006-04-11 11:25 ` quanstro
2006-04-11 12:58 Russ Cox
2006-04-12  0:50 erik quanstrom
2006-04-12  1:09 ` Charles Forsyth
2006-04-12 11:18 ` Aharon Robbins
2006-04-12 11:31   ` R
2006-04-12 14:01   ` Russ Cox
2006-04-12 13:44     ` Charles Forsyth
2006-04-12 14:50       ` Brantley Coile
2006-04-12  1:15 erik quanstrom
2006-04-12  1:23 ` Charles Forsyth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060411212504.GA193@submarine \
    --to=rvs@sun.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).