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

Ville Syrjälä ville.syrjala at linux.intel.com
Mon Sep 10 15:55:47 UTC 2018


On Mon, Sep 10, 2018 at 04:42:12PM +0100, Chris Wilson wrote:
> 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.

Right. There were some under tools IIRC, implemented in inline asm. 
Didn't bother figuring out what they're used for so I just changed
the name in igt_aux.h to igt_fls() to avoid the clash and moved on.

> 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

-- 
Ville Syrjälä
Intel


More information about the igt-dev mailing list