Support: Extract ScaledNumbers::compare()

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211507 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2014-06-23 17:47:40 +00:00
parent 88a564f55e
commit 18a301e578
4 changed files with 87 additions and 35 deletions

View File

@ -117,3 +117,16 @@ std::pair<uint64_t, int16_t> ScaledNumbers::divide64(uint64_t Dividend,
return getRounded(Quotient, Shift, Dividend >= getHalf(Divisor));
}
int ScaledNumbers::compareImpl(uint64_t L, uint64_t R, int ScaleDiff) {
assert(ScaleDiff >= 0 && "wrong argument order");
assert(ScaleDiff < 64 && "numbers too far apart");
uint64_t L_adjusted = L >> ScaleDiff;
if (L_adjusted < R)
return -1;
if (L_adjusted > R)
return 1;
return L > L_adjusted << ScaleDiff ? 1 : 0;
}