bound_view: Rewrite tri_compare() tail
bound_view: Rewrite tri_compare() tail

The new implementation is shorter and allows compiler to
produce nicer assembly. In particular clang-11 and -O3 flag:

Was:
    if (d1 == d2) {
        return w1 - w2;
    }
    return d1 < d2 ? w1 - (w1 <= 0) : -(w2 - (w2 <= 0));

    89 f0           mov    %esi,%eax
    39 d7           cmp    %edx,%edi
    74 13           je     403f69 <_Z7cmp_intiiii+0x19>
    7d 0a           jge    403f62 <_Z7cmp_intiiii+0x12>
    31 c9           xor    %ecx,%ecx
    85 c0           test   %eax,%eax
    0f 9e c1        setle  %cl
    29 c8           sub    %ecx,%eax
    c3              retq
    31 c0           xor    %eax,%eax
    85 c9           test   %ecx,%ecx
    0f 9e c0        setle  %al
    29 c8           sub    %ecx,%eax
    c3              retq

14 instructions 2 cond jumps, 2 cond sets

Now:
    return ((d1 <= d2) ? w1 << 1 : 1) - ((d2 <= d1) ? w2 << 1 : 1);

    8d 04 36        lea    (%rsi,%rsi,1),%eax
    39 d7           cmp    %edx,%edi
    be 01 00 00 00  mov    $0x1,%esi
    0f 4f c6        cmovg  %esi,%eax
    01 c9           add    %ecx,%ecx
    39 fa           cmp    %edi,%edx
    0f 4f ce        cmovg  %esi,%ecx
    29 c8           sub    %ecx,%eax
    c3              retq

9 instructions, 0 cond jumps, 2 cond movs

tests: unit(dev), perf(simple_query, release)

Signed-off-by: Pavel Emelyanov <c9a32589e048e044184536f7ac71ef92fe82df3e@scylladb.com>
Message-Id: <20210730092629.18940-1-c9a32589e048e044184536f7ac71ef92fe82df3e@scylladb.com>

scylladb/scylla,scylladb/scylla,scylladb/scylla,scylladb/scylla