🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #581

call and return speed (was: Register windows)

#581
From: Anton Ertl
Date: Sun, 08 Nov 2026 06:33
114 lines
5587 bytes
antispam@fricas.org (Waldek Hebisch) writes:
>The other is generated by the perl program below.
>Generated code contains only calls and returns

Which reminded me that I also have a microbenchmark that performs
calls to empty functions: 9 such calls to 5 different empty functions
in a row, and then a call to a function that does a little more than
nothing (including a conditional branch), then a jump back.  The
overall instruction count is 2.7 per call on AMD64.  And I have
results for that for a variety of microarchitectures.  You find the
results at the first column of
<https://www.complang.tuwien.ac.at/forth/threading/>.  See below for
your code.

In terms of cycles, Lion Cove (Core Ultra 225 P-core) is remarkable:
it takes just one cycle per call-return pair.  Here the
microarchitecture clearly is doing miraculous things; maybe inlining
in the microcode cache?

Next, we have the Cortex-A76 with 2.24 cycles per call.  Given the
clock rate of the Cortex-A76, it is plausible that it manages to push
something on the return-address stack in one cycle and pull it from
the return-address stack and use it for prediction in the next cycle.

Next, we have the Goldmont (predecessor to the present Intel E-cores)
with 2.88 cycles per call.  Similar considerations apply as for the
Cortex-A76.  What is interesting here is that the next
microarchitecture in this family, the Goldmont+, shows a much worse
result for this microbenchmark; this continues with further family
members Tremont and Gracemont, until finally Skymont gets down to 3.51
cycles.  My guess is that a big redesign of the branch predictor
happened in the Goldmont+ (compare also the, e.g., direct columns for
these processors), and the case "return from a very recent call"
became a victim of the redesign, and was only optimized again in
Skymont.

>-----------<cut here>---------------
>print << 'EOD1';
>        .file   "fib3c.pl"
>
>EOD1
>
>my($j);
>
>for($j = 2; $j < 50; $j++) {
>    my($k) = $j - 1;
>    my($l) = $j - 2;
>print << "EOD2";
>        .globl  fib$j
>        .type   fib$j, \@function
>fib$j:
>        call    fib$k
>        call    fib$l
>        ret
>        .size   fib$j, .-fib$j
>EOD2
>}
>-----------<cut here>---------------

I completed this as follows:

A C program fib.c with the following source code:

----------------
extern void fib49();

int main()
{
  fib49();
  return 0;
}

void fib1()
{
}

void fib0()
{
}
--------------------

And build and run the whole thing as follows:

perl fib3c.pl >fib.s
gcc -Wall -O fib.c fib.s -o fib
taskset -c 1 perf stat -c cycles:u -e instructions:u fib

fib benchmark executes 50_345_190_769 instructions, i.e., about
25_172_595_384 calls.

The Lion Cove takes 61_452_053_514 cycles, i.e., 2.44 cycles per call.
If half of the calls take 1 cycle (as seen in the subroutine
microbenchmark), the other half (which contains a call) take 3.88
cycles on average.  Or maybe the limited depth of the return-address
stack plays a role.  There are 6_448_145 branch mispredictions
reported, which are likely the result of the limited depth of the
return-address stack.  These mispredictions would typically account
for ~130M cycles, i.e, only 0.2% of the total cycles.  So the major
aspect seems to be how fast the handling of the return-address stack
works, and possible limitations of the optimization that produced the
miraculous 1 cycle/call on subroutine.

The Skymont takes 376_693_549_679 cycles, i.e., 14.96 cycles per call.
This is high, whatever the explanation is.  The number of branch
mispredictions is reported as 7_511, so either the return-address
stack is more than 40 or so deep or mispredictions from returns are
not counted on Skymont.

In any case, fib3 tests things that subroutine does not test.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Technical Details
Message-ID: <2026Nov8.073301@mips.complang.tuwien.ac.at>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <vpufbv$4qc5$1@dont-email.me> <1792870082-5857@newsgrouper.org> <11bj58a$327li$1@dont-email.me> <2026Oct26.193309@mips.complang.tuwien.ac.at> <11bob96$3af$2@gal.iecc.com> <11bpggu$1961c$1@dont-email.me> <1793120292-5857@newsgrouper.org> <2026Oct29.171118@mips.complang.tuwien.ac.at> <1793296454-5857@newsgrouper.org> <2026Oct29.190945@mips.complang.tuwien.ac.at> <11cnj5a$36etq$1@paganini.bofh.team> <2026Nov7.190141@mips.complang.tuwien.ac.at> <11couac$3eeoe$1@paganini.bofh.team>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: call and return speed (was: Register windows)
Date: Sun, 08 Nov 2026 06:33:01 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 114
Message-ID: <2026Nov8.073301@mips.complang.tuwien.ac.at>
References: <vpufbv$4qc5$1@dont-email.me> <1792870082-5857@newsgrouper.org> <11bj58a$327li$1@dont-email.me> <2026Oct26.193309@mips.complang.tuwien.ac.at> <11bob96$3af$2@gal.iecc.com> <11bpggu$1961c$1@dont-email.me> <1793120292-5857@newsgrouper.org> <2026Oct29.171118@mips.complang.tuwien.ac.at> <1793296454-5857@newsgrouper.org> <2026Oct29.190945@mips.complang.tuwien.ac.at> <11cnj5a$36etq$1@paganini.bofh.team> <2026Nov7.190141@mips.complang.tuwien.ac.at> <11couac$3eeoe$1@paganini.bofh.team>
Injection-Date: Sun, 08 Nov 2026 07:34:55 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="150029"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19EvFy+gXW0/bu0sqgT7Vtl"; posting-host="87833ee079892eac821fb6ff54eb825f"
Cancel-Lock: sha1:lPbj5PCHWekrx4jaqG02GrIBsuA= sha256:vtHMpH7qXtJ5WDaoxyfVFU+Ak44LGACN8IYeSICpFNs=
	sha1:oqZ0bdZ923p/OrfZ2XB/DGiWfOc= sha256:9Rw60rXuJZmcSpOvwSNs9PYngyosMyzMOEleuU7C1EI=
X-newsreader: xrn 10.11