[U-Boot] [PATCH 03/33] Add ALIGN_DOWN() to find next smallest alignment

Simon Glass sjg at chromium.org
Wed Nov 12 01:17:51 CET 2014


We have an ALIGN() macro - add a comment as to what this does. Also add a
new ALIGN_DOWN() macro, which aligns a value to the next smallest multiple.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 include/common.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/common.h b/include/common.h
index ecf7fca..28fba79 100644
--- a/include/common.h
+++ b/include/common.h
@@ -970,9 +970,24 @@ static inline phys_addr_t map_to_sysmem(const void *ptr)
 }							\
 )
 
+/**
+ * ALIGN() - return an aligned value not less than the given value
+ *
+ * @x:	Value to align
+ * @a:	Alignment to use, e.g. 4 to align to multiples of 4
+ */
 #define ALIGN(x,a)		__ALIGN_MASK((x),(typeof(x))(a)-1)
+
 #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
 
+/**
+ * ALIGN_DOWN() - return an aligned value not greater than the given value
+ *
+ * @x:	Value to align
+ * @a:	Alignment to use, e.g. 4 to align to multiples of 4
+ */
+#define ALIGN_DOWN(x, a)	((x) & ~((typeof(x))(a) - 1UL))
+
 /*
  * ARCH_DMA_MINALIGN is defined in asm/cache.h for each architecture.  It
  * is used to align DMA buffers.
-- 
2.1.0.rc2.206.gedb03e5



More information about the U-Boot mailing list