mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-12 13:38:21 +00:00
blockfreq: Defer to BranchProbability::scale()
`BlockMass` can now defer to `BranchProbability::scale()`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207547 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -311,32 +311,6 @@ std::pair<uint64_t, int16_t> UnsignedFloatBase::multiply64(uint64_t L,
|
||||
// BlockMass implementation.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
BlockMass &BlockMass::operator*=(const BranchProbability &P) {
|
||||
uint32_t N = P.getNumerator(), D = P.getDenominator();
|
||||
assert(D && "divide by 0");
|
||||
assert(N <= D && "fraction greater than 1");
|
||||
|
||||
// Fast path for multiplying by 1.0.
|
||||
if (!Mass || N == D)
|
||||
return *this;
|
||||
|
||||
// Get as much precision as we can.
|
||||
int Shift = countLeadingZeros(Mass);
|
||||
uint64_t ShiftedQuotient = (Mass << Shift) / D;
|
||||
uint64_t Product = ShiftedQuotient * N >> Shift;
|
||||
|
||||
// Now check for what's lost.
|
||||
uint64_t Left = ShiftedQuotient * (D - N) >> Shift;
|
||||
uint64_t Lost = Mass - Product - Left;
|
||||
|
||||
// TODO: prove this assertion.
|
||||
assert(Lost <= UINT32_MAX);
|
||||
|
||||
// Take the product plus a portion of the spoils.
|
||||
Mass = Product + Lost * N / D;
|
||||
return *this;
|
||||
}
|
||||
|
||||
UnsignedFloat<uint64_t> BlockMass::toFloat() const {
|
||||
if (isFull())
|
||||
return UnsignedFloat<uint64_t>(1, 0);
|
||||
|
Reference in New Issue
Block a user