From patchwork Mon Apr 6 23:07:04 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWlyb3NsYXYgw4XCoHVzdGVr?= X-Patchwork-Id: 16689 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n36NAdn2021664 for ; Mon, 6 Apr 2009 23:10:40 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758743AbZDFXKJ (ORCPT ); Mon, 6 Apr 2009 19:10:09 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758583AbZDFXKI (ORCPT ); Mon, 6 Apr 2009 19:10:08 -0400 Received: from main.gmane.org ([80.91.229.2]:46217 "EHLO ciao.gmane.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755529AbZDFXKH (ORCPT ); Mon, 6 Apr 2009 19:10:07 -0400 Received: from root by ciao.gmane.org with local (Exim 4.43) id 1Lqxx4-0008AQ-Vf for linux-media@vger.kernel.org; Mon, 06 Apr 2009 23:10:03 +0000 Received: from 63.84.broadband6.iol.cz ([88.101.84.63]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 06 Apr 2009 23:10:02 +0000 Received: from sustmidown by 63.84.broadband6.iol.cz with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 06 Apr 2009 23:10:02 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: linux-media@vger.kernel.org From: Miroslav =?utf-8?b?xaB1c3Rlaw==?= Subject: [PATCH] Re: cx88-dsp.c: missing =?utf-8?b?X19kaXZkaTM=?= on 32bit kernel Date: Mon, 6 Apr 2009 23:07:04 +0000 (UTC) Lines: 86 Message-ID: References: <200904062233.30966@centrum.cz> <200904062234.8192@centrum.cz> <200904062235.15206@centrum.cz> <200904062236.31983@centrum.cz> <200904062237.27161@centrum.cz> <200904062238.10335@centrum.cz> <200904062239.877@centrum.cz> <200904062240.9520@centrum.cz> <200904062240.1773@centrum.cz> Mime-Version: 1.0 X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: main.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 88.101.84.63 (Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b3) Gecko/20090327 Fedora/3.1-0.11.beta3.fc11 Firefox/3.1b3) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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. 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 Signed-off-by: Miroslav Sustek --- 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 Signed-off-by: Miroslav Sustek 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)