flat assembler
Message board for the users of flat assembler.

Index > Main > AMD: default conditional branch prediction policy

Author
Thread Post new topic Reply to topic
sylware



Joined: 23 Oct 2020
Posts: 633
Location: Marseille/France
sylware 30 Jul 2026, 14:35
I read in intel documentation the default conditional branch prediction policy: backward predicted taken, forward predicted not taken (at least the first time a conditional branch is encountered). Same than RISC-V.

But I am unable to find it in AMD CPU documentation, anybody?
Post 30 Jul 2026, 14:35
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1228
Location: Russia
macomics 30 Jul 2026, 17:02
Here. Chapter 7
Post 30 Jul 2026, 17:02
View user's profile Send private message Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 633
Location: Marseille/France
sylware 30 Jul 2026, 18:25
So it seems AMD prediction default rule is different than the one from Intel and RISC-V: 7.9, no mention of forward or backward branches, namely AMD default prediction is only forward.

Meh. 2014, still valid nowdays?
Post 30 Jul 2026, 18:25
View user's profile Send private message Reply with quote
redsock



Joined: 09 Oct 2009
Posts: 453
Location: Australia
redsock 30 Jul 2026, 18:54
Post 30 Jul 2026, 18:54
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1228
Location: Russia
macomics 31 Jul 2026, 16:51
sulware wrote:
Meh. 2014, still valid nowdays?
It looks like the Jan-2014 edition is the last one that is publicly available on the https://amd.com. There may be other editions, but I can't find anything.
Post 31 Jul 2026, 16:51
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4560
Location: vpcmpistri
bitRAKE 31 Jul 2026, 18:50
AMD switched to a scheme where they produce optimization manuals for each new core. For example, the Zen5 manual is document 58455. If you follow people like InstLatX6 on bsky|X, they usually broadcast documentation updates - very helpful, imho.
Post 31 Jul 2026, 18:50
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 633
Location: Marseille/France
sylware 01 Aug 2026, 11:23
Everything is gated by whatwg cartel web engines.
Post 01 Aug 2026, 11:23
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4560
Location: vpcmpistri
bitRAKE 01 Aug 2026, 13:33
https://github.com/bitRAKE/amd_zen_sogs

Now I have them all in one place. Zen4 missing from latest AMD portal.
Post 01 Aug 2026, 13:33
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 633
Location: Marseille/France
sylware 01 Aug 2026, 15:36
bitRAKE wrote:
https://github.com/bitRAKE/amd_zen_sogs

Now I have them all in one place. Zen4 missing from latest AMD portal.


This is what we call "bringing the hammer down" Smile

I skimmed 58455, and they hardly changed the conditional branch prediction: until a conditional branch is actually taken, it is always predicted not taken, without branch direction information. BUT, after being taken a first time, the second time the branch will be predicted taken.

This is different than Intel and RISC-V, then machine code will have to be different for many conditional branch use cases.

And yes, whatever the hardware micro-architecture, the cache line is paramount.

What is still very blurry in my mind: sorta common rules to manage BTB entries per cache lines.


Last edited by sylware on 02 Aug 2026, 10:57; edited 1 time in total
Post 01 Aug 2026, 15:36
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4560
Location: vpcmpistri
bitRAKE 01 Aug 2026, 16:43
The documentation reflects the complexity of the core(s).

I always have questions when I read something like:
Quote:
Only a limited number of targets that cross a 128GB aligned boundary relative to the branch address can be tracked in the L1 and L2 BTBs. Software should limit the number of branch targets that cross such a boundary.
Zen5 reduced it to 16GB -- I guess to reduce the number of address bits in the BTB. WTF, is "limited number"? Testing here shows that number is three.

I told the AI to build a test case for any ambiguity or falsifiable claim. It's still working. (The testing methodology takes time to refine into something useful. Some cases will need additional tooling.)

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.
Post 01 Aug 2026, 16:43
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2742
Furs 01 Aug 2026, 20:09
How do you even cross a 16GB boundary WTF?

Other than calling into another library or whatever, which is not something you can control due to ASLR, so how can "software limit it"? Makes no fucking sense.
Post 01 Aug 2026, 20:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21023
Location: In your JS exploiting you and your system
revolution 01 Aug 2026, 21:25
Furs wrote:
How do you even cross a 16GB boundary WTF?

Other than calling into another library or whatever, which is not something you can control due to ASLR, so how can "software limit it"? Makes no fucking sense.
Not every application uses one of the main OSes (Windows, Linux, Mac). And the CPU makers don't care about ASLR or similar things, that isn't their problem. Their advice is if the chosen OS doesn't play nice with their CPU then use a different OS.
Post 01 Aug 2026, 21:25
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 633
Location: Marseille/France
sylware 02 Aug 2026, 11:02
Huh? I have been thinking the BTB is actually dealing with "close code". Why do I recall something like 16MB (not GB)??
Post 02 Aug 2026, 11:02
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4560
Location: vpcmpistri
bitRAKE 03 Aug 2026, 22:58
Of course, we can't forget this beautiful resource ...
https://kib.kiev.ua/x86docs/
Post 03 Aug 2026, 22:58
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.