summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2015-09-26 10:09:36 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2015-09-26 10:09:36 +0000
commit2a63631abd8b2b88a2e27dd1270ec6cd4040c1d3 (patch)
treed7d27d4527f9cb75e477bd457d112293743c32e8 /llvm/include
parent00eecb88a4e07c0633822f38cff17143583fdae6 (diff)
downloadbcm5719-llvm-2a63631abd8b2b88a2e27dd1270ec6cd4040c1d3.tar.gz
bcm5719-llvm-2a63631abd8b2b88a2e27dd1270ec6cd4040c1d3.zip
[BranchProbability] Manually round the floating point output.
llvm::format compiles down to snprintf which has no defined rounding for floating point arguments, and MSVC has implemented it differently from what the BSD libcs and glibc do. Try to emulate the glibc rounding behavior to avoid changing tests. While there simplify code a bit and move trivial methods inline. llvm-svn: 248665
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/Support/BranchProbability.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/llvm/include/llvm/Support/BranchProbability.h b/llvm/include/llvm/Support/BranchProbability.h
index dd43857fa22..98b2a3d7d9a 100644
--- a/llvm/include/llvm/Support/BranchProbability.h
+++ b/llvm/include/llvm/Support/BranchProbability.h
@@ -79,8 +79,20 @@ public:
/// \return \c Num divided by \c this.
uint64_t scaleByInverse(uint64_t Num) const;
- BranchProbability &operator+=(BranchProbability RHS);
- BranchProbability &operator-=(BranchProbability RHS);
+ BranchProbability &operator+=(BranchProbability RHS) {
+ assert(N <= D - RHS.N &&
+ "The sum of branch probabilities should not exceed one!");
+ N += RHS.N;
+ return *this;
+ }
+
+ BranchProbability &operator-=(BranchProbability RHS) {
+ assert(N >= RHS.N &&
+ "Can only subtract a smaller probability from a larger one!");
+ N -= RHS.N;
+ return *this;
+ }
+
BranchProbability &operator*=(BranchProbability RHS) {
N = (static_cast<uint64_t>(N) * RHS.N + D / 2) / D;
return *this;
OpenPOWER on IntegriCloud