[PATCH] D25344: Add a fast path to alignTo.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 6 13:35:39 PDT 2016


My understanding is that modern CPUs do this already.

What could help is to have a dedicated alignToP2.


Cheers,
Rafael


On October 6, 2016 4:04:14 PM EDT, Rui Ueyama <ruiu at google.com> wrote:
>ruiu created this revision.
>ruiu added reviewers: rafael, davide.
>ruiu added a subscriber: llvm-commits.
>
>If an alignment is a power of two, we can avoid integer division,
>and it is very likely to happen.
>
>
>https://reviews.llvm.org/D25344
>
>Files:
>  include/llvm/Support/MathExtras.h
>
>
>Index: include/llvm/Support/MathExtras.h
>===================================================================
>--- include/llvm/Support/MathExtras.h
>+++ include/llvm/Support/MathExtras.h
>@@ -670,6 +670,10 @@
> /// \endcode
>inline uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew =
>0) {
>   assert(Align != 0u && "Align can't be 0.");
>+  if (LLVM_LIKELY(isPowerOf2_64(Align))) {
>+    Skew &= Align - 1;
>+    return ((Value + Align - 1 - Skew) & -Align) + Skew;
>+  }
>   Skew %= Align;
>   return (Value + Align - 1 - Skew) / Align * Align + Skew;
> }

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161006/e7439175/attachment.html>


More information about the llvm-commits mailing list