Subversion Repositories dashGPS

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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