Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

An adequate bootstrap is a contradiction in terms.


devel / comp.arch / Naive question; Branch Prediction

SubjectAuthor
* Naive question; Branch Predictiongareth evans
+- Re: Naive question; Branch PredictionTerje Mathisen
`* Re: Naive question; Branch PredictionMitchAlsup
 +* Re: Naive question; Branch PredictionStephen Fuld
 |`- Re: Naive question; Branch PredictionBGB
 `* Re: Naive question; Branch PredictionThomas Koenig
  `- Re: Naive question; Branch PredictionMitchAlsup

1
Naive question; Branch Prediction

<sha4pm$ro3$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20341&group=comp.arch#20341

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: headston...@yahoo.com (gareth evans)
Newsgroups: comp.arch
Subject: Naive question; Branch Prediction
Date: Wed, 8 Sep 2021 11:54:45 +0100
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <sha4pm$ro3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 8 Sep 2021 10:54:46 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d7796515fce32ae55b5d503048903c3a";
logging-data="28419"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18I7uVhwEkYXRc2DtEoLzCa"
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:JHx5wbKR/bR4SkRYLy41TZCVJRk=
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: gareth evans - Wed, 8 Sep 2021 10:54 UTC

There must be some background processing taking place at
a speed that is greater than the execution of program
instructions in order to estimate a future branch prediction.

OK; so why isn't that faster processing given over to
the instructions themselves?

Re: Naive question; Branch Prediction

<shaa6b$1f8i$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20342&group=comp.arch#20342

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!ppYixYMWAWh/woI8emJOIQ.user.46.165.242.91.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Naive question; Branch Prediction
Date: Wed, 8 Sep 2021 14:26:51 +0200
Organization: Aioe.org NNTP Server
Message-ID: <shaa6b$1f8i$1@gioia.aioe.org>
References: <sha4pm$ro3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="48402"; posting-host="ppYixYMWAWh/woI8emJOIQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.9
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Wed, 8 Sep 2021 12:26 UTC

gareth evans wrote:
> There must be some background processing taking place at
> a speed that is greater than the execution of program
> instructions in order to estimate a future branch prediction.

Your premise is wrong.
>
> OK; so why isn't that faster processing given over to
> the instructions themselves?

The branch prediction tables only need to be updated fast enough so that
they can be used by the next time the same branch comes around, i.e.
this can happen cycles after the actual branch has been taken (or not).

There have been CPUs which depended on having a few non-branch cycles in
order to update the branch tables, there you could hit a bad slowdown in
hand-written code that actually did have branches every cycle.

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Naive question; Branch Prediction

<53c0dc1b-1535-4fa7-b9ba-e76ffd6d378dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20346&group=comp.arch#20346

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:622a:c1:: with SMTP id p1mr4343935qtw.365.1631116433295;
Wed, 08 Sep 2021 08:53:53 -0700 (PDT)
X-Received: by 2002:a9d:798f:: with SMTP id h15mr3605457otm.227.1631116432982;
Wed, 08 Sep 2021 08:53:52 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Wed, 8 Sep 2021 08:53:52 -0700 (PDT)
In-Reply-To: <sha4pm$ro3$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=104.59.204.55; posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 104.59.204.55
References: <sha4pm$ro3$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <53c0dc1b-1535-4fa7-b9ba-e76ffd6d378dn@googlegroups.com>
Subject: Re: Naive question; Branch Prediction
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Wed, 08 Sep 2021 15:53:53 +0000
Content-Type: text/plain; charset="UTF-8"
 by: MitchAlsup - Wed, 8 Sep 2021 15:53 UTC

On Wednesday, September 8, 2021 at 5:54:49 AM UTC-5, gareth evans wrote:
> There must be some background processing taking place at
> a speed that is greater than the execution of program
> instructions in order to estimate a future branch prediction.
<
Terje is correct: your premise is incorrect.
>
> OK; so why isn't that faster processing given over to
> the instructions themselves?
<
Branch prediction is all done by recording branch histories
from the past and using the past to predict the future.

Re: Naive question; Branch Prediction

<shamno$tt8$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20349&group=comp.arch#20349

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Naive question; Branch Prediction
Date: Wed, 8 Sep 2021 09:00:54 -0700
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <shamno$tt8$1@dont-email.me>
References: <sha4pm$ro3$1@dont-email.me>
<53c0dc1b-1535-4fa7-b9ba-e76ffd6d378dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 8 Sep 2021 16:00:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ed9a25e958235b0c11e52da35061d41e";
logging-data="30632"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Aos5FGpzhH//51AvkPgGmg6VN97N1sAg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:mzjuZ69lWqgBat43dqTbhqoepQ8=
In-Reply-To: <53c0dc1b-1535-4fa7-b9ba-e76ffd6d378dn@googlegroups.com>
Content-Language: en-US
 by: Stephen Fuld - Wed, 8 Sep 2021 16:00 UTC

On 9/8/2021 8:53 AM, MitchAlsup wrote:
> On Wednesday, September 8, 2021 at 5:54:49 AM UTC-5, gareth evans wrote:
>> There must be some background processing taking place at
>> a speed that is greater than the execution of program
>> instructions in order to estimate a future branch prediction.
> <
> Terje is correct: your premise is incorrect.
>>
>> OK; so why isn't that faster processing given over to
>> the instructions themselves?
> <
> Branch prediction is all done by recording branch histories
> from the past and using the past to predict the future.

Yes, and to Gareth's question, the "processing" is pretty trivial.
Could just be compare the prediction to the reality and increment or
decrement a small counter. So not much "processing power" to "give
back" to processing instructions.

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Naive question; Branch Prediction

<shb04c$13v$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20355&group=comp.arch#20355

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: cr88...@gmail.com (BGB)
Newsgroups: comp.arch
Subject: Re: Naive question; Branch Prediction
Date: Wed, 8 Sep 2021 13:39:58 -0500
Organization: A noiseless patient Spider
Lines: 105
Message-ID: <shb04c$13v$1@dont-email.me>
References: <sha4pm$ro3$1@dont-email.me>
<53c0dc1b-1535-4fa7-b9ba-e76ffd6d378dn@googlegroups.com>
<shamno$tt8$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 8 Sep 2021 18:41:16 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="08dcb9fdc4399ded6529f931f2e1b694";
logging-data="1151"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hnNBNlTjRDRDldehz8l7c"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:2C6DRkHsNMqjqczTjgcCZVzV6jo=
In-Reply-To: <shamno$tt8$1@dont-email.me>
Content-Language: en-US
 by: BGB - Wed, 8 Sep 2021 18:39 UTC

On 9/8/2021 11:00 AM, Stephen Fuld wrote:
> On 9/8/2021 8:53 AM, MitchAlsup wrote:
>> On Wednesday, September 8, 2021 at 5:54:49 AM UTC-5, gareth evans wrote:
>>> There must be some background processing taking place at
>>> a speed that is greater than the execution of program
>>> instructions in order to estimate a future branch prediction.
>> <
>> Terje is correct: your premise is incorrect.
>>>
>>> OK; so why isn't that faster processing given over to
>>> the instructions themselves?
>> <
>> Branch prediction is all done by recording branch histories
>> from the past and using the past to predict the future.
>
> Yes, and to Gareth's question, the "processing" is pretty trivial. Could
> just be compare the prediction to the reality and increment or decrement
> a small counter.  So not much "processing power" to "give back" to
> processing instructions.
>
>

Yeah.

For example, in my case predicting is something like:
Form a small hash-index based on the address and branch history;
Fetch a 3-bit predictor;
Predict direction based on the predictor.

This part is done fairly early in the pipeline, and effectively diverts
instruction fetching to another location. The destination typically
comes from the branch instruction (or certain "fixed" registers).

The unconditional branch instructions may also do this.

This is along with a few other cases ('RTS' and 'JMP R1', which are used
in function returns), though these instructions have an interlock-check
of sorts against the rest of the pipeline to make sure nothing has LR or
R1 as a destination register.

Then, once the branch is executed, a similar process happens but
updating the predictor based on its current state and the branch direction.

States are, eg:
000: Small, Not-Taken
001: Small, Taken
010: Large, Not-Taken
011: Large, Taken
100: Small, Not-Taken, Alternating
101: Small, Taken, Alternating
110: Large, Not-Taken, Alternating
111: Large, Taken, Alternating

The first 4 predict branches which nearly always branch in the same
direction, whereas the alternating cases predict branches that tend to
branch the opposite direction from whatever they took last time. These
states are less common, but can help slightly.

Adding more levels to increase the "strength" of taken or not-taken
states was not effective in my tests (can actually make it worse).

The state update is basically a 4-bit table lookup to find the next state.

The branch, during the execute stage, sees whether or not the prediction
was correct or incorrect:
Correct: Behave mostly like a NOP;
Incorrect: Initiate a branch to the new location.

As can be noted, my ISA currently has several branch displacement sizes:
Disp8s, 16-bit branch ops, handled by predictor;
Disp20s, 32-bit branch ops, handled by predictor;
Disp33s, 64-bit branch ops, execute-stage (ignored by predictor);
Abs48, 64-bit branch ops, handled by predictor.

Nearly all local branches can fit into a 20 bit displacement (+/- 1MB in
this case). Non-local branches can use Abs48 (48-bit absolute address)
or a branch through a pointer.

The 33-bit branches are rare enough and expensive enough to handle early
that they can be left as non-predicted without too much adverse effect.
This could happen though in a binary with a ".text" section exceeding 1MB.

Part of the cost is due to adder latency, where a smaller adder has less
latency. This is not really an issue for Abs48 branches.

Previously, there was an issue with Mod-4GB branch-addressing due to the
adder latency issue, but then I came up with the idea that the
branch-predictor can ignore any branches which produce a carry outside
the low 24 bits or so (these would be left to the EX stages to deal
with). This allows dropping the Mod-4GB branch restriction.

Currently, the branch predictor will also ignore branches that are put
into a bundle, with the minor drawback that this effectively prevents
bundling instructions in parallel with a branch.

....

None of this is "general purpose" processing that would be of much use
as part of the ISA.

Re: Naive question; Branch Prediction

<shb4be$sqe$3@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20360&group=comp.arch#20360

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-c002-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Naive question; Branch Prediction
Date: Wed, 8 Sep 2021 19:53:18 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <shb4be$sqe$3@newsreader4.netcologne.de>
References: <sha4pm$ro3$1@dont-email.me>
<53c0dc1b-1535-4fa7-b9ba-e76ffd6d378dn@googlegroups.com>
Injection-Date: Wed, 8 Sep 2021 19:53:18 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-c002-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:c002:0:7285:c2ff:fe6c:992d";
logging-data="29518"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Wed, 8 Sep 2021 19:53 UTC

MitchAlsup <MitchAlsup@aol.com> schrieb:
> On Wednesday, September 8, 2021 at 5:54:49 AM UTC-5, gareth evans wrote:
>> There must be some background processing taking place at
>> a speed that is greater than the execution of program
>> instructions in order to estimate a future branch prediction.
><
> Terje is correct: your premise is incorrect.
>>
>> OK; so why isn't that faster processing given over to
>> the instructions themselves?
><
> Branch prediction is all done by recording branch histories
> from the past and using the past to predict the future.

I'm always astonished that it appears to work so well.

for (i=0; i<3; i++)
for (j=0; j<3; j++)

would already hard, correct?

Re: Naive question; Branch Prediction

<2d69f918-e635-493b-b089-c6db5dec28f2n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20361&group=comp.arch#20361

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a37:aa97:: with SMTP id t145mr5174840qke.145.1631131906080;
Wed, 08 Sep 2021 13:11:46 -0700 (PDT)
X-Received: by 2002:a9d:798f:: with SMTP id h15mr4538917otm.227.1631131905844;
Wed, 08 Sep 2021 13:11:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Wed, 8 Sep 2021 13:11:45 -0700 (PDT)
In-Reply-To: <shb4be$sqe$3@newsreader4.netcologne.de>
Injection-Info: google-groups.googlegroups.com; posting-host=104.59.204.55; posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 104.59.204.55
References: <sha4pm$ro3$1@dont-email.me> <53c0dc1b-1535-4fa7-b9ba-e76ffd6d378dn@googlegroups.com>
<shb4be$sqe$3@newsreader4.netcologne.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2d69f918-e635-493b-b089-c6db5dec28f2n@googlegroups.com>
Subject: Re: Naive question; Branch Prediction
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Wed, 08 Sep 2021 20:11:46 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 28
 by: MitchAlsup - Wed, 8 Sep 2021 20:11 UTC

On Wednesday, September 8, 2021 at 2:53:20 PM UTC-5, Thomas Koenig wrote:
> MitchAlsup <Mitch...@aol.com> schrieb:
> > On Wednesday, September 8, 2021 at 5:54:49 AM UTC-5, gareth evans wrote:
> >> There must be some background processing taking place at
> >> a speed that is greater than the execution of program
> >> instructions in order to estimate a future branch prediction.
> ><
> > Terje is correct: your premise is incorrect.
> >>
> >> OK; so why isn't that faster processing given over to
> >> the instructions themselves?
> ><
> > Branch prediction is all done by recording branch histories
> > from the past and using the past to predict the future.
> I'm always astonished that it appears to work so well.
>
> for (i=0; i<3; i++)
> for (j=0; j<3; j++)
>
> would already hard, correct?
<
Not when you include branch history ! in the prediction hash !!
The above loops have an inner pattern TTN and an outer pattern
of TTN. The inner pattern is at one virtual address, the outer
pattern is at a different virtual address, to they use different
prediction cells in the branch prediction table (2×3) cells. Given
1K-16K of these cells, there is scant interference (0.6%-0.01%),
as long as your has function works well.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor