🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

61 total messages Page 2 of 2 Started by John Savard Sat, 24 Oct 2026 00:05
Page 2 of 2 • 61 total messages
Re: Register windows (was: Why VAX Was the Ultimate CISC and Not RISC)
#490
Author: MitchAlsup
Date: Sat, 31 Oct 2026 18:22
141 lines
7686 bytes
anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:

> MitchAlsup <user5857@newsgrouper.org.invalid> writes:
> >anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
> >
> >> MitchAlsup <user5857@newsgrouper.org.invalid> writes:
> >> >anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
> >> >> In a modern
> >> >> (post-1995, with a few exceptions, most of which have died out in the
> >> >> meantime) processor the front end predicts the return from the
> >> >> processor-internal return stack and often starts fetching from there
> >> >> before the load-store unit sees the load of the return address.  The
> >> >> return address is then used to validate the branch prediction and
> >> >> retire the return instruction.
> >> >
> >> >You can't predict until you are within <about> 2-fetch cycles of the
> >> >instruction you are going to make a prediction about {RET here}.
> >> 
> >> Predictors can make predictions about anything.  But given that it is
> >> only useful to make predictions that are actually used, they will only
> >> predict the next few I-cache lines to be fetched, so yes, predicting a
> >> few fetch lines ahead could be common.
> >> 
> >> How many?  Depends on the latency of the I-cache.  Given that it is
> >> typically similar in size to the D-cache, it's latency will also be
> >> similar, i.e., around 4 cycles.
> >> 
> >> How many cache lines are fetched per cycle?  With a 10-wide front end,
> >> you probably do not want to underutilize the rest of the front end if
> >> there is a taken branch or there is a branch to a target less than 10
> >> instructions from the end of the cache line, so better fetch two cache
> >> lines per cycle.
> >
> >A cache line contains 16 instructions, so one would assume a partial
> >line is held over (to the next decode cycle) and one makes 1 fetch
> >in the sequential direction and 1 fetch to another predicted address.
> 
> With this design the rest of the front end would not be fully utilized
> if there are is more than on taken branch per n instructions (where n
> is the decode width).  With 10-wide designs, that's restrictive.

Remember, I am only shooting at a 6-wide machine. and for 6-wide, 1-
prediction per cycle is not very restrictive. Also note: I have 
conditional PREDicates which take 20% of front-end-redirects away.

K9 was 8-wide and we did have 2-predictions per cycle to deal with.

> I have programs here that have more than 1 taken branch on 10
> instructions:
> 
> perf stat -e instructions:u -e br_inst_retired.near_taken:u ./magichex 3 2
> ...
> 143280237      instructions:u
>  16156505      br_inst_retired.near_taken:u
> 
> That's 8.9 instructions per taken branch.

My statistics are low 9.x inst per taken branch.
 
> perf stat -e instructions:u -e br_inst_retired.near_taken:u gforth-fast --no-dynamic onebench.fs
> 4249141031      instructions:u
>  661631554      br_inst_retired.near_taken:u
> 
> That's 6.4 instructions per taken branch.
> 
> Although, admittedly, in the last case if we take the "--no-dynamic"
> away, this reduces the number of taken branches more than the number
> of instructions, resulting in more than 10 instructions per taken
> branch:
> 
> 2026987196      instructions:u
>  175323098      br_inst_retired.near_taken:u
> 
> But it uses dynamic native-code generation, which you have poo-pooed
> as "self-modifying code",

I have indeed.

>                           so presumably My 66000 will have to fall
> back to --no-dynamic and will have to take at least 661M cycles for
> this benchmark if it can only deal with one taken branch per cycle,
> whereas even a lowly Darkmont (Core Ultra 225 E-Core) can run this
> benchmark on 440M cycles.

If --no-dynamic has to do with dynamically loaded libraries, ABI 
allows for them via GOT (without PLT saving a branch in the process).
 
> >I have numerous examples of RISC-V (LLVM -O3) having 13 STs in prologue
> >and 13 LDs in epilogue. The distribution (excepting for leaf functions
> >(0 saved) and director functions (1 saved) is basically a Bell Curve
> >from 2->13.)
> 
> It's interesting that you have numerous examples of needing 13
> callee-saved registers for non-leaf functions, but apparently the 16
> caller-saved registers are enough for the leaf functions; i.e., there
> is not a single leaf function that needs more than 16 registers (the
> number of caller-saved registers in the RISC-V ABI).

There are leaf functions which need more than 16 registers--where did I
imply otherwise--there are "just not many".
 
> >> It does not
> >> need to decode the return instruction to predict it, it just needs to
> >> predict that there will be a return, and then use the hardware return
> >> stack to make the prediction.
> >
> >Maybe predictors have gotten that good.
> 
> They have to.  You cannot afford to wait to decode a branch before
> starting to predict it when you need to be able to deal with 1-2 taken
> branches per cycle.

Which is why we built the packet cache for Mc 88120 and a trace cache 
for K9. Mc 88120 could take all conditional branches per cycle and 1
conditional branch per cycle. K9 could take all unconditional and 2
conditional branches per cycle.

>                      If you wait for the fetch and the decode before
> starting to predict, you will see at most 1 taken branch every n
> cycles, where n=fetch_latency+decode_latency+predictor_latency, i.e.,

I see fetch-latency running concurrently with predictor-latency.
I do not see DECODE-latency getting in the way.

> >5 cycles on a modern CPU, possibly more like 10 cycles.  With one
> taken branch every 10 instructions or so, this would limit your IPC to
> 1-2, and much of the 10-wide design would starve.

Fetching as described above, and with annotation as above; I don't
see a problem feeding DECODE with 6-instructions per cycle. Remember
that 10-wide machine is only retiring 3 I/c.
 
> >No, of course not. Leaf functions (93%) save no registers at all as they
> >perform their duties in the freely-available temporary registers R0..15
> 
> If a leaf function needs more GPRs, it use callee-saved registers, and
> will save them in the prologue and load them in the epilogue.

Captain Obvious strikes again.
 
> - anton
Re: Register windows (was: Why VAX Was the Ultimate CISC and Not RISC)
#495
Author: Anton Ertl
Date: Sat, 31 Oct 2026 19:15
47 lines
3517 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> writes:
>anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
>> if we take the "--no-dynamic" away
...
>> But it uses dynamic native-code generation, which you have poo-pooed
>> as "self-modifying code",
>
>I have indeed.

>If --no-dynamic has to do with dynamically loaded libraries, ABI 
>allows for them via GOT (without PLT saving a branch in the process).

No, --no-dynamic falls back to using a threaded-code interpreter,
while --dynamic (default) uses native code generated at run-time (what
you call "self-modifying code" and want to disable; other people call
it "JIT compilation").

>There are leaf functions which need more than 16 registers--where did I
>imply otherwise--there are "just not many".

Here:
>> >Leaf functions (93%) save no registers at all as they
>> >perform their duties in the freely-available temporary registers R0..15

>Remember
>that 10-wide machine is only retiring 3 I/c.

I regularly see programs with >3IPC on 5-wide, 6-wide and 8-wide
machines.  E.g., for "gforth-fast onebench.fs" mentioned above on a
Darkmont (Core Ultra 225 E-Core).

  424_922_809      cpu_atom/cycles:u/
2_044_802_828      cpu_atom/instructions:u/         #    4.81  insn per cycle

A few weeks ago <2026Sep21.171615@mips.complang.tuwien.ac.at> I
reported measuring 6.75 IPC on a Rocket Lake, which is usually
considered to be 5-wide, and with reason (only 5 renamer slots etc.).
Here we see 7 IPC in a loop because the loop contains two cmp+branch
combinations, which consume only one slot in the path from the
microcode cache through the renamer to the schedulers.  Both branches
are taken in the measured loop, i.e., 1 taken branch every 3.5
instructions.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Re: Register windows (was: Why VAX Was the Ultimate CISC and Not RISC)
#498
Author: MitchAlsup
Date: Sat, 31 Oct 2026 20:44
64 lines
4044 bytes
anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:

> MitchAlsup <user5857@newsgrouper.org.invalid> writes:
> >anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
> >> if we take the "--no-dynamic" away
> ...
> >> But it uses dynamic native-code generation, which you have poo-pooed
> >> as "self-modifying code",
> >
> >I have indeed.
> 
> >If --no-dynamic has to do with dynamically loaded libraries, ABI 
> >allows for them via GOT (without PLT saving a branch in the process).
> 
> No, --no-dynamic falls back to using a threaded-code interpreter,
> while --dynamic (default) uses native code generated at run-time (what
> you call "self-modifying code" and want to disable; other people call
> it "JIT compilation").
> 
> >There are leaf functions which need more than 16 registers--where did I
> >imply otherwise--there are "just not many".
> 
> Here:
> >> >Leaf functions (93%) save no registers at all as they
> >> >perform their duties in the freely-available temporary registers R0..15
> 
> >Remember
> >that 10-wide machine is only retiring 3 I/c.
> 
> I regularly see programs with >3IPC on 5-wide, 6-wide and 8-wide
> machines.  E.g., for "gforth-fast onebench.fs" mentioned above on a
> Darkmont (Core Ultra 225 E-Core).
> 
>   424_922_809      cpu_atom/cycles:u/
> 2_044_802_828      cpu_atom/instructions:u/         #    4.81  insn per cycle
> 
> A few weeks ago <2026Sep21.171615@mips.complang.tuwien.ac.at> I
> reported measuring 6.75 IPC on a Rocket Lake, which is usually
> considered to be 5-wide, and with reason (only 5 renamer slots etc.).
> Here we see 7 IPC in a loop because the loop contains two cmp+branch
> combinations, which consume only one slot in the path from the
> microcode cache through the renamer to the schedulers.  Both branches
> are taken in the measured loop, i.e., 1 taken branch every 3.5
> instructions.

I see similar (at a smaller scale) when my cores perform CoIssue
(similar to instruction fusing, but designed to leverage RF ports
across instructions. A CoIssued instruction requires no more RF
ports or rename ports than any 'random' instruction can use.

Since STs do not write to RF, STs can be CoIssued with any following
calculation instruction (or branch instruction).

Since conditional Branch instructions do not write RF, they can be
CoIssued with previous calculation instruction.

STs and <conditional> branches make up 30%-odd of instruction stream:
so, the decoder looks to be processing 1.3 I/c in a 1-wide implementa-
tion.

There are other potentials--but since this is not close to RISC-V's
instruction fusing, I had to use a different word.
> 
> - anton
Re: Register windows
#557
Author: Paul Clayton
Date: Thu, 05 Nov 2026 03:45
150 lines
9428 bytes
On 10/31/26 4:44 PM, MitchAlsup wrote:
[snip]
> I see similar (at a smaller scale) when my cores perform CoIssue
> (similar to instruction fusing, but designed to leverage RF ports
> across instructions. A CoIssued instruction requires no more RF
> ports or rename ports than any 'random' instruction can use.

I think I would view CoIssue as a limited form of superscalar
execution that has fine-grained hazard detection.

With support for worst-case execution of three-source, one-
destination instructions (e.g., no source coming from the
forwarding network) and wide fetch (reducing fetch energy),
there would be more opportunities for two-wide execution in a
nominally one-wide design.

I would guess that even two-way register banking would expose
even more opportunities for dual issue at the cost of more
complex hazard detection. (A 50% chance of two-wide issue
enabled when base CoIssue is prevented only from the two
instructions each having a register destination. Clever register
allocation could increase the frequency of two-wide execution.)
Adding such execution opportunities might then incentivize
increasing execution resources, pushing the design closer to a
conventional two-wide superscalar.

(Even wider register access support for load/store multiple
operations — ENTER/EXIT, context switch, etc. — might sometimes
effectively provide more register ports, though I would have
guessed that banking would not have that much more overhead.)

Supporting two register destinations would presumably complicate
the forwarding; limited forwarding would introduce another
hazard to detect and potentially extend such to single issue.

Borrowing across cycles could also support wider execution.
E.g., if two instructions cannot CoIssue because both
instructions read two registers, the earlier instruction could
CoIssue with a pseudo-instruction that moves one register source
from the later instruction into a buffer. The next cycle the
first instruction would have only one register source (and one
buffer source), and so would have a better chance of being
eligible for CoIssue.

Stores may also tolerate delayed register read. An indexed
store might normally be ineligible for CoIssue (having three
register sources), but might be able to borrow a register
read port from the next cycle.

[I do wonder if it would be practical to detect/express that a
result is only stored. A Decoupled Access/Execute architecture
could simply use a register name to indicate result being sent
to the store queue (execute-to-access queue). This effectively
partially fuses a computation instruction and a potentially
substantially later store instruction, removing the need for
allocating a destination physical register and using a register
write port and possibly a register read port for the store (the
store data might be supplied by ordinary forwarding in a
conventional design).]

Dependent instructions would present opportunities for later
wider execution as one register operand would be from the
forwarding network and one or more register sources could be
read earlier and buffered.

Borrowing a register write might also be possible. With a
memory-access stage before writeback (classic 5-stage pipeline),
it might be possible for the register write slot from an
immediately previous no-register-write execution to be borrowed
(inserting the write into the second forwarding slot). Borrowing
a write slot from the following execution cycle

> Since STs do not write to RF, STs can be CoIssued with any following
> calculation instruction (or branch instruction).

Presumably excluding indexed loads, which read three register 
sources? With four register read ports, an indexed load could
CoIssue with an immediate-using calculation instruction (or an
instruction getting one source from the forwarding network), but
I thought only three read ports were the design target.

> Since conditional Branch instructions do not write RF, they can be
> CoIssued with previous calculation instruction.

Presumably this is not possible if the branch is dependent on
the result of the calculation instruction.

(A branch might also be CoIssued with a following calculation
instruction if the calculation instruction can be annulled,
which might not require much more hardware if predication is
implemented by suppressing register writes when the predicate
evaluation is delayed. This wastes some energy.)

> STs and <conditional> branches make up 30%-odd of instruction stream:
> so, the decoder looks to be processing 1.3 I/c in a 1-wide implementa-
> tion.
> 
> There are other potentials--but since this is not close to RISC-V's
> instruction fusing, I had to use a different word.

It is not clear to me that a separate term is needed. How is
CoIssue distinct from superscalar execution with management of
register read and write port hazards? Not having to look at the
register names to determine potential CoIssue has some
advantage, but a one-register source instruction could also
CoIssue with a two-register source if two register destinations
were supported without looking at the register names. If two-way
banking was used only one bit from each instruction would have
to be compared to enable two register writes. (The extra
forwarding complexity to support two register writes might make
more general superscalar execution a better choice.)

If register port count is the primary constraint, a three-read, 
one-write register file could support a slightly broader set of
instruction pairings. Two-read, one-write, and one-read/write
could support even more diverse pairings, some detectable just
from the opcode (two one register source instructions). Two-way
banking presents even more two-wide execution opportunities.

An instruction following an instruction with a register
destination would have to check for a dependency, which would
presumably delay register read or force instruction result 
nullification and instruction replay (wasting energy and adding
some complexity). Since a branch can CoIssue with a previous
calculation instruction, this case already needs to handle a
potential dependency.

A skewed or second-chance pipeline (skewed: address generation 
is one or more stages before execute; second-chance: branch and
perhaps other instructions can execute in an earlier execute
stage with address generation or a later stage) is another
superscalar variation. (Counterflow pipelines [Robert F. Sproull 
et al., "Counterflow Pipeline Processor Architecture", 1994] are
reminiscent of second-chance pipelines and cascaded execution.)

1.3 wide execution may be preferred over 1 wide or 1.9x wide
(not allowing two memory access instructions, two multiplies,
or two branches, but allowing most other instruction pairings);
faster than 1 wide and simpler than 1.9x wide. Such would also
be faster on integer code than early FPR+GPR superscalar. Not
being a hardware designer, I do not have a feel for how much
complexity (and delay) more flexible superscalar would add.
*IF* register file port count is the _only_ significant
constraint, more general two-wide execution seems reasonable.
A lot of instructions use an immediate for one operand or
get an operand from the forwarding network, and banking would
increase the effective port count. Yet I must assume that
CoIssue is a good design point, which indicates that hardware
overheads (and not mere design complexity) make 1.5 wide
execution excessively expensive.
Re: Register windows
#565
Author: Waldek Hebisch
Date: Sat, 07 Nov 2026 16:21
47 lines
2964 bytes
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
> MitchAlsup <user5857@newsgrouper.org.invalid> writes:
>>anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
>>> There is a third issue: Do you pass arguments in the register windows,
>>> or in what SPARC calls global registers?  AFAIK SPARC chose to pass
>>> them in windows, but that means that a call sequence like
>>> 
>>> int foo(a,b)
>>> {
>>>   ...
>>>   bar(a,b);
>>>   ...
>>> }
>>
>>It gets worse when::
>>
>>  type foo( a, b ){
>>      ...
>>      return bar( a, b );
>>      ...
>>  }
>>
>>Now you have to copy forward foo->bar and copy bar's return back
>>as foo's return.
> 
> No, it's a tail-call.  You just jump to bar without saving or
> restoring a register window.
> 
>>My 66000 takes advantage of this by LDing the Ret Addr first, and then
>>reLDing the rest of the file, so by the time that is done, FETCH already
>>has instructions for DECODE>
> 
> I get the impression that My 66000 lives in 1994.  In a modern
> (post-1995, with a few exceptions, most of which have died out in the
> meantime) processor the front end predicts the return from the
> processor-internal return stack and often starts fetching from there
> before the load-store unit sees the load of the return address.  The
> return address is then used to validate the branch prediction and
> retire the return instruction.

It must be more complex.  Silly fibonacci benchmark shows average
performance of function call per 2 clocks.  Given length of
the pipeline return address is pushed too late to use it for
fetching intructions after return.  In other words, return
must be predicted before the call starts executing.
-- 
                              Waldek Hebisch
Re: Register windows
#569
Author: Anton Ertl
Date: Sat, 07 Nov 2026 18:01
44 lines
3534 bytes
antispam@fricas.org (Waldek Hebisch) writes:
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>> In a modern
>> (post-1995, with a few exceptions, most of which have died out in the
>> meantime) processor the front end predicts the return from the
>> processor-internal return stack and often starts fetching from there
>> before the load-store unit sees the load of the return address.  The
>> return address is then used to validate the branch prediction and
>> retire the return instruction.
>
>It must be more complex.  Silly fibonacci benchmark shows average
>performance of function call per 2 clocks.

Without inlining?  On what hardware?

What I see on a Rocket Lake with a Fibonacci program compiled by the
Rust 1.89 compiler is 3.6 cycles per return (i.e., also per call, with
2.3 branches per return).  I have not looked at the code to see if
there is any inlining, but given that a regular fibonacci call
includes a call, a conditional branch, and a return (with any
recursive call accounted separately), showing 2.3 branches indicates
that there is at least some inlining going on here.

>Given length of
>the pipeline return address is pushed too late to use it for
>fetching intructions after return.  In other words, return
>must be predicted before the call starts executing.

Certainly.  Modern branch predictors have to trigger on addresses, not
on the results of fetches.  But if a microarchitecture really does a
non-inlined fibonacci program at two cycles per call, even more
prediction has to be done: In the base case (half of the calls) the
push to the return address stack is followed by a pull from the return
address stack, and all of that and the prediction based on the return
address must happen in two cycles.  Or maybe there is some special
fast path for such cases.

What the microarchitects do in the branch predictors is certainly
amazing.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Re: Register windows
#579
Author: Waldek Hebisch
Date: Sun, 08 Nov 2026 04:37
77 lines
3953 bytes
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
> antispam@fricas.org (Waldek Hebisch) writes:
>>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>> In a modern
>>> (post-1995, with a few exceptions, most of which have died out in the
>>> meantime) processor the front end predicts the return from the
>>> processor-internal return stack and often starts fetching from there
>>> before the load-store unit sees the load of the return address.  The
>>> return address is then used to validate the branch prediction and
>>> retire the return instruction.
>>
>>It must be more complex.  Silly fibonacci benchmark shows average
>>performance of function call per 2 clocks.
> 
> Without inlining?  On what hardware?
> 
> What I see on a Rocket Lake with a Fibonacci program compiled by the
> Rust 1.89 compiler is 3.6 cycles per return (i.e., also per call, with
> 2.3 branches per return).  I have not looked at the code to see if
> there is any inlining, but given that a regular fibonacci call
> includes a call, a conditional branch, and a return (with any
> recursive call accounted separately), showing 2.3 branches indicates
> that there is at least some inlining going on here.

A little correction.  This is on AMD Ryzen 9 7900 with claims
3.0 GHz clock.  But perf says that benchmark run at 5.310 GHz,
so number of clocks is larger.  I used two versions, one produced
by gcc -O which in assembly is:

fib:
        movq    %rdi, %rax
        cmpq    $1, %rdi
        jle     .L5
        pushq   %rbp
        pushq   %rbx
        subq    $8, %rsp
        movq    %rdi, %rbx
        leaq    -1(%rdi), %rdi
        call    fib
        movq    %rax, %rbp
        leaq    -2(%rbx), %rdi
        call    fib

So performs all expected calls.  This one needs 4.6 cycles
per call.  The other is generated by the perl program below.
Generated code contains only calls and returns, for each
n there is separate function.  Call structure is exactly the
same as when computing fibonacci.  This one needs 4.01
cycles per call.  For comparison, version which replaces
final call and ret by jump (corresponding to tail call
elimination) needs 2.43 clocks per "call".

-----------<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>---------------

-- 
                              Waldek Hebisch
Re: Register windows
#580
Author: Lawrence D’Oliveiro
Date: Sun, 08 Nov 2026 04:49
13 lines
1958 bytes
On Sun, 8 Nov 2026 04:37:34 -0000 (UTC), Waldek Hebisch wrote:

> 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

Shouldn’t there be a “fib0” somewhere?
call and return speed (was: Register windows)
#581
Author: 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>
Re: Register windows
#586
Author: Waldek Hebisch
Date: Sun, 08 Nov 2026 14:19
20 lines
1977 bytes
Lawrence D’Oliveiro <ldo@nz.invalid> wrote:
> On Sun, 8 Nov 2026 04:37:34 -0000 (UTC), Waldek Hebisch wrote:
> 
>> 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
> 
> Shouldn’t there be a “fib0” somewhere?

Yes, you need 'fib0' and 'fib1'.  You can add them as Anton did,
or at assembly level just take single 'ret'.

-- 
                              Waldek Hebisch
Page 2 of 2 • 61 total messages
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads