Add alignment macros.
Introduces align_up, align_down and is_aligned macros that use compiler
builtins if available.
Note: when we fallback to the non-builtin case we could cast back from
uintptr_t to the original type using __typeof() if we accept the
non-standard extension.
Change-Id: Ie0c56f19cb0edc8a211d8c1182b9af5eb329cd8c
diff --git a/src/api.c b/src/api.c
index d342bd6..5e7a033 100644
--- a/src/api.c
+++ b/src/api.c
@@ -619,8 +619,8 @@
int64_t ret;
/* Fail if addresses are not page-aligned. */
- if ((ipa_addr(send) & (PAGE_SIZE - 1)) ||
- (ipa_addr(recv) & (PAGE_SIZE - 1))) {
+ if (!is_aligned(ipa_addr(send), PAGE_SIZE) ||
+ !is_aligned(ipa_addr(recv), PAGE_SIZE)) {
return -1;
}
@@ -1265,8 +1265,8 @@
end = ipa_add(addr, size);
/* Fail if addresses are not page-aligned. */
- if ((ipa_addr(begin) & (PAGE_SIZE - 1)) ||
- (ipa_addr(end) & (PAGE_SIZE - 1))) {
+ if (!is_aligned(ipa_addr(begin), PAGE_SIZE) ||
+ !is_aligned(ipa_addr(end), PAGE_SIZE)) {
return -1;
}