diff options
Diffstat (limited to 'DSP/Source/FastMathFunctions')
-rw-r--r-- | DSP/Source/FastMathFunctions/CMakeLists.txt | 51 | ||||
-rw-r--r-- | DSP/Source/FastMathFunctions/FastMathFunctions.c | 37 | ||||
-rw-r--r-- | DSP/Source/FastMathFunctions/arm_cos_f32.c | 83 | ||||
-rw-r--r-- | DSP/Source/FastMathFunctions/arm_cos_q15.c | 44 | ||||
-rw-r--r-- | DSP/Source/FastMathFunctions/arm_cos_q31.c | 44 | ||||
-rw-r--r-- | DSP/Source/FastMathFunctions/arm_sin_f32.c | 91 | ||||
-rw-r--r-- | DSP/Source/FastMathFunctions/arm_sin_q15.c | 39 | ||||
-rw-r--r-- | DSP/Source/FastMathFunctions/arm_sin_q31.c | 38 | ||||
-rw-r--r-- | DSP/Source/FastMathFunctions/arm_sqrt_q15.c | 36 | ||||
-rw-r--r-- | DSP/Source/FastMathFunctions/arm_sqrt_q31.c | 38 |
10 files changed, 300 insertions, 201 deletions
diff --git a/DSP/Source/FastMathFunctions/CMakeLists.txt b/DSP/Source/FastMathFunctions/CMakeLists.txt new file mode 100644 index 0000000..6719b41 --- /dev/null +++ b/DSP/Source/FastMathFunctions/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required (VERSION 3.6) + +project(CMSISDSPFastMath) + + +file(GLOB SRC "./*_*.c") + +add_library(CMSISDSPFastMath STATIC) + +include(interpol) +interpol(CMSISDSPFastMath) + +if (CONFIGTABLE AND ALLFAST) + target_compile_definitions(CMSISDSPFastMath PUBLIC ARM_ALL_FAST_TABLES) +endif() + +if (NOT CONFIGTABLE OR ALLFAST OR ARM_COS_F32) +target_sources(CMSISDSPFastMath PRIVATE arm_cos_f32.c) +endif() + +if (NOT CONFIGTABLE OR ALLFAST OR ARM_COS_Q15) +target_sources(CMSISDSPFastMath PRIVATE arm_cos_q15.c) +endif() + +if (NOT CONFIGTABLE OR ALLFAST OR ARM_COS_Q31) +target_sources(CMSISDSPFastMath PRIVATE arm_cos_q31.c) +endif() + +if (NOT CONFIGTABLE OR ALLFAST OR ARM_SIN_F32) +target_sources(CMSISDSPFastMath PRIVATE arm_sin_f32.c) +endif() + +if (NOT CONFIGTABLE OR ALLFAST OR ARM_SIN_Q15) +target_sources(CMSISDSPFastMath PRIVATE arm_sin_q15.c) +endif() + +if (NOT CONFIGTABLE OR ALLFAST OR ARM_SIN_Q31) +target_sources(CMSISDSPFastMath PRIVATE arm_sin_q31.c) +endif() + +target_sources(CMSISDSPFastMath PRIVATE arm_sqrt_q15.c) +target_sources(CMSISDSPFastMath PRIVATE arm_sqrt_q31.c) + + +configdsp(CMSISDSPFastMath ..) + +### Includes +target_include_directories(CMSISDSPFastMath PUBLIC "${DSP}/../../Include") + + + diff --git a/DSP/Source/FastMathFunctions/FastMathFunctions.c b/DSP/Source/FastMathFunctions/FastMathFunctions.c new file mode 100644 index 0000000..abd919e --- /dev/null +++ b/DSP/Source/FastMathFunctions/FastMathFunctions.c @@ -0,0 +1,37 @@ +/* ---------------------------------------------------------------------- + * Project: CMSIS DSP Library + * Title: FastMathFunctions.c + * Description: Combination of all fast math function source files. + * + * $Date: 18. March 2019 + * $Revision: V1.0.0 + * + * Target Processor: Cortex-M cores + * -------------------------------------------------------------------- */ +/* + * Copyright (C) 2019 ARM Limited or its affiliates. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "arm_cos_f32.c" +#include "arm_cos_q15.c" +#include "arm_cos_q31.c" +#include "arm_sin_f32.c" +#include "arm_sin_q15.c" +#include "arm_sin_q31.c" +#include "arm_sqrt_q15.c" +#include "arm_sqrt_q31.c" + diff --git a/DSP/Source/FastMathFunctions/arm_cos_f32.c b/DSP/Source/FastMathFunctions/arm_cos_f32.c index e604b3c..26bd66e 100644 --- a/DSP/Source/FastMathFunctions/arm_cos_f32.c +++ b/DSP/Source/FastMathFunctions/arm_cos_f32.c @@ -3,13 +3,13 @@ * Title: arm_cos_f32.c * Description: Fast cosine calculation for floating-point values * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -28,56 +28,57 @@ #include "arm_math.h" #include "arm_common_tables.h" + /** - * @ingroup groupFastMath + @ingroup groupFastMath */ /** - * @defgroup cos Cosine - * - * Computes the trigonometric cosine function using a combination of table lookup - * and linear interpolation. There are separate functions for - * Q15, Q31, and floating-point data types. - * The input to the floating-point version is in radians and in the range [0 2*pi) while the - * fixed-point Q15 and Q31 have a scaled input with the range - * [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a - * value of 2*pi wraps around to 0. - * - * The implementation is based on table lookup using 256 values together with linear interpolation. - * The steps used are: - * -# Calculation of the nearest integer table index - * -# Compute the fractional portion (fract) of the table index. - * -# The final result equals <code>(1.0f-fract)*a + fract*b;</code> - * - * where - * <pre> - * b=Table[index+0]; - * c=Table[index+1]; - * </pre> + @defgroup cos Cosine + + Computes the trigonometric cosine function using a combination of table lookup + and linear interpolation. There are separate functions for + Q15, Q31, and floating-point data types. + The input to the floating-point version is in radians while the + fixed-point Q15 and Q31 have a scaled input with the range + [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a + value of 2*pi wraps around to 0. + + The implementation is based on table lookup using 256 values together with linear interpolation. + The steps used are: + -# Calculation of the nearest integer table index + -# Compute the fractional portion (fract) of the table index. + -# The final result equals <code>(1.0f-fract)*a + fract*b;</code> + + where + <pre> + b = Table[index]; + c = Table[index+1]; + </pre> */ - /** - * @addtogroup cos - * @{ +/** + @addtogroup cos + @{ */ /** - * @brief Fast approximation to the trigonometric cosine function for floating-point data. - * @param[in] x input value in radians. - * @return cos(x). + @brief Fast approximation to the trigonometric cosine function for floating-point data. + @param[in] x input value in radians + @return cos(x) */ float32_t arm_cos_f32( float32_t x) { - float32_t cosVal, fract, in; /* Temporary variables for input, output */ + float32_t cosVal, fract, in; /* Temporary input, output variables */ uint16_t index; /* Index variable */ float32_t a, b; /* Two nearest output values */ int32_t n; float32_t findex; /* input x is in radians */ - /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi, add 0.25 (pi/2) to read sine table */ + /* Scale input to [0 1] range from [0 2*PI] , divide input by 2*pi, add 0.25 (pi/2) to read sine table */ in = x * 0.159154943092f + 0.25f; /* Calculation of floor value of input */ @@ -93,8 +94,14 @@ float32_t arm_cos_f32( in = in - (float32_t) n; /* Calculation of index of the table */ - findex = (float32_t) FAST_MATH_TABLE_SIZE * in; - index = ((uint16_t)findex) & 0x1ff; + findex = (float32_t)FAST_MATH_TABLE_SIZE * in; + index = (uint16_t)findex; + + /* when "in" is exactly 1, we need to rotate the index down to 0 */ + if (index >= FAST_MATH_TABLE_SIZE) { + index = 0; + findex -= (float32_t)FAST_MATH_TABLE_SIZE; + } /* fractional value calculation */ fract = findex - (float32_t) index; @@ -104,12 +111,12 @@ float32_t arm_cos_f32( b = sinTable_f32[index+1]; /* Linear interpolation process */ - cosVal = (1.0f-fract)*a + fract*b; + cosVal = (1.0f - fract) * a + fract * b; - /* Return the output value */ + /* Return output value */ return (cosVal); } /** - * @} end of cos group + @} end of cos group */ diff --git a/DSP/Source/FastMathFunctions/arm_cos_q15.c b/DSP/Source/FastMathFunctions/arm_cos_q15.c index 7fa2e18..3bb829c 100644 --- a/DSP/Source/FastMathFunctions/arm_cos_q15.c +++ b/DSP/Source/FastMathFunctions/arm_cos_q15.c @@ -3,13 +3,13 @@ * Title: arm_cos_q15.c * Description: Fast cosine calculation for Q15 values * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -30,36 +30,35 @@ #include "arm_common_tables.h" /** - * @ingroup groupFastMath + @ingroup groupFastMath */ - /** - * @addtogroup cos - * @{ +/** + @addtogroup cos + @{ */ /** - * @brief Fast approximation to the trigonometric cosine function for Q15 data. - * @param[in] x Scaled input value in radians. - * @return cos(x). - * - * The Q15 input value is in the range [0 +0.9999] and is mapped to a radian - * value in the range [0 2*pi). + @brief Fast approximation to the trigonometric cosine function for Q15 data. + @param[in] x Scaled input value in radians + @return cos(x) + + The Q15 input value is in the range [0 +0.9999] and is mapped to a radian value in the range [0 2*PI). */ q15_t arm_cos_q15( q15_t x) { - q15_t cosVal; /* Temporary variables for input, output */ - int32_t index; /* Index variables */ - q15_t a, b; /* Four nearest output values */ + q15_t cosVal; /* Temporary input, output variables */ + int32_t index; /* Index variable */ + q15_t a, b; /* Two nearest output values */ q15_t fract; /* Temporary values for fractional values */ /* add 0.25 (pi/2) to read sine table */ x = (uint16_t)x + 0x2000; if (x < 0) - { /* convert negative numbers to corresponding positive ones */ - x = (uint16_t)x + 0x8000; + { /* convert negative numbers to corresponding positive ones */ + x = (uint16_t)x + 0x8000; } /* Calculate the nearest index */ @@ -73,12 +72,13 @@ q15_t arm_cos_q15( b = sinTable_q15[index+1]; /* Linear interpolation process */ - cosVal = (q31_t)(0x8000-fract)*a >> 16; - cosVal = (q15_t)((((q31_t)cosVal << 16) + ((q31_t)fract*b)) >> 16); + cosVal = (q31_t) (0x8000 - fract) * a >> 16; + cosVal = (q15_t) ((((q31_t) cosVal << 16) + ((q31_t) fract * b)) >> 16); - return cosVal << 1; + /* Return output value */ + return (cosVal << 1); } /** - * @} end of cos group + @} end of cos group */ diff --git a/DSP/Source/FastMathFunctions/arm_cos_q31.c b/DSP/Source/FastMathFunctions/arm_cos_q31.c index fde5368..8b7ff78 100644 --- a/DSP/Source/FastMathFunctions/arm_cos_q31.c +++ b/DSP/Source/FastMathFunctions/arm_cos_q31.c @@ -3,13 +3,13 @@ * Title: arm_cos_q31.c * Description: Fast cosine calculation for Q31 values * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -30,36 +30,35 @@ #include "arm_common_tables.h" /** - * @ingroup groupFastMath + @ingroup groupFastMath */ - /** - * @addtogroup cos - * @{ +/** + @addtogroup cos + @{ */ /** - * @brief Fast approximation to the trigonometric cosine function for Q31 data. - * @param[in] x Scaled input value in radians. - * @return cos(x). - * - * The Q31 input value is in the range [0 +0.9999] and is mapped to a radian - * value in the range [0 2*pi). + @brief Fast approximation to the trigonometric cosine function for Q31 data. + @param[in] x Scaled input value in radians + @return cos(x) + + The Q31 input value is in the range [0 +0.9999] and is mapped to a radian value in the range [0 2*PI). */ q31_t arm_cos_q31( q31_t x) { - q31_t cosVal; /* Temporary variables for input, output */ - int32_t index; /* Index variables */ - q31_t a, b; /* Four nearest output values */ + q31_t cosVal; /* Temporary input, output variables */ + int32_t index; /* Index variable */ + q31_t a, b; /* Two nearest output values */ q31_t fract; /* Temporary values for fractional values */ /* add 0.25 (pi/2) to read sine table */ x = (uint32_t)x + 0x20000000; if (x < 0) - { /* convert negative numbers to corresponding positive ones */ - x = (uint32_t)x + 0x80000000; + { /* convert negative numbers to corresponding positive ones */ + x = (uint32_t)x + 0x80000000; } /* Calculate the nearest index */ @@ -73,12 +72,13 @@ q31_t arm_cos_q31( b = sinTable_q31[index+1]; /* Linear interpolation process */ - cosVal = (q63_t)(0x80000000-fract)*a >> 32; - cosVal = (q31_t)((((q63_t)cosVal << 32) + ((q63_t)fract*b)) >> 32); + cosVal = (q63_t) (0x80000000 - fract) * a >> 32; + cosVal = (q31_t) ((((q63_t) cosVal << 32) + ((q63_t) fract * b)) >> 32); - return cosVal << 1; + /* Return output value */ + return (cosVal << 1); } /** - * @} end of cos group + @} end of cos group */ diff --git a/DSP/Source/FastMathFunctions/arm_sin_f32.c b/DSP/Source/FastMathFunctions/arm_sin_f32.c index ce8b9b9..97c6902 100644 --- a/DSP/Source/FastMathFunctions/arm_sin_f32.c +++ b/DSP/Source/FastMathFunctions/arm_sin_f32.c @@ -3,13 +3,13 @@ * Title: arm_sin_f32.c * Description: Fast sine calculation for floating-point values * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -28,70 +28,64 @@ #include "arm_math.h" #include "arm_common_tables.h" -#include <math.h> /** - * @ingroup groupFastMath + @ingroup groupFastMath */ /** - * @defgroup sin Sine - * - * Computes the trigonometric sine function using a combination of table lookup - * and linear interpolation. There are separate functions for - * Q15, Q31, and floating-point data types. - * The input to the floating-point version is in radians and in the range [0 2*pi) while the - * fixed-point Q15 and Q31 have a scaled input with the range - * [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a - * value of 2*pi wraps around to 0. - * - * The implementation is based on table lookup using 256 values together with linear interpolation. - * The steps used are: - * -# Calculation of the nearest integer table index - * -# Compute the fractional portion (fract) of the table index. - * -# The final result equals <code>(1.0f-fract)*a + fract*b;</code> - * - * where - * <pre> - * b=Table[index+0]; - * c=Table[index+1]; - * </pre> + @defgroup sin Sine + + Computes the trigonometric sine function using a combination of table lookup + and linear interpolation. There are separate functions for + Q15, Q31, and floating-point data types. + The input to the floating-point version is in radians while the + fixed-point Q15 and Q31 have a scaled input with the range + [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a + value of 2*pi wraps around to 0. + + The implementation is based on table lookup using 256 values together with linear interpolation. + The steps used are: + -# Calculation of the nearest integer table index + -# Compute the fractional portion (fract) of the table index. + -# The final result equals <code>(1.0f-fract)*a + fract*b;</code> + + where + <pre> + b = Table[index]; + c = Table[index+1]; + </pre> */ /** - * @addtogroup sin - * @{ + @addtogroup sin + @{ */ /** - * @brief Fast approximation to the trigonometric sine function for floating-point data. - * @param[in] x input value in radians. - * @return sin(x). + @brief Fast approximation to the trigonometric sine function for floating-point data. + @param[in] x input value in radians. + @return sin(x) */ float32_t arm_sin_f32( float32_t x) { - float32_t sinVal, fract, in; /* Temporary variables for input, output */ - uint16_t index; /* Index variable */ - float32_t a, b; /* Two nearest output values */ + float32_t sinVal, fract, in; /* Temporary input, output variables */ + uint16_t index; /* Index variable */ + float32_t a, b; /* Two nearest output values */ int32_t n; float32_t findex; - /* Special case for small negative inputs */ - if ((x < 0.0f) && (x >= -1.9e-7f)) { - return x; - } - /* input x is in radians */ - /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */ + /* Scale input to [0 1] range from [0 2*PI] , divide input by 2*pi */ in = x * 0.159154943092f; /* Calculation of floor value of input */ n = (int32_t) in; /* Make negative values towards -infinity */ - if (x < 0.0f) + if (in < 0.0f) { n--; } @@ -100,9 +94,14 @@ float32_t arm_sin_f32( in = in - (float32_t) n; /* Calculation of index of the table */ - findex = (float32_t) FAST_MATH_TABLE_SIZE * in; + findex = (float32_t)FAST_MATH_TABLE_SIZE * in; + index = (uint16_t)findex; - index = ((uint16_t)findex) & 0x1ff; + /* when "in" is exactly 1, we need to rotate the index down to 0 */ + if (index >= FAST_MATH_TABLE_SIZE) { + index = 0; + findex -= (float32_t)FAST_MATH_TABLE_SIZE; + } /* fractional value calculation */ fract = findex - (float32_t) index; @@ -112,12 +111,12 @@ float32_t arm_sin_f32( b = sinTable_f32[index+1]; /* Linear interpolation process */ - sinVal = (1.0f-fract)*a + fract*b; + sinVal = (1.0f - fract) * a + fract * b; - /* Return the output value */ + /* Return output value */ return (sinVal); } /** - * @} end of sin group + @} end of sin group */ diff --git a/DSP/Source/FastMathFunctions/arm_sin_q15.c b/DSP/Source/FastMathFunctions/arm_sin_q15.c index 7c8f627..1f0c2bf 100644 --- a/DSP/Source/FastMathFunctions/arm_sin_q15.c +++ b/DSP/Source/FastMathFunctions/arm_sin_q15.c @@ -3,13 +3,13 @@ * Title: arm_sin_q15.c * Description: Fast sine calculation for Q15 values * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -30,28 +30,28 @@ #include "arm_common_tables.h" /** - * @ingroup groupFastMath + @ingroup groupFastMath */ - /** - * @addtogroup sin - * @{ +/** + @addtogroup sin + @{ */ /** - * @brief Fast approximation to the trigonometric sine function for Q15 data. - * @param[in] x Scaled input value in radians. - * @return sin(x). - * - * The Q15 input value is in the range [0 +0.9999] and is mapped to a radian value in the range [0 2*pi). + @brief Fast approximation to the trigonometric sine function for Q15 data. + @param[in] x Scaled input value in radians + @return sin(x) + + The Q15 input value is in the range [0 +0.9999] and is mapped to a radian value in the range [0 2*PI). */ q15_t arm_sin_q15( q15_t x) { - q15_t sinVal; /* Temporary variables for input, output */ - int32_t index; /* Index variables */ - q15_t a, b; /* Four nearest output values */ + q15_t sinVal; /* Temporary input, output variables */ + int32_t index; /* Index variable */ + q15_t a, b; /* Two nearest output values */ q15_t fract; /* Temporary values for fractional values */ /* Calculate the nearest index */ @@ -65,12 +65,13 @@ q15_t arm_sin_q15( b = sinTable_q15[index+1]; /* Linear interpolation process */ - sinVal = (q31_t)(0x8000-fract)*a >> 16; - sinVal = (q15_t)((((q31_t)sinVal << 16) + ((q31_t)fract*b)) >> 16); + sinVal = (q31_t) (0x8000 - fract) * a >> 16; + sinVal = (q15_t) ((((q31_t) sinVal << 16) + ((q31_t) fract * b)) >> 16); - return sinVal << 1; + /* Return output value */ + return (sinVal << 1); } /** - * @} end of sin group + @} end of sin group */ diff --git a/DSP/Source/FastMathFunctions/arm_sin_q31.c b/DSP/Source/FastMathFunctions/arm_sin_q31.c index 8d3c7ac..8cefabb 100644 --- a/DSP/Source/FastMathFunctions/arm_sin_q31.c +++ b/DSP/Source/FastMathFunctions/arm_sin_q31.c @@ -3,13 +3,13 @@ * Title: arm_sin_q31.c * Description: Fast sine calculation for Q31 values * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -30,27 +30,28 @@ #include "arm_common_tables.h" /** - * @ingroup groupFastMath + @ingroup groupFastMath */ - /** - * @addtogroup sin - * @{ +/** + @addtogroup sin + @{ */ /** - * @brief Fast approximation to the trigonometric sine function for Q31 data. - * @param[in] x Scaled input value in radians. - * @return sin(x). - * - * The Q31 input value is in the range [0 +0.9999] and is mapped to a radian value in the range [0 2*pi). */ + @brief Fast approximation to the trigonometric sine function for Q31 data. + @param[in] x Scaled input value in radians + @return sin(x) + + The Q31 input value is in the range [0 +0.9999] and is mapped to a radian value in the range [0 2*PI). + */ q31_t arm_sin_q31( q31_t x) { q31_t sinVal; /* Temporary variables for input, output */ - int32_t index; /* Index variables */ - q31_t a, b; /* Four nearest output values */ + int32_t index; /* Index variable */ + q31_t a, b; /* Two nearest output values */ q31_t fract; /* Temporary values for fractional values */ /* Calculate the nearest index */ @@ -64,12 +65,13 @@ q31_t arm_sin_q31( b = sinTable_q31[index+1]; /* Linear interpolation process */ - sinVal = (q63_t)(0x80000000-fract)*a >> 32; - sinVal = (q31_t)((((q63_t)sinVal << 32) + ((q63_t)fract*b)) >> 32); + sinVal = (q63_t) (0x80000000 - fract) * a >> 32; + sinVal = (q31_t) ((((q63_t) sinVal << 32) + ((q63_t) fract * b)) >> 32); - return sinVal << 1; + /* Return output value */ + return (sinVal << 1); } /** - * @} end of sin group + @} end of sin group */ diff --git a/DSP/Source/FastMathFunctions/arm_sqrt_q15.c b/DSP/Source/FastMathFunctions/arm_sqrt_q15.c index 8487ed3..fab0a32 100644 --- a/DSP/Source/FastMathFunctions/arm_sqrt_q15.c +++ b/DSP/Source/FastMathFunctions/arm_sqrt_q15.c @@ -3,13 +3,13 @@ * Title: arm_sqrt_q15.c * Description: Q15 square root function * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -29,31 +29,30 @@ #include "arm_math.h" #include "arm_common_tables.h" - /** - * @ingroup groupFastMath + @ingroup groupFastMath */ /** - * @addtogroup SQRT - * @{ + @addtogroup SQRT + @{ */ - /** - * @brief Q15 square root function. - * @param[in] in input value. The range of the input value is [0 +1) or 0x0000 to 0x7FFF. - * @param[out] *pOut square root of input value. - * @return The function returns ARM_MATH_SUCCESS if the input value is positive - * and ARM_MATH_ARGUMENT_ERROR if the input is negative. For - * negative inputs, the function returns *pOut = 0. - */ +/** + @brief Q15 square root function. + @param[in] in input value. The range of the input value is [0 +1) or 0x0000 to 0x7FFF + @param[out] pOut points to square root of input value + @return execution status + - \ref ARM_MATH_SUCCESS : input value is positive + - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0 + */ arm_status arm_sqrt_q15( q15_t in, q15_t * pOut) { - q15_t number, temp1, var1, signBits1, half; q31_t bits_val1; + q15_t number, temp1, var1, signBits1, half; float32_t temp_float1; union { @@ -85,7 +84,7 @@ arm_status arm_sqrt_q15( /* Convert to float */ temp_float1 = number * 3.051757812500000e-005f; - /*Store as integer */ + /* Store as integer */ tempconv.floatval = temp_float1; bits_val1 = tempconv.fracval; /* Subtract the shifted value from the magic number to give intial guess */ @@ -135,10 +134,11 @@ arm_status arm_sqrt_q15( else { *pOut = 0; + return (ARM_MATH_ARGUMENT_ERROR); } } /** - * @} end of SQRT group + @} end of SQRT group */ diff --git a/DSP/Source/FastMathFunctions/arm_sqrt_q31.c b/DSP/Source/FastMathFunctions/arm_sqrt_q31.c index 0deea04..9889b13 100644 --- a/DSP/Source/FastMathFunctions/arm_sqrt_q31.c +++ b/DSP/Source/FastMathFunctions/arm_sqrt_q31.c @@ -3,13 +3,13 @@ * Title: arm_sqrt_q31.c * Description: Q31 square root function * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -30,33 +30,34 @@ #include "arm_common_tables.h" /** - * @ingroup groupFastMath + @ingroup groupFastMath */ /** - * @addtogroup SQRT - * @{ + @addtogroup SQRT + @{ */ /** - * @brief Q31 square root function. - * @param[in] in input value. The range of the input value is [0 +1) or 0x00000000 to 0x7FFFFFFF. - * @param[out] *pOut square root of input value. - * @return The function returns ARM_MATH_SUCCESS if the input value is positive - * and ARM_MATH_ARGUMENT_ERROR if the input is negative. For - * negative inputs, the function returns *pOut = 0. + @brief Q31 square root function. + @param[in] in input value. The range of the input value is [0 +1) or 0x00000000 to 0x7FFFFFFF + @param[out] pOut points to square root of input value + @return execution status + - \ref ARM_MATH_SUCCESS : input value is positive + - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0 */ arm_status arm_sqrt_q31( q31_t in, q31_t * pOut) { - q31_t number, temp1, bits_val1, var1, signBits1, half; + q31_t bits_val1; + q31_t number, temp1, var1, signBits1, half; float32_t temp_float1; union { - q31_t fracval; - float32_t floatval; + q31_t fracval; + float32_t floatval; } tempconv; number = in; @@ -81,9 +82,9 @@ arm_status arm_sqrt_q31( /* Store the number for later use */ temp1 = number; - /*Convert to float */ + /* Convert to float */ temp_float1 = number * 4.6566128731e-010f; - /*Store as integer */ + /* Store as integer */ tempconv.floatval = temp_float1; bits_val1 = tempconv.fracval; /* Subtract the shifted value from the magic number to give intial guess */ @@ -133,10 +134,11 @@ arm_status arm_sqrt_q31( else { *pOut = 0; + return (ARM_MATH_ARGUMENT_ERROR); } } /** - * @} end of SQRT group + @} end of SQRT group */ |