<div dir="ltr"><div dir="ltr">On Sat, 31 Aug 2024 at 17:16, Dom DiSc via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Friday, 30 August 2024 at 02:54:28 UTC, Manu wrote:<br>
> On Fri, 30 Aug 2024 at 04:32, Walter Bright via Digitalmars-d < <br>
> <a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>> wrote:<br>
><br>
>> On 8/28/2024 2:45 AM, Manu wrote:<br>
>> > Here's one that I just wrote a short while ago: <br>
>> > <a href="https://gist.github.com/TurkeyMan/0e49da245cc0086f852ac18deed21a9c" rel="noreferrer" target="_blank">https://gist.github.com/TurkeyMan/0e49da245cc0086f852ac18deed21a9c</a><br>
>><br>
>><br>
>> ```<br>
>> if (data.length < 4) // unlikely<br>
>>      return 0;<br>
>> ```<br>
>><br>
>> replace with:<br>
>><br>
>> ```<br>
>> if (data.length < 4)<br>
>>      goto Lreturn0;<br>
>> ```<br>
>><br>
><br>
> How is that any different? The branch prediction hasn't changed.<br>
<br>
I already asked this question.<br>
He said a single break or goto is NOT considered the hot branch <br>
by the compiler.<br></blockquote><div><br></div><div>The goto is not a branch at all. The if() is the branch... and it still predicts the pessimistic case incorrectly.</div><div>Replacing the return with a goto hasn't changed the control flow in any way; goto and return are equivalent; they are not branches.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
But I don't like this, because it's an implementation detail that <br>
every compiler may implement or not, and it's not documented <br>
anywhere.<br>
Maybe if the documentation would clearly state at a prominent <br>
point that a single break or goto has to be considered the cold <br>
path by the compiler, but a function call is to be considered the <br>
hot path (and all related queries about branch priorization link <br>
there), then I would consider this a solution. But is it likely <br>
this will happen?<br>
</blockquote></div></div>