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:
@ -379,6 +379,7 @@ WebRtc_Word16 WebRtcSpl_RandUArray(WebRtc_Word16* vector,
|
||||
|
||||
// Math functions
|
||||
WebRtc_Word32 WebRtcSpl_Sqrt(WebRtc_Word32 value);
|
||||
WebRtc_Word32 WebRtcSpl_SqrtFloor(WebRtc_Word32 value);
|
||||
|
||||
// Divisions. Implementations collected in division_operations.c and
|
||||
// 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
|
||||
//
|
||||
|
||||
//
|
||||
// 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(...)
|
||||
//
|
||||
|
@ -65,6 +65,7 @@
|
||||
'sin_table.c',
|
||||
'sin_table_1024.c',
|
||||
'spl_sqrt.c',
|
||||
'spl_sqrt_floor.c',
|
||||
'spl_version.c',
|
||||
'splitting_filter.c',
|
||||
'sqrt_of_one_minus_x_squared.c',
|
||||
|
@ -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;
|
||||
}
|
@ -147,6 +147,7 @@ TEST_F(SplTest, MathOperationsTest) {
|
||||
WebRtc_Word32 den = -5;
|
||||
WebRtc_UWord16 denU = 5;
|
||||
EXPECT_EQ(10, WebRtcSpl_Sqrt(A));
|
||||
EXPECT_EQ(10, WebRtcSpl_SqrtFloor(A));
|
||||
|
||||
|
||||
EXPECT_EQ(-91772805, WebRtcSpl_DivResultInQ31(den, num));
|
||||
|
Reference in New Issue
Block a user