[PATCH] D22440: Use a faster implementation of maxUIntN.
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 16 23:09:14 PDT 2016
jlebar updated this revision to Diff 64240.
jlebar marked an inline comment as done.
jlebar added a comment.
Use UINT64_MAX.
https://reviews.llvm.org/D22440
Files:
include/llvm/Support/MathExtras.h
Index: include/llvm/Support/MathExtras.h
===================================================================
--- include/llvm/Support/MathExtras.h
+++ include/llvm/Support/MathExtras.h
@@ -316,10 +316,11 @@
inline uint64_t maxUIntN(uint64_t N) {
assert(N > 0 && N <= 64 && "integer width out of range");
- // uint64_t(1) << 64 is undefined behavior.
- if (N == 64)
- return std::numeric_limits<uint64_t>::max();
- return (UINT64_C(1) << N) - 1;
+ // uint64_t(1) << 64 is undefined behavior, so we can't do
+ // (uint64_t(1) << N) - 1
+ // without checking first that N != 64. But this works and doesn't have a
+ // branch.
+ return UINT64_MAX >> (64 - N);
}
/// Gets the minimum value for a N-bit signed integer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22440.64240.patch
Type: text/x-patch
Size: 737 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160717/78274476/attachment.bin>
More information about the llvm-commits
mailing list