> > > +         for (val = 0; val <= 7; val++) {
> > > +                 period1 = div_s64(val * 1000000000, ppb);
> > > +                 period1 -= 8;
> > > +                 period1 >>= 4;
> > > +                 if (period1 < 1)
> > > +                         period1 = 1;
> > > +                 if (period1 > 0xFFFFFFE)
> > > +                         period1 = 0xFFFFFFE;
> > > +                 period2 = period1 + 1;
> > > +
> > > +                 temp = div_s64(val * 1000000000, (period1 * 16 + 8));
> > > +                 dif1 = ppb - temp;
> > > +                 if (dif1 < 0)
> > > +                         dif1 = -dif1;
> > > +
> > > +                 temp = div_s64(val * 1000000000, (period2 * 16 + 8));
> >
> > Forgetting the useless val=0 case, this still takes 21 64-bit
> > divisions on every adjustment.  There must be a better way.
> >
> > @tglx - Do you have a hint for Sudarsana?
> 
> Maybe we can improve it a bit by making it even uglier and save one of the
> divisions here; But that would still leave a 2-digit number of divisions. I 
> don't
> have an alternative algorithm that would solve that.

Apparently I was over optimistic; Tried pushing the ppb division
out of the loop, but truncation was insufficient and resulted in reduced
drift accuracy.

Richard - we're planning on sending v4 with the existing algorithm
[but without iterating on 'val == 0']; If you have any suggestion for
improving this, please share it.

Thanks,
Yuval

Reply via email to