dotnet/runtime

Optimize Half.CompareTo

Open

#43.117 geöffnet am 6. Okt. 2020

Auf GitHub ansehen
 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (5.445 Forks)batch import
area-System.Runtimehelp wantedtenet-performance

Repository-Metriken

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

Beschreibung

There is a same problem as mentioned here. In the worst case there can be 8 calls to IsNaN() due to two NaN-checks at the beginning of all operators

 public int CompareTo(Half other)
        {
            if (this < other) 
            {
                return -1;
            }

            if (this > other)
            {
                return 1;
            }

            if (this == other)
            {
                return 0;
            }

            if (IsNaN(this))
            {
                return IsNaN(other) ? 0 : -1;
            }

            Debug.Assert(IsNaN(other));
            return 1;
        }

Seems like simple operators inlining should help

Contributor Guide