From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu Date: Fri, 22 Feb 2008 10:02:23 +0000 From: "Douglas A. Gwyn" Message-ID: <47BDEB14.B9DCA12D@null.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit References: <5d375e920802171343p323a2708m9f193ae24d2c14e5@mail.gmail.com>, <47BC116F.3060906@proweb.co.uk> Subject: Re: [9fans] Non-stack-based calling conventions Topicbox-Message-UUID: 5ec17a8e-ead3-11e9-9d60-3106f5b1d025 maht wrote: > For the C version there's all sorts of pushing and popping return > addresses and arguments on to the stack > float > sqr(x float) > { > return x * x; > } > float > hyp(x float, y float) > { > return sqrt(sqr(x) + sqr(y)); > } [Assuming that the code is corrected and the types made compatible with the argument to sqrt.] The extra overhead occurs only because of the support for full recursion, with private instance data. Many C compilers dating back to around 1980 will in-line the calls to sqr, so the effect is: hyp: mul r2,r2,r2 mul r3,r3,r3 add r2,r3,r2 jmp sqrt It's hard to imagine anything more efficient (except when hyp itself can be in-lined.) Details of course depend on the machine architecture and linkage convention; the above is modeled loosely after the M*CORE, which is very nice in this respect.