[Zucchini] Add helpers for 2 byte and 4 byte alignment.

This CL adds specialized versions of AlignCeil():
  {IncrementForAlignCeil2(), IncrementForAlignCeil4()}.

Given a value to be aligned, these functions return an increment that
the caller can add to the given value to cause alignment. This scheme
admits iterator alignment. e.g., by:
  aligned_it = it + IncrementForAlignCeil4(it - base_it);

These functions will be used by code to add ARM support.

Bug: 918867
Change-Id: I6da038a748a29cde82e4c82e597455644213abd9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1524920
Reviewed-by: Samuel Huang <huangs@chromium.org>
Reviewed-by: Etienne Pierre-Doray <etiennep@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#641279}
NOKEYCHECK=True
GitOrigin-RevId: dc2c91d1d1cf5aeac19b25210e470909f175b160
diff --git a/algorithm.h b/algorithm.h
index 463aca3..898859f 100644
--- a/algorithm.h
+++ b/algorithm.h
@@ -53,6 +53,20 @@
   return T((x + m - 1) / m) * m;
 }
 
+// Specialized alignment helpers that returns the increment to |pos| to get the
+// next n-aligned value, where n is in {2, 4}. This is useful for aligning
+// iterators relative to a base iterator using:
+//   it += IncrementForAlignCeil2(it - base);
+template <class T>
+inline int IncrementForAlignCeil2(T pos) {
+  return static_cast<int>(pos & 1);  // Optimized from (-pos) & 1.
+}
+
+template <class T>
+inline int IncrementForAlignCeil4(T pos) {
+  return static_cast<int>((-pos) & 3);
+}
+
 // Sorts values in |container| and removes duplicates.
 template <class T>
 void SortAndUniquify(std::vector<T>* container) {