Standard way to supply hints to branches

Walter Bright newshound2 at digitalmars.com
Sat Aug 24 03:37:32 UTC 2024


On 8/23/2024 7:24 PM, Walter Bright wrote:
> On 8/23/2024 1:56 AM, Iain Buclaw wrote:
>> Regarding DMD, I recall it being said that its code generator always treats 
>> the true branch as the "likely" code path taken. So if you have `if (cond) 
>> cold; else hot;`, invert the condition for the benefit of DMD.
> 
> That's correct.

It's not pedantically correct. More precisely, any code following the `if` is 
presumed to be the hot path. A branch instruction doesn't count, i.e. it's the 
branch-not-taken that is considered the hot path.


More information about the Digitalmars-d mailing list