Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of dsp by
arm_sqrt_q15.c
00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 29. November 2010 00005 * $Revision: V1.0.3 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_sqrt_q15.c 00009 * 00010 * Description: Q15 square root function. 00011 * 00012 * Target Processor: Cortex-M4/Cortex-M3 00013 * 00014 * Version 1.0.3 2010/11/29 00015 * Re-organized the CMSIS folders and updated documentation. 00016 * 00017 * Version 1.0.2 2010/11/11 00018 * Documentation updated. 00019 * 00020 * Version 1.0.1 2010/10/05 00021 * Production release and review comments incorporated. 00022 * 00023 * Version 1.0.0 2010/09/20 00024 * Production release and review comments incorporated. 00025 * -------------------------------------------------------------------- */ 00026 00027 #include "arm_math.h" 00028 #include "arm_common_tables.h" 00029 00030 00031 /** 00032 * @ingroup groupFastMath 00033 */ 00034 00035 /** 00036 * @addtogroup SQRT 00037 * @{ 00038 */ 00039 00040 /** 00041 * @brief Q15 square root function. 00042 * @param[in] in input value. The range of the input value is [0 +1) or 0x0000 to 0x7FFF. 00043 * @param[out] *pOut square root of input value. 00044 * @return The function returns ARM_MATH_SUCCESS if input value is positive value or ARM_MATH_ARGUMENT_ERROR if 00045 * <code>in</code> is negative value and returns zero output for negative values. 00046 */ 00047 00048 arm_status arm_sqrt_q15( 00049 q15_t in, 00050 q15_t * pOut) 00051 { 00052 q31_t out; 00053 q31_t prevOut; 00054 q15_t oneByOut; 00055 uint32_t sign_bits; 00056 00057 if(in > 0) 00058 { 00059 /* run for ten iterations */ 00060 00061 /* Take initial guess as half of the input and first iteration */ 00062 out = ((q31_t) in >> 1u) + 0x3FFF; 00063 00064 /* Calculation of reciprocal of out */ 00065 /* oneByOut contains reciprocal of out which is in 2.14 format 00066 and oneByOut should be upscaled by signBits */ 00067 sign_bits = arm_recip_q15((q15_t) out, &oneByOut, (q15_t*)armRecipTableQ15); 00068 00069 /* 0.5 * (out) */ 00070 out = out >> 1u; 00071 /* prevOut = 0.5 * out + (in * (oneByOut << signBits))) */ 00072 prevOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits); 00073 00074 /* Third iteration */ 00075 sign_bits = arm_recip_q15((q15_t) prevOut, &oneByOut, (q15_t*)armRecipTableQ15); 00076 prevOut = prevOut >> 1u; 00077 out = prevOut + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits); 00078 00079 sign_bits = arm_recip_q15((q15_t) out, &oneByOut, (q15_t*)armRecipTableQ15); 00080 out = out >> 1u; 00081 prevOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits); 00082 00083 /* Fifth iteration */ 00084 sign_bits = arm_recip_q15((q15_t) prevOut, &oneByOut, (q15_t*)armRecipTableQ15); 00085 prevOut = prevOut >> 1u; 00086 out = prevOut + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits); 00087 00088 sign_bits = arm_recip_q15((q15_t) out, &oneByOut, (q15_t*)armRecipTableQ15); 00089 out = out >> 1u; 00090 prevOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits); 00091 00092 /* Seventh iteration */ 00093 sign_bits = arm_recip_q15((q15_t) prevOut, &oneByOut, (q15_t*)armRecipTableQ15); 00094 prevOut = prevOut >> 1u; 00095 out = prevOut + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits); 00096 00097 sign_bits = arm_recip_q15((q15_t) out, &oneByOut, (q15_t*)armRecipTableQ15); 00098 out = out >> 1u; 00099 prevOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits); 00100 00101 sign_bits = arm_recip_q15((q15_t) prevOut, &oneByOut, (q15_t*)armRecipTableQ15); 00102 prevOut = prevOut >> 1u; 00103 out = prevOut + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits); 00104 00105 /* tenth iteration */ 00106 sign_bits = arm_recip_q15((q15_t) out, &oneByOut, (q15_t*)armRecipTableQ15); 00107 out = out >> 1u; 00108 *pOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits); 00109 00110 return (ARM_MATH_SUCCESS); 00111 } 00112 else 00113 { 00114 00115 *pOut = 0; 00116 return (ARM_MATH_ARGUMENT_ERROR); 00117 } 00118 00119 } 00120 00121 /** 00122 * @} end of SQRT group 00123 */
Generated on Tue Jul 12 2022 19:55:44 by
1.7.2
