From a22b59b2a8fd68a9973c77a5400644fbdbf93091 Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Fri, 16 Jun 2017 14:19:47 +0200 Subject: [PATCH] macros: add mask() as a macro to calculate the bit mask --- include/macros.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/macros.h b/include/macros.h index f8189f3..bf7627f 100644 --- a/include/macros.h +++ b/include/macros.h @@ -21,6 +21,7 @@ #define ROUND_DOWN(x, k) ((x) & ~((k) - 1)) #define ROUND_UP(x, k) (((x) + (k) - 1) & ~((k) - 1)) +#define mask(x, k) ((x) & ((1 << (k)) - 1)) #define align(x, k) ((x) & ~((1 << (k)) - 1)) #define align_up(x, k) align(x + ((1 << (k)) - 1), k) #define is_aligned(x, k) (!((x) & ((1 << (k)) - 1)))