• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_offset_f32.c
4  * Description:  Floating-point vector offset
5  *
6  * $Date:        23 April 2021
7  * $Revision:    V1.9.0
8  *
9  * Target Processor: Cortex-M and Cortex-A cores
10  * -------------------------------------------------------------------- */
11 /*
12  * Copyright (C) 2010-2021 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 "dsp/basic_math_functions.h"
30 
31 /**
32   @ingroup groupMath
33  */
34 
35 /**
36   @defgroup BasicOffset Vector Offset
37 
38   Adds a constant offset to each element of a vector.
39 
40   <pre>
41       pDst[n] = pSrc[n] + offset,   0 <= n < blockSize.
42   </pre>
43 
44   The functions support in-place computation allowing the source and
45   destination pointers to reference the same memory buffer.
46   There are separate functions for floating-point, Q7, Q15, and Q31 data types.
47  */
48 
49 /**
50   @addtogroup BasicOffset
51   @{
52  */
53 
54 /**
55   @brief         Adds a constant offset to a floating-point vector.
56   @param[in]     pSrc       points to the input vector
57   @param[in]     offset     is the offset to be added
58   @param[out]    pDst       points to the output vector
59   @param[in]     blockSize  number of samples in each vector
60   @return        none
61  */
62 
63 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
64 
65 #include "arm_helium_utils.h"
66 
arm_offset_f32(const float32_t * pSrc,float32_t offset,float32_t * pDst,uint32_t blockSize)67 void arm_offset_f32(
68   const float32_t * pSrc,
69         float32_t offset,
70         float32_t * pDst,
71         uint32_t blockSize)
72 {
73         uint32_t blkCnt;                               /* Loop counter */
74 
75     f32x4_t vec1;
76     f32x4_t res;
77 
78     /* Compute 4 outputs at a time */
79     blkCnt = blockSize >> 2U;
80     while (blkCnt > 0U)
81     {
82         /* C = A + offset */
83 
84         /* Add offset and then store the results in the destination buffer. */
85         vec1 = vld1q(pSrc);
86         res = vaddq(vec1,offset);
87         vst1q(pDst, res);
88 
89         /* Increment pointers */
90         pSrc += 4;
91         pDst += 4;
92 
93         /* Decrement the loop counter */
94         blkCnt--;
95     }
96 
97     /* Tail */
98     blkCnt = blockSize & 0x3;
99 
100     if (blkCnt > 0U)
101     {
102         mve_pred16_t p0 = vctp32q(blkCnt);
103         vec1 = vld1q((float32_t const *) pSrc);
104         vstrwq_p(pDst, vaddq(vec1, offset), p0);
105     }
106 
107 
108 }
109 
110 #else
arm_offset_f32(const float32_t * pSrc,float32_t offset,float32_t * pDst,uint32_t blockSize)111 void arm_offset_f32(
112   const float32_t * pSrc,
113         float32_t offset,
114         float32_t * pDst,
115         uint32_t blockSize)
116 {
117         uint32_t blkCnt;                               /* Loop counter */
118 
119 #if defined(ARM_MATH_NEON_EXPERIMENTAL) && !defined(ARM_MATH_AUTOVECTORIZE)
120     f32x4_t vec1;
121     f32x4_t res;
122 
123     /* Compute 4 outputs at a time */
124     blkCnt = blockSize >> 2U;
125 
126     while (blkCnt > 0U)
127     {
128         /* C = A + offset */
129 
130         /* Add offset and then store the results in the destination buffer. */
131         vec1 = vld1q_f32(pSrc);
132         res = vaddq_f32(vec1,vdupq_n_f32(offset));
133         vst1q_f32(pDst, res);
134 
135         /* Increment pointers */
136         pSrc += 4;
137         pDst += 4;
138 
139         /* Decrement the loop counter */
140         blkCnt--;
141     }
142 
143     /* Tail */
144     blkCnt = blockSize & 0x3;
145 
146 #else
147 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
148 
149   /* Loop unrolling: Compute 4 outputs at a time */
150   blkCnt = blockSize >> 2U;
151 
152   while (blkCnt > 0U)
153   {
154     /* C = A + offset */
155 
156     /* Add offset and store result in destination buffer. */
157     *pDst++ = (*pSrc++) + offset;
158 
159     *pDst++ = (*pSrc++) + offset;
160 
161     *pDst++ = (*pSrc++) + offset;
162 
163     *pDst++ = (*pSrc++) + offset;
164 
165     /* Decrement loop counter */
166     blkCnt--;
167   }
168 
169   /* Loop unrolling: Compute remaining outputs */
170   blkCnt = blockSize % 0x4U;
171 
172 #else
173 
174   /* Initialize blkCnt with number of samples */
175   blkCnt = blockSize;
176 
177 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
178 #endif /* #if defined(ARM_MATH_NEON_EXPERIMENTAL) */
179 
180   while (blkCnt > 0U)
181   {
182     /* C = A + offset */
183 
184     /* Add offset and store result in destination buffer. */
185     *pDst++ = (*pSrc++) + offset;
186 
187     /* Decrement loop counter */
188     blkCnt--;
189   }
190 
191 }
192 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
193 
194 /**
195   @} end of BasicOffset group
196  */
197