aboutsummaryrefslogtreecommitdiff
path: root/lib/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common.h')
-rw-r--r--lib/common.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/common.h b/lib/common.h
index 599759f..4d60199 100644
--- a/lib/common.h
+++ b/lib/common.h
@@ -58,6 +58,14 @@
#define ROUND_DOWN(x, a) ((x) & ~((a)-1))
#define ROUND_UP(x,a) ROUND_DOWN((x)+(a)-1, a)
+/* Saturating uint64_t addition. */
+static inline uint64_t
+satadd_u64(uint64_t a, uint64_t b)
+{
+ uint64_t res = a + b;
+ return (res < a) ? UINT64_MAX : res;
+}
+
/*
* The size, in bytes, of the bitmap that represents the given range with the
* given page size.