[llvm] r257799 - [Support] Rename RoundUpToAlignment -> alignTo.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 14 12:43:11 PST 2016
Author: ruiu
Date: Thu Jan 14 14:43:11 2016
New Revision: 257799
URL: http://llvm.org/viewvc/llvm-project?rev=257799&view=rev
Log:
[Support] Rename RoundUpToAlignment -> alignTo.
Rounding up an integer m to a nearest multiple of n where n is a power
of 2 is used very often if you are writing code to emit binary files.
RoundUpToAlignment is a small function to do that. But we found that the
function has a small but annoying issue; the name is a bit too long.
Because it is used quite often, that hurts readability.
This patch is to rename the function. The original name is kept as a
forwarder, so that submitting this patch won't immediately break Clang
and other LLVM projects. Once I update all occurrences of RoundUpToAlignment,
I'll remove the old name entirely.
http://reviews.llvm.org/D16162
Modified:
llvm/trunk/include/llvm/Support/MathExtras.h
Modified: llvm/trunk/include/llvm/Support/MathExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MathExtras.h?rev=257799&r1=257798&r2=257799&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MathExtras.h (original)
+++ llvm/trunk/include/llvm/Support/MathExtras.h Thu Jan 14 14:43:11 2016
@@ -606,22 +606,26 @@ inline uint64_t PowerOf2Floor(uint64_t A
///
/// Examples:
/// \code
-/// RoundUpToAlignment(5, 8) = 8
-/// RoundUpToAlignment(17, 8) = 24
-/// RoundUpToAlignment(~0LL, 8) = 0
-/// RoundUpToAlignment(321, 255) = 510
+/// alignTo(5, 8) = 8
+/// alignTo(17, 8) = 24
+/// alignTo(~0LL, 8) = 0
+/// alignTo(321, 255) = 510
///
-/// RoundUpToAlignment(5, 8, 7) = 7
-/// RoundUpToAlignment(17, 8, 1) = 17
-/// RoundUpToAlignment(~0LL, 8, 3) = 3
-/// RoundUpToAlignment(321, 255, 42) = 552
+/// alignTo(5, 8, 7) = 7
+/// alignTo(17, 8, 1) = 17
+/// alignTo(~0LL, 8, 3) = 3
+/// alignTo(321, 255, 42) = 552
/// \endcode
-inline uint64_t RoundUpToAlignment(uint64_t Value, uint64_t Align,
- uint64_t Skew = 0) {
+inline uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew = 0) {
Skew %= Align;
return (Value + Align - 1 - Skew) / Align * Align + Skew;
}
+inline uint64_t RoundUpToAlignment(uint64_t Value, uint64_t Align,
+ uint64_t Skew = 0) {
+ return alignTo(Value, Align, Skew);
+}
+
/// Returns the offset to the next integer (mod 2**64) that is greater than
/// or equal to \p Value and is a multiple of \p Align. \p Align must be
/// non-zero.
More information about the llvm-commits
mailing list