[igt-dev] [PATCH i-g-t 3/3] lib: Add roundup_power_of_two()

Chris Wilson chris at chris-wilson.co.uk
Mon Sep 10 15:42:12 UTC 2018


Quoting Ville Syrjala (2018-09-10 16:34:07)
> From: Ville Syrjälä <ville.syrjala at linux.intel.com>
> 
> 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 at linux.intel.com>

Looks reasonable. There should be a few more fls around, it tends to be
useful.

Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>

> ---
>  lib/igt_aux.h          |  6 ++++++
>  lib/igt_fb.c           | 12 ++++--------
>  tests/gem_exec_reuse.c | 12 +-----------
>  3 files changed, 11 insertions(+), 19 deletions(-)
> 
> diff --git a/lib/igt_aux.h b/lib/igt_aux.h
> index ef89faa9bd30..192c3ad88658 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)

Though I wonder if __builtin_types_compatible_p(typeof(x), long long)
would be better (then we could have the long long; long; int cascade).
I've failed every time I tried to use types_compatible, maybe you'll
have better luck :)
-Chris


More information about the igt-dev mailing list