The CMSIS DSP 5 library

Dependents:   Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more

Committer:
xorjoep
Date:
Wed Jun 20 11:21:31 2018 +0000
Revision:
1:24714b45cd1b
The newest version of the CMSIS library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xorjoep 1:24714b45cd1b 1 /* ----------------------------------------------------------------------
xorjoep 1:24714b45cd1b 2 * Project: CMSIS DSP Library
xorjoep 1:24714b45cd1b 3 * Title: arm_negate_q7.c
xorjoep 1:24714b45cd1b 4 * Description: Negates Q7 vectors
xorjoep 1:24714b45cd1b 5 *
xorjoep 1:24714b45cd1b 6 * $Date: 27. January 2017
xorjoep 1:24714b45cd1b 7 * $Revision: V.1.5.1
xorjoep 1:24714b45cd1b 8 *
xorjoep 1:24714b45cd1b 9 * Target Processor: Cortex-M cores
xorjoep 1:24714b45cd1b 10 * -------------------------------------------------------------------- */
xorjoep 1:24714b45cd1b 11 /*
xorjoep 1:24714b45cd1b 12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
xorjoep 1:24714b45cd1b 13 *
xorjoep 1:24714b45cd1b 14 * SPDX-License-Identifier: Apache-2.0
xorjoep 1:24714b45cd1b 15 *
xorjoep 1:24714b45cd1b 16 * Licensed under the Apache License, Version 2.0 (the License); you may
xorjoep 1:24714b45cd1b 17 * not use this file except in compliance with the License.
xorjoep 1:24714b45cd1b 18 * You may obtain a copy of the License at
xorjoep 1:24714b45cd1b 19 *
xorjoep 1:24714b45cd1b 20 * www.apache.org/licenses/LICENSE-2.0
xorjoep 1:24714b45cd1b 21 *
xorjoep 1:24714b45cd1b 22 * Unless required by applicable law or agreed to in writing, software
xorjoep 1:24714b45cd1b 23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
xorjoep 1:24714b45cd1b 24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
xorjoep 1:24714b45cd1b 25 * See the License for the specific language governing permissions and
xorjoep 1:24714b45cd1b 26 * limitations under the License.
xorjoep 1:24714b45cd1b 27 */
xorjoep 1:24714b45cd1b 28
xorjoep 1:24714b45cd1b 29 #include "arm_math.h"
xorjoep 1:24714b45cd1b 30
xorjoep 1:24714b45cd1b 31 /**
xorjoep 1:24714b45cd1b 32 * @ingroup groupMath
xorjoep 1:24714b45cd1b 33 */
xorjoep 1:24714b45cd1b 34
xorjoep 1:24714b45cd1b 35 /**
xorjoep 1:24714b45cd1b 36 * @addtogroup negate
xorjoep 1:24714b45cd1b 37 * @{
xorjoep 1:24714b45cd1b 38 */
xorjoep 1:24714b45cd1b 39
xorjoep 1:24714b45cd1b 40 /**
xorjoep 1:24714b45cd1b 41 * @brief Negates the elements of a Q7 vector.
xorjoep 1:24714b45cd1b 42 * @param[in] *pSrc points to the input vector
xorjoep 1:24714b45cd1b 43 * @param[out] *pDst points to the output vector
xorjoep 1:24714b45cd1b 44 * @param[in] blockSize number of samples in the vector
xorjoep 1:24714b45cd1b 45 * @return none.
xorjoep 1:24714b45cd1b 46 *
xorjoep 1:24714b45cd1b 47 * <b>Scaling and Overflow Behavior:</b>
xorjoep 1:24714b45cd1b 48 * \par
xorjoep 1:24714b45cd1b 49 * The function uses saturating arithmetic.
xorjoep 1:24714b45cd1b 50 * The Q7 value -1 (0x80) will be saturated to the maximum allowable positive value 0x7F.
xorjoep 1:24714b45cd1b 51 */
xorjoep 1:24714b45cd1b 52
xorjoep 1:24714b45cd1b 53 void arm_negate_q7(
xorjoep 1:24714b45cd1b 54 q7_t * pSrc,
xorjoep 1:24714b45cd1b 55 q7_t * pDst,
xorjoep 1:24714b45cd1b 56 uint32_t blockSize)
xorjoep 1:24714b45cd1b 57 {
xorjoep 1:24714b45cd1b 58 uint32_t blkCnt; /* loop counter */
xorjoep 1:24714b45cd1b 59 q7_t in;
xorjoep 1:24714b45cd1b 60
xorjoep 1:24714b45cd1b 61 #if defined (ARM_MATH_DSP)
xorjoep 1:24714b45cd1b 62
xorjoep 1:24714b45cd1b 63 /* Run the below code for Cortex-M4 and Cortex-M3 */
xorjoep 1:24714b45cd1b 64 q31_t input; /* Input values1-4 */
xorjoep 1:24714b45cd1b 65 q31_t zero = 0x00000000;
xorjoep 1:24714b45cd1b 66
xorjoep 1:24714b45cd1b 67
xorjoep 1:24714b45cd1b 68 /*loop Unrolling */
xorjoep 1:24714b45cd1b 69 blkCnt = blockSize >> 2U;
xorjoep 1:24714b45cd1b 70
xorjoep 1:24714b45cd1b 71 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
xorjoep 1:24714b45cd1b 72 ** a second loop below computes the remaining 1 to 3 samples. */
xorjoep 1:24714b45cd1b 73 while (blkCnt > 0U)
xorjoep 1:24714b45cd1b 74 {
xorjoep 1:24714b45cd1b 75 /* C = -A */
xorjoep 1:24714b45cd1b 76 /* Read four inputs */
xorjoep 1:24714b45cd1b 77 input = *__SIMD32(pSrc)++;
xorjoep 1:24714b45cd1b 78
xorjoep 1:24714b45cd1b 79 /* Store the Negated results in the destination buffer in a single cycle by packing the results */
xorjoep 1:24714b45cd1b 80 *__SIMD32(pDst)++ = __QSUB8(zero, input);
xorjoep 1:24714b45cd1b 81
xorjoep 1:24714b45cd1b 82 /* Decrement the loop counter */
xorjoep 1:24714b45cd1b 83 blkCnt--;
xorjoep 1:24714b45cd1b 84 }
xorjoep 1:24714b45cd1b 85
xorjoep 1:24714b45cd1b 86 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
xorjoep 1:24714b45cd1b 87 ** No loop unrolling is used. */
xorjoep 1:24714b45cd1b 88 blkCnt = blockSize % 0x4U;
xorjoep 1:24714b45cd1b 89
xorjoep 1:24714b45cd1b 90 #else
xorjoep 1:24714b45cd1b 91
xorjoep 1:24714b45cd1b 92 /* Run the below code for Cortex-M0 */
xorjoep 1:24714b45cd1b 93
xorjoep 1:24714b45cd1b 94 /* Initialize blkCnt with number of samples */
xorjoep 1:24714b45cd1b 95 blkCnt = blockSize;
xorjoep 1:24714b45cd1b 96
xorjoep 1:24714b45cd1b 97 #endif /* #if defined (ARM_MATH_DSP) */
xorjoep 1:24714b45cd1b 98
xorjoep 1:24714b45cd1b 99 while (blkCnt > 0U)
xorjoep 1:24714b45cd1b 100 {
xorjoep 1:24714b45cd1b 101 /* C = -A */
xorjoep 1:24714b45cd1b 102 /* Negate and then store the results in the destination buffer. */ \
xorjoep 1:24714b45cd1b 103 in = *pSrc++;
xorjoep 1:24714b45cd1b 104 *pDst++ = (in == (q7_t) 0x80) ? 0x7f : -in;
xorjoep 1:24714b45cd1b 105
xorjoep 1:24714b45cd1b 106 /* Decrement the loop counter */
xorjoep 1:24714b45cd1b 107 blkCnt--;
xorjoep 1:24714b45cd1b 108 }
xorjoep 1:24714b45cd1b 109 }
xorjoep 1:24714b45cd1b 110
xorjoep 1:24714b45cd1b 111 /**
xorjoep 1:24714b45cd1b 112 * @} end of negate group
xorjoep 1:24714b45cd1b 113 */