Robert Lopez / CMSIS5
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_negate_q7.c Source File

arm_negate_q7.c

00001 /* ----------------------------------------------------------------------
00002  * Project:      CMSIS DSP Library
00003  * Title:        arm_negate_q7.c
00004  * Description:  Negates Q7 vectors
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 negate
00037  * @{
00038  */
00039 
00040 /**
00041  * @brief  Negates the elements of a Q7 vector.
00042  * @param[in]  *pSrc points to the input vector
00043  * @param[out]  *pDst points to the output vector
00044  * @param[in]  blockSize number of samples in the vector
00045  * @return none.
00046  *
00047  * <b>Scaling and Overflow Behavior:</b>
00048  * \par
00049  * The function uses saturating arithmetic.
00050  * The Q7 value -1 (0x80) will be saturated to the maximum allowable positive value 0x7F.
00051  */
00052 
00053 void arm_negate_q7(
00054   q7_t * pSrc,
00055   q7_t * pDst,
00056   uint32_t blockSize)
00057 {
00058   uint32_t blkCnt;                               /* loop counter */
00059   q7_t in;
00060 
00061 #if defined (ARM_MATH_DSP)
00062 
00063 /* Run the below code for Cortex-M4 and Cortex-M3 */
00064   q31_t input;                                   /* Input values1-4 */
00065   q31_t zero = 0x00000000;
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 */
00076     /* Read four inputs */
00077     input = *__SIMD32(pSrc)++;
00078 
00079     /* Store the Negated results in the destination buffer in a single cycle by packing the results */
00080     *__SIMD32(pDst)++ = __QSUB8(zero, input);
00081 
00082     /* Decrement the loop counter */
00083     blkCnt--;
00084   }
00085 
00086   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
00087    ** No loop unrolling is used. */
00088   blkCnt = blockSize % 0x4U;
00089 
00090 #else
00091 
00092   /* Run the below code for Cortex-M0 */
00093 
00094   /* Initialize blkCnt with number of samples */
00095   blkCnt = blockSize;
00096 
00097 #endif /* #if defined (ARM_MATH_DSP) */
00098 
00099   while (blkCnt > 0U)
00100   {
00101     /* C = -A */
00102     /* Negate and then store the results in the destination buffer. */ \
00103       in = *pSrc++;
00104     *pDst++ = (in == (q7_t) 0x80) ? 0x7f : -in;
00105 
00106     /* Decrement the loop counter */
00107     blkCnt--;
00108   }
00109 }
00110 
00111 /**
00112  * @} end of negate group
00113  */
00114