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