Standard way to supply hints to branches

Guillaume Piolat guillaume.piolat at gmail.com
Sun Sep 15 11:48:19 UTC 2024


On Friday, 23 August 2024 at 01:47:37 UTC, Manu wrote:
> How can we add an attribute to the branch condition that the 
> backend can take advantage of? I think it needs to be in the 
> language spec...

In case this thread goes nowhere, work-around is:

     version(LDC)
     {
         import ldc.intrinsics;
         bool likely(bool b) { return llvm_expect!bool(b, true); }
         bool unlikely(bool b) { return llvm_expect!bool(b, 
false); }
     }
     else
     {
         bool likely(bool b) { return b; }
         bool unlikely(bool b) { return b; }
     }

Not sure for GDC. This taken from lz4 source.


More information about the Digitalmars-d mailing list