1 /*
2 * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /******************************************************************************
18 * @file csi_simd.h
19 * @brief CSI Single Instruction Multiple Data (SIMD) Header File for GCC.
20 * @version V1.0
21 * @date 02. June 2017
22 ******************************************************************************/
23
24 #ifndef _CSI_SIMD_H_
25 #define _CSI_SIMD_H_
26
27 /**
28 \brief Halfword packing instruction. Combines bits[15:0] of val1 with bits[31:16]
29 of val2 levitated with the val3.
30 \details Combine a halfword from one register with a halfword from another register.
31 The second argument can be left-shifted before extraction of the halfword.
32 \param [in] val1 first 16-bit operands
33 \param [in] val2 second 16-bit operands
34 \param [in] val3 value for left-shifting val2. Value range [0..31].
35 \return the combination of halfwords.
36 \remark
37 res[15:0] = val1[15:0] \n
38 res[31:16] = val2[31:16] << val3
39 */
__PKHBT(uint32_t val1,uint32_t val2,uint32_t val3)40 __ALWAYS_INLINE uint32_t __PKHBT(uint32_t val1, uint32_t val2, uint32_t val3)
41 {
42 return ((((int32_t)(val1) << 0) & (int32_t)0x0000FFFF) | (((int32_t)(val2) << val3) & (int32_t)0xFFFF0000));
43 }
44
45 /**
46 \brief Halfword packing instruction. Combines bits[31:16] of val1 with bits[15:0]
47 of val2 right-shifted with the val3.
48 \details Combine a halfword from one register with a halfword from another register.
49 The second argument can be right-shifted before extraction of the halfword.
50 \param [in] val1 first 16-bit operands
51 \param [in] val2 second 16-bit operands
52 \param [in] val3 value for right-shifting val2. Value range [1..32].
53 \return the combination of halfwords.
54 \remark
55 res[15:0] = val2[15:0] >> val3 \n
56 res[31:16] = val1[31:16]
57 */
__PKHTB(uint32_t val1,uint32_t val2,uint32_t val3)58 __ALWAYS_INLINE uint32_t __PKHTB(uint32_t val1, uint32_t val2, uint32_t val3)
59 {
60 return ((((int32_t)(val1) << 0) & (int32_t)0xFFFF0000) | (((int32_t)(val2) >> val3) & (int32_t)0x0000FFFF));
61 }
62
63 /**
64 \brief Dual 16-bit signed saturate.
65 \details This function saturates a signed value.
66 \param [in] x two signed 16-bit values to be saturated.
67 \param [in] y bit position for saturation, an integral constant expression in the range 1 to 16.
68 \return the sum of the absolute differences of the following bytes, added to the accumulation value:\n
69 the signed saturation of the low halfword in val1, saturated to the bit position specified in
70 val2 and returned in the low halfword of the return value.\n
71 the signed saturation of the high halfword in val1, saturated to the bit position specified in
72 val2 and returned in the high halfword of the return value.
73 */
__SSAT16(int32_t x,const uint32_t y)74 __ALWAYS_INLINE uint32_t __SSAT16(int32_t x, const uint32_t y)
75 {
76 int32_t r = 0, s = 0;
77
78 r = __SSAT((((int32_t)x << 16) >> 16), y) & (int32_t)0x0000FFFF;
79 s = __SSAT((((int32_t)x) >> 16), y) & (int32_t)0x0000FFFF;
80
81 return ((uint32_t)((s << 16) | (r)));
82 }
83
84 /**
85 \brief Dual 16-bit unsigned saturate.
86 \details This function enables you to saturate two signed 16-bit values to a selected unsigned range.
87 \param [in] x two signed 16-bit values to be saturated.
88 \param [in] y bit position for saturation, an integral constant expression in the range 1 to 16.
89 \return the saturation of the two signed 16-bit values, as non-negative values:
90 the saturation of the low halfword in val1, saturated to the bit position specified in
91 val2 and returned in the low halfword of the return value.\n
92 the saturation of the high halfword in val1, saturated to the bit position specified in
93 val2 and returned in the high halfword of the return value.
94 */
__USAT16(uint32_t x,const uint32_t y)95 __ALWAYS_INLINE uint32_t __USAT16(uint32_t x, const uint32_t y)
96 {
97 int32_t r = 0, s = 0;
98
99 r = __IUSAT(((x << 16) >> 16), y) & 0x0000FFFF;
100 s = __IUSAT(((x) >> 16), y) & 0x0000FFFF;
101
102 return ((s << 16) | (r));
103 }
104
105 /**
106 \brief Quad 8-bit saturating addition.
107 \details This function enables you to perform four 8-bit integer additions,
108 saturating the results to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
109 \param [in] x first four 8-bit summands.
110 \param [in] y second four 8-bit summands.
111 \return the saturated addition of the first byte of each operand in the first byte of the return value.\n
112 the saturated addition of the second byte of each operand in the second byte of the return value.\n
113 the saturated addition of the third byte of each operand in the third byte of the return value.\n
114 the saturated addition of the fourth byte of each operand in the fourth byte of the return value.\n
115 The returned results are saturated to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
116 \remark
117 res[7:0] = val1[7:0] + val2[7:0] \n
118 res[15:8] = val1[15:8] + val2[15:8] \n
119 res[23:16] = val1[23:16] + val2[23:16] \n
120 res[31:24] = val1[31:24] + val2[31:24]
121 */
__QADD8(uint32_t x,uint32_t y)122 __ALWAYS_INLINE uint32_t __QADD8(uint32_t x, uint32_t y)
123 {
124 int32_t r, s, t, u;
125
126 r = __SSAT(((((int32_t)x << 24) >> 24) + (((int32_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF;
127 s = __SSAT(((((int32_t)x << 16) >> 24) + (((int32_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF;
128 t = __SSAT(((((int32_t)x << 8) >> 24) + (((int32_t)y << 8) >> 24)), 8) & (int32_t)0x000000FF;
129 u = __SSAT(((((int32_t)x) >> 24) + (((int32_t)y) >> 24)), 8) & (int32_t)0x000000FF;
130
131 return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
132 }
133
134 /**
135 \brief Quad 8-bit unsigned saturating addition.
136 \details This function enables you to perform four unsigned 8-bit integer additions,
137 saturating the results to the 8-bit unsigned integer range 0 < x < 2^8 - 1.
138 \param [in] x first four 8-bit summands.
139 \param [in] y second four 8-bit summands.
140 \return the saturated addition of the first byte of each operand in the first byte of the return value.\n
141 the saturated addition of the second byte of each operand in the second byte of the return value.\n
142 the saturated addition of the third byte of each operand in the third byte of the return value.\n
143 the saturated addition of the fourth byte of each operand in the fourth byte of the return value.\n
144 The returned results are saturated to the 8-bit signed integer range 0 <= x <= 2^8 - 1.
145 \remark
146 res[7:0] = val1[7:0] + val2[7:0] \n
147 res[15:8] = val1[15:8] + val2[15:8] \n
148 res[23:16] = val1[23:16] + val2[23:16] \n
149 res[31:24] = val1[31:24] + val2[31:24]
150 */
__UQADD8(uint32_t x,uint32_t y)151 __ALWAYS_INLINE uint32_t __UQADD8(uint32_t x, uint32_t y)
152 {
153 int32_t r, s, t, u;
154
155 r = __IUSAT((((x << 24) >> 24) + ((y << 24) >> 24)), 8) & 0x000000FF;
156 s = __IUSAT((((x << 16) >> 24) + ((y << 16) >> 24)), 8) & 0x000000FF;
157 t = __IUSAT((((x << 8) >> 24) + ((y << 8) >> 24)), 8) & 0x000000FF;
158 u = __IUSAT((((x) >> 24) + ((y) >> 24)), 8) & 0x000000FF;
159
160 return ((u << 24) | (t << 16) | (s << 8) | (r));
161 }
162
163 /**
164 \brief Quad 8-bit signed addition.
165 \details This function performs four 8-bit signed integer additions.
166 \param [in] x first four 8-bit summands.
167 \param [in] y second four 8-bit summands.
168 \return the addition of the first bytes from each operand, in the first byte of the return value.\n
169 the addition of the second bytes of each operand, in the second byte of the return value.\n
170 the addition of the third bytes of each operand, in the third byte of the return value.\n
171 the addition of the fourth bytes of each operand, in the fourth byte of the return value.
172 \remark
173 res[7:0] = val1[7:0] + val2[7:0] \n
174 res[15:8] = val1[15:8] + val2[15:8] \n
175 res[23:16] = val1[23:16] + val2[23:16] \n
176 res[31:24] = val1[31:24] + val2[31:24]
177 */
__SADD8(uint32_t x,uint32_t y)178 __ALWAYS_INLINE uint32_t __SADD8(uint32_t x, uint32_t y)
179 {
180 int32_t r, s, t, u;
181
182 r = ((((int32_t)x << 24) >> 24) + (((int32_t)y << 24) >> 24)) & (int32_t)0x000000FF;
183 s = ((((int32_t)x << 16) >> 24) + (((int32_t)y << 16) >> 24)) & (int32_t)0x000000FF;
184 t = ((((int32_t)x << 8) >> 24) + (((int32_t)y << 8) >> 24)) & (int32_t)0x000000FF;
185 u = ((((int32_t)x) >> 24) + (((int32_t)y) >> 24)) & (int32_t)0x000000FF;
186
187 return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
188 }
189
190 /**
191 \brief Quad 8-bit unsigned addition.
192 \details This function performs four unsigned 8-bit integer additions.
193 \param [in] x first four 8-bit summands.
194 \param [in] y second four 8-bit summands.
195 \return the addition of the first bytes from each operand, in the first byte of the return value.\n
196 the addition of the second bytes of each operand, in the second byte of the return value.\n
197 the addition of the third bytes of each operand, in the third byte of the return value.\n
198 the addition of the fourth bytes of each operand, in the fourth byte of the return value.
199 \remark
200 res[7:0] = val1[7:0] + val2[7:0] \n
201 res[15:8] = val1[15:8] + val2[15:8] \n
202 res[23:16] = val1[23:16] + val2[23:16] \n
203 res[31:24] = val1[31:24] + val2[31:24]
204 */
__UADD8(uint32_t x,uint32_t y)205 __ALWAYS_INLINE uint32_t __UADD8(uint32_t x, uint32_t y)
206 {
207 int32_t r, s, t, u;
208
209 r = (((x << 24) >> 24) + ((y << 24) >> 24)) & 0x000000FF;
210 s = (((x << 16) >> 24) + ((y << 16) >> 24)) & 0x000000FF;
211 t = (((x << 8) >> 24) + ((y << 8) >> 24)) & 0x000000FF;
212 u = (((x) >> 24) + ((y) >> 24)) & 0x000000FF;
213
214 return ((u << 24) | (t << 16) | (s << 8) | (r));
215 }
216
217 /**
218 \brief Quad 8-bit saturating subtract.
219 \details This function enables you to perform four 8-bit integer subtractions,
220 saturating the results to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
221 \param [in] x first four 8-bit summands.
222 \param [in] y second four 8-bit summands.
223 \return the subtraction of the first byte of each operand in the first byte of the return value.\n
224 the subtraction of the second byte of each operand in the second byte of the return value.\n
225 the subtraction of the third byte of each operand in the third byte of the return value.\n
226 the subtraction of the fourth byte of each operand in the fourth byte of the return value.\n
227 The returned results are saturated to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
228 \remark
229 res[7:0] = val1[7:0] - val2[7:0] \n
230 res[15:8] = val1[15:8] - val2[15:8] \n
231 res[23:16] = val1[23:16] - val2[23:16] \n
232 res[31:24] = val1[31:24] - val2[31:24]
233 */
__QSUB8(uint32_t x,uint32_t y)234 __ALWAYS_INLINE uint32_t __QSUB8(uint32_t x, uint32_t y)
235 {
236 int32_t r, s, t, u;
237
238 r = __SSAT(((((int32_t)x << 24) >> 24) - (((int32_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF;
239 s = __SSAT(((((int32_t)x << 16) >> 24) - (((int32_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF;
240 t = __SSAT(((((int32_t)x << 8) >> 24) - (((int32_t)y << 8) >> 24)), 8) & (int32_t)0x000000FF;
241 u = __SSAT(((((int32_t)x) >> 24) - (((int32_t)y) >> 24)), 8) & (int32_t)0x000000FF;
242
243 return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
244 }
245
246 /**
247 \brief Quad 8-bit unsigned saturating subtraction.
248 \details This function enables you to perform four unsigned 8-bit integer subtractions,
249 saturating the results to the 8-bit unsigned integer range 0 < x < 2^8 - 1.
250 \param [in] x first four 8-bit summands.
251 \param [in] y second four 8-bit summands.
252 \return the subtraction of the first byte of each operand in the first byte of the return value.\n
253 the subtraction of the second byte of each operand in the second byte of the return value.\n
254 the subtraction of the third byte of each operand in the third byte of the return value.\n
255 the subtraction of the fourth byte of each operand in the fourth byte of the return value.\n
256 The returned results are saturated to the 8-bit unsigned integer range 0 <= x <= 2^8 - 1.
257 \remark
258 res[7:0] = val1[7:0] - val2[7:0] \n
259 res[15:8] = val1[15:8] - val2[15:8] \n
260 res[23:16] = val1[23:16] - val2[23:16] \n
261 res[31:24] = val1[31:24] - val2[31:24]
262 */
__UQSUB8(uint32_t x,uint32_t y)263 __ALWAYS_INLINE uint32_t __UQSUB8(uint32_t x, uint32_t y)
264 {
265 int32_t r, s, t, u;
266
267 r = __IUSAT((((x << 24) >> 24) - ((y << 24) >> 24)), 8) & 0x000000FF;
268 s = __IUSAT((((x << 16) >> 24) - ((y << 16) >> 24)), 8) & 0x000000FF;
269 t = __IUSAT((((x << 8) >> 24) - ((y << 8) >> 24)), 8) & 0x000000FF;
270 u = __IUSAT((((x) >> 24) - ((y) >> 24)), 8) & 0x000000FF;
271
272 return ((u << 24) | (t << 16) | (s << 8) | (r));
273 }
274
275 /**
276 \brief Quad 8-bit signed subtraction.
277 \details This function enables you to perform four 8-bit signed integer subtractions.
278 \param [in] x first four 8-bit operands of each subtraction.
279 \param [in] y second four 8-bit operands of each subtraction.
280 \return the subtraction of the first bytes from each operand, in the first byte of the return value.\n
281 the subtraction of the second bytes of each operand, in the second byte of the return value.\n
282 the subtraction of the third bytes of each operand, in the third byte of the return value.\n
283 the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.
284 \remark
285 res[7:0] = val1[7:0] - val2[7:0] \n
286 res[15:8] = val1[15:8] - val2[15:8] \n
287 res[23:16] = val1[23:16] - val2[23:16] \n
288 res[31:24] = val1[31:24] - val2[31:24]
289 */
__SSUB8(uint32_t x,uint32_t y)290 __ALWAYS_INLINE uint32_t __SSUB8(uint32_t x, uint32_t y)
291 {
292 int32_t r, s, t, u;
293
294 r = ((((int32_t)x << 24) >> 24) - (((int32_t)y << 24) >> 24)) & (int32_t)0x000000FF;
295 s = ((((int32_t)x << 16) >> 24) - (((int32_t)y << 16) >> 24)) & (int32_t)0x000000FF;
296 t = ((((int32_t)x << 8) >> 24) - (((int32_t)y << 8) >> 24)) & (int32_t)0x000000FF;
297 u = ((((int32_t)x) >> 24) - (((int32_t)y) >> 24)) & (int32_t)0x000000FF;
298
299 return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
300 }
301
302 /**
303 \brief Quad 8-bit unsigned subtract.
304 \details This function enables you to perform four 8-bit unsigned integer subtractions.
305 \param [in] x first four 8-bit operands of each subtraction.
306 \param [in] y second four 8-bit operands of each subtraction.
307 \return the subtraction of the first bytes from each operand, in the first byte of the return value.\n
308 the subtraction of the second bytes of each operand, in the second byte of the return value.\n
309 the subtraction of the third bytes of each operand, in the third byte of the return value.\n
310 the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.
311 \remark
312 res[7:0] = val1[7:0] - val2[7:0] \n
313 res[15:8] = val1[15:8] - val2[15:8] \n
314 res[23:16] = val1[23:16] - val2[23:16] \n
315 res[31:24] = val1[31:24] - val2[31:24]
316 */
__USUB8(uint32_t x,uint32_t y)317 __ALWAYS_INLINE uint32_t __USUB8(uint32_t x, uint32_t y)
318 {
319 int32_t r, s, t, u;
320
321 r = (((x << 24) >> 24) - ((y << 24) >> 24)) & 0x000000FF;
322 s = (((x << 16) >> 24) - ((y << 16) >> 24)) & 0x000000FF;
323 t = (((x << 8) >> 24) - ((y << 8) >> 24)) & 0x000000FF;
324 u = (((x) >> 24) - ((y) >> 24)) & 0x000000FF;
325
326 return ((u << 24) | (t << 16) | (s << 8) | (r));
327 }
328
329 /**
330 \brief Unsigned sum of quad 8-bit unsigned absolute difference.
331 \details This function enables you to perform four unsigned 8-bit subtractions, and add the absolute values
332 of the differences together, returning the result as a single unsigned integer.
333 \param [in] x first four 8-bit operands of each subtraction.
334 \param [in] y second four 8-bit operands of each subtraction.
335 \return the subtraction of the first bytes from each operand, in the first byte of the return value.\n
336 the subtraction of the second bytes of each operand, in the second byte of the return value.\n
337 the subtraction of the third bytes of each operand, in the third byte of the return value.\n
338 the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.\n
339 The sum is returned as a single unsigned integer.
340 \remark
341 absdiff1 = val1[7:0] - val2[7:0] \n
342 absdiff2 = val1[15:8] - val2[15:8] \n
343 absdiff3 = val1[23:16] - val2[23:16] \n
344 absdiff4 = val1[31:24] - val2[31:24] \n
345 res[31:0] = absdiff1 + absdiff2 + absdiff3 + absdiff4
346 */
__USAD8(uint32_t x,uint32_t y)347 __ALWAYS_INLINE uint32_t __USAD8(uint32_t x, uint32_t y)
348 {
349 int32_t r, s, t, u;
350
351 r = (((x << 24) >> 24) - ((y << 24) >> 24)) & 0x000000FF;
352 s = (((x << 16) >> 24) - ((y << 16) >> 24)) & 0x000000FF;
353 t = (((x << 8) >> 24) - ((y << 8) >> 24)) & 0x000000FF;
354 u = (((x) >> 24) - ((y) >> 24)) & 0x000000FF;
355
356 return (u + t + s + r);
357 }
358
359 /**
360 \brief Unsigned sum of quad 8-bit unsigned absolute difference with 32-bit accumulate.
361 \details This function enables you to perform four unsigned 8-bit subtractions, and add the absolute values
362 of the differences to a 32-bit accumulate operand.
363 \param [in] x first four 8-bit operands of each subtraction.
364 \param [in] y second four 8-bit operands of each subtraction.
365 \param [in] sum accumulation value.
366 \return the sum of the absolute differences of the following bytes, added to the accumulation value:
367 the subtraction of the first bytes from each operand, in the first byte of the return value.\n
368 the subtraction of the second bytes of each operand, in the second byte of the return value.\n
369 the subtraction of the third bytes of each operand, in the third byte of the return value.\n
370 the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.
371 \remark
372 absdiff1 = val1[7:0] - val2[7:0] \n
373 absdiff2 = val1[15:8] - val2[15:8] \n
374 absdiff3 = val1[23:16] - val2[23:16] \n
375 absdiff4 = val1[31:24] - val2[31:24] \n
376 sum = absdiff1 + absdiff2 + absdiff3 + absdiff4 \n
377 res[31:0] = sum[31:0] + val3[31:0]
378 */
__USADA8(uint32_t x,uint32_t y,uint32_t sum)379 __ALWAYS_INLINE uint32_t __USADA8(uint32_t x, uint32_t y, uint32_t sum)
380 {
381 int32_t r, s, t, u;
382
383 r = (abs(((x << 24) >> 24) - ((y << 24) >> 24))) & 0x000000FF;
384 s = (abs(((x << 16) >> 24) - ((y << 16) >> 24))) & 0x000000FF;
385 t = (abs(((x << 8) >> 24) - ((y << 8) >> 24))) & 0x000000FF;
386 u = (abs(((x) >> 24) - ((y) >> 24))) & 0x000000FF;
387
388 return (u + t + s + r + sum);
389 }
390
391 /**
392 \brief Dual 16-bit saturating addition.
393 \details This function enables you to perform two 16-bit integer arithmetic additions in parallel,
394 saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
395 \param [in] x first two 16-bit summands.
396 \param [in] y second two 16-bit summands.
397 \return the saturated addition of the low halfwords, in the low halfword of the return value.\n
398 the saturated addition of the high halfwords, in the high halfword of the return value.\n
399 The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
400 \remark
401 res[15:0] = val1[15:0] + val2[15:0] \n
402 res[31:16] = val1[31:16] + val2[31:16]
403 */
__QADD16(uint32_t x,uint32_t y)404 __ALWAYS_INLINE uint32_t __QADD16(uint32_t x, uint32_t y)
405 {
406 int32_t r = 0, s = 0;
407
408 r = __SSAT(((((int32_t)x << 16) >> 16) + (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
409 s = __SSAT(((((int32_t)x) >> 16) + (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
410
411 return ((uint32_t)((s << 16) | (r)));
412 }
413
414 /**
415 \brief Dual 16-bit unsigned saturating addition.
416 \details This function enables you to perform two unsigned 16-bit integer additions, saturating
417 the results to the 16-bit unsigned integer range 0 < x < 2^16 - 1.
418 \param [in] x first two 16-bit summands.
419 \param [in] y second two 16-bit summands.
420 \return the saturated addition of the low halfwords, in the low halfword of the return value.\n
421 the saturated addition of the high halfwords, in the high halfword of the return value.\n
422 The results are saturated to the 16-bit unsigned integer range 0 < x < 2^16 - 1.
423 \remark
424 res[15:0] = val1[15:0] + val2[15:0] \n
425 res[31:16] = val1[31:16] + val2[31:16]
426 */
__UQADD16(uint32_t x,uint32_t y)427 __ALWAYS_INLINE uint32_t __UQADD16(uint32_t x, uint32_t y)
428 {
429 int32_t r = 0, s = 0;
430
431 r = __IUSAT((((x << 16) >> 16) + ((y << 16) >> 16)), 16) & 0x0000FFFF;
432 s = __IUSAT((((x) >> 16) + ((y) >> 16)), 16) & 0x0000FFFF;
433
434 return ((s << 16) | (r));
435 }
436
437 /**
438 \brief Dual 16-bit signed addition.
439 \details This function enables you to perform two 16-bit signed integer additions.
440 \param [in] x first two 16-bit summands.
441 \param [in] y second two 16-bit summands.
442 \return the addition of the low halfwords in the low halfword of the return value.\n
443 the addition of the high halfwords in the high halfword of the return value.
444 \remark
445 res[15:0] = val1[15:0] + val2[15:0] \n
446 res[31:16] = val1[31:16] + val2[31:16]
447 */
__SADD16(uint32_t x,uint32_t y)448 __ALWAYS_INLINE uint32_t __SADD16(uint32_t x, uint32_t y)
449 {
450 int32_t r = 0, s = 0;
451
452 r = ((((int32_t)x << 16) >> 16) + (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
453 s = ((((int32_t)x) >> 16) + (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
454
455 return ((uint32_t)((s << 16) | (r)));
456 }
457
458 /**
459 \brief Dual 16-bit unsigned addition
460 \details This function enables you to perform two 16-bit unsigned integer additions.
461 \param [in] x first two 16-bit summands for each addition.
462 \param [in] y second two 16-bit summands for each addition.
463 \return the addition of the low halfwords in the low halfword of the return value.\n
464 the addition of the high halfwords in the high halfword of the return value.
465 \remark
466 res[15:0] = val1[15:0] + val2[15:0] \n
467 res[31:16] = val1[31:16] + val2[31:16]
468 */
__UADD16(uint32_t x,uint32_t y)469 __ALWAYS_INLINE uint32_t __UADD16(uint32_t x, uint32_t y)
470 {
471 int32_t r = 0, s = 0;
472
473 r = (((x << 16) >> 16) + ((y << 16) >> 16)) & 0x0000FFFF;
474 s = (((x) >> 16) + ((y) >> 16)) & 0x0000FFFF;
475
476 return ((s << 16) | (r));
477 }
478
479
480 /**
481 \brief Dual 16-bit signed addition with halved results.
482 \details This function enables you to perform two signed 16-bit integer additions, halving the results.
483 \param [in] x first two 16-bit summands.
484 \param [in] y second two 16-bit summands.
485 \return the halved addition of the low halfwords, in the low halfword of the return value.\n
486 the halved addition of the high halfwords, in the high halfword of the return value.
487 \remark
488 res[15:0] = (val1[15:0] + val2[15:0]) >> 1 \n
489 res[31:16] = (val1[31:16] + val2[31:16]) >> 1
490 */
__SHADD16(uint32_t x,uint32_t y)491 __ALWAYS_INLINE uint32_t __SHADD16(uint32_t x, uint32_t y)
492 {
493 int32_t r, s;
494
495 r = (((((int32_t)x << 16) >> 16) + (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
496 s = (((((int32_t)x) >> 16) + (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
497
498 return ((uint32_t)((s << 16) | (r)));
499 }
500
501 /**
502 \brief Dual 16-bit unsigned addition with halved results.
503 \details This function enables you to perform two unsigned 16-bit integer additions, halving the results.
504 \param [in] x first two 16-bit summands.
505 \param [in] y second two 16-bit summands.
506 \return the halved addition of the low halfwords, in the low halfword of the return value.\n
507 the halved addition of the high halfwords, in the high halfword of the return value.
508 \remark
509 res[15:0] = (val1[15:0] + val2[15:0]) >> 1 \n
510 res[31:16] = (val1[31:16] + val2[31:16]) >> 1
511 */
__UHADD16(uint32_t x,uint32_t y)512 __ALWAYS_INLINE uint32_t __UHADD16(uint32_t x, uint32_t y)
513 {
514 int32_t r, s;
515
516 r = ((((x << 16) >> 16) + ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
517 s = ((((x) >> 16) + ((y) >> 16)) >> 1) & 0x0000FFFF;
518
519 return ((s << 16) | (r));
520 }
521
522 /**
523 \brief Quad 8-bit signed addition with halved results.
524 \details This function enables you to perform four signed 8-bit integer additions, halving the results.
525 \param [in] x first four 8-bit summands.
526 \param [in] y second four 8-bit summands.
527 \return the halved addition of the first bytes from each operand, in the first byte of the return value.\n
528 the halved addition of the second bytes from each operand, in the second byte of the return value.\n
529 the halved addition of the third bytes from each operand, in the third byte of the return value.\n
530 the halved addition of the fourth bytes from each operand, in the fourth byte of the return value.
531 \remark
532 res[7:0] = (val1[7:0] + val2[7:0] ) >> 1 \n
533 res[15:8] = (val1[15:8] + val2[15:8] ) >> 1 \n
534 res[23:16] = (val1[23:16] + val2[23:16]) >> 1 \n
535 res[31:24] = (val1[31:24] + val2[31:24]) >> 1
536 */
__SHADD8(uint32_t x,uint32_t y)537 __ALWAYS_INLINE uint32_t __SHADD8(uint32_t x, uint32_t y)
538 {
539 int32_t r, s, t, u;
540
541 r = (((((int32_t)x << 24) >> 24) + (((int32_t)y << 24) >> 24)) >> 1) & (int32_t)0x000000FF;
542 s = (((((int32_t)x << 16) >> 24) + (((int32_t)y << 16) >> 24)) >> 1) & (int32_t)0x000000FF;
543 t = (((((int32_t)x << 8) >> 24) + (((int32_t)y << 8) >> 24)) >> 1) & (int32_t)0x000000FF;
544 u = (((((int32_t)x) >> 24) + (((int32_t)y) >> 24)) >> 1) & (int32_t)0x000000FF;
545
546 return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
547 }
548
549 /**
550 \brief Quad 8-bit unsigned addition with halved results.
551 \details This function enables you to perform four unsigned 8-bit integer additions, halving the results.
552 \param [in] x first four 8-bit summands.
553 \param [in] y second four 8-bit summands.
554 \return the halved addition of the first bytes from each operand, in the first byte of the return value.\n
555 the halved addition of the second bytes from each operand, in the second byte of the return value.\n
556 the halved addition of the third bytes from each operand, in the third byte of the return value.\n
557 the halved addition of the fourth bytes from each operand, in the fourth byte of the return value.
558 \remark
559 res[7:0] = (val1[7:0] + val2[7:0] ) >> 1 \n
560 res[15:8] = (val1[15:8] + val2[15:8] ) >> 1 \n
561 res[23:16] = (val1[23:16] + val2[23:16]) >> 1 \n
562 res[31:24] = (val1[31:24] + val2[31:24]) >> 1
563 */
__UHADD8(uint32_t x,uint32_t y)564 __ALWAYS_INLINE uint32_t __UHADD8(uint32_t x, uint32_t y)
565 {
566 int32_t r, s, t, u;
567
568 r = ((((x << 24) >> 24) + ((y << 24) >> 24)) >> 1) & 0x000000FF;
569 s = ((((x << 16) >> 24) + ((y << 16) >> 24)) >> 1) & 0x000000FF;
570 t = ((((x << 8) >> 24) + ((y << 8) >> 24)) >> 1) & 0x000000FF;
571 u = ((((x) >> 24) + ((y) >> 24)) >> 1) & 0x000000FF;
572
573 return ((u << 24) | (t << 16) | (s << 8) | (r));
574 }
575
576 /**
577 \brief Dual 16-bit saturating subtract.
578 \details This function enables you to perform two 16-bit integer subtractions in parallel,
579 saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
580 \param [in] x first two 16-bit summands.
581 \param [in] y second two 16-bit summands.
582 \return the saturated subtraction of the low halfwords, in the low halfword of the return value.\n
583 the saturated subtraction of the high halfwords, in the high halfword of the return value.\n
584 The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
585 \remark
586 res[15:0] = val1[15:0] - val2[15:0] \n
587 res[31:16] = val1[31:16] - val2[31:16]
588 */
__QSUB16(uint32_t x,uint32_t y)589 __ALWAYS_INLINE uint32_t __QSUB16(uint32_t x, uint32_t y)
590 {
591 int32_t r, s;
592
593 r = __SSAT(((((int32_t)x << 16) >> 16) - (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
594 s = __SSAT(((((int32_t)x) >> 16) - (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
595
596 return ((uint32_t)((s << 16) | (r)));
597 }
598
599 /**
600 \brief Dual 16-bit unsigned saturating subtraction.
601 \details This function enables you to perform two unsigned 16-bit integer subtractions,
602 saturating the results to the 16-bit unsigned integer range 0 < x < 2^16 - 1.
603 \param [in] x first two 16-bit operands for each subtraction.
604 \param [in] y second two 16-bit operands for each subtraction.
605 \return the saturated subtraction of the low halfwords, in the low halfword of the return value.\n
606 the saturated subtraction of the high halfwords, in the high halfword of the return value.\n
607 The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
608 \remark
609 res[15:0] = val1[15:0] - val2[15:0] \n
610 res[31:16] = val1[31:16] - val2[31:16]
611 */
__UQSUB16(uint32_t x,uint32_t y)612 __ALWAYS_INLINE uint32_t __UQSUB16(uint32_t x, uint32_t y)
613 {
614 int32_t r, s;
615
616 r = __IUSAT((((x << 16) >> 16) - ((y << 16) >> 16)), 16) & 0x0000FFFF;
617 s = __IUSAT((((x) >> 16) - ((y) >> 16)), 16) & 0x0000FFFF;
618
619 return ((s << 16) | (r));
620 }
621
622 /**
623 \brief Dual 16-bit signed subtraction.
624 \details This function enables you to perform two 16-bit signed integer subtractions.
625 \param [in] x first two 16-bit operands of each subtraction.
626 \param [in] y second two 16-bit operands of each subtraction.
627 \return the subtraction of the low halfword in the second operand from the low
628 halfword in the first operand, in the low halfword of the return value. \n
629 the subtraction of the high halfword in the second operand from the high
630 halfword in the first operand, in the high halfword of the return value.
631 \remark
632 res[15:0] = val1[15:0] - val2[15:0] \n
633 res[31:16] = val1[31:16] - val2[31:16]
634 */
__SSUB16(uint32_t x,uint32_t y)635 __ALWAYS_INLINE uint32_t __SSUB16(uint32_t x, uint32_t y)
636 {
637 int32_t r, s;
638
639 r = ((((int32_t)x << 16) >> 16) - (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
640 s = ((((int32_t)x) >> 16) - (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
641
642 return ((uint32_t)((s << 16) | (r)));
643 }
644
645 /**
646 \brief Dual 16-bit unsigned subtract.
647 \details This function enables you to perform two 16-bit unsigned integer subtractions.
648 \param [in] x first two 16-bit operands of each subtraction.
649 \param [in] y second two 16-bit operands of each subtraction.
650 \return the subtraction of the low halfword in the second operand from the low
651 halfword in the first operand, in the low halfword of the return value. \n
652 the subtraction of the high halfword in the second operand from the high
653 halfword in the first operand, in the high halfword of the return value.
654 \remark
655 res[15:0] = val1[15:0] - val2[15:0] \n
656 res[31:16] = val1[31:16] - val2[31:16]
657 */
__USUB16(uint32_t x,uint32_t y)658 __ALWAYS_INLINE uint32_t __USUB16(uint32_t x, uint32_t y)
659 {
660 int32_t r, s;
661
662 r = (((x << 16) >> 16) - ((y << 16) >> 16)) & 0x0000FFFF;
663 s = (((x) >> 16) - ((y) >> 16)) & 0x0000FFFF;
664
665 return ((s << 16) | (r));
666 }
667
668 /**
669 \brief Dual 16-bit signed subtraction with halved results.
670 \details This function enables you to perform two signed 16-bit integer subtractions, halving the results.
671 \param [in] x first two 16-bit summands.
672 \param [in] y second two 16-bit summands.
673 \return the halved subtraction of the low halfwords, in the low halfword of the return value.\n
674 the halved subtraction of the high halfwords, in the high halfword of the return value.
675 \remark
676 res[15:0] = (val1[15:0] - val2[15:0]) >> 1 \n
677 res[31:16] = (val1[31:16] - val2[31:16]) >> 1
678 */
__SHSUB16(uint32_t x,uint32_t y)679 __ALWAYS_INLINE uint32_t __SHSUB16(uint32_t x, uint32_t y)
680 {
681 int32_t r, s;
682
683 r = (((((int32_t)x << 16) >> 16) - (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
684 s = (((((int32_t)x) >> 16) - (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
685
686 return ((uint32_t)((s << 16) | (r)));
687 }
688
689 /**
690 \brief Dual 16-bit unsigned subtraction with halved results.
691 \details This function enables you to perform two unsigned 16-bit integer subtractions, halving the results.
692 \param [in] x first two 16-bit summands.
693 \param [in] y second two 16-bit summands.
694 \return the halved subtraction of the low halfwords, in the low halfword of the return value.\n
695 the halved subtraction of the high halfwords, in the high halfword of the return value.
696 \remark
697 res[15:0] = (val1[15:0] - val2[15:0]) >> 1 \n
698 res[31:16] = (val1[31:16] - val2[31:16]) >> 1
699 */
__UHSUB16(uint32_t x,uint32_t y)700 __ALWAYS_INLINE uint32_t __UHSUB16(uint32_t x, uint32_t y)
701 {
702 int32_t r, s;
703
704 r = ((((x << 16) >> 16) - ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
705 s = ((((x) >> 16) - ((y) >> 16)) >> 1) & 0x0000FFFF;
706
707 return ((s << 16) | (r));
708 }
709
710 /**
711 \brief Quad 8-bit signed addition with halved results.
712 \details This function enables you to perform four signed 8-bit integer subtractions, halving the results.
713 \param [in] x first four 8-bit summands.
714 \param [in] y second four 8-bit summands.
715 \return the halved subtraction of the first bytes from each operand, in the first byte of the return value.\n
716 the halved subtraction of the second bytes from each operand, in the second byte of the return value.\n
717 the halved subtraction of the third bytes from each operand, in the third byte of the return value.\n
718 the halved subtraction of the fourth bytes from each operand, in the fourth byte of the return value.
719 \remark
720 res[7:0] = (val1[7:0] - val2[7:0] ) >> 1 \n
721 res[15:8] = (val1[15:8] - val2[15:8] ) >> 1 \n
722 res[23:16] = (val1[23:16] - val2[23:16]) >> 1 \n
723 res[31:24] = (val1[31:24] - val2[31:24]) >> 1
724 */
__SHSUB8(uint32_t x,uint32_t y)725 __ALWAYS_INLINE uint32_t __SHSUB8(uint32_t x, uint32_t y)
726 {
727 int32_t r, s, t, u;
728
729 r = (((((int32_t)x << 24) >> 24) - (((int32_t)y << 24) >> 24)) >> 1) & (int32_t)0x000000FF;
730 s = (((((int32_t)x << 16) >> 24) - (((int32_t)y << 16) >> 24)) >> 1) & (int32_t)0x000000FF;
731 t = (((((int32_t)x << 8) >> 24) - (((int32_t)y << 8) >> 24)) >> 1) & (int32_t)0x000000FF;
732 u = (((((int32_t)x) >> 24) - (((int32_t)y) >> 24)) >> 1) & (int32_t)0x000000FF;
733
734 return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
735 }
736
737 /**
738 \brief Quad 8-bit unsigned subtraction with halved results.
739 \details This function enables you to perform four unsigned 8-bit integer subtractions, halving the results.
740 \param [in] x first four 8-bit summands.
741 \param [in] y second four 8-bit summands.
742 \return the halved subtraction of the first bytes from each operand, in the first byte of the return value.\n
743 the halved subtraction of the second bytes from each operand, in the second byte of the return value.\n
744 the halved subtraction of the third bytes from each operand, in the third byte of the return value.\n
745 the halved subtraction of the fourth bytes from each operand, in the fourth byte of the return value.
746 \remark
747 res[7:0] = (val1[7:0] - val2[7:0] ) >> 1 \n
748 res[15:8] = (val1[15:8] - val2[15:8] ) >> 1 \n
749 res[23:16] = (val1[23:16] - val2[23:16]) >> 1 \n
750 res[31:24] = (val1[31:24] - val2[31:24]) >> 1
751 */
__UHSUB8(uint32_t x,uint32_t y)752 __ALWAYS_INLINE uint32_t __UHSUB8(uint32_t x, uint32_t y)
753 {
754 int32_t r, s, t, u;
755
756 r = ((((x << 24) >> 24) - ((y << 24) >> 24)) >> 1) & 0x000000FF;
757 s = ((((x << 16) >> 24) - ((y << 16) >> 24)) >> 1) & 0x000000FF;
758 t = ((((x << 8) >> 24) - ((y << 8) >> 24)) >> 1) & 0x000000FF;
759 u = ((((x) >> 24) - ((y) >> 24)) >> 1) & 0x000000FF;
760
761 return ((u << 24) | (t << 16) | (s << 8) | (r));
762 }
763
764 /**
765 \brief Dual 16-bit add and subtract with exchange.
766 \details This function enables you to exchange the halfwords of the one operand,
767 then add the high halfwords and subtract the low halfwords,
768 saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
769 \param [in] x first operand for the subtraction in the low halfword,
770 and the first operand for the addition in the high halfword.
771 \param [in] y second operand for the subtraction in the high halfword,
772 and the second operand for the addition in the low halfword.
773 \return the saturated subtraction of the high halfword in the second operand from the
774 low halfword in the first operand, in the low halfword of the return value.\n
775 the saturated addition of the high halfword in the first operand and the
776 low halfword in the second operand, in the high halfword of the return value.\n
777 The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
778 \remark
779 res[15:0] = val1[15:0] - val2[31:16] \n
780 res[31:16] = val1[31:16] + val2[15:0]
781 */
__QASX(uint32_t x,uint32_t y)782 __ALWAYS_INLINE uint32_t __QASX(uint32_t x, uint32_t y)
783 {
784 int32_t r, s;
785
786 r = __SSAT(((((int32_t)x << 16) >> 16) - (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
787 s = __SSAT(((((int32_t)x) >> 16) + (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
788
789 return ((uint32_t)((s << 16) | (r)));
790 }
791
792 /**
793 \brief Dual 16-bit unsigned saturating addition and subtraction with exchange.
794 \details This function enables you to exchange the halfwords of the second operand and
795 perform one unsigned 16-bit integer addition and one unsigned 16-bit subtraction,
796 saturating the results to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
797 \param [in] x first operand for the subtraction in the low halfword,
798 and the first operand for the addition in the high halfword.
799 \param [in] y second operand for the subtraction in the high halfword,
800 and the second operand for the addition in the low halfword.
801 \return the saturated subtraction of the high halfword in the second operand from the
802 low halfword in the first operand, in the low halfword of the return value.\n
803 the saturated addition of the high halfword in the first operand and the
804 low halfword in the second operand, in the high halfword of the return value.\n
805 The returned results are saturated to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
806 \remark
807 res[15:0] = val1[15:0] - val2[31:16] \n
808 res[31:16] = val1[31:16] + val2[15:0]
809 */
__UQASX(uint32_t x,uint32_t y)810 __ALWAYS_INLINE uint32_t __UQASX(uint32_t x, uint32_t y)
811 {
812 int32_t r, s;
813
814 r = __IUSAT((((x << 16) >> 16) - ((y) >> 16)), 16) & 0x0000FFFF;
815 s = __IUSAT((((x) >> 16) + ((y << 16) >> 16)), 16) & 0x0000FFFF;
816
817 return ((s << 16) | (r));
818 }
819
820 /**
821 \brief Dual 16-bit addition and subtraction with exchange.
822 \details It enables you to exchange the halfwords of the second operand, add the high halfwords
823 and subtract the low halfwords.
824 \param [in] x first operand for the subtraction in the low halfword,
825 and the first operand for the addition in the high halfword.
826 \param [in] y second operand for the subtraction in the high halfword,
827 and the second operand for the addition in the low halfword.
828 \return the subtraction of the high halfword in the second operand from the
829 low halfword in the first operand, in the low halfword of the return value.\n
830 the addition of the high halfword in the first operand and the
831 low halfword in the second operand, in the high halfword of the return value.
832 \remark
833 res[15:0] = val1[15:0] - val2[31:16] \n
834 res[31:16] = val1[31:16] + val2[15:0]
835 */
__SASX(uint32_t x,uint32_t y)836 __ALWAYS_INLINE uint32_t __SASX(uint32_t x, uint32_t y)
837 {
838 int32_t r, s;
839
840 r = ((((int32_t)x << 16) >> 16) - (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
841 s = ((((int32_t)x) >> 16) + (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
842
843 return ((uint32_t)((s << 16) | (r)));
844 }
845
846 /**
847 \brief Dual 16-bit unsigned addition and subtraction with exchange.
848 \details This function enables you to exchange the two halfwords of the second operand,
849 add the high halfwords and subtract the low halfwords.
850 \param [in] x first operand for the subtraction in the low halfword,
851 and the first operand for the addition in the high halfword.
852 \param [in] y second operand for the subtraction in the high halfword,
853 and the second operand for the addition in the low halfword.
854 \return the subtraction of the high halfword in the second operand from the
855 low halfword in the first operand, in the low halfword of the return value.\n
856 the addition of the high halfword in the first operand and the
857 low halfword in the second operand, in the high halfword of the return value.
858 \remark
859 res[15:0] = val1[15:0] - val2[31:16] \n
860 res[31:16] = val1[31:16] + val2[15:0]
861 */
__UASX(uint32_t x,uint32_t y)862 __ALWAYS_INLINE uint32_t __UASX(uint32_t x, uint32_t y)
863 {
864 int32_t r, s;
865
866 r = (((x << 16) >> 16) - ((y) >> 16)) & 0x0000FFFF;
867 s = (((x) >> 16) + ((y << 16) >> 16)) & 0x0000FFFF;
868
869 return ((s << 16) | (r));
870 }
871
872 /**
873 \brief Dual 16-bit signed addition and subtraction with halved results.
874 \details This function enables you to exchange the two halfwords of one operand, perform one
875 signed 16-bit integer addition and one signed 16-bit subtraction, and halve the results.
876 \param [in] x first 16-bit operands.
877 \param [in] y second 16-bit operands.
878 \return the halved subtraction of the high halfword in the second operand from the
879 low halfword in the first operand, in the low halfword of the return value.\n
880 the halved addition of the low halfword in the second operand from the high
881 halfword in the first operand, in the high halfword of the return value.
882 \remark
883 res[15:0] = (val1[15:0] - val2[31:16]) >> 1 \n
884 res[31:16] = (val1[31:16] + val2[15:0]) >> 1
885 */
__SHASX(uint32_t x,uint32_t y)886 __ALWAYS_INLINE uint32_t __SHASX(uint32_t x, uint32_t y)
887 {
888 int32_t r, s;
889
890 r = (((((int32_t)x << 16) >> 16) - (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
891 s = (((((int32_t)x) >> 16) + (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
892
893 return ((uint32_t)((s << 16) | (r)));
894 }
895
896 /**
897 \brief Dual 16-bit unsigned addition and subtraction with halved results and exchange.
898 \details This function enables you to exchange the halfwords of the second operand,
899 add the high halfwords and subtract the low halfwords, halving the results.
900 \param [in] x first operand for the subtraction in the low halfword, and
901 the first operand for the addition in the high halfword.
902 \param [in] y second operand for the subtraction in the high halfword, and
903 the second operand for the addition in the low halfword.
904 \return the halved subtraction of the high halfword in the second operand from the
905 low halfword in the first operand, in the low halfword of the return value.\n
906 the halved addition of the low halfword in the second operand from the high
907 halfword in the first operand, in the high halfword of the return value.
908 \remark
909 res[15:0] = (val1[15:0] - val2[31:16]) >> 1 \n
910 res[31:16] = (val1[31:16] + val2[15:0]) >> 1
911 */
__UHASX(uint32_t x,uint32_t y)912 __ALWAYS_INLINE uint32_t __UHASX(uint32_t x, uint32_t y)
913 {
914 int32_t r, s;
915
916 r = ((((x << 16) >> 16) - ((y) >> 16)) >> 1) & 0x0000FFFF;
917 s = ((((x) >> 16) + ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
918
919 return ((s << 16) | (r));
920 }
921
922 /**
923 \brief Dual 16-bit subtract and add with exchange.
924 \details This function enables you to exchange the halfwords of one operand,
925 then subtract the high halfwords and add the low halfwords,
926 saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
927 \param [in] x first operand for the addition in the low halfword,
928 and the first operand for the subtraction in the high halfword.
929 \param [in] y second operand for the addition in the high halfword,
930 and the second operand for the subtraction in the low halfword.
931 \return the saturated addition of the low halfword of the first operand and the high
932 halfword of the second operand, in the low halfword of the return value.\n
933 the saturated subtraction of the low halfword of the second operand from the
934 high halfword of the first operand, in the high halfword of the return value.\n
935 The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
936 \remark
937 res[15:0] = val1[15:0] + val2[31:16] \n
938 res[31:16] = val1[31:16] - val2[15:0]
939 */
__QSAX(uint32_t x,uint32_t y)940 __ALWAYS_INLINE uint32_t __QSAX(uint32_t x, uint32_t y)
941 {
942 int32_t r, s;
943
944 r = __SSAT(((((int32_t)x << 16) >> 16) + (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
945 s = __SSAT(((((int32_t)x) >> 16) - (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
946
947 return ((uint32_t)((s << 16) | (r)));
948 }
949
950 /**
951 \brief Dual 16-bit unsigned saturating subtraction and addition with exchange.
952 \details This function enables you to exchange the halfwords of the second operand and perform
953 one unsigned 16-bit integer subtraction and one unsigned 16-bit addition, saturating
954 the results to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
955 \param [in] x first operand for the addition in the low halfword,
956 and the first operand for the subtraction in the high halfword.
957 \param [in] y second operand for the addition in the high halfword,
958 and the second operand for the subtraction in the low halfword.
959 \return the saturated addition of the low halfword of the first operand and the high
960 halfword of the second operand, in the low halfword of the return value.\n
961 the saturated subtraction of the low halfword of the second operand from the
962 high halfword of the first operand, in the high halfword of the return value.\n
963 The returned results are saturated to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
964 \remark
965 res[15:0] = val1[15:0] + val2[31:16] \n
966 res[31:16] = val1[31:16] - val2[15:0]
967 */
__UQSAX(uint32_t x,uint32_t y)968 __ALWAYS_INLINE uint32_t __UQSAX(uint32_t x, uint32_t y)
969 {
970 int32_t r, s;
971
972 r = __IUSAT((((x << 16) >> 16) + ((y) >> 16)), 16) & 0x0000FFFF;
973 s = __IUSAT((((x) >> 16) - ((y << 16) >> 16)), 16) & 0x0000FFFF;
974
975 return ((s << 16) | (r));
976 }
977
978 /**
979 \brief Dual 16-bit unsigned subtract and add with exchange.
980 \details This function enables you to exchange the halfwords of the second operand,
981 subtract the high halfwords and add the low halfwords.
982 \param [in] x first operand for the addition in the low halfword,
983 and the first operand for the subtraction in the high halfword.
984 \param [in] y second operand for the addition in the high halfword,
985 and the second operand for the subtraction in the low halfword.
986 \return the addition of the low halfword of the first operand and the high
987 halfword of the second operand, in the low halfword of the return value.\n
988 the subtraction of the low halfword of the second operand from the
989 high halfword of the first operand, in the high halfword of the return value.\n
990 \remark
991 res[15:0] = val1[15:0] + val2[31:16] \n
992 res[31:16] = val1[31:16] - val2[15:0]
993 */
__USAX(uint32_t x,uint32_t y)994 __ALWAYS_INLINE uint32_t __USAX(uint32_t x, uint32_t y)
995 {
996 int32_t r, s;
997
998 r = (((x << 16) >> 16) + ((y) >> 16)) & 0x0000FFFF;
999 s = (((x) >> 16) - ((y << 16) >> 16)) & 0x0000FFFF;
1000
1001 return ((s << 16) | (r));
1002 }
1003
1004 /**
1005 \brief Dual 16-bit signed subtraction and addition with exchange.
1006 \details This function enables you to exchange the two halfwords of one operand and perform one
1007 16-bit integer subtraction and one 16-bit addition.
1008 \param [in] x first operand for the addition in the low halfword, and the first operand
1009 for the subtraction in the high halfword.
1010 \param [in] y second operand for the addition in the high halfword, and the second
1011 operand for the subtraction in the low halfword.
1012 \return the addition of the low halfword of the first operand and the high
1013 halfword of the second operand, in the low halfword of the return value.\n
1014 the subtraction of the low halfword of the second operand from the
1015 high halfword of the first operand, in the high halfword of the return value.\n
1016 \remark
1017 res[15:0] = val1[15:0] + val2[31:16] \n
1018 res[31:16] = val1[31:16] - val2[15:0]
1019 */
__SSAX(uint32_t x,uint32_t y)1020 __ALWAYS_INLINE uint32_t __SSAX(uint32_t x, uint32_t y)
1021 {
1022 int32_t r, s;
1023
1024 r = ((((int32_t)x << 16) >> 16) + (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
1025 s = ((((int32_t)x) >> 16) - (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
1026
1027 return ((uint32_t)((s << 16) | (r)));
1028 }
1029
1030
1031 /**
1032 \brief Dual 16-bit signed subtraction and addition with halved results.
1033 \details This function enables you to exchange the two halfwords of one operand, perform one signed
1034 16-bit integer subtraction and one signed 16-bit addition, and halve the results.
1035 \param [in] x first 16-bit operands.
1036 \param [in] y second 16-bit operands.
1037 \return the halved addition of the low halfword in the first operand and the
1038 high halfword in the second operand, in the low halfword of the return value.\n
1039 the halved subtraction of the low halfword in the second operand from the
1040 high halfword in the first operand, in the high halfword of the return value.
1041 \remark
1042 res[15:0] = (val1[15:0] + val2[31:16]) >> 1 \n
1043 res[31:16] = (val1[31:16] - val2[15:0]) >> 1
1044 */
__SHSAX(uint32_t x,uint32_t y)1045 __ALWAYS_INLINE uint32_t __SHSAX(uint32_t x, uint32_t y)
1046 {
1047 int32_t r, s;
1048
1049 r = (((((int32_t)x << 16) >> 16) + (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
1050 s = (((((int32_t)x) >> 16) - (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
1051
1052 return ((uint32_t)((s << 16) | (r)));
1053 }
1054
1055 /**
1056 \brief Dual 16-bit unsigned subtraction and addition with halved results and exchange.
1057 \details This function enables you to exchange the halfwords of the second operand,
1058 subtract the high halfwords and add the low halfwords, halving the results.
1059 \param [in] x first operand for the addition in the low halfword, and
1060 the first operand for the subtraction in the high halfword.
1061 \param [in] y second operand for the addition in the high halfword, and
1062 the second operand for the subtraction in the low halfword.
1063 \return the halved addition of the low halfword in the first operand and the
1064 high halfword in the second operand, in the low halfword of the return value.\n
1065 the halved subtraction of the low halfword in the second operand from the
1066 high halfword in the first operand, in the high halfword of the return value.
1067 \remark
1068 res[15:0] = (val1[15:0] + val2[31:16]) >> 1 \n
1069 res[31:16] = (val1[31:16] - val2[15:0]) >> 1
1070 */
__UHSAX(uint32_t x,uint32_t y)1071 __ALWAYS_INLINE uint32_t __UHSAX(uint32_t x, uint32_t y)
1072 {
1073 int32_t r, s;
1074
1075 r = ((((x << 16) >> 16) + ((y) >> 16)) >> 1) & 0x0000FFFF;
1076 s = ((((x) >> 16) - ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
1077
1078 return ((s << 16) | (r));
1079 }
1080
1081 /**
1082 \brief Dual 16-bit signed multiply with exchange returning difference.
1083 \details This function enables you to perform two 16-bit signed multiplications, subtracting
1084 one of the products from the other. The halfwords of the second operand are exchanged
1085 before performing the arithmetic. This produces top * bottom and bottom * top multiplication.
1086 \param [in] x first 16-bit operands for each multiplication.
1087 \param [in] y second 16-bit operands for each multiplication.
1088 \return the difference of the products of the two 16-bit signed multiplications.
1089 \remark
1090 p1 = val1[15:0] * val2[31:16] \n
1091 p2 = val1[31:16] * val2[15:0] \n
1092 res[31:0] = p1 - p2
1093 */
__SMUSDX(uint32_t x,uint32_t y)1094 __ALWAYS_INLINE uint32_t __SMUSDX(uint32_t x, uint32_t y)
1095 {
1096 return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) -
1097 ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16))));
1098 }
1099
1100 /**
1101 \brief Sum of dual 16-bit signed multiply with exchange.
1102 \details This function enables you to perform two 16-bit signed multiplications with exchanged
1103 halfwords of the second operand, adding the products together.
1104 \param [in] x first 16-bit operands for each multiplication.
1105 \param [in] y second 16-bit operands for each multiplication.
1106 \return the sum of the products of the two 16-bit signed multiplications with exchanged halfwords of the second operand.
1107 \remark
1108 p1 = val1[15:0] * val2[31:16] \n
1109 p2 = val1[31:16] * val2[15:0] \n
1110 res[31:0] = p1 + p2
1111 */
__SMUADX(uint32_t x,uint32_t y)1112 __ALWAYS_INLINE uint32_t __SMUADX(uint32_t x, uint32_t y)
1113 {
1114 return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) +
1115 ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16))));
1116 }
1117
1118
1119 /**
1120 \brief Saturating add.
1121 \details This function enables you to obtain the saturating add of two integers.
1122 \param [in] x first summand of the saturating add operation.
1123 \param [in] y second summand of the saturating add operation.
1124 \return the saturating addition of val1 and val2.
1125 \remark
1126 res[31:0] = SAT(val1 + SAT(val2))
1127 */
__QADD(int32_t x,int32_t y)1128 __ALWAYS_INLINE int32_t __QADD(int32_t x, int32_t y)
1129 {
1130 int32_t result;
1131
1132 if (y >= 0)
1133 {
1134 if (x + y >= x)
1135 {
1136 result = x + y;
1137 }
1138 else
1139 {
1140 result = 0x7FFFFFFF;
1141 }
1142 }
1143 else
1144 {
1145 if (x + y < x)
1146 {
1147 result = x + y;
1148 }
1149 else
1150 {
1151 result = 0x80000000;
1152 }
1153 }
1154
1155 return result;
1156 }
1157
1158 /**
1159 \brief Saturating subtract.
1160 \details This function enables you to obtain the saturating add of two integers.
1161 \param [in] x first summand of the saturating add operation.
1162 \param [in] y second summand of the saturating add operation.
1163 \return the saturating addition of val1 and val2.
1164 \remark
1165 res[31:0] = SAT(val1 + SAT(val2))
1166 */
__QSUB(int32_t x,int32_t y)1167 __ALWAYS_INLINE int32_t __QSUB(int32_t x, int32_t y)
1168 {
1169 int64_t tmp;
1170 int32_t result;
1171
1172 tmp = (int64_t)x - (int64_t)y;
1173
1174 if (tmp > 0x7fffffff)
1175 {
1176 tmp = 0x7fffffff;
1177 }
1178 else if (tmp < (-2147483647 - 1))
1179 {
1180 tmp = -2147483647 - 1;
1181 }
1182
1183 result = tmp;
1184 return result;
1185 }
1186
1187 /**
1188 \brief Dual 16-bit signed multiply with single 32-bit accumulator.
1189 \details This function enables you to perform two signed 16-bit multiplications,
1190 adding both results to a 32-bit accumulate operand.
1191 \param [in] x first 16-bit operands for each multiplication.
1192 \param [in] y second 16-bit operands for each multiplication.
1193 \param [in] sum accumulate value.
1194 \return the product of each multiplication added to the accumulate value, as a 32-bit integer.
1195 \remark
1196 p1 = val1[15:0] * val2[15:0] \n
1197 p2 = val1[31:16] * val2[31:16] \n
1198 res[31:0] = p1 + p2 + val3[31:0]
1199 */
__SMLAD(uint32_t x,uint32_t y,uint32_t sum)1200 __ALWAYS_INLINE uint32_t __SMLAD(uint32_t x, uint32_t y, uint32_t sum)
1201 {
1202 return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) +
1203 ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
1204 (((int32_t)sum))));
1205 }
1206
1207 /**
1208 \brief Pre-exchanged dual 16-bit signed multiply with single 32-bit accumulator.
1209 \details This function enables you to perform two signed 16-bit multiplications with exchanged
1210 halfwords of the second operand, adding both results to a 32-bit accumulate operand.
1211 \param [in] x first 16-bit operands for each multiplication.
1212 \param [in] y second 16-bit operands for each multiplication.
1213 \param [in] sum accumulate value.
1214 \return the product of each multiplication with exchanged halfwords of the second
1215 operand added to the accumulate value, as a 32-bit integer.
1216 \remark
1217 p1 = val1[15:0] * val2[31:16] \n
1218 p2 = val1[31:16] * val2[15:0] \n
1219 res[31:0] = p1 + p2 + val3[31:0]
1220 */
__SMLADX(uint32_t x,uint32_t y,uint32_t sum)1221 __ALWAYS_INLINE uint32_t __SMLADX(uint32_t x, uint32_t y, uint32_t sum)
1222 {
1223 return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) +
1224 ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
1225 (((int32_t)sum))));
1226 }
1227
1228 /**
1229 \brief Dual 16-bit signed multiply with exchange subtract with 32-bit accumulate.
1230 \details This function enables you to perform two 16-bit signed multiplications, take the
1231 difference of the products, subtracting the high halfword product from the low
1232 halfword product, and add the difference to a 32-bit accumulate operand.
1233 \param [in] x first 16-bit operands for each multiplication.
1234 \param [in] y second 16-bit operands for each multiplication.
1235 \param [in] sum accumulate value.
1236 \return the difference of the product of each multiplication, added to the accumulate value.
1237 \remark
1238 p1 = val1[15:0] * val2[15:0] \n
1239 p2 = val1[31:16] * val2[31:16] \n
1240 res[31:0] = p1 - p2 + val3[31:0]
1241 */
__SMLSD(uint32_t x,uint32_t y,uint32_t sum)1242 __ALWAYS_INLINE uint32_t __SMLSD(uint32_t x, uint32_t y, uint32_t sum)
1243 {
1244 return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) -
1245 ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
1246 (((int32_t)sum))));
1247 }
1248
1249 /**
1250 \brief Dual 16-bit signed multiply with exchange subtract with 32-bit accumulate.
1251 \details This function enables you to exchange the halfwords in the second operand, then perform two 16-bit
1252 signed multiplications. The difference of the products is added to a 32-bit accumulate operand.
1253 \param [in] x first 16-bit operands for each multiplication.
1254 \param [in] y second 16-bit operands for each multiplication.
1255 \param [in] sum accumulate value.
1256 \return the difference of the product of each multiplication, added to the accumulate value.
1257 \remark
1258 p1 = val1[15:0] * val2[31:16] \n
1259 p2 = val1[31:16] * val2[15:0] \n
1260 res[31:0] = p1 - p2 + val3[31:0]
1261 */
__SMLSDX(uint32_t x,uint32_t y,uint32_t sum)1262 __ALWAYS_INLINE uint32_t __SMLSDX(uint32_t x, uint32_t y, uint32_t sum)
1263 {
1264 return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) -
1265 ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
1266 (((int32_t)sum))));
1267 }
1268
1269 /**
1270 \brief Dual 16-bit signed multiply with single 64-bit accumulator.
1271 \details This function enables you to perform two signed 16-bit multiplications, adding both results
1272 to a 64-bit accumulate operand. Overflow is only possible as a result of the 64-bit addition.
1273 This overflow is not detected if it occurs. Instead, the result wraps around modulo2^64.
1274 \param [in] x first 16-bit operands for each multiplication.
1275 \param [in] y second 16-bit operands for each multiplication.
1276 \param [in] sum accumulate value.
1277 \return the product of each multiplication added to the accumulate value.
1278 \remark
1279 p1 = val1[15:0] * val2[15:0] \n
1280 p2 = val1[31:16] * val2[31:16] \n
1281 sum = p1 + p2 + val3[63:32][31:0] \n
1282 res[63:32] = sum[63:32] \n
1283 res[31:0] = sum[31:0]
1284 */
__SMLALD(uint32_t x,uint32_t y,uint64_t sum)1285 __ALWAYS_INLINE uint64_t __SMLALD(uint32_t x, uint32_t y, uint64_t sum)
1286 {
1287 return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) +
1288 ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
1289 (((uint64_t)sum))));
1290 }
1291
1292 /**
1293 \brief Dual 16-bit signed multiply with exchange with single 64-bit accumulator.
1294 \details This function enables you to exchange the halfwords of the second operand, and perform two
1295 signed 16-bit multiplications, adding both results to a 64-bit accumulate operand. Overflow
1296 is only possible as a result of the 64-bit addition. This overflow is not detected if it occurs.
1297 Instead, the result wraps around modulo2^64.
1298 \param [in] x first 16-bit operands for each multiplication.
1299 \param [in] y second 16-bit operands for each multiplication.
1300 \param [in] sum accumulate value.
1301 \return the product of each multiplication added to the accumulate value.
1302 \remark
1303 p1 = val1[15:0] * val2[31:16] \n
1304 p2 = val1[31:16] * val2[15:0] \n
1305 sum = p1 + p2 + val3[63:32][31:0] \n
1306 res[63:32] = sum[63:32] \n
1307 res[31:0] = sum[31:0]
1308 */
__SMLALDX(uint32_t x,uint32_t y,uint64_t sum)1309 __ALWAYS_INLINE uint64_t __SMLALDX(uint32_t x, uint32_t y, uint64_t sum)
1310 {
1311 return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) +
1312 ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
1313 (((uint64_t)sum))));
1314 }
1315
1316 /**
1317 \brief dual 16-bit signed multiply subtract with 64-bit accumulate.
1318 \details This function It enables you to perform two 16-bit signed multiplications, take the difference
1319 of the products, subtracting the high halfword product from the low halfword product, and add the
1320 difference to a 64-bit accumulate operand. Overflow cannot occur during the multiplications or the
1321 subtraction. Overflow can occur as a result of the 64-bit addition, and this overflow is not
1322 detected. Instead, the result wraps round to modulo2^64.
1323 \param [in] x first 16-bit operands for each multiplication.
1324 \param [in] y second 16-bit operands for each multiplication.
1325 \param [in] sum accumulate value.
1326 \return the difference of the product of each multiplication, added to the accumulate value.
1327 \remark
1328 p1 = val1[15:0] * val2[15:0] \n
1329 p2 = val1[31:16] * val2[31:16] \n
1330 res[63:0] = p1 - p2 + val3[63:0]
1331 */
__SMLSLD(uint32_t x,uint32_t y,uint64_t sum)1332 __ALWAYS_INLINE uint64_t __SMLSLD(uint32_t x, uint32_t y, uint64_t sum)
1333 {
1334 return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) -
1335 ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
1336 (((uint64_t)sum))));
1337 }
1338
1339 /**
1340 \brief Dual 16-bit signed multiply with exchange subtract with 64-bit accumulate.
1341 \details This function enables you to exchange the halfwords of the second operand, perform two 16-bit multiplications,
1342 adding the difference of the products to a 64-bit accumulate operand. Overflow cannot occur during the
1343 multiplications or the subtraction. Overflow can occur as a result of the 64-bit addition, and this overflow
1344 is not detected. Instead, the result wraps round to modulo2^64.
1345 \param [in] x first 16-bit operands for each multiplication.
1346 \param [in] y second 16-bit operands for each multiplication.
1347 \param [in] sum accumulate value.
1348 \return the difference of the product of each multiplication, added to the accumulate value.
1349 \remark
1350 p1 = val1[15:0] * val2[31:16] \n
1351 p2 = val1[31:16] * val2[15:0] \n
1352 res[63:0] = p1 - p2 + val3[63:0]
1353 */
__SMLSLDX(uint32_t x,uint32_t y,uint64_t sum)1354 __ALWAYS_INLINE uint64_t __SMLSLDX(uint32_t x, uint32_t y, uint64_t sum)
1355 {
1356 return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) -
1357 ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
1358 (((uint64_t)sum))));
1359 }
1360
1361 /**
1362 \brief 32-bit signed multiply with 32-bit truncated accumulator.
1363 \details This function enables you to perform a signed 32-bit multiplications, adding the most
1364 significant 32 bits of the 64-bit result to a 32-bit accumulate operand.
1365 \param [in] x first operand for multiplication.
1366 \param [in] y second operand for multiplication.
1367 \param [in] sum accumulate value.
1368 \return the product of multiplication (most significant 32 bits) is added to the accumulate value, as a 32-bit integer.
1369 \remark
1370 p = val1 * val2 \n
1371 res[31:0] = p[61:32] + val3[31:0]
1372 */
__SMMLA(int32_t x,int32_t y,int32_t sum)1373 __ALWAYS_INLINE uint32_t __SMMLA(int32_t x, int32_t y, int32_t sum)
1374 {
1375 return (uint32_t)((int32_t)((int64_t)((int64_t)x * (int64_t)y) >> 32) + sum);
1376 }
1377
1378 /**
1379 \brief Sum of dual 16-bit signed multiply.
1380 \details This function enables you to perform two 16-bit signed multiplications, adding the products together.
1381 \param [in] x first 16-bit operands for each multiplication.
1382 \param [in] y second 16-bit operands for each multiplication.
1383 \return the sum of the products of the two 16-bit signed multiplications.
1384 \remark
1385 p1 = val1[15:0] * val2[15:0] \n
1386 p2 = val1[31:16] * val2[31:16] \n
1387 res[31:0] = p1 + p2
1388 */
__SMUAD(uint32_t x,uint32_t y)1389 __ALWAYS_INLINE uint32_t __SMUAD(uint32_t x, uint32_t y)
1390 {
1391 return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) +
1392 ((((int32_t)x) >> 16) * (((int32_t)y) >> 16))));
1393 }
1394
1395 /**
1396 \brief Dual 16-bit signed multiply returning difference.
1397 \details This function enables you to perform two 16-bit signed multiplications, taking the difference
1398 of the products by subtracting the high halfword product from the low halfword product.
1399 \param [in] x first 16-bit operands for each multiplication.
1400 \param [in] y second 16-bit operands for each multiplication.
1401 \return the difference of the products of the two 16-bit signed multiplications.
1402 \remark
1403 p1 = val1[15:0] * val2[15:0] \n
1404 p2 = val1[31:16] * val2[31:16] \n
1405 res[31:0] = p1 - p2
1406 */
__SMUSD(uint32_t x,uint32_t y)1407 __ALWAYS_INLINE uint32_t __SMUSD(uint32_t x, uint32_t y)
1408 {
1409 return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) -
1410 ((((int32_t)x) >> 16) * (((int32_t)y) >> 16))));
1411 }
1412
1413 /**
1414 \brief Dual extracted 8-bit to 16-bit signed addition.
1415 \details This function enables you to extract two 8-bit values from the second operand (at bit positions
1416 [7:0] and [23:16]), sign-extend them to 16-bits each, and add the results to the first operand.
1417 \param [in] x values added to the sign-extended to 16-bit values.
1418 \param [in] y two 8-bit values to be extracted and sign-extended.
1419 \return the addition of val1 and val2, where the 8-bit values in val2[7:0] and
1420 val2[23:16] have been extracted and sign-extended prior to the addition.
1421 \remark
1422 res[15:0] = val1[15:0] + SignExtended(val2[7:0]) \n
1423 res[31:16] = val1[31:16] + SignExtended(val2[23:16])
1424 */
__SXTAB16(uint32_t x,uint32_t y)1425 __ALWAYS_INLINE uint32_t __SXTAB16(uint32_t x, uint32_t y)
1426 {
1427 return ((uint32_t)((((((int32_t)y << 24) >> 24) + (((int32_t)x << 16) >> 16)) & (int32_t)0x0000FFFF) |
1428 (((((int32_t)y << 8) >> 8) + (((int32_t)x >> 16) << 16)) & (int32_t)0xFFFF0000)));
1429 }
1430
1431 /**
1432 \brief Extracted 16-bit to 32-bit unsigned addition.
1433 \details This function enables you to extract two 8-bit values from one operand, zero-extend
1434 them to 16 bits each, and add the results to two 16-bit values from another operand.
1435 \param [in] x values added to the zero-extended to 16-bit values.
1436 \param [in] y two 8-bit values to be extracted and zero-extended.
1437 \return the addition of val1 and val2, where the 8-bit values in val2[7:0] and
1438 val2[23:16] have been extracted and zero-extended prior to the addition.
1439 \remark
1440 res[15:0] = ZeroExt(val2[7:0] to 16 bits) + val1[15:0] \n
1441 res[31:16] = ZeroExt(val2[31:16] to 16 bits) + val1[31:16]
1442 */
__UXTAB16(uint32_t x,uint32_t y)1443 __ALWAYS_INLINE uint32_t __UXTAB16(uint32_t x, uint32_t y)
1444 {
1445 return ((uint32_t)(((((y << 24) >> 24) + ((x << 16) >> 16)) & 0x0000FFFF) |
1446 ((((y << 8) >> 8) + ((x >> 16) << 16)) & 0xFFFF0000)));
1447 }
1448
1449 /**
1450 \brief Dual extract 8-bits and sign extend each to 16-bits.
1451 \details This function enables you to extract two 8-bit values from an operand and sign-extend them to 16 bits each.
1452 \param [in] x two 8-bit values in val[7:0] and val[23:16] to be sign-extended.
1453 \return the 8-bit values sign-extended to 16-bit values.\n
1454 sign-extended value of val[7:0] in the low halfword of the return value.\n
1455 sign-extended value of val[23:16] in the high halfword of the return value.
1456 \remark
1457 res[15:0] = SignExtended(val[7:0]) \n
1458 res[31:16] = SignExtended(val[23:16])
1459 */
__SXTB16(uint32_t x)1460 __ALWAYS_INLINE uint32_t __SXTB16(uint32_t x)
1461 {
1462 return ((uint32_t)(((((int32_t)x << 24) >> 24) & (int32_t)0x0000FFFF) |
1463 ((((int32_t)x << 8) >> 8) & (int32_t)0xFFFF0000)));
1464 }
1465
1466 /**
1467 \brief Dual extract 8-bits and zero-extend to 16-bits.
1468 \details This function enables you to extract two 8-bit values from an operand and zero-extend them to 16 bits each.
1469 \param [in] x two 8-bit values in val[7:0] and val[23:16] to be zero-extended.
1470 \return the 8-bit values sign-extended to 16-bit values.\n
1471 sign-extended value of val[7:0] in the low halfword of the return value.\n
1472 sign-extended value of val[23:16] in the high halfword of the return value.
1473 \remark
1474 res[15:0] = SignExtended(val[7:0]) \n
1475 res[31:16] = SignExtended(val[23:16])
1476 */
__UXTB16(uint32_t x)1477 __ALWAYS_INLINE uint32_t __UXTB16(uint32_t x)
1478 {
1479 return ((uint32_t)((((x << 24) >> 24) & 0x0000FFFF) |
1480 (((x << 8) >> 8) & 0xFFFF0000)));
1481 }
1482
1483 #endif /* _CSI_SIMD_H_ */
1484