dotnet/runtime

Optimize Half.CompareTo

Open

#43,117 建立於 2020年10月6日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)C# (5,445 fork)batch import
area-System.Runtimehelp wantedtenet-performance

倉庫指標

Star
 (17,886 star)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

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

貢獻者指南