dotnet/runtime

Could emit branchless form of i <= 0b00111 && j <= 0b00111 for unsigned integers

Open

#92.692 geöffnet am 27. Sept. 2023

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)C# (5.445 Forks)batch import
area-CodeGen-coreclrhelp wantedtenet-performance

Repository-Metriken

Stars
 (17.886 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 12T 11h) (661 gemergte PRs in 30 T)

Beschreibung

Similar to #61940, equivalent to (i | j) <= 0b0011, the constant value can be 2^n-1, also the condition can be <.

For example:

bool Test0(ulong x, ulong y) => x <= UInt32.MaxValue && y <= UInt32.MaxValue;

bool Test1(ulong x, ulong y) => (x | y) <= UInt32.MaxValue;

The JIT could produce the same output for the above, but currently not, see https://godbolt.org/z/G9Taxqcox

C:Test(ulong,ulong):ubyte:this (FullOpts):
       mov      eax, 0xD1FFAB1E
       cmp      rsi, rax
       ja       SHORT G_M42689_IG05
       mov      eax, 0xD1FFAB1E
       cmp      rdx, rax
       setbe    al
       movzx    rax, al
       ret      
G_M42689_IG05:
       xor      eax, eax
       ret      

C:Test1(ulong,ulong):ubyte:this (FullOpts):
       or       rdx, rsi
       mov      eax, 0xD1FFAB1E
       cmp      rdx, rax
       setbe    al
       movzx    rax, al
       ret      

Contributor Guide