diff options
author | Ville Syrjälä <ville.syrjala@linux.intel.com> | 2018-09-07 22:12:26 +0300 |
---|---|---|
committer | Ville Syrjälä <ville.syrjala@linux.intel.com> | 2018-09-11 17:23:30 +0300 |
commit | 20a7ead8bdf09774c7d58fcbe6a0980d08ed5365 (patch) | |
tree | ef61963222cd03faa20a7a828ea62681caba7bd6 /lib/igt_aux.h | |
parent | 5f8a33ad1a4ab5ce0d1eb2ba68ccc284d663531c (diff) |
lib: Add roundup_power_of_two()
Add a helper to round a value to the next power of two size.
And since we need fls() to implement that, reuse that elsewhere
as well.
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/igt_aux.h')
-rw-r--r-- | lib/igt_aux.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/igt_aux.h b/lib/igt_aux.h index ef89faa9..192c3ad8 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -287,4 +287,10 @@ void igt_lsof(const char *dpath); #define is_power_of_two(x) (((x) & ((x)-1)) == 0) +#define igt_fls(x) ((x) ? __builtin_choose_expr(sizeof(x) == 8, \ + 64 - __builtin_clzll(x), \ + 32 - __builtin_clz(x)) : 0) + +#define roundup_power_of_two(x) ((x) != 0 ? 1 << igt_fls((x) - 1) : 0) + #endif /* IGT_AUX_H */ |