llvm.org GIT mirror llvm / a0a6942
Use a faster implementation of maxUIntN. Summary: On x86-64 with clang 3.8, before: mov edx, 1 mov cl, dil shl rdx, cl cmp rdi, 64 mov rax, -1 cmovne rax, rdx ret after: mov ecx, 64 sub ecx, edi mov rax, -1 shr rax, cl ret Reviewers: rnk Subscribers: dylanmckay, mkuper, llvm-commits Differential Revision: https://reviews.llvm.org/D22440 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275718 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Lebar 4 years ago
1 changed file(s) with 5 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
315315 inline uint64_t maxUIntN(uint64_t N) {
316316 assert(N > 0 && N <= 64 && "integer width out of range");
317317
318 // uint64_t(1) << 64 is undefined behavior.
319 if (N == 64)
320 return std::numeric_limits::max();
321 return (UINT64_C(1) << N) - 1;
318 // uint64_t(1) << 64 is undefined behavior, so we can't do
319 // (uint64_t(1) << N) - 1
320 // without checking first that N != 64. But this works and doesn't have a
321 // branch.
322 return UINT64_MAX >> (64 - N);
322323 }
323324
324325 /// Gets the minimum value for a N-bit signed integer.