[PATCH] D22440: Use a faster implementation of maxUIntN.
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 17 11:26:55 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL275718: Use a faster implementation of maxUIntN. (authored by jlebar).
Changed prior to commit:
https://reviews.llvm.org/D22440?vs=64240&id=64257#toc
Repository:
rL LLVM
https://reviews.llvm.org/D22440
Files:
llvm/trunk/include/llvm/Support/MathExtras.h
Index: llvm/trunk/include/llvm/Support/MathExtras.h
===================================================================
--- llvm/trunk/include/llvm/Support/MathExtras.h
+++ llvm/trunk/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.64257.patch
Type: text/x-patch
Size: 770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160717/f568a302/attachment.bin>
More information about the llvm-commits
mailing list