[PATCH] D76274: [Alignment] Add alignTo with skew parameter
Guillaume Chatelet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 17 06:52:32 PDT 2020
gchatelet updated this revision to Diff 250754.
gchatelet marked 3 inline comments as done.
gchatelet added a comment.
Address comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76274/new/
https://reviews.llvm.org/D76274
Files:
llvm/include/llvm/Support/Alignment.h
llvm/unittests/Support/AlignmentTest.cpp
Index: llvm/unittests/Support/AlignmentTest.cpp
===================================================================
--- llvm/unittests/Support/AlignmentTest.cpp
+++ llvm/unittests/Support/AlignmentTest.cpp
@@ -126,6 +126,7 @@
}
TEST(AlignmentTest, AlignToWithSkew) {
+ EXPECT_EQ(alignTo(5, Align(8), 0), alignTo(5, Align(8)));
EXPECT_EQ(alignTo(5, Align(8), 7), 7U);
EXPECT_EQ(alignTo(17, Align(8), 1), 17U);
EXPECT_EQ(alignTo(~0LL, Align(8), 3), 3U);
Index: llvm/include/llvm/Support/Alignment.h
===================================================================
--- llvm/include/llvm/Support/Alignment.h
+++ llvm/include/llvm/Support/Alignment.h
@@ -164,17 +164,17 @@
/// Returns a multiple of A needed to store `Size` bytes.
inline uint64_t alignTo(uint64_t Size, Align A) {
- const uint64_t value = A.value();
- // The following line is equivalent to `(Size + value - 1) / value * value`.
+ const uint64_t Value = A.value();
+ // The following line is equivalent to `(Size + Value - 1) / Value * Value`.
// The division followed by a multiplication can be thought of as a right
// shift followed by a left shift which zeros out the extra bits produced in
- // the bump; `~(value - 1)` is a mask where all those bits being zeroed out
+ // the bump; `~(Value - 1)` is a mask where all those bits being zeroed out
// are just zero.
// Most compilers can generate this code but the pattern may be missed when
// multiple functions gets inlined.
- return (Size + value - 1) & ~(value - 1U);
+ return (Size + Value - 1) & ~(Value - 1U);
}
/// If non-zero \p Skew is specified, the return value will be a minimal integer
@@ -189,9 +189,9 @@
/// alignTo(~0LL, Align(8), 3) = 3
/// \endcode
inline uint64_t alignTo(uint64_t Size, Align A, uint64_t Skew) {
- const uint64_t value = A.value();
- Skew %= value;
- return ((Size + value - 1 - Skew) & ~(value - 1U)) + Skew;
+ const uint64_t Value = A.value();
+ Skew %= Value;
+ return ((Size + Value - 1 - Skew) & ~(Value - 1U)) + Skew;
}
/// Returns a multiple of A needed to store `Size` bytes.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76274.250754.patch
Type: text/x-patch
Size: 2104 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200317/21564a7d/attachment.bin>
More information about the llvm-commits
mailing list