From d4ad24a314cea1020c7cd08b27670f5da495e38d Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 5 Nov 2019 18:56:34 -0500 Subject: [PATCH 1/1] align.h: Implement ALIGN_FLOOR macro MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Implement the ALIGN_FLOOR macro which aligns the given value to the previous alignment boundary, or keeps the value as-is if it is already aligned. Signed-off-by: Mathieu Desnoyers Change-Id: I36d981e8fb705fafa3ff23ba2d82ec1babe73e45 Signed-off-by: Jérémie Galarneau --- src/common/align.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/common/align.h b/src/common/align.h index ed353206d..c8d9d5176 100644 --- a/src/common/align.h +++ b/src/common/align.h @@ -35,6 +35,12 @@ #define ALIGN(v, align) __ALIGN_MASK(v, (__typeof__(v)) (align) - 1) #endif +#define __ALIGN_FLOOR_MASK(v, mask) ((v) & ~(mask)) + +#ifndef ALIGN_FLOOR +#define ALIGN_FLOOR(v, align) __ALIGN_FLOOR_MASK(v, (__typeof__(v)) (align) - 1) +#endif + #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) /** -- 2.34.1