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