On Wed, Oct 11, 2017 at 10:29 AM, sakari.ai...@linux.intel.com
<sakari.ai...@linux.intel.com> wrote:
> On Wed, Oct 11, 2017 at 04:14:37AM +0000, Zhi, Yong wrote:

>> > > +static unsigned int ipu3_css_scaler_get_exp(unsigned int counter,
>> > > +                                           unsigned int divider) {
>> > > +       unsigned int i = 0;
>> > > +
>> > > +       while (counter <= divider / 2) {
>> > > +               divider /= 2;
>> > > +               i++;
>> > > +       }
>> > > +
>> > > +       return i;

>         return (!counter || divider < counter) ?
>                0 : fls(divider / counter) - 1;

Extra division is here (I dunno if counter is always power of 2 but it
doesn't matter for compiler).

Basically above calculates how much bits we need to shift divider to
get it less than counter.

I would consider to use something from log2.h.

Roughly like

if (!counter || divider < counter)
 return 0;
return order_base_2(divider) - order_base_2(counter);

-- 
With Best Regards,
Andy Shevchenko

Reply via email to