Standard way to supply hints to branches

Dom DiSc dominikus at scherkl.de
Sat Aug 31 16:11:53 UTC 2024


On Friday, 30 August 2024 at 02:54:28 UTC, Manu wrote:
> On Fri, 30 Aug 2024 at 04:32, Walter Bright via Digitalmars-d < 
> digitalmars-d at puremagic.com> wrote:
>
>> On 8/28/2024 2:45 AM, Manu wrote:
>> > Here's one that I just wrote a short while ago: 
>> > https://gist.github.com/TurkeyMan/0e49da245cc0086f852ac18deed21a9c
>>
>>
>> ```
>> if (data.length < 4) // unlikely
>>      return 0;
>> ```
>>
>> replace with:
>>
>> ```
>> if (data.length < 4)
>>      goto Lreturn0;
>> ```
>>
>
> How is that any different? The branch prediction hasn't changed.

I already asked this question.
He said a single break or goto is NOT considered the hot branch 
by the compiler.
But I don't like this, because it's an implementation detail that 
every compiler may implement or not, and it's not documented 
anywhere.
Maybe if the documentation would clearly state at a prominent 
point that a single break or goto has to be considered the cold 
path by the compiler, but a function call is to be considered the 
hot path (and all related queries about branch priorization link 
there), then I would consider this a solution. But is it likely 
this will happen?


More information about the Digitalmars-d mailing list