]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_armclang.h
Updated ARMv8M Mainline FPU settings in partition*.h.
[cmsis] / CMSIS / Core / Include / cmsis_armclang.h
1 /**************************************************************************//**
2  * @file     cmsis_armclang.h
3  * @brief    CMSIS Cortex-M Core Function/Instruction Header File
4  * @version  V5.00
5  * @date     28. October 2016
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2016 ARM Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the License); you may
13  * not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24
25 #ifndef __CMSIS_ARMCLANG_H
26 #define __CMSIS_ARMCLANG_H
27
28 #ifndef __ARM_COMPAT_H
29 #include <arm_compat.h>    /* Compatibility header for ARM Compiler 5 intrinsics */
30 #endif
31
32 /* CMSIS compiler specific defines */
33 #ifndef   __ASM
34   #define __ASM                     __asm
35 #endif
36 #ifndef   __INLINE
37   #define __INLINE                  __inline
38 #endif
39 #ifndef   __STATIC_INLINE
40   #define __STATIC_INLINE           static __inline
41 #endif
42 #ifndef   __NO_RETURN
43   #define __NO_RETURN               __attribute__((noreturn))
44 #endif
45 #ifndef   __USED
46   #define __USED                    __attribute__((used))
47 #endif
48 #ifndef   __WEAK
49   #define __WEAK                    __attribute__((weak))
50 #endif
51 #ifndef   __UNALIGNED_UINT32
52   #pragma clang diagnostic push
53   #pragma clang diagnostic ignored "-Wpacked"
54   struct __attribute__((packed)) T_UINT32 { uint32_t v; };
55   #pragma clang diagnostic pop
56   #define __UNALIGNED_UINT32(x)     (((struct T_UINT32 *)(x))->v)
57 #endif
58 #ifndef   __ALIGNED
59   #define __ALIGNED(x)              __attribute__((aligned(x)))
60 #endif
61 #ifndef   __PACKED
62   #define __PACKED                  __attribute__((packed, aligned(1)))
63 #endif
64
65
66 /* ###########################  Core Function Access  ########################### */
67 /** \ingroup  CMSIS_Core_FunctionInterface
68     \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
69   @{
70  */
71
72 /**
73   \brief   Enable IRQ Interrupts
74   \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
75            Can only be executed in Privileged modes.
76  */
77 /* intrinsic void __enable_irq();  see arm_compat.h */
78
79
80 /**
81   \brief   Disable IRQ Interrupts
82   \details Disables IRQ interrupts by setting the I-bit in the CPSR.
83            Can only be executed in Privileged modes.
84  */
85 /* intrinsic void __disable_irq();  see arm_compat.h */
86
87
88 /**
89   \brief   Get Control Register
90   \details Returns the content of the Control Register.
91   \return               Control Register value
92  */
93 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_CONTROL(void)
94 {
95   uint32_t result;
96
97   __ASM volatile ("MRS %0, control" : "=r" (result) );
98   return(result);
99 }
100
101
102 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
103 /**
104   \brief   Get Control Register (non-secure)
105   \details Returns the content of the non-secure Control Register when in secure mode.
106   \return               non-secure Control Register value
107  */
108 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_CONTROL_NS(void)
109 {
110   uint32_t result;
111
112   __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
113   return(result);
114 }
115 #endif
116
117
118 /**
119   \brief   Set Control Register
120   \details Writes the given value to the Control Register.
121   \param [in]    control  Control Register value to set
122  */
123 __attribute__((always_inline)) __STATIC_INLINE void __set_CONTROL(uint32_t control)
124 {
125   __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
126 }
127
128
129 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
130 /**
131   \brief   Set Control Register (non-secure)
132   \details Writes the given value to the non-secure Control Register when in secure state.
133   \param [in]    control  Control Register value to set
134  */
135 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_CONTROL_NS(uint32_t control)
136 {
137   __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
138 }
139 #endif
140
141
142 /**
143   \brief   Get IPSR Register
144   \details Returns the content of the IPSR Register.
145   \return               IPSR Register value
146  */
147 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_IPSR(void)
148 {
149   uint32_t result;
150
151   __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
152   return(result);
153 }
154
155
156 /**
157   \brief   Get APSR Register
158   \details Returns the content of the APSR Register.
159   \return               APSR Register value
160  */
161 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_APSR(void)
162 {
163   uint32_t result;
164
165   __ASM volatile ("MRS %0, apsr" : "=r" (result) );
166   return(result);
167 }
168
169
170 /**
171   \brief   Get xPSR Register
172   \details Returns the content of the xPSR Register.
173   \return               xPSR Register value
174  */
175 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_xPSR(void)
176 {
177   uint32_t result;
178
179   __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
180   return(result);
181 }
182
183
184 /**
185   \brief   Get Process Stack Pointer
186   \details Returns the current value of the Process Stack Pointer (PSP).
187   \return               PSP Register value
188  */
189 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PSP(void)
190 {
191   register uint32_t result;
192
193   __ASM volatile ("MRS %0, psp"  : "=r" (result) );
194   return(result);
195 }
196
197
198 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
199 /**
200   \brief   Get Process Stack Pointer (non-secure)
201   \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
202   \return               PSP Register value
203  */
204 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_PSP_NS(void)
205 {
206   register uint32_t result;
207
208   __ASM volatile ("MRS %0, psp_ns"  : "=r" (result) );
209   return(result);
210 }
211 #endif
212
213
214 /**
215   \brief   Set Process Stack Pointer
216   \details Assigns the given value to the Process Stack Pointer (PSP).
217   \param [in]    topOfProcStack  Process Stack Pointer value to set
218  */
219 __attribute__((always_inline)) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
220 {
221   __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : "sp");
222 }
223
224
225 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
226 /**
227   \brief   Set Process Stack Pointer (non-secure)
228   \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
229   \param [in]    topOfProcStack  Process Stack Pointer value to set
230  */
231 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
232 {
233   __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : "sp");
234 }
235 #endif
236
237
238 /**
239   \brief   Get Main Stack Pointer
240   \details Returns the current value of the Main Stack Pointer (MSP).
241   \return               MSP Register value
242  */
243 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_MSP(void)
244 {
245   register uint32_t result;
246
247   __ASM volatile ("MRS %0, msp" : "=r" (result) );
248   return(result);
249 }
250
251
252 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
253 /**
254   \brief   Get Main Stack Pointer (non-secure)
255   \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
256   \return               MSP Register value
257  */
258 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_MSP_NS(void)
259 {
260   register uint32_t result;
261
262   __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
263   return(result);
264 }
265 #endif
266
267
268 /**
269   \brief   Set Main Stack Pointer
270   \details Assigns the given value to the Main Stack Pointer (MSP).
271   \param [in]    topOfMainStack  Main Stack Pointer value to set
272  */
273 __attribute__((always_inline)) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
274 {
275   __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : "sp");
276 }
277
278
279 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
280 /**
281   \brief   Set Main Stack Pointer (non-secure)
282   \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
283   \param [in]    topOfMainStack  Main Stack Pointer value to set
284  */
285 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
286 {
287   __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : "sp");
288 }
289 #endif
290
291
292 /**
293   \brief   Get Priority Mask
294   \details Returns the current state of the priority mask bit from the Priority Mask Register.
295   \return               Priority Mask value
296  */
297 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PRIMASK(void)
298 {
299   uint32_t result;
300
301   __ASM volatile ("MRS %0, primask" : "=r" (result) );
302   return(result);
303 }
304
305
306 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
307 /**
308   \brief   Get Priority Mask (non-secure)
309   \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
310   \return               Priority Mask value
311  */
312 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_PRIMASK_NS(void)
313 {
314   uint32_t result;
315
316   __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
317   return(result);
318 }
319 #endif
320
321
322 /**
323   \brief   Set Priority Mask
324   \details Assigns the given value to the Priority Mask Register.
325   \param [in]    priMask  Priority Mask
326  */
327 __attribute__((always_inline)) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
328 {
329   __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
330 }
331
332
333 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
334 /**
335   \brief   Set Priority Mask (non-secure)
336   \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
337   \param [in]    priMask  Priority Mask
338  */
339 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
340 {
341   __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
342 }
343 #endif
344
345
346 #if ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
347      (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
348      (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    )
349 /**
350   \brief   Enable FIQ
351   \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
352            Can only be executed in Privileged modes.
353  */
354 #define __enable_fault_irq                __enable_fiq   /* see arm_compat.h */
355
356
357 /**
358   \brief   Disable FIQ
359   \details Disables FIQ interrupts by setting the F-bit in the CPSR.
360            Can only be executed in Privileged modes.
361  */
362 #define __disable_fault_irq               __disable_fiq   /* see arm_compat.h */
363
364
365 /**
366   \brief   Get Base Priority
367   \details Returns the current value of the Base Priority register.
368   \return               Base Priority register value
369  */
370 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_BASEPRI(void)
371 {
372   uint32_t result;
373
374   __ASM volatile ("MRS %0, basepri" : "=r" (result) );
375   return(result);
376 }
377
378
379 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
380 /**
381   \brief   Get Base Priority (non-secure)
382   \details Returns the current value of the non-secure Base Priority register when in secure state.
383   \return               Base Priority register value
384  */
385 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_BASEPRI_NS(void)
386 {
387   uint32_t result;
388
389   __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
390   return(result);
391 }
392 #endif
393
394
395 /**
396   \brief   Set Base Priority
397   \details Assigns the given value to the Base Priority register.
398   \param [in]    basePri  Base Priority value to set
399  */
400 __attribute__((always_inline)) __STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
401 {
402   __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
403 }
404
405
406 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
407 /**
408   \brief   Set Base Priority (non-secure)
409   \details Assigns the given value to the non-secure Base Priority register when in secure state.
410   \param [in]    basePri  Base Priority value to set
411  */
412 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
413 {
414   __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
415 }
416 #endif
417
418
419 /**
420   \brief   Set Base Priority with condition
421   \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
422            or the new value increases the BASEPRI priority level.
423   \param [in]    basePri  Base Priority value to set
424  */
425 __attribute__((always_inline)) __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
426 {
427   __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
428 }
429
430
431 /**
432   \brief   Get Fault Mask
433   \details Returns the current value of the Fault Mask register.
434   \return               Fault Mask register value
435  */
436 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
437 {
438   uint32_t result;
439
440   __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
441   return(result);
442 }
443
444
445 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
446 /**
447   \brief   Get Fault Mask (non-secure)
448   \details Returns the current value of the non-secure Fault Mask register when in secure state.
449   \return               Fault Mask register value
450  */
451 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_FAULTMASK_NS(void)
452 {
453   uint32_t result;
454
455   __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
456   return(result);
457 }
458 #endif
459
460
461 /**
462   \brief   Set Fault Mask
463   \details Assigns the given value to the Fault Mask register.
464   \param [in]    faultMask  Fault Mask value to set
465  */
466 __attribute__((always_inline)) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
467 {
468   __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
469 }
470
471
472 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
473 /**
474   \brief   Set Fault Mask (non-secure)
475   \details Assigns the given value to the non-secure Fault Mask register when in secure state.
476   \param [in]    faultMask  Fault Mask value to set
477  */
478 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
479 {
480   __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
481 }
482 #endif
483
484 #endif /* ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
485            (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
486            (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    ) */
487
488
489 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
490      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
491
492 /**
493   \brief   Get Process Stack Pointer Limit
494   \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
495   \return               PSPLIM Register value
496  */
497 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PSPLIM(void)
498 {
499   register uint32_t result;
500
501   __ASM volatile ("MRS %0, psplim"  : "=r" (result) );
502   return(result);
503 }
504
505
506 #if ((defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3)) && \
507      (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1))    )
508 /**
509   \brief   Get Process Stack Pointer Limit (non-secure)
510   \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
511   \return               PSPLIM Register value
512  */
513 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_PSPLIM_NS(void)
514 {
515   register uint32_t result;
516
517   __ASM volatile ("MRS %0, psplim_ns"  : "=r" (result) );
518   return(result);
519 }
520 #endif
521
522
523 /**
524   \brief   Set Process Stack Pointer Limit
525   \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
526   \param [in]    ProcStackPtrLimit  Process Stack Pointer Limit value to set
527  */
528 __attribute__((always_inline)) __STATIC_INLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
529 {
530   __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
531 }
532
533
534 #if ((defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3)) && \
535      (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1))    )
536 /**
537   \brief   Set Process Stack Pointer (non-secure)
538   \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
539   \param [in]    ProcStackPtrLimit  Process Stack Pointer Limit value to set
540  */
541 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
542 {
543   __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
544 }
545 #endif
546
547
548 /**
549   \brief   Get Main Stack Pointer Limit
550   \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
551   \return               MSPLIM Register value
552  */
553 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_MSPLIM(void)
554 {
555   register uint32_t result;
556
557   __ASM volatile ("MRS %0, msplim" : "=r" (result) );
558
559   return(result);
560 }
561
562
563 #if ((defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3)) && \
564      (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1))    )
565 /**
566   \brief   Get Main Stack Pointer Limit (non-secure)
567   \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
568   \return               MSPLIM Register value
569  */
570 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_MSPLIM_NS(void)
571 {
572   register uint32_t result;
573
574   __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
575   return(result);
576 }
577 #endif
578
579
580 /**
581   \brief   Set Main Stack Pointer Limit
582   \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
583   \param [in]    MainStackPtrLimit  Main Stack Pointer Limit value to set
584  */
585 __attribute__((always_inline)) __STATIC_INLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
586 {
587   __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
588 }
589
590
591 #if ((defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3)) && \
592      (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1))    )
593 /**
594   \brief   Set Main Stack Pointer Limit (non-secure)
595   \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
596   \param [in]    MainStackPtrLimit  Main Stack Pointer value to set
597  */
598 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
599 {
600   __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
601 }
602 #endif
603
604 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
605            (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    ) */
606
607
608 #if ((defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
609      (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    )
610
611 /**
612   \brief   Get FPSCR
613   \details Returns the current value of the Floating Point Status/Control register.
614   \return               Floating Point Status/Control register value
615  */
616 /* #define __get_FPSCR      __builtin_arm_get_fpscr */
617 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_FPSCR(void)
618 {
619 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
620      (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
621   uint32_t result;
622
623   __ASM volatile ("");                                 /* Empty asm statement works as a scheduling barrier */
624   __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
625   __ASM volatile ("");
626   return(result);
627 #else
628   return(0U);
629 #endif
630 }
631
632
633 /**
634   \brief   Set FPSCR
635   \details Assigns the given value to the Floating Point Status/Control register.
636   \param [in]    fpscr  Floating Point Status/Control value to set
637  */
638 /* #define __set_FPSCR      __builtin_arm_set_fpscr */
639 __attribute__((always_inline)) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
640 {
641 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
642      (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
643   __ASM volatile ("");                                 /* Empty asm statement works as a scheduling barrier */
644 /*  __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc"); */
645   __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) :);
646   __ASM volatile ("");
647 #else
648   (void)fpscr;
649 #endif
650 }
651
652 #endif /* ((defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
653            (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    ) */
654
655
656
657 /*@} end of CMSIS_Core_RegAccFunctions */
658
659
660 /* ##########################  Core Instruction Access  ######################### */
661 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
662   Access to dedicated instructions
663   @{
664 */
665
666 /* Define macros for porting to both thumb1 and thumb2.
667  * For thumb1, use low register (r0-r7), specified by constraint "l"
668  * Otherwise, use general registers, specified by constraint "r" */
669 #if defined (__thumb__) && !defined (__thumb2__)
670 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
671 #define __CMSIS_GCC_USE_REG(r) "l" (r)
672 #else
673 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
674 #define __CMSIS_GCC_USE_REG(r) "r" (r)
675 #endif
676
677 /**
678   \brief   No Operation
679   \details No Operation does nothing. This instruction can be used for code alignment purposes.
680  */
681 #define __NOP          __builtin_arm_nop
682
683 /**
684   \brief   Wait For Interrupt
685   \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
686  */
687 #define __WFI          __builtin_arm_wfi
688
689
690 /**
691   \brief   Wait For Event
692   \details Wait For Event is a hint instruction that permits the processor to enter
693            a low-power state until one of a number of events occurs.
694  */
695 #define __WFE          __builtin_arm_wfe
696
697
698 /**
699   \brief   Send Event
700   \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
701  */
702 #define __SEV          __builtin_arm_sev
703
704
705 /**
706   \brief   Instruction Synchronization Barrier
707   \details Instruction Synchronization Barrier flushes the pipeline in the processor,
708            so that all instructions following the ISB are fetched from cache or memory,
709            after the instruction has been completed.
710  */
711 #define __ISB()        __builtin_arm_isb(0xF);
712
713 /**
714   \brief   Data Synchronization Barrier
715   \details Acts as a special kind of Data Memory Barrier.
716            It completes when all explicit memory accesses before this instruction complete.
717  */
718 #define __DSB()        __builtin_arm_dsb(0xF);
719
720
721 /**
722   \brief   Data Memory Barrier
723   \details Ensures the apparent order of the explicit memory operations before
724            and after the instruction, without ensuring their completion.
725  */
726 #define __DMB()        __builtin_arm_dmb(0xF);
727
728
729 /**
730   \brief   Reverse byte order (32 bit)
731   \details Reverses the byte order in integer value.
732   \param [in]    value  Value to reverse
733   \return               Reversed value
734  */
735 #define __REV          __builtin_bswap32
736
737
738 /**
739   \brief   Reverse byte order (16 bit)
740   \details Reverses the byte order in two unsigned short values.
741   \param [in]    value  Value to reverse
742   \return               Reversed value
743  */
744 #define __REV16          __builtin_bswap16                /* ToDo ARMCLANG: check if __builtin_bswap16 could be used */
745 #if 0
746 __attribute__((always_inline)) __STATIC_INLINE uint32_t __REV16(uint32_t value)
747 {
748   uint32_t result;
749
750   __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
751   return(result);
752 }
753 #endif
754
755
756 /**
757   \brief   Reverse byte order in signed short value
758   \details Reverses the byte order in a signed short value with sign extension to integer.
759   \param [in]    value  Value to reverse
760   \return               Reversed value
761  */
762                                                           /* ToDo ARMCLANG: check if __builtin_bswap16 could be used */
763 __attribute__((always_inline)) __STATIC_INLINE int32_t __REVSH(int32_t value)
764 {
765   int32_t result;
766
767   __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
768   return(result);
769 }
770
771
772 /**
773   \brief   Rotate Right in unsigned value (32 bit)
774   \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
775   \param [in]    op1  Value to rotate
776   \param [in]    op2  Number of Bits to rotate
777   \return               Rotated value
778  */
779 __attribute__((always_inline)) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
780 {
781   return (op1 >> op2) | (op1 << (32U - op2));
782 }
783
784
785 /**
786   \brief   Breakpoint
787   \details Causes the processor to enter Debug state.
788            Debug tools can use this to investigate system state when the instruction at a particular address is reached.
789   \param [in]    value  is ignored by the processor.
790                  If required, a debugger can use it to store additional information about the breakpoint.
791  */
792 #define __BKPT(value)                       __ASM volatile ("bkpt "#value)
793
794
795 /**
796   \brief   Reverse bit order of value
797   \details Reverses the bit order of the given value.
798   \param [in]    value  Value to reverse
799   \return               Reversed value
800  */
801                                                           /* ToDo ARMCLANG: check if __builtin_arm_rbit is supported */
802 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
803 {
804   uint32_t result;
805
806 #if ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
807      (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
808      (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    )
809    __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
810 #else
811   int32_t s = (4 /*sizeof(v)*/ * 8) - 1; /* extra shift needed at end */
812
813   result = value;                      /* r will be reversed bits of v; first get LSB of v */
814   for (value >>= 1U; value; value >>= 1U)
815   {
816     result <<= 1U;
817     result |= value & 1U;
818     s--;
819   }
820   result <<= s;                        /* shift when v's highest bits are zero */
821 #endif
822   return(result);
823 }
824
825
826 /**
827   \brief   Count leading zeros
828   \details Counts the number of leading zeros of a data value.
829   \param [in]  value  Value to count the leading zeros
830   \return             number of leading zeros in value
831  */
832 #define __CLZ             __builtin_clz
833
834
835 #if ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
836      (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
837      (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
838      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
839 /**
840   \brief   LDR Exclusive (8 bit)
841   \details Executes a exclusive LDR instruction for 8 bit value.
842   \param [in]    ptr  Pointer to data
843   \return             value of type uint8_t at (*ptr)
844  */
845 #define __LDREXB        (uint8_t)__builtin_arm_ldrex
846
847
848 /**
849   \brief   LDR Exclusive (16 bit)
850   \details Executes a exclusive LDR instruction for 16 bit values.
851   \param [in]    ptr  Pointer to data
852   \return        value of type uint16_t at (*ptr)
853  */
854 #define __LDREXH        (uint16_t)__builtin_arm_ldrex
855
856
857 /**
858   \brief   LDR Exclusive (32 bit)
859   \details Executes a exclusive LDR instruction for 32 bit values.
860   \param [in]    ptr  Pointer to data
861   \return        value of type uint32_t at (*ptr)
862  */
863 #define __LDREXW        (uint32_t)__builtin_arm_ldrex
864
865
866 /**
867   \brief   STR Exclusive (8 bit)
868   \details Executes a exclusive STR instruction for 8 bit values.
869   \param [in]  value  Value to store
870   \param [in]    ptr  Pointer to location
871   \return          0  Function succeeded
872   \return          1  Function failed
873  */
874 #define __STREXB        (uint32_t)__builtin_arm_strex
875
876
877 /**
878   \brief   STR Exclusive (16 bit)
879   \details Executes a exclusive STR instruction for 16 bit values.
880   \param [in]  value  Value to store
881   \param [in]    ptr  Pointer to location
882   \return          0  Function succeeded
883   \return          1  Function failed
884  */
885 #define __STREXH        (uint32_t)__builtin_arm_strex
886
887
888 /**
889   \brief   STR Exclusive (32 bit)
890   \details Executes a exclusive STR instruction for 32 bit values.
891   \param [in]  value  Value to store
892   \param [in]    ptr  Pointer to location
893   \return          0  Function succeeded
894   \return          1  Function failed
895  */
896 #define __STREXW        (uint32_t)__builtin_arm_strex
897
898
899 /**
900   \brief   Remove the exclusive lock
901   \details Removes the exclusive lock which is created by LDREX.
902  */
903 #define __CLREX             __builtin_arm_clrex
904
905 #endif /* ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
906            (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
907            (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
908            (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    ) */
909
910
911 #if ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
912      (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
913      (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    )
914 /**
915   \brief   Signed Saturate
916   \details Saturates a signed value.
917   \param [in]  value  Value to be saturated
918   \param [in]    sat  Bit position to saturate to (1..32)
919   \return             Saturated value
920  */
921 #define __SSAT             __builtin_arm_ssat
922
923
924 /**
925   \brief   Unsigned Saturate
926   \details Saturates an unsigned value.
927   \param [in]  value  Value to be saturated
928   \param [in]    sat  Bit position to saturate to (0..31)
929   \return             Saturated value
930  */
931 #define __USAT             __builtin_arm_usat
932
933
934 /**
935   \brief   Rotate Right with Extend (32 bit)
936   \details Moves each bit of a bitstring right by one bit.
937            The carry input is shifted in at the left end of the bitstring.
938   \param [in]    value  Value to rotate
939   \return               Rotated value
940  */
941 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RRX(uint32_t value)
942 {
943   uint32_t result;
944
945   __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
946   return(result);
947 }
948
949
950 /**
951   \brief   LDRT Unprivileged (8 bit)
952   \details Executes a Unprivileged LDRT instruction for 8 bit value.
953   \param [in]    ptr  Pointer to data
954   \return             value of type uint8_t at (*ptr)
955  */
956 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *ptr)
957 {
958   uint32_t result;
959
960   __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
961   return ((uint8_t) result);    /* Add explicit type cast here */
962 }
963
964
965 /**
966   \brief   LDRT Unprivileged (16 bit)
967   \details Executes a Unprivileged LDRT instruction for 16 bit values.
968   \param [in]    ptr  Pointer to data
969   \return        value of type uint16_t at (*ptr)
970  */
971 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *ptr)
972 {
973   uint32_t result;
974
975   __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
976   return ((uint16_t) result);    /* Add explicit type cast here */
977 }
978
979
980 /**
981   \brief   LDRT Unprivileged (32 bit)
982   \details Executes a Unprivileged LDRT instruction for 32 bit values.
983   \param [in]    ptr  Pointer to data
984   \return        value of type uint32_t at (*ptr)
985  */
986 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t *ptr)
987 {
988   uint32_t result;
989
990   __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
991   return(result);
992 }
993
994
995 /**
996   \brief   STRT Unprivileged (8 bit)
997   \details Executes a Unprivileged STRT instruction for 8 bit values.
998   \param [in]  value  Value to store
999   \param [in]    ptr  Pointer to location
1000  */
1001 __attribute__((always_inline)) __STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
1002 {
1003   __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1004 }
1005
1006
1007 /**
1008   \brief   STRT Unprivileged (16 bit)
1009   \details Executes a Unprivileged STRT instruction for 16 bit values.
1010   \param [in]  value  Value to store
1011   \param [in]    ptr  Pointer to location
1012  */
1013 __attribute__((always_inline)) __STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
1014 {
1015   __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1016 }
1017
1018
1019 /**
1020   \brief   STRT Unprivileged (32 bit)
1021   \details Executes a Unprivileged STRT instruction for 32 bit values.
1022   \param [in]  value  Value to store
1023   \param [in]    ptr  Pointer to location
1024  */
1025 __attribute__((always_inline)) __STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
1026 {
1027   __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
1028 }
1029
1030 #endif /* ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
1031            (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
1032            (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    ) */
1033
1034
1035 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1036      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
1037 /**
1038   \brief   Load-Acquire (8 bit)
1039   \details Executes a LDAB instruction for 8 bit value.
1040   \param [in]    ptr  Pointer to data
1041   \return             value of type uint8_t at (*ptr)
1042  */
1043 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDAB(volatile uint8_t *ptr)
1044 {
1045   uint32_t result;
1046
1047   __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) );
1048   return ((uint8_t) result);
1049 }
1050
1051
1052 /**
1053   \brief   Load-Acquire (16 bit)
1054   \details Executes a LDAH instruction for 16 bit values.
1055   \param [in]    ptr  Pointer to data
1056   \return        value of type uint16_t at (*ptr)
1057  */
1058 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDAH(volatile uint16_t *ptr)
1059 {
1060   uint32_t result;
1061
1062   __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) );
1063   return ((uint16_t) result);
1064 }
1065
1066
1067 /**
1068   \brief   Load-Acquire (32 bit)
1069   \details Executes a LDA instruction for 32 bit values.
1070   \param [in]    ptr  Pointer to data
1071   \return        value of type uint32_t at (*ptr)
1072  */
1073 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDA(volatile uint32_t *ptr)
1074 {
1075   uint32_t result;
1076
1077   __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) );
1078   return(result);
1079 }
1080
1081
1082 /**
1083   \brief   Store-Release (8 bit)
1084   \details Executes a STLB instruction for 8 bit values.
1085   \param [in]  value  Value to store
1086   \param [in]    ptr  Pointer to location
1087  */
1088 __attribute__((always_inline)) __STATIC_INLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
1089 {
1090   __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1091 }
1092
1093
1094 /**
1095   \brief   Store-Release (16 bit)
1096   \details Executes a STLH instruction for 16 bit values.
1097   \param [in]  value  Value to store
1098   \param [in]    ptr  Pointer to location
1099  */
1100 __attribute__((always_inline)) __STATIC_INLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
1101 {
1102   __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1103 }
1104
1105
1106 /**
1107   \brief   Store-Release (32 bit)
1108   \details Executes a STL instruction for 32 bit values.
1109   \param [in]  value  Value to store
1110   \param [in]    ptr  Pointer to location
1111  */
1112 __attribute__((always_inline)) __STATIC_INLINE void __STL(uint32_t value, volatile uint32_t *ptr)
1113 {
1114   __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1115 }
1116
1117
1118 /**
1119   \brief   Load-Acquire Exclusive (8 bit)
1120   \details Executes a LDAB exclusive instruction for 8 bit value.
1121   \param [in]    ptr  Pointer to data
1122   \return             value of type uint8_t at (*ptr)
1123  */
1124 #define     __LDAEXB                 (uint8_t)__builtin_arm_ldaex
1125
1126
1127 /**
1128   \brief   Load-Acquire Exclusive (16 bit)
1129   \details Executes a LDAH exclusive instruction for 16 bit values.
1130   \param [in]    ptr  Pointer to data
1131   \return        value of type uint16_t at (*ptr)
1132  */
1133 #define     __LDAEXH                 (uint16_t)__builtin_arm_ldaex
1134
1135
1136 /**
1137   \brief   Load-Acquire Exclusive (32 bit)
1138   \details Executes a LDA exclusive instruction for 32 bit values.
1139   \param [in]    ptr  Pointer to data
1140   \return        value of type uint32_t at (*ptr)
1141  */
1142 #define     __LDAEX                  (uint32_t)__builtin_arm_ldaex
1143
1144
1145 /**
1146   \brief   Store-Release Exclusive (8 bit)
1147   \details Executes a STLB exclusive instruction for 8 bit values.
1148   \param [in]  value  Value to store
1149   \param [in]    ptr  Pointer to location
1150   \return          0  Function succeeded
1151   \return          1  Function failed
1152  */
1153 #define     __STLEXB                 (uint32_t)__builtin_arm_stlex
1154
1155
1156 /**
1157   \brief   Store-Release Exclusive (16 bit)
1158   \details Executes a STLH exclusive instruction for 16 bit values.
1159   \param [in]  value  Value to store
1160   \param [in]    ptr  Pointer to location
1161   \return          0  Function succeeded
1162   \return          1  Function failed
1163  */
1164 #define     __STLEXH                 (uint32_t)__builtin_arm_stlex
1165
1166
1167 /**
1168   \brief   Store-Release Exclusive (32 bit)
1169   \details Executes a STL exclusive instruction for 32 bit values.
1170   \param [in]  value  Value to store
1171   \param [in]    ptr  Pointer to location
1172   \return          0  Function succeeded
1173   \return          1  Function failed
1174  */
1175 #define     __STLEX                  (uint32_t)__builtin_arm_stlex
1176
1177 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1178            (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    ) */
1179
1180 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
1181
1182
1183 /* ###################  Compiler specific Intrinsics  ########################### */
1184 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1185   Access to dedicated SIMD instructions
1186   @{
1187 */
1188
1189 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
1190
1191 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
1192 {
1193   uint32_t result;
1194
1195   __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1196   return(result);
1197 }
1198
1199 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
1200 {
1201   uint32_t result;
1202
1203   __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1204   return(result);
1205 }
1206
1207 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
1208 {
1209   uint32_t result;
1210
1211   __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1212   return(result);
1213 }
1214
1215 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
1216 {
1217   uint32_t result;
1218
1219   __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1220   return(result);
1221 }
1222
1223 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
1224 {
1225   uint32_t result;
1226
1227   __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1228   return(result);
1229 }
1230
1231 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
1232 {
1233   uint32_t result;
1234
1235   __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1236   return(result);
1237 }
1238
1239
1240 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
1241 {
1242   uint32_t result;
1243
1244   __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1245   return(result);
1246 }
1247
1248 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
1249 {
1250   uint32_t result;
1251
1252   __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1253   return(result);
1254 }
1255
1256 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
1257 {
1258   uint32_t result;
1259
1260   __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1261   return(result);
1262 }
1263
1264 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
1265 {
1266   uint32_t result;
1267
1268   __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1269   return(result);
1270 }
1271
1272 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
1273 {
1274   uint32_t result;
1275
1276   __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1277   return(result);
1278 }
1279
1280 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
1281 {
1282   uint32_t result;
1283
1284   __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1285   return(result);
1286 }
1287
1288
1289 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
1290 {
1291   uint32_t result;
1292
1293   __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1294   return(result);
1295 }
1296
1297 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
1298 {
1299   uint32_t result;
1300
1301   __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1302   return(result);
1303 }
1304
1305 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
1306 {
1307   uint32_t result;
1308
1309   __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1310   return(result);
1311 }
1312
1313 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
1314 {
1315   uint32_t result;
1316
1317   __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1318   return(result);
1319 }
1320
1321 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
1322 {
1323   uint32_t result;
1324
1325   __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1326   return(result);
1327 }
1328
1329 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
1330 {
1331   uint32_t result;
1332
1333   __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1334   return(result);
1335 }
1336
1337 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
1338 {
1339   uint32_t result;
1340
1341   __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1342   return(result);
1343 }
1344
1345 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
1346 {
1347   uint32_t result;
1348
1349   __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1350   return(result);
1351 }
1352
1353 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
1354 {
1355   uint32_t result;
1356
1357   __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1358   return(result);
1359 }
1360
1361 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
1362 {
1363   uint32_t result;
1364
1365   __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1366   return(result);
1367 }
1368
1369 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
1370 {
1371   uint32_t result;
1372
1373   __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1374   return(result);
1375 }
1376
1377 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
1378 {
1379   uint32_t result;
1380
1381   __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1382   return(result);
1383 }
1384
1385 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
1386 {
1387   uint32_t result;
1388
1389   __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1390   return(result);
1391 }
1392
1393 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
1394 {
1395   uint32_t result;
1396
1397   __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1398   return(result);
1399 }
1400
1401 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
1402 {
1403   uint32_t result;
1404
1405   __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1406   return(result);
1407 }
1408
1409 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
1410 {
1411   uint32_t result;
1412
1413   __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1414   return(result);
1415 }
1416
1417 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
1418 {
1419   uint32_t result;
1420
1421   __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1422   return(result);
1423 }
1424
1425 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
1426 {
1427   uint32_t result;
1428
1429   __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1430   return(result);
1431 }
1432
1433 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
1434 {
1435   uint32_t result;
1436
1437   __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1438   return(result);
1439 }
1440
1441 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
1442 {
1443   uint32_t result;
1444
1445   __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1446   return(result);
1447 }
1448
1449 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
1450 {
1451   uint32_t result;
1452
1453   __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1454   return(result);
1455 }
1456
1457 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
1458 {
1459   uint32_t result;
1460
1461   __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1462   return(result);
1463 }
1464
1465 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
1466 {
1467   uint32_t result;
1468
1469   __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1470   return(result);
1471 }
1472
1473 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
1474 {
1475   uint32_t result;
1476
1477   __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1478   return(result);
1479 }
1480
1481 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
1482 {
1483   uint32_t result;
1484
1485   __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1486   return(result);
1487 }
1488
1489 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
1490 {
1491   uint32_t result;
1492
1493   __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1494   return(result);
1495 }
1496
1497 #define __SSAT16(ARG1,ARG2) \
1498 ({                          \
1499   int32_t __RES, __ARG1 = (ARG1); \
1500   __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) :  "I" (ARG2), "r" (__ARG1) ); \
1501   __RES; \
1502  })
1503
1504 #define __USAT16(ARG1,ARG2) \
1505 ({                          \
1506   uint32_t __RES, __ARG1 = (ARG1); \
1507   __ASM ("usat16 %0, %1, %2" : "=r" (__RES) :  "I" (ARG2), "r" (__ARG1) ); \
1508   __RES; \
1509  })
1510
1511 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1)
1512 {
1513   uint32_t result;
1514
1515   __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
1516   return(result);
1517 }
1518
1519 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
1520 {
1521   uint32_t result;
1522
1523   __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1524   return(result);
1525 }
1526
1527 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1)
1528 {
1529   uint32_t result;
1530
1531   __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
1532   return(result);
1533 }
1534
1535 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
1536 {
1537   uint32_t result;
1538
1539   __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1540   return(result);
1541 }
1542
1543 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUAD  (uint32_t op1, uint32_t op2)
1544 {
1545   uint32_t result;
1546
1547   __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1548   return(result);
1549 }
1550
1551 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
1552 {
1553   uint32_t result;
1554
1555   __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1556   return(result);
1557 }
1558
1559 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
1560 {
1561   uint32_t result;
1562
1563   __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1564   return(result);
1565 }
1566
1567 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
1568 {
1569   uint32_t result;
1570
1571   __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1572   return(result);
1573 }
1574
1575 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
1576 {
1577   union llreg_u{
1578     uint32_t w32[2];
1579     uint64_t w64;
1580   } llr;
1581   llr.w64 = acc;
1582
1583 #ifndef __ARMEB__   /* Little endian */
1584   __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1585 #else               /* Big endian */
1586   __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1587 #endif
1588
1589   return(llr.w64);
1590 }
1591
1592 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
1593 {
1594   union llreg_u{
1595     uint32_t w32[2];
1596     uint64_t w64;
1597   } llr;
1598   llr.w64 = acc;
1599
1600 #ifndef __ARMEB__   /* Little endian */
1601   __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1602 #else               /* Big endian */
1603   __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1604 #endif
1605
1606   return(llr.w64);
1607 }
1608
1609 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUSD  (uint32_t op1, uint32_t op2)
1610 {
1611   uint32_t result;
1612
1613   __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1614   return(result);
1615 }
1616
1617 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
1618 {
1619   uint32_t result;
1620
1621   __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1622   return(result);
1623 }
1624
1625 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
1626 {
1627   uint32_t result;
1628
1629   __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1630   return(result);
1631 }
1632
1633 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
1634 {
1635   uint32_t result;
1636
1637   __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1638   return(result);
1639 }
1640
1641 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
1642 {
1643   union llreg_u{
1644     uint32_t w32[2];
1645     uint64_t w64;
1646   } llr;
1647   llr.w64 = acc;
1648
1649 #ifndef __ARMEB__   /* Little endian */
1650   __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1651 #else               /* Big endian */
1652   __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1653 #endif
1654
1655   return(llr.w64);
1656 }
1657
1658 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
1659 {
1660   union llreg_u{
1661     uint32_t w32[2];
1662     uint64_t w64;
1663   } llr;
1664   llr.w64 = acc;
1665
1666 #ifndef __ARMEB__   /* Little endian */
1667   __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1668 #else               /* Big endian */
1669   __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1670 #endif
1671
1672   return(llr.w64);
1673 }
1674
1675 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SEL  (uint32_t op1, uint32_t op2)
1676 {
1677   uint32_t result;
1678
1679   __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1680   return(result);
1681 }
1682
1683 __attribute__((always_inline)) __STATIC_INLINE  int32_t __QADD( int32_t op1,  int32_t op2)
1684 {
1685   int32_t result;
1686
1687   __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1688   return(result);
1689 }
1690
1691 __attribute__((always_inline)) __STATIC_INLINE  int32_t __QSUB( int32_t op1,  int32_t op2)
1692 {
1693   int32_t result;
1694
1695   __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1696   return(result);
1697 }
1698
1699 #if 0
1700 #define __PKHBT(ARG1,ARG2,ARG3) \
1701 ({                          \
1702   uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1703   __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) :  "r" (__ARG1), "r" (__ARG2), "I" (ARG3)  ); \
1704   __RES; \
1705  })
1706
1707 #define __PKHTB(ARG1,ARG2,ARG3) \
1708 ({                          \
1709   uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1710   if (ARG3 == 0) \
1711     __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) :  "r" (__ARG1), "r" (__ARG2)  ); \
1712   else \
1713     __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) :  "r" (__ARG1), "r" (__ARG2), "I" (ARG3)  ); \
1714   __RES; \
1715  })
1716 #endif
1717
1718 #define __PKHBT(ARG1,ARG2,ARG3)          ( ((((uint32_t)(ARG1))          ) & 0x0000FFFFUL) |  \
1719                                            ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL)  )
1720
1721 #define __PKHTB(ARG1,ARG2,ARG3)          ( ((((uint32_t)(ARG1))          ) & 0xFFFF0000UL) |  \
1722                                            ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL)  )
1723
1724 __attribute__((always_inline)) __STATIC_INLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
1725 {
1726   int32_t result;
1727
1728   __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r"  (op1), "r" (op2), "r" (op3) );
1729   return(result);
1730 }
1731
1732 #endif /* (__ARM_FEATURE_DSP == 1) */
1733 /*@} end of group CMSIS_SIMD_intrinsics */
1734
1735
1736 #endif /* __CMSIS_ARMCLANG_H */