[PATCH] D47024: [MathExtras] Add alignToPowerOf2
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 17 12:12:46 PDT 2018
MaskRay created this revision.
MaskRay added reviewers: jlebar, ruiu.
Herald added a subscriber: llvm-commits.
When Align is a variable known to be a power of 2, this can be faster than alignTo by replacing a div instruction with bitwise operation.
Repository:
rL LLVM
https://reviews.llvm.org/D47024
Files:
include/llvm/Support/MathExtras.h
Index: include/llvm/Support/MathExtras.h
===================================================================
--- include/llvm/Support/MathExtras.h
+++ include/llvm/Support/MathExtras.h
@@ -687,6 +687,12 @@
return (Value + Align - 1) / Align * Align;
}
+inline uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) {
+ assert(Align != 0 && (Align & Align - 1) == 0 &&
+ "Align must be a power of 2");
+ return (Value + Align - 1) & -Align;
+}
+
/// Returns the integer ceil(Numerator / Denominator).
inline uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator) {
return alignTo(Numerator, Denominator) / Denominator;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47024.147367.patch
Type: text/x-patch
Size: 648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180517/ca74b2f3/attachment.bin>
More information about the llvm-commits
mailing list