Added the new sqrt routine as a separate function.

Review URL: http://webrtc-codereview.appspot.com/55004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@175 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
bjornv@google.com
2011-07-07 12:34:44 +00:00
parent 45a7b84dd2
commit c83a3d6e2e
4 changed files with 73 additions and 0 deletions

View File

@ -379,6 +379,7 @@ WebRtc_Word16 WebRtcSpl_RandUArray(WebRtc_Word16* vector,
// Math functions // Math functions
WebRtc_Word32 WebRtcSpl_Sqrt(WebRtc_Word32 value); WebRtc_Word32 WebRtcSpl_Sqrt(WebRtc_Word32 value);
WebRtc_Word32 WebRtcSpl_SqrtFloor(WebRtc_Word32 value);
// Divisions. Implementations collected in division_operations.c and // Divisions. Implementations collected in division_operations.c and
// descriptions at bottom of this file. // descriptions at bottom of this file.
@ -1319,6 +1320,23 @@ void WebRtcSpl_SynthesisQMF(const WebRtc_Word16* low_band,
// Return value : Result of the sqrt calculation // Return value : Result of the sqrt calculation
// //
//
// WebRtcSpl_SqrtFloor(...)
//
// Returns the square root of the input value |value|. The precision of this
// function is rounding down integer precision, i.e., sqrt(8) gives 2 as answer.
// If |value| is a negative number then 0 is returned.
//
// Algorithm:
//
// An iterative 4 cylce/bit routine
//
// Input:
// - value : Value to calculate sqrt of
//
// Return value : Result of the sqrt calculation
//
// //
// WebRtcSpl_DivU32U16(...) // WebRtcSpl_DivU32U16(...)
// //

View File

@ -65,6 +65,7 @@
'sin_table.c', 'sin_table.c',
'sin_table_1024.c', 'sin_table_1024.c',
'spl_sqrt.c', 'spl_sqrt.c',
'spl_sqrt_floor.c',
'spl_version.c', 'spl_version.c',
'splitting_filter.c', 'splitting_filter.c',
'sqrt_of_one_minus_x_squared.c', 'sqrt_of_one_minus_x_squared.c',

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
/*
* This file contains the function WebRtcSpl_SqrtFloor().
* The description header can be found in signal_processing_library.h
*
*/
#include "signal_processing_library.h"
#define WEBRTC_SPL_SQRT_ITER(N) \
try1 = root + (1 << (N)); \
if (value >= try1 << (N)) \
{ \
value -= try1 << (N); \
root |= 2 << (N); \
}
// (out) Square root of input parameter
WebRtc_Word32 WebRtcSpl_SqrtFloor(WebRtc_Word32 value)
{
// new routine for performance, 4 cycles/bit in ARM
// output precision is 16 bits
WebRtc_Word32 root = 0, try1;
WEBRTC_SPL_SQRT_ITER (15);
WEBRTC_SPL_SQRT_ITER (14);
WEBRTC_SPL_SQRT_ITER (13);
WEBRTC_SPL_SQRT_ITER (12);
WEBRTC_SPL_SQRT_ITER (11);
WEBRTC_SPL_SQRT_ITER (10);
WEBRTC_SPL_SQRT_ITER ( 9);
WEBRTC_SPL_SQRT_ITER ( 8);
WEBRTC_SPL_SQRT_ITER ( 7);
WEBRTC_SPL_SQRT_ITER ( 6);
WEBRTC_SPL_SQRT_ITER ( 5);
WEBRTC_SPL_SQRT_ITER ( 4);
WEBRTC_SPL_SQRT_ITER ( 3);
WEBRTC_SPL_SQRT_ITER ( 2);
WEBRTC_SPL_SQRT_ITER ( 1);
WEBRTC_SPL_SQRT_ITER ( 0);
return root >> 1;
}

View File

@ -147,6 +147,7 @@ TEST_F(SplTest, MathOperationsTest) {
WebRtc_Word32 den = -5; WebRtc_Word32 den = -5;
WebRtc_UWord16 denU = 5; WebRtc_UWord16 denU = 5;
EXPECT_EQ(10, WebRtcSpl_Sqrt(A)); EXPECT_EQ(10, WebRtcSpl_Sqrt(A));
EXPECT_EQ(10, WebRtcSpl_SqrtFloor(A));
EXPECT_EQ(-91772805, WebRtcSpl_DivResultInQ31(den, num)); EXPECT_EQ(-91772805, WebRtcSpl_DivResultInQ31(den, num));