From 1111135929860742483
X-Google-Thread: f78e5,174aa7b34b06a51
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news1.google.com!proxad.net!newsfeed.stueberl.de!newsfeed.vmunix.org!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: ben-public-nospam@decadentplace.org.uk (Ben Hutchings)
Newsgroups: comp.std.c++
Subject: Re: Is this really unspecified behavior?
Date: Sat, 24 Dec 2005 14:20:50 GMT
Organization: private site
Lines: 65
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <slrndqojcu.7l8.ben-public-nospam@decadentplace.org.uk>
References: <1132759176.368850.264850@g43g2000cwa.googlegroups.com> <H1phf.161529$zb5.99785@bgtnsc04-news.ops.worldnet.att.net> <1132933832.802917.153350@g14g2000cwa.googlegroups.com> <1133551647.532929.325730@z14g2000cwz.googlegroups.com> <1133583412.951239.208510@g49g2000cwa.googlegroups.com> <E1EjGBD-0005T8-00@chx400.switch.ch> <1133910546.716987.80030@g14g2000cwa.googlegroups.com> <E1EjzL6-0006ic-00@chx400.switch.ch> <0l5ep1ppfhdj5p1pcu7e4na4ub0vjajlq3@4ax.com> <E1Eoj80-0005p9-00@chx400.switch.ch> <87irtjy5sy.fsf@boost-consulting.com>
NNTP-Posting-Host: news.news.demon.net
X-Trace: news.demon.co.uk 1135434060 2883 158.152.254.254 (24 Dec 2005 14:21:00 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Sat, 24 Dec 2005 14:21:00 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-User-Agent: slrn/0.9.8.1 (Debian)
X-Orig-X-Trace: individual.net jj4OX72M1hklzazeByusJwwxkTZdDwdh1+mwLL89Hi03DiAY8=
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
X-Reply-To: Ben Hutchings <ben@decadentplace.org.uk>
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id jBOEKo85023277;
	Sun, 25 Dec 2005 01:20:50 +1100 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-Delivered-To: std-c++@ucar.edu
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Orig-Path: decadentplace.org.uk!news
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:2904

David Abrahams <dave@boost-consulting.com> wrote:
> hyrosen@mail.com (Hyman Rosen) writes:
<snip>
>> This hypothetical high-performance code and smart/stupid compiler is
>> a myth anyway, but people confused by order of evaluation issues are
>> all too real, ...
>
> Okay, maybe I'm one of them, and you can clear it up.  Andrew Koenig
> described why evaluation order might matter to a compiler
> (http://groups.google.com/group/comp.std.c++/msg/54716a09f97cc000).
> Do you have an argument against his post?

It *might* matter, but Sethi-Ullman numbering is not the state of the
art in code optimisation.

> Also, it seems obvious to me that in some cases at least, evaluating
> the arguments in the same order they need to be pushed onto the stack
> could be important:
>
>       g( f1(), f2(), f3() )
>
>       call  f3
>       push  r0
>       call  f2
>       push  r0
>       call  f1
>       push  r0
>       call  g
>
> If you force an ordering that conflicts with the calling convention,
> you end up with
>
>       sub   sp, #3
>       call  f1
>       mv    r0, sp+1
>       call  f2
>       mv    r0, sp+2
>       call  f3
>       mv    r0, sp+3
>       call  g
>
> What am I missing?
<snip>

First, AFAIK the only current architecture that has stack-based
calling conventions even for small numbers of function parameters is
x86, and for performance-sensitive code I suspect that will soon be
obsoleted by x86-64, which has register-based calling conventions due
to its larger register set.

Second, "push" is relatively complex and expensive even on x86;
certainly sufficiently so that current compilers already prefer
sp-relative addressing to pushing in some cases when generating code
for a function call.

-- 
Ben Hutchings
It is easier to write an incorrect program than to understand a correct one.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



