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