Aded CMSIS5 DSP and NN folder. Needs some work

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_offset_q31.c Source File

arm_offset_q31.c

00001 /* ----------------------------------------------------------------------
00002  * Project:      CMSIS DSP Library
00003  * Title:        arm_offset_q31.c
00004  * Description:  Q31 vector offset
00005  *
00006  * $Date:        27. January 2017
00007  * $Revision:    V.1.5.1
00008  *
00009  * Target Processor: Cortex-M cores
00010  * -------------------------------------------------------------------- */
00011 /*
00012  * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
00013  *
00014  * SPDX-License-Identifier: Apache-2.0
00015  *
00016  * Licensed under the Apache License, Version 2.0 (the License); you may
00017  * not use this file except in compliance with the License.
00018  * You may obtain a copy of the License at
00019  *
00020  * www.apache.org/licenses/LICENSE-2.0
00021  *
00022  * Unless required by applicable law or agreed to in writing, software
00023  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00024  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00025  * See the License for the specific language governing permissions and
00026  * limitations under the License.
00027  */
00028 
00029 #include "arm_math.h"
00030 
00031 /**
00032  * @ingroup groupMath
00033  */
00034 
00035 /**
00036  * @addtogroup offset
00037  * @{
00038  */
00039 
00040 /**
00041  * @brief  Adds a constant offset to a Q31 vector.
00042  * @param[in]  *pSrc points to the input vector
00043  * @param[in]  offset is the offset to be added
00044  * @param[out]  *pDst points to the output vector
00045  * @param[in]  blockSize number of samples in the vector
00046  * @return none.
00047  *
00048  * <b>Scaling and Overflow Behavior:</b>
00049  * \par
00050  * The function uses saturating arithmetic.
00051  * Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated.
00052  */
00053 
00054 void arm_offset_q31(
00055   q31_t * pSrc,
00056   q31_t offset,
00057   q31_t * pDst,
00058   uint32_t blockSize)
00059 {
00060   uint32_t blkCnt;                               /* loop counter */
00061 
00062 #if defined (ARM_MATH_DSP)
00063 
00064 /* Run the below code for Cortex-M4 and Cortex-M3 */
00065   q31_t in1, in2, in3, in4;
00066 
00067 
00068   /*loop Unrolling */
00069   blkCnt = blockSize >> 2U;
00070 
00071   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
00072    ** a second loop below computes the remaining 1 to 3 samples. */
00073   while (blkCnt > 0U)
00074   {
00075     /* C = A + offset */
00076     /* Add offset and then store the results in the destination buffer. */
00077     in1 = *pSrc++;
00078     in2 = *pSrc++;
00079     in3 = *pSrc++;
00080     in4 = *pSrc++;
00081 
00082     *pDst++ = __QADD(in1, offset);
00083     *pDst++ = __QADD(in2, offset);
00084     *pDst++ = __QADD(in3, offset);
00085     *pDst++ = __QADD(in4, offset);
00086 
00087     /* Decrement the loop counter */
00088     blkCnt--;
00089   }
00090 
00091   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
00092    ** No loop unrolling is used. */
00093   blkCnt = blockSize % 0x4U;
00094 
00095   while (blkCnt > 0U)
00096   {
00097     /* C = A + offset */
00098     /* Add offset and then store the result in the destination buffer. */
00099     *pDst++ = __QADD(*pSrc++, offset);
00100 
00101     /* Decrement the loop counter */
00102     blkCnt--;
00103   }
00104 
00105 #else
00106 
00107   /* Run the below code for Cortex-M0 */
00108 
00109   /* Initialize blkCnt with number of samples */
00110   blkCnt = blockSize;
00111 
00112   while (blkCnt > 0U)
00113   {
00114     /* C = A + offset */
00115     /* Add offset and then store the result in the destination buffer. */
00116     *pDst++ = (q31_t) clip_q63_to_q31((q63_t) * pSrc++ + offset);
00117 
00118     /* Decrement the loop counter */
00119     blkCnt--;
00120   }
00121 
00122 #endif /* #if defined (ARM_MATH_DSP) */
00123 
00124 }
00125 
00126 /**
00127  * @} end of offset group
00128  */
00129