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