Standard way to supply hints to branches

user1234 user1234 at 12.de
Sat Aug 24 09:11:34 UTC 2024


On Saturday, 24 August 2024 at 08:06:21 UTC, IchorDev wrote:
> On Saturday, 24 August 2024 at 03:37:32 UTC, Walter Bright 
> wrote:
>> 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.
>
> I think everyone in this thread can agree that we need a 
> compiler-agnostic solution for changing the presumed hot-path, 
> and one that doesn’t require rewriting existing code more than 
> just adding on one word. For example, `if((x == 
> y).expect(false)){}` makes it a pain to rewrite existing `if`s, 
> where `@unlikely if(x == y) {}` is easy.

You also have the `pragma` option. I think that would be more 
adequate as not every vendor has to support it. In other words 
"dmd can just ignore it". Bonus: pragma can be attached to 
statements, that's not the case of attributes.


More information about the Digitalmars-d mailing list