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