[PATCH] D114356: [Support] Add isShiftedUIntN to MathExtras.h

Craig Blackmore via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 22 03:54:28 PST 2021


craigblackmore created this revision.
Herald added a subscriber: dexonsmith.
craigblackmore requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is a non-templated version of isShiftedUInt which takes N and S as arguments.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114356

Files:
  llvm/include/llvm/Support/MathExtras.h


Index: llvm/include/llvm/Support/MathExtras.h
===================================================================
--- llvm/include/llvm/Support/MathExtras.h
+++ llvm/include/llvm/Support/MathExtras.h
@@ -461,6 +461,12 @@
   return N >= 64 || (minIntN(N) <= x && x <= maxIntN(N));
 }
 
+/// Checks if an unsigned integer is an N bit number shifted left by S.  Dynamic
+/// version of isShiftedUInt.
+inline bool isShiftedUIntN(unsigned N, unsigned S, uint64_t x) {
+  return isUIntN(N + S, x) && (x % (UINT64_C(1) << S) == 0);
+}
+
 /// Return true if the argument is a non-empty sequence of ones starting at the
 /// least significant bit with the remainder zero (32 bit version).
 /// Ex. isMask_32(0x0000FFFFU) == true.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114356.388863.patch
Type: text/x-patch
Size: 722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211122/1ba04592/attachment.bin>


More information about the llvm-commits mailing list