diff options
author | Craig Hesling <hesling@chromium.org> | 2019-12-18 10:40:01 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-12-20 17:37:06 +0000 |
commit | f776a287369e4ac46b17eb9001f3b78621f87325 (patch) | |
tree | 4909489f341027ee17f60657ae4d4184b90d83e5 /include/compile_time_macros.h | |
parent | 7ac25f043ae797e6fabab215e9acf612c8a2ca76 (diff) | |
download | chrome-ec-f776a287369e4ac46b17eb9001f3b78621f87325.tar.gz |
compile_time_macros: Add GENMASK and GENMASK_ULL
BRANCH=all
BUG=none
TEST=make buildall
TEST=make run-compile_time_macros
Change-Id: I586e009dac20e33701ded9a05c51ee806e466cae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1974356
Tested-by: Craig Hesling <hesling@chromium.org>
Auto-Submit: Craig Hesling <hesling@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'include/compile_time_macros.h')
-rw-r--r-- | include/compile_time_macros.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/compile_time_macros.h b/include/compile_time_macros.h index cdf8b1998b..e5c1242f4c 100644 --- a/include/compile_time_macros.h +++ b/include/compile_time_macros.h @@ -41,4 +41,20 @@ #define BIT(nr) (1U << (nr)) #define BIT_ULL(nr) (1ULL << (nr)) +/* + * Create a bit mask from least significant bit |l| + * to bit |h|, inclusive. + * + * Examples: + * GENMASK(31, 0) ==> 0xFF_FF_FF_FF + * GENMASK(3, 0) ==> 0x00_00_00_0F + * GENMASK(7, 4) ==> 0x00_00_00_F0 + * GENMASK(b, b) ==> BIT(b) + * + * Note that we shift after using BIT() to avoid compiler + * warnings for BIT(31+1). + */ +#define GENMASK(h, l) (((BIT(h)<<1) - 1) ^ (BIT(l) - 1)) +#define GENMASK_ULL(h, l) (((BIT_ULL(h)<<1) - 1) ^ (BIT_ULL(l) - 1)) + #endif /* __CROS_EC_COMPILE_TIME_MACROS_H */ |