Message ID | loom.20090406T230214-297@post.gmane.org (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
On Mon, 6 Apr 2009, Miroslav Å ustek wrote: > Well this patch should solve it. > > I don't know how many samples are processed so: > First patch is for situation when N*N fits in s32. > Second one uses two divisions, but doesn't have any abnormal restrictions for N. Both patches are fine, beacuse in the current implementation N is not bigger than 576. Thanks for fixing this problem. Regards, Marton > > Personally I think that two divisions won't hurt. :) > > > > ----- FILE: cx88-dsp_64bit_math1.patch ----- > > cx88-dsp: fixing 64bit math on 32bit kernels > > Note the limitation of N. > Personally I know nothing about possible size of samples array. > > From: Miroslav Sustek <sustmidown@centrum.cz> > Signed-off-by: Miroslav Sustek <sustmidown@centrum.cz> > > diff -r 8aa1d865373c linux/drivers/media/video/cx88/cx88-dsp.c > --- a/linux/drivers/media/video/cx88/cx88-dsp.c Wed Apr 01 20:25:00 2009 +0000 > +++ b/linux/drivers/media/video/cx88/cx88-dsp.c Tue Apr 07 00:08:48 2009 +0200 > @@ -100,13 +100,22 @@ > s32 s_prev2 = 0; > s32 coeff = 2*int_cos(freq); > u32 i; > + > + s64 tmp; > + u32 remainder; > + > for (i = 0; i < N; i++) { > s32 s = x[i] + ((s64)coeff*s_prev/32768) - s_prev2; > s_prev2 = s_prev; > s_prev = s; > } > - return (u32)(((s64)s_prev2*s_prev2 + (s64)s_prev*s_prev - > - (s64)coeff*s_prev2*s_prev/32768)/N/N); > + > + tmp = (s64)s_prev2*s_prev2 + (s64)s_prev*s_prev - > + (s64)coeff*s_prev2*s_prev/32768; > + > + /* XXX: N must be low enough so that N*N fits in s32. > + * Else we need two divisions. */ > + return (u32) div_s64_rem(tmp, N*N, &remainder); > } > > static u32 freq_magnitude(s16 x[], u32 N, u32 freq) > > > > ----- FILE: cx88-dsp_64bit_math2.patch ----- > > cx88-dsp: fixing 64bit math on 32bit kernels > > From: Miroslav Sustek <sustmidown@centrum.cz> > Signed-off-by: Miroslav Sustek <sustmidown@centrum.cz> > > diff -r 8aa1d865373c linux/drivers/media/video/cx88/cx88-dsp.c > --- a/linux/drivers/media/video/cx88/cx88-dsp.c Wed Apr 01 20:25:00 2009 +0000 > +++ b/linux/drivers/media/video/cx88/cx88-dsp.c Tue Apr 07 00:26:10 2009 +0200 > @@ -100,13 +100,22 @@ > s32 s_prev2 = 0; > s32 coeff = 2*int_cos(freq); > u32 i; > + > + s64 tmp; > + u32 remainder; > + > for (i = 0; i < N; i++) { > s32 s = x[i] + ((s64)coeff*s_prev/32768) - s_prev2; > s_prev2 = s_prev; > s_prev = s; > } > - return (u32)(((s64)s_prev2*s_prev2 + (s64)s_prev*s_prev - > - (s64)coeff*s_prev2*s_prev/32768)/N/N); > + > + tmp = (s64)s_prev2*s_prev2 + (s64)s_prev*s_prev - > + (s64)coeff*s_prev2*s_prev/32768; > + > + tmp = div_s64_rem(tmp, N, &remainder); > + > + return (u32)div_s64_rem(tmp, N, &remainder); > } > > static u32 freq_magnitude(s16 x[], u32 N, u32 freq) > > -- > To unsubscribe from this list: send the line "unsubscribe linux-media" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
diff -r 8aa1d865373c linux/drivers/media/video/cx88/cx88-dsp.c --- a/linux/drivers/media/video/cx88/cx88-dsp.c Wed Apr 01 20:25:00 2009 +0000 +++ b/linux/drivers/media/video/cx88/cx88-dsp.c Tue Apr 07 00:08:48 2009 +0200 @@ -100,13 +100,22 @@ s32 s_prev2 = 0; s32 coeff = 2*int_cos(freq); u32 i; + + s64 tmp; + u32 remainder; + for (i = 0; i < N; i++) { s32 s = x[i] + ((s64)coeff*s_prev/32768) - s_prev2; s_prev2 = s_prev; s_prev = s; } - return (u32)(((s64)s_prev2*s_prev2 + (s64)s_prev*s_prev - - (s64)coeff*s_prev2*s_prev/32768)/N/N); + + tmp = (s64)s_prev2*s_prev2 + (s64)s_prev*s_prev - + (s64)coeff*s_prev2*s_prev/32768; + + /* XXX: N must be low enough so that N*N fits in s32. + * Else we need two divisions. */ + return (u32) div_s64_rem(tmp, N*N, &remainder); } static u32 freq_magnitude(s16 x[], u32 N, u32 freq) ----- FILE: cx88-dsp_64bit_math2.patch ----- cx88-dsp: fixing 64bit math on 32bit kernels From: Miroslav Sustek <sustmidown@centrum.cz> Signed-off-by: Miroslav Sustek <sustmidown@centrum.cz> diff -r 8aa1d865373c linux/drivers/media/video/cx88/cx88-dsp.c --- a/linux/drivers/media/video/cx88/cx88-dsp.c Wed Apr 01 20:25:00 2009 +0000 +++ b/linux/drivers/media/video/cx88/cx88-dsp.c Tue Apr 07 00:26:10 2009 +0200 @@ -100,13 +100,22 @@ s32 s_prev2 = 0; s32 coeff = 2*int_cos(freq); u32 i; + + s64 tmp; + u32 remainder; + for (i = 0; i < N; i++) { s32 s = x[i] + ((s64)coeff*s_prev/32768) - s_prev2; s_prev2 = s_prev; s_prev = s; } - return (u32)(((s64)s_prev2*s_prev2 + (s64)s_prev*s_prev - - (s64)coeff*s_prev2*s_prev/32768)/N/N); + + tmp = (s64)s_prev2*s_prev2 + (s64)s_prev*s_prev - + (s64)coeff*s_prev2*s_prev/32768; + + tmp = div_s64_rem(tmp, N, &remainder); + + return (u32)div_s64_rem(tmp, N, &remainder); } static u32 freq_magnitude(s16 x[], u32 N, u32 freq)